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 list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
29,200 | rosasurfer/ministruts | src/cache/FileSystemCache.php | FileSystemCache.isCached | public function isCached($key) {
// Hier wird die eigentliche Arbeit gemacht. Die Methode prueft nicht nur, ob der Wert im Cache
// existiert, sondern speichert ihn auch im lokalen ReferencePool. Folgende Abfragen muessen so
// nicht ein weiteres Mal auf den Cache zugreifen, sondern koennen aus dem lokalen Pool bedient
// werden.
// ReferencePool abfragen
if ($this->getReferencePool()->isCached($key)) {
return true;
}
else {
// Datei suchen und auslesen
$file = $this->getFilePath($key);
$data = $this->readFile($file);
if (!$data) // Cache-Miss
return false;
// Cache-Hit, $data Format: array(created, $expires, $value, $dependency)
$created = $data[0];
$expires = $data[1];
$value = $data[2];
$dependency = $data[3];
// expires pruefen
if ($expires && $created+$expires < time()) {
$this->drop($key);
return false;
}
// Dependency pruefen
if ($dependency) {
$minValid = $dependency->getMinValidity();
if ($minValid) {
if (time() > $created+$minValid) {
if (!$dependency->isValid()) {
$this->drop($key);
return false;
}
// created aktualisieren (Wert praktisch neu in den Cache schreiben)
return $this->set($key, $value, $expires, $dependency);
}
}
elseif (!$dependency->isValid()) {
$this->drop($key);
return false;
}
}
// ok, Wert im ReferencePool speichern
$this->getReferencePool()->set($key, $value, Cache::EXPIRES_NEVER, $dependency);
return true;
}
} | php | public function isCached($key) {
// Hier wird die eigentliche Arbeit gemacht. Die Methode prueft nicht nur, ob der Wert im Cache
// existiert, sondern speichert ihn auch im lokalen ReferencePool. Folgende Abfragen muessen so
// nicht ein weiteres Mal auf den Cache zugreifen, sondern koennen aus dem lokalen Pool bedient
// werden.
// ReferencePool abfragen
if ($this->getReferencePool()->isCached($key)) {
return true;
}
else {
// Datei suchen und auslesen
$file = $this->getFilePath($key);
$data = $this->readFile($file);
if (!$data) // Cache-Miss
return false;
// Cache-Hit, $data Format: array(created, $expires, $value, $dependency)
$created = $data[0];
$expires = $data[1];
$value = $data[2];
$dependency = $data[3];
// expires pruefen
if ($expires && $created+$expires < time()) {
$this->drop($key);
return false;
}
// Dependency pruefen
if ($dependency) {
$minValid = $dependency->getMinValidity();
if ($minValid) {
if (time() > $created+$minValid) {
if (!$dependency->isValid()) {
$this->drop($key);
return false;
}
// created aktualisieren (Wert praktisch neu in den Cache schreiben)
return $this->set($key, $value, $expires, $dependency);
}
}
elseif (!$dependency->isValid()) {
$this->drop($key);
return false;
}
}
// ok, Wert im ReferencePool speichern
$this->getReferencePool()->set($key, $value, Cache::EXPIRES_NEVER, $dependency);
return true;
}
} | [
"public",
"function",
"isCached",
"(",
"$",
"key",
")",
"{",
"// Hier wird die eigentliche Arbeit gemacht. Die Methode prueft nicht nur, ob der Wert im Cache",
"// existiert, sondern speichert ihn auch im lokalen ReferencePool. Folgende Abfragen muessen so",
"// nicht ein weiteres Mal auf den Cache zugreifen, sondern koennen aus dem lokalen Pool bedient",
"// werden.",
"// ReferencePool abfragen",
"if",
"(",
"$",
"this",
"->",
"getReferencePool",
"(",
")",
"->",
"isCached",
"(",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"// Datei suchen und auslesen",
"$",
"file",
"=",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"key",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"readFile",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"data",
")",
"// Cache-Miss",
"return",
"false",
";",
"// Cache-Hit, $data Format: array(created, $expires, $value, $dependency)",
"$",
"created",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"expires",
"=",
"$",
"data",
"[",
"1",
"]",
";",
"$",
"value",
"=",
"$",
"data",
"[",
"2",
"]",
";",
"$",
"dependency",
"=",
"$",
"data",
"[",
"3",
"]",
";",
"// expires pruefen",
"if",
"(",
"$",
"expires",
"&&",
"$",
"created",
"+",
"$",
"expires",
"<",
"time",
"(",
")",
")",
"{",
"$",
"this",
"->",
"drop",
"(",
"$",
"key",
")",
";",
"return",
"false",
";",
"}",
"// Dependency pruefen",
"if",
"(",
"$",
"dependency",
")",
"{",
"$",
"minValid",
"=",
"$",
"dependency",
"->",
"getMinValidity",
"(",
")",
";",
"if",
"(",
"$",
"minValid",
")",
"{",
"if",
"(",
"time",
"(",
")",
">",
"$",
"created",
"+",
"$",
"minValid",
")",
"{",
"if",
"(",
"!",
"$",
"dependency",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"drop",
"(",
"$",
"key",
")",
";",
"return",
"false",
";",
"}",
"// created aktualisieren (Wert praktisch neu in den Cache schreiben)",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expires",
",",
"$",
"dependency",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"dependency",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"drop",
"(",
"$",
"key",
")",
";",
"return",
"false",
";",
"}",
"}",
"// ok, Wert im ReferencePool speichern",
"$",
"this",
"->",
"getReferencePool",
"(",
")",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"Cache",
"::",
"EXPIRES_NEVER",
",",
"$",
"dependency",
")",
";",
"return",
"true",
";",
"}",
"}"
] | Ob unter dem angegebenen Schluessel ein Wert im Cache gespeichert ist.
@param string $key - Schluessel
@return bool | [
"Ob",
"unter",
"dem",
"angegebenen",
"Schluessel",
"ein",
"Wert",
"im",
"Cache",
"gespeichert",
"ist",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/cache/FileSystemCache.php#L69-L122 |
29,201 | rosasurfer/ministruts | src/cache/FileSystemCache.php | FileSystemCache.get | public function get($key, $default = null) {
if ($this->isCached($key))
return $this->getReferencePool()->get($key);
return $default;
} | php | public function get($key, $default = null) {
if ($this->isCached($key))
return $this->getReferencePool()->get($key);
return $default;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCached",
"(",
"$",
"key",
")",
")",
"return",
"$",
"this",
"->",
"getReferencePool",
"(",
")",
"->",
"get",
"(",
"$",
"key",
")",
";",
"return",
"$",
"default",
";",
"}"
] | Gibt einen Wert aus dem Cache zurueck. Existiert der Wert nicht, wird der angegebene Defaultwert
zurueckgegeben.
@param string $key - Schluessel, unter dem der Wert gespeichert ist
@param mixed $default [optional] - Defaultwert (kann selbst auch NULL sein)
@return mixed - Der gespeicherte Wert oder NULL, falls kein solcher Schluessel existiert.
Achtung: Ist im Cache ein NULL-Wert gespeichert, wird ebenfalls NULL zurueckgegeben. | [
"Gibt",
"einen",
"Wert",
"aus",
"dem",
"Cache",
"zurueck",
".",
"Existiert",
"der",
"Wert",
"nicht",
"wird",
"der",
"angegebene",
"Defaultwert",
"zurueckgegeben",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/cache/FileSystemCache.php#L135-L140 |
29,202 | rosasurfer/ministruts | src/cache/FileSystemCache.php | FileSystemCache.getFilePath | private function getFilePath($key) {
$key = md5($key);
return $this->directory.$key[0].DIRECTORY_SEPARATOR.$key[1].DIRECTORY_SEPARATOR.substr($key, 2);
} | php | private function getFilePath($key) {
$key = md5($key);
return $this->directory.$key[0].DIRECTORY_SEPARATOR.$key[1].DIRECTORY_SEPARATOR.substr($key, 2);
} | [
"private",
"function",
"getFilePath",
"(",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"directory",
".",
"$",
"key",
"[",
"0",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"key",
"[",
"1",
"]",
".",
"DIRECTORY_SEPARATOR",
".",
"substr",
"(",
"$",
"key",
",",
"2",
")",
";",
"}"
] | Gibt den vollstaendigen Pfad zur Cache-Datei fuer den angegebenen Schluessel zurueck.
@param string $key - Schluessel des Wertes
@return string - Dateipfad | [
"Gibt",
"den",
"vollstaendigen",
"Pfad",
"zur",
"Cache",
"-",
"Datei",
"fuer",
"den",
"angegebenen",
"Schluessel",
"zurueck",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/cache/FileSystemCache.php#L202-L205 |
29,203 | rosasurfer/ministruts | src/cache/FileSystemCache.php | FileSystemCache.readFile | private function readFile($fileName) {
try {
$data = file_get_contents($fileName, false);
}
catch (PHPError $ex) {
if (strEndsWith($ex->getMessage(), 'failed to open stream: No such file or directory'))
return null;
throw $ex;
}
if ($data === false)
throw new RuntimeException('file_get_contents() returned FALSE, $fileName: "'.$fileName);
return unserialize($data);
} | php | private function readFile($fileName) {
try {
$data = file_get_contents($fileName, false);
}
catch (PHPError $ex) {
if (strEndsWith($ex->getMessage(), 'failed to open stream: No such file or directory'))
return null;
throw $ex;
}
if ($data === false)
throw new RuntimeException('file_get_contents() returned FALSE, $fileName: "'.$fileName);
return unserialize($data);
} | [
"private",
"function",
"readFile",
"(",
"$",
"fileName",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"fileName",
",",
"false",
")",
";",
"}",
"catch",
"(",
"PHPError",
"$",
"ex",
")",
"{",
"if",
"(",
"strEndsWith",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"'failed to open stream: No such file or directory'",
")",
")",
"return",
"null",
";",
"throw",
"$",
"ex",
";",
"}",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"throw",
"new",
"RuntimeException",
"(",
"'file_get_contents() returned FALSE, $fileName: \"'",
".",
"$",
"fileName",
")",
";",
"return",
"unserialize",
"(",
"$",
"data",
")",
";",
"}"
] | Liest die Datei mit dem angegebenen Namen ein und gibt den deserialisierten Inhalt zurueck.
@param string $fileName - vollstaendiger Dateiname
@return mixed - Wert | [
"Liest",
"die",
"Datei",
"mit",
"dem",
"angegebenen",
"Namen",
"ein",
"und",
"gibt",
"den",
"deserialisierten",
"Inhalt",
"zurueck",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/cache/FileSystemCache.php#L215-L229 |
29,204 | rosasurfer/ministruts | src/cache/FileSystemCache.php | FileSystemCache.writeFile | private function writeFile($fileName, $value, $expires) {
FS::mkDir(dirname($fileName));
file_put_contents($fileName, serialize($value));
// TODO: http://phpdevblog.niknovo.com/2009/11/serialize-vs-var-export-vs-json-encode.html
return true;
} | php | private function writeFile($fileName, $value, $expires) {
FS::mkDir(dirname($fileName));
file_put_contents($fileName, serialize($value));
// TODO: http://phpdevblog.niknovo.com/2009/11/serialize-vs-var-export-vs-json-encode.html
return true;
} | [
"private",
"function",
"writeFile",
"(",
"$",
"fileName",
",",
"$",
"value",
",",
"$",
"expires",
")",
"{",
"FS",
"::",
"mkDir",
"(",
"dirname",
"(",
"$",
"fileName",
")",
")",
";",
"file_put_contents",
"(",
"$",
"fileName",
",",
"serialize",
"(",
"$",
"value",
")",
")",
";",
"// TODO: http://phpdevblog.niknovo.com/2009/11/serialize-vs-var-export-vs-json-encode.html",
"return",
"true",
";",
"}"
] | Schreibt den angegebenen Wert in die Datei mit dem angegebenen Namen.
@param string $fileName - vollstaendiger Dateiname
@param mixed $value - der in die Datei zu schreibende Wert
@return bool - TRUE bei Erfolg, FALSE andererseits | [
"Schreibt",
"den",
"angegebenen",
"Wert",
"in",
"die",
"Datei",
"mit",
"dem",
"angegebenen",
"Namen",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/cache/FileSystemCache.php#L240-L246 |
29,205 | timble/kodekit | code/command/chain/chain.php | CommandChain.addHandler | public function addHandler(CommandHandlerInterface $handler)
{
$this->__queue->enqueue($handler, $handler->getPriority());
return $this;
} | php | public function addHandler(CommandHandlerInterface $handler)
{
$this->__queue->enqueue($handler, $handler->getPriority());
return $this;
} | [
"public",
"function",
"addHandler",
"(",
"CommandHandlerInterface",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"__queue",
"->",
"enqueue",
"(",
"$",
"handler",
",",
"$",
"handler",
"->",
"getPriority",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Attach a command handler to the chain
@param CommandHandlerInterface $handler The command handler
@return CommandChain | [
"Attach",
"a",
"command",
"handler",
"to",
"the",
"chain"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/command/chain/chain.php#L149-L153 |
29,206 | timble/kodekit | code/command/chain/chain.php | CommandChain.setHandlerPriority | public function setHandlerPriority(CommandHandlerInterface $handler, $priority)
{
$this->__queue->setPriority($handler, $priority);
return $this;
} | php | public function setHandlerPriority(CommandHandlerInterface $handler, $priority)
{
$this->__queue->setPriority($handler, $priority);
return $this;
} | [
"public",
"function",
"setHandlerPriority",
"(",
"CommandHandlerInterface",
"$",
"handler",
",",
"$",
"priority",
")",
"{",
"$",
"this",
"->",
"__queue",
"->",
"setPriority",
"(",
"$",
"handler",
",",
"$",
"priority",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the priority of a command handler
@param CommandHandlerInterface $handler A command handler
@param integer $priority The command priority
@return CommandChain | [
"Set",
"the",
"priority",
"of",
"a",
"command",
"handler"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/command/chain/chain.php#L184-L188 |
29,207 | rosasurfer/ministruts | src/db/orm/Worker.php | Worker.find | public function find($query, $allowMany = false) { // TODO: numRows() is not available on SQLite or with PDO and the
$result = $this->query($query); // emulation is slow. The check can be improved with fetchRow()
// when reset(-1) and internal record caching are implemented.
$object = $this->makeObject($result); //
if ($object && !$allowMany && $result->numRows() > 1) throw new MultipleRecordsException($query);
return $object;
} | php | public function find($query, $allowMany = false) { // TODO: numRows() is not available on SQLite or with PDO and the
$result = $this->query($query); // emulation is slow. The check can be improved with fetchRow()
// when reset(-1) and internal record caching are implemented.
$object = $this->makeObject($result); //
if ($object && !$allowMany && $result->numRows() > 1) throw new MultipleRecordsException($query);
return $object;
} | [
"public",
"function",
"find",
"(",
"$",
"query",
",",
"$",
"allowMany",
"=",
"false",
")",
"{",
"// TODO: numRows() is not available on SQLite or with PDO and the",
"$",
"result",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"query",
")",
";",
"// emulation is slow. The check can be improved with fetchRow()",
"// when reset(-1) and internal record caching are implemented.",
"$",
"object",
"=",
"$",
"this",
"->",
"makeObject",
"(",
"$",
"result",
")",
";",
"//",
"if",
"(",
"$",
"object",
"&&",
"!",
"$",
"allowMany",
"&&",
"$",
"result",
"->",
"numRows",
"(",
")",
">",
"1",
")",
"throw",
"new",
"MultipleRecordsException",
"(",
"$",
"query",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Find a single matching record and convert it to an instance of the entity class.
@param string $query - SQL query with optional ORM syntax
@param bool $allowMany [optional] - whether the query is allowed to return a multi-row result (default: no)
@return PersistableObject|null
@throws MultipleRecordsException if the query returned multiple rows and $allowMany was not set to TRUE. | [
"Find",
"a",
"single",
"matching",
"record",
"and",
"convert",
"it",
"to",
"an",
"instance",
"of",
"the",
"entity",
"class",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/Worker.php#L56-L63 |
29,208 | rosasurfer/ministruts | src/db/orm/Worker.php | Worker.translateQuery | private function translateQuery($sql) {
// model name pattern: ":User" => "t_user" (will also convert matching names in literals and comments)
$pattern = '/[^:]:([a-z_]\w*)\b/i';
if (preg_match_all($pattern, $sql, $matches, PREG_OFFSET_CAPTURE)) {
$namespace = strLeftTo($this->entityClass, '\\', -1, true, '');
foreach (\array_reverse($matches[1]) as $match) {
$modelName = $match[0];
$offset = $match[1];
$className = $namespace.$modelName;
if (is_a($className, PersistableObject::class, true)) {
/** @var DAO $dao */
$dao = $className::dao();
$table = $dao->getMapping()['table'];
$sql = substr_replace($sql, $table, $offset-1, strlen($modelName)+1);
}
}
}
return $sql;
} | php | private function translateQuery($sql) {
// model name pattern: ":User" => "t_user" (will also convert matching names in literals and comments)
$pattern = '/[^:]:([a-z_]\w*)\b/i';
if (preg_match_all($pattern, $sql, $matches, PREG_OFFSET_CAPTURE)) {
$namespace = strLeftTo($this->entityClass, '\\', -1, true, '');
foreach (\array_reverse($matches[1]) as $match) {
$modelName = $match[0];
$offset = $match[1];
$className = $namespace.$modelName;
if (is_a($className, PersistableObject::class, true)) {
/** @var DAO $dao */
$dao = $className::dao();
$table = $dao->getMapping()['table'];
$sql = substr_replace($sql, $table, $offset-1, strlen($modelName)+1);
}
}
}
return $sql;
} | [
"private",
"function",
"translateQuery",
"(",
"$",
"sql",
")",
"{",
"// model name pattern: \":User\" => \"t_user\" (will also convert matching names in literals and comments)",
"$",
"pattern",
"=",
"'/[^:]:([a-z_]\\w*)\\b/i'",
";",
"if",
"(",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"sql",
",",
"$",
"matches",
",",
"PREG_OFFSET_CAPTURE",
")",
")",
"{",
"$",
"namespace",
"=",
"strLeftTo",
"(",
"$",
"this",
"->",
"entityClass",
",",
"'\\\\'",
",",
"-",
"1",
",",
"true",
",",
"''",
")",
";",
"foreach",
"(",
"\\",
"array_reverse",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"as",
"$",
"match",
")",
"{",
"$",
"modelName",
"=",
"$",
"match",
"[",
"0",
"]",
";",
"$",
"offset",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"$",
"className",
"=",
"$",
"namespace",
".",
"$",
"modelName",
";",
"if",
"(",
"is_a",
"(",
"$",
"className",
",",
"PersistableObject",
"::",
"class",
",",
"true",
")",
")",
"{",
"/** @var DAO $dao */",
"$",
"dao",
"=",
"$",
"className",
"::",
"dao",
"(",
")",
";",
"$",
"table",
"=",
"$",
"dao",
"->",
"getMapping",
"(",
")",
"[",
"'table'",
"]",
";",
"$",
"sql",
"=",
"substr_replace",
"(",
"$",
"sql",
",",
"$",
"table",
",",
"$",
"offset",
"-",
"1",
",",
"strlen",
"(",
"$",
"modelName",
")",
"+",
"1",
")",
";",
"}",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | Translate entity names in a SQL query into their DBMS table counterparts. At the moment this translation requires all
entity classes to be in the same namespace as the worker's entity class.
@param string $sql - original SQL query
@return string - translated SQL query | [
"Translate",
"entity",
"names",
"in",
"a",
"SQL",
"query",
"into",
"their",
"DBMS",
"table",
"counterparts",
".",
"At",
"the",
"moment",
"this",
"translation",
"requires",
"all",
"entity",
"classes",
"to",
"be",
"in",
"the",
"same",
"namespace",
"as",
"the",
"worker",
"s",
"entity",
"class",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/Worker.php#L115-L134 |
29,209 | rosasurfer/ministruts | src/db/orm/Worker.php | Worker.makeObject | protected function makeObject(IResult $result) {
// TODO: Prefer to return existing instance from IdentityMap
$row = $result->fetchRow(ARRAY_ASSOC);
if ($row === null)
return null;
return PersistableObject::populateNew($this->entityClass, $row);
} | php | protected function makeObject(IResult $result) {
// TODO: Prefer to return existing instance from IdentityMap
$row = $result->fetchRow(ARRAY_ASSOC);
if ($row === null)
return null;
return PersistableObject::populateNew($this->entityClass, $row);
} | [
"protected",
"function",
"makeObject",
"(",
"IResult",
"$",
"result",
")",
"{",
"// TODO: Prefer to return existing instance from IdentityMap",
"$",
"row",
"=",
"$",
"result",
"->",
"fetchRow",
"(",
"ARRAY_ASSOC",
")",
";",
"if",
"(",
"$",
"row",
"===",
"null",
")",
"return",
"null",
";",
"return",
"PersistableObject",
"::",
"populateNew",
"(",
"$",
"this",
"->",
"entityClass",
",",
"$",
"row",
")",
";",
"}"
] | Convert the next row of a result to an object of the model class.
@param IResult $result
@return PersistableObject|null - instance or NULL if the result doesn't hold any more rows | [
"Convert",
"the",
"next",
"row",
"of",
"a",
"result",
"to",
"an",
"object",
"of",
"the",
"model",
"class",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/Worker.php#L144-L152 |
29,210 | rosasurfer/ministruts | src/db/orm/Worker.php | Worker.makeObjects | protected function makeObjects(IResult $result) {
// TODO: Prefer to return existing instances from IdentityMap
$instances = [];
while ($row = $result->fetchRow(ARRAY_ASSOC)) {
$instances[] = PersistableObject::populateNew($this->entityClass, $row);
}
return $instances;
} | php | protected function makeObjects(IResult $result) {
// TODO: Prefer to return existing instances from IdentityMap
$instances = [];
while ($row = $result->fetchRow(ARRAY_ASSOC)) {
$instances[] = PersistableObject::populateNew($this->entityClass, $row);
}
return $instances;
} | [
"protected",
"function",
"makeObjects",
"(",
"IResult",
"$",
"result",
")",
"{",
"// TODO: Prefer to return existing instances from IdentityMap",
"$",
"instances",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"result",
"->",
"fetchRow",
"(",
"ARRAY_ASSOC",
")",
")",
"{",
"$",
"instances",
"[",
"]",
"=",
"PersistableObject",
"::",
"populateNew",
"(",
"$",
"this",
"->",
"entityClass",
",",
"$",
"row",
")",
";",
"}",
"return",
"$",
"instances",
";",
"}"
] | Convert all remaining rows of a result to objects of the model class.
@param IResult $result
@return PersistableObject[] - array of instances or an empty array if the result doesn't hold any more rows | [
"Convert",
"all",
"remaining",
"rows",
"of",
"a",
"result",
"to",
"objects",
"of",
"the",
"model",
"class",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/Worker.php#L162-L171 |
29,211 | rosasurfer/ministruts | src/db/orm/Worker.php | Worker.getConnector | public function getConnector() {
if (!$this->connector) {
$mapping = $this->dao->getMapping();
$this->connector = ConnectionPool::getConnector($mapping['connection']);
}
return $this->connector;
} | php | public function getConnector() {
if (!$this->connector) {
$mapping = $this->dao->getMapping();
$this->connector = ConnectionPool::getConnector($mapping['connection']);
}
return $this->connector;
} | [
"public",
"function",
"getConnector",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"connector",
")",
"{",
"$",
"mapping",
"=",
"$",
"this",
"->",
"dao",
"->",
"getMapping",
"(",
")",
";",
"$",
"this",
"->",
"connector",
"=",
"ConnectionPool",
"::",
"getConnector",
"(",
"$",
"mapping",
"[",
"'connection'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"connector",
";",
"}"
] | Return the database adapter of the Worker's model class.
@return IConnector | [
"Return",
"the",
"database",
"adapter",
"of",
"the",
"Worker",
"s",
"model",
"class",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/Worker.php#L179-L185 |
29,212 | nicebooks-com/isbn | src/Internal/RangeService.php | RangeService.getRangeInfo | public static function getRangeInfo(string $isbn) : ?RangeInfo
{
$length = strlen($isbn);
$isbnPrefix = ($length === 10) ? '978' : substr($isbn, 0, 3);
$isbnDigits = ($length === 10) ? $isbn : substr($isbn, 3);
foreach (self::getRanges() as $rangeData) {
list ($eanPrefix, $groupIdentifier, $groupName, $ranges) = $rangeData;
if ($isbnPrefix !== $eanPrefix) {
continue;
}
$groupLength = strlen($groupIdentifier);
$isbnGroup = substr($isbnDigits, 0, $groupLength);
if ($isbnGroup !== $groupIdentifier) {
continue;
}
$rangeInfo = new RangeInfo;
$rangeInfo->groupIdentifier = ($length === 10 ? $groupIdentifier : $eanPrefix . '-' . $groupIdentifier);
$rangeInfo->groupName = $groupName;
foreach ($ranges as $range) {
list ($rangeLength, $rangeStart, $rangeEnd) = $range;
$rangeValue = substr($isbnDigits, $groupLength, $rangeLength);
$lastDigits = substr($isbnDigits, $groupLength + $rangeLength, -1);
$checkDigit = substr($isbnDigits, -1);
if (strcmp($rangeValue, $rangeStart) >= 0 && strcmp($rangeValue, $rangeEnd) <= 0) {
if ($length === 13) {
$rangeInfo->parts = [$isbnPrefix, $isbnGroup, $rangeValue, $lastDigits, $checkDigit];
} else {
$rangeInfo->parts = [$isbnGroup, $rangeValue, $lastDigits, $checkDigit];
}
break;
}
}
return $rangeInfo;
}
return null;
} | php | public static function getRangeInfo(string $isbn) : ?RangeInfo
{
$length = strlen($isbn);
$isbnPrefix = ($length === 10) ? '978' : substr($isbn, 0, 3);
$isbnDigits = ($length === 10) ? $isbn : substr($isbn, 3);
foreach (self::getRanges() as $rangeData) {
list ($eanPrefix, $groupIdentifier, $groupName, $ranges) = $rangeData;
if ($isbnPrefix !== $eanPrefix) {
continue;
}
$groupLength = strlen($groupIdentifier);
$isbnGroup = substr($isbnDigits, 0, $groupLength);
if ($isbnGroup !== $groupIdentifier) {
continue;
}
$rangeInfo = new RangeInfo;
$rangeInfo->groupIdentifier = ($length === 10 ? $groupIdentifier : $eanPrefix . '-' . $groupIdentifier);
$rangeInfo->groupName = $groupName;
foreach ($ranges as $range) {
list ($rangeLength, $rangeStart, $rangeEnd) = $range;
$rangeValue = substr($isbnDigits, $groupLength, $rangeLength);
$lastDigits = substr($isbnDigits, $groupLength + $rangeLength, -1);
$checkDigit = substr($isbnDigits, -1);
if (strcmp($rangeValue, $rangeStart) >= 0 && strcmp($rangeValue, $rangeEnd) <= 0) {
if ($length === 13) {
$rangeInfo->parts = [$isbnPrefix, $isbnGroup, $rangeValue, $lastDigits, $checkDigit];
} else {
$rangeInfo->parts = [$isbnGroup, $rangeValue, $lastDigits, $checkDigit];
}
break;
}
}
return $rangeInfo;
}
return null;
} | [
"public",
"static",
"function",
"getRangeInfo",
"(",
"string",
"$",
"isbn",
")",
":",
"?",
"RangeInfo",
"{",
"$",
"length",
"=",
"strlen",
"(",
"$",
"isbn",
")",
";",
"$",
"isbnPrefix",
"=",
"(",
"$",
"length",
"===",
"10",
")",
"?",
"'978'",
":",
"substr",
"(",
"$",
"isbn",
",",
"0",
",",
"3",
")",
";",
"$",
"isbnDigits",
"=",
"(",
"$",
"length",
"===",
"10",
")",
"?",
"$",
"isbn",
":",
"substr",
"(",
"$",
"isbn",
",",
"3",
")",
";",
"foreach",
"(",
"self",
"::",
"getRanges",
"(",
")",
"as",
"$",
"rangeData",
")",
"{",
"list",
"(",
"$",
"eanPrefix",
",",
"$",
"groupIdentifier",
",",
"$",
"groupName",
",",
"$",
"ranges",
")",
"=",
"$",
"rangeData",
";",
"if",
"(",
"$",
"isbnPrefix",
"!==",
"$",
"eanPrefix",
")",
"{",
"continue",
";",
"}",
"$",
"groupLength",
"=",
"strlen",
"(",
"$",
"groupIdentifier",
")",
";",
"$",
"isbnGroup",
"=",
"substr",
"(",
"$",
"isbnDigits",
",",
"0",
",",
"$",
"groupLength",
")",
";",
"if",
"(",
"$",
"isbnGroup",
"!==",
"$",
"groupIdentifier",
")",
"{",
"continue",
";",
"}",
"$",
"rangeInfo",
"=",
"new",
"RangeInfo",
";",
"$",
"rangeInfo",
"->",
"groupIdentifier",
"=",
"(",
"$",
"length",
"===",
"10",
"?",
"$",
"groupIdentifier",
":",
"$",
"eanPrefix",
".",
"'-'",
".",
"$",
"groupIdentifier",
")",
";",
"$",
"rangeInfo",
"->",
"groupName",
"=",
"$",
"groupName",
";",
"foreach",
"(",
"$",
"ranges",
"as",
"$",
"range",
")",
"{",
"list",
"(",
"$",
"rangeLength",
",",
"$",
"rangeStart",
",",
"$",
"rangeEnd",
")",
"=",
"$",
"range",
";",
"$",
"rangeValue",
"=",
"substr",
"(",
"$",
"isbnDigits",
",",
"$",
"groupLength",
",",
"$",
"rangeLength",
")",
";",
"$",
"lastDigits",
"=",
"substr",
"(",
"$",
"isbnDigits",
",",
"$",
"groupLength",
"+",
"$",
"rangeLength",
",",
"-",
"1",
")",
";",
"$",
"checkDigit",
"=",
"substr",
"(",
"$",
"isbnDigits",
",",
"-",
"1",
")",
";",
"if",
"(",
"strcmp",
"(",
"$",
"rangeValue",
",",
"$",
"rangeStart",
")",
">=",
"0",
"&&",
"strcmp",
"(",
"$",
"rangeValue",
",",
"$",
"rangeEnd",
")",
"<=",
"0",
")",
"{",
"if",
"(",
"$",
"length",
"===",
"13",
")",
"{",
"$",
"rangeInfo",
"->",
"parts",
"=",
"[",
"$",
"isbnPrefix",
",",
"$",
"isbnGroup",
",",
"$",
"rangeValue",
",",
"$",
"lastDigits",
",",
"$",
"checkDigit",
"]",
";",
"}",
"else",
"{",
"$",
"rangeInfo",
"->",
"parts",
"=",
"[",
"$",
"isbnGroup",
",",
"$",
"rangeValue",
",",
"$",
"lastDigits",
",",
"$",
"checkDigit",
"]",
";",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"rangeInfo",
";",
"}",
"return",
"null",
";",
"}"
] | Splits an ISBN into parts.
@param string $isbn The ISBN-10 or ISBN-13, regexp-validated.
@return RangeInfo|null | [
"Splits",
"an",
"ISBN",
"into",
"parts",
"."
] | f5ceb662e517b21e30c9dfa53c4d74823849232d | https://github.com/nicebooks-com/isbn/blob/f5ceb662e517b21e30c9dfa53c4d74823849232d/src/Internal/RangeService.php#L66-L111 |
29,213 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.load | public function load($ident, $metadata = [], array $idents = null)
{
if (!is_string($ident)) {
throw new InvalidArgumentException(sprintf(
'Metadata identifier must be a string, received %s',
is_object($ident) ? get_class($ident) : gettype($ident)
));
}
if (strpos($ident, '\\') !== false) {
$ident = $this->metaKeyFromClassName($ident);
}
$valid = $this->validateMetadataContainer($metadata, $metadataType, $targetMetadata);
if ($valid === false) {
throw new InvalidArgumentException(sprintf(
'Metadata object must be a class name or instance of %s, received %s',
MetadataInterface::class,
is_object($metadata) ? get_class($metadata) : gettype($metadata)
));
}
if (isset(static::$metadataCache[$ident])) {
$cachedMetadata = static::$metadataCache[$ident];
if (is_object($targetMetadata)) {
return $targetMetadata->merge($cachedMetadata);
} elseif (is_array($targetMetadata)) {
return array_replace_recursive($targetMetadata, $cachedMetadata->data());
}
return $cachedMetadata;
}
$data = $this->loadMetadataFromCache($ident, $idents);
if (is_object($targetMetadata)) {
return $targetMetadata->merge($data);
} elseif (is_array($targetMetadata)) {
return array_replace_recursive($targetMetadata, $data);
}
$targetMetadata = new $metadataType;
$targetMetadata->setData($data);
static::$metadataCache[$ident] = $targetMetadata;
return $targetMetadata;
} | php | public function load($ident, $metadata = [], array $idents = null)
{
if (!is_string($ident)) {
throw new InvalidArgumentException(sprintf(
'Metadata identifier must be a string, received %s',
is_object($ident) ? get_class($ident) : gettype($ident)
));
}
if (strpos($ident, '\\') !== false) {
$ident = $this->metaKeyFromClassName($ident);
}
$valid = $this->validateMetadataContainer($metadata, $metadataType, $targetMetadata);
if ($valid === false) {
throw new InvalidArgumentException(sprintf(
'Metadata object must be a class name or instance of %s, received %s',
MetadataInterface::class,
is_object($metadata) ? get_class($metadata) : gettype($metadata)
));
}
if (isset(static::$metadataCache[$ident])) {
$cachedMetadata = static::$metadataCache[$ident];
if (is_object($targetMetadata)) {
return $targetMetadata->merge($cachedMetadata);
} elseif (is_array($targetMetadata)) {
return array_replace_recursive($targetMetadata, $cachedMetadata->data());
}
return $cachedMetadata;
}
$data = $this->loadMetadataFromCache($ident, $idents);
if (is_object($targetMetadata)) {
return $targetMetadata->merge($data);
} elseif (is_array($targetMetadata)) {
return array_replace_recursive($targetMetadata, $data);
}
$targetMetadata = new $metadataType;
$targetMetadata->setData($data);
static::$metadataCache[$ident] = $targetMetadata;
return $targetMetadata;
} | [
"public",
"function",
"load",
"(",
"$",
"ident",
",",
"$",
"metadata",
"=",
"[",
"]",
",",
"array",
"$",
"idents",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"ident",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Metadata identifier must be a string, received %s'",
",",
"is_object",
"(",
"$",
"ident",
")",
"?",
"get_class",
"(",
"$",
"ident",
")",
":",
"gettype",
"(",
"$",
"ident",
")",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"ident",
",",
"'\\\\'",
")",
"!==",
"false",
")",
"{",
"$",
"ident",
"=",
"$",
"this",
"->",
"metaKeyFromClassName",
"(",
"$",
"ident",
")",
";",
"}",
"$",
"valid",
"=",
"$",
"this",
"->",
"validateMetadataContainer",
"(",
"$",
"metadata",
",",
"$",
"metadataType",
",",
"$",
"targetMetadata",
")",
";",
"if",
"(",
"$",
"valid",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Metadata object must be a class name or instance of %s, received %s'",
",",
"MetadataInterface",
"::",
"class",
",",
"is_object",
"(",
"$",
"metadata",
")",
"?",
"get_class",
"(",
"$",
"metadata",
")",
":",
"gettype",
"(",
"$",
"metadata",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"metadataCache",
"[",
"$",
"ident",
"]",
")",
")",
"{",
"$",
"cachedMetadata",
"=",
"static",
"::",
"$",
"metadataCache",
"[",
"$",
"ident",
"]",
";",
"if",
"(",
"is_object",
"(",
"$",
"targetMetadata",
")",
")",
"{",
"return",
"$",
"targetMetadata",
"->",
"merge",
"(",
"$",
"cachedMetadata",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"targetMetadata",
")",
")",
"{",
"return",
"array_replace_recursive",
"(",
"$",
"targetMetadata",
",",
"$",
"cachedMetadata",
"->",
"data",
"(",
")",
")",
";",
"}",
"return",
"$",
"cachedMetadata",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"loadMetadataFromCache",
"(",
"$",
"ident",
",",
"$",
"idents",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"targetMetadata",
")",
")",
"{",
"return",
"$",
"targetMetadata",
"->",
"merge",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"targetMetadata",
")",
")",
"{",
"return",
"array_replace_recursive",
"(",
"$",
"targetMetadata",
",",
"$",
"data",
")",
";",
"}",
"$",
"targetMetadata",
"=",
"new",
"$",
"metadataType",
";",
"$",
"targetMetadata",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"static",
"::",
"$",
"metadataCache",
"[",
"$",
"ident",
"]",
"=",
"$",
"targetMetadata",
";",
"return",
"$",
"targetMetadata",
";",
"}"
] | Load the metadata for the given identifier or interfaces.
Notes:
- If the requested dataset is found, it will be stored in the cache service.
- If the provided metadata container is an {@see MetadataInterface object},
it will be stored for the lifetime of the script (whether it be a longer
running process or a web request).
@param string $ident The metadata identifier to load.
@param mixed $metadata The metadata type to load the dataset into.
If $metadata is a {@see MetadataInterface} instance, the requested dataset will be merged into the object.
If $metadata is a class name, the requested dataset will be stored in a new instance of that class.
If $metadata is an array, the requested dataset will be merged into the array.
@param array $idents The metadata identifier(s) to load.
If $idents is provided, $ident will be used as the cache key
and $idents are loaded instead.
@throws InvalidArgumentException If the identifier is not a string.
@return MetadataInterface|array Returns the dataset, for the given $ident,
as an array or an instance of {@see MetadataInterface}.
See $metadata for more details. | [
"Load",
"the",
"metadata",
"for",
"the",
"given",
"identifier",
"or",
"interfaces",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L127-L175 |
29,214 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.loadMetadataByKey | public function loadMetadataByKey($ident)
{
if (!is_string($ident)) {
throw new InvalidArgumentException(
'Metadata identifier must be a string'
);
}
$lineage = $this->hierarchy($ident);
$metadata = [];
foreach ($lineage as $metaKey) {
$data = $this->loadMetadataFromSource($metaKey);
if (is_array($data)) {
$metadata = array_replace_recursive($metadata, $data);
}
}
return $metadata;
} | php | public function loadMetadataByKey($ident)
{
if (!is_string($ident)) {
throw new InvalidArgumentException(
'Metadata identifier must be a string'
);
}
$lineage = $this->hierarchy($ident);
$metadata = [];
foreach ($lineage as $metaKey) {
$data = $this->loadMetadataFromSource($metaKey);
if (is_array($data)) {
$metadata = array_replace_recursive($metadata, $data);
}
}
return $metadata;
} | [
"public",
"function",
"loadMetadataByKey",
"(",
"$",
"ident",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"ident",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Metadata identifier must be a string'",
")",
";",
"}",
"$",
"lineage",
"=",
"$",
"this",
"->",
"hierarchy",
"(",
"$",
"ident",
")",
";",
"$",
"metadata",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lineage",
"as",
"$",
"metaKey",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"loadMetadataFromSource",
"(",
"$",
"metaKey",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"metadata",
"=",
"array_replace_recursive",
"(",
"$",
"metadata",
",",
"$",
"data",
")",
";",
"}",
"}",
"return",
"$",
"metadata",
";",
"}"
] | Fetch the metadata for the given identifier.
@param string $ident The metadata identifier to load.
@throws InvalidArgumentException If the identifier is not a string.
@return array | [
"Fetch",
"the",
"metadata",
"for",
"the",
"given",
"identifier",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L184-L202 |
29,215 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.loadMetadataByKeys | public function loadMetadataByKeys(array $idents)
{
$metadata = [];
foreach ($idents as $metaKey) {
$data = $this->loadMetadataByKey($metaKey);
if (is_array($data)) {
$metadata = array_replace_recursive($metadata, $data);
}
}
return $metadata;
} | php | public function loadMetadataByKeys(array $idents)
{
$metadata = [];
foreach ($idents as $metaKey) {
$data = $this->loadMetadataByKey($metaKey);
if (is_array($data)) {
$metadata = array_replace_recursive($metadata, $data);
}
}
return $metadata;
} | [
"public",
"function",
"loadMetadataByKeys",
"(",
"array",
"$",
"idents",
")",
"{",
"$",
"metadata",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"idents",
"as",
"$",
"metaKey",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"loadMetadataByKey",
"(",
"$",
"metaKey",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"metadata",
"=",
"array_replace_recursive",
"(",
"$",
"metadata",
",",
"$",
"data",
")",
";",
"}",
"}",
"return",
"$",
"metadata",
";",
"}"
] | Fetch the metadata for the given identifiers.
@param array $idents One or more metadata identifiers to load.
@return array | [
"Fetch",
"the",
"metadata",
"for",
"the",
"given",
"identifiers",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L210-L221 |
29,216 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.loadMetadataFromCache | private function loadMetadataFromCache($ident, array $idents = null)
{
$cacheKey = $this->cacheKeyFromMetaKey($ident);
$cacheItem = $this->cachePool()->getItem($cacheKey);
if ($cacheItem->isHit()) {
$metadata = $cacheItem->get();
/** Backwards compatibility */
if ($metadata instanceof MetadataInterface) {
$metadata = $metadata->data();
$cacheItem->set($metadata);
$this->cachePool()->save($cacheItem);
}
return $metadata;
} else {
if (empty($idents)) {
$metadata = $this->loadMetadataByKey($ident);
} else {
$metadata = $this->loadMetadataByKeys($idents);
}
$cacheItem->set($metadata);
$this->cachePool()->save($cacheItem);
}
return $metadata;
} | php | private function loadMetadataFromCache($ident, array $idents = null)
{
$cacheKey = $this->cacheKeyFromMetaKey($ident);
$cacheItem = $this->cachePool()->getItem($cacheKey);
if ($cacheItem->isHit()) {
$metadata = $cacheItem->get();
/** Backwards compatibility */
if ($metadata instanceof MetadataInterface) {
$metadata = $metadata->data();
$cacheItem->set($metadata);
$this->cachePool()->save($cacheItem);
}
return $metadata;
} else {
if (empty($idents)) {
$metadata = $this->loadMetadataByKey($ident);
} else {
$metadata = $this->loadMetadataByKeys($idents);
}
$cacheItem->set($metadata);
$this->cachePool()->save($cacheItem);
}
return $metadata;
} | [
"private",
"function",
"loadMetadataFromCache",
"(",
"$",
"ident",
",",
"array",
"$",
"idents",
"=",
"null",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"cacheKeyFromMetaKey",
"(",
"$",
"ident",
")",
";",
"$",
"cacheItem",
"=",
"$",
"this",
"->",
"cachePool",
"(",
")",
"->",
"getItem",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"$",
"cacheItem",
"->",
"isHit",
"(",
")",
")",
"{",
"$",
"metadata",
"=",
"$",
"cacheItem",
"->",
"get",
"(",
")",
";",
"/** Backwards compatibility */",
"if",
"(",
"$",
"metadata",
"instanceof",
"MetadataInterface",
")",
"{",
"$",
"metadata",
"=",
"$",
"metadata",
"->",
"data",
"(",
")",
";",
"$",
"cacheItem",
"->",
"set",
"(",
"$",
"metadata",
")",
";",
"$",
"this",
"->",
"cachePool",
"(",
")",
"->",
"save",
"(",
"$",
"cacheItem",
")",
";",
"}",
"return",
"$",
"metadata",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"idents",
")",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"loadMetadataByKey",
"(",
"$",
"ident",
")",
";",
"}",
"else",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"loadMetadataByKeys",
"(",
"$",
"idents",
")",
";",
"}",
"$",
"cacheItem",
"->",
"set",
"(",
"$",
"metadata",
")",
";",
"$",
"this",
"->",
"cachePool",
"(",
")",
"->",
"save",
"(",
"$",
"cacheItem",
")",
";",
"}",
"return",
"$",
"metadata",
";",
"}"
] | Load a metadataset from the cache.
@param string $ident The metadata identifier to load / cache key for $idents.
@param array $idents If provided, $ident is used as the cache key
and these metadata identifiers are loaded instead.
@return array The data associated with the metadata identifier. | [
"Load",
"a",
"metadataset",
"from",
"the",
"cache",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L300-L328 |
29,217 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.loadFile | private function loadFile($path)
{
if (file_exists($path)) {
return $this->loadJsonFile($path);
}
$dirs = $this->paths();
if (empty($dirs)) {
return null;
}
$data = [];
$dirs = array_reverse($dirs);
foreach ($dirs as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.$path;
if (file_exists($file)) {
$data = array_replace_recursive($data, $this->loadJsonFile($file));
}
}
if (empty($data)) {
return null;
}
return $data;
} | php | private function loadFile($path)
{
if (file_exists($path)) {
return $this->loadJsonFile($path);
}
$dirs = $this->paths();
if (empty($dirs)) {
return null;
}
$data = [];
$dirs = array_reverse($dirs);
foreach ($dirs as $dir) {
$file = $dir.DIRECTORY_SEPARATOR.$path;
if (file_exists($file)) {
$data = array_replace_recursive($data, $this->loadJsonFile($file));
}
}
if (empty($data)) {
return null;
}
return $data;
} | [
"private",
"function",
"loadFile",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loadJsonFile",
"(",
"$",
"path",
")",
";",
"}",
"$",
"dirs",
"=",
"$",
"this",
"->",
"paths",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"dirs",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"dirs",
"=",
"array_reverse",
"(",
"$",
"dirs",
")",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"$",
"file",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"path",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"data",
"=",
"array_replace_recursive",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"loadJsonFile",
"(",
"$",
"file",
")",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Load a file as an array.
Supported file types: JSON.
@param string $path A file path to resolve and fetch.
@return array|null An associative array on success, NULL on failure. | [
"Load",
"a",
"file",
"as",
"an",
"array",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L352-L377 |
29,218 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.serializeMetaKey | public function serializeMetaKey($ident)
{
if (is_array($ident)) {
sort($ident);
$ident = implode(':', $ident);
}
return md5($ident);
} | php | public function serializeMetaKey($ident)
{
if (is_array($ident)) {
sort($ident);
$ident = implode(':', $ident);
}
return md5($ident);
} | [
"public",
"function",
"serializeMetaKey",
"(",
"$",
"ident",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"ident",
")",
")",
"{",
"sort",
"(",
"$",
"ident",
")",
";",
"$",
"ident",
"=",
"implode",
"(",
"':'",
",",
"$",
"ident",
")",
";",
"}",
"return",
"md5",
"(",
"$",
"ident",
")",
";",
"}"
] | Generate a store key.
@param string|string[] $ident The metadata identifier(s) to convert.
@return string | [
"Generate",
"a",
"store",
"key",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L411-L419 |
29,219 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.classNameFromMetaKey | private function classNameFromMetaKey($ident)
{
$key = $ident;
if (isset(static::$camelCache[$key])) {
return static::$camelCache[$key];
}
// Change "foo-bar" to "fooBar"
$parts = explode('-', $ident);
array_walk(
$parts,
function(&$i) {
$i = ucfirst($i);
}
);
$ident = implode('', $parts);
// Change "/foo/bar" to "\Foo\Bar"
$classname = str_replace('/', '\\', $ident);
$parts = explode('\\', $classname);
array_walk(
$parts,
function(&$i) {
$i = ucfirst($i);
}
);
$classname = trim(implode('\\', $parts), '\\');
static::$camelCache[$key] = $classname;
static::$snakeCache[$classname] = $key;
return $classname;
} | php | private function classNameFromMetaKey($ident)
{
$key = $ident;
if (isset(static::$camelCache[$key])) {
return static::$camelCache[$key];
}
// Change "foo-bar" to "fooBar"
$parts = explode('-', $ident);
array_walk(
$parts,
function(&$i) {
$i = ucfirst($i);
}
);
$ident = implode('', $parts);
// Change "/foo/bar" to "\Foo\Bar"
$classname = str_replace('/', '\\', $ident);
$parts = explode('\\', $classname);
array_walk(
$parts,
function(&$i) {
$i = ucfirst($i);
}
);
$classname = trim(implode('\\', $parts), '\\');
static::$camelCache[$key] = $classname;
static::$snakeCache[$classname] = $key;
return $classname;
} | [
"private",
"function",
"classNameFromMetaKey",
"(",
"$",
"ident",
")",
"{",
"$",
"key",
"=",
"$",
"ident",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"camelCache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"camelCache",
"[",
"$",
"key",
"]",
";",
"}",
"// Change \"foo-bar\" to \"fooBar\"",
"$",
"parts",
"=",
"explode",
"(",
"'-'",
",",
"$",
"ident",
")",
";",
"array_walk",
"(",
"$",
"parts",
",",
"function",
"(",
"&",
"$",
"i",
")",
"{",
"$",
"i",
"=",
"ucfirst",
"(",
"$",
"i",
")",
";",
"}",
")",
";",
"$",
"ident",
"=",
"implode",
"(",
"''",
",",
"$",
"parts",
")",
";",
"// Change \"/foo/bar\" to \"\\Foo\\Bar\"",
"$",
"classname",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"ident",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"classname",
")",
";",
"array_walk",
"(",
"$",
"parts",
",",
"function",
"(",
"&",
"$",
"i",
")",
"{",
"$",
"i",
"=",
"ucfirst",
"(",
"$",
"i",
")",
";",
"}",
")",
";",
"$",
"classname",
"=",
"trim",
"(",
"implode",
"(",
"'\\\\'",
",",
"$",
"parts",
")",
",",
"'\\\\'",
")",
";",
"static",
"::",
"$",
"camelCache",
"[",
"$",
"key",
"]",
"=",
"$",
"classname",
";",
"static",
"::",
"$",
"snakeCache",
"[",
"$",
"classname",
"]",
"=",
"$",
"key",
";",
"return",
"$",
"classname",
";",
"}"
] | Convert a kebab-cased namespace to CamelCase.
@param string $ident The metadata identifier to convert.
@return string Returns a valid PHP namespace. | [
"Convert",
"a",
"kebab",
"-",
"cased",
"namespace",
"to",
"CamelCase",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L453-L488 |
29,220 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.metaKeyFromClassName | private function metaKeyFromClassName($class)
{
$key = trim($class, '\\');
if (isset(static::$snakeCache[$key])) {
return static::$snakeCache[$key];
}
$ident = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $class));
$ident = str_replace('\\', '/', strtolower($ident));
$ident = ltrim($ident, '/');
static::$snakeCache[$key] = $ident;
static::$camelCache[$ident] = $key;
return $ident;
} | php | private function metaKeyFromClassName($class)
{
$key = trim($class, '\\');
if (isset(static::$snakeCache[$key])) {
return static::$snakeCache[$key];
}
$ident = strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $class));
$ident = str_replace('\\', '/', strtolower($ident));
$ident = ltrim($ident, '/');
static::$snakeCache[$key] = $ident;
static::$camelCache[$ident] = $key;
return $ident;
} | [
"private",
"function",
"metaKeyFromClassName",
"(",
"$",
"class",
")",
"{",
"$",
"key",
"=",
"trim",
"(",
"$",
"class",
",",
"'\\\\'",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"snakeCache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"snakeCache",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"ident",
"=",
"strtolower",
"(",
"preg_replace",
"(",
"'/([a-z])([A-Z])/'",
",",
"'$1-$2'",
",",
"$",
"class",
")",
")",
";",
"$",
"ident",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"strtolower",
"(",
"$",
"ident",
")",
")",
";",
"$",
"ident",
"=",
"ltrim",
"(",
"$",
"ident",
",",
"'/'",
")",
";",
"static",
"::",
"$",
"snakeCache",
"[",
"$",
"key",
"]",
"=",
"$",
"ident",
";",
"static",
"::",
"$",
"camelCache",
"[",
"$",
"ident",
"]",
"=",
"$",
"key",
";",
"return",
"$",
"ident",
";",
"}"
] | Convert a CamelCase namespace to kebab-case.
@param string $class The FQCN to convert.
@return string Returns a kebab-cased namespace. | [
"Convert",
"a",
"CamelCase",
"namespace",
"to",
"kebab",
"-",
"case",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L496-L512 |
29,221 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.validateMetadataContainer | private function validateMetadataContainer($metadata, &$type = null, &$bag = null)
{
// If variables are provided, clear existing values.
$type = null;
$bag = null;
if (is_array($metadata)) {
$type = 'array';
$bag = $metadata;
return true;
}
if (is_a($metadata, MetadataInterface::class, true)) {
if (is_object($metadata)) {
$type = get_class($metadata);
$bag = $metadata;
return true;
}
if (is_string($metadata)) {
$type = $metadata;
return true;
}
}
return false;
} | php | private function validateMetadataContainer($metadata, &$type = null, &$bag = null)
{
// If variables are provided, clear existing values.
$type = null;
$bag = null;
if (is_array($metadata)) {
$type = 'array';
$bag = $metadata;
return true;
}
if (is_a($metadata, MetadataInterface::class, true)) {
if (is_object($metadata)) {
$type = get_class($metadata);
$bag = $metadata;
return true;
}
if (is_string($metadata)) {
$type = $metadata;
return true;
}
}
return false;
} | [
"private",
"function",
"validateMetadataContainer",
"(",
"$",
"metadata",
",",
"&",
"$",
"type",
"=",
"null",
",",
"&",
"$",
"bag",
"=",
"null",
")",
"{",
"// If variables are provided, clear existing values.",
"$",
"type",
"=",
"null",
";",
"$",
"bag",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"metadata",
")",
")",
"{",
"$",
"type",
"=",
"'array'",
";",
"$",
"bag",
"=",
"$",
"metadata",
";",
"return",
"true",
";",
"}",
"if",
"(",
"is_a",
"(",
"$",
"metadata",
",",
"MetadataInterface",
"::",
"class",
",",
"true",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"metadata",
")",
")",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"metadata",
")",
";",
"$",
"bag",
"=",
"$",
"metadata",
";",
"return",
"true",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"metadata",
")",
")",
"{",
"$",
"type",
"=",
"$",
"metadata",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Validate a metadata type or container.
If specified, the method will also resolve the metadata type or container.
@param mixed $metadata The metadata type or container to validate.
@param string|null $type If provided, then it is filled with the resolved metadata type.
@param mixed|null $bag If provided, then it is filled with the resolved metadata container.
@return boolean | [
"Validate",
"a",
"metadata",
"type",
"or",
"container",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L524-L549 |
29,222 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.addPath | private function addPath($path)
{
$path = $this->resolvePath($path);
if ($this->validatePath($path)) {
$this->paths[] = $path;
}
return $this;
} | php | private function addPath($path)
{
$path = $this->resolvePath($path);
if ($this->validatePath($path)) {
$this->paths[] = $path;
}
return $this;
} | [
"private",
"function",
"addPath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"resolvePath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"this",
"->",
"validatePath",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Append a search path.
@param string $path A directory path.
@return self | [
"Append",
"a",
"search",
"path",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L623-L632 |
29,223 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataLoader.php | MetadataLoader.resolvePath | private function resolvePath($path)
{
if (!is_string($path)) {
throw new InvalidArgumentException(
'Path needs to be a string'
);
}
$basePath = $this->basePath();
$path = trim($path, '/\\');
if ($basePath && strpos($path, $basePath) === false) {
$path = $basePath.$path;
}
return $path;
} | php | private function resolvePath($path)
{
if (!is_string($path)) {
throw new InvalidArgumentException(
'Path needs to be a string'
);
}
$basePath = $this->basePath();
$path = trim($path, '/\\');
if ($basePath && strpos($path, $basePath) === false) {
$path = $basePath.$path;
}
return $path;
} | [
"private",
"function",
"resolvePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Path needs to be a string'",
")",
";",
"}",
"$",
"basePath",
"=",
"$",
"this",
"->",
"basePath",
"(",
")",
";",
"$",
"path",
"=",
"trim",
"(",
"$",
"path",
",",
"'/\\\\'",
")",
";",
"if",
"(",
"$",
"basePath",
"&&",
"strpos",
"(",
"$",
"path",
",",
"$",
"basePath",
")",
"===",
"false",
")",
"{",
"$",
"path",
"=",
"$",
"basePath",
".",
"$",
"path",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Parse a relative path using the base path if needed.
@param string $path The path to resolve.
@throws InvalidArgumentException If the path is invalid.
@return string | [
"Parse",
"a",
"relative",
"path",
"using",
"the",
"base",
"path",
"if",
"needed",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataLoader.php#L641-L657 |
29,224 | timble/kodekit | code/user/session/abstract.php | UserSessionAbstract.setHandler | public function setHandler($handler, $config = array())
{
if (!($handler instanceof UserSessionHandlerInterface))
{
if (is_string($handler) && strpos($handler, '.') === false)
{
$identifier = $this->getIdentifier()->toArray();
$identifier['path'] = array('session', 'handler');
$identifier['name'] = $handler;
// reset the handler
$handler = $identifier;
}
$identifier = $this->getIdentifier($handler);
//Set the configuration
$identifier->getConfig()->append($config);
$handler = $identifier;
}
$this->_handler = $handler;
return $this;
} | php | public function setHandler($handler, $config = array())
{
if (!($handler instanceof UserSessionHandlerInterface))
{
if (is_string($handler) && strpos($handler, '.') === false)
{
$identifier = $this->getIdentifier()->toArray();
$identifier['path'] = array('session', 'handler');
$identifier['name'] = $handler;
// reset the handler
$handler = $identifier;
}
$identifier = $this->getIdentifier($handler);
//Set the configuration
$identifier->getConfig()->append($config);
$handler = $identifier;
}
$this->_handler = $handler;
return $this;
} | [
"public",
"function",
"setHandler",
"(",
"$",
"handler",
",",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"handler",
"instanceof",
"UserSessionHandlerInterface",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"handler",
")",
"&&",
"strpos",
"(",
"$",
"handler",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"identifier",
"[",
"'path'",
"]",
"=",
"array",
"(",
"'session'",
",",
"'handler'",
")",
";",
"$",
"identifier",
"[",
"'name'",
"]",
"=",
"$",
"handler",
";",
"// reset the handler",
"$",
"handler",
"=",
"$",
"identifier",
";",
"}",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"handler",
")",
";",
"//Set the configuration",
"$",
"identifier",
"->",
"getConfig",
"(",
")",
"->",
"append",
"(",
"$",
"config",
")",
";",
"$",
"handler",
"=",
"$",
"identifier",
";",
"}",
"$",
"this",
"->",
"_handler",
"=",
"$",
"handler",
";",
"return",
"$",
"this",
";",
"}"
] | Method to set a session handler object
@param mixed $handler An object that implements UserSessionHandlerInterface, ObjectIdentifier object
or valid identifier string
@param array $config An optional associative array of configuration settings
@return $this | [
"Method",
"to",
"set",
"a",
"session",
"handler",
"object"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/user/session/abstract.php#L311-L334 |
29,225 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.merge | public function merge($objs)
{
$objs = $this->asArray($objs);
foreach ($objs as $obj) {
if (!$this->isAcceptable($obj)) {
throw new InvalidArgumentException(
sprintf(
'Must be an array of models, contains %s',
(is_object($obj) ? get_class($obj) : gettype($obj))
)
);
}
$key = $this->modelKey($obj);
$this->objects[$key] = $obj;
}
return $this;
} | php | public function merge($objs)
{
$objs = $this->asArray($objs);
foreach ($objs as $obj) {
if (!$this->isAcceptable($obj)) {
throw new InvalidArgumentException(
sprintf(
'Must be an array of models, contains %s',
(is_object($obj) ? get_class($obj) : gettype($obj))
)
);
}
$key = $this->modelKey($obj);
$this->objects[$key] = $obj;
}
return $this;
} | [
"public",
"function",
"merge",
"(",
"$",
"objs",
")",
"{",
"$",
"objs",
"=",
"$",
"this",
"->",
"asArray",
"(",
"$",
"objs",
")",
";",
"foreach",
"(",
"$",
"objs",
"as",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAcceptable",
"(",
"$",
"obj",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Must be an array of models, contains %s'",
",",
"(",
"is_object",
"(",
"$",
"obj",
")",
"?",
"get_class",
"(",
"$",
"obj",
")",
":",
"gettype",
"(",
"$",
"obj",
")",
")",
")",
")",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"modelKey",
"(",
"$",
"obj",
")",
";",
"$",
"this",
"->",
"objects",
"[",
"$",
"key",
"]",
"=",
"$",
"obj",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Merge the collection with the given objects.
@param array|Traversable $objs Array of objects to append to this collection.
@throws InvalidArgumentException If the given array contains an unacceptable value.
@return self | [
"Merge",
"the",
"collection",
"with",
"the",
"given",
"objects",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L91-L110 |
29,226 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.add | public function add($obj)
{
if (!$this->isAcceptable($obj)) {
throw new InvalidArgumentException(
sprintf(
'Must be a model, received %s',
(is_object($obj) ? get_class($obj) : gettype($obj))
)
);
}
$key = $this->modelKey($obj);
$this->objects[$key] = $obj;
return $this;
} | php | public function add($obj)
{
if (!$this->isAcceptable($obj)) {
throw new InvalidArgumentException(
sprintf(
'Must be a model, received %s',
(is_object($obj) ? get_class($obj) : gettype($obj))
)
);
}
$key = $this->modelKey($obj);
$this->objects[$key] = $obj;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAcceptable",
"(",
"$",
"obj",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Must be a model, received %s'",
",",
"(",
"is_object",
"(",
"$",
"obj",
")",
"?",
"get_class",
"(",
"$",
"obj",
")",
":",
"gettype",
"(",
"$",
"obj",
")",
")",
")",
")",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"modelKey",
"(",
"$",
"obj",
")",
";",
"$",
"this",
"->",
"objects",
"[",
"$",
"key",
"]",
"=",
"$",
"obj",
";",
"return",
"$",
"this",
";",
"}"
] | Add an object to the collection.
@param object $obj An acceptable object.
@throws InvalidArgumentException If the given object is not acceptable.
@return self | [
"Add",
"an",
"object",
"to",
"the",
"collection",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L119-L134 |
29,227 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.get | public function get($key)
{
if ($this->isAcceptable($key)) {
$key = $this->modelKey($key);
}
if ($this->has($key)) {
return $this->objects[$key];
}
return null;
} | php | public function get($key)
{
if ($this->isAcceptable($key)) {
$key = $this->modelKey($key);
}
if ($this->has($key)) {
return $this->objects[$key];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAcceptable",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"modelKey",
"(",
"$",
"key",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"objects",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieve the object by primary key.
@param mixed $key The primary key.
@return object|null Returns the requested object or NULL if not in the collection. | [
"Retrieve",
"the",
"object",
"by",
"primary",
"key",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L142-L153 |
29,228 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.has | public function has($key)
{
if ($this->isAcceptable($key)) {
$key = $this->modelKey($key);
}
return array_key_exists($key, $this->objects);
} | php | public function has($key)
{
if ($this->isAcceptable($key)) {
$key = $this->modelKey($key);
}
return array_key_exists($key, $this->objects);
} | [
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAcceptable",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"modelKey",
"(",
"$",
"key",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"objects",
")",
";",
"}"
] | Determine if an object exists in the collection by key.
@param mixed $key The primary key to lookup.
@return boolean | [
"Determine",
"if",
"an",
"object",
"exists",
"in",
"the",
"collection",
"by",
"key",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L161-L168 |
29,229 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.remove | public function remove($key)
{
if ($this->isAcceptable($key)) {
$key = $this->modelKey($key);
}
unset($this->objects[$key]);
return $this;
} | php | public function remove($key)
{
if ($this->isAcceptable($key)) {
$key = $this->modelKey($key);
}
unset($this->objects[$key]);
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAcceptable",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"modelKey",
"(",
"$",
"key",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"key",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove object from collection by primary key.
@param mixed $key The object primary key to remove.
@throws InvalidArgumentException If the given key is not acceptable.
@return self | [
"Remove",
"object",
"from",
"collection",
"by",
"primary",
"key",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L177-L186 |
29,230 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.resolveOffset | protected function resolveOffset($offset)
{
if (is_int($offset)) {
if ($offset < 0) {
$offset = ($this->count() - abs($offset));
}
}
return $offset;
} | php | protected function resolveOffset($offset)
{
if (is_int($offset)) {
if ($offset < 0) {
$offset = ($this->count() - abs($offset));
}
}
return $offset;
} | [
"protected",
"function",
"resolveOffset",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"offset",
")",
")",
"{",
"if",
"(",
"$",
"offset",
"<",
"0",
")",
"{",
"$",
"offset",
"=",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"-",
"abs",
"(",
"$",
"offset",
")",
")",
";",
"}",
"}",
"return",
"$",
"offset",
";",
"}"
] | Parse the array offset.
If offset is non-negative, the sequence will start at that offset in the collection.
If offset is negative, the sequence will start that far from the end of the collection.
@param integer $offset The array offset.
@return integer Returns the resolved array offset. | [
"Parse",
"the",
"array",
"offset",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L321-L330 |
29,231 | locomotivemtl/charcoal-core | src/Charcoal/Model/Collection.php | Collection.modelKey | protected function modelKey($obj)
{
if (!$this->isAcceptable($obj)) {
throw new InvalidArgumentException(
sprintf(
'Must be a model, received %s',
(is_object($obj) ? get_class($obj) : gettype($obj))
)
);
}
return $obj->id();
} | php | protected function modelKey($obj)
{
if (!$this->isAcceptable($obj)) {
throw new InvalidArgumentException(
sprintf(
'Must be a model, received %s',
(is_object($obj) ? get_class($obj) : gettype($obj))
)
);
}
return $obj->id();
} | [
"protected",
"function",
"modelKey",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAcceptable",
"(",
"$",
"obj",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Must be a model, received %s'",
",",
"(",
"is_object",
"(",
"$",
"obj",
")",
"?",
"get_class",
"(",
"$",
"obj",
")",
":",
"gettype",
"(",
"$",
"obj",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"obj",
"->",
"id",
"(",
")",
";",
"}"
] | Convert a given object into a model identifier.
Note: Practical for specialized collections extending the base collection.
@param object $obj An acceptable object.
@throws InvalidArgumentException If the given object is not acceptable.
@return boolean | [
"Convert",
"a",
"given",
"object",
"into",
"a",
"model",
"identifier",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Collection.php#L436-L448 |
29,232 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataConfig.php | MetadataConfig.defaults | public function defaults($key = null)
{
$data = [
'paths' => [],
'cache' => true,
];
if ($key) {
return isset($data[$key]) ? $data[$key] : null;
}
return $data;
} | php | public function defaults($key = null)
{
$data = [
'paths' => [],
'cache' => true,
];
if ($key) {
return isset($data[$key]) ? $data[$key] : null;
}
return $data;
} | [
"public",
"function",
"defaults",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"[",
"'paths'",
"=>",
"[",
"]",
",",
"'cache'",
"=>",
"true",
",",
"]",
";",
"if",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Retrieve the default values.
@param string|null $key Optional data key to retrieve.
@return mixed An associative array if $key is NULL.
If $key is specified, the value of that data key if it exists, NULL on failure. | [
"Retrieve",
"the",
"default",
"values",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataConfig.php#L38-L50 |
29,233 | locomotivemtl/charcoal-core | src/Charcoal/Model/Service/MetadataConfig.php | MetadataConfig.merge | public function merge($data)
{
foreach ($data as $key => $val) {
if ($key === 'paths') {
$this->addPaths((array)$val);
} elseif ($key === 'cache') {
$this->setCache($val);
} else {
$this->offsetReplace($key, $val);
}
}
return $this;
} | php | public function merge($data)
{
foreach ($data as $key => $val) {
if ($key === 'paths') {
$this->addPaths((array)$val);
} elseif ($key === 'cache') {
$this->setCache($val);
} else {
$this->offsetReplace($key, $val);
}
}
return $this;
} | [
"public",
"function",
"merge",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'paths'",
")",
"{",
"$",
"this",
"->",
"addPaths",
"(",
"(",
"array",
")",
"$",
"val",
")",
";",
"}",
"elseif",
"(",
"$",
"key",
"===",
"'cache'",
")",
"{",
"$",
"this",
"->",
"setCache",
"(",
"$",
"val",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"offsetReplace",
"(",
"$",
"key",
",",
"$",
"val",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add settings to configset, replacing existing settings with the same data key.
@see \Charcoal\Config\AbstractConfig::merge()
@param array|Traversable $data The data to merge.
@return self | [
"Add",
"settings",
"to",
"configset",
"replacing",
"existing",
"settings",
"with",
"the",
"same",
"data",
"key",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/Service/MetadataConfig.php#L59-L72 |
29,234 | timble/kodekit | code/model/state/state.php | ModelState.setProperty | public function setProperty($name, $property, $value)
{
if($this->has($name))
{
if($this->hasProperty($name, $property))
{
if($property !== 'value') {
$this->_data[$name]->$property = $value;
} else {
$this->set($name, $value);
}
}
}
return $this;
} | php | public function setProperty($name, $property, $value)
{
if($this->has($name))
{
if($this->hasProperty($name, $property))
{
if($property !== 'value') {
$this->_data[$name]->$property = $value;
} else {
$this->set($name, $value);
}
}
}
return $this;
} | [
"public",
"function",
"setProperty",
"(",
"$",
"name",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
",",
"$",
"property",
")",
")",
"{",
"if",
"(",
"$",
"property",
"!==",
"'value'",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"$",
"name",
"]",
"->",
"$",
"property",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set a state property
@param string $name The name of the state
@param string $property The name of the property
@param mixed $value The value of the property
@return ModelState | [
"Set",
"a",
"state",
"property"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/model/state/state.php#L289-L304 |
29,235 | timble/kodekit | code/model/state/state.php | ModelState._sanitize | protected function _sanitize($state)
{
//Treat empty string as null
if ($state->value === '') {
$state->value = null;
}
//Only filter if we have a value
if(!empty($state->value))
{
//Only accepts scalar values and array
if(!is_scalar($state->value) && !is_array($state->value))
{
throw new \UnexpectedValueException(
'Value needs to be an array or a scalar, "'.gettype($state->value).'" given'
);
}
$filter = $state->filter;
if(!($filter instanceof FilterInterface)) {
$filter = $this->getObject('filter.factory')->createChain($filter);
}
$state->value = $filter->sanitize($state->value);
}
return $state;
} | php | protected function _sanitize($state)
{
//Treat empty string as null
if ($state->value === '') {
$state->value = null;
}
//Only filter if we have a value
if(!empty($state->value))
{
//Only accepts scalar values and array
if(!is_scalar($state->value) && !is_array($state->value))
{
throw new \UnexpectedValueException(
'Value needs to be an array or a scalar, "'.gettype($state->value).'" given'
);
}
$filter = $state->filter;
if(!($filter instanceof FilterInterface)) {
$filter = $this->getObject('filter.factory')->createChain($filter);
}
$state->value = $filter->sanitize($state->value);
}
return $state;
} | [
"protected",
"function",
"_sanitize",
"(",
"$",
"state",
")",
"{",
"//Treat empty string as null",
"if",
"(",
"$",
"state",
"->",
"value",
"===",
"''",
")",
"{",
"$",
"state",
"->",
"value",
"=",
"null",
";",
"}",
"//Only filter if we have a value",
"if",
"(",
"!",
"empty",
"(",
"$",
"state",
"->",
"value",
")",
")",
"{",
"//Only accepts scalar values and array",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"state",
"->",
"value",
")",
"&&",
"!",
"is_array",
"(",
"$",
"state",
"->",
"value",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Value needs to be an array or a scalar, \"'",
".",
"gettype",
"(",
"$",
"state",
"->",
"value",
")",
".",
"'\" given'",
")",
";",
"}",
"$",
"filter",
"=",
"$",
"state",
"->",
"filter",
";",
"if",
"(",
"!",
"(",
"$",
"filter",
"instanceof",
"FilterInterface",
")",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"getObject",
"(",
"'filter.factory'",
")",
"->",
"createChain",
"(",
"$",
"filter",
")",
";",
"}",
"$",
"state",
"->",
"value",
"=",
"$",
"filter",
"->",
"sanitize",
"(",
"$",
"state",
"->",
"value",
")",
";",
"}",
"return",
"$",
"state",
";",
"}"
] | Sanitize a state by filtering the state value
@param object $state The state object.
@throws \UnexpectedValueException If the value is not a scalar or an array
@return object | [
"Sanitize",
"a",
"state",
"by",
"filtering",
"the",
"state",
"value"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/model/state/state.php#L473-L501 |
29,236 | locomotivemtl/charcoal-core | src/Charcoal/Source/Pagination.php | Pagination.setData | public function setData(array $data)
{
parent::setData($data);
if (isset($data['page'])) {
$this->setPage($data['page']);
}
if (isset($data['per_page'])) {
$this->setNumPerPage($data['per_page']);
}
if (isset($data['num_per_page'])) {
$this->setNumPerPage($data['num_per_page']);
}
return $this;
} | php | public function setData(array $data)
{
parent::setData($data);
if (isset($data['page'])) {
$this->setPage($data['page']);
}
if (isset($data['per_page'])) {
$this->setNumPerPage($data['per_page']);
}
if (isset($data['num_per_page'])) {
$this->setNumPerPage($data['num_per_page']);
}
return $this;
} | [
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"parent",
"::",
"setData",
"(",
"$",
"data",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'page'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setPage",
"(",
"$",
"data",
"[",
"'page'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'per_page'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setNumPerPage",
"(",
"$",
"data",
"[",
"'per_page'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'num_per_page'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setNumPerPage",
"(",
"$",
"data",
"[",
"'num_per_page'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the pagination clause data.
@param array<string,mixed> $data The expression data;
as an associative array.
@return self | [
"Set",
"the",
"pagination",
"clause",
"data",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Pagination.php#L43-L60 |
29,237 | locomotivemtl/charcoal-core | src/Charcoal/Source/Pagination.php | Pagination.setPage | public function setPage($page)
{
if (!is_numeric($page)) {
throw new InvalidArgumentException(
'Page number must be numeric.'
);
}
$page = (int)$page;
if ($page === 0) {
$page = 1;
} elseif ($page < 0) {
throw new InvalidArgumentException(
'Page number must be greater than zero.'
);
}
$this->page = $page;
return $this;
} | php | public function setPage($page)
{
if (!is_numeric($page)) {
throw new InvalidArgumentException(
'Page number must be numeric.'
);
}
$page = (int)$page;
if ($page === 0) {
$page = 1;
} elseif ($page < 0) {
throw new InvalidArgumentException(
'Page number must be greater than zero.'
);
}
$this->page = $page;
return $this;
} | [
"public",
"function",
"setPage",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"page",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Page number must be numeric.'",
")",
";",
"}",
"$",
"page",
"=",
"(",
"int",
")",
"$",
"page",
";",
"if",
"(",
"$",
"page",
"===",
"0",
")",
"{",
"$",
"page",
"=",
"1",
";",
"}",
"elseif",
"(",
"$",
"page",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Page number must be greater than zero.'",
")",
";",
"}",
"$",
"this",
"->",
"page",
"=",
"$",
"page",
";",
"return",
"$",
"this",
";",
"}"
] | Set the page number.
@param integer $page The current page.
Pages should start at 1.
@throws InvalidArgumentException If the parameter is not numeric or < 0.
@return self | [
"Set",
"the",
"page",
"number",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Pagination.php#L100-L119 |
29,238 | locomotivemtl/charcoal-core | src/Charcoal/Source/Pagination.php | Pagination.setNumPerPage | public function setNumPerPage($count)
{
if (!is_numeric($count)) {
throw new InvalidArgumentException(
'Number Per Page must be numeric.'
);
}
$count = (int)$count;
if ($count < 0) {
throw new InvalidArgumentException(
'Number Per Page must be greater than zero.'
);
}
$this->numPerPage = $count;
return $this;
} | php | public function setNumPerPage($count)
{
if (!is_numeric($count)) {
throw new InvalidArgumentException(
'Number Per Page must be numeric.'
);
}
$count = (int)$count;
if ($count < 0) {
throw new InvalidArgumentException(
'Number Per Page must be greater than zero.'
);
}
$this->numPerPage = $count;
return $this;
} | [
"public",
"function",
"setNumPerPage",
"(",
"$",
"count",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"count",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Number Per Page must be numeric.'",
")",
";",
"}",
"$",
"count",
"=",
"(",
"int",
")",
"$",
"count",
";",
"if",
"(",
"$",
"count",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Number Per Page must be greater than zero.'",
")",
";",
"}",
"$",
"this",
"->",
"numPerPage",
"=",
"$",
"count",
";",
"return",
"$",
"this",
";",
"}"
] | Set the number of results per page.
@param integer $count The number of results to return, per page.
Use 0 to request all results.
@throws InvalidArgumentException If the parameter is not numeric or < 0.
@return self | [
"Set",
"the",
"number",
"of",
"results",
"per",
"page",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Pagination.php#L139-L156 |
29,239 | locomotivemtl/charcoal-core | src/Charcoal/Source/Pagination.php | Pagination.first | public function first()
{
$page = $this->page();
$limit = $this->numPerPage();
return max(0, (($page - 1) * $limit));
} | php | public function first()
{
$page = $this->page();
$limit = $this->numPerPage();
return max(0, (($page - 1) * $limit));
} | [
"public",
"function",
"first",
"(",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"page",
"(",
")",
";",
"$",
"limit",
"=",
"$",
"this",
"->",
"numPerPage",
"(",
")",
";",
"return",
"max",
"(",
"0",
",",
"(",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"limit",
")",
")",
";",
"}"
] | Retrieve the pagination's lowest possible index.
@return integer | [
"Retrieve",
"the",
"pagination",
"s",
"lowest",
"possible",
"index",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Pagination.php#L173-L179 |
29,240 | timble/kodekit | code/http/token/token.php | HttpToken.setExpireTime | public function setExpireTime(\DateTime $date)
{
$date->setTimezone(new \DateTimeZone('UTC'));
$this->_claims['exp'] = (int)$date->format('U');
return $this;
} | php | public function setExpireTime(\DateTime $date)
{
$date->setTimezone(new \DateTimeZone('UTC'));
$this->_claims['exp'] = (int)$date->format('U');
return $this;
} | [
"public",
"function",
"setExpireTime",
"(",
"\\",
"DateTime",
"$",
"date",
")",
"{",
"$",
"date",
"->",
"setTimezone",
"(",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"$",
"this",
"->",
"_claims",
"[",
"'exp'",
"]",
"=",
"(",
"int",
")",
"$",
"date",
"->",
"format",
"(",
"'U'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the expiration time of the token.
Sets the 'exp' claim in the JWT claim segment. This claim identifies the expiration time on or after which the
token MUST NOT be accepted for processing
@param \DateTime $date A \DateTime instance
@return $this | [
"Sets",
"the",
"expiration",
"time",
"of",
"the",
"token",
"."
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/http/token/token.php#L268-L274 |
29,241 | timble/kodekit | code/http/token/token.php | HttpToken.toString | public function toString()
{
$date = new \DateTime('now');
//Make sure we have an issue time
if (!isset($this->_claims['iat'])) {
$this->setIssueTime($date);
}
if (!isset($this->_claims['exp'])){
$this->setExpireTime($date->modify('+24 hours'));
}
$header = $this->_toBase64url($this->_toJson($this->_header));
$payload = $this->_toBase64url($this->_toJson($this->_claims));
return sprintf("%s.%s", $header, $payload);
} | php | public function toString()
{
$date = new \DateTime('now');
//Make sure we have an issue time
if (!isset($this->_claims['iat'])) {
$this->setIssueTime($date);
}
if (!isset($this->_claims['exp'])){
$this->setExpireTime($date->modify('+24 hours'));
}
$header = $this->_toBase64url($this->_toJson($this->_header));
$payload = $this->_toBase64url($this->_toJson($this->_claims));
return sprintf("%s.%s", $header, $payload);
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
")",
";",
"//Make sure we have an issue time",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_claims",
"[",
"'iat'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setIssueTime",
"(",
"$",
"date",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_claims",
"[",
"'exp'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setExpireTime",
"(",
"$",
"date",
"->",
"modify",
"(",
"'+24 hours'",
")",
")",
";",
"}",
"$",
"header",
"=",
"$",
"this",
"->",
"_toBase64url",
"(",
"$",
"this",
"->",
"_toJson",
"(",
"$",
"this",
"->",
"_header",
")",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"_toBase64url",
"(",
"$",
"this",
"->",
"_toJson",
"(",
"$",
"this",
"->",
"_claims",
")",
")",
";",
"return",
"sprintf",
"(",
"\"%s.%s\"",
",",
"$",
"header",
",",
"$",
"payload",
")",
";",
"}"
] | Encode to a JWT string
This method returns the text representation of the name/value pair defined in the JWT token. First segment is
the name/value pairs of the header segment and the second segment is the collection of the name/value pair of
the claim segment.
By default tokens expire 24 hours after they have been issued. To change this set a different expire time.
@return string A serialised JWT token string | [
"Encode",
"to",
"a",
"JWT",
"string"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/http/token/token.php#L405-L422 |
29,242 | locomotivemtl/charcoal-core | src/Charcoal/Model/ModelLoaderBuilderTrait.php | ModelLoaderBuilderTrait.modelLoaderBuilder | protected function modelLoaderBuilder()
{
if (!isset($this->modelLoaderBuilder)) {
throw new RuntimeException(sprintf(
'Model Factory is not defined for [%s]',
get_class($this)
));
}
return $this->modelLoaderBuilder;
} | php | protected function modelLoaderBuilder()
{
if (!isset($this->modelLoaderBuilder)) {
throw new RuntimeException(sprintf(
'Model Factory is not defined for [%s]',
get_class($this)
));
}
return $this->modelLoaderBuilder;
} | [
"protected",
"function",
"modelLoaderBuilder",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"modelLoaderBuilder",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Model Factory is not defined for [%s]'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"modelLoaderBuilder",
";",
"}"
] | Retrieve the model loader builder.
@throws RuntimeException If the model loader builder is missing.
@return ModelLoaderBuilder | [
"Retrieve",
"the",
"model",
"loader",
"builder",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/ModelLoaderBuilderTrait.php#L51-L61 |
29,243 | locomotivemtl/charcoal-core | src/Charcoal/Model/ModelLoaderBuilderTrait.php | ModelLoaderBuilderTrait.modelLoader | protected function modelLoader($objType, $objKey = null)
{
if (!is_string($objType)) {
throw new InvalidArgumentException(sprintf(
'The object type must be a string, received %s',
is_object($objType) ? get_class($objType) : gettype($objType)
));
}
$key = $objKey;
if ($key === null) {
$key = '_';
} elseif (!is_string($key)) {
throw new InvalidArgumentException(sprintf(
'The object property key must be a string, received %s',
is_object($key) ? get_class($key) : gettype($key)
));
}
if (isset(self::$modelLoaders[$objType][$key])) {
return self::$modelLoaders[$objType][$key];
}
$builder = $this->modelLoaderBuilder();
self::$modelLoaders[$objType][$key] = $builder($objType, $objKey);
return self::$modelLoaders[$objType][$key];
} | php | protected function modelLoader($objType, $objKey = null)
{
if (!is_string($objType)) {
throw new InvalidArgumentException(sprintf(
'The object type must be a string, received %s',
is_object($objType) ? get_class($objType) : gettype($objType)
));
}
$key = $objKey;
if ($key === null) {
$key = '_';
} elseif (!is_string($key)) {
throw new InvalidArgumentException(sprintf(
'The object property key must be a string, received %s',
is_object($key) ? get_class($key) : gettype($key)
));
}
if (isset(self::$modelLoaders[$objType][$key])) {
return self::$modelLoaders[$objType][$key];
}
$builder = $this->modelLoaderBuilder();
self::$modelLoaders[$objType][$key] = $builder($objType, $objKey);
return self::$modelLoaders[$objType][$key];
} | [
"protected",
"function",
"modelLoader",
"(",
"$",
"objType",
",",
"$",
"objKey",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"objType",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The object type must be a string, received %s'",
",",
"is_object",
"(",
"$",
"objType",
")",
"?",
"get_class",
"(",
"$",
"objType",
")",
":",
"gettype",
"(",
"$",
"objType",
")",
")",
")",
";",
"}",
"$",
"key",
"=",
"$",
"objKey",
";",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"key",
"=",
"'_'",
";",
"}",
"elseif",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The object property key must be a string, received %s'",
",",
"is_object",
"(",
"$",
"key",
")",
"?",
"get_class",
"(",
"$",
"key",
")",
":",
"gettype",
"(",
"$",
"key",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"modelLoaders",
"[",
"$",
"objType",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"modelLoaders",
"[",
"$",
"objType",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"builder",
"=",
"$",
"this",
"->",
"modelLoaderBuilder",
"(",
")",
";",
"self",
"::",
"$",
"modelLoaders",
"[",
"$",
"objType",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"builder",
"(",
"$",
"objType",
",",
"$",
"objKey",
")",
";",
"return",
"self",
"::",
"$",
"modelLoaders",
"[",
"$",
"objType",
"]",
"[",
"$",
"key",
"]",
";",
"}"
] | Retrieve the object loader for the given model.
@param string $objType The target model.
@param string|null $objKey The target model's key to load by.
@throws InvalidArgumentException If the $objType or $objKey are invalid.
@return ModelInterface | [
"Retrieve",
"the",
"object",
"loader",
"for",
"the",
"given",
"model",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Model/ModelLoaderBuilderTrait.php#L71-L99 |
29,244 | deArcane/framework | src/Debugger/Report/Container.php | Container.add | public function add(INotification $note){
switch( $note->position ){
case Blueprint::TOP:
$this->top($note);
return;
case Blueprint::MIDDLE:
$this->middle($note);
return;
case Blueprint::BOTTOM:
$this->bottom($note);
return;
default:
$this->middle($note);
return;
}
} | php | public function add(INotification $note){
switch( $note->position ){
case Blueprint::TOP:
$this->top($note);
return;
case Blueprint::MIDDLE:
$this->middle($note);
return;
case Blueprint::BOTTOM:
$this->bottom($note);
return;
default:
$this->middle($note);
return;
}
} | [
"public",
"function",
"add",
"(",
"INotification",
"$",
"note",
")",
"{",
"switch",
"(",
"$",
"note",
"->",
"position",
")",
"{",
"case",
"Blueprint",
"::",
"TOP",
":",
"$",
"this",
"->",
"top",
"(",
"$",
"note",
")",
";",
"return",
";",
"case",
"Blueprint",
"::",
"MIDDLE",
":",
"$",
"this",
"->",
"middle",
"(",
"$",
"note",
")",
";",
"return",
";",
"case",
"Blueprint",
"::",
"BOTTOM",
":",
"$",
"this",
"->",
"bottom",
"(",
"$",
"note",
")",
";",
"return",
";",
"default",
":",
"$",
"this",
"->",
"middle",
"(",
"$",
"note",
")",
";",
"return",
";",
"}",
"}"
] | Yes, this looks like something is hard coded. We want this. | [
"Yes",
"this",
"looks",
"like",
"something",
"is",
"hard",
"coded",
".",
"We",
"want",
"this",
"."
] | 468da43678119f8c9e3f67183b5bec727c436404 | https://github.com/deArcane/framework/blob/468da43678119f8c9e3f67183b5bec727c436404/src/Debugger/Report/Container.php#L20-L38 |
29,245 | timble/kodekit | code/dispatcher/behavior/resettable.php | DispatcherBehaviorResettable._beforeSend | protected function _beforeSend(DispatcherContext $context)
{
$response = $context->response;
$request = $context->request;
if($response->isSuccess() && $referrer = $request->getReferrer()) {
$response->setRedirect($referrer);
}
} | php | protected function _beforeSend(DispatcherContext $context)
{
$response = $context->response;
$request = $context->request;
if($response->isSuccess() && $referrer = $request->getReferrer()) {
$response->setRedirect($referrer);
}
} | [
"protected",
"function",
"_beforeSend",
"(",
"DispatcherContext",
"$",
"context",
")",
"{",
"$",
"response",
"=",
"$",
"context",
"->",
"response",
";",
"$",
"request",
"=",
"$",
"context",
"->",
"request",
";",
"if",
"(",
"$",
"response",
"->",
"isSuccess",
"(",
")",
"&&",
"$",
"referrer",
"=",
"$",
"request",
"->",
"getReferrer",
"(",
")",
")",
"{",
"$",
"response",
"->",
"setRedirect",
"(",
"$",
"referrer",
")",
";",
"}",
"}"
] | Force a GET after POST using the referrer
Redirect if the controller has a returned a 2xx status code.
@param DispatcherContext $context The active command context
@return void | [
"Force",
"a",
"GET",
"after",
"POST",
"using",
"the",
"referrer"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/behavior/resettable.php#L43-L51 |
29,246 | timble/kodekit | code/dispatcher/abstract.php | DispatcherAbstract._actionFail | protected function _actionFail(DispatcherContext $context)
{
//Check an exception was passed
if(!isset($context->param) && !$context->param instanceof \Exception)
{
throw new \InvalidArgumentException(
"Action parameter 'exception' [Exception] is required"
);
}
//Get the exception object
$exception = $context->param;
//If the error code does not correspond to a status message, use 500
$code = $exception->getCode();
if(!isset(HttpResponse::$status_messages[$code])) {
$code = '500';
}
//Get the error message
$message = $exception->getMessage();
if(empty($message)) {
$message = HttpResponse::$status_messages[$code];
}
//Store the exception in the context
$context->exception = $exception;
//Set the response status
$context->response->setStatus($code , $message);
//Send the response
return $this->send($context);
} | php | protected function _actionFail(DispatcherContext $context)
{
//Check an exception was passed
if(!isset($context->param) && !$context->param instanceof \Exception)
{
throw new \InvalidArgumentException(
"Action parameter 'exception' [Exception] is required"
);
}
//Get the exception object
$exception = $context->param;
//If the error code does not correspond to a status message, use 500
$code = $exception->getCode();
if(!isset(HttpResponse::$status_messages[$code])) {
$code = '500';
}
//Get the error message
$message = $exception->getMessage();
if(empty($message)) {
$message = HttpResponse::$status_messages[$code];
}
//Store the exception in the context
$context->exception = $exception;
//Set the response status
$context->response->setStatus($code , $message);
//Send the response
return $this->send($context);
} | [
"protected",
"function",
"_actionFail",
"(",
"DispatcherContext",
"$",
"context",
")",
"{",
"//Check an exception was passed",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"->",
"param",
")",
"&&",
"!",
"$",
"context",
"->",
"param",
"instanceof",
"\\",
"Exception",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Action parameter 'exception' [Exception] is required\"",
")",
";",
"}",
"//Get the exception object",
"$",
"exception",
"=",
"$",
"context",
"->",
"param",
";",
"//If the error code does not correspond to a status message, use 500",
"$",
"code",
"=",
"$",
"exception",
"->",
"getCode",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"HttpResponse",
"::",
"$",
"status_messages",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"code",
"=",
"'500'",
";",
"}",
"//Get the error message",
"$",
"message",
"=",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"$",
"message",
"=",
"HttpResponse",
"::",
"$",
"status_messages",
"[",
"$",
"code",
"]",
";",
"}",
"//Store the exception in the context",
"$",
"context",
"->",
"exception",
"=",
"$",
"exception",
";",
"//Set the response status",
"$",
"context",
"->",
"response",
"->",
"setStatus",
"(",
"$",
"code",
",",
"$",
"message",
")",
";",
"//Send the response",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"context",
")",
";",
"}"
] | Handle errors and exceptions
@throws \InvalidArgumentException If the action parameter is not an instance of Exception or ExceptionError
@param DispatcherContext $context A dispatcher context object | [
"Handle",
"errors",
"and",
"exceptions"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/abstract.php#L342-L375 |
29,247 | timble/kodekit | code/object/decorator/abstract.php | ObjectDecoratorAbstract.setDelegate | public function setDelegate($delegate)
{
if (!is_object($delegate)) {
throw new \InvalidArgumentException('Delegate needs to be an object, '.gettype($delegate).' given');
}
$this->__delegate = $delegate;
return $this;
} | php | public function setDelegate($delegate)
{
if (!is_object($delegate)) {
throw new \InvalidArgumentException('Delegate needs to be an object, '.gettype($delegate).' given');
}
$this->__delegate = $delegate;
return $this;
} | [
"public",
"function",
"setDelegate",
"(",
"$",
"delegate",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"delegate",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Delegate needs to be an object, '",
".",
"gettype",
"(",
"$",
"delegate",
")",
".",
"' given'",
")",
";",
"}",
"$",
"this",
"->",
"__delegate",
"=",
"$",
"delegate",
";",
"return",
"$",
"this",
";",
"}"
] | Set the decorated object
@param object $delegate The decorated object
@return ObjectDecoratorAbstract
@throws \InvalidArgumentException If the delegate is not an object | [
"Set",
"the",
"decorated",
"object"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/decorator/abstract.php#L85-L93 |
29,248 | timble/kodekit | code/object/decorator/abstract.php | ObjectDecoratorAbstract.isMixedMethod | public function isMixedMethod($name)
{
$result = false;
$delegate = $this->getDelegate();
if (!($delegate instanceof ObjectMixable)) {
$result = $delegate->isMixedMethod($name);
}
return $result;
} | php | public function isMixedMethod($name)
{
$result = false;
$delegate = $this->getDelegate();
if (!($delegate instanceof ObjectMixable)) {
$result = $delegate->isMixedMethod($name);
}
return $result;
} | [
"public",
"function",
"isMixedMethod",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"delegate",
"=",
"$",
"this",
"->",
"getDelegate",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"delegate",
"instanceof",
"ObjectMixable",
")",
")",
"{",
"$",
"result",
"=",
"$",
"delegate",
"->",
"isMixedMethod",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Check if a mixed method exists
@param string $name The name of the method
@return mixed | [
"Check",
"if",
"a",
"mixed",
"method",
"exists"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/object/decorator/abstract.php#L165-L175 |
29,249 | locomotivemtl/charcoal-core | src/Charcoal/Source/FilterCollectionTrait.php | FilterCollectionTrait.addFilters | public function addFilters(array $filters)
{
foreach ($filters as $key => $filter) {
$this->addFilter($filter);
/** Name the expression if $key is a non-numeric string. */
if (is_string($key) && !is_numeric($key)) {
$filter = end($this->filters);
$filter->setName($key);
}
}
return $this;
} | php | public function addFilters(array $filters)
{
foreach ($filters as $key => $filter) {
$this->addFilter($filter);
/** Name the expression if $key is a non-numeric string. */
if (is_string($key) && !is_numeric($key)) {
$filter = end($this->filters);
$filter->setName($key);
}
}
return $this;
} | [
"public",
"function",
"addFilters",
"(",
"array",
"$",
"filters",
")",
"{",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"key",
"=>",
"$",
"filter",
")",
"{",
"$",
"this",
"->",
"addFilter",
"(",
"$",
"filter",
")",
";",
"/** Name the expression if $key is a non-numeric string. */",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"filter",
"=",
"end",
"(",
"$",
"this",
"->",
"filters",
")",
";",
"$",
"filter",
"->",
"setName",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Append one or more query filters on this object.
@uses self::processFilter()
@param mixed[] $filters One or more filters to add on this expression.
@return self | [
"Append",
"one",
"or",
"more",
"query",
"filters",
"on",
"this",
"object",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/FilterCollectionTrait.php#L51-L64 |
29,250 | locomotivemtl/charcoal-core | src/Charcoal/Source/FilterCollectionTrait.php | FilterCollectionTrait.processFilter | protected function processFilter($filter)
{
if (!is_string($filter) && is_callable($filter)) {
$expr = $this->createFilter();
/**
* @param FilterInterface $expr The new filter expression object.
* @param FilterCollectionInterface $this The context of the collection.
* @return string|array|FilterInterface The prepared filter expression
* string, structure, object.
*/
$filter = $filter($expr, $this);
}
if (is_string($filter)) {
$expr = $this->createFilter()->setCondition($filter);
$filter = $expr;
} elseif (is_array($filter)) {
$expr = $this->createFilter()->setData($filter);
$filter = $expr;
}
/** Append the filter to the expression's stack. */
if ($filter instanceof FilterInterface) {
return $filter;
}
throw new InvalidArgumentException(sprintf(
'Filter must be a string, structure, or Expression object; received %s',
is_object($filter) ? get_class($filter) : gettype($filter)
));
} | php | protected function processFilter($filter)
{
if (!is_string($filter) && is_callable($filter)) {
$expr = $this->createFilter();
/**
* @param FilterInterface $expr The new filter expression object.
* @param FilterCollectionInterface $this The context of the collection.
* @return string|array|FilterInterface The prepared filter expression
* string, structure, object.
*/
$filter = $filter($expr, $this);
}
if (is_string($filter)) {
$expr = $this->createFilter()->setCondition($filter);
$filter = $expr;
} elseif (is_array($filter)) {
$expr = $this->createFilter()->setData($filter);
$filter = $expr;
}
/** Append the filter to the expression's stack. */
if ($filter instanceof FilterInterface) {
return $filter;
}
throw new InvalidArgumentException(sprintf(
'Filter must be a string, structure, or Expression object; received %s',
is_object($filter) ? get_class($filter) : gettype($filter)
));
} | [
"protected",
"function",
"processFilter",
"(",
"$",
"filter",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"filter",
")",
"&&",
"is_callable",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"createFilter",
"(",
")",
";",
"/**\n * @param FilterInterface $expr The new filter expression object.\n * @param FilterCollectionInterface $this The context of the collection.\n * @return string|array|FilterInterface The prepared filter expression\n * string, structure, object.\n */",
"$",
"filter",
"=",
"$",
"filter",
"(",
"$",
"expr",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"createFilter",
"(",
")",
"->",
"setCondition",
"(",
"$",
"filter",
")",
";",
"$",
"filter",
"=",
"$",
"expr",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"createFilter",
"(",
")",
"->",
"setData",
"(",
"$",
"filter",
")",
";",
"$",
"filter",
"=",
"$",
"expr",
";",
"}",
"/** Append the filter to the expression's stack. */",
"if",
"(",
"$",
"filter",
"instanceof",
"FilterInterface",
")",
"{",
"return",
"$",
"filter",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Filter must be a string, structure, or Expression object; received %s'",
",",
"is_object",
"(",
"$",
"filter",
")",
"?",
"get_class",
"(",
"$",
"filter",
")",
":",
"gettype",
"(",
"$",
"filter",
")",
")",
")",
";",
"}"
] | Process a query filter to build a tree of expressions.
Implement in subclasses to dynamically parse filters before being appended.
@param mixed $filter The expression string, structure, object, or callable to be parsed.
@throws InvalidArgumentException If a filter is not a string, array, object, or callable.
@return FilterInterface | [
"Process",
"a",
"query",
"filter",
"to",
"build",
"a",
"tree",
"of",
"expressions",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/FilterCollectionTrait.php#L88-L118 |
29,251 | locomotivemtl/charcoal-core | src/Charcoal/Source/FilterCollectionTrait.php | FilterCollectionTrait.traverseFilters | public function traverseFilters(callable $callable)
{
foreach ($this->filters() as $expr) {
/**
* @param FilterInterface $expr The iterated filter expression object.
* @param FilterCollectionInterface $this The context of the traversal.
* @return void
*/
$callable($expr, $this);
if ($expr instanceof FilterCollectionInterface) {
$expr->traverseFilters($callable);
}
}
return $this;
} | php | public function traverseFilters(callable $callable)
{
foreach ($this->filters() as $expr) {
/**
* @param FilterInterface $expr The iterated filter expression object.
* @param FilterCollectionInterface $this The context of the traversal.
* @return void
*/
$callable($expr, $this);
if ($expr instanceof FilterCollectionInterface) {
$expr->traverseFilters($callable);
}
}
return $this;
} | [
"public",
"function",
"traverseFilters",
"(",
"callable",
"$",
"callable",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"(",
")",
"as",
"$",
"expr",
")",
"{",
"/**\n * @param FilterInterface $expr The iterated filter expression object.\n * @param FilterCollectionInterface $this The context of the traversal.\n * @return void\n */",
"$",
"callable",
"(",
"$",
"expr",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"expr",
"instanceof",
"FilterCollectionInterface",
")",
"{",
"$",
"expr",
"->",
"traverseFilters",
"(",
"$",
"callable",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Traverses the tree of query filters and applies a user function to every expression.
@param callable $callable The function to run for each expression.
@return self | [
"Traverses",
"the",
"tree",
"of",
"query",
"filters",
"and",
"applies",
"a",
"user",
"function",
"to",
"every",
"expression",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/FilterCollectionTrait.php#L146-L161 |
29,252 | rosasurfer/ministruts | src/db/sqlite/SQLiteResult.php | SQLiteResult.fetchRow | public function fetchRow($mode = ARRAY_BOTH) {
if (!$this->result || $this->nextRowIndex < 0) // no automatic result reset()
return null;
switch ($mode) {
case ARRAY_ASSOC: $mode = SQLITE3_ASSOC; break;
case ARRAY_NUM: $mode = SQLITE3_NUM; break;
default: $mode = SQLITE3_BOTH;
}
$row = $this->result->fetchArray($mode);
if ($row) {
$this->nextRowIndex++;
}
else {
if ($this->numRows === null) // update $numRows on-the-fly if not yet happened
$this->numRows = $this->nextRowIndex;
$row = null; // prevent fetchArray() to trigger an automatic reset()
$this->nextRowIndex = -1; // on second $row == null
}
return $row;
} | php | public function fetchRow($mode = ARRAY_BOTH) {
if (!$this->result || $this->nextRowIndex < 0) // no automatic result reset()
return null;
switch ($mode) {
case ARRAY_ASSOC: $mode = SQLITE3_ASSOC; break;
case ARRAY_NUM: $mode = SQLITE3_NUM; break;
default: $mode = SQLITE3_BOTH;
}
$row = $this->result->fetchArray($mode);
if ($row) {
$this->nextRowIndex++;
}
else {
if ($this->numRows === null) // update $numRows on-the-fly if not yet happened
$this->numRows = $this->nextRowIndex;
$row = null; // prevent fetchArray() to trigger an automatic reset()
$this->nextRowIndex = -1; // on second $row == null
}
return $row;
} | [
"public",
"function",
"fetchRow",
"(",
"$",
"mode",
"=",
"ARRAY_BOTH",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"result",
"||",
"$",
"this",
"->",
"nextRowIndex",
"<",
"0",
")",
"// no automatic result reset()",
"return",
"null",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"ARRAY_ASSOC",
":",
"$",
"mode",
"=",
"SQLITE3_ASSOC",
";",
"break",
";",
"case",
"ARRAY_NUM",
":",
"$",
"mode",
"=",
"SQLITE3_NUM",
";",
"break",
";",
"default",
":",
"$",
"mode",
"=",
"SQLITE3_BOTH",
";",
"}",
"$",
"row",
"=",
"$",
"this",
"->",
"result",
"->",
"fetchArray",
"(",
"$",
"mode",
")",
";",
"if",
"(",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"nextRowIndex",
"++",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"numRows",
"===",
"null",
")",
"// update $numRows on-the-fly if not yet happened",
"$",
"this",
"->",
"numRows",
"=",
"$",
"this",
"->",
"nextRowIndex",
";",
"$",
"row",
"=",
"null",
";",
"// prevent fetchArray() to trigger an automatic reset()",
"$",
"this",
"->",
"nextRowIndex",
"=",
"-",
"1",
";",
"// on second $row == null",
"}",
"return",
"$",
"row",
";",
"}"
] | Fetch the next row from the result set.
The types of the values of the returned array are mapped from SQLite3 types as follows: <br>
- Integers are mapped to int if they fit into the range PHP_INT_MIN...PHP_INT_MAX, otherwise to string. <br>
- Floats are mapped to float. <br>
- NULL values are mapped to NULL. <br>
- Strings and blobs are mapped to string. <br>
{@inheritdoc} | [
"Fetch",
"the",
"next",
"row",
"from",
"the",
"result",
"set",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/sqlite/SQLiteResult.php#L81-L102 |
29,253 | timble/kodekit | code/template/filter/block.php | TemplateFilterBlock.addBlock | public function addBlock($name, array $data)
{
if(!isset($this->__blocks[$name])) {
$this->__blocks[$name] = array();
}
$this->__blocks[$name][] = $data;
return $this;
} | php | public function addBlock($name, array $data)
{
if(!isset($this->__blocks[$name])) {
$this->__blocks[$name] = array();
}
$this->__blocks[$name][] = $data;
return $this;
} | [
"public",
"function",
"addBlock",
"(",
"$",
"name",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Add a block
@param string $name The name of the block
@param array $data The data of the block
@return TemplateFilterBlock | [
"Add",
"a",
"block"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/filter/block.php#L62-L71 |
29,254 | timble/kodekit | code/template/filter/block.php | TemplateFilterBlock.getBlocks | public function getBlocks($name)
{
$result = array();
if(isset($this->__blocks[$name])) {
$result = $this->__blocks[$name];
}
return $result;
} | php | public function getBlocks($name)
{
$result = array();
if(isset($this->__blocks[$name])) {
$result = $this->__blocks[$name];
}
return $result;
} | [
"public",
"function",
"getBlocks",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the blocks by name
@param $name
@return array List of blocks | [
"Get",
"the",
"blocks",
"by",
"name"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/filter/block.php#L79-L88 |
29,255 | timble/kodekit | code/template/filter/block.php | TemplateFilterBlock.hasBlocks | public function hasBlocks($name)
{
return isset($this->__blocks[$name]) && !empty($this->__blocks[$name]);
} | php | public function hasBlocks($name)
{
return isset($this->__blocks[$name]) && !empty($this->__blocks[$name]);
} | [
"public",
"function",
"hasBlocks",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"__blocks",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Check if blocks exists
@param $name
@return bool TRUE if blocks exist, FALSE otherwise | [
"Check",
"if",
"blocks",
"exists"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/filter/block.php#L96-L99 |
29,256 | timble/kodekit | code/template/filter/block.php | TemplateFilterBlock._renderBlocks | protected function _renderBlocks($name, $attribs = array())
{
$html = '';
$count = 1;
$blocks = $this->getBlocks($name);
foreach($blocks as $block)
{
//Set the block attributes
if($count == 1) {
$attribs['rel']['first'] = 'first';
}
if($count == count($blocks)) {
$attribs['rel']['last'] = 'last';
}
if(isset($block['attribs'])) {
$block['attribs'] = array_merge((array) $block['attribs'], $attribs);
} else {
$block['attribs'] = $attribs;
}
//Render the block
$content = $this->_renderBlock($block);
//Prepend or append the block
if($block['extend'] == 'prepend') {
$html = $content.$html;
} else {
$html = $html.$content;
}
$count++;
}
return $html;
} | php | protected function _renderBlocks($name, $attribs = array())
{
$html = '';
$count = 1;
$blocks = $this->getBlocks($name);
foreach($blocks as $block)
{
//Set the block attributes
if($count == 1) {
$attribs['rel']['first'] = 'first';
}
if($count == count($blocks)) {
$attribs['rel']['last'] = 'last';
}
if(isset($block['attribs'])) {
$block['attribs'] = array_merge((array) $block['attribs'], $attribs);
} else {
$block['attribs'] = $attribs;
}
//Render the block
$content = $this->_renderBlock($block);
//Prepend or append the block
if($block['extend'] == 'prepend') {
$html = $content.$html;
} else {
$html = $html.$content;
}
$count++;
}
return $html;
} | [
"protected",
"function",
"_renderBlocks",
"(",
"$",
"name",
",",
"$",
"attribs",
"=",
"array",
"(",
")",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"count",
"=",
"1",
";",
"$",
"blocks",
"=",
"$",
"this",
"->",
"getBlocks",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"block",
")",
"{",
"//Set the block attributes",
"if",
"(",
"$",
"count",
"==",
"1",
")",
"{",
"$",
"attribs",
"[",
"'rel'",
"]",
"[",
"'first'",
"]",
"=",
"'first'",
";",
"}",
"if",
"(",
"$",
"count",
"==",
"count",
"(",
"$",
"blocks",
")",
")",
"{",
"$",
"attribs",
"[",
"'rel'",
"]",
"[",
"'last'",
"]",
"=",
"'last'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"block",
"[",
"'attribs'",
"]",
")",
")",
"{",
"$",
"block",
"[",
"'attribs'",
"]",
"=",
"array_merge",
"(",
"(",
"array",
")",
"$",
"block",
"[",
"'attribs'",
"]",
",",
"$",
"attribs",
")",
";",
"}",
"else",
"{",
"$",
"block",
"[",
"'attribs'",
"]",
"=",
"$",
"attribs",
";",
"}",
"//Render the block",
"$",
"content",
"=",
"$",
"this",
"->",
"_renderBlock",
"(",
"$",
"block",
")",
";",
"//Prepend or append the block",
"if",
"(",
"$",
"block",
"[",
"'extend'",
"]",
"==",
"'prepend'",
")",
"{",
"$",
"html",
"=",
"$",
"content",
".",
"$",
"html",
";",
"}",
"else",
"{",
"$",
"html",
"=",
"$",
"html",
".",
"$",
"content",
";",
"}",
"$",
"count",
"++",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | Render the blocks
@param array $name The name of the block
@param array $attribs List of block attributes
@return string The rendered block | [
"Render",
"the",
"blocks"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/template/filter/block.php#L241-L278 |
29,257 | rosasurfer/ministruts | src/config/Config.php | Config.loadFile | protected function loadFile($filename) {
$lines = file($filename, FILE_IGNORE_NEW_LINES); // don't use FILE_SKIP_EMPTY_LINES to have correct line
// numbers for error messages
if ($lines && strStartsWith($lines[0], "\xEF\xBB\xBF")) {
$lines[0] = substr($lines[0], 3); // detect and drop a possible BOM header
}
foreach ($lines as $i => $line) {
$line = trim($line);
if (!strlen($line) || $line[0]=='#') // skip empty and comment lines
continue;
$parts = explode('=', $line, 2); // split key/value
if (sizeof($parts) < 2) {
// Don't trigger a regular error as it will cause an infinite loop if the same config is used by the error handler.
$msg = __METHOD__.'() Skipping syntax error in "'.$filename.'", line '.($i+1).': missing key-value separator';
stderr($msg);
error_log($msg, ERROR_LOG_DEFAULT);
continue;
}
$key = trim($parts[0]);
$rawValue = trim($parts[1]);
// drop possible comments
if (strpos($rawValue, '#')!==false && strlen($comment=$this->getLineComment($rawValue))) {
$value = trim(strLeft($rawValue, -strlen($comment)));
}
else {
$value = $rawValue;
}
// parse and store property value
$this->setProperty($key, $value);
}
return true;
} | php | protected function loadFile($filename) {
$lines = file($filename, FILE_IGNORE_NEW_LINES); // don't use FILE_SKIP_EMPTY_LINES to have correct line
// numbers for error messages
if ($lines && strStartsWith($lines[0], "\xEF\xBB\xBF")) {
$lines[0] = substr($lines[0], 3); // detect and drop a possible BOM header
}
foreach ($lines as $i => $line) {
$line = trim($line);
if (!strlen($line) || $line[0]=='#') // skip empty and comment lines
continue;
$parts = explode('=', $line, 2); // split key/value
if (sizeof($parts) < 2) {
// Don't trigger a regular error as it will cause an infinite loop if the same config is used by the error handler.
$msg = __METHOD__.'() Skipping syntax error in "'.$filename.'", line '.($i+1).': missing key-value separator';
stderr($msg);
error_log($msg, ERROR_LOG_DEFAULT);
continue;
}
$key = trim($parts[0]);
$rawValue = trim($parts[1]);
// drop possible comments
if (strpos($rawValue, '#')!==false && strlen($comment=$this->getLineComment($rawValue))) {
$value = trim(strLeft($rawValue, -strlen($comment)));
}
else {
$value = $rawValue;
}
// parse and store property value
$this->setProperty($key, $value);
}
return true;
} | [
"protected",
"function",
"loadFile",
"(",
"$",
"filename",
")",
"{",
"$",
"lines",
"=",
"file",
"(",
"$",
"filename",
",",
"FILE_IGNORE_NEW_LINES",
")",
";",
"// don't use FILE_SKIP_EMPTY_LINES to have correct line",
"// numbers for error messages",
"if",
"(",
"$",
"lines",
"&&",
"strStartsWith",
"(",
"$",
"lines",
"[",
"0",
"]",
",",
"\"\\xEF\\xBB\\xBF\"",
")",
")",
"{",
"$",
"lines",
"[",
"0",
"]",
"=",
"substr",
"(",
"$",
"lines",
"[",
"0",
"]",
",",
"3",
")",
";",
"// detect and drop a possible BOM header",
"}",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"i",
"=>",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"$",
"line",
")",
"||",
"$",
"line",
"[",
"0",
"]",
"==",
"'#'",
")",
"// skip empty and comment lines",
"continue",
";",
"$",
"parts",
"=",
"explode",
"(",
"'='",
",",
"$",
"line",
",",
"2",
")",
";",
"// split key/value",
"if",
"(",
"sizeof",
"(",
"$",
"parts",
")",
"<",
"2",
")",
"{",
"// Don't trigger a regular error as it will cause an infinite loop if the same config is used by the error handler.",
"$",
"msg",
"=",
"__METHOD__",
".",
"'() Skipping syntax error in \"'",
".",
"$",
"filename",
".",
"'\", line '",
".",
"(",
"$",
"i",
"+",
"1",
")",
".",
"': missing key-value separator'",
";",
"stderr",
"(",
"$",
"msg",
")",
";",
"error_log",
"(",
"$",
"msg",
",",
"ERROR_LOG_DEFAULT",
")",
";",
"continue",
";",
"}",
"$",
"key",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"$",
"rawValue",
"=",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"// drop possible comments",
"if",
"(",
"strpos",
"(",
"$",
"rawValue",
",",
"'#'",
")",
"!==",
"false",
"&&",
"strlen",
"(",
"$",
"comment",
"=",
"$",
"this",
"->",
"getLineComment",
"(",
"$",
"rawValue",
")",
")",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"strLeft",
"(",
"$",
"rawValue",
",",
"-",
"strlen",
"(",
"$",
"comment",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"rawValue",
";",
"}",
"// parse and store property value",
"$",
"this",
"->",
"setProperty",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Load a single properties file. New settings overwrite existing ones.
@param string $filename
@return bool - success status | [
"Load",
"a",
"single",
"properties",
"file",
".",
"New",
"settings",
"overwrite",
"existing",
"ones",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L103-L138 |
29,258 | rosasurfer/ministruts | src/config/Config.php | Config.get | public function get($key, $default = null) {
if (!is_string($key)) throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
// TODO: a numerically indexed property array will have integer keys
$notFound = false;
$value = $this->getProperty($key, $notFound);
if ($notFound) {
if (func_num_args() == 1) throw new RuntimeException('No configuration found for key "'.$key.'"');
return $default;
}
return $value;
} | php | public function get($key, $default = null) {
if (!is_string($key)) throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
// TODO: a numerically indexed property array will have integer keys
$notFound = false;
$value = $this->getProperty($key, $notFound);
if ($notFound) {
if (func_num_args() == 1) throw new RuntimeException('No configuration found for key "'.$key.'"');
return $default;
}
return $value;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"throw",
"new",
"IllegalTypeException",
"(",
"'Illegal type of parameter $key: '",
".",
"gettype",
"(",
"$",
"key",
")",
")",
";",
"// TODO: a numerically indexed property array will have integer keys",
"$",
"notFound",
"=",
"false",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"key",
",",
"$",
"notFound",
")",
";",
"if",
"(",
"$",
"notFound",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"==",
"1",
")",
"throw",
"new",
"RuntimeException",
"(",
"'No configuration found for key \"'",
".",
"$",
"key",
".",
"'\"'",
")",
";",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Return the config setting with the specified key or the default value if no such setting is found.
@param string $key - case-insensitive key
@param mixed $default [optional] - default value
@return mixed - config setting | [
"Return",
"the",
"config",
"setting",
"with",
"the",
"specified",
"key",
"or",
"the",
"default",
"value",
"if",
"no",
"such",
"setting",
"is",
"found",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L189-L201 |
29,259 | rosasurfer/ministruts | src/config/Config.php | Config.getProperty | protected function getProperty($key, &$notFound) {
$properties = $this->properties;
$subkeys = $this->parseSubkeys(strtolower($key));
$subKeysSize = sizeof($subkeys);
$notFound = false;
for ($i=0; $i < $subKeysSize; ++$i) {
$subkey = trim($subkeys[$i]);
if (!is_array($properties) || !key_exists($subkey, $properties))
break; // not found
if ($i+1 == $subKeysSize) // return at the last subkey
return $properties[$subkey];
$properties = $properties[$subkey]; // go to the next sublevel
}
$notFound = true;
return null;
} | php | protected function getProperty($key, &$notFound) {
$properties = $this->properties;
$subkeys = $this->parseSubkeys(strtolower($key));
$subKeysSize = sizeof($subkeys);
$notFound = false;
for ($i=0; $i < $subKeysSize; ++$i) {
$subkey = trim($subkeys[$i]);
if (!is_array($properties) || !key_exists($subkey, $properties))
break; // not found
if ($i+1 == $subKeysSize) // return at the last subkey
return $properties[$subkey];
$properties = $properties[$subkey]; // go to the next sublevel
}
$notFound = true;
return null;
} | [
"protected",
"function",
"getProperty",
"(",
"$",
"key",
",",
"&",
"$",
"notFound",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"properties",
";",
"$",
"subkeys",
"=",
"$",
"this",
"->",
"parseSubkeys",
"(",
"strtolower",
"(",
"$",
"key",
")",
")",
";",
"$",
"subKeysSize",
"=",
"sizeof",
"(",
"$",
"subkeys",
")",
";",
"$",
"notFound",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"subKeysSize",
";",
"++",
"$",
"i",
")",
"{",
"$",
"subkey",
"=",
"trim",
"(",
"$",
"subkeys",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"properties",
")",
"||",
"!",
"key_exists",
"(",
"$",
"subkey",
",",
"$",
"properties",
")",
")",
"break",
";",
"// not found",
"if",
"(",
"$",
"i",
"+",
"1",
"==",
"$",
"subKeysSize",
")",
"// return at the last subkey",
"return",
"$",
"properties",
"[",
"$",
"subkey",
"]",
";",
"$",
"properties",
"=",
"$",
"properties",
"[",
"$",
"subkey",
"]",
";",
"// go to the next sublevel",
"}",
"$",
"notFound",
"=",
"true",
";",
"return",
"null",
";",
"}"
] | Look-up a property and return its value.
@param string $key - property key
@param bool $notFound - reference to a flag indicating whether the property was found
@return mixed - Property value (including NULL) or NULL if no such property was found. If NULL is returned the flag
$notFound must be checked to find out whether the property was found. | [
"Look",
"-",
"up",
"a",
"property",
"and",
"return",
"its",
"value",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L278-L295 |
29,260 | rosasurfer/ministruts | src/config/Config.php | Config.parseSubkeys | protected function parseSubkeys($key) {
$k = $key;
$subkeys = [];
$quoteChars = ["'", '"']; // single and double quotes
while (true) {
$k = trim($k);
foreach ($quoteChars as $char) {
if (strpos($k, $char) === 0) { // subkey starts with a quote char
$pos = strpos($k, $char, 1); // find the ending quote char
if ($pos === false) throw new InvalidArgumentException('Invalid argument $key: '.$key);
$subkeys[] = substr($k, 1, $pos-1);
$k = trim(substr($k, $pos+1));
if (!strlen($k)) // last subkey or next char is a key separator
break 2;
if (strpos($k, '.') !== 0) throw new InvalidArgumentException('Invalid argument $key: '.$key);
$k = substr($k, 1);
continue 2;
}
}
// key is not quoted
$pos = strpos($k, '.'); // find next key separator
if ($pos === false) {
$subkeys[] = $k; // last subkey
break;
}
$subkeys[] = trim(substr($k, 0, $pos));
$k = substr($k, $pos+1); // next subkey
}
return $subkeys;
} | php | protected function parseSubkeys($key) {
$k = $key;
$subkeys = [];
$quoteChars = ["'", '"']; // single and double quotes
while (true) {
$k = trim($k);
foreach ($quoteChars as $char) {
if (strpos($k, $char) === 0) { // subkey starts with a quote char
$pos = strpos($k, $char, 1); // find the ending quote char
if ($pos === false) throw new InvalidArgumentException('Invalid argument $key: '.$key);
$subkeys[] = substr($k, 1, $pos-1);
$k = trim(substr($k, $pos+1));
if (!strlen($k)) // last subkey or next char is a key separator
break 2;
if (strpos($k, '.') !== 0) throw new InvalidArgumentException('Invalid argument $key: '.$key);
$k = substr($k, 1);
continue 2;
}
}
// key is not quoted
$pos = strpos($k, '.'); // find next key separator
if ($pos === false) {
$subkeys[] = $k; // last subkey
break;
}
$subkeys[] = trim(substr($k, 0, $pos));
$k = substr($k, $pos+1); // next subkey
}
return $subkeys;
} | [
"protected",
"function",
"parseSubkeys",
"(",
"$",
"key",
")",
"{",
"$",
"k",
"=",
"$",
"key",
";",
"$",
"subkeys",
"=",
"[",
"]",
";",
"$",
"quoteChars",
"=",
"[",
"\"'\"",
",",
"'\"'",
"]",
";",
"// single and double quotes",
"while",
"(",
"true",
")",
"{",
"$",
"k",
"=",
"trim",
"(",
"$",
"k",
")",
";",
"foreach",
"(",
"$",
"quoteChars",
"as",
"$",
"char",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"k",
",",
"$",
"char",
")",
"===",
"0",
")",
"{",
"// subkey starts with a quote char",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"k",
",",
"$",
"char",
",",
"1",
")",
";",
"// find the ending quote char",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid argument $key: '",
".",
"$",
"key",
")",
";",
"$",
"subkeys",
"[",
"]",
"=",
"substr",
"(",
"$",
"k",
",",
"1",
",",
"$",
"pos",
"-",
"1",
")",
";",
"$",
"k",
"=",
"trim",
"(",
"substr",
"(",
"$",
"k",
",",
"$",
"pos",
"+",
"1",
")",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"$",
"k",
")",
")",
"// last subkey or next char is a key separator",
"break",
"2",
";",
"if",
"(",
"strpos",
"(",
"$",
"k",
",",
"'.'",
")",
"!==",
"0",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid argument $key: '",
".",
"$",
"key",
")",
";",
"$",
"k",
"=",
"substr",
"(",
"$",
"k",
",",
"1",
")",
";",
"continue",
"2",
";",
"}",
"}",
"// key is not quoted",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"k",
",",
"'.'",
")",
";",
"// find next key separator",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"$",
"subkeys",
"[",
"]",
"=",
"$",
"k",
";",
"// last subkey",
"break",
";",
"}",
"$",
"subkeys",
"[",
"]",
"=",
"trim",
"(",
"substr",
"(",
"$",
"k",
",",
"0",
",",
"$",
"pos",
")",
")",
";",
"$",
"k",
"=",
"substr",
"(",
"$",
"k",
",",
"$",
"pos",
"+",
"1",
")",
";",
"// next subkey",
"}",
"return",
"$",
"subkeys",
";",
"}"
] | Parse the specified key into subkeys. Subkeys can consist of quoted strings.
@param string $key
@return string[] - array of subkeys | [
"Parse",
"the",
"specified",
"key",
"into",
"subkeys",
".",
"Subkeys",
"can",
"consist",
"of",
"quoted",
"strings",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L401-L433 |
29,261 | rosasurfer/ministruts | src/config/Config.php | Config.dump | public function dump(array $options = null) {
$lines = [];
$maxKeyLength = 0;
$values = $this->dumpNode([], $this->properties, $maxKeyLength);
if (isset($options['sort'])) {
if ($options['sort'] == SORT_ASC) {
ksort($values, SORT_NATURAL);
}
else if ($options['sort'] == SORT_DESC) {
krsort($values, SORT_NATURAL);
}
}
foreach ($values as $key => &$value) {
// convert special values to their string representation
if (is_null($value)) $value = '(null)';
elseif (is_bool($value)) $value = ($value ? '(true)' : '(false)');
elseif (is_string($value)) {
switch (strtolower($value)) {
case 'null' :
case '(null)' :
case 'true' :
case '(true)' :
case 'false' :
case '(false)':
case 'on' :
case 'off' :
case 'yes' :
case 'no' :
$value = '"'.$value.'"';
break;
default:
if (strContains($value, '#'))
$value = '"'.$value.'"';
}
}
$value = str_pad($key, $maxKeyLength, ' ', STR_PAD_RIGHT).' = '.$value;
}; unset($value);
$lines += $values;
$padLeft = isset($options['pad-left']) ? $options['pad-left'] : '';
return $padLeft.join(NL.$padLeft, $lines);
} | php | public function dump(array $options = null) {
$lines = [];
$maxKeyLength = 0;
$values = $this->dumpNode([], $this->properties, $maxKeyLength);
if (isset($options['sort'])) {
if ($options['sort'] == SORT_ASC) {
ksort($values, SORT_NATURAL);
}
else if ($options['sort'] == SORT_DESC) {
krsort($values, SORT_NATURAL);
}
}
foreach ($values as $key => &$value) {
// convert special values to their string representation
if (is_null($value)) $value = '(null)';
elseif (is_bool($value)) $value = ($value ? '(true)' : '(false)');
elseif (is_string($value)) {
switch (strtolower($value)) {
case 'null' :
case '(null)' :
case 'true' :
case '(true)' :
case 'false' :
case '(false)':
case 'on' :
case 'off' :
case 'yes' :
case 'no' :
$value = '"'.$value.'"';
break;
default:
if (strContains($value, '#'))
$value = '"'.$value.'"';
}
}
$value = str_pad($key, $maxKeyLength, ' ', STR_PAD_RIGHT).' = '.$value;
}; unset($value);
$lines += $values;
$padLeft = isset($options['pad-left']) ? $options['pad-left'] : '';
return $padLeft.join(NL.$padLeft, $lines);
} | [
"public",
"function",
"dump",
"(",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"$",
"maxKeyLength",
"=",
"0",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"dumpNode",
"(",
"[",
"]",
",",
"$",
"this",
"->",
"properties",
",",
"$",
"maxKeyLength",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'sort'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'sort'",
"]",
"==",
"SORT_ASC",
")",
"{",
"ksort",
"(",
"$",
"values",
",",
"SORT_NATURAL",
")",
";",
"}",
"else",
"if",
"(",
"$",
"options",
"[",
"'sort'",
"]",
"==",
"SORT_DESC",
")",
"{",
"krsort",
"(",
"$",
"values",
",",
"SORT_NATURAL",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"// convert special values to their string representation",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"'(null)'",
";",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"(",
"$",
"value",
"?",
"'(true)'",
":",
"'(false)'",
")",
";",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'null'",
":",
"case",
"'(null)'",
":",
"case",
"'true'",
":",
"case",
"'(true)'",
":",
"case",
"'false'",
":",
"case",
"'(false)'",
":",
"case",
"'on'",
":",
"case",
"'off'",
":",
"case",
"'yes'",
":",
"case",
"'no'",
":",
"$",
"value",
"=",
"'\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"break",
";",
"default",
":",
"if",
"(",
"strContains",
"(",
"$",
"value",
",",
"'#'",
")",
")",
"$",
"value",
"=",
"'\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"}",
"$",
"value",
"=",
"str_pad",
"(",
"$",
"key",
",",
"$",
"maxKeyLength",
",",
"' '",
",",
"STR_PAD_RIGHT",
")",
".",
"' = '",
".",
"$",
"value",
";",
"}",
";",
"unset",
"(",
"$",
"value",
")",
";",
"$",
"lines",
"+=",
"$",
"values",
";",
"$",
"padLeft",
"=",
"isset",
"(",
"$",
"options",
"[",
"'pad-left'",
"]",
")",
"?",
"$",
"options",
"[",
"'pad-left'",
"]",
":",
"''",
";",
"return",
"$",
"padLeft",
".",
"join",
"(",
"NL",
".",
"$",
"padLeft",
",",
"$",
"lines",
")",
";",
"}"
] | Return a plain text dump of the instance's preferences.
@param array $options [optional] - array with dump options: <br>
'sort' => SORT_ASC|SORT_DESC (default: unsorted) <br>
'pad-left' => string (default: no padding) <br>
@return string | [
"Return",
"a",
"plain",
"text",
"dump",
"of",
"the",
"instance",
"s",
"preferences",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L444-L488 |
29,262 | rosasurfer/ministruts | src/config/Config.php | Config.dumpNode | private function dumpNode(array $node, array $values, &$maxKeyLength) {
$result = [];
foreach ($values as $subkey => $value) {
if ($subkey==trim($subkey) && (strlen($subkey) || sizeof($values) > 1)) {
$sSubkey = $subkey;
}
else {
$sSubkey = '"'.$subkey.'"';
}
$key = join('.', \array_merge($node, $sSubkey=='' ? [] : [$sSubkey]));
$maxKeyLength = max(strlen($key), $maxKeyLength);
if (is_array($value)) {
$result += $this->{__FUNCTION__}(\array_merge($node, [$subkey]), $value, $maxKeyLength);
}
else {
$result[$key] = $value;
}
}
return $result;
} | php | private function dumpNode(array $node, array $values, &$maxKeyLength) {
$result = [];
foreach ($values as $subkey => $value) {
if ($subkey==trim($subkey) && (strlen($subkey) || sizeof($values) > 1)) {
$sSubkey = $subkey;
}
else {
$sSubkey = '"'.$subkey.'"';
}
$key = join('.', \array_merge($node, $sSubkey=='' ? [] : [$sSubkey]));
$maxKeyLength = max(strlen($key), $maxKeyLength);
if (is_array($value)) {
$result += $this->{__FUNCTION__}(\array_merge($node, [$subkey]), $value, $maxKeyLength);
}
else {
$result[$key] = $value;
}
}
return $result;
} | [
"private",
"function",
"dumpNode",
"(",
"array",
"$",
"node",
",",
"array",
"$",
"values",
",",
"&",
"$",
"maxKeyLength",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"subkey",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"subkey",
"==",
"trim",
"(",
"$",
"subkey",
")",
"&&",
"(",
"strlen",
"(",
"$",
"subkey",
")",
"||",
"sizeof",
"(",
"$",
"values",
")",
">",
"1",
")",
")",
"{",
"$",
"sSubkey",
"=",
"$",
"subkey",
";",
"}",
"else",
"{",
"$",
"sSubkey",
"=",
"'\"'",
".",
"$",
"subkey",
".",
"'\"'",
";",
"}",
"$",
"key",
"=",
"join",
"(",
"'.'",
",",
"\\",
"array_merge",
"(",
"$",
"node",
",",
"$",
"sSubkey",
"==",
"''",
"?",
"[",
"]",
":",
"[",
"$",
"sSubkey",
"]",
")",
")",
";",
"$",
"maxKeyLength",
"=",
"max",
"(",
"strlen",
"(",
"$",
"key",
")",
",",
"$",
"maxKeyLength",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"+=",
"$",
"this",
"->",
"{",
"__FUNCTION__",
"}",
"(",
"\\",
"array_merge",
"(",
"$",
"node",
",",
"[",
"$",
"subkey",
"]",
")",
",",
"$",
"value",
",",
"$",
"maxKeyLength",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Dump the tree structure of a node into a flat format and return it.
@param string[] $node [in ]
@param array $values [in ]
@param int $maxKeyLength [out]
@return array | [
"Dump",
"the",
"tree",
"structure",
"of",
"a",
"node",
"into",
"a",
"flat",
"format",
"and",
"return",
"it",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L500-L521 |
29,263 | rosasurfer/ministruts | src/config/Config.php | Config.export | public function export(array $options = null) {
$maxKeyLength = null;
$values = $this->dumpNode([], $this->properties, $maxKeyLength);
if (isset($options['sort'])) {
if ($options['sort'] == SORT_ASC) {
ksort($values, SORT_NATURAL);
}
else if ($options['sort'] == SORT_DESC) {
krsort($values, SORT_NATURAL);
}
}
foreach ($values as $key => &$value) {
// convert special values to their string representation
if (is_null($value)) $value = '(null)';
elseif (is_bool($value)) $value = ($value ? '(true)' : '(false)');
elseif (is_string($value)) {
switch (strtolower($value)) {
case 'null' :
case '(null)' :
case 'true' :
case '(true)' :
case 'false' :
case '(false)':
case 'on' :
case 'off' :
case 'yes' :
case 'no' :
$value = '"'.$value.'"';
break;
default:
if (strContains($value, '#'))
$value = '"'.$value.'"';
}
}
}; unset($value);
return $values;
} | php | public function export(array $options = null) {
$maxKeyLength = null;
$values = $this->dumpNode([], $this->properties, $maxKeyLength);
if (isset($options['sort'])) {
if ($options['sort'] == SORT_ASC) {
ksort($values, SORT_NATURAL);
}
else if ($options['sort'] == SORT_DESC) {
krsort($values, SORT_NATURAL);
}
}
foreach ($values as $key => &$value) {
// convert special values to their string representation
if (is_null($value)) $value = '(null)';
elseif (is_bool($value)) $value = ($value ? '(true)' : '(false)');
elseif (is_string($value)) {
switch (strtolower($value)) {
case 'null' :
case '(null)' :
case 'true' :
case '(true)' :
case 'false' :
case '(false)':
case 'on' :
case 'off' :
case 'yes' :
case 'no' :
$value = '"'.$value.'"';
break;
default:
if (strContains($value, '#'))
$value = '"'.$value.'"';
}
}
}; unset($value);
return $values;
} | [
"public",
"function",
"export",
"(",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"maxKeyLength",
"=",
"null",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"dumpNode",
"(",
"[",
"]",
",",
"$",
"this",
"->",
"properties",
",",
"$",
"maxKeyLength",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'sort'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'sort'",
"]",
"==",
"SORT_ASC",
")",
"{",
"ksort",
"(",
"$",
"values",
",",
"SORT_NATURAL",
")",
";",
"}",
"else",
"if",
"(",
"$",
"options",
"[",
"'sort'",
"]",
"==",
"SORT_DESC",
")",
"{",
"krsort",
"(",
"$",
"values",
",",
"SORT_NATURAL",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"// convert special values to their string representation",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"'(null)'",
";",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"(",
"$",
"value",
"?",
"'(true)'",
":",
"'(false)'",
")",
";",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'null'",
":",
"case",
"'(null)'",
":",
"case",
"'true'",
":",
"case",
"'(true)'",
":",
"case",
"'false'",
":",
"case",
"'(false)'",
":",
"case",
"'on'",
":",
"case",
"'off'",
":",
"case",
"'yes'",
":",
"case",
"'no'",
":",
"$",
"value",
"=",
"'\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"break",
";",
"default",
":",
"if",
"(",
"strContains",
"(",
"$",
"value",
",",
"'#'",
")",
")",
"$",
"value",
"=",
"'\"'",
".",
"$",
"value",
".",
"'\"'",
";",
"}",
"}",
"}",
";",
"unset",
"(",
"$",
"value",
")",
";",
"return",
"$",
"values",
";",
"}"
] | Return an array with "key-value" pairs of the config settings.
@param array $options [optional] - array with export options: <br>
'sort' => SORT_ASC|SORT_DESC (default: unsorted) <br>
@return string[] | [
"Return",
"an",
"array",
"with",
"key",
"-",
"value",
"pairs",
"of",
"the",
"config",
"settings",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L532-L571 |
29,264 | rosasurfer/ministruts | src/config/Config.php | Config.offsetExists | public function offsetExists($key) {
if (!is_string($key)) throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
$notFound = false;
$this->getProperty($key, $notFound);
return !$notFound;
} | php | public function offsetExists($key) {
if (!is_string($key)) throw new IllegalTypeException('Illegal type of parameter $key: '.gettype($key));
$notFound = false;
$this->getProperty($key, $notFound);
return !$notFound;
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"throw",
"new",
"IllegalTypeException",
"(",
"'Illegal type of parameter $key: '",
".",
"gettype",
"(",
"$",
"key",
")",
")",
";",
"$",
"notFound",
"=",
"false",
";",
"$",
"this",
"->",
"getProperty",
"(",
"$",
"key",
",",
"$",
"notFound",
")",
";",
"return",
"!",
"$",
"notFound",
";",
"}"
] | Whether a config setting with the specified key exists.
@param string $key - case-insensitive key
@return bool | [
"Whether",
"a",
"config",
"setting",
"with",
"the",
"specified",
"key",
"exists",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/config/Config.php#L581-L588 |
29,265 | timble/kodekit | code/event/publisher/profiler.php | EventPublisherProfiler.setDelegate | public function setDelegate($delegate)
{
if (!$delegate instanceof EventPublisherInterface) {
throw new \InvalidArgumentException('Delegate: '.get_class($delegate).' does not implement EventPublisherInterface');
}
return parent::setDelegate($delegate);
} | php | public function setDelegate($delegate)
{
if (!$delegate instanceof EventPublisherInterface) {
throw new \InvalidArgumentException('Delegate: '.get_class($delegate).' does not implement EventPublisherInterface');
}
return parent::setDelegate($delegate);
} | [
"public",
"function",
"setDelegate",
"(",
"$",
"delegate",
")",
"{",
"if",
"(",
"!",
"$",
"delegate",
"instanceof",
"EventPublisherInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Delegate: '",
".",
"get_class",
"(",
"$",
"delegate",
")",
".",
"' does not implement EventPublisherInterface'",
")",
";",
"}",
"return",
"parent",
"::",
"setDelegate",
"(",
"$",
"delegate",
")",
";",
"}"
] | Set the decorated event publisher
@param EventPublisherInterface $delegate The decorated event publisher
@return EventPublisherProfiler
@throws \InvalidArgumentException If the delegate is not an event publisher | [
"Set",
"the",
"decorated",
"event",
"publisher"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/event/publisher/profiler.php#L286-L293 |
29,266 | timble/kodekit | code/database/behavior/recursable.php | DatabaseBehaviorRecursable.hasChildren | public function hasChildren()
{
$result = false;
if(isset($this->__children[$this->id])) {
$result = (boolean) count($this->__children[$this->id]);
}
return $result;
} | php | public function hasChildren()
{
$result = false;
if(isset($this->__children[$this->id])) {
$result = (boolean) count($this->__children[$this->id]);
}
return $result;
} | [
"public",
"function",
"hasChildren",
"(",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"__children",
"[",
"$",
"this",
"->",
"id",
"]",
")",
")",
"{",
"$",
"result",
"=",
"(",
"boolean",
")",
"count",
"(",
"$",
"this",
"->",
"__children",
"[",
"$",
"this",
"->",
"id",
"]",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Check if the node has children
@return bool True if the node has one or more children | [
"Check",
"if",
"the",
"node",
"has",
"children"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/behavior/recursable.php#L77-L86 |
29,267 | timble/kodekit | code/database/behavior/recursable.php | DatabaseBehaviorRecursable.getChildren | public function getChildren()
{
$result = null;
if($this->hasChildren())
{
$parent = $this->id;
if(!$this->__children[$parent] instanceof DatabaseRowsetInterface)
{
$this->__children[$parent] = $this->getTable()->createRowset(array(
'data' => $this->__children[$parent]
));
}
$result = $this->__children[$parent];
}
return $result;
} | php | public function getChildren()
{
$result = null;
if($this->hasChildren())
{
$parent = $this->id;
if(!$this->__children[$parent] instanceof DatabaseRowsetInterface)
{
$this->__children[$parent] = $this->getTable()->createRowset(array(
'data' => $this->__children[$parent]
));
}
$result = $this->__children[$parent];
}
return $result;
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"hasChildren",
"(",
")",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"id",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
"instanceof",
"DatabaseRowsetInterface",
")",
"{",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"createRowset",
"(",
"array",
"(",
"'data'",
"=>",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the children
@return DatabaseRowsetInterface|null | [
"Get",
"the",
"children"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/behavior/recursable.php#L93-L112 |
29,268 | timble/kodekit | code/database/behavior/recursable.php | DatabaseBehaviorRecursable.getRecursiveIterator | public function getRecursiveIterator($max_level = 0, $parent = 0)
{
if($parent > 0 && !$this->__nodes->find($parent)) {
throw new \OutOfBoundsException('Parent does not exist');
}
//If the parent doesn't have any children create an empty rowset
if(isset($this->__children[$parent])) {
$config = array('data' => $this->__children[$parent]);
} else {
$config = array();
}
$iterator = new DatabaseIteratorRecursive($this->getTable()->createRowset($config), $max_level);
return $iterator;
} | php | public function getRecursiveIterator($max_level = 0, $parent = 0)
{
if($parent > 0 && !$this->__nodes->find($parent)) {
throw new \OutOfBoundsException('Parent does not exist');
}
//If the parent doesn't have any children create an empty rowset
if(isset($this->__children[$parent])) {
$config = array('data' => $this->__children[$parent]);
} else {
$config = array();
}
$iterator = new DatabaseIteratorRecursive($this->getTable()->createRowset($config), $max_level);
return $iterator;
} | [
"public",
"function",
"getRecursiveIterator",
"(",
"$",
"max_level",
"=",
"0",
",",
"$",
"parent",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"parent",
">",
"0",
"&&",
"!",
"$",
"this",
"->",
"__nodes",
"->",
"find",
"(",
"$",
"parent",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Parent does not exist'",
")",
";",
"}",
"//If the parent doesn't have any children create an empty rowset",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
")",
")",
"{",
"$",
"config",
"=",
"array",
"(",
"'data'",
"=>",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
")",
";",
"}",
"else",
"{",
"$",
"config",
"=",
"array",
"(",
")",
";",
"}",
"$",
"iterator",
"=",
"new",
"DatabaseIteratorRecursive",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"createRowset",
"(",
"$",
"config",
")",
",",
"$",
"max_level",
")",
";",
"return",
"$",
"iterator",
";",
"}"
] | Get the recursive iterator
@param integer $max_level The maximum allowed level. 0 is used for any level
@param integer $parent The key of the parent to start recursing from. 0 is used for the top level
@return DatabaseIteratorRecursive
@throws \OutOfBoundsException If a parent key is specified that doesn't exist. | [
"Get",
"the",
"recursive",
"iterator"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/behavior/recursable.php#L132-L147 |
29,269 | timble/kodekit | code/database/behavior/recursable.php | DatabaseBehaviorRecursable._afterSelect | protected function _afterSelect(DatabaseContext $context)
{
if(!$context->query->isCountQuery())
{
$rowset = ObjectConfig::unbox($context->data);
if ($rowset instanceof DatabaseRowsetInterface)
{
//Store the nodes
$this->__nodes = $rowset;
$this->__iterator = null;
$this->__children = array();
foreach ($this->__nodes as $key => $row)
{
//Force mixin the behavior into each row
$row->mixin($this);
if($row->isRecursable()) {
$parent = (int) $row->getProperty($this->_parent_column);
} else {
$parent = 0;
}
//Store the nodes by parent
$this->__children[$parent][$key] = $row;
}
//Sort the children
ksort($this->__children);
}
}
} | php | protected function _afterSelect(DatabaseContext $context)
{
if(!$context->query->isCountQuery())
{
$rowset = ObjectConfig::unbox($context->data);
if ($rowset instanceof DatabaseRowsetInterface)
{
//Store the nodes
$this->__nodes = $rowset;
$this->__iterator = null;
$this->__children = array();
foreach ($this->__nodes as $key => $row)
{
//Force mixin the behavior into each row
$row->mixin($this);
if($row->isRecursable()) {
$parent = (int) $row->getProperty($this->_parent_column);
} else {
$parent = 0;
}
//Store the nodes by parent
$this->__children[$parent][$key] = $row;
}
//Sort the children
ksort($this->__children);
}
}
} | [
"protected",
"function",
"_afterSelect",
"(",
"DatabaseContext",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"context",
"->",
"query",
"->",
"isCountQuery",
"(",
")",
")",
"{",
"$",
"rowset",
"=",
"ObjectConfig",
"::",
"unbox",
"(",
"$",
"context",
"->",
"data",
")",
";",
"if",
"(",
"$",
"rowset",
"instanceof",
"DatabaseRowsetInterface",
")",
"{",
"//Store the nodes",
"$",
"this",
"->",
"__nodes",
"=",
"$",
"rowset",
";",
"$",
"this",
"->",
"__iterator",
"=",
"null",
";",
"$",
"this",
"->",
"__children",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"__nodes",
"as",
"$",
"key",
"=>",
"$",
"row",
")",
"{",
"//Force mixin the behavior into each row",
"$",
"row",
"->",
"mixin",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"row",
"->",
"isRecursable",
"(",
")",
")",
"{",
"$",
"parent",
"=",
"(",
"int",
")",
"$",
"row",
"->",
"getProperty",
"(",
"$",
"this",
"->",
"_parent_column",
")",
";",
"}",
"else",
"{",
"$",
"parent",
"=",
"0",
";",
"}",
"//Store the nodes by parent",
"$",
"this",
"->",
"__children",
"[",
"$",
"parent",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"row",
";",
"}",
"//Sort the children",
"ksort",
"(",
"$",
"this",
"->",
"__children",
")",
";",
"}",
"}",
"}"
] | Filter the rowset
@param DatabaseContext $context | [
"Filter",
"the",
"rowset"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/behavior/recursable.php#L187-L219 |
29,270 | timble/kodekit | code/model/entity/abstract.php | ModelEntityAbstract.save | public function save()
{
if (!$this->isNew()) {
$this->setStatus(self::STATUS_UPDATED);
} else {
$this->setStatus(self::STATUS_CREATED);
}
return false;
} | php | public function save()
{
if (!$this->isNew()) {
$this->setStatus(self::STATUS_UPDATED);
} else {
$this->setStatus(self::STATUS_CREATED);
}
return false;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isNew",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setStatus",
"(",
"self",
"::",
"STATUS_UPDATED",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setStatus",
"(",
"self",
"::",
"STATUS_CREATED",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Saves the entity to the data store
@return boolean If successful return TRUE, otherwise FALSE | [
"Saves",
"the",
"entity",
"to",
"the",
"data",
"store"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/model/entity/abstract.php#L120-L129 |
29,271 | rosasurfer/ministruts | src/di/Di.php | Di.loadCustomServices | protected function loadCustomServices($configDir) {
if (!is_string($configDir)) throw new IllegalTypeException('Illegal type of parameter $configDir: '.gettype($configDir));
if (!is_file($file = $configDir.'/services.php'))
return false;
foreach (include($file) as $name => $definition) {
$this->set($name, $definition);
}
return true;
} | php | protected function loadCustomServices($configDir) {
if (!is_string($configDir)) throw new IllegalTypeException('Illegal type of parameter $configDir: '.gettype($configDir));
if (!is_file($file = $configDir.'/services.php'))
return false;
foreach (include($file) as $name => $definition) {
$this->set($name, $definition);
}
return true;
} | [
"protected",
"function",
"loadCustomServices",
"(",
"$",
"configDir",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"configDir",
")",
")",
"throw",
"new",
"IllegalTypeException",
"(",
"'Illegal type of parameter $configDir: '",
".",
"gettype",
"(",
"$",
"configDir",
")",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
"=",
"$",
"configDir",
".",
"'/services.php'",
")",
")",
"return",
"false",
";",
"foreach",
"(",
"include",
"(",
"$",
"file",
")",
"as",
"$",
"name",
"=>",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"definition",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Load custom service definitions.
@param string $configDir - directory to load service definitions from
@return bool - whether a custom service definitions has been found and successfully loaded | [
"Load",
"custom",
"service",
"definitions",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/di/Di.php#L58-L67 |
29,272 | timble/kodekit | code/database/behavior/sluggable.php | DatabaseBehaviorSluggable.getSlug | public function getSlug()
{
if (!$this->_unique)
{
$column = $this->getIdentityColumn();
$result = $this->{$column} . $this->_separator . $this->slug;
}
else $result = $this->slug;
return $result;
} | php | public function getSlug()
{
if (!$this->_unique)
{
$column = $this->getIdentityColumn();
$result = $this->{$column} . $this->_separator . $this->slug;
}
else $result = $this->slug;
return $result;
} | [
"public",
"function",
"getSlug",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_unique",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentityColumn",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"{",
"$",
"column",
"}",
".",
"$",
"this",
"->",
"_separator",
".",
"$",
"this",
"->",
"slug",
";",
"}",
"else",
"$",
"result",
"=",
"$",
"this",
"->",
"slug",
";",
"return",
"$",
"result",
";",
"}"
] | Get the canonical slug
This function will always return a unique and canonical slug. If the slug is not unique it will prepend the
identity column value.
@link : https://en.wikipedia.org/wiki/Canonicalization
@return string | [
"Get",
"the",
"canonical",
"slug"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/behavior/sluggable.php#L165-L175 |
29,273 | timble/kodekit | code/database/behavior/sluggable.php | DatabaseBehaviorSluggable._createSlug | protected function _createSlug()
{
//Regenerate the slug
if($this->isModified('slug')) {
$this->slug = $this->_createFilter()->sanitize($this->slug);
}
//Handle empty slug
if(empty($this->slug))
{
$slugs = array();
foreach($this->_columns as $column) {
$slugs[] = $this->_createFilter()->sanitize($this->$column);
}
$this->slug = implode($this->_separator, array_filter($slugs));
}
//Canonicalize the slug
if($this->_unique) {
$this->_canonicalizeSlug();
}
} | php | protected function _createSlug()
{
//Regenerate the slug
if($this->isModified('slug')) {
$this->slug = $this->_createFilter()->sanitize($this->slug);
}
//Handle empty slug
if(empty($this->slug))
{
$slugs = array();
foreach($this->_columns as $column) {
$slugs[] = $this->_createFilter()->sanitize($this->$column);
}
$this->slug = implode($this->_separator, array_filter($slugs));
}
//Canonicalize the slug
if($this->_unique) {
$this->_canonicalizeSlug();
}
} | [
"protected",
"function",
"_createSlug",
"(",
")",
"{",
"//Regenerate the slug",
"if",
"(",
"$",
"this",
"->",
"isModified",
"(",
"'slug'",
")",
")",
"{",
"$",
"this",
"->",
"slug",
"=",
"$",
"this",
"->",
"_createFilter",
"(",
")",
"->",
"sanitize",
"(",
"$",
"this",
"->",
"slug",
")",
";",
"}",
"//Handle empty slug",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"slug",
")",
")",
"{",
"$",
"slugs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_columns",
"as",
"$",
"column",
")",
"{",
"$",
"slugs",
"[",
"]",
"=",
"$",
"this",
"->",
"_createFilter",
"(",
")",
"->",
"sanitize",
"(",
"$",
"this",
"->",
"$",
"column",
")",
";",
"}",
"$",
"this",
"->",
"slug",
"=",
"implode",
"(",
"$",
"this",
"->",
"_separator",
",",
"array_filter",
"(",
"$",
"slugs",
")",
")",
";",
"}",
"//Canonicalize the slug",
"if",
"(",
"$",
"this",
"->",
"_unique",
")",
"{",
"$",
"this",
"->",
"_canonicalizeSlug",
"(",
")",
";",
"}",
"}"
] | Create the slug
@return void | [
"Create",
"the",
"slug"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/behavior/sluggable.php#L216-L238 |
29,274 | timble/kodekit | code/dispatcher/response/abstract.php | DispatcherResponseAbstract.getTransport | public function getTransport($transport, $config = array())
{
//Create the complete identifier if a partial identifier was passed
if (is_string($transport) && strpos($transport, '.') === false)
{
$identifier = $this->getIdentifier()->toArray();
if($identifier['package'] != 'dispatcher') {
$identifier['path'] = array('dispatcher', 'response', 'transport');
} else {
$identifier['path'] = array('response', 'transport');
}
$identifier['name'] = $transport;
$identifier = $this->getIdentifier($identifier);
}
else $identifier = $this->getIdentifier($transport);
if (!isset($this->_transports[$identifier->name]))
{
$transport = $this->getObject($identifier, array_merge($config, array('response' => $this)));
if (!($transport instanceof DispatcherResponseTransportInterface))
{
throw new \UnexpectedValueException(
"Transport handler $identifier does not implement DispatcherResponseTransportInterface"
);
}
$this->_transports[$transport->getIdentifier()->name] = $transport;
}
else $transport = $this->_transports[$identifier->name];
return $transport;
} | php | public function getTransport($transport, $config = array())
{
//Create the complete identifier if a partial identifier was passed
if (is_string($transport) && strpos($transport, '.') === false)
{
$identifier = $this->getIdentifier()->toArray();
if($identifier['package'] != 'dispatcher') {
$identifier['path'] = array('dispatcher', 'response', 'transport');
} else {
$identifier['path'] = array('response', 'transport');
}
$identifier['name'] = $transport;
$identifier = $this->getIdentifier($identifier);
}
else $identifier = $this->getIdentifier($transport);
if (!isset($this->_transports[$identifier->name]))
{
$transport = $this->getObject($identifier, array_merge($config, array('response' => $this)));
if (!($transport instanceof DispatcherResponseTransportInterface))
{
throw new \UnexpectedValueException(
"Transport handler $identifier does not implement DispatcherResponseTransportInterface"
);
}
$this->_transports[$transport->getIdentifier()->name] = $transport;
}
else $transport = $this->_transports[$identifier->name];
return $transport;
} | [
"public",
"function",
"getTransport",
"(",
"$",
"transport",
",",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"//Create the complete identifier if a partial identifier was passed",
"if",
"(",
"is_string",
"(",
"$",
"transport",
")",
"&&",
"strpos",
"(",
"$",
"transport",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"$",
"identifier",
"[",
"'package'",
"]",
"!=",
"'dispatcher'",
")",
"{",
"$",
"identifier",
"[",
"'path'",
"]",
"=",
"array",
"(",
"'dispatcher'",
",",
"'response'",
",",
"'transport'",
")",
";",
"}",
"else",
"{",
"$",
"identifier",
"[",
"'path'",
"]",
"=",
"array",
"(",
"'response'",
",",
"'transport'",
")",
";",
"}",
"$",
"identifier",
"[",
"'name'",
"]",
"=",
"$",
"transport",
";",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"identifier",
")",
";",
"}",
"else",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"transport",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_transports",
"[",
"$",
"identifier",
"->",
"name",
"]",
")",
")",
"{",
"$",
"transport",
"=",
"$",
"this",
"->",
"getObject",
"(",
"$",
"identifier",
",",
"array_merge",
"(",
"$",
"config",
",",
"array",
"(",
"'response'",
"=>",
"$",
"this",
")",
")",
")",
";",
"if",
"(",
"!",
"(",
"$",
"transport",
"instanceof",
"DispatcherResponseTransportInterface",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Transport handler $identifier does not implement DispatcherResponseTransportInterface\"",
")",
";",
"}",
"$",
"this",
"->",
"_transports",
"[",
"$",
"transport",
"->",
"getIdentifier",
"(",
")",
"->",
"name",
"]",
"=",
"$",
"transport",
";",
"}",
"else",
"$",
"transport",
"=",
"$",
"this",
"->",
"_transports",
"[",
"$",
"identifier",
"->",
"name",
"]",
";",
"return",
"$",
"transport",
";",
"}"
] | Get a transport handler by identifier
@param mixed $transport An object that implements ObjectInterface, ObjectIdentifier object
or valid identifier string
@param array $config An optional associative array of configuration settings
@throws \UnexpectedValueException
@return DispatcherResponseAbstract | [
"Get",
"a",
"transport",
"handler",
"by",
"identifier"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/response/abstract.php#L216-L250 |
29,275 | locomotivemtl/charcoal-core | src/Charcoal/Source/OrderCollectionTrait.php | OrderCollectionTrait.addOrders | public function addOrders(array $orders)
{
foreach ($orders as $key => $order) {
$this->addOrder($order);
/** Name the expression if $key is a non-numeric string. */
if (is_string($key) && !is_numeric($key)) {
$order = end($this->orders);
$order->setName($key);
}
}
return $this;
} | php | public function addOrders(array $orders)
{
foreach ($orders as $key => $order) {
$this->addOrder($order);
/** Name the expression if $key is a non-numeric string. */
if (is_string($key) && !is_numeric($key)) {
$order = end($this->orders);
$order->setName($key);
}
}
return $this;
} | [
"public",
"function",
"addOrders",
"(",
"array",
"$",
"orders",
")",
"{",
"foreach",
"(",
"$",
"orders",
"as",
"$",
"key",
"=>",
"$",
"order",
")",
"{",
"$",
"this",
"->",
"addOrder",
"(",
"$",
"order",
")",
";",
"/** Name the expression if $key is a non-numeric string. */",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"order",
"=",
"end",
"(",
"$",
"this",
"->",
"orders",
")",
";",
"$",
"order",
"->",
"setName",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Append one or more query orders on this object.
@uses self::processOrder()
@param mixed[] $orders One or more orders to add on this expression.
@return self | [
"Append",
"one",
"or",
"more",
"query",
"orders",
"on",
"this",
"object",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/OrderCollectionTrait.php#L51-L64 |
29,276 | locomotivemtl/charcoal-core | src/Charcoal/Source/OrderCollectionTrait.php | OrderCollectionTrait.processOrder | protected function processOrder($order)
{
if (!is_string($order) && is_callable($order)) {
$expr = $this->createOrder();
/**
* @param OrderInterface $expr The new order expression object.
* @param OrderCollectionInterface $this The context of the collection.
* @return string|array|OrderInterface The prepared order expression
* string, structure, object.
*/
$order = $order($expr, $this);
}
if (is_string($order)) {
$expr = $this->createOrder()->setCondition($order);
$order = $expr;
} elseif (is_array($order)) {
$expr = $this->createOrder()->setData($order);
$order = $expr;
}
/** Append the order to the expression's stack. */
if ($order instanceof OrderInterface) {
return $order;
}
throw new InvalidArgumentException(sprintf(
'Order must be a string, structure, or Expression object; received %s',
is_object($order) ? get_class($order) : gettype($order)
));
} | php | protected function processOrder($order)
{
if (!is_string($order) && is_callable($order)) {
$expr = $this->createOrder();
/**
* @param OrderInterface $expr The new order expression object.
* @param OrderCollectionInterface $this The context of the collection.
* @return string|array|OrderInterface The prepared order expression
* string, structure, object.
*/
$order = $order($expr, $this);
}
if (is_string($order)) {
$expr = $this->createOrder()->setCondition($order);
$order = $expr;
} elseif (is_array($order)) {
$expr = $this->createOrder()->setData($order);
$order = $expr;
}
/** Append the order to the expression's stack. */
if ($order instanceof OrderInterface) {
return $order;
}
throw new InvalidArgumentException(sprintf(
'Order must be a string, structure, or Expression object; received %s',
is_object($order) ? get_class($order) : gettype($order)
));
} | [
"protected",
"function",
"processOrder",
"(",
"$",
"order",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"order",
")",
"&&",
"is_callable",
"(",
"$",
"order",
")",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"createOrder",
"(",
")",
";",
"/**\n * @param OrderInterface $expr The new order expression object.\n * @param OrderCollectionInterface $this The context of the collection.\n * @return string|array|OrderInterface The prepared order expression\n * string, structure, object.\n */",
"$",
"order",
"=",
"$",
"order",
"(",
"$",
"expr",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"order",
")",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"createOrder",
"(",
")",
"->",
"setCondition",
"(",
"$",
"order",
")",
";",
"$",
"order",
"=",
"$",
"expr",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"order",
")",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"createOrder",
"(",
")",
"->",
"setData",
"(",
"$",
"order",
")",
";",
"$",
"order",
"=",
"$",
"expr",
";",
"}",
"/** Append the order to the expression's stack. */",
"if",
"(",
"$",
"order",
"instanceof",
"OrderInterface",
")",
"{",
"return",
"$",
"order",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Order must be a string, structure, or Expression object; received %s'",
",",
"is_object",
"(",
"$",
"order",
")",
"?",
"get_class",
"(",
"$",
"order",
")",
":",
"gettype",
"(",
"$",
"order",
")",
")",
")",
";",
"}"
] | Process a query order to build a tree of expressions.
Implement in subclasses to dynamically parse orders before being appended.
@param mixed $order The expression string, structure, object, or callable to be parsed.
@throws InvalidArgumentException If a order is not a string, array, object, or callable.
@return OrderInterface | [
"Process",
"a",
"query",
"order",
"to",
"build",
"a",
"tree",
"of",
"expressions",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/OrderCollectionTrait.php#L88-L118 |
29,277 | locomotivemtl/charcoal-core | src/Charcoal/Source/OrderCollectionTrait.php | OrderCollectionTrait.traverseOrders | public function traverseOrders(callable $callable)
{
foreach ($this->orders() as $expr) {
/**
* @param OrderInterface $expr The iterated order expression object.
* @param OrderCollectionInterface $this The context of the traversal.
* @return void
*/
$callable($expr, $this);
if ($expr instanceof OrderCollectionInterface) {
$expr->traverseOrders($callable);
}
}
return $this;
} | php | public function traverseOrders(callable $callable)
{
foreach ($this->orders() as $expr) {
/**
* @param OrderInterface $expr The iterated order expression object.
* @param OrderCollectionInterface $this The context of the traversal.
* @return void
*/
$callable($expr, $this);
if ($expr instanceof OrderCollectionInterface) {
$expr->traverseOrders($callable);
}
}
return $this;
} | [
"public",
"function",
"traverseOrders",
"(",
"callable",
"$",
"callable",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"orders",
"(",
")",
"as",
"$",
"expr",
")",
"{",
"/**\n * @param OrderInterface $expr The iterated order expression object.\n * @param OrderCollectionInterface $this The context of the traversal.\n * @return void\n */",
"$",
"callable",
"(",
"$",
"expr",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"expr",
"instanceof",
"OrderCollectionInterface",
")",
"{",
"$",
"expr",
"->",
"traverseOrders",
"(",
"$",
"callable",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Traverses the tree of query orders and applies a user function to every expression.
@param callable $callable The function to run for each expression.
@return self | [
"Traverses",
"the",
"tree",
"of",
"query",
"orders",
"and",
"applies",
"a",
"user",
"function",
"to",
"every",
"expression",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/OrderCollectionTrait.php#L146-L161 |
29,278 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.setData | public function setData(array $data)
{
parent::setData($data);
/** @deprecated */
if (isset($data['string'])) {
trigger_error(
sprintf(
'Filter expression option "string" is deprecated in favour of "condition": %s',
$data['string']
),
E_USER_DEPRECATED
);
$this->setCondition($data['string']);
}
/** @deprecated */
if (isset($data['table_name'])) {
trigger_error(
sprintf(
'Filter expression option "table_name" is deprecated in favour of "table": %s',
$data['table_name']
),
E_USER_DEPRECATED
);
$this->setTable($data['table_name']);
}
/** @deprecated */
if (isset($data['val'])) {
trigger_error(
sprintf(
'Filter expression option "val" is deprecated in favour of "value": %s',
$data['val']
),
E_USER_DEPRECATED
);
$this->setValue($data['val']);
}
/** @deprecated */
if (isset($data['operand'])) {
trigger_error(
sprintf(
'Query expression option "operand" is deprecated in favour of "conjunction": %s',
$data['operand']
),
E_USER_DEPRECATED
);
$this->setConjunction($data['operand']);
}
if (isset($data['table'])) {
$this->setTable($data['table']);
}
if (isset($data['property'])) {
$this->setProperty($data['property']);
}
if (isset($data['value'])) {
$this->setValue($data['value']);
}
if (isset($data['function'])) {
$this->setFunc($data['function']);
}
if (isset($data['func'])) {
$this->setFunc($data['func']);
}
if (isset($data['operator'])) {
$this->setOperator($data['operator']);
}
if (isset($data['conjunction'])) {
$this->setConjunction($data['conjunction']);
}
if (isset($data['conditions'])) {
$this->addFilters($data['conditions']);
}
if (isset($data['filters'])) {
$this->addFilters($data['filters']);
}
return $this;
} | php | public function setData(array $data)
{
parent::setData($data);
/** @deprecated */
if (isset($data['string'])) {
trigger_error(
sprintf(
'Filter expression option "string" is deprecated in favour of "condition": %s',
$data['string']
),
E_USER_DEPRECATED
);
$this->setCondition($data['string']);
}
/** @deprecated */
if (isset($data['table_name'])) {
trigger_error(
sprintf(
'Filter expression option "table_name" is deprecated in favour of "table": %s',
$data['table_name']
),
E_USER_DEPRECATED
);
$this->setTable($data['table_name']);
}
/** @deprecated */
if (isset($data['val'])) {
trigger_error(
sprintf(
'Filter expression option "val" is deprecated in favour of "value": %s',
$data['val']
),
E_USER_DEPRECATED
);
$this->setValue($data['val']);
}
/** @deprecated */
if (isset($data['operand'])) {
trigger_error(
sprintf(
'Query expression option "operand" is deprecated in favour of "conjunction": %s',
$data['operand']
),
E_USER_DEPRECATED
);
$this->setConjunction($data['operand']);
}
if (isset($data['table'])) {
$this->setTable($data['table']);
}
if (isset($data['property'])) {
$this->setProperty($data['property']);
}
if (isset($data['value'])) {
$this->setValue($data['value']);
}
if (isset($data['function'])) {
$this->setFunc($data['function']);
}
if (isset($data['func'])) {
$this->setFunc($data['func']);
}
if (isset($data['operator'])) {
$this->setOperator($data['operator']);
}
if (isset($data['conjunction'])) {
$this->setConjunction($data['conjunction']);
}
if (isset($data['conditions'])) {
$this->addFilters($data['conditions']);
}
if (isset($data['filters'])) {
$this->addFilters($data['filters']);
}
return $this;
} | [
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"parent",
"::",
"setData",
"(",
"$",
"data",
")",
";",
"/** @deprecated */",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'string'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'Filter expression option \"string\" is deprecated in favour of \"condition\": %s'",
",",
"$",
"data",
"[",
"'string'",
"]",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"setCondition",
"(",
"$",
"data",
"[",
"'string'",
"]",
")",
";",
"}",
"/** @deprecated */",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'table_name'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'Filter expression option \"table_name\" is deprecated in favour of \"table\": %s'",
",",
"$",
"data",
"[",
"'table_name'",
"]",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"setTable",
"(",
"$",
"data",
"[",
"'table_name'",
"]",
")",
";",
"}",
"/** @deprecated */",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'val'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'Filter expression option \"val\" is deprecated in favour of \"value\": %s'",
",",
"$",
"data",
"[",
"'val'",
"]",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"setValue",
"(",
"$",
"data",
"[",
"'val'",
"]",
")",
";",
"}",
"/** @deprecated */",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'operand'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'Query expression option \"operand\" is deprecated in favour of \"conjunction\": %s'",
",",
"$",
"data",
"[",
"'operand'",
"]",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"setConjunction",
"(",
"$",
"data",
"[",
"'operand'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'table'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setTable",
"(",
"$",
"data",
"[",
"'table'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'property'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setProperty",
"(",
"$",
"data",
"[",
"'property'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setValue",
"(",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'function'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setFunc",
"(",
"$",
"data",
"[",
"'function'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'func'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setFunc",
"(",
"$",
"data",
"[",
"'func'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'operator'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setOperator",
"(",
"$",
"data",
"[",
"'operator'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'conjunction'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setConjunction",
"(",
"$",
"data",
"[",
"'conjunction'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'conditions'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addFilters",
"(",
"$",
"data",
"[",
"'conditions'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'filters'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"addFilters",
"(",
"$",
"data",
"[",
"'filters'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the filter clause data.
@param array<string,mixed> $data The expression data;
as an associative array.
@return self | [
"Set",
"the",
"filter",
"clause",
"data",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L78-L167 |
29,279 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.defaultData | public function defaultData()
{
return [
'property' => null,
'table' => null,
'value' => null,
'func' => null,
'operator' => self::DEFAULT_OPERATOR,
'conjunction' => self::DEFAULT_CONJUNCTION,
'filters' => [],
'condition' => null,
'active' => true,
'name' => null,
];
} | php | public function defaultData()
{
return [
'property' => null,
'table' => null,
'value' => null,
'func' => null,
'operator' => self::DEFAULT_OPERATOR,
'conjunction' => self::DEFAULT_CONJUNCTION,
'filters' => [],
'condition' => null,
'active' => true,
'name' => null,
];
} | [
"public",
"function",
"defaultData",
"(",
")",
"{",
"return",
"[",
"'property'",
"=>",
"null",
",",
"'table'",
"=>",
"null",
",",
"'value'",
"=>",
"null",
",",
"'func'",
"=>",
"null",
",",
"'operator'",
"=>",
"self",
"::",
"DEFAULT_OPERATOR",
",",
"'conjunction'",
"=>",
"self",
"::",
"DEFAULT_CONJUNCTION",
",",
"'filters'",
"=>",
"[",
"]",
",",
"'condition'",
"=>",
"null",
",",
"'active'",
"=>",
"true",
",",
"'name'",
"=>",
"null",
",",
"]",
";",
"}"
] | Retrieve the default values for filtering.
@return array<string,mixed> An associative array. | [
"Retrieve",
"the",
"default",
"values",
"for",
"filtering",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L174-L188 |
29,280 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.data | public function data()
{
return [
'property' => $this->property(),
'table' => $this->table(),
'value' => $this->value(),
'func' => $this->func(),
'operator' => $this->operator(),
'conjunction' => $this->conjunction(),
'filters' => $this->filters(),
'condition' => $this->condition(),
'active' => $this->active(),
'name' => $this->name(),
];
} | php | public function data()
{
return [
'property' => $this->property(),
'table' => $this->table(),
'value' => $this->value(),
'func' => $this->func(),
'operator' => $this->operator(),
'conjunction' => $this->conjunction(),
'filters' => $this->filters(),
'condition' => $this->condition(),
'active' => $this->active(),
'name' => $this->name(),
];
} | [
"public",
"function",
"data",
"(",
")",
"{",
"return",
"[",
"'property'",
"=>",
"$",
"this",
"->",
"property",
"(",
")",
",",
"'table'",
"=>",
"$",
"this",
"->",
"table",
"(",
")",
",",
"'value'",
"=>",
"$",
"this",
"->",
"value",
"(",
")",
",",
"'func'",
"=>",
"$",
"this",
"->",
"func",
"(",
")",
",",
"'operator'",
"=>",
"$",
"this",
"->",
"operator",
"(",
")",
",",
"'conjunction'",
"=>",
"$",
"this",
"->",
"conjunction",
"(",
")",
",",
"'filters'",
"=>",
"$",
"this",
"->",
"filters",
"(",
")",
",",
"'condition'",
"=>",
"$",
"this",
"->",
"condition",
"(",
")",
",",
"'active'",
"=>",
"$",
"this",
"->",
"active",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"name",
"(",
")",
",",
"]",
";",
"}"
] | Retrieve the filter clause structure.
@return array<string,mixed> An associative array. | [
"Retrieve",
"the",
"filter",
"clause",
"structure",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L195-L209 |
29,281 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.setOperator | public function setOperator($operator)
{
if (!is_string($operator)) {
throw new InvalidArgumentException(
'Operator should be a string.'
);
}
$operator = strtoupper($operator);
if (!in_array($operator, $this->validOperators())) {
throw new InvalidArgumentException(sprintf(
'Comparison operator "%s" not allowed in this context.',
$operator
));
}
$this->operator = $operator;
return $this;
} | php | public function setOperator($operator)
{
if (!is_string($operator)) {
throw new InvalidArgumentException(
'Operator should be a string.'
);
}
$operator = strtoupper($operator);
if (!in_array($operator, $this->validOperators())) {
throw new InvalidArgumentException(sprintf(
'Comparison operator "%s" not allowed in this context.',
$operator
));
}
$this->operator = $operator;
return $this;
} | [
"public",
"function",
"setOperator",
"(",
"$",
"operator",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"operator",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Operator should be a string.'",
")",
";",
"}",
"$",
"operator",
"=",
"strtoupper",
"(",
"$",
"operator",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"operator",
",",
"$",
"this",
"->",
"validOperators",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Comparison operator \"%s\" not allowed in this context.'",
",",
"$",
"operator",
")",
")",
";",
"}",
"$",
"this",
"->",
"operator",
"=",
"$",
"operator",
";",
"return",
"$",
"this",
";",
"}"
] | Set the operator used for comparing field and value.
@param string $operator The comparison operator.
@throws InvalidArgumentException If the parameter is not a valid operator.
@return self | [
"Set",
"the",
"operator",
"used",
"for",
"comparing",
"field",
"and",
"value",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L240-L258 |
29,282 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.setFunc | public function setFunc($func)
{
if ($func === null) {
$this->func = $func;
return $this;
}
if (!is_string($func)) {
throw new InvalidArgumentException(
'Function name should be a string.'
);
}
$func = strtoupper($func);
if (!in_array($func, $this->validFunc())) {
throw new InvalidArgumentException(sprintf(
'Function "%s" not allowed in this context.',
$func
));
}
$this->func = $func;
return $this;
} | php | public function setFunc($func)
{
if ($func === null) {
$this->func = $func;
return $this;
}
if (!is_string($func)) {
throw new InvalidArgumentException(
'Function name should be a string.'
);
}
$func = strtoupper($func);
if (!in_array($func, $this->validFunc())) {
throw new InvalidArgumentException(sprintf(
'Function "%s" not allowed in this context.',
$func
));
}
$this->func = $func;
return $this;
} | [
"public",
"function",
"setFunc",
"(",
"$",
"func",
")",
"{",
"if",
"(",
"$",
"func",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"func",
"=",
"$",
"func",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"func",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Function name should be a string.'",
")",
";",
"}",
"$",
"func",
"=",
"strtoupper",
"(",
"$",
"func",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"func",
",",
"$",
"this",
"->",
"validFunc",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Function \"%s\" not allowed in this context.'",
",",
"$",
"func",
")",
")",
";",
"}",
"$",
"this",
"->",
"func",
"=",
"$",
"func",
";",
"return",
"$",
"this",
";",
"}"
] | Set the function to be called on the expression.
@param string $func The function name to invoke on the field.
@throws InvalidArgumentException If the parameter is not a valid function.
@return self | [
"Set",
"the",
"function",
"to",
"be",
"called",
"on",
"the",
"expression",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L277-L300 |
29,283 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.setConjunction | public function setConjunction($conjunction)
{
if (!is_string($conjunction)) {
throw new InvalidArgumentException(
'Conjunction should be a string.'
);
}
$conjunction = strtoupper($conjunction);
if (!in_array($conjunction, $this->validConjunctions())) {
throw new InvalidArgumentException(sprintf(
'Conjunction "%s" not allowed in this context.',
$conjunction
));
}
$this->conjunction = $conjunction;
return $this;
} | php | public function setConjunction($conjunction)
{
if (!is_string($conjunction)) {
throw new InvalidArgumentException(
'Conjunction should be a string.'
);
}
$conjunction = strtoupper($conjunction);
if (!in_array($conjunction, $this->validConjunctions())) {
throw new InvalidArgumentException(sprintf(
'Conjunction "%s" not allowed in this context.',
$conjunction
));
}
$this->conjunction = $conjunction;
return $this;
} | [
"public",
"function",
"setConjunction",
"(",
"$",
"conjunction",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"conjunction",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Conjunction should be a string.'",
")",
";",
"}",
"$",
"conjunction",
"=",
"strtoupper",
"(",
"$",
"conjunction",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"conjunction",
",",
"$",
"this",
"->",
"validConjunctions",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Conjunction \"%s\" not allowed in this context.'",
",",
"$",
"conjunction",
")",
")",
";",
"}",
"$",
"this",
"->",
"conjunction",
"=",
"$",
"conjunction",
";",
"return",
"$",
"this",
";",
"}"
] | Set the conjunction for joining the conditions of this expression.
@param string $conjunction The separator to use.
@throws InvalidArgumentException If the parameter is not a valid conjunction.
@return self | [
"Set",
"the",
"conjunction",
"for",
"joining",
"the",
"conditions",
"of",
"this",
"expression",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L319-L337 |
29,284 | locomotivemtl/charcoal-core | src/Charcoal/Source/Filter.php | Filter.createFilter | protected function createFilter(array $data = null)
{
$filter = new static();
if ($data !== null) {
$filter->setData($data);
}
return $filter;
} | php | protected function createFilter(array $data = null)
{
$filter = new static();
if ($data !== null) {
$filter->setData($data);
}
return $filter;
} | [
"protected",
"function",
"createFilter",
"(",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"filter",
"=",
"new",
"static",
"(",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"null",
")",
"{",
"$",
"filter",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"filter",
";",
"}"
] | Create a new filter expression.
@see FilterCollectionTrait::createFilter()
@param array $data Optional expression data.
@return self | [
"Create",
"a",
"new",
"filter",
"expression",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Filter.php#L426-L433 |
29,285 | rosasurfer/ministruts | src/db/orm/meta/EntityMapping.php | EntityMapping.getProperty | public function getProperty($name) {
if (!isset($this->mapping['properties'][$name]))
return null;
if (!isset($this->properties[$name]))
$this->properties[$name] = new PropertyMapping($this, $this->mapping['properties'][$name]);
return $this->properties[$name];
} | php | public function getProperty($name) {
if (!isset($this->mapping['properties'][$name]))
return null;
if (!isset($this->properties[$name]))
$this->properties[$name] = new PropertyMapping($this, $this->mapping['properties'][$name]);
return $this->properties[$name];
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"mapping",
"[",
"'properties'",
"]",
"[",
"$",
"name",
"]",
")",
")",
"return",
"null",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
")",
")",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
"=",
"new",
"PropertyMapping",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"mapping",
"[",
"'properties'",
"]",
"[",
"$",
"name",
"]",
")",
";",
"return",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
";",
"}"
] | Return the mapping instance of the property with the specified name.
@param string $name - a property's PHP name
@return PropertyMapping|null - mapping or NULL if no such property exists | [
"Return",
"the",
"mapping",
"instance",
"of",
"the",
"property",
"with",
"the",
"specified",
"name",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/meta/EntityMapping.php#L76-L84 |
29,286 | rosasurfer/ministruts | src/db/orm/meta/EntityMapping.php | EntityMapping.getIdentity | public function getIdentity() {
if ($this->identity === null) {
foreach ($this->mapping['properties'] as $name => $property) {
if (isset($property['primary']) && $property['primary']===true) {
return $this->identity = new PropertyMapping($this, $property);
}
}
throw new RuntimeException('Invalid mapping for entity "'.$this->getClassName().'" (missing primary key mapping)');
}
return $this->identity;
} | php | public function getIdentity() {
if ($this->identity === null) {
foreach ($this->mapping['properties'] as $name => $property) {
if (isset($property['primary']) && $property['primary']===true) {
return $this->identity = new PropertyMapping($this, $property);
}
}
throw new RuntimeException('Invalid mapping for entity "'.$this->getClassName().'" (missing primary key mapping)');
}
return $this->identity;
} | [
"public",
"function",
"getIdentity",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"identity",
"===",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mapping",
"[",
"'properties'",
"]",
"as",
"$",
"name",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'primary'",
"]",
")",
"&&",
"$",
"property",
"[",
"'primary'",
"]",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"identity",
"=",
"new",
"PropertyMapping",
"(",
"$",
"this",
",",
"$",
"property",
")",
";",
"}",
"}",
"throw",
"new",
"RuntimeException",
"(",
"'Invalid mapping for entity \"'",
".",
"$",
"this",
"->",
"getClassName",
"(",
")",
".",
"'\" (missing primary key mapping)'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"identity",
";",
"}"
] | Return the mapping instance of the entity's identity property.
@return PropertyMapping | [
"Return",
"the",
"mapping",
"instance",
"of",
"the",
"entity",
"s",
"identity",
"property",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/meta/EntityMapping.php#L92-L102 |
29,287 | rosasurfer/ministruts | src/db/orm/meta/EntityMapping.php | EntityMapping.getVersion | public function getVersion() {
if ($this->version === null) {
foreach ($this->mapping['properties'] as $name => $property) {
if (isset($property['version']) && $property['version']===true) {
return $this->version = new PropertyMapping($this, $property);
}
}
$this->version = false;
}
return $this->version ?: null;
} | php | public function getVersion() {
if ($this->version === null) {
foreach ($this->mapping['properties'] as $name => $property) {
if (isset($property['version']) && $property['version']===true) {
return $this->version = new PropertyMapping($this, $property);
}
}
$this->version = false;
}
return $this->version ?: null;
} | [
"public",
"function",
"getVersion",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"version",
"===",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mapping",
"[",
"'properties'",
"]",
"as",
"$",
"name",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"property",
"[",
"'version'",
"]",
")",
"&&",
"$",
"property",
"[",
"'version'",
"]",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"version",
"=",
"new",
"PropertyMapping",
"(",
"$",
"this",
",",
"$",
"property",
")",
";",
"}",
"}",
"$",
"this",
"->",
"version",
"=",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"version",
"?",
":",
"null",
";",
"}"
] | Return the mapping instance of the entity's versioning property.
@return PropertyMapping|null - mapping or NULL if versioning is not configured | [
"Return",
"the",
"mapping",
"instance",
"of",
"the",
"entity",
"s",
"versioning",
"property",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/meta/EntityMapping.php#L110-L120 |
29,288 | rosasurfer/ministruts | src/db/orm/meta/EntityMapping.php | EntityMapping.rewind | public function rewind() {
if ($this->iteratorKeys === null) {
$this->iteratorKeys = \array_keys($this->mapping['properties']);
}
$this->iteratorPosition = 0;
} | php | public function rewind() {
if ($this->iteratorKeys === null) {
$this->iteratorKeys = \array_keys($this->mapping['properties']);
}
$this->iteratorPosition = 0;
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"iteratorKeys",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"iteratorKeys",
"=",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"mapping",
"[",
"'properties'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"iteratorPosition",
"=",
"0",
";",
"}"
] | Reset the current iterator position. | [
"Reset",
"the",
"current",
"iterator",
"position",
"."
] | 9d27f93dd53d2d626c75c92cfde9d004bab34d30 | https://github.com/rosasurfer/ministruts/blob/9d27f93dd53d2d626c75c92cfde9d004bab34d30/src/db/orm/meta/EntityMapping.php#L126-L131 |
29,289 | timble/kodekit | code/view/behavior/decoratable.php | ViewBehaviorDecoratable._afterRender | protected function _afterRender(ViewContextInterface $context)
{
foreach ($this->getDecorators() as $decorator)
{
//Set the content to allow it to be decorated
$this->setContent($context->result);
//A fully qualified template path is required
$layout = $this->qualifyLayout($decorator);
//Unpack the data (first level only)
$data = $context->data->toArray();
$context->result = $this->getTemplate()
->setParameters($context->parameters)
->render($layout, $data);
}
} | php | protected function _afterRender(ViewContextInterface $context)
{
foreach ($this->getDecorators() as $decorator)
{
//Set the content to allow it to be decorated
$this->setContent($context->result);
//A fully qualified template path is required
$layout = $this->qualifyLayout($decorator);
//Unpack the data (first level only)
$data = $context->data->toArray();
$context->result = $this->getTemplate()
->setParameters($context->parameters)
->render($layout, $data);
}
} | [
"protected",
"function",
"_afterRender",
"(",
"ViewContextInterface",
"$",
"context",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getDecorators",
"(",
")",
"as",
"$",
"decorator",
")",
"{",
"//Set the content to allow it to be decorated",
"$",
"this",
"->",
"setContent",
"(",
"$",
"context",
"->",
"result",
")",
";",
"//A fully qualified template path is required",
"$",
"layout",
"=",
"$",
"this",
"->",
"qualifyLayout",
"(",
"$",
"decorator",
")",
";",
"//Unpack the data (first level only)",
"$",
"data",
"=",
"$",
"context",
"->",
"data",
"->",
"toArray",
"(",
")",
";",
"$",
"context",
"->",
"result",
"=",
"$",
"this",
"->",
"getTemplate",
"(",
")",
"->",
"setParameters",
"(",
"$",
"context",
"->",
"parameters",
")",
"->",
"render",
"(",
"$",
"layout",
",",
"$",
"data",
")",
";",
"}",
"}"
] | Decorate the view
@param ViewContextInterface $context A view context object
@return void | [
"Decorate",
"the",
"view"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/view/behavior/decoratable.php#L93-L110 |
29,290 | timble/kodekit | code/dispatcher/behavior/authenticatable.php | DispatcherBehaviorAuthenticatable.getAuthenticator | public function getAuthenticator($authenticator)
{
$result = null;
if(isset($this->__authenticators[$authenticator])) {
$result = $this->__authenticators[$authenticator];
}
return $result;
} | php | public function getAuthenticator($authenticator)
{
$result = null;
if(isset($this->__authenticators[$authenticator])) {
$result = $this->__authenticators[$authenticator];
}
return $result;
} | [
"public",
"function",
"getAuthenticator",
"(",
"$",
"authenticator",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"__authenticators",
"[",
"$",
"authenticator",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"__authenticators",
"[",
"$",
"authenticator",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get an authenticator by identifier
@param mixed $authenticator An object that implements ObjectInterface, ObjectIdentifier object
or valid identifier string
@return DispatcherAuthenticatorInterface|null | [
"Get",
"an",
"authenticator",
"by",
"identifier"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/behavior/authenticatable.php#L147-L156 |
29,291 | timble/kodekit | code/dispatcher/behavior/authenticatable.php | DispatcherBehaviorAuthenticatable._beforeDispatch | protected function _beforeDispatch(DispatcherContext $context)
{
// Check if the user has been explicitly authenticated for this request
if (!$this->getUser()->isAuthentic(true))
{
foreach($this->__authenticator_queue as $authenticator)
{
if($authenticator->authenticateRequest($context) === true) {
break;
}
}
}
} | php | protected function _beforeDispatch(DispatcherContext $context)
{
// Check if the user has been explicitly authenticated for this request
if (!$this->getUser()->isAuthentic(true))
{
foreach($this->__authenticator_queue as $authenticator)
{
if($authenticator->authenticateRequest($context) === true) {
break;
}
}
}
} | [
"protected",
"function",
"_beforeDispatch",
"(",
"DispatcherContext",
"$",
"context",
")",
"{",
"// Check if the user has been explicitly authenticated for this request",
"if",
"(",
"!",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"isAuthentic",
"(",
"true",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"__authenticator_queue",
"as",
"$",
"authenticator",
")",
"{",
"if",
"(",
"$",
"authenticator",
"->",
"authenticateRequest",
"(",
"$",
"context",
")",
"===",
"true",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}"
] | Authenticate the request
If an authenticator explicitly returns TRUE the authentication process will be halted and other authenticators
will not be called.
@param DispatcherContextInterface $context A dispatcher context object
@return void | [
"Authenticate",
"the",
"request"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/dispatcher/behavior/authenticatable.php#L167-L180 |
29,292 | timble/kodekit | code/database/table/abstract.php | DatabaseTableAbstract.setIdentityColumn | public function setIdentityColumn($column)
{
$columns = $this->getUniqueColumns();
if (!isset($columns[$column])) {
throw new \DomainException('Column ' . $column . 'is not unique');
}
$this->_identity_column = $column;
return $this;
} | php | public function setIdentityColumn($column)
{
$columns = $this->getUniqueColumns();
if (!isset($columns[$column])) {
throw new \DomainException('Column ' . $column . 'is not unique');
}
$this->_identity_column = $column;
return $this;
} | [
"public",
"function",
"setIdentityColumn",
"(",
"$",
"column",
")",
"{",
"$",
"columns",
"=",
"$",
"this",
"->",
"getUniqueColumns",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"columns",
"[",
"$",
"column",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Column '",
".",
"$",
"column",
".",
"'is not unique'",
")",
";",
"}",
"$",
"this",
"->",
"_identity_column",
"=",
"$",
"column",
";",
"return",
"$",
"this",
";",
"}"
] | Set the identity column of the table.
@param string $column The name of the identity column
@throws \DomainException If the column is not unique
@return DatabaseTableAbstract | [
"Set",
"the",
"identity",
"column",
"of",
"the",
"table",
"."
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/table/abstract.php#L385-L395 |
29,293 | timble/kodekit | code/database/table/abstract.php | DatabaseTableAbstract.createRow | public function createRow(array $options = array())
{
$identifier = $this->getIdentifier()->toArray();
$identifier['path'] = array('database', 'row');
$identifier['name'] = StringInflector::singularize($this->getIdentifier()->name);
//Force the table
$options['table'] = $this;
//Set the identity column if not set already
if (!isset($options['identity_column'])) {
$options['identity_column'] = $this->mapColumns($this->getIdentityColumn(), true);
}
return $this->getObject($identifier, $options);
} | php | public function createRow(array $options = array())
{
$identifier = $this->getIdentifier()->toArray();
$identifier['path'] = array('database', 'row');
$identifier['name'] = StringInflector::singularize($this->getIdentifier()->name);
//Force the table
$options['table'] = $this;
//Set the identity column if not set already
if (!isset($options['identity_column'])) {
$options['identity_column'] = $this->mapColumns($this->getIdentityColumn(), true);
}
return $this->getObject($identifier, $options);
} | [
"public",
"function",
"createRow",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"identifier",
"[",
"'path'",
"]",
"=",
"array",
"(",
"'database'",
",",
"'row'",
")",
";",
"$",
"identifier",
"[",
"'name'",
"]",
"=",
"StringInflector",
"::",
"singularize",
"(",
"$",
"this",
"->",
"getIdentifier",
"(",
")",
"->",
"name",
")",
";",
"//Force the table",
"$",
"options",
"[",
"'table'",
"]",
"=",
"$",
"this",
";",
"//Set the identity column if not set already",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'identity_column'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'identity_column'",
"]",
"=",
"$",
"this",
"->",
"mapColumns",
"(",
"$",
"this",
"->",
"getIdentityColumn",
"(",
")",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getObject",
"(",
"$",
"identifier",
",",
"$",
"options",
")",
";",
"}"
] | Get an instance of a row object for this table
@param array $options An optional associative array of configuration settings.
@return DatabaseRowInterface | [
"Get",
"an",
"instance",
"of",
"a",
"row",
"object",
"for",
"this",
"table"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/table/abstract.php#L475-L490 |
29,294 | timble/kodekit | code/database/table/abstract.php | DatabaseTableAbstract.lock | public function lock()
{
$result = null;
$context = $this->getContext();
$context->table = $this->getBase();
if ($this->invokeCommand('before.lock', $context) !== false)
{
if ($this->isConnected()) {
$context->result = $this->getDriver()->lock($this->getBase());
}
$this->invokeCommand('after.lock', $context);
}
return $context->result;
} | php | public function lock()
{
$result = null;
$context = $this->getContext();
$context->table = $this->getBase();
if ($this->invokeCommand('before.lock', $context) !== false)
{
if ($this->isConnected()) {
$context->result = $this->getDriver()->lock($this->getBase());
}
$this->invokeCommand('after.lock', $context);
}
return $context->result;
} | [
"public",
"function",
"lock",
"(",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"context",
"->",
"table",
"=",
"$",
"this",
"->",
"getBase",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"invokeCommand",
"(",
"'before.lock'",
",",
"$",
"context",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"$",
"context",
"->",
"result",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"lock",
"(",
"$",
"this",
"->",
"getBase",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"invokeCommand",
"(",
"'after.lock'",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"context",
"->",
"result",
";",
"}"
] | Lock the table.
return boolean True on success, false otherwise. | [
"Lock",
"the",
"table",
"."
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/database/table/abstract.php#L831-L848 |
29,295 | timble/kodekit | code/filesystem/locator/abstract.php | FilesystemLocatorAbstract.locate | final public function locate($url)
{
$result = false;
if(!isset($this->__location_cache[$url]))
{
$info = $this->parseUrl($url);
//Find the file
foreach($this->getPathTemplates($url) as $template)
{
$path = str_replace(
array('<Package>' , '<Path>' ,'<File>' , '<Format>' , '<Type>'),
array($info['package'], $info['path'], $info['file'], $info['format'], $info['type']),
$template
);
if ($results = glob($path))
{
foreach($results as $file)
{
if($result = $this->realPath($file)) {
break (2);
}
}
}
}
$this->__location_cache[$url] = $result;
}
return $this->__location_cache[$url];
} | php | final public function locate($url)
{
$result = false;
if(!isset($this->__location_cache[$url]))
{
$info = $this->parseUrl($url);
//Find the file
foreach($this->getPathTemplates($url) as $template)
{
$path = str_replace(
array('<Package>' , '<Path>' ,'<File>' , '<Format>' , '<Type>'),
array($info['package'], $info['path'], $info['file'], $info['format'], $info['type']),
$template
);
if ($results = glob($path))
{
foreach($results as $file)
{
if($result = $this->realPath($file)) {
break (2);
}
}
}
}
$this->__location_cache[$url] = $result;
}
return $this->__location_cache[$url];
} | [
"final",
"public",
"function",
"locate",
"(",
"$",
"url",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"__location_cache",
"[",
"$",
"url",
"]",
")",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"parseUrl",
"(",
"$",
"url",
")",
";",
"//Find the file",
"foreach",
"(",
"$",
"this",
"->",
"getPathTemplates",
"(",
"$",
"url",
")",
"as",
"$",
"template",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"array",
"(",
"'<Package>'",
",",
"'<Path>'",
",",
"'<File>'",
",",
"'<Format>'",
",",
"'<Type>'",
")",
",",
"array",
"(",
"$",
"info",
"[",
"'package'",
"]",
",",
"$",
"info",
"[",
"'path'",
"]",
",",
"$",
"info",
"[",
"'file'",
"]",
",",
"$",
"info",
"[",
"'format'",
"]",
",",
"$",
"info",
"[",
"'type'",
"]",
")",
",",
"$",
"template",
")",
";",
"if",
"(",
"$",
"results",
"=",
"glob",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"realPath",
"(",
"$",
"file",
")",
")",
"{",
"break",
"(",
"2",
")",
";",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"__location_cache",
"[",
"$",
"url",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"__location_cache",
"[",
"$",
"url",
"]",
";",
"}"
] | Locate the resource based on a url
@param string $url The resource url
@return string|false The physical file path for the resource or FALSE if the url cannot be located | [
"Locate",
"the",
"resource",
"based",
"on",
"a",
"url"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/filesystem/locator/abstract.php#L89-L121 |
29,296 | timble/kodekit | code/filesystem/locator/abstract.php | FilesystemLocatorAbstract.parseUrl | public function parseUrl($url)
{
$scheme = parse_url($url, PHP_URL_SCHEME);
$domain = parse_url($url, PHP_URL_HOST);
$basename = pathinfo($url, PATHINFO_BASENAME);
$parts = explode('.', $basename);
if(count($parts) == 3)
{
$type = array_pop($parts);
$format = array_pop($parts);
$file = array_pop($parts);
}
else
{
$type = '*';
$format = array_pop($parts);
$file = array_pop($parts);
}
$path = str_replace(array($scheme.'://', $scheme.':'), '', dirname($url));
if (strpos($path, $domain.'/') === 0) {
$path = substr($path, strlen($domain)+1);
}
$parts = explode('/', $path);
$info = array(
'type' => $type,
'domain' => $domain,
'package' => array_shift($parts),
'path' => implode('/', $parts),
'file' => $file,
'format' => $format ?: '*',
);
return $info;
} | php | public function parseUrl($url)
{
$scheme = parse_url($url, PHP_URL_SCHEME);
$domain = parse_url($url, PHP_URL_HOST);
$basename = pathinfo($url, PATHINFO_BASENAME);
$parts = explode('.', $basename);
if(count($parts) == 3)
{
$type = array_pop($parts);
$format = array_pop($parts);
$file = array_pop($parts);
}
else
{
$type = '*';
$format = array_pop($parts);
$file = array_pop($parts);
}
$path = str_replace(array($scheme.'://', $scheme.':'), '', dirname($url));
if (strpos($path, $domain.'/') === 0) {
$path = substr($path, strlen($domain)+1);
}
$parts = explode('/', $path);
$info = array(
'type' => $type,
'domain' => $domain,
'package' => array_shift($parts),
'path' => implode('/', $parts),
'file' => $file,
'format' => $format ?: '*',
);
return $info;
} | [
"public",
"function",
"parseUrl",
"(",
"$",
"url",
")",
"{",
"$",
"scheme",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_SCHEME",
")",
";",
"$",
"domain",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_HOST",
")",
";",
"$",
"basename",
"=",
"pathinfo",
"(",
"$",
"url",
",",
"PATHINFO_BASENAME",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"basename",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"3",
")",
"{",
"$",
"type",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"format",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"file",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"'*'",
";",
"$",
"format",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"file",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"$",
"path",
"=",
"str_replace",
"(",
"array",
"(",
"$",
"scheme",
".",
"'://'",
",",
"$",
"scheme",
".",
"':'",
")",
",",
"''",
",",
"dirname",
"(",
"$",
"url",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"$",
"domain",
".",
"'/'",
")",
"===",
"0",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"domain",
")",
"+",
"1",
")",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"info",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'domain'",
"=>",
"$",
"domain",
",",
"'package'",
"=>",
"array_shift",
"(",
"$",
"parts",
")",
",",
"'path'",
"=>",
"implode",
"(",
"'/'",
",",
"$",
"parts",
")",
",",
"'file'",
"=>",
"$",
"file",
",",
"'format'",
"=>",
"$",
"format",
"?",
":",
"'*'",
",",
")",
";",
"return",
"$",
"info",
";",
"}"
] | Parse the url
@param string $url The language url
@return array | [
"Parse",
"the",
"url"
] | 4c376f8873f8d10c55e3d290616ff622605cd246 | https://github.com/timble/kodekit/blob/4c376f8873f8d10c55e3d290616ff622605cd246/code/filesystem/locator/abstract.php#L129-L168 |
29,297 | locomotivemtl/charcoal-core | src/Charcoal/Source/Order.php | Order.setData | public function setData(array $data)
{
parent::setData($data);
/** @deprecated */
if (isset($data['string'])) {
trigger_error(
sprintf(
'Sort expression option "string" is deprecated in favour of "condition": %s',
$data['string']
),
E_USER_DEPRECATED
);
$this->setCondition($data['string']);
}
/** @deprecated */
if (isset($data['table_name'])) {
trigger_error(
sprintf(
'Sort expression option "table_name" is deprecated in favour of "table": %s',
$data['table_name']
),
E_USER_DEPRECATED
);
$this->setTable($data['table_name']);
}
if (isset($data['table'])) {
$this->setTable($data['table']);
}
if (isset($data['property'])) {
$this->setProperty($data['property']);
}
if (isset($data['direction'])) {
$this->setDirection($data['direction']);
}
if (isset($data['mode'])) {
$this->setMode($data['mode']);
}
if (isset($data['values'])) {
$this->setValues($data['values']);
if (!isset($data['mode'])) {
$this->setMode(self::MODE_VALUES);
}
}
if (isset($data['condition']) || isset($data['string'])) {
if (!isset($data['mode'])) {
$this->setMode(self::MODE_CUSTOM);
}
}
return $this;
} | php | public function setData(array $data)
{
parent::setData($data);
/** @deprecated */
if (isset($data['string'])) {
trigger_error(
sprintf(
'Sort expression option "string" is deprecated in favour of "condition": %s',
$data['string']
),
E_USER_DEPRECATED
);
$this->setCondition($data['string']);
}
/** @deprecated */
if (isset($data['table_name'])) {
trigger_error(
sprintf(
'Sort expression option "table_name" is deprecated in favour of "table": %s',
$data['table_name']
),
E_USER_DEPRECATED
);
$this->setTable($data['table_name']);
}
if (isset($data['table'])) {
$this->setTable($data['table']);
}
if (isset($data['property'])) {
$this->setProperty($data['property']);
}
if (isset($data['direction'])) {
$this->setDirection($data['direction']);
}
if (isset($data['mode'])) {
$this->setMode($data['mode']);
}
if (isset($data['values'])) {
$this->setValues($data['values']);
if (!isset($data['mode'])) {
$this->setMode(self::MODE_VALUES);
}
}
if (isset($data['condition']) || isset($data['string'])) {
if (!isset($data['mode'])) {
$this->setMode(self::MODE_CUSTOM);
}
}
return $this;
} | [
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"parent",
"::",
"setData",
"(",
"$",
"data",
")",
";",
"/** @deprecated */",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'string'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'Sort expression option \"string\" is deprecated in favour of \"condition\": %s'",
",",
"$",
"data",
"[",
"'string'",
"]",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"setCondition",
"(",
"$",
"data",
"[",
"'string'",
"]",
")",
";",
"}",
"/** @deprecated */",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'table_name'",
"]",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'Sort expression option \"table_name\" is deprecated in favour of \"table\": %s'",
",",
"$",
"data",
"[",
"'table_name'",
"]",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"setTable",
"(",
"$",
"data",
"[",
"'table_name'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'table'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setTable",
"(",
"$",
"data",
"[",
"'table'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'property'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setProperty",
"(",
"$",
"data",
"[",
"'property'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'direction'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setDirection",
"(",
"$",
"data",
"[",
"'direction'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'mode'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMode",
"(",
"$",
"data",
"[",
"'mode'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'values'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setValues",
"(",
"$",
"data",
"[",
"'values'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'mode'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMode",
"(",
"self",
"::",
"MODE_VALUES",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'condition'",
"]",
")",
"||",
"isset",
"(",
"$",
"data",
"[",
"'string'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'mode'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setMode",
"(",
"self",
"::",
"MODE_CUSTOM",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the order clause data.
@param array<string,mixed> $data The expression data;
as an associative array.
@return self | [
"Set",
"the",
"order",
"clause",
"data",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Order.php#L66-L125 |
29,298 | locomotivemtl/charcoal-core | src/Charcoal/Source/Order.php | Order.data | public function data()
{
return [
'property' => $this->property(),
'table' => $this->table(),
'direction' => $this->direction(),
'mode' => $this->mode(),
'values' => $this->values(),
'condition' => $this->condition(),
'active' => $this->active(),
'name' => $this->name(),
];
} | php | public function data()
{
return [
'property' => $this->property(),
'table' => $this->table(),
'direction' => $this->direction(),
'mode' => $this->mode(),
'values' => $this->values(),
'condition' => $this->condition(),
'active' => $this->active(),
'name' => $this->name(),
];
} | [
"public",
"function",
"data",
"(",
")",
"{",
"return",
"[",
"'property'",
"=>",
"$",
"this",
"->",
"property",
"(",
")",
",",
"'table'",
"=>",
"$",
"this",
"->",
"table",
"(",
")",
",",
"'direction'",
"=>",
"$",
"this",
"->",
"direction",
"(",
")",
",",
"'mode'",
"=>",
"$",
"this",
"->",
"mode",
"(",
")",
",",
"'values'",
"=>",
"$",
"this",
"->",
"values",
"(",
")",
",",
"'condition'",
"=>",
"$",
"this",
"->",
"condition",
"(",
")",
",",
"'active'",
"=>",
"$",
"this",
"->",
"active",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"name",
"(",
")",
",",
"]",
";",
"}"
] | Retrieve the order clause structure.
@return array<string,mixed> An associative array. | [
"Retrieve",
"the",
"order",
"clause",
"structure",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Order.php#L151-L163 |
29,299 | locomotivemtl/charcoal-core | src/Charcoal/Source/Order.php | Order.setMode | public function setMode($mode)
{
if ($mode === null) {
$this->mode = $mode;
return $this;
}
if (!is_string($mode)) {
throw new InvalidArgumentException(
'Order Mode must be a string.'
);
}
$mode = strtolower($mode);
$valid = $this->validModes();
if (!in_array($mode, $valid)) {
throw new InvalidArgumentException(sprintf(
'Invalid Order Mode. Must be one of "%s"',
implode('", "', $valid)
));
}
if (in_array($mode, [ self::MODE_ASC, self::MODE_DESC ])) {
$this->setDirection($mode);
}
$this->mode = $mode;
return $this;
} | php | public function setMode($mode)
{
if ($mode === null) {
$this->mode = $mode;
return $this;
}
if (!is_string($mode)) {
throw new InvalidArgumentException(
'Order Mode must be a string.'
);
}
$mode = strtolower($mode);
$valid = $this->validModes();
if (!in_array($mode, $valid)) {
throw new InvalidArgumentException(sprintf(
'Invalid Order Mode. Must be one of "%s"',
implode('", "', $valid)
));
}
if (in_array($mode, [ self::MODE_ASC, self::MODE_DESC ])) {
$this->setDirection($mode);
}
$this->mode = $mode;
return $this;
} | [
"public",
"function",
"setMode",
"(",
"$",
"mode",
")",
"{",
"if",
"(",
"$",
"mode",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"mode",
"=",
"$",
"mode",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"mode",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Order Mode must be a string.'",
")",
";",
"}",
"$",
"mode",
"=",
"strtolower",
"(",
"$",
"mode",
")",
";",
"$",
"valid",
"=",
"$",
"this",
"->",
"validModes",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"mode",
",",
"$",
"valid",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid Order Mode. Must be one of \"%s\"'",
",",
"implode",
"(",
"'\", \"'",
",",
"$",
"valid",
")",
")",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"mode",
",",
"[",
"self",
"::",
"MODE_ASC",
",",
"self",
"::",
"MODE_DESC",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setDirection",
"(",
"$",
"mode",
")",
";",
"}",
"$",
"this",
"->",
"mode",
"=",
"$",
"mode",
";",
"return",
"$",
"this",
";",
"}"
] | Set the, pre-defined, sorting mode.
@param string|null $mode The sorting mode.
@throws InvalidArgumentException If the mode is not a string or invalid.
@return self | [
"Set",
"the",
"pre",
"-",
"defined",
"sorting",
"mode",
"."
] | db3a7af547ccf96efe2d9be028b252bc8646f5d5 | https://github.com/locomotivemtl/charcoal-core/blob/db3a7af547ccf96efe2d9be028b252bc8646f5d5/src/Charcoal/Source/Order.php#L172-L200 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.