id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
100 | aloframework/handlers | src/class/ShutdownHandler.php | ShutdownHandler.register | public static function register(LoggerInterface $logger = null, $cfg = null) {
self::$registered = true;
$class = get_called_class();
$handler = new $class($logger, $cfg);
register_shutdown_function([$handler, 'handle']);
self::$lastRegisteredHandler = &$handler;
return $handler;
} | php | public static function register(LoggerInterface $logger = null, $cfg = null) {
self::$registered = true;
$class = get_called_class();
$handler = new $class($logger, $cfg);
register_shutdown_function([$handler, 'handle']);
self::$lastRegisteredHandler = &$handler;
return $handler;
} | [
"public",
"static",
"function",
"register",
"(",
"LoggerInterface",
"$",
"logger",
"=",
"null",
",",
"$",
"cfg",
"=",
"null",
")",
"{",
"self",
"::",
"$",
"registered",
"=",
"true",
";",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"$",
"handler",
"=",
"new",
"$",
"class",
"(",
"$",
"logger",
",",
"$",
"cfg",
")",
";",
"register_shutdown_function",
"(",
"[",
"$",
"handler",
",",
"'handle'",
"]",
")",
";",
"self",
"::",
"$",
"lastRegisteredHandler",
"=",
"&",
"$",
"handler",
";",
"return",
"$",
"handler",
";",
"}"
] | Registers the shutdown handler
@author Art <a.molcanovas@gmail.com>
@param LoggerInterface $logger If provided, this will be used to log shutdowns.
@param AbstractConfig $cfg Configuration options
@return self | [
"Registers",
"the",
"shutdown",
"handler"
] | 3f17510c5e9221855d39c332710d0e512ec8b42d | https://github.com/aloframework/handlers/blob/3f17510c5e9221855d39c332710d0e512ec8b42d/src/class/ShutdownHandler.php#L79-L88 |
101 | aloframework/handlers | src/class/ShutdownHandler.php | ShutdownHandler.handle | public function handle() {
if (ErrorHandler::isRegistered()) {
$e = new Error(error_get_last());
if (Error::shouldBeReported($e->getType())) {
$r = ErrorHandler::getLastReportedError();
$h = ErrorHandler::getLastRegisteredHandler();
if (!$e->isEmpty() && $h && ($r ? !$r->isEmpty() && !$r->equals($e) : true)) {
$h->handle($e->getType(),
Alo::ifnull($e->getMessage(), '<<unknown error>>'),
Alo::ifnull($e->getFile(), '<<unknown file>>'),
Alo::ifnull($e->getLine(), '<<unknown line>>'));
}
}
}
} | php | public function handle() {
if (ErrorHandler::isRegistered()) {
$e = new Error(error_get_last());
if (Error::shouldBeReported($e->getType())) {
$r = ErrorHandler::getLastReportedError();
$h = ErrorHandler::getLastRegisteredHandler();
if (!$e->isEmpty() && $h && ($r ? !$r->isEmpty() && !$r->equals($e) : true)) {
$h->handle($e->getType(),
Alo::ifnull($e->getMessage(), '<<unknown error>>'),
Alo::ifnull($e->getFile(), '<<unknown file>>'),
Alo::ifnull($e->getLine(), '<<unknown line>>'));
}
}
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"ErrorHandler",
"::",
"isRegistered",
"(",
")",
")",
"{",
"$",
"e",
"=",
"new",
"Error",
"(",
"error_get_last",
"(",
")",
")",
";",
"if",
"(",
"Error",
"::",
"shouldBeReported",
"(",
"$",
"e",
"->",
"getType",
"(",
")",
")",
")",
"{",
"$",
"r",
"=",
"ErrorHandler",
"::",
"getLastReportedError",
"(",
")",
";",
"$",
"h",
"=",
"ErrorHandler",
"::",
"getLastRegisteredHandler",
"(",
")",
";",
"if",
"(",
"!",
"$",
"e",
"->",
"isEmpty",
"(",
")",
"&&",
"$",
"h",
"&&",
"(",
"$",
"r",
"?",
"!",
"$",
"r",
"->",
"isEmpty",
"(",
")",
"&&",
"!",
"$",
"r",
"->",
"equals",
"(",
"$",
"e",
")",
":",
"true",
")",
")",
"{",
"$",
"h",
"->",
"handle",
"(",
"$",
"e",
"->",
"getType",
"(",
")",
",",
"Alo",
"::",
"ifnull",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'<<unknown error>>'",
")",
",",
"Alo",
"::",
"ifnull",
"(",
"$",
"e",
"->",
"getFile",
"(",
")",
",",
"'<<unknown file>>'",
")",
",",
"Alo",
"::",
"ifnull",
"(",
"$",
"e",
"->",
"getLine",
"(",
")",
",",
"'<<unknown line>>'",
")",
")",
";",
"}",
"}",
"}",
"}"
] | The shutdown handler
@author Art <a.molcanovas@gmail.com>
@since 1.2.1 Should now report fatal errors if no errors had been raised beforehand.
@codeCoverageIgnore | [
"The",
"shutdown",
"handler"
] | 3f17510c5e9221855d39c332710d0e512ec8b42d | https://github.com/aloframework/handlers/blob/3f17510c5e9221855d39c332710d0e512ec8b42d/src/class/ShutdownHandler.php#L97-L113 |
102 | puli/asset-plugin | src/Api/Target/InstallTarget.php | InstallTarget.match | public function match(Expression $expr)
{
return $expr->evaluate(array(
self::NAME => $this->name,
self::INSTALLER_NAME => $this->installerName,
self::LOCATION => $this->location,
self::URL_FORMAT => $this->urlFormat,
self::PARAMETER_VALUES => $this->parameterValues,
));
} | php | public function match(Expression $expr)
{
return $expr->evaluate(array(
self::NAME => $this->name,
self::INSTALLER_NAME => $this->installerName,
self::LOCATION => $this->location,
self::URL_FORMAT => $this->urlFormat,
self::PARAMETER_VALUES => $this->parameterValues,
));
} | [
"public",
"function",
"match",
"(",
"Expression",
"$",
"expr",
")",
"{",
"return",
"$",
"expr",
"->",
"evaluate",
"(",
"array",
"(",
"self",
"::",
"NAME",
"=>",
"$",
"this",
"->",
"name",
",",
"self",
"::",
"INSTALLER_NAME",
"=>",
"$",
"this",
"->",
"installerName",
",",
"self",
"::",
"LOCATION",
"=>",
"$",
"this",
"->",
"location",
",",
"self",
"::",
"URL_FORMAT",
"=>",
"$",
"this",
"->",
"urlFormat",
",",
"self",
"::",
"PARAMETER_VALUES",
"=>",
"$",
"this",
"->",
"parameterValues",
",",
")",
")",
";",
"}"
] | Returns whether the target matches the given expression.
@param Expression $expr The search criteria. You can use the fields
{@link NAME}, {@link CLASS_NAME},
{@link LOCATION}, {@link URL_FORMAT} and
{@link PARAMETER_VALUES} in the expression.
@return bool Returns `true` if the target matches the expression and
`false` otherwise. | [
"Returns",
"whether",
"the",
"target",
"matches",
"the",
"given",
"expression",
"."
] | f36c4a403a2173aced54376690a399884cde2627 | https://github.com/puli/asset-plugin/blob/f36c4a403a2173aced54376690a399884cde2627/src/Api/Target/InstallTarget.php#L237-L246 |
103 | budkit/budkit-framework | src/Budkit/Datastore/Drivers/MySQLi/Table.php | Table.save | public function save($data = null)
{
//1. Check if we have data and deal with it!
if (!is_null($data)) {
if (!$this->bindData($data)) {
//we could not save the data
return false;
}
}
//2. Check if the primary key has a value
$primary = $this->keys();
//3. if the primary key has a value, then we are updating, else we are inserting
if (isset($primary->Value) && !empty($primary->Value)) {
return $this->update($primary->Value);
} else {
return $this->insert();
}
//if we get here then there is a problem
return false;
} | php | public function save($data = null)
{
//1. Check if we have data and deal with it!
if (!is_null($data)) {
if (!$this->bindData($data)) {
//we could not save the data
return false;
}
}
//2. Check if the primary key has a value
$primary = $this->keys();
//3. if the primary key has a value, then we are updating, else we are inserting
if (isset($primary->Value) && !empty($primary->Value)) {
return $this->update($primary->Value);
} else {
return $this->insert();
}
//if we get here then there is a problem
return false;
} | [
"public",
"function",
"save",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"//1. Check if we have data and deal with it!",
"if",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"bindData",
"(",
"$",
"data",
")",
")",
"{",
"//we could not save the data",
"return",
"false",
";",
"}",
"}",
"//2. Check if the primary key has a value",
"$",
"primary",
"=",
"$",
"this",
"->",
"keys",
"(",
")",
";",
"//3. if the primary key has a value, then we are updating, else we are inserting",
"if",
"(",
"isset",
"(",
"$",
"primary",
"->",
"Value",
")",
"&&",
"!",
"empty",
"(",
"$",
"primary",
"->",
"Value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"update",
"(",
"$",
"primary",
"->",
"Value",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"insert",
"(",
")",
";",
"}",
"//if we get here then there is a problem",
"return",
"false",
";",
"}"
] | Saves changes to the database
@param type $data
@return type | [
"Saves",
"changes",
"to",
"the",
"database"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Drivers/MySQLi/Table.php#L76-L97 |
104 | budkit/budkit-framework | src/Budkit/Datastore/Drivers/MySQLi/Table.php | Table.keys | public function keys($type = 'primary', $limit = 1)
{
$valid = array("primary" => 'PRI', "unique" => 'UNI', "multiple" => 'MUL');
//Check if we have a valid key Type;
if (empty($this->schema) || !array_key_exists($type, $valid)) {
return array();
}
$keys = array();
$i = 0;
foreach ($this->schema as $field => $schema) {
if ($limit > 0 && $i >= $limit)
break; //useful with compound keys
if (strval($schema->Key) == $valid[$type]) {
$keys[$field] = $schema;
}
$i++;
}
$return = (array)$keys;
if ($limit === 1 && !empty($return)) {
$fieldname = array_keys($return);
$return = $return[$fieldname[0]];
}
return $return;
} | php | public function keys($type = 'primary', $limit = 1)
{
$valid = array("primary" => 'PRI', "unique" => 'UNI', "multiple" => 'MUL');
//Check if we have a valid key Type;
if (empty($this->schema) || !array_key_exists($type, $valid)) {
return array();
}
$keys = array();
$i = 0;
foreach ($this->schema as $field => $schema) {
if ($limit > 0 && $i >= $limit)
break; //useful with compound keys
if (strval($schema->Key) == $valid[$type]) {
$keys[$field] = $schema;
}
$i++;
}
$return = (array)$keys;
if ($limit === 1 && !empty($return)) {
$fieldname = array_keys($return);
$return = $return[$fieldname[0]];
}
return $return;
} | [
"public",
"function",
"keys",
"(",
"$",
"type",
"=",
"'primary'",
",",
"$",
"limit",
"=",
"1",
")",
"{",
"$",
"valid",
"=",
"array",
"(",
"\"primary\"",
"=>",
"'PRI'",
",",
"\"unique\"",
"=>",
"'UNI'",
",",
"\"multiple\"",
"=>",
"'MUL'",
")",
";",
"//Check if we have a valid key Type;",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"schema",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"valid",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"as",
"$",
"field",
"=>",
"$",
"schema",
")",
"{",
"if",
"(",
"$",
"limit",
">",
"0",
"&&",
"$",
"i",
">=",
"$",
"limit",
")",
"break",
";",
"//useful with compound keys",
"if",
"(",
"strval",
"(",
"$",
"schema",
"->",
"Key",
")",
"==",
"$",
"valid",
"[",
"$",
"type",
"]",
")",
"{",
"$",
"keys",
"[",
"$",
"field",
"]",
"=",
"$",
"schema",
";",
"}",
"$",
"i",
"++",
";",
"}",
"$",
"return",
"=",
"(",
"array",
")",
"$",
"keys",
";",
"if",
"(",
"$",
"limit",
"===",
"1",
"&&",
"!",
"empty",
"(",
"$",
"return",
")",
")",
"{",
"$",
"fieldname",
"=",
"array_keys",
"(",
"$",
"return",
")",
";",
"$",
"return",
"=",
"$",
"return",
"[",
"$",
"fieldname",
"[",
"0",
"]",
"]",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Returns all fields corresponding to the key type
@param string $type primary, unique, multiple | [
"Returns",
"all",
"fields",
"corresponding",
"to",
"the",
"key",
"type"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Drivers/MySQLi/Table.php#L104-L135 |
105 | budkit/budkit-framework | src/Budkit/Datastore/Drivers/MySQLi/Table.php | Table.update | public function update($key, $data = null)
{
//1. Check if we have data and deal with it!
if (!is_null($data)) {
if (!$this->bindData($data)) {
//we could not save the data
return false;
}
}
} | php | public function update($key, $data = null)
{
//1. Check if we have data and deal with it!
if (!is_null($data)) {
if (!$this->bindData($data)) {
//we could not save the data
return false;
}
}
} | [
"public",
"function",
"update",
"(",
"$",
"key",
",",
"$",
"data",
"=",
"null",
")",
"{",
"//1. Check if we have data and deal with it!",
"if",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"bindData",
"(",
"$",
"data",
")",
")",
"{",
"//we could not save the data",
"return",
"false",
";",
"}",
"}",
"}"
] | Updates the database table field value
@param type $key
@param type $data
@return type | [
"Updates",
"the",
"database",
"table",
"field",
"value"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Drivers/MySQLi/Table.php#L144-L153 |
106 | budkit/budkit-framework | src/Budkit/Datastore/Drivers/MySQLi/Table.php | Table.insert | public function insert($data = null, $updateIfExists = FALSE)
{
//1. Check if we have data and deal with it!
if (!is_null($data)) {
if (!$this->bindData($data)) {
//we could not save the data
return false;
}
}
$primary = $this->keys("primary");
$set = array();
foreach ($this->schema as $field => $fieldObject) {
//Skip the primary key for obvious reasons;
if ($field === $primary->Field) continue;
//Set the value pair for inserting
$set[$field] = isset($fieldObject->Value) ? $fieldObject->Value : $fieldObject->Default;
//Use Quotes in place of empty fields?
if (empty($set[$field]) || (isset($fieldObject->Validate) && $fieldObject->Validate == 'string')) {
$set[$field] = $this->dbo->Quote($set[$field]);
}
}
if ($updateIfExists):
$unique = $primary->Field;
if (empty($unique)) {
$updateIfExists = FALSE;
}
endif;
//Insert into the database
return $this->dbo->insert($this->getTableName(), $set, $updateIfExists, $unique);
} | php | public function insert($data = null, $updateIfExists = FALSE)
{
//1. Check if we have data and deal with it!
if (!is_null($data)) {
if (!$this->bindData($data)) {
//we could not save the data
return false;
}
}
$primary = $this->keys("primary");
$set = array();
foreach ($this->schema as $field => $fieldObject) {
//Skip the primary key for obvious reasons;
if ($field === $primary->Field) continue;
//Set the value pair for inserting
$set[$field] = isset($fieldObject->Value) ? $fieldObject->Value : $fieldObject->Default;
//Use Quotes in place of empty fields?
if (empty($set[$field]) || (isset($fieldObject->Validate) && $fieldObject->Validate == 'string')) {
$set[$field] = $this->dbo->Quote($set[$field]);
}
}
if ($updateIfExists):
$unique = $primary->Field;
if (empty($unique)) {
$updateIfExists = FALSE;
}
endif;
//Insert into the database
return $this->dbo->insert($this->getTableName(), $set, $updateIfExists, $unique);
} | [
"public",
"function",
"insert",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"updateIfExists",
"=",
"FALSE",
")",
"{",
"//1. Check if we have data and deal with it!",
"if",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"bindData",
"(",
"$",
"data",
")",
")",
"{",
"//we could not save the data",
"return",
"false",
";",
"}",
"}",
"$",
"primary",
"=",
"$",
"this",
"->",
"keys",
"(",
"\"primary\"",
")",
";",
"$",
"set",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"as",
"$",
"field",
"=>",
"$",
"fieldObject",
")",
"{",
"//Skip the primary key for obvious reasons;",
"if",
"(",
"$",
"field",
"===",
"$",
"primary",
"->",
"Field",
")",
"continue",
";",
"//Set the value pair for inserting",
"$",
"set",
"[",
"$",
"field",
"]",
"=",
"isset",
"(",
"$",
"fieldObject",
"->",
"Value",
")",
"?",
"$",
"fieldObject",
"->",
"Value",
":",
"$",
"fieldObject",
"->",
"Default",
";",
"//Use Quotes in place of empty fields?",
"if",
"(",
"empty",
"(",
"$",
"set",
"[",
"$",
"field",
"]",
")",
"||",
"(",
"isset",
"(",
"$",
"fieldObject",
"->",
"Validate",
")",
"&&",
"$",
"fieldObject",
"->",
"Validate",
"==",
"'string'",
")",
")",
"{",
"$",
"set",
"[",
"$",
"field",
"]",
"=",
"$",
"this",
"->",
"dbo",
"->",
"Quote",
"(",
"$",
"set",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"updateIfExists",
")",
":",
"$",
"unique",
"=",
"$",
"primary",
"->",
"Field",
";",
"if",
"(",
"empty",
"(",
"$",
"unique",
")",
")",
"{",
"$",
"updateIfExists",
"=",
"FALSE",
";",
"}",
"endif",
";",
"//Insert into the database",
"return",
"$",
"this",
"->",
"dbo",
"->",
"insert",
"(",
"$",
"this",
"->",
"getTableName",
"(",
")",
",",
"$",
"set",
",",
"$",
"updateIfExists",
",",
"$",
"unique",
")",
";",
"}"
] | Inserts a new record to the database
@param type $data
@return type | [
"Inserts",
"a",
"new",
"record",
"to",
"the",
"database"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Drivers/MySQLi/Table.php#L161-L198 |
107 | budkit/budkit-framework | src/Budkit/Datastore/Drivers/MySQLi/Table.php | Table.describe | public function describe()
{
$sql = 'DESCRIBE ' . $this->name;
$schema = $this->dbo->prepare($sql)->execute();
while ($row = $schema->fetchObject()) {
if (preg_match('/unsigned/', $row->Type)) {
$row->Unsigned = true;
}
if (preg_match('/^((?:var)?char)\((\d+)\)/', $row->Type, $matches)) {
//$row->Type = $matches[1];
$row->Validate = 'string'; //
$row->Length = $matches[2];
} else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row->Type, $matches)) {
//$row->Type = 'decimal';
$row->Validate = 'decimal';
$row->Precission = $matches[1];
$row->Scale = $matches[2];
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row->Type, $matches)) {
//$row->Type = 'float';
$row->Validate = 'float';
$row->Precission = $matches[1];
$row->Scale = $matches[2];
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row->Type, $matches)) {
//$row->Type = 'interger'; //$matches[1];
$row->Validate = 'interger';
$row->Length = $matches[2];
}
if (strtoupper($row->Key) == 'PRI') {
$row->Primary = true;
if ($row->Extra == 'auto_increment') {
$row->Identity = true;
} else {
$row->Identity = false;
}
}
if (strtoupper($row->Null) == 'NO') {
$row->Null = 0;
} else {
$row->Null = 1;
}
$this->schema[$row->Field] = $row;
}
//Just something good!
return true;
} | php | public function describe()
{
$sql = 'DESCRIBE ' . $this->name;
$schema = $this->dbo->prepare($sql)->execute();
while ($row = $schema->fetchObject()) {
if (preg_match('/unsigned/', $row->Type)) {
$row->Unsigned = true;
}
if (preg_match('/^((?:var)?char)\((\d+)\)/', $row->Type, $matches)) {
//$row->Type = $matches[1];
$row->Validate = 'string'; //
$row->Length = $matches[2];
} else if (preg_match('/^decimal\((\d+),(\d+)\)/', $row->Type, $matches)) {
//$row->Type = 'decimal';
$row->Validate = 'decimal';
$row->Precission = $matches[1];
$row->Scale = $matches[2];
} else if (preg_match('/^float\((\d+),(\d+)\)/', $row->Type, $matches)) {
//$row->Type = 'float';
$row->Validate = 'float';
$row->Precission = $matches[1];
$row->Scale = $matches[2];
} else if (preg_match('/^((?:big|medium|small|tiny)?int)\((\d+)\)/', $row->Type, $matches)) {
//$row->Type = 'interger'; //$matches[1];
$row->Validate = 'interger';
$row->Length = $matches[2];
}
if (strtoupper($row->Key) == 'PRI') {
$row->Primary = true;
if ($row->Extra == 'auto_increment') {
$row->Identity = true;
} else {
$row->Identity = false;
}
}
if (strtoupper($row->Null) == 'NO') {
$row->Null = 0;
} else {
$row->Null = 1;
}
$this->schema[$row->Field] = $row;
}
//Just something good!
return true;
} | [
"public",
"function",
"describe",
"(",
")",
"{",
"$",
"sql",
"=",
"'DESCRIBE '",
".",
"$",
"this",
"->",
"name",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"dbo",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"schema",
"->",
"fetchObject",
"(",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/unsigned/'",
",",
"$",
"row",
"->",
"Type",
")",
")",
"{",
"$",
"row",
"->",
"Unsigned",
"=",
"true",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^((?:var)?char)\\((\\d+)\\)/'",
",",
"$",
"row",
"->",
"Type",
",",
"$",
"matches",
")",
")",
"{",
"//$row->Type = $matches[1];",
"$",
"row",
"->",
"Validate",
"=",
"'string'",
";",
"//",
"$",
"row",
"->",
"Length",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^decimal\\((\\d+),(\\d+)\\)/'",
",",
"$",
"row",
"->",
"Type",
",",
"$",
"matches",
")",
")",
"{",
"//$row->Type = 'decimal';",
"$",
"row",
"->",
"Validate",
"=",
"'decimal'",
";",
"$",
"row",
"->",
"Precission",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"row",
"->",
"Scale",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^float\\((\\d+),(\\d+)\\)/'",
",",
"$",
"row",
"->",
"Type",
",",
"$",
"matches",
")",
")",
"{",
"//$row->Type = 'float';",
"$",
"row",
"->",
"Validate",
"=",
"'float'",
";",
"$",
"row",
"->",
"Precission",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"row",
"->",
"Scale",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^((?:big|medium|small|tiny)?int)\\((\\d+)\\)/'",
",",
"$",
"row",
"->",
"Type",
",",
"$",
"matches",
")",
")",
"{",
"//$row->Type = 'interger'; //$matches[1];",
"$",
"row",
"->",
"Validate",
"=",
"'interger'",
";",
"$",
"row",
"->",
"Length",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"strtoupper",
"(",
"$",
"row",
"->",
"Key",
")",
"==",
"'PRI'",
")",
"{",
"$",
"row",
"->",
"Primary",
"=",
"true",
";",
"if",
"(",
"$",
"row",
"->",
"Extra",
"==",
"'auto_increment'",
")",
"{",
"$",
"row",
"->",
"Identity",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"row",
"->",
"Identity",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"strtoupper",
"(",
"$",
"row",
"->",
"Null",
")",
"==",
"'NO'",
")",
"{",
"$",
"row",
"->",
"Null",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"row",
"->",
"Null",
"=",
"1",
";",
"}",
"$",
"this",
"->",
"schema",
"[",
"$",
"row",
"->",
"Field",
"]",
"=",
"$",
"row",
";",
"}",
"//Just something good!",
"return",
"true",
";",
"}"
] | Describes a table on load | [
"Describes",
"a",
"table",
"on",
"load"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Drivers/MySQLi/Table.php#L231-L282 |
108 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.add | public static function add($name, array $options)
{
// Already known?
if (array_key_exists($name, self::$_auths)) {
throw new \Exception("There is already a Auth defined for '$name'.", 1);
}
// Create it
$auth = new Auth($name, $options);
self::$_auths[$name] = $auth;
return $auth;
} | php | public static function add($name, array $options)
{
// Already known?
if (array_key_exists($name, self::$_auths)) {
throw new \Exception("There is already a Auth defined for '$name'.", 1);
}
// Create it
$auth = new Auth($name, $options);
self::$_auths[$name] = $auth;
return $auth;
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"name",
",",
"array",
"$",
"options",
")",
"{",
"// Already known?",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"_auths",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There is already a Auth defined for '$name'.\"",
",",
"1",
")",
";",
"}",
"// Create it",
"$",
"auth",
"=",
"new",
"Auth",
"(",
"$",
"name",
",",
"$",
"options",
")",
";",
"self",
"::",
"$",
"_auths",
"[",
"$",
"name",
"]",
"=",
"$",
"auth",
";",
"return",
"$",
"auth",
";",
"}"
] | Add a new authentication to the framework
@param string $name The reference key for this Auth object
@param array $options Array with options
@see __construct()
@return Auth The newly created Auth. | [
"Add",
"a",
"new",
"authentication",
"to",
"the",
"framework"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L148-L161 |
109 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.get | public static function get($name)
{
if (array_key_exists($name, self::$_auths)) {
return self::$_auths[$name];
} else {
throw new \Exception("There is no Auth defined for '$name'.", 1);
}
} | php | public static function get($name)
{
if (array_key_exists($name, self::$_auths)) {
return self::$_auths[$name];
} else {
throw new \Exception("There is no Auth defined for '$name'.", 1);
}
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"_auths",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_auths",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"There is no Auth defined for '$name'.\"",
",",
"1",
")",
";",
"}",
"}"
] | Retrieve a previously defined Auth by its name
@param string $name Name as used when the Auth was configured
@return Auth The Auth object | [
"Retrieve",
"a",
"previously",
"defined",
"Auth",
"by",
"its",
"name"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L168-L175 |
110 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.login | public function login($username, $password)
{
// Get result
$result = $this->validate($username, $password);
// Success?
$this->_result = $result;
if ($result->success) {
// Store it in the session
$storeObject = array(
'username' => $username,
'password' => $result->user->readAttribute($this->_passwordField)
);
$_SESSION[self::$_sessionPrefix . $this->name] = $storeObject;
// Store local vars
$this->_authenticated = true;
$this->_user = $result->user;
// Save last login
$llField = $this->_lastloginField;
$this->user->$llField = new \ActiveRecord\DateTime();
$this->user->save();
}
// Done.
return $result;
} | php | public function login($username, $password)
{
// Get result
$result = $this->validate($username, $password);
// Success?
$this->_result = $result;
if ($result->success) {
// Store it in the session
$storeObject = array(
'username' => $username,
'password' => $result->user->readAttribute($this->_passwordField)
);
$_SESSION[self::$_sessionPrefix . $this->name] = $storeObject;
// Store local vars
$this->_authenticated = true;
$this->_user = $result->user;
// Save last login
$llField = $this->_lastloginField;
$this->user->$llField = new \ActiveRecord\DateTime();
$this->user->save();
}
// Done.
return $result;
} | [
"public",
"function",
"login",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"// Get result",
"$",
"result",
"=",
"$",
"this",
"->",
"validate",
"(",
"$",
"username",
",",
"$",
"password",
")",
";",
"// Success?",
"$",
"this",
"->",
"_result",
"=",
"$",
"result",
";",
"if",
"(",
"$",
"result",
"->",
"success",
")",
"{",
"// Store it in the session",
"$",
"storeObject",
"=",
"array",
"(",
"'username'",
"=>",
"$",
"username",
",",
"'password'",
"=>",
"$",
"result",
"->",
"user",
"->",
"readAttribute",
"(",
"$",
"this",
"->",
"_passwordField",
")",
")",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"_sessionPrefix",
".",
"$",
"this",
"->",
"name",
"]",
"=",
"$",
"storeObject",
";",
"// Store local vars",
"$",
"this",
"->",
"_authenticated",
"=",
"true",
";",
"$",
"this",
"->",
"_user",
"=",
"$",
"result",
"->",
"user",
";",
"// Save last login",
"$",
"llField",
"=",
"$",
"this",
"->",
"_lastloginField",
";",
"$",
"this",
"->",
"user",
"->",
"$",
"llField",
"=",
"new",
"\\",
"ActiveRecord",
"\\",
"DateTime",
"(",
")",
";",
"$",
"this",
"->",
"user",
"->",
"save",
"(",
")",
";",
"}",
"// Done.",
"return",
"$",
"result",
";",
"}"
] | Validate the given username and password and store
the session is authentication is successful.
@param string $username The username for the user to validate.
@param string $password The unencrypted password for the user to validate.
@return \ChickenWire\Auth\AuthResult Result object containing information of authentication | [
"Validate",
"the",
"given",
"username",
"and",
"password",
"and",
"store",
"the",
"session",
"is",
"authentication",
"is",
"successful",
"."
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L324-L357 |
111 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.logout | public function logout()
{
// Am I authenticated?
if ($this->isAuthenticated() == false) {
// Cannot logout!
return false;
}
// Destroy my session
$this->_authenticated = false;
unset($_SESSION[self::$_sessionPrefix . $this->name]);
$this->_user = null;
return true;
} | php | public function logout()
{
// Am I authenticated?
if ($this->isAuthenticated() == false) {
// Cannot logout!
return false;
}
// Destroy my session
$this->_authenticated = false;
unset($_SESSION[self::$_sessionPrefix . $this->name]);
$this->_user = null;
return true;
} | [
"public",
"function",
"logout",
"(",
")",
"{",
"// Am I authenticated?",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
"==",
"false",
")",
"{",
"// Cannot logout!",
"return",
"false",
";",
"}",
"// Destroy my session",
"$",
"this",
"->",
"_authenticated",
"=",
"false",
";",
"unset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"_sessionPrefix",
".",
"$",
"this",
"->",
"name",
"]",
")",
";",
"$",
"this",
"->",
"_user",
"=",
"null",
";",
"return",
"true",
";",
"}"
] | Log out current user
@return boolean Wheter logout was successful | [
"Log",
"out",
"current",
"user"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L363-L380 |
112 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.validate | public function validate($username, $password)
{
// Store original password
$originalPassword = $password;
// Init model
$this->_initModel();
// Find user
$modelName = $this->_model;
$user = $modelName::find("first", array($this->_usernameField => $username));
// Anything?
if (is_null($user)) {
return new AuthResult(AuthResult::USER_NOT_FOUND);
}
// Pre-salt password
if ($this->_useSalt) {
$password = $user->readAttribute($this->_saltField) . $password;
}
// What type of validation to do?
$loginSuccess = false;
$serverPassword = $user->readAttribute($this->_passwordField);
switch ($this->_type) {
case self::MD5:
$loginSuccess = md5($password) == $serverPassword;
break;
case self::BLOWFISH:
$hasher = new PasswordHash(8, false);
$loginSuccess = $hasher->CheckPassword($password, $serverPassword);
break;
default:
throw new \Exception("Unknown encryption: " . $this->_type, 1);
break;
}
// Success?
if (!$loginSuccess) {
// Nope.
return new AuthResult(AuthResult::INCORRECT_PASSWORD);
} else {
// Rotate the salt?
if ($this->_rotateSalt) {
// Now's the moment to re-encrypt the password, so we can store the newly encrypted password in the session
$user->resaltPassword($originalPassword);
$user->Save();
}
// All ok!
return new AuthResult(AuthResult::SUCCESS, $user);
}
} | php | public function validate($username, $password)
{
// Store original password
$originalPassword = $password;
// Init model
$this->_initModel();
// Find user
$modelName = $this->_model;
$user = $modelName::find("first", array($this->_usernameField => $username));
// Anything?
if (is_null($user)) {
return new AuthResult(AuthResult::USER_NOT_FOUND);
}
// Pre-salt password
if ($this->_useSalt) {
$password = $user->readAttribute($this->_saltField) . $password;
}
// What type of validation to do?
$loginSuccess = false;
$serverPassword = $user->readAttribute($this->_passwordField);
switch ($this->_type) {
case self::MD5:
$loginSuccess = md5($password) == $serverPassword;
break;
case self::BLOWFISH:
$hasher = new PasswordHash(8, false);
$loginSuccess = $hasher->CheckPassword($password, $serverPassword);
break;
default:
throw new \Exception("Unknown encryption: " . $this->_type, 1);
break;
}
// Success?
if (!$loginSuccess) {
// Nope.
return new AuthResult(AuthResult::INCORRECT_PASSWORD);
} else {
// Rotate the salt?
if ($this->_rotateSalt) {
// Now's the moment to re-encrypt the password, so we can store the newly encrypted password in the session
$user->resaltPassword($originalPassword);
$user->Save();
}
// All ok!
return new AuthResult(AuthResult::SUCCESS, $user);
}
} | [
"public",
"function",
"validate",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"// Store original password",
"$",
"originalPassword",
"=",
"$",
"password",
";",
"// Init model",
"$",
"this",
"->",
"_initModel",
"(",
")",
";",
"// Find user",
"$",
"modelName",
"=",
"$",
"this",
"->",
"_model",
";",
"$",
"user",
"=",
"$",
"modelName",
"::",
"find",
"(",
"\"first\"",
",",
"array",
"(",
"$",
"this",
"->",
"_usernameField",
"=>",
"$",
"username",
")",
")",
";",
"// Anything?",
"if",
"(",
"is_null",
"(",
"$",
"user",
")",
")",
"{",
"return",
"new",
"AuthResult",
"(",
"AuthResult",
"::",
"USER_NOT_FOUND",
")",
";",
"}",
"// Pre-salt password",
"if",
"(",
"$",
"this",
"->",
"_useSalt",
")",
"{",
"$",
"password",
"=",
"$",
"user",
"->",
"readAttribute",
"(",
"$",
"this",
"->",
"_saltField",
")",
".",
"$",
"password",
";",
"}",
"// What type of validation to do?",
"$",
"loginSuccess",
"=",
"false",
";",
"$",
"serverPassword",
"=",
"$",
"user",
"->",
"readAttribute",
"(",
"$",
"this",
"->",
"_passwordField",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"_type",
")",
"{",
"case",
"self",
"::",
"MD5",
":",
"$",
"loginSuccess",
"=",
"md5",
"(",
"$",
"password",
")",
"==",
"$",
"serverPassword",
";",
"break",
";",
"case",
"self",
"::",
"BLOWFISH",
":",
"$",
"hasher",
"=",
"new",
"PasswordHash",
"(",
"8",
",",
"false",
")",
";",
"$",
"loginSuccess",
"=",
"$",
"hasher",
"->",
"CheckPassword",
"(",
"$",
"password",
",",
"$",
"serverPassword",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Unknown encryption: \"",
".",
"$",
"this",
"->",
"_type",
",",
"1",
")",
";",
"break",
";",
"}",
"// Success?",
"if",
"(",
"!",
"$",
"loginSuccess",
")",
"{",
"// Nope.",
"return",
"new",
"AuthResult",
"(",
"AuthResult",
"::",
"INCORRECT_PASSWORD",
")",
";",
"}",
"else",
"{",
"// Rotate the salt?",
"if",
"(",
"$",
"this",
"->",
"_rotateSalt",
")",
"{",
"// Now's the moment to re-encrypt the password, so we can store the newly encrypted password in the session",
"$",
"user",
"->",
"resaltPassword",
"(",
"$",
"originalPassword",
")",
";",
"$",
"user",
"->",
"Save",
"(",
")",
";",
"}",
"// All ok!",
"return",
"new",
"AuthResult",
"(",
"AuthResult",
"::",
"SUCCESS",
",",
"$",
"user",
")",
";",
"}",
"}"
] | Validate the given username and password.
@param string $username The username for the user to validate.
@param string $password The unencrypted password for the user to validate.
@return \ChickenWire\Auth\AuthResult Whether user validation was successful. | [
"Validate",
"the",
"given",
"username",
"and",
"password",
"."
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L389-L454 |
113 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.createLoginForm | public function createLoginForm($options = array())
{
// Default options
$options = array_merge(array(
"action" => $this->loginUri,
"method" => "post"
), $options);
// Create it!
$form = new Form($options);
// Done.
return $form;
} | php | public function createLoginForm($options = array())
{
// Default options
$options = array_merge(array(
"action" => $this->loginUri,
"method" => "post"
), $options);
// Create it!
$form = new Form($options);
// Done.
return $form;
} | [
"public",
"function",
"createLoginForm",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"// Default options",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"\"action\"",
"=>",
"$",
"this",
"->",
"loginUri",
",",
"\"method\"",
"=>",
"\"post\"",
")",
",",
"$",
"options",
")",
";",
"// Create it!",
"$",
"form",
"=",
"new",
"Form",
"(",
"$",
"options",
")",
";",
"// Done.",
"return",
"$",
"form",
";",
"}"
] | Create a Form object with preset options for this Auth
@param array $options (default: array()) Optional array of options to pass on to the Form constructor
@return \ChickenWire\Form\Form The created Form instance | [
"Create",
"a",
"Form",
"object",
"with",
"preset",
"options",
"for",
"this",
"Auth"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L461-L476 |
114 | rseyferth/chickenwire | src/ChickenWire/Auth.php | Auth.isAuthenticated | public function isAuthenticated()
{
// Already authenticated?
if ($this->_authenticated) return true;
// Check session
if (array_key_exists(self::$_sessionPrefix . $this->_name, $_SESSION)) {
// Get credentials
$cred = $_SESSION[self::$_sessionPrefix . $this->_name];
// Init model
$this->_initModel();
// Find user
$modelName = $this->_model;
$user = $modelName::find("first", array(
$this->_usernameField => $cred['username'],
$this->_passwordField => $cred['password']
));
// Anything?
if (is_null($user)) {
return false;
}
// Set result
$this->_result = new AuthResult(AuthResult::SUCCESS, $user);
$this->_authenticated = true;
$this->_user = $user;
return true;
}
// Not authenticated.
return false;
} | php | public function isAuthenticated()
{
// Already authenticated?
if ($this->_authenticated) return true;
// Check session
if (array_key_exists(self::$_sessionPrefix . $this->_name, $_SESSION)) {
// Get credentials
$cred = $_SESSION[self::$_sessionPrefix . $this->_name];
// Init model
$this->_initModel();
// Find user
$modelName = $this->_model;
$user = $modelName::find("first", array(
$this->_usernameField => $cred['username'],
$this->_passwordField => $cred['password']
));
// Anything?
if (is_null($user)) {
return false;
}
// Set result
$this->_result = new AuthResult(AuthResult::SUCCESS, $user);
$this->_authenticated = true;
$this->_user = $user;
return true;
}
// Not authenticated.
return false;
} | [
"public",
"function",
"isAuthenticated",
"(",
")",
"{",
"// Already authenticated?",
"if",
"(",
"$",
"this",
"->",
"_authenticated",
")",
"return",
"true",
";",
"// Check session",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"$",
"_sessionPrefix",
".",
"$",
"this",
"->",
"_name",
",",
"$",
"_SESSION",
")",
")",
"{",
"// Get credentials",
"$",
"cred",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"_sessionPrefix",
".",
"$",
"this",
"->",
"_name",
"]",
";",
"// Init model",
"$",
"this",
"->",
"_initModel",
"(",
")",
";",
"// Find user",
"$",
"modelName",
"=",
"$",
"this",
"->",
"_model",
";",
"$",
"user",
"=",
"$",
"modelName",
"::",
"find",
"(",
"\"first\"",
",",
"array",
"(",
"$",
"this",
"->",
"_usernameField",
"=>",
"$",
"cred",
"[",
"'username'",
"]",
",",
"$",
"this",
"->",
"_passwordField",
"=>",
"$",
"cred",
"[",
"'password'",
"]",
")",
")",
";",
"// Anything?",
"if",
"(",
"is_null",
"(",
"$",
"user",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Set result",
"$",
"this",
"->",
"_result",
"=",
"new",
"AuthResult",
"(",
"AuthResult",
"::",
"SUCCESS",
",",
"$",
"user",
")",
";",
"$",
"this",
"->",
"_authenticated",
"=",
"true",
";",
"$",
"this",
"->",
"_user",
"=",
"$",
"user",
";",
"return",
"true",
";",
"}",
"// Not authenticated.",
"return",
"false",
";",
"}"
] | Check if the current session is authenticated for this Auth instance
@return boolean True if authenticated, false when not authenticated. | [
"Check",
"if",
"the",
"current",
"session",
"is",
"authenticated",
"for",
"this",
"Auth",
"instance"
] | 74921f0a0d489366602e25df43eda894719e43d3 | https://github.com/rseyferth/chickenwire/blob/74921f0a0d489366602e25df43eda894719e43d3/src/ChickenWire/Auth.php#L482-L521 |
115 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.registerScheme | public function registerScheme(AuthenticationScheme $scheme, $name = null)
{
$this->schemes[$name ?: $scheme->getName()] = $scheme;
} | php | public function registerScheme(AuthenticationScheme $scheme, $name = null)
{
$this->schemes[$name ?: $scheme->getName()] = $scheme;
} | [
"public",
"function",
"registerScheme",
"(",
"AuthenticationScheme",
"$",
"scheme",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"schemes",
"[",
"$",
"name",
"?",
":",
"$",
"scheme",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"scheme",
";",
"}"
] | Add authentication scheme
@param AuthenticationScheme $scheme Scheme instance
@param string|null $name Custom name. If null, scheme name will be used | [
"Add",
"authentication",
"scheme"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L54-L57 |
116 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.setDefaultScheme | public function setDefaultScheme($scheme = null)
{
if ($scheme === null) {
$this->defaultScheme = null;
} else {
$this->checkScheme($scheme);
$this->defaultScheme = $scheme;
}
} | php | public function setDefaultScheme($scheme = null)
{
if ($scheme === null) {
$this->defaultScheme = null;
} else {
$this->checkScheme($scheme);
$this->defaultScheme = $scheme;
}
} | [
"public",
"function",
"setDefaultScheme",
"(",
"$",
"scheme",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"scheme",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultScheme",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"checkScheme",
"(",
"$",
"scheme",
")",
";",
"$",
"this",
"->",
"defaultScheme",
"=",
"$",
"scheme",
";",
"}",
"}"
] | Set default scheme
@param string|null $scheme Scheme name or null to clear default
@throws \OutOfBoundsException | [
"Set",
"default",
"scheme"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L66-L74 |
117 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.createCredentialsHeader | public function createCredentialsHeader(HttpRequest $request, $scheme, $username, $secretKey)
{
$value = $this->getScheme($scheme)->createRequestHeaderValue($request, $username, $secretKey);
return new HttpHeader($this->credentialsHeader, $scheme . ' ' . $value);
} | php | public function createCredentialsHeader(HttpRequest $request, $scheme, $username, $secretKey)
{
$value = $this->getScheme($scheme)->createRequestHeaderValue($request, $username, $secretKey);
return new HttpHeader($this->credentialsHeader, $scheme . ' ' . $value);
} | [
"public",
"function",
"createCredentialsHeader",
"(",
"HttpRequest",
"$",
"request",
",",
"$",
"scheme",
",",
"$",
"username",
",",
"$",
"secretKey",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getScheme",
"(",
"$",
"scheme",
")",
"->",
"createRequestHeaderValue",
"(",
"$",
"request",
",",
"$",
"username",
",",
"$",
"secretKey",
")",
";",
"return",
"new",
"HttpHeader",
"(",
"$",
"this",
"->",
"credentialsHeader",
",",
"$",
"scheme",
".",
"' '",
".",
"$",
"value",
")",
";",
"}"
] | Create auth credentials header for client request
@param HttpRequest $request Request for sign
@param string $scheme Authorization scheme name
@param string $username Username for API
@param string $secretKey Secret key for API
@return HttpHeader
@throws \OutOfBoundsException If scheme is not registered | [
"Create",
"auth",
"credentials",
"header",
"for",
"client",
"request"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L116-L121 |
118 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.parseRequest | public function parseRequest(HttpRequest $request)
{
foreach ($request->getHeaders() as $name => $value) {
if ($name === $this->credentialsHeader) {
if (!preg_match(self::HEADER_REGEX, $value, $matches)) {
throw new WrongSchemeHeaderException(
$this->credentialsHeader,
sprintf('Value does not match "%s"', self::HEADER_REGEX)
);
}
try {
$token = $this->getScheme($matches[1])->parseHeaderValue($matches[2]);
} catch (WrongHeaderValueException $e) {
throw new WrongSchemeHeaderException($this->credentialsHeader, 'Wrong scheme header value', $matches[1], $e);
}
return new AuthenticationData($matches[1], $token);
}
}
throw new HeaderNotFoundException($this->credentialsHeader);
} | php | public function parseRequest(HttpRequest $request)
{
foreach ($request->getHeaders() as $name => $value) {
if ($name === $this->credentialsHeader) {
if (!preg_match(self::HEADER_REGEX, $value, $matches)) {
throw new WrongSchemeHeaderException(
$this->credentialsHeader,
sprintf('Value does not match "%s"', self::HEADER_REGEX)
);
}
try {
$token = $this->getScheme($matches[1])->parseHeaderValue($matches[2]);
} catch (WrongHeaderValueException $e) {
throw new WrongSchemeHeaderException($this->credentialsHeader, 'Wrong scheme header value', $matches[1], $e);
}
return new AuthenticationData($matches[1], $token);
}
}
throw new HeaderNotFoundException($this->credentialsHeader);
} | [
"public",
"function",
"parseRequest",
"(",
"HttpRequest",
"$",
"request",
")",
"{",
"foreach",
"(",
"$",
"request",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"$",
"this",
"->",
"credentialsHeader",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"self",
"::",
"HEADER_REGEX",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"WrongSchemeHeaderException",
"(",
"$",
"this",
"->",
"credentialsHeader",
",",
"sprintf",
"(",
"'Value does not match \"%s\"'",
",",
"self",
"::",
"HEADER_REGEX",
")",
")",
";",
"}",
"try",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getScheme",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"->",
"parseHeaderValue",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"}",
"catch",
"(",
"WrongHeaderValueException",
"$",
"e",
")",
"{",
"throw",
"new",
"WrongSchemeHeaderException",
"(",
"$",
"this",
"->",
"credentialsHeader",
",",
"'Wrong scheme header value'",
",",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"e",
")",
";",
"}",
"return",
"new",
"AuthenticationData",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"token",
")",
";",
"}",
"}",
"throw",
"new",
"HeaderNotFoundException",
"(",
"$",
"this",
"->",
"credentialsHeader",
")",
";",
"}"
] | Parse request authentication data
@param HttpRequest $request
@return AuthenticationData
@throws \OutOfBoundsException
@throws WrongSchemeHeaderException
@throws HeaderNotFoundException | [
"Parse",
"request",
"authentication",
"data"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L133-L155 |
119 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.isRequestValid | public function isRequestValid(HttpRequest $request, AuthenticationData $data, $secretKey)
{
return $this->getScheme($data->getScheme())->isRequestValid($request, $data->getToken(), $secretKey);
} | php | public function isRequestValid(HttpRequest $request, AuthenticationData $data, $secretKey)
{
return $this->getScheme($data->getScheme())->isRequestValid($request, $data->getToken(), $secretKey);
} | [
"public",
"function",
"isRequestValid",
"(",
"HttpRequest",
"$",
"request",
",",
"AuthenticationData",
"$",
"data",
",",
"$",
"secretKey",
")",
"{",
"return",
"$",
"this",
"->",
"getScheme",
"(",
"$",
"data",
"->",
"getScheme",
"(",
")",
")",
"->",
"isRequestValid",
"(",
"$",
"request",
",",
"$",
"data",
"->",
"getToken",
"(",
")",
",",
"$",
"secretKey",
")",
";",
"}"
] | Check if request is valid for user
@param HttpRequest $request Request for check
@param AuthenticationData $data Data parsed from request
@param string $secretKey User API secret key
@return bool
@throws \OutOfBoundsException
@throws UnsupportedTokenException | [
"Check",
"if",
"request",
"is",
"valid",
"for",
"user"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L168-L171 |
120 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.createSchemeHeader | public function createSchemeHeader($scheme)
{
$schemeObj = $this->getScheme($scheme);
$value = $schemeObj->createResponseHeaderValue();
return new HttpHeader($this->schemeHeader, trim($scheme . ' ' . $value));
} | php | public function createSchemeHeader($scheme)
{
$schemeObj = $this->getScheme($scheme);
$value = $schemeObj->createResponseHeaderValue();
return new HttpHeader($this->schemeHeader, trim($scheme . ' ' . $value));
} | [
"public",
"function",
"createSchemeHeader",
"(",
"$",
"scheme",
")",
"{",
"$",
"schemeObj",
"=",
"$",
"this",
"->",
"getScheme",
"(",
"$",
"scheme",
")",
";",
"$",
"value",
"=",
"$",
"schemeObj",
"->",
"createResponseHeaderValue",
"(",
")",
";",
"return",
"new",
"HttpHeader",
"(",
"$",
"this",
"->",
"schemeHeader",
",",
"trim",
"(",
"$",
"scheme",
".",
"' '",
".",
"$",
"value",
")",
")",
";",
"}"
] | Create header for client notification about scheme
@param string $scheme
@return HttpHeader
@throws \OutOfBoundsException | [
"Create",
"header",
"for",
"client",
"notification",
"about",
"scheme"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L181-L187 |
121 | chEbba/HttpApiAuth | src/Che/HttpApiAuth/SchemeHandler.php | SchemeHandler.createMultiSchemeHeader | public function createMultiSchemeHeader()
{
$headers = [];
foreach ($this->schemes as $name => $scheme) {
$headers[$name] = $scheme->createResponseHeaderValue();
}
return new HttpHeader(
$this->schemeHeader,
sprintf('%s %s', implode('|', array_keys($headers)), implode('|', array_values($headers)))
);
} | php | public function createMultiSchemeHeader()
{
$headers = [];
foreach ($this->schemes as $name => $scheme) {
$headers[$name] = $scheme->createResponseHeaderValue();
}
return new HttpHeader(
$this->schemeHeader,
sprintf('%s %s', implode('|', array_keys($headers)), implode('|', array_values($headers)))
);
} | [
"public",
"function",
"createMultiSchemeHeader",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"schemes",
"as",
"$",
"name",
"=>",
"$",
"scheme",
")",
"{",
"$",
"headers",
"[",
"$",
"name",
"]",
"=",
"$",
"scheme",
"->",
"createResponseHeaderValue",
"(",
")",
";",
"}",
"return",
"new",
"HttpHeader",
"(",
"$",
"this",
"->",
"schemeHeader",
",",
"sprintf",
"(",
"'%s %s'",
",",
"implode",
"(",
"'|'",
",",
"array_keys",
"(",
"$",
"headers",
")",
")",
",",
"implode",
"(",
"'|'",
",",
"array_values",
"(",
"$",
"headers",
")",
")",
")",
")",
";",
"}"
] | Create header for client notification about all supported schemes
@return HttpHeader | [
"Create",
"header",
"for",
"client",
"notification",
"about",
"all",
"supported",
"schemes"
] | 99d017b2149a4956f5e942241e8b6c6efced7ea8 | https://github.com/chEbba/HttpApiAuth/blob/99d017b2149a4956f5e942241e8b6c6efced7ea8/src/Che/HttpApiAuth/SchemeHandler.php#L194-L205 |
122 | vspvt/kohana-annotations | classes/Kohana/Annotations.php | Kohana_Annotations.getMethodAnnotations | static function getMethodAnnotations($method, $class = NULL)
{
$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);
return static::instance()->getMethodAnnotations($method);
} | php | static function getMethodAnnotations($method, $class = NULL)
{
$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);
return static::instance()->getMethodAnnotations($method);
} | [
"static",
"function",
"getMethodAnnotations",
"(",
"$",
"method",
",",
"$",
"class",
"=",
"NULL",
")",
"{",
"$",
"method",
"instanceof",
"ReflectionMethod",
"or",
"$",
"method",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"return",
"static",
"::",
"instance",
"(",
")",
"->",
"getMethodAnnotations",
"(",
"$",
"method",
")",
";",
"}"
] | Get method annotations
@param mixed $method
@param mixed $class
@return array<object> | [
"Get",
"method",
"annotations"
] | 0433114f96a019b99f8936b96347980e3878f782 | https://github.com/vspvt/kohana-annotations/blob/0433114f96a019b99f8936b96347980e3878f782/classes/Kohana/Annotations.php#L84-L89 |
123 | vspvt/kohana-annotations | classes/Kohana/Annotations.php | Kohana_Annotations.getMethodAnnotation | static function getMethodAnnotation($method, $annotationName, $class = NULL)
{
$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);
return static::instance()->getMethodAnnotation($method, $annotationName);
} | php | static function getMethodAnnotation($method, $annotationName, $class = NULL)
{
$method instanceof ReflectionMethod or $method = new ReflectionMethod($class, $method);
return static::instance()->getMethodAnnotation($method, $annotationName);
} | [
"static",
"function",
"getMethodAnnotation",
"(",
"$",
"method",
",",
"$",
"annotationName",
",",
"$",
"class",
"=",
"NULL",
")",
"{",
"$",
"method",
"instanceof",
"ReflectionMethod",
"or",
"$",
"method",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"return",
"static",
"::",
"instance",
"(",
")",
"->",
"getMethodAnnotation",
"(",
"$",
"method",
",",
"$",
"annotationName",
")",
";",
"}"
] | Get method annotation
@param mixed $method
@param string $annotationName
@param mixed $class
@return null|object | [
"Get",
"method",
"annotation"
] | 0433114f96a019b99f8936b96347980e3878f782 | https://github.com/vspvt/kohana-annotations/blob/0433114f96a019b99f8936b96347980e3878f782/classes/Kohana/Annotations.php#L100-L105 |
124 | vspvt/kohana-annotations | classes/Kohana/Annotations.php | Kohana_Annotations.annotationClass | static function annotationClass($name)
{
if (!AnnotationRegistry::loadAnnotationClass($name)) {
throw new \Doctrine\Common\Annotations\AnnotationException('Annotation ' . $name . ' - not exists');
}
return new $name;
} | php | static function annotationClass($name)
{
if (!AnnotationRegistry::loadAnnotationClass($name)) {
throw new \Doctrine\Common\Annotations\AnnotationException('Annotation ' . $name . ' - not exists');
}
return new $name;
} | [
"static",
"function",
"annotationClass",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"AnnotationRegistry",
"::",
"loadAnnotationClass",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Annotations",
"\\",
"AnnotationException",
"(",
"'Annotation '",
".",
"$",
"name",
".",
"' - not exists'",
")",
";",
"}",
"return",
"new",
"$",
"name",
";",
"}"
] | Get annotation object
@param string $name
@return object
@throws Doctrine\Common\Annotations\AnnotationException | [
"Get",
"annotation",
"object"
] | 0433114f96a019b99f8936b96347980e3878f782 | https://github.com/vspvt/kohana-annotations/blob/0433114f96a019b99f8936b96347980e3878f782/classes/Kohana/Annotations.php#L115-L122 |
125 | ironedgesoftware/file-utils | src/File/Yaml.php | Yaml.decode | public function decode(array $options = [])
{
$options = array_merge(
[
'exceptionOnInvalidType' => false,
'objectSupport' => false,
'objectForMap' => false
],
$options
);
return SymfonyYaml::parse(
$this->getContents(),
$options['exceptionOnInvalidType'],
$options['objectSupport'],
$options['objectForMap']
);
} | php | public function decode(array $options = [])
{
$options = array_merge(
[
'exceptionOnInvalidType' => false,
'objectSupport' => false,
'objectForMap' => false
],
$options
);
return SymfonyYaml::parse(
$this->getContents(),
$options['exceptionOnInvalidType'],
$options['objectSupport'],
$options['objectForMap']
);
} | [
"public",
"function",
"decode",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'exceptionOnInvalidType'",
"=>",
"false",
",",
"'objectSupport'",
"=>",
"false",
",",
"'objectForMap'",
"=>",
"false",
"]",
",",
"$",
"options",
")",
";",
"return",
"SymfonyYaml",
"::",
"parse",
"(",
"$",
"this",
"->",
"getContents",
"(",
")",
",",
"$",
"options",
"[",
"'exceptionOnInvalidType'",
"]",
",",
"$",
"options",
"[",
"'objectSupport'",
"]",
",",
"$",
"options",
"[",
"'objectForMap'",
"]",
")",
";",
"}"
] | Decodes Yaml data.
@param array $options - Options.
@throws DecodeException
@return array | [
"Decodes",
"Yaml",
"data",
"."
] | d9f79d6f23db0e5ccb147b4d1fdbccbb70bd5beb | https://github.com/ironedgesoftware/file-utils/blob/d9f79d6f23db0e5ccb147b4d1fdbccbb70bd5beb/src/File/Yaml.php#L54-L71 |
126 | ironedgesoftware/file-utils | src/File/Yaml.php | Yaml.encode | public function encode(array $options = [])
{
$options = array_merge(
[
'inline' => 2,
'indent' => 4,
'exceptionOnInvalidType' => false,
'objectSupport' => false
],
$options
);
return SymfonyYaml::dump(
$this->getContents(),
$options['inline'],
$options['indent'],
$options['exceptionOnInvalidType'],
$options['objectSupport']
);
} | php | public function encode(array $options = [])
{
$options = array_merge(
[
'inline' => 2,
'indent' => 4,
'exceptionOnInvalidType' => false,
'objectSupport' => false
],
$options
);
return SymfonyYaml::dump(
$this->getContents(),
$options['inline'],
$options['indent'],
$options['exceptionOnInvalidType'],
$options['objectSupport']
);
} | [
"public",
"function",
"encode",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'inline'",
"=>",
"2",
",",
"'indent'",
"=>",
"4",
",",
"'exceptionOnInvalidType'",
"=>",
"false",
",",
"'objectSupport'",
"=>",
"false",
"]",
",",
"$",
"options",
")",
";",
"return",
"SymfonyYaml",
"::",
"dump",
"(",
"$",
"this",
"->",
"getContents",
"(",
")",
",",
"$",
"options",
"[",
"'inline'",
"]",
",",
"$",
"options",
"[",
"'indent'",
"]",
",",
"$",
"options",
"[",
"'exceptionOnInvalidType'",
"]",
",",
"$",
"options",
"[",
"'objectSupport'",
"]",
")",
";",
"}"
] | Encodes data in Yaml format.
@param array $options - Options.
@throws EncodeException
@return string | [
"Encodes",
"data",
"in",
"Yaml",
"format",
"."
] | d9f79d6f23db0e5ccb147b4d1fdbccbb70bd5beb | https://github.com/ironedgesoftware/file-utils/blob/d9f79d6f23db0e5ccb147b4d1fdbccbb70bd5beb/src/File/Yaml.php#L82-L101 |
127 | consolle/framework | src/Utils/Filesystem.php | Filesystem.pathInBase | public function pathInBase($filename)
{
$filename = str_replace('\\', '/', $filename);
$path_root = str_replace('\\', '/', base_path() . '/');
return str_replace($path_root, '', $filename);
} | php | public function pathInBase($filename)
{
$filename = str_replace('\\', '/', $filename);
$path_root = str_replace('\\', '/', base_path() . '/');
return str_replace($path_root, '', $filename);
} | [
"public",
"function",
"pathInBase",
"(",
"$",
"filename",
")",
"{",
"$",
"filename",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"filename",
")",
";",
"$",
"path_root",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"base_path",
"(",
")",
".",
"'/'",
")",
";",
"return",
"str_replace",
"(",
"$",
"path_root",
",",
"''",
",",
"$",
"filename",
")",
";",
"}"
] | Remove path base of filename
@param $filename
@return string | [
"Remove",
"path",
"base",
"of",
"filename"
] | 2799921d6983f31e775099eac116c337bbe29c74 | https://github.com/consolle/framework/blob/2799921d6983f31e775099eac116c337bbe29c74/src/Utils/Filesystem.php#L20-L26 |
128 | consolle/framework | src/Utils/Filesystem.php | Filesystem.combine | public function combine($path1, $path2, $div = '/')
{
$path1 .= (($path1[strlen($path1) - 1] != $div) ? $div : '');
return $path1 . $path2;
} | php | public function combine($path1, $path2, $div = '/')
{
$path1 .= (($path1[strlen($path1) - 1] != $div) ? $div : '');
return $path1 . $path2;
} | [
"public",
"function",
"combine",
"(",
"$",
"path1",
",",
"$",
"path2",
",",
"$",
"div",
"=",
"'/'",
")",
"{",
"$",
"path1",
".=",
"(",
"(",
"$",
"path1",
"[",
"strlen",
"(",
"$",
"path1",
")",
"-",
"1",
"]",
"!=",
"$",
"div",
")",
"?",
"$",
"div",
":",
"''",
")",
";",
"return",
"$",
"path1",
".",
"$",
"path2",
";",
"}"
] | Combine two paths
@return string | [
"Combine",
"two",
"paths"
] | 2799921d6983f31e775099eac116c337bbe29c74 | https://github.com/consolle/framework/blob/2799921d6983f31e775099eac116c337bbe29c74/src/Utils/Filesystem.php#L43-L47 |
129 | consolle/framework | src/Utils/Filesystem.php | Filesystem.rename | public function rename($filename, $newname, $try_another_name = false)
{
// Verificar se deve tentar outro nome caso ja exista
if ($try_another_name)
{
$file_mask = preg_replace('/(.[a-zA-Z0-9]+)$/', '_%s\1', $filename);
$contador = 1;
while ($this->exists($newname))
{
$newname = sprintf($file_mask, $contador);
$contador += 1;
}
}
$this->copy($filename, $newname);
$this->delete($filename);
return $newname;
} | php | public function rename($filename, $newname, $try_another_name = false)
{
// Verificar se deve tentar outro nome caso ja exista
if ($try_another_name)
{
$file_mask = preg_replace('/(.[a-zA-Z0-9]+)$/', '_%s\1', $filename);
$contador = 1;
while ($this->exists($newname))
{
$newname = sprintf($file_mask, $contador);
$contador += 1;
}
}
$this->copy($filename, $newname);
$this->delete($filename);
return $newname;
} | [
"public",
"function",
"rename",
"(",
"$",
"filename",
",",
"$",
"newname",
",",
"$",
"try_another_name",
"=",
"false",
")",
"{",
"// Verificar se deve tentar outro nome caso ja exista",
"if",
"(",
"$",
"try_another_name",
")",
"{",
"$",
"file_mask",
"=",
"preg_replace",
"(",
"'/(.[a-zA-Z0-9]+)$/'",
",",
"'_%s\\1'",
",",
"$",
"filename",
")",
";",
"$",
"contador",
"=",
"1",
";",
"while",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"newname",
")",
")",
"{",
"$",
"newname",
"=",
"sprintf",
"(",
"$",
"file_mask",
",",
"$",
"contador",
")",
";",
"$",
"contador",
"+=",
"1",
";",
"}",
"}",
"$",
"this",
"->",
"copy",
"(",
"$",
"filename",
",",
"$",
"newname",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"filename",
")",
";",
"return",
"$",
"newname",
";",
"}"
] | Rename file with option of make new filename
@return string | [
"Rename",
"file",
"with",
"option",
"of",
"make",
"new",
"filename"
] | 2799921d6983f31e775099eac116c337bbe29c74 | https://github.com/consolle/framework/blob/2799921d6983f31e775099eac116c337bbe29c74/src/Utils/Filesystem.php#L62-L80 |
130 | consolle/framework | src/Utils/Filesystem.php | Filesystem.synchronize | public function synchronize($fromPath, $toPath, $renames = array())
{
// Verificar se fromPath e um diertorio
if (!$this->isDirectory($fromPath))
return false;
// Verificar se deve criar o toPath
if (!$this->isDirectory($toPath))
$this->makeDirectory($toPath, 0777, true);
// Copiar sincronizar estrutura
$items = new \FilesystemIterator($fromPath, \FilesystemIterator::SKIP_DOTS);
foreach ($items as $item)
{
$target = $toPath . '/' . $item->getBasename();
if ($item->isDir())
{
$path = $item->getPathname();
if (!$this->synchronize($path, $target, $renames))
return false;
} else {
// verificar se deve renomear
foreach ($renames as $old => $new)
$target = str_replace($old, $new, $target);
// Verificar se arquivo existe
if ($this->exists($target))
{
$hash_file = md5_file($item->getPathname());
$hash_dest = md5_file($target);
if ($hash_file != $hash_dest) {
if (!$this->copy($item->getPathname(), $target))
return false;
}
} else {
if (!$this->copy($item->getPathname(), $target))
return false;
}
}
}
return true;
} | php | public function synchronize($fromPath, $toPath, $renames = array())
{
// Verificar se fromPath e um diertorio
if (!$this->isDirectory($fromPath))
return false;
// Verificar se deve criar o toPath
if (!$this->isDirectory($toPath))
$this->makeDirectory($toPath, 0777, true);
// Copiar sincronizar estrutura
$items = new \FilesystemIterator($fromPath, \FilesystemIterator::SKIP_DOTS);
foreach ($items as $item)
{
$target = $toPath . '/' . $item->getBasename();
if ($item->isDir())
{
$path = $item->getPathname();
if (!$this->synchronize($path, $target, $renames))
return false;
} else {
// verificar se deve renomear
foreach ($renames as $old => $new)
$target = str_replace($old, $new, $target);
// Verificar se arquivo existe
if ($this->exists($target))
{
$hash_file = md5_file($item->getPathname());
$hash_dest = md5_file($target);
if ($hash_file != $hash_dest) {
if (!$this->copy($item->getPathname(), $target))
return false;
}
} else {
if (!$this->copy($item->getPathname(), $target))
return false;
}
}
}
return true;
} | [
"public",
"function",
"synchronize",
"(",
"$",
"fromPath",
",",
"$",
"toPath",
",",
"$",
"renames",
"=",
"array",
"(",
")",
")",
"{",
"// Verificar se fromPath e um diertorio",
"if",
"(",
"!",
"$",
"this",
"->",
"isDirectory",
"(",
"$",
"fromPath",
")",
")",
"return",
"false",
";",
"// Verificar se deve criar o toPath",
"if",
"(",
"!",
"$",
"this",
"->",
"isDirectory",
"(",
"$",
"toPath",
")",
")",
"$",
"this",
"->",
"makeDirectory",
"(",
"$",
"toPath",
",",
"0777",
",",
"true",
")",
";",
"// Copiar sincronizar estrutura",
"$",
"items",
"=",
"new",
"\\",
"FilesystemIterator",
"(",
"$",
"fromPath",
",",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"target",
"=",
"$",
"toPath",
".",
"'/'",
".",
"$",
"item",
"->",
"getBasename",
"(",
")",
";",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"path",
"=",
"$",
"item",
"->",
"getPathname",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"synchronize",
"(",
"$",
"path",
",",
"$",
"target",
",",
"$",
"renames",
")",
")",
"return",
"false",
";",
"}",
"else",
"{",
"// verificar se deve renomear",
"foreach",
"(",
"$",
"renames",
"as",
"$",
"old",
"=>",
"$",
"new",
")",
"$",
"target",
"=",
"str_replace",
"(",
"$",
"old",
",",
"$",
"new",
",",
"$",
"target",
")",
";",
"// Verificar se arquivo existe",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"target",
")",
")",
"{",
"$",
"hash_file",
"=",
"md5_file",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
")",
";",
"$",
"hash_dest",
"=",
"md5_file",
"(",
"$",
"target",
")",
";",
"if",
"(",
"$",
"hash_file",
"!=",
"$",
"hash_dest",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"copy",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
",",
"$",
"target",
")",
")",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"copy",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
",",
"$",
"target",
")",
")",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Synchronize from path with to path
@param $fromPath
@param $toPath
@return boolean | [
"Synchronize",
"from",
"path",
"with",
"to",
"path"
] | 2799921d6983f31e775099eac116c337bbe29c74 | https://github.com/consolle/framework/blob/2799921d6983f31e775099eac116c337bbe29c74/src/Utils/Filesystem.php#L88-L130 |
131 | ripaclub/zf2-hanger-snippet | src/Service/SnippetHelperServiceFactory.php | SnippetHelperServiceFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$snippetHelper = new SnippetHelper();
// Get the top level service locator
$serviceManager = $serviceLocator;
if ($serviceManager instanceof HelperPluginManager) {
$serviceManager = $serviceManager->getServiceLocator();
}
if (!$serviceManager->has('Config')) {
return $snippetHelper;
}
$config = $serviceManager->get('Config');
$snippetsConfig = isset($config[$this->configKey]) ? $config[$this->configKey] : [];
if (!isset($snippetsConfig['snippets'])) {
return $snippetHelper;
}
$snippets = $snippetsConfig['snippets'];
if (!is_array($snippets)) {
return $snippetHelper;
}
return $this->configureSnippetHelper($snippetHelper, $config, $snippetsConfig);
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$snippetHelper = new SnippetHelper();
// Get the top level service locator
$serviceManager = $serviceLocator;
if ($serviceManager instanceof HelperPluginManager) {
$serviceManager = $serviceManager->getServiceLocator();
}
if (!$serviceManager->has('Config')) {
return $snippetHelper;
}
$config = $serviceManager->get('Config');
$snippetsConfig = isset($config[$this->configKey]) ? $config[$this->configKey] : [];
if (!isset($snippetsConfig['snippets'])) {
return $snippetHelper;
}
$snippets = $snippetsConfig['snippets'];
if (!is_array($snippets)) {
return $snippetHelper;
}
return $this->configureSnippetHelper($snippetHelper, $config, $snippetsConfig);
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"snippetHelper",
"=",
"new",
"SnippetHelper",
"(",
")",
";",
"// Get the top level service locator",
"$",
"serviceManager",
"=",
"$",
"serviceLocator",
";",
"if",
"(",
"$",
"serviceManager",
"instanceof",
"HelperPluginManager",
")",
"{",
"$",
"serviceManager",
"=",
"$",
"serviceManager",
"->",
"getServiceLocator",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"serviceManager",
"->",
"has",
"(",
"'Config'",
")",
")",
"{",
"return",
"$",
"snippetHelper",
";",
"}",
"$",
"config",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"'Config'",
")",
";",
"$",
"snippetsConfig",
"=",
"isset",
"(",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
")",
"?",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
":",
"[",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'snippets'",
"]",
")",
")",
"{",
"return",
"$",
"snippetHelper",
";",
"}",
"$",
"snippets",
"=",
"$",
"snippetsConfig",
"[",
"'snippets'",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"snippets",
")",
")",
"{",
"return",
"$",
"snippetHelper",
";",
"}",
"return",
"$",
"this",
"->",
"configureSnippetHelper",
"(",
"$",
"snippetHelper",
",",
"$",
"config",
",",
"$",
"snippetsConfig",
")",
";",
"}"
] | Create an appender helper service
@param ServiceLocatorInterface $serviceLocator
@return SnippetHelper | [
"Create",
"an",
"appender",
"helper",
"service"
] | f055fe49eabea6f963b20e7db8fb81edf3eb3545 | https://github.com/ripaclub/zf2-hanger-snippet/blob/f055fe49eabea6f963b20e7db8fb81edf3eb3545/src/Service/SnippetHelperServiceFactory.php#L28-L60 |
132 | ripaclub/zf2-hanger-snippet | src/Service/SnippetHelperServiceFactory.php | SnippetHelperServiceFactory.configureSnippetHelper | protected function configureSnippetHelper(SnippetHelper $snippetHelper, array $config, array $snippetsConfig)
{
$enableAll = isset($snippetsConfig['enable_all']) ?
(bool)$snippetsConfig['enable_all'] :
true;
foreach ($snippetsConfig['snippets'] as $name => $snippetsConfig) {
$values = [];
// Retrive values from global config if a config key was provided
if (isset($snippetsConfig['config_key']) && isset($config[$snippetsConfig['config_key']])) {
$values = $config[$snippetsConfig['config_key']];
}
// Merge provided values, if any
if (isset($snippetsConfig['values'])) {
$values = array_merge_recursive($values, $snippetsConfig['values']);
}
$snippetHelper->appendSnippet(
$name,
isset($snippetsConfig['template']) ? $snippetsConfig['template'] : 'hanger-snippet/' . $name,
$values,
isset($snippetsConfig['placement']) ? $snippetsConfig['placement'] : null,
isset($snippetsConfig['enabled']) ? $snippetsConfig['enabled'] : $enableAll
);
}
return $snippetHelper;
} | php | protected function configureSnippetHelper(SnippetHelper $snippetHelper, array $config, array $snippetsConfig)
{
$enableAll = isset($snippetsConfig['enable_all']) ?
(bool)$snippetsConfig['enable_all'] :
true;
foreach ($snippetsConfig['snippets'] as $name => $snippetsConfig) {
$values = [];
// Retrive values from global config if a config key was provided
if (isset($snippetsConfig['config_key']) && isset($config[$snippetsConfig['config_key']])) {
$values = $config[$snippetsConfig['config_key']];
}
// Merge provided values, if any
if (isset($snippetsConfig['values'])) {
$values = array_merge_recursive($values, $snippetsConfig['values']);
}
$snippetHelper->appendSnippet(
$name,
isset($snippetsConfig['template']) ? $snippetsConfig['template'] : 'hanger-snippet/' . $name,
$values,
isset($snippetsConfig['placement']) ? $snippetsConfig['placement'] : null,
isset($snippetsConfig['enabled']) ? $snippetsConfig['enabled'] : $enableAll
);
}
return $snippetHelper;
} | [
"protected",
"function",
"configureSnippetHelper",
"(",
"SnippetHelper",
"$",
"snippetHelper",
",",
"array",
"$",
"config",
",",
"array",
"$",
"snippetsConfig",
")",
"{",
"$",
"enableAll",
"=",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'enable_all'",
"]",
")",
"?",
"(",
"bool",
")",
"$",
"snippetsConfig",
"[",
"'enable_all'",
"]",
":",
"true",
";",
"foreach",
"(",
"$",
"snippetsConfig",
"[",
"'snippets'",
"]",
"as",
"$",
"name",
"=>",
"$",
"snippetsConfig",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"// Retrive values from global config if a config key was provided",
"if",
"(",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'config_key'",
"]",
")",
"&&",
"isset",
"(",
"$",
"config",
"[",
"$",
"snippetsConfig",
"[",
"'config_key'",
"]",
"]",
")",
")",
"{",
"$",
"values",
"=",
"$",
"config",
"[",
"$",
"snippetsConfig",
"[",
"'config_key'",
"]",
"]",
";",
"}",
"// Merge provided values, if any",
"if",
"(",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'values'",
"]",
")",
")",
"{",
"$",
"values",
"=",
"array_merge_recursive",
"(",
"$",
"values",
",",
"$",
"snippetsConfig",
"[",
"'values'",
"]",
")",
";",
"}",
"$",
"snippetHelper",
"->",
"appendSnippet",
"(",
"$",
"name",
",",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'template'",
"]",
")",
"?",
"$",
"snippetsConfig",
"[",
"'template'",
"]",
":",
"'hanger-snippet/'",
".",
"$",
"name",
",",
"$",
"values",
",",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'placement'",
"]",
")",
"?",
"$",
"snippetsConfig",
"[",
"'placement'",
"]",
":",
"null",
",",
"isset",
"(",
"$",
"snippetsConfig",
"[",
"'enabled'",
"]",
")",
"?",
"$",
"snippetsConfig",
"[",
"'enabled'",
"]",
":",
"$",
"enableAll",
")",
";",
"}",
"return",
"$",
"snippetHelper",
";",
"}"
] | Configure Snippet Helper
@param SnippetHelper $snippetHelper
@param array $config
@param array $snippetsConfig
@return SnippetHelper | [
"Configure",
"Snippet",
"Helper"
] | f055fe49eabea6f963b20e7db8fb81edf3eb3545 | https://github.com/ripaclub/zf2-hanger-snippet/blob/f055fe49eabea6f963b20e7db8fb81edf3eb3545/src/Service/SnippetHelperServiceFactory.php#L70-L100 |
133 | TechPromux/TechPromuxBaseBundle | Controller/Api/Resource/BaseResourceController.php | BaseResourceController.getProcessedForm | protected function getProcessedForm(Request $request, $action = 'POST', $resource = array(), $options = array())
{
$formType = $this->getResourceFormType($action, $resource, $options);
$formBuilder = $this->createFormBuilder($resource, $options);
$formType->configureFormBuilder($formBuilder, $options);
$form = $formBuilder->getForm();
$form->handleRequest($request);
$formType->validateForm($form);
return $form;
} | php | protected function getProcessedForm(Request $request, $action = 'POST', $resource = array(), $options = array())
{
$formType = $this->getResourceFormType($action, $resource, $options);
$formBuilder = $this->createFormBuilder($resource, $options);
$formType->configureFormBuilder($formBuilder, $options);
$form = $formBuilder->getForm();
$form->handleRequest($request);
$formType->validateForm($form);
return $form;
} | [
"protected",
"function",
"getProcessedForm",
"(",
"Request",
"$",
"request",
",",
"$",
"action",
"=",
"'POST'",
",",
"$",
"resource",
"=",
"array",
"(",
")",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"formType",
"=",
"$",
"this",
"->",
"getResourceFormType",
"(",
"$",
"action",
",",
"$",
"resource",
",",
"$",
"options",
")",
";",
"$",
"formBuilder",
"=",
"$",
"this",
"->",
"createFormBuilder",
"(",
"$",
"resource",
",",
"$",
"options",
")",
";",
"$",
"formType",
"->",
"configureFormBuilder",
"(",
"$",
"formBuilder",
",",
"$",
"options",
")",
";",
"$",
"form",
"=",
"$",
"formBuilder",
"->",
"getForm",
"(",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"$",
"formType",
"->",
"validateForm",
"(",
"$",
"form",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Get a processed and validated form
@param Request $request
@param string $action
@param array $resource
@param array $options
@return \Symfony\Component\Form\Form | [
"Get",
"a",
"processed",
"and",
"validated",
"form"
] | 2569b84cf5c024fd908a13a0f129def19050acd2 | https://github.com/TechPromux/TechPromuxBaseBundle/blob/2569b84cf5c024fd908a13a0f129def19050acd2/Controller/Api/Resource/BaseResourceController.php#L48-L63 |
134 | TechPromux/TechPromuxBaseBundle | Controller/Api/Resource/BaseResourceController.php | BaseResourceController.processPost | protected function processPost(Request $request)
{
$resource = $this->getResourceManager()->createNewInstance();
return $this->processAction($request, 'POST', $resource);
} | php | protected function processPost(Request $request)
{
$resource = $this->getResourceManager()->createNewInstance();
return $this->processAction($request, 'POST', $resource);
} | [
"protected",
"function",
"processPost",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"createNewInstance",
"(",
")",
";",
"return",
"$",
"this",
"->",
"processAction",
"(",
"$",
"request",
",",
"'POST'",
",",
"$",
"resource",
")",
";",
"}"
] | Create a new Resource.
@param Request $request
@return Resource | [
"Create",
"a",
"new",
"Resource",
"."
] | 2569b84cf5c024fd908a13a0f129def19050acd2 | https://github.com/TechPromux/TechPromuxBaseBundle/blob/2569b84cf5c024fd908a13a0f129def19050acd2/Controller/Api/Resource/BaseResourceController.php#L100-L104 |
135 | TechPromux/TechPromuxBaseBundle | Controller/Api/Resource/BaseResourceController.php | BaseResourceController.listAction | public function listAction(Request $request)
{
$this->checkAccess('LIST', null);
$resources = $this->getResourceManager()->findAll();
$view = $this->view($resources, \FOS\RestBundle\Util\Codes::HTTP_OK);
return $this->handleView($view);
} | php | public function listAction(Request $request)
{
$this->checkAccess('LIST', null);
$resources = $this->getResourceManager()->findAll();
$view = $this->view($resources, \FOS\RestBundle\Util\Codes::HTTP_OK);
return $this->handleView($view);
} | [
"public",
"function",
"listAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'LIST'",
",",
"null",
")",
";",
"$",
"resources",
"=",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"findAll",
"(",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"resources",
",",
"\\",
"FOS",
"\\",
"RestBundle",
"\\",
"Util",
"\\",
"Codes",
"::",
"HTTP_OK",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | List all resources.
@param Request $request the request object
@return View | [
"List",
"all",
"resources",
"."
] | 2569b84cf5c024fd908a13a0f129def19050acd2 | https://github.com/TechPromux/TechPromuxBaseBundle/blob/2569b84cf5c024fd908a13a0f129def19050acd2/Controller/Api/Resource/BaseResourceController.php#L149-L155 |
136 | TechPromux/TechPromuxBaseBundle | Controller/Api/Resource/BaseResourceController.php | BaseResourceController.getAction | public function getAction(Request $request, $id)
{
$this->checkAccess('GET', $id);
$resource = $this->getResourceManager()->find($id);
$view = $this->view($resource, \FOS\RestBundle\Util\Codes::HTTP_OK);
return $this->handleView($view);
} | php | public function getAction(Request $request, $id)
{
$this->checkAccess('GET', $id);
$resource = $this->getResourceManager()->find($id);
$view = $this->view($resource, \FOS\RestBundle\Util\Codes::HTTP_OK);
return $this->handleView($view);
} | [
"public",
"function",
"getAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'GET'",
",",
"$",
"id",
")",
";",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"view",
"(",
"$",
"resource",
",",
"\\",
"FOS",
"\\",
"RestBundle",
"\\",
"Util",
"\\",
"Codes",
"::",
"HTTP_OK",
")",
";",
"return",
"$",
"this",
"->",
"handleView",
"(",
"$",
"view",
")",
";",
"}"
] | Gets a resource for a given id.
@param Request $request the request object
@param mixed $id the resource id
@return View
@throws NotFoundHttpException when resource not exist | [
"Gets",
"a",
"resource",
"for",
"a",
"given",
"id",
"."
] | 2569b84cf5c024fd908a13a0f129def19050acd2 | https://github.com/TechPromux/TechPromuxBaseBundle/blob/2569b84cf5c024fd908a13a0f129def19050acd2/Controller/Api/Resource/BaseResourceController.php#L167-L173 |
137 | TechPromux/TechPromuxBaseBundle | Controller/Api/Resource/BaseResourceController.php | BaseResourceController.putAction | public function putAction(Request $request, $id)
{
$this->checkAccess('PUT', $id);
$resource = $this->getResourceManager()->find($id);
return $this->processPut($request, $resource);
} | php | public function putAction(Request $request, $id)
{
$this->checkAccess('PUT', $id);
$resource = $this->getResourceManager()->find($id);
return $this->processPut($request, $resource);
} | [
"public",
"function",
"putAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'PUT'",
",",
"$",
"id",
")",
";",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"processPut",
"(",
"$",
"request",
",",
"$",
"resource",
")",
";",
"}"
] | Update a Resource from the submitted data.
@param Request $request the request object
@param mixed $id the resource id
@return View | [
"Update",
"a",
"Resource",
"from",
"the",
"submitted",
"data",
"."
] | 2569b84cf5c024fd908a13a0f129def19050acd2 | https://github.com/TechPromux/TechPromuxBaseBundle/blob/2569b84cf5c024fd908a13a0f129def19050acd2/Controller/Api/Resource/BaseResourceController.php#L196-L201 |
138 | TechPromux/TechPromuxBaseBundle | Controller/Api/Resource/BaseResourceController.php | BaseResourceController.patchAction | public function patchAction(Request $request, $id)
{
$this->checkAccess('PATCH', $id);
$resource = $this->getResourceManager()->find($id);
return $this->processPatch($request, $resource);
} | php | public function patchAction(Request $request, $id)
{
$this->checkAccess('PATCH', $id);
$resource = $this->getResourceManager()->find($id);
return $this->processPatch($request, $resource);
} | [
"public",
"function",
"patchAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"checkAccess",
"(",
"'PATCH'",
",",
"$",
"id",
")",
";",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResourceManager",
"(",
")",
"->",
"find",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"processPatch",
"(",
"$",
"request",
",",
"$",
"resource",
")",
";",
"}"
] | Update partially a Resource from the submitted data.
@param Request $request the request object
@param mixed $id the resource id
@return View | [
"Update",
"partially",
"a",
"Resource",
"from",
"the",
"submitted",
"data",
"."
] | 2569b84cf5c024fd908a13a0f129def19050acd2 | https://github.com/TechPromux/TechPromuxBaseBundle/blob/2569b84cf5c024fd908a13a0f129def19050acd2/Controller/Api/Resource/BaseResourceController.php#L211-L216 |
139 | mszewcz/php-json-schema-validator | src/Validators/ObjectValidators/PropertiesValidator.php | PropertiesValidator.validate | public function validate($subject): bool
{
if (\is_array($this->schema['properties'])) {
foreach ($this->schema['properties'] as $propertyName => $propertySchema) {
if (isset($subject[$propertyName])) {
$nodeValidator = new NodeValidator($propertySchema, $this->rootSchema);
if (!$nodeValidator->validate($subject[$propertyName])) {
return false;
}
}
}
}
return true;
} | php | public function validate($subject): bool
{
if (\is_array($this->schema['properties'])) {
foreach ($this->schema['properties'] as $propertyName => $propertySchema) {
if (isset($subject[$propertyName])) {
$nodeValidator = new NodeValidator($propertySchema, $this->rootSchema);
if (!$nodeValidator->validate($subject[$propertyName])) {
return false;
}
}
}
}
return true;
} | [
"public",
"function",
"validate",
"(",
"$",
"subject",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"schema",
"[",
"'properties'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"[",
"'properties'",
"]",
"as",
"$",
"propertyName",
"=>",
"$",
"propertySchema",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"subject",
"[",
"$",
"propertyName",
"]",
")",
")",
"{",
"$",
"nodeValidator",
"=",
"new",
"NodeValidator",
"(",
"$",
"propertySchema",
",",
"$",
"this",
"->",
"rootSchema",
")",
";",
"if",
"(",
"!",
"$",
"nodeValidator",
"->",
"validate",
"(",
"$",
"subject",
"[",
"$",
"propertyName",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates subject against properties
@param array $subject
@return bool | [
"Validates",
"subject",
"against",
"properties"
] | f7768bfe07ce6508bb1ff36163560a5e5791de7d | https://github.com/mszewcz/php-json-schema-validator/blob/f7768bfe07ce6508bb1ff36163560a5e5791de7d/src/Validators/ObjectValidators/PropertiesValidator.php#L48-L61 |
140 | jooorooo/embed | src/Request.php | Request.getResolver | public function getResolver()
{
if ($this->resolver === null) {
$this->resolver = new $this->resolverClass(UrlRedirect::resolve($this->buildUrl()), $this->resolverConfig);
$this->parseUrl($this->resolver->getUrl());
}
return $this->resolver;
} | php | public function getResolver()
{
if ($this->resolver === null) {
$this->resolver = new $this->resolverClass(UrlRedirect::resolve($this->buildUrl()), $this->resolverConfig);
$this->parseUrl($this->resolver->getUrl());
}
return $this->resolver;
} | [
"public",
"function",
"getResolver",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resolver",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"resolver",
"=",
"new",
"$",
"this",
"->",
"resolverClass",
"(",
"UrlRedirect",
"::",
"resolve",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
")",
")",
",",
"$",
"this",
"->",
"resolverConfig",
")",
";",
"$",
"this",
"->",
"parseUrl",
"(",
"$",
"this",
"->",
"resolver",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolver",
";",
"}"
] | Returns the current resolver
It also create a new resolver if it's not exists
@return RequestResolvers\RequestResolverInterface | [
"Returns",
"the",
"current",
"resolver",
"It",
"also",
"create",
"a",
"new",
"resolver",
"if",
"it",
"s",
"not",
"exists"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Request.php#L62-L70 |
141 | jooorooo/embed | src/Request.php | Request.getHtmlContent | public function getHtmlContent()
{
if ($this->htmlContent === null) {
try {
if (($content = $this->getContent()) === '') {
return $this->htmlContent = false;
}
$errors = libxml_use_internal_errors(true);
$this->htmlContent = new \DOMDocument();
if ((mb_detect_encoding($content) === 'UTF-8') && mb_check_encoding($content, 'UTF-8')) {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
$content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $content);
}
//Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny)
//$content = preg_replace(['%<!--(?:[^-]++|-)*?-->|<!\[CDATA\[(?:[^\]]++|\])*?\]\]>%si', '%<script\b(?:"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|[^>"\']++)*>(?:[^<]++|<)*?</\s*script\s*>%si'], '', $content);
$this->htmlContent->loadHTML($content);
libxml_use_internal_errors($errors);
} catch (\Exception $E) {
return $this->htmlContent = false;
}
}
return $this->htmlContent;
} | php | public function getHtmlContent()
{
if ($this->htmlContent === null) {
try {
if (($content = $this->getContent()) === '') {
return $this->htmlContent = false;
}
$errors = libxml_use_internal_errors(true);
$this->htmlContent = new \DOMDocument();
if ((mb_detect_encoding($content) === 'UTF-8') && mb_check_encoding($content, 'UTF-8')) {
$content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
$content = preg_replace('/<head[^>]*>/', '<head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">', $content);
}
//Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny)
//$content = preg_replace(['%<!--(?:[^-]++|-)*?-->|<!\[CDATA\[(?:[^\]]++|\])*?\]\]>%si', '%<script\b(?:"(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\'|[^>"\']++)*>(?:[^<]++|<)*?</\s*script\s*>%si'], '', $content);
$this->htmlContent->loadHTML($content);
libxml_use_internal_errors($errors);
} catch (\Exception $E) {
return $this->htmlContent = false;
}
}
return $this->htmlContent;
} | [
"public",
"function",
"getHtmlContent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"htmlContent",
"===",
"null",
")",
"{",
"try",
"{",
"if",
"(",
"(",
"$",
"content",
"=",
"$",
"this",
"->",
"getContent",
"(",
")",
")",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"htmlContent",
"=",
"false",
";",
"}",
"$",
"errors",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"this",
"->",
"htmlContent",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"if",
"(",
"(",
"mb_detect_encoding",
"(",
"$",
"content",
")",
"===",
"'UTF-8'",
")",
"&&",
"mb_check_encoding",
"(",
"$",
"content",
",",
"'UTF-8'",
")",
")",
"{",
"$",
"content",
"=",
"mb_convert_encoding",
"(",
"$",
"content",
",",
"'HTML-ENTITIES'",
",",
"'UTF-8'",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'/<head[^>]*>/'",
",",
"'<head><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\">'",
",",
"$",
"content",
")",
";",
"}",
"//Remove all script elements, CDATA sections and comments (thanks https://github.com/jasny)",
"//$content = preg_replace(['%<!--(?:[^-]++|-)*?-->|<!\\[CDATA\\[(?:[^\\]]++|\\])*?\\]\\]>%si', '%<script\\b(?:\"(?:[^\"\\\\\\\\]++|\\\\\\\\.)*+\"|\\'(?:[^\\'\\\\\\\\]++|\\\\\\\\.)*+\\'|[^>\"\\']++)*>(?:[^<]++|<)*?</\\s*script\\s*>%si'], '', $content);",
"$",
"this",
"->",
"htmlContent",
"->",
"loadHTML",
"(",
"$",
"content",
")",
";",
"libxml_use_internal_errors",
"(",
"$",
"errors",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"E",
")",
"{",
"return",
"$",
"this",
"->",
"htmlContent",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"htmlContent",
";",
"}"
] | Get the content of the url as a DOMDocument object
@return \DOMDocument|false | [
"Get",
"the",
"content",
"of",
"the",
"url",
"as",
"a",
"DOMDocument",
"object"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Request.php#L167-L194 |
142 | jooorooo/embed | src/Request.php | Request.getJsonContent | public function getJsonContent()
{
if ($this->jsonContent === null) {
try {
if (($content = $this->getContent()) === '') {
return $this->jsonContent = false;
}
$this->jsonContent = json_decode($content, true);
} catch (\Exception $E) {
return $this->jsonContent = false;
}
}
return $this->jsonContent;
} | php | public function getJsonContent()
{
if ($this->jsonContent === null) {
try {
if (($content = $this->getContent()) === '') {
return $this->jsonContent = false;
}
$this->jsonContent = json_decode($content, true);
} catch (\Exception $E) {
return $this->jsonContent = false;
}
}
return $this->jsonContent;
} | [
"public",
"function",
"getJsonContent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"jsonContent",
"===",
"null",
")",
"{",
"try",
"{",
"if",
"(",
"(",
"$",
"content",
"=",
"$",
"this",
"->",
"getContent",
"(",
")",
")",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"jsonContent",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"jsonContent",
"=",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"E",
")",
"{",
"return",
"$",
"this",
"->",
"jsonContent",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"jsonContent",
";",
"}"
] | Get the content of the url as an array from json
@return false|array The content or false | [
"Get",
"the",
"content",
"of",
"the",
"url",
"as",
"an",
"array",
"from",
"json"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Request.php#L201-L216 |
143 | jooorooo/embed | src/Request.php | Request.getXMLContent | public function getXMLContent()
{
if ($this->xmlContent === null) {
try {
if (($content = $this->getContent()) === '') {
return $this->xmlContent = false;
}
$errors = libxml_use_internal_errors(true);
$this->xmlContent = new \SimpleXMLElement($content);
libxml_use_internal_errors($errors);
} catch (\Exception $E) {
return $this->xmlContent = false;
}
}
return $this->xmlContent;
} | php | public function getXMLContent()
{
if ($this->xmlContent === null) {
try {
if (($content = $this->getContent()) === '') {
return $this->xmlContent = false;
}
$errors = libxml_use_internal_errors(true);
$this->xmlContent = new \SimpleXMLElement($content);
libxml_use_internal_errors($errors);
} catch (\Exception $E) {
return $this->xmlContent = false;
}
}
return $this->xmlContent;
} | [
"public",
"function",
"getXMLContent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"xmlContent",
"===",
"null",
")",
"{",
"try",
"{",
"if",
"(",
"(",
"$",
"content",
"=",
"$",
"this",
"->",
"getContent",
"(",
")",
")",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"xmlContent",
"=",
"false",
";",
"}",
"$",
"errors",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"this",
"->",
"xmlContent",
"=",
"new",
"\\",
"SimpleXMLElement",
"(",
"$",
"content",
")",
";",
"libxml_use_internal_errors",
"(",
"$",
"errors",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"E",
")",
"{",
"return",
"$",
"this",
"->",
"xmlContent",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"xmlContent",
";",
"}"
] | Get the content of the url as an XML element
@return false|\SimpleXMLElement The content or false | [
"Get",
"the",
"content",
"of",
"the",
"url",
"as",
"an",
"XML",
"element"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Request.php#L223-L239 |
144 | jooorooo/embed | src/Request.php | Request.isValid | public function isValid(array $validCodes = null)
{
if ($validCodes === null) {
return $this->getHttpCode() === 200;
}
return in_array($this->getHttpCode(), $validCodes, true);
} | php | public function isValid(array $validCodes = null)
{
if ($validCodes === null) {
return $this->getHttpCode() === 200;
}
return in_array($this->getHttpCode(), $validCodes, true);
} | [
"public",
"function",
"isValid",
"(",
"array",
"$",
"validCodes",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"validCodes",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getHttpCode",
"(",
")",
"===",
"200",
";",
"}",
"return",
"in_array",
"(",
"$",
"this",
"->",
"getHttpCode",
"(",
")",
",",
"$",
"validCodes",
",",
"true",
")",
";",
"}"
] | Check if the response is valid or not
@param array $validCodes
@return boolean True if it's valid, false if not | [
"Check",
"if",
"the",
"response",
"is",
"valid",
"or",
"not"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Request.php#L248-L255 |
145 | WellCommerce/DataSet | Transformer/DataSetTransformerCollection.php | DataSetTransformerCollection.get | public function get($alias)
{
if (false === $this->has($alias)) {
throw new DataSetTransformerNotFoundException($alias);
}
return $this->items[$alias];
} | php | public function get($alias)
{
if (false === $this->has($alias)) {
throw new DataSetTransformerNotFoundException($alias);
}
return $this->items[$alias];
} | [
"public",
"function",
"get",
"(",
"$",
"alias",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"has",
"(",
"$",
"alias",
")",
")",
"{",
"throw",
"new",
"DataSetTransformerNotFoundException",
"(",
"$",
"alias",
")",
";",
"}",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"alias",
"]",
";",
"}"
] | Returns a dataset's transformer by its alias
@param string $alias
@return DataSetTransformerInterface
@throws DataSetTransformerNotFoundException | [
"Returns",
"a",
"dataset",
"s",
"transformer",
"by",
"its",
"alias"
] | 18720dc5416f245d22c502ceafce1a1b2db2b905 | https://github.com/WellCommerce/DataSet/blob/18720dc5416f245d22c502ceafce1a1b2db2b905/Transformer/DataSetTransformerCollection.php#L42-L49 |
146 | zamronypj/zzzcache | src/Cache.php | Cache.expired | private function expired($cacheId)
{
$item = $this->cachedItems[$cacheId];
return (! $this->storage->exists($cacheId)) ||
$this->timeUtil->expired($item->expiry);
} | php | private function expired($cacheId)
{
$item = $this->cachedItems[$cacheId];
return (! $this->storage->exists($cacheId)) ||
$this->timeUtil->expired($item->expiry);
} | [
"private",
"function",
"expired",
"(",
"$",
"cacheId",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"cachedItems",
"[",
"$",
"cacheId",
"]",
";",
"return",
"(",
"!",
"$",
"this",
"->",
"storage",
"->",
"exists",
"(",
"$",
"cacheId",
")",
")",
"||",
"$",
"this",
"->",
"timeUtil",
"->",
"expired",
"(",
"$",
"item",
"->",
"expiry",
")",
";",
"}"
] | test if cache is expired
@param string $cacheId cache identifier
@return boolean true if expired or false otherwise | [
"test",
"if",
"cache",
"is",
"expired"
] | 8f7a9e6a89de67ff9235d16a8fde69831956a2fd | https://github.com/zamronypj/zzzcache/blob/8f7a9e6a89de67ff9235d16a8fde69831956a2fd/src/Cache.php#L54-L59 |
147 | zamronypj/zzzcache | src/Cache.php | Cache.getFromCacheable | private function getFromCacheable($cacheId)
{
$cacheable = $this->cachedItems[$cacheId]->cacheable;
$data = $cacheable->data();
$ttl = $cacheable->ttl();
$this->storage->write($cacheId, $data, $ttl);
return $data;
} | php | private function getFromCacheable($cacheId)
{
$cacheable = $this->cachedItems[$cacheId]->cacheable;
$data = $cacheable->data();
$ttl = $cacheable->ttl();
$this->storage->write($cacheId, $data, $ttl);
return $data;
} | [
"private",
"function",
"getFromCacheable",
"(",
"$",
"cacheId",
")",
"{",
"$",
"cacheable",
"=",
"$",
"this",
"->",
"cachedItems",
"[",
"$",
"cacheId",
"]",
"->",
"cacheable",
";",
"$",
"data",
"=",
"$",
"cacheable",
"->",
"data",
"(",
")",
";",
"$",
"ttl",
"=",
"$",
"cacheable",
"->",
"ttl",
"(",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"write",
"(",
"$",
"cacheId",
",",
"$",
"data",
",",
"$",
"ttl",
")",
";",
"return",
"$",
"data",
";",
"}"
] | read content from Cacheable instance and write it to cache
storage when cache is missed
@param string $cacheId cache identifier
@return string content | [
"read",
"content",
"from",
"Cacheable",
"instance",
"and",
"write",
"it",
"to",
"cache",
"storage",
"when",
"cache",
"is",
"missed"
] | 8f7a9e6a89de67ff9235d16a8fde69831956a2fd | https://github.com/zamronypj/zzzcache/blob/8f7a9e6a89de67ff9235d16a8fde69831956a2fd/src/Cache.php#L79-L86 |
148 | zamronypj/zzzcache | src/Cache.php | Cache.get | public function get($cacheId)
{
$this->throwExceptionIfNotExists($cacheId);
if ($this->expired($cacheId)) {
return $this->getFromCacheable($cacheId);
}
return $this->getCachedItem($cacheId);
} | php | public function get($cacheId)
{
$this->throwExceptionIfNotExists($cacheId);
if ($this->expired($cacheId)) {
return $this->getFromCacheable($cacheId);
}
return $this->getCachedItem($cacheId);
} | [
"public",
"function",
"get",
"(",
"$",
"cacheId",
")",
"{",
"$",
"this",
"->",
"throwExceptionIfNotExists",
"(",
"$",
"cacheId",
")",
";",
"if",
"(",
"$",
"this",
"->",
"expired",
"(",
"$",
"cacheId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getFromCacheable",
"(",
"$",
"cacheId",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getCachedItem",
"(",
"$",
"cacheId",
")",
";",
"}"
] | retrieve cached item by id
@param string $cacheId cached item identifier
@return string cached item
@throws CacheNameNotFound | [
"retrieve",
"cached",
"item",
"by",
"id"
] | 8f7a9e6a89de67ff9235d16a8fde69831956a2fd | https://github.com/zamronypj/zzzcache/blob/8f7a9e6a89de67ff9235d16a8fde69831956a2fd/src/Cache.php#L107-L116 |
149 | zamronypj/zzzcache | src/Cache.php | Cache.add | public function add($cacheId, Cacheable $cacheable)
{
$this->cachedItems[$cacheId] = (object) [
'cacheable' => $cacheable,
'expiry' => $this->timeUtil->expiry($cacheable->ttl())
];
return $this;
} | php | public function add($cacheId, Cacheable $cacheable)
{
$this->cachedItems[$cacheId] = (object) [
'cacheable' => $cacheable,
'expiry' => $this->timeUtil->expiry($cacheable->ttl())
];
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"cacheId",
",",
"Cacheable",
"$",
"cacheable",
")",
"{",
"$",
"this",
"->",
"cachedItems",
"[",
"$",
"cacheId",
"]",
"=",
"(",
"object",
")",
"[",
"'cacheable'",
"=>",
"$",
"cacheable",
",",
"'expiry'",
"=>",
"$",
"this",
"->",
"timeUtil",
"->",
"expiry",
"(",
"$",
"cacheable",
"->",
"ttl",
"(",
")",
")",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | add cacheable item and associate it with cache identifier
@param string $cacheId cached item identifier
@param Cacheable $cacheable item to cached
@return CacheInterface current instance | [
"add",
"cacheable",
"item",
"and",
"associate",
"it",
"with",
"cache",
"identifier"
] | 8f7a9e6a89de67ff9235d16a8fde69831956a2fd | https://github.com/zamronypj/zzzcache/blob/8f7a9e6a89de67ff9235d16a8fde69831956a2fd/src/Cache.php#L125-L132 |
150 | zamronypj/zzzcache | src/Cache.php | Cache.remove | public function remove($cacheId)
{
$this->throwExceptionIfNotExists($cacheId);
unset($this->cachedItems[$cacheId]);
$this->storage->remove($cacheId);
return $this;
} | php | public function remove($cacheId)
{
$this->throwExceptionIfNotExists($cacheId);
unset($this->cachedItems[$cacheId]);
$this->storage->remove($cacheId);
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"cacheId",
")",
"{",
"$",
"this",
"->",
"throwExceptionIfNotExists",
"(",
"$",
"cacheId",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"cachedItems",
"[",
"$",
"cacheId",
"]",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"remove",
"(",
"$",
"cacheId",
")",
";",
"return",
"$",
"this",
";",
"}"
] | remove cached item by id
@param string $cacheId cached item identifier
@return CacheInterface current instance
@throws CacheNameNotFound | [
"remove",
"cached",
"item",
"by",
"id"
] | 8f7a9e6a89de67ff9235d16a8fde69831956a2fd | https://github.com/zamronypj/zzzcache/blob/8f7a9e6a89de67ff9235d16a8fde69831956a2fd/src/Cache.php#L150-L156 |
151 | Flowpack/Flowpack.SingleSignOn.Client | Classes/Flowpack/SingleSignOn/Client/Service/SingleSignOnManager.php | SingleSignOnManager.logout | public function logout() {
$allConfiguration = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.Flow');
$tokens = $this->securityContext->getAuthenticationTokensOfType('Flowpack\SingleSignOn\Client\Security\SingleSignOnToken');
foreach ($tokens as $token) {
$providerName = $token->getAuthenticationProviderName();
$serverIdentifier = \TYPO3\Flow\Utility\Arrays::getValueByPath($allConfiguration, 'security.authentication.providers.' . $providerName . '.providerOptions.server');
if ($serverIdentifier !== NULL) {
$ssoClient = $this->ssoClientFactory->create();
$ssoServer = $this->ssoServerFactory->create($serverIdentifier);
$ssoServer->destroySession($ssoClient, $token->getGlobalSessionId());
}
}
} | php | public function logout() {
$allConfiguration = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.Flow');
$tokens = $this->securityContext->getAuthenticationTokensOfType('Flowpack\SingleSignOn\Client\Security\SingleSignOnToken');
foreach ($tokens as $token) {
$providerName = $token->getAuthenticationProviderName();
$serverIdentifier = \TYPO3\Flow\Utility\Arrays::getValueByPath($allConfiguration, 'security.authentication.providers.' . $providerName . '.providerOptions.server');
if ($serverIdentifier !== NULL) {
$ssoClient = $this->ssoClientFactory->create();
$ssoServer = $this->ssoServerFactory->create($serverIdentifier);
$ssoServer->destroySession($ssoClient, $token->getGlobalSessionId());
}
}
} | [
"public",
"function",
"logout",
"(",
")",
"{",
"$",
"allConfiguration",
"=",
"$",
"this",
"->",
"configurationManager",
"->",
"getConfiguration",
"(",
"\\",
"TYPO3",
"\\",
"Flow",
"\\",
"Configuration",
"\\",
"ConfigurationManager",
"::",
"CONFIGURATION_TYPE_SETTINGS",
",",
"'TYPO3.Flow'",
")",
";",
"$",
"tokens",
"=",
"$",
"this",
"->",
"securityContext",
"->",
"getAuthenticationTokensOfType",
"(",
"'Flowpack\\SingleSignOn\\Client\\Security\\SingleSignOnToken'",
")",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"token",
")",
"{",
"$",
"providerName",
"=",
"$",
"token",
"->",
"getAuthenticationProviderName",
"(",
")",
";",
"$",
"serverIdentifier",
"=",
"\\",
"TYPO3",
"\\",
"Flow",
"\\",
"Utility",
"\\",
"Arrays",
"::",
"getValueByPath",
"(",
"$",
"allConfiguration",
",",
"'security.authentication.providers.'",
".",
"$",
"providerName",
".",
"'.providerOptions.server'",
")",
";",
"if",
"(",
"$",
"serverIdentifier",
"!==",
"NULL",
")",
"{",
"$",
"ssoClient",
"=",
"$",
"this",
"->",
"ssoClientFactory",
"->",
"create",
"(",
")",
";",
"$",
"ssoServer",
"=",
"$",
"this",
"->",
"ssoServerFactory",
"->",
"create",
"(",
"$",
"serverIdentifier",
")",
";",
"$",
"ssoServer",
"->",
"destroySession",
"(",
"$",
"ssoClient",
",",
"$",
"token",
"->",
"getGlobalSessionId",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Notify SSO servers about the logged out client
All active authentication tokens of type SingleSignOnToken will be
used to get the registered global session id and send a request
to the session service on the SSO server.
@return void | [
"Notify",
"SSO",
"servers",
"about",
"the",
"logged",
"out",
"client"
] | 0512b66bba7cf31fd03c9608a1e4c67a7c1c0e00 | https://github.com/Flowpack/Flowpack.SingleSignOn.Client/blob/0512b66bba7cf31fd03c9608a1e4c67a7c1c0e00/Classes/Flowpack/SingleSignOn/Client/Service/SingleSignOnManager.php#L51-L63 |
152 | antaresproject/tester | src/Adapter/ExtractAdapter.php | ExtractAdapter.generateScripts | public function generateScripts(array $params = null)
{
$cball = <<<CBALL
(function(window,$){
$('body').on('click', '#%s', function () {
$('div.test-results').remove();
var form=$(this).parents('form:first');
$.ajax({
url:"%s",
data:form.serialize(),
type:"POST",
beforeSend:function(){
form.find('input,button,select,textarea').addClass('btn-disabled').attr('disabled','disabled');
},
success:function(response){
$('<div/>').attr('class','test-results').html(response).insertAfter(form);
form.find('input,button,select,textarea').removeClass('btn-disabled').removeAttr('disabled');
},
error:function(response){
form.find('input,button,select,textarea').removeClass('btn-disabled').removeAttr('disabled');
}
});
return false;
});
})(window,jQuery);
CBALL;
$inlineScript = sprintf($cball, $params['id'], handles('antares::tools/tester/run', ['csrf' => true]));
app('antares.asset')
->container(app('config')->get('antares/tester::container'))
->inlineScript($params['id'], $inlineScript);
} | php | public function generateScripts(array $params = null)
{
$cball = <<<CBALL
(function(window,$){
$('body').on('click', '#%s', function () {
$('div.test-results').remove();
var form=$(this).parents('form:first');
$.ajax({
url:"%s",
data:form.serialize(),
type:"POST",
beforeSend:function(){
form.find('input,button,select,textarea').addClass('btn-disabled').attr('disabled','disabled');
},
success:function(response){
$('<div/>').attr('class','test-results').html(response).insertAfter(form);
form.find('input,button,select,textarea').removeClass('btn-disabled').removeAttr('disabled');
},
error:function(response){
form.find('input,button,select,textarea').removeClass('btn-disabled').removeAttr('disabled');
}
});
return false;
});
})(window,jQuery);
CBALL;
$inlineScript = sprintf($cball, $params['id'], handles('antares::tools/tester/run', ['csrf' => true]));
app('antares.asset')
->container(app('config')->get('antares/tester::container'))
->inlineScript($params['id'], $inlineScript);
} | [
"public",
"function",
"generateScripts",
"(",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"cball",
"=",
" <<<CBALL\n(function(window,$){ \n $('body').on('click', '#%s', function () {\n $('div.test-results').remove();\n var form=$(this).parents('form:first'); \n $.ajax({\n url:\"%s\",\n data:form.serialize(),\n type:\"POST\",\n beforeSend:function(){ \n form.find('input,button,select,textarea').addClass('btn-disabled').attr('disabled','disabled');\n },\n success:function(response){\n $('<div/>').attr('class','test-results').html(response).insertAfter(form);\n form.find('input,button,select,textarea').removeClass('btn-disabled').removeAttr('disabled');\n },\n error:function(response){\n form.find('input,button,select,textarea').removeClass('btn-disabled').removeAttr('disabled');\n }\n });\n return false;\n }); \n })(window,jQuery);\n\nCBALL",
";",
"$",
"inlineScript",
"=",
"sprintf",
"(",
"$",
"cball",
",",
"$",
"params",
"[",
"'id'",
"]",
",",
"handles",
"(",
"'antares::tools/tester/run'",
",",
"[",
"'csrf'",
"=>",
"true",
"]",
")",
")",
";",
"app",
"(",
"'antares.asset'",
")",
"->",
"container",
"(",
"app",
"(",
"'config'",
")",
"->",
"get",
"(",
"'antares/tester::container'",
")",
")",
"->",
"inlineScript",
"(",
"$",
"params",
"[",
"'id'",
"]",
",",
"$",
"inlineScript",
")",
";",
"}"
] | generates inline scripts to handle button click event
@param array $params | [
"generates",
"inline",
"scripts",
"to",
"handle",
"button",
"click",
"event"
] | 23e9b4dd7880475769486a8c8f979ab6530c99df | https://github.com/antaresproject/tester/blob/23e9b4dd7880475769486a8c8f979ab6530c99df/src/Adapter/ExtractAdapter.php#L36-L68 |
153 | antaresproject/tester | src/Adapter/ExtractAdapter.php | ExtractAdapter.extractForm | public function extractForm($className = null)
{
$traced = $this->findTraced($className);
$form = $traced['args'][1]['form'];
$controls = [];
foreach ($form->fieldsets as $fieldset) {
foreach ($fieldset->controls as $control) {
$controls[$control->name] = $this->resolveFieldValue($control->name, $form->row, $control);
}
}
$this->extractHiddens($controls, $form->hiddens);
$name = $this->extractModuleName($traced);
$name = str_replace('_', '-', $name);
$name = str_replace('components/', 'antaresproject/component-', $name);
$memory = app('antares.memory')->get("extensions.active.{$name}");
if (is_null($memory)) {
$memory = ['fullname' => 'core'];
}
$component = Component::findOneByName($memory['fullname']);
$attributes = [
'component_id' => $component->id,
'component' => $name,
'controls' => $controls
];
return $attributes;
} | php | public function extractForm($className = null)
{
$traced = $this->findTraced($className);
$form = $traced['args'][1]['form'];
$controls = [];
foreach ($form->fieldsets as $fieldset) {
foreach ($fieldset->controls as $control) {
$controls[$control->name] = $this->resolveFieldValue($control->name, $form->row, $control);
}
}
$this->extractHiddens($controls, $form->hiddens);
$name = $this->extractModuleName($traced);
$name = str_replace('_', '-', $name);
$name = str_replace('components/', 'antaresproject/component-', $name);
$memory = app('antares.memory')->get("extensions.active.{$name}");
if (is_null($memory)) {
$memory = ['fullname' => 'core'];
}
$component = Component::findOneByName($memory['fullname']);
$attributes = [
'component_id' => $component->id,
'component' => $name,
'controls' => $controls
];
return $attributes;
} | [
"public",
"function",
"extractForm",
"(",
"$",
"className",
"=",
"null",
")",
"{",
"$",
"traced",
"=",
"$",
"this",
"->",
"findTraced",
"(",
"$",
"className",
")",
";",
"$",
"form",
"=",
"$",
"traced",
"[",
"'args'",
"]",
"[",
"1",
"]",
"[",
"'form'",
"]",
";",
"$",
"controls",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"form",
"->",
"fieldsets",
"as",
"$",
"fieldset",
")",
"{",
"foreach",
"(",
"$",
"fieldset",
"->",
"controls",
"as",
"$",
"control",
")",
"{",
"$",
"controls",
"[",
"$",
"control",
"->",
"name",
"]",
"=",
"$",
"this",
"->",
"resolveFieldValue",
"(",
"$",
"control",
"->",
"name",
",",
"$",
"form",
"->",
"row",
",",
"$",
"control",
")",
";",
"}",
"}",
"$",
"this",
"->",
"extractHiddens",
"(",
"$",
"controls",
",",
"$",
"form",
"->",
"hiddens",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"extractModuleName",
"(",
"$",
"traced",
")",
";",
"$",
"name",
"=",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"str_replace",
"(",
"'components/'",
",",
"'antaresproject/component-'",
",",
"$",
"name",
")",
";",
"$",
"memory",
"=",
"app",
"(",
"'antares.memory'",
")",
"->",
"get",
"(",
"\"extensions.active.{$name}\"",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"memory",
")",
")",
"{",
"$",
"memory",
"=",
"[",
"'fullname'",
"=>",
"'core'",
"]",
";",
"}",
"$",
"component",
"=",
"Component",
"::",
"findOneByName",
"(",
"$",
"memory",
"[",
"'fullname'",
"]",
")",
";",
"$",
"attributes",
"=",
"[",
"'component_id'",
"=>",
"$",
"component",
"->",
"id",
",",
"'component'",
"=>",
"$",
"name",
",",
"'controls'",
"=>",
"$",
"controls",
"]",
";",
"return",
"$",
"attributes",
";",
"}"
] | extracting form properties
@return array | [
"extracting",
"form",
"properties"
] | 23e9b4dd7880475769486a8c8f979ab6530c99df | https://github.com/antaresproject/tester/blob/23e9b4dd7880475769486a8c8f979ab6530c99df/src/Adapter/ExtractAdapter.php#L75-L105 |
154 | antaresproject/tester | src/Adapter/ExtractAdapter.php | ExtractAdapter.findTraced | private function findTraced($className = null)
{
$traces = debug_backtrace();
$reflection = new ReflectionClass($className);
$filename = $reflection->getFileName();
$traced = null;
foreach ($traces as $trace) {
if (isset($trace['file']) and $filename == $trace['file']) {
$traced = $trace;
break;
}
}
return $traced;
} | php | private function findTraced($className = null)
{
$traces = debug_backtrace();
$reflection = new ReflectionClass($className);
$filename = $reflection->getFileName();
$traced = null;
foreach ($traces as $trace) {
if (isset($trace['file']) and $filename == $trace['file']) {
$traced = $trace;
break;
}
}
return $traced;
} | [
"private",
"function",
"findTraced",
"(",
"$",
"className",
"=",
"null",
")",
"{",
"$",
"traces",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"filename",
"=",
"$",
"reflection",
"->",
"getFileName",
"(",
")",
";",
"$",
"traced",
"=",
"null",
";",
"foreach",
"(",
"$",
"traces",
"as",
"$",
"trace",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"trace",
"[",
"'file'",
"]",
")",
"and",
"$",
"filename",
"==",
"$",
"trace",
"[",
"'file'",
"]",
")",
"{",
"$",
"traced",
"=",
"$",
"trace",
";",
"break",
";",
"}",
"}",
"return",
"$",
"traced",
";",
"}"
] | find traced form
@param String $className
@return mixed | [
"find",
"traced",
"form"
] | 23e9b4dd7880475769486a8c8f979ab6530c99df | https://github.com/antaresproject/tester/blob/23e9b4dd7880475769486a8c8f979ab6530c99df/src/Adapter/ExtractAdapter.php#L113-L128 |
155 | antaresproject/tester | src/Adapter/ExtractAdapter.php | ExtractAdapter.extractHiddens | private function extractHiddens(&$controls, array $hiddens = null)
{
if (!empty($hiddens)) {
$dom = new \DOMDocument('1.0');
$nodes = [];
foreach ($hiddens as $hidden) {
$dom->loadHTML($hidden);
$nodes = $dom->getElementsByTagName('input');
}
foreach ($nodes as $node) {
$controls[$node->getAttribute('name')] = $node->getAttribute('value');
}
}
} | php | private function extractHiddens(&$controls, array $hiddens = null)
{
if (!empty($hiddens)) {
$dom = new \DOMDocument('1.0');
$nodes = [];
foreach ($hiddens as $hidden) {
$dom->loadHTML($hidden);
$nodes = $dom->getElementsByTagName('input');
}
foreach ($nodes as $node) {
$controls[$node->getAttribute('name')] = $node->getAttribute('value');
}
}
} | [
"private",
"function",
"extractHiddens",
"(",
"&",
"$",
"controls",
",",
"array",
"$",
"hiddens",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"hiddens",
")",
")",
"{",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
")",
";",
"$",
"nodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"hiddens",
"as",
"$",
"hidden",
")",
"{",
"$",
"dom",
"->",
"loadHTML",
"(",
"$",
"hidden",
")",
";",
"$",
"nodes",
"=",
"$",
"dom",
"->",
"getElementsByTagName",
"(",
"'input'",
")",
";",
"}",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"controls",
"[",
"$",
"node",
"->",
"getAttribute",
"(",
"'name'",
")",
"]",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"'value'",
")",
";",
"}",
"}",
"}"
] | extract hidden elements from form
@param array $controls
@param array $hiddens | [
"extract",
"hidden",
"elements",
"from",
"form"
] | 23e9b4dd7880475769486a8c8f979ab6530c99df | https://github.com/antaresproject/tester/blob/23e9b4dd7880475769486a8c8f979ab6530c99df/src/Adapter/ExtractAdapter.php#L136-L149 |
156 | antaresproject/tester | src/Adapter/ExtractAdapter.php | ExtractAdapter.extractModuleName | protected function extractModuleName(array $traced)
{
$executor = str_replace(realpath(app_path() . '/../src'), '', $traced['file']);
$extractedPath = explode(DIRECTORY_SEPARATOR, $executor);
$names = [];
foreach ($extractedPath as $index => $directory) {
if ($directory == 'src') {
break;
}
if ($directory !== '' && $directory !== 'modules') {
$names[] = $directory;
}
}
return implode('/', $names);
} | php | protected function extractModuleName(array $traced)
{
$executor = str_replace(realpath(app_path() . '/../src'), '', $traced['file']);
$extractedPath = explode(DIRECTORY_SEPARATOR, $executor);
$names = [];
foreach ($extractedPath as $index => $directory) {
if ($directory == 'src') {
break;
}
if ($directory !== '' && $directory !== 'modules') {
$names[] = $directory;
}
}
return implode('/', $names);
} | [
"protected",
"function",
"extractModuleName",
"(",
"array",
"$",
"traced",
")",
"{",
"$",
"executor",
"=",
"str_replace",
"(",
"realpath",
"(",
"app_path",
"(",
")",
".",
"'/../src'",
")",
",",
"''",
",",
"$",
"traced",
"[",
"'file'",
"]",
")",
";",
"$",
"extractedPath",
"=",
"explode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"executor",
")",
";",
"$",
"names",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"extractedPath",
"as",
"$",
"index",
"=>",
"$",
"directory",
")",
"{",
"if",
"(",
"$",
"directory",
"==",
"'src'",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"directory",
"!==",
"''",
"&&",
"$",
"directory",
"!==",
"'modules'",
")",
"{",
"$",
"names",
"[",
"]",
"=",
"$",
"directory",
";",
"}",
"}",
"return",
"implode",
"(",
"'/'",
",",
"$",
"names",
")",
";",
"}"
] | extracting module path from debug_backtrace
@param array $traced
@return String | [
"extracting",
"module",
"path",
"from",
"debug_backtrace"
] | 23e9b4dd7880475769486a8c8f979ab6530c99df | https://github.com/antaresproject/tester/blob/23e9b4dd7880475769486a8c8f979ab6530c99df/src/Adapter/ExtractAdapter.php#L157-L173 |
157 | antaresproject/tester | src/Adapter/ExtractAdapter.php | ExtractAdapter.resolveFieldValue | protected function resolveFieldValue($name, $row, Fluent $control)
{
$value = null;
$model = data_get($row, $name);
if (!is_null($model)) {
$value = $model;
}
if (is_null($control->get('value'))) {
return $value;
}
$value = $control->get('value');
if ($value instanceof Closure) {
$value = $value($row, $control);
}
return $value;
} | php | protected function resolveFieldValue($name, $row, Fluent $control)
{
$value = null;
$model = data_get($row, $name);
if (!is_null($model)) {
$value = $model;
}
if (is_null($control->get('value'))) {
return $value;
}
$value = $control->get('value');
if ($value instanceof Closure) {
$value = $value($row, $control);
}
return $value;
} | [
"protected",
"function",
"resolveFieldValue",
"(",
"$",
"name",
",",
"$",
"row",
",",
"Fluent",
"$",
"control",
")",
"{",
"$",
"value",
"=",
"null",
";",
"$",
"model",
"=",
"data_get",
"(",
"$",
"row",
",",
"$",
"name",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"model",
")",
")",
"{",
"$",
"value",
"=",
"$",
"model",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"control",
"->",
"get",
"(",
"'value'",
")",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"value",
"=",
"$",
"control",
"->",
"get",
"(",
"'value'",
")",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Closure",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"(",
"$",
"row",
",",
"$",
"control",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | resolve field value
@param String $name
@param String $row
@param Fluent $control
@return String | mixed | [
"resolve",
"field",
"value"
] | 23e9b4dd7880475769486a8c8f979ab6530c99df | https://github.com/antaresproject/tester/blob/23e9b4dd7880475769486a8c8f979ab6530c99df/src/Adapter/ExtractAdapter.php#L183-L201 |
158 | brainbits/blocking | src/Validator/ExpiredValidator.php | ExpiredValidator.intervalToSeconds | private function intervalToSeconds(DateInterval $interval): int
{
$seconds = (int) $interval->format('%s');
$multiplier = 60;
$seconds += (int) $interval->format('%i') * $multiplier;
$multiplier *= 60;
$seconds += (int) $interval->format('%h') * $multiplier;
$multiplier *= 24;
$seconds += (int) $interval->format('%d') * $multiplier;
$multiplier *= 30;
$seconds += (int) $interval->format('%m') * $multiplier;
$multiplier *= 12;
$seconds += (int) $interval->format('%y') * $multiplier;
return $seconds;
} | php | private function intervalToSeconds(DateInterval $interval): int
{
$seconds = (int) $interval->format('%s');
$multiplier = 60;
$seconds += (int) $interval->format('%i') * $multiplier;
$multiplier *= 60;
$seconds += (int) $interval->format('%h') * $multiplier;
$multiplier *= 24;
$seconds += (int) $interval->format('%d') * $multiplier;
$multiplier *= 30;
$seconds += (int) $interval->format('%m') * $multiplier;
$multiplier *= 12;
$seconds += (int) $interval->format('%y') * $multiplier;
return $seconds;
} | [
"private",
"function",
"intervalToSeconds",
"(",
"DateInterval",
"$",
"interval",
")",
":",
"int",
"{",
"$",
"seconds",
"=",
"(",
"int",
")",
"$",
"interval",
"->",
"format",
"(",
"'%s'",
")",
";",
"$",
"multiplier",
"=",
"60",
";",
"$",
"seconds",
"+=",
"(",
"int",
")",
"$",
"interval",
"->",
"format",
"(",
"'%i'",
")",
"*",
"$",
"multiplier",
";",
"$",
"multiplier",
"*=",
"60",
";",
"$",
"seconds",
"+=",
"(",
"int",
")",
"$",
"interval",
"->",
"format",
"(",
"'%h'",
")",
"*",
"$",
"multiplier",
";",
"$",
"multiplier",
"*=",
"24",
";",
"$",
"seconds",
"+=",
"(",
"int",
")",
"$",
"interval",
"->",
"format",
"(",
"'%d'",
")",
"*",
"$",
"multiplier",
";",
"$",
"multiplier",
"*=",
"30",
";",
"$",
"seconds",
"+=",
"(",
"int",
")",
"$",
"interval",
"->",
"format",
"(",
"'%m'",
")",
"*",
"$",
"multiplier",
";",
"$",
"multiplier",
"*=",
"12",
";",
"$",
"seconds",
"+=",
"(",
"int",
")",
"$",
"interval",
"->",
"format",
"(",
"'%y'",
")",
"*",
"$",
"multiplier",
";",
"return",
"$",
"seconds",
";",
"}"
] | Calculate seconds from interval
@param DateInterval $interval
@return int | [
"Calculate",
"seconds",
"from",
"interval"
] | bf749fbdd3fcf9503940a278bb20475f92435bf9 | https://github.com/brainbits/blocking/blob/bf749fbdd3fcf9503940a278bb20475f92435bf9/src/Validator/ExpiredValidator.php#L51-L71 |
159 | emaphp/eMapper | lib/eMapper/Fluent/Query/FluentUpdate.php | FluentUpdate.setValue | public function setValue($value) {
if ($value instanceof \ArrayObject)
$this->value = $value->getArrayCopy();
elseif (is_object($value))
$this->value = get_object_vars($value);
elseif (is_array($value))
$this->value = $value;
else
throw new \InvalidArgumentException("Method 'setValue' expected an object or array value");
return $this;
} | php | public function setValue($value) {
if ($value instanceof \ArrayObject)
$this->value = $value->getArrayCopy();
elseif (is_object($value))
$this->value = get_object_vars($value);
elseif (is_array($value))
$this->value = $value;
else
throw new \InvalidArgumentException("Method 'setValue' expected an object or array value");
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"ArrayObject",
")",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
"->",
"getArrayCopy",
"(",
")",
";",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"$",
"this",
"->",
"value",
"=",
"get_object_vars",
"(",
"$",
"value",
")",
";",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"else",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Method 'setValue' expected an object or array value\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the value to update as an array|object
@param array|object $value
@throws \InvalidArgumentException
@return \eMapper\SQL\Fluent\FluentUpdate | [
"Sets",
"the",
"value",
"to",
"update",
"as",
"an",
"array|object"
] | df7100e601d2a1363d07028a786b6ceb22271829 | https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentUpdate.php#L47-L58 |
160 | emaphp/eMapper | lib/eMapper/Fluent/Query/FluentUpdate.php | FluentUpdate.setExpr | public function setExpr($expression) {
$this->valueList = func_get_args();
$this->expression = array_shift($this->valueList);
return $this;
} | php | public function setExpr($expression) {
$this->valueList = func_get_args();
$this->expression = array_shift($this->valueList);
return $this;
} | [
"public",
"function",
"setExpr",
"(",
"$",
"expression",
")",
"{",
"$",
"this",
"->",
"valueList",
"=",
"func_get_args",
"(",
")",
";",
"$",
"this",
"->",
"expression",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"valueList",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the value list expression
@param string $expression
@return \eMapper\SQL\Fluent\FluentUpdate | [
"Sets",
"the",
"value",
"list",
"expression"
] | df7100e601d2a1363d07028a786b6ceb22271829 | https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentUpdate.php#L65-L69 |
161 | emaphp/eMapper | lib/eMapper/Fluent/Query/FluentUpdate.php | FluentUpdate.buildSetClause | protected function buildSetClause() {
if (isset($this->expression))
return $this->expression;
$set = [];
foreach (array_keys($this->value) as $k )
$set[] = $k . '=#{' . $k . '}';
return implode(',', $set);
} | php | protected function buildSetClause() {
if (isset($this->expression))
return $this->expression;
$set = [];
foreach (array_keys($this->value) as $k )
$set[] = $k . '=#{' . $k . '}';
return implode(',', $set);
} | [
"protected",
"function",
"buildSetClause",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"expression",
")",
")",
"return",
"$",
"this",
"->",
"expression",
";",
"$",
"set",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"value",
")",
"as",
"$",
"k",
")",
"$",
"set",
"[",
"]",
"=",
"$",
"k",
".",
"'=#{'",
".",
"$",
"k",
".",
"'}'",
";",
"return",
"implode",
"(",
"','",
",",
"$",
"set",
")",
";",
"}"
] | Returns the set expression as a string
@return string | [
"Returns",
"the",
"set",
"expression",
"as",
"a",
"string"
] | df7100e601d2a1363d07028a786b6ceb22271829 | https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Fluent/Query/FluentUpdate.php#L75-L85 |
162 | mimmi20/ua-data-mapper | src/DeviceBrandnameMapper.php | DeviceBrandnameMapper.mapDeviceName | public function mapDeviceName(?string $deviceName): ?string
{
if (null === $deviceName) {
return null;
}
$brandName = null;
switch (mb_strtolower($deviceName)) {
case '':
case 'unknown':
case 'other':
case 'various':
case 'android 1.6':
case 'android 2.0':
case 'android 2.1':
case 'android 2.2':
case 'android 2.3':
case 'android 3.0':
case 'android 3.1':
case 'android 3.2':
case 'android 4.0':
case 'android 4.1':
case 'android 4.2':
case 'android 4.3':
case 'android 4.4':
case 'android 5.0':
case 'android 2.2 tablet':
case 'android 4 tablet':
case 'android 4.1 tablet':
case 'android 4.2 tablet':
case 'android 4.3 tablet':
case 'android 4.4 tablet':
case 'android 5.0 tablet':
case 'disguised as macintosh':
case 'mini 1':
case 'mini 4':
case 'mini 5':
case 'windows mobile 6.5':
case 'windows mobile 7':
case 'windows mobile 7.5':
case 'windows phone 7':
case 'windows phone 8':
case 'fennec tablet':
case 'tablet on android':
case 'fennec':
case 'opera for series 60':
case 'opera mini for s60':
case 'windows mobile (opera)':
case 'nokia unrecognized ovi browser':
$brandName = null;
break;
// Medion
case 'p9514':
case 'lifetab p9514':
case 'lifetab s9512':
$brandName = 'Medion';
break;
// HTC
case 'htc desire sv':
$brandName = 'HTC';
break;
// Apple
case 'ipad':
case 'iphone':
$brandName = 'Apple';
break;
default:
// nothing to do here
break;
}
return $brandName;
} | php | public function mapDeviceName(?string $deviceName): ?string
{
if (null === $deviceName) {
return null;
}
$brandName = null;
switch (mb_strtolower($deviceName)) {
case '':
case 'unknown':
case 'other':
case 'various':
case 'android 1.6':
case 'android 2.0':
case 'android 2.1':
case 'android 2.2':
case 'android 2.3':
case 'android 3.0':
case 'android 3.1':
case 'android 3.2':
case 'android 4.0':
case 'android 4.1':
case 'android 4.2':
case 'android 4.3':
case 'android 4.4':
case 'android 5.0':
case 'android 2.2 tablet':
case 'android 4 tablet':
case 'android 4.1 tablet':
case 'android 4.2 tablet':
case 'android 4.3 tablet':
case 'android 4.4 tablet':
case 'android 5.0 tablet':
case 'disguised as macintosh':
case 'mini 1':
case 'mini 4':
case 'mini 5':
case 'windows mobile 6.5':
case 'windows mobile 7':
case 'windows mobile 7.5':
case 'windows phone 7':
case 'windows phone 8':
case 'fennec tablet':
case 'tablet on android':
case 'fennec':
case 'opera for series 60':
case 'opera mini for s60':
case 'windows mobile (opera)':
case 'nokia unrecognized ovi browser':
$brandName = null;
break;
// Medion
case 'p9514':
case 'lifetab p9514':
case 'lifetab s9512':
$brandName = 'Medion';
break;
// HTC
case 'htc desire sv':
$brandName = 'HTC';
break;
// Apple
case 'ipad':
case 'iphone':
$brandName = 'Apple';
break;
default:
// nothing to do here
break;
}
return $brandName;
} | [
"public",
"function",
"mapDeviceName",
"(",
"?",
"string",
"$",
"deviceName",
")",
":",
"?",
"string",
"{",
"if",
"(",
"null",
"===",
"$",
"deviceName",
")",
"{",
"return",
"null",
";",
"}",
"$",
"brandName",
"=",
"null",
";",
"switch",
"(",
"mb_strtolower",
"(",
"$",
"deviceName",
")",
")",
"{",
"case",
"''",
":",
"case",
"'unknown'",
":",
"case",
"'other'",
":",
"case",
"'various'",
":",
"case",
"'android 1.6'",
":",
"case",
"'android 2.0'",
":",
"case",
"'android 2.1'",
":",
"case",
"'android 2.2'",
":",
"case",
"'android 2.3'",
":",
"case",
"'android 3.0'",
":",
"case",
"'android 3.1'",
":",
"case",
"'android 3.2'",
":",
"case",
"'android 4.0'",
":",
"case",
"'android 4.1'",
":",
"case",
"'android 4.2'",
":",
"case",
"'android 4.3'",
":",
"case",
"'android 4.4'",
":",
"case",
"'android 5.0'",
":",
"case",
"'android 2.2 tablet'",
":",
"case",
"'android 4 tablet'",
":",
"case",
"'android 4.1 tablet'",
":",
"case",
"'android 4.2 tablet'",
":",
"case",
"'android 4.3 tablet'",
":",
"case",
"'android 4.4 tablet'",
":",
"case",
"'android 5.0 tablet'",
":",
"case",
"'disguised as macintosh'",
":",
"case",
"'mini 1'",
":",
"case",
"'mini 4'",
":",
"case",
"'mini 5'",
":",
"case",
"'windows mobile 6.5'",
":",
"case",
"'windows mobile 7'",
":",
"case",
"'windows mobile 7.5'",
":",
"case",
"'windows phone 7'",
":",
"case",
"'windows phone 8'",
":",
"case",
"'fennec tablet'",
":",
"case",
"'tablet on android'",
":",
"case",
"'fennec'",
":",
"case",
"'opera for series 60'",
":",
"case",
"'opera mini for s60'",
":",
"case",
"'windows mobile (opera)'",
":",
"case",
"'nokia unrecognized ovi browser'",
":",
"$",
"brandName",
"=",
"null",
";",
"break",
";",
"// Medion",
"case",
"'p9514'",
":",
"case",
"'lifetab p9514'",
":",
"case",
"'lifetab s9512'",
":",
"$",
"brandName",
"=",
"'Medion'",
";",
"break",
";",
"// HTC",
"case",
"'htc desire sv'",
":",
"$",
"brandName",
"=",
"'HTC'",
";",
"break",
";",
"// Apple",
"case",
"'ipad'",
":",
"case",
"'iphone'",
":",
"$",
"brandName",
"=",
"'Apple'",
";",
"break",
";",
"default",
":",
"// nothing to do here",
"break",
";",
"}",
"return",
"$",
"brandName",
";",
"}"
] | maps the brand name of a device from the device name
@param string|null $deviceName
@return string|null | [
"maps",
"the",
"brand",
"name",
"of",
"a",
"device",
"from",
"the",
"device",
"name"
] | fdb249045066a4e793fb481c6304c736605996eb | https://github.com/mimmi20/ua-data-mapper/blob/fdb249045066a4e793fb481c6304c736605996eb/src/DeviceBrandnameMapper.php#L126-L199 |
163 | opendi/lang | src/StringUtils.php | StringUtils.mostSimilar | public static function mostSimilar($needle, $wordPool)
{
$distancePool = [];
$needle = mb_strtolower($needle);
foreach ($wordPool as $word) {
$distance = similar_text($needle, mb_strtolower($word));
if (!isset($distancePool[$distance])) {
$distancePool[$distance] = [];
}
$distancePool[$distance][] = $word;
}
$min = max(array_keys($distancePool));
// if distance is the same, we just pick the first we can get
return $distancePool[$min][0];
} | php | public static function mostSimilar($needle, $wordPool)
{
$distancePool = [];
$needle = mb_strtolower($needle);
foreach ($wordPool as $word) {
$distance = similar_text($needle, mb_strtolower($word));
if (!isset($distancePool[$distance])) {
$distancePool[$distance] = [];
}
$distancePool[$distance][] = $word;
}
$min = max(array_keys($distancePool));
// if distance is the same, we just pick the first we can get
return $distancePool[$min][0];
} | [
"public",
"static",
"function",
"mostSimilar",
"(",
"$",
"needle",
",",
"$",
"wordPool",
")",
"{",
"$",
"distancePool",
"=",
"[",
"]",
";",
"$",
"needle",
"=",
"mb_strtolower",
"(",
"$",
"needle",
")",
";",
"foreach",
"(",
"$",
"wordPool",
"as",
"$",
"word",
")",
"{",
"$",
"distance",
"=",
"similar_text",
"(",
"$",
"needle",
",",
"mb_strtolower",
"(",
"$",
"word",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"distancePool",
"[",
"$",
"distance",
"]",
")",
")",
"{",
"$",
"distancePool",
"[",
"$",
"distance",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"distancePool",
"[",
"$",
"distance",
"]",
"[",
"]",
"=",
"$",
"word",
";",
"}",
"$",
"min",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"distancePool",
")",
")",
";",
"// if distance is the same, we just pick the first we can get",
"return",
"$",
"distancePool",
"[",
"$",
"min",
"]",
"[",
"0",
"]",
";",
"}"
] | Finds a string in a pool of strings which is most similar to the given
needle.
@param string $needle
@param array $wordPool | [
"Finds",
"a",
"string",
"in",
"a",
"pool",
"of",
"strings",
"which",
"is",
"most",
"similar",
"to",
"the",
"given",
"needle",
"."
] | cbf813c484cd21ec11c35c0c11ec314a583e58ff | https://github.com/opendi/lang/blob/cbf813c484cd21ec11c35c0c11ec314a583e58ff/src/StringUtils.php#L28-L48 |
164 | opendi/lang | src/StringUtils.php | StringUtils.translit | public static function translit($string, $substChar = '?', $trim = true, $removeDuplicates = true)
{
// Cast scalars to strings, if non-scalar is given throw an exception
if (!is_string($string)) {
if (is_scalar($string)) {
$string = (string) $string;
} else {
$type = gettype($string);
throw new \InvalidArgumentException(__METHOD__ . "() expects parameter 1 to be string, $type given");
}
}
// Replace language-specific characters
$string = strtr($string, CharacterMap::get());
// Replace any leftover non-ASCII characters by the replacement char.
$string = preg_replace("/[^\\w]/", $substChar, $string);
if ($trim) {
$string = trim($string, $substChar);
}
if ($removeDuplicates) {
$string = preg_replace("/\\{$substChar}+/", $substChar, $string);
}
return $string;
} | php | public static function translit($string, $substChar = '?', $trim = true, $removeDuplicates = true)
{
// Cast scalars to strings, if non-scalar is given throw an exception
if (!is_string($string)) {
if (is_scalar($string)) {
$string = (string) $string;
} else {
$type = gettype($string);
throw new \InvalidArgumentException(__METHOD__ . "() expects parameter 1 to be string, $type given");
}
}
// Replace language-specific characters
$string = strtr($string, CharacterMap::get());
// Replace any leftover non-ASCII characters by the replacement char.
$string = preg_replace("/[^\\w]/", $substChar, $string);
if ($trim) {
$string = trim($string, $substChar);
}
if ($removeDuplicates) {
$string = preg_replace("/\\{$substChar}+/", $substChar, $string);
}
return $string;
} | [
"public",
"static",
"function",
"translit",
"(",
"$",
"string",
",",
"$",
"substChar",
"=",
"'?'",
",",
"$",
"trim",
"=",
"true",
",",
"$",
"removeDuplicates",
"=",
"true",
")",
"{",
"// Cast scalars to strings, if non-scalar is given throw an exception",
"if",
"(",
"!",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"string",
")",
")",
"{",
"$",
"string",
"=",
"(",
"string",
")",
"$",
"string",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"string",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\"() expects parameter 1 to be string, $type given\"",
")",
";",
"}",
"}",
"// Replace language-specific characters",
"$",
"string",
"=",
"strtr",
"(",
"$",
"string",
",",
"CharacterMap",
"::",
"get",
"(",
")",
")",
";",
"// Replace any leftover non-ASCII characters by the replacement char.",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/[^\\\\w]/\"",
",",
"$",
"substChar",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"trim",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"$",
"substChar",
")",
";",
"}",
"if",
"(",
"$",
"removeDuplicates",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/\\\\{$substChar}+/\"",
",",
"$",
"substChar",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Transliterates an UTF8 string to printable ASCII characters.
@param string $string The string to transliterate.
@param string $substChar The character to use for characters which
cannot be transliterated.
@param boolean $trim Whether to trim any subst characters from
beginning and end of string.
@param boolean $removeDuplicates Whether to remove duplicate subst chars
with only one.
@return string The transliterated string. | [
"Transliterates",
"an",
"UTF8",
"string",
"to",
"printable",
"ASCII",
"characters",
"."
] | cbf813c484cd21ec11c35c0c11ec314a583e58ff | https://github.com/opendi/lang/blob/cbf813c484cd21ec11c35c0c11ec314a583e58ff/src/StringUtils.php#L133-L160 |
165 | opendi/lang | src/StringUtils.php | StringUtils.slugify | public static function slugify($string)
{
if (!is_string($string)) {
$type = gettype($string);
throw new \InvalidArgumentException("Given argument is a $type, expected string.");
}
if (empty($string)) {
throw new \InvalidArgumentException("Cannot slugify an empty string.");
}
// Replace some language-specific characters which are not handled by
// iconv transliteration satisfactorily.
$string = strtr($string, CharacterMap::get());
// Replace non-alphanumeric characters by "-"
$string = preg_replace('/[^\\p{L}\\d]+/u', '-', $string);
// Trim
$string = trim($string, '-');
// Transliterate
$string = iconv('utf-8', 'ASCII//TRANSLIT', $string);
// Lowercase
$string = strtolower($string);
// Remove unwanted characters
$string = preg_replace('/[^-\w]+/', '', $string);
return $string;
} | php | public static function slugify($string)
{
if (!is_string($string)) {
$type = gettype($string);
throw new \InvalidArgumentException("Given argument is a $type, expected string.");
}
if (empty($string)) {
throw new \InvalidArgumentException("Cannot slugify an empty string.");
}
// Replace some language-specific characters which are not handled by
// iconv transliteration satisfactorily.
$string = strtr($string, CharacterMap::get());
// Replace non-alphanumeric characters by "-"
$string = preg_replace('/[^\\p{L}\\d]+/u', '-', $string);
// Trim
$string = trim($string, '-');
// Transliterate
$string = iconv('utf-8', 'ASCII//TRANSLIT', $string);
// Lowercase
$string = strtolower($string);
// Remove unwanted characters
$string = preg_replace('/[^-\w]+/', '', $string);
return $string;
} | [
"public",
"static",
"function",
"slugify",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"string",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Given argument is a $type, expected string.\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot slugify an empty string.\"",
")",
";",
"}",
"// Replace some language-specific characters which are not handled by",
"// iconv transliteration satisfactorily.",
"$",
"string",
"=",
"strtr",
"(",
"$",
"string",
",",
"CharacterMap",
"::",
"get",
"(",
")",
")",
";",
"// Replace non-alphanumeric characters by \"-\"",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[^\\\\p{L}\\\\d]+/u'",
",",
"'-'",
",",
"$",
"string",
")",
";",
"// Trim",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"'-'",
")",
";",
"// Transliterate",
"$",
"string",
"=",
"iconv",
"(",
"'utf-8'",
",",
"'ASCII//TRANSLIT'",
",",
"$",
"string",
")",
";",
"// Lowercase",
"$",
"string",
"=",
"strtolower",
"(",
"$",
"string",
")",
";",
"// Remove unwanted characters",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[^-\\w]+/'",
",",
"''",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Returns a slugified version of the string.
Converts the given string into a string consisting only of lowecase
ASCII characters and dashes (-). Used for constructing URLs.
@param string $string String to convert.
@return string Slugified string.
@throws InvalidArgumentException If given argument is not a string or is
empty. | [
"Returns",
"a",
"slugified",
"version",
"of",
"the",
"string",
"."
] | cbf813c484cd21ec11c35c0c11ec314a583e58ff | https://github.com/opendi/lang/blob/cbf813c484cd21ec11c35c0c11ec314a583e58ff/src/StringUtils.php#L175-L206 |
166 | rozaverta/cmf | core/Http/Request.php | Request.readJson | public function readJson($check_header = true, $override = false)
{
if( !is_null($this->from_json) && !$override )
{
return $this->from_json;
}
// set false json reader
$this->from_json = false;
if( $check_header )
{
$type = $this->server->getIs("CONTENT_TYPE") ? $this->server->get("CONTENT_TYPE") : $this->server->getOr("HTTP_ACCEPT", '');
if( ! preg_match('/(?:application|text)\/json(?:$|;| )/', $type) )
{
return false;
}
}
$body = $this->body();
if( strlen($body) && ( $body[0] === "{" || $body[0] === "[" ) )
{
$this->params_post = new Collection( Json::parse($body, true) );
$this->body = '';
$this->from_json = true;
}
return $this->from_json;
} | php | public function readJson($check_header = true, $override = false)
{
if( !is_null($this->from_json) && !$override )
{
return $this->from_json;
}
// set false json reader
$this->from_json = false;
if( $check_header )
{
$type = $this->server->getIs("CONTENT_TYPE") ? $this->server->get("CONTENT_TYPE") : $this->server->getOr("HTTP_ACCEPT", '');
if( ! preg_match('/(?:application|text)\/json(?:$|;| )/', $type) )
{
return false;
}
}
$body = $this->body();
if( strlen($body) && ( $body[0] === "{" || $body[0] === "[" ) )
{
$this->params_post = new Collection( Json::parse($body, true) );
$this->body = '';
$this->from_json = true;
}
return $this->from_json;
} | [
"public",
"function",
"readJson",
"(",
"$",
"check_header",
"=",
"true",
",",
"$",
"override",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"from_json",
")",
"&&",
"!",
"$",
"override",
")",
"{",
"return",
"$",
"this",
"->",
"from_json",
";",
"}",
"// set false json reader",
"$",
"this",
"->",
"from_json",
"=",
"false",
";",
"if",
"(",
"$",
"check_header",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"server",
"->",
"getIs",
"(",
"\"CONTENT_TYPE\"",
")",
"?",
"$",
"this",
"->",
"server",
"->",
"get",
"(",
"\"CONTENT_TYPE\"",
")",
":",
"$",
"this",
"->",
"server",
"->",
"getOr",
"(",
"\"HTTP_ACCEPT\"",
",",
"''",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/(?:application|text)\\/json(?:$|;| )/'",
",",
"$",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"$",
"body",
"=",
"$",
"this",
"->",
"body",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"body",
")",
"&&",
"(",
"$",
"body",
"[",
"0",
"]",
"===",
"\"{\"",
"||",
"$",
"body",
"[",
"0",
"]",
"===",
"\"[\"",
")",
")",
"{",
"$",
"this",
"->",
"params_post",
"=",
"new",
"Collection",
"(",
"Json",
"::",
"parse",
"(",
"$",
"body",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"body",
"=",
"''",
";",
"$",
"this",
"->",
"from_json",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"from_json",
";",
"}"
] | Load json content from body data
@param bool $check_header
@param bool $override
@return bool | [
"Load",
"json",
"content",
"from",
"body",
"data"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Http/Request.php#L345-L373 |
167 | rozaverta/cmf | core/Http/Request.php | Request.ip | public function ip()
{
if( is_null($this->ip_address) )
{
$remote = isset( $this->server["REMOTE_ADDR"] );
if( $remote && isset( $this->server["HTTP_CLIENT_IP"] ) )
{
$this->ip_address = $this->server["HTTP_CLIENT_IP"];
}
else if( $remote )
{
$this->ip_address = $_SERVER["REMOTE_ADDR"];
}
else if ( isset( $this->server["HTTP_CLIENT_IP"] ) )
{
$this->ip_address = $this->server["HTTP_CLIENT_IP"];
}
else if( isset( $this->server["HTTP_X_FORWARDED_FOR"] ) )
{
$this->ip_address = $this->server["HTTP_X_FORWARDED_FOR"];
}
else
{
$this->ip_address = "0.0.0.0";
}
if( strpos( $this->ip_address, ',' ) !== false )
{
$this->ip_address = end( explode( ',', $this->ip_address ) );
}
if( ! $this->ip_address )
{
$this->ip_address = "0.0.0.0";
}
}
return $this->ip_address;
} | php | public function ip()
{
if( is_null($this->ip_address) )
{
$remote = isset( $this->server["REMOTE_ADDR"] );
if( $remote && isset( $this->server["HTTP_CLIENT_IP"] ) )
{
$this->ip_address = $this->server["HTTP_CLIENT_IP"];
}
else if( $remote )
{
$this->ip_address = $_SERVER["REMOTE_ADDR"];
}
else if ( isset( $this->server["HTTP_CLIENT_IP"] ) )
{
$this->ip_address = $this->server["HTTP_CLIENT_IP"];
}
else if( isset( $this->server["HTTP_X_FORWARDED_FOR"] ) )
{
$this->ip_address = $this->server["HTTP_X_FORWARDED_FOR"];
}
else
{
$this->ip_address = "0.0.0.0";
}
if( strpos( $this->ip_address, ',' ) !== false )
{
$this->ip_address = end( explode( ',', $this->ip_address ) );
}
if( ! $this->ip_address )
{
$this->ip_address = "0.0.0.0";
}
}
return $this->ip_address;
} | [
"public",
"function",
"ip",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"ip_address",
")",
")",
"{",
"$",
"remote",
"=",
"isset",
"(",
"$",
"this",
"->",
"server",
"[",
"\"REMOTE_ADDR\"",
"]",
")",
";",
"if",
"(",
"$",
"remote",
"&&",
"isset",
"(",
"$",
"this",
"->",
"server",
"[",
"\"HTTP_CLIENT_IP\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"$",
"this",
"->",
"server",
"[",
"\"HTTP_CLIENT_IP\"",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"remote",
")",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"$",
"_SERVER",
"[",
"\"REMOTE_ADDR\"",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"server",
"[",
"\"HTTP_CLIENT_IP\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"$",
"this",
"->",
"server",
"[",
"\"HTTP_CLIENT_IP\"",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"server",
"[",
"\"HTTP_X_FORWARDED_FOR\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"$",
"this",
"->",
"server",
"[",
"\"HTTP_X_FORWARDED_FOR\"",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"\"0.0.0.0\"",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"ip_address",
",",
"','",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"end",
"(",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"ip_address",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"ip_address",
")",
"{",
"$",
"this",
"->",
"ip_address",
"=",
"\"0.0.0.0\"",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"ip_address",
";",
"}"
] | Gets the request IP address
@return string | [
"Gets",
"the",
"request",
"IP",
"address"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Http/Request.php#L390-L429 |
168 | rozaverta/cmf | core/Http/Request.php | Request.referer | public function referer( $valid_host = false, $valid_string = '' )
{
$ref = $this->server->getOr('HTTP_REFERER', '');
if( $ref ) {
if($valid_host) {
$host = BASE_PROTOCOL . "://" . APP_HOST;
$len = strlen($host);
if( substr($ref, 0, $len) !== $host ) {
return '';
}
if( strlen($ref) > $len ) {
$end = $ref[$len];
if( $end !== "/" && $end !== ":" ) {
return '';
}
}
}
if($valid_string && strpos($ref, $valid_string) === false) {
return '';
}
}
return $ref;
} | php | public function referer( $valid_host = false, $valid_string = '' )
{
$ref = $this->server->getOr('HTTP_REFERER', '');
if( $ref ) {
if($valid_host) {
$host = BASE_PROTOCOL . "://" . APP_HOST;
$len = strlen($host);
if( substr($ref, 0, $len) !== $host ) {
return '';
}
if( strlen($ref) > $len ) {
$end = $ref[$len];
if( $end !== "/" && $end !== ":" ) {
return '';
}
}
}
if($valid_string && strpos($ref, $valid_string) === false) {
return '';
}
}
return $ref;
} | [
"public",
"function",
"referer",
"(",
"$",
"valid_host",
"=",
"false",
",",
"$",
"valid_string",
"=",
"''",
")",
"{",
"$",
"ref",
"=",
"$",
"this",
"->",
"server",
"->",
"getOr",
"(",
"'HTTP_REFERER'",
",",
"''",
")",
";",
"if",
"(",
"$",
"ref",
")",
"{",
"if",
"(",
"$",
"valid_host",
")",
"{",
"$",
"host",
"=",
"BASE_PROTOCOL",
".",
"\"://\"",
".",
"APP_HOST",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"host",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"ref",
",",
"0",
",",
"$",
"len",
")",
"!==",
"$",
"host",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"ref",
")",
">",
"$",
"len",
")",
"{",
"$",
"end",
"=",
"$",
"ref",
"[",
"$",
"len",
"]",
";",
"if",
"(",
"$",
"end",
"!==",
"\"/\"",
"&&",
"$",
"end",
"!==",
"\":\"",
")",
"{",
"return",
"''",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"valid_string",
"&&",
"strpos",
"(",
"$",
"ref",
",",
"$",
"valid_string",
")",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"}",
"return",
"$",
"ref",
";",
"}"
] | Gets the request referer
@param bool $valid_host
@param string $valid_string
@return string | [
"Gets",
"the",
"request",
"referer"
] | 95ed38362e397d1c700ee255f7200234ef98d356 | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Http/Request.php#L458-L485 |
169 | benkle-libs/feed-parser | src/Traits/WithRelationsTrait.php | WithRelationsTrait.getRelation | public function getRelation($type)
{
if (!isset($this->relations[$type])) {
throw new RelationNotFoundException($type);
}
return $this->relations[$type];
} | php | public function getRelation($type)
{
if (!isset($this->relations[$type])) {
throw new RelationNotFoundException($type);
}
return $this->relations[$type];
} | [
"public",
"function",
"getRelation",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"RelationNotFoundException",
"(",
"$",
"type",
")",
";",
"}",
"return",
"$",
"this",
"->",
"relations",
"[",
"$",
"type",
"]",
";",
"}"
] | Get a relation link.
@param string $type
@return RelationLinkInterface
@throws RelationNotFoundException | [
"Get",
"a",
"relation",
"link",
"."
] | 8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f | https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Traits/WithRelationsTrait.php#L40-L46 |
170 | tapestry-cloud/database-plugin | src/Hydrators/File.php | File.hydrate | public function hydrate(Model $model, \Tapestry\Entities\File $file, \TapestryCloud\Database\Entities\ContentType $contentType = null)
{
$model->setUid($file->getUid());
$model->setLastModified($file->getLastModified());
$model->setFilename($file->getFilename());
$model->setExt($file->getExt());
$model->setPath($file->getPath());
$model->setToCopy($file->isToCopy());
$model->setDate($file->getData('date')->getTimestamp());
$model->setIsDraft($file->getData('draft', false));
if (!$file->isToCopy()) {
$frontMatter = new TapestryFrontMatter($file->getFileContent());
$model->setContent($frontMatter->getContent());
$inFile = [];
foreach (array_keys($frontMatter->getData()) as $inFileKey) {
$inFile[$inFileKey] = 1;
}
$inDatabase = [];
foreach ($model->getFrontMatterKeys() as $inDatabaseKey) {
if (isset($inFile[$inDatabaseKey])) {
$inDatabase[$inDatabaseKey] = 1;
} else {
$inDatabase[$inDatabaseKey] = -1; //@todo remove frontmatter from db when missing from file
}
}
foreach ($frontMatter->getData() as $key => $value) {
$fmRecord = new FrontMatter();
$fmRecord->setName($key);
if (isset($inDatabase[$key])){
$fmRecord = $model->getFrontMatterByKey($key, $fmRecord);
}
$fmRecord->setValue(json_encode($value));
$model->addFrontMatter($fmRecord);
$this->entityManager->persist($fmRecord);
}
}
if (!is_null($contentType)) {
$model->setContentType($contentType);
}
} | php | public function hydrate(Model $model, \Tapestry\Entities\File $file, \TapestryCloud\Database\Entities\ContentType $contentType = null)
{
$model->setUid($file->getUid());
$model->setLastModified($file->getLastModified());
$model->setFilename($file->getFilename());
$model->setExt($file->getExt());
$model->setPath($file->getPath());
$model->setToCopy($file->isToCopy());
$model->setDate($file->getData('date')->getTimestamp());
$model->setIsDraft($file->getData('draft', false));
if (!$file->isToCopy()) {
$frontMatter = new TapestryFrontMatter($file->getFileContent());
$model->setContent($frontMatter->getContent());
$inFile = [];
foreach (array_keys($frontMatter->getData()) as $inFileKey) {
$inFile[$inFileKey] = 1;
}
$inDatabase = [];
foreach ($model->getFrontMatterKeys() as $inDatabaseKey) {
if (isset($inFile[$inDatabaseKey])) {
$inDatabase[$inDatabaseKey] = 1;
} else {
$inDatabase[$inDatabaseKey] = -1; //@todo remove frontmatter from db when missing from file
}
}
foreach ($frontMatter->getData() as $key => $value) {
$fmRecord = new FrontMatter();
$fmRecord->setName($key);
if (isset($inDatabase[$key])){
$fmRecord = $model->getFrontMatterByKey($key, $fmRecord);
}
$fmRecord->setValue(json_encode($value));
$model->addFrontMatter($fmRecord);
$this->entityManager->persist($fmRecord);
}
}
if (!is_null($contentType)) {
$model->setContentType($contentType);
}
} | [
"public",
"function",
"hydrate",
"(",
"Model",
"$",
"model",
",",
"\\",
"Tapestry",
"\\",
"Entities",
"\\",
"File",
"$",
"file",
",",
"\\",
"TapestryCloud",
"\\",
"Database",
"\\",
"Entities",
"\\",
"ContentType",
"$",
"contentType",
"=",
"null",
")",
"{",
"$",
"model",
"->",
"setUid",
"(",
"$",
"file",
"->",
"getUid",
"(",
")",
")",
";",
"$",
"model",
"->",
"setLastModified",
"(",
"$",
"file",
"->",
"getLastModified",
"(",
")",
")",
";",
"$",
"model",
"->",
"setFilename",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
";",
"$",
"model",
"->",
"setExt",
"(",
"$",
"file",
"->",
"getExt",
"(",
")",
")",
";",
"$",
"model",
"->",
"setPath",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"model",
"->",
"setToCopy",
"(",
"$",
"file",
"->",
"isToCopy",
"(",
")",
")",
";",
"$",
"model",
"->",
"setDate",
"(",
"$",
"file",
"->",
"getData",
"(",
"'date'",
")",
"->",
"getTimestamp",
"(",
")",
")",
";",
"$",
"model",
"->",
"setIsDraft",
"(",
"$",
"file",
"->",
"getData",
"(",
"'draft'",
",",
"false",
")",
")",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"isToCopy",
"(",
")",
")",
"{",
"$",
"frontMatter",
"=",
"new",
"TapestryFrontMatter",
"(",
"$",
"file",
"->",
"getFileContent",
"(",
")",
")",
";",
"$",
"model",
"->",
"setContent",
"(",
"$",
"frontMatter",
"->",
"getContent",
"(",
")",
")",
";",
"$",
"inFile",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"frontMatter",
"->",
"getData",
"(",
")",
")",
"as",
"$",
"inFileKey",
")",
"{",
"$",
"inFile",
"[",
"$",
"inFileKey",
"]",
"=",
"1",
";",
"}",
"$",
"inDatabase",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"model",
"->",
"getFrontMatterKeys",
"(",
")",
"as",
"$",
"inDatabaseKey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"inFile",
"[",
"$",
"inDatabaseKey",
"]",
")",
")",
"{",
"$",
"inDatabase",
"[",
"$",
"inDatabaseKey",
"]",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"inDatabase",
"[",
"$",
"inDatabaseKey",
"]",
"=",
"-",
"1",
";",
"//@todo remove frontmatter from db when missing from file",
"}",
"}",
"foreach",
"(",
"$",
"frontMatter",
"->",
"getData",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fmRecord",
"=",
"new",
"FrontMatter",
"(",
")",
";",
"$",
"fmRecord",
"->",
"setName",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"inDatabase",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"fmRecord",
"=",
"$",
"model",
"->",
"getFrontMatterByKey",
"(",
"$",
"key",
",",
"$",
"fmRecord",
")",
";",
"}",
"$",
"fmRecord",
"->",
"setValue",
"(",
"json_encode",
"(",
"$",
"value",
")",
")",
";",
"$",
"model",
"->",
"addFrontMatter",
"(",
"$",
"fmRecord",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"fmRecord",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"contentType",
")",
")",
"{",
"$",
"model",
"->",
"setContentType",
"(",
"$",
"contentType",
")",
";",
"}",
"}"
] | File Hydration.
@param Model $model
@param \Tapestry\Entities\File $file
@param \TapestryCloud\Database\Entities\ContentType $contentType | [
"File",
"Hydration",
"."
] | b9d0e42c84e1691b8b4b269f81a85723d5e9ac8c | https://github.com/tapestry-cloud/database-plugin/blob/b9d0e42c84e1691b8b4b269f81a85723d5e9ac8c/src/Hydrators/File.php#L19-L66 |
171 | setrun/setrun-component-sys | src/commands/MigrateController.php | MigrateController.copyMigrations | protected function copyMigrations() : void
{
$this->stdout("\nCopy the migration files in a temp directory\n", Console::FG_YELLOW);
FileHelper::removeDirectory($this->migrationPath);
FileHelper::createDirectory($this->migrationPath);
if (!is_dir($this->migrationPath)) {
$this->stdout("Could not create a temporary directory migration\n", Console::FG_RED);
exit();
}
$this->stdout("\tCreated a directory migration\n", Console::FG_GREEN);
if ($dirs = $this->findMigrationDirs()) {
foreach ($dirs as $dir) {
FileHelper::copyDirectory($dir, $this->migrationPath);
}
}
$this->stdout("\tThe copied files components migrations\n", Console::FG_GREEN);
$appMigrateDir = \Yii::getAlias("@app/commands");
if (is_dir($appMigrateDir)) {
FileHelper::copyDirectory($appMigrateDir, $this->migrationPath);
}
$this->stdout("\tThe copied files app migrations\n\n", Console::FG_GREEN);
} | php | protected function copyMigrations() : void
{
$this->stdout("\nCopy the migration files in a temp directory\n", Console::FG_YELLOW);
FileHelper::removeDirectory($this->migrationPath);
FileHelper::createDirectory($this->migrationPath);
if (!is_dir($this->migrationPath)) {
$this->stdout("Could not create a temporary directory migration\n", Console::FG_RED);
exit();
}
$this->stdout("\tCreated a directory migration\n", Console::FG_GREEN);
if ($dirs = $this->findMigrationDirs()) {
foreach ($dirs as $dir) {
FileHelper::copyDirectory($dir, $this->migrationPath);
}
}
$this->stdout("\tThe copied files components migrations\n", Console::FG_GREEN);
$appMigrateDir = \Yii::getAlias("@app/commands");
if (is_dir($appMigrateDir)) {
FileHelper::copyDirectory($appMigrateDir, $this->migrationPath);
}
$this->stdout("\tThe copied files app migrations\n\n", Console::FG_GREEN);
} | [
"protected",
"function",
"copyMigrations",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"stdout",
"(",
"\"\\nCopy the migration files in a temp directory\\n\"",
",",
"Console",
"::",
"FG_YELLOW",
")",
";",
"FileHelper",
"::",
"removeDirectory",
"(",
"$",
"this",
"->",
"migrationPath",
")",
";",
"FileHelper",
"::",
"createDirectory",
"(",
"$",
"this",
"->",
"migrationPath",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"migrationPath",
")",
")",
"{",
"$",
"this",
"->",
"stdout",
"(",
"\"Could not create a temporary directory migration\\n\"",
",",
"Console",
"::",
"FG_RED",
")",
";",
"exit",
"(",
")",
";",
"}",
"$",
"this",
"->",
"stdout",
"(",
"\"\\tCreated a directory migration\\n\"",
",",
"Console",
"::",
"FG_GREEN",
")",
";",
"if",
"(",
"$",
"dirs",
"=",
"$",
"this",
"->",
"findMigrationDirs",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"FileHelper",
"::",
"copyDirectory",
"(",
"$",
"dir",
",",
"$",
"this",
"->",
"migrationPath",
")",
";",
"}",
"}",
"$",
"this",
"->",
"stdout",
"(",
"\"\\tThe copied files components migrations\\n\"",
",",
"Console",
"::",
"FG_GREEN",
")",
";",
"$",
"appMigrateDir",
"=",
"\\",
"Yii",
"::",
"getAlias",
"(",
"\"@app/commands\"",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"appMigrateDir",
")",
")",
"{",
"FileHelper",
"::",
"copyDirectory",
"(",
"$",
"appMigrateDir",
",",
"$",
"this",
"->",
"migrationPath",
")",
";",
"}",
"$",
"this",
"->",
"stdout",
"(",
"\"\\tThe copied files app migrations\\n\\n\"",
",",
"Console",
"::",
"FG_GREEN",
")",
";",
"}"
] | Copy migrations to temp directory.
@return void | [
"Copy",
"migrations",
"to",
"temp",
"directory",
"."
] | ad9a6442a2921e0f061ed4e455b050c56029d565 | https://github.com/setrun/setrun-component-sys/blob/ad9a6442a2921e0f061ed4e455b050c56029d565/src/commands/MigrateController.php#L61-L82 |
172 | setrun/setrun-component-sys | src/commands/MigrateController.php | MigrateController.clearNamespace | protected function clearNamespace(string $class)
{
if (file_exists($class)) {
$content = file_get_contents($class);
$content = preg_replace('#^namespace\s+(.+?);$#sm', ' ', $content);
file_put_contents($class, $content);
}
} | php | protected function clearNamespace(string $class)
{
if (file_exists($class)) {
$content = file_get_contents($class);
$content = preg_replace('#^namespace\s+(.+?);$#sm', ' ', $content);
file_put_contents($class, $content);
}
} | [
"protected",
"function",
"clearNamespace",
"(",
"string",
"$",
"class",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"class",
")",
";",
"$",
"content",
"=",
"preg_replace",
"(",
"'#^namespace\\s+(.+?);$#sm'",
",",
"' '",
",",
"$",
"content",
")",
";",
"file_put_contents",
"(",
"$",
"class",
",",
"$",
"content",
")",
";",
"}",
"}"
] | Clear namespace to php class file.
@param string $class | [
"Clear",
"namespace",
"to",
"php",
"class",
"file",
"."
] | ad9a6442a2921e0f061ed4e455b050c56029d565 | https://github.com/setrun/setrun-component-sys/blob/ad9a6442a2921e0f061ed4e455b050c56029d565/src/commands/MigrateController.php#L97-L104 |
173 | wearenolte/wp-widgets | src/Collection/LeanMenu.php | LeanMenu.update | public function update( $new_instance, $old_instance ) {
$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
$selected_menu = isset( $_REQUEST[ $this->get_menu_field_id() ] ) ?
sanitize_text_field( wp_unslash( $_REQUEST[ $this->get_menu_field_id() ] ) ) : false;
foreach ( $menus as $menu ) {
if ( $selected_menu === $menu->slug ) {
$new_instance['menu'] = $selected_menu;
break;
}
}
return $new_instance;
} | php | public function update( $new_instance, $old_instance ) {
$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
$selected_menu = isset( $_REQUEST[ $this->get_menu_field_id() ] ) ?
sanitize_text_field( wp_unslash( $_REQUEST[ $this->get_menu_field_id() ] ) ) : false;
foreach ( $menus as $menu ) {
if ( $selected_menu === $menu->slug ) {
$new_instance['menu'] = $selected_menu;
break;
}
}
return $new_instance;
} | [
"public",
"function",
"update",
"(",
"$",
"new_instance",
",",
"$",
"old_instance",
")",
"{",
"$",
"menus",
"=",
"get_terms",
"(",
"'nav_menu'",
",",
"array",
"(",
"'hide_empty'",
"=>",
"true",
")",
")",
";",
"$",
"selected_menu",
"=",
"isset",
"(",
"$",
"_REQUEST",
"[",
"$",
"this",
"->",
"get_menu_field_id",
"(",
")",
"]",
")",
"?",
"sanitize_text_field",
"(",
"wp_unslash",
"(",
"$",
"_REQUEST",
"[",
"$",
"this",
"->",
"get_menu_field_id",
"(",
")",
"]",
")",
")",
":",
"false",
";",
"foreach",
"(",
"$",
"menus",
"as",
"$",
"menu",
")",
"{",
"if",
"(",
"$",
"selected_menu",
"===",
"$",
"menu",
"->",
"slug",
")",
"{",
"$",
"new_instance",
"[",
"'menu'",
"]",
"=",
"$",
"selected_menu",
";",
"break",
";",
"}",
"}",
"return",
"$",
"new_instance",
";",
"}"
] | Save the menu slug
@param array $new_instance
@param array $old_instance
@return array | [
"Save",
"the",
"menu",
"slug"
] | 7b008dc3182f8b9da44657bd2fe714e7e48cf002 | https://github.com/wearenolte/wp-widgets/blob/7b008dc3182f8b9da44657bd2fe714e7e48cf002/src/Collection/LeanMenu.php#L64-L78 |
174 | wearenolte/wp-widgets | src/Collection/LeanMenu.php | LeanMenu.get_sub_menu_items | public function get_sub_menu_items( $menu_items, $parent_id ) {
$items = [];
foreach ( $menu_items as $menu_item ) {
if ( intval( $parent_id ) === intval( $menu_item->menu_item_parent ) ) {
$items[] = [
'title' => $menu_item->title,
'link' => str_replace( site_url(), '', $menu_item->url ),
'items' => self::get_sub_menu_items( $menu_items, $menu_item->ID ),
];
}
}
return $items;
} | php | public function get_sub_menu_items( $menu_items, $parent_id ) {
$items = [];
foreach ( $menu_items as $menu_item ) {
if ( intval( $parent_id ) === intval( $menu_item->menu_item_parent ) ) {
$items[] = [
'title' => $menu_item->title,
'link' => str_replace( site_url(), '', $menu_item->url ),
'items' => self::get_sub_menu_items( $menu_items, $menu_item->ID ),
];
}
}
return $items;
} | [
"public",
"function",
"get_sub_menu_items",
"(",
"$",
"menu_items",
",",
"$",
"parent_id",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"menu_items",
"as",
"$",
"menu_item",
")",
"{",
"if",
"(",
"intval",
"(",
"$",
"parent_id",
")",
"===",
"intval",
"(",
"$",
"menu_item",
"->",
"menu_item_parent",
")",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"[",
"'title'",
"=>",
"$",
"menu_item",
"->",
"title",
",",
"'link'",
"=>",
"str_replace",
"(",
"site_url",
"(",
")",
",",
"''",
",",
"$",
"menu_item",
"->",
"url",
")",
",",
"'items'",
"=>",
"self",
"::",
"get_sub_menu_items",
"(",
"$",
"menu_items",
",",
"$",
"menu_item",
"->",
"ID",
")",
",",
"]",
";",
"}",
"}",
"return",
"$",
"items",
";",
"}"
] | Recursively get all sub menu items.
@param array $menu_items All menu items.
@param int $parent_id The parent menu id.
@return array | [
"Recursively",
"get",
"all",
"sub",
"menu",
"items",
"."
] | 7b008dc3182f8b9da44657bd2fe714e7e48cf002 | https://github.com/wearenolte/wp-widgets/blob/7b008dc3182f8b9da44657bd2fe714e7e48cf002/src/Collection/LeanMenu.php#L116-L130 |
175 | orbasteam/util | src/Enum.php | Enum.buildClass | protected function buildClass($name)
{
$className = $this->formatClassName($name);
if (!class_exists($className)) {
throw new RuntimeException('Enum '.$className.' is not exists');
}
$enum = new $className();
if (!$enum instanceof Enumable) {
throw new RuntimeException('Enum '.$className.' is not instance of '.Enumable::class);
}
return $enum;
} | php | protected function buildClass($name)
{
$className = $this->formatClassName($name);
if (!class_exists($className)) {
throw new RuntimeException('Enum '.$className.' is not exists');
}
$enum = new $className();
if (!$enum instanceof Enumable) {
throw new RuntimeException('Enum '.$className.' is not instance of '.Enumable::class);
}
return $enum;
} | [
"protected",
"function",
"buildClass",
"(",
"$",
"name",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"formatClassName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Enum '",
".",
"$",
"className",
".",
"' is not exists'",
")",
";",
"}",
"$",
"enum",
"=",
"new",
"$",
"className",
"(",
")",
";",
"if",
"(",
"!",
"$",
"enum",
"instanceof",
"Enumable",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Enum '",
".",
"$",
"className",
".",
"' is not instance of '",
".",
"Enumable",
"::",
"class",
")",
";",
"}",
"return",
"$",
"enum",
";",
"}"
] | Build a Enum class.
@param string $name
@throws RuntimeException
@return Enumable | [
"Build",
"a",
"Enum",
"class",
"."
] | 9e7fb08029931cd5bfe697d57b2099e58cdaf901 | https://github.com/orbasteam/util/blob/9e7fb08029931cd5bfe697d57b2099e58cdaf901/src/Enum.php#L97-L111 |
176 | bishopb/vanilla | applications/dashboard/controllers/class.setupcontroller.php | SetupController.Initialize | public function Initialize() {
$this->Head = new HeadModule($this);
$this->AddCssFile('setup.css');
$this->AddJsFile('jquery.js');
// Make sure all errors are displayed.
SaveToConfig('Garden.Errors.MasterView', 'deverror.master.php', array('Save' => FALSE));
} | php | public function Initialize() {
$this->Head = new HeadModule($this);
$this->AddCssFile('setup.css');
$this->AddJsFile('jquery.js');
// Make sure all errors are displayed.
SaveToConfig('Garden.Errors.MasterView', 'deverror.master.php', array('Save' => FALSE));
} | [
"public",
"function",
"Initialize",
"(",
")",
"{",
"$",
"this",
"->",
"Head",
"=",
"new",
"HeadModule",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"AddCssFile",
"(",
"'setup.css'",
")",
";",
"$",
"this",
"->",
"AddJsFile",
"(",
"'jquery.js'",
")",
";",
"// Make sure all errors are displayed.",
"SaveToConfig",
"(",
"'Garden.Errors.MasterView'",
",",
"'deverror.master.php'",
",",
"array",
"(",
"'Save'",
"=>",
"FALSE",
")",
")",
";",
"}"
] | Add CSS & module, set error master view. Automatically run on every use.
@since 2.0.0
@access public | [
"Add",
"CSS",
"&",
"module",
"set",
"error",
"master",
"view",
".",
"Automatically",
"run",
"on",
"every",
"use",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.setupcontroller.php#L32-L38 |
177 | bishopb/vanilla | applications/dashboard/controllers/class.setupcontroller.php | SetupController.Index | public function Index() {
$this->AddJsFile('setup.js');
$this->ApplicationFolder = 'dashboard';
$this->MasterView = 'setup';
// Fatal error if Garden has already been installed.
$Installed = C('Garden.Installed');
if ($Installed) {
$this->View = "AlreadyInstalled";
$this->Render();
return;
}
if (!$this->_CheckPrerequisites()) {
$this->View = 'prerequisites';
} else {
$this->View = 'configure';
// Make sure the user has copied the htaccess file over.
if (!file_exists(PATH_ROOT.'/.htaccess') && !$this->Form->GetFormValue('SkipHtaccess')) {
$this->SetData('NoHtaccess', TRUE);
$this->Form->AddError(T('You are missing Vanilla\'s .htaccess file.', 'You are missing Vanilla\'s <b>.htaccess</b> file. Sometimes this file isn\'t copied if you are using ftp to upload your files because this file is hidden. Make sure you\'ve copied the <b>.htaccess</b> file before continuing.'));
}
$ApplicationManager = new Gdn_ApplicationManager();
// Need to go through all of the setups for each application. Garden,
if ($this->Configure() && $this->Form->IsPostBack()) {
// Get list of applications to enable during install
// Override by creating conf/config.php and adding this setting before install begins
$AppNames = C('Garden.Install.Applications', array('Conversations', 'Vanilla'));
try {
// Step through the available applications, enabling each of them.
foreach ($AppNames as $AppName) {
$Validation = new Gdn_Validation();
$ApplicationManager->RegisterPermissions($AppName, $Validation);
$ApplicationManager->EnableApplication($AppName, $Validation);
}
} catch (Exception $ex) {
$this->Form->AddError($ex);
}
if ($this->Form->ErrorCount() == 0) {
// Save a variable so that the application knows it has been installed.
// Now that the application is installed, select a more user friendly error page.
$Config = array('Garden.Installed' => TRUE);
SaveToConfig($Config);
// Go to the dashboard
Redirect('/settings/gettingstarted');
}
}
}
$this->Render();
} | php | public function Index() {
$this->AddJsFile('setup.js');
$this->ApplicationFolder = 'dashboard';
$this->MasterView = 'setup';
// Fatal error if Garden has already been installed.
$Installed = C('Garden.Installed');
if ($Installed) {
$this->View = "AlreadyInstalled";
$this->Render();
return;
}
if (!$this->_CheckPrerequisites()) {
$this->View = 'prerequisites';
} else {
$this->View = 'configure';
// Make sure the user has copied the htaccess file over.
if (!file_exists(PATH_ROOT.'/.htaccess') && !$this->Form->GetFormValue('SkipHtaccess')) {
$this->SetData('NoHtaccess', TRUE);
$this->Form->AddError(T('You are missing Vanilla\'s .htaccess file.', 'You are missing Vanilla\'s <b>.htaccess</b> file. Sometimes this file isn\'t copied if you are using ftp to upload your files because this file is hidden. Make sure you\'ve copied the <b>.htaccess</b> file before continuing.'));
}
$ApplicationManager = new Gdn_ApplicationManager();
// Need to go through all of the setups for each application. Garden,
if ($this->Configure() && $this->Form->IsPostBack()) {
// Get list of applications to enable during install
// Override by creating conf/config.php and adding this setting before install begins
$AppNames = C('Garden.Install.Applications', array('Conversations', 'Vanilla'));
try {
// Step through the available applications, enabling each of them.
foreach ($AppNames as $AppName) {
$Validation = new Gdn_Validation();
$ApplicationManager->RegisterPermissions($AppName, $Validation);
$ApplicationManager->EnableApplication($AppName, $Validation);
}
} catch (Exception $ex) {
$this->Form->AddError($ex);
}
if ($this->Form->ErrorCount() == 0) {
// Save a variable so that the application knows it has been installed.
// Now that the application is installed, select a more user friendly error page.
$Config = array('Garden.Installed' => TRUE);
SaveToConfig($Config);
// Go to the dashboard
Redirect('/settings/gettingstarted');
}
}
}
$this->Render();
} | [
"public",
"function",
"Index",
"(",
")",
"{",
"$",
"this",
"->",
"AddJsFile",
"(",
"'setup.js'",
")",
";",
"$",
"this",
"->",
"ApplicationFolder",
"=",
"'dashboard'",
";",
"$",
"this",
"->",
"MasterView",
"=",
"'setup'",
";",
"// Fatal error if Garden has already been installed.",
"$",
"Installed",
"=",
"C",
"(",
"'Garden.Installed'",
")",
";",
"if",
"(",
"$",
"Installed",
")",
"{",
"$",
"this",
"->",
"View",
"=",
"\"AlreadyInstalled\"",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_CheckPrerequisites",
"(",
")",
")",
"{",
"$",
"this",
"->",
"View",
"=",
"'prerequisites'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"View",
"=",
"'configure'",
";",
"// Make sure the user has copied the htaccess file over.",
"if",
"(",
"!",
"file_exists",
"(",
"PATH_ROOT",
".",
"'/.htaccess'",
")",
"&&",
"!",
"$",
"this",
"->",
"Form",
"->",
"GetFormValue",
"(",
"'SkipHtaccess'",
")",
")",
"{",
"$",
"this",
"->",
"SetData",
"(",
"'NoHtaccess'",
",",
"TRUE",
")",
";",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"T",
"(",
"'You are missing Vanilla\\'s .htaccess file.'",
",",
"'You are missing Vanilla\\'s <b>.htaccess</b> file. Sometimes this file isn\\'t copied if you are using ftp to upload your files because this file is hidden. Make sure you\\'ve copied the <b>.htaccess</b> file before continuing.'",
")",
")",
";",
"}",
"$",
"ApplicationManager",
"=",
"new",
"Gdn_ApplicationManager",
"(",
")",
";",
"// Need to go through all of the setups for each application. Garden,",
"if",
"(",
"$",
"this",
"->",
"Configure",
"(",
")",
"&&",
"$",
"this",
"->",
"Form",
"->",
"IsPostBack",
"(",
")",
")",
"{",
"// Get list of applications to enable during install",
"// Override by creating conf/config.php and adding this setting before install begins",
"$",
"AppNames",
"=",
"C",
"(",
"'Garden.Install.Applications'",
",",
"array",
"(",
"'Conversations'",
",",
"'Vanilla'",
")",
")",
";",
"try",
"{",
"// Step through the available applications, enabling each of them.",
"foreach",
"(",
"$",
"AppNames",
"as",
"$",
"AppName",
")",
"{",
"$",
"Validation",
"=",
"new",
"Gdn_Validation",
"(",
")",
";",
"$",
"ApplicationManager",
"->",
"RegisterPermissions",
"(",
"$",
"AppName",
",",
"$",
"Validation",
")",
";",
"$",
"ApplicationManager",
"->",
"EnableApplication",
"(",
"$",
"AppName",
",",
"$",
"Validation",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"$",
"ex",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"Form",
"->",
"ErrorCount",
"(",
")",
"==",
"0",
")",
"{",
"// Save a variable so that the application knows it has been installed.",
"// Now that the application is installed, select a more user friendly error page.",
"$",
"Config",
"=",
"array",
"(",
"'Garden.Installed'",
"=>",
"TRUE",
")",
";",
"SaveToConfig",
"(",
"$",
"Config",
")",
";",
"// Go to the dashboard",
"Redirect",
"(",
"'/settings/gettingstarted'",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | The summary of all settings available.
The menu items displayed here are collected from each application's
application controller and all plugin's definitions.
@since 2.0.0
@access public | [
"The",
"summary",
"of",
"all",
"settings",
"available",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.setupcontroller.php#L49-L102 |
178 | bishopb/vanilla | applications/dashboard/controllers/class.setupcontroller.php | SetupController._CheckPrerequisites | private function _CheckPrerequisites() {
// Make sure we are running at least PHP 5.1
if (version_compare(phpversion(), ENVIRONMENT_PHP_VERSION) < 0)
$this->Form->AddError(sprintf(T('You are running PHP version %1$s. Vanilla requires PHP %2$s or greater. You must upgrade PHP before you can continue.'), phpversion(), ENVIRONMENT_PHP_VERSION));
// Make sure PDO is available
if (!class_exists('PDO'))
$this->Form->AddError(T('You must have the PDO module enabled in PHP in order for Vanilla to connect to your database.'));
if (!defined('PDO::MYSQL_ATTR_USE_BUFFERED_QUERY'))
$this->Form->AddError(T('You must have the MySQL driver for PDO enabled in order for Vanilla to connect to your database.'));
// Make sure that the correct filesystem permissions are in place
$PermissionProblem = FALSE;
// Make sure the appropriate folders are writeable.
$ProblemDirectories = array();
if (!is_readable(PATH_CONF) || !IsWritable(PATH_CONF))
$ProblemDirectories[] = PATH_CONF;
if (!is_readable(PATH_UPLOADS) || !IsWritable(PATH_UPLOADS))
$ProblemDirectories[] = PATH_UPLOADS;
if (!is_readable(PATH_CACHE) || !IsWritable(PATH_CACHE))
$ProblemDirectories[] = PATH_CACHE;
if (count($ProblemDirectories) > 0) {
$PermissionProblem = TRUE;
$PermissionError = T(
'Some folders don\'t have correct permissions.',
'<p>Some of your folders do not have the correct permissions.</p><p>Using your ftp client, or via command line, make sure that the following permissions are set for your vanilla installation:</p>');
$PermissionHelp = '<pre>chmod -R 777 '.implode("\nchmod -R 777 ", $ProblemDirectories).'</pre>';
$this->Form->AddError($PermissionError.$PermissionHelp);
}
// Make sure the config folder is writeable
if (!$PermissionProblem) {
$ConfigFile = PATH_CONF.'/config.php';
if (!file_exists($ConfigFile))
file_put_contents($ConfigFile, '');
// Make sure the config file is writeable
if (!is_readable($ConfigFile) || !IsWritable($ConfigFile)) {
$this->Form->AddError(sprintf(T('Your configuration file does not have the correct permissions. PHP needs to be able to read and write to this file: <code>%s</code>'), $ConfigFile));
$PermissionProblem = TRUE;
}
}
// Make sure the cache folder is writeable
if (!$PermissionProblem) {
if (!file_exists(PATH_CACHE.'/Smarty')) mkdir(PATH_CACHE.'/Smarty');
if (!file_exists(PATH_CACHE.'/Smarty/cache')) mkdir(PATH_CACHE.'/Smarty/cache');
if (!file_exists(PATH_CACHE.'/Smarty/compile')) mkdir(PATH_CACHE.'/Smarty/compile');
}
return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
} | php | private function _CheckPrerequisites() {
// Make sure we are running at least PHP 5.1
if (version_compare(phpversion(), ENVIRONMENT_PHP_VERSION) < 0)
$this->Form->AddError(sprintf(T('You are running PHP version %1$s. Vanilla requires PHP %2$s or greater. You must upgrade PHP before you can continue.'), phpversion(), ENVIRONMENT_PHP_VERSION));
// Make sure PDO is available
if (!class_exists('PDO'))
$this->Form->AddError(T('You must have the PDO module enabled in PHP in order for Vanilla to connect to your database.'));
if (!defined('PDO::MYSQL_ATTR_USE_BUFFERED_QUERY'))
$this->Form->AddError(T('You must have the MySQL driver for PDO enabled in order for Vanilla to connect to your database.'));
// Make sure that the correct filesystem permissions are in place
$PermissionProblem = FALSE;
// Make sure the appropriate folders are writeable.
$ProblemDirectories = array();
if (!is_readable(PATH_CONF) || !IsWritable(PATH_CONF))
$ProblemDirectories[] = PATH_CONF;
if (!is_readable(PATH_UPLOADS) || !IsWritable(PATH_UPLOADS))
$ProblemDirectories[] = PATH_UPLOADS;
if (!is_readable(PATH_CACHE) || !IsWritable(PATH_CACHE))
$ProblemDirectories[] = PATH_CACHE;
if (count($ProblemDirectories) > 0) {
$PermissionProblem = TRUE;
$PermissionError = T(
'Some folders don\'t have correct permissions.',
'<p>Some of your folders do not have the correct permissions.</p><p>Using your ftp client, or via command line, make sure that the following permissions are set for your vanilla installation:</p>');
$PermissionHelp = '<pre>chmod -R 777 '.implode("\nchmod -R 777 ", $ProblemDirectories).'</pre>';
$this->Form->AddError($PermissionError.$PermissionHelp);
}
// Make sure the config folder is writeable
if (!$PermissionProblem) {
$ConfigFile = PATH_CONF.'/config.php';
if (!file_exists($ConfigFile))
file_put_contents($ConfigFile, '');
// Make sure the config file is writeable
if (!is_readable($ConfigFile) || !IsWritable($ConfigFile)) {
$this->Form->AddError(sprintf(T('Your configuration file does not have the correct permissions. PHP needs to be able to read and write to this file: <code>%s</code>'), $ConfigFile));
$PermissionProblem = TRUE;
}
}
// Make sure the cache folder is writeable
if (!$PermissionProblem) {
if (!file_exists(PATH_CACHE.'/Smarty')) mkdir(PATH_CACHE.'/Smarty');
if (!file_exists(PATH_CACHE.'/Smarty/cache')) mkdir(PATH_CACHE.'/Smarty/cache');
if (!file_exists(PATH_CACHE.'/Smarty/compile')) mkdir(PATH_CACHE.'/Smarty/compile');
}
return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
} | [
"private",
"function",
"_CheckPrerequisites",
"(",
")",
"{",
"// Make sure we are running at least PHP 5.1",
"if",
"(",
"version_compare",
"(",
"phpversion",
"(",
")",
",",
"ENVIRONMENT_PHP_VERSION",
")",
"<",
"0",
")",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"sprintf",
"(",
"T",
"(",
"'You are running PHP version %1$s. Vanilla requires PHP %2$s or greater. You must upgrade PHP before you can continue.'",
")",
",",
"phpversion",
"(",
")",
",",
"ENVIRONMENT_PHP_VERSION",
")",
")",
";",
"// Make sure PDO is available",
"if",
"(",
"!",
"class_exists",
"(",
"'PDO'",
")",
")",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"T",
"(",
"'You must have the PDO module enabled in PHP in order for Vanilla to connect to your database.'",
")",
")",
";",
"if",
"(",
"!",
"defined",
"(",
"'PDO::MYSQL_ATTR_USE_BUFFERED_QUERY'",
")",
")",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"T",
"(",
"'You must have the MySQL driver for PDO enabled in order for Vanilla to connect to your database.'",
")",
")",
";",
"// Make sure that the correct filesystem permissions are in place",
"$",
"PermissionProblem",
"=",
"FALSE",
";",
"// Make sure the appropriate folders are writeable.",
"$",
"ProblemDirectories",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_readable",
"(",
"PATH_CONF",
")",
"||",
"!",
"IsWritable",
"(",
"PATH_CONF",
")",
")",
"$",
"ProblemDirectories",
"[",
"]",
"=",
"PATH_CONF",
";",
"if",
"(",
"!",
"is_readable",
"(",
"PATH_UPLOADS",
")",
"||",
"!",
"IsWritable",
"(",
"PATH_UPLOADS",
")",
")",
"$",
"ProblemDirectories",
"[",
"]",
"=",
"PATH_UPLOADS",
";",
"if",
"(",
"!",
"is_readable",
"(",
"PATH_CACHE",
")",
"||",
"!",
"IsWritable",
"(",
"PATH_CACHE",
")",
")",
"$",
"ProblemDirectories",
"[",
"]",
"=",
"PATH_CACHE",
";",
"if",
"(",
"count",
"(",
"$",
"ProblemDirectories",
")",
">",
"0",
")",
"{",
"$",
"PermissionProblem",
"=",
"TRUE",
";",
"$",
"PermissionError",
"=",
"T",
"(",
"'Some folders don\\'t have correct permissions.'",
",",
"'<p>Some of your folders do not have the correct permissions.</p><p>Using your ftp client, or via command line, make sure that the following permissions are set for your vanilla installation:</p>'",
")",
";",
"$",
"PermissionHelp",
"=",
"'<pre>chmod -R 777 '",
".",
"implode",
"(",
"\"\\nchmod -R 777 \"",
",",
"$",
"ProblemDirectories",
")",
".",
"'</pre>'",
";",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"$",
"PermissionError",
".",
"$",
"PermissionHelp",
")",
";",
"}",
"// Make sure the config folder is writeable",
"if",
"(",
"!",
"$",
"PermissionProblem",
")",
"{",
"$",
"ConfigFile",
"=",
"PATH_CONF",
".",
"'/config.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"ConfigFile",
")",
")",
"file_put_contents",
"(",
"$",
"ConfigFile",
",",
"''",
")",
";",
"// Make sure the config file is writeable",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"ConfigFile",
")",
"||",
"!",
"IsWritable",
"(",
"$",
"ConfigFile",
")",
")",
"{",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"sprintf",
"(",
"T",
"(",
"'Your configuration file does not have the correct permissions. PHP needs to be able to read and write to this file: <code>%s</code>'",
")",
",",
"$",
"ConfigFile",
")",
")",
";",
"$",
"PermissionProblem",
"=",
"TRUE",
";",
"}",
"}",
"// Make sure the cache folder is writeable",
"if",
"(",
"!",
"$",
"PermissionProblem",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"PATH_CACHE",
".",
"'/Smarty'",
")",
")",
"mkdir",
"(",
"PATH_CACHE",
".",
"'/Smarty'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"PATH_CACHE",
".",
"'/Smarty/cache'",
")",
")",
"mkdir",
"(",
"PATH_CACHE",
".",
"'/Smarty/cache'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"PATH_CACHE",
".",
"'/Smarty/compile'",
")",
")",
"mkdir",
"(",
"PATH_CACHE",
".",
"'/Smarty/compile'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"Form",
"->",
"ErrorCount",
"(",
")",
"==",
"0",
"?",
"TRUE",
":",
"FALSE",
";",
"}"
] | Check minimum requirements for Garden.
@since 2.0.0
@access private
@return bool Whether platform passes requirement check. | [
"Check",
"minimum",
"requirements",
"for",
"Garden",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.setupcontroller.php#L257-L316 |
179 | opendi/lang | src/ArrayUtils.php | ArrayUtils.flatten | public static function flatten(array $array, $separator = '.', $prefix = '')
{
$result = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
$newPrefix = empty($prefix) ? $key : "$prefix.$key";
$result = array_merge($result, self::flatten($value, $separator, $newPrefix));
} else {
$newKey = empty($prefix) ? $key : "$prefix.$key";
$result[$newKey] = $value;
}
}
return $result;
} | php | public static function flatten(array $array, $separator = '.', $prefix = '')
{
$result = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
$newPrefix = empty($prefix) ? $key : "$prefix.$key";
$result = array_merge($result, self::flatten($value, $separator, $newPrefix));
} else {
$newKey = empty($prefix) ? $key : "$prefix.$key";
$result[$newKey] = $value;
}
}
return $result;
} | [
"public",
"static",
"function",
"flatten",
"(",
"array",
"$",
"array",
",",
"$",
"separator",
"=",
"'.'",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"newPrefix",
"=",
"empty",
"(",
"$",
"prefix",
")",
"?",
"$",
"key",
":",
"\"$prefix.$key\"",
";",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"self",
"::",
"flatten",
"(",
"$",
"value",
",",
"$",
"separator",
",",
"$",
"newPrefix",
")",
")",
";",
"}",
"else",
"{",
"$",
"newKey",
"=",
"empty",
"(",
"$",
"prefix",
")",
"?",
"$",
"key",
":",
"\"$prefix.$key\"",
";",
"$",
"result",
"[",
"$",
"newKey",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Flattens a deep array to a single dimension.
@param array $array Array to flatten.
@param string $separator Separator used to divide key values.
@param string $prefix Initial key prefix. Empty by default.
@throws InvalidArgumentException if a non-array value is given | [
"Flattens",
"a",
"deep",
"array",
"to",
"a",
"single",
"dimension",
"."
] | cbf813c484cd21ec11c35c0c11ec314a583e58ff | https://github.com/opendi/lang/blob/cbf813c484cd21ec11c35c0c11ec314a583e58ff/src/ArrayUtils.php#L37-L52 |
180 | opendi/lang | src/ArrayUtils.php | ArrayUtils.processReindexPath | private static function processReindexPath($path)
{
if (is_string($path) || is_integer($path)) {
// Single level path - one element only
$path = array(array($path));
} elseif (is_array($path) && !empty($path) && !is_array($path[0])) {
// Single level path - multiple elements
// Check each path element is either a string or an integer
foreach ($path as $key) {
if (!(is_string($key) || is_integer($key))) {
throw new InvalidArgumentException('Invalid reindex path.');
}
}
$path = array($path);
} elseif (is_array($path) && !empty($path) && is_array($path[0])) {
// Multilevel path
// Check each path element is an array (a sub-path)
foreach ($path as $subpath) {
if (!is_array($subpath) || empty($subpath)) {
throw new InvalidArgumentException('Invalid reindex path.');
}
// Check each sub-path element is a valid array key (either a string or an integer)
foreach ($subpath as $key) {
if (!(is_string($key) || is_integer($key))) {
throw new InvalidArgumentException('Invalid reindex path.');
}
}
}
} else {
throw new InvalidArgumentException('Invalid reindex path.');
}
return $path;
} | php | private static function processReindexPath($path)
{
if (is_string($path) || is_integer($path)) {
// Single level path - one element only
$path = array(array($path));
} elseif (is_array($path) && !empty($path) && !is_array($path[0])) {
// Single level path - multiple elements
// Check each path element is either a string or an integer
foreach ($path as $key) {
if (!(is_string($key) || is_integer($key))) {
throw new InvalidArgumentException('Invalid reindex path.');
}
}
$path = array($path);
} elseif (is_array($path) && !empty($path) && is_array($path[0])) {
// Multilevel path
// Check each path element is an array (a sub-path)
foreach ($path as $subpath) {
if (!is_array($subpath) || empty($subpath)) {
throw new InvalidArgumentException('Invalid reindex path.');
}
// Check each sub-path element is a valid array key (either a string or an integer)
foreach ($subpath as $key) {
if (!(is_string($key) || is_integer($key))) {
throw new InvalidArgumentException('Invalid reindex path.');
}
}
}
} else {
throw new InvalidArgumentException('Invalid reindex path.');
}
return $path;
} | [
"private",
"static",
"function",
"processReindexPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"path",
")",
"||",
"is_integer",
"(",
"$",
"path",
")",
")",
"{",
"// Single level path - one element only",
"$",
"path",
"=",
"array",
"(",
"array",
"(",
"$",
"path",
")",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"path",
")",
"&&",
"!",
"empty",
"(",
"$",
"path",
")",
"&&",
"!",
"is_array",
"(",
"$",
"path",
"[",
"0",
"]",
")",
")",
"{",
"// Single level path - multiple elements",
"// Check each path element is either a string or an integer",
"foreach",
"(",
"$",
"path",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"(",
"is_string",
"(",
"$",
"key",
")",
"||",
"is_integer",
"(",
"$",
"key",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid reindex path.'",
")",
";",
"}",
"}",
"$",
"path",
"=",
"array",
"(",
"$",
"path",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"path",
")",
"&&",
"!",
"empty",
"(",
"$",
"path",
")",
"&&",
"is_array",
"(",
"$",
"path",
"[",
"0",
"]",
")",
")",
"{",
"// Multilevel path",
"// Check each path element is an array (a sub-path)",
"foreach",
"(",
"$",
"path",
"as",
"$",
"subpath",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"subpath",
")",
"||",
"empty",
"(",
"$",
"subpath",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid reindex path.'",
")",
";",
"}",
"// Check each sub-path element is a valid array key (either a string or an integer)",
"foreach",
"(",
"$",
"subpath",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"(",
"is_string",
"(",
"$",
"key",
")",
"||",
"is_integer",
"(",
"$",
"key",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid reindex path.'",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid reindex path.'",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Processes and validates the given index path. | [
"Processes",
"and",
"validates",
"the",
"given",
"index",
"path",
"."
] | cbf813c484cd21ec11c35c0c11ec314a583e58ff | https://github.com/opendi/lang/blob/cbf813c484cd21ec11c35c0c11ec314a583e58ff/src/ArrayUtils.php#L115-L150 |
181 | sellerlabs/nucleus | src/SellerLabs/Nucleus/Data/Exceptions/MismatchedDataTypesException.php | MismatchedDataTypesException.setExpectedAndReceived | public function setExpectedAndReceived($expected, $received)
{
$this->expected = is_string($expected)
? $expected : get_class($expected);
$this->received = TypeHound::fetch($received);
$this->message = vsprintf(
'An instance of a %s was expected but got %s',
[$this->expected, $this->received]
);
} | php | public function setExpectedAndReceived($expected, $received)
{
$this->expected = is_string($expected)
? $expected : get_class($expected);
$this->received = TypeHound::fetch($received);
$this->message = vsprintf(
'An instance of a %s was expected but got %s',
[$this->expected, $this->received]
);
} | [
"public",
"function",
"setExpectedAndReceived",
"(",
"$",
"expected",
",",
"$",
"received",
")",
"{",
"$",
"this",
"->",
"expected",
"=",
"is_string",
"(",
"$",
"expected",
")",
"?",
"$",
"expected",
":",
"get_class",
"(",
"$",
"expected",
")",
";",
"$",
"this",
"->",
"received",
"=",
"TypeHound",
"::",
"fetch",
"(",
"$",
"received",
")",
";",
"$",
"this",
"->",
"message",
"=",
"vsprintf",
"(",
"'An instance of a %s was expected but got %s'",
",",
"[",
"$",
"this",
"->",
"expected",
",",
"$",
"this",
"->",
"received",
"]",
")",
";",
"}"
] | Set the expected class and the received value.
@param string|object $expected
@param mixed $received | [
"Set",
"the",
"expected",
"class",
"and",
"the",
"received",
"value",
"."
] | c05d9c23d424a6bd5ab2e29140805cc6e37e4623 | https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Data/Exceptions/MismatchedDataTypesException.php#L58-L69 |
182 | prooph/link-processor-proxy | src/ProcessingPlugin/MessageFlowLogger.php | MessageFlowLogger.tryLogMessage | private function tryLogMessage($message)
{
$messageId = null;
if ($message instanceof RemoteMessage) $messageId = $message->header()->uuid();
elseif ($message instanceof ProcessingMessage) $messageId = $message->uuid();
if (! $messageId) return;
$entry = $this->messageLogger->getEntryForMessageId($messageId);
if ($entry) return;
$this->messageLogger->logIncomingMessage($message);
} | php | private function tryLogMessage($message)
{
$messageId = null;
if ($message instanceof RemoteMessage) $messageId = $message->header()->uuid();
elseif ($message instanceof ProcessingMessage) $messageId = $message->uuid();
if (! $messageId) return;
$entry = $this->messageLogger->getEntryForMessageId($messageId);
if ($entry) return;
$this->messageLogger->logIncomingMessage($message);
} | [
"private",
"function",
"tryLogMessage",
"(",
"$",
"message",
")",
"{",
"$",
"messageId",
"=",
"null",
";",
"if",
"(",
"$",
"message",
"instanceof",
"RemoteMessage",
")",
"$",
"messageId",
"=",
"$",
"message",
"->",
"header",
"(",
")",
"->",
"uuid",
"(",
")",
";",
"elseif",
"(",
"$",
"message",
"instanceof",
"ProcessingMessage",
")",
"$",
"messageId",
"=",
"$",
"message",
"->",
"uuid",
"(",
")",
";",
"if",
"(",
"!",
"$",
"messageId",
")",
"return",
";",
"$",
"entry",
"=",
"$",
"this",
"->",
"messageLogger",
"->",
"getEntryForMessageId",
"(",
"$",
"messageId",
")",
";",
"if",
"(",
"$",
"entry",
")",
"return",
";",
"$",
"this",
"->",
"messageLogger",
"->",
"logIncomingMessage",
"(",
"$",
"message",
")",
";",
"}"
] | Message is only logged if it is has a valid type and is not logged already
otherwise it is ignored.
@param $message | [
"Message",
"is",
"only",
"logged",
"if",
"it",
"is",
"has",
"a",
"valid",
"type",
"and",
"is",
"not",
"logged",
"already",
"otherwise",
"it",
"is",
"ignored",
"."
] | 52106cc9a6524d35fae0dbee1e04eeb3b3e5cc10 | https://github.com/prooph/link-processor-proxy/blob/52106cc9a6524d35fae0dbee1e04eeb3b3e5cc10/src/ProcessingPlugin/MessageFlowLogger.php#L158-L172 |
183 | easy-system/es-container | src/ParametricTree/RecursiveLeaf.php | RecursiveLeaf.addChild | public function addChild(RecursiveLeafInterface $leaf)
{
$leaf->setDepth($this->depth + 1);
$this->children[] = $leaf;
} | php | public function addChild(RecursiveLeafInterface $leaf)
{
$leaf->setDepth($this->depth + 1);
$this->children[] = $leaf;
} | [
"public",
"function",
"addChild",
"(",
"RecursiveLeafInterface",
"$",
"leaf",
")",
"{",
"$",
"leaf",
"->",
"setDepth",
"(",
"$",
"this",
"->",
"depth",
"+",
"1",
")",
";",
"$",
"this",
"->",
"children",
"[",
"]",
"=",
"$",
"leaf",
";",
"}"
] | Adds the child leaf.
@param RecursiveLeafInterface $leaf The leaf | [
"Adds",
"the",
"child",
"leaf",
"."
] | 0e917d8ff2c3622f53b82d34436295539858be7d | https://github.com/easy-system/es-container/blob/0e917d8ff2c3622f53b82d34436295539858be7d/src/ParametricTree/RecursiveLeaf.php#L61-L65 |
184 | easy-system/es-container | src/ParametricTree/RecursiveLeaf.php | RecursiveLeaf.setUniqueKey | public function setUniqueKey($uniqueKey)
{
if (! is_null($this->uniqueKey)) {
throw new RuntimeException('The unique key was already set.');
}
if (! is_int($uniqueKey) && ! is_string($uniqueKey)) {
throw new InvalidArgumentException(sprintf(
'Invalid type of specified unique key; must be an integer or '
. 'an string, "%s" received.',
gettype($uniqueKey)
));
}
$this->uniqueKey = $uniqueKey;
} | php | public function setUniqueKey($uniqueKey)
{
if (! is_null($this->uniqueKey)) {
throw new RuntimeException('The unique key was already set.');
}
if (! is_int($uniqueKey) && ! is_string($uniqueKey)) {
throw new InvalidArgumentException(sprintf(
'Invalid type of specified unique key; must be an integer or '
. 'an string, "%s" received.',
gettype($uniqueKey)
));
}
$this->uniqueKey = $uniqueKey;
} | [
"public",
"function",
"setUniqueKey",
"(",
"$",
"uniqueKey",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"uniqueKey",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The unique key was already set.'",
")",
";",
"}",
"if",
"(",
"!",
"is_int",
"(",
"$",
"uniqueKey",
")",
"&&",
"!",
"is_string",
"(",
"$",
"uniqueKey",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid type of specified unique key; must be an integer or '",
".",
"'an string, \"%s\" received.'",
",",
"gettype",
"(",
"$",
"uniqueKey",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"uniqueKey",
"=",
"$",
"uniqueKey",
";",
"}"
] | Sets the unique key of leaf.
@param int|string $uniqueKey The unique key
@throws \RuntimeException If the unique key was already set
@throws \InvalidArgumentException If type of specified key is invalid | [
"Sets",
"the",
"unique",
"key",
"of",
"leaf",
"."
] | 0e917d8ff2c3622f53b82d34436295539858be7d | https://github.com/easy-system/es-container/blob/0e917d8ff2c3622f53b82d34436295539858be7d/src/ParametricTree/RecursiveLeaf.php#L93-L106 |
185 | easy-system/es-container | src/ParametricTree/RecursiveLeaf.php | RecursiveLeaf.setDepth | public function setDepth($depth)
{
if (! is_null($this->depth)) {
throw new RuntimeException('The depth was already set.');
}
if (! is_int($depth)) {
throw new InvalidArgumentException(sprintf(
'Invalid type of specified depth; must be an integer, '
. '"%s" received.',
gettype($depth)
));
}
$this->depth = $depth;
} | php | public function setDepth($depth)
{
if (! is_null($this->depth)) {
throw new RuntimeException('The depth was already set.');
}
if (! is_int($depth)) {
throw new InvalidArgumentException(sprintf(
'Invalid type of specified depth; must be an integer, '
. '"%s" received.',
gettype($depth)
));
}
$this->depth = $depth;
} | [
"public",
"function",
"setDepth",
"(",
"$",
"depth",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"depth",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The depth was already set.'",
")",
";",
"}",
"if",
"(",
"!",
"is_int",
"(",
"$",
"depth",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid type of specified depth; must be an integer, '",
".",
"'\"%s\" received.'",
",",
"gettype",
"(",
"$",
"depth",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"depth",
"=",
"$",
"depth",
";",
"}"
] | Sets the depth of leaf in the tree.
@param int $depth The depth of leaf in the tree
@throws \RuntimeException If the depth was already set
@throws \InvalidArgumentException If type of specified depth is invalid | [
"Sets",
"the",
"depth",
"of",
"leaf",
"in",
"the",
"tree",
"."
] | 0e917d8ff2c3622f53b82d34436295539858be7d | https://github.com/easy-system/es-container/blob/0e917d8ff2c3622f53b82d34436295539858be7d/src/ParametricTree/RecursiveLeaf.php#L126-L139 |
186 | jooorooo/embed | src/Providers/OEmbed.php | OEmbed.getEndPointFromRequest | protected static function getEndPointFromRequest(Request $request, array $config)
{
//Search the oembed provider using the domain
$class = self::getClassFromRequest($request);
if (class_exists($class) && $request->match($class::getPatterns())) {
return [
'endPoint' => $class::getEndpoint(),
'params' => $class::getParams($request),
];
}
//Search using embedly
if (!empty($config['embedlyKey']) && $request->match(OEmbed\Embedly::getPatterns())) {
return [
'endPoint' => OEmbed\Embedly::getEndpoint(),
'params' => OEmbed\Embedly::getParams($request) + ['key' => $config['embedlyKey']],
];
}
} | php | protected static function getEndPointFromRequest(Request $request, array $config)
{
//Search the oembed provider using the domain
$class = self::getClassFromRequest($request);
if (class_exists($class) && $request->match($class::getPatterns())) {
return [
'endPoint' => $class::getEndpoint(),
'params' => $class::getParams($request),
];
}
//Search using embedly
if (!empty($config['embedlyKey']) && $request->match(OEmbed\Embedly::getPatterns())) {
return [
'endPoint' => OEmbed\Embedly::getEndpoint(),
'params' => OEmbed\Embedly::getParams($request) + ['key' => $config['embedlyKey']],
];
}
} | [
"protected",
"static",
"function",
"getEndPointFromRequest",
"(",
"Request",
"$",
"request",
",",
"array",
"$",
"config",
")",
"{",
"//Search the oembed provider using the domain",
"$",
"class",
"=",
"self",
"::",
"getClassFromRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
"&&",
"$",
"request",
"->",
"match",
"(",
"$",
"class",
"::",
"getPatterns",
"(",
")",
")",
")",
"{",
"return",
"[",
"'endPoint'",
"=>",
"$",
"class",
"::",
"getEndpoint",
"(",
")",
",",
"'params'",
"=>",
"$",
"class",
"::",
"getParams",
"(",
"$",
"request",
")",
",",
"]",
";",
"}",
"//Search using embedly",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'embedlyKey'",
"]",
")",
"&&",
"$",
"request",
"->",
"match",
"(",
"OEmbed",
"\\",
"Embedly",
"::",
"getPatterns",
"(",
")",
")",
")",
"{",
"return",
"[",
"'endPoint'",
"=>",
"OEmbed",
"\\",
"Embedly",
"::",
"getEndpoint",
"(",
")",
",",
"'params'",
"=>",
"OEmbed",
"\\",
"Embedly",
"::",
"getParams",
"(",
"$",
"request",
")",
"+",
"[",
"'key'",
"=>",
"$",
"config",
"[",
"'embedlyKey'",
"]",
"]",
",",
"]",
";",
"}",
"}"
] | Returns the oembed link from the request
@param Request $request
@param array $config
@return array|null | [
"Returns",
"the",
"oembed",
"link",
"from",
"the",
"request"
] | 078e70a093f246dc8e10b92f909f9166932c4106 | https://github.com/jooorooo/embed/blob/078e70a093f246dc8e10b92f909f9166932c4106/src/Providers/OEmbed.php#L235-L254 |
187 | dmeikle/ra | src/Gossamer/Ra/Encryption/Encryption.php | Encryption.generateHash | public static function generateHash($password) {
// A higher "cost" is more secure but consumes more processing power
$cost = 10;
// Create a random salt
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
// Prefix information about the hash so PHP knows how to verify it later.
// "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
$salt = sprintf("$2a$%02d$", $cost) . $salt;
// Value:
// $2a$10$eImiTXuWVxfM37uY4JANjQ==
// Hash the password with the salt
$hash = crypt($password, $salt);
return $hash;
} | php | public static function generateHash($password) {
// A higher "cost" is more secure but consumes more processing power
$cost = 10;
// Create a random salt
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
// Prefix information about the hash so PHP knows how to verify it later.
// "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
$salt = sprintf("$2a$%02d$", $cost) . $salt;
// Value:
// $2a$10$eImiTXuWVxfM37uY4JANjQ==
// Hash the password with the salt
$hash = crypt($password, $salt);
return $hash;
} | [
"public",
"static",
"function",
"generateHash",
"(",
"$",
"password",
")",
"{",
"// A higher \"cost\" is more secure but consumes more processing power",
"$",
"cost",
"=",
"10",
";",
"// Create a random salt",
"$",
"salt",
"=",
"strtr",
"(",
"base64_encode",
"(",
"mcrypt_create_iv",
"(",
"16",
",",
"MCRYPT_DEV_URANDOM",
")",
")",
",",
"'+'",
",",
"'.'",
")",
";",
"// Prefix information about the hash so PHP knows how to verify it later.",
"// \"$2a$\" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.",
"$",
"salt",
"=",
"sprintf",
"(",
"\"$2a$%02d$\"",
",",
"$",
"cost",
")",
".",
"$",
"salt",
";",
"// Value:",
"// $2a$10$eImiTXuWVxfM37uY4JANjQ==",
"// Hash the password with the salt",
"$",
"hash",
"=",
"crypt",
"(",
"$",
"password",
",",
"$",
"salt",
")",
";",
"return",
"$",
"hash",
";",
"}"
] | generates the hash
@param string $password | [
"generates",
"the",
"hash"
] | dc4ea01d6111f1b7e71963ea5907ddd8322af119 | https://github.com/dmeikle/ra/blob/dc4ea01d6111f1b7e71963ea5907ddd8322af119/src/Gossamer/Ra/Encryption/Encryption.php#L33-L50 |
188 | agentmedia/phine-forms | src/Forms/Modules/Backend/RadioForm.php | RadioForm.AddOptionsField | private function AddOptionsField()
{
$name = 'Options';
$field = new Textarea($name, $this->OptionsString());
$this->AddField($field);
$this->SetTransAttribute($name, 'placeholder');
$this->SetRequired($name);
} | php | private function AddOptionsField()
{
$name = 'Options';
$field = new Textarea($name, $this->OptionsString());
$this->AddField($field);
$this->SetTransAttribute($name, 'placeholder');
$this->SetRequired($name);
} | [
"private",
"function",
"AddOptionsField",
"(",
")",
"{",
"$",
"name",
"=",
"'Options'",
";",
"$",
"field",
"=",
"new",
"Textarea",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"OptionsString",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"SetTransAttribute",
"(",
"$",
"name",
",",
"'placeholder'",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}"
] | Adds the options textarea | [
"Adds",
"the",
"options",
"textarea"
] | cd7a92ea443756bef5885a9e8f59ad6b8d2771fc | https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Backend/RadioForm.php#L115-L122 |
189 | agentmedia/phine-forms | src/Forms/Modules/Backend/RadioForm.php | RadioForm.SaveElement | protected function SaveElement()
{
$this->radio->SetLabel($this->Value('Label'));
$this->radio->SetName($this->Value('Name'));
$this->radio->SetValue($this->Value('Value'));
$this->radio->SetRequired((bool)$this->Value('Required'));
$this->radio->SetDisableFrontendValidation((bool)$this->Value('DisableFrontendValidation'));
return $this->radio;
} | php | protected function SaveElement()
{
$this->radio->SetLabel($this->Value('Label'));
$this->radio->SetName($this->Value('Name'));
$this->radio->SetValue($this->Value('Value'));
$this->radio->SetRequired((bool)$this->Value('Required'));
$this->radio->SetDisableFrontendValidation((bool)$this->Value('DisableFrontendValidation'));
return $this->radio;
} | [
"protected",
"function",
"SaveElement",
"(",
")",
"{",
"$",
"this",
"->",
"radio",
"->",
"SetLabel",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Label'",
")",
")",
";",
"$",
"this",
"->",
"radio",
"->",
"SetName",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Name'",
")",
")",
";",
"$",
"this",
"->",
"radio",
"->",
"SetValue",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Value'",
")",
")",
";",
"$",
"this",
"->",
"radio",
"->",
"SetRequired",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'Required'",
")",
")",
";",
"$",
"this",
"->",
"radio",
"->",
"SetDisableFrontendValidation",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'DisableFrontendValidation'",
")",
")",
";",
"return",
"$",
"this",
"->",
"radio",
";",
"}"
] | Stores the radio content's base properties
@return ContentRadio Returns the radio content element | [
"Stores",
"the",
"radio",
"content",
"s",
"base",
"properties"
] | cd7a92ea443756bef5885a9e8f59ad6b8d2771fc | https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Backend/RadioForm.php#L148-L156 |
190 | agentmedia/phine-forms | src/Forms/Modules/Backend/RadioForm.php | RadioForm.FetchOptions | private function FetchOptions()
{
$strOptions = $this->Value('Options');
$lines = Str::SplitLines($strOptions);
$result = array();
foreach ($lines as $line)
{
$dpPos = strpos($line, ':');
if ($dpPos !== false)
{
$value = trim(substr($line, 0, $dpPos));
$text = trim(substr($line, $dpPos + 1));
}
else
{
$value = $line;
$text = '';
}
$result[$value] = $text;
}
return $result;
} | php | private function FetchOptions()
{
$strOptions = $this->Value('Options');
$lines = Str::SplitLines($strOptions);
$result = array();
foreach ($lines as $line)
{
$dpPos = strpos($line, ':');
if ($dpPos !== false)
{
$value = trim(substr($line, 0, $dpPos));
$text = trim(substr($line, $dpPos + 1));
}
else
{
$value = $line;
$text = '';
}
$result[$value] = $text;
}
return $result;
} | [
"private",
"function",
"FetchOptions",
"(",
")",
"{",
"$",
"strOptions",
"=",
"$",
"this",
"->",
"Value",
"(",
"'Options'",
")",
";",
"$",
"lines",
"=",
"Str",
"::",
"SplitLines",
"(",
"$",
"strOptions",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"dpPos",
"=",
"strpos",
"(",
"$",
"line",
",",
"':'",
")",
";",
"if",
"(",
"$",
"dpPos",
"!==",
"false",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"$",
"dpPos",
")",
")",
";",
"$",
"text",
"=",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"$",
"dpPos",
"+",
"1",
")",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"line",
";",
"$",
"text",
"=",
"''",
";",
"}",
"$",
"result",
"[",
"$",
"value",
"]",
"=",
"$",
"text",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Fetches submitted options as array
@return array Returns the submitted options as value=>text array | [
"Fetches",
"submitted",
"options",
"as",
"array"
] | cd7a92ea443756bef5885a9e8f59ad6b8d2771fc | https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Backend/RadioForm.php#L201-L222 |
191 | bytic/database | src/Query/Select.php | Select.group | public function group($fields, $rollup = false)
{
$this->parts['group']['fields'] = $fields;
$this->parts['group']['rollup'] = $rollup;
return $this;
} | php | public function group($fields, $rollup = false)
{
$this->parts['group']['fields'] = $fields;
$this->parts['group']['rollup'] = $rollup;
return $this;
} | [
"public",
"function",
"group",
"(",
"$",
"fields",
",",
"$",
"rollup",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'fields'",
"]",
"=",
"$",
"fields",
";",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'rollup'",
"]",
"=",
"$",
"rollup",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the group paramater for the query
@param array $fields
@param boolean $rollup suport for modifier WITH ROLLUP
@return $this | [
"Sets",
"the",
"group",
"paramater",
"for",
"the",
"query"
] | 186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4 | https://github.com/bytic/database/blob/186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4/src/Query/Select.php#L108-L114 |
192 | bytic/database | src/Query/Select.php | Select.parseCols | protected function parseCols()
{
if (!isset($this->parts['cols']) || !is_array($this->parts['cols']) || count($this->parts['cols']) < 1) {
return '*';
} else {
$selectParts = [];
foreach ($this->parts['cols'] as $itemSelect) {
if (is_array($itemSelect)) {
$field = isset($itemSelect[0]) ? $itemSelect[0] : false;
$alias = isset($itemSelect[1]) ? $itemSelect[1] : false;
$protected = isset($itemSelect[2]) ? $itemSelect[2] : true;
$selectParts[] = ($protected ? $this->protect($field) : $field).(!empty($alias) ? ' AS '.$this->protect($alias) : '');
} else {
$selectParts[] = $itemSelect;
}
}
return implode(', ', $selectParts);
}
} | php | protected function parseCols()
{
if (!isset($this->parts['cols']) || !is_array($this->parts['cols']) || count($this->parts['cols']) < 1) {
return '*';
} else {
$selectParts = [];
foreach ($this->parts['cols'] as $itemSelect) {
if (is_array($itemSelect)) {
$field = isset($itemSelect[0]) ? $itemSelect[0] : false;
$alias = isset($itemSelect[1]) ? $itemSelect[1] : false;
$protected = isset($itemSelect[2]) ? $itemSelect[2] : true;
$selectParts[] = ($protected ? $this->protect($field) : $field).(!empty($alias) ? ' AS '.$this->protect($alias) : '');
} else {
$selectParts[] = $itemSelect;
}
}
return implode(', ', $selectParts);
}
} | [
"protected",
"function",
"parseCols",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parts",
"[",
"'cols'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"parts",
"[",
"'cols'",
"]",
")",
"||",
"count",
"(",
"$",
"this",
"->",
"parts",
"[",
"'cols'",
"]",
")",
"<",
"1",
")",
"{",
"return",
"'*'",
";",
"}",
"else",
"{",
"$",
"selectParts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"parts",
"[",
"'cols'",
"]",
"as",
"$",
"itemSelect",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"itemSelect",
")",
")",
"{",
"$",
"field",
"=",
"isset",
"(",
"$",
"itemSelect",
"[",
"0",
"]",
")",
"?",
"$",
"itemSelect",
"[",
"0",
"]",
":",
"false",
";",
"$",
"alias",
"=",
"isset",
"(",
"$",
"itemSelect",
"[",
"1",
"]",
")",
"?",
"$",
"itemSelect",
"[",
"1",
"]",
":",
"false",
";",
"$",
"protected",
"=",
"isset",
"(",
"$",
"itemSelect",
"[",
"2",
"]",
")",
"?",
"$",
"itemSelect",
"[",
"2",
"]",
":",
"true",
";",
"$",
"selectParts",
"[",
"]",
"=",
"(",
"$",
"protected",
"?",
"$",
"this",
"->",
"protect",
"(",
"$",
"field",
")",
":",
"$",
"field",
")",
".",
"(",
"!",
"empty",
"(",
"$",
"alias",
")",
"?",
"' AS '",
".",
"$",
"this",
"->",
"protect",
"(",
"$",
"alias",
")",
":",
"''",
")",
";",
"}",
"else",
"{",
"$",
"selectParts",
"[",
"]",
"=",
"$",
"itemSelect",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"selectParts",
")",
";",
"}",
"}"
] | Parses SELECT entries
@return string | [
"Parses",
"SELECT",
"entries"
] | 186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4 | https://github.com/bytic/database/blob/186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4/src/Query/Select.php#L189-L210 |
193 | bytic/database | src/Query/Select.php | Select.parseFrom | private function parseFrom()
{
if (!empty($this->parts['from'])) {
$parts = [];
foreach ($this->parts['from'] as $key => $item) {
if (is_array($item)) {
$table = isset($item[0]) ? $item[0] : false;
$alias = isset($item[1]) ? $item[1] : false;
if (is_object($table)) {
if (!$alias) {
trigger_error('Select statements in for need aliases defined', E_USER_ERROR);
}
$parts[$key] = '('.$table.') AS '.$this->protect($alias).$this->parseJoin($alias);
} else {
$parts[$key] = $this->protect($table).' AS '.$this->protect((!empty($alias) ? $alias : $table)).$this->parseJoin($alias);
}
} elseif (!strpos($item, ' ')) {
$parts[] = $this->protect($item).$this->parseJoin($item);
} else {
$parts[] = $item;
}
}
return implode(", ", array_unique($parts));
}
return null;
} | php | private function parseFrom()
{
if (!empty($this->parts['from'])) {
$parts = [];
foreach ($this->parts['from'] as $key => $item) {
if (is_array($item)) {
$table = isset($item[0]) ? $item[0] : false;
$alias = isset($item[1]) ? $item[1] : false;
if (is_object($table)) {
if (!$alias) {
trigger_error('Select statements in for need aliases defined', E_USER_ERROR);
}
$parts[$key] = '('.$table.') AS '.$this->protect($alias).$this->parseJoin($alias);
} else {
$parts[$key] = $this->protect($table).' AS '.$this->protect((!empty($alias) ? $alias : $table)).$this->parseJoin($alias);
}
} elseif (!strpos($item, ' ')) {
$parts[] = $this->protect($item).$this->parseJoin($item);
} else {
$parts[] = $item;
}
}
return implode(", ", array_unique($parts));
}
return null;
} | [
"private",
"function",
"parseFrom",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"parts",
"[",
"'from'",
"]",
")",
")",
"{",
"$",
"parts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"parts",
"[",
"'from'",
"]",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"table",
"=",
"isset",
"(",
"$",
"item",
"[",
"0",
"]",
")",
"?",
"$",
"item",
"[",
"0",
"]",
":",
"false",
";",
"$",
"alias",
"=",
"isset",
"(",
"$",
"item",
"[",
"1",
"]",
")",
"?",
"$",
"item",
"[",
"1",
"]",
":",
"false",
";",
"if",
"(",
"is_object",
"(",
"$",
"table",
")",
")",
"{",
"if",
"(",
"!",
"$",
"alias",
")",
"{",
"trigger_error",
"(",
"'Select statements in for need aliases defined'",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"parts",
"[",
"$",
"key",
"]",
"=",
"'('",
".",
"$",
"table",
".",
"') AS '",
".",
"$",
"this",
"->",
"protect",
"(",
"$",
"alias",
")",
".",
"$",
"this",
"->",
"parseJoin",
"(",
"$",
"alias",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"protect",
"(",
"$",
"table",
")",
".",
"' AS '",
".",
"$",
"this",
"->",
"protect",
"(",
"(",
"!",
"empty",
"(",
"$",
"alias",
")",
"?",
"$",
"alias",
":",
"$",
"table",
")",
")",
".",
"$",
"this",
"->",
"parseJoin",
"(",
"$",
"alias",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"strpos",
"(",
"$",
"item",
",",
"' '",
")",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"this",
"->",
"protect",
"(",
"$",
"item",
")",
".",
"$",
"this",
"->",
"parseJoin",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"implode",
"(",
"\", \"",
",",
"array_unique",
"(",
"$",
"parts",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Parses FROM entries
@return string | [
"Parses",
"FROM",
"entries"
] | 186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4 | https://github.com/bytic/database/blob/186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4/src/Query/Select.php#L216-L245 |
194 | bytic/database | src/Query/Select.php | Select.parseGroup | private function parseGroup()
{
$group = '';
if (isset($this->parts['group']['fields'])) {
if (is_array($this->parts['group']['fields'])) {
$groupFields = [];
foreach ($this->parts['group']['fields'] as $field) {
$field = is_array($field) ? $field : [$field];
$column = isset($field[0]) ? $field[0] : false;
$type = isset($field[1]) ? $field[1] : '';
$groupFields[] = $this->protect($column).($type ? ' '.strtoupper($type) : '');
}
$group .= implode(', ', $groupFields);
} else {
$group .= $this->parts['group']['fields'];
}
}
if (isset($this->parts['group']['rollup']) && $this->parts['group']['rollup'] !== false) {
$group .= ' WITH ROLLUP';
}
return $group;
} | php | private function parseGroup()
{
$group = '';
if (isset($this->parts['group']['fields'])) {
if (is_array($this->parts['group']['fields'])) {
$groupFields = [];
foreach ($this->parts['group']['fields'] as $field) {
$field = is_array($field) ? $field : [$field];
$column = isset($field[0]) ? $field[0] : false;
$type = isset($field[1]) ? $field[1] : '';
$groupFields[] = $this->protect($column).($type ? ' '.strtoupper($type) : '');
}
$group .= implode(', ', $groupFields);
} else {
$group .= $this->parts['group']['fields'];
}
}
if (isset($this->parts['group']['rollup']) && $this->parts['group']['rollup'] !== false) {
$group .= ' WITH ROLLUP';
}
return $group;
} | [
"private",
"function",
"parseGroup",
"(",
")",
"{",
"$",
"group",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'fields'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'fields'",
"]",
")",
")",
"{",
"$",
"groupFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'fields'",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"field",
"=",
"is_array",
"(",
"$",
"field",
")",
"?",
"$",
"field",
":",
"[",
"$",
"field",
"]",
";",
"$",
"column",
"=",
"isset",
"(",
"$",
"field",
"[",
"0",
"]",
")",
"?",
"$",
"field",
"[",
"0",
"]",
":",
"false",
";",
"$",
"type",
"=",
"isset",
"(",
"$",
"field",
"[",
"1",
"]",
")",
"?",
"$",
"field",
"[",
"1",
"]",
":",
"''",
";",
"$",
"groupFields",
"[",
"]",
"=",
"$",
"this",
"->",
"protect",
"(",
"$",
"column",
")",
".",
"(",
"$",
"type",
"?",
"' '",
".",
"strtoupper",
"(",
"$",
"type",
")",
":",
"''",
")",
";",
"}",
"$",
"group",
".=",
"implode",
"(",
"', '",
",",
"$",
"groupFields",
")",
";",
"}",
"else",
"{",
"$",
"group",
".=",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'fields'",
"]",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'rollup'",
"]",
")",
"&&",
"$",
"this",
"->",
"parts",
"[",
"'group'",
"]",
"[",
"'rollup'",
"]",
"!==",
"false",
")",
"{",
"$",
"group",
".=",
"' WITH ROLLUP'",
";",
"}",
"return",
"$",
"group",
";",
"}"
] | Parses GROUP entries
@uses $this->group['fields'] array with elements to group by
@return string | [
"Parses",
"GROUP",
"entries"
] | 186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4 | https://github.com/bytic/database/blob/186a7f1ae4fe2d8fa79acc34c06cfacd91488fa4/src/Query/Select.php#L307-L332 |
195 | Dragonrun1/event-mediator | src/AbstractContainerMediator.php | AbstractContainerMediator.addServiceListener | public function addServiceListener(string $eventName, array $listener, $priority = 0): ContainerMediatorInterface
{
$this->checkEventName($eventName);
$this->checkAllowedServiceListener($listener);
$priority = $this->getActualPriority($eventName, $priority);
if (\array_key_exists($eventName, $this->serviceListeners)
&& \array_key_exists($priority, $this->serviceListeners[$eventName])
&& \in_array($listener, $this->serviceListeners[$eventName][$priority], \true)
) {
return $this;
}
$this->serviceListeners[$eventName][$priority][] = $listener;
return $this;
} | php | public function addServiceListener(string $eventName, array $listener, $priority = 0): ContainerMediatorInterface
{
$this->checkEventName($eventName);
$this->checkAllowedServiceListener($listener);
$priority = $this->getActualPriority($eventName, $priority);
if (\array_key_exists($eventName, $this->serviceListeners)
&& \array_key_exists($priority, $this->serviceListeners[$eventName])
&& \in_array($listener, $this->serviceListeners[$eventName][$priority], \true)
) {
return $this;
}
$this->serviceListeners[$eventName][$priority][] = $listener;
return $this;
} | [
"public",
"function",
"addServiceListener",
"(",
"string",
"$",
"eventName",
",",
"array",
"$",
"listener",
",",
"$",
"priority",
"=",
"0",
")",
":",
"ContainerMediatorInterface",
"{",
"$",
"this",
"->",
"checkEventName",
"(",
"$",
"eventName",
")",
";",
"$",
"this",
"->",
"checkAllowedServiceListener",
"(",
"$",
"listener",
")",
";",
"$",
"priority",
"=",
"$",
"this",
"->",
"getActualPriority",
"(",
"$",
"eventName",
",",
"$",
"priority",
")",
";",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"serviceListeners",
")",
"&&",
"\\",
"array_key_exists",
"(",
"$",
"priority",
",",
"$",
"this",
"->",
"serviceListeners",
"[",
"$",
"eventName",
"]",
")",
"&&",
"\\",
"in_array",
"(",
"$",
"listener",
",",
"$",
"this",
"->",
"serviceListeners",
"[",
"$",
"eventName",
"]",
"[",
"$",
"priority",
"]",
",",
"\\",
"true",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"serviceListeners",
"[",
"$",
"eventName",
"]",
"[",
"$",
"priority",
"]",
"[",
"]",
"=",
"$",
"listener",
";",
"return",
"$",
"this",
";",
"}"
] | Add a service as an event listener.
@param string $eventName Name of the event the listener is being added for.
@param array $listener Listener to be added. ['containerID', 'method']
@param int|string $priority Priority level for the added listener.
@return ContainerMediatorInterface Fluent interface.
@throws \DomainException
@throws \InvalidArgumentException | [
"Add",
"a",
"service",
"as",
"an",
"event",
"listener",
"."
] | ff6d875440ce4da272ee509f7d47b5050e1eb7f5 | https://github.com/Dragonrun1/event-mediator/blob/ff6d875440ce4da272ee509f7d47b5050e1eb7f5/src/AbstractContainerMediator.php#L58-L71 |
196 | Dragonrun1/event-mediator | src/AbstractContainerMediator.php | AbstractContainerMediator.getServiceListeners | public function getServiceListeners(string $eventName = ''): array
{
$this->sortServiceListeners($eventName);
if ('' !== $eventName) {
return \array_key_exists($eventName, $this->serviceListeners) ? $this->serviceListeners[$eventName] : [];
}
return $this->serviceListeners;
} | php | public function getServiceListeners(string $eventName = ''): array
{
$this->sortServiceListeners($eventName);
if ('' !== $eventName) {
return \array_key_exists($eventName, $this->serviceListeners) ? $this->serviceListeners[$eventName] : [];
}
return $this->serviceListeners;
} | [
"public",
"function",
"getServiceListeners",
"(",
"string",
"$",
"eventName",
"=",
"''",
")",
":",
"array",
"{",
"$",
"this",
"->",
"sortServiceListeners",
"(",
"$",
"eventName",
")",
";",
"if",
"(",
"''",
"!==",
"$",
"eventName",
")",
"{",
"return",
"\\",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"serviceListeners",
")",
"?",
"$",
"this",
"->",
"serviceListeners",
"[",
"$",
"eventName",
"]",
":",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"serviceListeners",
";",
"}"
] | Get a list of service listeners for an event.
Note that if event name is empty all listeners will be returned. Any event subscribers are also included in the
list.
@param string $eventName Name of the event the list of service listeners is needed for.
@return array List of event service listeners or empty array if event is unknown or has no listeners or
subscribers.
@throws \InvalidArgumentException | [
"Get",
"a",
"list",
"of",
"service",
"listeners",
"for",
"an",
"event",
"."
] | ff6d875440ce4da272ee509f7d47b5050e1eb7f5 | https://github.com/Dragonrun1/event-mediator/blob/ff6d875440ce4da272ee509f7d47b5050e1eb7f5/src/AbstractContainerMediator.php#L142-L149 |
197 | Dragonrun1/event-mediator | src/AbstractContainerMediator.php | AbstractContainerMediator.removeServiceListener | public function removeServiceListener(string $eventName, array $listener, $priority = 0): ContainerMediatorInterface
{
$this->checkEventName($eventName);
if (!\array_key_exists($eventName, $this->serviceListeners)) {
return $this;
}
$this->checkAllowedServiceListener($listener);
if (\in_array($eventName, $this->loadedServices, \true)) {
$this->removeListener($eventName, [$this->getServiceByName($listener[0]), $listener[1]], $priority);
}
/**
* @var array $priorities
* @var int|string $atPriority
* @var array $listeners
*/
if ('last' !== $priority) {
$priorities = $this->serviceListeners[$eventName];
} else {
$priorities = \array_reverse($this->serviceListeners[$eventName], \true);
$priority = 'first';
}
$isIntPriority = \is_int($priority);
foreach ($priorities as $atPriority => $listeners) {
if ($isIntPriority && $priority !== $atPriority) {
continue;
}
$key = \array_search($listener, $listeners, \true);
if (\false !== $key) {
$this->bubbleUpUnsetServiceListener($eventName, $atPriority, $key);
if ('first' === $priority) {
break;
}
}
}
return $this;
} | php | public function removeServiceListener(string $eventName, array $listener, $priority = 0): ContainerMediatorInterface
{
$this->checkEventName($eventName);
if (!\array_key_exists($eventName, $this->serviceListeners)) {
return $this;
}
$this->checkAllowedServiceListener($listener);
if (\in_array($eventName, $this->loadedServices, \true)) {
$this->removeListener($eventName, [$this->getServiceByName($listener[0]), $listener[1]], $priority);
}
/**
* @var array $priorities
* @var int|string $atPriority
* @var array $listeners
*/
if ('last' !== $priority) {
$priorities = $this->serviceListeners[$eventName];
} else {
$priorities = \array_reverse($this->serviceListeners[$eventName], \true);
$priority = 'first';
}
$isIntPriority = \is_int($priority);
foreach ($priorities as $atPriority => $listeners) {
if ($isIntPriority && $priority !== $atPriority) {
continue;
}
$key = \array_search($listener, $listeners, \true);
if (\false !== $key) {
$this->bubbleUpUnsetServiceListener($eventName, $atPriority, $key);
if ('first' === $priority) {
break;
}
}
}
return $this;
} | [
"public",
"function",
"removeServiceListener",
"(",
"string",
"$",
"eventName",
",",
"array",
"$",
"listener",
",",
"$",
"priority",
"=",
"0",
")",
":",
"ContainerMediatorInterface",
"{",
"$",
"this",
"->",
"checkEventName",
"(",
"$",
"eventName",
")",
";",
"if",
"(",
"!",
"\\",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"serviceListeners",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"checkAllowedServiceListener",
"(",
"$",
"listener",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"loadedServices",
",",
"\\",
"true",
")",
")",
"{",
"$",
"this",
"->",
"removeListener",
"(",
"$",
"eventName",
",",
"[",
"$",
"this",
"->",
"getServiceByName",
"(",
"$",
"listener",
"[",
"0",
"]",
")",
",",
"$",
"listener",
"[",
"1",
"]",
"]",
",",
"$",
"priority",
")",
";",
"}",
"/**\n * @var array $priorities\n * @var int|string $atPriority\n * @var array $listeners\n */",
"if",
"(",
"'last'",
"!==",
"$",
"priority",
")",
"{",
"$",
"priorities",
"=",
"$",
"this",
"->",
"serviceListeners",
"[",
"$",
"eventName",
"]",
";",
"}",
"else",
"{",
"$",
"priorities",
"=",
"\\",
"array_reverse",
"(",
"$",
"this",
"->",
"serviceListeners",
"[",
"$",
"eventName",
"]",
",",
"\\",
"true",
")",
";",
"$",
"priority",
"=",
"'first'",
";",
"}",
"$",
"isIntPriority",
"=",
"\\",
"is_int",
"(",
"$",
"priority",
")",
";",
"foreach",
"(",
"$",
"priorities",
"as",
"$",
"atPriority",
"=>",
"$",
"listeners",
")",
"{",
"if",
"(",
"$",
"isIntPriority",
"&&",
"$",
"priority",
"!==",
"$",
"atPriority",
")",
"{",
"continue",
";",
"}",
"$",
"key",
"=",
"\\",
"array_search",
"(",
"$",
"listener",
",",
"$",
"listeners",
",",
"\\",
"true",
")",
";",
"if",
"(",
"\\",
"false",
"!==",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"bubbleUpUnsetServiceListener",
"(",
"$",
"eventName",
",",
"$",
"atPriority",
",",
"$",
"key",
")",
";",
"if",
"(",
"'first'",
"===",
"$",
"priority",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove a service as an event listener.
@param string $eventName Event name that listener is being removed from.
@param array $listener Service listener to be removed.
@param int|string $priority Priority level for the to be removed listener.
@return ContainerMediatorInterface Fluent interface.
@throws \DomainException
@throws \InvalidArgumentException | [
"Remove",
"a",
"service",
"as",
"an",
"event",
"listener",
"."
] | ff6d875440ce4da272ee509f7d47b5050e1eb7f5 | https://github.com/Dragonrun1/event-mediator/blob/ff6d875440ce4da272ee509f7d47b5050e1eb7f5/src/AbstractContainerMediator.php#L161-L196 |
198 | artscorestudio/layout-bundle | DependencyInjection/ASFLayoutExtension.php | ASFLayoutExtension.configureAsseticBundle | public function configureAsseticBundle(ContainerBuilder $container, array $config)
{
foreach (array_keys($container->getExtensions()) as $name) {
switch ($name) {
case 'assetic':
// Add jQuery in assets
$this->addJqueryInAssetic($container, $config['assets']['jquery']);
// Add Twitter Bootstrap assets
$this->addTwbsInAssetic($container, $config['assets']['twbs']);
// Add jQuery UI in assets
if (isset($config['assets']['jqueryui'])) {
$this->addJqueryUIInAssetic($container, $config['assets']['jqueryui']);
}
// Add select2 files
if (isset($config['assets']['select2'])) {
$this->addSelect2InAssetic($container, $config['assets']['select2']);
}
// Add Basinga js translation in assets
if (isset($config['assets']['bazinga_js_translation'])) {
$this->addBazingaJsTranslationInAssetic($container, $config['assets']['bazinga_js_translation']);
}
// Add Speaking URL in assets
if (isset($config['assets']['speakingurl'])) {
$this->addSpeakingURLInAssetic($container, $config['assets']['speakingurl']);
}
// Add TinyMCE in assets
if (isset($config['assets']['tinymce'])) {
$this->addTinyMCEInAssetic($container, $config['assets']['tinymce']);
}
// Add jQueryTagsInput in assets
if (isset($config['assets']['jquery_tags_input'])) {
$this->addJqueryTagsInputInAssetic($container, $config['assets']['jquery_tags_input']);
}
// Add PrismJS in assets
if (isset($config['assets']['prism_js'])) {
$this->addPrismJSInAssetic($container, $config['assets']['prism_js']);
}
break;
}
}
} | php | public function configureAsseticBundle(ContainerBuilder $container, array $config)
{
foreach (array_keys($container->getExtensions()) as $name) {
switch ($name) {
case 'assetic':
// Add jQuery in assets
$this->addJqueryInAssetic($container, $config['assets']['jquery']);
// Add Twitter Bootstrap assets
$this->addTwbsInAssetic($container, $config['assets']['twbs']);
// Add jQuery UI in assets
if (isset($config['assets']['jqueryui'])) {
$this->addJqueryUIInAssetic($container, $config['assets']['jqueryui']);
}
// Add select2 files
if (isset($config['assets']['select2'])) {
$this->addSelect2InAssetic($container, $config['assets']['select2']);
}
// Add Basinga js translation in assets
if (isset($config['assets']['bazinga_js_translation'])) {
$this->addBazingaJsTranslationInAssetic($container, $config['assets']['bazinga_js_translation']);
}
// Add Speaking URL in assets
if (isset($config['assets']['speakingurl'])) {
$this->addSpeakingURLInAssetic($container, $config['assets']['speakingurl']);
}
// Add TinyMCE in assets
if (isset($config['assets']['tinymce'])) {
$this->addTinyMCEInAssetic($container, $config['assets']['tinymce']);
}
// Add jQueryTagsInput in assets
if (isset($config['assets']['jquery_tags_input'])) {
$this->addJqueryTagsInputInAssetic($container, $config['assets']['jquery_tags_input']);
}
// Add PrismJS in assets
if (isset($config['assets']['prism_js'])) {
$this->addPrismJSInAssetic($container, $config['assets']['prism_js']);
}
break;
}
}
} | [
"public",
"function",
"configureAsseticBundle",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"container",
"->",
"getExtensions",
"(",
")",
")",
"as",
"$",
"name",
")",
"{",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'assetic'",
":",
"// Add jQuery in assets",
"$",
"this",
"->",
"addJqueryInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'jquery'",
"]",
")",
";",
"// Add Twitter Bootstrap assets",
"$",
"this",
"->",
"addTwbsInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'twbs'",
"]",
")",
";",
"// Add jQuery UI in assets",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'jqueryui'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addJqueryUIInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'jqueryui'",
"]",
")",
";",
"}",
"// Add select2 files",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'select2'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addSelect2InAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'select2'",
"]",
")",
";",
"}",
"// Add Basinga js translation in assets",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'bazinga_js_translation'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addBazingaJsTranslationInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'bazinga_js_translation'",
"]",
")",
";",
"}",
"// Add Speaking URL in assets",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'speakingurl'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addSpeakingURLInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'speakingurl'",
"]",
")",
";",
"}",
"// Add TinyMCE in assets",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'tinymce'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addTinyMCEInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'tinymce'",
"]",
")",
";",
"}",
"// Add jQueryTagsInput in assets",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'jquery_tags_input'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addJqueryTagsInputInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'jquery_tags_input'",
"]",
")",
";",
"}",
"// Add PrismJS in assets",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'prism_js'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addPrismJSInAssetic",
"(",
"$",
"container",
",",
"$",
"config",
"[",
"'assets'",
"]",
"[",
"'prism_js'",
"]",
")",
";",
"}",
"break",
";",
"}",
"}",
"}"
] | Add assets to Assetic Bundle.
@param ContainerBuilder $container
@param array $config | [
"Add",
"assets",
"to",
"Assetic",
"Bundle",
"."
] | 5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740 | https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L103-L151 |
199 | artscorestudio/layout-bundle | DependencyInjection/ASFLayoutExtension.php | ASFLayoutExtension.addJqueryUIInAssetic | protected function addJqueryUIInAssetic(ContainerBuilder $container, array $config)
{
if ($config['js'] !== false && $config['css'] !== false) {
$container->prependExtensionConfig('assetic', array(
'assets' => array(
'jqueryui_js' => $config['js'],
'jqueryui_css' => $config['css'],
),
));
} elseif ($config['js'] === false && $config['css'] !== false) {
throw new InvalidConfigurationException('You have enabled jQuery UI supports but js parameter is missing.');
} elseif ($config['js'] !== false && $config['css'] === false) {
throw new InvalidConfigurationException('You have enabled jQuery UI supports but css parameter is missing.');
}
} | php | protected function addJqueryUIInAssetic(ContainerBuilder $container, array $config)
{
if ($config['js'] !== false && $config['css'] !== false) {
$container->prependExtensionConfig('assetic', array(
'assets' => array(
'jqueryui_js' => $config['js'],
'jqueryui_css' => $config['css'],
),
));
} elseif ($config['js'] === false && $config['css'] !== false) {
throw new InvalidConfigurationException('You have enabled jQuery UI supports but js parameter is missing.');
} elseif ($config['js'] !== false && $config['css'] === false) {
throw new InvalidConfigurationException('You have enabled jQuery UI supports but css parameter is missing.');
}
} | [
"protected",
"function",
"addJqueryUIInAssetic",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"config",
"[",
"'js'",
"]",
"!==",
"false",
"&&",
"$",
"config",
"[",
"'css'",
"]",
"!==",
"false",
")",
"{",
"$",
"container",
"->",
"prependExtensionConfig",
"(",
"'assetic'",
",",
"array",
"(",
"'assets'",
"=>",
"array",
"(",
"'jqueryui_js'",
"=>",
"$",
"config",
"[",
"'js'",
"]",
",",
"'jqueryui_css'",
"=>",
"$",
"config",
"[",
"'css'",
"]",
",",
")",
",",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"config",
"[",
"'js'",
"]",
"===",
"false",
"&&",
"$",
"config",
"[",
"'css'",
"]",
"!==",
"false",
")",
"{",
"throw",
"new",
"InvalidConfigurationException",
"(",
"'You have enabled jQuery UI supports but js parameter is missing.'",
")",
";",
"}",
"elseif",
"(",
"$",
"config",
"[",
"'js'",
"]",
"!==",
"false",
"&&",
"$",
"config",
"[",
"'css'",
"]",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidConfigurationException",
"(",
"'You have enabled jQuery UI supports but css parameter is missing.'",
")",
";",
"}",
"}"
] | Adding jQuery UI in Assetic.
@param ContainerBuilder $container
@param array $config
@throws InvalidConfigurationException : "Js path not set or CSS path not set" | [
"Adding",
"jQuery",
"UI",
"in",
"Assetic",
"."
] | 5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740 | https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/DependencyInjection/ASFLayoutExtension.php#L178-L192 |