repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
linpax/microphp-framework | src/web/html/HeadTagTrait.php | HeadTagTrait.script | public static function script($text, array $attributes = [], $type = 'text/javascript')
{
return static::openTag('script',
array_merge($attributes, ['type' => $type])).
' /*<![CDATA[*/ '.$text.' /*]]>*/ '.
static::closeTag('script');
} | php | public static function script($text, array $attributes = [], $type = 'text/javascript')
{
return static::openTag('script',
array_merge($attributes, ['type' => $type])).
' /*<![CDATA[*/ '.$text.' /*]]>*/ '.
static::closeTag('script');
} | [
"public",
"static",
"function",
"script",
"(",
"$",
"text",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"type",
"=",
"'text/javascript'",
")",
"{",
"return",
"static",
"::",
"openTag",
"(",
"'script'",
",",
"array_merge",
"(",
"$",
"attributes",
",",
"[",
"'type'",
"=>",
"$",
"type",
"]",
")",
")",
".",
"' /*<![CDATA[*/ '",
".",
"$",
"text",
".",
"' /*]]>*/ '",
".",
"static",
"::",
"closeTag",
"(",
"'script'",
")",
";",
"}"
] | Render script source
@access public
@param string $text script
@param array $attributes attributes tag
@param string $type type of script
@return string
@static | [
"Render",
"script",
"source"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/web/html/HeadTagTrait.php#L152-L158 | train |
hiqdev/minii-caching | src/TagDependency.php | TagDependency.generateDependencyData | protected function generateDependencyData($cache)
{
$timestamps = $this->getTimestamps($cache, (array) $this->tags);
$newKeys = [];
foreach ($timestamps as $key => $timestamp) {
if ($timestamp === false) {
$newKeys[] = $key;
}
}
if (!empty($newKeys)) {
$timestamps = array_merge($timestamps, $this->touchKeys($cache, $newKeys));
}
return $timestamps;
} | php | protected function generateDependencyData($cache)
{
$timestamps = $this->getTimestamps($cache, (array) $this->tags);
$newKeys = [];
foreach ($timestamps as $key => $timestamp) {
if ($timestamp === false) {
$newKeys[] = $key;
}
}
if (!empty($newKeys)) {
$timestamps = array_merge($timestamps, $this->touchKeys($cache, $newKeys));
}
return $timestamps;
} | [
"protected",
"function",
"generateDependencyData",
"(",
"$",
"cache",
")",
"{",
"$",
"timestamps",
"=",
"$",
"this",
"->",
"getTimestamps",
"(",
"$",
"cache",
",",
"(",
"array",
")",
"$",
"this",
"->",
"tags",
")",
";",
"$",
"newKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"timestamps",
"as",
"$",
"key",
"=>",
"$",
"timestamp",
")",
"{",
"if",
"(",
"$",
"timestamp",
"===",
"false",
")",
"{",
"$",
"newKeys",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"newKeys",
")",
")",
"{",
"$",
"timestamps",
"=",
"array_merge",
"(",
"$",
"timestamps",
",",
"$",
"this",
"->",
"touchKeys",
"(",
"$",
"cache",
",",
"$",
"newKeys",
")",
")",
";",
"}",
"return",
"$",
"timestamps",
";",
"}"
] | Generates the data needed to determine if dependency has been changed.
This method does nothing in this class.
@param Cache $cache the cache component that is currently evaluating this dependency
@return mixed the data needed to determine if dependency has been changed. | [
"Generates",
"the",
"data",
"needed",
"to",
"determine",
"if",
"dependency",
"has",
"been",
"changed",
".",
"This",
"method",
"does",
"nothing",
"in",
"this",
"class",
"."
] | 04c3f810a4af43b53855ee9c5e3ef6455080b538 | https://github.com/hiqdev/minii-caching/blob/04c3f810a4af43b53855ee9c5e3ef6455080b538/src/TagDependency.php#L32-L47 | train |
hiqdev/minii-caching | src/TagDependency.php | TagDependency.getHasChanged | public function getHasChanged($cache)
{
$timestamps = $this->getTimestamps($cache, (array) $this->tags);
return $timestamps !== $this->data;
} | php | public function getHasChanged($cache)
{
$timestamps = $this->getTimestamps($cache, (array) $this->tags);
return $timestamps !== $this->data;
} | [
"public",
"function",
"getHasChanged",
"(",
"$",
"cache",
")",
"{",
"$",
"timestamps",
"=",
"$",
"this",
"->",
"getTimestamps",
"(",
"$",
"cache",
",",
"(",
"array",
")",
"$",
"this",
"->",
"tags",
")",
";",
"return",
"$",
"timestamps",
"!==",
"$",
"this",
"->",
"data",
";",
"}"
] | Performs the actual dependency checking.
@param Cache $cache the cache component that is currently evaluating this dependency
@return boolean whether the dependency is changed or not. | [
"Performs",
"the",
"actual",
"dependency",
"checking",
"."
] | 04c3f810a4af43b53855ee9c5e3ef6455080b538 | https://github.com/hiqdev/minii-caching/blob/04c3f810a4af43b53855ee9c5e3ef6455080b538/src/TagDependency.php#L54-L58 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Frontend/Navigation.php | Navigation.CreateSubLevel | protected function CreateSubLevel(NavigationItem $parent)
{
$navigation = new self();
$navigation->isSubLevel = true;
$navigation->naviParent = $parent;
$navigation->SetTreeItem($this->tree, $this->item);
return $navigation;
} | php | protected function CreateSubLevel(NavigationItem $parent)
{
$navigation = new self();
$navigation->isSubLevel = true;
$navigation->naviParent = $parent;
$navigation->SetTreeItem($this->tree, $this->item);
return $navigation;
} | [
"protected",
"function",
"CreateSubLevel",
"(",
"NavigationItem",
"$",
"parent",
")",
"{",
"$",
"navigation",
"=",
"new",
"self",
"(",
")",
";",
"$",
"navigation",
"->",
"isSubLevel",
"=",
"true",
";",
"$",
"navigation",
"->",
"naviParent",
"=",
"$",
"parent",
";",
"$",
"navigation",
"->",
"SetTreeItem",
"(",
"$",
"this",
"->",
"tree",
",",
"$",
"this",
"->",
"item",
")",
";",
"return",
"$",
"navigation",
";",
"}"
] | Creates a navigation renderer for a sub level
@param NavigationItem $parent
@return Navigation | [
"Creates",
"a",
"navigation",
"renderer",
"for",
"a",
"sub",
"level"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Frontend/Navigation.php#L97-L104 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Frontend/Navigation.php | Navigation.IsActive | private function IsActive()
{
$pageItem = $this->naviItem->GetPageItem();
if (!$pageItem)
{
return false;
}
return $pageItem->GetPage()->Equals(PageRenderer::Page());
} | php | private function IsActive()
{
$pageItem = $this->naviItem->GetPageItem();
if (!$pageItem)
{
return false;
}
return $pageItem->GetPage()->Equals(PageRenderer::Page());
} | [
"private",
"function",
"IsActive",
"(",
")",
"{",
"$",
"pageItem",
"=",
"$",
"this",
"->",
"naviItem",
"->",
"GetPageItem",
"(",
")",
";",
"if",
"(",
"!",
"$",
"pageItem",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"pageItem",
"->",
"GetPage",
"(",
")",
"->",
"Equals",
"(",
"PageRenderer",
"::",
"Page",
"(",
")",
")",
";",
"}"
] | Returns true if the current item points to the current page
@return boolean | [
"Returns",
"true",
"if",
"the",
"current",
"item",
"points",
"to",
"the",
"current",
"page"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Frontend/Navigation.php#L149-L157 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Frontend/Navigation.php | Navigation.IsTrail | private function IsTrail()
{
$pageItem = $this->naviItem->GetPageItem();
if (!$pageItem)
{
return false;
}
$parent = PageRenderer::Page()->GetParent();
$itemPage = $pageItem->GetPage();
while ($parent)
{
if ($itemPage->Equals($parent))
{
return true;
}
$parent = $parent->GetParent();
}
return false;
} | php | private function IsTrail()
{
$pageItem = $this->naviItem->GetPageItem();
if (!$pageItem)
{
return false;
}
$parent = PageRenderer::Page()->GetParent();
$itemPage = $pageItem->GetPage();
while ($parent)
{
if ($itemPage->Equals($parent))
{
return true;
}
$parent = $parent->GetParent();
}
return false;
} | [
"private",
"function",
"IsTrail",
"(",
")",
"{",
"$",
"pageItem",
"=",
"$",
"this",
"->",
"naviItem",
"->",
"GetPageItem",
"(",
")",
";",
"if",
"(",
"!",
"$",
"pageItem",
")",
"{",
"return",
"false",
";",
"}",
"$",
"parent",
"=",
"PageRenderer",
"::",
"Page",
"(",
")",
"->",
"GetParent",
"(",
")",
";",
"$",
"itemPage",
"=",
"$",
"pageItem",
"->",
"GetPage",
"(",
")",
";",
"while",
"(",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"itemPage",
"->",
"Equals",
"(",
"$",
"parent",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"parent",
"=",
"$",
"parent",
"->",
"GetParent",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the current navigation item points to a parent of the current page
@return boolean Returns true if the current page is a child of the current item | [
"Checks",
"if",
"the",
"current",
"navigation",
"item",
"points",
"to",
"a",
"parent",
"of",
"the",
"current",
"page"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Frontend/Navigation.php#L163-L181 | train |
nirou8/php-multiple-saml | lib/Saml2/Response.php | OneLogin_Saml2_Response.validateTimestamps | public function validateTimestamps()
{
if ($this->encrypted) {
$document = $this->decryptedDocument;
} else {
$document = $this->document;
}
$timestampNodes = $document->getElementsByTagName('Conditions');
for ($i = 0; $i < $timestampNodes->length; $i++) {
$nbAttribute = $timestampNodes->item($i)->attributes->getNamedItem("NotBefore");
$naAttribute = $timestampNodes->item($i)->attributes->getNamedItem("NotOnOrAfter");
if ($nbAttribute && OneLogin_SAML2_Utils::parseSAML2Time($nbAttribute->textContent) > time() + OneLogin_Saml2_Constants::ALLOWED_CLOCK_DRIFT) {
throw new OneLogin_Saml2_ValidationError(
'Could not validate timestamp: not yet valid. Check system clock.',
OneLogin_Saml2_ValidationError::ASSERTION_TOO_EARLY
);
}
if ($naAttribute && OneLogin_SAML2_Utils::parseSAML2Time($naAttribute->textContent) + OneLogin_Saml2_Constants::ALLOWED_CLOCK_DRIFT <= time()) {
throw new OneLogin_Saml2_ValidationError(
'Could not validate timestamp: expired. Check system clock.',
OneLogin_Saml2_ValidationError::ASSERTION_EXPIRED
);
}
}
return true;
} | php | public function validateTimestamps()
{
if ($this->encrypted) {
$document = $this->decryptedDocument;
} else {
$document = $this->document;
}
$timestampNodes = $document->getElementsByTagName('Conditions');
for ($i = 0; $i < $timestampNodes->length; $i++) {
$nbAttribute = $timestampNodes->item($i)->attributes->getNamedItem("NotBefore");
$naAttribute = $timestampNodes->item($i)->attributes->getNamedItem("NotOnOrAfter");
if ($nbAttribute && OneLogin_SAML2_Utils::parseSAML2Time($nbAttribute->textContent) > time() + OneLogin_Saml2_Constants::ALLOWED_CLOCK_DRIFT) {
throw new OneLogin_Saml2_ValidationError(
'Could not validate timestamp: not yet valid. Check system clock.',
OneLogin_Saml2_ValidationError::ASSERTION_TOO_EARLY
);
}
if ($naAttribute && OneLogin_SAML2_Utils::parseSAML2Time($naAttribute->textContent) + OneLogin_Saml2_Constants::ALLOWED_CLOCK_DRIFT <= time()) {
throw new OneLogin_Saml2_ValidationError(
'Could not validate timestamp: expired. Check system clock.',
OneLogin_Saml2_ValidationError::ASSERTION_EXPIRED
);
}
}
return true;
} | [
"public",
"function",
"validateTimestamps",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"encrypted",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"decryptedDocument",
";",
"}",
"else",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"document",
";",
"}",
"$",
"timestampNodes",
"=",
"$",
"document",
"->",
"getElementsByTagName",
"(",
"'Conditions'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"timestampNodes",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"nbAttribute",
"=",
"$",
"timestampNodes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"\"NotBefore\"",
")",
";",
"$",
"naAttribute",
"=",
"$",
"timestampNodes",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"\"NotOnOrAfter\"",
")",
";",
"if",
"(",
"$",
"nbAttribute",
"&&",
"OneLogin_SAML2_Utils",
"::",
"parseSAML2Time",
"(",
"$",
"nbAttribute",
"->",
"textContent",
")",
">",
"time",
"(",
")",
"+",
"OneLogin_Saml2_Constants",
"::",
"ALLOWED_CLOCK_DRIFT",
")",
"{",
"throw",
"new",
"OneLogin_Saml2_ValidationError",
"(",
"'Could not validate timestamp: not yet valid. Check system clock.'",
",",
"OneLogin_Saml2_ValidationError",
"::",
"ASSERTION_TOO_EARLY",
")",
";",
"}",
"if",
"(",
"$",
"naAttribute",
"&&",
"OneLogin_SAML2_Utils",
"::",
"parseSAML2Time",
"(",
"$",
"naAttribute",
"->",
"textContent",
")",
"+",
"OneLogin_Saml2_Constants",
"::",
"ALLOWED_CLOCK_DRIFT",
"<=",
"time",
"(",
")",
")",
"{",
"throw",
"new",
"OneLogin_Saml2_ValidationError",
"(",
"'Could not validate timestamp: expired. Check system clock.'",
",",
"OneLogin_Saml2_ValidationError",
"::",
"ASSERTION_EXPIRED",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Verifies that the document is still valid according Conditions Element.
@return bool | [
"Verifies",
"that",
"the",
"document",
"is",
"still",
"valid",
"according",
"Conditions",
"Element",
"."
] | 7eb5786e678db7d45459ce3441fa187946ae9a3b | https://github.com/nirou8/php-multiple-saml/blob/7eb5786e678db7d45459ce3441fa187946ae9a3b/lib/Saml2/Response.php#L875-L901 | train |
rawphp/RawMigrator | lib/commands/MigrateCommand.php | MigrateCommand.execute | public function execute( )
{
$this->doAction( self::ON_BEFORE_MIGRATE_CMD_EXECUTE_ACTION );
if ( NULL === $this->migrator )
{
throw new MigrationException( 'You must set the migrator before executing this command.' );
}
$verbose = self::getOption( $this, 'verbose' )->value;
$direction = self::getOption( $this, 'direction' )->value;
$levels = self::getOption( $this, 'levels' )->value;
$this->migrator->verbose = $verbose;
switch( $direction )
{
case 'up':
$this->migrator->migrateUp( $levels );
break;
case 'down':
$this->migrator->migrateDown( $levels );
break;
default:
// do nothing
break;
}
$this->doAction( self::ON_AFTER_MIGRATE_CMD_EXECUTE_ACTION );
} | php | public function execute( )
{
$this->doAction( self::ON_BEFORE_MIGRATE_CMD_EXECUTE_ACTION );
if ( NULL === $this->migrator )
{
throw new MigrationException( 'You must set the migrator before executing this command.' );
}
$verbose = self::getOption( $this, 'verbose' )->value;
$direction = self::getOption( $this, 'direction' )->value;
$levels = self::getOption( $this, 'levels' )->value;
$this->migrator->verbose = $verbose;
switch( $direction )
{
case 'up':
$this->migrator->migrateUp( $levels );
break;
case 'down':
$this->migrator->migrateDown( $levels );
break;
default:
// do nothing
break;
}
$this->doAction( self::ON_AFTER_MIGRATE_CMD_EXECUTE_ACTION );
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_BEFORE_MIGRATE_CMD_EXECUTE_ACTION",
")",
";",
"if",
"(",
"NULL",
"===",
"$",
"this",
"->",
"migrator",
")",
"{",
"throw",
"new",
"MigrationException",
"(",
"'You must set the migrator before executing this command.'",
")",
";",
"}",
"$",
"verbose",
"=",
"self",
"::",
"getOption",
"(",
"$",
"this",
",",
"'verbose'",
")",
"->",
"value",
";",
"$",
"direction",
"=",
"self",
"::",
"getOption",
"(",
"$",
"this",
",",
"'direction'",
")",
"->",
"value",
";",
"$",
"levels",
"=",
"self",
"::",
"getOption",
"(",
"$",
"this",
",",
"'levels'",
")",
"->",
"value",
";",
"$",
"this",
"->",
"migrator",
"->",
"verbose",
"=",
"$",
"verbose",
";",
"switch",
"(",
"$",
"direction",
")",
"{",
"case",
"'up'",
":",
"$",
"this",
"->",
"migrator",
"->",
"migrateUp",
"(",
"$",
"levels",
")",
";",
"break",
";",
"case",
"'down'",
":",
"$",
"this",
"->",
"migrator",
"->",
"migrateDown",
"(",
"$",
"levels",
")",
";",
"break",
";",
"default",
":",
"// do nothing",
"break",
";",
"}",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_AFTER_MIGRATE_CMD_EXECUTE_ACTION",
")",
";",
"}"
] | Executes the command action.
@action ON_BEFORE_MIGRATE_CMD_EXECUTE_ACTION
@action ON_AFTER_MIGRATE_CMD_EXECUTE_ACTION
@throws MigrationException if the migrator hasn't been set | [
"Executes",
"the",
"command",
"action",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/commands/MigrateCommand.php#L111-L143 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/pclasses/storage.intf.php | PCStorage.addPClass | public function addPClass($pclass)
{
if (! $pclass instanceof KlarnaPClass) {
throw new Klarna_InvalidTypeException('pclass', 'KlarnaPClass');
}
if (!isset($this->pclasses) || !is_array($this->pclasses)) {
$this->pclasses = array();
}
if ($pclass->getDescription() === null || $pclass->getType() === null) {
//Something went wrong, do not save these!
return;
}
if (!isset($this->pclasses[$pclass->getEid()])) {
$this->pclasses[$pclass->getEid()] = array();
}
$this->pclasses[$pclass->getEid()][$pclass->getId()] = $pclass;
} | php | public function addPClass($pclass)
{
if (! $pclass instanceof KlarnaPClass) {
throw new Klarna_InvalidTypeException('pclass', 'KlarnaPClass');
}
if (!isset($this->pclasses) || !is_array($this->pclasses)) {
$this->pclasses = array();
}
if ($pclass->getDescription() === null || $pclass->getType() === null) {
//Something went wrong, do not save these!
return;
}
if (!isset($this->pclasses[$pclass->getEid()])) {
$this->pclasses[$pclass->getEid()] = array();
}
$this->pclasses[$pclass->getEid()][$pclass->getId()] = $pclass;
} | [
"public",
"function",
"addPClass",
"(",
"$",
"pclass",
")",
"{",
"if",
"(",
"!",
"$",
"pclass",
"instanceof",
"KlarnaPClass",
")",
"{",
"throw",
"new",
"Klarna_InvalidTypeException",
"(",
"'pclass'",
",",
"'KlarnaPClass'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"pclasses",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"pclasses",
")",
")",
"{",
"$",
"this",
"->",
"pclasses",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"pclass",
"->",
"getDescription",
"(",
")",
"===",
"null",
"||",
"$",
"pclass",
"->",
"getType",
"(",
")",
"===",
"null",
")",
"{",
"//Something went wrong, do not save these!",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"pclass",
"->",
"getEid",
"(",
")",
"]",
")",
")",
"{",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"pclass",
"->",
"getEid",
"(",
")",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"pclass",
"->",
"getEid",
"(",
")",
"]",
"[",
"$",
"pclass",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"pclass",
";",
"}"
] | Adds a PClass to the storage.
@param KlarnaPClass $pclass PClass object.
@throws KlarnaException
@return void | [
"Adds",
"a",
"PClass",
"to",
"the",
"storage",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/storage.intf.php#L53-L72 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/pclasses/storage.intf.php | PCStorage.getPClass | public function getPClass($id, $eid, $country)
{
if (!is_int($id)) {
throw new InvalidArgumentException('Supplied ID is not an integer!');
}
if (!is_array($this->pclasses)) {
throw new Klarna_PClassException('No match for that eid!');
}
if (!isset($this->pclasses[$eid]) || !is_array($this->pclasses[$eid])) {
throw new Klarna_PClassException('No match for that eid!');
}
if (!isset($this->pclasses[$eid][$id])
|| !$this->pclasses[$eid][$id]->isValid()
) {
throw new Klarna_PClassException('No such pclass available!');
}
if ($this->pclasses[$eid][$id]->getCountry() !== $country) {
throw new Klarna_PClassException(
'You cannot use this pclass with set country!'
);
}
return $this->pclasses[$eid][$id];
} | php | public function getPClass($id, $eid, $country)
{
if (!is_int($id)) {
throw new InvalidArgumentException('Supplied ID is not an integer!');
}
if (!is_array($this->pclasses)) {
throw new Klarna_PClassException('No match for that eid!');
}
if (!isset($this->pclasses[$eid]) || !is_array($this->pclasses[$eid])) {
throw new Klarna_PClassException('No match for that eid!');
}
if (!isset($this->pclasses[$eid][$id])
|| !$this->pclasses[$eid][$id]->isValid()
) {
throw new Klarna_PClassException('No such pclass available!');
}
if ($this->pclasses[$eid][$id]->getCountry() !== $country) {
throw new Klarna_PClassException(
'You cannot use this pclass with set country!'
);
}
return $this->pclasses[$eid][$id];
} | [
"public",
"function",
"getPClass",
"(",
"$",
"id",
",",
"$",
"eid",
",",
"$",
"country",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Supplied ID is not an integer!'",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"pclasses",
")",
")",
"{",
"throw",
"new",
"Klarna_PClassException",
"(",
"'No match for that eid!'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"eid",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"eid",
"]",
")",
")",
"{",
"throw",
"new",
"Klarna_PClassException",
"(",
"'No match for that eid!'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"eid",
"]",
"[",
"$",
"id",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"eid",
"]",
"[",
"$",
"id",
"]",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"Klarna_PClassException",
"(",
"'No such pclass available!'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"eid",
"]",
"[",
"$",
"id",
"]",
"->",
"getCountry",
"(",
")",
"!==",
"$",
"country",
")",
"{",
"throw",
"new",
"Klarna_PClassException",
"(",
"'You cannot use this pclass with set country!'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pclasses",
"[",
"$",
"eid",
"]",
"[",
"$",
"id",
"]",
";",
"}"
] | Gets the PClass by ID.
@param int $id PClass ID.
@param int $eid Merchant ID.
@param int $country {@link KlarnaCountry Country} constant.
@throws KlarnaException
@return KlarnaPClass | [
"Gets",
"the",
"PClass",
"by",
"ID",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/storage.intf.php#L84-L111 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/pclasses/storage.intf.php | PCStorage.getPClasses | public function getPClasses($eid, $country, $type = null)
{
if (!is_int($country)) {
throw new Klarna_ArgumentNotSetException('country');
}
$tmp = false;
if (!is_array($this->pclasses)) {
return;
}
$tmp = array();
foreach ($this->pclasses as $eid => $pclasses) {
$tmp[$eid] = array();
foreach ($pclasses as $pclass) {
if (!$pclass->isValid()) {
continue; //Pclass invalid, skip it.
}
if ($pclass->getEid() === $eid
&& $pclass->getCountry() === $country
&& ($pclass->getType() === $type || $type === null)
) {
$tmp[$eid][$pclass->getId()] = $pclass;
}
}
}
return $tmp;
} | php | public function getPClasses($eid, $country, $type = null)
{
if (!is_int($country)) {
throw new Klarna_ArgumentNotSetException('country');
}
$tmp = false;
if (!is_array($this->pclasses)) {
return;
}
$tmp = array();
foreach ($this->pclasses as $eid => $pclasses) {
$tmp[$eid] = array();
foreach ($pclasses as $pclass) {
if (!$pclass->isValid()) {
continue; //Pclass invalid, skip it.
}
if ($pclass->getEid() === $eid
&& $pclass->getCountry() === $country
&& ($pclass->getType() === $type || $type === null)
) {
$tmp[$eid][$pclass->getId()] = $pclass;
}
}
}
return $tmp;
} | [
"public",
"function",
"getPClasses",
"(",
"$",
"eid",
",",
"$",
"country",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"country",
")",
")",
"{",
"throw",
"new",
"Klarna_ArgumentNotSetException",
"(",
"'country'",
")",
";",
"}",
"$",
"tmp",
"=",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"pclasses",
")",
")",
"{",
"return",
";",
"}",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"pclasses",
"as",
"$",
"eid",
"=>",
"$",
"pclasses",
")",
"{",
"$",
"tmp",
"[",
"$",
"eid",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"pclasses",
"as",
"$",
"pclass",
")",
"{",
"if",
"(",
"!",
"$",
"pclass",
"->",
"isValid",
"(",
")",
")",
"{",
"continue",
";",
"//Pclass invalid, skip it.",
"}",
"if",
"(",
"$",
"pclass",
"->",
"getEid",
"(",
")",
"===",
"$",
"eid",
"&&",
"$",
"pclass",
"->",
"getCountry",
"(",
")",
"===",
"$",
"country",
"&&",
"(",
"$",
"pclass",
"->",
"getType",
"(",
")",
"===",
"$",
"type",
"||",
"$",
"type",
"===",
"null",
")",
")",
"{",
"$",
"tmp",
"[",
"$",
"eid",
"]",
"[",
"$",
"pclass",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"pclass",
";",
"}",
"}",
"}",
"return",
"$",
"tmp",
";",
"}"
] | Returns an array of KlarnaPClasses, keyed with pclass ID.
If type is specified, only that type will be returned.
<b>Types available</b>:<br>
{@link KlarnaPClass::ACCOUNT}<br>
{@link KlarnaPClass::CAMPAIGN}<br>
{@link KlarnaPClass::SPECIAL}<br>
{@link KlarnaPClass::DELAY}<br>
{@link KlarnaPClass::MOBILE}<br>
@param int $eid Merchant ID.
@param int $country {@link KlarnaCountry Country} constant.
@param int $type PClass type identifier.
@throws KlarnaException
@return array An array of {@link KlarnaPClass PClasses}. | [
"Returns",
"an",
"array",
"of",
"KlarnaPClasses",
"keyed",
"with",
"pclass",
"ID",
".",
"If",
"type",
"is",
"specified",
"only",
"that",
"type",
"will",
"be",
"returned",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/storage.intf.php#L131-L160 | train |
Raphhh/puppy-application | src/Controller/AppController.php | AppController.render | public function render($templateFile, array $vars = [])
{
$this->getService('retriever')->setLocalVars($vars);
return $this->getService('template')->render($templateFile, $vars);
} | php | public function render($templateFile, array $vars = [])
{
$this->getService('retriever')->setLocalVars($vars);
return $this->getService('template')->render($templateFile, $vars);
} | [
"public",
"function",
"render",
"(",
"$",
"templateFile",
",",
"array",
"$",
"vars",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"getService",
"(",
"'retriever'",
")",
"->",
"setLocalVars",
"(",
"$",
"vars",
")",
";",
"return",
"$",
"this",
"->",
"getService",
"(",
"'template'",
")",
"->",
"render",
"(",
"$",
"templateFile",
",",
"$",
"vars",
")",
";",
"}"
] | renders a template.
uses template service.
@param string $templateFile
@param array $vars
@return mixed | [
"renders",
"a",
"template",
".",
"uses",
"template",
"service",
"."
] | 9291543cd28e19a2986abd7fb146898ca5f5f5da | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Controller/AppController.php#L39-L43 | train |
Raphhh/puppy-application | src/Controller/AppController.php | AppController.retrieve | public function retrieve($key, $default = '')
{
$retriever = $this->getService('retriever');
if($retriever->has($key)){
return $retriever->get($key);
}
return $default;
} | php | public function retrieve($key, $default = '')
{
$retriever = $this->getService('retriever');
if($retriever->has($key)){
return $retriever->get($key);
}
return $default;
} | [
"public",
"function",
"retrieve",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"''",
")",
"{",
"$",
"retriever",
"=",
"$",
"this",
"->",
"getService",
"(",
"'retriever'",
")",
";",
"if",
"(",
"$",
"retriever",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"retriever",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | retrieves a param from
- the matches of the uri
- the request
- the flash
@param string $key
@param string $default
@return string | [
"retrieves",
"a",
"param",
"from",
"-",
"the",
"matches",
"of",
"the",
"uri",
"-",
"the",
"request",
"-",
"the",
"flash"
] | 9291543cd28e19a2986abd7fb146898ca5f5f5da | https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Controller/AppController.php#L132-L139 | train |
agentmedia/phine-core | src/Core/Logic/Util/ClassFinder.php | ClassFinder.ModuleClass | static function ModuleClass($type, ModuleLocation $location)
{
$parts = \explode(self::$bundleModuleSeparator, $type);
if (count($parts) != 2)
{
throw new \InvalidArgumentException('Module type string must be in the format <bundle>-<module>');
}
$bundle = $parts[0];
$module = $parts[1];
$folderLocation = $location->Value();
return self::BundleNamespace($bundle) . "\\Modules\\$folderLocation\\$module";
} | php | static function ModuleClass($type, ModuleLocation $location)
{
$parts = \explode(self::$bundleModuleSeparator, $type);
if (count($parts) != 2)
{
throw new \InvalidArgumentException('Module type string must be in the format <bundle>-<module>');
}
$bundle = $parts[0];
$module = $parts[1];
$folderLocation = $location->Value();
return self::BundleNamespace($bundle) . "\\Modules\\$folderLocation\\$module";
} | [
"static",
"function",
"ModuleClass",
"(",
"$",
"type",
",",
"ModuleLocation",
"$",
"location",
")",
"{",
"$",
"parts",
"=",
"\\",
"explode",
"(",
"self",
"::",
"$",
"bundleModuleSeparator",
",",
"$",
"type",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"!=",
"2",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Module type string must be in the format <bundle>-<module>'",
")",
";",
"}",
"$",
"bundle",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"module",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"$",
"folderLocation",
"=",
"$",
"location",
"->",
"Value",
"(",
")",
";",
"return",
"self",
"::",
"BundleNamespace",
"(",
"$",
"bundle",
")",
".",
"\"\\\\Modules\\\\$folderLocation\\\\$module\"",
";",
"}"
] | Gets the class name by type string and module loation
@param string $type The (simplified) type string
@param ModuleLocation $location The location; either Backend or Frontend
@return string Returns the class name associated with the type string
@throws \InvalidArgumentException Raises exception if type has incorrect format | [
"Gets",
"the",
"class",
"name",
"by",
"type",
"string",
"and",
"module",
"loation"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/ClassFinder.php#L50-L61 | train |
agentmedia/phine-core | src/Core/Logic/Util/ClassFinder.php | ClassFinder.CreateModule | static function CreateModule($type, ModuleLocation $location)
{
$class = self::ModuleClass($type, $location);
if (!class_exists($class))
{
return null;
}
return new $class();
} | php | static function CreateModule($type, ModuleLocation $location)
{
$class = self::ModuleClass($type, $location);
if (!class_exists($class))
{
return null;
}
return new $class();
} | [
"static",
"function",
"CreateModule",
"(",
"$",
"type",
",",
"ModuleLocation",
"$",
"location",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"ModuleClass",
"(",
"$",
"type",
",",
"$",
"location",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}"
] | Finds the module associated with the given type and returns an instance
@param string $type The module type
@param ModuleLocation $location The location; either backend or frontend
@return ModuleBase | [
"Finds",
"the",
"module",
"associated",
"with",
"the",
"given",
"type",
"and",
"returns",
"an",
"instance"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/ClassFinder.php#L69-L77 | train |
agentmedia/phine-core | src/Core/Logic/Util/ClassFinder.php | ClassFinder.BackendNavModules | static function BackendNavModules()
{
$result = array();
$allBundles = PathUtil::Bundles();
//force Core to appear first
$coreKey = array_search('Core', $allBundles);
unset($allBundles[$coreKey]);
array_unshift($allBundles, 'Core');
$bundles = array_values($allBundles);
foreach ($bundles as $bundle)
{
$modules = PathUtil::BackendModules($bundle);
foreach ($modules as $module)
{
$type = self::CalcModuleType($bundle, $module);
$instance = self::CreateBackendModule($type);
if (!($instance instanceof BackendModule))
{
continue;
}
if ($instance->SideNavIndex() >= 0 &&
BackendModule::Guard()->Allow(BackendAction::Read(), $instance))
{
self::AddBackendNavModule($result, $instance);
}
}
}
return self::SortByNavIndex($result);
} | php | static function BackendNavModules()
{
$result = array();
$allBundles = PathUtil::Bundles();
//force Core to appear first
$coreKey = array_search('Core', $allBundles);
unset($allBundles[$coreKey]);
array_unshift($allBundles, 'Core');
$bundles = array_values($allBundles);
foreach ($bundles as $bundle)
{
$modules = PathUtil::BackendModules($bundle);
foreach ($modules as $module)
{
$type = self::CalcModuleType($bundle, $module);
$instance = self::CreateBackendModule($type);
if (!($instance instanceof BackendModule))
{
continue;
}
if ($instance->SideNavIndex() >= 0 &&
BackendModule::Guard()->Allow(BackendAction::Read(), $instance))
{
self::AddBackendNavModule($result, $instance);
}
}
}
return self::SortByNavIndex($result);
} | [
"static",
"function",
"BackendNavModules",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"allBundles",
"=",
"PathUtil",
"::",
"Bundles",
"(",
")",
";",
"//force Core to appear first",
"$",
"coreKey",
"=",
"array_search",
"(",
"'Core'",
",",
"$",
"allBundles",
")",
";",
"unset",
"(",
"$",
"allBundles",
"[",
"$",
"coreKey",
"]",
")",
";",
"array_unshift",
"(",
"$",
"allBundles",
",",
"'Core'",
")",
";",
"$",
"bundles",
"=",
"array_values",
"(",
"$",
"allBundles",
")",
";",
"foreach",
"(",
"$",
"bundles",
"as",
"$",
"bundle",
")",
"{",
"$",
"modules",
"=",
"PathUtil",
"::",
"BackendModules",
"(",
"$",
"bundle",
")",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"type",
"=",
"self",
"::",
"CalcModuleType",
"(",
"$",
"bundle",
",",
"$",
"module",
")",
";",
"$",
"instance",
"=",
"self",
"::",
"CreateBackendModule",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"(",
"$",
"instance",
"instanceof",
"BackendModule",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"instance",
"->",
"SideNavIndex",
"(",
")",
">=",
"0",
"&&",
"BackendModule",
"::",
"Guard",
"(",
")",
"->",
"Allow",
"(",
"BackendAction",
"::",
"Read",
"(",
")",
",",
"$",
"instance",
")",
")",
"{",
"self",
"::",
"AddBackendNavModule",
"(",
"$",
"result",
",",
"$",
"instance",
")",
";",
"}",
"}",
"}",
"return",
"self",
"::",
"SortByNavIndex",
"(",
"$",
"result",
")",
";",
"}"
] | The modules for the backend navigation
@return Returns an array with bundle names as keys and backend modules as list | [
"The",
"modules",
"for",
"the",
"backend",
"navigation"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/ClassFinder.php#L135-L167 | train |
agentmedia/phine-core | src/Core/Logic/Util/ClassFinder.php | ClassFinder.SortByNavIndex | private static function SortByNavIndex(array &$result)
{
$sorted = array();
foreach ($result as $bundle=>$modules)
{
ksort($modules);
$sorted[$bundle] = $modules;
}
return $sorted;
} | php | private static function SortByNavIndex(array &$result)
{
$sorted = array();
foreach ($result as $bundle=>$modules)
{
ksort($modules);
$sorted[$bundle] = $modules;
}
return $sorted;
} | [
"private",
"static",
"function",
"SortByNavIndex",
"(",
"array",
"&",
"$",
"result",
")",
"{",
"$",
"sorted",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"bundle",
"=>",
"$",
"modules",
")",
"{",
"ksort",
"(",
"$",
"modules",
")",
";",
"$",
"sorted",
"[",
"$",
"bundle",
"]",
"=",
"$",
"modules",
";",
"}",
"return",
"$",
"sorted",
";",
"}"
] | Sorts the the navigation items by index | [
"Sorts",
"the",
"the",
"navigation",
"items",
"by",
"index"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/ClassFinder.php#L172-L181 | train |
agentmedia/phine-core | src/Core/Logic/Util/ClassFinder.php | ClassFinder.AddBackendNavModule | private static function AddBackendNavModule(array &$result, BackendModule $module)
{
$bundle = $module->MyBundle();
if (!isset($result[$bundle]))
{
$result[$bundle] = array();
}
$result[$bundle][$module->SideNavIndex()] = $module;
} | php | private static function AddBackendNavModule(array &$result, BackendModule $module)
{
$bundle = $module->MyBundle();
if (!isset($result[$bundle]))
{
$result[$bundle] = array();
}
$result[$bundle][$module->SideNavIndex()] = $module;
} | [
"private",
"static",
"function",
"AddBackendNavModule",
"(",
"array",
"&",
"$",
"result",
",",
"BackendModule",
"$",
"module",
")",
"{",
"$",
"bundle",
"=",
"$",
"module",
"->",
"MyBundle",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"bundle",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"bundle",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"result",
"[",
"$",
"bundle",
"]",
"[",
"$",
"module",
"->",
"SideNavIndex",
"(",
")",
"]",
"=",
"$",
"module",
";",
"}"
] | Adds the module to the side navigation
@param array &$result The resulting array
@param BackendModule $module The backend module | [
"Adds",
"the",
"module",
"to",
"the",
"side",
"navigation"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/ClassFinder.php#L188-L196 | train |
Kris-Kuiper/sFire-Framework | src/Schedule/Schedule.php | Schedule.run | public function run() {
//Check if the function exec is enabled
if(false === function_exists('exec')) {
return trigger_error('Function "exec" is not enabled', E_USER_ERROR);
}
//Check if schedules folder is readable
if(false === is_readable(Path :: get('schedule'))) {
return trigger_error(printf('Could not read schedule folder "%s"', Path :: get('schedule')));
}
//Check if schedule cache folder is writable
if(false === is_writable(Path :: get('log-schedule'))) {
return trigger_error(printf('Could not write schedule cache folder "%s"', Path :: get('log-schedules')));
}
//Get all schedules from schedules folder
$schedules = glob(Path :: get('schedule') . Application :: get(['prefix', 'schedule']) . '*.php');
//For all the schedules classes; run the script
foreach($schedules as $schedule) {
//Remove path
$schedule = preg_replace('#^'. Path :: get('schedule') .'#', '', $schedule);
//Remove prefix
$schedule = preg_replace('#^'. Application :: get(['prefix', 'schedule']) .'#', '', $schedule);
//Remove extension
$schedule = preg_replace('#.php$#', '', $schedule);
//Execute schedule
$this -> exec(sprintf('%s %s %s', $this -> path, getcwd() . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_FILENAME'], $schedule), true);
}
} | php | public function run() {
//Check if the function exec is enabled
if(false === function_exists('exec')) {
return trigger_error('Function "exec" is not enabled', E_USER_ERROR);
}
//Check if schedules folder is readable
if(false === is_readable(Path :: get('schedule'))) {
return trigger_error(printf('Could not read schedule folder "%s"', Path :: get('schedule')));
}
//Check if schedule cache folder is writable
if(false === is_writable(Path :: get('log-schedule'))) {
return trigger_error(printf('Could not write schedule cache folder "%s"', Path :: get('log-schedules')));
}
//Get all schedules from schedules folder
$schedules = glob(Path :: get('schedule') . Application :: get(['prefix', 'schedule']) . '*.php');
//For all the schedules classes; run the script
foreach($schedules as $schedule) {
//Remove path
$schedule = preg_replace('#^'. Path :: get('schedule') .'#', '', $schedule);
//Remove prefix
$schedule = preg_replace('#^'. Application :: get(['prefix', 'schedule']) .'#', '', $schedule);
//Remove extension
$schedule = preg_replace('#.php$#', '', $schedule);
//Execute schedule
$this -> exec(sprintf('%s %s %s', $this -> path, getcwd() . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_FILENAME'], $schedule), true);
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"//Check if the function exec is enabled\r",
"if",
"(",
"false",
"===",
"function_exists",
"(",
"'exec'",
")",
")",
"{",
"return",
"trigger_error",
"(",
"'Function \"exec\" is not enabled'",
",",
"E_USER_ERROR",
")",
";",
"}",
"//Check if schedules folder is readable\r",
"if",
"(",
"false",
"===",
"is_readable",
"(",
"Path",
"::",
"get",
"(",
"'schedule'",
")",
")",
")",
"{",
"return",
"trigger_error",
"(",
"printf",
"(",
"'Could not read schedule folder \"%s\"'",
",",
"Path",
"::",
"get",
"(",
"'schedule'",
")",
")",
")",
";",
"}",
"//Check if schedule cache folder is writable\r",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"Path",
"::",
"get",
"(",
"'log-schedule'",
")",
")",
")",
"{",
"return",
"trigger_error",
"(",
"printf",
"(",
"'Could not write schedule cache folder \"%s\"'",
",",
"Path",
"::",
"get",
"(",
"'log-schedules'",
")",
")",
")",
";",
"}",
"//Get all schedules from schedules folder\r",
"$",
"schedules",
"=",
"glob",
"(",
"Path",
"::",
"get",
"(",
"'schedule'",
")",
".",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'schedule'",
"]",
")",
".",
"'*.php'",
")",
";",
"//For all the schedules classes; run the script\r",
"foreach",
"(",
"$",
"schedules",
"as",
"$",
"schedule",
")",
"{",
"//Remove path\r",
"$",
"schedule",
"=",
"preg_replace",
"(",
"'#^'",
".",
"Path",
"::",
"get",
"(",
"'schedule'",
")",
".",
"'#'",
",",
"''",
",",
"$",
"schedule",
")",
";",
"//Remove prefix\r",
"$",
"schedule",
"=",
"preg_replace",
"(",
"'#^'",
".",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'schedule'",
"]",
")",
".",
"'#'",
",",
"''",
",",
"$",
"schedule",
")",
";",
"//Remove extension\r",
"$",
"schedule",
"=",
"preg_replace",
"(",
"'#.php$#'",
",",
"''",
",",
"$",
"schedule",
")",
";",
"//Execute schedule\r",
"$",
"this",
"->",
"exec",
"(",
"sprintf",
"(",
"'%s %s %s'",
",",
"$",
"this",
"->",
"path",
",",
"getcwd",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"_SERVER",
"[",
"'SCRIPT_FILENAME'",
"]",
",",
"$",
"schedule",
")",
",",
"true",
")",
";",
"}",
"}"
] | Iterate over all schedule files and execute tasks | [
"Iterate",
"over",
"all",
"schedule",
"files",
"and",
"execute",
"tasks"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Schedule/Schedule.php#L53-L88 | train |
Kris-Kuiper/sFire-Framework | src/Schedule/Schedule.php | Schedule.task | public function task($script) {
if(false === is_string($script)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($script)), E_USER_ERROR);
}
$script = sprintf('%s%s%s.php', Path :: get('schedule'), Application :: get(['prefix', 'schedule']), NameConvert :: toCamelcase($script, true));
//Check if script is readable
if(false === is_readable($script)) {
return trigger_error(sprintf('Script "%s" is not a readable Schedule file', (string) $script));
}
//Include script
require_once($script);
//Create new instance
$file = new File($script);
$classname = $file -> entity() -> getName();
$class = new $classname();
//Check if needed constants are defined
foreach(['TIME', 'ENABLED'] as $constant) {
if(false === defined($classname . '::' . $constant)) {
return trigger_error(sprintf('Missing constant "%s" in Schedule "%s" class', $constant, $classname));
}
}
//Check if schedule has start method
if(false === is_callable([$class, 'start'])) {
return trigger_error(sprintf('Missing methode start in Schedule "%s" class', $classname));
}
//If the current schedule is enabled
if(true === $class :: ENABLED) {
$run = $this -> checkRun($class :: TIME);
if(true === $run) {
ob_start();
//Capture return ouput
$data = [];
$data[$classname]['start'] = date('Y-m-d H:i:s');
$data[$classname]['return'] = (string) $class -> start();
$data[$classname]['echo'] = ob_get_clean();
$data[$classname]['end'] = date('Y-m-d H:i:s');
//Check if the current schedule has the complete method
if(true === is_callable([$class, 'complete'])) {
$class -> complete($data[$classname]);
}
//Write to log
$logger = $this -> getLogger();
$logger -> setDirectory(Path :: get('log-schedule'));
$logger -> write(json_encode($data));
}
}
} | php | public function task($script) {
if(false === is_string($script)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($script)), E_USER_ERROR);
}
$script = sprintf('%s%s%s.php', Path :: get('schedule'), Application :: get(['prefix', 'schedule']), NameConvert :: toCamelcase($script, true));
//Check if script is readable
if(false === is_readable($script)) {
return trigger_error(sprintf('Script "%s" is not a readable Schedule file', (string) $script));
}
//Include script
require_once($script);
//Create new instance
$file = new File($script);
$classname = $file -> entity() -> getName();
$class = new $classname();
//Check if needed constants are defined
foreach(['TIME', 'ENABLED'] as $constant) {
if(false === defined($classname . '::' . $constant)) {
return trigger_error(sprintf('Missing constant "%s" in Schedule "%s" class', $constant, $classname));
}
}
//Check if schedule has start method
if(false === is_callable([$class, 'start'])) {
return trigger_error(sprintf('Missing methode start in Schedule "%s" class', $classname));
}
//If the current schedule is enabled
if(true === $class :: ENABLED) {
$run = $this -> checkRun($class :: TIME);
if(true === $run) {
ob_start();
//Capture return ouput
$data = [];
$data[$classname]['start'] = date('Y-m-d H:i:s');
$data[$classname]['return'] = (string) $class -> start();
$data[$classname]['echo'] = ob_get_clean();
$data[$classname]['end'] = date('Y-m-d H:i:s');
//Check if the current schedule has the complete method
if(true === is_callable([$class, 'complete'])) {
$class -> complete($data[$classname]);
}
//Write to log
$logger = $this -> getLogger();
$logger -> setDirectory(Path :: get('log-schedule'));
$logger -> write(json_encode($data));
}
}
} | [
"public",
"function",
"task",
"(",
"$",
"script",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"script",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"script",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"script",
"=",
"sprintf",
"(",
"'%s%s%s.php'",
",",
"Path",
"::",
"get",
"(",
"'schedule'",
")",
",",
"Application",
"::",
"get",
"(",
"[",
"'prefix'",
",",
"'schedule'",
"]",
")",
",",
"NameConvert",
"::",
"toCamelcase",
"(",
"$",
"script",
",",
"true",
")",
")",
";",
"//Check if script is readable\r",
"if",
"(",
"false",
"===",
"is_readable",
"(",
"$",
"script",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Script \"%s\" is not a readable Schedule file'",
",",
"(",
"string",
")",
"$",
"script",
")",
")",
";",
"}",
"//Include script\r",
"require_once",
"(",
"$",
"script",
")",
";",
"//Create new instance\r",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"script",
")",
";",
"$",
"classname",
"=",
"$",
"file",
"->",
"entity",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"class",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"//Check if needed constants are defined\r",
"foreach",
"(",
"[",
"'TIME'",
",",
"'ENABLED'",
"]",
"as",
"$",
"constant",
")",
"{",
"if",
"(",
"false",
"===",
"defined",
"(",
"$",
"classname",
".",
"'::'",
".",
"$",
"constant",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Missing constant \"%s\" in Schedule \"%s\" class'",
",",
"$",
"constant",
",",
"$",
"classname",
")",
")",
";",
"}",
"}",
"//Check if schedule has start method\r",
"if",
"(",
"false",
"===",
"is_callable",
"(",
"[",
"$",
"class",
",",
"'start'",
"]",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Missing methode start in Schedule \"%s\" class'",
",",
"$",
"classname",
")",
")",
";",
"}",
"//If the current schedule is enabled\r",
"if",
"(",
"true",
"===",
"$",
"class",
"::",
"ENABLED",
")",
"{",
"$",
"run",
"=",
"$",
"this",
"->",
"checkRun",
"(",
"$",
"class",
"::",
"TIME",
")",
";",
"if",
"(",
"true",
"===",
"$",
"run",
")",
"{",
"ob_start",
"(",
")",
";",
"//Capture return ouput \r",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"$",
"classname",
"]",
"[",
"'start'",
"]",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"data",
"[",
"$",
"classname",
"]",
"[",
"'return'",
"]",
"=",
"(",
"string",
")",
"$",
"class",
"->",
"start",
"(",
")",
";",
"$",
"data",
"[",
"$",
"classname",
"]",
"[",
"'echo'",
"]",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"data",
"[",
"$",
"classname",
"]",
"[",
"'end'",
"]",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"//Check if the current schedule has the complete method\r",
"if",
"(",
"true",
"===",
"is_callable",
"(",
"[",
"$",
"class",
",",
"'complete'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"complete",
"(",
"$",
"data",
"[",
"$",
"classname",
"]",
")",
";",
"}",
"//Write to log\r",
"$",
"logger",
"=",
"$",
"this",
"->",
"getLogger",
"(",
")",
";",
"$",
"logger",
"->",
"setDirectory",
"(",
"Path",
"::",
"get",
"(",
"'log-schedule'",
")",
")",
";",
"$",
"logger",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"}",
"}",
"}"
] | Execute individual task of schedule file
@param
@return | [
"Execute",
"individual",
"task",
"of",
"schedule",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Schedule/Schedule.php#L96-L157 | train |
Kris-Kuiper/sFire-Framework | src/Schedule/Schedule.php | Schedule.exec | private function exec($command, $background = false) {
exec(escapeshellcmd($command) . ($background === true ? ' > /dev/null &' : ''), $output);
return $output;
} | php | private function exec($command, $background = false) {
exec(escapeshellcmd($command) . ($background === true ? ' > /dev/null &' : ''), $output);
return $output;
} | [
"private",
"function",
"exec",
"(",
"$",
"command",
",",
"$",
"background",
"=",
"false",
")",
"{",
"exec",
"(",
"escapeshellcmd",
"(",
"$",
"command",
")",
".",
"(",
"$",
"background",
"===",
"true",
"?",
"' > /dev/null &'",
":",
"''",
")",
",",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Runs system command
@param string $command
@param boolean $background
@return string | [
"Runs",
"system",
"command"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Schedule/Schedule.php#L166-L171 | train |
Kris-Kuiper/sFire-Framework | src/Schedule/Schedule.php | Schedule.checkRun | private function checkRun($crontab) {
$time = explode(' ', date('i G j n w'));
$crontab = explode(' ', $crontab);
foreach($crontab as $k => &$v) {
$time[$k] = preg_replace('/^0+(?=\d)/', '', $time[$k]);
$v = explode(',', $v);
foreach ($v as &$v1) {
$v1 = preg_replace(['/^\*$/', '/^\d+$/', '/^(\d+)\-(\d+)$/', '/^\*\/(\d+)$/'], ['true', $time[$k] . '===\0', '(\1<=' . $time[$k] . ' and ' . $time[$k] . '<=\2)', $time[$k] . '%\1===0'], $v1);
}
$v = '(' . implode(' or ', $v) . ')';
}
$crontab = implode(' and ', $crontab);
return eval('return ' . $crontab . ';');
} | php | private function checkRun($crontab) {
$time = explode(' ', date('i G j n w'));
$crontab = explode(' ', $crontab);
foreach($crontab as $k => &$v) {
$time[$k] = preg_replace('/^0+(?=\d)/', '', $time[$k]);
$v = explode(',', $v);
foreach ($v as &$v1) {
$v1 = preg_replace(['/^\*$/', '/^\d+$/', '/^(\d+)\-(\d+)$/', '/^\*\/(\d+)$/'], ['true', $time[$k] . '===\0', '(\1<=' . $time[$k] . ' and ' . $time[$k] . '<=\2)', $time[$k] . '%\1===0'], $v1);
}
$v = '(' . implode(' or ', $v) . ')';
}
$crontab = implode(' and ', $crontab);
return eval('return ' . $crontab . ';');
} | [
"private",
"function",
"checkRun",
"(",
"$",
"crontab",
")",
"{",
"$",
"time",
"=",
"explode",
"(",
"' '",
",",
"date",
"(",
"'i G j n w'",
")",
")",
";",
"$",
"crontab",
"=",
"explode",
"(",
"' '",
",",
"$",
"crontab",
")",
";",
"foreach",
"(",
"$",
"crontab",
"as",
"$",
"k",
"=>",
"&",
"$",
"v",
")",
"{",
"$",
"time",
"[",
"$",
"k",
"]",
"=",
"preg_replace",
"(",
"'/^0+(?=\\d)/'",
",",
"''",
",",
"$",
"time",
"[",
"$",
"k",
"]",
")",
";",
"$",
"v",
"=",
"explode",
"(",
"','",
",",
"$",
"v",
")",
";",
"foreach",
"(",
"$",
"v",
"as",
"&",
"$",
"v1",
")",
"{",
"$",
"v1",
"=",
"preg_replace",
"(",
"[",
"'/^\\*$/'",
",",
"'/^\\d+$/'",
",",
"'/^(\\d+)\\-(\\d+)$/'",
",",
"'/^\\*\\/(\\d+)$/'",
"]",
",",
"[",
"'true'",
",",
"$",
"time",
"[",
"$",
"k",
"]",
".",
"'===\\0'",
",",
"'(\\1<='",
".",
"$",
"time",
"[",
"$",
"k",
"]",
".",
"' and '",
".",
"$",
"time",
"[",
"$",
"k",
"]",
".",
"'<=\\2)'",
",",
"$",
"time",
"[",
"$",
"k",
"]",
".",
"'%\\1===0'",
"]",
",",
"$",
"v1",
")",
";",
"}",
"$",
"v",
"=",
"'('",
".",
"implode",
"(",
"' or '",
",",
"$",
"v",
")",
".",
"')'",
";",
"}",
"$",
"crontab",
"=",
"implode",
"(",
"' and '",
",",
"$",
"crontab",
")",
";",
"return",
"eval",
"(",
"'return '",
".",
"$",
"crontab",
".",
"';'",
")",
";",
"}"
] | Checks if script should run
@param string $crontab
@return boolean | [
"Checks",
"if",
"script",
"should",
"run"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Schedule/Schedule.php#L179-L200 | train |
Kris-Kuiper/sFire-Framework | src/Schedule/Schedule.php | Schedule.bootstrap | private function bootstrap() {
include(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
new \Bootstrap(false);
} | php | private function bootstrap() {
include(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
new \Bootstrap(false);
} | [
"private",
"function",
"bootstrap",
"(",
")",
"{",
"include",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"dirname",
"(",
"__FILE__",
")",
")",
")",
")",
")",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'bootstrap.php'",
")",
";",
"new",
"\\",
"Bootstrap",
"(",
"false",
")",
";",
"}"
] | Load the bootstrap | [
"Load",
"the",
"bootstrap"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Schedule/Schedule.php#L206-L210 | train |
shrink0r/php-schema | src/Schema.php | Schema.verifySchema | protected function verifySchema(array $schema)
{
$customTypes = isset($schema['customTypes']) ? $schema['customTypes'] : [];
if (!is_array($customTypes)) {
throw new Exception("Given value for key 'customTypes' is not an array.");
}
$properties = isset($schema['properties']) ? $schema['properties'] : null;
if (!is_array($properties)) {
throw new Exception("Missing valid value for 'properties' key within given schema.");
}
return [ $customTypes, $properties ];
} | php | protected function verifySchema(array $schema)
{
$customTypes = isset($schema['customTypes']) ? $schema['customTypes'] : [];
if (!is_array($customTypes)) {
throw new Exception("Given value for key 'customTypes' is not an array.");
}
$properties = isset($schema['properties']) ? $schema['properties'] : null;
if (!is_array($properties)) {
throw new Exception("Missing valid value for 'properties' key within given schema.");
}
return [ $customTypes, $properties ];
} | [
"protected",
"function",
"verifySchema",
"(",
"array",
"$",
"schema",
")",
"{",
"$",
"customTypes",
"=",
"isset",
"(",
"$",
"schema",
"[",
"'customTypes'",
"]",
")",
"?",
"$",
"schema",
"[",
"'customTypes'",
"]",
":",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"customTypes",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Given value for key 'customTypes' is not an array.\"",
")",
";",
"}",
"$",
"properties",
"=",
"isset",
"(",
"$",
"schema",
"[",
"'properties'",
"]",
")",
"?",
"$",
"schema",
"[",
"'properties'",
"]",
":",
"null",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"properties",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Missing valid value for 'properties' key within given schema.\"",
")",
";",
"}",
"return",
"[",
"$",
"customTypes",
",",
"$",
"properties",
"]",
";",
"}"
] | Ensures that the given schema has valid values. Will yield defaults where available.
@param mixed[] $schema
@return mixed[] Returns the given schema plus defaults where applicable. | [
"Ensures",
"that",
"the",
"given",
"schema",
"has",
"valid",
"values",
".",
"Will",
"yield",
"defaults",
"where",
"available",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Schema.php#L127-L140 | train |
shrink0r/php-schema | src/Schema.php | Schema.validateMappedValues | protected function validateMappedValues(array $data)
{
$errors = [];
foreach (array_diff_key($this->properties, [ ':any_name:' => 1 ]) as $key => $property) {
$result = $this->selectValue($property, $data);
if ($result instanceof Ok) {
$value = $result->unwrap();
if ($value === null) {
continue;
}
$result = $property->validate($value);
}
if ($result instanceof Error) {
$errors[$key] = $result->unwrap();
}
}
return empty($errors) ? Ok::unit() : Error::unit($errors);
} | php | protected function validateMappedValues(array $data)
{
$errors = [];
foreach (array_diff_key($this->properties, [ ':any_name:' => 1 ]) as $key => $property) {
$result = $this->selectValue($property, $data);
if ($result instanceof Ok) {
$value = $result->unwrap();
if ($value === null) {
continue;
}
$result = $property->validate($value);
}
if ($result instanceof Error) {
$errors[$key] = $result->unwrap();
}
}
return empty($errors) ? Ok::unit() : Error::unit($errors);
} | [
"protected",
"function",
"validateMappedValues",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_diff_key",
"(",
"$",
"this",
"->",
"properties",
",",
"[",
"':any_name:'",
"=>",
"1",
"]",
")",
"as",
"$",
"key",
"=>",
"$",
"property",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"selectValue",
"(",
"$",
"property",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Ok",
")",
"{",
"$",
"value",
"=",
"$",
"result",
"->",
"unwrap",
"(",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"=",
"$",
"property",
"->",
"validate",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"result",
"instanceof",
"Error",
")",
"{",
"$",
"errors",
"[",
"$",
"key",
"]",
"=",
"$",
"result",
"->",
"unwrap",
"(",
")",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"errors",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"$",
"errors",
")",
";",
"}"
] | Validates the values of all explicitly defined schema properties.
@param array $data
@return ResultInterface | [
"Validates",
"the",
"values",
"of",
"all",
"explicitly",
"defined",
"schema",
"properties",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Schema.php#L149-L168 | train |
shrink0r/php-schema | src/Schema.php | Schema.selectValue | protected function selectValue(PropertyInterface $property, array $data)
{
$errors = [];
$key = $property->getName();
$value = array_key_exists($key, $data) ? $data[$key] : null;
if ($value === null && $property->isRequired()) {
if (!array_key_exists($key, $data)) {
$errors[] = Error::MISSING_KEY;
}
$errors[] = Error::MISSING_VALUE;
}
return empty($errors) ? Ok::unit($value) : Error::unit($errors);
} | php | protected function selectValue(PropertyInterface $property, array $data)
{
$errors = [];
$key = $property->getName();
$value = array_key_exists($key, $data) ? $data[$key] : null;
if ($value === null && $property->isRequired()) {
if (!array_key_exists($key, $data)) {
$errors[] = Error::MISSING_KEY;
}
$errors[] = Error::MISSING_VALUE;
}
return empty($errors) ? Ok::unit($value) : Error::unit($errors);
} | [
"protected",
"function",
"selectValue",
"(",
"PropertyInterface",
"$",
"property",
",",
"array",
"$",
"data",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"$",
"key",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"$",
"value",
"=",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
"?",
"$",
"data",
"[",
"$",
"key",
"]",
":",
"null",
";",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"$",
"property",
"->",
"isRequired",
"(",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"Error",
"::",
"MISSING_KEY",
";",
"}",
"$",
"errors",
"[",
"]",
"=",
"Error",
"::",
"MISSING_VALUE",
";",
"}",
"return",
"empty",
"(",
"$",
"errors",
")",
"?",
"Ok",
"::",
"unit",
"(",
"$",
"value",
")",
":",
"Error",
"::",
"unit",
"(",
"$",
"errors",
")",
";",
"}"
] | Returns the property's corresponding value from the given data array.
@param PropertyInterface $property
@param array $data
@return ResultInterface If the value does not exist an error is returned; otherwise Ok is returned. | [
"Returns",
"the",
"property",
"s",
"corresponding",
"value",
"from",
"the",
"given",
"data",
"array",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Schema.php#L178-L192 | train |
Mandarin-Medien/MMCmfContentBundle | Twig/NodeTreeRenderExtension.php | NodeTreeRenderExtension.renderNodeTreeFunction | public function renderNodeTreeFunction(\Twig_Environment $twig, NodeInterface $node, array $options=array())
{
return $twig->render('MMCmfContentBundle:Form/NodeTree:list.html.twig', array('node' => $node, 'icon' => $this->getIcon(get_class($node)), 'options' => $options));
} | php | public function renderNodeTreeFunction(\Twig_Environment $twig, NodeInterface $node, array $options=array())
{
return $twig->render('MMCmfContentBundle:Form/NodeTree:list.html.twig', array('node' => $node, 'icon' => $this->getIcon(get_class($node)), 'options' => $options));
} | [
"public",
"function",
"renderNodeTreeFunction",
"(",
"\\",
"Twig_Environment",
"$",
"twig",
",",
"NodeInterface",
"$",
"node",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"twig",
"->",
"render",
"(",
"'MMCmfContentBundle:Form/NodeTree:list.html.twig'",
",",
"array",
"(",
"'node'",
"=>",
"$",
"node",
",",
"'icon'",
"=>",
"$",
"this",
"->",
"getIcon",
"(",
"get_class",
"(",
"$",
"node",
")",
")",
",",
"'options'",
"=>",
"$",
"options",
")",
")",
";",
"}"
] | renders the menu
@param \Twig_Environment $twig
@param NodeInterface $node
@param array $options
@return string | [
"renders",
"the",
"menu"
] | 503ab31cef3ce068f767de5b72f833526355b726 | https://github.com/Mandarin-Medien/MMCmfContentBundle/blob/503ab31cef3ce068f767de5b72f833526355b726/Twig/NodeTreeRenderExtension.php#L46-L49 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/filters/XmlFilterer.php | XmlFilterer.pretty | protected function pretty()
{
$xml = $this->getParameter('value');
$level = $this->getParameter('level') != null ? intval($this->getParameter('level')) : 6;
// get an array containing each XML element
$xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml));
// hold current indentation level
$indent = 0;
// hold the XML segments
$pretty = array();
// shift off opening XML tag if present
if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
$pretty[] = array_shift($xml);
}
foreach ($xml as $el) {
if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
if($indent < 0) $indent = 0;
// opening tag, increase indent
$pretty[] = str_repeat(' ', $indent) . htmlentities($el,ENT_QUOTES);
$indent += $level;
} else {
if (preg_match('/^<\/.+>$/', $el)) {
// closing tag, decrease indent
$indent -= $level;
}
$pretty[] = str_repeat(' ', abs($indent)) . htmlentities($el,ENT_QUOTES);
}
}
return implode("<br/>", $pretty);
} | php | protected function pretty()
{
$xml = $this->getParameter('value');
$level = $this->getParameter('level') != null ? intval($this->getParameter('level')) : 6;
// get an array containing each XML element
$xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml));
// hold current indentation level
$indent = 0;
// hold the XML segments
$pretty = array();
// shift off opening XML tag if present
if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
$pretty[] = array_shift($xml);
}
foreach ($xml as $el) {
if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
if($indent < 0) $indent = 0;
// opening tag, increase indent
$pretty[] = str_repeat(' ', $indent) . htmlentities($el,ENT_QUOTES);
$indent += $level;
} else {
if (preg_match('/^<\/.+>$/', $el)) {
// closing tag, decrease indent
$indent -= $level;
}
$pretty[] = str_repeat(' ', abs($indent)) . htmlentities($el,ENT_QUOTES);
}
}
return implode("<br/>", $pretty);
} | [
"protected",
"function",
"pretty",
"(",
")",
"{",
"$",
"xml",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'value'",
")",
";",
"$",
"level",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'level'",
")",
"!=",
"null",
"?",
"intval",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'level'",
")",
")",
":",
"6",
";",
"// get an array containing each XML element",
"$",
"xml",
"=",
"explode",
"(",
"\"\\n\"",
",",
"preg_replace",
"(",
"'/>\\s*</'",
",",
"\">\\n<\"",
",",
"$",
"xml",
")",
")",
";",
"// hold current indentation level",
"$",
"indent",
"=",
"0",
";",
"// hold the XML segments",
"$",
"pretty",
"=",
"array",
"(",
")",
";",
"// shift off opening XML tag if present",
"if",
"(",
"count",
"(",
"$",
"xml",
")",
"&&",
"preg_match",
"(",
"'/^<\\?\\s*xml/'",
",",
"$",
"xml",
"[",
"0",
"]",
")",
")",
"{",
"$",
"pretty",
"[",
"]",
"=",
"array_shift",
"(",
"$",
"xml",
")",
";",
"}",
"foreach",
"(",
"$",
"xml",
"as",
"$",
"el",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^<([\\w])+[^>\\/]*>$/U'",
",",
"$",
"el",
")",
")",
"{",
"if",
"(",
"$",
"indent",
"<",
"0",
")",
"$",
"indent",
"=",
"0",
";",
"// opening tag, increase indent",
"$",
"pretty",
"[",
"]",
"=",
"str_repeat",
"(",
"' '",
",",
"$",
"indent",
")",
".",
"htmlentities",
"(",
"$",
"el",
",",
"ENT_QUOTES",
")",
";",
"$",
"indent",
"+=",
"$",
"level",
";",
"}",
"else",
"{",
"if",
"(",
"preg_match",
"(",
"'/^<\\/.+>$/'",
",",
"$",
"el",
")",
")",
"{",
"// closing tag, decrease indent",
"$",
"indent",
"-=",
"$",
"level",
";",
"}",
"$",
"pretty",
"[",
"]",
"=",
"str_repeat",
"(",
"' '",
",",
"abs",
"(",
"$",
"indent",
")",
")",
".",
"htmlentities",
"(",
"$",
"el",
",",
"ENT_QUOTES",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"\"<br/>\"",
",",
"$",
"pretty",
")",
";",
"}"
] | Formats an XML string
Expected Param:
value string XML snippet
@return string | [
"Formats",
"an",
"XML",
"string"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/XmlFilterer.php#L43-L78 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/plugins/PluginService.php | PluginService.getAllActive | public function getAllActive()
{
$dto = new DTO();
$dto->setParameter("Status", "enabled");
$dto->setParameter("Installed", "1");
$dto->setOrderBy("Priority");
$dto = $this->findAll($dto);
return $dto->getResults();
} | php | public function getAllActive()
{
$dto = new DTO();
$dto->setParameter("Status", "enabled");
$dto->setParameter("Installed", "1");
$dto->setOrderBy("Priority");
$dto = $this->findAll($dto);
return $dto->getResults();
} | [
"public",
"function",
"getAllActive",
"(",
")",
"{",
"$",
"dto",
"=",
"new",
"DTO",
"(",
")",
";",
"$",
"dto",
"->",
"setParameter",
"(",
"\"Status\"",
",",
"\"enabled\"",
")",
";",
"$",
"dto",
"->",
"setParameter",
"(",
"\"Installed\"",
",",
"\"1\"",
")",
";",
"$",
"dto",
"->",
"setOrderBy",
"(",
"\"Priority\"",
")",
";",
"$",
"dto",
"=",
"$",
"this",
"->",
"findAll",
"(",
"$",
"dto",
")",
";",
"return",
"$",
"dto",
"->",
"getResults",
"(",
")",
";",
"}"
] | Returns an array of all active plugins
@return array | [
"Returns",
"an",
"array",
"of",
"all",
"active",
"plugins"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/plugins/PluginService.php#L44-L55 | train |
SergioMadness/pwf-helpers | src/HttpHelper.php | HttpHelper.isAbsoluteUrl | public static function isAbsoluteUrl($_path)
{
$url = parse_url($_path);
return $url !== false && isset($url['scheme']) && $url['scheme'] != '';
} | php | public static function isAbsoluteUrl($_path)
{
$url = parse_url($_path);
return $url !== false && isset($url['scheme']) && $url['scheme'] != '';
} | [
"public",
"static",
"function",
"isAbsoluteUrl",
"(",
"$",
"_path",
")",
"{",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"_path",
")",
";",
"return",
"$",
"url",
"!==",
"false",
"&&",
"isset",
"(",
"$",
"url",
"[",
"'scheme'",
"]",
")",
"&&",
"$",
"url",
"[",
"'scheme'",
"]",
"!=",
"''",
";",
"}"
] | Check is url absolute
@param string $_path
@return bool | [
"Check",
"is",
"url",
"absolute"
] | d6cd44807c120356d60618cb08f237841c35e293 | https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/HttpHelper.php#L63-L68 | train |
SergioMadness/pwf-helpers | src/HttpHelper.php | HttpHelper.invokeSoap | public static function invokeSoap($wsdlURL, $method,
array $params = array(),
array $options = array())
{
try {
$soapClient = new \SoapClient($wsdlURL, $options);
$result = $soapClient->$method($params);
} catch (\SoapFault $ex) {
$result = false;
}
return $result;
} | php | public static function invokeSoap($wsdlURL, $method,
array $params = array(),
array $options = array())
{
try {
$soapClient = new \SoapClient($wsdlURL, $options);
$result = $soapClient->$method($params);
} catch (\SoapFault $ex) {
$result = false;
}
return $result;
} | [
"public",
"static",
"function",
"invokeSoap",
"(",
"$",
"wsdlURL",
",",
"$",
"method",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"try",
"{",
"$",
"soapClient",
"=",
"new",
"\\",
"SoapClient",
"(",
"$",
"wsdlURL",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"$",
"soapClient",
"->",
"$",
"method",
"(",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"\\",
"SoapFault",
"$",
"ex",
")",
"{",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Invoke SOAP method
@param string $wsdlURL
@param string $method
@param array $params
@param array $options
@return mixed | [
"Invoke",
"SOAP",
"method"
] | d6cd44807c120356d60618cb08f237841c35e293 | https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/HttpHelper.php#L79-L90 | train |
cultuurnet/udb3-udb2-bridge | src/Media/ImageCollectionFactory.php | ImageCollectionFactory.fromUdb2Item | public function fromUdb2Item(CultureFeed_Cdb_Item_Base $item)
{
$dutch = new Language('nl');
$dutchDetail = $item
->getDetails()
->getDetailByLanguage('nl');
$title = $dutchDetail->getTitle();
return $this->fromUdb2Media(
$dutchDetail->getMedia(),
new Description($title),
new CopyrightHolder($title),
$dutch
);
} | php | public function fromUdb2Item(CultureFeed_Cdb_Item_Base $item)
{
$dutch = new Language('nl');
$dutchDetail = $item
->getDetails()
->getDetailByLanguage('nl');
$title = $dutchDetail->getTitle();
return $this->fromUdb2Media(
$dutchDetail->getMedia(),
new Description($title),
new CopyrightHolder($title),
$dutch
);
} | [
"public",
"function",
"fromUdb2Item",
"(",
"CultureFeed_Cdb_Item_Base",
"$",
"item",
")",
"{",
"$",
"dutch",
"=",
"new",
"Language",
"(",
"'nl'",
")",
";",
"$",
"dutchDetail",
"=",
"$",
"item",
"->",
"getDetails",
"(",
")",
"->",
"getDetailByLanguage",
"(",
"'nl'",
")",
";",
"$",
"title",
"=",
"$",
"dutchDetail",
"->",
"getTitle",
"(",
")",
";",
"return",
"$",
"this",
"->",
"fromUdb2Media",
"(",
"$",
"dutchDetail",
"->",
"getMedia",
"(",
")",
",",
"new",
"Description",
"(",
"$",
"title",
")",
",",
"new",
"CopyrightHolder",
"(",
"$",
"title",
")",
",",
"$",
"dutch",
")",
";",
"}"
] | Create an ImageCollection from the media in the Dutch details of on an UDB2 item.
@param CultureFeed_Cdb_Item_Base $item
@return ImageCollection | [
"Create",
"an",
"ImageCollection",
"from",
"the",
"media",
"in",
"the",
"Dutch",
"details",
"of",
"on",
"an",
"UDB2",
"item",
"."
] | 2d5922af555ddd4802bc1805a31900d86e038c6a | https://github.com/cultuurnet/udb3-udb2-bridge/blob/2d5922af555ddd4802bc1805a31900d86e038c6a/src/Media/ImageCollectionFactory.php#L58-L72 | train |
gplcart/cli | controllers/Command.php | Command.outputFormat | protected function outputFormat($data, $default = null)
{
switch ($this->getParam(array('f'), $default)) {
case 'print-r':
$this->line(print_r($data, true));
break;
case 'var-export':
$this->line(var_export($data, true));
break;
case 'json':
$this->line(json_encode($data, JSON_PRETTY_PRINT));
break;
case 'var-dump':
ob_start();
var_dump($data);
$this->line(ob_get_clean());
break;
default:
return null; // Pass to table formatter
}
$this->output();
} | php | protected function outputFormat($data, $default = null)
{
switch ($this->getParam(array('f'), $default)) {
case 'print-r':
$this->line(print_r($data, true));
break;
case 'var-export':
$this->line(var_export($data, true));
break;
case 'json':
$this->line(json_encode($data, JSON_PRETTY_PRINT));
break;
case 'var-dump':
ob_start();
var_dump($data);
$this->line(ob_get_clean());
break;
default:
return null; // Pass to table formatter
}
$this->output();
} | [
"protected",
"function",
"outputFormat",
"(",
"$",
"data",
",",
"$",
"default",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getParam",
"(",
"array",
"(",
"'f'",
")",
",",
"$",
"default",
")",
")",
"{",
"case",
"'print-r'",
":",
"$",
"this",
"->",
"line",
"(",
"print_r",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"'var-export'",
":",
"$",
"this",
"->",
"line",
"(",
"var_export",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"break",
";",
"case",
"'json'",
":",
"$",
"this",
"->",
"line",
"(",
"json_encode",
"(",
"$",
"data",
",",
"JSON_PRETTY_PRINT",
")",
")",
";",
"break",
";",
"case",
"'var-dump'",
":",
"ob_start",
"(",
")",
";",
"var_dump",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"line",
"(",
"ob_get_clean",
"(",
")",
")",
";",
"break",
";",
"default",
":",
"return",
"null",
";",
"// Pass to table formatter",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Output formatted data
@param mixed $data
@param null|string $default
@return null | [
"Output",
"formatted",
"data"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/Command.php#L30-L52 | train |
gplcart/cli | controllers/Command.php | Command.getLimit | protected function getLimit(array $default_limit = array())
{
if (empty($default_limit)) {
$default_limit = $this->config->get('module_cli_limit', array(0, 100));
}
$limit = $this->getParam('l');
if (!isset($limit) || !is_numeric($limit)) {
return $default_limit;
}
$exploded = explode(',', $limit, 2);
if (count($exploded) == 1) {
array_unshift($exploded, 0);
}
return $exploded;
} | php | protected function getLimit(array $default_limit = array())
{
if (empty($default_limit)) {
$default_limit = $this->config->get('module_cli_limit', array(0, 100));
}
$limit = $this->getParam('l');
if (!isset($limit) || !is_numeric($limit)) {
return $default_limit;
}
$exploded = explode(',', $limit, 2);
if (count($exploded) == 1) {
array_unshift($exploded, 0);
}
return $exploded;
} | [
"protected",
"function",
"getLimit",
"(",
"array",
"$",
"default_limit",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"default_limit",
")",
")",
"{",
"$",
"default_limit",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'module_cli_limit'",
",",
"array",
"(",
"0",
",",
"100",
")",
")",
";",
"}",
"$",
"limit",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'l'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"limit",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"limit",
")",
")",
"{",
"return",
"$",
"default_limit",
";",
"}",
"$",
"exploded",
"=",
"explode",
"(",
"','",
",",
"$",
"limit",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"exploded",
")",
"==",
"1",
")",
"{",
"array_unshift",
"(",
"$",
"exploded",
",",
"0",
")",
";",
"}",
"return",
"$",
"exploded",
";",
"}"
] | Returns an array of limits form the limit option or a default value
@param array $default_limit
@return array | [
"Returns",
"an",
"array",
"of",
"limits",
"form",
"the",
"limit",
"option",
"or",
"a",
"default",
"value"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/Command.php#L96-L115 | train |
gplcart/cli | controllers/Command.php | Command.explodeList | protected function explodeList($value, $separator = null)
{
if (is_array($value)) {
return $value;
}
if ($value === '' || !is_string($value)) {
return array();
}
if (!isset($separator)) {
$separator = $this->config->get('module_cli_list_separator', '|');
}
return array_map('trim', explode($separator, $value));
} | php | protected function explodeList($value, $separator = null)
{
if (is_array($value)) {
return $value;
}
if ($value === '' || !is_string($value)) {
return array();
}
if (!isset($separator)) {
$separator = $this->config->get('module_cli_list_separator', '|');
}
return array_map('trim', explode($separator, $value));
} | [
"protected",
"function",
"explodeList",
"(",
"$",
"value",
",",
"$",
"separator",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"''",
"||",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"separator",
")",
")",
"{",
"$",
"separator",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'module_cli_list_separator'",
",",
"'|'",
")",
";",
"}",
"return",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"$",
"separator",
",",
"$",
"value",
")",
")",
";",
"}"
] | Explode a string using a separator character
@param string $value
@param string|null $separator
@return array | [
"Explode",
"a",
"string",
"using",
"a",
"separator",
"character"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/Command.php#L135-L150 | train |
gplcart/cli | controllers/Command.php | Command.setSubmittedJson | protected function setSubmittedJson($field)
{
$json = $this->getSubmitted($field);
if (isset($json)) {
$decoded = json_decode($json, true);
if (json_last_error() === JSON_ERROR_NONE) {
$this->setSubmitted($field, $decoded);
} else {
$decoded = json_decode(base64_decode($json), true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new InvalidArgumentException('Failed to decode the submitted JSON string');
}
$this->setSubmitted($field, $decoded);
}
}
} | php | protected function setSubmittedJson($field)
{
$json = $this->getSubmitted($field);
if (isset($json)) {
$decoded = json_decode($json, true);
if (json_last_error() === JSON_ERROR_NONE) {
$this->setSubmitted($field, $decoded);
} else {
$decoded = json_decode(base64_decode($json), true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new InvalidArgumentException('Failed to decode the submitted JSON string');
}
$this->setSubmitted($field, $decoded);
}
}
} | [
"protected",
"function",
"setSubmittedJson",
"(",
"$",
"field",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"getSubmitted",
"(",
"$",
"field",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"json",
")",
")",
"{",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"===",
"JSON_ERROR_NONE",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"$",
"field",
",",
"$",
"decoded",
")",
";",
"}",
"else",
"{",
"$",
"decoded",
"=",
"json_decode",
"(",
"base64_decode",
"(",
"$",
"json",
")",
",",
"true",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Failed to decode the submitted JSON string'",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"$",
"field",
",",
"$",
"decoded",
")",
";",
"}",
"}",
"}"
] | Convert a submitted JSON string into an array or FALSE on error
@param string $field | [
"Convert",
"a",
"submitted",
"JSON",
"string",
"into",
"an",
"array",
"or",
"FALSE",
"on",
"error"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/Command.php#L156-L172 | train |
gplcart/cli | controllers/Command.php | Command.setSubmittedList | protected function setSubmittedList($field)
{
$value = $this->getSubmitted($field);
if (isset($value)) {
$this->setSubmitted($field, $this->explodeList($value));
}
} | php | protected function setSubmittedList($field)
{
$value = $this->getSubmitted($field);
if (isset($value)) {
$this->setSubmitted($field, $this->explodeList($value));
}
} | [
"protected",
"function",
"setSubmittedList",
"(",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getSubmitted",
"(",
"$",
"field",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"explodeList",
"(",
"$",
"value",
")",
")",
";",
"}",
"}"
] | Converts a submitted string into an array using a character as an separator
@param $field | [
"Converts",
"a",
"submitted",
"string",
"into",
"an",
"array",
"using",
"a",
"character",
"as",
"an",
"separator"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/Command.php#L178-L185 | train |
gplcart/cli | controllers/Command.php | Command.validatePromptList | protected function validatePromptList($field, $label, $validator, $default = null)
{
$input = $this->prompt($label, $default);
if ($this->isValidInput($this->explodeList($input), $field, $validator)) {
$this->setSubmitted($field, $input);
} else {
$this->errors();
$this->validatePromptList($field, $label, $validator, $default);
}
} | php | protected function validatePromptList($field, $label, $validator, $default = null)
{
$input = $this->prompt($label, $default);
if ($this->isValidInput($this->explodeList($input), $field, $validator)) {
$this->setSubmitted($field, $input);
} else {
$this->errors();
$this->validatePromptList($field, $label, $validator, $default);
}
} | [
"protected",
"function",
"validatePromptList",
"(",
"$",
"field",
",",
"$",
"label",
",",
"$",
"validator",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"prompt",
"(",
"$",
"label",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidInput",
"(",
"$",
"this",
"->",
"explodeList",
"(",
"$",
"input",
")",
",",
"$",
"field",
",",
"$",
"validator",
")",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"$",
"field",
",",
"$",
"input",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"errors",
"(",
")",
";",
"$",
"this",
"->",
"validatePromptList",
"(",
"$",
"field",
",",
"$",
"label",
",",
"$",
"validator",
",",
"$",
"default",
")",
";",
"}",
"}"
] | Validate prompt input when dealing with multiple values separated by a list character
@param string $field
@param string $label
@param string $validator
@param null|string $default | [
"Validate",
"prompt",
"input",
"when",
"dealing",
"with",
"multiple",
"values",
"separated",
"by",
"a",
"list",
"character"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/Command.php#L194-L204 | train |
proem-components/service | Asset.php | Asset.fetch | public function fetch(array $params = [], AssetManagerInterface $assetManager = null)
{
$asset = $this->asset;
$this->set($params);
return $this->validate($asset($this, $assetManager));
} | php | public function fetch(array $params = [], AssetManagerInterface $assetManager = null)
{
$asset = $this->asset;
$this->set($params);
return $this->validate($asset($this, $assetManager));
} | [
"public",
"function",
"fetch",
"(",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"AssetManagerInterface",
"$",
"assetManager",
"=",
"null",
")",
"{",
"$",
"asset",
"=",
"$",
"this",
"->",
"asset",
";",
"$",
"this",
"->",
"set",
"(",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"validate",
"(",
"$",
"asset",
"(",
"$",
"this",
",",
"$",
"assetManager",
")",
")",
";",
"}"
] | Validate and retrieve an instantiated asset.
Here the closure is passed this asset container and optionally a
Proem\Service\AssetManagerInterface implementation.
This provides the closure with the ability to use any required parameters
and also be able to call upon any other assets stored in the service manager.
@param array $params Allow last minute setting of parameters.
@param Proem\Service\AssetManagerInterface $assetManager | [
"Validate",
"and",
"retrieve",
"an",
"instantiated",
"asset",
"."
] | 8c8e9547f16ecaa2789482f34947618f96e453cc | https://github.com/proem-components/service/blob/8c8e9547f16ecaa2789482f34947618f96e453cc/Asset.php#L140-L147 | train |
sndsgd/form | src/Form.php | Form.merge | public function merge(\sndsgd\Form ...$forms): Form
{
foreach ($forms as $form) {
$fields = array_values($form->getFields());
$this->addFields(...$fields);
}
return $this;
} | php | public function merge(\sndsgd\Form ...$forms): Form
{
foreach ($forms as $form) {
$fields = array_values($form->getFields());
$this->addFields(...$fields);
}
return $this;
} | [
"public",
"function",
"merge",
"(",
"\\",
"sndsgd",
"\\",
"Form",
"...",
"$",
"forms",
")",
":",
"Form",
"{",
"foreach",
"(",
"$",
"forms",
"as",
"$",
"form",
")",
"{",
"$",
"fields",
"=",
"array_values",
"(",
"$",
"form",
"->",
"getFields",
"(",
")",
")",
";",
"$",
"this",
"->",
"addFields",
"(",
"...",
"$",
"fields",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Merge the fields of one or more forms into this one
@param \sndsgd\Form $forms The forms to merge
@return \sndsgd\Form | [
"Merge",
"the",
"fields",
"of",
"one",
"or",
"more",
"forms",
"into",
"this",
"one"
] | 56b5b9572a8942aea34c97c7c838b871e198e34f | https://github.com/sndsgd/form/blob/56b5b9572a8942aea34c97c7c838b871e198e34f/src/Form.php#L29-L37 | train |
ekyna/Table | Util/Config.php | Config.isValidSelectionMode | static public function isValidSelectionMode($mode, $throw = false)
{
$valid = in_array($mode, [
static::SELECTION_SINGLE,
static::SELECTION_MULTIPLE,
], true);
if (!$valid && $throw) {
throw new Exception\InvalidArgumentException("Invalid selection mode '{$mode}'.");
}
return $valid;
} | php | static public function isValidSelectionMode($mode, $throw = false)
{
$valid = in_array($mode, [
static::SELECTION_SINGLE,
static::SELECTION_MULTIPLE,
], true);
if (!$valid && $throw) {
throw new Exception\InvalidArgumentException("Invalid selection mode '{$mode}'.");
}
return $valid;
} | [
"static",
"public",
"function",
"isValidSelectionMode",
"(",
"$",
"mode",
",",
"$",
"throw",
"=",
"false",
")",
"{",
"$",
"valid",
"=",
"in_array",
"(",
"$",
"mode",
",",
"[",
"static",
"::",
"SELECTION_SINGLE",
",",
"static",
"::",
"SELECTION_MULTIPLE",
",",
"]",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"valid",
"&&",
"$",
"throw",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid selection mode '{$mode}'.\"",
")",
";",
"}",
"return",
"$",
"valid",
";",
"}"
] | Returns whether the given selection mode is valid or not.
@param string $mode The selection mode.
@param bool $throw Whether to throw an exception if the given mode is not valid.
@return bool | [
"Returns",
"whether",
"the",
"given",
"selection",
"mode",
"is",
"valid",
"or",
"not",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Util/Config.php#L26-L38 | train |
ekyna/Table | Util/Config.php | Config.validateName | static public function validateName($name)
{
if (null !== $name && !is_string($name)) {
throw new Exception\UnexpectedTypeException($name, 'string, integer or null');
}
if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) {
throw new Exception\InvalidArgumentException(sprintf(
'The name "%s" contains illegal characters. Names should only contain letters, numbers and underscores.',
$name
));
}
} | php | static public function validateName($name)
{
if (null !== $name && !is_string($name)) {
throw new Exception\UnexpectedTypeException($name, 'string, integer or null');
}
if (!preg_match('/^[a-zA-Z0-9_]+$/', $name)) {
throw new Exception\InvalidArgumentException(sprintf(
'The name "%s" contains illegal characters. Names should only contain letters, numbers and underscores.',
$name
));
}
} | [
"static",
"public",
"function",
"validateName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"name",
"&&",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UnexpectedTypeException",
"(",
"$",
"name",
",",
"'string, integer or null'",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-zA-Z0-9_]+$/'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The name \"%s\" contains illegal characters. Names should only contain letters, numbers and underscores.'",
",",
"$",
"name",
")",
")",
";",
"}",
"}"
] | Validates whether the given variable is a valid name.
@param string $name The tested name
@throws Exception\UnexpectedTypeException If the name is not a string.
@throws Exception\InvalidArgumentException If the name contains invalid characters. | [
"Validates",
"whether",
"the",
"given",
"variable",
"is",
"a",
"valid",
"name",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Util/Config.php#L48-L60 | train |
DreadLabs/VantomasWebsite | src/ThreatDefense/ReCaptcha.php | ReCaptcha.isThreat | public function isThreat(DataInterface $data)
{
$response = $this->client->post(
self::API_ENDPOINT,
[
'secret' => $this->secret,
'response' => $data->getValue(),
]
);
if (!$response->isSuccess()) {
return true;
}
$validation = json_decode($response->getBody());
if (is_null($validation) || !$validation->success) {
return true;
}
return false;
} | php | public function isThreat(DataInterface $data)
{
$response = $this->client->post(
self::API_ENDPOINT,
[
'secret' => $this->secret,
'response' => $data->getValue(),
]
);
if (!$response->isSuccess()) {
return true;
}
$validation = json_decode($response->getBody());
if (is_null($validation) || !$validation->success) {
return true;
}
return false;
} | [
"public",
"function",
"isThreat",
"(",
"DataInterface",
"$",
"data",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"post",
"(",
"self",
"::",
"API_ENDPOINT",
",",
"[",
"'secret'",
"=>",
"$",
"this",
"->",
"secret",
",",
"'response'",
"=>",
"$",
"data",
"->",
"getValue",
"(",
")",
",",
"]",
")",
";",
"if",
"(",
"!",
"$",
"response",
"->",
"isSuccess",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"validation",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"validation",
")",
"||",
"!",
"$",
"validation",
"->",
"success",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Flags if the used Control impl detected a threat
@param DataInterface $data The incoming data to investigate
@return bool | [
"Flags",
"if",
"the",
"used",
"Control",
"impl",
"detected",
"a",
"threat"
] | 7f85f2b45bdf5ed9fa9d320c805c416bf99cd668 | https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/ThreatDefense/ReCaptcha.php#L64-L85 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/LazyLoaderTrait.php | LazyLoaderTrait.loadDelegates | private function loadDelegates($entity)
{
if (!$this instanceof LazyLoaderInterface) {
return $entity;
}
if (!$entity instanceof LazyPropertiesInterface) {
throw new \InvalidArgumentException(sprintf('%s objects cannot be hydrated with properties loading delegates without implementing %s.',
get_class($entity),
LazyPropertiesInterface::class
));
}
// global handler (deprecated)
if (isset($proxies[$loaderClass = static::class])) {
@trigger_error(
sprintf('Global loader delegate is deprecated and will be removed in 1.6. Make "%s" loader invokable instead, entity to handle is given at first parameter.',
static::class
),
E_USER_DEPRECATED
);
$proxies[$loaderClass]($entity);
unset($proxies[$loaderClass]);
}
// define delegates into object
$entity->registerLoaders(
$this->getLoadingDelegates()
);
// global handler
if (is_callable($this)) {
$this($entity);
}
return $entity;
} | php | private function loadDelegates($entity)
{
if (!$this instanceof LazyLoaderInterface) {
return $entity;
}
if (!$entity instanceof LazyPropertiesInterface) {
throw new \InvalidArgumentException(sprintf('%s objects cannot be hydrated with properties loading delegates without implementing %s.',
get_class($entity),
LazyPropertiesInterface::class
));
}
// global handler (deprecated)
if (isset($proxies[$loaderClass = static::class])) {
@trigger_error(
sprintf('Global loader delegate is deprecated and will be removed in 1.6. Make "%s" loader invokable instead, entity to handle is given at first parameter.',
static::class
),
E_USER_DEPRECATED
);
$proxies[$loaderClass]($entity);
unset($proxies[$loaderClass]);
}
// define delegates into object
$entity->registerLoaders(
$this->getLoadingDelegates()
);
// global handler
if (is_callable($this)) {
$this($entity);
}
return $entity;
} | [
"private",
"function",
"loadDelegates",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"instanceof",
"LazyLoaderInterface",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"if",
"(",
"!",
"$",
"entity",
"instanceof",
"LazyPropertiesInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s objects cannot be hydrated with properties loading delegates without implementing %s.'",
",",
"get_class",
"(",
"$",
"entity",
")",
",",
"LazyPropertiesInterface",
"::",
"class",
")",
")",
";",
"}",
"// global handler (deprecated)",
"if",
"(",
"isset",
"(",
"$",
"proxies",
"[",
"$",
"loaderClass",
"=",
"static",
"::",
"class",
"]",
")",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Global loader delegate is deprecated and will be removed in 1.6. Make \"%s\" loader invokable instead, entity to handle is given at first parameter.'",
",",
"static",
"::",
"class",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"proxies",
"[",
"$",
"loaderClass",
"]",
"(",
"$",
"entity",
")",
";",
"unset",
"(",
"$",
"proxies",
"[",
"$",
"loaderClass",
"]",
")",
";",
"}",
"// define delegates into object",
"$",
"entity",
"->",
"registerLoaders",
"(",
"$",
"this",
"->",
"getLoadingDelegates",
"(",
")",
")",
";",
"// global handler",
"if",
"(",
"is_callable",
"(",
"$",
"this",
")",
")",
"{",
"$",
"this",
"(",
"$",
"entity",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Hydrate lazy loads delegate into given Collectionnable, if enabled and if
entity supports it.
@param LazyPropertiesInterface $object (not hinted to help notation and custom exception)
@return LazyPropertiesInterface | [
"Hydrate",
"lazy",
"loads",
"delegate",
"into",
"given",
"Collectionnable",
"if",
"enabled",
"and",
"if",
"entity",
"supports",
"it",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/LazyLoaderTrait.php#L20-L55 | train |
mundschenk-at/wp-data-storage | src/class-transients.php | Transients.get_large_object | public function get_large_object( $key ) {
$encoded = $this->get( $key );
if ( false === $encoded ) {
return false;
}
$uncompressed = @\gzdecode( \base64_decode( $encoded ) ); // @codingStandardsIgnoreLine
if ( false === $uncompressed ) {
return false;
}
return $this->maybe_fix_object( \unserialize( $uncompressed ) ); // @codingStandardsIgnoreLine
} | php | public function get_large_object( $key ) {
$encoded = $this->get( $key );
if ( false === $encoded ) {
return false;
}
$uncompressed = @\gzdecode( \base64_decode( $encoded ) ); // @codingStandardsIgnoreLine
if ( false === $uncompressed ) {
return false;
}
return $this->maybe_fix_object( \unserialize( $uncompressed ) ); // @codingStandardsIgnoreLine
} | [
"public",
"function",
"get_large_object",
"(",
"$",
"key",
")",
"{",
"$",
"encoded",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"false",
"===",
"$",
"encoded",
")",
"{",
"return",
"false",
";",
"}",
"$",
"uncompressed",
"=",
"@",
"\\",
"gzdecode",
"(",
"\\",
"base64_decode",
"(",
"$",
"encoded",
")",
")",
";",
"// @codingStandardsIgnoreLine",
"if",
"(",
"false",
"===",
"$",
"uncompressed",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"maybe_fix_object",
"(",
"\\",
"unserialize",
"(",
"$",
"uncompressed",
")",
")",
";",
"// @codingStandardsIgnoreLine",
"}"
] | Retrieves a cached large object.
@param string $key The cache key.
@return mixed | [
"Retrieves",
"a",
"cached",
"large",
"object",
"."
] | f06bba365c4a5ebc57f841b17afc5d6b0e6b48d0 | https://github.com/mundschenk-at/wp-data-storage/blob/f06bba365c4a5ebc57f841b17afc5d6b0e6b48d0/src/class-transients.php#L117-L129 | train |
mundschenk-at/wp-data-storage | src/class-transients.php | Transients.set_large_object | public function set_large_object( $key, $value, $duration = 0 ) {
$compressed = \gzencode( \serialize( $value ) ); // @codingStandardsIgnoreLine
if ( false === $compressed ) {
return false; // @codeCoverageIgnore
}
// base64_encode() is used to safely store the gzipped serialized object
// in the WordPress database.
return $this->set( $key, \base64_encode( $compressed ), $duration ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
} | php | public function set_large_object( $key, $value, $duration = 0 ) {
$compressed = \gzencode( \serialize( $value ) ); // @codingStandardsIgnoreLine
if ( false === $compressed ) {
return false; // @codeCoverageIgnore
}
// base64_encode() is used to safely store the gzipped serialized object
// in the WordPress database.
return $this->set( $key, \base64_encode( $compressed ), $duration ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
} | [
"public",
"function",
"set_large_object",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"duration",
"=",
"0",
")",
"{",
"$",
"compressed",
"=",
"\\",
"gzencode",
"(",
"\\",
"serialize",
"(",
"$",
"value",
")",
")",
";",
"// @codingStandardsIgnoreLine",
"if",
"(",
"false",
"===",
"$",
"compressed",
")",
"{",
"return",
"false",
";",
"// @codeCoverageIgnore",
"}",
"// base64_encode() is used to safely store the gzipped serialized object",
"// in the WordPress database.",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"\\",
"base64_encode",
"(",
"$",
"compressed",
")",
",",
"$",
"duration",
")",
";",
"// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode",
"}"
] | Sets a transient for a large PHP object. The object will be stored in
serialized and gzip encoded form using Base64 encoding to ensure binary safety.
@param string $key The cache key.
@param mixed $value The value to store.
@param int $duration Optional. The duration in seconds. Default 0 (no expiration).
@return bool True if the cache could be set successfully. | [
"Sets",
"a",
"transient",
"for",
"a",
"large",
"PHP",
"object",
".",
"The",
"object",
"will",
"be",
"stored",
"in",
"serialized",
"and",
"gzip",
"encoded",
"form",
"using",
"Base64",
"encoding",
"to",
"ensure",
"binary",
"safety",
"."
] | f06bba365c4a5ebc57f841b17afc5d6b0e6b48d0 | https://github.com/mundschenk-at/wp-data-storage/blob/f06bba365c4a5ebc57f841b17afc5d6b0e6b48d0/src/class-transients.php#L155-L165 | train |
mwyatt/core | src/Request.php | Request.setFiles | protected function setFiles(array $files)
{
foreach ($files as $associativeName => $details) {
foreach ($details as $fileKey => $detail) {
$this->files[$fileKey][$associativeName] = $detail;
}
}
} | php | protected function setFiles(array $files)
{
foreach ($files as $associativeName => $details) {
foreach ($details as $fileKey => $detail) {
$this->files[$fileKey][$associativeName] = $detail;
}
}
} | [
"protected",
"function",
"setFiles",
"(",
"array",
"$",
"files",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"associativeName",
"=>",
"$",
"details",
")",
"{",
"foreach",
"(",
"$",
"details",
"as",
"$",
"fileKey",
"=>",
"$",
"detail",
")",
"{",
"$",
"this",
"->",
"files",
"[",
"$",
"fileKey",
"]",
"[",
"$",
"associativeName",
"]",
"=",
"$",
"detail",
";",
"}",
"}",
"}"
] | store the request files in a nice way
@param array $files | [
"store",
"the",
"request",
"files",
"in",
"a",
"nice",
"way"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Request.php#L35-L42 | train |
linpax/microphp-framework | src/mvc/controllers/Controller.php | Controller.getActionClassByName | public function getActionClassByName($name)
{
if (method_exists($this, 'actions')) {
$actions = $this->actions();
if (
!empty($actions[$name]) &&
class_exists($actions[$name]) &&
is_subclass_of($actions[$name], '\Micro\Mvc\Action')
) {
return $actions[$name];
}
}
return false;
} | php | public function getActionClassByName($name)
{
if (method_exists($this, 'actions')) {
$actions = $this->actions();
if (
!empty($actions[$name]) &&
class_exists($actions[$name]) &&
is_subclass_of($actions[$name], '\Micro\Mvc\Action')
) {
return $actions[$name];
}
}
return false;
} | [
"public",
"function",
"getActionClassByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'actions'",
")",
")",
"{",
"$",
"actions",
"=",
"$",
"this",
"->",
"actions",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"actions",
"[",
"$",
"name",
"]",
")",
"&&",
"class_exists",
"(",
"$",
"actions",
"[",
"$",
"name",
"]",
")",
"&&",
"is_subclass_of",
"(",
"$",
"actions",
"[",
"$",
"name",
"]",
",",
"'\\Micro\\Mvc\\Action'",
")",
")",
"{",
"return",
"$",
"actions",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get action class by name
@access public
@param string $name action name
@return bool | [
"Get",
"action",
"class",
"by",
"name"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/mvc/controllers/Controller.php#L114-L129 | train |
lasallecms/lasallecms-l5-formhandling-pkg | src/AdminFormHandling/AdminFormBaseController.php | AdminFormBaseController.confirmDeletionMultipleRows | public function confirmDeletionMultipleRows(Request $request) {
$checkboxes = $request->input('checkbox');
if (!$checkboxes) {
// flash message with redirect
Session::flash('status_code', 400 );
$message = 'You have not selected any rows for deletion.';
Session::flash('message', $message);
return Redirect::route('admin.'.$this->model->resource_route_name.'.index');
}
// Prepare array of records
// i) flatten the array (https://laravel.com/docs/5.1/helpers#method-array-flatten)
$flattenedChecklistArray = array_flatten($checkboxes);
// ii) find multiple records
$records = $this->model->findMany($flattenedChecklistArray);
return view('formhandling::adminformhandling/' . config('lasallecmsadmin.admin_template_name') . '/delete_confirmMultipleRows',
[
'user' => Auth::user(),
'repository' => $this->repository,
'records' => $records,
'package_title' => $this->model->package_title,
'table_name' => $this->model->table,
'model_class' => $this->model->model_class,
'checkboxes' => $checkboxes,
'resource_route_name' => $this->model->resource_route_name,
'HTMLHelper' => HTMLHelper::class,
'Config' => Config::class,
'Form' => Form::class,
]);
} | php | public function confirmDeletionMultipleRows(Request $request) {
$checkboxes = $request->input('checkbox');
if (!$checkboxes) {
// flash message with redirect
Session::flash('status_code', 400 );
$message = 'You have not selected any rows for deletion.';
Session::flash('message', $message);
return Redirect::route('admin.'.$this->model->resource_route_name.'.index');
}
// Prepare array of records
// i) flatten the array (https://laravel.com/docs/5.1/helpers#method-array-flatten)
$flattenedChecklistArray = array_flatten($checkboxes);
// ii) find multiple records
$records = $this->model->findMany($flattenedChecklistArray);
return view('formhandling::adminformhandling/' . config('lasallecmsadmin.admin_template_name') . '/delete_confirmMultipleRows',
[
'user' => Auth::user(),
'repository' => $this->repository,
'records' => $records,
'package_title' => $this->model->package_title,
'table_name' => $this->model->table,
'model_class' => $this->model->model_class,
'checkboxes' => $checkboxes,
'resource_route_name' => $this->model->resource_route_name,
'HTMLHelper' => HTMLHelper::class,
'Config' => Config::class,
'Form' => Form::class,
]);
} | [
"public",
"function",
"confirmDeletionMultipleRows",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"checkboxes",
"=",
"$",
"request",
"->",
"input",
"(",
"'checkbox'",
")",
";",
"if",
"(",
"!",
"$",
"checkboxes",
")",
"{",
"// flash message with redirect",
"Session",
"::",
"flash",
"(",
"'status_code'",
",",
"400",
")",
";",
"$",
"message",
"=",
"'You have not selected any rows for deletion.'",
";",
"Session",
"::",
"flash",
"(",
"'message'",
",",
"$",
"message",
")",
";",
"return",
"Redirect",
"::",
"route",
"(",
"'admin.'",
".",
"$",
"this",
"->",
"model",
"->",
"resource_route_name",
".",
"'.index'",
")",
";",
"}",
"// Prepare array of records",
"// i) flatten the array (https://laravel.com/docs/5.1/helpers#method-array-flatten)",
"$",
"flattenedChecklistArray",
"=",
"array_flatten",
"(",
"$",
"checkboxes",
")",
";",
"// ii) find multiple records",
"$",
"records",
"=",
"$",
"this",
"->",
"model",
"->",
"findMany",
"(",
"$",
"flattenedChecklistArray",
")",
";",
"return",
"view",
"(",
"'formhandling::adminformhandling/'",
".",
"config",
"(",
"'lasallecmsadmin.admin_template_name'",
")",
".",
"'/delete_confirmMultipleRows'",
",",
"[",
"'user'",
"=>",
"Auth",
"::",
"user",
"(",
")",
",",
"'repository'",
"=>",
"$",
"this",
"->",
"repository",
",",
"'records'",
"=>",
"$",
"records",
",",
"'package_title'",
"=>",
"$",
"this",
"->",
"model",
"->",
"package_title",
",",
"'table_name'",
"=>",
"$",
"this",
"->",
"model",
"->",
"table",
",",
"'model_class'",
"=>",
"$",
"this",
"->",
"model",
"->",
"model_class",
",",
"'checkboxes'",
"=>",
"$",
"checkboxes",
",",
"'resource_route_name'",
"=>",
"$",
"this",
"->",
"model",
"->",
"resource_route_name",
",",
"'HTMLHelper'",
"=>",
"HTMLHelper",
"::",
"class",
",",
"'Config'",
"=>",
"Config",
"::",
"class",
",",
"'Form'",
"=>",
"Form",
"::",
"class",
",",
"]",
")",
";",
"}"
] | Confirm multiple row deletions
@return Response | [
"Confirm",
"multiple",
"row",
"deletions"
] | 5f8c1e0515d24de097dc7d1e85a4bc5eebdd47c1 | https://github.com/lasallecms/lasallecms-l5-formhandling-pkg/blob/5f8c1e0515d24de097dc7d1e85a4bc5eebdd47c1/src/AdminFormHandling/AdminFormBaseController.php#L562-L597 | train |
lasallecms/lasallecms-l5-formhandling-pkg | src/AdminFormHandling/AdminFormBaseController.php | AdminFormBaseController.getFieldLIst | public function getFieldLIst()
{
if (!isset($this->model->field_list)) {
return $this->model->getFieldList();
}
return $this->model->field_list;
} | php | public function getFieldLIst()
{
if (!isset($this->model->field_list)) {
return $this->model->getFieldList();
}
return $this->model->field_list;
} | [
"public",
"function",
"getFieldLIst",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"model",
"->",
"field_list",
")",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"getFieldList",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"model",
"->",
"field_list",
";",
"}"
] | get the Model's Field List
@return array | [
"get",
"the",
"Model",
"s",
"Field",
"List"
] | 5f8c1e0515d24de097dc7d1e85a4bc5eebdd47c1 | https://github.com/lasallecms/lasallecms-l5-formhandling-pkg/blob/5f8c1e0515d24de097dc7d1e85a4bc5eebdd47c1/src/AdminFormHandling/AdminFormBaseController.php#L811-L819 | train |
phossa/phossa-di | src/Phossa/Di/Definition/Loader/LoadableTrait.php | LoadableTrait.loadDefinitionFromFile | protected function loadDefinitionFromFile(/*# string */ $file)/*# : array */
{
// check first
$this->checkFileExistence($file);
// get definition type and loader class base on suffix
list($type, $class) = $this->getFileTypeClass($file);
// load into an array
$data = $class::loadFromFile($file);
// associate with definition type
return $type ? [$type => $data] : $data;
} | php | protected function loadDefinitionFromFile(/*# string */ $file)/*# : array */
{
// check first
$this->checkFileExistence($file);
// get definition type and loader class base on suffix
list($type, $class) = $this->getFileTypeClass($file);
// load into an array
$data = $class::loadFromFile($file);
// associate with definition type
return $type ? [$type => $data] : $data;
} | [
"protected",
"function",
"loadDefinitionFromFile",
"(",
"/*# string */",
"$",
"file",
")",
"/*# : array */",
"{",
"// check first",
"$",
"this",
"->",
"checkFileExistence",
"(",
"$",
"file",
")",
";",
"// get definition type and loader class base on suffix",
"list",
"(",
"$",
"type",
",",
"$",
"class",
")",
"=",
"$",
"this",
"->",
"getFileTypeClass",
"(",
"$",
"file",
")",
";",
"// load into an array",
"$",
"data",
"=",
"$",
"class",
"::",
"loadFromFile",
"(",
"$",
"file",
")",
";",
"// associate with definition type",
"return",
"$",
"type",
"?",
"[",
"$",
"type",
"=>",
"$",
"data",
"]",
":",
"$",
"data",
";",
"}"
] | Load definitions from a file
@param string $file definition file name
@return array
@throws NotFoundException if file not found
@throws LogicException if something goes wrong
@access protected | [
"Load",
"definitions",
"from",
"a",
"file"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/Loader/LoadableTrait.php#L42-L55 | train |
phossa/phossa-di | src/Phossa/Di/Definition/Loader/LoadableTrait.php | LoadableTrait.getFileTypeClass | protected function getFileTypeClass(/*# string */ $filename)
{
$parts = explode('.', strtolower(basename($filename)));
$count = count($parts);
$suffix = $count > 1 ? $parts[$count - 1] : 'php';
$type = $count > 2 ? $parts[$count - 2][0] : '_';
// valid types
$types = ['s' => 'services', 'p' => 'parameters', 'm' => 'mappings'];
return [
isset($types[$type]) ? $types[$type] : false,
$this->getLoaderClass($suffix, $filename)
];
} | php | protected function getFileTypeClass(/*# string */ $filename)
{
$parts = explode('.', strtolower(basename($filename)));
$count = count($parts);
$suffix = $count > 1 ? $parts[$count - 1] : 'php';
$type = $count > 2 ? $parts[$count - 2][0] : '_';
// valid types
$types = ['s' => 'services', 'p' => 'parameters', 'm' => 'mappings'];
return [
isset($types[$type]) ? $types[$type] : false,
$this->getLoaderClass($suffix, $filename)
];
} | [
"protected",
"function",
"getFileTypeClass",
"(",
"/*# string */",
"$",
"filename",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"strtolower",
"(",
"basename",
"(",
"$",
"filename",
")",
")",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"parts",
")",
";",
"$",
"suffix",
"=",
"$",
"count",
">",
"1",
"?",
"$",
"parts",
"[",
"$",
"count",
"-",
"1",
"]",
":",
"'php'",
";",
"$",
"type",
"=",
"$",
"count",
">",
"2",
"?",
"$",
"parts",
"[",
"$",
"count",
"-",
"2",
"]",
"[",
"0",
"]",
":",
"'_'",
";",
"// valid types",
"$",
"types",
"=",
"[",
"'s'",
"=>",
"'services'",
",",
"'p'",
"=>",
"'parameters'",
",",
"'m'",
"=>",
"'mappings'",
"]",
";",
"return",
"[",
"isset",
"(",
"$",
"types",
"[",
"$",
"type",
"]",
")",
"?",
"$",
"types",
"[",
"$",
"type",
"]",
":",
"false",
",",
"$",
"this",
"->",
"getLoaderClass",
"(",
"$",
"suffix",
",",
"$",
"filename",
")",
"]",
";",
"}"
] | Get definition type and loader class
*.[php|json|xml] : all definitions
*.s*.[php|json|xml] : service definitions
*.p*.[php|json|xml] : parameter definitions
*.m*.[php|json|xml] : mappings definitions
@param string $filename definition file name
@return string[]
@throws LogicException if something goes wrong
@access protected | [
"Get",
"definition",
"type",
"and",
"loader",
"class"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/Loader/LoadableTrait.php#L70-L84 | train |
phossa/phossa-di | src/Phossa/Di/Definition/Loader/LoadableTrait.php | LoadableTrait.checkFileExistence | protected function checkFileExistence(/*# string */ $file)
{
if (!file_exists($file) || !is_readable($file)) {
throw new NotFoundException(
Message::get(Message::DEFINITION_NOT_FOUND, $file),
Message::DEFINITION_NOT_FOUND
);
}
} | php | protected function checkFileExistence(/*# string */ $file)
{
if (!file_exists($file) || !is_readable($file)) {
throw new NotFoundException(
Message::get(Message::DEFINITION_NOT_FOUND, $file),
Message::DEFINITION_NOT_FOUND
);
}
} | [
"protected",
"function",
"checkFileExistence",
"(",
"/*# string */",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
"||",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"DEFINITION_NOT_FOUND",
",",
"$",
"file",
")",
",",
"Message",
"::",
"DEFINITION_NOT_FOUND",
")",
";",
"}",
"}"
] | Check file exists and readable
@param string $file definition file name
@return void
@throws NotFoundException if not exist or readable
@access protected | [
"Check",
"file",
"exists",
"and",
"readable"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/Loader/LoadableTrait.php#L94-L102 | train |
phossa/phossa-di | src/Phossa/Di/Definition/Loader/LoadableTrait.php | LoadableTrait.getLoaderClass | protected function getLoaderClass(
/*# string */ $suffix,
/*# string */ $filename
) {
$class = __NAMESPACE__ . '\\Loader' . ucfirst($suffix);
if (!class_exists($class)) {
throw new LogicException(
Message::get(Message::FILE_SUFFIX_UNKNOWN, $filename),
Message::FILE_SUFFIX_UNKNOWN
);
}
return $class;
} | php | protected function getLoaderClass(
/*# string */ $suffix,
/*# string */ $filename
) {
$class = __NAMESPACE__ . '\\Loader' . ucfirst($suffix);
if (!class_exists($class)) {
throw new LogicException(
Message::get(Message::FILE_SUFFIX_UNKNOWN, $filename),
Message::FILE_SUFFIX_UNKNOWN
);
}
return $class;
} | [
"protected",
"function",
"getLoaderClass",
"(",
"/*# string */",
"$",
"suffix",
",",
"/*# string */",
"$",
"filename",
")",
"{",
"$",
"class",
"=",
"__NAMESPACE__",
".",
"'\\\\Loader'",
".",
"ucfirst",
"(",
"$",
"suffix",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"FILE_SUFFIX_UNKNOWN",
",",
"$",
"filename",
")",
",",
"Message",
"::",
"FILE_SUFFIX_UNKNOWN",
")",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | Get loader class name base on suffix
@param string $suffix
@param string $filename
@return string classname
@throws LogicException if not class not found
@access protected | [
"Get",
"loader",
"class",
"name",
"base",
"on",
"suffix"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/Loader/LoadableTrait.php#L113-L125 | train |
azhai/code-refactor | src/CodeRefactor/Mixin/CodeMixin.php | CodeMixin.setName | public function setName($name)
{
$this->name = $name;
if ($this->node) {
$this->node->name = $name;
}
} | php | public function setName($name)
{
$this->name = $name;
if ($this->node) {
$this->node->name = $name;
}
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"if",
"(",
"$",
"this",
"->",
"node",
")",
"{",
"$",
"this",
"->",
"node",
"->",
"name",
"=",
"$",
"name",
";",
"}",
"}"
] | Set the node name. | [
"Set",
"the",
"node",
"name",
"."
] | cddb437d72f8239957daeba8211dda5e9366d6ca | https://github.com/azhai/code-refactor/blob/cddb437d72f8239957daeba8211dda5e9366d6ca/src/CodeRefactor/Mixin/CodeMixin.php#L39-L45 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/svn/SubversionTools.php | SubversionTools.getInfo | public function getInfo($path = '.')
{
if(!$this->svnEnabled)
return false;
$user = escapeshellarg($this->svnUsername);
$pw = escapeshellarg($this->svnPassword);
$creds = !empty($this->svnUsername) && !empty($this->svnPassword) ? "--username {$user} --password {$pw}" : "";
$version = trim(shell_exec("svn info {$creds} ".PATH_ROOT.'/'.$path));
$this->Logger->debug($version);
if(empty($version))
return false;
$status = trim(shell_exec("svn log {$creds} -r HEAD ".PATH_ROOT.'/'.$path));
$this->Logger->debug($status);
$data = array();
$lines = explode("\n", $version);
foreach($lines as $line) {
$ld = explode(": ",$line, 2);
if(count($ld) == 2)
{
list($name, $value) = $ld;
$name = str_replace(' ', '', $name);
if($name == 'LastChangedDate')
$value = substr($value, 0, strpos($value,'('));
$data[$name] = $value;
}
}
if(!empty($status))
{
$lines = explode("\n", $status);
if(count($lines) <= 1)
return false;
$line2 = $lines[1];
$logData = explode(' | ', $line2);
$crevision = ltrim($logData[0], 'r');
$cuser = $logData[1];
$cdate = substr($logData[2], 0, strpos($logData[2],'('));
$data['LatestRevision'] = $crevision;
$data['LatestChangedDate'] = $cdate;
$data['LatestChangedAuthor'] = $cuser;
}
return $data;
} | php | public function getInfo($path = '.')
{
if(!$this->svnEnabled)
return false;
$user = escapeshellarg($this->svnUsername);
$pw = escapeshellarg($this->svnPassword);
$creds = !empty($this->svnUsername) && !empty($this->svnPassword) ? "--username {$user} --password {$pw}" : "";
$version = trim(shell_exec("svn info {$creds} ".PATH_ROOT.'/'.$path));
$this->Logger->debug($version);
if(empty($version))
return false;
$status = trim(shell_exec("svn log {$creds} -r HEAD ".PATH_ROOT.'/'.$path));
$this->Logger->debug($status);
$data = array();
$lines = explode("\n", $version);
foreach($lines as $line) {
$ld = explode(": ",$line, 2);
if(count($ld) == 2)
{
list($name, $value) = $ld;
$name = str_replace(' ', '', $name);
if($name == 'LastChangedDate')
$value = substr($value, 0, strpos($value,'('));
$data[$name] = $value;
}
}
if(!empty($status))
{
$lines = explode("\n", $status);
if(count($lines) <= 1)
return false;
$line2 = $lines[1];
$logData = explode(' | ', $line2);
$crevision = ltrim($logData[0], 'r');
$cuser = $logData[1];
$cdate = substr($logData[2], 0, strpos($logData[2],'('));
$data['LatestRevision'] = $crevision;
$data['LatestChangedDate'] = $cdate;
$data['LatestChangedAuthor'] = $cuser;
}
return $data;
} | [
"public",
"function",
"getInfo",
"(",
"$",
"path",
"=",
"'.'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"svnEnabled",
")",
"return",
"false",
";",
"$",
"user",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"svnUsername",
")",
";",
"$",
"pw",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"svnPassword",
")",
";",
"$",
"creds",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"svnUsername",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"svnPassword",
")",
"?",
"\"--username {$user} --password {$pw}\"",
":",
"\"\"",
";",
"$",
"version",
"=",
"trim",
"(",
"shell_exec",
"(",
"\"svn info {$creds} \"",
".",
"PATH_ROOT",
".",
"'/'",
".",
"$",
"path",
")",
")",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"$",
"version",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"version",
")",
")",
"return",
"false",
";",
"$",
"status",
"=",
"trim",
"(",
"shell_exec",
"(",
"\"svn log {$creds} -r HEAD \"",
".",
"PATH_ROOT",
".",
"'/'",
".",
"$",
"path",
")",
")",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"$",
"status",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"version",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"ld",
"=",
"explode",
"(",
"\": \"",
",",
"$",
"line",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"ld",
")",
"==",
"2",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"$",
"ld",
";",
"$",
"name",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"name",
"==",
"'LastChangedDate'",
")",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"strpos",
"(",
"$",
"value",
",",
"'('",
")",
")",
";",
"$",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"status",
")",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"status",
")",
";",
"if",
"(",
"count",
"(",
"$",
"lines",
")",
"<=",
"1",
")",
"return",
"false",
";",
"$",
"line2",
"=",
"$",
"lines",
"[",
"1",
"]",
";",
"$",
"logData",
"=",
"explode",
"(",
"' | '",
",",
"$",
"line2",
")",
";",
"$",
"crevision",
"=",
"ltrim",
"(",
"$",
"logData",
"[",
"0",
"]",
",",
"'r'",
")",
";",
"$",
"cuser",
"=",
"$",
"logData",
"[",
"1",
"]",
";",
"$",
"cdate",
"=",
"substr",
"(",
"$",
"logData",
"[",
"2",
"]",
",",
"0",
",",
"strpos",
"(",
"$",
"logData",
"[",
"2",
"]",
",",
"'('",
")",
")",
";",
"$",
"data",
"[",
"'LatestRevision'",
"]",
"=",
"$",
"crevision",
";",
"$",
"data",
"[",
"'LatestChangedDate'",
"]",
"=",
"$",
"cdate",
";",
"$",
"data",
"[",
"'LatestChangedAuthor'",
"]",
"=",
"$",
"cuser",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Performs an svn info on the provided path.
Returns an array of SVN commit data, or false on failure.
@param string $path
@return array|bool | [
"Performs",
"an",
"svn",
"info",
"on",
"the",
"provided",
"path",
".",
"Returns",
"an",
"array",
"of",
"SVN",
"commit",
"data",
"or",
"false",
"on",
"failure",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/svn/SubversionTools.php#L77-L129 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/svn/SubversionTools.php | SubversionTools.update | public function update($path = '.')
{
if(!$this->svnEnabled)
return false;
$user = escapeshellarg($this->svnUsername);
$pw = escapeshellarg($this->svnPassword);
$creds = !empty($this->svnUsername) && !empty($this->svnPassword) ? "--username {$user} --password {$pw}" : "";
$cmd = "svn update {$creds} -r HEAD ".PATH_ROOT.'/'.$path;
$this->Logger->debug($cmd);
$updateRes = trim(shell_exec($cmd));
if(empty($updateRes))
return false;
$this->Logger->debug($updateRes);
return true;
} | php | public function update($path = '.')
{
if(!$this->svnEnabled)
return false;
$user = escapeshellarg($this->svnUsername);
$pw = escapeshellarg($this->svnPassword);
$creds = !empty($this->svnUsername) && !empty($this->svnPassword) ? "--username {$user} --password {$pw}" : "";
$cmd = "svn update {$creds} -r HEAD ".PATH_ROOT.'/'.$path;
$this->Logger->debug($cmd);
$updateRes = trim(shell_exec($cmd));
if(empty($updateRes))
return false;
$this->Logger->debug($updateRes);
return true;
} | [
"public",
"function",
"update",
"(",
"$",
"path",
"=",
"'.'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"svnEnabled",
")",
"return",
"false",
";",
"$",
"user",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"svnUsername",
")",
";",
"$",
"pw",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"svnPassword",
")",
";",
"$",
"creds",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"svnUsername",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"svnPassword",
")",
"?",
"\"--username {$user} --password {$pw}\"",
":",
"\"\"",
";",
"$",
"cmd",
"=",
"\"svn update {$creds} -r HEAD \"",
".",
"PATH_ROOT",
".",
"'/'",
".",
"$",
"path",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"$",
"cmd",
")",
";",
"$",
"updateRes",
"=",
"trim",
"(",
"shell_exec",
"(",
"$",
"cmd",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"updateRes",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"$",
"updateRes",
")",
";",
"return",
"true",
";",
"}"
] | performs an svn update of the path provided
@param string $path
@return bool status of update | [
"performs",
"an",
"svn",
"update",
"of",
"the",
"path",
"provided"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/svn/SubversionTools.php#L137-L159 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/svn/SubversionTools.php | SubversionTools.copyPath | public function copyPath($fromPath, $toPath, $commitMessage)
{
$this->_validateSvnConfig();
$user = escapeshellarg($this->svnUsername);
$pw = escapeshellarg($this->svnPassword);
$fromPath = trim($fromPath, '/');
$toPath = trim($toPath, '/');
$fromPath = "{$this->svnRepository}/$fromPath/";
$toPath = "{$this->svnRepository}/{$toPath}/";
$svn = "svn copy --username {$user} --password {$pw} {$fromPath} {$toPath} --non-interactive -m \"{$commitMessage}\"";
$this->Logger->debug($svn);
$revision = trim(shell_exec($svn));
$this->Logger->debug($revision);
if(strpos($revision,'Committed revision') === FALSE) {
throw new SubversionToolsException("Subversion copy failed.");
}
return $toPath;
} | php | public function copyPath($fromPath, $toPath, $commitMessage)
{
$this->_validateSvnConfig();
$user = escapeshellarg($this->svnUsername);
$pw = escapeshellarg($this->svnPassword);
$fromPath = trim($fromPath, '/');
$toPath = trim($toPath, '/');
$fromPath = "{$this->svnRepository}/$fromPath/";
$toPath = "{$this->svnRepository}/{$toPath}/";
$svn = "svn copy --username {$user} --password {$pw} {$fromPath} {$toPath} --non-interactive -m \"{$commitMessage}\"";
$this->Logger->debug($svn);
$revision = trim(shell_exec($svn));
$this->Logger->debug($revision);
if(strpos($revision,'Committed revision') === FALSE) {
throw new SubversionToolsException("Subversion copy failed.");
}
return $toPath;
} | [
"public",
"function",
"copyPath",
"(",
"$",
"fromPath",
",",
"$",
"toPath",
",",
"$",
"commitMessage",
")",
"{",
"$",
"this",
"->",
"_validateSvnConfig",
"(",
")",
";",
"$",
"user",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"svnUsername",
")",
";",
"$",
"pw",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"svnPassword",
")",
";",
"$",
"fromPath",
"=",
"trim",
"(",
"$",
"fromPath",
",",
"'/'",
")",
";",
"$",
"toPath",
"=",
"trim",
"(",
"$",
"toPath",
",",
"'/'",
")",
";",
"$",
"fromPath",
"=",
"\"{$this->svnRepository}/$fromPath/\"",
";",
"$",
"toPath",
"=",
"\"{$this->svnRepository}/{$toPath}/\"",
";",
"$",
"svn",
"=",
"\"svn copy --username {$user} --password {$pw} {$fromPath} {$toPath} --non-interactive -m \\\"{$commitMessage}\\\"\"",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"$",
"svn",
")",
";",
"$",
"revision",
"=",
"trim",
"(",
"shell_exec",
"(",
"$",
"svn",
")",
")",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"$",
"revision",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"revision",
",",
"'Committed revision'",
")",
"===",
"FALSE",
")",
"{",
"throw",
"new",
"SubversionToolsException",
"(",
"\"Subversion copy failed.\"",
")",
";",
"}",
"return",
"$",
"toPath",
";",
"}"
] | Performs an svn copy of a repository path to another svn path in the same repository
fromPath and toPath should contain only the most specific portion of the
SVN repository URL needed to make the copy.
For example, a from path could be 'trunk' and to path 'tags'. Another example
would be copying from trunk to a branch, such as:
$fromPath: 'trunk'
$toPath: 'branches/plugins/crowdfusion-plugin/1.1.0'
$commitMessage 'tagging crowdfusion-plugin for development'
@param string $fromPath repository path to be copied (i.e. "trunk")
@param string $toPath repository path used to store the copy (i.e. "tags/tagname")
@param string $commitMessage svn commit message used when creating the copy
@throws SubversionToolsException
@return string Full SVN repository URL of the new path | [
"Performs",
"an",
"svn",
"copy",
"of",
"a",
"repository",
"path",
"to",
"another",
"svn",
"path",
"in",
"the",
"same",
"repository"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/svn/SubversionTools.php#L179-L204 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/svn/SubversionTools.php | SubversionTools._validateSvnConfig | protected function _validateSvnConfig()
{
if(!$this->svnEnabled)
throw new SubversionToolsException("Subversion support must be enabled for this action!");
if(empty($this->svnUsername))
throw new SubversionToolsException("Property svn.username is required");
if(empty($this->svnPassword))
throw new SubversionToolsException("Property svn.password is required");
if(empty($this->svnRepository))
throw new SubversionToolsException("Property svn.repository is required");
return true;
} | php | protected function _validateSvnConfig()
{
if(!$this->svnEnabled)
throw new SubversionToolsException("Subversion support must be enabled for this action!");
if(empty($this->svnUsername))
throw new SubversionToolsException("Property svn.username is required");
if(empty($this->svnPassword))
throw new SubversionToolsException("Property svn.password is required");
if(empty($this->svnRepository))
throw new SubversionToolsException("Property svn.repository is required");
return true;
} | [
"protected",
"function",
"_validateSvnConfig",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"svnEnabled",
")",
"throw",
"new",
"SubversionToolsException",
"(",
"\"Subversion support must be enabled for this action!\"",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"svnUsername",
")",
")",
"throw",
"new",
"SubversionToolsException",
"(",
"\"Property svn.username is required\"",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"svnPassword",
")",
")",
"throw",
"new",
"SubversionToolsException",
"(",
"\"Property svn.password is required\"",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"svnRepository",
")",
")",
"throw",
"new",
"SubversionToolsException",
"(",
"\"Property svn.repository is required\"",
")",
";",
"return",
"true",
";",
"}"
] | validates that all properties needed to work with the svn repository are populated
@throws SubversionToolsException
@return bool | [
"validates",
"that",
"all",
"properties",
"needed",
"to",
"work",
"with",
"the",
"svn",
"repository",
"are",
"populated"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/svn/SubversionTools.php#L348-L363 | train |
shgysk8zer0/core_api | traits/socket_client.php | Socket_Client.socketAccept | final public function socketAccept($socket = null)
{
if (is_resource($socket)) {
$this->socket = socket_accept($socket);
return $this->socket;
} else {
throw new InvalidArgumentException(__METHOD__ . ' expects $socket to be an instance of resource. ' . gettype($resource) . ' given instead');
}
} | php | final public function socketAccept($socket = null)
{
if (is_resource($socket)) {
$this->socket = socket_accept($socket);
return $this->socket;
} else {
throw new InvalidArgumentException(__METHOD__ . ' expects $socket to be an instance of resource. ' . gettype($resource) . ' given instead');
}
} | [
"final",
"public",
"function",
"socketAccept",
"(",
"$",
"socket",
"=",
"null",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"socket",
")",
")",
"{",
"$",
"this",
"->",
"socket",
"=",
"socket_accept",
"(",
"$",
"socket",
")",
";",
"return",
"$",
"this",
"->",
"socket",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"' expects $socket to be an instance of resource. '",
".",
"gettype",
"(",
"$",
"resource",
")",
".",
"' given instead'",
")",
";",
"}",
"}"
] | Creates a client side sockets from a server side one
@param resource $socket Socket created through socket_create
@return resource | [
"Creates",
"a",
"client",
"side",
"sockets",
"from",
"a",
"server",
"side",
"one"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/socket_client.php#L42-L50 | train |
shgysk8zer0/core_api | traits/socket_client.php | Socket_Client.socketWrite | final public function socketWrite($message = '', $length = null)
{
return @socket_write(
$this->socket,
"{$message}",
is_int($length) ? $length : strlen($message)
);
} | php | final public function socketWrite($message = '', $length = null)
{
return @socket_write(
$this->socket,
"{$message}",
is_int($length) ? $length : strlen($message)
);
} | [
"final",
"public",
"function",
"socketWrite",
"(",
"$",
"message",
"=",
"''",
",",
"$",
"length",
"=",
"null",
")",
"{",
"return",
"@",
"socket_write",
"(",
"$",
"this",
"->",
"socket",
",",
"\"{$message}\"",
",",
"is_int",
"(",
"$",
"length",
")",
"?",
"$",
"length",
":",
"strlen",
"(",
"$",
"message",
")",
")",
";",
"}"
] | Write to client socket
@param string $message The message to send
@param int $length Optional lenght (defaults to length of $message)
@return int The number of bytes successfully written to the socket or FALSE on failure | [
"Write",
"to",
"client",
"socket"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/socket_client.php#L71-L78 | train |
Wedeto/DB | src/Query/SubQuery.php | SubQuery.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
$scope = $params->getSubScope($this->scope_id);
$this->scope_id = $scope->getScopeID();
$q = $this->getQuery();
return '(' . $params->getDriver()->toSQL($scope, $q, false) . ')';
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
$scope = $params->getSubScope($this->scope_id);
$this->scope_id = $scope->getScopeID();
$q = $this->getQuery();
return '(' . $params->getDriver()->toSQL($scope, $q, false) . ')';
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"$",
"scope",
"=",
"$",
"params",
"->",
"getSubScope",
"(",
"$",
"this",
"->",
"scope_id",
")",
";",
"$",
"this",
"->",
"scope_id",
"=",
"$",
"scope",
"->",
"getScopeID",
"(",
")",
";",
"$",
"q",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"return",
"'('",
".",
"$",
"params",
"->",
"getDriver",
"(",
")",
"->",
"toSQL",
"(",
"$",
"scope",
",",
"$",
"q",
",",
"false",
")",
".",
"')'",
";",
"}"
] | Write a sub query as SQL query syntax
@param Parameters $params The query parameters: tables and placeholder values
@param SubQuery $query The query to write
@return string The generated SQL | [
"Write",
"a",
"sub",
"query",
"as",
"SQL",
"query",
"syntax"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/SubQuery.php#L59-L66 | train |
TuumPHP/Web | src/View/ViewProviders.php | ViewProviders.getViewEngine | public function getViewEngine()
{
if($this->app->exists(ViewEngineInterface::class)) {
return $this->app->get(ViewEngineInterface::class);
}
$view = View::forge($this->web->view_dir);
$this->app->set(ViewEngineInterface::class, $view, true);
return $view;
} | php | public function getViewEngine()
{
if($this->app->exists(ViewEngineInterface::class)) {
return $this->app->get(ViewEngineInterface::class);
}
$view = View::forge($this->web->view_dir);
$this->app->set(ViewEngineInterface::class, $view, true);
return $view;
} | [
"public",
"function",
"getViewEngine",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"exists",
"(",
"ViewEngineInterface",
"::",
"class",
")",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"get",
"(",
"ViewEngineInterface",
"::",
"class",
")",
";",
"}",
"$",
"view",
"=",
"View",
"::",
"forge",
"(",
"$",
"this",
"->",
"web",
"->",
"view_dir",
")",
";",
"$",
"this",
"->",
"app",
"->",
"set",
"(",
"ViewEngineInterface",
"::",
"class",
",",
"$",
"view",
",",
"true",
")",
";",
"return",
"$",
"view",
";",
"}"
] | get shared view engine, Renderer as default.
@return ViewEngineInterface|View | [
"get",
"shared",
"view",
"engine",
"Renderer",
"as",
"default",
"."
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/View/ViewProviders.php#L43-L51 | train |
TuumPHP/Web | src/View/ViewProviders.php | ViewProviders.getErrorView | public function getErrorView()
{
if($this->app->exists(ErrorView::class)) {
return $this->app->get(ErrorView::class);
}
$error_files = (array)$this->app->get(Web::ERROR_VIEWS);
if (empty($error_files)) {
$this->app->set(ErrorView::class, null, true);
return null;
}
$view = new ErrorView($this->getViewEngine(), $this->web->debug);
if (isset($error_files[0])) {
$view->default_error_file = $error_files[0];
unset($error_files[0]);
}
$view->setLogger($this->web->getLog());
$view->error_files = $error_files;
$this->app->set(ErrorView::class, $view, true);
return $view;
} | php | public function getErrorView()
{
if($this->app->exists(ErrorView::class)) {
return $this->app->get(ErrorView::class);
}
$error_files = (array)$this->app->get(Web::ERROR_VIEWS);
if (empty($error_files)) {
$this->app->set(ErrorView::class, null, true);
return null;
}
$view = new ErrorView($this->getViewEngine(), $this->web->debug);
if (isset($error_files[0])) {
$view->default_error_file = $error_files[0];
unset($error_files[0]);
}
$view->setLogger($this->web->getLog());
$view->error_files = $error_files;
$this->app->set(ErrorView::class, $view, true);
return $view;
} | [
"public",
"function",
"getErrorView",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"exists",
"(",
"ErrorView",
"::",
"class",
")",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"get",
"(",
"ErrorView",
"::",
"class",
")",
";",
"}",
"$",
"error_files",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"app",
"->",
"get",
"(",
"Web",
"::",
"ERROR_VIEWS",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"error_files",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"set",
"(",
"ErrorView",
"::",
"class",
",",
"null",
",",
"true",
")",
";",
"return",
"null",
";",
"}",
"$",
"view",
"=",
"new",
"ErrorView",
"(",
"$",
"this",
"->",
"getViewEngine",
"(",
")",
",",
"$",
"this",
"->",
"web",
"->",
"debug",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"error_files",
"[",
"0",
"]",
")",
")",
"{",
"$",
"view",
"->",
"default_error_file",
"=",
"$",
"error_files",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"error_files",
"[",
"0",
"]",
")",
";",
"}",
"$",
"view",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"web",
"->",
"getLog",
"(",
")",
")",
";",
"$",
"view",
"->",
"error_files",
"=",
"$",
"error_files",
";",
"$",
"this",
"->",
"app",
"->",
"set",
"(",
"ErrorView",
"::",
"class",
",",
"$",
"view",
",",
"true",
")",
";",
"return",
"$",
"view",
";",
"}"
] | get error view render, ErrorView,
@return ErrorView|null | [
"get",
"error",
"view",
"render",
"ErrorView"
] | 8f296b6358aa93226ce08d6cc54a309f5b0a9820 | https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/View/ViewProviders.php#L58-L78 | train |
afroware/jwtauth | src/Providers/AbstractServiceProvider.php | AbstractServiceProvider.registerManager | protected function registerManager()
{
$this->app->singleton('afroware.jwT.manager', function ($app) {
$instance = new Manager(
$app['afroware.jwT.provider.jwT'],
$app['afroware.jwT.blacklist'],
$app['afroware.jwT.payload.factory']
);
return $instance->setBlacklistEnabled((bool) $this->config('blacklist_enabled'))
->setPersistentClaims($this->config('persistent_claims'));
});
} | php | protected function registerManager()
{
$this->app->singleton('afroware.jwT.manager', function ($app) {
$instance = new Manager(
$app['afroware.jwT.provider.jwT'],
$app['afroware.jwT.blacklist'],
$app['afroware.jwT.payload.factory']
);
return $instance->setBlacklistEnabled((bool) $this->config('blacklist_enabled'))
->setPersistentClaims($this->config('persistent_claims'));
});
} | [
"protected",
"function",
"registerManager",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'afroware.jwT.manager'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"instance",
"=",
"new",
"Manager",
"(",
"$",
"app",
"[",
"'afroware.jwT.provider.jwT'",
"]",
",",
"$",
"app",
"[",
"'afroware.jwT.blacklist'",
"]",
",",
"$",
"app",
"[",
"'afroware.jwT.payload.factory'",
"]",
")",
";",
"return",
"$",
"instance",
"->",
"setBlacklistEnabled",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"config",
"(",
"'blacklist_enabled'",
")",
")",
"->",
"setPersistentClaims",
"(",
"$",
"this",
"->",
"config",
"(",
"'persistent_claims'",
")",
")",
";",
"}",
")",
";",
"}"
] | Register the bindings for the JwT Manager.
@return void | [
"Register",
"the",
"bindings",
"for",
"the",
"JwT",
"Manager",
"."
] | 54a0aebd811d87bfdd2b3668696fd53f50490cc1 | https://github.com/afroware/jwtauth/blob/54a0aebd811d87bfdd2b3668696fd53f50490cc1/src/Providers/AbstractServiceProvider.php#L171-L183 | train |
afroware/jwtauth | src/Providers/AbstractServiceProvider.php | AbstractServiceProvider.registerClaimFactory | protected function registerClaimFactory()
{
$this->app->singleton('afroware.jwT.claim.factory', function ($app) {
$factory = new ClaimFactory($app['request']);
$app->refresh('request', $factory, 'setRequest');
return $factory->setTTL($this->config('ttl'));
});
} | php | protected function registerClaimFactory()
{
$this->app->singleton('afroware.jwT.claim.factory', function ($app) {
$factory = new ClaimFactory($app['request']);
$app->refresh('request', $factory, 'setRequest');
return $factory->setTTL($this->config('ttl'));
});
} | [
"protected",
"function",
"registerClaimFactory",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'afroware.jwT.claim.factory'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"factory",
"=",
"new",
"ClaimFactory",
"(",
"$",
"app",
"[",
"'request'",
"]",
")",
";",
"$",
"app",
"->",
"refresh",
"(",
"'request'",
",",
"$",
"factory",
",",
"'setRequest'",
")",
";",
"return",
"$",
"factory",
"->",
"setTTL",
"(",
"$",
"this",
"->",
"config",
"(",
"'ttl'",
")",
")",
";",
"}",
")",
";",
"}"
] | Register the bindings for the Claim Factory.
@return void | [
"Register",
"the",
"bindings",
"for",
"the",
"Claim",
"Factory",
"."
] | 54a0aebd811d87bfdd2b3668696fd53f50490cc1 | https://github.com/afroware/jwtauth/blob/54a0aebd811d87bfdd2b3668696fd53f50490cc1/src/Providers/AbstractServiceProvider.php#L275-L283 | train |
Vectrex/vxPHP | src/Webpage/MenuEntry/MenuEntry.php | MenuEntry.isAuthenticatedByRole | public function isAuthenticatedByRole(Role $role) {
return !isset($this->auth) || $this->auth === $role->getRoleName();
} | php | public function isAuthenticatedByRole(Role $role) {
return !isset($this->auth) || $this->auth === $role->getRoleName();
} | [
"public",
"function",
"isAuthenticatedByRole",
"(",
"Role",
"$",
"role",
")",
"{",
"return",
"!",
"isset",
"(",
"$",
"this",
"->",
"auth",
")",
"||",
"$",
"this",
"->",
"auth",
"===",
"$",
"role",
"->",
"getRoleName",
"(",
")",
";",
"}"
] | check whether a role matches the auth attribute of the menu entry
@param Role $role
@return boolean | [
"check",
"whether",
"a",
"role",
"matches",
"the",
"auth",
"attribute",
"of",
"the",
"menu",
"entry"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/MenuEntry/MenuEntry.php#L147-L151 | train |
Vectrex/vxPHP | src/Webpage/MenuEntry/MenuEntry.php | MenuEntry.getHref | public function getHref() {
if(is_null($this->href)) {
if($this->localPage) {
$pathSegments = [];
$e = $this;
do {
$pathSegments[] = $e->path;
} while ($e = $e->menu->getParentEntry());
if(Application::getInstance()->getRouter()->getServerSideRewrite()) {
if(($script = basename($this->menu->getScript(), '.php')) == 'index') {
$script = '/';
}
else {
$script = '/'. $script . '/';
}
}
else {
$script = '/' . $this->menu->getScript() . '/';
}
$this->href = $script . implode('/', array_reverse(array_map('rawurlencode', $pathSegments)));
}
else {
$this->href = $this->path;
}
}
return $this->href;
} | php | public function getHref() {
if(is_null($this->href)) {
if($this->localPage) {
$pathSegments = [];
$e = $this;
do {
$pathSegments[] = $e->path;
} while ($e = $e->menu->getParentEntry());
if(Application::getInstance()->getRouter()->getServerSideRewrite()) {
if(($script = basename($this->menu->getScript(), '.php')) == 'index') {
$script = '/';
}
else {
$script = '/'. $script . '/';
}
}
else {
$script = '/' . $this->menu->getScript() . '/';
}
$this->href = $script . implode('/', array_reverse(array_map('rawurlencode', $pathSegments)));
}
else {
$this->href = $this->path;
}
}
return $this->href;
} | [
"public",
"function",
"getHref",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"href",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"localPage",
")",
"{",
"$",
"pathSegments",
"=",
"[",
"]",
";",
"$",
"e",
"=",
"$",
"this",
";",
"do",
"{",
"$",
"pathSegments",
"[",
"]",
"=",
"$",
"e",
"->",
"path",
";",
"}",
"while",
"(",
"$",
"e",
"=",
"$",
"e",
"->",
"menu",
"->",
"getParentEntry",
"(",
")",
")",
";",
"if",
"(",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"getRouter",
"(",
")",
"->",
"getServerSideRewrite",
"(",
")",
")",
"{",
"if",
"(",
"(",
"$",
"script",
"=",
"basename",
"(",
"$",
"this",
"->",
"menu",
"->",
"getScript",
"(",
")",
",",
"'.php'",
")",
")",
"==",
"'index'",
")",
"{",
"$",
"script",
"=",
"'/'",
";",
"}",
"else",
"{",
"$",
"script",
"=",
"'/'",
".",
"$",
"script",
".",
"'/'",
";",
"}",
"}",
"else",
"{",
"$",
"script",
"=",
"'/'",
".",
"$",
"this",
"->",
"menu",
"->",
"getScript",
"(",
")",
".",
"'/'",
";",
"}",
"$",
"this",
"->",
"href",
"=",
"$",
"script",
".",
"implode",
"(",
"'/'",
",",
"array_reverse",
"(",
"array_map",
"(",
"'rawurlencode'",
",",
"$",
"pathSegments",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"href",
"=",
"$",
"this",
"->",
"path",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"href",
";",
"}"
] | get href attribute value of menu entry | [
"get",
"href",
"attribute",
"value",
"of",
"menu",
"entry"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Webpage/MenuEntry/MenuEntry.php#L172-L212 | train |
judus/minimal-http | src/Response.php | Response.arrayToJson | public function arrayToJson($content = null)
{
if ($this->getJsonEncodeArray() && is_array($content)) {
$this->header('Content-Type: application/json');
return json_encode($content);
}
return $content;
} | php | public function arrayToJson($content = null)
{
if ($this->getJsonEncodeArray() && is_array($content)) {
$this->header('Content-Type: application/json');
return json_encode($content);
}
return $content;
} | [
"public",
"function",
"arrayToJson",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getJsonEncodeArray",
"(",
")",
"&&",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"$",
"this",
"->",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"return",
"json_encode",
"(",
"$",
"content",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Encode array to json if configured
@param $content
@return string | [
"Encode",
"array",
"to",
"json",
"if",
"configured"
] | 13c49e1350488acea8acf44ab5ed7796a39a9f1a | https://github.com/judus/minimal-http/blob/13c49e1350488acea8acf44ab5ed7796a39a9f1a/src/Response.php#L165-L173 | train |
judus/minimal-http | src/Response.php | Response.objectToJson | public function objectToJson($content = null)
{
if ($this->getJsonEncodeObject() && is_object($content)) {
if (method_exists($content, '__toString')) {
return (string)$content;
}
if (method_exists($content, 'toJson')) {
$this->header('Content-Type: application/json');
return json_encode($content);
}
if (method_exists($content, 'toArray')) {
$this->header('Content-Type: application/json');
return json_encode($content->toArray());
}
}
return $content;
} | php | public function objectToJson($content = null)
{
if ($this->getJsonEncodeObject() && is_object($content)) {
if (method_exists($content, '__toString')) {
return (string)$content;
}
if (method_exists($content, 'toJson')) {
$this->header('Content-Type: application/json');
return json_encode($content);
}
if (method_exists($content, 'toArray')) {
$this->header('Content-Type: application/json');
return json_encode($content->toArray());
}
}
return $content;
} | [
"public",
"function",
"objectToJson",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getJsonEncodeObject",
"(",
")",
"&&",
"is_object",
"(",
"$",
"content",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"content",
",",
"'__toString'",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"content",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"content",
",",
"'toJson'",
")",
")",
"{",
"$",
"this",
"->",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"return",
"json_encode",
"(",
"$",
"content",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"content",
",",
"'toArray'",
")",
")",
"{",
"$",
"this",
"->",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"return",
"json_encode",
"(",
"$",
"content",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"content",
";",
"}"
] | Encode object to json if configured
@param $content
@return string | [
"Encode",
"object",
"to",
"json",
"if",
"configured"
] | 13c49e1350488acea8acf44ab5ed7796a39a9f1a | https://github.com/judus/minimal-http/blob/13c49e1350488acea8acf44ab5ed7796a39a9f1a/src/Response.php#L182-L204 | train |
judus/minimal-http | src/Response.php | Response.printRecursiveNonAlphaNum | public function printRecursiveNonAlphaNum($content = null)
{
if (is_array($content) || is_object($content)) {
ob_start();
/** @noinspection PhpUndefinedFunctionInspection */
if (php_sapi_name() != 'cli' && !defined('STDIN')) {
d($content);
} else {
var_dump($content);
}
$content = ob_get_contents();
ob_end_clean();
}
return $content;
} | php | public function printRecursiveNonAlphaNum($content = null)
{
if (is_array($content) || is_object($content)) {
ob_start();
/** @noinspection PhpUndefinedFunctionInspection */
if (php_sapi_name() != 'cli' && !defined('STDIN')) {
d($content);
} else {
var_dump($content);
}
$content = ob_get_contents();
ob_end_clean();
}
return $content;
} | [
"public",
"function",
"printRecursiveNonAlphaNum",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
"||",
"is_object",
"(",
"$",
"content",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"/** @noinspection PhpUndefinedFunctionInspection */",
"if",
"(",
"php_sapi_name",
"(",
")",
"!=",
"'cli'",
"&&",
"!",
"defined",
"(",
"'STDIN'",
")",
")",
"{",
"d",
"(",
"$",
"content",
")",
";",
"}",
"else",
"{",
"var_dump",
"(",
"$",
"content",
")",
";",
"}",
"$",
"content",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Does a print_r with objects and array recursive
@param $content
@return string | [
"Does",
"a",
"print_r",
"with",
"objects",
"and",
"array",
"recursive"
] | 13c49e1350488acea8acf44ab5ed7796a39a9f1a | https://github.com/judus/minimal-http/blob/13c49e1350488acea8acf44ab5ed7796a39a9f1a/src/Response.php#L213-L231 | train |
ZendExperts/phpids | lib/IDS/Monitor.php | IDS_Monitor.getReport | public function getReport()
{
if (isset($this->centrifuge) && $this->centrifuge) {
$this->report->setCentrifuge($this->centrifuge);
}
return $this->report;
} | php | public function getReport()
{
if (isset($this->centrifuge) && $this->centrifuge) {
$this->report->setCentrifuge($this->centrifuge);
}
return $this->report;
} | [
"public",
"function",
"getReport",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"centrifuge",
")",
"&&",
"$",
"this",
"->",
"centrifuge",
")",
"{",
"$",
"this",
"->",
"report",
"->",
"setCentrifuge",
"(",
"$",
"this",
"->",
"centrifuge",
")",
";",
"}",
"return",
"$",
"this",
"->",
"report",
";",
"}"
] | Returns report object providing various functions to work with
detected results. Also the centrifuge data is being set as property
of the report object.
@return object IDS_Report | [
"Returns",
"report",
"object",
"providing",
"various",
"functions",
"to",
"work",
"with",
"detected",
"results",
".",
"Also",
"the",
"centrifuge",
"data",
"is",
"being",
"set",
"as",
"property",
"of",
"the",
"report",
"object",
"."
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Monitor.php#L761-L768 | train |
ptlis/grep-db | src/Replace/Result/RowReplaceResult.php | RowReplaceResult.getReplacedCount | public function getReplacedCount(): int
{
return intval(array_reduce(
$this->fieldResultList,
function (int $count, FieldReplaceResult $fieldResult) {
return $count + $fieldResult->getReplacedCount();
},
0
));
} | php | public function getReplacedCount(): int
{
return intval(array_reduce(
$this->fieldResultList,
function (int $count, FieldReplaceResult $fieldResult) {
return $count + $fieldResult->getReplacedCount();
},
0
));
} | [
"public",
"function",
"getReplacedCount",
"(",
")",
":",
"int",
"{",
"return",
"intval",
"(",
"array_reduce",
"(",
"$",
"this",
"->",
"fieldResultList",
",",
"function",
"(",
"int",
"$",
"count",
",",
"FieldReplaceResult",
"$",
"fieldResult",
")",
"{",
"return",
"$",
"count",
"+",
"$",
"fieldResult",
"->",
"getReplacedCount",
"(",
")",
";",
"}",
",",
"0",
")",
")",
";",
"}"
] | Get the number of replacements in all fields in this row. | [
"Get",
"the",
"number",
"of",
"replacements",
"in",
"all",
"fields",
"in",
"this",
"row",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Replace/Result/RowReplaceResult.php#L45-L54 | train |
ptlis/grep-db | src/Replace/Result/RowReplaceResult.php | RowReplaceResult.getErrorList | public function getErrorList(): array
{
$errorList = $this->errorList;
foreach ($this->fieldResultList as $fieldResult) {
foreach ($fieldResult->getErrorList() as $error) {
$errorList[] = $error;
}
}
return $errorList;
} | php | public function getErrorList(): array
{
$errorList = $this->errorList;
foreach ($this->fieldResultList as $fieldResult) {
foreach ($fieldResult->getErrorList() as $error) {
$errorList[] = $error;
}
}
return $errorList;
} | [
"public",
"function",
"getErrorList",
"(",
")",
":",
"array",
"{",
"$",
"errorList",
"=",
"$",
"this",
"->",
"errorList",
";",
"foreach",
"(",
"$",
"this",
"->",
"fieldResultList",
"as",
"$",
"fieldResult",
")",
"{",
"foreach",
"(",
"$",
"fieldResult",
"->",
"getErrorList",
"(",
")",
"as",
"$",
"error",
")",
"{",
"$",
"errorList",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"return",
"$",
"errorList",
";",
"}"
] | Get any replacement errors.
@return string[] | [
"Get",
"any",
"replacement",
"errors",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Replace/Result/RowReplaceResult.php#L61-L71 | train |
ScaraMVC/Framework | src/Scara/Foundation/Environment.php | Environment.get | public function get($key, $default = '')
{
if (!is_null($this->_env)) {
$item = ($this->has($key)) ? getenv($key) : $default;
if (is_numeric($item)) {
if (strrpos($item, '.') !== false) {
return floatval($item);
} else {
return intval($item);
}
}
switch ($item) {
case 'true':
return true;
break;
case 'false':
return false;
break;
}
return var_export($default, true);
}
return var_export($default, true);
} | php | public function get($key, $default = '')
{
if (!is_null($this->_env)) {
$item = ($this->has($key)) ? getenv($key) : $default;
if (is_numeric($item)) {
if (strrpos($item, '.') !== false) {
return floatval($item);
} else {
return intval($item);
}
}
switch ($item) {
case 'true':
return true;
break;
case 'false':
return false;
break;
}
return var_export($default, true);
}
return var_export($default, true);
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"_env",
")",
")",
"{",
"$",
"item",
"=",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"?",
"getenv",
"(",
"$",
"key",
")",
":",
"$",
"default",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"item",
")",
")",
"{",
"if",
"(",
"strrpos",
"(",
"$",
"item",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"return",
"floatval",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"return",
"intval",
"(",
"$",
"item",
")",
";",
"}",
"}",
"switch",
"(",
"$",
"item",
")",
"{",
"case",
"'true'",
":",
"return",
"true",
";",
"break",
";",
"case",
"'false'",
":",
"return",
"false",
";",
"break",
";",
"}",
"return",
"var_export",
"(",
"$",
"default",
",",
"true",
")",
";",
"}",
"return",
"var_export",
"(",
"$",
"default",
",",
"true",
")",
";",
"}"
] | Gets an environment variable.
@param string $key
@param string $default
@return string | [
"Gets",
"an",
"environment",
"variable",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Foundation/Environment.php#L45-L71 | train |
phossa/phossa-cache | src/Phossa/Cache/Driver/FilesystemDriver.php | FilesystemDriver.getPath | protected function getPath(/*# string */ $key)/*# : string */
{
// get directory first
if (($pos = strrpos($key, '/')) !== false) {
$dir = $this->dir_root . DIRECTORY_SEPARATOR .
substr($key, 0, $pos) . DIRECTORY_SEPARATOR;
$key = substr($key, $pos + 1);
} else {
$dir = $this->dir_root . DIRECTORY_SEPARATOR;
}
// get file path
if (is_callable($this->path_func)) {
$func = $this->path_func;
$file = $func($key);
// hashed version
} else {
$file = $key ? $this->hashIt($key) : '';
}
return $dir . $file;
} | php | protected function getPath(/*# string */ $key)/*# : string */
{
// get directory first
if (($pos = strrpos($key, '/')) !== false) {
$dir = $this->dir_root . DIRECTORY_SEPARATOR .
substr($key, 0, $pos) . DIRECTORY_SEPARATOR;
$key = substr($key, $pos + 1);
} else {
$dir = $this->dir_root . DIRECTORY_SEPARATOR;
}
// get file path
if (is_callable($this->path_func)) {
$func = $this->path_func;
$file = $func($key);
// hashed version
} else {
$file = $key ? $this->hashIt($key) : '';
}
return $dir . $file;
} | [
"protected",
"function",
"getPath",
"(",
"/*# string */",
"$",
"key",
")",
"/*# : string */",
"{",
"// get directory first",
"if",
"(",
"(",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"key",
",",
"'/'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"dir_root",
".",
"DIRECTORY_SEPARATOR",
".",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"$",
"pos",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"key",
"=",
"substr",
"(",
"$",
"key",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"dir_root",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"// get file path",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"path_func",
")",
")",
"{",
"$",
"func",
"=",
"$",
"this",
"->",
"path_func",
";",
"$",
"file",
"=",
"$",
"func",
"(",
"$",
"key",
")",
";",
"// hashed version",
"}",
"else",
"{",
"$",
"file",
"=",
"$",
"key",
"?",
"$",
"this",
"->",
"hashIt",
"(",
"$",
"key",
")",
":",
"''",
";",
"}",
"return",
"$",
"dir",
".",
"$",
"file",
";",
"}"
] | Get path base on key.
$key may contain '/' to signal a path
@param string $key item key
@return string
@access protected | [
"Get",
"path",
"base",
"on",
"key",
"."
] | ad86bee9c5c646fbae09f6f58a346b379d16276e | https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/FilesystemDriver.php#L255-L277 | train |
phossa/phossa-cache | src/Phossa/Cache/Driver/FilesystemDriver.php | FilesystemDriver.hashIt | protected function hashIt(/*# string */ $key)/*# : string */
{
$md5 = md5($key);
$hash = $this->file_pref . $md5 . $this->file_suff;
// no hash
if (!$this->hash_level) {
return $hash;
}
// hash
$pref = '';
for ($i = 0; $i < $this->hash_level; $i++) {
$pref .= $md5[$i] . '/';
}
return $pref . $hash;
} | php | protected function hashIt(/*# string */ $key)/*# : string */
{
$md5 = md5($key);
$hash = $this->file_pref . $md5 . $this->file_suff;
// no hash
if (!$this->hash_level) {
return $hash;
}
// hash
$pref = '';
for ($i = 0; $i < $this->hash_level; $i++) {
$pref .= $md5[$i] . '/';
}
return $pref . $hash;
} | [
"protected",
"function",
"hashIt",
"(",
"/*# string */",
"$",
"key",
")",
"/*# : string */",
"{",
"$",
"md5",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"$",
"hash",
"=",
"$",
"this",
"->",
"file_pref",
".",
"$",
"md5",
".",
"$",
"this",
"->",
"file_suff",
";",
"// no hash",
"if",
"(",
"!",
"$",
"this",
"->",
"hash_level",
")",
"{",
"return",
"$",
"hash",
";",
"}",
"// hash",
"$",
"pref",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"hash_level",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pref",
".=",
"$",
"md5",
"[",
"$",
"i",
"]",
".",
"'/'",
";",
"}",
"return",
"$",
"pref",
".",
"$",
"hash",
";",
"}"
] | Get hashed filename
@param string $key the key
@return string
@access protected | [
"Get",
"hashed",
"filename"
] | ad86bee9c5c646fbae09f6f58a346b379d16276e | https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/FilesystemDriver.php#L286-L302 | train |
phossa/phossa-cache | src/Phossa/Cache/Driver/FilesystemDriver.php | FilesystemDriver.deleteFromDir | protected function deleteFromDir(
/*# string */ $dir,
/*# int */ $maxlife = 0,
/*# bool */ $removeDir = false
)/*# : bool */ {
$now = time();
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
$sub = $dir . DIRECTORY_SEPARATOR . $file;
$res = true;
if (is_dir($sub)) {
$res = $this->deleteFromDir($sub, $maxlife, true);
} else {
if (!$maxlife || $now - filemtime($sub) > $maxlife) {
$res = unlink($sub);
}
}
if ($res === false) {
return $this->falseAndSetError(
Message::get(Message::CACHE_FAIL_DELETE, $sub),
Message::CACHE_FAIL_DELETE
);
}
}
if ($removeDir && ! @rmdir($dir)) {
return $this->falseAndSetError(
Message::get(Message::CACHE_FAIL_DELETE, $dir),
Message::CACHE_FAIL_DELETE
);
}
}
return true;
} | php | protected function deleteFromDir(
/*# string */ $dir,
/*# int */ $maxlife = 0,
/*# bool */ $removeDir = false
)/*# : bool */ {
$now = time();
if (is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
$sub = $dir . DIRECTORY_SEPARATOR . $file;
$res = true;
if (is_dir($sub)) {
$res = $this->deleteFromDir($sub, $maxlife, true);
} else {
if (!$maxlife || $now - filemtime($sub) > $maxlife) {
$res = unlink($sub);
}
}
if ($res === false) {
return $this->falseAndSetError(
Message::get(Message::CACHE_FAIL_DELETE, $sub),
Message::CACHE_FAIL_DELETE
);
}
}
if ($removeDir && ! @rmdir($dir)) {
return $this->falseAndSetError(
Message::get(Message::CACHE_FAIL_DELETE, $dir),
Message::CACHE_FAIL_DELETE
);
}
}
return true;
} | [
"protected",
"function",
"deleteFromDir",
"(",
"/*# string */",
"$",
"dir",
",",
"/*# int */",
"$",
"maxlife",
"=",
"0",
",",
"/*# bool */",
"$",
"removeDir",
"=",
"false",
")",
"/*# : bool */",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"files",
"=",
"scandir",
"(",
"$",
"dir",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"==",
"\".\"",
"||",
"$",
"file",
"==",
"\"..\"",
")",
"{",
"continue",
";",
"}",
"$",
"sub",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"$",
"res",
"=",
"true",
";",
"if",
"(",
"is_dir",
"(",
"$",
"sub",
")",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"deleteFromDir",
"(",
"$",
"sub",
",",
"$",
"maxlife",
",",
"true",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"maxlife",
"||",
"$",
"now",
"-",
"filemtime",
"(",
"$",
"sub",
")",
">",
"$",
"maxlife",
")",
"{",
"$",
"res",
"=",
"unlink",
"(",
"$",
"sub",
")",
";",
"}",
"}",
"if",
"(",
"$",
"res",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"falseAndSetError",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CACHE_FAIL_DELETE",
",",
"$",
"sub",
")",
",",
"Message",
"::",
"CACHE_FAIL_DELETE",
")",
";",
"}",
"}",
"if",
"(",
"$",
"removeDir",
"&&",
"!",
"@",
"rmdir",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"$",
"this",
"->",
"falseAndSetError",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CACHE_FAIL_DELETE",
",",
"$",
"dir",
")",
",",
"Message",
"::",
"CACHE_FAIL_DELETE",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Remove all contents under one directory
@param string $dir directory
@param int $maxlife delete those older than $maxlife seconds
@param bool $removeDir remove the directory also
@return bool
@access protected | [
"Remove",
"all",
"contents",
"under",
"one",
"directory"
] | ad86bee9c5c646fbae09f6f58a346b379d16276e | https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Driver/FilesystemDriver.php#L313-L349 | train |
railken/amethyst-authentication | src/Providers/AuthenticationServiceProvider.php | AuthenticationServiceProvider.register | public function register()
{
$this->app->register(\Laravel\Passport\PassportServiceProvider::class);
$this->app->register(\Railken\Amethyst\Providers\ApiServiceProvider::class);
$this->app->register(\Railken\Amethyst\Providers\UserServiceProvider::class);
$this->mergeConfigFrom(__DIR__.'/../../config/amethyst.authentication.php', 'amethyst.authentication');
} | php | public function register()
{
$this->app->register(\Laravel\Passport\PassportServiceProvider::class);
$this->app->register(\Railken\Amethyst\Providers\ApiServiceProvider::class);
$this->app->register(\Railken\Amethyst\Providers\UserServiceProvider::class);
$this->mergeConfigFrom(__DIR__.'/../../config/amethyst.authentication.php', 'amethyst.authentication');
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"Laravel",
"\\",
"Passport",
"\\",
"PassportServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"Railken",
"\\",
"Amethyst",
"\\",
"Providers",
"\\",
"ApiServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"Railken",
"\\",
"Amethyst",
"\\",
"Providers",
"\\",
"UserServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"__DIR__",
".",
"'/../../config/amethyst.authentication.php'",
",",
"'amethyst.authentication'",
")",
";",
"}"
] | Register any application services.so. | [
"Register",
"any",
"application",
"services",
".",
"so",
"."
] | 59f28ddffa41a5f7fae4d5504eacf7c664e54b46 | https://github.com/railken/amethyst-authentication/blob/59f28ddffa41a5f7fae4d5504eacf7c664e54b46/src/Providers/AuthenticationServiceProvider.php#L37-L43 | train |
AdamB7586/UK_Counties | src/Counties.php | Counties.getCountyID | public static function getCountyID($county){
if(in_array($county, self::$counties)){
$names = array_keys(self::$counties, $county);
return $names[0];
}
return false;
} | php | public static function getCountyID($county){
if(in_array($county, self::$counties)){
$names = array_keys(self::$counties, $county);
return $names[0];
}
return false;
} | [
"public",
"static",
"function",
"getCountyID",
"(",
"$",
"county",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"county",
",",
"self",
"::",
"$",
"counties",
")",
")",
"{",
"$",
"names",
"=",
"array_keys",
"(",
"self",
"::",
"$",
"counties",
",",
"$",
"county",
")",
";",
"return",
"$",
"names",
"[",
"0",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the id of a given county name
@param string $county This should be the county name you wish to find the id for
@return int|false Returns the id of the given county name if it exists else returns false | [
"Returns",
"the",
"id",
"of",
"a",
"given",
"county",
"name"
] | 8e9d34048acde404fce545506750f77b8f8d7275 | https://github.com/AdamB7586/UK_Counties/blob/8e9d34048acde404fce545506750f77b8f8d7275/src/Counties.php#L160-L166 | train |
AdamB7586/UK_Counties | src/Counties.php | Counties.getCountyName | public static function getCountyName($id){
if(is_numeric($id) && array_key_exists(intval($id), self::$counties)){
return self::$counties[intval($id)];
}
return false;
} | php | public static function getCountyName($id){
if(is_numeric($id) && array_key_exists(intval($id), self::$counties)){
return self::$counties[intval($id)];
}
return false;
} | [
"public",
"static",
"function",
"getCountyName",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"id",
")",
"&&",
"array_key_exists",
"(",
"intval",
"(",
"$",
"id",
")",
",",
"self",
"::",
"$",
"counties",
")",
")",
"{",
"return",
"self",
"::",
"$",
"counties",
"[",
"intval",
"(",
"$",
"id",
")",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Returns the county name of a given county id
@param int $id This should be the id of the county you wish to know the name of
@return string|false Will return the county name of the id if it exists else will return false | [
"Returns",
"the",
"county",
"name",
"of",
"a",
"given",
"county",
"id"
] | 8e9d34048acde404fce545506750f77b8f8d7275 | https://github.com/AdamB7586/UK_Counties/blob/8e9d34048acde404fce545506750f77b8f8d7275/src/Counties.php#L173-L178 | train |
GrottoPress/form-field | src/Field.php | Field.metaString | protected function metaString(): string
{
if (!$this->meta) {
return '';
}
return \join(' ', \array_map(function (string $key, $value): string {
return $this->slugify($key).'="'.$this->escape->attr($value).'"';
}, \array_keys($this->meta), \array_values($this->meta)));
} | php | protected function metaString(): string
{
if (!$this->meta) {
return '';
}
return \join(' ', \array_map(function (string $key, $value): string {
return $this->slugify($key).'="'.$this->escape->attr($value).'"';
}, \array_keys($this->meta), \array_values($this->meta)));
} | [
"protected",
"function",
"metaString",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"meta",
")",
"{",
"return",
"''",
";",
"}",
"return",
"\\",
"join",
"(",
"' '",
",",
"\\",
"array_map",
"(",
"function",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"slugify",
"(",
"$",
"key",
")",
".",
"'=\"'",
".",
"$",
"this",
"->",
"escape",
"->",
"attr",
"(",
"$",
"value",
")",
".",
"'\"'",
";",
"}",
",",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"meta",
")",
",",
"\\",
"array_values",
"(",
"$",
"this",
"->",
"meta",
")",
")",
")",
";",
"}"
] | Convert meta to string | [
"Convert",
"meta",
"to",
"string"
] | 6566ee2e0d1bab2176c74dedae3f01f86048ac11 | https://github.com/GrottoPress/form-field/blob/6566ee2e0d1bab2176c74dedae3f01f86048ac11/src/Field.php#L369-L378 | train |
GrottoPress/form-field | src/Field.php | Field.equiv | protected function equiv($a, $b): bool
{
if (\is_array($a) && \is_scalar($b)) {
return \in_array($b, $a);
}
if (\is_array($b) && \is_scalar($a)) {
return \in_array($a, $b);
}
return ($a == $b);
} | php | protected function equiv($a, $b): bool
{
if (\is_array($a) && \is_scalar($b)) {
return \in_array($b, $a);
}
if (\is_array($b) && \is_scalar($a)) {
return \in_array($a, $b);
}
return ($a == $b);
} | [
"protected",
"function",
"equiv",
"(",
"$",
"a",
",",
"$",
"b",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"a",
")",
"&&",
"\\",
"is_scalar",
"(",
"$",
"b",
")",
")",
"{",
"return",
"\\",
"in_array",
"(",
"$",
"b",
",",
"$",
"a",
")",
";",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"b",
")",
"&&",
"\\",
"is_scalar",
"(",
"$",
"a",
")",
")",
"{",
"return",
"\\",
"in_array",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"}",
"return",
"(",
"$",
"a",
"==",
"$",
"b",
")",
";",
"}"
] | Are two values equivalent.
For the purposes of this class, equivalence is defined as:
- When the two variables have equal values;
- When the two variables have identical values;
- When one variable's value is contained in the other variable's value,
where any one of the variables is a set/array.
@param mixed $a
@param mixed $b | [
"Are",
"two",
"values",
"equivalent",
"."
] | 6566ee2e0d1bab2176c74dedae3f01f86048ac11 | https://github.com/GrottoPress/form-field/blob/6566ee2e0d1bab2176c74dedae3f01f86048ac11/src/Field.php#L419-L430 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/Worker/WorkerRunnerManager.php | WorkerRunnerManager.addRunner | public function addRunner($name, WorkerRunnerInterface $runner, array $options = array())
{
$this->runners[$name] = array(
'runner' => $runner,
'options' => $options,
);
} | php | public function addRunner($name, WorkerRunnerInterface $runner, array $options = array())
{
$this->runners[$name] = array(
'runner' => $runner,
'options' => $options,
);
} | [
"public",
"function",
"addRunner",
"(",
"$",
"name",
",",
"WorkerRunnerInterface",
"$",
"runner",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"runners",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"'runner'",
"=>",
"$",
"runner",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
";",
"}"
] | Register runner.
@param string $name Worker name.
@param WorkerRunnerInterface $runner Worker runner.
@param array $options Worker options. | [
"Register",
"runner",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/Worker/WorkerRunnerManager.php#L30-L36 | train |
Gendoria/command-queue | src/Gendoria/CommandQueue/Worker/WorkerRunnerManager.php | WorkerRunnerManager.run | public function run($name, OutputInterface $output = null)
{
if (!$this->has($name)) {
throw new InvalidArgumentException("No runner service registered for provided name.");
}
/* @var $runner WorkerRunnerInterface */
$runner = $this->runners[$name]['runner'];
$runner->run($this->runners[$name]['options'], $output);
} | php | public function run($name, OutputInterface $output = null)
{
if (!$this->has($name)) {
throw new InvalidArgumentException("No runner service registered for provided name.");
}
/* @var $runner WorkerRunnerInterface */
$runner = $this->runners[$name]['runner'];
$runner->run($this->runners[$name]['options'], $output);
} | [
"public",
"function",
"run",
"(",
"$",
"name",
",",
"OutputInterface",
"$",
"output",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"No runner service registered for provided name.\"",
")",
";",
"}",
"/* @var $runner WorkerRunnerInterface */",
"$",
"runner",
"=",
"$",
"this",
"->",
"runners",
"[",
"$",
"name",
"]",
"[",
"'runner'",
"]",
";",
"$",
"runner",
"->",
"run",
"(",
"$",
"this",
"->",
"runners",
"[",
"$",
"name",
"]",
"[",
"'options'",
"]",
",",
"$",
"output",
")",
";",
"}"
] | Run worker.
@param string $name
@param OutputInterface $output
@return void
@throws InvalidArgumentException Thrown, if worker cannto be found for provided name.
@throws Exception Can be thrown, if runner resulted with an error. | [
"Run",
"worker",
"."
] | 4e1094570705942f2ce3b2c976b5b251c3c84b40 | https://github.com/Gendoria/command-queue/blob/4e1094570705942f2ce3b2c976b5b251c3c84b40/src/Gendoria/CommandQueue/Worker/WorkerRunnerManager.php#L58-L66 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/config/ConfigService.php | ConfigService.insertSnippet | public function insertSnippet(Plugin $plugin, $text, &$log = '')
{
$snippetProperties = $this->readProperties($text);
$configContents = file_get_contents($this->configFileLocation);
if (stripos($configContents, "BEGIN PLUGIN CONFIG: {$plugin->Slug}") === false) {
/* foreach($snippetProperties as $name => $value) {
if($this->ApplicationContext->propertyExists($name))
$log .= "
/////////////////////////////
WARNING, plugin configuration property exists in context already: ['.$name.']
/////////////////////////////\n\n";
} */
$configContents .= "\n\n// BEGIN PLUGIN CONFIG: {$plugin->Slug}\n";
$configContents .= $text."\n";
$configContents .= "// END PLUGIN CONFIG: {$plugin->Slug}\n";
if(!is_writable($this->configFileLocation))
{
$log .= "/////////////////////////////
WARNING, UNABLE TO WRITE TO YOUR CONFIG FILE.
PLEASE ADD THE FOLLOWING TO [".$this->configFileLocation."]:\n
".$configContents."\n
/////////////////////////////";
return false;
} else {
FileSystemUtils::safeFilePutContents($this->configFileLocation, $configContents);
}
} else {
foreach($snippetProperties as $name => $value)
if (!$this->ApplicationContext->propertyExists($name))
$log .= "
/////////////////////////////
WARNING, YOU MUST ADD THE NEW CONFIG PROPERTY TO ".$this->configFileLocation.":
\$properties['$name'] = ".$value.";
/////////////////////////////\n\n";
return false;
}
return true;
} | php | public function insertSnippet(Plugin $plugin, $text, &$log = '')
{
$snippetProperties = $this->readProperties($text);
$configContents = file_get_contents($this->configFileLocation);
if (stripos($configContents, "BEGIN PLUGIN CONFIG: {$plugin->Slug}") === false) {
/* foreach($snippetProperties as $name => $value) {
if($this->ApplicationContext->propertyExists($name))
$log .= "
/////////////////////////////
WARNING, plugin configuration property exists in context already: ['.$name.']
/////////////////////////////\n\n";
} */
$configContents .= "\n\n// BEGIN PLUGIN CONFIG: {$plugin->Slug}\n";
$configContents .= $text."\n";
$configContents .= "// END PLUGIN CONFIG: {$plugin->Slug}\n";
if(!is_writable($this->configFileLocation))
{
$log .= "/////////////////////////////
WARNING, UNABLE TO WRITE TO YOUR CONFIG FILE.
PLEASE ADD THE FOLLOWING TO [".$this->configFileLocation."]:\n
".$configContents."\n
/////////////////////////////";
return false;
} else {
FileSystemUtils::safeFilePutContents($this->configFileLocation, $configContents);
}
} else {
foreach($snippetProperties as $name => $value)
if (!$this->ApplicationContext->propertyExists($name))
$log .= "
/////////////////////////////
WARNING, YOU MUST ADD THE NEW CONFIG PROPERTY TO ".$this->configFileLocation.":
\$properties['$name'] = ".$value.";
/////////////////////////////\n\n";
return false;
}
return true;
} | [
"public",
"function",
"insertSnippet",
"(",
"Plugin",
"$",
"plugin",
",",
"$",
"text",
",",
"&",
"$",
"log",
"=",
"''",
")",
"{",
"$",
"snippetProperties",
"=",
"$",
"this",
"->",
"readProperties",
"(",
"$",
"text",
")",
";",
"$",
"configContents",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"configFileLocation",
")",
";",
"if",
"(",
"stripos",
"(",
"$",
"configContents",
",",
"\"BEGIN PLUGIN CONFIG: {$plugin->Slug}\"",
")",
"===",
"false",
")",
"{",
"/* foreach($snippetProperties as $name => $value) {\n if($this->ApplicationContext->propertyExists($name))\n $log .= \"\n /////////////////////////////\n WARNING, plugin configuration property exists in context already: ['.$name.']\n /////////////////////////////\\n\\n\";\n } */",
"$",
"configContents",
".=",
"\"\\n\\n// BEGIN PLUGIN CONFIG: {$plugin->Slug}\\n\"",
";",
"$",
"configContents",
".=",
"$",
"text",
".",
"\"\\n\"",
";",
"$",
"configContents",
".=",
"\"// END PLUGIN CONFIG: {$plugin->Slug}\\n\"",
";",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"this",
"->",
"configFileLocation",
")",
")",
"{",
"$",
"log",
".=",
"\"/////////////////////////////\nWARNING, UNABLE TO WRITE TO YOUR CONFIG FILE.\nPLEASE ADD THE FOLLOWING TO [\"",
".",
"$",
"this",
"->",
"configFileLocation",
".",
"\"]:\\n\n\"",
".",
"$",
"configContents",
".",
"\"\\n\n/////////////////////////////\"",
";",
"return",
"false",
";",
"}",
"else",
"{",
"FileSystemUtils",
"::",
"safeFilePutContents",
"(",
"$",
"this",
"->",
"configFileLocation",
",",
"$",
"configContents",
")",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"snippetProperties",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"if",
"(",
"!",
"$",
"this",
"->",
"ApplicationContext",
"->",
"propertyExists",
"(",
"$",
"name",
")",
")",
"$",
"log",
".=",
"\"\n/////////////////////////////\nWARNING, YOU MUST ADD THE NEW CONFIG PROPERTY TO \"",
".",
"$",
"this",
"->",
"configFileLocation",
".",
"\":\n\\$properties['$name'] = \"",
".",
"$",
"value",
".",
"\";\n/////////////////////////////\\n\\n\"",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Write the specified text to the config file
@param Plugin $plugin The plugin that requested the addition
@param string $text The text to add
@param string &$log Holds a log of the changes made
@return true | [
"Write",
"the",
"specified",
"text",
"to",
"the",
"config",
"file"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/config/ConfigService.php#L84-L128 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/config/ConfigService.php | ConfigService.readProperties | public function readProperties($config = null, $filter = null)
{
if(is_null($config))
$config = file_get_contents($this->configFileLocation);
$props = preg_match_all('/\s*\$properties\[[\'\"]([^\"^\']+)[\'\"]\]\s*=\s*(.*?);[\n\r\t]?/s', $config, $m);
$config = array();
foreach ($m[1] as $i => $key) {
if ($filter == null || stripos($key, $filter) !== false || stripos($m[2][$i], $filter) !== false)
$config[(string)$key] = (string)$m[2][$i];
}
return $config;
} | php | public function readProperties($config = null, $filter = null)
{
if(is_null($config))
$config = file_get_contents($this->configFileLocation);
$props = preg_match_all('/\s*\$properties\[[\'\"]([^\"^\']+)[\'\"]\]\s*=\s*(.*?);[\n\r\t]?/s', $config, $m);
$config = array();
foreach ($m[1] as $i => $key) {
if ($filter == null || stripos($key, $filter) !== false || stripos($m[2][$i], $filter) !== false)
$config[(string)$key] = (string)$m[2][$i];
}
return $config;
} | [
"public",
"function",
"readProperties",
"(",
"$",
"config",
"=",
"null",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"config",
")",
")",
"$",
"config",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"configFileLocation",
")",
";",
"$",
"props",
"=",
"preg_match_all",
"(",
"'/\\s*\\$properties\\[[\\'\\\"]([^\\\"^\\']+)[\\'\\\"]\\]\\s*=\\s*(.*?);[\\n\\r\\t]?/s'",
",",
"$",
"config",
",",
"$",
"m",
")",
";",
"$",
"config",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"m",
"[",
"1",
"]",
"as",
"$",
"i",
"=>",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"filter",
"==",
"null",
"||",
"stripos",
"(",
"$",
"key",
",",
"$",
"filter",
")",
"!==",
"false",
"||",
"stripos",
"(",
"$",
"m",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
",",
"$",
"filter",
")",
"!==",
"false",
")",
"$",
"config",
"[",
"(",
"string",
")",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"m",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Parses the properties file.
NOTE: Even though the properties file looks like php, and ends in a .php extension,
we just parse it out all by hand here.
@param string $config The contents of the config file to parse.
If not specified, it will use the config file from $this->configFileLocation
@param string $filter If specified, no config items with this in the name will be returned
@return array Returns an array of the config properties. | [
"Parses",
"the",
"properties",
"file",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/config/ConfigService.php#L142-L157 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/config/ConfigService.php | ConfigService.saveContents | public function saveContents($contents)
{
$path = pathinfo($this->configFileLocation);
//BACKUP CURRENT config.php
$backup = $this->backupPath.'/pluginconfig.'.date('Y_m_d_His').'.php';
FileSystemUtils::safeCopy($this->configFileLocation, $backup);
//OVERWRITE config.php WITH POSTED CONTENTS
FileSystemUtils::safeFilePutContents($this->configFileLocation, $contents);
$this->VersionService->incrementDeploymentRevision('Saved config.php');
} | php | public function saveContents($contents)
{
$path = pathinfo($this->configFileLocation);
//BACKUP CURRENT config.php
$backup = $this->backupPath.'/pluginconfig.'.date('Y_m_d_His').'.php';
FileSystemUtils::safeCopy($this->configFileLocation, $backup);
//OVERWRITE config.php WITH POSTED CONTENTS
FileSystemUtils::safeFilePutContents($this->configFileLocation, $contents);
$this->VersionService->incrementDeploymentRevision('Saved config.php');
} | [
"public",
"function",
"saveContents",
"(",
"$",
"contents",
")",
"{",
"$",
"path",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"configFileLocation",
")",
";",
"//BACKUP CURRENT config.php",
"$",
"backup",
"=",
"$",
"this",
"->",
"backupPath",
".",
"'/pluginconfig.'",
".",
"date",
"(",
"'Y_m_d_His'",
")",
".",
"'.php'",
";",
"FileSystemUtils",
"::",
"safeCopy",
"(",
"$",
"this",
"->",
"configFileLocation",
",",
"$",
"backup",
")",
";",
"//OVERWRITE config.php WITH POSTED CONTENTS",
"FileSystemUtils",
"::",
"safeFilePutContents",
"(",
"$",
"this",
"->",
"configFileLocation",
",",
"$",
"contents",
")",
";",
"$",
"this",
"->",
"VersionService",
"->",
"incrementDeploymentRevision",
"(",
"'Saved config.php'",
")",
";",
"}"
] | Writes the contents to the config file, after first
backing up the current config
@param string $contents The contents to write to the config file
@return void | [
"Writes",
"the",
"contents",
"to",
"the",
"config",
"file",
"after",
"first",
"backing",
"up",
"the",
"current",
"config"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/config/ConfigService.php#L167-L181 | train |
Blipfoto/php-sdk | src/Blipfoto/Api/Request.php | Request.header | public function header() {
$args = func_get_args();
$name = $args[0];
if (count($args) == 2) {
$this->headers[$name] = $args[1];
}
return $this->headers[$name];
} | php | public function header() {
$args = func_get_args();
$name = $args[0];
if (count($args) == 2) {
$this->headers[$name] = $args[1];
}
return $this->headers[$name];
} | [
"public",
"function",
"header",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"name",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
";",
"}"
] | Get and optionally set a header.
@param string $name
@param mixed $value (optional)
@return mixed | [
"Get",
"and",
"optionally",
"set",
"a",
"header",
"."
] | 04f770ac7427e79d15f97b993c787651079cdeb4 | https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Request.php#L88-L95 | train |
Blipfoto/php-sdk | src/Blipfoto/Api/Request.php | Request.url | public function url() {
$url = $this->client->endpoint() . $this->resource . '.json';
if (in_array($this->method, ['GET', 'DELETE']) && $this->params !== null) {
$url .= '?' . http_build_query($this->params);
}
return $url;
} | php | public function url() {
$url = $this->client->endpoint() . $this->resource . '.json';
if (in_array($this->method, ['GET', 'DELETE']) && $this->params !== null) {
$url .= '?' . http_build_query($this->params);
}
return $url;
} | [
"public",
"function",
"url",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"client",
"->",
"endpoint",
"(",
")",
".",
"$",
"this",
"->",
"resource",
".",
"'.json'",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"method",
",",
"[",
"'GET'",
",",
"'DELETE'",
"]",
")",
"&&",
"$",
"this",
"->",
"params",
"!==",
"null",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"this",
"->",
"params",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Return the request url.
@return string | [
"Return",
"the",
"request",
"url",
"."
] | 04f770ac7427e79d15f97b993c787651079cdeb4 | https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Request.php#L111-L117 | train |
Blipfoto/php-sdk | src/Blipfoto/Api/Request.php | Request.send | public function send() {
$url = $this->url();
// Set fields for post or put requests.
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $this->method);
if (in_array($this->method, ['POST', 'PUT'])) {
$this->buildBody();
} else {
$this->header('Content-Type', null);
}
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
// Capture rate limit response headers.
$rate_limit = [];
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$rate_limit) {
$parts = explode(':', trim($header), 2);
if (isset($parts[1]) && preg_match('/^X-RateLimit-(.*)/', $parts[0], $match)) {
$rate_limit[$match[1]] = (int) $parts[1];
}
return strlen($header);
});
// Set authorization.
$access_token = $this->client->accessToken();
if ($access_token === null) {
$this->setBearerToken($this->client->id());
} else {
$this->setBearerToken($access_token);
}
// Add headers.
$headers = [];
foreach ($this->headers as $name => $value) {
if ($value !== null) {
$headers[] = $name . ': ' . $value;
}
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
}
// Allow the client to access the request before it is sent.
$before = $this->client->before();
if (is_callable($before)) {
$before($this);
}
// Get response,
$body = @curl_exec($this->curl);
// Allow the client to access the request after it is sent.
$after = $this->client->after();
if (is_callable($after)) {
$after($this);
}
// Get status and error info before closing the handle.
$http_status = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
$error_code = curl_errno($this->curl);
$error_message = curl_error($this->curl);
@curl_close($this->curl);
// Check for curl error.
if ($error_code > 0) {
throw new NetworkException($error_message, $error_code);
}
return new Response($body, $http_status, $rate_limit);
} | php | public function send() {
$url = $this->url();
// Set fields for post or put requests.
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $this->method);
if (in_array($this->method, ['POST', 'PUT'])) {
$this->buildBody();
} else {
$this->header('Content-Type', null);
}
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
// Capture rate limit response headers.
$rate_limit = [];
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$rate_limit) {
$parts = explode(':', trim($header), 2);
if (isset($parts[1]) && preg_match('/^X-RateLimit-(.*)/', $parts[0], $match)) {
$rate_limit[$match[1]] = (int) $parts[1];
}
return strlen($header);
});
// Set authorization.
$access_token = $this->client->accessToken();
if ($access_token === null) {
$this->setBearerToken($this->client->id());
} else {
$this->setBearerToken($access_token);
}
// Add headers.
$headers = [];
foreach ($this->headers as $name => $value) {
if ($value !== null) {
$headers[] = $name . ': ' . $value;
}
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
}
// Allow the client to access the request before it is sent.
$before = $this->client->before();
if (is_callable($before)) {
$before($this);
}
// Get response,
$body = @curl_exec($this->curl);
// Allow the client to access the request after it is sent.
$after = $this->client->after();
if (is_callable($after)) {
$after($this);
}
// Get status and error info before closing the handle.
$http_status = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
$error_code = curl_errno($this->curl);
$error_message = curl_error($this->curl);
@curl_close($this->curl);
// Check for curl error.
if ($error_code > 0) {
throw new NetworkException($error_message, $error_code);
}
return new Response($body, $http_status, $rate_limit);
} | [
"public",
"function",
"send",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
"(",
")",
";",
"// Set fields for post or put requests.",
"$",
"this",
"->",
"curl",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"this",
"->",
"method",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"method",
",",
"[",
"'POST'",
",",
"'PUT'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buildBody",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"header",
"(",
"'Content-Type'",
",",
"null",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"// Capture rate limit response headers.",
"$",
"rate_limit",
"=",
"[",
"]",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_HEADERFUNCTION",
",",
"function",
"(",
"$",
"curl",
",",
"$",
"header",
")",
"use",
"(",
"&",
"$",
"rate_limit",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"trim",
"(",
"$",
"header",
")",
",",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"&&",
"preg_match",
"(",
"'/^X-RateLimit-(.*)/'",
",",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"match",
")",
")",
"{",
"$",
"rate_limit",
"[",
"$",
"match",
"[",
"1",
"]",
"]",
"=",
"(",
"int",
")",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"return",
"strlen",
"(",
"$",
"header",
")",
";",
"}",
")",
";",
"// Set authorization.",
"$",
"access_token",
"=",
"$",
"this",
"->",
"client",
"->",
"accessToken",
"(",
")",
";",
"if",
"(",
"$",
"access_token",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setBearerToken",
"(",
"$",
"this",
"->",
"client",
"->",
"id",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setBearerToken",
"(",
"$",
"access_token",
")",
";",
"}",
"// Add headers.",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"name",
".",
"': '",
".",
"$",
"value",
";",
"}",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"}",
"// Allow the client to access the request before it is sent.",
"$",
"before",
"=",
"$",
"this",
"->",
"client",
"->",
"before",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"before",
")",
")",
"{",
"$",
"before",
"(",
"$",
"this",
")",
";",
"}",
"// Get response,",
"$",
"body",
"=",
"@",
"curl_exec",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"// Allow the client to access the request after it is sent.",
"$",
"after",
"=",
"$",
"this",
"->",
"client",
"->",
"after",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"after",
")",
")",
"{",
"$",
"after",
"(",
"$",
"this",
")",
";",
"}",
"// Get status and error info before closing the handle.",
"$",
"http_status",
"=",
"curl_getinfo",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"$",
"error_code",
"=",
"curl_errno",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"$",
"error_message",
"=",
"curl_error",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"@",
"curl_close",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"// Check for curl error.",
"if",
"(",
"$",
"error_code",
">",
"0",
")",
"{",
"throw",
"new",
"NetworkException",
"(",
"$",
"error_message",
",",
"$",
"error_code",
")",
";",
"}",
"return",
"new",
"Response",
"(",
"$",
"body",
",",
"$",
"http_status",
",",
"$",
"rate_limit",
")",
";",
"}"
] | Make a request and return the response data if successful.
@return Response
@throws NetworkException | [
"Make",
"a",
"request",
"and",
"return",
"the",
"response",
"data",
"if",
"successful",
"."
] | 04f770ac7427e79d15f97b993c787651079cdeb4 | https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Request.php#L125-L194 | train |
Blipfoto/php-sdk | src/Blipfoto/Api/Request.php | Request.buildBody | protected function buildBody() {
// If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads
// will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off
// and use CurlFile.
if (count($this->files())) {
$body = [];
foreach ($this->params as $key => $value) {
$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"", "", $value]);
}
foreach ($this->files as $key => $path) {
$file = new File($path);
$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file->name()}\"", "Content-Type: application/octet-stream", "", $file->contents()]);
}
do {
$boundary = "---------------------" . md5(mt_rand() . microtime());
} while (preg_grep("/{$boundary}/", $body));
foreach ($body as $i => $part) {
$body[$i] = "--{$boundary}\r\n" . $part;
}
$body[] = "--{$boundary}--";
$body[] = "";
curl_setopt($this->curl, CURLOPT_POSTFIELDS, implode("\r\n", $body));
$this->header('Content-Type', 'multipart/form-data; boundary=' . $boundary);
} else {
curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($this->params));
$this->header('Content-Type', 'application/x-www-form-urlencoded');
}
} | php | protected function buildBody() {
// If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads
// will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off
// and use CurlFile.
if (count($this->files())) {
$body = [];
foreach ($this->params as $key => $value) {
$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"", "", $value]);
}
foreach ($this->files as $key => $path) {
$file = new File($path);
$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file->name()}\"", "Content-Type: application/octet-stream", "", $file->contents()]);
}
do {
$boundary = "---------------------" . md5(mt_rand() . microtime());
} while (preg_grep("/{$boundary}/", $body));
foreach ($body as $i => $part) {
$body[$i] = "--{$boundary}\r\n" . $part;
}
$body[] = "--{$boundary}--";
$body[] = "";
curl_setopt($this->curl, CURLOPT_POSTFIELDS, implode("\r\n", $body));
$this->header('Content-Type', 'multipart/form-data; boundary=' . $boundary);
} else {
curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($this->params));
$this->header('Content-Type', 'application/x-www-form-urlencoded');
}
} | [
"protected",
"function",
"buildBody",
"(",
")",
"{",
"// If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads",
"// will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off",
"// and use CurlFile.",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"files",
"(",
")",
")",
")",
"{",
"$",
"body",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"body",
"[",
"]",
"=",
"implode",
"(",
"\"\\r\\n\"",
",",
"[",
"\"Content-Disposition: form-data; name=\\\"{$key}\\\"\"",
",",
"\"\"",
",",
"$",
"value",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"files",
"as",
"$",
"key",
"=>",
"$",
"path",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"path",
")",
";",
"$",
"body",
"[",
"]",
"=",
"implode",
"(",
"\"\\r\\n\"",
",",
"[",
"\"Content-Disposition: form-data; name=\\\"{$key}\\\"; filename=\\\"{$file->name()}\\\"\"",
",",
"\"Content-Type: application/octet-stream\"",
",",
"\"\"",
",",
"$",
"file",
"->",
"contents",
"(",
")",
"]",
")",
";",
"}",
"do",
"{",
"$",
"boundary",
"=",
"\"---------------------\"",
".",
"md5",
"(",
"mt_rand",
"(",
")",
".",
"microtime",
"(",
")",
")",
";",
"}",
"while",
"(",
"preg_grep",
"(",
"\"/{$boundary}/\"",
",",
"$",
"body",
")",
")",
";",
"foreach",
"(",
"$",
"body",
"as",
"$",
"i",
"=>",
"$",
"part",
")",
"{",
"$",
"body",
"[",
"$",
"i",
"]",
"=",
"\"--{$boundary}\\r\\n\"",
".",
"$",
"part",
";",
"}",
"$",
"body",
"[",
"]",
"=",
"\"--{$boundary}--\"",
";",
"$",
"body",
"[",
"]",
"=",
"\"\"",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"body",
")",
")",
";",
"$",
"this",
"->",
"header",
"(",
"'Content-Type'",
",",
"'multipart/form-data; boundary='",
".",
"$",
"boundary",
")",
";",
"}",
"else",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"curl",
",",
"CURLOPT_POSTFIELDS",
",",
"http_build_query",
"(",
"$",
"this",
"->",
"params",
")",
")",
";",
"$",
"this",
"->",
"header",
"(",
"'Content-Type'",
",",
"'application/x-www-form-urlencoded'",
")",
";",
"}",
"}"
] | Build the request body. | [
"Build",
"the",
"request",
"body",
"."
] | 04f770ac7427e79d15f97b993c787651079cdeb4 | https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/Request.php#L208-L239 | train |
gplcart/cli | controllers/commands/Trigger.php | Trigger.cmdGetTrigger | public function cmdGetTrigger()
{
$result = $this->getListTrigger();
$this->outputFormat($result);
$this->outputFormatTableTrigger($result);
$this->output();
} | php | public function cmdGetTrigger()
{
$result = $this->getListTrigger();
$this->outputFormat($result);
$this->outputFormatTableTrigger($result);
$this->output();
} | [
"public",
"function",
"cmdGetTrigger",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListTrigger",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableTrigger",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "trigger-get" command | [
"Callback",
"for",
"trigger",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Trigger.php#L40-L46 | train |
gplcart/cli | controllers/commands/Trigger.php | Trigger.cmdUpdateTrigger | public function cmdUpdateTrigger()
{
$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->setSubmitted('data.conditions', $this->getSubmitted('conditions'));
$this->setSubmittedList('data.conditions');
$this->setSubmitted('update', $params[0]);
$this->validateComponent('trigger');
$this->updateTrigger($params[0]);
$this->output();
} | php | public function cmdUpdateTrigger()
{
$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->setSubmitted('data.conditions', $this->getSubmitted('conditions'));
$this->setSubmittedList('data.conditions');
$this->setSubmitted('update', $params[0]);
$this->validateComponent('trigger');
$this->updateTrigger($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateTrigger",
"(",
")",
"{",
"$",
"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",
"->",
"setSubmitted",
"(",
"'data.conditions'",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
"'conditions'",
")",
")",
";",
"$",
"this",
"->",
"setSubmittedList",
"(",
"'data.conditions'",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'trigger'",
")",
";",
"$",
"this",
"->",
"updateTrigger",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "trigger-update" command | [
"Callback",
"for",
"trigger",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Trigger.php#L96-L117 | train |
gplcart/cli | controllers/commands/Trigger.php | Trigger.addTrigger | protected function addTrigger()
{
if (!$this->isError()) {
$state_id = $this->trigger->add($this->getSubmitted());
if (empty($state_id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($state_id);
}
} | php | protected function addTrigger()
{
if (!$this->isError()) {
$state_id = $this->trigger->add($this->getSubmitted());
if (empty($state_id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($state_id);
}
} | [
"protected",
"function",
"addTrigger",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"state_id",
"=",
"$",
"this",
"->",
"trigger",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"state_id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"state_id",
")",
";",
"}",
"}"
] | Add a new trigger | [
"Add",
"a",
"new",
"trigger"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Trigger.php#L180-L189 | train |
gplcart/cli | controllers/commands/Trigger.php | Trigger.submitAddTrigger | protected function submitAddTrigger()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmitted('data.conditions', $this->getSubmitted('conditions'));
$this->setSubmittedList('data.conditions');
$this->validateComponent('trigger');
$this->addTrigger();
} | php | protected function submitAddTrigger()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmitted('data.conditions', $this->getSubmitted('conditions'));
$this->setSubmittedList('data.conditions');
$this->validateComponent('trigger');
$this->addTrigger();
} | [
"protected",
"function",
"submitAddTrigger",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'data.conditions'",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
"'conditions'",
")",
")",
";",
"$",
"this",
"->",
"setSubmittedList",
"(",
"'data.conditions'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'trigger'",
")",
";",
"$",
"this",
"->",
"addTrigger",
"(",
")",
";",
"}"
] | Add a new trigger at once | [
"Add",
"a",
"new",
"trigger",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Trigger.php#L205-L213 | train |
gplcart/cli | controllers/commands/Trigger.php | Trigger.wizardAddTrigger | protected function wizardAddTrigger()
{
$this->validatePrompt('name', $this->text('Name'), 'trigger');
$this->validatePrompt('store_id', $this->text('Store'), 'trigger');
$this->validatePromptList('data.conditions', $this->text('Conditions'), 'trigger');
$this->validatePrompt('status', $this->text('Status'), 'trigger', 0);
$this->validatePrompt('weight', $this->text('Weight'), 'trigger', 0);
$this->setSubmittedList('data.conditions');
$this->validateComponent('trigger');
$this->addTrigger();
} | php | protected function wizardAddTrigger()
{
$this->validatePrompt('name', $this->text('Name'), 'trigger');
$this->validatePrompt('store_id', $this->text('Store'), 'trigger');
$this->validatePromptList('data.conditions', $this->text('Conditions'), 'trigger');
$this->validatePrompt('status', $this->text('Status'), 'trigger', 0);
$this->validatePrompt('weight', $this->text('Weight'), 'trigger', 0);
$this->setSubmittedList('data.conditions');
$this->validateComponent('trigger');
$this->addTrigger();
} | [
"protected",
"function",
"wizardAddTrigger",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'name'",
",",
"$",
"this",
"->",
"text",
"(",
"'Name'",
")",
",",
"'trigger'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'store_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Store'",
")",
",",
"'trigger'",
")",
";",
"$",
"this",
"->",
"validatePromptList",
"(",
"'data.conditions'",
",",
"$",
"this",
"->",
"text",
"(",
"'Conditions'",
")",
",",
"'trigger'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'trigger'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'weight'",
",",
"$",
"this",
"->",
"text",
"(",
"'Weight'",
")",
",",
"'trigger'",
",",
"0",
")",
";",
"$",
"this",
"->",
"setSubmittedList",
"(",
"'data.conditions'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'trigger'",
")",
";",
"$",
"this",
"->",
"addTrigger",
"(",
")",
";",
"}"
] | Add a trigger step by step | [
"Add",
"a",
"trigger",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Trigger.php#L218-L229 | train |
valu-digital/valusetup | src/ValuSetup/Service/AuthService.php | AuthService.getIdentity | public function getIdentity()
{
if($this->hasIdentity()){
if($this->identity === null){
$identity = $this->authenticationService->getIdentity();
$identity = array_merge(
$identity,
$this->getOption('identity')
);
// Extend with real identity information
if ($this->getServiceBroker()->exists('User')) {
$userService = $this->getServiceBroker()->service('User');
// Access filter needs to be disabled to prevent infinite looping
$userService->disableFilter('access');
$extension = $userService->find(
'$'.$identity['username'],
array('id', 'email')
);
if ($extension) {
$identity = array_merge($identity, $extension);
}
}
$this->identity = $identity;
}
return $this->identity;
}
else{
return null;
}
} | php | public function getIdentity()
{
if($this->hasIdentity()){
if($this->identity === null){
$identity = $this->authenticationService->getIdentity();
$identity = array_merge(
$identity,
$this->getOption('identity')
);
// Extend with real identity information
if ($this->getServiceBroker()->exists('User')) {
$userService = $this->getServiceBroker()->service('User');
// Access filter needs to be disabled to prevent infinite looping
$userService->disableFilter('access');
$extension = $userService->find(
'$'.$identity['username'],
array('id', 'email')
);
if ($extension) {
$identity = array_merge($identity, $extension);
}
}
$this->identity = $identity;
}
return $this->identity;
}
else{
return null;
}
} | [
"public",
"function",
"getIdentity",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasIdentity",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"identity",
"===",
"null",
")",
"{",
"$",
"identity",
"=",
"$",
"this",
"->",
"authenticationService",
"->",
"getIdentity",
"(",
")",
";",
"$",
"identity",
"=",
"array_merge",
"(",
"$",
"identity",
",",
"$",
"this",
"->",
"getOption",
"(",
"'identity'",
")",
")",
";",
"// Extend with real identity information",
"if",
"(",
"$",
"this",
"->",
"getServiceBroker",
"(",
")",
"->",
"exists",
"(",
"'User'",
")",
")",
"{",
"$",
"userService",
"=",
"$",
"this",
"->",
"getServiceBroker",
"(",
")",
"->",
"service",
"(",
"'User'",
")",
";",
"// Access filter needs to be disabled to prevent infinite looping",
"$",
"userService",
"->",
"disableFilter",
"(",
"'access'",
")",
";",
"$",
"extension",
"=",
"$",
"userService",
"->",
"find",
"(",
"'$'",
".",
"$",
"identity",
"[",
"'username'",
"]",
",",
"array",
"(",
"'id'",
",",
"'email'",
")",
")",
";",
"if",
"(",
"$",
"extension",
")",
"{",
"$",
"identity",
"=",
"array_merge",
"(",
"$",
"identity",
",",
"$",
"extension",
")",
";",
"}",
"}",
"$",
"this",
"->",
"identity",
"=",
"$",
"identity",
";",
"}",
"return",
"$",
"this",
"->",
"identity",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Returns the identity or null if no identity is available
@return mixed|null | [
"Returns",
"the",
"identity",
"or",
"null",
"if",
"no",
"identity",
"is",
"available"
] | db1a0bfe1262d555eb11cd0d99625b9ee43d6744 | https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AuthService.php#L95-L131 | train |
valu-digital/valusetup | src/ValuSetup/Service/AuthService.php | AuthService.getStorage | public function getStorage()
{
if(!$this->storage && $this->getServiceLocator()->has(self::STORAGE_LOCATOR_KEY)){
$this->setStorage($this->getServiceLocator()->get(self::STORAGE_LOCATOR_KEY));
}
return $this->storage;
} | php | public function getStorage()
{
if(!$this->storage && $this->getServiceLocator()->has(self::STORAGE_LOCATOR_KEY)){
$this->setStorage($this->getServiceLocator()->get(self::STORAGE_LOCATOR_KEY));
}
return $this->storage;
} | [
"public",
"function",
"getStorage",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"storage",
"&&",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"has",
"(",
"self",
"::",
"STORAGE_LOCATOR_KEY",
")",
")",
"{",
"$",
"this",
"->",
"setStorage",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"STORAGE_LOCATOR_KEY",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"storage",
";",
"}"
] | Retrieve storage instance
@return \Zend\Authentication\Storage\StorageInterface
@ValuService\Exclude | [
"Retrieve",
"storage",
"instance"
] | db1a0bfe1262d555eb11cd0d99625b9ee43d6744 | https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AuthService.php#L172-L179 | train |
valu-digital/valusetup | src/ValuSetup/Service/AuthService.php | AuthService.getAuthenticationService | protected function getAuthenticationService()
{
if ($this->authenticationService === null) {
$this->authenticationService = new AuthenticationService($this->getStorage());
}
return $this->authenticationService;
} | php | protected function getAuthenticationService()
{
if ($this->authenticationService === null) {
$this->authenticationService = new AuthenticationService($this->getStorage());
}
return $this->authenticationService;
} | [
"protected",
"function",
"getAuthenticationService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"authenticationService",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"authenticationService",
"=",
"new",
"AuthenticationService",
"(",
"$",
"this",
"->",
"getStorage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"authenticationService",
";",
"}"
] | Retrieve AuthenticationService instance
@return \Zend\Authentication\AuthenticationService | [
"Retrieve",
"AuthenticationService",
"instance"
] | db1a0bfe1262d555eb11cd0d99625b9ee43d6744 | https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AuthService.php#L206-L213 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.