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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
25,400
|
bseddon/XPath20
|
DOM/DOMXPathNavigator.php
|
DOMXPathNavigator.MoveToNextAttribute
|
public function MoveToNextAttribute()
{
if ( is_null( $this->domNode ) || ! $this->domNode instanceof \DOMAttr )
{
return false;
}
$next = $this->domNode->nextSibling;
if ( is_null( $next ) ) return false;
$this->domNode = $next;
return true;
}
|
php
|
public function MoveToNextAttribute()
{
if ( is_null( $this->domNode ) || ! $this->domNode instanceof \DOMAttr )
{
return false;
}
$next = $this->domNode->nextSibling;
if ( is_null( $next ) ) return false;
$this->domNode = $next;
return true;
}
|
[
"public",
"function",
"MoveToNextAttribute",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
"||",
"!",
"$",
"this",
"->",
"domNode",
"instanceof",
"\\",
"DOMAttr",
")",
"{",
"return",
"false",
";",
"}",
"$",
"next",
"=",
"$",
"this",
"->",
"domNode",
"->",
"nextSibling",
";",
"if",
"(",
"is_null",
"(",
"$",
"next",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"domNode",
"=",
"$",
"next",
";",
"return",
"true",
";",
"}"
] |
When overridden in a derived class, moves the XPathNavigator
to the next attribute.
@return bool Returns true if the XPathNavigator is successful moving to the next attribute;
false if there are no more attributes. If false, the position of the XPathNavigator is unchanged.
|
[
"When",
"overridden",
"in",
"a",
"derived",
"class",
"moves",
"the",
"XPathNavigator",
"to",
"the",
"next",
"attribute",
"."
] |
69882b6efffaa5470a819d5fdd2f6473ddeb046d
|
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathNavigator.php#L924-L937
|
25,401
|
bseddon/XPath20
|
DOM/DOMXPathNavigator.php
|
DOMXPathNavigator.MoveToNextNamespace
|
public function MoveToNextNamespace( $namespaceScope = XPathNamespaceScope::Local )
{
if ( is_null( $this->domNode ) ) return false;
if ( $this->domNode->nodeType != XML_NAMESPACE_DECL_NODE ) return false;
$expression = $namespaceScope == XPathNamespaceScope::Local
? 'namespace::*[not(. = ../../namespace::*)]'
: 'namespace::*';
$xpath = new \DOMXPath( $this->domNode->nodeType == XML_DOCUMENT_NODE ? $this->domNode : $this->domNode->ownerDocument );
$namespaces = $xpath->query( $expression, $this->domNode->parentNode );
if ( ! count( $namespaces ) ) return false;
// Find the current node among the enties in the $namespaces list
$current = -1;
foreach ( $namespaces as $node )
{
$current++;
// Can't use the ->isSameNode() function with a DOMNamespaceNode for some reason
// So this concoction is used instead.
if ( $this->domNode->parentNode->getNodePath() . "/" . $this->domNode->nodeName == $node->parentNode->getNodePath() . "/" . $node->nodeName )
{
break;
}
}
if ( $current <= 0 ) return false;
$current--;
$this->domNode = $namespaces[ $current ];
return true;
}
|
php
|
public function MoveToNextNamespace( $namespaceScope = XPathNamespaceScope::Local )
{
if ( is_null( $this->domNode ) ) return false;
if ( $this->domNode->nodeType != XML_NAMESPACE_DECL_NODE ) return false;
$expression = $namespaceScope == XPathNamespaceScope::Local
? 'namespace::*[not(. = ../../namespace::*)]'
: 'namespace::*';
$xpath = new \DOMXPath( $this->domNode->nodeType == XML_DOCUMENT_NODE ? $this->domNode : $this->domNode->ownerDocument );
$namespaces = $xpath->query( $expression, $this->domNode->parentNode );
if ( ! count( $namespaces ) ) return false;
// Find the current node among the enties in the $namespaces list
$current = -1;
foreach ( $namespaces as $node )
{
$current++;
// Can't use the ->isSameNode() function with a DOMNamespaceNode for some reason
// So this concoction is used instead.
if ( $this->domNode->parentNode->getNodePath() . "/" . $this->domNode->nodeName == $node->parentNode->getNodePath() . "/" . $node->nodeName )
{
break;
}
}
if ( $current <= 0 ) return false;
$current--;
$this->domNode = $namespaces[ $current ];
return true;
}
|
[
"public",
"function",
"MoveToNextNamespace",
"(",
"$",
"namespaceScope",
"=",
"XPathNamespaceScope",
"::",
"Local",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
")",
"return",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"domNode",
"->",
"nodeType",
"!=",
"XML_NAMESPACE_DECL_NODE",
")",
"return",
"false",
";",
"$",
"expression",
"=",
"$",
"namespaceScope",
"==",
"XPathNamespaceScope",
"::",
"Local",
"?",
"'namespace::*[not(. = ../../namespace::*)]'",
":",
"'namespace::*'",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXPath",
"(",
"$",
"this",
"->",
"domNode",
"->",
"nodeType",
"==",
"XML_DOCUMENT_NODE",
"?",
"$",
"this",
"->",
"domNode",
":",
"$",
"this",
"->",
"domNode",
"->",
"ownerDocument",
")",
";",
"$",
"namespaces",
"=",
"$",
"xpath",
"->",
"query",
"(",
"$",
"expression",
",",
"$",
"this",
"->",
"domNode",
"->",
"parentNode",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"namespaces",
")",
")",
"return",
"false",
";",
"// Find the current node among the enties in the $namespaces list\r",
"$",
"current",
"=",
"-",
"1",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"node",
")",
"{",
"$",
"current",
"++",
";",
"// Can't use the ->isSameNode() function with a DOMNamespaceNode for some reason\r",
"// So this concoction is used instead.\r",
"if",
"(",
"$",
"this",
"->",
"domNode",
"->",
"parentNode",
"->",
"getNodePath",
"(",
")",
".",
"\"/\"",
".",
"$",
"this",
"->",
"domNode",
"->",
"nodeName",
"==",
"$",
"node",
"->",
"parentNode",
"->",
"getNodePath",
"(",
")",
".",
"\"/\"",
".",
"$",
"node",
"->",
"nodeName",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"current",
"<=",
"0",
")",
"return",
"false",
";",
"$",
"current",
"--",
";",
"$",
"this",
"->",
"domNode",
"=",
"$",
"namespaces",
"[",
"$",
"current",
"]",
";",
"return",
"true",
";",
"}"
] |
When overridden in a derived class, moves the XPathNavigator to the next namespace node matching the
XPathNamespaceScope specified.
@param XPathNamespaceScope $namespaceScope : (optional) An XPathNamespaceScope value describing the namespace scope.
@return bool Returns true if the XPathNavigator is successful moving to the next namespace node; otherwise,
false. If false, the position of the XPathNavigator is unchanged.
|
[
"When",
"overridden",
"in",
"a",
"derived",
"class",
"moves",
"the",
"XPathNavigator",
"to",
"the",
"next",
"namespace",
"node",
"matching",
"the",
"XPathNamespaceScope",
"specified",
"."
] |
69882b6efffaa5470a819d5fdd2f6473ddeb046d
|
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathNavigator.php#L947-L980
|
25,402
|
bseddon/XPath20
|
DOM/DOMXPathNavigator.php
|
DOMXPathNavigator.MoveToParent
|
public function MoveToParent()
{
if ( is_null( $this->domNode ) ) return false;
$parent = $this->domNode->parentNode;
if ( is_null( $parent ) ) return false;
$this->domNode = $parent;
return true;
}
|
php
|
public function MoveToParent()
{
if ( is_null( $this->domNode ) ) return false;
$parent = $this->domNode->parentNode;
if ( is_null( $parent ) ) return false;
$this->domNode = $parent;
return true;
}
|
[
"public",
"function",
"MoveToParent",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
")",
"return",
"false",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"domNode",
"->",
"parentNode",
";",
"if",
"(",
"is_null",
"(",
"$",
"parent",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"domNode",
"=",
"$",
"parent",
";",
"return",
"true",
";",
"}"
] |
When overridden in a derived class, moves the XPathNavigator to the parent node of the current node.
@return bool Returns true if the XPathNavigator is successful moving to the parent node of the current node; otherwise,
false. If false, the position of the XPathNavigator is unchanged.
|
[
"When",
"overridden",
"in",
"a",
"derived",
"class",
"moves",
"the",
"XPathNavigator",
"to",
"the",
"parent",
"node",
"of",
"the",
"current",
"node",
"."
] |
69882b6efffaa5470a819d5fdd2f6473ddeb046d
|
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathNavigator.php#L988-L997
|
25,403
|
bseddon/XPath20
|
DOM/DOMXPathNavigator.php
|
DOMXPathNavigator.MoveToPrevious
|
public function MoveToPrevious()
{
if ( is_null( $this->domNode ) || $this->domNode instanceof \DOMAttr ) return false;
$previous = $this->domNode->previousSibling;
if ( is_null( $previous ) ) return false;
$this->domNode = $previous;
return true;
}
|
php
|
public function MoveToPrevious()
{
if ( is_null( $this->domNode ) || $this->domNode instanceof \DOMAttr ) return false;
$previous = $this->domNode->previousSibling;
if ( is_null( $previous ) ) return false;
$this->domNode = $previous;
return true;
}
|
[
"public",
"function",
"MoveToPrevious",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
"||",
"$",
"this",
"->",
"domNode",
"instanceof",
"\\",
"DOMAttr",
")",
"return",
"false",
";",
"$",
"previous",
"=",
"$",
"this",
"->",
"domNode",
"->",
"previousSibling",
";",
"if",
"(",
"is_null",
"(",
"$",
"previous",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"domNode",
"=",
"$",
"previous",
";",
"return",
"true",
";",
"}"
] |
When overridden in a derived class, moves the XPathNavigator to the previous sibling node of the current node.
@return bool Returns true if the XPathNavigator is successful moving to the previous sibling node; otherwise,
false if there is no previous sibling node or if the XPathNavigator is currently positioned on an
attribute node. If false, the position of the XPathNavigator is unchanged.
|
[
"When",
"overridden",
"in",
"a",
"derived",
"class",
"moves",
"the",
"XPathNavigator",
"to",
"the",
"previous",
"sibling",
"node",
"of",
"the",
"current",
"node",
"."
] |
69882b6efffaa5470a819d5fdd2f6473ddeb046d
|
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathNavigator.php#L1006-L1016
|
25,404
|
bseddon/XPath20
|
DOM/DOMXPathNavigator.php
|
DOMXPathNavigator.ToString
|
public function ToString()
{
if ( is_null( $this->domNode ) ) return "";
if ( $this->domNode instanceof \DOMDocument )
{
$result = $this->domNode->saveXML( null );
// Remove any initial PI
$result = preg_replace( "/^<\?xml.*\?>\s/", "", $result );
return $result;
}
else
{
// InnerXml?
// return array_reduce(
// iterator_to_array( $this->domNode->childNodes ),
// function ( $carry, /** @var \DOMNode */ $child )
// {
// return $carry.$child->ownerDocument->saveXML( $child );
// }
// );
$result = $this->domNode->ownerDocument->SaveXML( $this->domNode );
return $result;
}
}
|
php
|
public function ToString()
{
if ( is_null( $this->domNode ) ) return "";
if ( $this->domNode instanceof \DOMDocument )
{
$result = $this->domNode->saveXML( null );
// Remove any initial PI
$result = preg_replace( "/^<\?xml.*\?>\s/", "", $result );
return $result;
}
else
{
// InnerXml?
// return array_reduce(
// iterator_to_array( $this->domNode->childNodes ),
// function ( $carry, /** @var \DOMNode */ $child )
// {
// return $carry.$child->ownerDocument->saveXML( $child );
// }
// );
$result = $this->domNode->ownerDocument->SaveXML( $this->domNode );
return $result;
}
}
|
[
"public",
"function",
"ToString",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
")",
"return",
"\"\"",
";",
"if",
"(",
"$",
"this",
"->",
"domNode",
"instanceof",
"\\",
"DOMDocument",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"domNode",
"->",
"saveXML",
"(",
"null",
")",
";",
"// Remove any initial PI\r",
"$",
"result",
"=",
"preg_replace",
"(",
"\"/^<\\?xml.*\\?>\\s/\"",
",",
"\"\"",
",",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"// InnerXml?\r",
"// return array_reduce(\r",
"// \titerator_to_array( $this->domNode->childNodes ),\r",
"// \tfunction ( $carry, /** @var \\DOMNode */ $child )\r",
"// \t{\r",
"// \t\treturn $carry.$child->ownerDocument->saveXML( $child );\r",
"// \t}\r",
"// );\r",
"$",
"result",
"=",
"$",
"this",
"->",
"domNode",
"->",
"ownerDocument",
"->",
"SaveXML",
"(",
"$",
"this",
"->",
"domNode",
")",
";",
"return",
"$",
"result",
";",
"}",
"}"
] |
Gets the text value of the current node.
@return string A string that contains the text value of the current node.
|
[
"Gets",
"the",
"text",
"value",
"of",
"the",
"current",
"node",
"."
] |
69882b6efffaa5470a819d5fdd2f6473ddeb046d
|
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathNavigator.php#L1105-L1128
|
25,405
|
ciims/ciims-plugins-awsuploader
|
CiiAWSUploader.php
|
CiiAWSUploader.getCdnURI
|
private function getCdnURI($path)
{
$cleancdn = explode('/', $path);
unset($cleancdn[0]);
unset($cleancdn[1]);
reset($cleancdn);
return implode($cleancdn, '/');
}
|
php
|
private function getCdnURI($path)
{
$cleancdn = explode('/', $path);
unset($cleancdn[0]);
unset($cleancdn[1]);
reset($cleancdn);
return implode($cleancdn, '/');
}
|
[
"private",
"function",
"getCdnURI",
"(",
"$",
"path",
")",
"{",
"$",
"cleancdn",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"unset",
"(",
"$",
"cleancdn",
"[",
"0",
"]",
")",
";",
"unset",
"(",
"$",
"cleancdn",
"[",
"1",
"]",
")",
";",
"reset",
"(",
"$",
"cleancdn",
")",
";",
"return",
"implode",
"(",
"$",
"cleancdn",
",",
"'/'",
")",
";",
"}"
] |
Retrieves a clean version of the CDN URI
@param string $path
@return string
|
[
"Retrieves",
"a",
"clean",
"version",
"of",
"the",
"CDN",
"URI"
] |
59e447e59f873521ebf966051fab6334696546a2
|
https://github.com/ciims/ciims-plugins-awsuploader/blob/59e447e59f873521ebf966051fab6334696546a2/CiiAWSUploader.php#L60-L67
|
25,406
|
jkaflik/process-util
|
src/ProcessUtil/ProcessUtil.php
|
ProcessUtil.executeCommand
|
public function executeCommand(array $arguments, $processBuilderCallback = null)
{
$processBuilder = clone $this->processBuilder;
$processBuilder->setArguments($arguments);
if (is_callable($processBuilderCallback)) {
$processBuilderCallback($processBuilder);
}
$process = $processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
if (127 === $process->getExitCode()) {
throw new ExecutableNotFoundException($process);
}
throw new ProcessFailedException($process);
}
return $process;
}
|
php
|
public function executeCommand(array $arguments, $processBuilderCallback = null)
{
$processBuilder = clone $this->processBuilder;
$processBuilder->setArguments($arguments);
if (is_callable($processBuilderCallback)) {
$processBuilderCallback($processBuilder);
}
$process = $processBuilder->getProcess();
$process->run();
if (!$process->isSuccessful()) {
if (127 === $process->getExitCode()) {
throw new ExecutableNotFoundException($process);
}
throw new ProcessFailedException($process);
}
return $process;
}
|
[
"public",
"function",
"executeCommand",
"(",
"array",
"$",
"arguments",
",",
"$",
"processBuilderCallback",
"=",
"null",
")",
"{",
"$",
"processBuilder",
"=",
"clone",
"$",
"this",
"->",
"processBuilder",
";",
"$",
"processBuilder",
"->",
"setArguments",
"(",
"$",
"arguments",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"processBuilderCallback",
")",
")",
"{",
"$",
"processBuilderCallback",
"(",
"$",
"processBuilder",
")",
";",
"}",
"$",
"process",
"=",
"$",
"processBuilder",
"->",
"getProcess",
"(",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"if",
"(",
"127",
"===",
"$",
"process",
"->",
"getExitCode",
"(",
")",
")",
"{",
"throw",
"new",
"ExecutableNotFoundException",
"(",
"$",
"process",
")",
";",
"}",
"throw",
"new",
"ProcessFailedException",
"(",
"$",
"process",
")",
";",
"}",
"return",
"$",
"process",
";",
"}"
] |
Executes given command
@param array $arguments
@param null $processBuilderCallback
@return \Symfony\Component\Process\Process
@throws ExecutableNotFoundException
@throws ProcessFailedException
|
[
"Executes",
"given",
"command"
] |
8d77f677189980e18e7b57e836d8908b56822bb8
|
https://github.com/jkaflik/process-util/blob/8d77f677189980e18e7b57e836d8908b56822bb8/src/ProcessUtil/ProcessUtil.php#L63-L84
|
25,407
|
angrycoders/db-driver
|
src/Db.php
|
Db.deleteTable
|
public function deleteTable($tableName)
{
try {
$this->db->deleteTable($tableName);
} catch (\Exception $e) {
throw new DbException($e->getMessage());
}
}
|
php
|
public function deleteTable($tableName)
{
try {
$this->db->deleteTable($tableName);
} catch (\Exception $e) {
throw new DbException($e->getMessage());
}
}
|
[
"public",
"function",
"deleteTable",
"(",
"$",
"tableName",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"db",
"->",
"deleteTable",
"(",
"$",
"tableName",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"DbException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Delete a table from db
@param string $tableName the name of the table
@throws DbException
|
[
"Delete",
"a",
"table",
"from",
"db"
] |
e5df527ac0ea5fa434cbda79692f37cf6f2abc73
|
https://github.com/angrycoders/db-driver/blob/e5df527ac0ea5fa434cbda79692f37cf6f2abc73/src/Db.php#L74-L81
|
25,408
|
mossphp/moss-storage
|
Moss/Storage/Schema/Schema.php
|
Schema.retrieveModels
|
protected function retrieveModels(array $entity = [])
{
$models = [];
foreach ((array) $entity as $node) {
$models[] = $this->models->get($node);
}
if (empty($models)) {
$models = $this->models->all();
}
return $models;
}
|
php
|
protected function retrieveModels(array $entity = [])
{
$models = [];
foreach ((array) $entity as $node) {
$models[] = $this->models->get($node);
}
if (empty($models)) {
$models = $this->models->all();
}
return $models;
}
|
[
"protected",
"function",
"retrieveModels",
"(",
"array",
"$",
"entity",
"=",
"[",
"]",
")",
"{",
"$",
"models",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"entity",
"as",
"$",
"node",
")",
"{",
"$",
"models",
"[",
"]",
"=",
"$",
"this",
"->",
"models",
"->",
"get",
"(",
"$",
"node",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"models",
")",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"models",
"->",
"all",
"(",
")",
";",
"}",
"return",
"$",
"models",
";",
"}"
] |
Returns array with models for operation
@param array $entity
@return ModelInterface[]
|
[
"Returns",
"array",
"with",
"models",
"for",
"operation"
] |
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
|
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L129-L141
|
25,409
|
mossphp/moss-storage
|
Moss/Storage/Schema/Schema.php
|
Schema.buildCreate
|
protected function buildCreate(array $models)
{
$schemaManager = $this->connection->getSchemaManager();
foreach ($models as $model) {
if ($schemaManager->tablesExist([$model->table()])) {
throw new SchemaException(sprintf('Unable to create table, table "%s" already exists', $model->table()));
}
$this->createTable($this->schema, $model);
}
$this->queries = array_merge(
$this->queries,
$this->schema->toSql($this->connection->getDatabasePlatform())
);
}
|
php
|
protected function buildCreate(array $models)
{
$schemaManager = $this->connection->getSchemaManager();
foreach ($models as $model) {
if ($schemaManager->tablesExist([$model->table()])) {
throw new SchemaException(sprintf('Unable to create table, table "%s" already exists', $model->table()));
}
$this->createTable($this->schema, $model);
}
$this->queries = array_merge(
$this->queries,
$this->schema->toSql($this->connection->getDatabasePlatform())
);
}
|
[
"protected",
"function",
"buildCreate",
"(",
"array",
"$",
"models",
")",
"{",
"$",
"schemaManager",
"=",
"$",
"this",
"->",
"connection",
"->",
"getSchemaManager",
"(",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"schemaManager",
"->",
"tablesExist",
"(",
"[",
"$",
"model",
"->",
"table",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"SchemaException",
"(",
"sprintf",
"(",
"'Unable to create table, table \"%s\" already exists'",
",",
"$",
"model",
"->",
"table",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"createTable",
"(",
"$",
"this",
"->",
"schema",
",",
"$",
"model",
")",
";",
"}",
"$",
"this",
"->",
"queries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"queries",
",",
"$",
"this",
"->",
"schema",
"->",
"toSql",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
")",
")",
";",
"}"
] |
Builds create table queries
@param ModelInterface[] $models
@throws SchemaException
|
[
"Builds",
"create",
"table",
"queries"
] |
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
|
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L150-L166
|
25,410
|
mossphp/moss-storage
|
Moss/Storage/Schema/Schema.php
|
Schema.createTable
|
protected function createTable(SchemaAsset $schema, ModelInterface $model)
{
$table = $schema->createTable($this->quoteIdentifier($model->table()));
foreach ($model->fields() as $field) {
$table->addColumn(
$this->quoteIdentifier($field->mappedName()),
$field->type(),
$field->attributes()
);
}
foreach ($model->indexes() as $index) {
switch ($index->type()) {
case 'primary':
$table->setPrimaryKey(
$this->quoteIdentifier($index->fields()),
$this->quoteIdentifier($index->name())
);
break;
case 'unique':
$table->addUniqueIndex(
$this->quoteIdentifier($index->fields()),
$this->quoteIdentifier($index->name())
);
break;
case 'foreign':
$table->addForeignKeyConstraint(
$index->table(),
$this->quoteIdentifier(array_keys($index->fields())),
$this->quoteIdentifier(array_values($index->fields())),
['onUpdate' => 'CASCADE', 'onDelete' => 'RESTRICT'],
$this->quoteIdentifier($index->name())
);
break;
case 'index':
default:
$table->addIndex(
$this->quoteIdentifier($index->fields()),
$this->quoteIdentifier($index->name())
);
}
}
}
|
php
|
protected function createTable(SchemaAsset $schema, ModelInterface $model)
{
$table = $schema->createTable($this->quoteIdentifier($model->table()));
foreach ($model->fields() as $field) {
$table->addColumn(
$this->quoteIdentifier($field->mappedName()),
$field->type(),
$field->attributes()
);
}
foreach ($model->indexes() as $index) {
switch ($index->type()) {
case 'primary':
$table->setPrimaryKey(
$this->quoteIdentifier($index->fields()),
$this->quoteIdentifier($index->name())
);
break;
case 'unique':
$table->addUniqueIndex(
$this->quoteIdentifier($index->fields()),
$this->quoteIdentifier($index->name())
);
break;
case 'foreign':
$table->addForeignKeyConstraint(
$index->table(),
$this->quoteIdentifier(array_keys($index->fields())),
$this->quoteIdentifier(array_values($index->fields())),
['onUpdate' => 'CASCADE', 'onDelete' => 'RESTRICT'],
$this->quoteIdentifier($index->name())
);
break;
case 'index':
default:
$table->addIndex(
$this->quoteIdentifier($index->fields()),
$this->quoteIdentifier($index->name())
);
}
}
}
|
[
"protected",
"function",
"createTable",
"(",
"SchemaAsset",
"$",
"schema",
",",
"ModelInterface",
"$",
"model",
")",
"{",
"$",
"table",
"=",
"$",
"schema",
"->",
"createTable",
"(",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"model",
"->",
"table",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"model",
"->",
"fields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"table",
"->",
"addColumn",
"(",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"field",
"->",
"mappedName",
"(",
")",
")",
",",
"$",
"field",
"->",
"type",
"(",
")",
",",
"$",
"field",
"->",
"attributes",
"(",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"model",
"->",
"indexes",
"(",
")",
"as",
"$",
"index",
")",
"{",
"switch",
"(",
"$",
"index",
"->",
"type",
"(",
")",
")",
"{",
"case",
"'primary'",
":",
"$",
"table",
"->",
"setPrimaryKey",
"(",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"fields",
"(",
")",
")",
",",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"name",
"(",
")",
")",
")",
";",
"break",
";",
"case",
"'unique'",
":",
"$",
"table",
"->",
"addUniqueIndex",
"(",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"fields",
"(",
")",
")",
",",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"name",
"(",
")",
")",
")",
";",
"break",
";",
"case",
"'foreign'",
":",
"$",
"table",
"->",
"addForeignKeyConstraint",
"(",
"$",
"index",
"->",
"table",
"(",
")",
",",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"array_keys",
"(",
"$",
"index",
"->",
"fields",
"(",
")",
")",
")",
",",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"array_values",
"(",
"$",
"index",
"->",
"fields",
"(",
")",
")",
")",
",",
"[",
"'onUpdate'",
"=>",
"'CASCADE'",
",",
"'onDelete'",
"=>",
"'RESTRICT'",
"]",
",",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"name",
"(",
")",
")",
")",
";",
"break",
";",
"case",
"'index'",
":",
"default",
":",
"$",
"table",
"->",
"addIndex",
"(",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"fields",
"(",
")",
")",
",",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"index",
"->",
"name",
"(",
")",
")",
")",
";",
"}",
"}",
"}"
] |
Creates table from model into schema
@param SchemaAsset $schema
@param ModelInterface $model
|
[
"Creates",
"table",
"from",
"model",
"into",
"schema"
] |
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
|
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L197-L240
|
25,411
|
mossphp/moss-storage
|
Moss/Storage/Schema/Schema.php
|
Schema.quoteIdentifier
|
protected function quoteIdentifier($identifier)
{
if (!is_array($identifier)) {
return $this->connection->quoteIdentifier($identifier);
}
foreach ($identifier as &$value) {
$value = $this->connection->quoteIdentifier($value);
unset($value);
}
return $identifier;
}
|
php
|
protected function quoteIdentifier($identifier)
{
if (!is_array($identifier)) {
return $this->connection->quoteIdentifier($identifier);
}
foreach ($identifier as &$value) {
$value = $this->connection->quoteIdentifier($value);
unset($value);
}
return $identifier;
}
|
[
"protected",
"function",
"quoteIdentifier",
"(",
"$",
"identifier",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"identifier",
")",
";",
"}",
"foreach",
"(",
"$",
"identifier",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"value",
")",
";",
"unset",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"identifier",
";",
"}"
] |
Quotes SQL identifier or array of identifiers
@param string|array $identifier
@return string|array
|
[
"Quotes",
"SQL",
"identifier",
"or",
"array",
"of",
"identifiers"
] |
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
|
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L249-L261
|
25,412
|
mossphp/moss-storage
|
Moss/Storage/Schema/Schema.php
|
Schema.buildDrop
|
protected function buildDrop(array $models)
{
$fromSchema = $this->connection->getSchemaManager()->createSchema();
$toSchema = clone $fromSchema;
foreach ($models as $model) {
if (!$toSchema->hasTable($model->table())) {
continue;
}
$toSchema->dropTable($model->table());
}
$sql = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
$this->queries = array_merge($this->queries, $sql);
}
|
php
|
protected function buildDrop(array $models)
{
$fromSchema = $this->connection->getSchemaManager()->createSchema();
$toSchema = clone $fromSchema;
foreach ($models as $model) {
if (!$toSchema->hasTable($model->table())) {
continue;
}
$toSchema->dropTable($model->table());
}
$sql = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
$this->queries = array_merge($this->queries, $sql);
}
|
[
"protected",
"function",
"buildDrop",
"(",
"array",
"$",
"models",
")",
"{",
"$",
"fromSchema",
"=",
"$",
"this",
"->",
"connection",
"->",
"getSchemaManager",
"(",
")",
"->",
"createSchema",
"(",
")",
";",
"$",
"toSchema",
"=",
"clone",
"$",
"fromSchema",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"toSchema",
"->",
"hasTable",
"(",
"$",
"model",
"->",
"table",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"toSchema",
"->",
"dropTable",
"(",
"$",
"model",
"->",
"table",
"(",
")",
")",
";",
"}",
"$",
"sql",
"=",
"$",
"fromSchema",
"->",
"getMigrateToSql",
"(",
"$",
"toSchema",
",",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
")",
";",
"$",
"this",
"->",
"queries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"queries",
",",
"$",
"sql",
")",
";",
"}"
] |
Builds drop table query
@param ModelInterface[] $models
|
[
"Builds",
"drop",
"table",
"query"
] |
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
|
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Schema/Schema.php#L268-L284
|
25,413
|
JurJean/SpraySerializer
|
src/Object/BoundClosureSerializer.php
|
BoundClosureSerializer.construct
|
public function construct($subject, &$data = array())
{
if (null === $this->constructed) {
$this->constructed = unserialize(
sprintf(
'O:%d:"%s":0:{}',
strlen($subject),
$subject
)
);
}
return clone $this->constructed;
}
|
php
|
public function construct($subject, &$data = array())
{
if (null === $this->constructed) {
$this->constructed = unserialize(
sprintf(
'O:%d:"%s":0:{}',
strlen($subject),
$subject
)
);
}
return clone $this->constructed;
}
|
[
"public",
"function",
"construct",
"(",
"$",
"subject",
",",
"&",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"constructed",
")",
"{",
"$",
"this",
"->",
"constructed",
"=",
"unserialize",
"(",
"sprintf",
"(",
"'O:%d:\"%s\":0:{}'",
",",
"strlen",
"(",
"$",
"subject",
")",
",",
"$",
"subject",
")",
")",
";",
"}",
"return",
"clone",
"$",
"this",
"->",
"constructed",
";",
"}"
] |
Construct a new object.
By default a new empty object is deserialized and from then on cloned.
@param string $subject The class name of the object to create
@param array $data The data to deserialize
@return object
|
[
"Construct",
"a",
"new",
"object",
"."
] |
4d2883efe489cc8716aea3334f622a576f650397
|
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L65-L77
|
25,414
|
JurJean/SpraySerializer
|
src/Object/BoundClosureSerializer.php
|
BoundClosureSerializer.serializer
|
protected function serializer()
{
if (null === $this->serializer) {
$self = $this;
$this->serializer = Closure::bind($this->bindSerializer(), null, $this->class);
}
return $this->serializer;
}
|
php
|
protected function serializer()
{
if (null === $this->serializer) {
$self = $this;
$this->serializer = Closure::bind($this->bindSerializer(), null, $this->class);
}
return $this->serializer;
}
|
[
"protected",
"function",
"serializer",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"serializer",
")",
"{",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"serializer",
"=",
"Closure",
"::",
"bind",
"(",
"$",
"this",
"->",
"bindSerializer",
"(",
")",
",",
"null",
",",
"$",
"this",
"->",
"class",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serializer",
";",
"}"
] |
Get a reference to the bound serialization closure.
@return Closure
|
[
"Get",
"a",
"reference",
"to",
"the",
"bound",
"serialization",
"closure",
"."
] |
4d2883efe489cc8716aea3334f622a576f650397
|
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L84-L91
|
25,415
|
JurJean/SpraySerializer
|
src/Object/BoundClosureSerializer.php
|
BoundClosureSerializer.deserializer
|
protected function deserializer()
{
if (null === $this->deserializer) {
$self = $this;
$this->deserializer = Closure::bind($this->bindDeserializer(), null, $this->class);
}
return $this->deserializer;
}
|
php
|
protected function deserializer()
{
if (null === $this->deserializer) {
$self = $this;
$this->deserializer = Closure::bind($this->bindDeserializer(), null, $this->class);
}
return $this->deserializer;
}
|
[
"protected",
"function",
"deserializer",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"deserializer",
")",
"{",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"deserializer",
"=",
"Closure",
"::",
"bind",
"(",
"$",
"this",
"->",
"bindDeserializer",
"(",
")",
",",
"null",
",",
"$",
"this",
"->",
"class",
")",
";",
"}",
"return",
"$",
"this",
"->",
"deserializer",
";",
"}"
] |
Get a reference to the bound deserialization closure.
@return Closure
|
[
"Get",
"a",
"reference",
"to",
"the",
"bound",
"deserialization",
"closure",
"."
] |
4d2883efe489cc8716aea3334f622a576f650397
|
https://github.com/JurJean/SpraySerializer/blob/4d2883efe489cc8716aea3334f622a576f650397/src/Object/BoundClosureSerializer.php#L129-L136
|
25,416
|
RocketPropelledTortoise/Core
|
src/Entities/FieldCollection.php
|
FieldCollection.initField
|
public static function initField($configuration = [])
{
if (!array_key_exists('type', $configuration) || !class_exists($configuration['type'])) {
throw new InvalidFieldTypeException('You did not specify a type on this class.');
}
$collection = new static();
$collection->configuration = $configuration;
$collection->type = $configuration['type'];
if (array_key_exists('max_items', $configuration)) {
$collection->maxItems = $configuration['max_items'];
}
return $collection;
}
|
php
|
public static function initField($configuration = [])
{
if (!array_key_exists('type', $configuration) || !class_exists($configuration['type'])) {
throw new InvalidFieldTypeException('You did not specify a type on this class.');
}
$collection = new static();
$collection->configuration = $configuration;
$collection->type = $configuration['type'];
if (array_key_exists('max_items', $configuration)) {
$collection->maxItems = $configuration['max_items'];
}
return $collection;
}
|
[
"public",
"static",
"function",
"initField",
"(",
"$",
"configuration",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'type'",
",",
"$",
"configuration",
")",
"||",
"!",
"class_exists",
"(",
"$",
"configuration",
"[",
"'type'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidFieldTypeException",
"(",
"'You did not specify a type on this class.'",
")",
";",
"}",
"$",
"collection",
"=",
"new",
"static",
"(",
")",
";",
"$",
"collection",
"->",
"configuration",
"=",
"$",
"configuration",
";",
"$",
"collection",
"->",
"type",
"=",
"$",
"configuration",
"[",
"'type'",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'max_items'",
",",
"$",
"configuration",
")",
")",
"{",
"$",
"collection",
"->",
"maxItems",
"=",
"$",
"configuration",
"[",
"'max_items'",
"]",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] |
Initialize a collection with the configuration
@param array $configuration
@throws InvalidFieldTypeException
@return static
|
[
"Initialize",
"a",
"collection",
"with",
"the",
"configuration"
] |
78b65663fc463e21e494257140ddbed0a9ccb3c3
|
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L46-L61
|
25,417
|
RocketPropelledTortoise/Core
|
src/Entities/FieldCollection.php
|
FieldCollection.validateSet
|
protected function validateSet($key, $value)
{
$maxItems = $this->getMaxItems();
if ((is_null($key) || !array_key_exists($key, $this->items)) && $maxItems != 0 && $this->count() >= $maxItems) {
throw new ItemCountException('The maximum number of items has been reached on this field.');
}
if (is_null($key) && is_null($value)) {
throw new NullValueException('You cannot add a null value');
}
}
|
php
|
protected function validateSet($key, $value)
{
$maxItems = $this->getMaxItems();
if ((is_null($key) || !array_key_exists($key, $this->items)) && $maxItems != 0 && $this->count() >= $maxItems) {
throw new ItemCountException('The maximum number of items has been reached on this field.');
}
if (is_null($key) && is_null($value)) {
throw new NullValueException('You cannot add a null value');
}
}
|
[
"protected",
"function",
"validateSet",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"maxItems",
"=",
"$",
"this",
"->",
"getMaxItems",
"(",
")",
";",
"if",
"(",
"(",
"is_null",
"(",
"$",
"key",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"items",
")",
")",
"&&",
"$",
"maxItems",
"!=",
"0",
"&&",
"$",
"this",
"->",
"count",
"(",
")",
">=",
"$",
"maxItems",
")",
"{",
"throw",
"new",
"ItemCountException",
"(",
"'The maximum number of items has been reached on this field.'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
"&&",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"NullValueException",
"(",
"'You cannot add a null value'",
")",
";",
"}",
"}"
] |
Validate input of OffsetSet
@param $key
@param $value
@throws ItemCountException
@throws NullValueException
|
[
"Validate",
"input",
"of",
"OffsetSet"
] |
78b65663fc463e21e494257140ddbed0a9ccb3c3
|
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L71-L81
|
25,418
|
RocketPropelledTortoise/Core
|
src/Entities/FieldCollection.php
|
FieldCollection.getFieldInstance
|
protected function getFieldInstance($value)
{
if ($value instanceof Field) {
return $value;
}
$container = new $this->type();
$container->value = $value;
return $container;
}
|
php
|
protected function getFieldInstance($value)
{
if ($value instanceof Field) {
return $value;
}
$container = new $this->type();
$container->value = $value;
return $container;
}
|
[
"protected",
"function",
"getFieldInstance",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Field",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"container",
"=",
"new",
"$",
"this",
"->",
"type",
"(",
")",
";",
"$",
"container",
"->",
"value",
"=",
"$",
"value",
";",
"return",
"$",
"container",
";",
"}"
] |
Get a field from a value
@param Field|mixed $value
@return Field
|
[
"Get",
"a",
"field",
"from",
"a",
"value"
] |
78b65663fc463e21e494257140ddbed0a9ccb3c3
|
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L89-L99
|
25,419
|
RocketPropelledTortoise/Core
|
src/Entities/FieldCollection.php
|
FieldCollection.clear
|
public function clear()
{
foreach ($this->items as $item) {
$this->deleted[] = $item;
}
$this->items = [];
}
|
php
|
public function clear()
{
foreach ($this->items as $item) {
$this->deleted[] = $item;
}
$this->items = [];
}
|
[
"public",
"function",
"clear",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"deleted",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"$",
"this",
"->",
"items",
"=",
"[",
"]",
";",
"}"
] |
Remove all items in this collection
@return void
|
[
"Remove",
"all",
"items",
"in",
"this",
"collection"
] |
78b65663fc463e21e494257140ddbed0a9ccb3c3
|
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L179-L186
|
25,420
|
RocketPropelledTortoise/Core
|
src/Entities/FieldCollection.php
|
FieldCollection.toArray
|
public function toArray()
{
if ($this->getMaxItems() != 1) {
return parent::toArray();
}
if (!array_key_exists(0, $this->items)) {
return null;
}
return $this->get(0)->toArray();
}
|
php
|
public function toArray()
{
if ($this->getMaxItems() != 1) {
return parent::toArray();
}
if (!array_key_exists(0, $this->items)) {
return null;
}
return $this->get(0)->toArray();
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMaxItems",
"(",
")",
"!=",
"1",
")",
"{",
"return",
"parent",
"::",
"toArray",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"0",
",",
"$",
"this",
"->",
"items",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"0",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] |
As we use a field collection even if we have only one value, we use it that way.
@return array|mixed|null
|
[
"As",
"we",
"use",
"a",
"field",
"collection",
"even",
"if",
"we",
"have",
"only",
"one",
"value",
"we",
"use",
"it",
"that",
"way",
"."
] |
78b65663fc463e21e494257140ddbed0a9ccb3c3
|
https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/FieldCollection.php#L203-L214
|
25,421
|
struggle-for-php/SfpStreamView
|
src/SfpStreamView/View.php
|
View.getScriptPath
|
function getScriptPath()
{
$fileName = $this->stack->pop();
if ($this->baseDir) {
return $this->baseDir . \DIRECTORY_SEPARATOR . $fileName;
} else {
return (string)$fileName;
}
}
|
php
|
function getScriptPath()
{
$fileName = $this->stack->pop();
if ($this->baseDir) {
return $this->baseDir . \DIRECTORY_SEPARATOR . $fileName;
} else {
return (string)$fileName;
}
}
|
[
"function",
"getScriptPath",
"(",
")",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"stack",
"->",
"pop",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"baseDir",
")",
"{",
"return",
"$",
"this",
"->",
"baseDir",
".",
"\\",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileName",
";",
"}",
"else",
"{",
"return",
"(",
"string",
")",
"$",
"fileName",
";",
"}",
"}"
] |
Get script file path
@return string
|
[
"Get",
"script",
"file",
"path"
] |
1ee960e122e4e7754a90cf81452567668ea1b32d
|
https://github.com/struggle-for-php/SfpStreamView/blob/1ee960e122e4e7754a90cf81452567668ea1b32d/src/SfpStreamView/View.php#L66-L74
|
25,422
|
struggle-for-php/SfpStreamView
|
src/SfpStreamView/View.php
|
View.assign
|
function assign($array)
{
if (!is_array($array) && !($array instanceof \Traversable)) {
throw new \InvalidArgumentException('$array must be array or Traversable.');
}
foreach ($array as $key => $value) {
$this->storage[$key] = $value;
}
}
|
php
|
function assign($array)
{
if (!is_array($array) && !($array instanceof \Traversable)) {
throw new \InvalidArgumentException('$array must be array or Traversable.');
}
foreach ($array as $key => $value) {
$this->storage[$key] = $value;
}
}
|
[
"function",
"assign",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
"&&",
"!",
"(",
"$",
"array",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$array must be array or Traversable.'",
")",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"storage",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] |
assign view vars
@param array|\Traversable $array
|
[
"assign",
"view",
"vars"
] |
1ee960e122e4e7754a90cf81452567668ea1b32d
|
https://github.com/struggle-for-php/SfpStreamView/blob/1ee960e122e4e7754a90cf81452567668ea1b32d/src/SfpStreamView/View.php#L89-L98
|
25,423
|
eureka-framework/component-response
|
src/Response/Header/HttpCode.php
|
HttpCode.getText
|
public static function getText($code)
{
$code = (int) $code;
if (!self::exists($code)) {
throw new \DomainException('Http Code does not exist!');
}
return self::$httpCodes[$code];
}
|
php
|
public static function getText($code)
{
$code = (int) $code;
if (!self::exists($code)) {
throw new \DomainException('Http Code does not exist!');
}
return self::$httpCodes[$code];
}
|
[
"public",
"static",
"function",
"getText",
"(",
"$",
"code",
")",
"{",
"$",
"code",
"=",
"(",
"int",
")",
"$",
"code",
";",
"if",
"(",
"!",
"self",
"::",
"exists",
"(",
"$",
"code",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Http Code does not exist!'",
")",
";",
"}",
"return",
"self",
"::",
"$",
"httpCodes",
"[",
"$",
"code",
"]",
";",
"}"
] |
Return text for the specified http code.
@param int $code
@return string
@throws \DomainException
|
[
"Return",
"text",
"for",
"the",
"specified",
"http",
"code",
"."
] |
f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a
|
https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Header/HttpCode.php#L98-L107
|
25,424
|
UWEnrollmentManagement/Connection
|
src/Connection.php
|
Connection.execGET
|
public function execGET($url, array $params = [])
{
$url = $this->baseUrl . $url;
// Build the query from the parameters
if ($params !== []) {
$url .= '?' . http_build_query($params);
}
// Set request options
$this->addOptions([
CURLOPT_URL => $url,
CURLOPT_HTTPGET => true,
]);
return $this->exec();
}
|
php
|
public function execGET($url, array $params = [])
{
$url = $this->baseUrl . $url;
// Build the query from the parameters
if ($params !== []) {
$url .= '?' . http_build_query($params);
}
// Set request options
$this->addOptions([
CURLOPT_URL => $url,
CURLOPT_HTTPGET => true,
]);
return $this->exec();
}
|
[
"public",
"function",
"execGET",
"(",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"baseUrl",
".",
"$",
"url",
";",
"// Build the query from the parameters",
"if",
"(",
"$",
"params",
"!==",
"[",
"]",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
")",
";",
"}",
"// Set request options",
"$",
"this",
"->",
"addOptions",
"(",
"[",
"CURLOPT_URL",
"=>",
"$",
"url",
",",
"CURLOPT_HTTPGET",
"=>",
"true",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"exec",
"(",
")",
";",
"}"
] |
Execute a GET request to a given URL, with optional parameters.
@param string $url
@param string[] $params Array of query parameter $key=>$value pairs.
@return ConnectionReturn The server's response
|
[
"Execute",
"a",
"GET",
"request",
"to",
"a",
"given",
"URL",
"with",
"optional",
"parameters",
"."
] |
56cadfd9003a3e2d875494a26d9cce69b9b0aa57
|
https://github.com/UWEnrollmentManagement/Connection/blob/56cadfd9003a3e2d875494a26d9cce69b9b0aa57/src/Connection.php#L103-L119
|
25,425
|
UWEnrollmentManagement/Connection
|
src/Connection.php
|
Connection.execPOST
|
public function execPOST($url, array $params = [])
{
$url = $this->baseUrl . $url;
$this->addOptions([
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
]);
return $this->exec();
}
|
php
|
public function execPOST($url, array $params = [])
{
$url = $this->baseUrl . $url;
$this->addOptions([
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
]);
return $this->exec();
}
|
[
"public",
"function",
"execPOST",
"(",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"baseUrl",
".",
"$",
"url",
";",
"$",
"this",
"->",
"addOptions",
"(",
"[",
"CURLOPT_URL",
"=>",
"$",
"url",
",",
"CURLOPT_POST",
"=>",
"true",
",",
"CURLOPT_POSTFIELDS",
"=>",
"$",
"params",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"exec",
"(",
")",
";",
"}"
] |
Execute a POST request to a given URL, with optional parameters.
@param string $url
@param string[] $params Array of POST parameter $key=>$value pairs.
@return ConnectionReturn The server's response.
|
[
"Execute",
"a",
"POST",
"request",
"to",
"a",
"given",
"URL",
"with",
"optional",
"parameters",
"."
] |
56cadfd9003a3e2d875494a26d9cce69b9b0aa57
|
https://github.com/UWEnrollmentManagement/Connection/blob/56cadfd9003a3e2d875494a26d9cce69b9b0aa57/src/Connection.php#L128-L139
|
25,426
|
spiral/console
|
src/Config/ConsoleConfig.php
|
ConsoleConfig.configureSequence
|
public function configureSequence(): \Generator
{
$sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? [];
foreach ($sequence as $item) {
yield $this->parseSequence($item);
}
}
|
php
|
public function configureSequence(): \Generator
{
$sequence = $this->config['configure'] ?? $this->config['configureSequence'] ?? [];
foreach ($sequence as $item) {
yield $this->parseSequence($item);
}
}
|
[
"public",
"function",
"configureSequence",
"(",
")",
":",
"\\",
"Generator",
"{",
"$",
"sequence",
"=",
"$",
"this",
"->",
"config",
"[",
"'configure'",
"]",
"??",
"$",
"this",
"->",
"config",
"[",
"'configureSequence'",
"]",
"??",
"[",
"]",
";",
"foreach",
"(",
"$",
"sequence",
"as",
"$",
"item",
")",
"{",
"yield",
"$",
"this",
"->",
"parseSequence",
"(",
"$",
"item",
")",
";",
"}",
"}"
] |
Get list of configure sequences.
@return \Generator|SequenceInterface[]
@throws ConfigException
|
[
"Get",
"list",
"of",
"configure",
"sequences",
"."
] |
c3d99450ddd32bcc6f87e2b2ed40821054a93da3
|
https://github.com/spiral/console/blob/c3d99450ddd32bcc6f87e2b2ed40821054a93da3/src/Config/ConsoleConfig.php#L69-L75
|
25,427
|
spiral/console
|
src/Config/ConsoleConfig.php
|
ConsoleConfig.updateSequence
|
public function updateSequence(): \Generator
{
$sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? [];
foreach ($sequence as $item) {
yield $this->parseSequence($item);
}
}
|
php
|
public function updateSequence(): \Generator
{
$sequence = $this->config['update'] ?? $this->config['updateSequence'] ?? [];
foreach ($sequence as $item) {
yield $this->parseSequence($item);
}
}
|
[
"public",
"function",
"updateSequence",
"(",
")",
":",
"\\",
"Generator",
"{",
"$",
"sequence",
"=",
"$",
"this",
"->",
"config",
"[",
"'update'",
"]",
"??",
"$",
"this",
"->",
"config",
"[",
"'updateSequence'",
"]",
"??",
"[",
"]",
";",
"foreach",
"(",
"$",
"sequence",
"as",
"$",
"item",
")",
"{",
"yield",
"$",
"this",
"->",
"parseSequence",
"(",
"$",
"item",
")",
";",
"}",
"}"
] |
Get list of all update sequences.
@return \Generator|SequenceInterface[]
@throws ConfigException
|
[
"Get",
"list",
"of",
"all",
"update",
"sequences",
"."
] |
c3d99450ddd32bcc6f87e2b2ed40821054a93da3
|
https://github.com/spiral/console/blob/c3d99450ddd32bcc6f87e2b2ed40821054a93da3/src/Config/ConsoleConfig.php#L84-L90
|
25,428
|
ekyna/Table
|
Http/Handler/ExportHandler.php
|
ExportHandler.getAdapter
|
private function getAdapter(TableInterface $table, $format)
{
$adapters = $table->getConfig()->getExportAdapters();
foreach ($adapters as $adapter) {
if ($adapter->supports($format)) {
return $adapter;
}
}
return null;
}
|
php
|
private function getAdapter(TableInterface $table, $format)
{
$adapters = $table->getConfig()->getExportAdapters();
foreach ($adapters as $adapter) {
if ($adapter->supports($format)) {
return $adapter;
}
}
return null;
}
|
[
"private",
"function",
"getAdapter",
"(",
"TableInterface",
"$",
"table",
",",
"$",
"format",
")",
"{",
"$",
"adapters",
"=",
"$",
"table",
"->",
"getConfig",
"(",
")",
"->",
"getExportAdapters",
"(",
")",
";",
"foreach",
"(",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"if",
"(",
"$",
"adapter",
"->",
"supports",
"(",
"$",
"format",
")",
")",
"{",
"return",
"$",
"adapter",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the adapter supporting the given format.
@param TableInterface $table
@param string $format
@return \Ekyna\Component\Table\Export\AdapterInterface|null
|
[
"Returns",
"the",
"adapter",
"supporting",
"the",
"given",
"format",
"."
] |
6f06e8fd8a3248d52f3a91f10508471344db311a
|
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Http/Handler/ExportHandler.php#L64-L75
|
25,429
|
jenskooij/cloudcontrol
|
src/util/DocumentSorter.php
|
DocumentSorter.sortDocumentsByField
|
public static function sortDocumentsByField($documents, $field, $order = 'ASC')
{
self::$orderByField = $field;
self::$order = strtoupper($order) === 'ASC' ? 'ASC' : 'DESC';
usort($documents, '\CloudControl\Cms\util\DocumentSorter::fieldCompare');
if ($order === 'DESC') {
return array_reverse($documents);
}
return $documents;
}
|
php
|
public static function sortDocumentsByField($documents, $field, $order = 'ASC')
{
self::$orderByField = $field;
self::$order = strtoupper($order) === 'ASC' ? 'ASC' : 'DESC';
usort($documents, '\CloudControl\Cms\util\DocumentSorter::fieldCompare');
if ($order === 'DESC') {
return array_reverse($documents);
}
return $documents;
}
|
[
"public",
"static",
"function",
"sortDocumentsByField",
"(",
"$",
"documents",
",",
"$",
"field",
",",
"$",
"order",
"=",
"'ASC'",
")",
"{",
"self",
"::",
"$",
"orderByField",
"=",
"$",
"field",
";",
"self",
"::",
"$",
"order",
"=",
"strtoupper",
"(",
"$",
"order",
")",
"===",
"'ASC'",
"?",
"'ASC'",
":",
"'DESC'",
";",
"usort",
"(",
"$",
"documents",
",",
"'\\CloudControl\\Cms\\util\\DocumentSorter::fieldCompare'",
")",
";",
"if",
"(",
"$",
"order",
"===",
"'DESC'",
")",
"{",
"return",
"array_reverse",
"(",
"$",
"documents",
")",
";",
"}",
"return",
"$",
"documents",
";",
"}"
] |
Sorts an array of Document instances
@param array $documents
@param string $field
@param string $order
@return array
|
[
"Sorts",
"an",
"array",
"of",
"Document",
"instances"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/DocumentSorter.php#L23-L32
|
25,430
|
jenskooij/cloudcontrol
|
src/util/DocumentSorter.php
|
DocumentSorter.fieldCompare
|
protected static function fieldCompare(Document $a, Document $b) {
$field = self::$orderByField;
if (property_exists('\CloudControl\Cms\storage\entities\Document', $field)) {
return strcasecmp($a->{$field}, $b->{$field});
}
if (!isset($a->fields->{$field}[0])) {
return -3;
}
if (!isset($b->fields->{$field}[0])) {
return 3;
}
return strcasecmp($a->fields->{$field}[0], $b->fields->{$field}[0]);
}
|
php
|
protected static function fieldCompare(Document $a, Document $b) {
$field = self::$orderByField;
if (property_exists('\CloudControl\Cms\storage\entities\Document', $field)) {
return strcasecmp($a->{$field}, $b->{$field});
}
if (!isset($a->fields->{$field}[0])) {
return -3;
}
if (!isset($b->fields->{$field}[0])) {
return 3;
}
return strcasecmp($a->fields->{$field}[0], $b->fields->{$field}[0]);
}
|
[
"protected",
"static",
"function",
"fieldCompare",
"(",
"Document",
"$",
"a",
",",
"Document",
"$",
"b",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"$",
"orderByField",
";",
"if",
"(",
"property_exists",
"(",
"'\\CloudControl\\Cms\\storage\\entities\\Document'",
",",
"$",
"field",
")",
")",
"{",
"return",
"strcasecmp",
"(",
"$",
"a",
"->",
"{",
"$",
"field",
"}",
",",
"$",
"b",
"->",
"{",
"$",
"field",
"}",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"a",
"->",
"fields",
"->",
"{",
"$",
"field",
"}",
"[",
"0",
"]",
")",
")",
"{",
"return",
"-",
"3",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"b",
"->",
"fields",
"->",
"{",
"$",
"field",
"}",
"[",
"0",
"]",
")",
")",
"{",
"return",
"3",
";",
"}",
"return",
"strcasecmp",
"(",
"$",
"a",
"->",
"fields",
"->",
"{",
"$",
"field",
"}",
"[",
"0",
"]",
",",
"$",
"b",
"->",
"fields",
"->",
"{",
"$",
"field",
"}",
"[",
"0",
"]",
")",
";",
"}"
] |
Compares two documents
@param Document $a
@param Document $b
@return int
|
[
"Compares",
"two",
"documents"
] |
76e5d9ac8f9c50d06d39a995d13cc03742536548
|
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/util/DocumentSorter.php#L40-L55
|
25,431
|
RhubarbPHP/Module.ImageProcessing
|
src/Image.php
|
Image.checkCacheValid
|
private function checkCacheValid( $cacheFile )
{
if ( file_exists( $cacheFile ) && ( filemtime( $cacheFile ) > filemtime( $this->filePath ) ) )
{
return true;
}
return false;
}
|
php
|
private function checkCacheValid( $cacheFile )
{
if ( file_exists( $cacheFile ) && ( filemtime( $cacheFile ) > filemtime( $this->filePath ) ) )
{
return true;
}
return false;
}
|
[
"private",
"function",
"checkCacheValid",
"(",
"$",
"cacheFile",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"cacheFile",
")",
"&&",
"(",
"filemtime",
"(",
"$",
"cacheFile",
")",
">",
"filemtime",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the cache file exists and is current.
@param mixed $cacheFile
@return bool
|
[
"Returns",
"true",
"if",
"the",
"cache",
"file",
"exists",
"and",
"is",
"current",
"."
] |
e980ae6b524ce60f550064257eb7318dce331c1a
|
https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/Image.php#L163-L171
|
25,432
|
RhubarbPHP/Module.ImageProcessing
|
src/Image.php
|
Image.ApplyMetricsToCanvas
|
public function ApplyMetricsToCanvas()
{
$destinationCanvas = @imageCreateTrueColor( $this->_metrics->frameWidth, $this->_metrics->frameHeight );
$backColor = imagecolorallocate( $destinationCanvas, 255, 255, 255 );
if( $this->_metrics->sourceFormat == 3 )
{
$backColor = imagecolorallocatealpha( $destinationCanvas, 255, 255, 255, 127 );
imagealphablending( $destinationCanvas, true );
imagesavealpha( $destinationCanvas, true );
}
imagefill( $destinationCanvas, 1, 1, $backColor );
@imageCopyResampled(
$destinationCanvas,
$this->GetCanvas(),
$this->_metrics->offsetX, $this->_metrics->offsetY, 0, 0,
$this->_metrics->scaleWidth, $this->_metrics->scaleHeight,
$this->_metrics->sourceWidth, $this->_metrics->sourceHeight );
$this->SetCanvas( $destinationCanvas );
$this->_metrics->Commit();
}
|
php
|
public function ApplyMetricsToCanvas()
{
$destinationCanvas = @imageCreateTrueColor( $this->_metrics->frameWidth, $this->_metrics->frameHeight );
$backColor = imagecolorallocate( $destinationCanvas, 255, 255, 255 );
if( $this->_metrics->sourceFormat == 3 )
{
$backColor = imagecolorallocatealpha( $destinationCanvas, 255, 255, 255, 127 );
imagealphablending( $destinationCanvas, true );
imagesavealpha( $destinationCanvas, true );
}
imagefill( $destinationCanvas, 1, 1, $backColor );
@imageCopyResampled(
$destinationCanvas,
$this->GetCanvas(),
$this->_metrics->offsetX, $this->_metrics->offsetY, 0, 0,
$this->_metrics->scaleWidth, $this->_metrics->scaleHeight,
$this->_metrics->sourceWidth, $this->_metrics->sourceHeight );
$this->SetCanvas( $destinationCanvas );
$this->_metrics->Commit();
}
|
[
"public",
"function",
"ApplyMetricsToCanvas",
"(",
")",
"{",
"$",
"destinationCanvas",
"=",
"@",
"imageCreateTrueColor",
"(",
"$",
"this",
"->",
"_metrics",
"->",
"frameWidth",
",",
"$",
"this",
"->",
"_metrics",
"->",
"frameHeight",
")",
";",
"$",
"backColor",
"=",
"imagecolorallocate",
"(",
"$",
"destinationCanvas",
",",
"255",
",",
"255",
",",
"255",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_metrics",
"->",
"sourceFormat",
"==",
"3",
")",
"{",
"$",
"backColor",
"=",
"imagecolorallocatealpha",
"(",
"$",
"destinationCanvas",
",",
"255",
",",
"255",
",",
"255",
",",
"127",
")",
";",
"imagealphablending",
"(",
"$",
"destinationCanvas",
",",
"true",
")",
";",
"imagesavealpha",
"(",
"$",
"destinationCanvas",
",",
"true",
")",
";",
"}",
"imagefill",
"(",
"$",
"destinationCanvas",
",",
"1",
",",
"1",
",",
"$",
"backColor",
")",
";",
"@",
"imageCopyResampled",
"(",
"$",
"destinationCanvas",
",",
"$",
"this",
"->",
"GetCanvas",
"(",
")",
",",
"$",
"this",
"->",
"_metrics",
"->",
"offsetX",
",",
"$",
"this",
"->",
"_metrics",
"->",
"offsetY",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"_metrics",
"->",
"scaleWidth",
",",
"$",
"this",
"->",
"_metrics",
"->",
"scaleHeight",
",",
"$",
"this",
"->",
"_metrics",
"->",
"sourceWidth",
",",
"$",
"this",
"->",
"_metrics",
"->",
"sourceHeight",
")",
";",
"$",
"this",
"->",
"SetCanvas",
"(",
"$",
"destinationCanvas",
")",
";",
"$",
"this",
"->",
"_metrics",
"->",
"Commit",
"(",
")",
";",
"}"
] |
Makes sure that the current image metrics are applied to the canvas, essentially committing the
changes.
|
[
"Makes",
"sure",
"that",
"the",
"current",
"image",
"metrics",
"are",
"applied",
"to",
"the",
"canvas",
"essentially",
"committing",
"the",
"changes",
"."
] |
e980ae6b524ce60f550064257eb7318dce331c1a
|
https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/Image.php#L188-L213
|
25,433
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.HasAnyPageRight
|
private function HasAnyPageRight(BackendPageRights $pageRights)
{
return $pageRights->GetRemove() ||
$pageRights->GetCreateIn() ||
$pageRights->GetEdit() ||
$pageRights->GetMove();
}
|
php
|
private function HasAnyPageRight(BackendPageRights $pageRights)
{
return $pageRights->GetRemove() ||
$pageRights->GetCreateIn() ||
$pageRights->GetEdit() ||
$pageRights->GetMove();
}
|
[
"private",
"function",
"HasAnyPageRight",
"(",
"BackendPageRights",
"$",
"pageRights",
")",
"{",
"return",
"$",
"pageRights",
"->",
"GetRemove",
"(",
")",
"||",
"$",
"pageRights",
"->",
"GetCreateIn",
"(",
")",
"||",
"$",
"pageRights",
"->",
"GetEdit",
"(",
")",
"||",
"$",
"pageRights",
"->",
"GetMove",
"(",
")",
";",
"}"
] |
True if any of the page rights is true
@param BackendPageRights $pageRights The page right
@return boolean Returns true if any access action is allowed
|
[
"True",
"if",
"any",
"of",
"the",
"page",
"rights",
"is",
"true"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L222-L228
|
25,434
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.HasAnyContentRight
|
private function HasAnyContentRight(BackendContentRights $contentRights)
{
return $contentRights->GetEdit() ||
$contentRights->GetRemove() ||
$contentRights->GetCreateIn() ||
$contentRights->GetMove();
}
|
php
|
private function HasAnyContentRight(BackendContentRights $contentRights)
{
return $contentRights->GetEdit() ||
$contentRights->GetRemove() ||
$contentRights->GetCreateIn() ||
$contentRights->GetMove();
}
|
[
"private",
"function",
"HasAnyContentRight",
"(",
"BackendContentRights",
"$",
"contentRights",
")",
"{",
"return",
"$",
"contentRights",
"->",
"GetEdit",
"(",
")",
"||",
"$",
"contentRights",
"->",
"GetRemove",
"(",
")",
"||",
"$",
"contentRights",
"->",
"GetCreateIn",
"(",
")",
"||",
"$",
"contentRights",
"->",
"GetMove",
"(",
")",
";",
"}"
] |
True if any of the content rights is true
@param BackendContentRights $contentRights
@return boolean Returns true if any access action is allowed
|
[
"True",
"if",
"any",
"of",
"the",
"content",
"rights",
"is",
"true"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L247-L253
|
25,435
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantGroupOnContent
|
private function GrantGroupOnContent(Usergroup $group, Usergroup $contentGroup, BackendContentRights $contentRights, BackendAction $action)
{
if (!$group->Equals($contentGroup))
{
return GrantResult::NoAccess();
}
$allowed = false;
switch ($action)
{
case BackendAction::Create():
$allowed = $contentRights->GetCreateIn();
break;
case BackendAction::Edit():
$allowed = $contentRights->GetEdit();
break;
case BackendAction::Move():
$allowed = $contentRights->GetMove();
break;
case BackendAction::Delete():
$allowed = $contentRights->GetRemove();
break;
case BackendAction::Read():
$allowed = $this->HasAnyContentRight($contentRights);
break;
}
return $allowed ? GrantResult::Allowed() : GrantResult::NoAccess();
}
|
php
|
private function GrantGroupOnContent(Usergroup $group, Usergroup $contentGroup, BackendContentRights $contentRights, BackendAction $action)
{
if (!$group->Equals($contentGroup))
{
return GrantResult::NoAccess();
}
$allowed = false;
switch ($action)
{
case BackendAction::Create():
$allowed = $contentRights->GetCreateIn();
break;
case BackendAction::Edit():
$allowed = $contentRights->GetEdit();
break;
case BackendAction::Move():
$allowed = $contentRights->GetMove();
break;
case BackendAction::Delete():
$allowed = $contentRights->GetRemove();
break;
case BackendAction::Read():
$allowed = $this->HasAnyContentRight($contentRights);
break;
}
return $allowed ? GrantResult::Allowed() : GrantResult::NoAccess();
}
|
[
"private",
"function",
"GrantGroupOnContent",
"(",
"Usergroup",
"$",
"group",
",",
"Usergroup",
"$",
"contentGroup",
",",
"BackendContentRights",
"$",
"contentRights",
",",
"BackendAction",
"$",
"action",
")",
"{",
"if",
"(",
"!",
"$",
"group",
"->",
"Equals",
"(",
"$",
"contentGroup",
")",
")",
"{",
"return",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}",
"$",
"allowed",
"=",
"false",
";",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"BackendAction",
"::",
"Create",
"(",
")",
":",
"$",
"allowed",
"=",
"$",
"contentRights",
"->",
"GetCreateIn",
"(",
")",
";",
"break",
";",
"case",
"BackendAction",
"::",
"Edit",
"(",
")",
":",
"$",
"allowed",
"=",
"$",
"contentRights",
"->",
"GetEdit",
"(",
")",
";",
"break",
";",
"case",
"BackendAction",
"::",
"Move",
"(",
")",
":",
"$",
"allowed",
"=",
"$",
"contentRights",
"->",
"GetMove",
"(",
")",
";",
"break",
";",
"case",
"BackendAction",
"::",
"Delete",
"(",
")",
":",
"$",
"allowed",
"=",
"$",
"contentRights",
"->",
"GetRemove",
"(",
")",
";",
"break",
";",
"case",
"BackendAction",
"::",
"Read",
"(",
")",
":",
"$",
"allowed",
"=",
"$",
"this",
"->",
"HasAnyContentRight",
"(",
"$",
"contentRights",
")",
";",
"break",
";",
"}",
"return",
"$",
"allowed",
"?",
"GrantResult",
"::",
"Allowed",
"(",
")",
":",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}"
] |
Calculates the grant result for a group on a content
@param Usergroup $group The evaluated group
@param Usergroup $contentGroup The group of the content
@param BackendContentRights $contentRights The rights of the content
@param BackendAction $action The action that shall be taken for the content
@return GrantResult Returns the calculated result
|
[
"Calculates",
"the",
"grant",
"result",
"for",
"a",
"group",
"on",
"a",
"content"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L400-L431
|
25,436
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantCreateLayout
|
private function GrantCreateLayout()
{
$groups = $this->GetGroups();
foreach ($groups as $group)
{
if ($group->GetCreateLayouts())
{
return GrantResult::Allowed();
}
}
return GrantResult::NoAccess();
}
|
php
|
private function GrantCreateLayout()
{
$groups = $this->GetGroups();
foreach ($groups as $group)
{
if ($group->GetCreateLayouts())
{
return GrantResult::Allowed();
}
}
return GrantResult::NoAccess();
}
|
[
"private",
"function",
"GrantCreateLayout",
"(",
")",
"{",
"$",
"groups",
"=",
"$",
"this",
"->",
"GetGroups",
"(",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"$",
"group",
"->",
"GetCreateLayouts",
"(",
")",
")",
"{",
"return",
"GrantResult",
"::",
"Allowed",
"(",
")",
";",
"}",
"}",
"return",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}"
] |
Grant access to create a new layout by common group settings
@return GrantResult
|
[
"Grant",
"access",
"to",
"create",
"a",
"new",
"layout",
"by",
"common",
"group",
"settings"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L437-L448
|
25,437
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantOnContent
|
private function GrantOnContent(Content $content, BackendAction $action)
{
if ($this->GetUser()->Equals($content->GetUser()))
{
return GrantResult::Allowed();
}
$contentRights = RightsFinder::FindContentRights($content);
$contentGroup = GroupFinder::FindContentGroup($content);
if (!$contentRights || !$contentGroup)
{
return GrantResult::NoAccess();
}
$groups = $this->GetGroups();
foreach ($groups as $group)
{
$result = $this->GrantGroupOnContent($group, $contentGroup, $contentRights, $action);
if ($result->Equals(GrantResult::Allowed()))
{
return $result;
}
}
return GrantResult::NoAccess();
}
|
php
|
private function GrantOnContent(Content $content, BackendAction $action)
{
if ($this->GetUser()->Equals($content->GetUser()))
{
return GrantResult::Allowed();
}
$contentRights = RightsFinder::FindContentRights($content);
$contentGroup = GroupFinder::FindContentGroup($content);
if (!$contentRights || !$contentGroup)
{
return GrantResult::NoAccess();
}
$groups = $this->GetGroups();
foreach ($groups as $group)
{
$result = $this->GrantGroupOnContent($group, $contentGroup, $contentRights, $action);
if ($result->Equals(GrantResult::Allowed()))
{
return $result;
}
}
return GrantResult::NoAccess();
}
|
[
"private",
"function",
"GrantOnContent",
"(",
"Content",
"$",
"content",
",",
"BackendAction",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"GetUser",
"(",
")",
"->",
"Equals",
"(",
"$",
"content",
"->",
"GetUser",
"(",
")",
")",
")",
"{",
"return",
"GrantResult",
"::",
"Allowed",
"(",
")",
";",
"}",
"$",
"contentRights",
"=",
"RightsFinder",
"::",
"FindContentRights",
"(",
"$",
"content",
")",
";",
"$",
"contentGroup",
"=",
"GroupFinder",
"::",
"FindContentGroup",
"(",
"$",
"content",
")",
";",
"if",
"(",
"!",
"$",
"contentRights",
"||",
"!",
"$",
"contentGroup",
")",
"{",
"return",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}",
"$",
"groups",
"=",
"$",
"this",
"->",
"GetGroups",
"(",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"GrantGroupOnContent",
"(",
"$",
"group",
",",
"$",
"contentGroup",
",",
"$",
"contentRights",
",",
"$",
"action",
")",
";",
"if",
"(",
"$",
"result",
"->",
"Equals",
"(",
"GrantResult",
"::",
"Allowed",
"(",
")",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}"
] |
Calculates the grant result for a content
@param Content $content The content
@param BackendAction $action The action that shall be taken on the content
@return GrantResult Returns the calculated grant result
|
[
"Calculates",
"the",
"grant",
"result",
"for",
"a",
"content"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L491-L513
|
25,438
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantAddPageToSite
|
function GrantAddPageToSite(Site $site)
{
//Dummy page for evaluation
$page = new Page();
$page->SetUserGroup($site->GetUserGroup());
$siteRights = $site->GetUserGroupRights();
if ($siteRights)
{
$page->SetUserGroupRights($siteRights->GetPageRights());
}
return $this->Grant(BackendAction::Create(), $page);
}
|
php
|
function GrantAddPageToSite(Site $site)
{
//Dummy page for evaluation
$page = new Page();
$page->SetUserGroup($site->GetUserGroup());
$siteRights = $site->GetUserGroupRights();
if ($siteRights)
{
$page->SetUserGroupRights($siteRights->GetPageRights());
}
return $this->Grant(BackendAction::Create(), $page);
}
|
[
"function",
"GrantAddPageToSite",
"(",
"Site",
"$",
"site",
")",
"{",
"//Dummy page for evaluation",
"$",
"page",
"=",
"new",
"Page",
"(",
")",
";",
"$",
"page",
"->",
"SetUserGroup",
"(",
"$",
"site",
"->",
"GetUserGroup",
"(",
")",
")",
";",
"$",
"siteRights",
"=",
"$",
"site",
"->",
"GetUserGroupRights",
"(",
")",
";",
"if",
"(",
"$",
"siteRights",
")",
"{",
"$",
"page",
"->",
"SetUserGroupRights",
"(",
"$",
"siteRights",
"->",
"GetPageRights",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"Grant",
"(",
"BackendAction",
"::",
"Create",
"(",
")",
",",
"$",
"page",
")",
";",
"}"
] |
Grant evaluation for adding a page on top of the site
@param Site $site The site
@return GrantResult The result
|
[
"Grant",
"evaluation",
"for",
"adding",
"a",
"page",
"on",
"top",
"of",
"the",
"site"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L610-L621
|
25,439
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantAddContentToPageArea
|
function GrantAddContentToPageArea(Page $page, Area $area)
{
$result = $this->Grant(BackendAction::Create(), $area);
if (!$result->ToBool())
{
return $result;
}
return $this->GrantAddContentToPage($page);
}
|
php
|
function GrantAddContentToPageArea(Page $page, Area $area)
{
$result = $this->Grant(BackendAction::Create(), $area);
if (!$result->ToBool())
{
return $result;
}
return $this->GrantAddContentToPage($page);
}
|
[
"function",
"GrantAddContentToPageArea",
"(",
"Page",
"$",
"page",
",",
"Area",
"$",
"area",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"Grant",
"(",
"BackendAction",
"::",
"Create",
"(",
")",
",",
"$",
"area",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"ToBool",
"(",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"GrantAddContentToPage",
"(",
"$",
"page",
")",
";",
"}"
] |
Grant evaluation vor a page are
@param Page $page
@param Area $area
@return GrantResult
|
[
"Grant",
"evaluation",
"vor",
"a",
"page",
"are"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L628-L637
|
25,440
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantAddContentToPage
|
function GrantAddContentToPage(Page $page)
{
//dummy content for evaluation
$content = new Content();
$content->SetUserGroup(GroupFinder::FindPageGroup($page));
$pageRights = RightsFinder::FindPageRights($page);
if ($pageRights)
{
$content->SetUserGroupRights($pageRights->GetContentRights());
}
return $this->Grant(BackendAction::Create(), $content);
}
|
php
|
function GrantAddContentToPage(Page $page)
{
//dummy content for evaluation
$content = new Content();
$content->SetUserGroup(GroupFinder::FindPageGroup($page));
$pageRights = RightsFinder::FindPageRights($page);
if ($pageRights)
{
$content->SetUserGroupRights($pageRights->GetContentRights());
}
return $this->Grant(BackendAction::Create(), $content);
}
|
[
"function",
"GrantAddContentToPage",
"(",
"Page",
"$",
"page",
")",
"{",
"//dummy content for evaluation",
"$",
"content",
"=",
"new",
"Content",
"(",
")",
";",
"$",
"content",
"->",
"SetUserGroup",
"(",
"GroupFinder",
"::",
"FindPageGroup",
"(",
"$",
"page",
")",
")",
";",
"$",
"pageRights",
"=",
"RightsFinder",
"::",
"FindPageRights",
"(",
"$",
"page",
")",
";",
"if",
"(",
"$",
"pageRights",
")",
"{",
"$",
"content",
"->",
"SetUserGroupRights",
"(",
"$",
"pageRights",
"->",
"GetContentRights",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"Grant",
"(",
"BackendAction",
"::",
"Create",
"(",
")",
",",
"$",
"content",
")",
";",
"}"
] |
Grant evaluation for adding content on top of a page area
@param Page $page The page
@return GrantResult GrantResult Returns the grant result telling if creation is allowed
|
[
"Grant",
"evaluation",
"for",
"adding",
"content",
"on",
"top",
"of",
"a",
"page",
"area"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L643-L654
|
25,441
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantAddContentToLayoutArea
|
function GrantAddContentToLayoutArea(Area $area)
{
$result = $this->Grant(BackendAction::Create(), $area);
if (!$result->ToBool())
{
return $result;
}
return $this->GrantAddContentToLayout($area->GetLayout());
}
|
php
|
function GrantAddContentToLayoutArea(Area $area)
{
$result = $this->Grant(BackendAction::Create(), $area);
if (!$result->ToBool())
{
return $result;
}
return $this->GrantAddContentToLayout($area->GetLayout());
}
|
[
"function",
"GrantAddContentToLayoutArea",
"(",
"Area",
"$",
"area",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"Grant",
"(",
"BackendAction",
"::",
"Create",
"(",
")",
",",
"$",
"area",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"ToBool",
"(",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"this",
"->",
"GrantAddContentToLayout",
"(",
"$",
"area",
"->",
"GetLayout",
"(",
")",
")",
";",
"}"
] |
Grant evaluation for adding content to layout area
@param Area $area
@return GrantResult
|
[
"Grant",
"evaluation",
"for",
"adding",
"content",
"to",
"layout",
"area"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L660-L668
|
25,442
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantAddContentToLayout
|
function GrantAddContentToLayout(Layout $layout)
{
//dummy content for evaluation
$content = new Content();
$content->SetUserGroup($layout->GetUserGroup());
$layoutRights = $layout->GetUserGroupRights();
if ($layoutRights)
{
$content->SetUserGroupRights($layoutRights->GetContentRights());
}
return $this->Grant(BackendAction::Create(), $content);
}
|
php
|
function GrantAddContentToLayout(Layout $layout)
{
//dummy content for evaluation
$content = new Content();
$content->SetUserGroup($layout->GetUserGroup());
$layoutRights = $layout->GetUserGroupRights();
if ($layoutRights)
{
$content->SetUserGroupRights($layoutRights->GetContentRights());
}
return $this->Grant(BackendAction::Create(), $content);
}
|
[
"function",
"GrantAddContentToLayout",
"(",
"Layout",
"$",
"layout",
")",
"{",
"//dummy content for evaluation",
"$",
"content",
"=",
"new",
"Content",
"(",
")",
";",
"$",
"content",
"->",
"SetUserGroup",
"(",
"$",
"layout",
"->",
"GetUserGroup",
"(",
")",
")",
";",
"$",
"layoutRights",
"=",
"$",
"layout",
"->",
"GetUserGroupRights",
"(",
")",
";",
"if",
"(",
"$",
"layoutRights",
")",
"{",
"$",
"content",
"->",
"SetUserGroupRights",
"(",
"$",
"layoutRights",
"->",
"GetContentRights",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"Grant",
"(",
"BackendAction",
"::",
"Create",
"(",
")",
",",
"$",
"content",
")",
";",
"}"
] |
Grant evaluation for adding content on top of a layout area
@param Layout $layout The layout
@return GrantResult Returns the grant result telling if creation is allowed
|
[
"Grant",
"evaluation",
"for",
"adding",
"content",
"on",
"top",
"of",
"a",
"layout",
"area"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L674-L685
|
25,443
|
agentmedia/phine-core
|
src/Core/Logic/Access/Backend/UserGuard.php
|
UserGuard.GrantAddContentToContainer
|
function GrantAddContentToContainer(Container $container)
{
//dummy content for evaluation
$content = new Content();
$content->SetUserGroup($container->GetUserGroup());
$containerRights = $container->GetUserGroupRights();
if ($containerRights)
{
$content->SetUserGroupRights($containerRights->GetContentRights());
}
return $this->Grant(BackendAction::Create(), $content);
}
|
php
|
function GrantAddContentToContainer(Container $container)
{
//dummy content for evaluation
$content = new Content();
$content->SetUserGroup($container->GetUserGroup());
$containerRights = $container->GetUserGroupRights();
if ($containerRights)
{
$content->SetUserGroupRights($containerRights->GetContentRights());
}
return $this->Grant(BackendAction::Create(), $content);
}
|
[
"function",
"GrantAddContentToContainer",
"(",
"Container",
"$",
"container",
")",
"{",
"//dummy content for evaluation",
"$",
"content",
"=",
"new",
"Content",
"(",
")",
";",
"$",
"content",
"->",
"SetUserGroup",
"(",
"$",
"container",
"->",
"GetUserGroup",
"(",
")",
")",
";",
"$",
"containerRights",
"=",
"$",
"container",
"->",
"GetUserGroupRights",
"(",
")",
";",
"if",
"(",
"$",
"containerRights",
")",
"{",
"$",
"content",
"->",
"SetUserGroupRights",
"(",
"$",
"containerRights",
"->",
"GetContentRights",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"Grant",
"(",
"BackendAction",
"::",
"Create",
"(",
")",
",",
"$",
"content",
")",
";",
"}"
] |
Grant evaluation for adding content on top of a container
@param Container $container The container
@return GrantResult Returns the grant result telling if creation is allowed
|
[
"Grant",
"evaluation",
"for",
"adding",
"content",
"on",
"top",
"of",
"a",
"container"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Backend/UserGuard.php#L716-L727
|
25,444
|
vaniocz/stdlib
|
src/UniversalJsonSerializer.php
|
UniversalJsonSerializer.serialize
|
public static function serialize($value): string
{
$serialized = json_encode(
self::encode($value, new SplObjectStorage()),
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException(json_last_error_msg());
}
return $serialized;
}
|
php
|
public static function serialize($value): string
{
$serialized = json_encode(
self::encode($value, new SplObjectStorage()),
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException(json_last_error_msg());
}
return $serialized;
}
|
[
"public",
"static",
"function",
"serialize",
"(",
"$",
"value",
")",
":",
"string",
"{",
"$",
"serialized",
"=",
"json_encode",
"(",
"self",
"::",
"encode",
"(",
"$",
"value",
",",
"new",
"SplObjectStorage",
"(",
")",
")",
",",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_UNESCAPED_SLASHES",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"json_last_error_msg",
"(",
")",
")",
";",
"}",
"return",
"$",
"serialized",
";",
"}"
] |
Serialize the given value into a JSON encoded string.
@param mixed $value The value to be serialized.
@return string The JSON encoded string.
|
[
"Serialize",
"the",
"given",
"value",
"into",
"a",
"JSON",
"encoded",
"string",
"."
] |
06a8343c42829d8fdeecad2bb5c30946fbd73e74
|
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/UniversalJsonSerializer.php#L22-L34
|
25,445
|
vaniocz/stdlib
|
src/UniversalJsonSerializer.php
|
UniversalJsonSerializer.objectProperties
|
private static function objectProperties($object): array
{
if ($object instanceof Serializable) {
return ['$' => $object->serialize()];
}
$class = get_class($object);
$properties = [];
do {
try {
$properties += Closure::bind(function () use ($object) {
return get_object_vars($object);
}, null, $class)->__invoke();
} catch (Throwable $e) {
return get_object_vars($object);
}
} while ($class = get_parent_class($class));
return method_exists($object, '__sleep')
? array_intersect_key($properties, array_flip($object->__sleep()))
: $properties;
}
|
php
|
private static function objectProperties($object): array
{
if ($object instanceof Serializable) {
return ['$' => $object->serialize()];
}
$class = get_class($object);
$properties = [];
do {
try {
$properties += Closure::bind(function () use ($object) {
return get_object_vars($object);
}, null, $class)->__invoke();
} catch (Throwable $e) {
return get_object_vars($object);
}
} while ($class = get_parent_class($class));
return method_exists($object, '__sleep')
? array_intersect_key($properties, array_flip($object->__sleep()))
: $properties;
}
|
[
"private",
"static",
"function",
"objectProperties",
"(",
"$",
"object",
")",
":",
"array",
"{",
"if",
"(",
"$",
"object",
"instanceof",
"Serializable",
")",
"{",
"return",
"[",
"'$'",
"=>",
"$",
"object",
"->",
"serialize",
"(",
")",
"]",
";",
"}",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"$",
"properties",
"=",
"[",
"]",
";",
"do",
"{",
"try",
"{",
"$",
"properties",
"+=",
"Closure",
"::",
"bind",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"object",
")",
"{",
"return",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"}",
",",
"null",
",",
"$",
"class",
")",
"->",
"__invoke",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"return",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"}",
"}",
"while",
"(",
"$",
"class",
"=",
"get_parent_class",
"(",
"$",
"class",
")",
")",
";",
"return",
"method_exists",
"(",
"$",
"object",
",",
"'__sleep'",
")",
"?",
"array_intersect_key",
"(",
"$",
"properties",
",",
"array_flip",
"(",
"$",
"object",
"->",
"__sleep",
"(",
")",
")",
")",
":",
"$",
"properties",
";",
"}"
] |
Get array of all the object properties.
@param object $object
@return mixed[] The array of all the object properties.
|
[
"Get",
"array",
"of",
"all",
"the",
"object",
"properties",
"."
] |
06a8343c42829d8fdeecad2bb5c30946fbd73e74
|
https://github.com/vaniocz/stdlib/blob/06a8343c42829d8fdeecad2bb5c30946fbd73e74/src/UniversalJsonSerializer.php#L72-L94
|
25,446
|
wearenolte/wp-acf
|
src/Acf/Transforms/Repeater.php
|
Repeater.apply
|
public static function apply( $field ) {
if ( 'repeater' === $field['type'] && is_array( $field['value'] ) ) {
self::transform_image_fields( $field );
self::transform_to_object( $field );
}
return $field['value'];
}
|
php
|
public static function apply( $field ) {
if ( 'repeater' === $field['type'] && is_array( $field['value'] ) ) {
self::transform_image_fields( $field );
self::transform_to_object( $field );
}
return $field['value'];
}
|
[
"public",
"static",
"function",
"apply",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"'repeater'",
"===",
"$",
"field",
"[",
"'type'",
"]",
"&&",
"is_array",
"(",
"$",
"field",
"[",
"'value'",
"]",
")",
")",
"{",
"self",
"::",
"transform_image_fields",
"(",
"$",
"field",
")",
";",
"self",
"::",
"transform_to_object",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"field",
"[",
"'value'",
"]",
";",
"}"
] |
Apply the transforms
@param array $field The field.
@return array
|
[
"Apply",
"the",
"transforms"
] |
2f5093438d637fa0eca42ad6d10f6b433ec078b2
|
https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf/Transforms/Repeater.php#L17-L25
|
25,447
|
wearenolte/wp-acf
|
src/Acf/Transforms/Repeater.php
|
Repeater.transform_image_fields
|
public static function transform_image_fields( &$field ) {
if ( empty( $field['value'] ) ) {
return $field['value'];
}
foreach ( $field['sub_fields'] as $sub_field ) {
if ( 'image' === $sub_field['type'] && 'id' === $sub_field['return_format'] ) {
foreach ( $field['value'] as $id => $item ) {
$field['value'][ $id ][ $sub_field['name'] ] =
Image::get_image_fields( $field, $item[ $sub_field['name'] ], $sub_field['name'] );
}
}
}
}
|
php
|
public static function transform_image_fields( &$field ) {
if ( empty( $field['value'] ) ) {
return $field['value'];
}
foreach ( $field['sub_fields'] as $sub_field ) {
if ( 'image' === $sub_field['type'] && 'id' === $sub_field['return_format'] ) {
foreach ( $field['value'] as $id => $item ) {
$field['value'][ $id ][ $sub_field['name'] ] =
Image::get_image_fields( $field, $item[ $sub_field['name'] ], $sub_field['name'] );
}
}
}
}
|
[
"public",
"static",
"function",
"transform_image_fields",
"(",
"&",
"$",
"field",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"field",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"$",
"field",
"[",
"'value'",
"]",
";",
"}",
"foreach",
"(",
"$",
"field",
"[",
"'sub_fields'",
"]",
"as",
"$",
"sub_field",
")",
"{",
"if",
"(",
"'image'",
"===",
"$",
"sub_field",
"[",
"'type'",
"]",
"&&",
"'id'",
"===",
"$",
"sub_field",
"[",
"'return_format'",
"]",
")",
"{",
"foreach",
"(",
"$",
"field",
"[",
"'value'",
"]",
"as",
"$",
"id",
"=>",
"$",
"item",
")",
"{",
"$",
"field",
"[",
"'value'",
"]",
"[",
"$",
"id",
"]",
"[",
"$",
"sub_field",
"[",
"'name'",
"]",
"]",
"=",
"Image",
"::",
"get_image_fields",
"(",
"$",
"field",
",",
"$",
"item",
"[",
"$",
"sub_field",
"[",
"'name'",
"]",
"]",
",",
"$",
"sub_field",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"}",
"}"
] |
Do the image size transform for an image sub fields.
@param string $field Field.
@return array
|
[
"Do",
"the",
"image",
"size",
"transform",
"for",
"an",
"image",
"sub",
"fields",
"."
] |
2f5093438d637fa0eca42ad6d10f6b433ec078b2
|
https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf/Transforms/Repeater.php#L33-L46
|
25,448
|
wearenolte/wp-acf
|
src/Acf/Transforms/Repeater.php
|
Repeater.transform_to_object
|
public static function transform_to_object( &$field ) {
if ( 1 !== count( $field['value'] ) ) {
return $field['value'];
}
$as_array = ! ( 1 === $field['min'] && 1 === $field['max'] );
$as_array = apply_filters( Filter::REPEATER_AS_ARRAY, $as_array, $field );
$field['value'] = $as_array ? $field['value'] : $field['value'][0];
}
|
php
|
public static function transform_to_object( &$field ) {
if ( 1 !== count( $field['value'] ) ) {
return $field['value'];
}
$as_array = ! ( 1 === $field['min'] && 1 === $field['max'] );
$as_array = apply_filters( Filter::REPEATER_AS_ARRAY, $as_array, $field );
$field['value'] = $as_array ? $field['value'] : $field['value'][0];
}
|
[
"public",
"static",
"function",
"transform_to_object",
"(",
"&",
"$",
"field",
")",
"{",
"if",
"(",
"1",
"!==",
"count",
"(",
"$",
"field",
"[",
"'value'",
"]",
")",
")",
"{",
"return",
"$",
"field",
"[",
"'value'",
"]",
";",
"}",
"$",
"as_array",
"=",
"!",
"(",
"1",
"===",
"$",
"field",
"[",
"'min'",
"]",
"&&",
"1",
"===",
"$",
"field",
"[",
"'max'",
"]",
")",
";",
"$",
"as_array",
"=",
"apply_filters",
"(",
"Filter",
"::",
"REPEATER_AS_ARRAY",
",",
"$",
"as_array",
",",
"$",
"field",
")",
";",
"$",
"field",
"[",
"'value'",
"]",
"=",
"$",
"as_array",
"?",
"$",
"field",
"[",
"'value'",
"]",
":",
"$",
"field",
"[",
"'value'",
"]",
"[",
"0",
"]",
";",
"}"
] |
Transform to an object if the filter is set and there is only 1 item.
@param array $field Field.
@return mixed
|
[
"Transform",
"to",
"an",
"object",
"if",
"the",
"filter",
"is",
"set",
"and",
"there",
"is",
"only",
"1",
"item",
"."
] |
2f5093438d637fa0eca42ad6d10f6b433ec078b2
|
https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf/Transforms/Repeater.php#L54-L63
|
25,449
|
danielgp/browser-agent-info
|
source/ArchitecturesCpu.php
|
ArchiecturesCpu.listOfKnownCpuArchitectures
|
private function listOfKnownCpuArchitectures()
{
$arc = array_merge($this->listOfCpuArchitecturesX86(), $this->listOfCpuArchitecturesX64());
ksort($arc);
return $arc;
}
|
php
|
private function listOfKnownCpuArchitectures()
{
$arc = array_merge($this->listOfCpuArchitecturesX86(), $this->listOfCpuArchitecturesX64());
ksort($arc);
return $arc;
}
|
[
"private",
"function",
"listOfKnownCpuArchitectures",
"(",
")",
"{",
"$",
"arc",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"listOfCpuArchitecturesX86",
"(",
")",
",",
"$",
"this",
"->",
"listOfCpuArchitecturesX64",
"(",
")",
")",
";",
"ksort",
"(",
"$",
"arc",
")",
";",
"return",
"$",
"arc",
";",
"}"
] |
Holds a list of Known CPU Srchitectures as array
@return array
|
[
"Holds",
"a",
"list",
"of",
"Known",
"CPU",
"Srchitectures",
"as",
"array"
] |
5e4b2c01793ee47ce517be2c799d64abe78d7f8a
|
https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/ArchitecturesCpu.php#L164-L169
|
25,450
|
Soneritics/Database
|
Soneritics/Database/DatabaseConnection/PDOMySQL.php
|
PDOMySQL.quote
|
public function quote($value)
{
if (is_array($value)) {
$result = [];
foreach ($value as $single) {
$result[] = $this->quote($single);
}
return sprintf(
'(%s)',
implode(', ', $result)
);
} else {
return $this->pdo->quote($value);
}
}
|
php
|
public function quote($value)
{
if (is_array($value)) {
$result = [];
foreach ($value as $single) {
$result[] = $this->quote($single);
}
return sprintf(
'(%s)',
implode(', ', $result)
);
} else {
return $this->pdo->quote($value);
}
}
|
[
"public",
"function",
"quote",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"single",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"single",
")",
";",
"}",
"return",
"sprintf",
"(",
"'(%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"result",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
"}"
] |
Quote a value for use in a query.
@param $value
@return string
|
[
"Quote",
"a",
"value",
"for",
"use",
"in",
"a",
"query",
"."
] |
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
|
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/DatabaseConnection/PDOMySQL.php#L67-L81
|
25,451
|
miguelibero/meinhof
|
src/Meinhof/Assetic/DelegatingResourceLoader.php
|
DelegatingResourceLoader.setLoaders
|
public function setLoaders(array $loaders)
{
$this->loaders = array();
foreach ($loaders as $type=>$loader) {
if (!$loader instanceof ResourceLoaderInterface) {
throw new \InvalidArgumentException("Not a valid resource loader.");
}
$this->loaders[$type] = $loader;
}
}
|
php
|
public function setLoaders(array $loaders)
{
$this->loaders = array();
foreach ($loaders as $type=>$loader) {
if (!$loader instanceof ResourceLoaderInterface) {
throw new \InvalidArgumentException("Not a valid resource loader.");
}
$this->loaders[$type] = $loader;
}
}
|
[
"public",
"function",
"setLoaders",
"(",
"array",
"$",
"loaders",
")",
"{",
"$",
"this",
"->",
"loaders",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"loaders",
"as",
"$",
"type",
"=>",
"$",
"loader",
")",
"{",
"if",
"(",
"!",
"$",
"loader",
"instanceof",
"ResourceLoaderInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Not a valid resource loader.\"",
")",
";",
"}",
"$",
"this",
"->",
"loaders",
"[",
"$",
"type",
"]",
"=",
"$",
"loader",
";",
"}",
"}"
] |
sets the list of available resource loaders
@param array $loaders a list of resource loaders indexed by type
|
[
"sets",
"the",
"list",
"of",
"available",
"resource",
"loaders"
] |
3a090f08485dc0da3e27463cf349dba374201072
|
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/Assetic/DelegatingResourceLoader.php#L56-L65
|
25,452
|
miguelibero/meinhof
|
src/Meinhof/Assetic/DelegatingResourceLoader.php
|
DelegatingResourceLoader.getLoader
|
protected function getLoader($type)
{
if (!isset($this->loaders[$type])) {
throw new \InvalidArgumentException("No loader defined for type '${type}'.");
}
return $this->loaders[$type];
}
|
php
|
protected function getLoader($type)
{
if (!isset($this->loaders[$type])) {
throw new \InvalidArgumentException("No loader defined for type '${type}'.");
}
return $this->loaders[$type];
}
|
[
"protected",
"function",
"getLoader",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"loaders",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No loader defined for type '${type}'.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"loaders",
"[",
"$",
"type",
"]",
";",
"}"
] |
Get the resource loader for a given type
@param string $type the resource type
@return ResourceLoaderInterface the resource loader
@throws \InvalidArgumentException if no loader defined for the given type
|
[
"Get",
"the",
"resource",
"loader",
"for",
"a",
"given",
"type"
] |
3a090f08485dc0da3e27463cf349dba374201072
|
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/Assetic/DelegatingResourceLoader.php#L87-L94
|
25,453
|
miguelibero/meinhof
|
src/Meinhof/Assetic/DelegatingResourceLoader.php
|
DelegatingResourceLoader.getResourceType
|
protected function getResourceType($name)
{
if (!isset($this->types[$name])) {
$template = $this->parser->parse($name);
if ($template instanceof TemplateReferenceInterface) {
$this->types[$name] = $template->get('engine');
}
}
if (!isset($this->types[$name])) {
throw new \RuntimeException("Could not load the given resource.");
}
return $this->types[$name];
}
|
php
|
protected function getResourceType($name)
{
if (!isset($this->types[$name])) {
$template = $this->parser->parse($name);
if ($template instanceof TemplateReferenceInterface) {
$this->types[$name] = $template->get('engine');
}
}
if (!isset($this->types[$name])) {
throw new \RuntimeException("Could not load the given resource.");
}
return $this->types[$name];
}
|
[
"protected",
"function",
"getResourceType",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"template",
"instanceof",
"TemplateReferenceInterface",
")",
"{",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
"=",
"$",
"template",
"->",
"get",
"(",
"'engine'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Could not load the given resource.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"types",
"[",
"$",
"name",
"]",
";",
"}"
] |
Returns the type of a resource
@param string $name the name of the resource
@return string type of the resource
@throws \RuntimeException if the resource could not be loaded
|
[
"Returns",
"the",
"type",
"of",
"a",
"resource"
] |
3a090f08485dc0da3e27463cf349dba374201072
|
https://github.com/miguelibero/meinhof/blob/3a090f08485dc0da3e27463cf349dba374201072/src/Meinhof/Assetic/DelegatingResourceLoader.php#L104-L117
|
25,454
|
praxigento/mobi_mod_downline
|
Observer/CustomerSaveAfterDataObject/A/GroupSwitch.php
|
GroupSwitch.registerGroupChange
|
private function registerGroupChange($custId, $groupIdOld, $groupIdNew)
{
$data = new EChangeGroup();
$data->setCustomerRef($custId);
$data->setGroupOld($groupIdOld);
$data->setGroupNew($groupIdNew);
$dateChanged = $this->hlpDate->getUtcNowForDb();
$data->setDateChanged($dateChanged);
$this->daoChangeGroup->create($data);
}
|
php
|
private function registerGroupChange($custId, $groupIdOld, $groupIdNew)
{
$data = new EChangeGroup();
$data->setCustomerRef($custId);
$data->setGroupOld($groupIdOld);
$data->setGroupNew($groupIdNew);
$dateChanged = $this->hlpDate->getUtcNowForDb();
$data->setDateChanged($dateChanged);
$this->daoChangeGroup->create($data);
}
|
[
"private",
"function",
"registerGroupChange",
"(",
"$",
"custId",
",",
"$",
"groupIdOld",
",",
"$",
"groupIdNew",
")",
"{",
"$",
"data",
"=",
"new",
"EChangeGroup",
"(",
")",
";",
"$",
"data",
"->",
"setCustomerRef",
"(",
"$",
"custId",
")",
";",
"$",
"data",
"->",
"setGroupOld",
"(",
"$",
"groupIdOld",
")",
";",
"$",
"data",
"->",
"setGroupNew",
"(",
"$",
"groupIdNew",
")",
";",
"$",
"dateChanged",
"=",
"$",
"this",
"->",
"hlpDate",
"->",
"getUtcNowForDb",
"(",
")",
";",
"$",
"data",
"->",
"setDateChanged",
"(",
"$",
"dateChanged",
")",
";",
"$",
"this",
"->",
"daoChangeGroup",
"->",
"create",
"(",
"$",
"data",
")",
";",
"}"
] |
Save group change event into registry.
@param int $custId
@param int $groupIdOld
@param int $groupIdNew
|
[
"Save",
"group",
"change",
"event",
"into",
"registry",
"."
] |
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
|
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Observer/CustomerSaveAfterDataObject/A/GroupSwitch.php#L65-L74
|
25,455
|
Aviogram/Common
|
src/Hydrator/ByClassMethods.php
|
ByClassMethods.getSetters
|
protected function getSetters($object)
{
// Get the current class
$class = get_class($object);
// Check if we have already parsed this class
if (array_key_exists($class, $this->classMethodsCache) === true) {
return $this->classMethodsCache[$class];
}
// Regex for parsing ReflectionParameter::__toString()
$regex = '/\[\s\<(?P<required>[^\>]+)\>\s' .
'(?:(?P<typehint_a>[^\s]+|(?P<typehint_b>[^\s]+)\sor\s(?P<typehint_c>[^\s]+))\s)?' .
'(?P<variable>\$[^\s]+)\s(?:=\s(?P<default>[^\]]+)\s)?\]/';
// Make reflection and fetch the methods
$reflectionClass = new ReflectionClass($object);
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
// Make result container
$setters = new Collection\Method();
// Loop through the methods
foreach ($methods as $method) {
// We only care about the setters
if (substr($method->getName(), 0, 3) !== 'set') {
continue;
}
// Get parameter collection
$parameters = $method->getParameters();
// We only take care of the first parameter of the setter
$parameter = $parameters[0];
$raw = (string) $parameter;
// If we cannot match it we continue
if (($result = preg_match($regex, $raw, $matches)) === false || $result === 0) {
continue;
}
// Parse the result of the regex
$required = ($matches['required'] === 'required');
$variable = $matches['variable'];
$default = $required ? null : $matches['default'];
$typehint = null;
// Advanced typehint detection
if (empty($matches['typehint_b']) === false) {
$typehint = $matches['typehint_b'];
} else if (empty($matches['typehint_a']) === false){
$typehint = $matches['typehint_a'];
}
// Set the correct default value
switch ($default) {
case null:
case 'NULL':
$default = null;
break;
case 'Array':
$default = array();
break;
default:
$default = trim($default, "'");
break;
}
// Has it child objects
$childObject = ($typehint !== null && $typehint !== 'array');
// Set the results the the response object
$setters->offsetSet(
$method->getName(),
new Entity\Method(
$required,
$default,
$typehint,
$childObject
)
);
}
// Return the just generated response
return $this->classMethodsCache[$class] = $setters;
}
|
php
|
protected function getSetters($object)
{
// Get the current class
$class = get_class($object);
// Check if we have already parsed this class
if (array_key_exists($class, $this->classMethodsCache) === true) {
return $this->classMethodsCache[$class];
}
// Regex for parsing ReflectionParameter::__toString()
$regex = '/\[\s\<(?P<required>[^\>]+)\>\s' .
'(?:(?P<typehint_a>[^\s]+|(?P<typehint_b>[^\s]+)\sor\s(?P<typehint_c>[^\s]+))\s)?' .
'(?P<variable>\$[^\s]+)\s(?:=\s(?P<default>[^\]]+)\s)?\]/';
// Make reflection and fetch the methods
$reflectionClass = new ReflectionClass($object);
$methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
// Make result container
$setters = new Collection\Method();
// Loop through the methods
foreach ($methods as $method) {
// We only care about the setters
if (substr($method->getName(), 0, 3) !== 'set') {
continue;
}
// Get parameter collection
$parameters = $method->getParameters();
// We only take care of the first parameter of the setter
$parameter = $parameters[0];
$raw = (string) $parameter;
// If we cannot match it we continue
if (($result = preg_match($regex, $raw, $matches)) === false || $result === 0) {
continue;
}
// Parse the result of the regex
$required = ($matches['required'] === 'required');
$variable = $matches['variable'];
$default = $required ? null : $matches['default'];
$typehint = null;
// Advanced typehint detection
if (empty($matches['typehint_b']) === false) {
$typehint = $matches['typehint_b'];
} else if (empty($matches['typehint_a']) === false){
$typehint = $matches['typehint_a'];
}
// Set the correct default value
switch ($default) {
case null:
case 'NULL':
$default = null;
break;
case 'Array':
$default = array();
break;
default:
$default = trim($default, "'");
break;
}
// Has it child objects
$childObject = ($typehint !== null && $typehint !== 'array');
// Set the results the the response object
$setters->offsetSet(
$method->getName(),
new Entity\Method(
$required,
$default,
$typehint,
$childObject
)
);
}
// Return the just generated response
return $this->classMethodsCache[$class] = $setters;
}
|
[
"protected",
"function",
"getSetters",
"(",
"$",
"object",
")",
"{",
"// Get the current class\r",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"// Check if we have already parsed this class\r",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"classMethodsCache",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"classMethodsCache",
"[",
"$",
"class",
"]",
";",
"}",
"// Regex for parsing ReflectionParameter::__toString()\r",
"$",
"regex",
"=",
"'/\\[\\s\\<(?P<required>[^\\>]+)\\>\\s'",
".",
"'(?:(?P<typehint_a>[^\\s]+|(?P<typehint_b>[^\\s]+)\\sor\\s(?P<typehint_c>[^\\s]+))\\s)?'",
".",
"'(?P<variable>\\$[^\\s]+)\\s(?:=\\s(?P<default>[^\\]]+)\\s)?\\]/'",
";",
"// Make reflection and fetch the methods\r",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"object",
")",
";",
"$",
"methods",
"=",
"$",
"reflectionClass",
"->",
"getMethods",
"(",
"ReflectionMethod",
"::",
"IS_PUBLIC",
")",
";",
"// Make result container\r",
"$",
"setters",
"=",
"new",
"Collection",
"\\",
"Method",
"(",
")",
";",
"// Loop through the methods\r",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"// We only care about the setters\r",
"if",
"(",
"substr",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"0",
",",
"3",
")",
"!==",
"'set'",
")",
"{",
"continue",
";",
"}",
"// Get parameter collection\r",
"$",
"parameters",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"// We only take care of the first parameter of the setter\r",
"$",
"parameter",
"=",
"$",
"parameters",
"[",
"0",
"]",
";",
"$",
"raw",
"=",
"(",
"string",
")",
"$",
"parameter",
";",
"// If we cannot match it we continue\r",
"if",
"(",
"(",
"$",
"result",
"=",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"raw",
",",
"$",
"matches",
")",
")",
"===",
"false",
"||",
"$",
"result",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"// Parse the result of the regex\r",
"$",
"required",
"=",
"(",
"$",
"matches",
"[",
"'required'",
"]",
"===",
"'required'",
")",
";",
"$",
"variable",
"=",
"$",
"matches",
"[",
"'variable'",
"]",
";",
"$",
"default",
"=",
"$",
"required",
"?",
"null",
":",
"$",
"matches",
"[",
"'default'",
"]",
";",
"$",
"typehint",
"=",
"null",
";",
"// Advanced typehint detection\r",
"if",
"(",
"empty",
"(",
"$",
"matches",
"[",
"'typehint_b'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"typehint",
"=",
"$",
"matches",
"[",
"'typehint_b'",
"]",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"matches",
"[",
"'typehint_a'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"typehint",
"=",
"$",
"matches",
"[",
"'typehint_a'",
"]",
";",
"}",
"// Set the correct default value\r",
"switch",
"(",
"$",
"default",
")",
"{",
"case",
"null",
":",
"case",
"'NULL'",
":",
"$",
"default",
"=",
"null",
";",
"break",
";",
"case",
"'Array'",
":",
"$",
"default",
"=",
"array",
"(",
")",
";",
"break",
";",
"default",
":",
"$",
"default",
"=",
"trim",
"(",
"$",
"default",
",",
"\"'\"",
")",
";",
"break",
";",
"}",
"// Has it child objects\r",
"$",
"childObject",
"=",
"(",
"$",
"typehint",
"!==",
"null",
"&&",
"$",
"typehint",
"!==",
"'array'",
")",
";",
"// Set the results the the response object\r",
"$",
"setters",
"->",
"offsetSet",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"new",
"Entity",
"\\",
"Method",
"(",
"$",
"required",
",",
"$",
"default",
",",
"$",
"typehint",
",",
"$",
"childObject",
")",
")",
";",
"}",
"// Return the just generated response\r",
"return",
"$",
"this",
"->",
"classMethodsCache",
"[",
"$",
"class",
"]",
"=",
"$",
"setters",
";",
"}"
] |
Get the setters of an object
@param mixed $object
@return Collection\Method
|
[
"Get",
"the",
"setters",
"of",
"an",
"object"
] |
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
|
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Hydrator/ByClassMethods.php#L136-L221
|
25,456
|
geoffadams/bedrest-core
|
library/BedRest/Content/Negotiation/Negotiator.php
|
Negotiator.setSupportedMediaTypes
|
public function setSupportedMediaTypes(array $mediaTypes)
{
foreach ($mediaTypes as $mediaType => $converterClass) {
if (!is_string($mediaType)) {
throw new Exception('Media type must be a string.');
}
if (!is_string($converterClass)) {
throw new Exception('Converter class name must be a string.');
}
}
$this->supportedMediaTypes = $mediaTypes;
}
|
php
|
public function setSupportedMediaTypes(array $mediaTypes)
{
foreach ($mediaTypes as $mediaType => $converterClass) {
if (!is_string($mediaType)) {
throw new Exception('Media type must be a string.');
}
if (!is_string($converterClass)) {
throw new Exception('Converter class name must be a string.');
}
}
$this->supportedMediaTypes = $mediaTypes;
}
|
[
"public",
"function",
"setSupportedMediaTypes",
"(",
"array",
"$",
"mediaTypes",
")",
"{",
"foreach",
"(",
"$",
"mediaTypes",
"as",
"$",
"mediaType",
"=>",
"$",
"converterClass",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"mediaType",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Media type must be a string.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"converterClass",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Converter class name must be a string.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"supportedMediaTypes",
"=",
"$",
"mediaTypes",
";",
"}"
] |
Sets the list of supported media types for negotiation.
@param array $mediaTypes
@throws \BedRest\Content\Negotiation\Exception
|
[
"Sets",
"the",
"list",
"of",
"supported",
"media",
"types",
"for",
"negotiation",
"."
] |
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
|
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Content/Negotiation/Negotiator.php#L54-L67
|
25,457
|
geoffadams/bedrest-core
|
library/BedRest/Content/Negotiation/Negotiator.php
|
Negotiator.negotiate
|
public function negotiate($content, MediaTypeList $mediaTypeList)
{
$contentType = $mediaTypeList->getBestMatch(array_keys($this->supportedMediaTypes));
if (!$contentType) {
throw new Exception('A suitable Content-Type could not be found.');
}
$result = new NegotiatedResult();
$result->contentType = $contentType;
$result->content = $this->encode($content, $contentType);
return $result;
}
|
php
|
public function negotiate($content, MediaTypeList $mediaTypeList)
{
$contentType = $mediaTypeList->getBestMatch(array_keys($this->supportedMediaTypes));
if (!$contentType) {
throw new Exception('A suitable Content-Type could not be found.');
}
$result = new NegotiatedResult();
$result->contentType = $contentType;
$result->content = $this->encode($content, $contentType);
return $result;
}
|
[
"public",
"function",
"negotiate",
"(",
"$",
"content",
",",
"MediaTypeList",
"$",
"mediaTypeList",
")",
"{",
"$",
"contentType",
"=",
"$",
"mediaTypeList",
"->",
"getBestMatch",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"supportedMediaTypes",
")",
")",
";",
"if",
"(",
"!",
"$",
"contentType",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'A suitable Content-Type could not be found.'",
")",
";",
"}",
"$",
"result",
"=",
"new",
"NegotiatedResult",
"(",
")",
";",
"$",
"result",
"->",
"contentType",
"=",
"$",
"contentType",
";",
"$",
"result",
"->",
"content",
"=",
"$",
"this",
"->",
"encode",
"(",
"$",
"content",
",",
"$",
"contentType",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Negotiates content based on a set of input criteria.
@param mixed $content
@param \BedRest\Content\Negotiation\MediaTypeList $mediaTypeList
@throws \BedRest\Content\Negotiation\Exception
@return \BedRest\Content\Negotiation\NegotiatedResult
|
[
"Negotiates",
"content",
"based",
"on",
"a",
"set",
"of",
"input",
"criteria",
"."
] |
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
|
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Content/Negotiation/Negotiator.php#L78-L90
|
25,458
|
zhaoxianfang/tools
|
src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
|
YamlFileLoader.loadFromExtensions
|
private function loadFromExtensions(array $content)
{
foreach ($content as $namespace => $values) {
if (in_array($namespace, array('imports', 'parameters', 'services'))) {
continue;
}
if (!is_array($values) && null !== $values) {
$values = array();
}
$this->container->loadFromExtension($namespace, $values);
}
}
|
php
|
private function loadFromExtensions(array $content)
{
foreach ($content as $namespace => $values) {
if (in_array($namespace, array('imports', 'parameters', 'services'))) {
continue;
}
if (!is_array($values) && null !== $values) {
$values = array();
}
$this->container->loadFromExtension($namespace, $values);
}
}
|
[
"private",
"function",
"loadFromExtensions",
"(",
"array",
"$",
"content",
")",
"{",
"foreach",
"(",
"$",
"content",
"as",
"$",
"namespace",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"namespace",
",",
"array",
"(",
"'imports'",
",",
"'parameters'",
",",
"'services'",
")",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
"&&",
"null",
"!==",
"$",
"values",
")",
"{",
"$",
"values",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"container",
"->",
"loadFromExtension",
"(",
"$",
"namespace",
",",
"$",
"values",
")",
";",
"}",
"}"
] |
Loads from Extensions.
|
[
"Loads",
"from",
"Extensions",
"."
] |
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
|
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php#L817-L830
|
25,459
|
rutger-speksnijder/simpleroute
|
src/SimpleRoute/Router.php
|
Router.setUrl
|
public function setUrl($url)
{
$this->url = $url;
// Check if the url ends with a slash
if ($this->url && substr($this->url, -1) !== '/') {
$this->url .= '/';
}
return $this;
}
|
php
|
public function setUrl($url)
{
$this->url = $url;
// Check if the url ends with a slash
if ($this->url && substr($this->url, -1) !== '/') {
$this->url .= '/';
}
return $this;
}
|
[
"public",
"function",
"setUrl",
"(",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"// Check if the url ends with a slash",
"if",
"(",
"$",
"this",
"->",
"url",
"&&",
"substr",
"(",
"$",
"this",
"->",
"url",
",",
"-",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"this",
"->",
"url",
".=",
"'/'",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the request url.
@param string $url The url.
@return $this The current object.
|
[
"Sets",
"the",
"request",
"url",
"."
] |
b862cea540d515e91d2c3a912b53e5e31939695e
|
https://github.com/rutger-speksnijder/simpleroute/blob/b862cea540d515e91d2c3a912b53e5e31939695e/src/SimpleRoute/Router.php#L124-L134
|
25,460
|
rutger-speksnijder/simpleroute
|
src/SimpleRoute/Router.php
|
Router.add
|
public function add($route, $callable, $type = 'any')
{
// Check if the route ends with a forward slash
if ($route && substr($route, -1) !== '/') {
$route .= '/';
}
// Add the route
$this->routes[strtolower($type)][$route] = $callable;
return $this;
}
|
php
|
public function add($route, $callable, $type = 'any')
{
// Check if the route ends with a forward slash
if ($route && substr($route, -1) !== '/') {
$route .= '/';
}
// Add the route
$this->routes[strtolower($type)][$route] = $callable;
return $this;
}
|
[
"public",
"function",
"add",
"(",
"$",
"route",
",",
"$",
"callable",
",",
"$",
"type",
"=",
"'any'",
")",
"{",
"// Check if the route ends with a forward slash",
"if",
"(",
"$",
"route",
"&&",
"substr",
"(",
"$",
"route",
",",
"-",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"route",
".=",
"'/'",
";",
"}",
"// Add the route",
"$",
"this",
"->",
"routes",
"[",
"strtolower",
"(",
"$",
"type",
")",
"]",
"[",
"$",
"route",
"]",
"=",
"$",
"callable",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a route to the router.
@param string $route The route.
@param callable $callable The method to execute when this route gets called.
@param string $type The request type to bind this route to.
@return $this The current object.
|
[
"Adds",
"a",
"route",
"to",
"the",
"router",
"."
] |
b862cea540d515e91d2c3a912b53e5e31939695e
|
https://github.com/rutger-speksnijder/simpleroute/blob/b862cea540d515e91d2c3a912b53e5e31939695e/src/SimpleRoute/Router.php#L155-L165
|
25,461
|
rutger-speksnijder/simpleroute
|
src/SimpleRoute/Router.php
|
Router.getMethodsByRoute
|
public function getMethodsByRoute($route)
{
// Check if a route was provided
if (!$route) {
return [];
}
// Loop through our routes
$methods = [];
foreach ($this->routes as $method => $routes) {
foreach ($routes as $availableRoute => $callable) {
// Check if the available route is the same as the specified route
if ($availableRoute === $route) {
$methods[] = $method;
continue 2;
}
// Check if the route matches
$regex = '/^' . str_replace('/', '\/', $availableRoute) . '/Uim';
if (preg_match($regex, $route, $matches) === 1 && $matches[0] === $route) {
$methods[] = $method;
continue 2;
}
}
}
// Return the methods array
return $methods;
}
|
php
|
public function getMethodsByRoute($route)
{
// Check if a route was provided
if (!$route) {
return [];
}
// Loop through our routes
$methods = [];
foreach ($this->routes as $method => $routes) {
foreach ($routes as $availableRoute => $callable) {
// Check if the available route is the same as the specified route
if ($availableRoute === $route) {
$methods[] = $method;
continue 2;
}
// Check if the route matches
$regex = '/^' . str_replace('/', '\/', $availableRoute) . '/Uim';
if (preg_match($regex, $route, $matches) === 1 && $matches[0] === $route) {
$methods[] = $method;
continue 2;
}
}
}
// Return the methods array
return $methods;
}
|
[
"public",
"function",
"getMethodsByRoute",
"(",
"$",
"route",
")",
"{",
"// Check if a route was provided",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// Loop through our routes",
"$",
"methods",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"method",
"=>",
"$",
"routes",
")",
"{",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"availableRoute",
"=>",
"$",
"callable",
")",
"{",
"// Check if the available route is the same as the specified route",
"if",
"(",
"$",
"availableRoute",
"===",
"$",
"route",
")",
"{",
"$",
"methods",
"[",
"]",
"=",
"$",
"method",
";",
"continue",
"2",
";",
"}",
"// Check if the route matches",
"$",
"regex",
"=",
"'/^'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\/'",
",",
"$",
"availableRoute",
")",
".",
"'/Uim'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"route",
",",
"$",
"matches",
")",
"===",
"1",
"&&",
"$",
"matches",
"[",
"0",
"]",
"===",
"$",
"route",
")",
"{",
"$",
"methods",
"[",
"]",
"=",
"$",
"method",
";",
"continue",
"2",
";",
"}",
"}",
"}",
"// Return the methods array",
"return",
"$",
"methods",
";",
"}"
] |
Returns an array of methods defined for a specific route.
Useful for an "OPTIONS" request.
@param string $route The route to get the methods from.
@return array An array with methods.
|
[
"Returns",
"an",
"array",
"of",
"methods",
"defined",
"for",
"a",
"specific",
"route",
".",
"Useful",
"for",
"an",
"OPTIONS",
"request",
"."
] |
b862cea540d515e91d2c3a912b53e5e31939695e
|
https://github.com/rutger-speksnijder/simpleroute/blob/b862cea540d515e91d2c3a912b53e5e31939695e/src/SimpleRoute/Router.php#L275-L303
|
25,462
|
rutger-speksnijder/simpleroute
|
src/SimpleRoute/Router.php
|
Router.execute
|
public function execute()
{
// Check if we have a url
if (!$this->url || trim($this->url) == '') {
$this->url = '/';
}
// Make sure the url starts with a slash
if (substr($this->url, 0, 1) !== '/') {
$this->url = '/' . $this->url;
}
// Check if the absolute route exists in our routes array
// - and if that route has the same type of request as the current request.
if (isset($this->routes[$this->method][$this->url])) {
return call_user_func_array($this->routes[$this->method][$this->url], []);
}
// Check if the absolute route exists in our routes array
// - and if that route has the "any" type.
if (isset($this->routes['any'][$this->url])) {
return call_user_func_array($this->routes['any'][$this->url], []);
}
// Create an array of methods to check and loop through them
$methods = [$this->method, 'any'];
foreach ($methods as $method) {
// Loop through the routes set for this method
foreach ($this->routes[$method] as $route => $callable) {
// Check if the route matches
$regex = '/^' . str_replace('/', '\/', $route) . '/Uim';
$matches = [];
if (preg_match($regex, $this->url, $matches) === 1 && $matches[0] === $this->url) {
// First value in the array is the string that matched
array_shift($matches);
// Execute the callable method
return call_user_func_array($callable, $matches);
}
}
}
// No route found, check if we have an empty route.
// - We should always have an empty route.
if (!isset($this->routes['any']['/'])) {
header('HTTP/1.1 404 Not Found');
exit;
}
// Return the empty route's callable
return call_user_func_array($this->routes['any']['/'], []);
}
|
php
|
public function execute()
{
// Check if we have a url
if (!$this->url || trim($this->url) == '') {
$this->url = '/';
}
// Make sure the url starts with a slash
if (substr($this->url, 0, 1) !== '/') {
$this->url = '/' . $this->url;
}
// Check if the absolute route exists in our routes array
// - and if that route has the same type of request as the current request.
if (isset($this->routes[$this->method][$this->url])) {
return call_user_func_array($this->routes[$this->method][$this->url], []);
}
// Check if the absolute route exists in our routes array
// - and if that route has the "any" type.
if (isset($this->routes['any'][$this->url])) {
return call_user_func_array($this->routes['any'][$this->url], []);
}
// Create an array of methods to check and loop through them
$methods = [$this->method, 'any'];
foreach ($methods as $method) {
// Loop through the routes set for this method
foreach ($this->routes[$method] as $route => $callable) {
// Check if the route matches
$regex = '/^' . str_replace('/', '\/', $route) . '/Uim';
$matches = [];
if (preg_match($regex, $this->url, $matches) === 1 && $matches[0] === $this->url) {
// First value in the array is the string that matched
array_shift($matches);
// Execute the callable method
return call_user_func_array($callable, $matches);
}
}
}
// No route found, check if we have an empty route.
// - We should always have an empty route.
if (!isset($this->routes['any']['/'])) {
header('HTTP/1.1 404 Not Found');
exit;
}
// Return the empty route's callable
return call_user_func_array($this->routes['any']['/'], []);
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"// Check if we have a url",
"if",
"(",
"!",
"$",
"this",
"->",
"url",
"||",
"trim",
"(",
"$",
"this",
"->",
"url",
")",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"'/'",
";",
"}",
"// Make sure the url starts with a slash",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"url",
",",
"0",
",",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"'/'",
".",
"$",
"this",
"->",
"url",
";",
"}",
"// Check if the absolute route exists in our routes array",
"// - and if that route has the same type of request as the current request.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"this",
"->",
"method",
"]",
"[",
"$",
"this",
"->",
"url",
"]",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"this",
"->",
"method",
"]",
"[",
"$",
"this",
"->",
"url",
"]",
",",
"[",
"]",
")",
";",
"}",
"// Check if the absolute route exists in our routes array",
"// - and if that route has the \"any\" type.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"'any'",
"]",
"[",
"$",
"this",
"->",
"url",
"]",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"routes",
"[",
"'any'",
"]",
"[",
"$",
"this",
"->",
"url",
"]",
",",
"[",
"]",
")",
";",
"}",
"// Create an array of methods to check and loop through them",
"$",
"methods",
"=",
"[",
"$",
"this",
"->",
"method",
",",
"'any'",
"]",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"// Loop through the routes set for this method",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"as",
"$",
"route",
"=>",
"$",
"callable",
")",
"{",
"// Check if the route matches",
"$",
"regex",
"=",
"'/^'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\/'",
",",
"$",
"route",
")",
".",
"'/Uim'",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"this",
"->",
"url",
",",
"$",
"matches",
")",
"===",
"1",
"&&",
"$",
"matches",
"[",
"0",
"]",
"===",
"$",
"this",
"->",
"url",
")",
"{",
"// First value in the array is the string that matched",
"array_shift",
"(",
"$",
"matches",
")",
";",
"// Execute the callable method",
"return",
"call_user_func_array",
"(",
"$",
"callable",
",",
"$",
"matches",
")",
";",
"}",
"}",
"}",
"// No route found, check if we have an empty route.",
"// - We should always have an empty route.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"'any'",
"]",
"[",
"'/'",
"]",
")",
")",
"{",
"header",
"(",
"'HTTP/1.1 404 Not Found'",
")",
";",
"exit",
";",
"}",
"// Return the empty route's callable",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"routes",
"[",
"'any'",
"]",
"[",
"'/'",
"]",
",",
"[",
"]",
")",
";",
"}"
] |
Executes the router based on the url.
@throws Exception Throws an exception if no location was set and no default route was found.
@return mixed The result of the callable method.
|
[
"Executes",
"the",
"router",
"based",
"on",
"the",
"url",
"."
] |
b862cea540d515e91d2c3a912b53e5e31939695e
|
https://github.com/rutger-speksnijder/simpleroute/blob/b862cea540d515e91d2c3a912b53e5e31939695e/src/SimpleRoute/Router.php#L312-L363
|
25,463
|
Stinger-Soft/DoctrineCommons
|
src/StingerSoft/DoctrineCommons/Utils/JsonImporter.php
|
JsonImporter.before
|
protected function before() {
if($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
$this->connection->executeUpdate('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"');
} else if($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->connection->executeUpdate('SET FOREIGN_KEY_CHECKS=0');
} else if($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
$this->connection->executeUpdate('PRAGMA foreign_keys = OFF');
}
}
|
php
|
protected function before() {
if($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
$this->connection->executeUpdate('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"');
} else if($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->connection->executeUpdate('SET FOREIGN_KEY_CHECKS=0');
} else if($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
$this->connection->executeUpdate('PRAGMA foreign_keys = OFF');
}
}
|
[
"protected",
"function",
"before",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
"instanceof",
"SQLServerPlatform",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeUpdate",
"(",
"'EXEC sp_msforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\"'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
"instanceof",
"MySqlPlatform",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeUpdate",
"(",
"'SET FOREIGN_KEY_CHECKS=0'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
"instanceof",
"SqlitePlatform",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeUpdate",
"(",
"'PRAGMA foreign_keys = OFF'",
")",
";",
"}",
"}"
] |
Executed before the import is started
|
[
"Executed",
"before",
"the",
"import",
"is",
"started"
] |
1f0dd56a94654c8de63927d7eec2175aab3cf809
|
https://github.com/Stinger-Soft/DoctrineCommons/blob/1f0dd56a94654c8de63927d7eec2175aab3cf809/src/StingerSoft/DoctrineCommons/Utils/JsonImporter.php#L132-L140
|
25,464
|
Stinger-Soft/DoctrineCommons
|
src/StingerSoft/DoctrineCommons/Utils/JsonImporter.php
|
JsonImporter.after
|
protected function after() {
if($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
$this->connection->executeUpdate('exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"');
} else if($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->connection->executeUpdate('SET FOREIGN_KEY_CHECKS=1');
} else if($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
$this->connection->executeUpdate('PRAGMA foreign_keys = ON');
}
}
|
php
|
protected function after() {
if($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
$this->connection->executeUpdate('exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"');
} else if($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
$this->connection->executeUpdate('SET FOREIGN_KEY_CHECKS=1');
} else if($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
$this->connection->executeUpdate('PRAGMA foreign_keys = ON');
}
}
|
[
"protected",
"function",
"after",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
"instanceof",
"SQLServerPlatform",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeUpdate",
"(",
"'exec sp_msforeachtable \"ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all\"'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
"instanceof",
"MySqlPlatform",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeUpdate",
"(",
"'SET FOREIGN_KEY_CHECKS=1'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"getDatabasePlatform",
"(",
")",
"instanceof",
"SqlitePlatform",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"executeUpdate",
"(",
"'PRAGMA foreign_keys = ON'",
")",
";",
"}",
"}"
] |
Executed after the import is finished
|
[
"Executed",
"after",
"the",
"import",
"is",
"finished"
] |
1f0dd56a94654c8de63927d7eec2175aab3cf809
|
https://github.com/Stinger-Soft/DoctrineCommons/blob/1f0dd56a94654c8de63927d7eec2175aab3cf809/src/StingerSoft/DoctrineCommons/Utils/JsonImporter.php#L145-L153
|
25,465
|
kambalabs/KmbPmProxy
|
src/KmbPmProxy/Hydrator/GroupHydrator.php
|
GroupHydrator.hydrate
|
public function hydrate($puppetModules, $group)
{
$availableClasses = [];
if (!empty($puppetModules)) {
foreach ($puppetModules as $puppetModule) {
if ($puppetModule->hasClasses()) {
foreach ($puppetModule->getClasses() as $puppetClass) {
$groupClass = $group->getClassByName($puppetClass->getName());
if ($groupClass != null) {
if ($puppetClass->hasParametersTemplates()) {
$this->groupClassHydrator->hydrate($puppetClass->getParametersTemplates(), $groupClass);
}
} else {
$availableClasses[$puppetModule->getName()][] = $puppetClass->getName();
}
}
}
}
}
return $group->setAvailableClasses($availableClasses);
}
|
php
|
public function hydrate($puppetModules, $group)
{
$availableClasses = [];
if (!empty($puppetModules)) {
foreach ($puppetModules as $puppetModule) {
if ($puppetModule->hasClasses()) {
foreach ($puppetModule->getClasses() as $puppetClass) {
$groupClass = $group->getClassByName($puppetClass->getName());
if ($groupClass != null) {
if ($puppetClass->hasParametersTemplates()) {
$this->groupClassHydrator->hydrate($puppetClass->getParametersTemplates(), $groupClass);
}
} else {
$availableClasses[$puppetModule->getName()][] = $puppetClass->getName();
}
}
}
}
}
return $group->setAvailableClasses($availableClasses);
}
|
[
"public",
"function",
"hydrate",
"(",
"$",
"puppetModules",
",",
"$",
"group",
")",
"{",
"$",
"availableClasses",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"puppetModules",
")",
")",
"{",
"foreach",
"(",
"$",
"puppetModules",
"as",
"$",
"puppetModule",
")",
"{",
"if",
"(",
"$",
"puppetModule",
"->",
"hasClasses",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"puppetModule",
"->",
"getClasses",
"(",
")",
"as",
"$",
"puppetClass",
")",
"{",
"$",
"groupClass",
"=",
"$",
"group",
"->",
"getClassByName",
"(",
"$",
"puppetClass",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"groupClass",
"!=",
"null",
")",
"{",
"if",
"(",
"$",
"puppetClass",
"->",
"hasParametersTemplates",
"(",
")",
")",
"{",
"$",
"this",
"->",
"groupClassHydrator",
"->",
"hydrate",
"(",
"$",
"puppetClass",
"->",
"getParametersTemplates",
"(",
")",
",",
"$",
"groupClass",
")",
";",
"}",
"}",
"else",
"{",
"$",
"availableClasses",
"[",
"$",
"puppetModule",
"->",
"getName",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"puppetClass",
"->",
"getName",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"group",
"->",
"setAvailableClasses",
"(",
"$",
"availableClasses",
")",
";",
"}"
] |
Hydrate group with the provided puppet modules data.
@param PuppetModule[] $puppetModules
@param GroupInterface $group
@return GroupInterface
|
[
"Hydrate",
"group",
"with",
"the",
"provided",
"puppet",
"modules",
"data",
"."
] |
b4c664ae8b6f29e4e8768461ed99e1b0b80bde18
|
https://github.com/kambalabs/KmbPmProxy/blob/b4c664ae8b6f29e4e8768461ed99e1b0b80bde18/src/KmbPmProxy/Hydrator/GroupHydrator.php#L38-L58
|
25,466
|
dmitrya2e/filtration-bundle
|
Manager/FilterSuperManager.php
|
FilterSuperManager.addFilter
|
public function addFilter(CollectionInterface $collection, $typeAlias, $name, array $options = [])
{
$filter = $this->filterCreator->create($typeAlias, $name, $options);
$collection->addFilter($filter);
return $filter;
}
|
php
|
public function addFilter(CollectionInterface $collection, $typeAlias, $name, array $options = [])
{
$filter = $this->filterCreator->create($typeAlias, $name, $options);
$collection->addFilter($filter);
return $filter;
}
|
[
"public",
"function",
"addFilter",
"(",
"CollectionInterface",
"$",
"collection",
",",
"$",
"typeAlias",
",",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"filterCreator",
"->",
"create",
"(",
"$",
"typeAlias",
",",
"$",
"name",
",",
"$",
"options",
")",
";",
"$",
"collection",
"->",
"addFilter",
"(",
"$",
"filter",
")",
";",
"return",
"$",
"filter",
";",
"}"
] |
Adds a filter to the collection.
@param CollectionInterface $collection The filter collection
@param string $typeAlias The alias of the filter service definition
@param string $name The internal name of the filter
@param array $options (Optional) The options of the filter
@see \Da2e\FiltrationBundle\Filter\Creator\FilterCreatorInterface::create() for complete documentation
@see \Da2e\FiltrationBundle\Filter\Collection\CollectionInterface::addFilter() for complete documentation
@return FilterInterface
|
[
"Adds",
"a",
"filter",
"to",
"the",
"collection",
"."
] |
fed5764af4e43871835744fb84957b2a76e9a215
|
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Manager/FilterSuperManager.php#L114-L120
|
25,467
|
dmitrya2e/filtration-bundle
|
Manager/FilterSuperManager.php
|
FilterSuperManager.createNamedForm
|
public function createNamedForm(
$name,
CollectionInterface $collection,
array $rootFormBuilderOptions = [],
array $filterFormBuilderOptions = [],
Request $request = null
) {
$form = $this->formCreator->createNamed($name, $collection, $rootFormBuilderOptions, $filterFormBuilderOptions);
if ($request !== null) {
$form->handleRequest($request);
}
return $form;
}
|
php
|
public function createNamedForm(
$name,
CollectionInterface $collection,
array $rootFormBuilderOptions = [],
array $filterFormBuilderOptions = [],
Request $request = null
) {
$form = $this->formCreator->createNamed($name, $collection, $rootFormBuilderOptions, $filterFormBuilderOptions);
if ($request !== null) {
$form->handleRequest($request);
}
return $form;
}
|
[
"public",
"function",
"createNamedForm",
"(",
"$",
"name",
",",
"CollectionInterface",
"$",
"collection",
",",
"array",
"$",
"rootFormBuilderOptions",
"=",
"[",
"]",
",",
"array",
"$",
"filterFormBuilderOptions",
"=",
"[",
"]",
",",
"Request",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"formCreator",
"->",
"createNamed",
"(",
"$",
"name",
",",
"$",
"collection",
",",
"$",
"rootFormBuilderOptions",
",",
"$",
"filterFormBuilderOptions",
")",
";",
"if",
"(",
"$",
"request",
"!==",
"null",
")",
"{",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"form",
";",
"}"
] |
Creates a filtration named form.
@param string $name The name of the root form
@param CollectionInterface $collection The filter collection
@param array $rootFormBuilderOptions (Optional)
@param array $filterFormBuilderOptions (Optional)
@param Request|null $request (Optional) If passed Request object,
FormInterface::handleRequest() will be executed
@see \Da2e\FiltrationBundle\Form\Creator\FormCreatorInterface::createNamed() for complete documentation
@return \Symfony\Component\Form\FormInterface
|
[
"Creates",
"a",
"filtration",
"named",
"form",
"."
] |
fed5764af4e43871835744fb84957b2a76e9a215
|
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Manager/FilterSuperManager.php#L164-L178
|
25,468
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.index
|
public function index($trashed = false)
{
$this->authorize(UsersPolicy::PERMISSION_LIST);
$users = $this->user->with('roles')->protectAdmins()->when($trashed, function ($query) {
return $query->onlyTrashed();
})->paginate(30);
$title = trans('auth::users.titles.users-list').($trashed ? ' - '.trans('core::generals.trashed') : '');
$this->setTitle($title);
$this->addBreadcrumb($title);
return $this->view('admin.users.index', compact('trashed', 'users'));
}
|
php
|
public function index($trashed = false)
{
$this->authorize(UsersPolicy::PERMISSION_LIST);
$users = $this->user->with('roles')->protectAdmins()->when($trashed, function ($query) {
return $query->onlyTrashed();
})->paginate(30);
$title = trans('auth::users.titles.users-list').($trashed ? ' - '.trans('core::generals.trashed') : '');
$this->setTitle($title);
$this->addBreadcrumb($title);
return $this->view('admin.users.index', compact('trashed', 'users'));
}
|
[
"public",
"function",
"index",
"(",
"$",
"trashed",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_LIST",
")",
";",
"$",
"users",
"=",
"$",
"this",
"->",
"user",
"->",
"with",
"(",
"'roles'",
")",
"->",
"protectAdmins",
"(",
")",
"->",
"when",
"(",
"$",
"trashed",
",",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"onlyTrashed",
"(",
")",
";",
"}",
")",
"->",
"paginate",
"(",
"30",
")",
";",
"$",
"title",
"=",
"trans",
"(",
"'auth::users.titles.users-list'",
")",
".",
"(",
"$",
"trashed",
"?",
"' - '",
".",
"trans",
"(",
"'core::generals.trashed'",
")",
":",
"''",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"title",
")",
";",
"$",
"this",
"->",
"addBreadcrumb",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.users.index'",
",",
"compact",
"(",
"'trashed'",
",",
"'users'",
")",
")",
";",
"}"
] |
List the users.
@param bool $trashed
@return \Illuminate\View\View
|
[
"List",
"the",
"users",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L71-L84
|
25,469
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.listByRole
|
public function listByRole(Role $role, $trashed = false)
{
$this->authorize(UsersPolicy::PERMISSION_LIST);
$users = $role->users()->with('roles')
->protectAdmins()
->paginate(30);
$title = trans('auth::users.titles.users-list')." - {$role->name} Role". ($trashed ? ' - '.trans('core::generals.trashed') : '');
$this->setTitle($title);
$this->addBreadcrumb($title);
return $this->view('admin.users.list', compact('trashed', 'users'));
}
|
php
|
public function listByRole(Role $role, $trashed = false)
{
$this->authorize(UsersPolicy::PERMISSION_LIST);
$users = $role->users()->with('roles')
->protectAdmins()
->paginate(30);
$title = trans('auth::users.titles.users-list')." - {$role->name} Role". ($trashed ? ' - '.trans('core::generals.trashed') : '');
$this->setTitle($title);
$this->addBreadcrumb($title);
return $this->view('admin.users.list', compact('trashed', 'users'));
}
|
[
"public",
"function",
"listByRole",
"(",
"Role",
"$",
"role",
",",
"$",
"trashed",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_LIST",
")",
";",
"$",
"users",
"=",
"$",
"role",
"->",
"users",
"(",
")",
"->",
"with",
"(",
"'roles'",
")",
"->",
"protectAdmins",
"(",
")",
"->",
"paginate",
"(",
"30",
")",
";",
"$",
"title",
"=",
"trans",
"(",
"'auth::users.titles.users-list'",
")",
".",
"\" - {$role->name} Role\"",
".",
"(",
"$",
"trashed",
"?",
"' - '",
".",
"trans",
"(",
"'core::generals.trashed'",
")",
":",
"''",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"title",
")",
";",
"$",
"this",
"->",
"addBreadcrumb",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.users.list'",
",",
"compact",
"(",
"'trashed'",
",",
"'users'",
")",
")",
";",
"}"
] |
List the users by a role.
@param \Arcanesoft\Contracts\Auth\Models\Role $role
@param bool $trashed
@return \Illuminate\View\View
|
[
"List",
"the",
"users",
"by",
"a",
"role",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L104-L117
|
25,470
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.create
|
public function create(Role $role)
{
$this->authorize(UsersPolicy::PERMISSION_CREATE);
$roles = $role->all();
$this->setTitle($title = trans('auth::users.titles.create-user'));
$this->addBreadcrumb($title);
return $this->view('admin.users.create', compact('roles'));
}
|
php
|
public function create(Role $role)
{
$this->authorize(UsersPolicy::PERMISSION_CREATE);
$roles = $role->all();
$this->setTitle($title = trans('auth::users.titles.create-user'));
$this->addBreadcrumb($title);
return $this->view('admin.users.create', compact('roles'));
}
|
[
"public",
"function",
"create",
"(",
"Role",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_CREATE",
")",
";",
"$",
"roles",
"=",
"$",
"role",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"title",
"=",
"trans",
"(",
"'auth::users.titles.create-user'",
")",
")",
";",
"$",
"this",
"->",
"addBreadcrumb",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.users.create'",
",",
"compact",
"(",
"'roles'",
")",
")",
";",
"}"
] |
Show the create a new user form.
@param \Arcanesoft\Contracts\Auth\Models\Role $role
@return \Illuminate\View\View
|
[
"Show",
"the",
"create",
"a",
"new",
"user",
"form",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L126-L136
|
25,471
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.store
|
public function store(CreateUserRequest $request, User $user)
{
$this->authorize(UsersPolicy::PERMISSION_CREATE);
$user->fill($request->getValidatedData());
$user->is_active = true;
$user->save();
$user->roles()->sync($request->get('roles'));
$this->transNotification('created', ['name' => $user->full_name], $user->toArray());
return redirect()->route('admin::auth.users.index');
}
|
php
|
public function store(CreateUserRequest $request, User $user)
{
$this->authorize(UsersPolicy::PERMISSION_CREATE);
$user->fill($request->getValidatedData());
$user->is_active = true;
$user->save();
$user->roles()->sync($request->get('roles'));
$this->transNotification('created', ['name' => $user->full_name], $user->toArray());
return redirect()->route('admin::auth.users.index');
}
|
[
"public",
"function",
"store",
"(",
"CreateUserRequest",
"$",
"request",
",",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_CREATE",
")",
";",
"$",
"user",
"->",
"fill",
"(",
"$",
"request",
"->",
"getValidatedData",
"(",
")",
")",
";",
"$",
"user",
"->",
"is_active",
"=",
"true",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"$",
"user",
"->",
"roles",
"(",
")",
"->",
"sync",
"(",
"$",
"request",
"->",
"get",
"(",
"'roles'",
")",
")",
";",
"$",
"this",
"->",
"transNotification",
"(",
"'created'",
",",
"[",
"'name'",
"=>",
"$",
"user",
"->",
"full_name",
"]",
",",
"$",
"user",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'admin::auth.users.index'",
")",
";",
"}"
] |
Store the new user.
@param \Arcanesoft\Auth\Http\Requests\Admin\Users\CreateUserRequest $request
@param \Arcanesoft\Contracts\Auth\Models\User $user
@return \Illuminate\Http\RedirectResponse
|
[
"Store",
"the",
"new",
"user",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L146-L158
|
25,472
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.show
|
public function show(User $user)
{
$this->authorize(UsersPolicy::PERMISSION_SHOW);
$user->load(['roles', 'roles.permissions']);
$this->setTitle($title = trans('auth::users.titles.user-details'));
$this->addBreadcrumb($title);
return $this->view('admin.users.show', compact('user'));
}
|
php
|
public function show(User $user)
{
$this->authorize(UsersPolicy::PERMISSION_SHOW);
$user->load(['roles', 'roles.permissions']);
$this->setTitle($title = trans('auth::users.titles.user-details'));
$this->addBreadcrumb($title);
return $this->view('admin.users.show', compact('user'));
}
|
[
"public",
"function",
"show",
"(",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_SHOW",
")",
";",
"$",
"user",
"->",
"load",
"(",
"[",
"'roles'",
",",
"'roles.permissions'",
"]",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"title",
"=",
"trans",
"(",
"'auth::users.titles.user-details'",
")",
")",
";",
"$",
"this",
"->",
"addBreadcrumb",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.users.show'",
",",
"compact",
"(",
"'user'",
")",
")",
";",
"}"
] |
Show the user's details.
@param \Arcanesoft\Contracts\Auth\Models\User $user
@return \Illuminate\View\View
|
[
"Show",
"the",
"user",
"s",
"details",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L167-L177
|
25,473
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.edit
|
public function edit(User $user, Role $role)
{
$this->authorize(UsersPolicy::PERMISSION_UPDATE);
$user->load(['roles', 'roles.permissions']);
$roles = $role->all();
$this->setTitle($title = trans('auth::users.titles.edit-user'));
$this->addBreadcrumb($title);
return $this->view('admin.users.edit', compact('user', 'roles'));
}
|
php
|
public function edit(User $user, Role $role)
{
$this->authorize(UsersPolicy::PERMISSION_UPDATE);
$user->load(['roles', 'roles.permissions']);
$roles = $role->all();
$this->setTitle($title = trans('auth::users.titles.edit-user'));
$this->addBreadcrumb($title);
return $this->view('admin.users.edit', compact('user', 'roles'));
}
|
[
"public",
"function",
"edit",
"(",
"User",
"$",
"user",
",",
"Role",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_UPDATE",
")",
";",
"$",
"user",
"->",
"load",
"(",
"[",
"'roles'",
",",
"'roles.permissions'",
"]",
")",
";",
"$",
"roles",
"=",
"$",
"role",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"title",
"=",
"trans",
"(",
"'auth::users.titles.edit-user'",
")",
")",
";",
"$",
"this",
"->",
"addBreadcrumb",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.users.edit'",
",",
"compact",
"(",
"'user'",
",",
"'roles'",
")",
")",
";",
"}"
] |
Show the edit the user form.
@param \Arcanesoft\Contracts\Auth\Models\User $user
@param \Arcanesoft\Contracts\Auth\Models\Role $role
@return \Illuminate\View\View
|
[
"Show",
"the",
"edit",
"the",
"user",
"form",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L187-L198
|
25,474
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.restore
|
public function restore(User $user)
{
$this->authorize(UsersPolicy::PERMISSION_UPDATE);
try {
$user->restore();
$message = $this->transNotification('restored', ['name' => $user->full_name], $user->toArray());
return $this->jsonResponseSuccess(compact('message'));
}
catch (\Exception $e) {
return $this->jsonResponseError(['message' => $e->getMessage()], 500);
}
}
|
php
|
public function restore(User $user)
{
$this->authorize(UsersPolicy::PERMISSION_UPDATE);
try {
$user->restore();
$message = $this->transNotification('restored', ['name' => $user->full_name], $user->toArray());
return $this->jsonResponseSuccess(compact('message'));
}
catch (\Exception $e) {
return $this->jsonResponseError(['message' => $e->getMessage()], 500);
}
}
|
[
"public",
"function",
"restore",
"(",
"User",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"UsersPolicy",
"::",
"PERMISSION_UPDATE",
")",
";",
"try",
"{",
"$",
"user",
"->",
"restore",
"(",
")",
";",
"$",
"message",
"=",
"$",
"this",
"->",
"transNotification",
"(",
"'restored'",
",",
"[",
"'name'",
"=>",
"$",
"user",
"->",
"full_name",
"]",
",",
"$",
"user",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"jsonResponseSuccess",
"(",
"compact",
"(",
"'message'",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"jsonResponseError",
"(",
"[",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
",",
"500",
")",
";",
"}",
"}"
] |
Restore the trashed user.
@param \Arcanesoft\Contracts\Auth\Models\User $user
@return \Illuminate\Http\JsonResponse
|
[
"Restore",
"the",
"trashed",
"user",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L254-L268
|
25,475
|
ARCANESOFT/Auth
|
src/Http/Controllers/Admin/UsersController.php
|
UsersController.impersonate
|
public function impersonate(User $user, Impersonator $impersonator)
{
/** @var \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $user */
if ( ! $impersonator->start(auth()->user(), $user)) {
$this->notifyDanger(
trans('auth::users.messages.impersonation-failed.message'),
trans('auth::users.messages.impersonation-failed.title')
);
return redirect()->back();
}
return redirect()->to('/');
}
|
php
|
public function impersonate(User $user, Impersonator $impersonator)
{
/** @var \Arcanedev\LaravelImpersonator\Contracts\Impersonatable $user */
if ( ! $impersonator->start(auth()->user(), $user)) {
$this->notifyDanger(
trans('auth::users.messages.impersonation-failed.message'),
trans('auth::users.messages.impersonation-failed.title')
);
return redirect()->back();
}
return redirect()->to('/');
}
|
[
"public",
"function",
"impersonate",
"(",
"User",
"$",
"user",
",",
"Impersonator",
"$",
"impersonator",
")",
"{",
"/** @var \\Arcanedev\\LaravelImpersonator\\Contracts\\Impersonatable $user */",
"if",
"(",
"!",
"$",
"impersonator",
"->",
"start",
"(",
"auth",
"(",
")",
"->",
"user",
"(",
")",
",",
"$",
"user",
")",
")",
"{",
"$",
"this",
"->",
"notifyDanger",
"(",
"trans",
"(",
"'auth::users.messages.impersonation-failed.message'",
")",
",",
"trans",
"(",
"'auth::users.messages.impersonation-failed.title'",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"}",
"return",
"redirect",
"(",
")",
"->",
"to",
"(",
"'/'",
")",
";",
"}"
] |
Impersonate a user.
@param \Arcanesoft\Contracts\Auth\Models\User $user
@param \Arcanedev\LaravelImpersonator\Contracts\Impersonator $impersonator
@return \Illuminate\Http\RedirectResponse
|
[
"Impersonate",
"a",
"user",
"."
] |
b33ca82597a76b1e395071f71ae3e51f1ec67e62
|
https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Http/Controllers/Admin/UsersController.php#L305-L318
|
25,476
|
squareproton/Bond
|
src/Bond/Pg/Catalog.php
|
Catalog.getEnum
|
private function getEnum()
{
$enumResult = $this->db->query(
new Raw( <<<SQL
SELECT
t.typname as name,
n.nspname as schema,
array_agg( e.enumlabel ORDER BY e.enumsortorder ) as labels
FROM
pg_enum e
INNER JOIN
pg_type t ON e.enumtypid = t.oid
INNER JOIN
pg_namespace n ON t.typnamespace = n.oid
WHERE
n.nspname = ANY( current_schemas(false) )
GROUP BY
t.typname, t.oid, n.nspname
ORDER BY
schema, t.typname ASC
SQL
)
);
$output = [];
foreach( $enumResult->fetch(Result::FLATTEN_PREVENT | Result::TYPE_DETECT) as $data ) {
$output[$data['name']] = $data['labels'];
}
return new Enum($output);
}
|
php
|
private function getEnum()
{
$enumResult = $this->db->query(
new Raw( <<<SQL
SELECT
t.typname as name,
n.nspname as schema,
array_agg( e.enumlabel ORDER BY e.enumsortorder ) as labels
FROM
pg_enum e
INNER JOIN
pg_type t ON e.enumtypid = t.oid
INNER JOIN
pg_namespace n ON t.typnamespace = n.oid
WHERE
n.nspname = ANY( current_schemas(false) )
GROUP BY
t.typname, t.oid, n.nspname
ORDER BY
schema, t.typname ASC
SQL
)
);
$output = [];
foreach( $enumResult->fetch(Result::FLATTEN_PREVENT | Result::TYPE_DETECT) as $data ) {
$output[$data['name']] = $data['labels'];
}
return new Enum($output);
}
|
[
"private",
"function",
"getEnum",
"(",
")",
"{",
"$",
"enumResult",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"new",
"Raw",
"(",
" <<<SQL\n SELECT\n t.typname as name,\n n.nspname as schema,\n array_agg( e.enumlabel ORDER BY e.enumsortorder ) as labels\n FROM\n pg_enum e\n INNER JOIN\n pg_type t ON e.enumtypid = t.oid\n INNER JOIN\n pg_namespace n ON t.typnamespace = n.oid\n WHERE\n n.nspname = ANY( current_schemas(false) )\n GROUP BY\n t.typname, t.oid, n.nspname\n ORDER BY\n schema, t.typname ASC\nSQL",
")",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"enumResult",
"->",
"fetch",
"(",
"Result",
"::",
"FLATTEN_PREVENT",
"|",
"Result",
"::",
"TYPE_DETECT",
")",
"as",
"$",
"data",
")",
"{",
"$",
"output",
"[",
"$",
"data",
"[",
"'name'",
"]",
"]",
"=",
"$",
"data",
"[",
"'labels'",
"]",
";",
"}",
"return",
"new",
"Enum",
"(",
"$",
"output",
")",
";",
"}"
] |
Get array of enum's and their values from the database
@param Bond\Pg
@return array
|
[
"Get",
"array",
"of",
"enum",
"s",
"and",
"their",
"values",
"from",
"the",
"database"
] |
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
|
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg/Catalog.php#L75-L107
|
25,477
|
Sectorr/Core
|
Sectorr/Core/Input/Input.php
|
Input.exists
|
public static function exists($type = 'post')
{
switch ($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
|
php
|
public static function exists($type = 'post')
{
switch ($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
|
[
"public",
"static",
"function",
"exists",
"(",
"$",
"type",
"=",
"'post'",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'post'",
":",
"return",
"(",
"!",
"empty",
"(",
"$",
"_POST",
")",
")",
"?",
"true",
":",
"false",
";",
"break",
";",
"case",
"'get'",
":",
"return",
"(",
"!",
"empty",
"(",
"$",
"_GET",
")",
")",
"?",
"true",
":",
"false",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"break",
";",
"}",
"}"
] |
Check the given request type exists.
@param string $type
@return bool
|
[
"Check",
"the",
"given",
"request",
"type",
"exists",
"."
] |
31df852dc6cc61642b0b87d9f0ae56c8e7da5a27
|
https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Input/Input.php#L24-L37
|
25,478
|
Sectorr/Core
|
Sectorr/Core/Input/Input.php
|
Input.get
|
public static function get($item)
{
if (isset($_POST[$item])) {
return $_POST[$item];
} elseif (isset($_GET[$item])) {
return $_GET[$item];
} else {
return '';
}
}
|
php
|
public static function get($item)
{
if (isset($_POST[$item])) {
return $_POST[$item];
} elseif (isset($_GET[$item])) {
return $_GET[$item];
} else {
return '';
}
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"item",
"]",
")",
")",
"{",
"return",
"$",
"_POST",
"[",
"$",
"item",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"item",
"]",
")",
")",
"{",
"return",
"$",
"_GET",
"[",
"$",
"item",
"]",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
Returns the given input item.
@param $item
@return string
|
[
"Returns",
"the",
"given",
"input",
"item",
"."
] |
31df852dc6cc61642b0b87d9f0ae56c8e7da5a27
|
https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Input/Input.php#L45-L54
|
25,479
|
brunschgi/TerrificComposerBundle
|
Form/SkinType.php
|
SkinType.buildForm
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
global $kernel;
// get all modules
$modules = array();
$dir = $kernel->getRootDir().'/../src/Terrific/Module/';
$finder = new Finder();
$finder->directories()->in($dir)->depth('== 0');
foreach ($finder as $file) {
$filename = $file->getFilename();
$module = str_replace('Bundle', '', $filename);
$modules[$module] = $module;
}
$builder->add('module', 'choice', array(
'choices' => $modules,
'multiple' => false,
'label' => 'Skin for Module'
));
$builder->add('name', 'text');
$builder->add('style', 'choice', array(
'choices' => array('css' => 'CSS', 'less' => 'LESS'),
'multiple' => false,
'expanded' => true
));
}
|
php
|
public function buildForm(FormBuilderInterface $builder, array $options)
{
global $kernel;
// get all modules
$modules = array();
$dir = $kernel->getRootDir().'/../src/Terrific/Module/';
$finder = new Finder();
$finder->directories()->in($dir)->depth('== 0');
foreach ($finder as $file) {
$filename = $file->getFilename();
$module = str_replace('Bundle', '', $filename);
$modules[$module] = $module;
}
$builder->add('module', 'choice', array(
'choices' => $modules,
'multiple' => false,
'label' => 'Skin for Module'
));
$builder->add('name', 'text');
$builder->add('style', 'choice', array(
'choices' => array('css' => 'CSS', 'less' => 'LESS'),
'multiple' => false,
'expanded' => true
));
}
|
[
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"global",
"$",
"kernel",
";",
"// get all modules",
"$",
"modules",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"$",
"kernel",
"->",
"getRootDir",
"(",
")",
".",
"'/../src/Terrific/Module/'",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"directories",
"(",
")",
"->",
"in",
"(",
"$",
"dir",
")",
"->",
"depth",
"(",
"'== 0'",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"filename",
"=",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"$",
"module",
"=",
"str_replace",
"(",
"'Bundle'",
",",
"''",
",",
"$",
"filename",
")",
";",
"$",
"modules",
"[",
"$",
"module",
"]",
"=",
"$",
"module",
";",
"}",
"$",
"builder",
"->",
"add",
"(",
"'module'",
",",
"'choice'",
",",
"array",
"(",
"'choices'",
"=>",
"$",
"modules",
",",
"'multiple'",
"=>",
"false",
",",
"'label'",
"=>",
"'Skin for Module'",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'name'",
",",
"'text'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'style'",
",",
"'choice'",
",",
"array",
"(",
"'choices'",
"=>",
"array",
"(",
"'css'",
"=>",
"'CSS'",
",",
"'less'",
"=>",
"'LESS'",
")",
",",
"'multiple'",
"=>",
"false",
",",
"'expanded'",
"=>",
"true",
")",
")",
";",
"}"
] |
Builds the Skin form.
@param \Symfony\Component\Form\FormBuilder $builder
@param array $options
|
[
"Builds",
"the",
"Skin",
"form",
"."
] |
6eef4ace887c19ef166ab6654de385bc1ffbf5f1
|
https://github.com/brunschgi/TerrificComposerBundle/blob/6eef4ace887c19ef166ab6654de385bc1ffbf5f1/Form/SkinType.php#L29-L58
|
25,480
|
Attibee/Bumble-Shell
|
src/Arg.php
|
Arg.addOption
|
public function addOption( $opt, $type ) {
if( $type !== self::OPT_PARAM || $type !== self::OPT_SWITCH ) {
return;
}
$this->options[(string)$opt] = $type;
}
|
php
|
public function addOption( $opt, $type ) {
if( $type !== self::OPT_PARAM || $type !== self::OPT_SWITCH ) {
return;
}
$this->options[(string)$opt] = $type;
}
|
[
"public",
"function",
"addOption",
"(",
"$",
"opt",
",",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"!==",
"self",
"::",
"OPT_PARAM",
"||",
"$",
"type",
"!==",
"self",
"::",
"OPT_SWITCH",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"(",
"string",
")",
"$",
"opt",
"]",
"=",
"$",
"type",
";",
"}"
] |
Adds an option to the argument parser.
@param string $opt The name of the option.
@param string $type Args::SWITCH or Args::PARAM
|
[
"Adds",
"an",
"option",
"to",
"the",
"argument",
"parser",
"."
] |
c42da09654c0f3f5d0c81815ab69b930e1052c55
|
https://github.com/Attibee/Bumble-Shell/blob/c42da09654c0f3f5d0c81815ab69b930e1052c55/src/Arg.php#L87-L93
|
25,481
|
Attibee/Bumble-Shell
|
src/Arg.php
|
Arg.parse
|
public function parse() {
global $argv;
$options = array();
$parameters = array();
$argc = count( $argv );
$paramCount = count( $this->parameters );
//get parameters
if( $argc - 1 < $paramCount ) {
throw new \Exception("The command requires $paramCount parameters.");
}
//last items are the params
for( $i = $paramCount - 1; $i >= 0; $i-- ) {
$this->abstractParameters[$this->parameters[$i]] = $argv[$argc - $i - 1];
}
//go through each arg
for( $i = 1; $i < $argc - $paramCount; $i++ ) {
$arg = $argv[$i];
//cannot start without a switch
if( !$this->isOption( $arg ) ) {
throw new \Exception("Invalid argument \"$arg\".");
}
//check if it's a valid option
$option = $arg[1];
if( $this->isParam( $option ) ) {
//the arg stands on its own, such as -f, not -ffile.txt
//set next as its value, move $i ahead
if( $this->isSolitary( $arg ) ) {
//last item
if( $i == $argc - $paramCount - 1 ) {
throw new \Exception("Parameter does not follow the option \"$option\".");
}
$this->abstractOptions[$option] = $argv[$i+1];
$i++;
} else {
$this->abstractOptions[$option] = substr( $arg, 2 );
}
} else if( $this->isSwitch( $option ) ) {
//loop through all switches in the param
for( $i = 1; $i < strlen( $param ) - 1; $i++ ) {
$s = $arg[$i];
//not a switch
if( !$this->isSwitch( $arg[$i] ) ) {
throw new \Exception("An invalid switch \"$s\" was provided.");
}
$this->abstractOptions[$s] = true;
}
}
}
}
|
php
|
public function parse() {
global $argv;
$options = array();
$parameters = array();
$argc = count( $argv );
$paramCount = count( $this->parameters );
//get parameters
if( $argc - 1 < $paramCount ) {
throw new \Exception("The command requires $paramCount parameters.");
}
//last items are the params
for( $i = $paramCount - 1; $i >= 0; $i-- ) {
$this->abstractParameters[$this->parameters[$i]] = $argv[$argc - $i - 1];
}
//go through each arg
for( $i = 1; $i < $argc - $paramCount; $i++ ) {
$arg = $argv[$i];
//cannot start without a switch
if( !$this->isOption( $arg ) ) {
throw new \Exception("Invalid argument \"$arg\".");
}
//check if it's a valid option
$option = $arg[1];
if( $this->isParam( $option ) ) {
//the arg stands on its own, such as -f, not -ffile.txt
//set next as its value, move $i ahead
if( $this->isSolitary( $arg ) ) {
//last item
if( $i == $argc - $paramCount - 1 ) {
throw new \Exception("Parameter does not follow the option \"$option\".");
}
$this->abstractOptions[$option] = $argv[$i+1];
$i++;
} else {
$this->abstractOptions[$option] = substr( $arg, 2 );
}
} else if( $this->isSwitch( $option ) ) {
//loop through all switches in the param
for( $i = 1; $i < strlen( $param ) - 1; $i++ ) {
$s = $arg[$i];
//not a switch
if( !$this->isSwitch( $arg[$i] ) ) {
throw new \Exception("An invalid switch \"$s\" was provided.");
}
$this->abstractOptions[$s] = true;
}
}
}
}
|
[
"public",
"function",
"parse",
"(",
")",
"{",
"global",
"$",
"argv",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"parameters",
"=",
"array",
"(",
")",
";",
"$",
"argc",
"=",
"count",
"(",
"$",
"argv",
")",
";",
"$",
"paramCount",
"=",
"count",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"//get parameters",
"if",
"(",
"$",
"argc",
"-",
"1",
"<",
"$",
"paramCount",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The command requires $paramCount parameters.\"",
")",
";",
"}",
"//last items are the params",
"for",
"(",
"$",
"i",
"=",
"$",
"paramCount",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"this",
"->",
"abstractParameters",
"[",
"$",
"this",
"->",
"parameters",
"[",
"$",
"i",
"]",
"]",
"=",
"$",
"argv",
"[",
"$",
"argc",
"-",
"$",
"i",
"-",
"1",
"]",
";",
"}",
"//go through each arg",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"argc",
"-",
"$",
"paramCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"arg",
"=",
"$",
"argv",
"[",
"$",
"i",
"]",
";",
"//cannot start without a switch",
"if",
"(",
"!",
"$",
"this",
"->",
"isOption",
"(",
"$",
"arg",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Invalid argument \\\"$arg\\\".\"",
")",
";",
"}",
"//check if it's a valid option",
"$",
"option",
"=",
"$",
"arg",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isParam",
"(",
"$",
"option",
")",
")",
"{",
"//the arg stands on its own, such as -f, not -ffile.txt",
"//set next as its value, move $i ahead",
"if",
"(",
"$",
"this",
"->",
"isSolitary",
"(",
"$",
"arg",
")",
")",
"{",
"//last item",
"if",
"(",
"$",
"i",
"==",
"$",
"argc",
"-",
"$",
"paramCount",
"-",
"1",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Parameter does not follow the option \\\"$option\\\".\"",
")",
";",
"}",
"$",
"this",
"->",
"abstractOptions",
"[",
"$",
"option",
"]",
"=",
"$",
"argv",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"$",
"i",
"++",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"abstractOptions",
"[",
"$",
"option",
"]",
"=",
"substr",
"(",
"$",
"arg",
",",
"2",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"isSwitch",
"(",
"$",
"option",
")",
")",
"{",
"//loop through all switches in the param",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"param",
")",
"-",
"1",
";",
"$",
"i",
"++",
")",
"{",
"$",
"s",
"=",
"$",
"arg",
"[",
"$",
"i",
"]",
";",
"//not a switch",
"if",
"(",
"!",
"$",
"this",
"->",
"isSwitch",
"(",
"$",
"arg",
"[",
"$",
"i",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"An invalid switch \\\"$s\\\" was provided.\"",
")",
";",
"}",
"$",
"this",
"->",
"abstractOptions",
"[",
"$",
"s",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"}"
] |
Parses the parameters and throws an error if the user supplied an invalid format.
|
[
"Parses",
"the",
"parameters",
"and",
"throws",
"an",
"error",
"if",
"the",
"user",
"supplied",
"an",
"invalid",
"format",
"."
] |
c42da09654c0f3f5d0c81815ab69b930e1052c55
|
https://github.com/Attibee/Bumble-Shell/blob/c42da09654c0f3f5d0c81815ab69b930e1052c55/src/Arg.php#L118-L176
|
25,482
|
kaiohken1982/Neobazaar
|
src/Neobazaar/Entity/MappedSuperclassBase.php
|
MappedSuperclassBase.exchangeArray
|
public function exchangeArray($data)
{
foreach($data as $prop => $value) {
$methodName = 'set' . ucfirst($prop);
if(method_exists ($this, $methodName)) {
call_user_func(array($this, $methodName), $value);
}
}
}
|
php
|
public function exchangeArray($data)
{
foreach($data as $prop => $value) {
$methodName = 'set' . ucfirst($prop);
if(method_exists ($this, $methodName)) {
call_user_func(array($this, $methodName), $value);
}
}
}
|
[
"public",
"function",
"exchangeArray",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"prop",
"=>",
"$",
"value",
")",
"{",
"$",
"methodName",
"=",
"'set'",
".",
"ucfirst",
"(",
"$",
"prop",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Exchange array - used in ZF2 form
@param array $data An array of data
|
[
"Exchange",
"array",
"-",
"used",
"in",
"ZF2",
"form"
] |
288c972dea981d715c4e136edb5dba0318c9e6cb
|
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Entity/MappedSuperclassBase.php#L30-L38
|
25,483
|
kaiohken1982/NeobazaarDocumentModule
|
src/Document/Service/Image.php
|
Image.delete
|
public function delete($idOrDocument)
{
$cache = $this->getServiceLocator()->get('ClassifiedCache');
$main = $this->getServiceLocator()->get('neobazaar.service.main');
$classifiedService = $this->getServiceLocator()->get('document.service.classified');
$entityManager = $main->getEntityManager();
$documentRepository = $main->getDocumentEntityRepository();
$entity = $documentRepository->getEntity($idOrDocument);
// It can NOT exists when add a NEW classified (parent still doesn't exists)
$parent = $entity->getParent();
// checking for permission, only if we are in edit mode
if(null !== $parent && !$classifiedService->checkIfOwnerOrAdmin($parent)) {
throw new \Exception('Non possiedi i permessi per agire su questo documento');
}
$cacheKey = $parent ? $documentRepository->getEncryptedId($parent->getDocumentId()) : 'noCache';
$imageModel = new ImageModel($entity, $this->getServiceLocator());
// 1) Delete the image
$phisical = $imageModel->deleteImages();
// 3) Remove the document
$entityManager->remove($entity);
$entityManager->flush();
// 4) Remove parent classified cache
if($cache->hasItem($cacheKey)) {
$cache->removeItem($cacheKey);
}
return $phisical;
}
|
php
|
public function delete($idOrDocument)
{
$cache = $this->getServiceLocator()->get('ClassifiedCache');
$main = $this->getServiceLocator()->get('neobazaar.service.main');
$classifiedService = $this->getServiceLocator()->get('document.service.classified');
$entityManager = $main->getEntityManager();
$documentRepository = $main->getDocumentEntityRepository();
$entity = $documentRepository->getEntity($idOrDocument);
// It can NOT exists when add a NEW classified (parent still doesn't exists)
$parent = $entity->getParent();
// checking for permission, only if we are in edit mode
if(null !== $parent && !$classifiedService->checkIfOwnerOrAdmin($parent)) {
throw new \Exception('Non possiedi i permessi per agire su questo documento');
}
$cacheKey = $parent ? $documentRepository->getEncryptedId($parent->getDocumentId()) : 'noCache';
$imageModel = new ImageModel($entity, $this->getServiceLocator());
// 1) Delete the image
$phisical = $imageModel->deleteImages();
// 3) Remove the document
$entityManager->remove($entity);
$entityManager->flush();
// 4) Remove parent classified cache
if($cache->hasItem($cacheKey)) {
$cache->removeItem($cacheKey);
}
return $phisical;
}
|
[
"public",
"function",
"delete",
"(",
"$",
"idOrDocument",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ClassifiedCache'",
")",
";",
"$",
"main",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'neobazaar.service.main'",
")",
";",
"$",
"classifiedService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'document.service.classified'",
")",
";",
"$",
"entityManager",
"=",
"$",
"main",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"documentRepository",
"=",
"$",
"main",
"->",
"getDocumentEntityRepository",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"documentRepository",
"->",
"getEntity",
"(",
"$",
"idOrDocument",
")",
";",
"// It can NOT exists when add a NEW classified (parent still doesn't exists)",
"$",
"parent",
"=",
"$",
"entity",
"->",
"getParent",
"(",
")",
";",
"// checking for permission, only if we are in edit mode",
"if",
"(",
"null",
"!==",
"$",
"parent",
"&&",
"!",
"$",
"classifiedService",
"->",
"checkIfOwnerOrAdmin",
"(",
"$",
"parent",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Non possiedi i permessi per agire su questo documento'",
")",
";",
"}",
"$",
"cacheKey",
"=",
"$",
"parent",
"?",
"$",
"documentRepository",
"->",
"getEncryptedId",
"(",
"$",
"parent",
"->",
"getDocumentId",
"(",
")",
")",
":",
"'noCache'",
";",
"$",
"imageModel",
"=",
"new",
"ImageModel",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
")",
";",
"// 1) Delete the image",
"$",
"phisical",
"=",
"$",
"imageModel",
"->",
"deleteImages",
"(",
")",
";",
"// 3) Remove the document",
"$",
"entityManager",
"->",
"remove",
"(",
"$",
"entity",
")",
";",
"$",
"entityManager",
"->",
"flush",
"(",
")",
";",
"// 4) Remove parent classified cache",
"if",
"(",
"$",
"cache",
"->",
"hasItem",
"(",
"$",
"cacheKey",
")",
")",
"{",
"$",
"cache",
"->",
"removeItem",
"(",
"$",
"cacheKey",
")",
";",
"}",
"return",
"$",
"phisical",
";",
"}"
] |
Delete an image document and related images.
If there is a parent delete its cache.
@param unknown $idOrDocument
@throws \Exception
@return boolean
|
[
"Delete",
"an",
"image",
"document",
"and",
"related",
"images",
".",
"If",
"there",
"is",
"a",
"parent",
"delete",
"its",
"cache",
"."
] |
edb0223878fe02e791d2a0266c5a7c0f2029e3fe
|
https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Service/Image.php#L147-L179
|
25,484
|
stubbles/stubbles-dbal
|
src/main/php/pdo/PdoDatabaseConnection.php
|
PdoDatabaseConnection.connect
|
public function connect(): DatabaseConnection
{
if (null !== $this->pdo) {
return $this;
}
try {
$pdoCreator = $this->getPdoCreator();
$this->pdo = $pdoCreator($this->configuration);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
if ($this->configuration->hasInitialQuery()) {
$this->pdo->query($this->configuration->getInitialQuery());
}
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
return $this;
}
|
php
|
public function connect(): DatabaseConnection
{
if (null !== $this->pdo) {
return $this;
}
try {
$pdoCreator = $this->getPdoCreator();
$this->pdo = $pdoCreator($this->configuration);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
if ($this->configuration->hasInitialQuery()) {
$this->pdo->query($this->configuration->getInitialQuery());
}
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
return $this;
}
|
[
"public",
"function",
"connect",
"(",
")",
":",
"DatabaseConnection",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"pdo",
")",
"{",
"return",
"$",
"this",
";",
"}",
"try",
"{",
"$",
"pdoCreator",
"=",
"$",
"this",
"->",
"getPdoCreator",
"(",
")",
";",
"$",
"this",
"->",
"pdo",
"=",
"$",
"pdoCreator",
"(",
"$",
"this",
"->",
"configuration",
")",
";",
"$",
"this",
"->",
"pdo",
"->",
"setAttribute",
"(",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"$",
"this",
"->",
"pdo",
"->",
"setAttribute",
"(",
"PDO",
"::",
"ATTR_DEFAULT_FETCH_MODE",
",",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"hasInitialQuery",
"(",
")",
")",
"{",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getInitialQuery",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"PDOException",
"$",
"pdoe",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"$",
"pdoe",
"->",
"getMessage",
"(",
")",
",",
"$",
"pdoe",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
establishes the connection
@return \stubbles\db\pdo\PdoDatabaseConnection
@throws \stubbles\db\DatabaseException
|
[
"establishes",
"the",
"connection"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoDatabaseConnection.php#L105-L124
|
25,485
|
stubbles/stubbles-dbal
|
src/main/php/pdo/PdoDatabaseConnection.php
|
PdoDatabaseConnection.prepare
|
public function prepare(string $statement, array $driverOptions = []): Statement
{
if (null === $this->pdo) {
$this->connect();
}
try {
return new PdoStatement(
$this->pdo->prepare($statement, $driverOptions)
);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
php
|
public function prepare(string $statement, array $driverOptions = []): Statement
{
if (null === $this->pdo) {
$this->connect();
}
try {
return new PdoStatement(
$this->pdo->prepare($statement, $driverOptions)
);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
[
"public",
"function",
"prepare",
"(",
"string",
"$",
"statement",
",",
"array",
"$",
"driverOptions",
"=",
"[",
"]",
")",
":",
"Statement",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"pdo",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"try",
"{",
"return",
"new",
"PdoStatement",
"(",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"statement",
",",
"$",
"driverOptions",
")",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pdoe",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"$",
"pdoe",
"->",
"getMessage",
"(",
")",
",",
"$",
"pdoe",
")",
";",
"}",
"}"
] |
creates a prepared statement
@param string $statement SQL statement
@param array $driverOptions optional one or more key=>value pairs to set attribute values for the Statement object
@return \stubbles\db\pdo\PdoStatement
@throws \stubbles\db\DatabaseException
@see http://php.net/pdo-prepare
|
[
"creates",
"a",
"prepared",
"statement"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoDatabaseConnection.php#L230-L243
|
25,486
|
stubbles/stubbles-dbal
|
src/main/php/pdo/PdoDatabaseConnection.php
|
PdoDatabaseConnection.query
|
public function query(string $sql, array $driverOptions = []): QueryResult
{
if (null === $this->pdo) {
$this->connect();
}
try {
if (!isset($driverOptions['fetchMode'])) {
return new PdoQueryResult($this->pdo->query($sql));
}
switch ($driverOptions['fetchMode']) {
case PDO::FETCH_COLUMN:
if (!isset($driverOptions['colNo'])) {
throw new \InvalidArgumentException(
'Fetch mode COLUMN requires driver option colNo.'
);
}
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode'],
$driverOptions['colNo']
);
break;
case PDO::FETCH_INTO:
if (!isset($driverOptions['object'])) {
throw new \InvalidArgumentException(
'Fetch mode INTO requires driver option object.'
);
}
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode'],
$driverOptions['object']
);
break;
case PDO::FETCH_CLASS:
if (!isset($driverOptions['classname'])) {
throw new \InvalidArgumentException(
'Fetch mode CLASS requires driver option classname.'
);
}
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode'],
$driverOptions['classname'],
$driverOptions['ctorargs'] ?? []
);
break;
default:
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode']
);
}
return new PdoQueryResult($pdoStatement);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
php
|
public function query(string $sql, array $driverOptions = []): QueryResult
{
if (null === $this->pdo) {
$this->connect();
}
try {
if (!isset($driverOptions['fetchMode'])) {
return new PdoQueryResult($this->pdo->query($sql));
}
switch ($driverOptions['fetchMode']) {
case PDO::FETCH_COLUMN:
if (!isset($driverOptions['colNo'])) {
throw new \InvalidArgumentException(
'Fetch mode COLUMN requires driver option colNo.'
);
}
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode'],
$driverOptions['colNo']
);
break;
case PDO::FETCH_INTO:
if (!isset($driverOptions['object'])) {
throw new \InvalidArgumentException(
'Fetch mode INTO requires driver option object.'
);
}
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode'],
$driverOptions['object']
);
break;
case PDO::FETCH_CLASS:
if (!isset($driverOptions['classname'])) {
throw new \InvalidArgumentException(
'Fetch mode CLASS requires driver option classname.'
);
}
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode'],
$driverOptions['classname'],
$driverOptions['ctorargs'] ?? []
);
break;
default:
$pdoStatement = $this->pdo->query(
$sql,
$driverOptions['fetchMode']
);
}
return new PdoQueryResult($pdoStatement);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
[
"public",
"function",
"query",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"driverOptions",
"=",
"[",
"]",
")",
":",
"QueryResult",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"pdo",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"try",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"driverOptions",
"[",
"'fetchMode'",
"]",
")",
")",
"{",
"return",
"new",
"PdoQueryResult",
"(",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
")",
")",
";",
"}",
"switch",
"(",
"$",
"driverOptions",
"[",
"'fetchMode'",
"]",
")",
"{",
"case",
"PDO",
"::",
"FETCH_COLUMN",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"driverOptions",
"[",
"'colNo'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Fetch mode COLUMN requires driver option colNo.'",
")",
";",
"}",
"$",
"pdoStatement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
",",
"$",
"driverOptions",
"[",
"'fetchMode'",
"]",
",",
"$",
"driverOptions",
"[",
"'colNo'",
"]",
")",
";",
"break",
";",
"case",
"PDO",
"::",
"FETCH_INTO",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"driverOptions",
"[",
"'object'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Fetch mode INTO requires driver option object.'",
")",
";",
"}",
"$",
"pdoStatement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
",",
"$",
"driverOptions",
"[",
"'fetchMode'",
"]",
",",
"$",
"driverOptions",
"[",
"'object'",
"]",
")",
";",
"break",
";",
"case",
"PDO",
"::",
"FETCH_CLASS",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"driverOptions",
"[",
"'classname'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Fetch mode CLASS requires driver option classname.'",
")",
";",
"}",
"$",
"pdoStatement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
",",
"$",
"driverOptions",
"[",
"'fetchMode'",
"]",
",",
"$",
"driverOptions",
"[",
"'classname'",
"]",
",",
"$",
"driverOptions",
"[",
"'ctorargs'",
"]",
"??",
"[",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"pdoStatement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
",",
"$",
"driverOptions",
"[",
"'fetchMode'",
"]",
")",
";",
"}",
"return",
"new",
"PdoQueryResult",
"(",
"$",
"pdoStatement",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pdoe",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"$",
"pdoe",
"->",
"getMessage",
"(",
")",
",",
"$",
"pdoe",
")",
";",
"}",
"}"
] |
executes a SQL statement
The driver options can be:
<code>
fetchMode => one of the PDO::FETCH_* constants
colNo => if fetchMode == PDO::FETCH_COLUMN this denotes the column number to fetch
object => if fetchMode == PDO::FETCH_INTO this denotes the object to fetch the data into
classname => if fetchMode == PDO::FETCH_CLASS this denotes the class to create and fetch the data into
ctorargs => (optional) if fetchMode == PDO::FETCH_CLASS this denotes the list of arguments for the constructor of the class to create and fetch the data into
</code>
@param string $sql the sql query to use
@param array $driverOptions optional how to fetch the data
@return \stubbles\db\pdo\PdoQueryResult
@throws \stubbles\db\DatabaseException
@throws \InvalidArgumentException
@see http://php.net/pdo-query
@see http://php.net/pdostatement-setfetchmode for the details on the fetch mode options
|
[
"executes",
"a",
"SQL",
"statement"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoDatabaseConnection.php#L265-L331
|
25,487
|
stubbles/stubbles-dbal
|
src/main/php/pdo/PdoDatabaseConnection.php
|
PdoDatabaseConnection.exec
|
public function exec(string $statement): int
{
if (null === $this->pdo) {
$this->connect();
}
try {
return $this->pdo->exec($statement);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
php
|
public function exec(string $statement): int
{
if (null === $this->pdo) {
$this->connect();
}
try {
return $this->pdo->exec($statement);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
[
"public",
"function",
"exec",
"(",
"string",
"$",
"statement",
")",
":",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"pdo",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"pdo",
"->",
"exec",
"(",
"$",
"statement",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pdoe",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"$",
"pdoe",
"->",
"getMessage",
"(",
")",
",",
"$",
"pdoe",
")",
";",
"}",
"}"
] |
execute an SQL statement and return the number of affected rows
@param string $statement the sql statement to execute d
@return int number of effected rows
@throws \stubbles\db\DatabaseException
|
[
"execute",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"number",
"of",
"affected",
"rows"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoDatabaseConnection.php#L340-L351
|
25,488
|
stubbles/stubbles-dbal
|
src/main/php/pdo/PdoDatabaseConnection.php
|
PdoDatabaseConnection.getLastInsertId
|
public function getLastInsertId(string $name = null)
{
if (null === $this->pdo) {
throw new DatabaseException('Not connected: can not retrieve last insert id');
}
try {
return $this->pdo->lastInsertId($name);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
php
|
public function getLastInsertId(string $name = null)
{
if (null === $this->pdo) {
throw new DatabaseException('Not connected: can not retrieve last insert id');
}
try {
return $this->pdo->lastInsertId($name);
} catch (PDOException $pdoe) {
throw new DatabaseException($pdoe->getMessage(), $pdoe);
}
}
|
[
"public",
"function",
"getLastInsertId",
"(",
"string",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"pdo",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"'Not connected: can not retrieve last insert id'",
")",
";",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"pdo",
"->",
"lastInsertId",
"(",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pdoe",
")",
"{",
"throw",
"new",
"DatabaseException",
"(",
"$",
"pdoe",
"->",
"getMessage",
"(",
")",
",",
"$",
"pdoe",
")",
";",
"}",
"}"
] |
returns the last insert id
@param string $name name of the sequence object from which the ID should be returned.
@return int
@throws \stubbles\db\DatabaseException
|
[
"returns",
"the",
"last",
"insert",
"id"
] |
b42a589025a9e511b40a2798ac84df94d6451c36
|
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoDatabaseConnection.php#L360-L371
|
25,489
|
AnonymPHP/Anonym-HttpFoundation
|
Server.php
|
Server.get
|
public function get($name = 'HTTP_HOST')
{
$name = isset($this->references[$name]) ? $this->references[$name]: $this->resolveCase($name);
return $this->has($name) ? $_SERVER[$name] : false;
}
|
php
|
public function get($name = 'HTTP_HOST')
{
$name = isset($this->references[$name]) ? $this->references[$name]: $this->resolveCase($name);
return $this->has($name) ? $_SERVER[$name] : false;
}
|
[
"public",
"function",
"get",
"(",
"$",
"name",
"=",
"'HTTP_HOST'",
")",
"{",
"$",
"name",
"=",
"isset",
"(",
"$",
"this",
"->",
"references",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"references",
"[",
"$",
"name",
"]",
":",
"$",
"this",
"->",
"resolveCase",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
"?",
"$",
"_SERVER",
"[",
"$",
"name",
"]",
":",
"false",
";",
"}"
] |
get the variable in server
@param string $name
@return string
|
[
"get",
"the",
"variable",
"in",
"server"
] |
943e5f40f45bc2e11a4b9e1d22c6583c31dc4317
|
https://github.com/AnonymPHP/Anonym-HttpFoundation/blob/943e5f40f45bc2e11a4b9e1d22c6583c31dc4317/Server.php#L46-L51
|
25,490
|
Wedeto/IO
|
src/Path.php
|
Path.rmtree
|
public static function rmtree(string $path)
{
$path = self::realpath($path);
if (empty($path)) // File/dir does not exist
return true;
if (empty(self::$required_prefix))
throw new \RuntimeException("Safety measure: required prefix needs to be set before running rmtree");
if (strpos($path, self::$required_prefix) !== 0)
throw new \RuntimeException("Refusing to remove directory outside " . self::$required_prefix);
self::checkWrite($path);
if (!is_dir($path))
return unlink($path) ? 1 : 0;
$cnt = 0;
$d = \dir($path);
while (($entry = $d->read()) !== false)
{
if ($entry === "." || $entry === "..")
continue;
$entry = $path . '/' . $entry;
self::checkWrite($entry);
if (is_dir($entry))
$cnt += self::rmtree($entry);
else
$cnt += (unlink($entry) ? 1 : 0);
}
rmdir($path);
return $cnt + 1;
}
|
php
|
public static function rmtree(string $path)
{
$path = self::realpath($path);
if (empty($path)) // File/dir does not exist
return true;
if (empty(self::$required_prefix))
throw new \RuntimeException("Safety measure: required prefix needs to be set before running rmtree");
if (strpos($path, self::$required_prefix) !== 0)
throw new \RuntimeException("Refusing to remove directory outside " . self::$required_prefix);
self::checkWrite($path);
if (!is_dir($path))
return unlink($path) ? 1 : 0;
$cnt = 0;
$d = \dir($path);
while (($entry = $d->read()) !== false)
{
if ($entry === "." || $entry === "..")
continue;
$entry = $path . '/' . $entry;
self::checkWrite($entry);
if (is_dir($entry))
$cnt += self::rmtree($entry);
else
$cnt += (unlink($entry) ? 1 : 0);
}
rmdir($path);
return $cnt + 1;
}
|
[
"public",
"static",
"function",
"rmtree",
"(",
"string",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"self",
"::",
"realpath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"// File/dir does not exist",
"return",
"true",
";",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"required_prefix",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Safety measure: required prefix needs to be set before running rmtree\"",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"self",
"::",
"$",
"required_prefix",
")",
"!==",
"0",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Refusing to remove directory outside \"",
".",
"self",
"::",
"$",
"required_prefix",
")",
";",
"self",
"::",
"checkWrite",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"return",
"unlink",
"(",
"$",
"path",
")",
"?",
"1",
":",
"0",
";",
"$",
"cnt",
"=",
"0",
";",
"$",
"d",
"=",
"\\",
"dir",
"(",
"$",
"path",
")",
";",
"while",
"(",
"(",
"$",
"entry",
"=",
"$",
"d",
"->",
"read",
"(",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"entry",
"===",
"\".\"",
"||",
"$",
"entry",
"===",
"\"..\"",
")",
"continue",
";",
"$",
"entry",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"entry",
";",
"self",
"::",
"checkWrite",
"(",
"$",
"entry",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"entry",
")",
")",
"$",
"cnt",
"+=",
"self",
"::",
"rmtree",
"(",
"$",
"entry",
")",
";",
"else",
"$",
"cnt",
"+=",
"(",
"unlink",
"(",
"$",
"entry",
")",
"?",
"1",
":",
"0",
")",
";",
"}",
"rmdir",
"(",
"$",
"path",
")",
";",
"return",
"$",
"cnt",
"+",
"1",
";",
"}"
] |
Delete a directory and its contents. The provided path must be inside the configured prefix.
@param $path string The path to remove
@return int Amount of files and directories that have been deleted
|
[
"Delete",
"a",
"directory",
"and",
"its",
"contents",
".",
"The",
"provided",
"path",
"must",
"be",
"inside",
"the",
"configured",
"prefix",
"."
] |
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
|
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/Path.php#L159-L194
|
25,491
|
Wedeto/IO
|
src/Path.php
|
Path.getPermissions
|
public static function getPermissions($path)
{
try
{
$mode = @fileperms($path);
if ($mode === false)
throw new IOException();
}
catch (Throwable $e)
{
throw new IOException("Could not stat: " . $path);
}
$perms = array(
'owner' => array(
'read' => (bool)($mode & 0x0100),
'write' => (bool)($mode & 0x0080),
'execute' => (bool)($mode & 0x0040)
),
'group' => array(
'read' => (bool)($mode & 0x0020),
'write' => (bool)($mode & 0x0010),
'execute' => (bool)($mode & 0x0008)
),
'world' => array(
'read' => (bool)($mode & 0x0004),
'write' => (bool)($mode & 0x0002),
'execute' => (bool)($mode & 0x0001)
)
);
$perms['mode'] = self::compileMode($perms);
return $perms;
}
|
php
|
public static function getPermissions($path)
{
try
{
$mode = @fileperms($path);
if ($mode === false)
throw new IOException();
}
catch (Throwable $e)
{
throw new IOException("Could not stat: " . $path);
}
$perms = array(
'owner' => array(
'read' => (bool)($mode & 0x0100),
'write' => (bool)($mode & 0x0080),
'execute' => (bool)($mode & 0x0040)
),
'group' => array(
'read' => (bool)($mode & 0x0020),
'write' => (bool)($mode & 0x0010),
'execute' => (bool)($mode & 0x0008)
),
'world' => array(
'read' => (bool)($mode & 0x0004),
'write' => (bool)($mode & 0x0002),
'execute' => (bool)($mode & 0x0001)
)
);
$perms['mode'] = self::compileMode($perms);
return $perms;
}
|
[
"public",
"static",
"function",
"getPermissions",
"(",
"$",
"path",
")",
"{",
"try",
"{",
"$",
"mode",
"=",
"@",
"fileperms",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"mode",
"===",
"false",
")",
"throw",
"new",
"IOException",
"(",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not stat: \"",
".",
"$",
"path",
")",
";",
"}",
"$",
"perms",
"=",
"array",
"(",
"'owner'",
"=>",
"array",
"(",
"'read'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0100",
")",
",",
"'write'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0080",
")",
",",
"'execute'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0040",
")",
")",
",",
"'group'",
"=>",
"array",
"(",
"'read'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0020",
")",
",",
"'write'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0010",
")",
",",
"'execute'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0008",
")",
")",
",",
"'world'",
"=>",
"array",
"(",
"'read'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0004",
")",
",",
"'write'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0002",
")",
",",
"'execute'",
"=>",
"(",
"bool",
")",
"(",
"$",
"mode",
"&",
"0x0001",
")",
")",
")",
";",
"$",
"perms",
"[",
"'mode'",
"]",
"=",
"self",
"::",
"compileMode",
"(",
"$",
"perms",
")",
";",
"return",
"$",
"perms",
";",
"}"
] |
Return the permissions set on the specified file.
@param string $path The path to examine
@return array An associative array containing 'owner', 'group' and 'world',
members, each containing 'read', 'write' and 'execute'
indicating their permissions.
|
[
"Return",
"the",
"permissions",
"set",
"on",
"the",
"specified",
"file",
"."
] |
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
|
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/Path.php#L279-L312
|
25,492
|
Wedeto/IO
|
src/Path.php
|
Path.compileMode
|
public static function compileMode(array $perms)
{
$fmode = 0;
$fmode |= !empty($perms['owner']['read']) ? self::OWNER_READ : 0;
$fmode |= !empty($perms['owner']['write']) ? self::OWNER_WRITE : 0;
$fmode |= !empty($perms['owner']['execute']) ? self::OWNER_EXECUTE : 0;
$fmode |= !empty($perms['group']['read']) ? self::GROUP_READ : 0;
$fmode |= !empty($perms['group']['write']) ? self::GROUP_WRITE : 0;
$fmode |= !empty($perms['group']['execute']) ? self::GROUP_EXECUTE : 0;
$fmode |= !empty($perms['world']['read']) ? self::WORLD_READ : 0;
$fmode |= !empty($perms['world']['write']) ? self::WORLD_WRITE : 0;
$fmode |= !empty($perms['world']['execute']) ? self::WORLD_EXECUTE : 0;
return $fmode;
}
|
php
|
public static function compileMode(array $perms)
{
$fmode = 0;
$fmode |= !empty($perms['owner']['read']) ? self::OWNER_READ : 0;
$fmode |= !empty($perms['owner']['write']) ? self::OWNER_WRITE : 0;
$fmode |= !empty($perms['owner']['execute']) ? self::OWNER_EXECUTE : 0;
$fmode |= !empty($perms['group']['read']) ? self::GROUP_READ : 0;
$fmode |= !empty($perms['group']['write']) ? self::GROUP_WRITE : 0;
$fmode |= !empty($perms['group']['execute']) ? self::GROUP_EXECUTE : 0;
$fmode |= !empty($perms['world']['read']) ? self::WORLD_READ : 0;
$fmode |= !empty($perms['world']['write']) ? self::WORLD_WRITE : 0;
$fmode |= !empty($perms['world']['execute']) ? self::WORLD_EXECUTE : 0;
return $fmode;
}
|
[
"public",
"static",
"function",
"compileMode",
"(",
"array",
"$",
"perms",
")",
"{",
"$",
"fmode",
"=",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'owner'",
"]",
"[",
"'read'",
"]",
")",
"?",
"self",
"::",
"OWNER_READ",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'owner'",
"]",
"[",
"'write'",
"]",
")",
"?",
"self",
"::",
"OWNER_WRITE",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'owner'",
"]",
"[",
"'execute'",
"]",
")",
"?",
"self",
"::",
"OWNER_EXECUTE",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'group'",
"]",
"[",
"'read'",
"]",
")",
"?",
"self",
"::",
"GROUP_READ",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'group'",
"]",
"[",
"'write'",
"]",
")",
"?",
"self",
"::",
"GROUP_WRITE",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'group'",
"]",
"[",
"'execute'",
"]",
")",
"?",
"self",
"::",
"GROUP_EXECUTE",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'world'",
"]",
"[",
"'read'",
"]",
")",
"?",
"self",
"::",
"WORLD_READ",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'world'",
"]",
"[",
"'write'",
"]",
")",
"?",
"self",
"::",
"WORLD_WRITE",
":",
"0",
";",
"$",
"fmode",
"|=",
"!",
"empty",
"(",
"$",
"perms",
"[",
"'world'",
"]",
"[",
"'execute'",
"]",
")",
"?",
"self",
"::",
"WORLD_EXECUTE",
":",
"0",
";",
"return",
"$",
"fmode",
";",
"}"
] |
Create a file mode from an array containing permissions. The array
can have 'owner', 'group' and 'world' members, each which can have
'read', 'write', and 'execute' booleans that indicate whether that
permission is present or not.
|
[
"Create",
"a",
"file",
"mode",
"from",
"an",
"array",
"containing",
"permissions",
".",
"The",
"array",
"can",
"have",
"owner",
"group",
"and",
"world",
"members",
"each",
"which",
"can",
"have",
"read",
"write",
"and",
"execute",
"booleans",
"that",
"indicate",
"whether",
"that",
"permission",
"is",
"present",
"or",
"not",
"."
] |
4cfeaedd1bd9bda3097d18cb12233a4afecb2e85
|
https://github.com/Wedeto/IO/blob/4cfeaedd1bd9bda3097d18cb12233a4afecb2e85/src/Path.php#L320-L336
|
25,493
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/filters/CmsFilterer.php
|
CmsFilterer.menu
|
protected function menu()
{
$this->Benchmark->start('getMenu');
try {
$menu = $this->CMSNavItemService->getMenu();
} catch (Exception $e) {
return '';
}
$this->Benchmark->end('getMenu');
$this->Benchmark->start('buildMenu');
$dom_id = $this->getParameter('id');
$dom_class = $this->getParameter('class');
$this->matchedCurrentURI = false;
$root_options = array();
if (!empty($dom_id))
$root_options[] = "id='{$dom_id}'";
if (!empty($dom_class))
$root_options[] = "class='{$dom_class}'";
$family_tree = "<ul " . join(' ', $root_options). ">\n";
$this->requestURI = ltrim($this->Request->getAdjustedRequestURI(), '/');
foreach ( $menu as $parent ) {
$family_tree .= $this->_buildMenuTree($parent, "parent", "<span>%s</span>", true);
}
$family_tree .= "</ul>\n";
$this->Benchmark->end('buildMenu');
return $family_tree;
}
|
php
|
protected function menu()
{
$this->Benchmark->start('getMenu');
try {
$menu = $this->CMSNavItemService->getMenu();
} catch (Exception $e) {
return '';
}
$this->Benchmark->end('getMenu');
$this->Benchmark->start('buildMenu');
$dom_id = $this->getParameter('id');
$dom_class = $this->getParameter('class');
$this->matchedCurrentURI = false;
$root_options = array();
if (!empty($dom_id))
$root_options[] = "id='{$dom_id}'";
if (!empty($dom_class))
$root_options[] = "class='{$dom_class}'";
$family_tree = "<ul " . join(' ', $root_options). ">\n";
$this->requestURI = ltrim($this->Request->getAdjustedRequestURI(), '/');
foreach ( $menu as $parent ) {
$family_tree .= $this->_buildMenuTree($parent, "parent", "<span>%s</span>", true);
}
$family_tree .= "</ul>\n";
$this->Benchmark->end('buildMenu');
return $family_tree;
}
|
[
"protected",
"function",
"menu",
"(",
")",
"{",
"$",
"this",
"->",
"Benchmark",
"->",
"start",
"(",
"'getMenu'",
")",
";",
"try",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"CMSNavItemService",
"->",
"getMenu",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"''",
";",
"}",
"$",
"this",
"->",
"Benchmark",
"->",
"end",
"(",
"'getMenu'",
")",
";",
"$",
"this",
"->",
"Benchmark",
"->",
"start",
"(",
"'buildMenu'",
")",
";",
"$",
"dom_id",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'id'",
")",
";",
"$",
"dom_class",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'class'",
")",
";",
"$",
"this",
"->",
"matchedCurrentURI",
"=",
"false",
";",
"$",
"root_options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dom_id",
")",
")",
"$",
"root_options",
"[",
"]",
"=",
"\"id='{$dom_id}'\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dom_class",
")",
")",
"$",
"root_options",
"[",
"]",
"=",
"\"class='{$dom_class}'\"",
";",
"$",
"family_tree",
"=",
"\"<ul \"",
".",
"join",
"(",
"' '",
",",
"$",
"root_options",
")",
".",
"\">\\n\"",
";",
"$",
"this",
"->",
"requestURI",
"=",
"ltrim",
"(",
"$",
"this",
"->",
"Request",
"->",
"getAdjustedRequestURI",
"(",
")",
",",
"'/'",
")",
";",
"foreach",
"(",
"$",
"menu",
"as",
"$",
"parent",
")",
"{",
"$",
"family_tree",
".=",
"$",
"this",
"->",
"_buildMenuTree",
"(",
"$",
"parent",
",",
"\"parent\"",
",",
"\"<span>%s</span>\"",
",",
"true",
")",
";",
"}",
"$",
"family_tree",
".=",
"\"</ul>\\n\"",
";",
"$",
"this",
"->",
"Benchmark",
"->",
"end",
"(",
"'buildMenu'",
")",
";",
"return",
"$",
"family_tree",
";",
"}"
] |
Returns a full HTML rendering of the CMS navigation menu
@return string
|
[
"Returns",
"a",
"full",
"HTML",
"rendering",
"of",
"the",
"CMS",
"navigation",
"menu"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/CmsFilterer.php#L135-L170
|
25,494
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/filters/CmsFilterer.php
|
CmsFilterer.lookupElementsForNav
|
protected function lookupElementsForNav($element_or_aspect)
{
$results = array();
if (substr($element_or_aspect, 0, 1) == '@') {
$elements = $this->ElementService->findAllWithAspect(substr($element_or_aspect, 1));
foreach ( $elements as $element ) {
$results[] = array('Name' => $element->Name, 'URI' => $element->Slug);
}
} else {
// Assume it's an element slug
$element = $this->ElementService->getBySlug($element_or_aspect);
$results[] = array('Name' => $element->Name, 'URI' => $element->Slug);
}
return $results;
}
|
php
|
protected function lookupElementsForNav($element_or_aspect)
{
$results = array();
if (substr($element_or_aspect, 0, 1) == '@') {
$elements = $this->ElementService->findAllWithAspect(substr($element_or_aspect, 1));
foreach ( $elements as $element ) {
$results[] = array('Name' => $element->Name, 'URI' => $element->Slug);
}
} else {
// Assume it's an element slug
$element = $this->ElementService->getBySlug($element_or_aspect);
$results[] = array('Name' => $element->Name, 'URI' => $element->Slug);
}
return $results;
}
|
[
"protected",
"function",
"lookupElementsForNav",
"(",
"$",
"element_or_aspect",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"element_or_aspect",
",",
"0",
",",
"1",
")",
"==",
"'@'",
")",
"{",
"$",
"elements",
"=",
"$",
"this",
"->",
"ElementService",
"->",
"findAllWithAspect",
"(",
"substr",
"(",
"$",
"element_or_aspect",
",",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"array",
"(",
"'Name'",
"=>",
"$",
"element",
"->",
"Name",
",",
"'URI'",
"=>",
"$",
"element",
"->",
"Slug",
")",
";",
"}",
"}",
"else",
"{",
"// Assume it's an element slug",
"$",
"element",
"=",
"$",
"this",
"->",
"ElementService",
"->",
"getBySlug",
"(",
"$",
"element_or_aspect",
")",
";",
"$",
"results",
"[",
"]",
"=",
"array",
"(",
"'Name'",
"=>",
"$",
"element",
"->",
"Name",
",",
"'URI'",
"=>",
"$",
"element",
"->",
"Slug",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
REturns all the elements for the specified element or aspect
@param string $element_or_aspect The element or aspect to lookup
@return array
|
[
"REturns",
"all",
"the",
"elements",
"for",
"the",
"specified",
"element",
"or",
"aspect"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/CmsFilterer.php#L275-L291
|
25,495
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/filters/CmsFilterer.php
|
CmsFilterer.sortingLink
|
public function sortingLink()
{
$filterlist = '';
if ($this->getParameter('filter') != null) {
foreach ($this->getParameter('filter') as $get => $value) {
$filterlist .= 'filter['.$get.'][]='.$value.'&';
}
}
if ($this->getParameter('sort') != null) {
$sort = $this->getParameter('sort');
} else {
$sort = array();
}
if (!empty($sort[$this->getParameter('field')])) {
if ($sort[$this->getParameter('field')] == 'ASC') {
return $filterlist.'sort['.$this->getParameter('field').']=DESC';
} else {
return $filterlist.'sort['.$this->getParameter('field').']=ASC';
}
}
return $filterlist.'sort['.$this->getParameter('field').']='.$this->getParameter('order');
}
|
php
|
public function sortingLink()
{
$filterlist = '';
if ($this->getParameter('filter') != null) {
foreach ($this->getParameter('filter') as $get => $value) {
$filterlist .= 'filter['.$get.'][]='.$value.'&';
}
}
if ($this->getParameter('sort') != null) {
$sort = $this->getParameter('sort');
} else {
$sort = array();
}
if (!empty($sort[$this->getParameter('field')])) {
if ($sort[$this->getParameter('field')] == 'ASC') {
return $filterlist.'sort['.$this->getParameter('field').']=DESC';
} else {
return $filterlist.'sort['.$this->getParameter('field').']=ASC';
}
}
return $filterlist.'sort['.$this->getParameter('field').']='.$this->getParameter('order');
}
|
[
"public",
"function",
"sortingLink",
"(",
")",
"{",
"$",
"filterlist",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'filter'",
")",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'filter'",
")",
"as",
"$",
"get",
"=>",
"$",
"value",
")",
"{",
"$",
"filterlist",
".=",
"'filter['",
".",
"$",
"get",
".",
"'][]='",
".",
"$",
"value",
".",
"'&'",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'sort'",
")",
"!=",
"null",
")",
"{",
"$",
"sort",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'sort'",
")",
";",
"}",
"else",
"{",
"$",
"sort",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"sort",
"[",
"$",
"this",
"->",
"getParameter",
"(",
"'field'",
")",
"]",
")",
")",
"{",
"if",
"(",
"$",
"sort",
"[",
"$",
"this",
"->",
"getParameter",
"(",
"'field'",
")",
"]",
"==",
"'ASC'",
")",
"{",
"return",
"$",
"filterlist",
".",
"'sort['",
".",
"$",
"this",
"->",
"getParameter",
"(",
"'field'",
")",
".",
"']=DESC'",
";",
"}",
"else",
"{",
"return",
"$",
"filterlist",
".",
"'sort['",
".",
"$",
"this",
"->",
"getParameter",
"(",
"'field'",
")",
".",
"']=ASC'",
";",
"}",
"}",
"return",
"$",
"filterlist",
".",
"'sort['",
".",
"$",
"this",
"->",
"getParameter",
"(",
"'field'",
")",
".",
"']='",
".",
"$",
"this",
"->",
"getParameter",
"(",
"'order'",
")",
";",
"}"
] |
Returns a URL with sort parameters
Expected Params:
filter string the string to operate upon
sort integer (optional) the starting point for our substring, default 0
field integer (optional) the length of the substring. default 1
order integer (optional) the length of the substring. default 1
@return string
|
[
"Returns",
"a",
"URL",
"with",
"sort",
"parameters"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/CmsFilterer.php#L304-L326
|
25,496
|
Vectrex/vxPHP
|
src/Webpage/DefaultMenuAuthenticator.php
|
DefaultMenuAuthenticator.authenticateMenuEntries
|
private function authenticateMenuEntries(Menu $menu, array $userRoles) {
foreach($menu->getEntries() as $e) {
if(!$e->getAuth()) {
$e->setAttribute('display', NULL);
}
else {
$e->setAttribute('display', 'none');
foreach($userRoles as $role) {
if($e->isAuthenticatedByRole($role)) {
$e->setAttribute('display', NULL);
break;
}
}
}
}
}
|
php
|
private function authenticateMenuEntries(Menu $menu, array $userRoles) {
foreach($menu->getEntries() as $e) {
if(!$e->getAuth()) {
$e->setAttribute('display', NULL);
}
else {
$e->setAttribute('display', 'none');
foreach($userRoles as $role) {
if($e->isAuthenticatedByRole($role)) {
$e->setAttribute('display', NULL);
break;
}
}
}
}
}
|
[
"private",
"function",
"authenticateMenuEntries",
"(",
"Menu",
"$",
"menu",
",",
"array",
"$",
"userRoles",
")",
"{",
"foreach",
"(",
"$",
"menu",
"->",
"getEntries",
"(",
")",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"e",
"->",
"getAuth",
"(",
")",
")",
"{",
"$",
"e",
"->",
"setAttribute",
"(",
"'display'",
",",
"NULL",
")",
";",
"}",
"else",
"{",
"$",
"e",
"->",
"setAttribute",
"(",
"'display'",
",",
"'none'",
")",
";",
"foreach",
"(",
"$",
"userRoles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"isAuthenticatedByRole",
"(",
"$",
"role",
")",
")",
"{",
"$",
"e",
"->",
"setAttribute",
"(",
"'display'",
",",
"NULL",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}"
] |
authenticate menu entries by checking each one against the
user's roles if necessary
@param Menu $menu
@param Role[] $userRoles
|
[
"authenticate",
"menu",
"entries",
"by",
"checking",
"each",
"one",
"against",
"the",
"user",
"s",
"roles",
"if",
"necessary"
] |
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
|
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/DefaultMenuAuthenticator.php#L115-L138
|
25,497
|
satori-php/middleware
|
src/Capsule.php
|
Capsule.offsetGet
|
public function offsetGet($key)
{
if (isset($this->granules[$key])) {
return $this->granules[$key];
}
throw new \OutOfBoundsException(sprintf('Granule "%s" is not defined.', $key));
}
|
php
|
public function offsetGet($key)
{
if (isset($this->granules[$key])) {
return $this->granules[$key];
}
throw new \OutOfBoundsException(sprintf('Granule "%s" is not defined.', $key));
}
|
[
"public",
"function",
"offsetGet",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"granules",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"granules",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Granule \"%s\" is not defined.'",
",",
"$",
"key",
")",
")",
";",
"}"
] |
Returns a granule.
@param string $key The unique key of the granule.
@throws \OutOfBoundsException If the granule is not defined.
@return mixed
|
[
"Returns",
"a",
"granule",
"."
] |
d43051baef9ccd2802e0a09e3b7aaaf72784dc7e
|
https://github.com/satori-php/middleware/blob/d43051baef9ccd2802e0a09e3b7aaaf72784dc7e/src/Capsule.php#L55-L62
|
25,498
|
bytic/orm
|
src/Relations/HasAndBelongsToMany.php
|
HasAndBelongsToMany.getLinkQuery
|
public function getLinkQuery($specific = true)
{
$query = $this->getDB()->newSelect();
$query->from($this->getTable());
if ($specific) {
$query = $this->populateQuerySpecific($query);
}
return $query;
}
|
php
|
public function getLinkQuery($specific = true)
{
$query = $this->getDB()->newSelect();
$query->from($this->getTable());
if ($specific) {
$query = $this->populateQuerySpecific($query);
}
return $query;
}
|
[
"public",
"function",
"getLinkQuery",
"(",
"$",
"specific",
"=",
"true",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getDB",
"(",
")",
"->",
"newSelect",
"(",
")",
";",
"$",
"query",
"->",
"from",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
";",
"if",
"(",
"$",
"specific",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"populateQuerySpecific",
"(",
"$",
"query",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] |
Simple select query from the link table
@param bool $specific
@return SelectQuery
|
[
"Simple",
"select",
"query",
"from",
"the",
"link",
"table"
] |
8d9a79b47761af0bfd9b8d1d28c83221dcac0de0
|
https://github.com/bytic/orm/blob/8d9a79b47761af0bfd9b8d1d28c83221dcac0de0/src/Relations/HasAndBelongsToMany.php#L116-L126
|
25,499
|
ARCANESOFT/SEO
|
src/Http/Controllers/Admin/SpammersController.php
|
SpammersController.index
|
public function index(Request $request)
{
$spammers = $this->paginate($this->blocker->all(), $request, $this->perPage);
$this->setTitle($title = trans('seo::spammers.titles.spammers-list'));
$this->addBreadcrumb($title);
return $this->view('admin.spammers.index', compact('spammers'));
}
|
php
|
public function index(Request $request)
{
$spammers = $this->paginate($this->blocker->all(), $request, $this->perPage);
$this->setTitle($title = trans('seo::spammers.titles.spammers-list'));
$this->addBreadcrumb($title);
return $this->view('admin.spammers.index', compact('spammers'));
}
|
[
"public",
"function",
"index",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"spammers",
"=",
"$",
"this",
"->",
"paginate",
"(",
"$",
"this",
"->",
"blocker",
"->",
"all",
"(",
")",
",",
"$",
"request",
",",
"$",
"this",
"->",
"perPage",
")",
";",
"$",
"this",
"->",
"setTitle",
"(",
"$",
"title",
"=",
"trans",
"(",
"'seo::spammers.titles.spammers-list'",
")",
")",
";",
"$",
"this",
"->",
"addBreadcrumb",
"(",
"$",
"title",
")",
";",
"return",
"$",
"this",
"->",
"view",
"(",
"'admin.spammers.index'",
",",
"compact",
"(",
"'spammers'",
")",
")",
";",
"}"
] |
List all the spammers.
@param \Illuminate\Http\Request $request
@return \Illuminate\View\View
|
[
"List",
"all",
"the",
"spammers",
"."
] |
ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2
|
https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Http/Controllers/Admin/SpammersController.php#L67-L75
|
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.