repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
gdbots/iam-php | src/Validator/UserValidator.php | UserValidator.createGetUserRequest | protected function createGetUserRequest(Message $message, NodeRef $nodeRef, Pbjx $pbjx): GetUserRequest
{
/** @var GetUserRequest $request */
$request = GetUserRequestV1Mixin::findOne()->createMessage();
return $request;
} | php | protected function createGetUserRequest(Message $message, NodeRef $nodeRef, Pbjx $pbjx): GetUserRequest
{
/** @var GetUserRequest $request */
$request = GetUserRequestV1Mixin::findOne()->createMessage();
return $request;
} | [
"protected",
"function",
"createGetUserRequest",
"(",
"Message",
"$",
"message",
",",
"NodeRef",
"$",
"nodeRef",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"GetUserRequest",
"{",
"/** @var GetUserRequest $request */",
"$",
"request",
"=",
"GetUserRequestV1Mixin",
"::",
"findOne",
"(",
")",
"->",
"createMessage",
"(",
")",
";",
"return",
"$",
"request",
";",
"}"
] | @param Message $message
@param NodeRef $nodeRef
@param Pbjx $pbjx
@return GetUserRequest | [
"@param",
"Message",
"$message",
"@param",
"NodeRef",
"$nodeRef",
"@param",
"Pbjx",
"$pbjx"
] | train | https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/Validator/UserValidator.php#L131-L136 |
mekras/atompub | src/Extension/AtomPubExtension.php | AtomPubExtension.parseDocument | public function parseDocument(Extensions $extensions, \DOMDocument $document)
{
if (AtomPub::NS === $document->documentElement->namespaceURI) {
switch ($document->documentElement->localName) {
case 'service':
// Node name already checked
return new ServiceDocument($extensions, $document);
case 'categories':
// Node name already checked
return new CategoryDocument($extensions, $document);
}
}
return null;
} | php | public function parseDocument(Extensions $extensions, \DOMDocument $document)
{
if (AtomPub::NS === $document->documentElement->namespaceURI) {
switch ($document->documentElement->localName) {
case 'service':
// Node name already checked
return new ServiceDocument($extensions, $document);
case 'categories':
// Node name already checked
return new CategoryDocument($extensions, $document);
}
}
return null;
} | [
"public",
"function",
"parseDocument",
"(",
"Extensions",
"$",
"extensions",
",",
"\\",
"DOMDocument",
"$",
"document",
")",
"{",
"if",
"(",
"AtomPub",
"::",
"NS",
"===",
"$",
"document",
"->",
"documentElement",
"->",
"namespaceURI",
")",
"{",
"switch",
"(",
"$",
"document",
"->",
"documentElement",
"->",
"localName",
")",
"{",
"case",
"'service'",
":",
"// Node name already checked",
"return",
"new",
"ServiceDocument",
"(",
"$",
"extensions",
",",
"$",
"document",
")",
";",
"case",
"'categories'",
":",
"// Node name already checked",
"return",
"new",
"CategoryDocument",
"(",
"$",
"extensions",
",",
"$",
"document",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Create Atom document from XML DOM document.
@param Extensions $extensions Extension registry.
@param \DOMDocument $document Source document.
@return Document|null
@since 1.0 | [
"Create",
"Atom",
"document",
"from",
"XML",
"DOM",
"document",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Extension/AtomPubExtension.php#L40-L54 |
mekras/atompub | src/Extension/AtomPubExtension.php | AtomPubExtension.createDocument | public function createDocument(Extensions $extensions, $name)
{
switch ($name) {
case 'app:service':
// No document — no exception.
return new ServiceDocument($extensions);
case 'app:categories':
// No document — no exception.
return new CategoryDocument($extensions);
}
return null;
} | php | public function createDocument(Extensions $extensions, $name)
{
switch ($name) {
case 'app:service':
// No document — no exception.
return new ServiceDocument($extensions);
case 'app:categories':
// No document — no exception.
return new CategoryDocument($extensions);
}
return null;
} | [
"public",
"function",
"createDocument",
"(",
"Extensions",
"$",
"extensions",
",",
"$",
"name",
")",
"{",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'app:service'",
":",
"// No document — no exception.",
"return",
"new",
"ServiceDocument",
"(",
"$",
"extensions",
")",
";",
"case",
"'app:categories'",
":",
"// No document — no exception.",
"return",
"new",
"CategoryDocument",
"(",
"$",
"extensions",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Create new Atom document.
@param Extensions $extensions Extension registry.
@param string $name Element name.
@return Document|null
@since 1.0 | [
"Create",
"new",
"Atom",
"document",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Extension/AtomPubExtension.php#L66-L78 |
mekras/atompub | src/Extension/AtomPubExtension.php | AtomPubExtension.parseElement | public function parseElement(Node $parent, \DOMElement $element)
{
if (AtomPub::NS === $element->namespaceURI) {
switch ($element->localName) {
case 'collection':
// Node name already checked
return new Collection($parent, $element);
case 'workspace':
// Node name already checked
return new Workspace($parent, $element);
}
}
return null;
} | php | public function parseElement(Node $parent, \DOMElement $element)
{
if (AtomPub::NS === $element->namespaceURI) {
switch ($element->localName) {
case 'collection':
// Node name already checked
return new Collection($parent, $element);
case 'workspace':
// Node name already checked
return new Workspace($parent, $element);
}
}
return null;
} | [
"public",
"function",
"parseElement",
"(",
"Node",
"$",
"parent",
",",
"\\",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"AtomPub",
"::",
"NS",
"===",
"$",
"element",
"->",
"namespaceURI",
")",
"{",
"switch",
"(",
"$",
"element",
"->",
"localName",
")",
"{",
"case",
"'collection'",
":",
"// Node name already checked",
"return",
"new",
"Collection",
"(",
"$",
"parent",
",",
"$",
"element",
")",
";",
"case",
"'workspace'",
":",
"// Node name already checked",
"return",
"new",
"Workspace",
"(",
"$",
"parent",
",",
"$",
"element",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Create Atom node from XML DOM element.
@param Node $parent Parent node.
@param \DOMElement $element DOM element.
@return Element|null
@since 1.0 | [
"Create",
"Atom",
"node",
"from",
"XML",
"DOM",
"element",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Extension/AtomPubExtension.php#L90-L104 |
mekras/atompub | src/Extension/AtomPubExtension.php | AtomPubExtension.createElement | public function createElement(Node $parent, $name)
{
switch ($name) {
case 'app:collection':
return new Collection($parent);
case 'app:workspace':
return new Workspace($parent);
}
return null;
} | php | public function createElement(Node $parent, $name)
{
switch ($name) {
case 'app:collection':
return new Collection($parent);
case 'app:workspace':
return new Workspace($parent);
}
return null;
} | [
"public",
"function",
"createElement",
"(",
"Node",
"$",
"parent",
",",
"$",
"name",
")",
"{",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'app:collection'",
":",
"return",
"new",
"Collection",
"(",
"$",
"parent",
")",
";",
"case",
"'app:workspace'",
":",
"return",
"new",
"Workspace",
"(",
"$",
"parent",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Create new Atom node.
@param Node $parent Parent node.
@param string $name Element name.
@return Element|null
@throws \InvalidArgumentException If $element has invalid namespace.
@since 1.0 | [
"Create",
"new",
"Atom",
"node",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Extension/AtomPubExtension.php#L118-L128 |
ajant/SimpleArrayLibrary | src/Categories/Counters.php | Counters.countMaxDepth | public static function countMaxDepth(array $array)
{
$maxDepth = 1;
foreach ($array as $element) {
$depth = 1;
if (is_array($element)) {
$depth += self::countMaxDepth($element);
}
if ($depth > $maxDepth) $maxDepth = $depth;
}
return $maxDepth;
} | php | public static function countMaxDepth(array $array)
{
$maxDepth = 1;
foreach ($array as $element) {
$depth = 1;
if (is_array($element)) {
$depth += self::countMaxDepth($element);
}
if ($depth > $maxDepth) $maxDepth = $depth;
}
return $maxDepth;
} | [
"public",
"static",
"function",
"countMaxDepth",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"maxDepth",
"=",
"1",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"element",
")",
"{",
"$",
"depth",
"=",
"1",
";",
"if",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"{",
"$",
"depth",
"+=",
"self",
"::",
"countMaxDepth",
"(",
"$",
"element",
")",
";",
"}",
"if",
"(",
"$",
"depth",
">",
"$",
"maxDepth",
")",
"$",
"maxDepth",
"=",
"$",
"depth",
";",
"}",
"return",
"$",
"maxDepth",
";",
"}"
] | Counts maximum array depth recursively
@param array $array
@return int | [
"Counts",
"maximum",
"array",
"depth",
"recursively"
] | train | https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Counters.php#L16-L28 |
ajant/SimpleArrayLibrary | src/Categories/Counters.php | Counters.countMaxDepthIterative | public static function countMaxDepthIterative(array $array)
{
$copy = $array;
$maxDepth = 1;
foreach ($copy as $element) {
$depth = 1;
while (!empty($element)) {
if (is_array($element)) {
++$depth;
$tmp = array_shift($element);
if (is_array($tmp)) {
array_push($element, array_shift($tmp));
}
} else {
break;
}
}
if ($depth > $maxDepth) {
$maxDepth = $depth;
}
}
return $maxDepth;
} | php | public static function countMaxDepthIterative(array $array)
{
$copy = $array;
$maxDepth = 1;
foreach ($copy as $element) {
$depth = 1;
while (!empty($element)) {
if (is_array($element)) {
++$depth;
$tmp = array_shift($element);
if (is_array($tmp)) {
array_push($element, array_shift($tmp));
}
} else {
break;
}
}
if ($depth > $maxDepth) {
$maxDepth = $depth;
}
}
return $maxDepth;
} | [
"public",
"static",
"function",
"countMaxDepthIterative",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"copy",
"=",
"$",
"array",
";",
"$",
"maxDepth",
"=",
"1",
";",
"foreach",
"(",
"$",
"copy",
"as",
"$",
"element",
")",
"{",
"$",
"depth",
"=",
"1",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"element",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"{",
"++",
"$",
"depth",
";",
"$",
"tmp",
"=",
"array_shift",
"(",
"$",
"element",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"tmp",
")",
")",
"{",
"array_push",
"(",
"$",
"element",
",",
"array_shift",
"(",
"$",
"tmp",
")",
")",
";",
"}",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"depth",
">",
"$",
"maxDepth",
")",
"{",
"$",
"maxDepth",
"=",
"$",
"depth",
";",
"}",
"}",
"return",
"$",
"maxDepth",
";",
"}"
] | Counts maximum array depth iteratively
@param array $array
@return int | [
"Counts",
"maximum",
"array",
"depth",
"iteratively"
] | train | https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Counters.php#L37-L61 |
ajant/SimpleArrayLibrary | src/Categories/Counters.php | Counters.countMinDepth | public static function countMinDepth($potentialArray, $depth = 0)
{
// validation, must be positive int or 0
if (!self::isLogicallyCastableToInt($depth)) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
if ($depth < 0) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
$return = $depth;
if (is_array($potentialArray)) {
$return++;
$childrenDepths = array();
foreach ($potentialArray as $element) {
$childrenDepths[] = self::countMinDepth($element, $return);
}
$return = empty($childrenDepths) ? $return : min($childrenDepths);
}
return $return;
} | php | public static function countMinDepth($potentialArray, $depth = 0)
{
// validation, must be positive int or 0
if (!self::isLogicallyCastableToInt($depth)) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
if ($depth < 0) {
throw new InvalidArgumentException('Depth parameter must be non-negative integer');
}
$return = $depth;
if (is_array($potentialArray)) {
$return++;
$childrenDepths = array();
foreach ($potentialArray as $element) {
$childrenDepths[] = self::countMinDepth($element, $return);
}
$return = empty($childrenDepths) ? $return : min($childrenDepths);
}
return $return;
} | [
"public",
"static",
"function",
"countMinDepth",
"(",
"$",
"potentialArray",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"// validation, must be positive int or 0",
"if",
"(",
"!",
"self",
"::",
"isLogicallyCastableToInt",
"(",
"$",
"depth",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Depth parameter must be non-negative integer'",
")",
";",
"}",
"if",
"(",
"$",
"depth",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Depth parameter must be non-negative integer'",
")",
";",
"}",
"$",
"return",
"=",
"$",
"depth",
";",
"if",
"(",
"is_array",
"(",
"$",
"potentialArray",
")",
")",
"{",
"$",
"return",
"++",
";",
"$",
"childrenDepths",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"potentialArray",
"as",
"$",
"element",
")",
"{",
"$",
"childrenDepths",
"[",
"]",
"=",
"self",
"::",
"countMinDepth",
"(",
"$",
"element",
",",
"$",
"return",
")",
";",
"}",
"$",
"return",
"=",
"empty",
"(",
"$",
"childrenDepths",
")",
"?",
"$",
"return",
":",
"min",
"(",
"$",
"childrenDepths",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Counts maximum array depth
@param mixed $potentialArray
@param int $depth
@return int
@throws InvalidArgumentException | [
"Counts",
"maximum",
"array",
"depth"
] | train | https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Counters.php#L72-L93 |
oroinc/OroLayoutComponent | HierarchyIterator.php | HierarchyIterator.getParent | public function getParent()
{
$depth = $this->iterator->getDepth();
return $depth === 0
? $this->id
: $this->iterator->getSubIterator($depth - 1)->key();
} | php | public function getParent()
{
$depth = $this->iterator->getDepth();
return $depth === 0
? $this->id
: $this->iterator->getSubIterator($depth - 1)->key();
} | [
"public",
"function",
"getParent",
"(",
")",
"{",
"$",
"depth",
"=",
"$",
"this",
"->",
"iterator",
"->",
"getDepth",
"(",
")",
";",
"return",
"$",
"depth",
"===",
"0",
"?",
"$",
"this",
"->",
"id",
":",
"$",
"this",
"->",
"iterator",
"->",
"getSubIterator",
"(",
"$",
"depth",
"-",
"1",
")",
"->",
"key",
"(",
")",
";",
"}"
] | Return the parent element
@return mixed | [
"Return",
"the",
"parent",
"element"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/HierarchyIterator.php#L36-L43 |
zicht/z | src/Zicht/Tool/Script/Node/Script.php | Script.compile | public function compile(Buffer $buffer)
{
/** @var Script\Annotation[] $annotations */
$annotations = array();
$nodes = $this->nodes;
while (current($nodes) instanceof Script\Annotation) {
$annotations[] = array_shift($nodes);
}
foreach ($annotations as $annotation) {
$annotation->beforeScript($buffer);
}
if (count($this->nodes)) {
$buffer->write('$z->cmd(');
foreach ($nodes as $i => $node) {
if ($i > 0) {
$buffer->raw(' . ');
}
$buffer->raw('$z->str(');
$node->compile($buffer);
$buffer->raw(')');
}
$buffer->raw(');')->eol();
}
foreach (array_reverse($annotations) as $annotation) {
$annotation->afterScript($buffer);
}
} | php | public function compile(Buffer $buffer)
{
/** @var Script\Annotation[] $annotations */
$annotations = array();
$nodes = $this->nodes;
while (current($nodes) instanceof Script\Annotation) {
$annotations[] = array_shift($nodes);
}
foreach ($annotations as $annotation) {
$annotation->beforeScript($buffer);
}
if (count($this->nodes)) {
$buffer->write('$z->cmd(');
foreach ($nodes as $i => $node) {
if ($i > 0) {
$buffer->raw(' . ');
}
$buffer->raw('$z->str(');
$node->compile($buffer);
$buffer->raw(')');
}
$buffer->raw(');')->eol();
}
foreach (array_reverse($annotations) as $annotation) {
$annotation->afterScript($buffer);
}
} | [
"public",
"function",
"compile",
"(",
"Buffer",
"$",
"buffer",
")",
"{",
"/** @var Script\\Annotation[] $annotations */",
"$",
"annotations",
"=",
"array",
"(",
")",
";",
"$",
"nodes",
"=",
"$",
"this",
"->",
"nodes",
";",
"while",
"(",
"current",
"(",
"$",
"nodes",
")",
"instanceof",
"Script",
"\\",
"Annotation",
")",
"{",
"$",
"annotations",
"[",
"]",
"=",
"array_shift",
"(",
"$",
"nodes",
")",
";",
"}",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"$",
"annotation",
"->",
"beforeScript",
"(",
"$",
"buffer",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"nodes",
")",
")",
"{",
"$",
"buffer",
"->",
"write",
"(",
"'$z->cmd('",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"i",
"=>",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"i",
">",
"0",
")",
"{",
"$",
"buffer",
"->",
"raw",
"(",
"' . '",
")",
";",
"}",
"$",
"buffer",
"->",
"raw",
"(",
"'$z->str('",
")",
";",
"$",
"node",
"->",
"compile",
"(",
"$",
"buffer",
")",
";",
"$",
"buffer",
"->",
"raw",
"(",
"')'",
")",
";",
"}",
"$",
"buffer",
"->",
"raw",
"(",
"');'",
")",
"->",
"eol",
"(",
")",
";",
"}",
"foreach",
"(",
"array_reverse",
"(",
"$",
"annotations",
")",
"as",
"$",
"annotation",
")",
"{",
"$",
"annotation",
"->",
"afterScript",
"(",
"$",
"buffer",
")",
";",
"}",
"}"
] | Compiles the node.
@param \Zicht\Tool\Script\Buffer $buffer
@return void | [
"Compiles",
"the",
"node",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Script/Node/Script.php#L24-L53 |
gdbots/iam-php | src/GrantRolesToUserHandler.php | GrantRolesToUserHandler.createUserRolesGranted | protected function createUserRolesGranted(GrantRolesToUser $command, Pbjx $pbjx): UserRolesGranted
{
/** @var UserRolesGranted $event */
$event = UserRolesGrantedV1Mixin::findOne()->createMessage();
return $event;
} | php | protected function createUserRolesGranted(GrantRolesToUser $command, Pbjx $pbjx): UserRolesGranted
{
/** @var UserRolesGranted $event */
$event = UserRolesGrantedV1Mixin::findOne()->createMessage();
return $event;
} | [
"protected",
"function",
"createUserRolesGranted",
"(",
"GrantRolesToUser",
"$",
"command",
",",
"Pbjx",
"$",
"pbjx",
")",
":",
"UserRolesGranted",
"{",
"/** @var UserRolesGranted $event */",
"$",
"event",
"=",
"UserRolesGrantedV1Mixin",
"::",
"findOne",
"(",
")",
"->",
"createMessage",
"(",
")",
";",
"return",
"$",
"event",
";",
"}"
] | @param GrantRolesToUser $command
@param Pbjx $pbjx
@return UserRolesGranted | [
"@param",
"GrantRolesToUser",
"$command",
"@param",
"Pbjx",
"$pbjx"
] | train | https://github.com/gdbots/iam-php/blob/3dbfa602de183a7ac5fb5140304e8cf4c4b15ab3/src/GrantRolesToUserHandler.php#L75-L80 |
BugBuster1701/contao-botdetection-bundle | src/Resources/contao/classes/Referrer/ProviderCommunication.php | ProviderCommunication.loadProviderFiles | public function loadProviderFiles()
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');
$lastWeek = time() - (7 * 24 * 60 * 60);
if (false === $this->allowUrlOpen)
{
$this->logMessage('ProviderCommunication::loadProviderFiles allowUrlOpen = false!', 'botdetection_debug');
return false;
}
foreach($this->referrerProvider as $source => $url)
{
if (false === file_exists($this->cachePath .'/'. strtolower($source) . '.txt') ||
$lastWeek > filemtime($this->cachePath .'/'. strtolower($source) . '.txt')
)
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');
$fileProvider = fopen($this->cachePath .'/'. strtolower($source) . '.txt', 'wb+');
fwrite($fileProvider, file_get_contents($url));
fclose($fileProvider);
}
}
//debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');
return true;
} | php | public function loadProviderFiles()
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');
$lastWeek = time() - (7 * 24 * 60 * 60);
if (false === $this->allowUrlOpen)
{
$this->logMessage('ProviderCommunication::loadProviderFiles allowUrlOpen = false!', 'botdetection_debug');
return false;
}
foreach($this->referrerProvider as $source => $url)
{
if (false === file_exists($this->cachePath .'/'. strtolower($source) . '.txt') ||
$lastWeek > filemtime($this->cachePath .'/'. strtolower($source) . '.txt')
)
{
//debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');
$fileProvider = fopen($this->cachePath .'/'. strtolower($source) . '.txt', 'wb+');
fwrite($fileProvider, file_get_contents($url));
fclose($fileProvider);
}
}
//debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');
return true;
} | [
"public",
"function",
"loadProviderFiles",
"(",
")",
"{",
"//debug $this->logMessage('ProviderCommunication::loadProviderFile: START','botdetection_debug');",
"$",
"lastWeek",
"=",
"time",
"(",
")",
"-",
"(",
"7",
"*",
"24",
"*",
"60",
"*",
"60",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"allowUrlOpen",
")",
"{",
"$",
"this",
"->",
"logMessage",
"(",
"'ProviderCommunication::loadProviderFiles allowUrlOpen = false!'",
",",
"'botdetection_debug'",
")",
";",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"referrerProvider",
"as",
"$",
"source",
"=>",
"$",
"url",
")",
"{",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"source",
")",
".",
"'.txt'",
")",
"||",
"$",
"lastWeek",
">",
"filemtime",
"(",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"source",
")",
".",
"'.txt'",
")",
")",
"{",
"//debug $this->logMessage('ProviderCommunication::loadProviderFile: '.$source,'botdetection_debug');",
"$",
"fileProvider",
"=",
"fopen",
"(",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"strtolower",
"(",
"$",
"source",
")",
".",
"'.txt'",
",",
"'wb+'",
")",
";",
"fwrite",
"(",
"$",
"fileProvider",
",",
"file_get_contents",
"(",
"$",
"url",
")",
")",
";",
"fclose",
"(",
"$",
"fileProvider",
")",
";",
"}",
"}",
"//debug $this->logMessage('ProviderCommunication::loadProviderFile: END','botdetection_debug');",
"return",
"true",
";",
"}"
] | Load Referrer Provider Files if
- provider files to old | [
"Load",
"Referrer",
"Provider",
"Files",
"if",
"-",
"provider",
"files",
"to",
"old"
] | train | https://github.com/BugBuster1701/contao-botdetection-bundle/blob/50c964acc354aa9116fae0e509cd7d075bd52f55/src/Resources/contao/classes/Referrer/ProviderCommunication.php#L98-L124 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Repository/AbstractDoctrineRepository.php | AbstractDoctrineRepository.find | public function find(string $id = null)
{
if (null === $id) {
return null;
}
$table = $this->getTable();
$this->logger->info('model: find row within table {table} with id {id}', ['table' => $table, 'id' => $id]);
if ($this->storageCache->has($id)) {
$this->logger->info(
'model: found row within cache for table {table} with id {id}',
['table' => $table, 'id' => $id]
);
return $this->fromPersistence($this->storageCache->get($id));
}
$qb = $this->connection->createQueryBuilder();
$qb->select('*')->from($this->getTable())->where($qb->expr()->eq('id', ':id'))->setParameter('id', $id);
$row = $qb->execute()->fetch(\PDO::FETCH_ASSOC);
if (false === $row) {
$this->logger->notice(
'model: row within table {table} with id {id} not found',
['table' => $table, 'id' => $id]
);
return null;
}
$this->storageCache->set($row['id'], $row);
return $this->fromPersistence($row);
} | php | public function find(string $id = null)
{
if (null === $id) {
return null;
}
$table = $this->getTable();
$this->logger->info('model: find row within table {table} with id {id}', ['table' => $table, 'id' => $id]);
if ($this->storageCache->has($id)) {
$this->logger->info(
'model: found row within cache for table {table} with id {id}',
['table' => $table, 'id' => $id]
);
return $this->fromPersistence($this->storageCache->get($id));
}
$qb = $this->connection->createQueryBuilder();
$qb->select('*')->from($this->getTable())->where($qb->expr()->eq('id', ':id'))->setParameter('id', $id);
$row = $qb->execute()->fetch(\PDO::FETCH_ASSOC);
if (false === $row) {
$this->logger->notice(
'model: row within table {table} with id {id} not found',
['table' => $table, 'id' => $id]
);
return null;
}
$this->storageCache->set($row['id'], $row);
return $this->fromPersistence($row);
} | [
"public",
"function",
"find",
"(",
"string",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"id",
")",
"{",
"return",
"null",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'model: find row within table {table} with id {id}'",
",",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"storageCache",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'model: found row within cache for table {table} with id {id}'",
",",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"$",
"this",
"->",
"fromPersistence",
"(",
"$",
"this",
"->",
"storageCache",
"->",
"get",
"(",
"$",
"id",
")",
")",
";",
"}",
"$",
"qb",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"select",
"(",
"'*'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
"->",
"where",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'id'",
",",
"':id'",
")",
")",
"->",
"setParameter",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"$",
"row",
"=",
"$",
"qb",
"->",
"execute",
"(",
")",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"false",
"===",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"'model: row within table {table} with id {id} not found'",
",",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"storageCache",
"->",
"set",
"(",
"$",
"row",
"[",
"'id'",
"]",
",",
"$",
"row",
")",
";",
"return",
"$",
"this",
"->",
"fromPersistence",
"(",
"$",
"row",
")",
";",
"}"
] | @param string $id
@return ModelInterface|null | [
"@param",
"string",
"$id"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Repository/AbstractDoctrineRepository.php#L65-L100 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Repository/AbstractDoctrineRepository.php | AbstractDoctrineRepository.findOneBy | public function findOneBy(array $criteria, array $orderBy = null)
{
$models = $this->findBy($criteria, $orderBy, 1, 0);
if ([] === $models) {
$this->logger->notice(
'model: row within table {table} with criteria {criteria} not found',
[
'table' => $this->getTable(),
'criteria' => $criteria,
'orderBy' => $orderBy,
'limit' => 1,
'offset' => 0,
]
);
return null;
}
return reset($models);
} | php | public function findOneBy(array $criteria, array $orderBy = null)
{
$models = $this->findBy($criteria, $orderBy, 1, 0);
if ([] === $models) {
$this->logger->notice(
'model: row within table {table} with criteria {criteria} not found',
[
'table' => $this->getTable(),
'criteria' => $criteria,
'orderBy' => $orderBy,
'limit' => 1,
'offset' => 0,
]
);
return null;
}
return reset($models);
} | [
"public",
"function",
"findOneBy",
"(",
"array",
"$",
"criteria",
",",
"array",
"$",
"orderBy",
"=",
"null",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"findBy",
"(",
"$",
"criteria",
",",
"$",
"orderBy",
",",
"1",
",",
"0",
")",
";",
"if",
"(",
"[",
"]",
"===",
"$",
"models",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"notice",
"(",
"'model: row within table {table} with criteria {criteria} not found'",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"getTable",
"(",
")",
",",
"'criteria'",
"=>",
"$",
"criteria",
",",
"'orderBy'",
"=>",
"$",
"orderBy",
",",
"'limit'",
"=>",
"1",
",",
"'offset'",
"=>",
"0",
",",
"]",
")",
";",
"return",
"null",
";",
"}",
"return",
"reset",
"(",
"$",
"models",
")",
";",
"}"
] | @param array $criteria
@return null|ModelInterface | [
"@param",
"array",
"$criteria"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Repository/AbstractDoctrineRepository.php#L107-L127 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Repository/AbstractDoctrineRepository.php | AbstractDoctrineRepository.findBy | public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
$table = $this->getTable();
$this->logger->info(
'model: find rows within table {table} with criteria {criteria}',
['table' => $table, 'criteria' => $criteria, 'orderBy' => $orderBy, 'limit' => $limit, 'offset' => $offset]
);
$qb = $this->connection->createQueryBuilder()
->select('*')
->from($table)
->setFirstResult($offset)
->setMaxResults($limit)
;
$this->addCriteriaToQueryBuilder($qb, $criteria);
$this->addOrderByToQueryBuilder($qb, $orderBy);
$rows = $qb->execute()->fetchAll(\PDO::FETCH_ASSOC);
if ([] === $rows) {
return [];
}
$models = [];
foreach ($rows as $row) {
$this->storageCache->set($row['id'], $row);
$models[] = $this->fromPersistence($row);
}
return $models;
} | php | public function findBy(array $criteria, array $orderBy = null, int $limit = null, int $offset = null): array
{
$table = $this->getTable();
$this->logger->info(
'model: find rows within table {table} with criteria {criteria}',
['table' => $table, 'criteria' => $criteria, 'orderBy' => $orderBy, 'limit' => $limit, 'offset' => $offset]
);
$qb = $this->connection->createQueryBuilder()
->select('*')
->from($table)
->setFirstResult($offset)
->setMaxResults($limit)
;
$this->addCriteriaToQueryBuilder($qb, $criteria);
$this->addOrderByToQueryBuilder($qb, $orderBy);
$rows = $qb->execute()->fetchAll(\PDO::FETCH_ASSOC);
if ([] === $rows) {
return [];
}
$models = [];
foreach ($rows as $row) {
$this->storageCache->set($row['id'], $row);
$models[] = $this->fromPersistence($row);
}
return $models;
} | [
"public",
"function",
"findBy",
"(",
"array",
"$",
"criteria",
",",
"array",
"$",
"orderBy",
"=",
"null",
",",
"int",
"$",
"limit",
"=",
"null",
",",
"int",
"$",
"offset",
"=",
"null",
")",
":",
"array",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'model: find rows within table {table} with criteria {criteria}'",
",",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'criteria'",
"=>",
"$",
"criteria",
",",
"'orderBy'",
"=>",
"$",
"orderBy",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'offset'",
"=>",
"$",
"offset",
"]",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'*'",
")",
"->",
"from",
"(",
"$",
"table",
")",
"->",
"setFirstResult",
"(",
"$",
"offset",
")",
"->",
"setMaxResults",
"(",
"$",
"limit",
")",
";",
"$",
"this",
"->",
"addCriteriaToQueryBuilder",
"(",
"$",
"qb",
",",
"$",
"criteria",
")",
";",
"$",
"this",
"->",
"addOrderByToQueryBuilder",
"(",
"$",
"qb",
",",
"$",
"orderBy",
")",
";",
"$",
"rows",
"=",
"$",
"qb",
"->",
"execute",
"(",
")",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"[",
"]",
"===",
"$",
"rows",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"models",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"storageCache",
"->",
"set",
"(",
"$",
"row",
"[",
"'id'",
"]",
",",
"$",
"row",
")",
";",
"$",
"models",
"[",
"]",
"=",
"$",
"this",
"->",
"fromPersistence",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"models",
";",
"}"
] | @param array $criteria
@return ModelInterface[]|array | [
"@param",
"array",
"$criteria"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Repository/AbstractDoctrineRepository.php#L134-L167 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Repository/AbstractDoctrineRepository.php | AbstractDoctrineRepository.persist | public function persist(ModelInterface $model): RepositoryInterface
{
$id = $model->getId();
$row = $model->toPersistence();
$this->connection->beginTransaction();
$alreadyExists = (bool) $this->find($id);
$stack = new RelatedModelManipulationStack();
foreach ($row as $field => $value) {
if ($value instanceof ModelCollectionInterface) {
$stack->addToRemoveModels($value->getInitialModels());
$stack->addToPersistModels($value->getModels());
unset($row[$field]);
} elseif ($value instanceof ModelReferenceInterface) {
$row[$field.'Id'] = $this->persistModelReference($value, $stack);
unset($row[$field]);
}
}
if (!$alreadyExists) {
$this->insert($id, $row);
} else {
$this->update($id, $row);
}
$this->removeRelatedModels($stack->getToRemoveModels());
$this->persistRelatedModels($stack->getToPersistModels());
$this->storageCache->set($id, $row);
$this->connection->commit();
return $this;
} | php | public function persist(ModelInterface $model): RepositoryInterface
{
$id = $model->getId();
$row = $model->toPersistence();
$this->connection->beginTransaction();
$alreadyExists = (bool) $this->find($id);
$stack = new RelatedModelManipulationStack();
foreach ($row as $field => $value) {
if ($value instanceof ModelCollectionInterface) {
$stack->addToRemoveModels($value->getInitialModels());
$stack->addToPersistModels($value->getModels());
unset($row[$field]);
} elseif ($value instanceof ModelReferenceInterface) {
$row[$field.'Id'] = $this->persistModelReference($value, $stack);
unset($row[$field]);
}
}
if (!$alreadyExists) {
$this->insert($id, $row);
} else {
$this->update($id, $row);
}
$this->removeRelatedModels($stack->getToRemoveModels());
$this->persistRelatedModels($stack->getToPersistModels());
$this->storageCache->set($id, $row);
$this->connection->commit();
return $this;
} | [
"public",
"function",
"persist",
"(",
"ModelInterface",
"$",
"model",
")",
":",
"RepositoryInterface",
"{",
"$",
"id",
"=",
"$",
"model",
"->",
"getId",
"(",
")",
";",
"$",
"row",
"=",
"$",
"model",
"->",
"toPersistence",
"(",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"alreadyExists",
"=",
"(",
"bool",
")",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"stack",
"=",
"new",
"RelatedModelManipulationStack",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"ModelCollectionInterface",
")",
"{",
"$",
"stack",
"->",
"addToRemoveModels",
"(",
"$",
"value",
"->",
"getInitialModels",
"(",
")",
")",
";",
"$",
"stack",
"->",
"addToPersistModels",
"(",
"$",
"value",
"->",
"getModels",
"(",
")",
")",
";",
"unset",
"(",
"$",
"row",
"[",
"$",
"field",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"ModelReferenceInterface",
")",
"{",
"$",
"row",
"[",
"$",
"field",
".",
"'Id'",
"]",
"=",
"$",
"this",
"->",
"persistModelReference",
"(",
"$",
"value",
",",
"$",
"stack",
")",
";",
"unset",
"(",
"$",
"row",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"alreadyExists",
")",
"{",
"$",
"this",
"->",
"insert",
"(",
"$",
"id",
",",
"$",
"row",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"update",
"(",
"$",
"id",
",",
"$",
"row",
")",
";",
"}",
"$",
"this",
"->",
"removeRelatedModels",
"(",
"$",
"stack",
"->",
"getToRemoveModels",
"(",
")",
")",
";",
"$",
"this",
"->",
"persistRelatedModels",
"(",
"$",
"stack",
"->",
"getToPersistModels",
"(",
")",
")",
";",
"$",
"this",
"->",
"storageCache",
"->",
"set",
"(",
"$",
"id",
",",
"$",
"row",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param ModelInterface $model
@return RepositoryInterface | [
"@param",
"ModelInterface",
"$model"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Repository/AbstractDoctrineRepository.php#L201-L238 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Repository/AbstractDoctrineRepository.php | AbstractDoctrineRepository.remove | public function remove(ModelInterface $model): RepositoryInterface
{
$id = $model->getId();
$table = $this->getTable();
if (null === $this->find($id)) {
return $this;
}
$this->connection->beginTransaction();
$row = $model->toPersistence();
foreach ($row as $field => $value) {
if ($value instanceof ModelCollectionInterface) {
$this->removeRelatedModels($value->getInitialModels());
} elseif ($value instanceof ModelReferenceInterface) {
if (null !== $initialModel = $value->getInitialModel()) {
$this->removeRelatedModel($initialModel);
}
}
}
$this->logger->info(
'model: remove row from table {table} with id {id}',
['table' => $table, 'id' => $id]
);
$this->connection->delete($table, ['id' => $id]);
$this->storageCache->remove($id);
$this->connection->commit();
return $this;
} | php | public function remove(ModelInterface $model): RepositoryInterface
{
$id = $model->getId();
$table = $this->getTable();
if (null === $this->find($id)) {
return $this;
}
$this->connection->beginTransaction();
$row = $model->toPersistence();
foreach ($row as $field => $value) {
if ($value instanceof ModelCollectionInterface) {
$this->removeRelatedModels($value->getInitialModels());
} elseif ($value instanceof ModelReferenceInterface) {
if (null !== $initialModel = $value->getInitialModel()) {
$this->removeRelatedModel($initialModel);
}
}
}
$this->logger->info(
'model: remove row from table {table} with id {id}',
['table' => $table, 'id' => $id]
);
$this->connection->delete($table, ['id' => $id]);
$this->storageCache->remove($id);
$this->connection->commit();
return $this;
} | [
"public",
"function",
"remove",
"(",
"ModelInterface",
"$",
"model",
")",
":",
"RepositoryInterface",
"{",
"$",
"id",
"=",
"$",
"model",
"->",
"getId",
"(",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"row",
"=",
"$",
"model",
"->",
"toPersistence",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"ModelCollectionInterface",
")",
"{",
"$",
"this",
"->",
"removeRelatedModels",
"(",
"$",
"value",
"->",
"getInitialModels",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"ModelReferenceInterface",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"initialModel",
"=",
"$",
"value",
"->",
"getInitialModel",
"(",
")",
")",
"{",
"$",
"this",
"->",
"removeRelatedModel",
"(",
"$",
"initialModel",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"'model: remove row from table {table} with id {id}'",
",",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"delete",
"(",
"$",
"table",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"$",
"this",
"->",
"storageCache",
"->",
"remove",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"commit",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param ModelInterface $model
@return RepositoryInterface | [
"@param",
"ModelInterface",
"$model"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Repository/AbstractDoctrineRepository.php#L245-L280 |
chubbyphp/chubbyphp-model-doctrine-dbal | src/Repository/AbstractDoctrineRepository.php | AbstractDoctrineRepository.persistModelReference | private function persistModelReference(ModelReferenceInterface $reference, RelatedModelManipulationStack $stack)
{
$initialModel = $reference->getInitialModel();
$model = $reference->getModel();
if (null !== $initialModel && (null === $model || $model->getId() !== $initialModel->getId())) {
$stack->addToRemoveModel($initialModel);
}
if (null !== $model) {
$this->persistRelatedModel($model);
return $model->getId();
}
return null;
} | php | private function persistModelReference(ModelReferenceInterface $reference, RelatedModelManipulationStack $stack)
{
$initialModel = $reference->getInitialModel();
$model = $reference->getModel();
if (null !== $initialModel && (null === $model || $model->getId() !== $initialModel->getId())) {
$stack->addToRemoveModel($initialModel);
}
if (null !== $model) {
$this->persistRelatedModel($model);
return $model->getId();
}
return null;
} | [
"private",
"function",
"persistModelReference",
"(",
"ModelReferenceInterface",
"$",
"reference",
",",
"RelatedModelManipulationStack",
"$",
"stack",
")",
"{",
"$",
"initialModel",
"=",
"$",
"reference",
"->",
"getInitialModel",
"(",
")",
";",
"$",
"model",
"=",
"$",
"reference",
"->",
"getModel",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"initialModel",
"&&",
"(",
"null",
"===",
"$",
"model",
"||",
"$",
"model",
"->",
"getId",
"(",
")",
"!==",
"$",
"initialModel",
"->",
"getId",
"(",
")",
")",
")",
"{",
"$",
"stack",
"->",
"addToRemoveModel",
"(",
"$",
"initialModel",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"persistRelatedModel",
"(",
"$",
"model",
")",
";",
"return",
"$",
"model",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | @param ModelReferenceInterface $reference
@param RelatedModelManipulationStack $stack
@return null|string | [
"@param",
"ModelReferenceInterface",
"$reference",
"@param",
"RelatedModelManipulationStack",
"$stack"
] | train | https://github.com/chubbyphp/chubbyphp-model-doctrine-dbal/blob/1079c28f5bffc2e2bec04122742d5008464c167f/src/Repository/AbstractDoctrineRepository.php#L330-L346 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/oracle/reader.php | ezcDbSchemaOracleReader.fetchTableFields | protected function fetchTableFields( $tableName )
{
$fields = array();
// will detect autoincrement field by presence of sequence tableName_fieldPos_seq
$sequencesQuery = $this->db->query( "SELECT * FROM user_sequences" );
$sequencesQuery->setFetchMode( PDO::FETCH_ASSOC );
$sequences = array();
foreach ( $sequencesQuery as $seq )
{
$sequences[] = $seq['sequence_name'];
}
// fetching fields info from Oracle
$resultArray = $this->db->query( "SELECT a.column_name AS field, " .
" a.column_id AS field_pos, " .
" DECODE (a.nullable, 'N', 1, 'Y', 0) AS notnull, " .
" a.data_type AS type, " .
" a.data_length AS length, " .
" a.data_precision AS precision, " .
" a.data_scale AS scale, " .
" a.data_default AS default_val " .
"FROM user_tab_columns a ".
"WHERE a.table_name = '$tableName' " .
"ORDER BY a.column_id" );
$resultArray->setFetchMode( PDO::FETCH_ASSOC );
foreach ( $resultArray as $row )
{
$row = $this->lowercase($row);
$fieldLength = $row['length'];
$fieldPrecision = null;
$fieldType = self::convertToGenericType( $row['type'], $fieldLength, $fieldPrecision );
if ( in_array( $fieldType, array( 'clob', 'blob', 'date', 'float', 'timestamp' ) ) )
{
$fieldLength = false;
}
else if ( $fieldType == 'integer' )
{
if ( $row['precision']!= '' )
{
$fieldType = 'decimal';
$fieldLength = $row['precision'];
}
else if ( $fieldLength == 22 ) // 22 is the default length for NUMBER in Oracle, so don't include length
{
$fieldLength = false;
}
}
$fieldNotNull = $row['notnull'];
$fieldDefault = null;
if ( $row['default_val'] != '' )
{
$row['default_val'] = rtrim( $row['default_val'] );
if ( $fieldType == 'boolean' )
{
( $row['default_val'] == '1' ) ? $fieldDefault = 'true': $fieldDefault = 'false';
}
else if ( $fieldType == 'text' )
{
$fieldDefault = substr( $row['default_val'], 1, -1 ); // avoid quotes for text
}
else
{
$fieldDefault = $row['default_val']; // have a number value
}
}
$fieldAutoIncrement = false;
// new sequence naming included
if ( in_array(
ezcDbSchemaOracleHelper::generateSuffixCompositeIdentName( $tableName, $row['field_pos'], 'seq' ),
$sequences
) || in_array(
ezcDbSchemaOracleHelper::generateSuffixCompositeIdentName( $tableName, $row['field'], 'seq' ),
$sequences
) )
{
$fieldAutoIncrement = true;
}
// FIXME: unsigned needs to be implemented
$fieldUnsigned = false;
$fields[$row['field']] = ezcDbSchema::createNewField( $fieldType, $fieldLength, $fieldNotNull, $fieldDefault, $fieldAutoIncrement, $fieldUnsigned );
}
return $fields;
} | php | protected function fetchTableFields( $tableName )
{
$fields = array();
// will detect autoincrement field by presence of sequence tableName_fieldPos_seq
$sequencesQuery = $this->db->query( "SELECT * FROM user_sequences" );
$sequencesQuery->setFetchMode( PDO::FETCH_ASSOC );
$sequences = array();
foreach ( $sequencesQuery as $seq )
{
$sequences[] = $seq['sequence_name'];
}
// fetching fields info from Oracle
$resultArray = $this->db->query( "SELECT a.column_name AS field, " .
" a.column_id AS field_pos, " .
" DECODE (a.nullable, 'N', 1, 'Y', 0) AS notnull, " .
" a.data_type AS type, " .
" a.data_length AS length, " .
" a.data_precision AS precision, " .
" a.data_scale AS scale, " .
" a.data_default AS default_val " .
"FROM user_tab_columns a ".
"WHERE a.table_name = '$tableName' " .
"ORDER BY a.column_id" );
$resultArray->setFetchMode( PDO::FETCH_ASSOC );
foreach ( $resultArray as $row )
{
$row = $this->lowercase($row);
$fieldLength = $row['length'];
$fieldPrecision = null;
$fieldType = self::convertToGenericType( $row['type'], $fieldLength, $fieldPrecision );
if ( in_array( $fieldType, array( 'clob', 'blob', 'date', 'float', 'timestamp' ) ) )
{
$fieldLength = false;
}
else if ( $fieldType == 'integer' )
{
if ( $row['precision']!= '' )
{
$fieldType = 'decimal';
$fieldLength = $row['precision'];
}
else if ( $fieldLength == 22 ) // 22 is the default length for NUMBER in Oracle, so don't include length
{
$fieldLength = false;
}
}
$fieldNotNull = $row['notnull'];
$fieldDefault = null;
if ( $row['default_val'] != '' )
{
$row['default_val'] = rtrim( $row['default_val'] );
if ( $fieldType == 'boolean' )
{
( $row['default_val'] == '1' ) ? $fieldDefault = 'true': $fieldDefault = 'false';
}
else if ( $fieldType == 'text' )
{
$fieldDefault = substr( $row['default_val'], 1, -1 ); // avoid quotes for text
}
else
{
$fieldDefault = $row['default_val']; // have a number value
}
}
$fieldAutoIncrement = false;
// new sequence naming included
if ( in_array(
ezcDbSchemaOracleHelper::generateSuffixCompositeIdentName( $tableName, $row['field_pos'], 'seq' ),
$sequences
) || in_array(
ezcDbSchemaOracleHelper::generateSuffixCompositeIdentName( $tableName, $row['field'], 'seq' ),
$sequences
) )
{
$fieldAutoIncrement = true;
}
// FIXME: unsigned needs to be implemented
$fieldUnsigned = false;
$fields[$row['field']] = ezcDbSchema::createNewField( $fieldType, $fieldLength, $fieldNotNull, $fieldDefault, $fieldAutoIncrement, $fieldUnsigned );
}
return $fields;
} | [
"protected",
"function",
"fetchTableFields",
"(",
"$",
"tableName",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"// will detect autoincrement field by presence of sequence tableName_fieldPos_seq",
"$",
"sequencesQuery",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"SELECT * FROM user_sequences\"",
")",
";",
"$",
"sequencesQuery",
"->",
"setFetchMode",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"sequences",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sequencesQuery",
"as",
"$",
"seq",
")",
"{",
"$",
"sequences",
"[",
"]",
"=",
"$",
"seq",
"[",
"'sequence_name'",
"]",
";",
"}",
"// fetching fields info from Oracle",
"$",
"resultArray",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"\"SELECT a.column_name AS field, \"",
".",
"\" a.column_id AS field_pos, \"",
".",
"\" DECODE (a.nullable, 'N', 1, 'Y', 0) AS notnull, \"",
".",
"\" a.data_type AS type, \"",
".",
"\" a.data_length AS length, \"",
".",
"\" a.data_precision AS precision, \"",
".",
"\" a.data_scale AS scale, \"",
".",
"\" a.data_default AS default_val \"",
".",
"\"FROM user_tab_columns a \"",
".",
"\"WHERE a.table_name = '$tableName' \"",
".",
"\"ORDER BY a.column_id\"",
")",
";",
"$",
"resultArray",
"->",
"setFetchMode",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"foreach",
"(",
"$",
"resultArray",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"lowercase",
"(",
"$",
"row",
")",
";",
"$",
"fieldLength",
"=",
"$",
"row",
"[",
"'length'",
"]",
";",
"$",
"fieldPrecision",
"=",
"null",
";",
"$",
"fieldType",
"=",
"self",
"::",
"convertToGenericType",
"(",
"$",
"row",
"[",
"'type'",
"]",
",",
"$",
"fieldLength",
",",
"$",
"fieldPrecision",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"fieldType",
",",
"array",
"(",
"'clob'",
",",
"'blob'",
",",
"'date'",
",",
"'float'",
",",
"'timestamp'",
")",
")",
")",
"{",
"$",
"fieldLength",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"fieldType",
"==",
"'integer'",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"'precision'",
"]",
"!=",
"''",
")",
"{",
"$",
"fieldType",
"=",
"'decimal'",
";",
"$",
"fieldLength",
"=",
"$",
"row",
"[",
"'precision'",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"fieldLength",
"==",
"22",
")",
"// 22 is the default length for NUMBER in Oracle, so don't include length",
"{",
"$",
"fieldLength",
"=",
"false",
";",
"}",
"}",
"$",
"fieldNotNull",
"=",
"$",
"row",
"[",
"'notnull'",
"]",
";",
"$",
"fieldDefault",
"=",
"null",
";",
"if",
"(",
"$",
"row",
"[",
"'default_val'",
"]",
"!=",
"''",
")",
"{",
"$",
"row",
"[",
"'default_val'",
"]",
"=",
"rtrim",
"(",
"$",
"row",
"[",
"'default_val'",
"]",
")",
";",
"if",
"(",
"$",
"fieldType",
"==",
"'boolean'",
")",
"{",
"(",
"$",
"row",
"[",
"'default_val'",
"]",
"==",
"'1'",
")",
"?",
"$",
"fieldDefault",
"=",
"'true'",
":",
"$",
"fieldDefault",
"=",
"'false'",
";",
"}",
"else",
"if",
"(",
"$",
"fieldType",
"==",
"'text'",
")",
"{",
"$",
"fieldDefault",
"=",
"substr",
"(",
"$",
"row",
"[",
"'default_val'",
"]",
",",
"1",
",",
"-",
"1",
")",
";",
"// avoid quotes for text",
"}",
"else",
"{",
"$",
"fieldDefault",
"=",
"$",
"row",
"[",
"'default_val'",
"]",
";",
"// have a number value",
"}",
"}",
"$",
"fieldAutoIncrement",
"=",
"false",
";",
"// new sequence naming included",
"if",
"(",
"in_array",
"(",
"ezcDbSchemaOracleHelper",
"::",
"generateSuffixCompositeIdentName",
"(",
"$",
"tableName",
",",
"$",
"row",
"[",
"'field_pos'",
"]",
",",
"'seq'",
")",
",",
"$",
"sequences",
")",
"||",
"in_array",
"(",
"ezcDbSchemaOracleHelper",
"::",
"generateSuffixCompositeIdentName",
"(",
"$",
"tableName",
",",
"$",
"row",
"[",
"'field'",
"]",
",",
"'seq'",
")",
",",
"$",
"sequences",
")",
")",
"{",
"$",
"fieldAutoIncrement",
"=",
"true",
";",
"}",
"// FIXME: unsigned needs to be implemented",
"$",
"fieldUnsigned",
"=",
"false",
";",
"$",
"fields",
"[",
"$",
"row",
"[",
"'field'",
"]",
"]",
"=",
"ezcDbSchema",
"::",
"createNewField",
"(",
"$",
"fieldType",
",",
"$",
"fieldLength",
",",
"$",
"fieldNotNull",
",",
"$",
"fieldDefault",
",",
"$",
"fieldAutoIncrement",
",",
"$",
"fieldUnsigned",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] | Fetch fields definition for the table $tableName
This method loops over all the fields in the table $tableName and
returns an array with the field specification. The key in the returned
array is the name of the field.
@param string $tableName
@return array(string=>ezcDbSchemaField) | [
"Fetch",
"fields",
"definition",
"for",
"the",
"table",
"$tableName"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/oracle/reader.php#L61-L153 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/oracle/reader.php | ezcDbSchemaOracleReader.convertToGenericType | static function convertToGenericType( $typeString, &$typeLength, $typePrecision )
{
if ( $typeString == 'NUMBER' && $typePrecision != '' )
{
$genericType = 'decimal';
}
else if ( $typeString == 'CHAR' && $typeLength == 1 )
{
$genericType = 'boolean';
$typeLength = 0;
}
else
{
if ( !isset( self::$typeMap[$typeString] ) )
{
throw new ezcDbSchemaUnsupportedTypeException( 'Oracle', $typeString );
}
$genericType = self::$typeMap[$typeString];
}
return $genericType;
} | php | static function convertToGenericType( $typeString, &$typeLength, $typePrecision )
{
if ( $typeString == 'NUMBER' && $typePrecision != '' )
{
$genericType = 'decimal';
}
else if ( $typeString == 'CHAR' && $typeLength == 1 )
{
$genericType = 'boolean';
$typeLength = 0;
}
else
{
if ( !isset( self::$typeMap[$typeString] ) )
{
throw new ezcDbSchemaUnsupportedTypeException( 'Oracle', $typeString );
}
$genericType = self::$typeMap[$typeString];
}
return $genericType;
} | [
"static",
"function",
"convertToGenericType",
"(",
"$",
"typeString",
",",
"&",
"$",
"typeLength",
",",
"$",
"typePrecision",
")",
"{",
"if",
"(",
"$",
"typeString",
"==",
"'NUMBER'",
"&&",
"$",
"typePrecision",
"!=",
"''",
")",
"{",
"$",
"genericType",
"=",
"'decimal'",
";",
"}",
"else",
"if",
"(",
"$",
"typeString",
"==",
"'CHAR'",
"&&",
"$",
"typeLength",
"==",
"1",
")",
"{",
"$",
"genericType",
"=",
"'boolean'",
";",
"$",
"typeLength",
"=",
"0",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"typeMap",
"[",
"$",
"typeString",
"]",
")",
")",
"{",
"throw",
"new",
"ezcDbSchemaUnsupportedTypeException",
"(",
"'Oracle'",
",",
"$",
"typeString",
")",
";",
"}",
"$",
"genericType",
"=",
"self",
"::",
"$",
"typeMap",
"[",
"$",
"typeString",
"]",
";",
"}",
"return",
"$",
"genericType",
";",
"}"
] | Converts the native Oracle type in $typeString to a generic DbSchema type.
This method converts a string like "VARCHAR2" to the generic DbSchema
type and uses parameters $typeLength and $typePrecision
to detect emulated types char(1) == 'boolean', number(N) == "decimal".
@param string $typeString
@param int $typeLength
@param int $typePrecision
@return string | [
"Converts",
"the",
"native",
"Oracle",
"type",
"in",
"$typeString",
"to",
"a",
"generic",
"DbSchema",
"type",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/oracle/reader.php#L167-L188 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/oracle/reader.php | ezcDbSchemaOracleReader.fetchTableIndexes | protected function fetchTableIndexes( $tableName )
{
$indexBuffer = array();
$indexesArray = array();
// fetching index info from Oracle
$getIndexSQL = "SELECT uind.index_name AS name, " .
" uind.index_type AS type, " .
" decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, " .
" uind_col.column_name AS column_name, " .
" uind_col.column_position AS column_pos " .
"FROM user_indexes uind, user_ind_columns uind_col " .
"WHERE uind.index_name = uind_col.index_name AND uind_col.table_name = '$tableName'";
$indexesArray = $this->db->query( $getIndexSQL )->fetchAll();
$primaryFound = false;
// getting columns to which each index related.
foreach ( $indexesArray as $row )
{
$row = $this->lowercase($row);
$keyName = $row['name'];
if ( $keyName == $tableName.'_pkey' )
{
$keyName = 'primary';
$indexBuffer[$keyName]['primary'] = true;
$indexBuffer[$keyName]['unique'] = true;
$primaryFound = true;
}
else
{
$indexBuffer[$keyName]['primary'] = false;
$indexBuffer[$keyName]['unique'] = ( $row['is_unique'] == 1 ) ? true : false;
}
$indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
}
$indexes = array();
foreach ( $indexBuffer as $indexName => $indexInfo )
{
$indexes[$indexName] = ezcDbSchema::createNewIndex( $indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique'] );
}
return $indexes;
} | php | protected function fetchTableIndexes( $tableName )
{
$indexBuffer = array();
$indexesArray = array();
// fetching index info from Oracle
$getIndexSQL = "SELECT uind.index_name AS name, " .
" uind.index_type AS type, " .
" decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, " .
" uind_col.column_name AS column_name, " .
" uind_col.column_position AS column_pos " .
"FROM user_indexes uind, user_ind_columns uind_col " .
"WHERE uind.index_name = uind_col.index_name AND uind_col.table_name = '$tableName'";
$indexesArray = $this->db->query( $getIndexSQL )->fetchAll();
$primaryFound = false;
// getting columns to which each index related.
foreach ( $indexesArray as $row )
{
$row = $this->lowercase($row);
$keyName = $row['name'];
if ( $keyName == $tableName.'_pkey' )
{
$keyName = 'primary';
$indexBuffer[$keyName]['primary'] = true;
$indexBuffer[$keyName]['unique'] = true;
$primaryFound = true;
}
else
{
$indexBuffer[$keyName]['primary'] = false;
$indexBuffer[$keyName]['unique'] = ( $row['is_unique'] == 1 ) ? true : false;
}
$indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
}
$indexes = array();
foreach ( $indexBuffer as $indexName => $indexInfo )
{
$indexes[$indexName] = ezcDbSchema::createNewIndex( $indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique'] );
}
return $indexes;
} | [
"protected",
"function",
"fetchTableIndexes",
"(",
"$",
"tableName",
")",
"{",
"$",
"indexBuffer",
"=",
"array",
"(",
")",
";",
"$",
"indexesArray",
"=",
"array",
"(",
")",
";",
"// fetching index info from Oracle",
"$",
"getIndexSQL",
"=",
"\"SELECT uind.index_name AS name, \"",
".",
"\" uind.index_type AS type, \"",
".",
"\" decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, \"",
".",
"\" uind_col.column_name AS column_name, \"",
".",
"\" uind_col.column_position AS column_pos \"",
".",
"\"FROM user_indexes uind, user_ind_columns uind_col \"",
".",
"\"WHERE uind.index_name = uind_col.index_name AND uind_col.table_name = '$tableName'\"",
";",
"$",
"indexesArray",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"getIndexSQL",
")",
"->",
"fetchAll",
"(",
")",
";",
"$",
"primaryFound",
"=",
"false",
";",
"// getting columns to which each index related.",
"foreach",
"(",
"$",
"indexesArray",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"lowercase",
"(",
"$",
"row",
")",
";",
"$",
"keyName",
"=",
"$",
"row",
"[",
"'name'",
"]",
";",
"if",
"(",
"$",
"keyName",
"==",
"$",
"tableName",
".",
"'_pkey'",
")",
"{",
"$",
"keyName",
"=",
"'primary'",
";",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'primary'",
"]",
"=",
"true",
";",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'unique'",
"]",
"=",
"true",
";",
"$",
"primaryFound",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'primary'",
"]",
"=",
"false",
";",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'unique'",
"]",
"=",
"(",
"$",
"row",
"[",
"'is_unique'",
"]",
"==",
"1",
")",
"?",
"true",
":",
"false",
";",
"}",
"$",
"indexBuffer",
"[",
"$",
"keyName",
"]",
"[",
"'fields'",
"]",
"[",
"$",
"row",
"[",
"'column_name'",
"]",
"]",
"=",
"ezcDbSchema",
"::",
"createNewIndexField",
"(",
")",
";",
"}",
"$",
"indexes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"indexBuffer",
"as",
"$",
"indexName",
"=>",
"$",
"indexInfo",
")",
"{",
"$",
"indexes",
"[",
"$",
"indexName",
"]",
"=",
"ezcDbSchema",
"::",
"createNewIndex",
"(",
"$",
"indexInfo",
"[",
"'fields'",
"]",
",",
"$",
"indexInfo",
"[",
"'primary'",
"]",
",",
"$",
"indexInfo",
"[",
"'unique'",
"]",
")",
";",
"}",
"return",
"$",
"indexes",
";",
"}"
] | Loops over all the indexes in the table $table and extracts information.
This method extracts information about the table $tableName's indexes
from the database and returns this schema as an array of
ezcDbSchemaIndex objects. The key in the array is the index' name.
@param string $tableName
@return array(string=>ezcDbSchemaIndex) | [
"Loops",
"over",
"all",
"the",
"indexes",
"in",
"the",
"table",
"$table",
"and",
"extracts",
"information",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/oracle/reader.php#L237-L285 |
BOOKEEN/opds-parser | src/Business/OpdsParserBusiness.php | OpdsParserBusiness.parse | private function parse(\SimpleXMLElement $xmldata)
{
if (!isset($xmldata->title)) {
throw new OpdsParserNoTitleException();
}
if ($xmldata->getName() === 'entry') {
return $this->parseEntry($xmldata);
}
return $this->parseFeed($xmldata);
} | php | private function parse(\SimpleXMLElement $xmldata)
{
if (!isset($xmldata->title)) {
throw new OpdsParserNoTitleException();
}
if ($xmldata->getName() === 'entry') {
return $this->parseEntry($xmldata);
}
return $this->parseFeed($xmldata);
} | [
"private",
"function",
"parse",
"(",
"\\",
"SimpleXMLElement",
"$",
"xmldata",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"xmldata",
"->",
"title",
")",
")",
"{",
"throw",
"new",
"OpdsParserNoTitleException",
"(",
")",
";",
"}",
"if",
"(",
"$",
"xmldata",
"->",
"getName",
"(",
")",
"===",
"'entry'",
")",
"{",
"return",
"$",
"this",
"->",
"parseEntry",
"(",
"$",
"xmldata",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parseFeed",
"(",
"$",
"xmldata",
")",
";",
"}"
] | Parse an OPDS flux.
@param \SimpleXMLElement $xmldata
@return Feed|Publication
@throws OpdsParserNoTitleException | [
"Parse",
"an",
"OPDS",
"flux",
"."
] | train | https://github.com/BOOKEEN/opds-parser/blob/b9ef065210e81ee63b029e37c6943c6fa8c74cef/src/Business/OpdsParserBusiness.php#L93-L106 |
BOOKEEN/opds-parser | src/Business/OpdsParserBusiness.php | OpdsParserBusiness.parsePagination | private function parsePagination(\SimpleXMLElement $xmldata)
{
$pagination = new Pagination();
$paginated = false;
foreach ($xmldata->children('opensearch', true) as $key => $value) {
switch ($key) {
case 'totalResults':
$pagination->setNumberOfItem((int) $value);
$paginated = true;
break;
case 'itemsPerPage':
$pagination->setItemsPerPage((int) $value);
$paginated = true;
break;
}
}
return $paginated ? $pagination : null;
} | php | private function parsePagination(\SimpleXMLElement $xmldata)
{
$pagination = new Pagination();
$paginated = false;
foreach ($xmldata->children('opensearch', true) as $key => $value) {
switch ($key) {
case 'totalResults':
$pagination->setNumberOfItem((int) $value);
$paginated = true;
break;
case 'itemsPerPage':
$pagination->setItemsPerPage((int) $value);
$paginated = true;
break;
}
}
return $paginated ? $pagination : null;
} | [
"private",
"function",
"parsePagination",
"(",
"\\",
"SimpleXMLElement",
"$",
"xmldata",
")",
"{",
"$",
"pagination",
"=",
"new",
"Pagination",
"(",
")",
";",
"$",
"paginated",
"=",
"false",
";",
"foreach",
"(",
"$",
"xmldata",
"->",
"children",
"(",
"'opensearch'",
",",
"true",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'totalResults'",
":",
"$",
"pagination",
"->",
"setNumberOfItem",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"$",
"paginated",
"=",
"true",
";",
"break",
";",
"case",
"'itemsPerPage'",
":",
"$",
"pagination",
"->",
"setItemsPerPage",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"$",
"paginated",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"paginated",
"?",
"$",
"pagination",
":",
"null",
";",
"}"
] | Met en forme la pagination si elle existe
@param \SimpleXMLElement $xmldata
@return Pagination|null null si elle n'existe pas | [
"Met",
"en",
"forme",
"la",
"pagination",
"si",
"elle",
"existe"
] | train | https://github.com/BOOKEEN/opds-parser/blob/b9ef065210e81ee63b029e37c6943c6fa8c74cef/src/Business/OpdsParserBusiness.php#L115-L134 |
mridang/magazine | lib/magento/Archive/Abstract.php | Mage_Archive_Abstract._writeFile | protected function _writeFile($destination, $data)
{
$destination = trim($destination);
if(false === file_put_contents($destination, $data)) {
throw new Mage_Exception("Can't write to file: " . $destination);
}
return true;
} | php | protected function _writeFile($destination, $data)
{
$destination = trim($destination);
if(false === file_put_contents($destination, $data)) {
throw new Mage_Exception("Can't write to file: " . $destination);
}
return true;
} | [
"protected",
"function",
"_writeFile",
"(",
"$",
"destination",
",",
"$",
"data",
")",
"{",
"$",
"destination",
"=",
"trim",
"(",
"$",
"destination",
")",
";",
"if",
"(",
"false",
"===",
"file_put_contents",
"(",
"$",
"destination",
",",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"\"Can't write to file: \"",
".",
"$",
"destination",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Write data to file. If file can't be opened - throw exception
@param string $destination
@param string $data
@return boolean
@throws Mage_Exception | [
"Write",
"data",
"to",
"file",
".",
"If",
"file",
"can",
"t",
"be",
"opened",
"-",
"throw",
"exception"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Abstract.php#L44-L51 |
mridang/magazine | lib/magento/Archive/Abstract.php | Mage_Archive_Abstract._readFile | protected function _readFile($source)
{
$data = '';
if (is_file($source) && is_readable($source)) {
$data = @file_get_contents($source);
if ($data === false) {
throw new Mage_Exception("Can't get contents from: " . $source);
}
}
return $data;
} | php | protected function _readFile($source)
{
$data = '';
if (is_file($source) && is_readable($source)) {
$data = @file_get_contents($source);
if ($data === false) {
throw new Mage_Exception("Can't get contents from: " . $source);
}
}
return $data;
} | [
"protected",
"function",
"_readFile",
"(",
"$",
"source",
")",
"{",
"$",
"data",
"=",
"''",
";",
"if",
"(",
"is_file",
"(",
"$",
"source",
")",
"&&",
"is_readable",
"(",
"$",
"source",
")",
")",
"{",
"$",
"data",
"=",
"@",
"file_get_contents",
"(",
"$",
"source",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"\"Can't get contents from: \"",
".",
"$",
"source",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Read data from file. If file can't be opened, throw to exception.
@param string $source
@return string
@throws Mage_Exception | [
"Read",
"data",
"from",
"file",
".",
"If",
"file",
"can",
"t",
"be",
"opened",
"throw",
"to",
"exception",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Abstract.php#L60-L70 |
mridang/magazine | lib/magento/Archive/Abstract.php | Mage_Archive_Abstract.getFilename | public function getFilename($source, $withExtension=false)
{
$file = str_replace(dirname($source) . DS, '', $source);
if (!$withExtension) {
$file = substr($file, 0, strrpos($file, '.'));
}
return $file;
} | php | public function getFilename($source, $withExtension=false)
{
$file = str_replace(dirname($source) . DS, '', $source);
if (!$withExtension) {
$file = substr($file, 0, strrpos($file, '.'));
}
return $file;
} | [
"public",
"function",
"getFilename",
"(",
"$",
"source",
",",
"$",
"withExtension",
"=",
"false",
")",
"{",
"$",
"file",
"=",
"str_replace",
"(",
"dirname",
"(",
"$",
"source",
")",
".",
"DS",
",",
"''",
",",
"$",
"source",
")",
";",
"if",
"(",
"!",
"$",
"withExtension",
")",
"{",
"$",
"file",
"=",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"strrpos",
"(",
"$",
"file",
",",
"'.'",
")",
")",
";",
"}",
"return",
"$",
"file",
";",
"}"
] | Get file name from source (URI) without last extension.
@param string $source
@param bool $withExtension
@return mixed|string | [
"Get",
"file",
"name",
"from",
"source",
"(",
"URI",
")",
"without",
"last",
"extension",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Abstract.php#L79-L86 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.get_post_id | public function get_post_id( $check_query = false ) {
global $post, $wp_query;
if ( ! isset( $post ) ) {
if ( $check_query && isset( $wp_query, $wp_query->query_vars['p'] ) ) {
$post_id = $wp_query->query_vars['p'];
} else {
$post_id = 0;
}
} else {
$post_id = $post->ID;
}
return $post_id;
} | php | public function get_post_id( $check_query = false ) {
global $post, $wp_query;
if ( ! isset( $post ) ) {
if ( $check_query && isset( $wp_query, $wp_query->query_vars['p'] ) ) {
$post_id = $wp_query->query_vars['p'];
} else {
$post_id = 0;
}
} else {
$post_id = $post->ID;
}
return $post_id;
} | [
"public",
"function",
"get_post_id",
"(",
"$",
"check_query",
"=",
"false",
")",
"{",
"global",
"$",
"post",
",",
"$",
"wp_query",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"post",
")",
")",
"{",
"if",
"(",
"$",
"check_query",
"&&",
"isset",
"(",
"$",
"wp_query",
",",
"$",
"wp_query",
"->",
"query_vars",
"[",
"'p'",
"]",
")",
")",
"{",
"$",
"post_id",
"=",
"$",
"wp_query",
"->",
"query_vars",
"[",
"'p'",
"]",
";",
"}",
"else",
"{",
"$",
"post_id",
"=",
"0",
";",
"}",
"}",
"else",
"{",
"$",
"post_id",
"=",
"$",
"post",
"->",
"ID",
";",
"}",
"return",
"$",
"post_id",
";",
"}"
] | @param bool $check_query
@return int | [
"@param",
"bool",
"$check_query"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L52-L65 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.get | public function get( $key, $post_id = null, $single = true, $default = '' ) {
if ( ! isset( $post_id ) ) {
$post_id = $this->get_post_id( true );
}
if ( $post_id <= 0 ) {
return $this->apply_filters( 'get_post_meta', $default, $key, $post_id, $single, $default );
}
return $this->apply_filters( 'get_post_meta', get_post_meta( $post_id, $this->get_meta_key( $key ), $single ), $key, $post_id, $single, $default, $this->get_post_prefix() );
} | php | public function get( $key, $post_id = null, $single = true, $default = '' ) {
if ( ! isset( $post_id ) ) {
$post_id = $this->get_post_id( true );
}
if ( $post_id <= 0 ) {
return $this->apply_filters( 'get_post_meta', $default, $key, $post_id, $single, $default );
}
return $this->apply_filters( 'get_post_meta', get_post_meta( $post_id, $this->get_meta_key( $key ), $single ), $key, $post_id, $single, $default, $this->get_post_prefix() );
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"post_id",
"=",
"null",
",",
"$",
"single",
"=",
"true",
",",
"$",
"default",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"post_id",
")",
")",
"{",
"$",
"post_id",
"=",
"$",
"this",
"->",
"get_post_id",
"(",
"true",
")",
";",
"}",
"if",
"(",
"$",
"post_id",
"<=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'get_post_meta'",
",",
"$",
"default",
",",
"$",
"key",
",",
"$",
"post_id",
",",
"$",
"single",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'get_post_meta'",
",",
"get_post_meta",
"(",
"$",
"post_id",
",",
"$",
"this",
"->",
"get_meta_key",
"(",
"$",
"key",
")",
",",
"$",
"single",
")",
",",
"$",
"key",
",",
"$",
"post_id",
",",
"$",
"single",
",",
"$",
"default",
",",
"$",
"this",
"->",
"get_post_prefix",
"(",
")",
")",
";",
"}"
] | @param string $key
@param int|null $post_id
@param bool $single
@param mixed $default
@return mixed | [
"@param",
"string",
"$key",
"@param",
"int|null",
"$post_id",
"@param",
"bool",
"$single",
"@param",
"mixed",
"$default"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L75-L84 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.set | public function set( $post_id, $key, $value, $add = false, $unique = false ) {
if ( $post_id <= 0 ) {
return false;
}
if ( ! $add ) {
return update_post_meta( $post_id, $this->get_meta_key( $key ), $value );
}
if ( $unique ) {
$values = $this->get( $key, $post_id, false, [] );
if ( in_array( $value, $values ) ) {
return false;
}
}
return add_post_meta( $post_id, $this->get_meta_key( $key ), $value );
} | php | public function set( $post_id, $key, $value, $add = false, $unique = false ) {
if ( $post_id <= 0 ) {
return false;
}
if ( ! $add ) {
return update_post_meta( $post_id, $this->get_meta_key( $key ), $value );
}
if ( $unique ) {
$values = $this->get( $key, $post_id, false, [] );
if ( in_array( $value, $values ) ) {
return false;
}
}
return add_post_meta( $post_id, $this->get_meta_key( $key ), $value );
} | [
"public",
"function",
"set",
"(",
"$",
"post_id",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"add",
"=",
"false",
",",
"$",
"unique",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"post_id",
"<=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"add",
")",
"{",
"return",
"update_post_meta",
"(",
"$",
"post_id",
",",
"$",
"this",
"->",
"get_meta_key",
"(",
"$",
"key",
")",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"unique",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"post_id",
",",
"false",
",",
"[",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"values",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"add_post_meta",
"(",
"$",
"post_id",
",",
"$",
"this",
"->",
"get_meta_key",
"(",
"$",
"key",
")",
",",
"$",
"value",
")",
";",
"}"
] | @param int $post_id
@param string $key
@param mixed $value
@param bool $add
@param bool $unique
@return bool|int | [
"@param",
"int",
"$post_id",
"@param",
"string",
"$key",
"@param",
"mixed",
"$value",
"@param",
"bool",
"$add",
"@param",
"bool",
"$unique"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L95-L112 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.delete | public function delete( $post_id, $key, $meta_value = '' ) {
if ( $post_id <= 0 ) {
return false;
}
return delete_post_meta( $post_id, $this->get_meta_key( $key ), $meta_value );
} | php | public function delete( $post_id, $key, $meta_value = '' ) {
if ( $post_id <= 0 ) {
return false;
}
return delete_post_meta( $post_id, $this->get_meta_key( $key ), $meta_value );
} | [
"public",
"function",
"delete",
"(",
"$",
"post_id",
",",
"$",
"key",
",",
"$",
"meta_value",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"post_id",
"<=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"return",
"delete_post_meta",
"(",
"$",
"post_id",
",",
"$",
"this",
"->",
"get_meta_key",
"(",
"$",
"key",
")",
",",
"$",
"meta_value",
")",
";",
"}"
] | @param int $post_id
@param string $key
@param mixed $meta_value
@return bool | [
"@param",
"int",
"$post_id",
"@param",
"string",
"$key",
"@param",
"mixed",
"$meta_value"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L121-L127 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.delete_matched | public function delete_matched( $key, $value ) {
$post_ids = $this->find( $key, $value );
if ( empty( $post_ids ) ) {
return true;
}
foreach ( $post_ids as $post_id ) {
$this->delete( $key, $post_id );
}
return true;
} | php | public function delete_matched( $key, $value ) {
$post_ids = $this->find( $key, $value );
if ( empty( $post_ids ) ) {
return true;
}
foreach ( $post_ids as $post_id ) {
$this->delete( $key, $post_id );
}
return true;
} | [
"public",
"function",
"delete_matched",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"post_ids",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"post_ids",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"post_ids",
"as",
"$",
"post_id",
")",
"{",
"$",
"this",
"->",
"delete",
"(",
"$",
"key",
",",
"$",
"post_id",
")",
";",
"}",
"return",
"true",
";",
"}"
] | @param string $key
@param string $value
@return bool | [
"@param",
"string",
"$key",
"@param",
"string",
"$value"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L154-L164 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.first | public function first( $key, $value ) {
$post_ids = $this->find( $key, $value );
if ( empty( $post_ids ) ) {
return false;
}
return reset( $post_ids );
} | php | public function first( $key, $value ) {
$post_ids = $this->find( $key, $value );
if ( empty( $post_ids ) ) {
return false;
}
return reset( $post_ids );
} | [
"public",
"function",
"first",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"post_ids",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"post_ids",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"reset",
"(",
"$",
"post_ids",
")",
";",
"}"
] | @param string $key
@param string $value
@return false|int | [
"@param",
"string",
"$key",
"@param",
"string",
"$value"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L190-L197 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.has_shortcode | public function has_shortcode( $tags ) {
if ( empty( $tags ) ) {
return false;
}
$tagnames = $this->get_tagnames();
if ( empty( $tagnames ) ) {
return false;
}
! is_array( $tags ) and $tags = [ $tags ];
return ! empty( array_intersect( $tags, $tagnames ) );
} | php | public function has_shortcode( $tags ) {
if ( empty( $tags ) ) {
return false;
}
$tagnames = $this->get_tagnames();
if ( empty( $tagnames ) ) {
return false;
}
! is_array( $tags ) and $tags = [ $tags ];
return ! empty( array_intersect( $tags, $tagnames ) );
} | [
"public",
"function",
"has_shortcode",
"(",
"$",
"tags",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"tags",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tagnames",
"=",
"$",
"this",
"->",
"get_tagnames",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"tagnames",
")",
")",
"{",
"return",
"false",
";",
"}",
"!",
"is_array",
"(",
"$",
"tags",
")",
"and",
"$",
"tags",
"=",
"[",
"$",
"tags",
"]",
";",
"return",
"!",
"empty",
"(",
"array_intersect",
"(",
"$",
"tags",
",",
"$",
"tagnames",
")",
")",
";",
"}"
] | @param array|string $tags
@return bool | [
"@param",
"array|string",
"$tags"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L220-L232 |
technote-space/wordpress-plugin-base | src/classes/models/lib/post.php | Post.uninstall | public function uninstall() {
global $wpdb;
$query = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s", $this->get_post_prefix() . '%' );
$wpdb->query( $query );
} | php | public function uninstall() {
global $wpdb;
$query = $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s", $this->get_post_prefix() . '%' );
$wpdb->query( $query );
} | [
"public",
"function",
"uninstall",
"(",
")",
"{",
"global",
"$",
"wpdb",
";",
"$",
"query",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"DELETE FROM $wpdb->postmeta WHERE meta_key LIKE %s\"",
",",
"$",
"this",
"->",
"get_post_prefix",
"(",
")",
".",
"'%'",
")",
";",
"$",
"wpdb",
"->",
"query",
"(",
"$",
"query",
")",
";",
"}"
] | uninstall | [
"uninstall"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/post.php#L285-L289 |
zhouyl/mellivora | Mellivora/View/FileViewFinder.php | FileViewFinder.findInPaths | protected function findInPaths($name, $paths)
{
foreach ((array) $paths as $path) {
foreach ($this->getPossibleViewFiles($name) as $file) {
if (is_file($viewPath = $path . '/' . $file)) {
return $viewPath;
}
}
}
throw new InvalidArgumentException("View [$name] not found.");
} | php | protected function findInPaths($name, $paths)
{
foreach ((array) $paths as $path) {
foreach ($this->getPossibleViewFiles($name) as $file) {
if (is_file($viewPath = $path . '/' . $file)) {
return $viewPath;
}
}
}
throw new InvalidArgumentException("View [$name] not found.");
} | [
"protected",
"function",
"findInPaths",
"(",
"$",
"name",
",",
"$",
"paths",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getPossibleViewFiles",
"(",
"$",
"name",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"viewPath",
"=",
"$",
"path",
".",
"'/'",
".",
"$",
"file",
")",
")",
"{",
"return",
"$",
"viewPath",
";",
"}",
"}",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"View [$name] not found.\"",
")",
";",
"}"
] | Find the given view in the list of paths.
@param string $name
@param array $paths
@throws \InvalidArgumentException
@return string | [
"Find",
"the",
"given",
"view",
"in",
"the",
"list",
"of",
"paths",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/View/FileViewFinder.php#L122-L133 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.initialize | protected function initialize() {
if ( ! $this->app->isset_shared_object( 'session_initialized', 'all' ) ) {
$this->app->set_shared_object( 'session_initialized', true, 'all' );
if ( ! $this->app->isset_shared_object( 'session_user_check_name', 'all' ) ) {
$this->app->set_shared_object( 'session_user_check_name', 'user_check', 'all' );
}
$this->check_session();
}
} | php | protected function initialize() {
if ( ! $this->app->isset_shared_object( 'session_initialized', 'all' ) ) {
$this->app->set_shared_object( 'session_initialized', true, 'all' );
if ( ! $this->app->isset_shared_object( 'session_user_check_name', 'all' ) ) {
$this->app->set_shared_object( 'session_user_check_name', 'user_check', 'all' );
}
$this->check_session();
}
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"->",
"isset_shared_object",
"(",
"'session_initialized'",
",",
"'all'",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"set_shared_object",
"(",
"'session_initialized'",
",",
"true",
",",
"'all'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"->",
"isset_shared_object",
"(",
"'session_user_check_name'",
",",
"'all'",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"set_shared_object",
"(",
"'session_user_check_name'",
",",
"'user_check'",
",",
"'all'",
")",
";",
"}",
"$",
"this",
"->",
"check_session",
"(",
")",
";",
"}",
"}"
] | initialize | [
"initialize"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L38-L46 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.check_session | private function check_session() {
if ( ! isset( $_SESSION ) ) {
@session_start();
}
if ( isset( $_SESSION ) ) {
$this->app->set_shared_object( 'is_valid_session', true, 'all' );
}
$this->security_process();
} | php | private function check_session() {
if ( ! isset( $_SESSION ) ) {
@session_start();
}
if ( isset( $_SESSION ) ) {
$this->app->set_shared_object( 'is_valid_session', true, 'all' );
}
$this->security_process();
} | [
"private",
"function",
"check_session",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
")",
")",
"{",
"@",
"session_start",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"set_shared_object",
"(",
"'is_valid_session'",
",",
"true",
",",
"'all'",
")",
";",
"}",
"$",
"this",
"->",
"security_process",
"(",
")",
";",
"}"
] | check | [
"check"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L67-L75 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.security_process | private function security_process() {
$check = $this->get( $this->get_user_check_name() );
if ( ! isset( $check ) ) {
$this->set( $this->get_user_check_name(), $this->app->user->user_id );
} else {
if ( $check != $this->app->user->user_id ) {
// prevent session fixation
$this->regenerate();
$this->set( $this->get_user_check_name(), $this->app->user->user_id );
}
}
} | php | private function security_process() {
$check = $this->get( $this->get_user_check_name() );
if ( ! isset( $check ) ) {
$this->set( $this->get_user_check_name(), $this->app->user->user_id );
} else {
if ( $check != $this->app->user->user_id ) {
// prevent session fixation
$this->regenerate();
$this->set( $this->get_user_check_name(), $this->app->user->user_id );
}
}
} | [
"private",
"function",
"security_process",
"(",
")",
"{",
"$",
"check",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"get_user_check_name",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"check",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"this",
"->",
"get_user_check_name",
"(",
")",
",",
"$",
"this",
"->",
"app",
"->",
"user",
"->",
"user_id",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"check",
"!=",
"$",
"this",
"->",
"app",
"->",
"user",
"->",
"user_id",
")",
"{",
"// prevent session fixation",
"$",
"this",
"->",
"regenerate",
"(",
")",
";",
"$",
"this",
"->",
"set",
"(",
"$",
"this",
"->",
"get_user_check_name",
"(",
")",
",",
"$",
"this",
"->",
"app",
"->",
"user",
"->",
"user_id",
")",
";",
"}",
"}",
"}"
] | security | [
"security"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L80-L91 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.regenerate | public function regenerate() {
if ( $this->is_valid_session() ) {
if ( ! $this->app->isset_shared_object( 'session_regenerated', 'all' ) ) {
session_regenerate_id( true );
$this->app->set_shared_object( 'session_regenerated', true, 'all' );
}
}
} | php | public function regenerate() {
if ( $this->is_valid_session() ) {
if ( ! $this->app->isset_shared_object( 'session_regenerated', 'all' ) ) {
session_regenerate_id( true );
$this->app->set_shared_object( 'session_regenerated', true, 'all' );
}
}
} | [
"public",
"function",
"regenerate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_valid_session",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"->",
"isset_shared_object",
"(",
"'session_regenerated'",
",",
"'all'",
")",
")",
"{",
"session_regenerate_id",
"(",
"true",
")",
";",
"$",
"this",
"->",
"app",
"->",
"set_shared_object",
"(",
"'session_regenerated'",
",",
"true",
",",
"'all'",
")",
";",
"}",
"}",
"}"
] | regenerate | [
"regenerate"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L96-L103 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.destroy | public function destroy() {
if ( $this->is_valid_session() ) {
$_SESSION = [];
setcookie( session_name(), '', time() - 1, '/' );
session_destroy();
$this->app->delete_shared_object( 'is_valid_session', 'all' );
}
} | php | public function destroy() {
if ( $this->is_valid_session() ) {
$_SESSION = [];
setcookie( session_name(), '', time() - 1, '/' );
session_destroy();
$this->app->delete_shared_object( 'is_valid_session', 'all' );
}
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_valid_session",
"(",
")",
")",
"{",
"$",
"_SESSION",
"=",
"[",
"]",
";",
"setcookie",
"(",
"session_name",
"(",
")",
",",
"''",
",",
"time",
"(",
")",
"-",
"1",
",",
"'/'",
")",
";",
"session_destroy",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"delete_shared_object",
"(",
"'is_valid_session'",
",",
"'all'",
")",
";",
"}",
"}"
] | destroy | [
"destroy"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L108-L115 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session._get | private function _get( $key, $data, $default ) {
if ( ! is_array( $data ) || ! array_key_exists( 'value', $data ) ) {
return $default;
}
if ( $this->_expired( $data ) ) {
$this->_delete( $key );
return $default;
}
return $data['value'];
} | php | private function _get( $key, $data, $default ) {
if ( ! is_array( $data ) || ! array_key_exists( 'value', $data ) ) {
return $default;
}
if ( $this->_expired( $data ) ) {
$this->_delete( $key );
return $default;
}
return $data['value'];
} | [
"private",
"function",
"_get",
"(",
"$",
"key",
",",
"$",
"data",
",",
"$",
"default",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"||",
"!",
"array_key_exists",
"(",
"'value'",
",",
"$",
"data",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_expired",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"_delete",
"(",
"$",
"key",
")",
";",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"data",
"[",
"'value'",
"]",
";",
"}"
] | @param string $key
@param mixed $data
@param mixed $default
@return mixed | [
"@param",
"string",
"$key",
"@param",
"mixed",
"$data",
"@param",
"mixed",
"$default"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L137-L148 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.get | public function get( $key, $default = null ) {
if ( ! $this->is_valid_session() ) {
return $default;
}
$key = $this->get_session_key( $key );
if ( array_key_exists( $key, $_SESSION ) ) {
return $this->_get( $key, $_SESSION[ $key ], $default );
}
return $default;
} | php | public function get( $key, $default = null ) {
if ( ! $this->is_valid_session() ) {
return $default;
}
$key = $this->get_session_key( $key );
if ( array_key_exists( $key, $_SESSION ) ) {
return $this->_get( $key, $_SESSION[ $key ], $default );
}
return $default;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid_session",
"(",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"get_session_key",
"(",
"$",
"key",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"_SESSION",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_get",
"(",
"$",
"key",
",",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
",",
"$",
"default",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | @param string $key
@param mixed $default
@return mixed | [
"@param",
"string",
"$key",
"@param",
"mixed",
"$default"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L195-L205 |
technote-space/wordpress-plugin-base | src/classes/models/lib/session.php | Session.exists | public function exists( $key ) {
if ( ! $this->is_valid_session() ) {
return false;
}
$key = $this->get_session_key( $key );
if ( ! array_key_exists( $key, $_SESSION ) ) {
return false;
}
return ! $this->_expired( $_SESSION[ $key ] );
} | php | public function exists( $key ) {
if ( ! $this->is_valid_session() ) {
return false;
}
$key = $this->get_session_key( $key );
if ( ! array_key_exists( $key, $_SESSION ) ) {
return false;
}
return ! $this->_expired( $_SESSION[ $key ] );
} | [
"public",
"function",
"exists",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid_session",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"get_session_key",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"_SESSION",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"!",
"$",
"this",
"->",
"_expired",
"(",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | @param string $key
@return bool | [
"@param",
"string",
"$key"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/session.php#L225-L236 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._initWriter | protected function _initWriter()
{
$this->_writer = new Mage_Archive_Helper_File($this->_destinationFilePath);
$this->_writer->open('w');
return $this;
} | php | protected function _initWriter()
{
$this->_writer = new Mage_Archive_Helper_File($this->_destinationFilePath);
$this->_writer->open('w');
return $this;
} | [
"protected",
"function",
"_initWriter",
"(",
")",
"{",
"$",
"this",
"->",
"_writer",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"this",
"->",
"_destinationFilePath",
")",
";",
"$",
"this",
"->",
"_writer",
"->",
"open",
"(",
"'w'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Initialize tarball writer
@return Mage_Archive_Tar | [
"Initialize",
"tarball",
"writer"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L91-L97 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._destroyWriter | protected function _destroyWriter()
{
if ($this->_writer instanceof Mage_Archive_Helper_File) {
$this->_writer->close();
$this->_writer = null;
}
return $this;
} | php | protected function _destroyWriter()
{
if ($this->_writer instanceof Mage_Archive_Helper_File) {
$this->_writer->close();
$this->_writer = null;
}
return $this;
} | [
"protected",
"function",
"_destroyWriter",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_writer",
"instanceof",
"Mage_Archive_Helper_File",
")",
"{",
"$",
"this",
"->",
"_writer",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"_writer",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Destroy tarball writer
@return Mage_Archive_Tar | [
"Destroy",
"tarball",
"writer"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L119-L127 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._initReader | protected function _initReader()
{
$this->_reader = new Mage_Archive_Helper_File($this->_getCurrentFile());
$this->_reader->open('r');
return $this;
} | php | protected function _initReader()
{
$this->_reader = new Mage_Archive_Helper_File($this->_getCurrentFile());
$this->_reader->open('r');
return $this;
} | [
"protected",
"function",
"_initReader",
"(",
")",
"{",
"$",
"this",
"->",
"_reader",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
")",
";",
"$",
"this",
"->",
"_reader",
"->",
"open",
"(",
"'r'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Initialize tarball reader
@return Mage_Archive_Tar | [
"Initialize",
"tarball",
"reader"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L148-L154 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._destroyReader | protected function _destroyReader()
{
if ($this->_reader instanceof Mage_Archive_Helper_File) {
$this->_reader->close();
$this->_reader = null;
}
return $this;
} | php | protected function _destroyReader()
{
if ($this->_reader instanceof Mage_Archive_Helper_File) {
$this->_reader->close();
$this->_reader = null;
}
return $this;
} | [
"protected",
"function",
"_destroyReader",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_reader",
"instanceof",
"Mage_Archive_Helper_File",
")",
"{",
"$",
"this",
"->",
"_reader",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"_reader",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Destroy tarball reader
@return Mage_Archive_Tar | [
"Destroy",
"tarball",
"reader"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L161-L169 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._setCurrentFile | protected function _setCurrentFile($file)
{
$this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
return $this;
} | php | protected function _setCurrentFile($file)
{
$this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
return $this;
} | [
"protected",
"function",
"_setCurrentFile",
"(",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"_currentFile",
"=",
"$",
"file",
".",
"(",
"(",
"!",
"is_link",
"(",
"$",
"file",
")",
"&&",
"is_dir",
"(",
"$",
"file",
")",
"&&",
"substr",
"(",
"$",
"file",
",",
"-",
"1",
")",
"!=",
"DS",
")",
"?",
"DS",
":",
"''",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set file which is packing.
@param string $file
@return Mage_Archive_Tar | [
"Set",
"file",
"which",
"is",
"packing",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L203-L207 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._setCurrentPath | protected function _setCurrentPath($path)
{
if ($this->_skipRoot && is_dir($path)) {
$this->_currentPath = $path.(substr($path, -1)!=DS?DS:'');
} else {
$this->_currentPath = dirname($path) . DS;
}
return $this;
} | php | protected function _setCurrentPath($path)
{
if ($this->_skipRoot && is_dir($path)) {
$this->_currentPath = $path.(substr($path, -1)!=DS?DS:'');
} else {
$this->_currentPath = dirname($path) . DS;
}
return $this;
} | [
"protected",
"function",
"_setCurrentPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_skipRoot",
"&&",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"_currentPath",
"=",
"$",
"path",
".",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"!=",
"DS",
"?",
"DS",
":",
"''",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_currentPath",
"=",
"dirname",
"(",
"$",
"path",
")",
".",
"DS",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set path to file which is packing.
@param string $path
@return Mage_Archive_Tar | [
"Set",
"path",
"to",
"file",
"which",
"is",
"packing",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L237-L245 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._packToTar | protected function _packToTar($skipRoot=false)
{
$file = $this->_getCurrentFile();
$header = '';
$data = '';
if (!$skipRoot) {
$header = $this->_composeHeader();
$data = $this->_readFile($file);
$data = str_pad($data, floor(((is_dir($file) ? 0 : filesize($file)) + 512 - 1) / 512) * 512, "\0");
}
$sub = '';
if (is_dir($file)) {
$treeDir = scandir($file);
if (empty($treeDir)) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($treeDir); /* remove './'*/
array_shift($treeDir); /* remove '../'*/
foreach ($treeDir as $item) {
$sub .= $this->_setCurrentFile($file.$item)->_packToTar(false);
}
}
$tarData = $header . $data . $sub;
$tarData = str_pad($tarData, floor((strlen($tarData) - 1) / 1536) * 1536, "\0");
return $tarData;
} | php | protected function _packToTar($skipRoot=false)
{
$file = $this->_getCurrentFile();
$header = '';
$data = '';
if (!$skipRoot) {
$header = $this->_composeHeader();
$data = $this->_readFile($file);
$data = str_pad($data, floor(((is_dir($file) ? 0 : filesize($file)) + 512 - 1) / 512) * 512, "\0");
}
$sub = '';
if (is_dir($file)) {
$treeDir = scandir($file);
if (empty($treeDir)) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($treeDir); /* remove './'*/
array_shift($treeDir); /* remove '../'*/
foreach ($treeDir as $item) {
$sub .= $this->_setCurrentFile($file.$item)->_packToTar(false);
}
}
$tarData = $header . $data . $sub;
$tarData = str_pad($tarData, floor((strlen($tarData) - 1) / 1536) * 1536, "\0");
return $tarData;
} | [
"protected",
"function",
"_packToTar",
"(",
"$",
"skipRoot",
"=",
"false",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"$",
"header",
"=",
"''",
";",
"$",
"data",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"skipRoot",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"_composeHeader",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"_readFile",
"(",
"$",
"file",
")",
";",
"$",
"data",
"=",
"str_pad",
"(",
"$",
"data",
",",
"floor",
"(",
"(",
"(",
"is_dir",
"(",
"$",
"file",
")",
"?",
"0",
":",
"filesize",
"(",
"$",
"file",
")",
")",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
",",
"\"\\0\"",
")",
";",
"}",
"$",
"sub",
"=",
"''",
";",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"$",
"treeDir",
"=",
"scandir",
"(",
"$",
"file",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"treeDir",
")",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Can\\'t scan dir: '",
".",
"$",
"file",
")",
";",
"}",
"array_shift",
"(",
"$",
"treeDir",
")",
";",
"/* remove './'*/",
"array_shift",
"(",
"$",
"treeDir",
")",
";",
"/* remove '../'*/",
"foreach",
"(",
"$",
"treeDir",
"as",
"$",
"item",
")",
"{",
"$",
"sub",
".=",
"$",
"this",
"->",
"_setCurrentFile",
"(",
"$",
"file",
".",
"$",
"item",
")",
"->",
"_packToTar",
"(",
"false",
")",
";",
"}",
"}",
"$",
"tarData",
"=",
"$",
"header",
".",
"$",
"data",
".",
"$",
"sub",
";",
"$",
"tarData",
"=",
"str_pad",
"(",
"$",
"tarData",
",",
"floor",
"(",
"(",
"strlen",
"(",
"$",
"tarData",
")",
"-",
"1",
")",
"/",
"1536",
")",
"*",
"1536",
",",
"\"\\0\"",
")",
";",
"return",
"$",
"tarData",
";",
"}"
] | Walk through directory and add to tar file or directory.
Result is packed string on TAR format.
@deprecated after 1.7.0.0
@param boolean $skipRoot
@return string | [
"Walk",
"through",
"directory",
"and",
"add",
"to",
"tar",
"file",
"or",
"directory",
".",
"Result",
"is",
"packed",
"string",
"on",
"TAR",
"format",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L265-L290 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._createTar | protected function _createTar($skipRoot = false, $finalize = false)
{
if (!$skipRoot) {
$this->_packAndWriteCurrentFile();
}
$file = $this->_getCurrentFile();
if (is_dir($file)) {
$dirFiles = scandir($file);
if (false === $dirFiles) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($dirFiles); /* remove './'*/
array_shift($dirFiles); /* remove '../'*/
foreach ($dirFiles as $item) {
$this->_setCurrentFile($file . $item)->_createTar();
}
}
if ($finalize) {
$this->_getWriter()->write(str_repeat("\0", self::TAR_BLOCK_SIZE * 12));
}
} | php | protected function _createTar($skipRoot = false, $finalize = false)
{
if (!$skipRoot) {
$this->_packAndWriteCurrentFile();
}
$file = $this->_getCurrentFile();
if (is_dir($file)) {
$dirFiles = scandir($file);
if (false === $dirFiles) {
throw new Mage_Exception('Can\'t scan dir: ' . $file);
}
array_shift($dirFiles); /* remove './'*/
array_shift($dirFiles); /* remove '../'*/
foreach ($dirFiles as $item) {
$this->_setCurrentFile($file . $item)->_createTar();
}
}
if ($finalize) {
$this->_getWriter()->write(str_repeat("\0", self::TAR_BLOCK_SIZE * 12));
}
} | [
"protected",
"function",
"_createTar",
"(",
"$",
"skipRoot",
"=",
"false",
",",
"$",
"finalize",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"skipRoot",
")",
"{",
"$",
"this",
"->",
"_packAndWriteCurrentFile",
"(",
")",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"$",
"dirFiles",
"=",
"scandir",
"(",
"$",
"file",
")",
";",
"if",
"(",
"false",
"===",
"$",
"dirFiles",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Can\\'t scan dir: '",
".",
"$",
"file",
")",
";",
"}",
"array_shift",
"(",
"$",
"dirFiles",
")",
";",
"/* remove './'*/",
"array_shift",
"(",
"$",
"dirFiles",
")",
";",
"/* remove '../'*/",
"foreach",
"(",
"$",
"dirFiles",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"_setCurrentFile",
"(",
"$",
"file",
".",
"$",
"item",
")",
"->",
"_createTar",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"finalize",
")",
"{",
"$",
"this",
"->",
"_getWriter",
"(",
")",
"->",
"write",
"(",
"str_repeat",
"(",
"\"\\0\"",
",",
"self",
"::",
"TAR_BLOCK_SIZE",
"*",
"12",
")",
")",
";",
"}",
"}"
] | Recursively walk through file tree and create tarball
@param boolean $skipRoot
@param boolean $finalize
@throws Mage_Exception | [
"Recursively",
"walk",
"through",
"file",
"tree",
"and",
"create",
"tarball"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L299-L325 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._packAndWriteCurrentFile | protected function _packAndWriteCurrentFile()
{
$archiveWriter = $this->_getWriter();
$archiveWriter->write($this->_composeHeader());
$currentFile = $this->_getCurrentFile();
$fileSize = 0;
if (is_file($currentFile) && !is_link($currentFile)) {
$fileReader = new Mage_Archive_Helper_File($currentFile);
$fileReader->open('r');
while (!$fileReader->eof()) {
$archiveWriter->write($fileReader->read());
}
$fileReader->close();
$fileSize = filesize($currentFile);
}
$appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
$archiveWriter->write(str_repeat("\0", $appendZerosCount));
} | php | protected function _packAndWriteCurrentFile()
{
$archiveWriter = $this->_getWriter();
$archiveWriter->write($this->_composeHeader());
$currentFile = $this->_getCurrentFile();
$fileSize = 0;
if (is_file($currentFile) && !is_link($currentFile)) {
$fileReader = new Mage_Archive_Helper_File($currentFile);
$fileReader->open('r');
while (!$fileReader->eof()) {
$archiveWriter->write($fileReader->read());
}
$fileReader->close();
$fileSize = filesize($currentFile);
}
$appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
$archiveWriter->write(str_repeat("\0", $appendZerosCount));
} | [
"protected",
"function",
"_packAndWriteCurrentFile",
"(",
")",
"{",
"$",
"archiveWriter",
"=",
"$",
"this",
"->",
"_getWriter",
"(",
")",
";",
"$",
"archiveWriter",
"->",
"write",
"(",
"$",
"this",
"->",
"_composeHeader",
"(",
")",
")",
";",
"$",
"currentFile",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"$",
"fileSize",
"=",
"0",
";",
"if",
"(",
"is_file",
"(",
"$",
"currentFile",
")",
"&&",
"!",
"is_link",
"(",
"$",
"currentFile",
")",
")",
"{",
"$",
"fileReader",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"currentFile",
")",
";",
"$",
"fileReader",
"->",
"open",
"(",
"'r'",
")",
";",
"while",
"(",
"!",
"$",
"fileReader",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"archiveWriter",
"->",
"write",
"(",
"$",
"fileReader",
"->",
"read",
"(",
")",
")",
";",
"}",
"$",
"fileReader",
"->",
"close",
"(",
")",
";",
"$",
"fileSize",
"=",
"filesize",
"(",
"$",
"currentFile",
")",
";",
"}",
"$",
"appendZerosCount",
"=",
"(",
"self",
"::",
"TAR_BLOCK_SIZE",
"-",
"$",
"fileSize",
"%",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"%",
"self",
"::",
"TAR_BLOCK_SIZE",
";",
"$",
"archiveWriter",
"->",
"write",
"(",
"str_repeat",
"(",
"\"\\0\"",
",",
"$",
"appendZerosCount",
")",
")",
";",
"}"
] | Write current file to tarball | [
"Write",
"current",
"file",
"to",
"tarball"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L330-L354 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._composeHeader | protected function _composeHeader($long = false)
{
$file = $this->_getCurrentFile();
$path = $this->_getCurrentPath();
$infoFile = stat($file);
$nameFile = str_replace($path, '', $file);
$nameFile = str_replace('\\', '/', $nameFile);
$packedHeader = '';
$longHeader = '';
if (!$long && strlen($nameFile)>100) {
$longHeader = $this->_composeHeader(true);
$longHeader .= str_pad($nameFile, floor((strlen($nameFile) + 512 - 1) / 512) * 512, "\0");
}
$header = array();
$header['100-name'] = $long?'././@LongLink':substr($nameFile, 0, 100);
$header['8-mode'] = $long ? ' '
: str_pad(substr(sprintf("%07o", $infoFile['mode']),-4), 6, '0', STR_PAD_LEFT);
$header['8-uid'] = $long || $infoFile['uid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['uid']);
$header['8-gid'] = $long || $infoFile['gid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['gid']);
$header['12-size'] = $long ? sprintf("%011o", strlen($nameFile)) : sprintf("%011o", is_dir($file)
? 0 : filesize($file));
$header['12-mtime'] = $long?'00000000000':sprintf("%011o", $infoFile['mtime']);
$header['8-check'] = sprintf('% 8s', '');
$header['1-type'] = $long ? 'L' : (is_link($file) ? 2 : (is_dir($file) ? 5 : 0));
$header['100-symlink'] = is_link($file) ? readlink($file) : '';
$header['6-magic'] = 'ustar ';
$header['2-version'] = ' ';
$a=function_exists('posix_getpwuid')?posix_getpwuid (fileowner($file)):array('name'=>'');
$header['32-uname'] = $a['name'];
$a=function_exists('posix_getgrgid')?posix_getgrgid (filegroup($file)):array('name'=>'');
$header['32-gname'] = $a['name'];
$header['8-devmajor'] = '';
$header['8-devminor'] = '';
$header['155-prefix'] = '';
$header['12-closer'] = '';
$packedHeader = '';
foreach ($header as $key=>$element) {
$length = explode('-', $key);
$packedHeader .= pack('a' . $length[0], $element);
}
$checksum = 0;
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($packedHeader, $i, 1));
}
$packedHeader = substr_replace($packedHeader, sprintf("%07o", $checksum)."\0", 148, 8);
return $longHeader . $packedHeader;
} | php | protected function _composeHeader($long = false)
{
$file = $this->_getCurrentFile();
$path = $this->_getCurrentPath();
$infoFile = stat($file);
$nameFile = str_replace($path, '', $file);
$nameFile = str_replace('\\', '/', $nameFile);
$packedHeader = '';
$longHeader = '';
if (!$long && strlen($nameFile)>100) {
$longHeader = $this->_composeHeader(true);
$longHeader .= str_pad($nameFile, floor((strlen($nameFile) + 512 - 1) / 512) * 512, "\0");
}
$header = array();
$header['100-name'] = $long?'././@LongLink':substr($nameFile, 0, 100);
$header['8-mode'] = $long ? ' '
: str_pad(substr(sprintf("%07o", $infoFile['mode']),-4), 6, '0', STR_PAD_LEFT);
$header['8-uid'] = $long || $infoFile['uid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['uid']);
$header['8-gid'] = $long || $infoFile['gid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['gid']);
$header['12-size'] = $long ? sprintf("%011o", strlen($nameFile)) : sprintf("%011o", is_dir($file)
? 0 : filesize($file));
$header['12-mtime'] = $long?'00000000000':sprintf("%011o", $infoFile['mtime']);
$header['8-check'] = sprintf('% 8s', '');
$header['1-type'] = $long ? 'L' : (is_link($file) ? 2 : (is_dir($file) ? 5 : 0));
$header['100-symlink'] = is_link($file) ? readlink($file) : '';
$header['6-magic'] = 'ustar ';
$header['2-version'] = ' ';
$a=function_exists('posix_getpwuid')?posix_getpwuid (fileowner($file)):array('name'=>'');
$header['32-uname'] = $a['name'];
$a=function_exists('posix_getgrgid')?posix_getgrgid (filegroup($file)):array('name'=>'');
$header['32-gname'] = $a['name'];
$header['8-devmajor'] = '';
$header['8-devminor'] = '';
$header['155-prefix'] = '';
$header['12-closer'] = '';
$packedHeader = '';
foreach ($header as $key=>$element) {
$length = explode('-', $key);
$packedHeader .= pack('a' . $length[0], $element);
}
$checksum = 0;
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($packedHeader, $i, 1));
}
$packedHeader = substr_replace($packedHeader, sprintf("%07o", $checksum)."\0", 148, 8);
return $longHeader . $packedHeader;
} | [
"protected",
"function",
"_composeHeader",
"(",
"$",
"long",
"=",
"false",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"_getCurrentFile",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"_getCurrentPath",
"(",
")",
";",
"$",
"infoFile",
"=",
"stat",
"(",
"$",
"file",
")",
";",
"$",
"nameFile",
"=",
"str_replace",
"(",
"$",
"path",
",",
"''",
",",
"$",
"file",
")",
";",
"$",
"nameFile",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"nameFile",
")",
";",
"$",
"packedHeader",
"=",
"''",
";",
"$",
"longHeader",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"long",
"&&",
"strlen",
"(",
"$",
"nameFile",
")",
">",
"100",
")",
"{",
"$",
"longHeader",
"=",
"$",
"this",
"->",
"_composeHeader",
"(",
"true",
")",
";",
"$",
"longHeader",
".=",
"str_pad",
"(",
"$",
"nameFile",
",",
"floor",
"(",
"(",
"strlen",
"(",
"$",
"nameFile",
")",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
",",
"\"\\0\"",
")",
";",
"}",
"$",
"header",
"=",
"array",
"(",
")",
";",
"$",
"header",
"[",
"'100-name'",
"]",
"=",
"$",
"long",
"?",
"'././@LongLink'",
":",
"substr",
"(",
"$",
"nameFile",
",",
"0",
",",
"100",
")",
";",
"$",
"header",
"[",
"'8-mode'",
"]",
"=",
"$",
"long",
"?",
"' '",
":",
"str_pad",
"(",
"substr",
"(",
"sprintf",
"(",
"\"%07o\"",
",",
"$",
"infoFile",
"[",
"'mode'",
"]",
")",
",",
"-",
"4",
")",
",",
"6",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"$",
"header",
"[",
"'8-uid'",
"]",
"=",
"$",
"long",
"||",
"$",
"infoFile",
"[",
"'uid'",
"]",
"==",
"0",
"?",
"\"\\0\\0\\0\\0\\0\\0\\0\"",
":",
"sprintf",
"(",
"\"%07o\"",
",",
"$",
"infoFile",
"[",
"'uid'",
"]",
")",
";",
"$",
"header",
"[",
"'8-gid'",
"]",
"=",
"$",
"long",
"||",
"$",
"infoFile",
"[",
"'gid'",
"]",
"==",
"0",
"?",
"\"\\0\\0\\0\\0\\0\\0\\0\"",
":",
"sprintf",
"(",
"\"%07o\"",
",",
"$",
"infoFile",
"[",
"'gid'",
"]",
")",
";",
"$",
"header",
"[",
"'12-size'",
"]",
"=",
"$",
"long",
"?",
"sprintf",
"(",
"\"%011o\"",
",",
"strlen",
"(",
"$",
"nameFile",
")",
")",
":",
"sprintf",
"(",
"\"%011o\"",
",",
"is_dir",
"(",
"$",
"file",
")",
"?",
"0",
":",
"filesize",
"(",
"$",
"file",
")",
")",
";",
"$",
"header",
"[",
"'12-mtime'",
"]",
"=",
"$",
"long",
"?",
"'00000000000'",
":",
"sprintf",
"(",
"\"%011o\"",
",",
"$",
"infoFile",
"[",
"'mtime'",
"]",
")",
";",
"$",
"header",
"[",
"'8-check'",
"]",
"=",
"sprintf",
"(",
"'% 8s'",
",",
"''",
")",
";",
"$",
"header",
"[",
"'1-type'",
"]",
"=",
"$",
"long",
"?",
"'L'",
":",
"(",
"is_link",
"(",
"$",
"file",
")",
"?",
"2",
":",
"(",
"is_dir",
"(",
"$",
"file",
")",
"?",
"5",
":",
"0",
")",
")",
";",
"$",
"header",
"[",
"'100-symlink'",
"]",
"=",
"is_link",
"(",
"$",
"file",
")",
"?",
"readlink",
"(",
"$",
"file",
")",
":",
"''",
";",
"$",
"header",
"[",
"'6-magic'",
"]",
"=",
"'ustar '",
";",
"$",
"header",
"[",
"'2-version'",
"]",
"=",
"' '",
";",
"$",
"a",
"=",
"function_exists",
"(",
"'posix_getpwuid'",
")",
"?",
"posix_getpwuid",
"(",
"fileowner",
"(",
"$",
"file",
")",
")",
":",
"array",
"(",
"'name'",
"=>",
"''",
")",
";",
"$",
"header",
"[",
"'32-uname'",
"]",
"=",
"$",
"a",
"[",
"'name'",
"]",
";",
"$",
"a",
"=",
"function_exists",
"(",
"'posix_getgrgid'",
")",
"?",
"posix_getgrgid",
"(",
"filegroup",
"(",
"$",
"file",
")",
")",
":",
"array",
"(",
"'name'",
"=>",
"''",
")",
";",
"$",
"header",
"[",
"'32-gname'",
"]",
"=",
"$",
"a",
"[",
"'name'",
"]",
";",
"$",
"header",
"[",
"'8-devmajor'",
"]",
"=",
"''",
";",
"$",
"header",
"[",
"'8-devminor'",
"]",
"=",
"''",
";",
"$",
"header",
"[",
"'155-prefix'",
"]",
"=",
"''",
";",
"$",
"header",
"[",
"'12-closer'",
"]",
"=",
"''",
";",
"$",
"packedHeader",
"=",
"''",
";",
"foreach",
"(",
"$",
"header",
"as",
"$",
"key",
"=>",
"$",
"element",
")",
"{",
"$",
"length",
"=",
"explode",
"(",
"'-'",
",",
"$",
"key",
")",
";",
"$",
"packedHeader",
".=",
"pack",
"(",
"'a'",
".",
"$",
"length",
"[",
"0",
"]",
",",
"$",
"element",
")",
";",
"}",
"$",
"checksum",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"512",
";",
"$",
"i",
"++",
")",
"{",
"$",
"checksum",
"+=",
"ord",
"(",
"substr",
"(",
"$",
"packedHeader",
",",
"$",
"i",
",",
"1",
")",
")",
";",
"}",
"$",
"packedHeader",
"=",
"substr_replace",
"(",
"$",
"packedHeader",
",",
"sprintf",
"(",
"\"%07o\"",
",",
"$",
"checksum",
")",
".",
"\"\\0\"",
",",
"148",
",",
"8",
")",
";",
"return",
"$",
"longHeader",
".",
"$",
"packedHeader",
";",
"}"
] | Compose header for current file in TAR format.
If length of file's name greater 100 characters,
method breaks header into two pieces. First contains
header and data with long name. Second contain only header.
@param boolean $long
@return string | [
"Compose",
"header",
"for",
"current",
"file",
"in",
"TAR",
"format",
".",
"If",
"length",
"of",
"file",
"s",
"name",
"greater",
"100",
"characters",
"method",
"breaks",
"header",
"into",
"two",
"pieces",
".",
"First",
"contains",
"header",
"and",
"data",
"with",
"long",
"name",
".",
"Second",
"contain",
"only",
"header",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L365-L414 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._unpackCurrentTar | protected function _unpackCurrentTar($destination)
{
$archiveReader = $this->_getReader();
$list = array();
while (!$archiveReader->eof()) {
$header = $this->_extractFileHeader();
if (!$header) {
continue;
}
$currentFile = $destination . $header['name'];
$dirname = dirname($currentFile);
if (in_array($header['type'], array("0",chr(0), ''))) {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($dirname, 0777, true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $dirname);
}
}
$this->_extractAndWriteFile($header, $currentFile);
$list[] = $currentFile;
} elseif ($header['type'] == '5') {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($currentFile, $header['mode'], true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $currentFile);
}
}
$list[] = $currentFile . DS;
} elseif ($header['type'] == '2') {
//we do not interrupt unpack process if symlink creation failed as symlinks are not so important
@symlink($header['symlink'], $currentFile);
}
}
return $list;
} | php | protected function _unpackCurrentTar($destination)
{
$archiveReader = $this->_getReader();
$list = array();
while (!$archiveReader->eof()) {
$header = $this->_extractFileHeader();
if (!$header) {
continue;
}
$currentFile = $destination . $header['name'];
$dirname = dirname($currentFile);
if (in_array($header['type'], array("0",chr(0), ''))) {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($dirname, 0777, true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $dirname);
}
}
$this->_extractAndWriteFile($header, $currentFile);
$list[] = $currentFile;
} elseif ($header['type'] == '5') {
if(!file_exists($dirname)) {
$mkdirResult = @mkdir($currentFile, $header['mode'], true);
if (false === $mkdirResult) {
throw new Mage_Exception('Failed to create directory ' . $currentFile);
}
}
$list[] = $currentFile . DS;
} elseif ($header['type'] == '2') {
//we do not interrupt unpack process if symlink creation failed as symlinks are not so important
@symlink($header['symlink'], $currentFile);
}
}
return $list;
} | [
"protected",
"function",
"_unpackCurrentTar",
"(",
"$",
"destination",
")",
"{",
"$",
"archiveReader",
"=",
"$",
"this",
"->",
"_getReader",
"(",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"while",
"(",
"!",
"$",
"archiveReader",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"_extractFileHeader",
"(",
")",
";",
"if",
"(",
"!",
"$",
"header",
")",
"{",
"continue",
";",
"}",
"$",
"currentFile",
"=",
"$",
"destination",
".",
"$",
"header",
"[",
"'name'",
"]",
";",
"$",
"dirname",
"=",
"dirname",
"(",
"$",
"currentFile",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"header",
"[",
"'type'",
"]",
",",
"array",
"(",
"\"0\"",
",",
"chr",
"(",
"0",
")",
",",
"''",
")",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dirname",
")",
")",
"{",
"$",
"mkdirResult",
"=",
"@",
"mkdir",
"(",
"$",
"dirname",
",",
"0777",
",",
"true",
")",
";",
"if",
"(",
"false",
"===",
"$",
"mkdirResult",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Failed to create directory '",
".",
"$",
"dirname",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_extractAndWriteFile",
"(",
"$",
"header",
",",
"$",
"currentFile",
")",
";",
"$",
"list",
"[",
"]",
"=",
"$",
"currentFile",
";",
"}",
"elseif",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'5'",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dirname",
")",
")",
"{",
"$",
"mkdirResult",
"=",
"@",
"mkdir",
"(",
"$",
"currentFile",
",",
"$",
"header",
"[",
"'mode'",
"]",
",",
"true",
")",
";",
"if",
"(",
"false",
"===",
"$",
"mkdirResult",
")",
"{",
"throw",
"new",
"Mage_Exception",
"(",
"'Failed to create directory '",
".",
"$",
"currentFile",
")",
";",
"}",
"}",
"$",
"list",
"[",
"]",
"=",
"$",
"currentFile",
".",
"DS",
";",
"}",
"elseif",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'2'",
")",
"{",
"//we do not interrupt unpack process if symlink creation failed as symlinks are not so important",
"@",
"symlink",
"(",
"$",
"header",
"[",
"'symlink'",
"]",
",",
"$",
"currentFile",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
] | Read TAR string from file, and unpacked it.
Create files and directories information about discribed
in the string.
@param string $destination path to file is unpacked
@return array list of files
@throws Mage_Exception | [
"Read",
"TAR",
"string",
"from",
"file",
"and",
"unpacked",
"it",
".",
"Create",
"files",
"and",
"directories",
"information",
"about",
"discribed",
"in",
"the",
"string",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L425-L471 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._parseHeader | protected function _parseHeader(&$pointer)
{
$firstLine = fread($pointer, 512);
if (strlen($firstLine)<512){
return false;
}
$fmt = self::_getFormatParseHeader();
$header = unpack ($fmt, $firstLine);
$header['mode']=$header['mode']+0;
$header['uid']=octdec($header['uid']);
$header['gid']=octdec($header['gid']);
$header['size']=octdec($header['size']);
$header['mtime']=octdec($header['mtime']);
$header['checksum']=octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$firstLine = substr_replace($firstLine, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($firstLine, $i, 1));
}
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if ($header['name'] == '././@LongLink' && $header['type'] == 'L') {
$realName = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
$headerMain = $this->_parseHeader($pointer);
$headerMain['name'] = $realName;
return $headerMain;
} else {
if ($header['size']>0) {
$header['data'] = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
} else {
$header['data'] = '';
}
return $header;
}
}
return false;
} | php | protected function _parseHeader(&$pointer)
{
$firstLine = fread($pointer, 512);
if (strlen($firstLine)<512){
return false;
}
$fmt = self::_getFormatParseHeader();
$header = unpack ($fmt, $firstLine);
$header['mode']=$header['mode']+0;
$header['uid']=octdec($header['uid']);
$header['gid']=octdec($header['gid']);
$header['size']=octdec($header['size']);
$header['mtime']=octdec($header['mtime']);
$header['checksum']=octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$firstLine = substr_replace($firstLine, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($firstLine, $i, 1));
}
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if ($header['name'] == '././@LongLink' && $header['type'] == 'L') {
$realName = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
$headerMain = $this->_parseHeader($pointer);
$headerMain['name'] = $realName;
return $headerMain;
} else {
if ($header['size']>0) {
$header['data'] = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
} else {
$header['data'] = '';
}
return $header;
}
}
return false;
} | [
"protected",
"function",
"_parseHeader",
"(",
"&",
"$",
"pointer",
")",
"{",
"$",
"firstLine",
"=",
"fread",
"(",
"$",
"pointer",
",",
"512",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"firstLine",
")",
"<",
"512",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fmt",
"=",
"self",
"::",
"_getFormatParseHeader",
"(",
")",
";",
"$",
"header",
"=",
"unpack",
"(",
"$",
"fmt",
",",
"$",
"firstLine",
")",
";",
"$",
"header",
"[",
"'mode'",
"]",
"=",
"$",
"header",
"[",
"'mode'",
"]",
"+",
"0",
";",
"$",
"header",
"[",
"'uid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'uid'",
"]",
")",
";",
"$",
"header",
"[",
"'gid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'gid'",
"]",
")",
";",
"$",
"header",
"[",
"'size'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"header",
"[",
"'mtime'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'mtime'",
"]",
")",
";",
"$",
"header",
"[",
"'checksum'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'checksum'",
"]",
")",
";",
"if",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"\"5\"",
")",
"{",
"$",
"header",
"[",
"'size'",
"]",
"=",
"0",
";",
"}",
"$",
"checksum",
"=",
"0",
";",
"$",
"firstLine",
"=",
"substr_replace",
"(",
"$",
"firstLine",
",",
"' '",
",",
"148",
",",
"8",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"512",
";",
"$",
"i",
"++",
")",
"{",
"$",
"checksum",
"+=",
"ord",
"(",
"substr",
"(",
"$",
"firstLine",
",",
"$",
"i",
",",
"1",
")",
")",
";",
"}",
"$",
"isUstar",
"=",
"'ustar'",
"==",
"strtolower",
"(",
"substr",
"(",
"$",
"header",
"[",
"'magic'",
"]",
",",
"0",
",",
"5",
")",
")",
";",
"$",
"checksumOk",
"=",
"$",
"header",
"[",
"'checksum'",
"]",
"==",
"$",
"checksum",
";",
"if",
"(",
"isset",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
"&&",
"$",
"checksumOk",
")",
"{",
"if",
"(",
"$",
"header",
"[",
"'name'",
"]",
"==",
"'././@LongLink'",
"&&",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'L'",
")",
"{",
"$",
"realName",
"=",
"substr",
"(",
"fread",
"(",
"$",
"pointer",
",",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
")",
",",
"0",
",",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"headerMain",
"=",
"$",
"this",
"->",
"_parseHeader",
"(",
"$",
"pointer",
")",
";",
"$",
"headerMain",
"[",
"'name'",
"]",
"=",
"$",
"realName",
";",
"return",
"$",
"headerMain",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"header",
"[",
"'size'",
"]",
">",
"0",
")",
"{",
"$",
"header",
"[",
"'data'",
"]",
"=",
"substr",
"(",
"fread",
"(",
"$",
"pointer",
",",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"512",
"-",
"1",
")",
"/",
"512",
")",
"*",
"512",
")",
",",
"0",
",",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"header",
"[",
"'data'",
"]",
"=",
"''",
";",
"}",
"return",
"$",
"header",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get header from TAR string and unpacked it by format.
@deprecated after 1.7.0.0
@param resource $pointer
@return string | [
"Get",
"header",
"from",
"TAR",
"string",
"and",
"unpacked",
"it",
"by",
"format",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L480-L527 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._extractFileHeader | protected function _extractFileHeader()
{
$archiveReader = $this->_getReader();
$headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);
if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
return false;
}
$header = unpack(self::_getFormatParseHeader(), $headerBlock);
$header['mode'] = octdec($header['mode']);
$header['uid'] = octdec($header['uid']);
$header['gid'] = octdec($header['gid']);
$header['size'] = octdec($header['size']);
$header['mtime'] = octdec($header['mtime']);
$header['checksum'] = octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$headerBlock = substr_replace($headerBlock, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($headerBlock, $i, 1));
}
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
$header['name'] = trim($header['name']);
return $header;
}
$realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
* self::TAR_BLOCK_SIZE;
$realNameBlock = $archiveReader->read($realNameBlockSize);
$realName = substr($realNameBlock, 0, $header['size']);
$headerMain = $this->_extractFileHeader();
$headerMain['name'] = trim($realName);
return $headerMain;
}
return false;
} | php | protected function _extractFileHeader()
{
$archiveReader = $this->_getReader();
$headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);
if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
return false;
}
$header = unpack(self::_getFormatParseHeader(), $headerBlock);
$header['mode'] = octdec($header['mode']);
$header['uid'] = octdec($header['uid']);
$header['gid'] = octdec($header['gid']);
$header['size'] = octdec($header['size']);
$header['mtime'] = octdec($header['mtime']);
$header['checksum'] = octdec($header['checksum']);
if ($header['type'] == "5") {
$header['size'] = 0;
}
$checksum = 0;
$headerBlock = substr_replace($headerBlock, ' ', 148, 8);
for ($i = 0; $i < 512; $i++) {
$checksum += ord(substr($headerBlock, $i, 1));
}
$checksumOk = $header['checksum'] == $checksum;
if (isset($header['name']) && $checksumOk) {
if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
$header['name'] = trim($header['name']);
return $header;
}
$realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
* self::TAR_BLOCK_SIZE;
$realNameBlock = $archiveReader->read($realNameBlockSize);
$realName = substr($realNameBlock, 0, $header['size']);
$headerMain = $this->_extractFileHeader();
$headerMain['name'] = trim($realName);
return $headerMain;
}
return false;
} | [
"protected",
"function",
"_extractFileHeader",
"(",
")",
"{",
"$",
"archiveReader",
"=",
"$",
"this",
"->",
"_getReader",
"(",
")",
";",
"$",
"headerBlock",
"=",
"$",
"archiveReader",
"->",
"read",
"(",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"headerBlock",
")",
"<",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"{",
"return",
"false",
";",
"}",
"$",
"header",
"=",
"unpack",
"(",
"self",
"::",
"_getFormatParseHeader",
"(",
")",
",",
"$",
"headerBlock",
")",
";",
"$",
"header",
"[",
"'mode'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'mode'",
"]",
")",
";",
"$",
"header",
"[",
"'uid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'uid'",
"]",
")",
";",
"$",
"header",
"[",
"'gid'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'gid'",
"]",
")",
";",
"$",
"header",
"[",
"'size'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"header",
"[",
"'mtime'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'mtime'",
"]",
")",
";",
"$",
"header",
"[",
"'checksum'",
"]",
"=",
"octdec",
"(",
"$",
"header",
"[",
"'checksum'",
"]",
")",
";",
"if",
"(",
"$",
"header",
"[",
"'type'",
"]",
"==",
"\"5\"",
")",
"{",
"$",
"header",
"[",
"'size'",
"]",
"=",
"0",
";",
"}",
"$",
"checksum",
"=",
"0",
";",
"$",
"headerBlock",
"=",
"substr_replace",
"(",
"$",
"headerBlock",
",",
"' '",
",",
"148",
",",
"8",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"512",
";",
"$",
"i",
"++",
")",
"{",
"$",
"checksum",
"+=",
"ord",
"(",
"substr",
"(",
"$",
"headerBlock",
",",
"$",
"i",
",",
"1",
")",
")",
";",
"}",
"$",
"checksumOk",
"=",
"$",
"header",
"[",
"'checksum'",
"]",
"==",
"$",
"checksum",
";",
"if",
"(",
"isset",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
"&&",
"$",
"checksumOk",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"header",
"[",
"'name'",
"]",
"==",
"'././@LongLink'",
"&&",
"$",
"header",
"[",
"'type'",
"]",
"==",
"'L'",
")",
")",
"{",
"$",
"header",
"[",
"'name'",
"]",
"=",
"trim",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
";",
"return",
"$",
"header",
";",
"}",
"$",
"realNameBlockSize",
"=",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"self",
"::",
"TAR_BLOCK_SIZE",
"-",
"1",
")",
"/",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"*",
"self",
"::",
"TAR_BLOCK_SIZE",
";",
"$",
"realNameBlock",
"=",
"$",
"archiveReader",
"->",
"read",
"(",
"$",
"realNameBlockSize",
")",
";",
"$",
"realName",
"=",
"substr",
"(",
"$",
"realNameBlock",
",",
"0",
",",
"$",
"header",
"[",
"'size'",
"]",
")",
";",
"$",
"headerMain",
"=",
"$",
"this",
"->",
"_extractFileHeader",
"(",
")",
";",
"$",
"headerMain",
"[",
"'name'",
"]",
"=",
"trim",
"(",
"$",
"realName",
")",
";",
"return",
"$",
"headerMain",
";",
"}",
"return",
"false",
";",
"}"
] | Read and decode file header information from tarball
@return array|boolean | [
"Read",
"and",
"decode",
"file",
"header",
"information",
"from",
"tarball"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L534-L583 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar._extractAndWriteFile | protected function _extractAndWriteFile($fileHeader, $destination)
{
$fileWriter = new Mage_Archive_Helper_File($destination);
$fileWriter->open('w', $fileHeader['mode']);
$archiveReader = $this->_getReader();
$filesize = $fileHeader['size'];
$bytesExtracted = 0;
while ($filesize > $bytesExtracted && !$archiveReader->eof()) {
$block = $archiveReader->read(self::TAR_BLOCK_SIZE);
$nonExtractedBytesCount = $filesize - $bytesExtracted;
$data = substr($block, 0, $nonExtractedBytesCount);
$fileWriter->write($data);
$bytesExtracted += strlen($block);
}
} | php | protected function _extractAndWriteFile($fileHeader, $destination)
{
$fileWriter = new Mage_Archive_Helper_File($destination);
$fileWriter->open('w', $fileHeader['mode']);
$archiveReader = $this->_getReader();
$filesize = $fileHeader['size'];
$bytesExtracted = 0;
while ($filesize > $bytesExtracted && !$archiveReader->eof()) {
$block = $archiveReader->read(self::TAR_BLOCK_SIZE);
$nonExtractedBytesCount = $filesize - $bytesExtracted;
$data = substr($block, 0, $nonExtractedBytesCount);
$fileWriter->write($data);
$bytesExtracted += strlen($block);
}
} | [
"protected",
"function",
"_extractAndWriteFile",
"(",
"$",
"fileHeader",
",",
"$",
"destination",
")",
"{",
"$",
"fileWriter",
"=",
"new",
"Mage_Archive_Helper_File",
"(",
"$",
"destination",
")",
";",
"$",
"fileWriter",
"->",
"open",
"(",
"'w'",
",",
"$",
"fileHeader",
"[",
"'mode'",
"]",
")",
";",
"$",
"archiveReader",
"=",
"$",
"this",
"->",
"_getReader",
"(",
")",
";",
"$",
"filesize",
"=",
"$",
"fileHeader",
"[",
"'size'",
"]",
";",
"$",
"bytesExtracted",
"=",
"0",
";",
"while",
"(",
"$",
"filesize",
">",
"$",
"bytesExtracted",
"&&",
"!",
"$",
"archiveReader",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"block",
"=",
"$",
"archiveReader",
"->",
"read",
"(",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
";",
"$",
"nonExtractedBytesCount",
"=",
"$",
"filesize",
"-",
"$",
"bytesExtracted",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"block",
",",
"0",
",",
"$",
"nonExtractedBytesCount",
")",
";",
"$",
"fileWriter",
"->",
"write",
"(",
"$",
"data",
")",
";",
"$",
"bytesExtracted",
"+=",
"strlen",
"(",
"$",
"block",
")",
";",
"}",
"}"
] | Extract next file from tarball by its $header information and save it to $destination
@param array $fileHeader
@param string $destination | [
"Extract",
"next",
"file",
"from",
"tarball",
"by",
"its",
"$header",
"information",
"and",
"save",
"it",
"to",
"$destination"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L591-L610 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar.pack | public function pack($source, $destination, $skipRoot = false)
{
$this->_setSkipRoot($skipRoot);
$source = realpath($source);
$tarData = $this->_setCurrentPath($source)
->_setDestinationFilePath($destination)
->_setCurrentFile($source);
$this->_initWriter();
$this->_createTar($skipRoot, true);
$this->_destroyWriter();
return $destination;
} | php | public function pack($source, $destination, $skipRoot = false)
{
$this->_setSkipRoot($skipRoot);
$source = realpath($source);
$tarData = $this->_setCurrentPath($source)
->_setDestinationFilePath($destination)
->_setCurrentFile($source);
$this->_initWriter();
$this->_createTar($skipRoot, true);
$this->_destroyWriter();
return $destination;
} | [
"public",
"function",
"pack",
"(",
"$",
"source",
",",
"$",
"destination",
",",
"$",
"skipRoot",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_setSkipRoot",
"(",
"$",
"skipRoot",
")",
";",
"$",
"source",
"=",
"realpath",
"(",
"$",
"source",
")",
";",
"$",
"tarData",
"=",
"$",
"this",
"->",
"_setCurrentPath",
"(",
"$",
"source",
")",
"->",
"_setDestinationFilePath",
"(",
"$",
"destination",
")",
"->",
"_setCurrentFile",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"_initWriter",
"(",
")",
";",
"$",
"this",
"->",
"_createTar",
"(",
"$",
"skipRoot",
",",
"true",
")",
";",
"$",
"this",
"->",
"_destroyWriter",
"(",
")",
";",
"return",
"$",
"destination",
";",
"}"
] | Pack file to TAR (Tape Archiver).
@param string $source
@param string $destination
@param boolean $skipRoot
@return string | [
"Pack",
"file",
"to",
"TAR",
"(",
"Tape",
"Archiver",
")",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L620-L633 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar.unpack | public function unpack($source, $destination)
{
$this->_setCurrentFile($source)
->_setCurrentPath($source);
$this->_initReader();
$this->_unpackCurrentTar($destination);
$this->_destroyReader();
return $destination;
} | php | public function unpack($source, $destination)
{
$this->_setCurrentFile($source)
->_setCurrentPath($source);
$this->_initReader();
$this->_unpackCurrentTar($destination);
$this->_destroyReader();
return $destination;
} | [
"public",
"function",
"unpack",
"(",
"$",
"source",
",",
"$",
"destination",
")",
"{",
"$",
"this",
"->",
"_setCurrentFile",
"(",
"$",
"source",
")",
"->",
"_setCurrentPath",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"_initReader",
"(",
")",
";",
"$",
"this",
"->",
"_unpackCurrentTar",
"(",
"$",
"destination",
")",
";",
"$",
"this",
"->",
"_destroyReader",
"(",
")",
";",
"return",
"$",
"destination",
";",
"}"
] | Unpack file from TAR (Tape Archiver).
@param string $source
@param string $destination
@return string | [
"Unpack",
"file",
"from",
"TAR",
"(",
"Tape",
"Archiver",
")",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L642-L652 |
mridang/magazine | lib/magento/Archive/Tar.php | Mage_Archive_Tar.extract | public function extract($file, $source, $destination)
{
$this->_setCurrentFile($source);
$this->_initReader();
$archiveReader = $this->_getReader();
$extractedFile = '';
while (!$archiveReader->eof()) {
$header = $this->_extractFileHeader();
if ($header['name'] == $file) {
$extractedFile = $destination . basename($header['name']);
$this->_extractAndWriteFile($header, $extractedFile);
break;
}
if ($header['type'] != 5){
$skipBytes = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
* self::TAR_BLOCK_SIZE;
$archiveReader->read($skipBytes);
}
}
$this->_destroyReader();
return $extractedFile;
} | php | public function extract($file, $source, $destination)
{
$this->_setCurrentFile($source);
$this->_initReader();
$archiveReader = $this->_getReader();
$extractedFile = '';
while (!$archiveReader->eof()) {
$header = $this->_extractFileHeader();
if ($header['name'] == $file) {
$extractedFile = $destination . basename($header['name']);
$this->_extractAndWriteFile($header, $extractedFile);
break;
}
if ($header['type'] != 5){
$skipBytes = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
* self::TAR_BLOCK_SIZE;
$archiveReader->read($skipBytes);
}
}
$this->_destroyReader();
return $extractedFile;
} | [
"public",
"function",
"extract",
"(",
"$",
"file",
",",
"$",
"source",
",",
"$",
"destination",
")",
"{",
"$",
"this",
"->",
"_setCurrentFile",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"_initReader",
"(",
")",
";",
"$",
"archiveReader",
"=",
"$",
"this",
"->",
"_getReader",
"(",
")",
";",
"$",
"extractedFile",
"=",
"''",
";",
"while",
"(",
"!",
"$",
"archiveReader",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"_extractFileHeader",
"(",
")",
";",
"if",
"(",
"$",
"header",
"[",
"'name'",
"]",
"==",
"$",
"file",
")",
"{",
"$",
"extractedFile",
"=",
"$",
"destination",
".",
"basename",
"(",
"$",
"header",
"[",
"'name'",
"]",
")",
";",
"$",
"this",
"->",
"_extractAndWriteFile",
"(",
"$",
"header",
",",
"$",
"extractedFile",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"header",
"[",
"'type'",
"]",
"!=",
"5",
")",
"{",
"$",
"skipBytes",
"=",
"floor",
"(",
"(",
"$",
"header",
"[",
"'size'",
"]",
"+",
"self",
"::",
"TAR_BLOCK_SIZE",
"-",
"1",
")",
"/",
"self",
"::",
"TAR_BLOCK_SIZE",
")",
"*",
"self",
"::",
"TAR_BLOCK_SIZE",
";",
"$",
"archiveReader",
"->",
"read",
"(",
"$",
"skipBytes",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_destroyReader",
"(",
")",
";",
"return",
"$",
"extractedFile",
";",
"}"
] | Extract one file from TAR (Tape Archiver).
@param string $file
@param string $source
@param string $destination
@return string | [
"Extract",
"one",
"file",
"from",
"TAR",
"(",
"Tape",
"Archiver",
")",
"."
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Archive/Tar.php#L662-L687 |
stk2k/net-driver | src/Util/HttpCompressionUtil.php | HttpCompressionUtil.deflateBody | public static function deflateBody($body, $content_encoding)
{
switch($content_encoding){
case 'gzip':
case 'deflate':
case 'compress':
$body = @zlib_decode($body);
if ( $body === FALSE ){
throw new DeflateException();
}
return $body;
break;
default:
return $body;
break;
}
} | php | public static function deflateBody($body, $content_encoding)
{
switch($content_encoding){
case 'gzip':
case 'deflate':
case 'compress':
$body = @zlib_decode($body);
if ( $body === FALSE ){
throw new DeflateException();
}
return $body;
break;
default:
return $body;
break;
}
} | [
"public",
"static",
"function",
"deflateBody",
"(",
"$",
"body",
",",
"$",
"content_encoding",
")",
"{",
"switch",
"(",
"$",
"content_encoding",
")",
"{",
"case",
"'gzip'",
":",
"case",
"'deflate'",
":",
"case",
"'compress'",
":",
"$",
"body",
"=",
"@",
"zlib_decode",
"(",
"$",
"body",
")",
";",
"if",
"(",
"$",
"body",
"===",
"FALSE",
")",
"{",
"throw",
"new",
"DeflateException",
"(",
")",
";",
"}",
"return",
"$",
"body",
";",
"break",
";",
"default",
":",
"return",
"$",
"body",
";",
"break",
";",
"}",
"}"
] | deflate body
@param string $body
@param string $content_encoding
@return string
@throws DeflateException | [
"deflate",
"body"
] | train | https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Util/HttpCompressionUtil.php#L18-L34 |
madkom/regex | src/Grepper.php | Grepper.grep | public function grep(array $subjects, int $flags = 0) : array
{
$result = preg_grep($this->pattern->getPattern() . $this->modifier, $subjects, $flags);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $result;
} | php | public function grep(array $subjects, int $flags = 0) : array
{
$result = preg_grep($this->pattern->getPattern() . $this->modifier, $subjects, $flags);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $result;
} | [
"public",
"function",
"grep",
"(",
"array",
"$",
"subjects",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"array",
"{",
"$",
"result",
"=",
"preg_grep",
"(",
"$",
"this",
"->",
"pattern",
"->",
"getPattern",
"(",
")",
".",
"$",
"this",
"->",
"modifier",
",",
"$",
"subjects",
",",
"$",
"flags",
")",
";",
"if",
"(",
"(",
"$",
"errno",
"=",
"preg_last_error",
"(",
")",
")",
"!==",
"PREG_NO_ERROR",
")",
"{",
"$",
"message",
"=",
"array_flip",
"(",
"get_defined_constants",
"(",
"true",
")",
"[",
"'pcre'",
"]",
")",
"[",
"$",
"errno",
"]",
";",
"switch",
"(",
"$",
"errno",
")",
"{",
"case",
"PREG_INTERNAL_ERROR",
":",
"throw",
"new",
"InternalException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BACKTRACK_LIMIT_ERROR",
":",
"throw",
"new",
"BacktrackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_RECURSION_LIMIT_ERROR",
":",
"throw",
"new",
"RecursionLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_ERROR",
":",
"throw",
"new",
"BadUtf8Exception",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_OFFSET_ERROR",
":",
"throw",
"new",
"BadUtf8OffsetException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_JIT_STACKLIMIT_ERROR",
":",
"throw",
"new",
"JitStackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Retrieve grepped subjects array
@param array $subjects
@param int $flags
@return array
@throws BacktrackLimitException
@throws BadUtf8Exception
@throws BadUtf8OffsetException
@throws InternalException
@throws JitStackLimitException
@throws RecursionLimitException | [
"Retrieve",
"grepped",
"subjects",
"array"
] | train | https://github.com/madkom/regex/blob/798c1124805b130b1110ee6e8dcc9a88d8aaffa8/src/Grepper.php#L56-L79 |
wenbinye/PhalconX | src/Helper/ExportHelper.php | ExportHelper.loadFile | public static function loadFile($file, $format = null)
{
if (!isset($format)) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
$format = ArrayHelper::fetch(self::$FORMATS, $ext);
if (!isset($format)) {
throw new \InvalidArgumentException("Cannot infer format from file '{$file}'");
}
}
if ($format == 'json') {
return json_decode(file_get_contents($file), true);
} elseif ($format == 'yaml') {
return Yaml::parse(file_get_contents($file));
} elseif ($format == 'php') {
return require($file);
} else {
throw new \InvalidArgumentException("Invalid format '{$format}'");
}
} | php | public static function loadFile($file, $format = null)
{
if (!isset($format)) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
$format = ArrayHelper::fetch(self::$FORMATS, $ext);
if (!isset($format)) {
throw new \InvalidArgumentException("Cannot infer format from file '{$file}'");
}
}
if ($format == 'json') {
return json_decode(file_get_contents($file), true);
} elseif ($format == 'yaml') {
return Yaml::parse(file_get_contents($file));
} elseif ($format == 'php') {
return require($file);
} else {
throw new \InvalidArgumentException("Invalid format '{$format}'");
}
} | [
"public",
"static",
"function",
"loadFile",
"(",
"$",
"file",
",",
"$",
"format",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"format",
")",
")",
"{",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"format",
"=",
"ArrayHelper",
"::",
"fetch",
"(",
"self",
"::",
"$",
"FORMATS",
",",
"$",
"ext",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"format",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot infer format from file '{$file}'\"",
")",
";",
"}",
"}",
"if",
"(",
"$",
"format",
"==",
"'json'",
")",
"{",
"return",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"$",
"format",
"==",
"'yaml'",
")",
"{",
"return",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"format",
"==",
"'php'",
")",
"{",
"return",
"require",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid format '{$format}'\"",
")",
";",
"}",
"}"
] | 读取序列化文件
@param string $file
@param string $format 文件格式,如果未指定,使用文件后缀判断格式
@return array | [
"读取序列化文件"
] | train | https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ExportHelper.php#L54-L72 |
andromeda-framework/doctrine | src/Doctrine/Console/Commands/SchemaDropCommand.php | SchemaDropCommand.executeSchemaCommand | protected function executeSchemaCommand(InputInterface $input, OutputInterface $output,
SchemaTool $schemaTool, array $metadata, SymfonyStyle $ui)
{
$merger = new MetadataMerger();
$metadata = $merger->merge($metadata);
return parent::executeSchemaCommand($input, $output, $schemaTool, $metadata, $ui);
} | php | protected function executeSchemaCommand(InputInterface $input, OutputInterface $output,
SchemaTool $schemaTool, array $metadata, SymfonyStyle $ui)
{
$merger = new MetadataMerger();
$metadata = $merger->merge($metadata);
return parent::executeSchemaCommand($input, $output, $schemaTool, $metadata, $ui);
} | [
"protected",
"function",
"executeSchemaCommand",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"SchemaTool",
"$",
"schemaTool",
",",
"array",
"$",
"metadata",
",",
"SymfonyStyle",
"$",
"ui",
")",
"{",
"$",
"merger",
"=",
"new",
"MetadataMerger",
"(",
")",
";",
"$",
"metadata",
"=",
"$",
"merger",
"->",
"merge",
"(",
"$",
"metadata",
")",
";",
"return",
"parent",
"::",
"executeSchemaCommand",
"(",
"$",
"input",
",",
"$",
"output",
",",
"$",
"schemaTool",
",",
"$",
"metadata",
",",
"$",
"ui",
")",
";",
"}"
] | Executes the Drop command.
@param InputInterface $input
@param OutputInterface $output
@param SchemaTool $schemaTool
@param ClassMetadata[] $metadata
@param SymfonyStyle $ui
@return int|NULL 0 or NULL if everything went fine, or an error code | [
"Executes",
"the",
"Drop",
"command",
"."
] | train | https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Console/Commands/SchemaDropCommand.php#L49-L56 |
jaxon-php/jaxon-jquery | src/SelectorTrait.php | SelectorTrait.jQuery | public function jQuery(string $sSelector, string $sContext = '')
{
return $this->getResponse()->plugin('jquery')->element($sSelector, $sContext);
} | php | public function jQuery(string $sSelector, string $sContext = '')
{
return $this->getResponse()->plugin('jquery')->element($sSelector, $sContext);
} | [
"public",
"function",
"jQuery",
"(",
"string",
"$",
"sSelector",
",",
"string",
"$",
"sContext",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"plugin",
"(",
"'jquery'",
")",
"->",
"element",
"(",
"$",
"sSelector",
",",
"$",
"sContext",
")",
";",
"}"
] | Create a JQuery Element with a given selector, and link it to the response attribute.
@param string $sSelector The jQuery selector
@param string $sContext A context associated to the selector
@return Jaxon\JQuery\Dom\Element | [
"Create",
"a",
"JQuery",
"Element",
"with",
"a",
"given",
"selector",
"and",
"link",
"it",
"to",
"the",
"response",
"attribute",
"."
] | train | https://github.com/jaxon-php/jaxon-jquery/blob/90766a8ea8a4124a3f110e96b316370f71762380/src/SelectorTrait.php#L22-L25 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.debug_encode | public function debug_encode($string,$options=0,$depth=512){
if ($options==0){
json_encode($string,JSON_UNESCAPED_UNICODE);
} else {
json_encode($string,$options,$depth);
}
$data = $this->errorMessage(json_last_error(),$string);
return json_encode($data,JSON_PRETTY_PRINT);
} | php | public function debug_encode($string,$options=0,$depth=512){
if ($options==0){
json_encode($string,JSON_UNESCAPED_UNICODE);
} else {
json_encode($string,$options,$depth);
}
$data = $this->errorMessage(json_last_error(),$string);
return json_encode($data,JSON_PRETTY_PRINT);
} | [
"public",
"function",
"debug_encode",
"(",
"$",
"string",
",",
"$",
"options",
"=",
"0",
",",
"$",
"depth",
"=",
"512",
")",
"{",
"if",
"(",
"$",
"options",
"==",
"0",
")",
"{",
"json_encode",
"(",
"$",
"string",
",",
"JSON_UNESCAPED_UNICODE",
")",
";",
"}",
"else",
"{",
"json_encode",
"(",
"$",
"string",
",",
"$",
"options",
",",
"$",
"depth",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"errorMessage",
"(",
"json_last_error",
"(",
")",
",",
"$",
"string",
")",
";",
"return",
"json_encode",
"(",
"$",
"data",
",",
"JSON_PRETTY_PRINT",
")",
";",
"}"
] | Debugger to test json encode
Note:
- Actualy this is hard to test json_encode in php way, you have to encode the string to another utf8 chars by yourself.
- This is because if you do in php, json_encode function will auto giving backslash in your string if it contains invalid chars.
- You have to create regex to convert char to invalid utf-8 for test in array
@param string is the array or string value
@return json string | [
"Debugger",
"to",
"test",
"json",
"encode",
"Note",
":",
"-",
"Actualy",
"this",
"is",
"hard",
"to",
"test",
"json_encode",
"in",
"php",
"way",
"you",
"have",
"to",
"encode",
"the",
"string",
"to",
"another",
"utf8",
"chars",
"by",
"yourself",
".",
"-",
"This",
"is",
"because",
"if",
"you",
"do",
"in",
"php",
"json_encode",
"function",
"will",
"auto",
"giving",
"backslash",
"in",
"your",
"string",
"if",
"it",
"contains",
"invalid",
"chars",
".",
"-",
"You",
"have",
"to",
"create",
"regex",
"to",
"convert",
"char",
"to",
"invalid",
"utf",
"-",
"8",
"for",
"test",
"in",
"array"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L25-L33 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.debug_decode | public function debug_decode($json,$assoc=false,$depth=512,$options=0){
$test = json_decode($json,$assoc,$depth,$options);
if (!empty($test)) $json = $test;
$data = $this->errorMessage(json_last_error(),$json);
return json_encode($data,JSON_PRETTY_PRINT);
} | php | public function debug_decode($json,$assoc=false,$depth=512,$options=0){
$test = json_decode($json,$assoc,$depth,$options);
if (!empty($test)) $json = $test;
$data = $this->errorMessage(json_last_error(),$json);
return json_encode($data,JSON_PRETTY_PRINT);
} | [
"public",
"function",
"debug_decode",
"(",
"$",
"json",
",",
"$",
"assoc",
"=",
"false",
",",
"$",
"depth",
"=",
"512",
",",
"$",
"options",
"=",
"0",
")",
"{",
"$",
"test",
"=",
"json_decode",
"(",
"$",
"json",
",",
"$",
"assoc",
",",
"$",
"depth",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"test",
")",
")",
"$",
"json",
"=",
"$",
"test",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"errorMessage",
"(",
"json_last_error",
"(",
")",
",",
"$",
"json",
")",
";",
"return",
"json_encode",
"(",
"$",
"data",
",",
"JSON_PRETTY_PRINT",
")",
";",
"}"
] | Debugger to test json decode
@param json is the json string
@return json string | [
"Debugger",
"to",
"test",
"json",
"decode"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L42-L47 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.errorMessage | public function errorMessage($jsonlasterror,$content){
$data = array();
switch ($jsonlasterror) {
case JSON_ERROR_NONE:
$msg = 'no errors found';
if($this->makesimple){
$data = ['status' => 'success','case' => 'json_error_none','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'success','case' => 'json_error_none','message' => $msg];
}
break;
case JSON_ERROR_DEPTH:
$msg = 'maximum stack depth exceeded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_depth','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_depth','message' => $msg];
}
break;
case JSON_ERROR_STATE_MISMATCH:
$msg = 'underflow or the modes mismatch';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_state_mismatch','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_state_mismatch','message' => $msg];
}
break;
case JSON_ERROR_CTRL_CHAR:
$msg = 'unexpected control character found';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_ctrl_char','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_ctrl_char','message' => $msg];
}
break;
case JSON_ERROR_SYNTAX:
$msg = 'syntax error, malformed json';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_syntax','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_syntax','message' => $msg];
}
break;
case JSON_ERROR_UTF8:
$msg = 'malformed UTF-8 characters, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_utf8','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_utf8','message' => $msg];
}
break;
case JSON_ERROR_RECURSION:
$msg = 'malformed one or more recursive references, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_recursion','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_recursion','message' => $msg];
}
break;
case JSON_ERROR_INF_OR_NAN:
$msg = 'malformed NAN or INF, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_inf_or_nan','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_inf_or_nan','message' => $msg];
}
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$msg = 'a value of a type that cannot be encoded was given';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_unsupported_type','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_unsupported_type','message' => $msg];
}
break;
case JSON_ERROR_INVALID_PROPERTY_NAME:
$msg = 'a property name that cannot be encoded was given';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_invalid_property_name','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_invalid_property_name','message' => $msg];
}
break;
case JSON_ERROR_UTF16:
$msg = 'malformed UTF-16 characters, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_utf16','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_utf16','message' => $msg];
}
break;
default:
$msg = 'unknown error';
if($this->makesimple){
$data = ['status' => 'error','case' => 'unknown','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'unknown','message' => $msg];
}
break;
}
return $data;
} | php | public function errorMessage($jsonlasterror,$content){
$data = array();
switch ($jsonlasterror) {
case JSON_ERROR_NONE:
$msg = 'no errors found';
if($this->makesimple){
$data = ['status' => 'success','case' => 'json_error_none','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'success','case' => 'json_error_none','message' => $msg];
}
break;
case JSON_ERROR_DEPTH:
$msg = 'maximum stack depth exceeded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_depth','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_depth','message' => $msg];
}
break;
case JSON_ERROR_STATE_MISMATCH:
$msg = 'underflow or the modes mismatch';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_state_mismatch','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_state_mismatch','message' => $msg];
}
break;
case JSON_ERROR_CTRL_CHAR:
$msg = 'unexpected control character found';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_ctrl_char','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_ctrl_char','message' => $msg];
}
break;
case JSON_ERROR_SYNTAX:
$msg = 'syntax error, malformed json';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_syntax','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_syntax','message' => $msg];
}
break;
case JSON_ERROR_UTF8:
$msg = 'malformed UTF-8 characters, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_utf8','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_utf8','message' => $msg];
}
break;
case JSON_ERROR_RECURSION:
$msg = 'malformed one or more recursive references, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_recursion','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_recursion','message' => $msg];
}
break;
case JSON_ERROR_INF_OR_NAN:
$msg = 'malformed NAN or INF, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_inf_or_nan','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_inf_or_nan','message' => $msg];
}
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$msg = 'a value of a type that cannot be encoded was given';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_unsupported_type','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_unsupported_type','message' => $msg];
}
break;
case JSON_ERROR_INVALID_PROPERTY_NAME:
$msg = 'a property name that cannot be encoded was given';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_invalid_property_name','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_invalid_property_name','message' => $msg];
}
break;
case JSON_ERROR_UTF16:
$msg = 'malformed UTF-16 characters, possibly incorrectly encoded';
if($this->makesimple){
$data = ['status' => 'error','case' => 'json_error_utf16','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'json_error_utf16','message' => $msg];
}
break;
default:
$msg = 'unknown error';
if($this->makesimple){
$data = ['status' => 'error','case' => 'unknown','message' => $msg];
} else {
$data = ['data'=> $content,'status' => 'error','case' => 'unknown','message' => $msg];
}
break;
}
return $data;
} | [
"public",
"function",
"errorMessage",
"(",
"$",
"jsonlasterror",
",",
"$",
"content",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"switch",
"(",
"$",
"jsonlasterror",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"$",
"msg",
"=",
"'no errors found'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'success'",
",",
"'case'",
"=>",
"'json_error_none'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'success'",
",",
"'case'",
"=>",
"'json_error_none'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"$",
"msg",
"=",
"'maximum stack depth exceeded'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_depth'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_depth'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_STATE_MISMATCH",
":",
"$",
"msg",
"=",
"'underflow or the modes mismatch'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_state_mismatch'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_state_mismatch'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"$",
"msg",
"=",
"'unexpected control character found'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_ctrl_char'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_ctrl_char'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"$",
"msg",
"=",
"'syntax error, malformed json'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_syntax'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_syntax'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_UTF8",
":",
"$",
"msg",
"=",
"'malformed UTF-8 characters, possibly incorrectly encoded'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_utf8'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_utf8'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_RECURSION",
":",
"$",
"msg",
"=",
"'malformed one or more recursive references, possibly incorrectly encoded'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_recursion'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_recursion'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_INF_OR_NAN",
":",
"$",
"msg",
"=",
"'malformed NAN or INF, possibly incorrectly encoded'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_inf_or_nan'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_inf_or_nan'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_UNSUPPORTED_TYPE",
":",
"$",
"msg",
"=",
"'a value of a type that cannot be encoded was given'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_unsupported_type'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_unsupported_type'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_INVALID_PROPERTY_NAME",
":",
"$",
"msg",
"=",
"'a property name that cannot be encoded was given'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_invalid_property_name'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_invalid_property_name'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"case",
"JSON_ERROR_UTF16",
":",
"$",
"msg",
"=",
"'malformed UTF-16 characters, possibly incorrectly encoded'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_utf16'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'json_error_utf16'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"default",
":",
"$",
"msg",
"=",
"'unknown error'",
";",
"if",
"(",
"$",
"this",
"->",
"makesimple",
")",
"{",
"$",
"data",
"=",
"[",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'unknown'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"'data'",
"=>",
"$",
"content",
",",
"'status'",
"=>",
"'error'",
",",
"'case'",
"=>",
"'unknown'",
",",
"'message'",
"=>",
"$",
"msg",
"]",
";",
"}",
"break",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Case error message about json
@param jsonlasterror is the json_last_error() function
@param content is the additional data about error in json
@return array | [
"Case",
"error",
"message",
"about",
"json"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L57-L158 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.trimValue | public function trimValue($string){
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->trimValue($v);
}
} else if (is_string ($string)) {
return trim($string);
}
return $string;
} | php | public function trimValue($string){
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->trimValue($v);
}
} else if (is_string ($string)) {
return trim($string);
}
return $string;
} | [
"public",
"function",
"trimValue",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"foreach",
"(",
"$",
"string",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"string",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"trimValue",
"(",
"$",
"v",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"return",
"trim",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Trim to strip the whitespace (or other characters) from the beginning and end of a string
@param string is the array string or value
@return string | [
"Trim",
"to",
"strip",
"the",
"whitespace",
"(",
"or",
"other",
"characters",
")",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L167-L176 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.convertToUTF8 | public function convertToUTF8($string){
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->convertToUTF8($v);
}
} else if (is_string ($string)) {
return utf8_encode($string);
}
return $string;
} | php | public function convertToUTF8($string){
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->convertToUTF8($v);
}
} else if (is_string ($string)) {
return utf8_encode($string);
}
return $string;
} | [
"public",
"function",
"convertToUTF8",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"foreach",
"(",
"$",
"string",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"string",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"convertToUTF8",
"(",
"$",
"v",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"return",
"utf8_encode",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Convert string to valid UTF8 chars (Faster but not support for ANSII)
@param string is the array string or value
@return string | [
"Convert",
"string",
"to",
"valid",
"UTF8",
"chars",
"(",
"Faster",
"but",
"not",
"support",
"for",
"ANSII",
")"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L185-L194 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.convertToUTF8Ansii | public function convertToUTF8Ansii($string){
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->convertToUTF8Ansii($v);
}
} else if (is_string ($string)) {
return mb_convert_encoding($string, "UTF-8", "Windows-1252");
}
return $string;
} | php | public function convertToUTF8Ansii($string){
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->convertToUTF8Ansii($v);
}
} else if (is_string ($string)) {
return mb_convert_encoding($string, "UTF-8", "Windows-1252");
}
return $string;
} | [
"public",
"function",
"convertToUTF8Ansii",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"foreach",
"(",
"$",
"string",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"string",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"convertToUTF8Ansii",
"(",
"$",
"v",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"return",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"\"UTF-8\"",
",",
"\"Windows-1252\"",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Convert string to valid UTF8 chars (slower but support ANSII)
@param string is the array string or value
@return string | [
"Convert",
"string",
"to",
"valid",
"UTF8",
"chars",
"(",
"slower",
"but",
"support",
"ANSII",
")"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L203-L212 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.fixControlChar | public function fixControlChar($string){
//Sanitize hidden control chars
for ($i = 0; $i <= 9; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 11; $i <= 12; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 14; $i <= 31; ++$i) {
$string = str_replace(chr($i), "", $string);
}
$string = str_replace(chr(127), "", $string);
//Handle Byte Order Mark (BOM)
if (0 === strpos(bin2hex($string), 'efbbbf')) {
$string = substr($string, 3);
}
//Handle newline char
$string = preg_replace("/[\r\n]+/", "\\n", $string);
return $string;
} | php | public function fixControlChar($string){
//Sanitize hidden control chars
for ($i = 0; $i <= 9; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 11; $i <= 12; ++$i) {
$string = str_replace(chr($i), "", $string);
}
for ($i = 14; $i <= 31; ++$i) {
$string = str_replace(chr($i), "", $string);
}
$string = str_replace(chr(127), "", $string);
//Handle Byte Order Mark (BOM)
if (0 === strpos(bin2hex($string), 'efbbbf')) {
$string = substr($string, 3);
}
//Handle newline char
$string = preg_replace("/[\r\n]+/", "\\n", $string);
return $string;
} | [
"public",
"function",
"fixControlChar",
"(",
"$",
"string",
")",
"{",
"//Sanitize hidden control chars",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"9",
";",
"++",
"$",
"i",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"$",
"i",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"11",
";",
"$",
"i",
"<=",
"12",
";",
"++",
"$",
"i",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"$",
"i",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"14",
";",
"$",
"i",
"<=",
"31",
";",
"++",
"$",
"i",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"$",
"i",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"chr",
"(",
"127",
")",
",",
"\"\"",
",",
"$",
"string",
")",
";",
"//Handle Byte Order Mark (BOM)",
"if",
"(",
"0",
"===",
"strpos",
"(",
"bin2hex",
"(",
"$",
"string",
")",
",",
"'efbbbf'",
")",
")",
"{",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"3",
")",
";",
"}",
"//Handle newline char",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/[\\r\\n]+/\"",
",",
"\"\\\\n\"",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Most common fixed hidden control char in json string which made json decode fails.
@param string is the string or json string
@return string | [
"Most",
"common",
"fixed",
"hidden",
"control",
"char",
"in",
"json",
"string",
"which",
"made",
"json",
"decode",
"fails",
"."
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L220-L239 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.modifyJsonStringInArray | public function modifyJsonStringInArray($data,$jsonfield,$setnewfield=""){
if (is_array($data)){
if (count($data) == count($data, COUNT_RECURSIVE)) {
foreach($data as $value){
if(!empty($setnewfield)){
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
$data[$setnewfield[$i]] = json_decode($data[$jsonfield[$i]]);
}
}
} else {
if (isset($data[$jsonfield])){
$data[$setnewfield] = json_decode($data[$jsonfield]);
}
}
} else {
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
if (is_string($data[$jsonfield[$i]])) {
$decode = json_decode($data[$jsonfield[$i]]);
if (!empty($decode)) $data[$jsonfield[$i]] = $decode;
}
}
}
} else {
if (isset($data[$jsonfield])){
$decode = json_decode($data[$jsonfield]);
if (!empty($decode)) $data[$jsonfield] = $decode;
}
}
}
}
} else {
foreach($data as $key => $value){
$data[$key] = $this->modifyJsonStringInArray($data[$key],$jsonfield,$setnewfield);
}
}
}
return $data;
} | php | public function modifyJsonStringInArray($data,$jsonfield,$setnewfield=""){
if (is_array($data)){
if (count($data) == count($data, COUNT_RECURSIVE)) {
foreach($data as $value){
if(!empty($setnewfield)){
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
$data[$setnewfield[$i]] = json_decode($data[$jsonfield[$i]]);
}
}
} else {
if (isset($data[$jsonfield])){
$data[$setnewfield] = json_decode($data[$jsonfield]);
}
}
} else {
if (is_array($jsonfield)){
for ($i=0;$i<count($jsonfield);$i++){
if (isset($data[$jsonfield[$i]])){
if (is_string($data[$jsonfield[$i]])) {
$decode = json_decode($data[$jsonfield[$i]]);
if (!empty($decode)) $data[$jsonfield[$i]] = $decode;
}
}
}
} else {
if (isset($data[$jsonfield])){
$decode = json_decode($data[$jsonfield]);
if (!empty($decode)) $data[$jsonfield] = $decode;
}
}
}
}
} else {
foreach($data as $key => $value){
$data[$key] = $this->modifyJsonStringInArray($data[$key],$jsonfield,$setnewfield);
}
}
}
return $data;
} | [
"public",
"function",
"modifyJsonStringInArray",
"(",
"$",
"data",
",",
"$",
"jsonfield",
",",
"$",
"setnewfield",
"=",
"\"\"",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"==",
"count",
"(",
"$",
"data",
",",
"COUNT_RECURSIVE",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"setnewfield",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"jsonfield",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"jsonfield",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"setnewfield",
"[",
"$",
"i",
"]",
"]",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"setnewfield",
"]",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"jsonfield",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"jsonfield",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"decode",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"decode",
")",
")",
"$",
"data",
"[",
"$",
"jsonfield",
"[",
"$",
"i",
"]",
"]",
"=",
"$",
"decode",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
")",
"{",
"$",
"decode",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"decode",
")",
")",
"$",
"data",
"[",
"$",
"jsonfield",
"]",
"=",
"$",
"decode",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"modifyJsonStringInArray",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"jsonfield",
",",
"$",
"setnewfield",
")",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Modify json data string in some field array to be nice json data structure
Note:
- When you put json into database, then you load it with using PDO:fetch() or PDO::fetchAll() it will be served as string inside some field array.
- So this function is make you easier to modify the json string to become nice json data structure automatically.
- This function is well tested at here >> https://3v4l.org/IWkjn
@param data is the data array
@param jsonfield is the field which is contains json string
@param setnewfield is to put the result of modified json string in new field
@return mixed array or string (if the $data is string then will return string) | [
"Modify",
"json",
"data",
"string",
"in",
"some",
"field",
"array",
"to",
"be",
"nice",
"json",
"data",
"structure"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L254-L295 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.concatenate | public function concatenate($data,$escape=true,$options=0,$depth=512){
if(!empty($data)){
if(is_array($data)){
if($escape) return addcslashes(json_encode($data,$options,$depth),"\"'\n");
return json_encode($data,$options,$depth);
}
if($escape) return addcslashes($data,"\"'\n");
return $data;
}
if($escape) return '';
return '""';
} | php | public function concatenate($data,$escape=true,$options=0,$depth=512){
if(!empty($data)){
if(is_array($data)){
if($escape) return addcslashes(json_encode($data,$options,$depth),"\"'\n");
return json_encode($data,$options,$depth);
}
if($escape) return addcslashes($data,"\"'\n");
return $data;
}
if($escape) return '';
return '""';
} | [
"public",
"function",
"concatenate",
"(",
"$",
"data",
",",
"$",
"escape",
"=",
"true",
",",
"$",
"options",
"=",
"0",
",",
"$",
"depth",
"=",
"512",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"$",
"escape",
")",
"return",
"addcslashes",
"(",
"json_encode",
"(",
"$",
"data",
",",
"$",
"options",
",",
"$",
"depth",
")",
",",
"\"\\\"'\\n\"",
")",
";",
"return",
"json_encode",
"(",
"$",
"data",
",",
"$",
"options",
",",
"$",
"depth",
")",
";",
"}",
"if",
"(",
"$",
"escape",
")",
"return",
"addcslashes",
"(",
"$",
"data",
",",
"\"\\\"'\\n\"",
")",
";",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"$",
"escape",
")",
"return",
"''",
";",
"return",
"'\"\"'",
";",
"}"
] | Concatenate json data
Example: https://3v4l.org/fXjhd
@param data is the json string or array value
@param escape if set to false then json data will not escaped. Default is true.
@param options is to set the options of json_encode (for data array only). Ex: JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE
@param depth is to set the recursion depth. Default is 512.
@return string | [
"Concatenate",
"json",
"data",
"Example",
":",
"https",
":",
"//",
"3v4l",
".",
"org",
"/",
"fXjhd"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L307-L318 |
aalfiann/json-class-php | src/JSONHelper.php | JSONHelper.minify | public function minify($json){
$tokenizer = "/\"|(\/\*)|(\*\/)|(\/\/)|\n|\r/";
$in_string = false;
$in_multiline_comment = false;
$in_singleline_comment = false;
$tmp; $tmp2; $new_str = array(); $ns = 0; $from = 0; $lc; $rc; $lastIndex = 0;
while (preg_match($tokenizer,$json,$tmp,PREG_OFFSET_CAPTURE,$lastIndex)){
$tmp = $tmp[0];
$lastIndex = $tmp[1] + strlen($tmp[0]);
$lc = substr($json,0,$lastIndex - strlen($tmp[0]));
$rc = substr($json,$lastIndex);
if (!$in_multiline_comment && !$in_singleline_comment){
$tmp2 = substr($lc,$from);
if (!$in_string){
$tmp2 = preg_replace("/(\n|\r|\s)*/","",$tmp2);
}
$new_str[] = $tmp2;
}
$from = $lastIndex;
if ($tmp[0] == "\"" && !$in_multiline_comment && !$in_singleline_comment){
preg_match("/(\\\\)*$/",$lc,$tmp2);
if (!$in_string || !$tmp2 || (strlen($tmp2[0]) % 2) == 0){ // start of string with ", or unescaped " character found to end string
$in_string = !$in_string;
}
$from--; // include " character in next catch
$rc = substr($json,$from);
} else if ($tmp[0] == "/*" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = true;
} else if ($tmp[0] == "*/" && !$in_string && $in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = false;
} else if ($tmp[0] == "//" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_singleline_comment = true;
} else if (($tmp[0] == "\n" || $tmp[0] == "\r") && !$in_string && !$in_multiline_comment && $in_singleline_comment){
$in_singleline_comment = false;
} else if (!$in_multiline_comment && !$in_singleline_comment && !(preg_match("/\n|\r|\s/",$tmp[0]))){
$new_str[] = $tmp[0];
}
}
$new_str[] = $rc;
return implode("",$new_str);
} | php | public function minify($json){
$tokenizer = "/\"|(\/\*)|(\*\/)|(\/\/)|\n|\r/";
$in_string = false;
$in_multiline_comment = false;
$in_singleline_comment = false;
$tmp; $tmp2; $new_str = array(); $ns = 0; $from = 0; $lc; $rc; $lastIndex = 0;
while (preg_match($tokenizer,$json,$tmp,PREG_OFFSET_CAPTURE,$lastIndex)){
$tmp = $tmp[0];
$lastIndex = $tmp[1] + strlen($tmp[0]);
$lc = substr($json,0,$lastIndex - strlen($tmp[0]));
$rc = substr($json,$lastIndex);
if (!$in_multiline_comment && !$in_singleline_comment){
$tmp2 = substr($lc,$from);
if (!$in_string){
$tmp2 = preg_replace("/(\n|\r|\s)*/","",$tmp2);
}
$new_str[] = $tmp2;
}
$from = $lastIndex;
if ($tmp[0] == "\"" && !$in_multiline_comment && !$in_singleline_comment){
preg_match("/(\\\\)*$/",$lc,$tmp2);
if (!$in_string || !$tmp2 || (strlen($tmp2[0]) % 2) == 0){ // start of string with ", or unescaped " character found to end string
$in_string = !$in_string;
}
$from--; // include " character in next catch
$rc = substr($json,$from);
} else if ($tmp[0] == "/*" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = true;
} else if ($tmp[0] == "*/" && !$in_string && $in_multiline_comment && !$in_singleline_comment){
$in_multiline_comment = false;
} else if ($tmp[0] == "//" && !$in_string && !$in_multiline_comment && !$in_singleline_comment){
$in_singleline_comment = true;
} else if (($tmp[0] == "\n" || $tmp[0] == "\r") && !$in_string && !$in_multiline_comment && $in_singleline_comment){
$in_singleline_comment = false;
} else if (!$in_multiline_comment && !$in_singleline_comment && !(preg_match("/\n|\r|\s/",$tmp[0]))){
$new_str[] = $tmp[0];
}
}
$new_str[] = $rc;
return implode("",$new_str);
} | [
"public",
"function",
"minify",
"(",
"$",
"json",
")",
"{",
"$",
"tokenizer",
"=",
"\"/\\\"|(\\/\\*)|(\\*\\/)|(\\/\\/)|\\n|\\r/\"",
";",
"$",
"in_string",
"=",
"false",
";",
"$",
"in_multiline_comment",
"=",
"false",
";",
"$",
"in_singleline_comment",
"=",
"false",
";",
"$",
"tmp",
";",
"$",
"tmp2",
";",
"$",
"new_str",
"=",
"array",
"(",
")",
";",
"$",
"ns",
"=",
"0",
";",
"$",
"from",
"=",
"0",
";",
"$",
"lc",
";",
"$",
"rc",
";",
"$",
"lastIndex",
"=",
"0",
";",
"while",
"(",
"preg_match",
"(",
"$",
"tokenizer",
",",
"$",
"json",
",",
"$",
"tmp",
",",
"PREG_OFFSET_CAPTURE",
",",
"$",
"lastIndex",
")",
")",
"{",
"$",
"tmp",
"=",
"$",
"tmp",
"[",
"0",
"]",
";",
"$",
"lastIndex",
"=",
"$",
"tmp",
"[",
"1",
"]",
"+",
"strlen",
"(",
"$",
"tmp",
"[",
"0",
"]",
")",
";",
"$",
"lc",
"=",
"substr",
"(",
"$",
"json",
",",
"0",
",",
"$",
"lastIndex",
"-",
"strlen",
"(",
"$",
"tmp",
"[",
"0",
"]",
")",
")",
";",
"$",
"rc",
"=",
"substr",
"(",
"$",
"json",
",",
"$",
"lastIndex",
")",
";",
"if",
"(",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"tmp2",
"=",
"substr",
"(",
"$",
"lc",
",",
"$",
"from",
")",
";",
"if",
"(",
"!",
"$",
"in_string",
")",
"{",
"$",
"tmp2",
"=",
"preg_replace",
"(",
"\"/(\\n|\\r|\\s)*/\"",
",",
"\"\"",
",",
"$",
"tmp2",
")",
";",
"}",
"$",
"new_str",
"[",
"]",
"=",
"$",
"tmp2",
";",
"}",
"$",
"from",
"=",
"$",
"lastIndex",
";",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"\\\"\"",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"preg_match",
"(",
"\"/(\\\\\\\\)*$/\"",
",",
"$",
"lc",
",",
"$",
"tmp2",
")",
";",
"if",
"(",
"!",
"$",
"in_string",
"||",
"!",
"$",
"tmp2",
"||",
"(",
"strlen",
"(",
"$",
"tmp2",
"[",
"0",
"]",
")",
"%",
"2",
")",
"==",
"0",
")",
"{",
"// start of string with \", or unescaped \" character found to end string",
"$",
"in_string",
"=",
"!",
"$",
"in_string",
";",
"}",
"$",
"from",
"--",
";",
"// include \" character in next catch",
"$",
"rc",
"=",
"substr",
"(",
"$",
"json",
",",
"$",
"from",
")",
";",
"}",
"else",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"/*\"",
"&&",
"!",
"$",
"in_string",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_multiline_comment",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"*/\"",
"&&",
"!",
"$",
"in_string",
"&&",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_multiline_comment",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"//\"",
"&&",
"!",
"$",
"in_string",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_singleline_comment",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"(",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"\\n\"",
"||",
"$",
"tmp",
"[",
"0",
"]",
"==",
"\"\\r\"",
")",
"&&",
"!",
"$",
"in_string",
"&&",
"!",
"$",
"in_multiline_comment",
"&&",
"$",
"in_singleline_comment",
")",
"{",
"$",
"in_singleline_comment",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"in_multiline_comment",
"&&",
"!",
"$",
"in_singleline_comment",
"&&",
"!",
"(",
"preg_match",
"(",
"\"/\\n|\\r|\\s/\"",
",",
"$",
"tmp",
"[",
"0",
"]",
")",
")",
")",
"{",
"$",
"new_str",
"[",
"]",
"=",
"$",
"tmp",
"[",
"0",
"]",
";",
"}",
"}",
"$",
"new_str",
"[",
"]",
"=",
"$",
"rc",
";",
"return",
"implode",
"(",
"\"\"",
",",
"$",
"new_str",
")",
";",
"}"
] | Minify the json string
@param json is the json string
@return string | [
"Minify",
"the",
"json",
"string"
] | train | https://github.com/aalfiann/json-class-php/blob/524be94b162031946137ea1b729ba390d83dc41e/src/JSONHelper.php#L326-L366 |
pvsaintpe/yii2-grid | widgets/GridView.php | GridView.renderPageSummary | public function renderPageSummary()
{
$content = parent::renderPageSummary();
if ($this->showCustomPageSummary) {
if (!$content) {
$content = "<tfoot></tfoot>";
}
if ($this->beforeSummary) {
foreach ($this->beforeSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
if ($this->afterSummary) {
foreach ($this->afterSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
return strtr(
$content,
[
'<tfoot>' => "<tfoot>\n" . parent::generateRows($this->beforeSummary),
'</tfoot>' => parent::generateRows($this->afterSummary) . "\n</tfoot>",
]
);
}
return $content;
} | php | public function renderPageSummary()
{
$content = parent::renderPageSummary();
if ($this->showCustomPageSummary) {
if (!$content) {
$content = "<tfoot></tfoot>";
}
if ($this->beforeSummary) {
foreach ($this->beforeSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
if ($this->afterSummary) {
foreach ($this->afterSummary as &$row) {
if (!isset($row['options'])) {
$row['options'] = $this->pageSummaryRowOptions;
}
}
}
return strtr(
$content,
[
'<tfoot>' => "<tfoot>\n" . parent::generateRows($this->beforeSummary),
'</tfoot>' => parent::generateRows($this->afterSummary) . "\n</tfoot>",
]
);
}
return $content;
} | [
"public",
"function",
"renderPageSummary",
"(",
")",
"{",
"$",
"content",
"=",
"parent",
"::",
"renderPageSummary",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"showCustomPageSummary",
")",
"{",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"\"<tfoot></tfoot>\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"beforeSummary",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"beforeSummary",
"as",
"&",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"row",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"pageSummaryRowOptions",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"afterSummary",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"afterSummary",
"as",
"&",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"row",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"pageSummaryRowOptions",
";",
"}",
"}",
"}",
"return",
"strtr",
"(",
"$",
"content",
",",
"[",
"'<tfoot>'",
"=>",
"\"<tfoot>\\n\"",
".",
"parent",
"::",
"generateRows",
"(",
"$",
"this",
"->",
"beforeSummary",
")",
",",
"'</tfoot>'",
"=>",
"parent",
"::",
"generateRows",
"(",
"$",
"this",
"->",
"afterSummary",
")",
".",
"\"\\n</tfoot>\"",
",",
"]",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Custom renders the table page summary.
@return string the rendering result.
@throws \yii\base\InvalidConfigException | [
"Custom",
"renders",
"the",
"table",
"page",
"summary",
"."
] | train | https://github.com/pvsaintpe/yii2-grid/blob/8c91a1737412070775dc3fbee6a89384a67ca2cf/widgets/GridView.php#L151-L186 |
tttptd/laravel-responder | src/Responder.php | Responder.error | public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
{
if ($exception = config("responder.exceptions.$errorCode")) {
if (class_exists($exception)) {
throw new $exception();
}
}
return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
} | php | public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
{
if ($exception = config("responder.exceptions.$errorCode")) {
if (class_exists($exception)) {
throw new $exception();
}
}
return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
} | [
"public",
"function",
"error",
"(",
"$",
"errorCode",
"=",
"null",
",",
"int",
"$",
"statusCode",
"=",
"null",
",",
"$",
"message",
"=",
"null",
")",
":",
"JsonResponse",
"{",
"if",
"(",
"$",
"exception",
"=",
"config",
"(",
"\"responder.exceptions.$errorCode\"",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"exception",
")",
")",
"{",
"throw",
"new",
"$",
"exception",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"errorResponse",
"->",
"setError",
"(",
"$",
"errorCode",
",",
"$",
"message",
")",
"->",
"respond",
"(",
"$",
"statusCode",
")",
";",
"}"
] | Generate an error JSON response.
@param mixed|null $errorCode
@param int|null $statusCode
@param mixed $message
@return \Illuminate\Http\JsonResponse | [
"Generate",
"an",
"error",
"JSON",
"response",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Responder.php#L54-L63 |
tttptd/laravel-responder | src/Responder.php | Responder.success | public function success($data = null, $statusCode = null, array $meta = []):JsonResponse
{
if (is_integer($data)) {
list($data, $statusCode, $meta) = [null, $data, is_array($statusCode) ? $statusCode : []];
}
if (is_array($statusCode)) {
list($statusCode, $meta) = [200, $statusCode];
}
return $this->successResponse->transform($data)->addMeta($meta)->respond($statusCode);
} | php | public function success($data = null, $statusCode = null, array $meta = []):JsonResponse
{
if (is_integer($data)) {
list($data, $statusCode, $meta) = [null, $data, is_array($statusCode) ? $statusCode : []];
}
if (is_array($statusCode)) {
list($statusCode, $meta) = [200, $statusCode];
}
return $this->successResponse->transform($data)->addMeta($meta)->respond($statusCode);
} | [
"public",
"function",
"success",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"statusCode",
"=",
"null",
",",
"array",
"$",
"meta",
"=",
"[",
"]",
")",
":",
"JsonResponse",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"data",
")",
")",
"{",
"list",
"(",
"$",
"data",
",",
"$",
"statusCode",
",",
"$",
"meta",
")",
"=",
"[",
"null",
",",
"$",
"data",
",",
"is_array",
"(",
"$",
"statusCode",
")",
"?",
"$",
"statusCode",
":",
"[",
"]",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"statusCode",
")",
")",
"{",
"list",
"(",
"$",
"statusCode",
",",
"$",
"meta",
")",
"=",
"[",
"200",
",",
"$",
"statusCode",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"successResponse",
"->",
"transform",
"(",
"$",
"data",
")",
"->",
"addMeta",
"(",
"$",
"meta",
")",
"->",
"respond",
"(",
"$",
"statusCode",
")",
";",
"}"
] | Generate a successful JSON response.
@param mixed|null $data
@param int|null $statusCode
@param array $meta
@return \Illuminate\Http\JsonResponse | [
"Generate",
"a",
"successful",
"JSON",
"response",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Responder.php#L73-L84 |
tttptd/laravel-responder | src/Responder.php | Responder.transform | public function transform($data = null, $transformer = null):SuccessResponseBuilder
{
return $this->successResponse->transform($data, $transformer);
} | php | public function transform($data = null, $transformer = null):SuccessResponseBuilder
{
return $this->successResponse->transform($data, $transformer);
} | [
"public",
"function",
"transform",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"transformer",
"=",
"null",
")",
":",
"SuccessResponseBuilder",
"{",
"return",
"$",
"this",
"->",
"successResponse",
"->",
"transform",
"(",
"$",
"data",
",",
"$",
"transformer",
")",
";",
"}"
] | Transform the data and return a success response builder.
@param mixed|null $data
@param callable|string|null $transformer
@return \Flugg\Responder\Http\SuccessResponseBuilder | [
"Transform",
"the",
"data",
"and",
"return",
"a",
"success",
"response",
"builder",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Responder.php#L93-L96 |
nicolasbeauvais/botscout-client | src/BotScout.php | BotScout.multi | public function multi(string $name = null, string $mail = null, string $ip = null)
{
return $this->makeRequest('multi', compact('name', 'mail', 'ip'));
} | php | public function multi(string $name = null, string $mail = null, string $ip = null)
{
return $this->makeRequest('multi', compact('name', 'mail', 'ip'));
} | [
"public",
"function",
"multi",
"(",
"string",
"$",
"name",
"=",
"null",
",",
"string",
"$",
"mail",
"=",
"null",
",",
"string",
"$",
"ip",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"makeRequest",
"(",
"'multi'",
",",
"compact",
"(",
"'name'",
",",
"'mail'",
",",
"'ip'",
")",
")",
";",
"}"
] | Test matches all parameters at once.
@param string $name
@param string $mail
@param string $ip
@return BotScoutResponse | [
"Test",
"matches",
"all",
"parameters",
"at",
"once",
"."
] | train | https://github.com/nicolasbeauvais/botscout-client/blob/bcc3f607998f02d79fd150f1ffd719c414262e86/src/BotScout.php#L34-L37 |
nicolasbeauvais/botscout-client | src/BotScout.php | BotScout.makeRequest | public function makeRequest(string $type = null, array $query = [])
{
if ($type) {
$query[$type] = null;
}
$query['key'] = $this->apiKey;
return $this->decodeResponse($this->client
->get($this->baseUrl, compact('query'))
->getBody()
->getContents());
} | php | public function makeRequest(string $type = null, array $query = [])
{
if ($type) {
$query[$type] = null;
}
$query['key'] = $this->apiKey;
return $this->decodeResponse($this->client
->get($this->baseUrl, compact('query'))
->getBody()
->getContents());
} | [
"public",
"function",
"makeRequest",
"(",
"string",
"$",
"type",
"=",
"null",
",",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"type",
")",
"{",
"$",
"query",
"[",
"$",
"type",
"]",
"=",
"null",
";",
"}",
"$",
"query",
"[",
"'key'",
"]",
"=",
"$",
"this",
"->",
"apiKey",
";",
"return",
"$",
"this",
"->",
"decodeResponse",
"(",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"$",
"this",
"->",
"baseUrl",
",",
"compact",
"(",
"'query'",
")",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
")",
";",
"}"
] | @param array $query
@return BotScoutResponse | [
"@param",
"array",
"$query"
] | train | https://github.com/nicolasbeauvais/botscout-client/blob/bcc3f607998f02d79fd150f1ffd719c414262e86/src/BotScout.php#L92-L104 |
nicolasbeauvais/botscout-client | src/BotScout.php | BotScout.decodeResponse | private function decodeResponse(string $response)
{
if (strpos($response, '!') !== false) {
throw new \Exception($response);
}
return new BotScoutResponse($response);
} | php | private function decodeResponse(string $response)
{
if (strpos($response, '!') !== false) {
throw new \Exception($response);
}
return new BotScoutResponse($response);
} | [
"private",
"function",
"decodeResponse",
"(",
"string",
"$",
"response",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"response",
",",
"'!'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"response",
")",
";",
"}",
"return",
"new",
"BotScoutResponse",
"(",
"$",
"response",
")",
";",
"}"
] | @param string $response
@return BotScoutResponse | [
"@param",
"string",
"$response"
] | train | https://github.com/nicolasbeauvais/botscout-client/blob/bcc3f607998f02d79fd150f1ffd719c414262e86/src/BotScout.php#L111-L118 |
ekuiter/feature-php | FeaturePhp/File/LogFile.php | LogFile.getContent | public function getContent() {
$content = "";
$maxLen = 0;
foreach ($this->logs as $log)
if ($log[0]) {
$name = $log[0]->getFeature()->getName();
$maxLen = strlen($name) > $maxLen ? strlen($name) : $maxLen;
}
foreach ($this->logs as $log)
$content .= sprintf("%-{$maxLen}s | $log[1]\n", $log[0] ? $log[0]->getFeature()->getName() : "");
return new TextFileContent($content);
} | php | public function getContent() {
$content = "";
$maxLen = 0;
foreach ($this->logs as $log)
if ($log[0]) {
$name = $log[0]->getFeature()->getName();
$maxLen = strlen($name) > $maxLen ? strlen($name) : $maxLen;
}
foreach ($this->logs as $log)
$content .= sprintf("%-{$maxLen}s | $log[1]\n", $log[0] ? $log[0]->getFeature()->getName() : "");
return new TextFileContent($content);
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"$",
"content",
"=",
"\"\"",
";",
"$",
"maxLen",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"logs",
"as",
"$",
"log",
")",
"if",
"(",
"$",
"log",
"[",
"0",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"log",
"[",
"0",
"]",
"->",
"getFeature",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"maxLen",
"=",
"strlen",
"(",
"$",
"name",
")",
">",
"$",
"maxLen",
"?",
"strlen",
"(",
"$",
"name",
")",
":",
"$",
"maxLen",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"logs",
"as",
"$",
"log",
")",
"$",
"content",
".=",
"sprintf",
"(",
"\"%-{$maxLen}s | $log[1]\\n\"",
",",
"$",
"log",
"[",
"0",
"]",
"?",
"$",
"log",
"[",
"0",
"]",
"->",
"getFeature",
"(",
")",
"->",
"getName",
"(",
")",
":",
"\"\"",
")",
";",
"return",
"new",
"TextFileContent",
"(",
"$",
"content",
")",
";",
"}"
] | Returns the log file's content.
Tabular output is generated.
@return TextFileContent | [
"Returns",
"the",
"log",
"file",
"s",
"content",
".",
"Tabular",
"output",
"is",
"generated",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/LogFile.php#L44-L58 |
hametuha/wpametu | src/WPametu/Tool/BatchProcessor.php | BatchProcessor.render_screen | public function render_screen(){
$this->register_batches();
?>
<div class="wrap">
<h2><?php $this->_e('Do Batch Actions') ?></h2>
<?php if( $this->batches ): ?>
<form id="batch-form" method="post" action="<?= admin_url('admin-ajax.php') ?>">
<input type="hidden" name="action" value="wpametu_batch">
<?php wp_nonce_field('wpametu_batch') ?>
<input type="hidden" name="page_num" id="page_num" value="1" />
<ol class="batch-container">
<?php
$counter = 0;
foreach( $this->batches as $batch_class ):
$counter++;
/** @var Batch $batch */
$batch = $batch_class::get_instance();
$option = $this->option;
if( isset($option[$batch_class]) ){
$last = $option[$batch_class];
}else{
$last = false;
}
?>
<li>
<input type="radio" id="batch-<?= $counter ?>" name="batch_class" value="<?= esc_attr(get_class($batch)) ?>" />
<label for="batch-<?= $counter ?>">
<span class="dashicons dashicons-yes"></span>
<strong><?= esc_html($batch->title) ?></strong><small>ver <?= esc_html($batch->version) ?></small>
<span class="description"><?= nl2br(esc_html($batch->description)) ?></span>
<?php if( false === $last ): ?>
<span class="executed not-yet"><?php $this->_e('Never executed') ?></span>
<?php else: ?>
<span class="executed"><?= date_i18n(get_option('date_format').' '.get_option('time_format'), $last) ?></span>
<?php endif; ?>
</label>
</li>
<?php endforeach; ?>
</ol>
<?php submit_button($this->__('Execute')) ?>
<div class="loader">
<div><span class="dashicons dashicons-update"></span></div>
</div>
</form>
<div id="batch-result">
<h3><span class="dashicons dashicons-media-code"></span> <?php $this->_e('Console') ?></h3>
<div class="console">
</div>
</div>
<?php else: ?>
<div class="error"><p><?php $this->_e('There is no classes.') ?></p></div>
<?php endif; ?>
</div>
<?php
} | php | public function render_screen(){
$this->register_batches();
?>
<div class="wrap">
<h2><?php $this->_e('Do Batch Actions') ?></h2>
<?php if( $this->batches ): ?>
<form id="batch-form" method="post" action="<?= admin_url('admin-ajax.php') ?>">
<input type="hidden" name="action" value="wpametu_batch">
<?php wp_nonce_field('wpametu_batch') ?>
<input type="hidden" name="page_num" id="page_num" value="1" />
<ol class="batch-container">
<?php
$counter = 0;
foreach( $this->batches as $batch_class ):
$counter++;
/** @var Batch $batch */
$batch = $batch_class::get_instance();
$option = $this->option;
if( isset($option[$batch_class]) ){
$last = $option[$batch_class];
}else{
$last = false;
}
?>
<li>
<input type="radio" id="batch-<?= $counter ?>" name="batch_class" value="<?= esc_attr(get_class($batch)) ?>" />
<label for="batch-<?= $counter ?>">
<span class="dashicons dashicons-yes"></span>
<strong><?= esc_html($batch->title) ?></strong><small>ver <?= esc_html($batch->version) ?></small>
<span class="description"><?= nl2br(esc_html($batch->description)) ?></span>
<?php if( false === $last ): ?>
<span class="executed not-yet"><?php $this->_e('Never executed') ?></span>
<?php else: ?>
<span class="executed"><?= date_i18n(get_option('date_format').' '.get_option('time_format'), $last) ?></span>
<?php endif; ?>
</label>
</li>
<?php endforeach; ?>
</ol>
<?php submit_button($this->__('Execute')) ?>
<div class="loader">
<div><span class="dashicons dashicons-update"></span></div>
</div>
</form>
<div id="batch-result">
<h3><span class="dashicons dashicons-media-code"></span> <?php $this->_e('Console') ?></h3>
<div class="console">
</div>
</div>
<?php else: ?>
<div class="error"><p><?php $this->_e('There is no classes.') ?></p></div>
<?php endif; ?>
</div>
<?php
} | [
"public",
"function",
"render_screen",
"(",
")",
"{",
"$",
"this",
"->",
"register_batches",
"(",
")",
";",
"?>\n\t\t<div class=\"wrap\">\n\t\t\t<h2><?php",
"$",
"this",
"->",
"_e",
"(",
"'Do Batch Actions'",
")",
"?></h2>\n\t\t\t<?php",
"if",
"(",
"$",
"this",
"->",
"batches",
")",
":",
"?>\n\t\t\t<form id=\"batch-form\" method=\"post\" action=\"<?=",
"admin_url",
"(",
"'admin-ajax.php'",
")",
"?>\">\n\t\t\t\t<input type=\"hidden\" name=\"action\" value=\"wpametu_batch\">\n\t\t\t\t<?php",
"wp_nonce_field",
"(",
"'wpametu_batch'",
")",
"?>\n\t\t\t\t<input type=\"hidden\" name=\"page_num\" id=\"page_num\" value=\"1\" />\n\t\t\t\t<ol class=\"batch-container\">\n\t\t\t\t<?php",
"$",
"counter",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"batches",
"as",
"$",
"batch_class",
")",
":",
"$",
"counter",
"++",
";",
"/** @var Batch $batch */",
"$",
"batch",
"=",
"$",
"batch_class",
"::",
"get_instance",
"(",
")",
";",
"$",
"option",
"=",
"$",
"this",
"->",
"option",
";",
"if",
"(",
"isset",
"(",
"$",
"option",
"[",
"$",
"batch_class",
"]",
")",
")",
"{",
"$",
"last",
"=",
"$",
"option",
"[",
"$",
"batch_class",
"]",
";",
"}",
"else",
"{",
"$",
"last",
"=",
"false",
";",
"}",
"?>\n\t\t\t\t<li>\n\t\t\t\t\t<input type=\"radio\" id=\"batch-<?=",
"$",
"counter",
"?>\" name=\"batch_class\" value=\"<?=",
"esc_attr",
"(",
"get_class",
"(",
"$",
"batch",
")",
")",
"?>\" />\n\t\t\t\t\t<label for=\"batch-<?=",
"$",
"counter",
"?>\">\n\t\t\t\t\t\t<span class=\"dashicons dashicons-yes\"></span>\n\t\t\t\t\t\t<strong><?=",
"esc_html",
"(",
"$",
"batch",
"->",
"title",
")",
"?></strong><small>ver <?=",
"esc_html",
"(",
"$",
"batch",
"->",
"version",
")",
"?></small>\n\t\t\t\t\t\t<span class=\"description\"><?=",
"nl2br",
"(",
"esc_html",
"(",
"$",
"batch",
"->",
"description",
")",
")",
"?></span>\n\t\t\t\t\t\t<?php",
"if",
"(",
"false",
"===",
"$",
"last",
")",
":",
"?>\n\t\t\t\t\t\t\t<span class=\"executed not-yet\"><?php",
"$",
"this",
"->",
"_e",
"(",
"'Never executed'",
")",
"?></span>\n\t\t\t\t\t\t<?php",
"else",
":",
"?>\n\t\t\t\t\t\t\t<span class=\"executed\"><?=",
"date_i18n",
"(",
"get_option",
"(",
"'date_format'",
")",
".",
"' '",
".",
"get_option",
"(",
"'time_format'",
")",
",",
"$",
"last",
")",
"?></span>\n\t\t\t\t\t\t<?php",
"endif",
";",
"?>\n\t\t\t\t\t</label>\n\t\t\t\t</li>\n\t\t\t\t<?php",
"endforeach",
";",
"?>\n\t\t\t\t</ol>\n\t\t\t\t<?php",
"submit_button",
"(",
"$",
"this",
"->",
"__",
"(",
"'Execute'",
")",
")",
"?>\n\t\t\t\t<div class=\"loader\">\n\t\t\t\t\t<div><span class=\"dashicons dashicons-update\"></span></div>\n\t\t\t\t</div>\n\t\t\t</form>\n\t\t\t<div id=\"batch-result\">\n\t\t\t\t<h3><span class=\"dashicons dashicons-media-code\"></span> <?php",
"$",
"this",
"->",
"_e",
"(",
"'Console'",
")",
"?></h3>\n\t\t\t\t<div class=\"console\">\n\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t\t<?php",
"else",
":",
"?>\n\t\t\t<div class=\"error\"><p><?php",
"$",
"this",
"->",
"_e",
"(",
"'There is no classes.'",
")",
"?></p></div>\n\t\t\t<?php",
"endif",
";",
"?>\n\t\t</div>\n\t\t<?php",
"}"
] | Render Admin screen | [
"Render",
"Admin",
"screen"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Tool/BatchProcessor.php#L67-L122 |
hametuha/wpametu | src/WPametu/Tool/BatchProcessor.php | BatchProcessor.admin_enqueue_scripts | public function admin_enqueue_scripts($page){
if( 'tools_page_wpametu-batch' == $page ){
wp_enqueue_script('wpametu-batch-helper');
wp_localize_script('wpametu-batch-helper', 'WpametuBatch', [
'confirm' => $this->__('Are you sure to execute this?'),
'alert' => $this->__('No Batch is selected.'),
'done' => $this->__('[DONE] Batch process done.')
]);
wp_enqueue_style('wpametu-batch-screen');
}
} | php | public function admin_enqueue_scripts($page){
if( 'tools_page_wpametu-batch' == $page ){
wp_enqueue_script('wpametu-batch-helper');
wp_localize_script('wpametu-batch-helper', 'WpametuBatch', [
'confirm' => $this->__('Are you sure to execute this?'),
'alert' => $this->__('No Batch is selected.'),
'done' => $this->__('[DONE] Batch process done.')
]);
wp_enqueue_style('wpametu-batch-screen');
}
} | [
"public",
"function",
"admin_enqueue_scripts",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"'tools_page_wpametu-batch'",
"==",
"$",
"page",
")",
"{",
"wp_enqueue_script",
"(",
"'wpametu-batch-helper'",
")",
";",
"wp_localize_script",
"(",
"'wpametu-batch-helper'",
",",
"'WpametuBatch'",
",",
"[",
"'confirm'",
"=>",
"$",
"this",
"->",
"__",
"(",
"'Are you sure to execute this?'",
")",
",",
"'alert'",
"=>",
"$",
"this",
"->",
"__",
"(",
"'No Batch is selected.'",
")",
",",
"'done'",
"=>",
"$",
"this",
"->",
"__",
"(",
"'[DONE] Batch process done.'",
")",
"]",
")",
";",
"wp_enqueue_style",
"(",
"'wpametu-batch-screen'",
")",
";",
"}",
"}"
] | Enqueue script
@param string $page | [
"Enqueue",
"script"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Tool/BatchProcessor.php#L129-L139 |
hametuha/wpametu | src/WPametu/Tool/BatchProcessor.php | BatchProcessor.register_batches | protected function register_batches(){
static $batch_registered = false;
if( !$batch_registered ){
// Register Batches
/** @var AutoLoader $auto_loader */
$auto_loader = AutoLoader::get_instance();
$root = $auto_loader->namespace_root;
$namespace = $auto_loader->namespace;
if( $namespace && $root && is_dir($root.'/Batches') ){
// Scan directory and find batch children
foreach( scandir($root.'/Batches') as $file ){
if( preg_match('/\.php$/', $file) ){
$class_name = $namespace.'\\Batches\\'.str_replace('.php', '', $file);
if( class_exists($class_name) && $this->is_sub_class_of($class_name, Batch::class) ){
$this->batches[] = $class_name;
}
}
}
}
$batch_registered = true;
}
} | php | protected function register_batches(){
static $batch_registered = false;
if( !$batch_registered ){
// Register Batches
/** @var AutoLoader $auto_loader */
$auto_loader = AutoLoader::get_instance();
$root = $auto_loader->namespace_root;
$namespace = $auto_loader->namespace;
if( $namespace && $root && is_dir($root.'/Batches') ){
// Scan directory and find batch children
foreach( scandir($root.'/Batches') as $file ){
if( preg_match('/\.php$/', $file) ){
$class_name = $namespace.'\\Batches\\'.str_replace('.php', '', $file);
if( class_exists($class_name) && $this->is_sub_class_of($class_name, Batch::class) ){
$this->batches[] = $class_name;
}
}
}
}
$batch_registered = true;
}
} | [
"protected",
"function",
"register_batches",
"(",
")",
"{",
"static",
"$",
"batch_registered",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"batch_registered",
")",
"{",
"// Register Batches",
"/** @var AutoLoader $auto_loader */",
"$",
"auto_loader",
"=",
"AutoLoader",
"::",
"get_instance",
"(",
")",
";",
"$",
"root",
"=",
"$",
"auto_loader",
"->",
"namespace_root",
";",
"$",
"namespace",
"=",
"$",
"auto_loader",
"->",
"namespace",
";",
"if",
"(",
"$",
"namespace",
"&&",
"$",
"root",
"&&",
"is_dir",
"(",
"$",
"root",
".",
"'/Batches'",
")",
")",
"{",
"// Scan directory and find batch children",
"foreach",
"(",
"scandir",
"(",
"$",
"root",
".",
"'/Batches'",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\.php$/'",
",",
"$",
"file",
")",
")",
"{",
"$",
"class_name",
"=",
"$",
"namespace",
".",
"'\\\\Batches\\\\'",
".",
"str_replace",
"(",
"'.php'",
",",
"''",
",",
"$",
"file",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class_name",
")",
"&&",
"$",
"this",
"->",
"is_sub_class_of",
"(",
"$",
"class_name",
",",
"Batch",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"batches",
"[",
"]",
"=",
"$",
"class_name",
";",
"}",
"}",
"}",
"}",
"$",
"batch_registered",
"=",
"true",
";",
"}",
"}"
] | Register Batch classes | [
"Register",
"Batch",
"classes"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Tool/BatchProcessor.php#L144-L165 |
hametuha/wpametu | src/WPametu/Tool/BatchProcessor.php | BatchProcessor.ajax | public function ajax(){
try{
if( !$this->input->verify_nonce('wpametu_batch') ){
throw new \Exception($this->__('You have no permission'), 403);
}
$this->register_batches();
$class_name = stripslashes($this->input->post('batch_class'));
if( false === array_search($class_name, $this->batches) ){
throw new \Exception(sprintf($this->__('Batch %s doesn\'t exist.'), $class_name), 404);
}
$page = $this->input->post('page_num');
if( !is_numeric($page) ){
throw new \Exception($this->__('Invalid arguments.'), 500);
}
// O.K. Here we go!
/** @var Batch $instance */
$instance = $class_name::get_instance();
$result = $instance->process($page);
if( !$result ){
throw new \Exception($this->__('Sorry, but batch returns unexpected result.'));
}
$json = array(
'success' => true,
'processed' => $result->processed,
'total' => $result->total,
'next' => $result->has_next,
);
if( $result->message ){
$json['message'] = $result->message;
}else{
$json['message'] = $result->total
? sprintf($this->__('%s / %s have been processed.'), number_format_i18n($result->processed), number_format_i18n($result->total))
: sprintf($this->__('%s have been processed.'), number_format_i18n($result->processed));
}
// If this is last, update
if( !$result->has_next ){
$option = $this->option;
$option[$class_name] = current_time('timestamp');
update_option($this->option_key, $option);
}
}catch ( \Exception $e ){
$json = array(
'success' => false,
'message' => $e->getMessage(),
);
}
wp_send_json($json);
} | php | public function ajax(){
try{
if( !$this->input->verify_nonce('wpametu_batch') ){
throw new \Exception($this->__('You have no permission'), 403);
}
$this->register_batches();
$class_name = stripslashes($this->input->post('batch_class'));
if( false === array_search($class_name, $this->batches) ){
throw new \Exception(sprintf($this->__('Batch %s doesn\'t exist.'), $class_name), 404);
}
$page = $this->input->post('page_num');
if( !is_numeric($page) ){
throw new \Exception($this->__('Invalid arguments.'), 500);
}
// O.K. Here we go!
/** @var Batch $instance */
$instance = $class_name::get_instance();
$result = $instance->process($page);
if( !$result ){
throw new \Exception($this->__('Sorry, but batch returns unexpected result.'));
}
$json = array(
'success' => true,
'processed' => $result->processed,
'total' => $result->total,
'next' => $result->has_next,
);
if( $result->message ){
$json['message'] = $result->message;
}else{
$json['message'] = $result->total
? sprintf($this->__('%s / %s have been processed.'), number_format_i18n($result->processed), number_format_i18n($result->total))
: sprintf($this->__('%s have been processed.'), number_format_i18n($result->processed));
}
// If this is last, update
if( !$result->has_next ){
$option = $this->option;
$option[$class_name] = current_time('timestamp');
update_option($this->option_key, $option);
}
}catch ( \Exception $e ){
$json = array(
'success' => false,
'message' => $e->getMessage(),
);
}
wp_send_json($json);
} | [
"public",
"function",
"ajax",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"input",
"->",
"verify_nonce",
"(",
"'wpametu_batch'",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"__",
"(",
"'You have no permission'",
")",
",",
"403",
")",
";",
"}",
"$",
"this",
"->",
"register_batches",
"(",
")",
";",
"$",
"class_name",
"=",
"stripslashes",
"(",
"$",
"this",
"->",
"input",
"->",
"post",
"(",
"'batch_class'",
")",
")",
";",
"if",
"(",
"false",
"===",
"array_search",
"(",
"$",
"class_name",
",",
"$",
"this",
"->",
"batches",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"$",
"this",
"->",
"__",
"(",
"'Batch %s doesn\\'t exist.'",
")",
",",
"$",
"class_name",
")",
",",
"404",
")",
";",
"}",
"$",
"page",
"=",
"$",
"this",
"->",
"input",
"->",
"post",
"(",
"'page_num'",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"page",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"__",
"(",
"'Invalid arguments.'",
")",
",",
"500",
")",
";",
"}",
"// O.K. Here we go!",
"/** @var Batch $instance */",
"$",
"instance",
"=",
"$",
"class_name",
"::",
"get_instance",
"(",
")",
";",
"$",
"result",
"=",
"$",
"instance",
"->",
"process",
"(",
"$",
"page",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"__",
"(",
"'Sorry, but batch returns unexpected result.'",
")",
")",
";",
"}",
"$",
"json",
"=",
"array",
"(",
"'success'",
"=>",
"true",
",",
"'processed'",
"=>",
"$",
"result",
"->",
"processed",
",",
"'total'",
"=>",
"$",
"result",
"->",
"total",
",",
"'next'",
"=>",
"$",
"result",
"->",
"has_next",
",",
")",
";",
"if",
"(",
"$",
"result",
"->",
"message",
")",
"{",
"$",
"json",
"[",
"'message'",
"]",
"=",
"$",
"result",
"->",
"message",
";",
"}",
"else",
"{",
"$",
"json",
"[",
"'message'",
"]",
"=",
"$",
"result",
"->",
"total",
"?",
"sprintf",
"(",
"$",
"this",
"->",
"__",
"(",
"'%s / %s have been processed.'",
")",
",",
"number_format_i18n",
"(",
"$",
"result",
"->",
"processed",
")",
",",
"number_format_i18n",
"(",
"$",
"result",
"->",
"total",
")",
")",
":",
"sprintf",
"(",
"$",
"this",
"->",
"__",
"(",
"'%s have been processed.'",
")",
",",
"number_format_i18n",
"(",
"$",
"result",
"->",
"processed",
")",
")",
";",
"}",
"// If this is last, update",
"if",
"(",
"!",
"$",
"result",
"->",
"has_next",
")",
"{",
"$",
"option",
"=",
"$",
"this",
"->",
"option",
";",
"$",
"option",
"[",
"$",
"class_name",
"]",
"=",
"current_time",
"(",
"'timestamp'",
")",
";",
"update_option",
"(",
"$",
"this",
"->",
"option_key",
",",
"$",
"option",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"json",
"=",
"array",
"(",
"'success'",
"=>",
"false",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
")",
";",
"}",
"wp_send_json",
"(",
"$",
"json",
")",
";",
"}"
] | Process Ajax | [
"Process",
"Ajax"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Tool/BatchProcessor.php#L171-L218 |
heidelpay/PhpDoc | src/phpDocumentor/Descriptor/ArgumentDescriptor.php | ArgumentDescriptor.getTypes | public function getTypes()
{
if (count($this->types)==0 &&
$this->getInheritedElement() !== null
) {
$this->setTypes($this->getInheritedElement()->getTypes());
}
return $this->types;
} | php | public function getTypes()
{
if (count($this->types)==0 &&
$this->getInheritedElement() !== null
) {
$this->setTypes($this->getInheritedElement()->getTypes());
}
return $this->types;
} | [
"public",
"function",
"getTypes",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"types",
")",
"==",
"0",
"&&",
"$",
"this",
"->",
"getInheritedElement",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setTypes",
"(",
"$",
"this",
"->",
"getInheritedElement",
"(",
")",
"->",
"getTypes",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"types",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/ArgumentDescriptor.php#L54-L63 |
OpenBuildings/monetary | src/OpenBuildings/Monetary/CURL.php | CURL.request | public function request(array $curl_options)
{
$curl = $this->_init($curl_options);
$response = $this->_execute($curl);
// Execute response
if ($response === FALSE)
{
$this->_handle_error($curl);
return FALSE;
}
$this->_close($curl);
return $response;
} | php | public function request(array $curl_options)
{
$curl = $this->_init($curl_options);
$response = $this->_execute($curl);
// Execute response
if ($response === FALSE)
{
$this->_handle_error($curl);
return FALSE;
}
$this->_close($curl);
return $response;
} | [
"public",
"function",
"request",
"(",
"array",
"$",
"curl_options",
")",
"{",
"$",
"curl",
"=",
"$",
"this",
"->",
"_init",
"(",
"$",
"curl_options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"_execute",
"(",
"$",
"curl",
")",
";",
"// Execute response",
"if",
"(",
"$",
"response",
"===",
"FALSE",
")",
"{",
"$",
"this",
"->",
"_handle_error",
"(",
"$",
"curl",
")",
";",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"_close",
"(",
"$",
"curl",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Perform a cURL request
@param array $curl_options
@return string response of the request
@throws Exception_Source If the remote returns an error. | [
"Perform",
"a",
"cURL",
"request"
] | train | https://github.com/OpenBuildings/monetary/blob/f7831ab055eaba7105f3f3530506b96de7fedd29/src/OpenBuildings/Monetary/CURL.php#L18-L34 |
OpenBuildings/monetary | src/OpenBuildings/Monetary/CURL.php | CURL._init | protected function _init(array $curl_options)
{
$options = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 10
);
$options += $curl_options;
$curl = curl_init();
curl_setopt_array($curl, $options);
return $curl;
} | php | protected function _init(array $curl_options)
{
$options = array(
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 10
);
$options += $curl_options;
$curl = curl_init();
curl_setopt_array($curl, $options);
return $curl;
} | [
"protected",
"function",
"_init",
"(",
"array",
"$",
"curl_options",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"FALSE",
",",
"CURLOPT_SSL_VERIFYHOST",
"=>",
"FALSE",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"TRUE",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"TRUE",
",",
"CURLOPT_MAXREDIRS",
"=>",
"10",
")",
";",
"$",
"options",
"+=",
"$",
"curl_options",
";",
"$",
"curl",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"options",
")",
";",
"return",
"$",
"curl",
";",
"}"
] | Initializes a cURL resource and set options
@param array $curl_options
@return resource cURL resource
@codeCoverageIgnore | [
"Initializes",
"a",
"cURL",
"resource",
"and",
"set",
"options"
] | train | https://github.com/OpenBuildings/monetary/blob/f7831ab055eaba7105f3f3530506b96de7fedd29/src/OpenBuildings/Monetary/CURL.php#L42-L59 |
OpenBuildings/monetary | src/OpenBuildings/Monetary/CURL.php | CURL._handle_error | protected function _handle_error($curl)
{
// Get the error code and message
$code = curl_errno($curl);
$error = curl_error($curl);
$this->_close($curl);
throw new Exception_Source(
'Fetching :source_name data failed: :error (:code)',
'remote',
array(
':error' => $error,
':code' => $code
)
);
} | php | protected function _handle_error($curl)
{
// Get the error code and message
$code = curl_errno($curl);
$error = curl_error($curl);
$this->_close($curl);
throw new Exception_Source(
'Fetching :source_name data failed: :error (:code)',
'remote',
array(
':error' => $error,
':code' => $code
)
);
} | [
"protected",
"function",
"_handle_error",
"(",
"$",
"curl",
")",
"{",
"// Get the error code and message",
"$",
"code",
"=",
"curl_errno",
"(",
"$",
"curl",
")",
";",
"$",
"error",
"=",
"curl_error",
"(",
"$",
"curl",
")",
";",
"$",
"this",
"->",
"_close",
"(",
"$",
"curl",
")",
";",
"throw",
"new",
"Exception_Source",
"(",
"'Fetching :source_name data failed: :error (:code)'",
",",
"'remote'",
",",
"array",
"(",
"':error'",
"=>",
"$",
"error",
",",
"':code'",
"=>",
"$",
"code",
")",
")",
";",
"}"
] | Handle cURL errors
@param resource $curl cURL resource with an error
@throws Exception_Source with the error message and error code | [
"Handle",
"cURL",
"errors"
] | train | https://github.com/OpenBuildings/monetary/blob/f7831ab055eaba7105f3f3530506b96de7fedd29/src/OpenBuildings/Monetary/CURL.php#L86-L102 |
sergmoro1/yii2-lookup | src/models/Property.php | Property.getValues | public static function getValues($name, $index = 'code') {
if($property_id = self::getId($name)) {
$a = [];
foreach(Lookup::find()
->select(['position', 'name'])
->where(['property_id' => $property_id])
->orderBy($index)->all() as $item)
$a[$item->$index] = $item->name;
return $a;
} else
return null;
} | php | public static function getValues($name, $index = 'code') {
if($property_id = self::getId($name)) {
$a = [];
foreach(Lookup::find()
->select(['position', 'name'])
->where(['property_id' => $property_id])
->orderBy($index)->all() as $item)
$a[$item->$index] = $item->name;
return $a;
} else
return null;
} | [
"public",
"static",
"function",
"getValues",
"(",
"$",
"name",
",",
"$",
"index",
"=",
"'code'",
")",
"{",
"if",
"(",
"$",
"property_id",
"=",
"self",
"::",
"getId",
"(",
"$",
"name",
")",
")",
"{",
"$",
"a",
"=",
"[",
"]",
";",
"foreach",
"(",
"Lookup",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"[",
"'position'",
",",
"'name'",
"]",
")",
"->",
"where",
"(",
"[",
"'property_id'",
"=>",
"$",
"property_id",
"]",
")",
"->",
"orderBy",
"(",
"$",
"index",
")",
"->",
"all",
"(",
")",
"as",
"$",
"item",
")",
"$",
"a",
"[",
"$",
"item",
"->",
"$",
"index",
"]",
"=",
"$",
"item",
"->",
"name",
";",
"return",
"$",
"a",
";",
"}",
"else",
"return",
"null",
";",
"}"
] | Get all property values as array with Code or Position as index.
@params string property name
@params string code or position
@return array | [
"Get",
"all",
"property",
"values",
"as",
"array",
"with",
"Code",
"or",
"Position",
"as",
"index",
"."
] | train | https://github.com/sergmoro1/yii2-lookup/blob/deff08a2612b3c54d313a6c60a74fcaae1193b21/src/models/Property.php#L45-L56 |
technote-space/wordpress-plugin-base | src/traits/cron.php | Cron.set_cron_event | private function set_cron_event() {
$interval = $this->get_interval();
if ( $interval > 0 ) {
if ( ! wp_next_scheduled( $this->get_hook_name() ) ) {
if ( $this->is_running_cron_process() ) {
return;
}
wp_schedule_single_event( time() + $interval, $this->get_hook_name() );
}
}
} | php | private function set_cron_event() {
$interval = $this->get_interval();
if ( $interval > 0 ) {
if ( ! wp_next_scheduled( $this->get_hook_name() ) ) {
if ( $this->is_running_cron_process() ) {
return;
}
wp_schedule_single_event( time() + $interval, $this->get_hook_name() );
}
}
} | [
"private",
"function",
"set_cron_event",
"(",
")",
"{",
"$",
"interval",
"=",
"$",
"this",
"->",
"get_interval",
"(",
")",
";",
"if",
"(",
"$",
"interval",
">",
"0",
")",
"{",
"if",
"(",
"!",
"wp_next_scheduled",
"(",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_running_cron_process",
"(",
")",
")",
"{",
"return",
";",
"}",
"wp_schedule_single_event",
"(",
"time",
"(",
")",
"+",
"$",
"interval",
",",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
";",
"}",
"}",
"}"
] | set cron event | [
"set",
"cron",
"event"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/cron.php#L43-L53 |
technote-space/wordpress-plugin-base | src/traits/cron.php | Cron.lock_cron_process | private function lock_cron_process() {
set_site_transient( $this->get_transient_key(), microtime(), $this->apply_filters( 'cron_process_expire', $this->get_expire(), $this->get_hook_name() ) );
} | php | private function lock_cron_process() {
set_site_transient( $this->get_transient_key(), microtime(), $this->apply_filters( 'cron_process_expire', $this->get_expire(), $this->get_hook_name() ) );
} | [
"private",
"function",
"lock_cron_process",
"(",
")",
"{",
"set_site_transient",
"(",
"$",
"this",
"->",
"get_transient_key",
"(",
")",
",",
"microtime",
"(",
")",
",",
"$",
"this",
"->",
"apply_filters",
"(",
"'cron_process_expire'",
",",
"$",
"this",
"->",
"get_expire",
"(",
")",
",",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
")",
";",
"}"
] | lock | [
"lock"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/cron.php#L69-L71 |
technote-space/wordpress-plugin-base | src/traits/cron.php | Cron.run | public final function run() {
if ( $this->is_running_cron_process() ) {
return;
}
set_time_limit( 0 );
$this->lock_cron_process();
$this->do_action( 'before_cron_run', $this->get_hook_name() );
$this->execute();
$this->do_action( 'after_cron_run', $this->get_hook_name() );
$this->set_cron_event();
$this->unlock_cron_process();
} | php | public final function run() {
if ( $this->is_running_cron_process() ) {
return;
}
set_time_limit( 0 );
$this->lock_cron_process();
$this->do_action( 'before_cron_run', $this->get_hook_name() );
$this->execute();
$this->do_action( 'after_cron_run', $this->get_hook_name() );
$this->set_cron_event();
$this->unlock_cron_process();
} | [
"public",
"final",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_running_cron_process",
"(",
")",
")",
"{",
"return",
";",
"}",
"set_time_limit",
"(",
"0",
")",
";",
"$",
"this",
"->",
"lock_cron_process",
"(",
")",
";",
"$",
"this",
"->",
"do_action",
"(",
"'before_cron_run'",
",",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
";",
"$",
"this",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"do_action",
"(",
"'after_cron_run'",
",",
"$",
"this",
"->",
"get_hook_name",
"(",
")",
")",
";",
"$",
"this",
"->",
"set_cron_event",
"(",
")",
";",
"$",
"this",
"->",
"unlock_cron_process",
"(",
")",
";",
"}"
] | run | [
"run"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/cron.php#L125-L136 |
SporkCode/Spork | src/Validator/AuthAdapter.php | AuthAdapter.isValid | public function isValid($value, array $context = null)
{
$context = (array) $context;
if (!array_key_exists($this->identity, $context) || empty($context[$this->identity])) {
// $this->error(self::IDENTITY_EMPTY);
return false;
}
if (!array_key_exists($this->credential, $context) || empty($context[$this->credential])) {
// $this->error(self::CREDENTIAL_EMPTY);
return false;
}
$authAdapter = $this->auth->getAdapter();
$authAdapter->setIdentity($context[$this->identity]);
$authAdapter->setCredential($context[$this->credential]);
$result = $this->authResult = $this->auth->authenticate();
if (!$result->isValid()) {
$this->error($result->getCode());
return false;
}
return true;
} | php | public function isValid($value, array $context = null)
{
$context = (array) $context;
if (!array_key_exists($this->identity, $context) || empty($context[$this->identity])) {
// $this->error(self::IDENTITY_EMPTY);
return false;
}
if (!array_key_exists($this->credential, $context) || empty($context[$this->credential])) {
// $this->error(self::CREDENTIAL_EMPTY);
return false;
}
$authAdapter = $this->auth->getAdapter();
$authAdapter->setIdentity($context[$this->identity]);
$authAdapter->setCredential($context[$this->credential]);
$result = $this->authResult = $this->auth->authenticate();
if (!$result->isValid()) {
$this->error($result->getCode());
return false;
}
return true;
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
",",
"array",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"context",
"=",
"(",
"array",
")",
"$",
"context",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"identity",
",",
"$",
"context",
")",
"||",
"empty",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"identity",
"]",
")",
")",
"{",
"// $this->error(self::IDENTITY_EMPTY);",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"credential",
",",
"$",
"context",
")",
"||",
"empty",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"credential",
"]",
")",
")",
"{",
"// $this->error(self::CREDENTIAL_EMPTY);",
"return",
"false",
";",
"}",
"$",
"authAdapter",
"=",
"$",
"this",
"->",
"auth",
"->",
"getAdapter",
"(",
")",
";",
"$",
"authAdapter",
"->",
"setIdentity",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"identity",
"]",
")",
";",
"$",
"authAdapter",
"->",
"setCredential",
"(",
"$",
"context",
"[",
"$",
"this",
"->",
"credential",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"authResult",
"=",
"$",
"this",
"->",
"auth",
"->",
"authenticate",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"result",
"->",
"getCode",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Test if authentication is valid
@see \Zend\Validator\ValidatorInterface::isValid()
@param mixed $value
@param array $context
@return boolean | [
"Test",
"if",
"authentication",
"is",
"valid"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Validator/AuthAdapter.php#L150-L176 |
antaresproject/notifications | src/Model/NotificationContents.php | NotificationContents.fires | protected function fires()
{
$className = isset($this->notification->classname) ? snake_case(class_basename($this->notification->classname)) : false;
if (! $className) {
return [];
}
$before = event('notifications:' . $className . '.render.before');
$after = event('notifications:' . $className . '.render.after');
return [
'before' => !empty($before) ? current($before) : '',
'after' => !empty($after) ? current($after) : ''
];
} | php | protected function fires()
{
$className = isset($this->notification->classname) ? snake_case(class_basename($this->notification->classname)) : false;
if (! $className) {
return [];
}
$before = event('notifications:' . $className . '.render.before');
$after = event('notifications:' . $className . '.render.after');
return [
'before' => !empty($before) ? current($before) : '',
'after' => !empty($after) ? current($after) : ''
];
} | [
"protected",
"function",
"fires",
"(",
")",
"{",
"$",
"className",
"=",
"isset",
"(",
"$",
"this",
"->",
"notification",
"->",
"classname",
")",
"?",
"snake_case",
"(",
"class_basename",
"(",
"$",
"this",
"->",
"notification",
"->",
"classname",
")",
")",
":",
"false",
";",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"before",
"=",
"event",
"(",
"'notifications:'",
".",
"$",
"className",
".",
"'.render.before'",
")",
";",
"$",
"after",
"=",
"event",
"(",
"'notifications:'",
".",
"$",
"className",
".",
"'.render.after'",
")",
";",
"return",
"[",
"'before'",
"=>",
"!",
"empty",
"(",
"$",
"before",
")",
"?",
"current",
"(",
"$",
"before",
")",
":",
"''",
",",
"'after'",
"=>",
"!",
"empty",
"(",
"$",
"after",
")",
"?",
"current",
"(",
"$",
"after",
")",
":",
"''",
"]",
";",
"}"
] | fires events for notification template
@return array | [
"fires",
"events",
"for",
"notification",
"template"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Model/NotificationContents.php#L88-L103 |
antaresproject/notifications | src/Model/NotificationContents.php | NotificationContents.save | public function save(array $options = array())
{
$fired = $this->fires();
$content = count($fired)
? str_replace([$fired['before'], $fired['after']], '', $this->content)
: $this->content;
$this->setAttribute('content', $content);
$this->attributes['content'] = $content;
parent::save($options);
} | php | public function save(array $options = array())
{
$fired = $this->fires();
$content = count($fired)
? str_replace([$fired['before'], $fired['after']], '', $this->content)
: $this->content;
$this->setAttribute('content', $content);
$this->attributes['content'] = $content;
parent::save($options);
} | [
"public",
"function",
"save",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"fired",
"=",
"$",
"this",
"->",
"fires",
"(",
")",
";",
"$",
"content",
"=",
"count",
"(",
"$",
"fired",
")",
"?",
"str_replace",
"(",
"[",
"$",
"fired",
"[",
"'before'",
"]",
",",
"$",
"fired",
"[",
"'after'",
"]",
"]",
",",
"''",
",",
"$",
"this",
"->",
"content",
")",
":",
"$",
"this",
"->",
"content",
";",
"$",
"this",
"->",
"setAttribute",
"(",
"'content'",
",",
"$",
"content",
")",
";",
"$",
"this",
"->",
"attributes",
"[",
"'content'",
"]",
"=",
"$",
"content",
";",
"parent",
"::",
"save",
"(",
"$",
"options",
")",
";",
"}"
] | saves notification content without data from fired events
@param array $options | [
"saves",
"notification",
"content",
"without",
"data",
"from",
"fired",
"events"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Model/NotificationContents.php#L133-L144 |
skmetaly/laravel-twitch-restful-api | src/API/Blocks.php | Blocks.blocks | public function blocks($login, $token = null)
{
$token = $this->getToken($token);
$url = config('twitch-api.api_url') . '/kraken/users/' . $login . '/blocks';
$request = $this->createRequest('GET', $url, $token);
$blocks = $this->client->send($request);
return $blocks->json();
} | php | public function blocks($login, $token = null)
{
$token = $this->getToken($token);
$url = config('twitch-api.api_url') . '/kraken/users/' . $login . '/blocks';
$request = $this->createRequest('GET', $url, $token);
$blocks = $this->client->send($request);
return $blocks->json();
} | [
"public",
"function",
"blocks",
"(",
"$",
"login",
",",
"$",
"token",
"=",
"null",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getToken",
"(",
"$",
"token",
")",
";",
"$",
"url",
"=",
"config",
"(",
"'twitch-api.api_url'",
")",
".",
"'/kraken/users/'",
".",
"$",
"login",
".",
"'/blocks'",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"'GET'",
",",
"$",
"url",
",",
"$",
"token",
")",
";",
"$",
"blocks",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"return",
"$",
"blocks",
"->",
"json",
"(",
")",
";",
"}"
] | Returns a list of blocks objects on :login's block list. List sorted by recency, newest first.
Authenticated, required scope: user_blocks_read
@param $login
@param null $token
@return json | [
"Returns",
"a",
"list",
"of",
"blocks",
"objects",
"on",
":",
"login",
"s",
"block",
"list",
".",
"List",
"sorted",
"by",
"recency",
"newest",
"first",
".",
"Authenticated",
"required",
"scope",
":",
"user_blocks_read"
] | train | https://github.com/skmetaly/laravel-twitch-restful-api/blob/70c83e441deb411ade2e343ad5cb0339c90dc6c2/src/API/Blocks.php#L25-L36 |
skmetaly/laravel-twitch-restful-api | src/API/Blocks.php | Blocks.putBlock | public function putBlock($user, $target, $token = null)
{
$token = $this->getToken($token);
$url = 'https://api.twitch.tv/kraken/users/' . $user . '/blocks/' . $target;
$type = 'PUT';
$request = $this->createRequest($type, $url, $token);
$response = $this->client->send($request);
return $response->json();
} | php | public function putBlock($user, $target, $token = null)
{
$token = $this->getToken($token);
$url = 'https://api.twitch.tv/kraken/users/' . $user . '/blocks/' . $target;
$type = 'PUT';
$request = $this->createRequest($type, $url, $token);
$response = $this->client->send($request);
return $response->json();
} | [
"public",
"function",
"putBlock",
"(",
"$",
"user",
",",
"$",
"target",
",",
"$",
"token",
"=",
"null",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getToken",
"(",
"$",
"token",
")",
";",
"$",
"url",
"=",
"'https://api.twitch.tv/kraken/users/'",
".",
"$",
"user",
".",
"'/blocks/'",
".",
"$",
"target",
";",
"$",
"type",
"=",
"'PUT'",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"type",
",",
"$",
"url",
",",
"$",
"token",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"return",
"$",
"response",
"->",
"json",
"(",
")",
";",
"}"
] | Adds :target to :user's block list. :user is the authenticated user and :target is user to be blocked. Returns a blocks object.
Authenticated, required scope: user_blocks_edit
@param $user
@param $target
@param null $token
@return json | [
"Adds",
":",
"target",
"to",
":",
"user",
"s",
"block",
"list",
".",
":",
"user",
"is",
"the",
"authenticated",
"user",
"and",
":",
"target",
"is",
"user",
"to",
"be",
"blocked",
".",
"Returns",
"a",
"blocks",
"object",
".",
"Authenticated",
"required",
"scope",
":",
"user_blocks_edit"
] | train | https://github.com/skmetaly/laravel-twitch-restful-api/blob/70c83e441deb411ade2e343ad5cb0339c90dc6c2/src/API/Blocks.php#L48-L61 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.