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
CakeCMS/Core
src/Plugin.php
Plugin._checkData
protected static function _checkData($plugin) { return (Arr::in($plugin, self::$_data)) ? self::$_data[$plugin] : []; }
php
protected static function _checkData($plugin) { return (Arr::in($plugin, self::$_data)) ? self::$_data[$plugin] : []; }
[ "protected", "static", "function", "_checkData", "(", "$", "plugin", ")", "{", "return", "(", "Arr", "::", "in", "(", "$", "plugin", ",", "self", "::", "$", "_data", ")", ")", "?", "self", "::", "$", "_data", "[", "$", "plugin", "]", ":", "[", "]", ";", "}" ]
Check plugin data. @param string $plugin @return array
[ "Check", "plugin", "data", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L243-L246
CakeCMS/Core
src/Plugin.php
Plugin._findPlugin
protected static function _findPlugin($name) { $output = null; $paths = App::path('Plugin'); $plugin = Configure::read('plugins.' . $name); if ($plugin !== null) { return $plugin; } foreach ($paths as $path) { $plgPath = $path . $name . DS; if (FS::isDir($plgPath)) { $output = $plgPath; break; } } return $output; }
php
protected static function _findPlugin($name) { $output = null; $paths = App::path('Plugin'); $plugin = Configure::read('plugins.' . $name); if ($plugin !== null) { return $plugin; } foreach ($paths as $path) { $plgPath = $path . $name . DS; if (FS::isDir($plgPath)) { $output = $plgPath; break; } } return $output; }
[ "protected", "static", "function", "_findPlugin", "(", "$", "name", ")", "{", "$", "output", "=", "null", ";", "$", "paths", "=", "App", "::", "path", "(", "'Plugin'", ")", ";", "$", "plugin", "=", "Configure", "::", "read", "(", "'plugins.'", ".", "$", "name", ")", ";", "if", "(", "$", "plugin", "!==", "null", ")", "{", "return", "$", "plugin", ";", "}", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "$", "plgPath", "=", "$", "path", ".", "$", "name", ".", "DS", ";", "if", "(", "FS", "::", "isDir", "(", "$", "plgPath", ")", ")", "{", "$", "output", "=", "$", "plgPath", ";", "break", ";", "}", "}", "return", "$", "output", ";", "}" ]
Find plugin dir in registered paths. @param string $name @return null|string
[ "Find", "plugin", "dir", "in", "registered", "paths", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L254-L273
CakeCMS/Core
src/Plugin.php
Plugin._getConfigForLoad
protected static function _getConfigForLoad($path) { $config = ['autoload' => true]; $routes = $path . 'config' . DS . Plugin::FILE_ROUTES; $bootstrap = $path . 'config' . DS . Plugin::FILE_BOOTSTRAP; if (FS::isFile($bootstrap)) { $config['bootstrap'] = true; } if (FS::isFile($routes)) { $config['routes'] = true; } $config['path'] = $path; return $config; }
php
protected static function _getConfigForLoad($path) { $config = ['autoload' => true]; $routes = $path . 'config' . DS . Plugin::FILE_ROUTES; $bootstrap = $path . 'config' . DS . Plugin::FILE_BOOTSTRAP; if (FS::isFile($bootstrap)) { $config['bootstrap'] = true; } if (FS::isFile($routes)) { $config['routes'] = true; } $config['path'] = $path; return $config; }
[ "protected", "static", "function", "_getConfigForLoad", "(", "$", "path", ")", "{", "$", "config", "=", "[", "'autoload'", "=>", "true", "]", ";", "$", "routes", "=", "$", "path", ".", "'config'", ".", "DS", ".", "Plugin", "::", "FILE_ROUTES", ";", "$", "bootstrap", "=", "$", "path", ".", "'config'", ".", "DS", ".", "Plugin", "::", "FILE_BOOTSTRAP", ";", "if", "(", "FS", "::", "isFile", "(", "$", "bootstrap", ")", ")", "{", "$", "config", "[", "'bootstrap'", "]", "=", "true", ";", "}", "if", "(", "FS", "::", "isFile", "(", "$", "routes", ")", ")", "{", "$", "config", "[", "'routes'", "]", "=", "true", ";", "}", "$", "config", "[", "'path'", "]", "=", "$", "path", ";", "return", "$", "config", ";", "}" ]
Get plugin configuration for load plugin. @param string $path @return array
[ "Get", "plugin", "configuration", "for", "load", "plugin", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L281-L298
CakeCMS/Core
src/Plugin.php
Plugin._getPluginData
protected static function _getPluginData(array $data, $key = null) { if (isset($data[$key])) { $data = $data[$key]; } return new Data($data); }
php
protected static function _getPluginData(array $data, $key = null) { if (isset($data[$key])) { $data = $data[$key]; } return new Data($data); }
[ "protected", "static", "function", "_getPluginData", "(", "array", "$", "data", ",", "$", "key", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "key", "]", ")", ")", "{", "$", "data", "=", "$", "data", "[", "$", "key", "]", ";", "}", "return", "new", "Data", "(", "$", "data", ")", ";", "}" ]
Get current plugin data. @param array $data @param null|string $key @return Data
[ "Get", "current", "plugin", "data", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L307-L314
CakeCMS/Core
src/Plugin.php
Plugin._isCallablePluginData
protected static function _isCallablePluginData($name, $plugin, $callback) { if (Arr::in($name, self::$_manifestEvents) && !isset(self::$_eventList[$name][$plugin]) && is_callable($callback) ) { return true; } return false; }
php
protected static function _isCallablePluginData($name, $plugin, $callback) { if (Arr::in($name, self::$_manifestEvents) && !isset(self::$_eventList[$name][$plugin]) && is_callable($callback) ) { return true; } return false; }
[ "protected", "static", "function", "_isCallablePluginData", "(", "$", "name", ",", "$", "plugin", ",", "$", "callback", ")", "{", "if", "(", "Arr", "::", "in", "(", "$", "name", ",", "self", "::", "$", "_manifestEvents", ")", "&&", "!", "isset", "(", "self", "::", "$", "_eventList", "[", "$", "name", "]", "[", "$", "plugin", "]", ")", "&&", "is_callable", "(", "$", "callback", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check manifest param on callable. @param string $name @param string $plugin @param mixed $callback @return bool
[ "Check", "manifest", "param", "on", "callable", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Plugin.php#L324-L334
yuncms/framework
src/helpers/PasswordHelper.php
PasswordHelper.hash
public static function hash($password, $cost = 10): string { return Yii::$app->security->generatePasswordHash($password, $cost); }
php
public static function hash($password, $cost = 10): string { return Yii::$app->security->generatePasswordHash($password, $cost); }
[ "public", "static", "function", "hash", "(", "$", "password", ",", "$", "cost", "=", "10", ")", ":", "string", "{", "return", "Yii", "::", "$", "app", "->", "security", "->", "generatePasswordHash", "(", "$", "password", ",", "$", "cost", ")", ";", "}" ]
Wrapper for yii security helper method. @param string $password @param int $cost @return string @throws \yii\base\Exception
[ "Wrapper", "for", "yii", "security", "helper", "method", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/PasswordHelper.php#L28-L31
yuncms/framework
src/helpers/PasswordHelper.php
PasswordHelper.validate
public static function validate($password, $hash): bool { return Yii::$app->security->validatePassword($password, $hash); }
php
public static function validate($password, $hash): bool { return Yii::$app->security->validatePassword($password, $hash); }
[ "public", "static", "function", "validate", "(", "$", "password", ",", "$", "hash", ")", ":", "bool", "{", "return", "Yii", "::", "$", "app", "->", "security", "->", "validatePassword", "(", "$", "password", ",", "$", "hash", ")", ";", "}" ]
Wrapper for yii security helper method. @param $password @param $hash @return boolean
[ "Wrapper", "for", "yii", "security", "helper", "method", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/PasswordHelper.php#L41-L44
yuncms/framework
src/helpers/PasswordHelper.php
PasswordHelper.generate
public static function generate($length): string { $sets = ['abcdefghjkmnpqrstuvwxyz', 'ABCDEFGHJKMNPQRSTUVWXYZ', '23456789']; $all = ''; $password = ''; foreach ($sets as $set) { $password .= $set[array_rand(str_split($set))]; $all .= $set; } $all = str_split($all); for ($i = 0; $i < $length - count($sets); $i++) { $password .= $all[array_rand($all)]; } $password = str_shuffle($password); return $password; }
php
public static function generate($length): string { $sets = ['abcdefghjkmnpqrstuvwxyz', 'ABCDEFGHJKMNPQRSTUVWXYZ', '23456789']; $all = ''; $password = ''; foreach ($sets as $set) { $password .= $set[array_rand(str_split($set))]; $all .= $set; } $all = str_split($all); for ($i = 0; $i < $length - count($sets); $i++) { $password .= $all[array_rand($all)]; } $password = str_shuffle($password); return $password; }
[ "public", "static", "function", "generate", "(", "$", "length", ")", ":", "string", "{", "$", "sets", "=", "[", "'abcdefghjkmnpqrstuvwxyz'", ",", "'ABCDEFGHJKMNPQRSTUVWXYZ'", ",", "'23456789'", "]", ";", "$", "all", "=", "''", ";", "$", "password", "=", "''", ";", "foreach", "(", "$", "sets", "as", "$", "set", ")", "{", "$", "password", ".=", "$", "set", "[", "array_rand", "(", "str_split", "(", "$", "set", ")", ")", "]", ";", "$", "all", ".=", "$", "set", ";", "}", "$", "all", "=", "str_split", "(", "$", "all", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", "-", "count", "(", "$", "sets", ")", ";", "$", "i", "++", ")", "{", "$", "password", ".=", "$", "all", "[", "array_rand", "(", "$", "all", ")", "]", ";", "}", "$", "password", "=", "str_shuffle", "(", "$", "password", ")", ";", "return", "$", "password", ";", "}" ]
Generates user-friendly random password containing at least one lower case letter, one uppercase letter and one digit. The remaining characters in the password are chosen at random from those three sets. @see https://gist.github.com/tylerhall/521810 @param $length @return string
[ "Generates", "user", "-", "friendly", "random", "password", "containing", "at", "least", "one", "lower", "case", "letter", "one", "uppercase", "letter", "and", "one", "digit", ".", "The", "remaining", "characters", "in", "the", "password", "are", "chosen", "at", "random", "from", "those", "three", "sets", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/PasswordHelper.php#L56-L74
titon/db
src/Titon/Db/Entity.php
Entity.toArray
public function toArray() { return array_map(function($value) { return ($value instanceof Arrayable) ? $value->toArray() : $value; }, $this->_data); }
php
public function toArray() { return array_map(function($value) { return ($value instanceof Arrayable) ? $value->toArray() : $value; }, $this->_data); }
[ "public", "function", "toArray", "(", ")", "{", "return", "array_map", "(", "function", "(", "$", "value", ")", "{", "return", "(", "$", "value", "instanceof", "Arrayable", ")", "?", "$", "value", "->", "toArray", "(", ")", ":", "$", "value", ";", "}", ",", "$", "this", "->", "_data", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Entity.php#L116-L120
devemio/php-readable-timer
src/TimerPool.php
TimerPool.stop
public function stop($marker) { if (array_key_exists($marker, $this->timers)) { $this->timers[$marker]->stop(); } }
php
public function stop($marker) { if (array_key_exists($marker, $this->timers)) { $this->timers[$marker]->stop(); } }
[ "public", "function", "stop", "(", "$", "marker", ")", "{", "if", "(", "array_key_exists", "(", "$", "marker", ",", "$", "this", "->", "timers", ")", ")", "{", "$", "this", "->", "timers", "[", "$", "marker", "]", "->", "stop", "(", ")", ";", "}", "}" ]
Stop timer with a specific marker. @param string $marker
[ "Stop", "timer", "with", "a", "specific", "marker", "." ]
train
https://github.com/devemio/php-readable-timer/blob/50916b630eda07999dc6676528afe59fb2105615/src/TimerPool.php#L48-L53
devemio/php-readable-timer
src/TimerPool.php
TimerPool.build
public function build() { foreach ($this->timers as $marker => $timer) { $this->markers[$marker] = $timer->time(); } arsort($this->markers); return $this->markers; }
php
public function build() { foreach ($this->timers as $marker => $timer) { $this->markers[$marker] = $timer->time(); } arsort($this->markers); return $this->markers; }
[ "public", "function", "build", "(", ")", "{", "foreach", "(", "$", "this", "->", "timers", "as", "$", "marker", "=>", "$", "timer", ")", "{", "$", "this", "->", "markers", "[", "$", "marker", "]", "=", "$", "timer", "->", "time", "(", ")", ";", "}", "arsort", "(", "$", "this", "->", "markers", ")", ";", "return", "$", "this", "->", "markers", ";", "}" ]
Return sorted times. @return string[]
[ "Return", "sorted", "times", "." ]
train
https://github.com/devemio/php-readable-timer/blob/50916b630eda07999dc6676528afe59fb2105615/src/TimerPool.php#L60-L67
webforge-labs/psc-cms
lib/Psc/System/Console/DeployCommand.php
DeployCommand.configure
protected function configure() { $this->setName('project:deploy'); $this->addArgument('mode',self::OPTIONAL | self::IS_ARRAY, 'staging oder normal', array('normal')); $this->addOption('deploymentsDir',self::VALUE_REQUIRED); //$this->addArgument('class',self::REQUIRED); $this->addOption('without-test','',self::VALUE_NONE); $this->addOption('qnd','',self::VALUE_NONE); $this->setDescription('Exportiert das Projekt mit allen Binaries und Sourcen in den Deployments Ordner'); $this->addOption('changes',null, self::VALUE_REQUIRED | self::VALUE_IS_ARRAY); }
php
protected function configure() { $this->setName('project:deploy'); $this->addArgument('mode',self::OPTIONAL | self::IS_ARRAY, 'staging oder normal', array('normal')); $this->addOption('deploymentsDir',self::VALUE_REQUIRED); //$this->addArgument('class',self::REQUIRED); $this->addOption('without-test','',self::VALUE_NONE); $this->addOption('qnd','',self::VALUE_NONE); $this->setDescription('Exportiert das Projekt mit allen Binaries und Sourcen in den Deployments Ordner'); $this->addOption('changes',null, self::VALUE_REQUIRED | self::VALUE_IS_ARRAY); }
[ "protected", "function", "configure", "(", ")", "{", "$", "this", "->", "setName", "(", "'project:deploy'", ")", ";", "$", "this", "->", "addArgument", "(", "'mode'", ",", "self", "::", "OPTIONAL", "|", "self", "::", "IS_ARRAY", ",", "'staging oder normal'", ",", "array", "(", "'normal'", ")", ")", ";", "$", "this", "->", "addOption", "(", "'deploymentsDir'", ",", "self", "::", "VALUE_REQUIRED", ")", ";", "//$this->addArgument('class',self::REQUIRED);", "$", "this", "->", "addOption", "(", "'without-test'", ",", "''", ",", "self", "::", "VALUE_NONE", ")", ";", "$", "this", "->", "addOption", "(", "'qnd'", ",", "''", ",", "self", "::", "VALUE_NONE", ")", ";", "$", "this", "->", "setDescription", "(", "'Exportiert das Projekt mit allen Binaries und Sourcen in den Deployments Ordner'", ")", ";", "$", "this", "->", "addOption", "(", "'changes'", ",", "null", ",", "self", "::", "VALUE_REQUIRED", "|", "self", "::", "VALUE_IS_ARRAY", ")", ";", "}" ]
/* /properties
[ "/", "*", "/", "properties" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/System/Console/DeployCommand.php#L60-L69
aedart/laravel-helpers
src/Traits/Config/ConfigTrait.php
ConfigTrait.getConfig
public function getConfig(): ?Repository { if (!$this->hasConfig()) { $this->setConfig($this->getDefaultConfig()); } return $this->config; }
php
public function getConfig(): ?Repository { if (!$this->hasConfig()) { $this->setConfig($this->getDefaultConfig()); } return $this->config; }
[ "public", "function", "getConfig", "(", ")", ":", "?", "Repository", "{", "if", "(", "!", "$", "this", "->", "hasConfig", "(", ")", ")", "{", "$", "this", "->", "setConfig", "(", "$", "this", "->", "getDefaultConfig", "(", ")", ")", ";", "}", "return", "$", "this", "->", "config", ";", "}" ]
Get config If no config has been set, this method will set and return a default config, if any such value is available @see getDefaultConfig() @return Repository|null config or null if none config has been set
[ "Get", "config" ]
train
https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Config/ConfigTrait.php#L53-L59
lmammino/e-foundation
src/Price/Model/PricedItemTrait.php
PricedItemTrait.calculateTotal
public function calculateTotal() { $this->calculateAdjustmentsTotal(); $this->total = ($this->quantity * $this->unitPrice) + $this->adjustmentsTotal; if ($this->total < 0) { $this->total = 0; } return $this; }
php
public function calculateTotal() { $this->calculateAdjustmentsTotal(); $this->total = ($this->quantity * $this->unitPrice) + $this->adjustmentsTotal; if ($this->total < 0) { $this->total = 0; } return $this; }
[ "public", "function", "calculateTotal", "(", ")", "{", "$", "this", "->", "calculateAdjustmentsTotal", "(", ")", ";", "$", "this", "->", "total", "=", "(", "$", "this", "->", "quantity", "*", "$", "this", "->", "unitPrice", ")", "+", "$", "this", "->", "adjustmentsTotal", ";", "if", "(", "$", "this", "->", "total", "<", "0", ")", "{", "$", "this", "->", "total", "=", "0", ";", "}", "return", "$", "this", ";", "}" ]
Calculates the total for the item @return $this
[ "Calculates", "the", "total", "for", "the", "item" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemTrait.php#L153-L164
lmammino/e-foundation
src/Price/Model/PricedItemTrait.php
PricedItemTrait.merge
public function merge(PricedItemInterface $item) { if ($this !== $item) { $this->quantity += $item->getQuantity(); } return $this; }
php
public function merge(PricedItemInterface $item) { if ($this !== $item) { $this->quantity += $item->getQuantity(); } return $this; }
[ "public", "function", "merge", "(", "PricedItemInterface", "$", "item", ")", "{", "if", "(", "$", "this", "!==", "$", "item", ")", "{", "$", "this", "->", "quantity", "+=", "$", "item", "->", "getQuantity", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemTrait.php#L177-L184
lmammino/e-foundation
src/Price/Model/PricedItemsContainerTrait.php
PricedItemsContainerTrait.setItems
public function setItems(Collection $items) { $this->itemsTotal = null; $this->total = null; foreach ($items as $item) { $this->addItem($item); } return $this; }
php
public function setItems(Collection $items) { $this->itemsTotal = null; $this->total = null; foreach ($items as $item) { $this->addItem($item); } return $this; }
[ "public", "function", "setItems", "(", "Collection", "$", "items", ")", "{", "$", "this", "->", "itemsTotal", "=", "null", ";", "$", "this", "->", "total", "=", "null", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "this", "->", "addItem", "(", "$", "item", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set items @param Collection $items @return $this
[ "Set", "items" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemsContainerTrait.php#L92-L102
lmammino/e-foundation
src/Price/Model/PricedItemsContainerTrait.php
PricedItemsContainerTrait.addItem
public function addItem(PricedItemInterface $item) { if ($this->hasItem($item)) { return $this; } foreach ($this->items as $existingItem) { if ($item->equals($existingItem)) { $existingItem->merge($item, false); $this->itemsTotal = null; $this->total = null; return $this; } } $item->setContainer($this); $this->items->add($item); $this->itemsTotal = null; $this->total = null; return $this; }
php
public function addItem(PricedItemInterface $item) { if ($this->hasItem($item)) { return $this; } foreach ($this->items as $existingItem) { if ($item->equals($existingItem)) { $existingItem->merge($item, false); $this->itemsTotal = null; $this->total = null; return $this; } } $item->setContainer($this); $this->items->add($item); $this->itemsTotal = null; $this->total = null; return $this; }
[ "public", "function", "addItem", "(", "PricedItemInterface", "$", "item", ")", "{", "if", "(", "$", "this", "->", "hasItem", "(", "$", "item", ")", ")", "{", "return", "$", "this", ";", "}", "foreach", "(", "$", "this", "->", "items", "as", "$", "existingItem", ")", "{", "if", "(", "$", "item", "->", "equals", "(", "$", "existingItem", ")", ")", "{", "$", "existingItem", "->", "merge", "(", "$", "item", ",", "false", ")", ";", "$", "this", "->", "itemsTotal", "=", "null", ";", "$", "this", "->", "total", "=", "null", ";", "return", "$", "this", ";", "}", "}", "$", "item", "->", "setContainer", "(", "$", "this", ")", ";", "$", "this", "->", "items", "->", "add", "(", "$", "item", ")", ";", "$", "this", "->", "itemsTotal", "=", "null", ";", "$", "this", "->", "total", "=", "null", ";", "return", "$", "this", ";", "}" ]
Add an item @param PricedItemInterface $item @return $this
[ "Add", "an", "item" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemsContainerTrait.php#L121-L145
lmammino/e-foundation
src/Price/Model/PricedItemsContainerTrait.php
PricedItemsContainerTrait.removeItem
public function removeItem(PricedItemInterface $item) { if ($this->hasItem($item)) { $item->setContainer(null); $this->items->removeElement($item); $this->itemsTotal = null; $this->total = null; } return $this; }
php
public function removeItem(PricedItemInterface $item) { if ($this->hasItem($item)) { $item->setContainer(null); $this->items->removeElement($item); $this->itemsTotal = null; $this->total = null; } return $this; }
[ "public", "function", "removeItem", "(", "PricedItemInterface", "$", "item", ")", "{", "if", "(", "$", "this", "->", "hasItem", "(", "$", "item", ")", ")", "{", "$", "item", "->", "setContainer", "(", "null", ")", ";", "$", "this", "->", "items", "->", "removeElement", "(", "$", "item", ")", ";", "$", "this", "->", "itemsTotal", "=", "null", ";", "$", "this", "->", "total", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Remove a given item @param PricedItemInterface $item @return $this
[ "Remove", "a", "given", "item" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemsContainerTrait.php#L154-L165
lmammino/e-foundation
src/Price/Model/PricedItemsContainerTrait.php
PricedItemsContainerTrait.calculateItemsTotal
public function calculateItemsTotal() { $itemsTotal = 0; foreach ($this->items as $item) { $itemsTotal += $item->getTotal(); } $this->itemsTotal = $itemsTotal; return $this; }
php
public function calculateItemsTotal() { $itemsTotal = 0; foreach ($this->items as $item) { $itemsTotal += $item->getTotal(); } $this->itemsTotal = $itemsTotal; return $this; }
[ "public", "function", "calculateItemsTotal", "(", ")", "{", "$", "itemsTotal", "=", "0", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "itemsTotal", "+=", "$", "item", "->", "getTotal", "(", ")", ";", "}", "$", "this", "->", "itemsTotal", "=", "$", "itemsTotal", ";", "return", "$", "this", ";", "}" ]
Calculate the total price for all the items @return $this
[ "Calculate", "the", "total", "price", "for", "all", "the", "items" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemsContainerTrait.php#L196-L207
lmammino/e-foundation
src/Price/Model/PricedItemsContainerTrait.php
PricedItemsContainerTrait.calculateTotal
public function calculateTotal() { $this->total = $this->getItemsTotal() + $this->getAdjustmentTotal(); if ($this->total < 0) { $this->total = 0; } return $this; }
php
public function calculateTotal() { $this->total = $this->getItemsTotal() + $this->getAdjustmentTotal(); if ($this->total < 0) { $this->total = 0; } return $this; }
[ "public", "function", "calculateTotal", "(", ")", "{", "$", "this", "->", "total", "=", "$", "this", "->", "getItemsTotal", "(", ")", "+", "$", "this", "->", "getAdjustmentTotal", "(", ")", ";", "if", "(", "$", "this", "->", "total", "<", "0", ")", "{", "$", "this", "->", "total", "=", "0", ";", "}", "return", "$", "this", ";", "}" ]
Calculate the total amount for the whole container @return $this
[ "Calculate", "the", "total", "amount", "for", "the", "whole", "container" ]
train
https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Price/Model/PricedItemsContainerTrait.php#L241-L250
vi-kon/laravel-auth
src/ViKon/Auth/Middleware/LoginRedirectorMiddleware.php
LoginRedirectorMiddleware.handle
public function handle(Request $request, Closure $next, $route) { $router = $this->container->make('router'); $currentRoute = $router->current(); $action = $currentRoute->getAction(); if (isset($action['role'])) { $action['roles'] = $action['role']; } if (isset($action['permission'])) { $action['permissions'] = $action['permission']; } // Redirect guest to login screen if route has least one role or permission if ((isset($action['roles']) || isset($action['permissions'])) && !$this->keeper->check()) { $url = $this->container->make('url'); $log = $this->container->make('log'); $redirect = $this->container->make('redirect'); $log->notice('Guest redirected to login screen', [ 'from' => $currentRoute->getName(), 'to' => $route, ]); return $redirect->guest($url->route($route)); } return $next($request); }
php
public function handle(Request $request, Closure $next, $route) { $router = $this->container->make('router'); $currentRoute = $router->current(); $action = $currentRoute->getAction(); if (isset($action['role'])) { $action['roles'] = $action['role']; } if (isset($action['permission'])) { $action['permissions'] = $action['permission']; } // Redirect guest to login screen if route has least one role or permission if ((isset($action['roles']) || isset($action['permissions'])) && !$this->keeper->check()) { $url = $this->container->make('url'); $log = $this->container->make('log'); $redirect = $this->container->make('redirect'); $log->notice('Guest redirected to login screen', [ 'from' => $currentRoute->getName(), 'to' => $route, ]); return $redirect->guest($url->route($route)); } return $next($request); }
[ "public", "function", "handle", "(", "Request", "$", "request", ",", "Closure", "$", "next", ",", "$", "route", ")", "{", "$", "router", "=", "$", "this", "->", "container", "->", "make", "(", "'router'", ")", ";", "$", "currentRoute", "=", "$", "router", "->", "current", "(", ")", ";", "$", "action", "=", "$", "currentRoute", "->", "getAction", "(", ")", ";", "if", "(", "isset", "(", "$", "action", "[", "'role'", "]", ")", ")", "{", "$", "action", "[", "'roles'", "]", "=", "$", "action", "[", "'role'", "]", ";", "}", "if", "(", "isset", "(", "$", "action", "[", "'permission'", "]", ")", ")", "{", "$", "action", "[", "'permissions'", "]", "=", "$", "action", "[", "'permission'", "]", ";", "}", "// Redirect guest to login screen if route has least one role or permission", "if", "(", "(", "isset", "(", "$", "action", "[", "'roles'", "]", ")", "||", "isset", "(", "$", "action", "[", "'permissions'", "]", ")", ")", "&&", "!", "$", "this", "->", "keeper", "->", "check", "(", ")", ")", "{", "$", "url", "=", "$", "this", "->", "container", "->", "make", "(", "'url'", ")", ";", "$", "log", "=", "$", "this", "->", "container", "->", "make", "(", "'log'", ")", ";", "$", "redirect", "=", "$", "this", "->", "container", "->", "make", "(", "'redirect'", ")", ";", "$", "log", "->", "notice", "(", "'Guest redirected to login screen'", ",", "[", "'from'", "=>", "$", "currentRoute", "->", "getName", "(", ")", ",", "'to'", "=>", "$", "route", ",", "]", ")", ";", "return", "$", "redirect", "->", "guest", "(", "$", "url", "->", "route", "(", "$", "route", ")", ")", ";", "}", "return", "$", "next", "(", "$", "request", ")", ";", "}" ]
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @param string $route route name @return \Illuminate\Http\RedirectResponse|mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Middleware/LoginRedirectorMiddleware.php#L44-L74
forxer/tao
src/Tao/Controller/Controller.php
Controller.redirectToRoute
protected function redirectToRoute($route, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH, $status = 302) { return $this->redirect($this->generateUrl($route, $parameters, $referenceType), $status); }
php
protected function redirectToRoute($route, array $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH, $status = 302) { return $this->redirect($this->generateUrl($route, $parameters, $referenceType), $status); }
[ "protected", "function", "redirectToRoute", "(", "$", "route", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ",", "$", "status", "=", "302", ")", "{", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "$", "route", ",", "$", "parameters", ",", "$", "referenceType", ")", ",", "$", "status", ")", ";", "}" ]
Returns a RedirectResponse to the given route with the given parameters. @param string $route The name of the route @param array $parameters An array of parameters @param int $status The status code to use for the Response @return RedirectResponse
[ "Returns", "a", "RedirectResponse", "to", "the", "given", "route", "with", "the", "given", "parameters", "." ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/Controller.php#L64-L67
forxer/tao
src/Tao/Controller/Controller.php
Controller.stream
public function stream($view, array $parameters = [], StreamedResponse $response = null) { $templating = $this->app['templating']; $callback = function () use($templating, $view, $parameters) { $templating->stream($view, $parameters); }; if (null === $response) { return new StreamedResponse($callback); } $response->setCallback($callback); return $response; }
php
public function stream($view, array $parameters = [], StreamedResponse $response = null) { $templating = $this->app['templating']; $callback = function () use($templating, $view, $parameters) { $templating->stream($view, $parameters); }; if (null === $response) { return new StreamedResponse($callback); } $response->setCallback($callback); return $response; }
[ "public", "function", "stream", "(", "$", "view", ",", "array", "$", "parameters", "=", "[", "]", ",", "StreamedResponse", "$", "response", "=", "null", ")", "{", "$", "templating", "=", "$", "this", "->", "app", "[", "'templating'", "]", ";", "$", "callback", "=", "function", "(", ")", "use", "(", "$", "templating", ",", "$", "view", ",", "$", "parameters", ")", "{", "$", "templating", "->", "stream", "(", "$", "view", ",", "$", "parameters", ")", ";", "}", ";", "if", "(", "null", "===", "$", "response", ")", "{", "return", "new", "StreamedResponse", "(", "$", "callback", ")", ";", "}", "$", "response", "->", "setCallback", "(", "$", "callback", ")", ";", "return", "$", "response", ";", "}" ]
Streams a view. @param string $view The view name @param array $parameters An array of parameters to pass to the view @param StreamedResponse $response A response instance @return StreamedResponse A StreamedResponse instance
[ "Streams", "a", "view", "." ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/Controller.php#L127-L142
forxer/tao
src/Tao/Controller/Controller.php
Controller.serve401
public function serve401() { $response = new Response(); $response->setStatusCode(Response::HTTP_UNAUTHORIZED); return $this->render('Errors/401', [], $response); }
php
public function serve401() { $response = new Response(); $response->setStatusCode(Response::HTTP_UNAUTHORIZED); return $this->render('Errors/401', [], $response); }
[ "public", "function", "serve401", "(", ")", "{", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "response", "->", "setStatusCode", "(", "Response", "::", "HTTP_UNAUTHORIZED", ")", ";", "return", "$", "this", "->", "render", "(", "'Errors/401'", ",", "[", "]", ",", "$", "response", ")", ";", "}" ]
Affichage page 401
[ "Affichage", "page", "401" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/Controller.php#L147-L153
forxer/tao
src/Tao/Controller/Controller.php
Controller.serve404
public function serve404() { $response = new Response(); $response->setStatusCode(Response::HTTP_NOT_FOUND); return $this->render('Errors/404', [], $response); }
php
public function serve404() { $response = new Response(); $response->setStatusCode(Response::HTTP_NOT_FOUND); return $this->render('Errors/404', [], $response); }
[ "public", "function", "serve404", "(", ")", "{", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "response", "->", "setStatusCode", "(", "Response", "::", "HTTP_NOT_FOUND", ")", ";", "return", "$", "this", "->", "render", "(", "'Errors/404'", ",", "[", "]", ",", "$", "response", ")", ";", "}" ]
Affichage page 404
[ "Affichage", "page", "404" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/Controller.php#L158-L164
forxer/tao
src/Tao/Controller/Controller.php
Controller.serve503
public function serve503() { $response = new Response(); $response->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE); $response->headers->set('Retry-After', 3600); return $this->render('Errors/503', [], $response); }
php
public function serve503() { $response = new Response(); $response->setStatusCode(Response::HTTP_SERVICE_UNAVAILABLE); $response->headers->set('Retry-After', 3600); return $this->render('Errors/503', [], $response); }
[ "public", "function", "serve503", "(", ")", "{", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "response", "->", "setStatusCode", "(", "Response", "::", "HTTP_SERVICE_UNAVAILABLE", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Retry-After'", ",", "3600", ")", ";", "return", "$", "this", "->", "render", "(", "'Errors/503'", ",", "[", "]", ",", "$", "response", ")", ";", "}" ]
Affichage page 503
[ "Affichage", "page", "503" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/Controller.php#L169-L176
forxer/tao
src/Tao/Controller/Controller.php
Controller.removeTrailingSlash
public function removeTrailingSlash() { $pathInfo = $this->app['request']->getPathInfo(); $requestUri = $this->app['request']->getRequestUri(); $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri); return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY); }
php
public function removeTrailingSlash() { $pathInfo = $this->app['request']->getPathInfo(); $requestUri = $this->app['request']->getRequestUri(); $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri); return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY); }
[ "public", "function", "removeTrailingSlash", "(", ")", "{", "$", "pathInfo", "=", "$", "this", "->", "app", "[", "'request'", "]", "->", "getPathInfo", "(", ")", ";", "$", "requestUri", "=", "$", "this", "->", "app", "[", "'request'", "]", "->", "getRequestUri", "(", ")", ";", "$", "url", "=", "str_replace", "(", "$", "pathInfo", ",", "rtrim", "(", "$", "pathInfo", ",", "' /'", ")", ",", "$", "requestUri", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "url", ",", "Response", "::", "HTTP_MOVED_PERMANENTLY", ")", ";", "}" ]
Remove trailing slash and redirect permanent @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Remove", "trailing", "slash", "and", "redirect", "permanent" ]
train
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Controller/Controller.php#L183-L191
dreamfactorysoftware/df-file
src/Models/WebDAVFileConfig.php
WebDAVFileConfig.prepareConfigSchemaField
protected static function prepareConfigSchemaField(array &$schema) { parent::prepareConfigSchemaField($schema); switch ($schema['name']) { case 'base_uri': $schema['description'] = 'WebDAV base uri. This should only be the host. No resource or prefixes. ' . 'For example: http://example.com Not http://example.com/somefolder .'; break; case 'username': $schema['description'] = 'WebDAV server username.'; break; case 'password': $schema['description'] = 'WebDAV server user password.'; break; case 'auth_type': $schema['type'] = 'picklist'; $schema['values'] = [ ['label' => 'None', 'name' => null], ['label' => 'Basic', 'name' => Client::AUTH_BASIC], ['label' => 'Digest', 'name' => Client::AUTH_DIGEST], ['label' => 'NTLM', 'name' => Client::AUTH_NTLM] ]; $schema['description'] = 'Auth Type. Valid options are basic, digest, ntlm.'; break; case 'encoding': $schema['type'] = 'picklist'; $schema['values'] = [ ['label' => 'None', 'name' => null], ['label' => 'Identity', 'name' => Client::ENCODING_IDENTITY], ['label' => 'Deflate', 'name' => Client::ENCODING_DEFLATE], ['label' => 'Gzip', 'name' => Client::ENCODING_GZIP] ]; $schema['description'] = 'Encoding. Valid options are identity, deflate, gzip.'; break; case 'proxy': $schema['description'] = 'Optional proxy server if any.'; break; } }
php
protected static function prepareConfigSchemaField(array &$schema) { parent::prepareConfigSchemaField($schema); switch ($schema['name']) { case 'base_uri': $schema['description'] = 'WebDAV base uri. This should only be the host. No resource or prefixes. ' . 'For example: http://example.com Not http://example.com/somefolder .'; break; case 'username': $schema['description'] = 'WebDAV server username.'; break; case 'password': $schema['description'] = 'WebDAV server user password.'; break; case 'auth_type': $schema['type'] = 'picklist'; $schema['values'] = [ ['label' => 'None', 'name' => null], ['label' => 'Basic', 'name' => Client::AUTH_BASIC], ['label' => 'Digest', 'name' => Client::AUTH_DIGEST], ['label' => 'NTLM', 'name' => Client::AUTH_NTLM] ]; $schema['description'] = 'Auth Type. Valid options are basic, digest, ntlm.'; break; case 'encoding': $schema['type'] = 'picklist'; $schema['values'] = [ ['label' => 'None', 'name' => null], ['label' => 'Identity', 'name' => Client::ENCODING_IDENTITY], ['label' => 'Deflate', 'name' => Client::ENCODING_DEFLATE], ['label' => 'Gzip', 'name' => Client::ENCODING_GZIP] ]; $schema['description'] = 'Encoding. Valid options are identity, deflate, gzip.'; break; case 'proxy': $schema['description'] = 'Optional proxy server if any.'; break; } }
[ "protected", "static", "function", "prepareConfigSchemaField", "(", "array", "&", "$", "schema", ")", "{", "parent", "::", "prepareConfigSchemaField", "(", "$", "schema", ")", ";", "switch", "(", "$", "schema", "[", "'name'", "]", ")", "{", "case", "'base_uri'", ":", "$", "schema", "[", "'description'", "]", "=", "'WebDAV base uri. This should only be the host. No resource or prefixes. '", ".", "'For example: http://example.com Not http://example.com/somefolder .'", ";", "break", ";", "case", "'username'", ":", "$", "schema", "[", "'description'", "]", "=", "'WebDAV server username.'", ";", "break", ";", "case", "'password'", ":", "$", "schema", "[", "'description'", "]", "=", "'WebDAV server user password.'", ";", "break", ";", "case", "'auth_type'", ":", "$", "schema", "[", "'type'", "]", "=", "'picklist'", ";", "$", "schema", "[", "'values'", "]", "=", "[", "[", "'label'", "=>", "'None'", ",", "'name'", "=>", "null", "]", ",", "[", "'label'", "=>", "'Basic'", ",", "'name'", "=>", "Client", "::", "AUTH_BASIC", "]", ",", "[", "'label'", "=>", "'Digest'", ",", "'name'", "=>", "Client", "::", "AUTH_DIGEST", "]", ",", "[", "'label'", "=>", "'NTLM'", ",", "'name'", "=>", "Client", "::", "AUTH_NTLM", "]", "]", ";", "$", "schema", "[", "'description'", "]", "=", "'Auth Type. Valid options are basic, digest, ntlm.'", ";", "break", ";", "case", "'encoding'", ":", "$", "schema", "[", "'type'", "]", "=", "'picklist'", ";", "$", "schema", "[", "'values'", "]", "=", "[", "[", "'label'", "=>", "'None'", ",", "'name'", "=>", "null", "]", ",", "[", "'label'", "=>", "'Identity'", ",", "'name'", "=>", "Client", "::", "ENCODING_IDENTITY", "]", ",", "[", "'label'", "=>", "'Deflate'", ",", "'name'", "=>", "Client", "::", "ENCODING_DEFLATE", "]", ",", "[", "'label'", "=>", "'Gzip'", ",", "'name'", "=>", "Client", "::", "ENCODING_GZIP", "]", "]", ";", "$", "schema", "[", "'description'", "]", "=", "'Encoding. Valid options are identity, deflate, gzip.'", ";", "break", ";", "case", "'proxy'", ":", "$", "schema", "[", "'description'", "]", "=", "'Optional proxy server if any.'", ";", "break", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/dreamfactorysoftware/df-file/blob/e78aaec3e1d6585b5e7fe9b7646af4b1180ecd66/src/Models/WebDAVFileConfig.php#L56-L95
ClanCats/Core
src/classes/CCView/Builder/CCFTemplate.php
CCView_Builder_CCFTemplate.repair_expression
public function repair_expression( $exp ) { $commands = explode( ' ', $exp ); // filter empty ones $commands = array_filter( $commands, function( $value ) { return !is_null( $value ); }); // bracket starting command if ( in_array( $commands[0], $this->bracket_starting_commands ) ) { // each = foreach if ( $commands[0] == 'each' ) { $commands[0] = 'foreach'; } // loop special elseif ( $commands[0] == 'loop' ) { $commands[0] = 'for'; $commands[1] = '$i=0;$i<'.$commands[1].';$i++'; } // remove the opening duble point end($commands); $key = key($commands); if ( substr( $commands[$key], -1 ) == ':' ) { $commands[$key] = substr( $commands[$key], 0, -1 ); // is it now empty? if ( $commands[$key] == ' ' || empty( $commands[$key] ) ) { unset( $commands[$key] ); } } // do we have brackets? if ( substr( $commands[1], 0, 1 ) != '(' ) { // add starting bracket $commands[1] = '( '.$commands[1]; // add ending bracket end($commands); $key = key($commands); $commands[$key] .= ' )'; } $commands[] = ':'; } // bracket ending command elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_ending_commands ) ) { // each = foreach if ( $commands[0] == 'endeach' ) { $commands[0] = 'endforeach'; } // loop special elseif ( $commands[0] == 'endloop' ) { $commands[0] = 'endfor'; } // check for semicolon if ( substr( $commands[0], 0, 1 ) != ';' ) { $commands[0] .= ';'; } } // bracket continue command elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_continue_commands ) ) { // remove the opening duble point end($commands); $key = key($commands); if ( substr( $commands[$key], -1 ) == ':' ) { $commands[$key] = substr( $commands[$key], 0, -1 ); // is it now empty? if ( $commands[$key] == ' ' || empty( $commands[$key] ) ) { unset( $commands[$key] ); } } // add the double point $commands[] = ':'; } return implode( ' ', $commands ); }
php
public function repair_expression( $exp ) { $commands = explode( ' ', $exp ); // filter empty ones $commands = array_filter( $commands, function( $value ) { return !is_null( $value ); }); // bracket starting command if ( in_array( $commands[0], $this->bracket_starting_commands ) ) { // each = foreach if ( $commands[0] == 'each' ) { $commands[0] = 'foreach'; } // loop special elseif ( $commands[0] == 'loop' ) { $commands[0] = 'for'; $commands[1] = '$i=0;$i<'.$commands[1].';$i++'; } // remove the opening duble point end($commands); $key = key($commands); if ( substr( $commands[$key], -1 ) == ':' ) { $commands[$key] = substr( $commands[$key], 0, -1 ); // is it now empty? if ( $commands[$key] == ' ' || empty( $commands[$key] ) ) { unset( $commands[$key] ); } } // do we have brackets? if ( substr( $commands[1], 0, 1 ) != '(' ) { // add starting bracket $commands[1] = '( '.$commands[1]; // add ending bracket end($commands); $key = key($commands); $commands[$key] .= ' )'; } $commands[] = ':'; } // bracket ending command elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_ending_commands ) ) { // each = foreach if ( $commands[0] == 'endeach' ) { $commands[0] = 'endforeach'; } // loop special elseif ( $commands[0] == 'endloop' ) { $commands[0] = 'endfor'; } // check for semicolon if ( substr( $commands[0], 0, 1 ) != ';' ) { $commands[0] .= ';'; } } // bracket continue command elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_continue_commands ) ) { // remove the opening duble point end($commands); $key = key($commands); if ( substr( $commands[$key], -1 ) == ':' ) { $commands[$key] = substr( $commands[$key], 0, -1 ); // is it now empty? if ( $commands[$key] == ' ' || empty( $commands[$key] ) ) { unset( $commands[$key] ); } } // add the double point $commands[] = ':'; } return implode( ' ', $commands ); }
[ "public", "function", "repair_expression", "(", "$", "exp", ")", "{", "$", "commands", "=", "explode", "(", "' '", ",", "$", "exp", ")", ";", "// filter empty ones", "$", "commands", "=", "array_filter", "(", "$", "commands", ",", "function", "(", "$", "value", ")", "{", "return", "!", "is_null", "(", "$", "value", ")", ";", "}", ")", ";", "// bracket starting command", "if", "(", "in_array", "(", "$", "commands", "[", "0", "]", ",", "$", "this", "->", "bracket_starting_commands", ")", ")", "{", "// each = foreach", "if", "(", "$", "commands", "[", "0", "]", "==", "'each'", ")", "{", "$", "commands", "[", "0", "]", "=", "'foreach'", ";", "}", "// loop special", "elseif", "(", "$", "commands", "[", "0", "]", "==", "'loop'", ")", "{", "$", "commands", "[", "0", "]", "=", "'for'", ";", "$", "commands", "[", "1", "]", "=", "'$i=0;$i<'", ".", "$", "commands", "[", "1", "]", ".", "';$i++'", ";", "}", "// remove the opening duble point", "end", "(", "$", "commands", ")", ";", "$", "key", "=", "key", "(", "$", "commands", ")", ";", "if", "(", "substr", "(", "$", "commands", "[", "$", "key", "]", ",", "-", "1", ")", "==", "':'", ")", "{", "$", "commands", "[", "$", "key", "]", "=", "substr", "(", "$", "commands", "[", "$", "key", "]", ",", "0", ",", "-", "1", ")", ";", "// is it now empty?", "if", "(", "$", "commands", "[", "$", "key", "]", "==", "' '", "||", "empty", "(", "$", "commands", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "commands", "[", "$", "key", "]", ")", ";", "}", "}", "// do we have brackets?", "if", "(", "substr", "(", "$", "commands", "[", "1", "]", ",", "0", ",", "1", ")", "!=", "'('", ")", "{", "// add starting bracket", "$", "commands", "[", "1", "]", "=", "'( '", ".", "$", "commands", "[", "1", "]", ";", "// add ending bracket", "end", "(", "$", "commands", ")", ";", "$", "key", "=", "key", "(", "$", "commands", ")", ";", "$", "commands", "[", "$", "key", "]", ".=", "' )'", ";", "}", "$", "commands", "[", "]", "=", "':'", ";", "}", "// bracket ending command", "elseif", "(", "count", "(", "$", "commands", "==", "1", ")", "&&", "in_array", "(", "$", "commands", "[", "0", "]", ",", "$", "this", "->", "bracket_ending_commands", ")", ")", "{", "// each = foreach", "if", "(", "$", "commands", "[", "0", "]", "==", "'endeach'", ")", "{", "$", "commands", "[", "0", "]", "=", "'endforeach'", ";", "}", "// loop special", "elseif", "(", "$", "commands", "[", "0", "]", "==", "'endloop'", ")", "{", "$", "commands", "[", "0", "]", "=", "'endfor'", ";", "}", "// check for semicolon", "if", "(", "substr", "(", "$", "commands", "[", "0", "]", ",", "0", ",", "1", ")", "!=", "';'", ")", "{", "$", "commands", "[", "0", "]", ".=", "';'", ";", "}", "}", "// bracket continue command", "elseif", "(", "count", "(", "$", "commands", "==", "1", ")", "&&", "in_array", "(", "$", "commands", "[", "0", "]", ",", "$", "this", "->", "bracket_continue_commands", ")", ")", "{", "// remove the opening duble point", "end", "(", "$", "commands", ")", ";", "$", "key", "=", "key", "(", "$", "commands", ")", ";", "if", "(", "substr", "(", "$", "commands", "[", "$", "key", "]", ",", "-", "1", ")", "==", "':'", ")", "{", "$", "commands", "[", "$", "key", "]", "=", "substr", "(", "$", "commands", "[", "$", "key", "]", ",", "0", ",", "-", "1", ")", ";", "// is it now empty?", "if", "(", "$", "commands", "[", "$", "key", "]", "==", "' '", "||", "empty", "(", "$", "commands", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "commands", "[", "$", "key", "]", ")", ";", "}", "}", "// add the double point", "$", "commands", "[", "]", "=", "':'", ";", "}", "return", "implode", "(", "' '", ",", "$", "commands", ")", ";", "}" ]
Repair an expression
[ "Repair", "an", "expression" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView/Builder/CCFTemplate.php#L102-L194
ClanCats/Core
src/classes/CCView/Builder/CCFTemplate.php
CCView_Builder_CCFTemplate.compile_phptag
private function compile_phptag( $view ) { // I hate this workaround $that = $this; return preg_replace_callback('/\{\%(.*?)\%\}/s', function( $match ) use( $that ) { $expression = trim( $match[1] ); // repair it $expression = $that->repair_expression( $expression ); return '<?php '.$expression.' ?>'; }, $view ); }
php
private function compile_phptag( $view ) { // I hate this workaround $that = $this; return preg_replace_callback('/\{\%(.*?)\%\}/s', function( $match ) use( $that ) { $expression = trim( $match[1] ); // repair it $expression = $that->repair_expression( $expression ); return '<?php '.$expression.' ?>'; }, $view ); }
[ "private", "function", "compile_phptag", "(", "$", "view", ")", "{", "// I hate this workaround", "$", "that", "=", "$", "this", ";", "return", "preg_replace_callback", "(", "'/\\{\\%(.*?)\\%\\}/s'", ",", "function", "(", "$", "match", ")", "use", "(", "$", "that", ")", "{", "$", "expression", "=", "trim", "(", "$", "match", "[", "1", "]", ")", ";", "// repair it ", "$", "expression", "=", "$", "that", "->", "repair_expression", "(", "$", "expression", ")", ";", "return", "'<?php '", ".", "$", "expression", ".", "' ?>'", ";", "}", ",", "$", "view", ")", ";", "}" ]
Search and replace for shortcuts of the php tag @param string $view @return void
[ "Search", "and", "replace", "for", "shortcuts", "of", "the", "php", "tag" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView/Builder/CCFTemplate.php#L223-L237
ClanCats/Core
src/classes/CCView/Builder/CCFTemplate.php
CCView_Builder_CCFTemplate.compile_arrays
private function compile_arrays( $view ) { $tokens = token_get_all( $view ); $tags = array( 0 => '' ); $tag_index = 0; $in_tag = false; // parse all php tags out of the view foreach ( $tokens as $token ) { if ( is_array( $token ) ) { if ( $token[0] === T_OPEN_TAG ) { $in_tag = true; } if ( $in_tag && !in_array( $token[0], array( T_INLINE_HTML ) ) ) { $tags[$tag_index] .= $token[1]; } if ( $token[0] === T_CLOSE_TAG ) { $in_tag = false; $tag_index++; } } else { if ( $in_tag ) { $tags[$tag_index] .= $token; } } } // lets make the tags search keys $tags = array_flip( $tags ); // now search and replace var in the php sections foreach( $tags as $search => &$replace ) { $replace = preg_replace_callback('/(\$[a-zA-Z0-9\_\.\-\>\;]+)/s', function( $match ) { $var = $match[1]; if ( strpos( $var, '.' ) !== false ) { $buffer = ''; $length = strlen( $var ); $inside_arr = false; for( $i=0;$i<$length;$i++ ) { $char = $var[$i]; if ( $char == '.' && !$inside_arr ) { $buffer .= "['"; $inside_arr = true; } else { if ( $inside_arr && in_array( $char, array( ';', '-', ',' ) ) ) { $buffer .= "']"; $inside_arr = false; } if ( $char == '.' ) { $buffer .= "']['"; $inside_arr = true; } else { $buffer .= $char; } } } if ( $inside_arr ) { $buffer .= "']"; } $var = $buffer; } return $var; }, $search ); } return CCStr::replace( $view, $tags ); }
php
private function compile_arrays( $view ) { $tokens = token_get_all( $view ); $tags = array( 0 => '' ); $tag_index = 0; $in_tag = false; // parse all php tags out of the view foreach ( $tokens as $token ) { if ( is_array( $token ) ) { if ( $token[0] === T_OPEN_TAG ) { $in_tag = true; } if ( $in_tag && !in_array( $token[0], array( T_INLINE_HTML ) ) ) { $tags[$tag_index] .= $token[1]; } if ( $token[0] === T_CLOSE_TAG ) { $in_tag = false; $tag_index++; } } else { if ( $in_tag ) { $tags[$tag_index] .= $token; } } } // lets make the tags search keys $tags = array_flip( $tags ); // now search and replace var in the php sections foreach( $tags as $search => &$replace ) { $replace = preg_replace_callback('/(\$[a-zA-Z0-9\_\.\-\>\;]+)/s', function( $match ) { $var = $match[1]; if ( strpos( $var, '.' ) !== false ) { $buffer = ''; $length = strlen( $var ); $inside_arr = false; for( $i=0;$i<$length;$i++ ) { $char = $var[$i]; if ( $char == '.' && !$inside_arr ) { $buffer .= "['"; $inside_arr = true; } else { if ( $inside_arr && in_array( $char, array( ';', '-', ',' ) ) ) { $buffer .= "']"; $inside_arr = false; } if ( $char == '.' ) { $buffer .= "']['"; $inside_arr = true; } else { $buffer .= $char; } } } if ( $inside_arr ) { $buffer .= "']"; } $var = $buffer; } return $var; }, $search ); } return CCStr::replace( $view, $tags ); }
[ "private", "function", "compile_arrays", "(", "$", "view", ")", "{", "$", "tokens", "=", "token_get_all", "(", "$", "view", ")", ";", "$", "tags", "=", "array", "(", "0", "=>", "''", ")", ";", "$", "tag_index", "=", "0", ";", "$", "in_tag", "=", "false", ";", "// parse all php tags out of the view", "foreach", "(", "$", "tokens", "as", "$", "token", ")", "{", "if", "(", "is_array", "(", "$", "token", ")", ")", "{", "if", "(", "$", "token", "[", "0", "]", "===", "T_OPEN_TAG", ")", "{", "$", "in_tag", "=", "true", ";", "}", "if", "(", "$", "in_tag", "&&", "!", "in_array", "(", "$", "token", "[", "0", "]", ",", "array", "(", "T_INLINE_HTML", ")", ")", ")", "{", "$", "tags", "[", "$", "tag_index", "]", ".=", "$", "token", "[", "1", "]", ";", "}", "if", "(", "$", "token", "[", "0", "]", "===", "T_CLOSE_TAG", ")", "{", "$", "in_tag", "=", "false", ";", "$", "tag_index", "++", ";", "}", "}", "else", "{", "if", "(", "$", "in_tag", ")", "{", "$", "tags", "[", "$", "tag_index", "]", ".=", "$", "token", ";", "}", "}", "}", "// lets make the tags search keys", "$", "tags", "=", "array_flip", "(", "$", "tags", ")", ";", "// now search and replace var in the php sections", "foreach", "(", "$", "tags", "as", "$", "search", "=>", "&", "$", "replace", ")", "{", "$", "replace", "=", "preg_replace_callback", "(", "'/(\\$[a-zA-Z0-9\\_\\.\\-\\>\\;]+)/s'", ",", "function", "(", "$", "match", ")", "{", "$", "var", "=", "$", "match", "[", "1", "]", ";", "if", "(", "strpos", "(", "$", "var", ",", "'.'", ")", "!==", "false", ")", "{", "$", "buffer", "=", "''", ";", "$", "length", "=", "strlen", "(", "$", "var", ")", ";", "$", "inside_arr", "=", "false", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "char", "=", "$", "var", "[", "$", "i", "]", ";", "if", "(", "$", "char", "==", "'.'", "&&", "!", "$", "inside_arr", ")", "{", "$", "buffer", ".=", "\"['\"", ";", "$", "inside_arr", "=", "true", ";", "}", "else", "{", "if", "(", "$", "inside_arr", "&&", "in_array", "(", "$", "char", ",", "array", "(", "';'", ",", "'-'", ",", "','", ")", ")", ")", "{", "$", "buffer", ".=", "\"']\"", ";", "$", "inside_arr", "=", "false", ";", "}", "if", "(", "$", "char", "==", "'.'", ")", "{", "$", "buffer", ".=", "\"']['\"", ";", "$", "inside_arr", "=", "true", ";", "}", "else", "{", "$", "buffer", ".=", "$", "char", ";", "}", "}", "}", "if", "(", "$", "inside_arr", ")", "{", "$", "buffer", ".=", "\"']\"", ";", "}", "$", "var", "=", "$", "buffer", ";", "}", "return", "$", "var", ";", "}", ",", "$", "search", ")", ";", "}", "return", "CCStr", "::", "replace", "(", "$", "view", ",", "$", "tags", ")", ";", "}" ]
Search and replace vars with . array access @param string $view @return void
[ "Search", "and", "replace", "vars", "with", ".", "array", "access" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCView/Builder/CCFTemplate.php#L245-L342
anexia-it/anexia-laravel-encryption
src/DatabaseEncryption.php
DatabaseEncryption.performInsert
protected function performInsert(Builder $query) { $encryptedFields = static::getEncryptedFields(); if (count($encryptedFields) && !$this->getEncryptKey()) { throw new \RuntimeException("No encryption key specified"); } $originalAttributes = $this->attributes; foreach ($encryptedFields as $encryptedField) { if (isset($this->attributes[$encryptedField])) { $this->attributes[$encryptedField] = DB::raw(static::getEncryptionService()->getEncryptExpression($this->attributes[$encryptedField], static::getEncryptKey())); } } $inserted = parent::performInsert($query); // reset the attributes to the decrypted values foreach ($encryptedFields as $encryptedField) { if (isset($this->attributes[$encryptedField])) { $this->attributes[$encryptedField] = $originalAttributes[$encryptedField]; } } return $inserted; }
php
protected function performInsert(Builder $query) { $encryptedFields = static::getEncryptedFields(); if (count($encryptedFields) && !$this->getEncryptKey()) { throw new \RuntimeException("No encryption key specified"); } $originalAttributes = $this->attributes; foreach ($encryptedFields as $encryptedField) { if (isset($this->attributes[$encryptedField])) { $this->attributes[$encryptedField] = DB::raw(static::getEncryptionService()->getEncryptExpression($this->attributes[$encryptedField], static::getEncryptKey())); } } $inserted = parent::performInsert($query); // reset the attributes to the decrypted values foreach ($encryptedFields as $encryptedField) { if (isset($this->attributes[$encryptedField])) { $this->attributes[$encryptedField] = $originalAttributes[$encryptedField]; } } return $inserted; }
[ "protected", "function", "performInsert", "(", "Builder", "$", "query", ")", "{", "$", "encryptedFields", "=", "static", "::", "getEncryptedFields", "(", ")", ";", "if", "(", "count", "(", "$", "encryptedFields", ")", "&&", "!", "$", "this", "->", "getEncryptKey", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"No encryption key specified\"", ")", ";", "}", "$", "originalAttributes", "=", "$", "this", "->", "attributes", ";", "foreach", "(", "$", "encryptedFields", "as", "$", "encryptedField", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "$", "encryptedField", "]", ")", ")", "{", "$", "this", "->", "attributes", "[", "$", "encryptedField", "]", "=", "DB", "::", "raw", "(", "static", "::", "getEncryptionService", "(", ")", "->", "getEncryptExpression", "(", "$", "this", "->", "attributes", "[", "$", "encryptedField", "]", ",", "static", "::", "getEncryptKey", "(", ")", ")", ")", ";", "}", "}", "$", "inserted", "=", "parent", "::", "performInsert", "(", "$", "query", ")", ";", "// reset the attributes to the decrypted values", "foreach", "(", "$", "encryptedFields", "as", "$", "encryptedField", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attributes", "[", "$", "encryptedField", "]", ")", ")", "{", "$", "this", "->", "attributes", "[", "$", "encryptedField", "]", "=", "$", "originalAttributes", "[", "$", "encryptedField", "]", ";", "}", "}", "return", "$", "inserted", ";", "}" ]
Perform insert with encryption @param Builder $query @return bool
[ "Perform", "insert", "with", "encryption" ]
train
https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryption.php#L59-L80
anexia-it/anexia-laravel-encryption
src/DatabaseEncryption.php
DatabaseEncryption.newBaseQueryBuilder
protected function newBaseQueryBuilder() { $connection = $this->getConnection(); return new DatabaseEncryptionQueryBuilder( $connection, $connection->getQueryGrammar(), $connection->getPostProcessor() ); }
php
protected function newBaseQueryBuilder() { $connection = $this->getConnection(); return new DatabaseEncryptionQueryBuilder( $connection, $connection->getQueryGrammar(), $connection->getPostProcessor() ); }
[ "protected", "function", "newBaseQueryBuilder", "(", ")", "{", "$", "connection", "=", "$", "this", "->", "getConnection", "(", ")", ";", "return", "new", "DatabaseEncryptionQueryBuilder", "(", "$", "connection", ",", "$", "connection", "->", "getQueryGrammar", "(", ")", ",", "$", "connection", "->", "getPostProcessor", "(", ")", ")", ";", "}" ]
Get a new query builder instance for the connection. Use the package's DatabaseEncryptionQueryBuilder. @return \Illuminate\Database\Query\Builder
[ "Get", "a", "new", "query", "builder", "instance", "for", "the", "connection", ".", "Use", "the", "package", "s", "DatabaseEncryptionQueryBuilder", "." ]
train
https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryption.php#L116-L123
anexia-it/anexia-laravel-encryption
src/DatabaseEncryption.php
DatabaseEncryption.getArrayableItems
protected function getArrayableItems(array $values) { $encryptedFields = static::getEncryptedFields(); if (count($this->getVisible()) > 0) { $visibles = $this->getVisible(); $intValues = array_intersect_key($values, array_flip($visibles)); foreach ($encryptedFields as $encryptedField) { if (in_array($encryptedField, $visibles) && isset($values[$encryptedField])) { $intValues["{$encryptedField}_encrypted"] = $values[$encryptedField]; } if (in_array($encryptedField, $visibles) && isset($values["{$encryptedField}_encrypted"])) { $intValues["{$encryptedField}_encrypted"] = $values["{$encryptedField}_encrypted"]; } } $values = $intValues; } if (count($this->getHidden()) > 0) { $hiddenFields = $this->getHidden(); $values = array_diff_key($values, array_flip($hiddenFields)); foreach ($encryptedFields as $encryptedField) { if (in_array($encryptedField, $hiddenFields)) { unset($values["{$encryptedField}_encrypted"]); } } } return $values; }
php
protected function getArrayableItems(array $values) { $encryptedFields = static::getEncryptedFields(); if (count($this->getVisible()) > 0) { $visibles = $this->getVisible(); $intValues = array_intersect_key($values, array_flip($visibles)); foreach ($encryptedFields as $encryptedField) { if (in_array($encryptedField, $visibles) && isset($values[$encryptedField])) { $intValues["{$encryptedField}_encrypted"] = $values[$encryptedField]; } if (in_array($encryptedField, $visibles) && isset($values["{$encryptedField}_encrypted"])) { $intValues["{$encryptedField}_encrypted"] = $values["{$encryptedField}_encrypted"]; } } $values = $intValues; } if (count($this->getHidden()) > 0) { $hiddenFields = $this->getHidden(); $values = array_diff_key($values, array_flip($hiddenFields)); foreach ($encryptedFields as $encryptedField) { if (in_array($encryptedField, $hiddenFields)) { unset($values["{$encryptedField}_encrypted"]); } } } return $values; }
[ "protected", "function", "getArrayableItems", "(", "array", "$", "values", ")", "{", "$", "encryptedFields", "=", "static", "::", "getEncryptedFields", "(", ")", ";", "if", "(", "count", "(", "$", "this", "->", "getVisible", "(", ")", ")", ">", "0", ")", "{", "$", "visibles", "=", "$", "this", "->", "getVisible", "(", ")", ";", "$", "intValues", "=", "array_intersect_key", "(", "$", "values", ",", "array_flip", "(", "$", "visibles", ")", ")", ";", "foreach", "(", "$", "encryptedFields", "as", "$", "encryptedField", ")", "{", "if", "(", "in_array", "(", "$", "encryptedField", ",", "$", "visibles", ")", "&&", "isset", "(", "$", "values", "[", "$", "encryptedField", "]", ")", ")", "{", "$", "intValues", "[", "\"{$encryptedField}_encrypted\"", "]", "=", "$", "values", "[", "$", "encryptedField", "]", ";", "}", "if", "(", "in_array", "(", "$", "encryptedField", ",", "$", "visibles", ")", "&&", "isset", "(", "$", "values", "[", "\"{$encryptedField}_encrypted\"", "]", ")", ")", "{", "$", "intValues", "[", "\"{$encryptedField}_encrypted\"", "]", "=", "$", "values", "[", "\"{$encryptedField}_encrypted\"", "]", ";", "}", "}", "$", "values", "=", "$", "intValues", ";", "}", "if", "(", "count", "(", "$", "this", "->", "getHidden", "(", ")", ")", ">", "0", ")", "{", "$", "hiddenFields", "=", "$", "this", "->", "getHidden", "(", ")", ";", "$", "values", "=", "array_diff_key", "(", "$", "values", ",", "array_flip", "(", "$", "hiddenFields", ")", ")", ";", "foreach", "(", "$", "encryptedFields", "as", "$", "encryptedField", ")", "{", "if", "(", "in_array", "(", "$", "encryptedField", ",", "$", "hiddenFields", ")", ")", "{", "unset", "(", "$", "values", "[", "\"{$encryptedField}_encrypted\"", "]", ")", ";", "}", "}", "}", "return", "$", "values", ";", "}" ]
Get an attribute array of all arrayable values. @param array $values @return array
[ "Get", "an", "attribute", "array", "of", "all", "arrayable", "values", "." ]
train
https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryption.php#L166-L198
christianblos/markdown2html
src/FilenameInfo.php
FilenameInfo.convertToLabel
private function convertToLabel($value) { $value = preg_replace('/(?<!-)-(?!-)/U', ' ', $value); $value = preg_replace('/(?<!-)--(?!-)/U', '-', $value); $value = preg_replace('/(?<!-)---(?!-)/U', ' - ', $value); return $value; }
php
private function convertToLabel($value) { $value = preg_replace('/(?<!-)-(?!-)/U', ' ', $value); $value = preg_replace('/(?<!-)--(?!-)/U', '-', $value); $value = preg_replace('/(?<!-)---(?!-)/U', ' - ', $value); return $value; }
[ "private", "function", "convertToLabel", "(", "$", "value", ")", "{", "$", "value", "=", "preg_replace", "(", "'/(?<!-)-(?!-)/U'", ",", "' '", ",", "$", "value", ")", ";", "$", "value", "=", "preg_replace", "(", "'/(?<!-)--(?!-)/U'", ",", "'-'", ",", "$", "value", ")", ";", "$", "value", "=", "preg_replace", "(", "'/(?<!-)---(?!-)/U'", ",", "' - '", ",", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
@param string $value @return string
[ "@param", "string", "$value" ]
train
https://github.com/christianblos/markdown2html/blob/2ae1177d71fe313c802962dbb9226b5a90bbc65a/src/FilenameInfo.php#L65-L72
VincentChalnot/SidusAdminBundle
Entity/AdminEntityMatcher.php
AdminEntityMatcher.getAdminForEntity
public function getAdminForEntity($entity): Admin { $class = \get_class($entity); if (array_key_exists($class, $this->cache)) { return $this->cache[$class]; } foreach ($this->adminRegistry->getAdmins() as $admin) { if (is_a($entity, $admin->getEntity())) { $this->cache[$class] = $admin; return $admin; } } throw new \UnexpectedValueException("No admin matching for entity '{$class}'"); }
php
public function getAdminForEntity($entity): Admin { $class = \get_class($entity); if (array_key_exists($class, $this->cache)) { return $this->cache[$class]; } foreach ($this->adminRegistry->getAdmins() as $admin) { if (is_a($entity, $admin->getEntity())) { $this->cache[$class] = $admin; return $admin; } } throw new \UnexpectedValueException("No admin matching for entity '{$class}'"); }
[ "public", "function", "getAdminForEntity", "(", "$", "entity", ")", ":", "Admin", "{", "$", "class", "=", "\\", "get_class", "(", "$", "entity", ")", ";", "if", "(", "array_key_exists", "(", "$", "class", ",", "$", "this", "->", "cache", ")", ")", "{", "return", "$", "this", "->", "cache", "[", "$", "class", "]", ";", "}", "foreach", "(", "$", "this", "->", "adminRegistry", "->", "getAdmins", "(", ")", "as", "$", "admin", ")", "{", "if", "(", "is_a", "(", "$", "entity", ",", "$", "admin", "->", "getEntity", "(", ")", ")", ")", "{", "$", "this", "->", "cache", "[", "$", "class", "]", "=", "$", "admin", ";", "return", "$", "admin", ";", "}", "}", "throw", "new", "\\", "UnexpectedValueException", "(", "\"No admin matching for entity '{$class}'\"", ")", ";", "}" ]
@param mixed $entity @throws \UnexpectedValueException @return Admin
[ "@param", "mixed", "$entity" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Entity/AdminEntityMatcher.php#L44-L61
ClanCats/Core
src/classes/CCOrbit.php
CCOrbit.installed_ships
public static function installed_ships() { $ships = static::$data->get( 'installed', array() ); foreach ( $ships as $key => $ship ) { $ships[$key] = CCROOT.$ship; } return $ships; }
php
public static function installed_ships() { $ships = static::$data->get( 'installed', array() ); foreach ( $ships as $key => $ship ) { $ships[$key] = CCROOT.$ship; } return $ships; }
[ "public", "static", "function", "installed_ships", "(", ")", "{", "$", "ships", "=", "static", "::", "$", "data", "->", "get", "(", "'installed'", ",", "array", "(", ")", ")", ";", "foreach", "(", "$", "ships", "as", "$", "key", "=>", "$", "ship", ")", "{", "$", "ships", "[", "$", "key", "]", "=", "CCROOT", ".", "$", "ship", ";", "}", "return", "$", "ships", ";", "}" ]
return all installed ships
[ "return", "all", "installed", "ships" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCOrbit.php#L85-L95
ClanCats/Core
src/classes/CCOrbit.php
CCOrbit.install
public static function install( $path ) { // load ship at path $ship = CCOrbit_Ship::create( $path ); if ( static::$data->has( 'installed.'.$ship->name ) ) { throw new CCException( "CCOrbit::install - {$ship->name} ship already installed." ); } if ( $ship->install !== false ) { $ship->event( $ship->install ); } static::$data->set( 'installed.'.$ship->name, CCStr::strip( $ship->path, CCROOT ) ); // save changes static::$data->write( 'json' ); }
php
public static function install( $path ) { // load ship at path $ship = CCOrbit_Ship::create( $path ); if ( static::$data->has( 'installed.'.$ship->name ) ) { throw new CCException( "CCOrbit::install - {$ship->name} ship already installed." ); } if ( $ship->install !== false ) { $ship->event( $ship->install ); } static::$data->set( 'installed.'.$ship->name, CCStr::strip( $ship->path, CCROOT ) ); // save changes static::$data->write( 'json' ); }
[ "public", "static", "function", "install", "(", "$", "path", ")", "{", "// load ship at path", "$", "ship", "=", "CCOrbit_Ship", "::", "create", "(", "$", "path", ")", ";", "if", "(", "static", "::", "$", "data", "->", "has", "(", "'installed.'", ".", "$", "ship", "->", "name", ")", ")", "{", "throw", "new", "CCException", "(", "\"CCOrbit::install - {$ship->name} ship already installed.\"", ")", ";", "}", "if", "(", "$", "ship", "->", "install", "!==", "false", ")", "{", "$", "ship", "->", "event", "(", "$", "ship", "->", "install", ")", ";", "}", "static", "::", "$", "data", "->", "set", "(", "'installed.'", ".", "$", "ship", "->", "name", ",", "CCStr", "::", "strip", "(", "$", "ship", "->", "path", ",", "CCROOT", ")", ")", ";", "// save changes", "static", "::", "$", "data", "->", "write", "(", "'json'", ")", ";", "}" ]
install a ship string $path | the ship name / the folder. If the path is not absolute, ORBITPATH gets used
[ "install", "a", "ship" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCOrbit.php#L111-L129
ClanCats/Core
src/classes/CCOrbit.php
CCOrbit.uninstall
public static function uninstall( $path ) { // load ship at path $ship = CCOrbit_Ship::create( $path ); if ( !static::$data->has( 'installed.'.$ship->name ) ) { throw new CCException( "CCOrbit::uninstall - {$ship->name} ship is not installed." ); } if ( $ship->uninstall !== false ) { $ship->event( $ship->uninstall ); } static::$data->delete( 'installed.'.$ship->name ); // save changes static::$data->write( 'json' ); }
php
public static function uninstall( $path ) { // load ship at path $ship = CCOrbit_Ship::create( $path ); if ( !static::$data->has( 'installed.'.$ship->name ) ) { throw new CCException( "CCOrbit::uninstall - {$ship->name} ship is not installed." ); } if ( $ship->uninstall !== false ) { $ship->event( $ship->uninstall ); } static::$data->delete( 'installed.'.$ship->name ); // save changes static::$data->write( 'json' ); }
[ "public", "static", "function", "uninstall", "(", "$", "path", ")", "{", "// load ship at path", "$", "ship", "=", "CCOrbit_Ship", "::", "create", "(", "$", "path", ")", ";", "if", "(", "!", "static", "::", "$", "data", "->", "has", "(", "'installed.'", ".", "$", "ship", "->", "name", ")", ")", "{", "throw", "new", "CCException", "(", "\"CCOrbit::uninstall - {$ship->name} ship is not installed.\"", ")", ";", "}", "if", "(", "$", "ship", "->", "uninstall", "!==", "false", ")", "{", "$", "ship", "->", "event", "(", "$", "ship", "->", "uninstall", ")", ";", "}", "static", "::", "$", "data", "->", "delete", "(", "'installed.'", ".", "$", "ship", "->", "name", ")", ";", "// save changes", "static", "::", "$", "data", "->", "write", "(", "'json'", ")", ";", "}" ]
install a ship string $path | the ship name / the folder. If the path is not absolute, ORBITPATH gets used
[ "install", "a", "ship" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCOrbit.php#L136-L153
ClanCats/Core
src/classes/CCOrbit.php
CCOrbit.enter
public static function enter( $path ) { if ( !is_array( $path ) ) { $path = array( $path ); } foreach( $path as $ship ) { // load ship at path $ship = CCOrbit_Ship::create( $ship ); if ( array_key_exists( $ship->name, static::$ships ) ) { throw new CCException( "CCOrbit::enter - {$ship->name} ship already entered." ); } if ( $ship->wake !== false ) { $ship->event( $ship->wake ); } CCProfiler::check( "CCOrbit - ship {$ship->name} launched." ); // add to our loaded ships static::$ships[$ship->name] = $ship; } }
php
public static function enter( $path ) { if ( !is_array( $path ) ) { $path = array( $path ); } foreach( $path as $ship ) { // load ship at path $ship = CCOrbit_Ship::create( $ship ); if ( array_key_exists( $ship->name, static::$ships ) ) { throw new CCException( "CCOrbit::enter - {$ship->name} ship already entered." ); } if ( $ship->wake !== false ) { $ship->event( $ship->wake ); } CCProfiler::check( "CCOrbit - ship {$ship->name} launched." ); // add to our loaded ships static::$ships[$ship->name] = $ship; } }
[ "public", "static", "function", "enter", "(", "$", "path", ")", "{", "if", "(", "!", "is_array", "(", "$", "path", ")", ")", "{", "$", "path", "=", "array", "(", "$", "path", ")", ";", "}", "foreach", "(", "$", "path", "as", "$", "ship", ")", "{", "// load ship at path", "$", "ship", "=", "CCOrbit_Ship", "::", "create", "(", "$", "ship", ")", ";", "if", "(", "array_key_exists", "(", "$", "ship", "->", "name", ",", "static", "::", "$", "ships", ")", ")", "{", "throw", "new", "CCException", "(", "\"CCOrbit::enter - {$ship->name} ship already entered.\"", ")", ";", "}", "if", "(", "$", "ship", "->", "wake", "!==", "false", ")", "{", "$", "ship", "->", "event", "(", "$", "ship", "->", "wake", ")", ";", "}", "CCProfiler", "::", "check", "(", "\"CCOrbit - ship {$ship->name} launched.\"", ")", ";", "// add to our loaded ships", "static", "::", "$", "ships", "[", "$", "ship", "->", "name", "]", "=", "$", "ship", ";", "}", "}" ]
Add a ship this loads the ship loader file @param string $path @return bool
[ "Add", "a", "ship", "this", "loads", "the", "ship", "loader", "file" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCOrbit.php#L162-L188
seeruo/framework
src/Library/Pinyin.php
Pinyin.getpy
public static function getpy($s, $quanpin = true, $daxie = false) { $s = preg_replace("/\s/is", "_", $s); $s = preg_replace("/(|\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\+|\=|\{|\}|\[|\]|\||\\|\:|\;|\"|\'|\<|\,|\>|\.|\?|\/)/is", "", $s); $i = 0; $py = ''; // 加入这一句,自动识别UTF-8 if (strlen("拼音") > 4){ $s = @iconv('UTF-8', 'GBK', $s); } if ($quanpin) { // 全拼 for ($i = 0; $i < strlen($s); $i++) { if (ord($s[$i]) > 128) { $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256); $py.=$char; $i++; } else { $py.=$s[$i]; } } } else { // 首字母 for ($i = 0; $i < strlen($s); $i++) { if (ord($s[$i]) > 128) { $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256); $py .=$char[0]; $i++; } else { $py .=$s[$i]; } } } // 判断是否输出小写字符 return ($daxie == true ? $py : strtolower($py)); }
php
public static function getpy($s, $quanpin = true, $daxie = false) { $s = preg_replace("/\s/is", "_", $s); $s = preg_replace("/(|\~|\`|\!|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\+|\=|\{|\}|\[|\]|\||\\|\:|\;|\"|\'|\<|\,|\>|\.|\?|\/)/is", "", $s); $i = 0; $py = ''; // 加入这一句,自动识别UTF-8 if (strlen("拼音") > 4){ $s = @iconv('UTF-8', 'GBK', $s); } if ($quanpin) { // 全拼 for ($i = 0; $i < strlen($s); $i++) { if (ord($s[$i]) > 128) { $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256); $py.=$char; $i++; } else { $py.=$s[$i]; } } } else { // 首字母 for ($i = 0; $i < strlen($s); $i++) { if (ord($s[$i]) > 128) { $char = self::asi2py(ord($s[$i]) + ord($s[$i + 1]) * 256); $py .=$char[0]; $i++; } else { $py .=$s[$i]; } } } // 判断是否输出小写字符 return ($daxie == true ? $py : strtolower($py)); }
[ "public", "static", "function", "getpy", "(", "$", "s", ",", "$", "quanpin", "=", "true", ",", "$", "daxie", "=", "false", ")", "{", "$", "s", "=", "preg_replace", "(", "\"/\\s/is\"", ",", "\"_\"", ",", "$", "s", ")", ";", "$", "s", "=", "preg_replace", "(", "\"/(|\\~|\\`|\\!|\\@|\\#|\\$|\\%|\\^|\\&|\\*|\\(|\\)|\\-|\\+|\\=|\\{|\\}|\\[|\\]|\\||\\\\|\\:|\\;|\\\"|\\'|\\<|\\,|\\>|\\.|\\?|\\/)/is\"", ",", "\"\"", ",", "$", "s", ")", ";", "$", "i", "=", "0", ";", "$", "py", "=", "''", ";", "// 加入这一句,自动识别UTF-8 ", "if", "(", "strlen", "(", "\"拼音\") > ", "4", "{", "", "", "", "$", "s", "=", "@", "iconv", "(", "'UTF-8'", ",", "'GBK'", ",", "$", "s", ")", ";", "}", "if", "(", "$", "quanpin", ")", "{", "// 全拼", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "s", ")", ";", "$", "i", "++", ")", "{", "if", "(", "ord", "(", "$", "s", "[", "$", "i", "]", ")", ">", "128", ")", "{", "$", "char", "=", "self", "::", "asi2py", "(", "ord", "(", "$", "s", "[", "$", "i", "]", ")", "+", "ord", "(", "$", "s", "[", "$", "i", "+", "1", "]", ")", "*", "256", ")", ";", "$", "py", ".=", "$", "char", ";", "$", "i", "++", ";", "}", "else", "{", "$", "py", ".=", "$", "s", "[", "$", "i", "]", ";", "}", "}", "}", "else", "{", "// 首字母 ", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "s", ")", ";", "$", "i", "++", ")", "{", "if", "(", "ord", "(", "$", "s", "[", "$", "i", "]", ")", ">", "128", ")", "{", "$", "char", "=", "self", "::", "asi2py", "(", "ord", "(", "$", "s", "[", "$", "i", "]", ")", "+", "ord", "(", "$", "s", "[", "$", "i", "+", "1", "]", ")", "*", "256", ")", ";", "$", "py", ".=", "$", "char", "[", "0", "]", ";", "$", "i", "++", ";", "}", "else", "{", "$", "py", ".=", "$", "s", "[", "$", "i", "]", ";", "}", "}", "}", "// 判断是否输出小写字符 ", "return", "(", "$", "daxie", "==", "true", "?", "$", "py", ":", "strtolower", "(", "$", "py", ")", ")", ";", "}" ]
[getpy 汉字转拼音函数] @DateTime 2018-10-08 @param [type] $s [汉字字符串] @param boolean $quanpin [是否全拼] @param boolean $daxie [首字母是否大写] @return [string] [description]
[ "[", "getpy", "汉字转拼音函数", "]" ]
train
https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Library/Pinyin.php#L530-L563
meccado/acl-admin-control-panel
src/Providers/AuthServiceProvider.php
AuthServiceProvider.boot
public function boot(GateContract $gate) { $this->registerPolicies($gate); if (\Schema::hasTable('permissions')) { // Dynamically register permissions with Laravel's Gate. foreach ($this->getPermissions() as $permission) { $gate->define($permission->name, function ($user) use ($permission) { return $user->hasPermission($permission); }); } } }
php
public function boot(GateContract $gate) { $this->registerPolicies($gate); if (\Schema::hasTable('permissions')) { // Dynamically register permissions with Laravel's Gate. foreach ($this->getPermissions() as $permission) { $gate->define($permission->name, function ($user) use ($permission) { return $user->hasPermission($permission); }); } } }
[ "public", "function", "boot", "(", "GateContract", "$", "gate", ")", "{", "$", "this", "->", "registerPolicies", "(", "$", "gate", ")", ";", "if", "(", "\\", "Schema", "::", "hasTable", "(", "'permissions'", ")", ")", "{", "// Dynamically register permissions with Laravel's Gate.", "foreach", "(", "$", "this", "->", "getPermissions", "(", ")", "as", "$", "permission", ")", "{", "$", "gate", "->", "define", "(", "$", "permission", "->", "name", ",", "function", "(", "$", "user", ")", "use", "(", "$", "permission", ")", "{", "return", "$", "user", "->", "hasPermission", "(", "$", "permission", ")", ";", "}", ")", ";", "}", "}", "}" ]
Register any application authentication / authorization services. @param \Illuminate\Contracts\Auth\Access\Gate $gate @return void
[ "Register", "any", "application", "authentication", "/", "authorization", "services", "." ]
train
https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Providers/AuthServiceProvider.php#L27-L39
xinix-technology/norm
src/Norm/Model.php
Model.setId
public function setId($givenId) { if (!isset($this->id)) { $this->id = $givenId; } return $this->id; }
php
public function setId($givenId) { if (!isset($this->id)) { $this->id = $givenId; } return $this->id; }
[ "public", "function", "setId", "(", "$", "givenId", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "id", ")", ")", "{", "$", "this", "->", "id", "=", "$", "givenId", ";", "}", "return", "$", "this", "->", "id", ";", "}" ]
Set id of model. @return int|string
[ "Set", "id", "of", "model", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L131-L137
xinix-technology/norm
src/Norm/Model.php
Model.get
public function get($key) { if ($key === '$id') { return $this->getId(); } $schema = $this->schema($key); if (isset($schema) and $schema->hasReader()) { return $schema->read($this); } return isset($this->attributes[$key]) ? $this->attributes[$key] : null; }
php
public function get($key) { if ($key === '$id') { return $this->getId(); } $schema = $this->schema($key); if (isset($schema) and $schema->hasReader()) { return $schema->read($this); } return isset($this->attributes[$key]) ? $this->attributes[$key] : null; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "if", "(", "$", "key", "===", "'$id'", ")", "{", "return", "$", "this", "->", "getId", "(", ")", ";", "}", "$", "schema", "=", "$", "this", "->", "schema", "(", "$", "key", ")", ";", "if", "(", "isset", "(", "$", "schema", ")", "and", "$", "schema", "->", "hasReader", "(", ")", ")", "{", "return", "$", "schema", "->", "read", "(", "$", "this", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "attributes", "[", "$", "key", "]", ")", "?", "$", "this", "->", "attributes", "[", "$", "key", "]", ":", "null", ";", "}" ]
Get the attribute. @param string $key @return mixed
[ "Get", "the", "attribute", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L160-L171
xinix-technology/norm
src/Norm/Model.php
Model.dump
public function dump() { $attributes = array(); if ($this->id) { $attributes['$id'] = $this->id; } foreach ($this->attributes as $key => $value) { $schema = $this->schema($key); if (! empty($schema['transient'])) { continue; } $attributes[$key] = $value; } return $attributes; }
php
public function dump() { $attributes = array(); if ($this->id) { $attributes['$id'] = $this->id; } foreach ($this->attributes as $key => $value) { $schema = $this->schema($key); if (! empty($schema['transient'])) { continue; } $attributes[$key] = $value; } return $attributes; }
[ "public", "function", "dump", "(", ")", "{", "$", "attributes", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "id", ")", "{", "$", "attributes", "[", "'$id'", "]", "=", "$", "this", "->", "id", ";", "}", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "schema", "=", "$", "this", "->", "schema", "(", "$", "key", ")", ";", "if", "(", "!", "empty", "(", "$", "schema", "[", "'transient'", "]", ")", ")", "{", "continue", ";", "}", "$", "attributes", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "attributes", ";", "}" ]
Dump attributes raw data. @method dump @return array
[ "Dump", "attributes", "raw", "data", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L180-L199
xinix-technology/norm
src/Norm/Model.php
Model.add
public function add($key, $value) { if (! isset($this->attributes[$key])) { $this->attributes[$key] = array(); } $this->attributes[$key][] = $value; return $this; }
php
public function add($key, $value) { if (! isset($this->attributes[$key])) { $this->attributes[$key] = array(); } $this->attributes[$key][] = $value; return $this; }
[ "public", "function", "add", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "attributes", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "attributes", "[", "$", "key", "]", "=", "array", "(", ")", ";", "}", "$", "this", "->", "attributes", "[", "$", "key", "]", "[", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Add an attributes data. @method add @param string $key @param mixed $value
[ "Add", "an", "attributes", "data", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L209-L218
xinix-technology/norm
src/Norm/Model.php
Model.set
public function set($key, $value = '') { if (is_array($key)) { foreach ($key as $k => $v) { if ($k !== '$id') { $this->set($k, $v); } } } elseif ($key === '$id') { throw new Exception('[Norm/Model] Restricting set for $id.'); } else { $this->attributes[$key] = $this->prepare($key, $value); } return $this; }
php
public function set($key, $value = '') { if (is_array($key)) { foreach ($key as $k => $v) { if ($k !== '$id') { $this->set($k, $v); } } } elseif ($key === '$id') { throw new Exception('[Norm/Model] Restricting set for $id.'); } else { $this->attributes[$key] = $this->prepare($key, $value); } return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", "=", "''", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "foreach", "(", "$", "key", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "k", "!==", "'$id'", ")", "{", "$", "this", "->", "set", "(", "$", "k", ",", "$", "v", ")", ";", "}", "}", "}", "elseif", "(", "$", "key", "===", "'$id'", ")", "{", "throw", "new", "Exception", "(", "'[Norm/Model] Restricting set for $id.'", ")", ";", "}", "else", "{", "$", "this", "->", "attributes", "[", "$", "key", "]", "=", "$", "this", "->", "prepare", "(", "$", "key", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set attribute(s). @param string|array $key @param string $value Optional.
[ "Set", "attribute", "(", "s", ")", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L226-L241
xinix-technology/norm
src/Norm/Model.php
Model.clear
public function clear($key = null) { if (func_num_args() === 0) { $this->attributes = array(); } elseif ($key === '$id') { throw new Exception('[Norm/Model] Restricting clear for $id.'); } else { unset($this->attributes[$key]); } return $this; }
php
public function clear($key = null) { if (func_num_args() === 0) { $this->attributes = array(); } elseif ($key === '$id') { throw new Exception('[Norm/Model] Restricting clear for $id.'); } else { unset($this->attributes[$key]); } return $this; }
[ "public", "function", "clear", "(", "$", "key", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", "===", "0", ")", "{", "$", "this", "->", "attributes", "=", "array", "(", ")", ";", "}", "elseif", "(", "$", "key", "===", "'$id'", ")", "{", "throw", "new", "Exception", "(", "'[Norm/Model] Restricting clear for $id.'", ")", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "attributes", "[", "$", "key", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Clear attributes value. @method clear @param string $key @return \Norm\Model
[ "Clear", "attributes", "value", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L252-L263
xinix-technology/norm
src/Norm/Model.php
Model.sync
public function sync($attributes) { if (isset($attributes['$id'])) { $this->state = static::STATE_ATTACHED; $this->id = $attributes['$id']; } else { foreach ($this->schema() as $key => $field) { if ($field->has('default')) { $attributes[$key] = $field['default']; } } $this->state = static::STATE_DETACHED; } $this->set($attributes); $this->populateOld(); }
php
public function sync($attributes) { if (isset($attributes['$id'])) { $this->state = static::STATE_ATTACHED; $this->id = $attributes['$id']; } else { foreach ($this->schema() as $key => $field) { if ($field->has('default')) { $attributes[$key] = $field['default']; } } $this->state = static::STATE_DETACHED; } $this->set($attributes); $this->populateOld(); }
[ "public", "function", "sync", "(", "$", "attributes", ")", "{", "if", "(", "isset", "(", "$", "attributes", "[", "'$id'", "]", ")", ")", "{", "$", "this", "->", "state", "=", "static", "::", "STATE_ATTACHED", ";", "$", "this", "->", "id", "=", "$", "attributes", "[", "'$id'", "]", ";", "}", "else", "{", "foreach", "(", "$", "this", "->", "schema", "(", ")", "as", "$", "key", "=>", "$", "field", ")", "{", "if", "(", "$", "field", "->", "has", "(", "'default'", ")", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "field", "[", "'default'", "]", ";", "}", "}", "$", "this", "->", "state", "=", "static", "::", "STATE_DETACHED", ";", "}", "$", "this", "->", "set", "(", "$", "attributes", ")", ";", "$", "this", "->", "populateOld", "(", ")", ";", "}" ]
Sync the existing attributes with new values. After update or insert, this method used to modify the existing attributes. @param array $attributes @return void
[ "Sync", "the", "existing", "attributes", "with", "new", "values", ".", "After", "update", "or", "insert", "this", "method", "used", "to", "modify", "the", "existing", "attributes", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L272-L289
xinix-technology/norm
src/Norm/Model.php
Model.prepare
public function prepare($key, $value, $schema = null) { if ($this->collection) { return $this->collection->prepare($key, $value, $schema); } else { return $value; } }
php
public function prepare($key, $value, $schema = null) { if ($this->collection) { return $this->collection->prepare($key, $value, $schema); } else { return $value; } }
[ "public", "function", "prepare", "(", "$", "key", ",", "$", "value", ",", "$", "schema", "=", "null", ")", "{", "if", "(", "$", "this", "->", "collection", ")", "{", "return", "$", "this", "->", "collection", "->", "prepare", "(", "$", "key", ",", "$", "value", ",", "$", "schema", ")", ";", "}", "else", "{", "return", "$", "value", ";", "}", "}" ]
Prepare model to be sync'd. @method prepare @param string $key @param string $value @param mixed $schema @return [type]
[ "Prepare", "model", "to", "be", "sync", "d", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L302-L309
xinix-technology/norm
src/Norm/Model.php
Model.toArray
public function toArray($fetchType = Model::FETCH_ALL) { if ($fetchType === Model::FETCH_RAW) { return $this->attributes; } $attributes = array(); if (empty($this->attributes)) { $this->attributes = array(); } if ($fetchType === Model::FETCH_ALL or $fetchType === Model::FETCH_HIDDEN) { $attributes['$type'] = $this->getClass(); $attributes['$id'] = $this->getId(); foreach ($this->attributes as $key => $value) { if ($key[0] === '$') { $attributes[$key] = $value; } } } if ($fetchType === Model::FETCH_ALL or $fetchType === Model::FETCH_PUBLISHED) { foreach ($this->attributes as $key => $value) { if ($key[0] !== '$') { $attributes[$key] = $value; } } } return $attributes; }
php
public function toArray($fetchType = Model::FETCH_ALL) { if ($fetchType === Model::FETCH_RAW) { return $this->attributes; } $attributes = array(); if (empty($this->attributes)) { $this->attributes = array(); } if ($fetchType === Model::FETCH_ALL or $fetchType === Model::FETCH_HIDDEN) { $attributes['$type'] = $this->getClass(); $attributes['$id'] = $this->getId(); foreach ($this->attributes as $key => $value) { if ($key[0] === '$') { $attributes[$key] = $value; } } } if ($fetchType === Model::FETCH_ALL or $fetchType === Model::FETCH_PUBLISHED) { foreach ($this->attributes as $key => $value) { if ($key[0] !== '$') { $attributes[$key] = $value; } } } return $attributes; }
[ "public", "function", "toArray", "(", "$", "fetchType", "=", "Model", "::", "FETCH_ALL", ")", "{", "if", "(", "$", "fetchType", "===", "Model", "::", "FETCH_RAW", ")", "{", "return", "$", "this", "->", "attributes", ";", "}", "$", "attributes", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "attributes", ")", ")", "{", "$", "this", "->", "attributes", "=", "array", "(", ")", ";", "}", "if", "(", "$", "fetchType", "===", "Model", "::", "FETCH_ALL", "or", "$", "fetchType", "===", "Model", "::", "FETCH_HIDDEN", ")", "{", "$", "attributes", "[", "'$type'", "]", "=", "$", "this", "->", "getClass", "(", ")", ";", "$", "attributes", "[", "'$id'", "]", "=", "$", "this", "->", "getId", "(", ")", ";", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "[", "0", "]", "===", "'$'", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}", "if", "(", "$", "fetchType", "===", "Model", "::", "FETCH_ALL", "or", "$", "fetchType", "===", "Model", "::", "FETCH_PUBLISHED", ")", "{", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "[", "0", "]", "!==", "'$'", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}", "return", "$", "attributes", ";", "}" ]
Get array structure of model @param mixed $fetchType @return array
[ "Get", "array", "structure", "of", "model" ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L352-L384
xinix-technology/norm
src/Norm/Model.php
Model.jsonSerialize
public function jsonSerialize() { if (! Norm::options('include')) { return $this->toArray(); } $destination = array(); $source = $this->toArray(); $schema = $this->collection->schema(); foreach ($source as $key => $value) { if (isset($schema[$key]) and isset($value)) { $destination[$key] = $schema[$key]->toJSON($value); } else { $destination[$key] = $value; } $destination[$key] = JsonKit::replaceObject($destination[$key]); } return $destination; }
php
public function jsonSerialize() { if (! Norm::options('include')) { return $this->toArray(); } $destination = array(); $source = $this->toArray(); $schema = $this->collection->schema(); foreach ($source as $key => $value) { if (isset($schema[$key]) and isset($value)) { $destination[$key] = $schema[$key]->toJSON($value); } else { $destination[$key] = $value; } $destination[$key] = JsonKit::replaceObject($destination[$key]); } return $destination; }
[ "public", "function", "jsonSerialize", "(", ")", "{", "if", "(", "!", "Norm", "::", "options", "(", "'include'", ")", ")", "{", "return", "$", "this", "->", "toArray", "(", ")", ";", "}", "$", "destination", "=", "array", "(", ")", ";", "$", "source", "=", "$", "this", "->", "toArray", "(", ")", ";", "$", "schema", "=", "$", "this", "->", "collection", "->", "schema", "(", ")", ";", "foreach", "(", "$", "source", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "schema", "[", "$", "key", "]", ")", "and", "isset", "(", "$", "value", ")", ")", "{", "$", "destination", "[", "$", "key", "]", "=", "$", "schema", "[", "$", "key", "]", "->", "toJSON", "(", "$", "value", ")", ";", "}", "else", "{", "$", "destination", "[", "$", "key", "]", "=", "$", "value", ";", "}", "$", "destination", "[", "$", "key", "]", "=", "JsonKit", "::", "replaceObject", "(", "$", "destination", "[", "$", "key", "]", ")", ";", "}", "return", "$", "destination", ";", "}" ]
Implement the json serializer normalizing the data structures. @return array
[ "Implement", "the", "json", "serializer", "normalizing", "the", "data", "structures", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L448-L470
xinix-technology/norm
src/Norm/Model.php
Model.previous
public function previous($key = null) { if (is_null($key)) { return $this->oldAttributes; } return $this->oldAttributes[$key]; }
php
public function previous($key = null) { if (is_null($key)) { return $this->oldAttributes; } return $this->oldAttributes[$key]; }
[ "public", "function", "previous", "(", "$", "key", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "oldAttributes", ";", "}", "return", "$", "this", "->", "oldAttributes", "[", "$", "key", "]", ";", "}" ]
Get original attributes @method previous @param string $key @return mixed
[ "Get", "original", "attributes" ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L493-L500
xinix-technology/norm
src/Norm/Model.php
Model.schema
public function schema($key = null) { if (func_num_args() === 0) { return $this->collection->schema(); } else { return $this->collection->schema($key); } }
php
public function schema($key = null) { if (func_num_args() === 0) { return $this->collection->schema(); } else { return $this->collection->schema($key); } }
[ "public", "function", "schema", "(", "$", "key", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", "===", "0", ")", "{", "return", "$", "this", "->", "collection", "->", "schema", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "collection", "->", "schema", "(", "$", "key", ")", ";", "}", "}" ]
Get schema configuration. @method schema @param string $key @return mixed
[ "Get", "schema", "configuration", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L535-L542
xinix-technology/norm
src/Norm/Model.php
Model.schemaByIndex
public function schemaByIndex($index) { $schema = array(); foreach ($this->collection->schema() as $value) { $schema[] = $value; } return (empty($schema[$index])) ? null : $schema[$index]; }
php
public function schemaByIndex($index) { $schema = array(); foreach ($this->collection->schema() as $value) { $schema[] = $value; } return (empty($schema[$index])) ? null : $schema[$index]; }
[ "public", "function", "schemaByIndex", "(", "$", "index", ")", "{", "$", "schema", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "collection", "->", "schema", "(", ")", "as", "$", "value", ")", "{", "$", "schema", "[", "]", "=", "$", "value", ";", "}", "return", "(", "empty", "(", "$", "schema", "[", "$", "index", "]", ")", ")", "?", "null", ":", "$", "schema", "[", "$", "index", "]", ";", "}" ]
Get schema configuration by offset name. @method schemaByIndex @param string $index @return mixed
[ "Get", "schema", "configuration", "by", "offset", "name", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L553-L562
xinix-technology/norm
src/Norm/Model.php
Model.format
public function format($field = null, $format = null) { $numArgs = func_num_args(); if ($numArgs === 0) { $formatter = $this->collection->option('format'); if (is_null($formatter)) { $schema = $this->schemaByIndex(0); if (!is_null($schema)) { return (isset($this[$schema['name']])) ? val($this[$schema['name']]) : null; } else { return '-- no formatter and schema --'; } } else { if ($formatter instanceof Closure) { return $formatter($this); } elseif (is_string($formatter)) { $result = preg_replace_callback('/{(\w+)}/', function($matches) { return $this->format($matches[1]); }, $formatter); return $result; } else { throw new Exception('Unknown format for Model formatter.'); } } } else { $format = $format ?: 'plain'; $schema = $this->schema($field); // TODO return value if no formatter or just throw exception? if (is_null($schema)) { throw new Exception("[Norm/Model] No formatter [$format] for field [$field]."); } else { $value = isset($this[$field]) ? val($this[$field]) : null; return $schema->format($format, $value, $this); } } }
php
public function format($field = null, $format = null) { $numArgs = func_num_args(); if ($numArgs === 0) { $formatter = $this->collection->option('format'); if (is_null($formatter)) { $schema = $this->schemaByIndex(0); if (!is_null($schema)) { return (isset($this[$schema['name']])) ? val($this[$schema['name']]) : null; } else { return '-- no formatter and schema --'; } } else { if ($formatter instanceof Closure) { return $formatter($this); } elseif (is_string($formatter)) { $result = preg_replace_callback('/{(\w+)}/', function($matches) { return $this->format($matches[1]); }, $formatter); return $result; } else { throw new Exception('Unknown format for Model formatter.'); } } } else { $format = $format ?: 'plain'; $schema = $this->schema($field); // TODO return value if no formatter or just throw exception? if (is_null($schema)) { throw new Exception("[Norm/Model] No formatter [$format] for field [$field]."); } else { $value = isset($this[$field]) ? val($this[$field]) : null; return $schema->format($format, $value, $this); } } }
[ "public", "function", "format", "(", "$", "field", "=", "null", ",", "$", "format", "=", "null", ")", "{", "$", "numArgs", "=", "func_num_args", "(", ")", ";", "if", "(", "$", "numArgs", "===", "0", ")", "{", "$", "formatter", "=", "$", "this", "->", "collection", "->", "option", "(", "'format'", ")", ";", "if", "(", "is_null", "(", "$", "formatter", ")", ")", "{", "$", "schema", "=", "$", "this", "->", "schemaByIndex", "(", "0", ")", ";", "if", "(", "!", "is_null", "(", "$", "schema", ")", ")", "{", "return", "(", "isset", "(", "$", "this", "[", "$", "schema", "[", "'name'", "]", "]", ")", ")", "?", "val", "(", "$", "this", "[", "$", "schema", "[", "'name'", "]", "]", ")", ":", "null", ";", "}", "else", "{", "return", "'-- no formatter and schema --'", ";", "}", "}", "else", "{", "if", "(", "$", "formatter", "instanceof", "Closure", ")", "{", "return", "$", "formatter", "(", "$", "this", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "formatter", ")", ")", "{", "$", "result", "=", "preg_replace_callback", "(", "'/{(\\w+)}/'", ",", "function", "(", "$", "matches", ")", "{", "return", "$", "this", "->", "format", "(", "$", "matches", "[", "1", "]", ")", ";", "}", ",", "$", "formatter", ")", ";", "return", "$", "result", ";", "}", "else", "{", "throw", "new", "Exception", "(", "'Unknown format for Model formatter.'", ")", ";", "}", "}", "}", "else", "{", "$", "format", "=", "$", "format", "?", ":", "'plain'", ";", "$", "schema", "=", "$", "this", "->", "schema", "(", "$", "field", ")", ";", "// TODO return value if no formatter or just throw exception?", "if", "(", "is_null", "(", "$", "schema", ")", ")", "{", "throw", "new", "Exception", "(", "\"[Norm/Model] No formatter [$format] for field [$field].\"", ")", ";", "}", "else", "{", "$", "value", "=", "isset", "(", "$", "this", "[", "$", "field", "]", ")", "?", "val", "(", "$", "this", "[", "$", "field", "]", ")", ":", "null", ";", "return", "$", "schema", "->", "format", "(", "$", "format", ",", "$", "value", ",", "$", "this", ")", ";", "}", "}", "}" ]
Format the model to HTML file. Bind it's attributes to view. @method format @param string $field @param string $format @return mixed
[ "Format", "the", "model", "to", "HTML", "file", ".", "Bind", "it", "s", "attributes", "to", "view", "." ]
train
https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Model.php#L574-L615
anime-db/app-bundle
src/Command/ClearMediaTempCommand.php
ClearMediaTempCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $start = microtime(true); if (file_exists($dir = $this->getContainer()->getParameter('kernel.root_dir').'/../web/media/tmp/')) { $fs = new Filesystem(); $finder = new Finder(); $finder->in($dir)->date('< 1 hour ago')->ignoreUnreadableDirs(); /* @var $file \SplFileInfo */ foreach ($finder as $file) { $fs->remove($file->getRealPath()); } } $output->writeln('Time: <info>'.round((microtime(true) - $start) * 1000, 2).'</info> s.'); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $start = microtime(true); if (file_exists($dir = $this->getContainer()->getParameter('kernel.root_dir').'/../web/media/tmp/')) { $fs = new Filesystem(); $finder = new Finder(); $finder->in($dir)->date('< 1 hour ago')->ignoreUnreadableDirs(); /* @var $file \SplFileInfo */ foreach ($finder as $file) { $fs->remove($file->getRealPath()); } } $output->writeln('Time: <info>'.round((microtime(true) - $start) * 1000, 2).'</info> s.'); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "start", "=", "microtime", "(", "true", ")", ";", "if", "(", "file_exists", "(", "$", "dir", "=", "$", "this", "->", "getContainer", "(", ")", "->", "getParameter", "(", "'kernel.root_dir'", ")", ".", "'/../web/media/tmp/'", ")", ")", "{", "$", "fs", "=", "new", "Filesystem", "(", ")", ";", "$", "finder", "=", "new", "Finder", "(", ")", ";", "$", "finder", "->", "in", "(", "$", "dir", ")", "->", "date", "(", "'< 1 hour ago'", ")", "->", "ignoreUnreadableDirs", "(", ")", ";", "/* @var $file \\SplFileInfo */", "foreach", "(", "$", "finder", "as", "$", "file", ")", "{", "$", "fs", "->", "remove", "(", "$", "file", "->", "getRealPath", "(", ")", ")", ";", "}", "}", "$", "output", "->", "writeln", "(", "'Time: <info>'", ".", "round", "(", "(", "microtime", "(", "true", ")", "-", "$", "start", ")", "*", "1000", ",", "2", ")", ".", "'</info> s.'", ")", ";", "}" ]
@param InputInterface $input @param OutputInterface $output @return bool
[ "@param", "InputInterface", "$input", "@param", "OutputInterface", "$output" ]
train
https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Command/ClearMediaTempCommand.php#L34-L50
phpmob/changmin
src/PhpMob/MediaBundle/Twig/ImagineExtension.php
ImagineExtension.filter
public function filter($path, $sizing, $inset = true, $default = null) { if ($path instanceof ImageInterface) { $path = $path->getPath(); } if (empty($path) && $default) { return $default; } if (empty($path)) { return $this->defaultImage; } $runtimeConfig = [ 'thumbnail' => [ 'size' => explode('x', strtolower($sizing)), 'mode' => $inset ? 'inset' : 'outbound', ], ]; return $this->cacheManager->getBrowserPath($path, $this->filter, $runtimeConfig); }
php
public function filter($path, $sizing, $inset = true, $default = null) { if ($path instanceof ImageInterface) { $path = $path->getPath(); } if (empty($path) && $default) { return $default; } if (empty($path)) { return $this->defaultImage; } $runtimeConfig = [ 'thumbnail' => [ 'size' => explode('x', strtolower($sizing)), 'mode' => $inset ? 'inset' : 'outbound', ], ]; return $this->cacheManager->getBrowserPath($path, $this->filter, $runtimeConfig); }
[ "public", "function", "filter", "(", "$", "path", ",", "$", "sizing", ",", "$", "inset", "=", "true", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "path", "instanceof", "ImageInterface", ")", "{", "$", "path", "=", "$", "path", "->", "getPath", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "path", ")", "&&", "$", "default", ")", "{", "return", "$", "default", ";", "}", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "return", "$", "this", "->", "defaultImage", ";", "}", "$", "runtimeConfig", "=", "[", "'thumbnail'", "=>", "[", "'size'", "=>", "explode", "(", "'x'", ",", "strtolower", "(", "$", "sizing", ")", ")", ",", "'mode'", "=>", "$", "inset", "?", "'inset'", ":", "'outbound'", ",", "]", ",", "]", ";", "return", "$", "this", "->", "cacheManager", "->", "getBrowserPath", "(", "$", "path", ",", "$", "this", "->", "filter", ",", "$", "runtimeConfig", ")", ";", "}" ]
@param string|ImageInterface $path @param $sizing @param bool $inset @param string $default = null @return string
[ "@param", "string|ImageInterface", "$path", "@param", "$sizing", "@param", "bool", "$inset", "@param", "string", "$default", "=", "null" ]
train
https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/MediaBundle/Twig/ImagineExtension.php#L64-L86
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia.endToolbar
public function endToolbar() { $this->_setBeginning(false); $toolbar = trim(ob_get_clean()); if (is_string($this->toolbar)) { $this->toolbar = [$this->toolbar]; } $this->toolbar[] = [ 'body' => $toolbar, 'options' => $this->_toolbarLastOptions, ]; $this->_toolbarLastOptions = []; }
php
public function endToolbar() { $this->_setBeginning(false); $toolbar = trim(ob_get_clean()); if (is_string($this->toolbar)) { $this->toolbar = [$this->toolbar]; } $this->toolbar[] = [ 'body' => $toolbar, 'options' => $this->_toolbarLastOptions, ]; $this->_toolbarLastOptions = []; }
[ "public", "function", "endToolbar", "(", ")", "{", "$", "this", "->", "_setBeginning", "(", "false", ")", ";", "$", "toolbar", "=", "trim", "(", "ob_get_clean", "(", ")", ")", ";", "if", "(", "is_string", "(", "$", "this", "->", "toolbar", ")", ")", "{", "$", "this", "->", "toolbar", "=", "[", "$", "this", "->", "toolbar", "]", ";", "}", "$", "this", "->", "toolbar", "[", "]", "=", "[", "'body'", "=>", "$", "toolbar", ",", "'options'", "=>", "$", "this", "->", "_toolbarLastOptions", ",", "]", ";", "$", "this", "->", "_toolbarLastOptions", "=", "[", "]", ";", "}" ]
End toolbar @throws Exception
[ "End", "toolbar" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L140-L152
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia.endBodyToolbar
public function endBodyToolbar() { $this->_setBeginning(false); $toolbar = trim(ob_get_clean()); if (is_string($this->bodyToolbar)) { $this->bodyToolbar = [$this->bodyToolbar]; } $this->bodyToolbar[] = [ 'body' => $toolbar, 'options' => $this->_bodyToolbarLastOptions, ]; $this->_bodyToolbarLastOptions = []; }
php
public function endBodyToolbar() { $this->_setBeginning(false); $toolbar = trim(ob_get_clean()); if (is_string($this->bodyToolbar)) { $this->bodyToolbar = [$this->bodyToolbar]; } $this->bodyToolbar[] = [ 'body' => $toolbar, 'options' => $this->_bodyToolbarLastOptions, ]; $this->_bodyToolbarLastOptions = []; }
[ "public", "function", "endBodyToolbar", "(", ")", "{", "$", "this", "->", "_setBeginning", "(", "false", ")", ";", "$", "toolbar", "=", "trim", "(", "ob_get_clean", "(", ")", ")", ";", "if", "(", "is_string", "(", "$", "this", "->", "bodyToolbar", ")", ")", "{", "$", "this", "->", "bodyToolbar", "=", "[", "$", "this", "->", "bodyToolbar", "]", ";", "}", "$", "this", "->", "bodyToolbar", "[", "]", "=", "[", "'body'", "=>", "$", "toolbar", ",", "'options'", "=>", "$", "this", "->", "_bodyToolbarLastOptions", ",", "]", ";", "$", "this", "->", "_bodyToolbarLastOptions", "=", "[", "]", ";", "}" ]
End Body Toolbar @throws Exception
[ "End", "Body", "Toolbar" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L196-L208
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia.beginFooter
public function beginFooter($options = []) { $this->_setBeginning(true); $this->footerOptions = ArrayHelper::merge($this->footerOptions, $options); ob_start(); }
php
public function beginFooter($options = []) { $this->_setBeginning(true); $this->footerOptions = ArrayHelper::merge($this->footerOptions, $options); ob_start(); }
[ "public", "function", "beginFooter", "(", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "_setBeginning", "(", "true", ")", ";", "$", "this", "->", "footerOptions", "=", "ArrayHelper", "::", "merge", "(", "$", "this", "->", "footerOptions", ",", "$", "options", ")", ";", "ob_start", "(", ")", ";", "}" ]
Begin Footer [[beginFooter]] your data [[endFooter]] @param array $options @throws Exception
[ "Begin", "Footer", "[[", "beginFooter", "]]", "your", "data", "[[", "endFooter", "]]" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L218-L223
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia._getToolbar
private function _getToolbar() { if ($this->toolbar !== null) { Html::addCssClass($this->toolbarOptions, 'widget-toolbar'); $toolbars = is_string($this->toolbar) ? [$this->toolbar] : $this->toolbar; foreach ($toolbars as $toolbar) { if (is_array($toolbar)) { $body = isset($toolbar['body']) ? $toolbar['body'] : null; $options = isset($toolbar['options']) ? $toolbar['options'] : []; Html::addCssClass($options, 'widget-toolbar'); echo Html::tag('div', $body, $options); } else { echo Html::tag('div', $toolbar, $this->toolbarOptions); } } } }
php
private function _getToolbar() { if ($this->toolbar !== null) { Html::addCssClass($this->toolbarOptions, 'widget-toolbar'); $toolbars = is_string($this->toolbar) ? [$this->toolbar] : $this->toolbar; foreach ($toolbars as $toolbar) { if (is_array($toolbar)) { $body = isset($toolbar['body']) ? $toolbar['body'] : null; $options = isset($toolbar['options']) ? $toolbar['options'] : []; Html::addCssClass($options, 'widget-toolbar'); echo Html::tag('div', $body, $options); } else { echo Html::tag('div', $toolbar, $this->toolbarOptions); } } } }
[ "private", "function", "_getToolbar", "(", ")", "{", "if", "(", "$", "this", "->", "toolbar", "!==", "null", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "toolbarOptions", ",", "'widget-toolbar'", ")", ";", "$", "toolbars", "=", "is_string", "(", "$", "this", "->", "toolbar", ")", "?", "[", "$", "this", "->", "toolbar", "]", ":", "$", "this", "->", "toolbar", ";", "foreach", "(", "$", "toolbars", "as", "$", "toolbar", ")", "{", "if", "(", "is_array", "(", "$", "toolbar", ")", ")", "{", "$", "body", "=", "isset", "(", "$", "toolbar", "[", "'body'", "]", ")", "?", "$", "toolbar", "[", "'body'", "]", ":", "null", ";", "$", "options", "=", "isset", "(", "$", "toolbar", "[", "'options'", "]", ")", "?", "$", "toolbar", "[", "'options'", "]", ":", "[", "]", ";", "Html", "::", "addCssClass", "(", "$", "options", ",", "'widget-toolbar'", ")", ";", "echo", "Html", "::", "tag", "(", "'div'", ",", "$", "body", ",", "$", "options", ")", ";", "}", "else", "{", "echo", "Html", "::", "tag", "(", "'div'", ",", "$", "toolbar", ",", "$", "this", "->", "toolbarOptions", ")", ";", "}", "}", "}", "}" ]
Get toolbar
[ "Get", "toolbar" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L238-L254
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia._getBodyToolbar
private function _getBodyToolbar() { if ($this->bodyToolbar !== null) { Html::addCssClass($this->bodyToolbarOptions, 'widget-body-toolbar'); $toolbars = is_string($this->bodyToolbar) ? [$this->bodyToolbar] : $this->bodyToolbar; foreach ($toolbars as $toolbar) { if (is_array($toolbar)) { $body = isset($toolbar['body']) ? $toolbar['body'] : null; $options = isset($toolbar['options']) ? $toolbar['options'] : []; Html::addCssClass($options, 'widget-body-toolbar'); echo Html::tag('div', $body, $options); } else { echo Html::tag('div', $toolbar, $this->bodyToolbarOptions); } } } }
php
private function _getBodyToolbar() { if ($this->bodyToolbar !== null) { Html::addCssClass($this->bodyToolbarOptions, 'widget-body-toolbar'); $toolbars = is_string($this->bodyToolbar) ? [$this->bodyToolbar] : $this->bodyToolbar; foreach ($toolbars as $toolbar) { if (is_array($toolbar)) { $body = isset($toolbar['body']) ? $toolbar['body'] : null; $options = isset($toolbar['options']) ? $toolbar['options'] : []; Html::addCssClass($options, 'widget-body-toolbar'); echo Html::tag('div', $body, $options); } else { echo Html::tag('div', $toolbar, $this->bodyToolbarOptions); } } } }
[ "private", "function", "_getBodyToolbar", "(", ")", "{", "if", "(", "$", "this", "->", "bodyToolbar", "!==", "null", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "bodyToolbarOptions", ",", "'widget-body-toolbar'", ")", ";", "$", "toolbars", "=", "is_string", "(", "$", "this", "->", "bodyToolbar", ")", "?", "[", "$", "this", "->", "bodyToolbar", "]", ":", "$", "this", "->", "bodyToolbar", ";", "foreach", "(", "$", "toolbars", "as", "$", "toolbar", ")", "{", "if", "(", "is_array", "(", "$", "toolbar", ")", ")", "{", "$", "body", "=", "isset", "(", "$", "toolbar", "[", "'body'", "]", ")", "?", "$", "toolbar", "[", "'body'", "]", ":", "null", ";", "$", "options", "=", "isset", "(", "$", "toolbar", "[", "'options'", "]", ")", "?", "$", "toolbar", "[", "'options'", "]", ":", "[", "]", ";", "Html", "::", "addCssClass", "(", "$", "options", ",", "'widget-body-toolbar'", ")", ";", "echo", "Html", "::", "tag", "(", "'div'", ",", "$", "body", ",", "$", "options", ")", ";", "}", "else", "{", "echo", "Html", "::", "tag", "(", "'div'", ",", "$", "toolbar", ",", "$", "this", "->", "bodyToolbarOptions", ")", ";", "}", "}", "}", "}" ]
Get body toolbar
[ "Get", "body", "toolbar" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L259-L275
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia._getFooter
private function _getFooter() { if ($this->footer !== null) { Html::addCssClass($this->footerOptions, 'ibox-footer'); $footers = is_string($this->footer) ? [$this->footer] : $this->footer; foreach ($footers as $footer) { if (is_array($footer)) { $body = isset($footer['body']) ? $footer['body'] : null; $options = isset($footer['options']) ? $footer['options'] : []; echo Html::tag('div', $body, $options); } else { echo Html::tag('div', $footer, $this->footerOptions); } } } }
php
private function _getFooter() { if ($this->footer !== null) { Html::addCssClass($this->footerOptions, 'ibox-footer'); $footers = is_string($this->footer) ? [$this->footer] : $this->footer; foreach ($footers as $footer) { if (is_array($footer)) { $body = isset($footer['body']) ? $footer['body'] : null; $options = isset($footer['options']) ? $footer['options'] : []; echo Html::tag('div', $body, $options); } else { echo Html::tag('div', $footer, $this->footerOptions); } } } }
[ "private", "function", "_getFooter", "(", ")", "{", "if", "(", "$", "this", "->", "footer", "!==", "null", ")", "{", "Html", "::", "addCssClass", "(", "$", "this", "->", "footerOptions", ",", "'ibox-footer'", ")", ";", "$", "footers", "=", "is_string", "(", "$", "this", "->", "footer", ")", "?", "[", "$", "this", "->", "footer", "]", ":", "$", "this", "->", "footer", ";", "foreach", "(", "$", "footers", "as", "$", "footer", ")", "{", "if", "(", "is_array", "(", "$", "footer", ")", ")", "{", "$", "body", "=", "isset", "(", "$", "footer", "[", "'body'", "]", ")", "?", "$", "footer", "[", "'body'", "]", ":", "null", ";", "$", "options", "=", "isset", "(", "$", "footer", "[", "'options'", "]", ")", "?", "$", "footer", "[", "'options'", "]", ":", "[", "]", ";", "echo", "Html", "::", "tag", "(", "'div'", ",", "$", "body", ",", "$", "options", ")", ";", "}", "else", "{", "echo", "Html", "::", "tag", "(", "'div'", ",", "$", "footer", ",", "$", "this", "->", "footerOptions", ")", ";", "}", "}", "}", "}" ]
Get footer
[ "Get", "footer" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L280-L295
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia._setLoad
private function _setLoad() { if ($this->load !== null && !array_key_exists('data-widget-load', $this->options)) { $this->options['data-widget-load'] = Url::to($this->load); } }
php
private function _setLoad() { if ($this->load !== null && !array_key_exists('data-widget-load', $this->options)) { $this->options['data-widget-load'] = Url::to($this->load); } }
[ "private", "function", "_setLoad", "(", ")", "{", "if", "(", "$", "this", "->", "load", "!==", "null", "&&", "!", "array_key_exists", "(", "'data-widget-load'", ",", "$", "this", "->", "options", ")", ")", "{", "$", "this", "->", "options", "[", "'data-widget-load'", "]", "=", "Url", "::", "to", "(", "$", "this", "->", "load", ")", ";", "}", "}" ]
Set load
[ "Set", "load" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L310-L315
yuncms/framework
src/admin/widgets/Inspinia.php
Inspinia._setBeginning
private function _setBeginning($bool) { if (!is_bool($bool)) { throw new Exception('$bool in not boolean'); } if ($this->_beginning === $bool) { throw new Exception("Error begin or end."); } $this->_beginning = $bool; }
php
private function _setBeginning($bool) { if (!is_bool($bool)) { throw new Exception('$bool in not boolean'); } if ($this->_beginning === $bool) { throw new Exception("Error begin or end."); } $this->_beginning = $bool; }
[ "private", "function", "_setBeginning", "(", "$", "bool", ")", "{", "if", "(", "!", "is_bool", "(", "$", "bool", ")", ")", "{", "throw", "new", "Exception", "(", "'$bool in not boolean'", ")", ";", "}", "if", "(", "$", "this", "->", "_beginning", "===", "$", "bool", ")", "{", "throw", "new", "Exception", "(", "\"Error begin or end.\"", ")", ";", "}", "$", "this", "->", "_beginning", "=", "$", "bool", ";", "}" ]
设置开始 @param $bool @throws Exception
[ "设置开始" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/widgets/Inspinia.php#L338-L347
activecollab/configfile
src/ConfigFile.php
ConfigFile.fileWithConstantsToArray
private function fileWithConstantsToArray($file_path) { $result = []; $lines = file($file_path); if (is_array($lines)) { foreach ($lines as $line) { $line = trim(trim($line, '<?php')); if ($this->strStartsWith($line, 'const ')) { list ($constant_name, $value) = $this->getFromConst($line); $result[$constant_name] = $value; } else { if ($this->strContains($line, 'define')) { foreach ($this->getFromDefine($line) as $option) { list ($constant_name, $value) = $option; $result[$constant_name] = $value; } } } } } return $result; }
php
private function fileWithConstantsToArray($file_path) { $result = []; $lines = file($file_path); if (is_array($lines)) { foreach ($lines as $line) { $line = trim(trim($line, '<?php')); if ($this->strStartsWith($line, 'const ')) { list ($constant_name, $value) = $this->getFromConst($line); $result[$constant_name] = $value; } else { if ($this->strContains($line, 'define')) { foreach ($this->getFromDefine($line) as $option) { list ($constant_name, $value) = $option; $result[$constant_name] = $value; } } } } } return $result; }
[ "private", "function", "fileWithConstantsToArray", "(", "$", "file_path", ")", "{", "$", "result", "=", "[", "]", ";", "$", "lines", "=", "file", "(", "$", "file_path", ")", ";", "if", "(", "is_array", "(", "$", "lines", ")", ")", "{", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "trim", "(", "$", "line", ",", "'<?php'", ")", ")", ";", "if", "(", "$", "this", "->", "strStartsWith", "(", "$", "line", ",", "'const '", ")", ")", "{", "list", "(", "$", "constant_name", ",", "$", "value", ")", "=", "$", "this", "->", "getFromConst", "(", "$", "line", ")", ";", "$", "result", "[", "$", "constant_name", "]", "=", "$", "value", ";", "}", "else", "{", "if", "(", "$", "this", "->", "strContains", "(", "$", "line", ",", "'define'", ")", ")", "{", "foreach", "(", "$", "this", "->", "getFromDefine", "(", "$", "line", ")", "as", "$", "option", ")", "{", "list", "(", "$", "constant_name", ",", "$", "value", ")", "=", "$", "option", ";", "$", "result", "[", "$", "constant_name", "]", "=", "$", "value", ";", "}", "}", "}", "}", "}", "return", "$", "result", ";", "}" ]
Get constants from the given PHP file (these constants need to be defined with const keyword) @param string $file_path @return array
[ "Get", "constants", "from", "the", "given", "PHP", "file", "(", "these", "constants", "need", "to", "be", "defined", "with", "const", "keyword", ")" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L78-L105
activecollab/configfile
src/ConfigFile.php
ConfigFile.getFromConst
private function getFromConst($line) { $eq_pos = strpos($line, '='); $semicolon_pos = strrpos($line, ';'); $constant_name = trim(substr($line, 6, $eq_pos - 6)); $value = trim(substr($line, $eq_pos + 1, $semicolon_pos - $eq_pos - 1)); return [$constant_name, $this->getNativeValueFromDefinition($value)]; }
php
private function getFromConst($line) { $eq_pos = strpos($line, '='); $semicolon_pos = strrpos($line, ';'); $constant_name = trim(substr($line, 6, $eq_pos - 6)); $value = trim(substr($line, $eq_pos + 1, $semicolon_pos - $eq_pos - 1)); return [$constant_name, $this->getNativeValueFromDefinition($value)]; }
[ "private", "function", "getFromConst", "(", "$", "line", ")", "{", "$", "eq_pos", "=", "strpos", "(", "$", "line", ",", "'='", ")", ";", "$", "semicolon_pos", "=", "strrpos", "(", "$", "line", ",", "';'", ")", ";", "$", "constant_name", "=", "trim", "(", "substr", "(", "$", "line", ",", "6", ",", "$", "eq_pos", "-", "6", ")", ")", ";", "$", "value", "=", "trim", "(", "substr", "(", "$", "line", ",", "$", "eq_pos", "+", "1", ",", "$", "semicolon_pos", "-", "$", "eq_pos", "-", "1", ")", ")", ";", "return", "[", "$", "constant_name", ",", "$", "this", "->", "getNativeValueFromDefinition", "(", "$", "value", ")", "]", ";", "}" ]
Return single option from const DB_XYZ defition line @param string $line @return string
[ "Return", "single", "option", "from", "const", "DB_XYZ", "defition", "line" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L113-L122
activecollab/configfile
src/ConfigFile.php
ConfigFile.getFromDefine
function getFromDefine($line) { $line = "<?php $line"; // Trick the parser that we are in PHP file, instead of analyzing a single line $state = 0; $key = $value = ''; $tokens = token_get_all($line); $token = reset($tokens); while ($token) { if (is_array($token)) { if ($token[0] == T_WHITESPACE || $token[0] == T_COMMENT || $token[0] == T_DOC_COMMENT) { // do nothing } else { if ($token[0] == T_STRING && strtolower($token[1]) == 'define') { $state = 1; } else { if ($state == 2 && $this->isConstantToken($token[0])) { $key = $token[1]; $state = 3; } else { if ($state == 4 && $this->isConstantToken($token[0])) { $value = $token[1]; $state = 5; } } } } } else { $symbol = trim($token); if ($symbol == '(' && $state == 1) { $state = 2; } else { if ($symbol == ',' && $state == 3) { $state = 4; } else { if ($symbol == ')' && $state == 5) { $state = 0; yield [$this->stripQuotes($key), $this->getNativeValueFromDefinition($value)]; } } } } $token = next($tokens); } }
php
function getFromDefine($line) { $line = "<?php $line"; // Trick the parser that we are in PHP file, instead of analyzing a single line $state = 0; $key = $value = ''; $tokens = token_get_all($line); $token = reset($tokens); while ($token) { if (is_array($token)) { if ($token[0] == T_WHITESPACE || $token[0] == T_COMMENT || $token[0] == T_DOC_COMMENT) { // do nothing } else { if ($token[0] == T_STRING && strtolower($token[1]) == 'define') { $state = 1; } else { if ($state == 2 && $this->isConstantToken($token[0])) { $key = $token[1]; $state = 3; } else { if ($state == 4 && $this->isConstantToken($token[0])) { $value = $token[1]; $state = 5; } } } } } else { $symbol = trim($token); if ($symbol == '(' && $state == 1) { $state = 2; } else { if ($symbol == ',' && $state == 3) { $state = 4; } else { if ($symbol == ')' && $state == 5) { $state = 0; yield [$this->stripQuotes($key), $this->getNativeValueFromDefinition($value)]; } } } } $token = next($tokens); } }
[ "function", "getFromDefine", "(", "$", "line", ")", "{", "$", "line", "=", "\"<?php $line\"", ";", "// Trick the parser that we are in PHP file, instead of analyzing a single line", "$", "state", "=", "0", ";", "$", "key", "=", "$", "value", "=", "''", ";", "$", "tokens", "=", "token_get_all", "(", "$", "line", ")", ";", "$", "token", "=", "reset", "(", "$", "tokens", ")", ";", "while", "(", "$", "token", ")", "{", "if", "(", "is_array", "(", "$", "token", ")", ")", "{", "if", "(", "$", "token", "[", "0", "]", "==", "T_WHITESPACE", "||", "$", "token", "[", "0", "]", "==", "T_COMMENT", "||", "$", "token", "[", "0", "]", "==", "T_DOC_COMMENT", ")", "{", "// do nothing", "}", "else", "{", "if", "(", "$", "token", "[", "0", "]", "==", "T_STRING", "&&", "strtolower", "(", "$", "token", "[", "1", "]", ")", "==", "'define'", ")", "{", "$", "state", "=", "1", ";", "}", "else", "{", "if", "(", "$", "state", "==", "2", "&&", "$", "this", "->", "isConstantToken", "(", "$", "token", "[", "0", "]", ")", ")", "{", "$", "key", "=", "$", "token", "[", "1", "]", ";", "$", "state", "=", "3", ";", "}", "else", "{", "if", "(", "$", "state", "==", "4", "&&", "$", "this", "->", "isConstantToken", "(", "$", "token", "[", "0", "]", ")", ")", "{", "$", "value", "=", "$", "token", "[", "1", "]", ";", "$", "state", "=", "5", ";", "}", "}", "}", "}", "}", "else", "{", "$", "symbol", "=", "trim", "(", "$", "token", ")", ";", "if", "(", "$", "symbol", "==", "'('", "&&", "$", "state", "==", "1", ")", "{", "$", "state", "=", "2", ";", "}", "else", "{", "if", "(", "$", "symbol", "==", "','", "&&", "$", "state", "==", "3", ")", "{", "$", "state", "=", "4", ";", "}", "else", "{", "if", "(", "$", "symbol", "==", "')'", "&&", "$", "state", "==", "5", ")", "{", "$", "state", "=", "0", ";", "yield", "[", "$", "this", "->", "stripQuotes", "(", "$", "key", ")", ",", "$", "this", "->", "getNativeValueFromDefinition", "(", "$", "value", ")", "]", ";", "}", "}", "}", "}", "$", "token", "=", "next", "(", "$", "tokens", ")", ";", "}", "}" ]
Return single option from define('DB_XYZ', value) defition line Adopted from: http://stackoverflow.com/questions/645862/regex-to-parse-define-contents-possible @param string $line @return array
[ "Return", "single", "option", "from", "define", "(", "DB_XYZ", "value", ")", "defition", "line" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L134-L181
activecollab/configfile
src/ConfigFile.php
ConfigFile.getOptionNameFromDefinition
public function getOptionNameFromDefinition($constant_name) { if ($this->strStartsWith($constant_name, "'") && $this->strEndsWith($constant_name, "'")) { return trim(trim($constant_name, "'")); // single quote } else { if ($this->strStartsWith($constant_name, '"') && $this->strEndsWith($constant_name, '"')) { return trim(trim($constant_name, '"')); // double quote } else { return $constant_name; } } }
php
public function getOptionNameFromDefinition($constant_name) { if ($this->strStartsWith($constant_name, "'") && $this->strEndsWith($constant_name, "'")) { return trim(trim($constant_name, "'")); // single quote } else { if ($this->strStartsWith($constant_name, '"') && $this->strEndsWith($constant_name, '"')) { return trim(trim($constant_name, '"')); // double quote } else { return $constant_name; } } }
[ "public", "function", "getOptionNameFromDefinition", "(", "$", "constant_name", ")", "{", "if", "(", "$", "this", "->", "strStartsWith", "(", "$", "constant_name", ",", "\"'\"", ")", "&&", "$", "this", "->", "strEndsWith", "(", "$", "constant_name", ",", "\"'\"", ")", ")", "{", "return", "trim", "(", "trim", "(", "$", "constant_name", ",", "\"'\"", ")", ")", ";", "// single quote", "}", "else", "{", "if", "(", "$", "this", "->", "strStartsWith", "(", "$", "constant_name", ",", "'\"'", ")", "&&", "$", "this", "->", "strEndsWith", "(", "$", "constant_name", ",", "'\"'", ")", ")", "{", "return", "trim", "(", "trim", "(", "$", "constant_name", ",", "'\"'", ")", ")", ";", "// double quote", "}", "else", "{", "return", "$", "constant_name", ";", "}", "}", "}" ]
Return config option name from defintiion string @param string $constant_name @return string
[ "Return", "config", "option", "name", "from", "defintiion", "string" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L189-L200
activecollab/configfile
src/ConfigFile.php
ConfigFile.getNativeValueFromDefinition
private function getNativeValueFromDefinition($value) { if ($this->strStartsWith($value, "'") && $this->strEndsWith($value, "'")) { $value = trim(trim($value, "'")); // single quote } else { if ($this->strStartsWith($value, '"') && $this->strEndsWith($value, '"')) { $value = trim(trim($value, '"')); // double quote } else { if ($value == 'true') { $value = true; } else { if ($value == 'false') { $value = false; } else { if (is_numeric($value)) { if (ctype_digit($value)) { return (integer)$value; } else { return (float)$value; } } } } } } return $value; }
php
private function getNativeValueFromDefinition($value) { if ($this->strStartsWith($value, "'") && $this->strEndsWith($value, "'")) { $value = trim(trim($value, "'")); // single quote } else { if ($this->strStartsWith($value, '"') && $this->strEndsWith($value, '"')) { $value = trim(trim($value, '"')); // double quote } else { if ($value == 'true') { $value = true; } else { if ($value == 'false') { $value = false; } else { if (is_numeric($value)) { if (ctype_digit($value)) { return (integer)$value; } else { return (float)$value; } } } } } } return $value; }
[ "private", "function", "getNativeValueFromDefinition", "(", "$", "value", ")", "{", "if", "(", "$", "this", "->", "strStartsWith", "(", "$", "value", ",", "\"'\"", ")", "&&", "$", "this", "->", "strEndsWith", "(", "$", "value", ",", "\"'\"", ")", ")", "{", "$", "value", "=", "trim", "(", "trim", "(", "$", "value", ",", "\"'\"", ")", ")", ";", "// single quote", "}", "else", "{", "if", "(", "$", "this", "->", "strStartsWith", "(", "$", "value", ",", "'\"'", ")", "&&", "$", "this", "->", "strEndsWith", "(", "$", "value", ",", "'\"'", ")", ")", "{", "$", "value", "=", "trim", "(", "trim", "(", "$", "value", ",", "'\"'", ")", ")", ";", "// double quote", "}", "else", "{", "if", "(", "$", "value", "==", "'true'", ")", "{", "$", "value", "=", "true", ";", "}", "else", "{", "if", "(", "$", "value", "==", "'false'", ")", "{", "$", "value", "=", "false", ";", "}", "else", "{", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "if", "(", "ctype_digit", "(", "$", "value", ")", ")", "{", "return", "(", "integer", ")", "$", "value", ";", "}", "else", "{", "return", "(", "float", ")", "$", "value", ";", "}", "}", "}", "}", "}", "}", "return", "$", "value", ";", "}" ]
Cast declared value to internal type @param string $value @return mixed
[ "Cast", "declared", "value", "to", "internal", "type" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L208-L235
activecollab/configfile
src/ConfigFile.php
ConfigFile.isConstantToken
private function isConstantToken($token) { return $token == T_CONSTANT_ENCAPSED_STRING || $token == T_STRING || $token == T_LNUMBER || $token == T_DNUMBER; }
php
private function isConstantToken($token) { return $token == T_CONSTANT_ENCAPSED_STRING || $token == T_STRING || $token == T_LNUMBER || $token == T_DNUMBER; }
[ "private", "function", "isConstantToken", "(", "$", "token", ")", "{", "return", "$", "token", "==", "T_CONSTANT_ENCAPSED_STRING", "||", "$", "token", "==", "T_STRING", "||", "$", "token", "==", "T_LNUMBER", "||", "$", "token", "==", "T_DNUMBER", ";", "}" ]
Return true if $token is constant token @param string $token @return bool
[ "Return", "true", "if", "$token", "is", "constant", "token" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L243-L246
activecollab/configfile
src/ConfigFile.php
ConfigFile.strStartsWith
private function strStartsWith($string, $niddle) { return mb_strtolower(substr($string, 0, mb_strlen($niddle))) == mb_strtolower($niddle); }
php
private function strStartsWith($string, $niddle) { return mb_strtolower(substr($string, 0, mb_strlen($niddle))) == mb_strtolower($niddle); }
[ "private", "function", "strStartsWith", "(", "$", "string", ",", "$", "niddle", ")", "{", "return", "mb_strtolower", "(", "substr", "(", "$", "string", ",", "0", ",", "mb_strlen", "(", "$", "niddle", ")", ")", ")", "==", "mb_strtolower", "(", "$", "niddle", ")", ";", "}" ]
Case insensitive string begins with @param string $string @param string $niddle @return boolean
[ "Case", "insensitive", "string", "begins", "with" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L266-L269
activecollab/configfile
src/ConfigFile.php
ConfigFile.strEndsWith
private function strEndsWith($string, $niddle) { return mb_substr($string, mb_strlen($string) - mb_strlen($niddle), mb_strlen($niddle)) == $niddle; }
php
private function strEndsWith($string, $niddle) { return mb_substr($string, mb_strlen($string) - mb_strlen($niddle), mb_strlen($niddle)) == $niddle; }
[ "private", "function", "strEndsWith", "(", "$", "string", ",", "$", "niddle", ")", "{", "return", "mb_substr", "(", "$", "string", ",", "mb_strlen", "(", "$", "string", ")", "-", "mb_strlen", "(", "$", "niddle", ")", ",", "mb_strlen", "(", "$", "niddle", ")", ")", "==", "$", "niddle", ";", "}" ]
Case insensitive string ends with @param string $string @param string $niddle @return boolean
[ "Case", "insensitive", "string", "ends", "with" ]
train
https://github.com/activecollab/configfile/blob/fe0ae7da3466f26e49e54b6dd3508c85421c0bdf/src/ConfigFile.php#L290-L293
2amigos/yiifoundation
helpers/Typo.php
Typo.vCard
public static function vCard($name, $address = '', $locality = '', $state = '', $zip = '', $email = '') { $items = array(); $items[] = \CHtml::tag('li', array('class' => 'fn'), $name); $items[] = \CHtml::tag('li', array('class' => 'street-address'), $address); $items[] = \CHtml::tag('li', array('class' => 'locality'), $locality); $sub = array(); $sub[] = \CHtml::tag('span', array('class' => 'state'), $state); $sub[] = \CHtml::tag('span', array('class' => 'zip'), $zip); $items[] = \CHtml::tag('li', array(), implode(", ", $sub)); $items[] = \CHtml::tag('li', array('class' => 'email'), $email); return \CHtml::tag('ul', array('class' => 'vcard'), implode("\n", $items)); }
php
public static function vCard($name, $address = '', $locality = '', $state = '', $zip = '', $email = '') { $items = array(); $items[] = \CHtml::tag('li', array('class' => 'fn'), $name); $items[] = \CHtml::tag('li', array('class' => 'street-address'), $address); $items[] = \CHtml::tag('li', array('class' => 'locality'), $locality); $sub = array(); $sub[] = \CHtml::tag('span', array('class' => 'state'), $state); $sub[] = \CHtml::tag('span', array('class' => 'zip'), $zip); $items[] = \CHtml::tag('li', array(), implode(", ", $sub)); $items[] = \CHtml::tag('li', array('class' => 'email'), $email); return \CHtml::tag('ul', array('class' => 'vcard'), implode("\n", $items)); }
[ "public", "static", "function", "vCard", "(", "$", "name", ",", "$", "address", "=", "''", ",", "$", "locality", "=", "''", ",", "$", "state", "=", "''", ",", "$", "zip", "=", "''", ",", "$", "email", "=", "''", ")", "{", "$", "items", "=", "array", "(", ")", ";", "$", "items", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'li'", ",", "array", "(", "'class'", "=>", "'fn'", ")", ",", "$", "name", ")", ";", "$", "items", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'li'", ",", "array", "(", "'class'", "=>", "'street-address'", ")", ",", "$", "address", ")", ";", "$", "items", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'li'", ",", "array", "(", "'class'", "=>", "'locality'", ")", ",", "$", "locality", ")", ";", "$", "sub", "=", "array", "(", ")", ";", "$", "sub", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'span'", ",", "array", "(", "'class'", "=>", "'state'", ")", ",", "$", "state", ")", ";", "$", "sub", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'span'", ",", "array", "(", "'class'", "=>", "'zip'", ")", ",", "$", "zip", ")", ";", "$", "items", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'li'", ",", "array", "(", ")", ",", "implode", "(", "\", \"", ",", "$", "sub", ")", ")", ";", "$", "items", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'li'", ",", "array", "(", "'class'", "=>", "'email'", ")", ",", "$", "email", ")", ";", "return", "\\", "CHtml", "::", "tag", "(", "'ul'", ",", "array", "(", "'class'", "=>", "'vcard'", ")", ",", "implode", "(", "\"\\n\"", ",", "$", "items", ")", ")", ";", "}" ]
Renders a handy microformat-friendly list for addresses @param string $name @param string $address @param string $locality @param string $state @param string $zip @param string $email @return string the generated vcard
[ "Renders", "a", "handy", "microformat", "-", "friendly", "list", "for", "addresses" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Typo.php#L64-L77
2amigos/yiifoundation
helpers/Typo.php
Typo.inlineList
public static function inlineList($items, $htmlOptions = array()) { $listItems = array(); Html::addCssClass($htmlOptions, 'inline-list'); foreach ($items as $item) { $listItems[] = \CHtml::tag('li', $htmlOptions, $item); } if (!empty($listItems)) { return \CHtml::tag('ul', $htmlOptions, implode("\n", $listItems)); } }
php
public static function inlineList($items, $htmlOptions = array()) { $listItems = array(); Html::addCssClass($htmlOptions, 'inline-list'); foreach ($items as $item) { $listItems[] = \CHtml::tag('li', $htmlOptions, $item); } if (!empty($listItems)) { return \CHtml::tag('ul', $htmlOptions, implode("\n", $listItems)); } }
[ "public", "static", "function", "inlineList", "(", "$", "items", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "$", "listItems", "=", "array", "(", ")", ";", "Html", "::", "addCssClass", "(", "$", "htmlOptions", ",", "'inline-list'", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "listItems", "[", "]", "=", "\\", "CHtml", "::", "tag", "(", "'li'", ",", "$", "htmlOptions", ",", "$", "item", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "listItems", ")", ")", "{", "return", "\\", "CHtml", "::", "tag", "(", "'ul'", ",", "$", "htmlOptions", ",", "implode", "(", "\"\\n\"", ",", "$", "listItems", ")", ")", ";", "}", "}" ]
Renders and inline list @param array $items the items to render @param array $htmlOptions the HTML attributes @return string the generated list
[ "Renders", "and", "inline", "list" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Typo.php#L85-L96
2amigos/yiifoundation
helpers/Typo.php
Typo.label
public static function label($text, $htmlOptions = array()) { ArrayHelper::addValue('class', 'label', $htmlOptions); return \CHtml::tag('span', $htmlOptions, $text); }
php
public static function label($text, $htmlOptions = array()) { ArrayHelper::addValue('class', 'label', $htmlOptions); return \CHtml::tag('span', $htmlOptions, $text); }
[ "public", "static", "function", "label", "(", "$", "text", ",", "$", "htmlOptions", "=", "array", "(", ")", ")", "{", "ArrayHelper", "::", "addValue", "(", "'class'", ",", "'label'", ",", "$", "htmlOptions", ")", ";", "return", "\\", "CHtml", "::", "tag", "(", "'span'", ",", "$", "htmlOptions", ",", "$", "text", ")", ";", "}" ]
Renders a Foundation label @param string $text the text to render within the label @param array $htmlOptions the HTML attributes @return string the generated label
[ "Renders", "a", "Foundation", "label" ]
train
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Typo.php#L104-L108
Chill-project/Main
Entity/PostalCode.php
PostalCode.setCountry
public function setCountry(\Chill\MainBundle\Entity\Country $country = null) { $this->country = $country; return $this; }
php
public function setCountry(\Chill\MainBundle\Entity\Country $country = null) { $this->country = $country; return $this; }
[ "public", "function", "setCountry", "(", "\\", "Chill", "\\", "MainBundle", "\\", "Entity", "\\", "Country", "$", "country", "=", "null", ")", "{", "$", "this", "->", "country", "=", "$", "country", ";", "return", "$", "this", ";", "}" ]
Set country @param \Chill\MainBundle\Entity\Country $country @return PostalCode
[ "Set", "country" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Entity/PostalCode.php#L96-L101
TheBigBrainsCompany/TbbcRestUtilBundle
Error/Factory/FormErrorFactory.php
FormErrorFactory.createError
public function createError(\Exception $exception, ExceptionMappingInterface $mapping) { if (!$this->supportsException($exception)) { return null; } $errorMessage = $mapping->getErrorMessage(); if (empty($errorMessage)) { $errorMessage = $exception->getMessage(); } $formErrors = $exception->getFormErrors(); $extendedMessage = array( 'global_errors' => $formErrors['form_errors'], 'property_errors' => $formErrors['field_errors'], ); return new Error($mapping->getHttpStatusCode(), $mapping->getErrorCode(), $errorMessage, $extendedMessage, $mapping->getErrorMoreInfoUrl()); }
php
public function createError(\Exception $exception, ExceptionMappingInterface $mapping) { if (!$this->supportsException($exception)) { return null; } $errorMessage = $mapping->getErrorMessage(); if (empty($errorMessage)) { $errorMessage = $exception->getMessage(); } $formErrors = $exception->getFormErrors(); $extendedMessage = array( 'global_errors' => $formErrors['form_errors'], 'property_errors' => $formErrors['field_errors'], ); return new Error($mapping->getHttpStatusCode(), $mapping->getErrorCode(), $errorMessage, $extendedMessage, $mapping->getErrorMoreInfoUrl()); }
[ "public", "function", "createError", "(", "\\", "Exception", "$", "exception", ",", "ExceptionMappingInterface", "$", "mapping", ")", "{", "if", "(", "!", "$", "this", "->", "supportsException", "(", "$", "exception", ")", ")", "{", "return", "null", ";", "}", "$", "errorMessage", "=", "$", "mapping", "->", "getErrorMessage", "(", ")", ";", "if", "(", "empty", "(", "$", "errorMessage", ")", ")", "{", "$", "errorMessage", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "}", "$", "formErrors", "=", "$", "exception", "->", "getFormErrors", "(", ")", ";", "$", "extendedMessage", "=", "array", "(", "'global_errors'", "=>", "$", "formErrors", "[", "'form_errors'", "]", ",", "'property_errors'", "=>", "$", "formErrors", "[", "'field_errors'", "]", ",", ")", ";", "return", "new", "Error", "(", "$", "mapping", "->", "getHttpStatusCode", "(", ")", ",", "$", "mapping", "->", "getErrorCode", "(", ")", ",", "$", "errorMessage", ",", "$", "extendedMessage", ",", "$", "mapping", "->", "getErrorMoreInfoUrl", "(", ")", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/TheBigBrainsCompany/TbbcRestUtilBundle/blob/48c0598a94a4f6b3883d349d8f134138e8bc6d7c/Error/Factory/FormErrorFactory.php#L33-L52
VincentChalnot/SidusAdminBundle
Request/ParamConverter/AdminEntityParamConverter.php
AdminEntityParamConverter.apply
public function apply(Request $request, ParamConverter $configuration): bool { if (!$request->attributes->has('_admin')) { throw new \UnexpectedValueException('Missing _admin request attribute'); } $admin = $request->attributes->get('_admin'); if (!$admin instanceof Admin) { throw new \UnexpectedValueException('_admin request attribute is not an Admin object'); } $entityManager = $this->doctrine->getManagerForClass($admin->getEntity()); if (!$entityManager instanceof EntityManagerInterface) { throw new \UnexpectedValueException("Unable to find an EntityManager for class {$admin->getEntity()}"); } $id = $request->attributes->get($configuration->getOptions()['attribute'] ?? 'id'); if (null === $id) { $m = "Unable to resolve request attribute for identifier, either use 'id' as a request parameter or set it"; $m .= " manually in the 'attribute' option of your param converter configuration"; throw new \UnexpectedValueException($m); } $repository = $entityManager->getRepository($admin->getEntity()); $entity = $repository->find($id); if (!$entity) { throw new NotFoundHttpException("No entity found for class {$admin->getEntity()} and id {$id}"); } $request->attributes->set($configuration->getName(), $entity); return true; }
php
public function apply(Request $request, ParamConverter $configuration): bool { if (!$request->attributes->has('_admin')) { throw new \UnexpectedValueException('Missing _admin request attribute'); } $admin = $request->attributes->get('_admin'); if (!$admin instanceof Admin) { throw new \UnexpectedValueException('_admin request attribute is not an Admin object'); } $entityManager = $this->doctrine->getManagerForClass($admin->getEntity()); if (!$entityManager instanceof EntityManagerInterface) { throw new \UnexpectedValueException("Unable to find an EntityManager for class {$admin->getEntity()}"); } $id = $request->attributes->get($configuration->getOptions()['attribute'] ?? 'id'); if (null === $id) { $m = "Unable to resolve request attribute for identifier, either use 'id' as a request parameter or set it"; $m .= " manually in the 'attribute' option of your param converter configuration"; throw new \UnexpectedValueException($m); } $repository = $entityManager->getRepository($admin->getEntity()); $entity = $repository->find($id); if (!$entity) { throw new NotFoundHttpException("No entity found for class {$admin->getEntity()} and id {$id}"); } $request->attributes->set($configuration->getName(), $entity); return true; }
[ "public", "function", "apply", "(", "Request", "$", "request", ",", "ParamConverter", "$", "configuration", ")", ":", "bool", "{", "if", "(", "!", "$", "request", "->", "attributes", "->", "has", "(", "'_admin'", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'Missing _admin request attribute'", ")", ";", "}", "$", "admin", "=", "$", "request", "->", "attributes", "->", "get", "(", "'_admin'", ")", ";", "if", "(", "!", "$", "admin", "instanceof", "Admin", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "'_admin request attribute is not an Admin object'", ")", ";", "}", "$", "entityManager", "=", "$", "this", "->", "doctrine", "->", "getManagerForClass", "(", "$", "admin", "->", "getEntity", "(", ")", ")", ";", "if", "(", "!", "$", "entityManager", "instanceof", "EntityManagerInterface", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "\"Unable to find an EntityManager for class {$admin->getEntity()}\"", ")", ";", "}", "$", "id", "=", "$", "request", "->", "attributes", "->", "get", "(", "$", "configuration", "->", "getOptions", "(", ")", "[", "'attribute'", "]", "??", "'id'", ")", ";", "if", "(", "null", "===", "$", "id", ")", "{", "$", "m", "=", "\"Unable to resolve request attribute for identifier, either use 'id' as a request parameter or set it\"", ";", "$", "m", ".=", "\" manually in the 'attribute' option of your param converter configuration\"", ";", "throw", "new", "\\", "UnexpectedValueException", "(", "$", "m", ")", ";", "}", "$", "repository", "=", "$", "entityManager", "->", "getRepository", "(", "$", "admin", "->", "getEntity", "(", ")", ")", ";", "$", "entity", "=", "$", "repository", "->", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "entity", ")", "{", "throw", "new", "NotFoundHttpException", "(", "\"No entity found for class {$admin->getEntity()} and id {$id}\"", ")", ";", "}", "$", "request", "->", "attributes", "->", "set", "(", "$", "configuration", "->", "getName", "(", ")", ",", "$", "entity", ")", ";", "return", "true", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/VincentChalnot/SidusAdminBundle/blob/3366f3f1525435860cf275ed2f1f0b58cf6eea18/Request/ParamConverter/AdminEntityParamConverter.php#L40-L67
yuncms/framework
src/user/models/AvatarForm.php
AvatarForm.save
public function save() { if ($this->validate()) { $user = $this->getUser(); if(AvatarHelper::save($user, $this->getOriginalImage())){ return true; } else { return false; } } return false; }
php
public function save() { if ($this->validate()) { $user = $this->getUser(); if(AvatarHelper::save($user, $this->getOriginalImage())){ return true; } else { return false; } } return false; }
[ "public", "function", "save", "(", ")", "{", "if", "(", "$", "this", "->", "validate", "(", ")", ")", "{", "$", "user", "=", "$", "this", "->", "getUser", "(", ")", ";", "if", "(", "AvatarHelper", "::", "save", "(", "$", "user", ",", "$", "this", "->", "getOriginalImage", "(", ")", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "return", "false", ";", "}" ]
保存头像 @return boolean @throws \yii\base\ErrorException @throws \yii\base\Exception
[ "保存头像" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/AvatarForm.php#L79-L90
yuncms/framework
src/user/models/AvatarForm.php
AvatarForm.getOriginalImage
public function getOriginalImage() { if ($this->_originalImage == null) { $this->_originalImage = Yii::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $this->getUser()->id . '_avatar.jpg'; } return $this->_originalImage; }
php
public function getOriginalImage() { if ($this->_originalImage == null) { $this->_originalImage = Yii::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $this->getUser()->id . '_avatar.jpg'; } return $this->_originalImage; }
[ "public", "function", "getOriginalImage", "(", ")", "{", "if", "(", "$", "this", "->", "_originalImage", "==", "null", ")", "{", "$", "this", "->", "_originalImage", "=", "Yii", "::", "$", "app", "->", "getPath", "(", ")", "->", "getTempPath", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "getUser", "(", ")", "->", "id", ".", "'_avatar.jpg'", ";", "}", "return", "$", "this", "->", "_originalImage", ";", "}" ]
获取原图路径 @return string @throws \yii\base\Exception
[ "获取原图路径" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/AvatarForm.php#L108-L114
yuncms/framework
src/user/models/AvatarForm.php
AvatarForm.afterValidate
public function afterValidate() { //保存原图 Image::crop($this->file->tempName, $this->width, $this->height, [$this->x, $this->y])->save($this->getOriginalImage(), ['quality' => 100]); parent::afterValidate(); }
php
public function afterValidate() { //保存原图 Image::crop($this->file->tempName, $this->width, $this->height, [$this->x, $this->y])->save($this->getOriginalImage(), ['quality' => 100]); parent::afterValidate(); }
[ "public", "function", "afterValidate", "(", ")", "{", "//保存原图", "Image", "::", "crop", "(", "$", "this", "->", "file", "->", "tempName", ",", "$", "this", "->", "width", ",", "$", "this", "->", "height", ",", "[", "$", "this", "->", "x", ",", "$", "this", "->", "y", "]", ")", "->", "save", "(", "$", "this", "->", "getOriginalImage", "(", ")", ",", "[", "'quality'", "=>", "100", "]", ")", ";", "parent", "::", "afterValidate", "(", ")", ";", "}" ]
验证后保存原图 @throws \yii\base\Exception
[ "验证后保存原图" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/AvatarForm.php#L130-L135
alanpich/slender
src/Core/Autoloader/PSR4ClassLoader.php
PSR4ClassLoader.addNamespace
public function addNamespace($prefix, $baseDir, $prepend = false) { // normalize namespace prefix $prefix = trim($prefix, '\\') . '\\'; // normalize the base directory with a trailing separator $baseDir = rtrim($baseDir, '/') . DIRECTORY_SEPARATOR; $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . '/'; // initialize the namespace prefix array if (isset($this->prefixes[$prefix]) === false) { $this->prefixes[$prefix] = array(); } // retain the base directory for the namespace prefix if ($prepend) { array_unshift($this->prefixes[$prefix], $baseDir); } else { array_push($this->prefixes[$prefix], $baseDir); } }
php
public function addNamespace($prefix, $baseDir, $prepend = false) { // normalize namespace prefix $prefix = trim($prefix, '\\') . '\\'; // normalize the base directory with a trailing separator $baseDir = rtrim($baseDir, '/') . DIRECTORY_SEPARATOR; $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . '/'; // initialize the namespace prefix array if (isset($this->prefixes[$prefix]) === false) { $this->prefixes[$prefix] = array(); } // retain the base directory for the namespace prefix if ($prepend) { array_unshift($this->prefixes[$prefix], $baseDir); } else { array_push($this->prefixes[$prefix], $baseDir); } }
[ "public", "function", "addNamespace", "(", "$", "prefix", ",", "$", "baseDir", ",", "$", "prepend", "=", "false", ")", "{", "// normalize namespace prefix", "$", "prefix", "=", "trim", "(", "$", "prefix", ",", "'\\\\'", ")", ".", "'\\\\'", ";", "// normalize the base directory with a trailing separator", "$", "baseDir", "=", "rtrim", "(", "$", "baseDir", ",", "'/'", ")", ".", "DIRECTORY_SEPARATOR", ";", "$", "baseDir", "=", "rtrim", "(", "$", "baseDir", ",", "DIRECTORY_SEPARATOR", ")", ".", "'/'", ";", "// initialize the namespace prefix array", "if", "(", "isset", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ")", "===", "false", ")", "{", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", "=", "array", "(", ")", ";", "}", "// retain the base directory for the namespace prefix", "if", "(", "$", "prepend", ")", "{", "array_unshift", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ",", "$", "baseDir", ")", ";", "}", "else", "{", "array_push", "(", "$", "this", "->", "prefixes", "[", "$", "prefix", "]", ",", "$", "baseDir", ")", ";", "}", "}" ]
Adds a base directory for a namespace prefix. @param string $prefix The namespace prefix. @param string $baseDir A base directory for class files in the namespace. @param bool $prepend If true, prepend the base directory to the stack instead of appending it; this causes it to be searched first rather than last. @return void
[ "Adds", "a", "base", "directory", "for", "a", "namespace", "prefix", "." ]
train
https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/Core/Autoloader/PSR4ClassLoader.php#L110-L130
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.getAllModels
public function getAllModels($model_name, Request $request) { $this->model_name = substr($model_name, 0, -1); return $this->getSomeModels($request, $request, 500); }
php
public function getAllModels($model_name, Request $request) { $this->model_name = substr($model_name, 0, -1); return $this->getSomeModels($request, $request, 500); }
[ "public", "function", "getAllModels", "(", "$", "model_name", ",", "Request", "$", "request", ")", "{", "$", "this", "->", "model_name", "=", "substr", "(", "$", "model_name", ",", "0", ",", "-", "1", ")", ";", "return", "$", "this", "->", "getSomeModels", "(", "$", "request", ",", "$", "request", ",", "500", ")", ";", "}" ]
@param $model_name @param Request $request @return \Illuminate\Http\JsonResponse
[ "@param", "$model_name", "@param", "Request", "$request" ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L28-L33
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.getSomeModels
public function getSomeModels($model_name, Request $request, $paginate = 100) { $this->checkParams(func_get_args()); $model = $this->findModel($model_name); $status = $request->ajax() ? 202 : 200; return response()->json($model->paginate($paginate), $status); }
php
public function getSomeModels($model_name, Request $request, $paginate = 100) { $this->checkParams(func_get_args()); $model = $this->findModel($model_name); $status = $request->ajax() ? 202 : 200; return response()->json($model->paginate($paginate), $status); }
[ "public", "function", "getSomeModels", "(", "$", "model_name", ",", "Request", "$", "request", ",", "$", "paginate", "=", "100", ")", "{", "$", "this", "->", "checkParams", "(", "func_get_args", "(", ")", ")", ";", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "model_name", ")", ";", "$", "status", "=", "$", "request", "->", "ajax", "(", ")", "?", "202", ":", "200", ";", "return", "response", "(", ")", "->", "json", "(", "$", "model", "->", "paginate", "(", "$", "paginate", ")", ",", "$", "status", ")", ";", "}" ]
@param $model_name @param Request $request @param int $paginate @return \Illuminate\Http\JsonResponse
[ "@param", "$model_name", "@param", "Request", "$request", "@param", "int", "$paginate" ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L42-L49
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.findModel
public function findModel($model_name, $id = null) { $model = config('kregel.warden.models.'.$model_name.'.model'); if (empty($id) | !is_numeric($id)) { return new $model(); } return $model::find($id); }
php
public function findModel($model_name, $id = null) { $model = config('kregel.warden.models.'.$model_name.'.model'); if (empty($id) | !is_numeric($id)) { return new $model(); } return $model::find($id); }
[ "public", "function", "findModel", "(", "$", "model_name", ",", "$", "id", "=", "null", ")", "{", "$", "model", "=", "config", "(", "'kregel.warden.models.'", ".", "$", "model_name", ".", "'.model'", ")", ";", "if", "(", "empty", "(", "$", "id", ")", "|", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "return", "new", "$", "model", "(", ")", ";", "}", "return", "$", "model", "::", "find", "(", "$", "id", ")", ";", "}" ]
@param $model_name @param null $id @return Model
[ "@param", "$model_name", "@param", "null", "$id" ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L57-L65
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.postModel
public function postModel($model_name, Request $request) { $this->checkParams(func_get_args()); $model = $this->findModel($model_name); if (empty($model)) { return $this->emptyModel($request); } // Need a way to validate the input for the model. If we then can not find any // way to validate the inputs then we might have some un-wanted inputs from // some of the users. We probably won't need to worry about validations. $input = Warden::clearInput([ 'uuid' => Warden::generateUUID(), ] + $request->all()); $model->fill($input); if (!empty($model->password)) { $model->password = bcrypt($model->password); } // Update a relationship. foreach ($input as $k => $i) { // If there are no relations for this point just break. if (empty($relations = FormModel::using('plain')->getRelationalDataAndModels($model, $k))) { break; } if (in_array($k, $relations) || !(empty($relations[$k]))) { // Check if there is a relation // if it's in_array, it's not a closure, just have to sync. Otherwise it's a closure // And we will have to call the closure and pass through the need model to it. $model->$k()->sync($i); $update_event = config('kregel.warden.models.'.$model_name.'.relations.'.$k.'.new'); if ($update_event instanceof Closure) { $update_event($model); } } } $this->uploadFileTest($model, $request); return $this->modelHasBeenSaved($model->save(), 'created', $request); }
php
public function postModel($model_name, Request $request) { $this->checkParams(func_get_args()); $model = $this->findModel($model_name); if (empty($model)) { return $this->emptyModel($request); } // Need a way to validate the input for the model. If we then can not find any // way to validate the inputs then we might have some un-wanted inputs from // some of the users. We probably won't need to worry about validations. $input = Warden::clearInput([ 'uuid' => Warden::generateUUID(), ] + $request->all()); $model->fill($input); if (!empty($model->password)) { $model->password = bcrypt($model->password); } // Update a relationship. foreach ($input as $k => $i) { // If there are no relations for this point just break. if (empty($relations = FormModel::using('plain')->getRelationalDataAndModels($model, $k))) { break; } if (in_array($k, $relations) || !(empty($relations[$k]))) { // Check if there is a relation // if it's in_array, it's not a closure, just have to sync. Otherwise it's a closure // And we will have to call the closure and pass through the need model to it. $model->$k()->sync($i); $update_event = config('kregel.warden.models.'.$model_name.'.relations.'.$k.'.new'); if ($update_event instanceof Closure) { $update_event($model); } } } $this->uploadFileTest($model, $request); return $this->modelHasBeenSaved($model->save(), 'created', $request); }
[ "public", "function", "postModel", "(", "$", "model_name", ",", "Request", "$", "request", ")", "{", "$", "this", "->", "checkParams", "(", "func_get_args", "(", ")", ")", ";", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "model_name", ")", ";", "if", "(", "empty", "(", "$", "model", ")", ")", "{", "return", "$", "this", "->", "emptyModel", "(", "$", "request", ")", ";", "}", "// Need a way to validate the input for the model. If we then can not find any", "// way to validate the inputs then we might have some un-wanted inputs from", "// some of the users. We probably won't need to worry about validations.", "$", "input", "=", "Warden", "::", "clearInput", "(", "[", "'uuid'", "=>", "Warden", "::", "generateUUID", "(", ")", ",", "]", "+", "$", "request", "->", "all", "(", ")", ")", ";", "$", "model", "->", "fill", "(", "$", "input", ")", ";", "if", "(", "!", "empty", "(", "$", "model", "->", "password", ")", ")", "{", "$", "model", "->", "password", "=", "bcrypt", "(", "$", "model", "->", "password", ")", ";", "}", "// Update a relationship.", "foreach", "(", "$", "input", "as", "$", "k", "=>", "$", "i", ")", "{", "// If there are no relations for this point just break.", "if", "(", "empty", "(", "$", "relations", "=", "FormModel", "::", "using", "(", "'plain'", ")", "->", "getRelationalDataAndModels", "(", "$", "model", ",", "$", "k", ")", ")", ")", "{", "break", ";", "}", "if", "(", "in_array", "(", "$", "k", ",", "$", "relations", ")", "||", "!", "(", "empty", "(", "$", "relations", "[", "$", "k", "]", ")", ")", ")", "{", "// Check if there is a relation", "// if it's in_array, it's not a closure, just have to sync. Otherwise it's a closure", "// And we will have to call the closure and pass through the need model to it.", "$", "model", "->", "$", "k", "(", ")", "->", "sync", "(", "$", "i", ")", ";", "$", "update_event", "=", "config", "(", "'kregel.warden.models.'", ".", "$", "model_name", ".", "'.relations.'", ".", "$", "k", ".", "'.new'", ")", ";", "if", "(", "$", "update_event", "instanceof", "Closure", ")", "{", "$", "update_event", "(", "$", "model", ")", ";", "}", "}", "}", "$", "this", "->", "uploadFileTest", "(", "$", "model", ",", "$", "request", ")", ";", "return", "$", "this", "->", "modelHasBeenSaved", "(", "$", "model", "->", "save", "(", ")", ",", "'created'", ",", "$", "request", ")", ";", "}" ]
@param $model_name @param Request $request @return \Illuminate\Http\JsonResponse
[ "@param", "$model_name", "@param", "Request", "$request" ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L73-L112
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.modelHasBeenSaved
protected function modelHasBeenSaved($saved, $type, $request) { if (!$saved) { return response()->json(['message' => 'Failed to '.$type.' resource', 'code' => 422], 422); } $status = $request->ajax() ? 202 : 200; if ($request->ajax()) { return response()->json(['message' => 'Successfully '.$type.' resource', 'code' => $status], $status); } if ($request->has('_redirect')) { // Remove the base part of the url, and just grab the tail end of the desired redirect, that way the // User can't be redirected away from your website. return $this->returnRedirect('Successfully '.$type.' resource', $request); } return redirect()->back()->with(['message' => 'Successfully '.$type.' resource']); }
php
protected function modelHasBeenSaved($saved, $type, $request) { if (!$saved) { return response()->json(['message' => 'Failed to '.$type.' resource', 'code' => 422], 422); } $status = $request->ajax() ? 202 : 200; if ($request->ajax()) { return response()->json(['message' => 'Successfully '.$type.' resource', 'code' => $status], $status); } if ($request->has('_redirect')) { // Remove the base part of the url, and just grab the tail end of the desired redirect, that way the // User can't be redirected away from your website. return $this->returnRedirect('Successfully '.$type.' resource', $request); } return redirect()->back()->with(['message' => 'Successfully '.$type.' resource']); }
[ "protected", "function", "modelHasBeenSaved", "(", "$", "saved", ",", "$", "type", ",", "$", "request", ")", "{", "if", "(", "!", "$", "saved", ")", "{", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'Failed to '", ".", "$", "type", ".", "' resource'", ",", "'code'", "=>", "422", "]", ",", "422", ")", ";", "}", "$", "status", "=", "$", "request", "->", "ajax", "(", ")", "?", "202", ":", "200", ";", "if", "(", "$", "request", "->", "ajax", "(", ")", ")", "{", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'Successfully '", ".", "$", "type", ".", "' resource'", ",", "'code'", "=>", "$", "status", "]", ",", "$", "status", ")", ";", "}", "if", "(", "$", "request", "->", "has", "(", "'_redirect'", ")", ")", "{", "// Remove the base part of the url, and just grab the tail end of the desired redirect, that way the", "// User can't be redirected away from your website.", "return", "$", "this", "->", "returnRedirect", "(", "'Successfully '", ".", "$", "type", ".", "' resource'", ",", "$", "request", ")", ";", "}", "return", "redirect", "(", ")", "->", "back", "(", ")", "->", "with", "(", "[", "'message'", "=>", "'Successfully '", ".", "$", "type", ".", "' resource'", "]", ")", ";", "}" ]
This method handles how submitted quests are handle, the main related methods for it are POST and. @param $saved @param $request @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
[ "This", "method", "handles", "how", "submitted", "quests", "are", "handle", "the", "main", "related", "methods", "for", "it", "are", "POST", "and", "." ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L123-L139
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.putModel
public function putModel($model_name, $id, Request $request) { $this->checkParams(func_get_args()); $model = $this->findModel($model_name, $id); if (empty($model)) { return $this->emptyModel($request); } $input = collect(Warden::clearInput($request->all())); // Remove the empty values. $this->validatePut($input, $model, $model_name); // Remove any values that are the same if ($input->isEmpty()) { // if the input is empty, return response()->json(['message' => 'Nothing to update for resource', 'code' => 205], 205); } /* * Here we need to calculate the actual values of our model. Since we're * just updating what we can then we only need the fillable from the model * * If the model has the Wardenable Trait then it skews the results with collections * and it also removes the _id's from the model and trims the value. * * If it has the Wardenable Trait, calculate the real values by flatMaping the values * of the getFillable array to the model it's self. */ if (method_exists($model, 'getWarden')) { $model_array = collect($model->getFillable())->flatMap(function ($value) use ($model) { // If the value is an instance of carbon it will throw an 'Array to String' exception. if ($model->$value instanceof Carbon) { // Convert the string to return [$value => $model->$value->__toString()]; } return [$value => $model->$value]; }); } else { // Since the model doesn't have getWarden then it doesn't have warden able. $model_array = collect($model->toArray()); } // Since wardenable messes with our normal method of just collect($model) // So we have to map the fillable to a new model $relationships = $input->filter(function ($value) { return is_array($value); }); // Assume that anything not in an array isn't a relationship. $not_relationships = $input->filter(function ($value) { return !is_array($value); }); // Before filling the model we need to convert all date time stamps into normal timestamps $dates = collect($not_relationships)->filter(function ($val, $key) use ($model) { return in_array($key, $model->getDates()); })->flatMap(function ($value, $key) use ($model) { if (count(explode(' ', $value)) > 1) { return [$key => Carbon::createFromFormat('Y-m-d H:i:s', $value)->__toString()]; } $value = $value === '-0001-11-30' ? '0000-00-00' : $value; return [$key => Carbon::createFromFormat('Y-m-d', $value)->__toString()]; }); // dd($dates, $not_relationships, $relationships); // Fill the differences between the current values and the new input. $model->fill($not_relationships->merge($dates)->toArray()); // Make sure the array if (!$relationships->isEmpty()) { foreach ($relationships as $many_relation => $values) { if ($model->$many_relation() instanceof BelongsToMany) { $model->$many_relation()->sync($values, false); } } } if (strtolower($request->server('REQUEST_METHOD')) === 'post') { $this->uploadFileTest($model, $request); } $saved = $model->save(); return $this->modelHasBeenSaved($saved, 'updated', $request); }
php
public function putModel($model_name, $id, Request $request) { $this->checkParams(func_get_args()); $model = $this->findModel($model_name, $id); if (empty($model)) { return $this->emptyModel($request); } $input = collect(Warden::clearInput($request->all())); // Remove the empty values. $this->validatePut($input, $model, $model_name); // Remove any values that are the same if ($input->isEmpty()) { // if the input is empty, return response()->json(['message' => 'Nothing to update for resource', 'code' => 205], 205); } /* * Here we need to calculate the actual values of our model. Since we're * just updating what we can then we only need the fillable from the model * * If the model has the Wardenable Trait then it skews the results with collections * and it also removes the _id's from the model and trims the value. * * If it has the Wardenable Trait, calculate the real values by flatMaping the values * of the getFillable array to the model it's self. */ if (method_exists($model, 'getWarden')) { $model_array = collect($model->getFillable())->flatMap(function ($value) use ($model) { // If the value is an instance of carbon it will throw an 'Array to String' exception. if ($model->$value instanceof Carbon) { // Convert the string to return [$value => $model->$value->__toString()]; } return [$value => $model->$value]; }); } else { // Since the model doesn't have getWarden then it doesn't have warden able. $model_array = collect($model->toArray()); } // Since wardenable messes with our normal method of just collect($model) // So we have to map the fillable to a new model $relationships = $input->filter(function ($value) { return is_array($value); }); // Assume that anything not in an array isn't a relationship. $not_relationships = $input->filter(function ($value) { return !is_array($value); }); // Before filling the model we need to convert all date time stamps into normal timestamps $dates = collect($not_relationships)->filter(function ($val, $key) use ($model) { return in_array($key, $model->getDates()); })->flatMap(function ($value, $key) use ($model) { if (count(explode(' ', $value)) > 1) { return [$key => Carbon::createFromFormat('Y-m-d H:i:s', $value)->__toString()]; } $value = $value === '-0001-11-30' ? '0000-00-00' : $value; return [$key => Carbon::createFromFormat('Y-m-d', $value)->__toString()]; }); // dd($dates, $not_relationships, $relationships); // Fill the differences between the current values and the new input. $model->fill($not_relationships->merge($dates)->toArray()); // Make sure the array if (!$relationships->isEmpty()) { foreach ($relationships as $many_relation => $values) { if ($model->$many_relation() instanceof BelongsToMany) { $model->$many_relation()->sync($values, false); } } } if (strtolower($request->server('REQUEST_METHOD')) === 'post') { $this->uploadFileTest($model, $request); } $saved = $model->save(); return $this->modelHasBeenSaved($saved, 'updated', $request); }
[ "public", "function", "putModel", "(", "$", "model_name", ",", "$", "id", ",", "Request", "$", "request", ")", "{", "$", "this", "->", "checkParams", "(", "func_get_args", "(", ")", ")", ";", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "model_name", ",", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "model", ")", ")", "{", "return", "$", "this", "->", "emptyModel", "(", "$", "request", ")", ";", "}", "$", "input", "=", "collect", "(", "Warden", "::", "clearInput", "(", "$", "request", "->", "all", "(", ")", ")", ")", ";", "// Remove the empty values.", "$", "this", "->", "validatePut", "(", "$", "input", ",", "$", "model", ",", "$", "model_name", ")", ";", "// Remove any values that are the same", "if", "(", "$", "input", "->", "isEmpty", "(", ")", ")", "{", "// if the input is empty,", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'Nothing to update for resource'", ",", "'code'", "=>", "205", "]", ",", "205", ")", ";", "}", "/*\n * Here we need to calculate the actual values of our model. Since we're\n * just updating what we can then we only need the fillable from the model\n *\n * If the model has the Wardenable Trait then it skews the results with collections\n * and it also removes the _id's from the model and trims the value.\n *\n * If it has the Wardenable Trait, calculate the real values by flatMaping the values\n * of the getFillable array to the model it's self.\n */", "if", "(", "method_exists", "(", "$", "model", ",", "'getWarden'", ")", ")", "{", "$", "model_array", "=", "collect", "(", "$", "model", "->", "getFillable", "(", ")", ")", "->", "flatMap", "(", "function", "(", "$", "value", ")", "use", "(", "$", "model", ")", "{", "// If the value is an instance of carbon it will throw an 'Array to String' exception.", "if", "(", "$", "model", "->", "$", "value", "instanceof", "Carbon", ")", "{", "// Convert the string to", "return", "[", "$", "value", "=>", "$", "model", "->", "$", "value", "->", "__toString", "(", ")", "]", ";", "}", "return", "[", "$", "value", "=>", "$", "model", "->", "$", "value", "]", ";", "}", ")", ";", "}", "else", "{", "// Since the model doesn't have getWarden then it doesn't have warden able.", "$", "model_array", "=", "collect", "(", "$", "model", "->", "toArray", "(", ")", ")", ";", "}", "// Since wardenable messes with our normal method of just collect($model)", "// So we have to map the fillable to a new model", "$", "relationships", "=", "$", "input", "->", "filter", "(", "function", "(", "$", "value", ")", "{", "return", "is_array", "(", "$", "value", ")", ";", "}", ")", ";", "// Assume that anything not in an array isn't a relationship.", "$", "not_relationships", "=", "$", "input", "->", "filter", "(", "function", "(", "$", "value", ")", "{", "return", "!", "is_array", "(", "$", "value", ")", ";", "}", ")", ";", "// Before filling the model we need to convert all date time stamps into normal timestamps", "$", "dates", "=", "collect", "(", "$", "not_relationships", ")", "->", "filter", "(", "function", "(", "$", "val", ",", "$", "key", ")", "use", "(", "$", "model", ")", "{", "return", "in_array", "(", "$", "key", ",", "$", "model", "->", "getDates", "(", ")", ")", ";", "}", ")", "->", "flatMap", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "model", ")", "{", "if", "(", "count", "(", "explode", "(", "' '", ",", "$", "value", ")", ")", ">", "1", ")", "{", "return", "[", "$", "key", "=>", "Carbon", "::", "createFromFormat", "(", "'Y-m-d H:i:s'", ",", "$", "value", ")", "->", "__toString", "(", ")", "]", ";", "}", "$", "value", "=", "$", "value", "===", "'-0001-11-30'", "?", "'0000-00-00'", ":", "$", "value", ";", "return", "[", "$", "key", "=>", "Carbon", "::", "createFromFormat", "(", "'Y-m-d'", ",", "$", "value", ")", "->", "__toString", "(", ")", "]", ";", "}", ")", ";", "// dd($dates, $not_relationships, $relationships);", "// Fill the differences between the current values and the new input.", "$", "model", "->", "fill", "(", "$", "not_relationships", "->", "merge", "(", "$", "dates", ")", "->", "toArray", "(", ")", ")", ";", "// Make sure the array", "if", "(", "!", "$", "relationships", "->", "isEmpty", "(", ")", ")", "{", "foreach", "(", "$", "relationships", "as", "$", "many_relation", "=>", "$", "values", ")", "{", "if", "(", "$", "model", "->", "$", "many_relation", "(", ")", "instanceof", "BelongsToMany", ")", "{", "$", "model", "->", "$", "many_relation", "(", ")", "->", "sync", "(", "$", "values", ",", "false", ")", ";", "}", "}", "}", "if", "(", "strtolower", "(", "$", "request", "->", "server", "(", "'REQUEST_METHOD'", ")", ")", "===", "'post'", ")", "{", "$", "this", "->", "uploadFileTest", "(", "$", "model", ",", "$", "request", ")", ";", "}", "$", "saved", "=", "$", "model", "->", "save", "(", ")", ";", "return", "$", "this", "->", "modelHasBeenSaved", "(", "$", "saved", ",", "'updated'", ",", "$", "request", ")", ";", "}" ]
@param $model_name @param $id @param Request $request @return \Illuminate\Http\JsonResponse
[ "@param", "$model_name", "@param", "$id", "@param", "Request", "$request" ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L158-L236
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.validatePut
public function validatePut($input, $model, $model_name) { return collect($input)->filter(function ($value, $key) use ($model, $input) { // Remove _token if (!isset($value) || $key === '_token') { return false; } //Remove values that are the same. if (isset($model->$key)) { if ($model->$key === $value) { return false; } } // Is there a relation? If there is, unset it. if ($this->doesModelRelate($model, $key, $value)) { return false; } // If there is a password field, if (((stripos($key, 'password') !== false) || (stripos($key, 'passwd') !== false)) && !empty($model->$key)) { if (\Hash::check($value, $model->$key)) { return false; } else { $user_model = config('kregel.warden.models.user.model'); $user = new $user_model(); if (empty($user->hashable)) { $input[$key] = bcrypt($value); return true; } } } return true; }); }
php
public function validatePut($input, $model, $model_name) { return collect($input)->filter(function ($value, $key) use ($model, $input) { // Remove _token if (!isset($value) || $key === '_token') { return false; } //Remove values that are the same. if (isset($model->$key)) { if ($model->$key === $value) { return false; } } // Is there a relation? If there is, unset it. if ($this->doesModelRelate($model, $key, $value)) { return false; } // If there is a password field, if (((stripos($key, 'password') !== false) || (stripos($key, 'passwd') !== false)) && !empty($model->$key)) { if (\Hash::check($value, $model->$key)) { return false; } else { $user_model = config('kregel.warden.models.user.model'); $user = new $user_model(); if (empty($user->hashable)) { $input[$key] = bcrypt($value); return true; } } } return true; }); }
[ "public", "function", "validatePut", "(", "$", "input", ",", "$", "model", ",", "$", "model_name", ")", "{", "return", "collect", "(", "$", "input", ")", "->", "filter", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "model", ",", "$", "input", ")", "{", "// Remove _token", "if", "(", "!", "isset", "(", "$", "value", ")", "||", "$", "key", "===", "'_token'", ")", "{", "return", "false", ";", "}", "//Remove values that are the same.", "if", "(", "isset", "(", "$", "model", "->", "$", "key", ")", ")", "{", "if", "(", "$", "model", "->", "$", "key", "===", "$", "value", ")", "{", "return", "false", ";", "}", "}", "// Is there a relation? If there is, unset it.", "if", "(", "$", "this", "->", "doesModelRelate", "(", "$", "model", ",", "$", "key", ",", "$", "value", ")", ")", "{", "return", "false", ";", "}", "// If there is a password field,", "if", "(", "(", "(", "stripos", "(", "$", "key", ",", "'password'", ")", "!==", "false", ")", "||", "(", "stripos", "(", "$", "key", ",", "'passwd'", ")", "!==", "false", ")", ")", "&&", "!", "empty", "(", "$", "model", "->", "$", "key", ")", ")", "{", "if", "(", "\\", "Hash", "::", "check", "(", "$", "value", ",", "$", "model", "->", "$", "key", ")", ")", "{", "return", "false", ";", "}", "else", "{", "$", "user_model", "=", "config", "(", "'kregel.warden.models.user.model'", ")", ";", "$", "user", "=", "new", "$", "user_model", "(", ")", ";", "if", "(", "empty", "(", "$", "user", "->", "hashable", ")", ")", "{", "$", "input", "[", "$", "key", "]", "=", "bcrypt", "(", "$", "value", ")", ";", "return", "true", ";", "}", "}", "}", "return", "true", ";", "}", ")", ";", "}" ]
This Checks for any values and the _token for csrf and removes it from any blank values and it also removes the _token from the input. If there is a password within the request it will compare it to the current hash. @param $input @param $model @return Collection
[ "This", "Checks", "for", "any", "values", "and", "the", "_token", "for", "csrf", "and", "removes", "it", "from", "any", "blank", "values", "and", "it", "also", "removes", "the", "_token", "from", "the", "input", ".", "If", "there", "is", "a", "password", "within", "the", "request", "it", "will", "compare", "it", "to", "the", "current", "hash", "." ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L248-L284
austinkregel/Warden
src/Warden/Http/Controllers/ApiController.php
ApiController.deleteModel
public function deleteModel($model_name, $id, Request $request) { $this->checkParams(func_get_args()); $status = $request->ajax() ? 202 : 200; $model = $this->findModel($model_name, $id); if (empty($model->id)) { if ($model = $model::withTrashed()->whereId($id)->first()) { $relations = config('kregel.warden.models.'.$model_name.'.relations'); foreach ($relations as $rel) { $model->$rel()->forceDelete(); $update_event = config('kregel.warden.models.'.$model_name.'.relations.'.$rel.'.delete'); if ($update_event instanceof Closure) { $update_event($model); } } $model->forceDelete(); return response()->json(['message' => 'Resource deleted from the system.', 'code' => $status], $status); } return response()->json(['message' => 'No resource found!', 'code' => 404], 404); } $model->delete(); if ($request->has('_redirect')) { // Remove the base part of the url, and just grab the tail end of the desired redirect, that way the // User can't be redirected away from your website. return $this->returnRedirect('Successfully updated resource', $request); } return response()->json(['message' => 'Successfully deleted resource', 'code' => $status], $status); }
php
public function deleteModel($model_name, $id, Request $request) { $this->checkParams(func_get_args()); $status = $request->ajax() ? 202 : 200; $model = $this->findModel($model_name, $id); if (empty($model->id)) { if ($model = $model::withTrashed()->whereId($id)->first()) { $relations = config('kregel.warden.models.'.$model_name.'.relations'); foreach ($relations as $rel) { $model->$rel()->forceDelete(); $update_event = config('kregel.warden.models.'.$model_name.'.relations.'.$rel.'.delete'); if ($update_event instanceof Closure) { $update_event($model); } } $model->forceDelete(); return response()->json(['message' => 'Resource deleted from the system.', 'code' => $status], $status); } return response()->json(['message' => 'No resource found!', 'code' => 404], 404); } $model->delete(); if ($request->has('_redirect')) { // Remove the base part of the url, and just grab the tail end of the desired redirect, that way the // User can't be redirected away from your website. return $this->returnRedirect('Successfully updated resource', $request); } return response()->json(['message' => 'Successfully deleted resource', 'code' => $status], $status); }
[ "public", "function", "deleteModel", "(", "$", "model_name", ",", "$", "id", ",", "Request", "$", "request", ")", "{", "$", "this", "->", "checkParams", "(", "func_get_args", "(", ")", ")", ";", "$", "status", "=", "$", "request", "->", "ajax", "(", ")", "?", "202", ":", "200", ";", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "model_name", ",", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "model", "->", "id", ")", ")", "{", "if", "(", "$", "model", "=", "$", "model", "::", "withTrashed", "(", ")", "->", "whereId", "(", "$", "id", ")", "->", "first", "(", ")", ")", "{", "$", "relations", "=", "config", "(", "'kregel.warden.models.'", ".", "$", "model_name", ".", "'.relations'", ")", ";", "foreach", "(", "$", "relations", "as", "$", "rel", ")", "{", "$", "model", "->", "$", "rel", "(", ")", "->", "forceDelete", "(", ")", ";", "$", "update_event", "=", "config", "(", "'kregel.warden.models.'", ".", "$", "model_name", ".", "'.relations.'", ".", "$", "rel", ".", "'.delete'", ")", ";", "if", "(", "$", "update_event", "instanceof", "Closure", ")", "{", "$", "update_event", "(", "$", "model", ")", ";", "}", "}", "$", "model", "->", "forceDelete", "(", ")", ";", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'Resource deleted from the system.'", ",", "'code'", "=>", "$", "status", "]", ",", "$", "status", ")", ";", "}", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'No resource found!'", ",", "'code'", "=>", "404", "]", ",", "404", ")", ";", "}", "$", "model", "->", "delete", "(", ")", ";", "if", "(", "$", "request", "->", "has", "(", "'_redirect'", ")", ")", "{", "// Remove the base part of the url, and just grab the tail end of the desired redirect, that way the", "// User can't be redirected away from your website.", "return", "$", "this", "->", "returnRedirect", "(", "'Successfully updated resource'", ",", "$", "request", ")", ";", "}", "return", "response", "(", ")", "->", "json", "(", "[", "'message'", "=>", "'Successfully deleted resource'", ",", "'code'", "=>", "$", "status", "]", ",", "$", "status", ")", ";", "}" ]
@param $model_name @param $id @param Request $request @throws \Exception @return \Illuminate\Http\JsonResponse
[ "@param", "$model_name", "@param", "$id", "@param", "Request", "$request" ]
train
https://github.com/austinkregel/Warden/blob/6f5a98bd79a488f0f300f4851061ac6f7d19f8a3/src/Warden/Http/Controllers/ApiController.php#L295-L327
yuncms/framework
src/helpers/UploadHelper.php
UploadHelper.getMaxUploadSize
public static function getMaxUploadSize($maxSize = null) { $maxUpload = (int)(ini_get('upload_max_filesize')); $maxPost = (int)(ini_get('post_max_size')); $memoryLimit = (int)(ini_get('memory_limit')); $min = min($maxUpload, $maxPost, $memoryLimit); if ($maxSize) { $maxSize = (int)$maxSize; return min($maxSize, $min); } return $min; }
php
public static function getMaxUploadSize($maxSize = null) { $maxUpload = (int)(ini_get('upload_max_filesize')); $maxPost = (int)(ini_get('post_max_size')); $memoryLimit = (int)(ini_get('memory_limit')); $min = min($maxUpload, $maxPost, $memoryLimit); if ($maxSize) { $maxSize = (int)$maxSize; return min($maxSize, $min); } return $min; }
[ "public", "static", "function", "getMaxUploadSize", "(", "$", "maxSize", "=", "null", ")", "{", "$", "maxUpload", "=", "(", "int", ")", "(", "ini_get", "(", "'upload_max_filesize'", ")", ")", ";", "$", "maxPost", "=", "(", "int", ")", "(", "ini_get", "(", "'post_max_size'", ")", ")", ";", "$", "memoryLimit", "=", "(", "int", ")", "(", "ini_get", "(", "'memory_limit'", ")", ")", ";", "$", "min", "=", "min", "(", "$", "maxUpload", ",", "$", "maxPost", ",", "$", "memoryLimit", ")", ";", "if", "(", "$", "maxSize", ")", "{", "$", "maxSize", "=", "(", "int", ")", "$", "maxSize", ";", "return", "min", "(", "$", "maxSize", ",", "$", "min", ")", ";", "}", "return", "$", "min", ";", "}" ]
返回允许上传的最大大小单位 MB @param string $maxSize 最大上传大小MB @return int the max upload size in MB
[ "返回允许上传的最大大小单位", "MB" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/UploadHelper.php#L46-L57
yuncms/framework
src/helpers/UploadHelper.php
UploadHelper.getAcceptImageMimeTypes
public static function getAcceptImageMimeTypes() { $imageAllowFiles = Yii::$app->getSettings()->get('imageAllowFiles','attachment'); $extensions = explode(',', $imageAllowFiles); array_walk($extensions, function (&$value) { $value = 'image/' . $value; }); return $extensions; }
php
public static function getAcceptImageMimeTypes() { $imageAllowFiles = Yii::$app->getSettings()->get('imageAllowFiles','attachment'); $extensions = explode(',', $imageAllowFiles); array_walk($extensions, function (&$value) { $value = 'image/' . $value; }); return $extensions; }
[ "public", "static", "function", "getAcceptImageMimeTypes", "(", ")", "{", "$", "imageAllowFiles", "=", "Yii", "::", "$", "app", "->", "getSettings", "(", ")", "->", "get", "(", "'imageAllowFiles'", ",", "'attachment'", ")", ";", "$", "extensions", "=", "explode", "(", "','", ",", "$", "imageAllowFiles", ")", ";", "array_walk", "(", "$", "extensions", ",", "function", "(", "&", "$", "value", ")", "{", "$", "value", "=", "'image/'", ".", "$", "value", ";", "}", ")", ";", "return", "$", "extensions", ";", "}" ]
获取允许上传的图像 mimeTypes 列表 @return array ['image/jpg','image/png']
[ "获取允许上传的图像", "mimeTypes", "列表" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/helpers/UploadHelper.php#L93-L101
Chill-project/Main
Routing/MenuComposer.php
MenuComposer.getRoutesFor
public function getRoutesFor($menuId, array $parameters = array()) { $routes = array(); $routeCollection = $this->container->get('router')->getRouteCollection(); foreach ($routeCollection->all() as $routeKey => $route) { if ($route->hasOption('menus')) { if (array_key_exists($menuId, $route->getOption('menus'))) { $route = $route->getOption('menus')[$menuId]; $route['key'] = $routeKey; $order = $this->resolveOrder($routes, $route['order']); //we do not want to duplicate order information unset($route['order']); $routes[$order] = $route; } } } ksort($routes); return $routes; }
php
public function getRoutesFor($menuId, array $parameters = array()) { $routes = array(); $routeCollection = $this->container->get('router')->getRouteCollection(); foreach ($routeCollection->all() as $routeKey => $route) { if ($route->hasOption('menus')) { if (array_key_exists($menuId, $route->getOption('menus'))) { $route = $route->getOption('menus')[$menuId]; $route['key'] = $routeKey; $order = $this->resolveOrder($routes, $route['order']); //we do not want to duplicate order information unset($route['order']); $routes[$order] = $route; } } } ksort($routes); return $routes; }
[ "public", "function", "getRoutesFor", "(", "$", "menuId", ",", "array", "$", "parameters", "=", "array", "(", ")", ")", "{", "$", "routes", "=", "array", "(", ")", ";", "$", "routeCollection", "=", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "getRouteCollection", "(", ")", ";", "foreach", "(", "$", "routeCollection", "->", "all", "(", ")", "as", "$", "routeKey", "=>", "$", "route", ")", "{", "if", "(", "$", "route", "->", "hasOption", "(", "'menus'", ")", ")", "{", "if", "(", "array_key_exists", "(", "$", "menuId", ",", "$", "route", "->", "getOption", "(", "'menus'", ")", ")", ")", "{", "$", "route", "=", "$", "route", "->", "getOption", "(", "'menus'", ")", "[", "$", "menuId", "]", ";", "$", "route", "[", "'key'", "]", "=", "$", "routeKey", ";", "$", "order", "=", "$", "this", "->", "resolveOrder", "(", "$", "routes", ",", "$", "route", "[", "'order'", "]", ")", ";", "//we do not want to duplicate order information", "unset", "(", "$", "route", "[", "'order'", "]", ")", ";", "$", "routes", "[", "$", "order", "]", "=", "$", "route", ";", "}", "}", "}", "ksort", "(", "$", "routes", ")", ";", "return", "$", "routes", ";", "}" ]
Return an array of routes added to $menuId, The array is aimed to build route with MenuTwig @param string $menuId @param array $parameters see https://redmine.champs-libres.coop/issues/179 @return array
[ "Return", "an", "array", "of", "routes", "added", "to", "$menuId", "The", "array", "is", "aimed", "to", "build", "route", "with", "MenuTwig" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Routing/MenuComposer.php#L61-L84
Chill-project/Main
Routing/MenuComposer.php
MenuComposer.resolveOrder
private function resolveOrder($routes, $order){ if (isset($routes[$order])) { return $this->resolveOrder($routes, $order + 1); } else { return $order; } }
php
private function resolveOrder($routes, $order){ if (isset($routes[$order])) { return $this->resolveOrder($routes, $order + 1); } else { return $order; } }
[ "private", "function", "resolveOrder", "(", "$", "routes", ",", "$", "order", ")", "{", "if", "(", "isset", "(", "$", "routes", "[", "$", "order", "]", ")", ")", "{", "return", "$", "this", "->", "resolveOrder", "(", "$", "routes", ",", "$", "order", "+", "1", ")", ";", "}", "else", "{", "return", "$", "order", ";", "}", "}" ]
recursive function to resolve the order of a array of routes. If the order chosen in routing.yml is already in used, find the first next order available. @param array $routes the routes previously added @param int $order @return int
[ "recursive", "function", "to", "resolve", "the", "order", "of", "a", "array", "of", "routes", ".", "If", "the", "order", "chosen", "in", "routing", ".", "yml", "is", "already", "in", "used", "find", "the", "first", "next", "order", "available", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Routing/MenuComposer.php#L95-L101
ondrakoupil/tools
src/Arrays.php
Arrays.arrayize
static function arrayize($value, $forceArrayFromObject = false) { if (is_array($value)) return $value; if (is_bool($value) or $value===null) return array(); if ($value instanceof \Traversable) { if ($forceArrayFromObject) { return iterator_to_array($value); } return $value; } if ($value instanceof \ArrayAccess) { return $value; } return array(0=>$value); }
php
static function arrayize($value, $forceArrayFromObject = false) { if (is_array($value)) return $value; if (is_bool($value) or $value===null) return array(); if ($value instanceof \Traversable) { if ($forceArrayFromObject) { return iterator_to_array($value); } return $value; } if ($value instanceof \ArrayAccess) { return $value; } return array(0=>$value); }
[ "static", "function", "arrayize", "(", "$", "value", ",", "$", "forceArrayFromObject", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "return", "$", "value", ";", "if", "(", "is_bool", "(", "$", "value", ")", "or", "$", "value", "===", "null", ")", "return", "array", "(", ")", ";", "if", "(", "$", "value", "instanceof", "\\", "Traversable", ")", "{", "if", "(", "$", "forceArrayFromObject", ")", "{", "return", "iterator_to_array", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}", "if", "(", "$", "value", "instanceof", "\\", "ArrayAccess", ")", "{", "return", "$", "value", ";", "}", "return", "array", "(", "0", "=>", "$", "value", ")", ";", "}" ]
Zajistí, aby zadaný argument byl array. Převede booly nebo nully na array(), pole nechá být, ArrayAccess a Traversable také, vše ostatní převede na array(0=>$hodnota) @param mixed $value @param bool $forceArrayFromObject True = Traversable objekty také převádět na array @return array|\ArrayAccess|\Traversable
[ "Zajistí", "aby", "zadaný", "argument", "byl", "array", "." ]
train
https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L17-L30
ondrakoupil/tools
src/Arrays.php
Arrays.transform
static function transform($input,$outputKeys,$outputValue) { $input=self::arrayize($input); $output=array(); foreach($input as $inputI=>$inputR) { if (is_array($outputValue)) { $novaPolozka=array(); foreach($outputValue as $ov) { if ($ov===false) { $novaPolozka["key"]=$inputI; } else { if (isset($inputR[$ov])) { $novaPolozka[$ov]=$inputR[$ov]; } else { $novaPolozka[$ov]=null; } } } } else { if ($outputValue===true) { $novaPolozka=$inputR; } elseif ($outputValue===false) { $novaPolozka=$inputI; } elseif (isset($inputR[$outputValue])) { $novaPolozka=$inputR[$outputValue]; } else { $novaPolozka=null; } } if ($outputKeys===false) { $output[]=$novaPolozka; } elseif ($outputKeys===true) { $output[$inputI]=$novaPolozka; } else { if (isset($inputR[$outputKeys])) { $output[$inputR[$outputKeys]]=$novaPolozka; } else { $output[]=$novaPolozka; } } } return $output; }
php
static function transform($input,$outputKeys,$outputValue) { $input=self::arrayize($input); $output=array(); foreach($input as $inputI=>$inputR) { if (is_array($outputValue)) { $novaPolozka=array(); foreach($outputValue as $ov) { if ($ov===false) { $novaPolozka["key"]=$inputI; } else { if (isset($inputR[$ov])) { $novaPolozka[$ov]=$inputR[$ov]; } else { $novaPolozka[$ov]=null; } } } } else { if ($outputValue===true) { $novaPolozka=$inputR; } elseif ($outputValue===false) { $novaPolozka=$inputI; } elseif (isset($inputR[$outputValue])) { $novaPolozka=$inputR[$outputValue]; } else { $novaPolozka=null; } } if ($outputKeys===false) { $output[]=$novaPolozka; } elseif ($outputKeys===true) { $output[$inputI]=$novaPolozka; } else { if (isset($inputR[$outputKeys])) { $output[$inputR[$outputKeys]]=$novaPolozka; } else { $output[]=$novaPolozka; } } } return $output; }
[ "static", "function", "transform", "(", "$", "input", ",", "$", "outputKeys", ",", "$", "outputValue", ")", "{", "$", "input", "=", "self", "::", "arrayize", "(", "$", "input", ")", ";", "$", "output", "=", "array", "(", ")", ";", "foreach", "(", "$", "input", "as", "$", "inputI", "=>", "$", "inputR", ")", "{", "if", "(", "is_array", "(", "$", "outputValue", ")", ")", "{", "$", "novaPolozka", "=", "array", "(", ")", ";", "foreach", "(", "$", "outputValue", "as", "$", "ov", ")", "{", "if", "(", "$", "ov", "===", "false", ")", "{", "$", "novaPolozka", "[", "\"key\"", "]", "=", "$", "inputI", ";", "}", "else", "{", "if", "(", "isset", "(", "$", "inputR", "[", "$", "ov", "]", ")", ")", "{", "$", "novaPolozka", "[", "$", "ov", "]", "=", "$", "inputR", "[", "$", "ov", "]", ";", "}", "else", "{", "$", "novaPolozka", "[", "$", "ov", "]", "=", "null", ";", "}", "}", "}", "}", "else", "{", "if", "(", "$", "outputValue", "===", "true", ")", "{", "$", "novaPolozka", "=", "$", "inputR", ";", "}", "elseif", "(", "$", "outputValue", "===", "false", ")", "{", "$", "novaPolozka", "=", "$", "inputI", ";", "}", "elseif", "(", "isset", "(", "$", "inputR", "[", "$", "outputValue", "]", ")", ")", "{", "$", "novaPolozka", "=", "$", "inputR", "[", "$", "outputValue", "]", ";", "}", "else", "{", "$", "novaPolozka", "=", "null", ";", "}", "}", "if", "(", "$", "outputKeys", "===", "false", ")", "{", "$", "output", "[", "]", "=", "$", "novaPolozka", ";", "}", "elseif", "(", "$", "outputKeys", "===", "true", ")", "{", "$", "output", "[", "$", "inputI", "]", "=", "$", "novaPolozka", ";", "}", "else", "{", "if", "(", "isset", "(", "$", "inputR", "[", "$", "outputKeys", "]", ")", ")", "{", "$", "output", "[", "$", "inputR", "[", "$", "outputKeys", "]", "]", "=", "$", "novaPolozka", ";", "}", "else", "{", "$", "output", "[", "]", "=", "$", "novaPolozka", ";", "}", "}", "}", "return", "$", "output", ";", "}" ]
Transformace dvoj(či více)-rozměrných polí či Traversable objektů @param array $input Vstupní pole. @param mixed $outputKeys Jak mají být tvořeny indexy výstupního pole? <br />False = numericky indexovat od 0. <br />True = zachovat původní indexy. <br />Cokoliv jiného - použít takto pojmenovanou hodnotu z druhého rozměru @param mixed $outputValue Jak mají být tvořeny hodnoty výstupního pole? <br />True = zachovat původní položky <br />String nebo array = vybrat pouze takto pojmenovanou položku nebo položky. <br />False = původní index. Může být zadán i jako prvek pole, pak bude daný prvek mít index [key]. @return mixed
[ "Transformace", "dvoj", "(", "či", "více", ")", "-", "rozměrných", "polí", "či", "Traversable", "objektů" ]
train
https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L56-L99
ondrakoupil/tools
src/Arrays.php
Arrays.sortByExternalKeys
static function sortByExternalKeys($dataArray, $keysArray) { $returnArray = array(); foreach($keysArray as $k) { if (isset($dataArray[$k])) { $returnArray[$k] = $dataArray[$k]; } else { $returnArray[$k] = null; } } return $returnArray; }
php
static function sortByExternalKeys($dataArray, $keysArray) { $returnArray = array(); foreach($keysArray as $k) { if (isset($dataArray[$k])) { $returnArray[$k] = $dataArray[$k]; } else { $returnArray[$k] = null; } } return $returnArray; }
[ "static", "function", "sortByExternalKeys", "(", "$", "dataArray", ",", "$", "keysArray", ")", "{", "$", "returnArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "keysArray", "as", "$", "k", ")", "{", "if", "(", "isset", "(", "$", "dataArray", "[", "$", "k", "]", ")", ")", "{", "$", "returnArray", "[", "$", "k", "]", "=", "$", "dataArray", "[", "$", "k", "]", ";", "}", "else", "{", "$", "returnArray", "[", "$", "k", "]", "=", "null", ";", "}", "}", "return", "$", "returnArray", ";", "}" ]
Seřadí prvky v jednom poli dle klíčů podle pořadí hodnot v jiném poli @param array $dataArray @param array $keysArray @return null
[ "Seřadí", "prvky", "v", "jednom", "poli", "dle", "klíčů", "podle", "pořadí", "hodnot", "v", "jiném", "poli" ]
train
https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L107-L117
ondrakoupil/tools
src/Arrays.php
Arrays.valuePicker
static function valuePicker($array, $hodnota, $ignoredValues = null) { $vrat=array(); foreach($array as $a) { if ((is_array($a) or ($a instanceof \ArrayAccess)) and isset($a[$hodnota])) { $vrat[]=$a[$hodnota]; } elseif (is_object($a) and isset($a->$hodnota)) { $vrat[]=$a->$hodnota; } } $vrat=array_values(array_unique($vrat)); if ($ignoredValues) { $ignoredValues = self::arrayize($ignoredValues); foreach($vrat as $i=>$r) { if (in_array($r, $ignoredValues, true)) unset($vrat[$i]); } $vrat = array_values($vrat); } return $vrat; }
php
static function valuePicker($array, $hodnota, $ignoredValues = null) { $vrat=array(); foreach($array as $a) { if ((is_array($a) or ($a instanceof \ArrayAccess)) and isset($a[$hodnota])) { $vrat[]=$a[$hodnota]; } elseif (is_object($a) and isset($a->$hodnota)) { $vrat[]=$a->$hodnota; } } $vrat=array_values(array_unique($vrat)); if ($ignoredValues) { $ignoredValues = self::arrayize($ignoredValues); foreach($vrat as $i=>$r) { if (in_array($r, $ignoredValues, true)) unset($vrat[$i]); } $vrat = array_values($vrat); } return $vrat; }
[ "static", "function", "valuePicker", "(", "$", "array", ",", "$", "hodnota", ",", "$", "ignoredValues", "=", "null", ")", "{", "$", "vrat", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "a", ")", "{", "if", "(", "(", "is_array", "(", "$", "a", ")", "or", "(", "$", "a", "instanceof", "\\", "ArrayAccess", ")", ")", "and", "isset", "(", "$", "a", "[", "$", "hodnota", "]", ")", ")", "{", "$", "vrat", "[", "]", "=", "$", "a", "[", "$", "hodnota", "]", ";", "}", "elseif", "(", "is_object", "(", "$", "a", ")", "and", "isset", "(", "$", "a", "->", "$", "hodnota", ")", ")", "{", "$", "vrat", "[", "]", "=", "$", "a", "->", "$", "hodnota", ";", "}", "}", "$", "vrat", "=", "array_values", "(", "array_unique", "(", "$", "vrat", ")", ")", ";", "if", "(", "$", "ignoredValues", ")", "{", "$", "ignoredValues", "=", "self", "::", "arrayize", "(", "$", "ignoredValues", ")", ";", "foreach", "(", "$", "vrat", "as", "$", "i", "=>", "$", "r", ")", "{", "if", "(", "in_array", "(", "$", "r", ",", "$", "ignoredValues", ",", "true", ")", ")", "unset", "(", "$", "vrat", "[", "$", "i", "]", ")", ";", "}", "$", "vrat", "=", "array_values", "(", "$", "vrat", ")", ";", "}", "return", "$", "vrat", ";", "}" ]
Vybere všechny možné hodnoty z dvourozměrného asociativního pole či Traversable objektu. Funkce iteruje po prvním rozměru pole $array a ve druhém rozměru hledá $hodnota. Ve druhém rozměru mohou být jak pole, tak objekty. Vrátí všechny různé nalezené hodnoty (bez duplikátů). @param array $array @param string $hodnota Index nebo jméno hodnoty, který chceme získat @param array $ignoredValues Volitelně lze doplnit hodnoty, které mají být ignorovány (pro porovnávání se používá striktní === ekvivalence) @return array
[ "Vybere", "všechny", "možné", "hodnoty", "z", "dvourozměrného", "asociativního", "pole", "či", "Traversable", "objektu", ".", "Funkce", "iteruje", "po", "prvním", "rozměru", "pole", "$array", "a", "ve", "druhém", "rozměru", "hledá", "$hodnota", ".", "Ve", "druhém", "rozměru", "mohou", "být", "jak", "pole", "tak", "objekty", ".", "Vrátí", "všechny", "různé", "nalezené", "hodnoty", "(", "bez", "duplikátů", ")", "." ]
train
https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L131-L151