repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
zicht/z
src/Zicht/Tool/Script/Node/Script/ForIn.php
ForIn.beforeScript
public function beforeScript(Buffer $buffer) { $buffer->write('foreach ((array)'); $this->nodes[0]->compile($buffer); $buffer ->raw(' as $_key => $_value) {')->eol()->indent(1) ->writeln(sprintf('$z->push(\'%s\', $_key);', $this->key)) ->writeln(sprintf('$z->push(\'%s\', $_value);', $this->value)) ; }
php
public function beforeScript(Buffer $buffer) { $buffer->write('foreach ((array)'); $this->nodes[0]->compile($buffer); $buffer ->raw(' as $_key => $_value) {')->eol()->indent(1) ->writeln(sprintf('$z->push(\'%s\', $_key);', $this->key)) ->writeln(sprintf('$z->push(\'%s\', $_value);', $this->value)) ; }
[ "public", "function", "beforeScript", "(", "Buffer", "$", "buffer", ")", "{", "$", "buffer", "->", "write", "(", "'foreach ((array)'", ")", ";", "$", "this", "->", "nodes", "[", "0", "]", "->", "compile", "(", "$", "buffer", ")", ";", "$", "buffer", "->", "raw", "(", "' as $_key => $_value) {'", ")", "->", "eol", "(", ")", "->", "indent", "(", "1", ")", "->", "writeln", "(", "sprintf", "(", "'$z->push(\\'%s\\', $_key);'", ",", "$", "this", "->", "key", ")", ")", "->", "writeln", "(", "sprintf", "(", "'$z->push(\\'%s\\', $_value);'", ",", "$", "this", "->", "value", ")", ")", ";", "}" ]
Allows the annotation to modify the buffer before the script is compiled. @param Buffer $buffer @return void
[ "Allows", "the", "annotation", "to", "modify", "the", "buffer", "before", "the", "script", "is", "compiled", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Script/Node/Script/ForIn.php#L41-L50
zicht/z
src/Zicht/Tool/Script/Node/Script/ForIn.php
ForIn.afterScript
public function afterScript(Buffer $buffer) { $buffer->write(sprintf('$z->pop(\'%s\');', $this->key)); $buffer->write(sprintf('$z->pop(\'%s\');', $this->value)); $buffer->indent(-1); $buffer->writeln('}'); }
php
public function afterScript(Buffer $buffer) { $buffer->write(sprintf('$z->pop(\'%s\');', $this->key)); $buffer->write(sprintf('$z->pop(\'%s\');', $this->value)); $buffer->indent(-1); $buffer->writeln('}'); }
[ "public", "function", "afterScript", "(", "Buffer", "$", "buffer", ")", "{", "$", "buffer", "->", "write", "(", "sprintf", "(", "'$z->pop(\\'%s\\');'", ",", "$", "this", "->", "key", ")", ")", ";", "$", "buffer", "->", "write", "(", "sprintf", "(", "'$z->pop(\\'%s\\');'", ",", "$", "this", "->", "value", ")", ")", ";", "$", "buffer", "->", "indent", "(", "-", "1", ")", ";", "$", "buffer", "->", "writeln", "(", "'}'", ")", ";", "}" ]
Allows the annotation to modify the buffer after the script is compiled. @param Buffer $buffer @return void
[ "Allows", "the", "annotation", "to", "modify", "the", "buffer", "after", "the", "script", "is", "compiled", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Script/Node/Script/ForIn.php#L58-L64
sokil/php-mongo-yii
src/Sokil/Mongo/Yii/LogRoute.php
LogRoute._timeToMongoDate
protected function _timeToMongoDate($time) { if(!is_numeric($time)) { $time = strtotime($time); if(!$time) { $time = time(); } } return new \MongoDate($time); }
php
protected function _timeToMongoDate($time) { if(!is_numeric($time)) { $time = strtotime($time); if(!$time) { $time = time(); } } return new \MongoDate($time); }
[ "protected", "function", "_timeToMongoDate", "(", "$", "time", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "time", ")", ")", "{", "$", "time", "=", "strtotime", "(", "$", "time", ")", ";", "if", "(", "!", "$", "time", ")", "{", "$", "time", "=", "time", "(", ")", ";", "}", "}", "return", "new", "\\", "MongoDate", "(", "$", "time", ")", ";", "}" ]
Convert time in different formats to mongo date @param mixed $time @return \MongoDate
[ "Convert", "time", "in", "different", "formats", "to", "mongo", "date" ]
train
https://github.com/sokil/php-mongo-yii/blob/d41b3b70953bc6521c73fcacc501e1596a9ed7d3/src/Sokil/Mongo/Yii/LogRoute.php#L16-L26
sokil/php-mongo-yii
src/Sokil/Mongo/Yii/LogRoute.php
LogRoute.processLogs
protected function processLogs($logs) { $logCollection = \Yii::app() ->{$this->serviceName} ->getCollection($this->collectionName); foreach ($logs as $log) { // time $logCollection ->createDocument(array( 'level' => $log[1], 'category' => $log[2], 'logtime' => $this->_timeToMongoDate($log[3]), 'message' => $log[0], 'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null, 'userAgent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null, )) ->save(); } }
php
protected function processLogs($logs) { $logCollection = \Yii::app() ->{$this->serviceName} ->getCollection($this->collectionName); foreach ($logs as $log) { // time $logCollection ->createDocument(array( 'level' => $log[1], 'category' => $log[2], 'logtime' => $this->_timeToMongoDate($log[3]), 'message' => $log[0], 'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null, 'userAgent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null, )) ->save(); } }
[ "protected", "function", "processLogs", "(", "$", "logs", ")", "{", "$", "logCollection", "=", "\\", "Yii", "::", "app", "(", ")", "->", "{", "$", "this", "->", "serviceName", "}", "->", "getCollection", "(", "$", "this", "->", "collectionName", ")", ";", "foreach", "(", "$", "logs", "as", "$", "log", ")", "{", "// time", "$", "logCollection", "->", "createDocument", "(", "array", "(", "'level'", "=>", "$", "log", "[", "1", "]", ",", "'category'", "=>", "$", "log", "[", "2", "]", ",", "'logtime'", "=>", "$", "this", "->", "_timeToMongoDate", "(", "$", "log", "[", "3", "]", ")", ",", "'message'", "=>", "$", "log", "[", "0", "]", ",", "'requestUri'", "=>", "isset", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", "?", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ":", "null", ",", "'userAgent'", "=>", "isset", "(", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", "?", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ":", "null", ",", ")", ")", "->", "save", "(", ")", ";", "}", "}" ]
Write log messages @param array $logs list of messages
[ "Write", "log", "messages" ]
train
https://github.com/sokil/php-mongo-yii/blob/d41b3b70953bc6521c73fcacc501e1596a9ed7d3/src/Sokil/Mongo/Yii/LogRoute.php#L32-L52
phootwork/lang
src/text/CheckerTrait.php
CheckerTrait.isSingular
public function isSingular(Pluralizer $pluralizer = null) { $pluralizer = $pluralizer ?: new EnglishPluralizer(); return $pluralizer->isSingular($this->string); }
php
public function isSingular(Pluralizer $pluralizer = null) { $pluralizer = $pluralizer ?: new EnglishPluralizer(); return $pluralizer->isSingular($this->string); }
[ "public", "function", "isSingular", "(", "Pluralizer", "$", "pluralizer", "=", "null", ")", "{", "$", "pluralizer", "=", "$", "pluralizer", "?", ":", "new", "EnglishPluralizer", "(", ")", ";", "return", "$", "pluralizer", "->", "isSingular", "(", "$", "this", "->", "string", ")", ";", "}" ]
Check if a string is singular form. @param Pluralizer $pluralizer A custom pluralizer. Default is the EnglishPluralizer @return boolean
[ "Check", "if", "a", "string", "is", "singular", "form", "." ]
train
https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/CheckerTrait.php#L101-L105
phootwork/lang
src/text/CheckerTrait.php
CheckerTrait.isPlural
public function isPlural(Pluralizer $pluralizer = null) { $pluralizer = $pluralizer ?: new EnglishPluralizer(); return $pluralizer->isPlural($this->string); }
php
public function isPlural(Pluralizer $pluralizer = null) { $pluralizer = $pluralizer ?: new EnglishPluralizer(); return $pluralizer->isPlural($this->string); }
[ "public", "function", "isPlural", "(", "Pluralizer", "$", "pluralizer", "=", "null", ")", "{", "$", "pluralizer", "=", "$", "pluralizer", "?", ":", "new", "EnglishPluralizer", "(", ")", ";", "return", "$", "pluralizer", "->", "isPlural", "(", "$", "this", "->", "string", ")", ";", "}" ]
Check if a string is plural form. @param Pluralizer $pluralizer A custom pluralizer. Default is the EnglishPluralizer @return boolean
[ "Check", "if", "a", "string", "is", "plural", "form", "." ]
train
https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/CheckerTrait.php#L114-L118
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.output
public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null) { return $this->get($tpl, $data, $compiler, true); }
php
public function output($tpl, $data = array(), Dwoo_ICompiler $compiler = null) { return $this->get($tpl, $data, $compiler, true); }
[ "public", "function", "output", "(", "$", "tpl", ",", "$", "data", "=", "array", "(", ")", ",", "Dwoo_ICompiler", "$", "compiler", "=", "null", ")", "{", "return", "$", "this", "->", "get", "(", "$", "tpl", ",", "$", "data", ",", "$", "compiler", ",", "true", ")", ";", "}" ]
outputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true) @see get @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, especially if you render a template multiple times @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're rendering the template from cache, it can be left null @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default Dwoo_Compiler will be used. @return string nothing or the template output if $output is true
[ "outputs", "the", "template", "instead", "of", "returning", "it", "this", "is", "basically", "a", "shortcut", "for", "get", "(", "*", "*", "*", "true", ")" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L289-L292
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.get
public function get($_tpl, $data = array(), $_compiler = null, $_output = false) { // a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one if ($this->template instanceof Dwoo_ITemplate) { $proxy = clone $this; return $proxy->get($_tpl, $data, $_compiler, $_output); } // auto-create template if required if ($_tpl instanceof Dwoo_ITemplate) { // valid, skip } elseif (is_string($_tpl) && file_exists($_tpl)) { $_tpl = new Dwoo_Template_File($_tpl); } else { throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file', E_USER_NOTICE); } // save the current template, enters render mode at the same time // if another rendering is requested it will be proxied to a new Dwoo instance $this->template = $_tpl; // load data if ($data instanceof Dwoo_IDataProvider) { $this->data = $data->getData(); } elseif (is_array($data)) { $this->data = $data; } else { throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array', E_USER_NOTICE); } $this->globals['template'] = $_tpl->getName(); $this->initRuntimeVars($_tpl); // try to get cached template $file = $_tpl->getCachedTemplate($this); $doCache = $file === true; $cacheLoaded = is_string($file); if ($cacheLoaded === true) { // cache is present, run it if ($_output === true) { include $file; $this->template = null; } else { ob_start(); include $file; $this->template = null; return ob_get_clean(); } } else { // no cache present if ($doCache === true) { $dynamicId = uniqid(); } // render template $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); $out = include $compiledTemplate; // template returned false so it needs to be recompiled if ($out === false) { $_tpl->forceCompilation(); $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); $out = include $compiledTemplate; } if ($doCache === true) { $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out); if (!class_exists('Dwoo_plugin_dynamic', false)) { $this->getLoader()->loadPlugin('dynamic'); } $out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate); } // process filters foreach ($this->filters as $filter) { if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) { $out = call_user_func($filter, $out); } else { $out = call_user_func($filter, $this, $out); } } if ($doCache === true) { // building cache $file = $_tpl->cache($this, $out); // run it from the cache to be sure dynamics are rendered if ($_output === true) { include $file; // exit render mode $this->template = null; } else { ob_start(); include $file; // exit render mode $this->template = null; return ob_get_clean(); } } else { // no need to build cache // exit render mode $this->template = null; // output if ($_output === true) { echo $out; } return $out; } } }
php
public function get($_tpl, $data = array(), $_compiler = null, $_output = false) { // a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one if ($this->template instanceof Dwoo_ITemplate) { $proxy = clone $this; return $proxy->get($_tpl, $data, $_compiler, $_output); } // auto-create template if required if ($_tpl instanceof Dwoo_ITemplate) { // valid, skip } elseif (is_string($_tpl) && file_exists($_tpl)) { $_tpl = new Dwoo_Template_File($_tpl); } else { throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file', E_USER_NOTICE); } // save the current template, enters render mode at the same time // if another rendering is requested it will be proxied to a new Dwoo instance $this->template = $_tpl; // load data if ($data instanceof Dwoo_IDataProvider) { $this->data = $data->getData(); } elseif (is_array($data)) { $this->data = $data; } else { throw new Dwoo_Exception('Dwoo->get/Dwoo->output\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array', E_USER_NOTICE); } $this->globals['template'] = $_tpl->getName(); $this->initRuntimeVars($_tpl); // try to get cached template $file = $_tpl->getCachedTemplate($this); $doCache = $file === true; $cacheLoaded = is_string($file); if ($cacheLoaded === true) { // cache is present, run it if ($_output === true) { include $file; $this->template = null; } else { ob_start(); include $file; $this->template = null; return ob_get_clean(); } } else { // no cache present if ($doCache === true) { $dynamicId = uniqid(); } // render template $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); $out = include $compiledTemplate; // template returned false so it needs to be recompiled if ($out === false) { $_tpl->forceCompilation(); $compiledTemplate = $_tpl->getCompiledTemplate($this, $_compiler); $out = include $compiledTemplate; } if ($doCache === true) { $out = preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php /*'.$dynamicId.'*/ echo \'$1\'; ?>', $out); if (!class_exists('Dwoo_plugin_dynamic', false)) { $this->getLoader()->loadPlugin('dynamic'); } $out = Dwoo_Plugin_dynamic::unescape($out, $dynamicId, $compiledTemplate); } // process filters foreach ($this->filters as $filter) { if (is_array($filter) && $filter[0] instanceof Dwoo_Filter) { $out = call_user_func($filter, $out); } else { $out = call_user_func($filter, $this, $out); } } if ($doCache === true) { // building cache $file = $_tpl->cache($this, $out); // run it from the cache to be sure dynamics are rendered if ($_output === true) { include $file; // exit render mode $this->template = null; } else { ob_start(); include $file; // exit render mode $this->template = null; return ob_get_clean(); } } else { // no need to build cache // exit render mode $this->template = null; // output if ($_output === true) { echo $out; } return $out; } } }
[ "public", "function", "get", "(", "$", "_tpl", ",", "$", "data", "=", "array", "(", ")", ",", "$", "_compiler", "=", "null", ",", "$", "_output", "=", "false", ")", "{", "// a render call came from within a template, so we need a new dwoo instance in order to avoid breaking this one", "if", "(", "$", "this", "->", "template", "instanceof", "Dwoo_ITemplate", ")", "{", "$", "proxy", "=", "clone", "$", "this", ";", "return", "$", "proxy", "->", "get", "(", "$", "_tpl", ",", "$", "data", ",", "$", "_compiler", ",", "$", "_output", ")", ";", "}", "// auto-create template if required", "if", "(", "$", "_tpl", "instanceof", "Dwoo_ITemplate", ")", "{", "// valid, skip", "}", "elseif", "(", "is_string", "(", "$", "_tpl", ")", "&&", "file_exists", "(", "$", "_tpl", ")", ")", "{", "$", "_tpl", "=", "new", "Dwoo_Template_File", "(", "$", "_tpl", ")", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Dwoo->get/Dwoo->output\\'s first argument must be a Dwoo_ITemplate (i.e. Dwoo_Template_File) or a valid path to a template file'", ",", "E_USER_NOTICE", ")", ";", "}", "// save the current template, enters render mode at the same time", "// if another rendering is requested it will be proxied to a new Dwoo instance", "$", "this", "->", "template", "=", "$", "_tpl", ";", "// load data", "if", "(", "$", "data", "instanceof", "Dwoo_IDataProvider", ")", "{", "$", "this", "->", "data", "=", "$", "data", "->", "getData", "(", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "data", "=", "$", "data", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Dwoo->get/Dwoo->output\\'s data argument must be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array'", ",", "E_USER_NOTICE", ")", ";", "}", "$", "this", "->", "globals", "[", "'template'", "]", "=", "$", "_tpl", "->", "getName", "(", ")", ";", "$", "this", "->", "initRuntimeVars", "(", "$", "_tpl", ")", ";", "// try to get cached template", "$", "file", "=", "$", "_tpl", "->", "getCachedTemplate", "(", "$", "this", ")", ";", "$", "doCache", "=", "$", "file", "===", "true", ";", "$", "cacheLoaded", "=", "is_string", "(", "$", "file", ")", ";", "if", "(", "$", "cacheLoaded", "===", "true", ")", "{", "// cache is present, run it", "if", "(", "$", "_output", "===", "true", ")", "{", "include", "$", "file", ";", "$", "this", "->", "template", "=", "null", ";", "}", "else", "{", "ob_start", "(", ")", ";", "include", "$", "file", ";", "$", "this", "->", "template", "=", "null", ";", "return", "ob_get_clean", "(", ")", ";", "}", "}", "else", "{", "// no cache present", "if", "(", "$", "doCache", "===", "true", ")", "{", "$", "dynamicId", "=", "uniqid", "(", ")", ";", "}", "// render template", "$", "compiledTemplate", "=", "$", "_tpl", "->", "getCompiledTemplate", "(", "$", "this", ",", "$", "_compiler", ")", ";", "$", "out", "=", "include", "$", "compiledTemplate", ";", "// template returned false so it needs to be recompiled", "if", "(", "$", "out", "===", "false", ")", "{", "$", "_tpl", "->", "forceCompilation", "(", ")", ";", "$", "compiledTemplate", "=", "$", "_tpl", "->", "getCompiledTemplate", "(", "$", "this", ",", "$", "_compiler", ")", ";", "$", "out", "=", "include", "$", "compiledTemplate", ";", "}", "if", "(", "$", "doCache", "===", "true", ")", "{", "$", "out", "=", "preg_replace", "(", "'/(<%|%>|<\\?php|<\\?|\\?>)/'", ",", "'<?php /*'", ".", "$", "dynamicId", ".", "'*/ echo \\'$1\\'; ?>'", ",", "$", "out", ")", ";", "if", "(", "!", "class_exists", "(", "'Dwoo_plugin_dynamic'", ",", "false", ")", ")", "{", "$", "this", "->", "getLoader", "(", ")", "->", "loadPlugin", "(", "'dynamic'", ")", ";", "}", "$", "out", "=", "Dwoo_Plugin_dynamic", "::", "unescape", "(", "$", "out", ",", "$", "dynamicId", ",", "$", "compiledTemplate", ")", ";", "}", "// process filters", "foreach", "(", "$", "this", "->", "filters", "as", "$", "filter", ")", "{", "if", "(", "is_array", "(", "$", "filter", ")", "&&", "$", "filter", "[", "0", "]", "instanceof", "Dwoo_Filter", ")", "{", "$", "out", "=", "call_user_func", "(", "$", "filter", ",", "$", "out", ")", ";", "}", "else", "{", "$", "out", "=", "call_user_func", "(", "$", "filter", ",", "$", "this", ",", "$", "out", ")", ";", "}", "}", "if", "(", "$", "doCache", "===", "true", ")", "{", "// building cache", "$", "file", "=", "$", "_tpl", "->", "cache", "(", "$", "this", ",", "$", "out", ")", ";", "// run it from the cache to be sure dynamics are rendered", "if", "(", "$", "_output", "===", "true", ")", "{", "include", "$", "file", ";", "// exit render mode", "$", "this", "->", "template", "=", "null", ";", "}", "else", "{", "ob_start", "(", ")", ";", "include", "$", "file", ";", "// exit render mode", "$", "this", "->", "template", "=", "null", ";", "return", "ob_get_clean", "(", ")", ";", "}", "}", "else", "{", "// no need to build cache", "// exit render mode", "$", "this", "->", "template", "=", "null", ";", "// output", "if", "(", "$", "_output", "===", "true", ")", "{", "echo", "$", "out", ";", "}", "return", "$", "out", ";", "}", "}", "}" ]
returns the given template rendered using the provided data and optional compiler @param mixed $tpl template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, especially if you render a template multiple times @param mixed $data the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're rendering the template from cache, it can be left null @param Dwoo_ICompiler $compiler the compiler that must be used to compile the template, if left empty a default Dwoo_Compiler will be used. @param bool $output flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true) @return string nothing or the template output if $output is true
[ "returns", "the", "given", "template", "rendered", "using", "the", "provided", "data", "and", "optional", "compiler" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L307-L417
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.initRuntimeVars
protected function initRuntimeVars(Dwoo_ITemplate $tpl) { $this->runtimePlugins = array(); $this->scope =& $this->data; $this->scopeTree = array(); $this->stack = array(); $this->curBlock = null; $this->buffer = ''; }
php
protected function initRuntimeVars(Dwoo_ITemplate $tpl) { $this->runtimePlugins = array(); $this->scope =& $this->data; $this->scopeTree = array(); $this->stack = array(); $this->curBlock = null; $this->buffer = ''; }
[ "protected", "function", "initRuntimeVars", "(", "Dwoo_ITemplate", "$", "tpl", ")", "{", "$", "this", "->", "runtimePlugins", "=", "array", "(", ")", ";", "$", "this", "->", "scope", "=", "&", "$", "this", "->", "data", ";", "$", "this", "->", "scopeTree", "=", "array", "(", ")", ";", "$", "this", "->", "stack", "=", "array", "(", ")", ";", "$", "this", "->", "curBlock", "=", "null", ";", "$", "this", "->", "buffer", "=", "''", ";", "}" ]
re-initializes the runtime variables before each template run override this method to inject data in the globals array if needed, this method is called before each template execution @param Dwoo_ITemplate $tpl the template that is going to be rendered
[ "re", "-", "initializes", "the", "runtime", "variables", "before", "each", "template", "run" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L443-L451
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.addPlugin
public function addPlugin($name, $callback, $compilable = false) { $compilable = $compilable ? self::COMPILABLE_PLUGIN : 0; if (is_array($callback)) { if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) { $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0])); } else { $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]); } } elseif (class_exists($callback, false)) { if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) { $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback); } else { $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback, 'function'=>'process'); } } elseif (function_exists($callback)) { $this->plugins[$name] = array('type'=>self::FUNC_PLUGIN | $compilable, 'callback'=>$callback); } else { throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists'); } }
php
public function addPlugin($name, $callback, $compilable = false) { $compilable = $compilable ? self::COMPILABLE_PLUGIN : 0; if (is_array($callback)) { if (is_subclass_of(is_object($callback[0]) ? get_class($callback[0]) : $callback[0], 'Dwoo_Block_Plugin')) { $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0])); } else { $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>(is_object($callback[0]) ? get_class($callback[0]) : $callback[0]), 'function'=>$callback[1]); } } elseif (class_exists($callback, false)) { if (is_subclass_of($callback, 'Dwoo_Block_Plugin')) { $this->plugins[$name] = array('type'=>self::BLOCK_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback); } else { $this->plugins[$name] = array('type'=>self::CLASS_PLUGIN | $compilable, 'callback'=>$callback, 'class'=>$callback, 'function'=>'process'); } } elseif (function_exists($callback)) { $this->plugins[$name] = array('type'=>self::FUNC_PLUGIN | $compilable, 'callback'=>$callback); } else { throw new Dwoo_Exception('Callback could not be processed correctly, please check that the function/class you used exists'); } }
[ "public", "function", "addPlugin", "(", "$", "name", ",", "$", "callback", ",", "$", "compilable", "=", "false", ")", "{", "$", "compilable", "=", "$", "compilable", "?", "self", "::", "COMPILABLE_PLUGIN", ":", "0", ";", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "if", "(", "is_subclass_of", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", "?", "get_class", "(", "$", "callback", "[", "0", "]", ")", ":", "$", "callback", "[", "0", "]", ",", "'Dwoo_Block_Plugin'", ")", ")", "{", "$", "this", "->", "plugins", "[", "$", "name", "]", "=", "array", "(", "'type'", "=>", "self", "::", "BLOCK_PLUGIN", "|", "$", "compilable", ",", "'callback'", "=>", "$", "callback", ",", "'class'", "=>", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", "?", "get_class", "(", "$", "callback", "[", "0", "]", ")", ":", "$", "callback", "[", "0", "]", ")", ")", ";", "}", "else", "{", "$", "this", "->", "plugins", "[", "$", "name", "]", "=", "array", "(", "'type'", "=>", "self", "::", "CLASS_PLUGIN", "|", "$", "compilable", ",", "'callback'", "=>", "$", "callback", ",", "'class'", "=>", "(", "is_object", "(", "$", "callback", "[", "0", "]", ")", "?", "get_class", "(", "$", "callback", "[", "0", "]", ")", ":", "$", "callback", "[", "0", "]", ")", ",", "'function'", "=>", "$", "callback", "[", "1", "]", ")", ";", "}", "}", "elseif", "(", "class_exists", "(", "$", "callback", ",", "false", ")", ")", "{", "if", "(", "is_subclass_of", "(", "$", "callback", ",", "'Dwoo_Block_Plugin'", ")", ")", "{", "$", "this", "->", "plugins", "[", "$", "name", "]", "=", "array", "(", "'type'", "=>", "self", "::", "BLOCK_PLUGIN", "|", "$", "compilable", ",", "'callback'", "=>", "$", "callback", ",", "'class'", "=>", "$", "callback", ")", ";", "}", "else", "{", "$", "this", "->", "plugins", "[", "$", "name", "]", "=", "array", "(", "'type'", "=>", "self", "::", "CLASS_PLUGIN", "|", "$", "compilable", ",", "'callback'", "=>", "$", "callback", ",", "'class'", "=>", "$", "callback", ",", "'function'", "=>", "'process'", ")", ";", "}", "}", "elseif", "(", "function_exists", "(", "$", "callback", ")", ")", "{", "$", "this", "->", "plugins", "[", "$", "name", "]", "=", "array", "(", "'type'", "=>", "self", "::", "FUNC_PLUGIN", "|", "$", "compilable", ",", "'callback'", "=>", "$", "callback", ")", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Callback could not be processed correctly, please check that the function/class you used exists'", ")", ";", "}", "}" ]
adds a custom plugin that is not in one of the plugin directories @param string $name the plugin name to be used in the templates @param callback $callback the plugin callback, either a function name, a class name or an array containing an object or class name and a method name @param bool $compilable if set to true, the plugin is assumed to be compilable
[ "adds", "a", "custom", "plugin", "that", "is", "not", "in", "one", "of", "the", "plugin", "directories" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L466-L486
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.addFilter
public function addFilter($callback, $autoload = false) { if ($autoload) { $class = 'Dwoo_Filter_'.$callback; if (!class_exists($class, false) && !function_exists($class)) { try { $this->getLoader()->loadPlugin($callback); } catch (Dwoo_Exception $e) { if (strstr($callback, 'Dwoo_Filter_')) { throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"'); } else { throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); } } } if (class_exists($class, false)) { $callback = array(new $class($this), 'process'); } elseif (function_exists($class)) { $callback = $class; } else { throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); } $this->filters[] = $callback; } else { $this->filters[] = $callback; } }
php
public function addFilter($callback, $autoload = false) { if ($autoload) { $class = 'Dwoo_Filter_'.$callback; if (!class_exists($class, false) && !function_exists($class)) { try { $this->getLoader()->loadPlugin($callback); } catch (Dwoo_Exception $e) { if (strstr($callback, 'Dwoo_Filter_')) { throw new Dwoo_Exception('Wrong filter name : '.$callback.', the "Dwoo_Filter_" prefix should not be used, please only use "'.str_replace('Dwoo_Filter_', '', $callback).'"'); } else { throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); } } } if (class_exists($class, false)) { $callback = array(new $class($this), 'process'); } elseif (function_exists($class)) { $callback = $class; } else { throw new Dwoo_Exception('Wrong filter name : '.$callback.', when using autoload the filter must be in one of your plugin dir as "name.php" containg a class or function named "Dwoo_Filter_name"'); } $this->filters[] = $callback; } else { $this->filters[] = $callback; } }
[ "public", "function", "addFilter", "(", "$", "callback", ",", "$", "autoload", "=", "false", ")", "{", "if", "(", "$", "autoload", ")", "{", "$", "class", "=", "'Dwoo_Filter_'", ".", "$", "callback", ";", "if", "(", "!", "class_exists", "(", "$", "class", ",", "false", ")", "&&", "!", "function_exists", "(", "$", "class", ")", ")", "{", "try", "{", "$", "this", "->", "getLoader", "(", ")", "->", "loadPlugin", "(", "$", "callback", ")", ";", "}", "catch", "(", "Dwoo_Exception", "$", "e", ")", "{", "if", "(", "strstr", "(", "$", "callback", ",", "'Dwoo_Filter_'", ")", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Wrong filter name : '", ".", "$", "callback", ".", "', the \"Dwoo_Filter_\" prefix should not be used, please only use \"'", ".", "str_replace", "(", "'Dwoo_Filter_'", ",", "''", ",", "$", "callback", ")", ".", "'\"'", ")", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Wrong filter name : '", ".", "$", "callback", ".", "', when using autoload the filter must be in one of your plugin dir as \"name.php\" containg a class or function named \"Dwoo_Filter_name\"'", ")", ";", "}", "}", "}", "if", "(", "class_exists", "(", "$", "class", ",", "false", ")", ")", "{", "$", "callback", "=", "array", "(", "new", "$", "class", "(", "$", "this", ")", ",", "'process'", ")", ";", "}", "elseif", "(", "function_exists", "(", "$", "class", ")", ")", "{", "$", "callback", "=", "$", "class", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Wrong filter name : '", ".", "$", "callback", ".", "', when using autoload the filter must be in one of your plugin dir as \"name.php\" containg a class or function named \"Dwoo_Filter_name\"'", ")", ";", "}", "$", "this", "->", "filters", "[", "]", "=", "$", "callback", ";", "}", "else", "{", "$", "this", "->", "filters", "[", "]", "=", "$", "callback", ";", "}", "}" ]
adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this instance @param mixed $callback a callback or a filter name if it is autoloaded from a plugin directory @param bool $autoload if true, the first parameter must be a filter name from one of the plugin directories
[ "adds", "a", "filter", "to", "this", "Dwoo", "instance", "it", "will", "be", "used", "to", "filter", "the", "output", "of", "all", "the", "templates", "rendered", "by", "this", "instance" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L506-L535
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.removeFilter
public function removeFilter($callback) { if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) { unset($this->filters[$index]); } elseif (($index = array_search($callback, $this->filters, true)) !== false) { unset($this->filters[$index]); } else { $class = 'Dwoo_Filter_' . $callback; foreach ($this->filters as $index=>$filter) { if (is_array($filter) && $filter[0] instanceof $class) { unset($this->filters[$index]); break; } } } }
php
public function removeFilter($callback) { if (($index = array_search('Dwoo_Filter_'.$callback, $this->filters, true)) !== false) { unset($this->filters[$index]); } elseif (($index = array_search($callback, $this->filters, true)) !== false) { unset($this->filters[$index]); } else { $class = 'Dwoo_Filter_' . $callback; foreach ($this->filters as $index=>$filter) { if (is_array($filter) && $filter[0] instanceof $class) { unset($this->filters[$index]); break; } } } }
[ "public", "function", "removeFilter", "(", "$", "callback", ")", "{", "if", "(", "(", "$", "index", "=", "array_search", "(", "'Dwoo_Filter_'", ".", "$", "callback", ",", "$", "this", "->", "filters", ",", "true", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "filters", "[", "$", "index", "]", ")", ";", "}", "elseif", "(", "(", "$", "index", "=", "array_search", "(", "$", "callback", ",", "$", "this", "->", "filters", ",", "true", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "filters", "[", "$", "index", "]", ")", ";", "}", "else", "{", "$", "class", "=", "'Dwoo_Filter_'", ".", "$", "callback", ";", "foreach", "(", "$", "this", "->", "filters", "as", "$", "index", "=>", "$", "filter", ")", "{", "if", "(", "is_array", "(", "$", "filter", ")", "&&", "$", "filter", "[", "0", "]", "instanceof", "$", "class", ")", "{", "unset", "(", "$", "this", "->", "filters", "[", "$", "index", "]", ")", ";", "break", ";", "}", "}", "}", "}" ]
removes a filter @param mixed $callback callback or filter name if it was autoloaded
[ "removes", "a", "filter" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L542-L557
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.addResource
public function addResource($name, $class, $compilerFactory = null) { if (strlen($name) < 2) { throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths'); } if (!class_exists($class)) { throw new Dwoo_Exception('Resource class does not exist'); } $interfaces = class_implements($class); if (in_array('Dwoo_ITemplate', $interfaces) === false) { throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate'); } $this->resources[$name] = array('class'=>$class, 'compiler'=>$compilerFactory); }
php
public function addResource($name, $class, $compilerFactory = null) { if (strlen($name) < 2) { throw new Dwoo_Exception('Resource names must be at least two-character long to avoid conflicts with Windows paths'); } if (!class_exists($class)) { throw new Dwoo_Exception('Resource class does not exist'); } $interfaces = class_implements($class); if (in_array('Dwoo_ITemplate', $interfaces) === false) { throw new Dwoo_Exception('Resource class must implement Dwoo_ITemplate'); } $this->resources[$name] = array('class'=>$class, 'compiler'=>$compilerFactory); }
[ "public", "function", "addResource", "(", "$", "name", ",", "$", "class", ",", "$", "compilerFactory", "=", "null", ")", "{", "if", "(", "strlen", "(", "$", "name", ")", "<", "2", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Resource names must be at least two-character long to avoid conflicts with Windows paths'", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Resource class does not exist'", ")", ";", "}", "$", "interfaces", "=", "class_implements", "(", "$", "class", ")", ";", "if", "(", "in_array", "(", "'Dwoo_ITemplate'", ",", "$", "interfaces", ")", "===", "false", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'Resource class must implement Dwoo_ITemplate'", ")", ";", "}", "$", "this", "->", "resources", "[", "$", "name", "]", "=", "array", "(", "'class'", "=>", "$", "class", ",", "'compiler'", "=>", "$", "compilerFactory", ")", ";", "}" ]
adds a resource or overrides a default one @param string $name the resource name @param string $class the resource class (which must implement Dwoo_ITemplate) @param callback $compilerFactory the compiler factory callback, a function that must return a compiler instance used to compile this resource, if none is provided. by default it will produce a Dwoo_Compiler object
[ "adds", "a", "resource", "or", "overrides", "a", "default", "one" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L566-L582
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.getLoader
public function getLoader() { if ($this->loader === null) { $this->loader = new Dwoo_Loader($this->getCompileDir()); } return $this->loader; }
php
public function getLoader() { if ($this->loader === null) { $this->loader = new Dwoo_Loader($this->getCompileDir()); } return $this->loader; }
[ "public", "function", "getLoader", "(", ")", "{", "if", "(", "$", "this", "->", "loader", "===", "null", ")", "{", "$", "this", "->", "loader", "=", "new", "Dwoo_Loader", "(", "$", "this", "->", "getCompileDir", "(", ")", ")", ";", "}", "return", "$", "this", "->", "loader", ";", "}" ]
returns the current loader object or a default one if none is currently found @param Dwoo_ILoader
[ "returns", "the", "current", "loader", "object", "or", "a", "default", "one", "if", "none", "is", "currently", "found" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L616-L623
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.getCacheDir
public function getCacheDir() { if ($this->cacheDir === null) { $this->setCacheDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); } return $this->cacheDir; }
php
public function getCacheDir() { if ($this->cacheDir === null) { $this->setCacheDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); } return $this->cacheDir; }
[ "public", "function", "getCacheDir", "(", ")", "{", "if", "(", "$", "this", "->", "cacheDir", "===", "null", ")", "{", "$", "this", "->", "setCacheDir", "(", "dirname", "(", "__FILE__", ")", ".", "DIRECTORY_SEPARATOR", ".", "'cache'", ".", "DIRECTORY_SEPARATOR", ")", ";", "}", "return", "$", "this", "->", "cacheDir", ";", "}" ]
returns the cache directory with a trailing DIRECTORY_SEPARATOR @return string
[ "returns", "the", "cache", "directory", "with", "a", "trailing", "DIRECTORY_SEPARATOR" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L642-L649
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.setCacheDir
public function setCacheDir($dir) { $this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; if (is_writable($this->cacheDir) === false) { throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable'); } }
php
public function setCacheDir($dir) { $this->cacheDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; if (is_writable($this->cacheDir) === false) { throw new Dwoo_Exception('The cache directory must be writable, chmod "'.$this->cacheDir.'" to make it writable'); } }
[ "public", "function", "setCacheDir", "(", "$", "dir", ")", "{", "$", "this", "->", "cacheDir", "=", "rtrim", "(", "$", "dir", ",", "'/\\\\'", ")", ".", "DIRECTORY_SEPARATOR", ";", "if", "(", "is_writable", "(", "$", "this", "->", "cacheDir", ")", "===", "false", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'The cache directory must be writable, chmod \"'", ".", "$", "this", "->", "cacheDir", ".", "'\" to make it writable'", ")", ";", "}", "}" ]
sets the cache directory and automatically appends a DIRECTORY_SEPARATOR @param string $dir the cache directory
[ "sets", "the", "cache", "directory", "and", "automatically", "appends", "a", "DIRECTORY_SEPARATOR" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L656-L662
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.getCompileDir
public function getCompileDir() { if ($this->compileDir === null) { $this->setCompileDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'compiled'.DIRECTORY_SEPARATOR); } return $this->compileDir; }
php
public function getCompileDir() { if ($this->compileDir === null) { $this->setCompileDir(dirname(__FILE__).DIRECTORY_SEPARATOR.'compiled'.DIRECTORY_SEPARATOR); } return $this->compileDir; }
[ "public", "function", "getCompileDir", "(", ")", "{", "if", "(", "$", "this", "->", "compileDir", "===", "null", ")", "{", "$", "this", "->", "setCompileDir", "(", "dirname", "(", "__FILE__", ")", ".", "DIRECTORY_SEPARATOR", ".", "'compiled'", ".", "DIRECTORY_SEPARATOR", ")", ";", "}", "return", "$", "this", "->", "compileDir", ";", "}" ]
returns the compile directory with a trailing DIRECTORY_SEPARATOR @return string
[ "returns", "the", "compile", "directory", "with", "a", "trailing", "DIRECTORY_SEPARATOR" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L669-L676
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.setCompileDir
public function setCompileDir($dir) { $this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; if (is_writable($this->compileDir) === false) { throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable'); } }
php
public function setCompileDir($dir) { $this->compileDir = rtrim($dir, '/\\').DIRECTORY_SEPARATOR; if (is_writable($this->compileDir) === false) { throw new Dwoo_Exception('The compile directory must be writable, chmod "'.$this->compileDir.'" to make it writable'); } }
[ "public", "function", "setCompileDir", "(", "$", "dir", ")", "{", "$", "this", "->", "compileDir", "=", "rtrim", "(", "$", "dir", ",", "'/\\\\'", ")", ".", "DIRECTORY_SEPARATOR", ";", "if", "(", "is_writable", "(", "$", "this", "->", "compileDir", ")", "===", "false", ")", "{", "throw", "new", "Dwoo_Exception", "(", "'The compile directory must be writable, chmod \"'", ".", "$", "this", "->", "compileDir", ".", "'\" to make it writable'", ")", ";", "}", "}" ]
sets the compile directory and automatically appends a DIRECTORY_SEPARATOR @param string $dir the compile directory
[ "sets", "the", "compile", "directory", "and", "automatically", "appends", "a", "DIRECTORY_SEPARATOR" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L683-L689
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.clearCache
public function clearCache($olderThan=-1) { $cacheDirs = new RecursiveDirectoryIterator($this->getCacheDir()); $cache = new RecursiveIteratorIterator($cacheDirs); $expired = time() - $olderThan; $count = 0; foreach ($cache as $file) { if ($cache->isDot() || $cache->isDir() || substr($file, -5) !== '.html') { continue; } if ($cache->getCTime() < $expired) { $count += unlink((string) $file) ? 1 : 0; } } return $count; }
php
public function clearCache($olderThan=-1) { $cacheDirs = new RecursiveDirectoryIterator($this->getCacheDir()); $cache = new RecursiveIteratorIterator($cacheDirs); $expired = time() - $olderThan; $count = 0; foreach ($cache as $file) { if ($cache->isDot() || $cache->isDir() || substr($file, -5) !== '.html') { continue; } if ($cache->getCTime() < $expired) { $count += unlink((string) $file) ? 1 : 0; } } return $count; }
[ "public", "function", "clearCache", "(", "$", "olderThan", "=", "-", "1", ")", "{", "$", "cacheDirs", "=", "new", "RecursiveDirectoryIterator", "(", "$", "this", "->", "getCacheDir", "(", ")", ")", ";", "$", "cache", "=", "new", "RecursiveIteratorIterator", "(", "$", "cacheDirs", ")", ";", "$", "expired", "=", "time", "(", ")", "-", "$", "olderThan", ";", "$", "count", "=", "0", ";", "foreach", "(", "$", "cache", "as", "$", "file", ")", "{", "if", "(", "$", "cache", "->", "isDot", "(", ")", "||", "$", "cache", "->", "isDir", "(", ")", "||", "substr", "(", "$", "file", ",", "-", "5", ")", "!==", "'.html'", ")", "{", "continue", ";", "}", "if", "(", "$", "cache", "->", "getCTime", "(", ")", "<", "$", "expired", ")", "{", "$", "count", "+=", "unlink", "(", "(", "string", ")", "$", "file", ")", "?", "1", ":", "0", ";", "}", "}", "return", "$", "count", ";", "}" ]
[util function] clears the cached templates if they are older than the given time @param int $olderThan minimum time (in seconds) required for a cached template to be cleared @return int the amount of templates cleared
[ "[", "util", "function", "]", "clears", "the", "cached", "templates", "if", "they", "are", "older", "than", "the", "given", "time" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L841-L856
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.templateFactory
public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null) { if (isset($this->resources[$resourceName])) { // TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe return call_user_func(array($this->resources[$resourceName]['class'], 'templateFactory'), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate); } else { throw new Dwoo_Exception('Unknown resource type : '.$resourceName); } }
php
public function templateFactory($resourceName, $resourceId, $cacheTime = null, $cacheId = null, $compileId = null, Dwoo_ITemplate $parentTemplate = null) { if (isset($this->resources[$resourceName])) { // TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe return call_user_func(array($this->resources[$resourceName]['class'], 'templateFactory'), $this, $resourceId, $cacheTime, $cacheId, $compileId, $parentTemplate); } else { throw new Dwoo_Exception('Unknown resource type : '.$resourceName); } }
[ "public", "function", "templateFactory", "(", "$", "resourceName", ",", "$", "resourceId", ",", "$", "cacheTime", "=", "null", ",", "$", "cacheId", "=", "null", ",", "$", "compileId", "=", "null", ",", "Dwoo_ITemplate", "$", "parentTemplate", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "resources", "[", "$", "resourceName", "]", ")", ")", "{", "// TODO could be changed to $this->resources[$resourceName]['class']::templateFactory(..) in 5.3 maybe", "return", "call_user_func", "(", "array", "(", "$", "this", "->", "resources", "[", "$", "resourceName", "]", "[", "'class'", "]", ",", "'templateFactory'", ")", ",", "$", "this", ",", "$", "resourceId", ",", "$", "cacheTime", ",", "$", "cacheId", ",", "$", "compileId", ",", "$", "parentTemplate", ")", ";", "}", "else", "{", "throw", "new", "Dwoo_Exception", "(", "'Unknown resource type : '", ".", "$", "resourceName", ")", ";", "}", "}" ]
[util function] fetches a template object of the given resource @param string $resourceName the resource name (i.e. file, string) @param string $resourceId the resource identifier (i.e. file path) @param int $cacheTime the cache time setting for this resource @param string $cacheId the unique cache identifier @param string $compileId the unique compiler identifier @return Dwoo_ITemplate
[ "[", "util", "function", "]", "fetches", "a", "template", "object", "of", "the", "given", "resource" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L868-L876
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.isArray
public function isArray($value, $checkIsEmpty=false) { if (is_array($value) === true) { if ($checkIsEmpty === false) { return true; } else { return count($value) > 0; } } elseif ($value instanceof Iterator) { if ($checkIsEmpty === false) { return true; } elseif ($value instanceof Countable) { return count($value) > 0; } else { $value->rewind(); return $value->valid(); } } elseif ($value instanceof ArrayAccess) { if ($checkIsEmpty === false) { return true; } elseif ($value instanceof Countable) { return count($value) > 0; } else { return $value->offsetExists(0); } } return false; }
php
public function isArray($value, $checkIsEmpty=false) { if (is_array($value) === true) { if ($checkIsEmpty === false) { return true; } else { return count($value) > 0; } } elseif ($value instanceof Iterator) { if ($checkIsEmpty === false) { return true; } elseif ($value instanceof Countable) { return count($value) > 0; } else { $value->rewind(); return $value->valid(); } } elseif ($value instanceof ArrayAccess) { if ($checkIsEmpty === false) { return true; } elseif ($value instanceof Countable) { return count($value) > 0; } else { return $value->offsetExists(0); } } return false; }
[ "public", "function", "isArray", "(", "$", "value", ",", "$", "checkIsEmpty", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "===", "true", ")", "{", "if", "(", "$", "checkIsEmpty", "===", "false", ")", "{", "return", "true", ";", "}", "else", "{", "return", "count", "(", "$", "value", ")", ">", "0", ";", "}", "}", "elseif", "(", "$", "value", "instanceof", "Iterator", ")", "{", "if", "(", "$", "checkIsEmpty", "===", "false", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "value", "instanceof", "Countable", ")", "{", "return", "count", "(", "$", "value", ")", ">", "0", ";", "}", "else", "{", "$", "value", "->", "rewind", "(", ")", ";", "return", "$", "value", "->", "valid", "(", ")", ";", "}", "}", "elseif", "(", "$", "value", "instanceof", "ArrayAccess", ")", "{", "if", "(", "$", "checkIsEmpty", "===", "false", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "value", "instanceof", "Countable", ")", "{", "return", "count", "(", "$", "value", ")", ">", "0", ";", "}", "else", "{", "return", "$", "value", "->", "offsetExists", "(", "0", ")", ";", "}", "}", "return", "false", ";", "}" ]
[util function] checks if the input is an array or an iterator object, optionally it can also check if it's empty @param mixed $value the variable to check @param bool $checkIsEmpty if true, the function will also check if the array is empty, and return true only if it's not empty @return bool true if it's an array (and not empty) or false if it's not an array (or if it's empty)
[ "[", "util", "function", "]", "checks", "if", "the", "input", "is", "an", "array", "or", "an", "iterator", "object", "optionally", "it", "can", "also", "check", "if", "it", "s", "empty" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L886-L913
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.addStack
public function addStack($blockName, array $args=array()) { if (isset($this->plugins[$blockName])) { $class = $this->plugins[$blockName]['class']; } else { $class = 'Dwoo_Plugin_'.$blockName; } if ($this->curBlock !== null) { $this->curBlock->buffer(ob_get_contents()); ob_clean(); } else { $this->buffer .= ob_get_contents(); ob_clean(); } $block = new $class($this); $cnt = count($args); if ($cnt===0) { $block->init(); } elseif ($cnt===1) { $block->init($args[0]); } elseif ($cnt===2) { $block->init($args[0], $args[1]); } elseif ($cnt===3) { $block->init($args[0], $args[1], $args[2]); } elseif ($cnt===4) { $block->init($args[0], $args[1], $args[2], $args[3]); } else { call_user_func_array(array($block,'init'), $args); } $this->stack[] = $this->curBlock = $block; return $block; }
php
public function addStack($blockName, array $args=array()) { if (isset($this->plugins[$blockName])) { $class = $this->plugins[$blockName]['class']; } else { $class = 'Dwoo_Plugin_'.$blockName; } if ($this->curBlock !== null) { $this->curBlock->buffer(ob_get_contents()); ob_clean(); } else { $this->buffer .= ob_get_contents(); ob_clean(); } $block = new $class($this); $cnt = count($args); if ($cnt===0) { $block->init(); } elseif ($cnt===1) { $block->init($args[0]); } elseif ($cnt===2) { $block->init($args[0], $args[1]); } elseif ($cnt===3) { $block->init($args[0], $args[1], $args[2]); } elseif ($cnt===4) { $block->init($args[0], $args[1], $args[2], $args[3]); } else { call_user_func_array(array($block,'init'), $args); } $this->stack[] = $this->curBlock = $block; return $block; }
[ "public", "function", "addStack", "(", "$", "blockName", ",", "array", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "plugins", "[", "$", "blockName", "]", ")", ")", "{", "$", "class", "=", "$", "this", "->", "plugins", "[", "$", "blockName", "]", "[", "'class'", "]", ";", "}", "else", "{", "$", "class", "=", "'Dwoo_Plugin_'", ".", "$", "blockName", ";", "}", "if", "(", "$", "this", "->", "curBlock", "!==", "null", ")", "{", "$", "this", "->", "curBlock", "->", "buffer", "(", "ob_get_contents", "(", ")", ")", ";", "ob_clean", "(", ")", ";", "}", "else", "{", "$", "this", "->", "buffer", ".=", "ob_get_contents", "(", ")", ";", "ob_clean", "(", ")", ";", "}", "$", "block", "=", "new", "$", "class", "(", "$", "this", ")", ";", "$", "cnt", "=", "count", "(", "$", "args", ")", ";", "if", "(", "$", "cnt", "===", "0", ")", "{", "$", "block", "->", "init", "(", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "1", ")", "{", "$", "block", "->", "init", "(", "$", "args", "[", "0", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "2", ")", "{", "$", "block", "->", "init", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "3", ")", "{", "$", "block", "->", "init", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "args", "[", "2", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "4", ")", "{", "$", "block", "->", "init", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "args", "[", "2", "]", ",", "$", "args", "[", "3", "]", ")", ";", "}", "else", "{", "call_user_func_array", "(", "array", "(", "$", "block", ",", "'init'", ")", ",", "$", "args", ")", ";", "}", "$", "this", "->", "stack", "[", "]", "=", "$", "this", "->", "curBlock", "=", "$", "block", ";", "return", "$", "block", ";", "}" ]
[runtime function] adds a block to the block stack @param string $blockName the block name (without Dwoo_Plugin_ prefix) @param array $args the arguments to be passed to the block's init() function @return Dwoo_Block_Plugin the newly created block
[ "[", "runtime", "function", "]", "adds", "a", "block", "to", "the", "block", "stack" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L940-L975
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.delStack
public function delStack() { $args = func_get_args(); $this->curBlock->buffer(ob_get_contents()); ob_clean(); $cnt = count($args); if ($cnt===0) { $this->curBlock->end(); } elseif ($cnt===1) { $this->curBlock->end($args[0]); } elseif ($cnt===2) { $this->curBlock->end($args[0], $args[1]); } elseif ($cnt===3) { $this->curBlock->end($args[0], $args[1], $args[2]); } elseif ($cnt===4) { $this->curBlock->end($args[0], $args[1], $args[2], $args[3]); } else { call_user_func_array(array($this->curBlock, 'end'), $args); } $tmp = array_pop($this->stack); if (count($this->stack) > 0) { $this->curBlock = end($this->stack); $this->curBlock->buffer($tmp->process()); } else { $this->curBlock = null; echo $tmp->process(); } unset($tmp); }
php
public function delStack() { $args = func_get_args(); $this->curBlock->buffer(ob_get_contents()); ob_clean(); $cnt = count($args); if ($cnt===0) { $this->curBlock->end(); } elseif ($cnt===1) { $this->curBlock->end($args[0]); } elseif ($cnt===2) { $this->curBlock->end($args[0], $args[1]); } elseif ($cnt===3) { $this->curBlock->end($args[0], $args[1], $args[2]); } elseif ($cnt===4) { $this->curBlock->end($args[0], $args[1], $args[2], $args[3]); } else { call_user_func_array(array($this->curBlock, 'end'), $args); } $tmp = array_pop($this->stack); if (count($this->stack) > 0) { $this->curBlock = end($this->stack); $this->curBlock->buffer($tmp->process()); } else { $this->curBlock = null; echo $tmp->process(); } unset($tmp); }
[ "public", "function", "delStack", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "this", "->", "curBlock", "->", "buffer", "(", "ob_get_contents", "(", ")", ")", ";", "ob_clean", "(", ")", ";", "$", "cnt", "=", "count", "(", "$", "args", ")", ";", "if", "(", "$", "cnt", "===", "0", ")", "{", "$", "this", "->", "curBlock", "->", "end", "(", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "1", ")", "{", "$", "this", "->", "curBlock", "->", "end", "(", "$", "args", "[", "0", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "2", ")", "{", "$", "this", "->", "curBlock", "->", "end", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "3", ")", "{", "$", "this", "->", "curBlock", "->", "end", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "args", "[", "2", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "4", ")", "{", "$", "this", "->", "curBlock", "->", "end", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "args", "[", "2", "]", ",", "$", "args", "[", "3", "]", ")", ";", "}", "else", "{", "call_user_func_array", "(", "array", "(", "$", "this", "->", "curBlock", ",", "'end'", ")", ",", "$", "args", ")", ";", "}", "$", "tmp", "=", "array_pop", "(", "$", "this", "->", "stack", ")", ";", "if", "(", "count", "(", "$", "this", "->", "stack", ")", ">", "0", ")", "{", "$", "this", "->", "curBlock", "=", "end", "(", "$", "this", "->", "stack", ")", ";", "$", "this", "->", "curBlock", "->", "buffer", "(", "$", "tmp", "->", "process", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "curBlock", "=", "null", ";", "echo", "$", "tmp", "->", "process", "(", ")", ";", "}", "unset", "(", "$", "tmp", ")", ";", "}" ]
[runtime function] removes the plugin at the top of the block stack calls the block buffer() function, followed by a call to end() and finally a call to process()
[ "[", "runtime", "function", "]", "removes", "the", "plugin", "at", "the", "top", "of", "the", "block", "stack" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L983-L1016
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.getParentBlock
public function getParentBlock(Dwoo_Block_Plugin $block) { $index = array_search($block, $this->stack, true); if ($index !== false && $index > 0) { return $this->stack[$index-1]; } return false; }
php
public function getParentBlock(Dwoo_Block_Plugin $block) { $index = array_search($block, $this->stack, true); if ($index !== false && $index > 0) { return $this->stack[$index-1]; } return false; }
[ "public", "function", "getParentBlock", "(", "Dwoo_Block_Plugin", "$", "block", ")", "{", "$", "index", "=", "array_search", "(", "$", "block", ",", "$", "this", "->", "stack", ",", "true", ")", ";", "if", "(", "$", "index", "!==", "false", "&&", "$", "index", ">", "0", ")", "{", "return", "$", "this", "->", "stack", "[", "$", "index", "-", "1", "]", ";", "}", "return", "false", ";", "}" ]
[runtime function] returns the parent block of the given block @param Dwoo_Block_Plugin $block @return Dwoo_Block_Plugin or false if the given block isn't in the stack
[ "[", "runtime", "function", "]", "returns", "the", "parent", "block", "of", "the", "given", "block" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L1024-L1031
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.findBlock
public function findBlock($type) { if (isset($this->plugins[$type])) { $type = $this->plugins[$type]['class']; } else { $type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type); } $keys = array_keys($this->stack); while (($key = array_pop($keys)) !== false) { if ($this->stack[$key] instanceof $type) { return $this->stack[$key]; } } return false; }
php
public function findBlock($type) { if (isset($this->plugins[$type])) { $type = $this->plugins[$type]['class']; } else { $type = 'Dwoo_Plugin_'.str_replace('Dwoo_Plugin_', '', $type); } $keys = array_keys($this->stack); while (($key = array_pop($keys)) !== false) { if ($this->stack[$key] instanceof $type) { return $this->stack[$key]; } } return false; }
[ "public", "function", "findBlock", "(", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "plugins", "[", "$", "type", "]", ")", ")", "{", "$", "type", "=", "$", "this", "->", "plugins", "[", "$", "type", "]", "[", "'class'", "]", ";", "}", "else", "{", "$", "type", "=", "'Dwoo_Plugin_'", ".", "str_replace", "(", "'Dwoo_Plugin_'", ",", "''", ",", "$", "type", ")", ";", "}", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "stack", ")", ";", "while", "(", "(", "$", "key", "=", "array_pop", "(", "$", "keys", ")", ")", "!==", "false", ")", "{", "if", "(", "$", "this", "->", "stack", "[", "$", "key", "]", "instanceof", "$", "type", ")", "{", "return", "$", "this", "->", "stack", "[", "$", "key", "]", ";", "}", "}", "return", "false", ";", "}" ]
[runtime function] finds the closest block of the given type, starting at the top of the stack @param string $type the type of plugin you want to find @return Dwoo_Block_Plugin or false if no plugin of such type is in the stack
[ "[", "runtime", "function", "]", "finds", "the", "closest", "block", "of", "the", "given", "type", "starting", "at", "the", "top", "of", "the", "stack" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L1039-L1054
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.classCall
public function classCall($plugName, array $params = array()) { $class = 'Dwoo_Plugin_'.$plugName; $plugin = $this->getObjectPlugin($class); $cnt = count($params); if ($cnt===0) { return $plugin->process(); } elseif ($cnt===1) { return $plugin->process($params[0]); } elseif ($cnt===2) { return $plugin->process($params[0], $params[1]); } elseif ($cnt===3) { return $plugin->process($params[0], $params[1], $params[2]); } elseif ($cnt===4) { return $plugin->process($params[0], $params[1], $params[2], $params[3]); } else { return call_user_func_array(array($plugin, 'process'), $params); } }
php
public function classCall($plugName, array $params = array()) { $class = 'Dwoo_Plugin_'.$plugName; $plugin = $this->getObjectPlugin($class); $cnt = count($params); if ($cnt===0) { return $plugin->process(); } elseif ($cnt===1) { return $plugin->process($params[0]); } elseif ($cnt===2) { return $plugin->process($params[0], $params[1]); } elseif ($cnt===3) { return $plugin->process($params[0], $params[1], $params[2]); } elseif ($cnt===4) { return $plugin->process($params[0], $params[1], $params[2], $params[3]); } else { return call_user_func_array(array($plugin, 'process'), $params); } }
[ "public", "function", "classCall", "(", "$", "plugName", ",", "array", "$", "params", "=", "array", "(", ")", ")", "{", "$", "class", "=", "'Dwoo_Plugin_'", ".", "$", "plugName", ";", "$", "plugin", "=", "$", "this", "->", "getObjectPlugin", "(", "$", "class", ")", ";", "$", "cnt", "=", "count", "(", "$", "params", ")", ";", "if", "(", "$", "cnt", "===", "0", ")", "{", "return", "$", "plugin", "->", "process", "(", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "1", ")", "{", "return", "$", "plugin", "->", "process", "(", "$", "params", "[", "0", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "2", ")", "{", "return", "$", "plugin", "->", "process", "(", "$", "params", "[", "0", "]", ",", "$", "params", "[", "1", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "3", ")", "{", "return", "$", "plugin", "->", "process", "(", "$", "params", "[", "0", "]", ",", "$", "params", "[", "1", "]", ",", "$", "params", "[", "2", "]", ")", ";", "}", "elseif", "(", "$", "cnt", "===", "4", ")", "{", "return", "$", "plugin", "->", "process", "(", "$", "params", "[", "0", "]", ",", "$", "params", "[", "1", "]", ",", "$", "params", "[", "2", "]", ",", "$", "params", "[", "3", "]", ")", ";", "}", "else", "{", "return", "call_user_func_array", "(", "array", "(", "$", "plugin", ",", "'process'", ")", ",", "$", "params", ")", ";", "}", "}" ]
[runtime function] calls the process() method of the given class-plugin name @param string $plugName the class plugin name (without Dwoo_Plugin_ prefix) @param array $params an array of parameters to send to the process() method @return string the process() return value
[ "[", "runtime", "function", "]", "calls", "the", "process", "()", "method", "of", "the", "given", "class", "-", "plugin", "name" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L1081-L1101
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.readVarInto
public function readVarInto($varstr, $data, $safeRead = false) { if ($data === null) { return null; } if (is_array($varstr) === false) { preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m); } else { $m = $varstr; } unset($varstr); while (list($k, $sep) = each($m[1])) { if ($sep === '.' || $sep === '[' || $sep === '') { if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) { $data = $data[$m[2][$k]]; } else { return null; } } else { if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]) || is_callable(array($data, '__get')))) { $data = $data->$m[2][$k]; } else { return null; } } } return $data; }
php
public function readVarInto($varstr, $data, $safeRead = false) { if ($data === null) { return null; } if (is_array($varstr) === false) { preg_match_all('#(\[|->|\.)?((?:[^.[\]-]|-(?!>))+)\]?#i', $varstr, $m); } else { $m = $varstr; } unset($varstr); while (list($k, $sep) = each($m[1])) { if ($sep === '.' || $sep === '[' || $sep === '') { if ((is_array($data) || $data instanceof ArrayAccess) && ($safeRead === false || isset($data[$m[2][$k]]))) { $data = $data[$m[2][$k]]; } else { return null; } } else { if (is_object($data) && ($safeRead === false || isset($data->$m[2][$k]) || is_callable(array($data, '__get')))) { $data = $data->$m[2][$k]; } else { return null; } } } return $data; }
[ "public", "function", "readVarInto", "(", "$", "varstr", ",", "$", "data", ",", "$", "safeRead", "=", "false", ")", "{", "if", "(", "$", "data", "===", "null", ")", "{", "return", "null", ";", "}", "if", "(", "is_array", "(", "$", "varstr", ")", "===", "false", ")", "{", "preg_match_all", "(", "'#(\\[|->|\\.)?((?:[^.[\\]-]|-(?!>))+)\\]?#i'", ",", "$", "varstr", ",", "$", "m", ")", ";", "}", "else", "{", "$", "m", "=", "$", "varstr", ";", "}", "unset", "(", "$", "varstr", ")", ";", "while", "(", "list", "(", "$", "k", ",", "$", "sep", ")", "=", "each", "(", "$", "m", "[", "1", "]", ")", ")", "{", "if", "(", "$", "sep", "===", "'.'", "||", "$", "sep", "===", "'['", "||", "$", "sep", "===", "''", ")", "{", "if", "(", "(", "is_array", "(", "$", "data", ")", "||", "$", "data", "instanceof", "ArrayAccess", ")", "&&", "(", "$", "safeRead", "===", "false", "||", "isset", "(", "$", "data", "[", "$", "m", "[", "2", "]", "[", "$", "k", "]", "]", ")", ")", ")", "{", "$", "data", "=", "$", "data", "[", "$", "m", "[", "2", "]", "[", "$", "k", "]", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "{", "if", "(", "is_object", "(", "$", "data", ")", "&&", "(", "$", "safeRead", "===", "false", "||", "isset", "(", "$", "data", "->", "$", "m", "[", "2", "]", "[", "$", "k", "]", ")", "||", "is_callable", "(", "array", "(", "$", "data", ",", "'__get'", ")", ")", ")", ")", "{", "$", "data", "=", "$", "data", "->", "$", "m", "[", "2", "]", "[", "$", "k", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}", "return", "$", "data", ";", "}" ]
[runtime function] reads a variable into the given data array @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") @param mixed $data the data array or object to read from @param bool $safeRead if true, the function will check whether the index exists to prevent any notices from being output @return mixed
[ "[", "runtime", "function", "]", "reads", "a", "variable", "into", "the", "given", "data", "array" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L1195-L1225
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.readParentVar
public function readParentVar($parentLevels, $varstr = null) { $tree = $this->scopeTree; $cur = $this->data; while ($parentLevels--!==0) { array_pop($tree); } while (($i = array_shift($tree)) !== null) { if (is_object($cur)) { $cur = $cur->$i; } else { $cur = $cur[$i]; } } if ($varstr!==null) { return $this->readVarInto($varstr, $cur); } else { return $cur; } }
php
public function readParentVar($parentLevels, $varstr = null) { $tree = $this->scopeTree; $cur = $this->data; while ($parentLevels--!==0) { array_pop($tree); } while (($i = array_shift($tree)) !== null) { if (is_object($cur)) { $cur = $cur->$i; } else { $cur = $cur[$i]; } } if ($varstr!==null) { return $this->readVarInto($varstr, $cur); } else { return $cur; } }
[ "public", "function", "readParentVar", "(", "$", "parentLevels", ",", "$", "varstr", "=", "null", ")", "{", "$", "tree", "=", "$", "this", "->", "scopeTree", ";", "$", "cur", "=", "$", "this", "->", "data", ";", "while", "(", "$", "parentLevels", "--", "!==", "0", ")", "{", "array_pop", "(", "$", "tree", ")", ";", "}", "while", "(", "(", "$", "i", "=", "array_shift", "(", "$", "tree", ")", ")", "!==", "null", ")", "{", "if", "(", "is_object", "(", "$", "cur", ")", ")", "{", "$", "cur", "=", "$", "cur", "->", "$", "i", ";", "}", "else", "{", "$", "cur", "=", "$", "cur", "[", "$", "i", "]", ";", "}", "}", "if", "(", "$", "varstr", "!==", "null", ")", "{", "return", "$", "this", "->", "readVarInto", "(", "$", "varstr", ",", "$", "cur", ")", ";", "}", "else", "{", "return", "$", "cur", ";", "}", "}" ]
[runtime function] reads a variable into the parent scope @param int $parentLevels the amount of parent levels to go from the current scope @param string $varstr the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") @return mixed
[ "[", "runtime", "function", "]", "reads", "a", "variable", "into", "the", "parent", "scope" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L1234-L1256
Eresus/EresusCMS
src/core/framework/core/3rdparty/dwoo/Dwoo.php
Dwoo.assignInScope
public function assignInScope($value, $scope) { $tree =& $this->scopeTree; $data =& $this->data; if (!is_string($scope)) { return $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR); } if (strstr($scope, '.') === false && strstr($scope, '->') === false) { $this->scope[$scope] = $value; } else { // TODO handle _root/_parent scopes ? preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m); $cur =& $this->scope; $last = array(array_pop($m[1]), array_pop($m[2])); while (list($k, $sep) = each($m[1])) { if ($sep === '.' || $sep === '[' || $sep === '') { if (is_array($cur) === false) { $cur = array(); } $cur =& $cur[$m[2][$k]]; } elseif ($sep === '->') { if (is_object($cur) === false) { $cur = new stdClass; } $cur =& $cur->$m[2][$k]; } else { return false; } } if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') { if (is_array($cur) === false) { $cur = array(); } $cur[$last[1]] = $value; } elseif ($last[0] === '->') { if (is_object($cur) === false) { $cur = new stdClass; } $cur->$last[1] = $value; } else { return false; } } }
php
public function assignInScope($value, $scope) { $tree =& $this->scopeTree; $data =& $this->data; if (!is_string($scope)) { return $this->triggerError('Assignments must be done into strings, ('.gettype($scope).') '.var_export($scope, true).' given', E_USER_ERROR); } if (strstr($scope, '.') === false && strstr($scope, '->') === false) { $this->scope[$scope] = $value; } else { // TODO handle _root/_parent scopes ? preg_match_all('#(\[|->|\.)?([^.[\]-]+)\]?#i', $scope, $m); $cur =& $this->scope; $last = array(array_pop($m[1]), array_pop($m[2])); while (list($k, $sep) = each($m[1])) { if ($sep === '.' || $sep === '[' || $sep === '') { if (is_array($cur) === false) { $cur = array(); } $cur =& $cur[$m[2][$k]]; } elseif ($sep === '->') { if (is_object($cur) === false) { $cur = new stdClass; } $cur =& $cur->$m[2][$k]; } else { return false; } } if ($last[0] === '.' || $last[0] === '[' || $last[0] === '') { if (is_array($cur) === false) { $cur = array(); } $cur[$last[1]] = $value; } elseif ($last[0] === '->') { if (is_object($cur) === false) { $cur = new stdClass; } $cur->$last[1] = $value; } else { return false; } } }
[ "public", "function", "assignInScope", "(", "$", "value", ",", "$", "scope", ")", "{", "$", "tree", "=", "&", "$", "this", "->", "scopeTree", ";", "$", "data", "=", "&", "$", "this", "->", "data", ";", "if", "(", "!", "is_string", "(", "$", "scope", ")", ")", "{", "return", "$", "this", "->", "triggerError", "(", "'Assignments must be done into strings, ('", ".", "gettype", "(", "$", "scope", ")", ".", "') '", ".", "var_export", "(", "$", "scope", ",", "true", ")", ".", "' given'", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "strstr", "(", "$", "scope", ",", "'.'", ")", "===", "false", "&&", "strstr", "(", "$", "scope", ",", "'->'", ")", "===", "false", ")", "{", "$", "this", "->", "scope", "[", "$", "scope", "]", "=", "$", "value", ";", "}", "else", "{", "// TODO handle _root/_parent scopes ?", "preg_match_all", "(", "'#(\\[|->|\\.)?([^.[\\]-]+)\\]?#i'", ",", "$", "scope", ",", "$", "m", ")", ";", "$", "cur", "=", "&", "$", "this", "->", "scope", ";", "$", "last", "=", "array", "(", "array_pop", "(", "$", "m", "[", "1", "]", ")", ",", "array_pop", "(", "$", "m", "[", "2", "]", ")", ")", ";", "while", "(", "list", "(", "$", "k", ",", "$", "sep", ")", "=", "each", "(", "$", "m", "[", "1", "]", ")", ")", "{", "if", "(", "$", "sep", "===", "'.'", "||", "$", "sep", "===", "'['", "||", "$", "sep", "===", "''", ")", "{", "if", "(", "is_array", "(", "$", "cur", ")", "===", "false", ")", "{", "$", "cur", "=", "array", "(", ")", ";", "}", "$", "cur", "=", "&", "$", "cur", "[", "$", "m", "[", "2", "]", "[", "$", "k", "]", "]", ";", "}", "elseif", "(", "$", "sep", "===", "'->'", ")", "{", "if", "(", "is_object", "(", "$", "cur", ")", "===", "false", ")", "{", "$", "cur", "=", "new", "stdClass", ";", "}", "$", "cur", "=", "&", "$", "cur", "->", "$", "m", "[", "2", "]", "[", "$", "k", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}", "if", "(", "$", "last", "[", "0", "]", "===", "'.'", "||", "$", "last", "[", "0", "]", "===", "'['", "||", "$", "last", "[", "0", "]", "===", "''", ")", "{", "if", "(", "is_array", "(", "$", "cur", ")", "===", "false", ")", "{", "$", "cur", "=", "array", "(", ")", ";", "}", "$", "cur", "[", "$", "last", "[", "1", "]", "]", "=", "$", "value", ";", "}", "elseif", "(", "$", "last", "[", "0", "]", "===", "'->'", ")", "{", "if", "(", "is_object", "(", "$", "cur", ")", "===", "false", ")", "{", "$", "cur", "=", "new", "stdClass", ";", "}", "$", "cur", "->", "$", "last", "[", "1", "]", "=", "$", "value", ";", "}", "else", "{", "return", "false", ";", "}", "}", "}" ]
[runtime function] assign the value to the given variable @param mixed $value the value to assign @param string $scope the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property") @return bool true if assigned correctly or false if a problem occured while parsing the var string
[ "[", "runtime", "function", "]", "assign", "the", "value", "to", "the", "given", "variable" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo.php#L1408-L1455
silvercommerce/geozones
src/Tasks/ZoneMigrationTask.php
ZoneMigrationTask.up
public function up() { $zones = Zone::get(); $this->log('Migrating Zones'); $i = 0; foreach ($zones as $zone) { $countries = json_decode($zone->Country); if (empty($countries) && isset($zone->Country)) { $countries = [$zone->Country]; $zone->Country = json_encode($countries); $zone->write(); $i++; } } $this->log("Migrated {$i} Zones"); }
php
public function up() { $zones = Zone::get(); $this->log('Migrating Zones'); $i = 0; foreach ($zones as $zone) { $countries = json_decode($zone->Country); if (empty($countries) && isset($zone->Country)) { $countries = [$zone->Country]; $zone->Country = json_encode($countries); $zone->write(); $i++; } } $this->log("Migrated {$i} Zones"); }
[ "public", "function", "up", "(", ")", "{", "$", "zones", "=", "Zone", "::", "get", "(", ")", ";", "$", "this", "->", "log", "(", "'Migrating Zones'", ")", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "zones", "as", "$", "zone", ")", "{", "$", "countries", "=", "json_decode", "(", "$", "zone", "->", "Country", ")", ";", "if", "(", "empty", "(", "$", "countries", ")", "&&", "isset", "(", "$", "zone", "->", "Country", ")", ")", "{", "$", "countries", "=", "[", "$", "zone", "->", "Country", "]", ";", "$", "zone", "->", "Country", "=", "json_encode", "(", "$", "countries", ")", ";", "$", "zone", "->", "write", "(", ")", ";", "$", "i", "++", ";", "}", "}", "$", "this", "->", "log", "(", "\"Migrated {$i} Zones\"", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/silvercommerce/geozones/blob/85af587805ae5cc6dce6a890ca04b338cf5552cb/src/Tasks/ZoneMigrationTask.php#L44-L62
silvercommerce/geozones
src/Tasks/ZoneMigrationTask.php
ZoneMigrationTask.down
public function down() { $zones = Zone::get(); $this->log('Downgrading Zones'); $i = 0; foreach ($zones as $zone) { $countries = json_decode($zone->Country); if (is_array($countries)) { $zone->Country = $countries[0]; $zone->write(); $i++; } } $this->log("Downgraded {$i} Zones"); }
php
public function down() { $zones = Zone::get(); $this->log('Downgrading Zones'); $i = 0; foreach ($zones as $zone) { $countries = json_decode($zone->Country); if (is_array($countries)) { $zone->Country = $countries[0]; $zone->write(); $i++; } } $this->log("Downgraded {$i} Zones"); }
[ "public", "function", "down", "(", ")", "{", "$", "zones", "=", "Zone", "::", "get", "(", ")", ";", "$", "this", "->", "log", "(", "'Downgrading Zones'", ")", ";", "$", "i", "=", "0", ";", "foreach", "(", "$", "zones", "as", "$", "zone", ")", "{", "$", "countries", "=", "json_decode", "(", "$", "zone", "->", "Country", ")", ";", "if", "(", "is_array", "(", "$", "countries", ")", ")", "{", "$", "zone", "->", "Country", "=", "$", "countries", "[", "0", "]", ";", "$", "zone", "->", "write", "(", ")", ";", "$", "i", "++", ";", "}", "}", "$", "this", "->", "log", "(", "\"Downgraded {$i} Zones\"", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/silvercommerce/geozones/blob/85af587805ae5cc6dce6a890ca04b338cf5552cb/src/Tasks/ZoneMigrationTask.php#L67-L84
nblum/silverstripe-flexible-content
code/GridFieldActiveAction.php
GridFieldActiveAction.handleAction
public function handleAction(\GridField $gridField, $actionName, $arguments, $data) { if ($actionName == 'toggle-active') { $item = $gridField->getList()->byID($arguments['RecordID']); if (!$item) { return; } if ($item->getField('Active')) { $item->setField('Active', 0); } else { $item->setField('Active', 1); } $item->write(); } }
php
public function handleAction(\GridField $gridField, $actionName, $arguments, $data) { if ($actionName == 'toggle-active') { $item = $gridField->getList()->byID($arguments['RecordID']); if (!$item) { return; } if ($item->getField('Active')) { $item->setField('Active', 0); } else { $item->setField('Active', 1); } $item->write(); } }
[ "public", "function", "handleAction", "(", "\\", "GridField", "$", "gridField", ",", "$", "actionName", ",", "$", "arguments", ",", "$", "data", ")", "{", "if", "(", "$", "actionName", "==", "'toggle-active'", ")", "{", "$", "item", "=", "$", "gridField", "->", "getList", "(", ")", "->", "byID", "(", "$", "arguments", "[", "'RecordID'", "]", ")", ";", "if", "(", "!", "$", "item", ")", "{", "return", ";", "}", "if", "(", "$", "item", "->", "getField", "(", "'Active'", ")", ")", "{", "$", "item", "->", "setField", "(", "'Active'", ",", "0", ")", ";", "}", "else", "{", "$", "item", "->", "setField", "(", "'Active'", ",", "1", ")", ";", "}", "$", "item", "->", "write", "(", ")", ";", "}", "}" ]
Handle the actions and apply any changes to the GridField @param \GridField $gridField @param string $actionName @param mixed $arguments @param array $data - form data @return void
[ "Handle", "the", "actions", "and", "apply", "any", "changes", "to", "the", "GridField" ]
train
https://github.com/nblum/silverstripe-flexible-content/blob/e20a06ee98b7f884965a951653d98af11eb6bc67/code/GridFieldActiveAction.php#L117-L131
ekuiter/feature-php
FeaturePhp/ProductLine/Product.php
Product.getAllGenerators
private function getAllGenerators() { $allGenerators = array(); foreach (fphp\Generator\Generator::getGeneratorMap() as $key => $klass) $allGenerators[$key] = new $klass($this->productLine->getGeneratorSettings($key)); return $allGenerators; }
php
private function getAllGenerators() { $allGenerators = array(); foreach (fphp\Generator\Generator::getGeneratorMap() as $key => $klass) $allGenerators[$key] = new $klass($this->productLine->getGeneratorSettings($key)); return $allGenerators; }
[ "private", "function", "getAllGenerators", "(", ")", "{", "$", "allGenerators", "=", "array", "(", ")", ";", "foreach", "(", "fphp", "\\", "Generator", "\\", "Generator", "::", "getGeneratorMap", "(", ")", "as", "$", "key", "=>", "$", "klass", ")", "$", "allGenerators", "[", "$", "key", "]", "=", "new", "$", "klass", "(", "$", "this", "->", "productLine", "->", "getGeneratorSettings", "(", "$", "key", ")", ")", ";", "return", "$", "allGenerators", ";", "}" ]
Returns all generators. The generators are instantiated with their respective generator settings. @return \FeaturePhp\Generator\Generator[]
[ "Returns", "all", "generators", ".", "The", "generators", "are", "instantiated", "with", "their", "respective", "generator", "settings", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/ProductLine/Product.php#L69-L74
ekuiter/feature-php
FeaturePhp/ProductLine/Product.php
Product.addArtifactToUsedGenerators
private function addArtifactToUsedGenerators($allGenerators, $feature, $func) { $artifact = $this->productLine->getArtifact($feature); foreach ($artifact->getGenerators() as $key => $cfg) { if (!array_key_exists($key, $allGenerators)) throw new ProductException("\"$key\" is not a valid generator"); call_user_func(array($allGenerators[$key], $func), $artifact); } }
php
private function addArtifactToUsedGenerators($allGenerators, $feature, $func) { $artifact = $this->productLine->getArtifact($feature); foreach ($artifact->getGenerators() as $key => $cfg) { if (!array_key_exists($key, $allGenerators)) throw new ProductException("\"$key\" is not a valid generator"); call_user_func(array($allGenerators[$key], $func), $artifact); } }
[ "private", "function", "addArtifactToUsedGenerators", "(", "$", "allGenerators", ",", "$", "feature", ",", "$", "func", ")", "{", "$", "artifact", "=", "$", "this", "->", "productLine", "->", "getArtifact", "(", "$", "feature", ")", ";", "foreach", "(", "$", "artifact", "->", "getGenerators", "(", ")", "as", "$", "key", "=>", "$", "cfg", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "allGenerators", ")", ")", "throw", "new", "ProductException", "(", "\"\\\"$key\\\" is not a valid generator\"", ")", ";", "call_user_func", "(", "array", "(", "$", "allGenerators", "[", "$", "key", "]", ",", "$", "func", ")", ",", "$", "artifact", ")", ";", "}", "}" ]
Adds a feature's artifact to all generators it specifies. This is done independently from whether the corresponding feature is selected or deselected to support generating code for both cases. @param \FeaturePhp\Generator\Generator[] $allGenerators @param \FeaturePhp\Model\Feature $feature @param callable $func whether to add a selected or deselected artifact
[ "Adds", "a", "feature", "s", "artifact", "to", "all", "generators", "it", "specifies", ".", "This", "is", "done", "independently", "from", "whether", "the", "corresponding", "feature", "is", "selected", "or", "deselected", "to", "support", "generating", "code", "for", "both", "cases", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/ProductLine/Product.php#L84-L91
ekuiter/feature-php
FeaturePhp/ProductLine/Product.php
Product.getGeneratorElements
private function getGeneratorElements($func) { $allGenerators = $this->getAllGenerators(); foreach ($this->configuration->getSelectedFeatures() as $feature) $this->addArtifactToUsedGenerators($allGenerators, $feature, "addSelectedArtifact"); foreach ($this->configuration->getDeselectedFeatures() as $feature) $this->addArtifactToUsedGenerators($allGenerators, $feature, "addDeselectedArtifact"); $elements = array(); foreach ($allGenerators as $generator) if ($generator->hasArtifacts()) $elements = array_merge($elements, call_user_func(array($generator, $func))); return $elements; }
php
private function getGeneratorElements($func) { $allGenerators = $this->getAllGenerators(); foreach ($this->configuration->getSelectedFeatures() as $feature) $this->addArtifactToUsedGenerators($allGenerators, $feature, "addSelectedArtifact"); foreach ($this->configuration->getDeselectedFeatures() as $feature) $this->addArtifactToUsedGenerators($allGenerators, $feature, "addDeselectedArtifact"); $elements = array(); foreach ($allGenerators as $generator) if ($generator->hasArtifacts()) $elements = array_merge($elements, call_user_func(array($generator, $func))); return $elements; }
[ "private", "function", "getGeneratorElements", "(", "$", "func", ")", "{", "$", "allGenerators", "=", "$", "this", "->", "getAllGenerators", "(", ")", ";", "foreach", "(", "$", "this", "->", "configuration", "->", "getSelectedFeatures", "(", ")", "as", "$", "feature", ")", "$", "this", "->", "addArtifactToUsedGenerators", "(", "$", "allGenerators", ",", "$", "feature", ",", "\"addSelectedArtifact\"", ")", ";", "foreach", "(", "$", "this", "->", "configuration", "->", "getDeselectedFeatures", "(", ")", "as", "$", "feature", ")", "$", "this", "->", "addArtifactToUsedGenerators", "(", "$", "allGenerators", ",", "$", "feature", ",", "\"addDeselectedArtifact\"", ")", ";", "$", "elements", "=", "array", "(", ")", ";", "foreach", "(", "$", "allGenerators", "as", "$", "generator", ")", "if", "(", "$", "generator", "->", "hasArtifacts", "(", ")", ")", "$", "elements", "=", "array_merge", "(", "$", "elements", ",", "call_user_func", "(", "array", "(", "$", "generator", ",", "$", "func", ")", ")", ")", ";", "return", "$", "elements", ";", "}" ]
Returns elements generated for the product. To do this, every artifact is registered with the generators it specifies. Then every generator generates some elements. Finally all the elements are merged. @param callable $func @return mixed[]
[ "Returns", "elements", "generated", "for", "the", "product", ".", "To", "do", "this", "every", "artifact", "is", "registered", "with", "the", "generators", "it", "specifies", ".", "Then", "every", "generator", "generates", "some", "elements", ".", "Finally", "all", "the", "elements", "are", "merged", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/ProductLine/Product.php#L100-L114
ekuiter/feature-php
FeaturePhp/ProductLine/Product.php
Product.generateFiles
public function generateFiles() { $files = $this->getGeneratorElements("generateFiles"); $files = fphp\Helper\_Array::assertNoDuplicates($files, "getTarget"); $files = fphp\Helper\_Array::sortByKey($files, "getTarget"); return $files; }
php
public function generateFiles() { $files = $this->getGeneratorElements("generateFiles"); $files = fphp\Helper\_Array::assertNoDuplicates($files, "getTarget"); $files = fphp\Helper\_Array::sortByKey($files, "getTarget"); return $files; }
[ "public", "function", "generateFiles", "(", ")", "{", "$", "files", "=", "$", "this", "->", "getGeneratorElements", "(", "\"generateFiles\"", ")", ";", "$", "files", "=", "fphp", "\\", "Helper", "\\", "_Array", "::", "assertNoDuplicates", "(", "$", "files", ",", "\"getTarget\"", ")", ";", "$", "files", "=", "fphp", "\\", "Helper", "\\", "_Array", "::", "sortByKey", "(", "$", "files", ",", "\"getTarget\"", ")", ";", "return", "$", "files", ";", "}" ]
Generates the product's files. @return \FeaturePhp\File\File[]
[ "Generates", "the", "product", "s", "files", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/ProductLine/Product.php#L120-L125
ekuiter/feature-php
FeaturePhp/ProductLine/Product.php
Product.trace
public function trace() { $tracingLinks = array_merge( $this->getGeneratorElements("trace"), $this->getAllGenerators()["runtime"]->traceRuntimeCalls($this->generateFiles(), $this->productLine) ); $tracingLinks = fphp\Helper\_Array::sortByKey($tracingLinks, "getFeatureName"); return $tracingLinks; }
php
public function trace() { $tracingLinks = array_merge( $this->getGeneratorElements("trace"), $this->getAllGenerators()["runtime"]->traceRuntimeCalls($this->generateFiles(), $this->productLine) ); $tracingLinks = fphp\Helper\_Array::sortByKey($tracingLinks, "getFeatureName"); return $tracingLinks; }
[ "public", "function", "trace", "(", ")", "{", "$", "tracingLinks", "=", "array_merge", "(", "$", "this", "->", "getGeneratorElements", "(", "\"trace\"", ")", ",", "$", "this", "->", "getAllGenerators", "(", ")", "[", "\"runtime\"", "]", "->", "traceRuntimeCalls", "(", "$", "this", "->", "generateFiles", "(", ")", ",", "$", "this", "->", "productLine", ")", ")", ";", "$", "tracingLinks", "=", "fphp", "\\", "Helper", "\\", "_Array", "::", "sortByKey", "(", "$", "tracingLinks", ",", "\"getFeatureName\"", ")", ";", "return", "$", "tracingLinks", ";", "}" ]
Returns tracing links for the product. @return \FeaturePhp\Artifact\TracingLink[]
[ "Returns", "tracing", "links", "for", "the", "product", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/ProductLine/Product.php#L131-L138
ouropencode/dachi
src/Session.php
Session.start
public static function start($name, $domain = "", $forceHttps = false) { session_name('sess_' . $name); $domain = $domain ? $domain : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ""); $https = $forceHttps ? true : isset($_SERVER['HTTPS']); if($domain == "localhost" || $domain == ".localhost") $domain = null; if(substr_count($domain, ".") < 2 && strlen($domain) >= 1 && $domain[0] != '.') $domain = '.' . $domain; session_set_cookie_params(time() + 3600, '/', $domain, $https); if(session_status() != PHP_SESSION_NONE) session_destroy(); session_start(); if(!self::isValid()) { $_SESSION = array(); session_destroy(); session_start(); } if(self::hasSessionMoved()) { $_SESSION = array(); $_SESSION['dachi_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; self::regenerate(); } else if (mt_rand(1, 100) <= 10) { self::regenerate(); } }
php
public static function start($name, $domain = "", $forceHttps = false) { session_name('sess_' . $name); $domain = $domain ? $domain : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ""); $https = $forceHttps ? true : isset($_SERVER['HTTPS']); if($domain == "localhost" || $domain == ".localhost") $domain = null; if(substr_count($domain, ".") < 2 && strlen($domain) >= 1 && $domain[0] != '.') $domain = '.' . $domain; session_set_cookie_params(time() + 3600, '/', $domain, $https); if(session_status() != PHP_SESSION_NONE) session_destroy(); session_start(); if(!self::isValid()) { $_SESSION = array(); session_destroy(); session_start(); } if(self::hasSessionMoved()) { $_SESSION = array(); $_SESSION['dachi_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; self::regenerate(); } else if (mt_rand(1, 100) <= 10) { self::regenerate(); } }
[ "public", "static", "function", "start", "(", "$", "name", ",", "$", "domain", "=", "\"\"", ",", "$", "forceHttps", "=", "false", ")", "{", "session_name", "(", "'sess_'", ".", "$", "name", ")", ";", "$", "domain", "=", "$", "domain", "?", "$", "domain", ":", "(", "isset", "(", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ")", "?", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ":", "\"\"", ")", ";", "$", "https", "=", "$", "forceHttps", "?", "true", ":", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", ";", "if", "(", "$", "domain", "==", "\"localhost\"", "||", "$", "domain", "==", "\".localhost\"", ")", "$", "domain", "=", "null", ";", "if", "(", "substr_count", "(", "$", "domain", ",", "\".\"", ")", "<", "2", "&&", "strlen", "(", "$", "domain", ")", ">=", "1", "&&", "$", "domain", "[", "0", "]", "!=", "'.'", ")", "$", "domain", "=", "'.'", ".", "$", "domain", ";", "session_set_cookie_params", "(", "time", "(", ")", "+", "3600", ",", "'/'", ",", "$", "domain", ",", "$", "https", ")", ";", "if", "(", "session_status", "(", ")", "!=", "PHP_SESSION_NONE", ")", "session_destroy", "(", ")", ";", "session_start", "(", ")", ";", "if", "(", "!", "self", "::", "isValid", "(", ")", ")", "{", "$", "_SESSION", "=", "array", "(", ")", ";", "session_destroy", "(", ")", ";", "session_start", "(", ")", ";", "}", "if", "(", "self", "::", "hasSessionMoved", "(", ")", ")", "{", "$", "_SESSION", "=", "array", "(", ")", ";", "$", "_SESSION", "[", "'dachi_agent'", "]", "=", "isset", "(", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", "?", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ":", "\"\"", ";", "self", "::", "regenerate", "(", ")", ";", "}", "else", "if", "(", "mt_rand", "(", "1", ",", "100", ")", "<=", "10", ")", "{", "self", "::", "regenerate", "(", ")", ";", "}", "}" ]
Start a session @param string $name The session name @param string $domain The domain this session is attached to. (defaults to php's SERVER_NAME) @param boolean $forceHttps Allow session only via HTTPS (defaults to 'yes if user is currently via HTTPS') @return null
[ "Start", "a", "session" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Session.php#L22-L54
ouropencode/dachi
src/Session.php
Session.hasSessionMoved
public static function hasSessionMoved() { if(!isset($_SESSION['dachi_agent'])) return true; $agents = $_SESSION['dachi_agent']; $agentc = $_SERVER['HTTP_USER_AGENT']; if($agents != $agentc) { if(strpos($agentc, "Trident") !== false && strpos($agents, "Trident") !== false) return false; return true; } return false; }
php
public static function hasSessionMoved() { if(!isset($_SESSION['dachi_agent'])) return true; $agents = $_SESSION['dachi_agent']; $agentc = $_SERVER['HTTP_USER_AGENT']; if($agents != $agentc) { if(strpos($agentc, "Trident") !== false && strpos($agents, "Trident") !== false) return false; return true; } return false; }
[ "public", "static", "function", "hasSessionMoved", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "_SESSION", "[", "'dachi_agent'", "]", ")", ")", "return", "true", ";", "$", "agents", "=", "$", "_SESSION", "[", "'dachi_agent'", "]", ";", "$", "agentc", "=", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ";", "if", "(", "$", "agents", "!=", "$", "agentc", ")", "{", "if", "(", "strpos", "(", "$", "agentc", ",", "\"Trident\"", ")", "!==", "false", "&&", "strpos", "(", "$", "agents", ",", "\"Trident\"", ")", "!==", "false", ")", "return", "false", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Has this session moved Moving is currently defined as "changing user agent". @return boolean
[ "Has", "this", "session", "moved" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Session.php#L63-L78
ouropencode/dachi
src/Session.php
Session.isValid
public static function isValid() { if(isset($_SESSION['dachi_closed']) && !isset($_SESSION['dachi_expires'])) return false; if(isset($_SESSION['dachi_expires']) && $_SESSION['dachi_expires'] < time()) return false; return true; }
php
public static function isValid() { if(isset($_SESSION['dachi_closed']) && !isset($_SESSION['dachi_expires'])) return false; if(isset($_SESSION['dachi_expires']) && $_SESSION['dachi_expires'] < time()) return false; return true; }
[ "public", "static", "function", "isValid", "(", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'dachi_closed'", "]", ")", "&&", "!", "isset", "(", "$", "_SESSION", "[", "'dachi_expires'", "]", ")", ")", "return", "false", ";", "if", "(", "isset", "(", "$", "_SESSION", "[", "'dachi_expires'", "]", ")", "&&", "$", "_SESSION", "[", "'dachi_expires'", "]", "<", "time", "(", ")", ")", "return", "false", ";", "return", "true", ";", "}" ]
Is this session still valid? Sessions are invalidated 10 seconds after regeneration, this is to allow AJAX requests to complete execution before terminating the session. This method will return false if the 10 second period has expired. @return boolean
[ "Is", "this", "session", "still", "valid?" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Session.php#L89-L97
ouropencode/dachi
src/Session.php
Session.regenerate
public static function regenerate() { if(isset($_SESSION['dachi_closed']) && $_SESSION['dachi_closed'] == true) return false; $_SESSION['dachi_closed'] = true; $_SESSION['dachi_expires'] = time() + 10; session_regenerate_id(false); $new_session = session_id(); session_write_close(); session_id($new_session); session_start(); unset($_SESSION['dachi_closed']); unset($_SESSION['dachi_expires']); }
php
public static function regenerate() { if(isset($_SESSION['dachi_closed']) && $_SESSION['dachi_closed'] == true) return false; $_SESSION['dachi_closed'] = true; $_SESSION['dachi_expires'] = time() + 10; session_regenerate_id(false); $new_session = session_id(); session_write_close(); session_id($new_session); session_start(); unset($_SESSION['dachi_closed']); unset($_SESSION['dachi_expires']); }
[ "public", "static", "function", "regenerate", "(", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'dachi_closed'", "]", ")", "&&", "$", "_SESSION", "[", "'dachi_closed'", "]", "==", "true", ")", "return", "false", ";", "$", "_SESSION", "[", "'dachi_closed'", "]", "=", "true", ";", "$", "_SESSION", "[", "'dachi_expires'", "]", "=", "time", "(", ")", "+", "10", ";", "session_regenerate_id", "(", "false", ")", ";", "$", "new_session", "=", "session_id", "(", ")", ";", "session_write_close", "(", ")", ";", "session_id", "(", "$", "new_session", ")", ";", "session_start", "(", ")", ";", "unset", "(", "$", "_SESSION", "[", "'dachi_closed'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'dachi_expires'", "]", ")", ";", "}" ]
Regenerate the session for security There is a 5% random chance on any page request that the session ID will be regenerated and a new session identity served to the user. This prevents static session IDs that can be stolen and reused. This method sets the old session to expire in 10 seconds. This allows for any pending requests to be served before the session ID changes. @return null
[ "Regenerate", "the", "session", "for", "security" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Session.php#L111-L128
gitiki/Gitiki
src/Git/Gitonomy/Commit.php
Commit.getDiffFile
public function getDiffFile($file) { $args = [ '-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $this->revision, '--', $this->repository->getWikiDir().$file, ]; $diff = Diff::parse($this->repository->run('diff-tree', $args)); $diff->setRepository($this->repository); return $diff; }
php
public function getDiffFile($file) { $args = [ '-r', '-p', '-m', '-M', '--no-commit-id', '--full-index', $this->revision, '--', $this->repository->getWikiDir().$file, ]; $diff = Diff::parse($this->repository->run('diff-tree', $args)); $diff->setRepository($this->repository); return $diff; }
[ "public", "function", "getDiffFile", "(", "$", "file", ")", "{", "$", "args", "=", "[", "'-r'", ",", "'-p'", ",", "'-m'", ",", "'-M'", ",", "'--no-commit-id'", ",", "'--full-index'", ",", "$", "this", "->", "revision", ",", "'--'", ",", "$", "this", "->", "repository", "->", "getWikiDir", "(", ")", ".", "$", "file", ",", "]", ";", "$", "diff", "=", "Diff", "::", "parse", "(", "$", "this", "->", "repository", "->", "run", "(", "'diff-tree'", ",", "$", "args", ")", ")", ";", "$", "diff", "->", "setRepository", "(", "$", "this", "->", "repository", ")", ";", "return", "$", "diff", ";", "}" ]
@param string $file Path to file @return Diff
[ "@param", "string", "$file", "Path", "to", "file" ]
train
https://github.com/gitiki/Gitiki/blob/f017672d4f5d0ef6015fad44724f05e3b1f08463/src/Git/Gitonomy/Commit.php#L23-L34
ShaoZeMing/laravel-merchant
src/Console/InstallCommand.php
InstallCommand.initDatabase
public function initDatabase() { $this->call('migrate'); if (Administrator::count() == 0) { $this->call('db:seed', ['--class' => \ShaoZeMing\Merchant\Auth\Database\AdminTablesSeeder::class]); } }
php
public function initDatabase() { $this->call('migrate'); if (Administrator::count() == 0) { $this->call('db:seed', ['--class' => \ShaoZeMing\Merchant\Auth\Database\AdminTablesSeeder::class]); } }
[ "public", "function", "initDatabase", "(", ")", "{", "$", "this", "->", "call", "(", "'migrate'", ")", ";", "if", "(", "Administrator", "::", "count", "(", ")", "==", "0", ")", "{", "$", "this", "->", "call", "(", "'db:seed'", ",", "[", "'--class'", "=>", "\\", "ShaoZeMing", "\\", "Merchant", "\\", "Auth", "\\", "Database", "\\", "AdminTablesSeeder", "::", "class", "]", ")", ";", "}", "}" ]
Create tables and seed it. @return void
[ "Create", "tables", "and", "seed", "it", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Console/InstallCommand.php#L48-L55
ShaoZeMing/laravel-merchant
src/Console/InstallCommand.php
InstallCommand.createExampleController
public function createExampleController() { $exampleController = $this->directory.'/Controllers/ExampleController.php'; $contents = $this->getStub('ExampleController'); $this->laravel['files']->put( $exampleController, str_replace('DummyNamespace', config('merchant.route.namespace'), $contents) ); $this->line('<info>ExampleController file was created:</info> '.str_replace(base_path(), '', $exampleController)); }
php
public function createExampleController() { $exampleController = $this->directory.'/Controllers/ExampleController.php'; $contents = $this->getStub('ExampleController'); $this->laravel['files']->put( $exampleController, str_replace('DummyNamespace', config('merchant.route.namespace'), $contents) ); $this->line('<info>ExampleController file was created:</info> '.str_replace(base_path(), '', $exampleController)); }
[ "public", "function", "createExampleController", "(", ")", "{", "$", "exampleController", "=", "$", "this", "->", "directory", ".", "'/Controllers/ExampleController.php'", ";", "$", "contents", "=", "$", "this", "->", "getStub", "(", "'ExampleController'", ")", ";", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "put", "(", "$", "exampleController", ",", "str_replace", "(", "'DummyNamespace'", ",", "config", "(", "'merchant.route.namespace'", ")", ",", "$", "contents", ")", ")", ";", "$", "this", "->", "line", "(", "'<info>ExampleController file was created:</info> '", ".", "str_replace", "(", "base_path", "(", ")", ",", "''", ",", "$", "exampleController", ")", ")", ";", "}" ]
Create HomeController. @return void
[ "Create", "HomeController", "." ]
train
https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Console/InstallCommand.php#L106-L116
netzmacht/contao-leaflet-geocode-widget
src/Widget/GeocodeWidget.php
GeocodeWidget.validator
protected function validator($value) { $value = parent::validator($value); if (!$value) { return $value; } if (is_array($value)) { foreach ($value as $key => $val) { $value[$key] = $this->validator($val); } return $value; } // See: http://stackoverflow.com/a/18690202 if (!preg_match( '#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#', $value )) { $this->addError( sprintf( $GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'], $value ) ); } return $value; }
php
protected function validator($value) { $value = parent::validator($value); if (!$value) { return $value; } if (is_array($value)) { foreach ($value as $key => $val) { $value[$key] = $this->validator($val); } return $value; } // See: http://stackoverflow.com/a/18690202 if (!preg_match( '#^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)(,[-+]?\d+)?$#', $value )) { $this->addError( sprintf( $GLOBALS['TL_LANG']['ERR']['leafletInvalidCoordinate'], $value ) ); } return $value; }
[ "protected", "function", "validator", "(", "$", "value", ")", "{", "$", "value", "=", "parent", "::", "validator", "(", "$", "value", ")", ";", "if", "(", "!", "$", "value", ")", "{", "return", "$", "value", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "value", "[", "$", "key", "]", "=", "$", "this", "->", "validator", "(", "$", "val", ")", ";", "}", "return", "$", "value", ";", "}", "// See: http://stackoverflow.com/a/18690202", "if", "(", "!", "preg_match", "(", "'#^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?),[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)(,[-+]?\\d+)?$#'", ",", "$", "value", ")", ")", "{", "$", "this", "->", "addError", "(", "sprintf", "(", "$", "GLOBALS", "[", "'TL_LANG'", "]", "[", "'ERR'", "]", "[", "'leafletInvalidCoordinate'", "]", ",", "$", "value", ")", ")", ";", "}", "return", "$", "value", ";", "}" ]
Validate the input. @param mixed $value Given value. @return mixed @SuppressWarnings(PHPMD.Superglobals)
[ "Validate", "the", "input", "." ]
train
https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/08acfbc473696f385d7c6aed6148e51c91443e12/src/Widget/GeocodeWidget.php#L60-L90
netzmacht/contao-leaflet-geocode-widget
src/Widget/GeocodeWidget.php
GeocodeWidget.generate
public function generate() { $wrapperClass = 'wizard'; if (!$this->multiple || !$this->size) { $this->size = 1; } else { $wrapperClass .= ' wizard_' . $this->size; } if (!is_array($this->value)) { $this->value = [$this->value]; } $buffer = ''; for ($index = 0; $index < $this->size; $index++) { $template = new \BackendTemplate($this->widgetTemplate); $template->setData( [ 'wrapperClass' => $wrapperClass, 'widget' => $this, 'value' => \StringUtil::specialchars($this->value[$index]), 'class' => $this->strClass ? ' ' . $this->strClass : '', 'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), 'name' => $this->strName . (($this->size > 1) ? '[]' : ''), 'attributes' => $this->getAttributes(), 'wizard' => $this->wizard, 'label' => $this->strLabel, 'radius' => $this->buildRadiusOptions() ] ); $buffer .= $template->parse(); } return $buffer; }
php
public function generate() { $wrapperClass = 'wizard'; if (!$this->multiple || !$this->size) { $this->size = 1; } else { $wrapperClass .= ' wizard_' . $this->size; } if (!is_array($this->value)) { $this->value = [$this->value]; } $buffer = ''; for ($index = 0; $index < $this->size; $index++) { $template = new \BackendTemplate($this->widgetTemplate); $template->setData( [ 'wrapperClass' => $wrapperClass, 'widget' => $this, 'value' => \StringUtil::specialchars($this->value[$index]), 'class' => $this->strClass ? ' ' . $this->strClass : '', 'id' => $this->strId . (($this->size > 1) ? '_' . $index : ''), 'name' => $this->strName . (($this->size > 1) ? '[]' : ''), 'attributes' => $this->getAttributes(), 'wizard' => $this->wizard, 'label' => $this->strLabel, 'radius' => $this->buildRadiusOptions() ] ); $buffer .= $template->parse(); } return $buffer; }
[ "public", "function", "generate", "(", ")", "{", "$", "wrapperClass", "=", "'wizard'", ";", "if", "(", "!", "$", "this", "->", "multiple", "||", "!", "$", "this", "->", "size", ")", "{", "$", "this", "->", "size", "=", "1", ";", "}", "else", "{", "$", "wrapperClass", ".=", "' wizard_'", ".", "$", "this", "->", "size", ";", "}", "if", "(", "!", "is_array", "(", "$", "this", "->", "value", ")", ")", "{", "$", "this", "->", "value", "=", "[", "$", "this", "->", "value", "]", ";", "}", "$", "buffer", "=", "''", ";", "for", "(", "$", "index", "=", "0", ";", "$", "index", "<", "$", "this", "->", "size", ";", "$", "index", "++", ")", "{", "$", "template", "=", "new", "\\", "BackendTemplate", "(", "$", "this", "->", "widgetTemplate", ")", ";", "$", "template", "->", "setData", "(", "[", "'wrapperClass'", "=>", "$", "wrapperClass", ",", "'widget'", "=>", "$", "this", ",", "'value'", "=>", "\\", "StringUtil", "::", "specialchars", "(", "$", "this", "->", "value", "[", "$", "index", "]", ")", ",", "'class'", "=>", "$", "this", "->", "strClass", "?", "' '", ".", "$", "this", "->", "strClass", ":", "''", ",", "'id'", "=>", "$", "this", "->", "strId", ".", "(", "(", "$", "this", "->", "size", ">", "1", ")", "?", "'_'", ".", "$", "index", ":", "''", ")", ",", "'name'", "=>", "$", "this", "->", "strName", ".", "(", "(", "$", "this", "->", "size", ">", "1", ")", "?", "'[]'", ":", "''", ")", ",", "'attributes'", "=>", "$", "this", "->", "getAttributes", "(", ")", ",", "'wizard'", "=>", "$", "this", "->", "wizard", ",", "'label'", "=>", "$", "this", "->", "strLabel", ",", "'radius'", "=>", "$", "this", "->", "buildRadiusOptions", "(", ")", "]", ")", ";", "$", "buffer", ".=", "$", "template", "->", "parse", "(", ")", ";", "}", "return", "$", "buffer", ";", "}" ]
Generate the widget. @return string
[ "Generate", "the", "widget", "." ]
train
https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/08acfbc473696f385d7c6aed6148e51c91443e12/src/Widget/GeocodeWidget.php#L97-L134
netzmacht/contao-leaflet-geocode-widget
src/Widget/GeocodeWidget.php
GeocodeWidget.buildRadiusOptions
private function buildRadiusOptions() { if (!$this->radius || !isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius])) { return null; } $options = [ 'element' => 'ctrl_' . $this->radius, 'min' => 0, 'max' => 0, 'defaultValue' => 0 ]; if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'])) { $config = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval']; $options['min'] = isset($config['minval']) ? (int) $config['minval'] : 0; $options['max'] = isset($config['maxval']) ? (int) $config['maxval'] : 0; $options['defaultValue'] = isset($config['default']) ? (int) $config['default'] : 0; $options['steps'] = isset($config['steps']) ? (int) $config['steps'] : 0; } return $options; }
php
private function buildRadiusOptions() { if (!$this->radius || !isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius])) { return null; } $options = [ 'element' => 'ctrl_' . $this->radius, 'min' => 0, 'max' => 0, 'defaultValue' => 0 ]; if (isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval'])) { $config = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->radius]['eval']; $options['min'] = isset($config['minval']) ? (int) $config['minval'] : 0; $options['max'] = isset($config['maxval']) ? (int) $config['maxval'] : 0; $options['defaultValue'] = isset($config['default']) ? (int) $config['default'] : 0; $options['steps'] = isset($config['steps']) ? (int) $config['steps'] : 0; } return $options; }
[ "private", "function", "buildRadiusOptions", "(", ")", "{", "if", "(", "!", "$", "this", "->", "radius", "||", "!", "isset", "(", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "this", "->", "strTable", "]", "[", "'fields'", "]", "[", "$", "this", "->", "radius", "]", ")", ")", "{", "return", "null", ";", "}", "$", "options", "=", "[", "'element'", "=>", "'ctrl_'", ".", "$", "this", "->", "radius", ",", "'min'", "=>", "0", ",", "'max'", "=>", "0", ",", "'defaultValue'", "=>", "0", "]", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "this", "->", "strTable", "]", "[", "'fields'", "]", "[", "$", "this", "->", "radius", "]", "[", "'eval'", "]", ")", ")", "{", "$", "config", "=", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "this", "->", "strTable", "]", "[", "'fields'", "]", "[", "$", "this", "->", "radius", "]", "[", "'eval'", "]", ";", "$", "options", "[", "'min'", "]", "=", "isset", "(", "$", "config", "[", "'minval'", "]", ")", "?", "(", "int", ")", "$", "config", "[", "'minval'", "]", ":", "0", ";", "$", "options", "[", "'max'", "]", "=", "isset", "(", "$", "config", "[", "'maxval'", "]", ")", "?", "(", "int", ")", "$", "config", "[", "'maxval'", "]", ":", "0", ";", "$", "options", "[", "'defaultValue'", "]", "=", "isset", "(", "$", "config", "[", "'default'", "]", ")", "?", "(", "int", ")", "$", "config", "[", "'default'", "]", ":", "0", ";", "$", "options", "[", "'steps'", "]", "=", "isset", "(", "$", "config", "[", "'steps'", "]", ")", "?", "(", "int", ")", "$", "config", "[", "'steps'", "]", ":", "0", ";", "}", "return", "$", "options", ";", "}" ]
Build the radius options. @return array|null @SuppressWarnings(PHPMD.Superglobals)
[ "Build", "the", "radius", "options", "." ]
train
https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/08acfbc473696f385d7c6aed6148e51c91443e12/src/Widget/GeocodeWidget.php#L143-L166
ajgarlag/AjglCsv
src/Charset/IconvConverter.php
IconvConverter.convert
public function convert($value, $inputCharset, $outputCharset) { if ($inputCharset !== $outputCharset) { $value = iconv($inputCharset, $outputCharset, $value); } return $value; }
php
public function convert($value, $inputCharset, $outputCharset) { if ($inputCharset !== $outputCharset) { $value = iconv($inputCharset, $outputCharset, $value); } return $value; }
[ "public", "function", "convert", "(", "$", "value", ",", "$", "inputCharset", ",", "$", "outputCharset", ")", "{", "if", "(", "$", "inputCharset", "!==", "$", "outputCharset", ")", "{", "$", "value", "=", "iconv", "(", "$", "inputCharset", ",", "$", "outputCharset", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ajgarlag/AjglCsv/blob/28872f58b9ef864893cac6faddfcb1229c2c2047/src/Charset/IconvConverter.php#L22-L29
DevGroup-ru/yii2-users-module
src/actions/BackendEditRbac.php
BackendEditRbac.run
public function run($id = null, $type) { $roleText = Yii::t('users', 'Role'); $permText = Yii::t('users', 'Permission'); if ($type == Item::TYPE_ROLE) { $modelName = $roleText; $permName = 'users-role-edit'; } else { $modelName = $permText; $permName = 'users-permission-edit'; } $authManager = Yii::$app->getAuthManager(); if (null !== $id) { $model = new AuthItemForm(); switch ($type) { case Item::TYPE_PERMISSION: $item = $authManager->getPermission($id); break; case Item::TYPE_ROLE: $item = $authManager->getRole($id); break; default: throw new InvalidParamException(Yii::t('users', 'Unexpected RBAC Item type')); } if (null === $item) { throw new NotFoundHttpException( Yii::t('users', "{model} with id :'{id}' not found!", [ 'model' => Yii::t('users', 'RBAC Item'), 'id' => $id ]) ); } $children = $authManager->getChildren($id); $selected = array_keys($children); $model->name = $item->name; $model->oldname = $item->name; $model->type = $item->type; $model->description = $item->description; $model->ruleName = $item->ruleName; $model->children = $selected; $actionName = "updateItem"; } else { if (true === in_array($type, [Item::TYPE_ROLE, Item::TYPE_PERMISSION])) { $model = new AuthItemForm(['isNewRecord' => true]); $model->type = $type; } else { throw new InvalidParamException(Yii::t('users', 'Unexpected RBAC Item type')); } $actionName = "createItem"; } $post = Yii::$app->request->post(); if (false === empty($post) && false === Yii::$app->user->can($permName)) { throw new ForbiddenHttpException(Yii::t( 'yii', 'You are not allowed to perform this action.' )); } if ($model->load($post) && $model->validate()) { $item = call_user_func([$model, $actionName]); if (false === empty($model->errors)) { Yii::$app->getSession()->setFlash('error', $model->getErrorMessage()); } else { Yii::$app->getSession()->setFlash( 'success', Yii::t('users', '{model} successfully saved!', ['model' => $modelName]) ); } return $this->controller->redirect(['/users/rbac-manage/edit', 'id' => $item->name, 'type' => $item->type]); } return $this->render( [ 'model' => $model, 'permName' => $permName, 'items' => self::getItems($type, $id, $authManager), ] ); }
php
public function run($id = null, $type) { $roleText = Yii::t('users', 'Role'); $permText = Yii::t('users', 'Permission'); if ($type == Item::TYPE_ROLE) { $modelName = $roleText; $permName = 'users-role-edit'; } else { $modelName = $permText; $permName = 'users-permission-edit'; } $authManager = Yii::$app->getAuthManager(); if (null !== $id) { $model = new AuthItemForm(); switch ($type) { case Item::TYPE_PERMISSION: $item = $authManager->getPermission($id); break; case Item::TYPE_ROLE: $item = $authManager->getRole($id); break; default: throw new InvalidParamException(Yii::t('users', 'Unexpected RBAC Item type')); } if (null === $item) { throw new NotFoundHttpException( Yii::t('users', "{model} with id :'{id}' not found!", [ 'model' => Yii::t('users', 'RBAC Item'), 'id' => $id ]) ); } $children = $authManager->getChildren($id); $selected = array_keys($children); $model->name = $item->name; $model->oldname = $item->name; $model->type = $item->type; $model->description = $item->description; $model->ruleName = $item->ruleName; $model->children = $selected; $actionName = "updateItem"; } else { if (true === in_array($type, [Item::TYPE_ROLE, Item::TYPE_PERMISSION])) { $model = new AuthItemForm(['isNewRecord' => true]); $model->type = $type; } else { throw new InvalidParamException(Yii::t('users', 'Unexpected RBAC Item type')); } $actionName = "createItem"; } $post = Yii::$app->request->post(); if (false === empty($post) && false === Yii::$app->user->can($permName)) { throw new ForbiddenHttpException(Yii::t( 'yii', 'You are not allowed to perform this action.' )); } if ($model->load($post) && $model->validate()) { $item = call_user_func([$model, $actionName]); if (false === empty($model->errors)) { Yii::$app->getSession()->setFlash('error', $model->getErrorMessage()); } else { Yii::$app->getSession()->setFlash( 'success', Yii::t('users', '{model} successfully saved!', ['model' => $modelName]) ); } return $this->controller->redirect(['/users/rbac-manage/edit', 'id' => $item->name, 'type' => $item->type]); } return $this->render( [ 'model' => $model, 'permName' => $permName, 'items' => self::getItems($type, $id, $authManager), ] ); }
[ "public", "function", "run", "(", "$", "id", "=", "null", ",", "$", "type", ")", "{", "$", "roleText", "=", "Yii", "::", "t", "(", "'users'", ",", "'Role'", ")", ";", "$", "permText", "=", "Yii", "::", "t", "(", "'users'", ",", "'Permission'", ")", ";", "if", "(", "$", "type", "==", "Item", "::", "TYPE_ROLE", ")", "{", "$", "modelName", "=", "$", "roleText", ";", "$", "permName", "=", "'users-role-edit'", ";", "}", "else", "{", "$", "modelName", "=", "$", "permText", ";", "$", "permName", "=", "'users-permission-edit'", ";", "}", "$", "authManager", "=", "Yii", "::", "$", "app", "->", "getAuthManager", "(", ")", ";", "if", "(", "null", "!==", "$", "id", ")", "{", "$", "model", "=", "new", "AuthItemForm", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "Item", "::", "TYPE_PERMISSION", ":", "$", "item", "=", "$", "authManager", "->", "getPermission", "(", "$", "id", ")", ";", "break", ";", "case", "Item", "::", "TYPE_ROLE", ":", "$", "item", "=", "$", "authManager", "->", "getRole", "(", "$", "id", ")", ";", "break", ";", "default", ":", "throw", "new", "InvalidParamException", "(", "Yii", "::", "t", "(", "'users'", ",", "'Unexpected RBAC Item type'", ")", ")", ";", "}", "if", "(", "null", "===", "$", "item", ")", "{", "throw", "new", "NotFoundHttpException", "(", "Yii", "::", "t", "(", "'users'", ",", "\"{model} with id :'{id}' not found!\"", ",", "[", "'model'", "=>", "Yii", "::", "t", "(", "'users'", ",", "'RBAC Item'", ")", ",", "'id'", "=>", "$", "id", "]", ")", ")", ";", "}", "$", "children", "=", "$", "authManager", "->", "getChildren", "(", "$", "id", ")", ";", "$", "selected", "=", "array_keys", "(", "$", "children", ")", ";", "$", "model", "->", "name", "=", "$", "item", "->", "name", ";", "$", "model", "->", "oldname", "=", "$", "item", "->", "name", ";", "$", "model", "->", "type", "=", "$", "item", "->", "type", ";", "$", "model", "->", "description", "=", "$", "item", "->", "description", ";", "$", "model", "->", "ruleName", "=", "$", "item", "->", "ruleName", ";", "$", "model", "->", "children", "=", "$", "selected", ";", "$", "actionName", "=", "\"updateItem\"", ";", "}", "else", "{", "if", "(", "true", "===", "in_array", "(", "$", "type", ",", "[", "Item", "::", "TYPE_ROLE", ",", "Item", "::", "TYPE_PERMISSION", "]", ")", ")", "{", "$", "model", "=", "new", "AuthItemForm", "(", "[", "'isNewRecord'", "=>", "true", "]", ")", ";", "$", "model", "->", "type", "=", "$", "type", ";", "}", "else", "{", "throw", "new", "InvalidParamException", "(", "Yii", "::", "t", "(", "'users'", ",", "'Unexpected RBAC Item type'", ")", ")", ";", "}", "$", "actionName", "=", "\"createItem\"", ";", "}", "$", "post", "=", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ";", "if", "(", "false", "===", "empty", "(", "$", "post", ")", "&&", "false", "===", "Yii", "::", "$", "app", "->", "user", "->", "can", "(", "$", "permName", ")", ")", "{", "throw", "new", "ForbiddenHttpException", "(", "Yii", "::", "t", "(", "'yii'", ",", "'You are not allowed to perform this action.'", ")", ")", ";", "}", "if", "(", "$", "model", "->", "load", "(", "$", "post", ")", "&&", "$", "model", "->", "validate", "(", ")", ")", "{", "$", "item", "=", "call_user_func", "(", "[", "$", "model", ",", "$", "actionName", "]", ")", ";", "if", "(", "false", "===", "empty", "(", "$", "model", "->", "errors", ")", ")", "{", "Yii", "::", "$", "app", "->", "getSession", "(", ")", "->", "setFlash", "(", "'error'", ",", "$", "model", "->", "getErrorMessage", "(", ")", ")", ";", "}", "else", "{", "Yii", "::", "$", "app", "->", "getSession", "(", ")", "->", "setFlash", "(", "'success'", ",", "Yii", "::", "t", "(", "'users'", ",", "'{model} successfully saved!'", ",", "[", "'model'", "=>", "$", "modelName", "]", ")", ")", ";", "}", "return", "$", "this", "->", "controller", "->", "redirect", "(", "[", "'/users/rbac-manage/edit'", ",", "'id'", "=>", "$", "item", "->", "name", ",", "'type'", "=>", "$", "item", "->", "type", "]", ")", ";", "}", "return", "$", "this", "->", "render", "(", "[", "'model'", "=>", "$", "model", ",", "'permName'", "=>", "$", "permName", ",", "'items'", "=>", "self", "::", "getItems", "(", "$", "type", ",", "$", "id", ",", "$", "authManager", ")", ",", "]", ")", ";", "}" ]
Updates or creates RBAC Item Type of item depends of given type @param null | string $id @param int $type @return string|\yii\web\Response @throws ForbiddenHttpException @throws NotFoundHttpException
[ "Updates", "or", "creates", "RBAC", "Item", "Type", "of", "item", "depends", "of", "given", "type" ]
train
https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/actions/BackendEditRbac.php#L36-L113
nabab/bbn
src/bbn/db/json.php
json.escape
public function escape($item) { if ( \is_string($item) && ($item = trim($item)) ){ $items = explode(".", str_replace("`", "", $item)); $r = []; foreach ( $items as $m ){ if ( !bbn\str::check_name($m) ){ return false; } array_push($r, "`".$m."`"); } return implode('.', $r); } return false; }
php
public function escape($item) { if ( \is_string($item) && ($item = trim($item)) ){ $items = explode(".", str_replace("`", "", $item)); $r = []; foreach ( $items as $m ){ if ( !bbn\str::check_name($m) ){ return false; } array_push($r, "`".$m."`"); } return implode('.', $r); } return false; }
[ "public", "function", "escape", "(", "$", "item", ")", "{", "if", "(", "\\", "is_string", "(", "$", "item", ")", "&&", "(", "$", "item", "=", "trim", "(", "$", "item", ")", ")", ")", "{", "$", "items", "=", "explode", "(", "\".\"", ",", "str_replace", "(", "\"`\"", ",", "\"\"", ",", "$", "item", ")", ")", ";", "$", "r", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "m", ")", "{", "if", "(", "!", "bbn", "\\", "str", "::", "check_name", "(", "$", "m", ")", ")", "{", "return", "false", ";", "}", "array_push", "(", "$", "r", ",", "\"`\"", ".", "$", "m", ".", "\"`\"", ")", ";", "}", "return", "implode", "(", "'.'", ",", "$", "r", ")", ";", "}", "return", "false", ";", "}" ]
Returns a database item expression escaped like database, table, column, key names @param string $item The item's name (escaped or not) @return string | false
[ "Returns", "a", "database", "item", "expression", "escaped", "like", "database", "table", "column", "key", "names" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L89-L103
nabab/bbn
src/bbn/db/json.php
json.table_full_name
public function table_full_name($table, $escaped=false) { if ( \is_string($table) && ($table = trim($table)) ){ $mtable = explode(".", str_replace("`", "", $table)); if ( \count($mtable) === 3 ){ $db = trim($mtable[0]); $table = trim($mtable[1]); } else if ( \count($mtable) === 2 ){ $db = trim($mtable[0]); $table = trim($mtable[1]); } else{ $db = $this->db->current; $table = trim($mtable[0]); } if ( bbn\str::check_name($db,$table) ){ return $escaped ? "`".$db."`.`".$table."`" : $db.".".$table; } } return false; }
php
public function table_full_name($table, $escaped=false) { if ( \is_string($table) && ($table = trim($table)) ){ $mtable = explode(".", str_replace("`", "", $table)); if ( \count($mtable) === 3 ){ $db = trim($mtable[0]); $table = trim($mtable[1]); } else if ( \count($mtable) === 2 ){ $db = trim($mtable[0]); $table = trim($mtable[1]); } else{ $db = $this->db->current; $table = trim($mtable[0]); } if ( bbn\str::check_name($db,$table) ){ return $escaped ? "`".$db."`.`".$table."`" : $db.".".$table; } } return false; }
[ "public", "function", "table_full_name", "(", "$", "table", ",", "$", "escaped", "=", "false", ")", "{", "if", "(", "\\", "is_string", "(", "$", "table", ")", "&&", "(", "$", "table", "=", "trim", "(", "$", "table", ")", ")", ")", "{", "$", "mtable", "=", "explode", "(", "\".\"", ",", "str_replace", "(", "\"`\"", ",", "\"\"", ",", "$", "table", ")", ")", ";", "if", "(", "\\", "count", "(", "$", "mtable", ")", "===", "3", ")", "{", "$", "db", "=", "trim", "(", "$", "mtable", "[", "0", "]", ")", ";", "$", "table", "=", "trim", "(", "$", "mtable", "[", "1", "]", ")", ";", "}", "else", "if", "(", "\\", "count", "(", "$", "mtable", ")", "===", "2", ")", "{", "$", "db", "=", "trim", "(", "$", "mtable", "[", "0", "]", ")", ";", "$", "table", "=", "trim", "(", "$", "mtable", "[", "1", "]", ")", ";", "}", "else", "{", "$", "db", "=", "$", "this", "->", "db", "->", "current", ";", "$", "table", "=", "trim", "(", "$", "mtable", "[", "0", "]", ")", ";", "}", "if", "(", "bbn", "\\", "str", "::", "check_name", "(", "$", "db", ",", "$", "table", ")", ")", "{", "return", "$", "escaped", "?", "\"`\"", ".", "$", "db", ".", "\"`.`\"", ".", "$", "table", ".", "\"`\"", ":", "$", "db", ".", "\".\"", ".", "$", "table", ";", "}", "}", "return", "false", ";", "}" ]
Returns a table's full name i.e. database.table @param string $table The table's name (escaped or not) @param bool $escaped If set to true the returned string will be escaped @return string | false
[ "Returns", "a", "table", "s", "full", "name", "i", ".", "e", ".", "database", ".", "table" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L112-L133
nabab/bbn
src/bbn/db/json.php
json.table_simple_name
public function table_simple_name($table, $escaped=false) { if ( \is_string($table) && ($table = trim($table)) ){ $mtable = explode(".", str_replace("`", "", $table)); switch ( \count($mtable) ){ case 1: $table = $mtable[0]; break; case 2: $table = $mtable[1]; break; case 3: $table = $mtable[1]; break; } if ( bbn\str::check_name($table) ){ return $escaped ? "`".$table."`" : $table; } } return false; }
php
public function table_simple_name($table, $escaped=false) { if ( \is_string($table) && ($table = trim($table)) ){ $mtable = explode(".", str_replace("`", "", $table)); switch ( \count($mtable) ){ case 1: $table = $mtable[0]; break; case 2: $table = $mtable[1]; break; case 3: $table = $mtable[1]; break; } if ( bbn\str::check_name($table) ){ return $escaped ? "`".$table."`" : $table; } } return false; }
[ "public", "function", "table_simple_name", "(", "$", "table", ",", "$", "escaped", "=", "false", ")", "{", "if", "(", "\\", "is_string", "(", "$", "table", ")", "&&", "(", "$", "table", "=", "trim", "(", "$", "table", ")", ")", ")", "{", "$", "mtable", "=", "explode", "(", "\".\"", ",", "str_replace", "(", "\"`\"", ",", "\"\"", ",", "$", "table", ")", ")", ";", "switch", "(", "\\", "count", "(", "$", "mtable", ")", ")", "{", "case", "1", ":", "$", "table", "=", "$", "mtable", "[", "0", "]", ";", "break", ";", "case", "2", ":", "$", "table", "=", "$", "mtable", "[", "1", "]", ";", "break", ";", "case", "3", ":", "$", "table", "=", "$", "mtable", "[", "1", "]", ";", "break", ";", "}", "if", "(", "bbn", "\\", "str", "::", "check_name", "(", "$", "table", ")", ")", "{", "return", "$", "escaped", "?", "\"`\"", ".", "$", "table", ".", "\"`\"", ":", "$", "table", ";", "}", "}", "return", "false", ";", "}" ]
Returns a table's simple name i.e. table @param string $table The table's name (escaped or not) @param bool $escaped If set to true the returned string will be escaped @return string | false
[ "Returns", "a", "table", "s", "simple", "name", "i", ".", "e", ".", "table" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L142-L162
nabab/bbn
src/bbn/db/json.php
json.col_full_name
public function col_full_name($col, $table='', $escaped=false) { if ( \is_string($col) && ($col = trim($col)) ){ $mcol = explode(".", str_replace("`", "", $col)); if ( \count($mcol) > 1 ){ $col = array_pop($mcol); $table = array_pop($mcol); $ok = 1; } else if ( !empty($table) ){ $table = $this->table_simple_name($table); $col = end($mcol); $ok = 1; } if ( isset($ok) && bbn\str::check_name($table, $col) ){ return $escaped ? "`".$table."`.`".$col."`" : $table.".".$col; } } return false; }
php
public function col_full_name($col, $table='', $escaped=false) { if ( \is_string($col) && ($col = trim($col)) ){ $mcol = explode(".", str_replace("`", "", $col)); if ( \count($mcol) > 1 ){ $col = array_pop($mcol); $table = array_pop($mcol); $ok = 1; } else if ( !empty($table) ){ $table = $this->table_simple_name($table); $col = end($mcol); $ok = 1; } if ( isset($ok) && bbn\str::check_name($table, $col) ){ return $escaped ? "`".$table."`.`".$col."`" : $table.".".$col; } } return false; }
[ "public", "function", "col_full_name", "(", "$", "col", ",", "$", "table", "=", "''", ",", "$", "escaped", "=", "false", ")", "{", "if", "(", "\\", "is_string", "(", "$", "col", ")", "&&", "(", "$", "col", "=", "trim", "(", "$", "col", ")", ")", ")", "{", "$", "mcol", "=", "explode", "(", "\".\"", ",", "str_replace", "(", "\"`\"", ",", "\"\"", ",", "$", "col", ")", ")", ";", "if", "(", "\\", "count", "(", "$", "mcol", ")", ">", "1", ")", "{", "$", "col", "=", "array_pop", "(", "$", "mcol", ")", ";", "$", "table", "=", "array_pop", "(", "$", "mcol", ")", ";", "$", "ok", "=", "1", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "table", ")", ")", "{", "$", "table", "=", "$", "this", "->", "table_simple_name", "(", "$", "table", ")", ";", "$", "col", "=", "end", "(", "$", "mcol", ")", ";", "$", "ok", "=", "1", ";", "}", "if", "(", "isset", "(", "$", "ok", ")", "&&", "bbn", "\\", "str", "::", "check_name", "(", "$", "table", ",", "$", "col", ")", ")", "{", "return", "$", "escaped", "?", "\"`\"", ".", "$", "table", ".", "\"`.`\"", ".", "$", "col", ".", "\"`\"", ":", "$", "table", ".", "\".\"", ".", "$", "col", ";", "}", "}", "return", "false", ";", "}" ]
Returns a column's full name i.e. table.column @param string $col The column's name (escaped or not) @param string $table The table's name (escaped or not) @param bool $escaped If set to true the returned string will be escaped @return string | false
[ "Returns", "a", "column", "s", "full", "name", "i", ".", "e", ".", "table", ".", "column" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L172-L191
nabab/bbn
src/bbn/db/json.php
json.col_simple_name
public function col_simple_name($col, $escaped=false) { if ( \is_string($col) && ($col = trim($col)) ){ $mcol = explode(".", str_replace("`", "", $col)); $col = end($mcol); if ( bbn\str::check_name($col) ){ return $escaped ? "`".$col."`" : $col; } } return false; }
php
public function col_simple_name($col, $escaped=false) { if ( \is_string($col) && ($col = trim($col)) ){ $mcol = explode(".", str_replace("`", "", $col)); $col = end($mcol); if ( bbn\str::check_name($col) ){ return $escaped ? "`".$col."`" : $col; } } return false; }
[ "public", "function", "col_simple_name", "(", "$", "col", ",", "$", "escaped", "=", "false", ")", "{", "if", "(", "\\", "is_string", "(", "$", "col", ")", "&&", "(", "$", "col", "=", "trim", "(", "$", "col", ")", ")", ")", "{", "$", "mcol", "=", "explode", "(", "\".\"", ",", "str_replace", "(", "\"`\"", ",", "\"\"", ",", "$", "col", ")", ")", ";", "$", "col", "=", "end", "(", "$", "mcol", ")", ";", "if", "(", "bbn", "\\", "str", "::", "check_name", "(", "$", "col", ")", ")", "{", "return", "$", "escaped", "?", "\"`\"", ".", "$", "col", ".", "\"`\"", ":", "$", "col", ";", "}", "}", "return", "false", ";", "}" ]
Returns a column's simple name i.e. column @param string $col The column's name (escaped or not) @param bool $escaped If set to true the returned string will be escaped @return string | false
[ "Returns", "a", "column", "s", "simple", "name", "i", ".", "e", ".", "column" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L200-L210
nabab/bbn
src/bbn/db/json.php
json.get_column_values
public function get_column_values($table, $field, array $where = [], $limit = false, $start = 0, $php = false) { if ( bbn\str::check_name($field) && ( $table = $this->table_full_name($table, 1) ) && ( $m = $this->db->modelize($table) ) && \count($m['fields']) > 0 ) { $r = ''; if ( $php ){ $r .= '$db->query("'; } if ( !isset($m['fields'][$field]) ){ die("The column $field doesn't exist in $table"); } $r .= "SELECT DISTINCT `$field` FROM $table".PHP_EOL. $this->db->get_where($where, $table).PHP_EOL. "ORDER BY `$field`"; if ( $limit ){ $r .= PHP_EOL . $this->get_limit([$limit, $start]); } if ( $php ){ $r .= '");'; } return $r; } return false; }
php
public function get_column_values($table, $field, array $where = [], $limit = false, $start = 0, $php = false) { if ( bbn\str::check_name($field) && ( $table = $this->table_full_name($table, 1) ) && ( $m = $this->db->modelize($table) ) && \count($m['fields']) > 0 ) { $r = ''; if ( $php ){ $r .= '$db->query("'; } if ( !isset($m['fields'][$field]) ){ die("The column $field doesn't exist in $table"); } $r .= "SELECT DISTINCT `$field` FROM $table".PHP_EOL. $this->db->get_where($where, $table).PHP_EOL. "ORDER BY `$field`"; if ( $limit ){ $r .= PHP_EOL . $this->get_limit([$limit, $start]); } if ( $php ){ $r .= '");'; } return $r; } return false; }
[ "public", "function", "get_column_values", "(", "$", "table", ",", "$", "field", ",", "array", "$", "where", "=", "[", "]", ",", "$", "limit", "=", "false", ",", "$", "start", "=", "0", ",", "$", "php", "=", "false", ")", "{", "if", "(", "bbn", "\\", "str", "::", "check_name", "(", "$", "field", ")", "&&", "(", "$", "table", "=", "$", "this", "->", "table_full_name", "(", "$", "table", ",", "1", ")", ")", "&&", "(", "$", "m", "=", "$", "this", "->", "db", "->", "modelize", "(", "$", "table", ")", ")", "&&", "\\", "count", "(", "$", "m", "[", "'fields'", "]", ")", ">", "0", ")", "{", "$", "r", "=", "''", ";", "if", "(", "$", "php", ")", "{", "$", "r", ".=", "'$db->query(\"'", ";", "}", "if", "(", "!", "isset", "(", "$", "m", "[", "'fields'", "]", "[", "$", "field", "]", ")", ")", "{", "die", "(", "\"The column $field doesn't exist in $table\"", ")", ";", "}", "$", "r", ".=", "\"SELECT DISTINCT `$field` FROM $table\"", ".", "PHP_EOL", ".", "$", "this", "->", "db", "->", "get_where", "(", "$", "where", ",", "$", "table", ")", ".", "PHP_EOL", ".", "\"ORDER BY `$field`\"", ";", "if", "(", "$", "limit", ")", "{", "$", "r", ".=", "PHP_EOL", ".", "$", "this", "->", "get_limit", "(", "[", "$", "limit", ",", "$", "start", "]", ")", ";", "}", "if", "(", "$", "php", ")", "{", "$", "r", ".=", "'\");'", ";", "}", "return", "$", "r", ";", "}", "return", "false", ";", "}" ]
Return an array of each values of the field $field in the table $table @return false|array
[ "Return", "an", "array", "of", "each", "values", "of", "the", "field", "$field", "in", "the", "table", "$table" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L651-L674
nabab/bbn
src/bbn/db/json.php
json.get_values_count
public function get_values_count($table, $field, array $where = [], $limit, $start, $php = false) { if ( ( $table = $this->table_full_name($table, 1) ) && ( $m = $this->db->modelize($table) ) && \count($m['fields']) > 0 ) { $r = ''; if ( $php ){ $r .= '$db->query("'; } if ( !isset($m['fields'][$field]) ){ die("The column $field doesn't exist in $table"); } $r .= "SELECT COUNT(*) AS num, `$field` AS val FROM $table"; if ( \count($where) > 0 ){ $r .= PHP_EOL . $this->db->get_where($where, $table); } $r .= PHP_EOL . "GROUP BY `$field`"; $r .= PHP_EOL . "ORDER BY `$field`"; if ( $limit ){ $r .= PHP_EOL . $this->get_limit([$limit, $start]); } if ( $php ){ $r .= '");'; } return $r; } return false; }
php
public function get_values_count($table, $field, array $where = [], $limit, $start, $php = false) { if ( ( $table = $this->table_full_name($table, 1) ) && ( $m = $this->db->modelize($table) ) && \count($m['fields']) > 0 ) { $r = ''; if ( $php ){ $r .= '$db->query("'; } if ( !isset($m['fields'][$field]) ){ die("The column $field doesn't exist in $table"); } $r .= "SELECT COUNT(*) AS num, `$field` AS val FROM $table"; if ( \count($where) > 0 ){ $r .= PHP_EOL . $this->db->get_where($where, $table); } $r .= PHP_EOL . "GROUP BY `$field`"; $r .= PHP_EOL . "ORDER BY `$field`"; if ( $limit ){ $r .= PHP_EOL . $this->get_limit([$limit, $start]); } if ( $php ){ $r .= '");'; } return $r; } return false; }
[ "public", "function", "get_values_count", "(", "$", "table", ",", "$", "field", ",", "array", "$", "where", "=", "[", "]", ",", "$", "limit", ",", "$", "start", ",", "$", "php", "=", "false", ")", "{", "if", "(", "(", "$", "table", "=", "$", "this", "->", "table_full_name", "(", "$", "table", ",", "1", ")", ")", "&&", "(", "$", "m", "=", "$", "this", "->", "db", "->", "modelize", "(", "$", "table", ")", ")", "&&", "\\", "count", "(", "$", "m", "[", "'fields'", "]", ")", ">", "0", ")", "{", "$", "r", "=", "''", ";", "if", "(", "$", "php", ")", "{", "$", "r", ".=", "'$db->query(\"'", ";", "}", "if", "(", "!", "isset", "(", "$", "m", "[", "'fields'", "]", "[", "$", "field", "]", ")", ")", "{", "die", "(", "\"The column $field doesn't exist in $table\"", ")", ";", "}", "$", "r", ".=", "\"SELECT COUNT(*) AS num, `$field` AS val FROM $table\"", ";", "if", "(", "\\", "count", "(", "$", "where", ")", ">", "0", ")", "{", "$", "r", ".=", "PHP_EOL", ".", "$", "this", "->", "db", "->", "get_where", "(", "$", "where", ",", "$", "table", ")", ";", "}", "$", "r", ".=", "PHP_EOL", ".", "\"GROUP BY `$field`\"", ";", "$", "r", ".=", "PHP_EOL", ".", "\"ORDER BY `$field`\"", ";", "if", "(", "$", "limit", ")", "{", "$", "r", ".=", "PHP_EOL", ".", "$", "this", "->", "get_limit", "(", "[", "$", "limit", ",", "$", "start", "]", ")", ";", "}", "if", "(", "$", "php", ")", "{", "$", "r", ".=", "'\");'", ";", "}", "return", "$", "r", ";", "}", "return", "false", ";", "}" ]
Return an array of double values arrays: each value of the field $field in the table $table and the number of instances @return false|array
[ "Return", "an", "array", "of", "double", "values", "arrays", ":", "each", "value", "of", "the", "field", "$field", "in", "the", "table", "$table", "and", "the", "number", "of", "instances" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db/json.php#L681-L707
oroinc/OroLayoutComponent
ExpressionLanguage/Encoder/JsonExpressionEncoder.php
JsonExpressionEncoder.encodeActions
public function encodeActions($actions) { return json_encode( [ '@actions' => array_map( function (Action $action) { return [ 'name' => $action->getName(), 'args' => $action->getArguments() ]; }, $actions ) ] ); }
php
public function encodeActions($actions) { return json_encode( [ '@actions' => array_map( function (Action $action) { return [ 'name' => $action->getName(), 'args' => $action->getArguments() ]; }, $actions ) ] ); }
[ "public", "function", "encodeActions", "(", "$", "actions", ")", "{", "return", "json_encode", "(", "[", "'@actions'", "=>", "array_map", "(", "function", "(", "Action", "$", "action", ")", "{", "return", "[", "'name'", "=>", "$", "action", "->", "getName", "(", ")", ",", "'args'", "=>", "$", "action", "->", "getArguments", "(", ")", "]", ";", "}", ",", "$", "actions", ")", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/ExpressionLanguage/Encoder/JsonExpressionEncoder.php#L32-L47
juskiewicz/Geolocation
src/Model/AddressCollection.php
AddressCollection.offsetGet
public function offsetGet($offset) { return isset($this->addresses[$offset]) ? $this->addresses[$offset] : null; }
php
public function offsetGet($offset) { return isset($this->addresses[$offset]) ? $this->addresses[$offset] : null; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "return", "isset", "(", "$", "this", "->", "addresses", "[", "$", "offset", "]", ")", "?", "$", "this", "->", "addresses", "[", "$", "offset", "]", ":", "null", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Model/AddressCollection.php#L56-L59
laraning/boost
src/Traits/CanCreateMany.php
CanCreateMany.createMany
public static function createMany(array $datasets) : array { $models = []; foreach ($datasets as $dataset) { $models[] = static::create($dataset); } return $models; }
php
public static function createMany(array $datasets) : array { $models = []; foreach ($datasets as $dataset) { $models[] = static::create($dataset); } return $models; }
[ "public", "static", "function", "createMany", "(", "array", "$", "datasets", ")", ":", "array", "{", "$", "models", "=", "[", "]", ";", "foreach", "(", "$", "datasets", "as", "$", "dataset", ")", "{", "$", "models", "[", "]", "=", "static", "::", "create", "(", "$", "dataset", ")", ";", "}", "return", "$", "models", ";", "}" ]
Creates many Models. @param array $datasets The data array of arrays. @return array The created models array.
[ "Creates", "many", "Models", "." ]
train
https://github.com/laraning/boost/blob/a57ac46f93eead7959c6743f5e709b1fb1429053/src/Traits/CanCreateMany.php#L17-L26
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Core/Transformer/Behaviour/Tag/ReturnTag.php
ReturnTag.process
public function process(\DOMDocument $xml) { $ignoreQry = '//tag[@name=\'return\' and @type=\'self\']' . '|//tag[@name=\'return\' and @type=\'$this\']' . '|//tag[@name=\'return\']/type[.=\'self\']' . '|//tag[@name=\'return\']/type[.=\'$this\']'; $xpath = new \DOMXPath($xml); $nodes = $xpath->query($ignoreQry); /** @var \DOMElement $node */ foreach ($nodes as $node) { // if a node with name 'type' is selected we need to reach one // level further. $docblock = ($node->nodeName == 'type') ? $node->parentNode->parentNode : $node->parentNode; /** @var \DOMElement $method */ $method = $docblock->parentNode; // if the method is not a method but a global function: error! if ($method->nodeName != 'method') { continue; } $type = $method->parentNode->getElementsByTagName('full_name') ->item(0)->nodeValue; // nodes with name type need to set their content; otherwise we set // an attribute of the class itself if ($node->nodeName == 'type') { $node->nodeValue = $type; // add a new tag @fluent to indicate that this is a fluent interface // we only add it here since there should always be a node `type` $fluent_tag = new \DOMElement('tag'); $docblock->appendChild($fluent_tag); $fluent_tag->setAttribute('name', 'fluent'); $fluent_tag->setAttribute( 'description', 'This method is part of a fluent interface and will return ' . 'the same instance' ); } else { $node->setAttribute('type', $type); } // check if an excerpt is set and override that as well if ($node->hasAttribute('excerpt') && (($node->getAttribute('excerpt') == 'self') || ($node->getAttribute('excerpt') == '$this')) ) { $node->setAttribute('excerpt', $type); } } return $xml; }
php
public function process(\DOMDocument $xml) { $ignoreQry = '//tag[@name=\'return\' and @type=\'self\']' . '|//tag[@name=\'return\' and @type=\'$this\']' . '|//tag[@name=\'return\']/type[.=\'self\']' . '|//tag[@name=\'return\']/type[.=\'$this\']'; $xpath = new \DOMXPath($xml); $nodes = $xpath->query($ignoreQry); /** @var \DOMElement $node */ foreach ($nodes as $node) { // if a node with name 'type' is selected we need to reach one // level further. $docblock = ($node->nodeName == 'type') ? $node->parentNode->parentNode : $node->parentNode; /** @var \DOMElement $method */ $method = $docblock->parentNode; // if the method is not a method but a global function: error! if ($method->nodeName != 'method') { continue; } $type = $method->parentNode->getElementsByTagName('full_name') ->item(0)->nodeValue; // nodes with name type need to set their content; otherwise we set // an attribute of the class itself if ($node->nodeName == 'type') { $node->nodeValue = $type; // add a new tag @fluent to indicate that this is a fluent interface // we only add it here since there should always be a node `type` $fluent_tag = new \DOMElement('tag'); $docblock->appendChild($fluent_tag); $fluent_tag->setAttribute('name', 'fluent'); $fluent_tag->setAttribute( 'description', 'This method is part of a fluent interface and will return ' . 'the same instance' ); } else { $node->setAttribute('type', $type); } // check if an excerpt is set and override that as well if ($node->hasAttribute('excerpt') && (($node->getAttribute('excerpt') == 'self') || ($node->getAttribute('excerpt') == '$this')) ) { $node->setAttribute('excerpt', $type); } } return $xml; }
[ "public", "function", "process", "(", "\\", "DOMDocument", "$", "xml", ")", "{", "$", "ignoreQry", "=", "'//tag[@name=\\'return\\' and @type=\\'self\\']'", ".", "'|//tag[@name=\\'return\\' and @type=\\'$this\\']'", ".", "'|//tag[@name=\\'return\\']/type[.=\\'self\\']'", ".", "'|//tag[@name=\\'return\\']/type[.=\\'$this\\']'", ";", "$", "xpath", "=", "new", "\\", "DOMXPath", "(", "$", "xml", ")", ";", "$", "nodes", "=", "$", "xpath", "->", "query", "(", "$", "ignoreQry", ")", ";", "/** @var \\DOMElement $node */", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "// if a node with name 'type' is selected we need to reach one", "// level further.", "$", "docblock", "=", "(", "$", "node", "->", "nodeName", "==", "'type'", ")", "?", "$", "node", "->", "parentNode", "->", "parentNode", ":", "$", "node", "->", "parentNode", ";", "/** @var \\DOMElement $method */", "$", "method", "=", "$", "docblock", "->", "parentNode", ";", "// if the method is not a method but a global function: error!", "if", "(", "$", "method", "->", "nodeName", "!=", "'method'", ")", "{", "continue", ";", "}", "$", "type", "=", "$", "method", "->", "parentNode", "->", "getElementsByTagName", "(", "'full_name'", ")", "->", "item", "(", "0", ")", "->", "nodeValue", ";", "// nodes with name type need to set their content; otherwise we set", "// an attribute of the class itself", "if", "(", "$", "node", "->", "nodeName", "==", "'type'", ")", "{", "$", "node", "->", "nodeValue", "=", "$", "type", ";", "// add a new tag @fluent to indicate that this is a fluent interface", "// we only add it here since there should always be a node `type`", "$", "fluent_tag", "=", "new", "\\", "DOMElement", "(", "'tag'", ")", ";", "$", "docblock", "->", "appendChild", "(", "$", "fluent_tag", ")", ";", "$", "fluent_tag", "->", "setAttribute", "(", "'name'", ",", "'fluent'", ")", ";", "$", "fluent_tag", "->", "setAttribute", "(", "'description'", ",", "'This method is part of a fluent interface and will return '", ".", "'the same instance'", ")", ";", "}", "else", "{", "$", "node", "->", "setAttribute", "(", "'type'", ",", "$", "type", ")", ";", "}", "// check if an excerpt is set and override that as well", "if", "(", "$", "node", "->", "hasAttribute", "(", "'excerpt'", ")", "&&", "(", "(", "$", "node", "->", "getAttribute", "(", "'excerpt'", ")", "==", "'self'", ")", "||", "(", "$", "node", "->", "getAttribute", "(", "'excerpt'", ")", "==", "'$this'", ")", ")", ")", "{", "$", "node", "->", "setAttribute", "(", "'excerpt'", ",", "$", "type", ")", ";", "}", "}", "return", "$", "xml", ";", "}" ]
Find all return tags that contain 'self' or '$this' and replace those terms for the name of the current class' type. @param \DOMDocument $xml Structure source to apply behaviour onto. @return \DOMDocument
[ "Find", "all", "return", "tags", "that", "contain", "self", "or", "$this", "and", "replace", "those", "terms", "for", "the", "name", "of", "the", "current", "class", "type", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Behaviour/Tag/ReturnTag.php#L27-L85
99designs/ergo-http
src/ResponseBuilder.php
ResponseBuilder.expires
public function expires($time) { if (!empty($time) && is_string($time) && !$timestamp = strtotime($time)) { throw new \Ergo\Routing\Exception("Invalid expiry time: $timestamp"); } else if (is_numeric($time)) { $timestamp = $time; } else if ($time == false) { return $this; } $this->addHeader('Expires', date('r', $timestamp)); return $this; }
php
public function expires($time) { if (!empty($time) && is_string($time) && !$timestamp = strtotime($time)) { throw new \Ergo\Routing\Exception("Invalid expiry time: $timestamp"); } else if (is_numeric($time)) { $timestamp = $time; } else if ($time == false) { return $this; } $this->addHeader('Expires', date('r', $timestamp)); return $this; }
[ "public", "function", "expires", "(", "$", "time", ")", "{", "if", "(", "!", "empty", "(", "$", "time", ")", "&&", "is_string", "(", "$", "time", ")", "&&", "!", "$", "timestamp", "=", "strtotime", "(", "$", "time", ")", ")", "{", "throw", "new", "\\", "Ergo", "\\", "Routing", "\\", "Exception", "(", "\"Invalid expiry time: $timestamp\"", ")", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "time", ")", ")", "{", "$", "timestamp", "=", "$", "time", ";", "}", "else", "if", "(", "$", "time", "==", "false", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "addHeader", "(", "'Expires'", ",", "date", "(", "'r'", ",", "$", "timestamp", ")", ")", ";", "return", "$", "this", ";", "}" ]
Sets the Expires header based on a Unix timestamp. @param int Unix timestamp @chainable
[ "Sets", "the", "Expires", "header", "based", "on", "a", "Unix", "timestamp", "." ]
train
https://github.com/99designs/ergo-http/blob/979b789f2e011a1cb70a00161e6b7bcd0d2e9c71/src/ResponseBuilder.php#L171-L184
Eresus/EresusCMS
src/core/Template/Service.php
Eresus_Template_Service.install
public function install($filename, $target) { if (!file_exists($filename)) { throw new RuntimeException('Template file not found: ' . $filename); } $target = $this->rootDir . '/' . $target; if (!file_exists($target)) { try { $umask = umask(0000); mkdir($target, 0777, true); umask($umask); } catch (Exception $e) { throw new RuntimeException( 'Can not create target directory: ' . $target, null, $e); } } $target .= '/' . basename($filename); if (file_exists($target)) { throw new RuntimeException(sprintf('Template "%s" is already installed', $target)); } if (!copy($filename, $target)) { throw new RuntimeException(sprintf('Failed to copy "%s" to "%s"', $filename, $target)); } }
php
public function install($filename, $target) { if (!file_exists($filename)) { throw new RuntimeException('Template file not found: ' . $filename); } $target = $this->rootDir . '/' . $target; if (!file_exists($target)) { try { $umask = umask(0000); mkdir($target, 0777, true); umask($umask); } catch (Exception $e) { throw new RuntimeException( 'Can not create target directory: ' . $target, null, $e); } } $target .= '/' . basename($filename); if (file_exists($target)) { throw new RuntimeException(sprintf('Template "%s" is already installed', $target)); } if (!copy($filename, $target)) { throw new RuntimeException(sprintf('Failed to copy "%s" to "%s"', $filename, $target)); } }
[ "public", "function", "install", "(", "$", "filename", ",", "$", "target", ")", "{", "if", "(", "!", "file_exists", "(", "$", "filename", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Template file not found: '", ".", "$", "filename", ")", ";", "}", "$", "target", "=", "$", "this", "->", "rootDir", ".", "'/'", ".", "$", "target", ";", "if", "(", "!", "file_exists", "(", "$", "target", ")", ")", "{", "try", "{", "$", "umask", "=", "umask", "(", "0000", ")", ";", "mkdir", "(", "$", "target", ",", "0777", ",", "true", ")", ";", "umask", "(", "$", "umask", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "RuntimeException", "(", "'Can not create target directory: '", ".", "$", "target", ",", "null", ",", "$", "e", ")", ";", "}", "}", "$", "target", ".=", "'/'", ".", "basename", "(", "$", "filename", ")", ";", "if", "(", "file_exists", "(", "$", "target", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Template \"%s\" is already installed'", ",", "$", "target", ")", ")", ";", "}", "if", "(", "!", "copy", "(", "$", "filename", ",", "$", "target", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Failed to copy \"%s\" to \"%s\"'", ",", "$", "filename", ",", "$", "target", ")", ")", ";", "}", "}" ]
Устанавливает шаблоны в общую папку шаблонов @param string $filename абсолютный путь к устанавливаемому шаблону @param string $target путь относительно общей директории шаблонов @throws RuntimeException @since 3.01
[ "Устанавливает", "шаблоны", "в", "общую", "папку", "шаблонов" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Template/Service.php#L85-L119
Eresus/EresusCMS
src/core/Template/Service.php
Eresus_Template_Service.remove
public function remove($path) { $path = $this->rootDir . '/' . $path; if (!file_exists($path)) { throw new RuntimeException(sprintf('Template file "%s" not found', $path)); } if (is_file($path)) { unlink($path); } else { $branch = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); $files = array(); $dirs = array(); foreach ($branch as $file) { /** @var SplFileInfo $file */ if (preg_match('/^\.{1,2}$/', $file->getFilename())) { continue; } if ($file->isDir()) { $dirs []= $file->getPathname(); } else { $files []= $file->getPathname(); } } /* Вначале удаляем все файлы */ foreach ($files as $file) { unlink($file); } /* Теперь удаляем директории, начиная с самых глубоких */ for ($i = count($dirs) - 1; $i >= 0; $i--) { rmdir($dirs[$i]); } rmdir($path); } }
php
public function remove($path) { $path = $this->rootDir . '/' . $path; if (!file_exists($path)) { throw new RuntimeException(sprintf('Template file "%s" not found', $path)); } if (is_file($path)) { unlink($path); } else { $branch = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); $files = array(); $dirs = array(); foreach ($branch as $file) { /** @var SplFileInfo $file */ if (preg_match('/^\.{1,2}$/', $file->getFilename())) { continue; } if ($file->isDir()) { $dirs []= $file->getPathname(); } else { $files []= $file->getPathname(); } } /* Вначале удаляем все файлы */ foreach ($files as $file) { unlink($file); } /* Теперь удаляем директории, начиная с самых глубоких */ for ($i = count($dirs) - 1; $i >= 0; $i--) { rmdir($dirs[$i]); } rmdir($path); } }
[ "public", "function", "remove", "(", "$", "path", ")", "{", "$", "path", "=", "$", "this", "->", "rootDir", ".", "'/'", ".", "$", "path", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Template file \"%s\" not found'", ",", "$", "path", ")", ")", ";", "}", "if", "(", "is_file", "(", "$", "path", ")", ")", "{", "unlink", "(", "$", "path", ")", ";", "}", "else", "{", "$", "branch", "=", "new", "RecursiveIteratorIterator", "(", "new", "RecursiveDirectoryIterator", "(", "$", "path", ")", ",", "RecursiveIteratorIterator", "::", "SELF_FIRST", ")", ";", "$", "files", "=", "array", "(", ")", ";", "$", "dirs", "=", "array", "(", ")", ";", "foreach", "(", "$", "branch", "as", "$", "file", ")", "{", "/** @var SplFileInfo $file */", "if", "(", "preg_match", "(", "'/^\\.{1,2}$/'", ",", "$", "file", "->", "getFilename", "(", ")", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "file", "->", "isDir", "(", ")", ")", "{", "$", "dirs", "[", "]", "=", "$", "file", "->", "getPathname", "(", ")", ";", "}", "else", "{", "$", "files", "[", "]", "=", "$", "file", "->", "getPathname", "(", ")", ";", "}", "}", "/* Вначале удаляем все файлы */", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "unlink", "(", "$", "file", ")", ";", "}", "/* Теперь удаляем директории, начиная с самых глубоких */", "for", "(", "$", "i", "=", "count", "(", "$", "dirs", ")", "-", "1", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "rmdir", "(", "$", "dirs", "[", "$", "i", "]", ")", ";", "}", "rmdir", "(", "$", "path", ")", ";", "}", "}" ]
Удаляет шаблон или папку шаблонов @param string $path имя файла или папки относительно общей директории шаблонов @throws RuntimeException @since 3.01
[ "Удаляет", "шаблон", "или", "папку", "шаблонов" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Template/Service.php#L130-L178
Eresus/EresusCMS
src/core/Template/Service.php
Eresus_Template_Service.getContents
public function getContents($name, $prefix = '') { $path = $this->rootDir . '/' . $this->getFilename($name, $prefix); if (!is_file($path)) { throw new RuntimeException('Template not exists: ' . $path); } $contents = file_get_contents($path); return $contents; }
php
public function getContents($name, $prefix = '') { $path = $this->rootDir . '/' . $this->getFilename($name, $prefix); if (!is_file($path)) { throw new RuntimeException('Template not exists: ' . $path); } $contents = file_get_contents($path); return $contents; }
[ "public", "function", "getContents", "(", "$", "name", ",", "$", "prefix", "=", "''", ")", "{", "$", "path", "=", "$", "this", "->", "rootDir", ".", "'/'", ".", "$", "this", "->", "getFilename", "(", "$", "name", ",", "$", "prefix", ")", ";", "if", "(", "!", "is_file", "(", "$", "path", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Template not exists: '", ".", "$", "path", ")", ";", "}", "$", "contents", "=", "file_get_contents", "(", "$", "path", ")", ";", "return", "$", "contents", ";", "}" ]
Возвращает содержимое шаблона @param string $name имя файла шаблона @param string $prefix опциональный префикс (путь относительно корня шаблонов) @throws RuntimeException @return string @since 3.01
[ "Возвращает", "содержимое", "шаблона" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Template/Service.php#L192-L204
Eresus/EresusCMS
src/core/Template/Service.php
Eresus_Template_Service.setContents
public function setContents($contents, $name, $prefix = '') { $path = $this->rootDir . '/' . $this->getFilename($name, $prefix); if (!is_file($path)) { throw new RuntimeException('Template not exists: ' . $path); } @file_put_contents($path, $contents); }
php
public function setContents($contents, $name, $prefix = '') { $path = $this->rootDir . '/' . $this->getFilename($name, $prefix); if (!is_file($path)) { throw new RuntimeException('Template not exists: ' . $path); } @file_put_contents($path, $contents); }
[ "public", "function", "setContents", "(", "$", "contents", ",", "$", "name", ",", "$", "prefix", "=", "''", ")", "{", "$", "path", "=", "$", "this", "->", "rootDir", ".", "'/'", ".", "$", "this", "->", "getFilename", "(", "$", "name", ",", "$", "prefix", ")", ";", "if", "(", "!", "is_file", "(", "$", "path", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Template not exists: '", ".", "$", "path", ")", ";", "}", "@", "file_put_contents", "(", "$", "path", ",", "$", "contents", ")", ";", "}" ]
Записывает содержимое шаблона @param string $contents содержимое шаблона @param string $name имя файла шаблона @param string $prefix опциональный префикс (путь относительно корня шаблонов) @throws RuntimeException @return void @since 3.01
[ "Записывает", "содержимое", "шаблона" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Template/Service.php#L219-L229
Eresus/EresusCMS
src/core/Template/Service.php
Eresus_Template_Service.getFilename
public function getFilename($name, $prefix = '') { $path = $name; if ($prefix != '') { $path = $prefix . '/' . $path; } return $path; }
php
public function getFilename($name, $prefix = '') { $path = $name; if ($prefix != '') { $path = $prefix . '/' . $path; } return $path; }
[ "public", "function", "getFilename", "(", "$", "name", ",", "$", "prefix", "=", "''", ")", "{", "$", "path", "=", "$", "name", ";", "if", "(", "$", "prefix", "!=", "''", ")", "{", "$", "path", "=", "$", "prefix", ".", "'/'", ".", "$", "path", ";", "}", "return", "$", "path", ";", "}" ]
Возвращает путь к файлу шаблона @param string $name имя файла шаблона @param string $prefix опциональный префикс (путь относительно корня шаблонов) @return string @since 1.00
[ "Возвращает", "путь", "к", "файлу", "шаблона" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Template/Service.php#L241-L250
Eresus/EresusCMS
src/core/Template/Service.php
Eresus_Template_Service.getTemplate
public function getTemplate($name, $prefix = '') { $path = $this->getFilename($name, $prefix); if (!is_file($this->rootDir . '/' . $path)) { throw new RuntimeException('Template not exists: ' . $path); } $tmpl = new Eresus_Template('templates/' . $path); return $tmpl; }
php
public function getTemplate($name, $prefix = '') { $path = $this->getFilename($name, $prefix); if (!is_file($this->rootDir . '/' . $path)) { throw new RuntimeException('Template not exists: ' . $path); } $tmpl = new Eresus_Template('templates/' . $path); return $tmpl; }
[ "public", "function", "getTemplate", "(", "$", "name", ",", "$", "prefix", "=", "''", ")", "{", "$", "path", "=", "$", "this", "->", "getFilename", "(", "$", "name", ",", "$", "prefix", ")", ";", "if", "(", "!", "is_file", "(", "$", "this", "->", "rootDir", ".", "'/'", ".", "$", "path", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Template not exists: '", ".", "$", "path", ")", ";", "}", "$", "tmpl", "=", "new", "Eresus_Template", "(", "'templates/'", ".", "$", "path", ")", ";", "return", "$", "tmpl", ";", "}" ]
Возвращает объект шаблона @param string $name имя файла шаблона @param string $prefix опциональный префикс (путь относительно корня шаблонов) @throws RuntimeException @return Eresus_Template @since 3.01
[ "Возвращает", "объект", "шаблона" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Template/Service.php#L264-L276
laraning/boost
src/Commands/ViewHintsCommand.php
ViewHintsCommand.handle
public function handle() { // Transform array. foreach (view()->getFinder()->getHints() as $key => $value) { $this->hints[] = [$key, $value[0]]; } $this->table($this->headers, $this->hints); }
php
public function handle() { // Transform array. foreach (view()->getFinder()->getHints() as $key => $value) { $this->hints[] = [$key, $value[0]]; } $this->table($this->headers, $this->hints); }
[ "public", "function", "handle", "(", ")", "{", "// Transform array.", "foreach", "(", "view", "(", ")", "->", "getFinder", "(", ")", "->", "getHints", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "hints", "[", "]", "=", "[", "$", "key", ",", "$", "value", "[", "0", "]", "]", ";", "}", "$", "this", "->", "table", "(", "$", "this", "->", "headers", ",", "$", "this", "->", "hints", ")", ";", "}" ]
Execute the console command. @return mixed
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/laraning/boost/blob/a57ac46f93eead7959c6743f5e709b1fb1429053/src/Commands/ViewHintsCommand.php#L52-L60
scherersoftware/cake-monitor
src/Middleware/ErrorHandlerMiddleware.php
ErrorHandlerMiddleware.handleException
public function handleException($exception, $request, $response) { $sentryHandler = new SentryHandler(); $sentryHandler->handle($exception); return parent::handleException($exception, $request, $response); }
php
public function handleException($exception, $request, $response) { $sentryHandler = new SentryHandler(); $sentryHandler->handle($exception); return parent::handleException($exception, $request, $response); }
[ "public", "function", "handleException", "(", "$", "exception", ",", "$", "request", ",", "$", "response", ")", "{", "$", "sentryHandler", "=", "new", "SentryHandler", "(", ")", ";", "$", "sentryHandler", "->", "handle", "(", "$", "exception", ")", ";", "return", "parent", "::", "handleException", "(", "$", "exception", ",", "$", "request", ",", "$", "response", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/scherersoftware/cake-monitor/blob/dbe07a1aac41b3db15e631d9e59cf26214bf6938/src/Middleware/ErrorHandlerMiddleware.php#L13-L18
jasny/controller
src/Controller/Output.php
Output.setResponseHeader
public function setResponseHeader($header, $value, $overwrite = true) { $fn = $overwrite ? 'withHeader' : 'withAddedHeader'; $response = $this->getResponse()->$fn($header, $value); $this->setResponse($response); }
php
public function setResponseHeader($header, $value, $overwrite = true) { $fn = $overwrite ? 'withHeader' : 'withAddedHeader'; $response = $this->getResponse()->$fn($header, $value); $this->setResponse($response); }
[ "public", "function", "setResponseHeader", "(", "$", "header", ",", "$", "value", ",", "$", "overwrite", "=", "true", ")", "{", "$", "fn", "=", "$", "overwrite", "?", "'withHeader'", ":", "'withAddedHeader'", ";", "$", "response", "=", "$", "this", "->", "getResponse", "(", ")", "->", "$", "fn", "(", "$", "header", ",", "$", "value", ")", ";", "$", "this", "->", "setResponse", "(", "$", "response", ")", ";", "}" ]
Set a response header @param string $header @param string $value @param boolean $overwrite
[ "Set", "a", "response", "header" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L47-L53
jasny/controller
src/Controller/Output.php
Output.respondWith
public function respondWith($status, $format = null) { $response = $this->getResponse(); // Shift arguments if $code is omitted if (isset($status) && !is_int($status) && (!is_string($status) || !preg_match('/^\d{3}\b/', $status))) { list($status, $format) = array_merge([null], func_get_args()); } if (!empty($status)) { list($code, $phrase) = explode(' ', $status, 2) + [1 => null]; $response = $response->withStatus((int)$code, $phrase); } if (!empty($format)) { $contentType = $this->getContentType($format); $response = $response->withHeader('Content-Type', $contentType); } $this->setResponse($response); }
php
public function respondWith($status, $format = null) { $response = $this->getResponse(); // Shift arguments if $code is omitted if (isset($status) && !is_int($status) && (!is_string($status) || !preg_match('/^\d{3}\b/', $status))) { list($status, $format) = array_merge([null], func_get_args()); } if (!empty($status)) { list($code, $phrase) = explode(' ', $status, 2) + [1 => null]; $response = $response->withStatus((int)$code, $phrase); } if (!empty($format)) { $contentType = $this->getContentType($format); $response = $response->withHeader('Content-Type', $contentType); } $this->setResponse($response); }
[ "public", "function", "respondWith", "(", "$", "status", ",", "$", "format", "=", "null", ")", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", ")", ";", "// Shift arguments if $code is omitted", "if", "(", "isset", "(", "$", "status", ")", "&&", "!", "is_int", "(", "$", "status", ")", "&&", "(", "!", "is_string", "(", "$", "status", ")", "||", "!", "preg_match", "(", "'/^\\d{3}\\b/'", ",", "$", "status", ")", ")", ")", "{", "list", "(", "$", "status", ",", "$", "format", ")", "=", "array_merge", "(", "[", "null", "]", ",", "func_get_args", "(", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "status", ")", ")", "{", "list", "(", "$", "code", ",", "$", "phrase", ")", "=", "explode", "(", "' '", ",", "$", "status", ",", "2", ")", "+", "[", "1", "=>", "null", "]", ";", "$", "response", "=", "$", "response", "->", "withStatus", "(", "(", "int", ")", "$", "code", ",", "$", "phrase", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "format", ")", ")", "{", "$", "contentType", "=", "$", "this", "->", "getContentType", "(", "$", "format", ")", ";", "$", "response", "=", "$", "response", "->", "withHeader", "(", "'Content-Type'", ",", "$", "contentType", ")", ";", "}", "$", "this", "->", "setResponse", "(", "$", "response", ")", ";", "}" ]
Set the headers with HTTP status code and content type. @link http://en.wikipedia.org/wiki/List_of_HTTP_status_codes Examples: <code> $this->respondWith(200, 'json'); $this->respondWith(200, 'application/json'); $this->respondWith(204); $this->respondWith("204 Created"); $this->respondWith('json'); </code> @param int|string $status HTTP status (may be omitted) @param string|array $format Mime or content format
[ "Set", "the", "headers", "with", "HTTP", "status", "code", "and", "content", "type", ".", "@link", "http", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "wiki", "/", "List_of_HTTP_status_codes" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L71-L91
jasny/controller
src/Controller/Output.php
Output.created
public function created($location = null) { $this->respondWith(201); if (!empty($location)) { $this->setResponseHeader('Location', $location); } }
php
public function created($location = null) { $this->respondWith(201); if (!empty($location)) { $this->setResponseHeader('Location', $location); } }
[ "public", "function", "created", "(", "$", "location", "=", "null", ")", "{", "$", "this", "->", "respondWith", "(", "201", ")", ";", "if", "(", "!", "empty", "(", "$", "location", ")", ")", "{", "$", "this", "->", "setResponseHeader", "(", "'Location'", ",", "$", "location", ")", ";", "}", "}" ]
Response with created 201 code, and optionally the created location @param string $location Url of created resource
[ "Response", "with", "created", "201", "code", "and", "optionally", "the", "created", "location" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L109-L116
jasny/controller
src/Controller/Output.php
Output.partialContent
public function partialContent($rangeFrom, $rangeTo, $totalSize) { $this->respondWith(206); $this->setResponseHeader('Content-Range', "bytes {$rangeFrom}-{$rangeTo}/{$totalSize}"); $this->setResponseHeader('Content-Length', $rangeTo - $rangeFrom); }
php
public function partialContent($rangeFrom, $rangeTo, $totalSize) { $this->respondWith(206); $this->setResponseHeader('Content-Range', "bytes {$rangeFrom}-{$rangeTo}/{$totalSize}"); $this->setResponseHeader('Content-Length', $rangeTo - $rangeFrom); }
[ "public", "function", "partialContent", "(", "$", "rangeFrom", ",", "$", "rangeTo", ",", "$", "totalSize", ")", "{", "$", "this", "->", "respondWith", "(", "206", ")", ";", "$", "this", "->", "setResponseHeader", "(", "'Content-Range'", ",", "\"bytes {$rangeFrom}-{$rangeTo}/{$totalSize}\"", ")", ";", "$", "this", "->", "setResponseHeader", "(", "'Content-Length'", ",", "$", "rangeTo", "-", "$", "rangeFrom", ")", ";", "}" ]
Respond with a 206 Partial content with `Content-Range` header @param int $rangeFrom Beginning of the range in bytes @param int $rangeTo End of the range in bytes @param int $totalSize Total size in bytes
[ "Respond", "with", "a", "206", "Partial", "content", "with", "Content", "-", "Range", "header" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L143-L149
jasny/controller
src/Controller/Output.php
Output.redirect
public function redirect($url, $code = 303) { $this->respondWith($code); $this->setResponseHeader('Location', $url); $urlHtml = htmlentities($url); $this->output('You are being redirected to <a href="' . $urlHtml . '">' . $urlHtml . '</a>', 'text/html'); }
php
public function redirect($url, $code = 303) { $this->respondWith($code); $this->setResponseHeader('Location', $url); $urlHtml = htmlentities($url); $this->output('You are being redirected to <a href="' . $urlHtml . '">' . $urlHtml . '</a>', 'text/html'); }
[ "public", "function", "redirect", "(", "$", "url", ",", "$", "code", "=", "303", ")", "{", "$", "this", "->", "respondWith", "(", "$", "code", ")", ";", "$", "this", "->", "setResponseHeader", "(", "'Location'", ",", "$", "url", ")", ";", "$", "urlHtml", "=", "htmlentities", "(", "$", "url", ")", ";", "$", "this", "->", "output", "(", "'You are being redirected to <a href=\"'", ".", "$", "urlHtml", ".", "'\">'", ".", "$", "urlHtml", ".", "'</a>'", ",", "'text/html'", ")", ";", "}" ]
Redirect to url and output a short message with the link @param string $url @param int $code 301 (Moved Permanently), 302 (Found), 303 (See Other) or 307 (Temporary Redirect)
[ "Redirect", "to", "url", "and", "output", "a", "short", "message", "with", "the", "link" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L158-L165
jasny/controller
src/Controller/Output.php
Output.getContentType
protected function getContentType($format) { // Check if it's already MIME if (\Jasny\str_contains($format, '/')) { return $format; } $repository = new ApacheMimeTypes(); $mime = $repository->findType($format); if (!isset($mime)) { throw new \UnexpectedValueException("Format '$format' doesn't correspond with a MIME type"); } return $mime; }
php
protected function getContentType($format) { // Check if it's already MIME if (\Jasny\str_contains($format, '/')) { return $format; } $repository = new ApacheMimeTypes(); $mime = $repository->findType($format); if (!isset($mime)) { throw new \UnexpectedValueException("Format '$format' doesn't correspond with a MIME type"); } return $mime; }
[ "protected", "function", "getContentType", "(", "$", "format", ")", "{", "// Check if it's already MIME", "if", "(", "\\", "Jasny", "\\", "str_contains", "(", "$", "format", ",", "'/'", ")", ")", "{", "return", "$", "format", ";", "}", "$", "repository", "=", "new", "ApacheMimeTypes", "(", ")", ";", "$", "mime", "=", "$", "repository", "->", "findType", "(", "$", "format", ")", ";", "if", "(", "!", "isset", "(", "$", "mime", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "\"Format '$format' doesn't correspond with a MIME type\"", ")", ";", "}", "return", "$", "mime", ";", "}" ]
Get MIME type for extension @param string $format @return string
[ "Get", "MIME", "type", "for", "extension" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L291-L306
jasny/controller
src/Controller/Output.php
Output.serializeData
protected function serializeData($data, $contentType) { if (is_string($data)) { return $data; } $repository = new ApacheMimeTypes(); list($format) = $repository->findExtensions($contentType) + [null]; $method = 'serializeDataTo' . $format; if (method_exists($this, $method)) { return $this->$method($data); } $type = (is_object($data) ? get_class($data) . ' ' : '') . gettype($data); throw new \UnexpectedValueException("Unable to serialize $type to '$contentType'"); }
php
protected function serializeData($data, $contentType) { if (is_string($data)) { return $data; } $repository = new ApacheMimeTypes(); list($format) = $repository->findExtensions($contentType) + [null]; $method = 'serializeDataTo' . $format; if (method_exists($this, $method)) { return $this->$method($data); } $type = (is_object($data) ? get_class($data) . ' ' : '') . gettype($data); throw new \UnexpectedValueException("Unable to serialize $type to '$contentType'"); }
[ "protected", "function", "serializeData", "(", "$", "data", ",", "$", "contentType", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "return", "$", "data", ";", "}", "$", "repository", "=", "new", "ApacheMimeTypes", "(", ")", ";", "list", "(", "$", "format", ")", "=", "$", "repository", "->", "findExtensions", "(", "$", "contentType", ")", "+", "[", "null", "]", ";", "$", "method", "=", "'serializeDataTo'", ".", "$", "format", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "return", "$", "this", "->", "$", "method", "(", "$", "data", ")", ";", "}", "$", "type", "=", "(", "is_object", "(", "$", "data", ")", "?", "get_class", "(", "$", "data", ")", ".", "' '", ":", "''", ")", ".", "gettype", "(", "$", "data", ")", ";", "throw", "new", "\\", "UnexpectedValueException", "(", "\"Unable to serialize $type to '$contentType'\"", ")", ";", "}" ]
Serialize data @param mixed $data @param string $contentType @return string
[ "Serialize", "data" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L326-L343
jasny/controller
src/Controller/Output.php
Output.serializeDataToXml
private function serializeDataToXml($data) { if ($data instanceof \SimpleXMLElement) { return $data->asXML(); } if (($data instanceof \DOMNode && isset($data->ownerDocument)) || $data instanceof \DOMDocument) { $dom = $data instanceof \DOMDocument ? $data : $data->ownerDocument; return $dom->saveXML($data); } $type = (is_object($data) ? get_class($data) . ' ' : '') . gettype($data); throw new \UnexpectedValueException("Unable to serialize $type to XML"); }
php
private function serializeDataToXml($data) { if ($data instanceof \SimpleXMLElement) { return $data->asXML(); } if (($data instanceof \DOMNode && isset($data->ownerDocument)) || $data instanceof \DOMDocument) { $dom = $data instanceof \DOMDocument ? $data : $data->ownerDocument; return $dom->saveXML($data); } $type = (is_object($data) ? get_class($data) . ' ' : '') . gettype($data); throw new \UnexpectedValueException("Unable to serialize $type to XML"); }
[ "private", "function", "serializeDataToXml", "(", "$", "data", ")", "{", "if", "(", "$", "data", "instanceof", "\\", "SimpleXMLElement", ")", "{", "return", "$", "data", "->", "asXML", "(", ")", ";", "}", "if", "(", "(", "$", "data", "instanceof", "\\", "DOMNode", "&&", "isset", "(", "$", "data", "->", "ownerDocument", ")", ")", "||", "$", "data", "instanceof", "\\", "DOMDocument", ")", "{", "$", "dom", "=", "$", "data", "instanceof", "\\", "DOMDocument", "?", "$", "data", ":", "$", "data", "->", "ownerDocument", ";", "return", "$", "dom", "->", "saveXML", "(", "$", "data", ")", ";", "}", "$", "type", "=", "(", "is_object", "(", "$", "data", ")", "?", "get_class", "(", "$", "data", ")", ".", "' '", ":", "''", ")", ".", "gettype", "(", "$", "data", ")", ";", "throw", "new", "\\", "UnexpectedValueException", "(", "\"Unable to serialize $type to XML\"", ")", ";", "}" ]
Serialize data to XML. @internal made private because this will likely move to a library @param mixed $data @return string
[ "Serialize", "data", "to", "XML", ".", "@internal", "made", "private", "because", "this", "will", "likely", "move", "to", "a", "library" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L364-L377
jasny/controller
src/Controller/Output.php
Output.outputContentType
protected function outputContentType($format) { if (!isset($format)) { $contentType = $this->getResponse()->getHeaderLine('Content-Type'); if (empty($contentType)) { $format = $this->defaultFormat ?: 'text/html'; } } if (empty($contentType)) { $contentType = $this->getContentType($format); $this->setResponseHeader('Content-Type', $contentType); } return $contentType; }
php
protected function outputContentType($format) { if (!isset($format)) { $contentType = $this->getResponse()->getHeaderLine('Content-Type'); if (empty($contentType)) { $format = $this->defaultFormat ?: 'text/html'; } } if (empty($contentType)) { $contentType = $this->getContentType($format); $this->setResponseHeader('Content-Type', $contentType); } return $contentType; }
[ "protected", "function", "outputContentType", "(", "$", "format", ")", "{", "if", "(", "!", "isset", "(", "$", "format", ")", ")", "{", "$", "contentType", "=", "$", "this", "->", "getResponse", "(", ")", "->", "getHeaderLine", "(", "'Content-Type'", ")", ";", "if", "(", "empty", "(", "$", "contentType", ")", ")", "{", "$", "format", "=", "$", "this", "->", "defaultFormat", "?", ":", "'text/html'", ";", "}", "}", "if", "(", "empty", "(", "$", "contentType", ")", ")", "{", "$", "contentType", "=", "$", "this", "->", "getContentType", "(", "$", "format", ")", ";", "$", "this", "->", "setResponseHeader", "(", "'Content-Type'", ",", "$", "contentType", ")", ";", "}", "return", "$", "contentType", ";", "}" ]
Set the content type for the output @param string $format @return string
[ "Set", "the", "content", "type", "for", "the", "output" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L385-L401
jasny/controller
src/Controller/Output.php
Output.output
public function output($data, $format = null) { $contentType = $this->outputContentType($format); try { $content = $this->serializeData($data, $contentType); } catch (\UnexpectedValueException $e) { if (!isset($format) && isset($this->defaultFormat) && $this->defaultFormat !== $contentType) { $this->output($data, $this->defaultFormat); // Try default format instead return; } throw $e; } $this->getResponse()->getBody()->write($content); }
php
public function output($data, $format = null) { $contentType = $this->outputContentType($format); try { $content = $this->serializeData($data, $contentType); } catch (\UnexpectedValueException $e) { if (!isset($format) && isset($this->defaultFormat) && $this->defaultFormat !== $contentType) { $this->output($data, $this->defaultFormat); // Try default format instead return; } throw $e; } $this->getResponse()->getBody()->write($content); }
[ "public", "function", "output", "(", "$", "data", ",", "$", "format", "=", "null", ")", "{", "$", "contentType", "=", "$", "this", "->", "outputContentType", "(", "$", "format", ")", ";", "try", "{", "$", "content", "=", "$", "this", "->", "serializeData", "(", "$", "data", ",", "$", "contentType", ")", ";", "}", "catch", "(", "\\", "UnexpectedValueException", "$", "e", ")", "{", "if", "(", "!", "isset", "(", "$", "format", ")", "&&", "isset", "(", "$", "this", "->", "defaultFormat", ")", "&&", "$", "this", "->", "defaultFormat", "!==", "$", "contentType", ")", "{", "$", "this", "->", "output", "(", "$", "data", ",", "$", "this", "->", "defaultFormat", ")", ";", "// Try default format instead", "return", ";", "}", "throw", "$", "e", ";", "}", "$", "this", "->", "getResponse", "(", ")", "->", "getBody", "(", ")", "->", "write", "(", "$", "content", ")", ";", "}" ]
Output result @param mixed $data @param string $format Output format as MIME or extension
[ "Output", "result" ]
train
https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/Output.php#L409-L425
delaneymethod/sharepoint-api
src/Client.php
Client.createFolder
public function createFolder($path) : bool { $path = $this->normalizePath($path); // Check if the path contains folders we dont want to create if (str_contains($path, $this->folderPathExcludeList)) { return true; } $this->folderPath = '/sites/'.$this->siteName.'/Shared%20Documents'; $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/folders'; $this->requestHeaders['Content-Type'] = 'application/json;odata=verbose'; $folderAttributes = [ '__metadata' => [ 'type' => 'SP.Folder', ], 'ServerRelativeUrl' => $this->folderPath.$path, ]; $options = [ 'headers' => $this->requestHeaders, 'body' => json_encode($folderAttributes) ]; $response = $this->send('POST', $requestUrl, $options); return $response->getStatusCode() === 200 ? true : false; }
php
public function createFolder($path) : bool { $path = $this->normalizePath($path); // Check if the path contains folders we dont want to create if (str_contains($path, $this->folderPathExcludeList)) { return true; } $this->folderPath = '/sites/'.$this->siteName.'/Shared%20Documents'; $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/folders'; $this->requestHeaders['Content-Type'] = 'application/json;odata=verbose'; $folderAttributes = [ '__metadata' => [ 'type' => 'SP.Folder', ], 'ServerRelativeUrl' => $this->folderPath.$path, ]; $options = [ 'headers' => $this->requestHeaders, 'body' => json_encode($folderAttributes) ]; $response = $this->send('POST', $requestUrl, $options); return $response->getStatusCode() === 200 ? true : false; }
[ "public", "function", "createFolder", "(", "$", "path", ")", ":", "bool", "{", "$", "path", "=", "$", "this", "->", "normalizePath", "(", "$", "path", ")", ";", "// Check if the path contains folders we dont want to create", "if", "(", "str_contains", "(", "$", "path", ",", "$", "this", "->", "folderPathExcludeList", ")", ")", "{", "return", "true", ";", "}", "$", "this", "->", "folderPath", "=", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/Shared%20Documents'", ";", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/folders'", ";", "$", "this", "->", "requestHeaders", "[", "'Content-Type'", "]", "=", "'application/json;odata=verbose'", ";", "$", "folderAttributes", "=", "[", "'__metadata'", "=>", "[", "'type'", "=>", "'SP.Folder'", ",", "]", ",", "'ServerRelativeUrl'", "=>", "$", "this", "->", "folderPath", ".", "$", "path", ",", "]", ";", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "'body'", "=>", "json_encode", "(", "$", "folderAttributes", ")", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'POST'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "return", "$", "response", "->", "getStatusCode", "(", ")", "===", "200", "?", "true", ":", "false", ";", "}" ]
Create a folder at a given path.
[ "Create", "a", "folder", "at", "a", "given", "path", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L71-L101
delaneymethod/sharepoint-api
src/Client.php
Client.delete
public function delete(string $path) : bool { $path = $this->normalizePath($path); // Check if the path contains folders we dont want to delete if (str_contains($path, $this->folderPathExcludeList)) { return true; } $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; $this->requestHeaders['IF-MATCH'] = 'etag'; $this->requestHeaders['X-HTTP-Method'] = 'DELETE'; $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('POST', $requestUrl, $options); return $response->getStatusCode() === 200 ? true : false; }
php
public function delete(string $path) : bool { $path = $this->normalizePath($path); // Check if the path contains folders we dont want to delete if (str_contains($path, $this->folderPathExcludeList)) { return true; } $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; $this->requestHeaders['IF-MATCH'] = 'etag'; $this->requestHeaders['X-HTTP-Method'] = 'DELETE'; $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('POST', $requestUrl, $options); return $response->getStatusCode() === 200 ? true : false; }
[ "public", "function", "delete", "(", "string", "$", "path", ")", ":", "bool", "{", "$", "path", "=", "$", "this", "->", "normalizePath", "(", "$", "path", ")", ";", "// Check if the path contains folders we dont want to delete", "if", "(", "str_contains", "(", "$", "path", ",", "$", "this", "->", "folderPathExcludeList", ")", ")", "{", "return", "true", ";", "}", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFolderByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "path", ".", "'\\')'", ";", "$", "this", "->", "requestHeaders", "[", "'IF-MATCH'", "]", "=", "'etag'", ";", "$", "this", "->", "requestHeaders", "[", "'X-HTTP-Method'", "]", "=", "'DELETE'", ";", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'POST'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "return", "$", "response", "->", "getStatusCode", "(", ")", "===", "200", "?", "true", ":", "false", ";", "}" ]
Delete the file or folder at a given path. If the path is a folder, all its contents will be deleted too. A successful response indicates that the file or folder was deleted.
[ "Delete", "the", "file", "or", "folder", "at", "a", "given", "path", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L109-L131
delaneymethod/sharepoint-api
src/Client.php
Client.getMetadata
public function getMetadata(string $path, array $mimeType) : array { $path = $this->normalizePath($path); // If plain/text, its a folder if (substr($mimeType['mimetype'], 0, 4) === 'text') { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; } else { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFileByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; } $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('GET', $requestUrl, $options); $metadata = json_decode($response->getBody())->d ?? []; // Making sure we convert the object to an array if (!is_array($metadata)) { $metadata = json_decode(json_encode($metadata), true); } return $metadata; }
php
public function getMetadata(string $path, array $mimeType) : array { $path = $this->normalizePath($path); // If plain/text, its a folder if (substr($mimeType['mimetype'], 0, 4) === 'text') { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; } else { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFileByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; } $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('GET', $requestUrl, $options); $metadata = json_decode($response->getBody())->d ?? []; // Making sure we convert the object to an array if (!is_array($metadata)) { $metadata = json_decode(json_encode($metadata), true); } return $metadata; }
[ "public", "function", "getMetadata", "(", "string", "$", "path", ",", "array", "$", "mimeType", ")", ":", "array", "{", "$", "path", "=", "$", "this", "->", "normalizePath", "(", "$", "path", ")", ";", "// If plain/text, its a folder", "if", "(", "substr", "(", "$", "mimeType", "[", "'mimetype'", "]", ",", "0", ",", "4", ")", "===", "'text'", ")", "{", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFolderByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "path", ".", "'\\')'", ";", "}", "else", "{", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFileByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "path", ".", "'\\')'", ";", "}", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'GET'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "$", "metadata", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ")", "->", "d", "??", "[", "]", ";", "// Making sure we convert the object to an array", "if", "(", "!", "is_array", "(", "$", "metadata", ")", ")", "{", "$", "metadata", "=", "json_decode", "(", "json_encode", "(", "$", "metadata", ")", ",", "true", ")", ";", "}", "return", "$", "metadata", ";", "}" ]
Returns the metadata for a file or folder. Note: Metadata for the root folder is unsupported.
[ "Returns", "the", "metadata", "for", "a", "file", "or", "folder", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L138-L163
delaneymethod/sharepoint-api
src/Client.php
Client.listFolder
public function listFolder(string $path, bool $recursive = false) : array { $path = $this->normalizePath($path); $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')/Folders'; $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('GET', $requestUrl, $options); $folders = json_decode($response->getBody())->d ?? ['results' => []]; // Making sure we convert the object to an array if (!is_array($folders)) { $folders = json_decode(json_encode($folders), true); } return $folders['results']; }
php
public function listFolder(string $path, bool $recursive = false) : array { $path = $this->normalizePath($path); $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$path.'\')/Folders'; $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('GET', $requestUrl, $options); $folders = json_decode($response->getBody())->d ?? ['results' => []]; // Making sure we convert the object to an array if (!is_array($folders)) { $folders = json_decode(json_encode($folders), true); } return $folders['results']; }
[ "public", "function", "listFolder", "(", "string", "$", "path", ",", "bool", "$", "recursive", "=", "false", ")", ":", "array", "{", "$", "path", "=", "$", "this", "->", "normalizePath", "(", "$", "path", ")", ";", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFolderByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "path", ".", "'\\')/Folders'", ";", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'GET'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "$", "folders", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ")", "->", "d", "??", "[", "'results'", "=>", "[", "]", "]", ";", "// Making sure we convert the object to an array", "if", "(", "!", "is_array", "(", "$", "folders", ")", ")", "{", "$", "folders", "=", "json_decode", "(", "json_encode", "(", "$", "folders", ")", ",", "true", ")", ";", "}", "return", "$", "folders", "[", "'results'", "]", ";", "}" ]
Returns the contents of a folder.
[ "Returns", "the", "contents", "of", "a", "folder", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L168-L188
delaneymethod/sharepoint-api
src/Client.php
Client.copy
public function copy(string $fromPath, string $toPath, array $mimeType) : bool { $fromPath = $this->normalizePath($fromPath); $toPath = $this->normalizePath($toPath); // If plain/text, its a folder if (substr($mimeType['mimetype'], 0, 4) === 'text') { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$fromPath.'\')/copyTo(strNewUrl=\''.$this->folderPath.$toPath.'\', bOverWrite=true)'; } else { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFileByServerRelativeUrl(\''.$this->folderPath.$fromPath.'\')/copyTo(strNewUrl=\''.$this->folderPath.$toPath.'\', bOverWrite=true)'; } $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('POST', $requestUrl, $options); return $response->getStatusCode() === 200 ? true : false; }
php
public function copy(string $fromPath, string $toPath, array $mimeType) : bool { $fromPath = $this->normalizePath($fromPath); $toPath = $this->normalizePath($toPath); // If plain/text, its a folder if (substr($mimeType['mimetype'], 0, 4) === 'text') { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.$fromPath.'\')/copyTo(strNewUrl=\''.$this->folderPath.$toPath.'\', bOverWrite=true)'; } else { $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFileByServerRelativeUrl(\''.$this->folderPath.$fromPath.'\')/copyTo(strNewUrl=\''.$this->folderPath.$toPath.'\', bOverWrite=true)'; } $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('POST', $requestUrl, $options); return $response->getStatusCode() === 200 ? true : false; }
[ "public", "function", "copy", "(", "string", "$", "fromPath", ",", "string", "$", "toPath", ",", "array", "$", "mimeType", ")", ":", "bool", "{", "$", "fromPath", "=", "$", "this", "->", "normalizePath", "(", "$", "fromPath", ")", ";", "$", "toPath", "=", "$", "this", "->", "normalizePath", "(", "$", "toPath", ")", ";", "// If plain/text, its a folder", "if", "(", "substr", "(", "$", "mimeType", "[", "'mimetype'", "]", ",", "0", ",", "4", ")", "===", "'text'", ")", "{", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFolderByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "fromPath", ".", "'\\')/copyTo(strNewUrl=\\''", ".", "$", "this", "->", "folderPath", ".", "$", "toPath", ".", "'\\', bOverWrite=true)'", ";", "}", "else", "{", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFileByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "fromPath", ".", "'\\')/copyTo(strNewUrl=\\''", ".", "$", "this", "->", "folderPath", ".", "$", "toPath", ".", "'\\', bOverWrite=true)'", ";", "}", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'POST'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "return", "$", "response", "->", "getStatusCode", "(", ")", "===", "200", "?", "true", ":", "false", ";", "}" ]
Copy a file or folder to a different location. https://msdn.microsoft.com/en-us/library/office/jj247198%28v=office.15%29.aspx
[ "Copy", "a", "file", "or", "folder", "to", "a", "different", "location", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L195-L215
delaneymethod/sharepoint-api
src/Client.php
Client.upload
public function upload(string $path, $contents) : array { $path = trim($path, '/'); // Split the path so we can grab the filename and folder path $segments = explode('/', $path); // Filename will be last item $path = last($segments); // Remove filename from segments so we're left with the folder path array_pop($segments); // Update the folder path $folderPath = implode('/', $segments); $this->folderPath = $this->folderPath.'/'.$folderPath; $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.'\')/Files/add(url=\''.$path.'\', overwrite=true)'; $options = [ 'headers' => $this->requestHeaders, 'body' => $contents, ]; $response = $this->send('POST', $requestUrl, $options); $file = json_decode($response->getBody())->d ?? []; // Making sure we convert the object to an array if (!is_array($file)) { $file = json_decode(json_encode($file), true); } return $file; }
php
public function upload(string $path, $contents) : array { $path = trim($path, '/'); // Split the path so we can grab the filename and folder path $segments = explode('/', $path); // Filename will be last item $path = last($segments); // Remove filename from segments so we're left with the folder path array_pop($segments); // Update the folder path $folderPath = implode('/', $segments); $this->folderPath = $this->folderPath.'/'.$folderPath; $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFolderByServerRelativeUrl(\''.$this->folderPath.'\')/Files/add(url=\''.$path.'\', overwrite=true)'; $options = [ 'headers' => $this->requestHeaders, 'body' => $contents, ]; $response = $this->send('POST', $requestUrl, $options); $file = json_decode($response->getBody())->d ?? []; // Making sure we convert the object to an array if (!is_array($file)) { $file = json_decode(json_encode($file), true); } return $file; }
[ "public", "function", "upload", "(", "string", "$", "path", ",", "$", "contents", ")", ":", "array", "{", "$", "path", "=", "trim", "(", "$", "path", ",", "'/'", ")", ";", "// Split the path so we can grab the filename and folder path", "$", "segments", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "// Filename will be last item", "$", "path", "=", "last", "(", "$", "segments", ")", ";", "// Remove filename from segments so we're left with the folder path", "array_pop", "(", "$", "segments", ")", ";", "// Update the folder path", "$", "folderPath", "=", "implode", "(", "'/'", ",", "$", "segments", ")", ";", "$", "this", "->", "folderPath", "=", "$", "this", "->", "folderPath", ".", "'/'", ".", "$", "folderPath", ";", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFolderByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "'\\')/Files/add(url=\\''", ".", "$", "path", ".", "'\\', overwrite=true)'", ";", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "'body'", "=>", "$", "contents", ",", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'POST'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "$", "file", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ")", "->", "d", "??", "[", "]", ";", "// Making sure we convert the object to an array", "if", "(", "!", "is_array", "(", "$", "file", ")", ")", "{", "$", "file", "=", "json_decode", "(", "json_encode", "(", "$", "file", ")", ",", "true", ")", ";", "}", "return", "$", "file", ";", "}" ]
Create a new file with the contents provided in the request. @param string $path @param string|resource $contents @return bool
[ "Create", "a", "new", "file", "with", "the", "contents", "provided", "in", "the", "request", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L252-L287
delaneymethod/sharepoint-api
src/Client.php
Client.download
public function download(string $path) { // To get specific file data pass in the value you want e.g. /Name $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFileByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('GET', $requestUrl, $options); return StreamWrapper::getResource($response->getBody()); }
php
public function download(string $path) { // To get specific file data pass in the value you want e.g. /Name $requestUrl = $this->siteUrl.'/sites/'.$this->siteName.'/_api/Web/GetFileByServerRelativeUrl(\''.$this->folderPath.$path.'\')'; $options = [ 'headers' => $this->requestHeaders, ]; $response = $this->send('GET', $requestUrl, $options); return StreamWrapper::getResource($response->getBody()); }
[ "public", "function", "download", "(", "string", "$", "path", ")", "{", "// To get specific file data pass in the value you want e.g. /Name ", "$", "requestUrl", "=", "$", "this", "->", "siteUrl", ".", "'/sites/'", ".", "$", "this", "->", "siteName", ".", "'/_api/Web/GetFileByServerRelativeUrl(\\''", ".", "$", "this", "->", "folderPath", ".", "$", "path", ".", "'\\')'", ";", "$", "options", "=", "[", "'headers'", "=>", "$", "this", "->", "requestHeaders", ",", "]", ";", "$", "response", "=", "$", "this", "->", "send", "(", "'GET'", ",", "$", "requestUrl", ",", "$", "options", ")", ";", "return", "StreamWrapper", "::", "getResource", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "}" ]
Download a file. @param string $path @return resource
[ "Download", "a", "file", "." ]
train
https://github.com/delaneymethod/sharepoint-api/blob/1ede2742292a13896f071427da5995abf5e9a545/src/Client.php#L296-L308
mothership-ec/composer
src/Composer/Repository/ArrayRepository.php
ArrayRepository.findPackage
public function findPackage($name, $version) { // normalize version & name $versionParser = new VersionParser(); $version = $versionParser->normalize($version); $name = strtolower($name); foreach ($this->getPackages() as $package) { if ($name === $package->getName() && $version === $package->getVersion()) { return $package; } } }
php
public function findPackage($name, $version) { // normalize version & name $versionParser = new VersionParser(); $version = $versionParser->normalize($version); $name = strtolower($name); foreach ($this->getPackages() as $package) { if ($name === $package->getName() && $version === $package->getVersion()) { return $package; } } }
[ "public", "function", "findPackage", "(", "$", "name", ",", "$", "version", ")", "{", "// normalize version & name", "$", "versionParser", "=", "new", "VersionParser", "(", ")", ";", "$", "version", "=", "$", "versionParser", "->", "normalize", "(", "$", "version", ")", ";", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "foreach", "(", "$", "this", "->", "getPackages", "(", ")", "as", "$", "package", ")", "{", "if", "(", "$", "name", "===", "$", "package", "->", "getName", "(", ")", "&&", "$", "version", "===", "$", "package", "->", "getVersion", "(", ")", ")", "{", "return", "$", "package", ";", "}", "}", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/ArrayRepository.php#L39-L51
mothership-ec/composer
src/Composer/Repository/ArrayRepository.php
ArrayRepository.findPackages
public function findPackages($name, $version = null) { // normalize name $name = strtolower($name); // normalize version if (null !== $version) { $versionParser = new VersionParser(); $version = $versionParser->normalize($version); } $packages = array(); foreach ($this->getPackages() as $package) { if ($package->getName() === $name && (null === $version || $version === $package->getVersion())) { $packages[] = $package; } } return $packages; }
php
public function findPackages($name, $version = null) { // normalize name $name = strtolower($name); // normalize version if (null !== $version) { $versionParser = new VersionParser(); $version = $versionParser->normalize($version); } $packages = array(); foreach ($this->getPackages() as $package) { if ($package->getName() === $name && (null === $version || $version === $package->getVersion())) { $packages[] = $package; } } return $packages; }
[ "public", "function", "findPackages", "(", "$", "name", ",", "$", "version", "=", "null", ")", "{", "// normalize name", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "// normalize version", "if", "(", "null", "!==", "$", "version", ")", "{", "$", "versionParser", "=", "new", "VersionParser", "(", ")", ";", "$", "version", "=", "$", "versionParser", "->", "normalize", "(", "$", "version", ")", ";", "}", "$", "packages", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getPackages", "(", ")", "as", "$", "package", ")", "{", "if", "(", "$", "package", "->", "getName", "(", ")", "===", "$", "name", "&&", "(", "null", "===", "$", "version", "||", "$", "version", "===", "$", "package", "->", "getVersion", "(", ")", ")", ")", "{", "$", "packages", "[", "]", "=", "$", "package", ";", "}", "}", "return", "$", "packages", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/ArrayRepository.php#L56-L76
alevilar/ristorantino-vendor
Printers/Lib/PrinterOutput/FilePrinterOutput.php
FilePrinterOutput.send
public function send( $printaitorViewObj ) { $texto = $printaitorViewObj->viewTextRender; $nombreImpresoraFiscal = $printaitorViewObj->printer['Printer']['alias']; $hostname = $printaitorViewObj->hostName; $nombreImpresoraFiscal = Inflector::slug($nombreImpresoraFiscal); // crear carpeta $printerFolderPath = "/tmp/$this->folder/$nombreImpresoraFiscal"; $folder = new Folder(); $folder->create($printerFolderPath, 0777); // crear archivo $randomName = md5( "$printerFolderPath".$texto ); $printerNamePath = "$printerFolderPath/$randomName.txt"; $file = new File($printerNamePath , $create = true, 0777); $file->write($texto); return $file->close(); }
php
public function send( $printaitorViewObj ) { $texto = $printaitorViewObj->viewTextRender; $nombreImpresoraFiscal = $printaitorViewObj->printer['Printer']['alias']; $hostname = $printaitorViewObj->hostName; $nombreImpresoraFiscal = Inflector::slug($nombreImpresoraFiscal); // crear carpeta $printerFolderPath = "/tmp/$this->folder/$nombreImpresoraFiscal"; $folder = new Folder(); $folder->create($printerFolderPath, 0777); // crear archivo $randomName = md5( "$printerFolderPath".$texto ); $printerNamePath = "$printerFolderPath/$randomName.txt"; $file = new File($printerNamePath , $create = true, 0777); $file->write($texto); return $file->close(); }
[ "public", "function", "send", "(", "$", "printaitorViewObj", ")", "{", "$", "texto", "=", "$", "printaitorViewObj", "->", "viewTextRender", ";", "$", "nombreImpresoraFiscal", "=", "$", "printaitorViewObj", "->", "printer", "[", "'Printer'", "]", "[", "'alias'", "]", ";", "$", "hostname", "=", "$", "printaitorViewObj", "->", "hostName", ";", "$", "nombreImpresoraFiscal", "=", "Inflector", "::", "slug", "(", "$", "nombreImpresoraFiscal", ")", ";", "// crear carpeta", "$", "printerFolderPath", "=", "\"/tmp/$this->folder/$nombreImpresoraFiscal\"", ";", "$", "folder", "=", "new", "Folder", "(", ")", ";", "$", "folder", "->", "create", "(", "$", "printerFolderPath", ",", "0777", ")", ";", "// crear archivo", "$", "randomName", "=", "md5", "(", "\"$printerFolderPath\"", ".", "$", "texto", ")", ";", "$", "printerNamePath", "=", "\"$printerFolderPath/$randomName.txt\"", ";", "$", "file", "=", "new", "File", "(", "$", "printerNamePath", ",", "$", "create", "=", "true", ",", "0777", ")", ";", "$", "file", "->", "write", "(", "$", "texto", ")", ";", "return", "$", "file", "->", "close", "(", ")", ";", "}" ]
Crea un archivo y lo coloca en la carpeta /tmp @param string $texto es el texto a imprimir @param string $nombreImpresoraFiscal nombre de la impresora @param string $hostname nombre o IP del host @return type boolean true si salio todo bien false caso contrario
[ "Crea", "un", "archivo", "y", "lo", "coloca", "en", "la", "carpeta", "/", "tmp" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Printers/Lib/PrinterOutput/FilePrinterOutput.php#L41-L59
php-lug/lug
app/AppKernel.php
AppKernel.registerBundles
public function registerBundles() { $bundles = [ new FrameworkBundle(), new SecurityBundle(), new TwigBundle(), new MonologBundle(), new FOSRestBundle(), new JMSSerializerBundle(), new BazingaHateoasBundle(), new IvoryBase64FileBundle(), new A2lixTranslationFormBundle(), new WhiteOctoberPagerfantaBundle(), new StofDoctrineExtensionsBundle(), new LugAdminBundle(), new LugGridBundle(), new LugLocaleBundle($this->driver), new LugResourceBundle(), new LugStorageBundle(), new LugTranslationBundle(), new LugUiBundle(), // FIXME - The registry bundle must be defined after all lug bundles // https://github.com/symfony/symfony/issues/13609 new LugRegistryBundle(), // FIXME - The knp bundle must be defined after the lug ui bundle // https://github.com/symfony/symfony/issues/13609 new KnpMenuBundle(), ]; // FIXME - The doctrine bundles must be defined after the lug resource bundle // https://github.com/symfony/symfony/issues/13609 if ($this->driver === ResourceInterface::DRIVER_DOCTRINE_ORM) { $bundles[] = new DoctrineBundle(); } elseif ($this->driver === ResourceInterface::DRIVER_DOCTRINE_MONGODB) { $bundles[] = new DoctrineMongoDBBundle(); } if (in_array($this->getEnvironment(), [self::ENVIRONMENT_DEV, self::ENVIRONMENT_TEST], true)) { $bundles[] = new DebugBundle(); $bundles[] = new WebProfilerBundle(); $bundles[] = new SensioDistributionBundle(); if ($this->driver === ResourceInterface::DRIVER_DOCTRINE_ORM) { $bundles[] = new DoctrineFixturesBundle(); } } return $bundles; }
php
public function registerBundles() { $bundles = [ new FrameworkBundle(), new SecurityBundle(), new TwigBundle(), new MonologBundle(), new FOSRestBundle(), new JMSSerializerBundle(), new BazingaHateoasBundle(), new IvoryBase64FileBundle(), new A2lixTranslationFormBundle(), new WhiteOctoberPagerfantaBundle(), new StofDoctrineExtensionsBundle(), new LugAdminBundle(), new LugGridBundle(), new LugLocaleBundle($this->driver), new LugResourceBundle(), new LugStorageBundle(), new LugTranslationBundle(), new LugUiBundle(), // FIXME - The registry bundle must be defined after all lug bundles // https://github.com/symfony/symfony/issues/13609 new LugRegistryBundle(), // FIXME - The knp bundle must be defined after the lug ui bundle // https://github.com/symfony/symfony/issues/13609 new KnpMenuBundle(), ]; // FIXME - The doctrine bundles must be defined after the lug resource bundle // https://github.com/symfony/symfony/issues/13609 if ($this->driver === ResourceInterface::DRIVER_DOCTRINE_ORM) { $bundles[] = new DoctrineBundle(); } elseif ($this->driver === ResourceInterface::DRIVER_DOCTRINE_MONGODB) { $bundles[] = new DoctrineMongoDBBundle(); } if (in_array($this->getEnvironment(), [self::ENVIRONMENT_DEV, self::ENVIRONMENT_TEST], true)) { $bundles[] = new DebugBundle(); $bundles[] = new WebProfilerBundle(); $bundles[] = new SensioDistributionBundle(); if ($this->driver === ResourceInterface::DRIVER_DOCTRINE_ORM) { $bundles[] = new DoctrineFixturesBundle(); } } return $bundles; }
[ "public", "function", "registerBundles", "(", ")", "{", "$", "bundles", "=", "[", "new", "FrameworkBundle", "(", ")", ",", "new", "SecurityBundle", "(", ")", ",", "new", "TwigBundle", "(", ")", ",", "new", "MonologBundle", "(", ")", ",", "new", "FOSRestBundle", "(", ")", ",", "new", "JMSSerializerBundle", "(", ")", ",", "new", "BazingaHateoasBundle", "(", ")", ",", "new", "IvoryBase64FileBundle", "(", ")", ",", "new", "A2lixTranslationFormBundle", "(", ")", ",", "new", "WhiteOctoberPagerfantaBundle", "(", ")", ",", "new", "StofDoctrineExtensionsBundle", "(", ")", ",", "new", "LugAdminBundle", "(", ")", ",", "new", "LugGridBundle", "(", ")", ",", "new", "LugLocaleBundle", "(", "$", "this", "->", "driver", ")", ",", "new", "LugResourceBundle", "(", ")", ",", "new", "LugStorageBundle", "(", ")", ",", "new", "LugTranslationBundle", "(", ")", ",", "new", "LugUiBundle", "(", ")", ",", "// FIXME - The registry bundle must be defined after all lug bundles", "// https://github.com/symfony/symfony/issues/13609", "new", "LugRegistryBundle", "(", ")", ",", "// FIXME - The knp bundle must be defined after the lug ui bundle", "// https://github.com/symfony/symfony/issues/13609", "new", "KnpMenuBundle", "(", ")", ",", "]", ";", "// FIXME - The doctrine bundles must be defined after the lug resource bundle", "// https://github.com/symfony/symfony/issues/13609", "if", "(", "$", "this", "->", "driver", "===", "ResourceInterface", "::", "DRIVER_DOCTRINE_ORM", ")", "{", "$", "bundles", "[", "]", "=", "new", "DoctrineBundle", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "driver", "===", "ResourceInterface", "::", "DRIVER_DOCTRINE_MONGODB", ")", "{", "$", "bundles", "[", "]", "=", "new", "DoctrineMongoDBBundle", "(", ")", ";", "}", "if", "(", "in_array", "(", "$", "this", "->", "getEnvironment", "(", ")", ",", "[", "self", "::", "ENVIRONMENT_DEV", ",", "self", "::", "ENVIRONMENT_TEST", "]", ",", "true", ")", ")", "{", "$", "bundles", "[", "]", "=", "new", "DebugBundle", "(", ")", ";", "$", "bundles", "[", "]", "=", "new", "WebProfilerBundle", "(", ")", ";", "$", "bundles", "[", "]", "=", "new", "SensioDistributionBundle", "(", ")", ";", "if", "(", "$", "this", "->", "driver", "===", "ResourceInterface", "::", "DRIVER_DOCTRINE_ORM", ")", "{", "$", "bundles", "[", "]", "=", "new", "DoctrineFixturesBundle", "(", ")", ";", "}", "}", "return", "$", "bundles", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/app/AppKernel.php#L69-L120
php-lug/lug
app/AppKernel.php
AppKernel.registerContainerConfiguration
public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); $this->registerDriverConfiguration($loader); }
php
public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); $this->registerDriverConfiguration($loader); }
[ "public", "function", "registerContainerConfiguration", "(", "LoaderInterface", "$", "loader", ")", "{", "$", "loader", "->", "load", "(", "$", "this", "->", "getRootDir", "(", ")", ".", "'/config/config_'", ".", "$", "this", "->", "getEnvironment", "(", ")", ".", "'.yml'", ")", ";", "$", "this", "->", "registerDriverConfiguration", "(", "$", "loader", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/app/AppKernel.php#L149-L154
discodian/core
src/Foundation/Application.php
Application.registerConfiguredProviders
public function registerConfiguredProviders() { foreach ([ CacheProvider::class, PartProvider::class, SchedulingProvider::class, ViewProvider::class, EventProvider::class, DatabaseProvider::class, LogProvider::class, HttpProvider::class, SocketProvider::class, ExtendProvider::class, ] as $provider) { $this->register($provider); } }
php
public function registerConfiguredProviders() { foreach ([ CacheProvider::class, PartProvider::class, SchedulingProvider::class, ViewProvider::class, EventProvider::class, DatabaseProvider::class, LogProvider::class, HttpProvider::class, SocketProvider::class, ExtendProvider::class, ] as $provider) { $this->register($provider); } }
[ "public", "function", "registerConfiguredProviders", "(", ")", "{", "foreach", "(", "[", "CacheProvider", "::", "class", ",", "PartProvider", "::", "class", ",", "SchedulingProvider", "::", "class", ",", "ViewProvider", "::", "class", ",", "EventProvider", "::", "class", ",", "DatabaseProvider", "::", "class", ",", "LogProvider", "::", "class", ",", "HttpProvider", "::", "class", ",", "SocketProvider", "::", "class", ",", "ExtendProvider", "::", "class", ",", "]", "as", "$", "provider", ")", "{", "$", "this", "->", "register", "(", "$", "provider", ")", ";", "}", "}" ]
Register all of the configured providers. @return void
[ "Register", "all", "of", "the", "configured", "providers", "." ]
train
https://github.com/discodian/core/blob/e007855f7c161e12391469eb39eaaf39cbb59897/src/Foundation/Application.php#L208-L225
discodian/core
src/Foundation/Application.php
Application.register
public function register($provider, $options = [], $force = false) { $instance = new $provider($this); if (method_exists($instance, 'register')) { $this->call([$instance, 'register']); } $this->providers[$provider] = $instance; }
php
public function register($provider, $options = [], $force = false) { $instance = new $provider($this); if (method_exists($instance, 'register')) { $this->call([$instance, 'register']); } $this->providers[$provider] = $instance; }
[ "public", "function", "register", "(", "$", "provider", ",", "$", "options", "=", "[", "]", ",", "$", "force", "=", "false", ")", "{", "$", "instance", "=", "new", "$", "provider", "(", "$", "this", ")", ";", "if", "(", "method_exists", "(", "$", "instance", ",", "'register'", ")", ")", "{", "$", "this", "->", "call", "(", "[", "$", "instance", ",", "'register'", "]", ")", ";", "}", "$", "this", "->", "providers", "[", "$", "provider", "]", "=", "$", "instance", ";", "}" ]
Register a service provider with the application. @param \Illuminate\Support\ServiceProvider|string $provider @param array $options @param bool $force @return \Illuminate\Support\ServiceProvider
[ "Register", "a", "service", "provider", "with", "the", "application", "." ]
train
https://github.com/discodian/core/blob/e007855f7c161e12391469eb39eaaf39cbb59897/src/Foundation/Application.php#L235-L242
discodian/core
src/Foundation/Application.php
Application.boot
public function boot() { if ($this->booted) { return; } $this->fireAppCallback($this->bootingCallbacks); /** @var ExtensionManager $manager */ $manager = $this->make(Manager::class); $manager->boot(); foreach ($this->providers as $provider) { if (method_exists($provider, 'boot')) { $this->call([$provider, 'boot']); } } $this->fireAppCallback($this->bootedCallbacks); }
php
public function boot() { if ($this->booted) { return; } $this->fireAppCallback($this->bootingCallbacks); /** @var ExtensionManager $manager */ $manager = $this->make(Manager::class); $manager->boot(); foreach ($this->providers as $provider) { if (method_exists($provider, 'boot')) { $this->call([$provider, 'boot']); } } $this->fireAppCallback($this->bootedCallbacks); }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "$", "this", "->", "booted", ")", "{", "return", ";", "}", "$", "this", "->", "fireAppCallback", "(", "$", "this", "->", "bootingCallbacks", ")", ";", "/** @var ExtensionManager $manager */", "$", "manager", "=", "$", "this", "->", "make", "(", "Manager", "::", "class", ")", ";", "$", "manager", "->", "boot", "(", ")", ";", "foreach", "(", "$", "this", "->", "providers", "as", "$", "provider", ")", "{", "if", "(", "method_exists", "(", "$", "provider", ",", "'boot'", ")", ")", "{", "$", "this", "->", "call", "(", "[", "$", "provider", ",", "'boot'", "]", ")", ";", "}", "}", "$", "this", "->", "fireAppCallback", "(", "$", "this", "->", "bootedCallbacks", ")", ";", "}" ]
Boot the application's service providers. @return void
[ "Boot", "the", "application", "s", "service", "providers", "." ]
train
https://github.com/discodian/core/blob/e007855f7c161e12391469eb39eaaf39cbb59897/src/Foundation/Application.php#L261-L281
kecik-framework/kecik
Kecik/Assets.php
Assets.images
public function images( $file, $version = '' ) { if ( empty( $version ) ) { $version = '?ver=' . Kecik::$version; } return $this->BaseUrl . Config::get( 'path.assets' ) . '/images/' . $file . $version; }
php
public function images( $file, $version = '' ) { if ( empty( $version ) ) { $version = '?ver=' . Kecik::$version; } return $this->BaseUrl . Config::get( 'path.assets' ) . '/images/' . $file . $version; }
[ "public", "function", "images", "(", "$", "file", ",", "$", "version", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "version", ")", ")", "{", "$", "version", "=", "'?ver='", ".", "Kecik", "::", "$", "version", ";", "}", "return", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "'/images/'", ".", "$", "file", ".", "$", "version", ";", "}" ]
Create of images Url from Assets @param $file @param string $version @return string
[ "Create", "of", "images", "Url", "from", "Assets" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Assets.php#L49-L56
kecik-framework/kecik
Kecik/Assets.php
Assets.url
public function url( $file = '', $version = '' ) { if ( empty( $version ) ) { $version = '?ver=' . Kecik::$version; } if ( ! empty( $file ) ) { return $this->BaseUrl . Config::get( 'path.assets' ) . '/' . $file . $version; } else { return $this->BaseUrl . Config::get( 'path.assets' ) . '/'; } }
php
public function url( $file = '', $version = '' ) { if ( empty( $version ) ) { $version = '?ver=' . Kecik::$version; } if ( ! empty( $file ) ) { return $this->BaseUrl . Config::get( 'path.assets' ) . '/' . $file . $version; } else { return $this->BaseUrl . Config::get( 'path.assets' ) . '/'; } }
[ "public", "function", "url", "(", "$", "file", "=", "''", ",", "$", "version", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "version", ")", ")", "{", "$", "version", "=", "'?ver='", ".", "Kecik", "::", "$", "version", ";", "}", "if", "(", "!", "empty", "(", "$", "file", ")", ")", "{", "return", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "'/'", ".", "$", "file", ".", "$", "version", ";", "}", "else", "{", "return", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "'/'", ";", "}", "}" ]
Create url from assets @param string $file @param string $version @return string
[ "Create", "url", "from", "assets" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Assets.php#L66-L78
kecik-framework/kecik
Kecik/Assets.php
AssetsBase.add
public function add( $file, $version = "", $attr = array() ) { if ( count( $attr ) <= 0 && is_array( $version ) ) { $attr = $version; $version = ""; } if ( empty( $version ) ) { $version = '?ver=' . Kecik::$version; } else { $version = '?ver=' . $version; } if ( ! in_array( $file, $this->assets[ $this->type ] ) ) { $this->assets[ $this->type ][] = $file; $this->attr[ $this->type ][] = $attr; $this->versions[ $this->type ][] = $version; } }
php
public function add( $file, $version = "", $attr = array() ) { if ( count( $attr ) <= 0 && is_array( $version ) ) { $attr = $version; $version = ""; } if ( empty( $version ) ) { $version = '?ver=' . Kecik::$version; } else { $version = '?ver=' . $version; } if ( ! in_array( $file, $this->assets[ $this->type ] ) ) { $this->assets[ $this->type ][] = $file; $this->attr[ $this->type ][] = $attr; $this->versions[ $this->type ][] = $version; } }
[ "public", "function", "add", "(", "$", "file", ",", "$", "version", "=", "\"\"", ",", "$", "attr", "=", "array", "(", ")", ")", "{", "if", "(", "count", "(", "$", "attr", ")", "<=", "0", "&&", "is_array", "(", "$", "version", ")", ")", "{", "$", "attr", "=", "$", "version", ";", "$", "version", "=", "\"\"", ";", "}", "if", "(", "empty", "(", "$", "version", ")", ")", "{", "$", "version", "=", "'?ver='", ".", "Kecik", "::", "$", "version", ";", "}", "else", "{", "$", "version", "=", "'?ver='", ".", "$", "version", ";", "}", "if", "(", "!", "in_array", "(", "$", "file", ",", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ")", "{", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", "[", "]", "=", "$", "file", ";", "$", "this", "->", "attr", "[", "$", "this", "->", "type", "]", "[", "]", "=", "$", "attr", ";", "$", "this", "->", "versions", "[", "$", "this", "->", "type", "]", "[", "]", "=", "$", "version", ";", "}", "}" ]
Add/register Assets for render to template @param $file @param string $version @param array $attr
[ "Add", "/", "register", "Assets", "for", "render", "to", "template" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Assets.php#L120-L139
kecik-framework/kecik
Kecik/Assets.php
AssetsBase.delete
public function delete( $file ) { $key = array_search( $file, $this->assets[ $this->type ] ); unset( $this->assets[ $this->type ][ $key ] ); unset( $this->attr[ $this->type ][ $key ] ); }
php
public function delete( $file ) { $key = array_search( $file, $this->assets[ $this->type ] ); unset( $this->assets[ $this->type ][ $key ] ); unset( $this->attr[ $this->type ][ $key ] ); }
[ "public", "function", "delete", "(", "$", "file", ")", "{", "$", "key", "=", "array_search", "(", "$", "file", ",", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ";", "unset", "(", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ")", ";", "unset", "(", "$", "this", "->", "attr", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ")", ";", "}" ]
Delete Assets from register delete @param $file
[ "Delete", "Assets", "from", "register", "delete" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Assets.php#L147-L151
kecik-framework/kecik
Kecik/Assets.php
AssetsBase.render
public function render( $file = '' ) { reset( $this->assets[ $this->type ] ); //reset($this->attr[$this->type]); $attr = ''; if ( $this->type == 'js' ) { if ( $file != '' ) { $key = array_search( $file, $this->assets[ $this->type ] ); $version = $this->versions[ $this->type ][ $key ]; $asset = $this->assets[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } if ( $key ) { return '<script type="text/javascript" src="' . $asset_url . '" ' . $attr . '></script>' . "\n"; } } else { $render = ''; while ( list( $key, $value ) = each( $this->assets[ $this->type ] ) ) { $asset = $this->assets[ $this->type ][ $key ]; $version = $this->versions[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } $attr = ''; while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } $render .= '<script type="text/javascript" src="' . $asset_url . '" ' . $attr . '></script>' . "\n"; } return $render; } } elseif ( $this->type == 'css' ) { if ( $file != '' ) { $key = array_search( $file, $this->assets[ $this->type ] ); $asset = $this->assets[ $this->type ][ $key ]; $version = $this->versions[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } if ( $key ) { return '<link rel="stylesheet" href="' . $asset_url . '" ' . $attr . ' />' . "\n"; } } else { $render = ''; while ( list( $key, $value ) = each( $this->assets[ $this->type ] ) ) { $attr = ''; $asset = $this->assets[ $this->type ][ $key ]; $version = $this->versions[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } $render .= '<link rel="stylesheet" href="' . $asset_url . '" ' . $attr . ' />' . "\n"; } return $render; } } }
php
public function render( $file = '' ) { reset( $this->assets[ $this->type ] ); //reset($this->attr[$this->type]); $attr = ''; if ( $this->type == 'js' ) { if ( $file != '' ) { $key = array_search( $file, $this->assets[ $this->type ] ); $version = $this->versions[ $this->type ][ $key ]; $asset = $this->assets[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } if ( $key ) { return '<script type="text/javascript" src="' . $asset_url . '" ' . $attr . '></script>' . "\n"; } } else { $render = ''; while ( list( $key, $value ) = each( $this->assets[ $this->type ] ) ) { $asset = $this->assets[ $this->type ][ $key ]; $version = $this->versions[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } $attr = ''; while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } $render .= '<script type="text/javascript" src="' . $asset_url . '" ' . $attr . '></script>' . "\n"; } return $render; } } elseif ( $this->type == 'css' ) { if ( $file != '' ) { $key = array_search( $file, $this->assets[ $this->type ] ); $asset = $this->assets[ $this->type ][ $key ]; $version = $this->versions[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } if ( $key ) { return '<link rel="stylesheet" href="' . $asset_url . '" ' . $attr . ' />' . "\n"; } } else { $render = ''; while ( list( $key, $value ) = each( $this->assets[ $this->type ] ) ) { $attr = ''; $asset = $this->assets[ $this->type ][ $key ]; $version = $this->versions[ $this->type ][ $key ]; if ( preg_match( "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $asset ) ) { $asset_url = $asset; } else { $asset_url = $this->BaseUrl . Config::get( 'path.assets' ) . "/$this->type/" . $asset . '.' . $this->type . $version; } while ( list( $at, $val ) = each( $this->attr[ $this->type ][ $key ] ) ) { $attr .= $at . '="' . $val . '" '; } $render .= '<link rel="stylesheet" href="' . $asset_url . '" ' . $attr . ' />' . "\n"; } return $render; } } }
[ "public", "function", "render", "(", "$", "file", "=", "''", ")", "{", "reset", "(", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ";", "//reset($this->attr[$this->type]);", "$", "attr", "=", "''", ";", "if", "(", "$", "this", "->", "type", "==", "'js'", ")", "{", "if", "(", "$", "file", "!=", "''", ")", "{", "$", "key", "=", "array_search", "(", "$", "file", ",", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ";", "$", "version", "=", "$", "this", "->", "versions", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "$", "asset", "=", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "if", "(", "preg_match", "(", "\"/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i\"", ",", "$", "asset", ")", ")", "{", "$", "asset_url", "=", "$", "asset", ";", "}", "else", "{", "$", "asset_url", "=", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "\"/$this->type/\"", ".", "$", "asset", ".", "'.'", ".", "$", "this", "->", "type", ".", "$", "version", ";", "}", "while", "(", "list", "(", "$", "at", ",", "$", "val", ")", "=", "each", "(", "$", "this", "->", "attr", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ")", ")", "{", "$", "attr", ".=", "$", "at", ".", "'=\"'", ".", "$", "val", ".", "'\" '", ";", "}", "if", "(", "$", "key", ")", "{", "return", "'<script type=\"text/javascript\" src=\"'", ".", "$", "asset_url", ".", "'\" '", ".", "$", "attr", ".", "'></script>'", ".", "\"\\n\"", ";", "}", "}", "else", "{", "$", "render", "=", "''", ";", "while", "(", "list", "(", "$", "key", ",", "$", "value", ")", "=", "each", "(", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ")", "{", "$", "asset", "=", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "$", "version", "=", "$", "this", "->", "versions", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "if", "(", "preg_match", "(", "\"/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i\"", ",", "$", "asset", ")", ")", "{", "$", "asset_url", "=", "$", "asset", ";", "}", "else", "{", "$", "asset_url", "=", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "\"/$this->type/\"", ".", "$", "asset", ".", "'.'", ".", "$", "this", "->", "type", ".", "$", "version", ";", "}", "$", "attr", "=", "''", ";", "while", "(", "list", "(", "$", "at", ",", "$", "val", ")", "=", "each", "(", "$", "this", "->", "attr", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ")", ")", "{", "$", "attr", ".=", "$", "at", ".", "'=\"'", ".", "$", "val", ".", "'\" '", ";", "}", "$", "render", ".=", "'<script type=\"text/javascript\" src=\"'", ".", "$", "asset_url", ".", "'\" '", ".", "$", "attr", ".", "'></script>'", ".", "\"\\n\"", ";", "}", "return", "$", "render", ";", "}", "}", "elseif", "(", "$", "this", "->", "type", "==", "'css'", ")", "{", "if", "(", "$", "file", "!=", "''", ")", "{", "$", "key", "=", "array_search", "(", "$", "file", ",", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ";", "$", "asset", "=", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "$", "version", "=", "$", "this", "->", "versions", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "if", "(", "preg_match", "(", "\"/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i\"", ",", "$", "asset", ")", ")", "{", "$", "asset_url", "=", "$", "asset", ";", "}", "else", "{", "$", "asset_url", "=", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "\"/$this->type/\"", ".", "$", "asset", ".", "'.'", ".", "$", "this", "->", "type", ".", "$", "version", ";", "}", "while", "(", "list", "(", "$", "at", ",", "$", "val", ")", "=", "each", "(", "$", "this", "->", "attr", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ")", ")", "{", "$", "attr", ".=", "$", "at", ".", "'=\"'", ".", "$", "val", ".", "'\" '", ";", "}", "if", "(", "$", "key", ")", "{", "return", "'<link rel=\"stylesheet\" href=\"'", ".", "$", "asset_url", ".", "'\" '", ".", "$", "attr", ".", "' />'", ".", "\"\\n\"", ";", "}", "}", "else", "{", "$", "render", "=", "''", ";", "while", "(", "list", "(", "$", "key", ",", "$", "value", ")", "=", "each", "(", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", ")", ")", "{", "$", "attr", "=", "''", ";", "$", "asset", "=", "$", "this", "->", "assets", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "$", "version", "=", "$", "this", "->", "versions", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ";", "if", "(", "preg_match", "(", "\"/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i\"", ",", "$", "asset", ")", ")", "{", "$", "asset_url", "=", "$", "asset", ";", "}", "else", "{", "$", "asset_url", "=", "$", "this", "->", "BaseUrl", ".", "Config", "::", "get", "(", "'path.assets'", ")", ".", "\"/$this->type/\"", ".", "$", "asset", ".", "'.'", ".", "$", "this", "->", "type", ".", "$", "version", ";", "}", "while", "(", "list", "(", "$", "at", ",", "$", "val", ")", "=", "each", "(", "$", "this", "->", "attr", "[", "$", "this", "->", "type", "]", "[", "$", "key", "]", ")", ")", "{", "$", "attr", ".=", "$", "at", ".", "'=\"'", ".", "$", "val", ".", "'\" '", ";", "}", "$", "render", ".=", "'<link rel=\"stylesheet\" href=\"'", ".", "$", "asset_url", ".", "'\" '", ".", "$", "attr", ".", "' />'", ".", "\"\\n\"", ";", "}", "return", "$", "render", ";", "}", "}", "}" ]
Render Assets which already registered @param string $file @return string
[ "Render", "Assets", "which", "already", "registered" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Assets.php#L160-L261
hametuha/wpametu
src/WPametu/UI/Field/Input.php
Input.get_field
protected function get_field( \WP_Post $post ){ $fields = []; foreach( $this->get_field_arguments() as $key => $val ){ $fields[] = sprintf('%s="%s"', $key, esc_attr($val)); } return $this->build_input($this->get_data($post), $fields); }
php
protected function get_field( \WP_Post $post ){ $fields = []; foreach( $this->get_field_arguments() as $key => $val ){ $fields[] = sprintf('%s="%s"', $key, esc_attr($val)); } return $this->build_input($this->get_data($post), $fields); }
[ "protected", "function", "get_field", "(", "\\", "WP_Post", "$", "post", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "get_field_arguments", "(", ")", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "fields", "[", "]", "=", "sprintf", "(", "'%s=\"%s\"'", ",", "$", "key", ",", "esc_attr", "(", "$", "val", ")", ")", ";", "}", "return", "$", "this", "->", "build_input", "(", "$", "this", "->", "get_data", "(", "$", "post", ")", ",", "$", "fields", ")", ";", "}" ]
Get field @param \WP_Post $post @return string
[ "Get", "field" ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Field/Input.php#L29-L35