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
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Vectrex/vxPHP | src/Database/Util.php | Util.getAlias | public static function getAlias(DatabaseInterface $connection, $aliasText, $tableName, $id = 0, $column = 'alias') {
$replace = [
'~(ä|ä)~' => 'ae',
'~(ö|ö)~' => 'oe',
'~(ü|ü)~' => 'ue',
'~(ß|ß)~' => 'ss',
'~\W+~' => '_',
'~(^_+|_+$)~' => ''
];
$primaryKeyName = $connection->getPrimaryKey($tableName);
$alias = preg_replace(
array_keys($replace),
array_values($replace),
strtolower($aliasText)
);
$statement = $connection->getConnection()->prepare(
sprintf(
'SELECT %1$s FROM %2$s WHERE LOWER(%1$s) LIKE ? AND %3$s != ?',
$column, $tableName, $primaryKeyName
)
);
$statement->execute([$alias . '%', $id]);
$aliasValues = $statement->fetchAll(\PDO::FETCH_COLUMN, 0);
if(count($aliasValues) === 0) {
return $alias;
}
$ndx = 2;
while(in_array($alias . '_' . $ndx, $aliasValues)) {
++$ndx;
}
return $alias . '_' . $ndx;
} | php | public static function getAlias(DatabaseInterface $connection, $aliasText, $tableName, $id = 0, $column = 'alias') {
$replace = [
'~(ä|ä)~' => 'ae',
'~(ö|ö)~' => 'oe',
'~(ü|ü)~' => 'ue',
'~(ß|ß)~' => 'ss',
'~\W+~' => '_',
'~(^_+|_+$)~' => ''
];
$primaryKeyName = $connection->getPrimaryKey($tableName);
$alias = preg_replace(
array_keys($replace),
array_values($replace),
strtolower($aliasText)
);
$statement = $connection->getConnection()->prepare(
sprintf(
'SELECT %1$s FROM %2$s WHERE LOWER(%1$s) LIKE ? AND %3$s != ?',
$column, $tableName, $primaryKeyName
)
);
$statement->execute([$alias . '%', $id]);
$aliasValues = $statement->fetchAll(\PDO::FETCH_COLUMN, 0);
if(count($aliasValues) === 0) {
return $alias;
}
$ndx = 2;
while(in_array($alias . '_' . $ndx, $aliasValues)) {
++$ndx;
}
return $alias . '_' . $ndx;
} | [
"public",
"static",
"function",
"getAlias",
"(",
"DatabaseInterface",
"$",
"connection",
",",
"$",
"aliasText",
",",
"$",
"tableName",
",",
"$",
"id",
"=",
"0",
",",
"$",
"column",
"=",
"'alias'",
")",
"{",
"$",
"replace",
"=",
"[",
"'~(ä|ä)~'\t",
"> ",
"ae',",
"",
"'~(ö|ö)~'\t",
"> ",
"oe',",
"",
"'~(ü|ü)~'\t",
"> ",
"ue',",
"",
"'~(ß|ß)~'\t",
"> ",
"ss',",
"",
"'~\\W+~'",
"=>",
"'_'",
",",
"'~(^_+|_+$)~'",
"=>",
"''",
"]",
";",
"$",
"primaryKeyName",
"=",
"$",
"connection",
"->",
"getPrimaryKey",
"(",
"$",
"tableName",
")",
";",
"$",
"alias",
"=",
"preg_replace",
"(",
"array_keys",
"(",
"$",
"replace",
")",
",",
"array_values",
"(",
"$",
"replace",
")",
",",
"strtolower",
"(",
"$",
"aliasText",
")",
")",
";",
"$",
"statement",
"=",
"$",
"connection",
"->",
"getConnection",
"(",
")",
"->",
"prepare",
"(",
"sprintf",
"(",
"'SELECT %1$s FROM %2$s WHERE LOWER(%1$s) LIKE ? AND %3$s != ?'",
",",
"$",
"column",
",",
"$",
"tableName",
",",
"$",
"primaryKeyName",
")",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"[",
"$",
"alias",
".",
"'%'",
",",
"$",
"id",
"]",
")",
";",
"$",
"aliasValues",
"=",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_COLUMN",
",",
"0",
")",
";",
"if",
"(",
"count",
"(",
"$",
"aliasValues",
")",
"===",
"0",
")",
"{",
"return",
"$",
"alias",
";",
"}",
"$",
"ndx",
"=",
"2",
";",
"while",
"(",
"in_array",
"(",
"$",
"alias",
".",
"'_'",
".",
"$",
"ndx",
",",
"$",
"aliasValues",
")",
")",
"{",
"++",
"$",
"ndx",
";",
"}",
"return",
"$",
"alias",
".",
"'_'",
".",
"$",
"ndx",
";",
"}"
] | checks whether $aliasText in $column is already present
if $aliasText is found, numeric increments are added to it
if $id is set, this record is left out from checking
returns string which is unique in $column
currently works only with single-field primary keys
@param DatabaseInterface $connection
@param string $aliasText
@param string $tableName
@param int $id
@param string $column
@return string | [
"checks",
"whether",
"$aliasText",
"in",
"$column",
"is",
"already",
"present",
"if",
"$aliasText",
"is",
"found",
"numeric",
"increments",
"are",
"added",
"to",
"it",
"if",
"$id",
"is",
"set",
"this",
"record",
"is",
"left",
"out",
"from",
"checking",
"returns",
"string",
"which",
"is",
"unique",
"in",
"$column"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Database/Util.php#L130-L170 |
raykolbe/CKEditorModule | src/CKEditorModule/View/Helper/CKEditor.php | CKEditor.getRenderedEditor | public function getRenderedEditor($id, array $options = array())
{
$config = clone $this->options;
$config->setFromArray($options);
$basePath = $this->getView()->basePath($config->getBasePath());
$editor = new \CKEditor($basePath);
return $editor->replace($id, $this->optionsToCKEditorConfig($config));
} | php | public function getRenderedEditor($id, array $options = array())
{
$config = clone $this->options;
$config->setFromArray($options);
$basePath = $this->getView()->basePath($config->getBasePath());
$editor = new \CKEditor($basePath);
return $editor->replace($id, $this->optionsToCKEditorConfig($config));
} | [
"public",
"function",
"getRenderedEditor",
"(",
"$",
"id",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"config",
"=",
"clone",
"$",
"this",
"->",
"options",
";",
"$",
"config",
"->",
"setFromArray",
"(",
"$",
"options",
")",
";",
"$",
"basePath",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"basePath",
"(",
"$",
"config",
"->",
"getBasePath",
"(",
")",
")",
";",
"$",
"editor",
"=",
"new",
"\\",
"CKEditor",
"(",
"$",
"basePath",
")",
";",
"return",
"$",
"editor",
"->",
"replace",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"optionsToCKEditorConfig",
"(",
"$",
"config",
")",
")",
";",
"}"
] | Generates output needed for CKEditor.
@param string $id The DOM ID to apply this editor to.
@param array $options An array of options specific to this instance.
@return string The HTML output. | [
"Generates",
"output",
"needed",
"for",
"CKEditor",
"."
] | train | https://github.com/raykolbe/CKEditorModule/blob/5088cc4ab085ee1e4ba9ee9d0209c27082c90259/src/CKEditorModule/View/Helper/CKEditor.php#L81-L90 |
raykolbe/CKEditorModule | src/CKEditorModule/View/Helper/CKEditor.php | CKEditor.optionsToCKEditorConfig | protected function optionsToCKEditorConfig(Options $options)
{
$config = array();
foreach ($options->toArray() as $key => $value) {
if (!array_key_exists($key, static::$optionsToConfigMap)) {
continue;
}
if (in_array($key, static::$optionsToPrependBasePath)) {
if (is_array($value)) {
foreach ($value as &$deepValue) {
$deepValue = $this->view->basePath($deepValue);
}
} else {
$value = $this->view->basePath($value);
}
}
$config[static::$optionsToConfigMap[$key]] = $value;
}
return $config;
} | php | protected function optionsToCKEditorConfig(Options $options)
{
$config = array();
foreach ($options->toArray() as $key => $value) {
if (!array_key_exists($key, static::$optionsToConfigMap)) {
continue;
}
if (in_array($key, static::$optionsToPrependBasePath)) {
if (is_array($value)) {
foreach ($value as &$deepValue) {
$deepValue = $this->view->basePath($deepValue);
}
} else {
$value = $this->view->basePath($value);
}
}
$config[static::$optionsToConfigMap[$key]] = $value;
}
return $config;
} | [
"protected",
"function",
"optionsToCKEditorConfig",
"(",
"Options",
"$",
"options",
")",
"{",
"$",
"config",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"options",
"->",
"toArray",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"static",
"::",
"$",
"optionsToConfigMap",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"static",
"::",
"$",
"optionsToPrependBasePath",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"&",
"$",
"deepValue",
")",
"{",
"$",
"deepValue",
"=",
"$",
"this",
"->",
"view",
"->",
"basePath",
"(",
"$",
"deepValue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"view",
"->",
"basePath",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"config",
"[",
"static",
"::",
"$",
"optionsToConfigMap",
"[",
"$",
"key",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Translates our internal Options object into a usable config array
for CKEditor.
@param \CKEditor\Options $options
@return array | [
"Translates",
"our",
"internal",
"Options",
"object",
"into",
"a",
"usable",
"config",
"array",
"for",
"CKEditor",
"."
] | train | https://github.com/raykolbe/CKEditorModule/blob/5088cc4ab085ee1e4ba9ee9d0209c27082c90259/src/CKEditorModule/View/Helper/CKEditor.php#L99-L121 |
Kris-Kuiper/sFire-Framework | src/Cache/Cache.php | Cache.setDriver | public function setDriver($driver) {
if(false === is_string($driver)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($driver)), E_USER_ERROR);
}
if(false === class_exists($driver)) {
$driver = __NAMESPACE__ . '\\Driver\\' . $driver;
if(false === class_exists($driver)) {
return trigger_error(sprintf('Driver "%s" does not exists', $driver), E_USER_ERROR);
}
}
$this -> driver = $driver;
return $this;
} | php | public function setDriver($driver) {
if(false === is_string($driver)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($driver)), E_USER_ERROR);
}
if(false === class_exists($driver)) {
$driver = __NAMESPACE__ . '\\Driver\\' . $driver;
if(false === class_exists($driver)) {
return trigger_error(sprintf('Driver "%s" does not exists', $driver), E_USER_ERROR);
}
}
$this -> driver = $driver;
return $this;
} | [
"public",
"function",
"setDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"driver",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"driver",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"driver",
")",
")",
"{",
"$",
"driver",
"=",
"__NAMESPACE__",
".",
"'\\\\Driver\\\\'",
".",
"$",
"driver",
";",
"if",
"(",
"false",
"===",
"class_exists",
"(",
"$",
"driver",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Driver \"%s\" does not exists'",
",",
"$",
"driver",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"}",
"$",
"this",
"->",
"driver",
"=",
"$",
"driver",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the driver
@param string $driver
@return sFire\Cache\Cache | [
"Sets",
"the",
"driver"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Cache.php#L34-L52 |
Kris-Kuiper/sFire-Framework | src/Cache/Cache.php | Cache.set | public function set($key, $value, $expiration = 300) {
if(false === ('-' . intval($expiration) == '-' . $expiration)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
}
$this -> call() -> set($key, $value, $expiration);
return $this;
} | php | public function set($key, $value, $expiration = 300) {
if(false === ('-' . intval($expiration) == '-' . $expiration)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
}
$this -> call() -> set($key, $value, $expiration);
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expiration",
"=",
"300",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"expiration",
")",
"==",
"'-'",
".",
"$",
"expiration",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"expiration",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"call",
"(",
")",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expiration",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set new cache by key name
@param mixed $key
@param mixed $value
@param int $expiration
@return sFire\Cache\Cache | [
"Set",
"new",
"cache",
"by",
"key",
"name"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Cache.php#L62-L70 |
Kris-Kuiper/sFire-Framework | src/Cache/Cache.php | Cache.touch | public function touch($key, $expiration = null) {
if(null !== $expiration && false === ('-' . intval($expiration) == '-' . $expiration)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
}
$this -> call() -> touch($key, $expiration);
return $this;
} | php | public function touch($key, $expiration = null) {
if(null !== $expiration && false === ('-' . intval($expiration) == '-' . $expiration)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($expiration)), E_USER_ERROR);
}
$this -> call() -> touch($key, $expiration);
return $this;
} | [
"public",
"function",
"touch",
"(",
"$",
"key",
",",
"$",
"expiration",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"expiration",
"&&",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"expiration",
")",
"==",
"'-'",
".",
"$",
"expiration",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"expiration",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"call",
"(",
")",
"->",
"touch",
"(",
"$",
"key",
",",
"$",
"expiration",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Reset lifetime of a cached file
@param mixed $key
@param int $expiration
@return sFire\Cache\Cache | [
"Reset",
"lifetime",
"of",
"a",
"cached",
"file"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Cache.php#L113-L121 |
Kris-Kuiper/sFire-Framework | src/Cache/Cache.php | Cache.call | private function call() {
if(null === $this -> driver) {
return trigger_error('Driver is not set. Set the driver with the setDriver() method', E_USER_ERROR);
}
if(null === $this -> driverInstance) {
$this -> driverInstance = new $this -> driver();
}
return $this -> driverInstance;
} | php | private function call() {
if(null === $this -> driver) {
return trigger_error('Driver is not set. Set the driver with the setDriver() method', E_USER_ERROR);
}
if(null === $this -> driverInstance) {
$this -> driverInstance = new $this -> driver();
}
return $this -> driverInstance;
} | [
"private",
"function",
"call",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"driver",
")",
"{",
"return",
"trigger_error",
"(",
"'Driver is not set. Set the driver with the setDriver() method'",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"driverInstance",
")",
"{",
"$",
"this",
"->",
"driverInstance",
"=",
"new",
"$",
"this",
"->",
"driver",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"driverInstance",
";",
"}"
] | Check if driver is set and returns it
@return mixed | [
"Check",
"if",
"driver",
"is",
"set",
"and",
"returns",
"it"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Cache/Cache.php#L137-L148 |
dms-org/common.structure | src/DateTime/TimeRange.php | TimeRange.contains | public function contains(TimeOfDay $time) : bool
{
return $this->start->isEarlierThanOrEqual($time) && $this->end->isLaterThanOrEqual($time);
} | php | public function contains(TimeOfDay $time) : bool
{
return $this->start->isEarlierThanOrEqual($time) && $this->end->isLaterThanOrEqual($time);
} | [
"public",
"function",
"contains",
"(",
"TimeOfDay",
"$",
"time",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"start",
"->",
"isEarlierThanOrEqual",
"(",
"$",
"time",
")",
"&&",
"$",
"this",
"->",
"end",
"->",
"isLaterThanOrEqual",
"(",
"$",
"time",
")",
";",
"}"
] | Returns whether the supplied time is within (inclusive) the time range.
@param TimeOfDay $time
@return bool | [
"Returns",
"whether",
"the",
"supplied",
"time",
"is",
"within",
"(",
"inclusive",
")",
"the",
"time",
"range",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimeRange.php#L68-L71 |
dms-org/common.structure | src/DateTime/TimeRange.php | TimeRange.containsExclusive | public function containsExclusive(TimeOfDay $time) : bool
{
return $this->start->isEarlierThan($time) && $this->end->isLaterThan($time);
} | php | public function containsExclusive(TimeOfDay $time) : bool
{
return $this->start->isEarlierThan($time) && $this->end->isLaterThan($time);
} | [
"public",
"function",
"containsExclusive",
"(",
"TimeOfDay",
"$",
"time",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"start",
"->",
"isEarlierThan",
"(",
"$",
"time",
")",
"&&",
"$",
"this",
"->",
"end",
"->",
"isLaterThan",
"(",
"$",
"time",
")",
";",
"}"
] | Returns whether the supplied time is within (exclusive) the time range.
@param TimeOfDay $time
@return bool | [
"Returns",
"whether",
"the",
"supplied",
"time",
"is",
"within",
"(",
"exclusive",
")",
"the",
"time",
"range",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimeRange.php#L80-L83 |
dms-org/common.structure | src/DateTime/TimeRange.php | TimeRange.encompasses | public function encompasses(TimeRange $otherRange) : bool
{
return $this->start->isEarlierThanOrEqual($otherRange->start) && $this->end->isLaterThanOrEqual($otherRange->end);
} | php | public function encompasses(TimeRange $otherRange) : bool
{
return $this->start->isEarlierThanOrEqual($otherRange->start) && $this->end->isLaterThanOrEqual($otherRange->end);
} | [
"public",
"function",
"encompasses",
"(",
"TimeRange",
"$",
"otherRange",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"start",
"->",
"isEarlierThanOrEqual",
"(",
"$",
"otherRange",
"->",
"start",
")",
"&&",
"$",
"this",
"->",
"end",
"->",
"isLaterThanOrEqual",
"(",
"$",
"otherRange",
"->",
"end",
")",
";",
"}"
] | Returns whether the supplied time range is encompassed by this
time range.
@param TimeRange $otherRange
@return bool | [
"Returns",
"whether",
"the",
"supplied",
"time",
"range",
"is",
"encompassed",
"by",
"this",
"time",
"range",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimeRange.php#L93-L96 |
dms-org/common.structure | src/DateTime/TimeRange.php | TimeRange.overlapsExclusive | public function overlapsExclusive(TimeRange $otherRange) : bool
{
return $this->containsExclusive($otherRange->start) || $this->containsExclusive($otherRange->end)
|| $this->encompasses($otherRange)
|| $otherRange->encompasses($this);
} | php | public function overlapsExclusive(TimeRange $otherRange) : bool
{
return $this->containsExclusive($otherRange->start) || $this->containsExclusive($otherRange->end)
|| $this->encompasses($otherRange)
|| $otherRange->encompasses($this);
} | [
"public",
"function",
"overlapsExclusive",
"(",
"TimeRange",
"$",
"otherRange",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"containsExclusive",
"(",
"$",
"otherRange",
"->",
"start",
")",
"||",
"$",
"this",
"->",
"containsExclusive",
"(",
"$",
"otherRange",
"->",
"end",
")",
"||",
"$",
"this",
"->",
"encompasses",
"(",
"$",
"otherRange",
")",
"||",
"$",
"otherRange",
"->",
"encompasses",
"(",
"$",
"this",
")",
";",
"}"
] | Returns whether the supplied time range overlaps (exclusive) this time range.
@param TimeRange $otherRange
@return bool | [
"Returns",
"whether",
"the",
"supplied",
"time",
"range",
"overlaps",
"(",
"exclusive",
")",
"this",
"time",
"range",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimeRange.php#L119-L124 |
fulgurio/LightCMSBundle | Utils/LightCMSUtils.php | LightCMSUtils.getUploadDir | static function getUploadDir($withUploadUrl = TRUE)
{
$dir = __DIR__ . '/../../../../web/';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../web';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../../web';
if (!is_dir($dir))
{
throw new \Exception('Upload dir not found');
}
}
}
if (!is_dir($dir . self::getUploadUrl()))
{
if (!is_writable($dir))
{
throw new \Exception($dir . ' is not writable');
}
else
{
mkdir($dir . self::getUploadUrl());
}
}
return $withUploadUrl ? $dir . self::getUploadUrl() : $dir;
} | php | static function getUploadDir($withUploadUrl = TRUE)
{
$dir = __DIR__ . '/../../../../web/';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../web';
if (!is_dir($dir))
{
$dir = __DIR__ . '/../../../../../../web';
if (!is_dir($dir))
{
throw new \Exception('Upload dir not found');
}
}
}
if (!is_dir($dir . self::getUploadUrl()))
{
if (!is_writable($dir))
{
throw new \Exception($dir . ' is not writable');
}
else
{
mkdir($dir . self::getUploadUrl());
}
}
return $withUploadUrl ? $dir . self::getUploadUrl() : $dir;
} | [
"static",
"function",
"getUploadDir",
"(",
"$",
"withUploadUrl",
"=",
"TRUE",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../../../web/'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../../../../web'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dir",
"=",
"__DIR__",
".",
"'/../../../../../../web'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Upload dir not found'",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
".",
"self",
"::",
"getUploadUrl",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"dir",
".",
"' is not writable'",
")",
";",
"}",
"else",
"{",
"mkdir",
"(",
"$",
"dir",
".",
"self",
"::",
"getUploadUrl",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"withUploadUrl",
"?",
"$",
"dir",
".",
"self",
"::",
"getUploadUrl",
"(",
")",
":",
"$",
"dir",
";",
"}"
] | Get upload file dir
@throws \Exception | [
"Get",
"upload",
"file",
"dir"
] | train | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Utils/LightCMSUtils.php#L23-L50 |
fulgurio/LightCMSBundle | Utils/LightCMSUtils.php | LightCMSUtils.getThumbFilename | static public function getThumbFilename($filename, $mimeType, $size)
{
if (substr($mimeType, 0, 5) == 'image')
{
$pos = mb_strrpos($filename, '.');
if ($pos === FALSE)
{
return $filename . '_' . $size['width'] . 'x' . $size['height'];
}
else
{
return mb_substr($filename, 0, $pos) . '_' . $size['width'] . 'x' . $size['height'] . mb_substr($filename, $pos);
}
}
else if ($mimeType == 'application/pdf')
{
return $GLOBALS['kernel']->getContainer()->get('templating.helper.assets')->getUrl('bundles/fulguriolightcms/img/thumb_pdf.png');
}
else
{
return 'http://www.placehold.it/' . $size['width'] . 'x' . $size['height'] . '/EFEFEF/AAAAAA';
}
} | php | static public function getThumbFilename($filename, $mimeType, $size)
{
if (substr($mimeType, 0, 5) == 'image')
{
$pos = mb_strrpos($filename, '.');
if ($pos === FALSE)
{
return $filename . '_' . $size['width'] . 'x' . $size['height'];
}
else
{
return mb_substr($filename, 0, $pos) . '_' . $size['width'] . 'x' . $size['height'] . mb_substr($filename, $pos);
}
}
else if ($mimeType == 'application/pdf')
{
return $GLOBALS['kernel']->getContainer()->get('templating.helper.assets')->getUrl('bundles/fulguriolightcms/img/thumb_pdf.png');
}
else
{
return 'http://www.placehold.it/' . $size['width'] . 'x' . $size['height'] . '/EFEFEF/AAAAAA';
}
} | [
"static",
"public",
"function",
"getThumbFilename",
"(",
"$",
"filename",
",",
"$",
"mimeType",
",",
"$",
"size",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"mimeType",
",",
"0",
",",
"5",
")",
"==",
"'image'",
")",
"{",
"$",
"pos",
"=",
"mb_strrpos",
"(",
"$",
"filename",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"FALSE",
")",
"{",
"return",
"$",
"filename",
".",
"'_'",
".",
"$",
"size",
"[",
"'width'",
"]",
".",
"'x'",
".",
"$",
"size",
"[",
"'height'",
"]",
";",
"}",
"else",
"{",
"return",
"mb_substr",
"(",
"$",
"filename",
",",
"0",
",",
"$",
"pos",
")",
".",
"'_'",
".",
"$",
"size",
"[",
"'width'",
"]",
".",
"'x'",
".",
"$",
"size",
"[",
"'height'",
"]",
".",
"mb_substr",
"(",
"$",
"filename",
",",
"$",
"pos",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"mimeType",
"==",
"'application/pdf'",
")",
"{",
"return",
"$",
"GLOBALS",
"[",
"'kernel'",
"]",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'templating.helper.assets'",
")",
"->",
"getUrl",
"(",
"'bundles/fulguriolightcms/img/thumb_pdf.png'",
")",
";",
"}",
"else",
"{",
"return",
"'http://www.placehold.it/'",
".",
"$",
"size",
"[",
"'width'",
"]",
".",
"'x'",
".",
"$",
"size",
"[",
"'height'",
"]",
".",
"'/EFEFEF/AAAAAA'",
";",
"}",
"}"
] | Get thumb filename for a specified size
@param string $filename
@param string $mimeType
@param array $size Contains width and height
@return string | [
"Get",
"thumb",
"filename",
"for",
"a",
"specified",
"size"
] | train | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Utils/LightCMSUtils.php#L70-L92 |
fulgurio/LightCMSBundle | Utils/LightCMSUtils.php | LightCMSUtils.cropPicture | static function cropPicture($sourcefile, $destfile, $fw, $fh, $jpegquality = 80)
{
list($ow, $oh, $from_type) = getimagesize($sourcefile);
switch($from_type)
{
case 1: // GIF
$srcImage = imageCreateFromGif($sourcefile) or die('Impossible de convertir cette image');
break;
case 2: // JPG
$srcImage = imageCreateFromJpeg($sourcefile) or die('Impossible de convertir cette image');
break;
case 3: // PNG
$srcImage = imageCreateFromPng($sourcefile) or die('Impossible de convertir cette image');
break;
default:
return;
}
if (($fw / $ow) > ($fh / $oh))
{
$tempw = $fw;
$temph = ($fw / $ow) * $oh;
}
else {
$tempw = ($fh / $oh) * $ow;
$temph = $fh;
}
$tempImage = imageCreateTrueColor($fw, $fh);
// imageAntiAlias($tempImage, true);
imagecopyresampled($tempImage, $srcImage, ($fw - $tempw) / 2, ($fh - $temph) / 2, 0, 0, $tempw, $temph, $ow, $oh);
imageJpeg($tempImage, $destfile, $jpegquality);
return getimagesize($destfile);
} | php | static function cropPicture($sourcefile, $destfile, $fw, $fh, $jpegquality = 80)
{
list($ow, $oh, $from_type) = getimagesize($sourcefile);
switch($from_type)
{
case 1: // GIF
$srcImage = imageCreateFromGif($sourcefile) or die('Impossible de convertir cette image');
break;
case 2: // JPG
$srcImage = imageCreateFromJpeg($sourcefile) or die('Impossible de convertir cette image');
break;
case 3: // PNG
$srcImage = imageCreateFromPng($sourcefile) or die('Impossible de convertir cette image');
break;
default:
return;
}
if (($fw / $ow) > ($fh / $oh))
{
$tempw = $fw;
$temph = ($fw / $ow) * $oh;
}
else {
$tempw = ($fh / $oh) * $ow;
$temph = $fh;
}
$tempImage = imageCreateTrueColor($fw, $fh);
// imageAntiAlias($tempImage, true);
imagecopyresampled($tempImage, $srcImage, ($fw - $tempw) / 2, ($fh - $temph) / 2, 0, 0, $tempw, $temph, $ow, $oh);
imageJpeg($tempImage, $destfile, $jpegquality);
return getimagesize($destfile);
} | [
"static",
"function",
"cropPicture",
"(",
"$",
"sourcefile",
",",
"$",
"destfile",
",",
"$",
"fw",
",",
"$",
"fh",
",",
"$",
"jpegquality",
"=",
"80",
")",
"{",
"list",
"(",
"$",
"ow",
",",
"$",
"oh",
",",
"$",
"from_type",
")",
"=",
"getimagesize",
"(",
"$",
"sourcefile",
")",
";",
"switch",
"(",
"$",
"from_type",
")",
"{",
"case",
"1",
":",
"// GIF",
"$",
"srcImage",
"=",
"imageCreateFromGif",
"(",
"$",
"sourcefile",
")",
"or",
"die",
"(",
"'Impossible de convertir cette image'",
")",
";",
"break",
";",
"case",
"2",
":",
"// JPG",
"$",
"srcImage",
"=",
"imageCreateFromJpeg",
"(",
"$",
"sourcefile",
")",
"or",
"die",
"(",
"'Impossible de convertir cette image'",
")",
";",
"break",
";",
"case",
"3",
":",
"// PNG",
"$",
"srcImage",
"=",
"imageCreateFromPng",
"(",
"$",
"sourcefile",
")",
"or",
"die",
"(",
"'Impossible de convertir cette image'",
")",
";",
"break",
";",
"default",
":",
"return",
";",
"}",
"if",
"(",
"(",
"$",
"fw",
"/",
"$",
"ow",
")",
">",
"(",
"$",
"fh",
"/",
"$",
"oh",
")",
")",
"{",
"$",
"tempw",
"=",
"$",
"fw",
";",
"$",
"temph",
"=",
"(",
"$",
"fw",
"/",
"$",
"ow",
")",
"*",
"$",
"oh",
";",
"}",
"else",
"{",
"$",
"tempw",
"=",
"(",
"$",
"fh",
"/",
"$",
"oh",
")",
"*",
"$",
"ow",
";",
"$",
"temph",
"=",
"$",
"fh",
";",
"}",
"$",
"tempImage",
"=",
"imageCreateTrueColor",
"(",
"$",
"fw",
",",
"$",
"fh",
")",
";",
"// imageAntiAlias($tempImage, true);",
"imagecopyresampled",
"(",
"$",
"tempImage",
",",
"$",
"srcImage",
",",
"(",
"$",
"fw",
"-",
"$",
"tempw",
")",
"/",
"2",
",",
"(",
"$",
"fh",
"-",
"$",
"temph",
")",
"/",
"2",
",",
"0",
",",
"0",
",",
"$",
"tempw",
",",
"$",
"temph",
",",
"$",
"ow",
",",
"$",
"oh",
")",
";",
"imageJpeg",
"(",
"$",
"tempImage",
",",
"$",
"destfile",
",",
"$",
"jpegquality",
")",
";",
"return",
"getimagesize",
"(",
"$",
"destfile",
")",
";",
"}"
] | Image cropper
@param string $sourcefile
@param string $destfile
@param number $fw
@param number $fh
@param number $jpegquality
@todo : use Exception | [
"Image",
"cropper"
] | train | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Utils/LightCMSUtils.php#L104-L135 |
fulgurio/LightCMSBundle | Utils/LightCMSUtils.php | LightCMSUtils.makeSlug | static public function makeSlug($title, $isFile = FALSE)
{
$slug = strtr(
utf8_decode(mb_strtolower($title, 'UTF-8')),
utf8_decode(
'àáâãäåòóôõöøèéêëçìíîïùúûüÿñ'),
'aaaaaaooooooeeeeciiiiuuuuyn');
if ($isFile)
{
return preg_replace(array('`[^a-z0-9\._]`i', '`[-]+`'), '-', $slug);
}
return preg_replace(array('`[^a-z0-9]`i', '`[-]+`'), '-', $slug);
} | php | static public function makeSlug($title, $isFile = FALSE)
{
$slug = strtr(
utf8_decode(mb_strtolower($title, 'UTF-8')),
utf8_decode(
'àáâãäåòóôõöøèéêëçìíîïùúûüÿñ'),
'aaaaaaooooooeeeeciiiiuuuuyn');
if ($isFile)
{
return preg_replace(array('`[^a-z0-9\._]`i', '`[-]+`'), '-', $slug);
}
return preg_replace(array('`[^a-z0-9]`i', '`[-]+`'), '-', $slug);
} | [
"static",
"public",
"function",
"makeSlug",
"(",
"$",
"title",
",",
"$",
"isFile",
"=",
"FALSE",
")",
"{",
"$",
"slug",
"=",
"strtr",
"(",
"utf8_decode",
"(",
"mb_strtolower",
"(",
"$",
"title",
",",
"'UTF-8'",
")",
")",
",",
"utf8_decode",
"(",
"'àáâãäåòóôõöøèéêëçìíîïùúûüÿñ'),",
"",
"",
"'aaaaaaooooooeeeeciiiiuuuuyn'",
")",
";",
"if",
"(",
"$",
"isFile",
")",
"{",
"return",
"preg_replace",
"(",
"array",
"(",
"'`[^a-z0-9\\._]`i'",
",",
"'`[-]+`'",
")",
",",
"'-'",
",",
"$",
"slug",
")",
";",
"}",
"return",
"preg_replace",
"(",
"array",
"(",
"'`[^a-z0-9]`i'",
",",
"'`[-]+`'",
")",
",",
"'-'",
",",
"$",
"slug",
")",
";",
"}"
] | Generate slug
@param string $title
@param boolean $isFile Allow "_" and "." characters if TRUE
@return string | [
"Generate",
"slug"
] | train | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Utils/LightCMSUtils.php#L144-L156 |
mwyatt/core | src/Cookie.php | Cookie.set | public function set($key, $value, $time)
{
if (isset($_COOKIE[$key])) {
setcookie($key, $value);
} else {
setcookie($key, $value, $time);
}
} | php | public function set($key, $value, $time)
{
if (isset($_COOKIE[$key])) {
setcookie($key, $value);
} else {
setcookie($key, $value, $time);
}
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"time",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"key",
"]",
")",
")",
"{",
"setcookie",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"setcookie",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"time",
")",
";",
"}",
"}"
] | If output exists prior to calling this function, setcookie() will fail
and return FALSE. If setcookie() successfully runs, it will return
TRUE. This does not indicate whether the user accepted the cookie.
updates the cookie if already set
@param string $key
@param string $value
@param int $time epoch | [
"If",
"output",
"exists",
"prior",
"to",
"calling",
"this",
"function",
"setcookie",
"()",
"will",
"fail",
"and",
"return",
"FALSE",
".",
"If",
"setcookie",
"()",
"successfully",
"runs",
"it",
"will",
"return",
"TRUE",
".",
"This",
"does",
"not",
"indicate",
"whether",
"the",
"user",
"accepted",
"the",
"cookie",
"."
] | train | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Cookie.php#L26-L33 |
koolkode/view | src/AbstractViewRenderer.php | AbstractViewRenderer.partial | protected function partial($resource, array $data = [])
{
if($resource instanceof ViewModelInterface)
{
return $this->view->render($resource, true);
}
return $this->view->render(new ViewModel($this->view->resolveResourcePath($resource), $data), true);
} | php | protected function partial($resource, array $data = [])
{
if($resource instanceof ViewModelInterface)
{
return $this->view->render($resource, true);
}
return $this->view->render(new ViewModel($this->view->resolveResourcePath($resource), $data), true);
} | [
"protected",
"function",
"partial",
"(",
"$",
"resource",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"resource",
"instanceof",
"ViewModelInterface",
")",
"{",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"$",
"resource",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"view",
"->",
"render",
"(",
"new",
"ViewModel",
"(",
"$",
"this",
"->",
"view",
"->",
"resolveResourcePath",
"(",
"$",
"resource",
")",
",",
"$",
"data",
")",
",",
"true",
")",
";",
"}"
] | Render a partial view and return the generated output.
@param string|ViewModelInterface $resource
@param array<string, mixed> $data | [
"Render",
"a",
"partial",
"view",
"and",
"return",
"the",
"generated",
"output",
"."
] | train | https://github.com/koolkode/view/blob/70a6784611c7184805d5a18fe6f7e534e4e44c59/src/AbstractViewRenderer.php#L59-L67 |
ThomasSquall/PHPMagicAnnotations | src/Reflection/Reflector.php | Reflector.getProperty | public function getProperty($name)
{
if ($this->reflected->hasProperty($name))
return $this->annotations['properties'][$name];
return null;
} | php | public function getProperty($name)
{
if ($this->reflected->hasProperty($name))
return $this->annotations['properties'][$name];
return null;
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"reflected",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"annotations",
"[",
"'properties'",
"]",
"[",
"$",
"name",
"]",
";",
"return",
"null",
";",
"}"
] | Returns the reflected parameter.
@param string $name
@return ReflectionProperty | [
"Returns",
"the",
"reflected",
"parameter",
"."
] | train | https://github.com/ThomasSquall/PHPMagicAnnotations/blob/3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001/src/Reflection/Reflector.php#L96-L102 |
ThomasSquall/PHPMagicAnnotations | src/Reflection/Reflector.php | Reflector.getMethod | public function getMethod($name)
{
if ($this->reflected->hasMethod($name))
return $this->annotations['methods'][$name];
return null;
} | php | public function getMethod($name)
{
if ($this->reflected->hasMethod($name))
return $this->annotations['methods'][$name];
return null;
} | [
"public",
"function",
"getMethod",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"reflected",
"->",
"hasMethod",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"annotations",
"[",
"'methods'",
"]",
"[",
"$",
"name",
"]",
";",
"return",
"null",
";",
"}"
] | Returns the reflected method.
@param string $name
@return ReflectionMethod | [
"Returns",
"the",
"reflected",
"method",
"."
] | train | https://github.com/ThomasSquall/PHPMagicAnnotations/blob/3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001/src/Reflection/Reflector.php#L118-L124 |
Bistro/Router | lib/Bistro/Router/Router.php | Router.match | public function match($method, $url)
{
$params = array();
foreach ($this->routes as $name => $route)
{
if ($route->isMatch($method, $url))
{
$params = $route->getMatchedParams();
break;
}
}
return $params;
} | php | public function match($method, $url)
{
$params = array();
foreach ($this->routes as $name => $route)
{
if ($route->isMatch($method, $url))
{
$params = $route->getMatchedParams();
break;
}
}
return $params;
} | [
"public",
"function",
"match",
"(",
"$",
"method",
",",
"$",
"url",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"isMatch",
"(",
"$",
"method",
",",
"$",
"url",
")",
")",
"{",
"$",
"params",
"=",
"$",
"route",
"->",
"getMatchedParams",
"(",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"params",
";",
"}"
] | Loops through all of the registered routes and tries to find a match.
@param string $method The http request method
@param string $url The url to match
@return array An array of matches params or an empty array | [
"Loops",
"through",
"all",
"of",
"the",
"registered",
"routes",
"and",
"tries",
"to",
"find",
"a",
"match",
"."
] | train | https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Router.php#L53-L67 |
Bistro/Router | lib/Bistro/Router/Router.php | Router.add | public function add($name, $pattern, $responds_to = array("GET", "POST", "PUT", "DELETE"))
{
$route = new Route($this->sub_directory.$pattern, $responds_to);
$this->routes[$name] = $route;
return $route;
} | php | public function add($name, $pattern, $responds_to = array("GET", "POST", "PUT", "DELETE"))
{
$route = new Route($this->sub_directory.$pattern, $responds_to);
$this->routes[$name] = $route;
return $route;
} | [
"public",
"function",
"add",
"(",
"$",
"name",
",",
"$",
"pattern",
",",
"$",
"responds_to",
"=",
"array",
"(",
"\"GET\"",
",",
"\"POST\"",
",",
"\"PUT\"",
",",
"\"DELETE\"",
")",
")",
"{",
"$",
"route",
"=",
"new",
"Route",
"(",
"$",
"this",
"->",
"sub_directory",
".",
"$",
"pattern",
",",
"$",
"responds_to",
")",
";",
"$",
"this",
"->",
"routes",
"[",
"$",
"name",
"]",
"=",
"$",
"route",
";",
"return",
"$",
"route",
";",
"}"
] | Adds a route.
@param string $name The route name
@param string $pattern The pattern for the route to match
@param array $responds_to An array of http verbs the route responds to.
@return \Bistro\Router\Route | [
"Adds",
"a",
"route",
"."
] | train | https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Router.php#L77-L82 |
Bistro/Router | lib/Bistro/Router/Router.php | Router.url | public function url($name, $params = array())
{
if ( ! array_key_exists($name, $this->routes))
{
throw new \UnexpectedValueException("A route with the name {$name} was not found");
}
$route = $this->routes[$name];
return $route->url($params);
} | php | public function url($name, $params = array())
{
if ( ! array_key_exists($name, $this->routes))
{
throw new \UnexpectedValueException("A route with the name {$name} was not found");
}
$route = $this->routes[$name];
return $route->url($params);
} | [
"public",
"function",
"url",
"(",
"$",
"name",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"A route with the name {$name} was not found\"",
")",
";",
"}",
"$",
"route",
"=",
"$",
"this",
"->",
"routes",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"route",
"->",
"url",
"(",
"$",
"params",
")",
";",
"}"
] | Reverse routing helper.
@throws \UnexpectedValueException
@param string $name The route name
@param array $params Route parameters
@return string The route url | [
"Reverse",
"routing",
"helper",
"."
] | train | https://github.com/Bistro/Router/blob/ab5c3fff119c0e6c43c05300122b236afabfff41/lib/Bistro/Router/Router.php#L141-L150 |
EvanDarwin/JSend | src/JSendResponse.php | JSendResponse.getArray | public function getArray()
{
$errors = empty($this->errors) ? null : $this->errors;
$response = array(
'status' => $this->getStatus(),
'data' => $this->data,
'errors' => $errors,
);
if (!is_null($this->code)) {
$response['code'] = $this->code;
}
if (!is_null($this->message)) {
$response['message'] = $this->message;
}
return $response;
} | php | public function getArray()
{
$errors = empty($this->errors) ? null : $this->errors;
$response = array(
'status' => $this->getStatus(),
'data' => $this->data,
'errors' => $errors,
);
if (!is_null($this->code)) {
$response['code'] = $this->code;
}
if (!is_null($this->message)) {
$response['message'] = $this->message;
}
return $response;
} | [
"public",
"function",
"getArray",
"(",
")",
"{",
"$",
"errors",
"=",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
"?",
"null",
":",
"$",
"this",
"->",
"errors",
";",
"$",
"response",
"=",
"array",
"(",
"'status'",
"=>",
"$",
"this",
"->",
"getStatus",
"(",
")",
",",
"'data'",
"=>",
"$",
"this",
"->",
"data",
",",
"'errors'",
"=>",
"$",
"errors",
",",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"code",
")",
")",
"{",
"$",
"response",
"[",
"'code'",
"]",
"=",
"$",
"this",
"->",
"code",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"message",
")",
")",
"{",
"$",
"response",
"[",
"'message'",
"]",
"=",
"$",
"this",
"->",
"message",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Returns the array version of the request response
@return array | [
"Returns",
"the",
"array",
"version",
"of",
"the",
"request",
"response"
] | train | https://github.com/EvanDarwin/JSend/blob/a31f7590e8503590d10012510ffc50a0ef064d02/src/JSendResponse.php#L117-L136 |
geoffroy-aubry/ErrorHandler | src/GAubry/ErrorHandler/ErrorHandler.php | ErrorHandler.addExcludedPath | public function addExcludedPath($sPath, $bEnforce = false)
{
if (substr($sPath, -1) !== '/') {
$sPath .= '/';
}
if (! $bEnforce) {
$sPath = realpath($sPath);
}
if (! in_array($sPath, $this->aExcludedPaths)) {
$this->aExcludedPaths[] = $sPath;
}
} | php | public function addExcludedPath($sPath, $bEnforce = false)
{
if (substr($sPath, -1) !== '/') {
$sPath .= '/';
}
if (! $bEnforce) {
$sPath = realpath($sPath);
}
if (! in_array($sPath, $this->aExcludedPaths)) {
$this->aExcludedPaths[] = $sPath;
}
} | [
"public",
"function",
"addExcludedPath",
"(",
"$",
"sPath",
",",
"$",
"bEnforce",
"=",
"false",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"sPath",
",",
"-",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"sPath",
".=",
"'/'",
";",
"}",
"if",
"(",
"!",
"$",
"bEnforce",
")",
"{",
"$",
"sPath",
"=",
"realpath",
"(",
"$",
"sPath",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"sPath",
",",
"$",
"this",
"->",
"aExcludedPaths",
")",
")",
"{",
"$",
"this",
"->",
"aExcludedPaths",
"[",
"]",
"=",
"$",
"sPath",
";",
"}",
"}"
] | Allows to ignore errors on some paths, useful with old libraries and deprecated code…
Trailing slash is optional.
@param string $sPath
@param bool $bEnforce By default all paths are normalized with realpath().
Set TRUE to avoid normalization.
Useful, for example, with some external PHP modules:
Couchbase PHP module say error was raised in "[CouchbaseNative]/" filename…
@see internalErrorHandler() | [
"Allows",
"to",
"ignore",
"errors",
"on",
"some",
"paths",
"useful",
"with",
"old",
"libraries",
"and",
"deprecated",
"code…",
"Trailing",
"slash",
"is",
"optional",
"."
] | train | https://github.com/geoffroy-aubry/ErrorHandler/blob/77575e8e0e4312f9a5f334e27c33549ec6adb35b/src/GAubry/ErrorHandler/ErrorHandler.php#L155-L166 |
geoffroy-aubry/ErrorHandler | src/GAubry/ErrorHandler/ErrorHandler.php | ErrorHandler.internalErrorHandler | public function internalErrorHandler($iErrNo, $sErrStr, $sErrFile, $iErrLine)
{
// Si l'erreur provient d'un répertoire exclu de ce handler, alors l'ignorer.
foreach ($this->aExcludedPaths as $sExcludedPath) {
if (stripos($sErrFile, $sExcludedPath) === 0) {
return true;
}
}
// Gestion de l'éventuel @ (error suppression operator) :
if ($this->aConfig['error_reporting_level'] !== 0
&& error_reporting() === 0 && $this->aConfig['auth_error_suppr_op']
) {
$iErrorReporting = 0;
} else {
$iErrorReporting = $this->aConfig['error_reporting_level'];
}
// Le seuil de transformation en exception est-il atteint ?
if (($iErrorReporting & $iErrNo) !== 0) {
$msg = "[from error handler] " . self::$aErrorTypes[$iErrNo]
. " -- $sErrStr, in file: '$sErrFile', line $iErrLine";
throw new \ErrorException($msg, $this->aConfig['default_error_code'], $iErrNo, $sErrFile, $iErrLine);
}
return true;
} | php | public function internalErrorHandler($iErrNo, $sErrStr, $sErrFile, $iErrLine)
{
// Si l'erreur provient d'un répertoire exclu de ce handler, alors l'ignorer.
foreach ($this->aExcludedPaths as $sExcludedPath) {
if (stripos($sErrFile, $sExcludedPath) === 0) {
return true;
}
}
// Gestion de l'éventuel @ (error suppression operator) :
if ($this->aConfig['error_reporting_level'] !== 0
&& error_reporting() === 0 && $this->aConfig['auth_error_suppr_op']
) {
$iErrorReporting = 0;
} else {
$iErrorReporting = $this->aConfig['error_reporting_level'];
}
// Le seuil de transformation en exception est-il atteint ?
if (($iErrorReporting & $iErrNo) !== 0) {
$msg = "[from error handler] " . self::$aErrorTypes[$iErrNo]
. " -- $sErrStr, in file: '$sErrFile', line $iErrLine";
throw new \ErrorException($msg, $this->aConfig['default_error_code'], $iErrNo, $sErrFile, $iErrLine);
}
return true;
} | [
"public",
"function",
"internalErrorHandler",
"(",
"$",
"iErrNo",
",",
"$",
"sErrStr",
",",
"$",
"sErrFile",
",",
"$",
"iErrLine",
")",
"{",
"// Si l'erreur provient d'un répertoire exclu de ce handler, alors l'ignorer.",
"foreach",
"(",
"$",
"this",
"->",
"aExcludedPaths",
"as",
"$",
"sExcludedPath",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"sErrFile",
",",
"$",
"sExcludedPath",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// Gestion de l'éventuel @ (error suppression operator) :",
"if",
"(",
"$",
"this",
"->",
"aConfig",
"[",
"'error_reporting_level'",
"]",
"!==",
"0",
"&&",
"error_reporting",
"(",
")",
"===",
"0",
"&&",
"$",
"this",
"->",
"aConfig",
"[",
"'auth_error_suppr_op'",
"]",
")",
"{",
"$",
"iErrorReporting",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"iErrorReporting",
"=",
"$",
"this",
"->",
"aConfig",
"[",
"'error_reporting_level'",
"]",
";",
"}",
"// Le seuil de transformation en exception est-il atteint ?",
"if",
"(",
"(",
"$",
"iErrorReporting",
"&",
"$",
"iErrNo",
")",
"!==",
"0",
")",
"{",
"$",
"msg",
"=",
"\"[from error handler] \"",
".",
"self",
"::",
"$",
"aErrorTypes",
"[",
"$",
"iErrNo",
"]",
".",
"\" -- $sErrStr, in file: '$sErrFile', line $iErrLine\"",
";",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"msg",
",",
"$",
"this",
"->",
"aConfig",
"[",
"'default_error_code'",
"]",
",",
"$",
"iErrNo",
",",
"$",
"sErrFile",
",",
"$",
"iErrLine",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Customized error handler function: throws an Exception with the message error if @ operator not used
and error source is not in excluded paths.
@param int $iErrNo level of the error raised.
@param string $sErrStr the error message.
@param string $sErrFile the filename that the error was raised in.
@param int $iErrLine the line number the error was raised at.
@throws \ErrorException if $iErrNo is present in $iErrorReporting
@return boolean true, then the normal error handler does not continue.
@see addExcludedPath() | [
"Customized",
"error",
"handler",
"function",
":",
"throws",
"an",
"Exception",
"with",
"the",
"message",
"error",
"if",
"@",
"operator",
"not",
"used",
"and",
"error",
"source",
"is",
"not",
"in",
"excluded",
"paths",
"."
] | train | https://github.com/geoffroy-aubry/ErrorHandler/blob/77575e8e0e4312f9a5f334e27c33549ec6adb35b/src/GAubry/ErrorHandler/ErrorHandler.php#L201-L226 |
geoffroy-aubry/ErrorHandler | src/GAubry/ErrorHandler/ErrorHandler.php | ErrorHandler.internalExceptionHandler | public function internalExceptionHandler(\Exception $oException)
{
if (! $this->aConfig['display_errors'] && ini_get('error_log') !== '' && ! $this->bIsRunningFromCLI) {
call_user_func($this->callbackGenericDisplay, $oException);
}
$this->log($oException);
if ($oException->getCode() != 0) {
$iErrorCode = $oException->getCode();
} else {
$iErrorCode = $this->aConfig['default_error_code'];
}
exit($iErrorCode);
} | php | public function internalExceptionHandler(\Exception $oException)
{
if (! $this->aConfig['display_errors'] && ini_get('error_log') !== '' && ! $this->bIsRunningFromCLI) {
call_user_func($this->callbackGenericDisplay, $oException);
}
$this->log($oException);
if ($oException->getCode() != 0) {
$iErrorCode = $oException->getCode();
} else {
$iErrorCode = $this->aConfig['default_error_code'];
}
exit($iErrorCode);
} | [
"public",
"function",
"internalExceptionHandler",
"(",
"\\",
"Exception",
"$",
"oException",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"aConfig",
"[",
"'display_errors'",
"]",
"&&",
"ini_get",
"(",
"'error_log'",
")",
"!==",
"''",
"&&",
"!",
"$",
"this",
"->",
"bIsRunningFromCLI",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"callbackGenericDisplay",
",",
"$",
"oException",
")",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"$",
"oException",
")",
";",
"if",
"(",
"$",
"oException",
"->",
"getCode",
"(",
")",
"!=",
"0",
")",
"{",
"$",
"iErrorCode",
"=",
"$",
"oException",
"->",
"getCode",
"(",
")",
";",
"}",
"else",
"{",
"$",
"iErrorCode",
"=",
"$",
"this",
"->",
"aConfig",
"[",
"'default_error_code'",
"]",
";",
"}",
"exit",
"(",
"$",
"iErrorCode",
")",
";",
"}"
] | Exception handler.
@SuppressWarnings(ExitExpression)
@param \Exception $oException | [
"Exception",
"handler",
".",
"@SuppressWarnings",
"(",
"ExitExpression",
")"
] | train | https://github.com/geoffroy-aubry/ErrorHandler/blob/77575e8e0e4312f9a5f334e27c33549ec6adb35b/src/GAubry/ErrorHandler/ErrorHandler.php#L234-L246 |
geoffroy-aubry/ErrorHandler | src/GAubry/ErrorHandler/ErrorHandler.php | ErrorHandler.internalShutdownFunction | public function internalShutdownFunction()
{
$aError = error_get_last();
if (! $this->aConfig['display_errors'] && is_array($aError) && $aError['type'] === E_ERROR) {
$oException = new \ErrorException(
$aError['message'],
$this->aConfig['default_error_code'],
$aError['type'],
$aError['file'],
$aError['line']
);
call_user_func($this->callbackGenericDisplay, $oException);
}
if (! empty($this->callbackAdditionalShutdownFct)) {
call_user_func($this->callbackAdditionalShutdownFct);
// @codeCoverageIgnoreStart
}
} | php | public function internalShutdownFunction()
{
$aError = error_get_last();
if (! $this->aConfig['display_errors'] && is_array($aError) && $aError['type'] === E_ERROR) {
$oException = new \ErrorException(
$aError['message'],
$this->aConfig['default_error_code'],
$aError['type'],
$aError['file'],
$aError['line']
);
call_user_func($this->callbackGenericDisplay, $oException);
}
if (! empty($this->callbackAdditionalShutdownFct)) {
call_user_func($this->callbackAdditionalShutdownFct);
// @codeCoverageIgnoreStart
}
} | [
"public",
"function",
"internalShutdownFunction",
"(",
")",
"{",
"$",
"aError",
"=",
"error_get_last",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"aConfig",
"[",
"'display_errors'",
"]",
"&&",
"is_array",
"(",
"$",
"aError",
")",
"&&",
"$",
"aError",
"[",
"'type'",
"]",
"===",
"E_ERROR",
")",
"{",
"$",
"oException",
"=",
"new",
"\\",
"ErrorException",
"(",
"$",
"aError",
"[",
"'message'",
"]",
",",
"$",
"this",
"->",
"aConfig",
"[",
"'default_error_code'",
"]",
",",
"$",
"aError",
"[",
"'type'",
"]",
",",
"$",
"aError",
"[",
"'file'",
"]",
",",
"$",
"aError",
"[",
"'line'",
"]",
")",
";",
"call_user_func",
"(",
"$",
"this",
"->",
"callbackGenericDisplay",
",",
"$",
"oException",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"callbackAdditionalShutdownFct",
")",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"callbackAdditionalShutdownFct",
")",
";",
"// @codeCoverageIgnoreStart",
"}",
"}"
] | Registered shutdown function. | [
"Registered",
"shutdown",
"function",
"."
] | train | https://github.com/geoffroy-aubry/ErrorHandler/blob/77575e8e0e4312f9a5f334e27c33549ec6adb35b/src/GAubry/ErrorHandler/ErrorHandler.php#L260-L277 |
geoffroy-aubry/ErrorHandler | src/GAubry/ErrorHandler/ErrorHandler.php | ErrorHandler.log | public function log($mError)
{
if (is_array($mError) || (is_object($mError) && ! ($mError instanceof \Exception))) {
$mError = print_r($mError, true);
}
if ($this->aConfig['display_errors']) {
if ($this->bIsRunningFromCLI) {
file_put_contents('php://stderr', $mError . "\n", E_USER_ERROR);
} else {
echo '<div class="' . $this->aConfig['error_div_class'] . '">' . $mError . '</div>';
}
}
if (! empty($this->aConfig['error_log_path'])) {
error_log($mError);
}
} | php | public function log($mError)
{
if (is_array($mError) || (is_object($mError) && ! ($mError instanceof \Exception))) {
$mError = print_r($mError, true);
}
if ($this->aConfig['display_errors']) {
if ($this->bIsRunningFromCLI) {
file_put_contents('php://stderr', $mError . "\n", E_USER_ERROR);
} else {
echo '<div class="' . $this->aConfig['error_div_class'] . '">' . $mError . '</div>';
}
}
if (! empty($this->aConfig['error_log_path'])) {
error_log($mError);
}
} | [
"public",
"function",
"log",
"(",
"$",
"mError",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mError",
")",
"||",
"(",
"is_object",
"(",
"$",
"mError",
")",
"&&",
"!",
"(",
"$",
"mError",
"instanceof",
"\\",
"Exception",
")",
")",
")",
"{",
"$",
"mError",
"=",
"print_r",
"(",
"$",
"mError",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"aConfig",
"[",
"'display_errors'",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bIsRunningFromCLI",
")",
"{",
"file_put_contents",
"(",
"'php://stderr'",
",",
"$",
"mError",
".",
"\"\\n\"",
",",
"E_USER_ERROR",
")",
";",
"}",
"else",
"{",
"echo",
"'<div class=\"'",
".",
"$",
"this",
"->",
"aConfig",
"[",
"'error_div_class'",
"]",
".",
"'\">'",
".",
"$",
"mError",
".",
"'</div>'",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"aConfig",
"[",
"'error_log_path'",
"]",
")",
")",
"{",
"error_log",
"(",
"$",
"mError",
")",
";",
"}",
"}"
] | According to context, logs specified error into STDERR, STDOUT or via error_log().
@param mixed $mError Error to log. Can be string, array or object. | [
"According",
"to",
"context",
"logs",
"specified",
"error",
"into",
"STDERR",
"STDOUT",
"or",
"via",
"error_log",
"()",
"."
] | train | https://github.com/geoffroy-aubry/ErrorHandler/blob/77575e8e0e4312f9a5f334e27c33549ec6adb35b/src/GAubry/ErrorHandler/ErrorHandler.php#L285-L302 |
SCLInternet/SclCurrency | src/SCL/Currency/Money/Calculator.php | Calculator.performOperationOn2Currencies | private function performOperationOn2Currencies($operation)
{
$this->assertCurrenciesMatch();
return new Money(
$operation($this->valueA->getUnits(), $this->valueB->getUnits()),
$this->valueA->getCurrency()
);
} | php | private function performOperationOn2Currencies($operation)
{
$this->assertCurrenciesMatch();
return new Money(
$operation($this->valueA->getUnits(), $this->valueB->getUnits()),
$this->valueA->getCurrency()
);
} | [
"private",
"function",
"performOperationOn2Currencies",
"(",
"$",
"operation",
")",
"{",
"$",
"this",
"->",
"assertCurrenciesMatch",
"(",
")",
";",
"return",
"new",
"Money",
"(",
"$",
"operation",
"(",
"$",
"this",
"->",
"valueA",
"->",
"getUnits",
"(",
")",
",",
"$",
"this",
"->",
"valueB",
"->",
"getUnits",
"(",
")",
")",
",",
"$",
"this",
"->",
"valueA",
"->",
"getCurrency",
"(",
")",
")",
";",
"}"
] | @param callable $operation Signature: int function(int $a, int $b)
@return Money | [
"@param",
"callable",
"$operation",
"Signature",
":",
"int",
"function",
"(",
"int",
"$a",
"int",
"$b",
")"
] | train | https://github.com/SCLInternet/SclCurrency/blob/788f0ff5d4a3146368a09eb3869cbb0559a9866a/src/SCL/Currency/Money/Calculator.php#L55-L63 |
rollerworks/search-core | Value/ValuesBag.php | ValuesBag.removeExcludedSimpleValue | public function removeExcludedSimpleValue(int $index)
{
if (isset($this->simpleExcludedValues[$index])) {
unset($this->simpleExcludedValues[$index]);
--$this->valuesCount;
}
return $this;
} | php | public function removeExcludedSimpleValue(int $index)
{
if (isset($this->simpleExcludedValues[$index])) {
unset($this->simpleExcludedValues[$index]);
--$this->valuesCount;
}
return $this;
} | [
"public",
"function",
"removeExcludedSimpleValue",
"(",
"int",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"simpleExcludedValues",
"[",
"$",
"index",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"simpleExcludedValues",
"[",
"$",
"index",
"]",
")",
";",
"--",
"$",
"this",
"->",
"valuesCount",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove a simple excluded value by index.
@param int $index
@return static | [
"Remove",
"a",
"simple",
"excluded",
"value",
"by",
"index",
"."
] | train | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L141-L150 |
rollerworks/search-core | Value/ValuesBag.php | ValuesBag.get | public function get(string $type): array
{
if (!isset($this->values[$type])) {
return [];
}
return $this->values[$type];
} | php | public function get(string $type): array
{
if (!isset($this->values[$type])) {
return [];
}
return $this->values[$type];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"type",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
";",
"}"
] | Get all values from a specific type.
@return ValueHolder[] | [
"Get",
"all",
"values",
"from",
"a",
"specific",
"type",
"."
] | train | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L157-L164 |
rollerworks/search-core | Value/ValuesBag.php | ValuesBag.has | public function has(string $type): bool
{
return isset($this->values[$type]) && \count($this->values[$type]) > 0;
} | php | public function has(string $type): bool
{
return isset($this->values[$type]) && \count($this->values[$type]) > 0;
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"type",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
")",
"&&",
"\\",
"count",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
")",
">",
"0",
";",
"}"
] | Get a single value by type and index.
@return bool | [
"Get",
"a",
"single",
"value",
"by",
"type",
"and",
"index",
"."
] | train | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L171-L174 |
rollerworks/search-core | Value/ValuesBag.php | ValuesBag.remove | public function remove(string $type, int $index)
{
if (isset($this->values[$type][$index])) {
unset($this->values[$type][$index]);
--$this->valuesCount;
}
return $this;
} | php | public function remove(string $type, int $index)
{
if (isset($this->values[$type][$index])) {
unset($this->values[$type][$index]);
--$this->valuesCount;
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"string",
"$",
"type",
",",
"int",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
"[",
"$",
"index",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"type",
"]",
"[",
"$",
"index",
"]",
")",
";",
"--",
"$",
"this",
"->",
"valuesCount",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove a value by type and index.
@return ValuesBag New ValuesBag object with the referenced values removed | [
"Remove",
"a",
"value",
"by",
"type",
"and",
"index",
"."
] | train | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Value/ValuesBag.php#L181-L190 |
dms-org/common.structure | src/Colour/Colour.php | Colour.define | protected function define(ClassDefinition $class)
{
$class->property($this->red)->asInt();
$class->property($this->green)->asInt();
$class->property($this->blue)->asInt();
} | php | protected function define(ClassDefinition $class)
{
$class->property($this->red)->asInt();
$class->property($this->green)->asInt();
$class->property($this->blue)->asInt();
} | [
"protected",
"function",
"define",
"(",
"ClassDefinition",
"$",
"class",
")",
"{",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"red",
")",
"->",
"asInt",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"green",
")",
"->",
"asInt",
"(",
")",
";",
"$",
"class",
"->",
"property",
"(",
"$",
"this",
"->",
"blue",
")",
"->",
"asInt",
"(",
")",
";",
"}"
] | Defines the structure of this class.
@param ClassDefinition $class | [
"Defines",
"the",
"structure",
"of",
"this",
"class",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L67-L74 |
dms-org/common.structure | src/Colour/Colour.php | Colour.fromRgbString | public static function fromRgbString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseRgbString($string);
return new self($r, $g, $b);
} | php | public static function fromRgbString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseRgbString($string);
return new self($r, $g, $b);
} | [
"public",
"static",
"function",
"fromRgbString",
"(",
"string",
"$",
"string",
")",
":",
"Colour",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"ColourStringParser",
"::",
"parseRgbString",
"(",
"$",
"string",
")",
";",
"return",
"new",
"self",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Creates a new colour from the supplied rgb string value
@param string $string eg: "rgb(100, 100, 100)"
@return Colour
@throws InvalidArgumentException | [
"Creates",
"a",
"new",
"colour",
"from",
"the",
"supplied",
"rgb",
"string",
"value"
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L84-L89 |
dms-org/common.structure | src/Colour/Colour.php | Colour.fromHexString | public static function fromHexString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseHexString($string);
return new self($r, $g, $b);
} | php | public static function fromHexString(string $string) : Colour
{
list($r, $g, $b) = ColourStringParser::parseHexString($string);
return new self($r, $g, $b);
} | [
"public",
"static",
"function",
"fromHexString",
"(",
"string",
"$",
"string",
")",
":",
"Colour",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"ColourStringParser",
"::",
"parseHexString",
"(",
"$",
"string",
")",
";",
"return",
"new",
"self",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Creates a new colour from the supplied hex value
@param string $string
@return Colour | [
"Creates",
"a",
"new",
"colour",
"from",
"the",
"supplied",
"hex",
"value"
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L98-L103 |
dms-org/common.structure | src/Colour/Colour.php | Colour.toHexString | public function toHexString() : string
{
return '#' . sprintf('%02x', $this->red) . sprintf('%02x', $this->green) . sprintf('%02x', $this->blue);
} | php | public function toHexString() : string
{
return '#' . sprintf('%02x', $this->red) . sprintf('%02x', $this->green) . sprintf('%02x', $this->blue);
} | [
"public",
"function",
"toHexString",
"(",
")",
":",
"string",
"{",
"return",
"'#'",
".",
"sprintf",
"(",
"'%02x'",
",",
"$",
"this",
"->",
"red",
")",
".",
"sprintf",
"(",
"'%02x'",
",",
"$",
"this",
"->",
"green",
")",
".",
"sprintf",
"(",
"'%02x'",
",",
"$",
"this",
"->",
"blue",
")",
";",
"}"
] | Gets the colour as a hex string.
@return string | [
"Gets",
"the",
"colour",
"as",
"a",
"hex",
"string",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/Colour.php#L144-L147 |
LartTyler/Doze | src/Serializer/EntityNormalizer.php | EntityNormalizer.getAttributes | protected function getAttributes($object, $format = null, array $context) {
return $this->extractAttributes($object, $format, $context);
} | php | protected function getAttributes($object, $format = null, array $context) {
return $this->extractAttributes($object, $format, $context);
} | [
"protected",
"function",
"getAttributes",
"(",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
")",
"{",
"return",
"$",
"this",
"->",
"extractAttributes",
"(",
"$",
"object",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/LartTyler/Doze/blob/b23b03f89b042e42b0c8a95a65fa00498fb7837f/src/Serializer/EntityNormalizer.php#L24-L26 |
LartTyler/Doze | src/Serializer/EntityNormalizer.php | EntityNormalizer.getAttributeValue | protected function getAttributeValue($object, $attribute, $format = null, array $context = []) {
$value = parent::getAttributeValue($object, $attribute, $format, $context);
if ($value instanceof EntityInterface && !$this->isExplicitlyAllowed($attribute, $context))
return $value->getId();
return $value;
} | php | protected function getAttributeValue($object, $attribute, $format = null, array $context = []) {
$value = parent::getAttributeValue($object, $attribute, $format, $context);
if ($value instanceof EntityInterface && !$this->isExplicitlyAllowed($attribute, $context))
return $value->getId();
return $value;
} | [
"protected",
"function",
"getAttributeValue",
"(",
"$",
"object",
",",
"$",
"attribute",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"value",
"=",
"parent",
"::",
"getAttributeValue",
"(",
"$",
"object",
",",
"$",
"attribute",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"value",
"instanceof",
"EntityInterface",
"&&",
"!",
"$",
"this",
"->",
"isExplicitlyAllowed",
"(",
"$",
"attribute",
",",
"$",
"context",
")",
")",
"return",
"$",
"value",
"->",
"getId",
"(",
")",
";",
"return",
"$",
"value",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/LartTyler/Doze/blob/b23b03f89b042e42b0c8a95a65fa00498fb7837f/src/Serializer/EntityNormalizer.php#L48-L55 |
robertmain/communique | src/Communique.php | Communique._call | protected function _call(\Communique\RESTClientRequest $request, $debug = null) {
foreach ($this->_interceptors as $request_interceptor) {
$request = $request_interceptor->request($request);
}
$response = $this->_http->request($request);
foreach ($this->_interceptors as $response_interceptor) {
$response = $response_interceptor->response($response);
}
if ($debug) {
$debug($request, $response);
}
return $response;
} | php | protected function _call(\Communique\RESTClientRequest $request, $debug = null) {
foreach ($this->_interceptors as $request_interceptor) {
$request = $request_interceptor->request($request);
}
$response = $this->_http->request($request);
foreach ($this->_interceptors as $response_interceptor) {
$response = $response_interceptor->response($response);
}
if ($debug) {
$debug($request, $response);
}
return $response;
} | [
"protected",
"function",
"_call",
"(",
"\\",
"Communique",
"\\",
"RESTClientRequest",
"$",
"request",
",",
"$",
"debug",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_interceptors",
"as",
"$",
"request_interceptor",
")",
"{",
"$",
"request",
"=",
"$",
"request_interceptor",
"->",
"request",
"(",
"$",
"request",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"_http",
"->",
"request",
"(",
"$",
"request",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_interceptors",
"as",
"$",
"response_interceptor",
")",
"{",
"$",
"response",
"=",
"$",
"response_interceptor",
"->",
"response",
"(",
"$",
"response",
")",
";",
"}",
"if",
"(",
"$",
"debug",
")",
"{",
"$",
"debug",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Makes the HTTP request using the chosen HTTP client.
@param \Communique\RESTClientRequest $request A RESTClientRequest object encapsulating the request
@param callable $debug A debugging callback to be run after the request has finished. This function is expected to accept two parameters, \Communique\RESTClientRequest and \Communique\RESTClientResponse
@return \Communique\RESTClientResponse A RESTClientResponse object encapsulating the response | [
"Makes",
"the",
"HTTP",
"request",
"using",
"the",
"chosen",
"HTTP",
"client",
"."
] | train | https://github.com/robertmain/communique/blob/025d4f0f9bc391f6f9fc653a363158d2f83e9051/src/Communique.php#L75-L87 |
robertmain/communique | src/Communique.php | Communique.put | public function put($url, $payload, array $headers = array(), $debug = null) {
$request = new \Communique\RESTClientRequest('put', $this->_BASE_URL . $url, $payload, $headers);
return $this->_call($request, $debug);
} | php | public function put($url, $payload, array $headers = array(), $debug = null) {
$request = new \Communique\RESTClientRequest('put', $this->_BASE_URL . $url, $payload, $headers);
return $this->_call($request, $debug);
} | [
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"payload",
",",
"array",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"$",
"debug",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"new",
"\\",
"Communique",
"\\",
"RESTClientRequest",
"(",
"'put'",
",",
"$",
"this",
"->",
"_BASE_URL",
".",
"$",
"url",
",",
"$",
"payload",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"_call",
"(",
"$",
"request",
",",
"$",
"debug",
")",
";",
"}"
] | Make an HTTP PUT request
@param String $url The API to make the request to
@param mixed $payload The payload of the request(any data you wish to send across)
@param array $headers Any headers you want to add to the request(optional)
@param callable $debug A function to be used for request debugging.
This function should accept two parameters, one for the request object one for the response object.
@return \Communique\RESTClientResponse REST response encapsulation object | [
"Make",
"an",
"HTTP",
"PUT",
"request"
] | train | https://github.com/robertmain/communique/blob/025d4f0f9bc391f6f9fc653a363158d2f83e9051/src/Communique.php#L112-L115 |
dpiquet/Mapping | src/Mapping.php | Mapping.addMapping | public function addMapping($key, array $accepted_names, $required = true)
{
$lower_accepted_names = [];
foreach($accepted_names as $name) {
$lower_name = strtolower($name);
if ($this->getMapping($lower_name) !== false) {
throw new MappingOverlapException(sprintf('Column name %s already mapped on %s', $name, $key));
}
$lower_accepted_names[] = $lower_name;
}
$this->mappings[$key] = [
'accepted_names' => $lower_accepted_names,
'required' => $required,
'index' => null,
];
return $this;
} | php | public function addMapping($key, array $accepted_names, $required = true)
{
$lower_accepted_names = [];
foreach($accepted_names as $name) {
$lower_name = strtolower($name);
if ($this->getMapping($lower_name) !== false) {
throw new MappingOverlapException(sprintf('Column name %s already mapped on %s', $name, $key));
}
$lower_accepted_names[] = $lower_name;
}
$this->mappings[$key] = [
'accepted_names' => $lower_accepted_names,
'required' => $required,
'index' => null,
];
return $this;
} | [
"public",
"function",
"addMapping",
"(",
"$",
"key",
",",
"array",
"$",
"accepted_names",
",",
"$",
"required",
"=",
"true",
")",
"{",
"$",
"lower_accepted_names",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"accepted_names",
"as",
"$",
"name",
")",
"{",
"$",
"lower_name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getMapping",
"(",
"$",
"lower_name",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"MappingOverlapException",
"(",
"sprintf",
"(",
"'Column name %s already mapped on %s'",
",",
"$",
"name",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"lower_accepted_names",
"[",
"]",
"=",
"$",
"lower_name",
";",
"}",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
"=",
"[",
"'accepted_names'",
"=>",
"$",
"lower_accepted_names",
",",
"'required'",
"=>",
"$",
"required",
",",
"'index'",
"=>",
"null",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add a mapping expectation
@param string $key Mapping identifier
@param array $accepted_names Allowed columns names
@param boolean $required Column is required
@return $this
@throws MappingOverlapException | [
"Add",
"a",
"mapping",
"expectation"
] | train | https://github.com/dpiquet/Mapping/blob/13cccfa490003a12b1c047c0c21f6a24815dd4ba/src/Mapping.php#L35-L56 |
dpiquet/Mapping | src/Mapping.php | Mapping.getMapping | protected function getMapping($name)
{
foreach($this->mappings as $key => $data) {
if (in_array(strtolower($name), $data['accepted_names'])) {
return $key;
}
}
return false;
} | php | protected function getMapping($name)
{
foreach($this->mappings as $key => $data) {
if (in_array(strtolower($name), $data['accepted_names'])) {
return $key;
}
}
return false;
} | [
"protected",
"function",
"getMapping",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mappings",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"name",
")",
",",
"$",
"data",
"[",
"'accepted_names'",
"]",
")",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get a mapped column index
@param string $name
@return int|false | [
"Get",
"a",
"mapped",
"column",
"index"
] | train | https://github.com/dpiquet/Mapping/blob/13cccfa490003a12b1c047c0c21f6a24815dd4ba/src/Mapping.php#L76-L85 |
dpiquet/Mapping | src/Mapping.php | Mapping.map | public function map(array $columns)
{
$maps = [];
$seenKeys = [];
foreach($columns as $index => $column_name) {
$key = $this->getMapping($column_name);
if ($key === false) {
continue;
}
if (in_array($key, $seenKeys)) {
throw new OverlapColumnException($key);
}
$seenKeys[] = $key;
$this->mappings[$key]['index'] = $index;
$maps[$key] = $index;
}
// Check all required mappings are satisfied
foreach($this->mappings as $key => $data) {
if ($data['required'] && !array_key_exists($key, $maps)) {
throw new MappingIncompleteException($key);
}
}
return $maps;
} | php | public function map(array $columns)
{
$maps = [];
$seenKeys = [];
foreach($columns as $index => $column_name) {
$key = $this->getMapping($column_name);
if ($key === false) {
continue;
}
if (in_array($key, $seenKeys)) {
throw new OverlapColumnException($key);
}
$seenKeys[] = $key;
$this->mappings[$key]['index'] = $index;
$maps[$key] = $index;
}
// Check all required mappings are satisfied
foreach($this->mappings as $key => $data) {
if ($data['required'] && !array_key_exists($key, $maps)) {
throw new MappingIncompleteException($key);
}
}
return $maps;
} | [
"public",
"function",
"map",
"(",
"array",
"$",
"columns",
")",
"{",
"$",
"maps",
"=",
"[",
"]",
";",
"$",
"seenKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"index",
"=>",
"$",
"column_name",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getMapping",
"(",
"$",
"column_name",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"seenKeys",
")",
")",
"{",
"throw",
"new",
"OverlapColumnException",
"(",
"$",
"key",
")",
";",
"}",
"$",
"seenKeys",
"[",
"]",
"=",
"$",
"key",
";",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
"[",
"'index'",
"]",
"=",
"$",
"index",
";",
"$",
"maps",
"[",
"$",
"key",
"]",
"=",
"$",
"index",
";",
"}",
"// Check all required mappings are satisfied",
"foreach",
"(",
"$",
"this",
"->",
"mappings",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'required'",
"]",
"&&",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"maps",
")",
")",
"{",
"throw",
"new",
"MappingIncompleteException",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"maps",
";",
"}"
] | Map columns on array
@param array $columns Array to map
@return array mappings
@throws MappingIncompleteException
@throws OverlapColumnException | [
"Map",
"columns",
"on",
"array"
] | train | https://github.com/dpiquet/Mapping/blob/13cccfa490003a12b1c047c0c21f6a24815dd4ba/src/Mapping.php#L96-L128 |
fond-of/spryker-companies-rest-api | src/FondOfSpryker/Zed/CompaniesRestApi/Business/Company/CompanyReader.php | CompanyReader.findCompanyByExternalReference | public function findCompanyByExternalReference(
RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer
): RestCompaniesResponseTransfer {
$companyTransfer = $this->findByExternalReference(
$restCompaniesRequestAttributesTransfer->getExternalReference()
);
if ($companyTransfer !== null) {
return $this->createCompanyResponseTransfer($companyTransfer);
}
return $this->createCompanyFailedToLoadErrorResponseTransfer();
} | php | public function findCompanyByExternalReference(
RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer
): RestCompaniesResponseTransfer {
$companyTransfer = $this->findByExternalReference(
$restCompaniesRequestAttributesTransfer->getExternalReference()
);
if ($companyTransfer !== null) {
return $this->createCompanyResponseTransfer($companyTransfer);
}
return $this->createCompanyFailedToLoadErrorResponseTransfer();
} | [
"public",
"function",
"findCompanyByExternalReference",
"(",
"RestCompaniesRequestAttributesTransfer",
"$",
"restCompaniesRequestAttributesTransfer",
")",
":",
"RestCompaniesResponseTransfer",
"{",
"$",
"companyTransfer",
"=",
"$",
"this",
"->",
"findByExternalReference",
"(",
"$",
"restCompaniesRequestAttributesTransfer",
"->",
"getExternalReference",
"(",
")",
")",
";",
"if",
"(",
"$",
"companyTransfer",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"createCompanyResponseTransfer",
"(",
"$",
"companyTransfer",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createCompanyFailedToLoadErrorResponseTransfer",
"(",
")",
";",
"}"
] | @param \Generated\Shared\Transfer\RestCompaniesRequestAttributesTransfer $restCompaniesRequestAttributesTransfer
@return \Generated\Shared\Transfer\RestCompaniesResponseTransfer | [
"@param",
"\\",
"Generated",
"\\",
"Shared",
"\\",
"Transfer",
"\\",
"RestCompaniesRequestAttributesTransfer",
"$restCompaniesRequestAttributesTransfer"
] | train | https://github.com/fond-of/spryker-companies-rest-api/blob/0df688aa37cd6d18f90ac2af0a1cbc39357d94d7/src/FondOfSpryker/Zed/CompaniesRestApi/Business/Company/CompanyReader.php#L34-L46 |
fond-of/spryker-companies-rest-api | src/FondOfSpryker/Zed/CompaniesRestApi/Business/Company/CompanyReader.php | CompanyReader.createCompanyResponseTransfer | protected function createCompanyResponseTransfer(CompanyTransfer $companyTransfer): RestCompaniesResponseTransfer
{
$restCompaniesResponseAttributesTransfer = new RestCompaniesResponseAttributesTransfer();
$restCompaniesResponseAttributesTransfer->fromArray(
$companyTransfer->toArray(),
true
);
$restCompaniesResponseTransfer = new RestCompaniesResponseTransfer();
$restCompaniesResponseTransfer->setIsSuccess(true)
->setRestCompaniesResponseAttributes($restCompaniesResponseAttributesTransfer);
return $restCompaniesResponseTransfer;
} | php | protected function createCompanyResponseTransfer(CompanyTransfer $companyTransfer): RestCompaniesResponseTransfer
{
$restCompaniesResponseAttributesTransfer = new RestCompaniesResponseAttributesTransfer();
$restCompaniesResponseAttributesTransfer->fromArray(
$companyTransfer->toArray(),
true
);
$restCompaniesResponseTransfer = new RestCompaniesResponseTransfer();
$restCompaniesResponseTransfer->setIsSuccess(true)
->setRestCompaniesResponseAttributes($restCompaniesResponseAttributesTransfer);
return $restCompaniesResponseTransfer;
} | [
"protected",
"function",
"createCompanyResponseTransfer",
"(",
"CompanyTransfer",
"$",
"companyTransfer",
")",
":",
"RestCompaniesResponseTransfer",
"{",
"$",
"restCompaniesResponseAttributesTransfer",
"=",
"new",
"RestCompaniesResponseAttributesTransfer",
"(",
")",
";",
"$",
"restCompaniesResponseAttributesTransfer",
"->",
"fromArray",
"(",
"$",
"companyTransfer",
"->",
"toArray",
"(",
")",
",",
"true",
")",
";",
"$",
"restCompaniesResponseTransfer",
"=",
"new",
"RestCompaniesResponseTransfer",
"(",
")",
";",
"$",
"restCompaniesResponseTransfer",
"->",
"setIsSuccess",
"(",
"true",
")",
"->",
"setRestCompaniesResponseAttributes",
"(",
"$",
"restCompaniesResponseAttributesTransfer",
")",
";",
"return",
"$",
"restCompaniesResponseTransfer",
";",
"}"
] | @param \Generated\Shared\Transfer\CompanyTransfer $companyTransfer
@return \Generated\Shared\Transfer\RestCompaniesResponseTransfer | [
"@param",
"\\",
"Generated",
"\\",
"Shared",
"\\",
"Transfer",
"\\",
"CompanyTransfer",
"$companyTransfer"
] | train | https://github.com/fond-of/spryker-companies-rest-api/blob/0df688aa37cd6d18f90ac2af0a1cbc39357d94d7/src/FondOfSpryker/Zed/CompaniesRestApi/Business/Company/CompanyReader.php#L53-L68 |
fridge-project/dbal | src/Fridge/DBAL/Type/TimeType.php | TimeType.convertToDatabaseValue | public function convertToDatabaseValue($value, PlatformInterface $platform)
{
return ($value === null) ? null : $value->format($platform->getTimeFormat());
} | php | public function convertToDatabaseValue($value, PlatformInterface $platform)
{
return ($value === null) ? null : $value->format($platform->getTimeFormat());
} | [
"public",
"function",
"convertToDatabaseValue",
"(",
"$",
"value",
",",
"PlatformInterface",
"$",
"platform",
")",
"{",
"return",
"(",
"$",
"value",
"===",
"null",
")",
"?",
"null",
":",
"$",
"value",
"->",
"format",
"(",
"$",
"platform",
"->",
"getTimeFormat",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Type/TimeType.php#L35-L38 |
fridge-project/dbal | src/Fridge/DBAL/Type/TimeType.php | TimeType.convertToPHPValue | public function convertToPHPValue($value, PlatformInterface $platform)
{
if ($value === null) {
return;
}
$val = \DateTime::createFromFormat($platform->getTimeFormat(), $value);
if ($val === false) {
throw TypeException::conversionToPHPFailed($value, $this->getName());
}
return $val;
} | php | public function convertToPHPValue($value, PlatformInterface $platform)
{
if ($value === null) {
return;
}
$val = \DateTime::createFromFormat($platform->getTimeFormat(), $value);
if ($val === false) {
throw TypeException::conversionToPHPFailed($value, $this->getName());
}
return $val;
} | [
"public",
"function",
"convertToPHPValue",
"(",
"$",
"value",
",",
"PlatformInterface",
"$",
"platform",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"val",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"platform",
"->",
"getTimeFormat",
"(",
")",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"val",
"===",
"false",
")",
"{",
"throw",
"TypeException",
"::",
"conversionToPHPFailed",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"val",
";",
"}"
] | {@inheritdoc}
@throws \Fridge\DBAL\Exception\TypeException If the database value can not be convert to his PHP value. | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Type/TimeType.php#L45-L58 |
TitaPHP/framework | src/TitaPHP/Helpers/NumberFormatter.php | NumberFormatter.currency | public static function currency( $value, $decimals = 2, $currencyCode = null )
{
$app = Application::instance();
$currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency');
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->formatCurrency($value, $currencyCode);
} | php | public static function currency( $value, $decimals = 2, $currencyCode = null )
{
$app = Application::instance();
$currencyCode = $currencyCode ?: $app->getConfig('app.settings.currency');
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->formatCurrency($value, $currencyCode);
} | [
"public",
"static",
"function",
"currency",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"2",
",",
"$",
"currencyCode",
"=",
"null",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"instance",
"(",
")",
";",
"$",
"currencyCode",
"=",
"$",
"currencyCode",
"?",
":",
"$",
"app",
"->",
"getConfig",
"(",
"'app.settings.currency'",
")",
";",
"$",
"nf",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"\\",
"Locale",
"::",
"getDefault",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"CURRENCY",
")",
";",
"$",
"nf",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"return",
"$",
"nf",
"->",
"formatCurrency",
"(",
"$",
"value",
",",
"$",
"currencyCode",
")",
";",
"}"
] | returns a string with currency formatted accordingly to locale settings
@param string $value
@param string $decimals
@param string $currencyCode
@return string | [
"returns",
"a",
"string",
"with",
"currency",
"formatted",
"accordingly",
"to",
"locale",
"settings"
] | train | https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Helpers/NumberFormatter.php#L14-L22 |
TitaPHP/framework | src/TitaPHP/Helpers/NumberFormatter.php | NumberFormatter.decimal | public static function decimal( $value, $decimals = 2 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->format($value);
} | php | public static function decimal( $value, $decimals = 2 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $nf->format($value);
} | [
"public",
"static",
"function",
"decimal",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"2",
")",
"{",
"$",
"nf",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"\\",
"Locale",
"::",
"getDefault",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"DECIMAL",
")",
";",
"$",
"nf",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"return",
"$",
"nf",
"->",
"format",
"(",
"$",
"value",
")",
";",
"}"
] | returns a string with decimal formatted accordingly to locale settings
@param string $value
@param string $decimals
@return string | [
"returns",
"a",
"string",
"with",
"decimal",
"formatted",
"accordingly",
"to",
"locale",
"settings"
] | train | https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Helpers/NumberFormatter.php#L30-L35 |
TitaPHP/framework | src/TitaPHP/Helpers/NumberFormatter.php | NumberFormatter.percentage | public static function percentage( $value, $decimals = 0 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::PERCENT);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $value > 1 ? $nf->format($value) : $nf->format($value);
} | php | public static function percentage( $value, $decimals = 0 )
{
$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::PERCENT);
$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
return $value > 1 ? $nf->format($value) : $nf->format($value);
} | [
"public",
"static",
"function",
"percentage",
"(",
"$",
"value",
",",
"$",
"decimals",
"=",
"0",
")",
"{",
"$",
"nf",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"\\",
"Locale",
"::",
"getDefault",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"PERCENT",
")",
";",
"$",
"nf",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"MAX_FRACTION_DIGITS",
",",
"$",
"decimals",
")",
";",
"return",
"$",
"value",
">",
"1",
"?",
"$",
"nf",
"->",
"format",
"(",
"$",
"value",
")",
":",
"$",
"nf",
"->",
"format",
"(",
"$",
"value",
")",
";",
"}"
] | returns a string with percentage formatted accordingly to Yii dateFormatter
@param $value
@param $decimals
@return string | [
"returns",
"a",
"string",
"with",
"percentage",
"formatted",
"accordingly",
"to",
"Yii",
"dateFormatter"
] | train | https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Helpers/NumberFormatter.php#L54-L59 |
devlabmtl/haven-cms | Entity/HtmlContent.php | HtmlContent.addTranslation | public function addTranslation(\Haven\CmsBundle\Entity\HtmlContentTranslation $translations) {
$translations->setParent($this);
$this->translations[] = $translations;
return $this;
} | php | public function addTranslation(\Haven\CmsBundle\Entity\HtmlContentTranslation $translations) {
$translations->setParent($this);
$this->translations[] = $translations;
return $this;
} | [
"public",
"function",
"addTranslation",
"(",
"\\",
"Haven",
"\\",
"CmsBundle",
"\\",
"Entity",
"\\",
"HtmlContentTranslation",
"$",
"translations",
")",
"{",
"$",
"translations",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"translations",
"[",
"]",
"=",
"$",
"translations",
";",
"return",
"$",
"this",
";",
"}"
] | Add translations
@param \Haven\CmsBundle\Entity\HtmlContentTranslation $translations
@return HtmlContent | [
"Add",
"translations"
] | train | https://github.com/devlabmtl/haven-cms/blob/c20761a07c201a966dbda1f3eae33617f80e1ece/Entity/HtmlContent.php#L105-L110 |
devlabmtl/haven-cms | Entity/HtmlContent.php | HtmlContent.removeTranslation | public function removeTranslation(\Haven\CmsBundle\Entity\HtmlContentTranslation $translations) {
$this->translations->removeElement($translations);
} | php | public function removeTranslation(\Haven\CmsBundle\Entity\HtmlContentTranslation $translations) {
$this->translations->removeElement($translations);
} | [
"public",
"function",
"removeTranslation",
"(",
"\\",
"Haven",
"\\",
"CmsBundle",
"\\",
"Entity",
"\\",
"HtmlContentTranslation",
"$",
"translations",
")",
"{",
"$",
"this",
"->",
"translations",
"->",
"removeElement",
"(",
"$",
"translations",
")",
";",
"}"
] | Remove translations
@param \Haven\CmsBundle\Entity\HtmlContentTranslation $translations | [
"Remove",
"translations"
] | train | https://github.com/devlabmtl/haven-cms/blob/c20761a07c201a966dbda1f3eae33617f80e1ece/Entity/HtmlContent.php#L117-L119 |
shrink0r/php-schema | src/Property/FloatProperty.php | FloatProperty.validate | public function validate($value)
{
return is_float($value) ? Ok::unit() : Error::unit([ Error::NON_FLOAT ]);
} | php | public function validate($value)
{
return is_float($value) ? Ok::unit() : Error::unit([ Error::NON_FLOAT ]);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"is_float",
"(",
"$",
"value",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_FLOAT",
"]",
")",
";",
"}"
] | Tells if a given value is a valid float.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned. | [
"Tells",
"if",
"a",
"given",
"value",
"is",
"a",
"valid",
"float",
"."
] | train | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/FloatProperty.php#L18-L21 |
kambalabs/KmbCache | src/KmbCache/Service/NodeStatisticsDataContextBuilderFactory.php | NodeStatisticsDataContextBuilderFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$service = new NodeStatisticsDataContextBuilder();
/** @var QueryBuilderInterface $queryBuilder */
$queryBuilder = $serviceLocator->get('KmbPuppetDb\Query\NodesEnvironmentsQueryBuilder');
$service->setNodesEnvironmentsQueryBuilder($queryBuilder);
/** @var EnvironmentInterface $permissionEnvironmentService */
$permissionEnvironmentService = $serviceLocator->get('KmbPermission\Service\Environment');
$service->setPermissionEnvironmentService($permissionEnvironmentService);
return $service;
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$service = new NodeStatisticsDataContextBuilder();
/** @var QueryBuilderInterface $queryBuilder */
$queryBuilder = $serviceLocator->get('KmbPuppetDb\Query\NodesEnvironmentsQueryBuilder');
$service->setNodesEnvironmentsQueryBuilder($queryBuilder);
/** @var EnvironmentInterface $permissionEnvironmentService */
$permissionEnvironmentService = $serviceLocator->get('KmbPermission\Service\Environment');
$service->setPermissionEnvironmentService($permissionEnvironmentService);
return $service;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"service",
"=",
"new",
"NodeStatisticsDataContextBuilder",
"(",
")",
";",
"/** @var QueryBuilderInterface $queryBuilder */",
"$",
"queryBuilder",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'KmbPuppetDb\\Query\\NodesEnvironmentsQueryBuilder'",
")",
";",
"$",
"service",
"->",
"setNodesEnvironmentsQueryBuilder",
"(",
"$",
"queryBuilder",
")",
";",
"/** @var EnvironmentInterface $permissionEnvironmentService */",
"$",
"permissionEnvironmentService",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'KmbPermission\\Service\\Environment'",
")",
";",
"$",
"service",
"->",
"setPermissionEnvironmentService",
"(",
"$",
"permissionEnvironmentService",
")",
";",
"return",
"$",
"service",
";",
"}"
] | Create service
@param ServiceLocatorInterface $serviceLocator
@return mixed | [
"Create",
"service"
] | train | https://github.com/kambalabs/KmbCache/blob/9865ccde8f17fa5ad0ace103e50c164559a389f0/src/KmbCache/Service/NodeStatisticsDataContextBuilderFactory.php#L36-L49 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.run | public function run(Storage $storage)
{
parent::run($storage);
$this->checkParameters();
$this->checkRequiredParameters();
$this->setFormId();
$this->initialize($storage);
$this->checkSubmit($storage);
} | php | public function run(Storage $storage)
{
parent::run($storage);
$this->checkParameters();
$this->checkRequiredParameters();
$this->setFormId();
$this->initialize($storage);
$this->checkSubmit($storage);
} | [
"public",
"function",
"run",
"(",
"Storage",
"$",
"storage",
")",
"{",
"parent",
"::",
"run",
"(",
"$",
"storage",
")",
";",
"$",
"this",
"->",
"checkParameters",
"(",
")",
";",
"$",
"this",
"->",
"checkRequiredParameters",
"(",
")",
";",
"$",
"this",
"->",
"setFormId",
"(",
")",
";",
"$",
"this",
"->",
"initialize",
"(",
"$",
"storage",
")",
";",
"$",
"this",
"->",
"checkSubmit",
"(",
"$",
"storage",
")",
";",
"}"
] | @param Storage $storage
@return void
@throws \Exception | [
"@param",
"Storage",
"$storage"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L74-L82 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.render | public function render($application = null)
{
$request = $this->setPathBackup();
$form = $this->renderTemplate($this->subTemplate);
$this->resetPathBackup($request);
$this->setFormParameter($form);
parent::render($application);
} | php | public function render($application = null)
{
$request = $this->setPathBackup();
$form = $this->renderTemplate($this->subTemplate);
$this->resetPathBackup($request);
$this->setFormParameter($form);
parent::render($application);
} | [
"public",
"function",
"render",
"(",
"$",
"application",
"=",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"setPathBackup",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"renderTemplate",
"(",
"$",
"this",
"->",
"subTemplate",
")",
";",
"$",
"this",
"->",
"resetPathBackup",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"setFormParameter",
"(",
"$",
"form",
")",
";",
"parent",
"::",
"render",
"(",
"$",
"application",
")",
";",
"}"
] | @param null|Application $application
@throws \Exception | [
"@param",
"null|Application",
"$application"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L89-L97 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.checkParameters | protected function checkParameters()
{
$this->checkDocumentTypeParameter();
$this->checkResponseFolderParameter();
$this->checkSubTemplateParameter();
$this->checkFormParameterNameParameter();
$this->checkThankYouMessageParameter();
$this->checkSubmitOncePerSessionParameter();
} | php | protected function checkParameters()
{
$this->checkDocumentTypeParameter();
$this->checkResponseFolderParameter();
$this->checkSubTemplateParameter();
$this->checkFormParameterNameParameter();
$this->checkThankYouMessageParameter();
$this->checkSubmitOncePerSessionParameter();
} | [
"protected",
"function",
"checkParameters",
"(",
")",
"{",
"$",
"this",
"->",
"checkDocumentTypeParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkResponseFolderParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkSubTemplateParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkFormParameterNameParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkThankYouMessageParameter",
"(",
")",
";",
"$",
"this",
"->",
"checkSubmitOncePerSessionParameter",
"(",
")",
";",
"}"
] | Checks if parameters were given in the CMS configuration and
sets them to their respective fields | [
"Checks",
"if",
"parameters",
"were",
"given",
"in",
"the",
"CMS",
"configuration",
"and",
"sets",
"them",
"to",
"their",
"respective",
"fields"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L103-L111 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.initialize | protected function initialize($storage)
{
$this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $storage->getImageSet()->getSmallestImageSet();
$this->parameters[self::PARAMETER_CMS_PREFIX] = '';
$this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $this->storage->getDocumentTypes()->getDocumentTypeBySlug($this->documentType,
true);
$this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes()->getDocumentTypes();
$this->parameters[self::PARAMETER_HIDE_TITLE_AND_STATE] = true;
$this->parameters[self::PARAMETER_FORM_ID] = $this->formId;
} | php | protected function initialize($storage)
{
$this->parameters[self::PARAMETER_SMALLEST_IMAGE] = $storage->getImageSet()->getSmallestImageSet();
$this->parameters[self::PARAMETER_CMS_PREFIX] = '';
$this->parameters[self::PARAMETER_DOCUMENT_TYPE] = $this->storage->getDocumentTypes()->getDocumentTypeBySlug($this->documentType,
true);
$this->parameters[self::PARAMETER_DOCUMENT_TYPES] = $this->storage->getDocumentTypes()->getDocumentTypes();
$this->parameters[self::PARAMETER_HIDE_TITLE_AND_STATE] = true;
$this->parameters[self::PARAMETER_FORM_ID] = $this->formId;
} | [
"protected",
"function",
"initialize",
"(",
"$",
"storage",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_SMALLEST_IMAGE",
"]",
"=",
"$",
"storage",
"->",
"getImageSet",
"(",
")",
"->",
"getSmallestImageSet",
"(",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_CMS_PREFIX",
"]",
"=",
"''",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_DOCUMENT_TYPE",
"]",
"=",
"$",
"this",
"->",
"storage",
"->",
"getDocumentTypes",
"(",
")",
"->",
"getDocumentTypeBySlug",
"(",
"$",
"this",
"->",
"documentType",
",",
"true",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_DOCUMENT_TYPES",
"]",
"=",
"$",
"this",
"->",
"storage",
"->",
"getDocumentTypes",
"(",
")",
"->",
"getDocumentTypes",
"(",
")",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_HIDE_TITLE_AND_STATE",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"parameters",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"=",
"$",
"this",
"->",
"formId",
";",
"}"
] | Sets variables needed for rendering the form template
@param Storage $storage | [
"Sets",
"variables",
"needed",
"for",
"rendering",
"the",
"form",
"template"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L118-L128 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.checkSubmit | protected function checkSubmit($storage)
{
if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) {
$postValues = $this->getPostValues($this->request);
$this->setUserSessionBackup();
$storage->getDocuments()->addDocument($postValues);
$this->restoreUserSessionBackup();
$this->setSubmitToSession();
$this->postSubmit($postValues, $storage);
}
} | php | protected function checkSubmit($storage)
{
if ($this->isFormSubmitted($this->request) && $this->isSubmitAllowed()) {
$postValues = $this->getPostValues($this->request);
$this->setUserSessionBackup();
$storage->getDocuments()->addDocument($postValues);
$this->restoreUserSessionBackup();
$this->setSubmitToSession();
$this->postSubmit($postValues, $storage);
}
} | [
"protected",
"function",
"checkSubmit",
"(",
"$",
"storage",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFormSubmitted",
"(",
"$",
"this",
"->",
"request",
")",
"&&",
"$",
"this",
"->",
"isSubmitAllowed",
"(",
")",
")",
"{",
"$",
"postValues",
"=",
"$",
"this",
"->",
"getPostValues",
"(",
"$",
"this",
"->",
"request",
")",
";",
"$",
"this",
"->",
"setUserSessionBackup",
"(",
")",
";",
"$",
"storage",
"->",
"getDocuments",
"(",
")",
"->",
"addDocument",
"(",
"$",
"postValues",
")",
";",
"$",
"this",
"->",
"restoreUserSessionBackup",
"(",
")",
";",
"$",
"this",
"->",
"setSubmitToSession",
"(",
")",
";",
"$",
"this",
"->",
"postSubmit",
"(",
"$",
"postValues",
",",
"$",
"storage",
")",
";",
"}",
"}"
] | If the form has been submitted, save the document
Calls $this->postSubmit() afterwards
@param Storage $storage
@throws \Exception | [
"If",
"the",
"form",
"has",
"been",
"submitted",
"save",
"the",
"document",
"Calls",
"$this",
"-",
">",
"postSubmit",
"()",
"afterwards"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L137-L147 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.setFormId | protected function setFormId()
{
if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
} else {
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true);
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false;
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
}
} | php | protected function setFormId()
{
if (isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
} else {
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] = (string)microtime(true);
$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName]['submitted'] = false;
$this->formId = $_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID];
}
} | [
"protected",
"function",
"setFormId",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
")",
")",
"{",
"$",
"this",
"->",
"formId",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
";",
"}",
"else",
"{",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"=",
"(",
"string",
")",
"microtime",
"(",
"true",
")",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"'submitted'",
"]",
"=",
"false",
";",
"$",
"this",
"->",
"formId",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
";",
"}",
"}"
] | Sets a unique id for this particular form, so it can recognize
it when a submit occurs | [
"Sets",
"a",
"unique",
"id",
"for",
"this",
"particular",
"form",
"so",
"it",
"can",
"recognize",
"it",
"when",
"a",
"submit",
"occurs"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L169-L178 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.setUserSessionBackup | protected function setUserSessionBackup()
{
$this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
$fakeUser = new \stdClass();
$fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
} | php | protected function setUserSessionBackup()
{
$this->userSessionBackup = isset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]) ? $_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] : null;
$fakeUser = new \stdClass();
$fakeUser->username = self::SESSION_PARAMETER_FORM_COMPONENT;
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $fakeUser;
} | [
"protected",
"function",
"setUserSessionBackup",
"(",
")",
"{",
"$",
"this",
"->",
"userSessionBackup",
"=",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
":",
"null",
";",
"$",
"fakeUser",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"fakeUser",
"->",
"username",
"=",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
"=",
"$",
"fakeUser",
";",
"}"
] | Temporarily stores the current user session in a backup variable
and sets a fake user instead | [
"Temporarily",
"stores",
"the",
"current",
"user",
"session",
"in",
"a",
"backup",
"variable",
"and",
"sets",
"a",
"fake",
"user",
"instead"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L198-L204 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.restoreUserSessionBackup | protected function restoreUserSessionBackup()
{
if ($this->userSessionBackup === null) {
unset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]);
} else {
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $this->userSessionBackup;
}
} | php | protected function restoreUserSessionBackup()
{
if ($this->userSessionBackup === null) {
unset($_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL]);
} else {
$_SESSION[self::SESSION_PARAMETER_CLOUDCONTROL] = $this->userSessionBackup;
}
} | [
"protected",
"function",
"restoreUserSessionBackup",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"userSessionBackup",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
")",
";",
"}",
"else",
"{",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_CLOUDCONTROL",
"]",
"=",
"$",
"this",
"->",
"userSessionBackup",
";",
"}",
"}"
] | Removes the fake user and restores the existing user
session if it was there | [
"Removes",
"the",
"fake",
"user",
"and",
"restores",
"the",
"existing",
"user",
"session",
"if",
"it",
"was",
"there"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L210-L217 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.checkFormIdInPost | private function checkFormIdInPost($request)
{
if (!isset($request::$post[self::PARAMETER_FORM_ID])) {
return false;
}
if (!$request::$post[self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
} | php | private function checkFormIdInPost($request)
{
if (!isset($request::$post[self::PARAMETER_FORM_ID])) {
return false;
}
if (!$request::$post[self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
} | [
"private",
"function",
"checkFormIdInPost",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"request",
"::",
"$",
"post",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"request",
"::",
"$",
"post",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"===",
"$",
"this",
"->",
"formId",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks if form id is set in _POST variable
@param $request
@return bool | [
"Checks",
"if",
"form",
"id",
"is",
"set",
"in",
"_POST",
"variable"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L364-L375 |
jenskooij/cloudcontrol | src/components/FormComponent.php | FormComponent.checkFormIdInSession | private function checkFormIdInSession()
{
if (!isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
return false;
}
if (!$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
} | php | private function checkFormIdInSession()
{
if (!isset($_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID])) {
return false;
}
if (!$_SESSION[self::SESSION_PARAMETER_FORM_COMPONENT][$this->formParameterName][self::PARAMETER_FORM_ID] === $this->formId) {
return false;
}
return true;
} | [
"private",
"function",
"checkFormIdInSession",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"_SESSION",
"[",
"self",
"::",
"SESSION_PARAMETER_FORM_COMPONENT",
"]",
"[",
"$",
"this",
"->",
"formParameterName",
"]",
"[",
"self",
"::",
"PARAMETER_FORM_ID",
"]",
"===",
"$",
"this",
"->",
"formId",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks if form is is set in _SESSION variable
@return bool | [
"Checks",
"if",
"form",
"is",
"is",
"set",
"in",
"_SESSION",
"variable"
] | train | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/FormComponent.php#L381-L392 |
DreadLabs/app-migration | src/Mediator.php | Mediator.negotiate | public function negotiate()
{
// This is a workaround for PHP5.5, @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/143#issuecomment-108148498
$catchedException = null;
try {
$this->lock->acquire();
$this->executeMigrations();
} catch (LockingException $exc) {
$this->logger->emergency($exc->getMessage());
$catchedException = $exc;
} catch (TopologyViolationException $exc) {
$this->logger->emergency('The version to migrate to is older than the current one.');
$catchedException = $exc;
} catch (MigrationException $exc) {
$this->logger->emergency('Migration of version ' . $exc->getCode() . ' failed.', array($exc->getMessage()));
$catchedException = $exc;
}
$this->lock->release();
if (!is_null($catchedException)) {
throw $catchedException;
}
} | php | public function negotiate()
{
// This is a workaround for PHP5.5, @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/143#issuecomment-108148498
$catchedException = null;
try {
$this->lock->acquire();
$this->executeMigrations();
} catch (LockingException $exc) {
$this->logger->emergency($exc->getMessage());
$catchedException = $exc;
} catch (TopologyViolationException $exc) {
$this->logger->emergency('The version to migrate to is older than the current one.');
$catchedException = $exc;
} catch (MigrationException $exc) {
$this->logger->emergency('Migration of version ' . $exc->getCode() . ' failed.', array($exc->getMessage()));
$catchedException = $exc;
}
$this->lock->release();
if (!is_null($catchedException)) {
throw $catchedException;
}
} | [
"public",
"function",
"negotiate",
"(",
")",
"{",
"// This is a workaround for PHP5.5, @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/143#issuecomment-108148498",
"$",
"catchedException",
"=",
"null",
";",
"try",
"{",
"$",
"this",
"->",
"lock",
"->",
"acquire",
"(",
")",
";",
"$",
"this",
"->",
"executeMigrations",
"(",
")",
";",
"}",
"catch",
"(",
"LockingException",
"$",
"exc",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"emergency",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"catchedException",
"=",
"$",
"exc",
";",
"}",
"catch",
"(",
"TopologyViolationException",
"$",
"exc",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"emergency",
"(",
"'The version to migrate to is older than the current one.'",
")",
";",
"$",
"catchedException",
"=",
"$",
"exc",
";",
"}",
"catch",
"(",
"MigrationException",
"$",
"exc",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"emergency",
"(",
"'Migration of version '",
".",
"$",
"exc",
"->",
"getCode",
"(",
")",
".",
"' failed.'",
",",
"array",
"(",
"$",
"exc",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"$",
"catchedException",
"=",
"$",
"exc",
";",
"}",
"$",
"this",
"->",
"lock",
"->",
"release",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"catchedException",
")",
")",
"{",
"throw",
"$",
"catchedException",
";",
"}",
"}"
] | Negotiates the migration process
@return void
@throws MigrationException If something went wrong with the involved
components | [
"Negotiates",
"the",
"migration",
"process"
] | train | https://github.com/DreadLabs/app-migration/blob/a416d770c51db28db9750251b40cd4f13e57c148/src/Mediator.php#L72-L99 |
DreadLabs/app-migration | src/Mediator.php | Mediator.executeMigrations | private function executeMigrations()
{
if ($this->migrator->needsToRun()) {
$latestVersion = $this->migrator->migrate();
$this->logger->info('Migrate all migrations up to version ' . $latestVersion . '.');
}
} | php | private function executeMigrations()
{
if ($this->migrator->needsToRun()) {
$latestVersion = $this->migrator->migrate();
$this->logger->info('Migrate all migrations up to version ' . $latestVersion . '.');
}
} | [
"private",
"function",
"executeMigrations",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"migrator",
"->",
"needsToRun",
"(",
")",
")",
"{",
"$",
"latestVersion",
"=",
"$",
"this",
"->",
"migrator",
"->",
"migrate",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'Migrate all migrations up to version '",
".",
"$",
"latestVersion",
".",
"'.'",
")",
";",
"}",
"}"
] | Executes migrations
@return void | [
"Executes",
"migrations"
] | train | https://github.com/DreadLabs/app-migration/blob/a416d770c51db28db9750251b40cd4f13e57c148/src/Mediator.php#L106-L112 |
Innmind/Math | src/Geometry/Theorem/AlKashi.php | AlKashi.angle | public static function angle(
Segment $a,
Segment $b,
Segment $c
): Degree {
$a = $a->length();
$b = $b->length();
$c = $c->length();
$longest = max($a, $b, $c);
$opposites = (new Set(Number::class))
->add($a)
->add($b)
->add($c)
->remove($longest);
$opposites = add(...$opposites);
if ($longest->higherThan($opposites) && !$longest->equals($opposites)) {
throw new SegmentsCannotBeJoined;
}
$cosAB = $a
->power(new Integer(2))
->add($b->power(new Integer(2)))
->subtract($c->power(new Integer(2)))
->divideBy(
(new Integer(2))
->multiplyBy($a)
->multiplyBy($b)
);
return arcCosine($cosAB)->toDegree();
} | php | public static function angle(
Segment $a,
Segment $b,
Segment $c
): Degree {
$a = $a->length();
$b = $b->length();
$c = $c->length();
$longest = max($a, $b, $c);
$opposites = (new Set(Number::class))
->add($a)
->add($b)
->add($c)
->remove($longest);
$opposites = add(...$opposites);
if ($longest->higherThan($opposites) && !$longest->equals($opposites)) {
throw new SegmentsCannotBeJoined;
}
$cosAB = $a
->power(new Integer(2))
->add($b->power(new Integer(2)))
->subtract($c->power(new Integer(2)))
->divideBy(
(new Integer(2))
->multiplyBy($a)
->multiplyBy($b)
);
return arcCosine($cosAB)->toDegree();
} | [
"public",
"static",
"function",
"angle",
"(",
"Segment",
"$",
"a",
",",
"Segment",
"$",
"b",
",",
"Segment",
"$",
"c",
")",
":",
"Degree",
"{",
"$",
"a",
"=",
"$",
"a",
"->",
"length",
"(",
")",
";",
"$",
"b",
"=",
"$",
"b",
"->",
"length",
"(",
")",
";",
"$",
"c",
"=",
"$",
"c",
"->",
"length",
"(",
")",
";",
"$",
"longest",
"=",
"max",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"c",
")",
";",
"$",
"opposites",
"=",
"(",
"new",
"Set",
"(",
"Number",
"::",
"class",
")",
")",
"->",
"add",
"(",
"$",
"a",
")",
"->",
"add",
"(",
"$",
"b",
")",
"->",
"add",
"(",
"$",
"c",
")",
"->",
"remove",
"(",
"$",
"longest",
")",
";",
"$",
"opposites",
"=",
"add",
"(",
"...",
"$",
"opposites",
")",
";",
"if",
"(",
"$",
"longest",
"->",
"higherThan",
"(",
"$",
"opposites",
")",
"&&",
"!",
"$",
"longest",
"->",
"equals",
"(",
"$",
"opposites",
")",
")",
"{",
"throw",
"new",
"SegmentsCannotBeJoined",
";",
"}",
"$",
"cosAB",
"=",
"$",
"a",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
"->",
"add",
"(",
"$",
"b",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
")",
"->",
"subtract",
"(",
"$",
"c",
"->",
"power",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
")",
"->",
"divideBy",
"(",
"(",
"new",
"Integer",
"(",
"2",
")",
")",
"->",
"multiplyBy",
"(",
"$",
"a",
")",
"->",
"multiplyBy",
"(",
"$",
"b",
")",
")",
";",
"return",
"arcCosine",
"(",
"$",
"cosAB",
")",
"->",
"toDegree",
"(",
")",
";",
"}"
] | Return the angle between a and b sides | [
"Return",
"the",
"angle",
"between",
"a",
"and",
"b",
"sides"
] | train | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Geometry/Theorem/AlKashi.php#L55-L86 |
davewwww/Ispec | src/Dwo/Ispec/Helper/IpInfoHelper.php | IpInfoHelper.getIp | public static function getIp(IpInfo $ipInfo)
{
$ip = $ipInfo->ip;
if (empty($ip)) {
if (empty($ipInfo->subnet)) {
throw new IspecException('no ip found');
}
list($ip) = explode('/', $ipInfo->subnet, 2);
}
return $ip;
} | php | public static function getIp(IpInfo $ipInfo)
{
$ip = $ipInfo->ip;
if (empty($ip)) {
if (empty($ipInfo->subnet)) {
throw new IspecException('no ip found');
}
list($ip) = explode('/', $ipInfo->subnet, 2);
}
return $ip;
} | [
"public",
"static",
"function",
"getIp",
"(",
"IpInfo",
"$",
"ipInfo",
")",
"{",
"$",
"ip",
"=",
"$",
"ipInfo",
"->",
"ip",
";",
"if",
"(",
"empty",
"(",
"$",
"ip",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ipInfo",
"->",
"subnet",
")",
")",
"{",
"throw",
"new",
"IspecException",
"(",
"'no ip found'",
")",
";",
"}",
"list",
"(",
"$",
"ip",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"ipInfo",
"->",
"subnet",
",",
"2",
")",
";",
"}",
"return",
"$",
"ip",
";",
"}"
] | @param IpInfo $ipInfo
@return IpInfo
@throws IspecException | [
"@param",
"IpInfo",
"$ipInfo"
] | train | https://github.com/davewwww/Ispec/blob/06e40344eaad27715c87c8f6830ab4894e89736d/src/Dwo/Ispec/Helper/IpInfoHelper.php#L22-L34 |
davewwww/Ispec | src/Dwo/Ispec/Helper/IpInfoHelper.php | IpInfoHelper.isIpInSubnets | public static function isIpInSubnets($ip, array $entries, &$entryReturn = null)
{
$ipObj = Factory::getAddress($ip);
foreach ($entries as $entry) {
if (Factory::getExpression(self::getSubnet($entry))->matches($ipObj)) {
$entryReturn = $entry;
return true;
}
}
return false;
} | php | public static function isIpInSubnets($ip, array $entries, &$entryReturn = null)
{
$ipObj = Factory::getAddress($ip);
foreach ($entries as $entry) {
if (Factory::getExpression(self::getSubnet($entry))->matches($ipObj)) {
$entryReturn = $entry;
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"isIpInSubnets",
"(",
"$",
"ip",
",",
"array",
"$",
"entries",
",",
"&",
"$",
"entryReturn",
"=",
"null",
")",
"{",
"$",
"ipObj",
"=",
"Factory",
"::",
"getAddress",
"(",
"$",
"ip",
")",
";",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"Factory",
"::",
"getExpression",
"(",
"self",
"::",
"getSubnet",
"(",
"$",
"entry",
")",
")",
"->",
"matches",
"(",
"$",
"ipObj",
")",
")",
"{",
"$",
"entryReturn",
"=",
"$",
"entry",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param string $ip
@param array|IpInfo[] $entries
@param mixed $entryReturn
@return bool | [
"@param",
"string",
"$ip",
"@param",
"array|IpInfo",
"[]",
"$entries",
"@param",
"mixed",
"$entryReturn"
] | train | https://github.com/davewwww/Ispec/blob/06e40344eaad27715c87c8f6830ab4894e89736d/src/Dwo/Ispec/Helper/IpInfoHelper.php#L43-L56 |
davewwww/Ispec | src/Dwo/Ispec/Helper/IpInfoHelper.php | IpInfoHelper.getSubnet | public static function getSubnet($data)
{
$subnet = null;
if ($data instanceof IpInfo) {
$subnet = $data->subnet;
} elseif (is_array($data) && isset($data['subnet'])) {
$subnet = $data['subnet'];
} else {
throw new IspecException('key "subnet" is missing');
}
return $subnet;
} | php | public static function getSubnet($data)
{
$subnet = null;
if ($data instanceof IpInfo) {
$subnet = $data->subnet;
} elseif (is_array($data) && isset($data['subnet'])) {
$subnet = $data['subnet'];
} else {
throw new IspecException('key "subnet" is missing');
}
return $subnet;
} | [
"public",
"static",
"function",
"getSubnet",
"(",
"$",
"data",
")",
"{",
"$",
"subnet",
"=",
"null",
";",
"if",
"(",
"$",
"data",
"instanceof",
"IpInfo",
")",
"{",
"$",
"subnet",
"=",
"$",
"data",
"->",
"subnet",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'subnet'",
"]",
")",
")",
"{",
"$",
"subnet",
"=",
"$",
"data",
"[",
"'subnet'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"IspecException",
"(",
"'key \"subnet\" is missing'",
")",
";",
"}",
"return",
"$",
"subnet",
";",
"}"
] | @return object|array $data
@return string
@throws IspecException | [
"@return",
"object|array",
"$data"
] | train | https://github.com/davewwww/Ispec/blob/06e40344eaad27715c87c8f6830ab4894e89736d/src/Dwo/Ispec/Helper/IpInfoHelper.php#L64-L77 |
fridge-project/dbal | src/Fridge/DBAL/Driver/MysqliDriver.php | MysqliDriver.connect | public function connect(array $parameters, $username = null, $password = null, array $driverOptions = array())
{
return new MysqliConnection($parameters, $username, $password);
} | php | public function connect(array $parameters, $username = null, $password = null, array $driverOptions = array())
{
return new MysqliConnection($parameters, $username, $password);
} | [
"public",
"function",
"connect",
"(",
"array",
"$",
"parameters",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"array",
"$",
"driverOptions",
"=",
"array",
"(",
")",
")",
"{",
"return",
"new",
"MysqliConnection",
"(",
"$",
"parameters",
",",
"$",
"username",
",",
"$",
"password",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/MysqliDriver.php#L29-L32 |
PenoaksDev/Milky-Framework | src/Milky/Framework.php | Framework.buildPath | public function buildPath()
{
$slugs = func_get_args();
if ( is_array( $slugs[0] ) )
$slugs = $slugs[0];
if ( count( $slugs ) == 0 )
return $this->basePath;
if ( Str::startsWith( $slugs[0], '__' ) )
{
$key = substr( $slugs[0], 2 );
if ( $key == 'base' )
$slugs[0] = $this->basePath;
else if ( array_key_exists( $key, $this->paths ) )
{
$paths = $this->paths[$key];
if ( is_array( $paths ) )
{
unset( $slugs[0] );
foreach ( array_reverse( $paths ) as $slug )
$slugs = Arr::prepend( $slugs, $slug );
}
else
$slugs[0] = $paths;
}
else
throw new FrameworkException( "Path [" . $key . "] is not set" );
return $this->buildPath( $slugs );
}
else if ( !Str::startsWith( $slugs[0], '/' ) )
$slugs = Arr::prepend( $slugs, $this->basePath );
$dir = strpos( end( $slugs ), '.' ) !== false ? implode( DIRECTORY_SEPARATOR, array_slice( $slugs, 0, count( $slugs ) - 1 ) ) : implode( DIRECTORY_SEPARATOR, $slugs );
if ( !file_exists( $dir ) )
if ( !mkdir( $dir, 0755, true ) )
throw new FrameworkException( "The directory [" . $dir . "] does not exist and we failed to create it" );
return implode( DIRECTORY_SEPARATOR, $slugs );
} | php | public function buildPath()
{
$slugs = func_get_args();
if ( is_array( $slugs[0] ) )
$slugs = $slugs[0];
if ( count( $slugs ) == 0 )
return $this->basePath;
if ( Str::startsWith( $slugs[0], '__' ) )
{
$key = substr( $slugs[0], 2 );
if ( $key == 'base' )
$slugs[0] = $this->basePath;
else if ( array_key_exists( $key, $this->paths ) )
{
$paths = $this->paths[$key];
if ( is_array( $paths ) )
{
unset( $slugs[0] );
foreach ( array_reverse( $paths ) as $slug )
$slugs = Arr::prepend( $slugs, $slug );
}
else
$slugs[0] = $paths;
}
else
throw new FrameworkException( "Path [" . $key . "] is not set" );
return $this->buildPath( $slugs );
}
else if ( !Str::startsWith( $slugs[0], '/' ) )
$slugs = Arr::prepend( $slugs, $this->basePath );
$dir = strpos( end( $slugs ), '.' ) !== false ? implode( DIRECTORY_SEPARATOR, array_slice( $slugs, 0, count( $slugs ) - 1 ) ) : implode( DIRECTORY_SEPARATOR, $slugs );
if ( !file_exists( $dir ) )
if ( !mkdir( $dir, 0755, true ) )
throw new FrameworkException( "The directory [" . $dir . "] does not exist and we failed to create it" );
return implode( DIRECTORY_SEPARATOR, $slugs );
} | [
"public",
"function",
"buildPath",
"(",
")",
"{",
"$",
"slugs",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"slugs",
"[",
"0",
"]",
")",
")",
"$",
"slugs",
"=",
"$",
"slugs",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"slugs",
")",
"==",
"0",
")",
"return",
"$",
"this",
"->",
"basePath",
";",
"if",
"(",
"Str",
"::",
"startsWith",
"(",
"$",
"slugs",
"[",
"0",
"]",
",",
"'__'",
")",
")",
"{",
"$",
"key",
"=",
"substr",
"(",
"$",
"slugs",
"[",
"0",
"]",
",",
"2",
")",
";",
"if",
"(",
"$",
"key",
"==",
"'base'",
")",
"$",
"slugs",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"basePath",
";",
"else",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"paths",
")",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"paths",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"paths",
")",
")",
"{",
"unset",
"(",
"$",
"slugs",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"paths",
")",
"as",
"$",
"slug",
")",
"$",
"slugs",
"=",
"Arr",
"::",
"prepend",
"(",
"$",
"slugs",
",",
"$",
"slug",
")",
";",
"}",
"else",
"$",
"slugs",
"[",
"0",
"]",
"=",
"$",
"paths",
";",
"}",
"else",
"throw",
"new",
"FrameworkException",
"(",
"\"Path [\"",
".",
"$",
"key",
".",
"\"] is not set\"",
")",
";",
"return",
"$",
"this",
"->",
"buildPath",
"(",
"$",
"slugs",
")",
";",
"}",
"else",
"if",
"(",
"!",
"Str",
"::",
"startsWith",
"(",
"$",
"slugs",
"[",
"0",
"]",
",",
"'/'",
")",
")",
"$",
"slugs",
"=",
"Arr",
"::",
"prepend",
"(",
"$",
"slugs",
",",
"$",
"this",
"->",
"basePath",
")",
";",
"$",
"dir",
"=",
"strpos",
"(",
"end",
"(",
"$",
"slugs",
")",
",",
"'.'",
")",
"!==",
"false",
"?",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"array_slice",
"(",
"$",
"slugs",
",",
"0",
",",
"count",
"(",
"$",
"slugs",
")",
"-",
"1",
")",
")",
":",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"slugs",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
")",
")",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"dir",
",",
"0755",
",",
"true",
")",
")",
"throw",
"new",
"FrameworkException",
"(",
"\"The directory [\"",
".",
"$",
"dir",
".",
"\"] does not exist and we failed to create it\"",
")",
";",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"slugs",
")",
";",
"}"
] | Append args to the base path
@return string
@throws FrameworkException | [
"Append",
"args",
"to",
"the",
"base",
"path"
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Framework.php#L237-L279 |
PenoaksDev/Milky-Framework | src/Milky/Framework.php | Framework.environment | public static function environment()
{
$env = static::fw()->config->get( 'app.env', 'production' );
if ( func_num_args() > 0 )
{
$patterns = is_array( func_get_arg( 0 ) ) ? func_get_arg( 0 ) : func_get_args();
foreach ( $patterns as $pattern )
if ( Str::is( $pattern, $env ) )
return true;
return false;
}
return $env;
} | php | public static function environment()
{
$env = static::fw()->config->get( 'app.env', 'production' );
if ( func_num_args() > 0 )
{
$patterns = is_array( func_get_arg( 0 ) ) ? func_get_arg( 0 ) : func_get_args();
foreach ( $patterns as $pattern )
if ( Str::is( $pattern, $env ) )
return true;
return false;
}
return $env;
} | [
"public",
"static",
"function",
"environment",
"(",
")",
"{",
"$",
"env",
"=",
"static",
"::",
"fw",
"(",
")",
"->",
"config",
"->",
"get",
"(",
"'app.env'",
",",
"'production'",
")",
";",
"if",
"(",
"func_num_args",
"(",
")",
">",
"0",
")",
"{",
"$",
"patterns",
"=",
"is_array",
"(",
"func_get_arg",
"(",
"0",
")",
")",
"?",
"func_get_arg",
"(",
"0",
")",
":",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"pattern",
")",
"if",
"(",
"Str",
"::",
"is",
"(",
"$",
"pattern",
",",
"$",
"env",
")",
")",
"return",
"true",
";",
"return",
"false",
";",
"}",
"return",
"$",
"env",
";",
"}"
] | Get or check the current application environment.
@param mixed
@return string | [
"Get",
"or",
"check",
"the",
"current",
"application",
"environment",
"."
] | train | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Framework.php#L335-L351 |
Subscribo/klarna-invoice-sdk-wrapped | src/Language.php | KlarnaLanguage.fromCode | public static function fromCode($val)
{
$val = strtoupper($val);
if (array_key_exists($val, self::$_languages)) {
return self::$_languages[$val];
}
return null;
} | php | public static function fromCode($val)
{
$val = strtoupper($val);
if (array_key_exists($val, self::$_languages)) {
return self::$_languages[$val];
}
return null;
} | [
"public",
"static",
"function",
"fromCode",
"(",
"$",
"val",
")",
"{",
"$",
"val",
"=",
"strtoupper",
"(",
"$",
"val",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"val",
",",
"self",
"::",
"$",
"_languages",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_languages",
"[",
"$",
"val",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Converts a language code, e.g. 'de' to the KlarnaLanguage constant.
@param string $val language code
@return int|null | [
"Converts",
"a",
"language",
"code",
"e",
".",
"g",
".",
"de",
"to",
"the",
"KlarnaLanguage",
"constant",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Language.php#L92-L99 |
Subscribo/klarna-invoice-sdk-wrapped | src/Language.php | KlarnaLanguage.getCode | public static function getCode($val)
{
if (self::$_languageFlip === array()) {
self::$_languageFlip = array_flip(self::$_languages);
}
if (array_key_exists($val, self::$_languageFlip)) {
return strtolower(self::$_languageFlip[$val]);
}
return null;
} | php | public static function getCode($val)
{
if (self::$_languageFlip === array()) {
self::$_languageFlip = array_flip(self::$_languages);
}
if (array_key_exists($val, self::$_languageFlip)) {
return strtolower(self::$_languageFlip[$val]);
}
return null;
} | [
"public",
"static",
"function",
"getCode",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_languageFlip",
"===",
"array",
"(",
")",
")",
"{",
"self",
"::",
"$",
"_languageFlip",
"=",
"array_flip",
"(",
"self",
"::",
"$",
"_languages",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"val",
",",
"self",
"::",
"$",
"_languageFlip",
")",
")",
"{",
"return",
"strtolower",
"(",
"self",
"::",
"$",
"_languageFlip",
"[",
"$",
"val",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Converts a KlarnaLanguage constant to the respective language code.
@param int $val KlarnaLanguage constant
@return lowercase string|null | [
"Converts",
"a",
"KlarnaLanguage",
"constant",
"to",
"the",
"respective",
"language",
"code",
"."
] | train | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Language.php#L108-L117 |
rafflesargentina/l5-filterable-sortable | src/QuerySorters.php | QuerySorters.apply | public function apply(Builder $builder)
{
$this->builder = $builder;
if (method_exists($this, $this->orderBy())) {
call_user_func([$this, $this->orderBy()]);
}
return $this->builder;
} | php | public function apply(Builder $builder)
{
$this->builder = $builder;
if (method_exists($this, $this->orderBy())) {
call_user_func([$this, $this->orderBy()]);
}
return $this->builder;
} | [
"public",
"function",
"apply",
"(",
"Builder",
"$",
"builder",
")",
"{",
"$",
"this",
"->",
"builder",
"=",
"$",
"builder",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"orderBy",
"(",
")",
")",
")",
"{",
"call_user_func",
"(",
"[",
"$",
"this",
",",
"$",
"this",
"->",
"orderBy",
"(",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"builder",
";",
"}"
] | Apply the sorter to the builder.
@param Builder $builder The builder instance.
@return Builder | [
"Apply",
"the",
"sorter",
"to",
"the",
"builder",
"."
] | train | https://github.com/rafflesargentina/l5-filterable-sortable/blob/eb3ecf399145ec7c5241ba2134ed0bea2057e6c3/src/QuerySorters.php#L82-L91 |
rafflesargentina/l5-filterable-sortable | src/QuerySorters.php | QuerySorters.listOrderByKeys | public static function listOrderByKeys()
{
$classMethods = get_class_methods(get_class());
$calledClassMethods = get_class_methods(get_called_class());
$filteredMethods = array_filter(
$calledClassMethods, function ($calledClassMethod) use ($classMethods) {
return !in_array($calledClassMethod, $classMethods, true);
}
);
$list = [];
foreach ($filteredMethods as $k => $v) {
$list[$v] = $v;
}
return $list;
} | php | public static function listOrderByKeys()
{
$classMethods = get_class_methods(get_class());
$calledClassMethods = get_class_methods(get_called_class());
$filteredMethods = array_filter(
$calledClassMethods, function ($calledClassMethod) use ($classMethods) {
return !in_array($calledClassMethod, $classMethods, true);
}
);
$list = [];
foreach ($filteredMethods as $k => $v) {
$list[$v] = $v;
}
return $list;
} | [
"public",
"static",
"function",
"listOrderByKeys",
"(",
")",
"{",
"$",
"classMethods",
"=",
"get_class_methods",
"(",
"get_class",
"(",
")",
")",
";",
"$",
"calledClassMethods",
"=",
"get_class_methods",
"(",
"get_called_class",
"(",
")",
")",
";",
"$",
"filteredMethods",
"=",
"array_filter",
"(",
"$",
"calledClassMethods",
",",
"function",
"(",
"$",
"calledClassMethod",
")",
"use",
"(",
"$",
"classMethods",
")",
"{",
"return",
"!",
"in_array",
"(",
"$",
"calledClassMethod",
",",
"$",
"classMethods",
",",
"true",
")",
";",
"}",
")",
";",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filteredMethods",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"list",
"[",
"$",
"v",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Pluck all sorters from class methods.
@return array | [
"Pluck",
"all",
"sorters",
"from",
"class",
"methods",
"."
] | train | https://github.com/rafflesargentina/l5-filterable-sortable/blob/eb3ecf399145ec7c5241ba2134ed0bea2057e6c3/src/QuerySorters.php#L139-L156 |
rafflesargentina/l5-filterable-sortable | src/QuerySorters.php | QuerySorters.getAppliedSorters | public static function getAppliedSorters()
{
$order = static::getOrderKey();
$orderBy = static::getOrderByKey();
$applied = \Illuminate\Support\Facades\Request::only($order, $orderBy);
$applied = array_filter($applied);
$default = [
$orderBy => static::getDefaultOrderBy(),
$order => static::getDefaultOrder()
];
return $applied ?: $default;
} | php | public static function getAppliedSorters()
{
$order = static::getOrderKey();
$orderBy = static::getOrderByKey();
$applied = \Illuminate\Support\Facades\Request::only($order, $orderBy);
$applied = array_filter($applied);
$default = [
$orderBy => static::getDefaultOrderBy(),
$order => static::getDefaultOrder()
];
return $applied ?: $default;
} | [
"public",
"static",
"function",
"getAppliedSorters",
"(",
")",
"{",
"$",
"order",
"=",
"static",
"::",
"getOrderKey",
"(",
")",
";",
"$",
"orderBy",
"=",
"static",
"::",
"getOrderByKey",
"(",
")",
";",
"$",
"applied",
"=",
"\\",
"Illuminate",
"\\",
"Support",
"\\",
"Facades",
"\\",
"Request",
"::",
"only",
"(",
"$",
"order",
",",
"$",
"orderBy",
")",
";",
"$",
"applied",
"=",
"array_filter",
"(",
"$",
"applied",
")",
";",
"$",
"default",
"=",
"[",
"$",
"orderBy",
"=>",
"static",
"::",
"getDefaultOrderBy",
"(",
")",
",",
"$",
"order",
"=>",
"static",
"::",
"getDefaultOrder",
"(",
")",
"]",
";",
"return",
"$",
"applied",
"?",
":",
"$",
"default",
";",
"}"
] | Get applied sorters from request or fallback to default.
@return array | [
"Get",
"applied",
"sorters",
"from",
"request",
"or",
"fallback",
"to",
"default",
"."
] | train | https://github.com/rafflesargentina/l5-filterable-sortable/blob/eb3ecf399145ec7c5241ba2134ed0bea2057e6c3/src/QuerySorters.php#L163-L178 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.getCredentials | public function getCredentials(Request $request)
{
// this method is only called if supports() returns true
// For Symfony lower than 3.4 the supports method need to be called manually here:
// if (!$this->supports($request)) {
// return null;
// }
$accessToken=$this->fetchAccessToken($this->getGoogleClient());
$session = $request->getSession();
$session->set('googleTokenF',$accessToken);
//return null;
return $accessToken;
} | php | public function getCredentials(Request $request)
{
// this method is only called if supports() returns true
// For Symfony lower than 3.4 the supports method need to be called manually here:
// if (!$this->supports($request)) {
// return null;
// }
$accessToken=$this->fetchAccessToken($this->getGoogleClient());
$session = $request->getSession();
$session->set('googleTokenF',$accessToken);
//return null;
return $accessToken;
} | [
"public",
"function",
"getCredentials",
"(",
"Request",
"$",
"request",
")",
"{",
"// this method is only called if supports() returns true",
"// For Symfony lower than 3.4 the supports method need to be called manually here:",
"// if (!$this->supports($request)) {",
"// return null;",
"// }",
"$",
"accessToken",
"=",
"$",
"this",
"->",
"fetchAccessToken",
"(",
"$",
"this",
"->",
"getGoogleClient",
"(",
")",
")",
";",
"$",
"session",
"=",
"$",
"request",
"->",
"getSession",
"(",
")",
";",
"$",
"session",
"->",
"set",
"(",
"'googleTokenF'",
",",
"$",
"accessToken",
")",
";",
"//return null;",
"return",
"$",
"accessToken",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L93-L109 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.getUser | public function getUser($credentials, UserProviderInterface $userProvider)
{
/** @var GoogleUser $googleUser */
$googleUser = $this->getGoogleClient()
->fetchUserFromToken($credentials);
$email = $googleUser->getEmail();
//Setto la variabile autorizzato a false
$autorizzato=false;
// 1) have they logged in with Google before? Easy!
$user = $this->em->getRepository('retItaliaAuthenticationBundle:SaUtente')
->findOneBy(['googleId' => $googleUser->getId(),'sospeso'=>['0',null]]);
if ($user) {
//Controllo se l'utente ha un'autorizzazione per l'applicazione
if ($this->controllaAutorizzazione($user))
return $user;
}
// 2) do we have a matching user by email?
$user = $this->em->getRepository('retItaliaAuthenticationBundle:SaUtente')
->findOneBy(['email' => $email,'sospeso'=>['0',null]]);
//Controllo se l'utente ha un'autorizzazione per l'applicazione
if (!$this->controllaAutorizzazione($user))
$user=null;
// 3) Maybe you just want to "register" them by creating
// a User object
if (!empty($user)) {
$user->setGoogleId($googleUser->getId());
$this->em->persist($user);
$this->em->flush();
}
return $user;
} | php | public function getUser($credentials, UserProviderInterface $userProvider)
{
/** @var GoogleUser $googleUser */
$googleUser = $this->getGoogleClient()
->fetchUserFromToken($credentials);
$email = $googleUser->getEmail();
//Setto la variabile autorizzato a false
$autorizzato=false;
// 1) have they logged in with Google before? Easy!
$user = $this->em->getRepository('retItaliaAuthenticationBundle:SaUtente')
->findOneBy(['googleId' => $googleUser->getId(),'sospeso'=>['0',null]]);
if ($user) {
//Controllo se l'utente ha un'autorizzazione per l'applicazione
if ($this->controllaAutorizzazione($user))
return $user;
}
// 2) do we have a matching user by email?
$user = $this->em->getRepository('retItaliaAuthenticationBundle:SaUtente')
->findOneBy(['email' => $email,'sospeso'=>['0',null]]);
//Controllo se l'utente ha un'autorizzazione per l'applicazione
if (!$this->controllaAutorizzazione($user))
$user=null;
// 3) Maybe you just want to "register" them by creating
// a User object
if (!empty($user)) {
$user->setGoogleId($googleUser->getId());
$this->em->persist($user);
$this->em->flush();
}
return $user;
} | [
"public",
"function",
"getUser",
"(",
"$",
"credentials",
",",
"UserProviderInterface",
"$",
"userProvider",
")",
"{",
"/** @var GoogleUser $googleUser */",
"$",
"googleUser",
"=",
"$",
"this",
"->",
"getGoogleClient",
"(",
")",
"->",
"fetchUserFromToken",
"(",
"$",
"credentials",
")",
";",
"$",
"email",
"=",
"$",
"googleUser",
"->",
"getEmail",
"(",
")",
";",
"//Setto la variabile autorizzato a false",
"$",
"autorizzato",
"=",
"false",
";",
"// 1) have they logged in with Google before? Easy!",
"$",
"user",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'retItaliaAuthenticationBundle:SaUtente'",
")",
"->",
"findOneBy",
"(",
"[",
"'googleId'",
"=>",
"$",
"googleUser",
"->",
"getId",
"(",
")",
",",
"'sospeso'",
"=>",
"[",
"'0'",
",",
"null",
"]",
"]",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"//Controllo se l'utente ha un'autorizzazione per l'applicazione",
"if",
"(",
"$",
"this",
"->",
"controllaAutorizzazione",
"(",
"$",
"user",
")",
")",
"return",
"$",
"user",
";",
"}",
"// 2) do we have a matching user by email?",
"$",
"user",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"'retItaliaAuthenticationBundle:SaUtente'",
")",
"->",
"findOneBy",
"(",
"[",
"'email'",
"=>",
"$",
"email",
",",
"'sospeso'",
"=>",
"[",
"'0'",
",",
"null",
"]",
"]",
")",
";",
"//Controllo se l'utente ha un'autorizzazione per l'applicazione",
"if",
"(",
"!",
"$",
"this",
"->",
"controllaAutorizzazione",
"(",
"$",
"user",
")",
")",
"$",
"user",
"=",
"null",
";",
"// 3) Maybe you just want to \"register\" them by creating",
"// a User object",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"$",
"user",
"->",
"setGoogleId",
"(",
"$",
"googleUser",
"->",
"getId",
"(",
")",
")",
";",
"$",
"this",
"->",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L114-L153 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.checkCredentials | public function checkCredentials($credentials, UserInterface $user)
{
/*if ($user->getPassword() === $credentials['password']) {
return true;
}*/
//return true;
if (empty($user->getIdUtente()))
throw new CustomUserMessageAuthenticationException($this->failMessage);
else return true;
} | php | public function checkCredentials($credentials, UserInterface $user)
{
/*if ($user->getPassword() === $credentials['password']) {
return true;
}*/
//return true;
if (empty($user->getIdUtente()))
throw new CustomUserMessageAuthenticationException($this->failMessage);
else return true;
} | [
"public",
"function",
"checkCredentials",
"(",
"$",
"credentials",
",",
"UserInterface",
"$",
"user",
")",
"{",
"/*if ($user->getPassword() === $credentials['password']) {\n return true;\n }*/",
"//return true;",
"if",
"(",
"empty",
"(",
"$",
"user",
"->",
"getIdUtente",
"(",
")",
")",
")",
"throw",
"new",
"CustomUserMessageAuthenticationException",
"(",
"$",
"this",
"->",
"failMessage",
")",
";",
"else",
"return",
"true",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L168-L177 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.onAuthenticationSuccess | public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
$session = $request->getSession();
// on success, let the request continue
$key = '_security.main.target_path'; #where "main" is your firewall name
//check if the referrer session key has been set
if ($session->has($key)) {
//set the url based on the link they were trying to access before being authenticated
$url = $session->get($key);
//remove the session key
$session->remove($key);
}
//if the referrer key was never set, redirect to a default route
else{
$url = $this->router->generate('homepage');
}
return new RedirectResponse($url);
} | php | public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
$session = $request->getSession();
// on success, let the request continue
$key = '_security.main.target_path'; #where "main" is your firewall name
//check if the referrer session key has been set
if ($session->has($key)) {
//set the url based on the link they were trying to access before being authenticated
$url = $session->get($key);
//remove the session key
$session->remove($key);
}
//if the referrer key was never set, redirect to a default route
else{
$url = $this->router->generate('homepage');
}
return new RedirectResponse($url);
} | [
"public",
"function",
"onAuthenticationSuccess",
"(",
"Request",
"$",
"request",
",",
"TokenInterface",
"$",
"token",
",",
"$",
"providerKey",
")",
"{",
"$",
"session",
"=",
"$",
"request",
"->",
"getSession",
"(",
")",
";",
"// on success, let the request continue",
"$",
"key",
"=",
"'_security.main.target_path'",
";",
"#where \"main\" is your firewall name",
"//check if the referrer session key has been set",
"if",
"(",
"$",
"session",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"//set the url based on the link they were trying to access before being authenticated",
"$",
"url",
"=",
"$",
"session",
"->",
"get",
"(",
"$",
"key",
")",
";",
"//remove the session key",
"$",
"session",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"//if the referrer key was never set, redirect to a default route",
"else",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'homepage'",
")",
";",
"}",
"return",
"new",
"RedirectResponse",
"(",
"$",
"url",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L182-L203 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.onAuthenticationFailure | public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
$url = $this->router->generate('nonAutorizzato');
return new RedirectResponse($url);
} | php | public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$request->getSession()->set(Security::AUTHENTICATION_ERROR, $exception);
$url = $this->router->generate('nonAutorizzato');
return new RedirectResponse($url);
} | [
"public",
"function",
"onAuthenticationFailure",
"(",
"Request",
"$",
"request",
",",
"AuthenticationException",
"$",
"exception",
")",
"{",
"$",
"request",
"->",
"getSession",
"(",
")",
"->",
"set",
"(",
"Security",
"::",
"AUTHENTICATION_ERROR",
",",
"$",
"exception",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'nonAutorizzato'",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"url",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L208-L213 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.start | public function start(Request $request, AuthenticationException $authException = null)
{
$url = $this->router->generate('login');
return new RedirectResponse($url);
} | php | public function start(Request $request, AuthenticationException $authException = null)
{
$url = $this->router->generate('login');
return new RedirectResponse($url);
} | [
"public",
"function",
"start",
"(",
"Request",
"$",
"request",
",",
"AuthenticationException",
"$",
"authException",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"'login'",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"url",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L218-L222 |
RetItaliaSpA/AuthenticationBundle | Security/GoogleAuthenticator.php | GoogleAuthenticator.controllaAutorizzazione | private function controllaAutorizzazione($user) {
//Preimposto autorizzato a false
$autorizzato=false;
//Innanzitutto controllo se l'entity utente non è vuota
if (!empty($user)) {
//Controllo se l'utente ha un'autorizzazione per l'applicazione
$autorizzazioni=$user->getIdAutorizzazione();
foreach($autorizzazioni as $autorizzazione){
/** @var SaAutorizzazione $autorizzazione */
if ($autorizzazione->getIdApplicazione()->getIdApplicazione()==$this->applicationId) {
$autorizzato=true;
break;
}
}
}
return $autorizzato;
} | php | private function controllaAutorizzazione($user) {
//Preimposto autorizzato a false
$autorizzato=false;
//Innanzitutto controllo se l'entity utente non è vuota
if (!empty($user)) {
//Controllo se l'utente ha un'autorizzazione per l'applicazione
$autorizzazioni=$user->getIdAutorizzazione();
foreach($autorizzazioni as $autorizzazione){
/** @var SaAutorizzazione $autorizzazione */
if ($autorizzazione->getIdApplicazione()->getIdApplicazione()==$this->applicationId) {
$autorizzato=true;
break;
}
}
}
return $autorizzato;
} | [
"private",
"function",
"controllaAutorizzazione",
"(",
"$",
"user",
")",
"{",
"//Preimposto autorizzato a false",
"$",
"autorizzato",
"=",
"false",
";",
"//Innanzitutto controllo se l'entity utente non è vuota",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"//Controllo se l'utente ha un'autorizzazione per l'applicazione",
"$",
"autorizzazioni",
"=",
"$",
"user",
"->",
"getIdAutorizzazione",
"(",
")",
";",
"foreach",
"(",
"$",
"autorizzazioni",
"as",
"$",
"autorizzazione",
")",
"{",
"/** @var SaAutorizzazione $autorizzazione */",
"if",
"(",
"$",
"autorizzazione",
"->",
"getIdApplicazione",
"(",
")",
"->",
"getIdApplicazione",
"(",
")",
"==",
"$",
"this",
"->",
"applicationId",
")",
"{",
"$",
"autorizzato",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"autorizzato",
";",
"}"
] | Questa funzione verifica se l'utente è autorizzato per uno specifico application id
@param $user
@return bool | [
"Questa",
"funzione",
"verifica",
"se",
"l",
"utente",
"è",
"autorizzato",
"per",
"uno",
"specifico",
"application",
"id"
] | train | https://github.com/RetItaliaSpA/AuthenticationBundle/blob/4c2b28d0d290a68ade9215f872c417749deea2cd/Security/GoogleAuthenticator.php#L238-L263 |
kherge-abandoned/lib-observer | src/lib/Phine/Observer/ArrayCollection.php | ArrayCollection.offsetSet | public function offsetSet($id, $subject)
{
if ($this->isSubjectRegistered($id)) {
$this->replaceSubject($id, $subject);
} else {
$this->registerSubject($id, $subject);
}
} | php | public function offsetSet($id, $subject)
{
if ($this->isSubjectRegistered($id)) {
$this->replaceSubject($id, $subject);
} else {
$this->registerSubject($id, $subject);
}
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"id",
",",
"$",
"subject",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSubjectRegistered",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"replaceSubject",
"(",
"$",
"id",
",",
"$",
"subject",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"registerSubject",
"(",
"$",
"id",
",",
"$",
"subject",
")",
";",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/kherge-abandoned/lib-observer/blob/a3ed2f81c79a056ba1fc4949e03c3e1601665106/src/lib/Phine/Observer/ArrayCollection.php#L46-L53 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.appendVisitor | public function appendVisitor(VisitorInterface $visitor)
{
foreach ($this->orderedRepositories as $repository) {
$repository->appendVisitor($visitor);
}
} | php | public function appendVisitor(VisitorInterface $visitor)
{
foreach ($this->orderedRepositories as $repository) {
$repository->appendVisitor($visitor);
}
} | [
"public",
"function",
"appendVisitor",
"(",
"VisitorInterface",
"$",
"visitor",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"repository",
"->",
"appendVisitor",
"(",
"$",
"visitor",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L66-L71 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.appendFilter | public function appendFilter(FilterInterface $filter)
{
foreach ($this->orderedRepositories as $repository) {
$repository->appendFilter(clone $filter);
}
return $this;
} | php | public function appendFilter(FilterInterface $filter)
{
foreach ($this->orderedRepositories as $repository) {
$repository->appendFilter(clone $filter);
}
return $this;
} | [
"public",
"function",
"appendFilter",
"(",
"FilterInterface",
"$",
"filter",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"repository",
"->",
"appendFilter",
"(",
"clone",
"$",
"filter",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L76-L82 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.fetchEntityByEntityId | public function fetchEntityByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findEntityByEntityId($entityId);
if ($entity) {
return $entity;
}
}
throw new EntityNotFoundException("Unable to find '$entityId' in any configured repository");
} | php | public function fetchEntityByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findEntityByEntityId($entityId);
if ($entity) {
return $entity;
}
}
throw new EntityNotFoundException("Unable to find '$entityId' in any configured repository");
} | [
"public",
"function",
"fetchEntityByEntityId",
"(",
"$",
"entityId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"entity",
"=",
"$",
"repository",
"->",
"findEntityByEntityId",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"throw",
"new",
"EntityNotFoundException",
"(",
"\"Unable to find '$entityId' in any configured repository\"",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L87-L98 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.fetchServiceProviderByEntityId | public function fetchServiceProviderByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findServiceProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
throw new EntityNotFoundException("Unable to find '$entityId' in any configured repository");
} | php | public function fetchServiceProviderByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findServiceProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
throw new EntityNotFoundException("Unable to find '$entityId' in any configured repository");
} | [
"public",
"function",
"fetchServiceProviderByEntityId",
"(",
"$",
"entityId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"entity",
"=",
"$",
"repository",
"->",
"findServiceProviderByEntityId",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"throw",
"new",
"EntityNotFoundException",
"(",
"\"Unable to find '$entityId' in any configured repository\"",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L103-L114 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.fetchIdentityProviderByEntityId | public function fetchIdentityProviderByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findIdentityProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
throw new EntityNotFoundException("Unable to find '$entityId' in any configured repository");
} | php | public function fetchIdentityProviderByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findIdentityProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
throw new EntityNotFoundException("Unable to find '$entityId' in any configured repository");
} | [
"public",
"function",
"fetchIdentityProviderByEntityId",
"(",
"$",
"entityId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"entity",
"=",
"$",
"repository",
"->",
"findIdentityProviderByEntityId",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"throw",
"new",
"EntityNotFoundException",
"(",
"\"Unable to find '$entityId' in any configured repository\"",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L119-L130 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findEntityByEntityId | public function findEntityByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findEntityByEntityId($entityId);
if ($entity) {
return $entity;
}
}
return null;
} | php | public function findEntityByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findEntityByEntityId($entityId);
if ($entity) {
return $entity;
}
}
return null;
} | [
"public",
"function",
"findEntityByEntityId",
"(",
"$",
"entityId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"entity",
"=",
"$",
"repository",
"->",
"findEntityByEntityId",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L135-L145 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findIdentityProviderByEntityId | public function findIdentityProviderByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findIdentityProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
return null;
} | php | public function findIdentityProviderByEntityId($entityId)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findIdentityProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
return null;
} | [
"public",
"function",
"findIdentityProviderByEntityId",
"(",
"$",
"entityId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"entity",
"=",
"$",
"repository",
"->",
"findIdentityProviderByEntityId",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L150-L160 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findServiceProviderByEntityId | public function findServiceProviderByEntityId($entityId, LoggerInterface $logger = null)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findServiceProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
return null;
} | php | public function findServiceProviderByEntityId($entityId, LoggerInterface $logger = null)
{
foreach ($this->orderedRepositories as $repository) {
$entity = $repository->findServiceProviderByEntityId($entityId);
if ($entity) {
return $entity;
}
}
return null;
} | [
"public",
"function",
"findServiceProviderByEntityId",
"(",
"$",
"entityId",
",",
"LoggerInterface",
"$",
"logger",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"entity",
"=",
"$",
"repository",
"->",
"findServiceProviderByEntityId",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L165-L175 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findIdentityProviders | public function findIdentityProviders()
{
$identityProviders = array();
foreach ($this->orderedRepositories as $repository) {
$repositoryIdentityProviders = $repository->findIdentityProviders();
foreach ($repositoryIdentityProviders as $identityProvider) {
// Earlier repositories have precedence, so if later repositories give the same entityId,
// then we ignore that.
if (isset($identityProviders[$identityProvider->entityId])) {
continue;
}
$identityProviders[$identityProvider->entityId] = $identityProvider;
}
}
return $identityProviders;
} | php | public function findIdentityProviders()
{
$identityProviders = array();
foreach ($this->orderedRepositories as $repository) {
$repositoryIdentityProviders = $repository->findIdentityProviders();
foreach ($repositoryIdentityProviders as $identityProvider) {
// Earlier repositories have precedence, so if later repositories give the same entityId,
// then we ignore that.
if (isset($identityProviders[$identityProvider->entityId])) {
continue;
}
$identityProviders[$identityProvider->entityId] = $identityProvider;
}
}
return $identityProviders;
} | [
"public",
"function",
"findIdentityProviders",
"(",
")",
"{",
"$",
"identityProviders",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"repositoryIdentityProviders",
"=",
"$",
"repository",
"->",
"findIdentityProviders",
"(",
")",
";",
"foreach",
"(",
"$",
"repositoryIdentityProviders",
"as",
"$",
"identityProvider",
")",
"{",
"// Earlier repositories have precedence, so if later repositories give the same entityId,",
"// then we ignore that.",
"if",
"(",
"isset",
"(",
"$",
"identityProviders",
"[",
"$",
"identityProvider",
"->",
"entityId",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"identityProviders",
"[",
"$",
"identityProvider",
"->",
"entityId",
"]",
"=",
"$",
"identityProvider",
";",
"}",
"}",
"return",
"$",
"identityProviders",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L180-L196 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findAllIdentityProviderEntityIds | public function findAllIdentityProviderEntityIds()
{
$identityProviderEntityIds = array();
foreach ($this->orderedRepositories as $repository) {
$identityProviderEntityIds = array_merge(
$identityProviderEntityIds,
$repository->findAllIdentityProviderEntityIds()
);
}
return array_values(array_unique($identityProviderEntityIds));
} | php | public function findAllIdentityProviderEntityIds()
{
$identityProviderEntityIds = array();
foreach ($this->orderedRepositories as $repository) {
$identityProviderEntityIds = array_merge(
$identityProviderEntityIds,
$repository->findAllIdentityProviderEntityIds()
);
}
return array_values(array_unique($identityProviderEntityIds));
} | [
"public",
"function",
"findAllIdentityProviderEntityIds",
"(",
")",
"{",
"$",
"identityProviderEntityIds",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"identityProviderEntityIds",
"=",
"array_merge",
"(",
"$",
"identityProviderEntityIds",
",",
"$",
"repository",
"->",
"findAllIdentityProviderEntityIds",
"(",
")",
")",
";",
"}",
"return",
"array_values",
"(",
"array_unique",
"(",
"$",
"identityProviderEntityIds",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L201-L211 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findReservedSchacHomeOrganizations | public function findReservedSchacHomeOrganizations()
{
$schacHomeOrganizations = array();
foreach ($this->orderedRepositories as $repository) {
$schacHomeOrganizations = array_merge(
$schacHomeOrganizations,
$repository->findReservedSchacHomeOrganizations()
);
}
return array_values(array_unique($schacHomeOrganizations));
} | php | public function findReservedSchacHomeOrganizations()
{
$schacHomeOrganizations = array();
foreach ($this->orderedRepositories as $repository) {
$schacHomeOrganizations = array_merge(
$schacHomeOrganizations,
$repository->findReservedSchacHomeOrganizations()
);
}
return array_values(array_unique($schacHomeOrganizations));
} | [
"public",
"function",
"findReservedSchacHomeOrganizations",
"(",
")",
"{",
"$",
"schacHomeOrganizations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"schacHomeOrganizations",
"=",
"array_merge",
"(",
"$",
"schacHomeOrganizations",
",",
"$",
"repository",
"->",
"findReservedSchacHomeOrganizations",
"(",
")",
")",
";",
"}",
"return",
"array_values",
"(",
"array_unique",
"(",
"$",
"schacHomeOrganizations",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L216-L226 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.findEntitiesPublishableInEdugain | public function findEntitiesPublishableInEdugain(MetadataRepositoryInterface $repository = null)
{
$entityIndex = array();
$entities = array();
foreach ($this->orderedRepositories as $repository) {
$repositoryEntities = $repository->findEntitiesPublishableInEdugain($this);
foreach ($repositoryEntities as $repositoryEntity) {
// When is an entity the same as another one? For now when it's the same role type (SP / IDP)
// and has the same entityId. Though the SAML2 spec allows for much more than that,
// we currently don't support anything more.
// Note that we avoid an O(n3) lookup here by maintaining an index.
$index = get_class($repositoryEntity) . ':' . $repositoryEntity->entityId;
if (in_array($index, $entityIndex)) {
continue;
}
$entityIndex[] = $index;
$entities[] = $repositoryEntity;
}
}
return $entities;
} | php | public function findEntitiesPublishableInEdugain(MetadataRepositoryInterface $repository = null)
{
$entityIndex = array();
$entities = array();
foreach ($this->orderedRepositories as $repository) {
$repositoryEntities = $repository->findEntitiesPublishableInEdugain($this);
foreach ($repositoryEntities as $repositoryEntity) {
// When is an entity the same as another one? For now when it's the same role type (SP / IDP)
// and has the same entityId. Though the SAML2 spec allows for much more than that,
// we currently don't support anything more.
// Note that we avoid an O(n3) lookup here by maintaining an index.
$index = get_class($repositoryEntity) . ':' . $repositoryEntity->entityId;
if (in_array($index, $entityIndex)) {
continue;
}
$entityIndex[] = $index;
$entities[] = $repositoryEntity;
}
}
return $entities;
} | [
"public",
"function",
"findEntitiesPublishableInEdugain",
"(",
"MetadataRepositoryInterface",
"$",
"repository",
"=",
"null",
")",
"{",
"$",
"entityIndex",
"=",
"array",
"(",
")",
";",
"$",
"entities",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"$",
"repositoryEntities",
"=",
"$",
"repository",
"->",
"findEntitiesPublishableInEdugain",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"repositoryEntities",
"as",
"$",
"repositoryEntity",
")",
"{",
"// When is an entity the same as another one? For now when it's the same role type (SP / IDP)",
"// and has the same entityId. Though the SAML2 spec allows for much more than that,",
"// we currently don't support anything more.",
"// Note that we avoid an O(n3) lookup here by maintaining an index.",
"$",
"index",
"=",
"get_class",
"(",
"$",
"repositoryEntity",
")",
".",
"':'",
".",
"$",
"repositoryEntity",
"->",
"entityId",
";",
"if",
"(",
"in_array",
"(",
"$",
"index",
",",
"$",
"entityIndex",
")",
")",
"{",
"continue",
";",
"}",
"$",
"entityIndex",
"[",
"]",
"=",
"$",
"index",
";",
"$",
"entities",
"[",
"]",
"=",
"$",
"repositoryEntity",
";",
"}",
"}",
"return",
"$",
"entities",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L231-L252 |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/CompositeMetadataRepository.php | CompositeMetadataRepository.fetchEntityManipulation | public function fetchEntityManipulation(AbstractRole $entity)
{
foreach ($this->orderedRepositories as $repository) {
if (!$repository->findEntityByEntityId($entity->entityId)) {
continue;
}
return $repository->fetchEntityManipulation($entity);
}
throw new \RuntimeException(
__METHOD__ . ' was unable to find a repository for entity: ' . $entity->entityId
);
} | php | public function fetchEntityManipulation(AbstractRole $entity)
{
foreach ($this->orderedRepositories as $repository) {
if (!$repository->findEntityByEntityId($entity->entityId)) {
continue;
}
return $repository->fetchEntityManipulation($entity);
}
throw new \RuntimeException(
__METHOD__ . ' was unable to find a repository for entity: ' . $entity->entityId
);
} | [
"public",
"function",
"fetchEntityManipulation",
"(",
"AbstractRole",
"$",
"entity",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orderedRepositories",
"as",
"$",
"repository",
")",
"{",
"if",
"(",
"!",
"$",
"repository",
"->",
"findEntityByEntityId",
"(",
"$",
"entity",
"->",
"entityId",
")",
")",
"{",
"continue",
";",
"}",
"return",
"$",
"repository",
"->",
"fetchEntityManipulation",
"(",
"$",
"entity",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"__METHOD__",
".",
"' was unable to find a repository for entity: '",
".",
"$",
"entity",
"->",
"entityId",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/CompositeMetadataRepository.php#L257-L270 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.