repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Service/Quicklist.php
Quicklist.getFirstAdminPerClass
private function getFirstAdminPerClass($class) { $code = null; $admins = $this->adminPool->getAdminClasses(); foreach ($admins as $key => $value) { if ($key === $class) { $code = current($value); break; } } return $code === null ? $this->adminPool->getAdminByClass($class) : $this->adminPool->getAdminByAdminCode($code); }
php
private function getFirstAdminPerClass($class) { $code = null; $admins = $this->adminPool->getAdminClasses(); foreach ($admins as $key => $value) { if ($key === $class) { $code = current($value); break; } } return $code === null ? $this->adminPool->getAdminByClass($class) : $this->adminPool->getAdminByAdminCode($code); }
[ "private", "function", "getFirstAdminPerClass", "(", "$", "class", ")", "{", "$", "code", "=", "null", ";", "$", "admins", "=", "$", "this", "->", "adminPool", "->", "getAdminClasses", "(", ")", ";", "foreach", "(", "$", "admins", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "===", "$", "class", ")", "{", "$", "code", "=", "current", "(", "$", "value", ")", ";", "break", ";", "}", "}", "return", "$", "code", "===", "null", "?", "$", "this", "->", "adminPool", "->", "getAdminByClass", "(", "$", "class", ")", ":", "$", "this", "->", "adminPool", "->", "getAdminByAdminCode", "(", "$", "code", ")", ";", "}" ]
Gets the first admin when there are multiple definitions. @param string $class @return null|\Sonata\AdminBundle\Admin\AdminInterface
[ "Gets", "the", "first", "admin", "when", "there", "are", "multiple", "definitions", "." ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Service/Quicklist.php#L81-L95
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Service/Quicklist.php
Quicklist.getResults
public function getResults($repository, $pattern, $language = null, $max = 15) { $queryResults = $this->findRecords($repository, $pattern, $language); $results = array(); foreach ($queryResults as $record) { $admin = $this->getFirstAdminPerClass(get_class($record)); if (!$admin) { $admin = $this->getFirstAdminPerClass(get_parent_class($record)); } $resultRecord = $this->createResultRecord($record, $admin); $results[] = $resultRecord; } // TODO do this sort in DQL. Unfortunately, doctrine is not too handy with this, so // I'll keep it like this for a second. Note the the "setMaxResults()" should be reverted to $max // and the slice can be removed usort( $results, function ($a, $b) use ($pattern) { $percentA = 0; $percentB = 0; similar_text($a['label'], $pattern, $percentA); similar_text($b['label'], $pattern, $percentB); return $percentB - $percentA; } ); return array_slice($results, 0, $max); }
php
public function getResults($repository, $pattern, $language = null, $max = 15) { $queryResults = $this->findRecords($repository, $pattern, $language); $results = array(); foreach ($queryResults as $record) { $admin = $this->getFirstAdminPerClass(get_class($record)); if (!$admin) { $admin = $this->getFirstAdminPerClass(get_parent_class($record)); } $resultRecord = $this->createResultRecord($record, $admin); $results[] = $resultRecord; } // TODO do this sort in DQL. Unfortunately, doctrine is not too handy with this, so // I'll keep it like this for a second. Note the the "setMaxResults()" should be reverted to $max // and the slice can be removed usort( $results, function ($a, $b) use ($pattern) { $percentA = 0; $percentB = 0; similar_text($a['label'], $pattern, $percentA); similar_text($b['label'], $pattern, $percentB); return $percentB - $percentA; } ); return array_slice($results, 0, $max); }
[ "public", "function", "getResults", "(", "$", "repository", ",", "$", "pattern", ",", "$", "language", "=", "null", ",", "$", "max", "=", "15", ")", "{", "$", "queryResults", "=", "$", "this", "->", "findRecords", "(", "$", "repository", ",", "$", "pattern", ",", "$", "language", ")", ";", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "queryResults", "as", "$", "record", ")", "{", "$", "admin", "=", "$", "this", "->", "getFirstAdminPerClass", "(", "get_class", "(", "$", "record", ")", ")", ";", "if", "(", "!", "$", "admin", ")", "{", "$", "admin", "=", "$", "this", "->", "getFirstAdminPerClass", "(", "get_parent_class", "(", "$", "record", ")", ")", ";", "}", "$", "resultRecord", "=", "$", "this", "->", "createResultRecord", "(", "$", "record", ",", "$", "admin", ")", ";", "$", "results", "[", "]", "=", "$", "resultRecord", ";", "}", "// TODO do this sort in DQL. Unfortunately, doctrine is not too handy with this, so", "// I'll keep it like this for a second. Note the the \"setMaxResults()\" should be reverted to $max", "// and the slice can be removed", "usort", "(", "$", "results", ",", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "pattern", ")", "{", "$", "percentA", "=", "0", ";", "$", "percentB", "=", "0", ";", "similar_text", "(", "$", "a", "[", "'label'", "]", ",", "$", "pattern", ",", "$", "percentA", ")", ";", "similar_text", "(", "$", "b", "[", "'label'", "]", ",", "$", "pattern", ",", "$", "percentB", ")", ";", "return", "$", "percentB", "-", "$", "percentA", ";", "}", ")", ";", "return", "array_slice", "(", "$", "results", ",", "0", ",", "$", "max", ")", ";", "}" ]
Get the result suggestions for the passed pattern @param string $repository @param string $pattern @param null|string $language @param int $max @return array
[ "Get", "the", "result", "suggestions", "for", "the", "passed", "pattern" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Service/Quicklist.php#L106-L137
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Service/Quicklist.php
Quicklist.getOne
public function getOne($repository, $id) { $repoConfig = $this->repos[$repository]; /** @var $q \Doctrine\ORM\QueryBuilder */ return $this->doctrine ->getRepository($repoConfig['repository']) ->find($id); }
php
public function getOne($repository, $id) { $repoConfig = $this->repos[$repository]; /** @var $q \Doctrine\ORM\QueryBuilder */ return $this->doctrine ->getRepository($repoConfig['repository']) ->find($id); }
[ "public", "function", "getOne", "(", "$", "repository", ",", "$", "id", ")", "{", "$", "repoConfig", "=", "$", "this", "->", "repos", "[", "$", "repository", "]", ";", "/** @var $q \\Doctrine\\ORM\\QueryBuilder */", "return", "$", "this", "->", "doctrine", "->", "getRepository", "(", "$", "repoConfig", "[", "'repository'", "]", ")", "->", "find", "(", "$", "id", ")", ";", "}" ]
Return a single record by it's id. Used to map the front-end variable back to an object from the repository. @param string $repository @param mixed $id @return object
[ "Return", "a", "single", "record", "by", "it", "s", "id", ".", "Used", "to", "map", "the", "front", "-", "end", "variable", "back", "to", "an", "object", "from", "the", "repository", "." ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Service/Quicklist.php#L147-L154
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Service/Quicklist.php
Quicklist.createResultRecord
public function createResultRecord($record, $admin) { $resultRecord = array( 'label' => (string)$record, 'value' => (string)$record, 'url' => ($admin ? $admin->generateObjectUrl('edit', $record) : null), 'id' => ($admin ? $admin->id($record) : null) ); return $resultRecord; }
php
public function createResultRecord($record, $admin) { $resultRecord = array( 'label' => (string)$record, 'value' => (string)$record, 'url' => ($admin ? $admin->generateObjectUrl('edit', $record) : null), 'id' => ($admin ? $admin->id($record) : null) ); return $resultRecord; }
[ "public", "function", "createResultRecord", "(", "$", "record", ",", "$", "admin", ")", "{", "$", "resultRecord", "=", "array", "(", "'label'", "=>", "(", "string", ")", "$", "record", ",", "'value'", "=>", "(", "string", ")", "$", "record", ",", "'url'", "=>", "(", "$", "admin", "?", "$", "admin", "->", "generateObjectUrl", "(", "'edit'", ",", "$", "record", ")", ":", "null", ")", ",", "'id'", "=>", "(", "$", "admin", "?", "$", "admin", "->", "id", "(", "$", "record", ")", ":", "null", ")", ")", ";", "return", "$", "resultRecord", ";", "}" ]
Creates result record @param object $record @param object $admin @return array
[ "Creates", "result", "record" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Service/Quicklist.php#L196-L205
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Event/Subscriber.php
Subscriber.addMenuItem
public function addMenuItem(MenuEvent $e) { $array = $e->getMenuConfig(); $this->menu->addChild( $this->factory->createItem($array['name'], $array) ); }
php
public function addMenuItem(MenuEvent $e) { $array = $e->getMenuConfig(); $this->menu->addChild( $this->factory->createItem($array['name'], $array) ); }
[ "public", "function", "addMenuItem", "(", "MenuEvent", "$", "e", ")", "{", "$", "array", "=", "$", "e", "->", "getMenuConfig", "(", ")", ";", "$", "this", "->", "menu", "->", "addChild", "(", "$", "this", "->", "factory", "->", "createItem", "(", "$", "array", "[", "'name'", "]", ",", "$", "array", ")", ")", ";", "}" ]
Add a child to the menu @param MenuEvent $e @return void
[ "Add", "a", "child", "to", "the", "menu" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Event/Subscriber.php#L57-L64
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Util/AdminUtil.php
AdminUtil.reorderTabs
public static function reorderTabs(FormMapper $formMapper, array $tabOrder) { $tabsOriginal = $formMapper->getAdmin()->getFormTabs(); //filter out tabs that doesn't exist (yet) $tabOrder = array_filter( $tabOrder, function ($key) use ($tabsOriginal) { return array_key_exists($key, $tabsOriginal); } ); $tabs = array_merge(array_flip($tabOrder), $tabsOriginal); $formMapper->getAdmin()->setFormTabs($tabs); }
php
public static function reorderTabs(FormMapper $formMapper, array $tabOrder) { $tabsOriginal = $formMapper->getAdmin()->getFormTabs(); //filter out tabs that doesn't exist (yet) $tabOrder = array_filter( $tabOrder, function ($key) use ($tabsOriginal) { return array_key_exists($key, $tabsOriginal); } ); $tabs = array_merge(array_flip($tabOrder), $tabsOriginal); $formMapper->getAdmin()->setFormTabs($tabs); }
[ "public", "static", "function", "reorderTabs", "(", "FormMapper", "$", "formMapper", ",", "array", "$", "tabOrder", ")", "{", "$", "tabsOriginal", "=", "$", "formMapper", "->", "getAdmin", "(", ")", "->", "getFormTabs", "(", ")", ";", "//filter out tabs that doesn't exist (yet)", "$", "tabOrder", "=", "array_filter", "(", "$", "tabOrder", ",", "function", "(", "$", "key", ")", "use", "(", "$", "tabsOriginal", ")", "{", "return", "array_key_exists", "(", "$", "key", ",", "$", "tabsOriginal", ")", ";", "}", ")", ";", "$", "tabs", "=", "array_merge", "(", "array_flip", "(", "$", "tabOrder", ")", ",", "$", "tabsOriginal", ")", ";", "$", "formMapper", "->", "getAdmin", "(", ")", "->", "setFormTabs", "(", "$", "tabs", ")", ";", "}" ]
Allows to reorder Tabs Need the formMapper since the used methods to set the tabs are protected in the original Sonata implementation @param FormMapper $formMapper @param array $tabOrder @return void
[ "Allows", "to", "reorder", "Tabs" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Util/AdminUtil.php#L40-L54
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Util/AdminUtil.php
AdminUtil.map
public function map(FormMapper $formMapper, $helpPrefix = null) { $this->formMapper = $formMapper; $this->helpPrefix = $helpPrefix; return $this; }
php
public function map(FormMapper $formMapper, $helpPrefix = null) { $this->formMapper = $formMapper; $this->helpPrefix = $helpPrefix; return $this; }
[ "public", "function", "map", "(", "FormMapper", "$", "formMapper", ",", "$", "helpPrefix", "=", "null", ")", "{", "$", "this", "->", "formMapper", "=", "$", "formMapper", ";", "$", "this", "->", "helpPrefix", "=", "$", "helpPrefix", ";", "return", "$", "this", ";", "}" ]
Start a mapping of fields on the given formMapper @param FormMapper $formMapper @param null|string $helpPrefix @return AdminUtil
[ "Start", "a", "mapping", "of", "fields", "on", "the", "given", "formMapper" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Util/AdminUtil.php#L63-L68
train
zicht/admin-bundle
src/Zicht/Bundle/AdminBundle/Util/AdminUtil.php
AdminUtil.add
public function add($name, $type = null, array $options = array(), array $fieldDescriptionOptions = array()) { if (null === $this->formMapper) { throw new LogicException('No FormMapper to add fields to, please make sure you start with AdminUtil->map'); } $this->formMapper->add($name, $type, $options, $fieldDescriptionOptions); if ($this->addHelp) { $this->formMapper->setHelps([$name => 'help' . (null !== $this->helpPrefix ? sprintf('.%s', $this->helpPrefix) : '') . '.' . $name]); } return $this; }
php
public function add($name, $type = null, array $options = array(), array $fieldDescriptionOptions = array()) { if (null === $this->formMapper) { throw new LogicException('No FormMapper to add fields to, please make sure you start with AdminUtil->map'); } $this->formMapper->add($name, $type, $options, $fieldDescriptionOptions); if ($this->addHelp) { $this->formMapper->setHelps([$name => 'help' . (null !== $this->helpPrefix ? sprintf('.%s', $this->helpPrefix) : '') . '.' . $name]); } return $this; }
[ "public", "function", "add", "(", "$", "name", ",", "$", "type", "=", "null", ",", "array", "$", "options", "=", "array", "(", ")", ",", "array", "$", "fieldDescriptionOptions", "=", "array", "(", ")", ")", "{", "if", "(", "null", "===", "$", "this", "->", "formMapper", ")", "{", "throw", "new", "LogicException", "(", "'No FormMapper to add fields to, please make sure you start with AdminUtil->map'", ")", ";", "}", "$", "this", "->", "formMapper", "->", "add", "(", "$", "name", ",", "$", "type", ",", "$", "options", ",", "$", "fieldDescriptionOptions", ")", ";", "if", "(", "$", "this", "->", "addHelp", ")", "{", "$", "this", "->", "formMapper", "->", "setHelps", "(", "[", "$", "name", "=>", "'help'", ".", "(", "null", "!==", "$", "this", "->", "helpPrefix", "?", "sprintf", "(", "'.%s'", ",", "$", "this", "->", "helpPrefix", ")", ":", "''", ")", ".", "'.'", ".", "$", "name", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add a field to the given formMapper @param string $name @param null $type @param array $options @param array $fieldDescriptionOptions @return $this
[ "Add", "a", "field", "to", "the", "given", "formMapper" ]
16c40205a897cdc43eb825c3ba00296ea1a3cb37
https://github.com/zicht/admin-bundle/blob/16c40205a897cdc43eb825c3ba00296ea1a3cb37/src/Zicht/Bundle/AdminBundle/Util/AdminUtil.php#L90-L100
train
altayalp/php-ftp-client
src/Abstracts/AbstractFtp.php
AbstractFtp.listItem
public function listItem($type, $dir = '.', $recursive = false, $ignore = array()) { if ($type != 'dir' && $type != 'file') { throw new \InvalidArgumentException('$type must "file" or "dir"'); } $fileList = $this->nList($dir); $fileInfo = array(); foreach ($fileList as $file) { // remove directory and subdirectory name $file = str_replace("$dir/", '', $file); if ($this->ignoreItem($type, $file, $ignore) !== true && $this->isDirOrFile("$dir/$file") == $type) { $fileInfo[] = $file; } if ($recursive === true && $this->isDirOrFile("$dir/$file") == 'dir') { $fileInfo = array_merge($fileInfo, $this->listItem($type, "$dir/$file", $recursive, $ignore)); } } return $fileInfo; }
php
public function listItem($type, $dir = '.', $recursive = false, $ignore = array()) { if ($type != 'dir' && $type != 'file') { throw new \InvalidArgumentException('$type must "file" or "dir"'); } $fileList = $this->nList($dir); $fileInfo = array(); foreach ($fileList as $file) { // remove directory and subdirectory name $file = str_replace("$dir/", '', $file); if ($this->ignoreItem($type, $file, $ignore) !== true && $this->isDirOrFile("$dir/$file") == $type) { $fileInfo[] = $file; } if ($recursive === true && $this->isDirOrFile("$dir/$file") == 'dir') { $fileInfo = array_merge($fileInfo, $this->listItem($type, "$dir/$file", $recursive, $ignore)); } } return $fileInfo; }
[ "public", "function", "listItem", "(", "$", "type", ",", "$", "dir", "=", "'.'", ",", "$", "recursive", "=", "false", ",", "$", "ignore", "=", "array", "(", ")", ")", "{", "if", "(", "$", "type", "!=", "'dir'", "&&", "$", "type", "!=", "'file'", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$type must \"file\" or \"dir\"'", ")", ";", "}", "$", "fileList", "=", "$", "this", "->", "nList", "(", "$", "dir", ")", ";", "$", "fileInfo", "=", "array", "(", ")", ";", "foreach", "(", "$", "fileList", "as", "$", "file", ")", "{", "// remove directory and subdirectory name", "$", "file", "=", "str_replace", "(", "\"$dir/\"", ",", "''", ",", "$", "file", ")", ";", "if", "(", "$", "this", "->", "ignoreItem", "(", "$", "type", ",", "$", "file", ",", "$", "ignore", ")", "!==", "true", "&&", "$", "this", "->", "isDirOrFile", "(", "\"$dir/$file\"", ")", "==", "$", "type", ")", "{", "$", "fileInfo", "[", "]", "=", "$", "file", ";", "}", "if", "(", "$", "recursive", "===", "true", "&&", "$", "this", "->", "isDirOrFile", "(", "\"$dir/$file\"", ")", "==", "'dir'", ")", "{", "$", "fileInfo", "=", "array_merge", "(", "$", "fileInfo", ",", "$", "this", "->", "listItem", "(", "$", "type", ",", "\"$dir/$file\"", ",", "$", "recursive", ",", "$", "ignore", ")", ")", ";", "}", "}", "return", "$", "fileInfo", ";", "}" ]
List of file or directory @link http://php.net/ftp_nlist Php manuel @access public @param string $dir ftp directory name @return array file list @throws FileException
[ "List", "of", "file", "or", "directory" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/Abstracts/AbstractFtp.php#L98-L116
train
altayalp/php-ftp-client
src/Files/SftpFile.php
SftpFile.wget
public function wget($httpFile, $remote) { if (! ini_get('allow_url_fopen')) { throw new \RuntimeException('allow_url_fopen must enabled'); } if (! $fileData = file_get_contents($httpFile)) { throw new \RuntimeException('Can nat get file content'); } $parseFile = $this->parseLastDirectory($remote); if (! file_put_contents($this->getWrapper("/$parseFile"), $fileData)) { throw new FileException('File not uploaded to ftp server'); } return true; }
php
public function wget($httpFile, $remote) { if (! ini_get('allow_url_fopen')) { throw new \RuntimeException('allow_url_fopen must enabled'); } if (! $fileData = file_get_contents($httpFile)) { throw new \RuntimeException('Can nat get file content'); } $parseFile = $this->parseLastDirectory($remote); if (! file_put_contents($this->getWrapper("/$parseFile"), $fileData)) { throw new FileException('File not uploaded to ftp server'); } return true; }
[ "public", "function", "wget", "(", "$", "httpFile", ",", "$", "remote", ")", "{", "if", "(", "!", "ini_get", "(", "'allow_url_fopen'", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'allow_url_fopen must enabled'", ")", ";", "}", "if", "(", "!", "$", "fileData", "=", "file_get_contents", "(", "$", "httpFile", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Can nat get file content'", ")", ";", "}", "$", "parseFile", "=", "$", "this", "->", "parseLastDirectory", "(", "$", "remote", ")", ";", "if", "(", "!", "file_put_contents", "(", "$", "this", "->", "getWrapper", "(", "\"/$parseFile\"", ")", ",", "$", "fileData", ")", ")", "{", "throw", "new", "FileException", "(", "'File not uploaded to ftp server'", ")", ";", "}", "return", "true", ";", "}" ]
Upload file to ssh server from http address @access public @param string $httpFile http file name with address @param string $remote file name to upload ssh server @return boolean true if success @throws FileException|RuntimeException
[ "Upload", "file", "to", "ssh", "server", "from", "http", "address" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/Files/SftpFile.php#L78-L91
train
rtconner/freshbooks-api
src/Freshbooks/XmlDomConstruct.php
XmlDomConstruct.fromMixed
public function fromMixed($mixed, DOMElement $domElement = null) { $domElement = is_null($domElement) ? $this : $domElement; if (is_array($mixed)) { foreach( $mixed as $index => $mixedElement ) { if ( is_int($index) ) { if ( $index == 0 ) { $node = $domElement; } else { $node = $this->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $node = $this->createElement($index); $domElement->appendChild($node); } $this->fromMixed($mixedElement, $node); } } else { $domElement->appendChild($this->createTextNode($mixed)); } }
php
public function fromMixed($mixed, DOMElement $domElement = null) { $domElement = is_null($domElement) ? $this : $domElement; if (is_array($mixed)) { foreach( $mixed as $index => $mixedElement ) { if ( is_int($index) ) { if ( $index == 0 ) { $node = $domElement; } else { $node = $this->createElement($domElement->tagName); $domElement->parentNode->appendChild($node); } } else { $node = $this->createElement($index); $domElement->appendChild($node); } $this->fromMixed($mixedElement, $node); } } else { $domElement->appendChild($this->createTextNode($mixed)); } }
[ "public", "function", "fromMixed", "(", "$", "mixed", ",", "DOMElement", "$", "domElement", "=", "null", ")", "{", "$", "domElement", "=", "is_null", "(", "$", "domElement", ")", "?", "$", "this", ":", "$", "domElement", ";", "if", "(", "is_array", "(", "$", "mixed", ")", ")", "{", "foreach", "(", "$", "mixed", "as", "$", "index", "=>", "$", "mixedElement", ")", "{", "if", "(", "is_int", "(", "$", "index", ")", ")", "{", "if", "(", "$", "index", "==", "0", ")", "{", "$", "node", "=", "$", "domElement", ";", "}", "else", "{", "$", "node", "=", "$", "this", "->", "createElement", "(", "$", "domElement", "->", "tagName", ")", ";", "$", "domElement", "->", "parentNode", "->", "appendChild", "(", "$", "node", ")", ";", "}", "}", "else", "{", "$", "node", "=", "$", "this", "->", "createElement", "(", "$", "index", ")", ";", "$", "domElement", "->", "appendChild", "(", "$", "node", ")", ";", "}", "$", "this", "->", "fromMixed", "(", "$", "mixedElement", ",", "$", "node", ")", ";", "}", "}", "else", "{", "$", "domElement", "->", "appendChild", "(", "$", "this", "->", "createTextNode", "(", "$", "mixed", ")", ")", ";", "}", "}" ]
CONSTRUCTS ELEMENTS AND TEXTS FROM AN ARRAY OR STRING. THE ARRAY CAN CONTAIN AN ELEMENT'S NAME IN THE INDEX PART AND AN ELEMENT'S TEXT IN THE VALUE PART. IT CAN ALSO CREATES AN XML WITH THE SAME ELEMENT TAGNAME ON THE SAME LEVEL. EX: <NODES> <NODE>TEXT</NODE> <NODE> <FIELD>HELLO</FIELD> <FIELD>WORLD</FIELD> </NODE> </NODES> ARRAY SHOULD THEN LOOK LIKE: ARRAY ( "NODES" => ARRAY ( "NODE" => ARRAY ( 0 => "TEXT" 1 => ARRAY ( "FIELD" => ARRAY ( 0 => "HELLO" 1 => "WORLD" ) ) ) ) ) @PARAM MIXED $MIXED AN ARRAY OR STRING. @PARAM DOMELEMENT[OPTIONAL] $DOMELEMENT THEN ELEMENT FROM WHERE THE ARRAY WILL BE CONSTRUCT TO.
[ "CONSTRUCTS", "ELEMENTS", "AND", "TEXTS", "FROM", "AN", "ARRAY", "OR", "STRING", ".", "THE", "ARRAY", "CAN", "CONTAIN", "AN", "ELEMENT", "S", "NAME", "IN", "THE", "INDEX", "PART", "AND", "AN", "ELEMENT", "S", "TEXT", "IN", "THE", "VALUE", "PART", "." ]
04488ee8e804bc3184deb04d457cd36857f24161
https://github.com/rtconner/freshbooks-api/blob/04488ee8e804bc3184deb04d457cd36857f24161/src/Freshbooks/XmlDomConstruct.php#L52-L80
train
altayalp/php-ftp-client
src/DirectoryFactory.php
DirectoryFactory.build
public static function build(ServerInterface $server) { if ($server instanceof SftpServer) { return new SftpDirectory($server); } elseif ($server instanceof FtpServer || $server instanceof SslServer) { return new FtpDirectory($server); } else { throw new \InvalidArgumentException('The argument is must instance of server class'); } }
php
public static function build(ServerInterface $server) { if ($server instanceof SftpServer) { return new SftpDirectory($server); } elseif ($server instanceof FtpServer || $server instanceof SslServer) { return new FtpDirectory($server); } else { throw new \InvalidArgumentException('The argument is must instance of server class'); } }
[ "public", "static", "function", "build", "(", "ServerInterface", "$", "server", ")", "{", "if", "(", "$", "server", "instanceof", "SftpServer", ")", "{", "return", "new", "SftpDirectory", "(", "$", "server", ")", ";", "}", "elseif", "(", "$", "server", "instanceof", "FtpServer", "||", "$", "server", "instanceof", "SslServer", ")", "{", "return", "new", "FtpDirectory", "(", "$", "server", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The argument is must instance of server class'", ")", ";", "}", "}" ]
Build method for Directory classes
[ "Build", "method", "for", "Directory", "classes" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/DirectoryFactory.php#L28-L37
train
altayalp/php-ftp-client
src/FileFactory.php
FileFactory.build
public static function build(ServerInterface $server) { if ($server instanceof SftpServer) { return new SftpFile($server); } elseif ($server instanceof FtpServer || $server instanceof SslServer) { return new FtpFile($server); } else { throw new \InvalidArgumentException('The argument is must instance of server class'); } }
php
public static function build(ServerInterface $server) { if ($server instanceof SftpServer) { return new SftpFile($server); } elseif ($server instanceof FtpServer || $server instanceof SslServer) { return new FtpFile($server); } else { throw new \InvalidArgumentException('The argument is must instance of server class'); } }
[ "public", "static", "function", "build", "(", "ServerInterface", "$", "server", ")", "{", "if", "(", "$", "server", "instanceof", "SftpServer", ")", "{", "return", "new", "SftpFile", "(", "$", "server", ")", ";", "}", "elseif", "(", "$", "server", "instanceof", "FtpServer", "||", "$", "server", "instanceof", "SslServer", ")", "{", "return", "new", "FtpFile", "(", "$", "server", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The argument is must instance of server class'", ")", ";", "}", "}" ]
Build method for File classes
[ "Build", "method", "for", "File", "classes" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/FileFactory.php#L29-L38
train
web-token/jwt-key-mgmt
JWKFactory.php
JWKFactory.createFromJsonObject
public static function createFromJsonObject(string $value) { $json = \json_decode($value, true); if (!\is_array($json)) { throw new \InvalidArgumentException('Invalid key or key set.'); } return self::createFromValues($json); }
php
public static function createFromJsonObject(string $value) { $json = \json_decode($value, true); if (!\is_array($json)) { throw new \InvalidArgumentException('Invalid key or key set.'); } return self::createFromValues($json); }
[ "public", "static", "function", "createFromJsonObject", "(", "string", "$", "value", ")", "{", "$", "json", "=", "\\", "json_decode", "(", "$", "value", ",", "true", ")", ";", "if", "(", "!", "\\", "is_array", "(", "$", "json", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid key or key set.'", ")", ";", "}", "return", "self", "::", "createFromValues", "(", "$", "json", ")", ";", "}" ]
Creates a key from a Json string. @return JWK|JWKSet
[ "Creates", "a", "key", "from", "a", "Json", "string", "." ]
bb38879f51a55e76ed0e3d4f182c82267c390c9a
https://github.com/web-token/jwt-key-mgmt/blob/bb38879f51a55e76ed0e3d4f182c82267c390c9a/JWKFactory.php#L227-L235
train
web-token/jwt-key-mgmt
JWKFactory.php
JWKFactory.createFromValues
public static function createFromValues(array $values) { if (\array_key_exists('keys', $values) && \is_array($values['keys'])) { return JWKSet::createFromKeyData($values); } return JWK::create($values); }
php
public static function createFromValues(array $values) { if (\array_key_exists('keys', $values) && \is_array($values['keys'])) { return JWKSet::createFromKeyData($values); } return JWK::create($values); }
[ "public", "static", "function", "createFromValues", "(", "array", "$", "values", ")", "{", "if", "(", "\\", "array_key_exists", "(", "'keys'", ",", "$", "values", ")", "&&", "\\", "is_array", "(", "$", "values", "[", "'keys'", "]", ")", ")", "{", "return", "JWKSet", "::", "createFromKeyData", "(", "$", "values", ")", ";", "}", "return", "JWK", "::", "create", "(", "$", "values", ")", ";", "}" ]
Creates a key or key set from the given input. @return JWK|JWKSet
[ "Creates", "a", "key", "or", "key", "set", "from", "the", "given", "input", "." ]
bb38879f51a55e76ed0e3d4f182c82267c390c9a
https://github.com/web-token/jwt-key-mgmt/blob/bb38879f51a55e76ed0e3d4f182c82267c390c9a/JWKFactory.php#L242-L249
train
web-token/jwt-key-mgmt
JWKFactory.php
JWKFactory.createFromSecret
public static function createFromSecret(string $secret, array $additional_values = []): JWK { $values = \array_merge( $additional_values, [ 'kty' => 'oct', 'k' => Base64Url::encode($secret), ] ); return JWK::create($values); }
php
public static function createFromSecret(string $secret, array $additional_values = []): JWK { $values = \array_merge( $additional_values, [ 'kty' => 'oct', 'k' => Base64Url::encode($secret), ] ); return JWK::create($values); }
[ "public", "static", "function", "createFromSecret", "(", "string", "$", "secret", ",", "array", "$", "additional_values", "=", "[", "]", ")", ":", "JWK", "{", "$", "values", "=", "\\", "array_merge", "(", "$", "additional_values", ",", "[", "'kty'", "=>", "'oct'", ",", "'k'", "=>", "Base64Url", "::", "encode", "(", "$", "secret", ")", ",", "]", ")", ";", "return", "JWK", "::", "create", "(", "$", "values", ")", ";", "}" ]
This method create a JWK object using a shared secret.
[ "This", "method", "create", "a", "JWK", "object", "using", "a", "shared", "secret", "." ]
bb38879f51a55e76ed0e3d4f182c82267c390c9a
https://github.com/web-token/jwt-key-mgmt/blob/bb38879f51a55e76ed0e3d4f182c82267c390c9a/JWKFactory.php#L254-L265
train
web-token/jwt-key-mgmt
JWKFactory.php
JWKFactory.createFromKeyFile
public static function createFromKeyFile(string $file, ?string $password = null, array $additional_values = []): JWK { $values = KeyConverter::loadFromKeyFile($file, $password); $values = \array_merge($values, $additional_values); return JWK::create($values); }
php
public static function createFromKeyFile(string $file, ?string $password = null, array $additional_values = []): JWK { $values = KeyConverter::loadFromKeyFile($file, $password); $values = \array_merge($values, $additional_values); return JWK::create($values); }
[ "public", "static", "function", "createFromKeyFile", "(", "string", "$", "file", ",", "?", "string", "$", "password", "=", "null", ",", "array", "$", "additional_values", "=", "[", "]", ")", ":", "JWK", "{", "$", "values", "=", "KeyConverter", "::", "loadFromKeyFile", "(", "$", "file", ",", "$", "password", ")", ";", "$", "values", "=", "\\", "array_merge", "(", "$", "values", ",", "$", "additional_values", ")", ";", "return", "JWK", "::", "create", "(", "$", "values", ")", ";", "}" ]
This method will try to load and convert a key file into a JWK object. If the key is encrypted, the password must be set. @throws \Exception
[ "This", "method", "will", "try", "to", "load", "and", "convert", "a", "key", "file", "into", "a", "JWK", "object", ".", "If", "the", "key", "is", "encrypted", "the", "password", "must", "be", "set", "." ]
bb38879f51a55e76ed0e3d4f182c82267c390c9a
https://github.com/web-token/jwt-key-mgmt/blob/bb38879f51a55e76ed0e3d4f182c82267c390c9a/JWKFactory.php#L335-L341
train
web-token/jwt-key-mgmt
JWKFactory.php
JWKFactory.createFromKey
public static function createFromKey(string $key, ?string $password = null, array $additional_values = []): JWK { $values = KeyConverter::loadFromKey($key, $password); $values = \array_merge($values, $additional_values); return JWK::create($values); }
php
public static function createFromKey(string $key, ?string $password = null, array $additional_values = []): JWK { $values = KeyConverter::loadFromKey($key, $password); $values = \array_merge($values, $additional_values); return JWK::create($values); }
[ "public", "static", "function", "createFromKey", "(", "string", "$", "key", ",", "?", "string", "$", "password", "=", "null", ",", "array", "$", "additional_values", "=", "[", "]", ")", ":", "JWK", "{", "$", "values", "=", "KeyConverter", "::", "loadFromKey", "(", "$", "key", ",", "$", "password", ")", ";", "$", "values", "=", "\\", "array_merge", "(", "$", "values", ",", "$", "additional_values", ")", ";", "return", "JWK", "::", "create", "(", "$", "values", ")", ";", "}" ]
This method will try to load and convert a key into a JWK object. If the key is encrypted, the password must be set. @throws \Exception
[ "This", "method", "will", "try", "to", "load", "and", "convert", "a", "key", "into", "a", "JWK", "object", ".", "If", "the", "key", "is", "encrypted", "the", "password", "must", "be", "set", "." ]
bb38879f51a55e76ed0e3d4f182c82267c390c9a
https://github.com/web-token/jwt-key-mgmt/blob/bb38879f51a55e76ed0e3d4f182c82267c390c9a/JWKFactory.php#L349-L355
train
web-token/jwt-key-mgmt
JWKFactory.php
JWKFactory.createFromX5C
public static function createFromX5C(array $x5c, array $additional_values = []): JWK { $values = KeyConverter::loadFromX5C($x5c); $values = \array_merge($values, $additional_values); return JWK::create($values); }
php
public static function createFromX5C(array $x5c, array $additional_values = []): JWK { $values = KeyConverter::loadFromX5C($x5c); $values = \array_merge($values, $additional_values); return JWK::create($values); }
[ "public", "static", "function", "createFromX5C", "(", "array", "$", "x5c", ",", "array", "$", "additional_values", "=", "[", "]", ")", ":", "JWK", "{", "$", "values", "=", "KeyConverter", "::", "loadFromX5C", "(", "$", "x5c", ")", ";", "$", "values", "=", "\\", "array_merge", "(", "$", "values", ",", "$", "additional_values", ")", ";", "return", "JWK", "::", "create", "(", "$", "values", ")", ";", "}" ]
This method will try to load and convert a X.509 certificate chain into a public key.
[ "This", "method", "will", "try", "to", "load", "and", "convert", "a", "X", ".", "509", "certificate", "chain", "into", "a", "public", "key", "." ]
bb38879f51a55e76ed0e3d4f182c82267c390c9a
https://github.com/web-token/jwt-key-mgmt/blob/bb38879f51a55e76ed0e3d4f182c82267c390c9a/JWKFactory.php#L360-L366
train
altayalp/php-ftp-client
src/Helper/Helper.php
Helper.formatByte
public static function formatByte($byte) { // ignore "Warning: Division by zero" if ($byte == 0) { return '0 B'; } $s = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb'); $e = floor(log($byte)/log(1024)); return sprintf('%.2f '.$s[$e], ($byte/pow(1024, floor($e)))); }
php
public static function formatByte($byte) { // ignore "Warning: Division by zero" if ($byte == 0) { return '0 B'; } $s = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb'); $e = floor(log($byte)/log(1024)); return sprintf('%.2f '.$s[$e], ($byte/pow(1024, floor($e)))); }
[ "public", "static", "function", "formatByte", "(", "$", "byte", ")", "{", "// ignore \"Warning: Division by zero\"", "if", "(", "$", "byte", "==", "0", ")", "{", "return", "'0 B'", ";", "}", "$", "s", "=", "array", "(", "'B'", ",", "'Kb'", ",", "'Mb'", ",", "'Gb'", ",", "'Tb'", ",", "'Pb'", ")", ";", "$", "e", "=", "floor", "(", "log", "(", "$", "byte", ")", "/", "log", "(", "1024", ")", ")", ";", "return", "sprintf", "(", "'%.2f '", ".", "$", "s", "[", "$", "e", "]", ",", "(", "$", "byte", "/", "pow", "(", "1024", ",", "floor", "(", "$", "e", ")", ")", ")", ")", ";", "}" ]
Format file size to human readable @access public @param int $byte byte of file size @return strıng formatted file size
[ "Format", "file", "size", "to", "human", "readable" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/Helper/Helper.php#L26-L35
train
borNfreee/tactician-domain-events
src/Middleware/ReleaseRecordedEventsMiddleware.php
ReleaseRecordedEventsMiddleware.execute
public function execute($command, callable $next) { try { $result = $next($command); } catch (\Exception $exception) { $this->eventRecorder->eraseEvents(); throw $exception; } $recordedEvents = $this->eventRecorder->releaseEvents(); foreach ($recordedEvents as $event) { $this->eventDispatcher->dispatch($event); } return $result; }
php
public function execute($command, callable $next) { try { $result = $next($command); } catch (\Exception $exception) { $this->eventRecorder->eraseEvents(); throw $exception; } $recordedEvents = $this->eventRecorder->releaseEvents(); foreach ($recordedEvents as $event) { $this->eventDispatcher->dispatch($event); } return $result; }
[ "public", "function", "execute", "(", "$", "command", ",", "callable", "$", "next", ")", "{", "try", "{", "$", "result", "=", "$", "next", "(", "$", "command", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "this", "->", "eventRecorder", "->", "eraseEvents", "(", ")", ";", "throw", "$", "exception", ";", "}", "$", "recordedEvents", "=", "$", "this", "->", "eventRecorder", "->", "releaseEvents", "(", ")", ";", "foreach", "(", "$", "recordedEvents", "as", "$", "event", ")", "{", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "$", "event", ")", ";", "}", "return", "$", "result", ";", "}" ]
Dispatches all the recorded events in the EventBus and erases them @param object $command @param callable $next @return mixed @throws \Exception
[ "Dispatches", "all", "the", "recorded", "events", "in", "the", "EventBus", "and", "erases", "them" ]
ab9eaa71eae3eafd8c1f5f2be20ab03bd95eeaef
https://github.com/borNfreee/tactician-domain-events/blob/ab9eaa71eae3eafd8c1f5f2be20ab03bd95eeaef/src/Middleware/ReleaseRecordedEventsMiddleware.php#L43-L60
train
altayalp/php-ftp-client
src/FtpTrait.php
FtpTrait.ignoreItem
private function ignoreItem($type, $name, $ignore) { if ($type == 'file' && in_array(pathinfo($name, PATHINFO_EXTENSION), $ignore)) { return true; } elseif ($type == 'dir' && in_array($name, $ignore)) { return true; } return false; }
php
private function ignoreItem($type, $name, $ignore) { if ($type == 'file' && in_array(pathinfo($name, PATHINFO_EXTENSION), $ignore)) { return true; } elseif ($type == 'dir' && in_array($name, $ignore)) { return true; } return false; }
[ "private", "function", "ignoreItem", "(", "$", "type", ",", "$", "name", ",", "$", "ignore", ")", "{", "if", "(", "$", "type", "==", "'file'", "&&", "in_array", "(", "pathinfo", "(", "$", "name", ",", "PATHINFO_EXTENSION", ")", ",", "$", "ignore", ")", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "type", "==", "'dir'", "&&", "in_array", "(", "$", "name", ",", "$", "ignore", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Ignore item to itemList @access private @param string $type Type of item @param string $name Name of item @param array $ignore Names or extension item for ignore @return boolean
[ "Ignore", "item", "to", "itemList" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/FtpTrait.php#L27-L35
train
hiqdev/payment-icons
src/console/DoController.php
DoController.fetchUniqueIconsList
public function fetchUniqueIconsList() { $md5s = []; foreach ($this->getIconsList() as $path => $name) { $hash = md5_file($path); if (in_array($hash, $md5s, true)) { continue; } $md5s[$path] = $hash; $list[$path] = $name; } return $list; }
php
public function fetchUniqueIconsList() { $md5s = []; foreach ($this->getIconsList() as $path => $name) { $hash = md5_file($path); if (in_array($hash, $md5s, true)) { continue; } $md5s[$path] = $hash; $list[$path] = $name; } return $list; }
[ "public", "function", "fetchUniqueIconsList", "(", ")", "{", "$", "md5s", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getIconsList", "(", ")", "as", "$", "path", "=>", "$", "name", ")", "{", "$", "hash", "=", "md5_file", "(", "$", "path", ")", ";", "if", "(", "in_array", "(", "$", "hash", ",", "$", "md5s", ",", "true", ")", ")", "{", "continue", ";", "}", "$", "md5s", "[", "$", "path", "]", "=", "$", "hash", ";", "$", "list", "[", "$", "path", "]", "=", "$", "name", ";", "}", "return", "$", "list", ";", "}" ]
Fetches list of unique icons. @return array
[ "Fetches", "list", "of", "unique", "icons", "." ]
223d0b19300dde5f94d3e290576899ed808eff77
https://github.com/hiqdev/payment-icons/blob/223d0b19300dde5f94d3e290576899ed808eff77/src/console/DoController.php#L38-L51
train
hiqdev/payment-icons
src/console/DoController.php
DoController.fetchIconsList
public function fetchIconsList() { $dir = Yii::getAlias('@hiqdev/paymenticons/assets/png/xs'); $files = scandir($dir); $list = []; foreach ($files as $file) { if ($file[0] === '.') { continue; } $name = pathinfo($file)['filename']; $list["$dir/$file"] = $name; } return $list; }
php
public function fetchIconsList() { $dir = Yii::getAlias('@hiqdev/paymenticons/assets/png/xs'); $files = scandir($dir); $list = []; foreach ($files as $file) { if ($file[0] === '.') { continue; } $name = pathinfo($file)['filename']; $list["$dir/$file"] = $name; } return $list; }
[ "public", "function", "fetchIconsList", "(", ")", "{", "$", "dir", "=", "Yii", "::", "getAlias", "(", "'@hiqdev/paymenticons/assets/png/xs'", ")", ";", "$", "files", "=", "scandir", "(", "$", "dir", ")", ";", "$", "list", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "[", "0", "]", "===", "'.'", ")", "{", "continue", ";", "}", "$", "name", "=", "pathinfo", "(", "$", "file", ")", "[", "'filename'", "]", ";", "$", "list", "[", "\"$dir/$file\"", "]", "=", "$", "name", ";", "}", "return", "$", "list", ";", "}" ]
Scans directory to prepare list of icons. @return array
[ "Scans", "directory", "to", "prepare", "list", "of", "icons", "." ]
223d0b19300dde5f94d3e290576899ed808eff77
https://github.com/hiqdev/payment-icons/blob/223d0b19300dde5f94d3e290576899ed808eff77/src/console/DoController.php#L70-L84
train
hiqdev/payment-icons
src/console/DoController.php
DoController.genCss
public function genCss() { $sizes = [ 'xs' => 'height: 38px; width: 60px;', 'sm' => 'height: 75px; width: 120px;', 'md' => 'height: 240px; width: 150px;', 'lg' => 'height: 480px; width: 300px;', ]; $res = '.pi { display: inline-block;height: 38px;width: 60px; }' . PHP_EOL; foreach (array_keys($sizes) as $size) { $res .= ".pi.pi-$size { $sizes[$size] }" . PHP_EOL; } foreach (array_keys($sizes) as $size) { foreach ($this->getIconsList() as $name) { if ($size === 'xs') { $res .= ".pi.pi-$size.pi-$name, .pi.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL; } else { $res .= ".pi.pi-$size.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL; } } $res .= PHP_EOL; } return $res; }
php
public function genCss() { $sizes = [ 'xs' => 'height: 38px; width: 60px;', 'sm' => 'height: 75px; width: 120px;', 'md' => 'height: 240px; width: 150px;', 'lg' => 'height: 480px; width: 300px;', ]; $res = '.pi { display: inline-block;height: 38px;width: 60px; }' . PHP_EOL; foreach (array_keys($sizes) as $size) { $res .= ".pi.pi-$size { $sizes[$size] }" . PHP_EOL; } foreach (array_keys($sizes) as $size) { foreach ($this->getIconsList() as $name) { if ($size === 'xs') { $res .= ".pi.pi-$size.pi-$name, .pi.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL; } else { $res .= ".pi.pi-$size.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL; } } $res .= PHP_EOL; } return $res; }
[ "public", "function", "genCss", "(", ")", "{", "$", "sizes", "=", "[", "'xs'", "=>", "'height: 38px; width: 60px;'", ",", "'sm'", "=>", "'height: 75px; width: 120px;'", ",", "'md'", "=>", "'height: 240px; width: 150px;'", ",", "'lg'", "=>", "'height: 480px; width: 300px;'", ",", "]", ";", "$", "res", "=", "'.pi { display: inline-block;height: 38px;width: 60px; }'", ".", "PHP_EOL", ";", "foreach", "(", "array_keys", "(", "$", "sizes", ")", "as", "$", "size", ")", "{", "$", "res", ".=", "\".pi.pi-$size { $sizes[$size] }\"", ".", "PHP_EOL", ";", "}", "foreach", "(", "array_keys", "(", "$", "sizes", ")", "as", "$", "size", ")", "{", "foreach", "(", "$", "this", "->", "getIconsList", "(", ")", "as", "$", "name", ")", "{", "if", "(", "$", "size", "===", "'xs'", ")", "{", "$", "res", ".=", "\".pi.pi-$size.pi-$name, .pi.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }\"", ".", "PHP_EOL", ";", "}", "else", "{", "$", "res", ".=", "\".pi.pi-$size.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }\"", ".", "PHP_EOL", ";", "}", "}", "$", "res", ".=", "PHP_EOL", ";", "}", "return", "$", "res", ";", "}" ]
Generates CSS file. @return string
[ "Generates", "CSS", "file", "." ]
223d0b19300dde5f94d3e290576899ed808eff77
https://github.com/hiqdev/payment-icons/blob/223d0b19300dde5f94d3e290576899ed808eff77/src/console/DoController.php#L90-L117
train
altayalp/php-ftp-client
src/Files/FtpFile.php
FtpFile.wget
public function wget($httpFile, $remote, $mode = FTP_BINARY) { if (! ini_get('allow_url_fopen')) { throw new \RuntimeException('allow_url_fopen must enabled'); } if (! $handle = fopen($httpFile)) { throw new \RuntimeException('File can not opened'); } if (! ftp_fput($this->session, $remote, $handle, $mode) ) { throw new FileException('File not uploaded to ftp server'); } fclose($handle); return true; }
php
public function wget($httpFile, $remote, $mode = FTP_BINARY) { if (! ini_get('allow_url_fopen')) { throw new \RuntimeException('allow_url_fopen must enabled'); } if (! $handle = fopen($httpFile)) { throw new \RuntimeException('File can not opened'); } if (! ftp_fput($this->session, $remote, $handle, $mode) ) { throw new FileException('File not uploaded to ftp server'); } fclose($handle); return true; }
[ "public", "function", "wget", "(", "$", "httpFile", ",", "$", "remote", ",", "$", "mode", "=", "FTP_BINARY", ")", "{", "if", "(", "!", "ini_get", "(", "'allow_url_fopen'", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'allow_url_fopen must enabled'", ")", ";", "}", "if", "(", "!", "$", "handle", "=", "fopen", "(", "$", "httpFile", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'File can not opened'", ")", ";", "}", "if", "(", "!", "ftp_fput", "(", "$", "this", "->", "session", ",", "$", "remote", ",", "$", "handle", ",", "$", "mode", ")", ")", "{", "throw", "new", "FileException", "(", "'File not uploaded to ftp server'", ")", ";", "}", "fclose", "(", "$", "handle", ")", ";", "return", "true", ";", "}" ]
Upload file to ftp server from http address @link http://php.net/ftp_fput Php manuel @access public @param string $httpFile http file name with address @param string $remote file name to upload ftp server @param string $mode Upload mode FTP_BINARY or FTP_ASCII @return boolean true if success @throws FileException|RuntimeException
[ "Upload", "file", "to", "ftp", "server", "from", "http", "address" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/Files/FtpFile.php#L78-L91
train
altayalp/php-ftp-client
src/Abstracts/AbstractSftp.php
AbstractSftp.listItem
protected function listItem($type, $dir = '/.', $recursive = false, $ignore = array()) { if ($type == 'dir') { $bool = true; } elseif ($type == 'file') { $bool = false; } else { throw new \InvalidArgumentException('$type must "file" or "dir"'); } $parseDir = $this->parseLastDirectory($dir); $sDir = $this->getWrapper($parseDir); $fileList = array_diff(scandir($sDir), array('..', '.')); $fileInfo = array(); foreach ($fileList as $file) { if ($this->ignoreItem($type, $file, $ignore) !== true && is_dir("$sDir/$file") === $bool) { $fileInfo[] = $file; } if ($recursive === true && is_dir("$sDir/$file") === true) { $fileInfo = array_merge($fileInfo, $this->listItem($type, "$dir/$file", $recursive, $ignore)); } } return $fileInfo; }
php
protected function listItem($type, $dir = '/.', $recursive = false, $ignore = array()) { if ($type == 'dir') { $bool = true; } elseif ($type == 'file') { $bool = false; } else { throw new \InvalidArgumentException('$type must "file" or "dir"'); } $parseDir = $this->parseLastDirectory($dir); $sDir = $this->getWrapper($parseDir); $fileList = array_diff(scandir($sDir), array('..', '.')); $fileInfo = array(); foreach ($fileList as $file) { if ($this->ignoreItem($type, $file, $ignore) !== true && is_dir("$sDir/$file") === $bool) { $fileInfo[] = $file; } if ($recursive === true && is_dir("$sDir/$file") === true) { $fileInfo = array_merge($fileInfo, $this->listItem($type, "$dir/$file", $recursive, $ignore)); } } return $fileInfo; }
[ "protected", "function", "listItem", "(", "$", "type", ",", "$", "dir", "=", "'/.'", ",", "$", "recursive", "=", "false", ",", "$", "ignore", "=", "array", "(", ")", ")", "{", "if", "(", "$", "type", "==", "'dir'", ")", "{", "$", "bool", "=", "true", ";", "}", "elseif", "(", "$", "type", "==", "'file'", ")", "{", "$", "bool", "=", "false", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$type must \"file\" or \"dir\"'", ")", ";", "}", "$", "parseDir", "=", "$", "this", "->", "parseLastDirectory", "(", "$", "dir", ")", ";", "$", "sDir", "=", "$", "this", "->", "getWrapper", "(", "$", "parseDir", ")", ";", "$", "fileList", "=", "array_diff", "(", "scandir", "(", "$", "sDir", ")", ",", "array", "(", "'..'", ",", "'.'", ")", ")", ";", "$", "fileInfo", "=", "array", "(", ")", ";", "foreach", "(", "$", "fileList", "as", "$", "file", ")", "{", "if", "(", "$", "this", "->", "ignoreItem", "(", "$", "type", ",", "$", "file", ",", "$", "ignore", ")", "!==", "true", "&&", "is_dir", "(", "\"$sDir/$file\"", ")", "===", "$", "bool", ")", "{", "$", "fileInfo", "[", "]", "=", "$", "file", ";", "}", "if", "(", "$", "recursive", "===", "true", "&&", "is_dir", "(", "\"$sDir/$file\"", ")", "===", "true", ")", "{", "$", "fileInfo", "=", "array_merge", "(", "$", "fileInfo", ",", "$", "this", "->", "listItem", "(", "$", "type", ",", "\"$dir/$file\"", ",", "$", "recursive", ",", "$", "ignore", ")", ")", ";", "}", "}", "return", "$", "fileInfo", ";", "}" ]
List of file @link http://php.net/scandir Php manuel @access public @param string $dir ssh directory name @return array file list @throws FileException
[ "List", "of", "file" ]
a31f1d5920dccbc719d038f6d2dd065c612f29f4
https://github.com/altayalp/php-ftp-client/blob/a31f1d5920dccbc719d038f6d2dd065c612f29f4/src/Abstracts/AbstractSftp.php#L153-L178
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_content.php
tl_content_c4g_maps.get_baselayers
public function get_baselayers(DataContainer $dc) { $id = 0; if ($dc->activeRecord->c4g_map_id != 0) { $id = $dc->activeRecord->c4g_map_id; } else { // take firstMapId, because it will be chosen as DEFAULT value for c4g_map_id $id = $this->firstMapId; } $profile = $this->Database->prepare( "SELECT b.baselayers ". "FROM tl_c4g_maps a, tl_c4g_map_profiles b ". "WHERE a.id = ? and a.profile = b.id") ->execute($id); $ids = deserialize($profile->baselayers,true); if (count($ids)>0) { $baseLayers = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers WHERE id IN (".implode(',',$ids).") ORDER BY name")->execute(); } else { $baseLayers = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name")->execute(); } if ($baseLayers->numRows > 0) { while ( $baseLayers->next () ) { $return [$baseLayers->id] = $baseLayers->name; } } return $return; }
php
public function get_baselayers(DataContainer $dc) { $id = 0; if ($dc->activeRecord->c4g_map_id != 0) { $id = $dc->activeRecord->c4g_map_id; } else { // take firstMapId, because it will be chosen as DEFAULT value for c4g_map_id $id = $this->firstMapId; } $profile = $this->Database->prepare( "SELECT b.baselayers ". "FROM tl_c4g_maps a, tl_c4g_map_profiles b ". "WHERE a.id = ? and a.profile = b.id") ->execute($id); $ids = deserialize($profile->baselayers,true); if (count($ids)>0) { $baseLayers = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers WHERE id IN (".implode(',',$ids).") ORDER BY name")->execute(); } else { $baseLayers = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name")->execute(); } if ($baseLayers->numRows > 0) { while ( $baseLayers->next () ) { $return [$baseLayers->id] = $baseLayers->name; } } return $return; }
[ "public", "function", "get_baselayers", "(", "DataContainer", "$", "dc", ")", "{", "$", "id", "=", "0", ";", "if", "(", "$", "dc", "->", "activeRecord", "->", "c4g_map_id", "!=", "0", ")", "{", "$", "id", "=", "$", "dc", "->", "activeRecord", "->", "c4g_map_id", ";", "}", "else", "{", "// take firstMapId, because it will be chosen as DEFAULT value for c4g_map_id", "$", "id", "=", "$", "this", "->", "firstMapId", ";", "}", "$", "profile", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT b.baselayers \"", ".", "\"FROM tl_c4g_maps a, tl_c4g_map_profiles b \"", ".", "\"WHERE a.id = ? and a.profile = b.id\"", ")", "->", "execute", "(", "$", "id", ")", ";", "$", "ids", "=", "deserialize", "(", "$", "profile", "->", "baselayers", ",", "true", ")", ";", "if", "(", "count", "(", "$", "ids", ")", ">", "0", ")", "{", "$", "baseLayers", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT id,name FROM tl_c4g_map_baselayers WHERE id IN (\"", ".", "implode", "(", "','", ",", "$", "ids", ")", ".", "\") ORDER BY name\"", ")", "->", "execute", "(", ")", ";", "}", "else", "{", "$", "baseLayers", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name\"", ")", "->", "execute", "(", ")", ";", "}", "if", "(", "$", "baseLayers", "->", "numRows", ">", "0", ")", "{", "while", "(", "$", "baseLayers", "->", "next", "(", ")", ")", "{", "$", "return", "[", "$", "baseLayers", "->", "id", "]", "=", "$", "baseLayers", "->", "name", ";", "}", "}", "return", "$", "return", ";", "}" ]
Return all base layers for current Map Profile as array @param object @return array
[ "Return", "all", "base", "layers", "for", "current", "Map", "Profile", "as", "array" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_content.php#L169-L199
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_content.php
tl_content_c4g_maps.get_maps
public function get_maps(DataContainer $dc) { $maps = $this->Database->prepare ( "SELECT * FROM tl_c4g_maps WHERE is_map=1 AND published=1" )->execute (); if ($maps->numRows > 0) { while ( $maps->next () ) { if (!isset($this->firstMapId)) { // save first map id $this->firstMapId = $maps->id; } $return [$maps->id] = $maps->name; } } return $return; }
php
public function get_maps(DataContainer $dc) { $maps = $this->Database->prepare ( "SELECT * FROM tl_c4g_maps WHERE is_map=1 AND published=1" )->execute (); if ($maps->numRows > 0) { while ( $maps->next () ) { if (!isset($this->firstMapId)) { // save first map id $this->firstMapId = $maps->id; } $return [$maps->id] = $maps->name; } } return $return; }
[ "public", "function", "get_maps", "(", "DataContainer", "$", "dc", ")", "{", "$", "maps", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT * FROM tl_c4g_maps WHERE is_map=1 AND published=1\"", ")", "->", "execute", "(", ")", ";", "if", "(", "$", "maps", "->", "numRows", ">", "0", ")", "{", "while", "(", "$", "maps", "->", "next", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "firstMapId", ")", ")", "{", "// save first map id", "$", "this", "->", "firstMapId", "=", "$", "maps", "->", "id", ";", "}", "$", "return", "[", "$", "maps", "->", "id", "]", "=", "$", "maps", "->", "name", ";", "}", "}", "return", "$", "return", ";", "}" ]
Return all defined maps @param object @return array
[ "Return", "all", "defined", "maps" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_content.php#L206-L219
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.getAllLocStyles
public function getAllLocStyles(DataContainer $dc) { $locStyles = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_locstyles ORDER BY name") ->execute(); while ($locStyles->next()) { $return[$locStyles->id] = $locStyles->name; } return $return; }
php
public function getAllLocStyles(DataContainer $dc) { $locStyles = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_locstyles ORDER BY name") ->execute(); while ($locStyles->next()) { $return[$locStyles->id] = $locStyles->name; } return $return; }
[ "public", "function", "getAllLocStyles", "(", "DataContainer", "$", "dc", ")", "{", "$", "locStyles", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT id,name FROM tl_c4g_map_locstyles ORDER BY name\"", ")", "->", "execute", "(", ")", ";", "while", "(", "$", "locStyles", "->", "next", "(", ")", ")", "{", "$", "return", "[", "$", "locStyles", "->", "id", "]", "=", "$", "locStyles", "->", "name", ";", "}", "return", "$", "return", ";", "}" ]
Return all Location Styles as array @param object @return array
[ "Return", "all", "Location", "Styles", "as", "array" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L987-L995
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.getAllBaseLayers
public function getAllBaseLayers(DataContainer $dc) { $baseLayers = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name") ->execute(); while ($baseLayers->next()) { $return[$baseLayers->id] = $baseLayers->name; } return $return; }
php
public function getAllBaseLayers(DataContainer $dc) { $baseLayers = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name") ->execute(); while ($baseLayers->next()) { $return[$baseLayers->id] = $baseLayers->name; } return $return; }
[ "public", "function", "getAllBaseLayers", "(", "DataContainer", "$", "dc", ")", "{", "$", "baseLayers", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT id,name FROM tl_c4g_map_baselayers ORDER BY name\"", ")", "->", "execute", "(", ")", ";", "while", "(", "$", "baseLayers", "->", "next", "(", ")", ")", "{", "$", "return", "[", "$", "baseLayers", "->", "id", "]", "=", "$", "baseLayers", "->", "name", ";", "}", "return", "$", "return", ";", "}" ]
Return all Base Layers as array @param object @return array
[ "Return", "all", "Base", "Layers", "as", "array" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1002-L1010
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.updateDCA
public function updateDCA(DataContainer $dc) { if (!$dc->id) { return; } $objProfile = $this->Database->prepare("SELECT zoom_panel, geosearch_engine, be_optimize_checkboxes_limit FROM tl_c4g_map_profiles WHERE id=?") ->limit(1) ->execute($dc->id); if ($objProfile->numRows > 0) { if ($objProfile->geosearch_engine == '2') { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch'] = str_replace('geosearch_engine,','geosearch_engine,geosearch_key,', $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch']); // make key-field mandatory $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['geosearch_key']['eval']['mandatory'] = true; } elseif ($objProfile->geosearch_engine == '3') { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch'] = str_replace('geosearch_engine,','geosearch_engine,geosearch_customengine_url,geosearch_customengine_attribution,geosearch_key,', $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch']); } elseif ($objProfile->geosearch_engine == '4') { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch'] = str_replace('geosearch_engine,','geosearch_engine,geosearch_key,', $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch']); } // convert checkboxes to chosenfields, if there are to many locationstyles if (intval($objProfile->be_optimize_checkboxes_limit) > 0) { // basemap-options $objLocCount = $this->Database->prepare("SELECT COUNT(id) AS entry_count FROM tl_c4g_map_baselayers")->execute(); if ($objLocCount->numRows > 0) { if (intval($objLocCount->entry_count) >= intval($objProfile->be_optimize_checkboxes_limit)) { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['baselayers']['inputType'] = 'select'; $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['baselayers']['eval']['chosen'] = true; } } // locationstyle-options $objLocCount = $this->Database->prepare("SELECT COUNT(id) AS entry_count FROM tl_c4g_map_locstyles")->execute(); if ($objLocCount->numRows > 0) { if (intval($objLocCount->entry_count) >= intval($objProfile->be_optimize_checkboxes_limit)) { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['locstyles']['inputType'] = 'select'; $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['locstyles']['eval']['chosen'] = true; } } } } }
php
public function updateDCA(DataContainer $dc) { if (!$dc->id) { return; } $objProfile = $this->Database->prepare("SELECT zoom_panel, geosearch_engine, be_optimize_checkboxes_limit FROM tl_c4g_map_profiles WHERE id=?") ->limit(1) ->execute($dc->id); if ($objProfile->numRows > 0) { if ($objProfile->geosearch_engine == '2') { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch'] = str_replace('geosearch_engine,','geosearch_engine,geosearch_key,', $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch']); // make key-field mandatory $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['geosearch_key']['eval']['mandatory'] = true; } elseif ($objProfile->geosearch_engine == '3') { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch'] = str_replace('geosearch_engine,','geosearch_engine,geosearch_customengine_url,geosearch_customengine_attribution,geosearch_key,', $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch']); } elseif ($objProfile->geosearch_engine == '4') { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch'] = str_replace('geosearch_engine,','geosearch_engine,geosearch_key,', $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['subpalettes']['geosearch']); } // convert checkboxes to chosenfields, if there are to many locationstyles if (intval($objProfile->be_optimize_checkboxes_limit) > 0) { // basemap-options $objLocCount = $this->Database->prepare("SELECT COUNT(id) AS entry_count FROM tl_c4g_map_baselayers")->execute(); if ($objLocCount->numRows > 0) { if (intval($objLocCount->entry_count) >= intval($objProfile->be_optimize_checkboxes_limit)) { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['baselayers']['inputType'] = 'select'; $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['baselayers']['eval']['chosen'] = true; } } // locationstyle-options $objLocCount = $this->Database->prepare("SELECT COUNT(id) AS entry_count FROM tl_c4g_map_locstyles")->execute(); if ($objLocCount->numRows > 0) { if (intval($objLocCount->entry_count) >= intval($objProfile->be_optimize_checkboxes_limit)) { $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['locstyles']['inputType'] = 'select'; $GLOBALS['TL_DCA']['tl_c4g_map_profiles']['fields']['locstyles']['eval']['chosen'] = true; } } } } }
[ "public", "function", "updateDCA", "(", "DataContainer", "$", "dc", ")", "{", "if", "(", "!", "$", "dc", "->", "id", ")", "{", "return", ";", "}", "$", "objProfile", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT zoom_panel, geosearch_engine, be_optimize_checkboxes_limit FROM tl_c4g_map_profiles WHERE id=?\"", ")", "->", "limit", "(", "1", ")", "->", "execute", "(", "$", "dc", "->", "id", ")", ";", "if", "(", "$", "objProfile", "->", "numRows", ">", "0", ")", "{", "if", "(", "$", "objProfile", "->", "geosearch_engine", "==", "'2'", ")", "{", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'subpalettes'", "]", "[", "'geosearch'", "]", "=", "str_replace", "(", "'geosearch_engine,'", ",", "'geosearch_engine,geosearch_key,'", ",", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'subpalettes'", "]", "[", "'geosearch'", "]", ")", ";", "// make key-field mandatory", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'fields'", "]", "[", "'geosearch_key'", "]", "[", "'eval'", "]", "[", "'mandatory'", "]", "=", "true", ";", "}", "elseif", "(", "$", "objProfile", "->", "geosearch_engine", "==", "'3'", ")", "{", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'subpalettes'", "]", "[", "'geosearch'", "]", "=", "str_replace", "(", "'geosearch_engine,'", ",", "'geosearch_engine,geosearch_customengine_url,geosearch_customengine_attribution,geosearch_key,'", ",", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'subpalettes'", "]", "[", "'geosearch'", "]", ")", ";", "}", "elseif", "(", "$", "objProfile", "->", "geosearch_engine", "==", "'4'", ")", "{", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'subpalettes'", "]", "[", "'geosearch'", "]", "=", "str_replace", "(", "'geosearch_engine,'", ",", "'geosearch_engine,geosearch_key,'", ",", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'subpalettes'", "]", "[", "'geosearch'", "]", ")", ";", "}", "// convert checkboxes to chosenfields, if there are to many locationstyles", "if", "(", "intval", "(", "$", "objProfile", "->", "be_optimize_checkboxes_limit", ")", ">", "0", ")", "{", "// basemap-options", "$", "objLocCount", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT COUNT(id) AS entry_count FROM tl_c4g_map_baselayers\"", ")", "->", "execute", "(", ")", ";", "if", "(", "$", "objLocCount", "->", "numRows", ">", "0", ")", "{", "if", "(", "intval", "(", "$", "objLocCount", "->", "entry_count", ")", ">=", "intval", "(", "$", "objProfile", "->", "be_optimize_checkboxes_limit", ")", ")", "{", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'fields'", "]", "[", "'baselayers'", "]", "[", "'inputType'", "]", "=", "'select'", ";", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'fields'", "]", "[", "'baselayers'", "]", "[", "'eval'", "]", "[", "'chosen'", "]", "=", "true", ";", "}", "}", "// locationstyle-options", "$", "objLocCount", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT COUNT(id) AS entry_count FROM tl_c4g_map_locstyles\"", ")", "->", "execute", "(", ")", ";", "if", "(", "$", "objLocCount", "->", "numRows", ">", "0", ")", "{", "if", "(", "intval", "(", "$", "objLocCount", "->", "entry_count", ")", ">=", "intval", "(", "$", "objProfile", "->", "be_optimize_checkboxes_limit", ")", ")", "{", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'fields'", "]", "[", "'locstyles'", "]", "[", "'inputType'", "]", "=", "'select'", ";", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "'tl_c4g_map_profiles'", "]", "[", "'fields'", "]", "[", "'locstyles'", "]", "[", "'eval'", "]", "[", "'chosen'", "]", "=", "true", ";", "}", "}", "}", "}", "}" ]
Update the palette information that depend on other values
[ "Update", "the", "palette", "information", "that", "depend", "on", "other", "values" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1015-L1063
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.pickUrl
public function pickUrl(DataContainer $dc) { return ' <a href="contao/page.php?do='.Input::get('do').'&amp;table='.$dc->table.'&amp;field='.$dc->field.'&amp;value='.str_replace(array('{{link_url::', '}}'), '', $dc->value).'" title="'.specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']).'" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\''.specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MOD']['page'][0])).'\',\'url\':this.href,\'id\':\''.$dc->field.'\',\'tag\':\'ctrl_'.$dc->field . ((Input::get('act') == 'editAll') ? '_' . $dc->id : '').'\',\'self\':this});return false">' . $this->generateImage('pickpage.gif', $GLOBALS['TL_LANG']['MSC']['pagepicker'], 'style="vertical-align:top;cursor:pointer"') . '</a>'; }
php
public function pickUrl(DataContainer $dc) { return ' <a href="contao/page.php?do='.Input::get('do').'&amp;table='.$dc->table.'&amp;field='.$dc->field.'&amp;value='.str_replace(array('{{link_url::', '}}'), '', $dc->value).'" title="'.specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']).'" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\''.specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MOD']['page'][0])).'\',\'url\':this.href,\'id\':\''.$dc->field.'\',\'tag\':\'ctrl_'.$dc->field . ((Input::get('act') == 'editAll') ? '_' . $dc->id : '').'\',\'self\':this});return false">' . $this->generateImage('pickpage.gif', $GLOBALS['TL_LANG']['MSC']['pagepicker'], 'style="vertical-align:top;cursor:pointer"') . '</a>'; }
[ "public", "function", "pickUrl", "(", "DataContainer", "$", "dc", ")", "{", "return", "' <a href=\"contao/page.php?do='", ".", "Input", "::", "get", "(", "'do'", ")", ".", "'&amp;table='", ".", "$", "dc", "->", "table", ".", "'&amp;field='", ".", "$", "dc", "->", "field", ".", "'&amp;value='", ".", "str_replace", "(", "array", "(", "'{{link_url::'", ",", "'}}'", ")", ",", "''", ",", "$", "dc", "->", "value", ")", ".", "'\" title=\"'", ".", "specialchars", "(", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'MSC'", "]", "[", "'pagepicker'", "]", ")", ".", "'\" onclick=\"Backend.getScrollOffset();Backend.openModalSelector({\\'width\\':765,\\'title\\':\\''", ".", "specialchars", "(", "str_replace", "(", "\"'\"", ",", "\"\\\\'\"", ",", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'MOD'", "]", "[", "'page'", "]", "[", "0", "]", ")", ")", ".", "'\\',\\'url\\':this.href,\\'id\\':\\''", ".", "$", "dc", "->", "field", ".", "'\\',\\'tag\\':\\'ctrl_'", ".", "$", "dc", "->", "field", ".", "(", "(", "Input", "::", "get", "(", "'act'", ")", "==", "'editAll'", ")", "?", "'_'", ".", "$", "dc", "->", "id", ":", "''", ")", ".", "'\\',\\'self\\':this});return false\">'", ".", "$", "this", "->", "generateImage", "(", "'pickpage.gif'", ",", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'MSC'", "]", "[", "'pagepicker'", "]", ",", "'style=\"vertical-align:top;cursor:pointer\"'", ")", ".", "'</a>'", ";", "}" ]
Return the page pick wizard for the editor_helpurl @param DataContainer $dc
[ "Return", "the", "page", "pick", "wizard", "for", "the", "editor_helpurl" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1069-L1072
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.editLocationStyle
public function editLocationStyle(DataContainer $dc) { return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=c4g_map_locstyles&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(specialchars($GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][1]), $dc->value) . '" style="padding-left:3px" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][0], 'style="vertical-align:top"') . '</a>'; }
php
public function editLocationStyle(DataContainer $dc) { return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=c4g_map_locstyles&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(specialchars($GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][1]), $dc->value) . '" style="padding-left:3px" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][0], 'style="vertical-align:top"') . '</a>'; }
[ "public", "function", "editLocationStyle", "(", "DataContainer", "$", "dc", ")", "{", "return", "(", "$", "dc", "->", "value", "<", "1", ")", "?", "''", ":", "' <a href=\"contao/main.php?do=c4g_map_locstyles&amp;act=edit&amp;id='", ".", "$", "dc", "->", "value", ".", "'&amp;popup=1&amp;nb=1&amp;rt='", ".", "REQUEST_TOKEN", ".", "'\" title=\"'", ".", "sprintf", "(", "specialchars", "(", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'tl_c4g_maps'", "]", "[", "'editalias'", "]", "[", "1", "]", ")", ",", "$", "dc", "->", "value", ")", ".", "'\" style=\"padding-left:3px\" onclick=\"Backend.openModalIframe({\\'width\\':768,\\'title\\':\\''", ".", "specialchars", "(", "str_replace", "(", "\"'\"", ",", "\"\\\\'\"", ",", "sprintf", "(", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'tl_c4g_maps'", "]", "[", "'editalias'", "]", "[", "1", "]", ",", "$", "dc", "->", "value", ")", ")", ")", ".", "'\\',\\'url\\':this.href});return false\">'", ".", "Image", "::", "getHtml", "(", "'alias.gif'", ",", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'tl_c4g_maps'", "]", "[", "'editalias'", "]", "[", "0", "]", ",", "'style=\"vertical-align:top\"'", ")", ".", "'</a>'", ";", "}" ]
Return the edit location style wizard @param \DataContainer @return string
[ "Return", "the", "edit", "location", "style", "wizard" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1079-L1082
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.getAllThemes
public function getAllThemes() { $return = []; $themes = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_themes ORDER BY name") ->execute(); while ($themes->next()) { $return[$themes->id] = $themes->name; } return $return; }
php
public function getAllThemes() { $return = []; $themes = $this->Database->prepare("SELECT id,name FROM tl_c4g_map_themes ORDER BY name") ->execute(); while ($themes->next()) { $return[$themes->id] = $themes->name; } return $return; }
[ "public", "function", "getAllThemes", "(", ")", "{", "$", "return", "=", "[", "]", ";", "$", "themes", "=", "$", "this", "->", "Database", "->", "prepare", "(", "\"SELECT id,name FROM tl_c4g_map_themes ORDER BY name\"", ")", "->", "execute", "(", ")", ";", "while", "(", "$", "themes", "->", "next", "(", ")", ")", "{", "$", "return", "[", "$", "themes", "->", "id", "]", "=", "$", "themes", "->", "name", ";", "}", "return", "$", "return", ";", "}" ]
Return all themes as array @return array
[ "Return", "all", "themes", "as", "array" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1088-L1097
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.editModule
public function editModule(DataContainer $dc) { return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $dc->value) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $GLOBALS['TL_LANG']['tl_content']['editalias'][0]) . '</a>'; }
php
public function editModule(DataContainer $dc) { return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['tl_content']['editalias'][1]), $dc->value) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $GLOBALS['TL_LANG']['tl_content']['editalias'][0]) . '</a>'; }
[ "public", "function", "editModule", "(", "DataContainer", "$", "dc", ")", "{", "return", "(", "$", "dc", "->", "value", "<", "1", ")", "?", "''", ":", "' <a href=\"contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id='", ".", "$", "dc", "->", "value", ".", "'&amp;popup=1&amp;nb=1&amp;rt='", ".", "REQUEST_TOKEN", ".", "'\" title=\"'", ".", "sprintf", "(", "StringUtil", "::", "specialchars", "(", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'tl_content'", "]", "[", "'editalias'", "]", "[", "1", "]", ")", ",", "$", "dc", "->", "value", ")", ".", "'\" onclick=\"Backend.openModalIframe({\\'title\\':\\''", ".", "StringUtil", "::", "specialchars", "(", "str_replace", "(", "\"'\"", ",", "\"\\\\'\"", ",", "sprintf", "(", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'tl_content'", "]", "[", "'editalias'", "]", "[", "1", "]", ",", "$", "dc", "->", "value", ")", ")", ")", ".", "'\\',\\'url\\':this.href});return false\">'", ".", "Image", "::", "getHtml", "(", "'alias.svg'", ",", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'tl_content'", "]", "[", "'editalias'", "]", "[", "0", "]", ")", ".", "'</a>'", ";", "}" ]
Return the edit module wizard @param DataContainer $dc @return string
[ "Return", "the", "edit", "module", "wizard" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1106-L1109
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_map_profiles.php
tl_c4g_map_profiles.getModules
public function getModules() { $arrModules = []; $objModules = $this->Database->execute("SELECT m.id, m.name, t.name AS theme FROM tl_module m LEFT JOIN tl_theme t ON m.pid=t.id ORDER BY t.name, m.name"); while ($objModules->next()) { $arrModules[$objModules->theme][$objModules->id] = $objModules->name . ' (ID ' . $objModules->id . ')'; } return $arrModules; }
php
public function getModules() { $arrModules = []; $objModules = $this->Database->execute("SELECT m.id, m.name, t.name AS theme FROM tl_module m LEFT JOIN tl_theme t ON m.pid=t.id ORDER BY t.name, m.name"); while ($objModules->next()) { $arrModules[$objModules->theme][$objModules->id] = $objModules->name . ' (ID ' . $objModules->id . ')'; } return $arrModules; }
[ "public", "function", "getModules", "(", ")", "{", "$", "arrModules", "=", "[", "]", ";", "$", "objModules", "=", "$", "this", "->", "Database", "->", "execute", "(", "\"SELECT m.id, m.name, t.name AS theme FROM tl_module m LEFT JOIN tl_theme t ON m.pid=t.id ORDER BY t.name, m.name\"", ")", ";", "while", "(", "$", "objModules", "->", "next", "(", ")", ")", "{", "$", "arrModules", "[", "$", "objModules", "->", "theme", "]", "[", "$", "objModules", "->", "id", "]", "=", "$", "objModules", "->", "name", ".", "' (ID '", ".", "$", "objModules", "->", "id", ".", "')'", ";", "}", "return", "$", "arrModules", ";", "}" ]
Get all modules and return them as array @return array
[ "Get", "all", "modules", "and", "return", "them", "as", "array" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_map_profiles.php#L1116-L1127
train
Kuestenschmiede/MapsBundle
Resources/contao/classes/Utils.php
Utils.validateLon
public static function validateLon($value) { if (strpos($value, '{{') !== -1) { return true; } if (self::validateGeo($value)) { return (($value >= -180.0) && ($value <= 180.0)); } return false; }
php
public static function validateLon($value) { if (strpos($value, '{{') !== -1) { return true; } if (self::validateGeo($value)) { return (($value >= -180.0) && ($value <= 180.0)); } return false; }
[ "public", "static", "function", "validateLon", "(", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "value", ",", "'{{'", ")", "!==", "-", "1", ")", "{", "return", "true", ";", "}", "if", "(", "self", "::", "validateGeo", "(", "$", "value", ")", ")", "{", "return", "(", "(", "$", "value", ">=", "-", "180.0", ")", "&&", "(", "$", "value", "<=", "180.0", ")", ")", ";", "}", "return", "false", ";", "}" ]
Validate a longitude coordinate @param [type] $value [description] @return [type] [description]
[ "Validate", "a", "longitude", "coordinate" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/classes/Utils.php#L28-L37
train
Kuestenschmiede/MapsBundle
Resources/contao/classes/Utils.php
Utils.validateLat
public static function validateLat($value) { if (strpos($value, '{{') !== -1) { return true; } if (self::validateGeo($value)) { return (($value >= -90.0) && ($value <= 90.0)); } return false; }
php
public static function validateLat($value) { if (strpos($value, '{{') !== -1) { return true; } if (self::validateGeo($value)) { return (($value >= -90.0) && ($value <= 90.0)); } return false; }
[ "public", "static", "function", "validateLat", "(", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "value", ",", "'{{'", ")", "!==", "-", "1", ")", "{", "return", "true", ";", "}", "if", "(", "self", "::", "validateGeo", "(", "$", "value", ")", ")", "{", "return", "(", "(", "$", "value", ">=", "-", "90.0", ")", "&&", "(", "$", "value", "<=", "90.0", ")", ")", ";", "}", "return", "false", ";", "}" ]
Validate a latitude coordinate @param [type] $value [description] @return [type] [description]
[ "Validate", "a", "latitude", "coordinate" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/classes/Utils.php#L44-L53
train
Kuestenschmiede/MapsBundle
Resources/contao/classes/Utils.php
Utils.validateGeo
public static function validateGeo($value) { if (!isset($value)) { return false; } $value = floatval($value); if ($value == 0) { return false; } return true; }
php
public static function validateGeo($value) { if (!isset($value)) { return false; } $value = floatval($value); if ($value == 0) { return false; } return true; }
[ "public", "static", "function", "validateGeo", "(", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "$", "value", "=", "floatval", "(", "$", "value", ")", ";", "if", "(", "$", "value", "==", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validate a Geo Coordinate @param [type] $value [description] @return [type] [description]
[ "Validate", "a", "Geo", "Coordinate" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/classes/Utils.php#L60-L70
train
Kuestenschmiede/MapsBundle
Classes/Services/LayerService.php
LayerService.setChildHide
private function setChildHide($childList, $parentLayer) { $newChildList = []; if ($childList && $parentLayer) { foreach($childList as $index=>$child) { if ($parentLayer->data_hidelayer) { $child['hide'] = $parentLayer->data_hidelayer; if ($child['hasChilds']) { $child['childs'] = $this->setChildHide($child['childs'], $parentLayer); } } $newChildList[$index] = $child; } } return $newChildList; }
php
private function setChildHide($childList, $parentLayer) { $newChildList = []; if ($childList && $parentLayer) { foreach($childList as $index=>$child) { if ($parentLayer->data_hidelayer) { $child['hide'] = $parentLayer->data_hidelayer; if ($child['hasChilds']) { $child['childs'] = $this->setChildHide($child['childs'], $parentLayer); } } $newChildList[$index] = $child; } } return $newChildList; }
[ "private", "function", "setChildHide", "(", "$", "childList", ",", "$", "parentLayer", ")", "{", "$", "newChildList", "=", "[", "]", ";", "if", "(", "$", "childList", "&&", "$", "parentLayer", ")", "{", "foreach", "(", "$", "childList", "as", "$", "index", "=>", "$", "child", ")", "{", "if", "(", "$", "parentLayer", "->", "data_hidelayer", ")", "{", "$", "child", "[", "'hide'", "]", "=", "$", "parentLayer", "->", "data_hidelayer", ";", "if", "(", "$", "child", "[", "'hasChilds'", "]", ")", "{", "$", "child", "[", "'childs'", "]", "=", "$", "this", "->", "setChildHide", "(", "$", "child", "[", "'childs'", "]", ",", "$", "parentLayer", ")", ";", "}", "}", "$", "newChildList", "[", "$", "index", "]", "=", "$", "child", ";", "}", "}", "return", "$", "newChildList", ";", "}" ]
Private function to set the hide property of childs correctly. @param $childList @param $parentLayer @return array
[ "Private", "function", "to", "set", "the", "hide", "property", "of", "childs", "correctly", "." ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Classes/Services/LayerService.php#L280-L296
train
Kuestenschmiede/MapsBundle
Classes/Services/LayerService.php
LayerService.getChildsForLinkedLayer
private function getChildsForLinkedLayer($layerId, $parentLayer) { $childLayers = C4gMapsModel::findPublishedByPid($layerId); $arrLayerData['childs'] = []; foreach ($childLayers as $childLayer) { if ($childLayer->location_type !== "none") { // we reached the "bottom" of the tree leaf $childData = $this->parseLayer($childLayer); $childData['pid'] = $parentLayer->id; $arrLayerData['childs'][] = $childData; $arrLayerData['hide'] = $parentLayer->data_hidelayer; } else { $currentChildLayer = $this->parseLayer($childLayer); // set correct pid for the contentless element $currentChildLayer['pid'] = $parentLayer->id; // $childLayer is the acutal existing layer. $arrChildData = $this->getChildsForLinkedLayer($childLayer->id, (object) $currentChildLayer); $currentChildLayer['childs'] = $arrChildData['childs']; $currentChildLayer['content'] = []; $currentChildLayer['hasChilds'] = count($currentChildLayer['childs']) > 0; $currentChildLayer['childsCount'] = count($currentChildLayer['childs']); $arrLayerData['childs'][] = $currentChildLayer; } $arrLayerData['content'] = []; $arrLayerData['hasChilds'] = count($arrLayerData['childs']) > 0; $arrLayerData['childsCount'] = count($arrLayerData['childs']); } return $arrLayerData; }
php
private function getChildsForLinkedLayer($layerId, $parentLayer) { $childLayers = C4gMapsModel::findPublishedByPid($layerId); $arrLayerData['childs'] = []; foreach ($childLayers as $childLayer) { if ($childLayer->location_type !== "none") { // we reached the "bottom" of the tree leaf $childData = $this->parseLayer($childLayer); $childData['pid'] = $parentLayer->id; $arrLayerData['childs'][] = $childData; $arrLayerData['hide'] = $parentLayer->data_hidelayer; } else { $currentChildLayer = $this->parseLayer($childLayer); // set correct pid for the contentless element $currentChildLayer['pid'] = $parentLayer->id; // $childLayer is the acutal existing layer. $arrChildData = $this->getChildsForLinkedLayer($childLayer->id, (object) $currentChildLayer); $currentChildLayer['childs'] = $arrChildData['childs']; $currentChildLayer['content'] = []; $currentChildLayer['hasChilds'] = count($currentChildLayer['childs']) > 0; $currentChildLayer['childsCount'] = count($currentChildLayer['childs']); $arrLayerData['childs'][] = $currentChildLayer; } $arrLayerData['content'] = []; $arrLayerData['hasChilds'] = count($arrLayerData['childs']) > 0; $arrLayerData['childsCount'] = count($arrLayerData['childs']); } return $arrLayerData; }
[ "private", "function", "getChildsForLinkedLayer", "(", "$", "layerId", ",", "$", "parentLayer", ")", "{", "$", "childLayers", "=", "C4gMapsModel", "::", "findPublishedByPid", "(", "$", "layerId", ")", ";", "$", "arrLayerData", "[", "'childs'", "]", "=", "[", "]", ";", "foreach", "(", "$", "childLayers", "as", "$", "childLayer", ")", "{", "if", "(", "$", "childLayer", "->", "location_type", "!==", "\"none\"", ")", "{", "// we reached the \"bottom\" of the tree leaf", "$", "childData", "=", "$", "this", "->", "parseLayer", "(", "$", "childLayer", ")", ";", "$", "childData", "[", "'pid'", "]", "=", "$", "parentLayer", "->", "id", ";", "$", "arrLayerData", "[", "'childs'", "]", "[", "]", "=", "$", "childData", ";", "$", "arrLayerData", "[", "'hide'", "]", "=", "$", "parentLayer", "->", "data_hidelayer", ";", "}", "else", "{", "$", "currentChildLayer", "=", "$", "this", "->", "parseLayer", "(", "$", "childLayer", ")", ";", "// set correct pid for the contentless element", "$", "currentChildLayer", "[", "'pid'", "]", "=", "$", "parentLayer", "->", "id", ";", "// $childLayer is the acutal existing layer.", "$", "arrChildData", "=", "$", "this", "->", "getChildsForLinkedLayer", "(", "$", "childLayer", "->", "id", ",", "(", "object", ")", "$", "currentChildLayer", ")", ";", "$", "currentChildLayer", "[", "'childs'", "]", "=", "$", "arrChildData", "[", "'childs'", "]", ";", "$", "currentChildLayer", "[", "'content'", "]", "=", "[", "]", ";", "$", "currentChildLayer", "[", "'hasChilds'", "]", "=", "count", "(", "$", "currentChildLayer", "[", "'childs'", "]", ")", ">", "0", ";", "$", "currentChildLayer", "[", "'childsCount'", "]", "=", "count", "(", "$", "currentChildLayer", "[", "'childs'", "]", ")", ";", "$", "arrLayerData", "[", "'childs'", "]", "[", "]", "=", "$", "currentChildLayer", ";", "}", "$", "arrLayerData", "[", "'content'", "]", "=", "[", "]", ";", "$", "arrLayerData", "[", "'hasChilds'", "]", "=", "count", "(", "$", "arrLayerData", "[", "'childs'", "]", ")", ">", "0", ";", "$", "arrLayerData", "[", "'childsCount'", "]", "=", "count", "(", "$", "arrLayerData", "[", "'childs'", "]", ")", ";", "}", "return", "$", "arrLayerData", ";", "}" ]
Returns the linked structure. @param $layerId @param $parentLayer @return array
[ "Returns", "the", "linked", "structure", "." ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Classes/Services/LayerService.php#L413-L444
train
verbb/expanded-singles
src/services/SinglesList.php
SinglesList.createSinglesList
public function createSinglesList(RegisterElementSourcesEvent $event) { $singles[] = ['heading' => Craft::t('app', 'Singles')]; // Grab all the Singles $singleSections = Craft::$app->sections->getSectionsByType(Section::TYPE_SINGLE); // Create list of Singles foreach ($singleSections as $single) { $entry = null; // If this is a multi-site, we need to grab the first site-enabled entry // Kind of annoying we can't query multiple site ids, or _all_ sites // https://github.com/craftcms/cms/issues/2854 if (Craft::$app->getIsMultiSite()) { foreach (Craft::$app->getSites()->getAllSiteIds() as $key => $siteId) { $entry = Entry::find() ->siteId($siteId) ->status(null) ->sectionId($single->id) ->one(); if ($entry) { break; } } } else { $entry = Entry::find() ->status(null) ->sectionId($single->id) ->one(); } if ($entry && Craft::$app->getUser()->checkPermission('editEntries:' . $single->uid)) { $url = $entry->getCpEditUrl(); $singles[] = [ 'key' => 'single:' . $single->uid, 'label' => Craft::t('site', $single->name), 'sites' => $single->getSiteIds(), 'data' => [ 'url' => $url, 'handle' => $single->handle ], 'criteria' => [ 'sectionId' => $single->id, 'editable' => false, ] ]; } } // Replace original Singles link with new singles list array_splice($event->sources, 1, 1, $singles); // Insert some JS to go straight to single page when clicked - rather than listing in Index Table if (ExpandedSingles::$plugin->getSettings()->redirectToEntry) { $js = '$(function() {' . '$("#main-content #sidebar nav a[data-url]").each(function(i, e) {' . 'var link = "<a href=" + $(this).data("url") + ">" + $(this).text() + "</a>";' . '$(this).replaceWith($(link));' . '});' . '});'; Craft::$app->view->registerJs($js); } // Update our element indexes to use the same columns as the original singles items // $newSettings = []; // $settings = Craft::$app->getElementIndexes()->getSettings(Entry::class); // // Get the singles index info - if none exists, then no need to go further // $singlesSettings = $settings['sources']['singles'] ?? null; // if (!$singlesSettings) { // return; // } // foreach ($singles as $key => $single) { // if (isset($single['key'])) { // $newSettings[$single['key']] = $singlesSettings; // } // } // Craft::$app->getElementIndexes()->saveSettings(Entry::class, $newSettings); }
php
public function createSinglesList(RegisterElementSourcesEvent $event) { $singles[] = ['heading' => Craft::t('app', 'Singles')]; // Grab all the Singles $singleSections = Craft::$app->sections->getSectionsByType(Section::TYPE_SINGLE); // Create list of Singles foreach ($singleSections as $single) { $entry = null; // If this is a multi-site, we need to grab the first site-enabled entry // Kind of annoying we can't query multiple site ids, or _all_ sites // https://github.com/craftcms/cms/issues/2854 if (Craft::$app->getIsMultiSite()) { foreach (Craft::$app->getSites()->getAllSiteIds() as $key => $siteId) { $entry = Entry::find() ->siteId($siteId) ->status(null) ->sectionId($single->id) ->one(); if ($entry) { break; } } } else { $entry = Entry::find() ->status(null) ->sectionId($single->id) ->one(); } if ($entry && Craft::$app->getUser()->checkPermission('editEntries:' . $single->uid)) { $url = $entry->getCpEditUrl(); $singles[] = [ 'key' => 'single:' . $single->uid, 'label' => Craft::t('site', $single->name), 'sites' => $single->getSiteIds(), 'data' => [ 'url' => $url, 'handle' => $single->handle ], 'criteria' => [ 'sectionId' => $single->id, 'editable' => false, ] ]; } } // Replace original Singles link with new singles list array_splice($event->sources, 1, 1, $singles); // Insert some JS to go straight to single page when clicked - rather than listing in Index Table if (ExpandedSingles::$plugin->getSettings()->redirectToEntry) { $js = '$(function() {' . '$("#main-content #sidebar nav a[data-url]").each(function(i, e) {' . 'var link = "<a href=" + $(this).data("url") + ">" + $(this).text() + "</a>";' . '$(this).replaceWith($(link));' . '});' . '});'; Craft::$app->view->registerJs($js); } // Update our element indexes to use the same columns as the original singles items // $newSettings = []; // $settings = Craft::$app->getElementIndexes()->getSettings(Entry::class); // // Get the singles index info - if none exists, then no need to go further // $singlesSettings = $settings['sources']['singles'] ?? null; // if (!$singlesSettings) { // return; // } // foreach ($singles as $key => $single) { // if (isset($single['key'])) { // $newSettings[$single['key']] = $singlesSettings; // } // } // Craft::$app->getElementIndexes()->saveSettings(Entry::class, $newSettings); }
[ "public", "function", "createSinglesList", "(", "RegisterElementSourcesEvent", "$", "event", ")", "{", "$", "singles", "[", "]", "=", "[", "'heading'", "=>", "Craft", "::", "t", "(", "'app'", ",", "'Singles'", ")", "]", ";", "// Grab all the Singles", "$", "singleSections", "=", "Craft", "::", "$", "app", "->", "sections", "->", "getSectionsByType", "(", "Section", "::", "TYPE_SINGLE", ")", ";", "// Create list of Singles", "foreach", "(", "$", "singleSections", "as", "$", "single", ")", "{", "$", "entry", "=", "null", ";", "// If this is a multi-site, we need to grab the first site-enabled entry", "// Kind of annoying we can't query multiple site ids, or _all_ sites", "// https://github.com/craftcms/cms/issues/2854", "if", "(", "Craft", "::", "$", "app", "->", "getIsMultiSite", "(", ")", ")", "{", "foreach", "(", "Craft", "::", "$", "app", "->", "getSites", "(", ")", "->", "getAllSiteIds", "(", ")", "as", "$", "key", "=>", "$", "siteId", ")", "{", "$", "entry", "=", "Entry", "::", "find", "(", ")", "->", "siteId", "(", "$", "siteId", ")", "->", "status", "(", "null", ")", "->", "sectionId", "(", "$", "single", "->", "id", ")", "->", "one", "(", ")", ";", "if", "(", "$", "entry", ")", "{", "break", ";", "}", "}", "}", "else", "{", "$", "entry", "=", "Entry", "::", "find", "(", ")", "->", "status", "(", "null", ")", "->", "sectionId", "(", "$", "single", "->", "id", ")", "->", "one", "(", ")", ";", "}", "if", "(", "$", "entry", "&&", "Craft", "::", "$", "app", "->", "getUser", "(", ")", "->", "checkPermission", "(", "'editEntries:'", ".", "$", "single", "->", "uid", ")", ")", "{", "$", "url", "=", "$", "entry", "->", "getCpEditUrl", "(", ")", ";", "$", "singles", "[", "]", "=", "[", "'key'", "=>", "'single:'", ".", "$", "single", "->", "uid", ",", "'label'", "=>", "Craft", "::", "t", "(", "'site'", ",", "$", "single", "->", "name", ")", ",", "'sites'", "=>", "$", "single", "->", "getSiteIds", "(", ")", ",", "'data'", "=>", "[", "'url'", "=>", "$", "url", ",", "'handle'", "=>", "$", "single", "->", "handle", "]", ",", "'criteria'", "=>", "[", "'sectionId'", "=>", "$", "single", "->", "id", ",", "'editable'", "=>", "false", ",", "]", "]", ";", "}", "}", "// Replace original Singles link with new singles list", "array_splice", "(", "$", "event", "->", "sources", ",", "1", ",", "1", ",", "$", "singles", ")", ";", "// Insert some JS to go straight to single page when clicked - rather than listing in Index Table", "if", "(", "ExpandedSingles", "::", "$", "plugin", "->", "getSettings", "(", ")", "->", "redirectToEntry", ")", "{", "$", "js", "=", "'$(function() {'", ".", "'$(\"#main-content #sidebar nav a[data-url]\").each(function(i, e) {'", ".", "'var link = \"<a href=\" + $(this).data(\"url\") + \">\" + $(this).text() + \"</a>\";'", ".", "'$(this).replaceWith($(link));'", ".", "'});'", ".", "'});'", ";", "Craft", "::", "$", "app", "->", "view", "->", "registerJs", "(", "$", "js", ")", ";", "}", "// Update our element indexes to use the same columns as the original singles items", "// $newSettings = [];", "// $settings = Craft::$app->getElementIndexes()->getSettings(Entry::class);", "// // Get the singles index info - if none exists, then no need to go further", "// $singlesSettings = $settings['sources']['singles'] ?? null;", "// if (!$singlesSettings) {", "// return;", "// }", "// foreach ($singles as $key => $single) {", "// if (isset($single['key'])) {", "// $newSettings[$single['key']] = $singlesSettings;", "// }", "// }", "// Craft::$app->getElementIndexes()->saveSettings(Entry::class, $newSettings);", "}" ]
Create a new singles list and replace the old one with it @param RegisterElementSourcesEvent $event @return void
[ "Create", "a", "new", "singles", "list", "and", "replace", "the", "old", "one", "with", "it" ]
eb202d0c6d6bcd6459157c584336467bffec0d70
https://github.com/verbb/expanded-singles/blob/eb202d0c6d6bcd6459157c584336467bffec0d70/src/services/SinglesList.php#L24-L109
train
Kuestenschmiede/MapsBundle
Resources/contao/dca/tl_c4g_settings.php
tl_settings_c4g_maps.getMapTables
public function getMapTables() { $tables = []; if (is_array($GLOBALS['con4gis']['maps']['sourcetable'])) { foreach ($GLOBALS['con4gis']['maps']['sourcetable'] as $key=>$sourcetable) { $tables[$key] = $GLOBALS['TL_LANG']['c4g_maps']['sourcetable'][$key]['name']; } } return $tables; }
php
public function getMapTables() { $tables = []; if (is_array($GLOBALS['con4gis']['maps']['sourcetable'])) { foreach ($GLOBALS['con4gis']['maps']['sourcetable'] as $key=>$sourcetable) { $tables[$key] = $GLOBALS['TL_LANG']['c4g_maps']['sourcetable'][$key]['name']; } } return $tables; }
[ "public", "function", "getMapTables", "(", ")", "{", "$", "tables", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "GLOBALS", "[", "'con4gis'", "]", "[", "'maps'", "]", "[", "'sourcetable'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'con4gis'", "]", "[", "'maps'", "]", "[", "'sourcetable'", "]", "as", "$", "key", "=>", "$", "sourcetable", ")", "{", "$", "tables", "[", "$", "key", "]", "=", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'c4g_maps'", "]", "[", "'sourcetable'", "]", "[", "$", "key", "]", "[", "'name'", "]", ";", "}", "}", "return", "$", "tables", ";", "}" ]
Return available Map tables @return array Array of map tables
[ "Return", "available", "Map", "tables" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/dca/tl_c4g_settings.php#L70-L82
train
ikkez/f3-middleware
lib/middleware.php
Middleware.on
public function on($event,$pattern,$handler) { $bak = $this->f3->ROUTES; $this->f3->ROUTES=array(); $this->f3->route($pattern,$handler); $this->routes[$event] = (isset($this->routes[$event])) ? $this->f3->extend('ROUTES',$this->routes[$event]) : $this->f3->ROUTES; $this->f3->ROUTES=$bak; }
php
public function on($event,$pattern,$handler) { $bak = $this->f3->ROUTES; $this->f3->ROUTES=array(); $this->f3->route($pattern,$handler); $this->routes[$event] = (isset($this->routes[$event])) ? $this->f3->extend('ROUTES',$this->routes[$event]) : $this->f3->ROUTES; $this->f3->ROUTES=$bak; }
[ "public", "function", "on", "(", "$", "event", ",", "$", "pattern", ",", "$", "handler", ")", "{", "$", "bak", "=", "$", "this", "->", "f3", "->", "ROUTES", ";", "$", "this", "->", "f3", "->", "ROUTES", "=", "array", "(", ")", ";", "$", "this", "->", "f3", "->", "route", "(", "$", "pattern", ",", "$", "handler", ")", ";", "$", "this", "->", "routes", "[", "$", "event", "]", "=", "(", "isset", "(", "$", "this", "->", "routes", "[", "$", "event", "]", ")", ")", "?", "$", "this", "->", "f3", "->", "extend", "(", "'ROUTES'", ",", "$", "this", "->", "routes", "[", "$", "event", "]", ")", ":", "$", "this", "->", "f3", "->", "ROUTES", ";", "$", "this", "->", "f3", "->", "ROUTES", "=", "$", "bak", ";", "}" ]
register route to a specific event @param $event @param $pattern @param $handler
[ "register", "route", "to", "a", "specific", "event" ]
88e1c01c86c237c7934f23254dbbdd237eb8de78
https://github.com/ikkez/f3-middleware/blob/88e1c01c86c237c7934f23254dbbdd237eb8de78/lib/middleware.php#L36-L43
train
Kuestenschmiede/MapsBundle
Resources/contao/modules/api/EditorApi.php
EditorApi.getEditorConfigForProfile
protected function getEditorConfigForProfile($intId) { $arrEditorConfig = array(); // Find the requested profile $objProfile = C4gMapProfilesModel::findById($intId); if ($objProfile == null) { HttpResultHelper::NotFound(); } // Get editor config from profile $arrEditorConfig['styles_point'] = unserialize($objProfile->editor_styles_point); $arrEditorConfig['styles_line'] = unserialize($objProfile->editor_styles_line); $arrEditorConfig['styles_polygon'] = unserialize($objProfile->editor_styles_polygon); $arrEditorConfig['styles_circle'] = unserialize($objProfile->editor_styles_circle); $arrEditorConfig['styles_freehand'] = unserialize($objProfile->editor_styles_freehand); $arrEditorConfig['vars'] = $objProfile->editor_vars; $arrEditorConfig['show_items'] = $objProfile->editor_show_items; $arrEditorConfig['helpurl'] = $objProfile->editor_helpurl; return $arrEditorConfig; }
php
protected function getEditorConfigForProfile($intId) { $arrEditorConfig = array(); // Find the requested profile $objProfile = C4gMapProfilesModel::findById($intId); if ($objProfile == null) { HttpResultHelper::NotFound(); } // Get editor config from profile $arrEditorConfig['styles_point'] = unserialize($objProfile->editor_styles_point); $arrEditorConfig['styles_line'] = unserialize($objProfile->editor_styles_line); $arrEditorConfig['styles_polygon'] = unserialize($objProfile->editor_styles_polygon); $arrEditorConfig['styles_circle'] = unserialize($objProfile->editor_styles_circle); $arrEditorConfig['styles_freehand'] = unserialize($objProfile->editor_styles_freehand); $arrEditorConfig['vars'] = $objProfile->editor_vars; $arrEditorConfig['show_items'] = $objProfile->editor_show_items; $arrEditorConfig['helpurl'] = $objProfile->editor_helpurl; return $arrEditorConfig; }
[ "protected", "function", "getEditorConfigForProfile", "(", "$", "intId", ")", "{", "$", "arrEditorConfig", "=", "array", "(", ")", ";", "// Find the requested profile", "$", "objProfile", "=", "C4gMapProfilesModel", "::", "findById", "(", "$", "intId", ")", ";", "if", "(", "$", "objProfile", "==", "null", ")", "{", "HttpResultHelper", "::", "NotFound", "(", ")", ";", "}", "// Get editor config from profile", "$", "arrEditorConfig", "[", "'styles_point'", "]", "=", "unserialize", "(", "$", "objProfile", "->", "editor_styles_point", ")", ";", "$", "arrEditorConfig", "[", "'styles_line'", "]", "=", "unserialize", "(", "$", "objProfile", "->", "editor_styles_line", ")", ";", "$", "arrEditorConfig", "[", "'styles_polygon'", "]", "=", "unserialize", "(", "$", "objProfile", "->", "editor_styles_polygon", ")", ";", "$", "arrEditorConfig", "[", "'styles_circle'", "]", "=", "unserialize", "(", "$", "objProfile", "->", "editor_styles_circle", ")", ";", "$", "arrEditorConfig", "[", "'styles_freehand'", "]", "=", "unserialize", "(", "$", "objProfile", "->", "editor_styles_freehand", ")", ";", "$", "arrEditorConfig", "[", "'vars'", "]", "=", "$", "objProfile", "->", "editor_vars", ";", "$", "arrEditorConfig", "[", "'show_items'", "]", "=", "$", "objProfile", "->", "editor_show_items", ";", "$", "arrEditorConfig", "[", "'helpurl'", "]", "=", "$", "objProfile", "->", "editor_helpurl", ";", "return", "$", "arrEditorConfig", ";", "}" ]
Returns the editor configuration from a given profile. @param $intId integer the profileId @return array
[ "Returns", "the", "editor", "configuration", "from", "a", "given", "profile", "." ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/modules/api/EditorApi.php#L39-L61
train
Kuestenschmiede/MapsBundle
Resources/contao/models/C4gMapsModel.php
C4gMapsModel.findPublishedByPid
public static function findPublishedByPid($intPid, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("$t.pid=?"); $arrValues = array($intPid); if (!C4GUtils::checkBackendUserLogin()) { $time = time(); $arrColumns[] = "$t.published=1"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "$t.sorting"; } return static::findBy($arrColumns, $arrValues, $arrOptions); }
php
public static function findPublishedByPid($intPid, array $arrOptions = array()) { $t = static::$strTable; $arrColumns = array("$t.pid=?"); $arrValues = array($intPid); if (!C4GUtils::checkBackendUserLogin()) { $time = time(); $arrColumns[] = "$t.published=1"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "$t.sorting"; } return static::findBy($arrColumns, $arrValues, $arrOptions); }
[ "public", "static", "function", "findPublishedByPid", "(", "$", "intPid", ",", "array", "$", "arrOptions", "=", "array", "(", ")", ")", "{", "$", "t", "=", "static", "::", "$", "strTable", ";", "$", "arrColumns", "=", "array", "(", "\"$t.pid=?\"", ")", ";", "$", "arrValues", "=", "array", "(", "$", "intPid", ")", ";", "if", "(", "!", "C4GUtils", "::", "checkBackendUserLogin", "(", ")", ")", "{", "$", "time", "=", "time", "(", ")", ";", "$", "arrColumns", "[", "]", "=", "\"$t.published=1\"", ";", "}", "if", "(", "!", "isset", "(", "$", "arrOptions", "[", "'order'", "]", ")", ")", "{", "$", "arrOptions", "[", "'order'", "]", "=", "\"$t.sorting\"", ";", "}", "return", "static", "::", "findBy", "(", "$", "arrColumns", ",", "$", "arrValues", ",", "$", "arrOptions", ")", ";", "}" ]
ToDo Funktioniert unter contao 4 offensichtlich nicht mehr so wie es soll.
[ "ToDo", "Funktioniert", "unter", "contao", "4", "offensichtlich", "nicht", "mehr", "so", "wie", "es", "soll", "." ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/models/C4gMapsModel.php#L28-L44
train
Kuestenschmiede/MapsBundle
Resources/contao/classes/ResourceLoader.php
ResourceLoader.loadGeopickerResources
public static function loadGeopickerResources($additionalResources = array()) { //load geopicker profile $profile = C4gMapProfilesModel::findBy('is_backend_geopicker_default', 1); // use default if the profile was not found if (!$profile) { $settings = C4gSettingsModel::findAll(); $profile = $settings[0]->defaultprofile; if (!$profile) { $profiles = C4gMapProfilesModel::findAll(); if ($profiles && (!empty($profiles))) { $length = count($profiles); $profile = $profiles[$length-1]; } else { return; } } } self::loadResourcesForProfile($profile->id, true, $profile); if (count($additionalResources) > 0) { self::loadResources($additionalResources); } }
php
public static function loadGeopickerResources($additionalResources = array()) { //load geopicker profile $profile = C4gMapProfilesModel::findBy('is_backend_geopicker_default', 1); // use default if the profile was not found if (!$profile) { $settings = C4gSettingsModel::findAll(); $profile = $settings[0]->defaultprofile; if (!$profile) { $profiles = C4gMapProfilesModel::findAll(); if ($profiles && (!empty($profiles))) { $length = count($profiles); $profile = $profiles[$length-1]; } else { return; } } } self::loadResourcesForProfile($profile->id, true, $profile); if (count($additionalResources) > 0) { self::loadResources($additionalResources); } }
[ "public", "static", "function", "loadGeopickerResources", "(", "$", "additionalResources", "=", "array", "(", ")", ")", "{", "//load geopicker profile", "$", "profile", "=", "C4gMapProfilesModel", "::", "findBy", "(", "'is_backend_geopicker_default'", ",", "1", ")", ";", "// use default if the profile was not found", "if", "(", "!", "$", "profile", ")", "{", "$", "settings", "=", "C4gSettingsModel", "::", "findAll", "(", ")", ";", "$", "profile", "=", "$", "settings", "[", "0", "]", "->", "defaultprofile", ";", "if", "(", "!", "$", "profile", ")", "{", "$", "profiles", "=", "C4gMapProfilesModel", "::", "findAll", "(", ")", ";", "if", "(", "$", "profiles", "&&", "(", "!", "empty", "(", "$", "profiles", ")", ")", ")", "{", "$", "length", "=", "count", "(", "$", "profiles", ")", ";", "$", "profile", "=", "$", "profiles", "[", "$", "length", "-", "1", "]", ";", "}", "else", "{", "return", ";", "}", "}", "}", "self", "::", "loadResourcesForProfile", "(", "$", "profile", "->", "id", ",", "true", ",", "$", "profile", ")", ";", "if", "(", "count", "(", "$", "additionalResources", ")", ">", "0", ")", "{", "self", "::", "loadResources", "(", "$", "additionalResources", ")", ";", "}", "}" ]
Loads the default geopicker profile and resources according to that profile @return void
[ "Loads", "the", "default", "geopicker", "profile", "and", "resources", "according", "to", "that", "profile" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/classes/ResourceLoader.php#L302-L324
train
Kuestenschmiede/MapsBundle
Resources/contao/classes/TextField.php
TextField.generateLabel
public function generateLabel() { if (($this->require_input) && ($this->value == '')) { $this->required = true; } return parent::generateLabel(); }
php
public function generateLabel() { if (($this->require_input) && ($this->value == '')) { $this->required = true; } return parent::generateLabel(); }
[ "public", "function", "generateLabel", "(", ")", "{", "if", "(", "(", "$", "this", "->", "require_input", ")", "&&", "(", "$", "this", "->", "value", "==", "''", ")", ")", "{", "$", "this", "->", "required", "=", "true", ";", "}", "return", "parent", "::", "generateLabel", "(", ")", ";", "}" ]
Check custom setting 'require_input', which implements custom mandatory handling possibility @return string
[ "Check", "custom", "setting", "require_input", "which", "implements", "custom", "mandatory", "handling", "possibility" ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Resources/contao/classes/TextField.php#L26-L32
train
Kuestenschmiede/MapsBundle
Classes/Services/LayerContentService.php
LayerContentService.getFolderData
public function getFolderData($objLayer, $key=false, $folder=false, $count=0) { if (!$folder) { $folder = $this->getFolder($objLayer); } if (!$key) { $key =$objLayer->id; } $folderPath = realpath(TL_ROOT.'/'.$folder); $countFiles = 2050; if (is_dir($folderPath)) { $dict = scandir($folderPath); unset($dict[array_search('.', $dict)]); unset($dict[array_search('..', $dict)]); foreach ($dict as $value) { // $value = utf8_encode($value); $path = realpath(TL_ROOT."/".$folder."/".$value); if (is_dir($path)) { $fileFolder = pathinfo($path); $arrSubFolder = $this->getFolderContent($objLayer, $fileFolder, $key, $count); $count += 1; $data = $this->getFolderData($objLayer, $arrSubFolder['id'], $folder."/".$value, $count); if ($data) { $arrSubFolder['childsCount'] = count($data); $arrSubFolder['childs'] = $data; $arrData[] = $arrSubFolder; } } elseif (is_file($path)) { $fileData = pathinfo($path); $arrFile = $this->getFileContent($objLayer, $folder, $fileData, $key, $countFiles); $countFiles += 2; if($arrFile) { $arrData[] = $arrFile; } } } return $arrData; } else { return false; } }
php
public function getFolderData($objLayer, $key=false, $folder=false, $count=0) { if (!$folder) { $folder = $this->getFolder($objLayer); } if (!$key) { $key =$objLayer->id; } $folderPath = realpath(TL_ROOT.'/'.$folder); $countFiles = 2050; if (is_dir($folderPath)) { $dict = scandir($folderPath); unset($dict[array_search('.', $dict)]); unset($dict[array_search('..', $dict)]); foreach ($dict as $value) { // $value = utf8_encode($value); $path = realpath(TL_ROOT."/".$folder."/".$value); if (is_dir($path)) { $fileFolder = pathinfo($path); $arrSubFolder = $this->getFolderContent($objLayer, $fileFolder, $key, $count); $count += 1; $data = $this->getFolderData($objLayer, $arrSubFolder['id'], $folder."/".$value, $count); if ($data) { $arrSubFolder['childsCount'] = count($data); $arrSubFolder['childs'] = $data; $arrData[] = $arrSubFolder; } } elseif (is_file($path)) { $fileData = pathinfo($path); $arrFile = $this->getFileContent($objLayer, $folder, $fileData, $key, $countFiles); $countFiles += 2; if($arrFile) { $arrData[] = $arrFile; } } } return $arrData; } else { return false; } }
[ "public", "function", "getFolderData", "(", "$", "objLayer", ",", "$", "key", "=", "false", ",", "$", "folder", "=", "false", ",", "$", "count", "=", "0", ")", "{", "if", "(", "!", "$", "folder", ")", "{", "$", "folder", "=", "$", "this", "->", "getFolder", "(", "$", "objLayer", ")", ";", "}", "if", "(", "!", "$", "key", ")", "{", "$", "key", "=", "$", "objLayer", "->", "id", ";", "}", "$", "folderPath", "=", "realpath", "(", "TL_ROOT", ".", "'/'", ".", "$", "folder", ")", ";", "$", "countFiles", "=", "2050", ";", "if", "(", "is_dir", "(", "$", "folderPath", ")", ")", "{", "$", "dict", "=", "scandir", "(", "$", "folderPath", ")", ";", "unset", "(", "$", "dict", "[", "array_search", "(", "'.'", ",", "$", "dict", ")", "]", ")", ";", "unset", "(", "$", "dict", "[", "array_search", "(", "'..'", ",", "$", "dict", ")", "]", ")", ";", "foreach", "(", "$", "dict", "as", "$", "value", ")", "{", "// $value = utf8_encode($value);", "$", "path", "=", "realpath", "(", "TL_ROOT", ".", "\"/\"", ".", "$", "folder", ".", "\"/\"", ".", "$", "value", ")", ";", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "$", "fileFolder", "=", "pathinfo", "(", "$", "path", ")", ";", "$", "arrSubFolder", "=", "$", "this", "->", "getFolderContent", "(", "$", "objLayer", ",", "$", "fileFolder", ",", "$", "key", ",", "$", "count", ")", ";", "$", "count", "+=", "1", ";", "$", "data", "=", "$", "this", "->", "getFolderData", "(", "$", "objLayer", ",", "$", "arrSubFolder", "[", "'id'", "]", ",", "$", "folder", ".", "\"/\"", ".", "$", "value", ",", "$", "count", ")", ";", "if", "(", "$", "data", ")", "{", "$", "arrSubFolder", "[", "'childsCount'", "]", "=", "count", "(", "$", "data", ")", ";", "$", "arrSubFolder", "[", "'childs'", "]", "=", "$", "data", ";", "$", "arrData", "[", "]", "=", "$", "arrSubFolder", ";", "}", "}", "elseif", "(", "is_file", "(", "$", "path", ")", ")", "{", "$", "fileData", "=", "pathinfo", "(", "$", "path", ")", ";", "$", "arrFile", "=", "$", "this", "->", "getFileContent", "(", "$", "objLayer", ",", "$", "folder", ",", "$", "fileData", ",", "$", "key", ",", "$", "countFiles", ")", ";", "$", "countFiles", "+=", "2", ";", "if", "(", "$", "arrFile", ")", "{", "$", "arrData", "[", "]", "=", "$", "arrFile", ";", "}", "}", "}", "return", "$", "arrData", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Creates the layer data for a given layer of the location_type folder. @param $objLayer @param bool $key @param bool $folder @param int $count @return array|bool
[ "Creates", "the", "layer", "data", "for", "a", "given", "layer", "of", "the", "location_type", "folder", "." ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Classes/Services/LayerContentService.php#L899-L940
train
Kuestenschmiede/MapsBundle
Classes/Services/LayerContentService.php
LayerContentService.getFileContent
private function getFileContent($objLayer, $folder, $fileInfo, $key, $count) { switch ($fileInfo['extension']) { case 'gpx': $child = array ( "id" => strval($key.$count), "pid" => $key, "name" => utf8_encode($fileInfo['filename']), "hide" => $objLayer->published, "display" => true, "type" => $fileInfo['extension'], "content" => array(), "cssClass" => $objLayer->cssClass, "childs" => array() ); $childLayerList = array ( "id" => strval($key.$count), "type" => "urlData", "format" => "GPX", "origType" => "gpx", "locationStyle" => $objLayer->locstyle, "cluster_fillcolor" => $objLayer->cluster_fillcolor, "cluster_fontcolor" => $objLayer->cluster_fontcolor, "cluster_zoom" => $objLayer->cluster_zoom, "cluster_popup" => $objLayer->cluster_popup, "loc_linkurl" => Controller::replaceInsertTags($objLayer->loc_linkurl), "hover_location" => $objLayer->hover_location, "hover_style" => $objLayer->hover_style, "data" => array ( "popup" => array( "content" => utf8_encode($fileInfo['filename']),//"tl_c4g_maps" . ":" . $objLayer->id . ":", "async" => false ), "tooltip" => $objLayer->tooltip, "tooltip_length" => $objLayer->tooltip_length, "label" => $objLayer->loc_label, 'zoom_onclick' => $objLayer -> loc_onclick_zoomto, "url" => utf8_encode($folder)."/".utf8_encode($fileInfo['basename']), ), "settings" => array ( "loadAsync" => false, "refresh" => false, "crossOrigine" => false, "boundingBox" => false, "cluster" => $objLayer->cluster_locations ? ($objLayer->cluster_distance ? $objLayer->cluster_distance : 20) : false, ) ); $child['content'][] = $childLayerList; // $childs[] = $child; return $child; case 'xml': return false; case 'geojson': return false; default: return false; } }
php
private function getFileContent($objLayer, $folder, $fileInfo, $key, $count) { switch ($fileInfo['extension']) { case 'gpx': $child = array ( "id" => strval($key.$count), "pid" => $key, "name" => utf8_encode($fileInfo['filename']), "hide" => $objLayer->published, "display" => true, "type" => $fileInfo['extension'], "content" => array(), "cssClass" => $objLayer->cssClass, "childs" => array() ); $childLayerList = array ( "id" => strval($key.$count), "type" => "urlData", "format" => "GPX", "origType" => "gpx", "locationStyle" => $objLayer->locstyle, "cluster_fillcolor" => $objLayer->cluster_fillcolor, "cluster_fontcolor" => $objLayer->cluster_fontcolor, "cluster_zoom" => $objLayer->cluster_zoom, "cluster_popup" => $objLayer->cluster_popup, "loc_linkurl" => Controller::replaceInsertTags($objLayer->loc_linkurl), "hover_location" => $objLayer->hover_location, "hover_style" => $objLayer->hover_style, "data" => array ( "popup" => array( "content" => utf8_encode($fileInfo['filename']),//"tl_c4g_maps" . ":" . $objLayer->id . ":", "async" => false ), "tooltip" => $objLayer->tooltip, "tooltip_length" => $objLayer->tooltip_length, "label" => $objLayer->loc_label, 'zoom_onclick' => $objLayer -> loc_onclick_zoomto, "url" => utf8_encode($folder)."/".utf8_encode($fileInfo['basename']), ), "settings" => array ( "loadAsync" => false, "refresh" => false, "crossOrigine" => false, "boundingBox" => false, "cluster" => $objLayer->cluster_locations ? ($objLayer->cluster_distance ? $objLayer->cluster_distance : 20) : false, ) ); $child['content'][] = $childLayerList; // $childs[] = $child; return $child; case 'xml': return false; case 'geojson': return false; default: return false; } }
[ "private", "function", "getFileContent", "(", "$", "objLayer", ",", "$", "folder", ",", "$", "fileInfo", ",", "$", "key", ",", "$", "count", ")", "{", "switch", "(", "$", "fileInfo", "[", "'extension'", "]", ")", "{", "case", "'gpx'", ":", "$", "child", "=", "array", "(", "\"id\"", "=>", "strval", "(", "$", "key", ".", "$", "count", ")", ",", "\"pid\"", "=>", "$", "key", ",", "\"name\"", "=>", "utf8_encode", "(", "$", "fileInfo", "[", "'filename'", "]", ")", ",", "\"hide\"", "=>", "$", "objLayer", "->", "published", ",", "\"display\"", "=>", "true", ",", "\"type\"", "=>", "$", "fileInfo", "[", "'extension'", "]", ",", "\"content\"", "=>", "array", "(", ")", ",", "\"cssClass\"", "=>", "$", "objLayer", "->", "cssClass", ",", "\"childs\"", "=>", "array", "(", ")", ")", ";", "$", "childLayerList", "=", "array", "(", "\"id\"", "=>", "strval", "(", "$", "key", ".", "$", "count", ")", ",", "\"type\"", "=>", "\"urlData\"", ",", "\"format\"", "=>", "\"GPX\"", ",", "\"origType\"", "=>", "\"gpx\"", ",", "\"locationStyle\"", "=>", "$", "objLayer", "->", "locstyle", ",", "\"cluster_fillcolor\"", "=>", "$", "objLayer", "->", "cluster_fillcolor", ",", "\"cluster_fontcolor\"", "=>", "$", "objLayer", "->", "cluster_fontcolor", ",", "\"cluster_zoom\"", "=>", "$", "objLayer", "->", "cluster_zoom", ",", "\"cluster_popup\"", "=>", "$", "objLayer", "->", "cluster_popup", ",", "\"loc_linkurl\"", "=>", "Controller", "::", "replaceInsertTags", "(", "$", "objLayer", "->", "loc_linkurl", ")", ",", "\"hover_location\"", "=>", "$", "objLayer", "->", "hover_location", ",", "\"hover_style\"", "=>", "$", "objLayer", "->", "hover_style", ",", "\"data\"", "=>", "array", "(", "\"popup\"", "=>", "array", "(", "\"content\"", "=>", "utf8_encode", "(", "$", "fileInfo", "[", "'filename'", "]", ")", ",", "//\"tl_c4g_maps\" . \":\" . $objLayer->id . \":\",", "\"async\"", "=>", "false", ")", ",", "\"tooltip\"", "=>", "$", "objLayer", "->", "tooltip", ",", "\"tooltip_length\"", "=>", "$", "objLayer", "->", "tooltip_length", ",", "\"label\"", "=>", "$", "objLayer", "->", "loc_label", ",", "'zoom_onclick'", "=>", "$", "objLayer", "->", "loc_onclick_zoomto", ",", "\"url\"", "=>", "utf8_encode", "(", "$", "folder", ")", ".", "\"/\"", ".", "utf8_encode", "(", "$", "fileInfo", "[", "'basename'", "]", ")", ",", ")", ",", "\"settings\"", "=>", "array", "(", "\"loadAsync\"", "=>", "false", ",", "\"refresh\"", "=>", "false", ",", "\"crossOrigine\"", "=>", "false", ",", "\"boundingBox\"", "=>", "false", ",", "\"cluster\"", "=>", "$", "objLayer", "->", "cluster_locations", "?", "(", "$", "objLayer", "->", "cluster_distance", "?", "$", "objLayer", "->", "cluster_distance", ":", "20", ")", ":", "false", ",", ")", ")", ";", "$", "child", "[", "'content'", "]", "[", "]", "=", "$", "childLayerList", ";", "// $childs[] = $child;", "return", "$", "child", ";", "case", "'xml'", ":", "return", "false", ";", "case", "'geojson'", ":", "return", "false", ";", "default", ":", "return", "false", ";", "}", "}" ]
Parses gpx contents of a given file for a given layer. @param $objLayer @param $folder @param $fileInfo @param $key @param $count @return array|bool
[ "Parses", "gpx", "contents", "of", "a", "given", "file", "for", "a", "given", "layer", "." ]
03c731323563d0f0c99918aed7729c4390de1187
https://github.com/Kuestenschmiede/MapsBundle/blob/03c731323563d0f0c99918aed7729c4390de1187/Classes/Services/LayerContentService.php#L978-L1043
train
caffeina-core/core
classes/Text.php
Text.render
public static function render($t,$v=null){ if (Options::get('core.text.replace_empties', true)) { $replacer = function($c) use ($v){ return Structure::fetch(trim($c[1]), $v); }; } else { $replacer = function($c) use ($v){ return Structure::fetch(trim($c[1]), $v) ?: $c[0]; }; } return preg_replace_callback("(\{\{([^}]+)\}\})S",$replacer,$t); }
php
public static function render($t,$v=null){ if (Options::get('core.text.replace_empties', true)) { $replacer = function($c) use ($v){ return Structure::fetch(trim($c[1]), $v); }; } else { $replacer = function($c) use ($v){ return Structure::fetch(trim($c[1]), $v) ?: $c[0]; }; } return preg_replace_callback("(\{\{([^}]+)\}\})S",$replacer,$t); }
[ "public", "static", "function", "render", "(", "$", "t", ",", "$", "v", "=", "null", ")", "{", "if", "(", "Options", "::", "get", "(", "'core.text.replace_empties'", ",", "true", ")", ")", "{", "$", "replacer", "=", "function", "(", "$", "c", ")", "use", "(", "$", "v", ")", "{", "return", "Structure", "::", "fetch", "(", "trim", "(", "$", "c", "[", "1", "]", ")", ",", "$", "v", ")", ";", "}", ";", "}", "else", "{", "$", "replacer", "=", "function", "(", "$", "c", ")", "use", "(", "$", "v", ")", "{", "return", "Structure", "::", "fetch", "(", "trim", "(", "$", "c", "[", "1", "]", ")", ",", "$", "v", ")", "?", ":", "$", "c", "[", "0", "]", ";", "}", ";", "}", "return", "preg_replace_callback", "(", "\"(\\{\\{([^}]+)\\}\\})S\"", ",", "$", "replacer", ",", "$", "t", ")", ";", "}" ]
Fast string templating. Uses a Twig-like syntax. @example echo Text::render('Your IP is : {{ server.REMOTE_HOST }}',array('server' => $_SERVER)); @author Stefano Azzolini <[email protected]> @access public @static @param mixed $t The text template @param mixed $v (default: null) The array of values exposed in template. @return string
[ "Fast", "string", "templating", ".", "Uses", "a", "Twig", "-", "like", "syntax", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Text.php#L30-L42
train
caffeina-core/core
classes/Text.php
Text.cut
public static function cut($text, $start_tag, $end_tag=null){ $_s = strlen($start_tag) + strpos($text, $start_tag); return $end_tag ? substr($text, $_s, strpos($text,$end_tag,$_s)-$_s) : substr($text, $_s); }
php
public static function cut($text, $start_tag, $end_tag=null){ $_s = strlen($start_tag) + strpos($text, $start_tag); return $end_tag ? substr($text, $_s, strpos($text,$end_tag,$_s)-$_s) : substr($text, $_s); }
[ "public", "static", "function", "cut", "(", "$", "text", ",", "$", "start_tag", ",", "$", "end_tag", "=", "null", ")", "{", "$", "_s", "=", "strlen", "(", "$", "start_tag", ")", "+", "strpos", "(", "$", "text", ",", "$", "start_tag", ")", ";", "return", "$", "end_tag", "?", "substr", "(", "$", "text", ",", "$", "_s", ",", "strpos", "(", "$", "text", ",", "$", "end_tag", ",", "$", "_s", ")", "-", "$", "_s", ")", ":", "substr", "(", "$", "text", ",", "$", "_s", ")", ";", "}" ]
Cut a string from the end of a substring to the start of another @example echo strcut("Name: Ethan Hunt; Role: Agent",'Name: ',';'); // Ethan Hunt @param string $text The source text @param string $start_tag The starting substring @param string $end_tag Ending substring, if omitted all remaining string is returned @return string The cutted string
[ "Cut", "a", "string", "from", "the", "end", "of", "a", "substring", "to", "the", "start", "of", "another" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Text.php#L94-L97
train
caffeina-core/core
classes/Structure.php
Structure.fetch
public static function fetch($path, $root) { $_ = (array)$root; if (strpos($path,'.') === false) { return isset($_[$path]) ? $_[$path] : null; } else { list($frag,$rest) = explode('.', $path, 2); if ($rest) { return isset($_[$frag]) ? self::fetch($rest, $_[$frag]) : null; } elseif ($frag) { return (array)$_[$frag]; } else { return null; } } }
php
public static function fetch($path, $root) { $_ = (array)$root; if (strpos($path,'.') === false) { return isset($_[$path]) ? $_[$path] : null; } else { list($frag,$rest) = explode('.', $path, 2); if ($rest) { return isset($_[$frag]) ? self::fetch($rest, $_[$frag]) : null; } elseif ($frag) { return (array)$_[$frag]; } else { return null; } } }
[ "public", "static", "function", "fetch", "(", "$", "path", ",", "$", "root", ")", "{", "$", "_", "=", "(", "array", ")", "$", "root", ";", "if", "(", "strpos", "(", "$", "path", ",", "'.'", ")", "===", "false", ")", "{", "return", "isset", "(", "$", "_", "[", "$", "path", "]", ")", "?", "$", "_", "[", "$", "path", "]", ":", "null", ";", "}", "else", "{", "list", "(", "$", "frag", ",", "$", "rest", ")", "=", "explode", "(", "'.'", ",", "$", "path", ",", "2", ")", ";", "if", "(", "$", "rest", ")", "{", "return", "isset", "(", "$", "_", "[", "$", "frag", "]", ")", "?", "self", "::", "fetch", "(", "$", "rest", ",", "$", "_", "[", "$", "frag", "]", ")", ":", "null", ";", "}", "elseif", "(", "$", "frag", ")", "{", "return", "(", "array", ")", "$", "_", "[", "$", "frag", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}" ]
Dot-Notation Array Path Resolver @param string $path The dot-notation path @param array $root The array to navigate @return mixed The pointed value
[ "Dot", "-", "Notation", "Array", "Path", "Resolver" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Structure.php#L86-L100
train
caffeina-core/core
classes/Map.php
Map.get
public function get($key, $default=null){ if (null !== ($ptr =& $this->find($key,false))){ return $ptr; } else { if ($default !== null){ return $this->set($key, is_callable($default) ? call_user_func($default) : $default); } else { return null; } } }
php
public function get($key, $default=null){ if (null !== ($ptr =& $this->find($key,false))){ return $ptr; } else { if ($default !== null){ return $this->set($key, is_callable($default) ? call_user_func($default) : $default); } else { return null; } } }
[ "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "null", "!==", "(", "$", "ptr", "=", "&", "$", "this", "->", "find", "(", "$", "key", ",", "false", ")", ")", ")", "{", "return", "$", "ptr", ";", "}", "else", "{", "if", "(", "$", "default", "!==", "null", ")", "{", "return", "$", "this", "->", "set", "(", "$", "key", ",", "is_callable", "(", "$", "default", ")", "?", "call_user_func", "(", "$", "default", ")", ":", "$", "default", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}" ]
Get a value assigned to a key path from the map @param string $key The key path of the value in dot notation @param mixed $default (optional) The default value. If is a callable it will executed and the return value will be used. @return mixed The value of the key or the default (resolved) value if the key not existed.
[ "Get", "a", "value", "assigned", "to", "a", "key", "path", "from", "the", "map" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Map.php#L32-L42
train
caffeina-core/core
classes/Map.php
Map.set
public function set($key, $value=null){ if (is_array($key)) { return $this->merge($key); } else { $ptr =& $this->find($key, true); return $ptr = $value; } }
php
public function set($key, $value=null){ if (is_array($key)) { return $this->merge($key); } else { $ptr =& $this->find($key, true); return $ptr = $value; } }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "merge", "(", "$", "key", ")", ";", "}", "else", "{", "$", "ptr", "=", "&", "$", "this", "->", "find", "(", "$", "key", ",", "true", ")", ";", "return", "$", "ptr", "=", "$", "value", ";", "}", "}" ]
Set a value for a key path from map @param string $key The key path of the value in dot notation @param mixed $value (optional) The value. If is a callable it will executed and the return value will be used. @return mixed The value of the key or the default (resolved) value if the key not existed.
[ "Set", "a", "value", "for", "a", "key", "path", "from", "map" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Map.php#L50-L57
train
caffeina-core/core
classes/Map.php
Map.delete
public function delete($key, $compact=true){ $this->set($key, null); if ($compact) $this->compact(); }
php
public function delete($key, $compact=true){ $this->set($key, null); if ($compact) $this->compact(); }
[ "public", "function", "delete", "(", "$", "key", ",", "$", "compact", "=", "true", ")", "{", "$", "this", "->", "set", "(", "$", "key", ",", "null", ")", ";", "if", "(", "$", "compact", ")", "$", "this", "->", "compact", "(", ")", ";", "}" ]
Delete a value and the key path from map. @param string $key The key path in dot notation @param boolean $compact (optional) Compact map removing empty paths.
[ "Delete", "a", "value", "and", "the", "key", "path", "from", "map", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Map.php#L64-L67
train
caffeina-core/core
classes/Map.php
Map.merge
public function merge($array, $merge_back=false){ $this->fields = $merge_back ? array_replace_recursive((array)$array, $this->fields) : array_replace_recursive($this->fields, (array)$array); }
php
public function merge($array, $merge_back=false){ $this->fields = $merge_back ? array_replace_recursive((array)$array, $this->fields) : array_replace_recursive($this->fields, (array)$array); }
[ "public", "function", "merge", "(", "$", "array", ",", "$", "merge_back", "=", "false", ")", "{", "$", "this", "->", "fields", "=", "$", "merge_back", "?", "array_replace_recursive", "(", "(", "array", ")", "$", "array", ",", "$", "this", "->", "fields", ")", ":", "array_replace_recursive", "(", "$", "this", "->", "fields", ",", "(", "array", ")", "$", "array", ")", ";", "}" ]
Merge an associative array to the map. @param array $array The array to merge @param boolean $merge_back If `true` merge the map over the $array, if `false` (default) the reverse.
[ "Merge", "an", "associative", "array", "to", "the", "map", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Map.php#L102-L106
train
caffeina-core/core
classes/Map.php
Map.compact
public function compact(){ $array_filter_rec = function($input, $callback = null) use (&$array_filter_rec) { foreach ($input as &$value) { if (is_array($value)) { $value = $array_filter_rec($value, $callback); } } return array_filter($input, $callback); }; $this->fields = $array_filter_rec($this->fields,function($a){ return $a !== null; }); }
php
public function compact(){ $array_filter_rec = function($input, $callback = null) use (&$array_filter_rec) { foreach ($input as &$value) { if (is_array($value)) { $value = $array_filter_rec($value, $callback); } } return array_filter($input, $callback); }; $this->fields = $array_filter_rec($this->fields,function($a){ return $a !== null; }); }
[ "public", "function", "compact", "(", ")", "{", "$", "array_filter_rec", "=", "function", "(", "$", "input", ",", "$", "callback", "=", "null", ")", "use", "(", "&", "$", "array_filter_rec", ")", "{", "foreach", "(", "$", "input", "as", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "array_filter_rec", "(", "$", "value", ",", "$", "callback", ")", ";", "}", "}", "return", "array_filter", "(", "$", "input", ",", "$", "callback", ")", ";", "}", ";", "$", "this", "->", "fields", "=", "$", "array_filter_rec", "(", "$", "this", "->", "fields", ",", "function", "(", "$", "a", ")", "{", "return", "$", "a", "!==", "null", ";", "}", ")", ";", "}" ]
Compact map removing empty paths
[ "Compact", "map", "removing", "empty", "paths" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Map.php#L112-L124
train
caffeina-core/core
classes/Map.php
Map.&
public function & find($path, $create=false, callable $operation=null) { $create ? $value =& $this->fields : $value = $this->fields; foreach (explode('.',$path) as $tok) if ($create || isset($value[$tok])) { $value =& $value[$tok]; } else { $value = $create ? $value : null; break; } if ( is_callable($operation) ) $operation($value); return $value; }
php
public function & find($path, $create=false, callable $operation=null) { $create ? $value =& $this->fields : $value = $this->fields; foreach (explode('.',$path) as $tok) if ($create || isset($value[$tok])) { $value =& $value[$tok]; } else { $value = $create ? $value : null; break; } if ( is_callable($operation) ) $operation($value); return $value; }
[ "public", "function", "&", "find", "(", "$", "path", ",", "$", "create", "=", "false", ",", "callable", "$", "operation", "=", "null", ")", "{", "$", "create", "?", "$", "value", "=", "&", "$", "this", "->", "fields", ":", "$", "value", "=", "$", "this", "->", "fields", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "path", ")", "as", "$", "tok", ")", "if", "(", "$", "create", "||", "isset", "(", "$", "value", "[", "$", "tok", "]", ")", ")", "{", "$", "value", "=", "&", "$", "value", "[", "$", "tok", "]", ";", "}", "else", "{", "$", "value", "=", "$", "create", "?", "$", "value", ":", "null", ";", "break", ";", "}", "if", "(", "is_callable", "(", "$", "operation", ")", ")", "$", "operation", "(", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
Navigate map and find the element from the path in dot notation. @param string $path Key path in dot notation. @param boolean $create If true will create empty paths. @param callable If passed this callback will be applied to the founded value. @return mixed The founded value.
[ "Navigate", "map", "and", "find", "the", "element", "from", "the", "path", "in", "dot", "notation", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Map.php#L133-L142
train
caffeina-core/core
classes/Session.php
Session.start
static public function start($name=null){ if (isset($_SESSION)) return; $ln = static::name($name); // Obfuscate IDs ini_set('session.hash_function', 'whirlpool'); session_cache_limiter('must-revalidate'); if (session_status() == PHP_SESSION_NONE) { @session_start(); } static::trigger("start", $name?:$ln); }
php
static public function start($name=null){ if (isset($_SESSION)) return; $ln = static::name($name); // Obfuscate IDs ini_set('session.hash_function', 'whirlpool'); session_cache_limiter('must-revalidate'); if (session_status() == PHP_SESSION_NONE) { @session_start(); } static::trigger("start", $name?:$ln); }
[ "static", "public", "function", "start", "(", "$", "name", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", ")", ")", "return", ";", "$", "ln", "=", "static", "::", "name", "(", "$", "name", ")", ";", "// Obfuscate IDs", "ini_set", "(", "'session.hash_function'", ",", "'whirlpool'", ")", ";", "session_cache_limiter", "(", "'must-revalidate'", ")", ";", "if", "(", "session_status", "(", ")", "==", "PHP_SESSION_NONE", ")", "{", "@", "session_start", "(", ")", ";", "}", "static", "::", "trigger", "(", "\"start\"", ",", "$", "name", "?", ":", "$", "ln", ")", ";", "}" ]
Start session handler @access public @static @return void
[ "Start", "session", "handler" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Session.php#L23-L33
train
caffeina-core/core
classes/Session.php
Session.get
static public function get($key,$default=null){ if (($active = static::active()) && isset($_SESSION[$key])) { return $_SESSION[$key]; } else if ($active) { return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default); } else { return (is_callable($default)?call_user_func($default):$default); } }
php
static public function get($key,$default=null){ if (($active = static::active()) && isset($_SESSION[$key])) { return $_SESSION[$key]; } else if ($active) { return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default); } else { return (is_callable($default)?call_user_func($default):$default); } }
[ "static", "public", "function", "get", "(", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "(", "$", "active", "=", "static", "::", "active", "(", ")", ")", "&&", "isset", "(", "$", "_SESSION", "[", "$", "key", "]", ")", ")", "{", "return", "$", "_SESSION", "[", "$", "key", "]", ";", "}", "else", "if", "(", "$", "active", ")", "{", "return", "$", "_SESSION", "[", "$", "key", "]", "=", "(", "is_callable", "(", "$", "default", ")", "?", "call_user_func", "(", "$", "default", ")", ":", "$", "default", ")", ";", "}", "else", "{", "return", "(", "is_callable", "(", "$", "default", ")", "?", "call_user_func", "(", "$", "default", ")", ":", "$", "default", ")", ";", "}", "}" ]
Get a session variable reference @access public @static @param mixed $key The variable name @return mixed The variable value
[ "Get", "a", "session", "variable", "reference" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Session.php#L80-L88
train
caffeina-core/core
classes/Response.php
Response.download
public static function download($data){ if (is_array($data)) { if (isset($data['filename'])) static::$force_dl = $data['filename']; if (isset($data['charset'])) static::charset($data['charset']); if (isset($data['mime'])) static::type($data['mime']); if (isset($data['body'])) static::body($data['body']); } else static::$force_dl = $data; }
php
public static function download($data){ if (is_array($data)) { if (isset($data['filename'])) static::$force_dl = $data['filename']; if (isset($data['charset'])) static::charset($data['charset']); if (isset($data['mime'])) static::type($data['mime']); if (isset($data['body'])) static::body($data['body']); } else static::$force_dl = $data; }
[ "public", "static", "function", "download", "(", "$", "data", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'filename'", "]", ")", ")", "static", "::", "$", "force_dl", "=", "$", "data", "[", "'filename'", "]", ";", "if", "(", "isset", "(", "$", "data", "[", "'charset'", "]", ")", ")", "static", "::", "charset", "(", "$", "data", "[", "'charset'", "]", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'mime'", "]", ")", ")", "static", "::", "type", "(", "$", "data", "[", "'mime'", "]", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'body'", "]", ")", ")", "static", "::", "body", "(", "$", "data", "[", "'body'", "]", ")", ";", "}", "else", "static", "::", "$", "force_dl", "=", "$", "data", ";", "}" ]
Force download of Response body @param mixed $data Pass a falsy value to disable download, pass a filename for exporting content or array with raw string data @return void
[ "Force", "download", "of", "Response", "body" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Response.php#L49-L56
train
caffeina-core/core
classes/Response.php
Response.enableCORS
public static function enableCORS($origin='*'){ // Allow from any origin if ($origin = $origin ?:( isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '*') )) { static::header('Access-Control-Allow-Origin', $origin); static::header('Access-Control-Allow-Credentials', 'true'); static::header('Access-Control-Max-Age', 86400); } // Access-Control headers are received during OPTIONS requests if (filter_input(INPUT_SERVER,'REQUEST_METHOD') == 'OPTIONS') { static::clean(); if (filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_METHOD')) { static::header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, PATCH, TRACE'); } if ($req_h = filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_HEADERS')) { static::header('Access-Control-Allow-Headers',$req_h); } self::trigger('cors.preflight'); static::send(); exit; } }
php
public static function enableCORS($origin='*'){ // Allow from any origin if ($origin = $origin ?:( isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '*') )) { static::header('Access-Control-Allow-Origin', $origin); static::header('Access-Control-Allow-Credentials', 'true'); static::header('Access-Control-Max-Age', 86400); } // Access-Control headers are received during OPTIONS requests if (filter_input(INPUT_SERVER,'REQUEST_METHOD') == 'OPTIONS') { static::clean(); if (filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_METHOD')) { static::header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, PATCH, TRACE'); } if ($req_h = filter_input(INPUT_SERVER,'HTTP_ACCESS_CONTROL_REQUEST_HEADERS')) { static::header('Access-Control-Allow-Headers',$req_h); } self::trigger('cors.preflight'); static::send(); exit; } }
[ "public", "static", "function", "enableCORS", "(", "$", "origin", "=", "'*'", ")", "{", "// Allow from any origin", "if", "(", "$", "origin", "=", "$", "origin", "?", ":", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_ORIGIN'", "]", ")", "?", "$", "_SERVER", "[", "'HTTP_ORIGIN'", "]", ":", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", "?", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ":", "'*'", ")", ")", ")", "{", "static", "::", "header", "(", "'Access-Control-Allow-Origin'", ",", "$", "origin", ")", ";", "static", "::", "header", "(", "'Access-Control-Allow-Credentials'", ",", "'true'", ")", ";", "static", "::", "header", "(", "'Access-Control-Max-Age'", ",", "86400", ")", ";", "}", "// Access-Control headers are received during OPTIONS requests", "if", "(", "filter_input", "(", "INPUT_SERVER", ",", "'REQUEST_METHOD'", ")", "==", "'OPTIONS'", ")", "{", "static", "::", "clean", "(", ")", ";", "if", "(", "filter_input", "(", "INPUT_SERVER", ",", "'HTTP_ACCESS_CONTROL_REQUEST_METHOD'", ")", ")", "{", "static", "::", "header", "(", "'Access-Control-Allow-Methods'", ",", "'GET, POST, PUT, DELETE, OPTIONS, HEAD, CONNECT, PATCH, TRACE'", ")", ";", "}", "if", "(", "$", "req_h", "=", "filter_input", "(", "INPUT_SERVER", ",", "'HTTP_ACCESS_CONTROL_REQUEST_HEADERS'", ")", ")", "{", "static", "::", "header", "(", "'Access-Control-Allow-Headers'", ",", "$", "req_h", ")", ";", "}", "self", "::", "trigger", "(", "'cors.preflight'", ")", ";", "static", "::", "send", "(", ")", ";", "exit", ";", "}", "}" ]
Enable CORS HTTP headers.
[ "Enable", "CORS", "HTTP", "headers", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Response.php#L68-L96
train
caffeina-core/core
classes/Response.php
Response.json
public static function json($payload){ static::type(static::TYPE_JSON); static::$payload[] = json_encode($payload, Options::get('core.response.json_flags',JSON_NUMERIC_CHECK|JSON_BIGINT_AS_STRING)); }
php
public static function json($payload){ static::type(static::TYPE_JSON); static::$payload[] = json_encode($payload, Options::get('core.response.json_flags',JSON_NUMERIC_CHECK|JSON_BIGINT_AS_STRING)); }
[ "public", "static", "function", "json", "(", "$", "payload", ")", "{", "static", "::", "type", "(", "static", "::", "TYPE_JSON", ")", ";", "static", "::", "$", "payload", "[", "]", "=", "json_encode", "(", "$", "payload", ",", "Options", "::", "get", "(", "'core.response.json_flags'", ",", "JSON_NUMERIC_CHECK", "|", "JSON_BIGINT_AS_STRING", ")", ")", ";", "}" ]
Append a JSON object to the buffer. @param mixed $payload Data to append to the response buffer
[ "Append", "a", "JSON", "object", "to", "the", "buffer", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Response.php#L135-L138
train
caffeina-core/core
classes/Response.php
Response.load
public static function load($data){ $data = (object)$data; if (isset($data->head)) static::headers($data->head); if (isset($data->body)) static::body($data->body); }
php
public static function load($data){ $data = (object)$data; if (isset($data->head)) static::headers($data->head); if (isset($data->body)) static::body($data->body); }
[ "public", "static", "function", "load", "(", "$", "data", ")", "{", "$", "data", "=", "(", "object", ")", "$", "data", ";", "if", "(", "isset", "(", "$", "data", "->", "head", ")", ")", "static", "::", "headers", "(", "$", "data", "->", "head", ")", ";", "if", "(", "isset", "(", "$", "data", "->", "body", ")", ")", "static", "::", "body", "(", "$", "data", "->", "body", ")", ";", "}" ]
Load response from a saved state @method load @param array $data head/body saved state
[ "Load", "response", "from", "a", "saved", "state" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Response.php#L252-L256
train
caffeina-core/core
classes/Shell.php
Shell._compileCommand
protected static function _compileCommand($command,array $params){ $s = $w = []; foreach ($params as $p) { if ($p instanceof static) { $s[] = '$('.$p->getShellCommand().')'; } else if (is_array($p)) foreach ($p as $key => $value) { if(is_numeric($key)){ $w[] = '--'.$value; } else { if(is_bool($value)){ if($value) $w[] = '--'.$key; } else { $w[] = '--'.$key.'='.escapeshellarg($value); } } } else { $s[] = $p; } } return trim( '/usr/bin/env '.$command.' '.implode(' ',array_merge($w,$s)) ); }
php
protected static function _compileCommand($command,array $params){ $s = $w = []; foreach ($params as $p) { if ($p instanceof static) { $s[] = '$('.$p->getShellCommand().')'; } else if (is_array($p)) foreach ($p as $key => $value) { if(is_numeric($key)){ $w[] = '--'.$value; } else { if(is_bool($value)){ if($value) $w[] = '--'.$key; } else { $w[] = '--'.$key.'='.escapeshellarg($value); } } } else { $s[] = $p; } } return trim( '/usr/bin/env '.$command.' '.implode(' ',array_merge($w,$s)) ); }
[ "protected", "static", "function", "_compileCommand", "(", "$", "command", ",", "array", "$", "params", ")", "{", "$", "s", "=", "$", "w", "=", "[", "]", ";", "foreach", "(", "$", "params", "as", "$", "p", ")", "{", "if", "(", "$", "p", "instanceof", "static", ")", "{", "$", "s", "[", "]", "=", "'$('", ".", "$", "p", "->", "getShellCommand", "(", ")", ".", "')'", ";", "}", "else", "if", "(", "is_array", "(", "$", "p", ")", ")", "foreach", "(", "$", "p", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "w", "[", "]", "=", "'--'", ".", "$", "value", ";", "}", "else", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "if", "(", "$", "value", ")", "$", "w", "[", "]", "=", "'--'", ".", "$", "key", ";", "}", "else", "{", "$", "w", "[", "]", "=", "'--'", ".", "$", "key", ".", "'='", ".", "escapeshellarg", "(", "$", "value", ")", ";", "}", "}", "}", "else", "{", "$", "s", "[", "]", "=", "$", "p", ";", "}", "}", "return", "trim", "(", "'/usr/bin/env '", ".", "$", "command", ".", "' '", ".", "implode", "(", "' '", ",", "array_merge", "(", "$", "w", ",", "$", "s", ")", ")", ")", ";", "}" ]
Compile a shell command @param string $command @param array $params @return string
[ "Compile", "a", "shell", "command" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Shell.php#L25-L47
train
caffeina-core/core
classes/Shell.php
Shell.pipe
public static function pipe(/* ... */){ $cmd = []; foreach (func_get_args() as $item) { $cmd[] = ($item instanceof static)?$item->getShellCommand():$item; } return new static(implode(' | ',$cmd)); }
php
public static function pipe(/* ... */){ $cmd = []; foreach (func_get_args() as $item) { $cmd[] = ($item instanceof static)?$item->getShellCommand():$item; } return new static(implode(' | ',$cmd)); }
[ "public", "static", "function", "pipe", "(", "/* ... */", ")", "{", "$", "cmd", "=", "[", "]", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "item", ")", "{", "$", "cmd", "[", "]", "=", "(", "$", "item", "instanceof", "static", ")", "?", "$", "item", "->", "getShellCommand", "(", ")", ":", "$", "item", ";", "}", "return", "new", "static", "(", "implode", "(", "' | '", ",", "$", "cmd", ")", ")", ";", "}" ]
Concatenate multiple shell commands via piping @return Shell The piped shell command
[ "Concatenate", "multiple", "shell", "commands", "via", "piping" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Shell.php#L83-L89
train
caffeina-core/core
classes/View.php
View.from
public static function from($template,$data=null){ $view = new self($template); return $data ? $view->with($data) : $view; }
php
public static function from($template,$data=null){ $view = new self($template); return $data ? $view->with($data) : $view; }
[ "public", "static", "function", "from", "(", "$", "template", ",", "$", "data", "=", "null", ")", "{", "$", "view", "=", "new", "self", "(", "$", "template", ")", ";", "return", "$", "data", "?", "$", "view", "->", "with", "(", "$", "data", ")", ":", "$", "view", ";", "}" ]
View factory method, can optionally pass data to pre-init view @param string $template The template path @param array $data The key-value map of data to pass to the view @return View
[ "View", "factory", "method", "can", "optionally", "pass", "data", "to", "pre", "-", "init", "view" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/View.php#L48-L51
train
caffeina-core/core
classes/View.php
View.with
public function with($data){ if ($data){ $tmp = array_merge($data, (isset($this->options['data'])?$this->options['data']:[])); $this->options['data'] = $tmp; } return $this; }
php
public function with($data){ if ($data){ $tmp = array_merge($data, (isset($this->options['data'])?$this->options['data']:[])); $this->options['data'] = $tmp; } return $this; }
[ "public", "function", "with", "(", "$", "data", ")", "{", "if", "(", "$", "data", ")", "{", "$", "tmp", "=", "array_merge", "(", "$", "data", ",", "(", "isset", "(", "$", "this", "->", "options", "[", "'data'", "]", ")", "?", "$", "this", "->", "options", "[", "'data'", "]", ":", "[", "]", ")", ")", ";", "$", "this", "->", "options", "[", "'data'", "]", "=", "$", "tmp", ";", "}", "return", "$", "this", ";", "}" ]
Assigns data to the view @param array $data The key-value map of data to pass to the view @return View
[ "Assigns", "data", "to", "the", "view" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/View.php#L58-L64
train
spiral/storage
src/Server/FtpServer.php
FtpServer.connect
protected function connect() { if (!empty($this->conn)) { return; } if (!extension_loaded('ftp')) { throw new ServerException( "Unable to initialize ftp storage server, extension 'ftp' not found" ); } $conn = ftp_connect( $this->options['host'], $this->options['port'], $this->options['timeout'] ); if (empty($conn)) { throw new ServerException( "Unable to connect to remote FTP server '{$this->options['host']}'" ); } if (!ftp_login($conn, $this->options['username'], $this->options['password'])) { throw new ServerException( "Unable to authorize on remote FTP server '{$this->options['host']}'" ); } if (!ftp_pasv($conn, $this->options['passive'])) { throw new ServerException( "Unable to set passive mode at remote FTP server '{$this->options['host']}'" ); } $this->conn = $conn; }
php
protected function connect() { if (!empty($this->conn)) { return; } if (!extension_loaded('ftp')) { throw new ServerException( "Unable to initialize ftp storage server, extension 'ftp' not found" ); } $conn = ftp_connect( $this->options['host'], $this->options['port'], $this->options['timeout'] ); if (empty($conn)) { throw new ServerException( "Unable to connect to remote FTP server '{$this->options['host']}'" ); } if (!ftp_login($conn, $this->options['username'], $this->options['password'])) { throw new ServerException( "Unable to authorize on remote FTP server '{$this->options['host']}'" ); } if (!ftp_pasv($conn, $this->options['passive'])) { throw new ServerException( "Unable to set passive mode at remote FTP server '{$this->options['host']}'" ); } $this->conn = $conn; }
[ "protected", "function", "connect", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "conn", ")", ")", "{", "return", ";", "}", "if", "(", "!", "extension_loaded", "(", "'ftp'", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to initialize ftp storage server, extension 'ftp' not found\"", ")", ";", "}", "$", "conn", "=", "ftp_connect", "(", "$", "this", "->", "options", "[", "'host'", "]", ",", "$", "this", "->", "options", "[", "'port'", "]", ",", "$", "this", "->", "options", "[", "'timeout'", "]", ")", ";", "if", "(", "empty", "(", "$", "conn", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to connect to remote FTP server '{$this->options['host']}'\"", ")", ";", "}", "if", "(", "!", "ftp_login", "(", "$", "conn", ",", "$", "this", "->", "options", "[", "'username'", "]", ",", "$", "this", "->", "options", "[", "'password'", "]", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to authorize on remote FTP server '{$this->options['host']}'\"", ")", ";", "}", "if", "(", "!", "ftp_pasv", "(", "$", "conn", ",", "$", "this", "->", "options", "[", "'passive'", "]", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to set passive mode at remote FTP server '{$this->options['host']}'\"", ")", ";", "}", "$", "this", "->", "conn", "=", "$", "conn", ";", "}" ]
Ensure FTP connection. @throws ServerException
[ "Ensure", "FTP", "connection", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/FtpServer.php#L182-L219
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.withClient
public function withClient(ClientInterface $client): AmazonServer { $server = clone $this; $server->client = $client; return $this; }
php
public function withClient(ClientInterface $client): AmazonServer { $server = clone $this; $server->client = $client; return $this; }
[ "public", "function", "withClient", "(", "ClientInterface", "$", "client", ")", ":", "AmazonServer", "{", "$", "server", "=", "clone", "$", "this", ";", "$", "server", "->", "client", "=", "$", "client", ";", "return", "$", "this", ";", "}" ]
Version of driver with alternative client being set up. @param ClientInterface $client @return self
[ "Version", "of", "driver", "with", "alternative", "client", "being", "set", "up", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L68-L74
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.buildUri
protected function buildUri(BucketInterface $bucket, string $name): UriInterface { return new Uri( $this->options['server'] . '/' . $bucket->getOption('bucket') . '/' . rawurlencode($name) ); }
php
protected function buildUri(BucketInterface $bucket, string $name): UriInterface { return new Uri( $this->options['server'] . '/' . $bucket->getOption('bucket') . '/' . rawurlencode($name) ); }
[ "protected", "function", "buildUri", "(", "BucketInterface", "$", "bucket", ",", "string", "$", "name", ")", ":", "UriInterface", "{", "return", "new", "Uri", "(", "$", "this", "->", "options", "[", "'server'", "]", ".", "'/'", ".", "$", "bucket", "->", "getOption", "(", "'bucket'", ")", ".", "'/'", ".", "rawurlencode", "(", "$", "name", ")", ")", ";", "}" ]
Create instance of UriInterface based on provided bucket options and storage object name. @param BucketInterface $bucket @param string $name @return UriInterface
[ "Create", "instance", "of", "UriInterface", "based", "on", "provided", "bucket", "options", "and", "storage", "object", "name", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L201-L206
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.buildRequest
protected function buildRequest( string $method, BucketInterface $bucket, string $name, array $headers = [], array $commands = [] ): RequestInterface { $headers += [ 'Date' => gmdate('D, d M Y H:i:s T'), 'Content-MD5' => '', 'Content-Type' => '' ]; $packedCommands = $this->packCommands($commands); return $this->signRequest( new Request($method, $this->buildUri($bucket, $name), $headers + $packedCommands), $packedCommands ); }
php
protected function buildRequest( string $method, BucketInterface $bucket, string $name, array $headers = [], array $commands = [] ): RequestInterface { $headers += [ 'Date' => gmdate('D, d M Y H:i:s T'), 'Content-MD5' => '', 'Content-Type' => '' ]; $packedCommands = $this->packCommands($commands); return $this->signRequest( new Request($method, $this->buildUri($bucket, $name), $headers + $packedCommands), $packedCommands ); }
[ "protected", "function", "buildRequest", "(", "string", "$", "method", ",", "BucketInterface", "$", "bucket", ",", "string", "$", "name", ",", "array", "$", "headers", "=", "[", "]", ",", "array", "$", "commands", "=", "[", "]", ")", ":", "RequestInterface", "{", "$", "headers", "+=", "[", "'Date'", "=>", "gmdate", "(", "'D, d M Y H:i:s T'", ")", ",", "'Content-MD5'", "=>", "''", ",", "'Content-Type'", "=>", "''", "]", ";", "$", "packedCommands", "=", "$", "this", "->", "packCommands", "(", "$", "commands", ")", ";", "return", "$", "this", "->", "signRequest", "(", "new", "Request", "(", "$", "method", ",", "$", "this", "->", "buildUri", "(", "$", "bucket", ",", "$", "name", ")", ",", "$", "headers", "+", "$", "packedCommands", ")", ",", "$", "packedCommands", ")", ";", "}" ]
Helper to create configured PSR7 request with set of amazon commands. @param string $method @param BucketInterface $bucket @param string $name @param array $headers @param array $commands Amazon commands associated with values. @return RequestInterface
[ "Helper", "to", "create", "configured", "PSR7", "request", "with", "set", "of", "amazon", "commands", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L219-L238
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.packCommands
private function packCommands(array $commands): array { $headers = []; foreach ($commands as $command => $value) { $headers['X-Amz-' . $command] = $value; } return $headers; }
php
private function packCommands(array $commands): array { $headers = []; foreach ($commands as $command => $value) { $headers['X-Amz-' . $command] = $value; } return $headers; }
[ "private", "function", "packCommands", "(", "array", "$", "commands", ")", ":", "array", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "commands", "as", "$", "command", "=>", "$", "value", ")", "{", "$", "headers", "[", "'X-Amz-'", ".", "$", "command", "]", "=", "$", "value", ";", "}", "return", "$", "headers", ";", "}" ]
Generate request headers based on provided set of amazon commands. @param array $commands @return array
[ "Generate", "request", "headers", "based", "on", "provided", "set", "of", "amazon", "commands", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L247-L255
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.run
private function run(RequestInterface $request, array $skipCodes = []): ?ResponseInterface { try { return $this->client->send($request); } catch (GuzzleException $e) { if (in_array($e->getCode(), $skipCodes)) { return null; } throw new ServerException($e->getMessage(), $e->getCode(), $e); } }
php
private function run(RequestInterface $request, array $skipCodes = []): ?ResponseInterface { try { return $this->client->send($request); } catch (GuzzleException $e) { if (in_array($e->getCode(), $skipCodes)) { return null; } throw new ServerException($e->getMessage(), $e->getCode(), $e); } }
[ "private", "function", "run", "(", "RequestInterface", "$", "request", ",", "array", "$", "skipCodes", "=", "[", "]", ")", ":", "?", "ResponseInterface", "{", "try", "{", "return", "$", "this", "->", "client", "->", "send", "(", "$", "request", ")", ";", "}", "catch", "(", "GuzzleException", "$", "e", ")", "{", "if", "(", "in_array", "(", "$", "e", "->", "getCode", "(", ")", ",", "$", "skipCodes", ")", ")", "{", "return", "null", ";", "}", "throw", "new", "ServerException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Wrap guzzle errors into @param RequestInterface $request @param array $skipCodes Method should return null if code matched. @return ResponseInterface
[ "Wrap", "guzzle", "errors", "into" ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L264-L275
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.signRequest
private function signRequest( RequestInterface $request, array $packedCommands = [] ): RequestInterface { $signature = [ $request->getMethod(), $request->getHeaderLine('Content-MD5'), $request->getHeaderLine('Content-Type'), $request->getHeaderLine('Date') ]; $normalizedCommands = []; foreach ($packedCommands as $command => $value) { if (!empty($value)) { $normalizedCommands[] = strtolower($command) . ':' . $value; } } if (!empty($normalizedCommands)) { sort($normalizedCommands); $signature[] = join("\n", $normalizedCommands); } $signature[] = $request->getUri()->getPath(); return $request->withAddedHeader( 'Authorization', 'AWS ' . $this->options['key'] . ':' . base64_encode(hash_hmac( 'sha1', join("\n", $signature), $this->options['secret'], true )) ); }
php
private function signRequest( RequestInterface $request, array $packedCommands = [] ): RequestInterface { $signature = [ $request->getMethod(), $request->getHeaderLine('Content-MD5'), $request->getHeaderLine('Content-Type'), $request->getHeaderLine('Date') ]; $normalizedCommands = []; foreach ($packedCommands as $command => $value) { if (!empty($value)) { $normalizedCommands[] = strtolower($command) . ':' . $value; } } if (!empty($normalizedCommands)) { sort($normalizedCommands); $signature[] = join("\n", $normalizedCommands); } $signature[] = $request->getUri()->getPath(); return $request->withAddedHeader( 'Authorization', 'AWS ' . $this->options['key'] . ':' . base64_encode(hash_hmac( 'sha1', join("\n", $signature), $this->options['secret'], true )) ); }
[ "private", "function", "signRequest", "(", "RequestInterface", "$", "request", ",", "array", "$", "packedCommands", "=", "[", "]", ")", ":", "RequestInterface", "{", "$", "signature", "=", "[", "$", "request", "->", "getMethod", "(", ")", ",", "$", "request", "->", "getHeaderLine", "(", "'Content-MD5'", ")", ",", "$", "request", "->", "getHeaderLine", "(", "'Content-Type'", ")", ",", "$", "request", "->", "getHeaderLine", "(", "'Date'", ")", "]", ";", "$", "normalizedCommands", "=", "[", "]", ";", "foreach", "(", "$", "packedCommands", "as", "$", "command", "=>", "$", "value", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "normalizedCommands", "[", "]", "=", "strtolower", "(", "$", "command", ")", ".", "':'", ".", "$", "value", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "normalizedCommands", ")", ")", "{", "sort", "(", "$", "normalizedCommands", ")", ";", "$", "signature", "[", "]", "=", "join", "(", "\"\\n\"", ",", "$", "normalizedCommands", ")", ";", "}", "$", "signature", "[", "]", "=", "$", "request", "->", "getUri", "(", ")", "->", "getPath", "(", ")", ";", "return", "$", "request", "->", "withAddedHeader", "(", "'Authorization'", ",", "'AWS '", ".", "$", "this", "->", "options", "[", "'key'", "]", ".", "':'", ".", "base64_encode", "(", "hash_hmac", "(", "'sha1'", ",", "join", "(", "\"\\n\"", ",", "$", "signature", ")", ",", "$", "this", "->", "options", "[", "'secret'", "]", ",", "true", ")", ")", ")", ";", "}" ]
Sign amazon request. @param RequestInterface $request @param array $packedCommands Headers generated based on request commands, see packCommands() method for more information. @return RequestInterface
[ "Sign", "amazon", "request", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L286-L320
train
spiral/storage
src/Server/AmazonServer.php
AmazonServer.createHeaders
private function createHeaders(BucketInterface $bucket, string $name, StreamInterface $stream): array { if (empty($mimetype = mimetype_from_filename($name))) { $mimetype = self::DEFAULT_MIMETYPE; }; //Possible to add custom headers into the bucket $headers = $bucket->getOption('headers', []); if (!empty($maxAge = $bucket->getOption('maxAge', 0))) { //Shortcut $headers['Cache-control'] = 'max-age=' . $bucket->getOption('maxAge', 0) . ', public'; $headers['Expires'] = gmdate( 'D, d M Y H:i:s T', time() + $bucket->getOption('maxAge', 0) ); } $stream->rewind(); return $headers + [ 'Content-MD5' => base64_encode(md5($stream->getContents(), true)), 'Content-Type' => $mimetype ]; }
php
private function createHeaders(BucketInterface $bucket, string $name, StreamInterface $stream): array { if (empty($mimetype = mimetype_from_filename($name))) { $mimetype = self::DEFAULT_MIMETYPE; }; //Possible to add custom headers into the bucket $headers = $bucket->getOption('headers', []); if (!empty($maxAge = $bucket->getOption('maxAge', 0))) { //Shortcut $headers['Cache-control'] = 'max-age=' . $bucket->getOption('maxAge', 0) . ', public'; $headers['Expires'] = gmdate( 'D, d M Y H:i:s T', time() + $bucket->getOption('maxAge', 0) ); } $stream->rewind(); return $headers + [ 'Content-MD5' => base64_encode(md5($stream->getContents(), true)), 'Content-Type' => $mimetype ]; }
[ "private", "function", "createHeaders", "(", "BucketInterface", "$", "bucket", ",", "string", "$", "name", ",", "StreamInterface", "$", "stream", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "mimetype", "=", "mimetype_from_filename", "(", "$", "name", ")", ")", ")", "{", "$", "mimetype", "=", "self", "::", "DEFAULT_MIMETYPE", ";", "}", ";", "//Possible to add custom headers into the bucket", "$", "headers", "=", "$", "bucket", "->", "getOption", "(", "'headers'", ",", "[", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "maxAge", "=", "$", "bucket", "->", "getOption", "(", "'maxAge'", ",", "0", ")", ")", ")", "{", "//Shortcut", "$", "headers", "[", "'Cache-control'", "]", "=", "'max-age='", ".", "$", "bucket", "->", "getOption", "(", "'maxAge'", ",", "0", ")", ".", "', public'", ";", "$", "headers", "[", "'Expires'", "]", "=", "gmdate", "(", "'D, d M Y H:i:s T'", ",", "time", "(", ")", "+", "$", "bucket", "->", "getOption", "(", "'maxAge'", ",", "0", ")", ")", ";", "}", "$", "stream", "->", "rewind", "(", ")", ";", "return", "$", "headers", "+", "[", "'Content-MD5'", "=>", "base64_encode", "(", "md5", "(", "$", "stream", "->", "getContents", "(", ")", ",", "true", ")", ")", ",", "'Content-Type'", "=>", "$", "mimetype", "]", ";", "}" ]
Generate object headers. @param BucketInterface $bucket @param string $name @param StreamInterface $stream @return array
[ "Generate", "object", "headers", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/AmazonServer.php#L331-L355
train
caffeina-core/core
classes/Hash.php
Hash.make
public static function make($payload, $method = 'md5', $raw_output = false) { return $method == 'murmur' ? static::murmur(serialize($payload)) : hash($method, serialize($payload), $raw_output); }
php
public static function make($payload, $method = 'md5', $raw_output = false) { return $method == 'murmur' ? static::murmur(serialize($payload)) : hash($method, serialize($payload), $raw_output); }
[ "public", "static", "function", "make", "(", "$", "payload", ",", "$", "method", "=", "'md5'", ",", "$", "raw_output", "=", "false", ")", "{", "return", "$", "method", "==", "'murmur'", "?", "static", "::", "murmur", "(", "serialize", "(", "$", "payload", ")", ")", ":", "hash", "(", "$", "method", ",", "serialize", "(", "$", "payload", ")", ",", "$", "raw_output", ")", ";", "}" ]
Create ah hash for payload @param mixed $payload The payload string/object/array @param integer $method The hashing method, default is "md5" @param bool $raw_output When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits. @return string The hash string
[ "Create", "ah", "hash", "for", "payload" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Hash.php#L23-L25
train
spiral/storage
src/Server/SftpServer.php
SftpServer.connect
protected function connect() { if (!empty($this->conn)) { return; } if (!extension_loaded('ssh2')) { throw new ServerException( "Unable to initialize sftp storage server, extension 'ssh2' not found" ); } $session = ssh2_connect( $this->options['host'], $this->options['port'], $this->options['methods'] ); if (empty($session)) { throw new ServerException( "Unable to connect to remote SSH server '{$this->options['host']}'" ); } //Authorization switch ($this->options['authMethod']) { case self::NONE: ssh2_auth_none($session, $this->options['username']); break; case self::PASSWORD: ssh2_auth_password( $session, $this->options['username'], $this->options['password'] ); break; case self::PUB_KEY: ssh2_auth_pubkey_file( $session, $this->options['username'], $this->options['publicKey'], $this->options['privateKey'], $this->options['secret'] ); break; } $this->conn = ssh2_sftp($session); }
php
protected function connect() { if (!empty($this->conn)) { return; } if (!extension_loaded('ssh2')) { throw new ServerException( "Unable to initialize sftp storage server, extension 'ssh2' not found" ); } $session = ssh2_connect( $this->options['host'], $this->options['port'], $this->options['methods'] ); if (empty($session)) { throw new ServerException( "Unable to connect to remote SSH server '{$this->options['host']}'" ); } //Authorization switch ($this->options['authMethod']) { case self::NONE: ssh2_auth_none($session, $this->options['username']); break; case self::PASSWORD: ssh2_auth_password( $session, $this->options['username'], $this->options['password'] ); break; case self::PUB_KEY: ssh2_auth_pubkey_file( $session, $this->options['username'], $this->options['publicKey'], $this->options['privateKey'], $this->options['secret'] ); break; } $this->conn = ssh2_sftp($session); }
[ "protected", "function", "connect", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "conn", ")", ")", "{", "return", ";", "}", "if", "(", "!", "extension_loaded", "(", "'ssh2'", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to initialize sftp storage server, extension 'ssh2' not found\"", ")", ";", "}", "$", "session", "=", "ssh2_connect", "(", "$", "this", "->", "options", "[", "'host'", "]", ",", "$", "this", "->", "options", "[", "'port'", "]", ",", "$", "this", "->", "options", "[", "'methods'", "]", ")", ";", "if", "(", "empty", "(", "$", "session", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to connect to remote SSH server '{$this->options['host']}'\"", ")", ";", "}", "//Authorization", "switch", "(", "$", "this", "->", "options", "[", "'authMethod'", "]", ")", "{", "case", "self", "::", "NONE", ":", "ssh2_auth_none", "(", "$", "session", ",", "$", "this", "->", "options", "[", "'username'", "]", ")", ";", "break", ";", "case", "self", "::", "PASSWORD", ":", "ssh2_auth_password", "(", "$", "session", ",", "$", "this", "->", "options", "[", "'username'", "]", ",", "$", "this", "->", "options", "[", "'password'", "]", ")", ";", "break", ";", "case", "self", "::", "PUB_KEY", ":", "ssh2_auth_pubkey_file", "(", "$", "session", ",", "$", "this", "->", "options", "[", "'username'", "]", ",", "$", "this", "->", "options", "[", "'publicKey'", "]", ",", "$", "this", "->", "options", "[", "'privateKey'", "]", ",", "$", "this", "->", "options", "[", "'secret'", "]", ")", ";", "break", ";", "}", "$", "this", "->", "conn", "=", "ssh2_sftp", "(", "$", "session", ")", ";", "}" ]
Ensure that SSH connection is up and can be used for file operations. @throws ServerException
[ "Ensure", "that", "SSH", "connection", "is", "up", "and", "can", "be", "used", "for", "file", "operations", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/SftpServer.php#L178-L228
train
spiral/storage
src/Server/SftpServer.php
SftpServer.castRemoteFilename
protected function castRemoteFilename(BucketInterface $bucket, string $name): string { return 'ssh2.sftp://' . $this->conn . $this->castPath($bucket, $name); }
php
protected function castRemoteFilename(BucketInterface $bucket, string $name): string { return 'ssh2.sftp://' . $this->conn . $this->castPath($bucket, $name); }
[ "protected", "function", "castRemoteFilename", "(", "BucketInterface", "$", "bucket", ",", "string", "$", "name", ")", ":", "string", "{", "return", "'ssh2.sftp://'", ".", "$", "this", "->", "conn", ".", "$", "this", "->", "castPath", "(", "$", "bucket", ",", "$", "name", ")", ";", "}" ]
Get ssh2 specific uri which can be used in default php functions. Assigned to ssh2.sftp stream wrapper. @param BucketInterface $bucket @param string $name @return string
[ "Get", "ssh2", "specific", "uri", "which", "can", "be", "used", "in", "default", "php", "functions", ".", "Assigned", "to", "ssh2", ".", "sftp", "stream", "wrapper", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/SftpServer.php#L239-L242
train
caffeina-core/core
classes/Loader.php
Loader.register
public static function register(){ ini_set('unserialize_callback_func', 'spl_autoload_call'); spl_autoload_register(function($class){ $cfile = strtr($class,'_\\','//') . '.php'; foreach (static::$paths as $path => $v) { $file = rtrim($path,'/').'/'.$cfile; if(is_file($file)) return include($file); } return false; },false,true); }
php
public static function register(){ ini_set('unserialize_callback_func', 'spl_autoload_call'); spl_autoload_register(function($class){ $cfile = strtr($class,'_\\','//') . '.php'; foreach (static::$paths as $path => $v) { $file = rtrim($path,'/').'/'.$cfile; if(is_file($file)) return include($file); } return false; },false,true); }
[ "public", "static", "function", "register", "(", ")", "{", "ini_set", "(", "'unserialize_callback_func'", ",", "'spl_autoload_call'", ")", ";", "spl_autoload_register", "(", "function", "(", "$", "class", ")", "{", "$", "cfile", "=", "strtr", "(", "$", "class", ",", "'_\\\\'", ",", "'//'", ")", ".", "'.php'", ";", "foreach", "(", "static", "::", "$", "paths", "as", "$", "path", "=>", "$", "v", ")", "{", "$", "file", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ".", "'/'", ".", "$", "cfile", ";", "if", "(", "is_file", "(", "$", "file", ")", ")", "return", "include", "(", "$", "file", ")", ";", "}", "return", "false", ";", "}", ",", "false", ",", "true", ")", ";", "}" ]
Register core autoloader @return bool Returns false if autoloader failed inclusion
[ "Register", "core", "autoloader" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Loader.php#L29-L39
train
caffeina-core/core
classes/Cache.php
Cache.using
public static function using($driver){ foreach((array)$driver as $key => $value){ if(is_numeric($key)){ $drv = $value; $conf = []; } else { $drv = $key; $conf = $value; } $class = 'Cache\\' . ucfirst(strtolower($drv)); if(class_exists($class) && $class::valid()) { static::$driver = new $class($conf); return true; } } return false; }
php
public static function using($driver){ foreach((array)$driver as $key => $value){ if(is_numeric($key)){ $drv = $value; $conf = []; } else { $drv = $key; $conf = $value; } $class = 'Cache\\' . ucfirst(strtolower($drv)); if(class_exists($class) && $class::valid()) { static::$driver = new $class($conf); return true; } } return false; }
[ "public", "static", "function", "using", "(", "$", "driver", ")", "{", "foreach", "(", "(", "array", ")", "$", "driver", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "drv", "=", "$", "value", ";", "$", "conf", "=", "[", "]", ";", "}", "else", "{", "$", "drv", "=", "$", "key", ";", "$", "conf", "=", "$", "value", ";", "}", "$", "class", "=", "'Cache\\\\'", ".", "ucfirst", "(", "strtolower", "(", "$", "drv", ")", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", "&&", "$", "class", "::", "valid", "(", ")", ")", "{", "static", "::", "$", "driver", "=", "new", "$", "class", "(", "$", "conf", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Load cache drivers with a FCFS strategy @method using @param mixed $driver can be a single driver name string, an array of driver names or a map [ driver_name => driver_options array ] @return bool true if a driver was loaded @example Cache::using('redis'); Cache::using(['redis','files','memory']); // Prefer "redis" over "files" over "memory" caching Cache::using([ 'redis' => [ 'host' => '127.0.0.1', 'prefix' => 'mycache', ], 'files' => [ 'cache_dir' => '/tmp', ], 'memory' ]);
[ "Load", "cache", "drivers", "with", "a", "FCFS", "strategy" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Cache.php#L57-L73
train
spiral/storage
src/Server/LocalServer.php
LocalServer.internalMove
protected function internalMove( BucketInterface $bucket, string $filename, string $destination ): bool { if (!$this->files->exists($filename)) { throw new ServerException("Unable to move '{$filename}', object does not exists"); } $mode = $bucket->getOption('mode', FilesInterface::RUNTIME); //Pre-ensuring location $this->files->ensureDirectory(dirname($destination), $mode); if (!$this->files->move($filename, $destination)) { throw new ServerException("Unable to move '{$filename}' to '{$destination}'."); } return $this->files->setPermissions($destination, $mode); }
php
protected function internalMove( BucketInterface $bucket, string $filename, string $destination ): bool { if (!$this->files->exists($filename)) { throw new ServerException("Unable to move '{$filename}', object does not exists"); } $mode = $bucket->getOption('mode', FilesInterface::RUNTIME); //Pre-ensuring location $this->files->ensureDirectory(dirname($destination), $mode); if (!$this->files->move($filename, $destination)) { throw new ServerException("Unable to move '{$filename}' to '{$destination}'."); } return $this->files->setPermissions($destination, $mode); }
[ "protected", "function", "internalMove", "(", "BucketInterface", "$", "bucket", ",", "string", "$", "filename", ",", "string", "$", "destination", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "files", "->", "exists", "(", "$", "filename", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to move '{$filename}', object does not exists\"", ")", ";", "}", "$", "mode", "=", "$", "bucket", "->", "getOption", "(", "'mode'", ",", "FilesInterface", "::", "RUNTIME", ")", ";", "//Pre-ensuring location", "$", "this", "->", "files", "->", "ensureDirectory", "(", "dirname", "(", "$", "destination", ")", ",", "$", "mode", ")", ";", "if", "(", "!", "$", "this", "->", "files", "->", "move", "(", "$", "filename", ",", "$", "destination", ")", ")", "{", "throw", "new", "ServerException", "(", "\"Unable to move '{$filename}' to '{$destination}'.\"", ")", ";", "}", "return", "$", "this", "->", "files", "->", "setPermissions", "(", "$", "destination", ",", "$", "mode", ")", ";", "}" ]
Move helper, ensure target directory existence, file permissions and etc. @param BucketInterface $bucket @param string $filename @param string $destination @return bool @throws ServerException
[ "Move", "helper", "ensure", "target", "directory", "existence", "file", "permissions", "and", "etc", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/LocalServer.php#L153-L172
train
spiral/storage
src/Config/StorageConfig.php
StorageConfig.getBucket
public function getBucket(string $name): array { if (!$this->hasBucket($name)) { throw new ConfigException("Undefined bucket `{$name}`"); } $bucket = $this->config['buckets'][$name]; if (!array_key_exists('options', $bucket)) { throw new ConfigException("Bucket `{$name}` must specify `options`"); } if (!array_key_exists('prefix', $bucket)) { throw new ConfigException("Bucket `{$name}` must specify `prefix`"); } if (!array_key_exists('server', $bucket)) { throw new ConfigException("Bucket `{$name}` must specify `server` name."); } return $bucket; }
php
public function getBucket(string $name): array { if (!$this->hasBucket($name)) { throw new ConfigException("Undefined bucket `{$name}`"); } $bucket = $this->config['buckets'][$name]; if (!array_key_exists('options', $bucket)) { throw new ConfigException("Bucket `{$name}` must specify `options`"); } if (!array_key_exists('prefix', $bucket)) { throw new ConfigException("Bucket `{$name}` must specify `prefix`"); } if (!array_key_exists('server', $bucket)) { throw new ConfigException("Bucket `{$name}` must specify `server` name."); } return $bucket; }
[ "public", "function", "getBucket", "(", "string", "$", "name", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "hasBucket", "(", "$", "name", ")", ")", "{", "throw", "new", "ConfigException", "(", "\"Undefined bucket `{$name}`\"", ")", ";", "}", "$", "bucket", "=", "$", "this", "->", "config", "[", "'buckets'", "]", "[", "$", "name", "]", ";", "if", "(", "!", "array_key_exists", "(", "'options'", ",", "$", "bucket", ")", ")", "{", "throw", "new", "ConfigException", "(", "\"Bucket `{$name}` must specify `options`\"", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'prefix'", ",", "$", "bucket", ")", ")", "{", "throw", "new", "ConfigException", "(", "\"Bucket `{$name}` must specify `prefix`\"", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'server'", ",", "$", "bucket", ")", ")", "{", "throw", "new", "ConfigException", "(", "\"Bucket `{$name}` must specify `server` name.\"", ")", ";", "}", "return", "$", "bucket", ";", "}" ]
Get bucket options. @param string $name @return array @throws ConfigException
[ "Get", "bucket", "options", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Config/StorageConfig.php#L98-L119
train
spiral/storage
src/Config/BucketResolver.php
BucketResolver.resolveBucket
public function resolveBucket(string $address, string &$name = null): string { $bucket = null; $length = 0; foreach ($this->prefixes as $id => $prefix) { if (strpos($address, $prefix) === 0 && strlen($prefix) > $length) { $bucket = $id; $length = strlen($prefix); } } if (empty($bucket)) { throw new ResolveException("Unable to resolve bucket of `{$address}`."); } $name = substr($address, $length); return $bucket; }
php
public function resolveBucket(string $address, string &$name = null): string { $bucket = null; $length = 0; foreach ($this->prefixes as $id => $prefix) { if (strpos($address, $prefix) === 0 && strlen($prefix) > $length) { $bucket = $id; $length = strlen($prefix); } } if (empty($bucket)) { throw new ResolveException("Unable to resolve bucket of `{$address}`."); } $name = substr($address, $length); return $bucket; }
[ "public", "function", "resolveBucket", "(", "string", "$", "address", ",", "string", "&", "$", "name", "=", "null", ")", ":", "string", "{", "$", "bucket", "=", "null", ";", "$", "length", "=", "0", ";", "foreach", "(", "$", "this", "->", "prefixes", "as", "$", "id", "=>", "$", "prefix", ")", "{", "if", "(", "strpos", "(", "$", "address", ",", "$", "prefix", ")", "===", "0", "&&", "strlen", "(", "$", "prefix", ")", ">", "$", "length", ")", "{", "$", "bucket", "=", "$", "id", ";", "$", "length", "=", "strlen", "(", "$", "prefix", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "bucket", ")", ")", "{", "throw", "new", "ResolveException", "(", "\"Unable to resolve bucket of `{$address}`.\"", ")", ";", "}", "$", "name", "=", "substr", "(", "$", "address", ",", "$", "length", ")", ";", "return", "$", "bucket", ";", "}" ]
Locate bucket name using object address. @param string $address @param string $name @return string @throws ResolveException
[ "Locate", "bucket", "name", "using", "object", "address", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Config/BucketResolver.php#L49-L67
train
spiral/storage
src/StorageBucket.php
StorageBucket.castStream
protected function castStream($source): StreamInterface { if ($source instanceof UploadedFileInterface || $source instanceof StreamableInterface) { $source = $source->getStream(); } if ($source instanceof StreamInterface) { //This step is important to prevent user errors $source->rewind(); return $source; } if (is_resource($source)) { return stream_for($source); } if (empty($source)) { //Guzzle? return stream_for(''); } if ($this->isFilename($source)) { //Must never pass user string in here, use Stream return stream_for(fopen($source, 'rb')); } //We do not allow source names in a string form throw new BucketException( "Source must be a valid resource, stream or filename, invalid value given" ); }
php
protected function castStream($source): StreamInterface { if ($source instanceof UploadedFileInterface || $source instanceof StreamableInterface) { $source = $source->getStream(); } if ($source instanceof StreamInterface) { //This step is important to prevent user errors $source->rewind(); return $source; } if (is_resource($source)) { return stream_for($source); } if (empty($source)) { //Guzzle? return stream_for(''); } if ($this->isFilename($source)) { //Must never pass user string in here, use Stream return stream_for(fopen($source, 'rb')); } //We do not allow source names in a string form throw new BucketException( "Source must be a valid resource, stream or filename, invalid value given" ); }
[ "protected", "function", "castStream", "(", "$", "source", ")", ":", "StreamInterface", "{", "if", "(", "$", "source", "instanceof", "UploadedFileInterface", "||", "$", "source", "instanceof", "StreamableInterface", ")", "{", "$", "source", "=", "$", "source", "->", "getStream", "(", ")", ";", "}", "if", "(", "$", "source", "instanceof", "StreamInterface", ")", "{", "//This step is important to prevent user errors", "$", "source", "->", "rewind", "(", ")", ";", "return", "$", "source", ";", "}", "if", "(", "is_resource", "(", "$", "source", ")", ")", "{", "return", "stream_for", "(", "$", "source", ")", ";", "}", "if", "(", "empty", "(", "$", "source", ")", ")", "{", "//Guzzle?", "return", "stream_for", "(", "''", ")", ";", "}", "if", "(", "$", "this", "->", "isFilename", "(", "$", "source", ")", ")", "{", "//Must never pass user string in here, use Stream", "return", "stream_for", "(", "fopen", "(", "$", "source", ",", "'rb'", ")", ")", ";", "}", "//We do not allow source names in a string form", "throw", "new", "BucketException", "(", "\"Source must be a valid resource, stream or filename, invalid value given\"", ")", ";", "}" ]
Cast stream associated with origin data. @param string|StreamInterface|resource $source @return StreamInterface
[ "Cast", "stream", "associated", "with", "origin", "data", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/StorageBucket.php#L381-L412
train
spiral/storage
src/StorageBucket.php
StorageBucket.isFilename
protected function isFilename($source): bool { if (!is_string($source)) { return false; } if (!preg_match('/[^A-Za-z0-9.#\\-$]/', $source)) { return false; } //To filter out binary strings $source = strval(str_replace("\0", "", $source)); return file_exists($source); }
php
protected function isFilename($source): bool { if (!is_string($source)) { return false; } if (!preg_match('/[^A-Za-z0-9.#\\-$]/', $source)) { return false; } //To filter out binary strings $source = strval(str_replace("\0", "", $source)); return file_exists($source); }
[ "protected", "function", "isFilename", "(", "$", "source", ")", ":", "bool", "{", "if", "(", "!", "is_string", "(", "$", "source", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "preg_match", "(", "'/[^A-Za-z0-9.#\\\\-$]/'", ",", "$", "source", ")", ")", "{", "return", "false", ";", "}", "//To filter out binary strings", "$", "source", "=", "strval", "(", "str_replace", "(", "\"\\0\"", ",", "\"\"", ",", "$", "source", ")", ")", ";", "return", "file_exists", "(", "$", "source", ")", ";", "}" ]
Check if given string is proper filename. @param mixed $source @return bool
[ "Check", "if", "given", "string", "is", "proper", "filename", "." ]
65b8336ea45bee9c3fef591bd8e317308774a841
https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/StorageBucket.php#L421-L435
train
caffeina-core/core
classes/CLI.php
CLI.on
public static function on($command,callable $callback,$description=''){ $parts = preg_split('/\s+/',$command); static::$commands[array_shift($parts)] = [$parts,$callback,$description]; }
php
public static function on($command,callable $callback,$description=''){ $parts = preg_split('/\s+/',$command); static::$commands[array_shift($parts)] = [$parts,$callback,$description]; }
[ "public", "static", "function", "on", "(", "$", "command", ",", "callable", "$", "callback", ",", "$", "description", "=", "''", ")", "{", "$", "parts", "=", "preg_split", "(", "'/\\s+/'", ",", "$", "command", ")", ";", "static", "::", "$", "commands", "[", "array_shift", "(", "$", "parts", ")", "]", "=", "[", "$", "parts", ",", "$", "callback", ",", "$", "description", "]", ";", "}" ]
Bind a callback to a command route @param string $command The command route, use ":" before a parameter for extraction. @param callable $callback The callback to be binded to the route.
[ "Bind", "a", "callback", "to", "a", "command", "route" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/CLI.php#L45-L48
train
caffeina-core/core
classes/CLI.php
CLI.help
public static function help(callable $callback = null){ $callback ? is_callable($callback) && static::$help = $callback : static::$help && call_user_func(static::$help); }
php
public static function help(callable $callback = null){ $callback ? is_callable($callback) && static::$help = $callback : static::$help && call_user_func(static::$help); }
[ "public", "static", "function", "help", "(", "callable", "$", "callback", "=", "null", ")", "{", "$", "callback", "?", "is_callable", "(", "$", "callback", ")", "&&", "static", "::", "$", "help", "=", "$", "callback", ":", "static", "::", "$", "help", "&&", "call_user_func", "(", "static", "::", "$", "help", ")", ";", "}" ]
Bind a callback to the "help" route. @param callable $callback The callback to be binded to the route. If omitted triggers the callback.
[ "Bind", "a", "callback", "to", "the", "help", "route", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/CLI.php#L54-L58
train
caffeina-core/core
classes/CLI.php
CLI.error
public static function error(callable $callback = null){ $callback ? is_callable($callback) && static::$error = $callback : static::$error && call_user_func(static::$error); }
php
public static function error(callable $callback = null){ $callback ? is_callable($callback) && static::$error = $callback : static::$error && call_user_func(static::$error); }
[ "public", "static", "function", "error", "(", "callable", "$", "callback", "=", "null", ")", "{", "$", "callback", "?", "is_callable", "(", "$", "callback", ")", "&&", "static", "::", "$", "error", "=", "$", "callback", ":", "static", "::", "$", "error", "&&", "call_user_func", "(", "static", "::", "$", "error", ")", ";", "}" ]
Bind a callback when an error occurs. @param callable $callback The callback to be binded to the route. If omitted triggers the callback.
[ "Bind", "a", "callback", "when", "an", "error", "occurs", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/CLI.php#L64-L68
train
caffeina-core/core
classes/CLI.php
CLI.input
public static function input($key=null,$default=null){ return $key ? (isset(static::$options[$key]) ? static::$options[$key] : (is_callable($default)?call_user_func($default):$default)) : static::$options; }
php
public static function input($key=null,$default=null){ return $key ? (isset(static::$options[$key]) ? static::$options[$key] : (is_callable($default)?call_user_func($default):$default)) : static::$options; }
[ "public", "static", "function", "input", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "return", "$", "key", "?", "(", "isset", "(", "static", "::", "$", "options", "[", "$", "key", "]", ")", "?", "static", "::", "$", "options", "[", "$", "key", "]", ":", "(", "is_callable", "(", "$", "default", ")", "?", "call_user_func", "(", "$", "default", ")", ":", "$", "default", ")", ")", ":", "static", "::", "$", "options", ";", "}" ]
Get a passed option @param string $key The name of the option paramenter @param mixed $default The default value if parameter is omitted. (if a callable it will be evaluated) @return mixed
[ "Get", "a", "passed", "option" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/CLI.php#L93-L95
train
caffeina-core/core
classes/CLI.php
CLI.commands
public static function commands(){ $results = []; foreach(static::$commands as $name => $cmd){ $results[] = [ 'name' => $name, 'params' => preg_replace('/:(\w+)/','[$1]',implode(' ',$cmd[0])), 'description' => $cmd[2], ]; } return $results; }
php
public static function commands(){ $results = []; foreach(static::$commands as $name => $cmd){ $results[] = [ 'name' => $name, 'params' => preg_replace('/:(\w+)/','[$1]',implode(' ',$cmd[0])), 'description' => $cmd[2], ]; } return $results; }
[ "public", "static", "function", "commands", "(", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "static", "::", "$", "commands", "as", "$", "name", "=>", "$", "cmd", ")", "{", "$", "results", "[", "]", "=", "[", "'name'", "=>", "$", "name", ",", "'params'", "=>", "preg_replace", "(", "'/:(\\w+)/'", ",", "'[$1]'", ",", "implode", "(", "' '", ",", "$", "cmd", "[", "0", "]", ")", ")", ",", "'description'", "=>", "$", "cmd", "[", "2", "]", ",", "]", ";", "}", "return", "$", "results", ";", "}" ]
Returns an explanation for the supported commands @method commands @return array The commands and their description.
[ "Returns", "an", "explanation", "for", "the", "supported", "commands" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/CLI.php#L104-L114
train
caffeina-core/core
classes/CLI.php
CLI.write
public static function write($message){ if( preg_match('~<[^>]+>~',$message)) { // Use preg_replace_callback for fast regex matches navigation echo strtr(preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){ static::write($m[1]); $color = strtoupper(trim($m[2])); if( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color]; static::$color_stack[] = $color; static::write($m[3]); array_pop(static::$color_stack); $back_color = array_pop(static::$color_stack) ?: static::$color_stack[]='NORMAL'; if( isset(static::$shell_colors[$back_color]) ) echo static::$shell_colors[$back_color]; static::write($m[4]); },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]); } else { echo strtr($message,["&BR;"=>PHP_EOL]); } }
php
public static function write($message){ if( preg_match('~<[^>]+>~',$message)) { // Use preg_replace_callback for fast regex matches navigation echo strtr(preg_replace_callback('~^(.*)<([^>]+)>(.+)</\2>(.*)$~USm',function($m){ static::write($m[1]); $color = strtoupper(trim($m[2])); if( isset(static::$shell_colors[$color]) ) echo static::$shell_colors[$color]; static::$color_stack[] = $color; static::write($m[3]); array_pop(static::$color_stack); $back_color = array_pop(static::$color_stack) ?: static::$color_stack[]='NORMAL'; if( isset(static::$shell_colors[$back_color]) ) echo static::$shell_colors[$back_color]; static::write($m[4]); },strtr($message,["\n"=>"&BR;"])),["&BR;"=>PHP_EOL]); } else { echo strtr($message,["&BR;"=>PHP_EOL]); } }
[ "public", "static", "function", "write", "(", "$", "message", ")", "{", "if", "(", "preg_match", "(", "'~<[^>]+>~'", ",", "$", "message", ")", ")", "{", "// Use preg_replace_callback for fast regex matches navigation", "echo", "strtr", "(", "preg_replace_callback", "(", "'~^(.*)<([^>]+)>(.+)</\\2>(.*)$~USm'", ",", "function", "(", "$", "m", ")", "{", "static", "::", "write", "(", "$", "m", "[", "1", "]", ")", ";", "$", "color", "=", "strtoupper", "(", "trim", "(", "$", "m", "[", "2", "]", ")", ")", ";", "if", "(", "isset", "(", "static", "::", "$", "shell_colors", "[", "$", "color", "]", ")", ")", "echo", "static", "::", "$", "shell_colors", "[", "$", "color", "]", ";", "static", "::", "$", "color_stack", "[", "]", "=", "$", "color", ";", "static", "::", "write", "(", "$", "m", "[", "3", "]", ")", ";", "array_pop", "(", "static", "::", "$", "color_stack", ")", ";", "$", "back_color", "=", "array_pop", "(", "static", "::", "$", "color_stack", ")", "?", ":", "static", "::", "$", "color_stack", "[", "]", "=", "'NORMAL'", ";", "if", "(", "isset", "(", "static", "::", "$", "shell_colors", "[", "$", "back_color", "]", ")", ")", "echo", "static", "::", "$", "shell_colors", "[", "$", "back_color", "]", ";", "static", "::", "write", "(", "$", "m", "[", "4", "]", ")", ";", "}", ",", "strtr", "(", "$", "message", ",", "[", "\"\\n\"", "=>", "\"&BR;\"", "]", ")", ")", ",", "[", "\"&BR;\"", "=>", "PHP_EOL", "]", ")", ";", "}", "else", "{", "echo", "strtr", "(", "$", "message", ",", "[", "\"&BR;\"", "=>", "PHP_EOL", "]", ")", ";", "}", "}" ]
Prints a message to the console with color formatting. @param string $message The html-like encoded message @return void
[ "Prints", "a", "message", "to", "the", "console", "with", "color", "formatting", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/CLI.php#L169-L186
train
caffeina-core/core
classes/Route.php
Route.match
public function match($URL, $method='get'){ $method = strtolower($method); // * is an http method wildcard if (empty($this->methods[$method]) && empty($this->methods['*'])) return false; return (bool) ( $this->dynamic ? preg_match($this->matcher_pattern, '/'.trim($URL,'/')) : rtrim($URL,'/') == rtrim($this->pattern,'/') ); }
php
public function match($URL, $method='get'){ $method = strtolower($method); // * is an http method wildcard if (empty($this->methods[$method]) && empty($this->methods['*'])) return false; return (bool) ( $this->dynamic ? preg_match($this->matcher_pattern, '/'.trim($URL,'/')) : rtrim($URL,'/') == rtrim($this->pattern,'/') ); }
[ "public", "function", "match", "(", "$", "URL", ",", "$", "method", "=", "'get'", ")", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "// * is an http method wildcard", "if", "(", "empty", "(", "$", "this", "->", "methods", "[", "$", "method", "]", ")", "&&", "empty", "(", "$", "this", "->", "methods", "[", "'*'", "]", ")", ")", "return", "false", ";", "return", "(", "bool", ")", "(", "$", "this", "->", "dynamic", "?", "preg_match", "(", "$", "this", "->", "matcher_pattern", ",", "'/'", ".", "trim", "(", "$", "URL", ",", "'/'", ")", ")", ":", "rtrim", "(", "$", "URL", ",", "'/'", ")", "==", "rtrim", "(", "$", "this", "->", "pattern", ",", "'/'", ")", ")", ";", "}" ]
Check if route match on a specified URL and HTTP Method. @param [type] $URL The URL to check against. @param string $method The HTTP Method to check against. @return boolean
[ "Check", "if", "route", "match", "on", "a", "specified", "URL", "and", "HTTP", "Method", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L79-L90
train
caffeina-core/core
classes/Route.php
Route.run
public function run(array $args, $method='get'){ $method = strtolower($method); $append_echoed_text = Options::get('core.route.append_echoed_text',true); static::trigger('start', $this, $args, $method); // Call direct befores if ( $this->befores ) { // Reverse befores order foreach (array_reverse($this->befores) as $mw) { static::trigger('before', $this, $mw); Event::trigger('core.route.before', $this, $mw); ob_start(); $mw_result = call_user_func($mw); $raw_echoed = ob_get_clean(); if ($append_echoed_text) Response::add($raw_echoed); if ( false === $mw_result ) { return ['']; } else { Response::add($mw_result); } } } $callback = (is_array($this->callback) && isset($this->callback[$method])) ? $this->callback[$method] : $this->callback; if (is_callable($callback) || is_a($callback, "View") ) { Response::type( Options::get('core.route.response_default_type', Response::TYPE_HTML) ); ob_start(); if (is_a($callback, "View")) { // Get the rendered view $view_results = (string)$callback; } else { $view_results = call_user_func_array($callback, $args); } $raw_echoed = ob_get_clean(); if ($append_echoed_text) Response::add($raw_echoed); Response::add($view_results); } // Apply afters if ( $this->afters ) { foreach ($this->afters as $mw) { static::trigger('after', $this, $mw); Event::trigger('core.route.after', $this, $mw); ob_start(); $mw_result = call_user_func($mw); $raw_echoed = ob_get_clean(); if ($append_echoed_text) Response::add($raw_echoed); if ( false === $mw_result ) { return ['']; } else { Response::add($mw_result); } } } static::trigger('end', $this, $args, $method); Event::trigger('core.route.end', $this); return [Filter::with('core.route.response', Response::body())]; }
php
public function run(array $args, $method='get'){ $method = strtolower($method); $append_echoed_text = Options::get('core.route.append_echoed_text',true); static::trigger('start', $this, $args, $method); // Call direct befores if ( $this->befores ) { // Reverse befores order foreach (array_reverse($this->befores) as $mw) { static::trigger('before', $this, $mw); Event::trigger('core.route.before', $this, $mw); ob_start(); $mw_result = call_user_func($mw); $raw_echoed = ob_get_clean(); if ($append_echoed_text) Response::add($raw_echoed); if ( false === $mw_result ) { return ['']; } else { Response::add($mw_result); } } } $callback = (is_array($this->callback) && isset($this->callback[$method])) ? $this->callback[$method] : $this->callback; if (is_callable($callback) || is_a($callback, "View") ) { Response::type( Options::get('core.route.response_default_type', Response::TYPE_HTML) ); ob_start(); if (is_a($callback, "View")) { // Get the rendered view $view_results = (string)$callback; } else { $view_results = call_user_func_array($callback, $args); } $raw_echoed = ob_get_clean(); if ($append_echoed_text) Response::add($raw_echoed); Response::add($view_results); } // Apply afters if ( $this->afters ) { foreach ($this->afters as $mw) { static::trigger('after', $this, $mw); Event::trigger('core.route.after', $this, $mw); ob_start(); $mw_result = call_user_func($mw); $raw_echoed = ob_get_clean(); if ($append_echoed_text) Response::add($raw_echoed); if ( false === $mw_result ) { return ['']; } else { Response::add($mw_result); } } } static::trigger('end', $this, $args, $method); Event::trigger('core.route.end', $this); return [Filter::with('core.route.response', Response::body())]; }
[ "public", "function", "run", "(", "array", "$", "args", ",", "$", "method", "=", "'get'", ")", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "$", "append_echoed_text", "=", "Options", "::", "get", "(", "'core.route.append_echoed_text'", ",", "true", ")", ";", "static", "::", "trigger", "(", "'start'", ",", "$", "this", ",", "$", "args", ",", "$", "method", ")", ";", "// Call direct befores", "if", "(", "$", "this", "->", "befores", ")", "{", "// Reverse befores order", "foreach", "(", "array_reverse", "(", "$", "this", "->", "befores", ")", "as", "$", "mw", ")", "{", "static", "::", "trigger", "(", "'before'", ",", "$", "this", ",", "$", "mw", ")", ";", "Event", "::", "trigger", "(", "'core.route.before'", ",", "$", "this", ",", "$", "mw", ")", ";", "ob_start", "(", ")", ";", "$", "mw_result", "=", "call_user_func", "(", "$", "mw", ")", ";", "$", "raw_echoed", "=", "ob_get_clean", "(", ")", ";", "if", "(", "$", "append_echoed_text", ")", "Response", "::", "add", "(", "$", "raw_echoed", ")", ";", "if", "(", "false", "===", "$", "mw_result", ")", "{", "return", "[", "''", "]", ";", "}", "else", "{", "Response", "::", "add", "(", "$", "mw_result", ")", ";", "}", "}", "}", "$", "callback", "=", "(", "is_array", "(", "$", "this", "->", "callback", ")", "&&", "isset", "(", "$", "this", "->", "callback", "[", "$", "method", "]", ")", ")", "?", "$", "this", "->", "callback", "[", "$", "method", "]", ":", "$", "this", "->", "callback", ";", "if", "(", "is_callable", "(", "$", "callback", ")", "||", "is_a", "(", "$", "callback", ",", "\"View\"", ")", ")", "{", "Response", "::", "type", "(", "Options", "::", "get", "(", "'core.route.response_default_type'", ",", "Response", "::", "TYPE_HTML", ")", ")", ";", "ob_start", "(", ")", ";", "if", "(", "is_a", "(", "$", "callback", ",", "\"View\"", ")", ")", "{", "// Get the rendered view", "$", "view_results", "=", "(", "string", ")", "$", "callback", ";", "}", "else", "{", "$", "view_results", "=", "call_user_func_array", "(", "$", "callback", ",", "$", "args", ")", ";", "}", "$", "raw_echoed", "=", "ob_get_clean", "(", ")", ";", "if", "(", "$", "append_echoed_text", ")", "Response", "::", "add", "(", "$", "raw_echoed", ")", ";", "Response", "::", "add", "(", "$", "view_results", ")", ";", "}", "// Apply afters", "if", "(", "$", "this", "->", "afters", ")", "{", "foreach", "(", "$", "this", "->", "afters", "as", "$", "mw", ")", "{", "static", "::", "trigger", "(", "'after'", ",", "$", "this", ",", "$", "mw", ")", ";", "Event", "::", "trigger", "(", "'core.route.after'", ",", "$", "this", ",", "$", "mw", ")", ";", "ob_start", "(", ")", ";", "$", "mw_result", "=", "call_user_func", "(", "$", "mw", ")", ";", "$", "raw_echoed", "=", "ob_get_clean", "(", ")", ";", "if", "(", "$", "append_echoed_text", ")", "Response", "::", "add", "(", "$", "raw_echoed", ")", ";", "if", "(", "false", "===", "$", "mw_result", ")", "{", "return", "[", "''", "]", ";", "}", "else", "{", "Response", "::", "add", "(", "$", "mw_result", ")", ";", "}", "}", "}", "static", "::", "trigger", "(", "'end'", ",", "$", "this", ",", "$", "args", ",", "$", "method", ")", ";", "Event", "::", "trigger", "(", "'core.route.end'", ",", "$", "this", ")", ";", "return", "[", "Filter", "::", "with", "(", "'core.route.response'", ",", "Response", "::", "body", "(", ")", ")", "]", ";", "}" ]
Run one of the mapped callbacks to a passed HTTP Method. @param array $args The arguments to be passed to the callback @param string $method The HTTP Method requested. @return array The callback response.
[ "Run", "one", "of", "the", "mapped", "callbacks", "to", "a", "passed", "HTTP", "Method", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L110-L174
train
caffeina-core/core
classes/Route.php
Route.runIfMatch
public function runIfMatch($URL, $method='get'){ return $this->match($URL,$method) ? $this->run($this->extractArgs($URL),$method) : null; }
php
public function runIfMatch($URL, $method='get'){ return $this->match($URL,$method) ? $this->run($this->extractArgs($URL),$method) : null; }
[ "public", "function", "runIfMatch", "(", "$", "URL", ",", "$", "method", "=", "'get'", ")", "{", "return", "$", "this", "->", "match", "(", "$", "URL", ",", "$", "method", ")", "?", "$", "this", "->", "run", "(", "$", "this", "->", "extractArgs", "(", "$", "URL", ")", ",", "$", "method", ")", ":", "null", ";", "}" ]
Check if route match URL and HTTP Method and run if it is valid. @param [type] $URL The URL to check against. @param string $method The HTTP Method to check against. @return array The callback response.
[ "Check", "if", "route", "match", "URL", "and", "HTTP", "Method", "and", "run", "if", "it", "is", "valid", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L182-L184
train
caffeina-core/core
classes/Route.php
Route.&
public function & via(...$methods){ $this->methods = []; foreach ($methods as $method){ $this->methods[strtolower($method)] = true; } return $this; }
php
public function & via(...$methods){ $this->methods = []; foreach ($methods as $method){ $this->methods[strtolower($method)] = true; } return $this; }
[ "public", "function", "&", "via", "(", "...", "$", "methods", ")", "{", "$", "this", "->", "methods", "=", "[", "]", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "$", "this", "->", "methods", "[", "strtolower", "(", "$", "method", ")", "]", "=", "true", ";", "}", "return", "$", "this", ";", "}" ]
Defines the HTTP Methods to bind the route onto. Example: <code> Route::on('/test')->via('get','post','delete'); </code> @return Route
[ "Defines", "the", "HTTP", "Methods", "to", "bind", "the", "route", "onto", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L266-L272
train
caffeina-core/core
classes/Route.php
Route.&
public function & rules(array $rules){ foreach ((array)$rules as $varname => $rule){ $this->rules[$varname] = $rule; } $this->pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules ); $this->matcher_pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules, false ); return $this; }
php
public function & rules(array $rules){ foreach ((array)$rules as $varname => $rule){ $this->rules[$varname] = $rule; } $this->pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules ); $this->matcher_pattern = $this->compilePatternAsRegex( $this->URLPattern, $this->rules, false ); return $this; }
[ "public", "function", "&", "rules", "(", "array", "$", "rules", ")", "{", "foreach", "(", "(", "array", ")", "$", "rules", "as", "$", "varname", "=>", "$", "rule", ")", "{", "$", "this", "->", "rules", "[", "$", "varname", "]", "=", "$", "rule", ";", "}", "$", "this", "->", "pattern", "=", "$", "this", "->", "compilePatternAsRegex", "(", "$", "this", "->", "URLPattern", ",", "$", "this", "->", "rules", ")", ";", "$", "this", "->", "matcher_pattern", "=", "$", "this", "->", "compilePatternAsRegex", "(", "$", "this", "->", "URLPattern", ",", "$", "this", "->", "rules", ",", "false", ")", ";", "return", "$", "this", ";", "}" ]
Defines the regex rules for the named parameter in the current URL pattern Example: <code> Route::on('/proxy/:number/:url') ->rules([ 'number' => '\d+', 'url' => '.+', ]); </code> @param array $rules The regex rules @return Route
[ "Defines", "the", "regex", "rules", "for", "the", "named", "parameter", "in", "the", "current", "URL", "pattern" ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L289-L296
train
caffeina-core/core
classes/Route.php
Route.&
public static function & map($URLPattern, $callbacks = []){ $route = new static($URLPattern); $route->callback = []; foreach ($callbacks as $method => $callback) { $method = strtolower($method); if (Request::method() !== $method) continue; $route->callback[$method] = $callback; $route->methods[$method] = 1; } return $route; }
php
public static function & map($URLPattern, $callbacks = []){ $route = new static($URLPattern); $route->callback = []; foreach ($callbacks as $method => $callback) { $method = strtolower($method); if (Request::method() !== $method) continue; $route->callback[$method] = $callback; $route->methods[$method] = 1; } return $route; }
[ "public", "static", "function", "&", "map", "(", "$", "URLPattern", ",", "$", "callbacks", "=", "[", "]", ")", "{", "$", "route", "=", "new", "static", "(", "$", "URLPattern", ")", ";", "$", "route", "->", "callback", "=", "[", "]", ";", "foreach", "(", "$", "callbacks", "as", "$", "method", "=>", "$", "callback", ")", "{", "$", "method", "=", "strtolower", "(", "$", "method", ")", ";", "if", "(", "Request", "::", "method", "(", ")", "!==", "$", "method", ")", "continue", ";", "$", "route", "->", "callback", "[", "$", "method", "]", "=", "$", "callback", ";", "$", "route", "->", "methods", "[", "$", "method", "]", "=", "1", ";", "}", "return", "$", "route", ";", "}" ]
Map a HTTP Method => callable array to a route. Example: <code> Route::map('/test'[ 'get' => function(){ echo "HTTP GET"; }, 'post' => function(){ echo "HTTP POST"; }, 'put' => function(){ echo "HTTP PUT"; }, 'delete' => function(){ echo "HTTP DELETE"; }, ]); </code> @param string $URLPattern The URL to match against, you can define named segments to be extracted and passed to the callback. @param array $callbacks The HTTP Method => callable map. @return Route
[ "Map", "a", "HTTP", "Method", "=", ">", "callable", "array", "to", "a", "route", "." ]
819134644dfb3b6379a12fff08fa5ec45a2c614c
https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L315-L325
train