id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
230,400
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceManager.php
ServiceManager.getServicesByTag
public function getServicesByTag($tag, $forceType = null) { $services = []; foreach ($this->taggedServices->key($tag, [], true) as $serviceName) { $service = $this->getService($serviceName); if (!$this->isNull($forceType) && !$this->isInstanceOf($service, $forceType)) { continue; } $services[$serviceName] = $service; } return $services; }
php
public function getServicesByTag($tag, $forceType = null) { $services = []; foreach ($this->taggedServices->key($tag, [], true) as $serviceName) { $service = $this->getService($serviceName); if (!$this->isNull($forceType) && !$this->isInstanceOf($service, $forceType)) { continue; } $services[$serviceName] = $service; } return $services; }
[ "public", "function", "getServicesByTag", "(", "$", "tag", ",", "$", "forceType", "=", "null", ")", "{", "$", "services", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "taggedServices", "->", "key", "(", "$", "tag", ",", "[", "]", ",", "true", ")", "as", "$", "serviceName", ")", "{", "$", "service", "=", "$", "this", "->", "getService", "(", "$", "serviceName", ")", ";", "if", "(", "!", "$", "this", "->", "isNull", "(", "$", "forceType", ")", "&&", "!", "$", "this", "->", "isInstanceOf", "(", "$", "service", ",", "$", "forceType", ")", ")", "{", "continue", ";", "}", "$", "services", "[", "$", "serviceName", "]", "=", "$", "service", ";", "}", "return", "$", "services", ";", "}" ]
Get multiple services by tag @param string $tag Tag to use for services filter @param null|string $forceType (Optional) Return only services which are instances of $forceType @return array
[ "Get", "multiple", "services", "by", "tag" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L71-L83
230,401
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceManager.php
ServiceManager.registerService
public function registerService($serviceName, ConfigObject $config, $overwrite = false) { /** * Check if service instance already exists */ if ($this->registeredServices->keyExists($serviceName) && !$overwrite) { throw new ServiceManagerException(ServiceManagerException::SERVICE_NAME_ALREADY_EXISTS, [$serviceName]); } $this->registeredServices[$serviceName] = $config; if ($this->instantiatedServices->keyExists($serviceName) && $overwrite) { $this->instantiatedServices->removeKey($serviceName); } /** * Tagify service */ foreach ($config->get('Tags', []) as $tag) { $tagServices = $this->taggedServices->key($tag, [], true); $tagServices[] = $serviceName; $this->taggedServices->key($tag, $tagServices); } return $this; }
php
public function registerService($serviceName, ConfigObject $config, $overwrite = false) { /** * Check if service instance already exists */ if ($this->registeredServices->keyExists($serviceName) && !$overwrite) { throw new ServiceManagerException(ServiceManagerException::SERVICE_NAME_ALREADY_EXISTS, [$serviceName]); } $this->registeredServices[$serviceName] = $config; if ($this->instantiatedServices->keyExists($serviceName) && $overwrite) { $this->instantiatedServices->removeKey($serviceName); } /** * Tagify service */ foreach ($config->get('Tags', []) as $tag) { $tagServices = $this->taggedServices->key($tag, [], true); $tagServices[] = $serviceName; $this->taggedServices->key($tag, $tagServices); } return $this; }
[ "public", "function", "registerService", "(", "$", "serviceName", ",", "ConfigObject", "$", "config", ",", "$", "overwrite", "=", "false", ")", "{", "/**\n * Check if service instance already exists\n */", "if", "(", "$", "this", "->", "registeredServices", "->", "keyExists", "(", "$", "serviceName", ")", "&&", "!", "$", "overwrite", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "SERVICE_NAME_ALREADY_EXISTS", ",", "[", "$", "serviceName", "]", ")", ";", "}", "$", "this", "->", "registeredServices", "[", "$", "serviceName", "]", "=", "$", "config", ";", "if", "(", "$", "this", "->", "instantiatedServices", "->", "keyExists", "(", "$", "serviceName", ")", "&&", "$", "overwrite", ")", "{", "$", "this", "->", "instantiatedServices", "->", "removeKey", "(", "$", "serviceName", ")", ";", "}", "/**\n * Tagify service\n */", "foreach", "(", "$", "config", "->", "get", "(", "'Tags'", ",", "[", "]", ")", "as", "$", "tag", ")", "{", "$", "tagServices", "=", "$", "this", "->", "taggedServices", "->", "key", "(", "$", "tag", ",", "[", "]", ",", "true", ")", ";", "$", "tagServices", "[", "]", "=", "$", "serviceName", ";", "$", "this", "->", "taggedServices", "->", "key", "(", "$", "tag", ",", "$", "tagServices", ")", ";", "}", "return", "$", "this", ";", "}" ]
Register service using given config @param string $serviceName @param ConfigObject $config @param bool $overwrite Overwrite service if it has been registered before (Default: false) @throws ServiceManagerException @return $this
[ "Register", "service", "using", "given", "config" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L96-L120
230,402
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceManager.php
ServiceManager.registerServices
public function registerServices($serviceGroup, ConfigObject $config, $overwrite = false) { foreach ($config as $serviceKey => $serviceConfig) { $this->registerService($serviceGroup . '.' . $serviceKey, $serviceConfig, $overwrite); } }
php
public function registerServices($serviceGroup, ConfigObject $config, $overwrite = false) { foreach ($config as $serviceKey => $serviceConfig) { $this->registerService($serviceGroup . '.' . $serviceKey, $serviceConfig, $overwrite); } }
[ "public", "function", "registerServices", "(", "$", "serviceGroup", ",", "ConfigObject", "$", "config", ",", "$", "overwrite", "=", "false", ")", "{", "foreach", "(", "$", "config", "as", "$", "serviceKey", "=>", "$", "serviceConfig", ")", "{", "$", "this", "->", "registerService", "(", "$", "serviceGroup", ".", "'.'", ".", "$", "serviceKey", ",", "$", "serviceConfig", ",", "$", "overwrite", ")", ";", "}", "}" ]
Register given services under given service group @param string $serviceGroup @param ConfigObject $config @param bool $overwrite Overwrite service if it has been registered before (Default: false)
[ "Register", "given", "services", "under", "given", "service", "group" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L129-L134
230,403
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceManager.php
ServiceManager.registerParameters
public function registerParameters($parameters = []) { foreach ($parameters as $name => $value) { $this->registerParameter($name, $value); } return $this; }
php
public function registerParameters($parameters = []) { foreach ($parameters as $name => $value) { $this->registerParameter($name, $value); } return $this; }
[ "public", "function", "registerParameters", "(", "$", "parameters", "=", "[", "]", ")", "{", "foreach", "(", "$", "parameters", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "registerParameter", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Register multiple parameters for use in service configs @param ArrayObject|array $parameters Array of key => value parameter names and values @return $this
[ "Register", "multiple", "parameters", "for", "use", "in", "service", "configs" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L158-L165
230,404
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceManager.php
ServiceManager.getServiceConfig
public function getServiceConfig($serviceName) { if (!$this->registeredServices->keyExists($serviceName)) { throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]); } return $this->registeredServices[$serviceName]; }
php
public function getServiceConfig($serviceName) { if (!$this->registeredServices->keyExists($serviceName)) { throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]); } return $this->registeredServices[$serviceName]; }
[ "public", "function", "getServiceConfig", "(", "$", "serviceName", ")", "{", "if", "(", "!", "$", "this", "->", "registeredServices", "->", "keyExists", "(", "$", "serviceName", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "SERVICE_DEFINITION_NOT_FOUND", ",", "[", "$", "serviceName", "]", ")", ";", "}", "return", "$", "this", "->", "registeredServices", "[", "$", "serviceName", "]", ";", "}" ]
Get registered service config @param $serviceName @throws ServiceManagerException @return ConfigObject
[ "Get", "registered", "service", "config" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L175-L182
230,405
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceManager.php
ServiceManager.instantiateService
private function instantiateService($serviceName) { // Make sure service is registered if (!$this->registeredServices->keyExists($serviceName)) { throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]); } // Get service config from registered services array $config = $this->registeredServices->key($serviceName); // Check circular referencing if ($this->references->keyExists($serviceName)) { throw new ServiceManagerException(ServiceManagerException::SERVICE_CIRCULAR_REFERENCE, [$serviceName]); } // Set service name reference for circular referencing checks $this->references->key($serviceName, $serviceName); // Compile ConfigObject into ServiceConfig $configCompiler = new ConfigCompiler($serviceName, $config, $this->parameters); $this->compiledConfig->key($serviceName, $configCompiler->compile()); /** * @var $config ServiceConfig */ $config = $this->compiledConfig->key($serviceName); // Construct service container and get service instance $serviceCreator = new ServiceCreator($config); $service = $serviceCreator->getService(); // Unset service name reference $this->references->removeKey($serviceName); // Store instance if this service has a CONTAINER scope if ($config->getScope() == ServiceScope::CONTAINER) { $this->instantiatedServices->key($serviceName, $service); } return $service; }
php
private function instantiateService($serviceName) { // Make sure service is registered if (!$this->registeredServices->keyExists($serviceName)) { throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]); } // Get service config from registered services array $config = $this->registeredServices->key($serviceName); // Check circular referencing if ($this->references->keyExists($serviceName)) { throw new ServiceManagerException(ServiceManagerException::SERVICE_CIRCULAR_REFERENCE, [$serviceName]); } // Set service name reference for circular referencing checks $this->references->key($serviceName, $serviceName); // Compile ConfigObject into ServiceConfig $configCompiler = new ConfigCompiler($serviceName, $config, $this->parameters); $this->compiledConfig->key($serviceName, $configCompiler->compile()); /** * @var $config ServiceConfig */ $config = $this->compiledConfig->key($serviceName); // Construct service container and get service instance $serviceCreator = new ServiceCreator($config); $service = $serviceCreator->getService(); // Unset service name reference $this->references->removeKey($serviceName); // Store instance if this service has a CONTAINER scope if ($config->getScope() == ServiceScope::CONTAINER) { $this->instantiatedServices->key($serviceName, $service); } return $service; }
[ "private", "function", "instantiateService", "(", "$", "serviceName", ")", "{", "// Make sure service is registered", "if", "(", "!", "$", "this", "->", "registeredServices", "->", "keyExists", "(", "$", "serviceName", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "SERVICE_DEFINITION_NOT_FOUND", ",", "[", "$", "serviceName", "]", ")", ";", "}", "// Get service config from registered services array", "$", "config", "=", "$", "this", "->", "registeredServices", "->", "key", "(", "$", "serviceName", ")", ";", "// Check circular referencing", "if", "(", "$", "this", "->", "references", "->", "keyExists", "(", "$", "serviceName", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "SERVICE_CIRCULAR_REFERENCE", ",", "[", "$", "serviceName", "]", ")", ";", "}", "// Set service name reference for circular referencing checks", "$", "this", "->", "references", "->", "key", "(", "$", "serviceName", ",", "$", "serviceName", ")", ";", "// Compile ConfigObject into ServiceConfig", "$", "configCompiler", "=", "new", "ConfigCompiler", "(", "$", "serviceName", ",", "$", "config", ",", "$", "this", "->", "parameters", ")", ";", "$", "this", "->", "compiledConfig", "->", "key", "(", "$", "serviceName", ",", "$", "configCompiler", "->", "compile", "(", ")", ")", ";", "/**\n * @var $config ServiceConfig\n */", "$", "config", "=", "$", "this", "->", "compiledConfig", "->", "key", "(", "$", "serviceName", ")", ";", "// Construct service container and get service instance", "$", "serviceCreator", "=", "new", "ServiceCreator", "(", "$", "config", ")", ";", "$", "service", "=", "$", "serviceCreator", "->", "getService", "(", ")", ";", "// Unset service name reference", "$", "this", "->", "references", "->", "removeKey", "(", "$", "serviceName", ")", ";", "// Store instance if this service has a CONTAINER scope", "if", "(", "$", "config", "->", "getScope", "(", ")", "==", "ServiceScope", "::", "CONTAINER", ")", "{", "$", "this", "->", "instantiatedServices", "->", "key", "(", "$", "serviceName", ",", "$", "service", ")", ";", "}", "return", "$", "service", ";", "}" ]
Instantiate service using given service name @param string $serviceName @return object @throws ServiceManagerException
[ "Instantiate", "service", "using", "given", "service", "name" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L205-L245
230,406
themsaid/katana-core
src/PostBuilder.php
PostBuilder.build
public function build() { $this->filesystem->put( sprintf('/%s/_blog/%s', KATANA_CONTENT_DIR, $this->nameFile()), $this->buildTemplate() ); }
php
public function build() { $this->filesystem->put( sprintf('/%s/_blog/%s', KATANA_CONTENT_DIR, $this->nameFile()), $this->buildTemplate() ); }
[ "public", "function", "build", "(", ")", "{", "$", "this", "->", "filesystem", "->", "put", "(", "sprintf", "(", "'/%s/_blog/%s'", ",", "KATANA_CONTENT_DIR", ",", "$", "this", "->", "nameFile", "(", ")", ")", ",", "$", "this", "->", "buildTemplate", "(", ")", ")", ";", "}" ]
Build the template view post. @return void
[ "Build", "the", "template", "view", "post", "." ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/PostBuilder.php#L55-L64
230,407
themsaid/katana-core
src/PostBuilder.php
PostBuilder.buildTemplate
public function buildTemplate() { return ($this->template)? "--- \rview::extends: _includes.blog_post_base \rview::yields: post_body \rpageTitle: ".$this->title." \rpost::title: ".$this->title." \rpost::date: ".date('F d, Y')." \rpost::brief: Write the description of the post here! \r--- \rWrite your post content here!": "@extends('_includes.blog_post_base') \r@section('post::title', '".$this->title."') \r@section('post::date', '".date('F d, Y')."') \r@section('post::brief', 'Write the description of the post here!') \r@section('pageTitle')- @yield('post::title')@stop \r@section('post_body') \r\t@markdown \r\t\tWrite your the content of the post here! \r\t@endmarkdown \r@stop"; }
php
public function buildTemplate() { return ($this->template)? "--- \rview::extends: _includes.blog_post_base \rview::yields: post_body \rpageTitle: ".$this->title." \rpost::title: ".$this->title." \rpost::date: ".date('F d, Y')." \rpost::brief: Write the description of the post here! \r--- \rWrite your post content here!": "@extends('_includes.blog_post_base') \r@section('post::title', '".$this->title."') \r@section('post::date', '".date('F d, Y')."') \r@section('post::brief', 'Write the description of the post here!') \r@section('pageTitle')- @yield('post::title')@stop \r@section('post_body') \r\t@markdown \r\t\tWrite your the content of the post here! \r\t@endmarkdown \r@stop"; }
[ "public", "function", "buildTemplate", "(", ")", "{", "return", "(", "$", "this", "->", "template", ")", "?", "\"---\n \\rview::extends: _includes.blog_post_base\n \\rview::yields: post_body\n \\rpageTitle: \"", ".", "$", "this", "->", "title", ".", "\"\n \\rpost::title: \"", ".", "$", "this", "->", "title", ".", "\"\n \\rpost::date: \"", ".", "date", "(", "'F d, Y'", ")", ".", "\"\n \\rpost::brief: Write the description of the post here!\n \\r---\n \n \\rWrite your post content here!\"", ":", "\"@extends('_includes.blog_post_base')\n \\r@section('post::title', '\"", ".", "$", "this", "->", "title", ".", "\"')\n \\r@section('post::date', '\"", ".", "date", "(", "'F d, Y'", ")", ".", "\"')\n \\r@section('post::brief', 'Write the description of the post here!')\n \\r@section('pageTitle')- @yield('post::title')@stop\n \\r@section('post_body')\n \\r\\t@markdown\n \\r\\t\\tWrite your the content of the post here!\n \\r\\t@endmarkdown\n \\r@stop\"", ";", "}" ]
Return the default template of the new post @return string
[ "Return", "the", "default", "template", "of", "the", "new", "post" ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/PostBuilder.php#L71-L95
230,408
themsaid/katana-core
src/PostBuilder.php
PostBuilder.nameFile
public function nameFile() { $slug = strtolower(trim($this->title)); $slug = preg_replace('/[^a-z0-9-]/', '-', $slug); $slug = preg_replace('/-+/', "-", $slug); $extension = ($this->template)? "md": "blade.php"; return sprintf('%s-%s-.%s', date('Y-m-d'), $slug, $extension); }
php
public function nameFile() { $slug = strtolower(trim($this->title)); $slug = preg_replace('/[^a-z0-9-]/', '-', $slug); $slug = preg_replace('/-+/', "-", $slug); $extension = ($this->template)? "md": "blade.php"; return sprintf('%s-%s-.%s', date('Y-m-d'), $slug, $extension); }
[ "public", "function", "nameFile", "(", ")", "{", "$", "slug", "=", "strtolower", "(", "trim", "(", "$", "this", "->", "title", ")", ")", ";", "$", "slug", "=", "preg_replace", "(", "'/[^a-z0-9-]/'", ",", "'-'", ",", "$", "slug", ")", ";", "$", "slug", "=", "preg_replace", "(", "'/-+/'", ",", "\"-\"", ",", "$", "slug", ")", ";", "$", "extension", "=", "(", "$", "this", "->", "template", ")", "?", "\"md\"", ":", "\"blade.php\"", ";", "return", "sprintf", "(", "'%s-%s-.%s'", ",", "date", "(", "'Y-m-d'", ")", ",", "$", "slug", ",", "$", "extension", ")", ";", "}" ]
Return the name file of the post @return string
[ "Return", "the", "name", "file", "of", "the", "post" ]
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/PostBuilder.php#L102-L113
230,409
Webiny/Framework
src/Webiny/Component/Rest/Response/Cache.php
Cache.saveResult
public static function saveResult(RequestBag $requestBag, $result) { // check if we have cache in settings if (!$requestBag->getApiConfig()->get('Cache', false) || $requestBag->getMethodData()['cache']['ttl'] <= 0) { return false; } $instance = new self($requestBag); return $instance->saveCallbackResult($result); }
php
public static function saveResult(RequestBag $requestBag, $result) { // check if we have cache in settings if (!$requestBag->getApiConfig()->get('Cache', false) || $requestBag->getMethodData()['cache']['ttl'] <= 0) { return false; } $instance = new self($requestBag); return $instance->saveCallbackResult($result); }
[ "public", "static", "function", "saveResult", "(", "RequestBag", "$", "requestBag", ",", "$", "result", ")", "{", "// check if we have cache in settings", "if", "(", "!", "$", "requestBag", "->", "getApiConfig", "(", ")", "->", "get", "(", "'Cache'", ",", "false", ")", "||", "$", "requestBag", "->", "getMethodData", "(", ")", "[", "'cache'", "]", "[", "'ttl'", "]", "<=", "0", ")", "{", "return", "false", ";", "}", "$", "instance", "=", "new", "self", "(", "$", "requestBag", ")", ";", "return", "$", "instance", "->", "saveCallbackResult", "(", "$", "result", ")", ";", "}" ]
Saves the result from the given api request into cache. @param RequestBag $requestBag @param mixed $result @return bool
[ "Saves", "the", "result", "from", "the", "given", "api", "request", "into", "cache", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Cache.php#L58-L68
230,410
Webiny/Framework
src/Webiny/Component/Rest/Response/Cache.php
Cache.saveCallbackResult
public function saveCallbackResult($result) { // get cache key $cacheKey = $this->getCacheKey(); // cache the result try { $cache = $this->cache($this->requestBag->getApiConfig()->get('Cache')); return $cache->save($cacheKey, $result, $this->requestBag->getMethodData()['cache']['ttl']); } catch (\Exception $e) { throw new RestException('Unable to save the result into cache. ' . $e->getMessage()); } }
php
public function saveCallbackResult($result) { // get cache key $cacheKey = $this->getCacheKey(); // cache the result try { $cache = $this->cache($this->requestBag->getApiConfig()->get('Cache')); return $cache->save($cacheKey, $result, $this->requestBag->getMethodData()['cache']['ttl']); } catch (\Exception $e) { throw new RestException('Unable to save the result into cache. ' . $e->getMessage()); } }
[ "public", "function", "saveCallbackResult", "(", "$", "result", ")", "{", "// get cache key", "$", "cacheKey", "=", "$", "this", "->", "getCacheKey", "(", ")", ";", "// cache the result", "try", "{", "$", "cache", "=", "$", "this", "->", "cache", "(", "$", "this", "->", "requestBag", "->", "getApiConfig", "(", ")", "->", "get", "(", "'Cache'", ")", ")", ";", "return", "$", "cache", "->", "save", "(", "$", "cacheKey", ",", "$", "result", ",", "$", "this", "->", "requestBag", "->", "getMethodData", "(", ")", "[", "'cache'", "]", "[", "'ttl'", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "RestException", "(", "'Unable to save the result into cache. '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Saves the result into cache. @param mixed $result Result that should be saved. @return bool @throws \Webiny\Component\Rest\RestException
[ "Saves", "the", "result", "into", "cache", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Cache.php#L130-L143
230,411
Webiny/Framework
src/Webiny/Component/Rest/Response/Cache.php
Cache.getCacheKey
private function getCacheKey() { if ($this->requestBag->getClassData()['cacheKeyInterface']) { $cacheKey = $this->requestBag->getClassInstance()->getCacheKey(); } else { $url = $this->httpRequest()->getCurrentUrl(true); $cacheKey = 'path-' . $url->getPath(); $cacheKey .= 'query-' . $this->serialize($url->getQuery()); $cacheKey .= 'method-' . $this->httpRequest()->getRequestMethod(); $cacheKey .= 'post-' . $this->serialize($this->httpRequest()->getPost()->getAll()); $cacheKey .= 'payload-' . $this->serialize($this->httpRequest()->getPayload()->getAll()); $cacheKey .= 'version-' . $this->requestBag->getClassData()['version']; $cacheKey = md5($cacheKey); } return $cacheKey; }
php
private function getCacheKey() { if ($this->requestBag->getClassData()['cacheKeyInterface']) { $cacheKey = $this->requestBag->getClassInstance()->getCacheKey(); } else { $url = $this->httpRequest()->getCurrentUrl(true); $cacheKey = 'path-' . $url->getPath(); $cacheKey .= 'query-' . $this->serialize($url->getQuery()); $cacheKey .= 'method-' . $this->httpRequest()->getRequestMethod(); $cacheKey .= 'post-' . $this->serialize($this->httpRequest()->getPost()->getAll()); $cacheKey .= 'payload-' . $this->serialize($this->httpRequest()->getPayload()->getAll()); $cacheKey .= 'version-' . $this->requestBag->getClassData()['version']; $cacheKey = md5($cacheKey); } return $cacheKey; }
[ "private", "function", "getCacheKey", "(", ")", "{", "if", "(", "$", "this", "->", "requestBag", "->", "getClassData", "(", ")", "[", "'cacheKeyInterface'", "]", ")", "{", "$", "cacheKey", "=", "$", "this", "->", "requestBag", "->", "getClassInstance", "(", ")", "->", "getCacheKey", "(", ")", ";", "}", "else", "{", "$", "url", "=", "$", "this", "->", "httpRequest", "(", ")", "->", "getCurrentUrl", "(", "true", ")", ";", "$", "cacheKey", "=", "'path-'", ".", "$", "url", "->", "getPath", "(", ")", ";", "$", "cacheKey", ".=", "'query-'", ".", "$", "this", "->", "serialize", "(", "$", "url", "->", "getQuery", "(", ")", ")", ";", "$", "cacheKey", ".=", "'method-'", ".", "$", "this", "->", "httpRequest", "(", ")", "->", "getRequestMethod", "(", ")", ";", "$", "cacheKey", ".=", "'post-'", ".", "$", "this", "->", "serialize", "(", "$", "this", "->", "httpRequest", "(", ")", "->", "getPost", "(", ")", "->", "getAll", "(", ")", ")", ";", "$", "cacheKey", ".=", "'payload-'", ".", "$", "this", "->", "serialize", "(", "$", "this", "->", "httpRequest", "(", ")", "->", "getPayload", "(", ")", "->", "getAll", "(", ")", ")", ";", "$", "cacheKey", ".=", "'version-'", ".", "$", "this", "->", "requestBag", "->", "getClassData", "(", ")", "[", "'version'", "]", ";", "$", "cacheKey", "=", "md5", "(", "$", "cacheKey", ")", ";", "}", "return", "$", "cacheKey", ";", "}" ]
Computes the cache key, or gets it from the implemented interface from the api class. @return string Cache key.
[ "Computes", "the", "cache", "key", "or", "gets", "it", "from", "the", "implemented", "interface", "from", "the", "api", "class", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Cache.php#L171-L187
230,412
milesj/admin
Controller/UploadController.php
UploadController.index
public function index() { $data = $this->request->data; if ($this->request->is('post')) { $data['FileUpload']['user_id'] = $this->Auth->user('id'); try { if ($this->Model->save($data, true)) { $this->Model->set($data); $this->AdminToolbar->logAction(ActionLog::CREATE, $this->Model, $this->Model->id); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully uploaded a new file')); $this->request->data = array(); if ($data[$this->Model->alias]['redirect_to'] === 'read') { $this->redirect(array('plugin' => 'admin', 'controller' => 'crud', 'action' => 'read', 'model' => $this->Model->urlSlug, $this->Model->id)); } } } catch (Exception $e) { $this->AdminToolbar->setFlashMessage($e->getMessage(), 'is-error'); } } if (empty($this->request->data)) { $this->request->data['FileUpload'] = Configure::read('Admin.uploads'); } }
php
public function index() { $data = $this->request->data; if ($this->request->is('post')) { $data['FileUpload']['user_id'] = $this->Auth->user('id'); try { if ($this->Model->save($data, true)) { $this->Model->set($data); $this->AdminToolbar->logAction(ActionLog::CREATE, $this->Model, $this->Model->id); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully uploaded a new file')); $this->request->data = array(); if ($data[$this->Model->alias]['redirect_to'] === 'read') { $this->redirect(array('plugin' => 'admin', 'controller' => 'crud', 'action' => 'read', 'model' => $this->Model->urlSlug, $this->Model->id)); } } } catch (Exception $e) { $this->AdminToolbar->setFlashMessage($e->getMessage(), 'is-error'); } } if (empty($this->request->data)) { $this->request->data['FileUpload'] = Configure::read('Admin.uploads'); } }
[ "public", "function", "index", "(", ")", "{", "$", "data", "=", "$", "this", "->", "request", "->", "data", ";", "if", "(", "$", "this", "->", "request", "->", "is", "(", "'post'", ")", ")", "{", "$", "data", "[", "'FileUpload'", "]", "[", "'user_id'", "]", "=", "$", "this", "->", "Auth", "->", "user", "(", "'id'", ")", ";", "try", "{", "if", "(", "$", "this", "->", "Model", "->", "save", "(", "$", "data", ",", "true", ")", ")", "{", "$", "this", "->", "Model", "->", "set", "(", "$", "data", ")", ";", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "CREATE", ",", "$", "this", "->", "Model", ",", "$", "this", "->", "Model", "->", "id", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Successfully uploaded a new file'", ")", ")", ";", "$", "this", "->", "request", "->", "data", "=", "array", "(", ")", ";", "if", "(", "$", "data", "[", "$", "this", "->", "Model", "->", "alias", "]", "[", "'redirect_to'", "]", "===", "'read'", ")", "{", "$", "this", "->", "redirect", "(", "array", "(", "'plugin'", "=>", "'admin'", ",", "'controller'", "=>", "'crud'", ",", "'action'", "=>", "'read'", ",", "'model'", "=>", "$", "this", "->", "Model", "->", "urlSlug", ",", "$", "this", "->", "Model", "->", "id", ")", ")", ";", "}", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "$", "e", "->", "getMessage", "(", ")", ",", "'is-error'", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "this", "->", "request", "->", "data", ")", ")", "{", "$", "this", "->", "request", "->", "data", "[", "'FileUpload'", "]", "=", "Configure", "::", "read", "(", "'Admin.uploads'", ")", ";", "}", "}" ]
Upload a file and set transport and transform settings.
[ "Upload", "a", "file", "and", "set", "transport", "and", "transform", "settings", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/UploadController.php#L13-L39
230,413
OpenBuildings/jam
classes/Kohana/Jam/Behavior/Paranoid.php
Kohana_Jam_Behavior_Paranoid.builder_paranoid_filter
public function builder_paranoid_filter(Database_Query $builder) { $filter_type = $builder->params('paranoid_filter_type') ?: Jam_Behavior_Paranoid::filter(); switch ($filter_type) { case Jam_Behavior_Paranoid::ALL: break; case Jam_Behavior_Paranoid::DELETED: $builder->where($this->_field, '=', TRUE); break; case Jam_Behavior_Paranoid::NORMAL: default: $builder->where($this->_field, '=', FALSE); break; } }
php
public function builder_paranoid_filter(Database_Query $builder) { $filter_type = $builder->params('paranoid_filter_type') ?: Jam_Behavior_Paranoid::filter(); switch ($filter_type) { case Jam_Behavior_Paranoid::ALL: break; case Jam_Behavior_Paranoid::DELETED: $builder->where($this->_field, '=', TRUE); break; case Jam_Behavior_Paranoid::NORMAL: default: $builder->where($this->_field, '=', FALSE); break; } }
[ "public", "function", "builder_paranoid_filter", "(", "Database_Query", "$", "builder", ")", "{", "$", "filter_type", "=", "$", "builder", "->", "params", "(", "'paranoid_filter_type'", ")", "?", ":", "Jam_Behavior_Paranoid", "::", "filter", "(", ")", ";", "switch", "(", "$", "filter_type", ")", "{", "case", "Jam_Behavior_Paranoid", "::", "ALL", ":", "break", ";", "case", "Jam_Behavior_Paranoid", "::", "DELETED", ":", "$", "builder", "->", "where", "(", "$", "this", "->", "_field", ",", "'='", ",", "TRUE", ")", ";", "break", ";", "case", "Jam_Behavior_Paranoid", "::", "NORMAL", ":", "default", ":", "$", "builder", "->", "where", "(", "$", "this", "->", "_field", ",", "'='", ",", "FALSE", ")", ";", "break", ";", "}", "}" ]
Perform the actual where modification when it is needed @param Jam_Query_Builder_Select $builder
[ "Perform", "the", "actual", "where", "modification", "when", "it", "is", "needed" ]
3239e93564d100ddb65055235f87ec99fc0d4370
https://github.com/OpenBuildings/jam/blob/3239e93564d100ddb65055235f87ec99fc0d4370/classes/Kohana/Jam/Behavior/Paranoid.php#L65-L83
230,414
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php
Message.getTo
public function getTo() { $recipients = []; foreach ($this->message->getTo() as $email => $name) { $recipients[] = new Email($email, $name); } return $recipients; }
php
public function getTo() { $recipients = []; foreach ($this->message->getTo() as $email => $name) { $recipients[] = new Email($email, $name); } return $recipients; }
[ "public", "function", "getTo", "(", ")", "{", "$", "recipients", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "message", "->", "getTo", "(", ")", "as", "$", "email", "=>", "$", "name", ")", "{", "$", "recipients", "[", "]", "=", "new", "Email", "(", "$", "email", ",", "$", "name", ")", ";", "}", "return", "$", "recipients", ";", "}" ]
Returns a list of defined recipients. @return array
[ "Returns", "a", "list", "of", "defined", "recipients", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php#L100-L108
230,415
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php
Message.getCc
public function getCc() { $recipients = []; foreach ($this->message->getCc() as $email => $name) { $recipients[] = new Email($email, $name); } return $recipients; }
php
public function getCc() { $recipients = []; foreach ($this->message->getCc() as $email => $name) { $recipients[] = new Email($email, $name); } return $recipients; }
[ "public", "function", "getCc", "(", ")", "{", "$", "recipients", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "message", "->", "getCc", "(", ")", "as", "$", "email", "=>", "$", "name", ")", "{", "$", "recipients", "[", "]", "=", "new", "Email", "(", "$", "email", ",", "$", "name", ")", ";", "}", "return", "$", "recipients", ";", "}" ]
Returns a list of addresses to whom the message will be copied to. @return array
[ "Returns", "a", "list", "of", "addresses", "to", "whom", "the", "message", "will", "be", "copied", "to", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php#L115-L123
230,416
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php
Message.getBcc
public function getBcc() { $recipients = []; foreach ($this->message->getBcc() as $email => $name) { $recipients[] = new Email($email, $name); } return $recipients; }
php
public function getBcc() { $recipients = []; foreach ($this->message->getBcc() as $email => $name) { $recipients[] = new Email($email, $name); } return $recipients; }
[ "public", "function", "getBcc", "(", ")", "{", "$", "recipients", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "message", "->", "getBcc", "(", ")", "as", "$", "email", "=>", "$", "name", ")", "{", "$", "recipients", "[", "]", "=", "new", "Email", "(", "$", "email", ",", "$", "name", ")", ";", "}", "return", "$", "recipients", ";", "}" ]
Returns a list of defined bcc recipients. @return array
[ "Returns", "a", "list", "of", "defined", "bcc", "recipients", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php#L130-L138
230,417
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php
Message.setBody
public function setBody($content, $type = 'text/html', $charset = 'utf-8') { $this->message->setBody($content, $type, $charset); return $this; }
php
public function setBody($content, $type = 'text/html', $charset = 'utf-8') { $this->message->setBody($content, $type, $charset); return $this; }
[ "public", "function", "setBody", "(", "$", "content", ",", "$", "type", "=", "'text/html'", ",", "$", "charset", "=", "'utf-8'", ")", "{", "$", "this", "->", "message", "->", "setBody", "(", "$", "content", ",", "$", "type", ",", "$", "charset", ")", ";", "return", "$", "this", ";", "}" ]
Set the message body. @param string $content The content of the body. @param string $type Content type. Default 'text/html'. @param string $charset Content body charset. Default 'utf-8'. @return \Webiny\Component\Mailer\MessageInterface
[ "Set", "the", "message", "body", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php#L161-L166
230,418
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php
Message.setContentTransferEncoding
public function setContentTransferEncoding($encoding) { switch ($encoding) { case '7bit': $encoder = \Swift_Encoding::get7BitEncoding(); break; case '8bit': $encoder = \Swift_Encoding::get8BitEncoding(); break; case 'base64': $encoder = \Swift_Encoding::getBase64Encoding(); break; case 'qp': $encoder = \Swift_Encoding::getQpEncoding(); break; default: throw new SwiftMailerException('Invalid encoding name provided. Valid encodings are [7bit, 8bit, base64, qp].' ); break; } $this->message->setEncoder($encoder); return $this; }
php
public function setContentTransferEncoding($encoding) { switch ($encoding) { case '7bit': $encoder = \Swift_Encoding::get7BitEncoding(); break; case '8bit': $encoder = \Swift_Encoding::get8BitEncoding(); break; case 'base64': $encoder = \Swift_Encoding::getBase64Encoding(); break; case 'qp': $encoder = \Swift_Encoding::getQpEncoding(); break; default: throw new SwiftMailerException('Invalid encoding name provided. Valid encodings are [7bit, 8bit, base64, qp].' ); break; } $this->message->setEncoder($encoder); return $this; }
[ "public", "function", "setContentTransferEncoding", "(", "$", "encoding", ")", "{", "switch", "(", "$", "encoding", ")", "{", "case", "'7bit'", ":", "$", "encoder", "=", "\\", "Swift_Encoding", "::", "get7BitEncoding", "(", ")", ";", "break", ";", "case", "'8bit'", ":", "$", "encoder", "=", "\\", "Swift_Encoding", "::", "get8BitEncoding", "(", ")", ";", "break", ";", "case", "'base64'", ":", "$", "encoder", "=", "\\", "Swift_Encoding", "::", "getBase64Encoding", "(", ")", ";", "break", ";", "case", "'qp'", ":", "$", "encoder", "=", "\\", "Swift_Encoding", "::", "getQpEncoding", "(", ")", ";", "break", ";", "default", ":", "throw", "new", "SwiftMailerException", "(", "'Invalid encoding name provided.\n\t\t\t\t\t\t\t\t\t\t\t\tValid encodings are [7bit, 8bit, base64, qp].'", ")", ";", "break", ";", "}", "$", "this", "->", "message", "->", "setEncoder", "(", "$", "encoder", ")", ";", "return", "$", "this", ";", "}" ]
Specifies the encoding scheme in the message. @param string $encoding @return $this @throws SwiftMailerException
[ "Specifies", "the", "encoding", "scheme", "in", "the", "message", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php#L252-L281
230,419
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php
Message.getHeaders
public function getHeaders() { $swiftHeaders = $this->message->getHeaders()->listAll(); $headers = []; foreach ($swiftHeaders as $headerName) { $headers[$headerName] = $this->getHeader($headerName); } return $headers; }
php
public function getHeaders() { $swiftHeaders = $this->message->getHeaders()->listAll(); $headers = []; foreach ($swiftHeaders as $headerName) { $headers[$headerName] = $this->getHeader($headerName); } return $headers; }
[ "public", "function", "getHeaders", "(", ")", "{", "$", "swiftHeaders", "=", "$", "this", "->", "message", "->", "getHeaders", "(", ")", "->", "listAll", "(", ")", ";", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "swiftHeaders", "as", "$", "headerName", ")", "{", "$", "headers", "[", "$", "headerName", "]", "=", "$", "this", "->", "getHeader", "(", "$", "headerName", ")", ";", "}", "return", "$", "headers", ";", "}" ]
Get all headers from the message. @return array
[ "Get", "all", "headers", "from", "the", "message", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/SwiftMailer/Message.php#L443-L452
230,420
Webiny/Framework
src/Webiny/Component/Image/Bridge/Imagine/Imagine.php
Imagine.getLibraryInstance
private function getLibraryInstance($library) { switch ($library) { case 'gd': return new \Imagine\Gd\Imagine(); break; case 'imagick': return new \Imagine\Imagick\Imagine(); break; case 'gmagick': return new \Imagine\Gmagick\Imagine(); break; default: throw new ImagineException('Unsupported image library "' . $library . '". Cannot create Imagine instance.' ); break; } }
php
private function getLibraryInstance($library) { switch ($library) { case 'gd': return new \Imagine\Gd\Imagine(); break; case 'imagick': return new \Imagine\Imagick\Imagine(); break; case 'gmagick': return new \Imagine\Gmagick\Imagine(); break; default: throw new ImagineException('Unsupported image library "' . $library . '". Cannot create Imagine instance.' ); break; } }
[ "private", "function", "getLibraryInstance", "(", "$", "library", ")", "{", "switch", "(", "$", "library", ")", "{", "case", "'gd'", ":", "return", "new", "\\", "Imagine", "\\", "Gd", "\\", "Imagine", "(", ")", ";", "break", ";", "case", "'imagick'", ":", "return", "new", "\\", "Imagine", "\\", "Imagick", "\\", "Imagine", "(", ")", ";", "break", ";", "case", "'gmagick'", ":", "return", "new", "\\", "Imagine", "\\", "Gmagick", "\\", "Imagine", "(", ")", ";", "break", ";", "default", ":", "throw", "new", "ImagineException", "(", "'Unsupported image library \"'", ".", "$", "library", ".", "'\". Cannot create Imagine instance.'", ")", ";", "break", ";", "}", "}" ]
Create a library instance based on given library name. @param string $library Name of the library. Supported libraries are gd, imagick and gmagick. @return \Imagine\Gd\Imagine|\Imagine\Gmagick\Imagine|\Imagine\Imagick\Imagine @throws ImagineException
[ "Create", "a", "library", "instance", "based", "on", "given", "library", "name", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Imagine.php#L50-L70
230,421
Webiny/Framework
src/Webiny/Component/Router/Loader/ConfigLoader.php
ConfigLoader.getRouteCollection
public function getRouteCollection() { foreach ($this->config as $name => $routeConfig) { $this->routeCollection->add($name, $this->processRoute($routeConfig)); } unset($this->config); return $this->routeCollection; }
php
public function getRouteCollection() { foreach ($this->config as $name => $routeConfig) { $this->routeCollection->add($name, $this->processRoute($routeConfig)); } unset($this->config); return $this->routeCollection; }
[ "public", "function", "getRouteCollection", "(", ")", "{", "foreach", "(", "$", "this", "->", "config", "as", "$", "name", "=>", "$", "routeConfig", ")", "{", "$", "this", "->", "routeCollection", "->", "add", "(", "$", "name", ",", "$", "this", "->", "processRoute", "(", "$", "routeConfig", ")", ")", ";", "}", "unset", "(", "$", "this", "->", "config", ")", ";", "return", "$", "this", "->", "routeCollection", ";", "}" ]
Builds and returns RouteCollection instance. @return RouteCollection
[ "Builds", "and", "returns", "RouteCollection", "instance", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Loader/ConfigLoader.php#L51-L60
230,422
Webiny/Framework
src/Webiny/Component/Router/Loader/ConfigLoader.php
ConfigLoader.processRoute
public function processRoute(ConfigObject $routeConfig) { // base route $callback = $this->isString($routeConfig->Callback) ? $routeConfig->Callback : $routeConfig->Callback->toArray(); $route = new Route($routeConfig->Path, $callback); // route options if (($options = $routeConfig->get('Options', false)) !== false) { $route->setOptions($options->toArray()); } // host if (($host = $routeConfig->get('Host', false)) !== false) { $route->setHost($host); } // schemes if (($schemes = $routeConfig->get('Schemes', false)) !== false) { $route->setSchemes($schemes); } // methods if (($methods = $routeConfig->get('Methods', false)) !== false) { $route->setMethods($methods->toArray()); } // tags if (($tags = $routeConfig->get('Tags', false)) !== false) { $route->setTags($tags->toArray()); } return $route; }
php
public function processRoute(ConfigObject $routeConfig) { // base route $callback = $this->isString($routeConfig->Callback) ? $routeConfig->Callback : $routeConfig->Callback->toArray(); $route = new Route($routeConfig->Path, $callback); // route options if (($options = $routeConfig->get('Options', false)) !== false) { $route->setOptions($options->toArray()); } // host if (($host = $routeConfig->get('Host', false)) !== false) { $route->setHost($host); } // schemes if (($schemes = $routeConfig->get('Schemes', false)) !== false) { $route->setSchemes($schemes); } // methods if (($methods = $routeConfig->get('Methods', false)) !== false) { $route->setMethods($methods->toArray()); } // tags if (($tags = $routeConfig->get('Tags', false)) !== false) { $route->setTags($tags->toArray()); } return $route; }
[ "public", "function", "processRoute", "(", "ConfigObject", "$", "routeConfig", ")", "{", "// base route", "$", "callback", "=", "$", "this", "->", "isString", "(", "$", "routeConfig", "->", "Callback", ")", "?", "$", "routeConfig", "->", "Callback", ":", "$", "routeConfig", "->", "Callback", "->", "toArray", "(", ")", ";", "$", "route", "=", "new", "Route", "(", "$", "routeConfig", "->", "Path", ",", "$", "callback", ")", ";", "// route options", "if", "(", "(", "$", "options", "=", "$", "routeConfig", "->", "get", "(", "'Options'", ",", "false", ")", ")", "!==", "false", ")", "{", "$", "route", "->", "setOptions", "(", "$", "options", "->", "toArray", "(", ")", ")", ";", "}", "// host", "if", "(", "(", "$", "host", "=", "$", "routeConfig", "->", "get", "(", "'Host'", ",", "false", ")", ")", "!==", "false", ")", "{", "$", "route", "->", "setHost", "(", "$", "host", ")", ";", "}", "// schemes", "if", "(", "(", "$", "schemes", "=", "$", "routeConfig", "->", "get", "(", "'Schemes'", ",", "false", ")", ")", "!==", "false", ")", "{", "$", "route", "->", "setSchemes", "(", "$", "schemes", ")", ";", "}", "// methods", "if", "(", "(", "$", "methods", "=", "$", "routeConfig", "->", "get", "(", "'Methods'", ",", "false", ")", ")", "!==", "false", ")", "{", "$", "route", "->", "setMethods", "(", "$", "methods", "->", "toArray", "(", ")", ")", ";", "}", "// tags", "if", "(", "(", "$", "tags", "=", "$", "routeConfig", "->", "get", "(", "'Tags'", ",", "false", ")", ")", "!==", "false", ")", "{", "$", "route", "->", "setTags", "(", "$", "tags", "->", "toArray", "(", ")", ")", ";", "}", "return", "$", "route", ";", "}" ]
Builds a Route instance based on the given route config. @param ConfigObject $routeConfig A config object containing route parameters. @return Route
[ "Builds", "a", "Route", "instance", "based", "on", "the", "given", "route", "config", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Loader/ConfigLoader.php#L69-L101
230,423
deanblackborough/zf3-view-helpers
src/Bootstrap3Button.php
Bootstrap3Button.setStyle
public function setStyle(string $style): Bootstrap3Button { if (in_array($style, $this->supported_styles) === true) { $this->style = $style; } else { $this->style = 'default'; } return $this; }
php
public function setStyle(string $style): Bootstrap3Button { if (in_array($style, $this->supported_styles) === true) { $this->style = $style; } else { $this->style = 'default'; } return $this; }
[ "public", "function", "setStyle", "(", "string", "$", "style", ")", ":", "Bootstrap3Button", "{", "if", "(", "in_array", "(", "$", "style", ",", "$", "this", "->", "supported_styles", ")", "===", "true", ")", "{", "$", "this", "->", "style", "=", "$", "style", ";", "}", "else", "{", "$", "this", "->", "style", "=", "'default'", ";", "}", "return", "$", "this", ";", "}" ]
Set the style for the button, one of the following, default, primary, success, info, warning, danger or link. If an incorrect style is passed in we set the style to btn-default @param string $style @return Bootstrap3Button
[ "Set", "the", "style", "for", "the", "button", "one", "of", "the", "following", "default", "primary", "success", "info", "warning", "danger", "or", "link", ".", "If", "an", "incorrect", "style", "is", "passed", "in", "we", "set", "the", "style", "to", "btn", "-", "default" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap3Button.php#L117-L126
230,424
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Css.php
Css._registerBlock
protected function _registerBlock(&$block, array $breakpoints = null) { $this->_blocks[] = array($breakpoints, $this->_minify($block)); $block = ''; }
php
protected function _registerBlock(&$block, array $breakpoints = null) { $this->_blocks[] = array($breakpoints, $this->_minify($block)); $block = ''; }
[ "protected", "function", "_registerBlock", "(", "&", "$", "block", ",", "array", "$", "breakpoints", "=", "null", ")", "{", "$", "this", "->", "_blocks", "[", "]", "=", "array", "(", "$", "breakpoints", ",", "$", "this", "->", "_minify", "(", "$", "block", ")", ")", ";", "$", "block", "=", "''", ";", "}" ]
Register block data @param string $block Block data @param array $breakpoints Breakpoints
[ "Register", "block", "data" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Css.php#L449-L453
230,425
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Css.php
Css._consumeDeclarationBlock
protected function _consumeDeclarationBlock($css, $peek, $offset = 0, &$declarationBlockStart = 0) { $declarationBlockStart = strpos($css, '{', $offset); if ($declarationBlockStart === false) { throw new \Tollwerk\Squeezr\Exception(sprintf(\Tollwerk\Squeezr\Exception::INVALID_DECLARATION_BLOCK_STR, $this->_peekToLine($peek)), \Tollwerk\Squeezr\Exception::INVALID_DECLARATION_BLOCK); } $declarationBlockBalance = 1; $declarationBlockPosition = $declarationBlockStart + 1; while ($declarationBlockBalance > 0) { // If either a block start or end delimiter is found if (preg_match("%[\{\}]%", $css, $declarationBlockDelimiter, PREG_OFFSET_CAPTURE, $declarationBlockPosition)) { $declarationBlockBalance += ($declarationBlockDelimiter[0][0] == '{') ? 1 : -1; $declarationBlockPosition = $declarationBlockDelimiter[0][1] + 1; // Else: error } else { throw new \Tollwerk\Squeezr\Exception(sprintf(\Tollwerk\Squeezr\Exception::UNBALANCED_DECLARATION_BLOCK_STR, $this->_peekToLine($peek)), \Tollwerk\Squeezr\Exception::UNBALANCED_DECLARATION_BLOCK); } } return substr($css, 0, $declarationBlockPosition); }
php
protected function _consumeDeclarationBlock($css, $peek, $offset = 0, &$declarationBlockStart = 0) { $declarationBlockStart = strpos($css, '{', $offset); if ($declarationBlockStart === false) { throw new \Tollwerk\Squeezr\Exception(sprintf(\Tollwerk\Squeezr\Exception::INVALID_DECLARATION_BLOCK_STR, $this->_peekToLine($peek)), \Tollwerk\Squeezr\Exception::INVALID_DECLARATION_BLOCK); } $declarationBlockBalance = 1; $declarationBlockPosition = $declarationBlockStart + 1; while ($declarationBlockBalance > 0) { // If either a block start or end delimiter is found if (preg_match("%[\{\}]%", $css, $declarationBlockDelimiter, PREG_OFFSET_CAPTURE, $declarationBlockPosition)) { $declarationBlockBalance += ($declarationBlockDelimiter[0][0] == '{') ? 1 : -1; $declarationBlockPosition = $declarationBlockDelimiter[0][1] + 1; // Else: error } else { throw new \Tollwerk\Squeezr\Exception(sprintf(\Tollwerk\Squeezr\Exception::UNBALANCED_DECLARATION_BLOCK_STR, $this->_peekToLine($peek)), \Tollwerk\Squeezr\Exception::UNBALANCED_DECLARATION_BLOCK); } } return substr($css, 0, $declarationBlockPosition); }
[ "protected", "function", "_consumeDeclarationBlock", "(", "$", "css", ",", "$", "peek", ",", "$", "offset", "=", "0", ",", "&", "$", "declarationBlockStart", "=", "0", ")", "{", "$", "declarationBlockStart", "=", "strpos", "(", "$", "css", ",", "'{'", ",", "$", "offset", ")", ";", "if", "(", "$", "declarationBlockStart", "===", "false", ")", "{", "throw", "new", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "(", "sprintf", "(", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "INVALID_DECLARATION_BLOCK_STR", ",", "$", "this", "->", "_peekToLine", "(", "$", "peek", ")", ")", ",", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "INVALID_DECLARATION_BLOCK", ")", ";", "}", "$", "declarationBlockBalance", "=", "1", ";", "$", "declarationBlockPosition", "=", "$", "declarationBlockStart", "+", "1", ";", "while", "(", "$", "declarationBlockBalance", ">", "0", ")", "{", "// If either a block start or end delimiter is found", "if", "(", "preg_match", "(", "\"%[\\{\\}]%\"", ",", "$", "css", ",", "$", "declarationBlockDelimiter", ",", "PREG_OFFSET_CAPTURE", ",", "$", "declarationBlockPosition", ")", ")", "{", "$", "declarationBlockBalance", "+=", "(", "$", "declarationBlockDelimiter", "[", "0", "]", "[", "0", "]", "==", "'{'", ")", "?", "1", ":", "-", "1", ";", "$", "declarationBlockPosition", "=", "$", "declarationBlockDelimiter", "[", "0", "]", "[", "1", "]", "+", "1", ";", "// Else: error", "}", "else", "{", "throw", "new", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "(", "sprintf", "(", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "UNBALANCED_DECLARATION_BLOCK_STR", ",", "$", "this", "->", "_peekToLine", "(", "$", "peek", ")", ")", ",", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "UNBALANCED_DECLARATION_BLOCK", ")", ";", "}", "}", "return", "substr", "(", "$", "css", ",", "0", ",", "$", "declarationBlockPosition", ")", ";", "}" ]
Detect and consume a declaration block within the given CSS text @param string $css CSS text @param int $peek Current peek (for line number detection in case of an error) @param int $offset Optional: Offset position @param int $declarationBlockStart Set by reference: Declaration block start position within the CSS text @return string Declaration block (starting at the beginning of the CSS text) @throws \Tollwerk\Squeezr\Exception If there is no declaration block starting or if it's unbalanced
[ "Detect", "and", "consume", "a", "declaration", "block", "within", "the", "given", "CSS", "text" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Css.php#L465-L491
230,426
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Css.php
Css._peekToLine
protected function _peekToLine($peek) { foreach ($this->_lines as $line => $length) { if ($length >= $peek) { break; } } return $line; }
php
protected function _peekToLine($peek) { foreach ($this->_lines as $line => $length) { if ($length >= $peek) { break; } } return $line; }
[ "protected", "function", "_peekToLine", "(", "$", "peek", ")", "{", "foreach", "(", "$", "this", "->", "_lines", "as", "$", "line", "=>", "$", "length", ")", "{", "if", "(", "$", "length", ">=", "$", "peek", ")", "{", "break", ";", "}", "}", "return", "$", "line", ";", "}" ]
Find the line number corresponding with a peek position within the CSS file @param int $peek Peek position @return int Line number
[ "Find", "the", "line", "number", "corresponding", "with", "a", "peek", "position", "within", "the", "CSS", "file" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Css.php#L584-L592
230,427
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Css.php
Css._compileCacheClassCode
protected function _compileCacheClassCode() { // Instantiate a minification provider (if enabled) if (SQUEEZR_CSS_MINIFY) { $this->_minifier = new Minify(); } // Parse the CSS file and extract breakpoint and CSS block info $this->_parse(); // Compile a corresponding PHP cache class $cacheClassCode = strtr(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Css'.DIRECTORY_SEPARATOR.'Cache.php'), array( 'FILEHASH' => md5($this->_relativeCssPath), "'BREAKPOINTS'" => var_export($this->_breakpointIndex, true), "'BLOCKS'" => var_export($this->_blocks, true), )); // Return the PHP cache class code return $cacheClassCode; }
php
protected function _compileCacheClassCode() { // Instantiate a minification provider (if enabled) if (SQUEEZR_CSS_MINIFY) { $this->_minifier = new Minify(); } // Parse the CSS file and extract breakpoint and CSS block info $this->_parse(); // Compile a corresponding PHP cache class $cacheClassCode = strtr(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Css'.DIRECTORY_SEPARATOR.'Cache.php'), array( 'FILEHASH' => md5($this->_relativeCssPath), "'BREAKPOINTS'" => var_export($this->_breakpointIndex, true), "'BLOCKS'" => var_export($this->_blocks, true), )); // Return the PHP cache class code return $cacheClassCode; }
[ "protected", "function", "_compileCacheClassCode", "(", ")", "{", "// Instantiate a minification provider (if enabled)", "if", "(", "SQUEEZR_CSS_MINIFY", ")", "{", "$", "this", "->", "_minifier", "=", "new", "Minify", "(", ")", ";", "}", "// Parse the CSS file and extract breakpoint and CSS block info", "$", "this", "->", "_parse", "(", ")", ";", "// Compile a corresponding PHP cache class", "$", "cacheClassCode", "=", "strtr", "(", "file_get_contents", "(", "__DIR__", ".", "DIRECTORY_SEPARATOR", ".", "'Css'", ".", "DIRECTORY_SEPARATOR", ".", "'Cache.php'", ")", ",", "array", "(", "'FILEHASH'", "=>", "md5", "(", "$", "this", "->", "_relativeCssPath", ")", ",", "\"'BREAKPOINTS'\"", "=>", "var_export", "(", "$", "this", "->", "_breakpointIndex", ",", "true", ")", ",", "\"'BLOCKS'\"", "=>", "var_export", "(", "$", "this", "->", "_blocks", ",", "true", ")", ",", ")", ")", ";", "// Return the PHP cache class code", "return", "$", "cacheClassCode", ";", "}" ]
Compile a PHP cache class representing the loaded CSS stylesheet @return string PHP class code @throws \Tollwerk\Squeezr\Css\Minifier\Exception If an invalid minification provider has been requested
[ "Compile", "a", "PHP", "cache", "class", "representing", "the", "loaded", "CSS", "stylesheet" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Css.php#L611-L631
230,428
Webiny/Framework
src/Webiny/Component/Mailer/Mailer.php
Mailer.getMessage
public function getMessage($config = null) { if ($config && !$config instanceof ConfigObject) { $config = new ConfigObject($config); } return Loader::getMessage($this->mailerName, $config); }
php
public function getMessage($config = null) { if ($config && !$config instanceof ConfigObject) { $config = new ConfigObject($config); } return Loader::getMessage($this->mailerName, $config); }
[ "public", "function", "getMessage", "(", "$", "config", "=", "null", ")", "{", "if", "(", "$", "config", "&&", "!", "$", "config", "instanceof", "ConfigObject", ")", "{", "$", "config", "=", "new", "ConfigObject", "(", "$", "config", ")", ";", "}", "return", "Loader", "::", "getMessage", "(", "$", "this", "->", "mailerName", ",", "$", "config", ")", ";", "}" ]
Creates a new message. @param array|ArrayObject|ConfigObject $config (Optional) @return MessageInterface @throws Bridge\MailerException
[ "Creates", "a", "new", "message", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Mailer.php#L59-L65
230,429
Webiny/Framework
src/Webiny/Component/Entity/EntityDataExtractor.php
EntityDataExtractor.buildFields
private function buildFields(&$parsedFields, StringObject $key) { if ($key->contains('.')) { $parts = $key->explode('.', 2)->val(); if (!isset($parsedFields[$parts[0]])) { $parsedFields[$parts[0]] = []; } elseif (!is_array($parsedFields[$parts[0]])) { $parsedFields[$parts[0]] = []; } $this->buildFields($parsedFields[$parts[0]], $this->str($parts[1])); } else { $parsedFields[$key->val()] = ''; } }
php
private function buildFields(&$parsedFields, StringObject $key) { if ($key->contains('.')) { $parts = $key->explode('.', 2)->val(); if (!isset($parsedFields[$parts[0]])) { $parsedFields[$parts[0]] = []; } elseif (!is_array($parsedFields[$parts[0]])) { $parsedFields[$parts[0]] = []; } $this->buildFields($parsedFields[$parts[0]], $this->str($parts[1])); } else { $parsedFields[$key->val()] = ''; } }
[ "private", "function", "buildFields", "(", "&", "$", "parsedFields", ",", "StringObject", "$", "key", ")", "{", "if", "(", "$", "key", "->", "contains", "(", "'.'", ")", ")", "{", "$", "parts", "=", "$", "key", "->", "explode", "(", "'.'", ",", "2", ")", "->", "val", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "parsedFields", "[", "$", "parts", "[", "0", "]", "]", ")", ")", "{", "$", "parsedFields", "[", "$", "parts", "[", "0", "]", "]", "=", "[", "]", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "parsedFields", "[", "$", "parts", "[", "0", "]", "]", ")", ")", "{", "$", "parsedFields", "[", "$", "parts", "[", "0", "]", "]", "=", "[", "]", ";", "}", "$", "this", "->", "buildFields", "(", "$", "parsedFields", "[", "$", "parts", "[", "0", "]", "]", ",", "$", "this", "->", "str", "(", "$", "parts", "[", "1", "]", ")", ")", ";", "}", "else", "{", "$", "parsedFields", "[", "$", "key", "->", "val", "(", ")", "]", "=", "''", ";", "}", "}" ]
Parse attribute key recursively @param ArrayObject $parsedFields Reference to array of parsed fields @param StringObject $key Current key to parse
[ "Parse", "attribute", "key", "recursively" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/EntityDataExtractor.php#L320-L334
230,430
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.init
protected function init() { $this->query = new Query(); $this->post = new Post(); $this->payload = new Payload(); $this->server = new Server(); $this->files = new Files(); $this->env = new Env(); $this->headers = new Headers(); }
php
protected function init() { $this->query = new Query(); $this->post = new Post(); $this->payload = new Payload(); $this->server = new Server(); $this->files = new Files(); $this->env = new Env(); $this->headers = new Headers(); }
[ "protected", "function", "init", "(", ")", "{", "$", "this", "->", "query", "=", "new", "Query", "(", ")", ";", "$", "this", "->", "post", "=", "new", "Post", "(", ")", ";", "$", "this", "->", "payload", "=", "new", "Payload", "(", ")", ";", "$", "this", "->", "server", "=", "new", "Server", "(", ")", ";", "$", "this", "->", "files", "=", "new", "Files", "(", ")", ";", "$", "this", "->", "env", "=", "new", "Env", "(", ")", ";", "$", "this", "->", "headers", "=", "new", "Headers", "(", ")", ";", "}" ]
This function prepare the Request and all of its sub-classes. This class is called automatically by SingletonTrait.
[ "This", "function", "prepare", "the", "Request", "and", "all", "of", "its", "sub", "-", "classes", ".", "This", "class", "is", "called", "automatically", "by", "SingletonTrait", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L87-L96
230,431
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.getTrustedHeaders
public function getTrustedHeaders() { $trustedHeaders = Http::getConfig()->TrustedHeaders; return [ 'client_ip' => $trustedHeaders->get('client_ip', self::HEADER_CLIENT_IP), 'client_host' => $trustedHeaders->get('client_host', self::HEADER_CLIENT_HOST), 'client_proto' => $trustedHeaders->get('client_proto', self::HEADER_CLIENT_PROTO), 'client_port' => $trustedHeaders->get('client_port', self::HEADER_CLIENT_PORT), ]; }
php
public function getTrustedHeaders() { $trustedHeaders = Http::getConfig()->TrustedHeaders; return [ 'client_ip' => $trustedHeaders->get('client_ip', self::HEADER_CLIENT_IP), 'client_host' => $trustedHeaders->get('client_host', self::HEADER_CLIENT_HOST), 'client_proto' => $trustedHeaders->get('client_proto', self::HEADER_CLIENT_PROTO), 'client_port' => $trustedHeaders->get('client_port', self::HEADER_CLIENT_PORT), ]; }
[ "public", "function", "getTrustedHeaders", "(", ")", "{", "$", "trustedHeaders", "=", "Http", "::", "getConfig", "(", ")", "->", "TrustedHeaders", ";", "return", "[", "'client_ip'", "=>", "$", "trustedHeaders", "->", "get", "(", "'client_ip'", ",", "self", "::", "HEADER_CLIENT_IP", ")", ",", "'client_host'", "=>", "$", "trustedHeaders", "->", "get", "(", "'client_host'", ",", "self", "::", "HEADER_CLIENT_HOST", ")", ",", "'client_proto'", "=>", "$", "trustedHeaders", "->", "get", "(", "'client_proto'", ",", "self", "::", "HEADER_CLIENT_PROTO", ")", ",", "'client_port'", "=>", "$", "trustedHeaders", "->", "get", "(", "'client_port'", ",", "self", "::", "HEADER_CLIENT_PORT", ")", ",", "]", ";", "}" ]
Get a list of trusted headers. @return array List of trusted headers.
[ "Get", "a", "list", "of", "trusted", "headers", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L243-L253
230,432
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.getCurrentUrl
public function getCurrentUrl($asUrlObject = false) { if ($this->currentUrl == '') { // schema $pageURL = 'http'; if ($this->isRequestSecured()) { $pageURL = 'https'; } $pageURL .= "://"; // port, server name and request uri $host = $this->getHostName(); $port = $this->getConnectionPort(); if ($port && $port != '80' && $port != '443') { $pageURL .= $host . ":" . $port . $this->server()->requestUri(); } else { $pageURL .= $host . $this->server()->requestUri(); } // query $query = $this->server()->queryString(); if ($query && strpos($pageURL, '?') === false) { $pageURL .= '?' . $query; } $this->currentUrl = $pageURL; } if ($asUrlObject) { return $this->url($this->currentUrl); } else { return $this->currentUrl; } }
php
public function getCurrentUrl($asUrlObject = false) { if ($this->currentUrl == '') { // schema $pageURL = 'http'; if ($this->isRequestSecured()) { $pageURL = 'https'; } $pageURL .= "://"; // port, server name and request uri $host = $this->getHostName(); $port = $this->getConnectionPort(); if ($port && $port != '80' && $port != '443') { $pageURL .= $host . ":" . $port . $this->server()->requestUri(); } else { $pageURL .= $host . $this->server()->requestUri(); } // query $query = $this->server()->queryString(); if ($query && strpos($pageURL, '?') === false) { $pageURL .= '?' . $query; } $this->currentUrl = $pageURL; } if ($asUrlObject) { return $this->url($this->currentUrl); } else { return $this->currentUrl; } }
[ "public", "function", "getCurrentUrl", "(", "$", "asUrlObject", "=", "false", ")", "{", "if", "(", "$", "this", "->", "currentUrl", "==", "''", ")", "{", "// schema", "$", "pageURL", "=", "'http'", ";", "if", "(", "$", "this", "->", "isRequestSecured", "(", ")", ")", "{", "$", "pageURL", "=", "'https'", ";", "}", "$", "pageURL", ".=", "\"://\"", ";", "// port, server name and request uri", "$", "host", "=", "$", "this", "->", "getHostName", "(", ")", ";", "$", "port", "=", "$", "this", "->", "getConnectionPort", "(", ")", ";", "if", "(", "$", "port", "&&", "$", "port", "!=", "'80'", "&&", "$", "port", "!=", "'443'", ")", "{", "$", "pageURL", ".=", "$", "host", ".", "\":\"", ".", "$", "port", ".", "$", "this", "->", "server", "(", ")", "->", "requestUri", "(", ")", ";", "}", "else", "{", "$", "pageURL", ".=", "$", "host", ".", "$", "this", "->", "server", "(", ")", "->", "requestUri", "(", ")", ";", "}", "// query", "$", "query", "=", "$", "this", "->", "server", "(", ")", "->", "queryString", "(", ")", ";", "if", "(", "$", "query", "&&", "strpos", "(", "$", "pageURL", ",", "'?'", ")", "===", "false", ")", "{", "$", "pageURL", ".=", "'?'", ".", "$", "query", ";", "}", "$", "this", "->", "currentUrl", "=", "$", "pageURL", ";", "}", "if", "(", "$", "asUrlObject", ")", "{", "return", "$", "this", "->", "url", "(", "$", "this", "->", "currentUrl", ")", ";", "}", "else", "{", "return", "$", "this", "->", "currentUrl", ";", "}", "}" ]
Get current url with schema, host, port, request uri and query string. You can get the result in a form of a string or as a url standard object. @param bool $asUrlObject In which format you want to get the result, url standard object or a string. @return string|\Webiny\Component\StdLib\StdObject\UrlObject\UrlObject Current url.
[ "Get", "current", "url", "with", "schema", "host", "port", "request", "uri", "and", "query", "string", ".", "You", "can", "get", "the", "result", "in", "a", "form", "of", "a", "string", "or", "as", "a", "url", "standard", "object", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L263-L297
230,433
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.getClientIp
public function getClientIp() { $remoteAddress = $this->server()->remoteAddress(); $fwdClientIp = $this->server()->get($this->getTrustedHeaders()['client_ip']); if ($fwdClientIp && $remoteAddress && in_array($remoteAddress, $this->getTrustedProxies())) { // Use the forwarded IP address, typically set when the // client is using a proxy server. // Format: "X-Forwarded-For: client1, proxy1, proxy2" $clientIps = explode(',', $fwdClientIp); $clientIp = array_shift($clientIps); } elseif ($fwdClientIp && in_array('*', $this->getTrustedProxies())) { $clientIps = explode(',', $fwdClientIp); $clientIp = array_shift($clientIps); } elseif ($this->server()->httpClientIp() && $remoteAddress && in_array($remoteAddress, $this->getTrustedProxies())) { // Use the forwarded IP address, typically set when the // client is using a proxy server. $clientIps = explode(',', $this->server()->httpClientIp()); $clientIp = array_shift($clientIps); } elseif ($this->server()->remoteAddress()) { // The remote IP address $clientIp = $this->server()->remoteAddress(); } else { return false; } return $clientIp; }
php
public function getClientIp() { $remoteAddress = $this->server()->remoteAddress(); $fwdClientIp = $this->server()->get($this->getTrustedHeaders()['client_ip']); if ($fwdClientIp && $remoteAddress && in_array($remoteAddress, $this->getTrustedProxies())) { // Use the forwarded IP address, typically set when the // client is using a proxy server. // Format: "X-Forwarded-For: client1, proxy1, proxy2" $clientIps = explode(',', $fwdClientIp); $clientIp = array_shift($clientIps); } elseif ($fwdClientIp && in_array('*', $this->getTrustedProxies())) { $clientIps = explode(',', $fwdClientIp); $clientIp = array_shift($clientIps); } elseif ($this->server()->httpClientIp() && $remoteAddress && in_array($remoteAddress, $this->getTrustedProxies())) { // Use the forwarded IP address, typically set when the // client is using a proxy server. $clientIps = explode(',', $this->server()->httpClientIp()); $clientIp = array_shift($clientIps); } elseif ($this->server()->remoteAddress()) { // The remote IP address $clientIp = $this->server()->remoteAddress(); } else { return false; } return $clientIp; }
[ "public", "function", "getClientIp", "(", ")", "{", "$", "remoteAddress", "=", "$", "this", "->", "server", "(", ")", "->", "remoteAddress", "(", ")", ";", "$", "fwdClientIp", "=", "$", "this", "->", "server", "(", ")", "->", "get", "(", "$", "this", "->", "getTrustedHeaders", "(", ")", "[", "'client_ip'", "]", ")", ";", "if", "(", "$", "fwdClientIp", "&&", "$", "remoteAddress", "&&", "in_array", "(", "$", "remoteAddress", ",", "$", "this", "->", "getTrustedProxies", "(", ")", ")", ")", "{", "// Use the forwarded IP address, typically set when the", "// client is using a proxy server.", "// Format: \"X-Forwarded-For: client1, proxy1, proxy2\"", "$", "clientIps", "=", "explode", "(", "','", ",", "$", "fwdClientIp", ")", ";", "$", "clientIp", "=", "array_shift", "(", "$", "clientIps", ")", ";", "}", "elseif", "(", "$", "fwdClientIp", "&&", "in_array", "(", "'*'", ",", "$", "this", "->", "getTrustedProxies", "(", ")", ")", ")", "{", "$", "clientIps", "=", "explode", "(", "','", ",", "$", "fwdClientIp", ")", ";", "$", "clientIp", "=", "array_shift", "(", "$", "clientIps", ")", ";", "}", "elseif", "(", "$", "this", "->", "server", "(", ")", "->", "httpClientIp", "(", ")", "&&", "$", "remoteAddress", "&&", "in_array", "(", "$", "remoteAddress", ",", "$", "this", "->", "getTrustedProxies", "(", ")", ")", ")", "{", "// Use the forwarded IP address, typically set when the", "// client is using a proxy server.", "$", "clientIps", "=", "explode", "(", "','", ",", "$", "this", "->", "server", "(", ")", "->", "httpClientIp", "(", ")", ")", ";", "$", "clientIp", "=", "array_shift", "(", "$", "clientIps", ")", ";", "}", "elseif", "(", "$", "this", "->", "server", "(", ")", "->", "remoteAddress", "(", ")", ")", "{", "// The remote IP address", "$", "clientIp", "=", "$", "this", "->", "server", "(", ")", "->", "remoteAddress", "(", ")", ";", "}", "else", "{", "return", "false", ";", "}", "return", "$", "clientIp", ";", "}" ]
Get client ip address. This function check and validates headers from trusted proxies. @return string Client IP address.
[ "Get", "client", "ip", "address", ".", "This", "function", "check", "and", "validates", "headers", "from", "trusted", "proxies", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L316-L343
230,434
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.isRequestSecured
public function isRequestSecured() { $remoteAddress = $this->server()->remoteAddress(); $protocol = $this->server()->serverProtocol(); $fwdProto = $this->server()->get($this->getTrustedHeaders()['client_proto']); if ($fwdProto && $fwdProto != '' && in_array($remoteAddress, $this->getTrustedProxies())) { $protocol = $fwdProto; } $protocol = strtolower($protocol); $isSecured = in_array($protocol, [ 'https', 'on', '1' ]); if (!$isSecured) { if (in_array(strtolower($this->server()->https()), [ 'https', 'on', '1' ])) { $isSecured = true; } } return $isSecured; }
php
public function isRequestSecured() { $remoteAddress = $this->server()->remoteAddress(); $protocol = $this->server()->serverProtocol(); $fwdProto = $this->server()->get($this->getTrustedHeaders()['client_proto']); if ($fwdProto && $fwdProto != '' && in_array($remoteAddress, $this->getTrustedProxies())) { $protocol = $fwdProto; } $protocol = strtolower($protocol); $isSecured = in_array($protocol, [ 'https', 'on', '1' ]); if (!$isSecured) { if (in_array(strtolower($this->server()->https()), [ 'https', 'on', '1' ])) { $isSecured = true; } } return $isSecured; }
[ "public", "function", "isRequestSecured", "(", ")", "{", "$", "remoteAddress", "=", "$", "this", "->", "server", "(", ")", "->", "remoteAddress", "(", ")", ";", "$", "protocol", "=", "$", "this", "->", "server", "(", ")", "->", "serverProtocol", "(", ")", ";", "$", "fwdProto", "=", "$", "this", "->", "server", "(", ")", "->", "get", "(", "$", "this", "->", "getTrustedHeaders", "(", ")", "[", "'client_proto'", "]", ")", ";", "if", "(", "$", "fwdProto", "&&", "$", "fwdProto", "!=", "''", "&&", "in_array", "(", "$", "remoteAddress", ",", "$", "this", "->", "getTrustedProxies", "(", ")", ")", ")", "{", "$", "protocol", "=", "$", "fwdProto", ";", "}", "$", "protocol", "=", "strtolower", "(", "$", "protocol", ")", ";", "$", "isSecured", "=", "in_array", "(", "$", "protocol", ",", "[", "'https'", ",", "'on'", ",", "'1'", "]", ")", ";", "if", "(", "!", "$", "isSecured", ")", "{", "if", "(", "in_array", "(", "strtolower", "(", "$", "this", "->", "server", "(", ")", "->", "https", "(", ")", ")", ",", "[", "'https'", ",", "'on'", ",", "'1'", "]", ")", ")", "{", "$", "isSecured", "=", "true", ";", "}", "}", "return", "$", "isSecured", ";", "}" ]
Check if connection is secured. This function check the forwarded headers from trusted proxies. @return bool True if connection is secured (https), otherwise false is returned.
[ "Check", "if", "connection", "is", "secured", ".", "This", "function", "check", "the", "forwarded", "headers", "from", "trusted", "proxies", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L351-L379
230,435
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.getConnectionPort
public function getConnectionPort() { $port = 80; $host = $this->server()->httpHost(); if (empty($host)) { return $port; } $host = $this->str($host); if ($host->contains(':')) { $port = $host->explode(':')->last(); } return $port; }
php
public function getConnectionPort() { $port = 80; $host = $this->server()->httpHost(); if (empty($host)) { return $port; } $host = $this->str($host); if ($host->contains(':')) { $port = $host->explode(':')->last(); } return $port; }
[ "public", "function", "getConnectionPort", "(", ")", "{", "$", "port", "=", "80", ";", "$", "host", "=", "$", "this", "->", "server", "(", ")", "->", "httpHost", "(", ")", ";", "if", "(", "empty", "(", "$", "host", ")", ")", "{", "return", "$", "port", ";", "}", "$", "host", "=", "$", "this", "->", "str", "(", "$", "host", ")", ";", "if", "(", "$", "host", "->", "contains", "(", "':'", ")", ")", "{", "$", "port", "=", "$", "host", "->", "explode", "(", "':'", ")", "->", "last", "(", ")", ";", "}", "return", "$", "port", ";", "}" ]
Return the connection port number. This function check the forwarded headers from trusted proxies. @return int Port number.
[ "Return", "the", "connection", "port", "number", ".", "This", "function", "check", "the", "forwarded", "headers", "from", "trusted", "proxies", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L387-L402
230,436
Webiny/Framework
src/Webiny/Component/Http/Request.php
Request.getHostName
public function getHostName() { $remoteAddress = $this->server()->remoteAddress(); $host = $this->server()->serverName(); $fwdHost = $this->server()->get($this->getTrustedHeaders()['client_host']); if ($fwdHost && $fwdHost != '' && in_array($remoteAddress, $this->getTrustedProxies())) { $host = $fwdHost; } return strtolower($host); }
php
public function getHostName() { $remoteAddress = $this->server()->remoteAddress(); $host = $this->server()->serverName(); $fwdHost = $this->server()->get($this->getTrustedHeaders()['client_host']); if ($fwdHost && $fwdHost != '' && in_array($remoteAddress, $this->getTrustedProxies())) { $host = $fwdHost; } return strtolower($host); }
[ "public", "function", "getHostName", "(", ")", "{", "$", "remoteAddress", "=", "$", "this", "->", "server", "(", ")", "->", "remoteAddress", "(", ")", ";", "$", "host", "=", "$", "this", "->", "server", "(", ")", "->", "serverName", "(", ")", ";", "$", "fwdHost", "=", "$", "this", "->", "server", "(", ")", "->", "get", "(", "$", "this", "->", "getTrustedHeaders", "(", ")", "[", "'client_host'", "]", ")", ";", "if", "(", "$", "fwdHost", "&&", "$", "fwdHost", "!=", "''", "&&", "in_array", "(", "$", "remoteAddress", ",", "$", "this", "->", "getTrustedProxies", "(", ")", ")", ")", "{", "$", "host", "=", "$", "fwdHost", ";", "}", "return", "strtolower", "(", "$", "host", ")", ";", "}" ]
Returns the host name. This function check the forwarded headers from trusted proxies. @return string Host name
[ "Returns", "the", "host", "name", ".", "This", "function", "check", "the", "forwarded", "headers", "from", "trusted", "proxies", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request.php#L410-L421
230,437
Webiny/Framework
src/Webiny/Component/Rest/Response/Security.php
Security.hasAccess
public static function hasAccess(RequestBag $requestBag) { // first we check if method requires a special access level if (!$requestBag->getApiConfig()->get('Security', false)) { return true; // no special access level required } // get the required role if (isset($requestBag->getMethodData()['role'])) { $role = $requestBag->getMethodData()['role']; } else { $role = $requestBag->getApiConfig()->get('Security.Role', 'ROLE_ANONYMOUS'); } // check if user has the access level required if ($requestBag->getClassData()['accessInterface']) { return $requestBag->getClassInstance()->hasAccess($role); } else { // get firewall name $firewallName = $requestBag->getApiConfig()->get('Security.Firewall', false); if (!$firewallName) { throw new RestException('When using Rest access rule, you must specify a Firewall in your configuration. Alternatively you can implement the AccessInterface and do the check on your own.' ); } return self::security()->firewall($firewallName)->getUser()->hasRole($role); } }
php
public static function hasAccess(RequestBag $requestBag) { // first we check if method requires a special access level if (!$requestBag->getApiConfig()->get('Security', false)) { return true; // no special access level required } // get the required role if (isset($requestBag->getMethodData()['role'])) { $role = $requestBag->getMethodData()['role']; } else { $role = $requestBag->getApiConfig()->get('Security.Role', 'ROLE_ANONYMOUS'); } // check if user has the access level required if ($requestBag->getClassData()['accessInterface']) { return $requestBag->getClassInstance()->hasAccess($role); } else { // get firewall name $firewallName = $requestBag->getApiConfig()->get('Security.Firewall', false); if (!$firewallName) { throw new RestException('When using Rest access rule, you must specify a Firewall in your configuration. Alternatively you can implement the AccessInterface and do the check on your own.' ); } return self::security()->firewall($firewallName)->getUser()->hasRole($role); } }
[ "public", "static", "function", "hasAccess", "(", "RequestBag", "$", "requestBag", ")", "{", "// first we check if method requires a special access level", "if", "(", "!", "$", "requestBag", "->", "getApiConfig", "(", ")", "->", "get", "(", "'Security'", ",", "false", ")", ")", "{", "return", "true", ";", "// no special access level required", "}", "// get the required role", "if", "(", "isset", "(", "$", "requestBag", "->", "getMethodData", "(", ")", "[", "'role'", "]", ")", ")", "{", "$", "role", "=", "$", "requestBag", "->", "getMethodData", "(", ")", "[", "'role'", "]", ";", "}", "else", "{", "$", "role", "=", "$", "requestBag", "->", "getApiConfig", "(", ")", "->", "get", "(", "'Security.Role'", ",", "'ROLE_ANONYMOUS'", ")", ";", "}", "// check if user has the access level required", "if", "(", "$", "requestBag", "->", "getClassData", "(", ")", "[", "'accessInterface'", "]", ")", "{", "return", "$", "requestBag", "->", "getClassInstance", "(", ")", "->", "hasAccess", "(", "$", "role", ")", ";", "}", "else", "{", "// get firewall name", "$", "firewallName", "=", "$", "requestBag", "->", "getApiConfig", "(", ")", "->", "get", "(", "'Security.Firewall'", ",", "false", ")", ";", "if", "(", "!", "$", "firewallName", ")", "{", "throw", "new", "RestException", "(", "'When using Rest access rule, you must specify a Firewall in your configuration.\n Alternatively you can implement the AccessInterface and do the check on your own.'", ")", ";", "}", "return", "self", "::", "security", "(", ")", "->", "firewall", "(", "$", "firewallName", ")", "->", "getUser", "(", ")", "->", "hasRole", "(", "$", "role", ")", ";", "}", "}" ]
Checks if current user has access to the current rest request. @param RequestBag $requestBag @return bool @throws \Webiny\Component\Rest\RestException
[ "Checks", "if", "current", "user", "has", "access", "to", "the", "current", "rest", "request", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/Security.php#L30-L58
230,438
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php
Smarty.setCompileDir
public function setCompileDir($compileDir) { if (!file_exists($compileDir)) { mkdir($compileDir, 0755, true); } $this->smarty->setCompileDir($compileDir); }
php
public function setCompileDir($compileDir) { if (!file_exists($compileDir)) { mkdir($compileDir, 0755, true); } $this->smarty->setCompileDir($compileDir); }
[ "public", "function", "setCompileDir", "(", "$", "compileDir", ")", "{", "if", "(", "!", "file_exists", "(", "$", "compileDir", ")", ")", "{", "mkdir", "(", "$", "compileDir", ",", "0755", ",", "true", ")", ";", "}", "$", "this", "->", "smarty", "->", "setCompileDir", "(", "$", "compileDir", ")", ";", "}" ]
Set Smarty compile dir. @param string $compileDir Absolute path where to store compiled files.
[ "Set", "Smarty", "compile", "dir", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php#L86-L93
230,439
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php
Smarty.setTemplateDir
public function setTemplateDir($templateDir) { $this->smarty->setTemplateDir($templateDir); if (!$this->getTemplateDir()) { throw new SmartyException("The template dir '" . $templateDir . "' does not exist."); } }
php
public function setTemplateDir($templateDir) { $this->smarty->setTemplateDir($templateDir); if (!$this->getTemplateDir()) { throw new SmartyException("The template dir '" . $templateDir . "' does not exist."); } }
[ "public", "function", "setTemplateDir", "(", "$", "templateDir", ")", "{", "$", "this", "->", "smarty", "->", "setTemplateDir", "(", "$", "templateDir", ")", ";", "if", "(", "!", "$", "this", "->", "getTemplateDir", "(", ")", ")", "{", "throw", "new", "SmartyException", "(", "\"The template dir '\"", ".", "$", "templateDir", ".", "\"' does not exist.\"", ")", ";", "}", "}" ]
Root path where the templates are stored. @param string $templateDir @throws SmartyException @internal param string $path Absolute path to the directory that holds the templates. @return void
[ "Root", "path", "where", "the", "templates", "are", "stored", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php#L139-L145
230,440
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php
Smarty.fetch
public function fetch($template, $parameters = []) { try { if (count($parameters) > 0) { $this->smarty->assign($parameters); } return $this->smarty->fetch($template); } catch (\Exception $e) { throw new SmartyException($e->getMessage()); } }
php
public function fetch($template, $parameters = []) { try { if (count($parameters) > 0) { $this->smarty->assign($parameters); } return $this->smarty->fetch($template); } catch (\Exception $e) { throw new SmartyException($e->getMessage()); } }
[ "public", "function", "fetch", "(", "$", "template", ",", "$", "parameters", "=", "[", "]", ")", "{", "try", "{", "if", "(", "count", "(", "$", "parameters", ")", ">", "0", ")", "{", "$", "this", "->", "smarty", "->", "assign", "(", "$", "parameters", ")", ";", "}", "return", "$", "this", "->", "smarty", "->", "fetch", "(", "$", "template", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "SmartyException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Fetch the template from the given location, parse it and return the output. @param string $template Path to the template. @param array $parameters A list of parameters to pass to the template. @throws SmartyException @return string Parsed template.
[ "Fetch", "the", "template", "from", "the", "given", "location", "parse", "it", "and", "return", "the", "output", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php#L206-L217
230,441
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php
Smarty.render
public function render($template, $parameters = []) { if (count($parameters) < 1) { $parameters = null; } echo $this->smarty->fetch($template, $parameters); }
php
public function render($template, $parameters = []) { if (count($parameters) < 1) { $parameters = null; } echo $this->smarty->fetch($template, $parameters); }
[ "public", "function", "render", "(", "$", "template", ",", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "count", "(", "$", "parameters", ")", "<", "1", ")", "{", "$", "parameters", "=", "null", ";", "}", "echo", "$", "this", "->", "smarty", "->", "fetch", "(", "$", "template", ",", "$", "parameters", ")", ";", "}" ]
Fetch the template from the given location, parse it and output the result to the browser. @param string $template Path to the template. @param array $parameters A list of parameters to pass to the template. @return void
[ "Fetch", "the", "template", "from", "the", "given", "location", "parse", "it", "and", "output", "the", "result", "to", "the", "browser", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php#L227-L233
230,442
Webiny/Framework
src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php
Smarty.registerPlugin
public function registerPlugin(Plugin $plugin) { try { $this->smarty->registerPlugin($plugin->getType(), $plugin->getName(), $plugin->getCallbackFunction(), $plugin->getAttribute('Cachable', true), $plugin->getAttribute('CacheAttr', null)); } catch (\SmartyException $e) { throw new SmartyException($e); } }
php
public function registerPlugin(Plugin $plugin) { try { $this->smarty->registerPlugin($plugin->getType(), $plugin->getName(), $plugin->getCallbackFunction(), $plugin->getAttribute('Cachable', true), $plugin->getAttribute('CacheAttr', null)); } catch (\SmartyException $e) { throw new SmartyException($e); } }
[ "public", "function", "registerPlugin", "(", "Plugin", "$", "plugin", ")", "{", "try", "{", "$", "this", "->", "smarty", "->", "registerPlugin", "(", "$", "plugin", "->", "getType", "(", ")", ",", "$", "plugin", "->", "getName", "(", ")", ",", "$", "plugin", "->", "getCallbackFunction", "(", ")", ",", "$", "plugin", "->", "getAttribute", "(", "'Cachable'", ",", "true", ")", ",", "$", "plugin", "->", "getAttribute", "(", "'CacheAttr'", ",", "null", ")", ")", ";", "}", "catch", "(", "\\", "SmartyException", "$", "e", ")", "{", "throw", "new", "SmartyException", "(", "$", "e", ")", ";", "}", "}" ]
Register a plugin for the template engine. @param Plugin $plugin @throws \Exception|SmartyException @return void
[ "Register", "a", "plugin", "for", "the", "template", "engine", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TemplateEngine/Bridge/Smarty/Smarty.php#L256-L264
230,443
Webiny/Framework
src/Webiny/Component/Entity/Attribute/One2ManyAttribute.php
One2ManyAttribute.getValue
public function getValue($params = [], $processCallbacks = true) { if ($this->isNull($this->value)) { // We need to load records from DB - but ONLY if parent record has an ID (otherwise no child records can exist in DB) $entityId = $this->parent->id; if (empty($entityId)) { // No child records exist - return an empty EntityCollection $this->value = new EntityCollection($this->entityClass, []); $this->dataLoaded = true; } else { // Try loading child records using parent id $query = [$this->relatedAttribute => $entityId]; // Get optional record filters $filters = $this->filter; if (is_string($filters) || is_callable($filters)) { $callable = is_string($filters) ? [$this->parent, $filters] : $filters; $filters = call_user_func_array($callable, []); } // Merge optional filters with main query $query = array_merge($query, $filters); $this->value = call_user_func_array([$this->entityClass, 'find'], [$query, $this->sorter]); $this->dataLoaded = true; } } return $processCallbacks ? $this->processGetValue($this->value, $params) : $this->value; }
php
public function getValue($params = [], $processCallbacks = true) { if ($this->isNull($this->value)) { // We need to load records from DB - but ONLY if parent record has an ID (otherwise no child records can exist in DB) $entityId = $this->parent->id; if (empty($entityId)) { // No child records exist - return an empty EntityCollection $this->value = new EntityCollection($this->entityClass, []); $this->dataLoaded = true; } else { // Try loading child records using parent id $query = [$this->relatedAttribute => $entityId]; // Get optional record filters $filters = $this->filter; if (is_string($filters) || is_callable($filters)) { $callable = is_string($filters) ? [$this->parent, $filters] : $filters; $filters = call_user_func_array($callable, []); } // Merge optional filters with main query $query = array_merge($query, $filters); $this->value = call_user_func_array([$this->entityClass, 'find'], [$query, $this->sorter]); $this->dataLoaded = true; } } return $processCallbacks ? $this->processGetValue($this->value, $params) : $this->value; }
[ "public", "function", "getValue", "(", "$", "params", "=", "[", "]", ",", "$", "processCallbacks", "=", "true", ")", "{", "if", "(", "$", "this", "->", "isNull", "(", "$", "this", "->", "value", ")", ")", "{", "// We need to load records from DB - but ONLY if parent record has an ID (otherwise no child records can exist in DB)", "$", "entityId", "=", "$", "this", "->", "parent", "->", "id", ";", "if", "(", "empty", "(", "$", "entityId", ")", ")", "{", "// No child records exist - return an empty EntityCollection", "$", "this", "->", "value", "=", "new", "EntityCollection", "(", "$", "this", "->", "entityClass", ",", "[", "]", ")", ";", "$", "this", "->", "dataLoaded", "=", "true", ";", "}", "else", "{", "// Try loading child records using parent id", "$", "query", "=", "[", "$", "this", "->", "relatedAttribute", "=>", "$", "entityId", "]", ";", "// Get optional record filters", "$", "filters", "=", "$", "this", "->", "filter", ";", "if", "(", "is_string", "(", "$", "filters", ")", "||", "is_callable", "(", "$", "filters", ")", ")", "{", "$", "callable", "=", "is_string", "(", "$", "filters", ")", "?", "[", "$", "this", "->", "parent", ",", "$", "filters", "]", ":", "$", "filters", ";", "$", "filters", "=", "call_user_func_array", "(", "$", "callable", ",", "[", "]", ")", ";", "}", "// Merge optional filters with main query", "$", "query", "=", "array_merge", "(", "$", "query", ",", "$", "filters", ")", ";", "$", "this", "->", "value", "=", "call_user_func_array", "(", "[", "$", "this", "->", "entityClass", ",", "'find'", "]", ",", "[", "$", "query", ",", "$", "this", "->", "sorter", "]", ")", ";", "$", "this", "->", "dataLoaded", "=", "true", ";", "}", "}", "return", "$", "processCallbacks", "?", "$", "this", "->", "processGetValue", "(", "$", "this", "->", "value", ",", "$", "params", ")", ":", "$", "this", "->", "value", ";", "}" ]
Set or get attribute value @param array $params @param bool $processCallbacks @return bool|null|AbstractEntity
[ "Set", "or", "get", "attribute", "value" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Attribute/One2ManyAttribute.php#L150-L178
230,444
mnapoli/phpunit-easymock
src/EasyMock.php
EasyMock.easyMock
protected function easyMock($classname, array $methods = array()) { if ($classname instanceof MockObject) { $mock = $classname; } else { $mock = $this->doCreateMock($classname); } foreach ($methods as $method => $return) { $this->mockMethod($mock, $method, new AnyInvokedCount(), $return); } return $mock; }
php
protected function easyMock($classname, array $methods = array()) { if ($classname instanceof MockObject) { $mock = $classname; } else { $mock = $this->doCreateMock($classname); } foreach ($methods as $method => $return) { $this->mockMethod($mock, $method, new AnyInvokedCount(), $return); } return $mock; }
[ "protected", "function", "easyMock", "(", "$", "classname", ",", "array", "$", "methods", "=", "array", "(", ")", ")", "{", "if", "(", "$", "classname", "instanceof", "MockObject", ")", "{", "$", "mock", "=", "$", "classname", ";", "}", "else", "{", "$", "mock", "=", "$", "this", "->", "doCreateMock", "(", "$", "classname", ")", ";", "}", "foreach", "(", "$", "methods", "as", "$", "method", "=>", "$", "return", ")", "{", "$", "this", "->", "mockMethod", "(", "$", "mock", ",", "$", "method", ",", "new", "AnyInvokedCount", "(", ")", ",", "$", "return", ")", ";", "}", "return", "$", "mock", ";", "}" ]
Mock the given class. Methods not specified in $methods will be mocked to return null (default PHPUnit behavior). The class constructor will *not* be called. @param string $classname The class to mock. Can also be an existing mock to mock new methods. @param array $methods Array of values to return, indexed by the method name. @return \PHPUnit\Framework\MockObject\MockObject
[ "Mock", "the", "given", "class", "." ]
cd71d4d897bab9cba02afd01af7701caf54e8b03
https://github.com/mnapoli/phpunit-easymock/blob/cd71d4d897bab9cba02afd01af7701caf54e8b03/src/EasyMock.php#L28-L41
230,445
mnapoli/phpunit-easymock
src/EasyMock.php
EasyMock.easySpy
protected function easySpy($classname, array $methods = array()) { if ($classname instanceof MockObject) { $mock = $classname; } else { $mock = $this->doCreateMock($classname); } foreach ($methods as $method => $return) { $this->mockMethod($mock, $method, new InvokedAtLeastOnce, $return); } return $mock; }
php
protected function easySpy($classname, array $methods = array()) { if ($classname instanceof MockObject) { $mock = $classname; } else { $mock = $this->doCreateMock($classname); } foreach ($methods as $method => $return) { $this->mockMethod($mock, $method, new InvokedAtLeastOnce, $return); } return $mock; }
[ "protected", "function", "easySpy", "(", "$", "classname", ",", "array", "$", "methods", "=", "array", "(", ")", ")", "{", "if", "(", "$", "classname", "instanceof", "MockObject", ")", "{", "$", "mock", "=", "$", "classname", ";", "}", "else", "{", "$", "mock", "=", "$", "this", "->", "doCreateMock", "(", "$", "classname", ")", ";", "}", "foreach", "(", "$", "methods", "as", "$", "method", "=>", "$", "return", ")", "{", "$", "this", "->", "mockMethod", "(", "$", "mock", ",", "$", "method", ",", "new", "InvokedAtLeastOnce", ",", "$", "return", ")", ";", "}", "return", "$", "mock", ";", "}" ]
Mock the given class by spying on method calls. This is the same as EasyMock::mock() except this assert that methods are called at least once. @see easyMock() @param string $classname The class to mock. Can also be an existing mock to mock new methods. @param array $methods Array of values to return, indexed by the method name. @return \PHPUnit\Framework\MockObject\MockObject
[ "Mock", "the", "given", "class", "by", "spying", "on", "method", "calls", "." ]
cd71d4d897bab9cba02afd01af7701caf54e8b03
https://github.com/mnapoli/phpunit-easymock/blob/cd71d4d897bab9cba02afd01af7701caf54e8b03/src/EasyMock.php#L56-L69
230,446
naneau/semver
src/Naneau/SemVer/Parser/Build.php
Build.parse
public static function parse($string) { // Explode over '.' $parts = explode('.', $string); // Instantiate $buildVersion = new BuildVersion; // No parts is no build? if (count($parts) === 0) { return $buildVersion; } // Discard "build" string should it prepend the build if ($parts[0] === 'build') { array_shift($parts); } // If the first part is a number it's the build number if (isset($parts[0]) && is_numeric($parts[0])) { $buildVersion->setNumber( (int) array_shift($parts) ); } // All other parts are custom and can simply be put on a stack foreach ($parts as $part) { $buildVersion->addPart($part); } // Return return $buildVersion; }
php
public static function parse($string) { // Explode over '.' $parts = explode('.', $string); // Instantiate $buildVersion = new BuildVersion; // No parts is no build? if (count($parts) === 0) { return $buildVersion; } // Discard "build" string should it prepend the build if ($parts[0] === 'build') { array_shift($parts); } // If the first part is a number it's the build number if (isset($parts[0]) && is_numeric($parts[0])) { $buildVersion->setNumber( (int) array_shift($parts) ); } // All other parts are custom and can simply be put on a stack foreach ($parts as $part) { $buildVersion->addPart($part); } // Return return $buildVersion; }
[ "public", "static", "function", "parse", "(", "$", "string", ")", "{", "// Explode over '.'", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "string", ")", ";", "// Instantiate", "$", "buildVersion", "=", "new", "BuildVersion", ";", "// No parts is no build?", "if", "(", "count", "(", "$", "parts", ")", "===", "0", ")", "{", "return", "$", "buildVersion", ";", "}", "// Discard \"build\" string should it prepend the build", "if", "(", "$", "parts", "[", "0", "]", "===", "'build'", ")", "{", "array_shift", "(", "$", "parts", ")", ";", "}", "// If the first part is a number it's the build number", "if", "(", "isset", "(", "$", "parts", "[", "0", "]", ")", "&&", "is_numeric", "(", "$", "parts", "[", "0", "]", ")", ")", "{", "$", "buildVersion", "->", "setNumber", "(", "(", "int", ")", "array_shift", "(", "$", "parts", ")", ")", ";", "}", "// All other parts are custom and can simply be put on a stack", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "$", "buildVersion", "->", "addPart", "(", "$", "part", ")", ";", "}", "// Return", "return", "$", "buildVersion", ";", "}" ]
Parse a build part string A build part can look like build.11.e0f985a @param string $string @return BuildVersion
[ "Parse", "a", "build", "part", "string" ]
c771ad1e6c89064c0a4fa714979639dc3649d6c8
https://github.com/naneau/semver/blob/c771ad1e6c89064c0a4fa714979639dc3649d6c8/src/Naneau/SemVer/Parser/Build.php#L33-L65
230,447
milesj/admin
Model/RequestObject.php
RequestObject.addObject
public function addObject($alias, $parent_id = null) { $query = array( 'alias' => $alias, 'parent_id' => $parent_id ); $result = $this->find('first', array( 'conditions' => $query )); if ($result) { return $result; } $this->create(); if ($this->save($query)) { $this->deleteCache(array('RequestObject::hasAlias', $alias)); return $this->getByAlias($alias); } return null; }
php
public function addObject($alias, $parent_id = null) { $query = array( 'alias' => $alias, 'parent_id' => $parent_id ); $result = $this->find('first', array( 'conditions' => $query )); if ($result) { return $result; } $this->create(); if ($this->save($query)) { $this->deleteCache(array('RequestObject::hasAlias', $alias)); return $this->getByAlias($alias); } return null; }
[ "public", "function", "addObject", "(", "$", "alias", ",", "$", "parent_id", "=", "null", ")", "{", "$", "query", "=", "array", "(", "'alias'", "=>", "$", "alias", ",", "'parent_id'", "=>", "$", "parent_id", ")", ";", "$", "result", "=", "$", "this", "->", "find", "(", "'first'", ",", "array", "(", "'conditions'", "=>", "$", "query", ")", ")", ";", "if", "(", "$", "result", ")", "{", "return", "$", "result", ";", "}", "$", "this", "->", "create", "(", ")", ";", "if", "(", "$", "this", "->", "save", "(", "$", "query", ")", ")", "{", "$", "this", "->", "deleteCache", "(", "array", "(", "'RequestObject::hasAlias'", ",", "$", "alias", ")", ")", ";", "return", "$", "this", "->", "getByAlias", "(", "$", "alias", ")", ";", "}", "return", "null", ";", "}" ]
Add an object if it does not exist. @param string $alias @param int $parent_id @return int
[ "Add", "an", "object", "if", "it", "does", "not", "exist", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L123-L146
230,448
milesj/admin
Model/RequestObject.php
RequestObject.addChildObject
public function addChildObject($alias, $parent_id, $model, $foreignKey) { $query = array( 'alias' => $alias, 'parent_id' => $parent_id, 'model' => $model, 'foreign_key' => $foreignKey ); $result = $this->find('first', array( 'conditions' => $query )); if ($result) { return $result; } $this->create(); if ($this->save($query)) { $this->deleteCache(array('RequestObject::hasAlias', $alias)); return $this->getByAlias($alias); } return null; }
php
public function addChildObject($alias, $parent_id, $model, $foreignKey) { $query = array( 'alias' => $alias, 'parent_id' => $parent_id, 'model' => $model, 'foreign_key' => $foreignKey ); $result = $this->find('first', array( 'conditions' => $query )); if ($result) { return $result; } $this->create(); if ($this->save($query)) { $this->deleteCache(array('RequestObject::hasAlias', $alias)); return $this->getByAlias($alias); } return null; }
[ "public", "function", "addChildObject", "(", "$", "alias", ",", "$", "parent_id", ",", "$", "model", ",", "$", "foreignKey", ")", "{", "$", "query", "=", "array", "(", "'alias'", "=>", "$", "alias", ",", "'parent_id'", "=>", "$", "parent_id", ",", "'model'", "=>", "$", "model", ",", "'foreign_key'", "=>", "$", "foreignKey", ")", ";", "$", "result", "=", "$", "this", "->", "find", "(", "'first'", ",", "array", "(", "'conditions'", "=>", "$", "query", ")", ")", ";", "if", "(", "$", "result", ")", "{", "return", "$", "result", ";", "}", "$", "this", "->", "create", "(", ")", ";", "if", "(", "$", "this", "->", "save", "(", "$", "query", ")", ")", "{", "$", "this", "->", "deleteCache", "(", "array", "(", "'RequestObject::hasAlias'", ",", "$", "alias", ")", ")", ";", "return", "$", "this", "->", "getByAlias", "(", "$", "alias", ")", ";", "}", "return", "null", ";", "}" ]
Add a child object if it does not exist. @param string $alias @param int $parent_id @param string $model @param int $foreignKey @return int
[ "Add", "a", "child", "object", "if", "it", "does", "not", "exist", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L157-L182
230,449
milesj/admin
Model/RequestObject.php
RequestObject.getPermissions
public function getPermissions($user_id) { try { $aros = $this->node(array(USER_MODEL => array('id' => $user_id))); } catch (Exception $e) { return array(); } return $this->ObjectPermission->getByAroId(Hash::extract($aros, '{n}.RequestObject.id')); }
php
public function getPermissions($user_id) { try { $aros = $this->node(array(USER_MODEL => array('id' => $user_id))); } catch (Exception $e) { return array(); } return $this->ObjectPermission->getByAroId(Hash::extract($aros, '{n}.RequestObject.id')); }
[ "public", "function", "getPermissions", "(", "$", "user_id", ")", "{", "try", "{", "$", "aros", "=", "$", "this", "->", "node", "(", "array", "(", "USER_MODEL", "=>", "array", "(", "'id'", "=>", "$", "user_id", ")", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "array", "(", ")", ";", "}", "return", "$", "this", "->", "ObjectPermission", "->", "getByAroId", "(", "Hash", "::", "extract", "(", "$", "aros", ",", "'{n}.RequestObject.id'", ")", ")", ";", "}" ]
Return a list of users permissions. Include parent groups permissions also. @param int $user_id @return array
[ "Return", "a", "list", "of", "users", "permissions", ".", "Include", "parent", "groups", "permissions", "also", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L276-L284
230,450
milesj/admin
Model/RequestObject.php
RequestObject.getCrudPermissions
public function getCrudPermissions($user_id, $filter = null) { return $this->cache(array(__METHOD__, $user_id), function($self) use ($user_id, $filter) { $crud = array(); if ($permissions = $self->getPermissions($user_id)) { foreach ($permissions as $permission) { if ($filter && stripos($permission['ControlObject']['alias'], $filter) === false) { continue; } $crud[$permission['ControlObject']['alias']] = array( 'create' => ($permission['ObjectPermission']['_create'] >= 0), 'read' => ($permission['ObjectPermission']['_read'] >= 0), 'update' => ($permission['ObjectPermission']['_update'] >= 0), 'delete' => ($permission['ObjectPermission']['_delete'] >= 0) ); } } return $crud; }); }
php
public function getCrudPermissions($user_id, $filter = null) { return $this->cache(array(__METHOD__, $user_id), function($self) use ($user_id, $filter) { $crud = array(); if ($permissions = $self->getPermissions($user_id)) { foreach ($permissions as $permission) { if ($filter && stripos($permission['ControlObject']['alias'], $filter) === false) { continue; } $crud[$permission['ControlObject']['alias']] = array( 'create' => ($permission['ObjectPermission']['_create'] >= 0), 'read' => ($permission['ObjectPermission']['_read'] >= 0), 'update' => ($permission['ObjectPermission']['_update'] >= 0), 'delete' => ($permission['ObjectPermission']['_delete'] >= 0) ); } } return $crud; }); }
[ "public", "function", "getCrudPermissions", "(", "$", "user_id", ",", "$", "filter", "=", "null", ")", "{", "return", "$", "this", "->", "cache", "(", "array", "(", "__METHOD__", ",", "$", "user_id", ")", ",", "function", "(", "$", "self", ")", "use", "(", "$", "user_id", ",", "$", "filter", ")", "{", "$", "crud", "=", "array", "(", ")", ";", "if", "(", "$", "permissions", "=", "$", "self", "->", "getPermissions", "(", "$", "user_id", ")", ")", "{", "foreach", "(", "$", "permissions", "as", "$", "permission", ")", "{", "if", "(", "$", "filter", "&&", "stripos", "(", "$", "permission", "[", "'ControlObject'", "]", "[", "'alias'", "]", ",", "$", "filter", ")", "===", "false", ")", "{", "continue", ";", "}", "$", "crud", "[", "$", "permission", "[", "'ControlObject'", "]", "[", "'alias'", "]", "]", "=", "array", "(", "'create'", "=>", "(", "$", "permission", "[", "'ObjectPermission'", "]", "[", "'_create'", "]", ">=", "0", ")", ",", "'read'", "=>", "(", "$", "permission", "[", "'ObjectPermission'", "]", "[", "'_read'", "]", ">=", "0", ")", ",", "'update'", "=>", "(", "$", "permission", "[", "'ObjectPermission'", "]", "[", "'_update'", "]", ">=", "0", ")", ",", "'delete'", "=>", "(", "$", "permission", "[", "'ObjectPermission'", "]", "[", "'_delete'", "]", ">=", "0", ")", ")", ";", "}", "}", "return", "$", "crud", ";", "}", ")", ";", "}" ]
Map all permissions to a boolean flagged list grouped by ACO and CRUD. @param int $user_id @param string $filter @return array
[ "Map", "all", "permissions", "to", "a", "boolean", "flagged", "list", "grouped", "by", "ACO", "and", "CRUD", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L293-L314
230,451
milesj/admin
Model/RequestObject.php
RequestObject.getRoles
public function getRoles($user_id) { $results = $this->find('all', array( 'conditions' => array( 'RequestObject.foreign_key' => $user_id, 'RequestObject.model' => USER_MODEL ) )); if ($results) { // Grab the direct parents (or roles) $results = $this->find('all', array( 'conditions' => array('RequestObject.id' => Hash::extract($results, '{n}.RequestObject.parent_id')) )); // Also grab the children of the parents since the user has access to them as well $results = array_merge($results, $this->find('all', array( 'conditions' => array( 'RequestObject.parent_id' => Hash::extract($results, '{n}.RequestObject.id'), 'RequestObject.model' => null, 'RequestObject.foreign_key' => null ) ))); } return $results; }
php
public function getRoles($user_id) { $results = $this->find('all', array( 'conditions' => array( 'RequestObject.foreign_key' => $user_id, 'RequestObject.model' => USER_MODEL ) )); if ($results) { // Grab the direct parents (or roles) $results = $this->find('all', array( 'conditions' => array('RequestObject.id' => Hash::extract($results, '{n}.RequestObject.parent_id')) )); // Also grab the children of the parents since the user has access to them as well $results = array_merge($results, $this->find('all', array( 'conditions' => array( 'RequestObject.parent_id' => Hash::extract($results, '{n}.RequestObject.id'), 'RequestObject.model' => null, 'RequestObject.foreign_key' => null ) ))); } return $results; }
[ "public", "function", "getRoles", "(", "$", "user_id", ")", "{", "$", "results", "=", "$", "this", "->", "find", "(", "'all'", ",", "array", "(", "'conditions'", "=>", "array", "(", "'RequestObject.foreign_key'", "=>", "$", "user_id", ",", "'RequestObject.model'", "=>", "USER_MODEL", ")", ")", ")", ";", "if", "(", "$", "results", ")", "{", "// Grab the direct parents (or roles)", "$", "results", "=", "$", "this", "->", "find", "(", "'all'", ",", "array", "(", "'conditions'", "=>", "array", "(", "'RequestObject.id'", "=>", "Hash", "::", "extract", "(", "$", "results", ",", "'{n}.RequestObject.parent_id'", ")", ")", ")", ")", ";", "// Also grab the children of the parents since the user has access to them as well", "$", "results", "=", "array_merge", "(", "$", "results", ",", "$", "this", "->", "find", "(", "'all'", ",", "array", "(", "'conditions'", "=>", "array", "(", "'RequestObject.parent_id'", "=>", "Hash", "::", "extract", "(", "$", "results", ",", "'{n}.RequestObject.id'", ")", ",", "'RequestObject.model'", "=>", "null", ",", "'RequestObject.foreign_key'", "=>", "null", ")", ")", ")", ")", ";", "}", "return", "$", "results", ";", "}" ]
Return a list of users roles defined in the ACL. @param int $user_id @return array
[ "Return", "a", "list", "of", "users", "roles", "defined", "in", "the", "ACL", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L322-L347
230,452
milesj/admin
Model/RequestObject.php
RequestObject.getStaffByAlias
public function getStaffByAlias($alias) { $access = $this->getByAlias($alias); return $this->find('all', array( 'conditions' => array( 'RequestObject.parent_id' => $access['RequestObject']['id'], 'RequestObject.foreign_key !=' => null, 'RequestObject.model' => USER_MODEL ), 'contain' => array('User', 'Parent'), 'cache' => array(__METHOD__, $alias) )); }
php
public function getStaffByAlias($alias) { $access = $this->getByAlias($alias); return $this->find('all', array( 'conditions' => array( 'RequestObject.parent_id' => $access['RequestObject']['id'], 'RequestObject.foreign_key !=' => null, 'RequestObject.model' => USER_MODEL ), 'contain' => array('User', 'Parent'), 'cache' => array(__METHOD__, $alias) )); }
[ "public", "function", "getStaffByAlias", "(", "$", "alias", ")", "{", "$", "access", "=", "$", "this", "->", "getByAlias", "(", "$", "alias", ")", ";", "return", "$", "this", "->", "find", "(", "'all'", ",", "array", "(", "'conditions'", "=>", "array", "(", "'RequestObject.parent_id'", "=>", "$", "access", "[", "'RequestObject'", "]", "[", "'id'", "]", ",", "'RequestObject.foreign_key !='", "=>", "null", ",", "'RequestObject.model'", "=>", "USER_MODEL", ")", ",", "'contain'", "=>", "array", "(", "'User'", ",", "'Parent'", ")", ",", "'cache'", "=>", "array", "(", "__METHOD__", ",", "$", "alias", ")", ")", ")", ";", "}" ]
Return all the staff by slug. @param string $alias @return array
[ "Return", "all", "the", "staff", "by", "slug", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L371-L383
230,453
milesj/admin
Model/RequestObject.php
RequestObject.isChildOf
public function isChildOf($user_id, $fk) { if (!$user_id || !$fk) { return false; } try { $aros = $this->node(array( 'model' => USER_MODEL, 'foreign_key' => $user_id )); } catch (Exception $e) { return false; } if ($aros) { foreach ($aros as $aro) { if (is_string($fk) && $aro['RequestObject']['alias'] == $fk) { return true; } else if (is_numeric($fk) && $aro['RequestObject']['id'] == $fk) { return true; } } } return false; }
php
public function isChildOf($user_id, $fk) { if (!$user_id || !$fk) { return false; } try { $aros = $this->node(array( 'model' => USER_MODEL, 'foreign_key' => $user_id )); } catch (Exception $e) { return false; } if ($aros) { foreach ($aros as $aro) { if (is_string($fk) && $aro['RequestObject']['alias'] == $fk) { return true; } else if (is_numeric($fk) && $aro['RequestObject']['id'] == $fk) { return true; } } } return false; }
[ "public", "function", "isChildOf", "(", "$", "user_id", ",", "$", "fk", ")", "{", "if", "(", "!", "$", "user_id", "||", "!", "$", "fk", ")", "{", "return", "false", ";", "}", "try", "{", "$", "aros", "=", "$", "this", "->", "node", "(", "array", "(", "'model'", "=>", "USER_MODEL", ",", "'foreign_key'", "=>", "$", "user_id", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "if", "(", "$", "aros", ")", "{", "foreach", "(", "$", "aros", "as", "$", "aro", ")", "{", "if", "(", "is_string", "(", "$", "fk", ")", "&&", "$", "aro", "[", "'RequestObject'", "]", "[", "'alias'", "]", "==", "$", "fk", ")", "{", "return", "true", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "fk", ")", "&&", "$", "aro", "[", "'RequestObject'", "]", "[", "'id'", "]", "==", "$", "fk", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Check to see if a user is a child of a specific alias. @param int $user_id @param int|string $fk @return bool
[ "Check", "to", "see", "if", "a", "user", "is", "a", "child", "of", "a", "specific", "alias", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/RequestObject.php#L406-L431
230,454
Webiny/Framework
src/Webiny/Component/StdLib/StdLibTrait.php
StdLibTrait.jsonDecode
protected static function jsonDecode($json, $assoc = false, $depth = 512, $options = 0) { return json_decode($json, $assoc, $depth, $options); }
php
protected static function jsonDecode($json, $assoc = false, $depth = 512, $options = 0) { return json_decode($json, $assoc, $depth, $options); }
[ "protected", "static", "function", "jsonDecode", "(", "$", "json", ",", "$", "assoc", "=", "false", ",", "$", "depth", "=", "512", ",", "$", "options", "=", "0", ")", "{", "return", "json_decode", "(", "$", "json", ",", "$", "assoc", ",", "$", "depth", ",", "$", "options", ")", ";", "}" ]
Decode JSON string @param string $json The json string being decoded. This function only works with UTF-8 encoded data. @param bool $assoc When TRUE, returned objects will be converted into associative arrays. @param int $depth User specified recursion depth. @param int $options Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats) @return mixed The value encoded in json in appropriate PHP type. NULL is returned if the json cannot be decoded or if the encoded data is deeper than the recursion limit.
[ "Decode", "JSON", "string" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdLibTrait.php#L44-L47
230,455
Webiny/Framework
src/Webiny/Component/StdLib/StdLibTrait.php
StdLibTrait.unserialize
protected static function unserialize($string) { if (is_array($string)) { return $string; } if (($data = unserialize($string)) !== false) { return $data; } return unserialize(stripslashes($string)); }
php
protected static function unserialize($string) { if (is_array($string)) { return $string; } if (($data = unserialize($string)) !== false) { return $data; } return unserialize(stripslashes($string)); }
[ "protected", "static", "function", "unserialize", "(", "$", "string", ")", "{", "if", "(", "is_array", "(", "$", "string", ")", ")", "{", "return", "$", "string", ";", "}", "if", "(", "(", "$", "data", "=", "unserialize", "(", "$", "string", ")", ")", "!==", "false", ")", "{", "return", "$", "data", ";", "}", "return", "unserialize", "(", "stripslashes", "(", "$", "string", ")", ")", ";", "}" ]
Unserializes the given string and returns the array. @param string $string String to serialize. @return array|mixed
[ "Unserializes", "the", "given", "string", "and", "returns", "the", "array", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdLibTrait.php#L68-L79
230,456
Webiny/Framework
src/Webiny/Component/OAuth2/OAuth2Request.php
OAuth2Request.setRequestType
public function setRequestType($requestType) { $requestType = $this->str($requestType)->caseUpper(); if (!$requestType->equals('GET') && !$requestType->equals('POST')) { throw new OAuth2Exception('Invalid request type provided "' . $requestType->val() . '". Possible values are GET and POST.' ); } $this->requestType = $requestType->val(); }
php
public function setRequestType($requestType) { $requestType = $this->str($requestType)->caseUpper(); if (!$requestType->equals('GET') && !$requestType->equals('POST')) { throw new OAuth2Exception('Invalid request type provided "' . $requestType->val() . '". Possible values are GET and POST.' ); } $this->requestType = $requestType->val(); }
[ "public", "function", "setRequestType", "(", "$", "requestType", ")", "{", "$", "requestType", "=", "$", "this", "->", "str", "(", "$", "requestType", ")", "->", "caseUpper", "(", ")", ";", "if", "(", "!", "$", "requestType", "->", "equals", "(", "'GET'", ")", "&&", "!", "$", "requestType", "->", "equals", "(", "'POST'", ")", ")", "{", "throw", "new", "OAuth2Exception", "(", "'Invalid request type provided \"'", ".", "$", "requestType", "->", "val", "(", ")", ".", "'\".\n\t\t\t\t\t\t\t\t\t\tPossible values are GET and POST.'", ")", ";", "}", "$", "this", "->", "requestType", "=", "$", "requestType", "->", "val", "(", ")", ";", "}" ]
Set the request type either to POST or GET. @param string $requestType Can be POST or GET @throws OAuth2Exception
[ "Set", "the", "request", "type", "either", "to", "POST", "or", "GET", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/OAuth2Request.php#L92-L103
230,457
Webiny/Framework
src/Webiny/Component/OAuth2/OAuth2Request.php
OAuth2Request.executeRequest
public function executeRequest() { // curl general $curl_options = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CUSTOMREQUEST => $this->requestType ]; // set to post if ($this->requestType == 'POST') { $curl_options[CURLOPT_POST] = true; } // build url and append query params $url = $this->url($this->getUrl()); $this->params[$this->oauth2->getAccessTokenName()] = $this->oauth2->getAccessToken(); if (count($this->getParams()) > 0) { $url->setQuery($this->getParams()); } $curl_options[CURLOPT_URL] = $url->val(); // check request headers if (count($this->getHeaders()) > 0) { $header = []; foreach ($this->getHeaders() as $key => $parsed_urlvalue) { $header[] = "$key: $parsed_urlvalue"; } $curl_options[CURLOPT_HTTPHEADER] = $header; } // init curl $ch = curl_init(); curl_setopt_array($ch, $curl_options); // https handling if ($this->certificateFile != '') { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, $this->certificateFile); } else { // bypass ssl verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } // execute the curl request $result = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if ($curl_error = curl_error($ch)) { throw new OAuth2Exception($curl_error); } else { $json_decode = $this->jsonDecode($result, true); } curl_close($ch); return [ 'result' => (null === $json_decode) ? $result : $json_decode, 'code' => $http_code, 'content_type' => $content_type ]; }
php
public function executeRequest() { // curl general $curl_options = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CUSTOMREQUEST => $this->requestType ]; // set to post if ($this->requestType == 'POST') { $curl_options[CURLOPT_POST] = true; } // build url and append query params $url = $this->url($this->getUrl()); $this->params[$this->oauth2->getAccessTokenName()] = $this->oauth2->getAccessToken(); if (count($this->getParams()) > 0) { $url->setQuery($this->getParams()); } $curl_options[CURLOPT_URL] = $url->val(); // check request headers if (count($this->getHeaders()) > 0) { $header = []; foreach ($this->getHeaders() as $key => $parsed_urlvalue) { $header[] = "$key: $parsed_urlvalue"; } $curl_options[CURLOPT_HTTPHEADER] = $header; } // init curl $ch = curl_init(); curl_setopt_array($ch, $curl_options); // https handling if ($this->certificateFile != '') { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_CAINFO, $this->certificateFile); } else { // bypass ssl verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } // execute the curl request $result = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); if ($curl_error = curl_error($ch)) { throw new OAuth2Exception($curl_error); } else { $json_decode = $this->jsonDecode($result, true); } curl_close($ch); return [ 'result' => (null === $json_decode) ? $result : $json_decode, 'code' => $http_code, 'content_type' => $content_type ]; }
[ "public", "function", "executeRequest", "(", ")", "{", "// curl general", "$", "curl_options", "=", "[", "CURLOPT_RETURNTRANSFER", "=>", "true", ",", "CURLOPT_SSL_VERIFYPEER", "=>", "true", ",", "CURLOPT_CUSTOMREQUEST", "=>", "$", "this", "->", "requestType", "]", ";", "// set to post", "if", "(", "$", "this", "->", "requestType", "==", "'POST'", ")", "{", "$", "curl_options", "[", "CURLOPT_POST", "]", "=", "true", ";", "}", "// build url and append query params", "$", "url", "=", "$", "this", "->", "url", "(", "$", "this", "->", "getUrl", "(", ")", ")", ";", "$", "this", "->", "params", "[", "$", "this", "->", "oauth2", "->", "getAccessTokenName", "(", ")", "]", "=", "$", "this", "->", "oauth2", "->", "getAccessToken", "(", ")", ";", "if", "(", "count", "(", "$", "this", "->", "getParams", "(", ")", ")", ">", "0", ")", "{", "$", "url", "->", "setQuery", "(", "$", "this", "->", "getParams", "(", ")", ")", ";", "}", "$", "curl_options", "[", "CURLOPT_URL", "]", "=", "$", "url", "->", "val", "(", ")", ";", "// check request headers", "if", "(", "count", "(", "$", "this", "->", "getHeaders", "(", ")", ")", ">", "0", ")", "{", "$", "header", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getHeaders", "(", ")", "as", "$", "key", "=>", "$", "parsed_urlvalue", ")", "{", "$", "header", "[", "]", "=", "\"$key: $parsed_urlvalue\"", ";", "}", "$", "curl_options", "[", "CURLOPT_HTTPHEADER", "]", "=", "$", "header", ";", "}", "// init curl", "$", "ch", "=", "curl_init", "(", ")", ";", "curl_setopt_array", "(", "$", "ch", ",", "$", "curl_options", ")", ";", "// https handling", "if", "(", "$", "this", "->", "certificateFile", "!=", "''", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "true", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "2", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CAINFO", ",", "$", "this", "->", "certificateFile", ")", ";", "}", "else", "{", "// bypass ssl verification", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "0", ")", ";", "}", "// execute the curl request", "$", "result", "=", "curl_exec", "(", "$", "ch", ")", ";", "$", "http_code", "=", "curl_getinfo", "(", "$", "ch", ",", "CURLINFO_HTTP_CODE", ")", ";", "$", "content_type", "=", "curl_getinfo", "(", "$", "ch", ",", "CURLINFO_CONTENT_TYPE", ")", ";", "if", "(", "$", "curl_error", "=", "curl_error", "(", "$", "ch", ")", ")", "{", "throw", "new", "OAuth2Exception", "(", "$", "curl_error", ")", ";", "}", "else", "{", "$", "json_decode", "=", "$", "this", "->", "jsonDecode", "(", "$", "result", ",", "true", ")", ";", "}", "curl_close", "(", "$", "ch", ")", ";", "return", "[", "'result'", "=>", "(", "null", "===", "$", "json_decode", ")", "?", "$", "result", ":", "$", "json_decode", ",", "'code'", "=>", "$", "http_code", ",", "'content_type'", "=>", "$", "content_type", "]", ";", "}" ]
Executes the OAuth2 request. @return array Array containing [result, code, content_type]. @throws OAuth2Exception
[ "Executes", "the", "OAuth2", "request", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/OAuth2Request.php#L162-L225
230,458
Webiny/Framework
src/Webiny/Component/Router/Matcher/MatchedRoute.php
MatchedRoute.hasTags
public function hasTags(array $tags, $matchAll = true) { $routeTags = $this->getRoute()->getTags(); $diffCount = count(array_diff($tags, $routeTags)); $tagsCount = count($tags); if ($matchAll) { if ($diffCount === 0) { return true; } } else { if ($tagsCount > $diffCount) { return true; } } return false; }
php
public function hasTags(array $tags, $matchAll = true) { $routeTags = $this->getRoute()->getTags(); $diffCount = count(array_diff($tags, $routeTags)); $tagsCount = count($tags); if ($matchAll) { if ($diffCount === 0) { return true; } } else { if ($tagsCount > $diffCount) { return true; } } return false; }
[ "public", "function", "hasTags", "(", "array", "$", "tags", ",", "$", "matchAll", "=", "true", ")", "{", "$", "routeTags", "=", "$", "this", "->", "getRoute", "(", ")", "->", "getTags", "(", ")", ";", "$", "diffCount", "=", "count", "(", "array_diff", "(", "$", "tags", ",", "$", "routeTags", ")", ")", ";", "$", "tagsCount", "=", "count", "(", "$", "tags", ")", ";", "if", "(", "$", "matchAll", ")", "{", "if", "(", "$", "diffCount", "===", "0", ")", "{", "return", "true", ";", "}", "}", "else", "{", "if", "(", "$", "tagsCount", ">", "$", "diffCount", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the current matched route has the given tags. @param array $tags List of tags to match. @param bool $matchAll Match all, or only one of the tags. @return bool
[ "Checks", "if", "the", "current", "matched", "route", "has", "the", "given", "tags", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Matcher/MatchedRoute.php#L68-L85
230,459
OpenBuildings/jam
classes/Kohana/Upload/Server.php
Kohana_Upload_Server.instance
public static function instance($name = NULL, array $config = NULL) { if ($name === NULL) { // Use the default instance name $name = Upload_Server::$default; } if ( ! isset(Upload_Server::$instances[$name])) { if ($config === NULL) { // Load the configuration for this database $config = Arr::get(Kohana::$config->load('jam.upload.servers'), $name); } $validation = Validation::factory($config) ->rule('type', 'not_empty') ->rule('params', 'not_empty') ->rule('params', 'is_array'); if ( ! $validation->check()) throw new Kohana_Exception('Upload server config had errors: :errors', array(':errors' => join(', ', $validation->errors('upload_server')))); $server = 'server_'.$validation['type']; Upload_Server::$instances[$name] = Upload_Server::$server($validation['params']); } return Upload_Server::$instances[$name]; }
php
public static function instance($name = NULL, array $config = NULL) { if ($name === NULL) { // Use the default instance name $name = Upload_Server::$default; } if ( ! isset(Upload_Server::$instances[$name])) { if ($config === NULL) { // Load the configuration for this database $config = Arr::get(Kohana::$config->load('jam.upload.servers'), $name); } $validation = Validation::factory($config) ->rule('type', 'not_empty') ->rule('params', 'not_empty') ->rule('params', 'is_array'); if ( ! $validation->check()) throw new Kohana_Exception('Upload server config had errors: :errors', array(':errors' => join(', ', $validation->errors('upload_server')))); $server = 'server_'.$validation['type']; Upload_Server::$instances[$name] = Upload_Server::$server($validation['params']); } return Upload_Server::$instances[$name]; }
[ "public", "static", "function", "instance", "(", "$", "name", "=", "NULL", ",", "array", "$", "config", "=", "NULL", ")", "{", "if", "(", "$", "name", "===", "NULL", ")", "{", "// Use the default instance name", "$", "name", "=", "Upload_Server", "::", "$", "default", ";", "}", "if", "(", "!", "isset", "(", "Upload_Server", "::", "$", "instances", "[", "$", "name", "]", ")", ")", "{", "if", "(", "$", "config", "===", "NULL", ")", "{", "// Load the configuration for this database", "$", "config", "=", "Arr", "::", "get", "(", "Kohana", "::", "$", "config", "->", "load", "(", "'jam.upload.servers'", ")", ",", "$", "name", ")", ";", "}", "$", "validation", "=", "Validation", "::", "factory", "(", "$", "config", ")", "->", "rule", "(", "'type'", ",", "'not_empty'", ")", "->", "rule", "(", "'params'", ",", "'not_empty'", ")", "->", "rule", "(", "'params'", ",", "'is_array'", ")", ";", "if", "(", "!", "$", "validation", "->", "check", "(", ")", ")", "throw", "new", "Kohana_Exception", "(", "'Upload server config had errors: :errors'", ",", "array", "(", "':errors'", "=>", "join", "(", "', '", ",", "$", "validation", "->", "errors", "(", "'upload_server'", ")", ")", ")", ")", ";", "$", "server", "=", "'server_'", ".", "$", "validation", "[", "'type'", "]", ";", "Upload_Server", "::", "$", "instances", "[", "$", "name", "]", "=", "Upload_Server", "::", "$", "server", "(", "$", "validation", "[", "'params'", "]", ")", ";", "}", "return", "Upload_Server", "::", "$", "instances", "[", "$", "name", "]", ";", "}" ]
Get a singleton Upload_Server instance. If configuration is not specified, it will be loaded from the Upload_Server configuration file using the same group as the name. // Load the default server $server = Upload_Server::instance(); // Create a custom configured instance $server = Upload_Server::instance('custom', $config); @param string instance name @param array configuration parameters @return Database
[ "Get", "a", "singleton", "Upload_Server", "instance", ".", "If", "configuration", "is", "not", "specified", "it", "will", "be", "loaded", "from", "the", "Upload_Server", "configuration", "file", "using", "the", "same", "group", "as", "the", "name", "." ]
3239e93564d100ddb65055235f87ec99fc0d4370
https://github.com/OpenBuildings/jam/blob/3239e93564d100ddb65055235f87ec99fc0d4370/classes/Kohana/Upload/Server.php#L37-L67
230,460
Webiny/Framework
src/Webiny/Component/ServiceManager/ServiceCreator.php
ServiceCreator.getService
public function getService() { // Get real arguments values $arguments = []; foreach ($this->config->getArguments() as $arg) { $arguments[] = $arg->value(); } $service = $this->getServiceInstance($arguments); // Call methods foreach ($this->config->getCalls() as $call) { $arguments = []; foreach ($call[1] as $arg) { $arguments[] = $arg->value(); } call_user_func_array([ $service, $call[0] ], $arguments ); } return $service; }
php
public function getService() { // Get real arguments values $arguments = []; foreach ($this->config->getArguments() as $arg) { $arguments[] = $arg->value(); } $service = $this->getServiceInstance($arguments); // Call methods foreach ($this->config->getCalls() as $call) { $arguments = []; foreach ($call[1] as $arg) { $arguments[] = $arg->value(); } call_user_func_array([ $service, $call[0] ], $arguments ); } return $service; }
[ "public", "function", "getService", "(", ")", "{", "// Get real arguments values", "$", "arguments", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "config", "->", "getArguments", "(", ")", "as", "$", "arg", ")", "{", "$", "arguments", "[", "]", "=", "$", "arg", "->", "value", "(", ")", ";", "}", "$", "service", "=", "$", "this", "->", "getServiceInstance", "(", "$", "arguments", ")", ";", "// Call methods", "foreach", "(", "$", "this", "->", "config", "->", "getCalls", "(", ")", "as", "$", "call", ")", "{", "$", "arguments", "=", "[", "]", ";", "foreach", "(", "$", "call", "[", "1", "]", "as", "$", "arg", ")", "{", "$", "arguments", "[", "]", "=", "$", "arg", "->", "value", "(", ")", ";", "}", "call_user_func_array", "(", "[", "$", "service", ",", "$", "call", "[", "0", "]", "]", ",", "$", "arguments", ")", ";", "}", "return", "$", "service", ";", "}" ]
Get service instance @return object
[ "Get", "service", "instance" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceCreator.php#L34-L58
230,461
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Update.php
Update.addMedia
public function addMedia($key, $value) { $available = array('link', 'description', 'picture', 'thumbnail'); // accept only valid types for media if ( ! in_array($key, $available)) { throw new InvalidArgumentException('Media type must be a valid value: '.implode(', ', $available)); } $this->media[$key] = $value; return $this; }
php
public function addMedia($key, $value) { $available = array('link', 'description', 'picture', 'thumbnail'); // accept only valid types for media if ( ! in_array($key, $available)) { throw new InvalidArgumentException('Media type must be a valid value: '.implode(', ', $available)); } $this->media[$key] = $value; return $this; }
[ "public", "function", "addMedia", "(", "$", "key", ",", "$", "value", ")", "{", "$", "available", "=", "array", "(", "'link'", ",", "'description'", ",", "'picture'", ",", "'thumbnail'", ")", ";", "// accept only valid types for media", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "available", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Media type must be a valid value: '", ".", "implode", "(", "', '", ",", "$", "available", ")", ")", ";", "}", "$", "this", "->", "media", "[", "$", "key", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Add media to the update. @param string $key @param string $value @return \Ipalaus\Buffer\Update
[ "Add", "media", "to", "the", "update", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Update.php#L95-L107
230,462
ipalaus/buffer-php-sdk
src/Ipalaus/Buffer/Update.php
Update.schedule
public function schedule($when) { if (is_numeric($when)) { $dt = new DateTime; $dt->setTimestamp($when); } else { $dt = new DateTime($when); } $this->scheduled_at = $dt->format(DateTime::ISO8601); return $this; }
php
public function schedule($when) { if (is_numeric($when)) { $dt = new DateTime; $dt->setTimestamp($when); } else { $dt = new DateTime($when); } $this->scheduled_at = $dt->format(DateTime::ISO8601); return $this; }
[ "public", "function", "schedule", "(", "$", "when", ")", "{", "if", "(", "is_numeric", "(", "$", "when", ")", ")", "{", "$", "dt", "=", "new", "DateTime", ";", "$", "dt", "->", "setTimestamp", "(", "$", "when", ")", ";", "}", "else", "{", "$", "dt", "=", "new", "DateTime", "(", "$", "when", ")", ";", "}", "$", "this", "->", "scheduled_at", "=", "$", "dt", "->", "format", "(", "DateTime", "::", "ISO8601", ")", ";", "return", "$", "this", ";", "}" ]
Schedule a post with a timestamp or a valid DateTime string. @param mixed $when @return \Ipalaus\Buffer\Update
[ "Schedule", "a", "post", "with", "a", "timestamp", "or", "a", "valid", "DateTime", "string", "." ]
f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f
https://github.com/ipalaus/buffer-php-sdk/blob/f9314df3510f1dcdd6b3d5f618ce845c5f56bd5f/src/Ipalaus/Buffer/Update.php#L115-L127
230,463
Webiny/Framework
src/Webiny/Component/OAuth2/OAuth2Loader.php
OAuth2Loader.getInstance
public static function getInstance($key) { if (isset(self::$instances[$key])) { return self::$instances; } $oauth2Config = OAuth2::getConfig()->get($key, false); if (!$oauth2Config) { throw new OAuth2Exception('Unable to read "OAuth2.' . $key . '" configuration.'); } if (self::str($oauth2Config->RedirectUri)->startsWith('http')) { $redirectUri = $oauth2Config->RedirectUri; } else { $redirectUri = self::httpRequest() ->getCurrentUrl(true) ->setPath($oauth2Config->RedirectUri) ->setQuery('') ->val(); } $instance = Bridge\OAuth2::getInstance($oauth2Config->ClientId, $oauth2Config->ClientSecret, $redirectUri); $server = $oauth2Config->get('Server', false); if (!$server) { throw new OAuth2Exception('Server missing for "OAuth2.' . $key . '" configuration.'); } $instance->setOAuth2Server($server); $instance->setScope($oauth2Config->get('Scope', '')); return new OAuth2($instance); }
php
public static function getInstance($key) { if (isset(self::$instances[$key])) { return self::$instances; } $oauth2Config = OAuth2::getConfig()->get($key, false); if (!$oauth2Config) { throw new OAuth2Exception('Unable to read "OAuth2.' . $key . '" configuration.'); } if (self::str($oauth2Config->RedirectUri)->startsWith('http')) { $redirectUri = $oauth2Config->RedirectUri; } else { $redirectUri = self::httpRequest() ->getCurrentUrl(true) ->setPath($oauth2Config->RedirectUri) ->setQuery('') ->val(); } $instance = Bridge\OAuth2::getInstance($oauth2Config->ClientId, $oauth2Config->ClientSecret, $redirectUri); $server = $oauth2Config->get('Server', false); if (!$server) { throw new OAuth2Exception('Server missing for "OAuth2.' . $key . '" configuration.'); } $instance->setOAuth2Server($server); $instance->setScope($oauth2Config->get('Scope', '')); return new OAuth2($instance); }
[ "public", "static", "function", "getInstance", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "instances", "[", "$", "key", "]", ")", ")", "{", "return", "self", "::", "$", "instances", ";", "}", "$", "oauth2Config", "=", "OAuth2", "::", "getConfig", "(", ")", "->", "get", "(", "$", "key", ",", "false", ")", ";", "if", "(", "!", "$", "oauth2Config", ")", "{", "throw", "new", "OAuth2Exception", "(", "'Unable to read \"OAuth2.'", ".", "$", "key", ".", "'\" configuration.'", ")", ";", "}", "if", "(", "self", "::", "str", "(", "$", "oauth2Config", "->", "RedirectUri", ")", "->", "startsWith", "(", "'http'", ")", ")", "{", "$", "redirectUri", "=", "$", "oauth2Config", "->", "RedirectUri", ";", "}", "else", "{", "$", "redirectUri", "=", "self", "::", "httpRequest", "(", ")", "->", "getCurrentUrl", "(", "true", ")", "->", "setPath", "(", "$", "oauth2Config", "->", "RedirectUri", ")", "->", "setQuery", "(", "''", ")", "->", "val", "(", ")", ";", "}", "$", "instance", "=", "Bridge", "\\", "OAuth2", "::", "getInstance", "(", "$", "oauth2Config", "->", "ClientId", ",", "$", "oauth2Config", "->", "ClientSecret", ",", "$", "redirectUri", ")", ";", "$", "server", "=", "$", "oauth2Config", "->", "get", "(", "'Server'", ",", "false", ")", ";", "if", "(", "!", "$", "server", ")", "{", "throw", "new", "OAuth2Exception", "(", "'Server missing for \"OAuth2.'", ".", "$", "key", ".", "'\" configuration.'", ")", ";", "}", "$", "instance", "->", "setOAuth2Server", "(", "$", "server", ")", ";", "$", "instance", "->", "setScope", "(", "$", "oauth2Config", "->", "get", "(", "'Scope'", ",", "''", ")", ")", ";", "return", "new", "OAuth2", "(", "$", "instance", ")", ";", "}" ]
Returns an instance to OAuth2 server based on the current configuration. @param string $key Unique identifier for the OAuth2 server that you wish to get. @return array|OAuth2 @throws OAuth2Exception
[ "Returns", "an", "instance", "to", "OAuth2", "server", "based", "on", "the", "current", "configuration", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/OAuth2Loader.php#L33-L66
230,464
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.append
public function append($str) { $value = $this->val(); $this->val($value . $str); return $this; }
php
public function append($str) { $value = $this->val(); $this->val($value . $str); return $this; }
[ "public", "function", "append", "(", "$", "str", ")", "{", "$", "value", "=", "$", "this", "->", "val", "(", ")", ";", "$", "this", "->", "val", "(", "$", "value", ".", "$", "str", ")", ";", "return", "$", "this", ";", "}" ]
Appends the given string to the current string. @param string $str String you wish to append @return $this
[ "Appends", "the", "given", "string", "to", "the", "current", "string", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L53-L59
230,465
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.prepend
public function prepend($str) { $value = $this->val(); $this->val($str . $value); return $this; }
php
public function prepend($str) { $value = $this->val(); $this->val($str . $value); return $this; }
[ "public", "function", "prepend", "(", "$", "str", ")", "{", "$", "value", "=", "$", "this", "->", "val", "(", ")", ";", "$", "this", "->", "val", "(", "$", "str", ".", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Prepend the given string to the current string. @param string $str String you wish to append @return $this
[ "Prepend", "the", "given", "string", "to", "the", "current", "string", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L68-L74
230,466
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.caseWordUpper
public function caseWordUpper() { $this->val(mb_convert_case($this->val(), MB_CASE_TITLE, self::DEF_ENCODING)); return $this; }
php
public function caseWordUpper() { $this->val(mb_convert_case($this->val(), MB_CASE_TITLE, self::DEF_ENCODING)); return $this; }
[ "public", "function", "caseWordUpper", "(", ")", "{", "$", "this", "->", "val", "(", "mb_convert_case", "(", "$", "this", "->", "val", "(", ")", ",", "MB_CASE_TITLE", ",", "self", "::", "DEF_ENCODING", ")", ")", ";", "return", "$", "this", ";", "}" ]
Make the first character of every word upper. @return $this
[ "Make", "the", "first", "character", "of", "every", "word", "upper", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L150-L155
230,467
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.subString
public function subString($startPosition, $length) { if (!$this->isNumber($startPosition)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$startPosition', 'integer' ]); } if (!$this->isNumber($length)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$length', 'integer' ]); } if ($length == 0) { $length = null; } $value = mb_substr($this->val(), $startPosition, $length, self::DEF_ENCODING); $this->val($value); return $this; }
php
public function subString($startPosition, $length) { if (!$this->isNumber($startPosition)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$startPosition', 'integer' ]); } if (!$this->isNumber($length)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$length', 'integer' ]); } if ($length == 0) { $length = null; } $value = mb_substr($this->val(), $startPosition, $length, self::DEF_ENCODING); $this->val($value); return $this; }
[ "public", "function", "subString", "(", "$", "startPosition", ",", "$", "length", ")", "{", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "startPosition", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$startPosition'", ",", "'integer'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "length", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$length'", ",", "'integer'", "]", ")", ";", "}", "if", "(", "$", "length", "==", "0", ")", "{", "$", "length", "=", "null", ";", "}", "$", "value", "=", "mb_substr", "(", "$", "this", "->", "val", "(", ")", ",", "$", "startPosition", ",", "$", "length", ",", "self", "::", "DEF_ENCODING", ")", ";", "$", "this", "->", "val", "(", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Returns a substring from the current string. @param int $startPosition From which char position will the substring start. @param int $length Where will the substring end. If 0 - to the end of string. @throws StringObjectException @return $this
[ "Returns", "a", "substring", "from", "the", "current", "string", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L295-L318
230,468
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.pregReplace
public function pregReplace($pattern, $replacement, $limit = -1, &$count = null) { $this->val(preg_replace($pattern, $replacement, $this->val(), $limit, $count)); return $this; }
php
public function pregReplace($pattern, $replacement, $limit = -1, &$count = null) { $this->val(preg_replace($pattern, $replacement, $this->val(), $limit, $count)); return $this; }
[ "public", "function", "pregReplace", "(", "$", "pattern", ",", "$", "replacement", ",", "$", "limit", "=", "-", "1", ",", "&", "$", "count", "=", "null", ")", "{", "$", "this", "->", "val", "(", "preg_replace", "(", "$", "pattern", ",", "$", "replacement", ",", "$", "this", "->", "val", "(", ")", ",", "$", "limit", ",", "$", "count", ")", ")", ";", "return", "$", "this", ";", "}" ]
Replace string using regex TODO: unit test @param string $pattern The pattern to search for. It can be either a string or an array with strings. @param mixed $replacement The string or an array with strings to replace. @param int $limit The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit). @param null $count If specified, this variable will be filled with the number of replacements done. @return $this
[ "Replace", "string", "using", "regex" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L354-L360
230,469
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.explode
public function explode($delimiter, $limit = null) { if (!$this->isString($delimiter)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$delimiter', 'string' ]); } if ($this->isNull($limit)) { $arr = explode($delimiter, $this->val()); } else { if (!$this->isNumber($limit)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$limit', 'integer' ]); } $arr = explode($delimiter, $this->val(), $limit); } if (!$arr) { throw new StringObjectException(StringObjectException::MSG_UNABLE_TO_EXPLODE, [$delimiter]); } return new ArrayObject($arr); }
php
public function explode($delimiter, $limit = null) { if (!$this->isString($delimiter)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$delimiter', 'string' ]); } if ($this->isNull($limit)) { $arr = explode($delimiter, $this->val()); } else { if (!$this->isNumber($limit)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$limit', 'integer' ]); } $arr = explode($delimiter, $this->val(), $limit); } if (!$arr) { throw new StringObjectException(StringObjectException::MSG_UNABLE_TO_EXPLODE, [$delimiter]); } return new ArrayObject($arr); }
[ "public", "function", "explode", "(", "$", "delimiter", ",", "$", "limit", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "delimiter", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$delimiter'", ",", "'string'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "isNull", "(", "$", "limit", ")", ")", "{", "$", "arr", "=", "explode", "(", "$", "delimiter", ",", "$", "this", "->", "val", "(", ")", ")", ";", "}", "else", "{", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "limit", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$limit'", ",", "'integer'", "]", ")", ";", "}", "$", "arr", "=", "explode", "(", "$", "delimiter", ",", "$", "this", "->", "val", "(", ")", ",", "$", "limit", ")", ";", "}", "if", "(", "!", "$", "arr", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_UNABLE_TO_EXPLODE", ",", "[", "$", "delimiter", "]", ")", ";", "}", "return", "new", "ArrayObject", "(", "$", "arr", ")", ";", "}" ]
Explode the current string with the given delimiter and return ArrayObject with the exploded values. @param string $delimiter String upon which the current string will be exploded. @param null|int $limit Limit the number of exploded items. @return ArrayObject ArrayObject object containing exploded values. @throws StringObjectException
[ "Explode", "the", "current", "string", "with", "the", "given", "delimiter", "and", "return", "ArrayObject", "with", "the", "exploded", "values", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L371-L398
230,470
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.split
public function split($chunkSize = 1) { if (!$this->isNumber($chunkSize)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$chunkSize', 'integer' ]); } $arr = str_split($this->val(), $chunkSize); return new ArrayObject($arr); }
php
public function split($chunkSize = 1) { if (!$this->isNumber($chunkSize)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$chunkSize', 'integer' ]); } $arr = str_split($this->val(), $chunkSize); return new ArrayObject($arr); }
[ "public", "function", "split", "(", "$", "chunkSize", "=", "1", ")", "{", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "chunkSize", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$chunkSize'", ",", "'integer'", "]", ")", ";", "}", "$", "arr", "=", "str_split", "(", "$", "this", "->", "val", "(", ")", ",", "$", "chunkSize", ")", ";", "return", "new", "ArrayObject", "(", "$", "arr", ")", ";", "}" ]
Split the string into chunks. @param int $chunkSize Size of each chunk. Set it to 1 if you want to get all the characters from the string. @throws StringObjectException @return ArrayObject ArrayObject containing string chunks.
[ "Split", "the", "string", "into", "chunks", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L408-L420
230,471
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.hash
public function hash($algo = 'sha1') { $algos = new ArrayObject(hash_algos()); if (!$algos->inArray($algo)) { throw new StringObjectException(StringObjectException::MSG_INVALID_HASH_ALGO, [$algo]); } $this->val(hash($algo, $this->val())); return $this; }
php
public function hash($algo = 'sha1') { $algos = new ArrayObject(hash_algos()); if (!$algos->inArray($algo)) { throw new StringObjectException(StringObjectException::MSG_INVALID_HASH_ALGO, [$algo]); } $this->val(hash($algo, $this->val())); return $this; }
[ "public", "function", "hash", "(", "$", "algo", "=", "'sha1'", ")", "{", "$", "algos", "=", "new", "ArrayObject", "(", "hash_algos", "(", ")", ")", ";", "if", "(", "!", "$", "algos", "->", "inArray", "(", "$", "algo", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_HASH_ALGO", ",", "[", "$", "algo", "]", ")", ";", "}", "$", "this", "->", "val", "(", "hash", "(", "$", "algo", ",", "$", "this", "->", "val", "(", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
Generate a hash value from the current string using the defined algorithm. @param string $algo Name of the algorithm used for calculation (md5, sha1, ripemd160,...). @throws StringObjectException @return $this
[ "Generate", "a", "hash", "value", "from", "the", "current", "string", "using", "the", "defined", "algorithm", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L430-L440
230,472
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.stripTags
public function stripTags($whiteList = '') { if (!$this->isString($whiteList)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$whiteList', 'integer' ]); } $this->val(strip_tags($this->val(), $whiteList)); return $this; }
php
public function stripTags($whiteList = '') { if (!$this->isString($whiteList)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$whiteList', 'integer' ]); } $this->val(strip_tags($this->val(), $whiteList)); return $this; }
[ "public", "function", "stripTags", "(", "$", "whiteList", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "whiteList", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$whiteList'", ",", "'integer'", "]", ")", ";", "}", "$", "this", "->", "val", "(", "strip_tags", "(", "$", "this", "->", "val", "(", ")", ",", "$", "whiteList", ")", ")", ";", "return", "$", "this", ";", "}" ]
Remove HTML tags from the string. @param string $whiteList A list of allowed HTML tags that you don't want to strip. Example: '<p><a>' @throws StringObjectException @return $this
[ "Remove", "HTML", "tags", "from", "the", "string", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L758-L770
230,473
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.wordWrap
public function wordWrap($length, $break = "\n", $cut = false) { if (!$this->isNumber($length)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$length', 'integer' ]); } if (!$this->isString($break)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$break', 'string' ]); } if (!$this->isBool($cut)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$cut', 'boolean' ]); } $this->val(wordwrap($this->val(), $length, $break, $cut)); return $this; }
php
public function wordWrap($length, $break = "\n", $cut = false) { if (!$this->isNumber($length)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$length', 'integer' ]); } if (!$this->isString($break)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$break', 'string' ]); } if (!$this->isBool($cut)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$cut', 'boolean' ]); } $this->val(wordwrap($this->val(), $length, $break, $cut)); return $this; }
[ "public", "function", "wordWrap", "(", "$", "length", ",", "$", "break", "=", "\"\\n\"", ",", "$", "cut", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "length", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$length'", ",", "'integer'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "break", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$break'", ",", "'string'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isBool", "(", "$", "cut", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$cut'", ",", "'boolean'", "]", ")", ";", "}", "$", "this", "->", "val", "(", "wordwrap", "(", "$", "this", "->", "val", "(", ")", ",", "$", "length", ",", "$", "break", ",", "$", "cut", ")", ")", ";", "return", "$", "this", ";", "}" ]
Wraps a string to a given number of characters using a string break character. @param int $length The number of characters at which the string will be wrapped. @param string $break The line is broken using the optional break parameter. @param bool $cut If the cut is set to TRUE, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart. @throws StringObjectException @return $this
[ "Wraps", "a", "string", "to", "a", "given", "number", "of", "characters", "using", "a", "string", "break", "character", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L795-L820
230,474
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.truncate
public function truncate($length, $ellipsis = '') { if (!$this->isNumber($length)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$length', 'integer' ]); } if (!$this->isString($ellipsis)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$ellipsis', 'string' ]); } if ($this->length() <= $length) { return $this; } if ($ellipsis != '') { $length = $length - strlen($ellipsis); } $this->wordWrap($length)->subString(0, $this->stringPosition("\n")); $this->val($this->val() . $ellipsis); return $this; }
php
public function truncate($length, $ellipsis = '') { if (!$this->isNumber($length)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$length', 'integer' ]); } if (!$this->isString($ellipsis)) { throw new StringObjectException(StringObjectException::MSG_INVALID_ARG, [ '$ellipsis', 'string' ]); } if ($this->length() <= $length) { return $this; } if ($ellipsis != '') { $length = $length - strlen($ellipsis); } $this->wordWrap($length)->subString(0, $this->stringPosition("\n")); $this->val($this->val() . $ellipsis); return $this; }
[ "public", "function", "truncate", "(", "$", "length", ",", "$", "ellipsis", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "isNumber", "(", "$", "length", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$length'", ",", "'integer'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "isString", "(", "$", "ellipsis", ")", ")", "{", "throw", "new", "StringObjectException", "(", "StringObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$ellipsis'", ",", "'string'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "length", "(", ")", "<=", "$", "length", ")", "{", "return", "$", "this", ";", "}", "if", "(", "$", "ellipsis", "!=", "''", ")", "{", "$", "length", "=", "$", "length", "-", "strlen", "(", "$", "ellipsis", ")", ";", "}", "$", "this", "->", "wordWrap", "(", "$", "length", ")", "->", "subString", "(", "0", ",", "$", "this", "->", "stringPosition", "(", "\"\\n\"", ")", ")", ";", "$", "this", "->", "val", "(", "$", "this", "->", "val", "(", ")", ".", "$", "ellipsis", ")", ";", "return", "$", "this", ";", "}" ]
Truncate the string to the given length without breaking words. @param int $length Length to which you which to trim. @param string $ellipsis Ellipsis is calculated in the string $length. @throws StringObjectException @return $this
[ "Truncate", "the", "string", "to", "the", "given", "length", "without", "breaking", "words", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L831-L860
230,475
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.base64Encode
public function base64Encode($webSafe = false) { $this->val(base64_encode($this->val())); if ($webSafe) { $this->replace('+', '-')->replace('/', '_'); } return $this; }
php
public function base64Encode($webSafe = false) { $this->val(base64_encode($this->val())); if ($webSafe) { $this->replace('+', '-')->replace('/', '_'); } return $this; }
[ "public", "function", "base64Encode", "(", "$", "webSafe", "=", "false", ")", "{", "$", "this", "->", "val", "(", "base64_encode", "(", "$", "this", "->", "val", "(", ")", ")", ")", ";", "if", "(", "$", "webSafe", ")", "{", "$", "this", "->", "replace", "(", "'+'", ",", "'-'", ")", "->", "replace", "(", "'/'", ",", "'_'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Encode string using base64_encode @param bool $webSafe Web safe encoding (replaces '+' with '-' and '/' with '_' after encoding) @return $this
[ "Encode", "string", "using", "base64_encode" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L941-L950
230,476
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php
ManipulatorTrait.base64Decode
public function base64Decode($webSafe = false) { $this->val(base64_decode($this->val())); if ($webSafe) { $this->replace('-', '+')->replace('_', '/'); } return $this; }
php
public function base64Decode($webSafe = false) { $this->val(base64_decode($this->val())); if ($webSafe) { $this->replace('-', '+')->replace('_', '/'); } return $this; }
[ "public", "function", "base64Decode", "(", "$", "webSafe", "=", "false", ")", "{", "$", "this", "->", "val", "(", "base64_decode", "(", "$", "this", "->", "val", "(", ")", ")", ")", ";", "if", "(", "$", "webSafe", ")", "{", "$", "this", "->", "replace", "(", "'-'", ",", "'+'", ")", "->", "replace", "(", "'_'", ",", "'/'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Decode base64 encoded string @param bool $webSafe Web sage decoding (replaces '-' with '+' and '_' with '/' before decoding) @return $this
[ "Decode", "base64", "encoded", "string" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/StringObject/ManipulatorTrait.php#L959-L968
230,477
alexandresalome/php-webdriver
src/WebDriver/Client.php
Client.request
public function request($verb, $path, $content = null, array $headers = array()) { $url = $this->url.$path; $request = new Request($verb, $url); $request->setContent($content); $response = new Response(); $this->client->send($request, $response); $response->setContent(str_replace("\0", "", $response->getContent())); $this->verifyResponse($response); return $response; }
php
public function request($verb, $path, $content = null, array $headers = array()) { $url = $this->url.$path; $request = new Request($verb, $url); $request->setContent($content); $response = new Response(); $this->client->send($request, $response); $response->setContent(str_replace("\0", "", $response->getContent())); $this->verifyResponse($response); return $response; }
[ "public", "function", "request", "(", "$", "verb", ",", "$", "path", ",", "$", "content", "=", "null", ",", "array", "$", "headers", "=", "array", "(", ")", ")", "{", "$", "url", "=", "$", "this", "->", "url", ".", "$", "path", ";", "$", "request", "=", "new", "Request", "(", "$", "verb", ",", "$", "url", ")", ";", "$", "request", "->", "setContent", "(", "$", "content", ")", ";", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "this", "->", "client", "->", "send", "(", "$", "request", ",", "$", "response", ")", ";", "$", "response", "->", "setContent", "(", "str_replace", "(", "\"\\0\"", ",", "\"\"", ",", "$", "response", "->", "getContent", "(", ")", ")", ")", ";", "$", "this", "->", "verifyResponse", "(", "$", "response", ")", ";", "return", "$", "response", ";", "}" ]
Plumbery method to request webdriver server. @param string $verb HTTP method to use (GET, POST, DELETE) @param string $path Relative URL to server, without prefix "/" @param string $content Content of request @param array $headers Additional HTTP headers
[ "Plumbery", "method", "to", "request", "webdriver", "server", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Client.php#L78-L90
230,478
alexandresalome/php-webdriver
src/WebDriver/Client.php
Client.createBrowser
public function createBrowser($capabilities) { if (is_string($capabilities)) { $capabilities = new Capabilities($capabilities); } elseif (!$capabilities instanceof Capabilities) { throw new LibraryException(sprintf('Expected a Capabilities or a string, given a "%s"', gettype($capabilities))); } $response = $this->request('POST', '/session', json_encode(array('desiredCapabilities' => $capabilities->toArray()))); $sessionId = $this->getSessionIdFromResponse($response); return $this->browsers[$sessionId] = new Browser($this, $sessionId); }
php
public function createBrowser($capabilities) { if (is_string($capabilities)) { $capabilities = new Capabilities($capabilities); } elseif (!$capabilities instanceof Capabilities) { throw new LibraryException(sprintf('Expected a Capabilities or a string, given a "%s"', gettype($capabilities))); } $response = $this->request('POST', '/session', json_encode(array('desiredCapabilities' => $capabilities->toArray()))); $sessionId = $this->getSessionIdFromResponse($response); return $this->browsers[$sessionId] = new Browser($this, $sessionId); }
[ "public", "function", "createBrowser", "(", "$", "capabilities", ")", "{", "if", "(", "is_string", "(", "$", "capabilities", ")", ")", "{", "$", "capabilities", "=", "new", "Capabilities", "(", "$", "capabilities", ")", ";", "}", "elseif", "(", "!", "$", "capabilities", "instanceof", "Capabilities", ")", "{", "throw", "new", "LibraryException", "(", "sprintf", "(", "'Expected a Capabilities or a string, given a \"%s\"'", ",", "gettype", "(", "$", "capabilities", ")", ")", ")", ";", "}", "$", "response", "=", "$", "this", "->", "request", "(", "'POST'", ",", "'/session'", ",", "json_encode", "(", "array", "(", "'desiredCapabilities'", "=>", "$", "capabilities", "->", "toArray", "(", ")", ")", ")", ")", ";", "$", "sessionId", "=", "$", "this", "->", "getSessionIdFromResponse", "(", "$", "response", ")", ";", "return", "$", "this", "->", "browsers", "[", "$", "sessionId", "]", "=", "new", "Browser", "(", "$", "this", ",", "$", "sessionId", ")", ";", "}" ]
Creates a new browser with desired capabilities. @param mixed $capabilities Capabilities to request to the server. Value can be a string (firefox) or a Capabilities object. @return Browser
[ "Creates", "a", "new", "browser", "with", "desired", "capabilities", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Client.php#L101-L113
230,479
alexandresalome/php-webdriver
src/WebDriver/Client.php
Client.getBrowser
public function getBrowser($sessionId) { if (!isset($this->browsers[$sessionId])) { throw new LibraryException(sprintf('The session "%s" was not found', $sessionId)); } return $this->browsers[$sessionId]; }
php
public function getBrowser($sessionId) { if (!isset($this->browsers[$sessionId])) { throw new LibraryException(sprintf('The session "%s" was not found', $sessionId)); } return $this->browsers[$sessionId]; }
[ "public", "function", "getBrowser", "(", "$", "sessionId", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "browsers", "[", "$", "sessionId", "]", ")", ")", "{", "throw", "new", "LibraryException", "(", "sprintf", "(", "'The session \"%s\" was not found'", ",", "$", "sessionId", ")", ")", ";", "}", "return", "$", "this", "->", "browsers", "[", "$", "sessionId", "]", ";", "}" ]
Returns a browser associated to a session ID. To get it, it must have been created. @param string $sessionId The session ID to fetch @return Browser @throws RuntimeException An exception is thrown if the session does not exists.
[ "Returns", "a", "browser", "associated", "to", "a", "session", "ID", ".", "To", "get", "it", "it", "must", "have", "been", "created", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Client.php#L136-L143
230,480
alexandresalome/php-webdriver
src/WebDriver/Client.php
Client.verifyResponse
protected function verifyResponse(Response $response) { $content = json_decode($response->getContent(), true); $statusCode = $response->getStatusCode(); if ($statusCode !== 204 && null === $content) { throw new LibraryException('Unable to parse response from server (status code: '.$response->getStatusCode().') '.$response->getContent()); } if (isset($content['status']) && $content['status'] !== ExceptionFactory::STATUS_SUCCESS) { throw ExceptionFactory::createExceptionFromArray($content); } if ($statusCode !== 200 && $statusCode !== 204 && ($statusCode < 300 || $statusCode > 303)) { throw new LibraryException(sprintf('Invalid status code (expected 200, 204, or 300-303. Got %s). Response content: %s', $statusCode, $response->getContent())); } }
php
protected function verifyResponse(Response $response) { $content = json_decode($response->getContent(), true); $statusCode = $response->getStatusCode(); if ($statusCode !== 204 && null === $content) { throw new LibraryException('Unable to parse response from server (status code: '.$response->getStatusCode().') '.$response->getContent()); } if (isset($content['status']) && $content['status'] !== ExceptionFactory::STATUS_SUCCESS) { throw ExceptionFactory::createExceptionFromArray($content); } if ($statusCode !== 200 && $statusCode !== 204 && ($statusCode < 300 || $statusCode > 303)) { throw new LibraryException(sprintf('Invalid status code (expected 200, 204, or 300-303. Got %s). Response content: %s', $statusCode, $response->getContent())); } }
[ "protected", "function", "verifyResponse", "(", "Response", "$", "response", ")", "{", "$", "content", "=", "json_decode", "(", "$", "response", "->", "getContent", "(", ")", ",", "true", ")", ";", "$", "statusCode", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "if", "(", "$", "statusCode", "!==", "204", "&&", "null", "===", "$", "content", ")", "{", "throw", "new", "LibraryException", "(", "'Unable to parse response from server (status code: '", ".", "$", "response", "->", "getStatusCode", "(", ")", ".", "') '", ".", "$", "response", "->", "getContent", "(", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "content", "[", "'status'", "]", ")", "&&", "$", "content", "[", "'status'", "]", "!==", "ExceptionFactory", "::", "STATUS_SUCCESS", ")", "{", "throw", "ExceptionFactory", "::", "createExceptionFromArray", "(", "$", "content", ")", ";", "}", "if", "(", "$", "statusCode", "!==", "200", "&&", "$", "statusCode", "!==", "204", "&&", "(", "$", "statusCode", "<", "300", "||", "$", "statusCode", ">", "303", ")", ")", "{", "throw", "new", "LibraryException", "(", "sprintf", "(", "'Invalid status code (expected 200, 204, or 300-303. Got %s). Response content: %s'", ",", "$", "statusCode", ",", "$", "response", "->", "getContent", "(", ")", ")", ")", ";", "}", "}" ]
Verifies every response received from the server to make sure no error happened during processing. @param Buzz\Message\Response A response object to verify
[ "Verifies", "every", "response", "received", "from", "the", "server", "to", "make", "sure", "no", "error", "happened", "during", "processing", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Client.php#L163-L179
230,481
Webiny/Framework
src/Webiny/Component/Entity/Attribute/AbstractCollectionAttribute.php
AbstractCollectionAttribute.normalizeValue
protected function normalizeValue($value) { if (is_null($value)) { return $value; } $entityClass = $this->getEntity(); // Validate Many2many attribute value if (!$this->isArray($value) && !$this->isArrayObject($value) && !$this->isInstanceOf($value, EntityCollection::class)) { $exception = new ValidationException(ValidationException::DATA_TYPE, [ 'array, ArrayObject or EntityCollection', gettype($value) ]); $exception->setAttribute($this->getName()); throw $exception; } /* @var $entityAttribute One2ManyAttribute */ $values = []; foreach ($value as $item) { $itemEntity = false; // $item can be an array of data, AbstractEntity or a simple mongo ID string if ($this->isInstanceOf($item, $entityClass)) { $itemEntity = $item; } elseif ($this->isArray($item) || $this->isArrayObject($item)) { $itemEntity = $entityClass::findById(isset($item['id']) ? $item['id'] : false); } elseif ($this->isString($item) && Entity::getInstance()->getDatabase()->isId($item)) { $itemEntity = $entityClass::findById($item); } // If instance was not found, create a new entity instance if (!$itemEntity) { $itemEntity = new $entityClass; } // If $item is an array - use it to populate the entity instance if ($this->isArray($item) || $this->isArrayObject($item)) { $itemEntity->populate($item); } $values[] = $itemEntity; } return new EntityCollection($this->getEntity(), $values); }
php
protected function normalizeValue($value) { if (is_null($value)) { return $value; } $entityClass = $this->getEntity(); // Validate Many2many attribute value if (!$this->isArray($value) && !$this->isArrayObject($value) && !$this->isInstanceOf($value, EntityCollection::class)) { $exception = new ValidationException(ValidationException::DATA_TYPE, [ 'array, ArrayObject or EntityCollection', gettype($value) ]); $exception->setAttribute($this->getName()); throw $exception; } /* @var $entityAttribute One2ManyAttribute */ $values = []; foreach ($value as $item) { $itemEntity = false; // $item can be an array of data, AbstractEntity or a simple mongo ID string if ($this->isInstanceOf($item, $entityClass)) { $itemEntity = $item; } elseif ($this->isArray($item) || $this->isArrayObject($item)) { $itemEntity = $entityClass::findById(isset($item['id']) ? $item['id'] : false); } elseif ($this->isString($item) && Entity::getInstance()->getDatabase()->isId($item)) { $itemEntity = $entityClass::findById($item); } // If instance was not found, create a new entity instance if (!$itemEntity) { $itemEntity = new $entityClass; } // If $item is an array - use it to populate the entity instance if ($this->isArray($item) || $this->isArrayObject($item)) { $itemEntity->populate($item); } $values[] = $itemEntity; } return new EntityCollection($this->getEntity(), $values); }
[ "protected", "function", "normalizeValue", "(", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "$", "entityClass", "=", "$", "this", "->", "getEntity", "(", ")", ";", "// Validate Many2many attribute value", "if", "(", "!", "$", "this", "->", "isArray", "(", "$", "value", ")", "&&", "!", "$", "this", "->", "isArrayObject", "(", "$", "value", ")", "&&", "!", "$", "this", "->", "isInstanceOf", "(", "$", "value", ",", "EntityCollection", "::", "class", ")", ")", "{", "$", "exception", "=", "new", "ValidationException", "(", "ValidationException", "::", "DATA_TYPE", ",", "[", "'array, ArrayObject or EntityCollection'", ",", "gettype", "(", "$", "value", ")", "]", ")", ";", "$", "exception", "->", "setAttribute", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "throw", "$", "exception", ";", "}", "/* @var $entityAttribute One2ManyAttribute */", "$", "values", "=", "[", "]", ";", "foreach", "(", "$", "value", "as", "$", "item", ")", "{", "$", "itemEntity", "=", "false", ";", "// $item can be an array of data, AbstractEntity or a simple mongo ID string", "if", "(", "$", "this", "->", "isInstanceOf", "(", "$", "item", ",", "$", "entityClass", ")", ")", "{", "$", "itemEntity", "=", "$", "item", ";", "}", "elseif", "(", "$", "this", "->", "isArray", "(", "$", "item", ")", "||", "$", "this", "->", "isArrayObject", "(", "$", "item", ")", ")", "{", "$", "itemEntity", "=", "$", "entityClass", "::", "findById", "(", "isset", "(", "$", "item", "[", "'id'", "]", ")", "?", "$", "item", "[", "'id'", "]", ":", "false", ")", ";", "}", "elseif", "(", "$", "this", "->", "isString", "(", "$", "item", ")", "&&", "Entity", "::", "getInstance", "(", ")", "->", "getDatabase", "(", ")", "->", "isId", "(", "$", "item", ")", ")", "{", "$", "itemEntity", "=", "$", "entityClass", "::", "findById", "(", "$", "item", ")", ";", "}", "// If instance was not found, create a new entity instance", "if", "(", "!", "$", "itemEntity", ")", "{", "$", "itemEntity", "=", "new", "$", "entityClass", ";", "}", "// If $item is an array - use it to populate the entity instance", "if", "(", "$", "this", "->", "isArray", "(", "$", "item", ")", "||", "$", "this", "->", "isArrayObject", "(", "$", "item", ")", ")", "{", "$", "itemEntity", "->", "populate", "(", "$", "item", ")", ";", "}", "$", "values", "[", "]", "=", "$", "itemEntity", ";", "}", "return", "new", "EntityCollection", "(", "$", "this", "->", "getEntity", "(", ")", ",", "$", "values", ")", ";", "}" ]
Normalize given value to be a valid array of entity instances @param mixed $value @return array @throws ValidationException
[ "Normalize", "given", "value", "to", "be", "a", "valid", "array", "of", "entity", "instances" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Attribute/AbstractCollectionAttribute.php#L160-L205
230,482
Webiny/Framework
src/Webiny/Component/Cache/Cache.php
Cache.Couchbase
public static function Couchbase($user, $password, $bucket, $host = '127.0.0.1:8091', $options = []) { return new CacheStorage(Storage\Couchbase::getInstance($user, $password, $bucket, $host), $options); }
php
public static function Couchbase($user, $password, $bucket, $host = '127.0.0.1:8091', $options = []) { return new CacheStorage(Storage\Couchbase::getInstance($user, $password, $bucket, $host), $options); }
[ "public", "static", "function", "Couchbase", "(", "$", "user", ",", "$", "password", ",", "$", "bucket", ",", "$", "host", "=", "'127.0.0.1:8091'", ",", "$", "options", "=", "[", "]", ")", "{", "return", "new", "CacheStorage", "(", "Storage", "\\", "Couchbase", "::", "getInstance", "(", "$", "user", ",", "$", "password", ",", "$", "bucket", ",", "$", "host", ")", ",", "$", "options", ")", ";", "}" ]
Create a cache instance with Couchbase as cache driver. @param string $user Couchbase username. @param string $password Couchbase password. @param string $bucket Couchbase bucket. @param string $host Couchbase host (with port number). @param array $options Cache options. @return CacheStorage
[ "Create", "a", "cache", "instance", "with", "Couchbase", "as", "cache", "driver", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Cache.php#L50-L53
230,483
Webiny/Framework
src/Webiny/Component/Cache/Cache.php
Cache.Memcache
public static function Memcache($host = '127.0.0.1', $port = 11211, $options = []) { return new CacheStorage(Storage\Memcache::getInstance($host, $port), $options); }
php
public static function Memcache($host = '127.0.0.1', $port = 11211, $options = []) { return new CacheStorage(Storage\Memcache::getInstance($host, $port), $options); }
[ "public", "static", "function", "Memcache", "(", "$", "host", "=", "'127.0.0.1'", ",", "$", "port", "=", "11211", ",", "$", "options", "=", "[", "]", ")", "{", "return", "new", "CacheStorage", "(", "Storage", "\\", "Memcache", "::", "getInstance", "(", "$", "host", ",", "$", "port", ")", ",", "$", "options", ")", ";", "}" ]
Create a cache instance with Memcache as cache driver. @param string $host Host where the memcached is running. @param int $port Port where memcached is running. @param array $options Cache options. @return CacheStorage
[ "Create", "a", "cache", "instance", "with", "Memcache", "as", "cache", "driver", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Cache.php#L64-L67
230,484
Webiny/Framework
src/Webiny/Component/Cache/Cache.php
Cache.Redis
public static function Redis($host = '127.0.0.1', $port = 6379, $options = []) { return new CacheStorage(Storage\Redis::getInstance($host, $port), $options); }
php
public static function Redis($host = '127.0.0.1', $port = 6379, $options = []) { return new CacheStorage(Storage\Redis::getInstance($host, $port), $options); }
[ "public", "static", "function", "Redis", "(", "$", "host", "=", "'127.0.0.1'", ",", "$", "port", "=", "6379", ",", "$", "options", "=", "[", "]", ")", "{", "return", "new", "CacheStorage", "(", "Storage", "\\", "Redis", "::", "getInstance", "(", "$", "host", ",", "$", "port", ")", ",", "$", "options", ")", ";", "}" ]
Create a cache instance with Redis as cache driver. @param string $host Host where the Redis server is running. @param int $port Port where Redis server is running. @param array $options Cache options. @return CacheStorage
[ "Create", "a", "cache", "instance", "with", "Redis", "as", "cache", "driver", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Cache.php#L78-L81
230,485
milesj/admin
Controller/AdminAppController.php
AdminAppController.isAuthorized
public function isAuthorized($user = null) { if (!$user) { throw new ForbiddenException(__d('admin', 'Invalid User')); } $aro = Admin::introspectModel('Admin.RequestObject'); if ($aro->isAdmin($user['id'])) { if (!$this->Session->read('Admin.crud')) { $this->Session->write('Admin.crud', $aro->getCrudPermissions($user['id'])); } return true; } throw new UnauthorizedException(__d('admin', 'Insufficient Access Permissions')); }
php
public function isAuthorized($user = null) { if (!$user) { throw new ForbiddenException(__d('admin', 'Invalid User')); } $aro = Admin::introspectModel('Admin.RequestObject'); if ($aro->isAdmin($user['id'])) { if (!$this->Session->read('Admin.crud')) { $this->Session->write('Admin.crud', $aro->getCrudPermissions($user['id'])); } return true; } throw new UnauthorizedException(__d('admin', 'Insufficient Access Permissions')); }
[ "public", "function", "isAuthorized", "(", "$", "user", "=", "null", ")", "{", "if", "(", "!", "$", "user", ")", "{", "throw", "new", "ForbiddenException", "(", "__d", "(", "'admin'", ",", "'Invalid User'", ")", ")", ";", "}", "$", "aro", "=", "Admin", "::", "introspectModel", "(", "'Admin.RequestObject'", ")", ";", "if", "(", "$", "aro", "->", "isAdmin", "(", "$", "user", "[", "'id'", "]", ")", ")", "{", "if", "(", "!", "$", "this", "->", "Session", "->", "read", "(", "'Admin.crud'", ")", ")", "{", "$", "this", "->", "Session", "->", "write", "(", "'Admin.crud'", ",", "$", "aro", "->", "getCrudPermissions", "(", "$", "user", "[", "'id'", "]", ")", ")", ";", "}", "return", "true", ";", "}", "throw", "new", "UnauthorizedException", "(", "__d", "(", "'admin'", ",", "'Insufficient Access Permissions'", ")", ")", ";", "}" ]
Validate the user is authorized. @param array $user @return bool @throws ForbiddenException @throws UnauthorizedException
[ "Validate", "the", "user", "is", "authorized", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/AdminAppController.php#L76-L92
230,486
milesj/admin
Controller/AdminAppController.php
AdminAppController.beforeRender
public function beforeRender() { $this->set('user', $this->Auth->user()); $this->set('config', Configure::read()); $this->set('model', $this->Model); }
php
public function beforeRender() { $this->set('user', $this->Auth->user()); $this->set('config', Configure::read()); $this->set('model', $this->Model); }
[ "public", "function", "beforeRender", "(", ")", "{", "$", "this", "->", "set", "(", "'user'", ",", "$", "this", "->", "Auth", "->", "user", "(", ")", ")", ";", "$", "this", "->", "set", "(", "'config'", ",", "Configure", "::", "read", "(", ")", ")", ";", "$", "this", "->", "set", "(", "'model'", ",", "$", "this", "->", "Model", ")", ";", "}" ]
Before render.
[ "Before", "render", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/AdminAppController.php#L111-L115
230,487
milesj/admin
Controller/AdminAppController.php
AdminAppController.proxy
public function proxy() { if (empty($this->Model) || empty($this->request->data[$this->Model->alias])) { $this->redirect($this->referer()); } $data = $this->request->data[$this->Model->alias]; $named = array(); foreach ($data as $key => $value) { if ( mb_substr($key, -7) === '_filter' || mb_substr($key, -11) === '_type_ahead' || $value === '') { continue; } $named[$key] = urlencode($value); if (isset($data[$key . '_filter'])) { $named[$key . '_filter'] = urlencode($data[$key . '_filter']); } if (isset($data[$key . '_type_ahead'])) { $named[$key . '_type_ahead'] = urlencode($data[$key . '_type_ahead']); } } $url = array('action' => 'index',); if ($this->name === 'Crud') { $url['model'] = $this->Model->urlSlug; } $this->redirect(array_merge($named, $url)); }
php
public function proxy() { if (empty($this->Model) || empty($this->request->data[$this->Model->alias])) { $this->redirect($this->referer()); } $data = $this->request->data[$this->Model->alias]; $named = array(); foreach ($data as $key => $value) { if ( mb_substr($key, -7) === '_filter' || mb_substr($key, -11) === '_type_ahead' || $value === '') { continue; } $named[$key] = urlencode($value); if (isset($data[$key . '_filter'])) { $named[$key . '_filter'] = urlencode($data[$key . '_filter']); } if (isset($data[$key . '_type_ahead'])) { $named[$key . '_type_ahead'] = urlencode($data[$key . '_type_ahead']); } } $url = array('action' => 'index',); if ($this->name === 'Crud') { $url['model'] = $this->Model->urlSlug; } $this->redirect(array_merge($named, $url)); }
[ "public", "function", "proxy", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "Model", ")", "||", "empty", "(", "$", "this", "->", "request", "->", "data", "[", "$", "this", "->", "Model", "->", "alias", "]", ")", ")", "{", "$", "this", "->", "redirect", "(", "$", "this", "->", "referer", "(", ")", ")", ";", "}", "$", "data", "=", "$", "this", "->", "request", "->", "data", "[", "$", "this", "->", "Model", "->", "alias", "]", ";", "$", "named", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "mb_substr", "(", "$", "key", ",", "-", "7", ")", "===", "'_filter'", "||", "mb_substr", "(", "$", "key", ",", "-", "11", ")", "===", "'_type_ahead'", "||", "$", "value", "===", "''", ")", "{", "continue", ";", "}", "$", "named", "[", "$", "key", "]", "=", "urlencode", "(", "$", "value", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "$", "key", ".", "'_filter'", "]", ")", ")", "{", "$", "named", "[", "$", "key", ".", "'_filter'", "]", "=", "urlencode", "(", "$", "data", "[", "$", "key", ".", "'_filter'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "$", "key", ".", "'_type_ahead'", "]", ")", ")", "{", "$", "named", "[", "$", "key", ".", "'_type_ahead'", "]", "=", "urlencode", "(", "$", "data", "[", "$", "key", ".", "'_type_ahead'", "]", ")", ";", "}", "}", "$", "url", "=", "array", "(", "'action'", "=>", "'index'", ",", ")", ";", "if", "(", "$", "this", "->", "name", "===", "'Crud'", ")", "{", "$", "url", "[", "'model'", "]", "=", "$", "this", "->", "Model", "->", "urlSlug", ";", "}", "$", "this", "->", "redirect", "(", "array_merge", "(", "$", "named", ",", "$", "url", ")", ")", ";", "}" ]
Proxy action to handle POST requests and redirect back with named params.
[ "Proxy", "action", "to", "handle", "POST", "requests", "and", "redirect", "back", "with", "named", "params", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/AdminAppController.php#L120-L154
230,488
everplays/agavi-form-models-set
src/Elements/RadioGroupModel.class.php
Form_Elements_RadioGroupModel.setValue
public function setValue($value) { $value = (int) $value; $value = parent::setValue($value); return $value; }
php
public function setValue($value) { $value = (int) $value; $value = parent::setValue($value); return $value; }
[ "public", "function", "setValue", "(", "$", "value", ")", "{", "$", "value", "=", "(", "int", ")", "$", "value", ";", "$", "value", "=", "parent", "::", "setValue", "(", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
prepares value before checking regular validation check @param mixed $value @return mixed
[ "prepares", "value", "before", "checking", "regular", "validation", "check" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/RadioGroupModel.class.php#L104-L109
230,489
everplays/agavi-form-models-set
src/Elements/ConditionModel.class.php
Form_Elements_ConditionModel.setValue
public function setValue($value) { $failure = true; switch($this->opration) { case '==': if($value==$this->condition) $failure = false; break; case '>': if($value>$this->condition) $failure = false; break; case '>=': if($value>=$this->condition) $faulure = false; break; case '<': if($value<$this->condition) $failure = false; break; case '<=': if($value<=$this->condition) $failure = false; break; case '*': if(strpos($value, $this->condition)!==false) $failure = false; break; case '^': if(strpos($value, $this->condition)===0) $failure = false; break; case '$': if(strrpos($value, $this->condition)==strlen($value)-strlen($this->condition)) $failure = false; break; default: break; } if($failure) throw $this->getContext()->getModel('ValidationException', 'Form', array( array( '' => 'condition failed' ) )); return $value; }
php
public function setValue($value) { $failure = true; switch($this->opration) { case '==': if($value==$this->condition) $failure = false; break; case '>': if($value>$this->condition) $failure = false; break; case '>=': if($value>=$this->condition) $faulure = false; break; case '<': if($value<$this->condition) $failure = false; break; case '<=': if($value<=$this->condition) $failure = false; break; case '*': if(strpos($value, $this->condition)!==false) $failure = false; break; case '^': if(strpos($value, $this->condition)===0) $failure = false; break; case '$': if(strrpos($value, $this->condition)==strlen($value)-strlen($this->condition)) $failure = false; break; default: break; } if($failure) throw $this->getContext()->getModel('ValidationException', 'Form', array( array( '' => 'condition failed' ) )); return $value; }
[ "public", "function", "setValue", "(", "$", "value", ")", "{", "$", "failure", "=", "true", ";", "switch", "(", "$", "this", "->", "opration", ")", "{", "case", "'=='", ":", "if", "(", "$", "value", "==", "$", "this", "->", "condition", ")", "$", "failure", "=", "false", ";", "break", ";", "case", "'>'", ":", "if", "(", "$", "value", ">", "$", "this", "->", "condition", ")", "$", "failure", "=", "false", ";", "break", ";", "case", "'>='", ":", "if", "(", "$", "value", ">=", "$", "this", "->", "condition", ")", "$", "faulure", "=", "false", ";", "break", ";", "case", "'<'", ":", "if", "(", "$", "value", "<", "$", "this", "->", "condition", ")", "$", "failure", "=", "false", ";", "break", ";", "case", "'<='", ":", "if", "(", "$", "value", "<=", "$", "this", "->", "condition", ")", "$", "failure", "=", "false", ";", "break", ";", "case", "'*'", ":", "if", "(", "strpos", "(", "$", "value", ",", "$", "this", "->", "condition", ")", "!==", "false", ")", "$", "failure", "=", "false", ";", "break", ";", "case", "'^'", ":", "if", "(", "strpos", "(", "$", "value", ",", "$", "this", "->", "condition", ")", "===", "0", ")", "$", "failure", "=", "false", ";", "break", ";", "case", "'$'", ":", "if", "(", "strrpos", "(", "$", "value", ",", "$", "this", "->", "condition", ")", "==", "strlen", "(", "$", "value", ")", "-", "strlen", "(", "$", "this", "->", "condition", ")", ")", "$", "failure", "=", "false", ";", "break", ";", "default", ":", "break", ";", "}", "if", "(", "$", "failure", ")", "throw", "$", "this", "->", "getContext", "(", ")", "->", "getModel", "(", "'ValidationException'", ",", "'Form'", ",", "array", "(", "array", "(", "''", "=>", "'condition failed'", ")", ")", ")", ";", "return", "$", "value", ";", "}" ]
checks given value can pass the conditions or not @param mixed $value @throws Form_ValidationExceptionModel if condition check fails @return mixed
[ "checks", "given", "value", "can", "pass", "the", "conditions", "or", "not" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/ConditionModel.class.php#L24-L71
230,490
everplays/agavi-form-models-set
src/Elements/CheckboxModel.class.php
Form_Elements_CheckboxModel.registerValidators
public function registerValidators(AgaviValidationManager $vm, array $depends, array $parameters=array()) { $this->value = isset($parameters[$this->name]); $vm->createValidator( 'AgaviIssetValidator', array($this->name), array('' => 'field is required'), array( 'translation_domain' => AgaviConfig::get('Form.TranslationDomain'), 'required' => (bool) $this->required, 'depends' => $depends ) ); }
php
public function registerValidators(AgaviValidationManager $vm, array $depends, array $parameters=array()) { $this->value = isset($parameters[$this->name]); $vm->createValidator( 'AgaviIssetValidator', array($this->name), array('' => 'field is required'), array( 'translation_domain' => AgaviConfig::get('Form.TranslationDomain'), 'required' => (bool) $this->required, 'depends' => $depends ) ); }
[ "public", "function", "registerValidators", "(", "AgaviValidationManager", "$", "vm", ",", "array", "$", "depends", ",", "array", "$", "parameters", "=", "array", "(", ")", ")", "{", "$", "this", "->", "value", "=", "isset", "(", "$", "parameters", "[", "$", "this", "->", "name", "]", ")", ";", "$", "vm", "->", "createValidator", "(", "'AgaviIssetValidator'", ",", "array", "(", "$", "this", "->", "name", ")", ",", "array", "(", "''", "=>", "'field is required'", ")", ",", "array", "(", "'translation_domain'", "=>", "AgaviConfig", "::", "get", "(", "'Form.TranslationDomain'", ")", ",", "'required'", "=>", "(", "bool", ")", "$", "this", "->", "required", ",", "'depends'", "=>", "$", "depends", ")", ")", ";", "}" ]
registers validators for element @param AgaviValidationManager $vm instance of AgaviValidationManager to register validators on it @param array $depends depends parameter of validations that get registered @param array $parameters
[ "registers", "validators", "for", "element" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/CheckboxModel.class.php#L103-L116
230,491
everplays/agavi-form-models-set
src/FormModel.class.php
Form_FormModel.html
public function html($client=null) { $this->setRendered(true); // children level 2 or deeper will be at the end of list so // when their parent get rendered they will be rendered too foreach($this->children as $child) { $child->setRendered(false); } $result = "<form id=\"".self::idPrefix."-{$this->id}\" enctype=\"multipart/form-data\" "; if(isset($this->action)) $result .= "action=\"".$this->action."\" "; $method = 'post'; if(isset($this->method)) $method = strtolower($this->method); $result .= "method=\"{$method}\" "; $result .= ">"; foreach($this->children as $child) { if(!$child->isRendered()) { $result .= $child->html($client); } } if(isset($this->submit)) $result .= "<input type=\"submit\" value=\"{$this->submit}\" class=\"btn primary\" />"; $result .="</form>"; if(isset($this->description) || isset($this->title)) { $result = "<div class=\"row\"><div class=\"span4\">". (isset($this->title)?"<h2>{$this->title}</h2>":''). (isset($this->description)?"<p>{$this->description}</p>":''). "</div><div class=\"span12\">". $result."</div></div>"; } if(!is_null($client) and is_callable(array($this, $client))) { $result = $this->{$client}($result); } return $result; }
php
public function html($client=null) { $this->setRendered(true); // children level 2 or deeper will be at the end of list so // when their parent get rendered they will be rendered too foreach($this->children as $child) { $child->setRendered(false); } $result = "<form id=\"".self::idPrefix."-{$this->id}\" enctype=\"multipart/form-data\" "; if(isset($this->action)) $result .= "action=\"".$this->action."\" "; $method = 'post'; if(isset($this->method)) $method = strtolower($this->method); $result .= "method=\"{$method}\" "; $result .= ">"; foreach($this->children as $child) { if(!$child->isRendered()) { $result .= $child->html($client); } } if(isset($this->submit)) $result .= "<input type=\"submit\" value=\"{$this->submit}\" class=\"btn primary\" />"; $result .="</form>"; if(isset($this->description) || isset($this->title)) { $result = "<div class=\"row\"><div class=\"span4\">". (isset($this->title)?"<h2>{$this->title}</h2>":''). (isset($this->description)?"<p>{$this->description}</p>":''). "</div><div class=\"span12\">". $result."</div></div>"; } if(!is_null($client) and is_callable(array($this, $client))) { $result = $this->{$client}($result); } return $result; }
[ "public", "function", "html", "(", "$", "client", "=", "null", ")", "{", "$", "this", "->", "setRendered", "(", "true", ")", ";", "// children level 2 or deeper will be at the end of list so", "// when their parent get rendered they will be rendered too", "foreach", "(", "$", "this", "->", "children", "as", "$", "child", ")", "{", "$", "child", "->", "setRendered", "(", "false", ")", ";", "}", "$", "result", "=", "\"<form id=\\\"\"", ".", "self", "::", "idPrefix", ".", "\"-{$this->id}\\\" enctype=\\\"multipart/form-data\\\" \"", ";", "if", "(", "isset", "(", "$", "this", "->", "action", ")", ")", "$", "result", ".=", "\"action=\\\"\"", ".", "$", "this", "->", "action", ".", "\"\\\" \"", ";", "$", "method", "=", "'post'", ";", "if", "(", "isset", "(", "$", "this", "->", "method", ")", ")", "$", "method", "=", "strtolower", "(", "$", "this", "->", "method", ")", ";", "$", "result", ".=", "\"method=\\\"{$method}\\\" \"", ";", "$", "result", ".=", "\">\"", ";", "foreach", "(", "$", "this", "->", "children", "as", "$", "child", ")", "{", "if", "(", "!", "$", "child", "->", "isRendered", "(", ")", ")", "{", "$", "result", ".=", "$", "child", "->", "html", "(", "$", "client", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "submit", ")", ")", "$", "result", ".=", "\"<input type=\\\"submit\\\" value=\\\"{$this->submit}\\\" class=\\\"btn primary\\\" />\"", ";", "$", "result", ".=", "\"</form>\"", ";", "if", "(", "isset", "(", "$", "this", "->", "description", ")", "||", "isset", "(", "$", "this", "->", "title", ")", ")", "{", "$", "result", "=", "\"<div class=\\\"row\\\"><div class=\\\"span4\\\">\"", ".", "(", "isset", "(", "$", "this", "->", "title", ")", "?", "\"<h2>{$this->title}</h2>\"", ":", "''", ")", ".", "(", "isset", "(", "$", "this", "->", "description", ")", "?", "\"<p>{$this->description}</p>\"", ":", "''", ")", ".", "\"</div><div class=\\\"span12\\\">\"", ".", "$", "result", ".", "\"</div></div>\"", ";", "}", "if", "(", "!", "is_null", "(", "$", "client", ")", "and", "is_callable", "(", "array", "(", "$", "this", ",", "$", "client", ")", ")", ")", "{", "$", "result", "=", "$", "this", "->", "{", "$", "client", "}", "(", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
generates html of form @return string generated html for element @param string $client javascript client library - for validation purpose
[ "generates", "html", "of", "form" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/FormModel.class.php#L31-L71
230,492
everplays/agavi-form-models-set
src/FormModel.class.php
Form_FormModel.fromJson
public static function fromJson($config, Form_Elements_FieldsetModel $form=null) { $contextProfile = AgaviConfig::get('core.default_context'); if(is_null($contextProfile)) { $contextProfile = md5(microtime()); AgaviConfig::set('core.default_context', $contextProfile); } $context = AgaviContext::getInstance(); $_form = $context->getModel('Form', 'Form', array($config, $form)); self::parseChildren($config, $_form); return $_form; }
php
public static function fromJson($config, Form_Elements_FieldsetModel $form=null) { $contextProfile = AgaviConfig::get('core.default_context'); if(is_null($contextProfile)) { $contextProfile = md5(microtime()); AgaviConfig::set('core.default_context', $contextProfile); } $context = AgaviContext::getInstance(); $_form = $context->getModel('Form', 'Form', array($config, $form)); self::parseChildren($config, $_form); return $_form; }
[ "public", "static", "function", "fromJson", "(", "$", "config", ",", "Form_Elements_FieldsetModel", "$", "form", "=", "null", ")", "{", "$", "contextProfile", "=", "AgaviConfig", "::", "get", "(", "'core.default_context'", ")", ";", "if", "(", "is_null", "(", "$", "contextProfile", ")", ")", "{", "$", "contextProfile", "=", "md5", "(", "microtime", "(", ")", ")", ";", "AgaviConfig", "::", "set", "(", "'core.default_context'", ",", "$", "contextProfile", ")", ";", "}", "$", "context", "=", "AgaviContext", "::", "getInstance", "(", ")", ";", "$", "_form", "=", "$", "context", "->", "getModel", "(", "'Form'", ",", "'Form'", ",", "array", "(", "$", "config", ",", "$", "form", ")", ")", ";", "self", "::", "parseChildren", "(", "$", "config", ",", "$", "_form", ")", ";", "return", "$", "_form", ";", "}" ]
parses config object should be used to make Form_FormModel object from a config (configuration is inspired by extjs lazy config) @param object $config lazy configuration @param Form_FormModel $form @return Form_FormModel
[ "parses", "config", "object" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/FormModel.class.php#L114-L126
230,493
everplays/agavi-form-models-set
src/Elements/FileFieldModel.class.php
Form_Elements_FileFieldModel.registerValidators
public function registerValidators(AgaviValidationManager $vm, array $depends, array $parameters=array(), array $files=array()) { if(isset($files[$this->name])) { if($files[$this->name] instanceof AgaviUploadedFile and !$files[$this->name]->hasError()) { $errors = $this->getValidationErrors($files[$this->name]); if(empty($errors)) { $this->value = $files[$this->name]; } } } $vm->createValidator( 'AgaviFileValidator', array($this->name), array( '' => 'field is required', 'mime_type' => 'format of uploaded file is not acceptable' ), array( // parameters 'name' => $this->name, 'mime_type' => empty($this->types)?'/.*/':'#^'.implode('$|^', $this->types).'$#', 'translation_domain' => AgaviConfig::get('Form.TranslationDomain'), 'required' => (bool) $this->required ) ); }
php
public function registerValidators(AgaviValidationManager $vm, array $depends, array $parameters=array(), array $files=array()) { if(isset($files[$this->name])) { if($files[$this->name] instanceof AgaviUploadedFile and !$files[$this->name]->hasError()) { $errors = $this->getValidationErrors($files[$this->name]); if(empty($errors)) { $this->value = $files[$this->name]; } } } $vm->createValidator( 'AgaviFileValidator', array($this->name), array( '' => 'field is required', 'mime_type' => 'format of uploaded file is not acceptable' ), array( // parameters 'name' => $this->name, 'mime_type' => empty($this->types)?'/.*/':'#^'.implode('$|^', $this->types).'$#', 'translation_domain' => AgaviConfig::get('Form.TranslationDomain'), 'required' => (bool) $this->required ) ); }
[ "public", "function", "registerValidators", "(", "AgaviValidationManager", "$", "vm", ",", "array", "$", "depends", ",", "array", "$", "parameters", "=", "array", "(", ")", ",", "array", "$", "files", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "files", "[", "$", "this", "->", "name", "]", ")", ")", "{", "if", "(", "$", "files", "[", "$", "this", "->", "name", "]", "instanceof", "AgaviUploadedFile", "and", "!", "$", "files", "[", "$", "this", "->", "name", "]", "->", "hasError", "(", ")", ")", "{", "$", "errors", "=", "$", "this", "->", "getValidationErrors", "(", "$", "files", "[", "$", "this", "->", "name", "]", ")", ";", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "$", "this", "->", "value", "=", "$", "files", "[", "$", "this", "->", "name", "]", ";", "}", "}", "}", "$", "vm", "->", "createValidator", "(", "'AgaviFileValidator'", ",", "array", "(", "$", "this", "->", "name", ")", ",", "array", "(", "''", "=>", "'field is required'", ",", "'mime_type'", "=>", "'format of uploaded file is not acceptable'", ")", ",", "array", "(", "// parameters", "'name'", "=>", "$", "this", "->", "name", ",", "'mime_type'", "=>", "empty", "(", "$", "this", "->", "types", ")", "?", "'/.*/'", ":", "'#^'", ".", "implode", "(", "'$|^'", ",", "$", "this", "->", "types", ")", ".", "'$#'", ",", "'translation_domain'", "=>", "AgaviConfig", "::", "get", "(", "'Form.TranslationDomain'", ")", ",", "'required'", "=>", "(", "bool", ")", "$", "this", "->", "required", ")", ")", ";", "}" ]
register special validators of this element on validation manager @param AgaviValidationManager $vm instance of AgaviValidationManager to register validators on it @param array $depends depends parameter of validations that get registered @param array $parameters @param array $files array of AgaviUploadedFile
[ "register", "special", "validators", "of", "this", "element", "on", "validation", "manager" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FileFieldModel.class.php#L110-L137
230,494
everplays/agavi-form-models-set
src/Elements/FieldsetModel.class.php
Form_Elements_FieldsetModel.addChild
public function addChild(Form_ElementModel $Child) { $cp = (array) $Child->parents; // child parents $fp = (array) $this->parents; // fieldset parents foreach($fp as $parent => $condition) $cp[$parent] = $condition; $Child->parents = $cp; $index = count($this->children); $this->children[] = $Child; if(isset($Child->id)) $this->id2index[$Child->id] = $index; if(isset($Child->name)) $this->name2index[$Child->name] = $index; }
php
public function addChild(Form_ElementModel $Child) { $cp = (array) $Child->parents; // child parents $fp = (array) $this->parents; // fieldset parents foreach($fp as $parent => $condition) $cp[$parent] = $condition; $Child->parents = $cp; $index = count($this->children); $this->children[] = $Child; if(isset($Child->id)) $this->id2index[$Child->id] = $index; if(isset($Child->name)) $this->name2index[$Child->name] = $index; }
[ "public", "function", "addChild", "(", "Form_ElementModel", "$", "Child", ")", "{", "$", "cp", "=", "(", "array", ")", "$", "Child", "->", "parents", ";", "// child parents", "$", "fp", "=", "(", "array", ")", "$", "this", "->", "parents", ";", "// fieldset parents", "foreach", "(", "$", "fp", "as", "$", "parent", "=>", "$", "condition", ")", "$", "cp", "[", "$", "parent", "]", "=", "$", "condition", ";", "$", "Child", "->", "parents", "=", "$", "cp", ";", "$", "index", "=", "count", "(", "$", "this", "->", "children", ")", ";", "$", "this", "->", "children", "[", "]", "=", "$", "Child", ";", "if", "(", "isset", "(", "$", "Child", "->", "id", ")", ")", "$", "this", "->", "id2index", "[", "$", "Child", "->", "id", "]", "=", "$", "index", ";", "if", "(", "isset", "(", "$", "Child", "->", "name", ")", ")", "$", "this", "->", "name2index", "[", "$", "Child", "->", "name", "]", "=", "$", "index", ";", "}" ]
adds Child to container @param Form_ElementModel $Child child to be added
[ "adds", "Child", "to", "container" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FieldsetModel.class.php#L33-L46
230,495
everplays/agavi-form-models-set
src/Elements/FieldsetModel.class.php
Form_Elements_FieldsetModel.getChildById
public function getChildById($id) { if(isset($this->id2index[$id])) return $this->children[$this->id2index[$id]]; return null; }
php
public function getChildById($id) { if(isset($this->id2index[$id])) return $this->children[$this->id2index[$id]]; return null; }
[ "public", "function", "getChildById", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "id2index", "[", "$", "id", "]", ")", ")", "return", "$", "this", "->", "children", "[", "$", "this", "->", "id2index", "[", "$", "id", "]", "]", ";", "return", "null", ";", "}" ]
returns Child by given id @param int $id id of Child @return Form_ElementModel Child or null
[ "returns", "Child", "by", "given", "id" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FieldsetModel.class.php#L54-L59
230,496
everplays/agavi-form-models-set
src/Elements/FieldsetModel.class.php
Form_Elements_FieldsetModel.getChildByName
public function getChildByName($name) { if(isset($this->name2index[$name])) return $this->children[$this->name2index[$name]]; return null; }
php
public function getChildByName($name) { if(isset($this->name2index[$name])) return $this->children[$this->name2index[$name]]; return null; }
[ "public", "function", "getChildByName", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "name2index", "[", "$", "name", "]", ")", ")", "return", "$", "this", "->", "children", "[", "$", "this", "->", "name2index", "[", "$", "name", "]", "]", ";", "return", "null", ";", "}" ]
returns Child by given name @param string $name name of Child @return Form_ElementModel Child or null
[ "returns", "Child", "by", "given", "name" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FieldsetModel.class.php#L67-L72
230,497
everplays/agavi-form-models-set
src/Elements/FieldsetModel.class.php
Form_Elements_FieldsetModel.removeChildById
public function removeChildById($id) { if(isset($this->id2index[$id])) { $tmp = $this->children[$this->id2index[$id]]; if(isset($tmp->name)) unset($this->name2index[$tmp->name]); unset($this->children[$this->id2index[$id]], $this->id2index[$id]); return $tmp; } return null; }
php
public function removeChildById($id) { if(isset($this->id2index[$id])) { $tmp = $this->children[$this->id2index[$id]]; if(isset($tmp->name)) unset($this->name2index[$tmp->name]); unset($this->children[$this->id2index[$id]], $this->id2index[$id]); return $tmp; } return null; }
[ "public", "function", "removeChildById", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "id2index", "[", "$", "id", "]", ")", ")", "{", "$", "tmp", "=", "$", "this", "->", "children", "[", "$", "this", "->", "id2index", "[", "$", "id", "]", "]", ";", "if", "(", "isset", "(", "$", "tmp", "->", "name", ")", ")", "unset", "(", "$", "this", "->", "name2index", "[", "$", "tmp", "->", "name", "]", ")", ";", "unset", "(", "$", "this", "->", "children", "[", "$", "this", "->", "id2index", "[", "$", "id", "]", "]", ",", "$", "this", "->", "id2index", "[", "$", "id", "]", ")", ";", "return", "$", "tmp", ";", "}", "return", "null", ";", "}" ]
removes an Child by id @param int $id id of Child @return Form_ElementModel removed Child or null
[ "removes", "an", "Child", "by", "id" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FieldsetModel.class.php#L90-L101
230,498
everplays/agavi-form-models-set
src/Elements/FieldsetModel.class.php
Form_Elements_FieldsetModel.removeChildByName
public function removeChildByName($name) { if(isset($this->name2index[$name])) { $tmp = $this->children[$this->name2index[$name]]; if(isset($tmp->id)) unset($this->id2index[$tmp->id]); unset($this->children[$this->name2index[$name]], $this->name2index[$name]); return $tmp; } return null; }
php
public function removeChildByName($name) { if(isset($this->name2index[$name])) { $tmp = $this->children[$this->name2index[$name]]; if(isset($tmp->id)) unset($this->id2index[$tmp->id]); unset($this->children[$this->name2index[$name]], $this->name2index[$name]); return $tmp; } return null; }
[ "public", "function", "removeChildByName", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "name2index", "[", "$", "name", "]", ")", ")", "{", "$", "tmp", "=", "$", "this", "->", "children", "[", "$", "this", "->", "name2index", "[", "$", "name", "]", "]", ";", "if", "(", "isset", "(", "$", "tmp", "->", "id", ")", ")", "unset", "(", "$", "this", "->", "id2index", "[", "$", "tmp", "->", "id", "]", ")", ";", "unset", "(", "$", "this", "->", "children", "[", "$", "this", "->", "name2index", "[", "$", "name", "]", "]", ",", "$", "this", "->", "name2index", "[", "$", "name", "]", ")", ";", "return", "$", "tmp", ";", "}", "return", "null", ";", "}" ]
removes an Child by name @param string $name name of Child @return Form_ElementModel removed Child or null
[ "removes", "an", "Child", "by", "name" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FieldsetModel.class.php#L109-L120
230,499
everplays/agavi-form-models-set
src/Elements/FieldsetModel.class.php
Form_Elements_FieldsetModel.removeChild
public function removeChild($Child) { $index = array_search($Child, $this->children); if($index!==false) { $tmp = $this->children[$index]; if(isset($tmp->id)) unset($this->id2index[$tmp->id]); if(isset($tmp->name)) unset($this->name2index[$tmp->name]); unset($this->children[$index]); return $tmp; } return null; }
php
public function removeChild($Child) { $index = array_search($Child, $this->children); if($index!==false) { $tmp = $this->children[$index]; if(isset($tmp->id)) unset($this->id2index[$tmp->id]); if(isset($tmp->name)) unset($this->name2index[$tmp->name]); unset($this->children[$index]); return $tmp; } return null; }
[ "public", "function", "removeChild", "(", "$", "Child", ")", "{", "$", "index", "=", "array_search", "(", "$", "Child", ",", "$", "this", "->", "children", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "$", "tmp", "=", "$", "this", "->", "children", "[", "$", "index", "]", ";", "if", "(", "isset", "(", "$", "tmp", "->", "id", ")", ")", "unset", "(", "$", "this", "->", "id2index", "[", "$", "tmp", "->", "id", "]", ")", ";", "if", "(", "isset", "(", "$", "tmp", "->", "name", ")", ")", "unset", "(", "$", "this", "->", "name2index", "[", "$", "tmp", "->", "name", "]", ")", ";", "unset", "(", "$", "this", "->", "children", "[", "$", "index", "]", ")", ";", "return", "$", "tmp", ";", "}", "return", "null", ";", "}" ]
removes an Child @param Form_ElementModel $Child Child to get removed @return Form_ElementModel removed Child or null
[ "removes", "an", "Child" ]
84b76f5facc6cea686ed2872eb6f4bd499f72d0e
https://github.com/everplays/agavi-form-models-set/blob/84b76f5facc6cea686ed2872eb6f4bd499f72d0e/src/Elements/FieldsetModel.class.php#L128-L142