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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
JDGrimes/wp-filesystem-mock
src/wp-mock-filesystem.php
WP_Mock_Filesystem.get_file_attr
public function get_file_attr( $file, $attr, $type = null ) { $file_atts = $this->get_file( $file ); if ( false === $file_atts || false === isset( $file_atts->$attr ) ) { return false; } if ( isset( $type ) && $type !== $file_atts->type ) { return false; } return $file_atts->$attr; }
php
public function get_file_attr( $file, $attr, $type = null ) { $file_atts = $this->get_file( $file ); if ( false === $file_atts || false === isset( $file_atts->$attr ) ) { return false; } if ( isset( $type ) && $type !== $file_atts->type ) { return false; } return $file_atts->$attr; }
[ "public", "function", "get_file_attr", "(", "$", "file", ",", "$", "attr", ",", "$", "type", "=", "null", ")", "{", "$", "file_atts", "=", "$", "this", "->", "get_file", "(", "$", "file", ")", ";", "if", "(", "false", "===", "$", "file_atts", "||", "false", "===", "isset", "(", "$", "file_atts", "->", "$", "attr", ")", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "type", ")", "&&", "$", "type", "!==", "$", "file_atts", "->", "type", ")", "{", "return", "false", ";", "}", "return", "$", "file_atts", "->", "$", "attr", ";", "}" ]
Get a piece of information about a file. @since 0.1.0 @param string $file The path to the file/directory. @param string $attr The file attribute to get. @param string $type The type of file this is expected to be. @return mixed The value of this attribute, or false on failure.
[ "Get", "a", "piece", "of", "information", "about", "a", "file", "." ]
986df3bfeb1554ae19856537dfeb558037275c25
https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L246-L259
train
JDGrimes/wp-filesystem-mock
src/wp-mock-filesystem.php
WP_Mock_Filesystem.set_file_attr
public function set_file_attr( $file, $attr, $value, $recursive = false ) { $file_atts = $this->get_file( $file ); if ( false === $file_atts ) { return false; } if ( 'contents' === $attr ) { if ( 'file' === $file_atts->type ) { $file_atts->size = mb_strlen( $value, '8bit' ); } else { return false; } } if ( true === $recursive ) { $this->set_file_attr_recursive( $file_atts, $attr, $value ); } $file_atts->$attr = $value; return true; }
php
public function set_file_attr( $file, $attr, $value, $recursive = false ) { $file_atts = $this->get_file( $file ); if ( false === $file_atts ) { return false; } if ( 'contents' === $attr ) { if ( 'file' === $file_atts->type ) { $file_atts->size = mb_strlen( $value, '8bit' ); } else { return false; } } if ( true === $recursive ) { $this->set_file_attr_recursive( $file_atts, $attr, $value ); } $file_atts->$attr = $value; return true; }
[ "public", "function", "set_file_attr", "(", "$", "file", ",", "$", "attr", ",", "$", "value", ",", "$", "recursive", "=", "false", ")", "{", "$", "file_atts", "=", "$", "this", "->", "get_file", "(", "$", "file", ")", ";", "if", "(", "false", "===", "$", "file_atts", ")", "{", "return", "false", ";", "}", "if", "(", "'contents'", "===", "$", "attr", ")", "{", "if", "(", "'file'", "===", "$", "file_atts", "->", "type", ")", "{", "$", "file_atts", "->", "size", "=", "mb_strlen", "(", "$", "value", ",", "'8bit'", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "if", "(", "true", "===", "$", "recursive", ")", "{", "$", "this", "->", "set_file_attr_recursive", "(", "$", "file_atts", ",", "$", "attr", ",", "$", "value", ")", ";", "}", "$", "file_atts", "->", "$", "attr", "=", "$", "value", ";", "return", "true", ";", "}" ]
Set the value of file attribute. @since 0.1.0 @param string $file The path of the file/directory. @param string $attr The attribute to set. @param mixed $value The new value for this attribute. @param bool $recursive Whether to set the value recursively. @return bool True if the attribute value was set, false otherwise.
[ "Set", "the", "value", "of", "file", "attribute", "." ]
986df3bfeb1554ae19856537dfeb558037275c25
https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L273-L296
train
JDGrimes/wp-filesystem-mock
src/wp-mock-filesystem.php
WP_Mock_Filesystem.set_file_attr_recursive
protected function set_file_attr_recursive( $file, $attr, $value ) { if ( 'dir' === $file->type ) { foreach ( $file->contents as $sub => $atts ) { $this->set_file_attr_recursive( $atts, $attr, $value ); } } $file->$attr = $value; }
php
protected function set_file_attr_recursive( $file, $attr, $value ) { if ( 'dir' === $file->type ) { foreach ( $file->contents as $sub => $atts ) { $this->set_file_attr_recursive( $atts, $attr, $value ); } } $file->$attr = $value; }
[ "protected", "function", "set_file_attr_recursive", "(", "$", "file", ",", "$", "attr", ",", "$", "value", ")", "{", "if", "(", "'dir'", "===", "$", "file", "->", "type", ")", "{", "foreach", "(", "$", "file", "->", "contents", "as", "$", "sub", "=>", "$", "atts", ")", "{", "$", "this", "->", "set_file_attr_recursive", "(", "$", "atts", ",", "$", "attr", ",", "$", "value", ")", ";", "}", "}", "$", "file", "->", "$", "attr", "=", "$", "value", ";", "}" ]
Set the value of file attribute recursively. @since 0.1.0 @param object $file The file data. @param string $attr The attribute to set. @param mixed $value The new value for this attribute. @return bool True if the attribute value was set, false otherwise.
[ "Set", "the", "value", "of", "file", "attribute", "recursively", "." ]
986df3bfeb1554ae19856537dfeb558037275c25
https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L309-L319
train
JDGrimes/wp-filesystem-mock
src/wp-mock-filesystem.php
WP_Mock_Filesystem.set_cwd
public function set_cwd( $cwd ) { $file = $this->get_file( $cwd ); if ( false === $file || 'dir' !== $file->type ) { return false; } $this->cwd = $this->normalize_path( $cwd ); if ( empty( $this->cwd ) ) { $this->cwd = '/'; } return true; }
php
public function set_cwd( $cwd ) { $file = $this->get_file( $cwd ); if ( false === $file || 'dir' !== $file->type ) { return false; } $this->cwd = $this->normalize_path( $cwd ); if ( empty( $this->cwd ) ) { $this->cwd = '/'; } return true; }
[ "public", "function", "set_cwd", "(", "$", "cwd", ")", "{", "$", "file", "=", "$", "this", "->", "get_file", "(", "$", "cwd", ")", ";", "if", "(", "false", "===", "$", "file", "||", "'dir'", "!==", "$", "file", "->", "type", ")", "{", "return", "false", ";", "}", "$", "this", "->", "cwd", "=", "$", "this", "->", "normalize_path", "(", "$", "cwd", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "cwd", ")", ")", "{", "$", "this", "->", "cwd", "=", "'/'", ";", "}", "return", "true", ";", "}" ]
Set the current working directory. @since 0.1.0 @param string $cwd The path to the new working directory. @return bool True if the current working directory was set, false otherwise.
[ "Set", "the", "current", "working", "directory", "." ]
986df3bfeb1554ae19856537dfeb558037275c25
https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L341-L356
train
JDGrimes/wp-filesystem-mock
src/wp-mock-filesystem.php
WP_Mock_Filesystem.copy
public function copy( $source, $destination ) { $source = $this->get_file( $source ); if ( false === $source ) { return false; } $destination_parent = $this->get_file( dirname( $destination ) ); $filename = basename( $destination ); if ( false === $destination_parent ) { return false; } $destination_parent->contents->$filename = clone $source; return true; }
php
public function copy( $source, $destination ) { $source = $this->get_file( $source ); if ( false === $source ) { return false; } $destination_parent = $this->get_file( dirname( $destination ) ); $filename = basename( $destination ); if ( false === $destination_parent ) { return false; } $destination_parent->contents->$filename = clone $source; return true; }
[ "public", "function", "copy", "(", "$", "source", ",", "$", "destination", ")", "{", "$", "source", "=", "$", "this", "->", "get_file", "(", "$", "source", ")", ";", "if", "(", "false", "===", "$", "source", ")", "{", "return", "false", ";", "}", "$", "destination_parent", "=", "$", "this", "->", "get_file", "(", "dirname", "(", "$", "destination", ")", ")", ";", "$", "filename", "=", "basename", "(", "$", "destination", ")", ";", "if", "(", "false", "===", "$", "destination_parent", ")", "{", "return", "false", ";", "}", "$", "destination_parent", "->", "contents", "->", "$", "filename", "=", "clone", "$", "source", ";", "return", "true", ";", "}" ]
Copy a file or directory. The destination will be overwritten if it already exists. @since 0.1.0 @param string $source The source path. @param string $destination The destination path. @return bool True if the file was copied, false otherwise.
[ "Copy", "a", "file", "or", "directory", "." ]
986df3bfeb1554ae19856537dfeb558037275c25
https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L370-L388
train
JDGrimes/wp-filesystem-mock
src/wp-mock-filesystem.php
WP_Mock_Filesystem.move
public function move( $source, $destination ) { if ( false === $this->copy( $source, $destination ) ) { return false; } $this->delete( $source ); return true; }
php
public function move( $source, $destination ) { if ( false === $this->copy( $source, $destination ) ) { return false; } $this->delete( $source ); return true; }
[ "public", "function", "move", "(", "$", "source", ",", "$", "destination", ")", "{", "if", "(", "false", "===", "$", "this", "->", "copy", "(", "$", "source", ",", "$", "destination", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "delete", "(", "$", "source", ")", ";", "return", "true", ";", "}" ]
Move a file or directory. @since 0.1.0 @param string $source The source path. @param string $destination The destination path. @return bool True if the file was moved, false otherwise.
[ "Move", "a", "file", "or", "directory", "." ]
986df3bfeb1554ae19856537dfeb558037275c25
https://github.com/JDGrimes/wp-filesystem-mock/blob/986df3bfeb1554ae19856537dfeb558037275c25/src/wp-mock-filesystem.php#L400-L409
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.run
public function run() { $this->make('Sun\Bootstrap\Provider')->registerRoute(); $this->route->register(); $httpMethod = $this->make('Sun\Contracts\Http\Request')->method(); $uri = $this->make('Sun\Contracts\Routing\UrlGenerator')->getUri(); $data = $this->route->dispatch($httpMethod, $uri); $this->make('Sun\Bootstrap\Provider')->dispatch(); $this->make('Sun\Contracts\Http\Response')->html($data); }
php
public function run() { $this->make('Sun\Bootstrap\Provider')->registerRoute(); $this->route->register(); $httpMethod = $this->make('Sun\Contracts\Http\Request')->method(); $uri = $this->make('Sun\Contracts\Routing\UrlGenerator')->getUri(); $data = $this->route->dispatch($httpMethod, $uri); $this->make('Sun\Bootstrap\Provider')->dispatch(); $this->make('Sun\Contracts\Http\Response')->html($data); }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "make", "(", "'Sun\\Bootstrap\\Provider'", ")", "->", "registerRoute", "(", ")", ";", "$", "this", "->", "route", "->", "register", "(", ")", ";", "$", "httpMethod", "=", "$", "this", "->", "make", "(", "'Sun\\Contracts\\Http\\Request'", ")", "->", "method", "(", ")", ";", "$", "uri", "=", "$", "this", "->", "make", "(", "'Sun\\Contracts\\Routing\\UrlGenerator'", ")", "->", "getUri", "(", ")", ";", "$", "data", "=", "$", "this", "->", "route", "->", "dispatch", "(", "$", "httpMethod", ",", "$", "uri", ")", ";", "$", "this", "->", "make", "(", "'Sun\\Bootstrap\\Provider'", ")", "->", "dispatch", "(", ")", ";", "$", "this", "->", "make", "(", "'Sun\\Contracts\\Http\\Response'", ")", "->", "html", "(", "$", "data", ")", ";", "}" ]
To run application
[ "To", "run", "application" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L233-L248
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.base_path
public function base_path($path = null) { return empty($path) ? $this->path : $this->path . $path; }
php
public function base_path($path = null) { return empty($path) ? $this->path : $this->path . $path; }
[ "public", "function", "base_path", "(", "$", "path", "=", "null", ")", "{", "return", "empty", "(", "$", "path", ")", "?", "$", "this", "->", "path", ":", "$", "this", "->", "path", ".", "$", "path", ";", "}" ]
To get application base directory path @param null $path @return string
[ "To", "get", "application", "base", "directory", "path" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L257-L260
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.app_path
public function app_path($path = null) { return empty($path) ? $this->base_path() . DIRECTORY_SEPARATOR . 'app' : $this->base_path() . 'app' . $path; }
php
public function app_path($path = null) { return empty($path) ? $this->base_path() . DIRECTORY_SEPARATOR . 'app' : $this->base_path() . 'app' . $path; }
[ "public", "function", "app_path", "(", "$", "path", "=", "null", ")", "{", "return", "empty", "(", "$", "path", ")", "?", "$", "this", "->", "base_path", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "'app'", ":", "$", "this", "->", "base_path", "(", ")", ".", "'app'", ".", "$", "path", ";", "}" ]
To get application app directory path @param null $path @return string
[ "To", "get", "application", "app", "directory", "path" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L269-L272
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.loadAlien
public function loadAlien() { $alien = $this->config->getAlien(); foreach ($alien as $alias => $namespace) { class_alias($namespace, $alias); } }
php
public function loadAlien() { $alien = $this->config->getAlien(); foreach ($alien as $alias => $namespace) { class_alias($namespace, $alias); } }
[ "public", "function", "loadAlien", "(", ")", "{", "$", "alien", "=", "$", "this", "->", "config", "->", "getAlien", "(", ")", ";", "foreach", "(", "$", "alien", "as", "$", "alias", "=>", "$", "namespace", ")", "{", "class_alias", "(", "$", "namespace", ",", "$", "alias", ")", ";", "}", "}" ]
To load alien
[ "To", "load", "alien" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L347-L354
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.getNamespace
public function getNamespace() { if(!is_null($this->appNamespace)) { return $this->appNamespace; } $composer = json_decode(file_get_contents(base_path().'/composer.json')); foreach($composer->autoload->{"psr-4"} as $namespace => $path) { if(realpath(app_path()) === realpath(base_path(). '/' .$path)) { return $this->appNamespace = $namespace; } } throw new Exception("Namespace detect problem."); }
php
public function getNamespace() { if(!is_null($this->appNamespace)) { return $this->appNamespace; } $composer = json_decode(file_get_contents(base_path().'/composer.json')); foreach($composer->autoload->{"psr-4"} as $namespace => $path) { if(realpath(app_path()) === realpath(base_path(). '/' .$path)) { return $this->appNamespace = $namespace; } } throw new Exception("Namespace detect problem."); }
[ "public", "function", "getNamespace", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "appNamespace", ")", ")", "{", "return", "$", "this", "->", "appNamespace", ";", "}", "$", "composer", "=", "json_decode", "(", "file_get_contents", "(", "base_path", "(", ")", ".", "'/composer.json'", ")", ")", ";", "foreach", "(", "$", "composer", "->", "autoload", "->", "{", "\"psr-4\"", "}", "as", "$", "namespace", "=>", "$", "path", ")", "{", "if", "(", "realpath", "(", "app_path", "(", ")", ")", "===", "realpath", "(", "base_path", "(", ")", ".", "'/'", ".", "$", "path", ")", ")", "{", "return", "$", "this", "->", "appNamespace", "=", "$", "namespace", ";", "}", "}", "throw", "new", "Exception", "(", "\"Namespace detect problem.\"", ")", ";", "}" ]
To get application namespace @return string @throws Exception
[ "To", "get", "application", "namespace" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L400-L415
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.bootstrap
protected function bootstrap() { $this->make('Sun\Bootstrap\Application')->bootstrap(); $this->make('Sun\Bootstrap\HandleExceptions')->bootstrap(); $this->make('Sun\Bootstrap\Route')->bootstrap(); $this->make('Sun\Bootstrap\Provider')->bootstrap(); $this->route = $this->make('Sun\Contracts\Routing\Route'); }
php
protected function bootstrap() { $this->make('Sun\Bootstrap\Application')->bootstrap(); $this->make('Sun\Bootstrap\HandleExceptions')->bootstrap(); $this->make('Sun\Bootstrap\Route')->bootstrap(); $this->make('Sun\Bootstrap\Provider')->bootstrap(); $this->route = $this->make('Sun\Contracts\Routing\Route'); }
[ "protected", "function", "bootstrap", "(", ")", "{", "$", "this", "->", "make", "(", "'Sun\\Bootstrap\\Application'", ")", "->", "bootstrap", "(", ")", ";", "$", "this", "->", "make", "(", "'Sun\\Bootstrap\\HandleExceptions'", ")", "->", "bootstrap", "(", ")", ";", "$", "this", "->", "make", "(", "'Sun\\Bootstrap\\Route'", ")", "->", "bootstrap", "(", ")", ";", "$", "this", "->", "make", "(", "'Sun\\Bootstrap\\Provider'", ")", "->", "bootstrap", "(", ")", ";", "$", "this", "->", "route", "=", "$", "this", "->", "make", "(", "'Sun\\Contracts\\Routing\\Route'", ")", ";", "}" ]
Bootstrap application required class
[ "Bootstrap", "application", "required", "class" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L434-L445
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.registerBindings
protected function registerBindings() { $binding = config('binding')?: []; foreach($binding as $contract => $implementation) { $this->bind($contract, $implementation); } }
php
protected function registerBindings() { $binding = config('binding')?: []; foreach($binding as $contract => $implementation) { $this->bind($contract, $implementation); } }
[ "protected", "function", "registerBindings", "(", ")", "{", "$", "binding", "=", "config", "(", "'binding'", ")", "?", ":", "[", "]", ";", "foreach", "(", "$", "binding", "as", "$", "contract", "=>", "$", "implementation", ")", "{", "$", "this", "->", "bind", "(", "$", "contract", ",", "$", "implementation", ")", ";", "}", "}" ]
To register all bindings
[ "To", "register", "all", "bindings" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L450-L457
train
IftekherSunny/Planet-Framework
src/Sun/Application.php
Application.config
public function config($location) { $keys = explode('.', $location); $filename = 'get' . strtoupper(array_shift($keys)); $location = implode('.', $keys); if(empty($location)) { return $this->config->{$filename}(); } return $this->config->{$filename}($location); }
php
public function config($location) { $keys = explode('.', $location); $filename = 'get' . strtoupper(array_shift($keys)); $location = implode('.', $keys); if(empty($location)) { return $this->config->{$filename}(); } return $this->config->{$filename}($location); }
[ "public", "function", "config", "(", "$", "location", ")", "{", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "location", ")", ";", "$", "filename", "=", "'get'", ".", "strtoupper", "(", "array_shift", "(", "$", "keys", ")", ")", ";", "$", "location", "=", "implode", "(", "'.'", ",", "$", "keys", ")", ";", "if", "(", "empty", "(", "$", "location", ")", ")", "{", "return", "$", "this", "->", "config", "->", "{", "$", "filename", "}", "(", ")", ";", "}", "return", "$", "this", "->", "config", "->", "{", "$", "filename", "}", "(", "$", "location", ")", ";", "}" ]
To get configuration @param string $location @return mixed
[ "To", "get", "configuration" ]
530e772fb97695c1c4e1af73f81675f189474d9f
https://github.com/IftekherSunny/Planet-Framework/blob/530e772fb97695c1c4e1af73f81675f189474d9f/src/Sun/Application.php#L466-L479
train
stonedz/pff2
src/Core/HookManager.php
HookManager.registerHook
public function registerHook(IHookProvider $prov, $moduleName, $loadBefore = null) { $found = false; if(is_a($prov, '\\pff\\Iface\\IBeforeHook')) { $found = $this->addHook($this->_beforeController, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IAfterHook')) { $found = $this->addHook($this->_afterController, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IBeforeSystemHook')) { $found = $this->addHook($this->_beforeSystem, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IBeforeViewHook')) { $found = $this->addHook($this->_beforeView, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IAfterViewHook')) { $found = $this->addHook($this->_afterView, $prov, $moduleName, $loadBefore); } if(!$found) { throw new HookException("Cannot add given class as a hook provider: ". get_class($prov)); } }
php
public function registerHook(IHookProvider $prov, $moduleName, $loadBefore = null) { $found = false; if(is_a($prov, '\\pff\\Iface\\IBeforeHook')) { $found = $this->addHook($this->_beforeController, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IAfterHook')) { $found = $this->addHook($this->_afterController, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IBeforeSystemHook')) { $found = $this->addHook($this->_beforeSystem, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IBeforeViewHook')) { $found = $this->addHook($this->_beforeView, $prov, $moduleName, $loadBefore); } if(is_a($prov, '\\pff\\Iface\\IAfterViewHook')) { $found = $this->addHook($this->_afterView, $prov, $moduleName, $loadBefore); } if(!$found) { throw new HookException("Cannot add given class as a hook provider: ". get_class($prov)); } }
[ "public", "function", "registerHook", "(", "IHookProvider", "$", "prov", ",", "$", "moduleName", ",", "$", "loadBefore", "=", "null", ")", "{", "$", "found", "=", "false", ";", "if", "(", "is_a", "(", "$", "prov", ",", "'\\\\pff\\\\Iface\\\\IBeforeHook'", ")", ")", "{", "$", "found", "=", "$", "this", "->", "addHook", "(", "$", "this", "->", "_beforeController", ",", "$", "prov", ",", "$", "moduleName", ",", "$", "loadBefore", ")", ";", "}", "if", "(", "is_a", "(", "$", "prov", ",", "'\\\\pff\\\\Iface\\\\IAfterHook'", ")", ")", "{", "$", "found", "=", "$", "this", "->", "addHook", "(", "$", "this", "->", "_afterController", ",", "$", "prov", ",", "$", "moduleName", ",", "$", "loadBefore", ")", ";", "}", "if", "(", "is_a", "(", "$", "prov", ",", "'\\\\pff\\\\Iface\\\\IBeforeSystemHook'", ")", ")", "{", "$", "found", "=", "$", "this", "->", "addHook", "(", "$", "this", "->", "_beforeSystem", ",", "$", "prov", ",", "$", "moduleName", ",", "$", "loadBefore", ")", ";", "}", "if", "(", "is_a", "(", "$", "prov", ",", "'\\\\pff\\\\Iface\\\\IBeforeViewHook'", ")", ")", "{", "$", "found", "=", "$", "this", "->", "addHook", "(", "$", "this", "->", "_beforeView", ",", "$", "prov", ",", "$", "moduleName", ",", "$", "loadBefore", ")", ";", "}", "if", "(", "is_a", "(", "$", "prov", ",", "'\\\\pff\\\\Iface\\\\IAfterViewHook'", ")", ")", "{", "$", "found", "=", "$", "this", "->", "addHook", "(", "$", "this", "->", "_afterView", ",", "$", "prov", ",", "$", "moduleName", ",", "$", "loadBefore", ")", ";", "}", "if", "(", "!", "$", "found", ")", "{", "throw", "new", "HookException", "(", "\"Cannot add given class as a hook provider: \"", ".", "get_class", "(", "$", "prov", ")", ")", ";", "}", "}" ]
Registers a hook provider @param IHookProvider $prov Hook provider (module) @param string $moduleName Name of the module @param string|null $loadBefore Hook must be run before specified module name @throws HookException
[ "Registers", "a", "hook", "provider" ]
ec3b087d4d4732816f61ac487f0cb25511e0da88
https://github.com/stonedz/pff2/blob/ec3b087d4d4732816f61ac487f0cb25511e0da88/src/Core/HookManager.php#L72-L98
train
ekyna/AdminBundle
Twig/AdminExtension.php
AdminExtension.renderResourceButton
public function renderResourceButton($resource, $action = 'view', array $options = [], array $attributes = []) { if ($this->helper->isGranted($resource, $action)) { $options = array_merge($this->getButtonOptions($action), $options); $label = null; if (array_key_exists('label', $options)) { $label = $options['label']; unset($options['label']); } elseif (array_key_exists('short', $options)) { if ($options['short']) { $label = 'ekyna_core.button.' . $action; } unset($options['short']); } if (null === $label) { $config = $this->helper->getRegistry()->findConfiguration($resource); $label = sprintf('%s.button.%s', $config->getId(), $action); } if (!array_key_exists('path', $options)) { $options['path'] = $this->helper->generateResourcePath($resource, $action); } if (!array_key_exists('type', $options)) { $options['type'] = 'link'; } return $this->ui->renderButton( $label, $options, $attributes ); } return ''; }
php
public function renderResourceButton($resource, $action = 'view', array $options = [], array $attributes = []) { if ($this->helper->isGranted($resource, $action)) { $options = array_merge($this->getButtonOptions($action), $options); $label = null; if (array_key_exists('label', $options)) { $label = $options['label']; unset($options['label']); } elseif (array_key_exists('short', $options)) { if ($options['short']) { $label = 'ekyna_core.button.' . $action; } unset($options['short']); } if (null === $label) { $config = $this->helper->getRegistry()->findConfiguration($resource); $label = sprintf('%s.button.%s', $config->getId(), $action); } if (!array_key_exists('path', $options)) { $options['path'] = $this->helper->generateResourcePath($resource, $action); } if (!array_key_exists('type', $options)) { $options['type'] = 'link'; } return $this->ui->renderButton( $label, $options, $attributes ); } return ''; }
[ "public", "function", "renderResourceButton", "(", "$", "resource", ",", "$", "action", "=", "'view'", ",", "array", "$", "options", "=", "[", "]", ",", "array", "$", "attributes", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "helper", "->", "isGranted", "(", "$", "resource", ",", "$", "action", ")", ")", "{", "$", "options", "=", "array_merge", "(", "$", "this", "->", "getButtonOptions", "(", "$", "action", ")", ",", "$", "options", ")", ";", "$", "label", "=", "null", ";", "if", "(", "array_key_exists", "(", "'label'", ",", "$", "options", ")", ")", "{", "$", "label", "=", "$", "options", "[", "'label'", "]", ";", "unset", "(", "$", "options", "[", "'label'", "]", ")", ";", "}", "elseif", "(", "array_key_exists", "(", "'short'", ",", "$", "options", ")", ")", "{", "if", "(", "$", "options", "[", "'short'", "]", ")", "{", "$", "label", "=", "'ekyna_core.button.'", ".", "$", "action", ";", "}", "unset", "(", "$", "options", "[", "'short'", "]", ")", ";", "}", "if", "(", "null", "===", "$", "label", ")", "{", "$", "config", "=", "$", "this", "->", "helper", "->", "getRegistry", "(", ")", "->", "findConfiguration", "(", "$", "resource", ")", ";", "$", "label", "=", "sprintf", "(", "'%s.button.%s'", ",", "$", "config", "->", "getId", "(", ")", ",", "$", "action", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'path'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'path'", "]", "=", "$", "this", "->", "helper", "->", "generateResourcePath", "(", "$", "resource", ",", "$", "action", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'type'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'type'", "]", "=", "'link'", ";", "}", "return", "$", "this", "->", "ui", "->", "renderButton", "(", "$", "label", ",", "$", "options", ",", "$", "attributes", ")", ";", "}", "return", "''", ";", "}" ]
Renders a resource action button. @param mixed $resource @param string $action @param array $options @param array $attributes @return string
[ "Renders", "a", "resource", "action", "button", "." ]
3f58e253ae9cf651add7f3d587caec80eaea459a
https://github.com/ekyna/AdminBundle/blob/3f58e253ae9cf651add7f3d587caec80eaea459a/Twig/AdminExtension.php#L69-L104
train
cityware/city-format
src/Rtf.php
Rtf.isPlainText
function isPlainText($s) { $arrfailAt = array("*", "fonttbl", "colortbl", "datastore", "themedata"); for ($i = 0; $i < count($arrfailAt); $i++) { if (!empty($s[$arrfailAt[$i]])) { return false; } } return true; }
php
function isPlainText($s) { $arrfailAt = array("*", "fonttbl", "colortbl", "datastore", "themedata"); for ($i = 0; $i < count($arrfailAt); $i++) { if (!empty($s[$arrfailAt[$i]])) { return false; } } return true; }
[ "function", "isPlainText", "(", "$", "s", ")", "{", "$", "arrfailAt", "=", "array", "(", "\"*\"", ",", "\"fonttbl\"", ",", "\"colortbl\"", ",", "\"datastore\"", ",", "\"themedata\"", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "arrfailAt", ")", ";", "$", "i", "++", ")", "{", "if", "(", "!", "empty", "(", "$", "s", "[", "$", "arrfailAt", "[", "$", "i", "]", "]", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
For example, there may be a description of font or color palette etc.
[ "For", "example", "there", "may", "be", "a", "description", "of", "font", "or", "color", "palette", "etc", "." ]
1e292670639a950ecf561b545462427512950c74
https://github.com/cityware/city-format/blob/1e292670639a950ecf561b545462427512950c74/src/Rtf.php#L23-L31
train
gintonicweb/admin-theme
src/View/Helper/IconsHelper.php
IconsHelper.actions
public function actions($actions) { $substitutes = $this->config('substitutes'); foreach ($actions as $name => $config) { if (array_key_exists($name, $substitutes)) { $actions[$name]['title'] = '<i class="' . $substitutes[$name] . '"></i>'; } } return $actions; }
php
public function actions($actions) { $substitutes = $this->config('substitutes'); foreach ($actions as $name => $config) { if (array_key_exists($name, $substitutes)) { $actions[$name]['title'] = '<i class="' . $substitutes[$name] . '"></i>'; } } return $actions; }
[ "public", "function", "actions", "(", "$", "actions", ")", "{", "$", "substitutes", "=", "$", "this", "->", "config", "(", "'substitutes'", ")", ";", "foreach", "(", "$", "actions", "as", "$", "name", "=>", "$", "config", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "substitutes", ")", ")", "{", "$", "actions", "[", "$", "name", "]", "[", "'title'", "]", "=", "'<i class=\"'", ".", "$", "substitutes", "[", "$", "name", "]", ".", "'\"></i>'", ";", "}", "}", "return", "$", "actions", ";", "}" ]
This method replaces a string by an action icon. Mainly used for action icons
[ "This", "method", "replaces", "a", "string", "by", "an", "action", "icon", ".", "Mainly", "used", "for", "action", "icons" ]
35a3c685c2d4e462ffea022d3d89c2c0ed7104a1
https://github.com/gintonicweb/admin-theme/blob/35a3c685c2d4e462ffea022d3d89c2c0ed7104a1/src/View/Helper/IconsHelper.php#L24-L35
train
leprephp/routing
src/Route.php
Route.allowMethod
public function allowMethod(string $method): Route { if (!in_array($method, self::$supportedMethods)) { throw new UnsupportedMethodException($method); } $this->methods[] = $method; return $this; }
php
public function allowMethod(string $method): Route { if (!in_array($method, self::$supportedMethods)) { throw new UnsupportedMethodException($method); } $this->methods[] = $method; return $this; }
[ "public", "function", "allowMethod", "(", "string", "$", "method", ")", ":", "Route", "{", "if", "(", "!", "in_array", "(", "$", "method", ",", "self", "::", "$", "supportedMethods", ")", ")", "{", "throw", "new", "UnsupportedMethodException", "(", "$", "method", ")", ";", "}", "$", "this", "->", "methods", "[", "]", "=", "$", "method", ";", "return", "$", "this", ";", "}" ]
Allows an HTTP method. @param string $method The HTTP method to allow @return $this @throws UnsupportedMethodException If the method is not supported
[ "Allows", "an", "HTTP", "method", "." ]
c76beb1d6629896be956f4e2ee76dc0e9a6ed0f1
https://github.com/leprephp/routing/blob/c76beb1d6629896be956f4e2ee76dc0e9a6ed0f1/src/Route.php#L98-L107
train
leprephp/routing
src/Route.php
Route.allowMethods
public function allowMethods(array $methods = []): Route { $this->methods = []; foreach ($methods as $method) { $this->allowMethod($method); } return $this; }
php
public function allowMethods(array $methods = []): Route { $this->methods = []; foreach ($methods as $method) { $this->allowMethod($method); } return $this; }
[ "public", "function", "allowMethods", "(", "array", "$", "methods", "=", "[", "]", ")", ":", "Route", "{", "$", "this", "->", "methods", "=", "[", "]", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "$", "this", "->", "allowMethod", "(", "$", "method", ")", ";", "}", "return", "$", "this", ";", "}" ]
Allows a list of HTTP methods. @param string[] $methods The HTTP methods list to allow @return $this @throws UnsupportedMethodException If at least one of the methods is not supported
[ "Allows", "a", "list", "of", "HTTP", "methods", "." ]
c76beb1d6629896be956f4e2ee76dc0e9a6ed0f1
https://github.com/leprephp/routing/blob/c76beb1d6629896be956f4e2ee76dc0e9a6ed0f1/src/Route.php#L116-L124
train
leprephp/routing
src/Route.php
Route.getName
public function getName(): string { if ($this->name === null) { $this->name = $this->path; } return $this->name; }
php
public function getName(): string { if ($this->name === null) { $this->name = $this->path; } return $this->name; }
[ "public", "function", "getName", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "name", "===", "null", ")", "{", "$", "this", "->", "name", "=", "$", "this", "->", "path", ";", "}", "return", "$", "this", "->", "name", ";", "}" ]
Returns the name of the route. @return string
[ "Returns", "the", "name", "of", "the", "route", "." ]
c76beb1d6629896be956f4e2ee76dc0e9a6ed0f1
https://github.com/leprephp/routing/blob/c76beb1d6629896be956f4e2ee76dc0e9a6ed0f1/src/Route.php#L154-L161
train
keeko/framework
src/foundation/AbstractModule.php
AbstractModule.getFilesPath
public function getFilesPath() { $repo = $this->getServiceContainer()->getResourceRepository(); if (!$repo->contains($this->getFilesPuliPath())) { $dir = new Directory($repo->get('/files')->getFilesystemPath()); $path = $dir->toPath()->append('managed/' . $this->model->getName()); $dir = new Directory($path); $dir->make(); } $dir = new Directory($repo->get($this->getFilesPuliPath())->getFilesystemPath()); return $dir->toPath(); }
php
public function getFilesPath() { $repo = $this->getServiceContainer()->getResourceRepository(); if (!$repo->contains($this->getFilesPuliPath())) { $dir = new Directory($repo->get('/files')->getFilesystemPath()); $path = $dir->toPath()->append('managed/' . $this->model->getName()); $dir = new Directory($path); $dir->make(); } $dir = new Directory($repo->get($this->getFilesPuliPath())->getFilesystemPath()); return $dir->toPath(); }
[ "public", "function", "getFilesPath", "(", ")", "{", "$", "repo", "=", "$", "this", "->", "getServiceContainer", "(", ")", "->", "getResourceRepository", "(", ")", ";", "if", "(", "!", "$", "repo", "->", "contains", "(", "$", "this", "->", "getFilesPuliPath", "(", ")", ")", ")", "{", "$", "dir", "=", "new", "Directory", "(", "$", "repo", "->", "get", "(", "'/files'", ")", "->", "getFilesystemPath", "(", ")", ")", ";", "$", "path", "=", "$", "dir", "->", "toPath", "(", ")", "->", "append", "(", "'managed/'", ".", "$", "this", "->", "model", "->", "getName", "(", ")", ")", ";", "$", "dir", "=", "new", "Directory", "(", "$", "path", ")", ";", "$", "dir", "->", "make", "(", ")", ";", "}", "$", "dir", "=", "new", "Directory", "(", "$", "repo", "->", "get", "(", "$", "this", "->", "getFilesPuliPath", "(", ")", ")", "->", "getFilesystemPath", "(", ")", ")", ";", "return", "$", "dir", "->", "toPath", "(", ")", ";", "}" ]
Returns the path for managed files for this module @return Path
[ "Returns", "the", "path", "for", "managed", "files", "for", "this", "module" ]
a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac
https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/foundation/AbstractModule.php#L111-L122
train
keeko/framework
src/foundation/AbstractModule.php
AbstractModule.getFilesUrl
public function getFilesUrl($suffix = '') { $generator = $this->getServiceContainer()->getUrlGenerator(); return $generator->generateUrl($this->getFilesPuliPath() . '/' . $suffix); }
php
public function getFilesUrl($suffix = '') { $generator = $this->getServiceContainer()->getUrlGenerator(); return $generator->generateUrl($this->getFilesPuliPath() . '/' . $suffix); }
[ "public", "function", "getFilesUrl", "(", "$", "suffix", "=", "''", ")", "{", "$", "generator", "=", "$", "this", "->", "getServiceContainer", "(", ")", "->", "getUrlGenerator", "(", ")", ";", "return", "$", "generator", "->", "generateUrl", "(", "$", "this", "->", "getFilesPuliPath", "(", ")", ".", "'/'", ".", "$", "suffix", ")", ";", "}" ]
Returns the url for a managed file @param string $suffix @return string
[ "Returns", "the", "url", "for", "a", "managed", "file" ]
a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac
https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/foundation/AbstractModule.php#L130-L133
train
keeko/framework
src/foundation/AbstractModule.php
AbstractModule.getPreferences
public function getPreferences() { if ($this->preferences === null) { $this->preferences = $this->service->getPreferenceLoader()->getModulePreferences($this->model->getId()); } return $this->preferences; }
php
public function getPreferences() { if ($this->preferences === null) { $this->preferences = $this->service->getPreferenceLoader()->getModulePreferences($this->model->getId()); } return $this->preferences; }
[ "public", "function", "getPreferences", "(", ")", "{", "if", "(", "$", "this", "->", "preferences", "===", "null", ")", "{", "$", "this", "->", "preferences", "=", "$", "this", "->", "service", "->", "getPreferenceLoader", "(", ")", "->", "getModulePreferences", "(", "$", "this", "->", "model", "->", "getId", "(", ")", ")", ";", "}", "return", "$", "this", "->", "preferences", ";", "}" ]
Returns the module's preferences @return Preferences
[ "Returns", "the", "module", "s", "preferences" ]
a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac
https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/foundation/AbstractModule.php#L140-L146
train
keeko/framework
src/foundation/AbstractModule.php
AbstractModule.getActionModel
public function getActionModel($actionName) { if (isset($this->actions[$actionName])) { return $this->actions[$actionName]['model']; } return mull; }
php
public function getActionModel($actionName) { if (isset($this->actions[$actionName])) { return $this->actions[$actionName]['model']; } return mull; }
[ "public", "function", "getActionModel", "(", "$", "actionName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "actions", "[", "$", "actionName", "]", ")", ")", "{", "return", "$", "this", "->", "actions", "[", "$", "actionName", "]", "[", "'model'", "]", ";", "}", "return", "mull", ";", "}" ]
Returns the model for the given action name @param string $actionName @return Action
[ "Returns", "the", "model", "for", "the", "given", "action", "name" ]
a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac
https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/foundation/AbstractModule.php#L175-L181
train
keeko/framework
src/foundation/AbstractModule.php
AbstractModule.loadAction
public function loadAction($nameOrAction, $format = null) { $model = null; if ($nameOrAction instanceof Action) { $model = $nameOrAction; $actionName = $nameOrAction->getName(); } else { $actionName = $nameOrAction; } if (!isset($this->actions[$actionName])) { throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $actionName, $this->model->getName())); } if ($model === null) { $model = $this->actions[$actionName]['model']; } /* @var $action ActionSchema */ $action = $this->actions[$actionName]['action']; // check permission if (!$this->service->getFirewall()->hasActionPermission($model)) { throw new PermissionDeniedException(sprintf('Can\'t access Action (%s) in Module (%s)', $actionName, $this->model->getName())); } // check if a response is given if ($format !== null) { if (!$action->hasResponder($format)) { throw new ModuleException(sprintf('No Responder (%s) given for Action (%s) in Module (%s)', $format, $actionName, $this->model->getName())); } $responseClass = $action->getResponder($format); if (!class_exists($responseClass)) { throw new ModuleException(sprintf('Responder (%s) not found in Module (%s)', $responseClass, $this->model->getName())); } $responder = new $responseClass($this); } else { $responder = new NullResponder($this); } // gets the action class $className = $model->getClassName(); if (!class_exists($className)) { throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $className, $this->model->getName())); } $class = new $className($model, $this, $responder); // locales // ------------ $localeService = $this->getServiceContainer()->getLocaleService(); // load module l10n $file = sprintf('/%s/locales/{locale}/translations.json', $this->package->getFullName()); $localeService->loadLocaleFile($file, $class->getCanonicalName()); // // load additional l10n files // foreach ($action->getL10n() as $file) { // $file = sprintf('/%s/locales/{locale}/%s', $this->package->getFullName(), $file); // $localeService->loadLocaleFile($file, $class->getCanonicalName()); // } // // load action l10n // $file = sprintf('/%s/locales/{locale}/actions/%s', $this->package->getFullName(), $actionName); // $localeService->loadLocaleFile($file, $class->getCanonicalName()); // assets // ------------ $app = $this->getServiceContainer()->getKernel()->getApplication(); $page = $app->getPage(); // scripts foreach ($action->getScripts() as $script) { $page->addScript($script); } // styles foreach ($action->getStyles() as $style) { $page->addStyle($style); } return $class; }
php
public function loadAction($nameOrAction, $format = null) { $model = null; if ($nameOrAction instanceof Action) { $model = $nameOrAction; $actionName = $nameOrAction->getName(); } else { $actionName = $nameOrAction; } if (!isset($this->actions[$actionName])) { throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $actionName, $this->model->getName())); } if ($model === null) { $model = $this->actions[$actionName]['model']; } /* @var $action ActionSchema */ $action = $this->actions[$actionName]['action']; // check permission if (!$this->service->getFirewall()->hasActionPermission($model)) { throw new PermissionDeniedException(sprintf('Can\'t access Action (%s) in Module (%s)', $actionName, $this->model->getName())); } // check if a response is given if ($format !== null) { if (!$action->hasResponder($format)) { throw new ModuleException(sprintf('No Responder (%s) given for Action (%s) in Module (%s)', $format, $actionName, $this->model->getName())); } $responseClass = $action->getResponder($format); if (!class_exists($responseClass)) { throw new ModuleException(sprintf('Responder (%s) not found in Module (%s)', $responseClass, $this->model->getName())); } $responder = new $responseClass($this); } else { $responder = new NullResponder($this); } // gets the action class $className = $model->getClassName(); if (!class_exists($className)) { throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $className, $this->model->getName())); } $class = new $className($model, $this, $responder); // locales // ------------ $localeService = $this->getServiceContainer()->getLocaleService(); // load module l10n $file = sprintf('/%s/locales/{locale}/translations.json', $this->package->getFullName()); $localeService->loadLocaleFile($file, $class->getCanonicalName()); // // load additional l10n files // foreach ($action->getL10n() as $file) { // $file = sprintf('/%s/locales/{locale}/%s', $this->package->getFullName(), $file); // $localeService->loadLocaleFile($file, $class->getCanonicalName()); // } // // load action l10n // $file = sprintf('/%s/locales/{locale}/actions/%s', $this->package->getFullName(), $actionName); // $localeService->loadLocaleFile($file, $class->getCanonicalName()); // assets // ------------ $app = $this->getServiceContainer()->getKernel()->getApplication(); $page = $app->getPage(); // scripts foreach ($action->getScripts() as $script) { $page->addScript($script); } // styles foreach ($action->getStyles() as $style) { $page->addStyle($style); } return $class; }
[ "public", "function", "loadAction", "(", "$", "nameOrAction", ",", "$", "format", "=", "null", ")", "{", "$", "model", "=", "null", ";", "if", "(", "$", "nameOrAction", "instanceof", "Action", ")", "{", "$", "model", "=", "$", "nameOrAction", ";", "$", "actionName", "=", "$", "nameOrAction", "->", "getName", "(", ")", ";", "}", "else", "{", "$", "actionName", "=", "$", "nameOrAction", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "actions", "[", "$", "actionName", "]", ")", ")", "{", "throw", "new", "ModuleException", "(", "sprintf", "(", "'Action (%s) not found in Module (%s)'", ",", "$", "actionName", ",", "$", "this", "->", "model", "->", "getName", "(", ")", ")", ")", ";", "}", "if", "(", "$", "model", "===", "null", ")", "{", "$", "model", "=", "$", "this", "->", "actions", "[", "$", "actionName", "]", "[", "'model'", "]", ";", "}", "/* @var $action ActionSchema */", "$", "action", "=", "$", "this", "->", "actions", "[", "$", "actionName", "]", "[", "'action'", "]", ";", "// check permission", "if", "(", "!", "$", "this", "->", "service", "->", "getFirewall", "(", ")", "->", "hasActionPermission", "(", "$", "model", ")", ")", "{", "throw", "new", "PermissionDeniedException", "(", "sprintf", "(", "'Can\\'t access Action (%s) in Module (%s)'", ",", "$", "actionName", ",", "$", "this", "->", "model", "->", "getName", "(", ")", ")", ")", ";", "}", "// check if a response is given", "if", "(", "$", "format", "!==", "null", ")", "{", "if", "(", "!", "$", "action", "->", "hasResponder", "(", "$", "format", ")", ")", "{", "throw", "new", "ModuleException", "(", "sprintf", "(", "'No Responder (%s) given for Action (%s) in Module (%s)'", ",", "$", "format", ",", "$", "actionName", ",", "$", "this", "->", "model", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "responseClass", "=", "$", "action", "->", "getResponder", "(", "$", "format", ")", ";", "if", "(", "!", "class_exists", "(", "$", "responseClass", ")", ")", "{", "throw", "new", "ModuleException", "(", "sprintf", "(", "'Responder (%s) not found in Module (%s)'", ",", "$", "responseClass", ",", "$", "this", "->", "model", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "responder", "=", "new", "$", "responseClass", "(", "$", "this", ")", ";", "}", "else", "{", "$", "responder", "=", "new", "NullResponder", "(", "$", "this", ")", ";", "}", "// gets the action class", "$", "className", "=", "$", "model", "->", "getClassName", "(", ")", ";", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "throw", "new", "ModuleException", "(", "sprintf", "(", "'Action (%s) not found in Module (%s)'", ",", "$", "className", ",", "$", "this", "->", "model", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "class", "=", "new", "$", "className", "(", "$", "model", ",", "$", "this", ",", "$", "responder", ")", ";", "// locales", "// ------------", "$", "localeService", "=", "$", "this", "->", "getServiceContainer", "(", ")", "->", "getLocaleService", "(", ")", ";", "// load module l10n", "$", "file", "=", "sprintf", "(", "'/%s/locales/{locale}/translations.json'", ",", "$", "this", "->", "package", "->", "getFullName", "(", ")", ")", ";", "$", "localeService", "->", "loadLocaleFile", "(", "$", "file", ",", "$", "class", "->", "getCanonicalName", "(", ")", ")", ";", "// \t\t// load additional l10n files", "// \t\tforeach ($action->getL10n() as $file) {", "// \t\t\t$file = sprintf('/%s/locales/{locale}/%s', $this->package->getFullName(), $file);", "// \t\t\t$localeService->loadLocaleFile($file, $class->getCanonicalName());", "// \t\t}", "// \t\t// load action l10n", "// \t\t$file = sprintf('/%s/locales/{locale}/actions/%s', $this->package->getFullName(), $actionName);", "// \t\t$localeService->loadLocaleFile($file, $class->getCanonicalName());", "// assets", "// ------------", "$", "app", "=", "$", "this", "->", "getServiceContainer", "(", ")", "->", "getKernel", "(", ")", "->", "getApplication", "(", ")", ";", "$", "page", "=", "$", "app", "->", "getPage", "(", ")", ";", "// scripts", "foreach", "(", "$", "action", "->", "getScripts", "(", ")", "as", "$", "script", ")", "{", "$", "page", "->", "addScript", "(", "$", "script", ")", ";", "}", "// styles", "foreach", "(", "$", "action", "->", "getStyles", "(", ")", "as", "$", "style", ")", "{", "$", "page", "->", "addStyle", "(", "$", "style", ")", ";", "}", "return", "$", "class", ";", "}" ]
Loads the given action @param Action|string $actionName @param string $format the response type (e.g. html, json, ...) @return AbstractAction
[ "Loads", "the", "given", "action" ]
a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac
https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/foundation/AbstractModule.php#L190-L277
train
keeko/framework
src/foundation/AbstractModule.php
AbstractModule.hasPermission
public function hasPermission($action, User $user = null) { return $this->getServiceContainer()->getFirewall()->hasPermission($this->getName(), $action, $user); }
php
public function hasPermission($action, User $user = null) { return $this->getServiceContainer()->getFirewall()->hasPermission($this->getName(), $action, $user); }
[ "public", "function", "hasPermission", "(", "$", "action", ",", "User", "$", "user", "=", "null", ")", "{", "return", "$", "this", "->", "getServiceContainer", "(", ")", "->", "getFirewall", "(", ")", "->", "hasPermission", "(", "$", "this", "->", "getName", "(", ")", ",", "$", "action", ",", "$", "user", ")", ";", "}" ]
Shortcut for getting permission on the given action in this module @param string $action @param User $user
[ "Shortcut", "for", "getting", "permission", "on", "the", "given", "action", "in", "this", "module" ]
a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac
https://github.com/keeko/framework/blob/a2c5d76a4ab7bd658e81d88fb3c98eee115c06ac/src/foundation/AbstractModule.php#L285-L287
train
luoxiaojun1992/lb_framework
components/db/mysql/Connection.php
Connection.getMasterConnection
protected function getMasterConnection() { $db_config = $this->containers['config']->get('mysql'); $master_db_config = $db_config['master']; $this->_master_db = isset($master_db_config['dbname']) ? $master_db_config['dbname'] : ''; $this->_master_host = isset($master_db_config['host']) ? $master_db_config['host'] : ''; $this->_master_username = isset($master_db_config['username']) ? $master_db_config['username'] : ''; $this->_master_password = isset($master_db_config['password']) ? $master_db_config['password'] : ''; $this->_master_options = isset($master_db_config['options']) ? $master_db_config['options'] : []; $this->getDsn(self::CONN_TYPE_MASTER); $this->getConnection(self::CONN_TYPE_MASTER); }
php
protected function getMasterConnection() { $db_config = $this->containers['config']->get('mysql'); $master_db_config = $db_config['master']; $this->_master_db = isset($master_db_config['dbname']) ? $master_db_config['dbname'] : ''; $this->_master_host = isset($master_db_config['host']) ? $master_db_config['host'] : ''; $this->_master_username = isset($master_db_config['username']) ? $master_db_config['username'] : ''; $this->_master_password = isset($master_db_config['password']) ? $master_db_config['password'] : ''; $this->_master_options = isset($master_db_config['options']) ? $master_db_config['options'] : []; $this->getDsn(self::CONN_TYPE_MASTER); $this->getConnection(self::CONN_TYPE_MASTER); }
[ "protected", "function", "getMasterConnection", "(", ")", "{", "$", "db_config", "=", "$", "this", "->", "containers", "[", "'config'", "]", "->", "get", "(", "'mysql'", ")", ";", "$", "master_db_config", "=", "$", "db_config", "[", "'master'", "]", ";", "$", "this", "->", "_master_db", "=", "isset", "(", "$", "master_db_config", "[", "'dbname'", "]", ")", "?", "$", "master_db_config", "[", "'dbname'", "]", ":", "''", ";", "$", "this", "->", "_master_host", "=", "isset", "(", "$", "master_db_config", "[", "'host'", "]", ")", "?", "$", "master_db_config", "[", "'host'", "]", ":", "''", ";", "$", "this", "->", "_master_username", "=", "isset", "(", "$", "master_db_config", "[", "'username'", "]", ")", "?", "$", "master_db_config", "[", "'username'", "]", ":", "''", ";", "$", "this", "->", "_master_password", "=", "isset", "(", "$", "master_db_config", "[", "'password'", "]", ")", "?", "$", "master_db_config", "[", "'password'", "]", ":", "''", ";", "$", "this", "->", "_master_options", "=", "isset", "(", "$", "master_db_config", "[", "'options'", "]", ")", "?", "$", "master_db_config", "[", "'options'", "]", ":", "[", "]", ";", "$", "this", "->", "getDsn", "(", "self", "::", "CONN_TYPE_MASTER", ")", ";", "$", "this", "->", "getConnection", "(", "self", "::", "CONN_TYPE_MASTER", ")", ";", "}" ]
Establish master node mysql connection
[ "Establish", "master", "node", "mysql", "connection" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/db/mysql/Connection.php#L92-L103
train
luoxiaojun1992/lb_framework
components/db/mysql/Connection.php
Connection.getSlaveConnection
protected function getSlaveConnection($server_hosts = []) { $db_config = $this->containers['config']->get('mysql'); $slave_config = $db_config['slaves']; if (!$server_hosts) { foreach ($slave_config as $key => $config) { $server_hosts[$key] = $config['host']; } } if ($server_hosts) { // 一致性HASH $target_host = LoadBalancer::getTargetHost($server_hosts); foreach ($server_hosts as $key => $server_host) { if ($server_host == $target_host) { $slave_target_num = $key; $target_slave_config = $slave_config[$slave_target_num]; $this->_slave_db = $target_slave_config['dbname'] ?? ''; $this->_slave_host = $target_slave_config['host'] ?? ''; $this->_slave_username = $target_slave_config['username'] ?? ''; $this->_slave_password = $target_slave_config['password'] ?? ''; $this->_slave_options = $target_slave_config['options'] ?? []; $this->getDsn(self::CONN_TYPE_SLAVE); try { $this->getConnection(self::CONN_TYPE_SLAVE); } catch (\PDOException $e) { unset($server_hosts[$slave_target_num]); $this->getSlaveConnection($server_hosts); } break; } } } }
php
protected function getSlaveConnection($server_hosts = []) { $db_config = $this->containers['config']->get('mysql'); $slave_config = $db_config['slaves']; if (!$server_hosts) { foreach ($slave_config as $key => $config) { $server_hosts[$key] = $config['host']; } } if ($server_hosts) { // 一致性HASH $target_host = LoadBalancer::getTargetHost($server_hosts); foreach ($server_hosts as $key => $server_host) { if ($server_host == $target_host) { $slave_target_num = $key; $target_slave_config = $slave_config[$slave_target_num]; $this->_slave_db = $target_slave_config['dbname'] ?? ''; $this->_slave_host = $target_slave_config['host'] ?? ''; $this->_slave_username = $target_slave_config['username'] ?? ''; $this->_slave_password = $target_slave_config['password'] ?? ''; $this->_slave_options = $target_slave_config['options'] ?? []; $this->getDsn(self::CONN_TYPE_SLAVE); try { $this->getConnection(self::CONN_TYPE_SLAVE); } catch (\PDOException $e) { unset($server_hosts[$slave_target_num]); $this->getSlaveConnection($server_hosts); } break; } } } }
[ "protected", "function", "getSlaveConnection", "(", "$", "server_hosts", "=", "[", "]", ")", "{", "$", "db_config", "=", "$", "this", "->", "containers", "[", "'config'", "]", "->", "get", "(", "'mysql'", ")", ";", "$", "slave_config", "=", "$", "db_config", "[", "'slaves'", "]", ";", "if", "(", "!", "$", "server_hosts", ")", "{", "foreach", "(", "$", "slave_config", "as", "$", "key", "=>", "$", "config", ")", "{", "$", "server_hosts", "[", "$", "key", "]", "=", "$", "config", "[", "'host'", "]", ";", "}", "}", "if", "(", "$", "server_hosts", ")", "{", "// 一致性HASH", "$", "target_host", "=", "LoadBalancer", "::", "getTargetHost", "(", "$", "server_hosts", ")", ";", "foreach", "(", "$", "server_hosts", "as", "$", "key", "=>", "$", "server_host", ")", "{", "if", "(", "$", "server_host", "==", "$", "target_host", ")", "{", "$", "slave_target_num", "=", "$", "key", ";", "$", "target_slave_config", "=", "$", "slave_config", "[", "$", "slave_target_num", "]", ";", "$", "this", "->", "_slave_db", "=", "$", "target_slave_config", "[", "'dbname'", "]", "??", "''", ";", "$", "this", "->", "_slave_host", "=", "$", "target_slave_config", "[", "'host'", "]", "??", "''", ";", "$", "this", "->", "_slave_username", "=", "$", "target_slave_config", "[", "'username'", "]", "??", "''", ";", "$", "this", "->", "_slave_password", "=", "$", "target_slave_config", "[", "'password'", "]", "??", "''", ";", "$", "this", "->", "_slave_options", "=", "$", "target_slave_config", "[", "'options'", "]", "??", "[", "]", ";", "$", "this", "->", "getDsn", "(", "self", "::", "CONN_TYPE_SLAVE", ")", ";", "try", "{", "$", "this", "->", "getConnection", "(", "self", "::", "CONN_TYPE_SLAVE", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "unset", "(", "$", "server_hosts", "[", "$", "slave_target_num", "]", ")", ";", "$", "this", "->", "getSlaveConnection", "(", "$", "server_hosts", ")", ";", "}", "break", ";", "}", "}", "}", "}" ]
Establish slave node mysql connection @param array $server_hosts
[ "Establish", "slave", "node", "mysql", "connection" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/db/mysql/Connection.php#L110-L142
train
luoxiaojun1992/lb_framework
components/db/mysql/Connection.php
Connection.getExtraConnection
protected function getExtraConnection($conn) { $dbConfigs = $this->containers['config']->get('mysql'); $dbConfig = $dbConfigs[$conn]; $this->extraConfigs[$conn]['_db'] = $dbConfig['dbname'] ?? ''; $this->extraConfigs[$conn]['_host'] = $dbConfig['host'] ?? ''; $this->extraConfigs[$conn]['_username'] = $dbConfig['username'] ?? ''; $this->extraConfigs[$conn]['_password'] = $dbConfig['password'] ?? ''; $this->extraConfigs[$conn]['_options'] = $dbConfig['options'] ?? ''; $this->getDsn($conn); $this->getConnection($conn); }
php
protected function getExtraConnection($conn) { $dbConfigs = $this->containers['config']->get('mysql'); $dbConfig = $dbConfigs[$conn]; $this->extraConfigs[$conn]['_db'] = $dbConfig['dbname'] ?? ''; $this->extraConfigs[$conn]['_host'] = $dbConfig['host'] ?? ''; $this->extraConfigs[$conn]['_username'] = $dbConfig['username'] ?? ''; $this->extraConfigs[$conn]['_password'] = $dbConfig['password'] ?? ''; $this->extraConfigs[$conn]['_options'] = $dbConfig['options'] ?? ''; $this->getDsn($conn); $this->getConnection($conn); }
[ "protected", "function", "getExtraConnection", "(", "$", "conn", ")", "{", "$", "dbConfigs", "=", "$", "this", "->", "containers", "[", "'config'", "]", "->", "get", "(", "'mysql'", ")", ";", "$", "dbConfig", "=", "$", "dbConfigs", "[", "$", "conn", "]", ";", "$", "this", "->", "extraConfigs", "[", "$", "conn", "]", "[", "'_db'", "]", "=", "$", "dbConfig", "[", "'dbname'", "]", "??", "''", ";", "$", "this", "->", "extraConfigs", "[", "$", "conn", "]", "[", "'_host'", "]", "=", "$", "dbConfig", "[", "'host'", "]", "??", "''", ";", "$", "this", "->", "extraConfigs", "[", "$", "conn", "]", "[", "'_username'", "]", "=", "$", "dbConfig", "[", "'username'", "]", "??", "''", ";", "$", "this", "->", "extraConfigs", "[", "$", "conn", "]", "[", "'_password'", "]", "=", "$", "dbConfig", "[", "'password'", "]", "??", "''", ";", "$", "this", "->", "extraConfigs", "[", "$", "conn", "]", "[", "'_options'", "]", "=", "$", "dbConfig", "[", "'options'", "]", "??", "''", ";", "$", "this", "->", "getDsn", "(", "$", "conn", ")", ";", "$", "this", "->", "getConnection", "(", "$", "conn", ")", ";", "}" ]
Establish extra mysql connection @param $conn
[ "Establish", "extra", "mysql", "connection" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/db/mysql/Connection.php#L149-L160
train
luoxiaojun1992/lb_framework
components/db/mysql/Connection.php
Connection.getConnection
protected function getConnection($node_type) { switch ($node_type) { case self::CONN_TYPE_MASTER: $this->write_conn = new \PDO($this->_master_dsn, $this->_master_username, $this->_master_password, $this->_master_options); break; case self::CONN_TYPE_SLAVE: $this->read_conn = new \PDO($this->_slave_dsn, $this->_slave_username, $this->_slave_password, $this->_slave_options); break; default: if (in_array($node_type, $this->extraConfigs) && in_array($node_type, $this->extraDsns)) { $extraConfig = $this->extraConfigs[$node_type]; $this->extraConns[$node_type] = new \PDO($this->extraDsns[$node_type], $extraConfig['_username'], $extraConfig['_password'], $extraConfig['_options']); } else { $this->write_conn = new \PDO($this->_master_dsn, $this->_master_username, $this->_master_password, $this->_master_options); } } }
php
protected function getConnection($node_type) { switch ($node_type) { case self::CONN_TYPE_MASTER: $this->write_conn = new \PDO($this->_master_dsn, $this->_master_username, $this->_master_password, $this->_master_options); break; case self::CONN_TYPE_SLAVE: $this->read_conn = new \PDO($this->_slave_dsn, $this->_slave_username, $this->_slave_password, $this->_slave_options); break; default: if (in_array($node_type, $this->extraConfigs) && in_array($node_type, $this->extraDsns)) { $extraConfig = $this->extraConfigs[$node_type]; $this->extraConns[$node_type] = new \PDO($this->extraDsns[$node_type], $extraConfig['_username'], $extraConfig['_password'], $extraConfig['_options']); } else { $this->write_conn = new \PDO($this->_master_dsn, $this->_master_username, $this->_master_password, $this->_master_options); } } }
[ "protected", "function", "getConnection", "(", "$", "node_type", ")", "{", "switch", "(", "$", "node_type", ")", "{", "case", "self", "::", "CONN_TYPE_MASTER", ":", "$", "this", "->", "write_conn", "=", "new", "\\", "PDO", "(", "$", "this", "->", "_master_dsn", ",", "$", "this", "->", "_master_username", ",", "$", "this", "->", "_master_password", ",", "$", "this", "->", "_master_options", ")", ";", "break", ";", "case", "self", "::", "CONN_TYPE_SLAVE", ":", "$", "this", "->", "read_conn", "=", "new", "\\", "PDO", "(", "$", "this", "->", "_slave_dsn", ",", "$", "this", "->", "_slave_username", ",", "$", "this", "->", "_slave_password", ",", "$", "this", "->", "_slave_options", ")", ";", "break", ";", "default", ":", "if", "(", "in_array", "(", "$", "node_type", ",", "$", "this", "->", "extraConfigs", ")", "&&", "in_array", "(", "$", "node_type", ",", "$", "this", "->", "extraDsns", ")", ")", "{", "$", "extraConfig", "=", "$", "this", "->", "extraConfigs", "[", "$", "node_type", "]", ";", "$", "this", "->", "extraConns", "[", "$", "node_type", "]", "=", "new", "\\", "PDO", "(", "$", "this", "->", "extraDsns", "[", "$", "node_type", "]", ",", "$", "extraConfig", "[", "'_username'", "]", ",", "$", "extraConfig", "[", "'_password'", "]", ",", "$", "extraConfig", "[", "'_options'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "write_conn", "=", "new", "\\", "PDO", "(", "$", "this", "->", "_master_dsn", ",", "$", "this", "->", "_master_username", ",", "$", "this", "->", "_master_password", ",", "$", "this", "->", "_master_options", ")", ";", "}", "}", "}" ]
Establish mysql connection @param $node_type
[ "Establish", "mysql", "connection" ]
12a865729e7738d7d1e07371ad7203243c4571fa
https://github.com/luoxiaojun1992/lb_framework/blob/12a865729e7738d7d1e07371ad7203243c4571fa/components/db/mysql/Connection.php#L191-L208
train
denkfabrik-neueMedien/silverstripe-siteinfo
src/extension/SiteInfoController.php
SiteInfoController.CountryNice
public function CountryNice() { // $config = SiteConfig::current_site_config(); return Zend_Locale::getTranslation($config->Country, "territory", i18n::get_locale()); }
php
public function CountryNice() { // $config = SiteConfig::current_site_config(); return Zend_Locale::getTranslation($config->Country, "territory", i18n::get_locale()); }
[ "public", "function", "CountryNice", "(", ")", "{", "//", "$", "config", "=", "SiteConfig", "::", "current_site_config", "(", ")", ";", "return", "Zend_Locale", "::", "getTranslation", "(", "$", "config", "->", "Country", ",", "\"territory\"", ",", "i18n", "::", "get_locale", "(", ")", ")", ";", "}" ]
Get the full translated country name @return false|string
[ "Get", "the", "full", "translated", "country", "name" ]
cd59ea0cf5c13678ff8efd93028d35c726670c25
https://github.com/denkfabrik-neueMedien/silverstripe-siteinfo/blob/cd59ea0cf5c13678ff8efd93028d35c726670c25/src/extension/SiteInfoController.php#L49-L54
train
borobudur-php/borobudur
src/Borobudur/Component/Mapper/ObjectMapper.php
ObjectMapper.fill
public function fill($data) { if (!$this->object) { throw new InvalidArgumentException( 'There are no object to be mapped' ); } if (!is_object($data)) { throw new InvalidArgumentException('Data should be an object'); } $data = $this->extractData($data); $allowed = $this->extractAllowedAttributes($this->class); foreach ($this->class->getProperties() as $property) { $name = $property->getName(); if (!in_array($name, $allowed, true) || !array_key_exists( $name, $data ) ) { continue; } $property->setAccessible(true); $property->setValue($this->object, $data[$name]); } return $this->object; }
php
public function fill($data) { if (!$this->object) { throw new InvalidArgumentException( 'There are no object to be mapped' ); } if (!is_object($data)) { throw new InvalidArgumentException('Data should be an object'); } $data = $this->extractData($data); $allowed = $this->extractAllowedAttributes($this->class); foreach ($this->class->getProperties() as $property) { $name = $property->getName(); if (!in_array($name, $allowed, true) || !array_key_exists( $name, $data ) ) { continue; } $property->setAccessible(true); $property->setValue($this->object, $data[$name]); } return $this->object; }
[ "public", "function", "fill", "(", "$", "data", ")", "{", "if", "(", "!", "$", "this", "->", "object", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'There are no object to be mapped'", ")", ";", "}", "if", "(", "!", "is_object", "(", "$", "data", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Data should be an object'", ")", ";", "}", "$", "data", "=", "$", "this", "->", "extractData", "(", "$", "data", ")", ";", "$", "allowed", "=", "$", "this", "->", "extractAllowedAttributes", "(", "$", "this", "->", "class", ")", ";", "foreach", "(", "$", "this", "->", "class", "->", "getProperties", "(", ")", "as", "$", "property", ")", "{", "$", "name", "=", "$", "property", "->", "getName", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "allowed", ",", "true", ")", "||", "!", "array_key_exists", "(", "$", "name", ",", "$", "data", ")", ")", "{", "continue", ";", "}", "$", "property", "->", "setAccessible", "(", "true", ")", ";", "$", "property", "->", "setValue", "(", "$", "this", "->", "object", ",", "$", "data", "[", "$", "name", "]", ")", ";", "}", "return", "$", "this", "->", "object", ";", "}" ]
Fill object from object @param object $data @return object
[ "Fill", "object", "from", "object" ]
6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44
https://github.com/borobudur-php/borobudur/blob/6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44/src/Borobudur/Component/Mapper/ObjectMapper.php#L71-L102
train
borobudur-php/borobudur
src/Borobudur/Component/Mapper/ObjectMapper.php
ObjectMapper.extractAllowedAttributes
private function extractAllowedAttributes(ReflectionClass $reflection): array { $allowed = []; foreach ( $reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method ) { if (!$this->isGetMethod($method)) { continue; } $name = $this->getAttributeName($method); if ($this->isExclude($name)) { continue; } $allowed[] = $name; } return $allowed; }
php
private function extractAllowedAttributes(ReflectionClass $reflection): array { $allowed = []; foreach ( $reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method ) { if (!$this->isGetMethod($method)) { continue; } $name = $this->getAttributeName($method); if ($this->isExclude($name)) { continue; } $allowed[] = $name; } return $allowed; }
[ "private", "function", "extractAllowedAttributes", "(", "ReflectionClass", "$", "reflection", ")", ":", "array", "{", "$", "allowed", "=", "[", "]", ";", "foreach", "(", "$", "reflection", "->", "getMethods", "(", "ReflectionMethod", "::", "IS_PUBLIC", ")", "as", "$", "method", ")", "{", "if", "(", "!", "$", "this", "->", "isGetMethod", "(", "$", "method", ")", ")", "{", "continue", ";", "}", "$", "name", "=", "$", "this", "->", "getAttributeName", "(", "$", "method", ")", ";", "if", "(", "$", "this", "->", "isExclude", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "$", "allowed", "[", "]", "=", "$", "name", ";", "}", "return", "$", "allowed", ";", "}" ]
Extract allowed attributes. @param ReflectionClass $reflection @return array
[ "Extract", "allowed", "attributes", "." ]
6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44
https://github.com/borobudur-php/borobudur/blob/6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44/src/Borobudur/Component/Mapper/ObjectMapper.php#L126-L145
train
borobudur-php/borobudur
src/Borobudur/Component/Mapper/ObjectMapper.php
ObjectMapper.isExclude
private function isExclude(string $key): bool { if (!empty($this->excludes) && in_array($key, $this->excludes, true)) { return true; } if (!empty($this->only) && !in_array($key, $this->only, true)) { return true; } return false; }
php
private function isExclude(string $key): bool { if (!empty($this->excludes) && in_array($key, $this->excludes, true)) { return true; } if (!empty($this->only) && !in_array($key, $this->only, true)) { return true; } return false; }
[ "private", "function", "isExclude", "(", "string", "$", "key", ")", ":", "bool", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "excludes", ")", "&&", "in_array", "(", "$", "key", ",", "$", "this", "->", "excludes", ",", "true", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "only", ")", "&&", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "only", ",", "true", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check whether current key is excluded. @param string $key @return bool
[ "Check", "whether", "current", "key", "is", "excluded", "." ]
6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44
https://github.com/borobudur-php/borobudur/blob/6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44/src/Borobudur/Component/Mapper/ObjectMapper.php#L154-L165
train
borobudur-php/borobudur
src/Borobudur/Component/Mapper/ObjectMapper.php
ObjectMapper.extractData
private function extractData(object $data): array { if ($data instanceof \stdClass) { return (array) $data; } $extracted = []; $reflection = new \ReflectionObject($data); foreach ( $reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method ) { if (!$this->isGetMethod($method)) { continue; } $extracted[$this->getAttributeName($method)] = $method->invoke( $data ); } return $extracted; }
php
private function extractData(object $data): array { if ($data instanceof \stdClass) { return (array) $data; } $extracted = []; $reflection = new \ReflectionObject($data); foreach ( $reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method ) { if (!$this->isGetMethod($method)) { continue; } $extracted[$this->getAttributeName($method)] = $method->invoke( $data ); } return $extracted; }
[ "private", "function", "extractData", "(", "object", "$", "data", ")", ":", "array", "{", "if", "(", "$", "data", "instanceof", "\\", "stdClass", ")", "{", "return", "(", "array", ")", "$", "data", ";", "}", "$", "extracted", "=", "[", "]", ";", "$", "reflection", "=", "new", "\\", "ReflectionObject", "(", "$", "data", ")", ";", "foreach", "(", "$", "reflection", "->", "getMethods", "(", "ReflectionMethod", "::", "IS_PUBLIC", ")", "as", "$", "method", ")", "{", "if", "(", "!", "$", "this", "->", "isGetMethod", "(", "$", "method", ")", ")", "{", "continue", ";", "}", "$", "extracted", "[", "$", "this", "->", "getAttributeName", "(", "$", "method", ")", "]", "=", "$", "method", "->", "invoke", "(", "$", "data", ")", ";", "}", "return", "$", "extracted", ";", "}" ]
Extract the object data to array. @param object $data @return array
[ "Extract", "the", "object", "data", "to", "array", "." ]
6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44
https://github.com/borobudur-php/borobudur/blob/6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44/src/Borobudur/Component/Mapper/ObjectMapper.php#L174-L195
train
borobudur-php/borobudur
src/Borobudur/Component/Mapper/ObjectMapper.php
ObjectMapper.getAttributeName
private function getAttributeName(ReflectionMethod $method): string { return lcfirst( substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3) ); }
php
private function getAttributeName(ReflectionMethod $method): string { return lcfirst( substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3) ); }
[ "private", "function", "getAttributeName", "(", "ReflectionMethod", "$", "method", ")", ":", "string", "{", "return", "lcfirst", "(", "substr", "(", "$", "method", "->", "name", ",", "0", "===", "strpos", "(", "$", "method", "->", "name", ",", "'is'", ")", "?", "2", ":", "3", ")", ")", ";", "}" ]
Get the attribute name from method. @param ReflectionMethod $method @return string
[ "Get", "the", "attribute", "name", "from", "method", "." ]
6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44
https://github.com/borobudur-php/borobudur/blob/6ab0d97e1819ba0b96dc4c3bca3a7c9b1217bd44/src/Borobudur/Component/Mapper/ObjectMapper.php#L225-L230
train
schpill/thin
src/Phonetic.php
Phonetic.setTolerance
public function setTolerance($tolerance = 0.20) { if ($tolerance < 0 || $tolerance > 1) { return false; } $this->_tolerance = round($tolerance, 2); return $this; }
php
public function setTolerance($tolerance = 0.20) { if ($tolerance < 0 || $tolerance > 1) { return false; } $this->_tolerance = round($tolerance, 2); return $this; }
[ "public", "function", "setTolerance", "(", "$", "tolerance", "=", "0.20", ")", "{", "if", "(", "$", "tolerance", "<", "0", "||", "$", "tolerance", ">", "1", ")", "{", "return", "false", ";", "}", "$", "this", "->", "_tolerance", "=", "round", "(", "$", "tolerance", ",", "2", ")", ";", "return", "$", "this", ";", "}" ]
Set fault tolerance for what is considered 'similar'. @param float $tol a percentage setting how close the strings need to be to be considered similar.
[ "Set", "fault", "tolerance", "for", "what", "is", "considered", "similar", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Phonetic.php#L43-L52
train
schpill/thin
src/Phonetic.php
Phonetic.similarity
public function similarity($string = null, $cmp = null, $language = 'french') { if (empty($string) || empty($cmp)) { return false; } if (strlen($string) > 255 || strlen($cmp) > 255) { return false; } $processedStr = $this->phoneme($string, $language); $processedCmp = $this->phoneme($cmp, $language); $score = levenshtein($processedStr, $processedCmp); $smaller = strlen($processedStr) < strlen($processedCmp) ? $processedStr : $processedCmp; $biggest = strlen($processedStr) < strlen($processedCmp) ? $processedCmp : $processedStr; $phonexStr = $this->getPhonex($string); $phonexCmp = $this->getPhonex($cmp); $scorePhonex = ($phonexStr + $phonexCmp) / 2; if (empty($biggest) || empty($smaller)) { return false; } $contain = strstr($biggest, $smaller); $avgLength = (strlen($processedStr) + strlen($processedCmp)) / 2; $finalScore = round((1.0 / $avgLength) * $score, 6); $finalScore = round(((1 - $finalScore) * 100), 2); $finalScore = 0 > $finalScore && false !== $contain ? 100 + $finalScore : $finalScore; $finalScore = 100 < $finalScore ? 100 : $finalScore; $finalScore = 0 > $finalScore ? 0 : $finalScore; if ($finalScore / 100 >= $this->_tolerance) { $grade = 1; } else { $grade = 0; } $proxMatch = self::checkProx(self::_iconv($string), self::_iconv($cmp)); $pctg = $finalScore > $proxMatch ? $finalScore : $proxMatch; if (strstr($string, ' ') && strstr($cmp, ' ')) { $matchWords = self::matchWords(self::_iconv($string), self::_iconv($cmp)); $pctg = $matchWords > $pctg ? $matchWords : $pctg; } $finalScore = $pctg > $finalScore ? $pctg : $finalScore; $data = array( 'cost' => $score, 'score' => $finalScore, 'similar' => $grade ); return $data; }
php
public function similarity($string = null, $cmp = null, $language = 'french') { if (empty($string) || empty($cmp)) { return false; } if (strlen($string) > 255 || strlen($cmp) > 255) { return false; } $processedStr = $this->phoneme($string, $language); $processedCmp = $this->phoneme($cmp, $language); $score = levenshtein($processedStr, $processedCmp); $smaller = strlen($processedStr) < strlen($processedCmp) ? $processedStr : $processedCmp; $biggest = strlen($processedStr) < strlen($processedCmp) ? $processedCmp : $processedStr; $phonexStr = $this->getPhonex($string); $phonexCmp = $this->getPhonex($cmp); $scorePhonex = ($phonexStr + $phonexCmp) / 2; if (empty($biggest) || empty($smaller)) { return false; } $contain = strstr($biggest, $smaller); $avgLength = (strlen($processedStr) + strlen($processedCmp)) / 2; $finalScore = round((1.0 / $avgLength) * $score, 6); $finalScore = round(((1 - $finalScore) * 100), 2); $finalScore = 0 > $finalScore && false !== $contain ? 100 + $finalScore : $finalScore; $finalScore = 100 < $finalScore ? 100 : $finalScore; $finalScore = 0 > $finalScore ? 0 : $finalScore; if ($finalScore / 100 >= $this->_tolerance) { $grade = 1; } else { $grade = 0; } $proxMatch = self::checkProx(self::_iconv($string), self::_iconv($cmp)); $pctg = $finalScore > $proxMatch ? $finalScore : $proxMatch; if (strstr($string, ' ') && strstr($cmp, ' ')) { $matchWords = self::matchWords(self::_iconv($string), self::_iconv($cmp)); $pctg = $matchWords > $pctg ? $matchWords : $pctg; } $finalScore = $pctg > $finalScore ? $pctg : $finalScore; $data = array( 'cost' => $score, 'score' => $finalScore, 'similar' => $grade ); return $data; }
[ "public", "function", "similarity", "(", "$", "string", "=", "null", ",", "$", "cmp", "=", "null", ",", "$", "language", "=", "'french'", ")", "{", "if", "(", "empty", "(", "$", "string", ")", "||", "empty", "(", "$", "cmp", ")", ")", "{", "return", "false", ";", "}", "if", "(", "strlen", "(", "$", "string", ")", ">", "255", "||", "strlen", "(", "$", "cmp", ")", ">", "255", ")", "{", "return", "false", ";", "}", "$", "processedStr", "=", "$", "this", "->", "phoneme", "(", "$", "string", ",", "$", "language", ")", ";", "$", "processedCmp", "=", "$", "this", "->", "phoneme", "(", "$", "cmp", ",", "$", "language", ")", ";", "$", "score", "=", "levenshtein", "(", "$", "processedStr", ",", "$", "processedCmp", ")", ";", "$", "smaller", "=", "strlen", "(", "$", "processedStr", ")", "<", "strlen", "(", "$", "processedCmp", ")", "?", "$", "processedStr", ":", "$", "processedCmp", ";", "$", "biggest", "=", "strlen", "(", "$", "processedStr", ")", "<", "strlen", "(", "$", "processedCmp", ")", "?", "$", "processedCmp", ":", "$", "processedStr", ";", "$", "phonexStr", "=", "$", "this", "->", "getPhonex", "(", "$", "string", ")", ";", "$", "phonexCmp", "=", "$", "this", "->", "getPhonex", "(", "$", "cmp", ")", ";", "$", "scorePhonex", "=", "(", "$", "phonexStr", "+", "$", "phonexCmp", ")", "/", "2", ";", "if", "(", "empty", "(", "$", "biggest", ")", "||", "empty", "(", "$", "smaller", ")", ")", "{", "return", "false", ";", "}", "$", "contain", "=", "strstr", "(", "$", "biggest", ",", "$", "smaller", ")", ";", "$", "avgLength", "=", "(", "strlen", "(", "$", "processedStr", ")", "+", "strlen", "(", "$", "processedCmp", ")", ")", "/", "2", ";", "$", "finalScore", "=", "round", "(", "(", "1.0", "/", "$", "avgLength", ")", "*", "$", "score", ",", "6", ")", ";", "$", "finalScore", "=", "round", "(", "(", "(", "1", "-", "$", "finalScore", ")", "*", "100", ")", ",", "2", ")", ";", "$", "finalScore", "=", "0", ">", "$", "finalScore", "&&", "false", "!==", "$", "contain", "?", "100", "+", "$", "finalScore", ":", "$", "finalScore", ";", "$", "finalScore", "=", "100", "<", "$", "finalScore", "?", "100", ":", "$", "finalScore", ";", "$", "finalScore", "=", "0", ">", "$", "finalScore", "?", "0", ":", "$", "finalScore", ";", "if", "(", "$", "finalScore", "/", "100", ">=", "$", "this", "->", "_tolerance", ")", "{", "$", "grade", "=", "1", ";", "}", "else", "{", "$", "grade", "=", "0", ";", "}", "$", "proxMatch", "=", "self", "::", "checkProx", "(", "self", "::", "_iconv", "(", "$", "string", ")", ",", "self", "::", "_iconv", "(", "$", "cmp", ")", ")", ";", "$", "pctg", "=", "$", "finalScore", ">", "$", "proxMatch", "?", "$", "finalScore", ":", "$", "proxMatch", ";", "if", "(", "strstr", "(", "$", "string", ",", "' '", ")", "&&", "strstr", "(", "$", "cmp", ",", "' '", ")", ")", "{", "$", "matchWords", "=", "self", "::", "matchWords", "(", "self", "::", "_iconv", "(", "$", "string", ")", ",", "self", "::", "_iconv", "(", "$", "cmp", ")", ")", ";", "$", "pctg", "=", "$", "matchWords", ">", "$", "pctg", "?", "$", "matchWords", ":", "$", "pctg", ";", "}", "$", "finalScore", "=", "$", "pctg", ">", "$", "finalScore", "?", "$", "pctg", ":", "$", "finalScore", ";", "$", "data", "=", "array", "(", "'cost'", "=>", "$", "score", ",", "'score'", "=>", "$", "finalScore", ",", "'similar'", "=>", "$", "grade", ")", ";", "return", "$", "data", ";", "}" ]
Compare 2 strings to see how similar they are. @param string $string The first string to compare. Max length of 255 chars. @param string $cmp The second string to comapre against the first. Max length of 255 chars. @param string $language The language to make phonemes @return mixed false if $string or $cmp is empty or longer then 255 chars, the max length for a PHP levenshtein.
[ "Compare", "2", "strings", "to", "see", "how", "similar", "they", "are", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Phonetic.php#L98-L157
train
schpill/thin
src/Phonetic.php
Phonetic.phoneme
public function phoneme($string = '', $language = 'french') { $parts = explode(' ', $string); $phonemes = array(); foreach ($parts as $p) { $p = $this->partCases(Inflector::lower($p)); $phon = $this->$language($p); if ($phon != ' ' && strlen($phon)) { array_push($phonemes, $phon); } } if($this->_sort) { sort($phonemes); } $string = implode(' ', $phonemes); return $string; }
php
public function phoneme($string = '', $language = 'french') { $parts = explode(' ', $string); $phonemes = array(); foreach ($parts as $p) { $p = $this->partCases(Inflector::lower($p)); $phon = $this->$language($p); if ($phon != ' ' && strlen($phon)) { array_push($phonemes, $phon); } } if($this->_sort) { sort($phonemes); } $string = implode(' ', $phonemes); return $string; }
[ "public", "function", "phoneme", "(", "$", "string", "=", "''", ",", "$", "language", "=", "'french'", ")", "{", "$", "parts", "=", "explode", "(", "' '", ",", "$", "string", ")", ";", "$", "phonemes", "=", "array", "(", ")", ";", "foreach", "(", "$", "parts", "as", "$", "p", ")", "{", "$", "p", "=", "$", "this", "->", "partCases", "(", "Inflector", "::", "lower", "(", "$", "p", ")", ")", ";", "$", "phon", "=", "$", "this", "->", "$", "language", "(", "$", "p", ")", ";", "if", "(", "$", "phon", "!=", "' '", "&&", "strlen", "(", "$", "phon", ")", ")", "{", "array_push", "(", "$", "phonemes", ",", "$", "phon", ")", ";", "}", "}", "if", "(", "$", "this", "->", "_sort", ")", "{", "sort", "(", "$", "phonemes", ")", ";", "}", "$", "string", "=", "implode", "(", "' '", ",", "$", "phonemes", ")", ";", "return", "$", "string", ";", "}" ]
Transform a given string into its phoneme equivalent. @param string $string The string to be transformed in phonemes. @param string $language The language to make phonemes @return string Phoneme string.
[ "Transform", "a", "given", "string", "into", "its", "phoneme", "equivalent", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Phonetic.php#L178-L199
train
feelinc/laravel-api
src/Sule/Api/Resources/Collection.php
Collection.getEtags
public function getEtags() { $etag = ''; if ($this->data instanceof ArrayableInterface) { $this->data = $this->data->toArray(); } foreach ( $this->data as $item ) { $item = new Resource($item); $etag .= $item->getEtag(); unset($item); } return md5( $etag ); }
php
public function getEtags() { $etag = ''; if ($this->data instanceof ArrayableInterface) { $this->data = $this->data->toArray(); } foreach ( $this->data as $item ) { $item = new Resource($item); $etag .= $item->getEtag(); unset($item); } return md5( $etag ); }
[ "public", "function", "getEtags", "(", ")", "{", "$", "etag", "=", "''", ";", "if", "(", "$", "this", "->", "data", "instanceof", "ArrayableInterface", ")", "{", "$", "this", "->", "data", "=", "$", "this", "->", "data", "->", "toArray", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "data", "as", "$", "item", ")", "{", "$", "item", "=", "new", "Resource", "(", "$", "item", ")", ";", "$", "etag", ".=", "$", "item", "->", "getEtag", "(", ")", ";", "unset", "(", "$", "item", ")", ";", "}", "return", "md5", "(", "$", "etag", ")", ";", "}" ]
Return ETag based on collection of items @return string md5 of all ETags
[ "Return", "ETag", "based", "on", "collection", "of", "items" ]
8b4abc4f1be255b441e09f5014e863a130c666d8
https://github.com/feelinc/laravel-api/blob/8b4abc4f1be255b441e09f5014e863a130c666d8/src/Sule/Api/Resources/Collection.php#L37-L52
train
courtney-miles/schnoop-schema
src/MySQL/Routine/AbstractRoutine.php
AbstractRoutine.makeCharacteristicsDDL
protected function makeCharacteristicsDDL() { return implode( " ", array_filter( [ $this->deterministic ? 'DETERMINISTIC' : 'NOT DETERMINISTIC', $this->dataAccess, !empty($this->sqlSecurity) ? 'SQL SECURITY ' . $this->sqlSecurity : null, !empty($this->comment) ? "\nCOMMENT '" . addslashes($this->comment) . "'" : null ] ) ); }
php
protected function makeCharacteristicsDDL() { return implode( " ", array_filter( [ $this->deterministic ? 'DETERMINISTIC' : 'NOT DETERMINISTIC', $this->dataAccess, !empty($this->sqlSecurity) ? 'SQL SECURITY ' . $this->sqlSecurity : null, !empty($this->comment) ? "\nCOMMENT '" . addslashes($this->comment) . "'" : null ] ) ); }
[ "protected", "function", "makeCharacteristicsDDL", "(", ")", "{", "return", "implode", "(", "\" \"", ",", "array_filter", "(", "[", "$", "this", "->", "deterministic", "?", "'DETERMINISTIC'", ":", "'NOT DETERMINISTIC'", ",", "$", "this", "->", "dataAccess", ",", "!", "empty", "(", "$", "this", "->", "sqlSecurity", ")", "?", "'SQL SECURITY '", ".", "$", "this", "->", "sqlSecurity", ":", "null", ",", "!", "empty", "(", "$", "this", "->", "comment", ")", "?", "\"\\nCOMMENT '\"", ".", "addslashes", "(", "$", "this", "->", "comment", ")", ".", "\"'\"", ":", "null", "]", ")", ")", ";", "}" ]
Make the portion of the routine DDL statement that describes deterministic, sql security and comment. @return string Characteristics DDL.
[ "Make", "the", "portion", "of", "the", "routine", "DDL", "statement", "that", "describes", "deterministic", "sql", "security", "and", "comment", "." ]
f96e9922257860171ecdcdbb6b78182276e2f60d
https://github.com/courtney-miles/schnoop-schema/blob/f96e9922257860171ecdcdbb6b78182276e2f60d/src/MySQL/Routine/AbstractRoutine.php#L338-L351
train
valu-digital/valuso
src/ValuSo/Service/BatchService.php
BatchService.createWorker
protected function createWorker($service) { return $this->getServiceBroker() ->service($service) ->context($this->command->getContext()); }
php
protected function createWorker($service) { return $this->getServiceBroker() ->service($service) ->context($this->command->getContext()); }
[ "protected", "function", "createWorker", "(", "$", "service", ")", "{", "return", "$", "this", "->", "getServiceBroker", "(", ")", "->", "service", "(", "$", "service", ")", "->", "context", "(", "$", "this", "->", "command", "->", "getContext", "(", ")", ")", ";", "}" ]
Create service worker @return \ValuSo\Broker\Worker
[ "Create", "service", "worker" ]
c96bed0f6bd21551822334fe6cfe913a7436dd17
https://github.com/valu-digital/valuso/blob/c96bed0f6bd21551822334fe6cfe913a7436dd17/src/ValuSo/Service/BatchService.php#L159-L164
train
silvercommerce/contact-admin
src/model/ContactLocation.php
ContactLocation.onAfterWrite
public function onAfterWrite() { parent::onAfterWrite(); if ($this->Default) { foreach ($this->Contact()->Locations() as $location) { if ($location->ID != $this->ID && $location->Default) { $location->Default = false; $location->write(); } } } }
php
public function onAfterWrite() { parent::onAfterWrite(); if ($this->Default) { foreach ($this->Contact()->Locations() as $location) { if ($location->ID != $this->ID && $location->Default) { $location->Default = false; $location->write(); } } } }
[ "public", "function", "onAfterWrite", "(", ")", "{", "parent", "::", "onAfterWrite", "(", ")", ";", "if", "(", "$", "this", "->", "Default", ")", "{", "foreach", "(", "$", "this", "->", "Contact", "(", ")", "->", "Locations", "(", ")", "as", "$", "location", ")", "{", "if", "(", "$", "location", "->", "ID", "!=", "$", "this", "->", "ID", "&&", "$", "location", "->", "Default", ")", "{", "$", "location", "->", "Default", "=", "false", ";", "$", "location", "->", "write", "(", ")", ";", "}", "}", "}", "}" ]
If we have assigned this as a default location, loop through other locations and disable default. @return void
[ "If", "we", "have", "assigned", "this", "as", "a", "default", "location", "loop", "through", "other", "locations", "and", "disable", "default", "." ]
32cbc2ef2589f93f9dd1796e5db2f11ad15d888c
https://github.com/silvercommerce/contact-admin/blob/32cbc2ef2589f93f9dd1796e5db2f11ad15d888c/src/model/ContactLocation.php#L232-L244
train
PhoxPHP/Glider
src/Connection/ConnectionLoader.php
ConnectionLoader.getConnectionsFromResource
public function getConnectionsFromResource() : Array { $baseDir = dirname(__DIR__); $configLocation = $baseDir . '/config.php'; if (!file_exists($configLocation) && class_exists(Config::class)) { $resourceConfig = Config::get('database'); }else{ $resourceConfig = include $configLocation; } if (gettype($resourceConfig) !== 'array') { throw new Exception('Invalid configuration type.'); } return $resourceConfig; }
php
public function getConnectionsFromResource() : Array { $baseDir = dirname(__DIR__); $configLocation = $baseDir . '/config.php'; if (!file_exists($configLocation) && class_exists(Config::class)) { $resourceConfig = Config::get('database'); }else{ $resourceConfig = include $configLocation; } if (gettype($resourceConfig) !== 'array') { throw new Exception('Invalid configuration type.'); } return $resourceConfig; }
[ "public", "function", "getConnectionsFromResource", "(", ")", ":", "Array", "{", "$", "baseDir", "=", "dirname", "(", "__DIR__", ")", ";", "$", "configLocation", "=", "$", "baseDir", ".", "'/config.php'", ";", "if", "(", "!", "file_exists", "(", "$", "configLocation", ")", "&&", "class_exists", "(", "Config", "::", "class", ")", ")", "{", "$", "resourceConfig", "=", "Config", "::", "get", "(", "'database'", ")", ";", "}", "else", "{", "$", "resourceConfig", "=", "include", "$", "configLocation", ";", "}", "if", "(", "gettype", "(", "$", "resourceConfig", ")", "!==", "'array'", ")", "{", "throw", "new", "Exception", "(", "'Invalid configuration type.'", ")", ";", "}", "return", "$", "resourceConfig", ";", "}" ]
Loads connection configuration. @access public @return <Array>
[ "Loads", "connection", "configuration", "." ]
17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042
https://github.com/PhoxPHP/Glider/blob/17aaf3b7bb6e70ea3ae1f04e30a7690e884bf042/src/Connection/ConnectionLoader.php#L37-L53
train
zbox/UnifiedPush
src/Zbox/UnifiedPush/Dispatcher.php
Dispatcher.getConnection
public function getConnection($serviceName) { if (empty($this->connectionPool[$serviceName])) { $this->initConnection($serviceName); } return $this->connectionPool[$serviceName]; }
php
public function getConnection($serviceName) { if (empty($this->connectionPool[$serviceName])) { $this->initConnection($serviceName); } return $this->connectionPool[$serviceName]; }
[ "public", "function", "getConnection", "(", "$", "serviceName", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "connectionPool", "[", "$", "serviceName", "]", ")", ")", "{", "$", "this", "->", "initConnection", "(", "$", "serviceName", ")", ";", "}", "return", "$", "this", "->", "connectionPool", "[", "$", "serviceName", "]", ";", "}" ]
Gets a service client connection by service name @param string $serviceName @return ServiceClientInterface
[ "Gets", "a", "service", "client", "connection", "by", "service", "name" ]
47da2d0577b18ac709cd947c68541014001e1866
https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/Dispatcher.php#L100-L107
train
zbox/UnifiedPush
src/Zbox/UnifiedPush/Dispatcher.php
Dispatcher.initConnection
public function initConnection($serviceName) { $connection = $this->clientFactory->createServiceClient($serviceName); $this->connectionPool[$serviceName] = $connection; return $this; }
php
public function initConnection($serviceName) { $connection = $this->clientFactory->createServiceClient($serviceName); $this->connectionPool[$serviceName] = $connection; return $this; }
[ "public", "function", "initConnection", "(", "$", "serviceName", ")", "{", "$", "connection", "=", "$", "this", "->", "clientFactory", "->", "createServiceClient", "(", "$", "serviceName", ")", ";", "$", "this", "->", "connectionPool", "[", "$", "serviceName", "]", "=", "$", "connection", ";", "return", "$", "this", ";", "}" ]
Initialize service client connection by service name @param string $serviceName @return $this
[ "Initialize", "service", "client", "connection", "by", "service", "name" ]
47da2d0577b18ac709cd947c68541014001e1866
https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/Dispatcher.php#L115-L121
train
zbox/UnifiedPush
src/Zbox/UnifiedPush/Dispatcher.php
Dispatcher.dispatch
public function dispatch(MessageInterface $message) { $builder = $this->notificationBuilder; $notifications = $builder->buildNotifications($message); /** @var Notification $notification */ foreach ($notifications as $notification) { $this->sendNotification($notification); } return $this; }
php
public function dispatch(MessageInterface $message) { $builder = $this->notificationBuilder; $notifications = $builder->buildNotifications($message); /** @var Notification $notification */ foreach ($notifications as $notification) { $this->sendNotification($notification); } return $this; }
[ "public", "function", "dispatch", "(", "MessageInterface", "$", "message", ")", "{", "$", "builder", "=", "$", "this", "->", "notificationBuilder", ";", "$", "notifications", "=", "$", "builder", "->", "buildNotifications", "(", "$", "message", ")", ";", "/** @var Notification $notification */", "foreach", "(", "$", "notifications", "as", "$", "notification", ")", "{", "$", "this", "->", "sendNotification", "(", "$", "notification", ")", ";", "}", "return", "$", "this", ";", "}" ]
Build notification and send it to notification service @param MessageInterface $message @return $this
[ "Build", "notification", "and", "send", "it", "to", "notification", "service" ]
47da2d0577b18ac709cd947c68541014001e1866
https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/Dispatcher.php#L148-L160
train
zbox/UnifiedPush
src/Zbox/UnifiedPush/Dispatcher.php
Dispatcher.dispatchAll
public function dispatchAll(MessageCollection $messages) { $collection = $messages->getMessageCollection(); while ($collection->valid()) { $message = $collection->current(); $this->dispatch($message); $collection->next(); } return $this; }
php
public function dispatchAll(MessageCollection $messages) { $collection = $messages->getMessageCollection(); while ($collection->valid()) { $message = $collection->current(); $this->dispatch($message); $collection->next(); } return $this; }
[ "public", "function", "dispatchAll", "(", "MessageCollection", "$", "messages", ")", "{", "$", "collection", "=", "$", "messages", "->", "getMessageCollection", "(", ")", ";", "while", "(", "$", "collection", "->", "valid", "(", ")", ")", "{", "$", "message", "=", "$", "collection", "->", "current", "(", ")", ";", "$", "this", "->", "dispatch", "(", "$", "message", ")", ";", "$", "collection", "->", "next", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Tries to dispatch all messages to notification service @param MessageCollection $messages @return $this
[ "Tries", "to", "dispatch", "all", "messages", "to", "notification", "service" ]
47da2d0577b18ac709cd947c68541014001e1866
https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/Dispatcher.php#L168-L179
train
zbox/UnifiedPush
src/Zbox/UnifiedPush/Dispatcher.php
Dispatcher.sendNotification
public function sendNotification(Notification $notification) { try { $connection = $this->getConnection($notification->getType()); $connection->setNotification($notification); $this->logger->info( sprintf( "Dispatching notification id: %s", $notification->getIdentifier() ) ); $this ->responseHandler ->addIdentifiedResponse( $notification->getIdentifier(), $connection->sendRequest() ); return true; } catch (ClientException $e) { $this->logger->error( sprintf("Client connection error: %s", $e->getMessage()) ); } catch (RuntimeException $e) { $this->logger->error( sprintf("Runtime error: %s", $e->getMessage()) ); } catch (\Exception $e) { $this->logger->error( sprintf("Error occurs: %s", $e->getMessage()) ); } return false; }
php
public function sendNotification(Notification $notification) { try { $connection = $this->getConnection($notification->getType()); $connection->setNotification($notification); $this->logger->info( sprintf( "Dispatching notification id: %s", $notification->getIdentifier() ) ); $this ->responseHandler ->addIdentifiedResponse( $notification->getIdentifier(), $connection->sendRequest() ); return true; } catch (ClientException $e) { $this->logger->error( sprintf("Client connection error: %s", $e->getMessage()) ); } catch (RuntimeException $e) { $this->logger->error( sprintf("Runtime error: %s", $e->getMessage()) ); } catch (\Exception $e) { $this->logger->error( sprintf("Error occurs: %s", $e->getMessage()) ); } return false; }
[ "public", "function", "sendNotification", "(", "Notification", "$", "notification", ")", "{", "try", "{", "$", "connection", "=", "$", "this", "->", "getConnection", "(", "$", "notification", "->", "getType", "(", ")", ")", ";", "$", "connection", "->", "setNotification", "(", "$", "notification", ")", ";", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "\"Dispatching notification id: %s\"", ",", "$", "notification", "->", "getIdentifier", "(", ")", ")", ")", ";", "$", "this", "->", "responseHandler", "->", "addIdentifiedResponse", "(", "$", "notification", "->", "getIdentifier", "(", ")", ",", "$", "connection", "->", "sendRequest", "(", ")", ")", ";", "return", "true", ";", "}", "catch", "(", "ClientException", "$", "e", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "sprintf", "(", "\"Client connection error: %s\"", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "sprintf", "(", "\"Runtime error: %s\"", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "sprintf", "(", "\"Error occurs: %s\"", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "return", "false", ";", "}" ]
Tries to connect and send a notification @param Notification $notification @return bool
[ "Tries", "to", "connect", "and", "send", "a", "notification" ]
47da2d0577b18ac709cd947c68541014001e1866
https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/Dispatcher.php#L187-L226
train
zbox/UnifiedPush
src/Zbox/UnifiedPush/Dispatcher.php
Dispatcher.loadFeedback
public function loadFeedback() { $serviceName = NotificationServices::APPLE_PUSH_NOTIFICATIONS_SERVICE; try { $this->logger->info(sprintf("Querying the feedback service '%s'", $serviceName)); $connection = $this->initFeedbackConnection($serviceName); $this ->responseHandler ->addResponse( $connection->sendRequest() ); } catch (RuntimeException $e) { $this->logger->error( sprintf("Runtime error while acquiring feedback: %s", $e->getMessage()) ); } catch (\Exception $e) { $this->logger->error( sprintf("Error occurs while acquiring feedback: %s", $e->getMessage()) ); } return $this; }
php
public function loadFeedback() { $serviceName = NotificationServices::APPLE_PUSH_NOTIFICATIONS_SERVICE; try { $this->logger->info(sprintf("Querying the feedback service '%s'", $serviceName)); $connection = $this->initFeedbackConnection($serviceName); $this ->responseHandler ->addResponse( $connection->sendRequest() ); } catch (RuntimeException $e) { $this->logger->error( sprintf("Runtime error while acquiring feedback: %s", $e->getMessage()) ); } catch (\Exception $e) { $this->logger->error( sprintf("Error occurs while acquiring feedback: %s", $e->getMessage()) ); } return $this; }
[ "public", "function", "loadFeedback", "(", ")", "{", "$", "serviceName", "=", "NotificationServices", "::", "APPLE_PUSH_NOTIFICATIONS_SERVICE", ";", "try", "{", "$", "this", "->", "logger", "->", "info", "(", "sprintf", "(", "\"Querying the feedback service '%s'\"", ",", "$", "serviceName", ")", ")", ";", "$", "connection", "=", "$", "this", "->", "initFeedbackConnection", "(", "$", "serviceName", ")", ";", "$", "this", "->", "responseHandler", "->", "addResponse", "(", "$", "connection", "->", "sendRequest", "(", ")", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "sprintf", "(", "\"Runtime error while acquiring feedback: %s\"", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "sprintf", "(", "\"Error occurs while acquiring feedback: %s\"", ",", "$", "e", "->", "getMessage", "(", ")", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Tries to connect and load feedback data @return $this @throws RuntimeException @throws \Exception
[ "Tries", "to", "connect", "and", "load", "feedback", "data" ]
47da2d0577b18ac709cd947c68541014001e1866
https://github.com/zbox/UnifiedPush/blob/47da2d0577b18ac709cd947c68541014001e1866/src/Zbox/UnifiedPush/Dispatcher.php#L235-L262
train
RadialCorp/magento-core
src/app/code/community/Radial/Amqp/controllers/Exchange/System/Config/ValidateController.php
Radial_Amqp_Exchange_System_Config_ValidateController.validateamqpAction
public function validateamqpAction() { $request = $this->getRequest(); $configMap = Mage::getModel('radial_amqp/config'); $hostname = $this->_validatorHelper->getParamOrFallbackValue( $request, self::HOSTNAME_PARAM, self::HOSTNAME_USE_DEFAULT_PARAM, $configMap->getPathForKey('hostname') ); $username = $this->_validatorHelper->getParamOrFallbackValue( $request, self::USERNAME_PARAM, self::USERNAME_USE_DEFAULT_PARAM, $configMap->getPathForKey('username') ); $password = $this->_validatorHelper->getEncryptedParamOrFallbackValue( $request, self::PASSWORD_PARAM, self::PASSWORD_USE_DEFAULT_PARAM, $configMap->getPathForKey('password') ); $validator = $this->_getAmqpApiValidator($this->_getSourceStore()); $this->getResponse()->setHeader('Content-Type', 'text/json') ->setBody(json_encode($validator->testConnection($hostname, $username, $password))); return $this; }
php
public function validateamqpAction() { $request = $this->getRequest(); $configMap = Mage::getModel('radial_amqp/config'); $hostname = $this->_validatorHelper->getParamOrFallbackValue( $request, self::HOSTNAME_PARAM, self::HOSTNAME_USE_DEFAULT_PARAM, $configMap->getPathForKey('hostname') ); $username = $this->_validatorHelper->getParamOrFallbackValue( $request, self::USERNAME_PARAM, self::USERNAME_USE_DEFAULT_PARAM, $configMap->getPathForKey('username') ); $password = $this->_validatorHelper->getEncryptedParamOrFallbackValue( $request, self::PASSWORD_PARAM, self::PASSWORD_USE_DEFAULT_PARAM, $configMap->getPathForKey('password') ); $validator = $this->_getAmqpApiValidator($this->_getSourceStore()); $this->getResponse()->setHeader('Content-Type', 'text/json') ->setBody(json_encode($validator->testConnection($hostname, $username, $password))); return $this; }
[ "public", "function", "validateamqpAction", "(", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "configMap", "=", "Mage", "::", "getModel", "(", "'radial_amqp/config'", ")", ";", "$", "hostname", "=", "$", "this", "->", "_validatorHelper", "->", "getParamOrFallbackValue", "(", "$", "request", ",", "self", "::", "HOSTNAME_PARAM", ",", "self", "::", "HOSTNAME_USE_DEFAULT_PARAM", ",", "$", "configMap", "->", "getPathForKey", "(", "'hostname'", ")", ")", ";", "$", "username", "=", "$", "this", "->", "_validatorHelper", "->", "getParamOrFallbackValue", "(", "$", "request", ",", "self", "::", "USERNAME_PARAM", ",", "self", "::", "USERNAME_USE_DEFAULT_PARAM", ",", "$", "configMap", "->", "getPathForKey", "(", "'username'", ")", ")", ";", "$", "password", "=", "$", "this", "->", "_validatorHelper", "->", "getEncryptedParamOrFallbackValue", "(", "$", "request", ",", "self", "::", "PASSWORD_PARAM", ",", "self", "::", "PASSWORD_USE_DEFAULT_PARAM", ",", "$", "configMap", "->", "getPathForKey", "(", "'password'", ")", ")", ";", "$", "validator", "=", "$", "this", "->", "_getAmqpApiValidator", "(", "$", "this", "->", "_getSourceStore", "(", ")", ")", ";", "$", "this", "->", "getResponse", "(", ")", "->", "setHeader", "(", "'Content-Type'", ",", "'text/json'", ")", "->", "setBody", "(", "json_encode", "(", "$", "validator", "->", "testConnection", "(", "$", "hostname", ",", "$", "username", ",", "$", "password", ")", ")", ")", ";", "return", "$", "this", ";", "}" ]
Test connecting to the AMQP server @return self
[ "Test", "connecting", "to", "the", "AMQP", "server" ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Amqp/controllers/Exchange/System/Config/ValidateController.php#L75-L103
train
RadialCorp/magento-core
src/app/code/community/Radial/Amqp/controllers/Exchange/System/Config/ValidateController.php
Radial_Amqp_Exchange_System_Config_ValidateController._getSourceStore
protected function _getSourceStore() { // this may return a Mage_Core_Model_Store or a Mage_Core_Model_Website $configSource = $this->_validatorHelper->getConfigSource($this->getRequest()); // When given a website, get the default store for that website. // AMQP config is only at global and website level, so no *current* // possibility for the default store to have a different value than the website. if ($configSource instanceof Mage_Core_Model_Website) { return $configSource->getDefaultStore(); } return $configSource; }
php
protected function _getSourceStore() { // this may return a Mage_Core_Model_Store or a Mage_Core_Model_Website $configSource = $this->_validatorHelper->getConfigSource($this->getRequest()); // When given a website, get the default store for that website. // AMQP config is only at global and website level, so no *current* // possibility for the default store to have a different value than the website. if ($configSource instanceof Mage_Core_Model_Website) { return $configSource->getDefaultStore(); } return $configSource; }
[ "protected", "function", "_getSourceStore", "(", ")", "{", "// this may return a Mage_Core_Model_Store or a Mage_Core_Model_Website", "$", "configSource", "=", "$", "this", "->", "_validatorHelper", "->", "getConfigSource", "(", "$", "this", "->", "getRequest", "(", ")", ")", ";", "// When given a website, get the default store for that website.", "// AMQP config is only at global and website level, so no *current*", "// possibility for the default store to have a different value than the website.", "if", "(", "$", "configSource", "instanceof", "Mage_Core_Model_Website", ")", "{", "return", "$", "configSource", "->", "getDefaultStore", "(", ")", ";", "}", "return", "$", "configSource", ";", "}" ]
Get a store context to use as the source of configuration. @return Mage_Core_Model_Store
[ "Get", "a", "store", "context", "to", "use", "as", "the", "source", "of", "configuration", "." ]
9bb5f218d9caf79eab8598f4f8447037a0cc6355
https://github.com/RadialCorp/magento-core/blob/9bb5f218d9caf79eab8598f4f8447037a0cc6355/src/app/code/community/Radial/Amqp/controllers/Exchange/System/Config/ValidateController.php#L108-L119
train
romaricdrigon/OrchestraBundle
Core/Entity/Action/EntityActionBuilder.php
EntityActionBuilder.buildName
protected function buildName($name) { $name = preg_replace('/([A-Z]{1})/', ' $1', $name); $name = ucfirst($name); return trim($name); }
php
protected function buildName($name) { $name = preg_replace('/([A-Z]{1})/', ' $1', $name); $name = ucfirst($name); return trim($name); }
[ "protected", "function", "buildName", "(", "$", "name", ")", "{", "$", "name", "=", "preg_replace", "(", "'/([A-Z]{1})/'", ",", "' $1'", ",", "$", "name", ")", ";", "$", "name", "=", "ucfirst", "(", "$", "name", ")", ";", "return", "trim", "(", "$", "name", ")", ";", "}" ]
Humanize name, adding a space before each capital @param string $name @return string
[ "Humanize", "name", "adding", "a", "space", "before", "each", "capital" ]
4abb9736fcb6b23ed08ebd14ab169867339a4785
https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Core/Entity/Action/EntityActionBuilder.php#L78-L85
train
romaricdrigon/OrchestraBundle
Core/Entity/Action/EntityActionBuilder.php
EntityActionBuilder.findCommand
protected function findCommand(\ReflectionMethod $reflectionMethod) { $parameters = $reflectionMethod->getParameters(); /** @var \ReflectionParameter $parameter */ foreach ($parameters as $parameter) { $class = $parameter->getClass(); if (null !== $class && true === $class->implementsInterface('RomaricDrigon\OrchestraBundle\Domain\Command\CommandInterface')) { return $class->getName(); } } return null; }
php
protected function findCommand(\ReflectionMethod $reflectionMethod) { $parameters = $reflectionMethod->getParameters(); /** @var \ReflectionParameter $parameter */ foreach ($parameters as $parameter) { $class = $parameter->getClass(); if (null !== $class && true === $class->implementsInterface('RomaricDrigon\OrchestraBundle\Domain\Command\CommandInterface')) { return $class->getName(); } } return null; }
[ "protected", "function", "findCommand", "(", "\\", "ReflectionMethod", "$", "reflectionMethod", ")", "{", "$", "parameters", "=", "$", "reflectionMethod", "->", "getParameters", "(", ")", ";", "/** @var \\ReflectionParameter $parameter */", "foreach", "(", "$", "parameters", "as", "$", "parameter", ")", "{", "$", "class", "=", "$", "parameter", "->", "getClass", "(", ")", ";", "if", "(", "null", "!==", "$", "class", "&&", "true", "===", "$", "class", "->", "implementsInterface", "(", "'RomaricDrigon\\OrchestraBundle\\Domain\\Command\\CommandInterface'", ")", ")", "{", "return", "$", "class", "->", "getName", "(", ")", ";", "}", "}", "return", "null", ";", "}" ]
Look if we have a parameter of type "CommandInterface", and then return its precise class name @param \ReflectionMethod $reflectionMethod @return null|string
[ "Look", "if", "we", "have", "a", "parameter", "of", "type", "CommandInterface", "and", "then", "return", "its", "precise", "class", "name" ]
4abb9736fcb6b23ed08ebd14ab169867339a4785
https://github.com/romaricdrigon/OrchestraBundle/blob/4abb9736fcb6b23ed08ebd14ab169867339a4785/Core/Entity/Action/EntityActionBuilder.php#L104-L118
train
fxpio/fxp-doctrine-console
Exception/ValidationException.php
ValidationException.buildGlobalErrors
private function buildGlobalErrors(array $errors, $msg) { if (!empty($errors)) { $msg .= sprintf('%s- errors:', PHP_EOL); foreach ($errors as $error) { $msg .= sprintf('%s - %s', PHP_EOL, $error); } } return $msg; }
php
private function buildGlobalErrors(array $errors, $msg) { if (!empty($errors)) { $msg .= sprintf('%s- errors:', PHP_EOL); foreach ($errors as $error) { $msg .= sprintf('%s - %s', PHP_EOL, $error); } } return $msg; }
[ "private", "function", "buildGlobalErrors", "(", "array", "$", "errors", ",", "$", "msg", ")", "{", "if", "(", "!", "empty", "(", "$", "errors", ")", ")", "{", "$", "msg", ".=", "sprintf", "(", "'%s- errors:'", ",", "PHP_EOL", ")", ";", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "$", "msg", ".=", "sprintf", "(", "'%s - %s'", ",", "PHP_EOL", ",", "$", "error", ")", ";", "}", "}", "return", "$", "msg", ";", "}" ]
Build the global errors and returns the exception message. @param string[] $errors The error messages @param string $msg The exception message @return string
[ "Build", "the", "global", "errors", "and", "returns", "the", "exception", "message", "." ]
2fc16d7a4eb0f247075c50de225ec2670ca5479a
https://github.com/fxpio/fxp-doctrine-console/blob/2fc16d7a4eb0f247075c50de225ec2670ca5479a/Exception/ValidationException.php#L73-L84
train
fxpio/fxp-doctrine-console
Exception/ValidationException.php
ValidationException.buildChildrenErrors
private function buildChildrenErrors(array $childrenErrors, $msg) { if (!empty($childrenErrors)) { $msg .= PHP_EOL.'- children:'; foreach ($childrenErrors as $child => $errors) { $msg .= sprintf('%s - %s', PHP_EOL, $child); $msg .= sprintf('%s - errors:', PHP_EOL); foreach ($errors as $error) { $msg .= sprintf('%s - %s', PHP_EOL, $error); } } } return $msg; }
php
private function buildChildrenErrors(array $childrenErrors, $msg) { if (!empty($childrenErrors)) { $msg .= PHP_EOL.'- children:'; foreach ($childrenErrors as $child => $errors) { $msg .= sprintf('%s - %s', PHP_EOL, $child); $msg .= sprintf('%s - errors:', PHP_EOL); foreach ($errors as $error) { $msg .= sprintf('%s - %s', PHP_EOL, $error); } } } return $msg; }
[ "private", "function", "buildChildrenErrors", "(", "array", "$", "childrenErrors", ",", "$", "msg", ")", "{", "if", "(", "!", "empty", "(", "$", "childrenErrors", ")", ")", "{", "$", "msg", ".=", "PHP_EOL", ".", "'- children:'", ";", "foreach", "(", "$", "childrenErrors", "as", "$", "child", "=>", "$", "errors", ")", "{", "$", "msg", ".=", "sprintf", "(", "'%s - %s'", ",", "PHP_EOL", ",", "$", "child", ")", ";", "$", "msg", ".=", "sprintf", "(", "'%s - errors:'", ",", "PHP_EOL", ")", ";", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "$", "msg", ".=", "sprintf", "(", "'%s - %s'", ",", "PHP_EOL", ",", "$", "error", ")", ";", "}", "}", "}", "return", "$", "msg", ";", "}" ]
Build the children errors and returns the exception message. @param array $childrenErrors The children error messages @param string $msg The exception message @return string
[ "Build", "the", "children", "errors", "and", "returns", "the", "exception", "message", "." ]
2fc16d7a4eb0f247075c50de225ec2670ca5479a
https://github.com/fxpio/fxp-doctrine-console/blob/2fc16d7a4eb0f247075c50de225ec2670ca5479a/Exception/ValidationException.php#L94-L110
train
chilimatic/chilimatic-framework
lib/database/sql/mysql/Simple.php
Simple.fetch_assoc
public function fetch_assoc($sql) { if (empty($sql)) return false; $res = $this->query($sql); $result = @mysql_fetch_assoc($res); $this->free($res); return $result; }
php
public function fetch_assoc($sql) { if (empty($sql)) return false; $res = $this->query($sql); $result = @mysql_fetch_assoc($res); $this->free($res); return $result; }
[ "public", "function", "fetch_assoc", "(", "$", "sql", ")", "{", "if", "(", "empty", "(", "$", "sql", ")", ")", "return", "false", ";", "$", "res", "=", "$", "this", "->", "query", "(", "$", "sql", ")", ";", "$", "result", "=", "@", "mysql_fetch_assoc", "(", "$", "res", ")", ";", "$", "this", "->", "free", "(", "$", "res", ")", ";", "return", "$", "result", ";", "}" ]
fetches an associative array @param $sql string @return bool array
[ "fetches", "an", "associative", "array" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/database/sql/mysql/Simple.php#L80-L90
train
chilimatic/chilimatic-framework
lib/database/sql/mysql/Simple.php
Simple.fetch_assoc_list
public function fetch_assoc_list($sql, $assign_by = null) { if (empty($sql)) return false; $result = array(); // send the query $res = $this->query($sql); if (empty($res)) return false; while (($row = @mysql_fetch_assoc($res)) !== false) { if (!empty($assign_by)) { $result[$row[$assign_by]] = $row; } elseif (!empty($assign_by) && is_array($assign_by)) { $key = ''; // for more complex keys foreach ($assign_by as $key_w) { $key = "- $row[$key_w]"; } // removes the first '- ' $key = substr($key, 2); $result[$key] = $row; } else { $result[] = $row; } } // free the ressource afterwards $this->free($res); return $result; }
php
public function fetch_assoc_list($sql, $assign_by = null) { if (empty($sql)) return false; $result = array(); // send the query $res = $this->query($sql); if (empty($res)) return false; while (($row = @mysql_fetch_assoc($res)) !== false) { if (!empty($assign_by)) { $result[$row[$assign_by]] = $row; } elseif (!empty($assign_by) && is_array($assign_by)) { $key = ''; // for more complex keys foreach ($assign_by as $key_w) { $key = "- $row[$key_w]"; } // removes the first '- ' $key = substr($key, 2); $result[$key] = $row; } else { $result[] = $row; } } // free the ressource afterwards $this->free($res); return $result; }
[ "public", "function", "fetch_assoc_list", "(", "$", "sql", ",", "$", "assign_by", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "sql", ")", ")", "return", "false", ";", "$", "result", "=", "array", "(", ")", ";", "// send the query", "$", "res", "=", "$", "this", "->", "query", "(", "$", "sql", ")", ";", "if", "(", "empty", "(", "$", "res", ")", ")", "return", "false", ";", "while", "(", "(", "$", "row", "=", "@", "mysql_fetch_assoc", "(", "$", "res", ")", ")", "!==", "false", ")", "{", "if", "(", "!", "empty", "(", "$", "assign_by", ")", ")", "{", "$", "result", "[", "$", "row", "[", "$", "assign_by", "]", "]", "=", "$", "row", ";", "}", "elseif", "(", "!", "empty", "(", "$", "assign_by", ")", "&&", "is_array", "(", "$", "assign_by", ")", ")", "{", "$", "key", "=", "''", ";", "// for more complex keys", "foreach", "(", "$", "assign_by", "as", "$", "key_w", ")", "{", "$", "key", "=", "\"- $row[$key_w]\"", ";", "}", "// removes the first '- '", "$", "key", "=", "substr", "(", "$", "key", ",", "2", ")", ";", "$", "result", "[", "$", "key", "]", "=", "$", "row", ";", "}", "else", "{", "$", "result", "[", "]", "=", "$", "row", ";", "}", "}", "// free the ressource afterwards", "$", "this", "->", "free", "(", "$", "res", ")", ";", "return", "$", "result", ";", "}" ]
simple wrapper for those lazy bastards who don't wanna control their own ressources @param $sql string @param $assign_by string @return array bool
[ "simple", "wrapper", "for", "those", "lazy", "bastards", "who", "don", "t", "wanna", "control", "their", "own", "ressources" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/database/sql/mysql/Simple.php#L102-L135
train
chilimatic/chilimatic-framework
lib/database/sql/mysql/Simple.php
Simple.fetch_object
public function fetch_object($sql) { if (empty($sql)) return false; $res = $this->query($sql); $result = @mysql_fetch_object($res); $this->free($res); return $result; }
php
public function fetch_object($sql) { if (empty($sql)) return false; $res = $this->query($sql); $result = @mysql_fetch_object($res); $this->free($res); return $result; }
[ "public", "function", "fetch_object", "(", "$", "sql", ")", "{", "if", "(", "empty", "(", "$", "sql", ")", ")", "return", "false", ";", "$", "res", "=", "$", "this", "->", "query", "(", "$", "sql", ")", ";", "$", "result", "=", "@", "mysql_fetch_object", "(", "$", "res", ")", ";", "$", "this", "->", "free", "(", "$", "res", ")", ";", "return", "$", "result", ";", "}" ]
fetches an object of the current row @param $sql string @return bool object
[ "fetches", "an", "object", "of", "the", "current", "row" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/database/sql/mysql/Simple.php#L145-L155
train
chilimatic/chilimatic-framework
lib/database/sql/mysql/Simple.php
Simple.fetch_string
public function fetch_string($sql) { if (empty($sql)) return false; $res = $this->query($sql); $row = @mysql_fetch_array($res); return (string)$row[0]; }
php
public function fetch_string($sql) { if (empty($sql)) return false; $res = $this->query($sql); $row = @mysql_fetch_array($res); return (string)$row[0]; }
[ "public", "function", "fetch_string", "(", "$", "sql", ")", "{", "if", "(", "empty", "(", "$", "sql", ")", ")", "return", "false", ";", "$", "res", "=", "$", "this", "->", "query", "(", "$", "sql", ")", ";", "$", "row", "=", "@", "mysql_fetch_array", "(", "$", "res", ")", ";", "return", "(", "string", ")", "$", "row", "[", "0", "]", ";", "}" ]
fetches a string wrapper for easy use @param $sql string @return string
[ "fetches", "a", "string", "wrapper", "for", "easy", "use" ]
8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12
https://github.com/chilimatic/chilimatic-framework/blob/8df7f12e75d75d3fd2197a58c80d39cbb4b9ff12/lib/database/sql/mysql/Simple.php#L207-L216
train
takashiki/mis
src/App.php
App.map
public function map(array $methods, $pattern, $callable) { $callable = is_string($callable) ? $this->resolveCallable($callable) : $callable; if ($callable instanceof Closure) { $callable = $callable->bindTo($this); } $route = $this->container->get('router')->map($methods, $pattern, $callable); if (is_callable([$route, 'setContainer'])) { $route->setContainer($this->container); } if (is_callable([$route, 'setOutputBuffering'])) { $route->setOutputBuffering($this->container->get('settings')['outputBuffering']); } return $route; }
php
public function map(array $methods, $pattern, $callable) { $callable = is_string($callable) ? $this->resolveCallable($callable) : $callable; if ($callable instanceof Closure) { $callable = $callable->bindTo($this); } $route = $this->container->get('router')->map($methods, $pattern, $callable); if (is_callable([$route, 'setContainer'])) { $route->setContainer($this->container); } if (is_callable([$route, 'setOutputBuffering'])) { $route->setOutputBuffering($this->container->get('settings')['outputBuffering']); } return $route; }
[ "public", "function", "map", "(", "array", "$", "methods", ",", "$", "pattern", ",", "$", "callable", ")", "{", "$", "callable", "=", "is_string", "(", "$", "callable", ")", "?", "$", "this", "->", "resolveCallable", "(", "$", "callable", ")", ":", "$", "callable", ";", "if", "(", "$", "callable", "instanceof", "Closure", ")", "{", "$", "callable", "=", "$", "callable", "->", "bindTo", "(", "$", "this", ")", ";", "}", "$", "route", "=", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "map", "(", "$", "methods", ",", "$", "pattern", ",", "$", "callable", ")", ";", "if", "(", "is_callable", "(", "[", "$", "route", ",", "'setContainer'", "]", ")", ")", "{", "$", "route", "->", "setContainer", "(", "$", "this", "->", "container", ")", ";", "}", "if", "(", "is_callable", "(", "[", "$", "route", ",", "'setOutputBuffering'", "]", ")", ")", "{", "$", "route", "->", "setOutputBuffering", "(", "$", "this", "->", "container", "->", "get", "(", "'settings'", ")", "[", "'outputBuffering'", "]", ")", ";", "}", "return", "$", "route", ";", "}" ]
Add route with multiple methods. @param string[] $methods Numeric array of HTTP method names @param string $pattern The route URI pattern @param mixed $callable The route callback routine @return RouteInterface
[ "Add", "route", "with", "multiple", "methods", "." ]
a40d228d868af4e77c6156d297086ca94b8fbac8
https://github.com/takashiki/mis/blob/a40d228d868af4e77c6156d297086ca94b8fbac8/src/App.php#L170-L187
train
takashiki/mis
src/App.php
App.group
public function group($pattern, $callable) { /** @var RouteGroup $group */ $group = $this->container->get('router')->pushGroup($pattern, $callable); $group->setContainer($this->container); $group($this); $this->container->get('router')->popGroup(); return $group; }
php
public function group($pattern, $callable) { /** @var RouteGroup $group */ $group = $this->container->get('router')->pushGroup($pattern, $callable); $group->setContainer($this->container); $group($this); $this->container->get('router')->popGroup(); return $group; }
[ "public", "function", "group", "(", "$", "pattern", ",", "$", "callable", ")", "{", "/** @var RouteGroup $group */", "$", "group", "=", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "pushGroup", "(", "$", "pattern", ",", "$", "callable", ")", ";", "$", "group", "->", "setContainer", "(", "$", "this", "->", "container", ")", ";", "$", "group", "(", "$", "this", ")", ";", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "popGroup", "(", ")", ";", "return", "$", "group", ";", "}" ]
Route Groups. This method accepts a route pattern and a callback. All route declarations in the callback will be prepended by the group(s) that it is in. @param string $pattern @param callable $callable @return RouteGroupInterface
[ "Route", "Groups", "." ]
a40d228d868af4e77c6156d297086ca94b8fbac8
https://github.com/takashiki/mis/blob/a40d228d868af4e77c6156d297086ca94b8fbac8/src/App.php#L201-L210
train
ekyna/AdminBundle
Dashboard/Dashboard.php
Dashboard.hasWidget
public function hasWidget($nameOrWidget) { $name = $nameOrWidget instanceof WidgetInterface ? $nameOrWidget->getName() : $nameOrWidget; return array_key_exists($name, $this->widgets); }
php
public function hasWidget($nameOrWidget) { $name = $nameOrWidget instanceof WidgetInterface ? $nameOrWidget->getName() : $nameOrWidget; return array_key_exists($name, $this->widgets); }
[ "public", "function", "hasWidget", "(", "$", "nameOrWidget", ")", "{", "$", "name", "=", "$", "nameOrWidget", "instanceof", "WidgetInterface", "?", "$", "nameOrWidget", "->", "getName", "(", ")", ":", "$", "nameOrWidget", ";", "return", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "widgets", ")", ";", "}" ]
Returns whether the dashboard has the widget or not. @param string|WidgetInterface $nameOrWidget @return bool
[ "Returns", "whether", "the", "dashboard", "has", "the", "widget", "or", "not", "." ]
3f58e253ae9cf651add7f3d587caec80eaea459a
https://github.com/ekyna/AdminBundle/blob/3f58e253ae9cf651add7f3d587caec80eaea459a/Dashboard/Dashboard.php#L34-L39
train
ekyna/AdminBundle
Dashboard/Dashboard.php
Dashboard.addWidget
public function addWidget(WidgetInterface $widget) { if ($this->hasWidget($widget)) { throw new \InvalidArgumentException(sprintf('Widget "%s" is already registered.', $widget->getName())); } $this->widgets[$widget->getName()] = $widget; return $this; }
php
public function addWidget(WidgetInterface $widget) { if ($this->hasWidget($widget)) { throw new \InvalidArgumentException(sprintf('Widget "%s" is already registered.', $widget->getName())); } $this->widgets[$widget->getName()] = $widget; return $this; }
[ "public", "function", "addWidget", "(", "WidgetInterface", "$", "widget", ")", "{", "if", "(", "$", "this", "->", "hasWidget", "(", "$", "widget", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Widget \"%s\" is already registered.'", ",", "$", "widget", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "this", "->", "widgets", "[", "$", "widget", "->", "getName", "(", ")", "]", "=", "$", "widget", ";", "return", "$", "this", ";", "}" ]
Adds the widget. @param WidgetInterface $widget @return Dashboard
[ "Adds", "the", "widget", "." ]
3f58e253ae9cf651add7f3d587caec80eaea459a
https://github.com/ekyna/AdminBundle/blob/3f58e253ae9cf651add7f3d587caec80eaea459a/Dashboard/Dashboard.php#L47-L56
train
schpill/thin
src/OneModel.php
OneWrapper.filter
public function filter() { $args = func_get_args(); $filter_function = array_shift($args); array_unshift($args, $this); if (method_exists($this->_class_name, $filter_function)) { return call_user_func_array([$this->_class_name, $filter_function], $args); } }
php
public function filter() { $args = func_get_args(); $filter_function = array_shift($args); array_unshift($args, $this); if (method_exists($this->_class_name, $filter_function)) { return call_user_func_array([$this->_class_name, $filter_function], $args); } }
[ "public", "function", "filter", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "filter_function", "=", "array_shift", "(", "$", "args", ")", ";", "array_unshift", "(", "$", "args", ",", "$", "this", ")", ";", "if", "(", "method_exists", "(", "$", "this", "->", "_class_name", ",", "$", "filter_function", ")", ")", "{", "return", "call_user_func_array", "(", "[", "$", "this", "->", "_class_name", ",", "$", "filter_function", "]", ",", "$", "args", ")", ";", "}", "}" ]
Add a custom filter to the method chain specified on the model class. This allows custom queries to be added to models. The filter should take an instance of the One wrapper as its first argument and return an instance of the One wrapper. Any arguments passed to this method after the name of the filter will be passed to the called filter function as arguments after the One class. @return OneWrapper
[ "Add", "a", "custom", "filter", "to", "the", "method", "chain", "specified", "on", "the", "model", "class", ".", "This", "allows", "custom", "queries", "to", "be", "added", "to", "models", ".", "The", "filter", "should", "take", "an", "instance", "of", "the", "One", "wrapper", "as", "its", "first", "argument", "and", "return", "an", "instance", "of", "the", "One", "wrapper", ".", "Any", "arguments", "passed", "to", "this", "method", "after", "the", "name", "of", "the", "filter", "will", "be", "passed", "to", "the", "called", "filter", "function", "as", "arguments", "after", "the", "One", "class", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L35-L44
train
schpill/thin
src/OneModel.php
OneWrapper.for_table
public static function for_table($table_name, $connection_name = parent::DEFAULT_CONNECTION) { self::_setupDb($connection_name); return new self($table_name, [], $connection_name); }
php
public static function for_table($table_name, $connection_name = parent::DEFAULT_CONNECTION) { self::_setupDb($connection_name); return new self($table_name, [], $connection_name); }
[ "public", "static", "function", "for_table", "(", "$", "table_name", ",", "$", "connection_name", "=", "parent", "::", "DEFAULT_CONNECTION", ")", "{", "self", "::", "_setupDb", "(", "$", "connection_name", ")", ";", "return", "new", "self", "(", "$", "table_name", ",", "[", "]", ",", "$", "connection_name", ")", ";", "}" ]
Factory method, return an instance of this class bound to the supplied table name. A repeat of content in parent::for_table, so that created class is OneWrapper, not One @param string $table_name @param string $connection_name @return OneWrapper
[ "Factory", "method", "return", "an", "instance", "of", "this", "class", "bound", "to", "the", "supplied", "table", "name", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L57-L62
train
schpill/thin
src/OneModel.php
OneWrapper._createModelInstance
protected function _createModelInstance($One) { if ($One === false) { return false; } $model = new $this->_class_name(); $model->set_one($One); return $model; }
php
protected function _createModelInstance($One) { if ($One === false) { return false; } $model = new $this->_class_name(); $model->set_one($One); return $model; }
[ "protected", "function", "_createModelInstance", "(", "$", "One", ")", "{", "if", "(", "$", "One", "===", "false", ")", "{", "return", "false", ";", "}", "$", "model", "=", "new", "$", "this", "->", "_class_name", "(", ")", ";", "$", "model", "->", "set_one", "(", "$", "One", ")", ";", "return", "$", "model", ";", "}" ]
Method to create an instance of the model class associated with this wrapper and populate it with the supplied One instance. @param One $One @return bool|Model
[ "Method", "to", "create", "an", "instance", "of", "the", "model", "class", "associated", "with", "this", "wrapper", "and", "populate", "it", "with", "the", "supplied", "One", "instance", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L72-L82
train
schpill/thin
src/OneModel.php
OneWrapper.find_many
public function find_many() { $results = parent::find_many(); foreach($results as $key => $result) { $results[$key] = $this->_createModelInstance($result); } return $results; }
php
public function find_many() { $results = parent::find_many(); foreach($results as $key => $result) { $results[$key] = $this->_createModelInstance($result); } return $results; }
[ "public", "function", "find_many", "(", ")", "{", "$", "results", "=", "parent", "::", "find_many", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "key", "=>", "$", "result", ")", "{", "$", "results", "[", "$", "key", "]", "=", "$", "this", "->", "_createModelInstance", "(", "$", "result", ")", ";", "}", "return", "$", "results", ";", "}" ]
Wrap One's find_many method to return an array of instances of the class associated with this wrapper instead of the raw One class. @return Array
[ "Wrap", "One", "s", "find_many", "method", "to", "return", "an", "array", "of", "instances", "of", "the", "class", "associated", "with", "this", "wrapper", "instead", "of", "the", "raw", "One", "class", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L104-L113
train
schpill/thin
src/OneModel.php
OneModel._hasOneOrMany
protected function _hasOneOrMany($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null) { $base_table_name = self::_getTableName(get_class($this)); $foreign_key_name = self::_buildForeignKeyName($foreign_key_name, $base_table_name); $where_value = ''; //Value of foreign_table.{$foreign_key_name} we're //looking for. Where foreign_table is the actual //database table in the associated model. if(is_null($foreign_key_name_in_current_models_table)) { //Match foreign_table.{$foreign_key_name} with the value of //{$this->_table}.{$this->id()} $where_value = $this->id(); } else { //Match foreign_table.{$foreign_key_name} with the value of //{$this->_table}.{$foreign_key_name_in_current_models_table} $where_value = $this->$foreign_key_name_in_current_models_table; } return self::factory($associated_class_name, $connection_name)->where($foreign_key_name, $where_value); }
php
protected function _hasOneOrMany($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null) { $base_table_name = self::_getTableName(get_class($this)); $foreign_key_name = self::_buildForeignKeyName($foreign_key_name, $base_table_name); $where_value = ''; //Value of foreign_table.{$foreign_key_name} we're //looking for. Where foreign_table is the actual //database table in the associated model. if(is_null($foreign_key_name_in_current_models_table)) { //Match foreign_table.{$foreign_key_name} with the value of //{$this->_table}.{$this->id()} $where_value = $this->id(); } else { //Match foreign_table.{$foreign_key_name} with the value of //{$this->_table}.{$foreign_key_name_in_current_models_table} $where_value = $this->$foreign_key_name_in_current_models_table; } return self::factory($associated_class_name, $connection_name)->where($foreign_key_name, $where_value); }
[ "protected", "function", "_hasOneOrMany", "(", "$", "associated_class_name", ",", "$", "foreign_key_name", "=", "null", ",", "$", "foreign_key_name_in_current_models_table", "=", "null", ",", "$", "connection_name", "=", "null", ")", "{", "$", "base_table_name", "=", "self", "::", "_getTableName", "(", "get_class", "(", "$", "this", ")", ")", ";", "$", "foreign_key_name", "=", "self", "::", "_buildForeignKeyName", "(", "$", "foreign_key_name", ",", "$", "base_table_name", ")", ";", "$", "where_value", "=", "''", ";", "//Value of foreign_table.{$foreign_key_name} we're", "//looking for. Where foreign_table is the actual", "//database table in the associated model.", "if", "(", "is_null", "(", "$", "foreign_key_name_in_current_models_table", ")", ")", "{", "//Match foreign_table.{$foreign_key_name} with the value of", "//{$this->_table}.{$this->id()}", "$", "where_value", "=", "$", "this", "->", "id", "(", ")", ";", "}", "else", "{", "//Match foreign_table.{$foreign_key_name} with the value of", "//{$this->_table}.{$foreign_key_name_in_current_models_table}", "$", "where_value", "=", "$", "this", "->", "$", "foreign_key_name_in_current_models_table", ";", "}", "return", "self", "::", "factory", "(", "$", "associated_class_name", ",", "$", "connection_name", ")", "->", "where", "(", "$", "foreign_key_name", ",", "$", "where_value", ")", ";", "}" ]
Internal method to construct the queries for both the has_one and has_many methods. These two types of association are identical; the only difference is whether find_one or find_many is used to complete the method chain. @param string $associated_class_name @param null|string $foreign_key_name @param null|string $foreign_key_name_in_current_models_table @param null|string $connection_name @return OneWrapper
[ "Internal", "method", "to", "construct", "the", "queries", "for", "both", "the", "has_one", "and", "has_many", "methods", ".", "These", "two", "types", "of", "association", "are", "identical", ";", "the", "only", "difference", "is", "whether", "find_one", "or", "find_many", "is", "used", "to", "complete", "the", "method", "chain", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L318-L338
train
schpill/thin
src/OneModel.php
OneModel.has_one
protected function has_one($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null) { return $this->_hasOneOrMany($associated_class_name, $foreign_key_name, $foreign_key_name_in_current_models_table, $connection_name); }
php
protected function has_one($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null) { return $this->_hasOneOrMany($associated_class_name, $foreign_key_name, $foreign_key_name_in_current_models_table, $connection_name); }
[ "protected", "function", "has_one", "(", "$", "associated_class_name", ",", "$", "foreign_key_name", "=", "null", ",", "$", "foreign_key_name_in_current_models_table", "=", "null", ",", "$", "connection_name", "=", "null", ")", "{", "return", "$", "this", "->", "_hasOneOrMany", "(", "$", "associated_class_name", ",", "$", "foreign_key_name", ",", "$", "foreign_key_name_in_current_models_table", ",", "$", "connection_name", ")", ";", "}" ]
Helper method to manage one-to-one relations where the foreign key is on the associated table. @param string $associated_class_name @param null|string $foreign_key_name @param null|string $foreign_key_name_in_current_models_table @param null|string $connection_name @return OneWrapper
[ "Helper", "method", "to", "manage", "one", "-", "to", "-", "one", "relations", "where", "the", "foreign", "key", "is", "on", "the", "associated", "table", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L350-L353
train
schpill/thin
src/OneModel.php
OneModel.has_many
protected function has_many($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null) { return $this->_hasOneOrMany($associated_class_name, $foreign_key_name, $foreign_key_name_in_current_models_table, $connection_name); }
php
protected function has_many($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null) { return $this->_hasOneOrMany($associated_class_name, $foreign_key_name, $foreign_key_name_in_current_models_table, $connection_name); }
[ "protected", "function", "has_many", "(", "$", "associated_class_name", ",", "$", "foreign_key_name", "=", "null", ",", "$", "foreign_key_name_in_current_models_table", "=", "null", ",", "$", "connection_name", "=", "null", ")", "{", "return", "$", "this", "->", "_hasOneOrMany", "(", "$", "associated_class_name", ",", "$", "foreign_key_name", ",", "$", "foreign_key_name_in_current_models_table", ",", "$", "connection_name", ")", ";", "}" ]
Helper method to manage one-to-many relations where the foreign key is on the associated table. @param string $associated_class_name @param null|string $foreign_key_name @param null|string $foreign_key_name_in_current_models_table @param null|string $connection_name @return OneWrapper
[ "Helper", "method", "to", "manage", "one", "-", "to", "-", "many", "relations", "where", "the", "foreign", "key", "is", "on", "the", "associated", "table", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L365-L368
train
schpill/thin
src/OneModel.php
OneModel.belongs_to
protected function belongs_to($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_associated_models_table = null, $connection_name = null) { $associated_table_name = self::_getTableName(self::$auto_prefix_models . $associated_class_name); $foreign_key_name = self::_buildForeignKeyName($foreign_key_name, $associated_table_name); $associated_object_id = $this->$foreign_key_name; $desired_record = null; if( is_null($foreign_key_name_in_associated_models_table) ) { //"{$associated_table_name}.primary_key = {$associated_object_id}" //NOTE: primary_key is a placeholder for the actual primary key column's name //in $associated_table_name $desired_record = self::factory($associated_class_name, $connection_name)->where_id_is($associated_object_id); } else { //"{$associated_table_name}.{$foreign_key_name_in_associated_models_table} = {$associated_object_id}" $desired_record = self::factory($associated_class_name, $connection_name)->where($foreign_key_name_in_associated_models_table, $associated_object_id); } return $desired_record; }
php
protected function belongs_to($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_associated_models_table = null, $connection_name = null) { $associated_table_name = self::_getTableName(self::$auto_prefix_models . $associated_class_name); $foreign_key_name = self::_buildForeignKeyName($foreign_key_name, $associated_table_name); $associated_object_id = $this->$foreign_key_name; $desired_record = null; if( is_null($foreign_key_name_in_associated_models_table) ) { //"{$associated_table_name}.primary_key = {$associated_object_id}" //NOTE: primary_key is a placeholder for the actual primary key column's name //in $associated_table_name $desired_record = self::factory($associated_class_name, $connection_name)->where_id_is($associated_object_id); } else { //"{$associated_table_name}.{$foreign_key_name_in_associated_models_table} = {$associated_object_id}" $desired_record = self::factory($associated_class_name, $connection_name)->where($foreign_key_name_in_associated_models_table, $associated_object_id); } return $desired_record; }
[ "protected", "function", "belongs_to", "(", "$", "associated_class_name", ",", "$", "foreign_key_name", "=", "null", ",", "$", "foreign_key_name_in_associated_models_table", "=", "null", ",", "$", "connection_name", "=", "null", ")", "{", "$", "associated_table_name", "=", "self", "::", "_getTableName", "(", "self", "::", "$", "auto_prefix_models", ".", "$", "associated_class_name", ")", ";", "$", "foreign_key_name", "=", "self", "::", "_buildForeignKeyName", "(", "$", "foreign_key_name", ",", "$", "associated_table_name", ")", ";", "$", "associated_object_id", "=", "$", "this", "->", "$", "foreign_key_name", ";", "$", "desired_record", "=", "null", ";", "if", "(", "is_null", "(", "$", "foreign_key_name_in_associated_models_table", ")", ")", "{", "//\"{$associated_table_name}.primary_key = {$associated_object_id}\"", "//NOTE: primary_key is a placeholder for the actual primary key column's name", "//in $associated_table_name", "$", "desired_record", "=", "self", "::", "factory", "(", "$", "associated_class_name", ",", "$", "connection_name", ")", "->", "where_id_is", "(", "$", "associated_object_id", ")", ";", "}", "else", "{", "//\"{$associated_table_name}.{$foreign_key_name_in_associated_models_table} = {$associated_object_id}\"", "$", "desired_record", "=", "self", "::", "factory", "(", "$", "associated_class_name", ",", "$", "connection_name", ")", "->", "where", "(", "$", "foreign_key_name_in_associated_models_table", ",", "$", "associated_object_id", ")", ";", "}", "return", "$", "desired_record", ";", "}" ]
Helper method to manage one-to-one and one-to-many relations where the foreign key is on the base table. @param string $associated_class_name @param null|string $foreign_key_name @param null|string $foreign_key_name_in_associated_models_table @param null|string $connection_name @return $this|null
[ "Helper", "method", "to", "manage", "one", "-", "to", "-", "one", "and", "one", "-", "to", "-", "many", "relations", "where", "the", "foreign", "key", "is", "on", "the", "base", "table", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L380-L399
train
schpill/thin
src/OneModel.php
OneModel.has_many_through
protected function has_many_through($associated_class_name, $join_class_name = null, $key_to_base_table = null, $key_to_associated_table = null, $key_in_base_table = null, $key_in_associated_table = null, $connection_name = null) { $base_class_name = get_class($this); // The class name of the join model, if not supplied, is // fOneed by concatenating the names of the base class // and the associated class, in alphabetical order. if (is_null($join_class_name)) { $model = explode('\\', $base_class_name); $model_name = end($model); if (substr($model_name, 0, strlen(self::$auto_prefix_models)) == self::$auto_prefix_models) { $model_name = substr($model_name, strlen(self::$auto_prefix_models), strlen($model_name)); } $class_names = [$model_name, $associated_class_name]; sort($class_names, SORT_STRING); $join_class_name = join("", $class_names); } // Get table names for each class $base_table_name = self::_getTableName($base_class_name); $associated_table_name = self::_getTableName(self::$auto_prefix_models . $associated_class_name); $join_table_name = self::_getTableName(self::$auto_prefix_models . $join_class_name); // Get ID column names $base_table_id_column = (is_null($key_in_base_table)) ? self::_getIdColumnName($base_class_name) : $key_in_base_table; $associated_table_id_column = (is_null($key_in_associated_table)) ? self::_getIdColumnName(self::$auto_prefix_models . $associated_class_name) : $key_in_associated_table; // Get the column names for each side of the join table $key_to_base_table = self::_buildForeignKeyName($key_to_base_table, $base_table_name); $key_to_associated_table = self::_buildForeignKeyName($key_to_associated_table, $associated_table_name); /* " SELECT {$associated_table_name}.* FROM {$associated_table_name} JOIN {$join_table_name} ON {$associated_table_name}.{$associated_table_id_column} = {$join_table_name}.{$key_to_associated_table} WHERE {$join_table_name}.{$key_to_base_table} = {$this->$base_table_id_column} ;" */ return self::factory($associated_class_name, $connection_name) ->select("{$associated_table_name}.*") ->join($join_table_name, ["{$associated_table_name}.{$associated_table_id_column}", '=', "{$join_table_name}.{$key_to_associated_table}"]) ->where("{$join_table_name}.{$key_to_base_table}", $this->$base_table_id_column); }
php
protected function has_many_through($associated_class_name, $join_class_name = null, $key_to_base_table = null, $key_to_associated_table = null, $key_in_base_table = null, $key_in_associated_table = null, $connection_name = null) { $base_class_name = get_class($this); // The class name of the join model, if not supplied, is // fOneed by concatenating the names of the base class // and the associated class, in alphabetical order. if (is_null($join_class_name)) { $model = explode('\\', $base_class_name); $model_name = end($model); if (substr($model_name, 0, strlen(self::$auto_prefix_models)) == self::$auto_prefix_models) { $model_name = substr($model_name, strlen(self::$auto_prefix_models), strlen($model_name)); } $class_names = [$model_name, $associated_class_name]; sort($class_names, SORT_STRING); $join_class_name = join("", $class_names); } // Get table names for each class $base_table_name = self::_getTableName($base_class_name); $associated_table_name = self::_getTableName(self::$auto_prefix_models . $associated_class_name); $join_table_name = self::_getTableName(self::$auto_prefix_models . $join_class_name); // Get ID column names $base_table_id_column = (is_null($key_in_base_table)) ? self::_getIdColumnName($base_class_name) : $key_in_base_table; $associated_table_id_column = (is_null($key_in_associated_table)) ? self::_getIdColumnName(self::$auto_prefix_models . $associated_class_name) : $key_in_associated_table; // Get the column names for each side of the join table $key_to_base_table = self::_buildForeignKeyName($key_to_base_table, $base_table_name); $key_to_associated_table = self::_buildForeignKeyName($key_to_associated_table, $associated_table_name); /* " SELECT {$associated_table_name}.* FROM {$associated_table_name} JOIN {$join_table_name} ON {$associated_table_name}.{$associated_table_id_column} = {$join_table_name}.{$key_to_associated_table} WHERE {$join_table_name}.{$key_to_base_table} = {$this->$base_table_id_column} ;" */ return self::factory($associated_class_name, $connection_name) ->select("{$associated_table_name}.*") ->join($join_table_name, ["{$associated_table_name}.{$associated_table_id_column}", '=', "{$join_table_name}.{$key_to_associated_table}"]) ->where("{$join_table_name}.{$key_to_base_table}", $this->$base_table_id_column); }
[ "protected", "function", "has_many_through", "(", "$", "associated_class_name", ",", "$", "join_class_name", "=", "null", ",", "$", "key_to_base_table", "=", "null", ",", "$", "key_to_associated_table", "=", "null", ",", "$", "key_in_base_table", "=", "null", ",", "$", "key_in_associated_table", "=", "null", ",", "$", "connection_name", "=", "null", ")", "{", "$", "base_class_name", "=", "get_class", "(", "$", "this", ")", ";", "// The class name of the join model, if not supplied, is", "// fOneed by concatenating the names of the base class", "// and the associated class, in alphabetical order.", "if", "(", "is_null", "(", "$", "join_class_name", ")", ")", "{", "$", "model", "=", "explode", "(", "'\\\\'", ",", "$", "base_class_name", ")", ";", "$", "model_name", "=", "end", "(", "$", "model", ")", ";", "if", "(", "substr", "(", "$", "model_name", ",", "0", ",", "strlen", "(", "self", "::", "$", "auto_prefix_models", ")", ")", "==", "self", "::", "$", "auto_prefix_models", ")", "{", "$", "model_name", "=", "substr", "(", "$", "model_name", ",", "strlen", "(", "self", "::", "$", "auto_prefix_models", ")", ",", "strlen", "(", "$", "model_name", ")", ")", ";", "}", "$", "class_names", "=", "[", "$", "model_name", ",", "$", "associated_class_name", "]", ";", "sort", "(", "$", "class_names", ",", "SORT_STRING", ")", ";", "$", "join_class_name", "=", "join", "(", "\"\"", ",", "$", "class_names", ")", ";", "}", "// Get table names for each class", "$", "base_table_name", "=", "self", "::", "_getTableName", "(", "$", "base_class_name", ")", ";", "$", "associated_table_name", "=", "self", "::", "_getTableName", "(", "self", "::", "$", "auto_prefix_models", ".", "$", "associated_class_name", ")", ";", "$", "join_table_name", "=", "self", "::", "_getTableName", "(", "self", "::", "$", "auto_prefix_models", ".", "$", "join_class_name", ")", ";", "// Get ID column names", "$", "base_table_id_column", "=", "(", "is_null", "(", "$", "key_in_base_table", ")", ")", "?", "self", "::", "_getIdColumnName", "(", "$", "base_class_name", ")", ":", "$", "key_in_base_table", ";", "$", "associated_table_id_column", "=", "(", "is_null", "(", "$", "key_in_associated_table", ")", ")", "?", "self", "::", "_getIdColumnName", "(", "self", "::", "$", "auto_prefix_models", ".", "$", "associated_class_name", ")", ":", "$", "key_in_associated_table", ";", "// Get the column names for each side of the join table", "$", "key_to_base_table", "=", "self", "::", "_buildForeignKeyName", "(", "$", "key_to_base_table", ",", "$", "base_table_name", ")", ";", "$", "key_to_associated_table", "=", "self", "::", "_buildForeignKeyName", "(", "$", "key_to_associated_table", ",", "$", "associated_table_name", ")", ";", "/*\n \" SELECT {$associated_table_name}.*\n FROM {$associated_table_name} JOIN {$join_table_name}\n ON {$associated_table_name}.{$associated_table_id_column} = {$join_table_name}.{$key_to_associated_table}\n WHERE {$join_table_name}.{$key_to_base_table} = {$this->$base_table_id_column} ;\"\n */", "return", "self", "::", "factory", "(", "$", "associated_class_name", ",", "$", "connection_name", ")", "->", "select", "(", "\"{$associated_table_name}.*\"", ")", "->", "join", "(", "$", "join_table_name", ",", "[", "\"{$associated_table_name}.{$associated_table_id_column}\"", ",", "'='", ",", "\"{$join_table_name}.{$key_to_associated_table}\"", "]", ")", "->", "where", "(", "\"{$join_table_name}.{$key_to_base_table}\"", ",", "$", "this", "->", "$", "base_table_id_column", ")", ";", "}" ]
Helper method to manage many-to-many relationships via an intermediate model. See README for a full explanation of the parameters. @param string $associated_class_name @param null|string $join_class_name @param null|string $key_to_base_table @param null|string $key_to_associated_table @param null|string $key_in_base_table @param null|string $key_in_associated_table @param null|string $connection_name @return OneWrapper
[ "Helper", "method", "to", "manage", "many", "-", "to", "-", "many", "relationships", "via", "an", "intermediate", "model", ".", "See", "README", "for", "a", "full", "explanation", "of", "the", "parameters", "." ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/OneModel.php#L414-L462
train
3ev/wordpress-core
src/Tev/Field/Factory.php
Factory.create
public function create($field, AbstractPost $post) { $data = get_field_object($field, $post->getId()); return $this->createFromField($data); }
php
public function create($field, AbstractPost $post) { $data = get_field_object($field, $post->getId()); return $this->createFromField($data); }
[ "public", "function", "create", "(", "$", "field", ",", "AbstractPost", "$", "post", ")", "{", "$", "data", "=", "get_field_object", "(", "$", "field", ",", "$", "post", "->", "getId", "(", ")", ")", ";", "return", "$", "this", "->", "createFromField", "(", "$", "data", ")", ";", "}" ]
Create a new custom field object. If the field is not registered, a `\Tev\Field\Model\NullField` will be returned. @param string $field Field name or ID @param \Tev\Post\Model\AbstractPost $post Post object field is for @return \Tev\Field\Model\AbstractField Field object @throws \Exception If field type is not registered
[ "Create", "a", "new", "custom", "field", "object", "." ]
da674fbec5bf3d5bd2a2141680a4c141113eb6b0
https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Field/Factory.php#L97-L102
train
3ev/wordpress-core
src/Tev/Field/Factory.php
Factory.createFromField
public function createFromField($field, $value = null) { if (!is_array($field)) { return new NullField; } if ($value !== null) { $field['value'] = $value; } return $this->resolve($field['type'], $field); }
php
public function createFromField($field, $value = null) { if (!is_array($field)) { return new NullField; } if ($value !== null) { $field['value'] = $value; } return $this->resolve($field['type'], $field); }
[ "public", "function", "createFromField", "(", "$", "field", ",", "$", "value", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "field", ")", ")", "{", "return", "new", "NullField", ";", "}", "if", "(", "$", "value", "!==", "null", ")", "{", "$", "field", "[", "'value'", "]", "=", "$", "value", ";", "}", "return", "$", "this", "->", "resolve", "(", "$", "field", "[", "'type'", "]", ",", "$", "field", ")", ";", "}" ]
Create a new custom field object from an existing set of field data. If the field is not registered, a `\Tev\Field\Model\NullField` will be returned. @param array $field Field data array @param mixed $value If supplied, will be set as the fields value @return \Tev\Field\Model\AbstractField Field object @throws \Exception If field type is not registered
[ "Create", "a", "new", "custom", "field", "object", "from", "an", "existing", "set", "of", "field", "data", "." ]
da674fbec5bf3d5bd2a2141680a4c141113eb6b0
https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Field/Factory.php#L116-L127
train
3ev/wordpress-core
src/Tev/Field/Factory.php
Factory.resolve
protected function resolve($type, array $data) { if ($this->registered($type)) { $f = $this->registry[$type]; if ($f instanceof Closure) { return $f($data, $this->app); } else { return new $f($data); } } else { throw new Exception("Field type $type not registered"); } }
php
protected function resolve($type, array $data) { if ($this->registered($type)) { $f = $this->registry[$type]; if ($f instanceof Closure) { return $f($data, $this->app); } else { return new $f($data); } } else { throw new Exception("Field type $type not registered"); } }
[ "protected", "function", "resolve", "(", "$", "type", ",", "array", "$", "data", ")", "{", "if", "(", "$", "this", "->", "registered", "(", "$", "type", ")", ")", "{", "$", "f", "=", "$", "this", "->", "registry", "[", "$", "type", "]", ";", "if", "(", "$", "f", "instanceof", "Closure", ")", "{", "return", "$", "f", "(", "$", "data", ",", "$", "this", "->", "app", ")", ";", "}", "else", "{", "return", "new", "$", "f", "(", "$", "data", ")", ";", "}", "}", "else", "{", "throw", "new", "Exception", "(", "\"Field type $type not registered\"", ")", ";", "}", "}" ]
Resolve a field object using its type, from the registered factory functions. @param string $type Field type @param array $data Field data @return \Tev\Field\Model\AbstractField Field object @throws \Exception If field type is not registered
[ "Resolve", "a", "field", "object", "using", "its", "type", "from", "the", "registered", "factory", "functions", "." ]
da674fbec5bf3d5bd2a2141680a4c141113eb6b0
https://github.com/3ev/wordpress-core/blob/da674fbec5bf3d5bd2a2141680a4c141113eb6b0/src/Tev/Field/Factory.php#L153-L165
train
pmdevelopment/tool-bundle
Framework/Configuration/FontAwesomeConfig.php
FontAwesomeConfig.getClasses
public static function getClasses($version) { if (false === in_array($version, self::getVersions())) { throw new \LogicException(sprintf("Version is not supported. Available: %s", implode(", ", self::getVersions()))); } $version = explode(".", $version); $subVersion = $version[1]; $icons = array(); /** * 4.4.0 Icons */ if (4 <= $subVersion) { $icons = FontAwesome\Version440::getIconsAll(); } return $icons; }
php
public static function getClasses($version) { if (false === in_array($version, self::getVersions())) { throw new \LogicException(sprintf("Version is not supported. Available: %s", implode(", ", self::getVersions()))); } $version = explode(".", $version); $subVersion = $version[1]; $icons = array(); /** * 4.4.0 Icons */ if (4 <= $subVersion) { $icons = FontAwesome\Version440::getIconsAll(); } return $icons; }
[ "public", "static", "function", "getClasses", "(", "$", "version", ")", "{", "if", "(", "false", "===", "in_array", "(", "$", "version", ",", "self", "::", "getVersions", "(", ")", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "\"Version is not supported. Available: %s\"", ",", "implode", "(", "\", \"", ",", "self", "::", "getVersions", "(", ")", ")", ")", ")", ";", "}", "$", "version", "=", "explode", "(", "\".\"", ",", "$", "version", ")", ";", "$", "subVersion", "=", "$", "version", "[", "1", "]", ";", "$", "icons", "=", "array", "(", ")", ";", "/**\n * 4.4.0 Icons\n */", "if", "(", "4", "<=", "$", "subVersion", ")", "{", "$", "icons", "=", "FontAwesome", "\\", "Version440", "::", "getIconsAll", "(", ")", ";", "}", "return", "$", "icons", ";", "}" ]
Get Icon Classes @param string $version @return array
[ "Get", "Icon", "Classes" ]
2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129
https://github.com/pmdevelopment/tool-bundle/blob/2cbc9f82c5b33fd7a9d389edd3676e9f70ea8129/Framework/Configuration/FontAwesomeConfig.php#L40-L59
train
phavour/phavour
Phavour/Session/Storage.php
Storage.lock
public function lock() { $this->_validate(); $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = true; return true; }
php
public function lock() { $this->_validate(); $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = true; return true; }
[ "public", "function", "lock", "(", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", "[", "$", "this", "->", "_namespaceName", "]", "=", "true", ";", "return", "true", ";", "}" ]
Lock the namespace, this will prevent removal of keys @return boolean @throws \Exception
[ "Lock", "the", "namespace", "this", "will", "prevent", "removal", "of", "keys" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L102-L107
train
phavour/phavour
Phavour/Session/Storage.php
Storage.unlock
public function unlock() { $this->_validate(); $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = false; return true; }
php
public function unlock() { $this->_validate(); $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = false; return true; }
[ "public", "function", "unlock", "(", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", "[", "$", "this", "->", "_namespaceName", "]", "=", "false", ";", "return", "true", ";", "}" ]
Unlock the namespace, this will allow removal of keys @return boolean @throws \Exception
[ "Unlock", "the", "namespace", "this", "will", "allow", "removal", "of", "keys" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L115-L120
train
phavour/phavour
Phavour/Session/Storage.php
Storage.isLocked
public function isLocked() { $this->_validate(); if ($_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] == true) { return true; } return false; }
php
public function isLocked() { $this->_validate(); if ($_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] == true) { return true; } return false; }
[ "public", "function", "isLocked", "(", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "if", "(", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", "[", "$", "this", "->", "_namespaceName", "]", "==", "true", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if a namespace is currently locked. @return boolean @throws \Exception
[ "Check", "if", "a", "namespace", "is", "currently", "locked", "." ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L128-L135
train
phavour/phavour
Phavour/Session/Storage.php
Storage.set
public function set($name, $value) { if (!$this->isLocked()) { $_SESSION[$this->publicStorage]['store'][$this->_namespaceName][$name] = $value; return true; } return false; }
php
public function set($name, $value) { if (!$this->isLocked()) { $_SESSION[$this->publicStorage]['store'][$this->_namespaceName][$name] = $value; return true; } return false; }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "isLocked", "(", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", "[", "$", "name", "]", "=", "$", "value", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Set a value in the current namespace @param string $name @param mixed $value @return boolean result of save @throws \Exception
[ "Set", "a", "value", "in", "the", "current", "namespace" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L145-L152
train
phavour/phavour
Phavour/Session/Storage.php
Storage.get
public function get($name) { $this->_validate(); if (array_key_exists($name, $_SESSION[$this->publicStorage]['store'][$this->_namespaceName])) { return $_SESSION[$this->publicStorage]['store'][$this->_namespaceName][$name]; } return false; }
php
public function get($name) { $this->_validate(); if (array_key_exists($name, $_SESSION[$this->publicStorage]['store'][$this->_namespaceName])) { return $_SESSION[$this->publicStorage]['store'][$this->_namespaceName][$name]; } return false; }
[ "public", "function", "get", "(", "$", "name", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", ")", ")", "{", "return", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", "[", "$", "name", "]", ";", "}", "return", "false", ";", "}" ]
Retrieve a single value from the namespace @param string $name @return mixed @throws \Exception
[ "Retrieve", "a", "single", "value", "from", "the", "namespace" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L161-L168
train
phavour/phavour
Phavour/Session/Storage.php
Storage.getAll
public function getAll() { $this->_validate(); if (array_key_exists($this->_namespaceName, $_SESSION[$this->publicStorage]['store'])) { return $_SESSION[$this->publicStorage]['store'][$this->_namespaceName]; } return false; }
php
public function getAll() { $this->_validate(); if (array_key_exists($this->_namespaceName, $_SESSION[$this->publicStorage]['store'])) { return $_SESSION[$this->publicStorage]['store'][$this->_namespaceName]; } return false; }
[ "public", "function", "getAll", "(", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "this", "->", "_namespaceName", ",", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", ")", ")", "{", "return", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", ";", "}", "return", "false", ";", "}" ]
Retrieve the entire namespace @return array success | boolean false failure @throws \Exception
[ "Retrieve", "the", "entire", "namespace" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L176-L183
train
phavour/phavour
Phavour/Session/Storage.php
Storage.remove
public function remove($name) { $this->_validate(); if (!$this->isLocked()) { if (!$this->get($name)) { return true; } unset($_SESSION[$this->publicStorage]['store'][$this->_namespaceName][$name]); return true; } return false; }
php
public function remove($name) { $this->_validate(); if (!$this->isLocked()) { if (!$this->get($name)) { return true; } unset($_SESSION[$this->publicStorage]['store'][$this->_namespaceName][$name]); return true; } return false; }
[ "public", "function", "remove", "(", "$", "name", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "if", "(", "!", "$", "this", "->", "isLocked", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "get", "(", "$", "name", ")", ")", "{", "return", "true", ";", "}", "unset", "(", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", "[", "$", "name", "]", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Remove an key from the namespace @param string $name @return boolean result of removal @throws \Exception
[ "Remove", "an", "key", "from", "the", "namespace" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L192-L203
train
phavour/phavour
Phavour/Session/Storage.php
Storage.removeAll
public function removeAll() { $this->_validate(); if (!$this->isLocked()) { $_SESSION[$this->publicStorage]['store'][$this->_namespaceName] = array(); return true; } return false; }
php
public function removeAll() { $this->_validate(); if (!$this->isLocked()) { $_SESSION[$this->publicStorage]['store'][$this->_namespaceName] = array(); return true; } return false; }
[ "public", "function", "removeAll", "(", ")", "{", "$", "this", "->", "_validate", "(", ")", ";", "if", "(", "!", "$", "this", "->", "isLocked", "(", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", "=", "array", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Clear all values currently held in this namespace @return boolean status of removal @throws \Exception
[ "Clear", "all", "values", "currently", "held", "in", "this", "namespace" ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L211-L219
train
phavour/phavour
Phavour/Session/Storage.php
Storage.setup
protected function setup() { if (array_key_exists($this->secretStorage, $_SESSION)) { if (!is_array($_SESSION[$this->secretStorage])) { $_SESSION[$this->secretStorage] = array('locks' => array($this->_namespaceName => false)); } else { if (!array_key_exists($this->_namespaceName, $_SESSION[$this->secretStorage]['locks'])) { $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = false; } else { if (!is_bool($_SESSION[$this->secretStorage]['locks'][$this->_namespaceName])) { $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = false; } } } } else { $_SESSION[$this->secretStorage] = array('locks' => array($this->_namespaceName => false)); } if (array_key_exists($this->publicStorage, $_SESSION)) { if (array_key_exists('store', $_SESSION[$this->publicStorage])) { if (!array_key_exists($this->_namespaceName, $_SESSION[$this->publicStorage]['store'])) { $_SESSION[$this->publicStorage]['store'][$this->_namespaceName] = array(); } } else { $_SESSION[$this->publicStorage]['store'] = array($this->_namespaceName => array()); } } else { $_SESSION[$this->publicStorage] = array('store' => array($this->_namespaceName => array())); } return true; }
php
protected function setup() { if (array_key_exists($this->secretStorage, $_SESSION)) { if (!is_array($_SESSION[$this->secretStorage])) { $_SESSION[$this->secretStorage] = array('locks' => array($this->_namespaceName => false)); } else { if (!array_key_exists($this->_namespaceName, $_SESSION[$this->secretStorage]['locks'])) { $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = false; } else { if (!is_bool($_SESSION[$this->secretStorage]['locks'][$this->_namespaceName])) { $_SESSION[$this->secretStorage]['locks'][$this->_namespaceName] = false; } } } } else { $_SESSION[$this->secretStorage] = array('locks' => array($this->_namespaceName => false)); } if (array_key_exists($this->publicStorage, $_SESSION)) { if (array_key_exists('store', $_SESSION[$this->publicStorage])) { if (!array_key_exists($this->_namespaceName, $_SESSION[$this->publicStorage]['store'])) { $_SESSION[$this->publicStorage]['store'][$this->_namespaceName] = array(); } } else { $_SESSION[$this->publicStorage]['store'] = array($this->_namespaceName => array()); } } else { $_SESSION[$this->publicStorage] = array('store' => array($this->_namespaceName => array())); } return true; }
[ "protected", "function", "setup", "(", ")", "{", "if", "(", "array_key_exists", "(", "$", "this", "->", "secretStorage", ",", "$", "_SESSION", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "=", "array", "(", "'locks'", "=>", "array", "(", "$", "this", "->", "_namespaceName", "=>", "false", ")", ")", ";", "}", "else", "{", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "_namespaceName", ",", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", "[", "$", "this", "->", "_namespaceName", "]", "=", "false", ";", "}", "else", "{", "if", "(", "!", "is_bool", "(", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", "[", "$", "this", "->", "_namespaceName", "]", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "[", "'locks'", "]", "[", "$", "this", "->", "_namespaceName", "]", "=", "false", ";", "}", "}", "}", "}", "else", "{", "$", "_SESSION", "[", "$", "this", "->", "secretStorage", "]", "=", "array", "(", "'locks'", "=>", "array", "(", "$", "this", "->", "_namespaceName", "=>", "false", ")", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "this", "->", "publicStorage", ",", "$", "_SESSION", ")", ")", "{", "if", "(", "array_key_exists", "(", "'store'", ",", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", ")", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "_namespaceName", ",", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", ")", ")", "{", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "[", "$", "this", "->", "_namespaceName", "]", "=", "array", "(", ")", ";", "}", "}", "else", "{", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "[", "'store'", "]", "=", "array", "(", "$", "this", "->", "_namespaceName", "=>", "array", "(", ")", ")", ";", "}", "}", "else", "{", "$", "_SESSION", "[", "$", "this", "->", "publicStorage", "]", "=", "array", "(", "'store'", "=>", "array", "(", "$", "this", "->", "_namespaceName", "=>", "array", "(", ")", ")", ")", ";", "}", "return", "true", ";", "}" ]
Ensure the session contains the data we expect to see. @return boolean
[ "Ensure", "the", "session", "contains", "the", "data", "we", "expect", "to", "see", "." ]
2246f78203312eb2e23fdb0f776f790e81b4d20f
https://github.com/phavour/phavour/blob/2246f78203312eb2e23fdb0f776f790e81b4d20f/Phavour/Session/Storage.php#L243-L274
train
kiler129/TinyWs
src/NetworkFrame.php
NetworkFrame.collectPayload
private function collectPayload() { if ($this->payloadLength === 0) { $this->logger->debug("Skipping payload collection [expected length === 0]"); return true; } $this->logger->debug("Trying to collect payload..."); if (!$this->headersCollected) { throw new LogicException("Cannot collect payload before headers!"); } $payloadData = substr($this->buffer, 0, $this->remainingPayloadBytes); $payloadDataLen = strlen($payloadData); $this->buffer = substr($this->buffer, $payloadDataLen); $this->remainingPayloadBytes -= $payloadDataLen; $this->payload .= $payloadData; $this->logger->debug("Got $payloadDataLen bytes of payload, " . $this->remainingPayloadBytes . " left"); if ($this->remainingPayloadBytes === 0 && ($this->secondFrameByte & 128)) { //Unmask after full payload is received $this->logger->debug("Unmasking payload"); $this->payload = $this->getMaskedPayload(); return true; } return ($this->remainingPayloadBytes === 0); }
php
private function collectPayload() { if ($this->payloadLength === 0) { $this->logger->debug("Skipping payload collection [expected length === 0]"); return true; } $this->logger->debug("Trying to collect payload..."); if (!$this->headersCollected) { throw new LogicException("Cannot collect payload before headers!"); } $payloadData = substr($this->buffer, 0, $this->remainingPayloadBytes); $payloadDataLen = strlen($payloadData); $this->buffer = substr($this->buffer, $payloadDataLen); $this->remainingPayloadBytes -= $payloadDataLen; $this->payload .= $payloadData; $this->logger->debug("Got $payloadDataLen bytes of payload, " . $this->remainingPayloadBytes . " left"); if ($this->remainingPayloadBytes === 0 && ($this->secondFrameByte & 128)) { //Unmask after full payload is received $this->logger->debug("Unmasking payload"); $this->payload = $this->getMaskedPayload(); return true; } return ($this->remainingPayloadBytes === 0); }
[ "private", "function", "collectPayload", "(", ")", "{", "if", "(", "$", "this", "->", "payloadLength", "===", "0", ")", "{", "$", "this", "->", "logger", "->", "debug", "(", "\"Skipping payload collection [expected length === 0]\"", ")", ";", "return", "true", ";", "}", "$", "this", "->", "logger", "->", "debug", "(", "\"Trying to collect payload...\"", ")", ";", "if", "(", "!", "$", "this", "->", "headersCollected", ")", "{", "throw", "new", "LogicException", "(", "\"Cannot collect payload before headers!\"", ")", ";", "}", "$", "payloadData", "=", "substr", "(", "$", "this", "->", "buffer", ",", "0", ",", "$", "this", "->", "remainingPayloadBytes", ")", ";", "$", "payloadDataLen", "=", "strlen", "(", "$", "payloadData", ")", ";", "$", "this", "->", "buffer", "=", "substr", "(", "$", "this", "->", "buffer", ",", "$", "payloadDataLen", ")", ";", "$", "this", "->", "remainingPayloadBytes", "-=", "$", "payloadDataLen", ";", "$", "this", "->", "payload", ".=", "$", "payloadData", ";", "$", "this", "->", "logger", "->", "debug", "(", "\"Got $payloadDataLen bytes of payload, \"", ".", "$", "this", "->", "remainingPayloadBytes", ".", "\" left\"", ")", ";", "if", "(", "$", "this", "->", "remainingPayloadBytes", "===", "0", "&&", "(", "$", "this", "->", "secondFrameByte", "&", "128", ")", ")", "{", "//Unmask after full payload is received", "$", "this", "->", "logger", "->", "debug", "(", "\"Unmasking payload\"", ")", ";", "$", "this", "->", "payload", "=", "$", "this", "->", "getMaskedPayload", "(", ")", ";", "return", "true", ";", "}", "return", "(", "$", "this", "->", "remainingPayloadBytes", "===", "0", ")", ";", "}" ]
Collects payload from buffer. Masked packets are decoded. @return bool|null Returns false if payload not yet collected, true if it was collected. Null is returned if payload cannot be collected yet @throws LogicException In case of calling before collecting headers
[ "Collects", "payload", "from", "buffer", ".", "Masked", "packets", "are", "decoded", "." ]
85f0335b87b3ec73ab47f5a5631eb86ba70b64a1
https://github.com/kiler129/TinyWs/blob/85f0335b87b3ec73ab47f5a5631eb86ba70b64a1/src/NetworkFrame.php#L194-L222
train
samsonos/php_core
src/XMLBuilder.php
XMLBuilder.setAttribute
protected function setAttribute(string $value, \DOMElement $node, array $classesMetadata) { if (array_key_exists($value, $classesMetadata)) { $node->setAttribute('service', $value); } elseif (class_exists($value)) { $node->setAttribute('class', $value); } else { $node->setAttribute('value', $value); } }
php
protected function setAttribute(string $value, \DOMElement $node, array $classesMetadata) { if (array_key_exists($value, $classesMetadata)) { $node->setAttribute('service', $value); } elseif (class_exists($value)) { $node->setAttribute('class', $value); } else { $node->setAttribute('value', $value); } }
[ "protected", "function", "setAttribute", "(", "string", "$", "value", ",", "\\", "DOMElement", "$", "node", ",", "array", "$", "classesMetadata", ")", "{", "if", "(", "array_key_exists", "(", "$", "value", ",", "$", "classesMetadata", ")", ")", "{", "$", "node", "->", "setAttribute", "(", "'service'", ",", "$", "value", ")", ";", "}", "elseif", "(", "class_exists", "(", "$", "value", ")", ")", "{", "$", "node", "->", "setAttribute", "(", "'class'", ",", "$", "value", ")", ";", "}", "else", "{", "$", "node", "->", "setAttribute", "(", "'value'", ",", "$", "value", ")", ";", "}", "}" ]
Set XML property or method argument value. @param string $value @param \DOMElement $node @param ClassMetadata[] $classesMetadata
[ "Set", "XML", "property", "or", "method", "argument", "value", "." ]
15f30528e2efab9e9cf16e9aad3899edced49de1
https://github.com/samsonos/php_core/blob/15f30528e2efab9e9cf16e9aad3899edced49de1/src/XMLBuilder.php#L24-L33
train
samsonos/php_core
src/XMLBuilder.php
XMLBuilder.buildXMLConfig
public function buildXMLConfig(array $classesMetadata, string $path) { foreach ($classesMetadata as $alias => $classMetadata) { $dom = new \DOMDocument("1.0", "utf-8"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $root = $dom->createElement("dependencies"); $dom->appendChild($root); // Build alias from class name if missing $alias = $alias ?? strtolower(str_replace('\\', '_', $classMetadata->className)); $classData = $dom->createElement('instance'); $classData->setAttribute('service', $alias); $classData->setAttribute('class', $classMetadata->className); foreach ($classMetadata->scopes as $scope) { $classData->setAttribute('scope', $scope); } $methodsData = $dom->createElement('methods'); foreach ($classMetadata->methodsMetadata as $method => $methodMetadata) { if (count($methodMetadata->dependencies)) { $methodData = $dom->createElement($method); $argumentsData = $dom->createElement('arguments'); foreach ($methodMetadata->dependencies as $argument => $dependency) { $argumentData = $dom->createElement($argument); $this->setAttribute($dependency, $argumentData, $classesMetadata); $argumentsData->appendChild($argumentData); } $methodData->appendChild($argumentsData); $methodsData->appendChild($methodData); } } $classData->appendChild($methodsData); $propertiesData = $dom->createElement('properties'); foreach ($classMetadata->propertiesMetadata as $property => $propertyMetadata) { if ($propertyMetadata->dependency !== null && $propertyMetadata->dependency !== '') { $propertyData = $dom->createElement($property); $this->setAttribute($propertyMetadata->dependency, $propertyData, $classesMetadata); $propertiesData->appendChild($propertyData); } } $classData->appendChild($propertiesData); $root->appendChild($classData); $dom->save($path . $alias . '.xml'); } }
php
public function buildXMLConfig(array $classesMetadata, string $path) { foreach ($classesMetadata as $alias => $classMetadata) { $dom = new \DOMDocument("1.0", "utf-8"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $root = $dom->createElement("dependencies"); $dom->appendChild($root); // Build alias from class name if missing $alias = $alias ?? strtolower(str_replace('\\', '_', $classMetadata->className)); $classData = $dom->createElement('instance'); $classData->setAttribute('service', $alias); $classData->setAttribute('class', $classMetadata->className); foreach ($classMetadata->scopes as $scope) { $classData->setAttribute('scope', $scope); } $methodsData = $dom->createElement('methods'); foreach ($classMetadata->methodsMetadata as $method => $methodMetadata) { if (count($methodMetadata->dependencies)) { $methodData = $dom->createElement($method); $argumentsData = $dom->createElement('arguments'); foreach ($methodMetadata->dependencies as $argument => $dependency) { $argumentData = $dom->createElement($argument); $this->setAttribute($dependency, $argumentData, $classesMetadata); $argumentsData->appendChild($argumentData); } $methodData->appendChild($argumentsData); $methodsData->appendChild($methodData); } } $classData->appendChild($methodsData); $propertiesData = $dom->createElement('properties'); foreach ($classMetadata->propertiesMetadata as $property => $propertyMetadata) { if ($propertyMetadata->dependency !== null && $propertyMetadata->dependency !== '') { $propertyData = $dom->createElement($property); $this->setAttribute($propertyMetadata->dependency, $propertyData, $classesMetadata); $propertiesData->appendChild($propertyData); } } $classData->appendChild($propertiesData); $root->appendChild($classData); $dom->save($path . $alias . '.xml'); } }
[ "public", "function", "buildXMLConfig", "(", "array", "$", "classesMetadata", ",", "string", "$", "path", ")", "{", "foreach", "(", "$", "classesMetadata", "as", "$", "alias", "=>", "$", "classMetadata", ")", "{", "$", "dom", "=", "new", "\\", "DOMDocument", "(", "\"1.0\"", ",", "\"utf-8\"", ")", ";", "$", "dom", "->", "preserveWhiteSpace", "=", "false", ";", "$", "dom", "->", "formatOutput", "=", "true", ";", "$", "root", "=", "$", "dom", "->", "createElement", "(", "\"dependencies\"", ")", ";", "$", "dom", "->", "appendChild", "(", "$", "root", ")", ";", "// Build alias from class name if missing", "$", "alias", "=", "$", "alias", "??", "strtolower", "(", "str_replace", "(", "'\\\\'", ",", "'_'", ",", "$", "classMetadata", "->", "className", ")", ")", ";", "$", "classData", "=", "$", "dom", "->", "createElement", "(", "'instance'", ")", ";", "$", "classData", "->", "setAttribute", "(", "'service'", ",", "$", "alias", ")", ";", "$", "classData", "->", "setAttribute", "(", "'class'", ",", "$", "classMetadata", "->", "className", ")", ";", "foreach", "(", "$", "classMetadata", "->", "scopes", "as", "$", "scope", ")", "{", "$", "classData", "->", "setAttribute", "(", "'scope'", ",", "$", "scope", ")", ";", "}", "$", "methodsData", "=", "$", "dom", "->", "createElement", "(", "'methods'", ")", ";", "foreach", "(", "$", "classMetadata", "->", "methodsMetadata", "as", "$", "method", "=>", "$", "methodMetadata", ")", "{", "if", "(", "count", "(", "$", "methodMetadata", "->", "dependencies", ")", ")", "{", "$", "methodData", "=", "$", "dom", "->", "createElement", "(", "$", "method", ")", ";", "$", "argumentsData", "=", "$", "dom", "->", "createElement", "(", "'arguments'", ")", ";", "foreach", "(", "$", "methodMetadata", "->", "dependencies", "as", "$", "argument", "=>", "$", "dependency", ")", "{", "$", "argumentData", "=", "$", "dom", "->", "createElement", "(", "$", "argument", ")", ";", "$", "this", "->", "setAttribute", "(", "$", "dependency", ",", "$", "argumentData", ",", "$", "classesMetadata", ")", ";", "$", "argumentsData", "->", "appendChild", "(", "$", "argumentData", ")", ";", "}", "$", "methodData", "->", "appendChild", "(", "$", "argumentsData", ")", ";", "$", "methodsData", "->", "appendChild", "(", "$", "methodData", ")", ";", "}", "}", "$", "classData", "->", "appendChild", "(", "$", "methodsData", ")", ";", "$", "propertiesData", "=", "$", "dom", "->", "createElement", "(", "'properties'", ")", ";", "foreach", "(", "$", "classMetadata", "->", "propertiesMetadata", "as", "$", "property", "=>", "$", "propertyMetadata", ")", "{", "if", "(", "$", "propertyMetadata", "->", "dependency", "!==", "null", "&&", "$", "propertyMetadata", "->", "dependency", "!==", "''", ")", "{", "$", "propertyData", "=", "$", "dom", "->", "createElement", "(", "$", "property", ")", ";", "$", "this", "->", "setAttribute", "(", "$", "propertyMetadata", "->", "dependency", ",", "$", "propertyData", ",", "$", "classesMetadata", ")", ";", "$", "propertiesData", "->", "appendChild", "(", "$", "propertyData", ")", ";", "}", "}", "$", "classData", "->", "appendChild", "(", "$", "propertiesData", ")", ";", "$", "root", "->", "appendChild", "(", "$", "classData", ")", ";", "$", "dom", "->", "save", "(", "$", "path", ".", "$", "alias", ".", "'.xml'", ")", ";", "}", "}" ]
Build class xml config from class metadata. TODO: Scan for existing config and change only not filled values. @param ClassMetadata[] $classesMetadata @param string $path Path where to store XML files
[ "Build", "class", "xml", "config", "from", "class", "metadata", "." ]
15f30528e2efab9e9cf16e9aad3899edced49de1
https://github.com/samsonos/php_core/blob/15f30528e2efab9e9cf16e9aad3899edced49de1/src/XMLBuilder.php#L43-L92
train
IStranger/yii2-resource-smart-load
base/Helper.php
Helper.filterByKeys
public static function filterByKeys($array, array $keysInc = null, array $keysExc = null) { if ($keysInc !== null) { $array = array_intersect_key($array, array_flip($keysInc)); } if ($keysExc) { $array = array_diff_key($array, array_flip($keysExc)); } return $array; }
php
public static function filterByKeys($array, array $keysInc = null, array $keysExc = null) { if ($keysInc !== null) { $array = array_intersect_key($array, array_flip($keysInc)); } if ($keysExc) { $array = array_diff_key($array, array_flip($keysExc)); } return $array; }
[ "public", "static", "function", "filterByKeys", "(", "$", "array", ",", "array", "$", "keysInc", "=", "null", ",", "array", "$", "keysExc", "=", "null", ")", "{", "if", "(", "$", "keysInc", "!==", "null", ")", "{", "$", "array", "=", "array_intersect_key", "(", "$", "array", ",", "array_flip", "(", "$", "keysInc", ")", ")", ";", "}", "if", "(", "$", "keysExc", ")", "{", "$", "array", "=", "array_diff_key", "(", "$", "array", ",", "array_flip", "(", "$", "keysExc", ")", ")", ";", "}", "return", "$", "array", ";", "}" ]
Filters items by given keys. @param array $array source assoc array @param array $keysInc keys of items, that should be included @param array $keysExc keys of items, that should be excluded @return array|mixed|null filtered array
[ "Filters", "items", "by", "given", "keys", "." ]
a4f203745d9a02fd97853b49c55b287aea6d7e6d
https://github.com/IStranger/yii2-resource-smart-load/blob/a4f203745d9a02fd97853b49c55b287aea6d7e6d/base/Helper.php#L72-L81
train
buse974/Dal
src/Dal/AbstractFactory/ModelAbstractFactory.php
ModelAbstractFactory.canCreate
public function canCreate(ContainerInterface $container, $requestedName) { $namespace = $this->getConfig($container)['namespace']; $ar = explode('_', $requestedName); return (count($ar) >= 2 && array_key_exists($ar[0], $namespace) && $ar[1] === 'model'); }
php
public function canCreate(ContainerInterface $container, $requestedName) { $namespace = $this->getConfig($container)['namespace']; $ar = explode('_', $requestedName); return (count($ar) >= 2 && array_key_exists($ar[0], $namespace) && $ar[1] === 'model'); }
[ "public", "function", "canCreate", "(", "ContainerInterface", "$", "container", ",", "$", "requestedName", ")", "{", "$", "namespace", "=", "$", "this", "->", "getConfig", "(", "$", "container", ")", "[", "'namespace'", "]", ";", "$", "ar", "=", "explode", "(", "'_'", ",", "$", "requestedName", ")", ";", "return", "(", "count", "(", "$", "ar", ")", ">=", "2", "&&", "array_key_exists", "(", "$", "ar", "[", "0", "]", ",", "$", "namespace", ")", "&&", "$", "ar", "[", "1", "]", "===", "'model'", ")", ";", "}" ]
Determine if we can create a Model with name {@inheritDoc} @see \Zend\ServiceManager\Factory\AbstractFactoryInterface::canCreate()
[ "Determine", "if", "we", "can", "create", "a", "Model", "with", "name" ]
faeac9e260c5e675bc7ed1fcea77c7ba251bf8ab
https://github.com/buse974/Dal/blob/faeac9e260c5e675bc7ed1fcea77c7ba251bf8ab/src/Dal/AbstractFactory/ModelAbstractFactory.php#L25-L31
train
jasny/entity
src/Traits/ToJsonTrait.php
ToJsonTrait.jsonSerialize
public function jsonSerialize(): stdClass { $object = (object)object_get_properties($this, $this instanceof DynamicEntity); /** @var Event\ToJson $event */ $event = $this->dispatchEvent(new Event\ToJson($this, $object)); $data = i\type_check($event->getPayload(), stdClass::class, new UnexpectedValueException()); return $data; }
php
public function jsonSerialize(): stdClass { $object = (object)object_get_properties($this, $this instanceof DynamicEntity); /** @var Event\ToJson $event */ $event = $this->dispatchEvent(new Event\ToJson($this, $object)); $data = i\type_check($event->getPayload(), stdClass::class, new UnexpectedValueException()); return $data; }
[ "public", "function", "jsonSerialize", "(", ")", ":", "stdClass", "{", "$", "object", "=", "(", "object", ")", "object_get_properties", "(", "$", "this", ",", "$", "this", "instanceof", "DynamicEntity", ")", ";", "/** @var Event\\ToJson $event */", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "new", "Event", "\\", "ToJson", "(", "$", "this", ",", "$", "object", ")", ")", ";", "$", "data", "=", "i", "\\", "type_check", "(", "$", "event", "->", "getPayload", "(", ")", ",", "stdClass", "::", "class", ",", "new", "UnexpectedValueException", "(", ")", ")", ";", "return", "$", "data", ";", "}" ]
Prepare entity for JsonSerialize encoding @return stdClass
[ "Prepare", "entity", "for", "JsonSerialize", "encoding" ]
5af7c94645671a3257d6565ff1891ff61fdcf69b
https://github.com/jasny/entity/blob/5af7c94645671a3257d6565ff1891ff61fdcf69b/src/Traits/ToJsonTrait.php#L32-L41
train
Phpillip/phpillip
src/EventListener/TemplateListener.php
TemplateListener.onKernelController
public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); if ($template = $this->getTemplate($request, $event->getController())) { $request->attributes->set('_template', $template); } }
php
public function onKernelController(FilterControllerEvent $event) { $request = $event->getRequest(); if ($template = $this->getTemplate($request, $event->getController())) { $request->attributes->set('_template', $template); } }
[ "public", "function", "onKernelController", "(", "FilterControllerEvent", "$", "event", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "if", "(", "$", "template", "=", "$", "this", "->", "getTemplate", "(", "$", "request", ",", "$", "event", "->", "getController", "(", ")", ")", ")", "{", "$", "request", "->", "attributes", "->", "set", "(", "'_template'", ",", "$", "template", ")", ";", "}", "}" ]
Handles Kernel Controller events @param FilterControllerEvent $event
[ "Handles", "Kernel", "Controller", "events" ]
c37afaafb536361e7e0b564659f1cd5b80b98be9
https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/EventListener/TemplateListener.php#L55-L62
train
Phpillip/phpillip
src/EventListener/TemplateListener.php
TemplateListener.onKernelView
public function onKernelView(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); $parameters = $event->getControllerResult(); if (!$response instanceof Response && $template = $request->attributes->get('_template')) { return $event->setControllerResult($this->templating->render($template, $parameters)); } }
php
public function onKernelView(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); $response = $event->getResponse(); $parameters = $event->getControllerResult(); if (!$response instanceof Response && $template = $request->attributes->get('_template')) { return $event->setControllerResult($this->templating->render($template, $parameters)); } }
[ "public", "function", "onKernelView", "(", "GetResponseForControllerResultEvent", "$", "event", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "$", "response", "=", "$", "event", "->", "getResponse", "(", ")", ";", "$", "parameters", "=", "$", "event", "->", "getControllerResult", "(", ")", ";", "if", "(", "!", "$", "response", "instanceof", "Response", "&&", "$", "template", "=", "$", "request", "->", "attributes", "->", "get", "(", "'_template'", ")", ")", "{", "return", "$", "event", "->", "setControllerResult", "(", "$", "this", "->", "templating", "->", "render", "(", "$", "template", ",", "$", "parameters", ")", ")", ";", "}", "}" ]
Handles Kernel View events @param GetResponseForControllerResultEvent $event
[ "Handles", "Kernel", "View", "events" ]
c37afaafb536361e7e0b564659f1cd5b80b98be9
https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/EventListener/TemplateListener.php#L69-L78
train
Phpillip/phpillip
src/EventListener/TemplateListener.php
TemplateListener.getTemplate
protected function getTemplate(Request $request, $controller) { if ($request->attributes->has('_template')) { return null; } $format = $request->attributes->get('_format', 'html'); $templates = []; if ($controllerInfo = $this->parseController($controller)) { $template = sprintf('%s/%s.%s.twig', $controllerInfo['name'], $controllerInfo['action'], $format); if ($this->templateExists($template)) { return $template; } else { $templates[] = $template; } } $route = $this->routes->get($request->attributes->get('_route')); if ($route && $route->hasContent()) { $template = sprintf('%s/%s.%s.twig', $route->getContent(), $route->isList() ? 'list' : 'show', $format); if ($this->templateExists($template)) { return $template; } else { $templates[] = $template; } } return array_pop($templates); }
php
protected function getTemplate(Request $request, $controller) { if ($request->attributes->has('_template')) { return null; } $format = $request->attributes->get('_format', 'html'); $templates = []; if ($controllerInfo = $this->parseController($controller)) { $template = sprintf('%s/%s.%s.twig', $controllerInfo['name'], $controllerInfo['action'], $format); if ($this->templateExists($template)) { return $template; } else { $templates[] = $template; } } $route = $this->routes->get($request->attributes->get('_route')); if ($route && $route->hasContent()) { $template = sprintf('%s/%s.%s.twig', $route->getContent(), $route->isList() ? 'list' : 'show', $format); if ($this->templateExists($template)) { return $template; } else { $templates[] = $template; } } return array_pop($templates); }
[ "protected", "function", "getTemplate", "(", "Request", "$", "request", ",", "$", "controller", ")", "{", "if", "(", "$", "request", "->", "attributes", "->", "has", "(", "'_template'", ")", ")", "{", "return", "null", ";", "}", "$", "format", "=", "$", "request", "->", "attributes", "->", "get", "(", "'_format'", ",", "'html'", ")", ";", "$", "templates", "=", "[", "]", ";", "if", "(", "$", "controllerInfo", "=", "$", "this", "->", "parseController", "(", "$", "controller", ")", ")", "{", "$", "template", "=", "sprintf", "(", "'%s/%s.%s.twig'", ",", "$", "controllerInfo", "[", "'name'", "]", ",", "$", "controllerInfo", "[", "'action'", "]", ",", "$", "format", ")", ";", "if", "(", "$", "this", "->", "templateExists", "(", "$", "template", ")", ")", "{", "return", "$", "template", ";", "}", "else", "{", "$", "templates", "[", "]", "=", "$", "template", ";", "}", "}", "$", "route", "=", "$", "this", "->", "routes", "->", "get", "(", "$", "request", "->", "attributes", "->", "get", "(", "'_route'", ")", ")", ";", "if", "(", "$", "route", "&&", "$", "route", "->", "hasContent", "(", ")", ")", "{", "$", "template", "=", "sprintf", "(", "'%s/%s.%s.twig'", ",", "$", "route", "->", "getContent", "(", ")", ",", "$", "route", "->", "isList", "(", ")", "?", "'list'", ":", "'show'", ",", "$", "format", ")", ";", "if", "(", "$", "this", "->", "templateExists", "(", "$", "template", ")", ")", "{", "return", "$", "template", ";", "}", "else", "{", "$", "templates", "[", "]", "=", "$", "template", ";", "}", "}", "return", "array_pop", "(", "$", "templates", ")", ";", "}" ]
Get template from the given request and controller @param Request $request @param mixed $controller @return string|null
[ "Get", "template", "from", "the", "given", "request", "and", "controller" ]
c37afaafb536361e7e0b564659f1cd5b80b98be9
https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/EventListener/TemplateListener.php#L88-L120
train
Phpillip/phpillip
src/EventListener/TemplateListener.php
TemplateListener.parseController
protected function parseController($controller) { if (!is_array($controller) || !is_object($controller[0]) || !isset($controller[1])) { return null; } if (!preg_match('#Controller\\\(.+)Controller$#', get_class($controller[0]), $matches)) { return null; } return ['name' => $matches[1], 'action' => $controller[1]]; }
php
protected function parseController($controller) { if (!is_array($controller) || !is_object($controller[0]) || !isset($controller[1])) { return null; } if (!preg_match('#Controller\\\(.+)Controller$#', get_class($controller[0]), $matches)) { return null; } return ['name' => $matches[1], 'action' => $controller[1]]; }
[ "protected", "function", "parseController", "(", "$", "controller", ")", "{", "if", "(", "!", "is_array", "(", "$", "controller", ")", "||", "!", "is_object", "(", "$", "controller", "[", "0", "]", ")", "||", "!", "isset", "(", "$", "controller", "[", "1", "]", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "preg_match", "(", "'#Controller\\\\\\(.+)Controller$#'", ",", "get_class", "(", "$", "controller", "[", "0", "]", ")", ",", "$", "matches", ")", ")", "{", "return", "null", ";", "}", "return", "[", "'name'", "=>", "$", "matches", "[", "1", "]", ",", "'action'", "=>", "$", "controller", "[", "1", "]", "]", ";", "}" ]
Parse controller to extract its name @param mixed $controller @return string
[ "Parse", "controller", "to", "extract", "its", "name" ]
c37afaafb536361e7e0b564659f1cd5b80b98be9
https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/EventListener/TemplateListener.php#L129-L140
train
Phpillip/phpillip
src/EventListener/TemplateListener.php
TemplateListener.templateExists
protected function templateExists($template) { try { $class = $this->templating->getTemplateClass($template); } catch (Twig_Error_Loader $e) { return false; } return $template; }
php
protected function templateExists($template) { try { $class = $this->templating->getTemplateClass($template); } catch (Twig_Error_Loader $e) { return false; } return $template; }
[ "protected", "function", "templateExists", "(", "$", "template", ")", "{", "try", "{", "$", "class", "=", "$", "this", "->", "templating", "->", "getTemplateClass", "(", "$", "template", ")", ";", "}", "catch", "(", "Twig_Error_Loader", "$", "e", ")", "{", "return", "false", ";", "}", "return", "$", "template", ";", "}" ]
Does the given template exists? @param string $template @return boolean
[ "Does", "the", "given", "template", "exists?" ]
c37afaafb536361e7e0b564659f1cd5b80b98be9
https://github.com/Phpillip/phpillip/blob/c37afaafb536361e7e0b564659f1cd5b80b98be9/src/EventListener/TemplateListener.php#L149-L158
train
Dhii/output-renderer-abstract
src/RenderCapableTemplateBlockTrait.php
RenderCapableTemplateBlockTrait._render
protected function _render() { try { $template = $this->_getTemplate(); $context = $this->_getContextFor($template); return $this->_renderTemplate($template, $context); } catch (RootException $e) { throw $this->_throwCouldNotRenderException($this->__('Could not render template'), null, $e); } }
php
protected function _render() { try { $template = $this->_getTemplate(); $context = $this->_getContextFor($template); return $this->_renderTemplate($template, $context); } catch (RootException $e) { throw $this->_throwCouldNotRenderException($this->__('Could not render template'), null, $e); } }
[ "protected", "function", "_render", "(", ")", "{", "try", "{", "$", "template", "=", "$", "this", "->", "_getTemplate", "(", ")", ";", "$", "context", "=", "$", "this", "->", "_getContextFor", "(", "$", "template", ")", ";", "return", "$", "this", "->", "_renderTemplate", "(", "$", "template", ",", "$", "context", ")", ";", "}", "catch", "(", "RootException", "$", "e", ")", "{", "throw", "$", "this", "->", "_throwCouldNotRenderException", "(", "$", "this", "->", "__", "(", "'Could not render template'", ")", ",", "null", ",", "$", "e", ")", ";", "}", "}" ]
Renders an internal template. @since [*next-version*] @throws CouldNotRenderExceptionInterface If the template could not be rendered. @throws RendererExceptionInterface If a problem related to a renderer occurs.
[ "Renders", "an", "internal", "template", "." ]
0f6e5eed940025332dd1986d6c771e10f7197b1a
https://github.com/Dhii/output-renderer-abstract/blob/0f6e5eed940025332dd1986d6c771e10f7197b1a/src/RenderCapableTemplateBlockTrait.php#L27-L37
train
schpill/thin
src/Html/Doctype.php
Doctype.doctype
public function doctype($doctype = null) { if (null !== $doctype) { switch ($doctype) { case static::XHTML11: case static::XHTML1_STRICT: case static::XHTML1_TRANSITIONAL: case static::XHTML1_FRAMESET: case static::XHTML_BASIC1: case static::XHTML1_RDFA: case static::XHTML1_RDFA11: case static::XHTML5: case static::HTML4_STRICT: case static::HTML4_LOOSE: case static::HTML4_FRAMESET: case static::HTML5: $this->setDoctype($doctype); break; default: if (substr($doctype, 0, 9) != '<!DOCTYPE') { $e = new Exception('The specified doctype is malformed'); throw $e; } if (stristr($doctype, 'xhtml')) { $type = static::CUSTOM_XHTML; } else { $type = static::CUSTOM; } $this->setDoctype($type); $this->_registry['doctypes'][$type] = $doctype; break; } } return $this; }
php
public function doctype($doctype = null) { if (null !== $doctype) { switch ($doctype) { case static::XHTML11: case static::XHTML1_STRICT: case static::XHTML1_TRANSITIONAL: case static::XHTML1_FRAMESET: case static::XHTML_BASIC1: case static::XHTML1_RDFA: case static::XHTML1_RDFA11: case static::XHTML5: case static::HTML4_STRICT: case static::HTML4_LOOSE: case static::HTML4_FRAMESET: case static::HTML5: $this->setDoctype($doctype); break; default: if (substr($doctype, 0, 9) != '<!DOCTYPE') { $e = new Exception('The specified doctype is malformed'); throw $e; } if (stristr($doctype, 'xhtml')) { $type = static::CUSTOM_XHTML; } else { $type = static::CUSTOM; } $this->setDoctype($type); $this->_registry['doctypes'][$type] = $doctype; break; } } return $this; }
[ "public", "function", "doctype", "(", "$", "doctype", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "doctype", ")", "{", "switch", "(", "$", "doctype", ")", "{", "case", "static", "::", "XHTML11", ":", "case", "static", "::", "XHTML1_STRICT", ":", "case", "static", "::", "XHTML1_TRANSITIONAL", ":", "case", "static", "::", "XHTML1_FRAMESET", ":", "case", "static", "::", "XHTML_BASIC1", ":", "case", "static", "::", "XHTML1_RDFA", ":", "case", "static", "::", "XHTML1_RDFA11", ":", "case", "static", "::", "XHTML5", ":", "case", "static", "::", "HTML4_STRICT", ":", "case", "static", "::", "HTML4_LOOSE", ":", "case", "static", "::", "HTML4_FRAMESET", ":", "case", "static", "::", "HTML5", ":", "$", "this", "->", "setDoctype", "(", "$", "doctype", ")", ";", "break", ";", "default", ":", "if", "(", "substr", "(", "$", "doctype", ",", "0", ",", "9", ")", "!=", "'<!DOCTYPE'", ")", "{", "$", "e", "=", "new", "Exception", "(", "'The specified doctype is malformed'", ")", ";", "throw", "$", "e", ";", "}", "if", "(", "stristr", "(", "$", "doctype", ",", "'xhtml'", ")", ")", "{", "$", "type", "=", "static", "::", "CUSTOM_XHTML", ";", "}", "else", "{", "$", "type", "=", "static", "::", "CUSTOM", ";", "}", "$", "this", "->", "setDoctype", "(", "$", "type", ")", ";", "$", "this", "->", "_registry", "[", "'doctypes'", "]", "[", "$", "type", "]", "=", "$", "doctype", ";", "break", ";", "}", "}", "return", "$", "this", ";", "}" ]
Set or retrieve doctype @param string $doctype @return FTV_Html_Doctype
[ "Set", "or", "retrieve", "doctype" ]
a9102d9d6f70e8b0f6be93153f70849f46489ee1
https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Html/Doctype.php#L84-L119
train