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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
splitbrain/php-archive | src/Tar.php | Tar.skipbytes | protected function skipbytes($bytes)
{
if ($this->comptype === Archive::COMPRESS_GZIP) {
@gzseek($this->fh, $bytes, SEEK_CUR);
} elseif ($this->comptype === Archive::COMPRESS_BZIP) {
// there is no seek in bzip2, we simply read on
// bzread allows to read a max of 8kb at once
while($bytes) {
$toread = min(8192, $bytes);
@bzread($this->fh, $toread);
$bytes -= $toread;
}
} else {
@fseek($this->fh, $bytes, SEEK_CUR);
}
} | php | protected function skipbytes($bytes)
{
if ($this->comptype === Archive::COMPRESS_GZIP) {
@gzseek($this->fh, $bytes, SEEK_CUR);
} elseif ($this->comptype === Archive::COMPRESS_BZIP) {
// there is no seek in bzip2, we simply read on
// bzread allows to read a max of 8kb at once
while($bytes) {
$toread = min(8192, $bytes);
@bzread($this->fh, $toread);
$bytes -= $toread;
}
} else {
@fseek($this->fh, $bytes, SEEK_CUR);
}
} | [
"protected",
"function",
"skipbytes",
"(",
"$",
"bytes",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"comptype",
"===",
"Archive",
"::",
"COMPRESS_GZIP",
")",
"{",
"@",
"gzseek",
"(",
"$",
"this",
"->",
"fh",
",",
"$",
"bytes",
",",
"SEEK_CUR",
")",
";",... | Skip forward in the open file pointer
This is basically a wrapper around seek() (and a workaround for bzip2)
@param int $bytes seek to this position | [
"Skip",
"forward",
"in",
"the",
"open",
"file",
"pointer"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L458-L473 | train |
splitbrain/php-archive | src/Tar.php | Tar.writeFileHeader | protected function writeFileHeader(FileInfo $fileinfo)
{
$this->writeRawFileHeader(
$fileinfo->getPath(),
$fileinfo->getUid(),
$fileinfo->getGid(),
$fileinfo->getMode(),
$fileinfo->getSize(),
$fileinfo->getMtime(),
$fileinfo->getIsdir() ? '5' : '0'
);
} | php | protected function writeFileHeader(FileInfo $fileinfo)
{
$this->writeRawFileHeader(
$fileinfo->getPath(),
$fileinfo->getUid(),
$fileinfo->getGid(),
$fileinfo->getMode(),
$fileinfo->getSize(),
$fileinfo->getMtime(),
$fileinfo->getIsdir() ? '5' : '0'
);
} | [
"protected",
"function",
"writeFileHeader",
"(",
"FileInfo",
"$",
"fileinfo",
")",
"{",
"$",
"this",
"->",
"writeRawFileHeader",
"(",
"$",
"fileinfo",
"->",
"getPath",
"(",
")",
",",
"$",
"fileinfo",
"->",
"getUid",
"(",
")",
",",
"$",
"fileinfo",
"->",
... | Write the given file meta data as header
@param FileInfo $fileinfo
@throws ArchiveIOException | [
"Write",
"the",
"given",
"file",
"meta",
"data",
"as",
"header"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L481-L492 | train |
splitbrain/php-archive | src/Tar.php | Tar.writeRawFileHeader | protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '')
{
// handle filename length restrictions
$prefix = '';
$namelen = strlen($name);
if ($namelen > 100) {
$file = basename($name);
$dir = dirname($name);
if (strlen($file) > 100 || strlen($dir) > 155) {
// we're still too large, let's use GNU longlink
$this->writeRawFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L');
for ($s = 0; $s < $namelen; $s += 512) {
$this->writebytes(pack("a512", substr($name, $s, 512)));
}
$name = substr($name, 0, 100); // cut off name
} else {
// we're fine when splitting, use POSIX ustar
$prefix = $dir;
$name = $file;
}
}
// values are needed in octal
$uid = sprintf("%6s ", decoct($uid));
$gid = sprintf("%6s ", decoct($gid));
$perm = sprintf("%6s ", decoct($perm));
$size = sprintf("%11s ", decoct($size));
$mtime = sprintf("%11s", decoct($mtime));
$data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime);
$data_last = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, "");
for ($i = 0, $chks = 0; $i < 148; $i++) {
$chks += ord($data_first[$i]);
}
for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) {
$chks += ord($data_last[$j]);
}
$this->writebytes($data_first);
$chks = pack("a8", sprintf("%6s ", decoct($chks)));
$this->writebytes($chks.$data_last);
} | php | protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '')
{
// handle filename length restrictions
$prefix = '';
$namelen = strlen($name);
if ($namelen > 100) {
$file = basename($name);
$dir = dirname($name);
if (strlen($file) > 100 || strlen($dir) > 155) {
// we're still too large, let's use GNU longlink
$this->writeRawFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L');
for ($s = 0; $s < $namelen; $s += 512) {
$this->writebytes(pack("a512", substr($name, $s, 512)));
}
$name = substr($name, 0, 100); // cut off name
} else {
// we're fine when splitting, use POSIX ustar
$prefix = $dir;
$name = $file;
}
}
// values are needed in octal
$uid = sprintf("%6s ", decoct($uid));
$gid = sprintf("%6s ", decoct($gid));
$perm = sprintf("%6s ", decoct($perm));
$size = sprintf("%11s ", decoct($size));
$mtime = sprintf("%11s", decoct($mtime));
$data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime);
$data_last = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, "");
for ($i = 0, $chks = 0; $i < 148; $i++) {
$chks += ord($data_first[$i]);
}
for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) {
$chks += ord($data_last[$j]);
}
$this->writebytes($data_first);
$chks = pack("a8", sprintf("%6s ", decoct($chks)));
$this->writebytes($chks.$data_last);
} | [
"protected",
"function",
"writeRawFileHeader",
"(",
"$",
"name",
",",
"$",
"uid",
",",
"$",
"gid",
",",
"$",
"perm",
",",
"$",
"size",
",",
"$",
"mtime",
",",
"$",
"typeflag",
"=",
"''",
")",
"{",
"// handle filename length restrictions",
"$",
"prefix",
... | Write a file header to the stream
@param string $name
@param int $uid
@param int $gid
@param int $perm
@param int $size
@param int $mtime
@param string $typeflag Set to '5' for directories
@throws ArchiveIOException | [
"Write",
"a",
"file",
"header",
"to",
"the",
"stream"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L506-L550 | train |
splitbrain/php-archive | src/Tar.php | Tar.parseHeader | protected function parseHeader($block)
{
if (!$block || strlen($block) != 512) {
throw new ArchiveCorruptedException('Unexpected length of header');
}
// null byte blocks are ignored
if(trim($block) === '') return false;
for ($i = 0, $chks = 0; $i < 148; $i++) {
$chks += ord($block[$i]);
}
for ($i = 156, $chks += 256; $i < 512; $i++) {
$chks += ord($block[$i]);
}
$header = @unpack(
"a100filename/a8perm/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix",
$block
);
if (!$header) {
throw new ArchiveCorruptedException('Failed to parse header');
}
$return['checksum'] = OctDec(trim($header['checksum']));
if ($return['checksum'] != $chks) {
throw new ArchiveCorruptedException('Header does not match it\'s checksum');
}
$return['filename'] = trim($header['filename']);
$return['perm'] = OctDec(trim($header['perm']));
$return['uid'] = OctDec(trim($header['uid']));
$return['gid'] = OctDec(trim($header['gid']));
$return['size'] = OctDec(trim($header['size']));
$return['mtime'] = OctDec(trim($header['mtime']));
$return['typeflag'] = $header['typeflag'];
$return['link'] = trim($header['link']);
$return['uname'] = trim($header['uname']);
$return['gname'] = trim($header['gname']);
// Handle ustar Posix compliant path prefixes
if (trim($header['prefix'])) {
$return['filename'] = trim($header['prefix']).'/'.$return['filename'];
}
// Handle Long-Link entries from GNU Tar
if ($return['typeflag'] == 'L') {
// following data block(s) is the filename
$filename = trim($this->readbytes(ceil($return['size'] / 512) * 512));
// next block is the real header
$block = $this->readbytes(512);
$return = $this->parseHeader($block);
// overwrite the filename
$return['filename'] = $filename;
}
return $return;
} | php | protected function parseHeader($block)
{
if (!$block || strlen($block) != 512) {
throw new ArchiveCorruptedException('Unexpected length of header');
}
// null byte blocks are ignored
if(trim($block) === '') return false;
for ($i = 0, $chks = 0; $i < 148; $i++) {
$chks += ord($block[$i]);
}
for ($i = 156, $chks += 256; $i < 512; $i++) {
$chks += ord($block[$i]);
}
$header = @unpack(
"a100filename/a8perm/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix",
$block
);
if (!$header) {
throw new ArchiveCorruptedException('Failed to parse header');
}
$return['checksum'] = OctDec(trim($header['checksum']));
if ($return['checksum'] != $chks) {
throw new ArchiveCorruptedException('Header does not match it\'s checksum');
}
$return['filename'] = trim($header['filename']);
$return['perm'] = OctDec(trim($header['perm']));
$return['uid'] = OctDec(trim($header['uid']));
$return['gid'] = OctDec(trim($header['gid']));
$return['size'] = OctDec(trim($header['size']));
$return['mtime'] = OctDec(trim($header['mtime']));
$return['typeflag'] = $header['typeflag'];
$return['link'] = trim($header['link']);
$return['uname'] = trim($header['uname']);
$return['gname'] = trim($header['gname']);
// Handle ustar Posix compliant path prefixes
if (trim($header['prefix'])) {
$return['filename'] = trim($header['prefix']).'/'.$return['filename'];
}
// Handle Long-Link entries from GNU Tar
if ($return['typeflag'] == 'L') {
// following data block(s) is the filename
$filename = trim($this->readbytes(ceil($return['size'] / 512) * 512));
// next block is the real header
$block = $this->readbytes(512);
$return = $this->parseHeader($block);
// overwrite the filename
$return['filename'] = $filename;
}
return $return;
} | [
"protected",
"function",
"parseHeader",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"$",
"block",
"||",
"strlen",
"(",
"$",
"block",
")",
"!=",
"512",
")",
"{",
"throw",
"new",
"ArchiveCorruptedException",
"(",
"'Unexpected length of header'",
")",
";",
"... | Decode the given tar file header
@param string $block a 512 byte block containing the header data
@return array|false returns false when this was a null block
@throws ArchiveCorruptedException | [
"Decode",
"the",
"given",
"tar",
"file",
"header"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L559-L617 | train |
splitbrain/php-archive | src/Tar.php | Tar.header2fileinfo | protected function header2fileinfo($header)
{
$fileinfo = new FileInfo();
$fileinfo->setPath($header['filename']);
$fileinfo->setMode($header['perm']);
$fileinfo->setUid($header['uid']);
$fileinfo->setGid($header['gid']);
$fileinfo->setSize($header['size']);
$fileinfo->setMtime($header['mtime']);
$fileinfo->setOwner($header['uname']);
$fileinfo->setGroup($header['gname']);
$fileinfo->setIsdir((bool) $header['typeflag']);
return $fileinfo;
} | php | protected function header2fileinfo($header)
{
$fileinfo = new FileInfo();
$fileinfo->setPath($header['filename']);
$fileinfo->setMode($header['perm']);
$fileinfo->setUid($header['uid']);
$fileinfo->setGid($header['gid']);
$fileinfo->setSize($header['size']);
$fileinfo->setMtime($header['mtime']);
$fileinfo->setOwner($header['uname']);
$fileinfo->setGroup($header['gname']);
$fileinfo->setIsdir((bool) $header['typeflag']);
return $fileinfo;
} | [
"protected",
"function",
"header2fileinfo",
"(",
"$",
"header",
")",
"{",
"$",
"fileinfo",
"=",
"new",
"FileInfo",
"(",
")",
";",
"$",
"fileinfo",
"->",
"setPath",
"(",
"$",
"header",
"[",
"'filename'",
"]",
")",
";",
"$",
"fileinfo",
"->",
"setMode",
... | Creates a FileInfo object from the given parsed header
@param $header
@return FileInfo | [
"Creates",
"a",
"FileInfo",
"object",
"from",
"the",
"given",
"parsed",
"header"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L625-L639 | train |
splitbrain/php-archive | src/Tar.php | Tar.compressioncheck | protected function compressioncheck($comptype)
{
if ($comptype === Archive::COMPRESS_GZIP && !function_exists('gzopen')) {
throw new ArchiveIllegalCompressionException('No gzip support available');
}
if ($comptype === Archive::COMPRESS_BZIP && !function_exists('bzopen')) {
throw new ArchiveIllegalCompressionException('No bzip2 support available');
}
} | php | protected function compressioncheck($comptype)
{
if ($comptype === Archive::COMPRESS_GZIP && !function_exists('gzopen')) {
throw new ArchiveIllegalCompressionException('No gzip support available');
}
if ($comptype === Archive::COMPRESS_BZIP && !function_exists('bzopen')) {
throw new ArchiveIllegalCompressionException('No bzip2 support available');
}
} | [
"protected",
"function",
"compressioncheck",
"(",
"$",
"comptype",
")",
"{",
"if",
"(",
"$",
"comptype",
"===",
"Archive",
"::",
"COMPRESS_GZIP",
"&&",
"!",
"function_exists",
"(",
"'gzopen'",
")",
")",
"{",
"throw",
"new",
"ArchiveIllegalCompressionException",
... | Checks if the given compression type is available and throws an exception if not
@param $comptype
@throws ArchiveIllegalCompressionException | [
"Checks",
"if",
"the",
"given",
"compression",
"type",
"is",
"available",
"and",
"throws",
"an",
"exception",
"if",
"not"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L647-L656 | train |
splitbrain/php-archive | src/Tar.php | Tar.filetype | public function filetype($file)
{
// for existing files, try to read the magic bytes
if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
$fh = @fopen($file, 'rb');
if(!$fh) return false;
$magic = fread($fh, 5);
fclose($fh);
if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP;
if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP;
}
// otherwise rely on file name
$file = strtolower($file);
if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
return Archive::COMPRESS_GZIP;
} elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {
return Archive::COMPRESS_BZIP;
}
return Archive::COMPRESS_NONE;
} | php | public function filetype($file)
{
// for existing files, try to read the magic bytes
if(file_exists($file) && is_readable($file) && filesize($file) > 5) {
$fh = @fopen($file, 'rb');
if(!$fh) return false;
$magic = fread($fh, 5);
fclose($fh);
if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP;
if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP;
}
// otherwise rely on file name
$file = strtolower($file);
if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') {
return Archive::COMPRESS_GZIP;
} elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') {
return Archive::COMPRESS_BZIP;
}
return Archive::COMPRESS_NONE;
} | [
"public",
"function",
"filetype",
"(",
"$",
"file",
")",
"{",
"// for existing files, try to read the magic bytes",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
"&&",
"is_readable",
"(",
"$",
"file",
")",
"&&",
"filesize",
"(",
"$",
"file",
")",
">",
"5"... | Guesses the wanted compression from the given file
Uses magic bytes for existing files, the file extension otherwise
You don't need to call this yourself. It's used when you pass Archive::COMPRESS_AUTO somewhere
@param string $file
@return int | [
"Guesses",
"the",
"wanted",
"compression",
"from",
"the",
"given",
"file"
] | 10d89013572ba1f4d4ad7fcb74860242f4c3860b | https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L668-L690 | train |
pyaesone17/active-state | src/Active.php | Active.checkActiveDeeply | protected function checkActiveDeeply($url,$method)
{
if(is_array($url)) {
foreach ($url as $value) { $urls[] = $value.'*'; }
return call_user_func_array(array($this->request,$method), $urls) ? $this->activeValue : $this->inActiveValue;
} else {
return $this->request->is($url) || $this->request->is($url . '/*') ? $this->activeValue : $this->inActiveValue;
}
} | php | protected function checkActiveDeeply($url,$method)
{
if(is_array($url)) {
foreach ($url as $value) { $urls[] = $value.'*'; }
return call_user_func_array(array($this->request,$method), $urls) ? $this->activeValue : $this->inActiveValue;
} else {
return $this->request->is($url) || $this->request->is($url . '/*') ? $this->activeValue : $this->inActiveValue;
}
} | [
"protected",
"function",
"checkActiveDeeply",
"(",
"$",
"url",
",",
"$",
"method",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"foreach",
"(",
"$",
"url",
"as",
"$",
"value",
")",
"{",
"$",
"urls",
"[",
"]",
"=",
"$",
"value"... | It checks the active state of given url deeply
@param string $url < url point to check >
@return string it returns wherether the state is active or no | [
"It",
"checks",
"the",
"active",
"state",
"of",
"given",
"url",
"deeply"
] | 4ebeef35fe0d533e63b63de2c4774635b2783877 | https://github.com/pyaesone17/active-state/blob/4ebeef35fe0d533e63b63de2c4774635b2783877/src/Active.php#L99-L107 | train |
pyaesone17/active-state | src/Active.php | Active.checkActive | protected function checkActive($url,$method)
{
if(is_array($url)){
return call_user_func_array(array($this->request,$method), $url) ? $this->activeValue : $this->inActiveValue;
} else{
return $this->request->{$method}($url) ? $this->activeValue : $this->inActiveValue;
}
} | php | protected function checkActive($url,$method)
{
if(is_array($url)){
return call_user_func_array(array($this->request,$method), $url) ? $this->activeValue : $this->inActiveValue;
} else{
return $this->request->{$method}($url) ? $this->activeValue : $this->inActiveValue;
}
} | [
"protected",
"function",
"checkActive",
"(",
"$",
"url",
",",
"$",
"method",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"method",
")",
... | It checks the active state of given url specificly
@param string $url < url point to check >
@return string it returns wherether the state is active or no | [
"It",
"checks",
"the",
"active",
"state",
"of",
"given",
"url",
"specificly"
] | 4ebeef35fe0d533e63b63de2c4774635b2783877 | https://github.com/pyaesone17/active-state/blob/4ebeef35fe0d533e63b63de2c4774635b2783877/src/Active.php#L113-L120 | train |
sebbmeyer/php-microsoft-teams-connector | src/TeamsConnector.php | TeamsConnector.send | public function send(TeamsConnectorInterface $card)
{
$json = json_encode($card->getMessage());
$ch = curl_init($this->webhookUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($json)
]);
$result = curl_exec($ch);
if ($result !== "1") {
throw new \Exception($result);
}
} | php | public function send(TeamsConnectorInterface $card)
{
$json = json_encode($card->getMessage());
$ch = curl_init($this->webhookUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($json)
]);
$result = curl_exec($ch);
if ($result !== "1") {
throw new \Exception($result);
}
} | [
"public",
"function",
"send",
"(",
"TeamsConnectorInterface",
"$",
"card",
")",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"card",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"this",
"->",
"webhookUrl",
")",
";",... | Sends card message as POST request
@param TeamsConnectorInterface $card
@throws Exception | [
"Sends",
"card",
"message",
"as",
"POST",
"request"
] | 8a43c54c7ec792ffa9c5577bcc5a0bd266faba28 | https://github.com/sebbmeyer/php-microsoft-teams-connector/blob/8a43c54c7ec792ffa9c5577bcc5a0bd266faba28/src/TeamsConnector.php#L23-L43 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.doAutoCommitFlushTransaction | protected function doAutoCommitFlushTransaction(ResourceInterface $resource, $autoCommit, $skipped = false)
{
$hasFlushError = $resource->getErrors()->count() > 0;
if ($autoCommit && !$skipped && !$hasFlushError) {
$rErrors = $this->flushTransaction($resource->getRealData());
$resource->getErrors()->addAll($rErrors);
$hasFlushError = $rErrors->count() > 0;
}
return $hasFlushError;
} | php | protected function doAutoCommitFlushTransaction(ResourceInterface $resource, $autoCommit, $skipped = false)
{
$hasFlushError = $resource->getErrors()->count() > 0;
if ($autoCommit && !$skipped && !$hasFlushError) {
$rErrors = $this->flushTransaction($resource->getRealData());
$resource->getErrors()->addAll($rErrors);
$hasFlushError = $rErrors->count() > 0;
}
return $hasFlushError;
} | [
"protected",
"function",
"doAutoCommitFlushTransaction",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"autoCommit",
",",
"$",
"skipped",
"=",
"false",
")",
"{",
"$",
"hasFlushError",
"=",
"$",
"resource",
"->",
"getErrors",
"(",
")",
"->",
"count",
"("... | Do the flush transaction for auto commit.
@param ResourceInterface $resource The resource
@param bool $autoCommit The auto commit
@param bool $skipped Check if the resource is skipped
@return bool Returns if there is an flush error | [
"Do",
"the",
"flush",
"transaction",
"for",
"auto",
"commit",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L39-L50 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.doFlushFinalTransaction | protected function doFlushFinalTransaction(ResourceListInterface $resources, $autoCommit, $hasError): void
{
if (!$autoCommit) {
if ($hasError) {
$this->cancelTransaction();
DomainUtil::cancelAllSuccessResources($resources);
} else {
$errors = $this->flushTransaction();
DomainUtil::moveFlushErrorsInResource($resources, $errors);
}
}
} | php | protected function doFlushFinalTransaction(ResourceListInterface $resources, $autoCommit, $hasError): void
{
if (!$autoCommit) {
if ($hasError) {
$this->cancelTransaction();
DomainUtil::cancelAllSuccessResources($resources);
} else {
$errors = $this->flushTransaction();
DomainUtil::moveFlushErrorsInResource($resources, $errors);
}
}
} | [
"protected",
"function",
"doFlushFinalTransaction",
"(",
"ResourceListInterface",
"$",
"resources",
",",
"$",
"autoCommit",
",",
"$",
"hasError",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"autoCommit",
")",
"{",
"if",
"(",
"$",
"hasError",
")",
"{",
"$",... | Do flush the final transaction for non auto commit.
@param ResourceListInterface $resources The list of object resource instance
@param bool $autoCommit Commit transaction for each resource or all
(continue the action even if there is an error on a resource)
@param bool $hasError Check if there is an error | [
"Do",
"flush",
"the",
"final",
"transaction",
"for",
"non",
"auto",
"commit",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L60-L71 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.finalizeResourceStatus | protected function finalizeResourceStatus(ResourceInterface $resource, $status, $hasError)
{
if ($resource->isValid()) {
$resource->setStatus($status);
} else {
$hasError = true;
$resource->setStatus(ResourceStatutes::ERROR);
$this->om->detach($resource->getRealData());
}
return $hasError;
} | php | protected function finalizeResourceStatus(ResourceInterface $resource, $status, $hasError)
{
if ($resource->isValid()) {
$resource->setStatus($status);
} else {
$hasError = true;
$resource->setStatus(ResourceStatutes::ERROR);
$this->om->detach($resource->getRealData());
}
return $hasError;
} | [
"protected",
"function",
"finalizeResourceStatus",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"status",
",",
"$",
"hasError",
")",
"{",
"if",
"(",
"$",
"resource",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"resource",
"->",
"setStatus",
"(",
"$",... | Finalize the action for a resource.
@param ResourceInterface $resource
@param string $status
@param bool $hasError
@return bool Returns the new hasError value | [
"Finalize",
"the",
"action",
"for",
"a",
"resource",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L82-L93 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.beginTransaction | protected function beginTransaction($autoCommit = false): void
{
if (!$autoCommit && null !== $this->connection) {
$this->connection->beginTransaction();
}
} | php | protected function beginTransaction($autoCommit = false): void
{
if (!$autoCommit && null !== $this->connection) {
$this->connection->beginTransaction();
}
} | [
"protected",
"function",
"beginTransaction",
"(",
"$",
"autoCommit",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"autoCommit",
"&&",
"null",
"!==",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"beginTran... | Begin automatically the database transaction.
@param bool $autoCommit Check if each resource must be flushed immediately or in the end | [
"Begin",
"automatically",
"the",
"database",
"transaction",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L100-L105 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.flushTransaction | protected function flushTransaction($object = null)
{
$violations = new ConstraintViolationList();
try {
$this->om->flush();
if (null !== $this->connection && null === $object) {
$this->connection->commit();
}
} catch (\Exception $e) {
$this->flushTransactionException($e, $violations, $object);
}
return $violations;
} | php | protected function flushTransaction($object = null)
{
$violations = new ConstraintViolationList();
try {
$this->om->flush();
if (null !== $this->connection && null === $object) {
$this->connection->commit();
}
} catch (\Exception $e) {
$this->flushTransactionException($e, $violations, $object);
}
return $violations;
} | [
"protected",
"function",
"flushTransaction",
"(",
"$",
"object",
"=",
"null",
")",
"{",
"$",
"violations",
"=",
"new",
"ConstraintViolationList",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"om",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"null",
"!=="... | Flush data in database with automatic declaration of the transaction for the collection.
@param null|object $object The resource for auto commit or null for flush at the end
@return ConstraintViolationList | [
"Flush",
"data",
"in",
"database",
"with",
"automatic",
"declaration",
"of",
"the",
"transaction",
"for",
"the",
"collection",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L114-L129 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.flushTransactionException | protected function flushTransactionException(\Exception $e, ConstraintViolationListInterface $violations, $object = null): void
{
if (null !== $this->connection && null === $object) {
$this->connection->rollback();
}
if ($e instanceof ConstraintViolationException) {
$violations->addAll($e->getConstraintViolations());
} else {
$message = DomainUtil::getExceptionMessage($this->translator, $e, $this->debug);
$violations->add(new ConstraintViolation($message, $message, [], $object, null, null));
}
} | php | protected function flushTransactionException(\Exception $e, ConstraintViolationListInterface $violations, $object = null): void
{
if (null !== $this->connection && null === $object) {
$this->connection->rollback();
}
if ($e instanceof ConstraintViolationException) {
$violations->addAll($e->getConstraintViolations());
} else {
$message = DomainUtil::getExceptionMessage($this->translator, $e, $this->debug);
$violations->add(new ConstraintViolation($message, $message, [], $object, null, null));
}
} | [
"protected",
"function",
"flushTransactionException",
"(",
"\\",
"Exception",
"$",
"e",
",",
"ConstraintViolationListInterface",
"$",
"violations",
",",
"$",
"object",
"=",
"null",
")",
":",
"void",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"connection... | Do the action when there is an exception on flush transaction.
@param \Exception $e The exception on flush transaction
@param ConstraintViolationListInterface $violations The constraint violation list
@param null|object $object The resource for auto commit or null for flush at the end
@throws | [
"Do",
"the",
"action",
"when",
"there",
"is",
"an",
"exception",
"on",
"flush",
"transaction",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L140-L153 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.validateResource | protected function validateResource($resource, $type): void
{
if (!$resource->isValid()) {
return;
}
$idError = $this->getErrorIdentifier($resource->getRealData(), $type);
$data = $resource->getData();
if ($data instanceof FormInterface) {
if (!$data->isSubmitted()) {
$data->submit([]);
}
} else {
$errors = $this->validator->validate($data);
$resource->getErrors()->addAll($errors);
}
if (null !== $idError) {
$resource->getErrors()->add(new ConstraintViolation($idError, $idError, [], $resource->getRealData(), null, null));
}
} | php | protected function validateResource($resource, $type): void
{
if (!$resource->isValid()) {
return;
}
$idError = $this->getErrorIdentifier($resource->getRealData(), $type);
$data = $resource->getData();
if ($data instanceof FormInterface) {
if (!$data->isSubmitted()) {
$data->submit([]);
}
} else {
$errors = $this->validator->validate($data);
$resource->getErrors()->addAll($errors);
}
if (null !== $idError) {
$resource->getErrors()->add(new ConstraintViolation($idError, $idError, [], $resource->getRealData(), null, null));
}
} | [
"protected",
"function",
"validateResource",
"(",
"$",
"resource",
",",
"$",
"type",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"resource",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"idError",
"=",
"$",
"this",
"->",
"getErrorIde... | Validate the resource and get the error list.
@param ResourceInterface $resource The resource
@param int $type The type of persist | [
"Validate",
"the",
"resource",
"and",
"get",
"the",
"error",
"list",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L173-L194 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.getErrorIdentifier | protected function getErrorIdentifier($object, $type)
{
$idValue = DomainUtil::getIdentifier($this->om, $object);
$idError = null;
if (Domain::TYPE_CREATE === $type && null !== $idValue) {
$idError = $this->translator->trans('domain.identifier.error_create', [], 'FxpResource');
} elseif (Domain::TYPE_UPDATE === $type && null === $idValue) {
$idError = $this->translator->trans('domain.identifier.error_update', [], 'FxpResource');
} elseif (Domain::TYPE_DELETE === $type && null === $idValue) {
$idError = $this->translator->trans('domain.identifier.error_delete', [], 'FxpResource');
} elseif (Domain::TYPE_UNDELETE === $type && null === $idValue) {
$idError = $this->translator->trans('domain.identifier.error_undeleted', [], 'FxpResource');
}
return $idError;
} | php | protected function getErrorIdentifier($object, $type)
{
$idValue = DomainUtil::getIdentifier($this->om, $object);
$idError = null;
if (Domain::TYPE_CREATE === $type && null !== $idValue) {
$idError = $this->translator->trans('domain.identifier.error_create', [], 'FxpResource');
} elseif (Domain::TYPE_UPDATE === $type && null === $idValue) {
$idError = $this->translator->trans('domain.identifier.error_update', [], 'FxpResource');
} elseif (Domain::TYPE_DELETE === $type && null === $idValue) {
$idError = $this->translator->trans('domain.identifier.error_delete', [], 'FxpResource');
} elseif (Domain::TYPE_UNDELETE === $type && null === $idValue) {
$idError = $this->translator->trans('domain.identifier.error_undeleted', [], 'FxpResource');
}
return $idError;
} | [
"protected",
"function",
"getErrorIdentifier",
"(",
"$",
"object",
",",
"$",
"type",
")",
"{",
"$",
"idValue",
"=",
"DomainUtil",
"::",
"getIdentifier",
"(",
"$",
"this",
"->",
"om",
",",
"$",
"object",
")",
";",
"$",
"idError",
"=",
"null",
";",
"if",... | Get the error of identifier.
@param object $object The object data
@param int $type The type of persist
@return null|string | [
"Get",
"the",
"error",
"of",
"identifier",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L204-L220 | train |
fxpio/fxp-resource | Domain/BaseDomain.php | BaseDomain.getSuccessStatus | protected function getSuccessStatus($type, $object)
{
if (Domain::TYPE_CREATE === $type) {
return ResourceStatutes::CREATED;
}
if (Domain::TYPE_UPDATE === $type) {
return ResourceStatutes::UPDATED;
}
if (Domain::TYPE_UNDELETE === $type) {
return ResourceStatutes::UNDELETED;
}
return null === DomainUtil::getIdentifier($this->om, $object)
? ResourceStatutes::CREATED
: ResourceStatutes::UPDATED;
} | php | protected function getSuccessStatus($type, $object)
{
if (Domain::TYPE_CREATE === $type) {
return ResourceStatutes::CREATED;
}
if (Domain::TYPE_UPDATE === $type) {
return ResourceStatutes::UPDATED;
}
if (Domain::TYPE_UNDELETE === $type) {
return ResourceStatutes::UNDELETED;
}
return null === DomainUtil::getIdentifier($this->om, $object)
? ResourceStatutes::CREATED
: ResourceStatutes::UPDATED;
} | [
"protected",
"function",
"getSuccessStatus",
"(",
"$",
"type",
",",
"$",
"object",
")",
"{",
"if",
"(",
"Domain",
"::",
"TYPE_CREATE",
"===",
"$",
"type",
")",
"{",
"return",
"ResourceStatutes",
"::",
"CREATED",
";",
"}",
"if",
"(",
"Domain",
"::",
"TYPE... | Get the success status.
@param int $type The type of persist
@param object $object The resource instance
@return string | [
"Get",
"the",
"success",
"status",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L230-L245 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/MenuSubscriber.php | MenuSubscriber.buildMenus | public function buildMenus(MenuEvent $event)
{
if (!$this->applicationConfiguration->getParameter('enable_menus')) {
return;
}
$menuConfigurations = array_merge_recursive(
$this->adminMenuConfigurations,
$event->getMenuConfigurations()
);
$configurationEvent = new MenuConfigurationEvent($menuConfigurations);
// Dispatch a pre-menu build event to allow dynamic configuration modifications
$this
->eventDispatcher
->dispatch(Events::MENU_CONFIGURATION, $configurationEvent)
;
$menuConfigurations = $configurationEvent->getMenuConfigurations();
foreach ($menuConfigurations as $name => $menuConfiguration) {
$this->menuFactory->create($name, $menuConfiguration);
}
} | php | public function buildMenus(MenuEvent $event)
{
if (!$this->applicationConfiguration->getParameter('enable_menus')) {
return;
}
$menuConfigurations = array_merge_recursive(
$this->adminMenuConfigurations,
$event->getMenuConfigurations()
);
$configurationEvent = new MenuConfigurationEvent($menuConfigurations);
// Dispatch a pre-menu build event to allow dynamic configuration modifications
$this
->eventDispatcher
->dispatch(Events::MENU_CONFIGURATION, $configurationEvent)
;
$menuConfigurations = $configurationEvent->getMenuConfigurations();
foreach ($menuConfigurations as $name => $menuConfiguration) {
$this->menuFactory->create($name, $menuConfiguration);
}
} | [
"public",
"function",
"buildMenus",
"(",
"MenuEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"applicationConfiguration",
"->",
"getParameter",
"(",
"'enable_menus'",
")",
")",
"{",
"return",
";",
"}",
"$",
"menuConfigurations",
"=",
"arra... | Build menus according to the given configuration.
@param MenuEvent $event | [
"Build",
"menus",
"according",
"to",
"the",
"given",
"configuration",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/MenuSubscriber.php#L71-L92 | train |
Smart-Core/CoreBundle | Pagerfanta/DoctrineORM/LegacyPaginator.php | LegacyPaginator.cloneQuery | private function cloneQuery(Query $query)
{
/* @var $cloneQuery Query */
$cloneQuery = clone $query;
$cloneQuery->setParameters($query->getParameters());
foreach ($query->getHints() as $name => $value) {
$cloneQuery->setHint($name, $value);
}
return $cloneQuery;
} | php | private function cloneQuery(Query $query)
{
/* @var $cloneQuery Query */
$cloneQuery = clone $query;
$cloneQuery->setParameters($query->getParameters());
foreach ($query->getHints() as $name => $value) {
$cloneQuery->setHint($name, $value);
}
return $cloneQuery;
} | [
"private",
"function",
"cloneQuery",
"(",
"Query",
"$",
"query",
")",
"{",
"/* @var $cloneQuery Query */",
"$",
"cloneQuery",
"=",
"clone",
"$",
"query",
";",
"$",
"cloneQuery",
"->",
"setParameters",
"(",
"$",
"query",
"->",
"getParameters",
"(",
")",
")",
... | Clones a query.
@param Query $query The query.
@return Query The cloned query. | [
"Clones",
"a",
"query",
"."
] | d74829de254237008eb92ad213c7e7f41d91aac4 | https://github.com/Smart-Core/CoreBundle/blob/d74829de254237008eb92ad213c7e7f41d91aac4/Pagerfanta/DoctrineORM/LegacyPaginator.php#L142-L152 | train |
fxpio/fxp-resource | ResourceList.php | ResourceList.getStatusValue | private function getStatusValue($countPending, $countCancel, $countError, $countSuccess)
{
$status = ResourceListStatutes::SUCCESSFULLY;
$count = $this->count();
if ($count > 0) {
$status = ResourceListStatutes::MIXED;
if ($count === $countPending) {
$status = ResourceListStatutes::PENDING;
} elseif ($count === $countCancel) {
$status = ResourceListStatutes::CANCEL;
} elseif ($count === $countError) {
$status = ResourceListStatutes::ERROR;
} elseif ($count === $countSuccess) {
$status = ResourceListStatutes::SUCCESSFULLY;
}
}
return $status;
} | php | private function getStatusValue($countPending, $countCancel, $countError, $countSuccess)
{
$status = ResourceListStatutes::SUCCESSFULLY;
$count = $this->count();
if ($count > 0) {
$status = ResourceListStatutes::MIXED;
if ($count === $countPending) {
$status = ResourceListStatutes::PENDING;
} elseif ($count === $countCancel) {
$status = ResourceListStatutes::CANCEL;
} elseif ($count === $countError) {
$status = ResourceListStatutes::ERROR;
} elseif ($count === $countSuccess) {
$status = ResourceListStatutes::SUCCESSFULLY;
}
}
return $status;
} | [
"private",
"function",
"getStatusValue",
"(",
"$",
"countPending",
",",
"$",
"countCancel",
",",
"$",
"countError",
",",
"$",
"countSuccess",
")",
"{",
"$",
"status",
"=",
"ResourceListStatutes",
"::",
"SUCCESSFULLY",
";",
"$",
"count",
"=",
"$",
"this",
"->... | Get the final status value.
@param int $countPending
@param int $countCancel
@param int $countError
@param int $countSuccess
@return string | [
"Get",
"the",
"final",
"status",
"value",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/ResourceList.php#L100-L120 | train |
larriereguichet/AdminBundle | src/Factory/ViewFactory.php | ViewFactory.create | public function create(
Request $request,
$actionName,
$adminName,
AdminConfiguration $adminConfiguration,
ActionConfiguration $actionConfiguration,
$entities,
array $forms = []
) {
if (key_exists('entity', $forms)) {
$form = $forms['entity'];
if ($this->shouldRedirect($form, $request, $adminConfiguration)) {
$routeName = RoutingLoader::generateRouteName(
$adminName,
'list',
$adminConfiguration->getParameter('routing_name_pattern')
);
$url = $this->router->generate($routeName);
$view = new RedirectView(
$actionName,
$adminName,
$actionConfiguration,
$adminConfiguration
);
$view->setUrl($url);
return $view;
}
}
$fields = $this
->fieldFactory
->createFields($actionConfiguration)
;
$formViews = [];
foreach ($forms as $identifier => $form) {
$formViews[$identifier] = $form->createView();
}
$view = new View(
$actionName,
$adminName,
$actionConfiguration,
$adminConfiguration,
$fields,
$formViews
);
$view->setEntities($entities);
return $view;
} | php | public function create(
Request $request,
$actionName,
$adminName,
AdminConfiguration $adminConfiguration,
ActionConfiguration $actionConfiguration,
$entities,
array $forms = []
) {
if (key_exists('entity', $forms)) {
$form = $forms['entity'];
if ($this->shouldRedirect($form, $request, $adminConfiguration)) {
$routeName = RoutingLoader::generateRouteName(
$adminName,
'list',
$adminConfiguration->getParameter('routing_name_pattern')
);
$url = $this->router->generate($routeName);
$view = new RedirectView(
$actionName,
$adminName,
$actionConfiguration,
$adminConfiguration
);
$view->setUrl($url);
return $view;
}
}
$fields = $this
->fieldFactory
->createFields($actionConfiguration)
;
$formViews = [];
foreach ($forms as $identifier => $form) {
$formViews[$identifier] = $form->createView();
}
$view = new View(
$actionName,
$adminName,
$actionConfiguration,
$adminConfiguration,
$fields,
$formViews
);
$view->setEntities($entities);
return $view;
} | [
"public",
"function",
"create",
"(",
"Request",
"$",
"request",
",",
"$",
"actionName",
",",
"$",
"adminName",
",",
"AdminConfiguration",
"$",
"adminConfiguration",
",",
"ActionConfiguration",
"$",
"actionConfiguration",
",",
"$",
"entities",
",",
"array",
"$",
... | Create a view for a given Admin and Action.
@param Request $request
@param string $actionName
@param string $adminName
@param AdminConfiguration $adminConfiguration
@param ActionConfiguration $actionConfiguration
@param $entities
@param FormInterface[] $forms
@return ViewInterface | [
"Create",
"a",
"view",
"for",
"a",
"given",
"Admin",
"and",
"Action",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/ViewFactory.php#L70-L121 | train |
larriereguichet/AdminBundle | src/Factory/FieldFactory.php | FieldFactory.create | public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface
{
$resolver = new OptionsResolver();
$configuration = $this->resolveConfiguration($configuration, $actionConfiguration);
// Dispatch an event to allow dynamic changes on the form type
$event = new FieldEvent(
$actionConfiguration->getAdminName(),
$actionConfiguration->getActionName(),
$name,
$actionConfiguration->getAdminConfiguration()->get('entity'),
$configuration['type']
);
$this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event);
if (null === $event->getType()) {
throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name);
}
$type = $event->getType();
$options = array_merge($configuration['options'], $event->getOptions());
if (!key_exists($type, $this->fieldsMapping)) {
$type = 'auto';
}
$field = $this->instanciateField($name, $type);
$field->configureOptions($resolver, $actionConfiguration);
try {
$field->setOptions($resolver->resolve($options));
} catch (\Exception $exception) {
throw new Exception(
'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(),
$exception->getCode(),
$exception
);
}
$event = new FieldEvent(
$actionConfiguration->getAdminName(),
$actionConfiguration->getActionName(),
$name,
$actionConfiguration->getAdminConfiguration()->get('entity'),
$type,
$field
);
$this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event);
return $field;
} | php | public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface
{
$resolver = new OptionsResolver();
$configuration = $this->resolveConfiguration($configuration, $actionConfiguration);
// Dispatch an event to allow dynamic changes on the form type
$event = new FieldEvent(
$actionConfiguration->getAdminName(),
$actionConfiguration->getActionName(),
$name,
$actionConfiguration->getAdminConfiguration()->get('entity'),
$configuration['type']
);
$this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event);
if (null === $event->getType()) {
throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name);
}
$type = $event->getType();
$options = array_merge($configuration['options'], $event->getOptions());
if (!key_exists($type, $this->fieldsMapping)) {
$type = 'auto';
}
$field = $this->instanciateField($name, $type);
$field->configureOptions($resolver, $actionConfiguration);
try {
$field->setOptions($resolver->resolve($options));
} catch (\Exception $exception) {
throw new Exception(
'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(),
$exception->getCode(),
$exception
);
}
$event = new FieldEvent(
$actionConfiguration->getAdminName(),
$actionConfiguration->getActionName(),
$name,
$actionConfiguration->getAdminConfiguration()->get('entity'),
$type,
$field
);
$this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event);
return $field;
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"configuration",
",",
"ActionConfiguration",
"$",
"actionConfiguration",
")",
":",
"FieldInterface",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"config... | Create a new field instance according to the given configuration.
@param string $name
@param array $configuration
@param ActionConfiguration $actionConfiguration
@return FieldInterface
@throws Exception | [
"Create",
"a",
"new",
"field",
"instance",
"according",
"to",
"the",
"given",
"configuration",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/FieldFactory.php#L117-L164 | train |
larriereguichet/AdminBundle | src/Factory/FieldFactory.php | FieldFactory.getFieldClass | private function getFieldClass(string $type): string
{
if (!array_key_exists($type, $this->fieldsMapping)) {
throw new Exception("Field type \"{$type}\" not found in field mapping. Allowed fields are \"".implode('", "', $this->fieldsMapping).'"');
}
return $this->fieldsMapping[$type];
} | php | private function getFieldClass(string $type): string
{
if (!array_key_exists($type, $this->fieldsMapping)) {
throw new Exception("Field type \"{$type}\" not found in field mapping. Allowed fields are \"".implode('", "', $this->fieldsMapping).'"');
}
return $this->fieldsMapping[$type];
} | [
"private",
"function",
"getFieldClass",
"(",
"string",
"$",
"type",
")",
":",
"string",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"fieldsMapping",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Field type \\\"{... | Return field class according to the field type. If the type is not present in the field mapping array, an
exception will be thrown.
@param string $type
@return string
@throws Exception | [
"Return",
"field",
"class",
"according",
"to",
"the",
"field",
"type",
".",
"If",
"the",
"type",
"is",
"not",
"present",
"in",
"the",
"field",
"mapping",
"array",
"an",
"exception",
"will",
"be",
"thrown",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/FieldFactory.php#L176-L183 | train |
larriereguichet/AdminBundle | src/Factory/ConfigurationFactory.php | ConfigurationFactory.createResourceMenuConfiguration | public function createResourceMenuConfiguration()
{
$menuConfiguration = [];
foreach ($this->resourceCollection->all() as $resource) {
$resourceConfiguration = $resource->getConfiguration();
// Add only entry for the "list" action
if (
!key_exists('actions', $resourceConfiguration) ||
null === $resourceConfiguration['actions'] ||
!array_key_exists('list', $resourceConfiguration['actions'])
) {
continue;
}
$menuConfiguration['items'][] = [
'text' => ucfirst($resource->getName()),
'admin' => $resource->getName(),
'action' => 'list',
];
}
return $menuConfiguration;
} | php | public function createResourceMenuConfiguration()
{
$menuConfiguration = [];
foreach ($this->resourceCollection->all() as $resource) {
$resourceConfiguration = $resource->getConfiguration();
// Add only entry for the "list" action
if (
!key_exists('actions', $resourceConfiguration) ||
null === $resourceConfiguration['actions'] ||
!array_key_exists('list', $resourceConfiguration['actions'])
) {
continue;
}
$menuConfiguration['items'][] = [
'text' => ucfirst($resource->getName()),
'admin' => $resource->getName(),
'action' => 'list',
];
}
return $menuConfiguration;
} | [
"public",
"function",
"createResourceMenuConfiguration",
"(",
")",
"{",
"$",
"menuConfiguration",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"resourceCollection",
"->",
"all",
"(",
")",
"as",
"$",
"resource",
")",
"{",
"$",
"resourceConfiguration",... | Build the resources menu items.
@return array | [
"Build",
"the",
"resources",
"menu",
"items",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/ConfigurationFactory.php#L96-L119 | train |
larriereguichet/AdminBundle | src/Factory/MenuFactory.php | MenuFactory.create | public function create(string $name, array $configuration): Menu
{
$resolver = new OptionsResolver();
$menuConfiguration = new MenuConfiguration($name, $this->applicationConfiguration->getParameter('title'));
$menuConfiguration->configureOptions($resolver);
$menuConfiguration->setParameters($resolver->resolve($configuration));
$menu = new Menu($name, $menuConfiguration);
foreach ($menuConfiguration->getParameter('items') as $itemName => $item) {
$menu->addItem($this->createMenuItem($itemName, $item, $menuConfiguration));
}
$this->menus[$name] = $menu;
return $menu;
} | php | public function create(string $name, array $configuration): Menu
{
$resolver = new OptionsResolver();
$menuConfiguration = new MenuConfiguration($name, $this->applicationConfiguration->getParameter('title'));
$menuConfiguration->configureOptions($resolver);
$menuConfiguration->setParameters($resolver->resolve($configuration));
$menu = new Menu($name, $menuConfiguration);
foreach ($menuConfiguration->getParameter('items') as $itemName => $item) {
$menu->addItem($this->createMenuItem($itemName, $item, $menuConfiguration));
}
$this->menus[$name] = $menu;
return $menu;
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"configuration",
")",
":",
"Menu",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"menuConfiguration",
"=",
"new",
"MenuConfiguration",
"(",
"$",
"name... | Create a menu item from a configuration array.
@param string $name
@param array $configuration
@return Menu | [
"Create",
"a",
"menu",
"item",
"from",
"a",
"configuration",
"array",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/MenuFactory.php#L54-L69 | train |
larriereguichet/AdminBundle | src/Factory/MenuFactory.php | MenuFactory.createMenuItem | public function createMenuItem(string $name, array $configuration, MenuConfiguration $parentConfiguration): MenuItem
{
// Resolve configuration for the current item
$resolver = new OptionsResolver();
$menuItemConfiguration = new MenuItemConfiguration($name, $parentConfiguration->getParameter('position'));
$menuItemConfiguration->configureOptions($resolver);
$resolvedConfiguration = $resolver->resolve($configuration);
if ($this->applicationConfiguration->getParameter('enable_extra_configuration')) {
$this->addExtraMenuItemConfiguration($resolvedConfiguration);
}
$menuItemConfiguration->setParameters($resolvedConfiguration);
return new MenuItem($menuItemConfiguration);
} | php | public function createMenuItem(string $name, array $configuration, MenuConfiguration $parentConfiguration): MenuItem
{
// Resolve configuration for the current item
$resolver = new OptionsResolver();
$menuItemConfiguration = new MenuItemConfiguration($name, $parentConfiguration->getParameter('position'));
$menuItemConfiguration->configureOptions($resolver);
$resolvedConfiguration = $resolver->resolve($configuration);
if ($this->applicationConfiguration->getParameter('enable_extra_configuration')) {
$this->addExtraMenuItemConfiguration($resolvedConfiguration);
}
$menuItemConfiguration->setParameters($resolvedConfiguration);
return new MenuItem($menuItemConfiguration);
} | [
"public",
"function",
"createMenuItem",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"configuration",
",",
"MenuConfiguration",
"$",
"parentConfiguration",
")",
":",
"MenuItem",
"{",
"// Resolve configuration for the current item",
"$",
"resolver",
"=",
"new",
"Opti... | Create a menu item according to the given configuration.
@param string $name
@param array $configuration
@param MenuConfiguration $parentConfiguration
@return MenuItem | [
"Create",
"a",
"menu",
"item",
"according",
"to",
"the",
"given",
"configuration",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/MenuFactory.php#L80-L94 | train |
larriereguichet/AdminBundle | src/Factory/MenuFactory.php | MenuFactory.getMenu | public function getMenu(string $name): Menu
{
if (!$this->hasMenu($name)) {
throw new Exception('Invalid menu name "'.$name.'"');
}
return $this->menus[$name];
} | php | public function getMenu(string $name): Menu
{
if (!$this->hasMenu($name)) {
throw new Exception('Invalid menu name "'.$name.'"');
}
return $this->menus[$name];
} | [
"public",
"function",
"getMenu",
"(",
"string",
"$",
"name",
")",
":",
"Menu",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasMenu",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid menu name \"'",
".",
"$",
"name",
".",
"'\"... | Return a menu with the given name.
@param string $name
@return Menu
@throws Exception | [
"Return",
"a",
"menu",
"with",
"the",
"given",
"name",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/MenuFactory.php#L117-L124 | train |
fxpio/fxp-resource | Handler/FormHandler.php | FormHandler.getDataListObjects | protected function getDataListObjects(FormConfigInterface $config, array $objects)
{
$limit = $this->getLimit($config instanceof FormConfigListInterface ? $config->getLimit() : null);
$dataList = $this->getDataList($config);
if (null !== $limit && \count($dataList) > $limit) {
$msg = $this->translator->trans('form_handler.size_exceeds', [
'{{ limit }}' => $limit,
], 'FxpResource');
throw new InvalidResourceException(sprintf($msg, $limit));
}
if (0 === \count($objects) && $config instanceof FormConfigListInterface) {
$objects = $config->convertObjects($dataList);
}
$dataList = array_values($dataList);
$objects = array_values($objects);
return [$dataList, $objects];
} | php | protected function getDataListObjects(FormConfigInterface $config, array $objects)
{
$limit = $this->getLimit($config instanceof FormConfigListInterface ? $config->getLimit() : null);
$dataList = $this->getDataList($config);
if (null !== $limit && \count($dataList) > $limit) {
$msg = $this->translator->trans('form_handler.size_exceeds', [
'{{ limit }}' => $limit,
], 'FxpResource');
throw new InvalidResourceException(sprintf($msg, $limit));
}
if (0 === \count($objects) && $config instanceof FormConfigListInterface) {
$objects = $config->convertObjects($dataList);
}
$dataList = array_values($dataList);
$objects = array_values($objects);
return [$dataList, $objects];
} | [
"protected",
"function",
"getDataListObjects",
"(",
"FormConfigInterface",
"$",
"config",
",",
"array",
"$",
"objects",
")",
"{",
"$",
"limit",
"=",
"$",
"this",
"->",
"getLimit",
"(",
"$",
"config",
"instanceof",
"FormConfigListInterface",
"?",
"$",
"config",
... | Get the data list and objects.
@param FormConfigInterface $config The form config
@param array[]|object[] $objects The list of object instance
@return array | [
"Get",
"the",
"data",
"list",
"and",
"objects",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/FormHandler.php#L118-L139 | train |
fxpio/fxp-resource | Handler/FormHandler.php | FormHandler.getDataList | protected function getDataList(FormConfigInterface $config)
{
$converter = $this->converterRegistry->get($config->getConverter());
$dataList = $converter->convert((string) $this->request->getContent());
if ($config instanceof FormConfigListInterface) {
try {
$dataList = $config->findList($dataList);
} catch (InvalidResourceException $e) {
throw new InvalidResourceException($this->translator->trans('form_handler.results_field_required', [], 'FxpResource'));
}
} else {
$dataList = [$dataList];
}
return $dataList;
} | php | protected function getDataList(FormConfigInterface $config)
{
$converter = $this->converterRegistry->get($config->getConverter());
$dataList = $converter->convert((string) $this->request->getContent());
if ($config instanceof FormConfigListInterface) {
try {
$dataList = $config->findList($dataList);
} catch (InvalidResourceException $e) {
throw new InvalidResourceException($this->translator->trans('form_handler.results_field_required', [], 'FxpResource'));
}
} else {
$dataList = [$dataList];
}
return $dataList;
} | [
"protected",
"function",
"getDataList",
"(",
"FormConfigInterface",
"$",
"config",
")",
"{",
"$",
"converter",
"=",
"$",
"this",
"->",
"converterRegistry",
"->",
"get",
"(",
"$",
"config",
"->",
"getConverter",
"(",
")",
")",
";",
"$",
"dataList",
"=",
"$"... | Get the form data list.
@param FormConfigInterface $config The form config
@return array | [
"Get",
"the",
"form",
"data",
"list",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/FormHandler.php#L148-L164 | train |
fxpio/fxp-resource | Handler/FormHandler.php | FormHandler.process | private function process(FormConfigInterface $config, array $objects)
{
list($dataList, $objects) = $this->getDataListObjects($config, $objects);
$forms = [];
if (\count($objects) !== \count($dataList)) {
$msg = $this->translator->trans('form_handler.different_size_request_list', [
'{{ requestSize }}' => \count($dataList),
'{{ objectSize }}' => \count($objects),
], 'FxpResource');
throw new InvalidResourceException($msg);
}
foreach ($objects as $i => $object) {
$form = $this->formFactory->create($config->getType(), $object, $config->getOptions());
$form->submit($dataList[$i], $config->getSubmitClearMissing());
$forms[] = $form;
}
return $forms;
} | php | private function process(FormConfigInterface $config, array $objects)
{
list($dataList, $objects) = $this->getDataListObjects($config, $objects);
$forms = [];
if (\count($objects) !== \count($dataList)) {
$msg = $this->translator->trans('form_handler.different_size_request_list', [
'{{ requestSize }}' => \count($dataList),
'{{ objectSize }}' => \count($objects),
], 'FxpResource');
throw new InvalidResourceException($msg);
}
foreach ($objects as $i => $object) {
$form = $this->formFactory->create($config->getType(), $object, $config->getOptions());
$form->submit($dataList[$i], $config->getSubmitClearMissing());
$forms[] = $form;
}
return $forms;
} | [
"private",
"function",
"process",
"(",
"FormConfigInterface",
"$",
"config",
",",
"array",
"$",
"objects",
")",
"{",
"list",
"(",
"$",
"dataList",
",",
"$",
"objects",
")",
"=",
"$",
"this",
"->",
"getDataListObjects",
"(",
"$",
"config",
",",
"$",
"obje... | Create the list of form for the object instances.
@param FormConfigInterface $config The form config
@param array[]|object[] $objects The list of object instance
@throws InvalidResourceException When the size if request data and the object instances is different
@return FormInterface[] | [
"Create",
"the",
"list",
"of",
"form",
"for",
"the",
"object",
"instances",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/FormHandler.php#L206-L228 | train |
hnhdigital-os/laravel-frontend-assets | src/IcheckInput.php | IcheckInput.config | public static function config($skin, $colour)
{
if (!empty($skin) && !empty($colour)) {
if (!env('APP_CDN', true)) {
FrontendAsset::add('vendor/icheck/'.$skin.'/'.$colour.'.css');
} else {
$version = FrontendAsset::version(class_basename(__CLASS__));
FrontendAsset::add('https://cdnjs.cloudflare.com/ajax/libs/iCheck/'.$version.'/skins/'.$skin.'/'.$colour.'.css');
}
}
} | php | public static function config($skin, $colour)
{
if (!empty($skin) && !empty($colour)) {
if (!env('APP_CDN', true)) {
FrontendAsset::add('vendor/icheck/'.$skin.'/'.$colour.'.css');
} else {
$version = FrontendAsset::version(class_basename(__CLASS__));
FrontendAsset::add('https://cdnjs.cloudflare.com/ajax/libs/iCheck/'.$version.'/skins/'.$skin.'/'.$colour.'.css');
}
}
} | [
"public",
"static",
"function",
"config",
"(",
"$",
"skin",
",",
"$",
"colour",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"skin",
")",
"&&",
"!",
"empty",
"(",
"$",
"colour",
")",
")",
"{",
"if",
"(",
"!",
"env",
"(",
"'APP_CDN'",
",",
"true... | Load skin for iCheck.
@param string $skin
@param string $colour
@return void | [
"Load",
"skin",
"for",
"iCheck",
"."
] | 242f605bf0c052f4d82421a8b95f227d46162e34 | https://github.com/hnhdigital-os/laravel-frontend-assets/blob/242f605bf0c052f4d82421a8b95f227d46162e34/src/IcheckInput.php#L27-L37 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.generateRouteName | private function generateRouteName(): string
{
if (!array_key_exists($this->actionName, $this->adminConfiguration->getParameter('actions'))) {
throw new Exception(
sprintf('Invalid action name %s for admin %s (available action are: %s)',
$this->actionName,
$this->adminName,
implode(', ', array_keys($this->adminConfiguration->getParameter('actions'))))
);
}
$routeName = RoutingLoader::generateRouteName(
$this->adminName,
$this->actionName,
$this->adminConfiguration->getParameter('routing_name_pattern')
);
return $routeName;
} | php | private function generateRouteName(): string
{
if (!array_key_exists($this->actionName, $this->adminConfiguration->getParameter('actions'))) {
throw new Exception(
sprintf('Invalid action name %s for admin %s (available action are: %s)',
$this->actionName,
$this->adminName,
implode(', ', array_keys($this->adminConfiguration->getParameter('actions'))))
);
}
$routeName = RoutingLoader::generateRouteName(
$this->adminName,
$this->actionName,
$this->adminConfiguration->getParameter('routing_name_pattern')
);
return $routeName;
} | [
"private",
"function",
"generateRouteName",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"actionName",
",",
"$",
"this",
"->",
"adminConfiguration",
"->",
"getParameter",
"(",
"'actions'",
")",
")",
")",
"{",
"t... | Generate an admin route name using the pattern in the configuration.
@return string
@throws Exception | [
"Generate",
"an",
"admin",
"route",
"name",
"using",
"the",
"pattern",
"in",
"the",
"configuration",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L138-L155 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.getFieldsNormalizer | private function getFieldsNormalizer()
{
return function(Options $options, $fields) {
$normalizedFields = [];
foreach ($fields as $name => $field) {
if (null === $field) {
$field = [];
}
$normalizedFields[$name] = $field;
}
return $normalizedFields;
};
} | php | private function getFieldsNormalizer()
{
return function(Options $options, $fields) {
$normalizedFields = [];
foreach ($fields as $name => $field) {
if (null === $field) {
$field = [];
}
$normalizedFields[$name] = $field;
}
return $normalizedFields;
};
} | [
"private",
"function",
"getFieldsNormalizer",
"(",
")",
"{",
"return",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"fields",
")",
"{",
"$",
"normalizedFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"... | Return the field normalizer. It will transform null configuration into array to allow field type guessing
working.
@return Closure | [
"Return",
"the",
"field",
"normalizer",
".",
"It",
"will",
"transform",
"null",
"configuration",
"into",
"array",
"to",
"allow",
"field",
"type",
"guessing",
"working",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L163-L178 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.getOrderNormalizer | private function getOrderNormalizer()
{
return function(Options $options, $order) {
foreach ($order as $field => $sort) {
if (!is_string($sort) || !is_string($field) || !in_array(strtolower($sort), ['asc', 'desc'])) {
throw new Exception(
'Order value should be an array of string (["field" => $key]), got '.gettype($sort)
);
}
}
return $order;
};
} | php | private function getOrderNormalizer()
{
return function(Options $options, $order) {
foreach ($order as $field => $sort) {
if (!is_string($sort) || !is_string($field) || !in_array(strtolower($sort), ['asc', 'desc'])) {
throw new Exception(
'Order value should be an array of string (["field" => $key]), got '.gettype($sort)
);
}
}
return $order;
};
} | [
"private",
"function",
"getOrderNormalizer",
"(",
")",
"{",
"return",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"order",
")",
"{",
"foreach",
"(",
"$",
"order",
"as",
"$",
"field",
"=>",
"$",
"sort",
")",
"{",
"if",
"(",
"!",
"is_string",
... | Return the order normalizer. It will check if the order value passed are valid.
@return Closure | [
"Return",
"the",
"order",
"normalizer",
".",
"It",
"will",
"check",
"if",
"the",
"order",
"value",
"passed",
"are",
"valid",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L185-L198 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.getLoadStrategyNormalizer | private function getLoadStrategyNormalizer()
{
return function(Options $options, $value) {
if (!$value) {
if ('create' == $this->actionName) {
$value = LAGAdminBundle::LOAD_STRATEGY_NONE;
} elseif ('list' == $this->actionName) {
$value = LAGAdminBundle::LOAD_STRATEGY_MULTIPLE;
} else {
$value = LAGAdminBundle::LOAD_STRATEGY_UNIQUE;
}
}
return $value;
};
} | php | private function getLoadStrategyNormalizer()
{
return function(Options $options, $value) {
if (!$value) {
if ('create' == $this->actionName) {
$value = LAGAdminBundle::LOAD_STRATEGY_NONE;
} elseif ('list' == $this->actionName) {
$value = LAGAdminBundle::LOAD_STRATEGY_MULTIPLE;
} else {
$value = LAGAdminBundle::LOAD_STRATEGY_UNIQUE;
}
}
return $value;
};
} | [
"private",
"function",
"getLoadStrategyNormalizer",
"(",
")",
"{",
"return",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"if",
"(",
"'create'",
"==",
"$",
"this",
"->",
"actionName",
... | Return the load strategy normalizer. It will set the default strategy according to the action name, if no value
is provided.
@return Closure | [
"Return",
"the",
"load",
"strategy",
"normalizer",
".",
"It",
"will",
"set",
"the",
"default",
"strategy",
"according",
"to",
"the",
"action",
"name",
"if",
"no",
"value",
"is",
"provided",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L206-L221 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.getCriteriaNormalizer | private function getCriteriaNormalizer()
{
return function(Options $options, $value) {
if (!$value) {
$idActions = [
'edit',
'delete',
];
if (in_array($this->actionName, $idActions)) {
$value = [
'id',
];
}
}
return $value;
};
} | php | private function getCriteriaNormalizer()
{
return function(Options $options, $value) {
if (!$value) {
$idActions = [
'edit',
'delete',
];
if (in_array($this->actionName, $idActions)) {
$value = [
'id',
];
}
}
return $value;
};
} | [
"private",
"function",
"getCriteriaNormalizer",
"(",
")",
"{",
"return",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"idActions",
"=",
"[",
"'edit'",
",",
"'delete'",
",",
"]",
... | Return the criteria normalizer. It will add the id parameters for the edit and delete actions if no value is
provided.
@return Closure | [
"Return",
"the",
"criteria",
"normalizer",
".",
"It",
"will",
"add",
"the",
"id",
"parameters",
"for",
"the",
"edit",
"and",
"delete",
"actions",
"if",
"no",
"value",
"is",
"provided",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L247-L265 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.getFiltersNormalizer | private function getFiltersNormalizer(): Closure
{
return function(Options $options, $data) {
$normalizedData = [];
foreach ($data as $name => $field) {
if (is_string($field)) {
$field = [
'type' => $field,
'options' => [],
];
}
$field['name'] = $name;
$resolver = new OptionsResolver();
$filterConfiguration = new FilterConfiguration();
$filterConfiguration->configureOptions($resolver);
$filterConfiguration->setParameters($resolver->resolve($field));
$normalizedData[$name] = $filterConfiguration->getParameters();
}
return $normalizedData;
};
} | php | private function getFiltersNormalizer(): Closure
{
return function(Options $options, $data) {
$normalizedData = [];
foreach ($data as $name => $field) {
if (is_string($field)) {
$field = [
'type' => $field,
'options' => [],
];
}
$field['name'] = $name;
$resolver = new OptionsResolver();
$filterConfiguration = new FilterConfiguration();
$filterConfiguration->configureOptions($resolver);
$filterConfiguration->setParameters($resolver->resolve($field));
$normalizedData[$name] = $filterConfiguration->getParameters();
}
return $normalizedData;
};
} | [
"private",
"function",
"getFiltersNormalizer",
"(",
")",
":",
"Closure",
"{",
"return",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"data",
")",
"{",
"$",
"normalizedData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"... | Return the filters normalizer.
@return Closure | [
"Return",
"the",
"filters",
"normalizer",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L296-L320 | train |
larriereguichet/AdminBundle | src/Configuration/ActionConfiguration.php | ActionConfiguration.getDefaultRoutePath | private function getDefaultRoutePath(): string
{
$pattern = $this
->adminConfiguration
->getParameter('routing_url_pattern')
;
$path = str_replace('{admin}', $this->adminName, $pattern);
$path = str_replace('{action}', $this->actionName, $path);
if (in_array($this->actionName, ['edit', 'delete'])) {
$path .= '/{id}';
}
return $path;
} | php | private function getDefaultRoutePath(): string
{
$pattern = $this
->adminConfiguration
->getParameter('routing_url_pattern')
;
$path = str_replace('{admin}', $this->adminName, $pattern);
$path = str_replace('{action}', $this->actionName, $path);
if (in_array($this->actionName, ['edit', 'delete'])) {
$path .= '/{id}';
}
return $path;
} | [
"private",
"function",
"getDefaultRoutePath",
"(",
")",
":",
"string",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"adminConfiguration",
"->",
"getParameter",
"(",
"'routing_url_pattern'",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"'{admin}'",
",",
"$",... | Return the default route path according to the action name.
@return string | [
"Return",
"the",
"default",
"route",
"path",
"according",
"to",
"the",
"action",
"name",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L386-L400 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/FormSubscriber.php | FormSubscriber.createForm | public function createForm(FormEvent $event): void
{
$admin = $event->getAdmin();
$action = $admin->getAction();
$configuration = $action->getConfiguration();
if (!$configuration->get('use_form')) {
return;
}
$entity = null;
if (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $configuration->get('load_strategy')) {
if (!$admin->getEntities()->isEmpty()) {
$entity = $admin->getEntities()->first();
}
}
if ('create' === $action->getName() || 'edit' === $action->getName()) {
$form = $this->adminFormFactory->createEntityForm($admin, $event->getRequest(), $entity);
$event->addForm($form, 'entity');
}
if ('delete' === $action->getName()) {
$form = $this->adminFormFactory->createDeleteForm($action, $event->getRequest(), $entity);
$event->addForm($form, 'delete');
}
} | php | public function createForm(FormEvent $event): void
{
$admin = $event->getAdmin();
$action = $admin->getAction();
$configuration = $action->getConfiguration();
if (!$configuration->get('use_form')) {
return;
}
$entity = null;
if (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $configuration->get('load_strategy')) {
if (!$admin->getEntities()->isEmpty()) {
$entity = $admin->getEntities()->first();
}
}
if ('create' === $action->getName() || 'edit' === $action->getName()) {
$form = $this->adminFormFactory->createEntityForm($admin, $event->getRequest(), $entity);
$event->addForm($form, 'entity');
}
if ('delete' === $action->getName()) {
$form = $this->adminFormFactory->createDeleteForm($action, $event->getRequest(), $entity);
$event->addForm($form, 'delete');
}
} | [
"public",
"function",
"createForm",
"(",
"FormEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"admin",
"=",
"$",
"event",
"->",
"getAdmin",
"(",
")",
";",
"$",
"action",
"=",
"$",
"admin",
"->",
"getAction",
"(",
")",
";",
"$",
"configuration",
"="... | Create a form for the loaded entity.
@param FormEvent $event | [
"Create",
"a",
"form",
"for",
"the",
"loaded",
"entity",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/FormSubscriber.php#L77-L103 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/FormSubscriber.php | FormSubscriber.handleForm | public function handleForm(FormEvent $event): void
{
$admin = $event->getAdmin();
$action = $admin->getAction();
if ('delete' === $action->getName()) {
if (!$admin->hasForm('delete')) {
return;
}
$form = $admin->getForm('delete');
$this->handleDeleteForm($event->getRequest(), $form, $admin);
}
} | php | public function handleForm(FormEvent $event): void
{
$admin = $event->getAdmin();
$action = $admin->getAction();
if ('delete' === $action->getName()) {
if (!$admin->hasForm('delete')) {
return;
}
$form = $admin->getForm('delete');
$this->handleDeleteForm($event->getRequest(), $form, $admin);
}
} | [
"public",
"function",
"handleForm",
"(",
"FormEvent",
"$",
"event",
")",
":",
"void",
"{",
"$",
"admin",
"=",
"$",
"event",
"->",
"getAdmin",
"(",
")",
";",
"$",
"action",
"=",
"$",
"admin",
"->",
"getAction",
"(",
")",
";",
"if",
"(",
"'delete'",
... | When the HANDLE_FORM event is dispatched, we handle the form according to the current action.
@param FormEvent $event | [
"When",
"the",
"HANDLE_FORM",
"event",
"is",
"dispatched",
"we",
"handle",
"the",
"form",
"according",
"to",
"the",
"current",
"action",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/FormSubscriber.php#L110-L122 | train |
larriereguichet/AdminBundle | src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php | ORMSubscriber.addOrder | public function addOrder(ORMFilterEvent $event)
{
$queryBuilder = $event->getQueryBuilder();
$admin = $event->getAdmin();
$actionConfiguration = $admin->getAction()->getConfiguration();
$request = $this->requestStack->getMasterRequest();
$sort = $request->get('sort');
$alias = $queryBuilder->getRootAliases()[0];
// The sort from the request override the configured one
if ($sort) {
$order = $request->get('order', 'asc');
$queryBuilder->addOrderBy($alias.'.'.$sort, $order);
} else {
foreach ($actionConfiguration->getParameter('order') as $field => $order) {
$queryBuilder->addOrderBy($alias.'.'.$field, $order);
}
}
} | php | public function addOrder(ORMFilterEvent $event)
{
$queryBuilder = $event->getQueryBuilder();
$admin = $event->getAdmin();
$actionConfiguration = $admin->getAction()->getConfiguration();
$request = $this->requestStack->getMasterRequest();
$sort = $request->get('sort');
$alias = $queryBuilder->getRootAliases()[0];
// The sort from the request override the configured one
if ($sort) {
$order = $request->get('order', 'asc');
$queryBuilder->addOrderBy($alias.'.'.$sort, $order);
} else {
foreach ($actionConfiguration->getParameter('order') as $field => $order) {
$queryBuilder->addOrderBy($alias.'.'.$field, $order);
}
}
} | [
"public",
"function",
"addOrder",
"(",
"ORMFilterEvent",
"$",
"event",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"event",
"->",
"getQueryBuilder",
"(",
")",
";",
"$",
"admin",
"=",
"$",
"event",
"->",
"getAdmin",
"(",
")",
";",
"$",
"actionConfiguration",
... | Add the order to query builder according to the configuration.
@param ORMFilterEvent $event | [
"Add",
"the",
"order",
"to",
"query",
"builder",
"according",
"to",
"the",
"configuration",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php#L57-L77 | train |
larriereguichet/AdminBundle | src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php | ORMSubscriber.addFilters | public function addFilters(ORMFilterEvent $event)
{
$queryBuilder = $event->getQueryBuilder();
foreach ($event->getFilters() as $filter) {
$alias = $queryBuilder->getRootAliases()[0];
$parameterName = 'filter_'.$filter->getName();
$value = $filter->getValue();
if ('like' === $filter->getComparator()) {
$value = '%'.$value.'%';
}
if ('and' === $filter->getOperator()) {
$method = 'andWhere';
} else {
$method = 'orWhere';
}
$queryBuilder->$method(sprintf(
'%s.%s %s %s',
$alias,
$filter->getName(),
$filter->getComparator(),
':'.$parameterName
));
$queryBuilder->setParameter($parameterName, $value);
}
} | php | public function addFilters(ORMFilterEvent $event)
{
$queryBuilder = $event->getQueryBuilder();
foreach ($event->getFilters() as $filter) {
$alias = $queryBuilder->getRootAliases()[0];
$parameterName = 'filter_'.$filter->getName();
$value = $filter->getValue();
if ('like' === $filter->getComparator()) {
$value = '%'.$value.'%';
}
if ('and' === $filter->getOperator()) {
$method = 'andWhere';
} else {
$method = 'orWhere';
}
$queryBuilder->$method(sprintf(
'%s.%s %s %s',
$alias,
$filter->getName(),
$filter->getComparator(),
':'.$parameterName
));
$queryBuilder->setParameter($parameterName, $value);
}
} | [
"public",
"function",
"addFilters",
"(",
"ORMFilterEvent",
"$",
"event",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"event",
"->",
"getQueryBuilder",
"(",
")",
";",
"foreach",
"(",
"$",
"event",
"->",
"getFilters",
"(",
")",
"as",
"$",
"filter",
")",
"{",
... | Add filter to the query builder.
@param ORMFilterEvent $event | [
"Add",
"filter",
"to",
"the",
"query",
"builder",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php#L84-L112 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.getIdentifier | public static function getIdentifier(ObjectManager $om, $object)
{
$propertyAccess = PropertyAccess::createPropertyAccessor();
$meta = $om->getClassMetadata(ClassUtils::getClass($object));
$ids = $meta->getIdentifier();
$value = null;
foreach ($ids as $id) {
$idVal = $propertyAccess->getValue($object, $id);
if (null !== $idVal) {
$value = $idVal;
break;
}
}
return $value;
} | php | public static function getIdentifier(ObjectManager $om, $object)
{
$propertyAccess = PropertyAccess::createPropertyAccessor();
$meta = $om->getClassMetadata(ClassUtils::getClass($object));
$ids = $meta->getIdentifier();
$value = null;
foreach ($ids as $id) {
$idVal = $propertyAccess->getValue($object, $id);
if (null !== $idVal) {
$value = $idVal;
break;
}
}
return $value;
} | [
"public",
"static",
"function",
"getIdentifier",
"(",
"ObjectManager",
"$",
"om",
",",
"$",
"object",
")",
"{",
"$",
"propertyAccess",
"=",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
";",
"$",
"meta",
"=",
"$",
"om",
"->",
"getClassMetadata",
... | Get the value of resource identifier.
@param ObjectManager $om The doctrine object manager
@param object $object The resource object
@return null|int|string | [
"Get",
"the",
"value",
"of",
"resource",
"identifier",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L51-L69 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.getIdentifierName | public static function getIdentifierName(ObjectManager $om, $className)
{
$meta = $om->getClassMetadata($className);
$ids = $meta->getIdentifier();
return implode('', $ids);
} | php | public static function getIdentifierName(ObjectManager $om, $className)
{
$meta = $om->getClassMetadata($className);
$ids = $meta->getIdentifier();
return implode('', $ids);
} | [
"public",
"static",
"function",
"getIdentifierName",
"(",
"ObjectManager",
"$",
"om",
",",
"$",
"className",
")",
"{",
"$",
"meta",
"=",
"$",
"om",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"$",
"ids",
"=",
"$",
"meta",
"->",
"getIdentif... | Get the name of identifier.
@param ObjectManager $om The doctrine object manager
@param string $className The class name
@return string | [
"Get",
"the",
"name",
"of",
"identifier",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L79-L85 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.getEventClasses | public static function getEventClasses($type)
{
$names = [PreUpsertsEvent::class, PostUpsertsEvent::class];
if (Domain::TYPE_CREATE === $type) {
$names = [PreCreatesEvent::class, PostCreatesEvent::class];
} elseif (Domain::TYPE_UPDATE === $type) {
$names = [PreUpdatesEvent::class, PostUpdatesEvent::class];
} elseif (Domain::TYPE_DELETE === $type) {
$names = [PreDeletesEvent::class, PostDeletesEvent::class];
} elseif (Domain::TYPE_UNDELETE === $type) {
$names = [PreUndeletesEvent::class, PostUndeletesEvent::class];
}
return $names;
} | php | public static function getEventClasses($type)
{
$names = [PreUpsertsEvent::class, PostUpsertsEvent::class];
if (Domain::TYPE_CREATE === $type) {
$names = [PreCreatesEvent::class, PostCreatesEvent::class];
} elseif (Domain::TYPE_UPDATE === $type) {
$names = [PreUpdatesEvent::class, PostUpdatesEvent::class];
} elseif (Domain::TYPE_DELETE === $type) {
$names = [PreDeletesEvent::class, PostDeletesEvent::class];
} elseif (Domain::TYPE_UNDELETE === $type) {
$names = [PreUndeletesEvent::class, PostUndeletesEvent::class];
}
return $names;
} | [
"public",
"static",
"function",
"getEventClasses",
"(",
"$",
"type",
")",
"{",
"$",
"names",
"=",
"[",
"PreUpsertsEvent",
"::",
"class",
",",
"PostUpsertsEvent",
"::",
"class",
"]",
";",
"if",
"(",
"Domain",
"::",
"TYPE_CREATE",
"===",
"$",
"type",
")",
... | Get the event names of persist action.
@param int $type The type of persist
@return array The list of pre event name and post event name | [
"Get",
"the",
"event",
"names",
"of",
"persist",
"action",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L94-L109 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.extractIdentifierInObjectList | public static function extractIdentifierInObjectList(array $identifiers, array &$objects)
{
$searchIds = [];
foreach ($identifiers as $identifier) {
if (\is_object($identifier)) {
$objects[] = $identifier;
continue;
}
$searchIds[] = $identifier;
}
return $searchIds;
} | php | public static function extractIdentifierInObjectList(array $identifiers, array &$objects)
{
$searchIds = [];
foreach ($identifiers as $identifier) {
if (\is_object($identifier)) {
$objects[] = $identifier;
continue;
}
$searchIds[] = $identifier;
}
return $searchIds;
} | [
"public",
"static",
"function",
"extractIdentifierInObjectList",
"(",
"array",
"$",
"identifiers",
",",
"array",
"&",
"$",
"objects",
")",
"{",
"$",
"searchIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"identifier",
")",
"{",
"if... | Extract the identifier that are not a object.
@param array $identifiers The list containing identifier or object
@param array $objects The real objects (by reference)
@return array The identifiers that are not a object | [
"Extract",
"the",
"identifier",
"that",
"are",
"not",
"a",
"object",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L119-L133 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.oneAction | public static function oneAction(ResourceListInterface $resources)
{
$resources->get(0)->getErrors()->addAll($resources->getErrors());
return $resources->get(0);
} | php | public static function oneAction(ResourceListInterface $resources)
{
$resources->get(0)->getErrors()->addAll($resources->getErrors());
return $resources->get(0);
} | [
"public",
"static",
"function",
"oneAction",
"(",
"ResourceListInterface",
"$",
"resources",
")",
"{",
"$",
"resources",
"->",
"get",
"(",
"0",
")",
"->",
"getErrors",
"(",
")",
"->",
"addAll",
"(",
"$",
"resources",
"->",
"getErrors",
"(",
")",
")",
";"... | Inject the list errors in the first resource, and return the this first resource.
@param ResourceListInterface $resources The resource list
@return ResourceInterface The first resource | [
"Inject",
"the",
"list",
"errors",
"in",
"the",
"first",
"resource",
"and",
"return",
"the",
"this",
"first",
"resource",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L142-L147 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.moveFlushErrorsInResource | public static function moveFlushErrorsInResource(ResourceListInterface $resources, ConstraintViolationListInterface $errors): void
{
if ($errors->count() > 0) {
$maps = static::getMapErrors($errors);
foreach ($resources->all() as $resource) {
$resource->setStatus(ResourceStatutes::ERROR);
$hash = spl_object_hash($resource->getRealData());
if (isset($maps[$hash])) {
$resource->getErrors()->add($maps[$hash]);
unset($maps[$hash]);
}
}
foreach ($maps as $error) {
$resources->getErrors()->add($error);
}
}
} | php | public static function moveFlushErrorsInResource(ResourceListInterface $resources, ConstraintViolationListInterface $errors): void
{
if ($errors->count() > 0) {
$maps = static::getMapErrors($errors);
foreach ($resources->all() as $resource) {
$resource->setStatus(ResourceStatutes::ERROR);
$hash = spl_object_hash($resource->getRealData());
if (isset($maps[$hash])) {
$resource->getErrors()->add($maps[$hash]);
unset($maps[$hash]);
}
}
foreach ($maps as $error) {
$resources->getErrors()->add($error);
}
}
} | [
"public",
"static",
"function",
"moveFlushErrorsInResource",
"(",
"ResourceListInterface",
"$",
"resources",
",",
"ConstraintViolationListInterface",
"$",
"errors",
")",
":",
"void",
"{",
"if",
"(",
"$",
"errors",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"... | Move the flush errors in each resource if the root object is present in constraint violation.
@param ResourceListInterface $resources The list of resources
@param ConstraintViolationListInterface $errors The list of flush errors | [
"Move",
"the",
"flush",
"errors",
"in",
"each",
"resource",
"if",
"the",
"root",
"object",
"is",
"present",
"in",
"constraint",
"violation",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L155-L173 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.cancelAllSuccessResources | public static function cancelAllSuccessResources(ResourceListInterface $resources): void
{
foreach ($resources->all() as $resource) {
if (ResourceStatutes::ERROR !== $resource->getStatus()) {
$resource->setStatus(ResourceStatutes::CANCELED);
}
}
} | php | public static function cancelAllSuccessResources(ResourceListInterface $resources): void
{
foreach ($resources->all() as $resource) {
if (ResourceStatutes::ERROR !== $resource->getStatus()) {
$resource->setStatus(ResourceStatutes::CANCELED);
}
}
} | [
"public",
"static",
"function",
"cancelAllSuccessResources",
"(",
"ResourceListInterface",
"$",
"resources",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"resources",
"->",
"all",
"(",
")",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"ResourceStatutes",
"::",
... | Cancel all resource in list that have an successfully status.
@param ResourceListInterface $resources The list of resources | [
"Cancel",
"all",
"resource",
"in",
"list",
"that",
"have",
"an",
"successfully",
"status",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L180-L187 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.getExceptionMessage | public static function getExceptionMessage(TranslatorInterface $translator, \Exception $exception, $debug = false)
{
$message = $translator->trans('domain.database_error', [], 'FxpResource');
if ($debug) {
$message .= ' ['.\get_class($exception).']';
}
if ($exception instanceof DriverException) {
return static::extractDriverExceptionMessage($exception, $message, $debug);
}
return $debug
? $exception->getMessage()
: $message;
} | php | public static function getExceptionMessage(TranslatorInterface $translator, \Exception $exception, $debug = false)
{
$message = $translator->trans('domain.database_error', [], 'FxpResource');
if ($debug) {
$message .= ' ['.\get_class($exception).']';
}
if ($exception instanceof DriverException) {
return static::extractDriverExceptionMessage($exception, $message, $debug);
}
return $debug
? $exception->getMessage()
: $message;
} | [
"public",
"static",
"function",
"getExceptionMessage",
"(",
"TranslatorInterface",
"$",
"translator",
",",
"\\",
"Exception",
"$",
"exception",
",",
"$",
"debug",
"=",
"false",
")",
"{",
"$",
"message",
"=",
"$",
"translator",
"->",
"trans",
"(",
"'domain.data... | Get the exception message.
@param TranslatorInterface $translator The translator
@param \Exception $exception The exception
@param bool $debug The debug mode
@return string | [
"Get",
"the",
"exception",
"message",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L198-L213 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.addResourceError | public static function addResourceError(ResourceInterface $resource, $message, \Exception $e = null): void
{
$resource->setStatus(ResourceStatutes::ERROR);
$resource->getErrors()->add(new ConstraintViolation($message, $message, [], $resource->getRealData(), null, null, null, null, null, $e));
} | php | public static function addResourceError(ResourceInterface $resource, $message, \Exception $e = null): void
{
$resource->setStatus(ResourceStatutes::ERROR);
$resource->getErrors()->add(new ConstraintViolation($message, $message, [], $resource->getRealData(), null, null, null, null, null, $e));
} | [
"public",
"static",
"function",
"addResourceError",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"message",
",",
"\\",
"Exception",
"$",
"e",
"=",
"null",
")",
":",
"void",
"{",
"$",
"resource",
"->",
"setStatus",
"(",
"ResourceStatutes",
"::",
"ERRO... | Add the error in resource.
@param ResourceInterface $resource The resource
@param string $message The error message
@param null|\Exception $e The exception | [
"Add",
"the",
"error",
"in",
"resource",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L222-L226 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.injectErrorMessage | public static function injectErrorMessage(TranslatorInterface $translator, ResourceInterface $resource, \Exception $e, $debug = false)
{
if ($e instanceof ConstraintViolationException) {
$resource->setStatus(ResourceStatutes::ERROR);
$resource->getErrors()->addAll($e->getConstraintViolations());
} else {
static::addResourceError($resource, static::getExceptionMessage($translator, $e, $debug), $e);
}
return true;
} | php | public static function injectErrorMessage(TranslatorInterface $translator, ResourceInterface $resource, \Exception $e, $debug = false)
{
if ($e instanceof ConstraintViolationException) {
$resource->setStatus(ResourceStatutes::ERROR);
$resource->getErrors()->addAll($e->getConstraintViolations());
} else {
static::addResourceError($resource, static::getExceptionMessage($translator, $e, $debug), $e);
}
return true;
} | [
"public",
"static",
"function",
"injectErrorMessage",
"(",
"TranslatorInterface",
"$",
"translator",
",",
"ResourceInterface",
"$",
"resource",
",",
"\\",
"Exception",
"$",
"e",
",",
"$",
"debug",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"C... | Inject the exception message in resource error list.
@param TranslatorInterface $translator The translator
@param ResourceInterface $resource The resource
@param \Exception $e The exception on persist action
@param bool $debug The debug mode
@return bool | [
"Inject",
"the",
"exception",
"message",
"in",
"resource",
"error",
"list",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L238-L248 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.getMapErrors | protected static function getMapErrors(ConstraintViolationListInterface $errors)
{
$maps = [];
$size = $errors->count();
for ($i = 0; $i < $size; ++$i) {
$root = $errors->get($i)->getRoot();
if (\is_object($root)) {
$maps[spl_object_hash($errors->get($i)->getRoot())] = $errors->get($i);
} else {
$maps[] = $errors->get($i);
}
}
return $maps;
} | php | protected static function getMapErrors(ConstraintViolationListInterface $errors)
{
$maps = [];
$size = $errors->count();
for ($i = 0; $i < $size; ++$i) {
$root = $errors->get($i)->getRoot();
if (\is_object($root)) {
$maps[spl_object_hash($errors->get($i)->getRoot())] = $errors->get($i);
} else {
$maps[] = $errors->get($i);
}
}
return $maps;
} | [
"protected",
"static",
"function",
"getMapErrors",
"(",
"ConstraintViolationListInterface",
"$",
"errors",
")",
"{",
"$",
"maps",
"=",
"[",
"]",
";",
"$",
"size",
"=",
"$",
"errors",
"->",
"count",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
... | Get the map of object hash and constraint violation list.
@param ConstraintViolationListInterface $errors
@return array The map of object hash and constraint violation list | [
"Get",
"the",
"map",
"of",
"object",
"hash",
"and",
"constraint",
"violation",
"list",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L257-L273 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.extractDriverExceptionMessage | protected static function extractDriverExceptionMessage(DriverException $exception, $message, $debug = false)
{
if ($debug && null !== $exception->getPrevious()) {
$prevMessage = static::getFirstException($exception)->getMessage();
$pos = strpos($prevMessage, ':');
if ($pos > 0 && 0 === strpos($prevMessage, 'SQLSTATE[')) {
$message .= ': '.trim(substr($prevMessage, $pos + 1));
}
}
return $message;
} | php | protected static function extractDriverExceptionMessage(DriverException $exception, $message, $debug = false)
{
if ($debug && null !== $exception->getPrevious()) {
$prevMessage = static::getFirstException($exception)->getMessage();
$pos = strpos($prevMessage, ':');
if ($pos > 0 && 0 === strpos($prevMessage, 'SQLSTATE[')) {
$message .= ': '.trim(substr($prevMessage, $pos + 1));
}
}
return $message;
} | [
"protected",
"static",
"function",
"extractDriverExceptionMessage",
"(",
"DriverException",
"$",
"exception",
",",
"$",
"message",
",",
"$",
"debug",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"debug",
"&&",
"null",
"!==",
"$",
"exception",
"->",
"getPrevious",
... | Format pdo driver exception.
@param DriverException $exception The exception
@param string $message The message
@param bool $debug The debug mode
@return string | [
"Format",
"pdo",
"driver",
"exception",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L284-L296 | train |
fxpio/fxp-resource | Domain/DomainUtil.php | DomainUtil.getFirstException | protected static function getFirstException(\Exception $exception)
{
if (null !== $exception->getPrevious()) {
return static::getFirstException($exception->getPrevious());
}
return $exception;
} | php | protected static function getFirstException(\Exception $exception)
{
if (null !== $exception->getPrevious()) {
return static::getFirstException($exception->getPrevious());
}
return $exception;
} | [
"protected",
"static",
"function",
"getFirstException",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
")",
"{",
"return",
"static",
"::",
"getFirstException",
"(",
"$",
"excepti... | Get the initial exception.
@param \Exception $exception
@return \Exception | [
"Get",
"the",
"initial",
"exception",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L305-L312 | train |
Smart-Core/CoreBundle | Pagerfanta/DoctrineORM/WhereInWalker.php | WhereInWalker.walkSelectStatement | public function walkSelectStatement(SelectStatement $AST)
{
$parent = null;
$parentName = null;
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
$parent = $qComp;
$parentName = $dqlAlias;
break;
}
}
$pathExpression = new PathExpression(
PathExpression::TYPE_STATE_FIELD, $parentName, $parent['metadata']->getSingleIdentifierFieldName()
);
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
$count = $this->_getQuery()->getHint('id.count');
if ($count > 0) {
// in new doctrine 2.2 version there's a different expression
if (property_exists('Doctrine\ORM\Query\AST\InExpression', 'expression')) {
$arithmeticExpression = new ArithmeticExpression();
$arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression(
array($pathExpression)
);
$inExpression = new InExpression($arithmeticExpression);
} else {
$inExpression = new InExpression($pathExpression);
}
$ns = $this->_getQuery()->getHint('pg.ns');
for ($i = 1; $i <= $count; $i++) {
$inExpression->literals[] = new InputParameter(":{$ns}_$i");
}
} else {
$inExpression = new NullComparisonExpression($pathExpression);
$inExpression->not = false;
}
$conditionalPrimary = new ConditionalPrimary;
$conditionalPrimary->simpleConditionalExpression = $inExpression;
// if no existing whereClause
if ($AST->whereClause === null) {
$AST->whereClause = new WhereClause(
new ConditionalExpression(array(
new ConditionalTerm(array(
new ConditionalFactor($conditionalPrimary)
))
))
);
} else { // add to the existing using AND
// existing AND clause
if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) {
$AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary;
}
// single clause where
elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) {
$AST->whereClause->conditionalExpression = new ConditionalExpression(
array(
new ConditionalTerm(
array(
$AST->whereClause->conditionalExpression,
$conditionalPrimary
)
)
)
);
}
// an OR or NOT clause
elseif ($AST->whereClause->conditionalExpression instanceof ConditionalExpression
|| $AST->whereClause->conditionalExpression instanceof ConditionalFactor
) {
$tmpPrimary = new ConditionalPrimary;
$tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression;
$AST->whereClause->conditionalExpression = new ConditionalTerm(
array(
$tmpPrimary,
$conditionalPrimary,
)
);
} else {
// error check to provide a more verbose error on failure
throw new \RuntimeException("Unknown conditionalExpression in WhereInWalker");
}
}
} | php | public function walkSelectStatement(SelectStatement $AST)
{
$parent = null;
$parentName = null;
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
$parent = $qComp;
$parentName = $dqlAlias;
break;
}
}
$pathExpression = new PathExpression(
PathExpression::TYPE_STATE_FIELD, $parentName, $parent['metadata']->getSingleIdentifierFieldName()
);
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
$count = $this->_getQuery()->getHint('id.count');
if ($count > 0) {
// in new doctrine 2.2 version there's a different expression
if (property_exists('Doctrine\ORM\Query\AST\InExpression', 'expression')) {
$arithmeticExpression = new ArithmeticExpression();
$arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression(
array($pathExpression)
);
$inExpression = new InExpression($arithmeticExpression);
} else {
$inExpression = new InExpression($pathExpression);
}
$ns = $this->_getQuery()->getHint('pg.ns');
for ($i = 1; $i <= $count; $i++) {
$inExpression->literals[] = new InputParameter(":{$ns}_$i");
}
} else {
$inExpression = new NullComparisonExpression($pathExpression);
$inExpression->not = false;
}
$conditionalPrimary = new ConditionalPrimary;
$conditionalPrimary->simpleConditionalExpression = $inExpression;
// if no existing whereClause
if ($AST->whereClause === null) {
$AST->whereClause = new WhereClause(
new ConditionalExpression(array(
new ConditionalTerm(array(
new ConditionalFactor($conditionalPrimary)
))
))
);
} else { // add to the existing using AND
// existing AND clause
if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) {
$AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary;
}
// single clause where
elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) {
$AST->whereClause->conditionalExpression = new ConditionalExpression(
array(
new ConditionalTerm(
array(
$AST->whereClause->conditionalExpression,
$conditionalPrimary
)
)
)
);
}
// an OR or NOT clause
elseif ($AST->whereClause->conditionalExpression instanceof ConditionalExpression
|| $AST->whereClause->conditionalExpression instanceof ConditionalFactor
) {
$tmpPrimary = new ConditionalPrimary;
$tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression;
$AST->whereClause->conditionalExpression = new ConditionalTerm(
array(
$tmpPrimary,
$conditionalPrimary,
)
);
} else {
// error check to provide a more verbose error on failure
throw new \RuntimeException("Unknown conditionalExpression in WhereInWalker");
}
}
} | [
"public",
"function",
"walkSelectStatement",
"(",
"SelectStatement",
"$",
"AST",
")",
"{",
"$",
"parent",
"=",
"null",
";",
"$",
"parentName",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"_getQueryComponents",
"(",
")",
"as",
"$",
"dqlAlias",
"=>"... | Replaces the whereClause in the AST
Generates a clause equivalent to WHERE IN (:pgid_1, :pgid_2, ...)
The parameter namespace (pgid) is retrieved from the pg.ns query hint
The total number of parameters is retrieved from the id.count query hint
@param SelectStatement $AST
@return void | [
"Replaces",
"the",
"whereClause",
"in",
"the",
"AST"
] | d74829de254237008eb92ad213c7e7f41d91aac4 | https://github.com/Smart-Core/CoreBundle/blob/d74829de254237008eb92ad213c7e7f41d91aac4/Pagerfanta/DoctrineORM/WhereInWalker.php#L50-L135 | train |
systemson/common | src/Utils/Implementations/AbstractWrapper.php | AbstractWrapper.getInstance | public static function getInstance()
{
$accesor = static::getAccessor();
if (!static::$instance instanceof $accesor) {
static::beforeConstruct();
$args = static::getArguments();
static::$instance = static::make($accesor, $args);
static::afterConstruct();
}
return static::$instance;
} | php | public static function getInstance()
{
$accesor = static::getAccessor();
if (!static::$instance instanceof $accesor) {
static::beforeConstruct();
$args = static::getArguments();
static::$instance = static::make($accesor, $args);
static::afterConstruct();
}
return static::$instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
")",
"{",
"$",
"accesor",
"=",
"static",
"::",
"getAccessor",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"$",
"instance",
"instanceof",
"$",
"accesor",
")",
"{",
"static",
"::",
"beforeConstruct",
"... | Returns the instance of the class. | [
"Returns",
"the",
"instance",
"of",
"the",
"class",
"."
] | 00333341bbdba6cd1e4cdb7561f7e17bc756935e | https://github.com/systemson/common/blob/00333341bbdba6cd1e4cdb7561f7e17bc756935e/src/Utils/Implementations/AbstractWrapper.php#L84-L99 | train |
fxpio/fxp-resource | Handler/DomainFormConfigList.php | DomainFormConfigList.findObjects | protected function findObjects(array $ids)
{
$foundObjects = $this->domain->getRepository()->findBy([
$this->identifier => array_unique($ids),
]);
$mapFinds = [];
$objects = [];
foreach ($foundObjects as $foundObject) {
$id = $this->propertyAccessor->getValue($foundObject, $this->identifier);
$mapFinds[$id] = $foundObject;
}
foreach ($ids as $i => $id) {
$objects[$i] = $mapFinds[$id]
?? $this->domain->newInstance($this->defaultValueOptions);
}
return $objects;
} | php | protected function findObjects(array $ids)
{
$foundObjects = $this->domain->getRepository()->findBy([
$this->identifier => array_unique($ids),
]);
$mapFinds = [];
$objects = [];
foreach ($foundObjects as $foundObject) {
$id = $this->propertyAccessor->getValue($foundObject, $this->identifier);
$mapFinds[$id] = $foundObject;
}
foreach ($ids as $i => $id) {
$objects[$i] = $mapFinds[$id]
?? $this->domain->newInstance($this->defaultValueOptions);
}
return $objects;
} | [
"protected",
"function",
"findObjects",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"foundObjects",
"=",
"$",
"this",
"->",
"domain",
"->",
"getRepository",
"(",
")",
"->",
"findBy",
"(",
"[",
"$",
"this",
"->",
"identifier",
"=>",
"array_unique",
"(",
"$",... | Find the objects.
@param int[] $ids The record ids
@return array | [
"Find",
"the",
"objects",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/DomainFormConfigList.php#L137-L156 | train |
larriereguichet/AdminBundle | src/Bridge/Twig/Extension/FieldExtension.php | FieldExtension.renderFieldHeader | public function renderFieldHeader(ViewInterface $admin, FieldInterface $field)
{
return $this->renderer->renderHeader($admin, $field);
} | php | public function renderFieldHeader(ViewInterface $admin, FieldInterface $field)
{
return $this->renderer->renderHeader($admin, $field);
} | [
"public",
"function",
"renderFieldHeader",
"(",
"ViewInterface",
"$",
"admin",
",",
"FieldInterface",
"$",
"field",
")",
"{",
"return",
"$",
"this",
"->",
"renderer",
"->",
"renderHeader",
"(",
"$",
"admin",
",",
"$",
"field",
")",
";",
"}"
] | Return the field header label.
@param ViewInterface $admin
@param FieldInterface $field
@return string | [
"Return",
"the",
"field",
"header",
"label",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Twig/Extension/FieldExtension.php#L44-L47 | train |
yawik/cv | src/Factory/Form/AttachmentsFormFactory.php | AttachmentsFormFactory.configureForm | protected function configureForm($form, AbstractOptions $options)
{
if (!$options instanceof ModuleOptions) {
throw new \InvalidArgumentException(sprintf('$options must be instance of %s', ModuleOptions::class));
}
$size = $options->getAttachmentsMaxSize();
$type = $options->getAttachmentsMimeType();
$count = $options->getAttachmentsCount();
$form->setIsDisableCapable(false)
->setIsDisableElementsCapable(false)
->setIsDescriptionsEnabled(true)
->setDescription(
/*@translate*/ 'Attach images or PDF Documents to your CV. Drag&drop them, or click into the attachement area. You can upload up to %sMB',
[round($size/(1024*1024))>0? round($size/(1024*1024)):round($size/(1024*1024), 1)]
)
->setParam('return', 'file-uri')
->setLabel(/*@translate*/ 'Attachments');
/* @var $file \Core\Form\Element\FileUpload */
$file = $form->get($this->fileName);
$file->setMaxSize($size);
if ($type) {
$file->setAllowedTypes($type);
}
$file->setMaxFileCount($count);
// pass form to element. Needed for file count validation
// I did not find another (better) way.
$file->setForm($form);
} | php | protected function configureForm($form, AbstractOptions $options)
{
if (!$options instanceof ModuleOptions) {
throw new \InvalidArgumentException(sprintf('$options must be instance of %s', ModuleOptions::class));
}
$size = $options->getAttachmentsMaxSize();
$type = $options->getAttachmentsMimeType();
$count = $options->getAttachmentsCount();
$form->setIsDisableCapable(false)
->setIsDisableElementsCapable(false)
->setIsDescriptionsEnabled(true)
->setDescription(
/*@translate*/ 'Attach images or PDF Documents to your CV. Drag&drop them, or click into the attachement area. You can upload up to %sMB',
[round($size/(1024*1024))>0? round($size/(1024*1024)):round($size/(1024*1024), 1)]
)
->setParam('return', 'file-uri')
->setLabel(/*@translate*/ 'Attachments');
/* @var $file \Core\Form\Element\FileUpload */
$file = $form->get($this->fileName);
$file->setMaxSize($size);
if ($type) {
$file->setAllowedTypes($type);
}
$file->setMaxFileCount($count);
// pass form to element. Needed for file count validation
// I did not find another (better) way.
$file->setForm($form);
} | [
"protected",
"function",
"configureForm",
"(",
"$",
"form",
",",
"AbstractOptions",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"$",
"options",
"instanceof",
"ModuleOptions",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'$opt... | configure the formular for uploading attachments
@param Form $form
@param AbstractOptions $options | [
"configure",
"the",
"formular",
"for",
"uploading",
"attachments"
] | a3c57c060d3f1c353c3e8ef3542b77147d4ec012 | https://github.com/yawik/cv/blob/a3c57c060d3f1c353c3e8ef3542b77147d4ec012/src/Factory/Form/AttachmentsFormFactory.php#L65-L97 | train |
larriereguichet/AdminBundle | src/Bridge/Doctrine/ORM/DataProvider/ORMDataProvider.php | ORMDataProvider.getCollection | public function getCollection(AdminInterface $admin, array $filters = [])
{
$adminConfiguration = $admin->getConfiguration();
$actionConfiguration = $admin->getAction()->getConfiguration();
// Create a query builder for the configured entity class
$queryBuilder = $this
->getRepository($adminConfiguration->getParameter('entity'))
->createQueryBuilder('entity')
;
// Dispatch an event to allow filter alteration on the query builder
$event = new ORMFilterEvent($queryBuilder, $admin, $filters);
$this->eventDispatcher->dispatch(Events::DOCTRINE_ORM_FILTER, $event);
if ('pagerfanta' === $actionConfiguration->getParameter('pager')) {
$pageParameter = $actionConfiguration->getParameter('page_parameter');
$request = $this->requestStack->getCurrentRequest();
$page = (int) $request->get($pageParameter, 1);
$adapter = new DoctrineORMAdapter($queryBuilder);
$pager = new Pagerfanta($adapter);
$pager->setCurrentPage($page);
$pager->setMaxPerPage($actionConfiguration->getParameter('max_per_page'));
$entities = $pager;
} else {
$entities = $queryBuilder->getQuery()->getResult();
}
return $entities;
} | php | public function getCollection(AdminInterface $admin, array $filters = [])
{
$adminConfiguration = $admin->getConfiguration();
$actionConfiguration = $admin->getAction()->getConfiguration();
// Create a query builder for the configured entity class
$queryBuilder = $this
->getRepository($adminConfiguration->getParameter('entity'))
->createQueryBuilder('entity')
;
// Dispatch an event to allow filter alteration on the query builder
$event = new ORMFilterEvent($queryBuilder, $admin, $filters);
$this->eventDispatcher->dispatch(Events::DOCTRINE_ORM_FILTER, $event);
if ('pagerfanta' === $actionConfiguration->getParameter('pager')) {
$pageParameter = $actionConfiguration->getParameter('page_parameter');
$request = $this->requestStack->getCurrentRequest();
$page = (int) $request->get($pageParameter, 1);
$adapter = new DoctrineORMAdapter($queryBuilder);
$pager = new Pagerfanta($adapter);
$pager->setCurrentPage($page);
$pager->setMaxPerPage($actionConfiguration->getParameter('max_per_page'));
$entities = $pager;
} else {
$entities = $queryBuilder->getQuery()->getResult();
}
return $entities;
} | [
"public",
"function",
"getCollection",
"(",
"AdminInterface",
"$",
"admin",
",",
"array",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"$",
"adminConfiguration",
"=",
"$",
"admin",
"->",
"getConfiguration",
"(",
")",
";",
"$",
"actionConfiguration",
"=",
"$",
... | Load a collection of entities.
@param AdminInterface $admin
@param array $filters
@return mixed | [
"Load",
"a",
"collection",
"of",
"entities",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Doctrine/ORM/DataProvider/ORMDataProvider.php#L60-L90 | train |
larriereguichet/AdminBundle | src/Factory/DataProviderFactory.php | DataProviderFactory.add | public function add($id, DataProviderInterface $dataProvider)
{
if ($this->has($id)) {
throw new Exception('Trying to add the data provider '.$id.' twice');
}
// add the data provider to collection, indexed by ids
$this->dataProviders[$id] = $dataProvider;
} | php | public function add($id, DataProviderInterface $dataProvider)
{
if ($this->has($id)) {
throw new Exception('Trying to add the data provider '.$id.' twice');
}
// add the data provider to collection, indexed by ids
$this->dataProviders[$id] = $dataProvider;
} | [
"public",
"function",
"add",
"(",
"$",
"id",
",",
"DataProviderInterface",
"$",
"dataProvider",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to add the data provider '",
".",
"$",
... | Add a data provider to the collection.
@param string $id The data provider service id
@param DataProviderInterface $dataProvider The data provider
@throws Exception | [
"Add",
"a",
"data",
"provider",
"to",
"the",
"collection",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/DataProviderFactory.php#L41-L48 | train |
larriereguichet/AdminBundle | src/Factory/DataProviderFactory.php | DataProviderFactory.get | public function get(string $id): DataProviderInterface
{
if (!$this->has($id)) {
throw new Exception('No data provider with id "'.$id.'" was loaded');
}
return $this->dataProviders[$id];
} | php | public function get(string $id): DataProviderInterface
{
if (!$this->has($id)) {
throw new Exception('No data provider with id "'.$id.'" was loaded');
}
return $this->dataProviders[$id];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"id",
")",
":",
"DataProviderInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'No data provider with id \"'",
".",
"$",
"id",
"... | Return an configured data provider or try to create one for the given entity class.
@param string $id The id of an existing data provider service
registry
@return DataProviderInterface
@throws Exception | [
"Return",
"an",
"configured",
"data",
"provider",
"or",
"try",
"to",
"create",
"one",
"for",
"the",
"given",
"entity",
"class",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/DataProviderFactory.php#L60-L67 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/ExtraConfigurationSubscriber.php | ExtraConfigurationSubscriber.addDefaultActions | private function addDefaultActions(array &$configuration)
{
if (!key_exists('actions', $configuration) || !is_array($configuration['actions'])) {
$configuration['actions'] = [];
}
if (0 !== count($configuration['actions'])) {
return;
}
$configuration['actions'] = [
'create' => [],
'list' => [],
'edit' => [],
'delete' => [],
];
} | php | private function addDefaultActions(array &$configuration)
{
if (!key_exists('actions', $configuration) || !is_array($configuration['actions'])) {
$configuration['actions'] = [];
}
if (0 !== count($configuration['actions'])) {
return;
}
$configuration['actions'] = [
'create' => [],
'list' => [],
'edit' => [],
'delete' => [],
];
} | [
"private",
"function",
"addDefaultActions",
"(",
"array",
"&",
"$",
"configuration",
")",
"{",
"if",
"(",
"!",
"key_exists",
"(",
"'actions'",
",",
"$",
"configuration",
")",
"||",
"!",
"is_array",
"(",
"$",
"configuration",
"[",
"'actions'",
"]",
")",
")"... | Defines the default CRUD actions if no action was configured.
@param array $configuration | [
"Defines",
"the",
"default",
"CRUD",
"actions",
"if",
"no",
"action",
"was",
"configured",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/ExtraConfigurationSubscriber.php#L125-L140 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/ExtraConfigurationSubscriber.php | ExtraConfigurationSubscriber.addDefaultLeftMenu | private function addDefaultLeftMenu(array &$configuration)
{
if (!$this->applicationConfiguration->getParameter('enable_menus')) {
return;
}
$menus = $this->configurationFactory->createResourceMenuConfiguration();
// Add the resources menu for each action of the admin
foreach ($configuration['actions'] as $name => $action) {
if (null === $action) {
$action = [];
}
if (key_exists('menus', $action) && key_exists('left', $action)) {
continue;
}
$configuration['actions'][$name]['menus']['left'] = $menus;
}
} | php | private function addDefaultLeftMenu(array &$configuration)
{
if (!$this->applicationConfiguration->getParameter('enable_menus')) {
return;
}
$menus = $this->configurationFactory->createResourceMenuConfiguration();
// Add the resources menu for each action of the admin
foreach ($configuration['actions'] as $name => $action) {
if (null === $action) {
$action = [];
}
if (key_exists('menus', $action) && key_exists('left', $action)) {
continue;
}
$configuration['actions'][$name]['menus']['left'] = $menus;
}
} | [
"private",
"function",
"addDefaultLeftMenu",
"(",
"array",
"&",
"$",
"configuration",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"applicationConfiguration",
"->",
"getParameter",
"(",
"'enable_menus'",
")",
")",
"{",
"return",
";",
"}",
"$",
"menus",
"=",
... | Add the default left menu configuration. One item for each Admin.
@param array $configuration | [
"Add",
"the",
"default",
"left",
"menu",
"configuration",
".",
"One",
"item",
"for",
"each",
"Admin",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/ExtraConfigurationSubscriber.php#L147-L166 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/ExtraConfigurationSubscriber.php | ExtraConfigurationSubscriber.addDefaultRightMenu | private function addDefaultRightMenu(array &$configuration)
{
if (!$this->applicationConfiguration->getParameter('enable_menus')) {
return;
}
if (!key_exists('list', $configuration['actions'])) {
return;
}
if (
key_exists('menus', $configuration['actions']['list']) &&
is_array($configuration['actions']['list']['menus']) &&
key_exists('right', $configuration['actions']['list']['menus'])
) {
return;
}
$configuration['actions']['list']['menus']['right'] = [];
} | php | private function addDefaultRightMenu(array &$configuration)
{
if (!$this->applicationConfiguration->getParameter('enable_menus')) {
return;
}
if (!key_exists('list', $configuration['actions'])) {
return;
}
if (
key_exists('menus', $configuration['actions']['list']) &&
is_array($configuration['actions']['list']['menus']) &&
key_exists('right', $configuration['actions']['list']['menus'])
) {
return;
}
$configuration['actions']['list']['menus']['right'] = [];
} | [
"private",
"function",
"addDefaultRightMenu",
"(",
"array",
"&",
"$",
"configuration",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"applicationConfiguration",
"->",
"getParameter",
"(",
"'enable_menus'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
... | Add the default right menu.
@param array $configuration | [
"Add",
"the",
"default",
"right",
"menu",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/ExtraConfigurationSubscriber.php#L173-L192 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/ExtraConfigurationSubscriber.php | ExtraConfigurationSubscriber.addDefaultFilters | private function addDefaultFilters(array &$configuration)
{
// Add the filters only for the "list" action
if (!key_exists('list', $configuration['actions'])) {
return;
}
// If some filters are already configured, we do not add the default filters
if (key_exists('filter', $configuration['actions']['list'])) {
return;
}
// TODO add a default unified filter
$metadata = $this->findMetadata($configuration['entity']);
if (null === $metadata) {
return;
}
$filters = [];
foreach ($metadata->getFieldNames() as $fieldName) {
$type = $metadata->getTypeOfField($fieldName);
$operator = $this->getOperatorFromFieldType($type);
$filters[$fieldName] = [
'type' => $type,
'options' => [],
'comparator' => $operator,
];
}
$configuration['actions']['list']['filters'] = $filters;
} | php | private function addDefaultFilters(array &$configuration)
{
// Add the filters only for the "list" action
if (!key_exists('list', $configuration['actions'])) {
return;
}
// If some filters are already configured, we do not add the default filters
if (key_exists('filter', $configuration['actions']['list'])) {
return;
}
// TODO add a default unified filter
$metadata = $this->findMetadata($configuration['entity']);
if (null === $metadata) {
return;
}
$filters = [];
foreach ($metadata->getFieldNames() as $fieldName) {
$type = $metadata->getTypeOfField($fieldName);
$operator = $this->getOperatorFromFieldType($type);
$filters[$fieldName] = [
'type' => $type,
'options' => [],
'comparator' => $operator,
];
}
$configuration['actions']['list']['filters'] = $filters;
} | [
"private",
"function",
"addDefaultFilters",
"(",
"array",
"&",
"$",
"configuration",
")",
"{",
"// Add the filters only for the \"list\" action",
"if",
"(",
"!",
"key_exists",
"(",
"'list'",
",",
"$",
"configuration",
"[",
"'actions'",
"]",
")",
")",
"{",
"return"... | Add default filters for the list actions, guessed using the entity metadata.
@param array $configuration | [
"Add",
"default",
"filters",
"for",
"the",
"list",
"actions",
"guessed",
"using",
"the",
"entity",
"metadata",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/ExtraConfigurationSubscriber.php#L269-L299 | train |
larriereguichet/AdminBundle | src/Configuration/ApplicationConfiguration.php | ApplicationConfiguration.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
// enable or disable extra configuration listener
'enable_extra_configuration' => true,
'enable_security' => true,
'enable_menus' => true,
'enable_homepage' => true,
'translation' => false,
'translation_pattern' => false,
'title' => 'AdminBundle application',
'description' => '',
'locale' => 'en',
// Main base template as bundles are not loaded when reading the configuration, the kernel
// locateResources will always failed. So we must not check resource existence here.
'base_template' => '@LAGAdmin/base.html.twig',
'block_template' => '@LAGAdmin/Form/fields.html.twig',
'menu_template' => '@LAGAdmin/Menu/menu.html.twig',
'list_template' => '@LAGAdmin/CRUD/list.html.twig',
'edit_template' => '@LAGAdmin/CRUD/edit.html.twig',
'create_template' => '@LAGAdmin/CRUD/create.html.twig',
'delete_template' => '@LAGAdmin/CRUD/delete.html.twig',
'homepage_template' => '@LAGAdmin/Pages/home.html.twig',
'homepage_route' => 'lag.admin.homepage',
'routing_url_pattern' => '/{admin}/{action}',
'routing_name_pattern' => 'lag.admin.{admin}.{action}',
'bootstrap' => true,
'date_format' => 'Y/m/d',
'pager' => 'pagerfanta',
// string length before truncation (0 means no truncation)
'string_length' => 200,
'string_length_truncate' => '...',
'max_per_page' => 20,
'admin_class' => Admin::class,
'action_class' => Action::class,
'permissions' => 'ROLE_ADMIN',
'page_parameter' => 'page',
])
->setAllowedTypes('enable_extra_configuration', 'boolean')
->setAllowedTypes('enable_security', 'boolean')
->setAllowedTypes('enable_menus', 'boolean')
->setAllowedTypes('title', 'string')
->setAllowedTypes('description', 'string')
->setAllowedTypes('locale', 'string')
->setAllowedTypes('base_template', 'string')
->setAllowedTypes('block_template', 'string')
->setAllowedTypes('bootstrap', 'boolean')
->setAllowedTypes('date_format', 'string')
->setAllowedTypes('string_length', 'integer')
->setAllowedTypes('string_length_truncate', 'string')
->setAllowedTypes('max_per_page', 'integer')
->setAllowedTypes('admin_class', 'string')
->setAllowedTypes('routing_name_pattern', 'string')
->setAllowedTypes('routing_url_pattern', 'string')
->setAllowedTypes('page_parameter', 'string')
->setNormalizer('routing_name_pattern', function(Options $options, $value) {
if (false === strstr($value, '{admin}')) {
throw new InvalidOptionsException(
'Admin routing configuration pattern name should contains the {admin} placeholder'
);
}
if (false === strstr($value, '{action}')) {
throw new InvalidOptionsException(
'Admin routing configuration pattern name should contains the {action} placeholder'
);
}
return $value;
})
->setNormalizer('routing_url_pattern', function(Options $options, $value) {
if (false === strstr($value, '{admin}')) {
throw new InvalidOptionsException('Admin routing configuration url pattern should contains {admin} placeholder');
}
if (false === strstr($value, '{action}')) {
throw new InvalidOptionsException('Admin routing configuration url pattern should contains the {action} placeholder');
}
return $value;
})
;
// admin field type mapping
$this->setFieldsOptions($resolver);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
// enable or disable extra configuration listener
'enable_extra_configuration' => true,
'enable_security' => true,
'enable_menus' => true,
'enable_homepage' => true,
'translation' => false,
'translation_pattern' => false,
'title' => 'AdminBundle application',
'description' => '',
'locale' => 'en',
// Main base template as bundles are not loaded when reading the configuration, the kernel
// locateResources will always failed. So we must not check resource existence here.
'base_template' => '@LAGAdmin/base.html.twig',
'block_template' => '@LAGAdmin/Form/fields.html.twig',
'menu_template' => '@LAGAdmin/Menu/menu.html.twig',
'list_template' => '@LAGAdmin/CRUD/list.html.twig',
'edit_template' => '@LAGAdmin/CRUD/edit.html.twig',
'create_template' => '@LAGAdmin/CRUD/create.html.twig',
'delete_template' => '@LAGAdmin/CRUD/delete.html.twig',
'homepage_template' => '@LAGAdmin/Pages/home.html.twig',
'homepage_route' => 'lag.admin.homepage',
'routing_url_pattern' => '/{admin}/{action}',
'routing_name_pattern' => 'lag.admin.{admin}.{action}',
'bootstrap' => true,
'date_format' => 'Y/m/d',
'pager' => 'pagerfanta',
// string length before truncation (0 means no truncation)
'string_length' => 200,
'string_length_truncate' => '...',
'max_per_page' => 20,
'admin_class' => Admin::class,
'action_class' => Action::class,
'permissions' => 'ROLE_ADMIN',
'page_parameter' => 'page',
])
->setAllowedTypes('enable_extra_configuration', 'boolean')
->setAllowedTypes('enable_security', 'boolean')
->setAllowedTypes('enable_menus', 'boolean')
->setAllowedTypes('title', 'string')
->setAllowedTypes('description', 'string')
->setAllowedTypes('locale', 'string')
->setAllowedTypes('base_template', 'string')
->setAllowedTypes('block_template', 'string')
->setAllowedTypes('bootstrap', 'boolean')
->setAllowedTypes('date_format', 'string')
->setAllowedTypes('string_length', 'integer')
->setAllowedTypes('string_length_truncate', 'string')
->setAllowedTypes('max_per_page', 'integer')
->setAllowedTypes('admin_class', 'string')
->setAllowedTypes('routing_name_pattern', 'string')
->setAllowedTypes('routing_url_pattern', 'string')
->setAllowedTypes('page_parameter', 'string')
->setNormalizer('routing_name_pattern', function(Options $options, $value) {
if (false === strstr($value, '{admin}')) {
throw new InvalidOptionsException(
'Admin routing configuration pattern name should contains the {admin} placeholder'
);
}
if (false === strstr($value, '{action}')) {
throw new InvalidOptionsException(
'Admin routing configuration pattern name should contains the {action} placeholder'
);
}
return $value;
})
->setNormalizer('routing_url_pattern', function(Options $options, $value) {
if (false === strstr($value, '{admin}')) {
throw new InvalidOptionsException('Admin routing configuration url pattern should contains {admin} placeholder');
}
if (false === strstr($value, '{action}')) {
throw new InvalidOptionsException('Admin routing configuration url pattern should contains the {action} placeholder');
}
return $value;
})
;
// admin field type mapping
$this->setFieldsOptions($resolver);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"// enable or disable extra configuration listener",
"'enable_extra_configuration'",
"=>",
"true",
",",
"'enable_security'",
"=>",
... | Configure configuration allowed parameters.
@param OptionsResolver $resolver | [
"Configure",
"configuration",
"allowed",
"parameters",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ApplicationConfiguration.php#L33-L117 | train |
larriereguichet/AdminBundle | src/DependencyInjection/LAGAdminExtension.php | LAGAdminExtension.load | public function load(array $configs, ContainerBuilder $builder)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($builder, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$loader->load('services/factories.yaml');
$loader->load('services/fields.yaml');
$loader->load('services/resources.yaml');
$loader->load('services/subscribers.yaml');
$loader->load('services/twig.yaml');
if ('dev' === $builder->getParameter('kernel.environment')) {
$loader->load('services_dev.yaml');
}
$applicationConfig = [];
$adminsConfig = [];
$menusConfig = [];
$enableExtraConfig = true;
if (key_exists('application', $config)) {
if (key_exists('enable_extra_configuration', $config['application'])) {
$enableExtraConfig = $config['application']['enable_extra_configuration'];
}
$applicationConfig = $config['application'];
}
if (key_exists('admins', $config)) {
$adminsConfig = $config['admins'];
}
if (key_exists('menus', $config)) {
$menusConfig = $config['menus'];
foreach ($menusConfig as $name => $menu) {
if (null === $menu) {
$menusConfig[$name] = [];
}
}
}
$builder->setParameter('lag.admin.enable_extra_configuration', $enableExtraConfig);
$builder->setParameter('lag.admin.application_configuration', $applicationConfig);
$builder->setParameter('lag.admins', $adminsConfig);
$builder->setParameter('lag.menus', $menusConfig);
} | php | public function load(array $configs, ContainerBuilder $builder)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($builder, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yaml');
$loader->load('services/factories.yaml');
$loader->load('services/fields.yaml');
$loader->load('services/resources.yaml');
$loader->load('services/subscribers.yaml');
$loader->load('services/twig.yaml');
if ('dev' === $builder->getParameter('kernel.environment')) {
$loader->load('services_dev.yaml');
}
$applicationConfig = [];
$adminsConfig = [];
$menusConfig = [];
$enableExtraConfig = true;
if (key_exists('application', $config)) {
if (key_exists('enable_extra_configuration', $config['application'])) {
$enableExtraConfig = $config['application']['enable_extra_configuration'];
}
$applicationConfig = $config['application'];
}
if (key_exists('admins', $config)) {
$adminsConfig = $config['admins'];
}
if (key_exists('menus', $config)) {
$menusConfig = $config['menus'];
foreach ($menusConfig as $name => $menu) {
if (null === $menu) {
$menusConfig[$name] = [];
}
}
}
$builder->setParameter('lag.admin.enable_extra_configuration', $enableExtraConfig);
$builder->setParameter('lag.admin.application_configuration', $applicationConfig);
$builder->setParameter('lag.admins', $adminsConfig);
$builder->setParameter('lag.menus', $menusConfig);
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"builder",
")",
"{",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"processConfiguration",
"(",
"$",
"confi... | Load the configuration into the container.
@param array $configs
@param ContainerBuilder $builder | [
"Load",
"the",
"configuration",
"into",
"the",
"container",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/DependencyInjection/LAGAdminExtension.php#L21-L66 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.doPersistList | protected function doPersistList(ResourceListInterface $resources, $autoCommit, $type)
{
$hasError = false;
$hasFlushError = false;
foreach ($resources as $i => $resource) {
if (!$autoCommit && $hasError) {
$resource->setStatus(ResourceStatutes::CANCELED);
} elseif ($autoCommit && $hasFlushError && $hasError) {
DomainUtil::addResourceError($resource, $this->translator->trans('domain.database_previous_error', [], 'FxpResource'));
} else {
list($successStatus, $hasFlushError) = $this->doPersistResource($resource, $autoCommit, $type);
$hasError = $this->finalizeResourceStatus($resource, $successStatus, $hasError);
}
}
return $hasError;
} | php | protected function doPersistList(ResourceListInterface $resources, $autoCommit, $type)
{
$hasError = false;
$hasFlushError = false;
foreach ($resources as $i => $resource) {
if (!$autoCommit && $hasError) {
$resource->setStatus(ResourceStatutes::CANCELED);
} elseif ($autoCommit && $hasFlushError && $hasError) {
DomainUtil::addResourceError($resource, $this->translator->trans('domain.database_previous_error', [], 'FxpResource'));
} else {
list($successStatus, $hasFlushError) = $this->doPersistResource($resource, $autoCommit, $type);
$hasError = $this->finalizeResourceStatus($resource, $successStatus, $hasError);
}
}
return $hasError;
} | [
"protected",
"function",
"doPersistList",
"(",
"ResourceListInterface",
"$",
"resources",
",",
"$",
"autoCommit",
",",
"$",
"type",
")",
"{",
"$",
"hasError",
"=",
"false",
";",
"$",
"hasFlushError",
"=",
"false",
";",
"foreach",
"(",
"$",
"resources",
"as",... | Do persist the resources.
@param ResourceListInterface $resources The list of object resource instance
@param bool $autoCommit Commit transaction for each resource or all
(continue the action even if there is an error on a resource)
@param int $type The type of persist action
@return bool Check if there is an error in list | [
"Do",
"persist",
"the",
"resources",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L149-L166 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.doPersistResource | protected function doPersistResource(ResourceInterface $resource, $autoCommit, $type)
{
$object = $resource->getRealData();
$this->validateUndeleteResource($resource, $type);
$this->validateResource($resource, $type);
$successStatus = $this->getSuccessStatus($type, $object);
$hasFlushError = false;
if ($resource->isValid()) {
try {
$this->om->persist($object);
$hasFlushError = $this->doAutoCommitFlushTransaction($resource, $autoCommit);
} catch (\Exception $e) {
$hasFlushError = DomainUtil::injectErrorMessage($this->translator, $resource, $e, $this->debug);
}
}
return [$successStatus, $hasFlushError];
} | php | protected function doPersistResource(ResourceInterface $resource, $autoCommit, $type)
{
$object = $resource->getRealData();
$this->validateUndeleteResource($resource, $type);
$this->validateResource($resource, $type);
$successStatus = $this->getSuccessStatus($type, $object);
$hasFlushError = false;
if ($resource->isValid()) {
try {
$this->om->persist($object);
$hasFlushError = $this->doAutoCommitFlushTransaction($resource, $autoCommit);
} catch (\Exception $e) {
$hasFlushError = DomainUtil::injectErrorMessage($this->translator, $resource, $e, $this->debug);
}
}
return [$successStatus, $hasFlushError];
} | [
"protected",
"function",
"doPersistResource",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"autoCommit",
",",
"$",
"type",
")",
"{",
"$",
"object",
"=",
"$",
"resource",
"->",
"getRealData",
"(",
")",
";",
"$",
"this",
"->",
"validateUndeleteResource",... | Do persist a resource.
@param ResourceInterface $resource The resource
@param bool $autoCommit Commit transaction for each resource or all
(continue the action even if there is an error on a resource)
@param int $type The type of persist action
@return array The successStatus and hasFlushError value | [
"Do",
"persist",
"a",
"resource",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L178-L196 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.validateUndeleteResource | protected function validateUndeleteResource(ResourceInterface $resource, $type): void
{
if (static::TYPE_UNDELETE === $type) {
$object = $resource->getRealData();
if ($object instanceof SoftDeletableInterface) {
$object->setDeletedAt();
} else {
DomainUtil::addResourceError($resource, $this->translator->trans('domain.resource_type_not_undeleted', [], 'FxpResource'));
}
}
} | php | protected function validateUndeleteResource(ResourceInterface $resource, $type): void
{
if (static::TYPE_UNDELETE === $type) {
$object = $resource->getRealData();
if ($object instanceof SoftDeletableInterface) {
$object->setDeletedAt();
} else {
DomainUtil::addResourceError($resource, $this->translator->trans('domain.resource_type_not_undeleted', [], 'FxpResource'));
}
}
} | [
"protected",
"function",
"validateUndeleteResource",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"type",
")",
":",
"void",
"{",
"if",
"(",
"static",
"::",
"TYPE_UNDELETE",
"===",
"$",
"type",
")",
"{",
"$",
"object",
"=",
"$",
"resource",
"->",
"g... | Validate the resource only when type is undelete.
@param ResourceInterface $resource The resource
@param int $type The type of persist action | [
"Validate",
"the",
"resource",
"only",
"when",
"type",
"is",
"undelete",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L204-L215 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.doDeleteList | protected function doDeleteList(ResourceListInterface $resources, $autoCommit, $soft = true)
{
$hasError = false;
$hasFlushError = false;
foreach ($resources as $i => $resource) {
list($continue, $hasError) = $this->prepareDeleteResource($resource, $autoCommit, $hasError, $hasFlushError);
if (!$continue) {
$skipped = $this->doDeleteResource($resource, $soft);
$hasFlushError = $this->doAutoCommitFlushTransaction($resource, $autoCommit, $skipped);
$hasError = $this->finalizeResourceStatus($resource, ResourceStatutes::DELETED, $hasError);
}
}
return $hasError;
} | php | protected function doDeleteList(ResourceListInterface $resources, $autoCommit, $soft = true)
{
$hasError = false;
$hasFlushError = false;
foreach ($resources as $i => $resource) {
list($continue, $hasError) = $this->prepareDeleteResource($resource, $autoCommit, $hasError, $hasFlushError);
if (!$continue) {
$skipped = $this->doDeleteResource($resource, $soft);
$hasFlushError = $this->doAutoCommitFlushTransaction($resource, $autoCommit, $skipped);
$hasError = $this->finalizeResourceStatus($resource, ResourceStatutes::DELETED, $hasError);
}
}
return $hasError;
} | [
"protected",
"function",
"doDeleteList",
"(",
"ResourceListInterface",
"$",
"resources",
",",
"$",
"autoCommit",
",",
"$",
"soft",
"=",
"true",
")",
"{",
"$",
"hasError",
"=",
"false",
";",
"$",
"hasFlushError",
"=",
"false",
";",
"foreach",
"(",
"$",
"res... | Do delete the resources.
@param ResourceListInterface $resources The list of object resource instance
@param bool $autoCommit Commit transaction for each resource or all
(continue the action even if there is an error on a resource)
@param bool $soft The soft deletable
@return bool Check if there is an error in list | [
"Do",
"delete",
"the",
"resources",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L227-L243 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.prepareDeleteResource | protected function prepareDeleteResource(ResourceInterface $resource, $autoCommit, $hasError, $hasFlushError)
{
$continue = false;
if (!$autoCommit && $hasError) {
$resource->setStatus(ResourceStatutes::CANCELED);
$continue = true;
} elseif ($autoCommit && $hasFlushError && $hasError) {
DomainUtil::addResourceError($resource, $this->translator->trans('domain.database_previous_error', [], 'FxpResource'));
$continue = true;
} elseif (null !== $idError = $this->getErrorIdentifier($resource->getRealData(), static::TYPE_DELETE)) {
$hasError = true;
$resource->setStatus(ResourceStatutes::ERROR);
$resource->getErrors()->add(new ConstraintViolation($idError, $idError, [], $resource->getRealData(), null, null));
$continue = true;
}
return [$continue, $hasError];
} | php | protected function prepareDeleteResource(ResourceInterface $resource, $autoCommit, $hasError, $hasFlushError)
{
$continue = false;
if (!$autoCommit && $hasError) {
$resource->setStatus(ResourceStatutes::CANCELED);
$continue = true;
} elseif ($autoCommit && $hasFlushError && $hasError) {
DomainUtil::addResourceError($resource, $this->translator->trans('domain.database_previous_error', [], 'FxpResource'));
$continue = true;
} elseif (null !== $idError = $this->getErrorIdentifier($resource->getRealData(), static::TYPE_DELETE)) {
$hasError = true;
$resource->setStatus(ResourceStatutes::ERROR);
$resource->getErrors()->add(new ConstraintViolation($idError, $idError, [], $resource->getRealData(), null, null));
$continue = true;
}
return [$continue, $hasError];
} | [
"protected",
"function",
"prepareDeleteResource",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"autoCommit",
",",
"$",
"hasError",
",",
"$",
"hasFlushError",
")",
"{",
"$",
"continue",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"autoCommit",
"&&",
"$",
... | Prepare the deletion of resource.
@param ResourceInterface $resource The resource
@param bool $autoCommit Commit transaction for each resource or all
(continue the action even if there is an error on a resource)
@param bool $hasError Check if there is an previous error
@param bool $hasFlushError Check if there is an previous flush error
@return array The check if the delete action must be continued and check if there is an error | [
"Prepare",
"the",
"deletion",
"of",
"resource",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L256-L274 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.doDeleteResource | protected function doDeleteResource(ResourceInterface $resource, $soft)
{
$skipped = false;
$object = $resource->getRealData();
if ($object instanceof SoftDeletableInterface) {
if ($soft) {
if ($object->isDeleted()) {
$skipped = true;
} else {
$this->doDeleteResourceAction($resource);
}
} else {
if (!$object->isDeleted()) {
$object->setDeletedAt(new \DateTime());
}
$this->doDeleteResourceAction($resource);
}
} else {
$this->doDeleteResourceAction($resource);
}
return $skipped;
} | php | protected function doDeleteResource(ResourceInterface $resource, $soft)
{
$skipped = false;
$object = $resource->getRealData();
if ($object instanceof SoftDeletableInterface) {
if ($soft) {
if ($object->isDeleted()) {
$skipped = true;
} else {
$this->doDeleteResourceAction($resource);
}
} else {
if (!$object->isDeleted()) {
$object->setDeletedAt(new \DateTime());
}
$this->doDeleteResourceAction($resource);
}
} else {
$this->doDeleteResourceAction($resource);
}
return $skipped;
} | [
"protected",
"function",
"doDeleteResource",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"soft",
")",
"{",
"$",
"skipped",
"=",
"false",
";",
"$",
"object",
"=",
"$",
"resource",
"->",
"getRealData",
"(",
")",
";",
"if",
"(",
"$",
"object",
"ins... | Do delete a resource.
@param ResourceInterface $resource The resource
@param bool $soft The soft deletable
@throws
@return bool Check if the resource is skipped or deleted | [
"Do",
"delete",
"a",
"resource",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L286-L309 | train |
fxpio/fxp-resource | Domain/Domain.php | Domain.doDeleteResourceAction | protected function doDeleteResourceAction(ResourceInterface $resource): void
{
try {
$this->om->remove($resource->getRealData());
} catch (\Exception $e) {
DomainUtil::injectErrorMessage($this->translator, $resource, $e, $this->debug);
}
} | php | protected function doDeleteResourceAction(ResourceInterface $resource): void
{
try {
$this->om->remove($resource->getRealData());
} catch (\Exception $e) {
DomainUtil::injectErrorMessage($this->translator, $resource, $e, $this->debug);
}
} | [
"protected",
"function",
"doDeleteResourceAction",
"(",
"ResourceInterface",
"$",
"resource",
")",
":",
"void",
"{",
"try",
"{",
"$",
"this",
"->",
"om",
"->",
"remove",
"(",
"$",
"resource",
"->",
"getRealData",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\... | Real delete a entity in object manager.
@param ResourceInterface $resource The resource | [
"Real",
"delete",
"a",
"entity",
"in",
"object",
"manager",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/Domain.php#L316-L323 | train |
hnhdigital-os/laravel-frontend-assets | src/GoogleMaps.php | GoogleMaps.loadExtensions | private function loadExtensions($extensions)
{
$extensions = Arr::wrap($extensions);
foreach ($extensions as $extension) {
$extension = 'ext'.$extension;
if (method_exists($this, $extension)) {
$this->$extension();
}
}
} | php | private function loadExtensions($extensions)
{
$extensions = Arr::wrap($extensions);
foreach ($extensions as $extension) {
$extension = 'ext'.$extension;
if (method_exists($this, $extension)) {
$this->$extension();
}
}
} | [
"private",
"function",
"loadExtensions",
"(",
"$",
"extensions",
")",
"{",
"$",
"extensions",
"=",
"Arr",
"::",
"wrap",
"(",
"$",
"extensions",
")",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"=",
"'ext'",... | Load requested extensions.
@param string|array $extensions
@return void | [
"Load",
"requested",
"extensions",
"."
] | 242f605bf0c052f4d82421a8b95f227d46162e34 | https://github.com/hnhdigital-os/laravel-frontend-assets/blob/242f605bf0c052f4d82421a8b95f227d46162e34/src/GoogleMaps.php#L28-L39 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/AdminSubscriber.php | AdminSubscriber.handleRequest | public function handleRequest(AdminEvent $event)
{
$actionName = $event->getRequest()->get('_action');
if (null === $actionName) {
throw new Exception('The _action was not found in the request');
}
$admin = $event->getAdmin();
$action = $this->actionFactory->create($actionName, $admin->getName(), $admin->getConfiguration());
$event->setAction($action);
} | php | public function handleRequest(AdminEvent $event)
{
$actionName = $event->getRequest()->get('_action');
if (null === $actionName) {
throw new Exception('The _action was not found in the request');
}
$admin = $event->getAdmin();
$action = $this->actionFactory->create($actionName, $admin->getName(), $admin->getConfiguration());
$event->setAction($action);
} | [
"public",
"function",
"handleRequest",
"(",
"AdminEvent",
"$",
"event",
")",
"{",
"$",
"actionName",
"=",
"$",
"event",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"'_action'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"actionName",
")",
"{",
"throw... | Define the current action according to the routing configuration.
@param AdminEvent $event
@throws Exception | [
"Define",
"the",
"current",
"action",
"according",
"to",
"the",
"routing",
"configuration",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/AdminSubscriber.php#L116-L127 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/AdminSubscriber.php | AdminSubscriber.createView | public function createView(ViewEvent $event)
{
$admin = $event->getAdmin();
$action = $admin->getAction();
$menuEvent = new MenuEvent($admin->getAction()->getConfiguration()->getParameter('menus'));
$this->eventDispatcher->dispatch(Events::MENU, $menuEvent);
$formName = '';
// The form name is different according to the current action
if ('edit' === $action->getName()) {
$formName = 'entity';
} elseif ('create' === $action->getName()) {
$formName = 'entity';
} elseif ('delete' === $action->getName()) {
$formName = 'delete';
}
if ($this->shouldRedirect($admin, $action, $formName, $event->getRequest(), $admin->getConfiguration())) {
$url = $this->getRedirectionUrl(
$admin,
$action,
$admin->getConfiguration(),
$event->getRequest()
);
$view = new RedirectView(
$action->getName(),
$admin->getName(),
$action->getConfiguration(),
$admin->getConfiguration()
);
$view->setUrl($url);
} else {
$view = $this->viewFactory->create(
$event->getRequest(),
$action->getName(),
$admin->getName(),
$admin->getConfiguration(),
$action->getConfiguration(),
$admin->getEntities(),
$admin->getForms()
);
}
$event->setView($view);
} | php | public function createView(ViewEvent $event)
{
$admin = $event->getAdmin();
$action = $admin->getAction();
$menuEvent = new MenuEvent($admin->getAction()->getConfiguration()->getParameter('menus'));
$this->eventDispatcher->dispatch(Events::MENU, $menuEvent);
$formName = '';
// The form name is different according to the current action
if ('edit' === $action->getName()) {
$formName = 'entity';
} elseif ('create' === $action->getName()) {
$formName = 'entity';
} elseif ('delete' === $action->getName()) {
$formName = 'delete';
}
if ($this->shouldRedirect($admin, $action, $formName, $event->getRequest(), $admin->getConfiguration())) {
$url = $this->getRedirectionUrl(
$admin,
$action,
$admin->getConfiguration(),
$event->getRequest()
);
$view = new RedirectView(
$action->getName(),
$admin->getName(),
$action->getConfiguration(),
$admin->getConfiguration()
);
$view->setUrl($url);
} else {
$view = $this->viewFactory->create(
$event->getRequest(),
$action->getName(),
$admin->getName(),
$admin->getConfiguration(),
$action->getConfiguration(),
$admin->getEntities(),
$admin->getForms()
);
}
$event->setView($view);
} | [
"public",
"function",
"createView",
"(",
"ViewEvent",
"$",
"event",
")",
"{",
"$",
"admin",
"=",
"$",
"event",
"->",
"getAdmin",
"(",
")",
";",
"$",
"action",
"=",
"$",
"admin",
"->",
"getAction",
"(",
")",
";",
"$",
"menuEvent",
"=",
"new",
"MenuEve... | Create a view using the view factory.
@param ViewEvent $event | [
"Create",
"a",
"view",
"using",
"the",
"view",
"factory",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/AdminSubscriber.php#L134-L178 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/AdminSubscriber.php | AdminSubscriber.loadEntities | public function loadEntities(EntityEvent $event)
{
$admin = $event->getAdmin();
$configuration = $admin->getConfiguration();
$actionConfiguration = $admin->getAction()->getConfiguration();
$dataProvider = $this->dataProviderFactory->get($configuration->getParameter('data_provider'));
$strategy = $actionConfiguration->getParameter('load_strategy');
$class = $configuration->getParameter('entity');
if (LAGAdminBundle::LOAD_STRATEGY_NONE === $strategy) {
return;
} elseif (LAGAdminBundle::LOAD_STRATEGY_MULTIPLE === $strategy) {
$entities = $dataProvider->getCollection($admin, $event->getFilters());
$event->setEntities($entities);
} elseif (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $strategy) {
$requirements = $actionConfiguration->getParameter('route_requirements');
$identifier = null;
foreach ($requirements as $name => $requirement) {
if (null !== $event->getRequest()->get($name)) {
$identifier = $event->getRequest()->get($name);
break;
}
}
if (null === $identifier) {
throw new Exception('Unable to find a identifier for the class "'.$class.'"');
}
$entity = $dataProvider->get($admin, $identifier);
$event->setEntities(new ArrayCollection([
$entity,
]));
}
} | php | public function loadEntities(EntityEvent $event)
{
$admin = $event->getAdmin();
$configuration = $admin->getConfiguration();
$actionConfiguration = $admin->getAction()->getConfiguration();
$dataProvider = $this->dataProviderFactory->get($configuration->getParameter('data_provider'));
$strategy = $actionConfiguration->getParameter('load_strategy');
$class = $configuration->getParameter('entity');
if (LAGAdminBundle::LOAD_STRATEGY_NONE === $strategy) {
return;
} elseif (LAGAdminBundle::LOAD_STRATEGY_MULTIPLE === $strategy) {
$entities = $dataProvider->getCollection($admin, $event->getFilters());
$event->setEntities($entities);
} elseif (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $strategy) {
$requirements = $actionConfiguration->getParameter('route_requirements');
$identifier = null;
foreach ($requirements as $name => $requirement) {
if (null !== $event->getRequest()->get($name)) {
$identifier = $event->getRequest()->get($name);
break;
}
}
if (null === $identifier) {
throw new Exception('Unable to find a identifier for the class "'.$class.'"');
}
$entity = $dataProvider->get($admin, $identifier);
$event->setEntities(new ArrayCollection([
$entity,
]));
}
} | [
"public",
"function",
"loadEntities",
"(",
"EntityEvent",
"$",
"event",
")",
"{",
"$",
"admin",
"=",
"$",
"event",
"->",
"getAdmin",
"(",
")",
";",
"$",
"configuration",
"=",
"$",
"admin",
"->",
"getConfiguration",
"(",
")",
";",
"$",
"actionConfiguration"... | Load entities into the event data to pass them to the Admin.
@param EntityEvent $event
@throws Exception | [
"Load",
"entities",
"into",
"the",
"event",
"data",
"to",
"pass",
"them",
"to",
"the",
"Admin",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/AdminSubscriber.php#L187-L222 | train |
larriereguichet/AdminBundle | src/Event/Subscriber/AdminSubscriber.php | AdminSubscriber.getRedirectionUrl | private function getRedirectionUrl(
AdminInterface $admin,
ActionInterface $action,
AdminConfiguration $configuration,
Request $request
): string {
if ('edit' === $action->getName()) {
$routeName = RoutingLoader::generateRouteName(
$admin->getName(),
'list',
$configuration->get('routing_name_pattern')
);
$url = $this->router->generate($routeName);
return $url;
}
// When the create form is submitted, the user should be redirected to the edit action after saving the form
// data
if ('create' === $action->getName()) {
$targetAction = 'list';
$routeParameters = [];
if (!$request->get('submit_and_redirect')) {
$targetAction = 'edit';
$routeParameters = [
'id' => $admin->getEntities()->first()->getId(),
];
}
$routeName = RoutingLoader::generateRouteName(
$admin->getName(),
$targetAction,
$configuration->get('routing_name_pattern')
);
$url = $this->router->generate($routeName, $routeParameters);
return $url;
}
if ('delete' === $action->getName()) {
$routeName = RoutingLoader::generateRouteName(
$admin->getName(),
'list',
$configuration->get('routing_name_pattern')
);
$url = $this->router->generate($routeName);
return $url;
}
throw new Exception('Unable to generate an redirection url for the current action');
} | php | private function getRedirectionUrl(
AdminInterface $admin,
ActionInterface $action,
AdminConfiguration $configuration,
Request $request
): string {
if ('edit' === $action->getName()) {
$routeName = RoutingLoader::generateRouteName(
$admin->getName(),
'list',
$configuration->get('routing_name_pattern')
);
$url = $this->router->generate($routeName);
return $url;
}
// When the create form is submitted, the user should be redirected to the edit action after saving the form
// data
if ('create' === $action->getName()) {
$targetAction = 'list';
$routeParameters = [];
if (!$request->get('submit_and_redirect')) {
$targetAction = 'edit';
$routeParameters = [
'id' => $admin->getEntities()->first()->getId(),
];
}
$routeName = RoutingLoader::generateRouteName(
$admin->getName(),
$targetAction,
$configuration->get('routing_name_pattern')
);
$url = $this->router->generate($routeName, $routeParameters);
return $url;
}
if ('delete' === $action->getName()) {
$routeName = RoutingLoader::generateRouteName(
$admin->getName(),
'list',
$configuration->get('routing_name_pattern')
);
$url = $this->router->generate($routeName);
return $url;
}
throw new Exception('Unable to generate an redirection url for the current action');
} | [
"private",
"function",
"getRedirectionUrl",
"(",
"AdminInterface",
"$",
"admin",
",",
"ActionInterface",
"$",
"action",
",",
"AdminConfiguration",
"$",
"configuration",
",",
"Request",
"$",
"request",
")",
":",
"string",
"{",
"if",
"(",
"'edit'",
"===",
"$",
"... | Return the url where the user should be redirected to. An exception will be thrown if no url can be generated.
@param AdminInterface $admin
@param ActionInterface $action
@param AdminConfiguration $configuration
@param Request $request
@return string
@throws Exception | [
"Return",
"the",
"url",
"where",
"the",
"user",
"should",
"be",
"redirected",
"to",
".",
"An",
"exception",
"will",
"be",
"thrown",
"if",
"no",
"url",
"can",
"be",
"generated",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/AdminSubscriber.php#L335-L386 | train |
larriereguichet/AdminBundle | src/Bridge/Doctrine/ORM/Helper/MetadataTrait.php | MetadataTrait.findMetadata | protected function findMetadata($class)
{
$metadata = null;
try {
// We could not use the hasMetadataFor() method as it is not working if the entity is not loaded. But
// the getMetadataFor() method could throw an exception if the class is not found
$metadata = $this->entityManager->getMetadataFactory()->getMetadataFor($class);
} catch (Exception $exception) {
// If an exception is raised, nothing to do. Extra data from metadata will be not used.
}
return $metadata;
} | php | protected function findMetadata($class)
{
$metadata = null;
try {
// We could not use the hasMetadataFor() method as it is not working if the entity is not loaded. But
// the getMetadataFor() method could throw an exception if the class is not found
$metadata = $this->entityManager->getMetadataFactory()->getMetadataFor($class);
} catch (Exception $exception) {
// If an exception is raised, nothing to do. Extra data from metadata will be not used.
}
return $metadata;
} | [
"protected",
"function",
"findMetadata",
"(",
"$",
"class",
")",
"{",
"$",
"metadata",
"=",
"null",
";",
"try",
"{",
"// We could not use the hasMetadataFor() method as it is not working if the entity is not loaded. But",
"// the getMetadataFor() method could throw an exception if th... | Return the Doctrine metadata of the given class.
@param $class
@return ClassMetadata|null | [
"Return",
"the",
"Doctrine",
"metadata",
"of",
"the",
"given",
"class",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Doctrine/ORM/Helper/MetadataTrait.php#L26-L39 | train |
larriereguichet/AdminBundle | src/Field/Helper/FieldConfigurationHelper.php | FieldConfigurationHelper.getActionField | private function getActionField(array $fields): ?string
{
$mapping = [
'title',
'name',
'id',
];
foreach ($mapping as $name) {
if (in_array($name, $fields)) {
return $name;
}
}
return null;
} | php | private function getActionField(array $fields): ?string
{
$mapping = [
'title',
'name',
'id',
];
foreach ($mapping as $name) {
if (in_array($name, $fields)) {
return $name;
}
}
return null;
} | [
"private",
"function",
"getActionField",
"(",
"array",
"$",
"fields",
")",
":",
"?",
"string",
"{",
"$",
"mapping",
"=",
"[",
"'title'",
",",
"'name'",
",",
"'id'",
",",
"]",
";",
"foreach",
"(",
"$",
"mapping",
"as",
"$",
"name",
")",
"{",
"if",
"... | Return the default action field if found.
@param array $fields
@return string|null | [
"Return",
"the",
"default",
"action",
"field",
"if",
"found",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Field/Helper/FieldConfigurationHelper.php#L260-L275 | train |
larriereguichet/AdminBundle | src/Utils/FormUtils.php | FormUtils.convertShortFormType | public static function convertShortFormType(?string $shortType): ?string
{
$mapping = [
'choice' => ChoiceType::class,
'string' => TextType::class,
'entity' => EntityType::class,
'date' => DateType::class,
'datetime' => DateType::class,
'text' => TextareaType::class,
'number' => NumberType::class,
'float' => NumberType::class,
'integer' => IntegerType::class,
'smallint' => IntegerType::class,
'boolean' => CheckboxType::class,
'bigint' => NumberType::class,
'decimal' => NumberType::class,
'guid' => TextType::class,
'array' => TextareaType::class,
'simple_array' => TextareaType::class,
'json_array' => TextareaType::class,
];
$type = $shortType;
if (key_exists($shortType, $mapping)) {
$type = $mapping[$shortType];
}
return $type;
} | php | public static function convertShortFormType(?string $shortType): ?string
{
$mapping = [
'choice' => ChoiceType::class,
'string' => TextType::class,
'entity' => EntityType::class,
'date' => DateType::class,
'datetime' => DateType::class,
'text' => TextareaType::class,
'number' => NumberType::class,
'float' => NumberType::class,
'integer' => IntegerType::class,
'smallint' => IntegerType::class,
'boolean' => CheckboxType::class,
'bigint' => NumberType::class,
'decimal' => NumberType::class,
'guid' => TextType::class,
'array' => TextareaType::class,
'simple_array' => TextareaType::class,
'json_array' => TextareaType::class,
];
$type = $shortType;
if (key_exists($shortType, $mapping)) {
$type = $mapping[$shortType];
}
return $type;
} | [
"public",
"static",
"function",
"convertShortFormType",
"(",
"?",
"string",
"$",
"shortType",
")",
":",
"?",
"string",
"{",
"$",
"mapping",
"=",
"[",
"'choice'",
"=>",
"ChoiceType",
"::",
"class",
",",
"'string'",
"=>",
"TextType",
"::",
"class",
",",
"'en... | Convert a shortcut type into its class type.
@param string|null $shortType
@return string|null | [
"Convert",
"a",
"shortcut",
"type",
"into",
"its",
"class",
"type",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Utils/FormUtils.php#L23-L51 | train |
larriereguichet/AdminBundle | src/Bridge/Twig/Extension/MenuExtension.php | MenuExtension.getMenu | public function getMenu(string $name, ViewInterface $view = null)
{
$menu = $this->menuFactory->getMenu($name);
return $this->environment->render($menu->get('template'), [
'menu' => $menu,
'admin' => $view,
]);
} | php | public function getMenu(string $name, ViewInterface $view = null)
{
$menu = $this->menuFactory->getMenu($name);
return $this->environment->render($menu->get('template'), [
'menu' => $menu,
'admin' => $view,
]);
} | [
"public",
"function",
"getMenu",
"(",
"string",
"$",
"name",
",",
"ViewInterface",
"$",
"view",
"=",
"null",
")",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"menuFactory",
"->",
"getMenu",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"envi... | Render a menu according to given name.
@param string $name
@param ViewInterface|null $view
@return string | [
"Render",
"a",
"menu",
"according",
"to",
"given",
"name",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Twig/Extension/MenuExtension.php#L45-L53 | train |
yawik/cv | src/Repository/Cv.php | Cv.findDraft | public function findDraft($user)
{
if ($user instanceof UserInterface) {
$user = $user->getId();
}
return $this->findOneDraftBy(['user' => $user]);
} | php | public function findDraft($user)
{
if ($user instanceof UserInterface) {
$user = $user->getId();
}
return $this->findOneDraftBy(['user' => $user]);
} | [
"public",
"function",
"findDraft",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"user",
"instanceof",
"UserInterface",
")",
"{",
"$",
"user",
"=",
"$",
"user",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"findOneDraftBy",
"(",
"[",... | Look for an drafted Document of a given user
@param $user
@return CvEntity|null | [
"Look",
"for",
"an",
"drafted",
"Document",
"of",
"a",
"given",
"user"
] | a3c57c060d3f1c353c3e8ef3542b77147d4ec012 | https://github.com/yawik/cv/blob/a3c57c060d3f1c353c3e8ef3542b77147d4ec012/src/Repository/Cv.php#L28-L35 | train |
systemson/common | src/Validator/Validator.php | Validator.isString | protected function isString(...$args)
{
foreach ($args as $arg) {
if (!is_string($arg) || $arg === '') {
return false;
}
}
return true;
} | php | protected function isString(...$args)
{
foreach ($args as $arg) {
if (!is_string($arg) || $arg === '') {
return false;
}
}
return true;
} | [
"protected",
"function",
"isString",
"(",
"...",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"arg",
")",
"||",
"$",
"arg",
"===",
"''",
")",
"{",
"return",
"false",
";",
... | Checks if the specified argument is a valid string.
@param string $arg The argument to validate.
@return bool True if the specified argument is valid. False if it does not. | [
"Checks",
"if",
"the",
"specified",
"argument",
"is",
"a",
"valid",
"string",
"."
] | 00333341bbdba6cd1e4cdb7561f7e17bc756935e | https://github.com/systemson/common/blob/00333341bbdba6cd1e4cdb7561f7e17bc756935e/src/Validator/Validator.php#L21-L30 | train |
systemson/common | src/Validator/Validator.php | Validator.isIterable | protected function isIterable(...$args)
{
foreach ($args as $arg) {
if (!is_array($arg) && !$arg instanceof \IteratorAggregate) {
return false;
}
}
return true;
} | php | protected function isIterable(...$args)
{
foreach ($args as $arg) {
if (!is_array($arg) && !$arg instanceof \IteratorAggregate) {
return false;
}
}
return true;
} | [
"protected",
"function",
"isIterable",
"(",
"...",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arg",
")",
"&&",
"!",
"$",
"arg",
"instanceof",
"\\",
"IteratorAggregate",
")",
... | Checks if the specified argument is a valid iterable.
@todo After updating to 7.1 validate with is_iterable().
@param array|object $arg The argument to validate.
@return bool True if the specified argument is valid. False if it does not. | [
"Checks",
"if",
"the",
"specified",
"argument",
"is",
"a",
"valid",
"iterable",
"."
] | 00333341bbdba6cd1e4cdb7561f7e17bc756935e | https://github.com/systemson/common/blob/00333341bbdba6cd1e4cdb7561f7e17bc756935e/src/Validator/Validator.php#L59-L68 | train |
systemson/common | src/Validator/Validator.php | Validator.isCallable | protected function isCallable($arg, $method = null)
{
if (is_callable($arg) || is_callable([$arg, $method]) || $this->isClass($arg)) {
return true;
}
return false;
} | php | protected function isCallable($arg, $method = null)
{
if (is_callable($arg) || is_callable([$arg, $method]) || $this->isClass($arg)) {
return true;
}
return false;
} | [
"protected",
"function",
"isCallable",
"(",
"$",
"arg",
",",
"$",
"method",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"arg",
")",
"||",
"is_callable",
"(",
"[",
"$",
"arg",
",",
"$",
"method",
"]",
")",
"||",
"$",
"this",
"->",
"... | Checks if the specified argument is a valid callable.
@param mixed $arg The argument to validate.
@return bool True if the specified argument is valid. False if it does not. | [
"Checks",
"if",
"the",
"specified",
"argument",
"is",
"a",
"valid",
"callable",
"."
] | 00333341bbdba6cd1e4cdb7561f7e17bc756935e | https://github.com/systemson/common/blob/00333341bbdba6cd1e4cdb7561f7e17bc756935e/src/Validator/Validator.php#L77-L84 | train |
systemson/common | src/Validator/Validator.php | Validator.isClass | protected function isClass(...$args)
{
foreach ($args as $arg) {
if (!$this->isString($arg) || !class_exists($arg)) {
return false;
}
}
return true;
} | php | protected function isClass(...$args)
{
foreach ($args as $arg) {
if (!$this->isString($arg) || !class_exists($arg)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"isClass",
"(",
"...",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isString",
"(",
"$",
"arg",
")",
"||",
"!",
"class_exists",
"(",
"$",
"arg",
")",
... | Checks if the specified argument is a valid class.
@param mixed $arg The argument to validate.
@return bool True if the specified argument is valid. False if it does not. | [
"Checks",
"if",
"the",
"specified",
"argument",
"is",
"a",
"valid",
"class",
"."
] | 00333341bbdba6cd1e4cdb7561f7e17bc756935e | https://github.com/systemson/common/blob/00333341bbdba6cd1e4cdb7561f7e17bc756935e/src/Validator/Validator.php#L93-L102 | train |
ajcastro/fk-adder | src/FkConfig.php | FkConfig.buildFkConfig | public static function buildFkConfig()
{
$config = require Config::get('fk_adder.fk_datatypes_path');
return collect($config)->map(function ($value, $fk) {
list($datatype, $referenceTable) = (explode(',', $value.','));
return new Fluent([
'datatype' => trim($datatype),
'referenceTable' => trim($referenceTable ?: BaseFk::guessReferenceTable($fk)),
]);
});
} | php | public static function buildFkConfig()
{
$config = require Config::get('fk_adder.fk_datatypes_path');
return collect($config)->map(function ($value, $fk) {
list($datatype, $referenceTable) = (explode(',', $value.','));
return new Fluent([
'datatype' => trim($datatype),
'referenceTable' => trim($referenceTable ?: BaseFk::guessReferenceTable($fk)),
]);
});
} | [
"public",
"static",
"function",
"buildFkConfig",
"(",
")",
"{",
"$",
"config",
"=",
"require",
"Config",
"::",
"get",
"(",
"'fk_adder.fk_datatypes_path'",
")",
";",
"return",
"collect",
"(",
"$",
"config",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"valu... | Build fk config array.
@return collect | [
"Build",
"fk",
"config",
"array",
"."
] | a79200d8333e1bf897c9069c3a1b575af868b188 | https://github.com/ajcastro/fk-adder/blob/a79200d8333e1bf897c9069c3a1b575af868b188/src/FkConfig.php#L22-L34 | train |
fxpio/fxp-resource | ResourceUtil.php | ResourceUtil.convertObjectsToResourceList | public static function convertObjectsToResourceList(array $objects, $requireClass, $allowForm = true)
{
$list = new ResourceList();
foreach ($objects as $i => $object) {
static::validateObjectResource($object, $requireClass, $i, $allowForm);
$list->add(new ResourceItem((object) $object));
}
return $list;
} | php | public static function convertObjectsToResourceList(array $objects, $requireClass, $allowForm = true)
{
$list = new ResourceList();
foreach ($objects as $i => $object) {
static::validateObjectResource($object, $requireClass, $i, $allowForm);
$list->add(new ResourceItem((object) $object));
}
return $list;
} | [
"public",
"static",
"function",
"convertObjectsToResourceList",
"(",
"array",
"$",
"objects",
",",
"$",
"requireClass",
",",
"$",
"allowForm",
"=",
"true",
")",
"{",
"$",
"list",
"=",
"new",
"ResourceList",
"(",
")",
";",
"foreach",
"(",
"$",
"objects",
"a... | Convert the object data of resource to resource list.
@param FormInterface[]|object[] $objects The resource object instance or form of object instance
@param string $requireClass The require class name
@param bool $allowForm Check if the form is allowed
@throws InvalidResourceException When the instance object in the list is not an instance of the required class
@return ResourceList | [
"Convert",
"the",
"object",
"data",
"of",
"resource",
"to",
"resource",
"list",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/ResourceUtil.php#L36-L46 | train |
fxpio/fxp-resource | ResourceUtil.php | ResourceUtil.validateObjectResource | public static function validateObjectResource($object, $requireClass, $i, $allowForm = true): void
{
if ($allowForm && $object instanceof FormInterface) {
$object = $object->getData();
}
if (!\is_object($object) || !$object instanceof $requireClass) {
throw new UnexpectedTypeException($object, $requireClass, $i);
}
} | php | public static function validateObjectResource($object, $requireClass, $i, $allowForm = true): void
{
if ($allowForm && $object instanceof FormInterface) {
$object = $object->getData();
}
if (!\is_object($object) || !$object instanceof $requireClass) {
throw new UnexpectedTypeException($object, $requireClass, $i);
}
} | [
"public",
"static",
"function",
"validateObjectResource",
"(",
"$",
"object",
",",
"$",
"requireClass",
",",
"$",
"i",
",",
"$",
"allowForm",
"=",
"true",
")",
":",
"void",
"{",
"if",
"(",
"$",
"allowForm",
"&&",
"$",
"object",
"instanceof",
"FormInterface... | Validate the resource object.
@param FormInterface|mixed $object The resource object or form of resource object
@param string $requireClass The required class
@param int $i The position of the object in the list
@param bool $allowForm Check if the form is allowed
@throws UnexpectedTypeException When the object parameter is not an object or a form instance
@throws InvalidResourceException When the object in form is not an object
@throws InvalidResourceException When the object instance is not an instance of the required class | [
"Validate",
"the",
"resource",
"object",
"."
] | cb786bdc04c67d242591fbde6d0723f7d6834f35 | https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/ResourceUtil.php#L60-L69 | train |
larriereguichet/AdminBundle | src/Factory/AdminFactory.php | AdminFactory.supports | public function supports(Request $request)
{
$routeParameters = $request->get('_route_params');
if (!is_array($routeParameters)) {
return false;
}
if (!key_exists(LAGAdminBundle::REQUEST_PARAMETER_ADMIN, $routeParameters) ||
!key_exists(LAGAdminBundle::REQUEST_PARAMETER_ACTION, $routeParameters)
) {
return false;
}
if (!$this->resourceCollection->has($routeParameters[LAGAdminBundle::REQUEST_PARAMETER_ADMIN])) {
return false;
}
return true;
} | php | public function supports(Request $request)
{
$routeParameters = $request->get('_route_params');
if (!is_array($routeParameters)) {
return false;
}
if (!key_exists(LAGAdminBundle::REQUEST_PARAMETER_ADMIN, $routeParameters) ||
!key_exists(LAGAdminBundle::REQUEST_PARAMETER_ACTION, $routeParameters)
) {
return false;
}
if (!$this->resourceCollection->has($routeParameters[LAGAdminBundle::REQUEST_PARAMETER_ADMIN])) {
return false;
}
return true;
} | [
"public",
"function",
"supports",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"routeParameters",
"=",
"$",
"request",
"->",
"get",
"(",
"'_route_params'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"routeParameters",
")",
")",
"{",
"return",
"fal... | Return true if the current Request is supported. Supported means that the Request has the required valid
parameters to get an admin from the registry.
@param Request $request
@return bool | [
"Return",
"true",
"if",
"the",
"current",
"Request",
"is",
"supported",
".",
"Supported",
"means",
"that",
"the",
"Request",
"has",
"the",
"required",
"valid",
"parameters",
"to",
"get",
"an",
"admin",
"from",
"the",
"registry",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/AdminFactory.php#L95-L114 | train |
larriereguichet/AdminBundle | src/Bridge/Twig/Extension/AdminExtension.php | AdminExtension.getMenuAction | public function getMenuAction(MenuItemConfiguration $configuration, ViewInterface $view = null): string
{
if ($configuration->getParameter('url')) {
return $configuration->getParameter('url');
}
$routeName = $configuration->getParameter('route');
if ($configuration->getParameter('admin')) {
$routeName = RoutingLoader::generateRouteName(
$configuration->getParameter('admin'),
$configuration->getParameter('action'),
$this
->applicationConfigurationStorage
->getConfiguration()
->getParameter('routing_name_pattern')
);
}
// Map the potential parameters to the entity
$routeParameters = [];
$configuredParameters = $configuration->getParameter('parameters');
if (0 !== count($configuredParameters)) {
if (null === $view) {
throw new Exception('A view should be provided if the menu item route requires parameters');
}
if (!$view->getEntities() instanceof Collection) {
throw new Exception(
'Entities returned by the view should be a instance of "'.Collection::class.'" to be used in menu action'
);
}
if (1 !== $view->getEntities()->count()) {
throw new Exception('You can not map route parameters if multiple entities are loaded');
}
$entity = $view->getEntities()->first();
$accessor = PropertyAccess::createPropertyAccessor();
foreach ($configuredParameters as $name => $requirements) {
$routeParameters[$name] = $accessor->getValue($entity, $name);
}
}
return $this->router->generate($routeName, $routeParameters);
} | php | public function getMenuAction(MenuItemConfiguration $configuration, ViewInterface $view = null): string
{
if ($configuration->getParameter('url')) {
return $configuration->getParameter('url');
}
$routeName = $configuration->getParameter('route');
if ($configuration->getParameter('admin')) {
$routeName = RoutingLoader::generateRouteName(
$configuration->getParameter('admin'),
$configuration->getParameter('action'),
$this
->applicationConfigurationStorage
->getConfiguration()
->getParameter('routing_name_pattern')
);
}
// Map the potential parameters to the entity
$routeParameters = [];
$configuredParameters = $configuration->getParameter('parameters');
if (0 !== count($configuredParameters)) {
if (null === $view) {
throw new Exception('A view should be provided if the menu item route requires parameters');
}
if (!$view->getEntities() instanceof Collection) {
throw new Exception(
'Entities returned by the view should be a instance of "'.Collection::class.'" to be used in menu action'
);
}
if (1 !== $view->getEntities()->count()) {
throw new Exception('You can not map route parameters if multiple entities are loaded');
}
$entity = $view->getEntities()->first();
$accessor = PropertyAccess::createPropertyAccessor();
foreach ($configuredParameters as $name => $requirements) {
$routeParameters[$name] = $accessor->getValue($entity, $name);
}
}
return $this->router->generate($routeName, $routeParameters);
} | [
"public",
"function",
"getMenuAction",
"(",
"MenuItemConfiguration",
"$",
"configuration",
",",
"ViewInterface",
"$",
"view",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"configuration",
"->",
"getParameter",
"(",
"'url'",
")",
")",
"{",
"return",
... | Return the url of an menu item.
@param MenuItemConfiguration $configuration
@param ViewInterface $view
@return string
@throws Exception | [
"Return",
"the",
"url",
"of",
"an",
"menu",
"item",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Twig/Extension/AdminExtension.php#L80-L124 | train |
larriereguichet/AdminBundle | src/Bridge/Twig/Extension/AdminExtension.php | AdminExtension.getAdminUrl | public function getAdminUrl(ViewInterface $view, string $actionName, $entity = null)
{
if (!$this->isAdminActionAllowed($view, $actionName)) {
throw new Exception('The action "'.$actionName.'" is not allowed for the admin "'.$view->getName().'"');
}
$configuration = $view->getAdminConfiguration();
$parameters = [];
$routeName = RoutingLoader::generateRouteName(
$view->getName(),
$actionName,
$configuration->getParameter('routing_name_pattern')
);
if (null !== $entity) {
$accessor = PropertyAccess::createPropertyAccessor();
$actionConfiguration = $this->configurationFactory->createActionConfiguration(
$actionName,
$configuration->getParameter('actions')[$actionName],
$view->getName(),
$view->getAdminConfiguration()
);
foreach ($actionConfiguration->getParameter('route_requirements') as $name => $requirements) {
$parameters[$name] = $accessor->getValue($entity, $name);
}
}
return $this->router->generate($routeName, $parameters);
} | php | public function getAdminUrl(ViewInterface $view, string $actionName, $entity = null)
{
if (!$this->isAdminActionAllowed($view, $actionName)) {
throw new Exception('The action "'.$actionName.'" is not allowed for the admin "'.$view->getName().'"');
}
$configuration = $view->getAdminConfiguration();
$parameters = [];
$routeName = RoutingLoader::generateRouteName(
$view->getName(),
$actionName,
$configuration->getParameter('routing_name_pattern')
);
if (null !== $entity) {
$accessor = PropertyAccess::createPropertyAccessor();
$actionConfiguration = $this->configurationFactory->createActionConfiguration(
$actionName,
$configuration->getParameter('actions')[$actionName],
$view->getName(),
$view->getAdminConfiguration()
);
foreach ($actionConfiguration->getParameter('route_requirements') as $name => $requirements) {
$parameters[$name] = $accessor->getValue($entity, $name);
}
}
return $this->router->generate($routeName, $parameters);
} | [
"public",
"function",
"getAdminUrl",
"(",
"ViewInterface",
"$",
"view",
",",
"string",
"$",
"actionName",
",",
"$",
"entity",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAdminActionAllowed",
"(",
"$",
"view",
",",
"$",
"actionName",
")",... | Return the url of an Admin action.
@param ViewInterface $view
@param string $actionName
@param mixed|null $entity
@return string
@throws Exception | [
"Return",
"the",
"url",
"of",
"an",
"Admin",
"action",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Twig/Extension/AdminExtension.php#L137-L165 | train |
larriereguichet/AdminBundle | src/Bridge/Twig/Extension/AdminExtension.php | AdminExtension.isAdminActionAllowed | public function isAdminActionAllowed(ViewInterface $view, string $actionName)
{
$configuration = $view->getAdminConfiguration();
return key_exists($actionName, $configuration->getParameter('actions'));
} | php | public function isAdminActionAllowed(ViewInterface $view, string $actionName)
{
$configuration = $view->getAdminConfiguration();
return key_exists($actionName, $configuration->getParameter('actions'));
} | [
"public",
"function",
"isAdminActionAllowed",
"(",
"ViewInterface",
"$",
"view",
",",
"string",
"$",
"actionName",
")",
"{",
"$",
"configuration",
"=",
"$",
"view",
"->",
"getAdminConfiguration",
"(",
")",
";",
"return",
"key_exists",
"(",
"$",
"actionName",
"... | Return true if the given action is allowed for the given Admin.
@param ViewInterface $view
@param string $actionName
@return bool | [
"Return",
"true",
"if",
"the",
"given",
"action",
"is",
"allowed",
"for",
"the",
"given",
"Admin",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Twig/Extension/AdminExtension.php#L175-L180 | train |
larriereguichet/AdminBundle | src/Routing/RoutingLoader.php | RoutingLoader.load | public function load($routingResource, $type = null)
{
if ($this->loaded) {
throw new RuntimeException('Do not add the Admin "extra" loader twice');
}
$routes = new RouteCollection();
foreach ($this->resourceCollection->all() as $name => $resource) {
$configuration = $this
->configurationFactory
->createAdminConfiguration(
$resource->getName(),
$resource->getConfiguration(),
$this->applicationConfiguration
)
;
foreach ($configuration->getParameter('actions') as $actionName => $actionData) {
$actionConfiguration = $this
->configurationFactory
->createActionConfiguration($actionName, $actionData, $name, $configuration)
;
$route = new Route(
$actionConfiguration->getParameter('route_path'),
$actionConfiguration->getParameter('route_defaults'),
$actionConfiguration->getParameter('route_requirements')
);
$routes->add($actionConfiguration->getParameter('route'), $route);
}
if ($this->applicationConfiguration->getParameter('enable_homepage')) {
$route = new Route('/', ['_controller' => HomeAction::class], []);
$routes->add('lag.admin.homepage', $route);
}
}
return $routes;
} | php | public function load($routingResource, $type = null)
{
if ($this->loaded) {
throw new RuntimeException('Do not add the Admin "extra" loader twice');
}
$routes = new RouteCollection();
foreach ($this->resourceCollection->all() as $name => $resource) {
$configuration = $this
->configurationFactory
->createAdminConfiguration(
$resource->getName(),
$resource->getConfiguration(),
$this->applicationConfiguration
)
;
foreach ($configuration->getParameter('actions') as $actionName => $actionData) {
$actionConfiguration = $this
->configurationFactory
->createActionConfiguration($actionName, $actionData, $name, $configuration)
;
$route = new Route(
$actionConfiguration->getParameter('route_path'),
$actionConfiguration->getParameter('route_defaults'),
$actionConfiguration->getParameter('route_requirements')
);
$routes->add($actionConfiguration->getParameter('route'), $route);
}
if ($this->applicationConfiguration->getParameter('enable_homepage')) {
$route = new Route('/', ['_controller' => HomeAction::class], []);
$routes->add('lag.admin.homepage', $route);
}
}
return $routes;
} | [
"public",
"function",
"load",
"(",
"$",
"routingResource",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loaded",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Do not add the Admin \"extra\" loader twice'",
")",
";",
"}",
"$"... | Load the Admin's route.
@param mixed $routingResource
@param string $type
@return RouteCollection
@throws Exception | [
"Load",
"the",
"Admin",
"s",
"route",
"."
] | 794991d72b3f50b70de424be7a89c3307f9eecc1 | https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Routing/RoutingLoader.php#L104-L141 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.