id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
36,100
yawik/install
src/Factory/Controller/Plugin/UserCreatorFactory.php
UserCreatorFactory.createDocumentManager
public function createDocumentManager($connection,$config) { $dbConn = new Connection($connection); $dm = DocumentManager::create($dbConn,$config); return $dm; }
php
public function createDocumentManager($connection,$config) { $dbConn = new Connection($connection); $dm = DocumentManager::create($dbConn,$config); return $dm; }
[ "public", "function", "createDocumentManager", "(", "$", "connection", ",", "$", "config", ")", "{", "$", "dbConn", "=", "new", "Connection", "(", "$", "connection", ")", ";", "$", "dm", "=", "DocumentManager", "::", "create", "(", "$", "dbConn", ",", "$", "config", ")", ";", "return", "$", "dm", ";", "}" ]
Create a document manager @param $connection @param $config @return DocumentManager @codeCoverageIgnore
[ "Create", "a", "document", "manager" ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Factory/Controller/Plugin/UserCreatorFactory.php#L67-L72
36,101
yawik/install
src/Validator/MongoDbConnection.php
MongoDbConnection.isValid
public function isValid($value) { $this->databaseError = null; // @codeCoverageIgnoreStart // This cannot be testes until we have a test database environment. try { $connection = new Client($value); $connection->listDatabases(); } catch (ConnectionTimeoutException $e) { $this->databaseError = $e->getMessage(); $this->error(self::NO_CONNECTION); return false; } catch (\Exception $e) { $this->databaseError = $e->getMessage(); $this->error(self::NO_CONNECTION); return false; } return true; // @codeCoverageIgnoreEnd }
php
public function isValid($value) { $this->databaseError = null; // @codeCoverageIgnoreStart // This cannot be testes until we have a test database environment. try { $connection = new Client($value); $connection->listDatabases(); } catch (ConnectionTimeoutException $e) { $this->databaseError = $e->getMessage(); $this->error(self::NO_CONNECTION); return false; } catch (\Exception $e) { $this->databaseError = $e->getMessage(); $this->error(self::NO_CONNECTION); return false; } return true; // @codeCoverageIgnoreEnd }
[ "public", "function", "isValid", "(", "$", "value", ")", "{", "$", "this", "->", "databaseError", "=", "null", ";", "// @codeCoverageIgnoreStart", "// This cannot be testes until we have a test database environment.", "try", "{", "$", "connection", "=", "new", "Client", "(", "$", "value", ")", ";", "$", "connection", "->", "listDatabases", "(", ")", ";", "}", "catch", "(", "ConnectionTimeoutException", "$", "e", ")", "{", "$", "this", "->", "databaseError", "=", "$", "e", "->", "getMessage", "(", ")", ";", "$", "this", "->", "error", "(", "self", "::", "NO_CONNECTION", ")", ";", "return", "false", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "databaseError", "=", "$", "e", "->", "getMessage", "(", ")", ";", "$", "this", "->", "error", "(", "self", "::", "NO_CONNECTION", ")", ";", "return", "false", ";", "}", "return", "true", ";", "// @codeCoverageIgnoreEnd", "}" ]
Returns true if and only if a mongodb connection can be established. @param string $value The mongodb connection string @return bool
[ "Returns", "true", "if", "and", "only", "if", "a", "mongodb", "connection", "can", "be", "established", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Validator/MongoDbConnection.php#L72-L93
36,102
eccube2/plugin-installer
src/Eccube2/Composer/Installers/Installer.php
Installer.getLocationPattern
protected function getLocationPattern($frameworkType) { $pattern = false; if (!empty($this->supportedTypes[$frameworkType])) { $frameworkClass = 'Eccube2\\Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; /** @var BaseInstaller $framework */ $framework = new $frameworkClass(null, $this->composer, $this->getIO()); $locations = array_keys($framework->getLocations()); $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; } return $pattern ? $pattern : '(\w+)'; }
php
protected function getLocationPattern($frameworkType) { $pattern = false; if (!empty($this->supportedTypes[$frameworkType])) { $frameworkClass = 'Eccube2\\Composer\\Installers\\' . $this->supportedTypes[$frameworkType]; /** @var BaseInstaller $framework */ $framework = new $frameworkClass(null, $this->composer, $this->getIO()); $locations = array_keys($framework->getLocations()); $pattern = $locations ? '(' . implode('|', $locations) . ')' : false; } return $pattern ? $pattern : '(\w+)'; }
[ "protected", "function", "getLocationPattern", "(", "$", "frameworkType", ")", "{", "$", "pattern", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "supportedTypes", "[", "$", "frameworkType", "]", ")", ")", "{", "$", "frameworkClass", "=", "'Eccube2\\\\Composer\\\\Installers\\\\'", ".", "$", "this", "->", "supportedTypes", "[", "$", "frameworkType", "]", ";", "/** @var BaseInstaller $framework */", "$", "framework", "=", "new", "$", "frameworkClass", "(", "null", ",", "$", "this", "->", "composer", ",", "$", "this", "->", "getIO", "(", ")", ")", ";", "$", "locations", "=", "array_keys", "(", "$", "framework", "->", "getLocations", "(", ")", ")", ";", "$", "pattern", "=", "$", "locations", "?", "'('", ".", "implode", "(", "'|'", ",", "$", "locations", ")", ".", "')'", ":", "false", ";", "}", "return", "$", "pattern", "?", "$", "pattern", ":", "'(\\w+)'", ";", "}" ]
Get the second part of the regular expression to check for support of a package type @param string $frameworkType @return string
[ "Get", "the", "second", "part", "of", "the", "regular", "expression", "to", "check", "for", "support", "of", "a", "package", "type" ]
809e24b241410693f5f5e0a9d73c0633a1acfc7d
https://github.com/eccube2/plugin-installer/blob/809e24b241410693f5f5e0a9d73c0633a1acfc7d/src/Eccube2/Composer/Installers/Installer.php#L45-L57
36,103
yawik/install
src/Controller/Index.php
Index.preDispatch
public function preDispatch(MvcEvent $event) { $this->layout()->setVariable('lang', $this->params('lang')); $p = $this->params()->fromQuery('p'); $request = $this->getRequest(); if ($p && $request->isXmlHttpRequest()) { $routeMatch = $event->getRouteMatch(); $routeMatch->setParam('action', $p); $response = $this->getResponse(); $response->getHeaders() ->addHeaderLine('Content-Type', 'application/json') ->addHeaderLine('Content-Encoding', 'utf8'); } }
php
public function preDispatch(MvcEvent $event) { $this->layout()->setVariable('lang', $this->params('lang')); $p = $this->params()->fromQuery('p'); $request = $this->getRequest(); if ($p && $request->isXmlHttpRequest()) { $routeMatch = $event->getRouteMatch(); $routeMatch->setParam('action', $p); $response = $this->getResponse(); $response->getHeaders() ->addHeaderLine('Content-Type', 'application/json') ->addHeaderLine('Content-Encoding', 'utf8'); } }
[ "public", "function", "preDispatch", "(", "MvcEvent", "$", "event", ")", "{", "$", "this", "->", "layout", "(", ")", "->", "setVariable", "(", "'lang'", ",", "$", "this", "->", "params", "(", "'lang'", ")", ")", ";", "$", "p", "=", "$", "this", "->", "params", "(", ")", "->", "fromQuery", "(", "'p'", ")", ";", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "if", "(", "$", "p", "&&", "$", "request", "->", "isXmlHttpRequest", "(", ")", ")", "{", "$", "routeMatch", "=", "$", "event", "->", "getRouteMatch", "(", ")", ";", "$", "routeMatch", "->", "setParam", "(", "'action'", ",", "$", "p", ")", ";", "$", "response", "=", "$", "this", "->", "getResponse", "(", ")", ";", "$", "response", "->", "getHeaders", "(", ")", "->", "addHeaderLine", "(", "'Content-Type'", ",", "'application/json'", ")", "->", "addHeaderLine", "(", "'Content-Encoding'", ",", "'utf8'", ")", ";", "}", "}" ]
Hook for custom preDispatch event. @param MvcEvent $event
[ "Hook", "for", "custom", "preDispatch", "event", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Index.php#L52-L67
36,104
yawik/install
src/Controller/Index.php
Index.prereqAction
public function prereqAction() { $prereqs = $this->plugin('Install/Prerequisites')->check(); $model = $this->createViewModel(array('prerequisites' => $prereqs), true); $model->setTemplate('install/index/prerequisites.ajax.phtml'); return $model; }
php
public function prereqAction() { $prereqs = $this->plugin('Install/Prerequisites')->check(); $model = $this->createViewModel(array('prerequisites' => $prereqs), true); $model->setTemplate('install/index/prerequisites.ajax.phtml'); return $model; }
[ "public", "function", "prereqAction", "(", ")", "{", "$", "prereqs", "=", "$", "this", "->", "plugin", "(", "'Install/Prerequisites'", ")", "->", "check", "(", ")", ";", "$", "model", "=", "$", "this", "->", "createViewModel", "(", "array", "(", "'prerequisites'", "=>", "$", "prereqs", ")", ",", "true", ")", ";", "$", "model", "->", "setTemplate", "(", "'install/index/prerequisites.ajax.phtml'", ")", ";", "return", "$", "model", ";", "}" ]
Action to check prerequisites via ajax request. @return ViewModel|ResponseInterface
[ "Action", "to", "check", "prerequisites", "via", "ajax", "request", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Index.php#L99-L107
36,105
yawik/install
src/Controller/Index.php
Index.installAction
public function installAction() { $form = $this->installForm; $form->setData($_POST); if (!$form->isValid()) { return $this->createJsonResponse( array( 'ok' => false, 'errors' => $form->getMessages(), ) ); } $data = $form->getData(); try { $options = [ 'connection' => $data['db_conn'], ]; $userOk = $this->plugin('Install/UserCreator', $options)->process($data['username'], $data['password'], $data['email']); $ok = $this->plugin('Install/ConfigCreator')->process($data['db_conn'], $data['email']); } catch (\Exception $exception) { /* @TODO: provide a way to handle global error message */ return $this->createJsonResponse([ 'ok' => false, 'errors' => [ 'global' => [$exception->getMessage()] ] ]); } /* * Make sure there's no cached config files */ $this->cacheService->clearCache(); $model = $this->createViewModel(array('ok' => $ok), true); $model->setTemplate('install/index/install.ajax.phtml'); return $model; }
php
public function installAction() { $form = $this->installForm; $form->setData($_POST); if (!$form->isValid()) { return $this->createJsonResponse( array( 'ok' => false, 'errors' => $form->getMessages(), ) ); } $data = $form->getData(); try { $options = [ 'connection' => $data['db_conn'], ]; $userOk = $this->plugin('Install/UserCreator', $options)->process($data['username'], $data['password'], $data['email']); $ok = $this->plugin('Install/ConfigCreator')->process($data['db_conn'], $data['email']); } catch (\Exception $exception) { /* @TODO: provide a way to handle global error message */ return $this->createJsonResponse([ 'ok' => false, 'errors' => [ 'global' => [$exception->getMessage()] ] ]); } /* * Make sure there's no cached config files */ $this->cacheService->clearCache(); $model = $this->createViewModel(array('ok' => $ok), true); $model->setTemplate('install/index/install.ajax.phtml'); return $model; }
[ "public", "function", "installAction", "(", ")", "{", "$", "form", "=", "$", "this", "->", "installForm", ";", "$", "form", "->", "setData", "(", "$", "_POST", ")", ";", "if", "(", "!", "$", "form", "->", "isValid", "(", ")", ")", "{", "return", "$", "this", "->", "createJsonResponse", "(", "array", "(", "'ok'", "=>", "false", ",", "'errors'", "=>", "$", "form", "->", "getMessages", "(", ")", ",", ")", ")", ";", "}", "$", "data", "=", "$", "form", "->", "getData", "(", ")", ";", "try", "{", "$", "options", "=", "[", "'connection'", "=>", "$", "data", "[", "'db_conn'", "]", ",", "]", ";", "$", "userOk", "=", "$", "this", "->", "plugin", "(", "'Install/UserCreator'", ",", "$", "options", ")", "->", "process", "(", "$", "data", "[", "'username'", "]", ",", "$", "data", "[", "'password'", "]", ",", "$", "data", "[", "'email'", "]", ")", ";", "$", "ok", "=", "$", "this", "->", "plugin", "(", "'Install/ConfigCreator'", ")", "->", "process", "(", "$", "data", "[", "'db_conn'", "]", ",", "$", "data", "[", "'email'", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "/* @TODO: provide a way to handle global error message */", "return", "$", "this", "->", "createJsonResponse", "(", "[", "'ok'", "=>", "false", ",", "'errors'", "=>", "[", "'global'", "=>", "[", "$", "exception", "->", "getMessage", "(", ")", "]", "]", "]", ")", ";", "}", "/*\n * Make sure there's no cached config files\n */", "$", "this", "->", "cacheService", "->", "clearCache", "(", ")", ";", "$", "model", "=", "$", "this", "->", "createViewModel", "(", "array", "(", "'ok'", "=>", "$", "ok", ")", ",", "true", ")", ";", "$", "model", "->", "setTemplate", "(", "'install/index/install.ajax.phtml'", ")", ";", "return", "$", "model", ";", "}" ]
Main working action. Creates the configuration. @return ResponseInterface|ViewModel
[ "Main", "working", "action", ".", "Creates", "the", "configuration", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Index.php#L114-L155
36,106
yawik/install
src/Controller/Index.php
Index.createViewModel
protected function createViewModel(array $params, $terminal = false) { if (!isset($params['lang'])) { $params['lang'] = $this->params('lang'); } $model = new ViewModel($params); $terminal && $model->setTerminal($terminal); return $model; }
php
protected function createViewModel(array $params, $terminal = false) { if (!isset($params['lang'])) { $params['lang'] = $this->params('lang'); } $model = new ViewModel($params); $terminal && $model->setTerminal($terminal); return $model; }
[ "protected", "function", "createViewModel", "(", "array", "$", "params", ",", "$", "terminal", "=", "false", ")", "{", "if", "(", "!", "isset", "(", "$", "params", "[", "'lang'", "]", ")", ")", "{", "$", "params", "[", "'lang'", "]", "=", "$", "this", "->", "params", "(", "'lang'", ")", ";", "}", "$", "model", "=", "new", "ViewModel", "(", "$", "params", ")", ";", "$", "terminal", "&&", "$", "model", "->", "setTerminal", "(", "$", "terminal", ")", ";", "return", "$", "model", ";", "}" ]
Creates a view model @param array $params @param bool $terminal @return ViewModel
[ "Creates", "a", "view", "model" ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Index.php#L176-L187
36,107
yawik/install
src/Controller/Index.php
Index.createJsonResponse
protected function createJsonResponse(array $variables) { $response = $this->getResponse(); $json = Json::encode($variables); $response->setContent($json); return $response; }
php
protected function createJsonResponse(array $variables) { $response = $this->getResponse(); $json = Json::encode($variables); $response->setContent($json); return $response; }
[ "protected", "function", "createJsonResponse", "(", "array", "$", "variables", ")", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", ")", ";", "$", "json", "=", "Json", "::", "encode", "(", "$", "variables", ")", ";", "$", "response", "->", "setContent", "(", "$", "json", ")", ";", "return", "$", "response", ";", "}" ]
Create a json response object for ajax requests. @param array $variables @return \Zend\Stdlib\ResponseInterface
[ "Create", "a", "json", "response", "object", "for", "ajax", "requests", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Index.php#L196-L203
36,108
systemson/cache
src/Driver/Base/FileCache.php
FileCache.filesystem
public function filesystem(string $path = null) { if (!$this->filesystem instanceof Filesystem) { $local = new Local($path); $this->filesystem = new Filesystem($local); } return $this->filesystem; }
php
public function filesystem(string $path = null) { if (!$this->filesystem instanceof Filesystem) { $local = new Local($path); $this->filesystem = new Filesystem($local); } return $this->filesystem; }
[ "public", "function", "filesystem", "(", "string", "$", "path", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "filesystem", "instanceof", "Filesystem", ")", "{", "$", "local", "=", "new", "Local", "(", "$", "path", ")", ";", "$", "this", "->", "filesystem", "=", "new", "Filesystem", "(", "$", "local", ")", ";", "}", "return", "$", "this", "->", "filesystem", ";", "}" ]
Gets a Filesystem instance. @return instance Filesystem
[ "Gets", "a", "Filesystem", "instance", "." ]
a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c
https://github.com/systemson/cache/blob/a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c/src/Driver/Base/FileCache.php#L37-L46
36,109
systemson/cache
src/Driver/Base/FileCache.php
FileCache.clear
public function clear() { foreach ($this->filesystem()->listContents() as $file) { $this->filesystem()->delete($file['path']); } return true; }
php
public function clear() { foreach ($this->filesystem()->listContents() as $file) { $this->filesystem()->delete($file['path']); } return true; }
[ "public", "function", "clear", "(", ")", "{", "foreach", "(", "$", "this", "->", "filesystem", "(", ")", "->", "listContents", "(", ")", "as", "$", "file", ")", "{", "$", "this", "->", "filesystem", "(", ")", "->", "delete", "(", "$", "file", "[", "'path'", "]", ")", ";", "}", "return", "true", ";", "}" ]
Deletes the cache folder. @return bool True on success and false on failure.
[ "Deletes", "the", "cache", "folder", "." ]
a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c
https://github.com/systemson/cache/blob/a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c/src/Driver/Base/FileCache.php#L129-L136
36,110
systemson/cache
src/Driver/Base/FileCache.php
FileCache.has
public function has($key) { /* If $key is not valid string throws InvalidArgumentException */ if (!$this->isString($key)) { throw new InvalidArgumentException('Cache key must be not empty string'); } if ($this->getRaw($key)) { return true; } return false; }
php
public function has($key) { /* If $key is not valid string throws InvalidArgumentException */ if (!$this->isString($key)) { throw new InvalidArgumentException('Cache key must be not empty string'); } if ($this->getRaw($key)) { return true; } return false; }
[ "public", "function", "has", "(", "$", "key", ")", "{", "/* If $key is not valid string throws InvalidArgumentException */", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Cache key must be not empty string'", ")", ";", "}", "if", "(", "$", "this", "->", "getRaw", "(", "$", "key", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Whether an item is present in the cache. @param string $key The cache item key. @throws \Psr\SimpleCache\InvalidArgumentException @return bool
[ "Whether", "an", "item", "is", "present", "in", "the", "cache", "." ]
a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c
https://github.com/systemson/cache/blob/a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c/src/Driver/Base/FileCache.php#L147-L159
36,111
systemson/cache
src/Driver/Base/FileCache.php
FileCache.getCachedItem
public function getCachedItem($key) { $path = sha1($key); if ($this->filesystem()->has($path)) { $item = explode(PHP_EOL, $this->filesystem()->read($path), 2); return new CacheItemClass($key, $item[1] ?? null, $item[0] ?? null); } }
php
public function getCachedItem($key) { $path = sha1($key); if ($this->filesystem()->has($path)) { $item = explode(PHP_EOL, $this->filesystem()->read($path), 2); return new CacheItemClass($key, $item[1] ?? null, $item[0] ?? null); } }
[ "public", "function", "getCachedItem", "(", "$", "key", ")", "{", "$", "path", "=", "sha1", "(", "$", "key", ")", ";", "if", "(", "$", "this", "->", "filesystem", "(", ")", "->", "has", "(", "$", "path", ")", ")", "{", "$", "item", "=", "explode", "(", "PHP_EOL", ",", "$", "this", "->", "filesystem", "(", ")", "->", "read", "(", "$", "path", ")", ",", "2", ")", ";", "return", "new", "CacheItemClass", "(", "$", "key", ",", "$", "item", "[", "1", "]", "??", "null", ",", "$", "item", "[", "0", "]", "??", "null", ")", ";", "}", "}" ]
Returns a CacheItemClass for the. @param string $key The cache item key. @throws \Psr\SimpleCache\InvalidArgumentException @return CacheItemInterface
[ "Returns", "a", "CacheItemClass", "for", "the", "." ]
a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c
https://github.com/systemson/cache/blob/a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c/src/Driver/Base/FileCache.php#L170-L179
36,112
systemson/cache
src/Driver/Base/FileCache.php
FileCache.isExpired
public function isExpired(CacheItemInterface $item) { if ($item->isExpired()) { $this->delete($item->getKey()); return true; } return false; }
php
public function isExpired(CacheItemInterface $item) { if ($item->isExpired()) { $this->delete($item->getKey()); return true; } return false; }
[ "public", "function", "isExpired", "(", "CacheItemInterface", "$", "item", ")", "{", "if", "(", "$", "item", "->", "isExpired", "(", ")", ")", "{", "$", "this", "->", "delete", "(", "$", "item", "->", "getKey", "(", ")", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Whether an item from the cache is expired. If it does, deletes it from the file system. @param CacheItemInterface $item The item to evaluate. @return
[ "Whether", "an", "item", "from", "the", "cache", "is", "expired", ".", "If", "it", "does", "deletes", "it", "from", "the", "file", "system", "." ]
a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c
https://github.com/systemson/cache/blob/a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c/src/Driver/Base/FileCache.php#L188-L197
36,113
yawik/install
src/Controller/Plugin/Prerequisites.php
Prerequisites.check
public function check($directories = null) { null == $directories && $directories = $this->directories; $return = array(); $valid = true; foreach ($directories as $path => $validationSpec) { $result = $this->checkDirectory($path, $validationSpec); $return['directories'][$path] = $result; $valid = $valid && $result['valid']; } $return['valid'] = $valid; return $return; }
php
public function check($directories = null) { null == $directories && $directories = $this->directories; $return = array(); $valid = true; foreach ($directories as $path => $validationSpec) { $result = $this->checkDirectory($path, $validationSpec); $return['directories'][$path] = $result; $valid = $valid && $result['valid']; } $return['valid'] = $valid; return $return; }
[ "public", "function", "check", "(", "$", "directories", "=", "null", ")", "{", "null", "==", "$", "directories", "&&", "$", "directories", "=", "$", "this", "->", "directories", ";", "$", "return", "=", "array", "(", ")", ";", "$", "valid", "=", "true", ";", "foreach", "(", "$", "directories", "as", "$", "path", "=>", "$", "validationSpec", ")", "{", "$", "result", "=", "$", "this", "->", "checkDirectory", "(", "$", "path", ",", "$", "validationSpec", ")", ";", "$", "return", "[", "'directories'", "]", "[", "$", "path", "]", "=", "$", "result", ";", "$", "valid", "=", "$", "valid", "&&", "$", "result", "[", "'valid'", "]", ";", "}", "$", "return", "[", "'valid'", "]", "=", "$", "valid", ";", "return", "$", "return", ";", "}" ]
Checks directories. Calls {@link checkDirectory()} for each directory in the array. Checks, if all directories has passed as valid according to the specs. @param null|array $directories @return array
[ "Checks", "directories", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/Prerequisites.php#L63-L77
36,114
yawik/install
src/Controller/Plugin/Prerequisites.php
Prerequisites.checkDirectory
public function checkDirectory($dir, $validationSpec) { $exists = file_exists($dir); $writable = $exists && is_writable($dir); $missing = !$exists; $creatable = $missing && is_writable(dirname($dir)); $return = array( 'exists' => $exists, 'writable' => $writable, 'missing' => $missing, 'creatable' => $creatable ); $return['valid'] = $this->validateDirectory($return, $validationSpec); return $return; }
php
public function checkDirectory($dir, $validationSpec) { $exists = file_exists($dir); $writable = $exists && is_writable($dir); $missing = !$exists; $creatable = $missing && is_writable(dirname($dir)); $return = array( 'exists' => $exists, 'writable' => $writable, 'missing' => $missing, 'creatable' => $creatable ); $return['valid'] = $this->validateDirectory($return, $validationSpec); return $return; }
[ "public", "function", "checkDirectory", "(", "$", "dir", ",", "$", "validationSpec", ")", "{", "$", "exists", "=", "file_exists", "(", "$", "dir", ")", ";", "$", "writable", "=", "$", "exists", "&&", "is_writable", "(", "$", "dir", ")", ";", "$", "missing", "=", "!", "$", "exists", ";", "$", "creatable", "=", "$", "missing", "&&", "is_writable", "(", "dirname", "(", "$", "dir", ")", ")", ";", "$", "return", "=", "array", "(", "'exists'", "=>", "$", "exists", ",", "'writable'", "=>", "$", "writable", ",", "'missing'", "=>", "$", "missing", ",", "'creatable'", "=>", "$", "creatable", ")", ";", "$", "return", "[", "'valid'", "]", "=", "$", "this", "->", "validateDirectory", "(", "$", "return", ",", "$", "validationSpec", ")", ";", "return", "$", "return", ";", "}" ]
Checks a directory. @param string $dir @param string $validationSpec @return array
[ "Checks", "a", "directory", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/Prerequisites.php#L87-L104
36,115
yawik/install
src/Controller/Plugin/Prerequisites.php
Prerequisites.validateDirectory
public function validateDirectory($result, $spec) { $spec = explode('|', $spec); $valid = false; foreach ($spec as $s) { if (isset($result[$s]) && $result[$s]) { $valid = true; break; } } return $valid; }
php
public function validateDirectory($result, $spec) { $spec = explode('|', $spec); $valid = false; foreach ($spec as $s) { if (isset($result[$s]) && $result[$s]) { $valid = true; break; } } return $valid; }
[ "public", "function", "validateDirectory", "(", "$", "result", ",", "$", "spec", ")", "{", "$", "spec", "=", "explode", "(", "'|'", ",", "$", "spec", ")", ";", "$", "valid", "=", "false", ";", "foreach", "(", "$", "spec", "as", "$", "s", ")", "{", "if", "(", "isset", "(", "$", "result", "[", "$", "s", "]", ")", "&&", "$", "result", "[", "$", "s", "]", ")", "{", "$", "valid", "=", "true", ";", "break", ";", "}", "}", "return", "$", "valid", ";", "}" ]
Validates a directory according to the spec @param array $result @param string $spec @return bool
[ "Validates", "a", "directory", "according", "to", "the", "spec" ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/Prerequisites.php#L114-L127
36,116
n2n/n2n-web
src/app/n2n/web/http/Response.php
Response.serverPush
public function serverPush(ServerPushDirective $directive) { if ($this->request->getProtocolVersion()->getMajorNum() < 2) { return; } $this->setHeader($directive->toHeader()); }
php
public function serverPush(ServerPushDirective $directive) { if ($this->request->getProtocolVersion()->getMajorNum() < 2) { return; } $this->setHeader($directive->toHeader()); }
[ "public", "function", "serverPush", "(", "ServerPushDirective", "$", "directive", ")", "{", "if", "(", "$", "this", "->", "request", "->", "getProtocolVersion", "(", ")", "->", "getMajorNum", "(", ")", "<", "2", ")", "{", "return", ";", "}", "$", "this", "->", "setHeader", "(", "$", "directive", "->", "toHeader", "(", ")", ")", ";", "}" ]
Server push will be ignored if HTTP version of request is lower than 2 or if sever push is disabled in app.ini @param ServerPushDirective $directive
[ "Server", "push", "will", "be", "ignored", "if", "HTTP", "version", "of", "request", "is", "lower", "than", "2", "or", "if", "sever", "push", "is", "disabled", "in", "app", ".", "ini" ]
1640c79f05d10d73093b98b70860ef8076d23e81
https://github.com/n2n/n2n-web/blob/1640c79f05d10d73093b98b70860ef8076d23e81/src/app/n2n/web/http/Response.php#L493-L499
36,117
yawik/install
src/Listener/LanguageSetter.php
LanguageSetter.onRoute
public function onRoute(MvcEvent $e) { /* @var $request \Zend\Http\PhpEnvironment\Request */ $request = $e->getRequest(); /* Detect language */ $lang = $request->getQuery('lang'); if (!$lang) { $headers = $request->getHeaders(); if ($headers->has('Accept-Language')) { /* @var $acceptLangs \Zend\Http\Header\AcceptLanguage */ $acceptLangs = $headers->get('Accept-Language'); $locales = $acceptLangs->getPrioritized(); $locale = $locales[0]; $lang = $locale->type; } else { $lang = 'en'; } } /* Set locale */ $translator = $e->getApplication()->getServiceManager()->get('mvctranslator'); $locale = $lang . '_' . strtoupper($lang); setlocale( LC_ALL, array( $locale . ".utf8", $locale . ".iso88591", $locale, substr($locale, 0, 2), 'de_DE.utf8', 'de_DE', 'de' ) ); \Locale::setDefault($locale); $translator->setLocale($locale); $routeMatch = $e->getRouteMatch(); if ($routeMatch && $routeMatch->getParam('lang') === null) { $routeMatch->setParam('lang', $lang); } /* @var $router \Zend\Mvc\Router\SimpleRouteStack */ $router = $e->getRouter(); $router->setDefaultParam('lang', $lang); }
php
public function onRoute(MvcEvent $e) { /* @var $request \Zend\Http\PhpEnvironment\Request */ $request = $e->getRequest(); /* Detect language */ $lang = $request->getQuery('lang'); if (!$lang) { $headers = $request->getHeaders(); if ($headers->has('Accept-Language')) { /* @var $acceptLangs \Zend\Http\Header\AcceptLanguage */ $acceptLangs = $headers->get('Accept-Language'); $locales = $acceptLangs->getPrioritized(); $locale = $locales[0]; $lang = $locale->type; } else { $lang = 'en'; } } /* Set locale */ $translator = $e->getApplication()->getServiceManager()->get('mvctranslator'); $locale = $lang . '_' . strtoupper($lang); setlocale( LC_ALL, array( $locale . ".utf8", $locale . ".iso88591", $locale, substr($locale, 0, 2), 'de_DE.utf8', 'de_DE', 'de' ) ); \Locale::setDefault($locale); $translator->setLocale($locale); $routeMatch = $e->getRouteMatch(); if ($routeMatch && $routeMatch->getParam('lang') === null) { $routeMatch->setParam('lang', $lang); } /* @var $router \Zend\Mvc\Router\SimpleRouteStack */ $router = $e->getRouter(); $router->setDefaultParam('lang', $lang); }
[ "public", "function", "onRoute", "(", "MvcEvent", "$", "e", ")", "{", "/* @var $request \\Zend\\Http\\PhpEnvironment\\Request */", "$", "request", "=", "$", "e", "->", "getRequest", "(", ")", ";", "/* Detect language */", "$", "lang", "=", "$", "request", "->", "getQuery", "(", "'lang'", ")", ";", "if", "(", "!", "$", "lang", ")", "{", "$", "headers", "=", "$", "request", "->", "getHeaders", "(", ")", ";", "if", "(", "$", "headers", "->", "has", "(", "'Accept-Language'", ")", ")", "{", "/* @var $acceptLangs \\Zend\\Http\\Header\\AcceptLanguage */", "$", "acceptLangs", "=", "$", "headers", "->", "get", "(", "'Accept-Language'", ")", ";", "$", "locales", "=", "$", "acceptLangs", "->", "getPrioritized", "(", ")", ";", "$", "locale", "=", "$", "locales", "[", "0", "]", ";", "$", "lang", "=", "$", "locale", "->", "type", ";", "}", "else", "{", "$", "lang", "=", "'en'", ";", "}", "}", "/* Set locale */", "$", "translator", "=", "$", "e", "->", "getApplication", "(", ")", "->", "getServiceManager", "(", ")", "->", "get", "(", "'mvctranslator'", ")", ";", "$", "locale", "=", "$", "lang", ".", "'_'", ".", "strtoupper", "(", "$", "lang", ")", ";", "setlocale", "(", "LC_ALL", ",", "array", "(", "$", "locale", ".", "\".utf8\"", ",", "$", "locale", ".", "\".iso88591\"", ",", "$", "locale", ",", "substr", "(", "$", "locale", ",", "0", ",", "2", ")", ",", "'de_DE.utf8'", ",", "'de_DE'", ",", "'de'", ")", ")", ";", "\\", "Locale", "::", "setDefault", "(", "$", "locale", ")", ";", "$", "translator", "->", "setLocale", "(", "$", "locale", ")", ";", "$", "routeMatch", "=", "$", "e", "->", "getRouteMatch", "(", ")", ";", "if", "(", "$", "routeMatch", "&&", "$", "routeMatch", "->", "getParam", "(", "'lang'", ")", "===", "null", ")", "{", "$", "routeMatch", "->", "setParam", "(", "'lang'", ",", "$", "lang", ")", ";", "}", "/* @var $router \\Zend\\Mvc\\Router\\SimpleRouteStack */", "$", "router", "=", "$", "e", "->", "getRouter", "(", ")", ";", "$", "router", "->", "setDefaultParam", "(", "'lang'", ",", "$", "lang", ")", ";", "}" ]
Listens to the route event. Detects the language to use and sets translator locale. The language is detected either via query parameter "lang" or browser setting (ACCEPT-LANGUAGE header) @param MvcEvent $e
[ "Listens", "to", "the", "route", "event", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Listener/LanguageSetter.php#L59-L106
36,118
systemson/cache
src/Driver/ApcuCache.php
ApcuCache.isCli
public static function isCli() { if (defined('STDIN')) { return true; } if (php_sapi_name() === 'cli') { return true; } if (array_key_exists('SHELL', $_ENV)) { return true; } if (empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) { return true; } if (!array_key_exists('REQUEST_METHOD', $_SERVER)) { return true; } return false; }
php
public static function isCli() { if (defined('STDIN')) { return true; } if (php_sapi_name() === 'cli') { return true; } if (array_key_exists('SHELL', $_ENV)) { return true; } if (empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) { return true; } if (!array_key_exists('REQUEST_METHOD', $_SERVER)) { return true; } return false; }
[ "public", "static", "function", "isCli", "(", ")", "{", "if", "(", "defined", "(", "'STDIN'", ")", ")", "{", "return", "true", ";", "}", "if", "(", "php_sapi_name", "(", ")", "===", "'cli'", ")", "{", "return", "true", ";", "}", "if", "(", "array_key_exists", "(", "'SHELL'", ",", "$", "_ENV", ")", ")", "{", "return", "true", ";", "}", "if", "(", "empty", "(", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ")", "and", "!", "isset", "(", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", "and", "count", "(", "$", "_SERVER", "[", "'argv'", "]", ")", ">", "0", ")", "{", "return", "true", ";", "}", "if", "(", "!", "array_key_exists", "(", "'REQUEST_METHOD'", ",", "$", "_SERVER", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Determines whether the script is being run on the CLI. @todo This method MUST be move to a helper. @return bool
[ "Determines", "whether", "the", "script", "is", "being", "run", "on", "the", "CLI", "." ]
a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c
https://github.com/systemson/cache/blob/a85de2648fe8c1f73be6cfdcea4d1ee27e42f15c/src/Driver/ApcuCache.php#L130-L153
36,119
yawik/install
src/Controller/Plugin/YawikConfigCreator.php
YawikConfigCreator.process
public function process($dbConn, $email) { // extract database $dbName = $this->dbNameExctractor->filter($dbConn); $config = array( 'doctrine' => array( 'connection' => array( 'odm_default' => array( 'connectionString' => $dbConn, ), ), 'configuration' => array( 'odm_default' => array( 'default_db' => $dbName, ), ), ), 'core_options' => array( 'system_message_email' => $email, ), ); $content = $this->generateConfigContent($config); $ok = $this->writeConfigFile($content); return $ok ? true : $content; }
php
public function process($dbConn, $email) { // extract database $dbName = $this->dbNameExctractor->filter($dbConn); $config = array( 'doctrine' => array( 'connection' => array( 'odm_default' => array( 'connectionString' => $dbConn, ), ), 'configuration' => array( 'odm_default' => array( 'default_db' => $dbName, ), ), ), 'core_options' => array( 'system_message_email' => $email, ), ); $content = $this->generateConfigContent($config); $ok = $this->writeConfigFile($content); return $ok ? true : $content; }
[ "public", "function", "process", "(", "$", "dbConn", ",", "$", "email", ")", "{", "// extract database", "$", "dbName", "=", "$", "this", "->", "dbNameExctractor", "->", "filter", "(", "$", "dbConn", ")", ";", "$", "config", "=", "array", "(", "'doctrine'", "=>", "array", "(", "'connection'", "=>", "array", "(", "'odm_default'", "=>", "array", "(", "'connectionString'", "=>", "$", "dbConn", ",", ")", ",", ")", ",", "'configuration'", "=>", "array", "(", "'odm_default'", "=>", "array", "(", "'default_db'", "=>", "$", "dbName", ",", ")", ",", ")", ",", ")", ",", "'core_options'", "=>", "array", "(", "'system_message_email'", "=>", "$", "email", ",", ")", ",", ")", ";", "$", "content", "=", "$", "this", "->", "generateConfigContent", "(", "$", "config", ")", ";", "$", "ok", "=", "$", "this", "->", "writeConfigFile", "(", "$", "content", ")", ";", "return", "$", "ok", "?", "true", ":", "$", "content", ";", "}" ]
Generates a configuration file. @param string $dbConn @param string $email @return bool|string
[ "Generates", "a", "configuration", "file", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/YawikConfigCreator.php#L52-L80
36,120
yawik/install
src/Controller/Plugin/YawikConfigCreator.php
YawikConfigCreator.generateConfigContent
protected function generateConfigContent(array $config) { /* This code is taken from ZF2s' classmap_generator.php script. */ // Create a file with the class/file map. // Stupid syntax highlighters make separating < from PHP declaration necessary $content = '<' . "?php\n" . "\n" . 'return ' . var_export($config, true) . ';'; // Fix \' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op $content = str_replace("\\'", "'", $content); // Remove unnecessary double-backslashes $content = str_replace('\\\\', '\\', $content); // Exchange "array (" width "array(" $content = str_replace('array (', 'array(', $content); // Make the file end by EOL $content = rtrim($content, "\n") . "\n"; var_export($config, true); return $content; }
php
protected function generateConfigContent(array $config) { /* This code is taken from ZF2s' classmap_generator.php script. */ // Create a file with the class/file map. // Stupid syntax highlighters make separating < from PHP declaration necessary $content = '<' . "?php\n" . "\n" . 'return ' . var_export($config, true) . ';'; // Fix \' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op $content = str_replace("\\'", "'", $content); // Remove unnecessary double-backslashes $content = str_replace('\\\\', '\\', $content); // Exchange "array (" width "array(" $content = str_replace('array (', 'array(', $content); // Make the file end by EOL $content = rtrim($content, "\n") . "\n"; var_export($config, true); return $content; }
[ "protected", "function", "generateConfigContent", "(", "array", "$", "config", ")", "{", "/* This code is taken from ZF2s' classmap_generator.php script. */", "// Create a file with the class/file map.", "// Stupid syntax highlighters make separating < from PHP declaration necessary", "$", "content", "=", "'<'", ".", "\"?php\\n\"", ".", "\"\\n\"", ".", "'return '", ".", "var_export", "(", "$", "config", ",", "true", ")", ".", "';'", ";", "// Fix \\' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op", "$", "content", "=", "str_replace", "(", "\"\\\\'\"", ",", "\"'\"", ",", "$", "content", ")", ";", "// Remove unnecessary double-backslashes", "$", "content", "=", "str_replace", "(", "'\\\\\\\\'", ",", "'\\\\'", ",", "$", "content", ")", ";", "// Exchange \"array (\" width \"array(\"", "$", "content", "=", "str_replace", "(", "'array ('", ",", "'array('", ",", "$", "content", ")", ";", "// Make the file end by EOL", "$", "content", "=", "rtrim", "(", "$", "content", ",", "\"\\n\"", ")", ".", "\"\\n\"", ";", "var_export", "(", "$", "config", ",", "true", ")", ";", "return", "$", "content", ";", "}" ]
Generates the content for the configuration file. @param array $config @return string
[ "Generates", "the", "content", "for", "the", "configuration", "file", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/YawikConfigCreator.php#L89-L115
36,121
yawik/install
src/Controller/Plugin/YawikConfigCreator.php
YawikConfigCreator.writeConfigFile
protected function writeConfigFile($content) { if (!is_writable('config/autoload')) { return false; } $file = 'config/autoload/yawik.config.global.php'; // need to chmod 777 to be usable by docker and local environment @touch($file); @chmod($file, 0777); return (bool) @file_put_contents($file, $content, LOCK_EX); }
php
protected function writeConfigFile($content) { if (!is_writable('config/autoload')) { return false; } $file = 'config/autoload/yawik.config.global.php'; // need to chmod 777 to be usable by docker and local environment @touch($file); @chmod($file, 0777); return (bool) @file_put_contents($file, $content, LOCK_EX); }
[ "protected", "function", "writeConfigFile", "(", "$", "content", ")", "{", "if", "(", "!", "is_writable", "(", "'config/autoload'", ")", ")", "{", "return", "false", ";", "}", "$", "file", "=", "'config/autoload/yawik.config.global.php'", ";", "// need to chmod 777 to be usable by docker and local environment", "@", "touch", "(", "$", "file", ")", ";", "@", "chmod", "(", "$", "file", ",", "0777", ")", ";", "return", "(", "bool", ")", "@", "file_put_contents", "(", "$", "file", ",", "$", "content", ",", "LOCK_EX", ")", ";", "}" ]
Writes the configuration content in a file. Returns false, if file cannot be created. @param string $content @return bool
[ "Writes", "the", "configuration", "content", "in", "a", "file", "." ]
1283d512a852d305e18d311c3eb1a84da98b9656
https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/YawikConfigCreator.php#L126-L137
36,122
elgentos/parser
src/Parser/StoryMetrics.php
StoryMetrics.addStories
public function addStories(Story ...$stories): void { \array_walk($stories, function ($story) { $this->stories[] = $story; $this->storyCount++; }); }
php
public function addStories(Story ...$stories): void { \array_walk($stories, function ($story) { $this->stories[] = $story; $this->storyCount++; }); }
[ "public", "function", "addStories", "(", "Story", "...", "$", "stories", ")", ":", "void", "{", "\\", "array_walk", "(", "$", "stories", ",", "function", "(", "$", "story", ")", "{", "$", "this", "->", "stories", "[", "]", "=", "$", "story", ";", "$", "this", "->", "storyCount", "++", ";", "}", ")", ";", "}" ]
Add story to book @param []Story ...$stories
[ "Add", "story", "to", "book" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser/StoryMetrics.php#L26-L32
36,123
elgentos/parser
src/Parser/StoryMetrics.php
StoryMetrics.createStory
public function createStory(string $name, RuleInterface ...$rules): Story { $story = new Story($name, ...$rules); $this->addStories($story); return $story; }
php
public function createStory(string $name, RuleInterface ...$rules): Story { $story = new Story($name, ...$rules); $this->addStories($story); return $story; }
[ "public", "function", "createStory", "(", "string", "$", "name", ",", "RuleInterface", "...", "$", "rules", ")", ":", "Story", "{", "$", "story", "=", "new", "Story", "(", "$", "name", ",", "...", "$", "rules", ")", ";", "$", "this", "->", "addStories", "(", "$", "story", ")", ";", "return", "$", "story", ";", "}" ]
Create a story from rules and add to book @param string $name @param RuleInterface ...$rules @return Story
[ "Create", "a", "story", "from", "rules", "and", "add", "to", "book" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser/StoryMetrics.php#L41-L47
36,124
elgentos/parser
src/Parser/StoryMetrics.php
StoryMetrics.getStoriesSortedByName
private function getStoriesSortedByName(): array { $stories = $this->stories; \usort($stories, function(Story $storyA, Story $storyB) { return $storyA->getName() <=> $storyB->getName(); }); return $stories; }
php
private function getStoriesSortedByName(): array { $stories = $this->stories; \usort($stories, function(Story $storyA, Story $storyB) { return $storyA->getName() <=> $storyB->getName(); }); return $stories; }
[ "private", "function", "getStoriesSortedByName", "(", ")", ":", "array", "{", "$", "stories", "=", "$", "this", "->", "stories", ";", "\\", "usort", "(", "$", "stories", ",", "function", "(", "Story", "$", "storyA", ",", "Story", "$", "storyB", ")", "{", "return", "$", "storyA", "->", "getName", "(", ")", "<=>", "$", "storyB", "->", "getName", "(", ")", ";", "}", ")", ";", "return", "$", "stories", ";", "}" ]
Sort stories by name @return array
[ "Sort", "stories", "by", "name" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser/StoryMetrics.php#L130-L138
36,125
elgentos/parser
src/Parser.php
Parser.readFile
public static function readFile(string $filename, string $rootDir = '.', ParserInterface $parser = null): array { $data = ['@import' => $filename]; $story = new Complex($rootDir); $parser = $parser ?? new Standard; $parser->parse($data, $story); return $data; }
php
public static function readFile(string $filename, string $rootDir = '.', ParserInterface $parser = null): array { $data = ['@import' => $filename]; $story = new Complex($rootDir); $parser = $parser ?? new Standard; $parser->parse($data, $story); return $data; }
[ "public", "static", "function", "readFile", "(", "string", "$", "filename", ",", "string", "$", "rootDir", "=", "'.'", ",", "ParserInterface", "$", "parser", "=", "null", ")", ":", "array", "{", "$", "data", "=", "[", "'@import'", "=>", "$", "filename", "]", ";", "$", "story", "=", "new", "Complex", "(", "$", "rootDir", ")", ";", "$", "parser", "=", "$", "parser", "??", "new", "Standard", ";", "$", "parser", "->", "parse", "(", "$", "data", ",", "$", "story", ")", ";", "return", "$", "data", ";", "}" ]
Read a file in a given basedir defaults to current workdir optional, give a own parser if you want to debug @param string $filename @param string $rootDir @param ParserInterface|null $parser @return array
[ "Read", "a", "file", "in", "a", "given", "basedir", "defaults", "to", "current", "workdir" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser.php#L33-L42
36,126
elgentos/parser
src/Parser.php
Parser.readSimple
public static function readSimple(string $filename, string $rootDir = '.', ParserInterface $parser = null): array { $data = ['@import' => $filename]; $story = new Simple($rootDir); $parser = $parser ?? new Standard; $parser->parse($data, $story); return $data; }
php
public static function readSimple(string $filename, string $rootDir = '.', ParserInterface $parser = null): array { $data = ['@import' => $filename]; $story = new Simple($rootDir); $parser = $parser ?? new Standard; $parser->parse($data, $story); return $data; }
[ "public", "static", "function", "readSimple", "(", "string", "$", "filename", ",", "string", "$", "rootDir", "=", "'.'", ",", "ParserInterface", "$", "parser", "=", "null", ")", ":", "array", "{", "$", "data", "=", "[", "'@import'", "=>", "$", "filename", "]", ";", "$", "story", "=", "new", "Simple", "(", "$", "rootDir", ")", ";", "$", "parser", "=", "$", "parser", "??", "new", "Standard", ";", "$", "parser", "->", "parse", "(", "$", "data", ",", "$", "story", ")", ";", "return", "$", "data", ";", "}" ]
Read a file without recursion @param string $filename @param string $rootDir @param ParserInterface|null $parser @return array
[ "Read", "a", "file", "without", "recursion" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser.php#L52-L61
36,127
elgentos/parser
src/Parser/Rule/FileAbstract.php
FileAbstract.safePath
private function safePath(string $path): string { while (($newPath = \str_replace('..', '', $path)) !== $path) { $path = $newPath; } return $path; }
php
private function safePath(string $path): string { while (($newPath = \str_replace('..', '', $path)) !== $path) { $path = $newPath; } return $path; }
[ "private", "function", "safePath", "(", "string", "$", "path", ")", ":", "string", "{", "while", "(", "(", "$", "newPath", "=", "\\", "str_replace", "(", "'..'", ",", "''", ",", "$", "path", ")", ")", "!==", "$", "path", ")", "{", "$", "path", "=", "$", "newPath", ";", "}", "return", "$", "path", ";", "}" ]
Filter nasty strings from path @param string $path @return string
[ "Filter", "nasty", "strings", "from", "path" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser/Rule/FileAbstract.php#L22-L29
36,128
elgentos/parser
src/Parser/Rule/MergeDown.php
MergeDown.niceMerge
private function niceMerge(array &$source, array &$destination): array { $merged = $source; foreach ($destination as $key => &$value) { if ( $this->mergeRecursive && isset($merged[$key]) && is_array($merged[$key]) ) { $merged[$key] = $this->niceMerge($source[$key], $value); continue; } $merged[$key] = $value; } return $merged; }
php
private function niceMerge(array &$source, array &$destination): array { $merged = $source; foreach ($destination as $key => &$value) { if ( $this->mergeRecursive && isset($merged[$key]) && is_array($merged[$key]) ) { $merged[$key] = $this->niceMerge($source[$key], $value); continue; } $merged[$key] = $value; } return $merged; }
[ "private", "function", "niceMerge", "(", "array", "&", "$", "source", ",", "array", "&", "$", "destination", ")", ":", "array", "{", "$", "merged", "=", "$", "source", ";", "foreach", "(", "$", "destination", "as", "$", "key", "=>", "&", "$", "value", ")", "{", "if", "(", "$", "this", "->", "mergeRecursive", "&&", "isset", "(", "$", "merged", "[", "$", "key", "]", ")", "&&", "is_array", "(", "$", "merged", "[", "$", "key", "]", ")", ")", "{", "$", "merged", "[", "$", "key", "]", "=", "$", "this", "->", "niceMerge", "(", "$", "source", "[", "$", "key", "]", ",", "$", "value", ")", ";", "continue", ";", "}", "$", "merged", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "merged", ";", "}" ]
Recursive nice merge @param array $source @param array $destination @return array
[ "Recursive", "nice", "merge" ]
3580a4f55c725123eab643628d1fc3d5dd0968b3
https://github.com/elgentos/parser/blob/3580a4f55c725123eab643628d1fc3d5dd0968b3/src/Parser/Rule/MergeDown.php#L65-L83
36,129
KnpLabs/KnpPiwikBundle
DependencyInjection/KnpPiwikExtension.php
KnpPiwikExtension.load
public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); if (!$container->hasDefinition('piwik.client')) { $loader->load('piwik.xml'); } $config = $this->mergeConfigs($configs); if (isset($config['connection'])) { $definition = $container->getDefinition('piwik.client'); $arguments = $definition->getArguments(); $arguments[0] = new Reference($config['connection']); $definition->setArguments($arguments); } if (isset($config['url'])) { $container->setParameter('piwik.connection.http.url', $config['url']); } if (isset($config['init'])) { $container->setParameter('piwik.connection.piwik.init', (bool) $config['init']); } if (isset($config['token'])) { $container->setParameter('piwik.client.token', $config['token']); } }
php
public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); if (!$container->hasDefinition('piwik.client')) { $loader->load('piwik.xml'); } $config = $this->mergeConfigs($configs); if (isset($config['connection'])) { $definition = $container->getDefinition('piwik.client'); $arguments = $definition->getArguments(); $arguments[0] = new Reference($config['connection']); $definition->setArguments($arguments); } if (isset($config['url'])) { $container->setParameter('piwik.connection.http.url', $config['url']); } if (isset($config['init'])) { $container->setParameter('piwik.connection.piwik.init', (bool) $config['init']); } if (isset($config['token'])) { $container->setParameter('piwik.client.token', $config['token']); } }
[ "public", "function", "load", "(", "array", "$", "configs", ",", "ContainerBuilder", "$", "container", ")", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "if", "(", "!", "$", "container", "->", "hasDefinition", "(", "'piwik.client'", ")", ")", "{", "$", "loader", "->", "load", "(", "'piwik.xml'", ")", ";", "}", "$", "config", "=", "$", "this", "->", "mergeConfigs", "(", "$", "configs", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'connection'", "]", ")", ")", "{", "$", "definition", "=", "$", "container", "->", "getDefinition", "(", "'piwik.client'", ")", ";", "$", "arguments", "=", "$", "definition", "->", "getArguments", "(", ")", ";", "$", "arguments", "[", "0", "]", "=", "new", "Reference", "(", "$", "config", "[", "'connection'", "]", ")", ";", "$", "definition", "->", "setArguments", "(", "$", "arguments", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'url'", "]", ")", ")", "{", "$", "container", "->", "setParameter", "(", "'piwik.connection.http.url'", ",", "$", "config", "[", "'url'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'init'", "]", ")", ")", "{", "$", "container", "->", "setParameter", "(", "'piwik.connection.piwik.init'", ",", "(", "bool", ")", "$", "config", "[", "'init'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "config", "[", "'token'", "]", ")", ")", "{", "$", "container", "->", "setParameter", "(", "'piwik.client.token'", ",", "$", "config", "[", "'token'", "]", ")", ";", "}", "}" ]
Loads the piwik configuration. @param array $config An array of configuration settings @param \Symfony\Component\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
[ "Loads", "the", "piwik", "configuration", "." ]
e905ed745237fb6fc71175a5b571b771b97b3f7f
https://github.com/KnpLabs/KnpPiwikBundle/blob/e905ed745237fb6fc71175a5b571b771b97b3f7f/DependencyInjection/KnpPiwikExtension.php#L28-L56
36,130
KnpLabs/KnpPiwikBundle
DependencyInjection/KnpPiwikExtension.php
KnpPiwikExtension.mergeConfigs
protected function mergeConfigs(array $configs) { $merged = array(); foreach ($configs as $config) { $merged = array_merge($merged, $config); } return $merged; }
php
protected function mergeConfigs(array $configs) { $merged = array(); foreach ($configs as $config) { $merged = array_merge($merged, $config); } return $merged; }
[ "protected", "function", "mergeConfigs", "(", "array", "$", "configs", ")", "{", "$", "merged", "=", "array", "(", ")", ";", "foreach", "(", "$", "configs", "as", "$", "config", ")", "{", "$", "merged", "=", "array_merge", "(", "$", "merged", ",", "$", "config", ")", ";", "}", "return", "$", "merged", ";", "}" ]
Merges the given configurations array @param array $config @return array
[ "Merges", "the", "given", "configurations", "array" ]
e905ed745237fb6fc71175a5b571b771b97b3f7f
https://github.com/KnpLabs/KnpPiwikBundle/blob/e905ed745237fb6fc71175a5b571b771b97b3f7f/DependencyInjection/KnpPiwikExtension.php#L65-L73
36,131
matthiasnoback/phpunit-asynchronicity
src/Asynchronicity/Polling/Poller.php
Poller.poll
public function poll(callable $probe, Timeout $timeout): void { $timeout->start(); $lastException = null; while (true) { try { $probe(); // the probe was successful, so we can return now return; } catch (Exception $exception) { // the probe was unsuccessful, we remember the last exception $lastException = $exception; } if ($timeout->hasTimedOut()) { throw new Interrupted('A timeout has occurred', 0, $lastException); } // we wait before trying again $timeout->wait(); } }
php
public function poll(callable $probe, Timeout $timeout): void { $timeout->start(); $lastException = null; while (true) { try { $probe(); // the probe was successful, so we can return now return; } catch (Exception $exception) { // the probe was unsuccessful, we remember the last exception $lastException = $exception; } if ($timeout->hasTimedOut()) { throw new Interrupted('A timeout has occurred', 0, $lastException); } // we wait before trying again $timeout->wait(); } }
[ "public", "function", "poll", "(", "callable", "$", "probe", ",", "Timeout", "$", "timeout", ")", ":", "void", "{", "$", "timeout", "->", "start", "(", ")", ";", "$", "lastException", "=", "null", ";", "while", "(", "true", ")", "{", "try", "{", "$", "probe", "(", ")", ";", "// the probe was successful, so we can return now", "return", ";", "}", "catch", "(", "Exception", "$", "exception", ")", "{", "// the probe was unsuccessful, we remember the last exception", "$", "lastException", "=", "$", "exception", ";", "}", "if", "(", "$", "timeout", "->", "hasTimedOut", "(", ")", ")", "{", "throw", "new", "Interrupted", "(", "'A timeout has occurred'", ",", "0", ",", "$", "lastException", ")", ";", "}", "// we wait before trying again", "$", "timeout", "->", "wait", "(", ")", ";", "}", "}" ]
Invoke the provided callable until it doesn't throw an exception anymore, or a timeout occurs. The poller will wait before invoking the callable again. @param callable $probe @param Timeout $timeout
[ "Invoke", "the", "provided", "callable", "until", "it", "doesn", "t", "throw", "an", "exception", "anymore", "or", "a", "timeout", "occurs", ".", "The", "poller", "will", "wait", "before", "invoking", "the", "callable", "again", "." ]
b7f7ff4485de7d569be18e4343855c1fcbe05c14
https://github.com/matthiasnoback/phpunit-asynchronicity/blob/b7f7ff4485de7d569be18e4343855c1fcbe05c14/src/Asynchronicity/Polling/Poller.php#L17-L40
36,132
KnpLabs/PiwikClient
src/Knp/PiwikClient/Client.php
Client.call
public function call($method, array $params = array(), $format = 'php') { $params['method'] = $method; $params['token_auth'] = $this->token; $params['format'] = $format; $data = $this->getConnection()->send($params); if ('php' === $format) { $object = unserialize($data); if (isset($object['result']) && 'error' === $object['result']) { throw new Exception($object['message']); } return $object; } else { return $data; } }
php
public function call($method, array $params = array(), $format = 'php') { $params['method'] = $method; $params['token_auth'] = $this->token; $params['format'] = $format; $data = $this->getConnection()->send($params); if ('php' === $format) { $object = unserialize($data); if (isset($object['result']) && 'error' === $object['result']) { throw new Exception($object['message']); } return $object; } else { return $data; } }
[ "public", "function", "call", "(", "$", "method", ",", "array", "$", "params", "=", "array", "(", ")", ",", "$", "format", "=", "'php'", ")", "{", "$", "params", "[", "'method'", "]", "=", "$", "method", ";", "$", "params", "[", "'token_auth'", "]", "=", "$", "this", "->", "token", ";", "$", "params", "[", "'format'", "]", "=", "$", "format", ";", "$", "data", "=", "$", "this", "->", "getConnection", "(", ")", "->", "send", "(", "$", "params", ")", ";", "if", "(", "'php'", "===", "$", "format", ")", "{", "$", "object", "=", "unserialize", "(", "$", "data", ")", ";", "if", "(", "isset", "(", "$", "object", "[", "'result'", "]", ")", "&&", "'error'", "===", "$", "object", "[", "'result'", "]", ")", "{", "throw", "new", "Exception", "(", "$", "object", "[", "'message'", "]", ")", ";", "}", "return", "$", "object", ";", "}", "else", "{", "return", "$", "data", ";", "}", "}" ]
Call specific method & return it's response. @param string $method method name @param array $params method parameters @param string $format return format (php, json, xml, csv, tsv, html, rss) @return mixed
[ "Call", "specific", "method", "&", "return", "it", "s", "response", "." ]
853f427b7506141477dc2a699945be1473baa8d3
https://github.com/KnpLabs/PiwikClient/blob/853f427b7506141477dc2a699945be1473baa8d3/src/Knp/PiwikClient/Client.php#L49-L68
36,133
KnpLabs/PiwikClient
src/Knp/PiwikClient/Connection/PiwikConnection.php
PiwikConnection.convertParamsToQuery
protected function convertParamsToQuery(array $params) { $query = array(); foreach ($params as $key => $val) { if (is_array($val)) { $val = implode(',', $val); } elseif ($val instanceof \DateTime) { $val = $val->format('Y-m-d'); } elseif (is_bool($val)) { if ($val) { $val = 1; } else { continue; } } else { $val = urlencode($val); } $query[] = $key . '=' . $val; } return implode('&', $query); }
php
protected function convertParamsToQuery(array $params) { $query = array(); foreach ($params as $key => $val) { if (is_array($val)) { $val = implode(',', $val); } elseif ($val instanceof \DateTime) { $val = $val->format('Y-m-d'); } elseif (is_bool($val)) { if ($val) { $val = 1; } else { continue; } } else { $val = urlencode($val); } $query[] = $key . '=' . $val; } return implode('&', $query); }
[ "protected", "function", "convertParamsToQuery", "(", "array", "$", "params", ")", "{", "$", "query", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "val", "=", "implode", "(", "','", ",", "$", "val", ")", ";", "}", "elseif", "(", "$", "val", "instanceof", "\\", "DateTime", ")", "{", "$", "val", "=", "$", "val", "->", "format", "(", "'Y-m-d'", ")", ";", "}", "elseif", "(", "is_bool", "(", "$", "val", ")", ")", "{", "if", "(", "$", "val", ")", "{", "$", "val", "=", "1", ";", "}", "else", "{", "continue", ";", "}", "}", "else", "{", "$", "val", "=", "urlencode", "(", "$", "val", ")", ";", "}", "$", "query", "[", "]", "=", "$", "key", ".", "'='", ".", "$", "val", ";", "}", "return", "implode", "(", "'&'", ",", "$", "query", ")", ";", "}" ]
Convert hash of parameters to query string. @param array $params hash @return string query string
[ "Convert", "hash", "of", "parameters", "to", "query", "string", "." ]
853f427b7506141477dc2a699945be1473baa8d3
https://github.com/KnpLabs/PiwikClient/blob/853f427b7506141477dc2a699945be1473baa8d3/src/Knp/PiwikClient/Connection/PiwikConnection.php#L47-L69
36,134
fillup/walmart-partner-api-sdk-php
src/mock/MockResponse.php
MockResponse.getResourceTypeFromUrl
public static function getResourceTypeFromUrl($url) { $matchFound = preg_match('/\/v[23]\/(\w+)[\/?]?/', $url, $matches); if( ! $matchFound || ! is_array($matches) || ! isset($matches[1])) { throw new \Exception('Unable to find resource type in url', 1462733277); } if ($matches[1] == 'getReport') { return 'report'; } elseif ($matches[1] == 'price') { return 'prices'; } return $matches[1]; }
php
public static function getResourceTypeFromUrl($url) { $matchFound = preg_match('/\/v[23]\/(\w+)[\/?]?/', $url, $matches); if( ! $matchFound || ! is_array($matches) || ! isset($matches[1])) { throw new \Exception('Unable to find resource type in url', 1462733277); } if ($matches[1] == 'getReport') { return 'report'; } elseif ($matches[1] == 'price') { return 'prices'; } return $matches[1]; }
[ "public", "static", "function", "getResourceTypeFromUrl", "(", "$", "url", ")", "{", "$", "matchFound", "=", "preg_match", "(", "'/\\/v[23]\\/(\\w+)[\\/?]?/'", ",", "$", "url", ",", "$", "matches", ")", ";", "if", "(", "!", "$", "matchFound", "||", "!", "is_array", "(", "$", "matches", ")", "||", "!", "isset", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unable to find resource type in url'", ",", "1462733277", ")", ";", "}", "if", "(", "$", "matches", "[", "1", "]", "==", "'getReport'", ")", "{", "return", "'report'", ";", "}", "elseif", "(", "$", "matches", "[", "1", "]", "==", "'price'", ")", "{", "return", "'prices'", ";", "}", "return", "$", "matches", "[", "1", "]", ";", "}" ]
Parse resource type out of url @param string $url @return string @throws \Exception
[ "Parse", "resource", "type", "out", "of", "url" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/mock/MockResponse.php#L94-L108
36,135
fillup/walmart-partner-api-sdk-php
src/mock/MockResponse.php
MockResponse.getPath
public static function getPath($url) { $matchFound = preg_match('/(\/v[23]\/.*$)/', $url, $matches); if( ! $matchFound || ! is_array($matches) || ! isset($matches[1])) { throw new \Exception('Unable to parse url path', 1462733286); } return $matches[1]; }
php
public static function getPath($url) { $matchFound = preg_match('/(\/v[23]\/.*$)/', $url, $matches); if( ! $matchFound || ! is_array($matches) || ! isset($matches[1])) { throw new \Exception('Unable to parse url path', 1462733286); } return $matches[1]; }
[ "public", "static", "function", "getPath", "(", "$", "url", ")", "{", "$", "matchFound", "=", "preg_match", "(", "'/(\\/v[23]\\/.*$)/'", ",", "$", "url", ",", "$", "matches", ")", ";", "if", "(", "!", "$", "matchFound", "||", "!", "is_array", "(", "$", "matches", ")", "||", "!", "isset", "(", "$", "matches", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unable to parse url path'", ",", "1462733286", ")", ";", "}", "return", "$", "matches", "[", "1", "]", ";", "}" ]
Parse request path out of url @param string $url @return string @throws \Exception
[ "Parse", "request", "path", "out", "of", "url" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/mock/MockResponse.php#L116-L124
36,136
fillup/walmart-partner-api-sdk-php
src/BaseClient.php
BaseClient.getEnvBaseUrl
public function getEnvBaseUrl($env) { switch ($env) { case self::ENV_PROD: return self::BASE_URL_PROD; case self::ENV_STAGE: return self::BASE_URL_STAGE; case self::ENV_MOCK: return null; } }
php
public function getEnvBaseUrl($env) { switch ($env) { case self::ENV_PROD: return self::BASE_URL_PROD; case self::ENV_STAGE: return self::BASE_URL_STAGE; case self::ENV_MOCK: return null; } }
[ "public", "function", "getEnvBaseUrl", "(", "$", "env", ")", "{", "switch", "(", "$", "env", ")", "{", "case", "self", "::", "ENV_PROD", ":", "return", "self", "::", "BASE_URL_PROD", ";", "case", "self", "::", "ENV_STAGE", ":", "return", "self", "::", "BASE_URL_STAGE", ";", "case", "self", "::", "ENV_MOCK", ":", "return", "null", ";", "}", "}" ]
Get baseUrl for given environment @param string $env @return null|string
[ "Get", "baseUrl", "for", "given", "environment" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/BaseClient.php#L93-L103
36,137
fillup/walmart-partner-api-sdk-php
src/Order.php
Order.listReleased
public function listReleased(array $config = []) { try { return $this->privateListReleased($config); } catch (\Exception $e) { if ($e instanceof RequestException) { /* * ListReleased and List return 404 error if no results are found, even for successful API calls, * So if result status is 404, transform to 200 with empty results. */ /** @var ResponseInterface $response */ $response = $e->getResponse(); if (strval($response->getStatusCode()) === '404') { return [ 'statusCode' => 200, 'list' => [ 'meta' => [ 'totalCount' => 0 ] ], 'elements' => [] ]; } throw $e; } else { throw $e; } } }
php
public function listReleased(array $config = []) { try { return $this->privateListReleased($config); } catch (\Exception $e) { if ($e instanceof RequestException) { /* * ListReleased and List return 404 error if no results are found, even for successful API calls, * So if result status is 404, transform to 200 with empty results. */ /** @var ResponseInterface $response */ $response = $e->getResponse(); if (strval($response->getStatusCode()) === '404') { return [ 'statusCode' => 200, 'list' => [ 'meta' => [ 'totalCount' => 0 ] ], 'elements' => [] ]; } throw $e; } else { throw $e; } } }
[ "public", "function", "listReleased", "(", "array", "$", "config", "=", "[", "]", ")", "{", "try", "{", "return", "$", "this", "->", "privateListReleased", "(", "$", "config", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "e", "instanceof", "RequestException", ")", "{", "/*\n * ListReleased and List return 404 error if no results are found, even for successful API calls,\n * So if result status is 404, transform to 200 with empty results.\n */", "/** @var ResponseInterface $response */", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "if", "(", "strval", "(", "$", "response", "->", "getStatusCode", "(", ")", ")", "===", "'404'", ")", "{", "return", "[", "'statusCode'", "=>", "200", ",", "'list'", "=>", "[", "'meta'", "=>", "[", "'totalCount'", "=>", "0", "]", "]", ",", "'elements'", "=>", "[", "]", "]", ";", "}", "throw", "$", "e", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}" ]
List released orders @param array $config @return array @throws \Exception
[ "List", "released", "orders" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Order.php#L76-L104
36,138
fillup/walmart-partner-api-sdk-php
src/Order.php
Order.listAll
public function listAll(array $config = []) { try { return $this->privateList($config); } catch (\Exception $e) { if ($e instanceof RequestException) { /* * ListReleased and List return 404 error if no results are found, even for successful API calls, * So if result status is 404, transform to 200 with empty results. */ /** @var ResponseInterface $response */ $response = $e->getResponse(); if (strval($response->getStatusCode()) === '404') { return [ 'statusCode' => 200, 'list' => [ 'meta' => [ 'totalCount' => 0 ] ], 'elements' => [] ]; } throw $e; } else { throw $e; } } }
php
public function listAll(array $config = []) { try { return $this->privateList($config); } catch (\Exception $e) { if ($e instanceof RequestException) { /* * ListReleased and List return 404 error if no results are found, even for successful API calls, * So if result status is 404, transform to 200 with empty results. */ /** @var ResponseInterface $response */ $response = $e->getResponse(); if (strval($response->getStatusCode()) === '404') { return [ 'statusCode' => 200, 'list' => [ 'meta' => [ 'totalCount' => 0 ] ], 'elements' => [] ]; } throw $e; } else { throw $e; } } }
[ "public", "function", "listAll", "(", "array", "$", "config", "=", "[", "]", ")", "{", "try", "{", "return", "$", "this", "->", "privateList", "(", "$", "config", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "e", "instanceof", "RequestException", ")", "{", "/*\n * ListReleased and List return 404 error if no results are found, even for successful API calls,\n * So if result status is 404, transform to 200 with empty results.\n */", "/** @var ResponseInterface $response */", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "if", "(", "strval", "(", "$", "response", "->", "getStatusCode", "(", ")", ")", "===", "'404'", ")", "{", "return", "[", "'statusCode'", "=>", "200", ",", "'list'", "=>", "[", "'meta'", "=>", "[", "'totalCount'", "=>", "0", "]", "]", ",", "'elements'", "=>", "[", "]", "]", ";", "}", "throw", "$", "e", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}" ]
List all orders @param array $config @return array @throws \Exception
[ "List", "all", "orders" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Order.php#L112-L140
36,139
fillup/walmart-partner-api-sdk-php
src/Order.php
Order.ship
public function ship($purchaseOrderId, $order) { if(!is_numeric($purchaseOrderId)){ throw new \Exception("purchaseOrderId must be numeric",1448480750); } $schema = [ '/orderShipment' => [ 'namespace' => 'ns3', 'childNamespace' => 'ns3', ], '/orderShipment/orderLines' => [ 'sendItemsAs' => 'orderLine', ], '/orderShipment/orderLines/orderLine/orderLineStatuses' => [ 'sendItemsAs' => 'orderLineStatus', ], '@namespaces' => [ 'ns3' => 'http://walmart.com/mp/v3/orders' ], ]; $a2x = new A2X($order, $schema); $xml = $a2x->asXml(); return $this->shipOrder([ 'purchaseOrderId' => $purchaseOrderId, 'order' => $xml, ]); }
php
public function ship($purchaseOrderId, $order) { if(!is_numeric($purchaseOrderId)){ throw new \Exception("purchaseOrderId must be numeric",1448480750); } $schema = [ '/orderShipment' => [ 'namespace' => 'ns3', 'childNamespace' => 'ns3', ], '/orderShipment/orderLines' => [ 'sendItemsAs' => 'orderLine', ], '/orderShipment/orderLines/orderLine/orderLineStatuses' => [ 'sendItemsAs' => 'orderLineStatus', ], '@namespaces' => [ 'ns3' => 'http://walmart.com/mp/v3/orders' ], ]; $a2x = new A2X($order, $schema); $xml = $a2x->asXml(); return $this->shipOrder([ 'purchaseOrderId' => $purchaseOrderId, 'order' => $xml, ]); }
[ "public", "function", "ship", "(", "$", "purchaseOrderId", ",", "$", "order", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "purchaseOrderId", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"purchaseOrderId must be numeric\"", ",", "1448480750", ")", ";", "}", "$", "schema", "=", "[", "'/orderShipment'", "=>", "[", "'namespace'", "=>", "'ns3'", ",", "'childNamespace'", "=>", "'ns3'", ",", "]", ",", "'/orderShipment/orderLines'", "=>", "[", "'sendItemsAs'", "=>", "'orderLine'", ",", "]", ",", "'/orderShipment/orderLines/orderLine/orderLineStatuses'", "=>", "[", "'sendItemsAs'", "=>", "'orderLineStatus'", ",", "]", ",", "'@namespaces'", "=>", "[", "'ns3'", "=>", "'http://walmart.com/mp/v3/orders'", "]", ",", "]", ";", "$", "a2x", "=", "new", "A2X", "(", "$", "order", ",", "$", "schema", ")", ";", "$", "xml", "=", "$", "a2x", "->", "asXml", "(", ")", ";", "return", "$", "this", "->", "shipOrder", "(", "[", "'purchaseOrderId'", "=>", "$", "purchaseOrderId", ",", "'order'", "=>", "$", "xml", ",", "]", ")", ";", "}" ]
Ship an order @param string $purchaseOrderId @param array $order @return array @throws \Exception
[ "Ship", "an", "order" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Order.php#L188-L217
36,140
fillup/walmart-partner-api-sdk-php
src/Order.php
Order.refund
public function refund($purchaseOrderId, $order) { if(!is_numeric($purchaseOrderId)){ throw new \Exception("purchaseOrderId must be numeric",1448480783); } $schema = [ '/orderRefund' => [ 'namespace' => 'ns3', 'childNamespace' => 'ns3', ], '/orderRefund/orderLines' => [ 'sendItemsAs' => 'orderLine', ], '/orderRefund/orderLines/orderLine/refunds' => [ 'sendItemsAs' => 'refund', ], '/orderRefund/orderLines/orderLine/refunds/refund/refundCharges' => [ 'sendItemsAs' => 'refundCharge', ], '@namespaces' => [ 'ns3' => 'http://walmart.com/mp/v3/orders' ], ]; $a2x = new A2X($order, $schema); $xml = $a2x->asXml(); return $this->refundOrder([ 'purchaseOrderId' => $purchaseOrderId, 'order' => $xml, ]); }
php
public function refund($purchaseOrderId, $order) { if(!is_numeric($purchaseOrderId)){ throw new \Exception("purchaseOrderId must be numeric",1448480783); } $schema = [ '/orderRefund' => [ 'namespace' => 'ns3', 'childNamespace' => 'ns3', ], '/orderRefund/orderLines' => [ 'sendItemsAs' => 'orderLine', ], '/orderRefund/orderLines/orderLine/refunds' => [ 'sendItemsAs' => 'refund', ], '/orderRefund/orderLines/orderLine/refunds/refund/refundCharges' => [ 'sendItemsAs' => 'refundCharge', ], '@namespaces' => [ 'ns3' => 'http://walmart.com/mp/v3/orders' ], ]; $a2x = new A2X($order, $schema); $xml = $a2x->asXml(); return $this->refundOrder([ 'purchaseOrderId' => $purchaseOrderId, 'order' => $xml, ]); }
[ "public", "function", "refund", "(", "$", "purchaseOrderId", ",", "$", "order", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "purchaseOrderId", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"purchaseOrderId must be numeric\"", ",", "1448480783", ")", ";", "}", "$", "schema", "=", "[", "'/orderRefund'", "=>", "[", "'namespace'", "=>", "'ns3'", ",", "'childNamespace'", "=>", "'ns3'", ",", "]", ",", "'/orderRefund/orderLines'", "=>", "[", "'sendItemsAs'", "=>", "'orderLine'", ",", "]", ",", "'/orderRefund/orderLines/orderLine/refunds'", "=>", "[", "'sendItemsAs'", "=>", "'refund'", ",", "]", ",", "'/orderRefund/orderLines/orderLine/refunds/refund/refundCharges'", "=>", "[", "'sendItemsAs'", "=>", "'refundCharge'", ",", "]", ",", "'@namespaces'", "=>", "[", "'ns3'", "=>", "'http://walmart.com/mp/v3/orders'", "]", ",", "]", ";", "$", "a2x", "=", "new", "A2X", "(", "$", "order", ",", "$", "schema", ")", ";", "$", "xml", "=", "$", "a2x", "->", "asXml", "(", ")", ";", "return", "$", "this", "->", "refundOrder", "(", "[", "'purchaseOrderId'", "=>", "$", "purchaseOrderId", ",", "'order'", "=>", "$", "xml", ",", "]", ")", ";", "}" ]
Refund an order @param string $purchaseOrderId @param array $order @return array @throws \Exception
[ "Refund", "an", "order" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Order.php#L226-L258
36,141
fillup/walmart-partner-api-sdk-php
src/Utils.php
Utils.stripNamespacesFromXml
public static function stripNamespacesFromXml($xml) { $xml = preg_replace('/<[a-zA-Z0-9]+:/','<',$xml); $xml = preg_replace('/<\/[a-zA-Z0-9]+:/','</',$xml); $xml = preg_replace('/ xmlns:[a-zA-Z0-9]+=".*">/','>',$xml); return $xml; }
php
public static function stripNamespacesFromXml($xml) { $xml = preg_replace('/<[a-zA-Z0-9]+:/','<',$xml); $xml = preg_replace('/<\/[a-zA-Z0-9]+:/','</',$xml); $xml = preg_replace('/ xmlns:[a-zA-Z0-9]+=".*">/','>',$xml); return $xml; }
[ "public", "static", "function", "stripNamespacesFromXml", "(", "$", "xml", ")", "{", "$", "xml", "=", "preg_replace", "(", "'/<[a-zA-Z0-9]+:/'", ",", "'<'", ",", "$", "xml", ")", ";", "$", "xml", "=", "preg_replace", "(", "'/<\\/[a-zA-Z0-9]+:/'", ",", "'</'", ",", "$", "xml", ")", ";", "$", "xml", "=", "preg_replace", "(", "'/ xmlns:[a-zA-Z0-9]+=\".*\">/'", ",", "'>'", ",", "$", "xml", ")", ";", "return", "$", "xml", ";", "}" ]
Remove namespaces from XML @param string $xml @return string
[ "Remove", "namespaces", "from", "XML" ]
8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7
https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Utils.php#L20-L27
36,142
Wandu/Framework
src/Wandu/Http/Factory/ServerRequestFactory.php
ServerRequestFactory.getPhpServerValuesFromPlainHeader
protected function getPhpServerValuesFromPlainHeader(array $plainHeaders) { $httpInformation = explode(' ', array_shift($plainHeaders)); $servers = [ 'REQUEST_METHOD' => $httpInformation[0], 'REQUEST_URI' => $httpInformation[1], 'SERVER_PROTOCOL' => $httpInformation[2], ]; foreach ($plainHeaders as $plainHeader) { list($key, $value) = array_map('trim', explode(':', $plainHeader, 2)); $servers['HTTP_' . strtoupper(str_replace('-', '_', $key))] = $value; } return $servers; }
php
protected function getPhpServerValuesFromPlainHeader(array $plainHeaders) { $httpInformation = explode(' ', array_shift($plainHeaders)); $servers = [ 'REQUEST_METHOD' => $httpInformation[0], 'REQUEST_URI' => $httpInformation[1], 'SERVER_PROTOCOL' => $httpInformation[2], ]; foreach ($plainHeaders as $plainHeader) { list($key, $value) = array_map('trim', explode(':', $plainHeader, 2)); $servers['HTTP_' . strtoupper(str_replace('-', '_', $key))] = $value; } return $servers; }
[ "protected", "function", "getPhpServerValuesFromPlainHeader", "(", "array", "$", "plainHeaders", ")", "{", "$", "httpInformation", "=", "explode", "(", "' '", ",", "array_shift", "(", "$", "plainHeaders", ")", ")", ";", "$", "servers", "=", "[", "'REQUEST_METHOD'", "=>", "$", "httpInformation", "[", "0", "]", ",", "'REQUEST_URI'", "=>", "$", "httpInformation", "[", "1", "]", ",", "'SERVER_PROTOCOL'", "=>", "$", "httpInformation", "[", "2", "]", ",", "]", ";", "foreach", "(", "$", "plainHeaders", "as", "$", "plainHeader", ")", "{", "list", "(", "$", "key", ",", "$", "value", ")", "=", "array_map", "(", "'trim'", ",", "explode", "(", "':'", ",", "$", "plainHeader", ",", "2", ")", ")", ";", "$", "servers", "[", "'HTTP_'", ".", "strtoupper", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "key", ")", ")", "]", "=", "$", "value", ";", "}", "return", "$", "servers", ";", "}" ]
Parse plain headers. @param array $plainHeaders @return array
[ "Parse", "plain", "headers", "." ]
765c9af25a649a5a33985f7bdb267b8f05d3d782
https://github.com/Wandu/Framework/blob/765c9af25a649a5a33985f7bdb267b8f05d3d782/src/Wandu/Http/Factory/ServerRequestFactory.php#L105-L118
36,143
oat-sa/lib-tao-dtms
src/DateTime.php
DateTime.getMicroseconds
public function getMicroseconds($asSeconds = false) { if ($asSeconds) { return round($this->microseconds * 1/1e6, 6); } return intval($this->microseconds); }
php
public function getMicroseconds($asSeconds = false) { if ($asSeconds) { return round($this->microseconds * 1/1e6, 6); } return intval($this->microseconds); }
[ "public", "function", "getMicroseconds", "(", "$", "asSeconds", "=", "false", ")", "{", "if", "(", "$", "asSeconds", ")", "{", "return", "round", "(", "$", "this", "->", "microseconds", "*", "1", "/", "1e6", ",", "6", ")", ";", "}", "return", "intval", "(", "$", "this", "->", "microseconds", ")", ";", "}" ]
Gets microseconds data from object @param boolean $asSeconds If defined, microseconds will be converted to seconds with fractions @return int|float
[ "Gets", "microseconds", "data", "from", "object" ]
dc3979af897154850756bc72e19a9670064b9f25
https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L35-L42
36,144
oat-sa/lib-tao-dtms
src/DateTime.php
DateTime.addMicroseconds
protected function addMicroseconds($microseconds) { if ($microseconds < 0) { throw new \InvalidArgumentException("Value of microseconds should be positive."); } $diff = $this->getMicroseconds() + $microseconds; $seconds = floor($diff / 1e6); $diff -= $seconds * 1e6; if ($diff >= 1e6) { $diff -= 1e6; $seconds++; } $this->modify("+$seconds seconds"); $this->setMicroseconds($diff); }
php
protected function addMicroseconds($microseconds) { if ($microseconds < 0) { throw new \InvalidArgumentException("Value of microseconds should be positive."); } $diff = $this->getMicroseconds() + $microseconds; $seconds = floor($diff / 1e6); $diff -= $seconds * 1e6; if ($diff >= 1e6) { $diff -= 1e6; $seconds++; } $this->modify("+$seconds seconds"); $this->setMicroseconds($diff); }
[ "protected", "function", "addMicroseconds", "(", "$", "microseconds", ")", "{", "if", "(", "$", "microseconds", "<", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Value of microseconds should be positive.\"", ")", ";", "}", "$", "diff", "=", "$", "this", "->", "getMicroseconds", "(", ")", "+", "$", "microseconds", ";", "$", "seconds", "=", "floor", "(", "$", "diff", "/", "1e6", ")", ";", "$", "diff", "-=", "$", "seconds", "*", "1e6", ";", "if", "(", "$", "diff", ">=", "1e6", ")", "{", "$", "diff", "-=", "1e6", ";", "$", "seconds", "++", ";", "}", "$", "this", "->", "modify", "(", "\"+$seconds seconds\"", ")", ";", "$", "this", "->", "setMicroseconds", "(", "$", "diff", ")", ";", "}" ]
Subtracts an amount of microseconds from a DateTime object @param $microseconds
[ "Subtracts", "an", "amount", "of", "microseconds", "from", "a", "DateTime", "object" ]
dc3979af897154850756bc72e19a9670064b9f25
https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L104-L121
36,145
oat-sa/lib-tao-dtms
src/DateTime.php
DateTime.subMicroseconds
protected function subMicroseconds($microseconds) { if ($microseconds < 0) { throw new \InvalidArgumentException("Value of microseconds should be positive."); } $diff = $this->getMicroseconds() - $microseconds; $seconds = floor($diff / 1e6); $diff -= $seconds * 1e6; if ($diff < 0) { $diff = abs($diff); $seconds++; } $this->modify("$seconds seconds"); $this->setMicroseconds($diff); }
php
protected function subMicroseconds($microseconds) { if ($microseconds < 0) { throw new \InvalidArgumentException("Value of microseconds should be positive."); } $diff = $this->getMicroseconds() - $microseconds; $seconds = floor($diff / 1e6); $diff -= $seconds * 1e6; if ($diff < 0) { $diff = abs($diff); $seconds++; } $this->modify("$seconds seconds"); $this->setMicroseconds($diff); }
[ "protected", "function", "subMicroseconds", "(", "$", "microseconds", ")", "{", "if", "(", "$", "microseconds", "<", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Value of microseconds should be positive.\"", ")", ";", "}", "$", "diff", "=", "$", "this", "->", "getMicroseconds", "(", ")", "-", "$", "microseconds", ";", "$", "seconds", "=", "floor", "(", "$", "diff", "/", "1e6", ")", ";", "$", "diff", "-=", "$", "seconds", "*", "1e6", ";", "if", "(", "$", "diff", "<", "0", ")", "{", "$", "diff", "=", "abs", "(", "$", "diff", ")", ";", "$", "seconds", "++", ";", "}", "$", "this", "->", "modify", "(", "\"$seconds seconds\"", ")", ";", "$", "this", "->", "setMicroseconds", "(", "$", "diff", ")", ";", "}" ]
Adds an amount of microseconds to a DateTime object @param $microseconds
[ "Adds", "an", "amount", "of", "microseconds", "to", "a", "DateTime", "object" ]
dc3979af897154850756bc72e19a9670064b9f25
https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L128-L145
36,146
oat-sa/lib-tao-dtms
src/DateTime.php
DateTime.add
public function add($interval) { parent::add($interval); if ($interval instanceof DateInterval) { if ($interval->invert) { // is negative, then sub $this->subMicroseconds($interval->u); } else { $this->addMicroseconds($interval->u); } } return $this; }
php
public function add($interval) { parent::add($interval); if ($interval instanceof DateInterval) { if ($interval->invert) { // is negative, then sub $this->subMicroseconds($interval->u); } else { $this->addMicroseconds($interval->u); } } return $this; }
[ "public", "function", "add", "(", "$", "interval", ")", "{", "parent", "::", "add", "(", "$", "interval", ")", ";", "if", "(", "$", "interval", "instanceof", "DateInterval", ")", "{", "if", "(", "$", "interval", "->", "invert", ")", "{", "// is negative, then sub", "$", "this", "->", "subMicroseconds", "(", "$", "interval", "->", "u", ")", ";", "}", "else", "{", "$", "this", "->", "addMicroseconds", "(", "$", "interval", "->", "u", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Adds an amount of days, months, years, hours, minutes, seconds and microseconds to a DateTime object @param DateInterval $interval @return DateTime $this
[ "Adds", "an", "amount", "of", "days", "months", "years", "hours", "minutes", "seconds", "and", "microseconds", "to", "a", "DateTime", "object" ]
dc3979af897154850756bc72e19a9670064b9f25
https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L153-L166
36,147
eleven-lab/laravel-geo
src/Eloquent/Model.php
Model.boot
protected static function boot() { parent::boot(); static::creating(function($model){ self::updateGeoAttributes($model); }); static::created(function($model){ self::updateGeoAttributes($model); }); static::updating(function($model){ self::updateGeoAttributes($model); }); static::updated(function($model){ self::updateGeoAttributes($model); }); }
php
protected static function boot() { parent::boot(); static::creating(function($model){ self::updateGeoAttributes($model); }); static::created(function($model){ self::updateGeoAttributes($model); }); static::updating(function($model){ self::updateGeoAttributes($model); }); static::updated(function($model){ self::updateGeoAttributes($model); }); }
[ "protected", "static", "function", "boot", "(", ")", "{", "parent", "::", "boot", "(", ")", ";", "static", "::", "creating", "(", "function", "(", "$", "model", ")", "{", "self", "::", "updateGeoAttributes", "(", "$", "model", ")", ";", "}", ")", ";", "static", "::", "created", "(", "function", "(", "$", "model", ")", "{", "self", "::", "updateGeoAttributes", "(", "$", "model", ")", ";", "}", ")", ";", "static", "::", "updating", "(", "function", "(", "$", "model", ")", "{", "self", "::", "updateGeoAttributes", "(", "$", "model", ")", ";", "}", ")", ";", "static", "::", "updated", "(", "function", "(", "$", "model", ")", "{", "self", "::", "updateGeoAttributes", "(", "$", "model", ")", ";", "}", ")", ";", "}" ]
Overriding the "booting" method of the model. @return void
[ "Overriding", "the", "booting", "method", "of", "the", "model", "." ]
3bd89e4b20563f79153c5dacc7b7f79a0c2ae0fa
https://github.com/eleven-lab/laravel-geo/blob/3bd89e4b20563f79153c5dacc7b7f79a0c2ae0fa/src/Eloquent/Model.php#L31-L50
36,148
theodorejb/peachy-sql
lib/SqlServer.php
SqlServer.query
public function query(string $sql, array $params = []): Statement { if (!$stmt = sqlsrv_query($this->connection, $sql, $params)) { throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params); } $statement = new Statement($stmt, false, $sql, $params); $statement->execute(); return $statement; }
php
public function query(string $sql, array $params = []): Statement { if (!$stmt = sqlsrv_query($this->connection, $sql, $params)) { throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params); } $statement = new Statement($stmt, false, $sql, $params); $statement->execute(); return $statement; }
[ "public", "function", "query", "(", "string", "$", "sql", ",", "array", "$", "params", "=", "[", "]", ")", ":", "Statement", "{", "if", "(", "!", "$", "stmt", "=", "sqlsrv_query", "(", "$", "this", "->", "connection", ",", "$", "sql", ",", "$", "params", ")", ")", "{", "throw", "new", "SqlException", "(", "'Query failed'", ",", "sqlsrv_errors", "(", ")", ",", "$", "sql", ",", "$", "params", ")", ";", "}", "$", "statement", "=", "new", "Statement", "(", "$", "stmt", ",", "false", ",", "$", "sql", ",", "$", "params", ")", ";", "$", "statement", "->", "execute", "(", ")", ";", "return", "$", "statement", ";", "}" ]
Prepares and executes a single SQL Server query with bound parameters @throws SqlException if an error occurs
[ "Prepares", "and", "executes", "a", "single", "SQL", "Server", "query", "with", "bound", "parameters" ]
f179c6fa6c4293c2713b6b59022f3cfc90890a98
https://github.com/theodorejb/peachy-sql/blob/f179c6fa6c4293c2713b6b59022f3cfc90890a98/lib/SqlServer.php#L101-L110
36,149
meritoo/common-library
src/Utilities/Arrays.php
Arrays.values2string
public static function values2string(array $array, $arrayColumnKey = '', $separator = ',') { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $values = []; foreach ($array as $key => $value) { $appendMe = null; if (is_array($value)) { $appendMe = self::values2string($value, $arrayColumnKey, $separator); } elseif (empty($arrayColumnKey)) { $appendMe = $value; } elseif ($key === $arrayColumnKey) { $appendMe = $array[$arrayColumnKey]; } /* * Part to append is unknown? * Let's go to next part */ if (null === $appendMe) { continue; } $values[] = $appendMe; } /* * No values found? * Nothing to do */ if (empty($values)) { return null; } return implode($separator, $values); }
php
public static function values2string(array $array, $arrayColumnKey = '', $separator = ',') { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $values = []; foreach ($array as $key => $value) { $appendMe = null; if (is_array($value)) { $appendMe = self::values2string($value, $arrayColumnKey, $separator); } elseif (empty($arrayColumnKey)) { $appendMe = $value; } elseif ($key === $arrayColumnKey) { $appendMe = $array[$arrayColumnKey]; } /* * Part to append is unknown? * Let's go to next part */ if (null === $appendMe) { continue; } $values[] = $appendMe; } /* * No values found? * Nothing to do */ if (empty($values)) { return null; } return implode($separator, $values); }
[ "public", "static", "function", "values2string", "(", "array", "$", "array", ",", "$", "arrayColumnKey", "=", "''", ",", "$", "separator", "=", "','", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "appendMe", "=", "null", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "appendMe", "=", "self", "::", "values2string", "(", "$", "value", ",", "$", "arrayColumnKey", ",", "$", "separator", ")", ";", "}", "elseif", "(", "empty", "(", "$", "arrayColumnKey", ")", ")", "{", "$", "appendMe", "=", "$", "value", ";", "}", "elseif", "(", "$", "key", "===", "$", "arrayColumnKey", ")", "{", "$", "appendMe", "=", "$", "array", "[", "$", "arrayColumnKey", "]", ";", "}", "/*\n * Part to append is unknown?\n * Let's go to next part\n */", "if", "(", "null", "===", "$", "appendMe", ")", "{", "continue", ";", "}", "$", "values", "[", "]", "=", "$", "appendMe", ";", "}", "/*\n * No values found?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "return", "null", ";", "}", "return", "implode", "(", "$", "separator", ",", "$", "values", ")", ";", "}" ]
Converts given array's column to string. Recursive call is made for multi-dimensional arrays. @param array $array Data to be converted @param int|string $arrayColumnKey (optional) Column name. Default: "". @param string $separator (optional) Separator used between values. Default: ",". @return null|string
[ "Converts", "given", "array", "s", "column", "to", "string", ".", "Recursive", "call", "is", "made", "for", "multi", "-", "dimensional", "arrays", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L35-L78
36,150
meritoo/common-library
src/Utilities/Arrays.php
Arrays.values2csv
public static function values2csv(array $array, $separator = ',') { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $rows = []; $lineSeparator = "\n"; foreach ($array as $row) { /* * I have to use html_entity_decode() function here, because some string values can contain * entities with semicolon and this can destroy the CSV column order. */ if (is_array($row) && !empty($row)) { foreach ($row as $key => $value) { $row[$key] = html_entity_decode($value); } $rows[] = implode($separator, $row); } } if (empty($rows)) { return ''; } return implode($lineSeparator, $rows); }
php
public static function values2csv(array $array, $separator = ',') { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $rows = []; $lineSeparator = "\n"; foreach ($array as $row) { /* * I have to use html_entity_decode() function here, because some string values can contain * entities with semicolon and this can destroy the CSV column order. */ if (is_array($row) && !empty($row)) { foreach ($row as $key => $value) { $row[$key] = html_entity_decode($value); } $rows[] = implode($separator, $row); } } if (empty($rows)) { return ''; } return implode($lineSeparator, $rows); }
[ "public", "static", "function", "values2csv", "(", "array", "$", "array", ",", "$", "separator", "=", "','", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "rows", "=", "[", "]", ";", "$", "lineSeparator", "=", "\"\\n\"", ";", "foreach", "(", "$", "array", "as", "$", "row", ")", "{", "/*\n * I have to use html_entity_decode() function here, because some string values can contain\n * entities with semicolon and this can destroy the CSV column order.\n */", "if", "(", "is_array", "(", "$", "row", ")", "&&", "!", "empty", "(", "$", "row", ")", ")", "{", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "row", "[", "$", "key", "]", "=", "html_entity_decode", "(", "$", "value", ")", ";", "}", "$", "rows", "[", "]", "=", "implode", "(", "$", "separator", ",", "$", "row", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "rows", ")", ")", "{", "return", "''", ";", "}", "return", "implode", "(", "$", "lineSeparator", ",", "$", "rows", ")", ";", "}" ]
Converts given array's rows to csv string @param array $array Data to be converted. It have to be an array that represents database table. @param string $separator (optional) Separator used between values. Default: ",". @return null|string
[ "Converts", "given", "array", "s", "rows", "to", "csv", "string" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L128-L161
36,151
meritoo/common-library
src/Utilities/Arrays.php
Arrays.isFirstElement
public static function isFirstElement(array $array, $element, $firstLevelOnly = true) { $firstElement = self::getFirstElement($array, $firstLevelOnly); return $element === $firstElement; }
php
public static function isFirstElement(array $array, $element, $firstLevelOnly = true) { $firstElement = self::getFirstElement($array, $firstLevelOnly); return $element === $firstElement; }
[ "public", "static", "function", "isFirstElement", "(", "array", "$", "array", ",", "$", "element", ",", "$", "firstLevelOnly", "=", "true", ")", "{", "$", "firstElement", "=", "self", "::", "getFirstElement", "(", "$", "array", ",", "$", "firstLevelOnly", ")", ";", "return", "$", "element", "===", "$", "firstElement", ";", "}" ]
Returns information if given element is the first one @param array $array The array to get the first element of @param mixed $element The element to check / verify @param bool $firstLevelOnly (optional) If is set to true, first element is returned. Otherwise - totally first element is returned (first of the First array). @return bool
[ "Returns", "information", "if", "given", "element", "is", "the", "first", "one" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L172-L177
36,152
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getFirstElement
public static function getFirstElement(array $array, $firstLevelOnly = true) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $firstKey = self::getFirstKey($array); $first = $array[$firstKey]; if (!$firstLevelOnly && is_array($first)) { $first = self::getFirstElement($first, $firstLevelOnly); } return $first; }
php
public static function getFirstElement(array $array, $firstLevelOnly = true) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $firstKey = self::getFirstKey($array); $first = $array[$firstKey]; if (!$firstLevelOnly && is_array($first)) { $first = self::getFirstElement($first, $firstLevelOnly); } return $first; }
[ "public", "static", "function", "getFirstElement", "(", "array", "$", "array", ",", "$", "firstLevelOnly", "=", "true", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "firstKey", "=", "self", "::", "getFirstKey", "(", "$", "array", ")", ";", "$", "first", "=", "$", "array", "[", "$", "firstKey", "]", ";", "if", "(", "!", "$", "firstLevelOnly", "&&", "is_array", "(", "$", "first", ")", ")", "{", "$", "first", "=", "self", "::", "getFirstElement", "(", "$", "first", ",", "$", "firstLevelOnly", ")", ";", "}", "return", "$", "first", ";", "}" ]
Returns the first element of given array It may be first element of given array or the totally first element from the all elements (first element of the first array). @param array $array The array to get the first element of @param bool $firstLevelOnly (optional) If is set to true, first element is returned. Otherwise - totally first element is returned (first of the first array). @return mixed
[ "Returns", "the", "first", "element", "of", "given", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L190-L208
36,153
meritoo/common-library
src/Utilities/Arrays.php
Arrays.isLastElement
public static function isLastElement(array $array, $element, $firstLevelOnly = true) { $lastElement = self::getLastElement($array, $firstLevelOnly); return $element === $lastElement; }
php
public static function isLastElement(array $array, $element, $firstLevelOnly = true) { $lastElement = self::getLastElement($array, $firstLevelOnly); return $element === $lastElement; }
[ "public", "static", "function", "isLastElement", "(", "array", "$", "array", ",", "$", "element", ",", "$", "firstLevelOnly", "=", "true", ")", "{", "$", "lastElement", "=", "self", "::", "getLastElement", "(", "$", "array", ",", "$", "firstLevelOnly", ")", ";", "return", "$", "element", "===", "$", "lastElement", ";", "}" ]
Returns information if given element is the last one @param array $array The array to get the last element of @param mixed $element The element to check / verify @param bool $firstLevelOnly (optional) If is set to true, last element is returned. Otherwise - totally last element is returned (last of the latest array). @return bool
[ "Returns", "information", "if", "given", "element", "is", "the", "last", "one" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L240-L245
36,154
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getLastElement
public static function getLastElement(array $array, $firstLevelOnly = true) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $last = end($array); if (!$firstLevelOnly && is_array($last)) { $last = self::getLastElement($last, $firstLevelOnly); } return $last; }
php
public static function getLastElement(array $array, $firstLevelOnly = true) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $last = end($array); if (!$firstLevelOnly && is_array($last)) { $last = self::getLastElement($last, $firstLevelOnly); } return $last; }
[ "public", "static", "function", "getLastElement", "(", "array", "$", "array", ",", "$", "firstLevelOnly", "=", "true", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "last", "=", "end", "(", "$", "array", ")", ";", "if", "(", "!", "$", "firstLevelOnly", "&&", "is_array", "(", "$", "last", ")", ")", "{", "$", "last", "=", "self", "::", "getLastElement", "(", "$", "last", ",", "$", "firstLevelOnly", ")", ";", "}", "return", "$", "last", ";", "}" ]
Returns the last element of given array It may be last element of given array or the totally last element from the all elements (last element of the latest array). @param array $array The array to get the last element of @param bool $firstLevelOnly (optional) If is set to true, last element is returned. Otherwise - totally last element is returned (last of the latest array). @return mixed
[ "Returns", "the", "last", "element", "of", "given", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L258-L275
36,155
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getLastRow
public static function getLastRow(array $array) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $effect = []; $last = end($array); if (is_array($last)) { // We've got an array, so looking for the last row of array will be done recursively $effect = self::getLastRow($last); /* * The last row is not an array or it's an empty array? * Let's use the previous candidate */ if (!is_array($effect) || (is_array($effect) && empty($effect))) { $effect = $last; } } return $effect; }
php
public static function getLastRow(array $array) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $effect = []; $last = end($array); if (is_array($last)) { // We've got an array, so looking for the last row of array will be done recursively $effect = self::getLastRow($last); /* * The last row is not an array or it's an empty array? * Let's use the previous candidate */ if (!is_array($effect) || (is_array($effect) && empty($effect))) { $effect = $last; } } return $effect; }
[ "public", "static", "function", "getLastRow", "(", "array", "$", "array", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "effect", "=", "[", "]", ";", "$", "last", "=", "end", "(", "$", "array", ")", ";", "if", "(", "is_array", "(", "$", "last", ")", ")", "{", "// We've got an array, so looking for the last row of array will be done recursively", "$", "effect", "=", "self", "::", "getLastRow", "(", "$", "last", ")", ";", "/*\n * The last row is not an array or it's an empty array?\n * Let's use the previous candidate\n */", "if", "(", "!", "is_array", "(", "$", "effect", ")", "||", "(", "is_array", "(", "$", "effect", ")", "&&", "empty", "(", "$", "effect", ")", ")", ")", "{", "$", "effect", "=", "$", "last", ";", "}", "}", "return", "$", "effect", ";", "}" ]
Returns the last row of array @param array $array The array to get the last row of @return mixed
[ "Returns", "the", "last", "row", "of", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L317-L344
36,156
meritoo/common-library
src/Utilities/Arrays.php
Arrays.replaceArrayKeys
public static function replaceArrayKeys($dataArray, $oldKeyPattern, $newKey) { $effect = []; if (is_array($dataArray) && !empty($dataArray)) { foreach ($dataArray as $key => $value) { if (preg_match($oldKeyPattern, $key)) { $key = $newKey; } if (is_array($value)) { $value = self::replaceArrayKeys($value, $oldKeyPattern, $newKey); } $effect[$key] = $value; } } return $effect; }
php
public static function replaceArrayKeys($dataArray, $oldKeyPattern, $newKey) { $effect = []; if (is_array($dataArray) && !empty($dataArray)) { foreach ($dataArray as $key => $value) { if (preg_match($oldKeyPattern, $key)) { $key = $newKey; } if (is_array($value)) { $value = self::replaceArrayKeys($value, $oldKeyPattern, $newKey); } $effect[$key] = $value; } } return $effect; }
[ "public", "static", "function", "replaceArrayKeys", "(", "$", "dataArray", ",", "$", "oldKeyPattern", ",", "$", "newKey", ")", "{", "$", "effect", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "dataArray", ")", "&&", "!", "empty", "(", "$", "dataArray", ")", ")", "{", "foreach", "(", "$", "dataArray", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "preg_match", "(", "$", "oldKeyPattern", ",", "$", "key", ")", ")", "{", "$", "key", "=", "$", "newKey", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "self", "::", "replaceArrayKeys", "(", "$", "value", ",", "$", "oldKeyPattern", ",", "$", "newKey", ")", ";", "}", "$", "effect", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "effect", ";", "}" ]
Replaces array keys that match given pattern with new key name @param array $dataArray The array @param string $oldKeyPattern Old key pattern @param string $newKey New key name @return array
[ "Replaces", "array", "keys", "that", "match", "given", "pattern", "with", "new", "key", "name" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L354-L373
36,157
meritoo/common-library
src/Utilities/Arrays.php
Arrays.array2JavaScript
public static function array2JavaScript(array $array, $jsVariableName = '', $preserveIndexes = false) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $result = ''; $counter = 0; $arrayCount = count($array); $arrayPrepared = self::quoteStrings($array); $isMultiDimensional = self::isMultiDimensional($arrayPrepared); /* * Name of the variable was not provided and it's a multi dimensional array? * Let's create the name, because variable is required for later usage (related to multi dimensional array) */ if (empty($jsVariableName) && $isMultiDimensional) { $jsVariableName = 'autoGeneratedVariable'; } if (!empty($jsVariableName) && is_string($jsVariableName)) { $result .= sprintf('var %s = ', $jsVariableName); } $result .= 'new Array('; if ($preserveIndexes || $isMultiDimensional) { $result .= $arrayCount; $result .= ');'; } foreach ($arrayPrepared as $index => $value) { ++$counter; if (is_array($value)) { $variable = $index; if (is_int($index)) { $variable = 'value_' . $variable; } $value = self::array2JavaScript($value, $variable, $preserveIndexes); if (null !== $value && '' !== $value) { /* * Add an empty line for the 1st iteration only. Required to avoid missing empty line after * declaration of variable: * * var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...); * autoGeneratedVariable[1] = new Array(...); */ if (1 === $counter) { $result .= "\n"; } $result .= $value . "\n"; $result .= sprintf('%s[%s] = %s;', $jsVariableName, Miscellaneous::quoteValue($index), $variable); if ($counter !== $arrayCount) { $result .= "\n"; } } } elseif ($preserveIndexes) { if (!empty($jsVariableName)) { $index = Miscellaneous::quoteValue($index); $result .= sprintf("\n%s[%s] = %s;", $jsVariableName, $index, $value); } } else { $format = '%s'; if ($counter < $arrayCount) { $format .= ', '; } $result .= sprintf($format, $value); } } if (!$preserveIndexes && !$isMultiDimensional) { $result .= ');'; } return $result; }
php
public static function array2JavaScript(array $array, $jsVariableName = '', $preserveIndexes = false) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $result = ''; $counter = 0; $arrayCount = count($array); $arrayPrepared = self::quoteStrings($array); $isMultiDimensional = self::isMultiDimensional($arrayPrepared); /* * Name of the variable was not provided and it's a multi dimensional array? * Let's create the name, because variable is required for later usage (related to multi dimensional array) */ if (empty($jsVariableName) && $isMultiDimensional) { $jsVariableName = 'autoGeneratedVariable'; } if (!empty($jsVariableName) && is_string($jsVariableName)) { $result .= sprintf('var %s = ', $jsVariableName); } $result .= 'new Array('; if ($preserveIndexes || $isMultiDimensional) { $result .= $arrayCount; $result .= ');'; } foreach ($arrayPrepared as $index => $value) { ++$counter; if (is_array($value)) { $variable = $index; if (is_int($index)) { $variable = 'value_' . $variable; } $value = self::array2JavaScript($value, $variable, $preserveIndexes); if (null !== $value && '' !== $value) { /* * Add an empty line for the 1st iteration only. Required to avoid missing empty line after * declaration of variable: * * var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...); * autoGeneratedVariable[1] = new Array(...); */ if (1 === $counter) { $result .= "\n"; } $result .= $value . "\n"; $result .= sprintf('%s[%s] = %s;', $jsVariableName, Miscellaneous::quoteValue($index), $variable); if ($counter !== $arrayCount) { $result .= "\n"; } } } elseif ($preserveIndexes) { if (!empty($jsVariableName)) { $index = Miscellaneous::quoteValue($index); $result .= sprintf("\n%s[%s] = %s;", $jsVariableName, $index, $value); } } else { $format = '%s'; if ($counter < $arrayCount) { $format .= ', '; } $result .= sprintf($format, $value); } } if (!$preserveIndexes && !$isMultiDimensional) { $result .= ');'; } return $result; }
[ "public", "static", "function", "array2JavaScript", "(", "array", "$", "array", ",", "$", "jsVariableName", "=", "''", ",", "$", "preserveIndexes", "=", "false", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "result", "=", "''", ";", "$", "counter", "=", "0", ";", "$", "arrayCount", "=", "count", "(", "$", "array", ")", ";", "$", "arrayPrepared", "=", "self", "::", "quoteStrings", "(", "$", "array", ")", ";", "$", "isMultiDimensional", "=", "self", "::", "isMultiDimensional", "(", "$", "arrayPrepared", ")", ";", "/*\n * Name of the variable was not provided and it's a multi dimensional array?\n * Let's create the name, because variable is required for later usage (related to multi dimensional array)\n */", "if", "(", "empty", "(", "$", "jsVariableName", ")", "&&", "$", "isMultiDimensional", ")", "{", "$", "jsVariableName", "=", "'autoGeneratedVariable'", ";", "}", "if", "(", "!", "empty", "(", "$", "jsVariableName", ")", "&&", "is_string", "(", "$", "jsVariableName", ")", ")", "{", "$", "result", ".=", "sprintf", "(", "'var %s = '", ",", "$", "jsVariableName", ")", ";", "}", "$", "result", ".=", "'new Array('", ";", "if", "(", "$", "preserveIndexes", "||", "$", "isMultiDimensional", ")", "{", "$", "result", ".=", "$", "arrayCount", ";", "$", "result", ".=", "');'", ";", "}", "foreach", "(", "$", "arrayPrepared", "as", "$", "index", "=>", "$", "value", ")", "{", "++", "$", "counter", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "variable", "=", "$", "index", ";", "if", "(", "is_int", "(", "$", "index", ")", ")", "{", "$", "variable", "=", "'value_'", ".", "$", "variable", ";", "}", "$", "value", "=", "self", "::", "array2JavaScript", "(", "$", "value", ",", "$", "variable", ",", "$", "preserveIndexes", ")", ";", "if", "(", "null", "!==", "$", "value", "&&", "''", "!==", "$", "value", ")", "{", "/*\n * Add an empty line for the 1st iteration only. Required to avoid missing empty line after\n * declaration of variable:\n *\n * var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);\n * autoGeneratedVariable[1] = new Array(...);\n */", "if", "(", "1", "===", "$", "counter", ")", "{", "$", "result", ".=", "\"\\n\"", ";", "}", "$", "result", ".=", "$", "value", ".", "\"\\n\"", ";", "$", "result", ".=", "sprintf", "(", "'%s[%s] = %s;'", ",", "$", "jsVariableName", ",", "Miscellaneous", "::", "quoteValue", "(", "$", "index", ")", ",", "$", "variable", ")", ";", "if", "(", "$", "counter", "!==", "$", "arrayCount", ")", "{", "$", "result", ".=", "\"\\n\"", ";", "}", "}", "}", "elseif", "(", "$", "preserveIndexes", ")", "{", "if", "(", "!", "empty", "(", "$", "jsVariableName", ")", ")", "{", "$", "index", "=", "Miscellaneous", "::", "quoteValue", "(", "$", "index", ")", ";", "$", "result", ".=", "sprintf", "(", "\"\\n%s[%s] = %s;\"", ",", "$", "jsVariableName", ",", "$", "index", ",", "$", "value", ")", ";", "}", "}", "else", "{", "$", "format", "=", "'%s'", ";", "if", "(", "$", "counter", "<", "$", "arrayCount", ")", "{", "$", "format", ".=", "', '", ";", "}", "$", "result", ".=", "sprintf", "(", "$", "format", ",", "$", "value", ")", ";", "}", "}", "if", "(", "!", "$", "preserveIndexes", "&&", "!", "$", "isMultiDimensional", ")", "{", "$", "result", ".=", "');'", ";", "}", "return", "$", "result", ";", "}" ]
Generates JavaScript code for given PHP array @param array $array The array that should be generated to JavaScript @param string $jsVariableName (optional) Name of the variable that will be in generated JavaScript code @param bool $preserveIndexes (optional) If is set to true and $jsVariableName isn't empty, indexes also will be added to the JavaScript code. Otherwise not. @return null|string
[ "Generates", "JavaScript", "code", "for", "given", "PHP", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L384-L472
36,158
meritoo/common-library
src/Utilities/Arrays.php
Arrays.setKeysAsValues
public static function setKeysAsValues(array $array, $ignoreDuplicatedValues = true) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $replaced = []; foreach ($array as $key => $value) { /* * The value it's an array? * Let's replace keys with values in this array first */ if (is_array($value)) { $replaced[$key] = self::setKeysAsValues($value, $ignoreDuplicatedValues); continue; } // Duplicated values shouldn't be ignored and processed value is used as key already? // Let's use an array and that will contain all values (to avoid ignoring / overriding duplicated values) if (!$ignoreDuplicatedValues && isset($replaced[$value])) { $existing = self::makeArray($replaced[$value]); $replaced[$value] = array_merge($existing, [ $key, ]); continue; } // Standard behaviour $replaced[$value] = $key; } return $replaced; }
php
public static function setKeysAsValues(array $array, $ignoreDuplicatedValues = true) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $replaced = []; foreach ($array as $key => $value) { /* * The value it's an array? * Let's replace keys with values in this array first */ if (is_array($value)) { $replaced[$key] = self::setKeysAsValues($value, $ignoreDuplicatedValues); continue; } // Duplicated values shouldn't be ignored and processed value is used as key already? // Let's use an array and that will contain all values (to avoid ignoring / overriding duplicated values) if (!$ignoreDuplicatedValues && isset($replaced[$value])) { $existing = self::makeArray($replaced[$value]); $replaced[$value] = array_merge($existing, [ $key, ]); continue; } // Standard behaviour $replaced[$value] = $key; } return $replaced; }
[ "public", "static", "function", "setKeysAsValues", "(", "array", "$", "array", ",", "$", "ignoreDuplicatedValues", "=", "true", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "replaced", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "/*\n * The value it's an array?\n * Let's replace keys with values in this array first\n */", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "replaced", "[", "$", "key", "]", "=", "self", "::", "setKeysAsValues", "(", "$", "value", ",", "$", "ignoreDuplicatedValues", ")", ";", "continue", ";", "}", "// Duplicated values shouldn't be ignored and processed value is used as key already?", "// Let's use an array and that will contain all values (to avoid ignoring / overriding duplicated values)", "if", "(", "!", "$", "ignoreDuplicatedValues", "&&", "isset", "(", "$", "replaced", "[", "$", "value", "]", ")", ")", "{", "$", "existing", "=", "self", "::", "makeArray", "(", "$", "replaced", "[", "$", "value", "]", ")", ";", "$", "replaced", "[", "$", "value", "]", "=", "array_merge", "(", "$", "existing", ",", "[", "$", "key", ",", "]", ")", ";", "continue", ";", "}", "// Standard behaviour", "$", "replaced", "[", "$", "value", "]", "=", "$", "key", ";", "}", "return", "$", "replaced", ";", "}" ]
Sets keys as values and values as keys in given array. Replaces keys with values. @param array $array The array to change values with keys @param bool $ignoreDuplicatedValues (optional) If is set to true, duplicated values are ignored. This means that when there is more than 1 value and that values become key, only the last value will be used with it's key, because other will be overridden. Otherwise - values are preserved and keys assigned to that values are returned as an array. @return null|array Example of $ignoreDuplicatedValues = false: - provided array $array = [ 'lorem' => 100, // <-- Duplicated value 'ipsum' => 200, 'dolor' => 100, // <-- Duplicated value ]; - result $replaced = [ 100 => [ 'lorem', // <-- Key of duplicated value 'dolor', // <-- Key of duplicated value ], 200 => 'ipsum', ];
[ "Sets", "keys", "as", "values", "and", "values", "as", "keys", "in", "given", "array", ".", "Replaces", "keys", "with", "values", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L656-L696
36,159
meritoo/common-library
src/Utilities/Arrays.php
Arrays.string2array
public static function string2array($string, $separator = '|', $valuesKeysSeparator = ':') { /* * Empty string? * Nothing to do */ if (empty($string)) { return null; } $array = []; $exploded = explode($separator, $string); foreach ($exploded as $item) { $exploded2 = explode($valuesKeysSeparator, $item); if (2 === count($exploded2)) { $key = trim($exploded2[0]); $value = trim($exploded2[1]); $array[$key] = $value; } } return $array; }
php
public static function string2array($string, $separator = '|', $valuesKeysSeparator = ':') { /* * Empty string? * Nothing to do */ if (empty($string)) { return null; } $array = []; $exploded = explode($separator, $string); foreach ($exploded as $item) { $exploded2 = explode($valuesKeysSeparator, $item); if (2 === count($exploded2)) { $key = trim($exploded2[0]); $value = trim($exploded2[1]); $array[$key] = $value; } } return $array; }
[ "public", "static", "function", "string2array", "(", "$", "string", ",", "$", "separator", "=", "'|'", ",", "$", "valuesKeysSeparator", "=", "':'", ")", "{", "/*\n * Empty string?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "string", ")", ")", "{", "return", "null", ";", "}", "$", "array", "=", "[", "]", ";", "$", "exploded", "=", "explode", "(", "$", "separator", ",", "$", "string", ")", ";", "foreach", "(", "$", "exploded", "as", "$", "item", ")", "{", "$", "exploded2", "=", "explode", "(", "$", "valuesKeysSeparator", ",", "$", "item", ")", ";", "if", "(", "2", "===", "count", "(", "$", "exploded2", ")", ")", "{", "$", "key", "=", "trim", "(", "$", "exploded2", "[", "0", "]", ")", ";", "$", "value", "=", "trim", "(", "$", "exploded2", "[", "1", "]", ")", ";", "$", "array", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "array", ";", "}" ]
Converts given string with special separators to array Example: ~ string: "light:jasny|dark:ciemny" ~ array as a result: [ 'light' => 'jasny', 'dark' => 'ciemny', ] @param string $string The string to be converted @param string $separator (optional) Separator used between name-value pairs in the string. Default: "|". @param string $valuesKeysSeparator (optional) Separator used between name and value in the string. Default: ":". @return array
[ "Converts", "given", "string", "with", "special", "separators", "to", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L777-L802
36,160
meritoo/common-library
src/Utilities/Arrays.php
Arrays.areKeysInArray
public static function areKeysInArray(array $keys, array $array, $explicit = true) { $result = false; if (!empty($array)) { $firstKey = true; foreach ($keys as $key) { $exists = array_key_exists($key, $array); if ($firstKey) { $result = $exists; $firstKey = false; } elseif ($explicit) { $result = $result && $exists; if (!$result) { break; } } else { $result = $result || $exists; if ($result) { break; } } } } return $result; }
php
public static function areKeysInArray(array $keys, array $array, $explicit = true) { $result = false; if (!empty($array)) { $firstKey = true; foreach ($keys as $key) { $exists = array_key_exists($key, $array); if ($firstKey) { $result = $exists; $firstKey = false; } elseif ($explicit) { $result = $result && $exists; if (!$result) { break; } } else { $result = $result || $exists; if ($result) { break; } } } } return $result; }
[ "public", "static", "function", "areKeysInArray", "(", "array", "$", "keys", ",", "array", "$", "array", ",", "$", "explicit", "=", "true", ")", "{", "$", "result", "=", "false", ";", "if", "(", "!", "empty", "(", "$", "array", ")", ")", "{", "$", "firstKey", "=", "true", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "exists", "=", "array_key_exists", "(", "$", "key", ",", "$", "array", ")", ";", "if", "(", "$", "firstKey", ")", "{", "$", "result", "=", "$", "exists", ";", "$", "firstKey", "=", "false", ";", "}", "elseif", "(", "$", "explicit", ")", "{", "$", "result", "=", "$", "result", "&&", "$", "exists", ";", "if", "(", "!", "$", "result", ")", "{", "break", ";", "}", "}", "else", "{", "$", "result", "=", "$", "result", "||", "$", "exists", ";", "if", "(", "$", "result", ")", "{", "break", ";", "}", "}", "}", "}", "return", "$", "result", ";", "}" ]
Returns information if given keys exist in given array @param array $keys The keys to find @param array $array The array that maybe contains keys @param bool $explicit (optional) If is set to true, all keys should exist in given array. Otherwise - not all. @return bool
[ "Returns", "information", "if", "given", "keys", "exist", "in", "given", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L812-L842
36,161
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getLastElementsPaths
public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '') { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } if (!empty($stopIfMatchedBy)) { $stopIfMatchedBy = self::makeArray($stopIfMatchedBy); } $paths = []; foreach ($array as $key => $value) { $path = $key; $stopRecursion = false; $valueIsArray = is_array($value); /* * If the path of parent element is delivered, * I have to use it and build longer path */ if (!empty($parentPath)) { $pathTemplate = '%s%s%s'; $path = sprintf($pathTemplate, $parentPath, $separator, $key); } /* * Check if the key or current path matches one of patterns at which the process should be stopped, * the recursive not used. It means that I have to pass current value and stop processing of the * array (don't go to the next step). */ if (!empty($stopIfMatchedBy)) { foreach ($stopIfMatchedBy as $rawPattern) { $pattern = sprintf('|%s|', $rawPattern); if (preg_match($pattern, $key) || preg_match($pattern, $path)) { $stopRecursion = true; break; } } } /* * The value is passed to the returned array if: * - it's not an array * or * - the process is stopped, recursive is not used */ if (!$valueIsArray || ($valueIsArray && empty($value)) || $stopRecursion) { $paths[$path] = $value; continue; } // Let's iterate through the next level, using recursive if ($valueIsArray) { $recursivePaths = self::getLastElementsPaths($value, $separator, $path, $stopIfMatchedBy); $paths += $recursivePaths; } } return $paths; }
php
public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '') { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } if (!empty($stopIfMatchedBy)) { $stopIfMatchedBy = self::makeArray($stopIfMatchedBy); } $paths = []; foreach ($array as $key => $value) { $path = $key; $stopRecursion = false; $valueIsArray = is_array($value); /* * If the path of parent element is delivered, * I have to use it and build longer path */ if (!empty($parentPath)) { $pathTemplate = '%s%s%s'; $path = sprintf($pathTemplate, $parentPath, $separator, $key); } /* * Check if the key or current path matches one of patterns at which the process should be stopped, * the recursive not used. It means that I have to pass current value and stop processing of the * array (don't go to the next step). */ if (!empty($stopIfMatchedBy)) { foreach ($stopIfMatchedBy as $rawPattern) { $pattern = sprintf('|%s|', $rawPattern); if (preg_match($pattern, $key) || preg_match($pattern, $path)) { $stopRecursion = true; break; } } } /* * The value is passed to the returned array if: * - it's not an array * or * - the process is stopped, recursive is not used */ if (!$valueIsArray || ($valueIsArray && empty($value)) || $stopRecursion) { $paths[$path] = $value; continue; } // Let's iterate through the next level, using recursive if ($valueIsArray) { $recursivePaths = self::getLastElementsPaths($value, $separator, $path, $stopIfMatchedBy); $paths += $recursivePaths; } } return $paths; }
[ "public", "static", "function", "getLastElementsPaths", "(", "array", "$", "array", ",", "$", "separator", "=", "'.'", ",", "$", "parentPath", "=", "''", ",", "$", "stopIfMatchedBy", "=", "''", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "stopIfMatchedBy", ")", ")", "{", "$", "stopIfMatchedBy", "=", "self", "::", "makeArray", "(", "$", "stopIfMatchedBy", ")", ";", "}", "$", "paths", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "path", "=", "$", "key", ";", "$", "stopRecursion", "=", "false", ";", "$", "valueIsArray", "=", "is_array", "(", "$", "value", ")", ";", "/*\n * If the path of parent element is delivered,\n * I have to use it and build longer path\n */", "if", "(", "!", "empty", "(", "$", "parentPath", ")", ")", "{", "$", "pathTemplate", "=", "'%s%s%s'", ";", "$", "path", "=", "sprintf", "(", "$", "pathTemplate", ",", "$", "parentPath", ",", "$", "separator", ",", "$", "key", ")", ";", "}", "/*\n * Check if the key or current path matches one of patterns at which the process should be stopped,\n * the recursive not used. It means that I have to pass current value and stop processing of the\n * array (don't go to the next step).\n */", "if", "(", "!", "empty", "(", "$", "stopIfMatchedBy", ")", ")", "{", "foreach", "(", "$", "stopIfMatchedBy", "as", "$", "rawPattern", ")", "{", "$", "pattern", "=", "sprintf", "(", "'|%s|'", ",", "$", "rawPattern", ")", ";", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "key", ")", "||", "preg_match", "(", "$", "pattern", ",", "$", "path", ")", ")", "{", "$", "stopRecursion", "=", "true", ";", "break", ";", "}", "}", "}", "/*\n * The value is passed to the returned array if:\n * - it's not an array\n * or\n * - the process is stopped, recursive is not used\n */", "if", "(", "!", "$", "valueIsArray", "||", "(", "$", "valueIsArray", "&&", "empty", "(", "$", "value", ")", ")", "||", "$", "stopRecursion", ")", "{", "$", "paths", "[", "$", "path", "]", "=", "$", "value", ";", "continue", ";", "}", "// Let's iterate through the next level, using recursive", "if", "(", "$", "valueIsArray", ")", "{", "$", "recursivePaths", "=", "self", "::", "getLastElementsPaths", "(", "$", "value", ",", "$", "separator", ",", "$", "path", ",", "$", "stopIfMatchedBy", ")", ";", "$", "paths", "+=", "$", "recursivePaths", ";", "}", "}", "return", "$", "paths", ";", "}" ]
Returns paths of the last elements @param array $array The array with elements @param string $separator (optional) Separator used between elements. Default: ".". @param string $parentPath (optional) Path of the parent element. Default: "". @param array|string $stopIfMatchedBy (optional) Patterns of keys or paths that matched will stop the process of path building and including children of those keys or paths (recursive will not be used for keys in lower level of given array). Default: "". @return null|array Examples - $stopIfMatchedBy argument: a) "\d+" b) [ "lorem\-", "\d+", ];
[ "Returns", "paths", "of", "the", "last", "elements" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L862-L929
36,162
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getValueByKeysPath
public static function getValueByKeysPath(array $array, array $keys) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $value = null; if (self::issetRecursive($array, $keys)) { foreach ($keys as $key) { $value = $array[$key]; array_shift($keys); if (is_array($value) && !empty($keys)) { $value = self::getValueByKeysPath($value, $keys); } break; } } return $value; }
php
public static function getValueByKeysPath(array $array, array $keys) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $value = null; if (self::issetRecursive($array, $keys)) { foreach ($keys as $key) { $value = $array[$key]; array_shift($keys); if (is_array($value) && !empty($keys)) { $value = self::getValueByKeysPath($value, $keys); } break; } } return $value; }
[ "public", "static", "function", "getValueByKeysPath", "(", "array", "$", "array", ",", "array", "$", "keys", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "value", "=", "null", ";", "if", "(", "self", "::", "issetRecursive", "(", "$", "array", ",", "$", "keys", ")", ")", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "value", "=", "$", "array", "[", "$", "key", "]", ";", "array_shift", "(", "$", "keys", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", "&&", "!", "empty", "(", "$", "keys", ")", ")", "{", "$", "value", "=", "self", "::", "getValueByKeysPath", "(", "$", "value", ",", "$", "keys", ")", ";", "}", "break", ";", "}", "}", "return", "$", "value", ";", "}" ]
Returns value of given array set under given path of keys, of course if the value exists. The keys should be delivered in the same order as used by source array. @param array $array The array which should contains a value @param array $keys Keys, path of keys, to find in given array @return mixed Examples: a) $array [ 'some key' => [ 'another some key' => [ 'yet another key' => 123, ], 'some different key' => 456, ] ] b) $keys [ 'some key', 'another some key', 'yet another key', ] Based on the above examples will return: 123
[ "Returns", "value", "of", "given", "array", "set", "under", "given", "path", "of", "keys", "of", "course", "if", "the", "value", "exists", ".", "The", "keys", "should", "be", "delivered", "in", "the", "same", "order", "as", "used", "by", "source", "array", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1043-L1069
36,163
meritoo/common-library
src/Utilities/Arrays.php
Arrays.issetRecursive
public static function issetRecursive(array $array, array $keys) { /* * No elements? * Nothing to do */ if (empty($array)) { return false; } $isset = false; foreach ($keys as $key) { $isset = isset($array[$key]); if ($isset) { $newArray = $array[$key]; array_shift($keys); if (is_array($newArray) && !empty($keys)) { $isset = self::issetRecursive($newArray, $keys); } } break; } return $isset; }
php
public static function issetRecursive(array $array, array $keys) { /* * No elements? * Nothing to do */ if (empty($array)) { return false; } $isset = false; foreach ($keys as $key) { $isset = isset($array[$key]); if ($isset) { $newArray = $array[$key]; array_shift($keys); if (is_array($newArray) && !empty($keys)) { $isset = self::issetRecursive($newArray, $keys); } } break; } return $isset; }
[ "public", "static", "function", "issetRecursive", "(", "array", "$", "array", ",", "array", "$", "keys", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "false", ";", "}", "$", "isset", "=", "false", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "isset", "=", "isset", "(", "$", "array", "[", "$", "key", "]", ")", ";", "if", "(", "$", "isset", ")", "{", "$", "newArray", "=", "$", "array", "[", "$", "key", "]", ";", "array_shift", "(", "$", "keys", ")", ";", "if", "(", "is_array", "(", "$", "newArray", ")", "&&", "!", "empty", "(", "$", "keys", ")", ")", "{", "$", "isset", "=", "self", "::", "issetRecursive", "(", "$", "newArray", ",", "$", "keys", ")", ";", "}", "}", "break", ";", "}", "return", "$", "isset", ";", "}" ]
Returns information if given path of keys are set is given array. The keys should be delivered in the same order as used by source array. @param array $array The array to check @param array $keys Keys, path of keys, to find in given array @return bool Examples: a) $array [ 'some key' => [ 'another some key' => [ 'yet another key' => 123, ], 'some different key' => 456, ] ] b) $keys [ 'some key', 'another some key', 'yet another key', ]
[ "Returns", "information", "if", "given", "path", "of", "keys", "are", "set", "is", "given", "array", ".", "The", "keys", "should", "be", "delivered", "in", "the", "same", "order", "as", "used", "by", "source", "array", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1097-L1125
36,164
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getAllValuesOfKey
public static function getAllValuesOfKey(array $array, $key) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $values = []; foreach ($array as $index => $value) { if ($index === $key) { $values[] = $value; continue; } if (is_array($value)) { $recursiveValues = self::getAllValuesOfKey($value, $key); if (!empty($recursiveValues)) { $merged = array_merge($values, $recursiveValues); $values = $merged; } } } return $values; }
php
public static function getAllValuesOfKey(array $array, $key) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $values = []; foreach ($array as $index => $value) { if ($index === $key) { $values[] = $value; continue; } if (is_array($value)) { $recursiveValues = self::getAllValuesOfKey($value, $key); if (!empty($recursiveValues)) { $merged = array_merge($values, $recursiveValues); $values = $merged; } } } return $values; }
[ "public", "static", "function", "getAllValuesOfKey", "(", "array", "$", "array", ",", "$", "key", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "index", "=>", "$", "value", ")", "{", "if", "(", "$", "index", "===", "$", "key", ")", "{", "$", "values", "[", "]", "=", "$", "value", ";", "continue", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "recursiveValues", "=", "self", "::", "getAllValuesOfKey", "(", "$", "value", ",", "$", "key", ")", ";", "if", "(", "!", "empty", "(", "$", "recursiveValues", ")", ")", "{", "$", "merged", "=", "array_merge", "(", "$", "values", ",", "$", "recursiveValues", ")", ";", "$", "values", "=", "$", "merged", ";", "}", "}", "}", "return", "$", "values", ";", "}" ]
Returns all values of given key. It may be useful when you want to retrieve all values of one column. @param array $array The array which should contain values of the key @param string $key The key @return null|array
[ "Returns", "all", "values", "of", "given", "key", ".", "It", "may", "be", "useful", "when", "you", "want", "to", "retrieve", "all", "values", "of", "one", "column", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1135-L1165
36,165
meritoo/common-library
src/Utilities/Arrays.php
Arrays.trimRecursive
public static function trimRecursive(array $array) { /* * No elements? * Nothing to do */ if (empty($array)) { return []; } $result = []; foreach ($array as $key => $value) { if (is_array($value)) { $result[$key] = self::trimRecursive($value); continue; } if (is_string($value)) { $value = trim($value); } $result[$key] = $value; } return $result; }
php
public static function trimRecursive(array $array) { /* * No elements? * Nothing to do */ if (empty($array)) { return []; } $result = []; foreach ($array as $key => $value) { if (is_array($value)) { $result[$key] = self::trimRecursive($value); continue; } if (is_string($value)) { $value = trim($value); } $result[$key] = $value; } return $result; }
[ "public", "static", "function", "trimRecursive", "(", "array", "$", "array", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "result", "[", "$", "key", "]", "=", "self", "::", "trimRecursive", "(", "$", "value", ")", ";", "continue", ";", "}", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "}", "$", "result", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Trims string values of given array and returns the new array @param array $array The array which values should be trimmed @return array
[ "Trims", "string", "values", "of", "given", "array", "and", "returns", "the", "new", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1211-L1238
36,166
meritoo/common-library
src/Utilities/Arrays.php
Arrays.sortByCustomKeysOrder
public static function sortByCustomKeysOrder(array $array, array $keysOrder) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $ordered = []; /* * 1st iteration: * Get elements in proper / required order */ if (!empty($keysOrder)) { foreach ($keysOrder as $key) { if (isset($array[$key])) { $ordered[$key] = $array[$key]; unset($array[$key]); } } } /* * 2nd iteration: * Get the rest of elements */ if (!empty($array)) { foreach ($array as $key => $element) { $ordered[$key] = $element; } } return $ordered; }
php
public static function sortByCustomKeysOrder(array $array, array $keysOrder) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } $ordered = []; /* * 1st iteration: * Get elements in proper / required order */ if (!empty($keysOrder)) { foreach ($keysOrder as $key) { if (isset($array[$key])) { $ordered[$key] = $array[$key]; unset($array[$key]); } } } /* * 2nd iteration: * Get the rest of elements */ if (!empty($array)) { foreach ($array as $key => $element) { $ordered[$key] = $element; } } return $ordered; }
[ "public", "static", "function", "sortByCustomKeysOrder", "(", "array", "$", "array", ",", "array", "$", "keysOrder", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "$", "ordered", "=", "[", "]", ";", "/*\n * 1st iteration:\n * Get elements in proper / required order\n */", "if", "(", "!", "empty", "(", "$", "keysOrder", ")", ")", "{", "foreach", "(", "$", "keysOrder", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "array", "[", "$", "key", "]", ")", ")", "{", "$", "ordered", "[", "$", "key", "]", "=", "$", "array", "[", "$", "key", "]", ";", "unset", "(", "$", "array", "[", "$", "key", "]", ")", ";", "}", "}", "}", "/*\n * 2nd iteration:\n * Get the rest of elements\n */", "if", "(", "!", "empty", "(", "$", "array", ")", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "element", ")", "{", "$", "ordered", "[", "$", "key", "]", "=", "$", "element", ";", "}", "}", "return", "$", "ordered", ";", "}" ]
Sorts an array by keys given in second array as values. Keys which are not in array with order are pushed after sorted elements. Example: - array to sort: <code> array( 'lorem' => array( 'ipsum' ), 'dolor' => array( 'sit', 'amet' ), 'neque' => 'neque' ) </code> - keys order: <code> array( 'dolor', 'lorem' ) </code> - the result: <code> array( 'dolor' => array( 'sit', 'amet' ), 'lorem' => array( 'ipsum' ), 'neque' => 'neque' // <-- the rest, values of other keys ) </code> @param array $array An array to sort @param array $keysOrder An array with keys of the 1st argument in proper / required order @return null|array
[ "Sorts", "an", "array", "by", "keys", "given", "in", "second", "array", "as", "values", ".", "Keys", "which", "are", "not", "in", "array", "with", "order", "are", "pushed", "after", "sorted", "elements", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1283-L1319
36,167
meritoo/common-library
src/Utilities/Arrays.php
Arrays.implodeSmart
public static function implodeSmart(array $array, $separator) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } foreach ($array as &$element) { if (is_array($element)) { $element = self::implodeSmart($element, $separator); } if (Regex::startsWith($element, $separator)) { $element = substr($element, 1); } if (Regex::endsWith($element, $separator)) { $element = substr($element, 0, -1); } } return implode($separator, $array); }
php
public static function implodeSmart(array $array, $separator) { /* * No elements? * Nothing to do */ if (empty($array)) { return null; } foreach ($array as &$element) { if (is_array($element)) { $element = self::implodeSmart($element, $separator); } if (Regex::startsWith($element, $separator)) { $element = substr($element, 1); } if (Regex::endsWith($element, $separator)) { $element = substr($element, 0, -1); } } return implode($separator, $array); }
[ "public", "static", "function", "implodeSmart", "(", "array", "$", "array", ",", "$", "separator", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "null", ";", "}", "foreach", "(", "$", "array", "as", "&", "$", "element", ")", "{", "if", "(", "is_array", "(", "$", "element", ")", ")", "{", "$", "element", "=", "self", "::", "implodeSmart", "(", "$", "element", ",", "$", "separator", ")", ";", "}", "if", "(", "Regex", "::", "startsWith", "(", "$", "element", ",", "$", "separator", ")", ")", "{", "$", "element", "=", "substr", "(", "$", "element", ",", "1", ")", ";", "}", "if", "(", "Regex", "::", "endsWith", "(", "$", "element", ",", "$", "separator", ")", ")", "{", "$", "element", "=", "substr", "(", "$", "element", ",", "0", ",", "-", "1", ")", ";", "}", "}", "return", "implode", "(", "$", "separator", ",", "$", "array", ")", ";", "}" ]
Returns smartly imploded string Separators located at the beginning or end of elements are removed. It's required to avoid problems with duplicated separator, e.g. "first//second/third", where separator is a "/" string. @param array $array The array with elements to implode @param string $separator Separator used to stick together elements of given array @return null|string
[ "Returns", "smartly", "imploded", "string" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1332-L1357
36,168
meritoo/common-library
src/Utilities/Arrays.php
Arrays.areAllValuesEmpty
public static function areAllValuesEmpty(array $array, $strictNull = false) { /* * No elements? * Nothing to do */ if (empty($array)) { return false; } foreach ($array as $element) { /* * If elements are verified if they are exactly null and the element is: * - not an array * - not null * or elements are NOT verified if they are exactly null and the element is: * - not empty (e.g. null, '', 0, array()) * * If one of the above is true, not all elements of given array are empty */ if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) { return false; } } return true; }
php
public static function areAllValuesEmpty(array $array, $strictNull = false) { /* * No elements? * Nothing to do */ if (empty($array)) { return false; } foreach ($array as $element) { /* * If elements are verified if they are exactly null and the element is: * - not an array * - not null * or elements are NOT verified if they are exactly null and the element is: * - not empty (e.g. null, '', 0, array()) * * If one of the above is true, not all elements of given array are empty */ if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) { return false; } } return true; }
[ "public", "static", "function", "areAllValuesEmpty", "(", "array", "$", "array", ",", "$", "strictNull", "=", "false", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "array", "as", "$", "element", ")", "{", "/*\n * If elements are verified if they are exactly null and the element is:\n * - not an array\n * - not null\n * or elements are NOT verified if they are exactly null and the element is:\n * - not empty (e.g. null, '', 0, array())\n *\n * If one of the above is true, not all elements of given array are empty\n */", "if", "(", "(", "!", "is_array", "(", "$", "element", ")", "&&", "$", "strictNull", "&&", "null", "!==", "$", "element", ")", "||", "!", "empty", "(", "$", "element", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Returns information if given array is empty, iow. information if all elements of given array are empty @param array $array The array to verify @param bool $strictNull (optional) If is set to true elements are verified if they are null. Otherwise - only if they are empty (e.g. null, '', 0, array()). @return bool
[ "Returns", "information", "if", "given", "array", "is", "empty", "iow", ".", "information", "if", "all", "elements", "of", "given", "array", "are", "empty" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1367-L1393
36,169
meritoo/common-library
src/Utilities/Arrays.php
Arrays.arrayDiffRecursive
public static function arrayDiffRecursive(array $array1, array $array2, $valuesOnly = false) { $effect = []; /* * Values should be compared only and both arrays are one-dimensional? * Let's find difference by using simple function */ if ($valuesOnly && 1 === self::getDimensionsCount($array1) && 1 === self::getDimensionsCount($array2)) { return array_diff($array1, $array2); } foreach ($array1 as $key => $value) { $array2HasKey = array_key_exists($key, $array2); // Values should be compared only? if ($valuesOnly) { $difference = null; if (is_array($value)) { if ($array2HasKey && is_array($array2[$key])) { $difference = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly); } } elseif (!$array2HasKey || ($array2HasKey && $value !== $array2[$key])) { /* * We are here, because: * a) 2nd array hasn't key from 1st array * OR * b) key exists in both, 1st and 2nd array, but values are different */ $difference = $value; } if (null !== $difference) { $effect[] = $difference; } // The key exists in 2nd array? } elseif ($array2HasKey) { // The value it's an array (it's a nested array)? if (is_array($value)) { $diff = []; if (is_array($array2[$key])) { // Let's verify the nested array $diff = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly); } if (empty($diff)) { continue; } $effect[$key] = $diff; } elseif ($value !== $array2[$key]) { // Value is different than in 2nd array? // OKay, I've got difference $effect[$key] = $value; } } else { // OKay, I've got difference $effect[$key] = $value; } } return $effect; }
php
public static function arrayDiffRecursive(array $array1, array $array2, $valuesOnly = false) { $effect = []; /* * Values should be compared only and both arrays are one-dimensional? * Let's find difference by using simple function */ if ($valuesOnly && 1 === self::getDimensionsCount($array1) && 1 === self::getDimensionsCount($array2)) { return array_diff($array1, $array2); } foreach ($array1 as $key => $value) { $array2HasKey = array_key_exists($key, $array2); // Values should be compared only? if ($valuesOnly) { $difference = null; if (is_array($value)) { if ($array2HasKey && is_array($array2[$key])) { $difference = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly); } } elseif (!$array2HasKey || ($array2HasKey && $value !== $array2[$key])) { /* * We are here, because: * a) 2nd array hasn't key from 1st array * OR * b) key exists in both, 1st and 2nd array, but values are different */ $difference = $value; } if (null !== $difference) { $effect[] = $difference; } // The key exists in 2nd array? } elseif ($array2HasKey) { // The value it's an array (it's a nested array)? if (is_array($value)) { $diff = []; if (is_array($array2[$key])) { // Let's verify the nested array $diff = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly); } if (empty($diff)) { continue; } $effect[$key] = $diff; } elseif ($value !== $array2[$key]) { // Value is different than in 2nd array? // OKay, I've got difference $effect[$key] = $value; } } else { // OKay, I've got difference $effect[$key] = $value; } } return $effect; }
[ "public", "static", "function", "arrayDiffRecursive", "(", "array", "$", "array1", ",", "array", "$", "array2", ",", "$", "valuesOnly", "=", "false", ")", "{", "$", "effect", "=", "[", "]", ";", "/*\n * Values should be compared only and both arrays are one-dimensional?\n * Let's find difference by using simple function\n */", "if", "(", "$", "valuesOnly", "&&", "1", "===", "self", "::", "getDimensionsCount", "(", "$", "array1", ")", "&&", "1", "===", "self", "::", "getDimensionsCount", "(", "$", "array2", ")", ")", "{", "return", "array_diff", "(", "$", "array1", ",", "$", "array2", ")", ";", "}", "foreach", "(", "$", "array1", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "array2HasKey", "=", "array_key_exists", "(", "$", "key", ",", "$", "array2", ")", ";", "// Values should be compared only?", "if", "(", "$", "valuesOnly", ")", "{", "$", "difference", "=", "null", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "$", "array2HasKey", "&&", "is_array", "(", "$", "array2", "[", "$", "key", "]", ")", ")", "{", "$", "difference", "=", "self", "::", "arrayDiffRecursive", "(", "$", "value", ",", "$", "array2", "[", "$", "key", "]", ",", "$", "valuesOnly", ")", ";", "}", "}", "elseif", "(", "!", "$", "array2HasKey", "||", "(", "$", "array2HasKey", "&&", "$", "value", "!==", "$", "array2", "[", "$", "key", "]", ")", ")", "{", "/*\n * We are here, because:\n * a) 2nd array hasn't key from 1st array\n * OR\n * b) key exists in both, 1st and 2nd array, but values are different\n */", "$", "difference", "=", "$", "value", ";", "}", "if", "(", "null", "!==", "$", "difference", ")", "{", "$", "effect", "[", "]", "=", "$", "difference", ";", "}", "// The key exists in 2nd array?", "}", "elseif", "(", "$", "array2HasKey", ")", "{", "// The value it's an array (it's a nested array)?", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "diff", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "array2", "[", "$", "key", "]", ")", ")", "{", "// Let's verify the nested array", "$", "diff", "=", "self", "::", "arrayDiffRecursive", "(", "$", "value", ",", "$", "array2", "[", "$", "key", "]", ",", "$", "valuesOnly", ")", ";", "}", "if", "(", "empty", "(", "$", "diff", ")", ")", "{", "continue", ";", "}", "$", "effect", "[", "$", "key", "]", "=", "$", "diff", ";", "}", "elseif", "(", "$", "value", "!==", "$", "array2", "[", "$", "key", "]", ")", "{", "// Value is different than in 2nd array?", "// OKay, I've got difference", "$", "effect", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "else", "{", "// OKay, I've got difference", "$", "effect", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "effect", ";", "}" ]
Returns an array containing all the entries from 1st array that are not present in 2nd array. An item from 1st array is the same as in 2nd array if both, keys and values, are the same. Example of difference: $array1 = [ 1 => 'Lorem', 2 => 'ipsum, ]; $array2 = [ 1 => 'Lorem', 5 => 'ipsum, // <-- The same values, but different key. Here we got 5, in 1st array - 2. ]; @param array $array1 The 1st array to verify @param array $array2 The 2nd array to verify @param bool $valuesOnly (optional) If is set to true, compares values only. Otherwise - keys and values (default behaviour). @return array
[ "Returns", "an", "array", "containing", "all", "the", "entries", "from", "1st", "array", "that", "are", "not", "present", "in", "2nd", "array", ".", "An", "item", "from", "1st", "array", "is", "the", "same", "as", "in", "2nd", "array", "if", "both", "keys", "and", "values", "are", "the", "same", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1416-L1481
36,170
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getDimensionsCount
public static function getDimensionsCount(array $array) { /* * No elements? * Nothing to do */ if (empty($array)) { return 0; } $dimensionsCount = 1; foreach ($array as $value) { if (is_array($value)) { /* * I have to increment returned value, because that means we've got 1 level more (if the value is an * array) */ $count = self::getDimensionsCount($value) + 1; if ($count > $dimensionsCount) { $dimensionsCount = $count; } } } return $dimensionsCount; }
php
public static function getDimensionsCount(array $array) { /* * No elements? * Nothing to do */ if (empty($array)) { return 0; } $dimensionsCount = 1; foreach ($array as $value) { if (is_array($value)) { /* * I have to increment returned value, because that means we've got 1 level more (if the value is an * array) */ $count = self::getDimensionsCount($value) + 1; if ($count > $dimensionsCount) { $dimensionsCount = $count; } } } return $dimensionsCount; }
[ "public", "static", "function", "getDimensionsCount", "(", "array", "$", "array", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "0", ";", "}", "$", "dimensionsCount", "=", "1", ";", "foreach", "(", "$", "array", "as", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "/*\n * I have to increment returned value, because that means we've got 1 level more (if the value is an\n * array)\n */", "$", "count", "=", "self", "::", "getDimensionsCount", "(", "$", "value", ")", "+", "1", ";", "if", "(", "$", "count", ">", "$", "dimensionsCount", ")", "{", "$", "dimensionsCount", "=", "$", "count", ";", "}", "}", "}", "return", "$", "dimensionsCount", ";", "}" ]
Returns count of dimensions, maximum nesting level actually, in given array @param array $array The array to verify @return int
[ "Returns", "count", "of", "dimensions", "maximum", "nesting", "level", "actually", "in", "given", "array" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1618-L1645
36,171
meritoo/common-library
src/Utilities/Arrays.php
Arrays.getNonEmptyValuesAsString
public static function getNonEmptyValuesAsString(array $values, $separator = ', ') { /* * No elements? * Nothing to do */ if (empty($values)) { return null; } $nonEmpty = self::getNonEmptyValues($values); /* * No values? * Nothing to do */ if (empty($nonEmpty)) { return ''; } return implode($separator, $nonEmpty); }
php
public static function getNonEmptyValuesAsString(array $values, $separator = ', ') { /* * No elements? * Nothing to do */ if (empty($values)) { return null; } $nonEmpty = self::getNonEmptyValues($values); /* * No values? * Nothing to do */ if (empty($nonEmpty)) { return ''; } return implode($separator, $nonEmpty); }
[ "public", "static", "function", "getNonEmptyValuesAsString", "(", "array", "$", "values", ",", "$", "separator", "=", "', '", ")", "{", "/*\n * No elements?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "return", "null", ";", "}", "$", "nonEmpty", "=", "self", "::", "getNonEmptyValues", "(", "$", "values", ")", ";", "/*\n * No values?\n * Nothing to do\n */", "if", "(", "empty", "(", "$", "nonEmpty", ")", ")", "{", "return", "''", ";", "}", "return", "implode", "(", "$", "separator", ",", "$", "nonEmpty", ")", ";", "}" ]
Returns non-empty values concatenated by given separator @param array $values The values to filter @param string $separator (optional) Separator used to implode the values. Default: ", ". @return null|string
[ "Returns", "non", "-", "empty", "values", "concatenated", "by", "given", "separator" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1678-L1699
36,172
CeusMedia/Common
src/Deprecation.php
Deprecation.message
public function message( $message ){ $trace = debug_backtrace(); $caller = next( $trace ); $message .= ', invoked in '.$caller['file'].' on line '.$caller['line']; if( $this->exceptionVersion ) if( version_compare( $this->version, $this->exceptionVersion ) >= 0 ) throw new Exception( 'Deprecated: '.$message ); if( version_compare( $this->version, $this->errorVersion ) >= 0 ){ self::notify( $message ); } }
php
public function message( $message ){ $trace = debug_backtrace(); $caller = next( $trace ); $message .= ', invoked in '.$caller['file'].' on line '.$caller['line']; if( $this->exceptionVersion ) if( version_compare( $this->version, $this->exceptionVersion ) >= 0 ) throw new Exception( 'Deprecated: '.$message ); if( version_compare( $this->version, $this->errorVersion ) >= 0 ){ self::notify( $message ); } }
[ "public", "function", "message", "(", "$", "message", ")", "{", "$", "trace", "=", "debug_backtrace", "(", ")", ";", "$", "caller", "=", "next", "(", "$", "trace", ")", ";", "$", "message", ".=", "', invoked in '", ".", "$", "caller", "[", "'file'", "]", ".", "' on line '", ".", "$", "caller", "[", "'line'", "]", ";", "if", "(", "$", "this", "->", "exceptionVersion", ")", "if", "(", "version_compare", "(", "$", "this", "->", "version", ",", "$", "this", "->", "exceptionVersion", ")", ">=", "0", ")", "throw", "new", "Exception", "(", "'Deprecated: '", ".", "$", "message", ")", ";", "if", "(", "version_compare", "(", "$", "this", "->", "version", ",", "$", "this", "->", "errorVersion", ")", ">=", "0", ")", "{", "self", "::", "notify", "(", "$", "message", ")", ";", "}", "}" ]
Show message as exception or deprecation error, depending on set versions and PHP version. Will throw an exception if set exception version reached detected library version. Will throw a deprecation error if set error version reached detected library version using PHP 5.3+. Will throw a deprecation notice if set error version reached detected library version using PHP lower 5.3. @access public @param string $version Library version to start showing deprecation error or notice @return void @throws Exception if set exception version reached detected library version
[ "Show", "message", "as", "exception", "or", "deprecation", "error", "depending", "on", "set", "versions", "and", "PHP", "version", ".", "Will", "throw", "an", "exception", "if", "set", "exception", "version", "reached", "detected", "library", "version", ".", "Will", "throw", "a", "deprecation", "error", "if", "set", "error", "version", "reached", "detected", "library", "version", "using", "PHP", "5", ".", "3", "+", ".", "Will", "throw", "a", "deprecation", "notice", "if", "set", "error", "version", "reached", "detected", "library", "version", "using", "PHP", "lower", "5", ".", "3", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Deprecation.php#L68-L78
36,173
CeusMedia/Common
src/XML/DOM/GoogleSitemapBuilder.php
XML_DOM_GoogleSitemapBuilder.buildSitemap
public static function buildSitemap( $links, $baseUrl = "" ) { $root = new XML_DOM_Node( "urlset" ); $root->setAttribute( 'xmlns', "http://www.google.com/schemas/sitemap/0.84" ); foreach( $links as $link ) { $child = new XML_DOM_Node( "url" ); $loc = new XML_DOM_Node( "loc", $baseUrl.$link ); $child->addChild( $loc ); $root->addChild( $child ); } $builder = new XML_DOM_Builder(); return $builder->build( $root ); }
php
public static function buildSitemap( $links, $baseUrl = "" ) { $root = new XML_DOM_Node( "urlset" ); $root->setAttribute( 'xmlns', "http://www.google.com/schemas/sitemap/0.84" ); foreach( $links as $link ) { $child = new XML_DOM_Node( "url" ); $loc = new XML_DOM_Node( "loc", $baseUrl.$link ); $child->addChild( $loc ); $root->addChild( $child ); } $builder = new XML_DOM_Builder(); return $builder->build( $root ); }
[ "public", "static", "function", "buildSitemap", "(", "$", "links", ",", "$", "baseUrl", "=", "\"\"", ")", "{", "$", "root", "=", "new", "XML_DOM_Node", "(", "\"urlset\"", ")", ";", "$", "root", "->", "setAttribute", "(", "'xmlns'", ",", "\"http://www.google.com/schemas/sitemap/0.84\"", ")", ";", "foreach", "(", "$", "links", "as", "$", "link", ")", "{", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"url\"", ")", ";", "$", "loc", "=", "new", "XML_DOM_Node", "(", "\"loc\"", ",", "$", "baseUrl", ".", "$", "link", ")", ";", "$", "child", "->", "addChild", "(", "$", "loc", ")", ";", "$", "root", "->", "addChild", "(", "$", "child", ")", ";", "}", "$", "builder", "=", "new", "XML_DOM_Builder", "(", ")", ";", "return", "$", "builder", "->", "build", "(", "$", "root", ")", ";", "}" ]
Builds and return XML of Sitemap. @access public @static @param string $links List of Sitemap Link @param string $baseUrl Basic URL to add to every Link @return bool
[ "Builds", "and", "return", "XML", "of", "Sitemap", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/GoogleSitemapBuilder.php#L77-L90
36,174
CeusMedia/Common
src/FS/File/CSS/Theme/Finder.php
FS_File_CSS_Theme_Finder.getThemes
public function getThemes( $withBrowsers = FALSE ) { $list = array(); $dir = new DirectoryIterator( $this->themePath ); foreach( $dir as $entry ) { if( !$entry->isDir() ) continue; if( substr( $entry->getFilename(), 0, 1 ) == "." ) continue; $themeName = $entry->getFilename(); if( $withBrowsers ) { $cssPath = $this->themePath.$entry->getFilename()."/".$this->cssPath; $subdir = new DirectoryIterator( $cssPath ); foreach( $subdir as $browser ) { if( !$browser->isDir() ) continue; if( substr( $browser->getFilename(), 0, 1 ) == "." ) continue; $browserName = $browser->getFilename(); $list[$themeName][$themeName.":".$browserName] = $browserName; } } else $list[] = $themeName; } return $list; }
php
public function getThemes( $withBrowsers = FALSE ) { $list = array(); $dir = new DirectoryIterator( $this->themePath ); foreach( $dir as $entry ) { if( !$entry->isDir() ) continue; if( substr( $entry->getFilename(), 0, 1 ) == "." ) continue; $themeName = $entry->getFilename(); if( $withBrowsers ) { $cssPath = $this->themePath.$entry->getFilename()."/".$this->cssPath; $subdir = new DirectoryIterator( $cssPath ); foreach( $subdir as $browser ) { if( !$browser->isDir() ) continue; if( substr( $browser->getFilename(), 0, 1 ) == "." ) continue; $browserName = $browser->getFilename(); $list[$themeName][$themeName.":".$browserName] = $browserName; } } else $list[] = $themeName; } return $list; }
[ "public", "function", "getThemes", "(", "$", "withBrowsers", "=", "FALSE", ")", "{", "$", "list", "=", "array", "(", ")", ";", "$", "dir", "=", "new", "DirectoryIterator", "(", "$", "this", "->", "themePath", ")", ";", "foreach", "(", "$", "dir", "as", "$", "entry", ")", "{", "if", "(", "!", "$", "entry", "->", "isDir", "(", ")", ")", "continue", ";", "if", "(", "substr", "(", "$", "entry", "->", "getFilename", "(", ")", ",", "0", ",", "1", ")", "==", "\".\"", ")", "continue", ";", "$", "themeName", "=", "$", "entry", "->", "getFilename", "(", ")", ";", "if", "(", "$", "withBrowsers", ")", "{", "$", "cssPath", "=", "$", "this", "->", "themePath", ".", "$", "entry", "->", "getFilename", "(", ")", ".", "\"/\"", ".", "$", "this", "->", "cssPath", ";", "$", "subdir", "=", "new", "DirectoryIterator", "(", "$", "cssPath", ")", ";", "foreach", "(", "$", "subdir", "as", "$", "browser", ")", "{", "if", "(", "!", "$", "browser", "->", "isDir", "(", ")", ")", "continue", ";", "if", "(", "substr", "(", "$", "browser", "->", "getFilename", "(", ")", ",", "0", ",", "1", ")", "==", "\".\"", ")", "continue", ";", "$", "browserName", "=", "$", "browser", "->", "getFilename", "(", ")", ";", "$", "list", "[", "$", "themeName", "]", "[", "$", "themeName", ".", "\":\"", ".", "$", "browserName", "]", "=", "$", "browserName", ";", "}", "}", "else", "$", "list", "[", "]", "=", "$", "themeName", ";", "}", "return", "$", "list", ";", "}" ]
Returns found Themes as List. @access public @param bool $withBrowsers Flag: Stylesheets with Browser Folders @return array
[ "Returns", "found", "Themes", "as", "List", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Theme/Finder.php#L59-L88
36,175
CeusMedia/Common
src/Alg/Math/Analysis/Progression.php
Alg_Math_Analysis_Progression.getPartialSum
public function getPartialSum( $from, $to ) { for( $i=$from; $i<=$to; $i++ ) $sum += $this->getValue( $i ); return $sum; }
php
public function getPartialSum( $from, $to ) { for( $i=$from; $i<=$to; $i++ ) $sum += $this->getValue( $i ); return $sum; }
[ "public", "function", "getPartialSum", "(", "$", "from", ",", "$", "to", ")", "{", "for", "(", "$", "i", "=", "$", "from", ";", "$", "i", "<=", "$", "to", ";", "$", "i", "++", ")", "$", "sum", "+=", "$", "this", "->", "getValue", "(", "$", "i", ")", ";", "return", "$", "sum", ";", "}" ]
Calculates partial Sum of Progression. @access public @param int $from Interval Start @param int $to Interval End @return double
[ "Calculates", "partial", "Sum", "of", "Progression", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L73-L78
36,176
CeusMedia/Common
src/Alg/Math/Analysis/Progression.php
Alg_Math_Analysis_Progression.isConvergent
public function isConvergent () { $is = true; for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ ) { $an = $this->getPartialSum( $this->interval->getStart(), $i ); $an1 = $this->getPartialSum( $this->interval->getStart(), $i+1 ); $diff = abs( $an1 - $an ); // echo "<br>an1: ".$an1." | an: ".$an." | diff: ".$diff; if (!$old_diff) $old_diff = $diff; else if( $diff >= $old_diff ) $is = false; } return $is; }
php
public function isConvergent () { $is = true; for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ ) { $an = $this->getPartialSum( $this->interval->getStart(), $i ); $an1 = $this->getPartialSum( $this->interval->getStart(), $i+1 ); $diff = abs( $an1 - $an ); // echo "<br>an1: ".$an1." | an: ".$an." | diff: ".$diff; if (!$old_diff) $old_diff = $diff; else if( $diff >= $old_diff ) $is = false; } return $is; }
[ "public", "function", "isConvergent", "(", ")", "{", "$", "is", "=", "true", ";", "for", "(", "$", "i", "=", "$", "this", "->", "interval", "->", "getStart", "(", ")", ";", "$", "i", "<", "$", "this", "->", "interval", "->", "getEnd", "(", ")", ";", "$", "i", "++", ")", "{", "$", "an", "=", "$", "this", "->", "getPartialSum", "(", "$", "this", "->", "interval", "->", "getStart", "(", ")", ",", "$", "i", ")", ";", "$", "an1", "=", "$", "this", "->", "getPartialSum", "(", "$", "this", "->", "interval", "->", "getStart", "(", ")", ",", "$", "i", "+", "1", ")", ";", "$", "diff", "=", "abs", "(", "$", "an1", "-", "$", "an", ")", ";", "//\t\t\techo \"<br>an1: \".$an1.\" | an: \".$an.\" | diff: \".$diff;\r", "if", "(", "!", "$", "old_diff", ")", "$", "old_diff", "=", "$", "diff", ";", "else", "if", "(", "$", "diff", ">=", "$", "old_diff", ")", "$", "is", "=", "false", ";", "}", "return", "$", "is", ";", "}" ]
Indicates whether this Progression is convergent. @access public @return bool @todo correct Function: harmonic progression is convergent which is WRONG
[ "Indicates", "whether", "this", "Progression", "is", "convergent", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L96-L110
36,177
CeusMedia/Common
src/Alg/Math/Analysis/Progression.php
Alg_Math_Analysis_Progression.toArray
public function toArray() { $array = array(); for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ ) { $value = $this->getPartialSum( $this->interval->getStart(), $i ); $array[$i] = $value; } return $array; }
php
public function toArray() { $array = array(); for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ ) { $value = $this->getPartialSum( $this->interval->getStart(), $i ); $array[$i] = $value; } return $array; }
[ "public", "function", "toArray", "(", ")", "{", "$", "array", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "$", "this", "->", "interval", "->", "getStart", "(", ")", ";", "$", "i", "<", "$", "this", "->", "interval", "->", "getEnd", "(", ")", ";", "$", "i", "++", ")", "{", "$", "value", "=", "$", "this", "->", "getPartialSum", "(", "$", "this", "->", "interval", "->", "getStart", "(", ")", ",", "$", "i", ")", ";", "$", "array", "[", "$", "i", "]", "=", "$", "value", ";", "}", "return", "$", "array", ";", "}" ]
Returns Sequence of Partial Sums as Array. @access public @return array
[ "Returns", "Sequence", "of", "Partial", "Sums", "as", "Array", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L128-L137
36,178
CeusMedia/Common
src/Alg/Math/Analysis/Progression.php
Alg_Math_Analysis_Progression.toTable
public function toTable() { $array = $this->toArray(); $code = "<table cellpadding=2 cellspacing=0 border=1>"; foreach( $array as $key => $value ) $code .= "<tr><td>".$key."</td><td>".round( $value,8 )."</td></tr>"; $code .= "</table>"; return $code; }
php
public function toTable() { $array = $this->toArray(); $code = "<table cellpadding=2 cellspacing=0 border=1>"; foreach( $array as $key => $value ) $code .= "<tr><td>".$key."</td><td>".round( $value,8 )."</td></tr>"; $code .= "</table>"; return $code; }
[ "public", "function", "toTable", "(", ")", "{", "$", "array", "=", "$", "this", "->", "toArray", "(", ")", ";", "$", "code", "=", "\"<table cellpadding=2 cellspacing=0 border=1>\"", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "$", "code", ".=", "\"<tr><td>\"", ".", "$", "key", ".", "\"</td><td>\"", ".", "round", "(", "$", "value", ",", "8", ")", ".", "\"</td></tr>\"", ";", "$", "code", ".=", "\"</table>\"", ";", "return", "$", "code", ";", "}" ]
Returns Sequence of Partial Sums as HTML Table. @access public @return array
[ "Returns", "Sequence", "of", "Partial", "Sums", "as", "HTML", "Table", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L144-L152
36,179
RhubarbPHP/Scaffold.TokenBasedRestApi
src/Model/ApiToken.php
ApiToken.validateToken
public static function validateToken($tokenString) { $tokens = ApiToken::find(new AndGroup( [ new Equals("Token", $tokenString), new GreaterThan("Expires", "now", true) ] )); if (count($tokens) != 1) { throw new TokenInvalidException(); } /** @var ApiToken $token */ $token = $tokens[0]; $settings = ApiSettings::singleton(); if ($settings->extendTokenExpirationOnUse) { $token->Expires = $settings->tokenExpiration; $token->save(); } return $token->AuthenticatedUser; }
php
public static function validateToken($tokenString) { $tokens = ApiToken::find(new AndGroup( [ new Equals("Token", $tokenString), new GreaterThan("Expires", "now", true) ] )); if (count($tokens) != 1) { throw new TokenInvalidException(); } /** @var ApiToken $token */ $token = $tokens[0]; $settings = ApiSettings::singleton(); if ($settings->extendTokenExpirationOnUse) { $token->Expires = $settings->tokenExpiration; $token->save(); } return $token->AuthenticatedUser; }
[ "public", "static", "function", "validateToken", "(", "$", "tokenString", ")", "{", "$", "tokens", "=", "ApiToken", "::", "find", "(", "new", "AndGroup", "(", "[", "new", "Equals", "(", "\"Token\"", ",", "$", "tokenString", ")", ",", "new", "GreaterThan", "(", "\"Expires\"", ",", "\"now\"", ",", "true", ")", "]", ")", ")", ";", "if", "(", "count", "(", "$", "tokens", ")", "!=", "1", ")", "{", "throw", "new", "TokenInvalidException", "(", ")", ";", "}", "/** @var ApiToken $token */", "$", "token", "=", "$", "tokens", "[", "0", "]", ";", "$", "settings", "=", "ApiSettings", "::", "singleton", "(", ")", ";", "if", "(", "$", "settings", "->", "extendTokenExpirationOnUse", ")", "{", "$", "token", "->", "Expires", "=", "$", "settings", "->", "tokenExpiration", ";", "$", "token", "->", "save", "(", ")", ";", "}", "return", "$", "token", "->", "AuthenticatedUser", ";", "}" ]
Validates a given token string is valid and returns the authenticated user model. @param $tokenString @return mixed @throws \Rhubarb\Scaffolds\TokenBasedRestApi\Exceptions\TokenInvalidException Thrown if the token is invalid.
[ "Validates", "a", "given", "token", "string", "is", "valid", "and", "returns", "the", "authenticated", "user", "model", "." ]
581deee0eb6a675afa82c55f792a67a7895fdda2
https://github.com/RhubarbPHP/Scaffold.TokenBasedRestApi/blob/581deee0eb6a675afa82c55f792a67a7895fdda2/src/Model/ApiToken.php#L68-L90
36,180
RhubarbPHP/Scaffold.TokenBasedRestApi
src/Model/ApiToken.php
ApiToken.retrieveOrCreateToken
public static function retrieveOrCreateToken(Model $user, $ipAddress) { try { $token = self::findFirst(new AndGroup([ new Equals("AuthenticatedUserID", $user->UniqueIdentifier), new Equals("IpAddress", $ipAddress), new GreaterThan("Expires", "now", true) ])); $token->Expires = ApiSettings::singleton()->tokenExpiration; $token->save(); } catch (RecordNotFoundException $ex) { $token = self::createToken($user, $ipAddress); } return $token; }
php
public static function retrieveOrCreateToken(Model $user, $ipAddress) { try { $token = self::findFirst(new AndGroup([ new Equals("AuthenticatedUserID", $user->UniqueIdentifier), new Equals("IpAddress", $ipAddress), new GreaterThan("Expires", "now", true) ])); $token->Expires = ApiSettings::singleton()->tokenExpiration; $token->save(); } catch (RecordNotFoundException $ex) { $token = self::createToken($user, $ipAddress); } return $token; }
[ "public", "static", "function", "retrieveOrCreateToken", "(", "Model", "$", "user", ",", "$", "ipAddress", ")", "{", "try", "{", "$", "token", "=", "self", "::", "findFirst", "(", "new", "AndGroup", "(", "[", "new", "Equals", "(", "\"AuthenticatedUserID\"", ",", "$", "user", "->", "UniqueIdentifier", ")", ",", "new", "Equals", "(", "\"IpAddress\"", ",", "$", "ipAddress", ")", ",", "new", "GreaterThan", "(", "\"Expires\"", ",", "\"now\"", ",", "true", ")", "]", ")", ")", ";", "$", "token", "->", "Expires", "=", "ApiSettings", "::", "singleton", "(", ")", "->", "tokenExpiration", ";", "$", "token", "->", "save", "(", ")", ";", "}", "catch", "(", "RecordNotFoundException", "$", "ex", ")", "{", "$", "token", "=", "self", "::", "createToken", "(", "$", "user", ",", "$", "ipAddress", ")", ";", "}", "return", "$", "token", ";", "}" ]
Looks up an existing valid token for the user at the specified IP address. If none is found, it creates a new one. @param Model $user @param string $ipAddress Usually the current HTTP requester's IP, retrieved from $_SERVER[REMOTE_ADDR] @return ApiToken
[ "Looks", "up", "an", "existing", "valid", "token", "for", "the", "user", "at", "the", "specified", "IP", "address", ".", "If", "none", "is", "found", "it", "creates", "a", "new", "one", "." ]
581deee0eb6a675afa82c55f792a67a7895fdda2
https://github.com/RhubarbPHP/Scaffold.TokenBasedRestApi/blob/581deee0eb6a675afa82c55f792a67a7895fdda2/src/Model/ApiToken.php#L113-L128
36,181
CeusMedia/Common
src/XML/DOM/FeedIdentifier.php
XML_DOM_FeedIdentifier.identifyFromFile
public function identifyFromFile( $fileName ) { $file = new FS_File_Reader( $fileName ); $xml = $file->readString(); return $this->identify( $xml ); }
php
public function identifyFromFile( $fileName ) { $file = new FS_File_Reader( $fileName ); $xml = $file->readString(); return $this->identify( $xml ); }
[ "public", "function", "identifyFromFile", "(", "$", "fileName", ")", "{", "$", "file", "=", "new", "FS_File_Reader", "(", "$", "fileName", ")", ";", "$", "xml", "=", "$", "file", "->", "readString", "(", ")", ";", "return", "$", "this", "->", "identify", "(", "$", "xml", ")", ";", "}" ]
Identifies Feed from a File. @access public @param string $fileName XML File of Feed @return string
[ "Identifies", "Feed", "from", "a", "File", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/FeedIdentifier.php#L88-L93
36,182
CeusMedia/Common
src/XML/DOM/FeedIdentifier.php
XML_DOM_FeedIdentifier.identifyFromTree
public function identifyFromTree( $tree ) { $this->type = ""; $this->version = ""; $nodename = strtolower( $tree->getNodeName() ); switch( $nodename ) { case 'feed': $type = "ATOM"; $version = $tree->getAttribute( 'version' ); break; case 'rss': $type = "RSS"; $version = $tree->getAttribute( 'version' ); break; case 'rdf:rdf': $type = "RSS"; $version = "1.0"; break; } if( $type && $version ) { $this->type = $type; $this->version = $version; return $type."/".$version; } return false; }
php
public function identifyFromTree( $tree ) { $this->type = ""; $this->version = ""; $nodename = strtolower( $tree->getNodeName() ); switch( $nodename ) { case 'feed': $type = "ATOM"; $version = $tree->getAttribute( 'version' ); break; case 'rss': $type = "RSS"; $version = $tree->getAttribute( 'version' ); break; case 'rdf:rdf': $type = "RSS"; $version = "1.0"; break; } if( $type && $version ) { $this->type = $type; $this->version = $version; return $type."/".$version; } return false; }
[ "public", "function", "identifyFromTree", "(", "$", "tree", ")", "{", "$", "this", "->", "type", "=", "\"\"", ";", "$", "this", "->", "version", "=", "\"\"", ";", "$", "nodename", "=", "strtolower", "(", "$", "tree", "->", "getNodeName", "(", ")", ")", ";", "switch", "(", "$", "nodename", ")", "{", "case", "'feed'", ":", "$", "type", "=", "\"ATOM\"", ";", "$", "version", "=", "$", "tree", "->", "getAttribute", "(", "'version'", ")", ";", "break", ";", "case", "'rss'", ":", "$", "type", "=", "\"RSS\"", ";", "$", "version", "=", "$", "tree", "->", "getAttribute", "(", "'version'", ")", ";", "break", ";", "case", "'rdf:rdf'", ":", "$", "type", "=", "\"RSS\"", ";", "$", "version", "=", "\"1.0\"", ";", "break", ";", "}", "if", "(", "$", "type", "&&", "$", "version", ")", "{", "$", "this", "->", "type", "=", "$", "type", ";", "$", "this", "->", "version", "=", "$", "version", ";", "return", "$", "type", ".", "\"/\"", ".", "$", "version", ";", "}", "return", "false", ";", "}" ]
Identifies Feed from XML Tree. @access public @param XML_DOM_Node $tree XML Tree of Feed @return string
[ "Identifies", "Feed", "from", "XML", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/FeedIdentifier.php#L101-L128
36,183
CeusMedia/Common
src/UI/Image/Rotator.php
UI_Image_Rotator.rotate
public function rotate( $angle, $type = NULL ) { if( !$this->sourceUri ) throw new RuntimeException( 'No source image set' ); # if( function_exists( 'imageantialias' ) ) # imageantialias( $this->target, TRUE ); $this->target = imagerotate( $this->source, $angle, 0 ); if( $this->targetUri ) return $this->saveImage( $type ); return TRUE; }
php
public function rotate( $angle, $type = NULL ) { if( !$this->sourceUri ) throw new RuntimeException( 'No source image set' ); # if( function_exists( 'imageantialias' ) ) # imageantialias( $this->target, TRUE ); $this->target = imagerotate( $this->source, $angle, 0 ); if( $this->targetUri ) return $this->saveImage( $type ); return TRUE; }
[ "public", "function", "rotate", "(", "$", "angle", ",", "$", "type", "=", "NULL", ")", "{", "if", "(", "!", "$", "this", "->", "sourceUri", ")", "throw", "new", "RuntimeException", "(", "'No source image set'", ")", ";", "#\t\tif( function_exists( 'imageantialias' ) )", "#\t\t\timageantialias( $this->target, TRUE );", "$", "this", "->", "target", "=", "imagerotate", "(", "$", "this", "->", "source", ",", "$", "angle", ",", "0", ")", ";", "if", "(", "$", "this", "->", "targetUri", ")", "return", "$", "this", "->", "saveImage", "(", "$", "type", ")", ";", "return", "TRUE", ";", "}" ]
Invertes Source Image. @access public @param int $angle Rotation angle in degrees @param int $type Output format type @return bool
[ "Invertes", "Source", "Image", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/Image/Rotator.php#L50-L62
36,184
CeusMedia/Common
src/UI/Image/Rotator.php
UI_Image_Rotator.rotateImage
public static function rotateImage( $imageUri, $angle, $quality = 100 ) { $modifier = new UI_Image_Rotator( $imageUri, $imageUri, $quality ); return $modifier->rotate( $angle ); }
php
public static function rotateImage( $imageUri, $angle, $quality = 100 ) { $modifier = new UI_Image_Rotator( $imageUri, $imageUri, $quality ); return $modifier->rotate( $angle ); }
[ "public", "static", "function", "rotateImage", "(", "$", "imageUri", ",", "$", "angle", ",", "$", "quality", "=", "100", ")", "{", "$", "modifier", "=", "new", "UI_Image_Rotator", "(", "$", "imageUri", ",", "$", "imageUri", ",", "$", "quality", ")", ";", "return", "$", "modifier", "->", "rotate", "(", "$", "angle", ")", ";", "}" ]
Rotates an Image statically. @access public @static @param string $imageUri URI of Image File @param int $angle Rotation angle in degrees @param int $quality JPEG Quality in percent
[ "Rotates", "an", "Image", "statically", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/Image/Rotator.php#L72-L76
36,185
CeusMedia/Common
src/FS/File/Log/Tracker/Reader.php
FS_File_Log_Tracker_Reader.callback
protected function callback( $matches ) { // print_m( $matches ); $data = array( 'timestamp' => $matches[1], 'datetime' => $matches[2], 'remote_addr' => $matches[3], 'request_uri' => $matches[4], 'referer_uri' => $matches[5], 'useragent' => $matches[6], ); return serialize( $data ); }
php
protected function callback( $matches ) { // print_m( $matches ); $data = array( 'timestamp' => $matches[1], 'datetime' => $matches[2], 'remote_addr' => $matches[3], 'request_uri' => $matches[4], 'referer_uri' => $matches[5], 'useragent' => $matches[6], ); return serialize( $data ); }
[ "protected", "function", "callback", "(", "$", "matches", ")", "{", "//\t\tprint_m( $matches );\r", "$", "data", "=", "array", "(", "'timestamp'", "=>", "$", "matches", "[", "1", "]", ",", "'datetime'", "=>", "$", "matches", "[", "2", "]", ",", "'remote_addr'", "=>", "$", "matches", "[", "3", "]", ",", "'request_uri'", "=>", "$", "matches", "[", "4", "]", ",", "'referer_uri'", "=>", "$", "matches", "[", "5", "]", ",", "'useragent'", "=>", "$", "matches", "[", "6", "]", ",", ")", ";", "return", "serialize", "(", "$", "data", ")", ";", "}" ]
Callback for Line Parser. @access protected @return string
[ "Callback", "for", "Line", "Parser", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Log/Tracker/Reader.php#L72-L84
36,186
CeusMedia/Common
src/FS/File/Log/Tracker/Reader.php
FS_File_Log_Tracker_Reader.getPagesPerVisitor
public function getPagesPerVisitor() { $remote_addrs = array(); $visitors = array(); $visitor = 0; foreach( $this->data as $entry ) { if( $entry['remote_addr'] != $this->skip ) { if( isset( $remote_addrs[$entry['remote_addr']] ) ) { if( $remote_addrs[$entry['remote_addr']] < $entry['timestamp'] - 30 * 60 ) { $visitor++; $visitors[$visitor] = 0; } $visitors[$visitor] ++; } else { $visitor++; $visitors[$visitor] = 1; $remote_addrs[$entry['remote_addr']] = $entry['timestamp']; } } } $total = 0; foreach( $visitors as $visitor => $pages ) $total += $pages; $pages = round( $total / count( $visitors ), 1 ); return $pages; }
php
public function getPagesPerVisitor() { $remote_addrs = array(); $visitors = array(); $visitor = 0; foreach( $this->data as $entry ) { if( $entry['remote_addr'] != $this->skip ) { if( isset( $remote_addrs[$entry['remote_addr']] ) ) { if( $remote_addrs[$entry['remote_addr']] < $entry['timestamp'] - 30 * 60 ) { $visitor++; $visitors[$visitor] = 0; } $visitors[$visitor] ++; } else { $visitor++; $visitors[$visitor] = 1; $remote_addrs[$entry['remote_addr']] = $entry['timestamp']; } } } $total = 0; foreach( $visitors as $visitor => $pages ) $total += $pages; $pages = round( $total / count( $visitors ), 1 ); return $pages; }
[ "public", "function", "getPagesPerVisitor", "(", ")", "{", "$", "remote_addrs", "=", "array", "(", ")", ";", "$", "visitors", "=", "array", "(", ")", ";", "$", "visitor", "=", "0", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "entry", ")", "{", "if", "(", "$", "entry", "[", "'remote_addr'", "]", "!=", "$", "this", "->", "skip", ")", "{", "if", "(", "isset", "(", "$", "remote_addrs", "[", "$", "entry", "[", "'remote_addr'", "]", "]", ")", ")", "{", "if", "(", "$", "remote_addrs", "[", "$", "entry", "[", "'remote_addr'", "]", "]", "<", "$", "entry", "[", "'timestamp'", "]", "-", "30", "*", "60", ")", "{", "$", "visitor", "++", ";", "$", "visitors", "[", "$", "visitor", "]", "=", "0", ";", "}", "$", "visitors", "[", "$", "visitor", "]", "++", ";", "}", "else", "{", "$", "visitor", "++", ";", "$", "visitors", "[", "$", "visitor", "]", "=", "1", ";", "$", "remote_addrs", "[", "$", "entry", "[", "'remote_addr'", "]", "]", "=", "$", "entry", "[", "'timestamp'", "]", ";", "}", "}", "}", "$", "total", "=", "0", ";", "foreach", "(", "$", "visitors", "as", "$", "visitor", "=>", "$", "pages", ")", "$", "total", "+=", "$", "pages", ";", "$", "pages", "=", "round", "(", "$", "total", "/", "count", "(", "$", "visitors", ")", ",", "1", ")", ";", "return", "$", "pages", ";", "}" ]
Calculates Page View Average of unique Visitors. @access public @return float
[ "Calculates", "Page", "View", "Average", "of", "unique", "Visitors", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Log/Tracker/Reader.php#L143-L174
36,187
CeusMedia/Common
src/FS/File/Log/Tracker/Reader.php
FS_File_Log_Tracker_Reader.getReferers
public function getReferers( $skip ) { $referers = array(); foreach( $this->data as $entry ) { if( $entry['remote_addr'] != $this->skip ) { if( $entry['referer_uri'] && !preg_match( "#.*".$skip.".*#si", $entry['referer_uri'] ) ) { if( isset( $referers[$entry['referer_uri']] ) ) $referers[$entry['referer_uri']] ++; else $referers[$entry['referer_uri']] = 1; } } } arsort( $referers ); foreach( $referers as $referer => $count ) $lines[] = "<tr><td>".$referer."</td><td>".$count."</td></tr>"; $lines = implode( "\n\t", $lines ); $content = "<table>".$lines."</table>"; return $content; }
php
public function getReferers( $skip ) { $referers = array(); foreach( $this->data as $entry ) { if( $entry['remote_addr'] != $this->skip ) { if( $entry['referer_uri'] && !preg_match( "#.*".$skip.".*#si", $entry['referer_uri'] ) ) { if( isset( $referers[$entry['referer_uri']] ) ) $referers[$entry['referer_uri']] ++; else $referers[$entry['referer_uri']] = 1; } } } arsort( $referers ); foreach( $referers as $referer => $count ) $lines[] = "<tr><td>".$referer."</td><td>".$count."</td></tr>"; $lines = implode( "\n\t", $lines ); $content = "<table>".$lines."</table>"; return $content; }
[ "public", "function", "getReferers", "(", "$", "skip", ")", "{", "$", "referers", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "data", "as", "$", "entry", ")", "{", "if", "(", "$", "entry", "[", "'remote_addr'", "]", "!=", "$", "this", "->", "skip", ")", "{", "if", "(", "$", "entry", "[", "'referer_uri'", "]", "&&", "!", "preg_match", "(", "\"#.*\"", ".", "$", "skip", ".", "\".*#si\"", ",", "$", "entry", "[", "'referer_uri'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "referers", "[", "$", "entry", "[", "'referer_uri'", "]", "]", ")", ")", "$", "referers", "[", "$", "entry", "[", "'referer_uri'", "]", "]", "++", ";", "else", "$", "referers", "[", "$", "entry", "[", "'referer_uri'", "]", "]", "=", "1", ";", "}", "}", "}", "arsort", "(", "$", "referers", ")", ";", "foreach", "(", "$", "referers", "as", "$", "referer", "=>", "$", "count", ")", "$", "lines", "[", "]", "=", "\"<tr><td>\"", ".", "$", "referer", ".", "\"</td><td>\"", ".", "$", "count", ".", "\"</td></tr>\"", ";", "$", "lines", "=", "implode", "(", "\"\\n\\t\"", ",", "$", "lines", ")", ";", "$", "content", "=", "\"<table>\"", ".", "$", "lines", ".", "\"</table>\"", ";", "return", "$", "content", ";", "}" ]
Returns Referers of unique Visitors. @access public @return array
[ "Returns", "Referers", "of", "unique", "Visitors", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Log/Tracker/Reader.php#L181-L203
36,188
CeusMedia/Common
src/XML/DOM/ObjectSerializer.php
XML_DOM_ObjectSerializer.serialize
public static function serialize( $object, $encoding = "utf-8" ) { $root = new XML_DOM_Node( "object" ); $root->setAttribute( 'class', get_class( $object ) ); $vars = get_object_vars( $object ); self::serializeVarsRec( $vars, $root ); $builder = new XML_DOM_Builder(); $serial = $builder->build( $root, $encoding ); return $serial; }
php
public static function serialize( $object, $encoding = "utf-8" ) { $root = new XML_DOM_Node( "object" ); $root->setAttribute( 'class', get_class( $object ) ); $vars = get_object_vars( $object ); self::serializeVarsRec( $vars, $root ); $builder = new XML_DOM_Builder(); $serial = $builder->build( $root, $encoding ); return $serial; }
[ "public", "static", "function", "serialize", "(", "$", "object", ",", "$", "encoding", "=", "\"utf-8\"", ")", "{", "$", "root", "=", "new", "XML_DOM_Node", "(", "\"object\"", ")", ";", "$", "root", "->", "setAttribute", "(", "'class'", ",", "get_class", "(", "$", "object", ")", ")", ";", "$", "vars", "=", "get_object_vars", "(", "$", "object", ")", ";", "self", "::", "serializeVarsRec", "(", "$", "vars", ",", "$", "root", ")", ";", "$", "builder", "=", "new", "XML_DOM_Builder", "(", ")", ";", "$", "serial", "=", "$", "builder", "->", "build", "(", "$", "root", ",", "$", "encoding", ")", ";", "return", "$", "serial", ";", "}" ]
Builds XML String from an Object. @access public @static @param mixed $object Object to serialize @param string $encoding Encoding Type @return string
[ "Builds", "XML", "String", "from", "an", "Object", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/ObjectSerializer.php#L52-L61
36,189
CeusMedia/Common
src/XML/DOM/ObjectSerializer.php
XML_DOM_ObjectSerializer.serializeVarsRec
protected static function serializeVarsRec( $array, &$node ) { foreach( $array as $key => $value) { switch( gettype( $value ) ) { case 'NULL': $child = new XML_DOM_Node( "null" ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'boolean': $child = new XML_DOM_Node( "boolean", (int) $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'string': $child = new XML_DOM_Node( "string", $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'integer': $child = new XML_DOM_Node( "integer", $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'double': $child = new XML_DOM_Node( "double", $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'array': $child = new XML_DOM_Node( "array" ); $child->setAttribute( "name", $key ); self::serializeVarsRec( $value, $child ); $node->addChild( $child ); break; case 'object': $child = new XML_DOM_Node( "object" ); $child->setAttribute( "name", $key ); $child->setAttribute( "class", get_class( $value ) ); $vars = get_object_vars( $value ); self::serializeVarsRec( $vars, $child ); $node->addChild( $child ); break; } } }
php
protected static function serializeVarsRec( $array, &$node ) { foreach( $array as $key => $value) { switch( gettype( $value ) ) { case 'NULL': $child = new XML_DOM_Node( "null" ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'boolean': $child = new XML_DOM_Node( "boolean", (int) $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'string': $child = new XML_DOM_Node( "string", $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'integer': $child = new XML_DOM_Node( "integer", $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'double': $child = new XML_DOM_Node( "double", $value ); $child->setAttribute( "name", $key ); $node->addChild( $child ); break; case 'array': $child = new XML_DOM_Node( "array" ); $child->setAttribute( "name", $key ); self::serializeVarsRec( $value, $child ); $node->addChild( $child ); break; case 'object': $child = new XML_DOM_Node( "object" ); $child->setAttribute( "name", $key ); $child->setAttribute( "class", get_class( $value ) ); $vars = get_object_vars( $value ); self::serializeVarsRec( $vars, $child ); $node->addChild( $child ); break; } } }
[ "protected", "static", "function", "serializeVarsRec", "(", "$", "array", ",", "&", "$", "node", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "gettype", "(", "$", "value", ")", ")", "{", "case", "'NULL'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"null\"", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "case", "'boolean'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"boolean\"", ",", "(", "int", ")", "$", "value", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "case", "'string'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"string\"", ",", "$", "value", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "case", "'integer'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"integer\"", ",", "$", "value", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "case", "'double'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"double\"", ",", "$", "value", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "case", "'array'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"array\"", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "self", "::", "serializeVarsRec", "(", "$", "value", ",", "$", "child", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "case", "'object'", ":", "$", "child", "=", "new", "XML_DOM_Node", "(", "\"object\"", ")", ";", "$", "child", "->", "setAttribute", "(", "\"name\"", ",", "$", "key", ")", ";", "$", "child", "->", "setAttribute", "(", "\"class\"", ",", "get_class", "(", "$", "value", ")", ")", ";", "$", "vars", "=", "get_object_vars", "(", "$", "value", ")", ";", "self", "::", "serializeVarsRec", "(", "$", "vars", ",", "$", "child", ")", ";", "$", "node", "->", "addChild", "(", "$", "child", ")", ";", "break", ";", "}", "}", "}" ]
Adds XML Nodes to a XML Tree by their Type while supporting nested Arrays. @access protected @static @param array $array Array of Vars to add @param XML_DOM_Node $node current XML Tree Node @return string
[ "Adds", "XML", "Nodes", "to", "a", "XML", "Tree", "by", "their", "Type", "while", "supporting", "nested", "Arrays", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/ObjectSerializer.php#L71-L118
36,190
CeusMedia/Common
src/XML/DOM/Parser.php
XML_DOM_Parser.loadXml
protected function loadXml( $xml ) { $xsv = new XML_DOM_SyntaxValidator; if( !$xsv->validate( $xml ) ) throw new Exception( "XML Document is not valid:".$xsv->getErrors() ); $this->document = $xsv->getDocument(); $this->clearOptions(); foreach( $this->attributes as $attribute ) if( isset( $this->document->$attribute ) ) $this->setOption( $attribute, $this->document->$attribute ); }
php
protected function loadXml( $xml ) { $xsv = new XML_DOM_SyntaxValidator; if( !$xsv->validate( $xml ) ) throw new Exception( "XML Document is not valid:".$xsv->getErrors() ); $this->document = $xsv->getDocument(); $this->clearOptions(); foreach( $this->attributes as $attribute ) if( isset( $this->document->$attribute ) ) $this->setOption( $attribute, $this->document->$attribute ); }
[ "protected", "function", "loadXml", "(", "$", "xml", ")", "{", "$", "xsv", "=", "new", "XML_DOM_SyntaxValidator", ";", "if", "(", "!", "$", "xsv", "->", "validate", "(", "$", "xml", ")", ")", "throw", "new", "Exception", "(", "\"XML Document is not valid:\"", ".", "$", "xsv", "->", "getErrors", "(", ")", ")", ";", "$", "this", "->", "document", "=", "$", "xsv", "->", "getDocument", "(", ")", ";", "$", "this", "->", "clearOptions", "(", ")", ";", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "attribute", ")", "if", "(", "isset", "(", "$", "this", "->", "document", "->", "$", "attribute", ")", ")", "$", "this", "->", "setOption", "(", "$", "attribute", ",", "$", "this", "->", "document", "->", "$", "attribute", ")", ";", "}" ]
Loads XML String into DOM Document Object before parsing. @access public @param string $xml XML to be parsed @return void
[ "Loads", "XML", "String", "into", "DOM", "Document", "Object", "before", "parsing", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Parser.php#L71-L81
36,191
CeusMedia/Common
src/XML/DOM/Parser.php
XML_DOM_Parser.parse
public function parse( $xml ) { $this->loadXml( $xml ); $root = $this->document->firstChild; while( $root->nodeType == XML_COMMENT_NODE ) $root = $root->nextSibling; $tree = new XML_DOM_Node( $root->nodeName ); if( $root->hasAttributes()) { $attributeNodes = $root->attributes; foreach( $attributeNodes as $attributeNode ) $tree->setAttribute( $attributeNode->nodeName, $attributeNode->nodeValue ); } $this->parseRecursive( $root, $tree ); return $tree; }
php
public function parse( $xml ) { $this->loadXml( $xml ); $root = $this->document->firstChild; while( $root->nodeType == XML_COMMENT_NODE ) $root = $root->nextSibling; $tree = new XML_DOM_Node( $root->nodeName ); if( $root->hasAttributes()) { $attributeNodes = $root->attributes; foreach( $attributeNodes as $attributeNode ) $tree->setAttribute( $attributeNode->nodeName, $attributeNode->nodeValue ); } $this->parseRecursive( $root, $tree ); return $tree; }
[ "public", "function", "parse", "(", "$", "xml", ")", "{", "$", "this", "->", "loadXml", "(", "$", "xml", ")", ";", "$", "root", "=", "$", "this", "->", "document", "->", "firstChild", ";", "while", "(", "$", "root", "->", "nodeType", "==", "XML_COMMENT_NODE", ")", "$", "root", "=", "$", "root", "->", "nextSibling", ";", "$", "tree", "=", "new", "XML_DOM_Node", "(", "$", "root", "->", "nodeName", ")", ";", "if", "(", "$", "root", "->", "hasAttributes", "(", ")", ")", "{", "$", "attributeNodes", "=", "$", "root", "->", "attributes", ";", "foreach", "(", "$", "attributeNodes", "as", "$", "attributeNode", ")", "$", "tree", "->", "setAttribute", "(", "$", "attributeNode", "->", "nodeName", ",", "$", "attributeNode", "->", "nodeValue", ")", ";", "}", "$", "this", "->", "parseRecursive", "(", "$", "root", ",", "$", "tree", ")", ";", "return", "$", "tree", ";", "}" ]
Parses XML String to XML Tree. @access public @param string $xml XML to parse @return XML_DOM_Node
[ "Parses", "XML", "String", "to", "XML", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Parser.php#L89-L105
36,192
CeusMedia/Common
src/XML/DOM/Parser.php
XML_DOM_Parser.parseRecursive
protected function parseRecursive( $root, $tree ) { $nodes = array(); if( $child = $root->firstChild ) { while( $child ) { $attributes = $child->hasAttributes()? $child->attributes : array(); switch( $child->nodeType ) { case XML_ELEMENT_NODE: $node = new XML_DOM_Node( $child->nodeName ); if( !$this->parseRecursive( $child, $node ) ) { # $node->setContent( utf8_decode( $child->textContent ) ); $node->setContent( $child->textContent ); } foreach( $attributes as $attribute) $node->setAttribute( $attribute->nodeName, stripslashes( $attribute->nodeValue ) ); $tree->addChild( $node ); break; case XML_TEXT_NODE: if( strlen( trim( $content = $child->textContent ) ) ) { return false; } else if( isset( $attributes['type'] ) && preg_match( "/.*ml/i", $attributes['type'] ) ) { return false; } break; case XML_CDATA_SECTION_NODE: $tree->setContent( stripslashes( $child->textContent ) ); break; default: break; } $child = $child->nextSibling; } } return true; }
php
protected function parseRecursive( $root, $tree ) { $nodes = array(); if( $child = $root->firstChild ) { while( $child ) { $attributes = $child->hasAttributes()? $child->attributes : array(); switch( $child->nodeType ) { case XML_ELEMENT_NODE: $node = new XML_DOM_Node( $child->nodeName ); if( !$this->parseRecursive( $child, $node ) ) { # $node->setContent( utf8_decode( $child->textContent ) ); $node->setContent( $child->textContent ); } foreach( $attributes as $attribute) $node->setAttribute( $attribute->nodeName, stripslashes( $attribute->nodeValue ) ); $tree->addChild( $node ); break; case XML_TEXT_NODE: if( strlen( trim( $content = $child->textContent ) ) ) { return false; } else if( isset( $attributes['type'] ) && preg_match( "/.*ml/i", $attributes['type'] ) ) { return false; } break; case XML_CDATA_SECTION_NODE: $tree->setContent( stripslashes( $child->textContent ) ); break; default: break; } $child = $child->nextSibling; } } return true; }
[ "protected", "function", "parseRecursive", "(", "$", "root", ",", "$", "tree", ")", "{", "$", "nodes", "=", "array", "(", ")", ";", "if", "(", "$", "child", "=", "$", "root", "->", "firstChild", ")", "{", "while", "(", "$", "child", ")", "{", "$", "attributes", "=", "$", "child", "->", "hasAttributes", "(", ")", "?", "$", "child", "->", "attributes", ":", "array", "(", ")", ";", "switch", "(", "$", "child", "->", "nodeType", ")", "{", "case", "XML_ELEMENT_NODE", ":", "$", "node", "=", "new", "XML_DOM_Node", "(", "$", "child", "->", "nodeName", ")", ";", "if", "(", "!", "$", "this", "->", "parseRecursive", "(", "$", "child", ",", "$", "node", ")", ")", "{", "#\t\t\t\t\t\t$node->setContent( utf8_decode( $child->textContent ) );\r", "$", "node", "->", "setContent", "(", "$", "child", "->", "textContent", ")", ";", "}", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "$", "node", "->", "setAttribute", "(", "$", "attribute", "->", "nodeName", ",", "stripslashes", "(", "$", "attribute", "->", "nodeValue", ")", ")", ";", "$", "tree", "->", "addChild", "(", "$", "node", ")", ";", "break", ";", "case", "XML_TEXT_NODE", ":", "if", "(", "strlen", "(", "trim", "(", "$", "content", "=", "$", "child", "->", "textContent", ")", ")", ")", "{", "return", "false", ";", "}", "else", "if", "(", "isset", "(", "$", "attributes", "[", "'type'", "]", ")", "&&", "preg_match", "(", "\"/.*ml/i\"", ",", "$", "attributes", "[", "'type'", "]", ")", ")", "{", "return", "false", ";", "}", "break", ";", "case", "XML_CDATA_SECTION_NODE", ":", "$", "tree", "->", "setContent", "(", "stripslashes", "(", "$", "child", "->", "textContent", ")", ")", ";", "break", ";", "default", ":", "break", ";", "}", "$", "child", "=", "$", "child", "->", "nextSibling", ";", "}", "}", "return", "true", ";", "}" ]
Parses XML File to XML Tree recursive. @access protected @param DOMElement $root DOM Node Element @param XML_DOM_Node $tree Parent XML Node @return bool
[ "Parses", "XML", "File", "to", "XML", "Tree", "recursive", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Parser.php#L114-L155
36,193
CeusMedia/Common
src/Net/XMPP/JID.php
Net_XMPP_JID.disassemble
static public function disassemble( $jid ){ if( !self::isValid( $jid ) ) throw new InvalidArgumentException( 'Given JID is not valid.' ); $matches = array(); preg_match_all( self::$regexJid, $jid, $matches ); return array( 'domain' => $matches[2][0], 'node' => $matches[1][0], 'resource' => $matches[3][0] ); }
php
static public function disassemble( $jid ){ if( !self::isValid( $jid ) ) throw new InvalidArgumentException( 'Given JID is not valid.' ); $matches = array(); preg_match_all( self::$regexJid, $jid, $matches ); return array( 'domain' => $matches[2][0], 'node' => $matches[1][0], 'resource' => $matches[3][0] ); }
[ "static", "public", "function", "disassemble", "(", "$", "jid", ")", "{", "if", "(", "!", "self", "::", "isValid", "(", "$", "jid", ")", ")", "throw", "new", "InvalidArgumentException", "(", "'Given JID is not valid.'", ")", ";", "$", "matches", "=", "array", "(", ")", ";", "preg_match_all", "(", "self", "::", "$", "regexJid", ",", "$", "jid", ",", "$", "matches", ")", ";", "return", "array", "(", "'domain'", "=>", "$", "matches", "[", "2", "]", "[", "0", "]", ",", "'node'", "=>", "$", "matches", "[", "1", "]", "[", "0", "]", ",", "'resource'", "=>", "$", "matches", "[", "3", "]", "[", "0", "]", ")", ";", "}" ]
Spilts JID into parts. @static @access public @return array
[ "Spilts", "JID", "into", "parts", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L68-L78
36,194
CeusMedia/Common
src/Net/XMPP/JID.php
Net_XMPP_JID.getJid
static public function getJid( $domain, $node = NULL, $resource = NULL ){ $jid = $domain; if( strlen( trim( $node ) ) ) $jid = $node.'@'.$domain; if( strlen( trim( $resource ) ) ) $jid .= "/".$resource; return $jid; }
php
static public function getJid( $domain, $node = NULL, $resource = NULL ){ $jid = $domain; if( strlen( trim( $node ) ) ) $jid = $node.'@'.$domain; if( strlen( trim( $resource ) ) ) $jid .= "/".$resource; return $jid; }
[ "static", "public", "function", "getJid", "(", "$", "domain", ",", "$", "node", "=", "NULL", ",", "$", "resource", "=", "NULL", ")", "{", "$", "jid", "=", "$", "domain", ";", "if", "(", "strlen", "(", "trim", "(", "$", "node", ")", ")", ")", "$", "jid", "=", "$", "node", ".", "'@'", ".", "$", "domain", ";", "if", "(", "strlen", "(", "trim", "(", "$", "resource", ")", ")", ")", "$", "jid", ".=", "\"/\"", ".", "$", "resource", ";", "return", "$", "jid", ";", "}" ]
Builds and returns JID from parts. @static @access public @param string $domain Domain name of XMPP server @param string $node Name of node on XMPP server @param string $resource Name of client resource @return string
[ "Builds", "and", "returns", "JID", "from", "parts", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L107-L114
36,195
CeusMedia/Common
src/Net/XMPP/JID.php
Net_XMPP_JID.set
public function set( $domain, $node = NULL, $resource = NULL ){ if( !strlen( trim( $domain ) ) ) throw new InvalidArgumentException( 'Domain is missing' ); $this->domain = $domain; $this->node = $node; $this->resource = $resource; }
php
public function set( $domain, $node = NULL, $resource = NULL ){ if( !strlen( trim( $domain ) ) ) throw new InvalidArgumentException( 'Domain is missing' ); $this->domain = $domain; $this->node = $node; $this->resource = $resource; }
[ "public", "function", "set", "(", "$", "domain", ",", "$", "node", "=", "NULL", ",", "$", "resource", "=", "NULL", ")", "{", "if", "(", "!", "strlen", "(", "trim", "(", "$", "domain", ")", ")", ")", "throw", "new", "InvalidArgumentException", "(", "'Domain is missing'", ")", ";", "$", "this", "->", "domain", "=", "$", "domain", ";", "$", "this", "->", "node", "=", "$", "node", ";", "$", "this", "->", "resource", "=", "$", "resource", ";", "}" ]
Sets JID by parts. @access public @param string $domain Domain name of XMPP server @param string $node Name of node on XMPP server @param string $resource Name of client resource @return void
[ "Sets", "JID", "by", "parts", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L152-L158
36,196
CeusMedia/Common
src/Net/XMPP/JID.php
Net_XMPP_JID.setJid
public function setJid( $jid ){ extract( self::disassemble( $jid ) ); $this->set( $domain, $node, $resource ); }
php
public function setJid( $jid ){ extract( self::disassemble( $jid ) ); $this->set( $domain, $node, $resource ); }
[ "public", "function", "setJid", "(", "$", "jid", ")", "{", "extract", "(", "self", "::", "disassemble", "(", "$", "jid", ")", ")", ";", "$", "this", "->", "set", "(", "$", "domain", ",", "$", "node", ",", "$", "resource", ")", ";", "}" ]
Sets JID. @access public @param string $jid JID: domain + optional node and resource @return void
[ "Sets", "JID", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L166-L169
36,197
CeusMedia/Common
src/Alg/Search/Interpolation.php
Alg_Search_Interpolation.calculateIndex
protected function calculateIndex( $list, $search, $lowbound, $highbound ) { $spanIndex = $list[$highbound] - $list[$lowbound]; $spanValues = $highbound - $lowbound; $spanDiff = $search - $list[$lowbound]; $index = $lowbound + round( $spanValues * ( $spanDiff / $spanIndex ) ); return $index; }
php
protected function calculateIndex( $list, $search, $lowbound, $highbound ) { $spanIndex = $list[$highbound] - $list[$lowbound]; $spanValues = $highbound - $lowbound; $spanDiff = $search - $list[$lowbound]; $index = $lowbound + round( $spanValues * ( $spanDiff / $spanIndex ) ); return $index; }
[ "protected", "function", "calculateIndex", "(", "$", "list", ",", "$", "search", ",", "$", "lowbound", ",", "$", "highbound", ")", "{", "$", "spanIndex", "=", "$", "list", "[", "$", "highbound", "]", "-", "$", "list", "[", "$", "lowbound", "]", ";", "$", "spanValues", "=", "$", "highbound", "-", "$", "lowbound", ";", "$", "spanDiff", "=", "$", "search", "-", "$", "list", "[", "$", "lowbound", "]", ";", "$", "index", "=", "$", "lowbound", "+", "round", "(", "$", "spanValues", "*", "(", "$", "spanDiff", "/", "$", "spanIndex", ")", ")", ";", "return", "$", "index", ";", "}" ]
Calculates next bound index. @access protected @param array $ist List to search in @param mixed $search Element to search @param int $lowbound Last lower bound @param int $highbound Last higher bound @return int
[ "Calculates", "next", "bound", "index", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Search/Interpolation.php#L49-L56
36,198
CeusMedia/Common
src/Alg/Search/Interpolation.php
Alg_Search_Interpolation.search
public function search( $list, $search ) { $lowbound = 0; // lowbound - untergrenze $highbound = sizeof( $list ) - 1; // highbound - obergrenze do { $index = $this->calculateIndex( $list, $search, $lowbound, $highbound ); // echo "[".$lowbound."|".$highbound."] search_index: ".$index.": ".$list[$index]."<br>"; if( $index < $lowbound || $index > $highbound ) return -1; if( $list[$index] == $search ) return $index; if( $list[$index] < $search ) $lowbound = $index+1; else $highbound = $index-1; } while( $lowbound < $highbound ); return -1; }
php
public function search( $list, $search ) { $lowbound = 0; // lowbound - untergrenze $highbound = sizeof( $list ) - 1; // highbound - obergrenze do { $index = $this->calculateIndex( $list, $search, $lowbound, $highbound ); // echo "[".$lowbound."|".$highbound."] search_index: ".$index.": ".$list[$index]."<br>"; if( $index < $lowbound || $index > $highbound ) return -1; if( $list[$index] == $search ) return $index; if( $list[$index] < $search ) $lowbound = $index+1; else $highbound = $index-1; } while( $lowbound < $highbound ); return -1; }
[ "public", "function", "search", "(", "$", "list", ",", "$", "search", ")", "{", "$", "lowbound", "=", "0", ";", "// lowbound - untergrenze\r", "$", "highbound", "=", "sizeof", "(", "$", "list", ")", "-", "1", ";", "// highbound - obergrenze\r", "do", "{", "$", "index", "=", "$", "this", "->", "calculateIndex", "(", "$", "list", ",", "$", "search", ",", "$", "lowbound", ",", "$", "highbound", ")", ";", "//\t\t\techo \"[\".$lowbound.\"|\".$highbound.\"] search_index: \".$index.\": \".$list[$index].\"<br>\";\r", "if", "(", "$", "index", "<", "$", "lowbound", "||", "$", "index", ">", "$", "highbound", ")", "return", "-", "1", ";", "if", "(", "$", "list", "[", "$", "index", "]", "==", "$", "search", ")", "return", "$", "index", ";", "if", "(", "$", "list", "[", "$", "index", "]", "<", "$", "search", ")", "$", "lowbound", "=", "$", "index", "+", "1", ";", "else", "$", "highbound", "=", "$", "index", "-", "1", ";", "}", "while", "(", "$", "lowbound", "<", "$", "highbound", ")", ";", "return", "-", "1", ";", "}" ]
Searches in List and returns position if found, else -1. @access public @param array $ist List to search in @param mixed $search Element to search @return int
[ "Searches", "in", "List", "and", "returns", "position", "if", "found", "else", "-", "1", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Search/Interpolation.php#L64-L83
36,199
CeusMedia/Common
src/Net/HTTP/Reader.php
Net_HTTP_Reader.applyCurlOptions
protected function applyCurlOptions( Net_CURL $curl, $options = array() ) { foreach( $options as $key => $value ) { if( is_string( $key ) ) { if( !( preg_match( "@^CURLOPT_@", $key ) && defined( $key ) ) ) throw new InvalidArgumentException( 'Invalid option constant key "'.$key.'"' ); $key = constant( $key ); } if( !is_int( $key ) ) throw new InvalidArgumentException( 'Option must be given as integer or string' ); $curl->setOption( $key, $value ); } }
php
protected function applyCurlOptions( Net_CURL $curl, $options = array() ) { foreach( $options as $key => $value ) { if( is_string( $key ) ) { if( !( preg_match( "@^CURLOPT_@", $key ) && defined( $key ) ) ) throw new InvalidArgumentException( 'Invalid option constant key "'.$key.'"' ); $key = constant( $key ); } if( !is_int( $key ) ) throw new InvalidArgumentException( 'Option must be given as integer or string' ); $curl->setOption( $key, $value ); } }
[ "protected", "function", "applyCurlOptions", "(", "Net_CURL", "$", "curl", ",", "$", "options", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "key", ")", ")", "{", "if", "(", "!", "(", "preg_match", "(", "\"@^CURLOPT_@\"", ",", "$", "key", ")", "&&", "defined", "(", "$", "key", ")", ")", ")", "throw", "new", "InvalidArgumentException", "(", "'Invalid option constant key \"'", ".", "$", "key", ".", "'\"'", ")", ";", "$", "key", "=", "constant", "(", "$", "key", ")", ";", "}", "if", "(", "!", "is_int", "(", "$", "key", ")", ")", "throw", "new", "InvalidArgumentException", "(", "'Option must be given as integer or string'", ")", ";", "$", "curl", "->", "setOption", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}" ]
Applies cURL Options to a cURL Object. @access protected @param Net_CURL $curl cURL Object @param array $options Map of cURL Options @return void
[ "Applies", "cURL", "Options", "to", "a", "cURL", "Object", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L72-L86