repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
thephpleague/glide | src/Manipulators/Size.php | Size.limitImageSize | public function limitImageSize($width, $height)
{
if ($this->maxImageSize !== null) {
$imageSize = $width * $height;
if ($imageSize > $this->maxImageSize) {
$width = $width / sqrt($imageSize / $this->maxImageSize);
$height = $height / sqrt($imageSize / $this->maxImageSize);
}
}
return [
(int) $width,
(int) $height,
];
} | php | public function limitImageSize($width, $height)
{
if ($this->maxImageSize !== null) {
$imageSize = $width * $height;
if ($imageSize > $this->maxImageSize) {
$width = $width / sqrt($imageSize / $this->maxImageSize);
$height = $height / sqrt($imageSize / $this->maxImageSize);
}
}
return [
(int) $width,
(int) $height,
];
} | [
"public",
"function",
"limitImageSize",
"(",
"$",
"width",
",",
"$",
"height",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"maxImageSize",
"!==",
"null",
")",
"{",
"$",
"imageSize",
"=",
"$",
"width",
"*",
"$",
"height",
";",
"if",
"(",
"$",
"imageSize",
">",
"$",
"this",
"->",
"maxImageSize",
")",
"{",
"$",
"width",
"=",
"$",
"width",
"/",
"sqrt",
"(",
"$",
"imageSize",
"/",
"$",
"this",
"->",
"maxImageSize",
")",
";",
"$",
"height",
"=",
"$",
"height",
"/",
"sqrt",
"(",
"$",
"imageSize",
"/",
"$",
"this",
"->",
"maxImageSize",
")",
";",
"}",
"}",
"return",
"[",
"(",
"int",
")",
"$",
"width",
",",
"(",
"int",
")",
"$",
"height",
",",
"]",
";",
"}"
] | Limit image size to maximum allowed image size.
@param integer $width The image width.
@param integer $height The image height.
@return integer[] The limited width and height. | [
"Limit",
"image",
"size",
"to",
"maximum",
"allowed",
"image",
"size",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L191-L206 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.runResize | public function runResize(Image $image, $fit, $width, $height)
{
if ($fit === 'contain') {
return $this->runContainResize($image, $width, $height);
}
if ($fit === 'fill') {
return $this->runFillResize($image, $width, $height);
}
if ($fit === 'max') {
return $this->runMaxResize($image, $width, $height);
}
if ($fit === 'stretch') {
return $this->runStretchResize($image, $width, $height);
}
if ($fit === 'crop') {
return $this->runCropResize($image, $width, $height);
}
return $image;
} | php | public function runResize(Image $image, $fit, $width, $height)
{
if ($fit === 'contain') {
return $this->runContainResize($image, $width, $height);
}
if ($fit === 'fill') {
return $this->runFillResize($image, $width, $height);
}
if ($fit === 'max') {
return $this->runMaxResize($image, $width, $height);
}
if ($fit === 'stretch') {
return $this->runStretchResize($image, $width, $height);
}
if ($fit === 'crop') {
return $this->runCropResize($image, $width, $height);
}
return $image;
} | [
"public",
"function",
"runResize",
"(",
"Image",
"$",
"image",
",",
"$",
"fit",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"if",
"(",
"$",
"fit",
"===",
"'contain'",
")",
"{",
"return",
"$",
"this",
"->",
"runContainResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"if",
"(",
"$",
"fit",
"===",
"'fill'",
")",
"{",
"return",
"$",
"this",
"->",
"runFillResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"if",
"(",
"$",
"fit",
"===",
"'max'",
")",
"{",
"return",
"$",
"this",
"->",
"runMaxResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"if",
"(",
"$",
"fit",
"===",
"'stretch'",
")",
"{",
"return",
"$",
"this",
"->",
"runStretchResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"if",
"(",
"$",
"fit",
"===",
"'crop'",
")",
"{",
"return",
"$",
"this",
"->",
"runCropResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform resize image manipulation.
@param Image $image The source image.
@param string $fit The fit.
@param integer $width The width.
@param integer $height The height.
@return Image The manipulated image. | [
"Perform",
"resize",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L216-L239 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.runContainResize | public function runContainResize(Image $image, $width, $height)
{
return $image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
} | php | public function runContainResize(Image $image, $width, $height)
{
return $image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
} | [
"public",
"function",
"runContainResize",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"return",
"$",
"image",
"->",
"resize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"function",
"(",
"$",
"constraint",
")",
"{",
"$",
"constraint",
"->",
"aspectRatio",
"(",
")",
";",
"}",
")",
";",
"}"
] | Perform contain resize image manipulation.
@param Image $image The source image.
@param integer $width The width.
@param integer $height The height.
@return Image The manipulated image. | [
"Perform",
"contain",
"resize",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L248-L253 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.runMaxResize | public function runMaxResize(Image $image, $width, $height)
{
return $image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
} | php | public function runMaxResize(Image $image, $width, $height)
{
return $image->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
} | [
"public",
"function",
"runMaxResize",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"return",
"$",
"image",
"->",
"resize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"function",
"(",
"$",
"constraint",
")",
"{",
"$",
"constraint",
"->",
"aspectRatio",
"(",
")",
";",
"$",
"constraint",
"->",
"upsize",
"(",
")",
";",
"}",
")",
";",
"}"
] | Perform max resize image manipulation.
@param Image $image The source image.
@param integer $width The width.
@param integer $height The height.
@return Image The manipulated image. | [
"Perform",
"max",
"resize",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L262-L268 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.runFillResize | public function runFillResize($image, $width, $height)
{
$image = $this->runMaxResize($image, $width, $height);
return $image->resizeCanvas($width, $height, 'center');
} | php | public function runFillResize($image, $width, $height)
{
$image = $this->runMaxResize($image, $width, $height);
return $image->resizeCanvas($width, $height, 'center');
} | [
"public",
"function",
"runFillResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"runMaxResize",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"return",
"$",
"image",
"->",
"resizeCanvas",
"(",
"$",
"width",
",",
"$",
"height",
",",
"'center'",
")",
";",
"}"
] | Perform fill resize image manipulation.
@param Image $image The source image.
@param integer $width The width.
@param integer $height The height.
@return Image The manipulated image. | [
"Perform",
"fill",
"resize",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L277-L282 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.runCropResize | public function runCropResize(Image $image, $width, $height)
{
list($resize_width, $resize_height) = $this->resolveCropResizeDimensions($image, $width, $height);
$zoom = $this->getCrop()[2];
$image->resize($resize_width * $zoom, $resize_height * $zoom, function ($constraint) {
$constraint->aspectRatio();
});
list($offset_x, $offset_y) = $this->resolveCropOffset($image, $width, $height);
return $image->crop($width, $height, $offset_x, $offset_y);
} | php | public function runCropResize(Image $image, $width, $height)
{
list($resize_width, $resize_height) = $this->resolveCropResizeDimensions($image, $width, $height);
$zoom = $this->getCrop()[2];
$image->resize($resize_width * $zoom, $resize_height * $zoom, function ($constraint) {
$constraint->aspectRatio();
});
list($offset_x, $offset_y) = $this->resolveCropOffset($image, $width, $height);
return $image->crop($width, $height, $offset_x, $offset_y);
} | [
"public",
"function",
"runCropResize",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"list",
"(",
"$",
"resize_width",
",",
"$",
"resize_height",
")",
"=",
"$",
"this",
"->",
"resolveCropResizeDimensions",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"zoom",
"=",
"$",
"this",
"->",
"getCrop",
"(",
")",
"[",
"2",
"]",
";",
"$",
"image",
"->",
"resize",
"(",
"$",
"resize_width",
"*",
"$",
"zoom",
",",
"$",
"resize_height",
"*",
"$",
"zoom",
",",
"function",
"(",
"$",
"constraint",
")",
"{",
"$",
"constraint",
"->",
"aspectRatio",
"(",
")",
";",
"}",
")",
";",
"list",
"(",
"$",
"offset_x",
",",
"$",
"offset_y",
")",
"=",
"$",
"this",
"->",
"resolveCropOffset",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"return",
"$",
"image",
"->",
"crop",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"offset_x",
",",
"$",
"offset_y",
")",
";",
"}"
] | Perform crop resize image manipulation.
@param Image $image The source image.
@param integer $width The width.
@param integer $height The height.
@return Image The manipulated image. | [
"Perform",
"crop",
"resize",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L303-L316 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.resolveCropResizeDimensions | public function resolveCropResizeDimensions(Image $image, $width, $height)
{
if ($height > $width * ($image->height() / $image->width())) {
return [$height * ($image->width() / $image->height()), $height];
}
return [$width, $width * ($image->height() / $image->width())];
} | php | public function resolveCropResizeDimensions(Image $image, $width, $height)
{
if ($height > $width * ($image->height() / $image->width())) {
return [$height * ($image->width() / $image->height()), $height];
}
return [$width, $width * ($image->height() / $image->width())];
} | [
"public",
"function",
"resolveCropResizeDimensions",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"if",
"(",
"$",
"height",
">",
"$",
"width",
"*",
"(",
"$",
"image",
"->",
"height",
"(",
")",
"/",
"$",
"image",
"->",
"width",
"(",
")",
")",
")",
"{",
"return",
"[",
"$",
"height",
"*",
"(",
"$",
"image",
"->",
"width",
"(",
")",
"/",
"$",
"image",
"->",
"height",
"(",
")",
")",
",",
"$",
"height",
"]",
";",
"}",
"return",
"[",
"$",
"width",
",",
"$",
"width",
"*",
"(",
"$",
"image",
"->",
"height",
"(",
")",
"/",
"$",
"image",
"->",
"width",
"(",
")",
")",
"]",
";",
"}"
] | Resolve the crop resize dimensions.
@param Image $image The source image.
@param integer $width The width.
@param integer $height The height.
@return array The resize dimensions. | [
"Resolve",
"the",
"crop",
"resize",
"dimensions",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L325-L332 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.resolveCropOffset | public function resolveCropOffset(Image $image, $width, $height)
{
list($offset_percentage_x, $offset_percentage_y) = $this->getCrop();
$offset_x = (int) (($image->width() * $offset_percentage_x / 100) - ($width / 2));
$offset_y = (int) (($image->height() * $offset_percentage_y / 100) - ($height / 2));
$max_offset_x = $image->width() - $width;
$max_offset_y = $image->height() - $height;
if ($offset_x < 0) {
$offset_x = 0;
}
if ($offset_y < 0) {
$offset_y = 0;
}
if ($offset_x > $max_offset_x) {
$offset_x = $max_offset_x;
}
if ($offset_y > $max_offset_y) {
$offset_y = $max_offset_y;
}
return [$offset_x, $offset_y];
} | php | public function resolveCropOffset(Image $image, $width, $height)
{
list($offset_percentage_x, $offset_percentage_y) = $this->getCrop();
$offset_x = (int) (($image->width() * $offset_percentage_x / 100) - ($width / 2));
$offset_y = (int) (($image->height() * $offset_percentage_y / 100) - ($height / 2));
$max_offset_x = $image->width() - $width;
$max_offset_y = $image->height() - $height;
if ($offset_x < 0) {
$offset_x = 0;
}
if ($offset_y < 0) {
$offset_y = 0;
}
if ($offset_x > $max_offset_x) {
$offset_x = $max_offset_x;
}
if ($offset_y > $max_offset_y) {
$offset_y = $max_offset_y;
}
return [$offset_x, $offset_y];
} | [
"public",
"function",
"resolveCropOffset",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"list",
"(",
"$",
"offset_percentage_x",
",",
"$",
"offset_percentage_y",
")",
"=",
"$",
"this",
"->",
"getCrop",
"(",
")",
";",
"$",
"offset_x",
"=",
"(",
"int",
")",
"(",
"(",
"$",
"image",
"->",
"width",
"(",
")",
"*",
"$",
"offset_percentage_x",
"/",
"100",
")",
"-",
"(",
"$",
"width",
"/",
"2",
")",
")",
";",
"$",
"offset_y",
"=",
"(",
"int",
")",
"(",
"(",
"$",
"image",
"->",
"height",
"(",
")",
"*",
"$",
"offset_percentage_y",
"/",
"100",
")",
"-",
"(",
"$",
"height",
"/",
"2",
")",
")",
";",
"$",
"max_offset_x",
"=",
"$",
"image",
"->",
"width",
"(",
")",
"-",
"$",
"width",
";",
"$",
"max_offset_y",
"=",
"$",
"image",
"->",
"height",
"(",
")",
"-",
"$",
"height",
";",
"if",
"(",
"$",
"offset_x",
"<",
"0",
")",
"{",
"$",
"offset_x",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"offset_y",
"<",
"0",
")",
"{",
"$",
"offset_y",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"offset_x",
">",
"$",
"max_offset_x",
")",
"{",
"$",
"offset_x",
"=",
"$",
"max_offset_x",
";",
"}",
"if",
"(",
"$",
"offset_y",
">",
"$",
"max_offset_y",
")",
"{",
"$",
"offset_y",
"=",
"$",
"max_offset_y",
";",
"}",
"return",
"[",
"$",
"offset_x",
",",
"$",
"offset_y",
"]",
";",
"}"
] | Resolve the crop offset.
@param Image $image The source image.
@param integer $width The width.
@param integer $height The height.
@return array The crop offset. | [
"Resolve",
"the",
"crop",
"offset",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L341-L368 | train |
thephpleague/glide | src/Manipulators/Size.php | Size.getCrop | public function getCrop()
{
$cropMethods = [
'crop-top-left' => [0, 0, 1.0],
'crop-top' => [50, 0, 1.0],
'crop-top-right' => [100, 0, 1.0],
'crop-left' => [0, 50, 1.0],
'crop-center' => [50, 50, 1.0],
'crop-right' => [100, 50, 1.0],
'crop-bottom-left' => [0, 100, 1.0],
'crop-bottom' => [50, 100, 1.0],
'crop-bottom-right' => [100, 100, 1.0],
];
if (array_key_exists($this->fit, $cropMethods)) {
return $cropMethods[$this->fit];
}
if (preg_match('/^crop-([\d]{1,3})-([\d]{1,3})(?:-([\d]{1,3}(?:\.\d+)?))*$/', $this->fit, $matches)) {
$matches[3] = isset($matches[3]) ? $matches[3] : 1;
if ($matches[1] > 100 or $matches[2] > 100 or $matches[3] > 100) {
return [50, 50, 1.0];
}
return [
(int) $matches[1],
(int) $matches[2],
(float) $matches[3],
];
}
return [50, 50, 1.0];
} | php | public function getCrop()
{
$cropMethods = [
'crop-top-left' => [0, 0, 1.0],
'crop-top' => [50, 0, 1.0],
'crop-top-right' => [100, 0, 1.0],
'crop-left' => [0, 50, 1.0],
'crop-center' => [50, 50, 1.0],
'crop-right' => [100, 50, 1.0],
'crop-bottom-left' => [0, 100, 1.0],
'crop-bottom' => [50, 100, 1.0],
'crop-bottom-right' => [100, 100, 1.0],
];
if (array_key_exists($this->fit, $cropMethods)) {
return $cropMethods[$this->fit];
}
if (preg_match('/^crop-([\d]{1,3})-([\d]{1,3})(?:-([\d]{1,3}(?:\.\d+)?))*$/', $this->fit, $matches)) {
$matches[3] = isset($matches[3]) ? $matches[3] : 1;
if ($matches[1] > 100 or $matches[2] > 100 or $matches[3] > 100) {
return [50, 50, 1.0];
}
return [
(int) $matches[1],
(int) $matches[2],
(float) $matches[3],
];
}
return [50, 50, 1.0];
} | [
"public",
"function",
"getCrop",
"(",
")",
"{",
"$",
"cropMethods",
"=",
"[",
"'crop-top-left'",
"=>",
"[",
"0",
",",
"0",
",",
"1.0",
"]",
",",
"'crop-top'",
"=>",
"[",
"50",
",",
"0",
",",
"1.0",
"]",
",",
"'crop-top-right'",
"=>",
"[",
"100",
",",
"0",
",",
"1.0",
"]",
",",
"'crop-left'",
"=>",
"[",
"0",
",",
"50",
",",
"1.0",
"]",
",",
"'crop-center'",
"=>",
"[",
"50",
",",
"50",
",",
"1.0",
"]",
",",
"'crop-right'",
"=>",
"[",
"100",
",",
"50",
",",
"1.0",
"]",
",",
"'crop-bottom-left'",
"=>",
"[",
"0",
",",
"100",
",",
"1.0",
"]",
",",
"'crop-bottom'",
"=>",
"[",
"50",
",",
"100",
",",
"1.0",
"]",
",",
"'crop-bottom-right'",
"=>",
"[",
"100",
",",
"100",
",",
"1.0",
"]",
",",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"fit",
",",
"$",
"cropMethods",
")",
")",
"{",
"return",
"$",
"cropMethods",
"[",
"$",
"this",
"->",
"fit",
"]",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^crop-([\\d]{1,3})-([\\d]{1,3})(?:-([\\d]{1,3}(?:\\.\\d+)?))*$/'",
",",
"$",
"this",
"->",
"fit",
",",
"$",
"matches",
")",
")",
"{",
"$",
"matches",
"[",
"3",
"]",
"=",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
"?",
"$",
"matches",
"[",
"3",
"]",
":",
"1",
";",
"if",
"(",
"$",
"matches",
"[",
"1",
"]",
">",
"100",
"or",
"$",
"matches",
"[",
"2",
"]",
">",
"100",
"or",
"$",
"matches",
"[",
"3",
"]",
">",
"100",
")",
"{",
"return",
"[",
"50",
",",
"50",
",",
"1.0",
"]",
";",
"}",
"return",
"[",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
",",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
",",
"(",
"float",
")",
"$",
"matches",
"[",
"3",
"]",
",",
"]",
";",
"}",
"return",
"[",
"50",
",",
"50",
",",
"1.0",
"]",
";",
"}"
] | Resolve crop with zoom.
@return integer[] The resolved crop. | [
"Resolve",
"crop",
"with",
"zoom",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Size.php#L374-L407 | train |
thephpleague/glide | src/Manipulators/Pixelate.php | Pixelate.run | public function run(Image $image)
{
$pixelate = $this->getPixelate();
if ($pixelate !== null) {
$image->pixelate($pixelate);
}
return $image;
} | php | public function run(Image $image)
{
$pixelate = $this->getPixelate();
if ($pixelate !== null) {
$image->pixelate($pixelate);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"pixelate",
"=",
"$",
"this",
"->",
"getPixelate",
"(",
")",
";",
"if",
"(",
"$",
"pixelate",
"!==",
"null",
")",
"{",
"$",
"image",
"->",
"pixelate",
"(",
"$",
"pixelate",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform pixelate image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"pixelate",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Pixelate.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Pixelate.php | Pixelate.getPixelate | public function getPixelate()
{
if (!is_numeric($this->pixel)) {
return;
}
if ($this->pixel < 0 or $this->pixel > 1000) {
return;
}
return (int) $this->pixel;
} | php | public function getPixelate()
{
if (!is_numeric($this->pixel)) {
return;
}
if ($this->pixel < 0 or $this->pixel > 1000) {
return;
}
return (int) $this->pixel;
} | [
"public",
"function",
"getPixelate",
"(",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"pixel",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"pixel",
"<",
"0",
"or",
"$",
"this",
"->",
"pixel",
">",
"1000",
")",
"{",
"return",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"pixel",
";",
"}"
] | Resolve pixelate amount.
@return string The resolved pixelate amount. | [
"Resolve",
"pixelate",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Pixelate.php#L32-L43 | train |
thephpleague/glide | src/Manipulators/Helpers/Dimension.php | Dimension.get | public function get($value)
{
if (is_numeric($value) and $value > 0) {
return (double) $value * $this->dpr;
}
if (preg_match('/^(\d{1,2}(?!\d)|100)(w|h)$/', $value, $matches)) {
if ($matches[2] === 'h') {
return (double) $this->image->height() * ($matches[1] / 100);
}
return (double) $this->image->width() * ($matches[1] / 100);
}
} | php | public function get($value)
{
if (is_numeric($value) and $value > 0) {
return (double) $value * $this->dpr;
}
if (preg_match('/^(\d{1,2}(?!\d)|100)(w|h)$/', $value, $matches)) {
if ($matches[2] === 'h') {
return (double) $this->image->height() * ($matches[1] / 100);
}
return (double) $this->image->width() * ($matches[1] / 100);
}
} | [
"public",
"function",
"get",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"and",
"$",
"value",
">",
"0",
")",
"{",
"return",
"(",
"double",
")",
"$",
"value",
"*",
"$",
"this",
"->",
"dpr",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^(\\d{1,2}(?!\\d)|100)(w|h)$/'",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"$",
"matches",
"[",
"2",
"]",
"===",
"'h'",
")",
"{",
"return",
"(",
"double",
")",
"$",
"this",
"->",
"image",
"->",
"height",
"(",
")",
"*",
"(",
"$",
"matches",
"[",
"1",
"]",
"/",
"100",
")",
";",
"}",
"return",
"(",
"double",
")",
"$",
"this",
"->",
"image",
"->",
"width",
"(",
")",
"*",
"(",
"$",
"matches",
"[",
"1",
"]",
"/",
"100",
")",
";",
"}",
"}"
] | Resolve the dimension.
@param string $value The dimension value.
@return double The resolved dimension. | [
"Resolve",
"the",
"dimension",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Helpers/Dimension.php#L37-L50 | train |
thephpleague/glide | src/Manipulators/Flip.php | Flip.run | public function run(Image $image)
{
if ($flip = $this->getFlip()) {
if ($flip === 'both') {
return $image->flip('h')->flip('v');
}
return $image->flip($flip);
}
return $image;
} | php | public function run(Image $image)
{
if ($flip = $this->getFlip()) {
if ($flip === 'both') {
return $image->flip('h')->flip('v');
}
return $image->flip($flip);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"$",
"flip",
"=",
"$",
"this",
"->",
"getFlip",
"(",
")",
")",
"{",
"if",
"(",
"$",
"flip",
"===",
"'both'",
")",
"{",
"return",
"$",
"image",
"->",
"flip",
"(",
"'h'",
")",
"->",
"flip",
"(",
"'v'",
")",
";",
"}",
"return",
"$",
"image",
"->",
"flip",
"(",
"$",
"flip",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform flip image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"flip",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Flip.php#L17-L28 | train |
thephpleague/glide | src/Manipulators/Brightness.php | Brightness.run | public function run(Image $image)
{
$brightness = $this->getBrightness();
if ($brightness !== null) {
$image->brightness($brightness);
}
return $image;
} | php | public function run(Image $image)
{
$brightness = $this->getBrightness();
if ($brightness !== null) {
$image->brightness($brightness);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"brightness",
"=",
"$",
"this",
"->",
"getBrightness",
"(",
")",
";",
"if",
"(",
"$",
"brightness",
"!==",
"null",
")",
"{",
"$",
"image",
"->",
"brightness",
"(",
"$",
"brightness",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform brightness image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"brightness",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Brightness.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Brightness.php | Brightness.getBrightness | public function getBrightness()
{
if (!preg_match('/^-*[0-9]+$/', $this->bri)) {
return;
}
if ($this->bri < -100 or $this->bri > 100) {
return;
}
return (int) $this->bri;
} | php | public function getBrightness()
{
if (!preg_match('/^-*[0-9]+$/', $this->bri)) {
return;
}
if ($this->bri < -100 or $this->bri > 100) {
return;
}
return (int) $this->bri;
} | [
"public",
"function",
"getBrightness",
"(",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^-*[0-9]+$/'",
",",
"$",
"this",
"->",
"bri",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"bri",
"<",
"-",
"100",
"or",
"$",
"this",
"->",
"bri",
">",
"100",
")",
"{",
"return",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"bri",
";",
"}"
] | Resolve brightness amount.
@return string The resolved brightness amount. | [
"Resolve",
"brightness",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Brightness.php#L32-L43 | train |
thephpleague/glide | src/Api/Api.php | Api.setManipulators | public function setManipulators(array $manipulators)
{
foreach ($manipulators as $manipulator) {
if (!($manipulator instanceof ManipulatorInterface)) {
throw new InvalidArgumentException('Not a valid manipulator.');
}
}
$this->manipulators = $manipulators;
} | php | public function setManipulators(array $manipulators)
{
foreach ($manipulators as $manipulator) {
if (!($manipulator instanceof ManipulatorInterface)) {
throw new InvalidArgumentException('Not a valid manipulator.');
}
}
$this->manipulators = $manipulators;
} | [
"public",
"function",
"setManipulators",
"(",
"array",
"$",
"manipulators",
")",
"{",
"foreach",
"(",
"$",
"manipulators",
"as",
"$",
"manipulator",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"manipulator",
"instanceof",
"ManipulatorInterface",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Not a valid manipulator.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"manipulators",
"=",
"$",
"manipulators",
";",
"}"
] | Set the manipulators.
@param array $manipulators Collection of manipulators. | [
"Set",
"the",
"manipulators",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Api/Api.php#L56-L65 | train |
thephpleague/glide | src/Api/Api.php | Api.run | public function run($source, array $params)
{
$image = $this->imageManager->make($source);
foreach ($this->manipulators as $manipulator) {
$manipulator->setParams($params);
$image = $manipulator->run($image);
}
return $image->getEncoded();
} | php | public function run($source, array $params)
{
$image = $this->imageManager->make($source);
foreach ($this->manipulators as $manipulator) {
$manipulator->setParams($params);
$image = $manipulator->run($image);
}
return $image->getEncoded();
} | [
"public",
"function",
"run",
"(",
"$",
"source",
",",
"array",
"$",
"params",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"imageManager",
"->",
"make",
"(",
"$",
"source",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"manipulators",
"as",
"$",
"manipulator",
")",
"{",
"$",
"manipulator",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"$",
"image",
"=",
"$",
"manipulator",
"->",
"run",
"(",
"$",
"image",
")",
";",
"}",
"return",
"$",
"image",
"->",
"getEncoded",
"(",
")",
";",
"}"
] | Perform image manipulations.
@param string $source Source image binary data.
@param array $params The manipulation params.
@return string Manipulated image binary data. | [
"Perform",
"image",
"manipulations",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Api/Api.php#L82-L93 | train |
thephpleague/glide | src/Manipulators/Background.php | Background.run | public function run(Image $image)
{
if (is_null($this->bg)) {
return $image;
}
$color = (new Color($this->bg))->formatted();
if ($color) {
$new = $image->getDriver()->newImage($image->width(), $image->height(), $color);
$new->mime = $image->mime;
$image = $new->insert($image, 'top-left', 0, 0);
}
return $image;
} | php | public function run(Image $image)
{
if (is_null($this->bg)) {
return $image;
}
$color = (new Color($this->bg))->formatted();
if ($color) {
$new = $image->getDriver()->newImage($image->width(), $image->height(), $color);
$new->mime = $image->mime;
$image = $new->insert($image, 'top-left', 0, 0);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"bg",
")",
")",
"{",
"return",
"$",
"image",
";",
"}",
"$",
"color",
"=",
"(",
"new",
"Color",
"(",
"$",
"this",
"->",
"bg",
")",
")",
"->",
"formatted",
"(",
")",
";",
"if",
"(",
"$",
"color",
")",
"{",
"$",
"new",
"=",
"$",
"image",
"->",
"getDriver",
"(",
")",
"->",
"newImage",
"(",
"$",
"image",
"->",
"width",
"(",
")",
",",
"$",
"image",
"->",
"height",
"(",
")",
",",
"$",
"color",
")",
";",
"$",
"new",
"->",
"mime",
"=",
"$",
"image",
"->",
"mime",
";",
"$",
"image",
"=",
"$",
"new",
"->",
"insert",
"(",
"$",
"image",
",",
"'top-left'",
",",
"0",
",",
"0",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform background image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"background",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Background.php#L18-L33 | train |
thephpleague/glide | src/Manipulators/Gamma.php | Gamma.run | public function run(Image $image)
{
$gamma = $this->getGamma();
if ($gamma) {
$image->gamma($gamma);
}
return $image;
} | php | public function run(Image $image)
{
$gamma = $this->getGamma();
if ($gamma) {
$image->gamma($gamma);
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"gamma",
"=",
"$",
"this",
"->",
"getGamma",
"(",
")",
";",
"if",
"(",
"$",
"gamma",
")",
"{",
"$",
"image",
"->",
"gamma",
"(",
"$",
"gamma",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform gamma image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"gamma",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Gamma.php#L17-L26 | train |
thephpleague/glide | src/Manipulators/Gamma.php | Gamma.getGamma | public function getGamma()
{
if (!preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) {
return;
}
if ($this->gam < 0.1 or $this->gam > 9.99) {
return;
}
return (double) $this->gam;
} | php | public function getGamma()
{
if (!preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) {
return;
}
if ($this->gam < 0.1 or $this->gam > 9.99) {
return;
}
return (double) $this->gam;
} | [
"public",
"function",
"getGamma",
"(",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[0-9]\\.*[0-9]*$/'",
",",
"$",
"this",
"->",
"gam",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"gam",
"<",
"0.1",
"or",
"$",
"this",
"->",
"gam",
">",
"9.99",
")",
"{",
"return",
";",
"}",
"return",
"(",
"double",
")",
"$",
"this",
"->",
"gam",
";",
"}"
] | Resolve gamma amount.
@return string The resolved gamma amount. | [
"Resolve",
"gamma",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Gamma.php#L32-L43 | train |
thephpleague/glide | src/Urls/UrlBuilderFactory.php | UrlBuilderFactory.create | public static function create($baseUrl, $signKey = null)
{
$httpSignature = null;
if (!is_null($signKey)) {
$httpSignature = SignatureFactory::create($signKey);
}
return new UrlBuilder($baseUrl, $httpSignature);
} | php | public static function create($baseUrl, $signKey = null)
{
$httpSignature = null;
if (!is_null($signKey)) {
$httpSignature = SignatureFactory::create($signKey);
}
return new UrlBuilder($baseUrl, $httpSignature);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"baseUrl",
",",
"$",
"signKey",
"=",
"null",
")",
"{",
"$",
"httpSignature",
"=",
"null",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"signKey",
")",
")",
"{",
"$",
"httpSignature",
"=",
"SignatureFactory",
"::",
"create",
"(",
"$",
"signKey",
")",
";",
"}",
"return",
"new",
"UrlBuilder",
"(",
"$",
"baseUrl",
",",
"$",
"httpSignature",
")",
";",
"}"
] | Create UrlBuilder instance.
@param string $baseUrl URL prefixed to generated URL.
@param string|null $signKey Secret key used to secure URLs.
@return UrlBuilder The UrlBuilder instance. | [
"Create",
"UrlBuilder",
"instance",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Urls/UrlBuilderFactory.php#L15-L24 | train |
thephpleague/glide | src/Manipulators/Watermark.php | Watermark.run | public function run(Image $image)
{
if ($watermark = $this->getImage($image)) {
$markw = $this->getDimension($image, 'markw');
$markh = $this->getDimension($image, 'markh');
$markx = $this->getDimension($image, 'markx');
$marky = $this->getDimension($image, 'marky');
$markpad = $this->getDimension($image, 'markpad');
$markfit = $this->getFit();
$markpos = $this->getPosition();
$markalpha = $this->getAlpha();
if ($markpad) {
$markx = $marky = $markpad;
}
$size = new Size();
$size->setParams([
'w' => $markw,
'h' => $markh,
'fit' => $markfit,
]);
$watermark = $size->run($watermark);
if ($markalpha < 100) {
$watermark->opacity($markalpha);
}
$image->insert($watermark, $markpos, intval($markx), intval($marky));
}
return $image;
} | php | public function run(Image $image)
{
if ($watermark = $this->getImage($image)) {
$markw = $this->getDimension($image, 'markw');
$markh = $this->getDimension($image, 'markh');
$markx = $this->getDimension($image, 'markx');
$marky = $this->getDimension($image, 'marky');
$markpad = $this->getDimension($image, 'markpad');
$markfit = $this->getFit();
$markpos = $this->getPosition();
$markalpha = $this->getAlpha();
if ($markpad) {
$markx = $marky = $markpad;
}
$size = new Size();
$size->setParams([
'w' => $markw,
'h' => $markh,
'fit' => $markfit,
]);
$watermark = $size->run($watermark);
if ($markalpha < 100) {
$watermark->opacity($markalpha);
}
$image->insert($watermark, $markpos, intval($markx), intval($marky));
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"$",
"watermark",
"=",
"$",
"this",
"->",
"getImage",
"(",
"$",
"image",
")",
")",
"{",
"$",
"markw",
"=",
"$",
"this",
"->",
"getDimension",
"(",
"$",
"image",
",",
"'markw'",
")",
";",
"$",
"markh",
"=",
"$",
"this",
"->",
"getDimension",
"(",
"$",
"image",
",",
"'markh'",
")",
";",
"$",
"markx",
"=",
"$",
"this",
"->",
"getDimension",
"(",
"$",
"image",
",",
"'markx'",
")",
";",
"$",
"marky",
"=",
"$",
"this",
"->",
"getDimension",
"(",
"$",
"image",
",",
"'marky'",
")",
";",
"$",
"markpad",
"=",
"$",
"this",
"->",
"getDimension",
"(",
"$",
"image",
",",
"'markpad'",
")",
";",
"$",
"markfit",
"=",
"$",
"this",
"->",
"getFit",
"(",
")",
";",
"$",
"markpos",
"=",
"$",
"this",
"->",
"getPosition",
"(",
")",
";",
"$",
"markalpha",
"=",
"$",
"this",
"->",
"getAlpha",
"(",
")",
";",
"if",
"(",
"$",
"markpad",
")",
"{",
"$",
"markx",
"=",
"$",
"marky",
"=",
"$",
"markpad",
";",
"}",
"$",
"size",
"=",
"new",
"Size",
"(",
")",
";",
"$",
"size",
"->",
"setParams",
"(",
"[",
"'w'",
"=>",
"$",
"markw",
",",
"'h'",
"=>",
"$",
"markh",
",",
"'fit'",
"=>",
"$",
"markfit",
",",
"]",
")",
";",
"$",
"watermark",
"=",
"$",
"size",
"->",
"run",
"(",
"$",
"watermark",
")",
";",
"if",
"(",
"$",
"markalpha",
"<",
"100",
")",
"{",
"$",
"watermark",
"->",
"opacity",
"(",
"$",
"markalpha",
")",
";",
"}",
"$",
"image",
"->",
"insert",
"(",
"$",
"watermark",
",",
"$",
"markpos",
",",
"intval",
"(",
"$",
"markx",
")",
",",
"intval",
"(",
"$",
"marky",
")",
")",
";",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform watermark image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"watermark",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Watermark.php#L87-L119 | train |
thephpleague/glide | src/Manipulators/Watermark.php | Watermark.getImage | public function getImage(Image $image)
{
if (is_null($this->watermarks)) {
return;
}
if (!is_string($this->mark)) {
return;
}
if ($this->mark === '') {
return;
}
$path = $this->mark;
if ($this->watermarksPathPrefix) {
$path = $this->watermarksPathPrefix.'/'.$path;
}
if ($this->watermarks->has($path)) {
$source = $this->watermarks->read($path);
if ($source === false) {
throw new FilesystemException(
'Could not read the image `'.$path.'`.'
);
}
return $image->getDriver()->init($source);
}
} | php | public function getImage(Image $image)
{
if (is_null($this->watermarks)) {
return;
}
if (!is_string($this->mark)) {
return;
}
if ($this->mark === '') {
return;
}
$path = $this->mark;
if ($this->watermarksPathPrefix) {
$path = $this->watermarksPathPrefix.'/'.$path;
}
if ($this->watermarks->has($path)) {
$source = $this->watermarks->read($path);
if ($source === false) {
throw new FilesystemException(
'Could not read the image `'.$path.'`.'
);
}
return $image->getDriver()->init($source);
}
} | [
"public",
"function",
"getImage",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"watermarks",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"this",
"->",
"mark",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"mark",
"===",
"''",
")",
"{",
"return",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"mark",
";",
"if",
"(",
"$",
"this",
"->",
"watermarksPathPrefix",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"watermarksPathPrefix",
".",
"'/'",
".",
"$",
"path",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"watermarks",
"->",
"has",
"(",
"$",
"path",
")",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"watermarks",
"->",
"read",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"source",
"===",
"false",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"'Could not read the image `'",
".",
"$",
"path",
".",
"'`.'",
")",
";",
"}",
"return",
"$",
"image",
"->",
"getDriver",
"(",
")",
"->",
"init",
"(",
"$",
"source",
")",
";",
"}",
"}"
] | Get the watermark image.
@param Image $image The source image.
@return Image|null The watermark image. | [
"Get",
"the",
"watermark",
"image",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Watermark.php#L126-L157 | train |
thephpleague/glide | src/Manipulators/Watermark.php | Watermark.getDimension | public function getDimension(Image $image, $field)
{
if ($this->{$field}) {
return (new Dimension($image, $this->getDpr()))->get($this->{$field});
}
} | php | public function getDimension(Image $image, $field)
{
if ($this->{$field}) {
return (new Dimension($image, $this->getDpr()))->get($this->{$field});
}
} | [
"public",
"function",
"getDimension",
"(",
"Image",
"$",
"image",
",",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"{",
"$",
"field",
"}",
")",
"{",
"return",
"(",
"new",
"Dimension",
"(",
"$",
"image",
",",
"$",
"this",
"->",
"getDpr",
"(",
")",
")",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"{",
"$",
"field",
"}",
")",
";",
"}",
"}"
] | Get a dimension.
@param Image $image The source image.
@param string $field The requested field.
@return double|null The dimension. | [
"Get",
"a",
"dimension",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Watermark.php#L165-L170 | train |
thephpleague/glide | src/Manipulators/Watermark.php | Watermark.getAlpha | public function getAlpha()
{
if (!is_numeric($this->markalpha)) {
return 100;
}
if ($this->markalpha < 0 or $this->markalpha > 100) {
return 100;
}
return (int) $this->markalpha;
} | php | public function getAlpha()
{
if (!is_numeric($this->markalpha)) {
return 100;
}
if ($this->markalpha < 0 or $this->markalpha > 100) {
return 100;
}
return (int) $this->markalpha;
} | [
"public",
"function",
"getAlpha",
"(",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"markalpha",
")",
")",
"{",
"return",
"100",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"markalpha",
"<",
"0",
"or",
"$",
"this",
"->",
"markalpha",
">",
"100",
")",
"{",
"return",
"100",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"markalpha",
";",
"}"
] | Get the alpha channel.
@return int The alpha. | [
"Get",
"the",
"alpha",
"channel",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Watermark.php#L245-L256 | train |
thephpleague/glide | src/Server.php | Server.getSourcePath | public function getSourcePath($path)
{
$path = trim($path, '/');
$baseUrl = $this->baseUrl.'/';
if (substr($path, 0, strlen($baseUrl)) === $baseUrl) {
$path = trim(substr($path, strlen($baseUrl)), '/');
}
if ($path === '') {
throw new FileNotFoundException('Image path missing.');
}
if ($this->sourcePathPrefix) {
$path = $this->sourcePathPrefix.'/'.$path;
}
return rawurldecode($path);
} | php | public function getSourcePath($path)
{
$path = trim($path, '/');
$baseUrl = $this->baseUrl.'/';
if (substr($path, 0, strlen($baseUrl)) === $baseUrl) {
$path = trim(substr($path, strlen($baseUrl)), '/');
}
if ($path === '') {
throw new FileNotFoundException('Image path missing.');
}
if ($this->sourcePathPrefix) {
$path = $this->sourcePathPrefix.'/'.$path;
}
return rawurldecode($path);
} | [
"public",
"function",
"getSourcePath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"baseUrl",
"=",
"$",
"this",
"->",
"baseUrl",
".",
"'/'",
";",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"strlen",
"(",
"$",
"baseUrl",
")",
")",
"===",
"$",
"baseUrl",
")",
"{",
"$",
"path",
"=",
"trim",
"(",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"baseUrl",
")",
")",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"$",
"path",
"===",
"''",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"'Image path missing.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"sourcePathPrefix",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"sourcePathPrefix",
".",
"'/'",
".",
"$",
"path",
";",
"}",
"return",
"rawurldecode",
"(",
"$",
"path",
")",
";",
"}"
] | Get source path.
@param string $path Image path.
@return string The source path.
@throws FileNotFoundException | [
"Get",
"source",
"path",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Server.php#L136-L155 | train |
thephpleague/glide | src/Server.php | Server.getCachePath | public function getCachePath($path, array $params = [])
{
$sourcePath = $this->getSourcePath($path);
if ($this->sourcePathPrefix) {
$sourcePath = substr($sourcePath, strlen($this->sourcePathPrefix) + 1);
}
$params = $this->getAllParams($params);
unset($params['s'], $params['p']);
ksort($params);
$md5 = md5($sourcePath.'?'.http_build_query($params));
$cachedPath = $this->groupCacheInFolders ? $sourcePath.'/'.$md5 : $md5;
if ($this->cachePathPrefix) {
$cachedPath = $this->cachePathPrefix.'/'.$cachedPath;
}
if ($this->cacheWithFileExtensions) {
$ext = (isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']);
$ext = ($ext === 'pjpg') ? 'jpg' : $ext;
$cachedPath .= '.'.$ext;
}
return $cachedPath;
} | php | public function getCachePath($path, array $params = [])
{
$sourcePath = $this->getSourcePath($path);
if ($this->sourcePathPrefix) {
$sourcePath = substr($sourcePath, strlen($this->sourcePathPrefix) + 1);
}
$params = $this->getAllParams($params);
unset($params['s'], $params['p']);
ksort($params);
$md5 = md5($sourcePath.'?'.http_build_query($params));
$cachedPath = $this->groupCacheInFolders ? $sourcePath.'/'.$md5 : $md5;
if ($this->cachePathPrefix) {
$cachedPath = $this->cachePathPrefix.'/'.$cachedPath;
}
if ($this->cacheWithFileExtensions) {
$ext = (isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']);
$ext = ($ext === 'pjpg') ? 'jpg' : $ext;
$cachedPath .= '.'.$ext;
}
return $cachedPath;
} | [
"public",
"function",
"getCachePath",
"(",
"$",
"path",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"sourcePath",
"=",
"$",
"this",
"->",
"getSourcePath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"this",
"->",
"sourcePathPrefix",
")",
"{",
"$",
"sourcePath",
"=",
"substr",
"(",
"$",
"sourcePath",
",",
"strlen",
"(",
"$",
"this",
"->",
"sourcePathPrefix",
")",
"+",
"1",
")",
";",
"}",
"$",
"params",
"=",
"$",
"this",
"->",
"getAllParams",
"(",
"$",
"params",
")",
";",
"unset",
"(",
"$",
"params",
"[",
"'s'",
"]",
",",
"$",
"params",
"[",
"'p'",
"]",
")",
";",
"ksort",
"(",
"$",
"params",
")",
";",
"$",
"md5",
"=",
"md5",
"(",
"$",
"sourcePath",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
")",
")",
";",
"$",
"cachedPath",
"=",
"$",
"this",
"->",
"groupCacheInFolders",
"?",
"$",
"sourcePath",
".",
"'/'",
".",
"$",
"md5",
":",
"$",
"md5",
";",
"if",
"(",
"$",
"this",
"->",
"cachePathPrefix",
")",
"{",
"$",
"cachedPath",
"=",
"$",
"this",
"->",
"cachePathPrefix",
".",
"'/'",
".",
"$",
"cachedPath",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cacheWithFileExtensions",
")",
"{",
"$",
"ext",
"=",
"(",
"isset",
"(",
"$",
"params",
"[",
"'fm'",
"]",
")",
"?",
"$",
"params",
"[",
"'fm'",
"]",
":",
"pathinfo",
"(",
"$",
"path",
")",
"[",
"'extension'",
"]",
")",
";",
"$",
"ext",
"=",
"(",
"$",
"ext",
"===",
"'pjpg'",
")",
"?",
"'jpg'",
":",
"$",
"ext",
";",
"$",
"cachedPath",
".=",
"'.'",
".",
"$",
"ext",
";",
"}",
"return",
"$",
"cachedPath",
";",
"}"
] | Get cache path.
@param string $path Image path.
@param array $params Image manipulation params.
@return string Cache path. | [
"Get",
"cache",
"path",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Server.php#L263-L290 | train |
thephpleague/glide | src/Server.php | Server.cacheFileExists | public function cacheFileExists($path, array $params)
{
return $this->cache->has(
$this->getCachePath($path, $params)
);
} | php | public function cacheFileExists($path, array $params)
{
return $this->cache->has(
$this->getCachePath($path, $params)
);
} | [
"public",
"function",
"cacheFileExists",
"(",
"$",
"path",
",",
"array",
"$",
"params",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"->",
"has",
"(",
"$",
"this",
"->",
"getCachePath",
"(",
"$",
"path",
",",
"$",
"params",
")",
")",
";",
"}"
] | Check if a cache file exists.
@param string $path Image path.
@param array $params Image manipulation params.
@return bool Whether the cache file exists. | [
"Check",
"if",
"a",
"cache",
"file",
"exists",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Server.php#L298-L303 | train |
thephpleague/glide | src/Server.php | Server.deleteCache | public function deleteCache($path)
{
if (!$this->groupCacheInFolders) {
throw new InvalidArgumentException(
'Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'
);
}
return $this->cache->deleteDir(
dirname($this->getCachePath($path))
);
} | php | public function deleteCache($path)
{
if (!$this->groupCacheInFolders) {
throw new InvalidArgumentException(
'Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'
);
}
return $this->cache->deleteDir(
dirname($this->getCachePath($path))
);
} | [
"public",
"function",
"deleteCache",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"groupCacheInFolders",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cache",
"->",
"deleteDir",
"(",
"dirname",
"(",
"$",
"this",
"->",
"getCachePath",
"(",
"$",
"path",
")",
")",
")",
";",
"}"
] | Delete cached manipulations for an image.
@param string $path Image path.
@return bool Whether the delete succeeded. | [
"Delete",
"cached",
"manipulations",
"for",
"an",
"image",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Server.php#L310-L321 | train |
thephpleague/glide | src/Server.php | Server.getAllParams | public function getAllParams(array $params)
{
$all = $this->defaults;
if (isset($params['p'])) {
foreach (explode(',', $params['p']) as $preset) {
if (isset($this->presets[$preset])) {
$all = array_merge($all, $this->presets[$preset]);
}
}
}
return array_merge($all, $params);
} | php | public function getAllParams(array $params)
{
$all = $this->defaults;
if (isset($params['p'])) {
foreach (explode(',', $params['p']) as $preset) {
if (isset($this->presets[$preset])) {
$all = array_merge($all, $this->presets[$preset]);
}
}
}
return array_merge($all, $params);
} | [
"public",
"function",
"getAllParams",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"all",
"=",
"$",
"this",
"->",
"defaults",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'p'",
"]",
")",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"params",
"[",
"'p'",
"]",
")",
"as",
"$",
"preset",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"presets",
"[",
"$",
"preset",
"]",
")",
")",
"{",
"$",
"all",
"=",
"array_merge",
"(",
"$",
"all",
",",
"$",
"this",
"->",
"presets",
"[",
"$",
"preset",
"]",
")",
";",
"}",
"}",
"}",
"return",
"array_merge",
"(",
"$",
"all",
",",
"$",
"params",
")",
";",
"}"
] | Get all image manipulations params, including defaults and presets.
@param array $params Image manipulation params.
@return array All image manipulation params. | [
"Get",
"all",
"image",
"manipulations",
"params",
"including",
"defaults",
"and",
"presets",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Server.php#L382-L395 | train |
thephpleague/glide | src/Server.php | Server.makeImage | public function makeImage($path, array $params)
{
$sourcePath = $this->getSourcePath($path);
$cachedPath = $this->getCachePath($path, $params);
if ($this->cacheFileExists($path, $params) === true) {
return $cachedPath;
}
if ($this->sourceFileExists($path) === false) {
throw new FileNotFoundException(
'Could not find the image `'.$sourcePath.'`.'
);
}
$source = $this->source->read(
$sourcePath
);
if ($source === false) {
throw new FilesystemException(
'Could not read the image `'.$sourcePath.'`.'
);
}
// We need to write the image to the local disk before
// doing any manipulations. This is because EXIF data
// can only be read from an actual file.
$tmp = tempnam(sys_get_temp_dir(), 'Glide');
if (file_put_contents($tmp, $source) === false) {
throw new FilesystemException(
'Unable to write temp file for `'.$sourcePath.'`.'
);
}
try {
$write = $this->cache->write(
$cachedPath,
$this->api->run($tmp, $this->getAllParams($params))
);
if ($write === false) {
throw new FilesystemException(
'Could not write the image `'.$cachedPath.'`.'
);
}
} catch (FileExistsException $exception) {
// This edge case occurs when the target already exists
// because it's currently be written to disk in another
// request. It's best to just fail silently.
} finally {
unlink($tmp);
}
return $cachedPath;
} | php | public function makeImage($path, array $params)
{
$sourcePath = $this->getSourcePath($path);
$cachedPath = $this->getCachePath($path, $params);
if ($this->cacheFileExists($path, $params) === true) {
return $cachedPath;
}
if ($this->sourceFileExists($path) === false) {
throw new FileNotFoundException(
'Could not find the image `'.$sourcePath.'`.'
);
}
$source = $this->source->read(
$sourcePath
);
if ($source === false) {
throw new FilesystemException(
'Could not read the image `'.$sourcePath.'`.'
);
}
// We need to write the image to the local disk before
// doing any manipulations. This is because EXIF data
// can only be read from an actual file.
$tmp = tempnam(sys_get_temp_dir(), 'Glide');
if (file_put_contents($tmp, $source) === false) {
throw new FilesystemException(
'Unable to write temp file for `'.$sourcePath.'`.'
);
}
try {
$write = $this->cache->write(
$cachedPath,
$this->api->run($tmp, $this->getAllParams($params))
);
if ($write === false) {
throw new FilesystemException(
'Could not write the image `'.$cachedPath.'`.'
);
}
} catch (FileExistsException $exception) {
// This edge case occurs when the target already exists
// because it's currently be written to disk in another
// request. It's best to just fail silently.
} finally {
unlink($tmp);
}
return $cachedPath;
} | [
"public",
"function",
"makeImage",
"(",
"$",
"path",
",",
"array",
"$",
"params",
")",
"{",
"$",
"sourcePath",
"=",
"$",
"this",
"->",
"getSourcePath",
"(",
"$",
"path",
")",
";",
"$",
"cachedPath",
"=",
"$",
"this",
"->",
"getCachePath",
"(",
"$",
"path",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cacheFileExists",
"(",
"$",
"path",
",",
"$",
"params",
")",
"===",
"true",
")",
"{",
"return",
"$",
"cachedPath",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"sourceFileExists",
"(",
"$",
"path",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"'Could not find the image `'",
".",
"$",
"sourcePath",
".",
"'`.'",
")",
";",
"}",
"$",
"source",
"=",
"$",
"this",
"->",
"source",
"->",
"read",
"(",
"$",
"sourcePath",
")",
";",
"if",
"(",
"$",
"source",
"===",
"false",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"'Could not read the image `'",
".",
"$",
"sourcePath",
".",
"'`.'",
")",
";",
"}",
"// We need to write the image to the local disk before",
"// doing any manipulations. This is because EXIF data",
"// can only be read from an actual file.",
"$",
"tmp",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'Glide'",
")",
";",
"if",
"(",
"file_put_contents",
"(",
"$",
"tmp",
",",
"$",
"source",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"'Unable to write temp file for `'",
".",
"$",
"sourcePath",
".",
"'`.'",
")",
";",
"}",
"try",
"{",
"$",
"write",
"=",
"$",
"this",
"->",
"cache",
"->",
"write",
"(",
"$",
"cachedPath",
",",
"$",
"this",
"->",
"api",
"->",
"run",
"(",
"$",
"tmp",
",",
"$",
"this",
"->",
"getAllParams",
"(",
"$",
"params",
")",
")",
")",
";",
"if",
"(",
"$",
"write",
"===",
"false",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"'Could not write the image `'",
".",
"$",
"cachedPath",
".",
"'`.'",
")",
";",
"}",
"}",
"catch",
"(",
"FileExistsException",
"$",
"exception",
")",
"{",
"// This edge case occurs when the target already exists",
"// because it's currently be written to disk in another",
"// request. It's best to just fail silently.",
"}",
"finally",
"{",
"unlink",
"(",
"$",
"tmp",
")",
";",
"}",
"return",
"$",
"cachedPath",
";",
"}"
] | Generate manipulated image.
@param string $path Image path.
@param array $params Image manipulation params.
@return string Cache path.
@throws FileNotFoundException
@throws FilesystemException | [
"Generate",
"manipulated",
"image",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Server.php#L489-L545 | train |
thephpleague/glide | src/Manipulators/Border.php | Border.run | public function run(Image $image)
{
if ($border = $this->getBorder($image)) {
list($width, $color, $method) = $border;
if ($method === 'overlay') {
return $this->runOverlay($image, $width, $color);
}
if ($method === 'shrink') {
return $this->runShrink($image, $width, $color);
}
if ($method === 'expand') {
return $this->runExpand($image, $width, $color);
}
}
return $image;
} | php | public function run(Image $image)
{
if ($border = $this->getBorder($image)) {
list($width, $color, $method) = $border;
if ($method === 'overlay') {
return $this->runOverlay($image, $width, $color);
}
if ($method === 'shrink') {
return $this->runShrink($image, $width, $color);
}
if ($method === 'expand') {
return $this->runExpand($image, $width, $color);
}
}
return $image;
} | [
"public",
"function",
"run",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"$",
"border",
"=",
"$",
"this",
"->",
"getBorder",
"(",
"$",
"image",
")",
")",
"{",
"list",
"(",
"$",
"width",
",",
"$",
"color",
",",
"$",
"method",
")",
"=",
"$",
"border",
";",
"if",
"(",
"$",
"method",
"===",
"'overlay'",
")",
"{",
"return",
"$",
"this",
"->",
"runOverlay",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"color",
")",
";",
"}",
"if",
"(",
"$",
"method",
"===",
"'shrink'",
")",
"{",
"return",
"$",
"this",
"->",
"runShrink",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"color",
")",
";",
"}",
"if",
"(",
"$",
"method",
"===",
"'expand'",
")",
"{",
"return",
"$",
"this",
"->",
"runExpand",
"(",
"$",
"image",
",",
"$",
"width",
",",
"$",
"color",
")",
";",
"}",
"}",
"return",
"$",
"image",
";",
"}"
] | Perform border image manipulation.
@param Image $image The source image.
@return Image The manipulated image. | [
"Perform",
"border",
"image",
"manipulation",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Border.php#L20-L39 | train |
thephpleague/glide | src/Manipulators/Border.php | Border.getBorder | public function getBorder(Image $image)
{
if (!$this->border) {
return;
}
$values = explode(',', $this->border);
$width = $this->getWidth($image, $this->getDpr(), isset($values[0]) ? $values[0] : null);
$color = $this->getColor(isset($values[1]) ? $values[1] : null);
$method = $this->getMethod(isset($values[2]) ? $values[2] : null);
if ($width) {
return [$width, $color, $method];
}
} | php | public function getBorder(Image $image)
{
if (!$this->border) {
return;
}
$values = explode(',', $this->border);
$width = $this->getWidth($image, $this->getDpr(), isset($values[0]) ? $values[0] : null);
$color = $this->getColor(isset($values[1]) ? $values[1] : null);
$method = $this->getMethod(isset($values[2]) ? $values[2] : null);
if ($width) {
return [$width, $color, $method];
}
} | [
"public",
"function",
"getBorder",
"(",
"Image",
"$",
"image",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"border",
")",
"{",
"return",
";",
"}",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"border",
")",
";",
"$",
"width",
"=",
"$",
"this",
"->",
"getWidth",
"(",
"$",
"image",
",",
"$",
"this",
"->",
"getDpr",
"(",
")",
",",
"isset",
"(",
"$",
"values",
"[",
"0",
"]",
")",
"?",
"$",
"values",
"[",
"0",
"]",
":",
"null",
")",
";",
"$",
"color",
"=",
"$",
"this",
"->",
"getColor",
"(",
"isset",
"(",
"$",
"values",
"[",
"1",
"]",
")",
"?",
"$",
"values",
"[",
"1",
"]",
":",
"null",
")",
";",
"$",
"method",
"=",
"$",
"this",
"->",
"getMethod",
"(",
"isset",
"(",
"$",
"values",
"[",
"2",
"]",
")",
"?",
"$",
"values",
"[",
"2",
"]",
":",
"null",
")",
";",
"if",
"(",
"$",
"width",
")",
"{",
"return",
"[",
"$",
"width",
",",
"$",
"color",
",",
"$",
"method",
"]",
";",
"}",
"}"
] | Resolve border amount.
@param Image $image The source image.
@return string The resolved border amount. | [
"Resolve",
"border",
"amount",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Border.php#L46-L61 | train |
thephpleague/glide | src/Manipulators/Border.php | Border.getWidth | public function getWidth(Image $image, $dpr, $width)
{
return (new Dimension($image, $dpr))->get($width);
} | php | public function getWidth(Image $image, $dpr, $width)
{
return (new Dimension($image, $dpr))->get($width);
} | [
"public",
"function",
"getWidth",
"(",
"Image",
"$",
"image",
",",
"$",
"dpr",
",",
"$",
"width",
")",
"{",
"return",
"(",
"new",
"Dimension",
"(",
"$",
"image",
",",
"$",
"dpr",
")",
")",
"->",
"get",
"(",
"$",
"width",
")",
";",
"}"
] | Get border width.
@param Image $image The source image.
@param double $dpr The device pixel ratio.
@param string $width The border width.
@return double The resolved border width. | [
"Get",
"border",
"width",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Border.php#L70-L73 | train |
thephpleague/glide | src/Manipulators/Border.php | Border.runOverlay | public function runOverlay(Image $image, $width, $color)
{
return $image->rectangle(
$width / 2,
$width / 2,
$image->width() - ($width / 2),
$image->height() - ($width / 2),
function ($draw) use ($width, $color) {
$draw->border($width, $color);
}
);
} | php | public function runOverlay(Image $image, $width, $color)
{
return $image->rectangle(
$width / 2,
$width / 2,
$image->width() - ($width / 2),
$image->height() - ($width / 2),
function ($draw) use ($width, $color) {
$draw->border($width, $color);
}
);
} | [
"public",
"function",
"runOverlay",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"color",
")",
"{",
"return",
"$",
"image",
"->",
"rectangle",
"(",
"$",
"width",
"/",
"2",
",",
"$",
"width",
"/",
"2",
",",
"$",
"image",
"->",
"width",
"(",
")",
"-",
"(",
"$",
"width",
"/",
"2",
")",
",",
"$",
"image",
"->",
"height",
"(",
")",
"-",
"(",
"$",
"width",
"/",
"2",
")",
",",
"function",
"(",
"$",
"draw",
")",
"use",
"(",
"$",
"width",
",",
"$",
"color",
")",
"{",
"$",
"draw",
"->",
"border",
"(",
"$",
"width",
",",
"$",
"color",
")",
";",
"}",
")",
";",
"}"
] | Run the overlay border method.
@param Image $image The source image.
@param double $width The border width.
@param string $color The border color.
@return Image The manipulated image. | [
"Run",
"the",
"overlay",
"border",
"method",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Border.php#L123-L134 | train |
thephpleague/glide | src/Manipulators/Border.php | Border.runShrink | public function runShrink(Image $image, $width, $color)
{
return $image
->resize(
$image->width() - ($width * 2),
$image->height() - ($width * 2)
)
->resizeCanvas(
$width * 2,
$width * 2,
'center',
true,
$color
);
} | php | public function runShrink(Image $image, $width, $color)
{
return $image
->resize(
$image->width() - ($width * 2),
$image->height() - ($width * 2)
)
->resizeCanvas(
$width * 2,
$width * 2,
'center',
true,
$color
);
} | [
"public",
"function",
"runShrink",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"color",
")",
"{",
"return",
"$",
"image",
"->",
"resize",
"(",
"$",
"image",
"->",
"width",
"(",
")",
"-",
"(",
"$",
"width",
"*",
"2",
")",
",",
"$",
"image",
"->",
"height",
"(",
")",
"-",
"(",
"$",
"width",
"*",
"2",
")",
")",
"->",
"resizeCanvas",
"(",
"$",
"width",
"*",
"2",
",",
"$",
"width",
"*",
"2",
",",
"'center'",
",",
"true",
",",
"$",
"color",
")",
";",
"}"
] | Run the shrink border method.
@param Image $image The source image.
@param double $width The border width.
@param string $color The border color.
@return Image The manipulated image. | [
"Run",
"the",
"shrink",
"border",
"method",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Border.php#L143-L157 | train |
thephpleague/glide | src/Manipulators/Border.php | Border.runExpand | public function runExpand(Image $image, $width, $color)
{
return $image->resizeCanvas(
$width * 2,
$width * 2,
'center',
true,
$color
);
} | php | public function runExpand(Image $image, $width, $color)
{
return $image->resizeCanvas(
$width * 2,
$width * 2,
'center',
true,
$color
);
} | [
"public",
"function",
"runExpand",
"(",
"Image",
"$",
"image",
",",
"$",
"width",
",",
"$",
"color",
")",
"{",
"return",
"$",
"image",
"->",
"resizeCanvas",
"(",
"$",
"width",
"*",
"2",
",",
"$",
"width",
"*",
"2",
",",
"'center'",
",",
"true",
",",
"$",
"color",
")",
";",
"}"
] | Run the expand border method.
@param Image $image The source image.
@param double $width The border width.
@param string $color The border color.
@return Image The manipulated image. | [
"Run",
"the",
"expand",
"border",
"method",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Manipulators/Border.php#L166-L175 | train |
thephpleague/glide | src/Urls/UrlBuilder.php | UrlBuilder.setBaseUrl | public function setBaseUrl($baseUrl)
{
if (substr($baseUrl, 0, 2) === '//') {
$baseUrl = 'http:'.$baseUrl;
$this->isRelativeDomain = true;
}
$this->baseUrl = rtrim($baseUrl, '/');
} | php | public function setBaseUrl($baseUrl)
{
if (substr($baseUrl, 0, 2) === '//') {
$baseUrl = 'http:'.$baseUrl;
$this->isRelativeDomain = true;
}
$this->baseUrl = rtrim($baseUrl, '/');
} | [
"public",
"function",
"setBaseUrl",
"(",
"$",
"baseUrl",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"baseUrl",
",",
"0",
",",
"2",
")",
"===",
"'//'",
")",
"{",
"$",
"baseUrl",
"=",
"'http:'",
".",
"$",
"baseUrl",
";",
"$",
"this",
"->",
"isRelativeDomain",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"baseUrl",
"=",
"rtrim",
"(",
"$",
"baseUrl",
",",
"'/'",
")",
";",
"}"
] | Set the base URL.
@param string $baseUrl The base URL. | [
"Set",
"the",
"base",
"URL",
"."
] | b97616835ee2a5ef3d600177a66c4bd68cce2170 | https://github.com/thephpleague/glide/blob/b97616835ee2a5ef3d600177a66c4bd68cce2170/src/Urls/UrlBuilder.php#L43-L51 | train |
sonata-project/SonataAdminBundle | src/Menu/MenuBuilder.php | MenuBuilder.createSidebarMenu | public function createSidebarMenu()
{
$menu = $this->factory->createItem('root');
foreach ($this->pool->getAdminGroups() as $name => $group) {
$extras = [
'icon' => $group['icon'],
'label_catalogue' => $group['label_catalogue'],
'roles' => $group['roles'],
'sonata_admin' => true,
];
$menuProvider = $group['provider'] ?? 'sonata_group_menu';
$subMenu = $this->provider->get(
$menuProvider,
[
'name' => $name,
'group' => $group,
]
);
$subMenu = $menu->addChild($subMenu);
$subMenu->setExtras(array_merge($subMenu->getExtras(), $extras));
}
$event = new ConfigureMenuEvent($this->factory, $menu);
$this->eventDispatcher->dispatch(ConfigureMenuEvent::SIDEBAR, $event);
return $event->getMenu();
} | php | public function createSidebarMenu()
{
$menu = $this->factory->createItem('root');
foreach ($this->pool->getAdminGroups() as $name => $group) {
$extras = [
'icon' => $group['icon'],
'label_catalogue' => $group['label_catalogue'],
'roles' => $group['roles'],
'sonata_admin' => true,
];
$menuProvider = $group['provider'] ?? 'sonata_group_menu';
$subMenu = $this->provider->get(
$menuProvider,
[
'name' => $name,
'group' => $group,
]
);
$subMenu = $menu->addChild($subMenu);
$subMenu->setExtras(array_merge($subMenu->getExtras(), $extras));
}
$event = new ConfigureMenuEvent($this->factory, $menu);
$this->eventDispatcher->dispatch(ConfigureMenuEvent::SIDEBAR, $event);
return $event->getMenu();
} | [
"public",
"function",
"createSidebarMenu",
"(",
")",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"factory",
"->",
"createItem",
"(",
"'root'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"pool",
"->",
"getAdminGroups",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"group",
")",
"{",
"$",
"extras",
"=",
"[",
"'icon'",
"=>",
"$",
"group",
"[",
"'icon'",
"]",
",",
"'label_catalogue'",
"=>",
"$",
"group",
"[",
"'label_catalogue'",
"]",
",",
"'roles'",
"=>",
"$",
"group",
"[",
"'roles'",
"]",
",",
"'sonata_admin'",
"=>",
"true",
",",
"]",
";",
"$",
"menuProvider",
"=",
"$",
"group",
"[",
"'provider'",
"]",
"??",
"'sonata_group_menu'",
";",
"$",
"subMenu",
"=",
"$",
"this",
"->",
"provider",
"->",
"get",
"(",
"$",
"menuProvider",
",",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'group'",
"=>",
"$",
"group",
",",
"]",
")",
";",
"$",
"subMenu",
"=",
"$",
"menu",
"->",
"addChild",
"(",
"$",
"subMenu",
")",
";",
"$",
"subMenu",
"->",
"setExtras",
"(",
"array_merge",
"(",
"$",
"subMenu",
"->",
"getExtras",
"(",
")",
",",
"$",
"extras",
")",
")",
";",
"}",
"$",
"event",
"=",
"new",
"ConfigureMenuEvent",
"(",
"$",
"this",
"->",
"factory",
",",
"$",
"menu",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"ConfigureMenuEvent",
"::",
"SIDEBAR",
",",
"$",
"event",
")",
";",
"return",
"$",
"event",
"->",
"getMenu",
"(",
")",
";",
"}"
] | Builds sidebar menu.
@return ItemInterface | [
"Builds",
"sidebar",
"menu",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Menu/MenuBuilder.php#L68-L97 | train |
sonata-project/SonataAdminBundle | src/Mapper/BaseGroupedMapper.php | BaseGroupedMapper.ifTrue | public function ifTrue($bool)
{
if (null !== $this->apply) {
throw new \RuntimeException('Cannot nest ifTrue or ifFalse call');
}
$this->apply = (true === $bool);
return $this;
} | php | public function ifTrue($bool)
{
if (null !== $this->apply) {
throw new \RuntimeException('Cannot nest ifTrue or ifFalse call');
}
$this->apply = (true === $bool);
return $this;
} | [
"public",
"function",
"ifTrue",
"(",
"$",
"bool",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"apply",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot nest ifTrue or ifFalse call'",
")",
";",
"}",
"$",
"this",
"->",
"apply",
"=",
"(",
"true",
"===",
"$",
"bool",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Only nested add if the condition match true.
@param bool $bool
@throws \RuntimeException
@return $this | [
"Only",
"nested",
"add",
"if",
"the",
"condition",
"match",
"true",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Mapper/BaseGroupedMapper.php#L166-L175 | train |
sonata-project/SonataAdminBundle | src/Mapper/BaseGroupedMapper.php | BaseGroupedMapper.ifFalse | public function ifFalse($bool)
{
if (null !== $this->apply) {
throw new \RuntimeException('Cannot nest ifTrue or ifFalse call');
}
$this->apply = (false === $bool);
return $this;
} | php | public function ifFalse($bool)
{
if (null !== $this->apply) {
throw new \RuntimeException('Cannot nest ifTrue or ifFalse call');
}
$this->apply = (false === $bool);
return $this;
} | [
"public",
"function",
"ifFalse",
"(",
"$",
"bool",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"apply",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot nest ifTrue or ifFalse call'",
")",
";",
"}",
"$",
"this",
"->",
"apply",
"=",
"(",
"false",
"===",
"$",
"bool",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Only nested add if the condition match false.
@param bool $bool
@throws \RuntimeException
@return $this | [
"Only",
"nested",
"add",
"if",
"the",
"condition",
"match",
"false",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Mapper/BaseGroupedMapper.php#L186-L195 | train |
sonata-project/SonataAdminBundle | src/Mapper/BaseGroupedMapper.php | BaseGroupedMapper.end | public function end()
{
if (null !== $this->currentGroup) {
$this->currentGroup = null;
} elseif (null !== $this->currentTab) {
$this->currentTab = null;
} else {
throw new \RuntimeException('No open tabs or groups, you cannot use end()');
}
return $this;
} | php | public function end()
{
if (null !== $this->currentGroup) {
$this->currentGroup = null;
} elseif (null !== $this->currentTab) {
$this->currentTab = null;
} else {
throw new \RuntimeException('No open tabs or groups, you cannot use end()');
}
return $this;
} | [
"public",
"function",
"end",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"currentGroup",
")",
"{",
"$",
"this",
"->",
"currentGroup",
"=",
"null",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"this",
"->",
"currentTab",
")",
"{",
"$",
"this",
"->",
"currentTab",
"=",
"null",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No open tabs or groups, you cannot use end()'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Close the current group or tab.
@throws \RuntimeException
@return $this | [
"Close",
"the",
"current",
"group",
"or",
"tab",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Mapper/BaseGroupedMapper.php#L226-L237 | train |
sonata-project/SonataAdminBundle | src/Mapper/BaseGroupedMapper.php | BaseGroupedMapper.addFieldToCurrentGroup | protected function addFieldToCurrentGroup($fieldName)
{
// Note this line must happen before the next line.
// See https://github.com/sonata-project/SonataAdminBundle/pull/1351
$currentGroup = $this->getCurrentGroupName();
$groups = $this->getGroups();
$groups[$currentGroup]['fields'][$fieldName] = $fieldName;
$this->setGroups($groups);
return $groups[$currentGroup];
} | php | protected function addFieldToCurrentGroup($fieldName)
{
// Note this line must happen before the next line.
// See https://github.com/sonata-project/SonataAdminBundle/pull/1351
$currentGroup = $this->getCurrentGroupName();
$groups = $this->getGroups();
$groups[$currentGroup]['fields'][$fieldName] = $fieldName;
$this->setGroups($groups);
return $groups[$currentGroup];
} | [
"protected",
"function",
"addFieldToCurrentGroup",
"(",
"$",
"fieldName",
")",
"{",
"// Note this line must happen before the next line.",
"// See https://github.com/sonata-project/SonataAdminBundle/pull/1351",
"$",
"currentGroup",
"=",
"$",
"this",
"->",
"getCurrentGroupName",
"(",
")",
";",
"$",
"groups",
"=",
"$",
"this",
"->",
"getGroups",
"(",
")",
";",
"$",
"groups",
"[",
"$",
"currentGroup",
"]",
"[",
"'fields'",
"]",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"fieldName",
";",
"$",
"this",
"->",
"setGroups",
"(",
"$",
"groups",
")",
";",
"return",
"$",
"groups",
"[",
"$",
"currentGroup",
"]",
";",
"}"
] | Add the field name to the current group.
@param string $fieldName | [
"Add",
"the",
"field",
"name",
"to",
"the",
"current",
"group",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Mapper/BaseGroupedMapper.php#L280-L290 | train |
sonata-project/SonataAdminBundle | src/Mapper/BaseGroupedMapper.php | BaseGroupedMapper.getCurrentGroupName | protected function getCurrentGroupName()
{
if (!$this->currentGroup) {
$this->with($this->admin->getLabel(), ['auto_created' => true]);
}
return $this->currentGroup;
} | php | protected function getCurrentGroupName()
{
if (!$this->currentGroup) {
$this->with($this->admin->getLabel(), ['auto_created' => true]);
}
return $this->currentGroup;
} | [
"protected",
"function",
"getCurrentGroupName",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"currentGroup",
")",
"{",
"$",
"this",
"->",
"with",
"(",
"$",
"this",
"->",
"admin",
"->",
"getLabel",
"(",
")",
",",
"[",
"'auto_created'",
"=>",
"true",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"currentGroup",
";",
"}"
] | Return the name of the currently selected group. The method also makes
sure a valid group name is currently selected.
Note that this can have the side effect to change the 'group' value
returned by the getGroup function
@return string | [
"Return",
"the",
"name",
"of",
"the",
"currently",
"selected",
"group",
".",
"The",
"method",
"also",
"makes",
"sure",
"a",
"valid",
"group",
"name",
"is",
"currently",
"selected",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Mapper/BaseGroupedMapper.php#L301-L308 | train |
sonata-project/SonataAdminBundle | src/Form/DataTransformer/ModelsToArrayTransformer.php | ModelsToArrayTransformer.legacyConstructor | private function legacyConstructor(array $args)
{
$choiceList = $args[0];
if (!$choiceList instanceof ModelChoiceList
&& !$choiceList instanceof ModelChoiceLoader
&& !$choiceList instanceof LazyChoiceList) {
throw new RuntimeException('First param passed to ModelsToArrayTransformer should be instance of
ModelChoiceLoader or ModelChoiceList or LazyChoiceList');
}
$this->choiceList = $choiceList;
$this->modelManager = $args[1];
$this->class = $args[2];
} | php | private function legacyConstructor(array $args)
{
$choiceList = $args[0];
if (!$choiceList instanceof ModelChoiceList
&& !$choiceList instanceof ModelChoiceLoader
&& !$choiceList instanceof LazyChoiceList) {
throw new RuntimeException('First param passed to ModelsToArrayTransformer should be instance of
ModelChoiceLoader or ModelChoiceList or LazyChoiceList');
}
$this->choiceList = $choiceList;
$this->modelManager = $args[1];
$this->class = $args[2];
} | [
"private",
"function",
"legacyConstructor",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"choiceList",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"$",
"choiceList",
"instanceof",
"ModelChoiceList",
"&&",
"!",
"$",
"choiceList",
"instanceof",
"ModelChoiceLoader",
"&&",
"!",
"$",
"choiceList",
"instanceof",
"LazyChoiceList",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'First param passed to ModelsToArrayTransformer should be instance of\n ModelChoiceLoader or ModelChoiceList or LazyChoiceList'",
")",
";",
"}",
"$",
"this",
"->",
"choiceList",
"=",
"$",
"choiceList",
";",
"$",
"this",
"->",
"modelManager",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"class",
"=",
"$",
"args",
"[",
"2",
"]",
";",
"}"
] | Simulates the old constructor for BC.
@throws RuntimeException | [
"Simulates",
"the",
"old",
"constructor",
"for",
"BC",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Form/DataTransformer/ModelsToArrayTransformer.php#L170-L184 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclManipulator.php | AdminObjectAclManipulator.createAclUsersForm | public function createAclUsersForm(AdminObjectAclData $data)
{
$aclValues = $data->getAclUsers();
$formBuilder = $this->formFactory->createNamedBuilder(self::ACL_USERS_FORM_NAME, FormType::class);
$form = $this->buildForm($data, $formBuilder, $aclValues);
$data->setAclUsersForm($form);
return $form;
} | php | public function createAclUsersForm(AdminObjectAclData $data)
{
$aclValues = $data->getAclUsers();
$formBuilder = $this->formFactory->createNamedBuilder(self::ACL_USERS_FORM_NAME, FormType::class);
$form = $this->buildForm($data, $formBuilder, $aclValues);
$data->setAclUsersForm($form);
return $form;
} | [
"public",
"function",
"createAclUsersForm",
"(",
"AdminObjectAclData",
"$",
"data",
")",
"{",
"$",
"aclValues",
"=",
"$",
"data",
"->",
"getAclUsers",
"(",
")",
";",
"$",
"formBuilder",
"=",
"$",
"this",
"->",
"formFactory",
"->",
"createNamedBuilder",
"(",
"self",
"::",
"ACL_USERS_FORM_NAME",
",",
"FormType",
"::",
"class",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"buildForm",
"(",
"$",
"data",
",",
"$",
"formBuilder",
",",
"$",
"aclValues",
")",
";",
"$",
"data",
"->",
"setAclUsersForm",
"(",
"$",
"form",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Gets the ACL users form.
@return Form | [
"Gets",
"the",
"ACL",
"users",
"form",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclManipulator.php#L91-L99 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclManipulator.php | AdminObjectAclManipulator.createAclRolesForm | public function createAclRolesForm(AdminObjectAclData $data)
{
$aclValues = $data->getAclRoles();
$formBuilder = $this->formFactory->createNamedBuilder(self::ACL_ROLES_FORM_NAME, FormType::class);
$form = $this->buildForm($data, $formBuilder, $aclValues);
$data->setAclRolesForm($form);
return $form;
} | php | public function createAclRolesForm(AdminObjectAclData $data)
{
$aclValues = $data->getAclRoles();
$formBuilder = $this->formFactory->createNamedBuilder(self::ACL_ROLES_FORM_NAME, FormType::class);
$form = $this->buildForm($data, $formBuilder, $aclValues);
$data->setAclRolesForm($form);
return $form;
} | [
"public",
"function",
"createAclRolesForm",
"(",
"AdminObjectAclData",
"$",
"data",
")",
"{",
"$",
"aclValues",
"=",
"$",
"data",
"->",
"getAclRoles",
"(",
")",
";",
"$",
"formBuilder",
"=",
"$",
"this",
"->",
"formFactory",
"->",
"createNamedBuilder",
"(",
"self",
"::",
"ACL_ROLES_FORM_NAME",
",",
"FormType",
"::",
"class",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"buildForm",
"(",
"$",
"data",
",",
"$",
"formBuilder",
",",
"$",
"aclValues",
")",
";",
"$",
"data",
"->",
"setAclRolesForm",
"(",
"$",
"form",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Gets the ACL roles form.
@return Form | [
"Gets",
"the",
"ACL",
"roles",
"form",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclManipulator.php#L106-L114 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclManipulator.php | AdminObjectAclManipulator.updateAclUsers | public function updateAclUsers(AdminObjectAclData $data)
{
$aclValues = $data->getAclUsers();
$form = $data->getAclUsersForm();
$this->buildAcl($data, $form, $aclValues);
} | php | public function updateAclUsers(AdminObjectAclData $data)
{
$aclValues = $data->getAclUsers();
$form = $data->getAclUsersForm();
$this->buildAcl($data, $form, $aclValues);
} | [
"public",
"function",
"updateAclUsers",
"(",
"AdminObjectAclData",
"$",
"data",
")",
"{",
"$",
"aclValues",
"=",
"$",
"data",
"->",
"getAclUsers",
"(",
")",
";",
"$",
"form",
"=",
"$",
"data",
"->",
"getAclUsersForm",
"(",
")",
";",
"$",
"this",
"->",
"buildAcl",
"(",
"$",
"data",
",",
"$",
"form",
",",
"$",
"aclValues",
")",
";",
"}"
] | Updates ACL users. | [
"Updates",
"ACL",
"users",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclManipulator.php#L119-L125 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclManipulator.php | AdminObjectAclManipulator.updateAclRoles | public function updateAclRoles(AdminObjectAclData $data)
{
$aclValues = $data->getAclRoles();
$form = $data->getAclRolesForm();
$this->buildAcl($data, $form, $aclValues);
} | php | public function updateAclRoles(AdminObjectAclData $data)
{
$aclValues = $data->getAclRoles();
$form = $data->getAclRolesForm();
$this->buildAcl($data, $form, $aclValues);
} | [
"public",
"function",
"updateAclRoles",
"(",
"AdminObjectAclData",
"$",
"data",
")",
"{",
"$",
"aclValues",
"=",
"$",
"data",
"->",
"getAclRoles",
"(",
")",
";",
"$",
"form",
"=",
"$",
"data",
"->",
"getAclRolesForm",
"(",
")",
";",
"$",
"this",
"->",
"buildAcl",
"(",
"$",
"data",
",",
"$",
"form",
",",
"$",
"aclValues",
")",
";",
"}"
] | Updates ACL roles. | [
"Updates",
"ACL",
"roles",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclManipulator.php#L130-L136 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclManipulator.php | AdminObjectAclManipulator.buildAcl | protected function buildAcl(AdminObjectAclData $data, Form $form, \Traversable $aclValues)
{
$masks = $data->getMasks();
$acl = $data->getAcl();
$matrices = $form->getData();
foreach ($aclValues as $aclValue) {
foreach ($matrices as $key => $matrix) {
if ($aclValue instanceof UserInterface) {
if (\array_key_exists('user', $matrix) && $aclValue->getUsername() === $matrix['user']) {
$matrices[$key]['acl_value'] = $aclValue;
}
} elseif (\array_key_exists('role', $matrix) && $aclValue === $matrix['role']) {
$matrices[$key]['acl_value'] = $aclValue;
}
}
}
foreach ($matrices as $matrix) {
if (!isset($matrix['acl_value'])) {
continue;
}
$securityIdentity = $this->getSecurityIdentity($matrix['acl_value']);
$maskBuilder = new $this->maskBuilderClass();
foreach ($data->getUserPermissions() as $permission) {
if (isset($matrix[$permission]) && true === $matrix[$permission]) {
$maskBuilder->add($permission);
}
}
// Restore OWNER and MASTER permissions
if (!$data->isOwner()) {
foreach ($data->getOwnerPermissions() as $permission) {
if ($acl->isGranted([$masks[$permission]], [$securityIdentity])) {
$maskBuilder->add($permission);
}
}
}
$mask = $maskBuilder->get();
$index = null;
$ace = null;
foreach ($acl->getObjectAces() as $currentIndex => $currentAce) {
if ($currentAce->getSecurityIdentity()->equals($securityIdentity)) {
$index = $currentIndex;
$ace = $currentAce;
break;
}
}
if ($ace) {
$acl->updateObjectAce($index, $mask);
} else {
$acl->insertObjectAce($securityIdentity, $mask);
}
}
$data->getSecurityHandler()->updateAcl($acl);
} | php | protected function buildAcl(AdminObjectAclData $data, Form $form, \Traversable $aclValues)
{
$masks = $data->getMasks();
$acl = $data->getAcl();
$matrices = $form->getData();
foreach ($aclValues as $aclValue) {
foreach ($matrices as $key => $matrix) {
if ($aclValue instanceof UserInterface) {
if (\array_key_exists('user', $matrix) && $aclValue->getUsername() === $matrix['user']) {
$matrices[$key]['acl_value'] = $aclValue;
}
} elseif (\array_key_exists('role', $matrix) && $aclValue === $matrix['role']) {
$matrices[$key]['acl_value'] = $aclValue;
}
}
}
foreach ($matrices as $matrix) {
if (!isset($matrix['acl_value'])) {
continue;
}
$securityIdentity = $this->getSecurityIdentity($matrix['acl_value']);
$maskBuilder = new $this->maskBuilderClass();
foreach ($data->getUserPermissions() as $permission) {
if (isset($matrix[$permission]) && true === $matrix[$permission]) {
$maskBuilder->add($permission);
}
}
// Restore OWNER and MASTER permissions
if (!$data->isOwner()) {
foreach ($data->getOwnerPermissions() as $permission) {
if ($acl->isGranted([$masks[$permission]], [$securityIdentity])) {
$maskBuilder->add($permission);
}
}
}
$mask = $maskBuilder->get();
$index = null;
$ace = null;
foreach ($acl->getObjectAces() as $currentIndex => $currentAce) {
if ($currentAce->getSecurityIdentity()->equals($securityIdentity)) {
$index = $currentIndex;
$ace = $currentAce;
break;
}
}
if ($ace) {
$acl->updateObjectAce($index, $mask);
} else {
$acl->insertObjectAce($securityIdentity, $mask);
}
}
$data->getSecurityHandler()->updateAcl($acl);
} | [
"protected",
"function",
"buildAcl",
"(",
"AdminObjectAclData",
"$",
"data",
",",
"Form",
"$",
"form",
",",
"\\",
"Traversable",
"$",
"aclValues",
")",
"{",
"$",
"masks",
"=",
"$",
"data",
"->",
"getMasks",
"(",
")",
";",
"$",
"acl",
"=",
"$",
"data",
"->",
"getAcl",
"(",
")",
";",
"$",
"matrices",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"foreach",
"(",
"$",
"aclValues",
"as",
"$",
"aclValue",
")",
"{",
"foreach",
"(",
"$",
"matrices",
"as",
"$",
"key",
"=>",
"$",
"matrix",
")",
"{",
"if",
"(",
"$",
"aclValue",
"instanceof",
"UserInterface",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"'user'",
",",
"$",
"matrix",
")",
"&&",
"$",
"aclValue",
"->",
"getUsername",
"(",
")",
"===",
"$",
"matrix",
"[",
"'user'",
"]",
")",
"{",
"$",
"matrices",
"[",
"$",
"key",
"]",
"[",
"'acl_value'",
"]",
"=",
"$",
"aclValue",
";",
"}",
"}",
"elseif",
"(",
"\\",
"array_key_exists",
"(",
"'role'",
",",
"$",
"matrix",
")",
"&&",
"$",
"aclValue",
"===",
"$",
"matrix",
"[",
"'role'",
"]",
")",
"{",
"$",
"matrices",
"[",
"$",
"key",
"]",
"[",
"'acl_value'",
"]",
"=",
"$",
"aclValue",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"matrices",
"as",
"$",
"matrix",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"matrix",
"[",
"'acl_value'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"securityIdentity",
"=",
"$",
"this",
"->",
"getSecurityIdentity",
"(",
"$",
"matrix",
"[",
"'acl_value'",
"]",
")",
";",
"$",
"maskBuilder",
"=",
"new",
"$",
"this",
"->",
"maskBuilderClass",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"getUserPermissions",
"(",
")",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"matrix",
"[",
"$",
"permission",
"]",
")",
"&&",
"true",
"===",
"$",
"matrix",
"[",
"$",
"permission",
"]",
")",
"{",
"$",
"maskBuilder",
"->",
"add",
"(",
"$",
"permission",
")",
";",
"}",
"}",
"// Restore OWNER and MASTER permissions",
"if",
"(",
"!",
"$",
"data",
"->",
"isOwner",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"->",
"getOwnerPermissions",
"(",
")",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"acl",
"->",
"isGranted",
"(",
"[",
"$",
"masks",
"[",
"$",
"permission",
"]",
"]",
",",
"[",
"$",
"securityIdentity",
"]",
")",
")",
"{",
"$",
"maskBuilder",
"->",
"add",
"(",
"$",
"permission",
")",
";",
"}",
"}",
"}",
"$",
"mask",
"=",
"$",
"maskBuilder",
"->",
"get",
"(",
")",
";",
"$",
"index",
"=",
"null",
";",
"$",
"ace",
"=",
"null",
";",
"foreach",
"(",
"$",
"acl",
"->",
"getObjectAces",
"(",
")",
"as",
"$",
"currentIndex",
"=>",
"$",
"currentAce",
")",
"{",
"if",
"(",
"$",
"currentAce",
"->",
"getSecurityIdentity",
"(",
")",
"->",
"equals",
"(",
"$",
"securityIdentity",
")",
")",
"{",
"$",
"index",
"=",
"$",
"currentIndex",
";",
"$",
"ace",
"=",
"$",
"currentAce",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"ace",
")",
"{",
"$",
"acl",
"->",
"updateObjectAce",
"(",
"$",
"index",
",",
"$",
"mask",
")",
";",
"}",
"else",
"{",
"$",
"acl",
"->",
"insertObjectAce",
"(",
"$",
"securityIdentity",
",",
"$",
"mask",
")",
";",
"}",
"}",
"$",
"data",
"->",
"getSecurityHandler",
"(",
")",
"->",
"updateAcl",
"(",
"$",
"acl",
")",
";",
"}"
] | Builds ACL. | [
"Builds",
"ACL",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclManipulator.php#L159-L221 | train |
sonata-project/SonataAdminBundle | src/DependencyInjection/Compiler/ExtensionCompilerPass.php | ExtensionCompilerPass.addExtension | private function addExtension(
array &$targets,
string $target,
string $extension,
array $attributes
): void {
if (!isset($targets[$target])) {
$targets[$target] = new \SplPriorityQueue();
}
$priority = $attributes['priority'] ?? 0;
$targets[$target]->insert(new Reference($extension), $priority);
} | php | private function addExtension(
array &$targets,
string $target,
string $extension,
array $attributes
): void {
if (!isset($targets[$target])) {
$targets[$target] = new \SplPriorityQueue();
}
$priority = $attributes['priority'] ?? 0;
$targets[$target]->insert(new Reference($extension), $priority);
} | [
"private",
"function",
"addExtension",
"(",
"array",
"&",
"$",
"targets",
",",
"string",
"$",
"target",
",",
"string",
"$",
"extension",
",",
"array",
"$",
"attributes",
")",
":",
"void",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"targets",
"[",
"$",
"target",
"]",
")",
")",
"{",
"$",
"targets",
"[",
"$",
"target",
"]",
"=",
"new",
"\\",
"SplPriorityQueue",
"(",
")",
";",
"}",
"$",
"priority",
"=",
"$",
"attributes",
"[",
"'priority'",
"]",
"??",
"0",
";",
"$",
"targets",
"[",
"$",
"target",
"]",
"->",
"insert",
"(",
"new",
"Reference",
"(",
"$",
"extension",
")",
",",
"$",
"priority",
")",
";",
"}"
] | Add extension configuration to the targets array. | [
"Add",
"extension",
"configuration",
"to",
"the",
"targets",
"array",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/DependencyInjection/Compiler/ExtensionCompilerPass.php#L218-L230 | train |
sonata-project/SonataAdminBundle | src/Admin/AdminHelper.php | AdminHelper.addNewInstance | public function addNewInstance($object, FieldDescriptionInterface $fieldDescription)
{
$instance = $fieldDescription->getAssociationAdmin()->getNewInstance();
$mapping = $fieldDescription->getAssociationMapping();
$method = sprintf('add%s', Inflector::classify($mapping['fieldName']));
if (!method_exists($object, $method)) {
$method = rtrim($method, 's');
if (!method_exists($object, $method)) {
$method = sprintf('add%s', Inflector::classify(Inflector::singularize($mapping['fieldName'])));
if (!method_exists($object, $method)) {
throw new \RuntimeException(
sprintf('Please add a method %s in the %s class!', $method, ClassUtils::getClass($object))
);
}
}
}
$object->$method($instance);
} | php | public function addNewInstance($object, FieldDescriptionInterface $fieldDescription)
{
$instance = $fieldDescription->getAssociationAdmin()->getNewInstance();
$mapping = $fieldDescription->getAssociationMapping();
$method = sprintf('add%s', Inflector::classify($mapping['fieldName']));
if (!method_exists($object, $method)) {
$method = rtrim($method, 's');
if (!method_exists($object, $method)) {
$method = sprintf('add%s', Inflector::classify(Inflector::singularize($mapping['fieldName'])));
if (!method_exists($object, $method)) {
throw new \RuntimeException(
sprintf('Please add a method %s in the %s class!', $method, ClassUtils::getClass($object))
);
}
}
}
$object->$method($instance);
} | [
"public",
"function",
"addNewInstance",
"(",
"$",
"object",
",",
"FieldDescriptionInterface",
"$",
"fieldDescription",
")",
"{",
"$",
"instance",
"=",
"$",
"fieldDescription",
"->",
"getAssociationAdmin",
"(",
")",
"->",
"getNewInstance",
"(",
")",
";",
"$",
"mapping",
"=",
"$",
"fieldDescription",
"->",
"getAssociationMapping",
"(",
")",
";",
"$",
"method",
"=",
"sprintf",
"(",
"'add%s'",
",",
"Inflector",
"::",
"classify",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"object",
",",
"$",
"method",
")",
")",
"{",
"$",
"method",
"=",
"rtrim",
"(",
"$",
"method",
",",
"'s'",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"object",
",",
"$",
"method",
")",
")",
"{",
"$",
"method",
"=",
"sprintf",
"(",
"'add%s'",
",",
"Inflector",
"::",
"classify",
"(",
"Inflector",
"::",
"singularize",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
")",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"object",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Please add a method %s in the %s class!'",
",",
"$",
"method",
",",
"ClassUtils",
"::",
"getClass",
"(",
"$",
"object",
")",
")",
")",
";",
"}",
"}",
"}",
"$",
"object",
"->",
"$",
"method",
"(",
"$",
"instance",
")",
";",
"}"
] | Add a new instance to the related FieldDescriptionInterface value.
@param object $object
@throws \RuntimeException | [
"Add",
"a",
"new",
"instance",
"to",
"the",
"related",
"FieldDescriptionInterface",
"value",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AdminHelper.php#L218-L240 | train |
sonata-project/SonataAdminBundle | src/Admin/AdminHelper.php | AdminHelper.getElementAccessPath | public function getElementAccessPath($elementId, $entity)
{
$propertyAccessor = $this->pool->getPropertyAccessor();
$idWithoutIdentifier = preg_replace('/^[^_]*_/', '', $elementId);
$initialPath = preg_replace('#(_(\d+)_)#', '[$2]_', $idWithoutIdentifier);
$parts = explode('_', $initialPath);
$totalPath = '';
$currentPath = '';
foreach ($parts as $part) {
$currentPath .= empty($currentPath) ? $part : '_'.$part;
$separator = empty($totalPath) ? '' : '.';
if ($propertyAccessor->isReadable($entity, $totalPath.$separator.$currentPath)) {
$totalPath .= $separator.$currentPath;
$currentPath = '';
}
}
if (!empty($currentPath)) {
throw new \Exception(
sprintf('Could not get element id from %s Failing part: %s', $elementId, $currentPath)
);
}
return $totalPath;
} | php | public function getElementAccessPath($elementId, $entity)
{
$propertyAccessor = $this->pool->getPropertyAccessor();
$idWithoutIdentifier = preg_replace('/^[^_]*_/', '', $elementId);
$initialPath = preg_replace('#(_(\d+)_)#', '[$2]_', $idWithoutIdentifier);
$parts = explode('_', $initialPath);
$totalPath = '';
$currentPath = '';
foreach ($parts as $part) {
$currentPath .= empty($currentPath) ? $part : '_'.$part;
$separator = empty($totalPath) ? '' : '.';
if ($propertyAccessor->isReadable($entity, $totalPath.$separator.$currentPath)) {
$totalPath .= $separator.$currentPath;
$currentPath = '';
}
}
if (!empty($currentPath)) {
throw new \Exception(
sprintf('Could not get element id from %s Failing part: %s', $elementId, $currentPath)
);
}
return $totalPath;
} | [
"public",
"function",
"getElementAccessPath",
"(",
"$",
"elementId",
",",
"$",
"entity",
")",
"{",
"$",
"propertyAccessor",
"=",
"$",
"this",
"->",
"pool",
"->",
"getPropertyAccessor",
"(",
")",
";",
"$",
"idWithoutIdentifier",
"=",
"preg_replace",
"(",
"'/^[^_]*_/'",
",",
"''",
",",
"$",
"elementId",
")",
";",
"$",
"initialPath",
"=",
"preg_replace",
"(",
"'#(_(\\d+)_)#'",
",",
"'[$2]_'",
",",
"$",
"idWithoutIdentifier",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'_'",
",",
"$",
"initialPath",
")",
";",
"$",
"totalPath",
"=",
"''",
";",
"$",
"currentPath",
"=",
"''",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"currentPath",
".=",
"empty",
"(",
"$",
"currentPath",
")",
"?",
"$",
"part",
":",
"'_'",
".",
"$",
"part",
";",
"$",
"separator",
"=",
"empty",
"(",
"$",
"totalPath",
")",
"?",
"''",
":",
"'.'",
";",
"if",
"(",
"$",
"propertyAccessor",
"->",
"isReadable",
"(",
"$",
"entity",
",",
"$",
"totalPath",
".",
"$",
"separator",
".",
"$",
"currentPath",
")",
")",
"{",
"$",
"totalPath",
".=",
"$",
"separator",
".",
"$",
"currentPath",
";",
"$",
"currentPath",
"=",
"''",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentPath",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Could not get element id from %s Failing part: %s'",
",",
"$",
"elementId",
",",
"$",
"currentPath",
")",
")",
";",
"}",
"return",
"$",
"totalPath",
";",
"}"
] | Get access path to element which works with PropertyAccessor.
@param string $elementId expects string in format used in form id field.
(uniqueIdentifier_model_sub_model or uniqueIdentifier_model_1_sub_model etc.)
@param mixed $entity
@throws \Exception
@return string | [
"Get",
"access",
"path",
"to",
"element",
"which",
"works",
"with",
"PropertyAccessor",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AdminHelper.php#L280-L308 | train |
sonata-project/SonataAdminBundle | src/Admin/AdminHelper.php | AdminHelper.getEntityClassName | protected function getEntityClassName(AdminInterface $admin, $elements)
{
$element = array_shift($elements);
$associationAdmin = $admin->getFormFieldDescription($element)->getAssociationAdmin();
if (0 === \count($elements)) {
return $associationAdmin->getClass();
}
return $this->getEntityClassName($associationAdmin, $elements);
} | php | protected function getEntityClassName(AdminInterface $admin, $elements)
{
$element = array_shift($elements);
$associationAdmin = $admin->getFormFieldDescription($element)->getAssociationAdmin();
if (0 === \count($elements)) {
return $associationAdmin->getClass();
}
return $this->getEntityClassName($associationAdmin, $elements);
} | [
"protected",
"function",
"getEntityClassName",
"(",
"AdminInterface",
"$",
"admin",
",",
"$",
"elements",
")",
"{",
"$",
"element",
"=",
"array_shift",
"(",
"$",
"elements",
")",
";",
"$",
"associationAdmin",
"=",
"$",
"admin",
"->",
"getFormFieldDescription",
"(",
"$",
"element",
")",
"->",
"getAssociationAdmin",
"(",
")",
";",
"if",
"(",
"0",
"===",
"\\",
"count",
"(",
"$",
"elements",
")",
")",
"{",
"return",
"$",
"associationAdmin",
"->",
"getClass",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getEntityClassName",
"(",
"$",
"associationAdmin",
",",
"$",
"elements",
")",
";",
"}"
] | Recursively find the class name of the admin responsible for the element at the end of an association chain.
@param array $elements
@return string | [
"Recursively",
"find",
"the",
"class",
"name",
"of",
"the",
"admin",
"responsible",
"for",
"the",
"element",
"at",
"the",
"end",
"of",
"an",
"association",
"chain",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AdminHelper.php#L317-L326 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclData.php | AdminObjectAclData.getUserPermissions | public function getUserPermissions()
{
$permissions = $this->getPermissions();
if (!$this->isOwner()) {
foreach (self::$ownerPermissions as $permission) {
$key = array_search($permission, $permissions, true);
if (false !== $key) {
unset($permissions[$key]);
}
}
}
return $permissions;
} | php | public function getUserPermissions()
{
$permissions = $this->getPermissions();
if (!$this->isOwner()) {
foreach (self::$ownerPermissions as $permission) {
$key = array_search($permission, $permissions, true);
if (false !== $key) {
unset($permissions[$key]);
}
}
}
return $permissions;
} | [
"public",
"function",
"getUserPermissions",
"(",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"getPermissions",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isOwner",
"(",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"ownerPermissions",
"as",
"$",
"permission",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"permission",
",",
"$",
"permissions",
",",
"true",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"permissions",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Get permissions that the current user can set.
@return array | [
"Get",
"permissions",
"that",
"the",
"current",
"user",
"can",
"set",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclData.php#L269-L283 | train |
sonata-project/SonataAdminBundle | src/Util/AdminObjectAclData.php | AdminObjectAclData.updateMasks | protected function updateMasks()
{
$permissions = $this->getPermissions();
$reflectionClass = new \ReflectionClass(new $this->maskBuilderClass());
$this->masks = [];
foreach ($permissions as $permission) {
$this->masks[$permission] = $reflectionClass->getConstant('MASK_'.$permission);
}
} | php | protected function updateMasks()
{
$permissions = $this->getPermissions();
$reflectionClass = new \ReflectionClass(new $this->maskBuilderClass());
$this->masks = [];
foreach ($permissions as $permission) {
$this->masks[$permission] = $reflectionClass->getConstant('MASK_'.$permission);
}
} | [
"protected",
"function",
"updateMasks",
"(",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"getPermissions",
"(",
")",
";",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"new",
"$",
"this",
"->",
"maskBuilderClass",
"(",
")",
")",
";",
"$",
"this",
"->",
"masks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"masks",
"[",
"$",
"permission",
"]",
"=",
"$",
"reflectionClass",
"->",
"getConstant",
"(",
"'MASK_'",
".",
"$",
"permission",
")",
";",
"}",
"}"
] | Cache masks. | [
"Cache",
"masks",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/AdminObjectAclData.php#L322-L331 | train |
sonata-project/SonataAdminBundle | src/Datagrid/Pager.php | Pager.getLinks | public function getLinks($nbLinks = null)
{
if (null === $nbLinks) {
$nbLinks = $this->getMaxPageLinks();
}
$links = [];
$tmp = $this->page - floor($nbLinks / 2);
$check = $this->lastPage - $nbLinks + 1;
$limit = $check > 0 ? $check : 1;
$begin = $tmp > 0 ? ($tmp > $limit ? $limit : $tmp) : 1;
$i = (int) $begin;
while ($i < $begin + $nbLinks && $i <= $this->lastPage) {
$links[] = $i++;
}
$this->currentMaxLink = \count($links) ? $links[\count($links) - 1] : 1;
return $links;
} | php | public function getLinks($nbLinks = null)
{
if (null === $nbLinks) {
$nbLinks = $this->getMaxPageLinks();
}
$links = [];
$tmp = $this->page - floor($nbLinks / 2);
$check = $this->lastPage - $nbLinks + 1;
$limit = $check > 0 ? $check : 1;
$begin = $tmp > 0 ? ($tmp > $limit ? $limit : $tmp) : 1;
$i = (int) $begin;
while ($i < $begin + $nbLinks && $i <= $this->lastPage) {
$links[] = $i++;
}
$this->currentMaxLink = \count($links) ? $links[\count($links) - 1] : 1;
return $links;
} | [
"public",
"function",
"getLinks",
"(",
"$",
"nbLinks",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"nbLinks",
")",
"{",
"$",
"nbLinks",
"=",
"$",
"this",
"->",
"getMaxPageLinks",
"(",
")",
";",
"}",
"$",
"links",
"=",
"[",
"]",
";",
"$",
"tmp",
"=",
"$",
"this",
"->",
"page",
"-",
"floor",
"(",
"$",
"nbLinks",
"/",
"2",
")",
";",
"$",
"check",
"=",
"$",
"this",
"->",
"lastPage",
"-",
"$",
"nbLinks",
"+",
"1",
";",
"$",
"limit",
"=",
"$",
"check",
">",
"0",
"?",
"$",
"check",
":",
"1",
";",
"$",
"begin",
"=",
"$",
"tmp",
">",
"0",
"?",
"(",
"$",
"tmp",
">",
"$",
"limit",
"?",
"$",
"limit",
":",
"$",
"tmp",
")",
":",
"1",
";",
"$",
"i",
"=",
"(",
"int",
")",
"$",
"begin",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"begin",
"+",
"$",
"nbLinks",
"&&",
"$",
"i",
"<=",
"$",
"this",
"->",
"lastPage",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"$",
"i",
"++",
";",
"}",
"$",
"this",
"->",
"currentMaxLink",
"=",
"\\",
"count",
"(",
"$",
"links",
")",
"?",
"$",
"links",
"[",
"\\",
"count",
"(",
"$",
"links",
")",
"-",
"1",
"]",
":",
"1",
";",
"return",
"$",
"links",
";",
"}"
] | Returns an array of page numbers to use in pagination links.
@param int $nbLinks The maximum number of page numbers to return
@return array | [
"Returns",
"an",
"array",
"of",
"page",
"numbers",
"to",
"use",
"in",
"pagination",
"links",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Datagrid/Pager.php#L136-L155 | train |
sonata-project/SonataAdminBundle | src/Datagrid/Pager.php | Pager.setCursor | public function setCursor($pos)
{
if ($pos < 1) {
$this->cursor = 1;
} else {
if ($pos > $this->nbResults) {
$this->cursor = $this->nbResults;
} else {
$this->cursor = $pos;
}
}
} | php | public function setCursor($pos)
{
if ($pos < 1) {
$this->cursor = 1;
} else {
if ($pos > $this->nbResults) {
$this->cursor = $this->nbResults;
} else {
$this->cursor = $pos;
}
}
} | [
"public",
"function",
"setCursor",
"(",
"$",
"pos",
")",
"{",
"if",
"(",
"$",
"pos",
"<",
"1",
")",
"{",
"$",
"this",
"->",
"cursor",
"=",
"1",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"pos",
">",
"$",
"this",
"->",
"nbResults",
")",
"{",
"$",
"this",
"->",
"cursor",
"=",
"$",
"this",
"->",
"nbResults",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cursor",
"=",
"$",
"pos",
";",
"}",
"}",
"}"
] | Sets the current cursor.
@param int $pos | [
"Sets",
"the",
"current",
"cursor",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Datagrid/Pager.php#L182-L193 | train |
sonata-project/SonataAdminBundle | src/Datagrid/Pager.php | Pager.initializeIterator | protected function initializeIterator()
{
$this->results = $this->getResults();
$this->resultsCounter = \count($this->results);
} | php | protected function initializeIterator()
{
$this->results = $this->getResults();
$this->resultsCounter = \count($this->results);
} | [
"protected",
"function",
"initializeIterator",
"(",
")",
"{",
"$",
"this",
"->",
"results",
"=",
"$",
"this",
"->",
"getResults",
"(",
")",
";",
"$",
"this",
"->",
"resultsCounter",
"=",
"\\",
"count",
"(",
"$",
"this",
"->",
"results",
")",
";",
"}"
] | Loads data into properties used for iteration. | [
"Loads",
"data",
"into",
"properties",
"used",
"for",
"iteration",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Datagrid/Pager.php#L602-L606 | train |
sonata-project/SonataAdminBundle | src/Datagrid/Pager.php | Pager.retrieveObject | protected function retrieveObject($offset)
{
$queryForRetrieve = clone $this->getQuery();
$queryForRetrieve
->setFirstResult($offset - 1)
->setMaxResults(1);
$results = $queryForRetrieve->execute();
return $results[0];
} | php | protected function retrieveObject($offset)
{
$queryForRetrieve = clone $this->getQuery();
$queryForRetrieve
->setFirstResult($offset - 1)
->setMaxResults(1);
$results = $queryForRetrieve->execute();
return $results[0];
} | [
"protected",
"function",
"retrieveObject",
"(",
"$",
"offset",
")",
"{",
"$",
"queryForRetrieve",
"=",
"clone",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"$",
"queryForRetrieve",
"->",
"setFirstResult",
"(",
"$",
"offset",
"-",
"1",
")",
"->",
"setMaxResults",
"(",
"1",
")",
";",
"$",
"results",
"=",
"$",
"queryForRetrieve",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"results",
"[",
"0",
"]",
";",
"}"
] | Retrieve the object for a certain offset.
@param int $offset
@return object | [
"Retrieve",
"the",
"object",
"for",
"a",
"certain",
"offset",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Datagrid/Pager.php#L624-L634 | train |
sonata-project/SonataAdminBundle | src/Annotation/Admin.php | Admin.generateFallback | private function generateFallback($name): void
{
if (empty($name)) {
return;
}
if (preg_match(AdminClass::CLASS_REGEX, $name, $matches)) {
if (empty($this->group)) {
$this->group = $matches[3];
}
if (empty($this->label)) {
$this->label = $matches[5];
}
}
} | php | private function generateFallback($name): void
{
if (empty($name)) {
return;
}
if (preg_match(AdminClass::CLASS_REGEX, $name, $matches)) {
if (empty($this->group)) {
$this->group = $matches[3];
}
if (empty($this->label)) {
$this->label = $matches[5];
}
}
} | [
"private",
"function",
"generateFallback",
"(",
"$",
"name",
")",
":",
"void",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"preg_match",
"(",
"AdminClass",
"::",
"CLASS_REGEX",
",",
"$",
"name",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"group",
")",
")",
"{",
"$",
"this",
"->",
"group",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"label",
")",
")",
"{",
"$",
"this",
"->",
"label",
"=",
"$",
"matches",
"[",
"5",
"]",
";",
"}",
"}",
"}"
] | Set group and label from class name it not set. | [
"Set",
"group",
"and",
"label",
"from",
"class",
"name",
"it",
"not",
"set",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Annotation/Admin.php#L161-L176 | train |
sonata-project/SonataAdminBundle | src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php | AddDependencyCallsCompilerPass.applyConfigurationFromAttribute | public function applyConfigurationFromAttribute(Definition $definition, array $attributes)
{
$keys = [
'model_manager',
'form_contractor',
'show_builder',
'list_builder',
'datagrid_builder',
'translator',
'configuration_pool',
'router',
'validator',
'security_handler',
'menu_factory',
'route_builder',
'label_translator_strategy',
];
foreach ($keys as $key) {
$method = 'set'.Inflector::classify($key);
if (!isset($attributes[$key]) || $definition->hasMethodCall($method)) {
continue;
}
$definition->addMethodCall($method, [new Reference($attributes[$key])]);
}
} | php | public function applyConfigurationFromAttribute(Definition $definition, array $attributes)
{
$keys = [
'model_manager',
'form_contractor',
'show_builder',
'list_builder',
'datagrid_builder',
'translator',
'configuration_pool',
'router',
'validator',
'security_handler',
'menu_factory',
'route_builder',
'label_translator_strategy',
];
foreach ($keys as $key) {
$method = 'set'.Inflector::classify($key);
if (!isset($attributes[$key]) || $definition->hasMethodCall($method)) {
continue;
}
$definition->addMethodCall($method, [new Reference($attributes[$key])]);
}
} | [
"public",
"function",
"applyConfigurationFromAttribute",
"(",
"Definition",
"$",
"definition",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"keys",
"=",
"[",
"'model_manager'",
",",
"'form_contractor'",
",",
"'show_builder'",
",",
"'list_builder'",
",",
"'datagrid_builder'",
",",
"'translator'",
",",
"'configuration_pool'",
",",
"'router'",
",",
"'validator'",
",",
"'security_handler'",
",",
"'menu_factory'",
",",
"'route_builder'",
",",
"'label_translator_strategy'",
",",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"method",
"=",
"'set'",
".",
"Inflector",
"::",
"classify",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"definition",
"->",
"hasMethodCall",
"(",
"$",
"method",
")",
")",
"{",
"continue",
";",
"}",
"$",
"definition",
"->",
"addMethodCall",
"(",
"$",
"method",
",",
"[",
"new",
"Reference",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
"]",
")",
";",
"}",
"}"
] | This method read the attribute keys and configure admin class to use the related dependency. | [
"This",
"method",
"read",
"the",
"attribute",
"keys",
"and",
"configure",
"admin",
"class",
"to",
"use",
"the",
"related",
"dependency",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php#L221-L247 | train |
sonata-project/SonataAdminBundle | src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php | AddDependencyCallsCompilerPass.replaceDefaultArguments | private function replaceDefaultArguments(
array $defaultArguments,
Definition $definition,
Definition $parentDefinition = null
): void {
$arguments = $definition->getArguments();
$parentArguments = $parentDefinition ? $parentDefinition->getArguments() : [];
foreach ($defaultArguments as $index => $value) {
$declaredInParent = $parentDefinition && \array_key_exists($index, $parentArguments);
$argumentValue = $declaredInParent ? $parentArguments[$index] : $arguments[$index];
if (null === $argumentValue || 0 === \strlen($argumentValue)) {
$arguments[$declaredInParent ? sprintf('index_%s', $index) : $index] = $value;
}
}
$definition->setArguments($arguments);
} | php | private function replaceDefaultArguments(
array $defaultArguments,
Definition $definition,
Definition $parentDefinition = null
): void {
$arguments = $definition->getArguments();
$parentArguments = $parentDefinition ? $parentDefinition->getArguments() : [];
foreach ($defaultArguments as $index => $value) {
$declaredInParent = $parentDefinition && \array_key_exists($index, $parentArguments);
$argumentValue = $declaredInParent ? $parentArguments[$index] : $arguments[$index];
if (null === $argumentValue || 0 === \strlen($argumentValue)) {
$arguments[$declaredInParent ? sprintf('index_%s', $index) : $index] = $value;
}
}
$definition->setArguments($arguments);
} | [
"private",
"function",
"replaceDefaultArguments",
"(",
"array",
"$",
"defaultArguments",
",",
"Definition",
"$",
"definition",
",",
"Definition",
"$",
"parentDefinition",
"=",
"null",
")",
":",
"void",
"{",
"$",
"arguments",
"=",
"$",
"definition",
"->",
"getArguments",
"(",
")",
";",
"$",
"parentArguments",
"=",
"$",
"parentDefinition",
"?",
"$",
"parentDefinition",
"->",
"getArguments",
"(",
")",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"defaultArguments",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"declaredInParent",
"=",
"$",
"parentDefinition",
"&&",
"\\",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"parentArguments",
")",
";",
"$",
"argumentValue",
"=",
"$",
"declaredInParent",
"?",
"$",
"parentArguments",
"[",
"$",
"index",
"]",
":",
"$",
"arguments",
"[",
"$",
"index",
"]",
";",
"if",
"(",
"null",
"===",
"$",
"argumentValue",
"||",
"0",
"===",
"\\",
"strlen",
"(",
"$",
"argumentValue",
")",
")",
"{",
"$",
"arguments",
"[",
"$",
"declaredInParent",
"?",
"sprintf",
"(",
"'index_%s'",
",",
"$",
"index",
")",
":",
"$",
"index",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"definition",
"->",
"setArguments",
"(",
"$",
"arguments",
")",
";",
"}"
] | Replace the empty arguments required by the Admin service definition. | [
"Replace",
"the",
"empty",
"arguments",
"required",
"by",
"the",
"Admin",
"service",
"definition",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php#L423-L441 | train |
sonata-project/SonataAdminBundle | src/Util/ObjectAclManipulator.php | ObjectAclManipulator.configureAcls | public function configureAcls(
OutputInterface $output,
AdminInterface $admin,
\Traversable $oids,
UserSecurityIdentity $securityIdentity = null
) {
$countAdded = 0;
$countUpdated = 0;
$securityHandler = $admin->getSecurityHandler();
if (!$securityHandler instanceof AclSecurityHandlerInterface) {
$output->writeln(sprintf('Admin `%s` is not configured to use ACL : <info>ignoring</info>', $admin->getCode()));
return [0, 0];
}
$acls = $securityHandler->findObjectAcls($oids);
foreach ($oids as $oid) {
if ($acls->contains($oid)) {
$acl = $acls->offsetGet($oid);
++$countUpdated;
} else {
$acl = $securityHandler->createAcl($oid);
++$countAdded;
}
if (null !== $securityIdentity) {
// add object owner
$securityHandler->addObjectOwner($acl, $securityIdentity);
}
$securityHandler->addObjectClassAces($acl, $securityHandler->buildSecurityInformation($admin));
try {
$securityHandler->updateAcl($acl);
} catch (\Exception $e) {
$output->writeln(sprintf('Error saving ObjectIdentity (%s, %s) ACL : %s <info>ignoring</info>', $oid->getIdentifier(), $oid->getType(), $e->getMessage()));
}
}
return [$countAdded, $countUpdated];
} | php | public function configureAcls(
OutputInterface $output,
AdminInterface $admin,
\Traversable $oids,
UserSecurityIdentity $securityIdentity = null
) {
$countAdded = 0;
$countUpdated = 0;
$securityHandler = $admin->getSecurityHandler();
if (!$securityHandler instanceof AclSecurityHandlerInterface) {
$output->writeln(sprintf('Admin `%s` is not configured to use ACL : <info>ignoring</info>', $admin->getCode()));
return [0, 0];
}
$acls = $securityHandler->findObjectAcls($oids);
foreach ($oids as $oid) {
if ($acls->contains($oid)) {
$acl = $acls->offsetGet($oid);
++$countUpdated;
} else {
$acl = $securityHandler->createAcl($oid);
++$countAdded;
}
if (null !== $securityIdentity) {
// add object owner
$securityHandler->addObjectOwner($acl, $securityIdentity);
}
$securityHandler->addObjectClassAces($acl, $securityHandler->buildSecurityInformation($admin));
try {
$securityHandler->updateAcl($acl);
} catch (\Exception $e) {
$output->writeln(sprintf('Error saving ObjectIdentity (%s, %s) ACL : %s <info>ignoring</info>', $oid->getIdentifier(), $oid->getType(), $e->getMessage()));
}
}
return [$countAdded, $countUpdated];
} | [
"public",
"function",
"configureAcls",
"(",
"OutputInterface",
"$",
"output",
",",
"AdminInterface",
"$",
"admin",
",",
"\\",
"Traversable",
"$",
"oids",
",",
"UserSecurityIdentity",
"$",
"securityIdentity",
"=",
"null",
")",
"{",
"$",
"countAdded",
"=",
"0",
";",
"$",
"countUpdated",
"=",
"0",
";",
"$",
"securityHandler",
"=",
"$",
"admin",
"->",
"getSecurityHandler",
"(",
")",
";",
"if",
"(",
"!",
"$",
"securityHandler",
"instanceof",
"AclSecurityHandlerInterface",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Admin `%s` is not configured to use ACL : <info>ignoring</info>'",
",",
"$",
"admin",
"->",
"getCode",
"(",
")",
")",
")",
";",
"return",
"[",
"0",
",",
"0",
"]",
";",
"}",
"$",
"acls",
"=",
"$",
"securityHandler",
"->",
"findObjectAcls",
"(",
"$",
"oids",
")",
";",
"foreach",
"(",
"$",
"oids",
"as",
"$",
"oid",
")",
"{",
"if",
"(",
"$",
"acls",
"->",
"contains",
"(",
"$",
"oid",
")",
")",
"{",
"$",
"acl",
"=",
"$",
"acls",
"->",
"offsetGet",
"(",
"$",
"oid",
")",
";",
"++",
"$",
"countUpdated",
";",
"}",
"else",
"{",
"$",
"acl",
"=",
"$",
"securityHandler",
"->",
"createAcl",
"(",
"$",
"oid",
")",
";",
"++",
"$",
"countAdded",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"securityIdentity",
")",
"{",
"// add object owner",
"$",
"securityHandler",
"->",
"addObjectOwner",
"(",
"$",
"acl",
",",
"$",
"securityIdentity",
")",
";",
"}",
"$",
"securityHandler",
"->",
"addObjectClassAces",
"(",
"$",
"acl",
",",
"$",
"securityHandler",
"->",
"buildSecurityInformation",
"(",
"$",
"admin",
")",
")",
";",
"try",
"{",
"$",
"securityHandler",
"->",
"updateAcl",
"(",
"$",
"acl",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Error saving ObjectIdentity (%s, %s) ACL : %s <info>ignoring</info>'",
",",
"$",
"oid",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"oid",
"->",
"getType",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"return",
"[",
"$",
"countAdded",
",",
"$",
"countUpdated",
"]",
";",
"}"
] | Configure the object ACL for the passed object identities.
@throws \Exception
@return array [countAdded, countUpdated] | [
"Configure",
"the",
"object",
"ACL",
"for",
"the",
"passed",
"object",
"identities",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Util/ObjectAclManipulator.php#L33-L74 | train |
sonata-project/SonataAdminBundle | src/Action/RetrieveAutocompleteItemsAction.php | RetrieveAutocompleteItemsAction.retrieveFilterFieldDescription | private function retrieveFilterFieldDescription(
AdminInterface $admin,
string $field
): FieldDescriptionInterface {
$admin->getFilterFieldDescriptions();
$fieldDescription = $admin->getFilterFieldDescription($field);
if (!$fieldDescription) {
throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
}
if (null === $fieldDescription->getTargetEntity()) {
throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field));
}
return $fieldDescription;
} | php | private function retrieveFilterFieldDescription(
AdminInterface $admin,
string $field
): FieldDescriptionInterface {
$admin->getFilterFieldDescriptions();
$fieldDescription = $admin->getFilterFieldDescription($field);
if (!$fieldDescription) {
throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
}
if (null === $fieldDescription->getTargetEntity()) {
throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field));
}
return $fieldDescription;
} | [
"private",
"function",
"retrieveFilterFieldDescription",
"(",
"AdminInterface",
"$",
"admin",
",",
"string",
"$",
"field",
")",
":",
"FieldDescriptionInterface",
"{",
"$",
"admin",
"->",
"getFilterFieldDescriptions",
"(",
")",
";",
"$",
"fieldDescription",
"=",
"$",
"admin",
"->",
"getFilterFieldDescription",
"(",
"$",
"field",
")",
";",
"if",
"(",
"!",
"$",
"fieldDescription",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The field \"%s\" does not exist.'",
",",
"$",
"field",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"fieldDescription",
"->",
"getTargetEntity",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'No associated entity with field \"%s\".'",
",",
"$",
"field",
")",
")",
";",
"}",
"return",
"$",
"fieldDescription",
";",
"}"
] | Retrieve the filter field description given by field name.
@throws \RuntimeException | [
"Retrieve",
"the",
"filter",
"field",
"description",
"given",
"by",
"field",
"name",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Action/RetrieveAutocompleteItemsAction.php#L181-L198 | train |
sonata-project/SonataAdminBundle | src/Admin/Pool.php | Pool.getInstance | public function getInstance($id)
{
if (!\in_array($id, $this->adminServiceIds, true)) {
$msg = sprintf('Admin service "%s" not found in admin pool.', $id);
$shortest = -1;
$closest = null;
$alternatives = [];
foreach ($this->adminServiceIds as $adminServiceId) {
$lev = levenshtein($id, $adminServiceId);
if ($lev <= $shortest || $shortest < 0) {
$closest = $adminServiceId;
$shortest = $lev;
}
if ($lev <= \strlen($adminServiceId) / 3 || false !== strpos($adminServiceId, $id)) {
$alternatives[$adminServiceId] = $lev;
}
}
if (null !== $closest) {
asort($alternatives);
unset($alternatives[$closest]);
$msg = sprintf(
'Admin service "%s" not found in admin pool. Did you mean "%s" or one of those: [%s]?',
$id,
$closest,
implode(', ', array_keys($alternatives))
);
}
throw new \InvalidArgumentException($msg);
}
$admin = $this->container->get($id);
if (!$admin instanceof AdminInterface) {
throw new InvalidArgumentException(sprintf('Found service "%s" is not a valid admin service', $id));
}
return $admin;
} | php | public function getInstance($id)
{
if (!\in_array($id, $this->adminServiceIds, true)) {
$msg = sprintf('Admin service "%s" not found in admin pool.', $id);
$shortest = -1;
$closest = null;
$alternatives = [];
foreach ($this->adminServiceIds as $adminServiceId) {
$lev = levenshtein($id, $adminServiceId);
if ($lev <= $shortest || $shortest < 0) {
$closest = $adminServiceId;
$shortest = $lev;
}
if ($lev <= \strlen($adminServiceId) / 3 || false !== strpos($adminServiceId, $id)) {
$alternatives[$adminServiceId] = $lev;
}
}
if (null !== $closest) {
asort($alternatives);
unset($alternatives[$closest]);
$msg = sprintf(
'Admin service "%s" not found in admin pool. Did you mean "%s" or one of those: [%s]?',
$id,
$closest,
implode(', ', array_keys($alternatives))
);
}
throw new \InvalidArgumentException($msg);
}
$admin = $this->container->get($id);
if (!$admin instanceof AdminInterface) {
throw new InvalidArgumentException(sprintf('Found service "%s" is not a valid admin service', $id));
}
return $admin;
} | [
"public",
"function",
"getInstance",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"adminServiceIds",
",",
"true",
")",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'Admin service \"%s\" not found in admin pool.'",
",",
"$",
"id",
")",
";",
"$",
"shortest",
"=",
"-",
"1",
";",
"$",
"closest",
"=",
"null",
";",
"$",
"alternatives",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"adminServiceIds",
"as",
"$",
"adminServiceId",
")",
"{",
"$",
"lev",
"=",
"levenshtein",
"(",
"$",
"id",
",",
"$",
"adminServiceId",
")",
";",
"if",
"(",
"$",
"lev",
"<=",
"$",
"shortest",
"||",
"$",
"shortest",
"<",
"0",
")",
"{",
"$",
"closest",
"=",
"$",
"adminServiceId",
";",
"$",
"shortest",
"=",
"$",
"lev",
";",
"}",
"if",
"(",
"$",
"lev",
"<=",
"\\",
"strlen",
"(",
"$",
"adminServiceId",
")",
"/",
"3",
"||",
"false",
"!==",
"strpos",
"(",
"$",
"adminServiceId",
",",
"$",
"id",
")",
")",
"{",
"$",
"alternatives",
"[",
"$",
"adminServiceId",
"]",
"=",
"$",
"lev",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"closest",
")",
"{",
"asort",
"(",
"$",
"alternatives",
")",
";",
"unset",
"(",
"$",
"alternatives",
"[",
"$",
"closest",
"]",
")",
";",
"$",
"msg",
"=",
"sprintf",
"(",
"'Admin service \"%s\" not found in admin pool. Did you mean \"%s\" or one of those: [%s]?'",
",",
"$",
"id",
",",
"$",
"closest",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"alternatives",
")",
")",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"admin",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"admin",
"instanceof",
"AdminInterface",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Found service \"%s\" is not a valid admin service'",
",",
"$",
"id",
")",
")",
";",
"}",
"return",
"$",
"admin",
";",
"}"
] | Returns a new admin instance depends on the given code.
@param string $id
@throws \InvalidArgumentException
@return AdminInterface | [
"Returns",
"a",
"new",
"admin",
"instance",
"depends",
"on",
"the",
"given",
"code",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/Pool.php#L273-L310 | train |
sonata-project/SonataAdminBundle | src/Bridge/Exporter/AdminExporter.php | AdminExporter.getAvailableFormats | public function getAvailableFormats(AdminInterface $admin): array
{
$adminExportFormats = $admin->getExportFormats();
// NEXT_MAJOR : compare with null
if ($adminExportFormats !== ['json', 'xml', 'csv', 'xls']) {
return $adminExportFormats;
}
return $this->exporter->getAvailableFormats();
} | php | public function getAvailableFormats(AdminInterface $admin): array
{
$adminExportFormats = $admin->getExportFormats();
// NEXT_MAJOR : compare with null
if ($adminExportFormats !== ['json', 'xml', 'csv', 'xls']) {
return $adminExportFormats;
}
return $this->exporter->getAvailableFormats();
} | [
"public",
"function",
"getAvailableFormats",
"(",
"AdminInterface",
"$",
"admin",
")",
":",
"array",
"{",
"$",
"adminExportFormats",
"=",
"$",
"admin",
"->",
"getExportFormats",
"(",
")",
";",
"// NEXT_MAJOR : compare with null",
"if",
"(",
"$",
"adminExportFormats",
"!==",
"[",
"'json'",
",",
"'xml'",
",",
"'csv'",
",",
"'xls'",
"]",
")",
"{",
"return",
"$",
"adminExportFormats",
";",
"}",
"return",
"$",
"this",
"->",
"exporter",
"->",
"getAvailableFormats",
"(",
")",
";",
"}"
] | Queries an admin for its default export formats, and falls back on global settings.
@param AdminInterface $admin the current admin object
@return string[] an array of formats | [
"Queries",
"an",
"admin",
"for",
"its",
"default",
"export",
"formats",
"and",
"falls",
"back",
"on",
"global",
"settings",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Bridge/Exporter/AdminExporter.php#L44-L54 | train |
sonata-project/SonataAdminBundle | src/Bridge/Exporter/AdminExporter.php | AdminExporter.getExportFilename | public function getExportFilename(AdminInterface $admin, string $format): string
{
$class = $admin->getClass();
return sprintf(
'export_%s_%s.%s',
strtolower(substr($class, strripos($class, '\\') + 1)),
date('Y_m_d_H_i_s', strtotime('now')),
$format
);
} | php | public function getExportFilename(AdminInterface $admin, string $format): string
{
$class = $admin->getClass();
return sprintf(
'export_%s_%s.%s',
strtolower(substr($class, strripos($class, '\\') + 1)),
date('Y_m_d_H_i_s', strtotime('now')),
$format
);
} | [
"public",
"function",
"getExportFilename",
"(",
"AdminInterface",
"$",
"admin",
",",
"string",
"$",
"format",
")",
":",
"string",
"{",
"$",
"class",
"=",
"$",
"admin",
"->",
"getClass",
"(",
")",
";",
"return",
"sprintf",
"(",
"'export_%s_%s.%s'",
",",
"strtolower",
"(",
"substr",
"(",
"$",
"class",
",",
"strripos",
"(",
"$",
"class",
",",
"'\\\\'",
")",
"+",
"1",
")",
")",
",",
"date",
"(",
"'Y_m_d_H_i_s'",
",",
"strtotime",
"(",
"'now'",
")",
")",
",",
"$",
"format",
")",
";",
"}"
] | Builds an export filename from the class associated with the provided admin,
the current date, and the provided format.
@param AdminInterface $admin the current admin object
@param string $format the format of the export file | [
"Builds",
"an",
"export",
"filename",
"from",
"the",
"class",
"associated",
"with",
"the",
"provided",
"admin",
"the",
"current",
"date",
"and",
"the",
"provided",
"format",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Bridge/Exporter/AdminExporter.php#L63-L73 | train |
sonata-project/SonataAdminBundle | src/Controller/CoreController.php | CoreController.searchAction | public function searchAction(Request $request)
{
$searchAction = $this->container->get(SearchAction::class);
return $searchAction($request);
} | php | public function searchAction(Request $request)
{
$searchAction = $this->container->get(SearchAction::class);
return $searchAction($request);
} | [
"public",
"function",
"searchAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"searchAction",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"SearchAction",
"::",
"class",
")",
";",
"return",
"$",
"searchAction",
"(",
"$",
"request",
")",
";",
"}"
] | The search action first render an empty page, if the query is set, then the template generates
some ajax request to retrieve results for each admin. The Ajax query returns a JSON response.
@throws \RuntimeException
@return JsonResponse|Response | [
"The",
"search",
"action",
"first",
"render",
"an",
"empty",
"page",
"if",
"the",
"query",
"is",
"set",
"then",
"the",
"template",
"generates",
"some",
"ajax",
"request",
"to",
"retrieve",
"results",
"for",
"each",
"admin",
".",
"The",
"Ajax",
"query",
"returns",
"a",
"JSON",
"response",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CoreController.php#L57-L62 | train |
sonata-project/SonataAdminBundle | src/Guesser/TypeGuesserChain.php | TypeGuesserChain.guess | private function guess(\Closure $closure): Guess
{
$guesses = [];
foreach ($this->guessers as $guesser) {
if ($guess = $closure($guesser)) {
$guesses[] = $guess;
}
}
return Guess::getBestGuess($guesses);
} | php | private function guess(\Closure $closure): Guess
{
$guesses = [];
foreach ($this->guessers as $guesser) {
if ($guess = $closure($guesser)) {
$guesses[] = $guess;
}
}
return Guess::getBestGuess($guesses);
} | [
"private",
"function",
"guess",
"(",
"\\",
"Closure",
"$",
"closure",
")",
":",
"Guess",
"{",
"$",
"guesses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"guessers",
"as",
"$",
"guesser",
")",
"{",
"if",
"(",
"$",
"guess",
"=",
"$",
"closure",
"(",
"$",
"guesser",
")",
")",
"{",
"$",
"guesses",
"[",
"]",
"=",
"$",
"guess",
";",
"}",
"}",
"return",
"Guess",
"::",
"getBestGuess",
"(",
"$",
"guesses",
")",
";",
"}"
] | Executes a closure for each guesser and returns the best guess from the
return values.
@param \Closure $closure The closure to execute. Accepts a guesser
as argument and should return a Guess instance
@return Guess The guess with the highest confidence | [
"Executes",
"a",
"closure",
"for",
"each",
"guesser",
"and",
"returns",
"the",
"best",
"guess",
"from",
"the",
"return",
"values",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Guesser/TypeGuesserChain.php#L64-L75 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.initialize | public function initialize()
{
if (!$this->classnameLabel) {
/* NEXT_MAJOR: remove cast to string, null is not supposed to be
supported but was documented as such */
$this->classnameLabel = substr(
(string) $this->getClass(),
strrpos((string) $this->getClass(), '\\') + 1
);
}
// NEXT_MAJOR: Remove this line.
$this->baseCodeRoute = $this->getCode();
$this->configure();
} | php | public function initialize()
{
if (!$this->classnameLabel) {
/* NEXT_MAJOR: remove cast to string, null is not supposed to be
supported but was documented as such */
$this->classnameLabel = substr(
(string) $this->getClass(),
strrpos((string) $this->getClass(), '\\') + 1
);
}
// NEXT_MAJOR: Remove this line.
$this->baseCodeRoute = $this->getCode();
$this->configure();
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"classnameLabel",
")",
"{",
"/* NEXT_MAJOR: remove cast to string, null is not supposed to be\n supported but was documented as such */",
"$",
"this",
"->",
"classnameLabel",
"=",
"substr",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"getClass",
"(",
")",
",",
"strrpos",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"getClass",
"(",
")",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"}",
"// NEXT_MAJOR: Remove this line.",
"$",
"this",
"->",
"baseCodeRoute",
"=",
"$",
"this",
"->",
"getCode",
"(",
")",
";",
"$",
"this",
"->",
"configure",
"(",
")",
";",
"}"
] | define custom variable. | [
"define",
"custom",
"variable",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L642-L657 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.getBaseRoutePattern | public function getBaseRoutePattern()
{
if (null !== $this->cachedBaseRoutePattern) {
return $this->cachedBaseRoutePattern;
}
if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern
$baseRoutePattern = $this->baseRoutePattern;
if (!$this->baseRoutePattern) {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', \get_class($this)));
}
$baseRoutePattern = $this->urlize($matches[5], '-');
}
$this->cachedBaseRoutePattern = sprintf(
'%s/%s/%s',
$this->getParent()->getBaseRoutePattern(),
$this->getParent()->getRouterIdParameter(),
$baseRoutePattern
);
} elseif ($this->baseRoutePattern) {
$this->cachedBaseRoutePattern = $this->baseRoutePattern;
} else {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', \get_class($this)));
}
$this->cachedBaseRoutePattern = sprintf(
'/%s%s/%s',
empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/',
$this->urlize($matches[3], '-'),
$this->urlize($matches[5], '-')
);
}
return $this->cachedBaseRoutePattern;
} | php | public function getBaseRoutePattern()
{
if (null !== $this->cachedBaseRoutePattern) {
return $this->cachedBaseRoutePattern;
}
if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern
$baseRoutePattern = $this->baseRoutePattern;
if (!$this->baseRoutePattern) {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', \get_class($this)));
}
$baseRoutePattern = $this->urlize($matches[5], '-');
}
$this->cachedBaseRoutePattern = sprintf(
'%s/%s/%s',
$this->getParent()->getBaseRoutePattern(),
$this->getParent()->getRouterIdParameter(),
$baseRoutePattern
);
} elseif ($this->baseRoutePattern) {
$this->cachedBaseRoutePattern = $this->baseRoutePattern;
} else {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', \get_class($this)));
}
$this->cachedBaseRoutePattern = sprintf(
'/%s%s/%s',
empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/',
$this->urlize($matches[3], '-'),
$this->urlize($matches[5], '-')
);
}
return $this->cachedBaseRoutePattern;
} | [
"public",
"function",
"getBaseRoutePattern",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"cachedBaseRoutePattern",
")",
"{",
"return",
"$",
"this",
"->",
"cachedBaseRoutePattern",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isChild",
"(",
")",
")",
"{",
"// the admin class is a child, prefix it with the parent route pattern",
"$",
"baseRoutePattern",
"=",
"$",
"this",
"->",
"baseRoutePattern",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"baseRoutePattern",
")",
"{",
"preg_match",
"(",
"self",
"::",
"CLASS_REGEX",
",",
"$",
"this",
"->",
"class",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"$",
"matches",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Please define a default `baseRoutePattern` value for the admin class `%s`'",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"$",
"baseRoutePattern",
"=",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"5",
"]",
",",
"'-'",
")",
";",
"}",
"$",
"this",
"->",
"cachedBaseRoutePattern",
"=",
"sprintf",
"(",
"'%s/%s/%s'",
",",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getBaseRoutePattern",
"(",
")",
",",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getRouterIdParameter",
"(",
")",
",",
"$",
"baseRoutePattern",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"baseRoutePattern",
")",
"{",
"$",
"this",
"->",
"cachedBaseRoutePattern",
"=",
"$",
"this",
"->",
"baseRoutePattern",
";",
"}",
"else",
"{",
"preg_match",
"(",
"self",
"::",
"CLASS_REGEX",
",",
"$",
"this",
"->",
"class",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"$",
"matches",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Please define a default `baseRoutePattern` value for the admin class `%s`'",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"cachedBaseRoutePattern",
"=",
"sprintf",
"(",
"'/%s%s/%s'",
",",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"?",
"''",
":",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"'-'",
")",
".",
"'/'",
",",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"3",
"]",
",",
"'-'",
")",
",",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"5",
"]",
",",
"'-'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cachedBaseRoutePattern",
";",
"}"
] | Returns the baseRoutePattern used to generate the routing information.
@throws \RuntimeException
@return string the baseRoutePattern used to generate the routing information | [
"Returns",
"the",
"baseRoutePattern",
"used",
"to",
"generate",
"the",
"routing",
"information",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L905-L946 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.getBaseRouteName | public function getBaseRouteName()
{
if (null !== $this->cachedBaseRouteName) {
return $this->cachedBaseRouteName;
}
if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
$baseRouteName = $this->baseRouteName;
if (!$this->baseRouteName) {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
}
$baseRouteName = $this->urlize($matches[5]);
}
$this->cachedBaseRouteName = sprintf(
'%s_%s',
$this->getParent()->getBaseRouteName(),
$baseRouteName
);
} elseif ($this->baseRouteName) {
$this->cachedBaseRouteName = $this->baseRouteName;
} else {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
}
$this->cachedBaseRouteName = sprintf('admin_%s%s_%s',
empty($matches[1]) ? '' : $this->urlize($matches[1]).'_',
$this->urlize($matches[3]),
$this->urlize($matches[5])
);
}
return $this->cachedBaseRouteName;
} | php | public function getBaseRouteName()
{
if (null !== $this->cachedBaseRouteName) {
return $this->cachedBaseRouteName;
}
if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
$baseRouteName = $this->baseRouteName;
if (!$this->baseRouteName) {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
}
$baseRouteName = $this->urlize($matches[5]);
}
$this->cachedBaseRouteName = sprintf(
'%s_%s',
$this->getParent()->getBaseRouteName(),
$baseRouteName
);
} elseif ($this->baseRouteName) {
$this->cachedBaseRouteName = $this->baseRouteName;
} else {
preg_match(self::CLASS_REGEX, $this->class, $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', \get_class($this)));
}
$this->cachedBaseRouteName = sprintf('admin_%s%s_%s',
empty($matches[1]) ? '' : $this->urlize($matches[1]).'_',
$this->urlize($matches[3]),
$this->urlize($matches[5])
);
}
return $this->cachedBaseRouteName;
} | [
"public",
"function",
"getBaseRouteName",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"cachedBaseRouteName",
")",
"{",
"return",
"$",
"this",
"->",
"cachedBaseRouteName",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isChild",
"(",
")",
")",
"{",
"// the admin class is a child, prefix it with the parent route name",
"$",
"baseRouteName",
"=",
"$",
"this",
"->",
"baseRouteName",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"baseRouteName",
")",
"{",
"preg_match",
"(",
"self",
"::",
"CLASS_REGEX",
",",
"$",
"this",
"->",
"class",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"$",
"matches",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`'",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"$",
"baseRouteName",
"=",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"}",
"$",
"this",
"->",
"cachedBaseRouteName",
"=",
"sprintf",
"(",
"'%s_%s'",
",",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getBaseRouteName",
"(",
")",
",",
"$",
"baseRouteName",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"baseRouteName",
")",
"{",
"$",
"this",
"->",
"cachedBaseRouteName",
"=",
"$",
"this",
"->",
"baseRouteName",
";",
"}",
"else",
"{",
"preg_match",
"(",
"self",
"::",
"CLASS_REGEX",
",",
"$",
"this",
"->",
"class",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"$",
"matches",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`'",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"cachedBaseRouteName",
"=",
"sprintf",
"(",
"'admin_%s%s_%s'",
",",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"?",
"''",
":",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
".",
"'_'",
",",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
",",
"$",
"this",
"->",
"urlize",
"(",
"$",
"matches",
"[",
"5",
"]",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cachedBaseRouteName",
";",
"}"
] | Returns the baseRouteName used to generate the routing information.
@throws \RuntimeException
@return string the baseRouteName used to generate the routing information | [
"Returns",
"the",
"baseRouteName",
"used",
"to",
"generate",
"the",
"routing",
"information",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L955-L994 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.buildBreadcrumbs | public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.',
E_USER_DEPRECATED
);
if (isset($this->breadcrumbs[$action])) {
return $this->breadcrumbs[$action];
}
return $this->breadcrumbs[$action] = $this->getBreadcrumbsBuilder()
->buildBreadcrumbs($this, $action, $menu);
} | php | public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.',
E_USER_DEPRECATED
);
if (isset($this->breadcrumbs[$action])) {
return $this->breadcrumbs[$action];
}
return $this->breadcrumbs[$action] = $this->getBreadcrumbsBuilder()
->buildBreadcrumbs($this, $action, $menu);
} | [
"public",
"function",
"buildBreadcrumbs",
"(",
"$",
"action",
",",
"MenuItemInterface",
"$",
"menu",
"=",
"null",
")",
"{",
"@",
"trigger_error",
"(",
"'The '",
".",
"__METHOD__",
".",
"' method is deprecated since version 3.2 and will be removed in 4.0.'",
",",
"E_USER_DEPRECATED",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"breadcrumbs",
"[",
"$",
"action",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"breadcrumbs",
"[",
"$",
"action",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"breadcrumbs",
"[",
"$",
"action",
"]",
"=",
"$",
"this",
"->",
"getBreadcrumbsBuilder",
"(",
")",
"->",
"buildBreadcrumbs",
"(",
"$",
"this",
",",
"$",
"action",
",",
"$",
"menu",
")",
";",
"}"
] | Generates the breadcrumbs array.
Note: the method will be called by the top admin instance (parent => child)
@param string $action
@return array | [
"Generates",
"the",
"breadcrumbs",
"array",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L1954-L1967 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.hasAccess | public function hasAccess($action, $object = null)
{
$access = $this->getAccess();
if (!\array_key_exists($action, $access)) {
return false;
}
if (!\is_array($access[$action])) {
$access[$action] = [$access[$action]];
}
foreach ($access[$action] as $role) {
if (false === $this->isGranted($role, $object)) {
return false;
}
}
return true;
} | php | public function hasAccess($action, $object = null)
{
$access = $this->getAccess();
if (!\array_key_exists($action, $access)) {
return false;
}
if (!\is_array($access[$action])) {
$access[$action] = [$access[$action]];
}
foreach ($access[$action] as $role) {
if (false === $this->isGranted($role, $object)) {
return false;
}
}
return true;
} | [
"public",
"function",
"hasAccess",
"(",
"$",
"action",
",",
"$",
"object",
"=",
"null",
")",
"{",
"$",
"access",
"=",
"$",
"this",
"->",
"getAccess",
"(",
")",
";",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"action",
",",
"$",
"access",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"access",
"[",
"$",
"action",
"]",
")",
")",
"{",
"$",
"access",
"[",
"$",
"action",
"]",
"=",
"[",
"$",
"access",
"[",
"$",
"action",
"]",
"]",
";",
"}",
"foreach",
"(",
"$",
"access",
"[",
"$",
"action",
"]",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"isGranted",
"(",
"$",
"role",
",",
"$",
"object",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Hook to handle access authorization, without throw Exception.
@param string $action
@param object $object
@return bool | [
"Hook",
"to",
"handle",
"access",
"authorization",
"without",
"throw",
"Exception",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2591-L2610 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.getDashboardActions | public function getDashboardActions()
{
$actions = [];
if ($this->hasRoute('create') && $this->hasAccess('create')) {
$actions['create'] = [
'label' => 'link_add',
'translation_domain' => 'SonataAdminBundle',
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('action_create'),
// 'template' => $this->getTemplateRegistry()->getTemplate('action_create'),
'url' => $this->generateUrl('create'),
'icon' => 'plus-circle',
];
}
if ($this->hasRoute('list') && $this->hasAccess('list')) {
$actions['list'] = [
'label' => 'link_list',
'translation_domain' => 'SonataAdminBundle',
'url' => $this->generateUrl('list'),
'icon' => 'list',
];
}
return $actions;
} | php | public function getDashboardActions()
{
$actions = [];
if ($this->hasRoute('create') && $this->hasAccess('create')) {
$actions['create'] = [
'label' => 'link_add',
'translation_domain' => 'SonataAdminBundle',
// NEXT_MAJOR: Remove this line and use commented line below it instead
'template' => $this->getTemplate('action_create'),
// 'template' => $this->getTemplateRegistry()->getTemplate('action_create'),
'url' => $this->generateUrl('create'),
'icon' => 'plus-circle',
];
}
if ($this->hasRoute('list') && $this->hasAccess('list')) {
$actions['list'] = [
'label' => 'link_list',
'translation_domain' => 'SonataAdminBundle',
'url' => $this->generateUrl('list'),
'icon' => 'list',
];
}
return $actions;
} | [
"public",
"function",
"getDashboardActions",
"(",
")",
"{",
"$",
"actions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"hasRoute",
"(",
"'create'",
")",
"&&",
"$",
"this",
"->",
"hasAccess",
"(",
"'create'",
")",
")",
"{",
"$",
"actions",
"[",
"'create'",
"]",
"=",
"[",
"'label'",
"=>",
"'link_add'",
",",
"'translation_domain'",
"=>",
"'SonataAdminBundle'",
",",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"'template'",
"=>",
"$",
"this",
"->",
"getTemplate",
"(",
"'action_create'",
")",
",",
"// 'template' => $this->getTemplateRegistry()->getTemplate('action_create'),",
"'url'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'create'",
")",
",",
"'icon'",
"=>",
"'plus-circle'",
",",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasRoute",
"(",
"'list'",
")",
"&&",
"$",
"this",
"->",
"hasAccess",
"(",
"'list'",
")",
")",
"{",
"$",
"actions",
"[",
"'list'",
"]",
"=",
"[",
"'label'",
"=>",
"'link_list'",
",",
"'translation_domain'",
"=>",
"'SonataAdminBundle'",
",",
"'url'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'list'",
")",
",",
"'icon'",
"=>",
"'list'",
",",
"]",
";",
"}",
"return",
"$",
"actions",
";",
"}"
] | Get the list of actions that can be accessed directly from the dashboard.
@return array | [
"Get",
"the",
"list",
"of",
"actions",
"that",
"can",
"be",
"accessed",
"directly",
"from",
"the",
"dashboard",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2712-L2738 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.isDefaultFilter | final public function isDefaultFilter($name)
{
$filter = $this->getFilterParameters();
$default = $this->getDefaultFilterValues();
if (!\array_key_exists($name, $filter) || !\array_key_exists($name, $default)) {
return false;
}
return $filter[$name] === $default[$name];
} | php | final public function isDefaultFilter($name)
{
$filter = $this->getFilterParameters();
$default = $this->getDefaultFilterValues();
if (!\array_key_exists($name, $filter) || !\array_key_exists($name, $default)) {
return false;
}
return $filter[$name] === $default[$name];
} | [
"final",
"public",
"function",
"isDefaultFilter",
"(",
"$",
"name",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilterParameters",
"(",
")",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"getDefaultFilterValues",
"(",
")",
";",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"filter",
")",
"||",
"!",
"\\",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"default",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"filter",
"[",
"$",
"name",
"]",
"===",
"$",
"default",
"[",
"$",
"name",
"]",
";",
"}"
] | Checks if a filter type is set to a default value.
@param string $name
@return bool | [
"Checks",
"if",
"a",
"filter",
"type",
"is",
"set",
"to",
"a",
"default",
"value",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2774-L2784 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.canAccessObject | public function canAccessObject($action, $object)
{
return $object && $this->id($object) && $this->hasAccess($action, $object);
} | php | public function canAccessObject($action, $object)
{
return $object && $this->id($object) && $this->hasAccess($action, $object);
} | [
"public",
"function",
"canAccessObject",
"(",
"$",
"action",
",",
"$",
"object",
")",
"{",
"return",
"$",
"object",
"&&",
"$",
"this",
"->",
"id",
"(",
"$",
"object",
")",
"&&",
"$",
"this",
"->",
"hasAccess",
"(",
"$",
"action",
",",
"$",
"object",
")",
";",
"}"
] | Check object existence and access, without throw Exception.
@param string $action
@param object $object
@return bool | [
"Check",
"object",
"existence",
"and",
"access",
"without",
"throw",
"Exception",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2794-L2797 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.getDefaultFilterValues | final protected function getDefaultFilterValues()
{
$defaultFilterValues = [];
$this->configureDefaultFilterValues($defaultFilterValues);
foreach ($this->getExtensions() as $extension) {
// NEXT_MAJOR: remove method check in next major release
if (method_exists($extension, 'configureDefaultFilterValues')) {
$extension->configureDefaultFilterValues($this, $defaultFilterValues);
}
}
return $defaultFilterValues;
} | php | final protected function getDefaultFilterValues()
{
$defaultFilterValues = [];
$this->configureDefaultFilterValues($defaultFilterValues);
foreach ($this->getExtensions() as $extension) {
// NEXT_MAJOR: remove method check in next major release
if (method_exists($extension, 'configureDefaultFilterValues')) {
$extension->configureDefaultFilterValues($this, $defaultFilterValues);
}
}
return $defaultFilterValues;
} | [
"final",
"protected",
"function",
"getDefaultFilterValues",
"(",
")",
"{",
"$",
"defaultFilterValues",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"configureDefaultFilterValues",
"(",
"$",
"defaultFilterValues",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"// NEXT_MAJOR: remove method check in next major release",
"if",
"(",
"method_exists",
"(",
"$",
"extension",
",",
"'configureDefaultFilterValues'",
")",
")",
"{",
"$",
"extension",
"->",
"configureDefaultFilterValues",
"(",
"$",
"this",
",",
"$",
"defaultFilterValues",
")",
";",
"}",
"}",
"return",
"$",
"defaultFilterValues",
";",
"}"
] | Returns a list of default filters.
@return array | [
"Returns",
"a",
"list",
"of",
"default",
"filters",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2812-L2826 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.configureTabMenu | protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
// Use configureSideMenu not to mess with previous overrides
// TODO remove once deprecation period is over
$this->configureSideMenu($menu, $action, $childAdmin);
} | php | protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
// Use configureSideMenu not to mess with previous overrides
// TODO remove once deprecation period is over
$this->configureSideMenu($menu, $action, $childAdmin);
} | [
"protected",
"function",
"configureTabMenu",
"(",
"MenuItemInterface",
"$",
"menu",
",",
"$",
"action",
",",
"AdminInterface",
"$",
"childAdmin",
"=",
"null",
")",
"{",
"// Use configureSideMenu not to mess with previous overrides",
"// TODO remove once deprecation period is over",
"$",
"this",
"->",
"configureSideMenu",
"(",
"$",
"menu",
",",
"$",
"action",
",",
"$",
"childAdmin",
")",
";",
"}"
] | Configures the tab menu in your admin.
@param string $action
@return mixed | [
"Configures",
"the",
"tab",
"menu",
"in",
"your",
"admin",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2878-L2883 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.buildShow | protected function buildShow()
{
if ($this->show) {
return;
}
$this->show = new FieldDescriptionCollection();
$mapper = new ShowMapper($this->showBuilder, $this->show, $this);
$this->configureShowFields($mapper);
foreach ($this->getExtensions() as $extension) {
$extension->configureShowFields($mapper);
}
} | php | protected function buildShow()
{
if ($this->show) {
return;
}
$this->show = new FieldDescriptionCollection();
$mapper = new ShowMapper($this->showBuilder, $this->show, $this);
$this->configureShowFields($mapper);
foreach ($this->getExtensions() as $extension) {
$extension->configureShowFields($mapper);
}
} | [
"protected",
"function",
"buildShow",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"show",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"show",
"=",
"new",
"FieldDescriptionCollection",
"(",
")",
";",
"$",
"mapper",
"=",
"new",
"ShowMapper",
"(",
"$",
"this",
"->",
"showBuilder",
",",
"$",
"this",
"->",
"show",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"configureShowFields",
"(",
"$",
"mapper",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"configureShowFields",
"(",
"$",
"mapper",
")",
";",
"}",
"}"
] | build the view FieldDescription array. | [
"build",
"the",
"view",
"FieldDescription",
"array",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2888-L2902 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.buildList | protected function buildList()
{
if ($this->list) {
return;
}
$this->list = $this->getListBuilder()->getBaseList();
$mapper = new ListMapper($this->getListBuilder(), $this->list, $this);
if (\count($this->getBatchActions()) > 0 && $this->hasRequest() && !$this->getRequest()->isXmlHttpRequest()) {
$fieldDescription = $this->getModelManager()->getNewFieldDescriptionInstance(
$this->getClass(),
'batch',
[
'label' => 'batch',
'code' => '_batch',
'sortable' => false,
'virtual_field' => true,
]
);
$fieldDescription->setAdmin($this);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$fieldDescription->setTemplate($this->getTemplate('batch'));
// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch'));
$mapper->add($fieldDescription, 'batch');
}
$this->configureListFields($mapper);
foreach ($this->getExtensions() as $extension) {
$extension->configureListFields($mapper);
}
if ($this->hasRequest() && $this->getRequest()->isXmlHttpRequest()) {
$fieldDescription = $this->getModelManager()->getNewFieldDescriptionInstance(
$this->getClass(),
'select',
[
'label' => false,
'code' => '_select',
'sortable' => false,
'virtual_field' => false,
]
);
$fieldDescription->setAdmin($this);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$fieldDescription->setTemplate($this->getTemplate('select'));
// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select'));
$mapper->add($fieldDescription, 'select');
}
} | php | protected function buildList()
{
if ($this->list) {
return;
}
$this->list = $this->getListBuilder()->getBaseList();
$mapper = new ListMapper($this->getListBuilder(), $this->list, $this);
if (\count($this->getBatchActions()) > 0 && $this->hasRequest() && !$this->getRequest()->isXmlHttpRequest()) {
$fieldDescription = $this->getModelManager()->getNewFieldDescriptionInstance(
$this->getClass(),
'batch',
[
'label' => 'batch',
'code' => '_batch',
'sortable' => false,
'virtual_field' => true,
]
);
$fieldDescription->setAdmin($this);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$fieldDescription->setTemplate($this->getTemplate('batch'));
// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch'));
$mapper->add($fieldDescription, 'batch');
}
$this->configureListFields($mapper);
foreach ($this->getExtensions() as $extension) {
$extension->configureListFields($mapper);
}
if ($this->hasRequest() && $this->getRequest()->isXmlHttpRequest()) {
$fieldDescription = $this->getModelManager()->getNewFieldDescriptionInstance(
$this->getClass(),
'select',
[
'label' => false,
'code' => '_select',
'sortable' => false,
'virtual_field' => false,
]
);
$fieldDescription->setAdmin($this);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$fieldDescription->setTemplate($this->getTemplate('select'));
// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select'));
$mapper->add($fieldDescription, 'select');
}
} | [
"protected",
"function",
"buildList",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"list",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"list",
"=",
"$",
"this",
"->",
"getListBuilder",
"(",
")",
"->",
"getBaseList",
"(",
")",
";",
"$",
"mapper",
"=",
"new",
"ListMapper",
"(",
"$",
"this",
"->",
"getListBuilder",
"(",
")",
",",
"$",
"this",
"->",
"list",
",",
"$",
"this",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"getBatchActions",
"(",
")",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"hasRequest",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"$",
"fieldDescription",
"=",
"$",
"this",
"->",
"getModelManager",
"(",
")",
"->",
"getNewFieldDescriptionInstance",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
",",
"'batch'",
",",
"[",
"'label'",
"=>",
"'batch'",
",",
"'code'",
"=>",
"'_batch'",
",",
"'sortable'",
"=>",
"false",
",",
"'virtual_field'",
"=>",
"true",
",",
"]",
")",
";",
"$",
"fieldDescription",
"->",
"setAdmin",
"(",
"$",
"this",
")",
";",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"fieldDescription",
"->",
"setTemplate",
"(",
"$",
"this",
"->",
"getTemplate",
"(",
"'batch'",
")",
")",
";",
"// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch'));",
"$",
"mapper",
"->",
"add",
"(",
"$",
"fieldDescription",
",",
"'batch'",
")",
";",
"}",
"$",
"this",
"->",
"configureListFields",
"(",
"$",
"mapper",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"configureListFields",
"(",
"$",
"mapper",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasRequest",
"(",
")",
"&&",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"$",
"fieldDescription",
"=",
"$",
"this",
"->",
"getModelManager",
"(",
")",
"->",
"getNewFieldDescriptionInstance",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
",",
"'select'",
",",
"[",
"'label'",
"=>",
"false",
",",
"'code'",
"=>",
"'_select'",
",",
"'sortable'",
"=>",
"false",
",",
"'virtual_field'",
"=>",
"false",
",",
"]",
")",
";",
"$",
"fieldDescription",
"->",
"setAdmin",
"(",
"$",
"this",
")",
";",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"fieldDescription",
"->",
"setTemplate",
"(",
"$",
"this",
"->",
"getTemplate",
"(",
"'select'",
")",
")",
";",
"// $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select'));",
"$",
"mapper",
"->",
"add",
"(",
"$",
"fieldDescription",
",",
"'select'",
")",
";",
"}",
"}"
] | build the list FieldDescription array. | [
"build",
"the",
"list",
"FieldDescription",
"array",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2907-L2962 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.buildForm | protected function buildForm()
{
if ($this->form) {
return;
}
// append parent object if any
// todo : clean the way the Admin class can retrieve set the object
if ($this->isChild() && $this->getParentAssociationMapping()) {
$parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
$propertyAccessor = $this->getConfigurationPool()->getPropertyAccessor();
$propertyPath = new PropertyPath($this->getParentAssociationMapping());
$object = $this->getSubject();
$value = $propertyAccessor->getValue($object, $propertyPath);
if (\is_array($value) || ($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
$value[] = $parent;
$propertyAccessor->setValue($object, $propertyPath, $value);
} else {
$propertyAccessor->setValue($object, $propertyPath, $parent);
}
}
$formBuilder = $this->getFormBuilder();
$formBuilder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$this->preValidate($event->getData());
}, 100);
$this->form = $formBuilder->getForm();
} | php | protected function buildForm()
{
if ($this->form) {
return;
}
// append parent object if any
// todo : clean the way the Admin class can retrieve set the object
if ($this->isChild() && $this->getParentAssociationMapping()) {
$parent = $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
$propertyAccessor = $this->getConfigurationPool()->getPropertyAccessor();
$propertyPath = new PropertyPath($this->getParentAssociationMapping());
$object = $this->getSubject();
$value = $propertyAccessor->getValue($object, $propertyPath);
if (\is_array($value) || ($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
$value[] = $parent;
$propertyAccessor->setValue($object, $propertyPath, $value);
} else {
$propertyAccessor->setValue($object, $propertyPath, $parent);
}
}
$formBuilder = $this->getFormBuilder();
$formBuilder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$this->preValidate($event->getData());
}, 100);
$this->form = $formBuilder->getForm();
} | [
"protected",
"function",
"buildForm",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"form",
")",
"{",
"return",
";",
"}",
"// append parent object if any",
"// todo : clean the way the Admin class can retrieve set the object",
"if",
"(",
"$",
"this",
"->",
"isChild",
"(",
")",
"&&",
"$",
"this",
"->",
"getParentAssociationMapping",
"(",
")",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getObject",
"(",
"$",
"this",
"->",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getIdParameter",
"(",
")",
")",
")",
";",
"$",
"propertyAccessor",
"=",
"$",
"this",
"->",
"getConfigurationPool",
"(",
")",
"->",
"getPropertyAccessor",
"(",
")",
";",
"$",
"propertyPath",
"=",
"new",
"PropertyPath",
"(",
"$",
"this",
"->",
"getParentAssociationMapping",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getSubject",
"(",
")",
";",
"$",
"value",
"=",
"$",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"object",
",",
"$",
"propertyPath",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"value",
")",
"||",
"(",
"$",
"value",
"instanceof",
"\\",
"Traversable",
"&&",
"$",
"value",
"instanceof",
"\\",
"ArrayAccess",
")",
")",
"{",
"$",
"value",
"[",
"]",
"=",
"$",
"parent",
";",
"$",
"propertyAccessor",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"propertyPath",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"propertyAccessor",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"propertyPath",
",",
"$",
"parent",
")",
";",
"}",
"}",
"$",
"formBuilder",
"=",
"$",
"this",
"->",
"getFormBuilder",
"(",
")",
";",
"$",
"formBuilder",
"->",
"addEventListener",
"(",
"FormEvents",
"::",
"POST_SUBMIT",
",",
"function",
"(",
"FormEvent",
"$",
"event",
")",
"{",
"$",
"this",
"->",
"preValidate",
"(",
"$",
"event",
"->",
"getData",
"(",
")",
")",
";",
"}",
",",
"100",
")",
";",
"$",
"this",
"->",
"form",
"=",
"$",
"formBuilder",
"->",
"getForm",
"(",
")",
";",
"}"
] | Build the form FieldDescription collection. | [
"Build",
"the",
"form",
"FieldDescription",
"collection",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L2967-L2999 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.getSubClass | protected function getSubClass($name)
{
if ($this->hasSubClass($name)) {
return $this->subClasses[$name];
}
throw new \RuntimeException(sprintf(
'Unable to find the subclass `%s` for admin `%s`',
$name,
\get_class($this)
));
} | php | protected function getSubClass($name)
{
if ($this->hasSubClass($name)) {
return $this->subClasses[$name];
}
throw new \RuntimeException(sprintf(
'Unable to find the subclass `%s` for admin `%s`',
$name,
\get_class($this)
));
} | [
"protected",
"function",
"getSubClass",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSubClass",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"subClasses",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to find the subclass `%s` for admin `%s`'",
",",
"$",
"name",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}"
] | Gets the subclass corresponding to the given name.
@param string $name The name of the sub class
@return string the subclass | [
"Gets",
"the",
"subclass",
"corresponding",
"to",
"the",
"given",
"name",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L3008-L3019 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.attachInlineValidator | protected function attachInlineValidator()
{
$admin = $this;
// add the custom inline validation option
$metadata = $this->validator->getMetadataFor($this->getClass());
$metadata->addConstraint(new InlineConstraint([
'service' => $this,
'method' => static function (ErrorElement $errorElement, $object) use ($admin) {
/* @var \Sonata\AdminBundle\Admin\AdminInterface $admin */
// This avoid the main validation to be cascaded to children
// The problem occurs when a model Page has a collection of Page as property
if ($admin->hasSubject() && spl_object_hash($object) !== spl_object_hash($admin->getSubject())) {
return;
}
$admin->validate($errorElement, $object);
foreach ($admin->getExtensions() as $extension) {
$extension->validate($admin, $errorElement, $object);
}
},
'serializingWarning' => true,
]));
} | php | protected function attachInlineValidator()
{
$admin = $this;
// add the custom inline validation option
$metadata = $this->validator->getMetadataFor($this->getClass());
$metadata->addConstraint(new InlineConstraint([
'service' => $this,
'method' => static function (ErrorElement $errorElement, $object) use ($admin) {
/* @var \Sonata\AdminBundle\Admin\AdminInterface $admin */
// This avoid the main validation to be cascaded to children
// The problem occurs when a model Page has a collection of Page as property
if ($admin->hasSubject() && spl_object_hash($object) !== spl_object_hash($admin->getSubject())) {
return;
}
$admin->validate($errorElement, $object);
foreach ($admin->getExtensions() as $extension) {
$extension->validate($admin, $errorElement, $object);
}
},
'serializingWarning' => true,
]));
} | [
"protected",
"function",
"attachInlineValidator",
"(",
")",
"{",
"$",
"admin",
"=",
"$",
"this",
";",
"// add the custom inline validation option",
"$",
"metadata",
"=",
"$",
"this",
"->",
"validator",
"->",
"getMetadataFor",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
")",
";",
"$",
"metadata",
"->",
"addConstraint",
"(",
"new",
"InlineConstraint",
"(",
"[",
"'service'",
"=>",
"$",
"this",
",",
"'method'",
"=>",
"static",
"function",
"(",
"ErrorElement",
"$",
"errorElement",
",",
"$",
"object",
")",
"use",
"(",
"$",
"admin",
")",
"{",
"/* @var \\Sonata\\AdminBundle\\Admin\\AdminInterface $admin */",
"// This avoid the main validation to be cascaded to children",
"// The problem occurs when a model Page has a collection of Page as property",
"if",
"(",
"$",
"admin",
"->",
"hasSubject",
"(",
")",
"&&",
"spl_object_hash",
"(",
"$",
"object",
")",
"!==",
"spl_object_hash",
"(",
"$",
"admin",
"->",
"getSubject",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"admin",
"->",
"validate",
"(",
"$",
"errorElement",
",",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"admin",
"->",
"getExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"validate",
"(",
"$",
"admin",
",",
"$",
"errorElement",
",",
"$",
"object",
")",
";",
"}",
"}",
",",
"'serializingWarning'",
"=>",
"true",
",",
"]",
")",
")",
";",
"}"
] | Attach the inline validator to the model metadata, this must be done once per admin. | [
"Attach",
"the",
"inline",
"validator",
"to",
"the",
"model",
"metadata",
"this",
"must",
"be",
"done",
"once",
"per",
"admin",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L3024-L3050 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.predefinePerPageOptions | protected function predefinePerPageOptions()
{
array_unshift($this->perPageOptions, $this->maxPerPage);
$this->perPageOptions = array_unique($this->perPageOptions);
sort($this->perPageOptions);
} | php | protected function predefinePerPageOptions()
{
array_unshift($this->perPageOptions, $this->maxPerPage);
$this->perPageOptions = array_unique($this->perPageOptions);
sort($this->perPageOptions);
} | [
"protected",
"function",
"predefinePerPageOptions",
"(",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"perPageOptions",
",",
"$",
"this",
"->",
"maxPerPage",
")",
";",
"$",
"this",
"->",
"perPageOptions",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"perPageOptions",
")",
";",
"sort",
"(",
"$",
"this",
"->",
"perPageOptions",
")",
";",
"}"
] | Predefine per page options. | [
"Predefine",
"per",
"page",
"options",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L3055-L3060 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.getAccess | protected function getAccess()
{
$access = array_merge([
'acl' => 'MASTER',
'export' => 'EXPORT',
'historyCompareRevisions' => 'EDIT',
'historyViewRevision' => 'EDIT',
'history' => 'EDIT',
'edit' => 'EDIT',
'show' => 'VIEW',
'create' => 'CREATE',
'delete' => 'DELETE',
'batchDelete' => 'DELETE',
'list' => 'LIST',
], $this->getAccessMapping());
foreach ($this->extensions as $extension) {
// TODO: remove method check in next major release
if (method_exists($extension, 'getAccessMapping')) {
$access = array_merge($access, $extension->getAccessMapping($this));
}
}
return $access;
} | php | protected function getAccess()
{
$access = array_merge([
'acl' => 'MASTER',
'export' => 'EXPORT',
'historyCompareRevisions' => 'EDIT',
'historyViewRevision' => 'EDIT',
'history' => 'EDIT',
'edit' => 'EDIT',
'show' => 'VIEW',
'create' => 'CREATE',
'delete' => 'DELETE',
'batchDelete' => 'DELETE',
'list' => 'LIST',
], $this->getAccessMapping());
foreach ($this->extensions as $extension) {
// TODO: remove method check in next major release
if (method_exists($extension, 'getAccessMapping')) {
$access = array_merge($access, $extension->getAccessMapping($this));
}
}
return $access;
} | [
"protected",
"function",
"getAccess",
"(",
")",
"{",
"$",
"access",
"=",
"array_merge",
"(",
"[",
"'acl'",
"=>",
"'MASTER'",
",",
"'export'",
"=>",
"'EXPORT'",
",",
"'historyCompareRevisions'",
"=>",
"'EDIT'",
",",
"'historyViewRevision'",
"=>",
"'EDIT'",
",",
"'history'",
"=>",
"'EDIT'",
",",
"'edit'",
"=>",
"'EDIT'",
",",
"'show'",
"=>",
"'VIEW'",
",",
"'create'",
"=>",
"'CREATE'",
",",
"'delete'",
"=>",
"'DELETE'",
",",
"'batchDelete'",
"=>",
"'DELETE'",
",",
"'list'",
"=>",
"'LIST'",
",",
"]",
",",
"$",
"this",
"->",
"getAccessMapping",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"// TODO: remove method check in next major release",
"if",
"(",
"method_exists",
"(",
"$",
"extension",
",",
"'getAccessMapping'",
")",
")",
"{",
"$",
"access",
"=",
"array_merge",
"(",
"$",
"access",
",",
"$",
"extension",
"->",
"getAccessMapping",
"(",
"$",
"this",
")",
")",
";",
"}",
"}",
"return",
"$",
"access",
";",
"}"
] | Return list routes with permissions name.
@return array | [
"Return",
"list",
"routes",
"with",
"permissions",
"name",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L3067-L3091 | train |
sonata-project/SonataAdminBundle | src/Admin/AbstractAdmin.php | AbstractAdmin.buildRoutes | private function buildRoutes(): void
{
if ($this->loaded['routes']) {
return;
}
$this->loaded['routes'] = true;
$this->routes = new RouteCollection(
$this->getBaseCodeRoute(),
$this->getBaseRouteName(),
$this->getBaseRoutePattern(),
$this->getBaseControllerName()
);
$this->routeBuilder->build($this, $this->routes);
$this->configureRoutes($this->routes);
foreach ($this->getExtensions() as $extension) {
$extension->configureRoutes($this, $this->routes);
}
} | php | private function buildRoutes(): void
{
if ($this->loaded['routes']) {
return;
}
$this->loaded['routes'] = true;
$this->routes = new RouteCollection(
$this->getBaseCodeRoute(),
$this->getBaseRouteName(),
$this->getBaseRoutePattern(),
$this->getBaseControllerName()
);
$this->routeBuilder->build($this, $this->routes);
$this->configureRoutes($this->routes);
foreach ($this->getExtensions() as $extension) {
$extension->configureRoutes($this, $this->routes);
}
} | [
"private",
"function",
"buildRoutes",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"loaded",
"[",
"'routes'",
"]",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"loaded",
"[",
"'routes'",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"routes",
"=",
"new",
"RouteCollection",
"(",
"$",
"this",
"->",
"getBaseCodeRoute",
"(",
")",
",",
"$",
"this",
"->",
"getBaseRouteName",
"(",
")",
",",
"$",
"this",
"->",
"getBaseRoutePattern",
"(",
")",
",",
"$",
"this",
"->",
"getBaseControllerName",
"(",
")",
")",
";",
"$",
"this",
"->",
"routeBuilder",
"->",
"build",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"routes",
")",
";",
"$",
"this",
"->",
"configureRoutes",
"(",
"$",
"this",
"->",
"routes",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"configureRoutes",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"routes",
")",
";",
"}",
"}"
] | Build all the related urls to the current admin. | [
"Build",
"all",
"the",
"related",
"urls",
"to",
"the",
"current",
"admin",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Admin/AbstractAdmin.php#L3103-L3125 | train |
sonata-project/SonataAdminBundle | src/Route/RouteCollection.php | RouteCollection.actionify | public function actionify($action)
{
if (false !== ($pos = strrpos($action, '.'))) {
$action = substr($action, $pos + 1);
}
// if this is a service rather than just a controller name, the suffix
// Action is not automatically appended to the method name
if (false === strpos($this->baseControllerName, ':')) {
$action .= 'Action';
}
return lcfirst(str_replace(' ', '', ucwords(strtr($action, '_-', ' '))));
} | php | public function actionify($action)
{
if (false !== ($pos = strrpos($action, '.'))) {
$action = substr($action, $pos + 1);
}
// if this is a service rather than just a controller name, the suffix
// Action is not automatically appended to the method name
if (false === strpos($this->baseControllerName, ':')) {
$action .= 'Action';
}
return lcfirst(str_replace(' ', '', ucwords(strtr($action, '_-', ' '))));
} | [
"public",
"function",
"actionify",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"false",
"!==",
"(",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"action",
",",
"'.'",
")",
")",
")",
"{",
"$",
"action",
"=",
"substr",
"(",
"$",
"action",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"// if this is a service rather than just a controller name, the suffix",
"// Action is not automatically appended to the method name",
"if",
"(",
"false",
"===",
"strpos",
"(",
"$",
"this",
"->",
"baseControllerName",
",",
"':'",
")",
")",
"{",
"$",
"action",
".=",
"'Action'",
";",
"}",
"return",
"lcfirst",
"(",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"strtr",
"(",
"$",
"action",
",",
"'_-'",
",",
"' '",
")",
")",
")",
")",
";",
"}"
] | Convert a word in to the format for a symfony action action_name => actionName.
@param string $action Word to actionify
@return string Actionified word | [
"Convert",
"a",
"word",
"in",
"to",
"the",
"format",
"for",
"a",
"symfony",
"action",
"action_name",
"=",
">",
"actionName",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Route/RouteCollection.php#L237-L250 | train |
sonata-project/SonataAdminBundle | src/Menu/Provider/GroupMenuProvider.php | GroupMenuProvider.get | public function get($name, array $options = [])
{
$group = $options['group'];
$menuItem = $this->menuFactory->createItem($options['name']);
if (empty($group['on_top']) || false === $group['on_top']) {
foreach ($group['items'] as $item) {
if ($this->canGenerateMenuItem($item, $group)) {
$menuItem->addChild($this->generateMenuItem($item, $group));
}
}
if (false === $menuItem->hasChildren()) {
$menuItem->setDisplay(false);
} elseif (!empty($group['keep_open'])) {
$menuItem->setAttribute('class', 'keep-open');
$menuItem->setExtra('keep_open', $group['keep_open']);
}
} elseif (1 === \count($group['items'])) {
if ($this->canGenerateMenuItem($group['items'][0], $group)) {
$menuItem = $this->generateMenuItem($group['items'][0], $group);
$menuItem->setExtra('on_top', $group['on_top']);
} else {
$menuItem->setDisplay(false);
}
}
$menuItem->setLabel($group['label']);
return $menuItem;
} | php | public function get($name, array $options = [])
{
$group = $options['group'];
$menuItem = $this->menuFactory->createItem($options['name']);
if (empty($group['on_top']) || false === $group['on_top']) {
foreach ($group['items'] as $item) {
if ($this->canGenerateMenuItem($item, $group)) {
$menuItem->addChild($this->generateMenuItem($item, $group));
}
}
if (false === $menuItem->hasChildren()) {
$menuItem->setDisplay(false);
} elseif (!empty($group['keep_open'])) {
$menuItem->setAttribute('class', 'keep-open');
$menuItem->setExtra('keep_open', $group['keep_open']);
}
} elseif (1 === \count($group['items'])) {
if ($this->canGenerateMenuItem($group['items'][0], $group)) {
$menuItem = $this->generateMenuItem($group['items'][0], $group);
$menuItem->setExtra('on_top', $group['on_top']);
} else {
$menuItem->setDisplay(false);
}
}
$menuItem->setLabel($group['label']);
return $menuItem;
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"group",
"=",
"$",
"options",
"[",
"'group'",
"]",
";",
"$",
"menuItem",
"=",
"$",
"this",
"->",
"menuFactory",
"->",
"createItem",
"(",
"$",
"options",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"group",
"[",
"'on_top'",
"]",
")",
"||",
"false",
"===",
"$",
"group",
"[",
"'on_top'",
"]",
")",
"{",
"foreach",
"(",
"$",
"group",
"[",
"'items'",
"]",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"canGenerateMenuItem",
"(",
"$",
"item",
",",
"$",
"group",
")",
")",
"{",
"$",
"menuItem",
"->",
"addChild",
"(",
"$",
"this",
"->",
"generateMenuItem",
"(",
"$",
"item",
",",
"$",
"group",
")",
")",
";",
"}",
"}",
"if",
"(",
"false",
"===",
"$",
"menuItem",
"->",
"hasChildren",
"(",
")",
")",
"{",
"$",
"menuItem",
"->",
"setDisplay",
"(",
"false",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"group",
"[",
"'keep_open'",
"]",
")",
")",
"{",
"$",
"menuItem",
"->",
"setAttribute",
"(",
"'class'",
",",
"'keep-open'",
")",
";",
"$",
"menuItem",
"->",
"setExtra",
"(",
"'keep_open'",
",",
"$",
"group",
"[",
"'keep_open'",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"1",
"===",
"\\",
"count",
"(",
"$",
"group",
"[",
"'items'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"canGenerateMenuItem",
"(",
"$",
"group",
"[",
"'items'",
"]",
"[",
"0",
"]",
",",
"$",
"group",
")",
")",
"{",
"$",
"menuItem",
"=",
"$",
"this",
"->",
"generateMenuItem",
"(",
"$",
"group",
"[",
"'items'",
"]",
"[",
"0",
"]",
",",
"$",
"group",
")",
";",
"$",
"menuItem",
"->",
"setExtra",
"(",
"'on_top'",
",",
"$",
"group",
"[",
"'on_top'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"menuItem",
"->",
"setDisplay",
"(",
"false",
")",
";",
"}",
"}",
"$",
"menuItem",
"->",
"setLabel",
"(",
"$",
"group",
"[",
"'label'",
"]",
")",
";",
"return",
"$",
"menuItem",
";",
"}"
] | Retrieves the menu based on the group options.
@param string $name
@throws \InvalidArgumentException if the menu does not exists
@return \Knp\Menu\ItemInterface | [
"Retrieves",
"the",
"menu",
"based",
"on",
"the",
"group",
"options",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Menu/Provider/GroupMenuProvider.php#L82-L112 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.renderWithExtraParams | public function renderWithExtraParams($view, array $parameters = [], Response $response = null)
{
if (!$this->isXmlHttpRequest()) {
$parameters['breadcrumbs_builder'] = $this->get('sonata.admin.breadcrumbs_builder');
}
$parameters['admin'] = $parameters['admin'] ??
$this->admin;
$parameters['base_template'] = $parameters['base_template'] ??
$this->getBaseTemplate();
$parameters['admin_pool'] = $this->get('sonata.admin.pool');
//NEXT_MAJOR: Remove method alias and use $this->render() directly.
return $this->originalRender($view, $parameters, $response);
} | php | public function renderWithExtraParams($view, array $parameters = [], Response $response = null)
{
if (!$this->isXmlHttpRequest()) {
$parameters['breadcrumbs_builder'] = $this->get('sonata.admin.breadcrumbs_builder');
}
$parameters['admin'] = $parameters['admin'] ??
$this->admin;
$parameters['base_template'] = $parameters['base_template'] ??
$this->getBaseTemplate();
$parameters['admin_pool'] = $this->get('sonata.admin.pool');
//NEXT_MAJOR: Remove method alias and use $this->render() directly.
return $this->originalRender($view, $parameters, $response);
} | [
"public",
"function",
"renderWithExtraParams",
"(",
"$",
"view",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"Response",
"$",
"response",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"$",
"parameters",
"[",
"'breadcrumbs_builder'",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.breadcrumbs_builder'",
")",
";",
"}",
"$",
"parameters",
"[",
"'admin'",
"]",
"=",
"$",
"parameters",
"[",
"'admin'",
"]",
"??",
"$",
"this",
"->",
"admin",
";",
"$",
"parameters",
"[",
"'base_template'",
"]",
"=",
"$",
"parameters",
"[",
"'base_template'",
"]",
"??",
"$",
"this",
"->",
"getBaseTemplate",
"(",
")",
";",
"$",
"parameters",
"[",
"'admin_pool'",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.pool'",
")",
";",
"//NEXT_MAJOR: Remove method alias and use $this->render() directly.",
"return",
"$",
"this",
"->",
"originalRender",
"(",
"$",
"view",
",",
"$",
"parameters",
",",
"$",
"response",
")",
";",
"}"
] | Renders a view while passing mandatory parameters on to the template.
@param string $view The view name
@return Response A Response instance | [
"Renders",
"a",
"view",
"while",
"passing",
"mandatory",
"parameters",
"on",
"to",
"the",
"template",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L128-L143 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.batchActionDelete | public function batchActionDelete(ProxyQueryInterface $query)
{
$this->admin->checkAccess('batchDelete');
$modelManager = $this->admin->getModelManager();
try {
$modelManager->batchDelete($this->admin->getClass(), $query);
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_batch_delete_success', [], 'SonataAdminBundle')
);
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash(
'sonata_flash_error',
$this->trans('flash_batch_delete_error', [], 'SonataAdminBundle')
);
}
return $this->redirectToList();
} | php | public function batchActionDelete(ProxyQueryInterface $query)
{
$this->admin->checkAccess('batchDelete');
$modelManager = $this->admin->getModelManager();
try {
$modelManager->batchDelete($this->admin->getClass(), $query);
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_batch_delete_success', [], 'SonataAdminBundle')
);
} catch (ModelManagerException $e) {
$this->handleModelManagerException($e);
$this->addFlash(
'sonata_flash_error',
$this->trans('flash_batch_delete_error', [], 'SonataAdminBundle')
);
}
return $this->redirectToList();
} | [
"public",
"function",
"batchActionDelete",
"(",
"ProxyQueryInterface",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'batchDelete'",
")",
";",
"$",
"modelManager",
"=",
"$",
"this",
"->",
"admin",
"->",
"getModelManager",
"(",
")",
";",
"try",
"{",
"$",
"modelManager",
"->",
"batchDelete",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
",",
"$",
"query",
")",
";",
"$",
"this",
"->",
"addFlash",
"(",
"'sonata_flash_success'",
",",
"$",
"this",
"->",
"trans",
"(",
"'flash_batch_delete_success'",
",",
"[",
"]",
",",
"'SonataAdminBundle'",
")",
")",
";",
"}",
"catch",
"(",
"ModelManagerException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleModelManagerException",
"(",
"$",
"e",
")",
";",
"$",
"this",
"->",
"addFlash",
"(",
"'sonata_flash_error'",
",",
"$",
"this",
"->",
"trans",
"(",
"'flash_batch_delete_error'",
",",
"[",
"]",
",",
"'SonataAdminBundle'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectToList",
"(",
")",
";",
"}"
] | Execute a batch delete.
@throws AccessDeniedException If access is not granted
@return RedirectResponse | [
"Execute",
"a",
"batch",
"delete",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L195-L216 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.showAction | public function showAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->checkParentChildAssociation($request, $object);
$this->admin->checkAccess('show', $object);
$preResponse = $this->preShow($request, $object);
if (null !== $preResponse) {
return $preResponse;
}
$this->admin->setSubject($object);
$fields = $this->admin->getShow();
\assert($fields instanceof FieldDescriptionCollection);
// NEXT_MAJOR: replace deprecation with exception
if (!\is_array($fields->getElements()) || 0 === $fields->count()) {
@trigger_error(
'Calling this method without implementing "configureShowFields"'
.' is not supported since 3.40.0'
.' and will no longer be possible in 4.0',
E_USER_DEPRECATED
);
}
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('show');
//$template = $this->templateRegistry->getTemplate('show');
return $this->renderWithExtraParams($template, [
'action' => 'show',
'object' => $object,
'elements' => $fields,
], null);
} | php | public function showAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->checkParentChildAssociation($request, $object);
$this->admin->checkAccess('show', $object);
$preResponse = $this->preShow($request, $object);
if (null !== $preResponse) {
return $preResponse;
}
$this->admin->setSubject($object);
$fields = $this->admin->getShow();
\assert($fields instanceof FieldDescriptionCollection);
// NEXT_MAJOR: replace deprecation with exception
if (!\is_array($fields->getElements()) || 0 === $fields->count()) {
@trigger_error(
'Calling this method without implementing "configureShowFields"'
.' is not supported since 3.40.0'
.' and will no longer be possible in 4.0',
E_USER_DEPRECATED
);
}
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('show');
//$template = $this->templateRegistry->getTemplate('show');
return $this->renderWithExtraParams($template, [
'action' => 'show',
'object' => $object,
'elements' => $fields,
], null);
} | [
"public",
"function",
"showAction",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the object with id: %s'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"checkParentChildAssociation",
"(",
"$",
"request",
",",
"$",
"object",
")",
";",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'show'",
",",
"$",
"object",
")",
";",
"$",
"preResponse",
"=",
"$",
"this",
"->",
"preShow",
"(",
"$",
"request",
",",
"$",
"object",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"preResponse",
")",
"{",
"return",
"$",
"preResponse",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"setSubject",
"(",
"$",
"object",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"admin",
"->",
"getShow",
"(",
")",
";",
"\\",
"assert",
"(",
"$",
"fields",
"instanceof",
"FieldDescriptionCollection",
")",
";",
"// NEXT_MAJOR: replace deprecation with exception",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"fields",
"->",
"getElements",
"(",
")",
")",
"||",
"0",
"===",
"$",
"fields",
"->",
"count",
"(",
")",
")",
"{",
"@",
"trigger_error",
"(",
"'Calling this method without implementing \"configureShowFields\"'",
".",
"' is not supported since 3.40.0'",
".",
"' and will no longer be possible in 4.0'",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"template",
"=",
"$",
"this",
"->",
"admin",
"->",
"getTemplate",
"(",
"'show'",
")",
";",
"//$template = $this->templateRegistry->getTemplate('show');",
"return",
"$",
"this",
"->",
"renderWithExtraParams",
"(",
"$",
"template",
",",
"[",
"'action'",
"=>",
"'show'",
",",
"'object'",
"=>",
"$",
"object",
",",
"'elements'",
"=>",
"$",
"fields",
",",
"]",
",",
"null",
")",
";",
"}"
] | Show action.
@param int|string|null $id
@throws NotFoundHttpException If the object does not exist
@throws AccessDeniedException If access is not granted
@return Response | [
"Show",
"action",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L692-L736 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.historyAction | public function historyAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('history', $object);
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw $this->createNotFoundException(
sprintf(
'unable to find the audit reader for class : %s',
$this->admin->getClass()
)
);
}
$reader = $manager->getReader($this->admin->getClass());
$revisions = $reader->findRevisions($this->admin->getClass(), $id);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('history');
// $template = $this->templateRegistry->getTemplate('history');
return $this->renderWithExtraParams($template, [
'action' => 'history',
'object' => $object,
'revisions' => $revisions,
'currentRevision' => $revisions ? current($revisions) : false,
], null);
} | php | public function historyAction($id = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('history', $object);
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw $this->createNotFoundException(
sprintf(
'unable to find the audit reader for class : %s',
$this->admin->getClass()
)
);
}
$reader = $manager->getReader($this->admin->getClass());
$revisions = $reader->findRevisions($this->admin->getClass(), $id);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('history');
// $template = $this->templateRegistry->getTemplate('history');
return $this->renderWithExtraParams($template, [
'action' => 'history',
'object' => $object,
'revisions' => $revisions,
'currentRevision' => $revisions ? current($revisions) : false,
], null);
} | [
"public",
"function",
"historyAction",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the object with id: %s'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'history'",
",",
"$",
"object",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.audit.manager'",
")",
";",
"if",
"(",
"!",
"$",
"manager",
"->",
"hasReader",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the audit reader for class : %s'",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"$",
"reader",
"=",
"$",
"manager",
"->",
"getReader",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
";",
"$",
"revisions",
"=",
"$",
"reader",
"->",
"findRevisions",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
",",
"$",
"id",
")",
";",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"template",
"=",
"$",
"this",
"->",
"admin",
"->",
"getTemplate",
"(",
"'history'",
")",
";",
"// $template = $this->templateRegistry->getTemplate('history');",
"return",
"$",
"this",
"->",
"renderWithExtraParams",
"(",
"$",
"template",
",",
"[",
"'action'",
"=>",
"'history'",
",",
"'object'",
"=>",
"$",
"object",
",",
"'revisions'",
"=>",
"$",
"revisions",
",",
"'currentRevision'",
"=>",
"$",
"revisions",
"?",
"current",
"(",
"$",
"revisions",
")",
":",
"false",
",",
"]",
",",
"null",
")",
";",
"}"
] | Show history revisions for object.
@param int|string|null $id
@throws AccessDeniedException If access is not granted
@throws NotFoundHttpException If the object does not exist or the audit reader is not available
@return Response | [
"Show",
"history",
"revisions",
"for",
"object",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L748-L786 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.historyViewRevisionAction | public function historyViewRevisionAction($id = null, $revision = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('historyViewRevision', $object);
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw $this->createNotFoundException(
sprintf(
'unable to find the audit reader for class : %s',
$this->admin->getClass()
)
);
}
$reader = $manager->getReader($this->admin->getClass());
// retrieve the revisioned object
$object = $reader->find($this->admin->getClass(), $id, $revision);
if (!$object) {
throw $this->createNotFoundException(
sprintf(
'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`',
$id,
$revision,
$this->admin->getClass()
)
);
}
$this->admin->setSubject($object);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('show');
// $template = $this->templateRegistry->getTemplate('show');
return $this->renderWithExtraParams($template, [
'action' => 'show',
'object' => $object,
'elements' => $this->admin->getShow(),
], null);
} | php | public function historyViewRevisionAction($id = null, $revision = null)
{
$request = $this->getRequest();
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('historyViewRevision', $object);
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw $this->createNotFoundException(
sprintf(
'unable to find the audit reader for class : %s',
$this->admin->getClass()
)
);
}
$reader = $manager->getReader($this->admin->getClass());
// retrieve the revisioned object
$object = $reader->find($this->admin->getClass(), $id, $revision);
if (!$object) {
throw $this->createNotFoundException(
sprintf(
'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`',
$id,
$revision,
$this->admin->getClass()
)
);
}
$this->admin->setSubject($object);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('show');
// $template = $this->templateRegistry->getTemplate('show');
return $this->renderWithExtraParams($template, [
'action' => 'show',
'object' => $object,
'elements' => $this->admin->getShow(),
], null);
} | [
"public",
"function",
"historyViewRevisionAction",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"revision",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the object with id: %s'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'historyViewRevision'",
",",
"$",
"object",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.audit.manager'",
")",
";",
"if",
"(",
"!",
"$",
"manager",
"->",
"hasReader",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the audit reader for class : %s'",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"$",
"reader",
"=",
"$",
"manager",
"->",
"getReader",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
";",
"// retrieve the revisioned object",
"$",
"object",
"=",
"$",
"reader",
"->",
"find",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
",",
"$",
"id",
",",
"$",
"revision",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`'",
",",
"$",
"id",
",",
"$",
"revision",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"setSubject",
"(",
"$",
"object",
")",
";",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"template",
"=",
"$",
"this",
"->",
"admin",
"->",
"getTemplate",
"(",
"'show'",
")",
";",
"// $template = $this->templateRegistry->getTemplate('show');",
"return",
"$",
"this",
"->",
"renderWithExtraParams",
"(",
"$",
"template",
",",
"[",
"'action'",
"=>",
"'show'",
",",
"'object'",
"=>",
"$",
"object",
",",
"'elements'",
"=>",
"$",
"this",
"->",
"admin",
"->",
"getShow",
"(",
")",
",",
"]",
",",
"null",
")",
";",
"}"
] | View history revision of object.
@param int|string|null $id
@param string|null $revision
@throws AccessDeniedException If access is not granted
@throws NotFoundHttpException If the object or revision does not exist or the audit reader is not available
@return Response | [
"View",
"history",
"revision",
"of",
"object",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L799-L850 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.historyCompareRevisionsAction | public function historyCompareRevisionsAction($id = null, $base_revision = null, $compare_revision = null)
{
$request = $this->getRequest();
$this->admin->checkAccess('historyCompareRevisions');
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw $this->createNotFoundException(
sprintf(
'unable to find the audit reader for class : %s',
$this->admin->getClass()
)
);
}
$reader = $manager->getReader($this->admin->getClass());
// retrieve the base revision
$base_object = $reader->find($this->admin->getClass(), $id, $base_revision);
if (!$base_object) {
throw $this->createNotFoundException(
sprintf(
'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`',
$id,
$base_revision,
$this->admin->getClass()
)
);
}
// retrieve the compare revision
$compare_object = $reader->find($this->admin->getClass(), $id, $compare_revision);
if (!$compare_object) {
throw $this->createNotFoundException(
sprintf(
'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`',
$id,
$compare_revision,
$this->admin->getClass()
)
);
}
$this->admin->setSubject($base_object);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('show_compare');
// $template = $this->templateRegistry->getTemplate('show_compare');
return $this->renderWithExtraParams($template, [
'action' => 'show',
'object' => $base_object,
'object_compare' => $compare_object,
'elements' => $this->admin->getShow(),
], null);
} | php | public function historyCompareRevisionsAction($id = null, $base_revision = null, $compare_revision = null)
{
$request = $this->getRequest();
$this->admin->checkAccess('historyCompareRevisions');
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$manager = $this->get('sonata.admin.audit.manager');
if (!$manager->hasReader($this->admin->getClass())) {
throw $this->createNotFoundException(
sprintf(
'unable to find the audit reader for class : %s',
$this->admin->getClass()
)
);
}
$reader = $manager->getReader($this->admin->getClass());
// retrieve the base revision
$base_object = $reader->find($this->admin->getClass(), $id, $base_revision);
if (!$base_object) {
throw $this->createNotFoundException(
sprintf(
'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`',
$id,
$base_revision,
$this->admin->getClass()
)
);
}
// retrieve the compare revision
$compare_object = $reader->find($this->admin->getClass(), $id, $compare_revision);
if (!$compare_object) {
throw $this->createNotFoundException(
sprintf(
'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`',
$id,
$compare_revision,
$this->admin->getClass()
)
);
}
$this->admin->setSubject($base_object);
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('show_compare');
// $template = $this->templateRegistry->getTemplate('show_compare');
return $this->renderWithExtraParams($template, [
'action' => 'show',
'object' => $base_object,
'object_compare' => $compare_object,
'elements' => $this->admin->getShow(),
], null);
} | [
"public",
"function",
"historyCompareRevisionsAction",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"base_revision",
"=",
"null",
",",
"$",
"compare_revision",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'historyCompareRevisions'",
")",
";",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the object with id: %s'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"manager",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.audit.manager'",
")",
";",
"if",
"(",
"!",
"$",
"manager",
"->",
"hasReader",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the audit reader for class : %s'",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"$",
"reader",
"=",
"$",
"manager",
"->",
"getReader",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
";",
"// retrieve the base revision",
"$",
"base_object",
"=",
"$",
"reader",
"->",
"find",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
",",
"$",
"id",
",",
"$",
"base_revision",
")",
";",
"if",
"(",
"!",
"$",
"base_object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`'",
",",
"$",
"id",
",",
"$",
"base_revision",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"// retrieve the compare revision",
"$",
"compare_object",
"=",
"$",
"reader",
"->",
"find",
"(",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
",",
"$",
"id",
",",
"$",
"compare_revision",
")",
";",
"if",
"(",
"!",
"$",
"compare_object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`'",
",",
"$",
"id",
",",
"$",
"compare_revision",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"setSubject",
"(",
"$",
"base_object",
")",
";",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"template",
"=",
"$",
"this",
"->",
"admin",
"->",
"getTemplate",
"(",
"'show_compare'",
")",
";",
"// $template = $this->templateRegistry->getTemplate('show_compare');",
"return",
"$",
"this",
"->",
"renderWithExtraParams",
"(",
"$",
"template",
",",
"[",
"'action'",
"=>",
"'show'",
",",
"'object'",
"=>",
"$",
"base_object",
",",
"'object_compare'",
"=>",
"$",
"compare_object",
",",
"'elements'",
"=>",
"$",
"this",
"->",
"admin",
"->",
"getShow",
"(",
")",
",",
"]",
",",
"null",
")",
";",
"}"
] | Compare history revisions of object.
@param int|string|null $id
@param int|string|null $base_revision
@param int|string|null $compare_revision
@throws AccessDeniedException If access is not granted
@throws NotFoundHttpException If the object or revision does not exist or the audit reader is not available
@return Response | [
"Compare",
"history",
"revisions",
"of",
"object",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L864-L929 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.exportAction | public function exportAction(Request $request)
{
$this->admin->checkAccess('export');
$format = $request->get('format');
// NEXT_MAJOR: remove the check
if (!$this->has('sonata.admin.admin_exporter')) {
@trigger_error(
'Not registering the exporter bundle is deprecated since version 3.14.'
.' You must register it to be able to use the export action in 4.0.',
E_USER_DEPRECATED
);
$allowedExportFormats = (array) $this->admin->getExportFormats();
$class = (string) $this->admin->getClass();
$filename = sprintf(
'export_%s_%s.%s',
strtolower((string) substr($class, strripos($class, '\\') + 1)),
date('Y_m_d_H_i_s', strtotime('now')),
$format
);
$exporter = $this->get('sonata.admin.exporter');
} else {
$adminExporter = $this->get('sonata.admin.admin_exporter');
$allowedExportFormats = $adminExporter->getAvailableFormats($this->admin);
$filename = $adminExporter->getExportFilename($this->admin, $format);
$exporter = $this->get('sonata.exporter.exporter');
}
if (!\in_array($format, $allowedExportFormats, true)) {
throw new \RuntimeException(
sprintf(
'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`',
$format,
$this->admin->getClass(),
implode(', ', $allowedExportFormats)
)
);
}
return $exporter->getResponse(
$format,
$filename,
$this->admin->getDataSourceIterator()
);
} | php | public function exportAction(Request $request)
{
$this->admin->checkAccess('export');
$format = $request->get('format');
// NEXT_MAJOR: remove the check
if (!$this->has('sonata.admin.admin_exporter')) {
@trigger_error(
'Not registering the exporter bundle is deprecated since version 3.14.'
.' You must register it to be able to use the export action in 4.0.',
E_USER_DEPRECATED
);
$allowedExportFormats = (array) $this->admin->getExportFormats();
$class = (string) $this->admin->getClass();
$filename = sprintf(
'export_%s_%s.%s',
strtolower((string) substr($class, strripos($class, '\\') + 1)),
date('Y_m_d_H_i_s', strtotime('now')),
$format
);
$exporter = $this->get('sonata.admin.exporter');
} else {
$adminExporter = $this->get('sonata.admin.admin_exporter');
$allowedExportFormats = $adminExporter->getAvailableFormats($this->admin);
$filename = $adminExporter->getExportFilename($this->admin, $format);
$exporter = $this->get('sonata.exporter.exporter');
}
if (!\in_array($format, $allowedExportFormats, true)) {
throw new \RuntimeException(
sprintf(
'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`',
$format,
$this->admin->getClass(),
implode(', ', $allowedExportFormats)
)
);
}
return $exporter->getResponse(
$format,
$filename,
$this->admin->getDataSourceIterator()
);
} | [
"public",
"function",
"exportAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'export'",
")",
";",
"$",
"format",
"=",
"$",
"request",
"->",
"get",
"(",
"'format'",
")",
";",
"// NEXT_MAJOR: remove the check",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"'sonata.admin.admin_exporter'",
")",
")",
"{",
"@",
"trigger_error",
"(",
"'Not registering the exporter bundle is deprecated since version 3.14.'",
".",
"' You must register it to be able to use the export action in 4.0.'",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"allowedExportFormats",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"admin",
"->",
"getExportFormats",
"(",
")",
";",
"$",
"class",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
";",
"$",
"filename",
"=",
"sprintf",
"(",
"'export_%s_%s.%s'",
",",
"strtolower",
"(",
"(",
"string",
")",
"substr",
"(",
"$",
"class",
",",
"strripos",
"(",
"$",
"class",
",",
"'\\\\'",
")",
"+",
"1",
")",
")",
",",
"date",
"(",
"'Y_m_d_H_i_s'",
",",
"strtotime",
"(",
"'now'",
")",
")",
",",
"$",
"format",
")",
";",
"$",
"exporter",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.exporter'",
")",
";",
"}",
"else",
"{",
"$",
"adminExporter",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.admin_exporter'",
")",
";",
"$",
"allowedExportFormats",
"=",
"$",
"adminExporter",
"->",
"getAvailableFormats",
"(",
"$",
"this",
"->",
"admin",
")",
";",
"$",
"filename",
"=",
"$",
"adminExporter",
"->",
"getExportFilename",
"(",
"$",
"this",
"->",
"admin",
",",
"$",
"format",
")",
";",
"$",
"exporter",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.exporter.exporter'",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"format",
",",
"$",
"allowedExportFormats",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`'",
",",
"$",
"format",
",",
"$",
"this",
"->",
"admin",
"->",
"getClass",
"(",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"allowedExportFormats",
")",
")",
")",
";",
"}",
"return",
"$",
"exporter",
"->",
"getResponse",
"(",
"$",
"format",
",",
"$",
"filename",
",",
"$",
"this",
"->",
"admin",
"->",
"getDataSourceIterator",
"(",
")",
")",
";",
"}"
] | Export data to specified format.
@throws AccessDeniedException If access is not granted
@throws \RuntimeException If the export format is invalid
@return Response | [
"Export",
"data",
"to",
"specified",
"format",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L939-L985 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.aclAction | public function aclAction($id = null)
{
$request = $this->getRequest();
if (!$this->admin->isAclEnabled()) {
throw $this->createNotFoundException('ACL are not enabled for this admin');
}
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('acl', $object);
$this->admin->setSubject($object);
$aclUsers = $this->getAclUsers();
$aclRoles = $this->getAclRoles();
$adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
$adminObjectAclData = new AdminObjectAclData(
$this->admin,
$object,
$aclUsers,
$adminObjectAclManipulator->getMaskBuilderClass(),
$aclRoles
);
$aclUsersForm = $adminObjectAclManipulator->createAclUsersForm($adminObjectAclData);
$aclRolesForm = $adminObjectAclManipulator->createAclRolesForm($adminObjectAclData);
if ('POST' === $request->getMethod()) {
if ($request->request->has(AdminObjectAclManipulator::ACL_USERS_FORM_NAME)) {
$form = $aclUsersForm;
$updateMethod = 'updateAclUsers';
} elseif ($request->request->has(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME)) {
$form = $aclRolesForm;
$updateMethod = 'updateAclRoles';
}
if (isset($form)) {
$form->handleRequest($request);
if ($form->isValid()) {
$adminObjectAclManipulator->$updateMethod($adminObjectAclData);
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_acl_edit_success', [], 'SonataAdminBundle')
);
return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
}
}
}
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('acl');
// $template = $this->templateRegistry->getTemplate('acl');
return $this->renderWithExtraParams($template, [
'action' => 'acl',
'permissions' => $adminObjectAclData->getUserPermissions(),
'object' => $object,
'users' => $aclUsers,
'roles' => $aclRoles,
'aclUsersForm' => $aclUsersForm->createView(),
'aclRolesForm' => $aclRolesForm->createView(),
], null);
} | php | public function aclAction($id = null)
{
$request = $this->getRequest();
if (!$this->admin->isAclEnabled()) {
throw $this->createNotFoundException('ACL are not enabled for this admin');
}
$id = $request->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw $this->createNotFoundException(sprintf('unable to find the object with id: %s', $id));
}
$this->admin->checkAccess('acl', $object);
$this->admin->setSubject($object);
$aclUsers = $this->getAclUsers();
$aclRoles = $this->getAclRoles();
$adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
$adminObjectAclData = new AdminObjectAclData(
$this->admin,
$object,
$aclUsers,
$adminObjectAclManipulator->getMaskBuilderClass(),
$aclRoles
);
$aclUsersForm = $adminObjectAclManipulator->createAclUsersForm($adminObjectAclData);
$aclRolesForm = $adminObjectAclManipulator->createAclRolesForm($adminObjectAclData);
if ('POST' === $request->getMethod()) {
if ($request->request->has(AdminObjectAclManipulator::ACL_USERS_FORM_NAME)) {
$form = $aclUsersForm;
$updateMethod = 'updateAclUsers';
} elseif ($request->request->has(AdminObjectAclManipulator::ACL_ROLES_FORM_NAME)) {
$form = $aclRolesForm;
$updateMethod = 'updateAclRoles';
}
if (isset($form)) {
$form->handleRequest($request);
if ($form->isValid()) {
$adminObjectAclManipulator->$updateMethod($adminObjectAclData);
$this->addFlash(
'sonata_flash_success',
$this->trans('flash_acl_edit_success', [], 'SonataAdminBundle')
);
return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
}
}
}
// NEXT_MAJOR: Remove this line and use commented line below it instead
$template = $this->admin->getTemplate('acl');
// $template = $this->templateRegistry->getTemplate('acl');
return $this->renderWithExtraParams($template, [
'action' => 'acl',
'permissions' => $adminObjectAclData->getUserPermissions(),
'object' => $object,
'users' => $aclUsers,
'roles' => $aclRoles,
'aclUsersForm' => $aclUsersForm->createView(),
'aclRolesForm' => $aclRolesForm->createView(),
], null);
} | [
"public",
"function",
"aclAction",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"admin",
"->",
"isAclEnabled",
"(",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'ACL are not enabled for this admin'",
")",
";",
"}",
"$",
"id",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"sprintf",
"(",
"'unable to find the object with id: %s'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"->",
"checkAccess",
"(",
"'acl'",
",",
"$",
"object",
")",
";",
"$",
"this",
"->",
"admin",
"->",
"setSubject",
"(",
"$",
"object",
")",
";",
"$",
"aclUsers",
"=",
"$",
"this",
"->",
"getAclUsers",
"(",
")",
";",
"$",
"aclRoles",
"=",
"$",
"this",
"->",
"getAclRoles",
"(",
")",
";",
"$",
"adminObjectAclManipulator",
"=",
"$",
"this",
"->",
"get",
"(",
"'sonata.admin.object.manipulator.acl.admin'",
")",
";",
"$",
"adminObjectAclData",
"=",
"new",
"AdminObjectAclData",
"(",
"$",
"this",
"->",
"admin",
",",
"$",
"object",
",",
"$",
"aclUsers",
",",
"$",
"adminObjectAclManipulator",
"->",
"getMaskBuilderClass",
"(",
")",
",",
"$",
"aclRoles",
")",
";",
"$",
"aclUsersForm",
"=",
"$",
"adminObjectAclManipulator",
"->",
"createAclUsersForm",
"(",
"$",
"adminObjectAclData",
")",
";",
"$",
"aclRolesForm",
"=",
"$",
"adminObjectAclManipulator",
"->",
"createAclRolesForm",
"(",
"$",
"adminObjectAclData",
")",
";",
"if",
"(",
"'POST'",
"===",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"request",
"->",
"has",
"(",
"AdminObjectAclManipulator",
"::",
"ACL_USERS_FORM_NAME",
")",
")",
"{",
"$",
"form",
"=",
"$",
"aclUsersForm",
";",
"$",
"updateMethod",
"=",
"'updateAclUsers'",
";",
"}",
"elseif",
"(",
"$",
"request",
"->",
"request",
"->",
"has",
"(",
"AdminObjectAclManipulator",
"::",
"ACL_ROLES_FORM_NAME",
")",
")",
"{",
"$",
"form",
"=",
"$",
"aclRolesForm",
";",
"$",
"updateMethod",
"=",
"'updateAclRoles'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"form",
")",
")",
"{",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"adminObjectAclManipulator",
"->",
"$",
"updateMethod",
"(",
"$",
"adminObjectAclData",
")",
";",
"$",
"this",
"->",
"addFlash",
"(",
"'sonata_flash_success'",
",",
"$",
"this",
"->",
"trans",
"(",
"'flash_acl_edit_success'",
",",
"[",
"]",
",",
"'SonataAdminBundle'",
")",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"admin",
"->",
"generateObjectUrl",
"(",
"'acl'",
",",
"$",
"object",
")",
")",
";",
"}",
"}",
"}",
"// NEXT_MAJOR: Remove this line and use commented line below it instead",
"$",
"template",
"=",
"$",
"this",
"->",
"admin",
"->",
"getTemplate",
"(",
"'acl'",
")",
";",
"// $template = $this->templateRegistry->getTemplate('acl');",
"return",
"$",
"this",
"->",
"renderWithExtraParams",
"(",
"$",
"template",
",",
"[",
"'action'",
"=>",
"'acl'",
",",
"'permissions'",
"=>",
"$",
"adminObjectAclData",
"->",
"getUserPermissions",
"(",
")",
",",
"'object'",
"=>",
"$",
"object",
",",
"'users'",
"=>",
"$",
"aclUsers",
",",
"'roles'",
"=>",
"$",
"aclRoles",
",",
"'aclUsersForm'",
"=>",
"$",
"aclUsersForm",
"->",
"createView",
"(",
")",
",",
"'aclRolesForm'",
"=>",
"$",
"aclRolesForm",
"->",
"createView",
"(",
")",
",",
"]",
",",
"null",
")",
";",
"}"
] | Returns the Response object associated to the acl action.
@param int|string|null $id
@throws AccessDeniedException If access is not granted
@throws NotFoundHttpException If the object does not exist or the ACL is not enabled
@return Response|RedirectResponse | [
"Returns",
"the",
"Response",
"object",
"associated",
"to",
"the",
"acl",
"action",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L997-L1068 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.getRestMethod | protected function getRestMethod()
{
$request = $this->getRequest();
if (Request::getHttpMethodParameterOverride() || !$request->request->has('_method')) {
return $request->getMethod();
}
return $request->request->get('_method');
} | php | protected function getRestMethod()
{
$request = $this->getRequest();
if (Request::getHttpMethodParameterOverride() || !$request->request->has('_method')) {
return $request->getMethod();
}
return $request->request->get('_method');
} | [
"protected",
"function",
"getRestMethod",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"Request",
"::",
"getHttpMethodParameterOverride",
"(",
")",
"||",
"!",
"$",
"request",
"->",
"request",
"->",
"has",
"(",
"'_method'",
")",
")",
"{",
"return",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"}",
"return",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'_method'",
")",
";",
"}"
] | Returns the correct RESTful verb, given either by the request itself or
via the "_method" parameter.
@return string HTTP method, either | [
"Returns",
"the",
"correct",
"RESTful",
"verb",
"given",
"either",
"by",
"the",
"request",
"itself",
"or",
"via",
"the",
"_method",
"parameter",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1122-L1131 | train |
sonata-project/SonataAdminBundle | src/Controller/CRUDController.php | CRUDController.configure | protected function configure()
{
$request = $this->getRequest();
$adminCode = $request->get('_sonata_admin');
if (!$adminCode) {
throw new \RuntimeException(sprintf(
'There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`',
\get_class($this),
$request->get('_route')
));
}
$this->admin = $this->container->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);
if (!$this->admin) {
throw new \RuntimeException(sprintf(
'Unable to find the admin class related to the current controller (%s)',
\get_class($this)
));
}
$this->templateRegistry = $this->container->get($this->admin->getCode().'.template_registry');
if (!$this->templateRegistry instanceof TemplateRegistryInterface) {
throw new \RuntimeException(sprintf(
'Unable to find the template registry related to the current admin (%s)',
$this->admin->getCode()
));
}
$rootAdmin = $this->admin;
while ($rootAdmin->isChild()) {
$rootAdmin->setCurrentChild(true);
$rootAdmin = $rootAdmin->getParent();
}
$rootAdmin->setRequest($request);
if ($request->get('uniqid')) {
$this->admin->setUniqid($request->get('uniqid'));
}
} | php | protected function configure()
{
$request = $this->getRequest();
$adminCode = $request->get('_sonata_admin');
if (!$adminCode) {
throw new \RuntimeException(sprintf(
'There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`',
\get_class($this),
$request->get('_route')
));
}
$this->admin = $this->container->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);
if (!$this->admin) {
throw new \RuntimeException(sprintf(
'Unable to find the admin class related to the current controller (%s)',
\get_class($this)
));
}
$this->templateRegistry = $this->container->get($this->admin->getCode().'.template_registry');
if (!$this->templateRegistry instanceof TemplateRegistryInterface) {
throw new \RuntimeException(sprintf(
'Unable to find the template registry related to the current admin (%s)',
$this->admin->getCode()
));
}
$rootAdmin = $this->admin;
while ($rootAdmin->isChild()) {
$rootAdmin->setCurrentChild(true);
$rootAdmin = $rootAdmin->getParent();
}
$rootAdmin->setRequest($request);
if ($request->get('uniqid')) {
$this->admin->setUniqid($request->get('uniqid'));
}
} | [
"protected",
"function",
"configure",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"adminCode",
"=",
"$",
"request",
"->",
"get",
"(",
"'_sonata_admin'",
")",
";",
"if",
"(",
"!",
"$",
"adminCode",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'There is no `_sonata_admin` defined for the controller `%s` and the current route `%s`'",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"request",
"->",
"get",
"(",
"'_route'",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"admin",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sonata.admin.pool'",
")",
"->",
"getAdminByAdminCode",
"(",
"$",
"adminCode",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"admin",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to find the admin class related to the current controller (%s)'",
",",
"\\",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"templateRegistry",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getCode",
"(",
")",
".",
"'.template_registry'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"templateRegistry",
"instanceof",
"TemplateRegistryInterface",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to find the template registry related to the current admin (%s)'",
",",
"$",
"this",
"->",
"admin",
"->",
"getCode",
"(",
")",
")",
")",
";",
"}",
"$",
"rootAdmin",
"=",
"$",
"this",
"->",
"admin",
";",
"while",
"(",
"$",
"rootAdmin",
"->",
"isChild",
"(",
")",
")",
"{",
"$",
"rootAdmin",
"->",
"setCurrentChild",
"(",
"true",
")",
";",
"$",
"rootAdmin",
"=",
"$",
"rootAdmin",
"->",
"getParent",
"(",
")",
";",
"}",
"$",
"rootAdmin",
"->",
"setRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'uniqid'",
")",
")",
"{",
"$",
"this",
"->",
"admin",
"->",
"setUniqid",
"(",
"$",
"request",
"->",
"get",
"(",
"'uniqid'",
")",
")",
";",
"}",
"}"
] | Contextualize the admin class depends on the current request.
@throws \RuntimeException | [
"Contextualize",
"the",
"admin",
"class",
"depends",
"on",
"the",
"current",
"request",
"."
] | 7e5417109126e936800ee1e9f588463af5a7b7cd | https://github.com/sonata-project/SonataAdminBundle/blob/7e5417109126e936800ee1e9f588463af5a7b7cd/src/Controller/CRUDController.php#L1138-L1181 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.