repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
nicodevs/laito | src/Laito/Controller.php | Controller.destroy | public function destroy($id = null)
{
// Check the ID
if (!isset($id)) {
throw new \InvalidArgumentException('Undefined ID', 400);
}
// Delete the record
$result = $this->model->destroy($id);
// Return results
return [
'success' => true,
'id' => $result
];
} | php | public function destroy($id = null)
{
// Check the ID
if (!isset($id)) {
throw new \InvalidArgumentException('Undefined ID', 400);
}
// Delete the record
$result = $this->model->destroy($id);
// Return results
return [
'success' => true,
'id' => $result
];
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"// Check the ID",
"if",
"(",
"!",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Undefined ID'",
",",
"400",
")",
";",
"}",
"// Delete the record",
"$",
"result",
"=",
"$",
"this",
"->",
"model",
"->",
"destroy",
"(",
"$",
"id",
")",
";",
"// Return results",
"return",
"[",
"'success'",
"=>",
"true",
",",
"'id'",
"=>",
"$",
"result",
"]",
";",
"}"
] | Remove the specified resource from storage
@param array $id Resource ID
@return array Response | [
"Remove",
"the",
"specified",
"resource",
"from",
"storage"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Controller.php#L155-L170 |
icicleio/dns | src/Executor/MultiExecutor.php | MultiExecutor.execute | public function execute(string $name, $type, array $options = []): \Generator
{
if (empty($this->executors)) {
throw new NoExecutorsError('No executors defined.');
}
$executors = $this->executors;
$count = count($executors);
for ($i = 0; $i < $count; ++$i) {
try {
return yield from $executors[$i]->execute($name, $type, $options);
} catch (MessageException $exception) {
// If it is still at the head, shift executor in main list to the tail for future requests.
if ($this->executors[0] === $executors[$i]) {
$this->executors[] = array_shift($this->executors);
}
}
}
throw $exception;
} | php | public function execute(string $name, $type, array $options = []): \Generator
{
if (empty($this->executors)) {
throw new NoExecutorsError('No executors defined.');
}
$executors = $this->executors;
$count = count($executors);
for ($i = 0; $i < $count; ++$i) {
try {
return yield from $executors[$i]->execute($name, $type, $options);
} catch (MessageException $exception) {
// If it is still at the head, shift executor in main list to the tail for future requests.
if ($this->executors[0] === $executors[$i]) {
$this->executors[] = array_shift($this->executors);
}
}
}
throw $exception;
} | [
"public",
"function",
"execute",
"(",
"string",
"$",
"name",
",",
"$",
"type",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"\\",
"Generator",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"executors",
")",
")",
"{",
"throw",
"new",
"NoExecutorsError",
"(",
"'No executors defined.'",
")",
";",
"}",
"$",
"executors",
"=",
"$",
"this",
"->",
"executors",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"executors",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"++",
"$",
"i",
")",
"{",
"try",
"{",
"return",
"yield",
"from",
"$",
"executors",
"[",
"$",
"i",
"]",
"->",
"execute",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"MessageException",
"$",
"exception",
")",
"{",
"// If it is still at the head, shift executor in main list to the tail for future requests.",
"if",
"(",
"$",
"this",
"->",
"executors",
"[",
"0",
"]",
"===",
"$",
"executors",
"[",
"$",
"i",
"]",
")",
"{",
"$",
"this",
"->",
"executors",
"[",
"]",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"executors",
")",
";",
"}",
"}",
"}",
"throw",
"$",
"exception",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/icicleio/dns/blob/31ca939e2661f87bd807c54be0e7ad1762a5b14a/src/Executor/MultiExecutor.php#L32-L53 |
CatLabInteractive/Accounts | src/CatLab/Accounts/Authenticators/Base/DeligatedAuthenticator.php | DeligatedAuthenticator.processLogin | private function processLogin (DeligatedUser $deligatedUser, $email, $password)
{
$mapper = \Neuron\MapperFactory::getUserMapper ();
ExpectedType::check ($mapper, UserMapper::class);
$user = $mapper->getFromLogin ($email, $password);
if ($user)
{
// Everything okay
// Link the deligated user to this user.
$deligatedUser->setUser ($user);
MapperFactory::getDeligatedMapper ()->update ($deligatedUser);
return $this->module->login ($this->request, $user);
}
else {
// Check if we have this email address
$user = $mapper->getFromEmail ($email);
if ($user)
{
return 'PASSWORD_INCORRECT';
}
else {
return 'USER_NOT_FOUND';
}
}
} | php | private function processLogin (DeligatedUser $deligatedUser, $email, $password)
{
$mapper = \Neuron\MapperFactory::getUserMapper ();
ExpectedType::check ($mapper, UserMapper::class);
$user = $mapper->getFromLogin ($email, $password);
if ($user)
{
// Everything okay
// Link the deligated user to this user.
$deligatedUser->setUser ($user);
MapperFactory::getDeligatedMapper ()->update ($deligatedUser);
return $this->module->login ($this->request, $user);
}
else {
// Check if we have this email address
$user = $mapper->getFromEmail ($email);
if ($user)
{
return 'PASSWORD_INCORRECT';
}
else {
return 'USER_NOT_FOUND';
}
}
} | [
"private",
"function",
"processLogin",
"(",
"DeligatedUser",
"$",
"deligatedUser",
",",
"$",
"email",
",",
"$",
"password",
")",
"{",
"$",
"mapper",
"=",
"\\",
"Neuron",
"\\",
"MapperFactory",
"::",
"getUserMapper",
"(",
")",
";",
"ExpectedType",
"::",
"check",
"(",
"$",
"mapper",
",",
"UserMapper",
"::",
"class",
")",
";",
"$",
"user",
"=",
"$",
"mapper",
"->",
"getFromLogin",
"(",
"$",
"email",
",",
"$",
"password",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"// Everything okay",
"// Link the deligated user to this user.",
"$",
"deligatedUser",
"->",
"setUser",
"(",
"$",
"user",
")",
";",
"MapperFactory",
"::",
"getDeligatedMapper",
"(",
")",
"->",
"update",
"(",
"$",
"deligatedUser",
")",
";",
"return",
"$",
"this",
"->",
"module",
"->",
"login",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"user",
")",
";",
"}",
"else",
"{",
"// Check if we have this email address",
"$",
"user",
"=",
"$",
"mapper",
"->",
"getFromEmail",
"(",
"$",
"email",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"return",
"'PASSWORD_INCORRECT'",
";",
"}",
"else",
"{",
"return",
"'USER_NOT_FOUND'",
";",
"}",
"}",
"}"
] | Return an error (string) or redirect
@param DeligatedUser $deligatedUser
@param $email
@param $password
@return Response|string
@throws ExpectedType | [
"Return",
"an",
"error",
"(",
"string",
")",
"or",
"redirect"
] | train | https://github.com/CatLabInteractive/Accounts/blob/e5465ad815c3caba5b7c1fde7b465a5fa05f3298/src/CatLab/Accounts/Authenticators/Base/DeligatedAuthenticator.php#L204-L233 |
Linkvalue-Interne/MobileNotifBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('link_value_mobile_notif');
$rootNode
->children()
->arrayNode('clients')
->isRequired()
->children()
->append($this->addApnsClientsNode())
->append($this->addGcmClientsNode())
->end()
->end()
->end()
;
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('link_value_mobile_notif');
$rootNode
->children()
->arrayNode('clients')
->isRequired()
->children()
->append($this->addApnsClientsNode())
->append($this->addGcmClientsNode())
->end()
->end()
->end()
;
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'link_value_mobile_notif'",
")",
";",
"$",
"rootNode",
"->",
"children",
"(",
")",
"->",
"arrayNode",
"(",
"'clients'",
")",
"->",
"isRequired",
"(",
")",
"->",
"children",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"addApnsClientsNode",
"(",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"addGcmClientsNode",
"(",
")",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Linkvalue-Interne/MobileNotifBundle/blob/8124f4132c581516be9928ece81ae2cf9f59763d/DependencyInjection/Configuration.php#L16-L34 |
Linkvalue-Interne/MobileNotifBundle | DependencyInjection/Configuration.php | Configuration.addApnsClientsNode | private function addApnsClientsNode()
{
$builder = new TreeBuilder();
$node = $builder->root('apns');
$node
->useAttributeAsKey('name')
->prototype('array')
->children()
->arrayNode('services')
->addDefaultsIfNotSet()
->children()
->scalarNode('logger')->defaultValue('logger')->end()
->scalarNode('profiler')->defaultValue('link_value_mobile_notif.profiler.client_profiler')->end()
->end()
->end()
->arrayNode('params')
->children()
->scalarNode('endpoint')->cannotBeEmpty()->defaultValue('tls://gateway.sandbox.push.apple.com:2195')->end()
->scalarNode('ssl_pem_path')->cannotBeEmpty()->isRequired()->end()
->scalarNode('ssl_passphrase')->cannotBeEmpty()->end()
->end()
->end()
->end()
->end()
;
return $node;
} | php | private function addApnsClientsNode()
{
$builder = new TreeBuilder();
$node = $builder->root('apns');
$node
->useAttributeAsKey('name')
->prototype('array')
->children()
->arrayNode('services')
->addDefaultsIfNotSet()
->children()
->scalarNode('logger')->defaultValue('logger')->end()
->scalarNode('profiler')->defaultValue('link_value_mobile_notif.profiler.client_profiler')->end()
->end()
->end()
->arrayNode('params')
->children()
->scalarNode('endpoint')->cannotBeEmpty()->defaultValue('tls://gateway.sandbox.push.apple.com:2195')->end()
->scalarNode('ssl_pem_path')->cannotBeEmpty()->isRequired()->end()
->scalarNode('ssl_passphrase')->cannotBeEmpty()->end()
->end()
->end()
->end()
->end()
;
return $node;
} | [
"private",
"function",
"addApnsClientsNode",
"(",
")",
"{",
"$",
"builder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"node",
"=",
"$",
"builder",
"->",
"root",
"(",
"'apns'",
")",
";",
"$",
"node",
"->",
"useAttributeAsKey",
"(",
"'name'",
")",
"->",
"prototype",
"(",
"'array'",
")",
"->",
"children",
"(",
")",
"->",
"arrayNode",
"(",
"'services'",
")",
"->",
"addDefaultsIfNotSet",
"(",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'logger'",
")",
"->",
"defaultValue",
"(",
"'logger'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'profiler'",
")",
"->",
"defaultValue",
"(",
"'link_value_mobile_notif.profiler.client_profiler'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'params'",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'endpoint'",
")",
"->",
"cannotBeEmpty",
"(",
")",
"->",
"defaultValue",
"(",
"'tls://gateway.sandbox.push.apple.com:2195'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'ssl_pem_path'",
")",
"->",
"cannotBeEmpty",
"(",
")",
"->",
"isRequired",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'ssl_passphrase'",
")",
"->",
"cannotBeEmpty",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"node",
";",
"}"
] | Add APNS clients node.
@return \Symfony\Component\Config\Definition\Builder\NodeDefinition | [
"Add",
"APNS",
"clients",
"node",
"."
] | train | https://github.com/Linkvalue-Interne/MobileNotifBundle/blob/8124f4132c581516be9928ece81ae2cf9f59763d/DependencyInjection/Configuration.php#L41-L69 |
ming123jew/magazine | Base.php | Base.autoload | public function autoload($controller,$action){
$className = '\\magazine\\controller\\'.$controller;
$controller = new $className($this->request);
if(method_exists($controller,$action)){
return call_user_func([$controller, $action]);
}
return false;
} | php | public function autoload($controller,$action){
$className = '\\magazine\\controller\\'.$controller;
$controller = new $className($this->request);
if(method_exists($controller,$action)){
return call_user_func([$controller, $action]);
}
return false;
} | [
"public",
"function",
"autoload",
"(",
"$",
"controller",
",",
"$",
"action",
")",
"{",
"$",
"className",
"=",
"'\\\\magazine\\\\controller\\\\'",
".",
"$",
"controller",
";",
"$",
"controller",
"=",
"new",
"$",
"className",
"(",
"$",
"this",
"->",
"request",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"controller",
",",
"$",
"action",
")",
")",
"{",
"return",
"call_user_func",
"(",
"[",
"$",
"controller",
",",
"$",
"action",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] | 加载控制器方法
@access public
@param string $controller 控制器
@param string $action 方法名
@return mixed | [
"加载控制器方法"
] | train | https://github.com/ming123jew/magazine/blob/b20b9441dddb7fcaee36eb2d9c2264d68291d475/Base.php#L50-L58 |
kkthek/diqa-util | maintenance/runStatistics.php | RunStatistics.getStatisticSites | private function getStatisticSites() {
$result = [ ];
$StatistikQuery = new \SMWPrintRequest ( \SMWPrintRequest::PRINT_PROP, "StatistikQuery",
\SMWPropertyValue::makeUserProperty ( 'StatistikQuery' ) );
$StatistikTemplate = new \SMWPrintRequest ( \SMWPrintRequest::PRINT_PROP, "StatistikTemplate",
\SMWPropertyValue::makeUserProperty ( 'StatistikTemplate' ) );
$pages = QueryUtils::executeBasicQuery ( '[[Category:Statistik]]', [$StatistikQuery, $StatistikTemplate ], [] );
while ( $res = $pages->getNext () ) {
$pageID = $res [0]->getNextText ( SMW_OUTPUT_WIKI );
$StatistikQuery = $res [1]->getNextText ( SMW_OUTPUT_WIKI );
$StatistikTemplate = $res [2]->getNextText ( SMW_OUTPUT_WIKI );
$mwTitle = \Title::newFromText ( $pageID );
$result [] = [ 'title' => $mwTitle,
'statistikQuery' => urldecode($StatistikQuery),
'statistikTemplate' => urldecode($StatistikTemplate)
];
}
return $result;
} | php | private function getStatisticSites() {
$result = [ ];
$StatistikQuery = new \SMWPrintRequest ( \SMWPrintRequest::PRINT_PROP, "StatistikQuery",
\SMWPropertyValue::makeUserProperty ( 'StatistikQuery' ) );
$StatistikTemplate = new \SMWPrintRequest ( \SMWPrintRequest::PRINT_PROP, "StatistikTemplate",
\SMWPropertyValue::makeUserProperty ( 'StatistikTemplate' ) );
$pages = QueryUtils::executeBasicQuery ( '[[Category:Statistik]]', [$StatistikQuery, $StatistikTemplate ], [] );
while ( $res = $pages->getNext () ) {
$pageID = $res [0]->getNextText ( SMW_OUTPUT_WIKI );
$StatistikQuery = $res [1]->getNextText ( SMW_OUTPUT_WIKI );
$StatistikTemplate = $res [2]->getNextText ( SMW_OUTPUT_WIKI );
$mwTitle = \Title::newFromText ( $pageID );
$result [] = [ 'title' => $mwTitle,
'statistikQuery' => urldecode($StatistikQuery),
'statistikTemplate' => urldecode($StatistikTemplate)
];
}
return $result;
} | [
"private",
"function",
"getStatisticSites",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"StatistikQuery",
"=",
"new",
"\\",
"SMWPrintRequest",
"(",
"\\",
"SMWPrintRequest",
"::",
"PRINT_PROP",
",",
"\"StatistikQuery\"",
",",
"\\",
"SMWPropertyValue",
"::",
"makeUserProperty",
"(",
"'StatistikQuery'",
")",
")",
";",
"$",
"StatistikTemplate",
"=",
"new",
"\\",
"SMWPrintRequest",
"(",
"\\",
"SMWPrintRequest",
"::",
"PRINT_PROP",
",",
"\"StatistikTemplate\"",
",",
"\\",
"SMWPropertyValue",
"::",
"makeUserProperty",
"(",
"'StatistikTemplate'",
")",
")",
";",
"$",
"pages",
"=",
"QueryUtils",
"::",
"executeBasicQuery",
"(",
"'[[Category:Statistik]]'",
",",
"[",
"$",
"StatistikQuery",
",",
"$",
"StatistikTemplate",
"]",
",",
"[",
"]",
")",
";",
"while",
"(",
"$",
"res",
"=",
"$",
"pages",
"->",
"getNext",
"(",
")",
")",
"{",
"$",
"pageID",
"=",
"$",
"res",
"[",
"0",
"]",
"->",
"getNextText",
"(",
"SMW_OUTPUT_WIKI",
")",
";",
"$",
"StatistikQuery",
"=",
"$",
"res",
"[",
"1",
"]",
"->",
"getNextText",
"(",
"SMW_OUTPUT_WIKI",
")",
";",
"$",
"StatistikTemplate",
"=",
"$",
"res",
"[",
"2",
"]",
"->",
"getNextText",
"(",
"SMW_OUTPUT_WIKI",
")",
";",
"$",
"mwTitle",
"=",
"\\",
"Title",
"::",
"newFromText",
"(",
"$",
"pageID",
")",
";",
"$",
"result",
"[",
"]",
"=",
"[",
"'title'",
"=>",
"$",
"mwTitle",
",",
"'statistikQuery'",
"=>",
"urldecode",
"(",
"$",
"StatistikQuery",
")",
",",
"'statistikTemplate'",
"=>",
"urldecode",
"(",
"$",
"StatistikTemplate",
")",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns array of statistic site with StatistikQuery, StatistikTemplate annotations
@return array of [ title, statistikQuery, statistikTemplate ] | [
"Returns",
"array",
"of",
"statistic",
"site",
"with",
"StatistikQuery",
"StatistikTemplate",
"annotations"
] | train | https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/maintenance/runStatistics.php#L49-L71 |
kkthek/diqa-util | maintenance/runStatistics.php | RunStatistics.doQuery | private function doQuery($query, $title) {
if (preg_match('/\{\{#ask:([^}]*)\}\}/', $query, $matches) == 1) {
$parts = explode("|", $matches[1]);
$query = array_shift($parts);
$params = [];
foreach($parts as $p) {
$keyValue = explode("=", $p);
$params[trim($keyValue[0])] = trim($keyValue[1]);
}
$out = QueryUtils::executeCountQuery ( $query, [], $params )->getCountValue();
} else {
// assume $query is wikitext
global $wgParser;
$popt = new ParserOptions();
$out = strip_tags($wgParser->parse( $query, $title, $popt )->getRawText());
}
return $out;
} | php | private function doQuery($query, $title) {
if (preg_match('/\{\{#ask:([^}]*)\}\}/', $query, $matches) == 1) {
$parts = explode("|", $matches[1]);
$query = array_shift($parts);
$params = [];
foreach($parts as $p) {
$keyValue = explode("=", $p);
$params[trim($keyValue[0])] = trim($keyValue[1]);
}
$out = QueryUtils::executeCountQuery ( $query, [], $params )->getCountValue();
} else {
// assume $query is wikitext
global $wgParser;
$popt = new ParserOptions();
$out = strip_tags($wgParser->parse( $query, $title, $popt )->getRawText());
}
return $out;
} | [
"private",
"function",
"doQuery",
"(",
"$",
"query",
",",
"$",
"title",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\{\\{#ask:([^}]*)\\}\\}/'",
",",
"$",
"query",
",",
"$",
"matches",
")",
"==",
"1",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"\"|\"",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"query",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"p",
")",
"{",
"$",
"keyValue",
"=",
"explode",
"(",
"\"=\"",
",",
"$",
"p",
")",
";",
"$",
"params",
"[",
"trim",
"(",
"$",
"keyValue",
"[",
"0",
"]",
")",
"]",
"=",
"trim",
"(",
"$",
"keyValue",
"[",
"1",
"]",
")",
";",
"}",
"$",
"out",
"=",
"QueryUtils",
"::",
"executeCountQuery",
"(",
"$",
"query",
",",
"[",
"]",
",",
"$",
"params",
")",
"->",
"getCountValue",
"(",
")",
";",
"}",
"else",
"{",
"// assume $query is wikitext",
"global",
"$",
"wgParser",
";",
"$",
"popt",
"=",
"new",
"ParserOptions",
"(",
")",
";",
"$",
"out",
"=",
"strip_tags",
"(",
"$",
"wgParser",
"->",
"parse",
"(",
"$",
"query",
",",
"$",
"title",
",",
"$",
"popt",
")",
"->",
"getRawText",
"(",
")",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Executes the statistic query. (count-Query!)
@param string $query
@return number | [
"Executes",
"the",
"statistic",
"query",
".",
"(",
"count",
"-",
"Query!",
")"
] | train | https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/maintenance/runStatistics.php#L78-L96 |
kkthek/diqa-util | maintenance/runStatistics.php | RunStatistics.appendToSite | private function appendToSite($mwTitle, $template, $value) {
$dateFormat = $this->getOption('dateformat', 'd.m.Y');
$template = str_replace('{{{now}}}', date($dateFormat), $template);
$template = str_replace('{{{value}}}', $value, $template);
$template = str_replace(["\n", "\r"], "", $template);
$this->logger->log("add statistic object: ".$template);
WikiUpdatorUtil::createOrAppendsToTitle($mwTitle, $template);
} | php | private function appendToSite($mwTitle, $template, $value) {
$dateFormat = $this->getOption('dateformat', 'd.m.Y');
$template = str_replace('{{{now}}}', date($dateFormat), $template);
$template = str_replace('{{{value}}}', $value, $template);
$template = str_replace(["\n", "\r"], "", $template);
$this->logger->log("add statistic object: ".$template);
WikiUpdatorUtil::createOrAppendsToTitle($mwTitle, $template);
} | [
"private",
"function",
"appendToSite",
"(",
"$",
"mwTitle",
",",
"$",
"template",
",",
"$",
"value",
")",
"{",
"$",
"dateFormat",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'dateformat'",
",",
"'d.m.Y'",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'{{{now}}}'",
",",
"date",
"(",
"$",
"dateFormat",
")",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'{{{value}}}'",
",",
"$",
"value",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"[",
"\"\\n\"",
",",
"\"\\r\"",
"]",
",",
"\"\"",
",",
"$",
"template",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"\"add statistic object: \"",
".",
"$",
"template",
")",
";",
"WikiUpdatorUtil",
"::",
"createOrAppendsToTitle",
"(",
"$",
"mwTitle",
",",
"$",
"template",
")",
";",
"}"
] | Append template (=subobject) to the page
@param Title $mwTitle
@param string $template
@param string $value | [
"Append",
"template",
"(",
"=",
"subobject",
")",
"to",
"the",
"page"
] | train | https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/maintenance/runStatistics.php#L104-L111 |
Stinger-Soft/MediaParsingBundle | Parser/ParserCompilerPass.php | ParserCompilerPass.process | public function process(ContainerBuilder $container){
if (!$container->hasDefinition(ParserChainInterface::SERVICE_ID)) {
return;
}
$definition = $container->getDefinition(ParserChainInterface::SERVICE_ID);
$taggedServices = $container->findTaggedServiceIds(MediaParserInterface::SERVICE_TAG);
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
$definition->addMethodCall(
'addParser',
array(new Reference($id))
);
}
}
} | php | public function process(ContainerBuilder $container){
if (!$container->hasDefinition(ParserChainInterface::SERVICE_ID)) {
return;
}
$definition = $container->getDefinition(ParserChainInterface::SERVICE_ID);
$taggedServices = $container->findTaggedServiceIds(MediaParserInterface::SERVICE_TAG);
foreach ($taggedServices as $id => $tagAttributes) {
foreach ($tagAttributes as $attributes) {
$definition->addMethodCall(
'addParser',
array(new Reference($id))
);
}
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"$",
"container",
"->",
"hasDefinition",
"(",
"ParserChainInterface",
"::",
"SERVICE_ID",
")",
")",
"{",
"return",
";",
"}",
"$",
"definition",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"ParserChainInterface",
"::",
"SERVICE_ID",
")",
";",
"$",
"taggedServices",
"=",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"MediaParserInterface",
"::",
"SERVICE_TAG",
")",
";",
"foreach",
"(",
"$",
"taggedServices",
"as",
"$",
"id",
"=>",
"$",
"tagAttributes",
")",
"{",
"foreach",
"(",
"$",
"tagAttributes",
"as",
"$",
"attributes",
")",
"{",
"$",
"definition",
"->",
"addMethodCall",
"(",
"'addParser'",
",",
"array",
"(",
"new",
"Reference",
"(",
"$",
"id",
")",
")",
")",
";",
"}",
"}",
"}"
] | Searches for all Audio Parsers that are tagged as 'stinger_soft.audioparser' inside all services.yml files
@see Symfony\Component\DependencyInjection\Compiler.CompilerPassInterface::process() | [
"Searches",
"for",
"all",
"Audio",
"Parsers",
"that",
"are",
"tagged",
"as",
"stinger_soft",
".",
"audioparser",
"inside",
"all",
"services",
".",
"yml",
"files"
] | train | https://github.com/Stinger-Soft/MediaParsingBundle/blob/6f68ddf75c1c4ef4da912643710abc824fd8d3e2/Parser/ParserCompilerPass.php#L24-L41 |
bseddon/XPath20 | Value/GMonthValue.php | GMonthValue.Equals | public function Equals( $obj )
{
if ( ! $obj instanceof GMonthValue )
{
return false;
}
/**
* @var DateTimeValueBase $other
*/
$other = $obj;
return $this->ToString( null ) == $other->ToString( null );
} | php | public function Equals( $obj )
{
if ( ! $obj instanceof GMonthValue )
{
return false;
}
/**
* @var DateTimeValueBase $other
*/
$other = $obj;
return $this->ToString( null ) == $other->ToString( null );
} | [
"public",
"function",
"Equals",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"$",
"obj",
"instanceof",
"GMonthValue",
")",
"{",
"return",
"false",
";",
"}",
"/**\r\n\t\t * @var DateTimeValueBase $other\r\n\t\t */",
"$",
"other",
"=",
"$",
"obj",
";",
"return",
"$",
"this",
"->",
"ToString",
"(",
"null",
")",
"==",
"$",
"other",
"->",
"ToString",
"(",
"null",
")",
";",
"}"
] | Equals
@param object $obj
@return bool | [
"Equals"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/GMonthValue.php#L81-L93 |
bseddon/XPath20 | Value/GMonthValue.php | GMonthValue.Parse | public static function Parse($text)
{
$text = strtoupper( trim( $text ) );
$result = preg_match( "/^--(?<month>\d{1,2})(?<offset>(?=[+\-a-zA-Z])(([+\-]\d{2}(:\d{2}))|Z|((\?!-|\\+)(?i)[^0-9].{3,})))?$/i", $text, $matches );
if ( ! $result )
{
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "xs:gYear" ) );
}
$error = empty( $matches['month'] ) || $matches['month'] > 12 || $matches['month'] < 1;
$offsetMatches = null;
if ( ! $error && ! empty( $matches['offset'] ) )
{
$error = $matches['offset'] != "Z" &&
! in_array( $matches['offset'], timezone_identifiers_list() ) &&
! preg_match( "/^[+-](?<hours>\d{2})(:(?<minutes>\d{2}))?$/", $matches['offset'], $offsetMatches );
if ( ! $error && ! is_null( $offsetMatches ) )
{
$error = empty( $offsetMatches['hours'] ) || $offsetMatches['hours'] > 14 ||
empty( $offsetMatches['minutes'] ) || $offsetMatches['minutes'] > 59;
}
}
if ( $error )
{
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "xs:gMonth" ) );
}
$dateTime = \DateTime::createFromFormat( "!--mO", $text );
if ( $dateTime )
return new GMonthValue( $dateTime );
$dateTime = \DateTime::createFromFormat( "!--m\Z", $text );
if ( $dateTime )
return new GMonthValue( $dateTime );
$dateTime = \DateTime::createFromFormat( "!--m", $text );
if ( $dateTime )
return new GMonthValue( $dateTime );
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::InvalidFormat, array( $text, "xs:gMonth" ) );
} | php | public static function Parse($text)
{
$text = strtoupper( trim( $text ) );
$result = preg_match( "/^--(?<month>\d{1,2})(?<offset>(?=[+\-a-zA-Z])(([+\-]\d{2}(:\d{2}))|Z|((\?!-|\\+)(?i)[^0-9].{3,})))?$/i", $text, $matches );
if ( ! $result )
{
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "xs:gYear" ) );
}
$error = empty( $matches['month'] ) || $matches['month'] > 12 || $matches['month'] < 1;
$offsetMatches = null;
if ( ! $error && ! empty( $matches['offset'] ) )
{
$error = $matches['offset'] != "Z" &&
! in_array( $matches['offset'], timezone_identifiers_list() ) &&
! preg_match( "/^[+-](?<hours>\d{2})(:(?<minutes>\d{2}))?$/", $matches['offset'], $offsetMatches );
if ( ! $error && ! is_null( $offsetMatches ) )
{
$error = empty( $offsetMatches['hours'] ) || $offsetMatches['hours'] > 14 ||
empty( $offsetMatches['minutes'] ) || $offsetMatches['minutes'] > 59;
}
}
if ( $error )
{
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "xs:gMonth" ) );
}
$dateTime = \DateTime::createFromFormat( "!--mO", $text );
if ( $dateTime )
return new GMonthValue( $dateTime );
$dateTime = \DateTime::createFromFormat( "!--m\Z", $text );
if ( $dateTime )
return new GMonthValue( $dateTime );
$dateTime = \DateTime::createFromFormat( "!--m", $text );
if ( $dateTime )
return new GMonthValue( $dateTime );
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::InvalidFormat, array( $text, "xs:gMonth" ) );
} | [
"public",
"static",
"function",
"Parse",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"strtoupper",
"(",
"trim",
"(",
"$",
"text",
")",
")",
";",
"$",
"result",
"=",
"preg_match",
"(",
"\"/^--(?<month>\\d{1,2})(?<offset>(?=[+\\-a-zA-Z])(([+\\-]\\d{2}(:\\d{2}))|Z|((\\?!-|\\\\+)(?i)[^0-9].{3,})))?$/i\"",
",",
"$",
"text",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"FORG0001\"",
",",
"Resources",
"::",
"FORG0001",
",",
"array",
"(",
"$",
"text",
",",
"\"xs:gYear\"",
")",
")",
";",
"}",
"$",
"error",
"=",
"empty",
"(",
"$",
"matches",
"[",
"'month'",
"]",
")",
"||",
"$",
"matches",
"[",
"'month'",
"]",
">",
"12",
"||",
"$",
"matches",
"[",
"'month'",
"]",
"<",
"1",
";",
"$",
"offsetMatches",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"error",
"&&",
"!",
"empty",
"(",
"$",
"matches",
"[",
"'offset'",
"]",
")",
")",
"{",
"$",
"error",
"=",
"$",
"matches",
"[",
"'offset'",
"]",
"!=",
"\"Z\"",
"&&",
"!",
"in_array",
"(",
"$",
"matches",
"[",
"'offset'",
"]",
",",
"timezone_identifiers_list",
"(",
")",
")",
"&&",
"!",
"preg_match",
"(",
"\"/^[+-](?<hours>\\d{2})(:(?<minutes>\\d{2}))?$/\"",
",",
"$",
"matches",
"[",
"'offset'",
"]",
",",
"$",
"offsetMatches",
")",
";",
"if",
"(",
"!",
"$",
"error",
"&&",
"!",
"is_null",
"(",
"$",
"offsetMatches",
")",
")",
"{",
"$",
"error",
"=",
"empty",
"(",
"$",
"offsetMatches",
"[",
"'hours'",
"]",
")",
"||",
"$",
"offsetMatches",
"[",
"'hours'",
"]",
">",
"14",
"||",
"empty",
"(",
"$",
"offsetMatches",
"[",
"'minutes'",
"]",
")",
"||",
"$",
"offsetMatches",
"[",
"'minutes'",
"]",
">",
"59",
";",
"}",
"}",
"if",
"(",
"$",
"error",
")",
"{",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"FORG0001\"",
",",
"Resources",
"::",
"FORG0001",
",",
"array",
"(",
"$",
"text",
",",
"\"xs:gMonth\"",
")",
")",
";",
"}",
"$",
"dateTime",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"\"!--mO\"",
",",
"$",
"text",
")",
";",
"if",
"(",
"$",
"dateTime",
")",
"return",
"new",
"GMonthValue",
"(",
"$",
"dateTime",
")",
";",
"$",
"dateTime",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"\"!--m\\Z\"",
",",
"$",
"text",
")",
";",
"if",
"(",
"$",
"dateTime",
")",
"return",
"new",
"GMonthValue",
"(",
"$",
"dateTime",
")",
";",
"$",
"dateTime",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"\"!--m\"",
",",
"$",
"text",
")",
";",
"if",
"(",
"$",
"dateTime",
")",
"return",
"new",
"GMonthValue",
"(",
"$",
"dateTime",
")",
";",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"FORG0001\"",
",",
"Resources",
"::",
"InvalidFormat",
",",
"array",
"(",
"$",
"text",
",",
"\"xs:gMonth\"",
")",
")",
";",
"}"
] | Parse
@param string $text
@return GMonthValue | [
"Parse"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/GMonthValue.php#L130-L174 |
GetOlympus/olympus-text-field | src/Text/Text.php | Text.setVars | protected function setVars()
{
$this->getModel()->setFaIcon('fa-text-width');
$this->getModel()->setStyle('css'.S.'text.css');
$this->getModel()->setTemplate('text.html.twig');
} | php | protected function setVars()
{
$this->getModel()->setFaIcon('fa-text-width');
$this->getModel()->setStyle('css'.S.'text.css');
$this->getModel()->setTemplate('text.html.twig');
} | [
"protected",
"function",
"setVars",
"(",
")",
"{",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"setFaIcon",
"(",
"'fa-text-width'",
")",
";",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"setStyle",
"(",
"'css'",
".",
"S",
".",
"'text.css'",
")",
";",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"setTemplate",
"(",
"'text.html.twig'",
")",
";",
"}"
] | Prepare variables. | [
"Prepare",
"variables",
"."
] | train | https://github.com/GetOlympus/olympus-text-field/blob/b25a0af8d3e678e2a722e43c25f334e80960a028/src/Text/Text.php#L25-L30 |
GetOlympus/olympus-text-field | src/Text/Text.php | Text.getVars | protected function getVars($content, $details = [])
{
// Build defaults
$defaults = [
'id' => '',
'title' => Translate::t('text.title', [], 'textfield'),
'default' => '',
'description' => '',
'options' => [
'type' => 'text',
'min' => '',
'max' => '',
'step' => '',
'class' => '',
'before' => '',
'after' => '',
],
// options
'attrs' => '',
'placeholder' => '',
'maxlength' => '',
];
// Build defaults data
$vars = array_merge($defaults, $content);
// Retrieve field value
$vars['val'] = $this->getValue($content['id'], $details, $vars['default']);
// Attributes
$vars['attrs'] = 'size="30"';
$vars['attrs'] .= !empty($vars['placeholder']) ? ' placeholder="'.$vars['placeholder'].'"' : '';
$vars['attrs'] .= !empty($vars['maxlength']) ? ' maxlength="'.$vars['maxlength'].'"' : '';
// Class
$vars['class'] = isset($vars['options']['class']) && !empty($vars['options']['class']) ? $vars['options']['class'] : '';
// Prepend & Append
$vars['before'] = isset($vars['options']['before']) && !empty($vars['options']['before']) ? $vars['options']['before'] : '';
$vars['after'] = isset($vars['options']['after']) && !empty($vars['options']['after']) ? $vars['options']['after'] : '';
// Check type
$type = isset($vars['options']['type']) && !empty($vars['options']['type']) ? $vars['options']['type'] : 'text';
$vars['type'] = $type;
// Check options
if ('number' === $type || 'range' === $type) {
// Special variables
$vars['attrs'] .= isset($vars['options']['min']) && !empty($vars['options']['min']) ? ' min="'.$vars['options']['min'].'"' : '';
$vars['attrs'] .= isset($vars['options']['max']) && !empty($vars['options']['max']) ? ' max="'.$vars['options']['max'].'"' : '';
$vars['attrs'] .= isset($vars['options']['step']) && !empty($vars['options']['step']) ? ' step="'.$vars['options']['step'].'"' : ' step="1"';
}
// Update vars
$this->getModel()->setVars($vars);
} | php | protected function getVars($content, $details = [])
{
// Build defaults
$defaults = [
'id' => '',
'title' => Translate::t('text.title', [], 'textfield'),
'default' => '',
'description' => '',
'options' => [
'type' => 'text',
'min' => '',
'max' => '',
'step' => '',
'class' => '',
'before' => '',
'after' => '',
],
// options
'attrs' => '',
'placeholder' => '',
'maxlength' => '',
];
// Build defaults data
$vars = array_merge($defaults, $content);
// Retrieve field value
$vars['val'] = $this->getValue($content['id'], $details, $vars['default']);
// Attributes
$vars['attrs'] = 'size="30"';
$vars['attrs'] .= !empty($vars['placeholder']) ? ' placeholder="'.$vars['placeholder'].'"' : '';
$vars['attrs'] .= !empty($vars['maxlength']) ? ' maxlength="'.$vars['maxlength'].'"' : '';
// Class
$vars['class'] = isset($vars['options']['class']) && !empty($vars['options']['class']) ? $vars['options']['class'] : '';
// Prepend & Append
$vars['before'] = isset($vars['options']['before']) && !empty($vars['options']['before']) ? $vars['options']['before'] : '';
$vars['after'] = isset($vars['options']['after']) && !empty($vars['options']['after']) ? $vars['options']['after'] : '';
// Check type
$type = isset($vars['options']['type']) && !empty($vars['options']['type']) ? $vars['options']['type'] : 'text';
$vars['type'] = $type;
// Check options
if ('number' === $type || 'range' === $type) {
// Special variables
$vars['attrs'] .= isset($vars['options']['min']) && !empty($vars['options']['min']) ? ' min="'.$vars['options']['min'].'"' : '';
$vars['attrs'] .= isset($vars['options']['max']) && !empty($vars['options']['max']) ? ' max="'.$vars['options']['max'].'"' : '';
$vars['attrs'] .= isset($vars['options']['step']) && !empty($vars['options']['step']) ? ' step="'.$vars['options']['step'].'"' : ' step="1"';
}
// Update vars
$this->getModel()->setVars($vars);
} | [
"protected",
"function",
"getVars",
"(",
"$",
"content",
",",
"$",
"details",
"=",
"[",
"]",
")",
"{",
"// Build defaults",
"$",
"defaults",
"=",
"[",
"'id'",
"=>",
"''",
",",
"'title'",
"=>",
"Translate",
"::",
"t",
"(",
"'text.title'",
",",
"[",
"]",
",",
"'textfield'",
")",
",",
"'default'",
"=>",
"''",
",",
"'description'",
"=>",
"''",
",",
"'options'",
"=>",
"[",
"'type'",
"=>",
"'text'",
",",
"'min'",
"=>",
"''",
",",
"'max'",
"=>",
"''",
",",
"'step'",
"=>",
"''",
",",
"'class'",
"=>",
"''",
",",
"'before'",
"=>",
"''",
",",
"'after'",
"=>",
"''",
",",
"]",
",",
"// options",
"'attrs'",
"=>",
"''",
",",
"'placeholder'",
"=>",
"''",
",",
"'maxlength'",
"=>",
"''",
",",
"]",
";",
"// Build defaults data",
"$",
"vars",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"content",
")",
";",
"// Retrieve field value",
"$",
"vars",
"[",
"'val'",
"]",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"content",
"[",
"'id'",
"]",
",",
"$",
"details",
",",
"$",
"vars",
"[",
"'default'",
"]",
")",
";",
"// Attributes",
"$",
"vars",
"[",
"'attrs'",
"]",
"=",
"'size=\"30\"'",
";",
"$",
"vars",
"[",
"'attrs'",
"]",
".=",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'placeholder'",
"]",
")",
"?",
"' placeholder=\"'",
".",
"$",
"vars",
"[",
"'placeholder'",
"]",
".",
"'\"'",
":",
"''",
";",
"$",
"vars",
"[",
"'attrs'",
"]",
".=",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'maxlength'",
"]",
")",
"?",
"' maxlength=\"'",
".",
"$",
"vars",
"[",
"'maxlength'",
"]",
".",
"'\"'",
":",
"''",
";",
"// Class",
"$",
"vars",
"[",
"'class'",
"]",
"=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'class'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'class'",
"]",
")",
"?",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'class'",
"]",
":",
"''",
";",
"// Prepend & Append",
"$",
"vars",
"[",
"'before'",
"]",
"=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'before'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'before'",
"]",
")",
"?",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'before'",
"]",
":",
"''",
";",
"$",
"vars",
"[",
"'after'",
"]",
"=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'after'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'after'",
"]",
")",
"?",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'after'",
"]",
":",
"''",
";",
"// Check type",
"$",
"type",
"=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'type'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'type'",
"]",
")",
"?",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'type'",
"]",
":",
"'text'",
";",
"$",
"vars",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"// Check options",
"if",
"(",
"'number'",
"===",
"$",
"type",
"||",
"'range'",
"===",
"$",
"type",
")",
"{",
"// Special variables",
"$",
"vars",
"[",
"'attrs'",
"]",
".=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'min'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'min'",
"]",
")",
"?",
"' min=\"'",
".",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'min'",
"]",
".",
"'\"'",
":",
"''",
";",
"$",
"vars",
"[",
"'attrs'",
"]",
".=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'max'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'max'",
"]",
")",
"?",
"' max=\"'",
".",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'max'",
"]",
".",
"'\"'",
":",
"''",
";",
"$",
"vars",
"[",
"'attrs'",
"]",
".=",
"isset",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'step'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'step'",
"]",
")",
"?",
"' step=\"'",
".",
"$",
"vars",
"[",
"'options'",
"]",
"[",
"'step'",
"]",
".",
"'\"'",
":",
"' step=\"1\"'",
";",
"}",
"// Update vars",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"setVars",
"(",
"$",
"vars",
")",
";",
"}"
] | Prepare HTML component.
@param array $content
@param array $details | [
"Prepare",
"HTML",
"component",
"."
] | train | https://github.com/GetOlympus/olympus-text-field/blob/b25a0af8d3e678e2a722e43c25f334e80960a028/src/Text/Text.php#L38-L94 |
sndsgd/http | src/http/request/Host.php | Host.getDnsName | public function getDnsName(): string
{
$host = $this->environment["HTTP_HOST"] ?? "";
$port = strpos($host, ":");
if ($port !== false) {
return substr($host, 0, $port);
}
return $host;
} | php | public function getDnsName(): string
{
$host = $this->environment["HTTP_HOST"] ?? "";
$port = strpos($host, ":");
if ($port !== false) {
return substr($host, 0, $port);
}
return $host;
} | [
"public",
"function",
"getDnsName",
"(",
")",
":",
"string",
"{",
"$",
"host",
"=",
"$",
"this",
"->",
"environment",
"[",
"\"HTTP_HOST\"",
"]",
"??",
"\"\"",
";",
"$",
"port",
"=",
"strpos",
"(",
"$",
"host",
",",
"\":\"",
")",
";",
"if",
"(",
"$",
"port",
"!==",
"false",
")",
"{",
"return",
"substr",
"(",
"$",
"host",
",",
"0",
",",
"$",
"port",
")",
";",
"}",
"return",
"$",
"host",
";",
"}"
] | Retrieve the name of the request host
@return string | [
"Retrieve",
"the",
"name",
"of",
"the",
"request",
"host"
] | train | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/request/Host.php#L45-L53 |
Topolis/Filter | src/Types/NumberFilter.php | NumberFilter.filter | public function filter($value) {
//Validate
if(!is_numeric($value) && $this->options["validate"]) {
return Filter::ERR_INVALID;
}
$value = (double)$value;
// Validate Values to Min/Max/Decimals
if( (!$this->options["adjust"] && $value < $this->options["min"]) ||
(!$this->options["adjust"] && $value > $this->options["max"]) ) {
return Filter::ERR_INVALID;
}
//Validate decimal count
if($this->options["decimals"] !== false && $this->options["round"] === false) {
$decimalcount = strpos($value,".") !== false ? strlen($value) - strpos($value,".") - 1 : 0;
if($decimalcount != $this->options["decimals"])
return Filter::ERR_INVALID;
}
// Adjust values to Min/Max
if($this->options["adjust"] && $this->options["min"] !== false) {
$value = max($this->options["min"], $value);
}
if($this->options["adjust"] && $this->options["max"] !== false) {
$value = min($this->options["max"], $value);
}
//Round/Floor if needed
if($this->options["decimals"] !== false && $this->options["round"] !== false) {
switch($this->options["round"]) {
case self::SI_NUMBER_CEIL: $value = ceil($value * pow(10,$this->options["decimals"])) / pow(10,$this->options["decimals"]); break;
case self::SI_NUMBER_FLOOR: $value = self::floor($value, $this->options["decimals"]); break;
case self::SI_NUMBER_ROUND: $value = round($value, $this->options["decimals"]); break;
}
}
return $value;
} | php | public function filter($value) {
//Validate
if(!is_numeric($value) && $this->options["validate"]) {
return Filter::ERR_INVALID;
}
$value = (double)$value;
// Validate Values to Min/Max/Decimals
if( (!$this->options["adjust"] && $value < $this->options["min"]) ||
(!$this->options["adjust"] && $value > $this->options["max"]) ) {
return Filter::ERR_INVALID;
}
//Validate decimal count
if($this->options["decimals"] !== false && $this->options["round"] === false) {
$decimalcount = strpos($value,".") !== false ? strlen($value) - strpos($value,".") - 1 : 0;
if($decimalcount != $this->options["decimals"])
return Filter::ERR_INVALID;
}
// Adjust values to Min/Max
if($this->options["adjust"] && $this->options["min"] !== false) {
$value = max($this->options["min"], $value);
}
if($this->options["adjust"] && $this->options["max"] !== false) {
$value = min($this->options["max"], $value);
}
//Round/Floor if needed
if($this->options["decimals"] !== false && $this->options["round"] !== false) {
switch($this->options["round"]) {
case self::SI_NUMBER_CEIL: $value = ceil($value * pow(10,$this->options["decimals"])) / pow(10,$this->options["decimals"]); break;
case self::SI_NUMBER_FLOOR: $value = self::floor($value, $this->options["decimals"]); break;
case self::SI_NUMBER_ROUND: $value = round($value, $this->options["decimals"]); break;
}
}
return $value;
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"//Validate",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"\"validate\"",
"]",
")",
"{",
"return",
"Filter",
"::",
"ERR_INVALID",
";",
"}",
"$",
"value",
"=",
"(",
"double",
")",
"$",
"value",
";",
"// Validate Values to Min/Max/Decimals",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"options",
"[",
"\"adjust\"",
"]",
"&&",
"$",
"value",
"<",
"$",
"this",
"->",
"options",
"[",
"\"min\"",
"]",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"options",
"[",
"\"adjust\"",
"]",
"&&",
"$",
"value",
">",
"$",
"this",
"->",
"options",
"[",
"\"max\"",
"]",
")",
")",
"{",
"return",
"Filter",
"::",
"ERR_INVALID",
";",
"}",
"//Validate decimal count",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
"!==",
"false",
"&&",
"$",
"this",
"->",
"options",
"[",
"\"round\"",
"]",
"===",
"false",
")",
"{",
"$",
"decimalcount",
"=",
"strpos",
"(",
"$",
"value",
",",
"\".\"",
")",
"!==",
"false",
"?",
"strlen",
"(",
"$",
"value",
")",
"-",
"strpos",
"(",
"$",
"value",
",",
"\".\"",
")",
"-",
"1",
":",
"0",
";",
"if",
"(",
"$",
"decimalcount",
"!=",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
")",
"return",
"Filter",
"::",
"ERR_INVALID",
";",
"}",
"// Adjust values to Min/Max",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"\"adjust\"",
"]",
"&&",
"$",
"this",
"->",
"options",
"[",
"\"min\"",
"]",
"!==",
"false",
")",
"{",
"$",
"value",
"=",
"max",
"(",
"$",
"this",
"->",
"options",
"[",
"\"min\"",
"]",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"\"adjust\"",
"]",
"&&",
"$",
"this",
"->",
"options",
"[",
"\"max\"",
"]",
"!==",
"false",
")",
"{",
"$",
"value",
"=",
"min",
"(",
"$",
"this",
"->",
"options",
"[",
"\"max\"",
"]",
",",
"$",
"value",
")",
";",
"}",
"//Round/Floor if needed",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
"!==",
"false",
"&&",
"$",
"this",
"->",
"options",
"[",
"\"round\"",
"]",
"!==",
"false",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"options",
"[",
"\"round\"",
"]",
")",
"{",
"case",
"self",
"::",
"SI_NUMBER_CEIL",
":",
"$",
"value",
"=",
"ceil",
"(",
"$",
"value",
"*",
"pow",
"(",
"10",
",",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
")",
")",
"/",
"pow",
"(",
"10",
",",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
")",
";",
"break",
";",
"case",
"self",
"::",
"SI_NUMBER_FLOOR",
":",
"$",
"value",
"=",
"self",
"::",
"floor",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
")",
";",
"break",
";",
"case",
"self",
"::",
"SI_NUMBER_ROUND",
":",
"$",
"value",
"=",
"round",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"options",
"[",
"\"decimals\"",
"]",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | execute the filter on a value
@param mixed $value
@return mixed | [
"execute",
"the",
"filter",
"on",
"a",
"value"
] | train | https://github.com/Topolis/Filter/blob/6208a6270490c39f028248dc99f21b3e816e388b/src/Types/NumberFilter.php#L68-L107 |
Topolis/Filter | src/Types/NumberFilter.php | NumberFilter.validate | public function validate($value) {
return (string)$value == (string)$this->filter($value) ? $value : Filter::ERR_INVALID;
} | php | public function validate($value) {
return (string)$value == (string)$this->filter($value) ? $value : Filter::ERR_INVALID;
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"string",
")",
"$",
"value",
"==",
"(",
"string",
")",
"$",
"this",
"->",
"filter",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"Filter",
"::",
"ERR_INVALID",
";",
"}"
] | execute the filter on a value
@param mixed $value
@return mixed | [
"execute",
"the",
"filter",
"on",
"a",
"value"
] | train | https://github.com/Topolis/Filter/blob/6208a6270490c39f028248dc99f21b3e816e388b/src/Types/NumberFilter.php#L114-L116 |
Topolis/Filter | src/Types/NumberFilter.php | NumberFilter.floor | static function floor($number, $prec = 0) {
$number = $number * pow(10,$prec);
$number = bcdiv($number, pow(10,$prec), $prec);
return $number;
} | php | static function floor($number, $prec = 0) {
$number = $number * pow(10,$prec);
$number = bcdiv($number, pow(10,$prec), $prec);
return $number;
} | [
"static",
"function",
"floor",
"(",
"$",
"number",
",",
"$",
"prec",
"=",
"0",
")",
"{",
"$",
"number",
"=",
"$",
"number",
"*",
"pow",
"(",
"10",
",",
"$",
"prec",
")",
";",
"$",
"number",
"=",
"bcdiv",
"(",
"$",
"number",
",",
"pow",
"(",
"10",
",",
"$",
"prec",
")",
",",
"$",
"prec",
")",
";",
"return",
"$",
"number",
";",
"}"
] | cut of (round down) decimals with optional precision.
Replacement for floor with higher precision to avoid round errors in standard floor
<code>
$x = Math::floor(123.2345344); // $x will be 123
$x = Math::floor(2823.787214, 2); // $x will be 2823.28
</code>
@param int|float $number input number
@param int $prec (Optional) number of decimals in result. Default: 0
@return int; | [
"cut",
"of",
"(",
"round",
"down",
")",
"decimals",
"with",
"optional",
"precision",
".",
"Replacement",
"for",
"floor",
"with",
"higher",
"precision",
"to",
"avoid",
"round",
"errors",
"in",
"standard",
"floor"
] | train | https://github.com/Topolis/Filter/blob/6208a6270490c39f028248dc99f21b3e816e388b/src/Types/NumberFilter.php#L131-L135 |
gplcart/cli | controllers/commands/Role.php | Role.cmdPermAddRole | public function cmdPermAddRole()
{
list($role_id, $existing, $submitted) = $this->getPermissionsRole();
$data = array('permissions' => array_unique(array_merge($existing, $submitted)));
$this->setSubmitted(null, $data);
$this->setSubmitted('update', $role_id);
$this->validateComponent('user_role');
$this->updateRole($role_id);
$this->output();
} | php | public function cmdPermAddRole()
{
list($role_id, $existing, $submitted) = $this->getPermissionsRole();
$data = array('permissions' => array_unique(array_merge($existing, $submitted)));
$this->setSubmitted(null, $data);
$this->setSubmitted('update', $role_id);
$this->validateComponent('user_role');
$this->updateRole($role_id);
$this->output();
} | [
"public",
"function",
"cmdPermAddRole",
"(",
")",
"{",
"list",
"(",
"$",
"role_id",
",",
"$",
"existing",
",",
"$",
"submitted",
")",
"=",
"$",
"this",
"->",
"getPermissionsRole",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
"'permissions'",
"=>",
"array_unique",
"(",
"array_merge",
"(",
"$",
"existing",
",",
"$",
"submitted",
")",
")",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"role_id",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'user_role'",
")",
";",
"$",
"this",
"->",
"updateRole",
"(",
"$",
"role_id",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "role-perm-add" command | [
"Callback",
"for",
"role",
"-",
"perm",
"-",
"add",
"command"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L40-L53 |
gplcart/cli | controllers/commands/Role.php | Role.cmdPermDeleteRole | public function cmdPermDeleteRole()
{
list($role_id, $existing, $submitted) = $this->getPermissionsRole();
$data = array(
'permissions' => array_unique(array_diff($existing, $submitted))
);
$this->setSubmitted(null, $data);
$this->setSubmitted('update', $role_id);
$this->validateComponent('user_role');
$this->updateRole($role_id);
$this->output();
} | php | public function cmdPermDeleteRole()
{
list($role_id, $existing, $submitted) = $this->getPermissionsRole();
$data = array(
'permissions' => array_unique(array_diff($existing, $submitted))
);
$this->setSubmitted(null, $data);
$this->setSubmitted('update', $role_id);
$this->validateComponent('user_role');
$this->updateRole($role_id);
$this->output();
} | [
"public",
"function",
"cmdPermDeleteRole",
"(",
")",
"{",
"list",
"(",
"$",
"role_id",
",",
"$",
"existing",
",",
"$",
"submitted",
")",
"=",
"$",
"this",
"->",
"getPermissionsRole",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
"'permissions'",
"=>",
"array_unique",
"(",
"array_diff",
"(",
"$",
"existing",
",",
"$",
"submitted",
")",
")",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"role_id",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'user_role'",
")",
";",
"$",
"this",
"->",
"updateRole",
"(",
"$",
"role_id",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "role-perm-delete" command | [
"Callback",
"for",
"role",
"-",
"perm",
"-",
"delete",
"command"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L58-L73 |
gplcart/cli | controllers/commands/Role.php | Role.cmdGetRole | public function cmdGetRole()
{
$result = $this->getListRole();
$this->outputFormat($result);
$this->outputFormatTableRole($result);
$this->output();
} | php | public function cmdGetRole()
{
$result = $this->getListRole();
$this->outputFormat($result);
$this->outputFormatTableRole($result);
$this->output();
} | [
"public",
"function",
"cmdGetRole",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListRole",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableRole",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "role-get" command | [
"Callback",
"for",
"role",
"-",
"get",
"command"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L78-L84 |
gplcart/cli | controllers/commands/Role.php | Role.cmdDeleteRole | public function cmdDeleteRole()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (!isset($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (isset($id)) {
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->role->delete($id);
} else if ($all) {
$deleted = $count = 0;
foreach ($this->role->getList() as $item) {
$count++;
$deleted += (int) $this->role->delete($item['role_id']);
}
$result = $count && $count == $deleted;
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdDeleteRole()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (!isset($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (isset($id)) {
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->role->delete($id);
} else if ($all) {
$deleted = $count = 0;
foreach ($this->role->getList() as $item) {
$count++;
$deleted += (int) $this->role->delete($item['role_id']);
}
$result = $count && $count == $deleted;
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdDeleteRole",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"id",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"role",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"$",
"all",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"role",
"->",
"getList",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"role",
"->",
"delete",
"(",
"$",
"item",
"[",
"'role_id'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"count",
"&&",
"$",
"count",
"==",
"$",
"deleted",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "role-delete" command | [
"Callback",
"for",
"role",
"-",
"delete",
"command"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L89-L124 |
gplcart/cli | controllers/commands/Role.php | Role.cmdUpdateRole | public function cmdUpdateRole()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmittedList('permissions');
$this->setSubmitted('update', $params[0]);
$this->validateComponent('user_role');
$this->updateRole($params[0]);
$this->output();
} | php | public function cmdUpdateRole()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmittedList('permissions');
$this->setSubmitted('update', $params[0]);
$this->validateComponent('user_role');
$this->updateRole($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateRole",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmittedList",
"(",
"'permissions'",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'user_role'",
")",
";",
"$",
"this",
"->",
"updateRole",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "role-update" command | [
"Callback",
"for",
"role",
"-",
"update",
"command"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L143-L163 |
gplcart/cli | controllers/commands/Role.php | Role.getListRole | protected function getListRole()
{
$id = $this->getParam(0);
if (!isset($id)) {
return $this->role->getList(array('limit' => $this->getLimit()));
}
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->role->get($id);
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
return array($result);
} | php | protected function getListRole()
{
$id = $this->getParam(0);
if (!isset($id)) {
return $this->role->getList(array('limit' => $this->getLimit()));
}
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->role->get($id);
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
return array($result);
} | [
"protected",
"function",
"getListRole",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"role",
"->",
"getList",
"(",
"array",
"(",
"'limit'",
"=>",
"$",
"this",
"->",
"getLimit",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"role",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"return",
"array",
"(",
"$",
"result",
")",
";",
"}"
] | Returns an array of user roles
@return array | [
"Returns",
"an",
"array",
"of",
"user",
"roles"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L169-L188 |
gplcart/cli | controllers/commands/Role.php | Role.outputFormatTableRole | protected function outputFormatTableRole(array $items)
{
$header = array(
$this->text('ID'),
$this->text('Name'),
$this->text('Redirect'),
$this->text('Permissions'),
$this->text('Enabled')
);
$rows = array();
foreach ($items as $item) {
$rows[] = array(
$item['role_id'],
$item['name'],
$item['redirect'],
count($item['permissions']),
empty($item['status']) ? $this->text('No') : $this->text('Yes')
);
}
$this->outputFormatTable($rows, $header);
} | php | protected function outputFormatTableRole(array $items)
{
$header = array(
$this->text('ID'),
$this->text('Name'),
$this->text('Redirect'),
$this->text('Permissions'),
$this->text('Enabled')
);
$rows = array();
foreach ($items as $item) {
$rows[] = array(
$item['role_id'],
$item['name'],
$item['redirect'],
count($item['permissions']),
empty($item['status']) ? $this->text('No') : $this->text('Yes')
);
}
$this->outputFormatTable($rows, $header);
} | [
"protected",
"function",
"outputFormatTableRole",
"(",
"array",
"$",
"items",
")",
"{",
"$",
"header",
"=",
"array",
"(",
"$",
"this",
"->",
"text",
"(",
"'ID'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Redirect'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Permissions'",
")",
",",
"$",
"this",
"->",
"text",
"(",
"'Enabled'",
")",
")",
";",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"array",
"(",
"$",
"item",
"[",
"'role_id'",
"]",
",",
"$",
"item",
"[",
"'name'",
"]",
",",
"$",
"item",
"[",
"'redirect'",
"]",
",",
"count",
"(",
"$",
"item",
"[",
"'permissions'",
"]",
")",
",",
"empty",
"(",
"$",
"item",
"[",
"'status'",
"]",
")",
"?",
"$",
"this",
"->",
"text",
"(",
"'No'",
")",
":",
"$",
"this",
"->",
"text",
"(",
"'Yes'",
")",
")",
";",
"}",
"$",
"this",
"->",
"outputFormatTable",
"(",
"$",
"rows",
",",
"$",
"header",
")",
";",
"}"
] | Output table format
@param array $items | [
"Output",
"table",
"format"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L194-L217 |
gplcart/cli | controllers/commands/Role.php | Role.getPermissionsRole | protected function getPermissionsRole()
{
$arguments = $this->getArguments();
if (count($arguments) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$role_id = array_shift($arguments);
if (!is_numeric($role_id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$role = $this->role->get($role_id);
if (!isset($role['permissions'])) {
$this->errorAndExit($this->text('Unexpected result'));
}
return array($role_id, $role['permissions'], $arguments);
} | php | protected function getPermissionsRole()
{
$arguments = $this->getArguments();
if (count($arguments) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
$role_id = array_shift($arguments);
if (!is_numeric($role_id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$role = $this->role->get($role_id);
if (!isset($role['permissions'])) {
$this->errorAndExit($this->text('Unexpected result'));
}
return array($role_id, $role['permissions'], $arguments);
} | [
"protected",
"function",
"getPermissionsRole",
"(",
")",
"{",
"$",
"arguments",
"=",
"$",
"this",
"->",
"getArguments",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"arguments",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"role_id",
"=",
"array_shift",
"(",
"$",
"arguments",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"role_id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"role",
"=",
"$",
"this",
"->",
"role",
"->",
"get",
"(",
"$",
"role_id",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"role",
"[",
"'permissions'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"return",
"array",
"(",
"$",
"role_id",
",",
"$",
"role",
"[",
"'permissions'",
"]",
",",
"$",
"arguments",
")",
";",
"}"
] | Returns an array containing parsed submitted data, such as:
role ID, the role permissions, submitted permissions
@return array | [
"Returns",
"an",
"array",
"containing",
"parsed",
"submitted",
"data",
"such",
"as",
":",
"role",
"ID",
"the",
"role",
"permissions",
"submitted",
"permissions"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L224-L245 |
gplcart/cli | controllers/commands/Role.php | Role.updateRole | protected function updateRole($role_id)
{
if (!$this->isError() && !$this->role->update($role_id, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | php | protected function updateRole($role_id)
{
if (!$this->isError() && !$this->role->update($role_id, $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
} | [
"protected",
"function",
"updateRole",
"(",
"$",
"role_id",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"role",
"->",
"update",
"(",
"$",
"role_id",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"}"
] | Updates a user role
@param string $role_id | [
"Updates",
"a",
"user",
"role"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L251-L256 |
gplcart/cli | controllers/commands/Role.php | Role.submitAddRole | protected function submitAddRole()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmittedList('permissions');
$this->validateComponent('user_role');
$this->addRole();
} | php | protected function submitAddRole()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmittedList('permissions');
$this->validateComponent('user_role');
$this->addRole();
} | [
"protected",
"function",
"submitAddRole",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSubmittedList",
"(",
"'permissions'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'user_role'",
")",
";",
"$",
"this",
"->",
"addRole",
"(",
")",
";",
"}"
] | Add a new user role at once | [
"Add",
"a",
"new",
"user",
"role",
"at",
"once"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L261-L267 |
gplcart/cli | controllers/commands/Role.php | Role.addRole | protected function addRole()
{
if (!$this->isError()) {
$id = $this->role->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | php | protected function addRole()
{
if (!$this->isError()) {
$id = $this->role->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | [
"protected",
"function",
"addRole",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"role",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Add a new user role | [
"Add",
"a",
"new",
"user",
"role"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L272-L281 |
gplcart/cli | controllers/commands/Role.php | Role.wizardAddRole | protected function wizardAddRole()
{
$this->validatePrompt('name', $this->text('Name'), 'user_role');
$this->validatePromptList('permissions', $this->text('Permissions'), 'user_role');
$this->validatePrompt('redirect', $this->text('Redirect'), 'user_role', '');
$this->validatePrompt('status', $this->text('Status'), 'user_role', 0);
$this->setSubmittedList('permissions');
$this->validateComponent('user_role');
$this->addRole();
} | php | protected function wizardAddRole()
{
$this->validatePrompt('name', $this->text('Name'), 'user_role');
$this->validatePromptList('permissions', $this->text('Permissions'), 'user_role');
$this->validatePrompt('redirect', $this->text('Redirect'), 'user_role', '');
$this->validatePrompt('status', $this->text('Status'), 'user_role', 0);
$this->setSubmittedList('permissions');
$this->validateComponent('user_role');
$this->addRole();
} | [
"protected",
"function",
"wizardAddRole",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"'user_role'",
")",
";",
"$",
"this",
"->",
"validatePromptList",
"(",
"'permissions'",
",",
"$",
"this",
"->",
"text",
"(",
"'Permissions'",
")",
",",
"'user_role'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'redirect'",
",",
"$",
"this",
"->",
"text",
"(",
"'Redirect'",
")",
",",
"'user_role'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'user_role'",
",",
"0",
")",
";",
"$",
"this",
"->",
"setSubmittedList",
"(",
"'permissions'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'user_role'",
")",
";",
"$",
"this",
"->",
"addRole",
"(",
")",
";",
"}"
] | Add a new user role step by step | [
"Add",
"a",
"new",
"user",
"role",
"step",
"by",
"step"
] | train | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Role.php#L286-L296 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.All | public function All( $Func )
{
$result = true;
$Func = new Expression( $Func );
foreach ( $this->repository as $item )
$result &= $Func->execute( $item );
return (boolean)$result;
} | php | public function All( $Func )
{
$result = true;
$Func = new Expression( $Func );
foreach ( $this->repository as $item )
$result &= $Func->execute( $item );
return (boolean)$result;
} | [
"public",
"function",
"All",
"(",
"$",
"Func",
")",
"{",
"$",
"result",
"=",
"true",
";",
"$",
"Func",
"=",
"new",
"Expression",
"(",
"$",
"Func",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"as",
"$",
"item",
")",
"$",
"result",
"&=",
"$",
"Func",
"->",
"execute",
"(",
"$",
"item",
")",
";",
"return",
"(",
"boolean",
")",
"$",
"result",
";",
"}"
] | Retreive all items with or without condition
@param string|Closure $Func
@return bool | [
"Retreive",
"all",
"items",
"with",
"or",
"without",
"condition"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L72-L84 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Where | public function Where( $Func )
{
if ( $Func != null ){
$repo = array();
$Func = new Expression( $Func );
foreach ( $this->repository as $item )
if ( $Func->execute( $item ) )
$repo[] = $item;
} else {
$repo = $this->repository;
}
return $this->getClone()->setRepository( $repo );
} | php | public function Where( $Func )
{
if ( $Func != null ){
$repo = array();
$Func = new Expression( $Func );
foreach ( $this->repository as $item )
if ( $Func->execute( $item ) )
$repo[] = $item;
} else {
$repo = $this->repository;
}
return $this->getClone()->setRepository( $repo );
} | [
"public",
"function",
"Where",
"(",
"$",
"Func",
")",
"{",
"if",
"(",
"$",
"Func",
"!=",
"null",
")",
"{",
"$",
"repo",
"=",
"array",
"(",
")",
";",
"$",
"Func",
"=",
"new",
"Expression",
"(",
"$",
"Func",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"as",
"$",
"item",
")",
"if",
"(",
"$",
"Func",
"->",
"execute",
"(",
"$",
"item",
")",
")",
"$",
"repo",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"else",
"{",
"$",
"repo",
"=",
"$",
"this",
"->",
"repository",
";",
"}",
"return",
"$",
"this",
"->",
"getClone",
"(",
")",
"->",
"setRepository",
"(",
"$",
"repo",
")",
";",
"}"
] | Filters a sequence of values based on a predicate.
@param string|Closure $Func
@return Queryable | [
"Filters",
"a",
"sequence",
"of",
"values",
"based",
"on",
"a",
"predicate",
"."
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L92-L113 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Any | public function Any( $Func )
{
$result = false;
$Func = new Expression( $Func );
foreach ( $this->repository as $item ) $result |= $Func->execute( $item );
return (boolean)$result;
} | php | public function Any( $Func )
{
$result = false;
$Func = new Expression( $Func );
foreach ( $this->repository as $item ) $result |= $Func->execute( $item );
return (boolean)$result;
} | [
"public",
"function",
"Any",
"(",
"$",
"Func",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"Func",
"=",
"new",
"Expression",
"(",
"$",
"Func",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"as",
"$",
"item",
")",
"$",
"result",
"|=",
"$",
"Func",
"->",
"execute",
"(",
"$",
"item",
")",
";",
"return",
"(",
"boolean",
")",
"$",
"result",
";",
"}"
] | Determines whether a sequence contains any elements.
@param string|Closure $Func
@return bool | [
"Determines",
"whether",
"a",
"sequence",
"contains",
"any",
"elements",
"."
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L121-L132 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Count | public function Count( $Func = null )
{
return $Func ? $this->Where( $Func )->Count() : count( $this->repository );
} | php | public function Count( $Func = null )
{
return $Func ? $this->Where( $Func )->Count() : count( $this->repository );
} | [
"public",
"function",
"Count",
"(",
"$",
"Func",
"=",
"null",
")",
"{",
"return",
"$",
"Func",
"?",
"$",
"this",
"->",
"Where",
"(",
"$",
"Func",
")",
"->",
"Count",
"(",
")",
":",
"count",
"(",
"$",
"this",
"->",
"repository",
")",
";",
"}"
] | Count repository with or without condition
@param string|Closure $Func
@return int | [
"Count",
"repository",
"with",
"or",
"without",
"condition"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L140-L145 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Average | public function Average( $Func = null )
{
$items = $this->Select( $Func );
$count = $items->Count();
$sum = 0;
foreach ( $items as $item ) $sum += $item;
return $sum / $count;
} | php | public function Average( $Func = null )
{
$items = $this->Select( $Func );
$count = $items->Count();
$sum = 0;
foreach ( $items as $item ) $sum += $item;
return $sum / $count;
} | [
"public",
"function",
"Average",
"(",
"$",
"Func",
"=",
"null",
")",
"{",
"$",
"items",
"=",
"$",
"this",
"->",
"Select",
"(",
"$",
"Func",
")",
";",
"$",
"count",
"=",
"$",
"items",
"->",
"Count",
"(",
")",
";",
"$",
"sum",
"=",
"0",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"$",
"sum",
"+=",
"$",
"item",
";",
"return",
"$",
"sum",
"/",
"$",
"count",
";",
"}"
] | Get Average of sequence
@param string|Closure $Func
@return double | [
"Get",
"Average",
"of",
"sequence"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L153-L166 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Sum | public function Sum( $Func = null )
{
$items = $this->Select( $Func );
$sum = 0;
foreach ( $items as $item ) $sum += $item;
return $sum;
} | php | public function Sum( $Func = null )
{
$items = $this->Select( $Func );
$sum = 0;
foreach ( $items as $item ) $sum += $item;
return $sum;
} | [
"public",
"function",
"Sum",
"(",
"$",
"Func",
"=",
"null",
")",
"{",
"$",
"items",
"=",
"$",
"this",
"->",
"Select",
"(",
"$",
"Func",
")",
";",
"$",
"sum",
"=",
"0",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"$",
"sum",
"+=",
"$",
"item",
";",
"return",
"$",
"sum",
";",
"}"
] | Get sum of sequence
@param string|Closure $Func
@return double | [
"Get",
"sum",
"of",
"sequence"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L174-L182 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Concat | public function Concat( $source )
{
$source = is_array($source) ? $source : ( $source instanceof Queryable ? $source->toList() : iterator_to_array($source) );
return $this
->getClone()
->setRepository( array_merge( $this->repository , $source ) );
} | php | public function Concat( $source )
{
$source = is_array($source) ? $source : ( $source instanceof Queryable ? $source->toList() : iterator_to_array($source) );
return $this
->getClone()
->setRepository( array_merge( $this->repository , $source ) );
} | [
"public",
"function",
"Concat",
"(",
"$",
"source",
")",
"{",
"$",
"source",
"=",
"is_array",
"(",
"$",
"source",
")",
"?",
"$",
"source",
":",
"(",
"$",
"source",
"instanceof",
"Queryable",
"?",
"$",
"source",
"->",
"toList",
"(",
")",
":",
"iterator_to_array",
"(",
"$",
"source",
")",
")",
";",
"return",
"$",
"this",
"->",
"getClone",
"(",
")",
"->",
"setRepository",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"repository",
",",
"$",
"source",
")",
")",
";",
"}"
] | Concatenates two sequences.
@param array|Queryable|Traversable $source
@return Queryable | [
"Concatenates",
"two",
"sequences",
"."
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L201-L210 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Except | public function Except( $items )
{
return $this
->getClone()
->setRepository( array_diff( $this->repository , $items instanceof Queryable ? $items->toArray() : $items ) );
} | php | public function Except( $items )
{
return $this
->getClone()
->setRepository( array_diff( $this->repository , $items instanceof Queryable ? $items->toArray() : $items ) );
} | [
"public",
"function",
"Except",
"(",
"$",
"items",
")",
"{",
"return",
"$",
"this",
"->",
"getClone",
"(",
")",
"->",
"setRepository",
"(",
"array_diff",
"(",
"$",
"this",
"->",
"repository",
",",
"$",
"items",
"instanceof",
"Queryable",
"?",
"$",
"items",
"->",
"toArray",
"(",
")",
":",
"$",
"items",
")",
")",
";",
"}"
] | Produces the set difference of two sequences by using the default equality comparer to compare values.
@param array|Queryable $items Items
@return Queryable | [
"Produces",
"the",
"set",
"difference",
"of",
"two",
"sequences",
"by",
"using",
"the",
"default",
"equality",
"comparer",
"to",
"compare",
"values",
"."
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L232-L239 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.First | public function First( $Func = null , $default = null )
{
$bag = $Func ? $this->Select($Func) : $this->repository;
return current($bag) ?: $default;
} | php | public function First( $Func = null , $default = null )
{
$bag = $Func ? $this->Select($Func) : $this->repository;
return current($bag) ?: $default;
} | [
"public",
"function",
"First",
"(",
"$",
"Func",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"bag",
"=",
"$",
"Func",
"?",
"$",
"this",
"->",
"Select",
"(",
"$",
"Func",
")",
":",
"$",
"this",
"->",
"repository",
";",
"return",
"current",
"(",
"$",
"bag",
")",
"?",
":",
"$",
"default",
";",
"}"
] | Get first element of sequence with or without condition
@param string|Closure $Func Condition
@param null $default
@return mixed
@internal param mixed $defaul Default | [
"Get",
"first",
"element",
"of",
"sequence",
"with",
"or",
"without",
"condition"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L249-L253 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Select | public function Select( $Func = null )
{
if ( $Func == null ) return $this;
$Func = new Expression( $Func );
$obj = $this->getClone();
foreach ( $obj->repository as &$item )
$item = $Func->execute( $item );
return $obj;
} | php | public function Select( $Func = null )
{
if ( $Func == null ) return $this;
$Func = new Expression( $Func );
$obj = $this->getClone();
foreach ( $obj->repository as &$item )
$item = $Func->execute( $item );
return $obj;
} | [
"public",
"function",
"Select",
"(",
"$",
"Func",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"Func",
"==",
"null",
")",
"return",
"$",
"this",
";",
"$",
"Func",
"=",
"new",
"Expression",
"(",
"$",
"Func",
")",
";",
"$",
"obj",
"=",
"$",
"this",
"->",
"getClone",
"(",
")",
";",
"foreach",
"(",
"$",
"obj",
"->",
"repository",
"as",
"&",
"$",
"item",
")",
"$",
"item",
"=",
"$",
"Func",
"->",
"execute",
"(",
"$",
"item",
")",
";",
"return",
"$",
"obj",
";",
"}"
] | Select
@param null|Closure $Func Selector
@return $this|Queryable | [
"Select"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L305-L319 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.SelectKeyValue | public function SelectKeyValue( $Key , $Value ) {
$Key = new Expression( $Key );
$Value = new Expression( $Value );
$items = array();
foreach ( $this->repository as $item ) {
$_k = $Key->execute( $item );
$_v = $Value->execute( $item );
$items[$_k] = $_v;
}
return new Queryable( $items );
} | php | public function SelectKeyValue( $Key , $Value ) {
$Key = new Expression( $Key );
$Value = new Expression( $Value );
$items = array();
foreach ( $this->repository as $item ) {
$_k = $Key->execute( $item );
$_v = $Value->execute( $item );
$items[$_k] = $_v;
}
return new Queryable( $items );
} | [
"public",
"function",
"SelectKeyValue",
"(",
"$",
"Key",
",",
"$",
"Value",
")",
"{",
"$",
"Key",
"=",
"new",
"Expression",
"(",
"$",
"Key",
")",
";",
"$",
"Value",
"=",
"new",
"Expression",
"(",
"$",
"Value",
")",
";",
"$",
"items",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"repository",
"as",
"$",
"item",
")",
"{",
"$",
"_k",
"=",
"$",
"Key",
"->",
"execute",
"(",
"$",
"item",
")",
";",
"$",
"_v",
"=",
"$",
"Value",
"->",
"execute",
"(",
"$",
"item",
")",
";",
"$",
"items",
"[",
"$",
"_k",
"]",
"=",
"$",
"_v",
";",
"}",
"return",
"new",
"Queryable",
"(",
"$",
"items",
")",
";",
"}"
] | Select key value
@param Closure $Key
@param Closure $Value
@return Queryable | [
"Select",
"key",
"value"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L328-L343 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Intersect | public function Intersect( $items )
{
return $this
->getClone()
->setRepository( array_intersect( $this->repository , $items instanceof Queryable ? $items->toArray() : $items ) );
} | php | public function Intersect( $items )
{
return $this
->getClone()
->setRepository( array_intersect( $this->repository , $items instanceof Queryable ? $items->toArray() : $items ) );
} | [
"public",
"function",
"Intersect",
"(",
"$",
"items",
")",
"{",
"return",
"$",
"this",
"->",
"getClone",
"(",
")",
"->",
"setRepository",
"(",
"array_intersect",
"(",
"$",
"this",
"->",
"repository",
",",
"$",
"items",
"instanceof",
"Queryable",
"?",
"$",
"items",
"->",
"toArray",
"(",
")",
":",
"$",
"items",
")",
")",
";",
"}"
] | Get Intersect of two sequence
@param array|Queryable $items
@return Queryable | [
"Get",
"Intersect",
"of",
"two",
"sequence"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L367-L374 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Cast | public function Cast( $type )
{
$obj = $this->getClone();
foreach ($obj->repository as &$value) {
settype($value, $type);
}
return $obj;
} | php | public function Cast( $type )
{
$obj = $this->getClone();
foreach ($obj->repository as &$value) {
settype($value, $type);
}
return $obj;
} | [
"public",
"function",
"Cast",
"(",
"$",
"type",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"getClone",
"(",
")",
";",
"foreach",
"(",
"$",
"obj",
"->",
"repository",
"as",
"&",
"$",
"value",
")",
"{",
"settype",
"(",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Casts the elements to the specified type.
@param string $type Type
@return Queryable | [
"Casts",
"the",
"elements",
"to",
"the",
"specified",
"type",
"."
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L382-L393 |
mdzzohrabi/Azera-Queryable | Queryable.php | Queryable.Sort | public function Sort( $Func = null )
{
$sorted = $this->repository;
$Func = new Expression( $Func );
usort( $sorted , [ $Func , 'execute' ] );
return $this
->getClone()
->setRepository( $sorted );
} | php | public function Sort( $Func = null )
{
$sorted = $this->repository;
$Func = new Expression( $Func );
usort( $sorted , [ $Func , 'execute' ] );
return $this
->getClone()
->setRepository( $sorted );
} | [
"public",
"function",
"Sort",
"(",
"$",
"Func",
"=",
"null",
")",
"{",
"$",
"sorted",
"=",
"$",
"this",
"->",
"repository",
";",
"$",
"Func",
"=",
"new",
"Expression",
"(",
"$",
"Func",
")",
";",
"usort",
"(",
"$",
"sorted",
",",
"[",
"$",
"Func",
",",
"'execute'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"getClone",
"(",
")",
"->",
"setRepository",
"(",
"$",
"sorted",
")",
";",
"}"
] | Sort sequence by given comparator
@param Expression $Func Comparator
@return Queryable | [
"Sort",
"sequence",
"by",
"given",
"comparator"
] | train | https://github.com/mdzzohrabi/Azera-Queryable/blob/6b85f335d33f8326c259e623b0c410396789f70b/Queryable.php#L553-L564 |
Dhii/config | src/TokenEndAwareTrait.php | TokenEndAwareTrait._setTokenEnd | public function _setTokenEnd($delimiter)
{
if (
!($delimiter instanceof Stringable) &&
!is_string($delimiter) &&
!is_null($delimiter)
) {
throw $this->_createInvalidArgumentException($this->__('Invalid token start delimiter'), null, null, $delimiter);
}
$this->tokenEnd = $delimiter;
} | php | public function _setTokenEnd($delimiter)
{
if (
!($delimiter instanceof Stringable) &&
!is_string($delimiter) &&
!is_null($delimiter)
) {
throw $this->_createInvalidArgumentException($this->__('Invalid token start delimiter'), null, null, $delimiter);
}
$this->tokenEnd = $delimiter;
} | [
"public",
"function",
"_setTokenEnd",
"(",
"$",
"delimiter",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"delimiter",
"instanceof",
"Stringable",
")",
"&&",
"!",
"is_string",
"(",
"$",
"delimiter",
")",
"&&",
"!",
"is_null",
"(",
"$",
"delimiter",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"_createInvalidArgumentException",
"(",
"$",
"this",
"->",
"__",
"(",
"'Invalid token start delimiter'",
")",
",",
"null",
",",
"null",
",",
"$",
"delimiter",
")",
";",
"}",
"$",
"this",
"->",
"tokenEnd",
"=",
"$",
"delimiter",
";",
"}"
] | Assigns the token end delimiter.
@since [*next-version*]
@param string|Stringable|null $delimiter The delimiter that marks the end of a token.
@throws InvalidArgumentException If the delimiter is invalid. | [
"Assigns",
"the",
"token",
"end",
"delimiter",
"."
] | train | https://github.com/Dhii/config/blob/1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf/src/TokenEndAwareTrait.php#L44-L55 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.compare | public static function compare($string, $value, $length = 0) {
$string = (string) $string;
$value = (string) $value;
if ($length > 0) {
return strncasecmp($string, $value, $length);
}
return strcasecmp($string, $value);
} | php | public static function compare($string, $value, $length = 0) {
$string = (string) $string;
$value = (string) $value;
if ($length > 0) {
return strncasecmp($string, $value, $length);
}
return strcasecmp($string, $value);
} | [
"public",
"static",
"function",
"compare",
"(",
"$",
"string",
",",
"$",
"value",
",",
"$",
"length",
"=",
"0",
")",
"{",
"$",
"string",
"=",
"(",
"string",
")",
"$",
"string",
";",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"$",
"length",
">",
"0",
")",
"{",
"return",
"strncasecmp",
"(",
"$",
"string",
",",
"$",
"value",
",",
"$",
"length",
")",
";",
"}",
"return",
"strcasecmp",
"(",
"$",
"string",
",",
"$",
"value",
")",
";",
"}"
] | Compares to strings alphabetically. Returns 0 if they are equal, negative if passed value is greater, or positive if current value is greater.
@param string $string
@param string $value
@param int $length
@return int | [
"Compares",
"to",
"strings",
"alphabetically",
".",
"Returns",
"0",
"if",
"they",
"are",
"equal",
"negative",
"if",
"passed",
"value",
"is",
"greater",
"or",
"positive",
"if",
"current",
"value",
"is",
"greater",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L49-L58 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.contains | public static function contains($string, $needle, $strict = true, $offset = 0) {
return (static::indexOf($string, $needle, $strict, $offset) !== false);
} | php | public static function contains($string, $needle, $strict = true, $offset = 0) {
return (static::indexOf($string, $needle, $strict, $offset) !== false);
} | [
"public",
"static",
"function",
"contains",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"strict",
"=",
"true",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"return",
"(",
"static",
"::",
"indexOf",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"strict",
",",
"$",
"offset",
")",
"!==",
"false",
")",
";",
"}"
] | Check to see if a string exists within this string.
@param string $string
@param string $needle
@param bool $strict
@param int $offset
@return bool | [
"Check",
"to",
"see",
"if",
"a",
"string",
"exists",
"within",
"this",
"string",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L69-L71 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.endsWith | public static function endsWith($string, $needle, $strict = true) {
$end = static::extract($string, -mb_strlen($needle));
if ($strict) {
return ($end === $needle);
}
return (mb_strtolower($end) === mb_strtolower($needle));
} | php | public static function endsWith($string, $needle, $strict = true) {
$end = static::extract($string, -mb_strlen($needle));
if ($strict) {
return ($end === $needle);
}
return (mb_strtolower($end) === mb_strtolower($needle));
} | [
"public",
"static",
"function",
"endsWith",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"strict",
"=",
"true",
")",
"{",
"$",
"end",
"=",
"static",
"::",
"extract",
"(",
"$",
"string",
",",
"-",
"mb_strlen",
"(",
"$",
"needle",
")",
")",
";",
"if",
"(",
"$",
"strict",
")",
"{",
"return",
"(",
"$",
"end",
"===",
"$",
"needle",
")",
";",
"}",
"return",
"(",
"mb_strtolower",
"(",
"$",
"end",
")",
"===",
"mb_strtolower",
"(",
"$",
"needle",
")",
")",
";",
"}"
] | Checks to see if the string ends with a specific value.
@param string $string
@param string $needle
@param bool $strict
@return bool | [
"Checks",
"to",
"see",
"if",
"the",
"string",
"ends",
"with",
"a",
"specific",
"value",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L81-L89 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.extract | public static function extract($string, $offset, $length = null) {
if ($length) {
return mb_substr($string, $offset, $length);
}
return mb_substr($string, $offset);
} | php | public static function extract($string, $offset, $length = null) {
if ($length) {
return mb_substr($string, $offset, $length);
}
return mb_substr($string, $offset);
} | [
"public",
"static",
"function",
"extract",
"(",
"$",
"string",
",",
"$",
"offset",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"length",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"$",
"offset",
",",
"$",
"length",
")",
";",
"}",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"$",
"offset",
")",
";",
"}"
] | Extracts a portion of a string.
@param string $string
@param int $offset
@param int $length
@return string | [
"Extracts",
"a",
"portion",
"of",
"a",
"string",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L99-L105 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.generate | public static function generate($length, $seed = self::ALNUM) {
$return = '';
$seed = (string) $seed;
$totalChars = mb_strlen($seed) - 1;
for ($i = 0; $i < $length; ++$i) {
$return .= $seed[rand(0, $totalChars)];
}
return $return;
} | php | public static function generate($length, $seed = self::ALNUM) {
$return = '';
$seed = (string) $seed;
$totalChars = mb_strlen($seed) - 1;
for ($i = 0; $i < $length; ++$i) {
$return .= $seed[rand(0, $totalChars)];
}
return $return;
} | [
"public",
"static",
"function",
"generate",
"(",
"$",
"length",
",",
"$",
"seed",
"=",
"self",
"::",
"ALNUM",
")",
"{",
"$",
"return",
"=",
"''",
";",
"$",
"seed",
"=",
"(",
"string",
")",
"$",
"seed",
";",
"$",
"totalChars",
"=",
"mb_strlen",
"(",
"$",
"seed",
")",
"-",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"return",
".=",
"$",
"seed",
"[",
"rand",
"(",
"0",
",",
"$",
"totalChars",
")",
"]",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Generates a string of random characters.
@param int $length
@param string $seed
@return string | [
"Generates",
"a",
"string",
"of",
"random",
"characters",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L114-L124 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.indexOf | public static function indexOf($string, $needle, $strict = true, $offset = 0) {
if ($strict) {
return mb_strpos($string, $needle, $offset);
}
return mb_stripos($string, $needle, $offset);
} | php | public static function indexOf($string, $needle, $strict = true, $offset = 0) {
if ($strict) {
return mb_strpos($string, $needle, $offset);
}
return mb_stripos($string, $needle, $offset);
} | [
"public",
"static",
"function",
"indexOf",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"strict",
"=",
"true",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"strict",
")",
"{",
"return",
"mb_strpos",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"offset",
")",
";",
"}",
"return",
"mb_stripos",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"offset",
")",
";",
"}"
] | Grab the index of the first matched character.
@param string $string
@param string $needle
@param bool $strict
@param int $offset
@return int | [
"Grab",
"the",
"index",
"of",
"the",
"first",
"matched",
"character",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L135-L141 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.insert | public static function insert($string, array $data, array $options = array()) {
$options = $options + array(
'before' => '{',
'after' => '}',
'escape' => true
);
foreach ($data as $key => $value) {
$string = str_replace($options['before'] . $key . $options['after'], $value, $string);
}
if ($options['escape']) {
$string = Sanitize::escape($string);
}
return $string;
} | php | public static function insert($string, array $data, array $options = array()) {
$options = $options + array(
'before' => '{',
'after' => '}',
'escape' => true
);
foreach ($data as $key => $value) {
$string = str_replace($options['before'] . $key . $options['after'], $value, $string);
}
if ($options['escape']) {
$string = Sanitize::escape($string);
}
return $string;
} | [
"public",
"static",
"function",
"insert",
"(",
"$",
"string",
",",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'before'",
"=>",
"'{'",
",",
"'after'",
"=>",
"'}'",
",",
"'escape'",
"=>",
"true",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"options",
"[",
"'before'",
"]",
".",
"$",
"key",
".",
"$",
"options",
"[",
"'after'",
"]",
",",
"$",
"value",
",",
"$",
"string",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'escape'",
"]",
")",
"{",
"$",
"string",
"=",
"Sanitize",
"::",
"escape",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Insert values into a string defined by an array of key tokens.
@uses Titon\Utility\Sanitize
@param string $string
@param array $data
@param array $options {
@type string $before Opening variable delimiter
@type string $after Closing variable delimiter
@type bool $escape Escape the string
}
@return string | [
"Insert",
"values",
"into",
"a",
"string",
"defined",
"by",
"an",
"array",
"of",
"key",
"tokens",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L157-L173 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.lastIndexOf | public static function lastIndexOf($string, $needle, $strict = true, $offset = 0) {
if ($strict) {
return mb_strrpos($string, $needle, $offset);
}
return mb_strripos($string, $needle, $offset);
} | php | public static function lastIndexOf($string, $needle, $strict = true, $offset = 0) {
if ($strict) {
return mb_strrpos($string, $needle, $offset);
}
return mb_strripos($string, $needle, $offset);
} | [
"public",
"static",
"function",
"lastIndexOf",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"strict",
"=",
"true",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"strict",
")",
"{",
"return",
"mb_strrpos",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"offset",
")",
";",
"}",
"return",
"mb_strripos",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"offset",
")",
";",
"}"
] | Grab the index of the last matched character.
@param string $string
@param string $needle
@param bool $strict
@param int $offset
@return int | [
"Grab",
"the",
"index",
"of",
"the",
"last",
"matched",
"character",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L184-L190 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.listing | public static function listing($items, $glue = ' & ', $sep = ', ') {
if (is_array($items)) {
$lastItem = array_pop($items);
if (count($items) === 0) {
return $lastItem;
}
$items = implode($sep, $items);
$items = $items . $glue . $lastItem;
}
return $items;
} | php | public static function listing($items, $glue = ' & ', $sep = ', ') {
if (is_array($items)) {
$lastItem = array_pop($items);
if (count($items) === 0) {
return $lastItem;
}
$items = implode($sep, $items);
$items = $items . $glue . $lastItem;
}
return $items;
} | [
"public",
"static",
"function",
"listing",
"(",
"$",
"items",
",",
"$",
"glue",
"=",
"' & '",
",",
"$",
"sep",
"=",
"', '",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"items",
")",
")",
"{",
"$",
"lastItem",
"=",
"array_pop",
"(",
"$",
"items",
")",
";",
"if",
"(",
"count",
"(",
"$",
"items",
")",
"===",
"0",
")",
"{",
"return",
"$",
"lastItem",
";",
"}",
"$",
"items",
"=",
"implode",
"(",
"$",
"sep",
",",
"$",
"items",
")",
";",
"$",
"items",
"=",
"$",
"items",
".",
"$",
"glue",
".",
"$",
"lastItem",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Creates a comma separated list with the last item having an ampersand prefixing it.
@param array $items
@param string $glue
@param string $sep
@return string | [
"Creates",
"a",
"comma",
"separated",
"list",
"with",
"the",
"last",
"item",
"having",
"an",
"ampersand",
"prefixing",
"it",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L200-L213 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.shorten | public static function shorten($string, $limit = 25, $glue = ' … ') {
if (mb_strlen($string) > $limit) {
$width = round($limit / 2);
// prefix
$pre = mb_substr($string, 0, $width);
if (mb_substr($pre, -1) !== ' ' && ($i = static::lastIndexOf($pre, ' '))) {
$pre = mb_substr($pre, 0, $i);
}
// suffix
$suf = mb_substr($string, -$width);
if (mb_substr($suf, 0, 1) !== ' ' && ($i = static::indexOf($suf, ' '))) {
$suf = mb_substr($suf, $i);
}
return trim($pre) . $glue . trim($suf);
}
return $string;
} | php | public static function shorten($string, $limit = 25, $glue = ' … ') {
if (mb_strlen($string) > $limit) {
$width = round($limit / 2);
// prefix
$pre = mb_substr($string, 0, $width);
if (mb_substr($pre, -1) !== ' ' && ($i = static::lastIndexOf($pre, ' '))) {
$pre = mb_substr($pre, 0, $i);
}
// suffix
$suf = mb_substr($string, -$width);
if (mb_substr($suf, 0, 1) !== ' ' && ($i = static::indexOf($suf, ' '))) {
$suf = mb_substr($suf, $i);
}
return trim($pre) . $glue . trim($suf);
}
return $string;
} | [
"public",
"static",
"function",
"shorten",
"(",
"$",
"string",
",",
"$",
"limit",
"=",
"25",
",",
"$",
"glue",
"=",
"' … '",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"string",
")",
">",
"$",
"limit",
")",
"{",
"$",
"width",
"=",
"round",
"(",
"$",
"limit",
"/",
"2",
")",
";",
"// prefix",
"$",
"pre",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"width",
")",
";",
"if",
"(",
"mb_substr",
"(",
"$",
"pre",
",",
"-",
"1",
")",
"!==",
"' '",
"&&",
"(",
"$",
"i",
"=",
"static",
"::",
"lastIndexOf",
"(",
"$",
"pre",
",",
"' '",
")",
")",
")",
"{",
"$",
"pre",
"=",
"mb_substr",
"(",
"$",
"pre",
",",
"0",
",",
"$",
"i",
")",
";",
"}",
"// suffix",
"$",
"suf",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"-",
"$",
"width",
")",
";",
"if",
"(",
"mb_substr",
"(",
"$",
"suf",
",",
"0",
",",
"1",
")",
"!==",
"' '",
"&&",
"(",
"$",
"i",
"=",
"static",
"::",
"indexOf",
"(",
"$",
"suf",
",",
"' '",
")",
")",
")",
"{",
"$",
"suf",
"=",
"mb_substr",
"(",
"$",
"suf",
",",
"$",
"i",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"pre",
")",
".",
"$",
"glue",
".",
"trim",
"(",
"$",
"suf",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | If a string is too long, shorten it in the middle while also respecting whitespace and preserving words.
@param string $string
@param int $limit
@param string $glue
@return string | [
"If",
"a",
"string",
"is",
"too",
"long",
"shorten",
"it",
"in",
"the",
"middle",
"while",
"also",
"respecting",
"whitespace",
"and",
"preserving",
"words",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L223-L245 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.startsWith | public static function startsWith($string, $needle, $strict = true) {
$start = static::extract($string, 0, mb_strlen($needle));
if ($strict) {
return ($start === $needle);
}
return (mb_strtolower($start) === mb_strtolower($needle));
} | php | public static function startsWith($string, $needle, $strict = true) {
$start = static::extract($string, 0, mb_strlen($needle));
if ($strict) {
return ($start === $needle);
}
return (mb_strtolower($start) === mb_strtolower($needle));
} | [
"public",
"static",
"function",
"startsWith",
"(",
"$",
"string",
",",
"$",
"needle",
",",
"$",
"strict",
"=",
"true",
")",
"{",
"$",
"start",
"=",
"static",
"::",
"extract",
"(",
"$",
"string",
",",
"0",
",",
"mb_strlen",
"(",
"$",
"needle",
")",
")",
";",
"if",
"(",
"$",
"strict",
")",
"{",
"return",
"(",
"$",
"start",
"===",
"$",
"needle",
")",
";",
"}",
"return",
"(",
"mb_strtolower",
"(",
"$",
"start",
")",
"===",
"mb_strtolower",
"(",
"$",
"needle",
")",
")",
";",
"}"
] | Checks to see if the string starts with a specific value.
@param string $string
@param string $needle
@param bool $strict
@return bool | [
"Checks",
"to",
"see",
"if",
"the",
"string",
"starts",
"with",
"a",
"specific",
"value",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L255-L263 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.truncate | public static function truncate($string, $limit = 25, array $options = array()) {
$options = $options + array(
'html' => true,
'word' => true,
'suffix' => '…',
'prefix' => '',
'open' => '<',
'close' => '>'
);
// If we should preserve HTML
if ($options['open'] !== '<' || $options['close'] !== '>') {
$options['html'] = false;
}
if (!$options['html']) {
$string = strip_tags($string);
}
// If string is shorten than limit
$length = mb_strlen($string);
if ($length <= $limit || !$limit) {
return $string;
}
// Generate tokens
$open = $options['open'];
$close = $options['close'];
$tokens = array();
$token = '';
$i = 0;
while ($i < $length) {
$char = $string[$i];
if ($char === $open || $char === '&') {
$tokens[] = $token;
$token = $char;
} else if ($char === $close || $char === ';') {
$tokens[] = $token . $char;
$token = '';
} else {
$token .= $char;
}
$i++;
}
$tokens[] = $token;
// Determine output
$current = 0;
$inHtml = false;
$htmlPattern = '/\\' . $open . '\/?(?:.*?)\\' . $close . '/iSu';
$entityPattern = '/&[a-z0-9]{2,8};|&#[0-9]{1,7};/iSu';
$output = '';
foreach ($tokens as $token) {
// Increase limit by 1 for tokens
if (preg_match($entityPattern, $token) && $current < $limit) {
$current++;
$output .= $token;
// Increase limit by 0 for HTML tags but check for tag boundaries
} else if (preg_match($htmlPattern, $token)) {
$inHtml = (mb_substr($token, 0, 2) !== $open . '/');
$output .= $token;
// Regular string
} else {
$length = mb_strlen($token);
if ($current >= $limit) {
// Do nothing, we reached the limit
} else if (($current + $length) >= $limit) {
$allowed = ($limit - $current);
$output .= mb_substr($token, 0, $allowed);
$current += $allowed;
} else {
$output .= $token;
$current += $length;
}
}
// We done?
if ($current >= $limit && !$inHtml) {
break;
}
}
// If we should preserve words
if ($options['word']) {
$lastChar = mb_substr($output, -1);
if ($lastChar !== ' ' && $lastChar !== $close && $lastChar !== ';') {
$output = mb_substr($string, 0, static::lastIndexOf($output, ' '));
}
}
return $options['prefix'] . trim($output) . $options['suffix'];
} | php | public static function truncate($string, $limit = 25, array $options = array()) {
$options = $options + array(
'html' => true,
'word' => true,
'suffix' => '…',
'prefix' => '',
'open' => '<',
'close' => '>'
);
// If we should preserve HTML
if ($options['open'] !== '<' || $options['close'] !== '>') {
$options['html'] = false;
}
if (!$options['html']) {
$string = strip_tags($string);
}
// If string is shorten than limit
$length = mb_strlen($string);
if ($length <= $limit || !$limit) {
return $string;
}
// Generate tokens
$open = $options['open'];
$close = $options['close'];
$tokens = array();
$token = '';
$i = 0;
while ($i < $length) {
$char = $string[$i];
if ($char === $open || $char === '&') {
$tokens[] = $token;
$token = $char;
} else if ($char === $close || $char === ';') {
$tokens[] = $token . $char;
$token = '';
} else {
$token .= $char;
}
$i++;
}
$tokens[] = $token;
// Determine output
$current = 0;
$inHtml = false;
$htmlPattern = '/\\' . $open . '\/?(?:.*?)\\' . $close . '/iSu';
$entityPattern = '/&[a-z0-9]{2,8};|&#[0-9]{1,7};/iSu';
$output = '';
foreach ($tokens as $token) {
// Increase limit by 1 for tokens
if (preg_match($entityPattern, $token) && $current < $limit) {
$current++;
$output .= $token;
// Increase limit by 0 for HTML tags but check for tag boundaries
} else if (preg_match($htmlPattern, $token)) {
$inHtml = (mb_substr($token, 0, 2) !== $open . '/');
$output .= $token;
// Regular string
} else {
$length = mb_strlen($token);
if ($current >= $limit) {
// Do nothing, we reached the limit
} else if (($current + $length) >= $limit) {
$allowed = ($limit - $current);
$output .= mb_substr($token, 0, $allowed);
$current += $allowed;
} else {
$output .= $token;
$current += $length;
}
}
// We done?
if ($current >= $limit && !$inHtml) {
break;
}
}
// If we should preserve words
if ($options['word']) {
$lastChar = mb_substr($output, -1);
if ($lastChar !== ' ' && $lastChar !== $close && $lastChar !== ';') {
$output = mb_substr($string, 0, static::lastIndexOf($output, ' '));
}
}
return $options['prefix'] . trim($output) . $options['suffix'];
} | [
"public",
"static",
"function",
"truncate",
"(",
"$",
"string",
",",
"$",
"limit",
"=",
"25",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"+",
"array",
"(",
"'html'",
"=>",
"true",
",",
"'word'",
"=>",
"true",
",",
"'suffix'",
"=>",
"'…'",
",",
"'prefix'",
"=>",
"''",
",",
"'open'",
"=>",
"'<'",
",",
"'close'",
"=>",
"'>'",
")",
";",
"// If we should preserve HTML",
"if",
"(",
"$",
"options",
"[",
"'open'",
"]",
"!==",
"'<'",
"||",
"$",
"options",
"[",
"'close'",
"]",
"!==",
"'>'",
")",
"{",
"$",
"options",
"[",
"'html'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"options",
"[",
"'html'",
"]",
")",
"{",
"$",
"string",
"=",
"strip_tags",
"(",
"$",
"string",
")",
";",
"}",
"// If string is shorten than limit",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"string",
")",
";",
"if",
"(",
"$",
"length",
"<=",
"$",
"limit",
"||",
"!",
"$",
"limit",
")",
"{",
"return",
"$",
"string",
";",
"}",
"// Generate tokens",
"$",
"open",
"=",
"$",
"options",
"[",
"'open'",
"]",
";",
"$",
"close",
"=",
"$",
"options",
"[",
"'close'",
"]",
";",
"$",
"tokens",
"=",
"array",
"(",
")",
";",
"$",
"token",
"=",
"''",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"length",
")",
"{",
"$",
"char",
"=",
"$",
"string",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"char",
"===",
"$",
"open",
"||",
"$",
"char",
"===",
"'&'",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"$",
"token",
"=",
"$",
"char",
";",
"}",
"else",
"if",
"(",
"$",
"char",
"===",
"$",
"close",
"||",
"$",
"char",
"===",
"';'",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"token",
".",
"$",
"char",
";",
"$",
"token",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"token",
".=",
"$",
"char",
";",
"}",
"$",
"i",
"++",
";",
"}",
"$",
"tokens",
"[",
"]",
"=",
"$",
"token",
";",
"// Determine output",
"$",
"current",
"=",
"0",
";",
"$",
"inHtml",
"=",
"false",
";",
"$",
"htmlPattern",
"=",
"'/\\\\'",
".",
"$",
"open",
".",
"'\\/?(?:.*?)\\\\'",
".",
"$",
"close",
".",
"'/iSu'",
";",
"$",
"entityPattern",
"=",
"'/&[a-z0-9]{2,8};|&#[0-9]{1,7};/iSu'",
";",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"token",
")",
"{",
"// Increase limit by 1 for tokens",
"if",
"(",
"preg_match",
"(",
"$",
"entityPattern",
",",
"$",
"token",
")",
"&&",
"$",
"current",
"<",
"$",
"limit",
")",
"{",
"$",
"current",
"++",
";",
"$",
"output",
".=",
"$",
"token",
";",
"// Increase limit by 0 for HTML tags but check for tag boundaries",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"$",
"htmlPattern",
",",
"$",
"token",
")",
")",
"{",
"$",
"inHtml",
"=",
"(",
"mb_substr",
"(",
"$",
"token",
",",
"0",
",",
"2",
")",
"!==",
"$",
"open",
".",
"'/'",
")",
";",
"$",
"output",
".=",
"$",
"token",
";",
"// Regular string",
"}",
"else",
"{",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"token",
")",
";",
"if",
"(",
"$",
"current",
">=",
"$",
"limit",
")",
"{",
"// Do nothing, we reached the limit",
"}",
"else",
"if",
"(",
"(",
"$",
"current",
"+",
"$",
"length",
")",
">=",
"$",
"limit",
")",
"{",
"$",
"allowed",
"=",
"(",
"$",
"limit",
"-",
"$",
"current",
")",
";",
"$",
"output",
".=",
"mb_substr",
"(",
"$",
"token",
",",
"0",
",",
"$",
"allowed",
")",
";",
"$",
"current",
"+=",
"$",
"allowed",
";",
"}",
"else",
"{",
"$",
"output",
".=",
"$",
"token",
";",
"$",
"current",
"+=",
"$",
"length",
";",
"}",
"}",
"// We done?",
"if",
"(",
"$",
"current",
">=",
"$",
"limit",
"&&",
"!",
"$",
"inHtml",
")",
"{",
"break",
";",
"}",
"}",
"// If we should preserve words",
"if",
"(",
"$",
"options",
"[",
"'word'",
"]",
")",
"{",
"$",
"lastChar",
"=",
"mb_substr",
"(",
"$",
"output",
",",
"-",
"1",
")",
";",
"if",
"(",
"$",
"lastChar",
"!==",
"' '",
"&&",
"$",
"lastChar",
"!==",
"$",
"close",
"&&",
"$",
"lastChar",
"!==",
"';'",
")",
"{",
"$",
"output",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"static",
"::",
"lastIndexOf",
"(",
"$",
"output",
",",
"' '",
")",
")",
";",
"}",
"}",
"return",
"$",
"options",
"[",
"'prefix'",
"]",
".",
"trim",
"(",
"$",
"output",
")",
".",
"$",
"options",
"[",
"'suffix'",
"]",
";",
"}"
] | Truncates a string to a certain length. Will preserve HTML tags and words if the flags are true.
@param string $string
@param int $limit
@param array $options {
@type bool $html True to preserve HTML tags
@type bool $word True to preserve trailing words
@type string $suffix Will be appended to the end of the output
@type string $prefix Will be appended to the beginning of the out output
@type string $open The opening tag (defaults to < HTML)
@type string $close The closing tag (defaults to > HTML)
}
@return string | [
"Truncates",
"a",
"string",
"to",
"a",
"certain",
"length",
".",
"Will",
"preserve",
"HTML",
"tags",
"and",
"words",
"if",
"the",
"flags",
"are",
"true",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L280-L385 |
vpg/titon.utility | src/Titon/Utility/Str.php | Str.uuid | public static function uuid() {
return sprintf('%s-%s-%s%s-%s%s-%s',
static::generate(8, Str::HEX), // 1
static::generate(4, Str::HEX), // 2
4, // 3
static::generate(3, Str::HEX), // 3
static::generate(1, '89AB'), // 4
static::generate(3, Str::HEX), // 4
static::generate(12, Str::HEX)); // 5
} | php | public static function uuid() {
return sprintf('%s-%s-%s%s-%s%s-%s',
static::generate(8, Str::HEX), // 1
static::generate(4, Str::HEX), // 2
4, // 3
static::generate(3, Str::HEX), // 3
static::generate(1, '89AB'), // 4
static::generate(3, Str::HEX), // 4
static::generate(12, Str::HEX)); // 5
} | [
"public",
"static",
"function",
"uuid",
"(",
")",
"{",
"return",
"sprintf",
"(",
"'%s-%s-%s%s-%s%s-%s'",
",",
"static",
"::",
"generate",
"(",
"8",
",",
"Str",
"::",
"HEX",
")",
",",
"// 1",
"static",
"::",
"generate",
"(",
"4",
",",
"Str",
"::",
"HEX",
")",
",",
"// 2",
"4",
",",
"// 3",
"static",
"::",
"generate",
"(",
"3",
",",
"Str",
"::",
"HEX",
")",
",",
"// 3",
"static",
"::",
"generate",
"(",
"1",
",",
"'89AB'",
")",
",",
"// 4",
"static",
"::",
"generate",
"(",
"3",
",",
"Str",
"::",
"HEX",
")",
",",
"// 4",
"static",
"::",
"generate",
"(",
"12",
",",
"Str",
"::",
"HEX",
")",
")",
";",
"// 5",
"}"
] | Creates UUID version 4: random number generation based.
@return string | [
"Creates",
"UUID",
"version",
"4",
":",
"random",
"number",
"generation",
"based",
"."
] | train | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Str.php#L392-L401 |
agentmedia/phine-core | src/Core/Logic/Module/BackendForm.php | BackendForm.AddRichTextField | protected function AddRichTextField($name, $value = '')
{
$renderer = new CKEditorRenderer(PathUtil::BackendRTEPath(), PathUtil::BackendRTEUrl(),
PathUtil::UploadPath(), PathUtil::UploadUrl(), self::Guard());
$field = new Custom($renderer);
$field->SetName($name);
$field->SetValue($value);
$this->AddField($field);
return $field;
} | php | protected function AddRichTextField($name, $value = '')
{
$renderer = new CKEditorRenderer(PathUtil::BackendRTEPath(), PathUtil::BackendRTEUrl(),
PathUtil::UploadPath(), PathUtil::UploadUrl(), self::Guard());
$field = new Custom($renderer);
$field->SetName($name);
$field->SetValue($value);
$this->AddField($field);
return $field;
} | [
"protected",
"function",
"AddRichTextField",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"''",
")",
"{",
"$",
"renderer",
"=",
"new",
"CKEditorRenderer",
"(",
"PathUtil",
"::",
"BackendRTEPath",
"(",
")",
",",
"PathUtil",
"::",
"BackendRTEUrl",
"(",
")",
",",
"PathUtil",
"::",
"UploadPath",
"(",
")",
",",
"PathUtil",
"::",
"UploadUrl",
"(",
")",
",",
"self",
"::",
"Guard",
"(",
")",
")",
";",
"$",
"field",
"=",
"new",
"Custom",
"(",
"$",
"renderer",
")",
";",
"$",
"field",
"->",
"SetName",
"(",
"$",
"name",
")",
";",
"$",
"field",
"->",
"SetValue",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"return",
"$",
"field",
";",
"}"
] | Adds a field with the default rich text editor
@param string $name The field name
@param string $value The field value
@return Custom Returns the custom field containing the RT Editor | [
"Adds",
"a",
"field",
"with",
"the",
"default",
"rich",
"text",
"editor"
] | train | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/BackendForm.php#L16-L25 |
freialib/hlin.archetype | src/Trait/Context.php | ContextTrait.addpath | function addpath($name, $fspath, $overwrite = false) {
if ( ! $overwrite && isset($this->registeredpaths[$name])) {
throw new Panic("A path is already registered for $name.");
}
else { // path is not registered yet or overwrite == true
$this->registeredpaths[$name] = $fspath;
}
} | php | function addpath($name, $fspath, $overwrite = false) {
if ( ! $overwrite && isset($this->registeredpaths[$name])) {
throw new Panic("A path is already registered for $name.");
}
else { // path is not registered yet or overwrite == true
$this->registeredpaths[$name] = $fspath;
}
} | [
"function",
"addpath",
"(",
"$",
"name",
",",
"$",
"fspath",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"overwrite",
"&&",
"isset",
"(",
"$",
"this",
"->",
"registeredpaths",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"Panic",
"(",
"\"A path is already registered for $name.\"",
")",
";",
"}",
"else",
"{",
"// path is not registered yet or overwrite == true",
"$",
"this",
"->",
"registeredpaths",
"[",
"$",
"name",
"]",
"=",
"$",
"fspath",
";",
"}",
"}"
] | Registers a path under a specified name.
If the path is already registered the method will Panic unless the 3rd
parameter is passed. | [
"Registers",
"a",
"path",
"under",
"a",
"specified",
"name",
"."
] | train | https://github.com/freialib/hlin.archetype/blob/d8750a9bf4b7efb8063899969e3f39c1915c423a/src/Trait/Context.php#L96-L103 |
freialib/hlin.archetype | src/Trait/Context.php | ContextTrait.path | function path($name, $null_on_failure = false) {
if ( ! isset($this->registeredpaths[$name])) {
if ($null_on_failure) {
return null;
}
else { // panic
throw new Panic("There is no path registered for $name.");
}
}
else { //
return $this->registeredpaths[$name];
}
} | php | function path($name, $null_on_failure = false) {
if ( ! isset($this->registeredpaths[$name])) {
if ($null_on_failure) {
return null;
}
else { // panic
throw new Panic("There is no path registered for $name.");
}
}
else { //
return $this->registeredpaths[$name];
}
} | [
"function",
"path",
"(",
"$",
"name",
",",
"$",
"null_on_failure",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"registeredpaths",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"$",
"null_on_failure",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"// panic",
"throw",
"new",
"Panic",
"(",
"\"There is no path registered for $name.\"",
")",
";",
"}",
"}",
"else",
"{",
"//",
"return",
"$",
"this",
"->",
"registeredpaths",
"[",
"$",
"name",
"]",
";",
"}",
"}"
] | Retrieves the specified path. If the path is not registered the method
will Panic, unless the second parameter is set, in which case it will
just return null.
@return string|null | [
"Retrieves",
"the",
"specified",
"path",
".",
"If",
"the",
"path",
"is",
"not",
"registered",
"the",
"method",
"will",
"Panic",
"unless",
"the",
"second",
"parameter",
"is",
"set",
"in",
"which",
"case",
"it",
"will",
"just",
"return",
"null",
"."
] | train | https://github.com/freialib/hlin.archetype/blob/d8750a9bf4b7efb8063899969e3f39c1915c423a/src/Trait/Context.php#L112-L124 |
TiMESPLiNTER/tsfw-db | lib/timesplinter/tsfw/db/DB.php | DB.execute | public function execute(\PDOStatement $stmnt)
{
try {
$old = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, 'us_US');
$stmnt->execute();
setlocale(LC_NUMERIC, $old);
$this->triggerListeners('onExecute', array($this, $stmnt));
} catch(\PDOException $e) {
throw new DBException($e->errorInfo[2], $e->errorInfo[1], $stmnt->queryString);
}
} | php | public function execute(\PDOStatement $stmnt)
{
try {
$old = setlocale(LC_NUMERIC, NULL);
setlocale(LC_NUMERIC, 'us_US');
$stmnt->execute();
setlocale(LC_NUMERIC, $old);
$this->triggerListeners('onExecute', array($this, $stmnt));
} catch(\PDOException $e) {
throw new DBException($e->errorInfo[2], $e->errorInfo[1], $stmnt->queryString);
}
} | [
"public",
"function",
"execute",
"(",
"\\",
"PDOStatement",
"$",
"stmnt",
")",
"{",
"try",
"{",
"$",
"old",
"=",
"setlocale",
"(",
"LC_NUMERIC",
",",
"NULL",
")",
";",
"setlocale",
"(",
"LC_NUMERIC",
",",
"'us_US'",
")",
";",
"$",
"stmnt",
"->",
"execute",
"(",
")",
";",
"setlocale",
"(",
"LC_NUMERIC",
",",
"$",
"old",
")",
";",
"$",
"this",
"->",
"triggerListeners",
"(",
"'onExecute'",
",",
"array",
"(",
"$",
"this",
",",
"$",
"stmnt",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"DBException",
"(",
"$",
"e",
"->",
"errorInfo",
"[",
"2",
"]",
",",
"$",
"e",
"->",
"errorInfo",
"[",
"1",
"]",
",",
"$",
"stmnt",
"->",
"queryString",
")",
";",
"}",
"}"
] | This method does the same as execute() of a PDOStatement but it fixes a
known issue of php that e.x. floats in some locale-settings contains a
comma instead of a point as decimal separator. It sets LC_NUMERIC to
us_US, executes the query and sets the LC_NUMERIC back to the old locale.
@param \PDOStatement $stmnt The statement to execute
@throws DBException | [
"This",
"method",
"does",
"the",
"same",
"as",
"execute",
"()",
"of",
"a",
"PDOStatement",
"but",
"it",
"fixes",
"a",
"known",
"issue",
"of",
"php",
"that",
"e",
".",
"x",
".",
"floats",
"in",
"some",
"locale",
"-",
"settings",
"contains",
"a",
"comma",
"instead",
"of",
"a",
"point",
"as",
"decimal",
"separator",
".",
"It",
"sets",
"LC_NUMERIC",
"to",
"us_US",
"executes",
"the",
"query",
"and",
"sets",
"the",
"LC_NUMERIC",
"back",
"to",
"the",
"old",
"locale",
"."
] | train | https://github.com/TiMESPLiNTER/tsfw-db/blob/d897d3d3a3d761a0f4fc9aa20426429d0aad1d92/lib/timesplinter/tsfw/db/DB.php#L82-L96 |
TiMESPLiNTER/tsfw-db | lib/timesplinter/tsfw/db/DB.php | DB.addListener | public function addListener(DBListener $listener, $name = null)
{
if($name !== null)
$this->listeners->offsetSet($name, $listener);
else
$this->listeners->append($listener);
} | php | public function addListener(DBListener $listener, $name = null)
{
if($name !== null)
$this->listeners->offsetSet($name, $listener);
else
$this->listeners->append($listener);
} | [
"public",
"function",
"addListener",
"(",
"DBListener",
"$",
"listener",
",",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"$",
"this",
"->",
"listeners",
"->",
"offsetSet",
"(",
"$",
"name",
",",
"$",
"listener",
")",
";",
"else",
"$",
"this",
"->",
"listeners",
"->",
"append",
"(",
"$",
"listener",
")",
";",
"}"
] | Adds a DBListener to listen on some events of the DB class
@param DBListener $listener The listener object to register
@param string $name The name of the listener [optional] | [
"Adds",
"a",
"DBListener",
"to",
"listen",
"on",
"some",
"events",
"of",
"the",
"DB",
"class"
] | train | https://github.com/TiMESPLiNTER/tsfw-db/blob/d897d3d3a3d761a0f4fc9aa20426429d0aad1d92/lib/timesplinter/tsfw/db/DB.php#L142-L148 |
TiMESPLiNTER/tsfw-db | lib/timesplinter/tsfw/db/DB.php | DB.triggerListeners | protected function triggerListeners($method, array $params = array())
{
if($this->muteListeners === true)
return;
// Mute all the listeners cause we don't want listeners called in listeners
// If we do so: unmute the listeners in the listener method itself
$this->muteListeners = true;
foreach($this->listeners as $l) {
/** @var DBListener $l */
call_user_func_array(array($l, $method), $params);
}
// Unmute listeners cause from now on we're not in a listener method anymore
$this->muteListeners = false;
} | php | protected function triggerListeners($method, array $params = array())
{
if($this->muteListeners === true)
return;
// Mute all the listeners cause we don't want listeners called in listeners
// If we do so: unmute the listeners in the listener method itself
$this->muteListeners = true;
foreach($this->listeners as $l) {
/** @var DBListener $l */
call_user_func_array(array($l, $method), $params);
}
// Unmute listeners cause from now on we're not in a listener method anymore
$this->muteListeners = false;
} | [
"protected",
"function",
"triggerListeners",
"(",
"$",
"method",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"muteListeners",
"===",
"true",
")",
"return",
";",
"// Mute all the listeners cause we don't want listeners called in listeners",
"// If we do so: unmute the listeners in the listener method itself",
"$",
"this",
"->",
"muteListeners",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"as",
"$",
"l",
")",
"{",
"/** @var DBListener $l */",
"call_user_func_array",
"(",
"array",
"(",
"$",
"l",
",",
"$",
"method",
")",
",",
"$",
"params",
")",
";",
"}",
"// Unmute listeners cause from now on we're not in a listener method anymore",
"$",
"this",
"->",
"muteListeners",
"=",
"false",
";",
"}"
] | Triggers a call of a specific method from all registered listener classes if the listeners are not set to mute
@param string $method The listener method that should be called
@param array $params The parameters for the listener method | [
"Triggers",
"a",
"call",
"of",
"a",
"specific",
"method",
"from",
"all",
"registered",
"listener",
"classes",
"if",
"the",
"listeners",
"are",
"not",
"set",
"to",
"mute"
] | train | https://github.com/TiMESPLiNTER/tsfw-db/blob/d897d3d3a3d761a0f4fc9aa20426429d0aad1d92/lib/timesplinter/tsfw/db/DB.php#L208-L224 |
Bistro/session | lib/Bistro/Session/MockArray.php | MockArray.getOnce | public function getOnce($key, $default = null)
{
$value = $this->get($key, $default);
$this->delete($key);
return $value;
} | php | public function getOnce($key, $default = null)
{
$value = $this->get($key, $default);
$this->delete($key);
return $value;
} | [
"public",
"function",
"getOnce",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"return",
"$",
"value",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/Bistro/session/blob/cebd8c77288458abde9ffdcd8efd69004a536a49/lib/Bistro/Session/MockArray.php#L63-L68 |
Bistro/session | lib/Bistro/Session/MockArray.php | MockArray.read | public function read(array $data = null)
{
if ($data === null)
{
$data = array();
}
$this->started = true;
$this->replace($data);
return $this;
} | php | public function read(array $data = null)
{
if ($data === null)
{
$data = array();
}
$this->started = true;
$this->replace($data);
return $this;
} | [
"public",
"function",
"read",
"(",
"array",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"started",
"=",
"true",
";",
"$",
"this",
"->",
"replace",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/Bistro/session/blob/cebd8c77288458abde9ffdcd8efd69004a536a49/lib/Bistro/Session/MockArray.php#L100-L111 |
cubicmushroom/valueobjects | src/Geography/CountryCodeName.php | CountryCodeName.getName | public static function getName(CountryCode $code)
{
$codeValue = $code->toNative();
$name = self::$names[$codeValue];
return new StringLiteral($name);
} | php | public static function getName(CountryCode $code)
{
$codeValue = $code->toNative();
$name = self::$names[$codeValue];
return new StringLiteral($name);
} | [
"public",
"static",
"function",
"getName",
"(",
"CountryCode",
"$",
"code",
")",
"{",
"$",
"codeValue",
"=",
"$",
"code",
"->",
"toNative",
"(",
")",
";",
"$",
"name",
"=",
"self",
"::",
"$",
"names",
"[",
"$",
"codeValue",
"]",
";",
"return",
"new",
"StringLiteral",
"(",
"$",
"name",
")",
";",
"}"
] | Returns country name
@param CountryCode $code
@return String | [
"Returns",
"country",
"name"
] | train | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/CountryCodeName.php#L262-L268 |
linpax/microphp-framework | src/queue/drivers/RabbitMQ.php | RabbitMQ.send | public function send($message, $route, $chat)
{
$exchange = new \AMQPExchange($this->channel);
$exchange->setName($chat);
return $exchange->publish($message, $route);
} | php | public function send($message, $route, $chat)
{
$exchange = new \AMQPExchange($this->channel);
$exchange->setName($chat);
return $exchange->publish($message, $route);
} | [
"public",
"function",
"send",
"(",
"$",
"message",
",",
"$",
"route",
",",
"$",
"chat",
")",
"{",
"$",
"exchange",
"=",
"new",
"\\",
"AMQPExchange",
"(",
"$",
"this",
"->",
"channel",
")",
";",
"$",
"exchange",
"->",
"setName",
"(",
"$",
"chat",
")",
";",
"return",
"$",
"exchange",
"->",
"publish",
"(",
"$",
"message",
",",
"$",
"route",
")",
";",
"}"
] | Send message
@access public
@param string $message message text
@param string $route name route
@param string $chat name chat room
@return bool
@throws \AMQPConnectionException
@throws \AMQPChannelException
@throws \AMQPExchangeException | [
"Send",
"message"
] | train | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/queue/drivers/RabbitMQ.php#L68-L74 |
linpax/microphp-framework | src/queue/drivers/RabbitMQ.php | RabbitMQ.read | public function read($chat, $route, $nameReader = 'random')
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($nameReader);
/** @noinspection PhpUndefinedMethodInspection */
$queue->declare();
$queue->bind($chat, $route);
$envelop = $queue->get();
if ($envelop) {
$queue->ack($envelop->getDeliveryTag());
return $envelop;
}
return false;
} | php | public function read($chat, $route, $nameReader = 'random')
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($nameReader);
/** @noinspection PhpUndefinedMethodInspection */
$queue->declare();
$queue->bind($chat, $route);
$envelop = $queue->get();
if ($envelop) {
$queue->ack($envelop->getDeliveryTag());
return $envelop;
}
return false;
} | [
"public",
"function",
"read",
"(",
"$",
"chat",
",",
"$",
"route",
",",
"$",
"nameReader",
"=",
"'random'",
")",
"{",
"$",
"queue",
"=",
"new",
"\\",
"AMQPQueue",
"(",
"$",
"this",
"->",
"channel",
")",
";",
"$",
"queue",
"->",
"setName",
"(",
"$",
"nameReader",
")",
";",
"/** @noinspection PhpUndefinedMethodInspection */",
"$",
"queue",
"->",
"declare",
"(",
")",
";",
"$",
"queue",
"->",
"bind",
"(",
"$",
"chat",
",",
"$",
"route",
")",
";",
"$",
"envelop",
"=",
"$",
"queue",
"->",
"get",
"(",
")",
";",
"if",
"(",
"$",
"envelop",
")",
"{",
"$",
"queue",
"->",
"ack",
"(",
"$",
"envelop",
"->",
"getDeliveryTag",
"(",
")",
")",
";",
"return",
"$",
"envelop",
";",
"}",
"return",
"false",
";",
"}"
] | Read current message
@access public
@param string $chat name chat room
@param string $route name route
@param string $nameReader name queue
@return \AMQPEnvelope|bool
@throws \AMQPConnectionException
@throws \AMQPChannelException
@throws \AMQPQueueException | [
"Read",
"current",
"message"
] | train | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/queue/drivers/RabbitMQ.php#L90-L106 |
linpax/microphp-framework | src/queue/drivers/RabbitMQ.php | RabbitMQ.readAll | public function readAll($chat, $route, $nameReader)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($nameReader);
/** @noinspection PhpUndefinedMethodInspection */
$queue->declare();
$queue->bind($chat, $route);
$result = [];
while ($envelop = $queue->get()) {
$queue->ack($envelop->getDeliveryTag());
$result[] = $envelop;
}
return $result;
} | php | public function readAll($chat, $route, $nameReader)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($nameReader);
/** @noinspection PhpUndefinedMethodInspection */
$queue->declare();
$queue->bind($chat, $route);
$result = [];
while ($envelop = $queue->get()) {
$queue->ack($envelop->getDeliveryTag());
$result[] = $envelop;
}
return $result;
} | [
"public",
"function",
"readAll",
"(",
"$",
"chat",
",",
"$",
"route",
",",
"$",
"nameReader",
")",
"{",
"$",
"queue",
"=",
"new",
"\\",
"AMQPQueue",
"(",
"$",
"this",
"->",
"channel",
")",
";",
"$",
"queue",
"->",
"setName",
"(",
"$",
"nameReader",
")",
";",
"/** @noinspection PhpUndefinedMethodInspection */",
"$",
"queue",
"->",
"declare",
"(",
")",
";",
"$",
"queue",
"->",
"bind",
"(",
"$",
"chat",
",",
"$",
"route",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"envelop",
"=",
"$",
"queue",
"->",
"get",
"(",
")",
")",
"{",
"$",
"queue",
"->",
"ack",
"(",
"$",
"envelop",
"->",
"getDeliveryTag",
"(",
")",
")",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"envelop",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Read all messages
@access public
@param string $chat name chat room
@param string $route name route
@param string $nameReader name queue
@return array
@throws \AMQPConnectionException
@throws \AMQPQueueException
@throws \AMQPChannelException | [
"Read",
"all",
"messages"
] | train | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/queue/drivers/RabbitMQ.php#L122-L137 |
Eden-PHP/Timezone | src/Index.php | Index.convertTo | public function convertTo($zone, $format = null)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 1 must be a timezone identifier
->test(1, 'location', 'utc', 'abbr')
//argument 2 must be a string or null
->test(2, 'string', 'null');
$time = $this->time + $this->calculateOffset($zone);
if (!is_null($format)) {
return date($format, $time);
}
return $time;
} | php | public function convertTo($zone, $format = null)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 1 must be a timezone identifier
->test(1, 'location', 'utc', 'abbr')
//argument 2 must be a string or null
->test(2, 'string', 'null');
$time = $this->time + $this->calculateOffset($zone);
if (!is_null($format)) {
return date($format, $time);
}
return $time;
} | [
"public",
"function",
"convertTo",
"(",
"$",
"zone",
",",
"$",
"format",
"=",
"null",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"//argument 1 must be a string",
"->",
"test",
"(",
"1",
",",
"'string'",
")",
"//argument 1 must be a timezone identifier",
"->",
"test",
"(",
"1",
",",
"'location'",
",",
"'utc'",
",",
"'abbr'",
")",
"//argument 2 must be a string or null",
"->",
"test",
"(",
"2",
",",
"'string'",
",",
"'null'",
")",
";",
"$",
"time",
"=",
"$",
"this",
"->",
"time",
"+",
"$",
"this",
"->",
"calculateOffset",
"(",
"$",
"zone",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"format",
")",
")",
"{",
"return",
"date",
"(",
"$",
"format",
",",
"$",
"time",
")",
";",
"}",
"return",
"$",
"time",
";",
"}"
] | Convert current time set here to another time zone
@param *string $zone valid UTC, GMT, PHP Location or TZ Abbreviation
@param string|null $format format
@return string|int | [
"Convert",
"current",
"time",
"set",
"here",
"to",
"another",
"time",
"zone"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L76-L93 |
Eden-PHP/Timezone | src/Index.php | Index.getGMT | public function getGMT($prefix = self::GMT)
{
//argument must be a string
Argument::i()->test(1, 'string');
list($hour, $minute, $sign) = $this->getUtcParts($this->offset);
return $prefix.$sign.$hour.$minute;
} | php | public function getGMT($prefix = self::GMT)
{
//argument must be a string
Argument::i()->test(1, 'string');
list($hour, $minute, $sign) = $this->getUtcParts($this->offset);
return $prefix.$sign.$hour.$minute;
} | [
"public",
"function",
"getGMT",
"(",
"$",
"prefix",
"=",
"self",
"::",
"GMT",
")",
"{",
"//argument must be a string",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"1",
",",
"'string'",
")",
";",
"list",
"(",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"sign",
")",
"=",
"$",
"this",
"->",
"getUtcParts",
"(",
"$",
"this",
"->",
"offset",
")",
";",
"return",
"$",
"prefix",
".",
"$",
"sign",
".",
"$",
"hour",
".",
"$",
"minute",
";",
"}"
] | Returns the GMT Format
@param string $prefix Prefix to add before the returned value
@return string | [
"Returns",
"the",
"GMT",
"Format"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L102-L109 |
Eden-PHP/Timezone | src/Index.php | Index.getGMTDates | public function getGMTDates($format, $interval = 30, $prefix = self::GMT)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 2 must be an integer
->test(2, 'int')
//argument 3 must be a string or null
->test(3, 'string', 'null');
$offsets = $this->getOffsetDates($format, $interval);
$dates = array();
foreach ($offsets as $offset => $date) {
list($hour, $minute, $sign) = $this->getUtcParts($offset);
$gmt = $prefix.$sign.$hour.$minute;
$dates[$gmt] = $date;
}
return $dates;
} | php | public function getGMTDates($format, $interval = 30, $prefix = self::GMT)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 2 must be an integer
->test(2, 'int')
//argument 3 must be a string or null
->test(3, 'string', 'null');
$offsets = $this->getOffsetDates($format, $interval);
$dates = array();
foreach ($offsets as $offset => $date) {
list($hour, $minute, $sign) = $this->getUtcParts($offset);
$gmt = $prefix.$sign.$hour.$minute;
$dates[$gmt] = $date;
}
return $dates;
} | [
"public",
"function",
"getGMTDates",
"(",
"$",
"format",
",",
"$",
"interval",
"=",
"30",
",",
"$",
"prefix",
"=",
"self",
"::",
"GMT",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"//argument 1 must be a string",
"->",
"test",
"(",
"1",
",",
"'string'",
")",
"//argument 2 must be an integer",
"->",
"test",
"(",
"2",
",",
"'int'",
")",
"//argument 3 must be a string or null",
"->",
"test",
"(",
"3",
",",
"'string'",
",",
"'null'",
")",
";",
"$",
"offsets",
"=",
"$",
"this",
"->",
"getOffsetDates",
"(",
"$",
"format",
",",
"$",
"interval",
")",
";",
"$",
"dates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"offsets",
"as",
"$",
"offset",
"=>",
"$",
"date",
")",
"{",
"list",
"(",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"sign",
")",
"=",
"$",
"this",
"->",
"getUtcParts",
"(",
"$",
"offset",
")",
";",
"$",
"gmt",
"=",
"$",
"prefix",
".",
"$",
"sign",
".",
"$",
"hour",
".",
"$",
"minute",
";",
"$",
"dates",
"[",
"$",
"gmt",
"]",
"=",
"$",
"date",
";",
"}",
"return",
"$",
"dates",
";",
"}"
] | Returns a list of GMT formats and dates in a 24 hour period
@param *string $format The format of each date to display
@param int $interval The frequency of rows
@param string|null $prefix The prefix to add before each date display
@return array | [
"Returns",
"a",
"list",
"of",
"GMT",
"formats",
"and",
"dates",
"in",
"a",
"24",
"hour",
"period"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L120-L140 |
Eden-PHP/Timezone | src/Index.php | Index.getOffsetDates | public function getOffsetDates($format, $interval = 30)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 2 must be an integer
->test(2, 'int');
$dates = array();
$interval *= 60;
for ($i=-12*3600; $i <= (12*3600); $i+=$interval) {
$time = $this->time + $i;
$dates[$i] = date($format, $time);
}
return $dates;
} | php | public function getOffsetDates($format, $interval = 30)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 2 must be an integer
->test(2, 'int');
$dates = array();
$interval *= 60;
for ($i=-12*3600; $i <= (12*3600); $i+=$interval) {
$time = $this->time + $i;
$dates[$i] = date($format, $time);
}
return $dates;
} | [
"public",
"function",
"getOffsetDates",
"(",
"$",
"format",
",",
"$",
"interval",
"=",
"30",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"//argument 1 must be a string",
"->",
"test",
"(",
"1",
",",
"'string'",
")",
"//argument 2 must be an integer",
"->",
"test",
"(",
"2",
",",
"'int'",
")",
";",
"$",
"dates",
"=",
"array",
"(",
")",
";",
"$",
"interval",
"*=",
"60",
";",
"for",
"(",
"$",
"i",
"=",
"-",
"12",
"*",
"3600",
";",
"$",
"i",
"<=",
"(",
"12",
"*",
"3600",
")",
";",
"$",
"i",
"+=",
"$",
"interval",
")",
"{",
"$",
"time",
"=",
"$",
"this",
"->",
"time",
"+",
"$",
"i",
";",
"$",
"dates",
"[",
"$",
"i",
"]",
"=",
"date",
"(",
"$",
"format",
",",
"$",
"time",
")",
";",
"}",
"return",
"$",
"dates",
";",
"}"
] | Returns a list of offsets and dates in a 24 hour period
@param *string $format The format of each date to display
@param int $interval The frequency of rows
@return array | [
"Returns",
"a",
"list",
"of",
"offsets",
"and",
"dates",
"in",
"a",
"24",
"hour",
"period"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L160-L177 |
Eden-PHP/Timezone | src/Index.php | Index.getTime | public function getTime($format = null)
{
//argument 1 must be a string or null
Argument::i()->test(1, 'string', 'null');
$time = $this->time + $this->offset;
if (!is_null($format)) {
return date($format, $time);
}
return $time;
} | php | public function getTime($format = null)
{
//argument 1 must be a string or null
Argument::i()->test(1, 'string', 'null');
$time = $this->time + $this->offset;
if (!is_null($format)) {
return date($format, $time);
}
return $time;
} | [
"public",
"function",
"getTime",
"(",
"$",
"format",
"=",
"null",
")",
"{",
"//argument 1 must be a string or null",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"1",
",",
"'string'",
",",
"'null'",
")",
";",
"$",
"time",
"=",
"$",
"this",
"->",
"time",
"+",
"$",
"this",
"->",
"offset",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"format",
")",
")",
"{",
"return",
"date",
"(",
"$",
"format",
",",
"$",
"time",
")",
";",
"}",
"return",
"$",
"time",
";",
"}"
] | Returns the time or date
@param string|null $format Time format
@return string|int | [
"Returns",
"the",
"time",
"or",
"date"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L186-L198 |
Eden-PHP/Timezone | src/Index.php | Index.getUTC | public function getUTC($prefix = self::UTC)
{
//argument 1 must be a string
Argument::i()->test(1, 'string');
list($hour, $minute, $sign) = $this->getUtcParts($this->offset);
return $prefix.$sign.$hour.':'.$minute;
} | php | public function getUTC($prefix = self::UTC)
{
//argument 1 must be a string
Argument::i()->test(1, 'string');
list($hour, $minute, $sign) = $this->getUtcParts($this->offset);
return $prefix.$sign.$hour.':'.$minute;
} | [
"public",
"function",
"getUTC",
"(",
"$",
"prefix",
"=",
"self",
"::",
"UTC",
")",
"{",
"//argument 1 must be a string",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"1",
",",
"'string'",
")",
";",
"list",
"(",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"sign",
")",
"=",
"$",
"this",
"->",
"getUtcParts",
"(",
"$",
"this",
"->",
"offset",
")",
";",
"return",
"$",
"prefix",
".",
"$",
"sign",
".",
"$",
"hour",
".",
"':'",
".",
"$",
"minute",
";",
"}"
] | Returns the UTC Format
@param string|null $prefix The prefix to add before the returned value
@return string | [
"Returns",
"the",
"UTC",
"Format"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L207-L214 |
Eden-PHP/Timezone | src/Index.php | Index.getUTCDates | public function getUTCDates($format, $interval = 30, $prefix = self::UTC)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 2 must be an integer
->test(2, 'int')
//argument 3 must be a string or null
->test(3, 'string', 'null');
$offsets = $this->getOffsetDates($format, $interval);
$dates = array();
foreach ($offsets as $offset => $date) {
list($hour, $minute, $sign) = $this->getUtcParts($offset);
$utc = $prefix.$sign.$hour.':'.$minute;
$dates[$utc] = $date;
}
return $dates;
} | php | public function getUTCDates($format, $interval = 30, $prefix = self::UTC)
{
Argument::i()
//argument 1 must be a string
->test(1, 'string')
//argument 2 must be an integer
->test(2, 'int')
//argument 3 must be a string or null
->test(3, 'string', 'null');
$offsets = $this->getOffsetDates($format, $interval);
$dates = array();
foreach ($offsets as $offset => $date) {
list($hour, $minute, $sign) = $this->getUtcParts($offset);
$utc = $prefix.$sign.$hour.':'.$minute;
$dates[$utc] = $date;
}
return $dates;
} | [
"public",
"function",
"getUTCDates",
"(",
"$",
"format",
",",
"$",
"interval",
"=",
"30",
",",
"$",
"prefix",
"=",
"self",
"::",
"UTC",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"//argument 1 must be a string",
"->",
"test",
"(",
"1",
",",
"'string'",
")",
"//argument 2 must be an integer",
"->",
"test",
"(",
"2",
",",
"'int'",
")",
"//argument 3 must be a string or null",
"->",
"test",
"(",
"3",
",",
"'string'",
",",
"'null'",
")",
";",
"$",
"offsets",
"=",
"$",
"this",
"->",
"getOffsetDates",
"(",
"$",
"format",
",",
"$",
"interval",
")",
";",
"$",
"dates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"offsets",
"as",
"$",
"offset",
"=>",
"$",
"date",
")",
"{",
"list",
"(",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"sign",
")",
"=",
"$",
"this",
"->",
"getUtcParts",
"(",
"$",
"offset",
")",
";",
"$",
"utc",
"=",
"$",
"prefix",
".",
"$",
"sign",
".",
"$",
"hour",
".",
"':'",
".",
"$",
"minute",
";",
"$",
"dates",
"[",
"$",
"utc",
"]",
"=",
"$",
"date",
";",
"}",
"return",
"$",
"dates",
";",
"}"
] | Returns a list of UTC formats and dates in a 24 hour period
@param *string $format The format of each date to display
@param int $interval The frequency of rows
@param string|null $prefix The prefix to add before each date display
@return array | [
"Returns",
"a",
"list",
"of",
"UTC",
"formats",
"and",
"dates",
"in",
"a",
"24",
"hour",
"period"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L225-L245 |
Eden-PHP/Timezone | src/Index.php | Index.toRelative | public function toRelative($time = null, $level = 7, $default = 'F d, Y')
{
Argument::i()
//argument 1 must be an integer or string
->test(1, 'int', 'string', 'null')
//argument 2 must be an integer
->test(2, 'int');
//if no time
if (is_null($time)) {
//time get now
$time = time();
}
if (is_string($time)) {
$time = strtotime($time);
}
$passed = $time - $this->time;
$gravity = array(
'second' => 1,
'minute' => 60,
'hour' => 60 * 60,
'day' => 60 * 60 * 24,
'week' => 60 * 60 * 24 * 7,
'month' => 60 * 60 * 24 * 30,
'year' => 60 * 60 * 24 * 30 * 12);
$tokens = array();
$i = 0;
foreach ($gravity as $magnitude => $distance) {
if ($i >= $level) {
break;
}
array_unshift($tokens, array($distance, $magnitude));
array_push($tokens, array($distance * -1, $magnitude));
$i++;
}
if ($passed > $tokens[0][0] || $passed < $tokens[count($tokens) - 1][0]) {
return date($default, $this->time);
}
for ($i = 0; $i < count($tokens); $i++) {
$distance = $tokens[$i][0];
$relative = $tokens[$i][1];
if ($passed < $distance) {
continue;
}
if ($distance < 0) {
$distance = $tokens[$i-1][0];
$relative = $tokens[$i-1][1];
}
$difference = (int) round($passed / $distance);
if ($relative === 'second' && -5 < $difference && $difference < 5) {
return 'Now';
}
if ($relative === 'day' && $difference === 1) {
if ($tokens[$i][0] < 0) {
return 'Tomorrow';
}
return 'Yesterday';
}
$suffix = $distance > 0 ? ' ago': ' from now';
return $difference . ' ' . $relative . ($difference === 1 ? '' : 's') . $suffix;
}
return date($default, $this->time);
} | php | public function toRelative($time = null, $level = 7, $default = 'F d, Y')
{
Argument::i()
//argument 1 must be an integer or string
->test(1, 'int', 'string', 'null')
//argument 2 must be an integer
->test(2, 'int');
//if no time
if (is_null($time)) {
//time get now
$time = time();
}
if (is_string($time)) {
$time = strtotime($time);
}
$passed = $time - $this->time;
$gravity = array(
'second' => 1,
'minute' => 60,
'hour' => 60 * 60,
'day' => 60 * 60 * 24,
'week' => 60 * 60 * 24 * 7,
'month' => 60 * 60 * 24 * 30,
'year' => 60 * 60 * 24 * 30 * 12);
$tokens = array();
$i = 0;
foreach ($gravity as $magnitude => $distance) {
if ($i >= $level) {
break;
}
array_unshift($tokens, array($distance, $magnitude));
array_push($tokens, array($distance * -1, $magnitude));
$i++;
}
if ($passed > $tokens[0][0] || $passed < $tokens[count($tokens) - 1][0]) {
return date($default, $this->time);
}
for ($i = 0; $i < count($tokens); $i++) {
$distance = $tokens[$i][0];
$relative = $tokens[$i][1];
if ($passed < $distance) {
continue;
}
if ($distance < 0) {
$distance = $tokens[$i-1][0];
$relative = $tokens[$i-1][1];
}
$difference = (int) round($passed / $distance);
if ($relative === 'second' && -5 < $difference && $difference < 5) {
return 'Now';
}
if ($relative === 'day' && $difference === 1) {
if ($tokens[$i][0] < 0) {
return 'Tomorrow';
}
return 'Yesterday';
}
$suffix = $distance > 0 ? ' ago': ' from now';
return $difference . ' ' . $relative . ($difference === 1 ? '' : 's') . $suffix;
}
return date($default, $this->time);
} | [
"public",
"function",
"toRelative",
"(",
"$",
"time",
"=",
"null",
",",
"$",
"level",
"=",
"7",
",",
"$",
"default",
"=",
"'F d, Y'",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"//argument 1 must be an integer or string",
"->",
"test",
"(",
"1",
",",
"'int'",
",",
"'string'",
",",
"'null'",
")",
"//argument 2 must be an integer",
"->",
"test",
"(",
"2",
",",
"'int'",
")",
";",
"//if no time",
"if",
"(",
"is_null",
"(",
"$",
"time",
")",
")",
"{",
"//time get now",
"$",
"time",
"=",
"time",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"time",
")",
")",
"{",
"$",
"time",
"=",
"strtotime",
"(",
"$",
"time",
")",
";",
"}",
"$",
"passed",
"=",
"$",
"time",
"-",
"$",
"this",
"->",
"time",
";",
"$",
"gravity",
"=",
"array",
"(",
"'second'",
"=>",
"1",
",",
"'minute'",
"=>",
"60",
",",
"'hour'",
"=>",
"60",
"*",
"60",
",",
"'day'",
"=>",
"60",
"*",
"60",
"*",
"24",
",",
"'week'",
"=>",
"60",
"*",
"60",
"*",
"24",
"*",
"7",
",",
"'month'",
"=>",
"60",
"*",
"60",
"*",
"24",
"*",
"30",
",",
"'year'",
"=>",
"60",
"*",
"60",
"*",
"24",
"*",
"30",
"*",
"12",
")",
";",
"$",
"tokens",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"gravity",
"as",
"$",
"magnitude",
"=>",
"$",
"distance",
")",
"{",
"if",
"(",
"$",
"i",
">=",
"$",
"level",
")",
"{",
"break",
";",
"}",
"array_unshift",
"(",
"$",
"tokens",
",",
"array",
"(",
"$",
"distance",
",",
"$",
"magnitude",
")",
")",
";",
"array_push",
"(",
"$",
"tokens",
",",
"array",
"(",
"$",
"distance",
"*",
"-",
"1",
",",
"$",
"magnitude",
")",
")",
";",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"$",
"passed",
">",
"$",
"tokens",
"[",
"0",
"]",
"[",
"0",
"]",
"||",
"$",
"passed",
"<",
"$",
"tokens",
"[",
"count",
"(",
"$",
"tokens",
")",
"-",
"1",
"]",
"[",
"0",
"]",
")",
"{",
"return",
"date",
"(",
"$",
"default",
",",
"$",
"this",
"->",
"time",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"distance",
"=",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
";",
"$",
"relative",
"=",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"passed",
"<",
"$",
"distance",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"distance",
"<",
"0",
")",
"{",
"$",
"distance",
"=",
"$",
"tokens",
"[",
"$",
"i",
"-",
"1",
"]",
"[",
"0",
"]",
";",
"$",
"relative",
"=",
"$",
"tokens",
"[",
"$",
"i",
"-",
"1",
"]",
"[",
"1",
"]",
";",
"}",
"$",
"difference",
"=",
"(",
"int",
")",
"round",
"(",
"$",
"passed",
"/",
"$",
"distance",
")",
";",
"if",
"(",
"$",
"relative",
"===",
"'second'",
"&&",
"-",
"5",
"<",
"$",
"difference",
"&&",
"$",
"difference",
"<",
"5",
")",
"{",
"return",
"'Now'",
";",
"}",
"if",
"(",
"$",
"relative",
"===",
"'day'",
"&&",
"$",
"difference",
"===",
"1",
")",
"{",
"if",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"<",
"0",
")",
"{",
"return",
"'Tomorrow'",
";",
"}",
"return",
"'Yesterday'",
";",
"}",
"$",
"suffix",
"=",
"$",
"distance",
">",
"0",
"?",
"' ago'",
":",
"' from now'",
";",
"return",
"$",
"difference",
".",
"' '",
".",
"$",
"relative",
".",
"(",
"$",
"difference",
"===",
"1",
"?",
"''",
":",
"'s'",
")",
".",
"$",
"suffix",
";",
"}",
"return",
"date",
"(",
"$",
"default",
",",
"$",
"this",
"->",
"time",
")",
";",
"}"
] | Returns the relative distance
$time > this->time = ago
@param int|string $time The time to make relative
@param int $level The granular level
@param string $default The default date format
@return Eden\Timezone\Index | [
"Returns",
"the",
"relative",
"distance",
"$time",
">",
"this",
"-",
">",
"time",
"=",
"ago"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L257-L337 |
Eden-PHP/Timezone | src/Index.php | Index.setTime | public function setTime($time)
{
//argument 1 must be an integer or string
Argument::i()->test(1, 'int', 'string');
if (is_string($time)) {
$time = strtotime($time);
}
$this->time = $time - $this->offset;
return $this;
} | php | public function setTime($time)
{
//argument 1 must be an integer or string
Argument::i()->test(1, 'int', 'string');
if (is_string($time)) {
$time = strtotime($time);
}
$this->time = $time - $this->offset;
return $this;
} | [
"public",
"function",
"setTime",
"(",
"$",
"time",
")",
"{",
"//argument 1 must be an integer or string",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"1",
",",
"'int'",
",",
"'string'",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"time",
")",
")",
"{",
"$",
"time",
"=",
"strtotime",
"(",
"$",
"time",
")",
";",
"}",
"$",
"this",
"->",
"time",
"=",
"$",
"time",
"-",
"$",
"this",
"->",
"offset",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a new time
@param *int|string $time The time value
@return Eden\Timezone\Index | [
"Sets",
"a",
"new",
"time"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L346-L356 |
Eden-PHP/Timezone | src/Index.php | Index.calculateOffset | protected function calculateOffset($zone)
{
if ($this->validation()->isLocation($zone)) {
return $this->getOffsetFromLocation($zone);
}
if ($this->validation()->isUtc($zone)) {
return $this->getOffsetFromUtc($zone);
}
if ($this->validation()->isAbbr($zone)) {
return $this->getOffsetFromAbbr($zone);
}
return 0;
} | php | protected function calculateOffset($zone)
{
if ($this->validation()->isLocation($zone)) {
return $this->getOffsetFromLocation($zone);
}
if ($this->validation()->isUtc($zone)) {
return $this->getOffsetFromUtc($zone);
}
if ($this->validation()->isAbbr($zone)) {
return $this->getOffsetFromAbbr($zone);
}
return 0;
} | [
"protected",
"function",
"calculateOffset",
"(",
"$",
"zone",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validation",
"(",
")",
"->",
"isLocation",
"(",
"$",
"zone",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getOffsetFromLocation",
"(",
"$",
"zone",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"validation",
"(",
")",
"->",
"isUtc",
"(",
"$",
"zone",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getOffsetFromUtc",
"(",
"$",
"zone",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"validation",
"(",
")",
"->",
"isAbbr",
"(",
"$",
"zone",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getOffsetFromAbbr",
"(",
"$",
"zone",
")",
";",
"}",
"return",
"0",
";",
"}"
] | returns the offset based on timezone
@param *string $zone The timezone to calculate the offset with
@return string|int | [
"returns",
"the",
"offset",
"based",
"on",
"timezone"
] | train | https://github.com/Eden-PHP/Timezone/blob/6926376a6d492495522afc3f68a7ed270f640712/src/Index.php#L375-L390 |
eureka-framework/component-template | src/Template/Pattern/PatternBlock.php | PatternBlock.render | public function render()
{
//~ Search block / endblock
$pattern = '`{% ?block:([^%]+)? ?%}(.*?)?{% ?endblock ?%}`is';
$replace = array();
if ((bool) preg_match_all($pattern, $this->templateContent, $matches)) {
foreach ($matches[0] as $index => $string) {
$block = trim($matches[1][$index]);
$content = $matches[2][$index];
$replace[$string] = '<?php Block::getInstance()->begin(); ?>' . $content . '<?php Block::getInstance()->end(\'' . addslashes($block) . '\'); ?>';
}
$this->templateContent = str_replace(array_keys($replace), $replace, $this->templateContent);
}
$pattern = '`{% ?getblock:([^%]+)%}`is';
$replace = array();
//~ Search for getblock
if ((bool) preg_match_all($pattern, $this->templateContent, $matches)) {
foreach ($matches[0] as $index => $replaceString) {
$block = trim($matches[1][$index]);
$replace[$replaceString] = '<?=Block::getInstance()->get(\'' . addslashes($block) . '\'); ?>';
}
$this->templateContent = trim(str_replace(array_keys($replace), $replace, $this->templateContent));
}
return $this->templateContent;
} | php | public function render()
{
//~ Search block / endblock
$pattern = '`{% ?block:([^%]+)? ?%}(.*?)?{% ?endblock ?%}`is';
$replace = array();
if ((bool) preg_match_all($pattern, $this->templateContent, $matches)) {
foreach ($matches[0] as $index => $string) {
$block = trim($matches[1][$index]);
$content = $matches[2][$index];
$replace[$string] = '<?php Block::getInstance()->begin(); ?>' . $content . '<?php Block::getInstance()->end(\'' . addslashes($block) . '\'); ?>';
}
$this->templateContent = str_replace(array_keys($replace), $replace, $this->templateContent);
}
$pattern = '`{% ?getblock:([^%]+)%}`is';
$replace = array();
//~ Search for getblock
if ((bool) preg_match_all($pattern, $this->templateContent, $matches)) {
foreach ($matches[0] as $index => $replaceString) {
$block = trim($matches[1][$index]);
$replace[$replaceString] = '<?=Block::getInstance()->get(\'' . addslashes($block) . '\'); ?>';
}
$this->templateContent = trim(str_replace(array_keys($replace), $replace, $this->templateContent));
}
return $this->templateContent;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"//~ Search block / endblock",
"$",
"pattern",
"=",
"'`{% ?block:([^%]+)? ?%}(.*?)?{% ?endblock ?%}`is'",
";",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"if",
"(",
"(",
"bool",
")",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"templateContent",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"string",
")",
"{",
"$",
"block",
"=",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
")",
";",
"$",
"content",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"replace",
"[",
"$",
"string",
"]",
"=",
"'<?php Block::getInstance()->begin(); ?>'",
".",
"$",
"content",
".",
"'<?php Block::getInstance()->end(\\''",
".",
"addslashes",
"(",
"$",
"block",
")",
".",
"'\\'); ?>'",
";",
"}",
"$",
"this",
"->",
"templateContent",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replace",
")",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"templateContent",
")",
";",
"}",
"$",
"pattern",
"=",
"'`{% ?getblock:([^%]+)%}`is'",
";",
"$",
"replace",
"=",
"array",
"(",
")",
";",
"//~ Search for getblock",
"if",
"(",
"(",
"bool",
")",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"templateContent",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"replaceString",
")",
"{",
"$",
"block",
"=",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
")",
";",
"$",
"replace",
"[",
"$",
"replaceString",
"]",
"=",
"'<?=Block::getInstance()->get(\\''",
".",
"addslashes",
"(",
"$",
"block",
")",
".",
"'\\'); ?>'",
";",
"}",
"$",
"this",
"->",
"templateContent",
"=",
"trim",
"(",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replace",
")",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"templateContent",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"templateContent",
";",
"}"
] | Search & replace current defined pattern for template.
Example of template:
<code>
# In Template:
#
# {%block:my_block_name%}
# <!-- Html / PHP code -->
# {%endblock%}
# {% block: my_another_block_name %}
# <!-- Html / PHP code -->
# {% endblock %}
#
# {%getblock:my_block_name%}
# In Compiled template:
<?php Block::getInstance()->begin(); ?>
<!-- Html / PHP code -->
<?php Block::getInstance()->end('my_block_name'); ?>
<?php Block::getInstance()->begin(); ?>
<!-- Html / PHP code -->
<?php Block::getInstance()->end('my_another_block_name'); ?>
</code>
@return string Compiled template | [
"Search",
"&",
"replace",
"current",
"defined",
"pattern",
"for",
"template",
".",
"Example",
"of",
"template",
":"
] | train | https://github.com/eureka-framework/component-template/blob/42e9b3954b79892ba340ba7ca909f03ee99c36fe/src/Template/Pattern/PatternBlock.php#L47-L77 |
shgysk8zer0/core_api | traits/image.php | Image._loadImage | final protected function _loadImage($fname)
{
$data = getimagesize($fname);
if (is_array($data)) {
list(
$this->_image_width,
$this->_image_height,
$this->_image_type,
$this->_image_attr
) = $data;
$this->_image_mime = array_key_exists('mime', $data)
? $data['mime']
: image_type_to_mime_type($this->_image_type);
switch ($this->_image_type) {
case IMAGETYPE_JPEG:
$this->_image_handle = imagecreatefromjpeg($fname);
break;
case IMAGETYPE_PNG:
$this->_image_handle = imagecreatefrompng($fname);
break;
case IMAGETYPE_GIF:
$this->_image_handle = imagecreatefromgif($fname);
break;
default:
trigger_error(sprintf('Unsupported file type for "%s"', $fname));
break;
}
}
} | php | final protected function _loadImage($fname)
{
$data = getimagesize($fname);
if (is_array($data)) {
list(
$this->_image_width,
$this->_image_height,
$this->_image_type,
$this->_image_attr
) = $data;
$this->_image_mime = array_key_exists('mime', $data)
? $data['mime']
: image_type_to_mime_type($this->_image_type);
switch ($this->_image_type) {
case IMAGETYPE_JPEG:
$this->_image_handle = imagecreatefromjpeg($fname);
break;
case IMAGETYPE_PNG:
$this->_image_handle = imagecreatefrompng($fname);
break;
case IMAGETYPE_GIF:
$this->_image_handle = imagecreatefromgif($fname);
break;
default:
trigger_error(sprintf('Unsupported file type for "%s"', $fname));
break;
}
}
} | [
"final",
"protected",
"function",
"_loadImage",
"(",
"$",
"fname",
")",
"{",
"$",
"data",
"=",
"getimagesize",
"(",
"$",
"fname",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"list",
"(",
"$",
"this",
"->",
"_image_width",
",",
"$",
"this",
"->",
"_image_height",
",",
"$",
"this",
"->",
"_image_type",
",",
"$",
"this",
"->",
"_image_attr",
")",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"_image_mime",
"=",
"array_key_exists",
"(",
"'mime'",
",",
"$",
"data",
")",
"?",
"$",
"data",
"[",
"'mime'",
"]",
":",
"image_type_to_mime_type",
"(",
"$",
"this",
"->",
"_image_type",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"_image_type",
")",
"{",
"case",
"IMAGETYPE_JPEG",
":",
"$",
"this",
"->",
"_image_handle",
"=",
"imagecreatefromjpeg",
"(",
"$",
"fname",
")",
";",
"break",
";",
"case",
"IMAGETYPE_PNG",
":",
"$",
"this",
"->",
"_image_handle",
"=",
"imagecreatefrompng",
"(",
"$",
"fname",
")",
";",
"break",
";",
"case",
"IMAGETYPE_GIF",
":",
"$",
"this",
"->",
"_image_handle",
"=",
"imagecreatefromgif",
"(",
"$",
"fname",
")",
";",
"break",
";",
"default",
":",
"trigger_error",
"(",
"sprintf",
"(",
"'Unsupported file type for \"%s\"'",
",",
"$",
"fname",
")",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Get image attributes and create the handle/resource
@param string $fname Path to image file | [
"Get",
"image",
"attributes",
"and",
"create",
"the",
"handle",
"/",
"resource"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L77-L109 |
shgysk8zer0/core_api | traits/image.php | Image.crop | final public function crop($x = 0, $y = 0, $width = null, $height = null)
{
$this->_image_handle = imagecrop(
$this->_image_handle,
array_merge(
array(
'x' => 0,
'y' => 0,
'width' => $this->imageWidth(),
'height' => $this->imageHeight()
),
array_filter(
array_combine(
array('x', 'y', 'width', 'height'),
array($x, $y, $width, $height)
)
)
)
);
return $this;
} | php | final public function crop($x = 0, $y = 0, $width = null, $height = null)
{
$this->_image_handle = imagecrop(
$this->_image_handle,
array_merge(
array(
'x' => 0,
'y' => 0,
'width' => $this->imageWidth(),
'height' => $this->imageHeight()
),
array_filter(
array_combine(
array('x', 'y', 'width', 'height'),
array($x, $y, $width, $height)
)
)
)
);
return $this;
} | [
"final",
"public",
"function",
"crop",
"(",
"$",
"x",
"=",
"0",
",",
"$",
"y",
"=",
"0",
",",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_image_handle",
"=",
"imagecrop",
"(",
"$",
"this",
"->",
"_image_handle",
",",
"array_merge",
"(",
"array",
"(",
"'x'",
"=>",
"0",
",",
"'y'",
"=>",
"0",
",",
"'width'",
"=>",
"$",
"this",
"->",
"imageWidth",
"(",
")",
",",
"'height'",
"=>",
"$",
"this",
"->",
"imageHeight",
"(",
")",
")",
",",
"array_filter",
"(",
"array_combine",
"(",
"array",
"(",
"'x'",
",",
"'y'",
",",
"'width'",
",",
"'height'",
")",
",",
"array",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"width",
",",
"$",
"height",
")",
")",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Crop an image from $x, $y to $width & $height
@param int $x Starting x coordinate
@param int $y Starting y coordinate
@param int $width Ending width in pixels
@param int $height Ending height in pixels
@return self | [
"Crop",
"an",
"image",
"from",
"$x",
"$y",
"to",
"$width",
"&",
"$height"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L142-L163 |
shgysk8zer0/core_api | traits/image.php | Image.resizeImage | final public function resizeImage($width = null, $height = null)
{
if (is_int($width) and is_int($height)) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled(
$new_image,
$this->_image_handle,
0,
0,
0,
0,
$width,
$height,
$this->imageWidth(),
$this->imageHeight()
);
if (is_resource($new_image)) {
$this->_image_handle = $new_image;
}
}
return $this;
} | php | final public function resizeImage($width = null, $height = null)
{
if (is_int($width) and is_int($height)) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled(
$new_image,
$this->_image_handle,
0,
0,
0,
0,
$width,
$height,
$this->imageWidth(),
$this->imageHeight()
);
if (is_resource($new_image)) {
$this->_image_handle = $new_image;
}
}
return $this;
} | [
"final",
"public",
"function",
"resizeImage",
"(",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"width",
")",
"and",
"is_int",
"(",
"$",
"height",
")",
")",
"{",
"$",
"new_image",
"=",
"imagecreatetruecolor",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"imagecopyresampled",
"(",
"$",
"new_image",
",",
"$",
"this",
"->",
"_image_handle",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"this",
"->",
"imageWidth",
"(",
")",
",",
"$",
"this",
"->",
"imageHeight",
"(",
")",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"new_image",
")",
")",
"{",
"$",
"this",
"->",
"_image_handle",
"=",
"$",
"new_image",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Resize an image to an exact width and height
@param int $width Width in pixels
@param int $height Height in pixels
@return self With $this->_image_handle as resized image | [
"Resize",
"an",
"image",
"to",
"an",
"exact",
"width",
"and",
"height"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L172-L193 |
shgysk8zer0/core_api | traits/image.php | Image.scaleImage | final public function scaleImage($factor = 1)
{
// Scaling by a factor of 1 produces no changes, so do not scale if it is 1
if (is_numeric($factor) and $factor !== 1) {
$new_width = round(abs($factor * $this->imageWidth()));
$new_height = round(abs($factor * $this->imageHeight()));
$this->_image_handle = imagescale($this->_image_handle, $new_width, $new_height);
}
return $this;
} | php | final public function scaleImage($factor = 1)
{
// Scaling by a factor of 1 produces no changes, so do not scale if it is 1
if (is_numeric($factor) and $factor !== 1) {
$new_width = round(abs($factor * $this->imageWidth()));
$new_height = round(abs($factor * $this->imageHeight()));
$this->_image_handle = imagescale($this->_image_handle, $new_width, $new_height);
}
return $this;
} | [
"final",
"public",
"function",
"scaleImage",
"(",
"$",
"factor",
"=",
"1",
")",
"{",
"// Scaling by a factor of 1 produces no changes, so do not scale if it is 1",
"if",
"(",
"is_numeric",
"(",
"$",
"factor",
")",
"and",
"$",
"factor",
"!==",
"1",
")",
"{",
"$",
"new_width",
"=",
"round",
"(",
"abs",
"(",
"$",
"factor",
"*",
"$",
"this",
"->",
"imageWidth",
"(",
")",
")",
")",
";",
"$",
"new_height",
"=",
"round",
"(",
"abs",
"(",
"$",
"factor",
"*",
"$",
"this",
"->",
"imageHeight",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"_image_handle",
"=",
"imagescale",
"(",
"$",
"this",
"->",
"_image_handle",
",",
"$",
"new_width",
",",
"$",
"new_height",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Scale an image by given $factor
@param float $factor Amount to scale by (0.5 is half, 2 is double, etc.)
@return self
@see https://php.net/manual/en/function.imagescale.php | [
"Scale",
"an",
"image",
"by",
"given",
"$factor"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L202-L212 |
shgysk8zer0/core_api | traits/image.php | Image.rotateImage | final public function rotateImage(
$angle = 0,
array $bgd_color = array(0, 0, 0, 127),
$ignore_transparent = false
)
{
$this->_image_handle = imagerotate(
$this->_image_handle,
$angle,
$this->_createImageColorAlpha($bgd_color),
$ignore_transparent ? 1 : 0
);
} | php | final public function rotateImage(
$angle = 0,
array $bgd_color = array(0, 0, 0, 127),
$ignore_transparent = false
)
{
$this->_image_handle = imagerotate(
$this->_image_handle,
$angle,
$this->_createImageColorAlpha($bgd_color),
$ignore_transparent ? 1 : 0
);
} | [
"final",
"public",
"function",
"rotateImage",
"(",
"$",
"angle",
"=",
"0",
",",
"array",
"$",
"bgd_color",
"=",
"array",
"(",
"0",
",",
"0",
",",
"0",
",",
"127",
")",
",",
"$",
"ignore_transparent",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_image_handle",
"=",
"imagerotate",
"(",
"$",
"this",
"->",
"_image_handle",
",",
"$",
"angle",
",",
"$",
"this",
"->",
"_createImageColorAlpha",
"(",
"$",
"bgd_color",
")",
",",
"$",
"ignore_transparent",
"?",
"1",
":",
"0",
")",
";",
"}"
] | Rotate an image with a given angle
@param int $angle Rotation angle, in degrees.
@param array $bgd_color RGBA array for background color
@param bool $ignore_transparent Ignore transparent colors? | [
"Rotate",
"an",
"image",
"with",
"a",
"given",
"angle"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L221-L233 |
shgysk8zer0/core_api | traits/image.php | Image._createImageColorAlpha | final protected function _createImageColorAlpha(array $rgba = array())
{
$keys = array('r', 'g', 'b', 'a');
$rgba = array_filter($rgba, 'is_int');
$rgba = array_map('abs', $rgba);
$rgba = array_pad($rgba, count($keys), 0);
$rgba = array_slice($rgba, 0, count($keys));
$rgba = array_combine($keys, $rgba);
extract($rgba);
return imagecolorallocatealpha(
$this->_image_handle,
min($r, 255),
min($g, 255),
min($b, 255),
min($a, 127)
);
} | php | final protected function _createImageColorAlpha(array $rgba = array())
{
$keys = array('r', 'g', 'b', 'a');
$rgba = array_filter($rgba, 'is_int');
$rgba = array_map('abs', $rgba);
$rgba = array_pad($rgba, count($keys), 0);
$rgba = array_slice($rgba, 0, count($keys));
$rgba = array_combine($keys, $rgba);
extract($rgba);
return imagecolorallocatealpha(
$this->_image_handle,
min($r, 255),
min($g, 255),
min($b, 255),
min($a, 127)
);
} | [
"final",
"protected",
"function",
"_createImageColorAlpha",
"(",
"array",
"$",
"rgba",
"=",
"array",
"(",
")",
")",
"{",
"$",
"keys",
"=",
"array",
"(",
"'r'",
",",
"'g'",
",",
"'b'",
",",
"'a'",
")",
";",
"$",
"rgba",
"=",
"array_filter",
"(",
"$",
"rgba",
",",
"'is_int'",
")",
";",
"$",
"rgba",
"=",
"array_map",
"(",
"'abs'",
",",
"$",
"rgba",
")",
";",
"$",
"rgba",
"=",
"array_pad",
"(",
"$",
"rgba",
",",
"count",
"(",
"$",
"keys",
")",
",",
"0",
")",
";",
"$",
"rgba",
"=",
"array_slice",
"(",
"$",
"rgba",
",",
"0",
",",
"count",
"(",
"$",
"keys",
")",
")",
";",
"$",
"rgba",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"$",
"rgba",
")",
";",
"extract",
"(",
"$",
"rgba",
")",
";",
"return",
"imagecolorallocatealpha",
"(",
"$",
"this",
"->",
"_image_handle",
",",
"min",
"(",
"$",
"r",
",",
"255",
")",
",",
"min",
"(",
"$",
"g",
",",
"255",
")",
",",
"min",
"(",
"$",
"b",
",",
"255",
")",
",",
"min",
"(",
"$",
"a",
",",
"127",
")",
")",
";",
"}"
] | Allocate a color for an image
@param array $rgba RGBA array for color
@return int A color identifier or FALSE if the allocation failed.
@see https://php.net/manual/en/function.imagecolorallocatealpha.php | [
"Allocate",
"a",
"color",
"for",
"an",
"image"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L242-L260 |
shgysk8zer0/core_api | traits/image.php | Image.imagePNG | final public function imagePNG($filename = null, $quality = -1, $filters = PNG_NO_FILTER)
{
return imagepng($this->_image_handle, $filename, $quality, $filters);
} | php | final public function imagePNG($filename = null, $quality = -1, $filters = PNG_NO_FILTER)
{
return imagepng($this->_image_handle, $filename, $quality, $filters);
} | [
"final",
"public",
"function",
"imagePNG",
"(",
"$",
"filename",
"=",
"null",
",",
"$",
"quality",
"=",
"-",
"1",
",",
"$",
"filters",
"=",
"PNG_NO_FILTER",
")",
"{",
"return",
"imagepng",
"(",
"$",
"this",
"->",
"_image_handle",
",",
"$",
"filename",
",",
"$",
"quality",
",",
"$",
"filters",
")",
";",
"}"
] | Output a PNG image to either the browser or a file
@param string $filename The path to save the file to. null outputs directly
@param int $quality Compression level: from 0 (no compression) to 9.
@param int $filters Any combination of the PNG_FILTER_XXX constants.
@return bool True on success, false on failure | [
"Output",
"a",
"PNG",
"image",
"to",
"either",
"the",
"browser",
"or",
"a",
"file"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L295-L298 |
shgysk8zer0/core_api | traits/image.php | Image.saveImage | final public function saveImage($filename)
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if (! is_string($extension)) {
$extension = image_type_to_extension($this->_image_type);
$filename .= ".{$extension}";
}
switch(strtolower($extension))
{
case 'jpeg':
case 'jpg':
return $this->imageJPEG($filename);
break;
case 'png':
return $this->imagePNG($filename);
break;
case 'gif':
return $this->imageGIF($filename);
default:
trigger_error('Invalid extension or not an image', E_USER_WARNING);
return false;
}
} | php | final public function saveImage($filename)
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if (! is_string($extension)) {
$extension = image_type_to_extension($this->_image_type);
$filename .= ".{$extension}";
}
switch(strtolower($extension))
{
case 'jpeg':
case 'jpg':
return $this->imageJPEG($filename);
break;
case 'png':
return $this->imagePNG($filename);
break;
case 'gif':
return $this->imageGIF($filename);
default:
trigger_error('Invalid extension or not an image', E_USER_WARNING);
return false;
}
} | [
"final",
"public",
"function",
"saveImage",
"(",
"$",
"filename",
")",
"{",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"filename",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"extension",
")",
")",
"{",
"$",
"extension",
"=",
"image_type_to_extension",
"(",
"$",
"this",
"->",
"_image_type",
")",
";",
"$",
"filename",
".=",
"\".{$extension}\"",
";",
"}",
"switch",
"(",
"strtolower",
"(",
"$",
"extension",
")",
")",
"{",
"case",
"'jpeg'",
":",
"case",
"'jpg'",
":",
"return",
"$",
"this",
"->",
"imageJPEG",
"(",
"$",
"filename",
")",
";",
"break",
";",
"case",
"'png'",
":",
"return",
"$",
"this",
"->",
"imagePNG",
"(",
"$",
"filename",
")",
";",
"break",
";",
"case",
"'gif'",
":",
"return",
"$",
"this",
"->",
"imageGIF",
"(",
"$",
"filename",
")",
";",
"default",
":",
"trigger_error",
"(",
"'Invalid extension or not an image'",
",",
"E_USER_WARNING",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Generic save funciton, which converts image according to extension
@param string $filename Path and extension to save to
@return bool Success or failure of save | [
"Generic",
"save",
"funciton",
"which",
"converts",
"image",
"according",
"to",
"extension"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L306-L333 |
shgysk8zer0/core_api | traits/image.php | Image.imageAsDOMElement | final public function imageAsDOMElement($as = null)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$image = $dom->appendChild($dom->createElement('img'));
$image->setAttribute('height', $this->imageHeight());
$image->setAttribute('width', $this->imageWidth());
$image->setAttribute('alt', $this->alt_text);
$image->setAttribute('src', $this->dataURI($as));
return $image;
} | php | final public function imageAsDOMElement($as = null)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$image = $dom->appendChild($dom->createElement('img'));
$image->setAttribute('height', $this->imageHeight());
$image->setAttribute('width', $this->imageWidth());
$image->setAttribute('alt', $this->alt_text);
$image->setAttribute('src', $this->dataURI($as));
return $image;
} | [
"final",
"public",
"function",
"imageAsDOMElement",
"(",
"$",
"as",
"=",
"null",
")",
"{",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
";",
"$",
"image",
"=",
"$",
"dom",
"->",
"appendChild",
"(",
"$",
"dom",
"->",
"createElement",
"(",
"'img'",
")",
")",
";",
"$",
"image",
"->",
"setAttribute",
"(",
"'height'",
",",
"$",
"this",
"->",
"imageHeight",
"(",
")",
")",
";",
"$",
"image",
"->",
"setAttribute",
"(",
"'width'",
",",
"$",
"this",
"->",
"imageWidth",
"(",
")",
")",
";",
"$",
"image",
"->",
"setAttribute",
"(",
"'alt'",
",",
"$",
"this",
"->",
"alt_text",
")",
";",
"$",
"image",
"->",
"setAttribute",
"(",
"'src'",
",",
"$",
"this",
"->",
"dataURI",
"(",
"$",
"as",
")",
")",
";",
"return",
"$",
"image",
";",
"}"
] | Create a DOMElement containing attributes of the image
@param void
@return DOMElement
@uses DOMDocument | [
"Create",
"a",
"DOMElement",
"containing",
"attributes",
"of",
"the",
"image"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L342-L351 |
shgysk8zer0/core_api | traits/image.php | Image.imageAsString | final public function imageAsString($as = null)
{
$image = $this->imageAsDOMElement($as);
return $image->ownerDocument->saveHTML($image);
} | php | final public function imageAsString($as = null)
{
$image = $this->imageAsDOMElement($as);
return $image->ownerDocument->saveHTML($image);
} | [
"final",
"public",
"function",
"imageAsString",
"(",
"$",
"as",
"=",
"null",
")",
"{",
"$",
"image",
"=",
"$",
"this",
"->",
"imageAsDOMElement",
"(",
"$",
"as",
")",
";",
"return",
"$",
"image",
"->",
"ownerDocument",
"->",
"saveHTML",
"(",
"$",
"image",
")",
";",
"}"
] | Uses imageAsDOMElement and returns it as an HTML string
@param void
@return string HTML <img> element | [
"Uses",
"imageAsDOMElement",
"and",
"returns",
"it",
"as",
"an",
"HTML",
"string"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L359-L363 |
shgysk8zer0/core_api | traits/image.php | Image.dataURI | final public function dataURI($as = null)
{
$mime = is_int($as) ? image_type_to_mime_type($as) : $this->_image_mime;
return 'data:' . $mime . ';base64,' . base64_encode($this->imageAsBinary($as));
} | php | final public function dataURI($as = null)
{
$mime = is_int($as) ? image_type_to_mime_type($as) : $this->_image_mime;
return 'data:' . $mime . ';base64,' . base64_encode($this->imageAsBinary($as));
} | [
"final",
"public",
"function",
"dataURI",
"(",
"$",
"as",
"=",
"null",
")",
"{",
"$",
"mime",
"=",
"is_int",
"(",
"$",
"as",
")",
"?",
"image_type_to_mime_type",
"(",
"$",
"as",
")",
":",
"$",
"this",
"->",
"_image_mime",
";",
"return",
"'data:'",
".",
"$",
"mime",
".",
"';base64,'",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"imageAsBinary",
"(",
"$",
"as",
")",
")",
";",
"}"
] | Converts image to a base64 encoded string
@param void
@return string "data:image/*;base64,..." | [
"Converts",
"image",
"to",
"a",
"base64",
"encoded",
"string"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L371-L375 |
shgysk8zer0/core_api | traits/image.php | Image.imageAsBinary | final public function imageAsBinary($as = null, $ob = true)
{
if ($ob) {
ob_start();
}
switch (is_int($as) ? $as : $this->_image_type) {
case IMAGETYPE_JPEG:
$this->imageJPEG();
break;
case IMAGETYPE_GIF:
$this->imageGIF();
break;
case IMAGETYPE_PNG:
$this->imagePNG();
break;
}
if ($ob) {
return ob_get_clean();
}
} | php | final public function imageAsBinary($as = null, $ob = true)
{
if ($ob) {
ob_start();
}
switch (is_int($as) ? $as : $this->_image_type) {
case IMAGETYPE_JPEG:
$this->imageJPEG();
break;
case IMAGETYPE_GIF:
$this->imageGIF();
break;
case IMAGETYPE_PNG:
$this->imagePNG();
break;
}
if ($ob) {
return ob_get_clean();
}
} | [
"final",
"public",
"function",
"imageAsBinary",
"(",
"$",
"as",
"=",
"null",
",",
"$",
"ob",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"ob",
")",
"{",
"ob_start",
"(",
")",
";",
"}",
"switch",
"(",
"is_int",
"(",
"$",
"as",
")",
"?",
"$",
"as",
":",
"$",
"this",
"->",
"_image_type",
")",
"{",
"case",
"IMAGETYPE_JPEG",
":",
"$",
"this",
"->",
"imageJPEG",
"(",
")",
";",
"break",
";",
"case",
"IMAGETYPE_GIF",
":",
"$",
"this",
"->",
"imageGIF",
"(",
")",
";",
"break",
";",
"case",
"IMAGETYPE_PNG",
":",
"$",
"this",
"->",
"imagePNG",
"(",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"ob",
")",
"{",
"return",
"ob_get_clean",
"(",
")",
";",
"}",
"}"
] | Calls image* method to get binary image data and returns as string using output buffering
@param int $type Optional IMAGETYPE_* constant to convert to
@param bool $ob Whether or not to use output buffering (true returns string)
@return mixed Binary image data if $ob is true, otherwise null | [
"Calls",
"image",
"*",
"method",
"to",
"get",
"binary",
"image",
"data",
"and",
"returns",
"as",
"string",
"using",
"output",
"buffering"
] | train | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/image.php#L384-L405 |
tonis-io-legacy/view | src/Strategy/JsonStrategy.php | JsonStrategy.render | public function render(ModelInterface $model)
{
if (!$model instanceof JsonModel) {
return '{}';
}
$result = json_encode($model->getData());
if ($model->isJSONP()) {
$result = sprintf('%s(%s);', $model->getCallbackMethod(), $result);
}
return $result;
} | php | public function render(ModelInterface $model)
{
if (!$model instanceof JsonModel) {
return '{}';
}
$result = json_encode($model->getData());
if ($model->isJSONP()) {
$result = sprintf('%s(%s);', $model->getCallbackMethod(), $result);
}
return $result;
} | [
"public",
"function",
"render",
"(",
"ModelInterface",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"JsonModel",
")",
"{",
"return",
"'{}'",
";",
"}",
"$",
"result",
"=",
"json_encode",
"(",
"$",
"model",
"->",
"getData",
"(",
")",
")",
";",
"if",
"(",
"$",
"model",
"->",
"isJSONP",
"(",
")",
")",
"{",
"$",
"result",
"=",
"sprintf",
"(",
"'%s(%s);'",
",",
"$",
"model",
"->",
"getCallbackMethod",
"(",
")",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/tonis-io-legacy/view/blob/20e703cd3f6243dc08b2eec028a8997c33e9edcc/src/Strategy/JsonStrategy.php#L22-L35 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.exec | protected static function exec($statement, $data)
{
$self = self::getInstance();
$statement = $self->makeStatement($statement);
$make = $self->pdo->prepare($statement);
$data = array_merge($data, $self->optionWhereData);
$make->execute($data);
$self->makeEmpty();
$error = $make->errorInfo();
if ($error[1] and $self->showErrorQuery) {
var_dump(
array(
"Error" => $error
)
);
}
return $make;
} | php | protected static function exec($statement, $data)
{
$self = self::getInstance();
$statement = $self->makeStatement($statement);
$make = $self->pdo->prepare($statement);
$data = array_merge($data, $self->optionWhereData);
$make->execute($data);
$self->makeEmpty();
$error = $make->errorInfo();
if ($error[1] and $self->showErrorQuery) {
var_dump(
array(
"Error" => $error
)
);
}
return $make;
} | [
"protected",
"static",
"function",
"exec",
"(",
"$",
"statement",
",",
"$",
"data",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"self",
"->",
"makeStatement",
"(",
"$",
"statement",
")",
";",
"$",
"make",
"=",
"$",
"self",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"statement",
")",
";",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"self",
"->",
"optionWhereData",
")",
";",
"$",
"make",
"->",
"execute",
"(",
"$",
"data",
")",
";",
"$",
"self",
"->",
"makeEmpty",
"(",
")",
";",
"$",
"error",
"=",
"$",
"make",
"->",
"errorInfo",
"(",
")",
";",
"if",
"(",
"$",
"error",
"[",
"1",
"]",
"and",
"$",
"self",
"->",
"showErrorQuery",
")",
"{",
"var_dump",
"(",
"array",
"(",
"\"Error\"",
"=>",
"$",
"error",
")",
")",
";",
"}",
"return",
"$",
"make",
";",
"}"
] | Execute Override
@param string $statement
@param array $data
@return \PDO | [
"Execute",
"Override"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L96-L117 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeStatement | protected static function makeStatement($statement)
{
$self = self::getInstance();
$optionWhere = (!empty($self->optionWhere)) ? " WHERE ". substr(implode("", $self->optionWhere), 4) : null;
$optionJoin = implode("", $self->optionJoin);
$optionOrder = $self->optionOrder;
$optionLimit = $self->optionLimit;
return $statement.$optionJoin.$optionWhere.$optionOrder.$optionLimit;
} | php | protected static function makeStatement($statement)
{
$self = self::getInstance();
$optionWhere = (!empty($self->optionWhere)) ? " WHERE ". substr(implode("", $self->optionWhere), 4) : null;
$optionJoin = implode("", $self->optionJoin);
$optionOrder = $self->optionOrder;
$optionLimit = $self->optionLimit;
return $statement.$optionJoin.$optionWhere.$optionOrder.$optionLimit;
} | [
"protected",
"static",
"function",
"makeStatement",
"(",
"$",
"statement",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"optionWhere",
"=",
"(",
"!",
"empty",
"(",
"$",
"self",
"->",
"optionWhere",
")",
")",
"?",
"\" WHERE \"",
".",
"substr",
"(",
"implode",
"(",
"\"\"",
",",
"$",
"self",
"->",
"optionWhere",
")",
",",
"4",
")",
":",
"null",
";",
"$",
"optionJoin",
"=",
"implode",
"(",
"\"\"",
",",
"$",
"self",
"->",
"optionJoin",
")",
";",
"$",
"optionOrder",
"=",
"$",
"self",
"->",
"optionOrder",
";",
"$",
"optionLimit",
"=",
"$",
"self",
"->",
"optionLimit",
";",
"return",
"$",
"statement",
".",
"$",
"optionJoin",
".",
"$",
"optionWhere",
".",
"$",
"optionOrder",
".",
"$",
"optionLimit",
";",
"}"
] | Make Query Statement
@param string $statement
@return string | [
"Make",
"Query",
"Statement"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L125-L135 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeMultipleInsert | protected static function makeMultipleInsert($table, $data)
{
$insert_values = array();
foreach ($data as $d) {
$insert_values = array_merge($insert_values, array_values($d));
$count = count($d);
$array = array_fill(0, $count, '?');
$placeholder[] = '('.implode(',', $array).')';
}
$column = implode(',', array_keys($data[0]));
$values = implode(',', $placeholder);
$query = "INSERT INTO {$table} ({$column}) VALUES {$values}";
return [$query, $insert_values];
} | php | protected static function makeMultipleInsert($table, $data)
{
$insert_values = array();
foreach ($data as $d) {
$insert_values = array_merge($insert_values, array_values($d));
$count = count($d);
$array = array_fill(0, $count, '?');
$placeholder[] = '('.implode(',', $array).')';
}
$column = implode(',', array_keys($data[0]));
$values = implode(',', $placeholder);
$query = "INSERT INTO {$table} ({$column}) VALUES {$values}";
return [$query, $insert_values];
} | [
"protected",
"static",
"function",
"makeMultipleInsert",
"(",
"$",
"table",
",",
"$",
"data",
")",
"{",
"$",
"insert_values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"d",
")",
"{",
"$",
"insert_values",
"=",
"array_merge",
"(",
"$",
"insert_values",
",",
"array_values",
"(",
"$",
"d",
")",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"d",
")",
";",
"$",
"array",
"=",
"array_fill",
"(",
"0",
",",
"$",
"count",
",",
"'?'",
")",
";",
"$",
"placeholder",
"[",
"]",
"=",
"'('",
".",
"implode",
"(",
"','",
",",
"$",
"array",
")",
".",
"')'",
";",
"}",
"$",
"column",
"=",
"implode",
"(",
"','",
",",
"array_keys",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
";",
"$",
"values",
"=",
"implode",
"(",
"','",
",",
"$",
"placeholder",
")",
";",
"$",
"query",
"=",
"\"INSERT INTO {$table} ({$column}) VALUES {$values}\"",
";",
"return",
"[",
"$",
"query",
",",
"$",
"insert_values",
"]",
";",
"}"
] | Make Multiple Insert Parameter
@param string $table
@param array $data
@return array | [
"Make",
"Multiple",
"Insert",
"Parameter"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L159-L178 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeUpdateParameter | protected static function makeUpdateParameter($data)
{
foreach ($data as $field => $value) {
$newData[] = "{$field}=:{$field}";
}
$newData = implode(",", $newData); // override new data
return $newData;
} | php | protected static function makeUpdateParameter($data)
{
foreach ($data as $field => $value) {
$newData[] = "{$field}=:{$field}";
}
$newData = implode(",", $newData); // override new data
return $newData;
} | [
"protected",
"static",
"function",
"makeUpdateParameter",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"newData",
"[",
"]",
"=",
"\"{$field}=:{$field}\"",
";",
"}",
"$",
"newData",
"=",
"implode",
"(",
"\",\"",
",",
"$",
"newData",
")",
";",
"// override new data",
"return",
"$",
"newData",
";",
"}"
] | Make Update Parameter
@param array $data
@return array | [
"Make",
"Update",
"Parameter"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L186-L195 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeSelect | protected static function makeSelect()
{
$self = self::getInstance();
$select = (!empty($self->optionSelect)) ? $self->optionSelect : "*";
return "SELECT {$select} FROM {$self->table_name} ";
} | php | protected static function makeSelect()
{
$self = self::getInstance();
$select = (!empty($self->optionSelect)) ? $self->optionSelect : "*";
return "SELECT {$select} FROM {$self->table_name} ";
} | [
"protected",
"static",
"function",
"makeSelect",
"(",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"select",
"=",
"(",
"!",
"empty",
"(",
"$",
"self",
"->",
"optionSelect",
")",
")",
"?",
"$",
"self",
"->",
"optionSelect",
":",
"\"*\"",
";",
"return",
"\"SELECT {$select} FROM {$self->table_name} \"",
";",
"}"
] | Make Select Query
@return string | [
"Make",
"Select",
"Query"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L202-L208 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeEmpty | protected static function makeEmpty()
{
$self = self::getInstance();
$self->optionWhere = [];
$self->optionWhereData = [];
$self->optionJoin = [];
$self->optionLimit = null;
$self->optionSelect = null;
$self->table_name = null;
return $self;
} | php | protected static function makeEmpty()
{
$self = self::getInstance();
$self->optionWhere = [];
$self->optionWhereData = [];
$self->optionJoin = [];
$self->optionLimit = null;
$self->optionSelect = null;
$self->table_name = null;
return $self;
} | [
"protected",
"static",
"function",
"makeEmpty",
"(",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"self",
"->",
"optionWhere",
"=",
"[",
"]",
";",
"$",
"self",
"->",
"optionWhereData",
"=",
"[",
"]",
";",
"$",
"self",
"->",
"optionJoin",
"=",
"[",
"]",
";",
"$",
"self",
"->",
"optionLimit",
"=",
"null",
";",
"$",
"self",
"->",
"optionSelect",
"=",
"null",
";",
"$",
"self",
"->",
"table_name",
"=",
"null",
";",
"return",
"$",
"self",
";",
"}"
] | Empty All Option
@return Instance | [
"Empty",
"All",
"Option"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L215-L227 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.