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
|
---|---|---|---|---|---|---|---|---|---|---|---|
21,600 |
brightmarch/rest-easy
|
src/Brightmarch/RestEasy/Controller/Controller.php
|
Controller.resourceRequires
|
public function resourceRequires()
{
$this->requiredTypes = array_merge(func_get_args(), $this->requiredTypes);
$this->canServerSupportThisRequest();
return $this;
}
|
php
|
public function resourceRequires()
{
$this->requiredTypes = array_merge(func_get_args(), $this->requiredTypes);
$this->canServerSupportThisRequest();
return $this;
}
|
[
"public",
"function",
"resourceRequires",
"(",
")",
"{",
"$",
"this",
"->",
"requiredTypes",
"=",
"array_merge",
"(",
"func_get_args",
"(",
")",
",",
"$",
"this",
"->",
"requiredTypes",
")",
";",
"$",
"this",
"->",
"canServerSupportThisRequest",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set a list of content types this resource requires.
@param [string, string, ...]
@return Controller
|
[
"Set",
"a",
"list",
"of",
"content",
"types",
"this",
"resource",
"requires",
"."
] |
a6903cdff0a5de2e4466d3e3438c59b9903049f4
|
https://github.com/brightmarch/rest-easy/blob/a6903cdff0a5de2e4466d3e3438c59b9903049f4/src/Brightmarch/RestEasy/Controller/Controller.php#L56-L62
|
21,601 |
brightmarch/rest-easy
|
src/Brightmarch/RestEasy/Controller/Controller.php
|
Controller.renderResource
|
public function renderResource($view, array $parameters=[], $statusCode=200)
{
$this->findContentType()
->findViewType()
->buildViewTemplate($view)
->checkViewTemplateExists();
$response = $this->createResponse($statusCode);
$response->headers
->set('Content-Type', $this->contentType);
return $this->render($this->viewTemplateName, $parameters, $response);
}
|
php
|
public function renderResource($view, array $parameters=[], $statusCode=200)
{
$this->findContentType()
->findViewType()
->buildViewTemplate($view)
->checkViewTemplateExists();
$response = $this->createResponse($statusCode);
$response->headers
->set('Content-Type', $this->contentType);
return $this->render($this->viewTemplateName, $parameters, $response);
}
|
[
"public",
"function",
"renderResource",
"(",
"$",
"view",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"statusCode",
"=",
"200",
")",
"{",
"$",
"this",
"->",
"findContentType",
"(",
")",
"->",
"findViewType",
"(",
")",
"->",
"buildViewTemplate",
"(",
"$",
"view",
")",
"->",
"checkViewTemplateExists",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"createResponse",
"(",
"$",
"statusCode",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"$",
"this",
"->",
"contentType",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"this",
"->",
"viewTemplateName",
",",
"$",
"parameters",
",",
"$",
"response",
")",
";",
"}"
] |
Creates a Response object and returns it.
@param string $view
@param array $parameters
@param integer $statusCode
@return Symfony\Component\HttpFoundation\Response
|
[
"Creates",
"a",
"Response",
"object",
"and",
"returns",
"it",
"."
] |
a6903cdff0a5de2e4466d3e3438c59b9903049f4
|
https://github.com/brightmarch/rest-easy/blob/a6903cdff0a5de2e4466d3e3438c59b9903049f4/src/Brightmarch/RestEasy/Controller/Controller.php#L72-L84
|
21,602 |
heidelpay/PhpDoc
|
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php
|
TypeCollectionAssembler.convertToArrayDescriptor
|
protected function convertToArrayDescriptor($descriptor)
{
$arrayDescriptor = new CollectionDescriptor('array');
$arrayDescriptor->setTypes(array($descriptor));
$arrayDescriptor->setKeyTypes(array('mixed'));
return $arrayDescriptor;
}
|
php
|
protected function convertToArrayDescriptor($descriptor)
{
$arrayDescriptor = new CollectionDescriptor('array');
$arrayDescriptor->setTypes(array($descriptor));
$arrayDescriptor->setKeyTypes(array('mixed'));
return $arrayDescriptor;
}
|
[
"protected",
"function",
"convertToArrayDescriptor",
"(",
"$",
"descriptor",
")",
"{",
"$",
"arrayDescriptor",
"=",
"new",
"CollectionDescriptor",
"(",
"'array'",
")",
";",
"$",
"arrayDescriptor",
"->",
"setTypes",
"(",
"array",
"(",
"$",
"descriptor",
")",
")",
";",
"$",
"arrayDescriptor",
"->",
"setKeyTypes",
"(",
"array",
"(",
"'mixed'",
")",
")",
";",
"return",
"$",
"arrayDescriptor",
";",
"}"
] |
Wraps the given Descriptor inside a Collection Descriptor of type array and returns that.
@param DescriptorAbstract $descriptor
@return CollectionDescriptor
|
[
"Wraps",
"the",
"given",
"Descriptor",
"inside",
"a",
"Collection",
"Descriptor",
"of",
"type",
"array",
"and",
"returns",
"that",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php#L99-L106
|
21,603 |
heidelpay/PhpDoc
|
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php
|
TypeCollectionAssembler.findClassNameForType
|
protected function findClassNameForType($type)
{
$className = (isset($this->typeToValueObjectClassName[$type]))
? $this->typeToValueObjectClassName[$type]
: false;
return $className;
}
|
php
|
protected function findClassNameForType($type)
{
$className = (isset($this->typeToValueObjectClassName[$type]))
? $this->typeToValueObjectClassName[$type]
: false;
return $className;
}
|
[
"protected",
"function",
"findClassNameForType",
"(",
"$",
"type",
")",
"{",
"$",
"className",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"typeToValueObjectClassName",
"[",
"$",
"type",
"]",
")",
")",
"?",
"$",
"this",
"->",
"typeToValueObjectClassName",
"[",
"$",
"type",
"]",
":",
"false",
";",
"return",
"$",
"className",
";",
"}"
] |
Returns the class name of the Value Object class associated with a given type or false if the type is unknown.
@param string $type
@return string|boolean
|
[
"Returns",
"the",
"class",
"name",
"of",
"the",
"Value",
"Object",
"class",
"associated",
"with",
"a",
"given",
"type",
"or",
"false",
"if",
"the",
"type",
"is",
"unknown",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/TypeCollectionAssembler.php#L115-L122
|
21,604 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php
|
ezcDbFactory.getImplementations
|
static public function getImplementations()
{
$list = array();
foreach ( self::$implementations as $name => $className )
{
$list[] = $name;
}
return $list;
}
|
php
|
static public function getImplementations()
{
$list = array();
foreach ( self::$implementations as $name => $className )
{
$list[] = $name;
}
return $list;
}
|
[
"static",
"public",
"function",
"getImplementations",
"(",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"implementations",
"as",
"$",
"name",
"=>",
"$",
"className",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Returns a list with supported database implementations.
Example:
<code>
ezcDbFactory::getImplementations();
</code>
@return array(string)
|
[
"Returns",
"a",
"list",
"with",
"supported",
"database",
"implementations",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php#L101-L109
|
21,605 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php
|
ezcDbFactory.create
|
static public function create( $dbParams )
{
if ( is_string( $dbParams ) )
{
$dbParams = self::parseDSN( $dbParams );
}
else if ( !is_array( $dbParams ) )
{
throw new ezcBaseValueException( 'dbParams', $dbParams, 'string or array', 'parameter' );
}
$impName = null; // implementation name
foreach ( $dbParams as $key => $val )
{
if ( in_array( $key, array( 'phptype', 'type', 'handler', 'driver' ) ) )
{
$impName = $val;
break;
}
}
if ( $impName === null || !array_key_exists( $impName, self::$implementations ) )
{
throw new ezcDbHandlerNotFoundException( $impName, array_keys( self::$implementations ) );
}
$className = self::$implementations[$impName];
$instance = new $className( $dbParams );
return $instance;
}
|
php
|
static public function create( $dbParams )
{
if ( is_string( $dbParams ) )
{
$dbParams = self::parseDSN( $dbParams );
}
else if ( !is_array( $dbParams ) )
{
throw new ezcBaseValueException( 'dbParams', $dbParams, 'string or array', 'parameter' );
}
$impName = null; // implementation name
foreach ( $dbParams as $key => $val )
{
if ( in_array( $key, array( 'phptype', 'type', 'handler', 'driver' ) ) )
{
$impName = $val;
break;
}
}
if ( $impName === null || !array_key_exists( $impName, self::$implementations ) )
{
throw new ezcDbHandlerNotFoundException( $impName, array_keys( self::$implementations ) );
}
$className = self::$implementations[$impName];
$instance = new $className( $dbParams );
return $instance;
}
|
[
"static",
"public",
"function",
"create",
"(",
"$",
"dbParams",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"dbParams",
")",
")",
"{",
"$",
"dbParams",
"=",
"self",
"::",
"parseDSN",
"(",
"$",
"dbParams",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dbParams",
")",
")",
"{",
"throw",
"new",
"ezcBaseValueException",
"(",
"'dbParams'",
",",
"$",
"dbParams",
",",
"'string or array'",
",",
"'parameter'",
")",
";",
"}",
"$",
"impName",
"=",
"null",
";",
"// implementation name",
"foreach",
"(",
"$",
"dbParams",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"array",
"(",
"'phptype'",
",",
"'type'",
",",
"'handler'",
",",
"'driver'",
")",
")",
")",
"{",
"$",
"impName",
"=",
"$",
"val",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"impName",
"===",
"null",
"||",
"!",
"array_key_exists",
"(",
"$",
"impName",
",",
"self",
"::",
"$",
"implementations",
")",
")",
"{",
"throw",
"new",
"ezcDbHandlerNotFoundException",
"(",
"$",
"impName",
",",
"array_keys",
"(",
"self",
"::",
"$",
"implementations",
")",
")",
";",
"}",
"$",
"className",
"=",
"self",
"::",
"$",
"implementations",
"[",
"$",
"impName",
"]",
";",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
"$",
"dbParams",
")",
";",
"return",
"$",
"instance",
";",
"}"
] |
Creates and returns an instance of the specified ezcDbHandler implementation.
Supported database parameters are:
- phptype|type|handler|driver: Database implementation
- user|username: Database user name
- pass|password: Database user password
- dbname|database: Database name
- host|hostspec: Name of the host database is running on
- port: TCP port
- charset: Client character set
- socket: UNIX socket path
The list above is actually driver-dependent and may be extended in the future.
You can specify any parameters your database handler supports.
@throws ezcDbHandlerNotFoundException if the requested database handler could not be found.
@param mixed $dbParams Database parameters
(driver, host, port, user, pass, etc).
May be specified either as array (key => val ....) or as DSN string.
Format of the DSN is the same as accepted by PEAR::DB::parseDSN().
@return ezcDbHandler
|
[
"Creates",
"and",
"returns",
"an",
"instance",
"of",
"the",
"specified",
"ezcDbHandler",
"implementation",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/factory.php#L134-L165
|
21,606 |
surebert/surebert-framework
|
src/sb/Samba/Connection.php
|
Connection.execute
|
public function execute($command, &$output = null)
{
$cmd = "smbclient '\\\\{$this->host}\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1";
exec($cmd, $output, $return);
if($return === 1){
$errmsg = sprintf("Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s",
$this->host,
$this->share,
$this->username,
$this->domain,
implode(" ", $output)
);
throw new \Exception($errmsg);
}
if($this->debug == true){
file_put_contents("php://stdout", "\n".$cmd);
file_put_contents("php://stdout", "\n".print_r($output, 1));
}
//LOG: Transaction
if(self::$log) {
self::$log->samba("Command: $cmd \n Output:" . print_r($output, 1) . "\n Return: " . print_r($return, 1) . "\n\n\n");
}
return $return;
}
|
php
|
public function execute($command, &$output = null)
{
$cmd = "smbclient '\\\\{$this->host}\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1";
exec($cmd, $output, $return);
if($return === 1){
$errmsg = sprintf("Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s",
$this->host,
$this->share,
$this->username,
$this->domain,
implode(" ", $output)
);
throw new \Exception($errmsg);
}
if($this->debug == true){
file_put_contents("php://stdout", "\n".$cmd);
file_put_contents("php://stdout", "\n".print_r($output, 1));
}
//LOG: Transaction
if(self::$log) {
self::$log->samba("Command: $cmd \n Output:" . print_r($output, 1) . "\n Return: " . print_r($return, 1) . "\n\n\n");
}
return $return;
}
|
[
"public",
"function",
"execute",
"(",
"$",
"command",
",",
"&",
"$",
"output",
"=",
"null",
")",
"{",
"$",
"cmd",
"=",
"\"smbclient '\\\\\\\\{$this->host}\\\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1\"",
";",
"exec",
"(",
"$",
"cmd",
",",
"$",
"output",
",",
"$",
"return",
")",
";",
"if",
"(",
"$",
"return",
"===",
"1",
")",
"{",
"$",
"errmsg",
"=",
"sprintf",
"(",
"\"Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s\"",
",",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"share",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"domain",
",",
"implode",
"(",
"\" \"",
",",
"$",
"output",
")",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"errmsg",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"debug",
"==",
"true",
")",
"{",
"file_put_contents",
"(",
"\"php://stdout\"",
",",
"\"\\n\"",
".",
"$",
"cmd",
")",
";",
"file_put_contents",
"(",
"\"php://stdout\"",
",",
"\"\\n\"",
".",
"print_r",
"(",
"$",
"output",
",",
"1",
")",
")",
";",
"}",
"//LOG: Transaction",
"if",
"(",
"self",
"::",
"$",
"log",
")",
"{",
"self",
"::",
"$",
"log",
"->",
"samba",
"(",
"\"Command: $cmd \\n Output:\"",
".",
"print_r",
"(",
"$",
"output",
",",
"1",
")",
".",
"\"\\n Return: \"",
".",
"print_r",
"(",
"$",
"return",
",",
"1",
")",
".",
"\"\\n\\n\\n\"",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Executes the command line function that completes the remote windows operations
@param $command string the command to issue to the smbclient
@param $output array what the command line returns
@param $log boolean whether to log this transaction
@return int Exit code for smbclient: 0 for success, 1 for error
|
[
"Executes",
"the",
"command",
"line",
"function",
"that",
"completes",
"the",
"remote",
"windows",
"operations"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L152-L180
|
21,607 |
surebert/surebert-framework
|
src/sb/Samba/Connection.php
|
Connection.parseListing
|
private function parseListing($listing, $subdir = '')
{
$ret = new \sb\Samba\Listing();
$exp = '/^\s{2}([\w \-]+\.?\w{3,4})\s+([A-Z]?)\s+(\d+)\s+(\w{3}.+)$/';
preg_match_all($exp, $listing, $matches);
if($matches[0]) {
$ret->name = $matches[1][0];
$ret->type = $matches[2][0];
$ret->size = $matches[3][0];
$ret->path = $subdir;
$ret->datemodified = $matches[4][0];
return $ret;
}
return 0;
}
|
php
|
private function parseListing($listing, $subdir = '')
{
$ret = new \sb\Samba\Listing();
$exp = '/^\s{2}([\w \-]+\.?\w{3,4})\s+([A-Z]?)\s+(\d+)\s+(\w{3}.+)$/';
preg_match_all($exp, $listing, $matches);
if($matches[0]) {
$ret->name = $matches[1][0];
$ret->type = $matches[2][0];
$ret->size = $matches[3][0];
$ret->path = $subdir;
$ret->datemodified = $matches[4][0];
return $ret;
}
return 0;
}
|
[
"private",
"function",
"parseListing",
"(",
"$",
"listing",
",",
"$",
"subdir",
"=",
"''",
")",
"{",
"$",
"ret",
"=",
"new",
"\\",
"sb",
"\\",
"Samba",
"\\",
"Listing",
"(",
")",
";",
"$",
"exp",
"=",
"'/^\\s{2}([\\w \\-]+\\.?\\w{3,4})\\s+([A-Z]?)\\s+(\\d+)\\s+(\\w{3}.+)$/'",
";",
"preg_match_all",
"(",
"$",
"exp",
",",
"$",
"listing",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
"{",
"$",
"ret",
"->",
"name",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"0",
"]",
";",
"$",
"ret",
"->",
"type",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
";",
"$",
"ret",
"->",
"size",
"=",
"$",
"matches",
"[",
"3",
"]",
"[",
"0",
"]",
";",
"$",
"ret",
"->",
"path",
"=",
"$",
"subdir",
";",
"$",
"ret",
"->",
"datemodified",
"=",
"$",
"matches",
"[",
"4",
"]",
"[",
"0",
"]",
";",
"return",
"$",
"ret",
";",
"}",
"return",
"0",
";",
"}"
] |
Converts a line of returned output into a \sb\Samba_Listing object
@param $listing
@param $subdir
@return \sb\Samba\Listing
|
[
"Converts",
"a",
"line",
"of",
"returned",
"output",
"into",
"a",
"\\",
"sb",
"\\",
"Samba_Listing",
"object"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Samba/Connection.php#L235-L253
|
21,608 |
willhoffmann/domuserp-php
|
src/Resources/Companies/Secondary/Branches.php
|
Branches.get
|
public function get($id)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/empresas/' . $this->companyId . '/filiais/' . $id
);
return $data;
}
|
php
|
public function get($id)
{
$data = $this->execute(
self::HTTP_GET,
self::DOMUSERP_API_PEDIDOVENDA . '/empresas/' . $this->companyId . '/filiais/' . $id
);
return $data;
}
|
[
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"self",
"::",
"DOMUSERP_API_PEDIDOVENDA",
".",
"'/empresas/'",
".",
"$",
"this",
"->",
"companyId",
".",
"'/filiais/'",
".",
"$",
"id",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Gets the branch data according to the id parameter
@param int $id
@return array|string
@throws \GuzzleHttp\Exception\GuzzleException
|
[
"Gets",
"the",
"branch",
"data",
"according",
"to",
"the",
"id",
"parameter"
] |
44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6
|
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Companies/Secondary/Branches.php#L52-L60
|
21,609 |
BugBuster1701/contao-botdetection-bundle
|
src/Resources/contao/classes/CheckBotReferrer.php
|
CheckBotReferrer.getReferrerLocalList
|
protected static function getReferrerLocalList()
{
$botreferrerlist = array();
if (isset($GLOBALS['BOTDETECTION']['BOT_REFERRER'])
&& \is_array($GLOBALS['BOTDETECTION']['BOT_REFERRER'])
)
{
foreach ($GLOBALS['BOTDETECTION']['BOT_REFERRER'] as $search)
{
$botreferrerlist[] = $search;
}
return $botreferrerlist;
}
return false;
}
|
php
|
protected static function getReferrerLocalList()
{
$botreferrerlist = array();
if (isset($GLOBALS['BOTDETECTION']['BOT_REFERRER'])
&& \is_array($GLOBALS['BOTDETECTION']['BOT_REFERRER'])
)
{
foreach ($GLOBALS['BOTDETECTION']['BOT_REFERRER'] as $search)
{
$botreferrerlist[] = $search;
}
return $botreferrerlist;
}
return false;
}
|
[
"protected",
"static",
"function",
"getReferrerLocalList",
"(",
")",
"{",
"$",
"botreferrerlist",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'BOTDETECTION'",
"]",
"[",
"'BOT_REFERRER'",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"GLOBALS",
"[",
"'BOTDETECTION'",
"]",
"[",
"'BOT_REFERRER'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"GLOBALS",
"[",
"'BOTDETECTION'",
"]",
"[",
"'BOT_REFERRER'",
"]",
"as",
"$",
"search",
")",
"{",
"$",
"botreferrerlist",
"[",
"]",
"=",
"$",
"search",
";",
"}",
"return",
"$",
"botreferrerlist",
";",
"}",
"return",
"false",
";",
"}"
] |
Get Referrer List, self defined over localconfig
@param string $Bot_Referrer_List
@return boolean|array: false: no list, array: Referrer List
|
[
"Get",
"Referrer",
"List",
"self",
"defined",
"over",
"localconfig"
] |
50c964acc354aa9116fae0e509cd7d075bd52f55
|
https://github.com/BugBuster1701/contao-botdetection-bundle/blob/50c964acc354aa9116fae0e509cd7d075bd52f55/src/Resources/contao/classes/CheckBotReferrer.php#L159-L175
|
21,610 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.channelFileList
|
public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE)
{
$files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray();
$count = count($files);
for($i = 0; $i < $count; $i++)
{
$files[$i]["sid"] = $this->getId();
$files[$i]["cid"] = $files[0]["cid"];
$files[$i]["path"] = $files[0]["path"];
$files[$i]["src"] = new Str($cid ? $files[$i]["path"] : "/");
if(!$files[$i]["src"]->endsWith("/"))
{
$files[$i]["src"]->append("/");
}
$files[$i]["src"]->append($files[$i]["name"]);
if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY)
{
$files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
}
}
uasort($files, array(__CLASS__, "sortFileList"));
return $files;
}
|
php
|
public function channelFileList($cid, $cpw = "", $path = "/", $recursive = FALSE)
{
$files = $this->execute("ftgetfilelist", array("cid" => $cid, "cpw" => $cpw, "path" => $path))->toArray();
$count = count($files);
for($i = 0; $i < $count; $i++)
{
$files[$i]["sid"] = $this->getId();
$files[$i]["cid"] = $files[0]["cid"];
$files[$i]["path"] = $files[0]["path"];
$files[$i]["src"] = new Str($cid ? $files[$i]["path"] : "/");
if(!$files[$i]["src"]->endsWith("/"))
{
$files[$i]["src"]->append("/");
}
$files[$i]["src"]->append($files[$i]["name"]);
if($recursive && $files[$i]["type"] == TeamSpeak3::FILE_TYPE_DIRECTORY)
{
$files = array_merge($files, $this->channelFileList($cid, $cpw, $path . $files[$i]["name"], $recursive));
}
}
uasort($files, array(__CLASS__, "sortFileList"));
return $files;
}
|
[
"public",
"function",
"channelFileList",
"(",
"$",
"cid",
",",
"$",
"cpw",
"=",
"\"\"",
",",
"$",
"path",
"=",
"\"/\"",
",",
"$",
"recursive",
"=",
"FALSE",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"execute",
"(",
"\"ftgetfilelist\"",
",",
"array",
"(",
"\"cid\"",
"=>",
"$",
"cid",
",",
"\"cpw\"",
"=>",
"$",
"cpw",
",",
"\"path\"",
"=>",
"$",
"path",
")",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"files",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"sid\"",
"]",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"cid\"",
"]",
"=",
"$",
"files",
"[",
"0",
"]",
"[",
"\"cid\"",
"]",
";",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"path\"",
"]",
"=",
"$",
"files",
"[",
"0",
"]",
"[",
"\"path\"",
"]",
";",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"src\"",
"]",
"=",
"new",
"Str",
"(",
"$",
"cid",
"?",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"path\"",
"]",
":",
"\"/\"",
")",
";",
"if",
"(",
"!",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"src\"",
"]",
"->",
"endsWith",
"(",
"\"/\"",
")",
")",
"{",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"src\"",
"]",
"->",
"append",
"(",
"\"/\"",
")",
";",
"}",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"src\"",
"]",
"->",
"append",
"(",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"name\"",
"]",
")",
";",
"if",
"(",
"$",
"recursive",
"&&",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"type\"",
"]",
"==",
"TeamSpeak3",
"::",
"FILE_TYPE_DIRECTORY",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"$",
"this",
"->",
"channelFileList",
"(",
"$",
"cid",
",",
"$",
"cpw",
",",
"$",
"path",
".",
"$",
"files",
"[",
"$",
"i",
"]",
"[",
"\"name\"",
"]",
",",
"$",
"recursive",
")",
")",
";",
"}",
"}",
"uasort",
"(",
"$",
"files",
",",
"array",
"(",
"__CLASS__",
",",
"\"sortFileList\"",
")",
")",
";",
"return",
"$",
"files",
";",
"}"
] |
Returns a list of files and directories stored in the specified channels file repository.
@param integer $cid
@param string $cpw
@param string $path
@param boolean $recursive
@return array
|
[
"Returns",
"a",
"list",
"of",
"files",
"and",
"directories",
"stored",
"in",
"the",
"specified",
"channels",
"file",
"repository",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L491-L519
|
21,611 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.channelGetById
|
public function channelGetById($cid)
{
if(!array_key_exists((string) $cid, $this->channelList()))
{
throw new Exception("invalid channelID", 0x300);
}
return $this->channelList[intval((string) $cid)];
}
|
php
|
public function channelGetById($cid)
{
if(!array_key_exists((string) $cid, $this->channelList()))
{
throw new Exception("invalid channelID", 0x300);
}
return $this->channelList[intval((string) $cid)];
}
|
[
"public",
"function",
"channelGetById",
"(",
"$",
"cid",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"(",
"string",
")",
"$",
"cid",
",",
"$",
"this",
"->",
"channelList",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"invalid channelID\"",
",",
"0x300",
")",
";",
"}",
"return",
"$",
"this",
"->",
"channelList",
"[",
"intval",
"(",
"(",
"string",
")",
"$",
"cid",
")",
"]",
";",
"}"
] |
Returns the Channel object matching the given ID.
@param integer $cid
@throws Exception
@return Channel
|
[
"Returns",
"the",
"Channel",
"object",
"matching",
"the",
"given",
"ID",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L624-L632
|
21,612 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.channelGetByName
|
public function channelGetByName($name)
{
foreach($this->channelList() as $channel)
{
if($channel["channel_name"] == $name) return $channel;
}
throw new Exception("invalid channelID", 0x300);
}
|
php
|
public function channelGetByName($name)
{
foreach($this->channelList() as $channel)
{
if($channel["channel_name"] == $name) return $channel;
}
throw new Exception("invalid channelID", 0x300);
}
|
[
"public",
"function",
"channelGetByName",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"channelList",
"(",
")",
"as",
"$",
"channel",
")",
"{",
"if",
"(",
"$",
"channel",
"[",
"\"channel_name\"",
"]",
"==",
"$",
"name",
")",
"return",
"$",
"channel",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"invalid channelID\"",
",",
"0x300",
")",
";",
"}"
] |
Returns the Channel object matching the given name.
@param string $name
@throws Exception
@return Channel
|
[
"Returns",
"the",
"Channel",
"object",
"matching",
"the",
"given",
"name",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L641-L649
|
21,613 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.clientList
|
public function clientList(array $filter = array())
{
if($this->clientList === null)
{
$clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid");
$this->clientList = array();
foreach($clients as $clid => $client)
{
if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue;
$this->clientList[$clid] = new Client($this, $client);
}
uasort($this->clientList, array(__CLASS__, "sortClientList"));
$this->resetNodeList();
}
return $this->filterList($this->clientList, $filter);
}
|
php
|
public function clientList(array $filter = array())
{
if($this->clientList === null)
{
$clients = $this->request("clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip")->toAssocArray("clid");
$this->clientList = array();
foreach($clients as $clid => $client)
{
if($this->getParent()->getExcludeQueryClients() && $client["client_type"]) continue;
$this->clientList[$clid] = new Client($this, $client);
}
uasort($this->clientList, array(__CLASS__, "sortClientList"));
$this->resetNodeList();
}
return $this->filterList($this->clientList, $filter);
}
|
[
"public",
"function",
"clientList",
"(",
"array",
"$",
"filter",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"clientList",
"===",
"null",
")",
"{",
"$",
"clients",
"=",
"$",
"this",
"->",
"request",
"(",
"\"clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip\"",
")",
"->",
"toAssocArray",
"(",
"\"clid\"",
")",
";",
"$",
"this",
"->",
"clientList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"clients",
"as",
"$",
"clid",
"=>",
"$",
"client",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getExcludeQueryClients",
"(",
")",
"&&",
"$",
"client",
"[",
"\"client_type\"",
"]",
")",
"continue",
";",
"$",
"this",
"->",
"clientList",
"[",
"$",
"clid",
"]",
"=",
"new",
"Client",
"(",
"$",
"this",
",",
"$",
"client",
")",
";",
"}",
"uasort",
"(",
"$",
"this",
"->",
"clientList",
",",
"array",
"(",
"__CLASS__",
",",
"\"sortClientList\"",
")",
")",
";",
"$",
"this",
"->",
"resetNodeList",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filterList",
"(",
"$",
"this",
"->",
"clientList",
",",
"$",
"filter",
")",
";",
"}"
] |
Returns an array filled with Client objects.
@param array $filter
@return array|Client[]
|
[
"Returns",
"an",
"array",
"filled",
"with",
"Client",
"objects",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L657-L678
|
21,614 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.clientGetByName
|
public function clientGetByName($name)
{
foreach($this->clientList() as $client)
{
if($client["client_nickname"] == $name) return $client;
}
throw new Exception("invalid clientID", 0x200);
}
|
php
|
public function clientGetByName($name)
{
foreach($this->clientList() as $client)
{
if($client["client_nickname"] == $name) return $client;
}
throw new Exception("invalid clientID", 0x200);
}
|
[
"public",
"function",
"clientGetByName",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"clientList",
"(",
")",
"as",
"$",
"client",
")",
"{",
"if",
"(",
"$",
"client",
"[",
"\"client_nickname\"",
"]",
"==",
"$",
"name",
")",
"return",
"$",
"client",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"invalid clientID\"",
",",
"0x200",
")",
";",
"}"
] |
Returns the Client object matching the given name.
@param string $name
@throws Exception
@return Client
|
[
"Returns",
"the",
"Client",
"object",
"matching",
"the",
"given",
"name",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L785-L793
|
21,615 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.clientGetByUid
|
public function clientGetByUid($uid)
{
foreach($this->clientList() as $client)
{
if($client["client_unique_identifier"] == $uid) return $client;
}
throw new Exception("invalid clientID", 0x200);
}
|
php
|
public function clientGetByUid($uid)
{
foreach($this->clientList() as $client)
{
if($client["client_unique_identifier"] == $uid) return $client;
}
throw new Exception("invalid clientID", 0x200);
}
|
[
"public",
"function",
"clientGetByUid",
"(",
"$",
"uid",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"clientList",
"(",
")",
"as",
"$",
"client",
")",
"{",
"if",
"(",
"$",
"client",
"[",
"\"client_unique_identifier\"",
"]",
"==",
"$",
"uid",
")",
"return",
"$",
"client",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"invalid clientID\"",
",",
"0x200",
")",
";",
"}"
] |
Returns the Client object matching the given unique identifier.
@param string $uid
@throws Exception
@return Client
|
[
"Returns",
"the",
"Client",
"object",
"matching",
"the",
"given",
"unique",
"identifier",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L802-L810
|
21,616 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.clientGetByDbid
|
public function clientGetByDbid($dbid)
{
foreach($this->clientList() as $client)
{
if($client["client_database_id"] == $dbid) return $client;
}
throw new Exception("invalid clientID", 0x200);
}
|
php
|
public function clientGetByDbid($dbid)
{
foreach($this->clientList() as $client)
{
if($client["client_database_id"] == $dbid) return $client;
}
throw new Exception("invalid clientID", 0x200);
}
|
[
"public",
"function",
"clientGetByDbid",
"(",
"$",
"dbid",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"clientList",
"(",
")",
"as",
"$",
"client",
")",
"{",
"if",
"(",
"$",
"client",
"[",
"\"client_database_id\"",
"]",
"==",
"$",
"dbid",
")",
"return",
"$",
"client",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"invalid clientID\"",
",",
"0x200",
")",
";",
"}"
] |
Returns the Client object matching the given database ID.
@param integer $dbid
@throws Exception
@return Client
|
[
"Returns",
"the",
"Client",
"object",
"matching",
"the",
"given",
"database",
"ID",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L819-L827
|
21,617 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.clientMove
|
public function clientMove($clid, $cid, $cpw = null)
{
$this->clientListReset();
$this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw));
if($clid instanceof Node)
{
$clid = $clid->getId();
}
if($cid instanceof Node)
{
$cid = $cid->getId();
}
if(!is_array($clid) && $clid == $this->whoamiGet("client_id"))
{
$this->getParent()->whoamiSet("client_channel_id", $cid);
}
}
|
php
|
public function clientMove($clid, $cid, $cpw = null)
{
$this->clientListReset();
$this->execute("clientmove", array("clid" => $clid, "cid" => $cid, "cpw" => $cpw));
if($clid instanceof Node)
{
$clid = $clid->getId();
}
if($cid instanceof Node)
{
$cid = $cid->getId();
}
if(!is_array($clid) && $clid == $this->whoamiGet("client_id"))
{
$this->getParent()->whoamiSet("client_channel_id", $cid);
}
}
|
[
"public",
"function",
"clientMove",
"(",
"$",
"clid",
",",
"$",
"cid",
",",
"$",
"cpw",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"clientListReset",
"(",
")",
";",
"$",
"this",
"->",
"execute",
"(",
"\"clientmove\"",
",",
"array",
"(",
"\"clid\"",
"=>",
"$",
"clid",
",",
"\"cid\"",
"=>",
"$",
"cid",
",",
"\"cpw\"",
"=>",
"$",
"cpw",
")",
")",
";",
"if",
"(",
"$",
"clid",
"instanceof",
"Node",
")",
"{",
"$",
"clid",
"=",
"$",
"clid",
"->",
"getId",
"(",
")",
";",
"}",
"if",
"(",
"$",
"cid",
"instanceof",
"Node",
")",
"{",
"$",
"cid",
"=",
"$",
"cid",
"->",
"getId",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"clid",
")",
"&&",
"$",
"clid",
"==",
"$",
"this",
"->",
"whoamiGet",
"(",
"\"client_id\"",
")",
")",
"{",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"whoamiSet",
"(",
"\"client_channel_id\"",
",",
"$",
"cid",
")",
";",
"}",
"}"
] |
Moves a client to another channel.
@param integer $clid
@param integer $cid
@param string $cpw
@return void
|
[
"Moves",
"a",
"client",
"to",
"another",
"channel",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L885-L905
|
21,618 |
lukasz-adamski/teamspeak3-framework
|
src/TeamSpeak3/Node/Server.php
|
Server.serverGroupGetById
|
public function serverGroupGetById($sgid)
{
if(!array_key_exists((string) $sgid, $this->serverGroupList()))
{
throw new Exception("invalid groupID", 0xA00);
}
return $this->sgroupList[intval((string) $sgid)];
}
|
php
|
public function serverGroupGetById($sgid)
{
if(!array_key_exists((string) $sgid, $this->serverGroupList()))
{
throw new Exception("invalid groupID", 0xA00);
}
return $this->sgroupList[intval((string) $sgid)];
}
|
[
"public",
"function",
"serverGroupGetById",
"(",
"$",
"sgid",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"(",
"string",
")",
"$",
"sgid",
",",
"$",
"this",
"->",
"serverGroupList",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"invalid groupID\"",
",",
"0xA00",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sgroupList",
"[",
"intval",
"(",
"(",
"string",
")",
"$",
"sgid",
")",
"]",
";",
"}"
] |
Returns the Servergroup object matching the given ID.
@param integer $sgid
@throws Exception
@return ServerGroup
|
[
"Returns",
"the",
"Servergroup",
"object",
"matching",
"the",
"given",
"ID",
"."
] |
39a56eca608da6b56b6aa386a7b5b31dc576c41a
|
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Node/Server.php#L1157-L1165
|
21,619 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.selectList
|
public function selectList($meta, ...$args)
{
if (!$args) {
throw new \InvalidArgumentException();
}
$fields = null;
$query = null;
if (!isset($args[1]) && $args[0] instanceof Query\Select) {
$query = $args[0];
}
elseif ((is_array($args[0]) || is_string($args[0])) && !isset($args[2])) {
$fields = $args[0];
$query = isset($args[1]) ? $args[1] : null;
}
else {
throw new \InvalidArgumentException();
}
$query = $query instanceof Query\Select ? $query : Query\Select::fromParamArgs([$query]);
if ($fields) {
$query->fields = $fields;
}
if (!$query->fields) {
throw new \InvalidArgumentException();
}
$singleMode = false;
if (is_string($query->fields)) {
$singleMode = true;
$query->fields = [$query->fields];
}
$mapper = $this->mapper;
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
list ($sql, $params, $props) = $query->buildQuery($meta);
if ($props) {
$params = $this->mapper->formatParams($meta, $props, $params);
}
$stmt = $this->getConnector()->prepare($sql)->execute($params);
$mappedRows = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$mappedRow = $mapper->mapRowToProperties($meta, $row);
if ($singleMode) {
$mappedRows[] = current($mappedRow);
} else {
$mappedRows[] = $mappedRow;
}
}
return $mappedRows;
}
|
php
|
public function selectList($meta, ...$args)
{
if (!$args) {
throw new \InvalidArgumentException();
}
$fields = null;
$query = null;
if (!isset($args[1]) && $args[0] instanceof Query\Select) {
$query = $args[0];
}
elseif ((is_array($args[0]) || is_string($args[0])) && !isset($args[2])) {
$fields = $args[0];
$query = isset($args[1]) ? $args[1] : null;
}
else {
throw new \InvalidArgumentException();
}
$query = $query instanceof Query\Select ? $query : Query\Select::fromParamArgs([$query]);
if ($fields) {
$query->fields = $fields;
}
if (!$query->fields) {
throw new \InvalidArgumentException();
}
$singleMode = false;
if (is_string($query->fields)) {
$singleMode = true;
$query->fields = [$query->fields];
}
$mapper = $this->mapper;
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
list ($sql, $params, $props) = $query->buildQuery($meta);
if ($props) {
$params = $this->mapper->formatParams($meta, $props, $params);
}
$stmt = $this->getConnector()->prepare($sql)->execute($params);
$mappedRows = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$mappedRow = $mapper->mapRowToProperties($meta, $row);
if ($singleMode) {
$mappedRows[] = current($mappedRow);
} else {
$mappedRows[] = $mappedRow;
}
}
return $mappedRows;
}
|
[
"public",
"function",
"selectList",
"(",
"$",
"meta",
",",
"...",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"$",
"args",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"fields",
"=",
"null",
";",
"$",
"query",
"=",
"null",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"$",
"args",
"[",
"0",
"]",
"instanceof",
"Query",
"\\",
"Select",
")",
"{",
"$",
"query",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"}",
"elseif",
"(",
"(",
"is_array",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"||",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"&&",
"!",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"query",
"=",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"?",
"$",
"args",
"[",
"1",
"]",
":",
"null",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"query",
"=",
"$",
"query",
"instanceof",
"Query",
"\\",
"Select",
"?",
"$",
"query",
":",
"Query",
"\\",
"Select",
"::",
"fromParamArgs",
"(",
"[",
"$",
"query",
"]",
")",
";",
"if",
"(",
"$",
"fields",
")",
"{",
"$",
"query",
"->",
"fields",
"=",
"$",
"fields",
";",
"}",
"if",
"(",
"!",
"$",
"query",
"->",
"fields",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"singleMode",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"query",
"->",
"fields",
")",
")",
"{",
"$",
"singleMode",
"=",
"true",
";",
"$",
"query",
"->",
"fields",
"=",
"[",
"$",
"query",
"->",
"fields",
"]",
";",
"}",
"$",
"mapper",
"=",
"$",
"this",
"->",
"mapper",
";",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"props",
")",
"=",
"$",
"query",
"->",
"buildQuery",
"(",
"$",
"meta",
")",
";",
"if",
"(",
"$",
"props",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"mapper",
"->",
"formatParams",
"(",
"$",
"meta",
",",
"$",
"props",
",",
"$",
"params",
")",
";",
"}",
"$",
"stmt",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"$",
"mappedRows",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"$",
"mappedRow",
"=",
"$",
"mapper",
"->",
"mapRowToProperties",
"(",
"$",
"meta",
",",
"$",
"row",
")",
";",
"if",
"(",
"$",
"singleMode",
")",
"{",
"$",
"mappedRows",
"[",
"]",
"=",
"current",
"(",
"$",
"mappedRow",
")",
";",
"}",
"else",
"{",
"$",
"mappedRows",
"[",
"]",
"=",
"$",
"mappedRow",
";",
"}",
"}",
"return",
"$",
"mappedRows",
";",
"}"
] |
Dunno about this. Consider it unstable, don't count on it still
being here in v6
|
[
"Dunno",
"about",
"this",
".",
"Consider",
"it",
"unstable",
"don",
"t",
"count",
"on",
"it",
"still",
"being",
"here",
"in",
"v6"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L217-L270
|
21,620 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.assignRelated
|
public function assignRelated($source, $relationNames=null, $meta=null)
{
if (!$source) { return; }
$stack = [];
$sourceIsArray = is_array($source) || $source instanceof \Traversable;
if (!$sourceIsArray) {
$source = array($source);
}
if ($meta !== null) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($source[0]));
}
if (!$relationNames) {
if ($meta->autoRelations) {
$relationNames = $meta->autoRelations;
} else {
throw new Exception("relationNames not passed, class {$meta->class} does not define autoRelations");
}
}
$relationMap = [];
foreach ((array)$relationNames as $relationName) {
if (!isset($meta->relations[$relationName])) {
throw new Exception("Unknown relation $relationName on {$meta->class}");
}
$relationMap[$relationName] = $rel = $meta->relations[$relationName];
if ($rel['mode'] == 'class') {
throw new Exception("Relation $relationName is not assignable for class {$meta->class}");
}
}
$done = [];
foreach ($relationMap as $relationName=>$relation) {
if (isset($done[$relationName])) {
continue;
}
$done[$relationName] = true;
$missing = [];
foreach ($source as $idx=>$item) {
// we have to assume it's missing if we see a getter as there
// may be serious unintended side effects from calling a getter
// that may be unpopulated. it might lazy load if it's an active
// record, or it might throw an exception because the 'set' hasn't
// been called.
// check for isset as well as falsey for the situation where we're using
// stdClasses as the response object
if (isset($relation['getter']) || !isset($item->{$relationName}) || !$item->{$relationName}) {
$missing[$idx] = $item;
}
}
if ($missing) {
$result = $this->getRelated($missing, $relationName, ['stack'=>$stack], $meta);
$relator = $this->getRelator($meta, $relationName);
$this->populateObjectsWithRelated($missing, $result, $relation);
}
}
}
|
php
|
public function assignRelated($source, $relationNames=null, $meta=null)
{
if (!$source) { return; }
$stack = [];
$sourceIsArray = is_array($source) || $source instanceof \Traversable;
if (!$sourceIsArray) {
$source = array($source);
}
if ($meta !== null) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($source[0]));
}
if (!$relationNames) {
if ($meta->autoRelations) {
$relationNames = $meta->autoRelations;
} else {
throw new Exception("relationNames not passed, class {$meta->class} does not define autoRelations");
}
}
$relationMap = [];
foreach ((array)$relationNames as $relationName) {
if (!isset($meta->relations[$relationName])) {
throw new Exception("Unknown relation $relationName on {$meta->class}");
}
$relationMap[$relationName] = $rel = $meta->relations[$relationName];
if ($rel['mode'] == 'class') {
throw new Exception("Relation $relationName is not assignable for class {$meta->class}");
}
}
$done = [];
foreach ($relationMap as $relationName=>$relation) {
if (isset($done[$relationName])) {
continue;
}
$done[$relationName] = true;
$missing = [];
foreach ($source as $idx=>$item) {
// we have to assume it's missing if we see a getter as there
// may be serious unintended side effects from calling a getter
// that may be unpopulated. it might lazy load if it's an active
// record, or it might throw an exception because the 'set' hasn't
// been called.
// check for isset as well as falsey for the situation where we're using
// stdClasses as the response object
if (isset($relation['getter']) || !isset($item->{$relationName}) || !$item->{$relationName}) {
$missing[$idx] = $item;
}
}
if ($missing) {
$result = $this->getRelated($missing, $relationName, ['stack'=>$stack], $meta);
$relator = $this->getRelator($meta, $relationName);
$this->populateObjectsWithRelated($missing, $result, $relation);
}
}
}
|
[
"public",
"function",
"assignRelated",
"(",
"$",
"source",
",",
"$",
"relationNames",
"=",
"null",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"source",
")",
"{",
"return",
";",
"}",
"$",
"stack",
"=",
"[",
"]",
";",
"$",
"sourceIsArray",
"=",
"is_array",
"(",
"$",
"source",
")",
"||",
"$",
"source",
"instanceof",
"\\",
"Traversable",
";",
"if",
"(",
"!",
"$",
"sourceIsArray",
")",
"{",
"$",
"source",
"=",
"array",
"(",
"$",
"source",
")",
";",
"}",
"if",
"(",
"$",
"meta",
"!==",
"null",
")",
"{",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"get_class",
"(",
"$",
"source",
"[",
"0",
"]",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"relationNames",
")",
"{",
"if",
"(",
"$",
"meta",
"->",
"autoRelations",
")",
"{",
"$",
"relationNames",
"=",
"$",
"meta",
"->",
"autoRelations",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"relationNames not passed, class {$meta->class} does not define autoRelations\"",
")",
";",
"}",
"}",
"$",
"relationMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"relationNames",
"as",
"$",
"relationName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"meta",
"->",
"relations",
"[",
"$",
"relationName",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unknown relation $relationName on {$meta->class}\"",
")",
";",
"}",
"$",
"relationMap",
"[",
"$",
"relationName",
"]",
"=",
"$",
"rel",
"=",
"$",
"meta",
"->",
"relations",
"[",
"$",
"relationName",
"]",
";",
"if",
"(",
"$",
"rel",
"[",
"'mode'",
"]",
"==",
"'class'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Relation $relationName is not assignable for class {$meta->class}\"",
")",
";",
"}",
"}",
"$",
"done",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"relationMap",
"as",
"$",
"relationName",
"=>",
"$",
"relation",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"done",
"[",
"$",
"relationName",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"done",
"[",
"$",
"relationName",
"]",
"=",
"true",
";",
"$",
"missing",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"source",
"as",
"$",
"idx",
"=>",
"$",
"item",
")",
"{",
"// we have to assume it's missing if we see a getter as there",
"// may be serious unintended side effects from calling a getter",
"// that may be unpopulated. it might lazy load if it's an active",
"// record, or it might throw an exception because the 'set' hasn't",
"// been called.",
"// check for isset as well as falsey for the situation where we're using",
"// stdClasses as the response object",
"if",
"(",
"isset",
"(",
"$",
"relation",
"[",
"'getter'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"item",
"->",
"{",
"$",
"relationName",
"}",
")",
"||",
"!",
"$",
"item",
"->",
"{",
"$",
"relationName",
"}",
")",
"{",
"$",
"missing",
"[",
"$",
"idx",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"if",
"(",
"$",
"missing",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getRelated",
"(",
"$",
"missing",
",",
"$",
"relationName",
",",
"[",
"'stack'",
"=>",
"$",
"stack",
"]",
",",
"$",
"meta",
")",
";",
"$",
"relator",
"=",
"$",
"this",
"->",
"getRelator",
"(",
"$",
"meta",
",",
"$",
"relationName",
")",
";",
"$",
"this",
"->",
"populateObjectsWithRelated",
"(",
"$",
"missing",
",",
"$",
"result",
",",
"$",
"relation",
")",
";",
"}",
"}",
"}"
] |
Retrieve related objects from the database and assign them to the source
if the source field is not yet populated.
@param object|array Source objects to assign relations for
@param string|array The name of the relation(s) to assign
@return void
|
[
"Retrieve",
"related",
"objects",
"from",
"the",
"database",
"and",
"assign",
"them",
"to",
"the",
"source",
"if",
"the",
"source",
"field",
"is",
"not",
"yet",
"populated",
"."
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L330-L393
|
21,621 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.getRelated
|
public function getRelated($source, $relationName, $query=null, $meta=null)
{
if (!$source) { return; }
$sourceIsArray = false;
$test = $source;
if (is_array($test) || $test instanceof \Traversable) {
$sourceIsArray = true;
$test = $test[0];
}
if (!$meta) {
if ($query instanceof Meta) {
list ($meta, $query) = [$query, null];
} else {
$meta = $this->mapper->getMeta(get_class($test));
}
}
else {
$meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta);
}
if (!isset($meta->relations[$relationName])) {
throw new Exception("Unknown relation $relationName on {$meta->class}");
}
$relation = $meta->relations[$relationName];
$relator = $this->getRelator($relation);
if ($query) {
// need to support both Query\Criteria and Query\Select
// this is a cheeky hack - the API doesn't declare support for
// Select in Relators because it carries promises of things like
// 'fields' and whatnot that we'll never be able to satisfy.
// That whole hierarchy needs to be cleaned
// up into a bunch of traits so we can have RelatorCriteria or something.
$query = $query instanceof Query\Criteria ? $query : Query\Select::fromParamArgs([$query]);
$stack = $query->stack;
}
else {
$stack = [];
}
$stack[$meta->class] = true;
if ($sourceIsArray) {
return $relator->getRelatedForList($meta, $source, $relation, $query ?: null, $stack);
} else {
return $relator->getRelated($meta, $source, $relation, $query ?: null, $stack);
}
}
|
php
|
public function getRelated($source, $relationName, $query=null, $meta=null)
{
if (!$source) { return; }
$sourceIsArray = false;
$test = $source;
if (is_array($test) || $test instanceof \Traversable) {
$sourceIsArray = true;
$test = $test[0];
}
if (!$meta) {
if ($query instanceof Meta) {
list ($meta, $query) = [$query, null];
} else {
$meta = $this->mapper->getMeta(get_class($test));
}
}
else {
$meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta);
}
if (!isset($meta->relations[$relationName])) {
throw new Exception("Unknown relation $relationName on {$meta->class}");
}
$relation = $meta->relations[$relationName];
$relator = $this->getRelator($relation);
if ($query) {
// need to support both Query\Criteria and Query\Select
// this is a cheeky hack - the API doesn't declare support for
// Select in Relators because it carries promises of things like
// 'fields' and whatnot that we'll never be able to satisfy.
// That whole hierarchy needs to be cleaned
// up into a bunch of traits so we can have RelatorCriteria or something.
$query = $query instanceof Query\Criteria ? $query : Query\Select::fromParamArgs([$query]);
$stack = $query->stack;
}
else {
$stack = [];
}
$stack[$meta->class] = true;
if ($sourceIsArray) {
return $relator->getRelatedForList($meta, $source, $relation, $query ?: null, $stack);
} else {
return $relator->getRelated($meta, $source, $relation, $query ?: null, $stack);
}
}
|
[
"public",
"function",
"getRelated",
"(",
"$",
"source",
",",
"$",
"relationName",
",",
"$",
"query",
"=",
"null",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"source",
")",
"{",
"return",
";",
"}",
"$",
"sourceIsArray",
"=",
"false",
";",
"$",
"test",
"=",
"$",
"source",
";",
"if",
"(",
"is_array",
"(",
"$",
"test",
")",
"||",
"$",
"test",
"instanceof",
"\\",
"Traversable",
")",
"{",
"$",
"sourceIsArray",
"=",
"true",
";",
"$",
"test",
"=",
"$",
"test",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
")",
"{",
"if",
"(",
"$",
"query",
"instanceof",
"Meta",
")",
"{",
"list",
"(",
"$",
"meta",
",",
"$",
"query",
")",
"=",
"[",
"$",
"query",
",",
"null",
"]",
";",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"get_class",
"(",
"$",
"test",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"meta",
":",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"meta",
"->",
"relations",
"[",
"$",
"relationName",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unknown relation $relationName on {$meta->class}\"",
")",
";",
"}",
"$",
"relation",
"=",
"$",
"meta",
"->",
"relations",
"[",
"$",
"relationName",
"]",
";",
"$",
"relator",
"=",
"$",
"this",
"->",
"getRelator",
"(",
"$",
"relation",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"// need to support both Query\\Criteria and Query\\Select",
"// this is a cheeky hack - the API doesn't declare support for",
"// Select in Relators because it carries promises of things like ",
"// 'fields' and whatnot that we'll never be able to satisfy. ",
"// That whole hierarchy needs to be cleaned",
"// up into a bunch of traits so we can have RelatorCriteria or something.",
"$",
"query",
"=",
"$",
"query",
"instanceof",
"Query",
"\\",
"Criteria",
"?",
"$",
"query",
":",
"Query",
"\\",
"Select",
"::",
"fromParamArgs",
"(",
"[",
"$",
"query",
"]",
")",
";",
"$",
"stack",
"=",
"$",
"query",
"->",
"stack",
";",
"}",
"else",
"{",
"$",
"stack",
"=",
"[",
"]",
";",
"}",
"$",
"stack",
"[",
"$",
"meta",
"->",
"class",
"]",
"=",
"true",
";",
"if",
"(",
"$",
"sourceIsArray",
")",
"{",
"return",
"$",
"relator",
"->",
"getRelatedForList",
"(",
"$",
"meta",
",",
"$",
"source",
",",
"$",
"relation",
",",
"$",
"query",
"?",
":",
"null",
",",
"$",
"stack",
")",
";",
"}",
"else",
"{",
"return",
"$",
"relator",
"->",
"getRelated",
"(",
"$",
"meta",
",",
"$",
"source",
",",
"$",
"relation",
",",
"$",
"query",
"?",
":",
"null",
",",
"$",
"stack",
")",
";",
"}",
"}"
] |
Get related objects from the database
Supports the following signatures:
- getRelated( object|array $source , string $relationName )
- getRelated( object|array $source , string $relationName , $query )
- getRelated( object|array $source , string $relationName , Meta $meta )
- getRelated( object|array $source , string $relationName , $query, Meta $meta )
@return object[]
|
[
"Get",
"related",
"objects",
"from",
"the",
"database"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L478-L528
|
21,622 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.insertTable
|
public function insertTable($meta, $query)
{
$meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta);
if (!$meta->canInsert) {
throw new Exception("Class {$meta->class} prohibits insert");
}
$query = $query instanceof Query\Insert ? $query : new Query\Insert(['values'=>$query]);
$query->values = $this->mapper->mapPropertiesToRow($meta, $query->values);
if (!$query->table) {
$query->table = $meta->table;
}
list ($sql, $params) = $query->buildQuery($meta);
// no need to formatParams here - they're already field names
$stmt = $this->getConnector()->prepare($sql);
$stmt->execute($params);
$lastInsertId = $this->getConnector()->lastInsertId();
return $lastInsertId;
}
|
php
|
public function insertTable($meta, $query)
{
$meta = $meta instanceof Meta ? $meta : $this->mapper->getMeta($meta);
if (!$meta->canInsert) {
throw new Exception("Class {$meta->class} prohibits insert");
}
$query = $query instanceof Query\Insert ? $query : new Query\Insert(['values'=>$query]);
$query->values = $this->mapper->mapPropertiesToRow($meta, $query->values);
if (!$query->table) {
$query->table = $meta->table;
}
list ($sql, $params) = $query->buildQuery($meta);
// no need to formatParams here - they're already field names
$stmt = $this->getConnector()->prepare($sql);
$stmt->execute($params);
$lastInsertId = $this->getConnector()->lastInsertId();
return $lastInsertId;
}
|
[
"public",
"function",
"insertTable",
"(",
"$",
"meta",
",",
"$",
"query",
")",
"{",
"$",
"meta",
"=",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"meta",
":",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
";",
"if",
"(",
"!",
"$",
"meta",
"->",
"canInsert",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class {$meta->class} prohibits insert\"",
")",
";",
"}",
"$",
"query",
"=",
"$",
"query",
"instanceof",
"Query",
"\\",
"Insert",
"?",
"$",
"query",
":",
"new",
"Query",
"\\",
"Insert",
"(",
"[",
"'values'",
"=>",
"$",
"query",
"]",
")",
";",
"$",
"query",
"->",
"values",
"=",
"$",
"this",
"->",
"mapper",
"->",
"mapPropertiesToRow",
"(",
"$",
"meta",
",",
"$",
"query",
"->",
"values",
")",
";",
"if",
"(",
"!",
"$",
"query",
"->",
"table",
")",
"{",
"$",
"query",
"->",
"table",
"=",
"$",
"meta",
"->",
"table",
";",
"}",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"query",
"->",
"buildQuery",
"(",
"$",
"meta",
")",
";",
"// no need to formatParams here - they're already field names",
"$",
"stmt",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"$",
"lastInsertId",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"lastInsertId",
"(",
")",
";",
"return",
"$",
"lastInsertId",
";",
"}"
] |
Insert values into a table
insertTable ( $meta , array $propertyValues );
insertTable ( $meta , Query\Insert $query );
- $meta can be an instance of Amiss\Meta or a class name.
- $propertyValues keys must exist in the corresponding Meta.
@return int|null
|
[
"Insert",
"values",
"into",
"a",
"table"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L541-L561
|
21,623 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.insert
|
public function insert($object, $meta=null)
{
$query = new Query\Insert;
if (is_array($meta)) {
throw new \BadMethodCallException("Please use insertTable()");
}
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->canInsert) {
throw new Exception("Meta {$meta->id} prohibits insert");
}
event_before: {
if (isset($meta->on['beforeInsert'])) {
foreach ($meta->on['beforeInsert'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeInsert'])) {
foreach ($this->on['beforeInsert'] as $cb) { $cb($object, $meta); }
}
}
query: {
$query->values = $this->mapper->mapObjectToRow($object, $meta, 'insert');
if (!$query->table) {
$query->table = $meta->table;
}
list ($sql, $params, $props) = $query->buildQuery($meta);
$stmt = $this->getConnector()->prepare($sql);
$stmt->execute($params);
}
$lastInsertId = null;
// we need to be careful with "lastInsertId": SQLite generates one even without a PRIMARY
if ($object && $meta->primary) {
$lastInsertId = $this->getConnector()->lastInsertId();
if ($lastInsertId && $meta->autoinc) {
$field = $meta->fields[$meta->autoinc];
$handler = $this->mapper->determineTypeHandler(Mapper::AUTOINC_TYPE);
if (!$handler) {
throw new \UnexpectedValueException();
}
$meta->setValue($object, $meta->autoinc, $lastInsertId);
}
}
event_after: {
if (isset($meta->on['afterInsert'])) {
foreach ($meta->on['afterInsert'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterInsert'])) {
foreach ($this->on['afterInsert'] as $cb) { $cb($object, $meta); }
}
}
return $lastInsertId;
}
|
php
|
public function insert($object, $meta=null)
{
$query = new Query\Insert;
if (is_array($meta)) {
throw new \BadMethodCallException("Please use insertTable()");
}
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->canInsert) {
throw new Exception("Meta {$meta->id} prohibits insert");
}
event_before: {
if (isset($meta->on['beforeInsert'])) {
foreach ($meta->on['beforeInsert'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeInsert'])) {
foreach ($this->on['beforeInsert'] as $cb) { $cb($object, $meta); }
}
}
query: {
$query->values = $this->mapper->mapObjectToRow($object, $meta, 'insert');
if (!$query->table) {
$query->table = $meta->table;
}
list ($sql, $params, $props) = $query->buildQuery($meta);
$stmt = $this->getConnector()->prepare($sql);
$stmt->execute($params);
}
$lastInsertId = null;
// we need to be careful with "lastInsertId": SQLite generates one even without a PRIMARY
if ($object && $meta->primary) {
$lastInsertId = $this->getConnector()->lastInsertId();
if ($lastInsertId && $meta->autoinc) {
$field = $meta->fields[$meta->autoinc];
$handler = $this->mapper->determineTypeHandler(Mapper::AUTOINC_TYPE);
if (!$handler) {
throw new \UnexpectedValueException();
}
$meta->setValue($object, $meta->autoinc, $lastInsertId);
}
}
event_after: {
if (isset($meta->on['afterInsert'])) {
foreach ($meta->on['afterInsert'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterInsert'])) {
foreach ($this->on['afterInsert'] as $cb) { $cb($object, $meta); }
}
}
return $lastInsertId;
}
|
[
"public",
"function",
"insert",
"(",
"$",
"object",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"\\",
"Insert",
";",
"if",
"(",
"is_array",
"(",
"$",
"meta",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"Please use insertTable()\"",
")",
";",
"}",
"if",
"(",
"$",
"meta",
")",
"{",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"->",
"canInsert",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Meta {$meta->id} prohibits insert\"",
")",
";",
"}",
"event_before",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeInsert'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeInsert'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeInsert'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeInsert'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"query",
":",
"{",
"$",
"query",
"->",
"values",
"=",
"$",
"this",
"->",
"mapper",
"->",
"mapObjectToRow",
"(",
"$",
"object",
",",
"$",
"meta",
",",
"'insert'",
")",
";",
"if",
"(",
"!",
"$",
"query",
"->",
"table",
")",
"{",
"$",
"query",
"->",
"table",
"=",
"$",
"meta",
"->",
"table",
";",
"}",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"props",
")",
"=",
"$",
"query",
"->",
"buildQuery",
"(",
"$",
"meta",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"}",
"$",
"lastInsertId",
"=",
"null",
";",
"// we need to be careful with \"lastInsertId\": SQLite generates one even without a PRIMARY",
"if",
"(",
"$",
"object",
"&&",
"$",
"meta",
"->",
"primary",
")",
"{",
"$",
"lastInsertId",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"lastInsertId",
"(",
")",
";",
"if",
"(",
"$",
"lastInsertId",
"&&",
"$",
"meta",
"->",
"autoinc",
")",
"{",
"$",
"field",
"=",
"$",
"meta",
"->",
"fields",
"[",
"$",
"meta",
"->",
"autoinc",
"]",
";",
"$",
"handler",
"=",
"$",
"this",
"->",
"mapper",
"->",
"determineTypeHandler",
"(",
"Mapper",
"::",
"AUTOINC_TYPE",
")",
";",
"if",
"(",
"!",
"$",
"handler",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
")",
";",
"}",
"$",
"meta",
"->",
"setValue",
"(",
"$",
"object",
",",
"$",
"meta",
"->",
"autoinc",
",",
"$",
"lastInsertId",
")",
";",
"}",
"}",
"event_after",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterInsert'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterInsert'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterInsert'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterInsert'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"return",
"$",
"lastInsertId",
";",
"}"
] |
Insert an object into the database, or values into a table
insert($object)
insert($object, Meta $meta)
@return int|null
|
[
"Insert",
"an",
"object",
"into",
"the",
"database",
"or",
"values",
"into",
"a",
"table"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L571-L634
|
21,624 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.updateTable
|
public function updateTable($meta, ...$args)
{
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
if (!$meta->canUpdate) {
throw new Exception("Meta {$meta->id} prohibits update");
}
$query = Query\Update::fromParamArgs($args);
if (!$query->set) {
throw new \InvalidArgumentException("Query missing 'set' values");
}
list ($sql, $params, $setProps, $whereProps) = $query->buildQuery($meta);
if ($setProps) {
$params = $this->mapper->formatParams($meta, $setProps, $params);
}
if ($whereProps) {
$params = $this->mapper->formatParams($meta, $whereProps, $params);
}
return $this->getConnector()->exec($sql, $params);
}
|
php
|
public function updateTable($meta, ...$args)
{
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
if (!$meta->canUpdate) {
throw new Exception("Meta {$meta->id} prohibits update");
}
$query = Query\Update::fromParamArgs($args);
if (!$query->set) {
throw new \InvalidArgumentException("Query missing 'set' values");
}
list ($sql, $params, $setProps, $whereProps) = $query->buildQuery($meta);
if ($setProps) {
$params = $this->mapper->formatParams($meta, $setProps, $params);
}
if ($whereProps) {
$params = $this->mapper->formatParams($meta, $whereProps, $params);
}
return $this->getConnector()->exec($sql, $params);
}
|
[
"public",
"function",
"updateTable",
"(",
"$",
"meta",
",",
"...",
"$",
"args",
")",
"{",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"if",
"(",
"!",
"$",
"meta",
"->",
"canUpdate",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Meta {$meta->id} prohibits update\"",
")",
";",
"}",
"$",
"query",
"=",
"Query",
"\\",
"Update",
"::",
"fromParamArgs",
"(",
"$",
"args",
")",
";",
"if",
"(",
"!",
"$",
"query",
"->",
"set",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Query missing 'set' values\"",
")",
";",
"}",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"setProps",
",",
"$",
"whereProps",
")",
"=",
"$",
"query",
"->",
"buildQuery",
"(",
"$",
"meta",
")",
";",
"if",
"(",
"$",
"setProps",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"mapper",
"->",
"formatParams",
"(",
"$",
"meta",
",",
"$",
"setProps",
",",
"$",
"params",
")",
";",
"}",
"if",
"(",
"$",
"whereProps",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"mapper",
"->",
"formatParams",
"(",
"$",
"meta",
",",
"$",
"whereProps",
",",
"$",
"params",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"exec",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Update a table by criteria.
updateTable ( $meta , array $values , $criteria... )
updateTable ( $meta , Query\Update $query , $criteria... )
@return void
|
[
"Update",
"a",
"table",
"by",
"criteria",
"."
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L644-L665
|
21,625 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.update
|
public function update($object, $meta=null)
{
$query = new Query\Update();
if (!is_object($object)) {
throw new \BadMethodCallException("Please use updateTable()");
}
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->primary) {
throw new Exception("Cannot update: meta {$meta->id} has no primary key");
}
if (!$meta->canUpdate) {
throw new Exception("Meta {$meta->id} prohibits update");
}
event_before: {
if (isset($meta->on['beforeUpdate'])) {
foreach ($meta->on['beforeUpdate'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeUpdate'])) {
foreach ($this->on['beforeUpdate'] as $cb) { $cb($object, $meta); }
}
}
query: {
$query->set = $this->mapper->mapObjectToRow($object, $meta, 'update');
$query->where = $meta->getIndexValue($object);
list ($sql, $params, $props) = $query->buildQuery($meta);
// don't need to do formatParams - it's already covered by the mapPropertiesToRow call in
// table update mode
$return = $this->getConnector()->exec($sql, $params);
}
event_after: {
if (isset($meta->on['afterUpdate'])) {
foreach ($meta->on['afterUpdate'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterUpdate'])) {
foreach ($this->on['afterUpdate'] as $cb) { $cb($object, $meta); }
}
}
return $return;
}
|
php
|
public function update($object, $meta=null)
{
$query = new Query\Update();
if (!is_object($object)) {
throw new \BadMethodCallException("Please use updateTable()");
}
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->primary) {
throw new Exception("Cannot update: meta {$meta->id} has no primary key");
}
if (!$meta->canUpdate) {
throw new Exception("Meta {$meta->id} prohibits update");
}
event_before: {
if (isset($meta->on['beforeUpdate'])) {
foreach ($meta->on['beforeUpdate'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeUpdate'])) {
foreach ($this->on['beforeUpdate'] as $cb) { $cb($object, $meta); }
}
}
query: {
$query->set = $this->mapper->mapObjectToRow($object, $meta, 'update');
$query->where = $meta->getIndexValue($object);
list ($sql, $params, $props) = $query->buildQuery($meta);
// don't need to do formatParams - it's already covered by the mapPropertiesToRow call in
// table update mode
$return = $this->getConnector()->exec($sql, $params);
}
event_after: {
if (isset($meta->on['afterUpdate'])) {
foreach ($meta->on['afterUpdate'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterUpdate'])) {
foreach ($this->on['afterUpdate'] as $cb) { $cb($object, $meta); }
}
}
return $return;
}
|
[
"public",
"function",
"update",
"(",
"$",
"object",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"\\",
"Update",
"(",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"Please use updateTable()\"",
")",
";",
"}",
"if",
"(",
"$",
"meta",
")",
"{",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"->",
"primary",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Cannot update: meta {$meta->id} has no primary key\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"->",
"canUpdate",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Meta {$meta->id} prohibits update\"",
")",
";",
"}",
"event_before",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeUpdate'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeUpdate'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeUpdate'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeUpdate'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"query",
":",
"{",
"$",
"query",
"->",
"set",
"=",
"$",
"this",
"->",
"mapper",
"->",
"mapObjectToRow",
"(",
"$",
"object",
",",
"$",
"meta",
",",
"'update'",
")",
";",
"$",
"query",
"->",
"where",
"=",
"$",
"meta",
"->",
"getIndexValue",
"(",
"$",
"object",
")",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"props",
")",
"=",
"$",
"query",
"->",
"buildQuery",
"(",
"$",
"meta",
")",
";",
"// don't need to do formatParams - it's already covered by the mapPropertiesToRow call in",
"// table update mode",
"$",
"return",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"exec",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"event_after",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterUpdate'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterUpdate'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterUpdate'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterUpdate'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Update an object in the database, or update a table by criteria.
update ( $object )
update ( $object , $meta )
@return void
|
[
"Update",
"an",
"object",
"in",
"the",
"database",
"or",
"update",
"a",
"table",
"by",
"criteria",
"."
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L675-L724
|
21,626 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.deleteTable
|
public function deleteTable($meta, ...$args)
{
if (!isset($args[0])) {
throw new \InvalidArgumentException("Cannot delete from table without a condition (pass the string '1=1' if you really meant to do this)");
}
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
if (!$meta->canDelete) {
throw new Exception("Meta {$meta->id} prohibits update");
}
$query = Query\Criteria::fromParamArgs($args);
return $this->executeDelete($meta, $query);
}
|
php
|
public function deleteTable($meta, ...$args)
{
if (!isset($args[0])) {
throw new \InvalidArgumentException("Cannot delete from table without a condition (pass the string '1=1' if you really meant to do this)");
}
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
if (!$meta->canDelete) {
throw new Exception("Meta {$meta->id} prohibits update");
}
$query = Query\Criteria::fromParamArgs($args);
return $this->executeDelete($meta, $query);
}
|
[
"public",
"function",
"deleteTable",
"(",
"$",
"meta",
",",
"...",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot delete from table without a condition (pass the string '1=1' if you really meant to do this)\"",
")",
";",
"}",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"if",
"(",
"!",
"$",
"meta",
"->",
"canDelete",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Meta {$meta->id} prohibits update\"",
")",
";",
"}",
"$",
"query",
"=",
"Query",
"\\",
"Criteria",
"::",
"fromParamArgs",
"(",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"executeDelete",
"(",
"$",
"meta",
",",
"$",
"query",
")",
";",
"}"
] |
Delete from a table by criteria
deleteTable ( $meta , $criteria... );
@return void
|
[
"Delete",
"from",
"a",
"table",
"by",
"criteria"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L733-L744
|
21,627 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.delete
|
public function delete($object, $meta=null)
{
$query = new Query\Criteria();
if (!is_object($object)) {
throw new \BadMethodCallException("Please use deleteTable()");
}
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->canDelete) {
throw new Exception("Meta {$meta->id} prohibits delete");
}
event_before: {
if (isset($meta->on['beforeDelete'])) {
foreach ($meta->on['beforeDelete'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeDelete'])) {
foreach ($this->on['beforeDelete'] as $cb) { $cb($object, $meta); }
}
}
$query->where = $meta->getIndexValue($object);
$return = $this->executeDelete($meta, $query);
event_after: {
if (isset($meta->on['afterDelete'])) {
foreach ($meta->on['afterDelete'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterDelete'])) {
foreach ($this->on['afterDelete'] as $cb) { $cb($object, $meta); }
}
}
return $return;
}
|
php
|
public function delete($object, $meta=null)
{
$query = new Query\Criteria();
if (!is_object($object)) {
throw new \BadMethodCallException("Please use deleteTable()");
}
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->canDelete) {
throw new Exception("Meta {$meta->id} prohibits delete");
}
event_before: {
if (isset($meta->on['beforeDelete'])) {
foreach ($meta->on['beforeDelete'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeDelete'])) {
foreach ($this->on['beforeDelete'] as $cb) { $cb($object, $meta); }
}
}
$query->where = $meta->getIndexValue($object);
$return = $this->executeDelete($meta, $query);
event_after: {
if (isset($meta->on['afterDelete'])) {
foreach ($meta->on['afterDelete'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterDelete'])) {
foreach ($this->on['afterDelete'] as $cb) { $cb($object, $meta); }
}
}
return $return;
}
|
[
"public",
"function",
"delete",
"(",
"$",
"object",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"\\",
"Criteria",
"(",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"Please use deleteTable()\"",
")",
";",
"}",
"if",
"(",
"$",
"meta",
")",
"{",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"->",
"canDelete",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Meta {$meta->id} prohibits delete\"",
")",
";",
"}",
"event_before",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeDelete'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeDelete'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeDelete'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeDelete'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"$",
"query",
"->",
"where",
"=",
"$",
"meta",
"->",
"getIndexValue",
"(",
"$",
"object",
")",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"executeDelete",
"(",
"$",
"meta",
",",
"$",
"query",
")",
";",
"event_after",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterDelete'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterDelete'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterDelete'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterDelete'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Delete an object from the database
delete ( $object )
delete ( $object, $meta )
@return void
|
[
"Delete",
"an",
"object",
"from",
"the",
"database"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L754-L794
|
21,628 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.save
|
public function save($object, $meta=null)
{
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->primary) {
throw new Exception("No primary key for {$meta->id}");
}
$shouldInsert = null;
$prival = null;
if ($meta->autoinc) {
$prival = $meta->getValue($object, $meta->autoinc);
$shouldInsert = !$prival;
} else {
$prival = $meta->getIndexValue($object);
}
event_before: {
if (isset($meta->on['beforeSave'])) {
foreach ($meta->on['beforeSave'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeSave'])) {
foreach ($this->on['beforeSave'] as $cb) { $cb($object, $meta); }
}
}
if ($shouldInsert === null) {
$newpri = $meta->getIndexValue($object);
$shouldInsert = $newpri != $prival;
}
if ($shouldInsert) {
$this->insert($object, $meta);
} else {
$this->update($object, $meta);
}
event_after: {
if (isset($meta->on['afterSave'])) {
foreach ($meta->on['afterSave'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterSave'])) {
foreach ($this->on['afterSave'] as $cb) { $cb($object, $meta); }
}
}
}
|
php
|
public function save($object, $meta=null)
{
if ($meta) {
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
} else {
$meta = $this->mapper->getMeta(get_class($object));
}
if (!$meta->primary) {
throw new Exception("No primary key for {$meta->id}");
}
$shouldInsert = null;
$prival = null;
if ($meta->autoinc) {
$prival = $meta->getValue($object, $meta->autoinc);
$shouldInsert = !$prival;
} else {
$prival = $meta->getIndexValue($object);
}
event_before: {
if (isset($meta->on['beforeSave'])) {
foreach ($meta->on['beforeSave'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['beforeSave'])) {
foreach ($this->on['beforeSave'] as $cb) { $cb($object, $meta); }
}
}
if ($shouldInsert === null) {
$newpri = $meta->getIndexValue($object);
$shouldInsert = $newpri != $prival;
}
if ($shouldInsert) {
$this->insert($object, $meta);
} else {
$this->update($object, $meta);
}
event_after: {
if (isset($meta->on['afterSave'])) {
foreach ($meta->on['afterSave'] as $cb) { $cb = [$object, $cb]; $cb(); }
}
if (isset($this->on['afterSave'])) {
foreach ($this->on['afterSave'] as $cb) { $cb($object, $meta); }
}
}
}
|
[
"public",
"function",
"save",
"(",
"$",
"object",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"meta",
")",
"{",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"}",
"else",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"->",
"primary",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"No primary key for {$meta->id}\"",
")",
";",
"}",
"$",
"shouldInsert",
"=",
"null",
";",
"$",
"prival",
"=",
"null",
";",
"if",
"(",
"$",
"meta",
"->",
"autoinc",
")",
"{",
"$",
"prival",
"=",
"$",
"meta",
"->",
"getValue",
"(",
"$",
"object",
",",
"$",
"meta",
"->",
"autoinc",
")",
";",
"$",
"shouldInsert",
"=",
"!",
"$",
"prival",
";",
"}",
"else",
"{",
"$",
"prival",
"=",
"$",
"meta",
"->",
"getIndexValue",
"(",
"$",
"object",
")",
";",
"}",
"event_before",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeSave'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'beforeSave'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeSave'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'beforeSave'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"shouldInsert",
"===",
"null",
")",
"{",
"$",
"newpri",
"=",
"$",
"meta",
"->",
"getIndexValue",
"(",
"$",
"object",
")",
";",
"$",
"shouldInsert",
"=",
"$",
"newpri",
"!=",
"$",
"prival",
";",
"}",
"if",
"(",
"$",
"shouldInsert",
")",
"{",
"$",
"this",
"->",
"insert",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"update",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"event_after",
":",
"{",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterSave'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"meta",
"->",
"on",
"[",
"'afterSave'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"=",
"[",
"$",
"object",
",",
"$",
"cb",
"]",
";",
"$",
"cb",
"(",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterSave'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"on",
"[",
"'afterSave'",
"]",
"as",
"$",
"cb",
")",
"{",
"$",
"cb",
"(",
"$",
"object",
",",
"$",
"meta",
")",
";",
"}",
"}",
"}",
"}"
] |
If an object has an autoincrement primary key, insert or update as necessary.
@return void
|
[
"If",
"an",
"object",
"has",
"an",
"autoincrement",
"primary",
"key",
"insert",
"or",
"update",
"as",
"necessary",
"."
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L809-L858
|
21,629 |
shabbyrobe/amiss
|
src/Sql/Manager.php
|
Manager.createKeyCriteria
|
public function createKeyCriteria($meta, $id, $indexId=null)
{
if ($indexId == null) {
$indexId = 'primary';
}
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
if (!isset($meta->indexes[$indexId])) {
throw new Exception("Index $indexId does not exist on meta {$meta->id}");
}
$index = $meta->indexes[$indexId];
if (!$index['key']) {
throw new Exception("Index $indexId is not a key index for meta {$meta->id}");
}
if (!is_array($id)) {
$id = array($id);
}
$where = array();
foreach ($index['fields'] as $idx=>$p) {
$idVal = isset($id[$p]) ? $id[$p] : (isset($id[$idx]) ? $id[$idx] : null);
if (!$idVal) {
throw new \InvalidArgumentException("Couldn't get ID value when getting {$meta->id} by index '{$indexId}'");
}
$where[$p] = $idVal;
}
return array('where'=>$where);
}
|
php
|
public function createKeyCriteria($meta, $id, $indexId=null)
{
if ($indexId == null) {
$indexId = 'primary';
}
$meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
if (!isset($meta->indexes[$indexId])) {
throw new Exception("Index $indexId does not exist on meta {$meta->id}");
}
$index = $meta->indexes[$indexId];
if (!$index['key']) {
throw new Exception("Index $indexId is not a key index for meta {$meta->id}");
}
if (!is_array($id)) {
$id = array($id);
}
$where = array();
foreach ($index['fields'] as $idx=>$p) {
$idVal = isset($id[$p]) ? $id[$p] : (isset($id[$idx]) ? $id[$idx] : null);
if (!$idVal) {
throw new \InvalidArgumentException("Couldn't get ID value when getting {$meta->id} by index '{$indexId}'");
}
$where[$p] = $idVal;
}
return array('where'=>$where);
}
|
[
"public",
"function",
"createKeyCriteria",
"(",
"$",
"meta",
",",
"$",
"id",
",",
"$",
"indexId",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"indexId",
"==",
"null",
")",
"{",
"$",
"indexId",
"=",
"'primary'",
";",
"}",
"$",
"meta",
"=",
"!",
"$",
"meta",
"instanceof",
"Meta",
"?",
"$",
"this",
"->",
"mapper",
"->",
"getMeta",
"(",
"$",
"meta",
")",
":",
"$",
"meta",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"meta",
"->",
"indexes",
"[",
"$",
"indexId",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Index $indexId does not exist on meta {$meta->id}\"",
")",
";",
"}",
"$",
"index",
"=",
"$",
"meta",
"->",
"indexes",
"[",
"$",
"indexId",
"]",
";",
"if",
"(",
"!",
"$",
"index",
"[",
"'key'",
"]",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Index $indexId is not a key index for meta {$meta->id}\"",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"id",
")",
")",
"{",
"$",
"id",
"=",
"array",
"(",
"$",
"id",
")",
";",
"}",
"$",
"where",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"index",
"[",
"'fields'",
"]",
"as",
"$",
"idx",
"=>",
"$",
"p",
")",
"{",
"$",
"idVal",
"=",
"isset",
"(",
"$",
"id",
"[",
"$",
"p",
"]",
")",
"?",
"$",
"id",
"[",
"$",
"p",
"]",
":",
"(",
"isset",
"(",
"$",
"id",
"[",
"$",
"idx",
"]",
")",
"?",
"$",
"id",
"[",
"$",
"idx",
"]",
":",
"null",
")",
";",
"if",
"(",
"!",
"$",
"idVal",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Couldn't get ID value when getting {$meta->id} by index '{$indexId}'\"",
")",
";",
"}",
"$",
"where",
"[",
"$",
"p",
"]",
"=",
"$",
"idVal",
";",
"}",
"return",
"array",
"(",
"'where'",
"=>",
"$",
"where",
")",
";",
"}"
] |
Creates an array criteria for a key index
@param mixed $meta Meta or class name
@return array Criteria
|
[
"Creates",
"an",
"array",
"criteria",
"for",
"a",
"key",
"index"
] |
ba261f0d1f985ed36e9fd2903ac0df86c5b9498d
|
https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Manager.php#L865-L892
|
21,630 |
getuisdk/getui-php-sdk
|
src/PBInputStringReader.php
|
PBInputStringReader.next
|
public function next($is_string = false)
{
$package = '';
while (true) {
if ($this->pointer >= $this->length) {
return false;
}
$string = $this->string[$this->pointer];
$this->pointer++;
if ($is_string === true) {
return ord($string);
}
$value = decbin(ord($string));
if ($value >= 10000000 && $is_string === false) {
// now fill to eight with 00
$package .= $value;
} else {
// now fill to length of eight with 0
$value = substr('00000000', 0, 8 - strlen($value) % 8) . $value;
return $this->base128->getValue($package . $value);
}
}
return $package;
}
|
php
|
public function next($is_string = false)
{
$package = '';
while (true) {
if ($this->pointer >= $this->length) {
return false;
}
$string = $this->string[$this->pointer];
$this->pointer++;
if ($is_string === true) {
return ord($string);
}
$value = decbin(ord($string));
if ($value >= 10000000 && $is_string === false) {
// now fill to eight with 00
$package .= $value;
} else {
// now fill to length of eight with 0
$value = substr('00000000', 0, 8 - strlen($value) % 8) . $value;
return $this->base128->getValue($package . $value);
}
}
return $package;
}
|
[
"public",
"function",
"next",
"(",
"$",
"is_string",
"=",
"false",
")",
"{",
"$",
"package",
"=",
"''",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pointer",
">=",
"$",
"this",
"->",
"length",
")",
"{",
"return",
"false",
";",
"}",
"$",
"string",
"=",
"$",
"this",
"->",
"string",
"[",
"$",
"this",
"->",
"pointer",
"]",
";",
"$",
"this",
"->",
"pointer",
"++",
";",
"if",
"(",
"$",
"is_string",
"===",
"true",
")",
"{",
"return",
"ord",
"(",
"$",
"string",
")",
";",
"}",
"$",
"value",
"=",
"decbin",
"(",
"ord",
"(",
"$",
"string",
")",
")",
";",
"if",
"(",
"$",
"value",
">=",
"10000000",
"&&",
"$",
"is_string",
"===",
"false",
")",
"{",
"// now fill to eight with 00\r",
"$",
"package",
".=",
"$",
"value",
";",
"}",
"else",
"{",
"// now fill to length of eight with 0\r",
"$",
"value",
"=",
"substr",
"(",
"'00000000'",
",",
"0",
",",
"8",
"-",
"strlen",
"(",
"$",
"value",
")",
"%",
"8",
")",
".",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"base128",
"->",
"getValue",
"(",
"$",
"package",
".",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"package",
";",
"}"
] |
get the next
@param boolean $is_string - if set to true only one byte is read
@return mixed
|
[
"get",
"the",
"next"
] |
e91773b099bcbfd7492a44086b373d1c9fee37e2
|
https://github.com/getuisdk/getui-php-sdk/blob/e91773b099bcbfd7492a44086b373d1c9fee37e2/src/PBInputStringReader.php#L30-L57
|
21,631 |
sinri/Ark-Core
|
src/ArkHelper.php
|
ArkHelper.registerAutoload
|
public static function registerAutoload($base_namespace, $base_path, $extension = '.php')
{
spl_autoload_register(function ($class_name) use ($base_namespace, $base_path, $extension) {
$file_path = self::getFilePathForClassName(
$class_name,
$base_namespace,
$base_path,
$extension
);
if ($file_path) {
/** @noinspection PhpIncludeInspection */
require_once $file_path;
}
});
}
|
php
|
public static function registerAutoload($base_namespace, $base_path, $extension = '.php')
{
spl_autoload_register(function ($class_name) use ($base_namespace, $base_path, $extension) {
$file_path = self::getFilePathForClassName(
$class_name,
$base_namespace,
$base_path,
$extension
);
if ($file_path) {
/** @noinspection PhpIncludeInspection */
require_once $file_path;
}
});
}
|
[
"public",
"static",
"function",
"registerAutoload",
"(",
"$",
"base_namespace",
",",
"$",
"base_path",
",",
"$",
"extension",
"=",
"'.php'",
")",
"{",
"spl_autoload_register",
"(",
"function",
"(",
"$",
"class_name",
")",
"use",
"(",
"$",
"base_namespace",
",",
"$",
"base_path",
",",
"$",
"extension",
")",
"{",
"$",
"file_path",
"=",
"self",
"::",
"getFilePathForClassName",
"(",
"$",
"class_name",
",",
"$",
"base_namespace",
",",
"$",
"base_path",
",",
"$",
"extension",
")",
";",
"if",
"(",
"$",
"file_path",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"require_once",
"$",
"file_path",
";",
"}",
"}",
")",
";",
"}"
] |
For Autoload File
@param string $base_namespace such as sinri\enoch
@param string $base_path /code/sinri/enoch
@param string $extension
|
[
"For",
"Autoload",
"File"
] |
fb5715e72b500ddc08dd52d9701d713fe49f48c6
|
https://github.com/sinri/Ark-Core/blob/fb5715e72b500ddc08dd52d9701d713fe49f48c6/src/ArkHelper.php#L39-L53
|
21,632 |
sinri/Ark-Core
|
src/ArkHelper.php
|
ArkHelper.removeFromArray
|
public static function removeFromArray(&$array, $keychain)
{
if (!is_array($array)) {
$array = [];
}
if (!is_array($keychain)) {
$keychain = [$keychain];
}
$headKey = array_shift($keychain);
if (empty($keychain)) {
//last
unset($array[$headKey]);
} else {
//not last
if (isset($array[$headKey])) {
self::removeFromArray($array[$headKey], $keychain);
}
}
}
|
php
|
public static function removeFromArray(&$array, $keychain)
{
if (!is_array($array)) {
$array = [];
}
if (!is_array($keychain)) {
$keychain = [$keychain];
}
$headKey = array_shift($keychain);
if (empty($keychain)) {
//last
unset($array[$headKey]);
} else {
//not last
if (isset($array[$headKey])) {
self::removeFromArray($array[$headKey], $keychain);
}
}
}
|
[
"public",
"static",
"function",
"removeFromArray",
"(",
"&",
"$",
"array",
",",
"$",
"keychain",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keychain",
")",
")",
"{",
"$",
"keychain",
"=",
"[",
"$",
"keychain",
"]",
";",
"}",
"$",
"headKey",
"=",
"array_shift",
"(",
"$",
"keychain",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"keychain",
")",
")",
"{",
"//last",
"unset",
"(",
"$",
"array",
"[",
"$",
"headKey",
"]",
")",
";",
"}",
"else",
"{",
"//not last",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"headKey",
"]",
")",
")",
"{",
"self",
"::",
"removeFromArray",
"(",
"$",
"array",
"[",
"$",
"headKey",
"]",
",",
"$",
"keychain",
")",
";",
"}",
"}",
"}"
] |
Unset item and nested item in array
@since 1.2
@param array $array
@param array|string|int $keychain
|
[
"Unset",
"item",
"and",
"nested",
"item",
"in",
"array"
] |
fb5715e72b500ddc08dd52d9701d713fe49f48c6
|
https://github.com/sinri/Ark-Core/blob/fb5715e72b500ddc08dd52d9701d713fe49f48c6/src/ArkHelper.php#L154-L173
|
21,633 |
frdl/webfan
|
.ApplicationComposer/lib/frdl/ApplicationComposer/ApplicationComposerBootstrap.php
|
ApplicationComposerBootstrap.wd
|
public function wd($dir = null, $code = E_USER_WARNING){
if(null !== $dir && is_dir($dir)){
$this->wd = $dir;
if(chdir($dir) === false){
throw new \Exception('Cannot change to directory '.$dir.' in '.__METHOD__, $code);
return $this;
}
}else{
$dir = $this->wd;
}
return $this;
}
|
php
|
public function wd($dir = null, $code = E_USER_WARNING){
if(null !== $dir && is_dir($dir)){
$this->wd = $dir;
if(chdir($dir) === false){
throw new \Exception('Cannot change to directory '.$dir.' in '.__METHOD__, $code);
return $this;
}
}else{
$dir = $this->wd;
}
return $this;
}
|
[
"public",
"function",
"wd",
"(",
"$",
"dir",
"=",
"null",
",",
"$",
"code",
"=",
"E_USER_WARNING",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"dir",
"&&",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"this",
"->",
"wd",
"=",
"$",
"dir",
";",
"if",
"(",
"chdir",
"(",
"$",
"dir",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot change to directory '",
".",
"$",
"dir",
".",
"' in '",
".",
"__METHOD__",
",",
"$",
"code",
")",
";",
"return",
"$",
"this",
";",
"}",
"}",
"else",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"wd",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
set working directory
|
[
"set",
"working",
"directory"
] |
84d270377685224e891cd9d571b103b36f05b845
|
https://github.com/frdl/webfan/blob/84d270377685224e891cd9d571b103b36f05b845/.ApplicationComposer/lib/frdl/ApplicationComposer/ApplicationComposerBootstrap.php#L67-L78
|
21,634 |
unclecheese/silverstripe-bootstrap-tagfield
|
code/BootstrapTagField.php
|
BootstrapTagField.formatJSON
|
protected function formatJSON(SS_List $list) {
$ret = array ();
foreach($list as $item) {
$ret[] = array(
'id' => $item->{$this->idField},
'label' => $item->{$this->labelField}
);
}
return Convert::array2json($ret);
}
|
php
|
protected function formatJSON(SS_List $list) {
$ret = array ();
foreach($list as $item) {
$ret[] = array(
'id' => $item->{$this->idField},
'label' => $item->{$this->labelField}
);
}
return Convert::array2json($ret);
}
|
[
"protected",
"function",
"formatJSON",
"(",
"SS_List",
"$",
"list",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"item",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"item",
"->",
"{",
"$",
"this",
"->",
"idField",
"}",
",",
"'label'",
"=>",
"$",
"item",
"->",
"{",
"$",
"this",
"->",
"labelField",
"}",
")",
";",
"}",
"return",
"Convert",
"::",
"array2json",
"(",
"$",
"ret",
")",
";",
"}"
] |
Formats JSON so that it is usable by the JS component
@param SS_List $list The list to format
@return string JSON
|
[
"Formats",
"JSON",
"so",
"that",
"it",
"is",
"usable",
"by",
"the",
"JS",
"component"
] |
ada0c647f90ccb753d26a5d01889b2b4fbe2af76
|
https://github.com/unclecheese/silverstripe-bootstrap-tagfield/blob/ada0c647f90ccb753d26a5d01889b2b4fbe2af76/code/BootstrapTagField.php#L80-L90
|
21,635 |
unclecheese/silverstripe-bootstrap-tagfield
|
code/BootstrapTagField.php
|
BootstrapTagField.query
|
public function query(SS_HTTPRequest $r) {
return $this->formatJSON($this->source->filter(array(
$this->labelField.':PartialMatch' => $r->getVar('q')
))
->limit(10));
}
|
php
|
public function query(SS_HTTPRequest $r) {
return $this->formatJSON($this->source->filter(array(
$this->labelField.':PartialMatch' => $r->getVar('q')
))
->limit(10));
}
|
[
"public",
"function",
"query",
"(",
"SS_HTTPRequest",
"$",
"r",
")",
"{",
"return",
"$",
"this",
"->",
"formatJSON",
"(",
"$",
"this",
"->",
"source",
"->",
"filter",
"(",
"array",
"(",
"$",
"this",
"->",
"labelField",
".",
"':PartialMatch'",
"=>",
"$",
"r",
"->",
"getVar",
"(",
"'q'",
")",
")",
")",
"->",
"limit",
"(",
"10",
")",
")",
";",
"}"
] |
An AJAX endpoint for querying the typeahead
@param SS_HTTPRequest $r The request
@return string JSON
|
[
"An",
"AJAX",
"endpoint",
"for",
"querying",
"the",
"typeahead"
] |
ada0c647f90ccb753d26a5d01889b2b4fbe2af76
|
https://github.com/unclecheese/silverstripe-bootstrap-tagfield/blob/ada0c647f90ccb753d26a5d01889b2b4fbe2af76/code/BootstrapTagField.php#L98-L103
|
21,636 |
unclecheese/silverstripe-bootstrap-tagfield
|
code/BootstrapTagField.php
|
BootstrapTagField.getValuesJSON
|
protected function getValuesJSON() {
$value = $this->value;
if($value instanceof SS_List) {
$values = $value->column($this->idField);
}
else if(is_array($value)) {
$values = array_keys($value);
}
else if(is_string($value)) {
$values = explode(',', $value);
$values = str_replace('{comma}', ',', $values);
}
return $this->formatJSON($this->source->filter(array(
$this->idField => $values
)));
}
|
php
|
protected function getValuesJSON() {
$value = $this->value;
if($value instanceof SS_List) {
$values = $value->column($this->idField);
}
else if(is_array($value)) {
$values = array_keys($value);
}
else if(is_string($value)) {
$values = explode(',', $value);
$values = str_replace('{comma}', ',', $values);
}
return $this->formatJSON($this->source->filter(array(
$this->idField => $values
)));
}
|
[
"protected",
"function",
"getValuesJSON",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"$",
"value",
"instanceof",
"SS_List",
")",
"{",
"$",
"values",
"=",
"$",
"value",
"->",
"column",
"(",
"$",
"this",
"->",
"idField",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"values",
"=",
"array_keys",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"values",
"=",
"str_replace",
"(",
"'{comma}'",
",",
"','",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatJSON",
"(",
"$",
"this",
"->",
"source",
"->",
"filter",
"(",
"array",
"(",
"$",
"this",
"->",
"idField",
"=>",
"$",
"values",
")",
")",
")",
";",
"}"
] |
Gets the current values assigned to the field, formatted as a JSON array
@return string JSON
|
[
"Gets",
"the",
"current",
"values",
"assigned",
"to",
"the",
"field",
"formatted",
"as",
"a",
"JSON",
"array"
] |
ada0c647f90ccb753d26a5d01889b2b4fbe2af76
|
https://github.com/unclecheese/silverstripe-bootstrap-tagfield/blob/ada0c647f90ccb753d26a5d01889b2b4fbe2af76/code/BootstrapTagField.php#L122-L138
|
21,637 |
unclecheese/silverstripe-bootstrap-tagfield
|
code/BootstrapTagField.php
|
BootstrapTagField.setPrefetch
|
public function setPrefetch(SS_List $list) {
if(!$list instanceof SS_List) {
throw new Exception('Prefetch list must be an instance of SS_List');
}
$this->prefetch = $list;
return $this;
}
|
php
|
public function setPrefetch(SS_List $list) {
if(!$list instanceof SS_List) {
throw new Exception('Prefetch list must be an instance of SS_List');
}
$this->prefetch = $list;
return $this;
}
|
[
"public",
"function",
"setPrefetch",
"(",
"SS_List",
"$",
"list",
")",
"{",
"if",
"(",
"!",
"$",
"list",
"instanceof",
"SS_List",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Prefetch list must be an instance of SS_List'",
")",
";",
"}",
"$",
"this",
"->",
"prefetch",
"=",
"$",
"list",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the prefetch records list
@param SS_List $list
@return BootstrapTagField
|
[
"Sets",
"the",
"prefetch",
"records",
"list"
] |
ada0c647f90ccb753d26a5d01889b2b4fbe2af76
|
https://github.com/unclecheese/silverstripe-bootstrap-tagfield/blob/ada0c647f90ccb753d26a5d01889b2b4fbe2af76/code/BootstrapTagField.php#L146-L154
|
21,638 |
unclecheese/silverstripe-bootstrap-tagfield
|
code/BootstrapTagField.php
|
BootstrapTagField.Field
|
public function Field($properties = array()) {
Requirements::javascript(BOOTSTRAP_TAGFIELD_DIR.'/javascript/typeahead.js');
Requirements::javascript(BOOTSTRAP_TAGFIELD_DIR.'/javascript/bootstrap-tagfield.js');
Requirements::javascript(BOOTSTRAP_TAGFIELD_DIR.'/javascript/bootstrap-tagfield-init.js');
Requirements::css(BOOTSTRAP_TAGFIELD_DIR.'/css/bootstrap-tagfield.css');
$this->setAttribute('data-value', $this->getValuesJSON())
->setAttribute('data-bootstrap-tags', true)
->setAttribute('data-query-url', $this->Link('query'))
->setAttribute('data-prefetch-url', $this->Link('prefetch'))
->setAttribute('data-freeinput', $this->freeInput)
->setAttribute('class', 'text');
return $this->renderWith(
$this->getTemplates()
);
}
|
php
|
public function Field($properties = array()) {
Requirements::javascript(BOOTSTRAP_TAGFIELD_DIR.'/javascript/typeahead.js');
Requirements::javascript(BOOTSTRAP_TAGFIELD_DIR.'/javascript/bootstrap-tagfield.js');
Requirements::javascript(BOOTSTRAP_TAGFIELD_DIR.'/javascript/bootstrap-tagfield-init.js');
Requirements::css(BOOTSTRAP_TAGFIELD_DIR.'/css/bootstrap-tagfield.css');
$this->setAttribute('data-value', $this->getValuesJSON())
->setAttribute('data-bootstrap-tags', true)
->setAttribute('data-query-url', $this->Link('query'))
->setAttribute('data-prefetch-url', $this->Link('prefetch'))
->setAttribute('data-freeinput', $this->freeInput)
->setAttribute('class', 'text');
return $this->renderWith(
$this->getTemplates()
);
}
|
[
"public",
"function",
"Field",
"(",
"$",
"properties",
"=",
"array",
"(",
")",
")",
"{",
"Requirements",
"::",
"javascript",
"(",
"BOOTSTRAP_TAGFIELD_DIR",
".",
"'/javascript/typeahead.js'",
")",
";",
"Requirements",
"::",
"javascript",
"(",
"BOOTSTRAP_TAGFIELD_DIR",
".",
"'/javascript/bootstrap-tagfield.js'",
")",
";",
"Requirements",
"::",
"javascript",
"(",
"BOOTSTRAP_TAGFIELD_DIR",
".",
"'/javascript/bootstrap-tagfield-init.js'",
")",
";",
"Requirements",
"::",
"css",
"(",
"BOOTSTRAP_TAGFIELD_DIR",
".",
"'/css/bootstrap-tagfield.css'",
")",
";",
"$",
"this",
"->",
"setAttribute",
"(",
"'data-value'",
",",
"$",
"this",
"->",
"getValuesJSON",
"(",
")",
")",
"->",
"setAttribute",
"(",
"'data-bootstrap-tags'",
",",
"true",
")",
"->",
"setAttribute",
"(",
"'data-query-url'",
",",
"$",
"this",
"->",
"Link",
"(",
"'query'",
")",
")",
"->",
"setAttribute",
"(",
"'data-prefetch-url'",
",",
"$",
"this",
"->",
"Link",
"(",
"'prefetch'",
")",
")",
"->",
"setAttribute",
"(",
"'data-freeinput'",
",",
"$",
"this",
"->",
"freeInput",
")",
"->",
"setAttribute",
"(",
"'class'",
",",
"'text'",
")",
";",
"return",
"$",
"this",
"->",
"renderWith",
"(",
"$",
"this",
"->",
"getTemplates",
"(",
")",
")",
";",
"}"
] |
Renders the field
@param array $properties
@return SSViewer
|
[
"Renders",
"the",
"field"
] |
ada0c647f90ccb753d26a5d01889b2b4fbe2af76
|
https://github.com/unclecheese/silverstripe-bootstrap-tagfield/blob/ada0c647f90ccb753d26a5d01889b2b4fbe2af76/code/BootstrapTagField.php#L252-L268
|
21,639 |
zicht/z
|
src/Zicht/Tool/Script/Compiler.php
|
Compiler.parse
|
public function parse($input)
{
if (strlen($input) == 0) {
return null;
}
return $this->parser->parse(new TokenStream($this->tokenizer->getTokens($input)));
}
|
php
|
public function parse($input)
{
if (strlen($input) == 0) {
return null;
}
return $this->parser->parse(new TokenStream($this->tokenizer->getTokens($input)));
}
|
[
"public",
"function",
"parse",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"input",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"new",
"TokenStream",
"(",
"$",
"this",
"->",
"tokenizer",
"->",
"getTokens",
"(",
"$",
"input",
")",
")",
")",
";",
"}"
] |
Parses the raw string input and returns the resulting root node.
@param string $input
@return Node
|
[
"Parses",
"the",
"raw",
"string",
"input",
"and",
"returns",
"the",
"resulting",
"root",
"node",
"."
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Script/Compiler.php#L36-L42
|
21,640 |
zicht/z
|
src/Zicht/Tool/Script/Compiler.php
|
Compiler.compile
|
public function compile($input)
{
if (strlen($input) == 0) {
return null;
}
try {
$buffer = new Buffer();
$this->parse($input)->compile($buffer);
$code = $buffer->getResult();
return $code;
} catch (\UnexpectedValueException $e) {
throw new \UnexpectedValueException('Error while compiling input: ' . Util::toPhp($input), 0, $e);
}
}
|
php
|
public function compile($input)
{
if (strlen($input) == 0) {
return null;
}
try {
$buffer = new Buffer();
$this->parse($input)->compile($buffer);
$code = $buffer->getResult();
return $code;
} catch (\UnexpectedValueException $e) {
throw new \UnexpectedValueException('Error while compiling input: ' . Util::toPhp($input), 0, $e);
}
}
|
[
"public",
"function",
"compile",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"input",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"$",
"buffer",
"=",
"new",
"Buffer",
"(",
")",
";",
"$",
"this",
"->",
"parse",
"(",
"$",
"input",
")",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"code",
"=",
"$",
"buffer",
"->",
"getResult",
"(",
")",
";",
"return",
"$",
"code",
";",
"}",
"catch",
"(",
"\\",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Error while compiling input: '",
".",
"Util",
"::",
"toPhp",
"(",
"$",
"input",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] |
Compile an input string to PHP code
@param string $input
@return string
|
[
"Compile",
"an",
"input",
"string",
"to",
"PHP",
"code"
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Script/Compiler.php#L50-L63
|
21,641 |
icicleio/cache
|
src/MemoryCache.php
|
MemoryCache.unlock
|
protected function unlock(string $key)
{
if (!isset($this->locks[$key])) {
throw new InvalidArgumentError('No lock was set on the given key.');
}
$awaitable = $this->locks[$key];
unset($this->locks[$key]);
$awaitable->resolve();
}
|
php
|
protected function unlock(string $key)
{
if (!isset($this->locks[$key])) {
throw new InvalidArgumentError('No lock was set on the given key.');
}
$awaitable = $this->locks[$key];
unset($this->locks[$key]);
$awaitable->resolve();
}
|
[
"protected",
"function",
"unlock",
"(",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"locks",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentError",
"(",
"'No lock was set on the given key.'",
")",
";",
"}",
"$",
"awaitable",
"=",
"$",
"this",
"->",
"locks",
"[",
"$",
"key",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"locks",
"[",
"$",
"key",
"]",
")",
";",
"$",
"awaitable",
"->",
"resolve",
"(",
")",
";",
"}"
] |
Unlocks the given key. Throws if the key was not locked.
@param string $key
@throws \Icicle\Exception\InvalidArgumentError
|
[
"Unlocks",
"the",
"given",
"key",
".",
"Throws",
"if",
"the",
"key",
"was",
"not",
"locked",
"."
] |
d4edeed7c36dc261f051f880d389db80bb3672cf
|
https://github.com/icicleio/cache/blob/d4edeed7c36dc261f051f880d389db80bb3672cf/src/MemoryCache.php#L216-L225
|
21,642 |
JBZoo/Profiler
|
src/Benchmark.php
|
Benchmark._warmup
|
private function _warmup()
{
$warmup = new Test('warmup', function () {
});
$this->_overhead = $warmup->runTest($this->_count);
// One call each method for init (warmup)
/** @var Test $test */
foreach ($this->_tests as $test) {
$test->runTest(1);
}
$this->out(
'PHP Overhead: ' .
'time=' . Timer::formatMS($this->_overhead['time']) . '; ' .
'memory=' . FS::format($this->_overhead['memory'], 2) . ';' .
PHP_EOL
);
}
|
php
|
private function _warmup()
{
$warmup = new Test('warmup', function () {
});
$this->_overhead = $warmup->runTest($this->_count);
// One call each method for init (warmup)
/** @var Test $test */
foreach ($this->_tests as $test) {
$test->runTest(1);
}
$this->out(
'PHP Overhead: ' .
'time=' . Timer::formatMS($this->_overhead['time']) . '; ' .
'memory=' . FS::format($this->_overhead['memory'], 2) . ';' .
PHP_EOL
);
}
|
[
"private",
"function",
"_warmup",
"(",
")",
"{",
"$",
"warmup",
"=",
"new",
"Test",
"(",
"'warmup'",
",",
"function",
"(",
")",
"{",
"}",
")",
";",
"$",
"this",
"->",
"_overhead",
"=",
"$",
"warmup",
"->",
"runTest",
"(",
"$",
"this",
"->",
"_count",
")",
";",
"// One call each method for init (warmup)",
"/** @var Test $test */",
"foreach",
"(",
"$",
"this",
"->",
"_tests",
"as",
"$",
"test",
")",
"{",
"$",
"test",
"->",
"runTest",
"(",
"1",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"'PHP Overhead: '",
".",
"'time='",
".",
"Timer",
"::",
"formatMS",
"(",
"$",
"this",
"->",
"_overhead",
"[",
"'time'",
"]",
")",
".",
"'; '",
".",
"'memory='",
".",
"FS",
"::",
"format",
"(",
"$",
"this",
"->",
"_overhead",
"[",
"'memory'",
"]",
",",
"2",
")",
".",
"';'",
".",
"PHP_EOL",
")",
";",
"}"
] |
Runs an empty test to determine the benchmark overhead and run each test once
|
[
"Runs",
"an",
"empty",
"test",
"to",
"determine",
"the",
"benchmark",
"overhead",
"and",
"run",
"each",
"test",
"once"
] |
a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69
|
https://github.com/JBZoo/Profiler/blob/a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69/src/Benchmark.php#L77-L97
|
21,643 |
JBZoo/Profiler
|
src/Benchmark.php
|
Benchmark.outputTable
|
public function outputTable(array $lines, $padding = 4)
{
$pad = function ($string, $width) use ($padding) {
if ($width > 0) {
return str_pad($string, $width, ' ') . str_repeat(' ', $padding);
} else {
return str_pad($string, -$width, ' ', STR_PAD_LEFT) . str_repeat(' ', $padding);
}
};
// init width with keys' length
$cols = array_combine(
array_keys($lines[0]),
array_map('strlen', array_keys($lines[0]))
);
foreach ($cols as $col => $width) {
foreach ($lines as $line) {
$width = max($width, strlen($line[$col]));
}
if ($col !== self::COL_NAME) {
$width = -$width;
}
$this->out($pad($col, $width), false);
$cols[$col] = $width;
}
$this->out('');
foreach ($lines as $line) {
foreach ($cols as $col => $width) {
$this->out($pad($line[$col], $width), false);
}
$this->out('');
}
}
|
php
|
public function outputTable(array $lines, $padding = 4)
{
$pad = function ($string, $width) use ($padding) {
if ($width > 0) {
return str_pad($string, $width, ' ') . str_repeat(' ', $padding);
} else {
return str_pad($string, -$width, ' ', STR_PAD_LEFT) . str_repeat(' ', $padding);
}
};
// init width with keys' length
$cols = array_combine(
array_keys($lines[0]),
array_map('strlen', array_keys($lines[0]))
);
foreach ($cols as $col => $width) {
foreach ($lines as $line) {
$width = max($width, strlen($line[$col]));
}
if ($col !== self::COL_NAME) {
$width = -$width;
}
$this->out($pad($col, $width), false);
$cols[$col] = $width;
}
$this->out('');
foreach ($lines as $line) {
foreach ($cols as $col => $width) {
$this->out($pad($line[$col], $width), false);
}
$this->out('');
}
}
|
[
"public",
"function",
"outputTable",
"(",
"array",
"$",
"lines",
",",
"$",
"padding",
"=",
"4",
")",
"{",
"$",
"pad",
"=",
"function",
"(",
"$",
"string",
",",
"$",
"width",
")",
"use",
"(",
"$",
"padding",
")",
"{",
"if",
"(",
"$",
"width",
">",
"0",
")",
"{",
"return",
"str_pad",
"(",
"$",
"string",
",",
"$",
"width",
",",
"' '",
")",
".",
"str_repeat",
"(",
"' '",
",",
"$",
"padding",
")",
";",
"}",
"else",
"{",
"return",
"str_pad",
"(",
"$",
"string",
",",
"-",
"$",
"width",
",",
"' '",
",",
"STR_PAD_LEFT",
")",
".",
"str_repeat",
"(",
"' '",
",",
"$",
"padding",
")",
";",
"}",
"}",
";",
"// init width with keys' length",
"$",
"cols",
"=",
"array_combine",
"(",
"array_keys",
"(",
"$",
"lines",
"[",
"0",
"]",
")",
",",
"array_map",
"(",
"'strlen'",
",",
"array_keys",
"(",
"$",
"lines",
"[",
"0",
"]",
")",
")",
")",
";",
"foreach",
"(",
"$",
"cols",
"as",
"$",
"col",
"=>",
"$",
"width",
")",
"{",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"width",
"=",
"max",
"(",
"$",
"width",
",",
"strlen",
"(",
"$",
"line",
"[",
"$",
"col",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"col",
"!==",
"self",
"::",
"COL_NAME",
")",
"{",
"$",
"width",
"=",
"-",
"$",
"width",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"$",
"pad",
"(",
"$",
"col",
",",
"$",
"width",
")",
",",
"false",
")",
";",
"$",
"cols",
"[",
"$",
"col",
"]",
"=",
"$",
"width",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"''",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"foreach",
"(",
"$",
"cols",
"as",
"$",
"col",
"=>",
"$",
"width",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"$",
"pad",
"(",
"$",
"line",
"[",
"$",
"col",
"]",
",",
"$",
"width",
")",
",",
"false",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"''",
")",
";",
"}",
"}"
] |
Output results in columns, padding right if values are string, left if numeric
@param array $lines array(array('Name' => 'Value'));
@param integer $padding space between columns
|
[
"Output",
"results",
"in",
"columns",
"padding",
"right",
"if",
"values",
"are",
"string",
"left",
"if",
"numeric"
] |
a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69
|
https://github.com/JBZoo/Profiler/blob/a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69/src/Benchmark.php#L156-L194
|
21,644 |
JBZoo/Profiler
|
src/Benchmark.php
|
Benchmark.formatResults
|
public function formatResults(array $results)
{
uasort($results['list'], function ($testOne, $testTwo) {
if ($testOne['time'] === $testTwo['time']) {
return 0;
} else {
return ($testOne['time'] < $testTwo['time']) ? -1 : 1;
}
});
$minTime = INF;
$minMemory = INF;
foreach ($results['list'] as $name => $result) {
// time
$time = $result['time'];
//$time -= $this->_overhead['time']; // Substract base_time
$results['list'][$name]['time'] = $time;
$minTime = min($minTime, $time);
// memory
$memory = $results['list'][$name]['memory'];
$memory -= $this->_overhead['memory'];
$results['list'][$name]['memory'] = $memory;
$minMemory = min($minMemory, $memory);
}
$output = array();
$isOne = count($results['list']) === 1;
foreach ($results['list'] as $name => $result) {
if ($isOne) {
$output[] = array(
self::COL_NAME => $name,
self::COL_TIME => $this->_timeFormat($result['time'], 0),
self::COL_TIME_ONE => $this->_timeFormat($result['time'] / $this->_count),
self::COL_MEMORY => FS::format($result['memory'], 2),
);
} else {
$output[] = array(
self::COL_NAME => $name,
self::COL_TIME => $this->_timeFormat($result['time'], 0),
self::COL_TIME_ONE => $this->_timeFormat($result['time'] / $this->_count),
self::COL_TIME_REL => Vars::relativePercent($minTime, $result['time']),
self::COL_MEMORY => FS::format($result['memory'], 2),
self::COL_MEMORY_REL => Vars::relativePercent($minMemory, $result['memory']),
);
}
}
return $output;
}
|
php
|
public function formatResults(array $results)
{
uasort($results['list'], function ($testOne, $testTwo) {
if ($testOne['time'] === $testTwo['time']) {
return 0;
} else {
return ($testOne['time'] < $testTwo['time']) ? -1 : 1;
}
});
$minTime = INF;
$minMemory = INF;
foreach ($results['list'] as $name => $result) {
// time
$time = $result['time'];
//$time -= $this->_overhead['time']; // Substract base_time
$results['list'][$name]['time'] = $time;
$minTime = min($minTime, $time);
// memory
$memory = $results['list'][$name]['memory'];
$memory -= $this->_overhead['memory'];
$results['list'][$name]['memory'] = $memory;
$minMemory = min($minMemory, $memory);
}
$output = array();
$isOne = count($results['list']) === 1;
foreach ($results['list'] as $name => $result) {
if ($isOne) {
$output[] = array(
self::COL_NAME => $name,
self::COL_TIME => $this->_timeFormat($result['time'], 0),
self::COL_TIME_ONE => $this->_timeFormat($result['time'] / $this->_count),
self::COL_MEMORY => FS::format($result['memory'], 2),
);
} else {
$output[] = array(
self::COL_NAME => $name,
self::COL_TIME => $this->_timeFormat($result['time'], 0),
self::COL_TIME_ONE => $this->_timeFormat($result['time'] / $this->_count),
self::COL_TIME_REL => Vars::relativePercent($minTime, $result['time']),
self::COL_MEMORY => FS::format($result['memory'], 2),
self::COL_MEMORY_REL => Vars::relativePercent($minMemory, $result['memory']),
);
}
}
return $output;
}
|
[
"public",
"function",
"formatResults",
"(",
"array",
"$",
"results",
")",
"{",
"uasort",
"(",
"$",
"results",
"[",
"'list'",
"]",
",",
"function",
"(",
"$",
"testOne",
",",
"$",
"testTwo",
")",
"{",
"if",
"(",
"$",
"testOne",
"[",
"'time'",
"]",
"===",
"$",
"testTwo",
"[",
"'time'",
"]",
")",
"{",
"return",
"0",
";",
"}",
"else",
"{",
"return",
"(",
"$",
"testOne",
"[",
"'time'",
"]",
"<",
"$",
"testTwo",
"[",
"'time'",
"]",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"}",
")",
";",
"$",
"minTime",
"=",
"INF",
";",
"$",
"minMemory",
"=",
"INF",
";",
"foreach",
"(",
"$",
"results",
"[",
"'list'",
"]",
"as",
"$",
"name",
"=>",
"$",
"result",
")",
"{",
"// time",
"$",
"time",
"=",
"$",
"result",
"[",
"'time'",
"]",
";",
"//$time -= $this->_overhead['time']; // Substract base_time",
"$",
"results",
"[",
"'list'",
"]",
"[",
"$",
"name",
"]",
"[",
"'time'",
"]",
"=",
"$",
"time",
";",
"$",
"minTime",
"=",
"min",
"(",
"$",
"minTime",
",",
"$",
"time",
")",
";",
"// memory",
"$",
"memory",
"=",
"$",
"results",
"[",
"'list'",
"]",
"[",
"$",
"name",
"]",
"[",
"'memory'",
"]",
";",
"$",
"memory",
"-=",
"$",
"this",
"->",
"_overhead",
"[",
"'memory'",
"]",
";",
"$",
"results",
"[",
"'list'",
"]",
"[",
"$",
"name",
"]",
"[",
"'memory'",
"]",
"=",
"$",
"memory",
";",
"$",
"minMemory",
"=",
"min",
"(",
"$",
"minMemory",
",",
"$",
"memory",
")",
";",
"}",
"$",
"output",
"=",
"array",
"(",
")",
";",
"$",
"isOne",
"=",
"count",
"(",
"$",
"results",
"[",
"'list'",
"]",
")",
"===",
"1",
";",
"foreach",
"(",
"$",
"results",
"[",
"'list'",
"]",
"as",
"$",
"name",
"=>",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"isOne",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"COL_NAME",
"=>",
"$",
"name",
",",
"self",
"::",
"COL_TIME",
"=>",
"$",
"this",
"->",
"_timeFormat",
"(",
"$",
"result",
"[",
"'time'",
"]",
",",
"0",
")",
",",
"self",
"::",
"COL_TIME_ONE",
"=>",
"$",
"this",
"->",
"_timeFormat",
"(",
"$",
"result",
"[",
"'time'",
"]",
"/",
"$",
"this",
"->",
"_count",
")",
",",
"self",
"::",
"COL_MEMORY",
"=>",
"FS",
"::",
"format",
"(",
"$",
"result",
"[",
"'memory'",
"]",
",",
"2",
")",
",",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"COL_NAME",
"=>",
"$",
"name",
",",
"self",
"::",
"COL_TIME",
"=>",
"$",
"this",
"->",
"_timeFormat",
"(",
"$",
"result",
"[",
"'time'",
"]",
",",
"0",
")",
",",
"self",
"::",
"COL_TIME_ONE",
"=>",
"$",
"this",
"->",
"_timeFormat",
"(",
"$",
"result",
"[",
"'time'",
"]",
"/",
"$",
"this",
"->",
"_count",
")",
",",
"self",
"::",
"COL_TIME_REL",
"=>",
"Vars",
"::",
"relativePercent",
"(",
"$",
"minTime",
",",
"$",
"result",
"[",
"'time'",
"]",
")",
",",
"self",
"::",
"COL_MEMORY",
"=>",
"FS",
"::",
"format",
"(",
"$",
"result",
"[",
"'memory'",
"]",
",",
"2",
")",
",",
"self",
"::",
"COL_MEMORY_REL",
"=>",
"Vars",
"::",
"relativePercent",
"(",
"$",
"minMemory",
",",
"$",
"result",
"[",
"'memory'",
"]",
")",
",",
")",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
Format the results, rounding numbers, showing difference percentages
and removing a flat time based on the benchmark overhead
@param array $results array($name => array('time' => 1.0))
@return array array(array('Test' => $name, 'Time' => '1000 ms', 'Perc' => '100 %'))
|
[
"Format",
"the",
"results",
"rounding",
"numbers",
"showing",
"difference",
"percentages",
"and",
"removing",
"a",
"flat",
"time",
"based",
"on",
"the",
"benchmark",
"overhead"
] |
a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69
|
https://github.com/JBZoo/Profiler/blob/a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69/src/Benchmark.php#L203-L256
|
21,645 |
zhouyl/mellivora
|
Mellivora/Database/Eloquent/Relations/BelongsToMany.php
|
BelongsToMany.shouldSelect
|
protected function shouldSelect(array $columns = ['*'])
{
if ($columns === ['*']) {
$columns = [$this->related->getTable() . '.*'];
}
return array_merge($columns, $this->aliasedPivotColumns());
}
|
php
|
protected function shouldSelect(array $columns = ['*'])
{
if ($columns === ['*']) {
$columns = [$this->related->getTable() . '.*'];
}
return array_merge($columns, $this->aliasedPivotColumns());
}
|
[
"protected",
"function",
"shouldSelect",
"(",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"$",
"columns",
"===",
"[",
"'*'",
"]",
")",
"{",
"$",
"columns",
"=",
"[",
"$",
"this",
"->",
"related",
"->",
"getTable",
"(",
")",
".",
"'.*'",
"]",
";",
"}",
"return",
"array_merge",
"(",
"$",
"columns",
",",
"$",
"this",
"->",
"aliasedPivotColumns",
"(",
")",
")",
";",
"}"
] |
Get the select columns for the relation query.
@param array $columns
@return \Mellivora\Database\Eloquent\Relations\BelongsToMany
|
[
"Get",
"the",
"select",
"columns",
"for",
"the",
"relation",
"query",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Relations/BelongsToMany.php#L534-L541
|
21,646 |
stk2k/net-driver
|
src/Http/HttpProxyGetRequest.php
|
HttpProxyGetRequest.getProxyServer
|
public function getProxyServer()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_SERVER]) ? $proxy_options[EnumProxyOption::PROXY_SERVER] : '';
}
|
php
|
public function getProxyServer()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_SERVER]) ? $proxy_options[EnumProxyOption::PROXY_SERVER] : '';
}
|
[
"public",
"function",
"getProxyServer",
"(",
")",
"{",
"$",
"proxy_options",
"=",
"$",
"this",
"->",
"getOption",
"(",
"EnumRequestOption",
"::",
"PROXY_OPTIONS",
",",
"[",
"]",
")",
";",
"return",
"isset",
"(",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_SERVER",
"]",
")",
"?",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_SERVER",
"]",
":",
"''",
";",
"}"
] |
Returns proxy server
@return string
|
[
"Returns",
"proxy",
"server"
] |
75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c
|
https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Http/HttpProxyGetRequest.php#L28-L32
|
21,647 |
stk2k/net-driver
|
src/Http/HttpProxyGetRequest.php
|
HttpProxyGetRequest.getProxyPort
|
public function getProxyPort()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_PORT]) ? $proxy_options[EnumProxyOption::PROXY_PORT] : '';
}
|
php
|
public function getProxyPort()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_PORT]) ? $proxy_options[EnumProxyOption::PROXY_PORT] : '';
}
|
[
"public",
"function",
"getProxyPort",
"(",
")",
"{",
"$",
"proxy_options",
"=",
"$",
"this",
"->",
"getOption",
"(",
"EnumRequestOption",
"::",
"PROXY_OPTIONS",
",",
"[",
"]",
")",
";",
"return",
"isset",
"(",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_PORT",
"]",
")",
"?",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_PORT",
"]",
":",
"''",
";",
"}"
] |
Returns proxy port
@return mixed
|
[
"Returns",
"proxy",
"port"
] |
75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c
|
https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Http/HttpProxyGetRequest.php#L39-L43
|
21,648 |
stk2k/net-driver
|
src/Http/HttpProxyGetRequest.php
|
HttpProxyGetRequest.getProxyType
|
public function getProxyType()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_TYPE]) ? $proxy_options[EnumProxyOption::PROXY_TYPE] : 'http';
}
|
php
|
public function getProxyType()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_TYPE]) ? $proxy_options[EnumProxyOption::PROXY_TYPE] : 'http';
}
|
[
"public",
"function",
"getProxyType",
"(",
")",
"{",
"$",
"proxy_options",
"=",
"$",
"this",
"->",
"getOption",
"(",
"EnumRequestOption",
"::",
"PROXY_OPTIONS",
",",
"[",
"]",
")",
";",
"return",
"isset",
"(",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_TYPE",
"]",
")",
"?",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_TYPE",
"]",
":",
"'http'",
";",
"}"
] |
Returns proxy type
available values:
'http' for HTTP proxy
'https' for HTTPS proxy
@return string
|
[
"Returns",
"proxy",
"type"
] |
75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c
|
https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Http/HttpProxyGetRequest.php#L55-L59
|
21,649 |
stk2k/net-driver
|
src/Http/HttpProxyGetRequest.php
|
HttpProxyGetRequest.getProxyAuth
|
public function getProxyAuth()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_AUTH]) ? $proxy_options[EnumProxyOption::PROXY_AUTH] : null;
}
|
php
|
public function getProxyAuth()
{
$proxy_options = $this->getOption(EnumRequestOption::PROXY_OPTIONS, []);
return isset($proxy_options[EnumProxyOption::PROXY_AUTH]) ? $proxy_options[EnumProxyOption::PROXY_AUTH] : null;
}
|
[
"public",
"function",
"getProxyAuth",
"(",
")",
"{",
"$",
"proxy_options",
"=",
"$",
"this",
"->",
"getOption",
"(",
"EnumRequestOption",
"::",
"PROXY_OPTIONS",
",",
"[",
"]",
")",
";",
"return",
"isset",
"(",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_AUTH",
"]",
")",
"?",
"$",
"proxy_options",
"[",
"EnumProxyOption",
"::",
"PROXY_AUTH",
"]",
":",
"null",
";",
"}"
] |
Returns proxy auth
available values:
'basic' for BASIC auth
null or empty('') for no auth
@return string
|
[
"Returns",
"proxy",
"auth"
] |
75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c
|
https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Http/HttpProxyGetRequest.php#L71-L75
|
21,650 |
hametuha/wpametu
|
src/WPametu/UI/Field/Textarea.php
|
TextArea.build_input
|
protected function build_input($data, array $fields = []){
$fields = implode(' ', $fields);
return sprintf('<textarea id="%1$s" name="%1$s" %2$s>%3$s</textarea>%4$s',
$this->name, $fields, esc_textarea($data), $this->length_helper($data));
}
|
php
|
protected function build_input($data, array $fields = []){
$fields = implode(' ', $fields);
return sprintf('<textarea id="%1$s" name="%1$s" %2$s>%3$s</textarea>%4$s',
$this->name, $fields, esc_textarea($data), $this->length_helper($data));
}
|
[
"protected",
"function",
"build_input",
"(",
"$",
"data",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"$",
"fields",
"=",
"implode",
"(",
"' '",
",",
"$",
"fields",
")",
";",
"return",
"sprintf",
"(",
"'<textarea id=\"%1$s\" name=\"%1$s\" %2$s>%3$s</textarea>%4$s'",
",",
"$",
"this",
"->",
"name",
",",
"$",
"fields",
",",
"esc_textarea",
"(",
"$",
"data",
")",
",",
"$",
"this",
"->",
"length_helper",
"(",
"$",
"data",
")",
")",
";",
"}"
] |
Make input field
@param mixed $data
@param array $fields
@return string
|
[
"Make",
"input",
"field"
] |
0939373800815a8396291143d2a57967340da5aa
|
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Field/Textarea.php#L36-L40
|
21,651 |
infusephp/infuse
|
src/RouteResolver.php
|
RouteResolver.resolve
|
public function resolve($route, $req, $res, array $args)
{
$result = false;
if (is_array($route) || is_string($route)) {
// method name and controller supplied
if (is_string($route) && $req->params('controller')) {
$route = [$req->params('controller'), $route];
// method name supplied
} elseif (is_string($route)) {
$route = [$this->defaultController, $route];
// no method name? fallback to the index() method
} elseif (count($route) == 1) {
$route[] = $this->defaultAction;
}
list($controller, $method) = $route;
$controller = $this->namespace.'\\'.$controller;
if (!class_exists($controller)) {
throw new \Exception("Controller does not exist: $controller");
}
$controllerObj = new $controller();
// give the controller access to the DI container
if (method_exists($controllerObj, 'setApp')) {
$controllerObj->setApp($this->app);
}
// collect any preset route parameters
if (isset($route[2])) {
$params = $route[2];
$req->setParams($params);
}
$result = $controllerObj->$method($req, $res, $args);
} elseif (is_callable($route)) {
$result = call_user_func($route, $req, $res, $args);
}
if ($result instanceof View) {
$res->render($result);
}
return $res;
}
|
php
|
public function resolve($route, $req, $res, array $args)
{
$result = false;
if (is_array($route) || is_string($route)) {
// method name and controller supplied
if (is_string($route) && $req->params('controller')) {
$route = [$req->params('controller'), $route];
// method name supplied
} elseif (is_string($route)) {
$route = [$this->defaultController, $route];
// no method name? fallback to the index() method
} elseif (count($route) == 1) {
$route[] = $this->defaultAction;
}
list($controller, $method) = $route;
$controller = $this->namespace.'\\'.$controller;
if (!class_exists($controller)) {
throw new \Exception("Controller does not exist: $controller");
}
$controllerObj = new $controller();
// give the controller access to the DI container
if (method_exists($controllerObj, 'setApp')) {
$controllerObj->setApp($this->app);
}
// collect any preset route parameters
if (isset($route[2])) {
$params = $route[2];
$req->setParams($params);
}
$result = $controllerObj->$method($req, $res, $args);
} elseif (is_callable($route)) {
$result = call_user_func($route, $req, $res, $args);
}
if ($result instanceof View) {
$res->render($result);
}
return $res;
}
|
[
"public",
"function",
"resolve",
"(",
"$",
"route",
",",
"$",
"req",
",",
"$",
"res",
",",
"array",
"$",
"args",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"route",
")",
"||",
"is_string",
"(",
"$",
"route",
")",
")",
"{",
"// method name and controller supplied",
"if",
"(",
"is_string",
"(",
"$",
"route",
")",
"&&",
"$",
"req",
"->",
"params",
"(",
"'controller'",
")",
")",
"{",
"$",
"route",
"=",
"[",
"$",
"req",
"->",
"params",
"(",
"'controller'",
")",
",",
"$",
"route",
"]",
";",
"// method name supplied",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"route",
")",
")",
"{",
"$",
"route",
"=",
"[",
"$",
"this",
"->",
"defaultController",
",",
"$",
"route",
"]",
";",
"// no method name? fallback to the index() method",
"}",
"elseif",
"(",
"count",
"(",
"$",
"route",
")",
"==",
"1",
")",
"{",
"$",
"route",
"[",
"]",
"=",
"$",
"this",
"->",
"defaultAction",
";",
"}",
"list",
"(",
"$",
"controller",
",",
"$",
"method",
")",
"=",
"$",
"route",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"namespace",
".",
"'\\\\'",
".",
"$",
"controller",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"controller",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Controller does not exist: $controller\"",
")",
";",
"}",
"$",
"controllerObj",
"=",
"new",
"$",
"controller",
"(",
")",
";",
"// give the controller access to the DI container",
"if",
"(",
"method_exists",
"(",
"$",
"controllerObj",
",",
"'setApp'",
")",
")",
"{",
"$",
"controllerObj",
"->",
"setApp",
"(",
"$",
"this",
"->",
"app",
")",
";",
"}",
"// collect any preset route parameters",
"if",
"(",
"isset",
"(",
"$",
"route",
"[",
"2",
"]",
")",
")",
"{",
"$",
"params",
"=",
"$",
"route",
"[",
"2",
"]",
";",
"$",
"req",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"}",
"$",
"result",
"=",
"$",
"controllerObj",
"->",
"$",
"method",
"(",
"$",
"req",
",",
"$",
"res",
",",
"$",
"args",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"route",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func",
"(",
"$",
"route",
",",
"$",
"req",
",",
"$",
"res",
",",
"$",
"args",
")",
";",
"}",
"if",
"(",
"$",
"result",
"instanceof",
"View",
")",
"{",
"$",
"res",
"->",
"render",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] |
Executes a route handler.
@param array|string $route array('controller','method') or array('controller')
or 'method'
@param Request $req
@param Response $res
@param array $args
@throws Exception when the route cannot be resolved.
@return Response
|
[
"Executes",
"a",
"route",
"handler",
"."
] |
7520b237c69f3d8a07d95d7481b26027ced2ed83
|
https://github.com/infusephp/infuse/blob/7520b237c69f3d8a07d95d7481b26027ced2ed83/src/RouteResolver.php#L117-L163
|
21,652 |
heidelpay/PhpDoc
|
src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml/InterfaceConverter.php
|
InterfaceConverter.convert
|
public function convert(\DOMElement $parent, InterfaceDescriptor $interface)
{
$child = new \DOMElement('interface');
$parent->appendChild($child);
/** @var InterfaceDescriptor $parentInterface */
foreach ($interface->getParent() as $parentInterface) {
$parentFqcn = is_string($parentInterface) === false
? $parentInterface->getFullyQualifiedStructuralElementName()
: $parentInterface;
$child->appendChild(new \DOMElement('extends', $parentFqcn));
}
$namespace = $interface->getNamespace()->getFullyQualifiedStructuralElementName();
$child->setAttribute('namespace', ltrim($namespace, '\\'));
$child->setAttribute('line', $interface->getLine());
$child->appendChild(new \DOMElement('name', $interface->getName()));
$child->appendChild(new \DOMElement('full_name', $interface->getFullyQualifiedStructuralElementName()));
$this->docBlockConverter->convert($child, $interface);
foreach ($interface->getConstants() as $constant) {
$this->constantConverter->convert($child, $constant);
}
foreach ($interface->getMethods() as $method) {
$this->methodConverter->convert($child, $method);
}
return $child;
}
|
php
|
public function convert(\DOMElement $parent, InterfaceDescriptor $interface)
{
$child = new \DOMElement('interface');
$parent->appendChild($child);
/** @var InterfaceDescriptor $parentInterface */
foreach ($interface->getParent() as $parentInterface) {
$parentFqcn = is_string($parentInterface) === false
? $parentInterface->getFullyQualifiedStructuralElementName()
: $parentInterface;
$child->appendChild(new \DOMElement('extends', $parentFqcn));
}
$namespace = $interface->getNamespace()->getFullyQualifiedStructuralElementName();
$child->setAttribute('namespace', ltrim($namespace, '\\'));
$child->setAttribute('line', $interface->getLine());
$child->appendChild(new \DOMElement('name', $interface->getName()));
$child->appendChild(new \DOMElement('full_name', $interface->getFullyQualifiedStructuralElementName()));
$this->docBlockConverter->convert($child, $interface);
foreach ($interface->getConstants() as $constant) {
$this->constantConverter->convert($child, $constant);
}
foreach ($interface->getMethods() as $method) {
$this->methodConverter->convert($child, $method);
}
return $child;
}
|
[
"public",
"function",
"convert",
"(",
"\\",
"DOMElement",
"$",
"parent",
",",
"InterfaceDescriptor",
"$",
"interface",
")",
"{",
"$",
"child",
"=",
"new",
"\\",
"DOMElement",
"(",
"'interface'",
")",
";",
"$",
"parent",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"/** @var InterfaceDescriptor $parentInterface */",
"foreach",
"(",
"$",
"interface",
"->",
"getParent",
"(",
")",
"as",
"$",
"parentInterface",
")",
"{",
"$",
"parentFqcn",
"=",
"is_string",
"(",
"$",
"parentInterface",
")",
"===",
"false",
"?",
"$",
"parentInterface",
"->",
"getFullyQualifiedStructuralElementName",
"(",
")",
":",
"$",
"parentInterface",
";",
"$",
"child",
"->",
"appendChild",
"(",
"new",
"\\",
"DOMElement",
"(",
"'extends'",
",",
"$",
"parentFqcn",
")",
")",
";",
"}",
"$",
"namespace",
"=",
"$",
"interface",
"->",
"getNamespace",
"(",
")",
"->",
"getFullyQualifiedStructuralElementName",
"(",
")",
";",
"$",
"child",
"->",
"setAttribute",
"(",
"'namespace'",
",",
"ltrim",
"(",
"$",
"namespace",
",",
"'\\\\'",
")",
")",
";",
"$",
"child",
"->",
"setAttribute",
"(",
"'line'",
",",
"$",
"interface",
"->",
"getLine",
"(",
")",
")",
";",
"$",
"child",
"->",
"appendChild",
"(",
"new",
"\\",
"DOMElement",
"(",
"'name'",
",",
"$",
"interface",
"->",
"getName",
"(",
")",
")",
")",
";",
"$",
"child",
"->",
"appendChild",
"(",
"new",
"\\",
"DOMElement",
"(",
"'full_name'",
",",
"$",
"interface",
"->",
"getFullyQualifiedStructuralElementName",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"docBlockConverter",
"->",
"convert",
"(",
"$",
"child",
",",
"$",
"interface",
")",
";",
"foreach",
"(",
"$",
"interface",
"->",
"getConstants",
"(",
")",
"as",
"$",
"constant",
")",
"{",
"$",
"this",
"->",
"constantConverter",
"->",
"convert",
"(",
"$",
"child",
",",
"$",
"constant",
")",
";",
"}",
"foreach",
"(",
"$",
"interface",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
"$",
"this",
"->",
"methodConverter",
"->",
"convert",
"(",
"$",
"child",
",",
"$",
"method",
")",
";",
"}",
"return",
"$",
"child",
";",
"}"
] |
Export the given reflected interface definition to the provided parent element.
This method creates a new child element on the given parent XML element
and takes the properties of the Reflection argument and sets the
elements and attributes on the child.
If a child DOMElement is provided then the properties and attributes are
set on this but the child element is not appended onto the parent. This
is the responsibility of the invoker. Essentially this means that the
$parent argument is ignored in this case.
@param \DOMElement $parent Element to augment.
@param InterfaceDescriptor $interface Element to export.
@return \DOMElement
|
[
"Export",
"the",
"given",
"reflected",
"interface",
"definition",
"to",
"the",
"provided",
"parent",
"element",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Xml/InterfaceConverter.php#L66-L97
|
21,653 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerTenderCommand.php
|
WorkerTenderCommand.handle
|
private function handle($key, ChildProcessContainer $child)
{
$tube = $this->tube;
$child->processOutput('child_' . $tube . $key);
//send unhealthy child processes to bed (kill em off)
if (!$child->checkHealth()) {
$child->getReadyForBed();
}
//send old children to bed (kill em off)
$readyStatusses = array(ChildProcessContainer::STATUS_READY, ChildProcessContainer::STATUS_ALIVE);
if ($child->getAge() >= $this->input->getOption('max-worker-age') &&
in_array($child->status, $readyStatusses)
) {
$child->bedtime();
}
//Kill off processes that have used up too much memory already
if ($child->getBufferLength() >= $this->input->getOption('max-worker-buffer') &&
in_array($child->status, $readyStatusses)
) {
$child->bedtime();
}
//if the child is dead ,clean up the mess
if ($child->isDead()) {
$child->cleanUp();
}
//if the child is cleaned up remove the object and clean up some memory
if ($child->isCleanedUp()) {
$this->verboseOutput("<info>Unsetting Child</info>: $key");
unset($this->family[$key]);
$this->verboseOutput("<info>Children left</info>: " . count($this->family));
}
}
|
php
|
private function handle($key, ChildProcessContainer $child)
{
$tube = $this->tube;
$child->processOutput('child_' . $tube . $key);
//send unhealthy child processes to bed (kill em off)
if (!$child->checkHealth()) {
$child->getReadyForBed();
}
//send old children to bed (kill em off)
$readyStatusses = array(ChildProcessContainer::STATUS_READY, ChildProcessContainer::STATUS_ALIVE);
if ($child->getAge() >= $this->input->getOption('max-worker-age') &&
in_array($child->status, $readyStatusses)
) {
$child->bedtime();
}
//Kill off processes that have used up too much memory already
if ($child->getBufferLength() >= $this->input->getOption('max-worker-buffer') &&
in_array($child->status, $readyStatusses)
) {
$child->bedtime();
}
//if the child is dead ,clean up the mess
if ($child->isDead()) {
$child->cleanUp();
}
//if the child is cleaned up remove the object and clean up some memory
if ($child->isCleanedUp()) {
$this->verboseOutput("<info>Unsetting Child</info>: $key");
unset($this->family[$key]);
$this->verboseOutput("<info>Children left</info>: " . count($this->family));
}
}
|
[
"private",
"function",
"handle",
"(",
"$",
"key",
",",
"ChildProcessContainer",
"$",
"child",
")",
"{",
"$",
"tube",
"=",
"$",
"this",
"->",
"tube",
";",
"$",
"child",
"->",
"processOutput",
"(",
"'child_'",
".",
"$",
"tube",
".",
"$",
"key",
")",
";",
"//send unhealthy child processes to bed (kill em off)",
"if",
"(",
"!",
"$",
"child",
"->",
"checkHealth",
"(",
")",
")",
"{",
"$",
"child",
"->",
"getReadyForBed",
"(",
")",
";",
"}",
"//send old children to bed (kill em off)",
"$",
"readyStatusses",
"=",
"array",
"(",
"ChildProcessContainer",
"::",
"STATUS_READY",
",",
"ChildProcessContainer",
"::",
"STATUS_ALIVE",
")",
";",
"if",
"(",
"$",
"child",
"->",
"getAge",
"(",
")",
">=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'max-worker-age'",
")",
"&&",
"in_array",
"(",
"$",
"child",
"->",
"status",
",",
"$",
"readyStatusses",
")",
")",
"{",
"$",
"child",
"->",
"bedtime",
"(",
")",
";",
"}",
"//Kill off processes that have used up too much memory already",
"if",
"(",
"$",
"child",
"->",
"getBufferLength",
"(",
")",
">=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'max-worker-buffer'",
")",
"&&",
"in_array",
"(",
"$",
"child",
"->",
"status",
",",
"$",
"readyStatusses",
")",
")",
"{",
"$",
"child",
"->",
"bedtime",
"(",
")",
";",
"}",
"//if the child is dead ,clean up the mess",
"if",
"(",
"$",
"child",
"->",
"isDead",
"(",
")",
")",
"{",
"$",
"child",
"->",
"cleanUp",
"(",
")",
";",
"}",
"//if the child is cleaned up remove the object and clean up some memory",
"if",
"(",
"$",
"child",
"->",
"isCleanedUp",
"(",
")",
")",
"{",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Unsetting Child</info>: $key\"",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"family",
"[",
"$",
"key",
"]",
")",
";",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Children left</info>: \"",
".",
"count",
"(",
"$",
"this",
"->",
"family",
")",
")",
";",
"}",
"}"
] |
Handles all child communication things
@param string $key
@param ChildProcessContainer $child
@return void
|
[
"Handles",
"all",
"child",
"communication",
"things"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L106-L137
|
21,654 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerTenderCommand.php
|
WorkerTenderCommand.familyPlanning
|
private function familyPlanning()
{
list($total, $available) = $this->countWorkers();
if ($this->shutdownGracefully) {
if ($total > 0) {
$this->verboseOutput("<info>Shutting down</info> $total remaining children");
foreach ($this->family as $cnr => $child) {
$this->verboseOutput("<info>Child: $cnr </info>" . $child->status);
}
$this->tellChildrenToPrepareForBed();
} else {
$this->keepWorking = false;
}
return;
}
list($shouldHaveLessWorkers, $shouldHaveMoreWorkers) = $this->moreOrLess($total, $available);
if ($shouldHaveMoreWorkers) {
$this->family[] = $this->spawnChild();
}
if ($shouldHaveLessWorkers) {
//find one of the family members not doing anything and cap it!
if ($this->findDisposableWorkers()) {
//we found one
$this->verboseOutput("<info>Found a disposable worker</info>");
}
}
}
|
php
|
private function familyPlanning()
{
list($total, $available) = $this->countWorkers();
if ($this->shutdownGracefully) {
if ($total > 0) {
$this->verboseOutput("<info>Shutting down</info> $total remaining children");
foreach ($this->family as $cnr => $child) {
$this->verboseOutput("<info>Child: $cnr </info>" . $child->status);
}
$this->tellChildrenToPrepareForBed();
} else {
$this->keepWorking = false;
}
return;
}
list($shouldHaveLessWorkers, $shouldHaveMoreWorkers) = $this->moreOrLess($total, $available);
if ($shouldHaveMoreWorkers) {
$this->family[] = $this->spawnChild();
}
if ($shouldHaveLessWorkers) {
//find one of the family members not doing anything and cap it!
if ($this->findDisposableWorkers()) {
//we found one
$this->verboseOutput("<info>Found a disposable worker</info>");
}
}
}
|
[
"private",
"function",
"familyPlanning",
"(",
")",
"{",
"list",
"(",
"$",
"total",
",",
"$",
"available",
")",
"=",
"$",
"this",
"->",
"countWorkers",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shutdownGracefully",
")",
"{",
"if",
"(",
"$",
"total",
">",
"0",
")",
"{",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Shutting down</info> $total remaining children\"",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"family",
"as",
"$",
"cnr",
"=>",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Child: $cnr </info>\"",
".",
"$",
"child",
"->",
"status",
")",
";",
"}",
"$",
"this",
"->",
"tellChildrenToPrepareForBed",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"keepWorking",
"=",
"false",
";",
"}",
"return",
";",
"}",
"list",
"(",
"$",
"shouldHaveLessWorkers",
",",
"$",
"shouldHaveMoreWorkers",
")",
"=",
"$",
"this",
"->",
"moreOrLess",
"(",
"$",
"total",
",",
"$",
"available",
")",
";",
"if",
"(",
"$",
"shouldHaveMoreWorkers",
")",
"{",
"$",
"this",
"->",
"family",
"[",
"]",
"=",
"$",
"this",
"->",
"spawnChild",
"(",
")",
";",
"}",
"if",
"(",
"$",
"shouldHaveLessWorkers",
")",
"{",
"//find one of the family members not doing anything and cap it!",
"if",
"(",
"$",
"this",
"->",
"findDisposableWorkers",
"(",
")",
")",
"{",
"//we found one",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Found a disposable worker</info>\"",
")",
";",
"}",
"}",
"}"
] |
Produce more hands for the work needed
@return void
|
[
"Produce",
"more",
"hands",
"for",
"the",
"work",
"needed"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L144-L171
|
21,655 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerTenderCommand.php
|
WorkerTenderCommand.countWorkers
|
public function countWorkers()
{
$total = count($this->family);
$busy = 0;
$available = 0;
foreach ($this->family as &$child) {
switch ($child->status) {
case ChildProcessContainer::STATUS_ALIVE:
case ChildProcessContainer::STATUS_READY:
$available++;
break;
case ChildProcessContainer::STATUS_BUSY:
case ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY:
$busy++;
break;
}
}
return array($total, $available);
}
|
php
|
public function countWorkers()
{
$total = count($this->family);
$busy = 0;
$available = 0;
foreach ($this->family as &$child) {
switch ($child->status) {
case ChildProcessContainer::STATUS_ALIVE:
case ChildProcessContainer::STATUS_READY:
$available++;
break;
case ChildProcessContainer::STATUS_BUSY:
case ChildProcessContainer::STATUS_BUSY_BUT_SLEEPY:
$busy++;
break;
}
}
return array($total, $available);
}
|
[
"public",
"function",
"countWorkers",
"(",
")",
"{",
"$",
"total",
"=",
"count",
"(",
"$",
"this",
"->",
"family",
")",
";",
"$",
"busy",
"=",
"0",
";",
"$",
"available",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"family",
"as",
"&",
"$",
"child",
")",
"{",
"switch",
"(",
"$",
"child",
"->",
"status",
")",
"{",
"case",
"ChildProcessContainer",
"::",
"STATUS_ALIVE",
":",
"case",
"ChildProcessContainer",
"::",
"STATUS_READY",
":",
"$",
"available",
"++",
";",
"break",
";",
"case",
"ChildProcessContainer",
"::",
"STATUS_BUSY",
":",
"case",
"ChildProcessContainer",
"::",
"STATUS_BUSY_BUT_SLEEPY",
":",
"$",
"busy",
"++",
";",
"break",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"total",
",",
"$",
"available",
")",
";",
"}"
] |
Returns an array with the worker counts
@return array
|
[
"Returns",
"an",
"array",
"with",
"the",
"worker",
"counts"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L178-L196
|
21,656 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerTenderCommand.php
|
WorkerTenderCommand.moreOrLess
|
public function moreOrLess($total, $available)
{
$shouldHaveMoreWorkers = false;
$shouldHaveLessWorkers = false;
$minWorkers = $this->input->getOption('min-workers');
$maxWorkers = $this->input->getOption('max-workers');
$spareWorkers = $this->input->getOption('spare-workers');
if ($total < $minWorkers) {
//too little workers,spawn more please
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little workers</info>: $total / $minWorkers");
} elseif (($available < $spareWorkers) && ($total <= $maxWorkers)) {
//we have not enough spare workers we should spawn some more... unless we have reached the max workers limit
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little spare workers</info>: $available / $spareWorkers");
} elseif ($total >= $maxWorkers) {
//we should have less workers because we somehow ended up over the limit
$shouldHaveLessWorkers = true;
} elseif ($available >= $minWorkers + $spareWorkers && !$shouldHaveMoreWorkers) {
//we have more than enough workers for the amount of work we should probably kill one off.
$shouldHaveLessWorkers = true;
}
return array($shouldHaveLessWorkers, $shouldHaveMoreWorkers);
}
|
php
|
public function moreOrLess($total, $available)
{
$shouldHaveMoreWorkers = false;
$shouldHaveLessWorkers = false;
$minWorkers = $this->input->getOption('min-workers');
$maxWorkers = $this->input->getOption('max-workers');
$spareWorkers = $this->input->getOption('spare-workers');
if ($total < $minWorkers) {
//too little workers,spawn more please
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little workers</info>: $total / $minWorkers");
} elseif (($available < $spareWorkers) && ($total <= $maxWorkers)) {
//we have not enough spare workers we should spawn some more... unless we have reached the max workers limit
$shouldHaveMoreWorkers = true;
$this->verboseOutput("<info>Too little spare workers</info>: $available / $spareWorkers");
} elseif ($total >= $maxWorkers) {
//we should have less workers because we somehow ended up over the limit
$shouldHaveLessWorkers = true;
} elseif ($available >= $minWorkers + $spareWorkers && !$shouldHaveMoreWorkers) {
//we have more than enough workers for the amount of work we should probably kill one off.
$shouldHaveLessWorkers = true;
}
return array($shouldHaveLessWorkers, $shouldHaveMoreWorkers);
}
|
[
"public",
"function",
"moreOrLess",
"(",
"$",
"total",
",",
"$",
"available",
")",
"{",
"$",
"shouldHaveMoreWorkers",
"=",
"false",
";",
"$",
"shouldHaveLessWorkers",
"=",
"false",
";",
"$",
"minWorkers",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'min-workers'",
")",
";",
"$",
"maxWorkers",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'max-workers'",
")",
";",
"$",
"spareWorkers",
"=",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'spare-workers'",
")",
";",
"if",
"(",
"$",
"total",
"<",
"$",
"minWorkers",
")",
"{",
"//too little workers,spawn more please",
"$",
"shouldHaveMoreWorkers",
"=",
"true",
";",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Too little workers</info>: $total / $minWorkers\"",
")",
";",
"}",
"elseif",
"(",
"(",
"$",
"available",
"<",
"$",
"spareWorkers",
")",
"&&",
"(",
"$",
"total",
"<=",
"$",
"maxWorkers",
")",
")",
"{",
"//we have not enough spare workers we should spawn some more... unless we have reached the max workers limit",
"$",
"shouldHaveMoreWorkers",
"=",
"true",
";",
"$",
"this",
"->",
"verboseOutput",
"(",
"\"<info>Too little spare workers</info>: $available / $spareWorkers\"",
")",
";",
"}",
"elseif",
"(",
"$",
"total",
">=",
"$",
"maxWorkers",
")",
"{",
"//we should have less workers because we somehow ended up over the limit",
"$",
"shouldHaveLessWorkers",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"available",
">=",
"$",
"minWorkers",
"+",
"$",
"spareWorkers",
"&&",
"!",
"$",
"shouldHaveMoreWorkers",
")",
"{",
"//we have more than enough workers for the amount of work we should probably kill one off.",
"$",
"shouldHaveLessWorkers",
"=",
"true",
";",
"}",
"return",
"array",
"(",
"$",
"shouldHaveLessWorkers",
",",
"$",
"shouldHaveMoreWorkers",
")",
";",
"}"
] |
Returns two booleans if there should be more or less workers
@param integer $total
@param integer $busy
@param integer $available
@return array
|
[
"Returns",
"two",
"booleans",
"if",
"there",
"should",
"be",
"more",
"or",
"less",
"workers"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L206-L229
|
21,657 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerTenderCommand.php
|
WorkerTenderCommand.findDisposableWorkers
|
private function findDisposableWorkers()
{
$disposableStatusses = array(ChildProcessContainer::STATUS_READY, ChildProcessContainer::STATUS_ALIVE);
foreach ($this->family as &$child) {
if (in_array($child->status, $disposableStatusses)) {
if ($child->getAge() < 10) {
//less than ten seconds old keep it alive a bit to let its do its job
continue;
}
$child->bedTime();
return true;
}
}
return false;
}
|
php
|
private function findDisposableWorkers()
{
$disposableStatusses = array(ChildProcessContainer::STATUS_READY, ChildProcessContainer::STATUS_ALIVE);
foreach ($this->family as &$child) {
if (in_array($child->status, $disposableStatusses)) {
if ($child->getAge() < 10) {
//less than ten seconds old keep it alive a bit to let its do its job
continue;
}
$child->bedTime();
return true;
}
}
return false;
}
|
[
"private",
"function",
"findDisposableWorkers",
"(",
")",
"{",
"$",
"disposableStatusses",
"=",
"array",
"(",
"ChildProcessContainer",
"::",
"STATUS_READY",
",",
"ChildProcessContainer",
"::",
"STATUS_ALIVE",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"family",
"as",
"&",
"$",
"child",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"child",
"->",
"status",
",",
"$",
"disposableStatusses",
")",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getAge",
"(",
")",
"<",
"10",
")",
"{",
"//less than ten seconds old keep it alive a bit to let its do its job",
"continue",
";",
"}",
"$",
"child",
"->",
"bedTime",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Finds disposable workers, if it finds them it returns true
@return boolean
|
[
"Finds",
"disposable",
"workers",
"if",
"it",
"finds",
"them",
"it",
"returns",
"true"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L236-L251
|
21,658 |
webdevvie/pheanstalk-task-queue-bundle
|
Command/WorkerTenderCommand.php
|
WorkerTenderCommand.spawnChild
|
private function spawnChild()
{
$child = new ChildProcessContainer(
$this->consolePath,
$this->input->getOption('worker-command'),
$this->tube,
$this
);
$child->start();
return $child;
}
|
php
|
private function spawnChild()
{
$child = new ChildProcessContainer(
$this->consolePath,
$this->input->getOption('worker-command'),
$this->tube,
$this
);
$child->start();
return $child;
}
|
[
"private",
"function",
"spawnChild",
"(",
")",
"{",
"$",
"child",
"=",
"new",
"ChildProcessContainer",
"(",
"$",
"this",
"->",
"consolePath",
",",
"$",
"this",
"->",
"input",
"->",
"getOption",
"(",
"'worker-command'",
")",
",",
"$",
"this",
"->",
"tube",
",",
"$",
"this",
")",
";",
"$",
"child",
"->",
"start",
"(",
")",
";",
"return",
"$",
"child",
";",
"}"
] |
Spawns a new child
@return Child
|
[
"Spawns",
"a",
"new",
"child"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/WorkerTenderCommand.php#L271-L281
|
21,659 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.createEventObject
|
protected function createEventObject($eventName, array $data)
{
if (!array_key_exists($eventName, $this->options['events'])) {
throw new \InvalidArgumentException('Event is not defined.');
}
$namespace = $this->options['events'][$eventName]['object'];
$instance = new $namespace($eventName, $data);
if (!($instance instanceof EventInterface)) {
throw new \LogicException('Invalid interface of event object');
}
return $instance;
}
|
php
|
protected function createEventObject($eventName, array $data)
{
if (!array_key_exists($eventName, $this->options['events'])) {
throw new \InvalidArgumentException('Event is not defined.');
}
$namespace = $this->options['events'][$eventName]['object'];
$instance = new $namespace($eventName, $data);
if (!($instance instanceof EventInterface)) {
throw new \LogicException('Invalid interface of event object');
}
return $instance;
}
|
[
"protected",
"function",
"createEventObject",
"(",
"$",
"eventName",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Event is not defined.'",
")",
";",
"}",
"$",
"namespace",
"=",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"[",
"'object'",
"]",
";",
"$",
"instance",
"=",
"new",
"$",
"namespace",
"(",
"$",
"eventName",
",",
"$",
"data",
")",
";",
"if",
"(",
"!",
"(",
"$",
"instance",
"instanceof",
"EventInterface",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Invalid interface of event object'",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
return event object or create it if not exist
@param string $eventName
@param array $data
@return EventInterface
@throws \LogicException
@throws \InvalidArgumentException
|
[
"return",
"event",
"object",
"or",
"create",
"it",
"if",
"not",
"exist"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L89-L103
|
21,660 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.triggerEvent
|
public function triggerEvent($name, array $data = [])
{
try {
/** @var EventInterface $event */
$event = $this->createEventObject($name, $data);
} catch (\InvalidArgumentException $exception) {
return $this;
}
foreach ($this->options['events'][$name]['listeners'] as $eventListener) {
if ($event->isPropagationStopped()) {
$this->loggerInstance->makeLogEvent($name, $eventListener, self::EVENT_STATUS_BREAK);
break;
}
$this->executeListener($eventListener, $event, $name);
}
return $this;
}
|
php
|
public function triggerEvent($name, array $data = [])
{
try {
/** @var EventInterface $event */
$event = $this->createEventObject($name, $data);
} catch (\InvalidArgumentException $exception) {
return $this;
}
foreach ($this->options['events'][$name]['listeners'] as $eventListener) {
if ($event->isPropagationStopped()) {
$this->loggerInstance->makeLogEvent($name, $eventListener, self::EVENT_STATUS_BREAK);
break;
}
$this->executeListener($eventListener, $event, $name);
}
return $this;
}
|
[
"public",
"function",
"triggerEvent",
"(",
"$",
"name",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"/** @var EventInterface $event */",
"$",
"event",
"=",
"$",
"this",
"->",
"createEventObject",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"name",
"]",
"[",
"'listeners'",
"]",
"as",
"$",
"eventListener",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"$",
"this",
"->",
"loggerInstance",
"->",
"makeLogEvent",
"(",
"$",
"name",
",",
"$",
"eventListener",
",",
"self",
"::",
"EVENT_STATUS_BREAK",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"executeListener",
"(",
"$",
"eventListener",
",",
"$",
"event",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
trigger new event with automatic call all subscribed listeners
@param string $name
@param array $data
@return $this
@throws \LogicException
|
[
"trigger",
"new",
"event",
"with",
"automatic",
"call",
"all",
"subscribed",
"listeners"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L129-L148
|
21,661 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.addEventListener
|
public function addEventListener($eventName, array $listeners)
{
if (!array_key_exists($eventName, $this->options['events'])) {
$this->options['events'][$eventName] = [
'object' =>BaseEvent::class,
'listeners' => $listeners,
];
}
$this->options['events'][$eventName]['listeners'] = array_merge(
$this->options['events'][$eventName]['listeners'],
$listeners
);
return $this;
}
|
php
|
public function addEventListener($eventName, array $listeners)
{
if (!array_key_exists($eventName, $this->options['events'])) {
$this->options['events'][$eventName] = [
'object' =>BaseEvent::class,
'listeners' => $listeners,
];
}
$this->options['events'][$eventName]['listeners'] = array_merge(
$this->options['events'][$eventName]['listeners'],
$listeners
);
return $this;
}
|
[
"public",
"function",
"addEventListener",
"(",
"$",
"eventName",
",",
"array",
"$",
"listeners",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"=",
"[",
"'object'",
"=>",
"BaseEvent",
"::",
"class",
",",
"'listeners'",
"=>",
"$",
"listeners",
",",
"]",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"[",
"'listeners'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"options",
"[",
"'events'",
"]",
"[",
"$",
"eventName",
"]",
"[",
"'listeners'",
"]",
",",
"$",
"listeners",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
dynamically add new listener or listeners for given event name
listeners are added at end of the list
@param string $eventName
@param array $listeners
@return $this
|
[
"dynamically",
"add",
"new",
"listener",
"or",
"listeners",
"for",
"given",
"event",
"name",
"listeners",
"are",
"added",
"at",
"end",
"of",
"the",
"list"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L179-L194
|
21,662 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.readEventConfiguration
|
public function readEventConfiguration($path, $type)
{
if (!file_exists($path)) {
throw new \InvalidArgumentException('File ' . $path . 'don\'t exists.');
}
$name = '\BlueEvent\Event\Config\\' . ucfirst($type) . 'Config';
if (!class_exists($name)) {
throw new \InvalidArgumentException('Incorrect configuration type: ' . $type);
}
/** @var \BlueEvent\Event\Config\ConfigReader $reader */
$reader = new $name;
return $this->setEventConfiguration($reader->readConfig($path));
}
|
php
|
public function readEventConfiguration($path, $type)
{
if (!file_exists($path)) {
throw new \InvalidArgumentException('File ' . $path . 'don\'t exists.');
}
$name = '\BlueEvent\Event\Config\\' . ucfirst($type) . 'Config';
if (!class_exists($name)) {
throw new \InvalidArgumentException('Incorrect configuration type: ' . $type);
}
/** @var \BlueEvent\Event\Config\ConfigReader $reader */
$reader = new $name;
return $this->setEventConfiguration($reader->readConfig($path));
}
|
[
"public",
"function",
"readEventConfiguration",
"(",
"$",
"path",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'File '",
".",
"$",
"path",
".",
"'don\\'t exists.'",
")",
";",
"}",
"$",
"name",
"=",
"'\\BlueEvent\\Event\\Config\\\\'",
".",
"ucfirst",
"(",
"$",
"type",
")",
".",
"'Config'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Incorrect configuration type: '",
".",
"$",
"type",
")",
";",
"}",
"/** @var \\BlueEvent\\Event\\Config\\ConfigReader $reader */",
"$",
"reader",
"=",
"new",
"$",
"name",
";",
"return",
"$",
"this",
"->",
"setEventConfiguration",
"(",
"$",
"reader",
"->",
"readConfig",
"(",
"$",
"path",
")",
")",
";",
"}"
] |
read configuration from file
@param mixed $path
@param string $type
@return $this
@throws \InvalidArgumentException
|
[
"read",
"configuration",
"from",
"file"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L217-L233
|
21,663 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.logEvent
|
public function logEvent(array $events = [])
{
foreach ($events as $event) {
if (!in_array($event, $this->loggerInstance->logEvents, true)) {
$this->loggerInstance->logEvents[] = $event;
}
}
return $this;
}
|
php
|
public function logEvent(array $events = [])
{
foreach ($events as $event) {
if (!in_array($event, $this->loggerInstance->logEvents, true)) {
$this->loggerInstance->logEvents[] = $event;
}
}
return $this;
}
|
[
"public",
"function",
"logEvent",
"(",
"array",
"$",
"events",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"event",
",",
"$",
"this",
"->",
"loggerInstance",
"->",
"logEvents",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"loggerInstance",
"->",
"logEvents",
"[",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
log given events by given name
@param array $events
@return $this
|
[
"log",
"given",
"events",
"by",
"given",
"name"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L253-L262
|
21,664 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.getConfiguration
|
public function getConfiguration($option = null)
{
if (!is_null($option)) {
return $this->options[$option];
}
return $this->options;
}
|
php
|
public function getConfiguration($option = null)
{
if (!is_null($option)) {
return $this->options[$option];
}
return $this->options;
}
|
[
"public",
"function",
"getConfiguration",
"(",
"$",
"option",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"option",
")",
")",
"{",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"options",
";",
"}"
] |
get complete object configuration or value of single option
@param $option string|null
@return mixed
|
[
"get",
"complete",
"object",
"configuration",
"or",
"value",
"of",
"single",
"option"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L282-L289
|
21,665 |
bluetree-service/event
|
src/Event/Base/EventDispatcher.php
|
EventDispatcher.addError
|
protected function addError(\Exception $exception)
{
$this->errorList[$exception->getCode()] = [
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'file' => $exception->getFile(),
'trace' => $exception->getTraceAsString(),
];
$this->hasErrors = true;
return $this;
}
|
php
|
protected function addError(\Exception $exception)
{
$this->errorList[$exception->getCode()] = [
'message' => $exception->getMessage(),
'line' => $exception->getLine(),
'file' => $exception->getFile(),
'trace' => $exception->getTraceAsString(),
];
$this->hasErrors = true;
return $this;
}
|
[
"protected",
"function",
"addError",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"errorList",
"[",
"$",
"exception",
"->",
"getCode",
"(",
")",
"]",
"=",
"[",
"'message'",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'line'",
"=>",
"$",
"exception",
"->",
"getLine",
"(",
")",
",",
"'file'",
"=>",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"'trace'",
"=>",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
",",
"]",
";",
"$",
"this",
"->",
"hasErrors",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] |
add new error to list
@param \Exception $exception
@return $this
|
[
"add",
"new",
"error",
"to",
"list"
] |
64ef4c77af6284fc22748285d5e527edbdbed69b
|
https://github.com/bluetree-service/event/blob/64ef4c77af6284fc22748285d5e527edbdbed69b/src/Event/Base/EventDispatcher.php#L350-L361
|
21,666 |
GreenCape/joomla-cli
|
src/GreenCape/JoomlaCLI/Application.php
|
Application.addPlugins
|
private function addPlugins($path)
{
foreach (glob($path . '/*.php') as $filename)
{
$commandClass = __NAMESPACE__ . '\\' . basename($filename, '.php') . 'Command';
$command = new $commandClass;
$this->add($command);
}
}
|
php
|
private function addPlugins($path)
{
foreach (glob($path . '/*.php') as $filename)
{
$commandClass = __NAMESPACE__ . '\\' . basename($filename, '.php') . 'Command';
$command = new $commandClass;
$this->add($command);
}
}
|
[
"private",
"function",
"addPlugins",
"(",
"$",
"path",
")",
"{",
"foreach",
"(",
"glob",
"(",
"$",
"path",
".",
"'/*.php'",
")",
"as",
"$",
"filename",
")",
"{",
"$",
"commandClass",
"=",
"__NAMESPACE__",
".",
"'\\\\'",
".",
"basename",
"(",
"$",
"filename",
",",
"'.php'",
")",
".",
"'Command'",
";",
"$",
"command",
"=",
"new",
"$",
"commandClass",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"command",
")",
";",
"}",
"}"
] |
Dynamically add all commands from a path
@param string $path The directory with the plugins
@return void
|
[
"Dynamically",
"add",
"all",
"commands",
"from",
"a",
"path"
] |
74a6940f27b1f66c99330d4f9e2c5ac314cdd369
|
https://github.com/GreenCape/joomla-cli/blob/74a6940f27b1f66c99330d4f9e2c5ac314cdd369/src/GreenCape/JoomlaCLI/Application.php#L96-L104
|
21,667 |
unclecheese/silverstripe-blubber
|
code/Sampler.php
|
Sampler.execute
|
public function execute() {
$results = ArrayList::create();
foreach($this->classes as $c) {
if($this->isOmitted($c)) continue;
$list = DataList::create($c)
->filter('ClassName', $c)
->limit($this->getLimitFor($c))
->sort("RAND()");
foreach($list as $record) {
$results->push($record);
}
}
return $results;
}
|
php
|
public function execute() {
$results = ArrayList::create();
foreach($this->classes as $c) {
if($this->isOmitted($c)) continue;
$list = DataList::create($c)
->filter('ClassName', $c)
->limit($this->getLimitFor($c))
->sort("RAND()");
foreach($list as $record) {
$results->push($record);
}
}
return $results;
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"results",
"=",
"ArrayList",
"::",
"create",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOmitted",
"(",
"$",
"c",
")",
")",
"continue",
";",
"$",
"list",
"=",
"DataList",
"::",
"create",
"(",
"$",
"c",
")",
"->",
"filter",
"(",
"'ClassName'",
",",
"$",
"c",
")",
"->",
"limit",
"(",
"$",
"this",
"->",
"getLimitFor",
"(",
"$",
"c",
")",
")",
"->",
"sort",
"(",
"\"RAND()\"",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"record",
")",
"{",
"$",
"results",
"->",
"push",
"(",
"$",
"record",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] |
Executes the query, gets the samples
@return ArrayList
|
[
"Executes",
"the",
"query",
"gets",
"the",
"samples"
] |
f2549bd5eddeb0ca0303a3c09be4a8136fcc6661
|
https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Sampler.php#L56-L73
|
21,668 |
unclecheese/silverstripe-blubber
|
code/Sampler.php
|
Sampler.isOmitted
|
protected function isOmitted($c) {
foreach($this->omissions as $o) {
if($c == $o || is_subclass_of($c, $o)) {
return true;
}
}
return false;
}
|
php
|
protected function isOmitted($c) {
foreach($this->omissions as $o) {
if($c == $o || is_subclass_of($c, $o)) {
return true;
}
}
return false;
}
|
[
"protected",
"function",
"isOmitted",
"(",
"$",
"c",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"omissions",
"as",
"$",
"o",
")",
"{",
"if",
"(",
"$",
"c",
"==",
"$",
"o",
"||",
"is_subclass_of",
"(",
"$",
"c",
",",
"$",
"o",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns true if a class is omitted
@param string $c The class name
@return boolean
|
[
"Returns",
"true",
"if",
"a",
"class",
"is",
"omitted"
] |
f2549bd5eddeb0ca0303a3c09be4a8136fcc6661
|
https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Sampler.php#L81-L89
|
21,669 |
PHPPowertools/HTML5
|
src/PowerTools/HTML5/Parser/DOMTreeBuilder.php
|
HTML5_Parser_DOMTreeBuilder.isAncestor
|
protected function isAncestor($tagname) {
$candidate = $this->current;
while ($candidate->nodeType === XML_ELEMENT_NODE) {
if ($candidate->tagName == $tagname) {
return true;
}
$candidate = $candidate->parentNode;
}
return false;
}
|
php
|
protected function isAncestor($tagname) {
$candidate = $this->current;
while ($candidate->nodeType === XML_ELEMENT_NODE) {
if ($candidate->tagName == $tagname) {
return true;
}
$candidate = $candidate->parentNode;
}
return false;
}
|
[
"protected",
"function",
"isAncestor",
"(",
"$",
"tagname",
")",
"{",
"$",
"candidate",
"=",
"$",
"this",
"->",
"current",
";",
"while",
"(",
"$",
"candidate",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
")",
"{",
"if",
"(",
"$",
"candidate",
"->",
"tagName",
"==",
"$",
"tagname",
")",
"{",
"return",
"true",
";",
"}",
"$",
"candidate",
"=",
"$",
"candidate",
"->",
"parentNode",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if the given tagname is an ancestor of the present candidate.
If $this->current or anything above $this->current matches the given tag
name, this returns true.
|
[
"Checks",
"if",
"the",
"given",
"tagname",
"is",
"an",
"ancestor",
"of",
"the",
"present",
"candidate",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/DOMTreeBuilder.php#L663-L673
|
21,670 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.setPointColor
|
public function setPointColor($r, $g, $b)
{
$this->ink['point'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
php
|
public function setPointColor($r, $g, $b)
{
$this->ink['point'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
[
"public",
"function",
"setPointColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Sets the point color in rgb format
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255
|
[
"Sets",
"the",
"point",
"color",
"in",
"rgb",
"format"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L143-L147
|
21,671 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.setLineColor
|
public function setLineColor($r, $g, $b)
{
$this->ink['line'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
php
|
public function setLineColor($r, $g, $b)
{
$this->ink['line'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
[
"public",
"function",
"setLineColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'line'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Sets the line color in rgb format
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255
|
[
"Sets",
"the",
"line",
"color",
"in",
"rgb",
"format"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L156-L160
|
21,672 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.setTextColor
|
public function setTextColor($r, $g, $b)
{
$this->ink['text'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
php
|
public function setTextColor($r, $g, $b)
{
$this->ink['text'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
[
"public",
"function",
"setTextColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Sets the text color in rgb format - labels
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255
|
[
"Sets",
"the",
"text",
"color",
"in",
"rgb",
"format",
"-",
"labels"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L169-L172
|
21,673 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.setAxisColor
|
public function setAxisColor($r, $g, $b)
{
$this->ink['axis'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
php
|
public function setAxisColor($r, $g, $b)
{
$this->ink['axis'] = imagecolorallocate($this->im, $r, $g, $b);
}
|
[
"public",
"function",
"setAxisColor",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] |
Sets the axis color in rgb format - axis
@param integer $r The red value 0-255
@param integer $g The green value 0-255
@param integer $b The blue value 0-255
|
[
"Sets",
"the",
"axis",
"color",
"in",
"rgb",
"format",
"-",
"axis"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L181-L184
|
21,674 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.createBackground
|
private function createBackground()
{
imagefilledrectangle($this->im, 0, 0, $this->width, $this->height,
$this->ink['black']);
}
|
php
|
private function createBackground()
{
imagefilledrectangle($this->im, 0, 0, $this->width, $this->height,
$this->ink['black']);
}
|
[
"private",
"function",
"createBackground",
"(",
")",
"{",
"imagefilledrectangle",
"(",
"$",
"this",
"->",
"im",
",",
"0",
",",
"0",
",",
"$",
"this",
"->",
"width",
",",
"$",
"this",
"->",
"height",
",",
"$",
"this",
"->",
"ink",
"[",
"'black'",
"]",
")",
";",
"}"
] |
Create the backgrround image
|
[
"Create",
"the",
"backgrround",
"image"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L198-L203
|
21,675 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.allocateColors
|
private function allocateColors()
{
$this->ink['red'] = imagecolorallocate($this->im, 0xff, 0x00, 0x00);
$this->ink['orange'] = imagecolorallocate($this->im, 0xd2, 0x8a, 0x00);
$this->ink['yellow'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['green'] = imagecolorallocate($this->im, 0x00, 0xff, 0x00);
$this->ink['blue'] = imagecolorallocate($this->im, 0x00, 0x00, 0xff);
$this->ink['purple'] = imagecolorallocate($this->im, 0x70, 0x70, 0xf9);
$this->ink['white'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['black'] = imagecolorallocate($this->im, 0x00, 0x00, 0x00);
$this->ink['gray'] = imagecolorallocate($this->im, 0xaf, 0xaf, 0xaf);
$this->ink['axis'] = imagecolorallocate($this->im, 95, 95, 95);
$this->ink['line'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['background'] = imagecolorallocate($this->im, 0x00, 0x00,
0x00);
$this->ink['text'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['point'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
}
|
php
|
private function allocateColors()
{
$this->ink['red'] = imagecolorallocate($this->im, 0xff, 0x00, 0x00);
$this->ink['orange'] = imagecolorallocate($this->im, 0xd2, 0x8a, 0x00);
$this->ink['yellow'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['green'] = imagecolorallocate($this->im, 0x00, 0xff, 0x00);
$this->ink['blue'] = imagecolorallocate($this->im, 0x00, 0x00, 0xff);
$this->ink['purple'] = imagecolorallocate($this->im, 0x70, 0x70, 0xf9);
$this->ink['white'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['black'] = imagecolorallocate($this->im, 0x00, 0x00, 0x00);
$this->ink['gray'] = imagecolorallocate($this->im, 0xaf, 0xaf, 0xaf);
$this->ink['axis'] = imagecolorallocate($this->im, 95, 95, 95);
$this->ink['line'] = imagecolorallocate($this->im, 0xff, 0xff, 0x00);
$this->ink['background'] = imagecolorallocate($this->im, 0x00, 0x00,
0x00);
$this->ink['text'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
$this->ink['point'] = imagecolorallocate($this->im, 0xff, 0xff, 0xff);
}
|
[
"private",
"function",
"allocateColors",
"(",
")",
"{",
"$",
"this",
"->",
"ink",
"[",
"'red'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0x00",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'orange'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xd2",
",",
"0x8a",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'yellow'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'green'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0xff",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'blue'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0x00",
",",
"0xff",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'purple'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x70",
",",
"0x70",
",",
"0xf9",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'white'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0xff",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'black'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0x00",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'gray'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xaf",
",",
"0xaf",
",",
"0xaf",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"95",
",",
"95",
",",
"95",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'line'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'background'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0x00",
",",
"0x00",
",",
"0x00",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0xff",
")",
";",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
"=",
"imagecolorallocate",
"(",
"$",
"this",
"->",
"im",
",",
"0xff",
",",
"0xff",
",",
"0xff",
")",
";",
"}"
] |
Allocates the default color used
|
[
"Allocates",
"the",
"default",
"color",
"used"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L209-L230
|
21,676 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.mapYvalue
|
private function mapYvalue($value)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(30, $this->graph_height), Array($this->min, $this->max));
return $rangeMapper->convert($value);
}
|
php
|
private function mapYvalue($value)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(30, $this->graph_height), Array($this->min, $this->max));
return $rangeMapper->convert($value);
}
|
[
"private",
"function",
"mapYvalue",
"(",
"$",
"value",
")",
"{",
"$",
"rangeMapper",
"=",
"new",
"\\",
"sb",
"\\",
"Math",
"\\",
"RangeMapper",
"(",
"Array",
"(",
"30",
",",
"$",
"this",
"->",
"graph_height",
")",
",",
"Array",
"(",
"$",
"this",
"->",
"min",
",",
"$",
"this",
"->",
"max",
")",
")",
";",
"return",
"$",
"rangeMapper",
"->",
"convert",
"(",
"$",
"value",
")",
";",
"}"
] |
Converts the range from point to pixel value
@param integer $value The value to convert
@return integer The number as converted into the pixel range on the graph
|
[
"Converts",
"the",
"range",
"from",
"point",
"to",
"pixel",
"value"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L238-L243
|
21,677 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.setValues
|
private function setValues($values)
{
$numbers = Array();
foreach ($values as $key => $val) {
$value = new \stdClass();
$value->label = trim($key);
if (!is_numeric($val)) {
$val = null;
}
$value->value = $val;
$this->values[] = $value;
$numbers[] = $val;
}
$min_max = Array();
foreach ($numbers as $number) {
if (!is_null($number)) {
array_push($min_max, $number);
}
}
$this->min = min($min_max);
$this->max = max($min_max);
$this->total_values = count($numbers);
$separation_dist = (($this->graph_width - 40) / $this->total_values);
$i = 0;
$this->points = Array();
foreach ($this->values as $value) {
$point = new \stdClass();
$point->x = ($i * $separation_dist) + $this->axis_offset + 40;
$point->y = $this->plotValue($value->value);
$point->label = $value->label;
$point->value = $value->value;
$this->points[] = $point;
$i++;
}
return $this->points;
}
|
php
|
private function setValues($values)
{
$numbers = Array();
foreach ($values as $key => $val) {
$value = new \stdClass();
$value->label = trim($key);
if (!is_numeric($val)) {
$val = null;
}
$value->value = $val;
$this->values[] = $value;
$numbers[] = $val;
}
$min_max = Array();
foreach ($numbers as $number) {
if (!is_null($number)) {
array_push($min_max, $number);
}
}
$this->min = min($min_max);
$this->max = max($min_max);
$this->total_values = count($numbers);
$separation_dist = (($this->graph_width - 40) / $this->total_values);
$i = 0;
$this->points = Array();
foreach ($this->values as $value) {
$point = new \stdClass();
$point->x = ($i * $separation_dist) + $this->axis_offset + 40;
$point->y = $this->plotValue($value->value);
$point->label = $value->label;
$point->value = $value->value;
$this->points[] = $point;
$i++;
}
return $this->points;
}
|
[
"private",
"function",
"setValues",
"(",
"$",
"values",
")",
"{",
"$",
"numbers",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"value",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"value",
"->",
"label",
"=",
"trim",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"$",
"val",
"=",
"null",
";",
"}",
"$",
"value",
"->",
"value",
"=",
"$",
"val",
";",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"numbers",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"min_max",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"numbers",
"as",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"number",
")",
")",
"{",
"array_push",
"(",
"$",
"min_max",
",",
"$",
"number",
")",
";",
"}",
"}",
"$",
"this",
"->",
"min",
"=",
"min",
"(",
"$",
"min_max",
")",
";",
"$",
"this",
"->",
"max",
"=",
"max",
"(",
"$",
"min_max",
")",
";",
"$",
"this",
"->",
"total_values",
"=",
"count",
"(",
"$",
"numbers",
")",
";",
"$",
"separation_dist",
"=",
"(",
"(",
"$",
"this",
"->",
"graph_width",
"-",
"40",
")",
"/",
"$",
"this",
"->",
"total_values",
")",
";",
"$",
"i",
"=",
"0",
";",
"$",
"this",
"->",
"points",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"point",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"point",
"->",
"x",
"=",
"(",
"$",
"i",
"*",
"$",
"separation_dist",
")",
"+",
"$",
"this",
"->",
"axis_offset",
"+",
"40",
";",
"$",
"point",
"->",
"y",
"=",
"$",
"this",
"->",
"plotValue",
"(",
"$",
"value",
"->",
"value",
")",
";",
"$",
"point",
"->",
"label",
"=",
"$",
"value",
"->",
"label",
";",
"$",
"point",
"->",
"value",
"=",
"$",
"value",
"->",
"value",
";",
"$",
"this",
"->",
"points",
"[",
"]",
"=",
"$",
"point",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"this",
"->",
"points",
";",
"}"
] |
Converts the values into usable data for the drawing of the graph
@param array $values
|
[
"Converts",
"the",
"values",
"into",
"usable",
"data",
"for",
"the",
"drawing",
"of",
"the",
"graph"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L250-L294
|
21,678 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.plotValue
|
private function plotValue($y)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(
$this->axis_offset,
$this->graph_height - $this->axis_offset
), Array($this->max, $this->min));
return $rangeMapper->convert($y);
}
|
php
|
private function plotValue($y)
{
$rangeMapper = new \sb\Math\RangeMapper(Array(
$this->axis_offset,
$this->graph_height - $this->axis_offset
), Array($this->max, $this->min));
return $rangeMapper->convert($y);
}
|
[
"private",
"function",
"plotValue",
"(",
"$",
"y",
")",
"{",
"$",
"rangeMapper",
"=",
"new",
"\\",
"sb",
"\\",
"Math",
"\\",
"RangeMapper",
"(",
"Array",
"(",
"$",
"this",
"->",
"axis_offset",
",",
"$",
"this",
"->",
"graph_height",
"-",
"$",
"this",
"->",
"axis_offset",
")",
",",
"Array",
"(",
"$",
"this",
"->",
"max",
",",
"$",
"this",
"->",
"min",
")",
")",
";",
"return",
"$",
"rangeMapper",
"->",
"convert",
"(",
"$",
"y",
")",
";",
"}"
] |
Converts points on the graph to pixels
@param integer $y
@return integer The value in pixels
|
[
"Converts",
"points",
"on",
"the",
"graph",
"to",
"pixels"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L341-L348
|
21,679 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.connectPoints
|
private function connectPoints()
{
foreach ($this->points as $point) {
if (is_null($point->value)) {
$last_x = $point->x;
$last_y = $point->y;
$last_val = $point->value;
continue;
}
if (isset($last_x) && (isset($last_val) && !is_null($last_val))) {
imageline($this->im, $last_x, $last_y, $point->x, $point->y,
$this->ink['line']);
}
$last_val = $point->value;
$last_x = $point->x;
$last_y = $point->y;
}
}
|
php
|
private function connectPoints()
{
foreach ($this->points as $point) {
if (is_null($point->value)) {
$last_x = $point->x;
$last_y = $point->y;
$last_val = $point->value;
continue;
}
if (isset($last_x) && (isset($last_val) && !is_null($last_val))) {
imageline($this->im, $last_x, $last_y, $point->x, $point->y,
$this->ink['line']);
}
$last_val = $point->value;
$last_x = $point->x;
$last_y = $point->y;
}
}
|
[
"private",
"function",
"connectPoints",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"points",
"as",
"$",
"point",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"point",
"->",
"value",
")",
")",
"{",
"$",
"last_x",
"=",
"$",
"point",
"->",
"x",
";",
"$",
"last_y",
"=",
"$",
"point",
"->",
"y",
";",
"$",
"last_val",
"=",
"$",
"point",
"->",
"value",
";",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"last_x",
")",
"&&",
"(",
"isset",
"(",
"$",
"last_val",
")",
"&&",
"!",
"is_null",
"(",
"$",
"last_val",
")",
")",
")",
"{",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"last_x",
",",
"$",
"last_y",
",",
"$",
"point",
"->",
"x",
",",
"$",
"point",
"->",
"y",
",",
"$",
"this",
"->",
"ink",
"[",
"'line'",
"]",
")",
";",
"}",
"$",
"last_val",
"=",
"$",
"point",
"->",
"value",
";",
"$",
"last_x",
"=",
"$",
"point",
"->",
"x",
";",
"$",
"last_y",
"=",
"$",
"point",
"->",
"y",
";",
"}",
"}"
] |
Connect the points on a graph
|
[
"Connect",
"the",
"points",
"on",
"a",
"graph"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L354-L373
|
21,680 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.draw
|
public function draw()
{
$this->drawYaxis();
if ($this->connect_points == 1) {
$this->connectPoints();
}
foreach ($this->points as $point) {
if ($this->y_axis_hints == 1) {
imagedashedline($this->im, $point->x, $this->height, $point->x,
0, $this->ink['axis']);
} else {
//add axis line
imageline($this->im, $point->x, $this->graph_height, $point->x,
$this->graph_height + 10, $this->ink['axis']);
}
//add axis label
imagestring($this->im, 1, $point->x + 5, $this->graph_height + 10,
$point->label, $this->ink['text']);
//don't plot actual point if it is null
if (is_null($point->value)) {
continue;
}
//plot point
imagefilledellipse($this->im, $point->x, $point->y, 7, 7,
$this->ink['point']);
//add point label
if ($point->y <= 5) {
$posy = $point->y + 5;
} elseif ($point->y >= $this->graph_height - 5) {
$posy = $point->y - 20;
} else {
$posy = $point->y - 15;
}
imagestring($this->im, 3, $point->x + 10, $posy, $point->value,
$this->ink['point']);
}
}
|
php
|
public function draw()
{
$this->drawYaxis();
if ($this->connect_points == 1) {
$this->connectPoints();
}
foreach ($this->points as $point) {
if ($this->y_axis_hints == 1) {
imagedashedline($this->im, $point->x, $this->height, $point->x,
0, $this->ink['axis']);
} else {
//add axis line
imageline($this->im, $point->x, $this->graph_height, $point->x,
$this->graph_height + 10, $this->ink['axis']);
}
//add axis label
imagestring($this->im, 1, $point->x + 5, $this->graph_height + 10,
$point->label, $this->ink['text']);
//don't plot actual point if it is null
if (is_null($point->value)) {
continue;
}
//plot point
imagefilledellipse($this->im, $point->x, $point->y, 7, 7,
$this->ink['point']);
//add point label
if ($point->y <= 5) {
$posy = $point->y + 5;
} elseif ($point->y >= $this->graph_height - 5) {
$posy = $point->y - 20;
} else {
$posy = $point->y - 15;
}
imagestring($this->im, 3, $point->x + 10, $posy, $point->value,
$this->ink['point']);
}
}
|
[
"public",
"function",
"draw",
"(",
")",
"{",
"$",
"this",
"->",
"drawYaxis",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"connect_points",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"connectPoints",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"points",
"as",
"$",
"point",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"y_axis_hints",
"==",
"1",
")",
"{",
"imagedashedline",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"point",
"->",
"x",
",",
"$",
"this",
"->",
"height",
",",
"$",
"point",
"->",
"x",
",",
"0",
",",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
")",
";",
"}",
"else",
"{",
"//add axis line",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"point",
"->",
"x",
",",
"$",
"this",
"->",
"graph_height",
",",
"$",
"point",
"->",
"x",
",",
"$",
"this",
"->",
"graph_height",
"+",
"10",
",",
"$",
"this",
"->",
"ink",
"[",
"'axis'",
"]",
")",
";",
"}",
"//add axis label",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"1",
",",
"$",
"point",
"->",
"x",
"+",
"5",
",",
"$",
"this",
"->",
"graph_height",
"+",
"10",
",",
"$",
"point",
"->",
"label",
",",
"$",
"this",
"->",
"ink",
"[",
"'text'",
"]",
")",
";",
"//don't plot actual point if it is null",
"if",
"(",
"is_null",
"(",
"$",
"point",
"->",
"value",
")",
")",
"{",
"continue",
";",
"}",
"//plot point",
"imagefilledellipse",
"(",
"$",
"this",
"->",
"im",
",",
"$",
"point",
"->",
"x",
",",
"$",
"point",
"->",
"y",
",",
"7",
",",
"7",
",",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
")",
";",
"//add point label",
"if",
"(",
"$",
"point",
"->",
"y",
"<=",
"5",
")",
"{",
"$",
"posy",
"=",
"$",
"point",
"->",
"y",
"+",
"5",
";",
"}",
"elseif",
"(",
"$",
"point",
"->",
"y",
">=",
"$",
"this",
"->",
"graph_height",
"-",
"5",
")",
"{",
"$",
"posy",
"=",
"$",
"point",
"->",
"y",
"-",
"20",
";",
"}",
"else",
"{",
"$",
"posy",
"=",
"$",
"point",
"->",
"y",
"-",
"15",
";",
"}",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"3",
",",
"$",
"point",
"->",
"x",
"+",
"10",
",",
"$",
"posy",
",",
"$",
"point",
"->",
"value",
",",
"$",
"this",
"->",
"ink",
"[",
"'point'",
"]",
")",
";",
"}",
"}"
] |
Draw the basic graph and plot the points
|
[
"Draw",
"the",
"basic",
"graph",
"and",
"plot",
"the",
"points"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L379-L425
|
21,681 |
surebert/surebert-framework
|
src/sb/Graph/Point.php
|
Point.addHorizontalLine
|
public function addHorizontalLine($y, $color = 'red', $label = '')
{
if (!array_key_exists($color, $this->ink)) {
throw(new \Exception("Ink color must be in " . implode(",",
\array_keys($this->ink))));
}
$y = $this->plotValue($y);
imageline($this->im, 0, $y, $this->width, $y, $this->ink[$color]);
imagestring($this->im, 2, $this->graph_width / 2 + $this->axis_offset,
$y, $label, $this->ink[$color]);
}
|
php
|
public function addHorizontalLine($y, $color = 'red', $label = '')
{
if (!array_key_exists($color, $this->ink)) {
throw(new \Exception("Ink color must be in " . implode(",",
\array_keys($this->ink))));
}
$y = $this->plotValue($y);
imageline($this->im, 0, $y, $this->width, $y, $this->ink[$color]);
imagestring($this->im, 2, $this->graph_width / 2 + $this->axis_offset,
$y, $label, $this->ink[$color]);
}
|
[
"public",
"function",
"addHorizontalLine",
"(",
"$",
"y",
",",
"$",
"color",
"=",
"'red'",
",",
"$",
"label",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"color",
",",
"$",
"this",
"->",
"ink",
")",
")",
"{",
"throw",
"(",
"new",
"\\",
"Exception",
"(",
"\"Ink color must be in \"",
".",
"implode",
"(",
"\",\"",
",",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"ink",
")",
")",
")",
")",
";",
"}",
"$",
"y",
"=",
"$",
"this",
"->",
"plotValue",
"(",
"$",
"y",
")",
";",
"imageline",
"(",
"$",
"this",
"->",
"im",
",",
"0",
",",
"$",
"y",
",",
"$",
"this",
"->",
"width",
",",
"$",
"y",
",",
"$",
"this",
"->",
"ink",
"[",
"$",
"color",
"]",
")",
";",
"imagestring",
"(",
"$",
"this",
"->",
"im",
",",
"2",
",",
"$",
"this",
"->",
"graph_width",
"/",
"2",
"+",
"$",
"this",
"->",
"axis_offset",
",",
"$",
"y",
",",
"$",
"label",
",",
"$",
"this",
"->",
"ink",
"[",
"$",
"color",
"]",
")",
";",
"}"
] |
Add a horizontal line
@param integer $y The y value
@param string $color red, orange, yellow, green, blue, purple
@param string $label The line label
|
[
"Add",
"a",
"horizontal",
"line"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Graph/Point.php#L434-L447
|
21,682 |
spiral-modules/listing
|
source/Listing/Prototypes/DependedModificator.php
|
DependedModificator.loadDependencies
|
protected function loadDependencies(RecordSelector $selector)
{
if (empty($this->dependencies)) {
return $selector;
}
foreach ($this->dependencies as $dependency) {
$selector = $selector->with(
$dependency->getRelation(),
$dependency->getOptions()
);
}
return $selector;
}
|
php
|
protected function loadDependencies(RecordSelector $selector)
{
if (empty($this->dependencies)) {
return $selector;
}
foreach ($this->dependencies as $dependency) {
$selector = $selector->with(
$dependency->getRelation(),
$dependency->getOptions()
);
}
return $selector;
}
|
[
"protected",
"function",
"loadDependencies",
"(",
"RecordSelector",
"$",
"selector",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"dependencies",
")",
")",
"{",
"return",
"$",
"selector",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"dependencies",
"as",
"$",
"dependency",
")",
"{",
"$",
"selector",
"=",
"$",
"selector",
"->",
"with",
"(",
"$",
"dependency",
"->",
"getRelation",
"(",
")",
",",
"$",
"dependency",
"->",
"getOptions",
"(",
")",
")",
";",
"}",
"return",
"$",
"selector",
";",
"}"
] |
Apply dependencies for RecordSelector
@param RecordSelector $selector
@return RecordSelector
|
[
"Apply",
"dependencies",
"for",
"RecordSelector"
] |
89abe8939ce91cbf61b51b99e93ce1e57c8af83c
|
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Prototypes/DependedModificator.php#L72-L86
|
21,683 |
LeaseCloud/leasecloud-php-sdk
|
src/Webook.php
|
Webook.validateSignature
|
public static function validateSignature($signature, $payload)
{
$parts = explode(',', $signature);
$parameters = [];
$t = 0;
// Find the timestamp
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 't') {
$t = $parsed['t'];
break;
}
}
if ($t === 0) {
return false;
}
$wanted = hash_hmac('sha256', $t . '.' . $payload, self::$secret);
// Find v1 hashes
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 'v1') {
if ($wanted === $parsed['v1']) {
return true;
}
}
}
return false;
}
|
php
|
public static function validateSignature($signature, $payload)
{
$parts = explode(',', $signature);
$parameters = [];
$t = 0;
// Find the timestamp
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 't') {
$t = $parsed['t'];
break;
}
}
if ($t === 0) {
return false;
}
$wanted = hash_hmac('sha256', $t . '.' . $payload, self::$secret);
// Find v1 hashes
foreach ($parts as $part) {
parse_str($part, $parsed);
if (key($parsed) === 'v1') {
if ($wanted === $parsed['v1']) {
return true;
}
}
}
return false;
}
|
[
"public",
"static",
"function",
"validateSignature",
"(",
"$",
"signature",
",",
"$",
"payload",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"signature",
")",
";",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"t",
"=",
"0",
";",
"// Find the timestamp",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"parse_str",
"(",
"$",
"part",
",",
"$",
"parsed",
")",
";",
"if",
"(",
"key",
"(",
"$",
"parsed",
")",
"===",
"'t'",
")",
"{",
"$",
"t",
"=",
"$",
"parsed",
"[",
"'t'",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"t",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"wanted",
"=",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"t",
".",
"'.'",
".",
"$",
"payload",
",",
"self",
"::",
"$",
"secret",
")",
";",
"// Find v1 hashes",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"parse_str",
"(",
"$",
"part",
",",
"$",
"parsed",
")",
";",
"if",
"(",
"key",
"(",
"$",
"parsed",
")",
"===",
"'v1'",
")",
"{",
"if",
"(",
"$",
"wanted",
"===",
"$",
"parsed",
"[",
"'v1'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Validate the webhook signature
@param string $signature The string passed in header LeaseCloud-Signature
@param string $payload The raw payload
@return bool True if the signature is valid, otherwise false
|
[
"Validate",
"the",
"webhook",
"signature"
] |
091b073dd4f79ba915a68c0ed151bd9bfa61e7ca
|
https://github.com/LeaseCloud/leasecloud-php-sdk/blob/091b073dd4f79ba915a68c0ed151bd9bfa61e7ca/src/Webook.php#L35-L66
|
21,684 |
NuclearCMS/Hierarchy
|
src/Tags/Taggable.php
|
Taggable.attachTag
|
public function attachTag($id)
{
if ( ! $this->tags->contains($id))
{
return $this->tags()->attach($id);
}
}
|
php
|
public function attachTag($id)
{
if ( ! $this->tags->contains($id))
{
return $this->tags()->attach($id);
}
}
|
[
"public",
"function",
"attachTag",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tags",
"->",
"contains",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tags",
"(",
")",
"->",
"attach",
"(",
"$",
"id",
")",
";",
"}",
"}"
] |
Links a tag to the node
@param int $id
|
[
"Links",
"a",
"tag",
"to",
"the",
"node"
] |
535171c5e2db72265313fd2110aec8456e46f459
|
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/Taggable.php#L36-L42
|
21,685 |
bpolaszek/simple-dbal
|
src/Model/Adapter/Mysqli/MysqliAdapter.php
|
MysqliAdapter.executeParallel
|
private function executeParallel($stmt, array $values = null): PromiseInterface
{
if (is_string($stmt)) {
$stmt = $this->emulatePrepare((string) $stmt, $values);
} else {
if (!$stmt instanceof Statement) {
throw new \InvalidArgumentException(sprintf('Expected %s object, got %s', Statement::class, get_class($stmt)));
}
if (!$stmt instanceof EmulatedStatement) {
$stmt = $this->emulatePrepare((string) $stmt, $values ?? $stmt->getValues());
} elseif (null !== $values) {
$stmt = $stmt->withValues($values);
}
}
try {
// Clone connection (Mysqli Asynchronous queries require a different connection to work properly)
$credentials = $this->getCredentials();
$cnx = self::createLink($credentials);
if ($this->hasOption('charset')) {
$cnx->set_charset($this->getOption('charset'));
}
} catch (mysqli_sql_exception $e) {
throw new AccessDeniedException($e->getMessage(), (int) $e->getCode(), $e);
}
$stmt->bind();
$promise = MysqliAsync::query($stmt->getRunnableQuery(), $cnx)->then(function ($result) use ($cnx, $stmt) {
if (!$result instanceof mysqli_result) {
$result = null;
}
return new Result($cnx, $result);
});
return $promise;
}
|
php
|
private function executeParallel($stmt, array $values = null): PromiseInterface
{
if (is_string($stmt)) {
$stmt = $this->emulatePrepare((string) $stmt, $values);
} else {
if (!$stmt instanceof Statement) {
throw new \InvalidArgumentException(sprintf('Expected %s object, got %s', Statement::class, get_class($stmt)));
}
if (!$stmt instanceof EmulatedStatement) {
$stmt = $this->emulatePrepare((string) $stmt, $values ?? $stmt->getValues());
} elseif (null !== $values) {
$stmt = $stmt->withValues($values);
}
}
try {
// Clone connection (Mysqli Asynchronous queries require a different connection to work properly)
$credentials = $this->getCredentials();
$cnx = self::createLink($credentials);
if ($this->hasOption('charset')) {
$cnx->set_charset($this->getOption('charset'));
}
} catch (mysqli_sql_exception $e) {
throw new AccessDeniedException($e->getMessage(), (int) $e->getCode(), $e);
}
$stmt->bind();
$promise = MysqliAsync::query($stmt->getRunnableQuery(), $cnx)->then(function ($result) use ($cnx, $stmt) {
if (!$result instanceof mysqli_result) {
$result = null;
}
return new Result($cnx, $result);
});
return $promise;
}
|
[
"private",
"function",
"executeParallel",
"(",
"$",
"stmt",
",",
"array",
"$",
"values",
"=",
"null",
")",
":",
"PromiseInterface",
"{",
"if",
"(",
"is_string",
"(",
"$",
"stmt",
")",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"emulatePrepare",
"(",
"(",
"string",
")",
"$",
"stmt",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"stmt",
"instanceof",
"Statement",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Expected %s object, got %s'",
",",
"Statement",
"::",
"class",
",",
"get_class",
"(",
"$",
"stmt",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"stmt",
"instanceof",
"EmulatedStatement",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"emulatePrepare",
"(",
"(",
"string",
")",
"$",
"stmt",
",",
"$",
"values",
"??",
"$",
"stmt",
"->",
"getValues",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"values",
")",
"{",
"$",
"stmt",
"=",
"$",
"stmt",
"->",
"withValues",
"(",
"$",
"values",
")",
";",
"}",
"}",
"try",
"{",
"// Clone connection (Mysqli Asynchronous queries require a different connection to work properly)",
"$",
"credentials",
"=",
"$",
"this",
"->",
"getCredentials",
"(",
")",
";",
"$",
"cnx",
"=",
"self",
"::",
"createLink",
"(",
"$",
"credentials",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasOption",
"(",
"'charset'",
")",
")",
"{",
"$",
"cnx",
"->",
"set_charset",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'charset'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"mysqli_sql_exception",
"$",
"e",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"(",
"int",
")",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"$",
"stmt",
"->",
"bind",
"(",
")",
";",
"$",
"promise",
"=",
"MysqliAsync",
"::",
"query",
"(",
"$",
"stmt",
"->",
"getRunnableQuery",
"(",
")",
",",
"$",
"cnx",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"$",
"cnx",
",",
"$",
"stmt",
")",
"{",
"if",
"(",
"!",
"$",
"result",
"instanceof",
"mysqli_result",
")",
"{",
"$",
"result",
"=",
"null",
";",
"}",
"return",
"new",
"Result",
"(",
"$",
"cnx",
",",
"$",
"result",
")",
";",
"}",
")",
";",
"return",
"$",
"promise",
";",
"}"
] |
EXPERIMENTAL ! Executes a statement asynchronously.
The promise will return a Result object.
@param $stmt
@param array|null $values
@return PromiseInterface
|
[
"EXPERIMENTAL",
"!",
"Executes",
"a",
"statement",
"asynchronously",
".",
"The",
"promise",
"will",
"return",
"a",
"Result",
"object",
"."
] |
52cb50d326ba5854191814b470f5e84950ebb6e6
|
https://github.com/bpolaszek/simple-dbal/blob/52cb50d326ba5854191814b470f5e84950ebb6e6/src/Model/Adapter/Mysqli/MysqliAdapter.php#L232-L266
|
21,686 |
watoki/curir
|
src/protocol/MimeTypes.php
|
MimeTypes.getType
|
public static function getType($extension) {
foreach (self::$map as $mime => $exts) {
if (in_array(strtolower($extension), $exts)) {
return $mime;
}
}
return null;
}
|
php
|
public static function getType($extension) {
foreach (self::$map as $mime => $exts) {
if (in_array(strtolower($extension), $exts)) {
return $mime;
}
}
return null;
}
|
[
"public",
"static",
"function",
"getType",
"(",
"$",
"extension",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"map",
"as",
"$",
"mime",
"=>",
"$",
"exts",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"extension",
")",
",",
"$",
"exts",
")",
")",
"{",
"return",
"$",
"mime",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Retruns MIME type belonging to given file extension or null if not found.
@static
@param $extension
@return null|string
|
[
"Retruns",
"MIME",
"type",
"belonging",
"to",
"given",
"file",
"extension",
"or",
"null",
"if",
"not",
"found",
"."
] |
20a44e1d1980f472369991e19ef8d3bafda79a64
|
https://github.com/watoki/curir/blob/20a44e1d1980f472369991e19ef8d3bafda79a64/src/protocol/MimeTypes.php#L137-L144
|
21,687 |
zicht/z
|
src/Zicht/Tool/PropertyPath/PropertyAccessor.php
|
PropertyAccessor.setByPath
|
public static function setByPath(&$subject, array $path, $value)
{
$ptr = & $subject;
foreach ($path as $key) {
if (is_object($ptr)) {
if (!isset($ptr->$key)) {
$ptr->$key = array();
}
$ptr = & $ptr->$key;
} elseif (is_array($ptr)) {
if (!isset($ptr[$key])) {
$ptr[$key] = array();
}
$ptr = & $ptr[$key];
}
}
$ptr = $value;
return $subject;
}
|
php
|
public static function setByPath(&$subject, array $path, $value)
{
$ptr = & $subject;
foreach ($path as $key) {
if (is_object($ptr)) {
if (!isset($ptr->$key)) {
$ptr->$key = array();
}
$ptr = & $ptr->$key;
} elseif (is_array($ptr)) {
if (!isset($ptr[$key])) {
$ptr[$key] = array();
}
$ptr = & $ptr[$key];
}
}
$ptr = $value;
return $subject;
}
|
[
"public",
"static",
"function",
"setByPath",
"(",
"&",
"$",
"subject",
",",
"array",
"$",
"path",
",",
"$",
"value",
")",
"{",
"$",
"ptr",
"=",
"&",
"$",
"subject",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"ptr",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ptr",
"->",
"$",
"key",
")",
")",
"{",
"$",
"ptr",
"->",
"$",
"key",
"=",
"array",
"(",
")",
";",
"}",
"$",
"ptr",
"=",
"&",
"$",
"ptr",
"->",
"$",
"key",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"ptr",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ptr",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"ptr",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"ptr",
"=",
"&",
"$",
"ptr",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"$",
"ptr",
"=",
"$",
"value",
";",
"return",
"$",
"subject",
";",
"}"
] |
Set a property value by a path of property or key names.
@param mixed &$subject
@param array $path
@param mixed $value
@return mixed
|
[
"Set",
"a",
"property",
"value",
"by",
"a",
"path",
"of",
"property",
"or",
"key",
"names",
"."
] |
6a1731dad20b018555a96b726a61d4bf8ec8c886
|
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/PropertyPath/PropertyAccessor.php#L52-L70
|
21,688 |
netvlies/NetvliesFormBundle
|
Service/FormService.php
|
FormService.get
|
public function get($id)
{
if (!isset($this->forms[$id])) {
$contentRepository = $this->container->get('doctrine')->getRepository('NetvliesFormBundle:Form');
$form = $contentRepository->findOneById($id);
$formBuilder = $this->container->get('form.factory')->createBuilder();
$formBuilder->add('form_id', 'hidden', array('data' => $id));
foreach ($form->getFields() as $field) {
$type = $field->getType();
$options = array(
'label' => $field->getLabel(),
'constraints' => array(),
);
if ($field->getRequired()) {
$options['constraints'][] = new NotBlank();
} else {
$options['required'] = false;
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
}
switch ($field->getType()) {
case 'select':
$type = 'choice';
$options['expanded'] = ($field->getSelectType() != 'dropdown');
$options['multiple'] = $field->getSelectMultiple();
$options['choices'] = array();
foreach ($field->getOptions() as $option) {
$options['choices'][$option->getLabel()] = $option->getLabel();
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
if ($options['multiple']) {
$options['data'] = explode(',', $options['data']);
}
}
break;
case 'email':
$options['constraints'][] = new Email();
break;
case 'date':
$options['widget'] = 'single_text';
$options['attr']['class'] = 'datepicker';
$options['attr']['placeholder'] = 'dd-mm-yyyy';
$options['input'] = 'string';
$options['format'] = 'd-M-y';
break;
}
$formBuilder->add('field_'.$field->getId(), $type, $options);
}
if ($form->getAddCaptcha()) {
$formBuilder->add('captcha', 'captcha');
}
$form->setSf2Form($formBuilder->getForm());
$this->forms[$id] = $form;
}
return $this->forms[$id];
}
|
php
|
public function get($id)
{
if (!isset($this->forms[$id])) {
$contentRepository = $this->container->get('doctrine')->getRepository('NetvliesFormBundle:Form');
$form = $contentRepository->findOneById($id);
$formBuilder = $this->container->get('form.factory')->createBuilder();
$formBuilder->add('form_id', 'hidden', array('data' => $id));
foreach ($form->getFields() as $field) {
$type = $field->getType();
$options = array(
'label' => $field->getLabel(),
'constraints' => array(),
);
if ($field->getRequired()) {
$options['constraints'][] = new NotBlank();
} else {
$options['required'] = false;
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
}
switch ($field->getType()) {
case 'select':
$type = 'choice';
$options['expanded'] = ($field->getSelectType() != 'dropdown');
$options['multiple'] = $field->getSelectMultiple();
$options['choices'] = array();
foreach ($field->getOptions() as $option) {
$options['choices'][$option->getLabel()] = $option->getLabel();
}
if ($field->getDefault()) {
$options['data'] = $field->getDefault();
if ($options['multiple']) {
$options['data'] = explode(',', $options['data']);
}
}
break;
case 'email':
$options['constraints'][] = new Email();
break;
case 'date':
$options['widget'] = 'single_text';
$options['attr']['class'] = 'datepicker';
$options['attr']['placeholder'] = 'dd-mm-yyyy';
$options['input'] = 'string';
$options['format'] = 'd-M-y';
break;
}
$formBuilder->add('field_'.$field->getId(), $type, $options);
}
if ($form->getAddCaptcha()) {
$formBuilder->add('captcha', 'captcha');
}
$form->setSf2Form($formBuilder->getForm());
$this->forms[$id] = $form;
}
return $this->forms[$id];
}
|
[
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"forms",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"contentRepository",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'doctrine'",
")",
"->",
"getRepository",
"(",
"'NetvliesFormBundle:Form'",
")",
";",
"$",
"form",
"=",
"$",
"contentRepository",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"$",
"formBuilder",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"createBuilder",
"(",
")",
";",
"$",
"formBuilder",
"->",
"add",
"(",
"'form_id'",
",",
"'hidden'",
",",
"array",
"(",
"'data'",
"=>",
"$",
"id",
")",
")",
";",
"foreach",
"(",
"$",
"form",
"->",
"getFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"type",
"=",
"$",
"field",
"->",
"getType",
"(",
")",
";",
"$",
"options",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"field",
"->",
"getLabel",
"(",
")",
",",
"'constraints'",
"=>",
"array",
"(",
")",
",",
")",
";",
"if",
"(",
"$",
"field",
"->",
"getRequired",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'constraints'",
"]",
"[",
"]",
"=",
"new",
"NotBlank",
"(",
")",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"'required'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"getDefault",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'data'",
"]",
"=",
"$",
"field",
"->",
"getDefault",
"(",
")",
";",
"}",
"switch",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"'select'",
":",
"$",
"type",
"=",
"'choice'",
";",
"$",
"options",
"[",
"'expanded'",
"]",
"=",
"(",
"$",
"field",
"->",
"getSelectType",
"(",
")",
"!=",
"'dropdown'",
")",
";",
"$",
"options",
"[",
"'multiple'",
"]",
"=",
"$",
"field",
"->",
"getSelectMultiple",
"(",
")",
";",
"$",
"options",
"[",
"'choices'",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"field",
"->",
"getOptions",
"(",
")",
"as",
"$",
"option",
")",
"{",
"$",
"options",
"[",
"'choices'",
"]",
"[",
"$",
"option",
"->",
"getLabel",
"(",
")",
"]",
"=",
"$",
"option",
"->",
"getLabel",
"(",
")",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"getDefault",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'data'",
"]",
"=",
"$",
"field",
"->",
"getDefault",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'multiple'",
"]",
")",
"{",
"$",
"options",
"[",
"'data'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"options",
"[",
"'data'",
"]",
")",
";",
"}",
"}",
"break",
";",
"case",
"'email'",
":",
"$",
"options",
"[",
"'constraints'",
"]",
"[",
"]",
"=",
"new",
"Email",
"(",
")",
";",
"break",
";",
"case",
"'date'",
":",
"$",
"options",
"[",
"'widget'",
"]",
"=",
"'single_text'",
";",
"$",
"options",
"[",
"'attr'",
"]",
"[",
"'class'",
"]",
"=",
"'datepicker'",
";",
"$",
"options",
"[",
"'attr'",
"]",
"[",
"'placeholder'",
"]",
"=",
"'dd-mm-yyyy'",
";",
"$",
"options",
"[",
"'input'",
"]",
"=",
"'string'",
";",
"$",
"options",
"[",
"'format'",
"]",
"=",
"'d-M-y'",
";",
"break",
";",
"}",
"$",
"formBuilder",
"->",
"add",
"(",
"'field_'",
".",
"$",
"field",
"->",
"getId",
"(",
")",
",",
"$",
"type",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"form",
"->",
"getAddCaptcha",
"(",
")",
")",
"{",
"$",
"formBuilder",
"->",
"add",
"(",
"'captcha'",
",",
"'captcha'",
")",
";",
"}",
"$",
"form",
"->",
"setSf2Form",
"(",
"$",
"formBuilder",
"->",
"getForm",
"(",
")",
")",
";",
"$",
"this",
"->",
"forms",
"[",
"$",
"id",
"]",
"=",
"$",
"form",
";",
"}",
"return",
"$",
"this",
"->",
"forms",
"[",
"$",
"id",
"]",
";",
"}"
] |
Builds the form with the requested ID. When a form is requested for the
second time, the instance created earlier is returned to ensure only one
form instance is used and form properties can be set and retrieved from
all locations where the form is used.
@param $id
@return mixed
|
[
"Builds",
"the",
"form",
"with",
"the",
"requested",
"ID",
".",
"When",
"a",
"form",
"is",
"requested",
"for",
"the",
"second",
"time",
"the",
"instance",
"created",
"earlier",
"is",
"returned",
"to",
"ensure",
"only",
"one",
"form",
"instance",
"is",
"used",
"and",
"form",
"properties",
"can",
"be",
"set",
"and",
"retrieved",
"from",
"all",
"locations",
"where",
"the",
"form",
"is",
"used",
"."
] |
93f9a3321d9925040111374e7c1014a6400a2d08
|
https://github.com/netvlies/NetvliesFormBundle/blob/93f9a3321d9925040111374e7c1014a6400a2d08/Service/FormService.php#L32-L99
|
21,689 |
PHPPowertools/HTML5
|
src/PowerTools/HTML5.php
|
HTML5.load
|
public function load($file) {
// Handle the case where file is a resource.
if (is_resource($file)) {
// FIXME: We need a StreamInputStream class.
return $this->loadHTML(stream_get_contents($file));
}
$input = new HTML5_Inputstream_File($file);
return $this->parse($input);
}
|
php
|
public function load($file) {
// Handle the case where file is a resource.
if (is_resource($file)) {
// FIXME: We need a StreamInputStream class.
return $this->loadHTML(stream_get_contents($file));
}
$input = new HTML5_Inputstream_File($file);
return $this->parse($input);
}
|
[
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"// Handle the case where file is a resource.",
"if",
"(",
"is_resource",
"(",
"$",
"file",
")",
")",
"{",
"// FIXME: We need a StreamInputStream class.",
"return",
"$",
"this",
"->",
"loadHTML",
"(",
"stream_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}",
"$",
"input",
"=",
"new",
"HTML5_Inputstream_File",
"(",
"$",
"file",
")",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
"$",
"input",
")",
";",
"}"
] |
Load and parse an HTML file.
This will apply the HTML5 parser, which is tolerant of many
varieties of HTML, including XHTML 1, HTML 4, and well-formed HTML
3. Note that in these cases, not all of the old data will be
preserved. For example, XHTML's XML declaration will be removed.
The rules governing parsing are set out in the HTML 5 spec.
@param string $file
The path to the file to parse. If this is a resource, it is
assumed to be an open stream whose pointer is set to the first
byte of input.
@return \DOMDocument A DOM document. These object type is defined by the libxml
library, and should have been included with your version of PHP.
|
[
"Load",
"and",
"parse",
"an",
"HTML",
"file",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L139-L149
|
21,690 |
PHPPowertools/HTML5
|
src/PowerTools/HTML5.php
|
HTML5.parse
|
public function parse(HTML5_Inputstream_Interface $input) {
$this->errors = array();
$events = new HTML5_Parser_DOMTreeBuilder(false, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->document();
}
|
php
|
public function parse(HTML5_Inputstream_Interface $input) {
$this->errors = array();
$events = new HTML5_Parser_DOMTreeBuilder(false, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->document();
}
|
[
"public",
"function",
"parse",
"(",
"HTML5_Inputstream_Interface",
"$",
"input",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"events",
"=",
"new",
"HTML5_Parser_DOMTreeBuilder",
"(",
"false",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"scanner",
"=",
"new",
"HTML5_Parser_Scanner",
"(",
"$",
"input",
")",
";",
"$",
"parser",
"=",
"new",
"HTML5_Parser_Tokenizer",
"(",
"$",
"scanner",
",",
"$",
"events",
")",
";",
"$",
"parser",
"->",
"parse",
"(",
")",
";",
"$",
"this",
"->",
"errors",
"=",
"$",
"events",
"->",
"getErrors",
"(",
")",
";",
"return",
"$",
"events",
"->",
"document",
"(",
")",
";",
"}"
] |
Parse an input stream.
Lower-level loading function. This requires an input stream instead
of a string, file, or resource.
|
[
"Parse",
"an",
"input",
"stream",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L225-L235
|
21,691 |
PHPPowertools/HTML5
|
src/PowerTools/HTML5.php
|
HTML5.parseFragment
|
public function parseFragment(HTML5_Inputstream_Interface $input) {
$events = new HTML5_Parser_DOMTreeBuilder(true, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->fragment();
}
|
php
|
public function parseFragment(HTML5_Inputstream_Interface $input) {
$events = new HTML5_Parser_DOMTreeBuilder(true, $this->options);
$scanner = new HTML5_Parser_Scanner($input);
$parser = new HTML5_Parser_Tokenizer($scanner, $events);
$parser->parse();
$this->errors = $events->getErrors();
return $events->fragment();
}
|
[
"public",
"function",
"parseFragment",
"(",
"HTML5_Inputstream_Interface",
"$",
"input",
")",
"{",
"$",
"events",
"=",
"new",
"HTML5_Parser_DOMTreeBuilder",
"(",
"true",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"scanner",
"=",
"new",
"HTML5_Parser_Scanner",
"(",
"$",
"input",
")",
";",
"$",
"parser",
"=",
"new",
"HTML5_Parser_Tokenizer",
"(",
"$",
"scanner",
",",
"$",
"events",
")",
";",
"$",
"parser",
"->",
"parse",
"(",
")",
";",
"$",
"this",
"->",
"errors",
"=",
"$",
"events",
"->",
"getErrors",
"(",
")",
";",
"return",
"$",
"events",
"->",
"fragment",
"(",
")",
";",
"}"
] |
Parse an input stream where the stream is a fragment.
Lower-level loading function. This requires an input stream instead
of a string, file, or resource.
|
[
"Parse",
"an",
"input",
"stream",
"where",
"the",
"stream",
"is",
"a",
"fragment",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L243-L252
|
21,692 |
PHPPowertools/HTML5
|
src/PowerTools/HTML5.php
|
HTML5.save
|
public function save($dom, $file, $options = array()) {
$close = true;
if (is_resource($file)) {
$stream = $file;
$close = false;
} else {
$stream = fopen($file, 'w');
}
$options = array_merge($this->getOptions(), $options);
$rules = new HTML5_Serializer_OutputRules($stream, $options);
$trav = new HTML5_Serializer_Traverser($dom, $stream, $rules, $options);
$trav->walk();
if ($close) {
fclose($stream);
}
}
|
php
|
public function save($dom, $file, $options = array()) {
$close = true;
if (is_resource($file)) {
$stream = $file;
$close = false;
} else {
$stream = fopen($file, 'w');
}
$options = array_merge($this->getOptions(), $options);
$rules = new HTML5_Serializer_OutputRules($stream, $options);
$trav = new HTML5_Serializer_Traverser($dom, $stream, $rules, $options);
$trav->walk();
if ($close) {
fclose($stream);
}
}
|
[
"public",
"function",
"save",
"(",
"$",
"dom",
",",
"$",
"file",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"close",
"=",
"true",
";",
"if",
"(",
"is_resource",
"(",
"$",
"file",
")",
")",
"{",
"$",
"stream",
"=",
"$",
"file",
";",
"$",
"close",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"file",
",",
"'w'",
")",
";",
"}",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"options",
")",
";",
"$",
"rules",
"=",
"new",
"HTML5_Serializer_OutputRules",
"(",
"$",
"stream",
",",
"$",
"options",
")",
";",
"$",
"trav",
"=",
"new",
"HTML5_Serializer_Traverser",
"(",
"$",
"dom",
",",
"$",
"stream",
",",
"$",
"rules",
",",
"$",
"options",
")",
";",
"$",
"trav",
"->",
"walk",
"(",
")",
";",
"if",
"(",
"$",
"close",
")",
"{",
"fclose",
"(",
"$",
"stream",
")",
";",
"}",
"}"
] |
Save a DOM into a given file as HTML5.
@param mixed $dom
The DOM to be serialized.
@param string $file
The filename to be written.
@param array $options
Configuration options when serializing the DOM. These include:
- encode_entities: Text written to the output is escaped by default and not all
entities are encoded. If this is set to true all entities will be encoded.
Defaults to false.
|
[
"Save",
"a",
"DOM",
"into",
"a",
"given",
"file",
"as",
"HTML5",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L267-L284
|
21,693 |
PHPPowertools/HTML5
|
src/PowerTools/HTML5.php
|
HTML5.saveHTML
|
public function saveHTML($dom, $options = array()) {
$stream = fopen('php://temp', 'w');
$this->save($dom, $stream, array_merge($this->getOptions(), $options));
return stream_get_contents($stream, - 1, 0);
}
|
php
|
public function saveHTML($dom, $options = array()) {
$stream = fopen('php://temp', 'w');
$this->save($dom, $stream, array_merge($this->getOptions(), $options));
return stream_get_contents($stream, - 1, 0);
}
|
[
"public",
"function",
"saveHTML",
"(",
"$",
"dom",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"stream",
"=",
"fopen",
"(",
"'php://temp'",
",",
"'w'",
")",
";",
"$",
"this",
"->",
"save",
"(",
"$",
"dom",
",",
"$",
"stream",
",",
"array_merge",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"options",
")",
")",
";",
"return",
"stream_get_contents",
"(",
"$",
"stream",
",",
"-",
"1",
",",
"0",
")",
";",
"}"
] |
Convert a DOM into an HTML5 string.
@param mixed $dom
The DOM to be serialized.
@param array $options
Configuration options when serializing the DOM. These include:
- encode_entities: Text written to the output is escaped by default and not all
entities are encoded. If this is set to true all entities will be encoded.
Defaults to false.
@return string A HTML5 documented generated from the DOM.
|
[
"Convert",
"a",
"DOM",
"into",
"an",
"HTML5",
"string",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5.php#L299-L304
|
21,694 |
Erdiko/core
|
src/Logger.php
|
Logger.interpolate
|
function interpolate($message, array $context = array())
{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
if ($key == "exception" && $val instanceof \Exception) {
$replace['{' . $key . '}'] = $val->getMessage();
} else {
$replace['{' . $key . '}'] = $val;
}
}
// interpolate replacement values into the message and return
return strtr($message, $replace);
}
|
php
|
function interpolate($message, array $context = array())
{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
if ($key == "exception" && $val instanceof \Exception) {
$replace['{' . $key . '}'] = $val->getMessage();
} else {
$replace['{' . $key . '}'] = $val;
}
}
// interpolate replacement values into the message and return
return strtr($message, $replace);
}
|
[
"function",
"interpolate",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"// build a replacement array with braces around the context keys",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"context",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"\"exception\"",
"&&",
"$",
"val",
"instanceof",
"\\",
"Exception",
")",
"{",
"$",
"replace",
"[",
"'{'",
".",
"$",
"key",
".",
"'}'",
"]",
"=",
"$",
"val",
"->",
"getMessage",
"(",
")",
";",
"}",
"else",
"{",
"$",
"replace",
"[",
"'{'",
".",
"$",
"key",
".",
"'}'",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"// interpolate replacement values into the message and return",
"return",
"strtr",
"(",
"$",
"message",
",",
"$",
"replace",
")",
";",
"}"
] |
Implementation of Placeholder Interpolation
The message MAY contain placeholders which implementors MAY replace with values from the context array.
Placeholder names MUST correspond to keys in the context array.
@param string $message or an object with a __toString() method
@param array $context replacement values for placeholders
@return bool
|
[
"Implementation",
"of",
"Placeholder",
"Interpolation",
"The",
"message",
"MAY",
"contain",
"placeholders",
"which",
"implementors",
"MAY",
"replace",
"with",
"values",
"from",
"the",
"context",
"array",
".",
"Placeholder",
"names",
"MUST",
"correspond",
"to",
"keys",
"in",
"the",
"context",
"array",
"."
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L115-L129
|
21,695 |
Erdiko/core
|
src/Logger.php
|
Logger.addLogFile
|
public function addLogFile($key, $logFileName)
{
$arrayKey=strtolower($key);
return $this->_logFiles[$arrayKey] = $logFileName;
}
|
php
|
public function addLogFile($key, $logFileName)
{
$arrayKey=strtolower($key);
return $this->_logFiles[$arrayKey] = $logFileName;
}
|
[
"public",
"function",
"addLogFile",
"(",
"$",
"key",
",",
"$",
"logFileName",
")",
"{",
"$",
"arrayKey",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"_logFiles",
"[",
"$",
"arrayKey",
"]",
"=",
"$",
"logFileName",
";",
"}"
] |
Add log file
Valid if multiple log files exist
@param mixed $key
@param string $logFileName
@return bool
|
[
"Add",
"log",
"file",
"Valid",
"if",
"multiple",
"log",
"files",
"exist"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Logger.php#L139-L143
|
21,696 |
mothership-ec/composer
|
src/Composer/Command/HomeCommand.php
|
HomeCommand.getPackage
|
protected function getPackage(RepositoryInterface $repos, $name)
{
$name = strtolower($name);
$pool = new Pool('dev');
$pool->addRepository($repos);
$matches = $pool->whatProvides($name);
foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
return $package;
}
}
|
php
|
protected function getPackage(RepositoryInterface $repos, $name)
{
$name = strtolower($name);
$pool = new Pool('dev');
$pool->addRepository($repos);
$matches = $pool->whatProvides($name);
foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
return $package;
}
}
|
[
"protected",
"function",
"getPackage",
"(",
"RepositoryInterface",
"$",
"repos",
",",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"pool",
"=",
"new",
"Pool",
"(",
"'dev'",
")",
";",
"$",
"pool",
"->",
"addRepository",
"(",
"$",
"repos",
")",
";",
"$",
"matches",
"=",
"$",
"pool",
"->",
"whatProvides",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"index",
"=>",
"$",
"package",
")",
"{",
"// skip providers/replacers",
"if",
"(",
"$",
"package",
"->",
"getName",
"(",
")",
"!==",
"$",
"name",
")",
"{",
"unset",
"(",
"$",
"matches",
"[",
"$",
"index",
"]",
")",
";",
"continue",
";",
"}",
"return",
"$",
"package",
";",
"}",
"}"
] |
finds a package by name
@param RepositoryInterface $repos
@param string $name
@return CompletePackageInterface
|
[
"finds",
"a",
"package",
"by",
"name"
] |
fa6ad031a939d8d33b211e428fdbdd28cfce238c
|
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Command/HomeCommand.php#L109-L125
|
21,697 |
mothership-ec/composer
|
src/Composer/Command/HomeCommand.php
|
HomeCommand.openBrowser
|
private function openBrowser($url)
{
$url = ProcessExecutor::escape($url);
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
return passthru('start "web" explorer "' . $url . '"');
}
passthru('which xdg-open', $linux);
passthru('which open', $osx);
if (0 === $linux) {
passthru('xdg-open ' . $url);
} elseif (0 === $osx) {
passthru('open ' . $url);
} else {
$this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url);
}
}
|
php
|
private function openBrowser($url)
{
$url = ProcessExecutor::escape($url);
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
return passthru('start "web" explorer "' . $url . '"');
}
passthru('which xdg-open', $linux);
passthru('which open', $osx);
if (0 === $linux) {
passthru('xdg-open ' . $url);
} elseif (0 === $osx) {
passthru('open ' . $url);
} else {
$this->getIO()->writeError('no suitable browser opening command found, open yourself: ' . $url);
}
}
|
[
"private",
"function",
"openBrowser",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"ProcessExecutor",
"::",
"escape",
"(",
"$",
"url",
")",
";",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_MAJOR'",
")",
")",
"{",
"return",
"passthru",
"(",
"'start \"web\" explorer \"'",
".",
"$",
"url",
".",
"'\"'",
")",
";",
"}",
"passthru",
"(",
"'which xdg-open'",
",",
"$",
"linux",
")",
";",
"passthru",
"(",
"'which open'",
",",
"$",
"osx",
")",
";",
"if",
"(",
"0",
"===",
"$",
"linux",
")",
"{",
"passthru",
"(",
"'xdg-open '",
".",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"0",
"===",
"$",
"osx",
")",
"{",
"passthru",
"(",
"'open '",
".",
"$",
"url",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getIO",
"(",
")",
"->",
"writeError",
"(",
"'no suitable browser opening command found, open yourself: '",
".",
"$",
"url",
")",
";",
"}",
"}"
] |
opens a url in your system default browser
@param string $url
|
[
"opens",
"a",
"url",
"in",
"your",
"system",
"default",
"browser"
] |
fa6ad031a939d8d33b211e428fdbdd28cfce238c
|
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Command/HomeCommand.php#L132-L150
|
21,698 |
Baachi/CouchDB
|
src/CouchDB/DesignDocument/Result.php
|
Result.getFirstRow
|
public function getFirstRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, 0, 1);
return current($row);
}
|
php
|
public function getFirstRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, 0, 1);
return current($row);
}
|
[
"public",
"function",
"getFirstRow",
"(",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"data",
"[",
"'rows'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"row",
"=",
"array_slice",
"(",
"$",
"rows",
",",
"0",
",",
"1",
")",
";",
"return",
"current",
"(",
"$",
"row",
")",
";",
"}"
] |
Return the first row.
@return bool|array
|
[
"Return",
"the",
"first",
"row",
"."
] |
6be364c2f3d9c7b1288b1c11115469c91819ff5c
|
https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/DesignDocument/Result.php#L60-L70
|
21,699 |
Baachi/CouchDB
|
src/CouchDB/DesignDocument/Result.php
|
Result.getLastRow
|
public function getLastRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, count($rows) - 1);
return current($row);
}
|
php
|
public function getLastRow()
{
$rows = $this->data['rows'];
if (empty($rows)) {
return false;
}
$row = array_slice($rows, count($rows) - 1);
return current($row);
}
|
[
"public",
"function",
"getLastRow",
"(",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"data",
"[",
"'rows'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"row",
"=",
"array_slice",
"(",
"$",
"rows",
",",
"count",
"(",
"$",
"rows",
")",
"-",
"1",
")",
";",
"return",
"current",
"(",
"$",
"row",
")",
";",
"}"
] |
Return the last row.
@return bool|array
|
[
"Return",
"the",
"last",
"row",
"."
] |
6be364c2f3d9c7b1288b1c11115469c91819ff5c
|
https://github.com/Baachi/CouchDB/blob/6be364c2f3d9c7b1288b1c11115469c91819ff5c/src/CouchDB/DesignDocument/Result.php#L77-L87
|
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.