repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
eureka-framework/component-orm
src/Orm/DataMapper/MapperAbstract.php
MapperAbstract.initCache
public function initCache(Cache $cache, $enableCache = false) { $this->cache = $cache; $this->isCacheEnabled = $enableCache; if ($enableCache) { $this->cache->enable(); } else { $this->cache->disable(); } return $this; }
php
public function initCache(Cache $cache, $enableCache = false) { $this->cache = $cache; $this->isCacheEnabled = $enableCache; if ($enableCache) { $this->cache->enable(); } else { $this->cache->disable(); } return $this; }
[ "public", "function", "initCache", "(", "Cache", "$", "cache", ",", "$", "enableCache", "=", "false", ")", "{", "$", "this", "->", "cache", "=", "$", "cache", ";", "$", "this", "->", "isCacheEnabled", "=", "$", "enableCache", ";", "if", "(", "$", "enableCache", ")", "{", "$", "this", "->", "cache", "->", "enable", "(", ")", ";", "}", "else", "{", "$", "this", "->", "cache", "->", "disable", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set cache instance & enable cache if it is specified. @param Cache $cache @param bool $enableCache @return self
[ "Set", "cache", "instance", "&", "enable", "cache", "if", "it", "is", "specified", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L933-L945
train
rougin/blueprint
src/Console.php
Console.boot
public static function boot($filename = null, Injector $injector = null, $directory = null) { $directory = $directory === null ? getcwd() : $directory; $injector = $injector === null ? new Injector : $injector; $system = new Filesystem(new Local($directory)); $injector->share($system); $console = new Symfony(self::$name, self::$version); $blueprint = new Blueprint($console, $injector); return self::paths($blueprint, $directory, $filename); }
php
public static function boot($filename = null, Injector $injector = null, $directory = null) { $directory = $directory === null ? getcwd() : $directory; $injector = $injector === null ? new Injector : $injector; $system = new Filesystem(new Local($directory)); $injector->share($system); $console = new Symfony(self::$name, self::$version); $blueprint = new Blueprint($console, $injector); return self::paths($blueprint, $directory, $filename); }
[ "public", "static", "function", "boot", "(", "$", "filename", "=", "null", ",", "Injector", "$", "injector", "=", "null", ",", "$", "directory", "=", "null", ")", "{", "$", "directory", "=", "$", "directory", "===", "null", "?", "getcwd", "(", ")", ":", "$", "directory", ";", "$", "injector", "=", "$", "injector", "===", "null", "?", "new", "Injector", ":", "$", "injector", ";", "$", "system", "=", "new", "Filesystem", "(", "new", "Local", "(", "$", "directory", ")", ")", ";", "$", "injector", "->", "share", "(", "$", "system", ")", ";", "$", "console", "=", "new", "Symfony", "(", "self", "::", "$", "name", ",", "self", "::", "$", "version", ")", ";", "$", "blueprint", "=", "new", "Blueprint", "(", "$", "console", ",", "$", "injector", ")", ";", "return", "self", "::", "paths", "(", "$", "blueprint", ",", "$", "directory", ",", "$", "filename", ")", ";", "}" ]
Prepares the console application. @param string|null $filename @param \Auryn\Injector|null $injector @param string|null $directory @return \Rougin\Blueprint\Blueprint
[ "Prepares", "the", "console", "application", "." ]
02dab857b0fab60e060632f11f73e24467483e5b
https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Console.php#L39-L54
train
rougin/blueprint
src/Console.php
Console.paths
protected static function paths(Blueprint $blueprint, $directory, $filename = null) { $yaml = file_exists($filename) ? file_get_contents($filename) : ''; $yaml = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $yaml); $yaml = str_replace('%%CURRENT_DIRECTORY%%', $directory, $yaml); $result = Yaml::parse($yaml) ?: self::defaults(); $blueprint->setTemplatePath($result['paths']['templates']); $blueprint->setCommandPath($result['paths']['commands']); $blueprint->setCommandNamespace($result['namespaces']['commands']); return $blueprint; }
php
protected static function paths(Blueprint $blueprint, $directory, $filename = null) { $yaml = file_exists($filename) ? file_get_contents($filename) : ''; $yaml = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $yaml); $yaml = str_replace('%%CURRENT_DIRECTORY%%', $directory, $yaml); $result = Yaml::parse($yaml) ?: self::defaults(); $blueprint->setTemplatePath($result['paths']['templates']); $blueprint->setCommandPath($result['paths']['commands']); $blueprint->setCommandNamespace($result['namespaces']['commands']); return $blueprint; }
[ "protected", "static", "function", "paths", "(", "Blueprint", "$", "blueprint", ",", "$", "directory", ",", "$", "filename", "=", "null", ")", "{", "$", "yaml", "=", "file_exists", "(", "$", "filename", ")", "?", "file_get_contents", "(", "$", "filename", ")", ":", "''", ";", "$", "yaml", "=", "str_replace", "(", "array", "(", "'\\\\'", ",", "'/'", ")", ",", "DIRECTORY_SEPARATOR", ",", "$", "yaml", ")", ";", "$", "yaml", "=", "str_replace", "(", "'%%CURRENT_DIRECTORY%%'", ",", "$", "directory", ",", "$", "yaml", ")", ";", "$", "result", "=", "Yaml", "::", "parse", "(", "$", "yaml", ")", "?", ":", "self", "::", "defaults", "(", ")", ";", "$", "blueprint", "->", "setTemplatePath", "(", "$", "result", "[", "'paths'", "]", "[", "'templates'", "]", ")", ";", "$", "blueprint", "->", "setCommandPath", "(", "$", "result", "[", "'paths'", "]", "[", "'commands'", "]", ")", ";", "$", "blueprint", "->", "setCommandNamespace", "(", "$", "result", "[", "'namespaces'", "]", "[", "'commands'", "]", ")", ";", "return", "$", "blueprint", ";", "}" ]
Prepares the paths that are defined from a YAML file. @param \Rougin\Blueprint\Blueprint $blueprint @param string $directory @param string|null $filename @return \Rougin\Blueprint\Blueprint
[ "Prepares", "the", "paths", "that", "are", "defined", "from", "a", "YAML", "file", "." ]
02dab857b0fab60e060632f11f73e24467483e5b
https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Console.php#L82-L99
train
cogentParadigm/behat-starbug-extension
src/Context/ShellContext.php
ShellContext.iShouldSeeInTheOutput
public function iShouldSeeInTheOutput($string) { if (strpos($this->output, $string) === false) { throw new Exception(sprintf('Did not see "%s" in output "%s"', $string, $this->output)); } }
php
public function iShouldSeeInTheOutput($string) { if (strpos($this->output, $string) === false) { throw new Exception(sprintf('Did not see "%s" in output "%s"', $string, $this->output)); } }
[ "public", "function", "iShouldSeeInTheOutput", "(", "$", "string", ")", "{", "if", "(", "strpos", "(", "$", "this", "->", "output", ",", "$", "string", ")", "===", "false", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Did not see \"%s\" in output \"%s\"'", ",", "$", "string", ",", "$", "this", "->", "output", ")", ")", ";", "}", "}" ]
Validate command output. @Then I should see :string in the output @throws Exception if output does not contain phrase.
[ "Validate", "command", "output", "." ]
76da5d943773857ad2388a7cccb6632176b452a9
https://github.com/cogentParadigm/behat-starbug-extension/blob/76da5d943773857ad2388a7cccb6632176b452a9/src/Context/ShellContext.php#L27-L31
train
AmericanCouncils/WebServicesBundle
Controller.php
Controller.decodeRequest
protected function decodeRequest($class, Context $ctx = null) { $container = $this->container; $request = $container->get('request'); $serializerFormat = $this->container->get('ac_web_services.negotiator')->negotiateRequestFormat($request); $data = $request->getContent(); //check for raw form submission, php is stupid about this, so there needs to be a check for it here if ('form' === $serializerFormat && $container->getParameter('ac_web_services.serializer.enable_form_deserialization')) { $data = $request->request->all(); if (empty($data)) { if ( 0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH')) ) { parse_str($request->getContent(), $data); } } } if (!$data) { return null; } return $this->deserialize($data, $class, $serializerFormat, $ctx); }
php
protected function decodeRequest($class, Context $ctx = null) { $container = $this->container; $request = $container->get('request'); $serializerFormat = $this->container->get('ac_web_services.negotiator')->negotiateRequestFormat($request); $data = $request->getContent(); //check for raw form submission, php is stupid about this, so there needs to be a check for it here if ('form' === $serializerFormat && $container->getParameter('ac_web_services.serializer.enable_form_deserialization')) { $data = $request->request->all(); if (empty($data)) { if ( 0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded') && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), array('PUT', 'DELETE', 'PATCH')) ) { parse_str($request->getContent(), $data); } } } if (!$data) { return null; } return $this->deserialize($data, $class, $serializerFormat, $ctx); }
[ "protected", "function", "decodeRequest", "(", "$", "class", ",", "Context", "$", "ctx", "=", "null", ")", "{", "$", "container", "=", "$", "this", "->", "container", ";", "$", "request", "=", "$", "container", "->", "get", "(", "'request'", ")", ";", "$", "serializerFormat", "=", "$", "this", "->", "container", "->", "get", "(", "'ac_web_services.negotiator'", ")", "->", "negotiateRequestFormat", "(", "$", "request", ")", ";", "$", "data", "=", "$", "request", "->", "getContent", "(", ")", ";", "//check for raw form submission, php is stupid about this, so there needs to be a check for it here", "if", "(", "'form'", "===", "$", "serializerFormat", "&&", "$", "container", "->", "getParameter", "(", "'ac_web_services.serializer.enable_form_deserialization'", ")", ")", "{", "$", "data", "=", "$", "request", "->", "request", "->", "all", "(", ")", ";", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "request", "->", "headers", "->", "get", "(", "'CONTENT_TYPE'", ")", ",", "'application/x-www-form-urlencoded'", ")", "&&", "in_array", "(", "strtoupper", "(", "$", "request", "->", "server", "->", "get", "(", "'REQUEST_METHOD'", ",", "'GET'", ")", ")", ",", "array", "(", "'PUT'", ",", "'DELETE'", ",", "'PATCH'", ")", ")", ")", "{", "parse_str", "(", "$", "request", "->", "getContent", "(", ")", ",", "$", "data", ")", ";", "}", "}", "}", "if", "(", "!", "$", "data", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "deserialize", "(", "$", "data", ",", "$", "class", ",", "$", "serializerFormat", ",", "$", "ctx", ")", ";", "}" ]
Convenience method for decoding incoming API data. The data format is determined via a negotiation service, and then deserialized. @return mixed
[ "Convenience", "method", "for", "decoding", "incoming", "API", "data", ".", "The", "data", "format", "is", "determined", "via", "a", "negotiation", "service", "and", "then", "deserialized", "." ]
3f6270ecf31138ba2271a94a407c0d1a05542929
https://github.com/AmericanCouncils/WebServicesBundle/blob/3f6270ecf31138ba2271a94a407c0d1a05542929/Controller.php#L18-L45
train
AmericanCouncils/WebServicesBundle
Controller.php
Controller.validate
protected function validate($obj) { $errors = $this->container->get('validator')->validate($obj); if (count($errors) > 0) { throw new ValidationException($errors); } }
php
protected function validate($obj) { $errors = $this->container->get('validator')->validate($obj); if (count($errors) > 0) { throw new ValidationException($errors); } }
[ "protected", "function", "validate", "(", "$", "obj", ")", "{", "$", "errors", "=", "$", "this", "->", "container", "->", "get", "(", "'validator'", ")", "->", "validate", "(", "$", "obj", ")", ";", "if", "(", "count", "(", "$", "errors", ")", ">", "0", ")", "{", "throw", "new", "ValidationException", "(", "$", "errors", ")", ";", "}", "}" ]
Convenience validation method that will automatically throw custom ValidationExceptions when validation fails. @throws ValidationException
[ "Convenience", "validation", "method", "that", "will", "automatically", "throw", "custom", "ValidationExceptions", "when", "validation", "fails", "." ]
3f6270ecf31138ba2271a94a407c0d1a05542929
https://github.com/AmericanCouncils/WebServicesBundle/blob/3f6270ecf31138ba2271a94a407c0d1a05542929/Controller.php#L76-L83
train
Wedeto/DB
src/Query/GroupByClause.php
GroupByClause.toSQL
public function toSQL(Parameters $params, bool $inner_clause) { $groups = $this->getGroups(); $having = $this->getHaving(); if (count($groups) === 0) throw new QueryException("No groups in GROUP BY clause"); $drv = $params->getDriver(); $parts = array(); foreach ($groups as $group) { $parts[] = $drv->toSQL($params, $group); } $having = !empty($having) ? ' ' . $drv->toSQL($params, $having) : ""; return "GROUP BY " . implode(", ", $parts) . $having; }
php
public function toSQL(Parameters $params, bool $inner_clause) { $groups = $this->getGroups(); $having = $this->getHaving(); if (count($groups) === 0) throw new QueryException("No groups in GROUP BY clause"); $drv = $params->getDriver(); $parts = array(); foreach ($groups as $group) { $parts[] = $drv->toSQL($params, $group); } $having = !empty($having) ? ' ' . $drv->toSQL($params, $having) : ""; return "GROUP BY " . implode(", ", $parts) . $having; }
[ "public", "function", "toSQL", "(", "Parameters", "$", "params", ",", "bool", "$", "inner_clause", ")", "{", "$", "groups", "=", "$", "this", "->", "getGroups", "(", ")", ";", "$", "having", "=", "$", "this", "->", "getHaving", "(", ")", ";", "if", "(", "count", "(", "$", "groups", ")", "===", "0", ")", "throw", "new", "QueryException", "(", "\"No groups in GROUP BY clause\"", ")", ";", "$", "drv", "=", "$", "params", "->", "getDriver", "(", ")", ";", "$", "parts", "=", "array", "(", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "$", "parts", "[", "]", "=", "$", "drv", "->", "toSQL", "(", "$", "params", ",", "$", "group", ")", ";", "}", "$", "having", "=", "!", "empty", "(", "$", "having", ")", "?", "' '", ".", "$", "drv", "->", "toSQL", "(", "$", "params", ",", "$", "having", ")", ":", "\"\"", ";", "return", "\"GROUP BY \"", ".", "implode", "(", "\", \"", ",", "$", "parts", ")", ".", "$", "having", ";", "}" ]
Write a GROUPBY clause as SQL query syntax @param Parameters $params The query parameters: tables and placeholder values @param bool $inner_clause Unused @return string The generated SQL
[ "Write", "a", "GROUPBY", "clause", "as", "SQL", "query", "syntax" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/GroupByClause.php#L91-L110
train
WellCommerce/CartBundle
Manager/Front/CartProductManager.php
CartProductManager.getCartProductInCart
protected function getCartProductInCart(CartProductInterface $cartProduct, CartInterface $cart) { return $this->getRepository()->findOneBy([ 'id' => $cartProduct->getId(), 'cart' => $cart ]); }
php
protected function getCartProductInCart(CartProductInterface $cartProduct, CartInterface $cart) { return $this->getRepository()->findOneBy([ 'id' => $cartProduct->getId(), 'cart' => $cart ]); }
[ "protected", "function", "getCartProductInCart", "(", "CartProductInterface", "$", "cartProduct", ",", "CartInterface", "$", "cart", ")", "{", "return", "$", "this", "->", "getRepository", "(", ")", "->", "findOneBy", "(", "[", "'id'", "=>", "$", "cartProduct", "->", "getId", "(", ")", ",", "'cart'", "=>", "$", "cart", "]", ")", ";", "}" ]
Returns an item from cart @param CartProductInterface $cartProduct @param CartInterface $cart @return null|CartProductInterface
[ "Returns", "an", "item", "from", "cart" ]
77c1e12b36bde008dca61260481b21135e339396
https://github.com/WellCommerce/CartBundle/blob/77c1e12b36bde008dca61260481b21135e339396/Manager/Front/CartProductManager.php#L118-L124
train
Wedeto/Auth
src/Authentication.php
Authentication.setUserClass
public function setUserClass(string $classname) { if (!class_exists($classname) || !is_subclass_of($classname, UserInterface::class)) throw new DomainException("Invalid user class: $classname"); $this->user_class = $classname; return $this; }
php
public function setUserClass(string $classname) { if (!class_exists($classname) || !is_subclass_of($classname, UserInterface::class)) throw new DomainException("Invalid user class: $classname"); $this->user_class = $classname; return $this; }
[ "public", "function", "setUserClass", "(", "string", "$", "classname", ")", "{", "if", "(", "!", "class_exists", "(", "$", "classname", ")", "||", "!", "is_subclass_of", "(", "$", "classname", ",", "UserInterface", "::", "class", ")", ")", "throw", "new", "DomainException", "(", "\"Invalid user class: $classname\"", ")", ";", "$", "this", "->", "user_class", "=", "$", "classname", ";", "return", "$", "this", ";", "}" ]
Set the UserInterface class that represents users. @param string $classname The class to use for users. This should implement Wedeto\Auth\UserInterface. @return Wedeto\Auth\Authentication Provides fluent interface
[ "Set", "the", "UserInterface", "class", "that", "represents", "users", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L67-L73
train
Wedeto/Auth
src/Authentication.php
Authentication.setGroupClass
public function setGroupClass(string $classname) { if (!class_exists($classname) || !is_subclass_of($classname, GroupInterface::class)) throw new DomainException("Invalid group class: $classname"); $this->group_class = $classname; return $this; }
php
public function setGroupClass(string $classname) { if (!class_exists($classname) || !is_subclass_of($classname, GroupInterface::class)) throw new DomainException("Invalid group class: $classname"); $this->group_class = $classname; return $this; }
[ "public", "function", "setGroupClass", "(", "string", "$", "classname", ")", "{", "if", "(", "!", "class_exists", "(", "$", "classname", ")", "||", "!", "is_subclass_of", "(", "$", "classname", ",", "GroupInterface", "::", "class", ")", ")", "throw", "new", "DomainException", "(", "\"Invalid group class: $classname\"", ")", ";", "$", "this", "->", "group_class", "=", "$", "classname", ";", "return", "$", "this", ";", "}" ]
Set the GroupInterface class that represents groups. @param string $classname the class to use for gruops. This should implement Wedeto\Auth\GroupInterface. @return Wedeto\Auth\Authentication PRovides fluent interface
[ "Set", "the", "GroupInterface", "class", "that", "represents", "groups", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L81-L87
train
Wedeto/Auth
src/Authentication.php
Authentication.getUserFromSession
public function getUserFromSession(Session $session) { $cl = $this->getUserClass(); $this->user = new $cl; $this->user->obtainFromSession($session); return $this->user; }
php
public function getUserFromSession(Session $session) { $cl = $this->getUserClass(); $this->user = new $cl; $this->user->obtainFromSession($session); return $this->user; }
[ "public", "function", "getUserFromSession", "(", "Session", "$", "session", ")", "{", "$", "cl", "=", "$", "this", "->", "getUserClass", "(", ")", ";", "$", "this", "->", "user", "=", "new", "$", "cl", ";", "$", "this", "->", "user", "->", "obtainFromSession", "(", "$", "session", ")", ";", "return", "$", "this", "->", "user", ";", "}" ]
Obtain the current user from the active session @param Wedeto\HTTP\Session $session The session object @return Wedeto\Auth\UserInteface The current user. Can be anonymous if noone is logged in.
[ "Obtain", "the", "current", "user", "from", "the", "active", "session" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L139-L145
train
Wedeto/Auth
src/Authentication.php
Authentication.getUser
public function getUser(string $userid) { $cl = $this->getUserClass(); $user = new $cl; return $user->obtainByUserID($userid); }
php
public function getUser(string $userid) { $cl = $this->getUserClass(); $user = new $cl; return $user->obtainByUserID($userid); }
[ "public", "function", "getUser", "(", "string", "$", "userid", ")", "{", "$", "cl", "=", "$", "this", "->", "getUserClass", "(", ")", ";", "$", "user", "=", "new", "$", "cl", ";", "return", "$", "user", "->", "obtainByUserID", "(", "$", "userid", ")", ";", "}" ]
Obtain a user by its user ID. @param string $userID The User ID to load @return Wedeto\Auth\UserInterface The user @throws Wedeto\Auth\NotFoundException When the user does not exist
[ "Obtain", "a", "user", "by", "its", "user", "ID", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L153-L158
train
Wedeto/Auth
src/Authentication.php
Authentication.getGroup
public function getGroup(string $groupid) { $cl = $this->getGroupClass(); $group = new $cl; return $group->obtainByGroupID($groupid); }
php
public function getGroup(string $groupid) { $cl = $this->getGroupClass(); $group = new $cl; return $group->obtainByGroupID($groupid); }
[ "public", "function", "getGroup", "(", "string", "$", "groupid", ")", "{", "$", "cl", "=", "$", "this", "->", "getGroupClass", "(", ")", ";", "$", "group", "=", "new", "$", "cl", ";", "return", "$", "group", "->", "obtainByGroupID", "(", "$", "groupid", ")", ";", "}" ]
Obtain a group by its group ID. @param string $groupid The group ID to load @return Wedeto\Auth\GroupInterface The loaded group @throws Wedeto\Auth\NotFoundException When the group does not exist
[ "Obtain", "a", "group", "by", "its", "group", "ID", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L166-L171
train
Wedeto/Auth
src/Authentication.php
Authentication.login
public function login(string $username, string $password, Session $session) { if ($session->has('authentication', 'user_id')) { throw new AuthenticationError( "Already logged in", AuthenticationError::DUPLICATE_SESSION ); } $cl = $this->getUserClass(); $this->user = new $cl; try { $this->user->obtainFromLogin($username, $password); } catch (AuthenticationError $e) { throw $e; } catch (\Exception $e) { throw new AuthenticationError("Login failed", $e->getCode(), $e); } $session->set('authentication', 'user_id', $this->user->getUserID()); return $this->user; }
php
public function login(string $username, string $password, Session $session) { if ($session->has('authentication', 'user_id')) { throw new AuthenticationError( "Already logged in", AuthenticationError::DUPLICATE_SESSION ); } $cl = $this->getUserClass(); $this->user = new $cl; try { $this->user->obtainFromLogin($username, $password); } catch (AuthenticationError $e) { throw $e; } catch (\Exception $e) { throw new AuthenticationError("Login failed", $e->getCode(), $e); } $session->set('authentication', 'user_id', $this->user->getUserID()); return $this->user; }
[ "public", "function", "login", "(", "string", "$", "username", ",", "string", "$", "password", ",", "Session", "$", "session", ")", "{", "if", "(", "$", "session", "->", "has", "(", "'authentication'", ",", "'user_id'", ")", ")", "{", "throw", "new", "AuthenticationError", "(", "\"Already logged in\"", ",", "AuthenticationError", "::", "DUPLICATE_SESSION", ")", ";", "}", "$", "cl", "=", "$", "this", "->", "getUserClass", "(", ")", ";", "$", "this", "->", "user", "=", "new", "$", "cl", ";", "try", "{", "$", "this", "->", "user", "->", "obtainFromLogin", "(", "$", "username", ",", "$", "password", ")", ";", "}", "catch", "(", "AuthenticationError", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "AuthenticationError", "(", "\"Login failed\"", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "$", "session", "->", "set", "(", "'authentication'", ",", "'user_id'", ",", "$", "this", "->", "user", "->", "getUserID", "(", ")", ")", ";", "return", "$", "this", "->", "user", ";", "}" ]
Check if the provided details contain a valid login. @param string $username The user to log in @param string $password The password to verify @param Wedeto\HTTP\Session $session The session to log into @throws Wedeto\Auth\AuthenticationError When logging in fails @return Wedeto\Auth\UserInterface The logged in user
[ "Check", "if", "the", "provided", "details", "contain", "a", "valid", "login", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L189-L216
train
Wedeto/Auth
src/Authentication.php
Authentication.hash
public function hash(string $password) { $algorithm = $this->config->dget('algorithm', PASSWORD_DEFAULT); $options['cost'] = $this->config->dget('cost', 10); return password_hash($password, $algorithm, $options); }
php
public function hash(string $password) { $algorithm = $this->config->dget('algorithm', PASSWORD_DEFAULT); $options['cost'] = $this->config->dget('cost', 10); return password_hash($password, $algorithm, $options); }
[ "public", "function", "hash", "(", "string", "$", "password", ")", "{", "$", "algorithm", "=", "$", "this", "->", "config", "->", "dget", "(", "'algorithm'", ",", "PASSWORD_DEFAULT", ")", ";", "$", "options", "[", "'cost'", "]", "=", "$", "this", "->", "config", "->", "dget", "(", "'cost'", ",", "10", ")", ";", "return", "password_hash", "(", "$", "password", ",", "$", "algorithm", ",", "$", "options", ")", ";", "}" ]
Create a hash of the password @param string $password The password to hash @return string The hashed password
[ "Create", "a", "hash", "of", "the", "password" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L223-L229
train
Wedeto/Auth
src/Authentication.php
Authentication.verify
public function verify(string $password, string $hash) { if (substr($hash, 0, 1) !== "$") { $salt = $this->config->dget('salt', ''); $append = $this->config->dget('salt_placement', 'append') === 'append'; $to_hash = $append ? $password . $salt : $salt . $password; $pw_hash = hash('sha256', $to_hash); return $pw_hash === $hash; } return password_verify($password, $hash); }
php
public function verify(string $password, string $hash) { if (substr($hash, 0, 1) !== "$") { $salt = $this->config->dget('salt', ''); $append = $this->config->dget('salt_placement', 'append') === 'append'; $to_hash = $append ? $password . $salt : $salt . $password; $pw_hash = hash('sha256', $to_hash); return $pw_hash === $hash; } return password_verify($password, $hash); }
[ "public", "function", "verify", "(", "string", "$", "password", ",", "string", "$", "hash", ")", "{", "if", "(", "substr", "(", "$", "hash", ",", "0", ",", "1", ")", "!==", "\"$\"", ")", "{", "$", "salt", "=", "$", "this", "->", "config", "->", "dget", "(", "'salt'", ",", "''", ")", ";", "$", "append", "=", "$", "this", "->", "config", "->", "dget", "(", "'salt_placement'", ",", "'append'", ")", "===", "'append'", ";", "$", "to_hash", "=", "$", "append", "?", "$", "password", ".", "$", "salt", ":", "$", "salt", ".", "$", "password", ";", "$", "pw_hash", "=", "hash", "(", "'sha256'", ",", "$", "to_hash", ")", ";", "return", "$", "pw_hash", "===", "$", "hash", ";", "}", "return", "password_verify", "(", "$", "password", ",", "$", "hash", ")", ";", "}" ]
Check if the password matches the provided hash. The password should come from user input, the hash from persistent storage. @param string $password The password to verify @param string $hash The hash of the correct password @return bool True if the password matches the hash, false if it does not.
[ "Check", "if", "the", "password", "matches", "the", "provided", "hash", ".", "The", "password", "should", "come", "from", "user", "input", "the", "hash", "from", "persistent", "storage", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L239-L251
train
Wedeto/Auth
src/Authentication.php
Authentication.needsRehash
public function needsRehash(string $hash) { if (substr($hash, 0, 1) !== "$") return true; $algorithm = $this->config->dget('algorithm', PASSWORD_DEFAULT); $options['cost'] = $this->config->dget('cost', 10); return password_needs_rehash($hash, $algorithm, $options); }
php
public function needsRehash(string $hash) { if (substr($hash, 0, 1) !== "$") return true; $algorithm = $this->config->dget('algorithm', PASSWORD_DEFAULT); $options['cost'] = $this->config->dget('cost', 10); return password_needs_rehash($hash, $algorithm, $options); }
[ "public", "function", "needsRehash", "(", "string", "$", "hash", ")", "{", "if", "(", "substr", "(", "$", "hash", ",", "0", ",", "1", ")", "!==", "\"$\"", ")", "return", "true", ";", "$", "algorithm", "=", "$", "this", "->", "config", "->", "dget", "(", "'algorithm'", ",", "PASSWORD_DEFAULT", ")", ";", "$", "options", "[", "'cost'", "]", "=", "$", "this", "->", "config", "->", "dget", "(", "'cost'", ",", "10", ")", ";", "return", "password_needs_rehash", "(", "$", "hash", ",", "$", "algorithm", ",", "$", "options", ")", ";", "}" ]
Check if the password needs a rehash @param string $hash The hash to check @return bool True if the password needs to be rehashed, false if not
[ "Check", "if", "the", "password", "needs", "a", "rehash" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/Authentication.php#L258-L266
train
joegreen88/zf1-component-validate
src/Zend/Validate/Barcode/Upce.php
Zend_Validate_Barcode_Upce.checkLength
public function checkLength($value) { if (strlen($value) != 8) { $this->setCheck(false); } else { $this->setCheck(true); } return parent::checkLength($value); }
php
public function checkLength($value) { if (strlen($value) != 8) { $this->setCheck(false); } else { $this->setCheck(true); } return parent::checkLength($value); }
[ "public", "function", "checkLength", "(", "$", "value", ")", "{", "if", "(", "strlen", "(", "$", "value", ")", "!=", "8", ")", "{", "$", "this", "->", "setCheck", "(", "false", ")", ";", "}", "else", "{", "$", "this", "->", "setCheck", "(", "true", ")", ";", "}", "return", "parent", "::", "checkLength", "(", "$", "value", ")", ";", "}" ]
Overrides parent checkLength @param string $value Value @return boolean
[ "Overrides", "parent", "checkLength" ]
88d9ea016f73d48ff0ba7d06ecbbf28951fd279e
https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Barcode/Upce.php#L59-L68
train
gilbertsoft/typo3-gswarranty
Classes/Backend/ToolbarItems/WarrantyLinkToolbarItem.php
WarrantyLinkToolbarItem.getFluidTemplateObject
protected function getFluidTemplateObject($filename) { $view = GeneralUtility::makeInstance(StandaloneView::class); $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']); if (\Gilbertsoft\Warranty\Utility\Adapter::isCompatVersion('8.7')) { $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']); $view->assignMultiple([ 'iconSize' => 'default', ]); } else { $view->setPartialRootPaths(['EXT:gswarranty/Resources/Private/Partials/ToolbarItems']); $view->assignMultiple([ 'iconSize' => 'small', ]); } $view->setTemplateRootPaths(['EXT:gswarranty/Resources/Private/Templates/ToolbarItems']); $view->setTemplate($filename); return $view; }
php
protected function getFluidTemplateObject($filename) { $view = GeneralUtility::makeInstance(StandaloneView::class); $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']); if (\Gilbertsoft\Warranty\Utility\Adapter::isCompatVersion('8.7')) { $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials/ToolbarItems']); $view->assignMultiple([ 'iconSize' => 'default', ]); } else { $view->setPartialRootPaths(['EXT:gswarranty/Resources/Private/Partials/ToolbarItems']); $view->assignMultiple([ 'iconSize' => 'small', ]); } $view->setTemplateRootPaths(['EXT:gswarranty/Resources/Private/Templates/ToolbarItems']); $view->setTemplate($filename); return $view; }
[ "protected", "function", "getFluidTemplateObject", "(", "$", "filename", ")", "{", "$", "view", "=", "GeneralUtility", "::", "makeInstance", "(", "StandaloneView", "::", "class", ")", ";", "$", "view", "->", "setLayoutRootPaths", "(", "[", "'EXT:backend/Resources/Private/Layouts'", "]", ")", ";", "if", "(", "\\", "Gilbertsoft", "\\", "Warranty", "\\", "Utility", "\\", "Adapter", "::", "isCompatVersion", "(", "'8.7'", ")", ")", "{", "$", "view", "->", "setPartialRootPaths", "(", "[", "'EXT:backend/Resources/Private/Partials/ToolbarItems'", "]", ")", ";", "$", "view", "->", "assignMultiple", "(", "[", "'iconSize'", "=>", "'default'", ",", "]", ")", ";", "}", "else", "{", "$", "view", "->", "setPartialRootPaths", "(", "[", "'EXT:gswarranty/Resources/Private/Partials/ToolbarItems'", "]", ")", ";", "$", "view", "->", "assignMultiple", "(", "[", "'iconSize'", "=>", "'small'", ",", "]", ")", ";", "}", "$", "view", "->", "setTemplateRootPaths", "(", "[", "'EXT:gswarranty/Resources/Private/Templates/ToolbarItems'", "]", ")", ";", "$", "view", "->", "setTemplate", "(", "$", "filename", ")", ";", "return", "$", "view", ";", "}" ]
Returns a new standalone view, shorthand function @param string $filename Which templateFile should be used. @return StandaloneView
[ "Returns", "a", "new", "standalone", "view", "shorthand", "function" ]
2026dd04e6df9db61b56df3860e1f3462db54c69
https://github.com/gilbertsoft/typo3-gswarranty/blob/2026dd04e6df9db61b56df3860e1f3462db54c69/Classes/Backend/ToolbarItems/WarrantyLinkToolbarItem.php#L100-L119
train
Erebot/Module_Wordlists
src/Wordlists/Wordlist.php
Wordlist.parseFile
protected function parseFile($file) { $this->file = $file; // When running as a PHAR, copy the SQLite database // to a temporary file. Required as the SQLite3 driver // does not support streams (and it can"t, see #55154). if (!strncasecmp(__FILE__, 'phar://', 7)) { $this->file = tempnam( sys_get_temp_dir(), 'Wordlists' ); copy($file, $this->file); } $this->db = new \PDO('sqlite:' . $this->file); $metadata = $this->db->query( 'SELECT type, value '. 'FROM metadata '. 'ORDER BY type ASC, id ASC' ); foreach ($metadata as $row) { if (!array_key_exists($row['type'], $this->metadata)) { continue; } if (is_array($this->metadata[$row['type']])) { $this->metadata[$row['type']][] = $row['value']; } else { $this->metadata[$row['type']] = $row['value']; } } // Try to create a collator for the given locale. $this->collator = new \Collator( str_replace('-', '_', $this->metadata['locale']) ); // -127 = U_USING_DEFAULT_WARNING // -128 = U_USING_FALLBACK_WARNING. // 0 = U_ZERO_ERROR (no error). if (!in_array(intl_get_error_code(), array(-127, -128, 0))) { throw new \Erebot\InvalidValueException( "Invalid locale (".$this->metadata['locale']."): ". intl_get_error_message() ); } // Ignore differences in case, accents and punctuation. $this->collator->setStrength(\Collator::PRIMARY); $this->countQuery = $this->db->prepare( 'SELECT COUNT(1) '. 'FROM words' ); $this->getQuery = $this->db->prepare( 'SELECT value '. 'FROM words '. 'ORDER BY sortkey ASC '. 'LIMIT 1 OFFSET :offset' ); $this->existsQuery = $this->db->prepare( 'SELECT value '. 'FROM words '. 'WHERE sortkey = :key '. 'LIMIT 1' ); }
php
protected function parseFile($file) { $this->file = $file; // When running as a PHAR, copy the SQLite database // to a temporary file. Required as the SQLite3 driver // does not support streams (and it can"t, see #55154). if (!strncasecmp(__FILE__, 'phar://', 7)) { $this->file = tempnam( sys_get_temp_dir(), 'Wordlists' ); copy($file, $this->file); } $this->db = new \PDO('sqlite:' . $this->file); $metadata = $this->db->query( 'SELECT type, value '. 'FROM metadata '. 'ORDER BY type ASC, id ASC' ); foreach ($metadata as $row) { if (!array_key_exists($row['type'], $this->metadata)) { continue; } if (is_array($this->metadata[$row['type']])) { $this->metadata[$row['type']][] = $row['value']; } else { $this->metadata[$row['type']] = $row['value']; } } // Try to create a collator for the given locale. $this->collator = new \Collator( str_replace('-', '_', $this->metadata['locale']) ); // -127 = U_USING_DEFAULT_WARNING // -128 = U_USING_FALLBACK_WARNING. // 0 = U_ZERO_ERROR (no error). if (!in_array(intl_get_error_code(), array(-127, -128, 0))) { throw new \Erebot\InvalidValueException( "Invalid locale (".$this->metadata['locale']."): ". intl_get_error_message() ); } // Ignore differences in case, accents and punctuation. $this->collator->setStrength(\Collator::PRIMARY); $this->countQuery = $this->db->prepare( 'SELECT COUNT(1) '. 'FROM words' ); $this->getQuery = $this->db->prepare( 'SELECT value '. 'FROM words '. 'ORDER BY sortkey ASC '. 'LIMIT 1 OFFSET :offset' ); $this->existsQuery = $this->db->prepare( 'SELECT value '. 'FROM words '. 'WHERE sortkey = :key '. 'LIMIT 1' ); }
[ "protected", "function", "parseFile", "(", "$", "file", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "// When running as a PHAR, copy the SQLite database", "// to a temporary file. Required as the SQLite3 driver", "// does not support streams (and it can\"t, see #55154).", "if", "(", "!", "strncasecmp", "(", "__FILE__", ",", "'phar://'", ",", "7", ")", ")", "{", "$", "this", "->", "file", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "'Wordlists'", ")", ";", "copy", "(", "$", "file", ",", "$", "this", "->", "file", ")", ";", "}", "$", "this", "->", "db", "=", "new", "\\", "PDO", "(", "'sqlite:'", ".", "$", "this", "->", "file", ")", ";", "$", "metadata", "=", "$", "this", "->", "db", "->", "query", "(", "'SELECT type, value '", ".", "'FROM metadata '", ".", "'ORDER BY type ASC, id ASC'", ")", ";", "foreach", "(", "$", "metadata", "as", "$", "row", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "row", "[", "'type'", "]", ",", "$", "this", "->", "metadata", ")", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "metadata", "[", "$", "row", "[", "'type'", "]", "]", ")", ")", "{", "$", "this", "->", "metadata", "[", "$", "row", "[", "'type'", "]", "]", "[", "]", "=", "$", "row", "[", "'value'", "]", ";", "}", "else", "{", "$", "this", "->", "metadata", "[", "$", "row", "[", "'type'", "]", "]", "=", "$", "row", "[", "'value'", "]", ";", "}", "}", "// Try to create a collator for the given locale.", "$", "this", "->", "collator", "=", "new", "\\", "Collator", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "this", "->", "metadata", "[", "'locale'", "]", ")", ")", ";", "// -127 = U_USING_DEFAULT_WARNING", "// -128 = U_USING_FALLBACK_WARNING.", "// 0 = U_ZERO_ERROR (no error).", "if", "(", "!", "in_array", "(", "intl_get_error_code", "(", ")", ",", "array", "(", "-", "127", ",", "-", "128", ",", "0", ")", ")", ")", "{", "throw", "new", "\\", "Erebot", "\\", "InvalidValueException", "(", "\"Invalid locale (\"", ".", "$", "this", "->", "metadata", "[", "'locale'", "]", ".", "\"): \"", ".", "intl_get_error_message", "(", ")", ")", ";", "}", "// Ignore differences in case, accents and punctuation.", "$", "this", "->", "collator", "->", "setStrength", "(", "\\", "Collator", "::", "PRIMARY", ")", ";", "$", "this", "->", "countQuery", "=", "$", "this", "->", "db", "->", "prepare", "(", "'SELECT COUNT(1) '", ".", "'FROM words'", ")", ";", "$", "this", "->", "getQuery", "=", "$", "this", "->", "db", "->", "prepare", "(", "'SELECT value '", ".", "'FROM words '", ".", "'ORDER BY sortkey ASC '", ".", "'LIMIT 1 OFFSET :offset'", ")", ";", "$", "this", "->", "existsQuery", "=", "$", "this", "->", "db", "->", "prepare", "(", "'SELECT value '", ".", "'FROM words '", ".", "'WHERE sortkey = :key '", ".", "'LIMIT 1'", ")", ";", "}" ]
Parse the content of a SQLite file representing a list of words. \param string $file The full path to the SQLite file containing the list of words to use. \throw Erebot::InvalidValueException The locale indicated in the file was invalid.
[ "Parse", "the", "content", "of", "a", "SQLite", "file", "representing", "a", "list", "of", "words", "." ]
121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7
https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists/Wordlist.php#L145-L210
train
Erebot/Module_Wordlists
src/Wordlists/Wordlist.php
Wordlist.count
public function count() { $this->countQuery->execute(); $res = $this->countQuery->fetchColumn(); $this->countQuery->closeCursor(); return (int) $res; }
php
public function count() { $this->countQuery->execute(); $res = $this->countQuery->fetchColumn(); $this->countQuery->closeCursor(); return (int) $res; }
[ "public", "function", "count", "(", ")", "{", "$", "this", "->", "countQuery", "->", "execute", "(", ")", ";", "$", "res", "=", "$", "this", "->", "countQuery", "->", "fetchColumn", "(", ")", ";", "$", "this", "->", "countQuery", "->", "closeCursor", "(", ")", ";", "return", "(", "int", ")", "$", "res", ";", "}" ]
Returns the number of words in the list. \retval int Number of words in the list.
[ "Returns", "the", "number", "of", "words", "in", "the", "list", "." ]
121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7
https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists/Wordlist.php#L238-L244
train
Erebot/Module_Wordlists
src/Wordlists/Wordlist.php
Wordlist.findWord
public function findWord($word) { $key = $this->collator->getSortKey($word); /* In intl > 3.0.0a1, the key now ends with a trailing NUL byte. * We remove it for backward-compatibility with older releases. */ if (substr($key, -1) === "\0") { $key = substr($key, 0, -1); } $this->existsQuery->execute(array(':key' => $key)); $res = $this->existsQuery->fetchColumn(); $this->existsQuery->closeCursor(); if ($res === false || $res === null) { return null; } return $res; }
php
public function findWord($word) { $key = $this->collator->getSortKey($word); /* In intl > 3.0.0a1, the key now ends with a trailing NUL byte. * We remove it for backward-compatibility with older releases. */ if (substr($key, -1) === "\0") { $key = substr($key, 0, -1); } $this->existsQuery->execute(array(':key' => $key)); $res = $this->existsQuery->fetchColumn(); $this->existsQuery->closeCursor(); if ($res === false || $res === null) { return null; } return $res; }
[ "public", "function", "findWord", "(", "$", "word", ")", "{", "$", "key", "=", "$", "this", "->", "collator", "->", "getSortKey", "(", "$", "word", ")", ";", "/* In intl > 3.0.0a1, the key now ends with a trailing NUL byte.\n * We remove it for backward-compatibility with older releases. */", "if", "(", "substr", "(", "$", "key", ",", "-", "1", ")", "===", "\"\\0\"", ")", "{", "$", "key", "=", "substr", "(", "$", "key", ",", "0", ",", "-", "1", ")", ";", "}", "$", "this", "->", "existsQuery", "->", "execute", "(", "array", "(", "':key'", "=>", "$", "key", ")", ")", ";", "$", "res", "=", "$", "this", "->", "existsQuery", "->", "fetchColumn", "(", ")", ";", "$", "this", "->", "existsQuery", "->", "closeCursor", "(", ")", ";", "if", "(", "$", "res", "===", "false", "||", "$", "res", "===", "null", ")", "{", "return", "null", ";", "}", "return", "$", "res", ";", "}" ]
Look for a word in the list. \param string $word The word to look for. \retval mixed If the given word was found, it is returned as it appears in the list (this may include case or accentuation variations). Otherwise, \b null is returned.
[ "Look", "for", "a", "word", "in", "the", "list", "." ]
121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7
https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists/Wordlist.php#L258-L275
train
Erebot/Module_Wordlists
src/Wordlists/Wordlist.php
Wordlist.offsetGet
public function offsetGet($offset) { if (!is_int($offset)) { throw new \Erebot\InvalidValueException('An integer was expected'); } $this->getQuery->execute(array(':offset' => $offset)); $res = $this->getQuery->fetchColumn(); $this->getQuery->closeCursor(); if ($res == '' || $res === null || $res === false) { return null; } return $res; }
php
public function offsetGet($offset) { if (!is_int($offset)) { throw new \Erebot\InvalidValueException('An integer was expected'); } $this->getQuery->execute(array(':offset' => $offset)); $res = $this->getQuery->fetchColumn(); $this->getQuery->closeCursor(); if ($res == '' || $res === null || $res === false) { return null; } return $res; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "if", "(", "!", "is_int", "(", "$", "offset", ")", ")", "{", "throw", "new", "\\", "Erebot", "\\", "InvalidValueException", "(", "'An integer was expected'", ")", ";", "}", "$", "this", "->", "getQuery", "->", "execute", "(", "array", "(", "':offset'", "=>", "$", "offset", ")", ")", ";", "$", "res", "=", "$", "this", "->", "getQuery", "->", "fetchColumn", "(", ")", ";", "$", "this", "->", "getQuery", "->", "closeCursor", "(", ")", ";", "if", "(", "$", "res", "==", "''", "||", "$", "res", "===", "null", "||", "$", "res", "===", "false", ")", "{", "return", "null", ";", "}", "return", "$", "res", ";", "}" ]
Returns the word at the given offset. \param int $offset Offset of the word to retrieve. \retval string The word at the given $offset. \throw Erebot::InvalidValueException The given offset is not an integer.
[ "Returns", "the", "word", "at", "the", "given", "offset", "." ]
121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7
https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists/Wordlist.php#L308-L322
train
Erebot/Module_Wordlists
src/Wordlists/Wordlist.php
Wordlist.getMetadata
public function getMetadata($type) { // Handle special cases here: name and path to file. if ($type == self::METADATA_NAME) { return $this->name; } if ($type == self::METADATA_FILE) { return $this->file; } if (!array_key_exists($type, $this->metadata)) { throw new \Erebot\InvalidValueException( 'Invalid metadata type "' . $type . '"' ); } return $this->metadata[$type]; }
php
public function getMetadata($type) { // Handle special cases here: name and path to file. if ($type == self::METADATA_NAME) { return $this->name; } if ($type == self::METADATA_FILE) { return $this->file; } if (!array_key_exists($type, $this->metadata)) { throw new \Erebot\InvalidValueException( 'Invalid metadata type "' . $type . '"' ); } return $this->metadata[$type]; }
[ "public", "function", "getMetadata", "(", "$", "type", ")", "{", "// Handle special cases here: name and path to file.", "if", "(", "$", "type", "==", "self", "::", "METADATA_NAME", ")", "{", "return", "$", "this", "->", "name", ";", "}", "if", "(", "$", "type", "==", "self", "::", "METADATA_FILE", ")", "{", "return", "$", "this", "->", "file", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "type", ",", "$", "this", "->", "metadata", ")", ")", "{", "throw", "new", "\\", "Erebot", "\\", "InvalidValueException", "(", "'Invalid metadata type \"'", ".", "$", "type", ".", "'\"'", ")", ";", "}", "return", "$", "this", "->", "metadata", "[", "$", "type", "]", ";", "}" ]
Returns metadata associated with the list. \param string $type Type of metadata to return. See the constants named METADATA_* from this class for valid types. \retval mixed The requested metadata. This is a string for types that accept a single value (or \b null if the list does not provide any value) or an array for multi-valued types (an empty array may be returned in case the list does not provide any value). \throw Erebot::InvalidValueException The given metadata type is invalid.
[ "Returns", "metadata", "associated", "with", "the", "list", "." ]
121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7
https://github.com/Erebot/Module_Wordlists/blob/121d1cc72619ec0be2ddf0f3d6a66bac0a5bd1b7/src/Wordlists/Wordlist.php#L342-L358
train
irfantoor/database
src/Database/AbstractDatabase.php
AbstractDatabase.insert
public function insert($q, $data) { if (is_string($q)) { $this->defaults['table'] = $q; $q = []; } extract($this->defaults); extract($q); if (!$table) throw new Exception("table [$tabel] not defined", 1); $sql = 'INSERT INTO ' . $table . ' ' . '(' . implode(', ', array_keys($data)) . ') ' . 'VALUES ( :' . implode(', :', array_keys($data)) . ');'; return $this->query($sql, $data); }
php
public function insert($q, $data) { if (is_string($q)) { $this->defaults['table'] = $q; $q = []; } extract($this->defaults); extract($q); if (!$table) throw new Exception("table [$tabel] not defined", 1); $sql = 'INSERT INTO ' . $table . ' ' . '(' . implode(', ', array_keys($data)) . ') ' . 'VALUES ( :' . implode(', :', array_keys($data)) . ');'; return $this->query($sql, $data); }
[ "public", "function", "insert", "(", "$", "q", ",", "$", "data", ")", "{", "if", "(", "is_string", "(", "$", "q", ")", ")", "{", "$", "this", "->", "defaults", "[", "'table'", "]", "=", "$", "q", ";", "$", "q", "=", "[", "]", ";", "}", "extract", "(", "$", "this", "->", "defaults", ")", ";", "extract", "(", "$", "q", ")", ";", "if", "(", "!", "$", "table", ")", "throw", "new", "Exception", "(", "\"table [$tabel] not defined\"", ",", "1", ")", ";", "$", "sql", "=", "'INSERT INTO '", ".", "$", "table", ".", "' '", ".", "'('", ".", "implode", "(", "', '", ",", "array_keys", "(", "$", "data", ")", ")", ".", "') '", ".", "'VALUES ( :'", ".", "implode", "(", "', :'", ",", "array_keys", "(", "$", "data", ")", ")", ".", "');'", ";", "return", "$", "this", "->", "query", "(", "$", "sql", ",", "$", "data", ")", ";", "}" ]
inserts a record @param string|array $q name of table or array containg additional information as well @param array $data associative array with binding data
[ "inserts", "a", "record" ]
0e01e2f265b95f17b1a888137c4364714c367128
https://github.com/irfantoor/database/blob/0e01e2f265b95f17b1a888137c4364714c367128/src/Database/AbstractDatabase.php#L102-L119
train
irfantoor/database
src/Database/AbstractDatabase.php
AbstractDatabase.query
public function query($sql, $data = []) { $this->_init(); try { $q = $this->db->prepare($sql); } catch (PDOException $e) { throw new Exception($e->getMessage()); } foreach ($data as $k => $v) { $$k = $v; $q->bindParam(':' . $k, $$k); # bindParam( ... , PDO::PARAM_INT ...); } $result = $q->execute(); if (strpos(trim(strtoupper($sql)), 'SELECT') === 0) { $rows = []; while($row = $q->fetch()) { $rows[] = $row; } return $rows; } return $result; }
php
public function query($sql, $data = []) { $this->_init(); try { $q = $this->db->prepare($sql); } catch (PDOException $e) { throw new Exception($e->getMessage()); } foreach ($data as $k => $v) { $$k = $v; $q->bindParam(':' . $k, $$k); # bindParam( ... , PDO::PARAM_INT ...); } $result = $q->execute(); if (strpos(trim(strtoupper($sql)), 'SELECT') === 0) { $rows = []; while($row = $q->fetch()) { $rows[] = $row; } return $rows; } return $result; }
[ "public", "function", "query", "(", "$", "sql", ",", "$", "data", "=", "[", "]", ")", "{", "$", "this", "->", "_init", "(", ")", ";", "try", "{", "$", "q", "=", "$", "this", "->", "db", "->", "prepare", "(", "$", "sql", ")", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "throw", "new", "Exception", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "$", "k", "=", "$", "v", ";", "$", "q", "->", "bindParam", "(", "':'", ".", "$", "k", ",", "$", "$", "k", ")", ";", "# bindParam( ... , PDO::PARAM_INT ...);", "}", "$", "result", "=", "$", "q", "->", "execute", "(", ")", ";", "if", "(", "strpos", "(", "trim", "(", "strtoupper", "(", "$", "sql", ")", ")", ",", "'SELECT'", ")", "===", "0", ")", "{", "$", "rows", "=", "[", "]", ";", "while", "(", "$", "row", "=", "$", "q", "->", "fetch", "(", ")", ")", "{", "$", "rows", "[", "]", "=", "$", "row", ";", "}", "return", "$", "rows", ";", "}", "return", "$", "result", ";", "}" ]
Verifies if a condition can return records @param string $where
[ "Verifies", "if", "a", "condition", "can", "return", "records" ]
0e01e2f265b95f17b1a888137c4364714c367128
https://github.com/irfantoor/database/blob/0e01e2f265b95f17b1a888137c4364714c367128/src/Database/AbstractDatabase.php#L197-L223
train
koolkode/context
src/Scope/ScopedProxyGenerator.php
ScopedProxyGenerator.generateProxyCode
public function generateProxyCode(\ReflectionClass $ref) { $methods = $this->collectProxyMethods($ref); $implements = ['\KoolKode\Context\Scope\ScopedProxyInterface']; $code = 'namespace ' . $ref->getNamespaceName() . ' { '; $code .= 'if(!class_exists(' . var_export($ref->name . '__scoped', true) . ', false)) { '; $code .= 'final class ' . $ref->getShortName() . '__scoped'; if($ref->isInterface()) { $implements[] = '\\' . $ref->name; } else { $code .= ' extends \\' . $ref->name; } $code .= ' implements ' . implode(', ', $implements) . ' { '; $code .= 'use \KoolKode\Context\Scope\ScopedProxyTrait; '; $code .= 'private $__K2Binding, $__K2Scope, $__K2Target; '; $code .= 'public final function __construct(\KoolKode\Context\Bind\BindingInterface $binding, \KoolKode\Context\Scope\ScopeManagerInterface $scope, \SplObjectStorage & $target) { '; $code .= '$this->__K2Binding = $binding; $this->__K2Scope = $scope; $this->__K2Target = & $target; '; $fieldNames = array_unique($this->collectRemovedFieldNames($ref)); if(!empty($fieldNames)) { $code .= ' unset('; foreach($fieldNames as $i => $name) { if($i != 0) { $code .= ', '; } $code .= '$this->' . $name; } $code .= ');'; } $code.= ' } '; foreach($methods as $method) { $code .= $this->buildMethodSignature($method, true); $code .= ' { '; $code .= 'if(!$this->__K2Target->offsetExists($this)) { $this->__K2Scope->activateInstance($this); } '; $code .= 'return call_user_func_array([$this->__K2Target[$this], __FUNCTION__], func_get_args()); '; $code .= '} '; } return $code . ' } } } '; }
php
public function generateProxyCode(\ReflectionClass $ref) { $methods = $this->collectProxyMethods($ref); $implements = ['\KoolKode\Context\Scope\ScopedProxyInterface']; $code = 'namespace ' . $ref->getNamespaceName() . ' { '; $code .= 'if(!class_exists(' . var_export($ref->name . '__scoped', true) . ', false)) { '; $code .= 'final class ' . $ref->getShortName() . '__scoped'; if($ref->isInterface()) { $implements[] = '\\' . $ref->name; } else { $code .= ' extends \\' . $ref->name; } $code .= ' implements ' . implode(', ', $implements) . ' { '; $code .= 'use \KoolKode\Context\Scope\ScopedProxyTrait; '; $code .= 'private $__K2Binding, $__K2Scope, $__K2Target; '; $code .= 'public final function __construct(\KoolKode\Context\Bind\BindingInterface $binding, \KoolKode\Context\Scope\ScopeManagerInterface $scope, \SplObjectStorage & $target) { '; $code .= '$this->__K2Binding = $binding; $this->__K2Scope = $scope; $this->__K2Target = & $target; '; $fieldNames = array_unique($this->collectRemovedFieldNames($ref)); if(!empty($fieldNames)) { $code .= ' unset('; foreach($fieldNames as $i => $name) { if($i != 0) { $code .= ', '; } $code .= '$this->' . $name; } $code .= ');'; } $code.= ' } '; foreach($methods as $method) { $code .= $this->buildMethodSignature($method, true); $code .= ' { '; $code .= 'if(!$this->__K2Target->offsetExists($this)) { $this->__K2Scope->activateInstance($this); } '; $code .= 'return call_user_func_array([$this->__K2Target[$this], __FUNCTION__], func_get_args()); '; $code .= '} '; } return $code . ' } } } '; }
[ "public", "function", "generateProxyCode", "(", "\\", "ReflectionClass", "$", "ref", ")", "{", "$", "methods", "=", "$", "this", "->", "collectProxyMethods", "(", "$", "ref", ")", ";", "$", "implements", "=", "[", "'\\KoolKode\\Context\\Scope\\ScopedProxyInterface'", "]", ";", "$", "code", "=", "'namespace '", ".", "$", "ref", "->", "getNamespaceName", "(", ")", ".", "' { '", ";", "$", "code", ".=", "'if(!class_exists('", ".", "var_export", "(", "$", "ref", "->", "name", ".", "'__scoped'", ",", "true", ")", ".", "', false)) { '", ";", "$", "code", ".=", "'final class '", ".", "$", "ref", "->", "getShortName", "(", ")", ".", "'__scoped'", ";", "if", "(", "$", "ref", "->", "isInterface", "(", ")", ")", "{", "$", "implements", "[", "]", "=", "'\\\\'", ".", "$", "ref", "->", "name", ";", "}", "else", "{", "$", "code", ".=", "' extends \\\\'", ".", "$", "ref", "->", "name", ";", "}", "$", "code", ".=", "' implements '", ".", "implode", "(", "', '", ",", "$", "implements", ")", ".", "' { '", ";", "$", "code", ".=", "'use \\KoolKode\\Context\\Scope\\ScopedProxyTrait; '", ";", "$", "code", ".=", "'private $__K2Binding, $__K2Scope, $__K2Target; '", ";", "$", "code", ".=", "'public final function __construct(\\KoolKode\\Context\\Bind\\BindingInterface $binding, \\KoolKode\\Context\\Scope\\ScopeManagerInterface $scope, \\SplObjectStorage & $target) { '", ";", "$", "code", ".=", "'$this->__K2Binding = $binding; $this->__K2Scope = $scope; $this->__K2Target = & $target; '", ";", "$", "fieldNames", "=", "array_unique", "(", "$", "this", "->", "collectRemovedFieldNames", "(", "$", "ref", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "fieldNames", ")", ")", "{", "$", "code", ".=", "' unset('", ";", "foreach", "(", "$", "fieldNames", "as", "$", "i", "=>", "$", "name", ")", "{", "if", "(", "$", "i", "!=", "0", ")", "{", "$", "code", ".=", "', '", ";", "}", "$", "code", ".=", "'$this->'", ".", "$", "name", ";", "}", "$", "code", ".=", "');'", ";", "}", "$", "code", ".=", "' } '", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "$", "code", ".=", "$", "this", "->", "buildMethodSignature", "(", "$", "method", ",", "true", ")", ";", "$", "code", ".=", "' { '", ";", "$", "code", ".=", "'if(!$this->__K2Target->offsetExists($this)) { $this->__K2Scope->activateInstance($this); } '", ";", "$", "code", ".=", "'return call_user_func_array([$this->__K2Target[$this], __FUNCTION__], func_get_args()); '", ";", "$", "code", ".=", "'} '", ";", "}", "return", "$", "code", ".", "' } } } '", ";", "}" ]
Generates the PHP code of a scoped proxy for the given type. @param \ReflectionClass $type @return string
[ "Generates", "the", "PHP", "code", "of", "a", "scoped", "proxy", "for", "the", "given", "type", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Scope/ScopedProxyGenerator.php#L31-L89
train
koolkode/context
src/Scope/ScopedProxyGenerator.php
ScopedProxyGenerator.collectProxyMethods
protected function collectProxyMethods(\ReflectionClass $ref) { $methods = []; foreach($ref->getMethods() as $method) { if($method->isStatic() || $method->isPrivate()) { continue; } if(substr($method->getName(), 0, 2) == '__') { continue; } if($method->isFinal()) { throw new ScopedProxyException(sprintf('Unable to build scoped proxy due to final method %s->%s()', $ref->getName(), $method->getName())); } $methods[strtolower($method->getName())] = $method; } return $methods; }
php
protected function collectProxyMethods(\ReflectionClass $ref) { $methods = []; foreach($ref->getMethods() as $method) { if($method->isStatic() || $method->isPrivate()) { continue; } if(substr($method->getName(), 0, 2) == '__') { continue; } if($method->isFinal()) { throw new ScopedProxyException(sprintf('Unable to build scoped proxy due to final method %s->%s()', $ref->getName(), $method->getName())); } $methods[strtolower($method->getName())] = $method; } return $methods; }
[ "protected", "function", "collectProxyMethods", "(", "\\", "ReflectionClass", "$", "ref", ")", "{", "$", "methods", "=", "[", "]", ";", "foreach", "(", "$", "ref", "->", "getMethods", "(", ")", "as", "$", "method", ")", "{", "if", "(", "$", "method", "->", "isStatic", "(", ")", "||", "$", "method", "->", "isPrivate", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "substr", "(", "$", "method", "->", "getName", "(", ")", ",", "0", ",", "2", ")", "==", "'__'", ")", "{", "continue", ";", "}", "if", "(", "$", "method", "->", "isFinal", "(", ")", ")", "{", "throw", "new", "ScopedProxyException", "(", "sprintf", "(", "'Unable to build scoped proxy due to final method %s->%s()'", ",", "$", "ref", "->", "getName", "(", ")", ",", "$", "method", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "methods", "[", "strtolower", "(", "$", "method", "->", "getName", "(", ")", ")", "]", "=", "$", "method", ";", "}", "return", "$", "methods", ";", "}" ]
Collects all public instance methods of the given type using reflection. @param \ReflectionClass $ref @return array<string, \ReflectionMethod> @throws ScopedProxyException
[ "Collects", "all", "public", "instance", "methods", "of", "the", "given", "type", "using", "reflection", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Scope/ScopedProxyGenerator.php#L99-L124
train
fulgurio/LightCMSBundle
DataFixtures/ORM/LoadHomePage.php
LoadHomePage.addMeta
private function addMeta($page, $key, $value) { $meta = new PageMeta(); $meta->setMetaKey($key); $meta->setMetaValue($value); $meta->setPage($page); return $meta; }
php
private function addMeta($page, $key, $value) { $meta = new PageMeta(); $meta->setMetaKey($key); $meta->setMetaValue($value); $meta->setPage($page); return $meta; }
[ "private", "function", "addMeta", "(", "$", "page", ",", "$", "key", ",", "$", "value", ")", "{", "$", "meta", "=", "new", "PageMeta", "(", ")", ";", "$", "meta", "->", "setMetaKey", "(", "$", "key", ")", ";", "$", "meta", "->", "setMetaValue", "(", "$", "value", ")", ";", "$", "meta", "->", "setPage", "(", "$", "page", ")", ";", "return", "$", "meta", ";", "}" ]
Add meta to page @param \Fulgurio\LightCMSBundle\Entity\Page $page @param string $key @param string $value @return \Fulgurio\LightCMSBundle\Entity\PageMeta
[ "Add", "meta", "to", "page" ]
66319af52b97b6552b7c391ee370538263f42d10
https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/DataFixtures/ORM/LoadHomePage.php#L64-L71
train
PenoaksDev/Milky-Framework
src/Milky/Cache/RedisTaggedCache.php
RedisTaggedCache.pushKeys
protected function pushKeys( $namespace, $key, $reference ) { $fullKey = $this->getPrefix() . sha1( $namespace ) . ':' . $key; foreach ( explode( '|', $namespace ) as $segment ) { $this->store->connection()->sadd( $this->referenceKey( $segment, $reference ), $fullKey ); } }
php
protected function pushKeys( $namespace, $key, $reference ) { $fullKey = $this->getPrefix() . sha1( $namespace ) . ':' . $key; foreach ( explode( '|', $namespace ) as $segment ) { $this->store->connection()->sadd( $this->referenceKey( $segment, $reference ), $fullKey ); } }
[ "protected", "function", "pushKeys", "(", "$", "namespace", ",", "$", "key", ",", "$", "reference", ")", "{", "$", "fullKey", "=", "$", "this", "->", "getPrefix", "(", ")", ".", "sha1", "(", "$", "namespace", ")", ".", "':'", ".", "$", "key", ";", "foreach", "(", "explode", "(", "'|'", ",", "$", "namespace", ")", "as", "$", "segment", ")", "{", "$", "this", "->", "store", "->", "connection", "(", ")", "->", "sadd", "(", "$", "this", "->", "referenceKey", "(", "$", "segment", ",", "$", "reference", ")", ",", "$", "fullKey", ")", ";", "}", "}" ]
Store a reference to the cache key against the reference key. @param string $namespace @param string $key @param string $reference
[ "Store", "a", "reference", "to", "the", "cache", "key", "against", "the", "reference", "key", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Cache/RedisTaggedCache.php#L86-L94
train
mvccore/ext-router-media
src/MvcCore/Ext/Routers/Media/UrlByRouteSectionsMedia.php
UrlByRouteSectionsMedia.urlByRouteSectionsMedia
protected function urlByRouteSectionsMedia (\MvcCore\IRoute & $route, array & $params = [], array & $defaultParams = [], $routeMethod = NULL) { // separate `$mediaSiteVersion` from `$params` to work with the version more specifically $mediaVersionUrlParam = static::URL_PARAM_MEDIA_VERSION; if (isset($params[$mediaVersionUrlParam])) { $mediaSiteVersion = $params[$mediaVersionUrlParam]; unset($params[$mediaVersionUrlParam]); } else if (isset($defaultParams[$mediaVersionUrlParam])) { $mediaSiteVersion = $defaultParams[$mediaVersionUrlParam]; unset($defaultParams[$mediaVersionUrlParam]); } else { $mediaSiteVersion = $this->mediaSiteVersion; } // get url version value from application value (only for allowed request types) $routeMethod = $route->GetMethod(); if ($this->routeGetRequestsOnly && $routeMethod !== NULL && $routeMethod !== \MvcCore\IRequest::METHOD_GET) { $mediaSiteUrlValue = NULL; } else if (isset($this->allowedMediaVersionsAndUrlValues[$mediaSiteVersion])) { $mediaSiteUrlValue = $this->allowedMediaVersionsAndUrlValues[$mediaSiteVersion]; } else { $mediaSiteUrlValue = NULL; $selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__; trigger_error( '['.$selfClass.'] Not allowed media site version used to generate url: `' .$mediaSiteVersion.'`. Allowed values: `' .implode('`, `', array_keys($this->allowedMediaVersionsAndUrlValues)) . '`.', E_USER_ERROR ); } // add special switching param to global get, if strict session mode and target version is different if ($this->stricModeBySession && $mediaSiteVersion !== NULL && $mediaSiteVersion !== $this->mediaSiteVersion) $params[static::URL_PARAM_SWITCH_MEDIA_VERSION] = $mediaSiteVersion; return [$mediaVersionUrlParam, $mediaSiteUrlValue]; }
php
protected function urlByRouteSectionsMedia (\MvcCore\IRoute & $route, array & $params = [], array & $defaultParams = [], $routeMethod = NULL) { // separate `$mediaSiteVersion` from `$params` to work with the version more specifically $mediaVersionUrlParam = static::URL_PARAM_MEDIA_VERSION; if (isset($params[$mediaVersionUrlParam])) { $mediaSiteVersion = $params[$mediaVersionUrlParam]; unset($params[$mediaVersionUrlParam]); } else if (isset($defaultParams[$mediaVersionUrlParam])) { $mediaSiteVersion = $defaultParams[$mediaVersionUrlParam]; unset($defaultParams[$mediaVersionUrlParam]); } else { $mediaSiteVersion = $this->mediaSiteVersion; } // get url version value from application value (only for allowed request types) $routeMethod = $route->GetMethod(); if ($this->routeGetRequestsOnly && $routeMethod !== NULL && $routeMethod !== \MvcCore\IRequest::METHOD_GET) { $mediaSiteUrlValue = NULL; } else if (isset($this->allowedMediaVersionsAndUrlValues[$mediaSiteVersion])) { $mediaSiteUrlValue = $this->allowedMediaVersionsAndUrlValues[$mediaSiteVersion]; } else { $mediaSiteUrlValue = NULL; $selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__; trigger_error( '['.$selfClass.'] Not allowed media site version used to generate url: `' .$mediaSiteVersion.'`. Allowed values: `' .implode('`, `', array_keys($this->allowedMediaVersionsAndUrlValues)) . '`.', E_USER_ERROR ); } // add special switching param to global get, if strict session mode and target version is different if ($this->stricModeBySession && $mediaSiteVersion !== NULL && $mediaSiteVersion !== $this->mediaSiteVersion) $params[static::URL_PARAM_SWITCH_MEDIA_VERSION] = $mediaSiteVersion; return [$mediaVersionUrlParam, $mediaSiteUrlValue]; }
[ "protected", "function", "urlByRouteSectionsMedia", "(", "\\", "MvcCore", "\\", "IRoute", "&", "$", "route", ",", "array", "&", "$", "params", "=", "[", "]", ",", "array", "&", "$", "defaultParams", "=", "[", "]", ",", "$", "routeMethod", "=", "NULL", ")", "{", "// separate `$mediaSiteVersion` from `$params` to work with the version more specifically", "$", "mediaVersionUrlParam", "=", "static", "::", "URL_PARAM_MEDIA_VERSION", ";", "if", "(", "isset", "(", "$", "params", "[", "$", "mediaVersionUrlParam", "]", ")", ")", "{", "$", "mediaSiteVersion", "=", "$", "params", "[", "$", "mediaVersionUrlParam", "]", ";", "unset", "(", "$", "params", "[", "$", "mediaVersionUrlParam", "]", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "defaultParams", "[", "$", "mediaVersionUrlParam", "]", ")", ")", "{", "$", "mediaSiteVersion", "=", "$", "defaultParams", "[", "$", "mediaVersionUrlParam", "]", ";", "unset", "(", "$", "defaultParams", "[", "$", "mediaVersionUrlParam", "]", ")", ";", "}", "else", "{", "$", "mediaSiteVersion", "=", "$", "this", "->", "mediaSiteVersion", ";", "}", "// get url version value from application value (only for allowed request types)", "$", "routeMethod", "=", "$", "route", "->", "GetMethod", "(", ")", ";", "if", "(", "$", "this", "->", "routeGetRequestsOnly", "&&", "$", "routeMethod", "!==", "NULL", "&&", "$", "routeMethod", "!==", "\\", "MvcCore", "\\", "IRequest", "::", "METHOD_GET", ")", "{", "$", "mediaSiteUrlValue", "=", "NULL", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "allowedMediaVersionsAndUrlValues", "[", "$", "mediaSiteVersion", "]", ")", ")", "{", "$", "mediaSiteUrlValue", "=", "$", "this", "->", "allowedMediaVersionsAndUrlValues", "[", "$", "mediaSiteVersion", "]", ";", "}", "else", "{", "$", "mediaSiteUrlValue", "=", "NULL", ";", "$", "selfClass", "=", "version_compare", "(", "PHP_VERSION", ",", "'5.5'", ",", "'>'", ")", "?", "self", "::", "class", ":", "__CLASS__", ";", "trigger_error", "(", "'['", ".", "$", "selfClass", ".", "'] Not allowed media site version used to generate url: `'", ".", "$", "mediaSiteVersion", ".", "'`. Allowed values: `'", ".", "implode", "(", "'`, `'", ",", "array_keys", "(", "$", "this", "->", "allowedMediaVersionsAndUrlValues", ")", ")", ".", "'`.'", ",", "E_USER_ERROR", ")", ";", "}", "// add special switching param to global get, if strict session mode and target version is different", "if", "(", "$", "this", "->", "stricModeBySession", "&&", "$", "mediaSiteVersion", "!==", "NULL", "&&", "$", "mediaSiteVersion", "!==", "$", "this", "->", "mediaSiteVersion", ")", "$", "params", "[", "static", "::", "URL_PARAM_SWITCH_MEDIA_VERSION", "]", "=", "$", "mediaSiteVersion", ";", "return", "[", "$", "mediaVersionUrlParam", ",", "$", "mediaSiteUrlValue", "]", ";", "}" ]
Return media site version for result URL as media site version param name string and media site version param value string. If media site version is specified in given params array, return this media site version. If there is not any specific media site version in params array, try to look into given default params array and if there is also nothing, use current media site version from router (which could be from session or from request). Change params array and add special media site version switch param when router is configured to hold media site version strictly in session. But do not return any media site version for not allowed route methods and do not return any not allowed values for media site version. @param \MvcCore\Route|\MvcCore\IRoute $route @param array $params @param string|NULL $routeMethod @return array `[string $mediaVersionUrlParam, string $mediaSiteUrlValue]`
[ "Return", "media", "site", "version", "for", "result", "URL", "as", "media", "site", "version", "param", "name", "string", "and", "media", "site", "version", "param", "value", "string", "." ]
976e83290cf25ad6bc32e4824790b5e0d5d4c08b
https://github.com/mvccore/ext-router-media/blob/976e83290cf25ad6bc32e4824790b5e0d5d4c08b/src/MvcCore/Ext/Routers/Media/UrlByRouteSectionsMedia.php#L36-L70
train
bseries/cms_core
extensions/helper/Editor.php
Editor.field
public function field($name, array $options = []) { $options += [ 'features' => null, 'size' => 'beta', 'help' => true ]; $classes = []; $classes[] = 'use-editor'; $classes[] = 'editor-size--' . $options['size']; if (is_string($options['features'])) { $options['features'] = Settings::read('editor.features.' . $options['features']); } foreach ($options['features'] as $feature) { $classes[] = 'editor-' . $feature; } $options['type'] = 'textarea'; $options['wrap'] = ['class' => implode(' ', $classes)]; unset($options['features']); unset($options['size']); // We must preprocess the value, as inline media might change its // URLs. This happens when versions are regenerated. // // Invalid media URLs are not really a problem as the media ID // is dictating what is been display in the app part. // // @see lithium\template\helper\Form::_defaults() if (!empty($options['value'])) { $value = $options['value']; } else { $value = $this->_context->form->binding($name)->data; } $value = $this->parse($value, [ 'mediaVersion' => 'fix2admin' ]); $html = $this->_context->form->field($name, compact('value') + $options); if ($options['help']) { extract(Message::aliases()); // Insert *into* fields array by replacing last closing div. $help = '<div class="help">' . $t('ENTER for paragraphs, SHIFT+ENTER for hard line breaks', ['scope' => 'cms_core']). '</div>'; $html = str_replace('</div>', $help . '</div>', $html); } return $html; }
php
public function field($name, array $options = []) { $options += [ 'features' => null, 'size' => 'beta', 'help' => true ]; $classes = []; $classes[] = 'use-editor'; $classes[] = 'editor-size--' . $options['size']; if (is_string($options['features'])) { $options['features'] = Settings::read('editor.features.' . $options['features']); } foreach ($options['features'] as $feature) { $classes[] = 'editor-' . $feature; } $options['type'] = 'textarea'; $options['wrap'] = ['class' => implode(' ', $classes)]; unset($options['features']); unset($options['size']); // We must preprocess the value, as inline media might change its // URLs. This happens when versions are regenerated. // // Invalid media URLs are not really a problem as the media ID // is dictating what is been display in the app part. // // @see lithium\template\helper\Form::_defaults() if (!empty($options['value'])) { $value = $options['value']; } else { $value = $this->_context->form->binding($name)->data; } $value = $this->parse($value, [ 'mediaVersion' => 'fix2admin' ]); $html = $this->_context->form->field($name, compact('value') + $options); if ($options['help']) { extract(Message::aliases()); // Insert *into* fields array by replacing last closing div. $help = '<div class="help">' . $t('ENTER for paragraphs, SHIFT+ENTER for hard line breaks', ['scope' => 'cms_core']). '</div>'; $html = str_replace('</div>', $help . '</div>', $html); } return $html; }
[ "public", "function", "field", "(", "$", "name", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "+=", "[", "'features'", "=>", "null", ",", "'size'", "=>", "'beta'", ",", "'help'", "=>", "true", "]", ";", "$", "classes", "=", "[", "]", ";", "$", "classes", "[", "]", "=", "'use-editor'", ";", "$", "classes", "[", "]", "=", "'editor-size--'", ".", "$", "options", "[", "'size'", "]", ";", "if", "(", "is_string", "(", "$", "options", "[", "'features'", "]", ")", ")", "{", "$", "options", "[", "'features'", "]", "=", "Settings", "::", "read", "(", "'editor.features.'", ".", "$", "options", "[", "'features'", "]", ")", ";", "}", "foreach", "(", "$", "options", "[", "'features'", "]", "as", "$", "feature", ")", "{", "$", "classes", "[", "]", "=", "'editor-'", ".", "$", "feature", ";", "}", "$", "options", "[", "'type'", "]", "=", "'textarea'", ";", "$", "options", "[", "'wrap'", "]", "=", "[", "'class'", "=>", "implode", "(", "' '", ",", "$", "classes", ")", "]", ";", "unset", "(", "$", "options", "[", "'features'", "]", ")", ";", "unset", "(", "$", "options", "[", "'size'", "]", ")", ";", "// We must preprocess the value, as inline media might change its", "// URLs. This happens when versions are regenerated.", "//", "// Invalid media URLs are not really a problem as the media ID", "// is dictating what is been display in the app part.", "//", "// @see lithium\\template\\helper\\Form::_defaults()", "if", "(", "!", "empty", "(", "$", "options", "[", "'value'", "]", ")", ")", "{", "$", "value", "=", "$", "options", "[", "'value'", "]", ";", "}", "else", "{", "$", "value", "=", "$", "this", "->", "_context", "->", "form", "->", "binding", "(", "$", "name", ")", "->", "data", ";", "}", "$", "value", "=", "$", "this", "->", "parse", "(", "$", "value", ",", "[", "'mediaVersion'", "=>", "'fix2admin'", "]", ")", ";", "$", "html", "=", "$", "this", "->", "_context", "->", "form", "->", "field", "(", "$", "name", ",", "compact", "(", "'value'", ")", "+", "$", "options", ")", ";", "if", "(", "$", "options", "[", "'help'", "]", ")", "{", "extract", "(", "Message", "::", "aliases", "(", ")", ")", ";", "// Insert *into* fields array by replacing last closing div.", "$", "help", "=", "'<div class=\"help\">'", ".", "$", "t", "(", "'ENTER for paragraphs, SHIFT+ENTER for hard line breaks'", ",", "[", "'scope'", "=>", "'cms_core'", "]", ")", ".", "'</div>'", ";", "$", "html", "=", "str_replace", "(", "'</div>'", ",", "$", "help", ".", "'</div>'", ",", "$", "html", ")", ";", "}", "return", "$", "html", ";", "}" ]
as `features`.
[ "as", "features", "." ]
5a2b861de6916cad83512d20f790068ffa41319e
https://github.com/bseries/cms_core/blob/5a2b861de6916cad83512d20f790068ffa41319e/extensions/helper/Editor.php#L26-L74
train
MindyPHP/OrmNestedSet
TreeModel.php
TreeModel.save
public function save(array $fields = []) { if ($this->getIsNewRecord()) { if ($this->parent) { $this->appendTo($this->parent); } else { $this->makeRoot(); } return parent::save($fields); } if (in_array('parent_id', $this->getDirtyAttributes())) { $saved = parent::save($fields); if ($saved) { if ($this->parent) { $this->moveAsLast($this->parent); } elseif ($this->isRoot()) { $this->moveAsRoot(); } /** @var array $parent */ $parent = $this->objects()->asArray()->get(['pk' => $this->pk]); if (null !== $parent) { $this->setAttributes($parent); $this->setIsNewRecord(false); } return $saved; } return $saved; } return parent::save($fields); }
php
public function save(array $fields = []) { if ($this->getIsNewRecord()) { if ($this->parent) { $this->appendTo($this->parent); } else { $this->makeRoot(); } return parent::save($fields); } if (in_array('parent_id', $this->getDirtyAttributes())) { $saved = parent::save($fields); if ($saved) { if ($this->parent) { $this->moveAsLast($this->parent); } elseif ($this->isRoot()) { $this->moveAsRoot(); } /** @var array $parent */ $parent = $this->objects()->asArray()->get(['pk' => $this->pk]); if (null !== $parent) { $this->setAttributes($parent); $this->setIsNewRecord(false); } return $saved; } return $saved; } return parent::save($fields); }
[ "public", "function", "save", "(", "array", "$", "fields", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "getIsNewRecord", "(", ")", ")", "{", "if", "(", "$", "this", "->", "parent", ")", "{", "$", "this", "->", "appendTo", "(", "$", "this", "->", "parent", ")", ";", "}", "else", "{", "$", "this", "->", "makeRoot", "(", ")", ";", "}", "return", "parent", "::", "save", "(", "$", "fields", ")", ";", "}", "if", "(", "in_array", "(", "'parent_id'", ",", "$", "this", "->", "getDirtyAttributes", "(", ")", ")", ")", "{", "$", "saved", "=", "parent", "::", "save", "(", "$", "fields", ")", ";", "if", "(", "$", "saved", ")", "{", "if", "(", "$", "this", "->", "parent", ")", "{", "$", "this", "->", "moveAsLast", "(", "$", "this", "->", "parent", ")", ";", "}", "elseif", "(", "$", "this", "->", "isRoot", "(", ")", ")", "{", "$", "this", "->", "moveAsRoot", "(", ")", ";", "}", "/** @var array $parent */", "$", "parent", "=", "$", "this", "->", "objects", "(", ")", "->", "asArray", "(", ")", "->", "get", "(", "[", "'pk'", "=>", "$", "this", "->", "pk", "]", ")", ";", "if", "(", "null", "!==", "$", "parent", ")", "{", "$", "this", "->", "setAttributes", "(", "$", "parent", ")", ";", "$", "this", "->", "setIsNewRecord", "(", "false", ")", ";", "}", "return", "$", "saved", ";", "}", "return", "$", "saved", ";", "}", "return", "parent", "::", "save", "(", "$", "fields", ")", ";", "}" ]
Create root node if multiple-root tree mode. Update node if it's not new. @param array $fields @throws \Exception @return bool whether the saving succeeds
[ "Create", "root", "node", "if", "multiple", "-", "root", "tree", "mode", ".", "Update", "node", "if", "it", "s", "not", "new", "." ]
8231c55f9b95314789983c0b0ec83a9eb70adf79
https://github.com/MindyPHP/OrmNestedSet/blob/8231c55f9b95314789983c0b0ec83a9eb70adf79/TreeModel.php#L112-L147
train
MindyPHP/OrmNestedSet
TreeModel.php
TreeModel.moveAsRoot
public function moveAsRoot() { if ($this->getIsNewRecord()) { throw new Exception('The node should not be new record.'); } if ($this->isRoot()) { throw new Exception('The node already is root node.'); } $delta = 1 - $this->lft; $this ->objects() ->filter([ 'lft__gte' => $this->lft, 'rgt__lte' => $this->rgt, 'root' => $this->root, ]) ->update([ 'lft' => new Expression('lft' . sprintf('%+d', $delta)), 'rgt' => new Expression('rgt' . sprintf('%+d', $delta)), 'level' => new Expression('level' . sprintf('%+d', 1 - $this->level)), 'root' => $this->getMaxRoot(), ]); $this ->shiftLeftRight($this->rgt + 1, $this->lft - $this->rgt - 1); return $this; }
php
public function moveAsRoot() { if ($this->getIsNewRecord()) { throw new Exception('The node should not be new record.'); } if ($this->isRoot()) { throw new Exception('The node already is root node.'); } $delta = 1 - $this->lft; $this ->objects() ->filter([ 'lft__gte' => $this->lft, 'rgt__lte' => $this->rgt, 'root' => $this->root, ]) ->update([ 'lft' => new Expression('lft' . sprintf('%+d', $delta)), 'rgt' => new Expression('rgt' . sprintf('%+d', $delta)), 'level' => new Expression('level' . sprintf('%+d', 1 - $this->level)), 'root' => $this->getMaxRoot(), ]); $this ->shiftLeftRight($this->rgt + 1, $this->lft - $this->rgt - 1); return $this; }
[ "public", "function", "moveAsRoot", "(", ")", "{", "if", "(", "$", "this", "->", "getIsNewRecord", "(", ")", ")", "{", "throw", "new", "Exception", "(", "'The node should not be new record.'", ")", ";", "}", "if", "(", "$", "this", "->", "isRoot", "(", ")", ")", "{", "throw", "new", "Exception", "(", "'The node already is root node.'", ")", ";", "}", "$", "delta", "=", "1", "-", "$", "this", "->", "lft", ";", "$", "this", "->", "objects", "(", ")", "->", "filter", "(", "[", "'lft__gte'", "=>", "$", "this", "->", "lft", ",", "'rgt__lte'", "=>", "$", "this", "->", "rgt", ",", "'root'", "=>", "$", "this", "->", "root", ",", "]", ")", "->", "update", "(", "[", "'lft'", "=>", "new", "Expression", "(", "'lft'", ".", "sprintf", "(", "'%+d'", ",", "$", "delta", ")", ")", ",", "'rgt'", "=>", "new", "Expression", "(", "'rgt'", ".", "sprintf", "(", "'%+d'", ",", "$", "delta", ")", ")", ",", "'level'", "=>", "new", "Expression", "(", "'level'", ".", "sprintf", "(", "'%+d'", ",", "1", "-", "$", "this", "->", "level", ")", ")", ",", "'root'", "=>", "$", "this", "->", "getMaxRoot", "(", ")", ",", "]", ")", ";", "$", "this", "->", "shiftLeftRight", "(", "$", "this", "->", "rgt", "+", "1", ",", "$", "this", "->", "lft", "-", "$", "this", "->", "rgt", "-", "1", ")", ";", "return", "$", "this", ";", "}" ]
Move node as new root. @throws Exception @throws \Exception @return $this
[ "Move", "node", "as", "new", "root", "." ]
8231c55f9b95314789983c0b0ec83a9eb70adf79
https://github.com/MindyPHP/OrmNestedSet/blob/8231c55f9b95314789983c0b0ec83a9eb70adf79/TreeModel.php#L317-L346
train
MindyPHP/OrmNestedSet
TreeModel.php
TreeModel.isDescendantOf
public function isDescendantOf($subj) { return ($this->lft > $subj->lft) && ($this->rgt < $subj->rgt) && ($this->root === $subj->root); }
php
public function isDescendantOf($subj) { return ($this->lft > $subj->lft) && ($this->rgt < $subj->rgt) && ($this->root === $subj->root); }
[ "public", "function", "isDescendantOf", "(", "$", "subj", ")", "{", "return", "(", "$", "this", "->", "lft", ">", "$", "subj", "->", "lft", ")", "&&", "(", "$", "this", "->", "rgt", "<", "$", "subj", "->", "rgt", ")", "&&", "(", "$", "this", "->", "root", "===", "$", "subj", "->", "root", ")", ";", "}" ]
Determines if node is descendant of subject node. @param TreeModel $subj the subject node @return bool whether the node is descendant of subject node
[ "Determines", "if", "node", "is", "descendant", "of", "subject", "node", "." ]
8231c55f9b95314789983c0b0ec83a9eb70adf79
https://github.com/MindyPHP/OrmNestedSet/blob/8231c55f9b95314789983c0b0ec83a9eb70adf79/TreeModel.php#L355-L358
train
Fenzland/http-api-gluer
src/Gluer/TMakeInstance_.php
TMakeInstance_.make_
static public function make_( string $url , string $method , array $request_transformer_meta , array $response_transformer_meta , string $request_content_type , string $response_content_type= null ):self { return new static( $url , $method , Transformer::make_( $request_transformer_meta ) , Transformer::make_( $response_transformer_meta ) , $request_content_type , $response_content_type??$request_content_type ); }
php
static public function make_( string $url , string $method , array $request_transformer_meta , array $response_transformer_meta , string $request_content_type , string $response_content_type= null ):self { return new static( $url , $method , Transformer::make_( $request_transformer_meta ) , Transformer::make_( $response_transformer_meta ) , $request_content_type , $response_content_type??$request_content_type ); }
[ "static", "public", "function", "make_", "(", "string", "$", "url", ",", "string", "$", "method", ",", "array", "$", "request_transformer_meta", ",", "array", "$", "response_transformer_meta", ",", "string", "$", "request_content_type", ",", "string", "$", "response_content_type", "=", "null", ")", ":", "self", "{", "return", "new", "static", "(", "$", "url", ",", "$", "method", ",", "Transformer", "::", "make_", "(", "$", "request_transformer_meta", ")", ",", "Transformer", "::", "make_", "(", "$", "response_transformer_meta", ")", ",", "$", "request_content_type", ",", "$", "response_content_type", "??", "$", "request_content_type", ")", ";", "}" ]
Static method make_ @static @access public @param string $url @param string $method @param array $request_transformer_meta @param array $response_transformer_meta @param string $request_content_type @param string $response_content_type @return self
[ "Static", "method", "make_" ]
3488de28b7f54fb444ec47f84034473a7d86e17e
https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/TMakeInstance_.php#L29-L56
train
raframework/rapkg
src/Rapkg/Retry/Retry.php
Retry.checkOptions
private static function checkOptions($options) { if (!isset($options['retries']) || !is_int($options['retries']) || $options['retries'] <= 0) { throw new \InvalidArgumentException( 'retry: the options.retries must be an integer with a positive value' ); } if (!isset($options['interval']) || !is_float($options['interval']) || $options['interval'] <= 0.0) { throw new \InvalidArgumentException( 'retry: the options.interval must be a float with a positive value' ); } }
php
private static function checkOptions($options) { if (!isset($options['retries']) || !is_int($options['retries']) || $options['retries'] <= 0) { throw new \InvalidArgumentException( 'retry: the options.retries must be an integer with a positive value' ); } if (!isset($options['interval']) || !is_float($options['interval']) || $options['interval'] <= 0.0) { throw new \InvalidArgumentException( 'retry: the options.interval must be a float with a positive value' ); } }
[ "private", "static", "function", "checkOptions", "(", "$", "options", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'retries'", "]", ")", "||", "!", "is_int", "(", "$", "options", "[", "'retries'", "]", ")", "||", "$", "options", "[", "'retries'", "]", "<=", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'retry: the options.retries must be an integer with a positive value'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "options", "[", "'interval'", "]", ")", "||", "!", "is_float", "(", "$", "options", "[", "'interval'", "]", ")", "||", "$", "options", "[", "'interval'", "]", "<=", "0.0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'retry: the options.interval must be a float with a positive value'", ")", ";", "}", "}" ]
Check the options, throw an `InvalidArgumentException` on invalid format value. @param $options @throws \InvalidArgumentException
[ "Check", "the", "options", "throw", "an", "InvalidArgumentException", "on", "invalid", "format", "value", "." ]
7c4371911369d7c9d4463127bcd285144d7347ee
https://github.com/raframework/rapkg/blob/7c4371911369d7c9d4463127bcd285144d7347ee/src/Rapkg/Retry/Retry.php#L82-L94
train
kherge-abandoned/Entities
src/lib/KevinGH/Entities/EntitiesServiceProvider.php
EntitiesServiceProvider.createCache
public function createCache(Application $app) { $cache = new Pimple; foreach ($app['ems.options'] as $name => $options) { $cache[$name] = $cache->share( function () use ($app, $cache, $options) { $class = 'Doctrine\Common\Cache\\' . $options['caching_driver']; switch ($options['caching_driver']) { case 'ApcCache': case 'ArrayCache': case 'XcacheCache': return new $class(); case 'MemcacheCache': $cache = new $class(); if ((false === isset($app['memcache'])) && (false === isset($options['memcache']))) { throw new RuntimeException ( 'No Memcache client available as a service.' ); } $cache->setMemcache( isset($options['memcache']) ? $options['memcache'] : $app['memcache'] ); return $cache; case 'MemcachedCache': $cache = new $class(); if ((false === isset($app['memcached'])) && (false === isset($options['memcached']))) { throw new RuntimeException ( 'No Memcached client available as a service.' ); } $cache->setMemcached( isset($options['memcached']) ? $options['memcached'] : $app['memcached'] ); return $cache; default: throw new InvalidArgumentException ( "Unsupported cache class: $class" ); } } ); } return $cache; }
php
public function createCache(Application $app) { $cache = new Pimple; foreach ($app['ems.options'] as $name => $options) { $cache[$name] = $cache->share( function () use ($app, $cache, $options) { $class = 'Doctrine\Common\Cache\\' . $options['caching_driver']; switch ($options['caching_driver']) { case 'ApcCache': case 'ArrayCache': case 'XcacheCache': return new $class(); case 'MemcacheCache': $cache = new $class(); if ((false === isset($app['memcache'])) && (false === isset($options['memcache']))) { throw new RuntimeException ( 'No Memcache client available as a service.' ); } $cache->setMemcache( isset($options['memcache']) ? $options['memcache'] : $app['memcache'] ); return $cache; case 'MemcachedCache': $cache = new $class(); if ((false === isset($app['memcached'])) && (false === isset($options['memcached']))) { throw new RuntimeException ( 'No Memcached client available as a service.' ); } $cache->setMemcached( isset($options['memcached']) ? $options['memcached'] : $app['memcached'] ); return $cache; default: throw new InvalidArgumentException ( "Unsupported cache class: $class" ); } } ); } return $cache; }
[ "public", "function", "createCache", "(", "Application", "$", "app", ")", "{", "$", "cache", "=", "new", "Pimple", ";", "foreach", "(", "$", "app", "[", "'ems.options'", "]", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "cache", "[", "$", "name", "]", "=", "$", "cache", "->", "share", "(", "function", "(", ")", "use", "(", "$", "app", ",", "$", "cache", ",", "$", "options", ")", "{", "$", "class", "=", "'Doctrine\\Common\\Cache\\\\'", ".", "$", "options", "[", "'caching_driver'", "]", ";", "switch", "(", "$", "options", "[", "'caching_driver'", "]", ")", "{", "case", "'ApcCache'", ":", "case", "'ArrayCache'", ":", "case", "'XcacheCache'", ":", "return", "new", "$", "class", "(", ")", ";", "case", "'MemcacheCache'", ":", "$", "cache", "=", "new", "$", "class", "(", ")", ";", "if", "(", "(", "false", "===", "isset", "(", "$", "app", "[", "'memcache'", "]", ")", ")", "&&", "(", "false", "===", "isset", "(", "$", "options", "[", "'memcache'", "]", ")", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'No Memcache client available as a service.'", ")", ";", "}", "$", "cache", "->", "setMemcache", "(", "isset", "(", "$", "options", "[", "'memcache'", "]", ")", "?", "$", "options", "[", "'memcache'", "]", ":", "$", "app", "[", "'memcache'", "]", ")", ";", "return", "$", "cache", ";", "case", "'MemcachedCache'", ":", "$", "cache", "=", "new", "$", "class", "(", ")", ";", "if", "(", "(", "false", "===", "isset", "(", "$", "app", "[", "'memcached'", "]", ")", ")", "&&", "(", "false", "===", "isset", "(", "$", "options", "[", "'memcached'", "]", ")", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'No Memcached client available as a service.'", ")", ";", "}", "$", "cache", "->", "setMemcached", "(", "isset", "(", "$", "options", "[", "'memcached'", "]", ")", "?", "$", "options", "[", "'memcached'", "]", ":", "$", "app", "[", "'memcached'", "]", ")", ";", "return", "$", "cache", ";", "default", ":", "throw", "new", "InvalidArgumentException", "(", "\"Unsupported cache class: $class\"", ")", ";", "}", "}", ")", ";", "}", "return", "$", "cache", ";", "}" ]
Creates the cache instances for the entity managers. @param Application $app The application. @return Pimple The cache instance manager.
[ "Creates", "the", "cache", "instances", "for", "the", "entity", "managers", "." ]
0d8558a437c7390b50b6b4b617037766465bb12f
https://github.com/kherge-abandoned/Entities/blob/0d8558a437c7390b50b6b4b617037766465bb12f/src/lib/KevinGH/Entities/EntitiesServiceProvider.php#L43-L101
train
kherge-abandoned/Entities
src/lib/KevinGH/Entities/EntitiesServiceProvider.php
EntitiesServiceProvider.createConfig
public function createConfig(Application $app) { $config = new Pimple; foreach ($app['ems.options'] as $name => $options) { $config[$name] = $config->share( function () use ($app, $name, $options) { $config = new Configuration; $config->setAutoGenerateProxyClasses( $options['proxy_auto_generate'] ); $config->setMetadataCacheImpl($app['ems.cache'][$name]); $config->setMetadataDriverImpl($app['ems.mapping'][$name]); $config->setQueryCacheImpl($app['ems.cache'][$name]); $config->setProxyDir($options['proxy_dir']); $config->setProxyNamespace($options['proxy_namespace']); return $config; } ); } return $config; }
php
public function createConfig(Application $app) { $config = new Pimple; foreach ($app['ems.options'] as $name => $options) { $config[$name] = $config->share( function () use ($app, $name, $options) { $config = new Configuration; $config->setAutoGenerateProxyClasses( $options['proxy_auto_generate'] ); $config->setMetadataCacheImpl($app['ems.cache'][$name]); $config->setMetadataDriverImpl($app['ems.mapping'][$name]); $config->setQueryCacheImpl($app['ems.cache'][$name]); $config->setProxyDir($options['proxy_dir']); $config->setProxyNamespace($options['proxy_namespace']); return $config; } ); } return $config; }
[ "public", "function", "createConfig", "(", "Application", "$", "app", ")", "{", "$", "config", "=", "new", "Pimple", ";", "foreach", "(", "$", "app", "[", "'ems.options'", "]", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "config", "[", "$", "name", "]", "=", "$", "config", "->", "share", "(", "function", "(", ")", "use", "(", "$", "app", ",", "$", "name", ",", "$", "options", ")", "{", "$", "config", "=", "new", "Configuration", ";", "$", "config", "->", "setAutoGenerateProxyClasses", "(", "$", "options", "[", "'proxy_auto_generate'", "]", ")", ";", "$", "config", "->", "setMetadataCacheImpl", "(", "$", "app", "[", "'ems.cache'", "]", "[", "$", "name", "]", ")", ";", "$", "config", "->", "setMetadataDriverImpl", "(", "$", "app", "[", "'ems.mapping'", "]", "[", "$", "name", "]", ")", ";", "$", "config", "->", "setQueryCacheImpl", "(", "$", "app", "[", "'ems.cache'", "]", "[", "$", "name", "]", ")", ";", "$", "config", "->", "setProxyDir", "(", "$", "options", "[", "'proxy_dir'", "]", ")", ";", "$", "config", "->", "setProxyNamespace", "(", "$", "options", "[", "'proxy_namespace'", "]", ")", ";", "return", "$", "config", ";", "}", ")", ";", "}", "return", "$", "config", ";", "}" ]
Creates the configuration instances for the entity managers. @param Application $app The application. @return Pimple The config instance manager.
[ "Creates", "the", "configuration", "instances", "for", "the", "entity", "managers", "." ]
0d8558a437c7390b50b6b4b617037766465bb12f
https://github.com/kherge-abandoned/Entities/blob/0d8558a437c7390b50b6b4b617037766465bb12f/src/lib/KevinGH/Entities/EntitiesServiceProvider.php#L110-L135
train
kherge-abandoned/Entities
src/lib/KevinGH/Entities/EntitiesServiceProvider.php
EntitiesServiceProvider.createEntityManager
public function createEntityManager(Application $app) { $ems = new Pimple; foreach ($app['ems.options'] as $name => $options) { $ems[$name] = $ems->share( function () use ($app, $name, $options) { if (false === isset($options['db'])) { $options['db'] = $name; } if (isset($app['dbs'][$options['db']])) { $em = EntityManager::create( $app['dbs'][$options['db']], $app['ems.config'][$name], $app['dbs.event_manager'][$options['db']] ); } else { $em = EntityManager::create( $app['db'], $app['ems.config'][$name], $app['db.event_manager'] ); } if ($options['flush_on_terminate']) { $app['dispatcher']->addListener( SilexEvents::FINISH, function () use ($em) { $em->flush(); // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd ); } return $em; } ); } return $ems; }
php
public function createEntityManager(Application $app) { $ems = new Pimple; foreach ($app['ems.options'] as $name => $options) { $ems[$name] = $ems->share( function () use ($app, $name, $options) { if (false === isset($options['db'])) { $options['db'] = $name; } if (isset($app['dbs'][$options['db']])) { $em = EntityManager::create( $app['dbs'][$options['db']], $app['ems.config'][$name], $app['dbs.event_manager'][$options['db']] ); } else { $em = EntityManager::create( $app['db'], $app['ems.config'][$name], $app['db.event_manager'] ); } if ($options['flush_on_terminate']) { $app['dispatcher']->addListener( SilexEvents::FINISH, function () use ($em) { $em->flush(); // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd ); } return $em; } ); } return $ems; }
[ "public", "function", "createEntityManager", "(", "Application", "$", "app", ")", "{", "$", "ems", "=", "new", "Pimple", ";", "foreach", "(", "$", "app", "[", "'ems.options'", "]", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "ems", "[", "$", "name", "]", "=", "$", "ems", "->", "share", "(", "function", "(", ")", "use", "(", "$", "app", ",", "$", "name", ",", "$", "options", ")", "{", "if", "(", "false", "===", "isset", "(", "$", "options", "[", "'db'", "]", ")", ")", "{", "$", "options", "[", "'db'", "]", "=", "$", "name", ";", "}", "if", "(", "isset", "(", "$", "app", "[", "'dbs'", "]", "[", "$", "options", "[", "'db'", "]", "]", ")", ")", "{", "$", "em", "=", "EntityManager", "::", "create", "(", "$", "app", "[", "'dbs'", "]", "[", "$", "options", "[", "'db'", "]", "]", ",", "$", "app", "[", "'ems.config'", "]", "[", "$", "name", "]", ",", "$", "app", "[", "'dbs.event_manager'", "]", "[", "$", "options", "[", "'db'", "]", "]", ")", ";", "}", "else", "{", "$", "em", "=", "EntityManager", "::", "create", "(", "$", "app", "[", "'db'", "]", ",", "$", "app", "[", "'ems.config'", "]", "[", "$", "name", "]", ",", "$", "app", "[", "'db.event_manager'", "]", ")", ";", "}", "if", "(", "$", "options", "[", "'flush_on_terminate'", "]", ")", "{", "$", "app", "[", "'dispatcher'", "]", "->", "addListener", "(", "SilexEvents", "::", "FINISH", ",", "function", "(", ")", "use", "(", "$", "em", ")", "{", "$", "em", "->", "flush", "(", ")", ";", "// @codeCoverageIgnoreStart", "}", "// @codeCoverageIgnoreEnd", ")", ";", "}", "return", "$", "em", ";", "}", ")", ";", "}", "return", "$", "ems", ";", "}" ]
Creates the entity manager instances. @param Application $app The application. @return Pimple The entity manager instance manager.
[ "Creates", "the", "entity", "manager", "instances", "." ]
0d8558a437c7390b50b6b4b617037766465bb12f
https://github.com/kherge-abandoned/Entities/blob/0d8558a437c7390b50b6b4b617037766465bb12f/src/lib/KevinGH/Entities/EntitiesServiceProvider.php#L144-L186
train
kherge-abandoned/Entities
src/lib/KevinGH/Entities/EntitiesServiceProvider.php
EntitiesServiceProvider.createMapping
public function createMapping(Application $app) { $mapping = new Pimple; foreach ($app['ems.options'] as $name => $options) { $mapping[$name] = $mapping->share( function () use ($app, $options) { $class = 'Doctrine\ORM\Mapping\Driver\\' . $options['mapping_driver']; switch ($options['mapping_driver']) { case 'AnnotationDriver': $config = new Configuration; return $config->newDefaultAnnotationDriver( $options['mapping_paths'] ); case 'XmlDriver': return new $class ( $options['mapping_paths'] ); case 'YamlDriver': $driver = new $class ( $options['mapping_paths'], '.yml' ); return $driver; default: throw new InvalidArgumentException ( "Unsupported mapping class: $class" ); } } ); } return $mapping; }
php
public function createMapping(Application $app) { $mapping = new Pimple; foreach ($app['ems.options'] as $name => $options) { $mapping[$name] = $mapping->share( function () use ($app, $options) { $class = 'Doctrine\ORM\Mapping\Driver\\' . $options['mapping_driver']; switch ($options['mapping_driver']) { case 'AnnotationDriver': $config = new Configuration; return $config->newDefaultAnnotationDriver( $options['mapping_paths'] ); case 'XmlDriver': return new $class ( $options['mapping_paths'] ); case 'YamlDriver': $driver = new $class ( $options['mapping_paths'], '.yml' ); return $driver; default: throw new InvalidArgumentException ( "Unsupported mapping class: $class" ); } } ); } return $mapping; }
[ "public", "function", "createMapping", "(", "Application", "$", "app", ")", "{", "$", "mapping", "=", "new", "Pimple", ";", "foreach", "(", "$", "app", "[", "'ems.options'", "]", "as", "$", "name", "=>", "$", "options", ")", "{", "$", "mapping", "[", "$", "name", "]", "=", "$", "mapping", "->", "share", "(", "function", "(", ")", "use", "(", "$", "app", ",", "$", "options", ")", "{", "$", "class", "=", "'Doctrine\\ORM\\Mapping\\Driver\\\\'", ".", "$", "options", "[", "'mapping_driver'", "]", ";", "switch", "(", "$", "options", "[", "'mapping_driver'", "]", ")", "{", "case", "'AnnotationDriver'", ":", "$", "config", "=", "new", "Configuration", ";", "return", "$", "config", "->", "newDefaultAnnotationDriver", "(", "$", "options", "[", "'mapping_paths'", "]", ")", ";", "case", "'XmlDriver'", ":", "return", "new", "$", "class", "(", "$", "options", "[", "'mapping_paths'", "]", ")", ";", "case", "'YamlDriver'", ":", "$", "driver", "=", "new", "$", "class", "(", "$", "options", "[", "'mapping_paths'", "]", ",", "'.yml'", ")", ";", "return", "$", "driver", ";", "default", ":", "throw", "new", "InvalidArgumentException", "(", "\"Unsupported mapping class: $class\"", ")", ";", "}", "}", ")", ";", "}", "return", "$", "mapping", ";", "}" ]
Creates the mapping instances for the entity managers. @param Application $app The application. @return Pimple The mapping instance manager.
[ "Creates", "the", "mapping", "instances", "for", "the", "entity", "managers", "." ]
0d8558a437c7390b50b6b4b617037766465bb12f
https://github.com/kherge-abandoned/Entities/blob/0d8558a437c7390b50b6b4b617037766465bb12f/src/lib/KevinGH/Entities/EntitiesServiceProvider.php#L195-L234
train
sndsgd/sndsgd-event
src/event/Handler.php
Handler.canHandle
public function canHandle($type, $namespace) { # no type; namespace must match if ($type === null) { if ($this->namespace === null || $namespace !== $this->namespace) { return false; } } else { if ($this->type !== $type) { return false; } else if ($namespace !== null && $this->namespace !== $namespace) { return false; } else if ($namespace === null && $this->namespace !== null) { return false; } } return true; }
php
public function canHandle($type, $namespace) { # no type; namespace must match if ($type === null) { if ($this->namespace === null || $namespace !== $this->namespace) { return false; } } else { if ($this->type !== $type) { return false; } else if ($namespace !== null && $this->namespace !== $namespace) { return false; } else if ($namespace === null && $this->namespace !== null) { return false; } } return true; }
[ "public", "function", "canHandle", "(", "$", "type", ",", "$", "namespace", ")", "{", "# no type; namespace must match", "if", "(", "$", "type", "===", "null", ")", "{", "if", "(", "$", "this", "->", "namespace", "===", "null", "||", "$", "namespace", "!==", "$", "this", "->", "namespace", ")", "{", "return", "false", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "type", "!==", "$", "type", ")", "{", "return", "false", ";", "}", "else", "if", "(", "$", "namespace", "!==", "null", "&&", "$", "this", "->", "namespace", "!==", "$", "namespace", ")", "{", "return", "false", ";", "}", "else", "if", "(", "$", "namespace", "===", "null", "&&", "$", "this", "->", "namespace", "!==", "null", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Determine if the handler can handle an event type and namespace @param string|null $type An event type @param string|null $namespace An event namespace @return boolean
[ "Determine", "if", "the", "handler", "can", "handle", "an", "event", "type", "and", "namespace" ]
531bd348fd77db6a27346aa6dfec43e99ecd3eef
https://github.com/sndsgd/sndsgd-event/blob/531bd348fd77db6a27346aa6dfec43e99ecd3eef/src/event/Handler.php#L38-L59
train
phpffcms/ffcms-core
src/App.php
App.loadNativeServices
private function loadNativeServices(): void { // initialize memory and properties controllers self::$Memory = MemoryObject::instance(); self::$Properties = new Properties(); // initialize debugger if (isset($this->_services['Debug']) && $this->_services['Debug'] === true && Debug::isEnabled()) { self::$Debug = new Debug(); $this->startMeasure(__METHOD__); } // prepare request data self::$Request = Request::createFromGlobals(); // initialize response, securty translate and other workers self::$Security = new Security(); self::$Response = new Response(); self::$View = new View(); self::$Translate = new Translate(); self::$Alias = new Alias(); self::$Event = new EventManager(); self::$Cron = new CronManager(); // stop debug timeline if (self::$Debug) { $this->stopMeasure(__METHOD__); } }
php
private function loadNativeServices(): void { // initialize memory and properties controllers self::$Memory = MemoryObject::instance(); self::$Properties = new Properties(); // initialize debugger if (isset($this->_services['Debug']) && $this->_services['Debug'] === true && Debug::isEnabled()) { self::$Debug = new Debug(); $this->startMeasure(__METHOD__); } // prepare request data self::$Request = Request::createFromGlobals(); // initialize response, securty translate and other workers self::$Security = new Security(); self::$Response = new Response(); self::$View = new View(); self::$Translate = new Translate(); self::$Alias = new Alias(); self::$Event = new EventManager(); self::$Cron = new CronManager(); // stop debug timeline if (self::$Debug) { $this->stopMeasure(__METHOD__); } }
[ "private", "function", "loadNativeServices", "(", ")", ":", "void", "{", "// initialize memory and properties controllers", "self", "::", "$", "Memory", "=", "MemoryObject", "::", "instance", "(", ")", ";", "self", "::", "$", "Properties", "=", "new", "Properties", "(", ")", ";", "// initialize debugger", "if", "(", "isset", "(", "$", "this", "->", "_services", "[", "'Debug'", "]", ")", "&&", "$", "this", "->", "_services", "[", "'Debug'", "]", "===", "true", "&&", "Debug", "::", "isEnabled", "(", ")", ")", "{", "self", "::", "$", "Debug", "=", "new", "Debug", "(", ")", ";", "$", "this", "->", "startMeasure", "(", "__METHOD__", ")", ";", "}", "// prepare request data", "self", "::", "$", "Request", "=", "Request", "::", "createFromGlobals", "(", ")", ";", "// initialize response, securty translate and other workers", "self", "::", "$", "Security", "=", "new", "Security", "(", ")", ";", "self", "::", "$", "Response", "=", "new", "Response", "(", ")", ";", "self", "::", "$", "View", "=", "new", "View", "(", ")", ";", "self", "::", "$", "Translate", "=", "new", "Translate", "(", ")", ";", "self", "::", "$", "Alias", "=", "new", "Alias", "(", ")", ";", "self", "::", "$", "Event", "=", "new", "EventManager", "(", ")", ";", "self", "::", "$", "Cron", "=", "new", "CronManager", "(", ")", ";", "// stop debug timeline", "if", "(", "self", "::", "$", "Debug", ")", "{", "$", "this", "->", "stopMeasure", "(", "__METHOD__", ")", ";", "}", "}" ]
Prepare native static symbolic links for app services @throws NativeException
[ "Prepare", "native", "static", "symbolic", "links", "for", "app", "services" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/App.php#L123-L147
train
phpffcms/ffcms-core
src/App.php
App.loadDynamicServices
private function loadDynamicServices(): void { $this->startMeasure(__METHOD__); /** @var array $objects */ $objects = App::$Properties->getAll('object'); if (!Any::isArray($objects)) { throw new NativeException('Object configurations is not loaded: /Private/Config/Object.php'); } // each all objects as service_name => service_instance() foreach ($objects as $name => $instance) { // check if definition of object is exist and services list contains it or is null to auto build if (property_exists(get_called_class(), $name) && $instance instanceof \Closure && (isset($this->_services[$name]) || $this->_services === null)) { if ($this->_services[$name] === true || $this->_services === null) { // initialize from configs self::${$name} = $instance(); } elseif (is_callable($this->_services[$name])) { // raw initialization from App::run() self::${$name} = $this->_services[$name](); } } elseif (Str::startsWith('_', $name)) { // just anonymous callback without entry-point @call_user_func($instance); } } $this->stopMeasure(__METHOD__); }
php
private function loadDynamicServices(): void { $this->startMeasure(__METHOD__); /** @var array $objects */ $objects = App::$Properties->getAll('object'); if (!Any::isArray($objects)) { throw new NativeException('Object configurations is not loaded: /Private/Config/Object.php'); } // each all objects as service_name => service_instance() foreach ($objects as $name => $instance) { // check if definition of object is exist and services list contains it or is null to auto build if (property_exists(get_called_class(), $name) && $instance instanceof \Closure && (isset($this->_services[$name]) || $this->_services === null)) { if ($this->_services[$name] === true || $this->_services === null) { // initialize from configs self::${$name} = $instance(); } elseif (is_callable($this->_services[$name])) { // raw initialization from App::run() self::${$name} = $this->_services[$name](); } } elseif (Str::startsWith('_', $name)) { // just anonymous callback without entry-point @call_user_func($instance); } } $this->stopMeasure(__METHOD__); }
[ "private", "function", "loadDynamicServices", "(", ")", ":", "void", "{", "$", "this", "->", "startMeasure", "(", "__METHOD__", ")", ";", "/** @var array $objects */", "$", "objects", "=", "App", "::", "$", "Properties", "->", "getAll", "(", "'object'", ")", ";", "if", "(", "!", "Any", "::", "isArray", "(", "$", "objects", ")", ")", "{", "throw", "new", "NativeException", "(", "'Object configurations is not loaded: /Private/Config/Object.php'", ")", ";", "}", "// each all objects as service_name => service_instance()", "foreach", "(", "$", "objects", "as", "$", "name", "=>", "$", "instance", ")", "{", "// check if definition of object is exist and services list contains it or is null to auto build", "if", "(", "property_exists", "(", "get_called_class", "(", ")", ",", "$", "name", ")", "&&", "$", "instance", "instanceof", "\\", "Closure", "&&", "(", "isset", "(", "$", "this", "->", "_services", "[", "$", "name", "]", ")", "||", "$", "this", "->", "_services", "===", "null", ")", ")", "{", "if", "(", "$", "this", "->", "_services", "[", "$", "name", "]", "===", "true", "||", "$", "this", "->", "_services", "===", "null", ")", "{", "// initialize from configs", "self", "::", "$", "{", "$", "name", "}", "=", "$", "instance", "(", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "this", "->", "_services", "[", "$", "name", "]", ")", ")", "{", "// raw initialization from App::run()", "self", "::", "$", "{", "$", "name", "}", "=", "$", "this", "->", "_services", "[", "$", "name", "]", "(", ")", ";", "}", "}", "elseif", "(", "Str", "::", "startsWith", "(", "'_'", ",", "$", "name", ")", ")", "{", "// just anonymous callback without entry-point", "@", "call_user_func", "(", "$", "instance", ")", ";", "}", "}", "$", "this", "->", "stopMeasure", "(", "__METHOD__", ")", ";", "}" ]
Prepare dynamic static links from object configurations as anonymous functions @throws NativeException
[ "Prepare", "dynamic", "static", "links", "from", "object", "configurations", "as", "anonymous", "functions" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/App.php#L153-L178
train
phpffcms/ffcms-core
src/App.php
App.run
public function run(): void { try { /** @var \Ffcms\Core\Arch\Controller $callClass */ $callClass = $this->getCallbackClass(); $callMethod = 'action' . self::$Request->getAction(); $arguments = self::$Request->getArguments(); // check if callback method (action) is exist in class object if (!method_exists($callClass, $callMethod)) { throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"'); } // check if method arguments counts equals passed count $requiredArgCount = $this->getMethodRequiredArgCount($callClass, $callMethod); // compare method arg count with passed if (count($arguments) < $requiredArgCount) { throw new NotFoundException(__('Arguments for method %method% is not enough. Expected: %required%, got: %current%.', [ 'method' => $callMethod, 'required' => $requiredArgCount, 'current' => count($arguments) ])); } // make callback call to action in controller and get response $response = call_user_func_array([$callClass, $callMethod], $arguments); // if no response - throw 404 not found if (!$response) { throw new NotFoundException('Page not found: 404 error'); } } catch (\Exception $e) { // check if exception is system-based throw if ($e instanceof TemplateException) { $response = $e->display(); } else { // or hook exception to system based :))) if (App::$Debug) { $msg = $e->getMessage() . $e->getTraceAsString(); $response = (new NativeException($msg))->display(); } else { $response = (new NativeException($e->getMessage()))->display(); } } } // set full rendered content to response builder self::$Response->setContent($response); // echo full response to user via symfony http foundation self::$Response->send(); }
php
public function run(): void { try { /** @var \Ffcms\Core\Arch\Controller $callClass */ $callClass = $this->getCallbackClass(); $callMethod = 'action' . self::$Request->getAction(); $arguments = self::$Request->getArguments(); // check if callback method (action) is exist in class object if (!method_exists($callClass, $callMethod)) { throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"'); } // check if method arguments counts equals passed count $requiredArgCount = $this->getMethodRequiredArgCount($callClass, $callMethod); // compare method arg count with passed if (count($arguments) < $requiredArgCount) { throw new NotFoundException(__('Arguments for method %method% is not enough. Expected: %required%, got: %current%.', [ 'method' => $callMethod, 'required' => $requiredArgCount, 'current' => count($arguments) ])); } // make callback call to action in controller and get response $response = call_user_func_array([$callClass, $callMethod], $arguments); // if no response - throw 404 not found if (!$response) { throw new NotFoundException('Page not found: 404 error'); } } catch (\Exception $e) { // check if exception is system-based throw if ($e instanceof TemplateException) { $response = $e->display(); } else { // or hook exception to system based :))) if (App::$Debug) { $msg = $e->getMessage() . $e->getTraceAsString(); $response = (new NativeException($msg))->display(); } else { $response = (new NativeException($e->getMessage()))->display(); } } } // set full rendered content to response builder self::$Response->setContent($response); // echo full response to user via symfony http foundation self::$Response->send(); }
[ "public", "function", "run", "(", ")", ":", "void", "{", "try", "{", "/** @var \\Ffcms\\Core\\Arch\\Controller $callClass */", "$", "callClass", "=", "$", "this", "->", "getCallbackClass", "(", ")", ";", "$", "callMethod", "=", "'action'", ".", "self", "::", "$", "Request", "->", "getAction", "(", ")", ";", "$", "arguments", "=", "self", "::", "$", "Request", "->", "getArguments", "(", ")", ";", "// check if callback method (action) is exist in class object", "if", "(", "!", "method_exists", "(", "$", "callClass", ",", "$", "callMethod", ")", ")", "{", "throw", "new", "NotFoundException", "(", "'Method \"'", ".", "App", "::", "$", "Security", "->", "strip_tags", "(", "$", "callMethod", ")", ".", "'()\" not founded in \"'", ".", "get_class", "(", "$", "callClass", ")", ".", "'\"'", ")", ";", "}", "// check if method arguments counts equals passed count", "$", "requiredArgCount", "=", "$", "this", "->", "getMethodRequiredArgCount", "(", "$", "callClass", ",", "$", "callMethod", ")", ";", "// compare method arg count with passed", "if", "(", "count", "(", "$", "arguments", ")", "<", "$", "requiredArgCount", ")", "{", "throw", "new", "NotFoundException", "(", "__", "(", "'Arguments for method %method% is not enough. Expected: %required%, got: %current%.'", ",", "[", "'method'", "=>", "$", "callMethod", ",", "'required'", "=>", "$", "requiredArgCount", ",", "'current'", "=>", "count", "(", "$", "arguments", ")", "]", ")", ")", ";", "}", "// make callback call to action in controller and get response", "$", "response", "=", "call_user_func_array", "(", "[", "$", "callClass", ",", "$", "callMethod", "]", ",", "$", "arguments", ")", ";", "// if no response - throw 404 not found", "if", "(", "!", "$", "response", ")", "{", "throw", "new", "NotFoundException", "(", "'Page not found: 404 error'", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// check if exception is system-based throw", "if", "(", "$", "e", "instanceof", "TemplateException", ")", "{", "$", "response", "=", "$", "e", "->", "display", "(", ")", ";", "}", "else", "{", "// or hook exception to system based :)))", "if", "(", "App", "::", "$", "Debug", ")", "{", "$", "msg", "=", "$", "e", "->", "getMessage", "(", ")", ".", "$", "e", "->", "getTraceAsString", "(", ")", ";", "$", "response", "=", "(", "new", "NativeException", "(", "$", "msg", ")", ")", "->", "display", "(", ")", ";", "}", "else", "{", "$", "response", "=", "(", "new", "NativeException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ")", "->", "display", "(", ")", ";", "}", "}", "}", "// set full rendered content to response builder", "self", "::", "$", "Response", "->", "setContent", "(", "$", "response", ")", ";", "// echo full response to user via symfony http foundation", "self", "::", "$", "Response", "->", "send", "(", ")", ";", "}" ]
Run applications and display output. Main entry point of system. @return void
[ "Run", "applications", "and", "display", "output", ".", "Main", "entry", "point", "of", "system", "." ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/App.php#L184-L234
train
phpffcms/ffcms-core
src/App.php
App.getCallbackClass
private function getCallbackClass() { // define callback class namespace/name full path $cName = (self::$Request->getCallbackAlias() ?? '\Apps\Controller\\' . env_name . '\\' . self::$Request->getController()); if (!class_exists($cName)) { throw new NotFoundException('Callback class not found: ' . App::$Security->strip_tags($cName)); } return new $cName; }
php
private function getCallbackClass() { // define callback class namespace/name full path $cName = (self::$Request->getCallbackAlias() ?? '\Apps\Controller\\' . env_name . '\\' . self::$Request->getController()); if (!class_exists($cName)) { throw new NotFoundException('Callback class not found: ' . App::$Security->strip_tags($cName)); } return new $cName; }
[ "private", "function", "getCallbackClass", "(", ")", "{", "// define callback class namespace/name full path", "$", "cName", "=", "(", "self", "::", "$", "Request", "->", "getCallbackAlias", "(", ")", "??", "'\\Apps\\Controller\\\\'", ".", "env_name", ".", "'\\\\'", ".", "self", "::", "$", "Request", "->", "getController", "(", ")", ")", ";", "if", "(", "!", "class_exists", "(", "$", "cName", ")", ")", "{", "throw", "new", "NotFoundException", "(", "'Callback class not found: '", ".", "App", "::", "$", "Security", "->", "strip_tags", "(", "$", "cName", ")", ")", ";", "}", "return", "new", "$", "cName", ";", "}" ]
Get callback class instance @return Controller @throws NotFoundException
[ "Get", "callback", "class", "instance" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/App.php#L241-L250
train
locomotivemtl/charcoal-config
src/Charcoal/Config/DelegatesAwareTrait.php
DelegatesAwareTrait.setDelegates
final public function setDelegates(array $delegates) { $this->delegates = []; foreach ($delegates as $delegate) { $this->addDelegate($delegate); } return $this; }
php
final public function setDelegates(array $delegates) { $this->delegates = []; foreach ($delegates as $delegate) { $this->addDelegate($delegate); } return $this; }
[ "final", "public", "function", "setDelegates", "(", "array", "$", "delegates", ")", "{", "$", "this", "->", "delegates", "=", "[", "]", ";", "foreach", "(", "$", "delegates", "as", "$", "delegate", ")", "{", "$", "this", "->", "addDelegate", "(", "$", "delegate", ")", ";", "}", "return", "$", "this", ";", "}" ]
Assigns a collection of delegare objects. @param EntityInterface[] $delegates One or more delegate objects to register. @return self
[ "Assigns", "a", "collection", "of", "delegare", "objects", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/DelegatesAwareTrait.php#L27-L34
train
locomotivemtl/charcoal-config
src/Charcoal/Config/DelegatesAwareTrait.php
DelegatesAwareTrait.hasInDelegates
final protected function hasInDelegates($key) { foreach ($this->delegates as $delegate) { if (isset($delegate[$key])) { return true; } } return false; }
php
final protected function hasInDelegates($key) { foreach ($this->delegates as $delegate) { if (isset($delegate[$key])) { return true; } } return false; }
[ "final", "protected", "function", "hasInDelegates", "(", "$", "key", ")", "{", "foreach", "(", "$", "this", "->", "delegates", "as", "$", "delegate", ")", "{", "if", "(", "isset", "(", "$", "delegate", "[", "$", "key", "]", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Determines if a delegate object contains the specified key and if its value is not NULL. Iterates over each object in the delegate stack and stops on the first match containing the specified key. @param string $key The data key to check. @return boolean TRUE if $key exists and has a value other than NULL, FALSE otherwise.
[ "Determines", "if", "a", "delegate", "object", "contains", "the", "specified", "key", "and", "if", "its", "value", "is", "not", "NULL", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/DelegatesAwareTrait.php#L69-L77
train
locomotivemtl/charcoal-config
src/Charcoal/Config/DelegatesAwareTrait.php
DelegatesAwareTrait.getInDelegates
final protected function getInDelegates($key) { foreach ($this->delegates as $delegate) { if (isset($delegate[$key])) { return $delegate[$key]; } } return null; }
php
final protected function getInDelegates($key) { foreach ($this->delegates as $delegate) { if (isset($delegate[$key])) { return $delegate[$key]; } } return null; }
[ "final", "protected", "function", "getInDelegates", "(", "$", "key", ")", "{", "foreach", "(", "$", "this", "->", "delegates", "as", "$", "delegate", ")", "{", "if", "(", "isset", "(", "$", "delegate", "[", "$", "key", "]", ")", ")", "{", "return", "$", "delegate", "[", "$", "key", "]", ";", "}", "}", "return", "null", ";", "}" ]
Returns the value from the specified key found on the first delegate object. Iterates over each object in the delegate stack and stops on the first match containing a value that is not NULL. @param string $key The data key to retrieve. @return mixed Value of the requested $key on success, NULL if the $key is not set.
[ "Returns", "the", "value", "from", "the", "specified", "key", "found", "on", "the", "first", "delegate", "object", "." ]
722b34955360c287dea8fffb3b5491866ce5f6cb
https://github.com/locomotivemtl/charcoal-config/blob/722b34955360c287dea8fffb3b5491866ce5f6cb/src/Charcoal/Config/DelegatesAwareTrait.php#L88-L96
train
spoom-php/core
src/extension/Helper/Collection.php
Collection.merge
public static function merge( $destination, $source, bool $deep = true, bool $assoc = false ) { if( !static::is( $destination, false, true ) ) throw new \TypeError( 'Destination must be array(like)' ); else if( !static::is( $source, true ) ) throw new \TypeError( 'Source must be iterable' ); else { // handle special case when both arrays are completly numeric if( !$assoc && static::isNumeric( $source ) && static::isNumeric( $destination ) ) { $index = -1; foreach( $destination as $tmp => $_ ) $index = max( $index, $tmp ); } $result = $destination; foreach( $source as $key => $value ) { $tmp = isset( $index ) ? ++$index : $key; if( !$deep || !static::is( $value, true ) || !static::is( $result[ $tmp ] ?? null, true ) ) $result[ $tmp ] = $value; else $result[ $tmp ] = static::merge( $result[ $tmp ], $value, $deep ); } } return $result; }
php
public static function merge( $destination, $source, bool $deep = true, bool $assoc = false ) { if( !static::is( $destination, false, true ) ) throw new \TypeError( 'Destination must be array(like)' ); else if( !static::is( $source, true ) ) throw new \TypeError( 'Source must be iterable' ); else { // handle special case when both arrays are completly numeric if( !$assoc && static::isNumeric( $source ) && static::isNumeric( $destination ) ) { $index = -1; foreach( $destination as $tmp => $_ ) $index = max( $index, $tmp ); } $result = $destination; foreach( $source as $key => $value ) { $tmp = isset( $index ) ? ++$index : $key; if( !$deep || !static::is( $value, true ) || !static::is( $result[ $tmp ] ?? null, true ) ) $result[ $tmp ] = $value; else $result[ $tmp ] = static::merge( $result[ $tmp ], $value, $deep ); } } return $result; }
[ "public", "static", "function", "merge", "(", "$", "destination", ",", "$", "source", ",", "bool", "$", "deep", "=", "true", ",", "bool", "$", "assoc", "=", "false", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "destination", ",", "false", ",", "true", ")", ")", "throw", "new", "\\", "TypeError", "(", "'Destination must be array(like)'", ")", ";", "else", "if", "(", "!", "static", "::", "is", "(", "$", "source", ",", "true", ")", ")", "throw", "new", "\\", "TypeError", "(", "'Source must be iterable'", ")", ";", "else", "{", "// handle special case when both arrays are completly numeric", "if", "(", "!", "$", "assoc", "&&", "static", "::", "isNumeric", "(", "$", "source", ")", "&&", "static", "::", "isNumeric", "(", "$", "destination", ")", ")", "{", "$", "index", "=", "-", "1", ";", "foreach", "(", "$", "destination", "as", "$", "tmp", "=>", "$", "_", ")", "$", "index", "=", "max", "(", "$", "index", ",", "$", "tmp", ")", ";", "}", "$", "result", "=", "$", "destination", ";", "foreach", "(", "$", "source", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "tmp", "=", "isset", "(", "$", "index", ")", "?", "++", "$", "index", ":", "$", "key", ";", "if", "(", "!", "$", "deep", "||", "!", "static", "::", "is", "(", "$", "value", ",", "true", ")", "||", "!", "static", "::", "is", "(", "$", "result", "[", "$", "tmp", "]", "??", "null", ",", "true", ")", ")", "$", "result", "[", "$", "tmp", "]", "=", "$", "value", ";", "else", "$", "result", "[", "$", "tmp", "]", "=", "static", "::", "merge", "(", "$", "result", "[", "$", "tmp", "]", ",", "$", "value", ",", "$", "deep", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Recursive merge of two arrays This is like the array_merge_recursive() without the strange array-creating thing @param array|object $destination @param array|object $source @param bool $deep @param bool $assoc Handle numeric arrays like associative (overwrite keys, not extend) @return array|object The extended destination @throws \TypeError
[ "Recursive", "merge", "of", "two", "arrays" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/Helper/Collection.php#L59-L82
train
spoom-php/core
src/extension/Helper/Collection.php
Collection.mapList
public static function mapList( $list, $map, ?string $key = null ): array { if( !static::is( $list, true ) ) throw new \TypeError( 'The $list must be iterable' ); else { $_list = []; foreach( $list as $index => $item ) { if( !static::is( $item, false, true ) ) throw new \TypeError( 'All $list element must be arraylike' ); else { $_key = $key ? $item[ $key ] : $index; if( !static::is( $map, true, true ) ) $_list[ $_key ] = $item[ $map ] ?? null; else $_list[ $_key ] = static::map( $item, [], $map ); } } return $_list; } }
php
public static function mapList( $list, $map, ?string $key = null ): array { if( !static::is( $list, true ) ) throw new \TypeError( 'The $list must be iterable' ); else { $_list = []; foreach( $list as $index => $item ) { if( !static::is( $item, false, true ) ) throw new \TypeError( 'All $list element must be arraylike' ); else { $_key = $key ? $item[ $key ] : $index; if( !static::is( $map, true, true ) ) $_list[ $_key ] = $item[ $map ] ?? null; else $_list[ $_key ] = static::map( $item, [], $map ); } } return $_list; } }
[ "public", "static", "function", "mapList", "(", "$", "list", ",", "$", "map", ",", "?", "string", "$", "key", "=", "null", ")", ":", "array", "{", "if", "(", "!", "static", "::", "is", "(", "$", "list", ",", "true", ")", ")", "throw", "new", "\\", "TypeError", "(", "'The $list must be iterable'", ")", ";", "else", "{", "$", "_list", "=", "[", "]", ";", "foreach", "(", "$", "list", "as", "$", "index", "=>", "$", "item", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "item", ",", "false", ",", "true", ")", ")", "throw", "new", "\\", "TypeError", "(", "'All $list element must be arraylike'", ")", ";", "else", "{", "$", "_key", "=", "$", "key", "?", "$", "item", "[", "$", "key", "]", ":", "$", "index", ";", "if", "(", "!", "static", "::", "is", "(", "$", "map", ",", "true", ",", "true", ")", ")", "$", "_list", "[", "$", "_key", "]", "=", "$", "item", "[", "$", "map", "]", "??", "null", ";", "else", "$", "_list", "[", "$", "_key", "]", "=", "static", "::", "map", "(", "$", "item", ",", "[", "]", ",", "$", "map", ")", ";", "}", "}", "return", "$", "_list", ";", "}", "}" ]
Re-map an array of arraylikes into a new array @param array[] $list @param string|array|array[] $map @param string|null $key @return array[]
[ "Re", "-", "map", "an", "array", "of", "arraylikes", "into", "a", "new", "array" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/Helper/Collection.php#L92-L111
train
spoom-php/core
src/extension/Helper/Collection.php
Collection.copy
public static function copy( $input, bool $deep = true ) { if( !static::is( $input ) ) return $input; else { if( is_array( $input ) ) { $result = []; foreach( $input as $k => $e ) { $result[ $k ] = $deep ? static::copy( $e, $deep ) : $e; } } else { // handle (and detect non-)cloneable object (private __clone method is considered non-cloneable) if( method_exists( $input, '__clone' ) && !is_callable( [ $input, '__clone' ] ) ) $result = $input; else if( !( $input instanceof \StdClass ) ) $result = clone $input; else { $result = new \stdClass(); foreach( $input as $k => $e ) { $result->{$k} = $deep ? static::copy( $e, $deep ) : $e; } } } return $result ?? $input; } }
php
public static function copy( $input, bool $deep = true ) { if( !static::is( $input ) ) return $input; else { if( is_array( $input ) ) { $result = []; foreach( $input as $k => $e ) { $result[ $k ] = $deep ? static::copy( $e, $deep ) : $e; } } else { // handle (and detect non-)cloneable object (private __clone method is considered non-cloneable) if( method_exists( $input, '__clone' ) && !is_callable( [ $input, '__clone' ] ) ) $result = $input; else if( !( $input instanceof \StdClass ) ) $result = clone $input; else { $result = new \stdClass(); foreach( $input as $k => $e ) { $result->{$k} = $deep ? static::copy( $e, $deep ) : $e; } } } return $result ?? $input; } }
[ "public", "static", "function", "copy", "(", "$", "input", ",", "bool", "$", "deep", "=", "true", ")", "{", "if", "(", "!", "static", "::", "is", "(", "$", "input", ")", ")", "return", "$", "input", ";", "else", "{", "if", "(", "is_array", "(", "$", "input", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "input", "as", "$", "k", "=>", "$", "e", ")", "{", "$", "result", "[", "$", "k", "]", "=", "$", "deep", "?", "static", "::", "copy", "(", "$", "e", ",", "$", "deep", ")", ":", "$", "e", ";", "}", "}", "else", "{", "// handle (and detect non-)cloneable object (private __clone method is considered non-cloneable)", "if", "(", "method_exists", "(", "$", "input", ",", "'__clone'", ")", "&&", "!", "is_callable", "(", "[", "$", "input", ",", "'__clone'", "]", ")", ")", "$", "result", "=", "$", "input", ";", "else", "if", "(", "!", "(", "$", "input", "instanceof", "\\", "StdClass", ")", ")", "$", "result", "=", "clone", "$", "input", ";", "else", "{", "$", "result", "=", "new", "\\", "stdClass", "(", ")", ";", "foreach", "(", "$", "input", "as", "$", "k", "=>", "$", "e", ")", "{", "$", "result", "->", "{", "$", "k", "}", "=", "$", "deep", "?", "static", "::", "copy", "(", "$", "e", ",", "$", "deep", ")", ":", "$", "e", ";", "}", "}", "}", "return", "$", "result", "??", "$", "input", ";", "}", "}" ]
Deep copy of a collection @param array|object $input @param bool $deep Deep copy or not @return array|object
[ "Deep", "copy", "of", "a", "collection" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/Helper/Collection.php#L150-L178
train
agentmedia/phine-core
src/Core/Logic/Caching/FileCacher.php
FileCacher.MustUseCache
function MustUseCache() { if ($this->cacheLifetime == 0) { return false; } if (!File::Exists($this->file)) { return false; } $now = Date::Now(); $lastMod = File::GetLastModified($this->file); if ($now->TimeStamp() - $lastMod->TimeStamp() < $this->cacheLifetime) { return true; } return false; }
php
function MustUseCache() { if ($this->cacheLifetime == 0) { return false; } if (!File::Exists($this->file)) { return false; } $now = Date::Now(); $lastMod = File::GetLastModified($this->file); if ($now->TimeStamp() - $lastMod->TimeStamp() < $this->cacheLifetime) { return true; } return false; }
[ "function", "MustUseCache", "(", ")", "{", "if", "(", "$", "this", "->", "cacheLifetime", "==", "0", ")", "{", "return", "false", ";", "}", "if", "(", "!", "File", "::", "Exists", "(", "$", "this", "->", "file", ")", ")", "{", "return", "false", ";", "}", "$", "now", "=", "Date", "::", "Now", "(", ")", ";", "$", "lastMod", "=", "File", "::", "GetLastModified", "(", "$", "this", "->", "file", ")", ";", "if", "(", "$", "now", "->", "TimeStamp", "(", ")", "-", "$", "lastMod", "->", "TimeStamp", "(", ")", "<", "$", "this", "->", "cacheLifetime", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Calculates if the cache content needs to be used @return boolean
[ "Calculates", "if", "the", "cache", "content", "needs", "to", "be", "used" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Caching/FileCacher.php#L48-L65
train
Wedeto/DB
src/DB.php
DB.setupDriver
protected function setupDriver(string $type) { // A full namespaced class name may be provided $driver = null; $driver_class = null; if (is_a($type, Driver::class, true)) { $driver_class = $type; $driver = new $type($this); } else { // Or the name of one of the included drivers $driver_class = "Wedeto\\DB\\Driver\\" . $type; if (is_a($driver_class, Driver::class, true)) { $driver = new $driver_class($this); } } if ($driver === null) throw new DriverException("No driver available for database type $type"); $actual_class = get_class($driver); if (strcmp($driver_class, $actual_class) != 0) { // Warn if the case doesn't match the actual classname self::$logger->warning( "WARNING: Configurated class {} does not match actual " . "classname: {}. This may cause issues with " . "autoloading.", [$driver_class, $actual_class] ); } return $driver; }
php
protected function setupDriver(string $type) { // A full namespaced class name may be provided $driver = null; $driver_class = null; if (is_a($type, Driver::class, true)) { $driver_class = $type; $driver = new $type($this); } else { // Or the name of one of the included drivers $driver_class = "Wedeto\\DB\\Driver\\" . $type; if (is_a($driver_class, Driver::class, true)) { $driver = new $driver_class($this); } } if ($driver === null) throw new DriverException("No driver available for database type $type"); $actual_class = get_class($driver); if (strcmp($driver_class, $actual_class) != 0) { // Warn if the case doesn't match the actual classname self::$logger->warning( "WARNING: Configurated class {} does not match actual " . "classname: {}. This may cause issues with " . "autoloading.", [$driver_class, $actual_class] ); } return $driver; }
[ "protected", "function", "setupDriver", "(", "string", "$", "type", ")", "{", "// A full namespaced class name may be provided", "$", "driver", "=", "null", ";", "$", "driver_class", "=", "null", ";", "if", "(", "is_a", "(", "$", "type", ",", "Driver", "::", "class", ",", "true", ")", ")", "{", "$", "driver_class", "=", "$", "type", ";", "$", "driver", "=", "new", "$", "type", "(", "$", "this", ")", ";", "}", "else", "{", "// Or the name of one of the included drivers", "$", "driver_class", "=", "\"Wedeto\\\\DB\\\\Driver\\\\\"", ".", "$", "type", ";", "if", "(", "is_a", "(", "$", "driver_class", ",", "Driver", "::", "class", ",", "true", ")", ")", "{", "$", "driver", "=", "new", "$", "driver_class", "(", "$", "this", ")", ";", "}", "}", "if", "(", "$", "driver", "===", "null", ")", "throw", "new", "DriverException", "(", "\"No driver available for database type $type\"", ")", ";", "$", "actual_class", "=", "get_class", "(", "$", "driver", ")", ";", "if", "(", "strcmp", "(", "$", "driver_class", ",", "$", "actual_class", ")", "!=", "0", ")", "{", "// Warn if the case doesn't match the actual classname", "self", "::", "$", "logger", "->", "warning", "(", "\"WARNING: Configurated class {} does not match actual \"", ".", "\"classname: {}. This may cause issues with \"", ".", "\"autoloading.\"", ",", "[", "$", "driver_class", ",", "$", "actual_class", "]", ")", ";", "}", "return", "$", "driver", ";", "}" ]
Find a proper driver based on the 'type' parameter in the configuration. @param string $type The type / driver name. @return Wedeto\DB\Driver\Driver A initialized driver object @throws Wedeto\DB\Exception\DriverException When no driver could be found
[ "Find", "a", "proper", "driver", "based", "on", "the", "type", "parameter", "in", "the", "configuration", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DB.php#L90-L125
train
Wedeto/DB
src/DB.php
DB.getDAO
public function getDAO(string $class) { if (!isset($this->dao[$class])) { if (!is_subclass_of($class, Model::class)) throw new DAOException("$class is not a valid Model"); $tablename = $class::getTablename(); $dao = DI::getInjector()->newInstance( DAO::class, ['classname' => $class, 'tablename' => $tablename, 'db' => $this] ); $this->dao[$class] = $dao; } return $this->dao[$class]; }
php
public function getDAO(string $class) { if (!isset($this->dao[$class])) { if (!is_subclass_of($class, Model::class)) throw new DAOException("$class is not a valid Model"); $tablename = $class::getTablename(); $dao = DI::getInjector()->newInstance( DAO::class, ['classname' => $class, 'tablename' => $tablename, 'db' => $this] ); $this->dao[$class] = $dao; } return $this->dao[$class]; }
[ "public", "function", "getDAO", "(", "string", "$", "class", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "dao", "[", "$", "class", "]", ")", ")", "{", "if", "(", "!", "is_subclass_of", "(", "$", "class", ",", "Model", "::", "class", ")", ")", "throw", "new", "DAOException", "(", "\"$class is not a valid Model\"", ")", ";", "$", "tablename", "=", "$", "class", "::", "getTablename", "(", ")", ";", "$", "dao", "=", "DI", "::", "getInjector", "(", ")", "->", "newInstance", "(", "DAO", "::", "class", ",", "[", "'classname'", "=>", "$", "class", ",", "'tablename'", "=>", "$", "tablename", ",", "'db'", "=>", "$", "this", "]", ")", ";", "$", "this", "->", "dao", "[", "$", "class", "]", "=", "$", "dao", ";", "}", "return", "$", "this", "->", "dao", "[", "$", "class", "]", ";", "}" ]
Get a DAO for a model. When none is available, a new one will be instantiated. @param string $class The name of the Model class @return DAO An instantiated DAO for the class.
[ "Get", "a", "DAO", "for", "a", "model", ".", "When", "none", "is", "available", "a", "new", "one", "will", "be", "instantiated", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DB.php#L222-L238
train
Wedeto/DB
src/DB.php
DB.clearCache
public function clearCache() { if (!empty($this->schema)) { $this->schema->clearCache(); } $this->dao = []; $this->schema = null; return $this; }
php
public function clearCache() { if (!empty($this->schema)) { $this->schema->clearCache(); } $this->dao = []; $this->schema = null; return $this; }
[ "public", "function", "clearCache", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "schema", ")", ")", "{", "$", "this", "->", "schema", "->", "clearCache", "(", ")", ";", "}", "$", "this", "->", "dao", "=", "[", "]", ";", "$", "this", "->", "schema", "=", "null", ";", "return", "$", "this", ";", "}" ]
Flush all cached DAOs and schema - useful after a schema alteration @return DB Provides fluent interface
[ "Flush", "all", "cached", "DAOs", "and", "schema", "-", "useful", "after", "a", "schema", "alteration" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DB.php#L244-L254
train
Wedeto/DB
src/DB.php
DB.setDAO
public function setDAO(string $class, DAO $dao = null) { if (!is_subclass_of($class, Model::class)) throw new DAOException("$class is not a valid Model"); $this->dao[$class] = $dao; return $this; }
php
public function setDAO(string $class, DAO $dao = null) { if (!is_subclass_of($class, Model::class)) throw new DAOException("$class is not a valid Model"); $this->dao[$class] = $dao; return $this; }
[ "public", "function", "setDAO", "(", "string", "$", "class", ",", "DAO", "$", "dao", "=", "null", ")", "{", "if", "(", "!", "is_subclass_of", "(", "$", "class", ",", "Model", "::", "class", ")", ")", "throw", "new", "DAOException", "(", "\"$class is not a valid Model\"", ")", ";", "$", "this", "->", "dao", "[", "$", "class", "]", "=", "$", "dao", ";", "return", "$", "this", ";", "}" ]
Set the DAO for a model manually. @param string $class The name of the Model class @param DAO $dao The DAO to set. Omit to reset - a new one will be instantiated on request @return DB Provides fluent interface
[ "Set", "the", "DAO", "for", "a", "model", "manually", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DB.php#L262-L269
train
Wedeto/DB
src/DB.php
DB.prepareQuery
public function prepareQuery(Query $query) { $parameters = new Parameters($this->driver); if ($this->pdo === null) $this->connect(); $sql = $this->driver->toSQL($parameters, $query); $statement = $this->prepare($sql); $parameters->bindParameters($statement); return $statement; }
php
public function prepareQuery(Query $query) { $parameters = new Parameters($this->driver); if ($this->pdo === null) $this->connect(); $sql = $this->driver->toSQL($parameters, $query); $statement = $this->prepare($sql); $parameters->bindParameters($statement); return $statement; }
[ "public", "function", "prepareQuery", "(", "Query", "$", "query", ")", "{", "$", "parameters", "=", "new", "Parameters", "(", "$", "this", "->", "driver", ")", ";", "if", "(", "$", "this", "->", "pdo", "===", "null", ")", "$", "this", "->", "connect", "(", ")", ";", "$", "sql", "=", "$", "this", "->", "driver", "->", "toSQL", "(", "$", "parameters", ",", "$", "query", ")", ";", "$", "statement", "=", "$", "this", "->", "prepare", "(", "$", "sql", ")", ";", "$", "parameters", "->", "bindParameters", "(", "$", "statement", ")", ";", "return", "$", "statement", ";", "}" ]
Prepare a query and return the PDOStatement @param Wedeto\DB\Query\Query The query to prepare @return PDOStatement The prepared statement
[ "Prepare", "a", "query", "and", "return", "the", "PDOStatement" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DB.php#L307-L319
train
Wedeto/DB
src/DB.php
DB.executeSQL
public function executeSQL(string $filename) { $fh = @fopen($filename, "r"); if ($fh === false) throw new IOException("Unable to open file '$filename'"); $prefix = $this->driver->getTablePrefix(); $statement = ''; while (!feof($fh)) { $line = fgets($fh); $trimmed = trim($line); // Skip comments if (substr($trimmed, 0, 2) === '--') continue; if ($line) $statement .= "\n" . $line; if (substr($trimmed, -1) === ';') { $statement = trim(str_replace('%PREFIX%', $prefix, $statement)); $this->exec($statement); $statement = ''; } } fclose($fh); return $this; }
php
public function executeSQL(string $filename) { $fh = @fopen($filename, "r"); if ($fh === false) throw new IOException("Unable to open file '$filename'"); $prefix = $this->driver->getTablePrefix(); $statement = ''; while (!feof($fh)) { $line = fgets($fh); $trimmed = trim($line); // Skip comments if (substr($trimmed, 0, 2) === '--') continue; if ($line) $statement .= "\n" . $line; if (substr($trimmed, -1) === ';') { $statement = trim(str_replace('%PREFIX%', $prefix, $statement)); $this->exec($statement); $statement = ''; } } fclose($fh); return $this; }
[ "public", "function", "executeSQL", "(", "string", "$", "filename", ")", "{", "$", "fh", "=", "@", "fopen", "(", "$", "filename", ",", "\"r\"", ")", ";", "if", "(", "$", "fh", "===", "false", ")", "throw", "new", "IOException", "(", "\"Unable to open file '$filename'\"", ")", ";", "$", "prefix", "=", "$", "this", "->", "driver", "->", "getTablePrefix", "(", ")", ";", "$", "statement", "=", "''", ";", "while", "(", "!", "feof", "(", "$", "fh", ")", ")", "{", "$", "line", "=", "fgets", "(", "$", "fh", ")", ";", "$", "trimmed", "=", "trim", "(", "$", "line", ")", ";", "// Skip comments", "if", "(", "substr", "(", "$", "trimmed", ",", "0", ",", "2", ")", "===", "'--'", ")", "continue", ";", "if", "(", "$", "line", ")", "$", "statement", ".=", "\"\\n\"", ".", "$", "line", ";", "if", "(", "substr", "(", "$", "trimmed", ",", "-", "1", ")", "===", "';'", ")", "{", "$", "statement", "=", "trim", "(", "str_replace", "(", "'%PREFIX%'", ",", "$", "prefix", ",", "$", "statement", ")", ")", ";", "$", "this", "->", "exec", "(", "$", "statement", ")", ";", "$", "statement", "=", "''", ";", "}", "}", "fclose", "(", "$", "fh", ")", ";", "return", "$", "this", ";", "}" ]
Execute a SQL file in the database. This will scan the file for statements, skipping comment-only lines. Occurences of %PREFIX% will be replaced with the configured table prefix. YOU ARE STRONGLY ADVISED TO ENCLOSE ALL TABLE REFERENCES WITH IDENTIFIER QUOTES. For MySQL use backticks, for PostgreSQL use double quotes. Failing to do so may introduce problems when a prefix is used that requires quoting, for example when it includes hyphens. There are a two basic restrictions on the format: 1) each statement should be terminated with a semi-colon 2) each semi-colon should be at the end of a line, not followed by a comment. 3) Any line where the first two non-white space characters are -- is treated as a comment. Regardless of quotes. Therefore, the use of -- should be avoided except for comments. Not adhering to 1) will result in the last statement not being executed. Not adhering to 2) will result in the semi-colon not being detected, thus leading to the last statement not being executed. Not adhering to 3) will result in lines being skipped. Statements are concatenated and fed to the SQL driver, so any other language construct understood by the database is allowed. @param string $filename The SQL file to load and execute @return $this Provides fluent interface @throws PDOException When the SQL is faulty
[ "Execute", "a", "SQL", "file", "in", "the", "database", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/DB.php#L354-L384
train
MARCspec/php-marc-spec
src/MARCspec.php
MARCspec.addSubfield
private function addSubfield($_subfield) { if (array_key_exists('subfieldtagrange', $_subfield)) { $_subfieldRange = $this->handleSubfieldRanges($_subfield['subfieldtagrange']); } else { $_subfieldRange[] = $_subfield['subfieldtag']; } foreach ($_subfieldRange as $subfieldTag) { $Subfield = new Subfield((string) $subfieldTag); if (array_key_exists('index', $_subfield)) { $_pos = $this->validatePos($_subfield['index']); $Subfield->setIndexStartEnd($_pos[0], $_pos[1]); } else { // as of MARCspec 3.2.2 spec without index is always an abbreviation $Subfield->setIndexStartEnd(0, '#'); } if (array_key_exists('charpos', $_subfield)) { $_chars = $this->validatePos($_subfield['charpos']); $Subfield->setCharStartEnd($_chars[0], $_chars[1]); } if (array_key_exists('subspecs', $_subfield)) { $_subSpecs = []; foreach ($_subfield['subspecs'] as $subspec) { if (!array_key_exists('operator', $subspec)) { foreach ($subspec as $orSubSpec) { $_subSpecs[] = $this->createSubSpec($orSubSpec, $Subfield); } $Subfield->addSubSpec($_subSpecs); } else { $Subspec = $this->createSubSpec($subspec, $Subfield); $Subfield->addSubSpec($Subspec); } } } $this->addSubfields($Subfield); } }
php
private function addSubfield($_subfield) { if (array_key_exists('subfieldtagrange', $_subfield)) { $_subfieldRange = $this->handleSubfieldRanges($_subfield['subfieldtagrange']); } else { $_subfieldRange[] = $_subfield['subfieldtag']; } foreach ($_subfieldRange as $subfieldTag) { $Subfield = new Subfield((string) $subfieldTag); if (array_key_exists('index', $_subfield)) { $_pos = $this->validatePos($_subfield['index']); $Subfield->setIndexStartEnd($_pos[0], $_pos[1]); } else { // as of MARCspec 3.2.2 spec without index is always an abbreviation $Subfield->setIndexStartEnd(0, '#'); } if (array_key_exists('charpos', $_subfield)) { $_chars = $this->validatePos($_subfield['charpos']); $Subfield->setCharStartEnd($_chars[0], $_chars[1]); } if (array_key_exists('subspecs', $_subfield)) { $_subSpecs = []; foreach ($_subfield['subspecs'] as $subspec) { if (!array_key_exists('operator', $subspec)) { foreach ($subspec as $orSubSpec) { $_subSpecs[] = $this->createSubSpec($orSubSpec, $Subfield); } $Subfield->addSubSpec($_subSpecs); } else { $Subspec = $this->createSubSpec($subspec, $Subfield); $Subfield->addSubSpec($Subspec); } } } $this->addSubfields($Subfield); } }
[ "private", "function", "addSubfield", "(", "$", "_subfield", ")", "{", "if", "(", "array_key_exists", "(", "'subfieldtagrange'", ",", "$", "_subfield", ")", ")", "{", "$", "_subfieldRange", "=", "$", "this", "->", "handleSubfieldRanges", "(", "$", "_subfield", "[", "'subfieldtagrange'", "]", ")", ";", "}", "else", "{", "$", "_subfieldRange", "[", "]", "=", "$", "_subfield", "[", "'subfieldtag'", "]", ";", "}", "foreach", "(", "$", "_subfieldRange", "as", "$", "subfieldTag", ")", "{", "$", "Subfield", "=", "new", "Subfield", "(", "(", "string", ")", "$", "subfieldTag", ")", ";", "if", "(", "array_key_exists", "(", "'index'", ",", "$", "_subfield", ")", ")", "{", "$", "_pos", "=", "$", "this", "->", "validatePos", "(", "$", "_subfield", "[", "'index'", "]", ")", ";", "$", "Subfield", "->", "setIndexStartEnd", "(", "$", "_pos", "[", "0", "]", ",", "$", "_pos", "[", "1", "]", ")", ";", "}", "else", "{", "// as of MARCspec 3.2.2 spec without index is always an abbreviation", "$", "Subfield", "->", "setIndexStartEnd", "(", "0", ",", "'#'", ")", ";", "}", "if", "(", "array_key_exists", "(", "'charpos'", ",", "$", "_subfield", ")", ")", "{", "$", "_chars", "=", "$", "this", "->", "validatePos", "(", "$", "_subfield", "[", "'charpos'", "]", ")", ";", "$", "Subfield", "->", "setCharStartEnd", "(", "$", "_chars", "[", "0", "]", ",", "$", "_chars", "[", "1", "]", ")", ";", "}", "if", "(", "array_key_exists", "(", "'subspecs'", ",", "$", "_subfield", ")", ")", "{", "$", "_subSpecs", "=", "[", "]", ";", "foreach", "(", "$", "_subfield", "[", "'subspecs'", "]", "as", "$", "subspec", ")", "{", "if", "(", "!", "array_key_exists", "(", "'operator'", ",", "$", "subspec", ")", ")", "{", "foreach", "(", "$", "subspec", "as", "$", "orSubSpec", ")", "{", "$", "_subSpecs", "[", "]", "=", "$", "this", "->", "createSubSpec", "(", "$", "orSubSpec", ",", "$", "Subfield", ")", ";", "}", "$", "Subfield", "->", "addSubSpec", "(", "$", "_subSpecs", ")", ";", "}", "else", "{", "$", "Subspec", "=", "$", "this", "->", "createSubSpec", "(", "$", "subspec", ",", "$", "Subfield", ")", ";", "$", "Subfield", "->", "addSubSpec", "(", "$", "Subspec", ")", ";", "}", "}", "}", "$", "this", "->", "addSubfields", "(", "$", "Subfield", ")", ";", "}", "}" ]
Creates and adds a single subfield from the MARCspecParser result. @param array $_subfield The MARCspecParser result array
[ "Creates", "and", "adds", "a", "single", "subfield", "from", "the", "MARCspecParser", "result", "." ]
853d77ad3d510ce05c33535bfa3f1068dccdeef6
https://github.com/MARCspec/php-marc-spec/blob/853d77ad3d510ce05c33535bfa3f1068dccdeef6/src/MARCspec.php#L206-L251
train
MARCspec/php-marc-spec
src/MARCspec.php
MARCspec.handleSubfieldRanges
private function handleSubfieldRanges($arg) { if (strlen($arg) < 3) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::LENGTH3, $arg ); } if (preg_match('/[a-z]/', $arg[0]) && !preg_match('/[a-z]/', $arg[2])) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } if (preg_match('/[A-Z]/', $arg[0]) && !preg_match('/[A-Z]/', $arg[2])) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } if (preg_match('/[0-9]/', $arg[0]) && !preg_match('/[0-9]/', $arg[2])) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } if ($arg[0] > $arg[2]) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } return range((string) $arg[0], (string) $arg[2]); }
php
private function handleSubfieldRanges($arg) { if (strlen($arg) < 3) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::LENGTH3, $arg ); } if (preg_match('/[a-z]/', $arg[0]) && !preg_match('/[a-z]/', $arg[2])) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } if (preg_match('/[A-Z]/', $arg[0]) && !preg_match('/[A-Z]/', $arg[2])) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } if (preg_match('/[0-9]/', $arg[0]) && !preg_match('/[0-9]/', $arg[2])) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } if ($arg[0] > $arg[2]) { throw new InvalidMARCspecException( InvalidMARCspecException::SF. InvalidMARCspecException::RANGE, $arg ); } return range((string) $arg[0], (string) $arg[2]); }
[ "private", "function", "handleSubfieldRanges", "(", "$", "arg", ")", "{", "if", "(", "strlen", "(", "$", "arg", ")", "<", "3", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "SF", ".", "InvalidMARCspecException", "::", "LENGTH3", ",", "$", "arg", ")", ";", "}", "if", "(", "preg_match", "(", "'/[a-z]/'", ",", "$", "arg", "[", "0", "]", ")", "&&", "!", "preg_match", "(", "'/[a-z]/'", ",", "$", "arg", "[", "2", "]", ")", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "SF", ".", "InvalidMARCspecException", "::", "RANGE", ",", "$", "arg", ")", ";", "}", "if", "(", "preg_match", "(", "'/[A-Z]/'", ",", "$", "arg", "[", "0", "]", ")", "&&", "!", "preg_match", "(", "'/[A-Z]/'", ",", "$", "arg", "[", "2", "]", ")", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "SF", ".", "InvalidMARCspecException", "::", "RANGE", ",", "$", "arg", ")", ";", "}", "if", "(", "preg_match", "(", "'/[0-9]/'", ",", "$", "arg", "[", "0", "]", ")", "&&", "!", "preg_match", "(", "'/[0-9]/'", ",", "$", "arg", "[", "2", "]", ")", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "SF", ".", "InvalidMARCspecException", "::", "RANGE", ",", "$", "arg", ")", ";", "}", "if", "(", "$", "arg", "[", "0", "]", ">", "$", "arg", "[", "2", "]", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "SF", ".", "InvalidMARCspecException", "::", "RANGE", ",", "$", "arg", ")", ";", "}", "return", "range", "(", "(", "string", ")", "$", "arg", "[", "0", "]", ",", "(", "string", ")", "$", "arg", "[", "2", "]", ")", ";", "}" ]
Parses subfield ranges into single subfields. @internal @param string $arg The assumed subfield range @throws CK\MARCspec\Exception\InvalidMARCspecException @return array $_range[string] An array of subfield tags
[ "Parses", "subfield", "ranges", "into", "single", "subfields", "." ]
853d77ad3d510ce05c33535bfa3f1068dccdeef6
https://github.com/MARCspec/php-marc-spec/blob/853d77ad3d510ce05c33535bfa3f1068dccdeef6/src/MARCspec.php#L317-L357
train
MARCspec/php-marc-spec
src/MARCspec.php
MARCspec.validatePos
public static function validatePos($pos) { $posLength = strlen($pos); if (1 > $posLength) { throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR1, $pos ); } if (preg_match('/[^0-9\-#]/', $pos)) { // alphabetic characters etc. are not valid throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR2, $pos ); } if (strpos($pos, '-') === $posLength - 1) { // something like 123- is not valid throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR3, $pos ); } if (0 === strpos($pos, '-')) { // something like -123 ist not valid throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR4, $pos ); } if (strpos($pos, '-') !== strrpos($pos, '-')) { // only one - is allowed throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR5, $pos ); } $_pos = explode('-', $pos); if (2 < count($_pos)) { throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR6, $pos ); } if (1 == count($_pos)) { $_pos[1] = null; } return $_pos; }
php
public static function validatePos($pos) { $posLength = strlen($pos); if (1 > $posLength) { throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR1, $pos ); } if (preg_match('/[^0-9\-#]/', $pos)) { // alphabetic characters etc. are not valid throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR2, $pos ); } if (strpos($pos, '-') === $posLength - 1) { // something like 123- is not valid throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR3, $pos ); } if (0 === strpos($pos, '-')) { // something like -123 ist not valid throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR4, $pos ); } if (strpos($pos, '-') !== strrpos($pos, '-')) { // only one - is allowed throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR5, $pos ); } $_pos = explode('-', $pos); if (2 < count($_pos)) { throw new InvalidMARCspecException( InvalidMARCspecException::PR. InvalidMARCspecException::PR6, $pos ); } if (1 == count($_pos)) { $_pos[1] = null; } return $_pos; }
[ "public", "static", "function", "validatePos", "(", "$", "pos", ")", "{", "$", "posLength", "=", "strlen", "(", "$", "pos", ")", ";", "if", "(", "1", ">", "$", "posLength", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "PR", ".", "InvalidMARCspecException", "::", "PR1", ",", "$", "pos", ")", ";", "}", "if", "(", "preg_match", "(", "'/[^0-9\\-#]/'", ",", "$", "pos", ")", ")", "{", "// alphabetic characters etc. are not valid", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "PR", ".", "InvalidMARCspecException", "::", "PR2", ",", "$", "pos", ")", ";", "}", "if", "(", "strpos", "(", "$", "pos", ",", "'-'", ")", "===", "$", "posLength", "-", "1", ")", "{", "// something like 123- is not valid", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "PR", ".", "InvalidMARCspecException", "::", "PR3", ",", "$", "pos", ")", ";", "}", "if", "(", "0", "===", "strpos", "(", "$", "pos", ",", "'-'", ")", ")", "{", "// something like -123 ist not valid", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "PR", ".", "InvalidMARCspecException", "::", "PR4", ",", "$", "pos", ")", ";", "}", "if", "(", "strpos", "(", "$", "pos", ",", "'-'", ")", "!==", "strrpos", "(", "$", "pos", ",", "'-'", ")", ")", "{", "// only one - is allowed", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "PR", ".", "InvalidMARCspecException", "::", "PR5", ",", "$", "pos", ")", ";", "}", "$", "_pos", "=", "explode", "(", "'-'", ",", "$", "pos", ")", ";", "if", "(", "2", "<", "count", "(", "$", "_pos", ")", ")", "{", "throw", "new", "InvalidMARCspecException", "(", "InvalidMARCspecException", "::", "PR", ".", "InvalidMARCspecException", "::", "PR6", ",", "$", "pos", ")", ";", "}", "if", "(", "1", "==", "count", "(", "$", "_pos", ")", ")", "{", "$", "_pos", "[", "1", "]", "=", "null", ";", "}", "return", "$", "_pos", ";", "}" ]
validate a position or range. @param string $pos The position or range @throws CK\MARCspec\Exception\InvalidMARCspecException @return array $_pos[string] An numeric array of character or index positions. $_pos[1] might be empty.
[ "validate", "a", "position", "or", "range", "." ]
853d77ad3d510ce05c33535bfa3f1068dccdeef6
https://github.com/MARCspec/php-marc-spec/blob/853d77ad3d510ce05c33535bfa3f1068dccdeef6/src/MARCspec.php#L387-L446
train
anonymframework/Events
EventDispatcher.php
EventDispatcher.resolveResponseArray
private function resolveResponseArray(array $response) { if ($count = count($response)) { if ($count === 1) { $response = $response[0]; } } $this->firing[] = $response; return $response; }
php
private function resolveResponseArray(array $response) { if ($count = count($response)) { if ($count === 1) { $response = $response[0]; } } $this->firing[] = $response; return $response; }
[ "private", "function", "resolveResponseArray", "(", "array", "$", "response", ")", "{", "if", "(", "$", "count", "=", "count", "(", "$", "response", ")", ")", "{", "if", "(", "$", "count", "===", "1", ")", "{", "$", "response", "=", "$", "response", "[", "0", "]", ";", "}", "}", "$", "this", "->", "firing", "[", "]", "=", "$", "response", ";", "return", "$", "response", ";", "}" ]
resolve the return parameter @param array $response @return mixed
[ "resolve", "the", "return", "parameter" ]
efee1ead21cdfae00b128e3ea73aae07dc1ede2d
https://github.com/anonymframework/Events/blob/efee1ead21cdfae00b128e3ea73aae07dc1ede2d/EventDispatcher.php#L90-L100
train
anonymframework/Events
EventDispatcher.php
EventDispatcher.resolveEventAndListeners
private function resolveEventAndListeners($event) { if (is_object($event) && $event instanceof EventDispatch) { $name = get_class($event); } else { $name = $event; } if (is_string($name)) { if ($this->hasListiner($name) && $listeners = $this->getListeners($name)) { if (count($listeners) === 1) { $listeners = $listeners[0]; $listeners = [$listeners instanceof Closure ? $listeners : (new $listeners)]; } } else { throw new EventListenerException(sprintf('Your %s event havent got listener', $event)); } } return [$listeners, $event]; }
php
private function resolveEventAndListeners($event) { if (is_object($event) && $event instanceof EventDispatch) { $name = get_class($event); } else { $name = $event; } if (is_string($name)) { if ($this->hasListiner($name) && $listeners = $this->getListeners($name)) { if (count($listeners) === 1) { $listeners = $listeners[0]; $listeners = [$listeners instanceof Closure ? $listeners : (new $listeners)]; } } else { throw new EventListenerException(sprintf('Your %s event havent got listener', $event)); } } return [$listeners, $event]; }
[ "private", "function", "resolveEventAndListeners", "(", "$", "event", ")", "{", "if", "(", "is_object", "(", "$", "event", ")", "&&", "$", "event", "instanceof", "EventDispatch", ")", "{", "$", "name", "=", "get_class", "(", "$", "event", ")", ";", "}", "else", "{", "$", "name", "=", "$", "event", ";", "}", "if", "(", "is_string", "(", "$", "name", ")", ")", "{", "if", "(", "$", "this", "->", "hasListiner", "(", "$", "name", ")", "&&", "$", "listeners", "=", "$", "this", "->", "getListeners", "(", "$", "name", ")", ")", "{", "if", "(", "count", "(", "$", "listeners", ")", "===", "1", ")", "{", "$", "listeners", "=", "$", "listeners", "[", "0", "]", ";", "$", "listeners", "=", "[", "$", "listeners", "instanceof", "Closure", "?", "$", "listeners", ":", "(", "new", "$", "listeners", ")", "]", ";", "}", "}", "else", "{", "throw", "new", "EventListenerException", "(", "sprintf", "(", "'Your %s event havent got listener'", ",", "$", "event", ")", ")", ";", "}", "}", "return", "[", "$", "listeners", ",", "$", "event", "]", ";", "}" ]
resolve the event and listener @param mixed $event @throws EventListenerException @return null|string|EventDispatch
[ "resolve", "the", "event", "and", "listener" ]
efee1ead21cdfae00b128e3ea73aae07dc1ede2d
https://github.com/anonymframework/Events/blob/efee1ead21cdfae00b128e3ea73aae07dc1ede2d/EventDispatcher.php#L161-L182
train
RudyMas/Emvc_Core
src/Core.php
Core.settingUpRootMapping
private function settingUpRootMapping() { $arrayServerName = explode('.', $_SERVER['SERVER_NAME']); $scriptName = rtrim(str_replace($arrayServerName, '', dirname($_SERVER['SCRIPT_NAME'])), '/\\'); define('BASE_URL', $scriptName); define('SYSTEM_ROOT', $_SERVER['DOCUMENT_ROOT'] . BASE_URL); }
php
private function settingUpRootMapping() { $arrayServerName = explode('.', $_SERVER['SERVER_NAME']); $scriptName = rtrim(str_replace($arrayServerName, '', dirname($_SERVER['SCRIPT_NAME'])), '/\\'); define('BASE_URL', $scriptName); define('SYSTEM_ROOT', $_SERVER['DOCUMENT_ROOT'] . BASE_URL); }
[ "private", "function", "settingUpRootMapping", "(", ")", "{", "$", "arrayServerName", "=", "explode", "(", "'.'", ",", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ")", ";", "$", "scriptName", "=", "rtrim", "(", "str_replace", "(", "$", "arrayServerName", ",", "''", ",", "dirname", "(", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ")", ")", ",", "'/\\\\'", ")", ";", "define", "(", "'BASE_URL'", ",", "$", "scriptName", ")", ";", "define", "(", "'SYSTEM_ROOT'", ",", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ".", "BASE_URL", ")", ";", "}" ]
Creating BASE_URL & SYSTEM_ROOT BASE_URL = Path to the root of the website SYSTEM_ROOT = Full system path to the root of the website
[ "Creating", "BASE_URL", "&", "SYSTEM_ROOT" ]
f7c89a2562eed5535f350a90f71a928e3504aeac
https://github.com/RudyMas/Emvc_Core/blob/f7c89a2562eed5535f350a90f71a928e3504aeac/src/Core.php#L50-L56
train
RudyMas/Emvc_Core
src/Core.php
Core.loadingConfig
private function loadingConfig() { if ($_SERVER['HTTP_HOST'] == SERVER_DEVELOP) { if (!is_file(SYSTEM_ROOT . '/config/config.local.php')) @copy(SYSTEM_ROOT . '/config/config.sample.php', SYSTEM_ROOT . '/config/config.local.php'); require_once('config/config.local.php'); } else { if (!is_file(SYSTEM_ROOT . '/config/config.php')) @copy(SYSTEM_ROOT . '/config/config.sample.php', SYSTEM_ROOT . '/config/config.php'); require_once('config/config.php'); } }
php
private function loadingConfig() { if ($_SERVER['HTTP_HOST'] == SERVER_DEVELOP) { if (!is_file(SYSTEM_ROOT . '/config/config.local.php')) @copy(SYSTEM_ROOT . '/config/config.sample.php', SYSTEM_ROOT . '/config/config.local.php'); require_once('config/config.local.php'); } else { if (!is_file(SYSTEM_ROOT . '/config/config.php')) @copy(SYSTEM_ROOT . '/config/config.sample.php', SYSTEM_ROOT . '/config/config.php'); require_once('config/config.php'); } }
[ "private", "function", "loadingConfig", "(", ")", "{", "if", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", "==", "SERVER_DEVELOP", ")", "{", "if", "(", "!", "is_file", "(", "SYSTEM_ROOT", ".", "'/config/config.local.php'", ")", ")", "@", "copy", "(", "SYSTEM_ROOT", ".", "'/config/config.sample.php'", ",", "SYSTEM_ROOT", ".", "'/config/config.local.php'", ")", ";", "require_once", "(", "'config/config.local.php'", ")", ";", "}", "else", "{", "if", "(", "!", "is_file", "(", "SYSTEM_ROOT", ".", "'/config/config.php'", ")", ")", "@", "copy", "(", "SYSTEM_ROOT", ".", "'/config/config.sample.php'", ",", "SYSTEM_ROOT", ".", "'/config/config.php'", ")", ";", "require_once", "(", "'config/config.php'", ")", ";", "}", "}" ]
Loading the configuration files for the website Checks if certain files exist, if not, it uses the standard config file by copying it
[ "Loading", "the", "configuration", "files", "for", "the", "website" ]
f7c89a2562eed5535f350a90f71a928e3504aeac
https://github.com/RudyMas/Emvc_Core/blob/f7c89a2562eed5535f350a90f71a928e3504aeac/src/Core.php#L63-L74
train
RudyMas/Emvc_Core
src/Core.php
Core.loadingDatabases
private function loadingDatabases() { $database = []; if ($_SERVER['HTTP_HOST'] == SERVER_DEVELOP) { if (!is_file(SYSTEM_ROOT . '/config/database.local.php')) @copy(SYSTEM_ROOT . '/config/database.sample.php', SYSTEM_ROOT . '/config/database.local.php'); require_once('config/database.local.php'); } else { if (!is_file(SYSTEM_ROOT . '/config/database.php')) @copy(SYSTEM_ROOT . '/config/database.sample.php', SYSTEM_ROOT . '/config/database.php'); require_once('config/database.php'); } foreach ($database as $connect) { $object = $connect['objectName']; $this->DB[$object] = new DBconnect($connect['dbHost'], $connect['port'], $connect['dbUsername'], $connect['dbPassword'], $connect['dbName'], $connect['dbCharset'], $connect['dbType']); } }
php
private function loadingDatabases() { $database = []; if ($_SERVER['HTTP_HOST'] == SERVER_DEVELOP) { if (!is_file(SYSTEM_ROOT . '/config/database.local.php')) @copy(SYSTEM_ROOT . '/config/database.sample.php', SYSTEM_ROOT . '/config/database.local.php'); require_once('config/database.local.php'); } else { if (!is_file(SYSTEM_ROOT . '/config/database.php')) @copy(SYSTEM_ROOT . '/config/database.sample.php', SYSTEM_ROOT . '/config/database.php'); require_once('config/database.php'); } foreach ($database as $connect) { $object = $connect['objectName']; $this->DB[$object] = new DBconnect($connect['dbHost'], $connect['port'], $connect['dbUsername'], $connect['dbPassword'], $connect['dbName'], $connect['dbCharset'], $connect['dbType']); } }
[ "private", "function", "loadingDatabases", "(", ")", "{", "$", "database", "=", "[", "]", ";", "if", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", "==", "SERVER_DEVELOP", ")", "{", "if", "(", "!", "is_file", "(", "SYSTEM_ROOT", ".", "'/config/database.local.php'", ")", ")", "@", "copy", "(", "SYSTEM_ROOT", ".", "'/config/database.sample.php'", ",", "SYSTEM_ROOT", ".", "'/config/database.local.php'", ")", ";", "require_once", "(", "'config/database.local.php'", ")", ";", "}", "else", "{", "if", "(", "!", "is_file", "(", "SYSTEM_ROOT", ".", "'/config/database.php'", ")", ")", "@", "copy", "(", "SYSTEM_ROOT", ".", "'/config/database.sample.php'", ",", "SYSTEM_ROOT", ".", "'/config/database.php'", ")", ";", "require_once", "(", "'config/database.php'", ")", ";", "}", "foreach", "(", "$", "database", "as", "$", "connect", ")", "{", "$", "object", "=", "$", "connect", "[", "'objectName'", "]", ";", "$", "this", "->", "DB", "[", "$", "object", "]", "=", "new", "DBconnect", "(", "$", "connect", "[", "'dbHost'", "]", ",", "$", "connect", "[", "'port'", "]", ",", "$", "connect", "[", "'dbUsername'", "]", ",", "$", "connect", "[", "'dbPassword'", "]", ",", "$", "connect", "[", "'dbName'", "]", ",", "$", "connect", "[", "'dbCharset'", "]", ",", "$", "connect", "[", "'dbType'", "]", ")", ";", "}", "}" ]
Loading the databases for the websites
[ "Loading", "the", "databases", "for", "the", "websites" ]
f7c89a2562eed5535f350a90f71a928e3504aeac
https://github.com/RudyMas/Emvc_Core/blob/f7c89a2562eed5535f350a90f71a928e3504aeac/src/Core.php#L79-L96
train
native5/native5-sdk-client-php
src/Native5/ConfigurationFactory.php
ConfigurationFactory.makeConfig
protected function makeConfig() { $this->_checkConfig(); // Construct the Configuration object if (empty($this->_configuration) || !($this->_configuration instanceof Configuration)) { $this->_configuration = new Configuration(trim($this->_config['app']['name'])); // Local Environment if (isset($this->_config['environment']) && (strcasecmp($this->_config['environment'], 'local') == 0)) $this->_configuration->setLocal(); if (isset($this->_config['app']['preventMultipleLogins']) && (strcasecmp($this->_config['app']['preventMultipleLogins'], 'true') == 0 || $this->_config['app']['preventMultipleLogins'])) $this->_configuration->setPreventMultipleLogins(); // App Configuration // Default Grade if (isset($this->_config['app']['defaultGrade'])) $this->_configuration->setDefaultGrade(trim($this->_config['app']['defaultGrade'])); // Log Level if (isset($this->_config['app']['logLevel'])) $this->_configuration->setLogLevel(trim($this->_config['app']['logLevel'])); //Track Analytics if (isset($this->_config['app']['trackAnalytics'])) $this->_configuration->setLogAnalytics(trim($this->_config['app']['trackAnalytics'])); // Api Configuration // Url $this->_configuration->setApiUrl(trim($this->_config['api']['url'])); // Shared Key $sharedKey = getenv('NATIVE5_API_SHARED_KEY'); if(empty($sharedKey)) $this->_configuration->setSharedKey(trim($this->_config['api']['sharedKey'])); else $this->_configuration->setSharedKey(trim($sharedKey)); // Secret Key $secretKey = getenv('NATIVE5_API_SECRET_KEY'); if(empty($secretKey)) $this->_configuration->setSecretKey(trim($this->_config['api']['secretKey'])); else $this->_configuration->setSecretKey(trim($secretKey)); if (isset($this->_config['nativeBinaryOnly'])) $this->_configuration->setNativeBinary(trim($this->_config['nativeBinaryOnly'])); // Set the raw config $this->_configuration->setRawConfiguration($this->_config); } return $this->_configuration; }
php
protected function makeConfig() { $this->_checkConfig(); // Construct the Configuration object if (empty($this->_configuration) || !($this->_configuration instanceof Configuration)) { $this->_configuration = new Configuration(trim($this->_config['app']['name'])); // Local Environment if (isset($this->_config['environment']) && (strcasecmp($this->_config['environment'], 'local') == 0)) $this->_configuration->setLocal(); if (isset($this->_config['app']['preventMultipleLogins']) && (strcasecmp($this->_config['app']['preventMultipleLogins'], 'true') == 0 || $this->_config['app']['preventMultipleLogins'])) $this->_configuration->setPreventMultipleLogins(); // App Configuration // Default Grade if (isset($this->_config['app']['defaultGrade'])) $this->_configuration->setDefaultGrade(trim($this->_config['app']['defaultGrade'])); // Log Level if (isset($this->_config['app']['logLevel'])) $this->_configuration->setLogLevel(trim($this->_config['app']['logLevel'])); //Track Analytics if (isset($this->_config['app']['trackAnalytics'])) $this->_configuration->setLogAnalytics(trim($this->_config['app']['trackAnalytics'])); // Api Configuration // Url $this->_configuration->setApiUrl(trim($this->_config['api']['url'])); // Shared Key $sharedKey = getenv('NATIVE5_API_SHARED_KEY'); if(empty($sharedKey)) $this->_configuration->setSharedKey(trim($this->_config['api']['sharedKey'])); else $this->_configuration->setSharedKey(trim($sharedKey)); // Secret Key $secretKey = getenv('NATIVE5_API_SECRET_KEY'); if(empty($secretKey)) $this->_configuration->setSecretKey(trim($this->_config['api']['secretKey'])); else $this->_configuration->setSecretKey(trim($secretKey)); if (isset($this->_config['nativeBinaryOnly'])) $this->_configuration->setNativeBinary(trim($this->_config['nativeBinaryOnly'])); // Set the raw config $this->_configuration->setRawConfiguration($this->_config); } return $this->_configuration; }
[ "protected", "function", "makeConfig", "(", ")", "{", "$", "this", "->", "_checkConfig", "(", ")", ";", "// Construct the Configuration object", "if", "(", "empty", "(", "$", "this", "->", "_configuration", ")", "||", "!", "(", "$", "this", "->", "_configuration", "instanceof", "Configuration", ")", ")", "{", "$", "this", "->", "_configuration", "=", "new", "Configuration", "(", "trim", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'name'", "]", ")", ")", ";", "// Local Environment", "if", "(", "isset", "(", "$", "this", "->", "_config", "[", "'environment'", "]", ")", "&&", "(", "strcasecmp", "(", "$", "this", "->", "_config", "[", "'environment'", "]", ",", "'local'", ")", "==", "0", ")", ")", "$", "this", "->", "_configuration", "->", "setLocal", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'preventMultipleLogins'", "]", ")", "&&", "(", "strcasecmp", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'preventMultipleLogins'", "]", ",", "'true'", ")", "==", "0", "||", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'preventMultipleLogins'", "]", ")", ")", "$", "this", "->", "_configuration", "->", "setPreventMultipleLogins", "(", ")", ";", "// App Configuration", "// Default Grade", "if", "(", "isset", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'defaultGrade'", "]", ")", ")", "$", "this", "->", "_configuration", "->", "setDefaultGrade", "(", "trim", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'defaultGrade'", "]", ")", ")", ";", "// Log Level", "if", "(", "isset", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'logLevel'", "]", ")", ")", "$", "this", "->", "_configuration", "->", "setLogLevel", "(", "trim", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'logLevel'", "]", ")", ")", ";", "//Track Analytics", "if", "(", "isset", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'trackAnalytics'", "]", ")", ")", "$", "this", "->", "_configuration", "->", "setLogAnalytics", "(", "trim", "(", "$", "this", "->", "_config", "[", "'app'", "]", "[", "'trackAnalytics'", "]", ")", ")", ";", "// Api Configuration", "// Url", "$", "this", "->", "_configuration", "->", "setApiUrl", "(", "trim", "(", "$", "this", "->", "_config", "[", "'api'", "]", "[", "'url'", "]", ")", ")", ";", "// Shared Key", "$", "sharedKey", "=", "getenv", "(", "'NATIVE5_API_SHARED_KEY'", ")", ";", "if", "(", "empty", "(", "$", "sharedKey", ")", ")", "$", "this", "->", "_configuration", "->", "setSharedKey", "(", "trim", "(", "$", "this", "->", "_config", "[", "'api'", "]", "[", "'sharedKey'", "]", ")", ")", ";", "else", "$", "this", "->", "_configuration", "->", "setSharedKey", "(", "trim", "(", "$", "sharedKey", ")", ")", ";", "// Secret Key", "$", "secretKey", "=", "getenv", "(", "'NATIVE5_API_SECRET_KEY'", ")", ";", "if", "(", "empty", "(", "$", "secretKey", ")", ")", "$", "this", "->", "_configuration", "->", "setSecretKey", "(", "trim", "(", "$", "this", "->", "_config", "[", "'api'", "]", "[", "'secretKey'", "]", ")", ")", ";", "else", "$", "this", "->", "_configuration", "->", "setSecretKey", "(", "trim", "(", "$", "secretKey", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_config", "[", "'nativeBinaryOnly'", "]", ")", ")", "$", "this", "->", "_configuration", "->", "setNativeBinary", "(", "trim", "(", "$", "this", "->", "_config", "[", "'nativeBinaryOnly'", "]", ")", ")", ";", "// Set the raw config", "$", "this", "->", "_configuration", "->", "setRawConfiguration", "(", "$", "this", "->", "_config", ")", ";", "}", "return", "$", "this", "->", "_configuration", ";", "}" ]
makeConfig Wrap the associative configuration array inside a Configuration class @access public @return void @note the ftp configuration should be of the following format: mixed[] $configuration { @type string "host" domain name or IP address of ftp host @type string "port" port where ftp service is running on the host @type string "user" ftp username @type string "private_key" ftp user ssh private key for login into ftp host @type string "public_key" ftp user ssh public key for login into ftp host @type string "directory" directory on ftp host (optional) }
[ "makeConfig", "Wrap", "the", "associative", "configuration", "array", "inside", "a", "Configuration", "class" ]
e1f598cf27654d81bb5facace1990b737242a2f9
https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/ConfigurationFactory.php#L58-L107
train
jabernardo/lollipop-php
Library/HTTP/Upload.php
Upload.store
public function store($dest_folder, Callable $modifyName = null) { if (!isset($_FILES[$this->_file])) { return false; } if (is_array($_FILES[$this->_file]['name'])) { // Multiple file uploads $count = count($_FILES[$this->_file]['name']); $stored = []; $fails = []; for ($i = 0; $i < $count; $i++) { // Get modified name from callback $dest = rtrim($dest_folder, '/') . '/' . (is_callable($modifyName) ? $modifyName($_FILES[$this->_file]['name'][$i]) : $_FILES[$this->_file]['name'][$i]); if (File::rename($_FILES[$this->_file]['tmp_name'][$i], $dest)) { // Record all uploaded files $stored[] = $_FILES[$this->_file]['name'][$i]; } else { $fails[] = $_FILES[$this->_file]['name'][$i]; } } return [ 'stored' => $stored, 'failed' => $fails ]; } // Single file upload $dest = rtrim($dest_folder, '/') . '/' . (is_callable($modifyName) ? $modifyName($_FILES[$this->_file]['name']) : $_FILES[$this->_file]['name']); return File::rename($_FILES[$this->_file]['tmp_name'], $dest); }
php
public function store($dest_folder, Callable $modifyName = null) { if (!isset($_FILES[$this->_file])) { return false; } if (is_array($_FILES[$this->_file]['name'])) { // Multiple file uploads $count = count($_FILES[$this->_file]['name']); $stored = []; $fails = []; for ($i = 0; $i < $count; $i++) { // Get modified name from callback $dest = rtrim($dest_folder, '/') . '/' . (is_callable($modifyName) ? $modifyName($_FILES[$this->_file]['name'][$i]) : $_FILES[$this->_file]['name'][$i]); if (File::rename($_FILES[$this->_file]['tmp_name'][$i], $dest)) { // Record all uploaded files $stored[] = $_FILES[$this->_file]['name'][$i]; } else { $fails[] = $_FILES[$this->_file]['name'][$i]; } } return [ 'stored' => $stored, 'failed' => $fails ]; } // Single file upload $dest = rtrim($dest_folder, '/') . '/' . (is_callable($modifyName) ? $modifyName($_FILES[$this->_file]['name']) : $_FILES[$this->_file]['name']); return File::rename($_FILES[$this->_file]['tmp_name'], $dest); }
[ "public", "function", "store", "(", "$", "dest_folder", ",", "Callable", "$", "modifyName", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", ")", ")", "{", "// Multiple file uploads", "$", "count", "=", "count", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", ")", ";", "$", "stored", "=", "[", "]", ";", "$", "fails", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "// Get modified name from callback", "$", "dest", "=", "rtrim", "(", "$", "dest_folder", ",", "'/'", ")", ".", "'/'", ".", "(", "is_callable", "(", "$", "modifyName", ")", "?", "$", "modifyName", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", "[", "$", "i", "]", ")", ":", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", "[", "$", "i", "]", ")", ";", "if", "(", "File", "::", "rename", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'tmp_name'", "]", "[", "$", "i", "]", ",", "$", "dest", ")", ")", "{", "// Record all uploaded files", "$", "stored", "[", "]", "=", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", "[", "$", "i", "]", ";", "}", "else", "{", "$", "fails", "[", "]", "=", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", "[", "$", "i", "]", ";", "}", "}", "return", "[", "'stored'", "=>", "$", "stored", ",", "'failed'", "=>", "$", "fails", "]", ";", "}", "// Single file upload", "$", "dest", "=", "rtrim", "(", "$", "dest_folder", ",", "'/'", ")", ".", "'/'", ".", "(", "is_callable", "(", "$", "modifyName", ")", "?", "$", "modifyName", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", ")", ":", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'name'", "]", ")", ";", "return", "File", "::", "rename", "(", "$", "_FILES", "[", "$", "this", "->", "_file", "]", "[", "'tmp_name'", "]", ",", "$", "dest", ")", ";", "}" ]
Store temporary files to destination path of uploads @access public @param string $dest_folder Destination path @param Callable $modifyName Name modification callback @return mixed Returns `false` if upload fails. Returns `array` of stored and failed files for multiple file upload.
[ "Store", "temporary", "files", "to", "destination", "path", "of", "uploads" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/HTTP/Upload.php#L98-L133
train
g4code/buffer
src/Adapter/Base.php
Base.setSize
public function setSize($size = null) { $this->_size = is_int($size)? $size : self::DEFAULT_SIZE; }
php
public function setSize($size = null) { $this->_size = is_int($size)? $size : self::DEFAULT_SIZE; }
[ "public", "function", "setSize", "(", "$", "size", "=", "null", ")", "{", "$", "this", "->", "_size", "=", "is_int", "(", "$", "size", ")", "?", "$", "size", ":", "self", "::", "DEFAULT_SIZE", ";", "}" ]
Set buffer size @param int $size
[ "Set", "buffer", "size" ]
2f98fe8681f337095aac60542e31ca9034a795be
https://github.com/g4code/buffer/blob/2f98fe8681f337095aac60542e31ca9034a795be/src/Adapter/Base.php#L83-L85
train
nails/module-blog
blog/models/blog_tag_model.php
NAILS_Blog_tag_model.create
public function create($aData, $bReturnObject = false) { $aTagData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aTagData['label'] = trim($aData['label']); } if (empty($aData['blog_id'])) { $this->setError('"blog_id" is a required field.'); return false; } else { $aTagData['blog_id'] = $aData['blog_id']; } // -------------------------------------------------------------------------- $aTagData['slug'] = $this->generateSlug($aData['label']); if (isset($aData['description'])) { $aTagData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aTagData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aTagData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aTagData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::create($aTagData, $bReturnObject); }
php
public function create($aData, $bReturnObject = false) { $aTagData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aTagData['label'] = trim($aData['label']); } if (empty($aData['blog_id'])) { $this->setError('"blog_id" is a required field.'); return false; } else { $aTagData['blog_id'] = $aData['blog_id']; } // -------------------------------------------------------------------------- $aTagData['slug'] = $this->generateSlug($aData['label']); if (isset($aData['description'])) { $aTagData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aTagData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aTagData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aTagData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::create($aTagData, $bReturnObject); }
[ "public", "function", "create", "(", "$", "aData", ",", "$", "bReturnObject", "=", "false", ")", "{", "$", "aTagData", "=", "array", "(", ")", ";", "// --------------------------------------------------------------------------", "// Some basic sanity testing", "if", "(", "empty", "(", "$", "aData", "[", "'label'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'\"label\" is a required field.'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "aTagData", "[", "'label'", "]", "=", "trim", "(", "$", "aData", "[", "'label'", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "aData", "[", "'blog_id'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'\"blog_id\" is a required field.'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "aTagData", "[", "'blog_id'", "]", "=", "$", "aData", "[", "'blog_id'", "]", ";", "}", "// --------------------------------------------------------------------------", "$", "aTagData", "[", "'slug'", "]", "=", "$", "this", "->", "generateSlug", "(", "$", "aData", "[", "'label'", "]", ")", ";", "if", "(", "isset", "(", "$", "aData", "[", "'description'", "]", ")", ")", "{", "$", "aTagData", "[", "'description'", "]", "=", "$", "aData", "[", "'description'", "]", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_title'", "]", ")", ")", "{", "$", "aTagData", "[", "'seo_title'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_title'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_description'", "]", ")", ")", "{", "$", "aTagData", "[", "'seo_description'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ")", "{", "$", "aTagData", "[", "'seo_keywords'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ";", "}", "return", "parent", "::", "create", "(", "$", "aTagData", ",", "$", "bReturnObject", ")", ";", "}" ]
Creates a new tag @param array $aData The data to create the tag with @param boolean $bReturnObject Whether to return the full tag object (or just the ID) @return mixed
[ "Creates", "a", "new", "tag" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/blog/models/blog_tag_model.php#L74-L126
train
nails/module-blog
blog/models/blog_tag_model.php
NAILS_Blog_tag_model.update
public function update($iId, $aData) { $aTagData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aTagData['label'] = trim($aData['label']); } // -------------------------------------------------------------------------- $aTagData['slug'] = $this->generateSlug($aData['label'], $iId); if (isset($aData['description'])) { $aTagData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aTagData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aTagData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aTagData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::update($iId, $aTagData); }
php
public function update($iId, $aData) { $aTagData = array(); // -------------------------------------------------------------------------- // Some basic sanity testing if (empty($aData['label'])) { $this->setError('"label" is a required field.'); return false; } else { $aTagData['label'] = trim($aData['label']); } // -------------------------------------------------------------------------- $aTagData['slug'] = $this->generateSlug($aData['label'], $iId); if (isset($aData['description'])) { $aTagData['description'] = $aData['description']; } if (isset($aData['seo_title'])) { $aTagData['seo_title'] = strip_tags($aData['seo_title']); } if (isset($aData['seo_description'])) { $aTagData['seo_description'] = strip_tags($aData['seo_description']); } if (isset($aData['seo_keywords'])) { $aTagData['seo_keywords'] = strip_tags($aData['seo_keywords']); } return parent::update($iId, $aTagData); }
[ "public", "function", "update", "(", "$", "iId", ",", "$", "aData", ")", "{", "$", "aTagData", "=", "array", "(", ")", ";", "// --------------------------------------------------------------------------", "// Some basic sanity testing", "if", "(", "empty", "(", "$", "aData", "[", "'label'", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'\"label\" is a required field.'", ")", ";", "return", "false", ";", "}", "else", "{", "$", "aTagData", "[", "'label'", "]", "=", "trim", "(", "$", "aData", "[", "'label'", "]", ")", ";", "}", "// --------------------------------------------------------------------------", "$", "aTagData", "[", "'slug'", "]", "=", "$", "this", "->", "generateSlug", "(", "$", "aData", "[", "'label'", "]", ",", "$", "iId", ")", ";", "if", "(", "isset", "(", "$", "aData", "[", "'description'", "]", ")", ")", "{", "$", "aTagData", "[", "'description'", "]", "=", "$", "aData", "[", "'description'", "]", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_title'", "]", ")", ")", "{", "$", "aTagData", "[", "'seo_title'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_title'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_description'", "]", ")", ")", "{", "$", "aTagData", "[", "'seo_description'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_description'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ")", "{", "$", "aTagData", "[", "'seo_keywords'", "]", "=", "strip_tags", "(", "$", "aData", "[", "'seo_keywords'", "]", ")", ";", "}", "return", "parent", "::", "update", "(", "$", "iId", ",", "$", "aTagData", ")", ";", "}" ]
Updates an existing tag @param integer $iId The tag's ID @param stdClass $aData The data to update the tag with @return boolean
[ "Updates", "an", "existing", "tag" ]
7b369c5209f4343fff7c7e2a22c237d5a95c8c24
https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/blog/models/blog_tag_model.php#L136-L178
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setCreatedAt
public function setCreatedAt($created_at) { $this -> created_at = $created_at !== null ? new \DateTime($created_at) : null; return $this; }
php
public function setCreatedAt($created_at) { $this -> created_at = $created_at !== null ? new \DateTime($created_at) : null; return $this; }
[ "public", "function", "setCreatedAt", "(", "$", "created_at", ")", "{", "$", "this", "->", "created_at", "=", "$", "created_at", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "created_at", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the created at @param string $created_at @return TimestampAwareTrait
[ "Sets", "the", "created", "at" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L92-L96
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setCreatedOn
public function setCreatedOn($created_on) { $this -> created_on = $created_on !== null ? new \DateTime($created_on) : null; return $this; }
php
public function setCreatedOn($created_on) { $this -> created_on = $created_on !== null ? new \DateTime($created_on) : null; return $this; }
[ "public", "function", "setCreatedOn", "(", "$", "created_on", ")", "{", "$", "this", "->", "created_on", "=", "$", "created_on", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "created_on", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the created on @param string $created_on @return TimestampAwareTrait
[ "Sets", "the", "created", "on" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L113-L117
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setUpdatedAt
public function setUpdatedAt($updated_at) { $this -> updated_at = $updated_at !== null ? new \DateTime($updated_at) : null; return $this; }
php
public function setUpdatedAt($updated_at) { $this -> updated_at = $updated_at !== null ? new \DateTime($updated_at) : null; return $this; }
[ "public", "function", "setUpdatedAt", "(", "$", "updated_at", ")", "{", "$", "this", "->", "updated_at", "=", "$", "updated_at", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "updated_at", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the updated at @param string $updated_at @return TimestampAwareTrait
[ "Sets", "the", "updated", "at" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L133-L137
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setUpdatedOn
public function setUpdatedOn($updated_on) { $this -> updated_on = $updated_on !== null ? new \DateTime($updated_on) : null; return $this; }
php
public function setUpdatedOn($updated_on) { $this -> updated_on = $updated_on !== null ? new \DateTime($updated_on) : null; return $this; }
[ "public", "function", "setUpdatedOn", "(", "$", "updated_on", ")", "{", "$", "this", "->", "updated_on", "=", "$", "updated_on", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "updated_on", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the updated on @param string $updated_on @return TimestampAwareTrait
[ "Sets", "the", "updated", "on" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L153-L157
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setEditedAt
public function setEditedAt($edited_at) { $this -> edited_at = $edited_at !== null ? new \DateTime($edited_at) : null; return $this; }
php
public function setEditedAt($edited_at) { $this -> edited_at = $edited_at !== null ? new \DateTime($edited_at) : null; return $this; }
[ "public", "function", "setEditedAt", "(", "$", "edited_at", ")", "{", "$", "this", "->", "edited_at", "=", "$", "edited_at", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "edited_at", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the edited at @param string $edited_at @return TimestampAwareTrait
[ "Sets", "the", "edited", "at" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L173-L177
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setEditedOn
public function setEditedOn($edited_on) { $this -> edited_on = $edited_on !== null ? new \DateTime($edited_on) : null; return $this; }
php
public function setEditedOn($edited_on) { $this -> edited_on = $edited_on !== null ? new \DateTime($edited_on) : null; return $this; }
[ "public", "function", "setEditedOn", "(", "$", "edited_on", ")", "{", "$", "this", "->", "edited_on", "=", "$", "edited_on", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "edited_on", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the edited on @param string $edited_on @return TimestampAwareTrait
[ "Sets", "the", "edited", "on" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L193-L197
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setDeletedAt
public function setDeletedAt($deleted_at) { $this -> deleted_at = $deleted_at !== null ? new \DateTime($deleted_at) : null; return $this; }
php
public function setDeletedAt($deleted_at) { $this -> deleted_at = $deleted_at !== null ? new \DateTime($deleted_at) : null; return $this; }
[ "public", "function", "setDeletedAt", "(", "$", "deleted_at", ")", "{", "$", "this", "->", "deleted_at", "=", "$", "deleted_at", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "deleted_at", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the deleted at @param string $deleted_at @return TimestampAwareTrait
[ "Sets", "the", "deleted", "at" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L213-L217
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setDeletedOn
public function setDeletedOn($deleted_on) { $this -> deleted_on = $deleted_on !== null ? new \DateTime($deleted_on) : null; return $this; }
php
public function setDeletedOn($deleted_on) { $this -> deleted_on = $deleted_on !== null ? new \DateTime($deleted_on) : null; return $this; }
[ "public", "function", "setDeletedOn", "(", "$", "deleted_on", ")", "{", "$", "this", "->", "deleted_on", "=", "$", "deleted_on", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "deleted_on", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the deleted on @param string $deleted_on @return TimestampAwareTrait
[ "Sets", "the", "deleted", "on" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L233-L237
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setActivatedAt
public function setActivatedAt($activated_at) { $this -> activated_at = $activated_at !== null ? new \DateTime($activated_at) : null; return $this; }
php
public function setActivatedAt($activated_at) { $this -> activated_at = $activated_at !== null ? new \DateTime($activated_at) : null; return $this; }
[ "public", "function", "setActivatedAt", "(", "$", "activated_at", ")", "{", "$", "this", "->", "activated_at", "=", "$", "activated_at", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "activated_at", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the activated_at @param string $activated at @return TimestampAwareTrait
[ "Sets", "the", "activated_at" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L253-L257
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setActivatedOn
public function setActivatedOn($activated_on) { $this -> activated_on = $activated_on !== null ? new \DateTime($activated_on) : null; return $this; }
php
public function setActivatedOn($activated_on) { $this -> activated_on = $activated_on !== null ? new \DateTime($activated_on) : null; return $this; }
[ "public", "function", "setActivatedOn", "(", "$", "activated_on", ")", "{", "$", "this", "->", "activated_on", "=", "$", "activated_on", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "activated_on", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the activated on @param string $activated_on @return TimestampAwareTrait
[ "Sets", "the", "activated", "on" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L273-L277
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setCompletedAt
public function setCompletedAt($completed_at) { $this -> completed_at = $completed_at !== null ? new \DateTime($completed_at) : null; return $this; }
php
public function setCompletedAt($completed_at) { $this -> completed_at = $completed_at !== null ? new \DateTime($completed_at) : null; return $this; }
[ "public", "function", "setCompletedAt", "(", "$", "completed_at", ")", "{", "$", "this", "->", "completed_at", "=", "$", "completed_at", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "completed_at", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the completed at @param string $completed_at @return TimestampAwareTrait
[ "Sets", "the", "completed", "at" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L293-L297
train
Kris-Kuiper/sFire-Framework
src/Entity/Traits/TimestampAwareTrait.php
TimestampAwareTrait.setCompletedOn
public function setCompletedOn($completed_on) { $this -> completed_on = $completed_on !== null ? new \DateTime($completed_on) : null; return $this; }
php
public function setCompletedOn($completed_on) { $this -> completed_on = $completed_on !== null ? new \DateTime($completed_on) : null; return $this; }
[ "public", "function", "setCompletedOn", "(", "$", "completed_on", ")", "{", "$", "this", "->", "completed_on", "=", "$", "completed_on", "!==", "null", "?", "new", "\\", "DateTime", "(", "$", "completed_on", ")", ":", "null", ";", "return", "$", "this", ";", "}" ]
Sets the completed on @param string $completed_on @return TimestampAwareTrait
[ "Sets", "the", "completed", "on" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Entity/Traits/TimestampAwareTrait.php#L313-L317
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.newInstance
public function newInstance($data=null) { $class = $this->getClassName(); $conv = $this->newConverterInstance(); if(is_null($data)) { $data = array(); } if($conv instanceof IListConverter) { $data = $conv; } $o = new $class($data); if($conv instanceof IBaseConverter) { $o->setConverter($conv); } return $o; }
php
public function newInstance($data=null) { $class = $this->getClassName(); $conv = $this->newConverterInstance(); if(is_null($data)) { $data = array(); } if($conv instanceof IListConverter) { $data = $conv; } $o = new $class($data); if($conv instanceof IBaseConverter) { $o->setConverter($conv); } return $o; }
[ "public", "function", "newInstance", "(", "$", "data", "=", "null", ")", "{", "$", "class", "=", "$", "this", "->", "getClassName", "(", ")", ";", "$", "conv", "=", "$", "this", "->", "newConverterInstance", "(", ")", ";", "if", "(", "is_null", "(", "$", "data", ")", ")", "{", "$", "data", "=", "array", "(", ")", ";", "}", "if", "(", "$", "conv", "instanceof", "IListConverter", ")", "{", "$", "data", "=", "$", "conv", ";", "}", "$", "o", "=", "new", "$", "class", "(", "$", "data", ")", ";", "if", "(", "$", "conv", "instanceof", "IBaseConverter", ")", "{", "$", "o", "->", "setConverter", "(", "$", "conv", ")", ";", "}", "return", "$", "o", ";", "}" ]
Creates new instance of current class type Expect a subclass of \PerrysLambda\ArrayBase @return \PerrysLambda\ArrayBase
[ "Creates", "new", "instance", "of", "current", "class", "type", "Expect", "a", "subclass", "of", "\\", "PerrysLambda", "\\", "ArrayBase" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L96-L118
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.applyDefaults
public function applyDefaults(array $defaults) { foreach($defaults as $dkey => $dvalue) { if(!$this->exists($dkey)) { $this[$dkey] = $dvalue; } } }
php
public function applyDefaults(array $defaults) { foreach($defaults as $dkey => $dvalue) { if(!$this->exists($dkey)) { $this[$dkey] = $dvalue; } } }
[ "public", "function", "applyDefaults", "(", "array", "$", "defaults", ")", "{", "foreach", "(", "$", "defaults", "as", "$", "dkey", "=>", "$", "dvalue", ")", "{", "if", "(", "!", "$", "this", "->", "exists", "(", "$", "dkey", ")", ")", "{", "$", "this", "[", "$", "dkey", "]", "=", "$", "dvalue", ";", "}", "}", "}" ]
Applies given fields to this object if field does not exist @param array $defaults
[ "Applies", "given", "fields", "to", "this", "object", "if", "field", "does", "not", "exist" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L172-L181
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.regenerateKeyCache
protected function regenerateKeyCache() { if(is_array($this->__data)) { $i=0; $this->__keycache = array(); $this->__keycacheindex = array(); foreach($this->__data as $key => $value) { $this->__keycache[$key] = $i; $this->__keycacheindex[$i] = $key; $i++; } } else { $this->__keycache = null; $this->__keycacheindex = null; } $this->__keycacheinvalid = false; }
php
protected function regenerateKeyCache() { if(is_array($this->__data)) { $i=0; $this->__keycache = array(); $this->__keycacheindex = array(); foreach($this->__data as $key => $value) { $this->__keycache[$key] = $i; $this->__keycacheindex[$i] = $key; $i++; } } else { $this->__keycache = null; $this->__keycacheindex = null; } $this->__keycacheinvalid = false; }
[ "protected", "function", "regenerateKeyCache", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "__data", ")", ")", "{", "$", "i", "=", "0", ";", "$", "this", "->", "__keycache", "=", "array", "(", ")", ";", "$", "this", "->", "__keycacheindex", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "__data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "__keycache", "[", "$", "key", "]", "=", "$", "i", ";", "$", "this", "->", "__keycacheindex", "[", "$", "i", "]", "=", "$", "key", ";", "$", "i", "++", ";", "}", "}", "else", "{", "$", "this", "->", "__keycache", "=", "null", ";", "$", "this", "->", "__keycacheindex", "=", "null", ";", "}", "$", "this", "->", "__keycacheinvalid", "=", "false", ";", "}" ]
Regenerate array key cache
[ "Regenerate", "array", "key", "cache" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L215-L236
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.getNames
public function getNames() { if($this->isKeycacheInvalid()) { $this->regenerateKeyCache(); } if(is_array($this->__keycacheindex)) { return $this->__keycacheindex; } return array(); }
php
public function getNames() { if($this->isKeycacheInvalid()) { $this->regenerateKeyCache(); } if(is_array($this->__keycacheindex)) { return $this->__keycacheindex; } return array(); }
[ "public", "function", "getNames", "(", ")", "{", "if", "(", "$", "this", "->", "isKeycacheInvalid", "(", ")", ")", "{", "$", "this", "->", "regenerateKeyCache", "(", ")", ";", "}", "if", "(", "is_array", "(", "$", "this", "->", "__keycacheindex", ")", ")", "{", "return", "$", "this", "->", "__keycacheindex", ";", "}", "return", "array", "(", ")", ";", "}" ]
Get all field names @return array
[ "Get", "all", "field", "names" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L242-L253
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.getNameByValue
public function getNameByValue($value) { $i = array_search($value, $this->__data, true); if($i===false) { return null; } return $i; }
php
public function getNameByValue($value) { $i = array_search($value, $this->__data, true); if($i===false) { return null; } return $i; }
[ "public", "function", "getNameByValue", "(", "$", "value", ")", "{", "$", "i", "=", "array_search", "(", "$", "value", ",", "$", "this", "->", "__data", ",", "true", ")", ";", "if", "(", "$", "i", "===", "false", ")", "{", "return", "null", ";", "}", "return", "$", "i", ";", "}" ]
Get field name by its value NULL if not exist @param mixed $value @return mixed
[ "Get", "field", "name", "by", "its", "value", "NULL", "if", "not", "exist" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L285-L293
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.indexOfKey
public function indexOfKey($key) { if($this->isKeycacheInvalid()) { $this->regenerateKeyCache(); } if(isset($this->__keycache[$key])) { return $this->__keycache[$key]; } return -1; }
php
public function indexOfKey($key) { if($this->isKeycacheInvalid()) { $this->regenerateKeyCache(); } if(isset($this->__keycache[$key])) { return $this->__keycache[$key]; } return -1; }
[ "public", "function", "indexOfKey", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "isKeycacheInvalid", "(", ")", ")", "{", "$", "this", "->", "regenerateKeyCache", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "__keycache", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "__keycache", "[", "$", "key", "]", ";", "}", "return", "-", "1", ";", "}" ]
Index of key @param mixed $key @return int
[ "Index", "of", "key" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L300-L313
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.indexOfValue
public function indexOfValue($value) { $name = $this->getNameByValue($value); if(!is_null($name)) { return $this->indexOfKey($name); } return -1; }
php
public function indexOfValue($value) { $name = $this->getNameByValue($value); if(!is_null($name)) { return $this->indexOfKey($name); } return -1; }
[ "public", "function", "indexOfValue", "(", "$", "value", ")", "{", "$", "name", "=", "$", "this", "->", "getNameByValue", "(", "$", "value", ")", ";", "if", "(", "!", "is_null", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "indexOfKey", "(", "$", "name", ")", ";", "}", "return", "-", "1", ";", "}" ]
Index of element -1 = element not found @param mixed $value @return int
[ "Index", "of", "element", "-", "1", "=", "element", "not", "found" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L321-L329
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.&
public function &get($field, $default=null, $autoset=false) { if($this->exists($field)) { return $this->__data[$field]; } if($autoset===true) { $this->set($field, $default); return $this->get($field); } return $default; }
php
public function &get($field, $default=null, $autoset=false) { if($this->exists($field)) { return $this->__data[$field]; } if($autoset===true) { $this->set($field, $default); return $this->get($field); } return $default; }
[ "public", "function", "&", "get", "(", "$", "field", ",", "$", "default", "=", "null", ",", "$", "autoset", "=", "false", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "field", ")", ")", "{", "return", "$", "this", "->", "__data", "[", "$", "field", "]", ";", "}", "if", "(", "$", "autoset", "===", "true", ")", "{", "$", "this", "->", "set", "(", "$", "field", ",", "$", "default", ")", ";", "return", "$", "this", "->", "get", "(", "$", "field", ")", ";", "}", "return", "$", "default", ";", "}" ]
Get field by its name @param mixed $field @param mixed $default @param bool $autoset @return mixed
[ "Get", "field", "by", "its", "name" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L396-L408
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.getScalarAt
public function getScalarAt($i, $default=null) { $name = $this->getNameAt($i); if(!is_null($name)) { return $this->getScalar($name, $default); } return new ScalarProperty($default); }
php
public function getScalarAt($i, $default=null) { $name = $this->getNameAt($i); if(!is_null($name)) { return $this->getScalar($name, $default); } return new ScalarProperty($default); }
[ "public", "function", "getScalarAt", "(", "$", "i", ",", "$", "default", "=", "null", ")", "{", "$", "name", "=", "$", "this", "->", "getNameAt", "(", "$", "i", ")", ";", "if", "(", "!", "is_null", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "getScalar", "(", "$", "name", ",", "$", "default", ")", ";", "}", "return", "new", "ScalarProperty", "(", "$", "default", ")", ";", "}" ]
Get field value as scalar by index @param int $i @param mixed $default @return \PerrysLambda\ScalarProperty
[ "Get", "field", "value", "as", "scalar", "by", "index" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L416-L424
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.getScalar
public function getScalar($field, $default=null, $autoset=false) { $value = $this->get($field, $default, $autoset); return new ScalarProperty($value); }
php
public function getScalar($field, $default=null, $autoset=false) { $value = $this->get($field, $default, $autoset); return new ScalarProperty($value); }
[ "public", "function", "getScalar", "(", "$", "field", ",", "$", "default", "=", "null", ",", "$", "autoset", "=", "false", ")", "{", "$", "value", "=", "$", "this", "->", "get", "(", "$", "field", ",", "$", "default", ",", "$", "autoset", ")", ";", "return", "new", "ScalarProperty", "(", "$", "value", ")", ";", "}" ]
Get field value as scalar by field name @param mixed $field @param mixed $default @param bool $autoset @return \PerrysLambda\ScalarProperty
[ "Get", "field", "value", "as", "scalar", "by", "field", "name" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L433-L437
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.removeAt
public function removeAt($i) { $field = $this->getNameAt($i); $this->removeKey($field); return $this; }
php
public function removeAt($i) { $field = $this->getNameAt($i); $this->removeKey($field); return $this; }
[ "public", "function", "removeAt", "(", "$", "i", ")", "{", "$", "field", "=", "$", "this", "->", "getNameAt", "(", "$", "i", ")", ";", "$", "this", "->", "removeKey", "(", "$", "field", ")", ";", "return", "$", "this", ";", "}" ]
Remove field by index @param int $i @return \PerrysLambda\ArrayList
[ "Remove", "field", "by", "index" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L523-L528
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.removeValue
public function removeValue($value) { $i = $this->getNameByValue($value); if($i>=0) { $this->removeKey($i); } return $this; }
php
public function removeValue($value) { $i = $this->getNameByValue($value); if($i>=0) { $this->removeKey($i); } return $this; }
[ "public", "function", "removeValue", "(", "$", "value", ")", "{", "$", "i", "=", "$", "this", "->", "getNameByValue", "(", "$", "value", ")", ";", "if", "(", "$", "i", ">=", "0", ")", "{", "$", "this", "->", "removeKey", "(", "$", "i", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove field by its value @param mixed $value @return \PerrysLambda\ArrayList
[ "Remove", "field", "by", "its", "value" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L535-L543
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.removeKey
public function removeKey($field) { if($this->exists($field)) { unset($this->__data[$field]); $this->invalidateKeycache(); } return $this; }
php
public function removeKey($field) { if($this->exists($field)) { unset($this->__data[$field]); $this->invalidateKeycache(); } return $this; }
[ "public", "function", "removeKey", "(", "$", "field", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "field", ")", ")", "{", "unset", "(", "$", "this", "->", "__data", "[", "$", "field", "]", ")", ";", "$", "this", "->", "invalidateKeycache", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Remove field by name @param mixed $field @return \PerrysLambda\ArrayList
[ "Remove", "field", "by", "name" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L550-L558
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.getIsAllKeysValid
public function getIsAllKeysValid(array $data) { $keys = array_keys($data); foreach($keys as $key) { if(!$this->getIsValidKey($key)) { return false; } } return true; }
php
public function getIsAllKeysValid(array $data) { $keys = array_keys($data); foreach($keys as $key) { if(!$this->getIsValidKey($key)) { return false; } } return true; }
[ "public", "function", "getIsAllKeysValid", "(", "array", "$", "data", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "data", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "getIsValidKey", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Validate all field keys @param array $data @return boolean
[ "Validate", "all", "field", "keys" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L565-L576
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.getIsAllValuesValid
public function getIsAllValuesValid(array $data) { foreach($data as $value) { if(!$this->getIsValidValue($value)) { return false; } } return true; }
php
public function getIsAllValuesValid(array $data) { foreach($data as $value) { if(!$this->getIsValidValue($value)) { return false; } } return true; }
[ "public", "function", "getIsAllValuesValid", "(", "array", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "getIsValidValue", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Validate all field values @param array $data @return boolean
[ "Validate", "all", "field", "values" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L583-L593
train
perryflynn/PerrysLambda
src/PerrysLambda/ArrayBase.php
ArrayBase.where
public function where($where) { $where = LambdaUtils::toConditionCallable($where); $collection = $this->newInstance(); foreach($this as $record) { if(call_user_func($where, $record)) { $collection->add($record); } } return $collection; }
php
public function where($where) { $where = LambdaUtils::toConditionCallable($where); $collection = $this->newInstance(); foreach($this as $record) { if(call_user_func($where, $record)) { $collection->add($record); } } return $collection; }
[ "public", "function", "where", "(", "$", "where", ")", "{", "$", "where", "=", "LambdaUtils", "::", "toConditionCallable", "(", "$", "where", ")", ";", "$", "collection", "=", "$", "this", "->", "newInstance", "(", ")", ";", "foreach", "(", "$", "this", "as", "$", "record", ")", "{", "if", "(", "call_user_func", "(", "$", "where", ",", "$", "record", ")", ")", "{", "$", "collection", "->", "add", "(", "$", "record", ")", ";", "}", "}", "return", "$", "collection", ";", "}" ]
filter by condition @param callable|array $where @return \PerrysLambda\ArrayList
[ "filter", "by", "condition" ]
9f1734ae4689d73278b887f9354dfd31428e96de
https://github.com/perryflynn/PerrysLambda/blob/9f1734ae4689d73278b887f9354dfd31428e96de/src/PerrysLambda/ArrayBase.php#L618-L630
train