repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
composer/xdebug-handler | src/Process.php | Process.escape | public static function escape($arg, $meta = true, $module = false)
{
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
return "'".str_replace("'", "'\\''", $arg)."'";
}
$quote = strpbrk($arg, " \t") !== false || $arg === '';
$arg = preg_replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);
if ($meta) {
$meta = $dquotes || preg_match('/%[^%]+%/', $arg);
if (!$meta) {
$quote = $quote || strpbrk($arg, '^&|<>()') !== false;
} elseif ($module && !$dquotes && $quote) {
$meta = false;
}
}
if ($quote) {
$arg = '"'.preg_replace('/(\\\\*)$/', '$1$1', $arg).'"';
}
if ($meta) {
$arg = preg_replace('/(["^&|<>()%])/', '^$1', $arg);
}
return $arg;
} | php | public static function escape($arg, $meta = true, $module = false)
{
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
return "'".str_replace("'", "'\\''", $arg)."'";
}
$quote = strpbrk($arg, " \t") !== false || $arg === '';
$arg = preg_replace('/(\\\\*)"/', '$1$1\\"', $arg, -1, $dquotes);
if ($meta) {
$meta = $dquotes || preg_match('/%[^%]+%/', $arg);
if (!$meta) {
$quote = $quote || strpbrk($arg, '^&|<>()') !== false;
} elseif ($module && !$dquotes && $quote) {
$meta = false;
}
}
if ($quote) {
$arg = '"'.preg_replace('/(\\\\*)$/', '$1$1', $arg).'"';
}
if ($meta) {
$arg = preg_replace('/(["^&|<>()%])/', '^$1', $arg);
}
return $arg;
} | [
"public",
"static",
"function",
"escape",
"(",
"$",
"arg",
",",
"$",
"meta",
"=",
"true",
",",
"$",
"module",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
")",
"{",
"return",
"\"'\"",
".",
"str_replace",
"... | Escapes a string to be used as a shell argument.
From https://github.com/johnstevenson/winbox-args
MIT Licensed (c) John Stevenson <john-stevenson@blueyonder.co.uk>
@param string $arg The argument to be escaped
@param bool $meta Additionally escape cmd.exe meta characters
@param bool $module The argument is the module to invoke
@return string The escaped argument | [
"Escapes",
"a",
"string",
"to",
"be",
"used",
"as",
"a",
"shell",
"argument",
"."
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/Process.php#L75-L104 |
composer/xdebug-handler | src/Process.php | Process.supportsColor | public static function supportsColor($output)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return (function_exists('sapi_windows_vt100_support')
&& sapi_windows_vt100_support($output))
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
}
if (function_exists('stream_isatty')) {
return stream_isatty($output);
} elseif (function_exists('posix_isatty')) {
return posix_isatty($output);
}
$stat = fstat($output);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
} | php | public static function supportsColor($output)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return (function_exists('sapi_windows_vt100_support')
&& sapi_windows_vt100_support($output))
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
}
if (function_exists('stream_isatty')) {
return stream_isatty($output);
} elseif (function_exists('posix_isatty')) {
return posix_isatty($output);
}
$stat = fstat($output);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
} | [
"public",
"static",
"function",
"supportsColor",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
")",
"{",
"return",
"(",
"function_exists",
"(",
"'sapi_windows_vt100_support'",
")",
"&&",
"sapi_windows_vt100_support",
"(... | Returns true if the output stream supports colors
This is tricky on Windows, because Cygwin, Msys2 etc emulate pseudo
terminals via named pipes, so we can only check the environment.
@param mixed $output A valid CLI output stream
@return bool | [
"Returns",
"true",
"if",
"the",
"output",
"stream",
"supports",
"colors"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/Process.php#L116-L135 |
composer/xdebug-handler | src/Process.php | Process.setEnv | public static function setEnv($name, $value = false)
{
$unset = false === $value;
if (!putenv($unset ? $name : $name.'='.$value)) {
return false;
}
if ($unset) {
unset($_SERVER[$name]);
} else {
$_SERVER[$name] = $value;
}
return true;
} | php | public static function setEnv($name, $value = false)
{
$unset = false === $value;
if (!putenv($unset ? $name : $name.'='.$value)) {
return false;
}
if ($unset) {
unset($_SERVER[$name]);
} else {
$_SERVER[$name] = $value;
}
return true;
} | [
"public",
"static",
"function",
"setEnv",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"false",
")",
"{",
"$",
"unset",
"=",
"false",
"===",
"$",
"value",
";",
"if",
"(",
"!",
"putenv",
"(",
"$",
"unset",
"?",
"$",
"name",
":",
"$",
"name",
".",
"... | Makes putenv environment changes available in $_SERVER
@param string $name
@param string|false $value A false value unsets the variable
@return bool Whether the environment variable was set | [
"Makes",
"putenv",
"environment",
"changes",
"available",
"in",
"$_SERVER"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/Process.php#L145-L159 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.check | public function check()
{
$this->notify(Status::CHECK, $this->loaded);
$envArgs = explode('|', (string) getenv($this->envAllowXdebug));
if (empty($envArgs[0]) && $this->requiresRestart((bool) $this->loaded)) {
// Restart required
$this->notify(Status::RESTART);
if ($this->prepareRestart()) {
$command = $this->getCommand();
$this->notify(Status::RESTARTING, $command);
$this->restart($command);
}
return;
}
if (self::RESTART_ID === $envArgs[0] && count($envArgs) === 5) {
// Restarting, so unset environment variable and use saved values
$this->notify(Status::RESTARTED);
Process::setEnv($this->envAllowXdebug);
self::$inRestart = true;
if (!$this->loaded) {
// Skipped version is only set if xdebug is not loaded
self::$skipped = $envArgs[1];
}
// Put restart settings in the environment
$this->setEnvRestartSettings($envArgs);
return;
}
$this->notify(Status::NORESTART);
if ($settings = self::getRestartSettings()) {
// Called with existing settings, so sync our settings
$this->syncSettings($settings);
}
} | php | public function check()
{
$this->notify(Status::CHECK, $this->loaded);
$envArgs = explode('|', (string) getenv($this->envAllowXdebug));
if (empty($envArgs[0]) && $this->requiresRestart((bool) $this->loaded)) {
// Restart required
$this->notify(Status::RESTART);
if ($this->prepareRestart()) {
$command = $this->getCommand();
$this->notify(Status::RESTARTING, $command);
$this->restart($command);
}
return;
}
if (self::RESTART_ID === $envArgs[0] && count($envArgs) === 5) {
// Restarting, so unset environment variable and use saved values
$this->notify(Status::RESTARTED);
Process::setEnv($this->envAllowXdebug);
self::$inRestart = true;
if (!$this->loaded) {
// Skipped version is only set if xdebug is not loaded
self::$skipped = $envArgs[1];
}
// Put restart settings in the environment
$this->setEnvRestartSettings($envArgs);
return;
}
$this->notify(Status::NORESTART);
if ($settings = self::getRestartSettings()) {
// Called with existing settings, so sync our settings
$this->syncSettings($settings);
}
} | [
"public",
"function",
"check",
"(",
")",
"{",
"$",
"this",
"->",
"notify",
"(",
"Status",
"::",
"CHECK",
",",
"$",
"this",
"->",
"loaded",
")",
";",
"$",
"envArgs",
"=",
"explode",
"(",
"'|'",
",",
"(",
"string",
")",
"getenv",
"(",
"$",
"this",
... | Checks if xdebug is loaded and the process needs to be restarted
This behaviour can be disabled by setting the MYAPP_ALLOW_XDEBUG
environment variable to 1. This variable is used internally so that
the restarted process is created only once. | [
"Checks",
"if",
"xdebug",
"is",
"loaded",
"and",
"the",
"process",
"needs",
"to",
"be",
"restarted"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L124-L164 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.getAllIniFiles | public static function getAllIniFiles()
{
if (!empty(self::$name)) {
$env = getenv(self::$name.self::SUFFIX_INIS);
if (false !== $env) {
return explode(PATH_SEPARATOR, $env);
}
}
$paths = array((string) php_ini_loaded_file());
if ($scanned = php_ini_scanned_files()) {
$paths = array_merge($paths, array_map('trim', explode(',', $scanned)));
}
return $paths;
} | php | public static function getAllIniFiles()
{
if (!empty(self::$name)) {
$env = getenv(self::$name.self::SUFFIX_INIS);
if (false !== $env) {
return explode(PATH_SEPARATOR, $env);
}
}
$paths = array((string) php_ini_loaded_file());
if ($scanned = php_ini_scanned_files()) {
$paths = array_merge($paths, array_map('trim', explode(',', $scanned)));
}
return $paths;
} | [
"public",
"static",
"function",
"getAllIniFiles",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"name",
")",
")",
"{",
"$",
"env",
"=",
"getenv",
"(",
"self",
"::",
"$",
"name",
".",
"self",
"::",
"SUFFIX_INIS",
")",
";",
"if",
... | Returns an array of php.ini locations with at least one entry
The equivalent of calling php_ini_loaded_file then php_ini_scanned_files.
The loaded ini location is the first entry and may be empty.
@return array | [
"Returns",
"an",
"array",
"of",
"php",
".",
"ini",
"locations",
"with",
"at",
"least",
"one",
"entry"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L174-L191 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.getRestartSettings | public static function getRestartSettings()
{
$envArgs = explode('|', (string) getenv(self::RESTART_SETTINGS));
if (count($envArgs) !== 6
|| (!self::$inRestart && php_ini_loaded_file() !== $envArgs[0])) {
return;
}
return array(
'tmpIni' => $envArgs[0],
'scannedInis' => (bool) $envArgs[1],
'scanDir' => '*' === $envArgs[2] ? false : $envArgs[2],
'phprc' => '*' === $envArgs[3] ? false : $envArgs[3],
'inis' => explode(PATH_SEPARATOR, $envArgs[4]),
'skipped' => $envArgs[5],
);
} | php | public static function getRestartSettings()
{
$envArgs = explode('|', (string) getenv(self::RESTART_SETTINGS));
if (count($envArgs) !== 6
|| (!self::$inRestart && php_ini_loaded_file() !== $envArgs[0])) {
return;
}
return array(
'tmpIni' => $envArgs[0],
'scannedInis' => (bool) $envArgs[1],
'scanDir' => '*' === $envArgs[2] ? false : $envArgs[2],
'phprc' => '*' === $envArgs[3] ? false : $envArgs[3],
'inis' => explode(PATH_SEPARATOR, $envArgs[4]),
'skipped' => $envArgs[5],
);
} | [
"public",
"static",
"function",
"getRestartSettings",
"(",
")",
"{",
"$",
"envArgs",
"=",
"explode",
"(",
"'|'",
",",
"(",
"string",
")",
"getenv",
"(",
"self",
"::",
"RESTART_SETTINGS",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"envArgs",
")",
"!==... | Returns an array of restart settings or null
Settings will be available if the current process was restarted, or
called with the settings from an existing restart.
@return array|null | [
"Returns",
"an",
"array",
"of",
"restart",
"settings",
"or",
"null"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L201-L218 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.doRestart | private function doRestart($command)
{
passthru($command, $exitCode);
$this->notify(Status::INFO, 'Restarted process exited '.$exitCode);
if ($this->debug === '2') {
$this->notify(Status::INFO, 'Temp ini saved: '.$this->tmpIni);
} else {
@unlink($this->tmpIni);
}
exit($exitCode);
} | php | private function doRestart($command)
{
passthru($command, $exitCode);
$this->notify(Status::INFO, 'Restarted process exited '.$exitCode);
if ($this->debug === '2') {
$this->notify(Status::INFO, 'Temp ini saved: '.$this->tmpIni);
} else {
@unlink($this->tmpIni);
}
exit($exitCode);
} | [
"private",
"function",
"doRestart",
"(",
"$",
"command",
")",
"{",
"passthru",
"(",
"$",
"command",
",",
"$",
"exitCode",
")",
";",
"$",
"this",
"->",
"notify",
"(",
"Status",
"::",
"INFO",
",",
"'Restarted process exited '",
".",
"$",
"exitCode",
")",
"... | Executes the restarted command then deletes the tmp ini
@param string $command | [
"Executes",
"the",
"restarted",
"command",
"then",
"deletes",
"the",
"tmp",
"ini"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L257-L269 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.prepareRestart | private function prepareRestart()
{
$error = '';
$iniFiles = self::getAllIniFiles();
$scannedInis = count($iniFiles) > 1;
$tmpDir = sys_get_temp_dir();
if (!$this->cli) {
$error = 'Unsupported SAPI: '.PHP_SAPI;
} elseif (!defined('PHP_BINARY')) {
$error = 'PHP version is too old: '.PHP_VERSION;
} elseif (!$this->checkConfiguration($info)) {
$error = $info;
} elseif (!$this->checkScanDirConfig()) {
$error = 'PHP version does not report scanned inis: '.PHP_VERSION;
} elseif (!$this->checkMainScript()) {
$error = 'Unable to access main script: '.$this->script;
} elseif (!$this->writeTmpIni($iniFiles, $tmpDir, $error)) {
$error = $error ?: 'Unable to create temp ini file at: '.$tmpDir;
} elseif (!$this->setEnvironment($scannedInis, $iniFiles)) {
$error = 'Unable to set environment variables';
}
if ($error) {
$this->notify(Status::ERROR, $error);
}
return empty($error);
} | php | private function prepareRestart()
{
$error = '';
$iniFiles = self::getAllIniFiles();
$scannedInis = count($iniFiles) > 1;
$tmpDir = sys_get_temp_dir();
if (!$this->cli) {
$error = 'Unsupported SAPI: '.PHP_SAPI;
} elseif (!defined('PHP_BINARY')) {
$error = 'PHP version is too old: '.PHP_VERSION;
} elseif (!$this->checkConfiguration($info)) {
$error = $info;
} elseif (!$this->checkScanDirConfig()) {
$error = 'PHP version does not report scanned inis: '.PHP_VERSION;
} elseif (!$this->checkMainScript()) {
$error = 'Unable to access main script: '.$this->script;
} elseif (!$this->writeTmpIni($iniFiles, $tmpDir, $error)) {
$error = $error ?: 'Unable to create temp ini file at: '.$tmpDir;
} elseif (!$this->setEnvironment($scannedInis, $iniFiles)) {
$error = 'Unable to set environment variables';
}
if ($error) {
$this->notify(Status::ERROR, $error);
}
return empty($error);
} | [
"private",
"function",
"prepareRestart",
"(",
")",
"{",
"$",
"error",
"=",
"''",
";",
"$",
"iniFiles",
"=",
"self",
"::",
"getAllIniFiles",
"(",
")",
";",
"$",
"scannedInis",
"=",
"count",
"(",
"$",
"iniFiles",
")",
">",
"1",
";",
"$",
"tmpDir",
"=",... | Returns true if everything was written for the restart
If any of the following fails (however unlikely) we must return false to
stop potential recursion:
- tmp ini file creation
- environment variable creation
@return bool | [
"Returns",
"true",
"if",
"everything",
"was",
"written",
"for",
"the",
"restart"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L281-L309 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.writeTmpIni | private function writeTmpIni(array $iniFiles, $tmpDir, &$error)
{
if (!$this->tmpIni = @tempnam($tmpDir, '')) {
return false;
}
// $iniFiles has at least one item and it may be empty
if (empty($iniFiles[0])) {
array_shift($iniFiles);
}
$content = '';
$regex = '/^\s*(zend_extension\s*=.*xdebug.*)$/mi';
foreach ($iniFiles as $file) {
// Check for inaccessible ini files
if (!$data = @file_get_contents($file)) {
$error = 'Unable to read ini: '.$file;
return false;
}
$content .= preg_replace($regex, ';$1', $data).PHP_EOL;
}
// Merge loaded settings into our ini content, if it is valid
if ($config = parse_ini_string($content)) {
$loaded = ini_get_all(null, false);
$content .= $this->mergeLoadedConfig($loaded, $config);
}
// Work-around for https://bugs.php.net/bug.php?id=75932
$content .= 'opcache.enable_cli=0'.PHP_EOL;
return @file_put_contents($this->tmpIni, $content);
} | php | private function writeTmpIni(array $iniFiles, $tmpDir, &$error)
{
if (!$this->tmpIni = @tempnam($tmpDir, '')) {
return false;
}
// $iniFiles has at least one item and it may be empty
if (empty($iniFiles[0])) {
array_shift($iniFiles);
}
$content = '';
$regex = '/^\s*(zend_extension\s*=.*xdebug.*)$/mi';
foreach ($iniFiles as $file) {
// Check for inaccessible ini files
if (!$data = @file_get_contents($file)) {
$error = 'Unable to read ini: '.$file;
return false;
}
$content .= preg_replace($regex, ';$1', $data).PHP_EOL;
}
// Merge loaded settings into our ini content, if it is valid
if ($config = parse_ini_string($content)) {
$loaded = ini_get_all(null, false);
$content .= $this->mergeLoadedConfig($loaded, $config);
}
// Work-around for https://bugs.php.net/bug.php?id=75932
$content .= 'opcache.enable_cli=0'.PHP_EOL;
return @file_put_contents($this->tmpIni, $content);
} | [
"private",
"function",
"writeTmpIni",
"(",
"array",
"$",
"iniFiles",
",",
"$",
"tmpDir",
",",
"&",
"$",
"error",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tmpIni",
"=",
"@",
"tempnam",
"(",
"$",
"tmpDir",
",",
"''",
")",
")",
"{",
"return",
"... | Returns true if the tmp ini file was written
@param array $iniFiles All ini files used in the current process
@param string $tmpDir The system temporary directory
@param string $error Set by method if ini file cannot be read
@return bool | [
"Returns",
"true",
"if",
"the",
"tmp",
"ini",
"file",
"was",
"written"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L320-L353 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.getCommand | private function getCommand()
{
$php = array(PHP_BINARY);
$args = array_slice($_SERVER['argv'], 1);
if (!$this->persistent) {
// Use command-line options
array_push($php, '-n', '-c', $this->tmpIni);
}
if (defined('STDOUT') && Process::supportsColor(STDOUT)) {
$args = Process::addColorOption($args, $this->colorOption);
}
$args = array_merge($php, array($this->script), $args);
$cmd = Process::escape(array_shift($args), true, true);
foreach ($args as $arg) {
$cmd .= ' '.Process::escape($arg);
}
return $cmd;
} | php | private function getCommand()
{
$php = array(PHP_BINARY);
$args = array_slice($_SERVER['argv'], 1);
if (!$this->persistent) {
// Use command-line options
array_push($php, '-n', '-c', $this->tmpIni);
}
if (defined('STDOUT') && Process::supportsColor(STDOUT)) {
$args = Process::addColorOption($args, $this->colorOption);
}
$args = array_merge($php, array($this->script), $args);
$cmd = Process::escape(array_shift($args), true, true);
foreach ($args as $arg) {
$cmd .= ' '.Process::escape($arg);
}
return $cmd;
} | [
"private",
"function",
"getCommand",
"(",
")",
"{",
"$",
"php",
"=",
"array",
"(",
"PHP_BINARY",
")",
";",
"$",
"args",
"=",
"array_slice",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
",",
"1",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"persistent"... | Returns the restart command line
@return string | [
"Returns",
"the",
"restart",
"command",
"line"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L360-L382 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.setEnvironment | private function setEnvironment($scannedInis, array $iniFiles)
{
$scanDir = getenv('PHP_INI_SCAN_DIR');
$phprc = getenv('PHPRC');
// Make original inis available to restarted process
if (!putenv($this->envOriginalInis.'='.implode(PATH_SEPARATOR, $iniFiles))) {
return false;
}
if ($this->persistent) {
// Use the environment to persist the settings
if (!putenv('PHP_INI_SCAN_DIR=') || !putenv('PHPRC='.$this->tmpIni)) {
return false;
}
}
// Flag restarted process and save values for it to use
$envArgs = array(
self::RESTART_ID,
$this->loaded,
(int) $scannedInis,
false === $scanDir ? '*' : $scanDir,
false === $phprc ? '*' : $phprc,
);
return putenv($this->envAllowXdebug.'='.implode('|', $envArgs));
} | php | private function setEnvironment($scannedInis, array $iniFiles)
{
$scanDir = getenv('PHP_INI_SCAN_DIR');
$phprc = getenv('PHPRC');
// Make original inis available to restarted process
if (!putenv($this->envOriginalInis.'='.implode(PATH_SEPARATOR, $iniFiles))) {
return false;
}
if ($this->persistent) {
// Use the environment to persist the settings
if (!putenv('PHP_INI_SCAN_DIR=') || !putenv('PHPRC='.$this->tmpIni)) {
return false;
}
}
// Flag restarted process and save values for it to use
$envArgs = array(
self::RESTART_ID,
$this->loaded,
(int) $scannedInis,
false === $scanDir ? '*' : $scanDir,
false === $phprc ? '*' : $phprc,
);
return putenv($this->envAllowXdebug.'='.implode('|', $envArgs));
} | [
"private",
"function",
"setEnvironment",
"(",
"$",
"scannedInis",
",",
"array",
"$",
"iniFiles",
")",
"{",
"$",
"scanDir",
"=",
"getenv",
"(",
"'PHP_INI_SCAN_DIR'",
")",
";",
"$",
"phprc",
"=",
"getenv",
"(",
"'PHPRC'",
")",
";",
"// Make original inis availab... | Returns true if the restart environment variables were set
No need to update $_SERVER since this is set in the restarted process.
@param bool $scannedInis Whether there were scanned ini files
@param array $iniFiles All ini files used in the current process
@return bool | [
"Returns",
"true",
"if",
"the",
"restart",
"environment",
"variables",
"were",
"set"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L394-L421 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.mergeLoadedConfig | private function mergeLoadedConfig(array $loadedConfig, array $iniConfig)
{
$content = '';
foreach ($loadedConfig as $name => $value) {
// Value will either be null, string or array (HHVM only)
if (!is_string($value)
|| strpos($name, 'xdebug') === 0
|| $name === 'apc.mmap_file_mask') {
continue;
}
if (!isset($iniConfig[$name]) || $iniConfig[$name] !== $value) {
// Double-quote escape each value
$content .= $name.'="'.addcslashes($value, '\\"').'"'.PHP_EOL;
}
}
return $content;
} | php | private function mergeLoadedConfig(array $loadedConfig, array $iniConfig)
{
$content = '';
foreach ($loadedConfig as $name => $value) {
// Value will either be null, string or array (HHVM only)
if (!is_string($value)
|| strpos($name, 'xdebug') === 0
|| $name === 'apc.mmap_file_mask') {
continue;
}
if (!isset($iniConfig[$name]) || $iniConfig[$name] !== $value) {
// Double-quote escape each value
$content .= $name.'="'.addcslashes($value, '\\"').'"'.PHP_EOL;
}
}
return $content;
} | [
"private",
"function",
"mergeLoadedConfig",
"(",
"array",
"$",
"loadedConfig",
",",
"array",
"$",
"iniConfig",
")",
"{",
"$",
"content",
"=",
"''",
";",
"foreach",
"(",
"$",
"loadedConfig",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"// Value will ei... | Returns default, changed and command-line ini settings
@param array $loadedConfig All current ini settings
@param array $iniConfig Settings from user ini files
@return string | [
"Returns",
"default",
"changed",
"and",
"command",
"-",
"line",
"ini",
"settings"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L442-L461 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.checkMainScript | private function checkMainScript()
{
if (null !== $this->script) {
// Allow an application to set -- for standard input
return file_exists($this->script) || '--' === $this->script;
}
if (file_exists($this->script = $_SERVER['argv'][0])) {
return true;
}
// Use a backtrace to resolve Phar and chdir issues
$options = PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false;
$trace = debug_backtrace($options);
if (($main = end($trace)) && isset($main['file'])) {
return file_exists($this->script = $main['file']);
}
return false;
} | php | private function checkMainScript()
{
if (null !== $this->script) {
// Allow an application to set -- for standard input
return file_exists($this->script) || '--' === $this->script;
}
if (file_exists($this->script = $_SERVER['argv'][0])) {
return true;
}
// Use a backtrace to resolve Phar and chdir issues
$options = PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : false;
$trace = debug_backtrace($options);
if (($main = end($trace)) && isset($main['file'])) {
return file_exists($this->script = $main['file']);
}
return false;
} | [
"private",
"function",
"checkMainScript",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"script",
")",
"{",
"// Allow an application to set -- for standard input",
"return",
"file_exists",
"(",
"$",
"this",
"->",
"script",
")",
"||",
"'--'",
"===",... | Returns true if the script name can be used
@return bool | [
"Returns",
"true",
"if",
"the",
"script",
"name",
"can",
"be",
"used"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L468-L488 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.setEnvRestartSettings | private function setEnvRestartSettings($envArgs)
{
$settings = array(
php_ini_loaded_file(),
$envArgs[2],
$envArgs[3],
$envArgs[4],
getenv($this->envOriginalInis),
self::$skipped,
);
Process::setEnv(self::RESTART_SETTINGS, implode('|', $settings));
} | php | private function setEnvRestartSettings($envArgs)
{
$settings = array(
php_ini_loaded_file(),
$envArgs[2],
$envArgs[3],
$envArgs[4],
getenv($this->envOriginalInis),
self::$skipped,
);
Process::setEnv(self::RESTART_SETTINGS, implode('|', $settings));
} | [
"private",
"function",
"setEnvRestartSettings",
"(",
"$",
"envArgs",
")",
"{",
"$",
"settings",
"=",
"array",
"(",
"php_ini_loaded_file",
"(",
")",
",",
"$",
"envArgs",
"[",
"2",
"]",
",",
"$",
"envArgs",
"[",
"3",
"]",
",",
"$",
"envArgs",
"[",
"4",
... | Adds restart settings to the environment
@param string $envArgs | [
"Adds",
"restart",
"settings",
"to",
"the",
"environment"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L495-L507 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.syncSettings | private function syncSettings(array $settings)
{
if (false === getenv($this->envOriginalInis)) {
// Called by another app, so make original inis available
Process::setEnv($this->envOriginalInis, implode(PATH_SEPARATOR, $settings['inis']));
}
self::$skipped = $settings['skipped'];
$this->notify(Status::INFO, 'Process called with existing restart settings');
} | php | private function syncSettings(array $settings)
{
if (false === getenv($this->envOriginalInis)) {
// Called by another app, so make original inis available
Process::setEnv($this->envOriginalInis, implode(PATH_SEPARATOR, $settings['inis']));
}
self::$skipped = $settings['skipped'];
$this->notify(Status::INFO, 'Process called with existing restart settings');
} | [
"private",
"function",
"syncSettings",
"(",
"array",
"$",
"settings",
")",
"{",
"if",
"(",
"false",
"===",
"getenv",
"(",
"$",
"this",
"->",
"envOriginalInis",
")",
")",
"{",
"// Called by another app, so make original inis available",
"Process",
"::",
"setEnv",
"... | Syncs settings and the environment if called with existing settings
@param array $settings | [
"Syncs",
"settings",
"and",
"the",
"environment",
"if",
"called",
"with",
"existing",
"settings"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L514-L523 |
composer/xdebug-handler | src/XdebugHandler.php | XdebugHandler.checkConfiguration | private function checkConfiguration(&$info)
{
if (false !== strpos(ini_get('disable_functions'), 'passthru')) {
$info = 'passthru function is disabled';
return false;
}
if (extension_loaded('uopz')) {
// uopz works at opcode level and disables exit calls
if (function_exists('uopz_allow_exit')) {
@uopz_allow_exit(true);
} else {
$info = 'uopz extension is not compatible';
return false;
}
}
return true;
} | php | private function checkConfiguration(&$info)
{
if (false !== strpos(ini_get('disable_functions'), 'passthru')) {
$info = 'passthru function is disabled';
return false;
}
if (extension_loaded('uopz')) {
// uopz works at opcode level and disables exit calls
if (function_exists('uopz_allow_exit')) {
@uopz_allow_exit(true);
} else {
$info = 'uopz extension is not compatible';
return false;
}
}
return true;
} | [
"private",
"function",
"checkConfiguration",
"(",
"&",
"$",
"info",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"ini_get",
"(",
"'disable_functions'",
")",
",",
"'passthru'",
")",
")",
"{",
"$",
"info",
"=",
"'passthru function is disabled'",
";",
"r... | Returns true if there are no known configuration issues
@param string $info Set by method | [
"Returns",
"true",
"if",
"there",
"are",
"no",
"known",
"configuration",
"issues"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/XdebugHandler.php#L546-L564 |
composer/xdebug-handler | src/PhpConfig.php | PhpConfig.getDataAndReset | private function getDataAndReset()
{
if ($data = XdebugHandler::getRestartSettings()) {
Process::setEnv('PHPRC', $data['phprc']);
Process::setEnv('PHP_INI_SCAN_DIR', $data['scanDir']);
}
return $data;
} | php | private function getDataAndReset()
{
if ($data = XdebugHandler::getRestartSettings()) {
Process::setEnv('PHPRC', $data['phprc']);
Process::setEnv('PHP_INI_SCAN_DIR', $data['scanDir']);
}
return $data;
} | [
"private",
"function",
"getDataAndReset",
"(",
")",
"{",
"if",
"(",
"$",
"data",
"=",
"XdebugHandler",
"::",
"getRestartSettings",
"(",
")",
")",
"{",
"Process",
"::",
"setEnv",
"(",
"'PHPRC'",
",",
"$",
"data",
"[",
"'phprc'",
"]",
")",
";",
"Process",
... | Returns restart data if available and resets the environment
@return array|null | [
"Returns",
"restart",
"data",
"if",
"available",
"and",
"resets",
"the",
"environment"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/PhpConfig.php#L64-L72 |
composer/xdebug-handler | src/Status.php | Status.report | public function report($op, $data)
{
if ($this->logger || $this->debug) {
call_user_func(array($this, 'report'.$op), $data);
}
} | php | public function report($op, $data)
{
if ($this->logger || $this->debug) {
call_user_func(array($this, 'report'.$op), $data);
}
} | [
"public",
"function",
"report",
"(",
"$",
"op",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"||",
"$",
"this",
"->",
"debug",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"'report'",
".",
"$",
"op",
")"... | Calls a handler method to report a message
@param string $op The handler constant
@param null|string $data Data required by the handler | [
"Calls",
"a",
"handler",
"method",
"to",
"report",
"a",
"message"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/Status.php#L68-L73 |
composer/xdebug-handler | src/Status.php | Status.output | private function output($text, $level = null)
{
if ($this->logger) {
$this->logger->log($level ?: LogLevel::DEBUG, $text);
}
if ($this->debug) {
fwrite(STDERR, sprintf('xdebug-handler[%d] %s', getmypid(), $text.PHP_EOL));
}
} | php | private function output($text, $level = null)
{
if ($this->logger) {
$this->logger->log($level ?: LogLevel::DEBUG, $text);
}
if ($this->debug) {
fwrite(STDERR, sprintf('xdebug-handler[%d] %s', getmypid(), $text.PHP_EOL));
}
} | [
"private",
"function",
"output",
"(",
"$",
"text",
",",
"$",
"level",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"level",
"?",
":",
"LogLevel",
"::",
"DEBUG",
",",
... | Outputs a status message
@param string $text
@param string $level | [
"Outputs",
"a",
"status",
"message"
] | train | https://github.com/composer/xdebug-handler/blob/0af624bc9c20a3c9252793625bbe976af082d401/src/Status.php#L81-L90 |
VincentChalnot/SidusEAVModelBundle | Twig/SidusTwigExtension.php | SidusTwigExtension.tryTrans | public function tryTrans($tIds, array $parameters = [], $fallback = null, $humanizeFallback = true)
{
return $this->tryTranslate($tIds, $parameters, $fallback, $humanizeFallback);
} | php | public function tryTrans($tIds, array $parameters = [], $fallback = null, $humanizeFallback = true)
{
return $this->tryTranslate($tIds, $parameters, $fallback, $humanizeFallback);
} | [
"public",
"function",
"tryTrans",
"(",
"$",
"tIds",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"fallback",
"=",
"null",
",",
"$",
"humanizeFallback",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"tryTranslate",
"(",
"$",
"tIds",
... | @param string|array $tIds
@param array $parameters
@param string|null $fallback
@param bool $humanizeFallback
@return string | [
"@param",
"string|array",
"$tIds",
"@param",
"array",
"$parameters",
"@param",
"string|null",
"$fallback",
"@param",
"bool",
"$humanizeFallback"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Twig/SidusTwigExtension.php#L70-L73 |
VincentChalnot/SidusEAVModelBundle | SidusEAVModelBundle.php | SidusEAVModelBundle.build | public function build(ContainerBuilder $container)
{
$container->addCompilerPass(
new GenericCompilerPass(
AttributeTypeRegistry::class,
'sidus.attribute_type',
'addType'
)
);
$container->addCompilerPass(
new GenericCompilerPass(
AttributeRegistry::class,
'sidus.attribute',
'addAttribute'
)
);
$container->addCompilerPass(
new GenericCompilerPass(
FamilyRegistry::class,
'sidus.family',
'addFamily'
)
);
} | php | public function build(ContainerBuilder $container)
{
$container->addCompilerPass(
new GenericCompilerPass(
AttributeTypeRegistry::class,
'sidus.attribute_type',
'addType'
)
);
$container->addCompilerPass(
new GenericCompilerPass(
AttributeRegistry::class,
'sidus.attribute',
'addAttribute'
)
);
$container->addCompilerPass(
new GenericCompilerPass(
FamilyRegistry::class,
'sidus.family',
'addFamily'
)
);
} | [
"public",
"function",
"build",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"GenericCompilerPass",
"(",
"AttributeTypeRegistry",
"::",
"class",
",",
"'sidus.attribute_type'",
",",
"'addType'",
")",
")",
... | Adding compiler passes to inject services into configuration handlers
@param ContainerBuilder $container | [
"Adding",
"compiler",
"passes",
"to",
"inject",
"services",
"into",
"configuration",
"handlers"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/SidusEAVModelBundle.php#L31-L54 |
VincentChalnot/SidusEAVModelBundle | Serializer/CircularReferenceHandler.php | CircularReferenceHandler.isCircularReference | public function isCircularReference($object, &$context)
{
$objectHash = spl_object_hash($object);
if (isset($context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash])) {
if ($context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash] >= $this->circularReferenceLimit) {
unset($context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash]);
return true;
}
++$context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash];
} else {
$context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash] = 1;
}
return false;
} | php | public function isCircularReference($object, &$context)
{
$objectHash = spl_object_hash($object);
if (isset($context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash])) {
if ($context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash] >= $this->circularReferenceLimit) {
unset($context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash]);
return true;
}
++$context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash];
} else {
$context[AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT][$objectHash] = 1;
}
return false;
} | [
"public",
"function",
"isCircularReference",
"(",
"$",
"object",
",",
"&",
"$",
"context",
")",
"{",
"$",
"objectHash",
"=",
"spl_object_hash",
"(",
"$",
"object",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"AbstractNormalizer",
"::",
"CIRCULA... | Detects if the configured circular reference limit is reached.
@param mixed $object
@param array $context
@throws CircularReferenceException
@return bool | [
"Detects",
"if",
"the",
"configured",
"circular",
"reference",
"limit",
"is",
"reached",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/CircularReferenceHandler.php#L67-L84 |
VincentChalnot/SidusEAVModelBundle | Serializer/CircularReferenceHandler.php | CircularReferenceHandler.handleCircularReference | public function handleCircularReference($object)
{
if ($this->circularReferenceHandler) {
return \call_user_func($this->circularReferenceHandler, $object);
}
throw new CircularReferenceException(
sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit)
);
} | php | public function handleCircularReference($object)
{
if ($this->circularReferenceHandler) {
return \call_user_func($this->circularReferenceHandler, $object);
}
throw new CircularReferenceException(
sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit)
);
} | [
"public",
"function",
"handleCircularReference",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"circularReferenceHandler",
")",
"{",
"return",
"\\",
"call_user_func",
"(",
"$",
"this",
"->",
"circularReferenceHandler",
",",
"$",
"object",
")",
";... | Handles a circular reference.
If a circular reference handler is set, it will be called. Otherwise, a
{@class CircularReferenceException} will be thrown.
@param mixed $object
@throws CircularReferenceException
@return mixed | [
"Handles",
"a",
"circular",
"reference",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/CircularReferenceHandler.php#L98-L107 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/AttributeNormalizer.php | AttributeNormalizer.getShortReference | protected function getShortReference($object, $format, array $context)
{
return [
'code' => $object->getCode(),
'type' => $object->getType()->getCode(),
'collection' => $object->isCollection(),
];
} | php | protected function getShortReference($object, $format, array $context)
{
return [
'code' => $object->getCode(),
'type' => $object->getType()->getCode(),
'collection' => $object->isCollection(),
];
} | [
"protected",
"function",
"getShortReference",
"(",
"$",
"object",
",",
"$",
"format",
",",
"array",
"$",
"context",
")",
"{",
"return",
"[",
"'code'",
"=>",
"$",
"object",
"->",
"getCode",
"(",
")",
",",
"'type'",
"=>",
"$",
"object",
"->",
"getType",
... | @param AttributeInterface $object
@param string $format
@param array $context
@return array | [
"@param",
"AttributeInterface",
"$object",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/AttributeNormalizer.php#L68-L75 |
VincentChalnot/SidusEAVModelBundle | Command/FixDataDiscriminatorsCommand.php | FixDataDiscriminatorsCommand.initialize | protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->familyRegistry = $this->getContainer()->get(FamilyRegistry::class);
$this->entityManager = $this->getContainer()->get('sidus_eav_model.entity_manager');
} | php | protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->familyRegistry = $this->getContainer()->get(FamilyRegistry::class);
$this->entityManager = $this->getContainer()->get('sidus_eav_model.entity_manager');
} | [
"protected",
"function",
"initialize",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"familyRegistry",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"FamilyRegistry",
"::",
"cla... | @param InputInterface $input
@param OutputInterface $output
@throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
@throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
@throws \LogicException | [
"@param",
"InputInterface",
"$input",
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/FixDataDiscriminatorsCommand.php#L53-L57 |
VincentChalnot/SidusEAVModelBundle | Command/FixDataDiscriminatorsCommand.php | FixDataDiscriminatorsCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ($this->familyRegistry->getFamilies() as $family) {
$this->updateFamilyData($family, $output);
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ($this->familyRegistry->getFamilies() as $family) {
$this->updateFamilyData($family, $output);
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"familyRegistry",
"->",
"getFamilies",
"(",
")",
"as",
"$",
"family",
")",
"{",
"$",
"this",
"->",
... | @param InputInterface $input
@param OutputInterface $output
@throws \UnexpectedValueException
@throws \InvalidArgumentException
@throws \RuntimeException
@throws \Doctrine\DBAL\DBALException
@return int|null|void | [
"@param",
"InputInterface",
"$input",
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/FixDataDiscriminatorsCommand.php#L70-L75 |
VincentChalnot/SidusEAVModelBundle | Command/FixDataDiscriminatorsCommand.php | FixDataDiscriminatorsCommand.updateFamilyData | protected function updateFamilyData(FamilyInterface $family, OutputInterface $output)
{
if (!$family->isInstantiable()) {
return;
}
$metadata = $this->entityManager->getClassMetadata($family->getDataClass());
if (!$metadata->discriminatorColumn) {
return;
}
$sql = $this->generateSql(
$metadata->getTableName(),
$metadata->discriminatorColumn['fieldName'],
$metadata->getColumnName('family')
);
$count = $this->updateTable($sql, $metadata->discriminatorValue, $family->getCode());
if ($count) {
$output->writeln("<comment>{$count} data updated for family {$family->getCode()}</comment>");
} else {
$output->writeln("<info>No data to clean for family {$family->getCode()}</info>");
}
} | php | protected function updateFamilyData(FamilyInterface $family, OutputInterface $output)
{
if (!$family->isInstantiable()) {
return;
}
$metadata = $this->entityManager->getClassMetadata($family->getDataClass());
if (!$metadata->discriminatorColumn) {
return;
}
$sql = $this->generateSql(
$metadata->getTableName(),
$metadata->discriminatorColumn['fieldName'],
$metadata->getColumnName('family')
);
$count = $this->updateTable($sql, $metadata->discriminatorValue, $family->getCode());
if ($count) {
$output->writeln("<comment>{$count} data updated for family {$family->getCode()}</comment>");
} else {
$output->writeln("<info>No data to clean for family {$family->getCode()}</info>");
}
} | [
"protected",
"function",
"updateFamilyData",
"(",
"FamilyInterface",
"$",
"family",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"!",
"$",
"family",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"metadata",
"=",
"$",
... | @param FamilyInterface $family
@param OutputInterface $output
@throws \UnexpectedValueException
@throws \Doctrine\DBAL\DBALException
@throws \RuntimeException
@throws \InvalidArgumentException | [
"@param",
"FamilyInterface",
"$family",
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/FixDataDiscriminatorsCommand.php#L86-L107 |
VincentChalnot/SidusEAVModelBundle | Command/FixDataDiscriminatorsCommand.php | FixDataDiscriminatorsCommand.updateTable | protected function updateTable($sql, $discriminatorValue, $familyCode)
{
$connection = $this->entityManager->getConnection();
$stmt = $connection->prepare($sql);
$stmt->bindValue(':discrValue', $discriminatorValue);
$stmt->bindValue(':familyCode', $familyCode);
if (!$stmt->execute()) {
throw new \RuntimeException("Unable to run SQL statement {$sql}");
}
return $stmt->rowCount();
} | php | protected function updateTable($sql, $discriminatorValue, $familyCode)
{
$connection = $this->entityManager->getConnection();
$stmt = $connection->prepare($sql);
$stmt->bindValue(':discrValue', $discriminatorValue);
$stmt->bindValue(':familyCode', $familyCode);
if (!$stmt->execute()) {
throw new \RuntimeException("Unable to run SQL statement {$sql}");
}
return $stmt->rowCount();
} | [
"protected",
"function",
"updateTable",
"(",
"$",
"sql",
",",
"$",
"discriminatorValue",
",",
"$",
"familyCode",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getConnection",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"connection"... | @param string $sql
@param string $discriminatorValue
@param string $familyCode
@throws \RuntimeException
@throws \Doctrine\DBAL\DBALException
@return int | [
"@param",
"string",
"$sql",
"@param",
"string",
"$discriminatorValue",
"@param",
"string",
"$familyCode"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/FixDataDiscriminatorsCommand.php#L138-L150 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVQueryBuilder.php | EAVQueryBuilder.attribute | public function attribute(AttributeInterface $attribute, $enforceFamilyCondition = true)
{
$attributeQb = new AttributeQueryBuilder($this, $attribute, $enforceFamilyCondition);
if ($this->context) {
$attributeQb->setContext($this->context);
}
return $attributeQb;
} | php | public function attribute(AttributeInterface $attribute, $enforceFamilyCondition = true)
{
$attributeQb = new AttributeQueryBuilder($this, $attribute, $enforceFamilyCondition);
if ($this->context) {
$attributeQb->setContext($this->context);
}
return $attributeQb;
} | [
"public",
"function",
"attribute",
"(",
"AttributeInterface",
"$",
"attribute",
",",
"$",
"enforceFamilyCondition",
"=",
"true",
")",
"{",
"$",
"attributeQb",
"=",
"new",
"AttributeQueryBuilder",
"(",
"$",
"this",
",",
"$",
"attribute",
",",
"$",
"enforceFamilyC... | @param AttributeInterface $attribute
@param bool $enforceFamilyCondition
@return AttributeQueryBuilderInterface | [
"@param",
"AttributeInterface",
"$attribute",
"@param",
"bool",
"$enforceFamilyCondition"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVQueryBuilder.php#L67-L75 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVQueryBuilder.php | EAVQueryBuilder.addOrderBy | public function addOrderBy(AttributeQueryBuilderInterface $attributeQueryBuilder, $direction = null)
{
$this->queryBuilder->addOrderBy($attributeQueryBuilder->applyJoin()->getColumn(), $direction);
return $this;
} | php | public function addOrderBy(AttributeQueryBuilderInterface $attributeQueryBuilder, $direction = null)
{
$this->queryBuilder->addOrderBy($attributeQueryBuilder->applyJoin()->getColumn(), $direction);
return $this;
} | [
"public",
"function",
"addOrderBy",
"(",
"AttributeQueryBuilderInterface",
"$",
"attributeQueryBuilder",
",",
"$",
"direction",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"queryBuilder",
"->",
"addOrderBy",
"(",
"$",
"attributeQueryBuilder",
"->",
"applyJoin",
"(",
... | @param AttributeQueryBuilderInterface $attributeQueryBuilder
@param string $direction
@return EAVQueryBuilder | [
"@param",
"AttributeQueryBuilderInterface",
"$attributeQueryBuilder",
"@param",
"string",
"$direction"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVQueryBuilder.php#L109-L114 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVQueryBuilder.php | EAVQueryBuilder.apply | public function apply(DQLHandlerInterface $DQLHandler)
{
$this->isApplied = true;
$qb = $this->getQueryBuilder();
if ($DQLHandler->getDQL()) {
$qb->andWhere($DQLHandler->getDQL());
}
foreach ($DQLHandler->getParameters() as $key => $value) {
$qb->setParameter($key, $value);
}
return $qb;
} | php | public function apply(DQLHandlerInterface $DQLHandler)
{
$this->isApplied = true;
$qb = $this->getQueryBuilder();
if ($DQLHandler->getDQL()) {
$qb->andWhere($DQLHandler->getDQL());
}
foreach ($DQLHandler->getParameters() as $key => $value) {
$qb->setParameter($key, $value);
}
return $qb;
} | [
"public",
"function",
"apply",
"(",
"DQLHandlerInterface",
"$",
"DQLHandler",
")",
"{",
"$",
"this",
"->",
"isApplied",
"=",
"true",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"getQueryBuilder",
"(",
")",
";",
"if",
"(",
"$",
"DQLHandler",
"->",
"getDQL",
... | @param DQLHandlerInterface $DQLHandler
@return QueryBuilder | [
"@param",
"DQLHandlerInterface",
"$DQLHandler"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVQueryBuilder.php#L121-L136 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVQueryBuilder.php | EAVQueryBuilder.getStatement | protected function getStatement($glue, array $dqlHandlers)
{
if ($this->isApplied) {
throw new \LogicException('Query was already applied to query builder');
}
$dqlStatement = [];
$parameters = [];
foreach ($dqlHandlers as $dqlHandler) {
if (!$dqlHandler instanceof DQLHandlerInterface) {
throw new \UnexpectedValueException('$dqlHandlers parameters must be an array of DQLHandlerInterface');
}
$dqlStatement[] = '('.$dqlHandler->getDQL().')';
foreach ($dqlHandler->getParameters() as $key => $value) {
$parameters[$key] = $value;
}
}
return new DQLHandler(implode($glue, $dqlStatement), $parameters);
} | php | protected function getStatement($glue, array $dqlHandlers)
{
if ($this->isApplied) {
throw new \LogicException('Query was already applied to query builder');
}
$dqlStatement = [];
$parameters = [];
foreach ($dqlHandlers as $dqlHandler) {
if (!$dqlHandler instanceof DQLHandlerInterface) {
throw new \UnexpectedValueException('$dqlHandlers parameters must be an array of DQLHandlerInterface');
}
$dqlStatement[] = '('.$dqlHandler->getDQL().')';
foreach ($dqlHandler->getParameters() as $key => $value) {
$parameters[$key] = $value;
}
}
return new DQLHandler(implode($glue, $dqlStatement), $parameters);
} | [
"protected",
"function",
"getStatement",
"(",
"$",
"glue",
",",
"array",
"$",
"dqlHandlers",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isApplied",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Query was already applied to query builder'",
")",
";",
"... | @param string $glue
@param DQLHandlerInterface[] $dqlHandlers
@throws \LogicException
@throws \UnexpectedValueException
@return DQLHandlerInterface | [
"@param",
"string",
"$glue",
"@param",
"DQLHandlerInterface",
"[]",
"$dqlHandlers"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVQueryBuilder.php#L155-L174 |
VincentChalnot/SidusEAVModelBundle | Command/PurgeOrphanDataCommand.php | PurgeOrphanDataCommand.initialize | protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->familyRegistry = $this->getContainer()->get(FamilyRegistry::class);
$this->entityManager = $this->getContainer()->get('sidus_eav_model.entity_manager');
$this->dataClass = $this->getContainer()->getParameter('sidus_eav_model.entity.data.class');
$this->valueClass = $this->getContainer()->getParameter('sidus_eav_model.entity.value.class');
} | php | protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->familyRegistry = $this->getContainer()->get(FamilyRegistry::class);
$this->entityManager = $this->getContainer()->get('sidus_eav_model.entity_manager');
$this->dataClass = $this->getContainer()->getParameter('sidus_eav_model.entity.data.class');
$this->valueClass = $this->getContainer()->getParameter('sidus_eav_model.entity.value.class');
} | [
"protected",
"function",
"initialize",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"familyRegistry",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"FamilyRegistry",
"::",
"cla... | @param InputInterface $input
@param OutputInterface $output
@throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
@throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
@throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
@throws \LogicException | [
"@param",
"InputInterface",
"$input",
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/PurgeOrphanDataCommand.php#L58-L64 |
VincentChalnot/SidusEAVModelBundle | Command/PurgeOrphanDataCommand.php | PurgeOrphanDataCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->purgeMissingFamilies($output);
$this->purgeMissingAttributes($output);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->purgeMissingFamilies($output);
$this->purgeMissingAttributes($output);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"purgeMissingFamilies",
"(",
"$",
"output",
")",
";",
"$",
"this",
"->",
"purgeMissingAttributes",
"(",
"$",
"output",
... | @param InputInterface $input
@param OutputInterface $output
@throws \Exception
@return int|null|void | [
"@param",
"InputInterface",
"$input",
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/PurgeOrphanDataCommand.php#L74-L78 |
VincentChalnot/SidusEAVModelBundle | Command/PurgeOrphanDataCommand.php | PurgeOrphanDataCommand.purgeMissingFamilies | protected function purgeMissingFamilies(OutputInterface $output)
{
$metadata = $this->entityManager->getClassMetadata($this->dataClass);
$table = $metadata->getTableName();
$flattenedFamilyCodes = $this->quoteArray($this->familyRegistry->getFamilyCodes());
// LIMIT is not natively supported for delete statements in Doctrine
$sql = "DELETE FROM `{$table}` WHERE family_code NOT IN ({$flattenedFamilyCodes}) LIMIT 1000";
$count = $this->executeWithPaging($sql);
if ($count) {
$output->writeln("<comment>{$count} data purged with missing family</comment>");
} else {
$output->writeln('<info>No data to purge</info>');
}
} | php | protected function purgeMissingFamilies(OutputInterface $output)
{
$metadata = $this->entityManager->getClassMetadata($this->dataClass);
$table = $metadata->getTableName();
$flattenedFamilyCodes = $this->quoteArray($this->familyRegistry->getFamilyCodes());
// LIMIT is not natively supported for delete statements in Doctrine
$sql = "DELETE FROM `{$table}` WHERE family_code NOT IN ({$flattenedFamilyCodes}) LIMIT 1000";
$count = $this->executeWithPaging($sql);
if ($count) {
$output->writeln("<comment>{$count} data purged with missing family</comment>");
} else {
$output->writeln('<info>No data to purge</info>');
}
} | [
"protected",
"function",
"purgeMissingFamilies",
"(",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getClassMetadata",
"(",
"$",
"this",
"->",
"dataClass",
")",
";",
"$",
"table",
"=",
"$",
"meta... | @param OutputInterface $output
@throws \UnexpectedValueException
@throws \RuntimeException
@throws \InvalidArgumentException
@throws \Doctrine\DBAL\DBALException | [
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/PurgeOrphanDataCommand.php#L88-L104 |
VincentChalnot/SidusEAVModelBundle | Command/PurgeOrphanDataCommand.php | PurgeOrphanDataCommand.purgeMissingAttributes | protected function purgeMissingAttributes(OutputInterface $output)
{
$metadata = $this->entityManager->getClassMetadata($this->valueClass);
$table = $metadata->getTableName();
foreach ($this->familyRegistry->getFamilies() as $family) {
$attributeCodes = [];
foreach ($family->getAttributes() as $attribute) {
$attributeCodes[] = $attribute->getCode();
}
$quotedFamilyCode = $this->entityManager->getConnection()->quote($family->getCode());
$flattenedAttributeCodes = $this->quoteArray($attributeCodes);
// LIMIT is not natively supported for delete statements in Doctrine
$sql = "DELETE FROM `{$table}` WHERE family_code = {$quotedFamilyCode} AND attribute_code NOT IN ({$flattenedAttributeCodes}) LIMIT 1000";
$count = $this->executeWithPaging($sql);
if ($count) {
$output->writeln(
"<comment>{$count} values purged in family {$family->getCode()} with missing attributes</comment>"
);
} else {
$output->writeln("<info>No values to purge for family {$family->getCode()}</info>");
}
}
} | php | protected function purgeMissingAttributes(OutputInterface $output)
{
$metadata = $this->entityManager->getClassMetadata($this->valueClass);
$table = $metadata->getTableName();
foreach ($this->familyRegistry->getFamilies() as $family) {
$attributeCodes = [];
foreach ($family->getAttributes() as $attribute) {
$attributeCodes[] = $attribute->getCode();
}
$quotedFamilyCode = $this->entityManager->getConnection()->quote($family->getCode());
$flattenedAttributeCodes = $this->quoteArray($attributeCodes);
// LIMIT is not natively supported for delete statements in Doctrine
$sql = "DELETE FROM `{$table}` WHERE family_code = {$quotedFamilyCode} AND attribute_code NOT IN ({$flattenedAttributeCodes}) LIMIT 1000";
$count = $this->executeWithPaging($sql);
if ($count) {
$output->writeln(
"<comment>{$count} values purged in family {$family->getCode()} with missing attributes</comment>"
);
} else {
$output->writeln("<info>No values to purge for family {$family->getCode()}</info>");
}
}
} | [
"protected",
"function",
"purgeMissingAttributes",
"(",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getClassMetadata",
"(",
"$",
"this",
"->",
"valueClass",
")",
";",
"$",
"table",
"=",
"$",
"m... | @param OutputInterface $output
@throws \UnexpectedValueException
@throws \RuntimeException
@throws \InvalidArgumentException
@throws \Doctrine\DBAL\DBALException | [
"@param",
"OutputInterface",
"$output"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/PurgeOrphanDataCommand.php#L114-L141 |
VincentChalnot/SidusEAVModelBundle | Command/PurgeOrphanDataCommand.php | PurgeOrphanDataCommand.executeWithPaging | protected function executeWithPaging($sql)
{
$count = 0;
do {
$stmt = $this->entityManager->getConnection()->executeQuery($sql);
$stmt->execute();
$lastCount = $stmt->rowCount();
$count += $lastCount;
} while ($lastCount > 0);
return $count;
} | php | protected function executeWithPaging($sql)
{
$count = 0;
do {
$stmt = $this->entityManager->getConnection()->executeQuery($sql);
$stmt->execute();
$lastCount = $stmt->rowCount();
$count += $lastCount;
} while ($lastCount > 0);
return $count;
} | [
"protected",
"function",
"executeWithPaging",
"(",
"$",
"sql",
")",
"{",
"$",
"count",
"=",
"0",
";",
"do",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getConnection",
"(",
")",
"->",
"executeQuery",
"(",
"$",
"sql",
")",
";",
"... | @param string $sql
@throws \Doctrine\DBAL\DBALException
@return int | [
"@param",
"string",
"$sql"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/PurgeOrphanDataCommand.php#L150-L161 |
VincentChalnot/SidusEAVModelBundle | Command/PurgeOrphanDataCommand.php | PurgeOrphanDataCommand.quoteArray | protected function quoteArray(array $array)
{
array_walk(
$array,
function (&$value) {
$value = $this->entityManager->getConnection()->quote($value);
}
);
return implode(', ', $array);
} | php | protected function quoteArray(array $array)
{
array_walk(
$array,
function (&$value) {
$value = $this->entityManager->getConnection()->quote($value);
}
);
return implode(', ', $array);
} | [
"protected",
"function",
"quoteArray",
"(",
"array",
"$",
"array",
")",
"{",
"array_walk",
"(",
"$",
"array",
",",
"function",
"(",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getConnection",
"(",
")",
"->... | Quote a PHP array to allow using it in native SQL query
@param array $array
@return string | [
"Quote",
"a",
"PHP",
"array",
"to",
"allow",
"using",
"it",
"in",
"native",
"SQL",
"query"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Command/PurgeOrphanDataCommand.php#L170-L180 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.addAttribute | public function addAttribute(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$resolver = new OptionsResolver();
$this->configureOptions($attribute, $resolver);
$options = $resolver->resolve($options);
if ($options['hidden']) {
return;
}
$builder = $this->resolveBuilder($builder, $attribute, $options);
// The 'multiple' option triggers the usage of the Collection form type
if ($options['multiple']) {
// This means that a specific attribute can be a collection of data but might NOT be "multiple" in a sense
// that it will not be edited as a "collection" form type.
// Be wary of the vocabulary here
$this->addMultipleAttribute($builder, $attribute, $options);
} else {
$this->addSingleAttribute($builder, $attribute, $options);
}
} | php | public function addAttribute(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$resolver = new OptionsResolver();
$this->configureOptions($attribute, $resolver);
$options = $resolver->resolve($options);
if ($options['hidden']) {
return;
}
$builder = $this->resolveBuilder($builder, $attribute, $options);
// The 'multiple' option triggers the usage of the Collection form type
if ($options['multiple']) {
// This means that a specific attribute can be a collection of data but might NOT be "multiple" in a sense
// that it will not be edited as a "collection" form type.
// Be wary of the vocabulary here
$this->addMultipleAttribute($builder, $attribute, $options);
} else {
$this->addSingleAttribute($builder, $attribute, $options);
}
} | [
"public",
"function",
"addAttribute",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"this",... | @param FormBuilderInterface $builder
@param AttributeInterface $attribute
@param array $options
@throws \Exception | [
"@param",
"FormBuilderInterface",
"$builder",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L50-L74 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.resolveBuilder | protected function resolveBuilder(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$group = $attribute->getGroup();
if (null === $group || $options['ignore_group']) {
return $builder;
}
$groupPath = explode('.', $group);
$subBuilder = $builder;
foreach ($groupPath as $level => $groupCode) {
$subBuilder = $this->buildFieldset($subBuilder, $attribute, $groupPath, $level, $options);
}
return $subBuilder;
} | php | protected function resolveBuilder(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$group = $attribute->getGroup();
if (null === $group || $options['ignore_group']) {
return $builder;
}
$groupPath = explode('.', $group);
$subBuilder = $builder;
foreach ($groupPath as $level => $groupCode) {
$subBuilder = $this->buildFieldset($subBuilder, $attribute, $groupPath, $level, $options);
}
return $subBuilder;
} | [
"protected",
"function",
"resolveBuilder",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"group",
"=",
"$",
"attribute",
"->",
"getGroup",
"(",
")",
";",
... | @param FormBuilderInterface $builder
@param AttributeInterface $attribute
@param array $options
@throws \Symfony\Component\Form\Exception\InvalidArgumentException
@throws \InvalidArgumentException
@return FormBuilderInterface | [
"@param",
"FormBuilderInterface",
"$builder",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L86-L104 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.buildFieldset | protected function buildFieldset(
FormBuilderInterface $parentBuilder,
AttributeInterface $attribute,
array $groupPath,
$level,
array $options = []
) {
$fieldsetCode = '__'.$groupPath[$level];
if ($parentBuilder->has($fieldsetCode)) {
return $parentBuilder->get($fieldsetCode);
}
$fieldsetOptions = [
'label' => $this->getGroupLabel($attribute->getFamily(), $groupPath, $level),
'inherit_data' => true,
];
$fieldsetPath = $this->getFieldsetPath($groupPath, $level);
if (isset($options['fieldset_options'][$fieldsetPath])) {
$fieldsetOptions = array_merge($fieldsetOptions, $options['fieldset_options'][$fieldsetPath]);
}
$parentBuilder->add($fieldsetCode, FormType::class, $fieldsetOptions);
return $parentBuilder->get($fieldsetCode);
} | php | protected function buildFieldset(
FormBuilderInterface $parentBuilder,
AttributeInterface $attribute,
array $groupPath,
$level,
array $options = []
) {
$fieldsetCode = '__'.$groupPath[$level];
if ($parentBuilder->has($fieldsetCode)) {
return $parentBuilder->get($fieldsetCode);
}
$fieldsetOptions = [
'label' => $this->getGroupLabel($attribute->getFamily(), $groupPath, $level),
'inherit_data' => true,
];
$fieldsetPath = $this->getFieldsetPath($groupPath, $level);
if (isset($options['fieldset_options'][$fieldsetPath])) {
$fieldsetOptions = array_merge($fieldsetOptions, $options['fieldset_options'][$fieldsetPath]);
}
$parentBuilder->add($fieldsetCode, FormType::class, $fieldsetOptions);
return $parentBuilder->get($fieldsetCode);
} | [
"protected",
"function",
"buildFieldset",
"(",
"FormBuilderInterface",
"$",
"parentBuilder",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"groupPath",
",",
"$",
"level",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"fieldsetCo... | @param FormBuilderInterface $parentBuilder
@param AttributeInterface $attribute
@param array $groupPath
@param int $level
@param array $options
@throws \Symfony\Component\Form\Exception\InvalidArgumentException
@throws \InvalidArgumentException
@return FormBuilderInterface | [
"@param",
"FormBuilderInterface",
"$parentBuilder",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$groupPath",
"@param",
"int",
"$level",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L118-L143 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.getGroupLabel | protected function getGroupLabel(FamilyInterface $family, array $groupPath, $level)
{
$fallBack = isset($groupPath[$level]) ? $groupPath[$level] : null;
$fieldsetPath = $this->getFieldsetPath($groupPath, $level);
$transKeys = [
"eav.family.{$family->getCode()}.group.{$fieldsetPath}.label",
"eav.group.{$fieldsetPath}.label",
];
return ucfirst($this->tryTranslate($transKeys, [], $fallBack));
} | php | protected function getGroupLabel(FamilyInterface $family, array $groupPath, $level)
{
$fallBack = isset($groupPath[$level]) ? $groupPath[$level] : null;
$fieldsetPath = $this->getFieldsetPath($groupPath, $level);
$transKeys = [
"eav.family.{$family->getCode()}.group.{$fieldsetPath}.label",
"eav.group.{$fieldsetPath}.label",
];
return ucfirst($this->tryTranslate($transKeys, [], $fallBack));
} | [
"protected",
"function",
"getGroupLabel",
"(",
"FamilyInterface",
"$",
"family",
",",
"array",
"$",
"groupPath",
",",
"$",
"level",
")",
"{",
"$",
"fallBack",
"=",
"isset",
"(",
"$",
"groupPath",
"[",
"$",
"level",
"]",
")",
"?",
"$",
"groupPath",
"[",
... | Use label from formOptions or use translation or automatically create human readable one
@param FamilyInterface $family
@param array $groupPath
@param int $level
@throws \InvalidArgumentException
@return string | [
"Use",
"label",
"from",
"formOptions",
"or",
"use",
"translation",
"or",
"automatically",
"create",
"human",
"readable",
"one"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L156-L166 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.addSingleAttribute | protected function addSingleAttribute(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$formOptions = $options['form_options'];
unset($formOptions['collection_options']); // Ignoring collection_options if set
$builder->add($attribute->getCode(), $options['form_type'], $formOptions);
} | php | protected function addSingleAttribute(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$formOptions = $options['form_options'];
unset($formOptions['collection_options']); // Ignoring collection_options if set
$builder->add($attribute->getCode(), $options['form_type'], $formOptions);
} | [
"protected",
"function",
"addSingleAttribute",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"formOptions",
"=",
"$",
"options",
"[",
"'form_options'",
"]",
... | @param FormBuilderInterface $builder
@param AttributeInterface $attribute
@param array $options
@throws \Exception | [
"@param",
"FormBuilderInterface",
"$builder",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L175-L184 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.addMultipleAttribute | protected function addMultipleAttribute(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$formOptions = $options['form_options'];
$disabled = array_key_exists('disabled', $formOptions) ? !$formOptions['disabled'] : true;
$label = $formOptions['label']; // Keeping configured label
$formOptions['label'] = false; // Removing label from entry_options
$collectionOptions = [
'label' => $label,
'translation_domain' => $formOptions['translation_domain'],
'translate_label' => $formOptions['translate_label'],
'entry_type' => $options['form_type'],
'entry_options' => $formOptions,
'allow_add' => $disabled,
'allow_delete' => $disabled,
'required' => $formOptions['required'],
'prototype_name' => '__'.$attribute->getCode().'__',
];
if (!empty($formOptions['collection_options'])) {
$collectionOptions = array_merge($collectionOptions, $formOptions['collection_options']);
}
unset($collectionOptions['entry_options']['collection_options']);
$builder->add($attribute->getCode(), $options['collection_type'], $collectionOptions);
} | php | protected function addMultipleAttribute(
FormBuilderInterface $builder,
AttributeInterface $attribute,
array $options = []
) {
$formOptions = $options['form_options'];
$disabled = array_key_exists('disabled', $formOptions) ? !$formOptions['disabled'] : true;
$label = $formOptions['label']; // Keeping configured label
$formOptions['label'] = false; // Removing label from entry_options
$collectionOptions = [
'label' => $label,
'translation_domain' => $formOptions['translation_domain'],
'translate_label' => $formOptions['translate_label'],
'entry_type' => $options['form_type'],
'entry_options' => $formOptions,
'allow_add' => $disabled,
'allow_delete' => $disabled,
'required' => $formOptions['required'],
'prototype_name' => '__'.$attribute->getCode().'__',
];
if (!empty($formOptions['collection_options'])) {
$collectionOptions = array_merge($collectionOptions, $formOptions['collection_options']);
}
unset($collectionOptions['entry_options']['collection_options']);
$builder->add($attribute->getCode(), $options['collection_type'], $collectionOptions);
} | [
"protected",
"function",
"addMultipleAttribute",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"formOptions",
"=",
"$",
"options",
"[",
"'form_options'",
"]",... | @param FormBuilderInterface $builder
@param AttributeInterface $attribute
@param array $options
@throws \Exception | [
"@param",
"FormBuilderInterface",
"$builder",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L193-L220 |
VincentChalnot/SidusEAVModelBundle | Form/AttributeFormBuilder.php | AttributeFormBuilder.configureOptions | protected function configureOptions(AttributeInterface $attribute, OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'label' => null,
'form_type' => $attribute->getFormType(),
'hidden' => $attribute->getOption('hidden', false),
'merge_form_options' => true,
'multiple' => $attribute->isMultiple(),
'form_options' => [],
'validation_rules' => null,
'collection_type' => $this->collectionType,
'ignore_group' => false,
'fieldset_options' => [],
]
);
$resolver->setAllowedTypes('label', ['NULL', 'string']);
$resolver->setAllowedTypes('form_type', ['string']);
$resolver->setAllowedTypes('hidden', ['boolean']);
$resolver->setAllowedTypes('merge_form_options', ['boolean']);
$resolver->setAllowedTypes('multiple', ['boolean']);
$resolver->setAllowedTypes('form_options', ['array']);
$resolver->setAllowedTypes('validation_rules', ['NULL', 'array']);
$resolver->setAllowedTypes('collection_type', ['string']);
$resolver->setAllowedTypes('ignore_group', ['boolean']);
$resolver->setAllowedTypes('fieldset_options', ['array']);
$resolver->setNormalizer(
'form_options',
function (Options $options, $value) use ($attribute) {
$formOptions = $value;
if ($options['merge_form_options']) {
$formOptions = array_merge($attribute->getFormOptions(), $value);
}
// If set, override constraints by configured validation rules
if (null !== $options['validation_rules']) {
$formOptions['constraints'] = $this->parseValidationRules($options['validation_rules']);
}
$label = array_key_exists('label', $formOptions) ? $formOptions['label'] : null;
$defaultOptions = [
'label' => $label ?: ucfirst($attribute),
'translation_domain' => null,
'translate_label' => null !== $label,
'required' => $attribute->isRequired(),
];
return array_merge($defaultOptions, $formOptions);
}
);
$resolver->setNormalizer(
'label',
function (Options $options, $value) use ($attribute) {
if (null === $value) {
return ucfirst($attribute);
}
return $value;
}
);
} | php | protected function configureOptions(AttributeInterface $attribute, OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'label' => null,
'form_type' => $attribute->getFormType(),
'hidden' => $attribute->getOption('hidden', false),
'merge_form_options' => true,
'multiple' => $attribute->isMultiple(),
'form_options' => [],
'validation_rules' => null,
'collection_type' => $this->collectionType,
'ignore_group' => false,
'fieldset_options' => [],
]
);
$resolver->setAllowedTypes('label', ['NULL', 'string']);
$resolver->setAllowedTypes('form_type', ['string']);
$resolver->setAllowedTypes('hidden', ['boolean']);
$resolver->setAllowedTypes('merge_form_options', ['boolean']);
$resolver->setAllowedTypes('multiple', ['boolean']);
$resolver->setAllowedTypes('form_options', ['array']);
$resolver->setAllowedTypes('validation_rules', ['NULL', 'array']);
$resolver->setAllowedTypes('collection_type', ['string']);
$resolver->setAllowedTypes('ignore_group', ['boolean']);
$resolver->setAllowedTypes('fieldset_options', ['array']);
$resolver->setNormalizer(
'form_options',
function (Options $options, $value) use ($attribute) {
$formOptions = $value;
if ($options['merge_form_options']) {
$formOptions = array_merge($attribute->getFormOptions(), $value);
}
// If set, override constraints by configured validation rules
if (null !== $options['validation_rules']) {
$formOptions['constraints'] = $this->parseValidationRules($options['validation_rules']);
}
$label = array_key_exists('label', $formOptions) ? $formOptions['label'] : null;
$defaultOptions = [
'label' => $label ?: ucfirst($attribute),
'translation_domain' => null,
'translate_label' => null !== $label,
'required' => $attribute->isRequired(),
];
return array_merge($defaultOptions, $formOptions);
}
);
$resolver->setNormalizer(
'label',
function (Options $options, $value) use ($attribute) {
if (null === $value) {
return ucfirst($attribute);
}
return $value;
}
);
} | [
"protected",
"function",
"configureOptions",
"(",
"AttributeInterface",
"$",
"attribute",
",",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'label'",
"=>",
"null",
",",
"'form_type'",
"=>",
"$",
"attribute",
"->"... | @param AttributeInterface $attribute
@param OptionsResolver $resolver
@throws \Symfony\Component\OptionsResolver\Exception\AccessException
@throws \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
@throws \Symfony\Component\Validator\Exception\MappingException
@throws \UnexpectedValueException | [
"@param",
"AttributeInterface",
"$attribute",
"@param",
"OptionsResolver",
"$resolver"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/AttributeFormBuilder.php#L231-L292 |
VincentChalnot/SidusEAVModelBundle | Request/ParamConverter/FamilyParamConverter.php | FamilyParamConverter.apply | public function apply(Request $request, ParamConverter $configuration)
{
$originalName = $configuration->getName();
if ($request->attributes->has('familyCode')) {
$configuration->setName('familyCode');
}
if (!parent::apply($request, $configuration)) {
return false;
}
if ($originalName !== $configuration->getName()) {
$request->attributes->set($originalName, $request->attributes->get($configuration->getName()));
}
return true;
} | php | public function apply(Request $request, ParamConverter $configuration)
{
$originalName = $configuration->getName();
if ($request->attributes->has('familyCode')) {
$configuration->setName('familyCode');
}
if (!parent::apply($request, $configuration)) {
return false;
}
if ($originalName !== $configuration->getName()) {
$request->attributes->set($originalName, $request->attributes->get($configuration->getName()));
}
return true;
} | [
"public",
"function",
"apply",
"(",
"Request",
"$",
"request",
",",
"ParamConverter",
"$",
"configuration",
")",
"{",
"$",
"originalName",
"=",
"$",
"configuration",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"attributes",
"->",
"has"... | Stores the object in the request.
@param Request $request The request
@param ParamConverter $configuration Contains the name, class and options of the object
@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@throws \InvalidArgumentException
@return bool True if the object has been successfully set, else false | [
"Stores",
"the",
"object",
"in",
"the",
"request",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Request/ParamConverter/FamilyParamConverter.php#L49-L63 |
VincentChalnot/SidusEAVModelBundle | Form/Type/DataType.php | DataType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->buildValuesForm($builder, $options);
$this->buildDataForm($builder, $options);
$builder->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) {
$data = $event->getData();
if ($data instanceof DataInterface) {
$data->setUpdatedAt(new \DateTime());
}
}
);
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->buildValuesForm($builder, $options);
$this->buildDataForm($builder, $options);
$builder->addEventListener(
FormEvents::POST_SUBMIT,
function (FormEvent $event) {
$data = $event->getData();
if ($data instanceof DataInterface) {
$data->setUpdatedAt(new \DateTime());
}
}
);
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"buildValuesForm",
"(",
"$",
"builder",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"buildDataForm",
"(",
"$",
... | @param FormBuilderInterface $builder
@param array $options
@throws \Exception | [
"@param",
"FormBuilderInterface",
"$builder",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/Type/DataType.php#L68-L82 |
VincentChalnot/SidusEAVModelBundle | Form/Type/DataType.php | DataType.buildValuesForm | public function buildValuesForm(FormBuilderInterface $builder, array $options = [])
{
/** @var FamilyInterface $family */
$family = $options['family'];
$attributes = $family->getAttributes();
if ($options['attributes_config']) {
if (!$options['merge_attributes_config']) {
$attributes = [];
}
foreach (array_keys($options['attributes_config']) as $attributeCode) {
$attributes[$attributeCode] = $family->getAttribute($attributeCode);
}
}
foreach ($attributes as $attribute) {
$this->attributeFormBuilder->addAttribute(
$builder,
$attribute,
$this->resolveAttributeConfig($attribute, $options)
);
}
} | php | public function buildValuesForm(FormBuilderInterface $builder, array $options = [])
{
/** @var FamilyInterface $family */
$family = $options['family'];
$attributes = $family->getAttributes();
if ($options['attributes_config']) {
if (!$options['merge_attributes_config']) {
$attributes = [];
}
foreach (array_keys($options['attributes_config']) as $attributeCode) {
$attributes[$attributeCode] = $family->getAttribute($attributeCode);
}
}
foreach ($attributes as $attribute) {
$this->attributeFormBuilder->addAttribute(
$builder,
$attribute,
$this->resolveAttributeConfig($attribute, $options)
);
}
} | [
"public",
"function",
"buildValuesForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"/** @var FamilyInterface $family */",
"$",
"family",
"=",
"$",
"options",
"[",
"'family'",
"]",
";",
"$",
"attributes",
... | @param FormBuilderInterface $builder
@param array $options
@throws \Exception | [
"@param",
"FormBuilderInterface",
"$builder",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/Type/DataType.php#L102-L124 |
VincentChalnot/SidusEAVModelBundle | Form/Type/DataType.php | DataType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'empty_data' => null,
'data_class' => null,
'attributes_config' => null,
'merge_attributes_config' => false,
'attribute' => null,
'family' => null,
'fieldset_options' => [],
]
);
$resolver->setAllowedTypes('attributes_config', ['NULL', 'array']);
$resolver->setAllowedTypes('merge_attributes_config', ['bool']);
$resolver->setAllowedTypes('attribute', ['NULL', AttributeInterface::class]);
$resolver->setAllowedTypes('family', ['NULL', 'string', FamilyInterface::class]);
$resolver->setAllowedTypes('fieldset_options', ['array']);
$resolver->setNormalizer(
'family',
function (Options $options, $value) {
// If family option is not set, try to fetch the family from the attribute option
if (null === $value) {
/** @var AttributeInterface $attribute */
$attribute = $options['attribute'];
if (!$attribute) {
throw new MissingOptionsException(
"An option is missing: you must set either the 'family' option or the 'attribute' option"
);
}
$allowedFamilies = $attribute->getOption('allowed_families', []);
if (1 !== \count($allowedFamilies)) {
$m = "Can't automatically compute the 'family' option with an attribute with no family allowed";
$m .= " or multiple allowed families, please set the 'family' option manually";
throw new MissingOptionsException($m);
}
$value = reset($allowedFamilies);
}
if ($value instanceof FamilyInterface) {
return $value;
}
return $this->familyRegistry->getFamily($value);
}
);
$resolver->setNormalizer(
'empty_data',
function (Options $options, $value) {
if (null !== $value) {
return $value;
}
/** @var FamilyInterface $family */
$family = $options['family'];
if ($family->isSingleton()) {
/** @var DataRepository $repository */
$repository = $this->repositoryFinder->getRepository($family->getDataClass());
return $repository->getInstance($family);
}
return $family->createData();
}
);
$resolver->setNormalizer(
'data_class',
function (Options $options, $value) {
if (null !== $value) {
$m = "DataType form does not supports the 'data_class' option, it will be automatically resolved";
$m .= ' with the family';
throw new \UnexpectedValueException($m);
}
/** @var FamilyInterface $family */
$family = $options['family'];
return $family->getDataClass();
}
);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'empty_data' => null,
'data_class' => null,
'attributes_config' => null,
'merge_attributes_config' => false,
'attribute' => null,
'family' => null,
'fieldset_options' => [],
]
);
$resolver->setAllowedTypes('attributes_config', ['NULL', 'array']);
$resolver->setAllowedTypes('merge_attributes_config', ['bool']);
$resolver->setAllowedTypes('attribute', ['NULL', AttributeInterface::class]);
$resolver->setAllowedTypes('family', ['NULL', 'string', FamilyInterface::class]);
$resolver->setAllowedTypes('fieldset_options', ['array']);
$resolver->setNormalizer(
'family',
function (Options $options, $value) {
// If family option is not set, try to fetch the family from the attribute option
if (null === $value) {
/** @var AttributeInterface $attribute */
$attribute = $options['attribute'];
if (!$attribute) {
throw new MissingOptionsException(
"An option is missing: you must set either the 'family' option or the 'attribute' option"
);
}
$allowedFamilies = $attribute->getOption('allowed_families', []);
if (1 !== \count($allowedFamilies)) {
$m = "Can't automatically compute the 'family' option with an attribute with no family allowed";
$m .= " or multiple allowed families, please set the 'family' option manually";
throw new MissingOptionsException($m);
}
$value = reset($allowedFamilies);
}
if ($value instanceof FamilyInterface) {
return $value;
}
return $this->familyRegistry->getFamily($value);
}
);
$resolver->setNormalizer(
'empty_data',
function (Options $options, $value) {
if (null !== $value) {
return $value;
}
/** @var FamilyInterface $family */
$family = $options['family'];
if ($family->isSingleton()) {
/** @var DataRepository $repository */
$repository = $this->repositoryFinder->getRepository($family->getDataClass());
return $repository->getInstance($family);
}
return $family->createData();
}
);
$resolver->setNormalizer(
'data_class',
function (Options $options, $value) {
if (null !== $value) {
$m = "DataType form does not supports the 'data_class' option, it will be automatically resolved";
$m .= ' with the family';
throw new \UnexpectedValueException($m);
}
/** @var FamilyInterface $family */
$family = $options['family'];
return $family->getDataClass();
}
);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'empty_data'",
"=>",
"null",
",",
"'data_class'",
"=>",
"null",
",",
"'attributes_config'",
"=>",
"null",
",",
"'merge_a... | @param OptionsResolver $resolver
@throws AccessException
@throws UndefinedOptionsException
@throws MissingFamilyException
@throws \UnexpectedValueException
@throws \Symfony\Component\OptionsResolver\Exception\MissingOptionsException | [
"@param",
"OptionsResolver",
"$resolver"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/Type/DataType.php#L135-L216 |
VincentChalnot/SidusEAVModelBundle | Form/Type/DataType.php | DataType.resolveAttributeConfig | protected function resolveAttributeConfig(AttributeInterface $attribute, array $options)
{
$attributeConfig = [];
if (array_key_exists('fieldset_options', $options)) {
$attributeConfig['fieldset_options'] = $options['fieldset_options']; // Copy all fieldset options
}
if (isset($options['attributes_config'][$attribute->getCode()])) {
return array_merge($attributeConfig, $options['attributes_config'][$attribute->getCode()]);
}
return array_merge($attributeConfig, $attribute->getOption('attribute_config', []));
} | php | protected function resolveAttributeConfig(AttributeInterface $attribute, array $options)
{
$attributeConfig = [];
if (array_key_exists('fieldset_options', $options)) {
$attributeConfig['fieldset_options'] = $options['fieldset_options']; // Copy all fieldset options
}
if (isset($options['attributes_config'][$attribute->getCode()])) {
return array_merge($attributeConfig, $options['attributes_config'][$attribute->getCode()]);
}
return array_merge($attributeConfig, $attribute->getOption('attribute_config', []));
} | [
"protected",
"function",
"resolveAttributeConfig",
"(",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"options",
")",
"{",
"$",
"attributeConfig",
"=",
"[",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'fieldset_options'",
",",
"$",
"options",
")"... | @param AttributeInterface $attribute
@param array $options
@return array | [
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$options"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/Type/DataType.php#L232-L243 |
VincentChalnot/SidusEAVModelBundle | DependencyInjection/SidusEAVModelExtension.php | SidusEAVModelExtension.load | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->globalConfig = $config;
$container->setParameter('sidus_eav_model.entity.data.class', $config['data_class']);
$container->setParameter('sidus_eav_model.entity.value.class', $config['value_class']);
$container->setParameter('sidus_eav_model.form.collection_type', $config['collection_type']);
$container->setParameter('sidus_eav_model.context.form_type', $config['context_form_type']);
$container->setParameter('sidus_eav_model.context.default_context', $config['default_context']);
$container->setParameter('sidus_eav_model.context.global_mask', $config['global_context_mask']);
// Injecting custom doctrine type
$doctrineTypes = $container->getParameter('doctrine.dbal.connection_factory.types');
$doctrineTypes['sidus_family'] = ['class' => FamilyType::class, 'commented' => true];
$container->setParameter('doctrine.dbal.connection_factory.types', $doctrineTypes);
// Load services config
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/services'));
$loader->load('attribute_types.yml');
$loader->load('configuration.yml');
$loader->load('context.yml');
$loader->load('debug.yml');
$loader->load('deprecated.yml');
$loader->load('doctrine.yml');
$loader->load('entities.yml');
$loader->load('events.yml');
$loader->load('forms.yml');
$loader->load('manager.yml');
$loader->load('param_converters.yml');
$loader->load('twig.yml');
$loader->load('validators.yml');
if ($config['serializer_enabled']) {
// Only load normalizers if symfony serializer is loaded
$loader->load('serializer.yml');
$loader->load('normalizer.yml');
$loader->load('denormalizer.yml');
$loader->load('deprecated_serializer.yml');
}
// The DatagridBundle might be installed
/** @noinspection PhpUndefinedClassInspection */
if (interface_exists(RenderableInterface::class)) {
$loader->load('datagrid.yml');
}
/** @noinspection PhpUndefinedClassInspection */
if (interface_exists(ColumnValueRendererInterface::class)) {
$loader->load('datagrid-v2.yml');
}
// Add global attribute configuration to handler
$attributeConfiguration = $container->getDefinition(AttributeRegistry::class);
$attributeConfiguration->addMethodCall('parseGlobalConfig', [$config['attributes']]);
$this->createFamilyServices($config, $container);
} | php | public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->globalConfig = $config;
$container->setParameter('sidus_eav_model.entity.data.class', $config['data_class']);
$container->setParameter('sidus_eav_model.entity.value.class', $config['value_class']);
$container->setParameter('sidus_eav_model.form.collection_type', $config['collection_type']);
$container->setParameter('sidus_eav_model.context.form_type', $config['context_form_type']);
$container->setParameter('sidus_eav_model.context.default_context', $config['default_context']);
$container->setParameter('sidus_eav_model.context.global_mask', $config['global_context_mask']);
// Injecting custom doctrine type
$doctrineTypes = $container->getParameter('doctrine.dbal.connection_factory.types');
$doctrineTypes['sidus_family'] = ['class' => FamilyType::class, 'commented' => true];
$container->setParameter('doctrine.dbal.connection_factory.types', $doctrineTypes);
// Load services config
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/services'));
$loader->load('attribute_types.yml');
$loader->load('configuration.yml');
$loader->load('context.yml');
$loader->load('debug.yml');
$loader->load('deprecated.yml');
$loader->load('doctrine.yml');
$loader->load('entities.yml');
$loader->load('events.yml');
$loader->load('forms.yml');
$loader->load('manager.yml');
$loader->load('param_converters.yml');
$loader->load('twig.yml');
$loader->load('validators.yml');
if ($config['serializer_enabled']) {
// Only load normalizers if symfony serializer is loaded
$loader->load('serializer.yml');
$loader->load('normalizer.yml');
$loader->load('denormalizer.yml');
$loader->load('deprecated_serializer.yml');
}
// The DatagridBundle might be installed
/** @noinspection PhpUndefinedClassInspection */
if (interface_exists(RenderableInterface::class)) {
$loader->load('datagrid.yml');
}
/** @noinspection PhpUndefinedClassInspection */
if (interface_exists(ColumnValueRendererInterface::class)) {
$loader->load('datagrid-v2.yml');
}
// Add global attribute configuration to handler
$attributeConfiguration = $container->getDefinition(AttributeRegistry::class);
$attributeConfiguration->addMethodCall('parseGlobalConfig', [$config['attributes']]);
$this->createFamilyServices($config, $container);
} | [
"public",
"function",
"load",
"(",
"array",
"$",
"configs",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"configuration",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"processConfiguration",
"(",
"$",
"con... | Generate automatically services for attributes and families from configuration
@param array $configs
@param ContainerBuilder $container
@throws \Exception | [
"Generate",
"automatically",
"services",
"for",
"attributes",
"and",
"families",
"from",
"configuration"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/DependencyInjection/SidusEAVModelExtension.php#L46-L103 |
VincentChalnot/SidusEAVModelBundle | DependencyInjection/SidusEAVModelExtension.php | SidusEAVModelExtension.createFamilyServices | protected function createFamilyServices(array $config, ContainerBuilder $container)
{
// Automatically declare a service for each family configured
foreach ((array) $config['families'] as $code => $familyConfiguration) {
if (empty($familyConfiguration['data_class'])) {
$familyConfiguration['data_class'] = $config['data_class'];
}
if (empty($familyConfiguration['value_class'])) {
$familyConfiguration['value_class'] = $config['value_class'];
}
$this->addFamilyServiceDefinition($code, $familyConfiguration, $container);
}
} | php | protected function createFamilyServices(array $config, ContainerBuilder $container)
{
// Automatically declare a service for each family configured
foreach ((array) $config['families'] as $code => $familyConfiguration) {
if (empty($familyConfiguration['data_class'])) {
$familyConfiguration['data_class'] = $config['data_class'];
}
if (empty($familyConfiguration['value_class'])) {
$familyConfiguration['value_class'] = $config['value_class'];
}
$this->addFamilyServiceDefinition($code, $familyConfiguration, $container);
}
} | [
"protected",
"function",
"createFamilyServices",
"(",
"array",
"$",
"config",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"// Automatically declare a service for each family configured",
"foreach",
"(",
"(",
"array",
")",
"$",
"config",
"[",
"'families'",
"]",
... | @param array $config
@param ContainerBuilder $container
@throws \Exception | [
"@param",
"array",
"$config",
"@param",
"ContainerBuilder",
"$container"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/DependencyInjection/SidusEAVModelExtension.php#L111-L123 |
VincentChalnot/SidusEAVModelBundle | DependencyInjection/SidusEAVModelExtension.php | SidusEAVModelExtension.addFamilyServiceDefinition | protected function addFamilyServiceDefinition($code, $familyConfiguration, ContainerBuilder $container)
{
$definition = new Definition(
$container->getParameter('sidus_eav_model.family.class'),
[
$code,
new Reference(AttributeRegistry::class),
new Reference(FamilyRegistry::class),
new Reference(ContextManagerInterface::class),
$familyConfiguration,
]
);
$definition->addMethodCall('setTranslator', [new Reference('translator')]);
$definition->addTag('sidus.family');
$container->setDefinition('sidus_eav_model.family.'.$code, $definition);
} | php | protected function addFamilyServiceDefinition($code, $familyConfiguration, ContainerBuilder $container)
{
$definition = new Definition(
$container->getParameter('sidus_eav_model.family.class'),
[
$code,
new Reference(AttributeRegistry::class),
new Reference(FamilyRegistry::class),
new Reference(ContextManagerInterface::class),
$familyConfiguration,
]
);
$definition->addMethodCall('setTranslator', [new Reference('translator')]);
$definition->addTag('sidus.family');
$container->setDefinition('sidus_eav_model.family.'.$code, $definition);
} | [
"protected",
"function",
"addFamilyServiceDefinition",
"(",
"$",
"code",
",",
"$",
"familyConfiguration",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"definition",
"=",
"new",
"Definition",
"(",
"$",
"container",
"->",
"getParameter",
"(",
"'sidus_ea... | @param string $code
@param array $familyConfiguration
@param ContainerBuilder $container
@throws BadMethodCallException
@throws InvalidArgumentException | [
"@param",
"string",
"$code",
"@param",
"array",
"$familyConfiguration",
"@param",
"ContainerBuilder",
"$container"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/DependencyInjection/SidusEAVModelExtension.php#L133-L148 |
VincentChalnot/SidusEAVModelBundle | Doctrine/OptimizedDataLoader.php | OptimizedDataLoader.load | public function load($entities, $depth = 1)
{
if (!\is_array($entities) && !$entities instanceof \Traversable) {
throw new \InvalidArgumentException(self::E_MSG);
}
$entitiesByValueClassByIds = $this->sortEntitiesByValueClass($entities);
foreach ($entitiesByValueClassByIds as $valueClass => $entitiesById) {
$this->loadEntityValues($valueClass, $entitiesById);
}
$this->loadRelatedEntities($entities, $depth);
} | php | public function load($entities, $depth = 1)
{
if (!\is_array($entities) && !$entities instanceof \Traversable) {
throw new \InvalidArgumentException(self::E_MSG);
}
$entitiesByValueClassByIds = $this->sortEntitiesByValueClass($entities);
foreach ($entitiesByValueClassByIds as $valueClass => $entitiesById) {
$this->loadEntityValues($valueClass, $entitiesById);
}
$this->loadRelatedEntities($entities, $depth);
} | [
"public",
"function",
"load",
"(",
"$",
"entities",
",",
"$",
"depth",
"=",
"1",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"entities",
")",
"&&",
"!",
"$",
"entities",
"instanceof",
"\\",
"Traversable",
")",
"{",
"throw",
"new",
"\\",
"... | @param DataInterface[] $entities
@param int $depth
@throws \UnexpectedValueException
@throws \InvalidArgumentException | [
"@param",
"DataInterface",
"[]",
"$entities",
"@param",
"int",
"$depth"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/OptimizedDataLoader.php#L49-L61 |
VincentChalnot/SidusEAVModelBundle | Doctrine/OptimizedDataLoader.php | OptimizedDataLoader.sortEntitiesByValueClass | protected function sortEntitiesByValueClass($entities)
{
$entitiesByValueClassByIds = [];
foreach ($entities as $entity) {
if (null === $entity) {
continue;
}
if (!$entity instanceof DataInterface) {
throw new \InvalidArgumentException(self::E_MSG);
}
$entitiesByValueClassByIds[$entity->getFamily()->getValueClass()][$entity->getId()] = $entity;
}
return $entitiesByValueClassByIds;
} | php | protected function sortEntitiesByValueClass($entities)
{
$entitiesByValueClassByIds = [];
foreach ($entities as $entity) {
if (null === $entity) {
continue;
}
if (!$entity instanceof DataInterface) {
throw new \InvalidArgumentException(self::E_MSG);
}
$entitiesByValueClassByIds[$entity->getFamily()->getValueClass()][$entity->getId()] = $entity;
}
return $entitiesByValueClassByIds;
} | [
"protected",
"function",
"sortEntitiesByValueClass",
"(",
"$",
"entities",
")",
"{",
"$",
"entitiesByValueClassByIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"entity",
")",
"{",
... | @param DataInterface[] $entities
@throws \InvalidArgumentException
@return DataInterface[][] | [
"@param",
"DataInterface",
"[]",
"$entities"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/OptimizedDataLoader.php#L82-L96 |
VincentChalnot/SidusEAVModelBundle | Doctrine/OptimizedDataLoader.php | OptimizedDataLoader.loadEntityValues | protected function loadEntityValues($valueClass, array $entitiesById)
{
foreach ($this->getValues($valueClass, $entitiesById) as $valueEntity) {
$data = $valueEntity->getData();
$refl = new \ReflectionClass($data);
$valuesProperty = $refl->getProperty('values');
$valuesProperty->setAccessible(true);
$dataValues = $valuesProperty->getValue($data);
if ($dataValues instanceof PersistentCollection) {
$dataValues->setInitialized(true);
$dataValues->add($valueEntity);
} else {
throw new \UnexpectedValueException('Data.values is not an instance of PersistentCollection');
}
}
} | php | protected function loadEntityValues($valueClass, array $entitiesById)
{
foreach ($this->getValues($valueClass, $entitiesById) as $valueEntity) {
$data = $valueEntity->getData();
$refl = new \ReflectionClass($data);
$valuesProperty = $refl->getProperty('values');
$valuesProperty->setAccessible(true);
$dataValues = $valuesProperty->getValue($data);
if ($dataValues instanceof PersistentCollection) {
$dataValues->setInitialized(true);
$dataValues->add($valueEntity);
} else {
throw new \UnexpectedValueException('Data.values is not an instance of PersistentCollection');
}
}
} | [
"protected",
"function",
"loadEntityValues",
"(",
"$",
"valueClass",
",",
"array",
"$",
"entitiesById",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getValues",
"(",
"$",
"valueClass",
",",
"$",
"entitiesById",
")",
"as",
"$",
"valueEntity",
")",
"{",
"$"... | @param string $valueClass
@param DataInterface[] $entitiesById
@throws \UnexpectedValueException | [
"@param",
"string",
"$valueClass",
"@param",
"DataInterface",
"[]",
"$entitiesById"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/OptimizedDataLoader.php#L104-L120 |
VincentChalnot/SidusEAVModelBundle | Doctrine/OptimizedDataLoader.php | OptimizedDataLoader.getValues | protected function getValues($valueClass, array $entitiesById)
{
/** @var EntityRepository $valueRepository */
$valueRepository = $this->entityManager->getRepository($valueClass);
$qb = $valueRepository->createQueryBuilder('e');
$qb
->addSelect('d', 'dv')
->join('e.data', 'd')
->leftJoin('e.dataValue', 'dv')
->where('e.data IN (:data)')
->setParameter('data', $entitiesById);
return $qb->getQuery()->getResult();
} | php | protected function getValues($valueClass, array $entitiesById)
{
/** @var EntityRepository $valueRepository */
$valueRepository = $this->entityManager->getRepository($valueClass);
$qb = $valueRepository->createQueryBuilder('e');
$qb
->addSelect('d', 'dv')
->join('e.data', 'd')
->leftJoin('e.dataValue', 'dv')
->where('e.data IN (:data)')
->setParameter('data', $entitiesById);
return $qb->getQuery()->getResult();
} | [
"protected",
"function",
"getValues",
"(",
"$",
"valueClass",
",",
"array",
"$",
"entitiesById",
")",
"{",
"/** @var EntityRepository $valueRepository */",
"$",
"valueRepository",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getRepository",
"(",
"$",
"valueClass",
... | @param string $valueClass
@param array $entitiesById
@return ValueInterface[] | [
"@param",
"string",
"$valueClass",
"@param",
"array",
"$entitiesById"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/OptimizedDataLoader.php#L128-L141 |
VincentChalnot/SidusEAVModelBundle | Doctrine/OptimizedDataLoader.php | OptimizedDataLoader.loadRelatedEntities | protected function loadRelatedEntities($entities, $depth)
{
if (0 <= $depth) {
return;
}
$relatedEntities = [];
foreach ($entities as $entity) {
if (null === $entity) {
continue;
}
$family = $entity->getFamily();
foreach ($family->getAttributes() as $attribute) {
$this->appendRelatedEntities($relatedEntities, $attribute, $entity);
}
}
$this->load($relatedEntities, $depth - 1);
} | php | protected function loadRelatedEntities($entities, $depth)
{
if (0 <= $depth) {
return;
}
$relatedEntities = [];
foreach ($entities as $entity) {
if (null === $entity) {
continue;
}
$family = $entity->getFamily();
foreach ($family->getAttributes() as $attribute) {
$this->appendRelatedEntities($relatedEntities, $attribute, $entity);
}
}
$this->load($relatedEntities, $depth - 1);
} | [
"protected",
"function",
"loadRelatedEntities",
"(",
"$",
"entities",
",",
"$",
"depth",
")",
"{",
"if",
"(",
"0",
"<=",
"$",
"depth",
")",
"{",
"return",
";",
"}",
"$",
"relatedEntities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$... | @param DataInterface[] $entities
@param int $depth
@throws \UnexpectedValueException
@throws \InvalidArgumentException | [
"@param",
"DataInterface",
"[]",
"$entities",
"@param",
"int",
"$depth"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/OptimizedDataLoader.php#L150-L167 |
VincentChalnot/SidusEAVModelBundle | DataGrid/EAVColumnRenderer.php | EAVColumnRenderer.renderColumnLabel | public function renderColumnLabel(Column $column): string
{
// If already defined in translations, ignore
$key = "datagrid.{$column->getDataGrid()->getCode()}.{$column->getCode()}"; // Same as base logic
if ($this->translator instanceof TranslatorBagInterface && $this->translator->getCatalogue()->has($key)) {
return $this->baseRenderer->renderColumnLabel($column);
}
$queryHandler = $column->getDataGrid()->getQueryHandler();
// EAVFilterBundle might not be installed
/** @noinspection ClassConstantCanBeUsedInspection */
if (!is_a($queryHandler, 'Sidus\EAVFilterBundle\Query\Handler\EAVQueryHandlerInterface')) {
return $this->baseRenderer->renderColumnLabel($column);
}
/** @var \Sidus\EAVFilterBundle\Query\Handler\EAVQueryHandlerInterface $queryHandler */
$family = $queryHandler->getFamily();
if (!$family->hasAttribute($column->getCode())) {
return $this->baseRenderer->renderColumnLabel($column);
}
return $family->getAttribute($column->getCode())->getLabel();
} | php | public function renderColumnLabel(Column $column): string
{
// If already defined in translations, ignore
$key = "datagrid.{$column->getDataGrid()->getCode()}.{$column->getCode()}"; // Same as base logic
if ($this->translator instanceof TranslatorBagInterface && $this->translator->getCatalogue()->has($key)) {
return $this->baseRenderer->renderColumnLabel($column);
}
$queryHandler = $column->getDataGrid()->getQueryHandler();
// EAVFilterBundle might not be installed
/** @noinspection ClassConstantCanBeUsedInspection */
if (!is_a($queryHandler, 'Sidus\EAVFilterBundle\Query\Handler\EAVQueryHandlerInterface')) {
return $this->baseRenderer->renderColumnLabel($column);
}
/** @var \Sidus\EAVFilterBundle\Query\Handler\EAVQueryHandlerInterface $queryHandler */
$family = $queryHandler->getFamily();
if (!$family->hasAttribute($column->getCode())) {
return $this->baseRenderer->renderColumnLabel($column);
}
return $family->getAttribute($column->getCode())->getLabel();
} | [
"public",
"function",
"renderColumnLabel",
"(",
"Column",
"$",
"column",
")",
":",
"string",
"{",
"// If already defined in translations, ignore",
"$",
"key",
"=",
"\"datagrid.{$column->getDataGrid()->getCode()}.{$column->getCode()}\"",
";",
"// Same as base logic",
"if",
"(",
... | @param Column $column
@throws \Symfony\Component\Translation\Exception\InvalidArgumentException
@throws \Sidus\EAVModelBundle\Exception\MissingAttributeException
@return string | [
"@param",
"Column",
"$column"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/DataGrid/EAVColumnRenderer.php#L53-L75 |
VincentChalnot/SidusEAVModelBundle | Cache/AnnotationGenerator.php | AnnotationGenerator.warmUp | public function warmUp($cacheDir)
{
$baseDir = $this->annotationDir.DIRECTORY_SEPARATOR.'Sidus'.DIRECTORY_SEPARATOR.'EAV'.DIRECTORY_SEPARATOR;
if (!@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
throw new \RuntimeException("Unable to create annotations directory: {$baseDir}");
}
foreach ($this->familyRegistry->getFamilies() as $family) {
$content = $this->getFileHeader($family);
foreach ($family->getAttributes() as $attribute) {
$content .= $this->getAttributeMethods($family, $attribute);
}
$content .= "}\n";
$this->writeFile($baseDir.$family->getCode().'.php', $content);
}
} | php | public function warmUp($cacheDir)
{
$baseDir = $this->annotationDir.DIRECTORY_SEPARATOR.'Sidus'.DIRECTORY_SEPARATOR.'EAV'.DIRECTORY_SEPARATOR;
if (!@mkdir($baseDir, 0777, true) && !is_dir($baseDir)) {
throw new \RuntimeException("Unable to create annotations directory: {$baseDir}");
}
foreach ($this->familyRegistry->getFamilies() as $family) {
$content = $this->getFileHeader($family);
foreach ($family->getAttributes() as $attribute) {
$content .= $this->getAttributeMethods($family, $attribute);
}
$content .= "}\n";
$this->writeFile($baseDir.$family->getCode().'.php', $content);
}
} | [
"public",
"function",
"warmUp",
"(",
"$",
"cacheDir",
")",
"{",
"$",
"baseDir",
"=",
"$",
"this",
"->",
"annotationDir",
".",
"DIRECTORY_SEPARATOR",
".",
"'Sidus'",
".",
"DIRECTORY_SEPARATOR",
".",
"'EAV'",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"!",
"@... | Warms up the cache.
@param string $cacheDir The cache directory
@throws \UnexpectedValueException
@throws \Sidus\EAVModelBundle\Exception\MissingFamilyException
@throws \RuntimeException
@throws \ReflectionException | [
"Warms",
"up",
"the",
"cache",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Cache/AnnotationGenerator.php#L75-L93 |
VincentChalnot/SidusEAVModelBundle | Cache/AnnotationGenerator.php | AnnotationGenerator.getFileHeader | protected function getFileHeader(FamilyInterface $family)
{
$content = <<<EOT
<?php
namespace Sidus\EAV;
use Doctrine\Common\Collections\Collection;
abstract class {$family->getCode()} extends
EOT;
if ($family->getParent()) {
$content .= $family->getParent()->getCode();
} else {
$content .= '\\'.$family->getDataClass();
}
$content .= "\n{\n";
return $content;
} | php | protected function getFileHeader(FamilyInterface $family)
{
$content = <<<EOT
<?php
namespace Sidus\EAV;
use Doctrine\Common\Collections\Collection;
abstract class {$family->getCode()} extends
EOT;
if ($family->getParent()) {
$content .= $family->getParent()->getCode();
} else {
$content .= '\\'.$family->getDataClass();
}
$content .= "\n{\n";
return $content;
} | [
"protected",
"function",
"getFileHeader",
"(",
"FamilyInterface",
"$",
"family",
")",
"{",
"$",
"content",
"=",
" <<<EOT\n<?php\n\nnamespace Sidus\\EAV;\n\nuse Doctrine\\Common\\Collections\\Collection;\n\nabstract class {$family->getCode()} extends \nEOT",
";",
"if",
"(",
"$",
"fa... | @param FamilyInterface $family
@return string | [
"@param",
"FamilyInterface",
"$family"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Cache/AnnotationGenerator.php#L100-L119 |
VincentChalnot/SidusEAVModelBundle | Cache/AnnotationGenerator.php | AnnotationGenerator.getAttributeMethods | protected function getAttributeMethods(FamilyInterface $family, AttributeInterface $attribute)
{
if ($this->isAttributeInherited($family, $attribute)) {
return '';
}
$content = '';
$dataClass = new \ReflectionClass($family->getDataClass());
$getter = 'get'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($getter)) {
$content .= $this->generateGetAnnotation($family, $attribute);
$content .= "abstract public function {$getter}(array \$context = null);\n\n";
}
$setter = 'set'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($setter)) {
$content .= $this->generateSetAnnotation($family, $attribute);
$content .= 'abstract public function set'.ucfirst($attribute->getCode());
$content .= '($value, array $context = null);'."\n\n";
}
if ($attribute->isCollection()) {
// Adder and remover
$setter = 'add'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($setter)) {
$content .= $this->generateSetAnnotation($family, $attribute, true);
$content .= 'abstract public function add'.ucfirst($attribute->getCode());
$content .= '($value, array $context = null);'."\n\n";
}
$setter = 'remove'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($setter)) {
$content .= $this->generateSetAnnotation($family, $attribute, true);
$content .= 'abstract public function remove'.ucfirst($attribute->getCode());
$content .= '($value, array $context = null);'."\n\n";
}
}
return $content;
} | php | protected function getAttributeMethods(FamilyInterface $family, AttributeInterface $attribute)
{
if ($this->isAttributeInherited($family, $attribute)) {
return '';
}
$content = '';
$dataClass = new \ReflectionClass($family->getDataClass());
$getter = 'get'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($getter)) {
$content .= $this->generateGetAnnotation($family, $attribute);
$content .= "abstract public function {$getter}(array \$context = null);\n\n";
}
$setter = 'set'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($setter)) {
$content .= $this->generateSetAnnotation($family, $attribute);
$content .= 'abstract public function set'.ucfirst($attribute->getCode());
$content .= '($value, array $context = null);'."\n\n";
}
if ($attribute->isCollection()) {
// Adder and remover
$setter = 'add'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($setter)) {
$content .= $this->generateSetAnnotation($family, $attribute, true);
$content .= 'abstract public function add'.ucfirst($attribute->getCode());
$content .= '($value, array $context = null);'."\n\n";
}
$setter = 'remove'.ucfirst($attribute->getCode());
if (!$dataClass->hasMethod($setter)) {
$content .= $this->generateSetAnnotation($family, $attribute, true);
$content .= 'abstract public function remove'.ucfirst($attribute->getCode());
$content .= '($value, array $context = null);'."\n\n";
}
}
return $content;
} | [
"protected",
"function",
"getAttributeMethods",
"(",
"FamilyInterface",
"$",
"family",
",",
"AttributeInterface",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAttributeInherited",
"(",
"$",
"family",
",",
"$",
"attribute",
")",
")",
"{",
"retur... | @param FamilyInterface $family
@param AttributeInterface $attribute
@throws \UnexpectedValueException
@throws \Sidus\EAVModelBundle\Exception\MissingFamilyException
@throws \ReflectionException
@return string | [
"@param",
"FamilyInterface",
"$family",
"@param",
"AttributeInterface",
"$attribute"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Cache/AnnotationGenerator.php#L131-L170 |
VincentChalnot/SidusEAVModelBundle | Cache/AnnotationGenerator.php | AnnotationGenerator.getPHPType | protected function getPHPType(
FamilyInterface $family,
AttributeInterface $attribute,
$forceSingle = false
) {
$type = substr($attribute->getType()->getDatabaseType(), 0, -\strlen('Value'));
$collection = $attribute->isCollection() && !$forceSingle;
// Scalar types
if (\in_array($type, ['bool', 'integer', 'decimal', 'string', 'text'], true)) {
if ('text' === $type) {
return 'string';
}
if ('decimal' === $type) {
return 'double';
}
if ($collection) {
return $type.'[]|Collection';
}
return $type;
}
if (\in_array($type, ['date', 'datetime'], true)) {
/** @noinspection ClassConstantCanBeUsedInspection */
$type = '\DateTime';
if ($collection) {
$type .= '[]|Collection';
}
return $type;
}
if ('data' === $type || 'constrainedData' === $type) {
$familyCodes = $attribute->getOption('allowed_families');
if ($familyCodes) {
if (!\is_array($familyCodes)) {
$familyCodes = [$familyCodes];
}
$types = [];
foreach ($familyCodes as $familyCode) {
$types[] = $familyCode.($collection ? '[]' : '');
$family = $this->familyRegistry->getFamily($familyCode);
if ($family->getDataClass()) {
$types[] = '\\'.ltrim($family->getDataClass(), '\\').($collection ? '[]' : '');
}
}
if ($collection) {
$types[] = 'Collection';
}
return implode('|', $types);
}
// Couldn't find any family (rare case)
if ($collection) {
return 'Collection';
}
return 'mixed';
}
// Then there are the custom relation cases:
$type = $this->getTargetClass($family, $attribute, $forceSingle);
if ($type) {
return $type;
}
// Fallback in any other case
if ($collection) {
return 'Collection';
}
return 'mixed';
} | php | protected function getPHPType(
FamilyInterface $family,
AttributeInterface $attribute,
$forceSingle = false
) {
$type = substr($attribute->getType()->getDatabaseType(), 0, -\strlen('Value'));
$collection = $attribute->isCollection() && !$forceSingle;
// Scalar types
if (\in_array($type, ['bool', 'integer', 'decimal', 'string', 'text'], true)) {
if ('text' === $type) {
return 'string';
}
if ('decimal' === $type) {
return 'double';
}
if ($collection) {
return $type.'[]|Collection';
}
return $type;
}
if (\in_array($type, ['date', 'datetime'], true)) {
/** @noinspection ClassConstantCanBeUsedInspection */
$type = '\DateTime';
if ($collection) {
$type .= '[]|Collection';
}
return $type;
}
if ('data' === $type || 'constrainedData' === $type) {
$familyCodes = $attribute->getOption('allowed_families');
if ($familyCodes) {
if (!\is_array($familyCodes)) {
$familyCodes = [$familyCodes];
}
$types = [];
foreach ($familyCodes as $familyCode) {
$types[] = $familyCode.($collection ? '[]' : '');
$family = $this->familyRegistry->getFamily($familyCode);
if ($family->getDataClass()) {
$types[] = '\\'.ltrim($family->getDataClass(), '\\').($collection ? '[]' : '');
}
}
if ($collection) {
$types[] = 'Collection';
}
return implode('|', $types);
}
// Couldn't find any family (rare case)
if ($collection) {
return 'Collection';
}
return 'mixed';
}
// Then there are the custom relation cases:
$type = $this->getTargetClass($family, $attribute, $forceSingle);
if ($type) {
return $type;
}
// Fallback in any other case
if ($collection) {
return 'Collection';
}
return 'mixed';
} | [
"protected",
"function",
"getPHPType",
"(",
"FamilyInterface",
"$",
"family",
",",
"AttributeInterface",
"$",
"attribute",
",",
"$",
"forceSingle",
"=",
"false",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"attribute",
"->",
"getType",
"(",
")",
"->",
... | @param FamilyInterface $family
@param AttributeInterface $attribute
@param bool $forceSingle
@throws \UnexpectedValueException
@throws \Sidus\EAVModelBundle\Exception\MissingFamilyException
@return string | [
"@param",
"FamilyInterface",
"$family",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"bool",
"$forceSingle"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Cache/AnnotationGenerator.php#L250-L322 |
VincentChalnot/SidusEAVModelBundle | Cache/AnnotationGenerator.php | AnnotationGenerator.getTargetClass | protected function getTargetClass(
FamilyInterface $parentFamily,
AttributeInterface $attribute,
$forceSingle = false
) {
$classMetadata = $this->manager->getClassMetadata($parentFamily->getValueClass());
try {
$mapping = $classMetadata->getAssociationMapping($attribute->getType()->getDatabaseType());
} catch (MappingException $e) {
return null;
}
if (empty($mapping['targetEntity'])) {
return null;
}
$type = $mapping['targetEntity'];
if (!$forceSingle && $attribute->isCollection()) {
$type .= '[]|Collection';
}
return '\\'.$type;
} | php | protected function getTargetClass(
FamilyInterface $parentFamily,
AttributeInterface $attribute,
$forceSingle = false
) {
$classMetadata = $this->manager->getClassMetadata($parentFamily->getValueClass());
try {
$mapping = $classMetadata->getAssociationMapping($attribute->getType()->getDatabaseType());
} catch (MappingException $e) {
return null;
}
if (empty($mapping['targetEntity'])) {
return null;
}
$type = $mapping['targetEntity'];
if (!$forceSingle && $attribute->isCollection()) {
$type .= '[]|Collection';
}
return '\\'.$type;
} | [
"protected",
"function",
"getTargetClass",
"(",
"FamilyInterface",
"$",
"parentFamily",
",",
"AttributeInterface",
"$",
"attribute",
",",
"$",
"forceSingle",
"=",
"false",
")",
"{",
"$",
"classMetadata",
"=",
"$",
"this",
"->",
"manager",
"->",
"getClassMetadata",... | @param FamilyInterface $parentFamily
@param AttributeInterface $attribute
@param bool $forceSingle
@throws \UnexpectedValueException
@return string | [
"@param",
"FamilyInterface",
"$parentFamily",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"bool",
"$forceSingle"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Cache/AnnotationGenerator.php#L333-L354 |
VincentChalnot/SidusEAVModelBundle | Cache/AnnotationGenerator.php | AnnotationGenerator.isAttributeInherited | protected function isAttributeInherited(FamilyInterface $family, AttributeInterface $attribute)
{
if (!$family->getParent()) {
return false;
}
if ($family->getParent()->hasAttribute($attribute->getCode())) {
return true;
}
return $this->isAttributeInherited($family->getParent(), $attribute);
} | php | protected function isAttributeInherited(FamilyInterface $family, AttributeInterface $attribute)
{
if (!$family->getParent()) {
return false;
}
if ($family->getParent()->hasAttribute($attribute->getCode())) {
return true;
}
return $this->isAttributeInherited($family->getParent(), $attribute);
} | [
"protected",
"function",
"isAttributeInherited",
"(",
"FamilyInterface",
"$",
"family",
",",
"AttributeInterface",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"family",
"->",
"getParent",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$"... | @param FamilyInterface $family
@param AttributeInterface $attribute
@return bool | [
"@param",
"FamilyInterface",
"$family",
"@param",
"AttributeInterface",
"$attribute"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Cache/AnnotationGenerator.php#L362-L372 |
VincentChalnot/SidusEAVModelBundle | Serializer/Denormalizer/FamilyDenormalizer.php | FamilyDenormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = [])
{
if ($data instanceof FamilyInterface) {
return $data;
}
if (\is_string($data)) {
return $this->resolveFamily($data);
}
if (\is_array($data)) {
foreach (['family', 'familyCode', 'family_code', 'code'] as $property) {
if (array_key_exists($property, $data)) {
return $this->resolveFamily($data[$property]);
}
}
}
throw new UnexpectedValueException('Unknown data format');
} | php | public function denormalize($data, $class, $format = null, array $context = [])
{
if ($data instanceof FamilyInterface) {
return $data;
}
if (\is_string($data)) {
return $this->resolveFamily($data);
}
if (\is_array($data)) {
foreach (['family', 'familyCode', 'family_code', 'code'] as $property) {
if (array_key_exists($property, $data)) {
return $this->resolveFamily($data[$property]);
}
}
}
throw new UnexpectedValueException('Unknown data format');
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"FamilyInterface",
")",
"{",
"return",
"$",
"data"... | Denormalizes data back into an object of the given class.
@param mixed $data data to restore
@param string $class the expected class to instantiate
@param string $format format the given data was extracted from
@param array $context options available to the denormalizer
@throws \Symfony\Component\Serializer\Exception\UnexpectedValueException
@return FamilyInterface | [
"Denormalizes",
"data",
"back",
"into",
"an",
"object",
"of",
"the",
"given",
"class",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Denormalizer/FamilyDenormalizer.php#L49-L66 |
VincentChalnot/SidusEAVModelBundle | Serializer/Denormalizer/FamilyDenormalizer.php | FamilyDenormalizer.resolveFamily | protected function resolveFamily($familyCode)
{
try {
return $this->familyRegistry->getFamily($familyCode);
} catch (MissingFamilyException $e) {
throw new UnexpectedValueException($e->getMessage(), 0, $e);
}
} | php | protected function resolveFamily($familyCode)
{
try {
return $this->familyRegistry->getFamily($familyCode);
} catch (MissingFamilyException $e) {
throw new UnexpectedValueException($e->getMessage(), 0, $e);
}
} | [
"protected",
"function",
"resolveFamily",
"(",
"$",
"familyCode",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"familyRegistry",
"->",
"getFamily",
"(",
"$",
"familyCode",
")",
";",
"}",
"catch",
"(",
"MissingFamilyException",
"$",
"e",
")",
"{",
"th... | @param string $familyCode
@throws \Symfony\Component\Serializer\Exception\UnexpectedValueException
@return FamilyInterface | [
"@param",
"string",
"$familyCode"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Denormalizer/FamilyDenormalizer.php#L89-L96 |
VincentChalnot/SidusEAVModelBundle | Serializer/EntityProvider.php | EntityProvider.getEntity | public function getEntity(FamilyInterface $family, $data, NameConverterInterface $nameConverter = null)
{
/** @var DataRepository $repository */
$entityManager = $this->doctrine->getManagerForClass($family->getDataClass());
if (!$entityManager instanceof EntityManagerInterface) {
throw new UnexpectedValueException("No manager found for class {$family->getDataClass()}");
}
$repository = $entityManager->getRepository($family->getDataClass());
if ($family->isSingleton()) {
try {
return $repository->getInstance($family);
} catch (\Exception $e) {
throw new UnexpectedValueException("Unable to get singleton for family {$family->getCode()}", 0, $e);
}
}
// In case we are trying to resolve a simple reference
if (is_scalar($data)) {
try {
$entity = $repository->findByIdentifier($family, $data, true);
} catch (\Exception $e) {
throw new UnexpectedValueException(
"Unable to resolve id/identifier {$data} for family {$family->getCode()}",
0,
$e
);
}
if (!$entity) {
throw new UnexpectedValueException(
"No entity found for {$family->getCode()} with identifier '{$data}'"
);
}
return $entity;
}
if (!\is_array($data) && !$data instanceof \ArrayAccess) {
throw new UnexpectedValueException('Unable to denormalize data from unknown format');
}
// If the id is set (and not null), don't even look for the identifier
if (isset($data['id'])) {
/** @noinspection PhpIncompatibleReturnTypeInspection */
return $repository->find($data['id']);
}
// Try to resolve the identifier
$reference = $this->resolveIdentifier($data, $family, $nameConverter);
if (null !== $reference) {
try {
$entity = $repository->findByIdentifier($family, $reference);
if ($entity) {
return $entity;
}
} catch (NonUniqueResultException $e) {
throw new UnexpectedValueException(
"Non unique result for identifier {$reference} for family {$family->getCode()}",
0,
$e
);
} catch (\Exception $e) {
throw new UnexpectedValueException(
"Unable to resolve identifier {$reference} for family {$family->getCode()}",
0,
$e
);
}
}
// Maybe the entity already exists but is not yet persisted
if (null !== $reference && $this->hasCreatedEntity($family, $reference)) {
return $this->getCreatedEntity($family, $reference);
}
$entity = $family->createData();
// If we can, store the created entity for later
if (null !== $reference) {
$this->addCreatedEntity($entity, $reference);
}
return $entity;
} | php | public function getEntity(FamilyInterface $family, $data, NameConverterInterface $nameConverter = null)
{
/** @var DataRepository $repository */
$entityManager = $this->doctrine->getManagerForClass($family->getDataClass());
if (!$entityManager instanceof EntityManagerInterface) {
throw new UnexpectedValueException("No manager found for class {$family->getDataClass()}");
}
$repository = $entityManager->getRepository($family->getDataClass());
if ($family->isSingleton()) {
try {
return $repository->getInstance($family);
} catch (\Exception $e) {
throw new UnexpectedValueException("Unable to get singleton for family {$family->getCode()}", 0, $e);
}
}
// In case we are trying to resolve a simple reference
if (is_scalar($data)) {
try {
$entity = $repository->findByIdentifier($family, $data, true);
} catch (\Exception $e) {
throw new UnexpectedValueException(
"Unable to resolve id/identifier {$data} for family {$family->getCode()}",
0,
$e
);
}
if (!$entity) {
throw new UnexpectedValueException(
"No entity found for {$family->getCode()} with identifier '{$data}'"
);
}
return $entity;
}
if (!\is_array($data) && !$data instanceof \ArrayAccess) {
throw new UnexpectedValueException('Unable to denormalize data from unknown format');
}
// If the id is set (and not null), don't even look for the identifier
if (isset($data['id'])) {
/** @noinspection PhpIncompatibleReturnTypeInspection */
return $repository->find($data['id']);
}
// Try to resolve the identifier
$reference = $this->resolveIdentifier($data, $family, $nameConverter);
if (null !== $reference) {
try {
$entity = $repository->findByIdentifier($family, $reference);
if ($entity) {
return $entity;
}
} catch (NonUniqueResultException $e) {
throw new UnexpectedValueException(
"Non unique result for identifier {$reference} for family {$family->getCode()}",
0,
$e
);
} catch (\Exception $e) {
throw new UnexpectedValueException(
"Unable to resolve identifier {$reference} for family {$family->getCode()}",
0,
$e
);
}
}
// Maybe the entity already exists but is not yet persisted
if (null !== $reference && $this->hasCreatedEntity($family, $reference)) {
return $this->getCreatedEntity($family, $reference);
}
$entity = $family->createData();
// If we can, store the created entity for later
if (null !== $reference) {
$this->addCreatedEntity($entity, $reference);
}
return $entity;
} | [
"public",
"function",
"getEntity",
"(",
"FamilyInterface",
"$",
"family",
",",
"$",
"data",
",",
"NameConverterInterface",
"$",
"nameConverter",
"=",
"null",
")",
"{",
"/** @var DataRepository $repository */",
"$",
"entityManager",
"=",
"$",
"this",
"->",
"doctrine"... | @param FamilyInterface $family
@param mixed $data
@param NameConverterInterface $nameConverter
@throws SerializerExceptionInterface
@return DataInterface|null | [
"@param",
"FamilyInterface",
"$family",
"@param",
"mixed",
"$data",
"@param",
"NameConverterInterface",
"$nameConverter"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/EntityProvider.php#L59-L144 |
VincentChalnot/SidusEAVModelBundle | Serializer/EntityProvider.php | EntityProvider.onFlush | public function onFlush(OnFlushEventArgs $event)
{
$uow = $event->getEntityManager()->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof DataInterface
&& $this->hasCreatedEntity(
$entity->getFamily(),
$entity->getIdentifier()
)
) {
$this->removeCreatedEntity($entity->getFamily(), $entity->getIdentifier());
}
}
} | php | public function onFlush(OnFlushEventArgs $event)
{
$uow = $event->getEntityManager()->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof DataInterface
&& $this->hasCreatedEntity(
$entity->getFamily(),
$entity->getIdentifier()
)
) {
$this->removeCreatedEntity($entity->getFamily(), $entity->getIdentifier());
}
}
} | [
"public",
"function",
"onFlush",
"(",
"OnFlushEventArgs",
"$",
"event",
")",
"{",
"$",
"uow",
"=",
"$",
"event",
"->",
"getEntityManager",
"(",
")",
"->",
"getUnitOfWork",
"(",
")",
";",
"foreach",
"(",
"$",
"uow",
"->",
"getScheduledEntityInsertions",
"(",
... | When an entity is created, we don't need to keep the reference anymore
@param OnFlushEventArgs $event
@throws \Sidus\EAVModelBundle\Exception\InvalidValueDataException | [
"When",
"an",
"entity",
"is",
"created",
"we",
"don",
"t",
"need",
"to",
"keep",
"the",
"reference",
"anymore"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/EntityProvider.php#L153-L167 |
VincentChalnot/SidusEAVModelBundle | Serializer/EntityProvider.php | EntityProvider.resolveIdentifier | protected function resolveIdentifier(
array $data,
FamilyInterface $family,
NameConverterInterface $nameConverter = null
) {
if (!$family->getAttributeAsIdentifier()) {
return null;
}
$attributeCode = $family->getAttributeAsIdentifier()->getCode();
if ($nameConverter) {
$attributeCode = $nameConverter->normalize($attributeCode);
}
if (array_key_exists($attributeCode, $data)) {
return $data[$attributeCode];
}
return null;
} | php | protected function resolveIdentifier(
array $data,
FamilyInterface $family,
NameConverterInterface $nameConverter = null
) {
if (!$family->getAttributeAsIdentifier()) {
return null;
}
$attributeCode = $family->getAttributeAsIdentifier()->getCode();
if ($nameConverter) {
$attributeCode = $nameConverter->normalize($attributeCode);
}
if (array_key_exists($attributeCode, $data)) {
return $data[$attributeCode];
}
return null;
} | [
"protected",
"function",
"resolveIdentifier",
"(",
"array",
"$",
"data",
",",
"FamilyInterface",
"$",
"family",
",",
"NameConverterInterface",
"$",
"nameConverter",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"family",
"->",
"getAttributeAsIdentifier",
"(",
")",... | @param array|\ArrayAccess $data
@param FamilyInterface $family
@param NameConverterInterface $nameConverter
@return mixed | [
"@param",
"array|",
"\\",
"ArrayAccess",
"$data",
"@param",
"FamilyInterface",
"$family",
"@param",
"NameConverterInterface",
"$nameConverter"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/EntityProvider.php#L176-L193 |
VincentChalnot/SidusEAVModelBundle | Serializer/EntityProvider.php | EntityProvider.getCreatedEntity | protected function getCreatedEntity(FamilyInterface $family, $reference)
{
if (!$this->hasCreatedEntity($family, $reference)) {
return null;
}
return $this->createdEntities[$family->getCode()][$reference];
} | php | protected function getCreatedEntity(FamilyInterface $family, $reference)
{
if (!$this->hasCreatedEntity($family, $reference)) {
return null;
}
return $this->createdEntities[$family->getCode()][$reference];
} | [
"protected",
"function",
"getCreatedEntity",
"(",
"FamilyInterface",
"$",
"family",
",",
"$",
"reference",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCreatedEntity",
"(",
"$",
"family",
",",
"$",
"reference",
")",
")",
"{",
"return",
"null",
";",
"... | @param FamilyInterface $family
@param int|string $reference
@return DataInterface | [
"@param",
"FamilyInterface",
"$family",
"@param",
"int|string",
"$reference"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/EntityProvider.php#L201-L208 |
VincentChalnot/SidusEAVModelBundle | Serializer/EntityProvider.php | EntityProvider.hasCreatedEntity | protected function hasCreatedEntity(FamilyInterface $family, $reference)
{
return array_key_exists($family->getCode(), $this->createdEntities)
&& array_key_exists(
$reference,
$this->createdEntities[$family->getCode()]
);
} | php | protected function hasCreatedEntity(FamilyInterface $family, $reference)
{
return array_key_exists($family->getCode(), $this->createdEntities)
&& array_key_exists(
$reference,
$this->createdEntities[$family->getCode()]
);
} | [
"protected",
"function",
"hasCreatedEntity",
"(",
"FamilyInterface",
"$",
"family",
",",
"$",
"reference",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"family",
"->",
"getCode",
"(",
")",
",",
"$",
"this",
"->",
"createdEntities",
")",
"&&",
"array_key_e... | @param FamilyInterface $family
@param int|string $reference
@return bool | [
"@param",
"FamilyInterface",
"$family",
"@param",
"int|string",
"$reference"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/EntityProvider.php#L231-L238 |
VincentChalnot/SidusEAVModelBundle | Form/Type/SimpleDataSelectorType.php | SimpleDataSelectorType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$this->fixDoctrineQueryBuilderNormalizer($resolver);
$queryBuilder = function (EntityRepository $repository, $options) {
$qb = $repository->createQueryBuilder('d');
if (!empty($options['allowed_families'])) {
/** @var FamilyInterface[] $families */
$families = $options['allowed_families'];
$familyCodes = [];
foreach ($families as $family) {
$familyCodes[] = $family->getCode();
}
$qb
->andWhere('d.family IN (:allowedFamilies)')
->setParameter('allowedFamilies', $familyCodes);
}
$qb->setMaxResults($options['max_results']);
return $qb;
};
$resolver->setDefaults(
[
'em' => $this->entityManager,
'class' => $this->dataClass,
'query_builder' => $queryBuilder,
'max_results' => 100,
]
);
$this->allowedFamiliesOptionConfigurator->configureOptions($resolver);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$this->fixDoctrineQueryBuilderNormalizer($resolver);
$queryBuilder = function (EntityRepository $repository, $options) {
$qb = $repository->createQueryBuilder('d');
if (!empty($options['allowed_families'])) {
/** @var FamilyInterface[] $families */
$families = $options['allowed_families'];
$familyCodes = [];
foreach ($families as $family) {
$familyCodes[] = $family->getCode();
}
$qb
->andWhere('d.family IN (:allowedFamilies)')
->setParameter('allowedFamilies', $familyCodes);
}
$qb->setMaxResults($options['max_results']);
return $qb;
};
$resolver->setDefaults(
[
'em' => $this->entityManager,
'class' => $this->dataClass,
'query_builder' => $queryBuilder,
'max_results' => 100,
]
);
$this->allowedFamiliesOptionConfigurator->configureOptions($resolver);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"this",
"->",
"fixDoctrineQueryBuilderNormalizer",
"(",
"$",
"resolver",
")",
";",
"$",
"queryBuilder",
"=",
"function",
"(",
"EntityRepository",
"$",
"repository",
"... | @param OptionsResolver $resolver
@throws \Exception | [
"@param",
"OptionsResolver",
"$resolver"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/Type/SimpleDataSelectorType.php#L60-L93 |
VincentChalnot/SidusEAVModelBundle | Form/Type/SimpleDataSelectorType.php | SimpleDataSelectorType.fixDoctrineQueryBuilderNormalizer | protected function fixDoctrineQueryBuilderNormalizer(OptionsResolver $resolver)
{
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
if (\is_callable($queryBuilder)) {
$queryBuilder = $queryBuilder($this->entityManager->getRepository($options['class']), $options);
if (!$queryBuilder instanceof QueryBuilder) {
throw new UnexpectedTypeException($queryBuilder, QueryBuilder::class);
}
}
return $queryBuilder;
};
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
} | php | protected function fixDoctrineQueryBuilderNormalizer(OptionsResolver $resolver)
{
$queryBuilderNormalizer = function (Options $options, $queryBuilder) {
if (\is_callable($queryBuilder)) {
$queryBuilder = $queryBuilder($this->entityManager->getRepository($options['class']), $options);
if (!$queryBuilder instanceof QueryBuilder) {
throw new UnexpectedTypeException($queryBuilder, QueryBuilder::class);
}
}
return $queryBuilder;
};
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
} | [
"protected",
"function",
"fixDoctrineQueryBuilderNormalizer",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"queryBuilderNormalizer",
"=",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"queryBuilder",
")",
"{",
"if",
"(",
"\\",
"is_callable",
"("... | Adding an options parameter in the query builder normalizer
Taken directly from \Symfony\Bridge\Doctrine\Form\Type\EntityType
@param OptionsResolver $resolver
@throws \Exception | [
"Adding",
"an",
"options",
"parameter",
"in",
"the",
"query",
"builder",
"normalizer",
"Taken",
"directly",
"from",
"\\",
"Symfony",
"\\",
"Bridge",
"\\",
"Doctrine",
"\\",
"Form",
"\\",
"Type",
"\\",
"EntityType"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Form/Type/SimpleDataSelectorType.php#L119-L134 |
VincentChalnot/SidusEAVModelBundle | Model/Family.php | Family.getLabel | public function getLabel()
{
if ($this->label) {
return $this->label;
}
if (null === $this->translator) {
return $this->fallbackLabel;
}
return $this->tryTranslate("eav.family.{$this->getCode()}.label", [], $this->getCode());
} | php | public function getLabel()
{
if ($this->label) {
return $this->label;
}
if (null === $this->translator) {
return $this->fallbackLabel;
}
return $this->tryTranslate("eav.family.{$this->getCode()}.label", [], $this->getCode());
} | [
"public",
"function",
"getLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"label",
")",
"{",
"return",
"$",
"this",
"->",
"label",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"translator",
")",
"{",
"return",
"$",
"this",
"->",
"f... | Will check the translator for the key "eav.family.{$code}.label"
and humanize the code if no translation is found
@return string | [
"Will",
"check",
"the",
"translator",
"for",
"the",
"key",
"eav",
".",
"family",
".",
"{",
"$code",
"}",
".",
"label",
"and",
"humanize",
"the",
"code",
"if",
"no",
"translation",
"is",
"found"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Model/Family.php#L330-L340 |
VincentChalnot/SidusEAVModelBundle | Model/Family.php | Family.getMatchingCodes | public function getMatchingCodes()
{
$codes = [$this->getCode()];
foreach ($this->getChildren() as $child) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$codes = array_merge($codes, $child->getMatchingCodes());
}
return $codes;
} | php | public function getMatchingCodes()
{
$codes = [$this->getCode()];
foreach ($this->getChildren() as $child) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$codes = array_merge($codes, $child->getMatchingCodes());
}
return $codes;
} | [
"public",
"function",
"getMatchingCodes",
"(",
")",
"{",
"$",
"codes",
"=",
"[",
"$",
"this",
"->",
"getCode",
"(",
")",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"/** @noinspection SlowArrayOpera... | Return current family code and all it's sub-families codes
@return array | [
"Return",
"current",
"family",
"code",
"and",
"all",
"it",
"s",
"sub",
"-",
"families",
"codes"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Model/Family.php#L363-L372 |
VincentChalnot/SidusEAVModelBundle | Model/Family.php | Family.createValue | public function createValue(DataInterface $data, AttributeInterface $attribute, array $context = null)
{
$valueClass = $this->getValueClass();
/** @var ValueInterface $value */
$value = new $valueClass($data, $attribute);
$data->addValue($value);
if ($value instanceof ContextualValueInterface
&& $data instanceof ContextualDataInterface
&& \count($attribute->getContextMask())
) {
if ($context) {
$context = array_merge($data->getCurrentContext(), $context);
} else {
$context = $data->getCurrentContext();
}
foreach ($attribute->getContextMask() as $key) {
$value->setContextValue($key, $context[$key]);
}
}
return $value;
} | php | public function createValue(DataInterface $data, AttributeInterface $attribute, array $context = null)
{
$valueClass = $this->getValueClass();
/** @var ValueInterface $value */
$value = new $valueClass($data, $attribute);
$data->addValue($value);
if ($value instanceof ContextualValueInterface
&& $data instanceof ContextualDataInterface
&& \count($attribute->getContextMask())
) {
if ($context) {
$context = array_merge($data->getCurrentContext(), $context);
} else {
$context = $data->getCurrentContext();
}
foreach ($attribute->getContextMask() as $key) {
$value->setContextValue($key, $context[$key]);
}
}
return $value;
} | [
"public",
"function",
"createValue",
"(",
"DataInterface",
"$",
"data",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"valueClass",
"=",
"$",
"this",
"->",
"getValueClass",
"(",
")",
";",
"/** @var Val... | @param DataInterface $data
@param AttributeInterface $attribute
@param array $context
@throws UnexpectedValueException
@return ValueInterface | [
"@param",
"DataInterface",
"$data",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Model/Family.php#L415-L437 |
VincentChalnot/SidusEAVModelBundle | Model/Family.php | Family.createData | public function createData()
{
if (!$this->isInstantiable()) {
throw new \LogicException("Family {$this->getCode()} is not instantiable");
}
if ($this->isSingleton()) {
throw new \LogicException(
"Family {$this->getCode()} is a singleton, use the repository to retrieve the instance"
);
}
$dataClass = $this->getDataClass();
return new $dataClass($this);
} | php | public function createData()
{
if (!$this->isInstantiable()) {
throw new \LogicException("Family {$this->getCode()} is not instantiable");
}
if ($this->isSingleton()) {
throw new \LogicException(
"Family {$this->getCode()} is a singleton, use the repository to retrieve the instance"
);
}
$dataClass = $this->getDataClass();
return new $dataClass($this);
} | [
"public",
"function",
"createData",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Family {$this->getCode()} is not instantiable\"",
")",
";",
"}",
"if",
"(",
"$",
"this... | @throws \LogicException
@return DataInterface | [
"@throws",
"\\",
"LogicException"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Model/Family.php#L444-L457 |
VincentChalnot/SidusEAVModelBundle | Model/Family.php | Family.copyFromFamily | protected function copyFromFamily(FamilyInterface $parent)
{
foreach ($parent->getAttributes() as $attribute) {
$this->addAttribute(clone $attribute);
}
if ($parent->getAttributeAsLabel()) {
$this->attributeAsLabel = $this->getAttribute($parent->getAttributeAsLabel()->getCode());
}
if ($parent->getAttributeAsIdentifier()) {
$this->attributeAsIdentifier = $this->getAttribute($parent->getAttributeAsIdentifier()->getCode());
}
$this->valueClass = $parent->getValueClass();
$this->dataClass = $parent->getDataClass();
} | php | protected function copyFromFamily(FamilyInterface $parent)
{
foreach ($parent->getAttributes() as $attribute) {
$this->addAttribute(clone $attribute);
}
if ($parent->getAttributeAsLabel()) {
$this->attributeAsLabel = $this->getAttribute($parent->getAttributeAsLabel()->getCode());
}
if ($parent->getAttributeAsIdentifier()) {
$this->attributeAsIdentifier = $this->getAttribute($parent->getAttributeAsIdentifier()->getCode());
}
$this->valueClass = $parent->getValueClass();
$this->dataClass = $parent->getDataClass();
} | [
"protected",
"function",
"copyFromFamily",
"(",
"FamilyInterface",
"$",
"parent",
")",
"{",
"foreach",
"(",
"$",
"parent",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attribute",
")",
"{",
"$",
"this",
"->",
"addAttribute",
"(",
"clone",
"$",
"attribute",
... | @param FamilyInterface $parent
@throws \UnexpectedValueException | [
"@param",
"FamilyInterface",
"$parent"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Model/Family.php#L578-L591 |
VincentChalnot/SidusEAVModelBundle | Model/Family.php | Family.buildAttributes | protected function buildAttributes(AttributeRegistry $attributeRegistry, array $config)
{
foreach ((array) $config['attributes'] as $attributeCode => $attributeConfig) {
if ($attributeRegistry->hasAttribute($attributeCode)) {
// If attribute already exists, merge family config into clone
$attribute = clone $attributeRegistry->getAttribute($attributeCode);
if (null !== $attributeConfig) {
$attribute->mergeConfiguration($attributeConfig);
}
} else {
// If attribute doesn't exists, create it locally
$attribute = $attributeRegistry->createAttribute($attributeCode, $attributeConfig);
}
$this->addAttribute($attribute);
}
} | php | protected function buildAttributes(AttributeRegistry $attributeRegistry, array $config)
{
foreach ((array) $config['attributes'] as $attributeCode => $attributeConfig) {
if ($attributeRegistry->hasAttribute($attributeCode)) {
// If attribute already exists, merge family config into clone
$attribute = clone $attributeRegistry->getAttribute($attributeCode);
if (null !== $attributeConfig) {
$attribute->mergeConfiguration($attributeConfig);
}
} else {
// If attribute doesn't exists, create it locally
$attribute = $attributeRegistry->createAttribute($attributeCode, $attributeConfig);
}
$this->addAttribute($attribute);
}
} | [
"protected",
"function",
"buildAttributes",
"(",
"AttributeRegistry",
"$",
"attributeRegistry",
",",
"array",
"$",
"config",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"config",
"[",
"'attributes'",
"]",
"as",
"$",
"attributeCode",
"=>",
"$",
"attribute... | @param AttributeRegistry $attributeRegistry
@param array $config
@throws \UnexpectedValueException | [
"@param",
"AttributeRegistry",
"$attributeRegistry",
"@param",
"array",
"$config"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Model/Family.php#L599-L614 |
VincentChalnot/SidusEAVModelBundle | Doctrine/SingleFamilyQueryBuilder.php | SingleFamilyQueryBuilder.attributeByCode | public function attributeByCode($attributeCode)
{
$attribute = $this->getFamily()->getAttribute($attributeCode);
return $this->attribute($attribute);
} | php | public function attributeByCode($attributeCode)
{
$attribute = $this->getFamily()->getAttribute($attributeCode);
return $this->attribute($attribute);
} | [
"public",
"function",
"attributeByCode",
"(",
"$",
"attributeCode",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"getFamily",
"(",
")",
"->",
"getAttribute",
"(",
"$",
"attributeCode",
")",
";",
"return",
"$",
"this",
"->",
"attribute",
"(",
"$",
... | @param string $attributeCode
@throws \Sidus\EAVModelBundle\Exception\MissingAttributeException
@return AttributeQueryBuilderInterface | [
"@param",
"string",
"$attributeCode"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/SingleFamilyQueryBuilder.php#L56-L61 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.normalize | public function normalize($object, $format = null, array $context = [])
{
$this->maxDepthHandler->handleMaxDepth($context);
if ($this->byReferenceHandler->isByShortReference($context)) {
return $object->getIdentifier();
}
if ($this->circularReferenceHandler->isCircularReference($object, $context)) {
return $this->circularReferenceHandler->handleCircularReference($object);
}
$data = [];
foreach ($this->extractStandardAttributes($object, $format, $context) as $attribute) {
$subContext = $context; // Copy context and force by reference
$subContext[ByReferenceHandler::BY_REFERENCE_KEY] = true; // Keep in mind that the normalizer might not support it
$attributeValue = $this->getAttributeValue($object, $attribute, $format, $subContext);
$data = $this->updateData($data, $attribute, $attributeValue);
}
foreach ($this->extractEAVAttributes($object, $format, $context) as $attribute) {
$attributeValue = $this->getEAVAttributeValue($object, $attribute, $format, $context);
$data = $this->updateData($data, $attribute->getCode(), $attributeValue);
}
return $data;
} | php | public function normalize($object, $format = null, array $context = [])
{
$this->maxDepthHandler->handleMaxDepth($context);
if ($this->byReferenceHandler->isByShortReference($context)) {
return $object->getIdentifier();
}
if ($this->circularReferenceHandler->isCircularReference($object, $context)) {
return $this->circularReferenceHandler->handleCircularReference($object);
}
$data = [];
foreach ($this->extractStandardAttributes($object, $format, $context) as $attribute) {
$subContext = $context; // Copy context and force by reference
$subContext[ByReferenceHandler::BY_REFERENCE_KEY] = true; // Keep in mind that the normalizer might not support it
$attributeValue = $this->getAttributeValue($object, $attribute, $format, $subContext);
$data = $this->updateData($data, $attribute, $attributeValue);
}
foreach ($this->extractEAVAttributes($object, $format, $context) as $attribute) {
$attributeValue = $this->getEAVAttributeValue($object, $attribute, $format, $context);
$data = $this->updateData($data, $attribute->getCode(), $attributeValue);
}
return $data;
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"maxDepthHandler",
"->",
"handleMaxDepth",
"(",
"$",
"context",
")",
";",
"if",
"(",
"$"... | Normalizes an object into a set of arrays/scalars.
@param DataInterface $object object to normalize
@param string $format format the normalization result will be encoded as
@param array $context Context options for the normalizer
@throws InvalidArgumentException
@throws \Symfony\Component\Serializer\Exception\RuntimeException
@throws \Symfony\Component\PropertyAccess\Exception\ExceptionInterface
@throws \Sidus\EAVModelBundle\Exception\EAVExceptionInterface
@throws \Sidus\EAVModelBundle\Exception\InvalidValueDataException
@throws \Symfony\Component\Serializer\Exception\CircularReferenceException
@throws \ReflectionException
@return array | [
"Normalizes",
"an",
"object",
"into",
"a",
"set",
"of",
"arrays",
"/",
"scalars",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L122-L150 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.updateData | protected function updateData(array $data, $attribute, $attributeValue)
{
if ($this->nameConverter) {
$attribute = $this->nameConverter->normalize($attribute);
}
$data[$attribute] = $attributeValue;
return $data;
} | php | protected function updateData(array $data, $attribute, $attributeValue)
{
if ($this->nameConverter) {
$attribute = $this->nameConverter->normalize($attribute);
}
$data[$attribute] = $attributeValue;
return $data;
} | [
"protected",
"function",
"updateData",
"(",
"array",
"$",
"data",
",",
"$",
"attribute",
",",
"$",
"attributeValue",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"nameConverter",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"nameConverter",
"->",
"norm... | Sets an attribute and apply the name converter if necessary.
@param array $data
@param string $attribute
@param mixed $attributeValue
@return array | [
"Sets",
"an",
"attribute",
"and",
"apply",
"the",
"name",
"converter",
"if",
"necessary",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L161-L170 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.getAttributeValue | protected function getAttributeValue(
DataInterface $object,
$attribute,
$format = null,
array $context = []
) {
$rawValue = $this->propertyAccessor->getValue($object, $attribute);
$subContext = $this->getAttributeContext($object, $attribute, $rawValue, $context);
return $this->normalizer->normalize($rawValue, $format, $subContext);
} | php | protected function getAttributeValue(
DataInterface $object,
$attribute,
$format = null,
array $context = []
) {
$rawValue = $this->propertyAccessor->getValue($object, $attribute);
$subContext = $this->getAttributeContext($object, $attribute, $rawValue, $context);
return $this->normalizer->normalize($rawValue, $format, $subContext);
} | [
"protected",
"function",
"getAttributeValue",
"(",
"DataInterface",
"$",
"object",
",",
"$",
"attribute",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"rawValue",
"=",
"$",
"this",
"->",
"propertyAccessor",
... | @param DataInterface $object
@param string $attribute
@param string $format
@param array $context
@throws \Symfony\Component\PropertyAccess\Exception\ExceptionInterface
@return mixed | [
"@param",
"DataInterface",
"$object",
"@param",
"string",
"$attribute",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L182-L192 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.getAttributeContext | protected function getAttributeContext(
DataInterface $object,
$attribute,
/** @noinspection PhpUnusedParameterInspection */
$rawValue,
array $context
) {
return array_merge(
$context,
[
'parent' => $object,
'attribute' => $attribute,
]
);
} | php | protected function getAttributeContext(
DataInterface $object,
$attribute,
/** @noinspection PhpUnusedParameterInspection */
$rawValue,
array $context
) {
return array_merge(
$context,
[
'parent' => $object,
'attribute' => $attribute,
]
);
} | [
"protected",
"function",
"getAttributeContext",
"(",
"DataInterface",
"$",
"object",
",",
"$",
"attribute",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"rawValue",
",",
"array",
"$",
"context",
")",
"{",
"return",
"array_merge",
"(",
"$",
"context",... | @param DataInterface $object
@param string $attribute
@param mixed $rawValue
@param array $context
@return array | [
"@param",
"DataInterface",
"$object",
"@param",
"string",
"$attribute",
"@param",
"mixed",
"$rawValue",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L202-L216 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.getEAVAttributeValue | protected function getEAVAttributeValue(
DataInterface $object,
AttributeInterface $attribute,
$format = null,
array $context = []
) {
$rawValue = $object->get($attribute->getCode());
$subContext = $this->getEAVAttributeContext($object, $attribute, $rawValue, $context);
return $this->normalizer->normalize($rawValue, $format, $subContext);
} | php | protected function getEAVAttributeValue(
DataInterface $object,
AttributeInterface $attribute,
$format = null,
array $context = []
) {
$rawValue = $object->get($attribute->getCode());
$subContext = $this->getEAVAttributeContext($object, $attribute, $rawValue, $context);
return $this->normalizer->normalize($rawValue, $format, $subContext);
} | [
"protected",
"function",
"getEAVAttributeValue",
"(",
"DataInterface",
"$",
"object",
",",
"AttributeInterface",
"$",
"attribute",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"rawValue",
"=",
"$",
"object",
... | @param DataInterface $object
@param AttributeInterface $attribute
@param string $format
@param array $context
@throws EAVExceptionInterface
@return mixed | [
"@param",
"DataInterface",
"$object",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L228-L238 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.getEAVAttributeContext | protected function getEAVAttributeContext(
DataInterface $object,
AttributeInterface $attribute,
/** @noinspection PhpUnusedParameterInspection */
$rawValue,
array $context
) {
$options = $attribute->getOption(static::SERIALIZER_OPTIONS, []);
$byReference = $attribute->getType()->isRelation();
if (array_key_exists(ByReferenceHandler::BY_REFERENCE_KEY, $options)) {
$byReference = $options[ByReferenceHandler::BY_REFERENCE_KEY];
}
$byShortReference = false;
if (array_key_exists(ByReferenceHandler::BY_SHORT_REFERENCE_KEY, $options)) {
$byShortReference = $options[ByReferenceHandler::BY_SHORT_REFERENCE_KEY];
}
$maxDepth = $context[MaxDepthHandler::MAX_DEPTH_KEY];
if (array_key_exists(MaxDepthHandler::MAX_DEPTH_KEY, $options)) {
$maxDepth = $options[MaxDepthHandler::MAX_DEPTH_KEY];
}
return array_merge(
$context,
[
MaxDepthHandler::MAX_DEPTH_KEY => $maxDepth,
ByReferenceHandler::BY_REFERENCE_KEY => $byReference,
ByReferenceHandler::BY_SHORT_REFERENCE_KEY => $byShortReference,
'parent' => $object,
'attribute' => $attribute->getCode(),
'eav_attribute' => $attribute,
]
);
} | php | protected function getEAVAttributeContext(
DataInterface $object,
AttributeInterface $attribute,
/** @noinspection PhpUnusedParameterInspection */
$rawValue,
array $context
) {
$options = $attribute->getOption(static::SERIALIZER_OPTIONS, []);
$byReference = $attribute->getType()->isRelation();
if (array_key_exists(ByReferenceHandler::BY_REFERENCE_KEY, $options)) {
$byReference = $options[ByReferenceHandler::BY_REFERENCE_KEY];
}
$byShortReference = false;
if (array_key_exists(ByReferenceHandler::BY_SHORT_REFERENCE_KEY, $options)) {
$byShortReference = $options[ByReferenceHandler::BY_SHORT_REFERENCE_KEY];
}
$maxDepth = $context[MaxDepthHandler::MAX_DEPTH_KEY];
if (array_key_exists(MaxDepthHandler::MAX_DEPTH_KEY, $options)) {
$maxDepth = $options[MaxDepthHandler::MAX_DEPTH_KEY];
}
return array_merge(
$context,
[
MaxDepthHandler::MAX_DEPTH_KEY => $maxDepth,
ByReferenceHandler::BY_REFERENCE_KEY => $byReference,
ByReferenceHandler::BY_SHORT_REFERENCE_KEY => $byShortReference,
'parent' => $object,
'attribute' => $attribute->getCode(),
'eav_attribute' => $attribute,
]
);
} | [
"protected",
"function",
"getEAVAttributeContext",
"(",
"DataInterface",
"$",
"object",
",",
"AttributeInterface",
"$",
"attribute",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"rawValue",
",",
"array",
"$",
"context",
")",
"{",
"$",
"options",
"=",
... | @param DataInterface $object
@param AttributeInterface $attribute
@param mixed $rawValue
@param array $context
@return array | [
"@param",
"DataInterface",
"$object",
"@param",
"AttributeInterface",
"$attribute",
"@param",
"mixed",
"$rawValue",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L248-L283 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.extractStandardAttributes | protected function extractStandardAttributes(DataInterface $object, $format = null, array $context = [])
{
// If not using groups, detect manually
$attributes = [];
// methods
$reflClass = new \ReflectionClass($object);
foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) {
if (0 !== $reflMethod->getNumberOfRequiredParameters() ||
$reflMethod->isStatic() ||
$reflMethod->isConstructor() ||
$reflMethod->isDestructor()
) {
continue;
}
$name = $reflMethod->name;
$attributeName = null;
if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) {
// getters and hassers
$attributeName = lcfirst(substr($name, 3));
} elseif (0 === strpos($name, 'is')) {
// issers
$attributeName = lcfirst(substr($name, 2));
}
// Skipping eav attributes
if ($object->getFamily()->hasAttribute($attributeName)) {
continue;
}
if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName, $format, $context)) {
$attributes[$attributeName] = true;
}
}
return array_keys($attributes);
} | php | protected function extractStandardAttributes(DataInterface $object, $format = null, array $context = [])
{
// If not using groups, detect manually
$attributes = [];
// methods
$reflClass = new \ReflectionClass($object);
foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) {
if (0 !== $reflMethod->getNumberOfRequiredParameters() ||
$reflMethod->isStatic() ||
$reflMethod->isConstructor() ||
$reflMethod->isDestructor()
) {
continue;
}
$name = $reflMethod->name;
$attributeName = null;
if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) {
// getters and hassers
$attributeName = lcfirst(substr($name, 3));
} elseif (0 === strpos($name, 'is')) {
// issers
$attributeName = lcfirst(substr($name, 2));
}
// Skipping eav attributes
if ($object->getFamily()->hasAttribute($attributeName)) {
continue;
}
if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName, $format, $context)) {
$attributes[$attributeName] = true;
}
}
return array_keys($attributes);
} | [
"protected",
"function",
"extractStandardAttributes",
"(",
"DataInterface",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// If not using groups, detect manually",
"$",
"attributes",
"=",
"[",
"]",
";",
... | @param DataInterface $object
@param string $format
@param array $context
@throws InvalidArgumentException
@throws \ReflectionException
@return array | [
"@param",
"DataInterface",
"$object",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L295-L333 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.extractEAVAttributes | protected function extractEAVAttributes(DataInterface $object, $format = null, array $context = [])
{
$allowedAttributes = [];
foreach ($object->getFamily()->getAttributes() as $attribute) {
if ($this->isAllowedEAVAttribute($object, $attribute, $format, $context)) {
$allowedAttributes[] = $attribute;
}
}
return $allowedAttributes;
} | php | protected function extractEAVAttributes(DataInterface $object, $format = null, array $context = [])
{
$allowedAttributes = [];
foreach ($object->getFamily()->getAttributes() as $attribute) {
if ($this->isAllowedEAVAttribute($object, $attribute, $format, $context)) {
$allowedAttributes[] = $attribute;
}
}
return $allowedAttributes;
} | [
"protected",
"function",
"extractEAVAttributes",
"(",
"DataInterface",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"allowedAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"object",
"->... | @param DataInterface $object
@param string $format
@param array $context
@throws InvalidArgumentException
@return \Sidus\EAVModelBundle\Model\AttributeInterface[] | [
"@param",
"DataInterface",
"$object",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L344-L354 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.isAllowedEAVAttribute | protected function isAllowedEAVAttribute(
DataInterface $object,
AttributeInterface $attribute,
/** @noinspection PhpUnusedParameterInspection */
$format = null,
array $context = []
) {
$options = $attribute->getOption(static::SERIALIZER_OPTIONS, []);
// Ignore attributes set as serializer: expose: false
if (array_key_exists(static::EXPOSE_KEY, $options) && !$options[static::EXPOSE_KEY]) {
return false;
}
// If normalizing by reference, we just check if it's among the allowed attributes
if ($this->byReferenceHandler->isByReference($context)) {
return \in_array($attribute->getCode(), $this->referenceAttributes, true);
}
// Also check ignored attributes
if (\in_array($attribute->getCode(), $this->ignoredAttributes, true)) {
return false;
}
return $this->isEAVGroupAllowed($object, $attribute, $context);
} | php | protected function isAllowedEAVAttribute(
DataInterface $object,
AttributeInterface $attribute,
/** @noinspection PhpUnusedParameterInspection */
$format = null,
array $context = []
) {
$options = $attribute->getOption(static::SERIALIZER_OPTIONS, []);
// Ignore attributes set as serializer: expose: false
if (array_key_exists(static::EXPOSE_KEY, $options) && !$options[static::EXPOSE_KEY]) {
return false;
}
// If normalizing by reference, we just check if it's among the allowed attributes
if ($this->byReferenceHandler->isByReference($context)) {
return \in_array($attribute->getCode(), $this->referenceAttributes, true);
}
// Also check ignored attributes
if (\in_array($attribute->getCode(), $this->ignoredAttributes, true)) {
return false;
}
return $this->isEAVGroupAllowed($object, $attribute, $context);
} | [
"protected",
"function",
"isAllowedEAVAttribute",
"(",
"DataInterface",
"$",
"object",
",",
"AttributeInterface",
"$",
"attribute",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
... | Is this EAV attribute allowed?
@param DataInterface $object
@param AttributeInterface $attribute
@param string|null $format
@param array $context
@throws InvalidArgumentException
@return bool | [
"Is",
"this",
"EAV",
"attribute",
"allowed?"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L368-L393 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.isEAVGroupAllowed | protected function isEAVGroupAllowed(/** @noinspection PhpUnusedParameterInspection */
DataInterface $object,
AttributeInterface $attribute,
array $context
) {
if (!isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) {
return true;
}
$serializerOptions = $attribute->getOption(static::SERIALIZER_OPTIONS, []);
if (!array_key_exists(static::GROUPS, $serializerOptions)) {
return false;
}
$groups = $serializerOptions[static::GROUPS];
if (!\is_array($groups)) {
throw new InvalidArgumentException(
"Invalid 'serializer.groups' option for attribute {$attribute->getCode()} : should be an array"
);
}
return 0 < \count(array_intersect($groups, $context[static::GROUPS]));
} | php | protected function isEAVGroupAllowed(/** @noinspection PhpUnusedParameterInspection */
DataInterface $object,
AttributeInterface $attribute,
array $context
) {
if (!isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) {
return true;
}
$serializerOptions = $attribute->getOption(static::SERIALIZER_OPTIONS, []);
if (!array_key_exists(static::GROUPS, $serializerOptions)) {
return false;
}
$groups = $serializerOptions[static::GROUPS];
if (!\is_array($groups)) {
throw new InvalidArgumentException(
"Invalid 'serializer.groups' option for attribute {$attribute->getCode()} : should be an array"
);
}
return 0 < \count(array_intersect($groups, $context[static::GROUPS]));
} | [
"protected",
"function",
"isEAVGroupAllowed",
"(",
"/** @noinspection PhpUnusedParameterInspection */",
"DataInterface",
"$",
"object",
",",
"AttributeInterface",
"$",
"attribute",
",",
"array",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
... | Gets attributes to normalize using groups.
@param DataInterface $object
@param AttributeInterface $attribute
@param array $context
@throws InvalidArgumentException
@return bool | [
"Gets",
"attributes",
"to",
"normalize",
"using",
"groups",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L406-L428 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.isAllowedAttribute | protected function isAllowedAttribute(
DataInterface $object,
$attribute,
/** @noinspection PhpUnusedParameterInspection */
$format = null,
array $context = []
) {
// If normalizing by reference, we just check if it's among the allowed attributes
if ($this->byReferenceHandler->isByReference($context)) {
return \in_array($attribute, $this->referenceAttributes, true);
}
// Check ignored attributes
if (\in_array($attribute, $this->ignoredAttributes, true)) {
return false;
}
return $this->isGroupAllowed($object, $attribute, $context);
} | php | protected function isAllowedAttribute(
DataInterface $object,
$attribute,
/** @noinspection PhpUnusedParameterInspection */
$format = null,
array $context = []
) {
// If normalizing by reference, we just check if it's among the allowed attributes
if ($this->byReferenceHandler->isByReference($context)) {
return \in_array($attribute, $this->referenceAttributes, true);
}
// Check ignored attributes
if (\in_array($attribute, $this->ignoredAttributes, true)) {
return false;
}
return $this->isGroupAllowed($object, $attribute, $context);
} | [
"protected",
"function",
"isAllowedAttribute",
"(",
"DataInterface",
"$",
"object",
",",
"$",
"attribute",
",",
"/** @noinspection PhpUnusedParameterInspection */",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// If normalizing... | Is this attribute allowed?
@param DataInterface $object
@param string $attribute
@param string|null $format
@param array $context
@throws InvalidArgumentException
@return bool | [
"Is",
"this",
"attribute",
"allowed?"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L442-L460 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/EAVDataNormalizer.php | EAVDataNormalizer.isGroupAllowed | protected function isGroupAllowed(DataInterface $object, $attribute, array $context)
{
if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) {
return true;
}
$attributesMetadatas = $this->classMetadataFactory->getMetadataFor($object)->getAttributesMetadata();
foreach ($attributesMetadatas as $attributeMetadata) {
// Alright, it's completely inefficient...
if ($attributeMetadata->getName() === $attribute) {
return 0 < \count(array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS]));
}
}
return false;
} | php | protected function isGroupAllowed(DataInterface $object, $attribute, array $context)
{
if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !\is_array($context[static::GROUPS])) {
return true;
}
$attributesMetadatas = $this->classMetadataFactory->getMetadataFor($object)->getAttributesMetadata();
foreach ($attributesMetadatas as $attributeMetadata) {
// Alright, it's completely inefficient...
if ($attributeMetadata->getName() === $attribute) {
return 0 < \count(array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS]));
}
}
return false;
} | [
"protected",
"function",
"isGroupAllowed",
"(",
"DataInterface",
"$",
"object",
",",
"$",
"attribute",
",",
"array",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"classMetadataFactory",
"||",
"!",
"isset",
"(",
"$",
"context",
"[",
"static"... | Gets attributes to normalize using groups.
@param DataInterface $object
@param string $attribute
@param array $context
@throws InvalidArgumentException
@return bool | [
"Gets",
"attributes",
"to",
"normalize",
"using",
"groups",
"."
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/EAVDataNormalizer.php#L473-L488 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/Flat/FlatNormalizer.php | FlatNormalizer.normalize | public function normalize($object, $format = null, array $context = [])
{
if (array_key_exists(MaxDepthHandler::DEPTH_KEY, $context) && $context[MaxDepthHandler::DEPTH_KEY] > 0) {
$context[ByReferenceHandler::BY_SHORT_REFERENCE_KEY] = true;
}
return $this->baseNormalizer->normalize($object, $format, $context);
} | php | public function normalize($object, $format = null, array $context = [])
{
if (array_key_exists(MaxDepthHandler::DEPTH_KEY, $context) && $context[MaxDepthHandler::DEPTH_KEY] > 0) {
$context[ByReferenceHandler::BY_SHORT_REFERENCE_KEY] = true;
}
return $this->baseNormalizer->normalize($object, $format, $context);
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"MaxDepthHandler",
"::",
"DEPTH_KEY",
",",
"$",
"context",
")",
"&&",
"$"... | {@inheritdoc} | [
"{"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/Flat/FlatNormalizer.php#L46-L53 |
VincentChalnot/SidusEAVModelBundle | Serializer/Normalizer/Flat/FlatNormalizer.php | FlatNormalizer.supportsNormalization | public function supportsNormalization($data, $format = null)
{
return $this->baseNormalizer->supportsNormalization($data, $format) && \in_array(
$format,
$this->supportedFormats,
true
);
} | php | public function supportsNormalization($data, $format = null)
{
return $this->baseNormalizer->supportsNormalization($data, $format) && \in_array(
$format,
$this->supportedFormats,
true
);
} | [
"public",
"function",
"supportsNormalization",
"(",
"$",
"data",
",",
"$",
"format",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"baseNormalizer",
"->",
"supportsNormalization",
"(",
"$",
"data",
",",
"$",
"format",
")",
"&&",
"\\",
"in_array",
"("... | {@inheritdoc} | [
"{"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Serializer/Normalizer/Flat/FlatNormalizer.php#L58-L65 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVFinder.php | EAVFinder.findBy | public function findBy(FamilyInterface $family, array $filterBy, array $orderBy = [])
{
$qb = $this->getQb($family, $filterBy, $orderBy);
$results = $qb->getQuery()->getResult();
$this->dataLoader->load($results);
return $results;
} | php | public function findBy(FamilyInterface $family, array $filterBy, array $orderBy = [])
{
$qb = $this->getQb($family, $filterBy, $orderBy);
$results = $qb->getQuery()->getResult();
$this->dataLoader->load($results);
return $results;
} | [
"public",
"function",
"findBy",
"(",
"FamilyInterface",
"$",
"family",
",",
"array",
"$",
"filterBy",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getQb",
"(",
"$",
"family",
",",
"$",
"filterBy",
",",
... | @param FamilyInterface $family
@param array $filterBy
@param array $orderBy
@throws \InvalidArgumentException
@throws \UnexpectedValueException
@throws \LogicException
@throws MissingAttributeException
@return DataInterface[] | [
"@param",
"FamilyInterface",
"$family",
"@param",
"array",
"$filterBy",
"@param",
"array",
"$orderBy"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVFinder.php#L72-L79 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVFinder.php | EAVFinder.findOneBy | public function findOneBy(FamilyInterface $family, array $filterBy)
{
$qb = $this->getQb($family, $filterBy);
$pager = new Paginator($qb);
$pager->getQuery()->setMaxResults(1);
$result = $pager->getIterator()->current();
$this->dataLoader->loadSingle($result);
return $result;
} | php | public function findOneBy(FamilyInterface $family, array $filterBy)
{
$qb = $this->getQb($family, $filterBy);
$pager = new Paginator($qb);
$pager->getQuery()->setMaxResults(1);
$result = $pager->getIterator()->current();
$this->dataLoader->loadSingle($result);
return $result;
} | [
"public",
"function",
"findOneBy",
"(",
"FamilyInterface",
"$",
"family",
",",
"array",
"$",
"filterBy",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getQb",
"(",
"$",
"family",
",",
"$",
"filterBy",
")",
";",
"$",
"pager",
"=",
"new",
"Paginator",
... | @param FamilyInterface $family
@param array $filterBy
@throws \InvalidArgumentException
@throws \UnexpectedValueException
@throws \LogicException
@throws MissingAttributeException
@return DataInterface | [
"@param",
"FamilyInterface",
"$family",
"@param",
"array",
"$filterBy"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVFinder.php#L92-L102 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVFinder.php | EAVFinder.filterBy | public function filterBy(FamilyInterface $family, array $filterBy, array $orderBy = [])
{
$qb = $this->getFilterByQb($family, $filterBy, $orderBy);
$results = $qb->getQuery()->getResult();
$this->dataLoader->load($results);
return $results;
} | php | public function filterBy(FamilyInterface $family, array $filterBy, array $orderBy = [])
{
$qb = $this->getFilterByQb($family, $filterBy, $orderBy);
$results = $qb->getQuery()->getResult();
$this->dataLoader->load($results);
return $results;
} | [
"public",
"function",
"filterBy",
"(",
"FamilyInterface",
"$",
"family",
",",
"array",
"$",
"filterBy",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getFilterByQb",
"(",
"$",
"family",
",",
"$",
"filterBy",... | @param FamilyInterface $family
@param array $filterBy
@param array $orderBy
@throws \UnexpectedValueException
@throws \Sidus\EAVModelBundle\Exception\MissingAttributeException
@throws \LogicException
@throws \InvalidArgumentException
@return DataInterface[] | [
"@param",
"FamilyInterface",
"$family",
"@param",
"array",
"$filterBy",
"@param",
"array",
"$orderBy"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVFinder.php#L116-L124 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVFinder.php | EAVFinder.filterOneBy | public function filterOneBy(FamilyInterface $family, array $filterBy, array $orderBy = [])
{
$qb = $this->getFilterByQb($family, $filterBy, $orderBy);
$pager = new Paginator($qb);
$pager->getQuery()->setMaxResults(1);
$result = $pager->getIterator()->current();
$this->dataLoader->loadSingle($result);
return $result;
} | php | public function filterOneBy(FamilyInterface $family, array $filterBy, array $orderBy = [])
{
$qb = $this->getFilterByQb($family, $filterBy, $orderBy);
$pager = new Paginator($qb);
$pager->getQuery()->setMaxResults(1);
$result = $pager->getIterator()->current();
$this->dataLoader->loadSingle($result);
return $result;
} | [
"public",
"function",
"filterOneBy",
"(",
"FamilyInterface",
"$",
"family",
",",
"array",
"$",
"filterBy",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"getFilterByQb",
"(",
"$",
"family",
",",
"$",
"filterB... | @param FamilyInterface $family
@param array $filterBy
@param array $orderBy
@throws \UnexpectedValueException
@throws \Sidus\EAVModelBundle\Exception\MissingAttributeException
@throws \LogicException
@throws \InvalidArgumentException
@return DataInterface|null | [
"@param",
"FamilyInterface",
"$family",
"@param",
"array",
"$filterBy",
"@param",
"array",
"$orderBy"
] | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVFinder.php#L138-L149 |
VincentChalnot/SidusEAVModelBundle | Doctrine/EAVFinder.php | EAVFinder.getFilterByQb | public function getFilterByQb(FamilyInterface $family, array $filterBy, array $orderBy = [], $alias = 'e')
{
$repository = $this->entityManager->getRepository($family->getDataClass());
if (!$repository instanceof DataRepository) {
throw new \UnexpectedValueException(
"Repository for class {$family->getDataClass()} must be a DataRepository"
);
}
$eavQb = $repository->createFamilyQueryBuilder($family, $alias);
// Add order by
foreach ($orderBy as $attributeCode => $direction) {
$eavQb->addOrderBy($eavQb->a($attributeCode), $direction);
}
$dqlHandlers = [];
foreach ($filterBy as $filter) {
list($attributeCode, $operator, $value) = $filter;
$attributeQb = $eavQb->a($attributeCode);
$handleDefaultValues = true;
if (!array_key_exists($operator, static::FILTER_OPERATORS)) {
$m = "Invalid filter operator '{$operator}', valid operators are: ";
$m .= implode(', ', array_keys(self::FILTER_OPERATORS));
throw new \InvalidArgumentException($m);
}
$method = static::FILTER_OPERATORS[$operator];
switch ($operator) {
case 'is null':
case 'is not null':
$dqlHandler = $attributeQb->$method();
$handleDefaultValues = false;
break;
case 'in':
case 'not in':
$handleDefaultValues = false;
default:
$dqlHandler = $attributeQb->$method($value);
}
if ($handleDefaultValues
&& null !== $value
&& $value === $family->getAttribute($attributeCode)->getDefault()
) {
$dqlHandlers[] = $eavQb->getOr(
[
$dqlHandler,
(clone $attributeQb)->isNull(), // Handles default values not yet persisted to database
]
);
} else {
$dqlHandlers[] = $dqlHandler;
}
}
return $eavQb->apply($eavQb->getAnd($dqlHandlers));
} | php | public function getFilterByQb(FamilyInterface $family, array $filterBy, array $orderBy = [], $alias = 'e')
{
$repository = $this->entityManager->getRepository($family->getDataClass());
if (!$repository instanceof DataRepository) {
throw new \UnexpectedValueException(
"Repository for class {$family->getDataClass()} must be a DataRepository"
);
}
$eavQb = $repository->createFamilyQueryBuilder($family, $alias);
// Add order by
foreach ($orderBy as $attributeCode => $direction) {
$eavQb->addOrderBy($eavQb->a($attributeCode), $direction);
}
$dqlHandlers = [];
foreach ($filterBy as $filter) {
list($attributeCode, $operator, $value) = $filter;
$attributeQb = $eavQb->a($attributeCode);
$handleDefaultValues = true;
if (!array_key_exists($operator, static::FILTER_OPERATORS)) {
$m = "Invalid filter operator '{$operator}', valid operators are: ";
$m .= implode(', ', array_keys(self::FILTER_OPERATORS));
throw new \InvalidArgumentException($m);
}
$method = static::FILTER_OPERATORS[$operator];
switch ($operator) {
case 'is null':
case 'is not null':
$dqlHandler = $attributeQb->$method();
$handleDefaultValues = false;
break;
case 'in':
case 'not in':
$handleDefaultValues = false;
default:
$dqlHandler = $attributeQb->$method($value);
}
if ($handleDefaultValues
&& null !== $value
&& $value === $family->getAttribute($attributeCode)->getDefault()
) {
$dqlHandlers[] = $eavQb->getOr(
[
$dqlHandler,
(clone $attributeQb)->isNull(), // Handles default values not yet persisted to database
]
);
} else {
$dqlHandlers[] = $dqlHandler;
}
}
return $eavQb->apply($eavQb->getAnd($dqlHandlers));
} | [
"public",
"function",
"getFilterByQb",
"(",
"FamilyInterface",
"$",
"family",
",",
"array",
"$",
"filterBy",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
",",
"$",
"alias",
"=",
"'e'",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"entityManager",... | @param FamilyInterface $family
@param array $filterBy Filters with format [['attribute1','operator1','value1'],
['attribute2','operator2','value2'], etc.]
@param array $orderBy
@param string $alias
@throws \Sidus\EAVModelBundle\Exception\MissingAttributeException
@throws \UnexpectedValueException
@throws \LogicException
@throws \InvalidArgumentException
@return QueryBuilder | [
"@param",
"FamilyInterface",
"$family",
"@param",
"array",
"$filterBy",
"Filters",
"with",
"format",
"[[",
"attribute1",
"operator1",
"value1",
"]",
"[",
"attribute2",
"operator2",
"value2",
"]",
"etc",
".",
"]",
"@param",
"array",
"$orderBy",
"@param",
"string",
... | train | https://github.com/VincentChalnot/SidusEAVModelBundle/blob/6a0e184ac7ed2aead48b05e5f97badac7fe8000f/Doctrine/EAVFinder.php#L165-L223 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.