repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
hiqdev/minii-widgets
src/DetailView.php
DetailView.normalizeAttributes
protected function normalizeAttributes() { if ($this->attributes === null) { if ($this->model instanceof Model) { $this->attributes = $this->model->attributes(); } elseif (is_object($this->model)) { $this->attributes = $this->model instanceof Arrayable ? $this->model->toArray() : array_keys(get_object_vars($this->model)); } elseif (is_array($this->model)) { $this->attributes = array_keys($this->model); } else { throw new InvalidConfigException('The "model" property must be either an array or an object.'); } sort($this->attributes); } foreach ($this->attributes as $i => $attribute) { if (is_string($attribute)) { if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $attribute, $matches)) { throw new InvalidConfigException('The attribute must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"'); } $attribute = [ 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', 'label' => isset($matches[5]) ? $matches[5] : null, ]; } if (!is_array($attribute)) { throw new InvalidConfigException('The attribute configuration must be an array.'); } if (isset($attribute['visible']) && !$attribute['visible']) { unset($this->attributes[$i]); continue; } if (!isset($attribute['format'])) { $attribute['format'] = 'text'; } if (isset($attribute['attribute'])) { $attributeName = $attribute['attribute']; if (!isset($attribute['label'])) { $attribute['label'] = $this->model instanceof Model ? $this->model->getAttributeLabel($attributeName) : Inflector::camel2words($attributeName, true); } if (!array_key_exists('value', $attribute)) { $attribute['value'] = ArrayHelper::getValue($this->model, $attributeName); } } elseif (!isset($attribute['label']) || !array_key_exists('value', $attribute)) { throw new InvalidConfigException('The attribute configuration requires the "attribute" element to determine the value and display label.'); } $this->attributes[$i] = $attribute; } }
php
protected function normalizeAttributes() { if ($this->attributes === null) { if ($this->model instanceof Model) { $this->attributes = $this->model->attributes(); } elseif (is_object($this->model)) { $this->attributes = $this->model instanceof Arrayable ? $this->model->toArray() : array_keys(get_object_vars($this->model)); } elseif (is_array($this->model)) { $this->attributes = array_keys($this->model); } else { throw new InvalidConfigException('The "model" property must be either an array or an object.'); } sort($this->attributes); } foreach ($this->attributes as $i => $attribute) { if (is_string($attribute)) { if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $attribute, $matches)) { throw new InvalidConfigException('The attribute must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"'); } $attribute = [ 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', 'label' => isset($matches[5]) ? $matches[5] : null, ]; } if (!is_array($attribute)) { throw new InvalidConfigException('The attribute configuration must be an array.'); } if (isset($attribute['visible']) && !$attribute['visible']) { unset($this->attributes[$i]); continue; } if (!isset($attribute['format'])) { $attribute['format'] = 'text'; } if (isset($attribute['attribute'])) { $attributeName = $attribute['attribute']; if (!isset($attribute['label'])) { $attribute['label'] = $this->model instanceof Model ? $this->model->getAttributeLabel($attributeName) : Inflector::camel2words($attributeName, true); } if (!array_key_exists('value', $attribute)) { $attribute['value'] = ArrayHelper::getValue($this->model, $attributeName); } } elseif (!isset($attribute['label']) || !array_key_exists('value', $attribute)) { throw new InvalidConfigException('The attribute configuration requires the "attribute" element to determine the value and display label.'); } $this->attributes[$i] = $attribute; } }
[ "protected", "function", "normalizeAttributes", "(", ")", "{", "if", "(", "$", "this", "->", "attributes", "===", "null", ")", "{", "if", "(", "$", "this", "->", "model", "instanceof", "Model", ")", "{", "$", "this", "->", "attributes", "=", "$", "this", "->", "model", "->", "attributes", "(", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "this", "->", "model", ")", ")", "{", "$", "this", "->", "attributes", "=", "$", "this", "->", "model", "instanceof", "Arrayable", "?", "$", "this", "->", "model", "->", "toArray", "(", ")", ":", "array_keys", "(", "get_object_vars", "(", "$", "this", "->", "model", ")", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "this", "->", "model", ")", ")", "{", "$", "this", "->", "attributes", "=", "array_keys", "(", "$", "this", "->", "model", ")", ";", "}", "else", "{", "throw", "new", "InvalidConfigException", "(", "'The \"model\" property must be either an array or an object.'", ")", ";", "}", "sort", "(", "$", "this", "->", "attributes", ")", ";", "}", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "i", "=>", "$", "attribute", ")", "{", "if", "(", "is_string", "(", "$", "attribute", ")", ")", "{", "if", "(", "!", "preg_match", "(", "'/^([\\w\\.]+)(:(\\w*))?(:(.*))?$/'", ",", "$", "attribute", ",", "$", "matches", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "'The attribute must be specified in the format of \"attribute\", \"attribute:format\" or \"attribute:format:label\"'", ")", ";", "}", "$", "attribute", "=", "[", "'attribute'", "=>", "$", "matches", "[", "1", "]", ",", "'format'", "=>", "isset", "(", "$", "matches", "[", "3", "]", ")", "?", "$", "matches", "[", "3", "]", ":", "'text'", ",", "'label'", "=>", "isset", "(", "$", "matches", "[", "5", "]", ")", "?", "$", "matches", "[", "5", "]", ":", "null", ",", "]", ";", "}", "if", "(", "!", "is_array", "(", "$", "attribute", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "'The attribute configuration must be an array.'", ")", ";", "}", "if", "(", "isset", "(", "$", "attribute", "[", "'visible'", "]", ")", "&&", "!", "$", "attribute", "[", "'visible'", "]", ")", "{", "unset", "(", "$", "this", "->", "attributes", "[", "$", "i", "]", ")", ";", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "attribute", "[", "'format'", "]", ")", ")", "{", "$", "attribute", "[", "'format'", "]", "=", "'text'", ";", "}", "if", "(", "isset", "(", "$", "attribute", "[", "'attribute'", "]", ")", ")", "{", "$", "attributeName", "=", "$", "attribute", "[", "'attribute'", "]", ";", "if", "(", "!", "isset", "(", "$", "attribute", "[", "'label'", "]", ")", ")", "{", "$", "attribute", "[", "'label'", "]", "=", "$", "this", "->", "model", "instanceof", "Model", "?", "$", "this", "->", "model", "->", "getAttributeLabel", "(", "$", "attributeName", ")", ":", "Inflector", "::", "camel2words", "(", "$", "attributeName", ",", "true", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'value'", ",", "$", "attribute", ")", ")", "{", "$", "attribute", "[", "'value'", "]", "=", "ArrayHelper", "::", "getValue", "(", "$", "this", "->", "model", ",", "$", "attributeName", ")", ";", "}", "}", "elseif", "(", "!", "isset", "(", "$", "attribute", "[", "'label'", "]", ")", "||", "!", "array_key_exists", "(", "'value'", ",", "$", "attribute", ")", ")", "{", "throw", "new", "InvalidConfigException", "(", "'The attribute configuration requires the \"attribute\" element to determine the value and display label.'", ")", ";", "}", "$", "this", "->", "attributes", "[", "$", "i", "]", "=", "$", "attribute", ";", "}", "}" ]
Normalizes the attribute specifications. @throws InvalidConfigException
[ "Normalizes", "the", "attribute", "specifications", "." ]
b8bc54a3645e9e45c228e3ec81b11ff4775385c3
https://github.com/hiqdev/minii-widgets/blob/b8bc54a3645e9e45c228e3ec81b11ff4775385c3/src/DetailView.php#L170-L223
train
jenskooij/cloudcontrol
src/storage/storage/UsersStorage.php
UsersStorage.getUserBySlug
public function getUserBySlug($slug) { $return = array(); $users = $this->repository->users; foreach ($users as $user) { if ($user->slug == $slug) { $return = $user; break; } } return $return; }
php
public function getUserBySlug($slug) { $return = array(); $users = $this->repository->users; foreach ($users as $user) { if ($user->slug == $slug) { $return = $user; break; } } return $return; }
[ "public", "function", "getUserBySlug", "(", "$", "slug", ")", "{", "$", "return", "=", "array", "(", ")", ";", "$", "users", "=", "$", "this", "->", "repository", "->", "users", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "if", "(", "$", "user", "->", "slug", "==", "$", "slug", ")", "{", "$", "return", "=", "$", "user", ";", "break", ";", "}", "}", "return", "$", "return", ";", "}" ]
Get user by slug @param $slug @return array
[ "Get", "user", "by", "slug" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/UsersStorage.php#L30-L43
train
jenskooij/cloudcontrol
src/storage/storage/UsersStorage.php
UsersStorage.deleteUserBySlug
public function deleteUserBySlug($slug) { $userToDelete = $this->getUserBySlug($slug); if (empty($userToDelete)) { throw new \Exception('Trying to delete a user that doesn\'t exist.'); } $users = $this->getUsers(); foreach ($users as $key => $user) { if ($user->slug == $userToDelete->slug) { unset($users[$key]); $this->repository->users = array_values($users); } } $this->save(); }
php
public function deleteUserBySlug($slug) { $userToDelete = $this->getUserBySlug($slug); if (empty($userToDelete)) { throw new \Exception('Trying to delete a user that doesn\'t exist.'); } $users = $this->getUsers(); foreach ($users as $key => $user) { if ($user->slug == $userToDelete->slug) { unset($users[$key]); $this->repository->users = array_values($users); } } $this->save(); }
[ "public", "function", "deleteUserBySlug", "(", "$", "slug", ")", "{", "$", "userToDelete", "=", "$", "this", "->", "getUserBySlug", "(", "$", "slug", ")", ";", "if", "(", "empty", "(", "$", "userToDelete", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Trying to delete a user that doesn\\'t exist.'", ")", ";", "}", "$", "users", "=", "$", "this", "->", "getUsers", "(", ")", ";", "foreach", "(", "$", "users", "as", "$", "key", "=>", "$", "user", ")", "{", "if", "(", "$", "user", "->", "slug", "==", "$", "userToDelete", "->", "slug", ")", "{", "unset", "(", "$", "users", "[", "$", "key", "]", ")", ";", "$", "this", "->", "repository", "->", "users", "=", "array_values", "(", "$", "users", ")", ";", "}", "}", "$", "this", "->", "save", "(", ")", ";", "}" ]
Delete user by slug @param $slug @throws \Exception
[ "Delete", "user", "by", "slug" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/UsersStorage.php#L101-L115
train
tedmoyses/glomr-lib
src/Build/BladeBuilder.php
BladeBuilder.buildPathFromSource
private function buildPathFromSource(string $path) :string { //return $this->buildContext->getPath('build') . '/' . return str_replace('.', '/', str_replace($this->context . ".", '', $this->viewNameFromSource($path))) . $this->buildExtension; }
php
private function buildPathFromSource(string $path) :string { //return $this->buildContext->getPath('build') . '/' . return str_replace('.', '/', str_replace($this->context . ".", '', $this->viewNameFromSource($path))) . $this->buildExtension; }
[ "private", "function", "buildPathFromSource", "(", "string", "$", "path", ")", ":", "string", "{", "//return $this->buildContext->getPath('build') . '/' .", "return", "str_replace", "(", "'.'", ",", "'/'", ",", "str_replace", "(", "$", "this", "->", "context", ".", "\".\"", ",", "''", ",", "$", "this", "->", "viewNameFromSource", "(", "$", "path", ")", ")", ")", ".", "$", "this", "->", "buildExtension", ";", "}" ]
start with the build path strip context from view name including first . replace remaining dots in view name with slashes add build extension @param string $path Source file path @return string destination path
[ "start", "with", "the", "build", "path", "strip", "context", "from", "view", "name", "including", "first", ".", "replace", "remaining", "dots", "in", "view", "name", "with", "slashes", "add", "build", "extension" ]
40c577fca0bb120f07a08fc444ed75460bd9021c
https://github.com/tedmoyses/glomr-lib/blob/40c577fca0bb120f07a08fc444ed75460bd9021c/src/Build/BladeBuilder.php#L116-L120
train
gr-group/grsupport
src/Classes/Support.php
Support.agent
public function agent($arg = null) { $agent = new Agent(); if ($arg) { return $agent->is($arg); } return new Agent(); }
php
public function agent($arg = null) { $agent = new Agent(); if ($arg) { return $agent->is($arg); } return new Agent(); }
[ "public", "function", "agent", "(", "$", "arg", "=", "null", ")", "{", "$", "agent", "=", "new", "Agent", "(", ")", ";", "if", "(", "$", "arg", ")", "{", "return", "$", "agent", "->", "is", "(", "$", "arg", ")", ";", "}", "return", "new", "Agent", "(", ")", ";", "}" ]
Start Jenssegers Agent @return Jenssegers\Agent\Agent
[ "Start", "Jenssegers", "Agent" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L19-L28
train
gr-group/grsupport
src/Classes/Support.php
Support.authRequest
public function authRequest($guard = null) { return is_null($guard) ? request()->user() ?? request()->user('api') : request()->user($guard); }
php
public function authRequest($guard = null) { return is_null($guard) ? request()->user() ?? request()->user('api') : request()->user($guard); }
[ "public", "function", "authRequest", "(", "$", "guard", "=", "null", ")", "{", "return", "is_null", "(", "$", "guard", ")", "?", "request", "(", ")", "->", "user", "(", ")", "??", "request", "(", ")", "->", "user", "(", "'api'", ")", ":", "request", "(", ")", "->", "user", "(", "$", "guard", ")", ";", "}" ]
Get auth request by guard @param string $guard Web / Api @return Illuminate\Database\Eloquent\Model
[ "Get", "auth", "request", "by", "guard" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L54-L57
train
gr-group/grsupport
src/Classes/Support.php
Support.randomNumbers
public function randomNumbers($length = 6) { $nums = '0123456789'; $out = $nums[mt_rand(1, strlen($nums)-1)]; for ($p = 0; $p < $length-1; $p++) { $out .= $nums[mt_rand(0, strlen($nums)-1)]; } return $out; }
php
public function randomNumbers($length = 6) { $nums = '0123456789'; $out = $nums[mt_rand(1, strlen($nums)-1)]; for ($p = 0; $p < $length-1; $p++) { $out .= $nums[mt_rand(0, strlen($nums)-1)]; } return $out; }
[ "public", "function", "randomNumbers", "(", "$", "length", "=", "6", ")", "{", "$", "nums", "=", "'0123456789'", ";", "$", "out", "=", "$", "nums", "[", "mt_rand", "(", "1", ",", "strlen", "(", "$", "nums", ")", "-", "1", ")", "]", ";", "for", "(", "$", "p", "=", "0", ";", "$", "p", "<", "$", "length", "-", "1", ";", "$", "p", "++", ")", "{", "$", "out", ".=", "$", "nums", "[", "mt_rand", "(", "0", ",", "strlen", "(", "$", "nums", ")", "-", "1", ")", "]", ";", "}", "return", "$", "out", ";", "}" ]
Generate random numbers @param integer $length @return string
[ "Generate", "random", "numbers" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L121-L132
train
gr-group/grsupport
src/Classes/Support.php
Support.fileSearch
public function fileSearch($file, $subject) { return str_contains(file_get_contents(str_contains($file, '/') ? $file : $file), $subject); }
php
public function fileSearch($file, $subject) { return str_contains(file_get_contents(str_contains($file, '/') ? $file : $file), $subject); }
[ "public", "function", "fileSearch", "(", "$", "file", ",", "$", "subject", ")", "{", "return", "str_contains", "(", "file_get_contents", "(", "str_contains", "(", "$", "file", ",", "'/'", ")", "?", "$", "file", ":", "$", "file", ")", ",", "$", "subject", ")", ";", "}" ]
Search for a content within a file @param string $file @param string $subject @return boolean
[ "Search", "for", "a", "content", "within", "a", "file" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L159-L162
train
gr-group/grsupport
src/Classes/Support.php
Support.fileEdit
public function fileEdit($file, $search, $replace) { file_put_contents($file, str_replace( $search, $replace, file_get_contents($file) )); }
php
public function fileEdit($file, $search, $replace) { file_put_contents($file, str_replace( $search, $replace, file_get_contents($file) )); }
[ "public", "function", "fileEdit", "(", "$", "file", ",", "$", "search", ",", "$", "replace", ")", "{", "file_put_contents", "(", "$", "file", ",", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "file_get_contents", "(", "$", "file", ")", ")", ")", ";", "}" ]
Edit part of the contents of a file @param string $file @param string $search @param string $replace @return void
[ "Edit", "part", "of", "the", "contents", "of", "a", "file" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L171-L178
train
gr-group/grsupport
src/Classes/Support.php
Support.rangeHours
public function rangeHours($start, $end, $interval = 1, $select = true) { $tStart = strtotime($start); $tEnd = strtotime($end); $tNow = $tStart; $hours = []; while ($tNow <= $tEnd) { $hours[] = date("H:i", $tNow); $tNow = strtotime('+'.$interval.' hour', $tNow); } if ($select) { $hours = collect($hours)->map(function ($item) { return [ $item => $item ]; })->collapse()->all(); } return $hours; }
php
public function rangeHours($start, $end, $interval = 1, $select = true) { $tStart = strtotime($start); $tEnd = strtotime($end); $tNow = $tStart; $hours = []; while ($tNow <= $tEnd) { $hours[] = date("H:i", $tNow); $tNow = strtotime('+'.$interval.' hour', $tNow); } if ($select) { $hours = collect($hours)->map(function ($item) { return [ $item => $item ]; })->collapse()->all(); } return $hours; }
[ "public", "function", "rangeHours", "(", "$", "start", ",", "$", "end", ",", "$", "interval", "=", "1", ",", "$", "select", "=", "true", ")", "{", "$", "tStart", "=", "strtotime", "(", "$", "start", ")", ";", "$", "tEnd", "=", "strtotime", "(", "$", "end", ")", ";", "$", "tNow", "=", "$", "tStart", ";", "$", "hours", "=", "[", "]", ";", "while", "(", "$", "tNow", "<=", "$", "tEnd", ")", "{", "$", "hours", "[", "]", "=", "date", "(", "\"H:i\"", ",", "$", "tNow", ")", ";", "$", "tNow", "=", "strtotime", "(", "'+'", ".", "$", "interval", ".", "' hour'", ",", "$", "tNow", ")", ";", "}", "if", "(", "$", "select", ")", "{", "$", "hours", "=", "collect", "(", "$", "hours", ")", "->", "map", "(", "function", "(", "$", "item", ")", "{", "return", "[", "$", "item", "=>", "$", "item", "]", ";", "}", ")", "->", "collapse", "(", ")", "->", "all", "(", ")", ";", "}", "return", "$", "hours", ";", "}" ]
Interval between two hours @param string $start 01:00:00 @param string $end 23:00:00 @param integer $interval Interval in hours @param boolean $select For use in select of a form or array only @return array
[ "Interval", "between", "two", "hours" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L203-L224
train
gr-group/grsupport
src/Classes/Support.php
Support.limtitLines
public function limtitLines($str, $lines = 1) { $line = "\n"; for ($i=2; $i<=$lines; $i++) { $line .= "\n"; } return preg_replace("/[\r\n]+/", "$line", $str); }
php
public function limtitLines($str, $lines = 1) { $line = "\n"; for ($i=2; $i<=$lines; $i++) { $line .= "\n"; } return preg_replace("/[\r\n]+/", "$line", $str); }
[ "public", "function", "limtitLines", "(", "$", "str", ",", "$", "lines", "=", "1", ")", "{", "$", "line", "=", "\"\\n\"", ";", "for", "(", "$", "i", "=", "2", ";", "$", "i", "<=", "$", "lines", ";", "$", "i", "++", ")", "{", "$", "line", ".=", "\"\\n\"", ";", "}", "return", "preg_replace", "(", "\"/[\\r\\n]+/\"", ",", "\"$line\"", ",", "$", "str", ")", ";", "}" ]
Limits the amount of line breaks in a string @param string $str @param integer $lines Number of lines to be limited @return string
[ "Limits", "the", "amount", "of", "line", "breaks", "in", "a", "string" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L232-L239
train
gr-group/grsupport
src/Classes/Support.php
Support.urlParser
public function urlParser($str, $rule) { $linkify = new Linkify(['callback' => function ($url, $caption, $isEmail) use ($rule) { $rule = str_replace('[url]', $url, $rule); $rule = str_replace('[caption]', $caption, $rule); return $rule; }]); return $linkify->process($str); }
php
public function urlParser($str, $rule) { $linkify = new Linkify(['callback' => function ($url, $caption, $isEmail) use ($rule) { $rule = str_replace('[url]', $url, $rule); $rule = str_replace('[caption]', $caption, $rule); return $rule; }]); return $linkify->process($str); }
[ "public", "function", "urlParser", "(", "$", "str", ",", "$", "rule", ")", "{", "$", "linkify", "=", "new", "Linkify", "(", "[", "'callback'", "=>", "function", "(", "$", "url", ",", "$", "caption", ",", "$", "isEmail", ")", "use", "(", "$", "rule", ")", "{", "$", "rule", "=", "str_replace", "(", "'[url]'", ",", "$", "url", ",", "$", "rule", ")", ";", "$", "rule", "=", "str_replace", "(", "'[caption]'", ",", "$", "caption", ",", "$", "rule", ")", ";", "return", "$", "rule", ";", "}", "]", ")", ";", "return", "$", "linkify", "->", "process", "(", "$", "str", ")", ";", "}" ]
Parse URLs from string @param string $str @param string $rule substitution rule, for example: <a href="[url]">[caption]</a> @return string
[ "Parse", "URLs", "from", "string" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L257-L266
train
gr-group/grsupport
src/Classes/Support.php
Support.urlParserMultiple
public function urlParserMultiple($str, $rule, $html = null) { $explode = explode(';', $str); $url = collect($explode)->map(function ($item) use ($rule) { return $this->urlParser($item, $rule); }); if (is_null($html)) { $url = $url->all(); } else { $url = $url->implode($html); } return $url; }
php
public function urlParserMultiple($str, $rule, $html = null) { $explode = explode(';', $str); $url = collect($explode)->map(function ($item) use ($rule) { return $this->urlParser($item, $rule); }); if (is_null($html)) { $url = $url->all(); } else { $url = $url->implode($html); } return $url; }
[ "public", "function", "urlParserMultiple", "(", "$", "str", ",", "$", "rule", ",", "$", "html", "=", "null", ")", "{", "$", "explode", "=", "explode", "(", "';'", ",", "$", "str", ")", ";", "$", "url", "=", "collect", "(", "$", "explode", ")", "->", "map", "(", "function", "(", "$", "item", ")", "use", "(", "$", "rule", ")", "{", "return", "$", "this", "->", "urlParser", "(", "$", "item", ",", "$", "rule", ")", ";", "}", ")", ";", "if", "(", "is_null", "(", "$", "html", ")", ")", "{", "$", "url", "=", "$", "url", "->", "all", "(", ")", ";", "}", "else", "{", "$", "url", "=", "$", "url", "->", "implode", "(", "$", "html", ")", ";", "}", "return", "$", "url", ";", "}" ]
Parse multiple URLs from string separated by commas or semicolons @param string $str @param string $rule substitution rule, for example: <a href="[url]">[caption]</a> @param string $html if null returns array if filled with an html tag, returns a string separated by the tag @return mixed
[ "Parse", "multiple", "URLs", "from", "string", "separated", "by", "commas", "or", "semicolons" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L275-L289
train
gr-group/grsupport
src/Classes/Support.php
Support.countries
public function countries($by = null, $value = null) { $countries = json_decode(file_get_contents(__DIR__ . '/../../data/countries.json'), true); if (is_null($by) && is_null($value)) { $countries = collect($countries)->values()->all(); } else { if ($by == 'locale') { $value = str_replace(' ', '_', $value); $value = str_replace('-', '_', $value); } if ($by == 'locale' && strlen($value) == 2) { if ($value == 'en') { $value = 'en_US'; } elseif ($value == 'br') { $value = 'pt_BR'; } else { $value = $value.'_'.strtoupper($value); } } $countries = (object) collect($countries)->filter(function ($item) use ($by, $value) { return strtolower($item[$by]) == strtolower($value); })->values()->first(); } return $countries; }
php
public function countries($by = null, $value = null) { $countries = json_decode(file_get_contents(__DIR__ . '/../../data/countries.json'), true); if (is_null($by) && is_null($value)) { $countries = collect($countries)->values()->all(); } else { if ($by == 'locale') { $value = str_replace(' ', '_', $value); $value = str_replace('-', '_', $value); } if ($by == 'locale' && strlen($value) == 2) { if ($value == 'en') { $value = 'en_US'; } elseif ($value == 'br') { $value = 'pt_BR'; } else { $value = $value.'_'.strtoupper($value); } } $countries = (object) collect($countries)->filter(function ($item) use ($by, $value) { return strtolower($item[$by]) == strtolower($value); })->values()->first(); } return $countries; }
[ "public", "function", "countries", "(", "$", "by", "=", "null", ",", "$", "value", "=", "null", ")", "{", "$", "countries", "=", "json_decode", "(", "file_get_contents", "(", "__DIR__", ".", "'/../../data/countries.json'", ")", ",", "true", ")", ";", "if", "(", "is_null", "(", "$", "by", ")", "&&", "is_null", "(", "$", "value", ")", ")", "{", "$", "countries", "=", "collect", "(", "$", "countries", ")", "->", "values", "(", ")", "->", "all", "(", ")", ";", "}", "else", "{", "if", "(", "$", "by", "==", "'locale'", ")", "{", "$", "value", "=", "str_replace", "(", "' '", ",", "'_'", ",", "$", "value", ")", ";", "$", "value", "=", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "value", ")", ";", "}", "if", "(", "$", "by", "==", "'locale'", "&&", "strlen", "(", "$", "value", ")", "==", "2", ")", "{", "if", "(", "$", "value", "==", "'en'", ")", "{", "$", "value", "=", "'en_US'", ";", "}", "elseif", "(", "$", "value", "==", "'br'", ")", "{", "$", "value", "=", "'pt_BR'", ";", "}", "else", "{", "$", "value", "=", "$", "value", ".", "'_'", ".", "strtoupper", "(", "$", "value", ")", ";", "}", "}", "$", "countries", "=", "(", "object", ")", "collect", "(", "$", "countries", ")", "->", "filter", "(", "function", "(", "$", "item", ")", "use", "(", "$", "by", ",", "$", "value", ")", "{", "return", "strtolower", "(", "$", "item", "[", "$", "by", "]", ")", "==", "strtolower", "(", "$", "value", ")", ";", "}", ")", "->", "values", "(", ")", "->", "first", "(", ")", ";", "}", "return", "$", "countries", ";", "}" ]
Countries search and list @param string $by Column to search (locale, name, shortname, slug) @param string $value Value to search @return array
[ "Countries", "search", "and", "list" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L317-L345
train
gr-group/grsupport
src/Classes/Support.php
Support.countryCodeByLocale
public function countryCodeByLocale($locale) { if (str_contains($locale, ' ')) { $locale = str_replace(' ', '-', $locale); } if (strlen($locale) == 2) { if ($locale == 'en') { $locale = 'en-US'; } else { $locale = $locale.'-'.strtoupper($locale); } } return Locale::getRegion($locale); }
php
public function countryCodeByLocale($locale) { if (str_contains($locale, ' ')) { $locale = str_replace(' ', '-', $locale); } if (strlen($locale) == 2) { if ($locale == 'en') { $locale = 'en-US'; } else { $locale = $locale.'-'.strtoupper($locale); } } return Locale::getRegion($locale); }
[ "public", "function", "countryCodeByLocale", "(", "$", "locale", ")", "{", "if", "(", "str_contains", "(", "$", "locale", ",", "' '", ")", ")", "{", "$", "locale", "=", "str_replace", "(", "' '", ",", "'-'", ",", "$", "locale", ")", ";", "}", "if", "(", "strlen", "(", "$", "locale", ")", "==", "2", ")", "{", "if", "(", "$", "locale", "==", "'en'", ")", "{", "$", "locale", "=", "'en-US'", ";", "}", "else", "{", "$", "locale", "=", "$", "locale", ".", "'-'", ".", "strtoupper", "(", "$", "locale", ")", ";", "}", "}", "return", "Locale", "::", "getRegion", "(", "$", "locale", ")", ";", "}" ]
Get Country code by Locale @param string $locale pt-BR, en-US, es-ES, ... @return string
[ "Get", "Country", "code", "by", "Locale" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L352-L367
train
gr-group/grsupport
src/Classes/Support.php
Support.extractHashtags
public function extractHashtags($str, $type = 'arr') { preg_match_all("/(#\w+)/", $str, $matches); $matches = $type == 'arr' ? $matches[0] : implode(', ', $matches[0]); return $matches; }
php
public function extractHashtags($str, $type = 'arr') { preg_match_all("/(#\w+)/", $str, $matches); $matches = $type == 'arr' ? $matches[0] : implode(', ', $matches[0]); return $matches; }
[ "public", "function", "extractHashtags", "(", "$", "str", ",", "$", "type", "=", "'arr'", ")", "{", "preg_match_all", "(", "\"/(#\\w+)/\"", ",", "$", "str", ",", "$", "matches", ")", ";", "$", "matches", "=", "$", "type", "==", "'arr'", "?", "$", "matches", "[", "0", "]", ":", "implode", "(", "', '", ",", "$", "matches", "[", "0", "]", ")", ";", "return", "$", "matches", ";", "}" ]
Extract hashtags from strings @param string $str @param string $type arr || str @return mixed
[ "Extract", "hashtags", "from", "strings" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L432-L437
train
gr-group/grsupport
src/Classes/Support.php
Support.summaryNumbers
public function summaryNumbers($number) { $x = round($number); $x_number_format = number_format($x); $x_array = explode(',', $x_number_format); $x_parts = ['k', 'm', 'b', 't']; $x_count_parts = count($x_array) - 1; $x_display = $x; if (!isset($x_array[1])) { return $x_array[0]; } $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : ''); $x_display .= $x_parts[$x_count_parts - 1]; return $x_display; }
php
public function summaryNumbers($number) { $x = round($number); $x_number_format = number_format($x); $x_array = explode(',', $x_number_format); $x_parts = ['k', 'm', 'b', 't']; $x_count_parts = count($x_array) - 1; $x_display = $x; if (!isset($x_array[1])) { return $x_array[0]; } $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : ''); $x_display .= $x_parts[$x_count_parts - 1]; return $x_display; }
[ "public", "function", "summaryNumbers", "(", "$", "number", ")", "{", "$", "x", "=", "round", "(", "$", "number", ")", ";", "$", "x_number_format", "=", "number_format", "(", "$", "x", ")", ";", "$", "x_array", "=", "explode", "(", "','", ",", "$", "x_number_format", ")", ";", "$", "x_parts", "=", "[", "'k'", ",", "'m'", ",", "'b'", ",", "'t'", "]", ";", "$", "x_count_parts", "=", "count", "(", "$", "x_array", ")", "-", "1", ";", "$", "x_display", "=", "$", "x", ";", "if", "(", "!", "isset", "(", "$", "x_array", "[", "1", "]", ")", ")", "{", "return", "$", "x_array", "[", "0", "]", ";", "}", "$", "x_display", "=", "$", "x_array", "[", "0", "]", ".", "(", "(", "int", ")", "$", "x_array", "[", "1", "]", "[", "0", "]", "!==", "0", "?", "'.'", ".", "$", "x_array", "[", "1", "]", "[", "0", "]", ":", "''", ")", ";", "$", "x_display", ".=", "$", "x_parts", "[", "$", "x_count_parts", "-", "1", "]", ";", "return", "$", "x_display", ";", "}" ]
Format numbers in instagram followers style @param integer $number @return string
[ "Format", "numbers", "in", "instagram", "followers", "style" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L444-L460
train
gr-group/grsupport
src/Classes/Support.php
Support.urlWithParams
public function urlWithParams($path = null, $qs = [], $secure = null) { $url = app('url')->to($path, $secure); if (count($qs)){ foreach($qs as $key => $value){ $qs[$key] = sprintf('%s=%s',$key, urlencode($value)); } $url = sprintf('%s?%s', $url, implode('&', $qs)); } return $url; }
php
public function urlWithParams($path = null, $qs = [], $secure = null) { $url = app('url')->to($path, $secure); if (count($qs)){ foreach($qs as $key => $value){ $qs[$key] = sprintf('%s=%s',$key, urlencode($value)); } $url = sprintf('%s?%s', $url, implode('&', $qs)); } return $url; }
[ "public", "function", "urlWithParams", "(", "$", "path", "=", "null", ",", "$", "qs", "=", "[", "]", ",", "$", "secure", "=", "null", ")", "{", "$", "url", "=", "app", "(", "'url'", ")", "->", "to", "(", "$", "path", ",", "$", "secure", ")", ";", "if", "(", "count", "(", "$", "qs", ")", ")", "{", "foreach", "(", "$", "qs", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "qs", "[", "$", "key", "]", "=", "sprintf", "(", "'%s=%s'", ",", "$", "key", ",", "urlencode", "(", "$", "value", ")", ")", ";", "}", "$", "url", "=", "sprintf", "(", "'%s?%s'", ",", "$", "url", ",", "implode", "(", "'&'", ",", "$", "qs", ")", ")", ";", "}", "return", "$", "url", ";", "}" ]
Laravel route with query strings @param string $path @param array $qs @param boolean $secure @return string
[ "Laravel", "route", "with", "query", "strings" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L469-L479
train
gr-group/grsupport
src/Classes/Support.php
Support.getRoutesName
public function getRoutesName($contains = null, $exact = true) { $routeCollection = \Route::getRoutes(); $routes = collect($routeCollection)->map(function($item){ return $item->getName(); })->filter(function($item){ return !is_null($item); })->values(); if($contains){ return $routes->contains(function($item, $key) use($contains,$exact) { return $exact ? $contains == $item : str_contains($item, $contains); }); } return $routes; }
php
public function getRoutesName($contains = null, $exact = true) { $routeCollection = \Route::getRoutes(); $routes = collect($routeCollection)->map(function($item){ return $item->getName(); })->filter(function($item){ return !is_null($item); })->values(); if($contains){ return $routes->contains(function($item, $key) use($contains,$exact) { return $exact ? $contains == $item : str_contains($item, $contains); }); } return $routes; }
[ "public", "function", "getRoutesName", "(", "$", "contains", "=", "null", ",", "$", "exact", "=", "true", ")", "{", "$", "routeCollection", "=", "\\", "Route", "::", "getRoutes", "(", ")", ";", "$", "routes", "=", "collect", "(", "$", "routeCollection", ")", "->", "map", "(", "function", "(", "$", "item", ")", "{", "return", "$", "item", "->", "getName", "(", ")", ";", "}", ")", "->", "filter", "(", "function", "(", "$", "item", ")", "{", "return", "!", "is_null", "(", "$", "item", ")", ";", "}", ")", "->", "values", "(", ")", ";", "if", "(", "$", "contains", ")", "{", "return", "$", "routes", "->", "contains", "(", "function", "(", "$", "item", ",", "$", "key", ")", "use", "(", "$", "contains", ",", "$", "exact", ")", "{", "return", "$", "exact", "?", "$", "contains", "==", "$", "item", ":", "str_contains", "(", "$", "item", ",", "$", "contains", ")", ";", "}", ")", ";", "}", "return", "$", "routes", ";", "}" ]
Get all routes name @param string $contains Search for a specific word @param boolean $exact Exact search by word or not @return array
[ "Get", "all", "routes", "name" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L507-L524
train
gr-group/grsupport
src/Classes/Support.php
Support.getAllKeysRoutes
public function getAllKeysRoutes() { $routeCollection = \Route::getRoutes(); $routes = collect($routeCollection)->map(function($item){ return explode('/', $item->getPrefix()); })->values()->collapse()->filter(function($item, $key){ return $item !== ''; })->groupBy(function($item){ return $item; })->keys()->all(); return $routes; }
php
public function getAllKeysRoutes() { $routeCollection = \Route::getRoutes(); $routes = collect($routeCollection)->map(function($item){ return explode('/', $item->getPrefix()); })->values()->collapse()->filter(function($item, $key){ return $item !== ''; })->groupBy(function($item){ return $item; })->keys()->all(); return $routes; }
[ "public", "function", "getAllKeysRoutes", "(", ")", "{", "$", "routeCollection", "=", "\\", "Route", "::", "getRoutes", "(", ")", ";", "$", "routes", "=", "collect", "(", "$", "routeCollection", ")", "->", "map", "(", "function", "(", "$", "item", ")", "{", "return", "explode", "(", "'/'", ",", "$", "item", "->", "getPrefix", "(", ")", ")", ";", "}", ")", "->", "values", "(", ")", "->", "collapse", "(", ")", "->", "filter", "(", "function", "(", "$", "item", ",", "$", "key", ")", "{", "return", "$", "item", "!==", "''", ";", "}", ")", "->", "groupBy", "(", "function", "(", "$", "item", ")", "{", "return", "$", "item", ";", "}", ")", "->", "keys", "(", ")", "->", "all", "(", ")", ";", "return", "$", "routes", ";", "}" ]
Get all keys of routes @return array
[ "Get", "all", "keys", "of", "routes" ]
2f199dba4f051545bdd8b795be9a840a7f445b47
https://github.com/gr-group/grsupport/blob/2f199dba4f051545bdd8b795be9a840a7f445b47/src/Classes/Support.php#L563-L576
train
infusephp/cron
src/Libs/JobSchedule.php
JobSchedule.getScheduledJobs
public function getScheduledJobs() { $jobs = []; foreach ($this->jobs as $job) { $model = CronJob::find($job['id']); // create a new model if this is the job's first run if (!$model) { $model = new CronJob(); $model->id = $job['id']; $model->save(); } // check if scheduled to run $params = new DateParameters($job); $date = new CronDate($params, $model->last_ran); if ($date->getNextRun() > time()) { continue; } $job = array_replace([ 'successUrl' => '', 'expires' => 0, ], $job); $job['model'] = $model; $jobs[] = $job; } return $jobs; }
php
public function getScheduledJobs() { $jobs = []; foreach ($this->jobs as $job) { $model = CronJob::find($job['id']); // create a new model if this is the job's first run if (!$model) { $model = new CronJob(); $model->id = $job['id']; $model->save(); } // check if scheduled to run $params = new DateParameters($job); $date = new CronDate($params, $model->last_ran); if ($date->getNextRun() > time()) { continue; } $job = array_replace([ 'successUrl' => '', 'expires' => 0, ], $job); $job['model'] = $model; $jobs[] = $job; } return $jobs; }
[ "public", "function", "getScheduledJobs", "(", ")", "{", "$", "jobs", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "jobs", "as", "$", "job", ")", "{", "$", "model", "=", "CronJob", "::", "find", "(", "$", "job", "[", "'id'", "]", ")", ";", "// create a new model if this is the job's first run", "if", "(", "!", "$", "model", ")", "{", "$", "model", "=", "new", "CronJob", "(", ")", ";", "$", "model", "->", "id", "=", "$", "job", "[", "'id'", "]", ";", "$", "model", "->", "save", "(", ")", ";", "}", "// check if scheduled to run", "$", "params", "=", "new", "DateParameters", "(", "$", "job", ")", ";", "$", "date", "=", "new", "CronDate", "(", "$", "params", ",", "$", "model", "->", "last_ran", ")", ";", "if", "(", "$", "date", "->", "getNextRun", "(", ")", ">", "time", "(", ")", ")", "{", "continue", ";", "}", "$", "job", "=", "array_replace", "(", "[", "'successUrl'", "=>", "''", ",", "'expires'", "=>", "0", ",", "]", ",", "$", "job", ")", ";", "$", "job", "[", "'model'", "]", "=", "$", "model", ";", "$", "jobs", "[", "]", "=", "$", "job", ";", "}", "return", "$", "jobs", ";", "}" ]
Gets all of the jobs scheduled to run, now. @return array array(model => CronJob)
[ "Gets", "all", "of", "the", "jobs", "scheduled", "to", "run", "now", "." ]
783f6078b455a48415efeba0a6ee97ab17a3a903
https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/JobSchedule.php#L115-L146
train
infusephp/cron
src/Libs/JobSchedule.php
JobSchedule.runScheduled
public function runScheduled(OutputInterface $output) { $success = true; $event = new ScheduleRunBeginEvent(); $this->dispatcher->dispatch($event::NAME, $event); foreach ($this->getScheduledJobs() as $jobInfo) { $job = $jobInfo['model']; $run = $this->runJob($job, $jobInfo, $output); $success = $run->succeeded() && $success; } $event = new ScheduleRunFinishedEvent(); $this->dispatcher->dispatch($event::NAME, $event); return $success; }
php
public function runScheduled(OutputInterface $output) { $success = true; $event = new ScheduleRunBeginEvent(); $this->dispatcher->dispatch($event::NAME, $event); foreach ($this->getScheduledJobs() as $jobInfo) { $job = $jobInfo['model']; $run = $this->runJob($job, $jobInfo, $output); $success = $run->succeeded() && $success; } $event = new ScheduleRunFinishedEvent(); $this->dispatcher->dispatch($event::NAME, $event); return $success; }
[ "public", "function", "runScheduled", "(", "OutputInterface", "$", "output", ")", "{", "$", "success", "=", "true", ";", "$", "event", "=", "new", "ScheduleRunBeginEvent", "(", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "$", "event", "::", "NAME", ",", "$", "event", ")", ";", "foreach", "(", "$", "this", "->", "getScheduledJobs", "(", ")", "as", "$", "jobInfo", ")", "{", "$", "job", "=", "$", "jobInfo", "[", "'model'", "]", ";", "$", "run", "=", "$", "this", "->", "runJob", "(", "$", "job", ",", "$", "jobInfo", ",", "$", "output", ")", ";", "$", "success", "=", "$", "run", "->", "succeeded", "(", ")", "&&", "$", "success", ";", "}", "$", "event", "=", "new", "ScheduleRunFinishedEvent", "(", ")", ";", "$", "this", "->", "dispatcher", "->", "dispatch", "(", "$", "event", "::", "NAME", ",", "$", "event", ")", ";", "return", "$", "success", ";", "}" ]
Runs any scheduled tasks. @param OutputInterface $output @return bool true if all tasks ran successfully
[ "Runs", "any", "scheduled", "tasks", "." ]
783f6078b455a48415efeba0a6ee97ab17a3a903
https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/JobSchedule.php#L155-L173
train
wb-crowdfusion/crowdfusion
system/core/classes/systemdb/AbstractSystemService.php
AbstractSystemService.add
public function add(ModelObject $obj) { $obj->CreationDate = $this->DateFactory->newStorageDate(); if(!$obj->hasModifiedDate()) $obj->ModifiedDate = $this->DateFactory->newStorageDate(); $this->validator->validateFor(__FUNCTION__, $obj)->throwOnError(); return $this->dao->add($obj); }
php
public function add(ModelObject $obj) { $obj->CreationDate = $this->DateFactory->newStorageDate(); if(!$obj->hasModifiedDate()) $obj->ModifiedDate = $this->DateFactory->newStorageDate(); $this->validator->validateFor(__FUNCTION__, $obj)->throwOnError(); return $this->dao->add($obj); }
[ "public", "function", "add", "(", "ModelObject", "$", "obj", ")", "{", "$", "obj", "->", "CreationDate", "=", "$", "this", "->", "DateFactory", "->", "newStorageDate", "(", ")", ";", "if", "(", "!", "$", "obj", "->", "hasModifiedDate", "(", ")", ")", "$", "obj", "->", "ModifiedDate", "=", "$", "this", "->", "DateFactory", "->", "newStorageDate", "(", ")", ";", "$", "this", "->", "validator", "->", "validateFor", "(", "__FUNCTION__", ",", "$", "obj", ")", "->", "throwOnError", "(", ")", ";", "return", "$", "this", "->", "dao", "->", "add", "(", "$", "obj", ")", ";", "}" ]
Performs an INSERT for the given ModelObject through our DAO. CreationDate and ModifiedDate are set, and the validator is run, Validation errors will throw a ValidationException @param ModelObject $obj The Object to Add @return mixed See the add() method of our DAO
[ "Performs", "an", "INSERT", "for", "the", "given", "ModelObject", "through", "our", "DAO", ".", "CreationDate", "and", "ModifiedDate", "are", "set", "and", "the", "validator", "is", "run" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/AbstractSystemService.php#L67-L76
train
wb-crowdfusion/crowdfusion
system/core/classes/systemdb/AbstractSystemService.php
AbstractSystemService.edit
public function edit(ModelObject $obj) { if(!$obj->hasModifiedDate()) $obj->ModifiedDate = $this->DateFactory->newStorageDate(); $this->validator->validateFor(__FUNCTION__, $obj)->throwOnError(); return $this->dao->edit($obj); }
php
public function edit(ModelObject $obj) { if(!$obj->hasModifiedDate()) $obj->ModifiedDate = $this->DateFactory->newStorageDate(); $this->validator->validateFor(__FUNCTION__, $obj)->throwOnError(); return $this->dao->edit($obj); }
[ "public", "function", "edit", "(", "ModelObject", "$", "obj", ")", "{", "if", "(", "!", "$", "obj", "->", "hasModifiedDate", "(", ")", ")", "$", "obj", "->", "ModifiedDate", "=", "$", "this", "->", "DateFactory", "->", "newStorageDate", "(", ")", ";", "$", "this", "->", "validator", "->", "validateFor", "(", "__FUNCTION__", ",", "$", "obj", ")", "->", "throwOnError", "(", ")", ";", "return", "$", "this", "->", "dao", "->", "edit", "(", "$", "obj", ")", ";", "}" ]
Performs an UPDATE for the given ModelObject through our DAO. ModifiedDate is updated, and the validator is run. Validation Errors will throw a ValidationException @param ModelObject $obj The ModelObject to edit @return mixed See the edit() method of our DAO
[ "Performs", "an", "UPDATE", "for", "the", "given", "ModelObject", "through", "our", "DAO", ".", "ModifiedDate", "is", "updated", "and", "the", "validator", "is", "run", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/AbstractSystemService.php#L88-L95
train
wb-crowdfusion/crowdfusion
system/core/classes/systemdb/AbstractSystemService.php
AbstractSystemService.delete
public function delete($objSlug) { $this->validator->validateFor(__FUNCTION__, $objSlug)->throwOnError(); return $this->dao->delete($objSlug); }
php
public function delete($objSlug) { $this->validator->validateFor(__FUNCTION__, $objSlug)->throwOnError(); return $this->dao->delete($objSlug); }
[ "public", "function", "delete", "(", "$", "objSlug", ")", "{", "$", "this", "->", "validator", "->", "validateFor", "(", "__FUNCTION__", ",", "$", "objSlug", ")", "->", "throwOnError", "(", ")", ";", "return", "$", "this", "->", "dao", "->", "delete", "(", "$", "objSlug", ")", ";", "}" ]
Performs a DELETE for the given slug through our DAO. The validator is run. Validation Errors will throw a ValidationException @param string $objSlug The slug of the item to delete @return mixed See the delete() method of our DAO
[ "Performs", "a", "DELETE", "for", "the", "given", "slug", "through", "our", "DAO", ".", "The", "validator", "is", "run", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/AbstractSystemService.php#L107-L112
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.getSerializationType
public function getSerializationType() { switch ($this->association) { case self::ASSOCIATION_TYPE_EMBED_ONE: case self::ASSOCIATION_TYPE_EMBED_MANY: return TypeFactory::getType(Type::MAP); case self::ASSOCIATION_TYPE_REFERENCE_ONE: case self::ASSOCIATION_TYPE_REFERENCE_MANY: return $this->getReferenceSerializationType(); } throw new \BadMethodCallException; }
php
public function getSerializationType() { switch ($this->association) { case self::ASSOCIATION_TYPE_EMBED_ONE: case self::ASSOCIATION_TYPE_EMBED_MANY: return TypeFactory::getType(Type::MAP); case self::ASSOCIATION_TYPE_REFERENCE_ONE: case self::ASSOCIATION_TYPE_REFERENCE_MANY: return $this->getReferenceSerializationType(); } throw new \BadMethodCallException; }
[ "public", "function", "getSerializationType", "(", ")", "{", "switch", "(", "$", "this", "->", "association", ")", "{", "case", "self", "::", "ASSOCIATION_TYPE_EMBED_ONE", ":", "case", "self", "::", "ASSOCIATION_TYPE_EMBED_MANY", ":", "return", "TypeFactory", "::", "getType", "(", "Type", "::", "MAP", ")", ";", "case", "self", "::", "ASSOCIATION_TYPE_REFERENCE_ONE", ":", "case", "self", "::", "ASSOCIATION_TYPE_REFERENCE_MANY", ":", "return", "$", "this", "->", "getReferenceSerializationType", "(", ")", ";", "}", "throw", "new", "\\", "BadMethodCallException", ";", "}" ]
Return the Type used to serialize individual association values. @return Type
[ "Return", "the", "Type", "used", "to", "serialize", "individual", "association", "values", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L610-L622
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.makeReflection
private function makeReflection() { if ($this->reflection === null) { $this->reflection = new \ReflectionProperty($this->className, $this->name); $this->reflection->setAccessible(true); } }
php
private function makeReflection() { if ($this->reflection === null) { $this->reflection = new \ReflectionProperty($this->className, $this->name); $this->reflection->setAccessible(true); } }
[ "private", "function", "makeReflection", "(", ")", "{", "if", "(", "$", "this", "->", "reflection", "===", "null", ")", "{", "$", "this", "->", "reflection", "=", "new", "\\", "ReflectionProperty", "(", "$", "this", "->", "className", ",", "$", "this", "->", "name", ")", ";", "$", "this", "->", "reflection", "->", "setAccessible", "(", "true", ")", ";", "}", "}" ]
Retrieve and store reflection metadata for this property from php internals. @return void
[ "Retrieve", "and", "store", "reflection", "metadata", "for", "this", "property", "from", "php", "internals", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L845-L852
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.mapAttribute
public function mapAttribute(ClassMetadata $class) { $this->applyDefaults(); $this->validate(); $this->makeGenerator(); $class->addAttributeMapping($this); }
php
public function mapAttribute(ClassMetadata $class) { $this->applyDefaults(); $this->validate(); $this->makeGenerator(); $class->addAttributeMapping($this); }
[ "public", "function", "mapAttribute", "(", "ClassMetadata", "$", "class", ")", "{", "$", "this", "->", "applyDefaults", "(", ")", ";", "$", "this", "->", "validate", "(", ")", ";", "$", "this", "->", "makeGenerator", "(", ")", ";", "$", "class", "->", "addAttributeMapping", "(", "$", "this", ")", ";", "}" ]
Map this property as an attribute. @param ClassMetadata $class @return void
[ "Map", "this", "property", "as", "an", "attribute", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L861-L868
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.mapManyEmbedded
public function mapManyEmbedded(ClassMetadata $class, $type = Type::LIST_) { $this->embedded = true; $this->type = $type; $this->mapAttribute($class); }
php
public function mapManyEmbedded(ClassMetadata $class, $type = Type::LIST_) { $this->embedded = true; $this->type = $type; $this->mapAttribute($class); }
[ "public", "function", "mapManyEmbedded", "(", "ClassMetadata", "$", "class", ",", "$", "type", "=", "Type", "::", "LIST_", ")", "{", "$", "this", "->", "embedded", "=", "true", ";", "$", "this", "->", "type", "=", "$", "type", ";", "$", "this", "->", "mapAttribute", "(", "$", "class", ")", ";", "}" ]
Map this property as a collection of embedded documents. @param ClassMetadata $class @param string $type @return void
[ "Map", "this", "property", "as", "a", "collection", "of", "embedded", "documents", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L878-L884
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.mapManyReference
public function mapManyReference(ClassMetadata $class, $type = Type::LIST_) { $this->reference = true; $this->type = $type; $this->mapAttribute($class); }
php
public function mapManyReference(ClassMetadata $class, $type = Type::LIST_) { $this->reference = true; $this->type = $type; $this->mapAttribute($class); }
[ "public", "function", "mapManyReference", "(", "ClassMetadata", "$", "class", ",", "$", "type", "=", "Type", "::", "LIST_", ")", "{", "$", "this", "->", "reference", "=", "true", ";", "$", "this", "->", "type", "=", "$", "type", ";", "$", "this", "->", "mapAttribute", "(", "$", "class", ")", ";", "}" ]
Map this property as a collection of document references. @param ClassMetadata $class @param string $type @return void
[ "Map", "this", "property", "as", "a", "collection", "of", "document", "references", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L894-L900
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.mapOneEmbedded
public function mapOneEmbedded(ClassMetadata $class) { $this->embedded = true; $this->type = self::TYPE_ONE; $this->mapAttribute($class); }
php
public function mapOneEmbedded(ClassMetadata $class) { $this->embedded = true; $this->type = self::TYPE_ONE; $this->mapAttribute($class); }
[ "public", "function", "mapOneEmbedded", "(", "ClassMetadata", "$", "class", ")", "{", "$", "this", "->", "embedded", "=", "true", ";", "$", "this", "->", "type", "=", "self", "::", "TYPE_ONE", ";", "$", "this", "->", "mapAttribute", "(", "$", "class", ")", ";", "}" ]
Map this property as a single embedded document. @param ClassMetadata $class @return void
[ "Map", "this", "property", "as", "a", "single", "embedded", "document", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L909-L915
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.mapOneReference
public function mapOneReference(ClassMetadata $class) { $this->reference = true; $this->type = self::TYPE_ONE; $this->mapAttribute($class); }
php
public function mapOneReference(ClassMetadata $class) { $this->reference = true; $this->type = self::TYPE_ONE; $this->mapAttribute($class); }
[ "public", "function", "mapOneReference", "(", "ClassMetadata", "$", "class", ")", "{", "$", "this", "->", "reference", "=", "true", ";", "$", "this", "->", "type", "=", "self", "::", "TYPE_ONE", ";", "$", "this", "->", "mapAttribute", "(", "$", "class", ")", ";", "}" ]
Map this property as a single document reference. @param ClassMetadata $class @return void
[ "Map", "this", "property", "as", "a", "single", "document", "reference", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L924-L930
train
cloudtek/dynamodm
lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php
PropertyMetadata.setValueAndWakeProxy
public function setValueAndWakeProxy($document, $value) { if ($document instanceof Proxy && !$document->__isInitialized()) { //property changes to an uninitialized proxy will not be tracked or persisted, //so the proxy needs to be loaded first. $document->__load(); } $this->setValue($document, $value); return $this; }
php
public function setValueAndWakeProxy($document, $value) { if ($document instanceof Proxy && !$document->__isInitialized()) { //property changes to an uninitialized proxy will not be tracked or persisted, //so the proxy needs to be loaded first. $document->__load(); } $this->setValue($document, $value); return $this; }
[ "public", "function", "setValueAndWakeProxy", "(", "$", "document", ",", "$", "value", ")", "{", "if", "(", "$", "document", "instanceof", "Proxy", "&&", "!", "$", "document", "->", "__isInitialized", "(", ")", ")", "{", "//property changes to an uninitialized proxy will not be tracked or persisted,", "//so the proxy needs to be loaded first.", "$", "document", "->", "__load", "(", ")", ";", "}", "$", "this", "->", "setValue", "(", "$", "document", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
Sets this mapped attribute to the specified value on the given document, waking the document if proxied. @param object $document @param mixed $value @return $this
[ "Sets", "this", "mapped", "attribute", "to", "the", "specified", "value", "on", "the", "given", "document", "waking", "the", "document", "if", "proxied", "." ]
119d355e2c5cbaef1f867970349b4432f5704fcd
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Mapping/PropertyMetadata.php#L978-L989
train
dspsofts/relaypoint-core
src/Address.php
Address.addOpeningHour
public function addOpeningHour($day, $hours) { $openingHour = new OpeningHours($day, $hours); $this->openingHours[$day] = $openingHour; }
php
public function addOpeningHour($day, $hours) { $openingHour = new OpeningHours($day, $hours); $this->openingHours[$day] = $openingHour; }
[ "public", "function", "addOpeningHour", "(", "$", "day", ",", "$", "hours", ")", "{", "$", "openingHour", "=", "new", "OpeningHours", "(", "$", "day", ",", "$", "hours", ")", ";", "$", "this", "->", "openingHours", "[", "$", "day", "]", "=", "$", "openingHour", ";", "}" ]
Adds an opening schedule for a day. @param string $day Day @param string $hours Opening hours of that day
[ "Adds", "an", "opening", "schedule", "for", "a", "day", "." ]
a312742724f03b74d058aec2bc02e944a63b2187
https://github.com/dspsofts/relaypoint-core/blob/a312742724f03b74d058aec2bc02e944a63b2187/src/Address.php#L44-L48
train
facile-it/sentry-common
src/Sanitizer/Sanitizer.php
Sanitizer.sanitize
public function sanitize($value) { if ($value instanceof Traversable) { return $this->sanitize(iterator_to_array($value)); } elseif (is_array($value)) { return array_map([$this, 'sanitize'], $value); } elseif (is_object($value)) { return $this->sanitizeObject($value); } elseif (is_resource($value)) { return get_resource_type($value); } return $value; }
php
public function sanitize($value) { if ($value instanceof Traversable) { return $this->sanitize(iterator_to_array($value)); } elseif (is_array($value)) { return array_map([$this, 'sanitize'], $value); } elseif (is_object($value)) { return $this->sanitizeObject($value); } elseif (is_resource($value)) { return get_resource_type($value); } return $value; }
[ "public", "function", "sanitize", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "Traversable", ")", "{", "return", "$", "this", "->", "sanitize", "(", "iterator_to_array", "(", "$", "value", ")", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "array_map", "(", "[", "$", "this", ",", "'sanitize'", "]", ",", "$", "value", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "value", ")", ")", "{", "return", "$", "this", "->", "sanitizeObject", "(", "$", "value", ")", ";", "}", "elseif", "(", "is_resource", "(", "$", "value", ")", ")", "{", "return", "get_resource_type", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Sanitize recursively a value @param mixed $value @return mixed
[ "Sanitize", "recursively", "a", "value" ]
63ca40700e19363e6af94c69ef8f0f889ba031bd
https://github.com/facile-it/sentry-common/blob/63ca40700e19363e6af94c69ef8f0f889ba031bd/src/Sanitizer/Sanitizer.php#L18-L31
train
xelax90/xelax-site-config
src/XelaxSiteConfig/Controller/SiteConfigController.php
SiteConfigController.indexAction
public function indexAction(){ $configForm = $this->getForm(); $configForm->setData($this->getConfig()); $view = new ViewModel(array('title' => $this->getEditTitle(), 'configForm' => $configForm)); $view->setTemplate('xelax-site-config/site-config/index.phtml'); return $view; }
php
public function indexAction(){ $configForm = $this->getForm(); $configForm->setData($this->getConfig()); $view = new ViewModel(array('title' => $this->getEditTitle(), 'configForm' => $configForm)); $view->setTemplate('xelax-site-config/site-config/index.phtml'); return $view; }
[ "public", "function", "indexAction", "(", ")", "{", "$", "configForm", "=", "$", "this", "->", "getForm", "(", ")", ";", "$", "configForm", "->", "setData", "(", "$", "this", "->", "getConfig", "(", ")", ")", ";", "$", "view", "=", "new", "ViewModel", "(", "array", "(", "'title'", "=>", "$", "this", "->", "getEditTitle", "(", ")", ",", "'configForm'", "=>", "$", "configForm", ")", ")", ";", "$", "view", "->", "setTemplate", "(", "'xelax-site-config/site-config/index.phtml'", ")", ";", "return", "$", "view", ";", "}" ]
Show current config @return ViewModel
[ "Show", "current", "config" ]
76c86e2f716fc2c66b59124a69e35c4cadfeb3db
https://github.com/xelax90/xelax-site-config/blob/76c86e2f716fc2c66b59124a69e35c4cadfeb3db/src/XelaxSiteConfig/Controller/SiteConfigController.php#L106-L113
train
Finesse/QueryScribe
src/Exceptions/InvalidReturnValueException.php
InvalidReturnValueException.create
public static function create(string $name, $value, array $expectedTypes): self { return new static(sprintf( '%s expected to be %s, %s returned', ucfirst($name), implode(' or ', $expectedTypes), is_object($value) ? get_class($value) : gettype($value) )); }
php
public static function create(string $name, $value, array $expectedTypes): self { return new static(sprintf( '%s expected to be %s, %s returned', ucfirst($name), implode(' or ', $expectedTypes), is_object($value) ? get_class($value) : gettype($value) )); }
[ "public", "static", "function", "create", "(", "string", "$", "name", ",", "$", "value", ",", "array", "$", "expectedTypes", ")", ":", "self", "{", "return", "new", "static", "(", "sprintf", "(", "'%s expected to be %s, %s returned'", ",", "ucfirst", "(", "$", "name", ")", ",", "implode", "(", "' or '", ",", "$", "expectedTypes", ")", ",", "is_object", "(", "$", "value", ")", "?", "get_class", "(", "$", "value", ")", ":", "gettype", "(", "$", "value", ")", ")", ")", ";", "}" ]
Makes an exception instance. @param string $name Value name @param mixed $value Actual value @param string[] $expectedTypes Expected types names @return static
[ "Makes", "an", "exception", "instance", "." ]
4edba721e37693780d142229b3ecb0cd4004c7a5
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/Exceptions/InvalidReturnValueException.php#L20-L28
train
WellCommerce/CurrencyBundle
Converter/CurrencyConverter.php
CurrencyConverter.loadExchangeRates
protected function loadExchangeRates($targetCurrency) { if (!isset($this->exchangeRates[$targetCurrency])) { $currencyRates = $this->currencyRateRepository->findBy(['currencyTo' => $targetCurrency]); if (count($currencyRates) === 0) { throw new MissingCurrencyRatesException($targetCurrency); } foreach ($currencyRates as $rate) { $this->setExchangeRate($rate, $targetCurrency); } } }
php
protected function loadExchangeRates($targetCurrency) { if (!isset($this->exchangeRates[$targetCurrency])) { $currencyRates = $this->currencyRateRepository->findBy(['currencyTo' => $targetCurrency]); if (count($currencyRates) === 0) { throw new MissingCurrencyRatesException($targetCurrency); } foreach ($currencyRates as $rate) { $this->setExchangeRate($rate, $targetCurrency); } } }
[ "protected", "function", "loadExchangeRates", "(", "$", "targetCurrency", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "exchangeRates", "[", "$", "targetCurrency", "]", ")", ")", "{", "$", "currencyRates", "=", "$", "this", "->", "currencyRateRepository", "->", "findBy", "(", "[", "'currencyTo'", "=>", "$", "targetCurrency", "]", ")", ";", "if", "(", "count", "(", "$", "currencyRates", ")", "===", "0", ")", "{", "throw", "new", "MissingCurrencyRatesException", "(", "$", "targetCurrency", ")", ";", "}", "foreach", "(", "$", "currencyRates", "as", "$", "rate", ")", "{", "$", "this", "->", "setExchangeRate", "(", "$", "rate", ",", "$", "targetCurrency", ")", ";", "}", "}", "}" ]
Sets exchange rates for target currency @param string $targetCurrency
[ "Sets", "exchange", "rates", "for", "target", "currency" ]
48a6995eedb9c1f93d10751a6d1070e4cbca307e
https://github.com/WellCommerce/CurrencyBundle/blob/48a6995eedb9c1f93d10751a6d1070e4cbca307e/Converter/CurrencyConverter.php#L88-L99
train
Game-scan/Core
src/Request/Api/GameApiRequest.php
GameApiRequest.get
public function get($ressourceToGrab, array $parameters = null) { $this->apiRequest->clean(); $this->apiRequest->setHeaders($this->apiConfiguration->getHeaders()); $this->apiRequest->setParameters($this->apiConfiguration->getParameters()); return $this->apiRequest->get($ressourceToGrab, $parameters); }
php
public function get($ressourceToGrab, array $parameters = null) { $this->apiRequest->clean(); $this->apiRequest->setHeaders($this->apiConfiguration->getHeaders()); $this->apiRequest->setParameters($this->apiConfiguration->getParameters()); return $this->apiRequest->get($ressourceToGrab, $parameters); }
[ "public", "function", "get", "(", "$", "ressourceToGrab", ",", "array", "$", "parameters", "=", "null", ")", "{", "$", "this", "->", "apiRequest", "->", "clean", "(", ")", ";", "$", "this", "->", "apiRequest", "->", "setHeaders", "(", "$", "this", "->", "apiConfiguration", "->", "getHeaders", "(", ")", ")", ";", "$", "this", "->", "apiRequest", "->", "setParameters", "(", "$", "this", "->", "apiConfiguration", "->", "getParameters", "(", ")", ")", ";", "return", "$", "this", "->", "apiRequest", "->", "get", "(", "$", "ressourceToGrab", ",", "$", "parameters", ")", ";", "}" ]
Request a ressource of an api with the get http method @param $ressourceToGrab @param array|null $parameters @return string
[ "Request", "a", "ressource", "of", "an", "api", "with", "the", "get", "http", "method" ]
777652235678bbd9c3ea20344b998a01359339bd
https://github.com/Game-scan/Core/blob/777652235678bbd9c3ea20344b998a01359339bd/src/Request/Api/GameApiRequest.php#L34-L41
train
PenoaksDev/Milky-Framework
src/Milky/Http/Routing/Router.php
Router.substituteBindings
protected function substituteBindings( $route ) { foreach ( $route->parameters() as $key => $value ) { if ( isset( $this->binders[$key] ) ) { $route->setParameter( $key, $this->performBinding( $key, $value, $route ) ); } } $this->substituteImplicitBindings( $route ); return $route; }
php
protected function substituteBindings( $route ) { foreach ( $route->parameters() as $key => $value ) { if ( isset( $this->binders[$key] ) ) { $route->setParameter( $key, $this->performBinding( $key, $value, $route ) ); } } $this->substituteImplicitBindings( $route ); return $route; }
[ "protected", "function", "substituteBindings", "(", "$", "route", ")", "{", "foreach", "(", "$", "route", "->", "parameters", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "binders", "[", "$", "key", "]", ")", ")", "{", "$", "route", "->", "setParameter", "(", "$", "key", ",", "$", "this", "->", "performBinding", "(", "$", "key", ",", "$", "value", ",", "$", "route", ")", ")", ";", "}", "}", "$", "this", "->", "substituteImplicitBindings", "(", "$", "route", ")", ";", "return", "$", "route", ";", "}" ]
Substitute the route bindings onto the route. @param Route $route @return Route
[ "Substitute", "the", "route", "bindings", "onto", "the", "route", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/Router.php#L801-L814
train
PenoaksDev/Milky-Framework
src/Milky/Http/Routing/Router.php
Router.substituteImplicitBindings
protected function substituteImplicitBindings( $route ) { $parameters = $route->parameters(); foreach ( $route->signatureParameters( Model::class ) as $parameter ) { $class = $parameter->getClass(); if ( array_key_exists( $parameter->name, $parameters ) && !$route->getParameter( $parameter->name ) instanceof Model ) { $method = $parameter->isDefaultValueAvailable() ? 'first' : 'firstOrFail'; $model = $class->newInstance(); $route->setParameter( $parameter->name, $model->where( $model->getRouteKeyName(), $parameters[$parameter->name] )->{$method()} ); } } }
php
protected function substituteImplicitBindings( $route ) { $parameters = $route->parameters(); foreach ( $route->signatureParameters( Model::class ) as $parameter ) { $class = $parameter->getClass(); if ( array_key_exists( $parameter->name, $parameters ) && !$route->getParameter( $parameter->name ) instanceof Model ) { $method = $parameter->isDefaultValueAvailable() ? 'first' : 'firstOrFail'; $model = $class->newInstance(); $route->setParameter( $parameter->name, $model->where( $model->getRouteKeyName(), $parameters[$parameter->name] )->{$method()} ); } } }
[ "protected", "function", "substituteImplicitBindings", "(", "$", "route", ")", "{", "$", "parameters", "=", "$", "route", "->", "parameters", "(", ")", ";", "foreach", "(", "$", "route", "->", "signatureParameters", "(", "Model", "::", "class", ")", "as", "$", "parameter", ")", "{", "$", "class", "=", "$", "parameter", "->", "getClass", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "parameter", "->", "name", ",", "$", "parameters", ")", "&&", "!", "$", "route", "->", "getParameter", "(", "$", "parameter", "->", "name", ")", "instanceof", "Model", ")", "{", "$", "method", "=", "$", "parameter", "->", "isDefaultValueAvailable", "(", ")", "?", "'first'", ":", "'firstOrFail'", ";", "$", "model", "=", "$", "class", "->", "newInstance", "(", ")", ";", "$", "route", "->", "setParameter", "(", "$", "parameter", "->", "name", ",", "$", "model", "->", "where", "(", "$", "model", "->", "getRouteKeyName", "(", ")", ",", "$", "parameters", "[", "$", "parameter", "->", "name", "]", ")", "->", "{", "$", "method", "(", ")", "}", ")", ";", "}", "}", "}" ]
Substitute the implicit Eloquent model bindings for the route. @param Route $route
[ "Substitute", "the", "implicit", "Eloquent", "model", "bindings", "for", "the", "route", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/Router.php#L821-L838
train
stubbles/stubbles-dbal
src/main/php/pdo/PdoStatement.php
PdoStatement.bindParam
public function bindParam($param, &$variable, $type = null, int $length = null): bool { try { return $this->pdoStatement->bindParam($param, $variable, $type, $length, null); } catch (PDOException $pdoe) { throw new DatabaseException($pdoe->getMessage(), $pdoe); } }
php
public function bindParam($param, &$variable, $type = null, int $length = null): bool { try { return $this->pdoStatement->bindParam($param, $variable, $type, $length, null); } catch (PDOException $pdoe) { throw new DatabaseException($pdoe->getMessage(), $pdoe); } }
[ "public", "function", "bindParam", "(", "$", "param", ",", "&", "$", "variable", ",", "$", "type", "=", "null", ",", "int", "$", "length", "=", "null", ")", ":", "bool", "{", "try", "{", "return", "$", "this", "->", "pdoStatement", "->", "bindParam", "(", "$", "param", ",", "$", "variable", ",", "$", "type", ",", "$", "length", ",", "null", ")", ";", "}", "catch", "(", "PDOException", "$", "pdoe", ")", "{", "throw", "new", "DatabaseException", "(", "$", "pdoe", "->", "getMessage", "(", ")", ",", "$", "pdoe", ")", ";", "}", "}" ]
bind a parameter of a prepared query to the specified variable The binding will be via reference, so it is evaluated at the time when the prepared statement is executed meaning that in opposite to bindValue() the value of the variable at the time of execution will be used, not the value at the time when this method is called. @param int|string $param the order number of the parameter or its name @param mixed &$variable the variable to bind to the parameter @param int|string $type optional type of the parameter @param int $length optional length of the data type @return bool true on success, false on failure @throws \stubbles\db\DatabaseException @see http://php.net/pdostatement-bindParam
[ "bind", "a", "parameter", "of", "a", "prepared", "query", "to", "the", "specified", "variable" ]
b42a589025a9e511b40a2798ac84df94d6451c36
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoStatement.php#L56-L63
train
stubbles/stubbles-dbal
src/main/php/pdo/PdoStatement.php
PdoStatement.bindValue
public function bindValue($param, $value, $type = null): bool { try { return $this->pdoStatement->bindValue($param, $value, $type); } catch (PDOException $pdoe) { throw new DatabaseException($pdoe->getMessage(), $pdoe); } }
php
public function bindValue($param, $value, $type = null): bool { try { return $this->pdoStatement->bindValue($param, $value, $type); } catch (PDOException $pdoe) { throw new DatabaseException($pdoe->getMessage(), $pdoe); } }
[ "public", "function", "bindValue", "(", "$", "param", ",", "$", "value", ",", "$", "type", "=", "null", ")", ":", "bool", "{", "try", "{", "return", "$", "this", "->", "pdoStatement", "->", "bindValue", "(", "$", "param", ",", "$", "value", ",", "$", "type", ")", ";", "}", "catch", "(", "PDOException", "$", "pdoe", ")", "{", "throw", "new", "DatabaseException", "(", "$", "pdoe", "->", "getMessage", "(", ")", ",", "$", "pdoe", ")", ";", "}", "}" ]
bind a value to the parameter of a prepared query In opposite to bindParam() this will use the value as it is at the time when this method is called. @param int|string $param the order number of the parameter or its name @param mixed $value the value to bind @param int|string $type optional type of the parameter @return bool true on success, false on failure @throws \stubbles\db\DatabaseException @see http://php.net/pdostatement-bindValue
[ "bind", "a", "value", "to", "the", "parameter", "of", "a", "prepared", "query" ]
b42a589025a9e511b40a2798ac84df94d6451c36
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoStatement.php#L78-L85
train
stubbles/stubbles-dbal
src/main/php/pdo/PdoStatement.php
PdoStatement.execute
public function execute(array $values = []): QueryResult { try { if ($this->pdoStatement->execute($values)) { return new PdoQueryResult($this->pdoStatement); } throw new DatabaseException('Executing the prepared statement failed.'); } catch (PDOException $pdoe) { throw new DatabaseException($pdoe->getMessage(), $pdoe); } }
php
public function execute(array $values = []): QueryResult { try { if ($this->pdoStatement->execute($values)) { return new PdoQueryResult($this->pdoStatement); } throw new DatabaseException('Executing the prepared statement failed.'); } catch (PDOException $pdoe) { throw new DatabaseException($pdoe->getMessage(), $pdoe); } }
[ "public", "function", "execute", "(", "array", "$", "values", "=", "[", "]", ")", ":", "QueryResult", "{", "try", "{", "if", "(", "$", "this", "->", "pdoStatement", "->", "execute", "(", "$", "values", ")", ")", "{", "return", "new", "PdoQueryResult", "(", "$", "this", "->", "pdoStatement", ")", ";", "}", "throw", "new", "DatabaseException", "(", "'Executing the prepared statement failed.'", ")", ";", "}", "catch", "(", "PDOException", "$", "pdoe", ")", "{", "throw", "new", "DatabaseException", "(", "$", "pdoe", "->", "getMessage", "(", ")", ",", "$", "pdoe", ")", ";", "}", "}" ]
executes a prepared statement @param array $values optional specifies all necessary information for bindParam() the array elements must use keys corresponding to the number of the position or name of the parameter @return \stubbles\db\pdo\PdoQueryResult @throws \stubbles\db\DatabaseException @see http://php.net/pdostatement-execute
[ "executes", "a", "prepared", "statement" ]
b42a589025a9e511b40a2798ac84df94d6451c36
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/pdo/PdoStatement.php#L97-L108
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/SourceQuery.php
SourceQuery.filterByHost
public function filterByHost($host = null, $comparison = null) { if (null === $comparison) { if (is_array($host)) { $comparison = Criteria::IN; } } return $this->addUsingAlias(SourceTableMap::COL_HOST, $host, $comparison); }
php
public function filterByHost($host = null, $comparison = null) { if (null === $comparison) { if (is_array($host)) { $comparison = Criteria::IN; } } return $this->addUsingAlias(SourceTableMap::COL_HOST, $host, $comparison); }
[ "public", "function", "filterByHost", "(", "$", "host", "=", "null", ",", "$", "comparison", "=", "null", ")", "{", "if", "(", "null", "===", "$", "comparison", ")", "{", "if", "(", "is_array", "(", "$", "host", ")", ")", "{", "$", "comparison", "=", "Criteria", "::", "IN", ";", "}", "}", "return", "$", "this", "->", "addUsingAlias", "(", "SourceTableMap", "::", "COL_HOST", ",", "$", "host", ",", "$", "comparison", ")", ";", "}" ]
Filter the query on the host column Example usage: <code> $query->filterByHost('fooValue'); // WHERE host = 'fooValue' $query->filterByHost('%fooValue%', Criteria::LIKE); // WHERE host LIKE '%fooValue%' </code> @param string $host The value to use as filter. @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL @return $this|ChildSourceQuery The current query, for fluid interface
[ "Filter", "the", "query", "on", "the", "host", "column" ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/SourceQuery.php#L372-L381
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Base/SourceQuery.php
SourceQuery.filterByEndpoint
public function filterByEndpoint($endpoint = null, $comparison = null) { if (null === $comparison) { if (is_array($endpoint)) { $comparison = Criteria::IN; } } return $this->addUsingAlias(SourceTableMap::COL_ENDPOINT, $endpoint, $comparison); }
php
public function filterByEndpoint($endpoint = null, $comparison = null) { if (null === $comparison) { if (is_array($endpoint)) { $comparison = Criteria::IN; } } return $this->addUsingAlias(SourceTableMap::COL_ENDPOINT, $endpoint, $comparison); }
[ "public", "function", "filterByEndpoint", "(", "$", "endpoint", "=", "null", ",", "$", "comparison", "=", "null", ")", "{", "if", "(", "null", "===", "$", "comparison", ")", "{", "if", "(", "is_array", "(", "$", "endpoint", ")", ")", "{", "$", "comparison", "=", "Criteria", "::", "IN", ";", "}", "}", "return", "$", "this", "->", "addUsingAlias", "(", "SourceTableMap", "::", "COL_ENDPOINT", ",", "$", "endpoint", ",", "$", "comparison", ")", ";", "}" ]
Filter the query on the endpoint column Example usage: <code> $query->filterByEndpoint('fooValue'); // WHERE endpoint = 'fooValue' $query->filterByEndpoint('%fooValue%', Criteria::LIKE); // WHERE endpoint LIKE '%fooValue%' </code> @param string $endpoint The value to use as filter. @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL @return $this|ChildSourceQuery The current query, for fluid interface
[ "Filter", "the", "query", "on", "the", "endpoint", "column" ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/SourceQuery.php#L397-L406
train
ringoteam/RingoPhpRedmonBundle
Controller/CrudController.php
CrudController.indexAction
public function indexAction() { // Get all instances $instances = $this->getManager()->findAll(); $worker = $this->get('ringo_php_redmon.instance_worker'); if(is_array($instances)) { foreach($instances as $index => $instance) { // Ping server and get potential error message $working = $worker->setInstance($instance)->ping(); $instances[$index]->setWorking($working); $instances[$index]->setError($worker->getMessage()); } } return $this->render( $this->getTemplatePath().'index.html.twig', array( 'instances' => $instances ) ); }
php
public function indexAction() { // Get all instances $instances = $this->getManager()->findAll(); $worker = $this->get('ringo_php_redmon.instance_worker'); if(is_array($instances)) { foreach($instances as $index => $instance) { // Ping server and get potential error message $working = $worker->setInstance($instance)->ping(); $instances[$index]->setWorking($working); $instances[$index]->setError($worker->getMessage()); } } return $this->render( $this->getTemplatePath().'index.html.twig', array( 'instances' => $instances ) ); }
[ "public", "function", "indexAction", "(", ")", "{", "// Get all instances", "$", "instances", "=", "$", "this", "->", "getManager", "(", ")", "->", "findAll", "(", ")", ";", "$", "worker", "=", "$", "this", "->", "get", "(", "'ringo_php_redmon.instance_worker'", ")", ";", "if", "(", "is_array", "(", "$", "instances", ")", ")", "{", "foreach", "(", "$", "instances", "as", "$", "index", "=>", "$", "instance", ")", "{", "// Ping server and get potential error message", "$", "working", "=", "$", "worker", "->", "setInstance", "(", "$", "instance", ")", "->", "ping", "(", ")", ";", "$", "instances", "[", "$", "index", "]", "->", "setWorking", "(", "$", "working", ")", ";", "$", "instances", "[", "$", "index", "]", "->", "setError", "(", "$", "worker", "->", "getMessage", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "render", "(", "$", "this", "->", "getTemplatePath", "(", ")", ".", "'index.html.twig'", ",", "array", "(", "'instances'", "=>", "$", "instances", ")", ")", ";", "}" ]
List of instances action @return mixed
[ "List", "of", "instances", "action" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/CrudController.php#L30-L51
train
ringoteam/RingoPhpRedmonBundle
Controller/CrudController.php
CrudController.editAction
public function editAction($id) { $instance = $this->getManager()->find($id); if(!$instance) { return new RedirectResponse($this->generateUrl('ringo_php_redmon')); } $form = $this->getForm($instance); return $this->render( $this->getTemplatePath().'edit.html.twig', array( 'form' => $form->createView(), 'id' => $id, 'errors' => array() ) ); }
php
public function editAction($id) { $instance = $this->getManager()->find($id); if(!$instance) { return new RedirectResponse($this->generateUrl('ringo_php_redmon')); } $form = $this->getForm($instance); return $this->render( $this->getTemplatePath().'edit.html.twig', array( 'form' => $form->createView(), 'id' => $id, 'errors' => array() ) ); }
[ "public", "function", "editAction", "(", "$", "id", ")", "{", "$", "instance", "=", "$", "this", "->", "getManager", "(", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "instance", ")", "{", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon'", ")", ")", ";", "}", "$", "form", "=", "$", "this", "->", "getForm", "(", "$", "instance", ")", ";", "return", "$", "this", "->", "render", "(", "$", "this", "->", "getTemplatePath", "(", ")", ".", "'edit.html.twig'", ",", "array", "(", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", "'id'", "=>", "$", "id", ",", "'errors'", "=>", "array", "(", ")", ")", ")", ";", "}" ]
Edit instance action @param string $id The instance ID @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Edit", "instance", "action" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/CrudController.php#L109-L124
train
ringoteam/RingoPhpRedmonBundle
Controller/CrudController.php
CrudController.updateAction
public function updateAction($id) { $form = $this->getForm(); // Get request $request = $this->get('request'); if ('POST' == $request->getMethod()) { $form->submit($request); if ($form->isValid()) { // Save instance $this->getManager()->create($form->getData()); $this->get('session')->getFlashBag()->add('success', 'Instance Redis updated successfully'); return new RedirectResponse($this->generateUrl('ringo_php_redmon')); }else { $this->get('session')->getFlashBag()->add('error', 'Some errors found'); } } return $this->render( $this->getTemplatePath().'edit.html.twig', array( 'form' => $form->createView(), 'errors' => $form->getErrors() ) ); }
php
public function updateAction($id) { $form = $this->getForm(); // Get request $request = $this->get('request'); if ('POST' == $request->getMethod()) { $form->submit($request); if ($form->isValid()) { // Save instance $this->getManager()->create($form->getData()); $this->get('session')->getFlashBag()->add('success', 'Instance Redis updated successfully'); return new RedirectResponse($this->generateUrl('ringo_php_redmon')); }else { $this->get('session')->getFlashBag()->add('error', 'Some errors found'); } } return $this->render( $this->getTemplatePath().'edit.html.twig', array( 'form' => $form->createView(), 'errors' => $form->getErrors() ) ); }
[ "public", "function", "updateAction", "(", "$", "id", ")", "{", "$", "form", "=", "$", "this", "->", "getForm", "(", ")", ";", "// Get request", "$", "request", "=", "$", "this", "->", "get", "(", "'request'", ")", ";", "if", "(", "'POST'", "==", "$", "request", "->", "getMethod", "(", ")", ")", "{", "$", "form", "->", "submit", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "// Save instance", "$", "this", "->", "getManager", "(", ")", "->", "create", "(", "$", "form", "->", "getData", "(", ")", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'success'", ",", "'Instance Redis updated successfully'", ")", ";", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon'", ")", ")", ";", "}", "else", "{", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'error'", ",", "'Some errors found'", ")", ";", "}", "}", "return", "$", "this", "->", "render", "(", "$", "this", "->", "getTemplatePath", "(", ")", ".", "'edit.html.twig'", ",", "array", "(", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", "'errors'", "=>", "$", "form", "->", "getErrors", "(", ")", ")", ")", ";", "}" ]
Update instance action @param string $id The instance ID @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Update", "instance", "action" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/CrudController.php#L132-L158
train
ringoteam/RingoPhpRedmonBundle
Controller/CrudController.php
CrudController.deleteAction
public function deleteAction($id) { $instance = $this->getManager()->find($id); if($instance) { $this->getManager()->delete($instance); $this->get('session')->getFlashBag()->add('success', 'Instance Redis has been deleted successfully'); }else { $this->get('session')->getFlashBag()->add('error', 'This instance does not exist'); } return new RedirectResponse($this->generateUrl('ringo_php_redmon')); }
php
public function deleteAction($id) { $instance = $this->getManager()->find($id); if($instance) { $this->getManager()->delete($instance); $this->get('session')->getFlashBag()->add('success', 'Instance Redis has been deleted successfully'); }else { $this->get('session')->getFlashBag()->add('error', 'This instance does not exist'); } return new RedirectResponse($this->generateUrl('ringo_php_redmon')); }
[ "public", "function", "deleteAction", "(", "$", "id", ")", "{", "$", "instance", "=", "$", "this", "->", "getManager", "(", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "$", "instance", ")", "{", "$", "this", "->", "getManager", "(", ")", "->", "delete", "(", "$", "instance", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'success'", ",", "'Instance Redis has been deleted successfully'", ")", ";", "}", "else", "{", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'error'", ",", "'This instance does not exist'", ")", ";", "}", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon'", ")", ")", ";", "}" ]
Delete instance action @param string $id The instance ID @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Delete", "instance", "action" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/CrudController.php#L166-L177
train
ringoteam/RingoPhpRedmonBundle
Controller/CrudController.php
CrudController.getForm
protected function getForm(Instance $instance = null) { if($instance == null) { $instance = $this->getManager()->createNew(); } return $this->createForm( $this->container->get('ringo_php_redmon.form.instance_type'), $instance ); }
php
protected function getForm(Instance $instance = null) { if($instance == null) { $instance = $this->getManager()->createNew(); } return $this->createForm( $this->container->get('ringo_php_redmon.form.instance_type'), $instance ); }
[ "protected", "function", "getForm", "(", "Instance", "$", "instance", "=", "null", ")", "{", "if", "(", "$", "instance", "==", "null", ")", "{", "$", "instance", "=", "$", "this", "->", "getManager", "(", ")", "->", "createNew", "(", ")", ";", "}", "return", "$", "this", "->", "createForm", "(", "$", "this", "->", "container", "->", "get", "(", "'ringo_php_redmon.form.instance_type'", ")", ",", "$", "instance", ")", ";", "}" ]
Create Form instance @param Instance $instance @return \Symfony\Component\Form\Form
[ "Create", "Form", "instance" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/CrudController.php#L195-L205
train
zapheus/zapheus
src/Http/Message/Request.php
Request.attribute
public function attribute($name) { $exists = isset($this->attributes[$name]); return $exists ? $this->attributes[$name] : null; }
php
public function attribute($name) { $exists = isset($this->attributes[$name]); return $exists ? $this->attributes[$name] : null; }
[ "public", "function", "attribute", "(", "$", "name", ")", "{", "$", "exists", "=", "isset", "(", "$", "this", "->", "attributes", "[", "$", "name", "]", ")", ";", "return", "$", "exists", "?", "$", "this", "->", "attributes", "[", "$", "name", "]", ":", "null", ";", "}" ]
Returns an instance with the specified derived request attribute. @param string $name @return mixed
[ "Returns", "an", "instance", "with", "the", "specified", "derived", "request", "attribute", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Http/Message/Request.php#L103-L108
train
zapheus/zapheus
src/Http/Message/Request.php
Request.query
public function query($name) { $exists = isset($this->queries[$name]); return $exists ? $this->queries[$name] : null; }
php
public function query($name) { $exists = isset($this->queries[$name]); return $exists ? $this->queries[$name] : null; }
[ "public", "function", "query", "(", "$", "name", ")", "{", "$", "exists", "=", "isset", "(", "$", "this", "->", "queries", "[", "$", "name", "]", ")", ";", "return", "$", "exists", "?", "$", "this", "->", "queries", "[", "$", "name", "]", ":", "null", ";", "}" ]
Returns the specified query string argument. @param string $name @return array
[ "Returns", "the", "specified", "query", "string", "argument", "." ]
96618b5cee7d20b6700d0475e4334ae4b5163a6b
https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Http/Message/Request.php#L208-L213
train
squareproton/Bond
lib/SebastianBergmann/Diff.php
Diff.longestCommonSubsequence
protected function longestCommonSubsequence(array $from, array $to) { $common = array(); $matrix = array(); $fromLength = count($from); $toLength = count($to); for ($i = 0; $i <= $fromLength; ++$i) { $matrix[$i][0] = 0; } for ($j = 0; $j <= $toLength; ++$j) { $matrix[0][$j] = 0; } for ($i = 1; $i <= $fromLength; ++$i) { for ($j = 1; $j <= $toLength; ++$j) { $matrix[$i][$j] = max( $matrix[$i-1][$j], $matrix[$i][$j-1], $from[$i-1] === $to[$j-1] ? $matrix[$i-1][$j-1] + 1 : 0 ); } } $i = $fromLength; $j = $toLength; while ($i > 0 && $j > 0) { if ($from[$i-1] === $to[$j-1]) { array_unshift($common, $from[$i-1]); --$i; --$j; } else if ($matrix[$i][$j-1] > $matrix[$i-1][$j]) { --$j; } else { --$i; } } return $common; }
php
protected function longestCommonSubsequence(array $from, array $to) { $common = array(); $matrix = array(); $fromLength = count($from); $toLength = count($to); for ($i = 0; $i <= $fromLength; ++$i) { $matrix[$i][0] = 0; } for ($j = 0; $j <= $toLength; ++$j) { $matrix[0][$j] = 0; } for ($i = 1; $i <= $fromLength; ++$i) { for ($j = 1; $j <= $toLength; ++$j) { $matrix[$i][$j] = max( $matrix[$i-1][$j], $matrix[$i][$j-1], $from[$i-1] === $to[$j-1] ? $matrix[$i-1][$j-1] + 1 : 0 ); } } $i = $fromLength; $j = $toLength; while ($i > 0 && $j > 0) { if ($from[$i-1] === $to[$j-1]) { array_unshift($common, $from[$i-1]); --$i; --$j; } else if ($matrix[$i][$j-1] > $matrix[$i-1][$j]) { --$j; } else { --$i; } } return $common; }
[ "protected", "function", "longestCommonSubsequence", "(", "array", "$", "from", ",", "array", "$", "to", ")", "{", "$", "common", "=", "array", "(", ")", ";", "$", "matrix", "=", "array", "(", ")", ";", "$", "fromLength", "=", "count", "(", "$", "from", ")", ";", "$", "toLength", "=", "count", "(", "$", "to", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<=", "$", "fromLength", ";", "++", "$", "i", ")", "{", "$", "matrix", "[", "$", "i", "]", "[", "0", "]", "=", "0", ";", "}", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<=", "$", "toLength", ";", "++", "$", "j", ")", "{", "$", "matrix", "[", "0", "]", "[", "$", "j", "]", "=", "0", ";", "}", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "fromLength", ";", "++", "$", "i", ")", "{", "for", "(", "$", "j", "=", "1", ";", "$", "j", "<=", "$", "toLength", ";", "++", "$", "j", ")", "{", "$", "matrix", "[", "$", "i", "]", "[", "$", "j", "]", "=", "max", "(", "$", "matrix", "[", "$", "i", "-", "1", "]", "[", "$", "j", "]", ",", "$", "matrix", "[", "$", "i", "]", "[", "$", "j", "-", "1", "]", ",", "$", "from", "[", "$", "i", "-", "1", "]", "===", "$", "to", "[", "$", "j", "-", "1", "]", "?", "$", "matrix", "[", "$", "i", "-", "1", "]", "[", "$", "j", "-", "1", "]", "+", "1", ":", "0", ")", ";", "}", "}", "$", "i", "=", "$", "fromLength", ";", "$", "j", "=", "$", "toLength", ";", "while", "(", "$", "i", ">", "0", "&&", "$", "j", ">", "0", ")", "{", "if", "(", "$", "from", "[", "$", "i", "-", "1", "]", "===", "$", "to", "[", "$", "j", "-", "1", "]", ")", "{", "array_unshift", "(", "$", "common", ",", "$", "from", "[", "$", "i", "-", "1", "]", ")", ";", "--", "$", "i", ";", "--", "$", "j", ";", "}", "else", "if", "(", "$", "matrix", "[", "$", "i", "]", "[", "$", "j", "-", "1", "]", ">", "$", "matrix", "[", "$", "i", "-", "1", "]", "[", "$", "j", "]", ")", "{", "--", "$", "j", ";", "}", "else", "{", "--", "$", "i", ";", "}", "}", "return", "$", "common", ";", "}" ]
Calculates the longest common subsequence of two arrays. @param array $from @param array $to @return array
[ "Calculates", "the", "longest", "common", "subsequence", "of", "two", "arrays", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/lib/SebastianBergmann/Diff.php#L257-L302
train
praxigento/mobi_mod_downline
Service/Snap/Calc.php
Calc.getDwnlLog
private function getDwnlLog($datestamp) { $result = []; /* prepare query parameters */ $tsFrom = $this->hlpPeriod->getTimestampFrom($datestamp); $periodTo = $this->hlpPeriod->getPeriodCurrent(); $tsTo = $this->hlpPeriod->getTimestampTo($periodTo); /* perform query */ $query = $this->qGetChanges->build(); $conn = $query->getConnection(); $bind = [ QGetChanges::BND_DATE_FROM => $tsFrom, QGetChanges::BND_DATE_TO => $tsTo ]; $rs = $conn->fetchAll($query, $bind); /* compose result */ foreach ($rs as $one) { $item = new EChange($one); $result[] = $item; } return $result; }
php
private function getDwnlLog($datestamp) { $result = []; /* prepare query parameters */ $tsFrom = $this->hlpPeriod->getTimestampFrom($datestamp); $periodTo = $this->hlpPeriod->getPeriodCurrent(); $tsTo = $this->hlpPeriod->getTimestampTo($periodTo); /* perform query */ $query = $this->qGetChanges->build(); $conn = $query->getConnection(); $bind = [ QGetChanges::BND_DATE_FROM => $tsFrom, QGetChanges::BND_DATE_TO => $tsTo ]; $rs = $conn->fetchAll($query, $bind); /* compose result */ foreach ($rs as $one) { $item = new EChange($one); $result[] = $item; } return $result; }
[ "private", "function", "getDwnlLog", "(", "$", "datestamp", ")", "{", "$", "result", "=", "[", "]", ";", "/* prepare query parameters */", "$", "tsFrom", "=", "$", "this", "->", "hlpPeriod", "->", "getTimestampFrom", "(", "$", "datestamp", ")", ";", "$", "periodTo", "=", "$", "this", "->", "hlpPeriod", "->", "getPeriodCurrent", "(", ")", ";", "$", "tsTo", "=", "$", "this", "->", "hlpPeriod", "->", "getTimestampTo", "(", "$", "periodTo", ")", ";", "/* perform query */", "$", "query", "=", "$", "this", "->", "qGetChanges", "->", "build", "(", ")", ";", "$", "conn", "=", "$", "query", "->", "getConnection", "(", ")", ";", "$", "bind", "=", "[", "QGetChanges", "::", "BND_DATE_FROM", "=>", "$", "tsFrom", ",", "QGetChanges", "::", "BND_DATE_TO", "=>", "$", "tsTo", "]", ";", "$", "rs", "=", "$", "conn", "->", "fetchAll", "(", "$", "query", ",", "$", "bind", ")", ";", "/* compose result */", "foreach", "(", "$", "rs", "as", "$", "one", ")", "{", "$", "item", "=", "new", "EChange", "(", "$", "one", ")", ";", "$", "result", "[", "]", "=", "$", "item", ";", "}", "return", "$", "result", ";", "}" ]
Load change log starting from the given date. @param string $datestamp @return \Praxigento\Downline\Repo\Data\Change[] @throws \Exception
[ "Load", "change", "log", "starting", "from", "the", "given", "date", "." ]
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Service/Snap/Calc.php#L89-L111
train
praxigento/mobi_mod_downline
Service/Snap/Calc.php
Calc.getDwnlSnap
private function getDwnlSnap($datestamp) { $result = []; $query = $this->qSnapOnDate->build(); $query->order(QSnapOnDate::AS_DWNL_SNAP . '.' . ESnap::A_DEPTH); $conn = $query->getConnection(); $bind = [ QSnapOnDate::BND_ON_DATE => $datestamp ]; $rows = $conn->fetchAll($query, $bind); foreach ($rows as $one) { $item = new ESnap($one); $custId = $item->getCustomerRef(); $result[$custId] = $item; } return $result; }
php
private function getDwnlSnap($datestamp) { $result = []; $query = $this->qSnapOnDate->build(); $query->order(QSnapOnDate::AS_DWNL_SNAP . '.' . ESnap::A_DEPTH); $conn = $query->getConnection(); $bind = [ QSnapOnDate::BND_ON_DATE => $datestamp ]; $rows = $conn->fetchAll($query, $bind); foreach ($rows as $one) { $item = new ESnap($one); $custId = $item->getCustomerRef(); $result[$custId] = $item; } return $result; }
[ "private", "function", "getDwnlSnap", "(", "$", "datestamp", ")", "{", "$", "result", "=", "[", "]", ";", "$", "query", "=", "$", "this", "->", "qSnapOnDate", "->", "build", "(", ")", ";", "$", "query", "->", "order", "(", "QSnapOnDate", "::", "AS_DWNL_SNAP", ".", "'.'", ".", "ESnap", "::", "A_DEPTH", ")", ";", "$", "conn", "=", "$", "query", "->", "getConnection", "(", ")", ";", "$", "bind", "=", "[", "QSnapOnDate", "::", "BND_ON_DATE", "=>", "$", "datestamp", "]", ";", "$", "rows", "=", "$", "conn", "->", "fetchAll", "(", "$", "query", ",", "$", "bind", ")", ";", "foreach", "(", "$", "rows", "as", "$", "one", ")", "{", "$", "item", "=", "new", "ESnap", "(", "$", "one", ")", ";", "$", "custId", "=", "$", "item", "->", "getCustomerRef", "(", ")", ";", "$", "result", "[", "$", "custId", "]", "=", "$", "item", ";", "}", "return", "$", "result", ";", "}" ]
Load downline snapshot on the given date. @param string $datestamp @return ESnap[] @throws \Exception
[ "Load", "downline", "snapshot", "on", "the", "given", "date", "." ]
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Service/Snap/Calc.php#L120-L136
train
libreworks/caridea-auth
src/Principal.php
Principal.getAnonymous
public static function getAnonymous(): Principal { if (self::$anon === null) { self::$anon = new self(null, [], true); } return self::$anon; }
php
public static function getAnonymous(): Principal { if (self::$anon === null) { self::$anon = new self(null, [], true); } return self::$anon; }
[ "public", "static", "function", "getAnonymous", "(", ")", ":", "Principal", "{", "if", "(", "self", "::", "$", "anon", "===", "null", ")", "{", "self", "::", "$", "anon", "=", "new", "self", "(", "null", ",", "[", "]", ",", "true", ")", ";", "}", "return", "self", "::", "$", "anon", ";", "}" ]
Gets a token representing an anonymous authentication. @return Principal The anonymous principal
[ "Gets", "a", "token", "representing", "an", "anonymous", "authentication", "." ]
1bf965c57716942b18ca3204629f6bda99cf876a
https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Principal.php#L122-L128
train
ciims/ciims-modules-install
models/DatabaseForm.php
DatabaseForm.validateConnection
public function validateConnection() { // Make sure all fields are provided if ($this->validate()) { // Just turning the connection on and off. A CDbException will be thrown if something goes wrong try { $connection = new CDbConnection("mysql:host={$this->host};dbname={$this->dbname}", $this->username, $this->password); $connection->setActive(true); $connection->setActive(false); $this->dsn = $connection->connectionString; return true; } catch (Exception $e) { // Add errors to all fields for the visual indicator $this->addError('username', ''); $this->addError('password', ''); $this->addError('dbname', ''); $this->addError('host', ''); $this->addError('dsn',Yii::t('Install.main', 'Unable to connect to database using the provided credentials.')); return false; } } $this->addError('dsn',Yii::t('Install.main', 'Unable to connect to database using the provided credentials.')); return false; }
php
public function validateConnection() { // Make sure all fields are provided if ($this->validate()) { // Just turning the connection on and off. A CDbException will be thrown if something goes wrong try { $connection = new CDbConnection("mysql:host={$this->host};dbname={$this->dbname}", $this->username, $this->password); $connection->setActive(true); $connection->setActive(false); $this->dsn = $connection->connectionString; return true; } catch (Exception $e) { // Add errors to all fields for the visual indicator $this->addError('username', ''); $this->addError('password', ''); $this->addError('dbname', ''); $this->addError('host', ''); $this->addError('dsn',Yii::t('Install.main', 'Unable to connect to database using the provided credentials.')); return false; } } $this->addError('dsn',Yii::t('Install.main', 'Unable to connect to database using the provided credentials.')); return false; }
[ "public", "function", "validateConnection", "(", ")", "{", "// Make sure all fields are provided", "if", "(", "$", "this", "->", "validate", "(", ")", ")", "{", "// Just turning the connection on and off. A CDbException will be thrown if something goes wrong", "try", "{", "$", "connection", "=", "new", "CDbConnection", "(", "\"mysql:host={$this->host};dbname={$this->dbname}\"", ",", "$", "this", "->", "username", ",", "$", "this", "->", "password", ")", ";", "$", "connection", "->", "setActive", "(", "true", ")", ";", "$", "connection", "->", "setActive", "(", "false", ")", ";", "$", "this", "->", "dsn", "=", "$", "connection", "->", "connectionString", ";", "return", "true", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// Add errors to all fields for the visual indicator", "$", "this", "->", "addError", "(", "'username'", ",", "''", ")", ";", "$", "this", "->", "addError", "(", "'password'", ",", "''", ")", ";", "$", "this", "->", "addError", "(", "'dbname'", ",", "''", ")", ";", "$", "this", "->", "addError", "(", "'host'", ",", "''", ")", ";", "$", "this", "->", "addError", "(", "'dsn'", ",", "Yii", "::", "t", "(", "'Install.main'", ",", "'Unable to connect to database using the provided credentials.'", ")", ")", ";", "return", "false", ";", "}", "}", "$", "this", "->", "addError", "(", "'dsn'", ",", "Yii", "::", "t", "(", "'Install.main'", ",", "'Unable to connect to database using the provided credentials.'", ")", ")", ";", "return", "false", ";", "}" ]
Validator for connection to MySQL @return bool Whether or not we could connect to MySQL
[ "Validator", "for", "connection", "to", "MySQL" ]
54d6a93e5c42c2d98e19de38a90e27f77358e88b
https://github.com/ciims/ciims-modules-install/blob/54d6a93e5c42c2d98e19de38a90e27f77358e88b/models/DatabaseForm.php#L61-L89
train
quantaphp/container-factories
src/Configuration/PhpFileConfiguration.php
PhpFileConfiguration.contents
private function contents(): array { if (! $this->contents) { if (! file_exists($this->path)) { throw new \LogicException( vsprintf('The PHP configuration file does not exist (%s)', [ realpath($this->path), ]) ); } $contents = require $this->path; if (! is_array($contents)) { throw new \UnexpectedValueException( vsprintf('The PHP configuration file must return an array, %s returned (%s)', [ gettype($contents), realpath($this->path), ]) ); } $this->contents = [ 'parameters' => $contents['parameters'] ?? [], 'aliases' => $contents['aliases'] ?? [], 'invokables' => $contents['invokables'] ?? [], 'factories' => $contents['factories'] ?? [], 'tags' => $contents['tags'] ?? [], 'mappers' => $contents['mappers'] ?? [], 'extensions' => $contents['extensions'] ?? [], ]; } return $this->contents; }
php
private function contents(): array { if (! $this->contents) { if (! file_exists($this->path)) { throw new \LogicException( vsprintf('The PHP configuration file does not exist (%s)', [ realpath($this->path), ]) ); } $contents = require $this->path; if (! is_array($contents)) { throw new \UnexpectedValueException( vsprintf('The PHP configuration file must return an array, %s returned (%s)', [ gettype($contents), realpath($this->path), ]) ); } $this->contents = [ 'parameters' => $contents['parameters'] ?? [], 'aliases' => $contents['aliases'] ?? [], 'invokables' => $contents['invokables'] ?? [], 'factories' => $contents['factories'] ?? [], 'tags' => $contents['tags'] ?? [], 'mappers' => $contents['mappers'] ?? [], 'extensions' => $contents['extensions'] ?? [], ]; } return $this->contents; }
[ "private", "function", "contents", "(", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "contents", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "path", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "vsprintf", "(", "'The PHP configuration file does not exist (%s)'", ",", "[", "realpath", "(", "$", "this", "->", "path", ")", ",", "]", ")", ")", ";", "}", "$", "contents", "=", "require", "$", "this", "->", "path", ";", "if", "(", "!", "is_array", "(", "$", "contents", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "vsprintf", "(", "'The PHP configuration file must return an array, %s returned (%s)'", ",", "[", "gettype", "(", "$", "contents", ")", ",", "realpath", "(", "$", "this", "->", "path", ")", ",", "]", ")", ")", ";", "}", "$", "this", "->", "contents", "=", "[", "'parameters'", "=>", "$", "contents", "[", "'parameters'", "]", "??", "[", "]", ",", "'aliases'", "=>", "$", "contents", "[", "'aliases'", "]", "??", "[", "]", ",", "'invokables'", "=>", "$", "contents", "[", "'invokables'", "]", "??", "[", "]", ",", "'factories'", "=>", "$", "contents", "[", "'factories'", "]", "??", "[", "]", ",", "'tags'", "=>", "$", "contents", "[", "'tags'", "]", "??", "[", "]", ",", "'mappers'", "=>", "$", "contents", "[", "'mappers'", "]", "??", "[", "]", ",", "'extensions'", "=>", "$", "contents", "[", "'extensions'", "]", "??", "[", "]", ",", "]", ";", "}", "return", "$", "this", "->", "contents", ";", "}" ]
Return the content of the file and cache it. @return array[]; @throws \LogicException @throws \UnexpectedValueException
[ "Return", "the", "content", "of", "the", "file", "and", "cache", "it", "." ]
5e753d66a18d0ce4418cbf33fe6d6b74948f303d
https://github.com/quantaphp/container-factories/blob/5e753d66a18d0ce4418cbf33fe6d6b74948f303d/src/Configuration/PhpFileConfiguration.php#L208-L242
train
quantaphp/container-factories
src/Configuration/PhpFileConfiguration.php
PhpFileConfiguration.keyNotArrayErrorMessage
private function keyNotArrayErrorMessage(array $contents, string ...$path): string { $value = array_reduce($path, function (array $arr, string $key) { return $arr[$key]; }, $contents); return vsprintf('The key [%s] of the configuration array must be an array, %s given (%s)', [ implode('.', $path), gettype($value), realpath($this->path), ]); }
php
private function keyNotArrayErrorMessage(array $contents, string ...$path): string { $value = array_reduce($path, function (array $arr, string $key) { return $arr[$key]; }, $contents); return vsprintf('The key [%s] of the configuration array must be an array, %s given (%s)', [ implode('.', $path), gettype($value), realpath($this->path), ]); }
[ "private", "function", "keyNotArrayErrorMessage", "(", "array", "$", "contents", ",", "string", "...", "$", "path", ")", ":", "string", "{", "$", "value", "=", "array_reduce", "(", "$", "path", ",", "function", "(", "array", "$", "arr", ",", "string", "$", "key", ")", "{", "return", "$", "arr", "[", "$", "key", "]", ";", "}", ",", "$", "contents", ")", ";", "return", "vsprintf", "(", "'The key [%s] of the configuration array must be an array, %s given (%s)'", ",", "[", "implode", "(", "'.'", ",", "$", "path", ")", ",", "gettype", "(", "$", "value", ")", ",", "realpath", "(", "$", "this", "->", "path", ")", ",", "]", ")", ";", "}" ]
Return the error message of the exception thrown when a key of the configuration array is not an array. @param array $contents @param string ...$path @return string
[ "Return", "the", "error", "message", "of", "the", "exception", "thrown", "when", "a", "key", "of", "the", "configuration", "array", "is", "not", "an", "array", "." ]
5e753d66a18d0ce4418cbf33fe6d6b74948f303d
https://github.com/quantaphp/container-factories/blob/5e753d66a18d0ce4418cbf33fe6d6b74948f303d/src/Configuration/PhpFileConfiguration.php#L252-L263
train
quantaphp/container-factories
src/Configuration/PhpFileConfiguration.php
PhpFileConfiguration.arrayKeyTypeErrorMessage
private function arrayKeyTypeErrorMessage(array $contents, string $key, string $type, string ...$path): string { $arr = array_reduce($path, function (array $arr, string $key) { return $arr[$key]; }, $contents); return vsprintf('The key [%s] of the configuration array must be an array of %s, %s given for key [%s] (%s)', [ implode('.', $path), $type, gettype($arr[$key]), $key, realpath($this->path), ]); }
php
private function arrayKeyTypeErrorMessage(array $contents, string $key, string $type, string ...$path): string { $arr = array_reduce($path, function (array $arr, string $key) { return $arr[$key]; }, $contents); return vsprintf('The key [%s] of the configuration array must be an array of %s, %s given for key [%s] (%s)', [ implode('.', $path), $type, gettype($arr[$key]), $key, realpath($this->path), ]); }
[ "private", "function", "arrayKeyTypeErrorMessage", "(", "array", "$", "contents", ",", "string", "$", "key", ",", "string", "$", "type", ",", "string", "...", "$", "path", ")", ":", "string", "{", "$", "arr", "=", "array_reduce", "(", "$", "path", ",", "function", "(", "array", "$", "arr", ",", "string", "$", "key", ")", "{", "return", "$", "arr", "[", "$", "key", "]", ";", "}", ",", "$", "contents", ")", ";", "return", "vsprintf", "(", "'The key [%s] of the configuration array must be an array of %s, %s given for key [%s] (%s)'", ",", "[", "implode", "(", "'.'", ",", "$", "path", ")", ",", "$", "type", ",", "gettype", "(", "$", "arr", "[", "$", "key", "]", ")", ",", "$", "key", ",", "realpath", "(", "$", "this", "->", "path", ")", ",", "]", ")", ";", "}" ]
Return the error message of the exception thrown when a key of an array is associated to a value with an unexpected type. @param array $contents @param string $key @param string $type @param string ...$path @return string
[ "Return", "the", "error", "message", "of", "the", "exception", "thrown", "when", "a", "key", "of", "an", "array", "is", "associated", "to", "a", "value", "with", "an", "unexpected", "type", "." ]
5e753d66a18d0ce4418cbf33fe6d6b74948f303d
https://github.com/quantaphp/container-factories/blob/5e753d66a18d0ce4418cbf33fe6d6b74948f303d/src/Configuration/PhpFileConfiguration.php#L275-L288
train
freialib/hlin.security
src/Auth.php
Auth.instance
static function instance(array $whitelist, array $blacklist, array $aliaslist, $main_entity_id = \hlin\Auth::Unidentified, $main_entity_role = \hlin\Auth::Guest, \hlin\archetype\Logger $logger = null) { $i = new static; $i->whitelist = $whitelist; $i->blacklist = $blacklist; $i->aliaslist = $aliaslist; $i->id = $main_entity_id; $i->role = $main_entity_role; $i->logger = $logger; return $i; }
php
static function instance(array $whitelist, array $blacklist, array $aliaslist, $main_entity_id = \hlin\Auth::Unidentified, $main_entity_role = \hlin\Auth::Guest, \hlin\archetype\Logger $logger = null) { $i = new static; $i->whitelist = $whitelist; $i->blacklist = $blacklist; $i->aliaslist = $aliaslist; $i->id = $main_entity_id; $i->role = $main_entity_role; $i->logger = $logger; return $i; }
[ "static", "function", "instance", "(", "array", "$", "whitelist", ",", "array", "$", "blacklist", ",", "array", "$", "aliaslist", ",", "$", "main_entity_id", "=", "\\", "hlin", "\\", "Auth", "::", "Unidentified", ",", "$", "main_entity_role", "=", "\\", "hlin", "\\", "Auth", "::", "Guest", ",", "\\", "hlin", "\\", "archetype", "\\", "Logger", "$", "logger", "=", "null", ")", "{", "$", "i", "=", "new", "static", ";", "$", "i", "->", "whitelist", "=", "$", "whitelist", ";", "$", "i", "->", "blacklist", "=", "$", "blacklist", ";", "$", "i", "->", "aliaslist", "=", "$", "aliaslist", ";", "$", "i", "->", "id", "=", "$", "main_entity_id", ";", "$", "i", "->", "role", "=", "$", "main_entity_role", ";", "$", "i", "->", "logger", "=", "$", "logger", ";", "return", "$", "i", ";", "}" ]
Most operations are on the current entity, so we require the current entity is set to facilitate the process; some operations also require the current entity to resolve. @return static
[ "Most", "operations", "are", "on", "the", "current", "entity", "so", "we", "require", "the", "current", "entity", "is", "set", "to", "facilitate", "the", "process", ";", "some", "operations", "also", "require", "the", "current", "entity", "to", "resolve", "." ]
7f6aea6a7eb64f1095e176ddfad64008eed68b2e
https://github.com/freialib/hlin.security/blob/7f6aea6a7eb64f1095e176ddfad64008eed68b2e/src/Auth.php#L48-L62
train
Vectrex/vxPHP
src/Http/Request.php
Request.overrideGlobals
public function overrideGlobals() { $this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), NULL, '&'))); $_GET = $this->query->all(); $_POST = $this->request->all(); $_SERVER = $this->server->all(); $_COOKIE = $this->cookies->all(); foreach ($this->headers->all() as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); if (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { $_SERVER[$key] = implode(', ', $value); } else { $_SERVER['HTTP_' . $key] = implode(', ', $value); } } $request = ['g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE]; $requestOrder = ini_get('request_order') ?: ini_get('variables_order'); $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp'; $_REQUEST = []; foreach (str_split($requestOrder) as $order) { $_REQUEST = array_merge($_REQUEST, $request[$order]); } }
php
public function overrideGlobals() { $this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), NULL, '&'))); $_GET = $this->query->all(); $_POST = $this->request->all(); $_SERVER = $this->server->all(); $_COOKIE = $this->cookies->all(); foreach ($this->headers->all() as $key => $value) { $key = strtoupper(str_replace('-', '_', $key)); if (in_array($key, ['CONTENT_TYPE', 'CONTENT_LENGTH'])) { $_SERVER[$key] = implode(', ', $value); } else { $_SERVER['HTTP_' . $key] = implode(', ', $value); } } $request = ['g' => $_GET, 'p' => $_POST, 'c' => $_COOKIE]; $requestOrder = ini_get('request_order') ?: ini_get('variables_order'); $requestOrder = preg_replace('#[^cgp]#', '', strtolower($requestOrder)) ?: 'gp'; $_REQUEST = []; foreach (str_split($requestOrder) as $order) { $_REQUEST = array_merge($_REQUEST, $request[$order]); } }
[ "public", "function", "overrideGlobals", "(", ")", "{", "$", "this", "->", "server", "->", "set", "(", "'QUERY_STRING'", ",", "static", "::", "normalizeQueryString", "(", "http_build_query", "(", "$", "this", "->", "query", "->", "all", "(", ")", ",", "NULL", ",", "'&'", ")", ")", ")", ";", "$", "_GET", "=", "$", "this", "->", "query", "->", "all", "(", ")", ";", "$", "_POST", "=", "$", "this", "->", "request", "->", "all", "(", ")", ";", "$", "_SERVER", "=", "$", "this", "->", "server", "->", "all", "(", ")", ";", "$", "_COOKIE", "=", "$", "this", "->", "cookies", "->", "all", "(", ")", ";", "foreach", "(", "$", "this", "->", "headers", "->", "all", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "key", "=", "strtoupper", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "key", ")", ")", ";", "if", "(", "in_array", "(", "$", "key", ",", "[", "'CONTENT_TYPE'", ",", "'CONTENT_LENGTH'", "]", ")", ")", "{", "$", "_SERVER", "[", "$", "key", "]", "=", "implode", "(", "', '", ",", "$", "value", ")", ";", "}", "else", "{", "$", "_SERVER", "[", "'HTTP_'", ".", "$", "key", "]", "=", "implode", "(", "', '", ",", "$", "value", ")", ";", "}", "}", "$", "request", "=", "[", "'g'", "=>", "$", "_GET", ",", "'p'", "=>", "$", "_POST", ",", "'c'", "=>", "$", "_COOKIE", "]", ";", "$", "requestOrder", "=", "ini_get", "(", "'request_order'", ")", "?", ":", "ini_get", "(", "'variables_order'", ")", ";", "$", "requestOrder", "=", "preg_replace", "(", "'#[^cgp]#'", ",", "''", ",", "strtolower", "(", "$", "requestOrder", ")", ")", "?", ":", "'gp'", ";", "$", "_REQUEST", "=", "[", "]", ";", "foreach", "(", "str_split", "(", "$", "requestOrder", ")", "as", "$", "order", ")", "{", "$", "_REQUEST", "=", "array_merge", "(", "$", "_REQUEST", ",", "$", "request", "[", "$", "order", "]", ")", ";", "}", "}" ]
Overrides the PHP global variables according to this request instance. It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. $_FILES is never overridden, see rfc1867
[ "Overrides", "the", "PHP", "global", "variables", "according", "to", "this", "request", "instance", "." ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Request.php#L486-L519
train
Vectrex/vxPHP
src/Http/Request.php
Request.setTrustedHosts
public static function setTrustedHosts(array $hostPatterns) { self::$trustedHostPatterns = array_map(function ($hostPattern) { return sprintf('#%s#i', $hostPattern); }, $hostPatterns); self::$trustedHosts = []; }
php
public static function setTrustedHosts(array $hostPatterns) { self::$trustedHostPatterns = array_map(function ($hostPattern) { return sprintf('#%s#i', $hostPattern); }, $hostPatterns); self::$trustedHosts = []; }
[ "public", "static", "function", "setTrustedHosts", "(", "array", "$", "hostPatterns", ")", "{", "self", "::", "$", "trustedHostPatterns", "=", "array_map", "(", "function", "(", "$", "hostPattern", ")", "{", "return", "sprintf", "(", "'#%s#i'", ",", "$", "hostPattern", ")", ";", "}", ",", "$", "hostPatterns", ")", ";", "self", "::", "$", "trustedHosts", "=", "[", "]", ";", "}" ]
Sets a list of trusted host patterns. You should only list the hosts you manage using regexs. @param array $hostPatterns A list of trusted host patterns
[ "Sets", "a", "list", "of", "trusted", "host", "patterns", ".", "You", "should", "only", "list", "the", "hosts", "you", "manage", "using", "regexs", "." ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Http/Request.php#L550-L558
train
phossa/phossa-config
src/Phossa/Config/Env/Environment.php
Environment.getContents
protected function getContents(/*# string */ $path)/*# string */ { // read in file $contents = @file_get_contents($path); // failed if (false === $contents) { throw new NotFoundException( Message::get(Message::CONFIG_FILE_NOTFOUND, $path), Message::CONFIG_FILE_NOTFOUND ); } return $contents; }
php
protected function getContents(/*# string */ $path)/*# string */ { // read in file $contents = @file_get_contents($path); // failed if (false === $contents) { throw new NotFoundException( Message::get(Message::CONFIG_FILE_NOTFOUND, $path), Message::CONFIG_FILE_NOTFOUND ); } return $contents; }
[ "protected", "function", "getContents", "(", "/*# string */", "$", "path", ")", "/*# string */", "{", "// read in file", "$", "contents", "=", "@", "file_get_contents", "(", "$", "path", ")", ";", "// failed", "if", "(", "false", "===", "$", "contents", ")", "{", "throw", "new", "NotFoundException", "(", "Message", "::", "get", "(", "Message", "::", "CONFIG_FILE_NOTFOUND", ",", "$", "path", ")", ",", "Message", "::", "CONFIG_FILE_NOTFOUND", ")", ";", "}", "return", "$", "contents", ";", "}" ]
Read contents from a local file system @param string $path @return string @access protected @throws NotFoundException if no file found
[ "Read", "contents", "from", "a", "local", "file", "system" ]
fdb90831da06408bb674ab777754e67025604bed
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Env/Environment.php#L85-L98
train
phossa/phossa-config
src/Phossa/Config/Env/Environment.php
Environment.matchEnv
protected function matchEnv(/*# string */ $name) { if ('_' === $name[0]) { // PHP super globals like _SERVER, _COOKIE etc. $pos = strpos($name, '.'); if (false !== $pos) { $pref = substr($name, 0, $pos); $suff = substr($name, $pos + 1); if (isset($GLOBALS[$pref][$suff])) { return $GLOBALS[$pref][$suff]; } } } return getenv($name); }
php
protected function matchEnv(/*# string */ $name) { if ('_' === $name[0]) { // PHP super globals like _SERVER, _COOKIE etc. $pos = strpos($name, '.'); if (false !== $pos) { $pref = substr($name, 0, $pos); $suff = substr($name, $pos + 1); if (isset($GLOBALS[$pref][$suff])) { return $GLOBALS[$pref][$suff]; } } } return getenv($name); }
[ "protected", "function", "matchEnv", "(", "/*# string */", "$", "name", ")", "{", "if", "(", "'_'", "===", "$", "name", "[", "0", "]", ")", "{", "// PHP super globals like _SERVER, _COOKIE etc.", "$", "pos", "=", "strpos", "(", "$", "name", ",", "'.'", ")", ";", "if", "(", "false", "!==", "$", "pos", ")", "{", "$", "pref", "=", "substr", "(", "$", "name", ",", "0", ",", "$", "pos", ")", ";", "$", "suff", "=", "substr", "(", "$", "name", ",", "$", "pos", "+", "1", ")", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "$", "pref", "]", "[", "$", "suff", "]", ")", ")", "{", "return", "$", "GLOBALS", "[", "$", "pref", "]", "[", "$", "suff", "]", ";", "}", "}", "}", "return", "getenv", "(", "$", "name", ")", ";", "}" ]
Find the env value base one the name - support super globals like '_SERVER.HTTP_HOST' etc. - use getenv() @param string $name @return string|false @access protected
[ "Find", "the", "env", "value", "base", "one", "the", "name" ]
fdb90831da06408bb674ab777754e67025604bed
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Env/Environment.php#L166-L180
train
theomessin/ts-framework
src/Helper/Convert.php
Convert.permissionType
public static function permissionType($type) { if ($type == Teamspeak::PERM_TYPE_SERVERGROUP) { return "Server Group"; } if ($type == Teamspeak::PERM_TYPE_CLIENT) { return "Client"; } if ($type == Teamspeak::PERM_TYPE_CHANNEL) { return "Channel"; } if ($type == Teamspeak::PERM_TYPE_CHANNELGROUP) { return "Channel Group"; } if ($type == Teamspeak::PERM_TYPE_CHANNELCLIENT) { return "Channel Client"; } return "Unknown"; }
php
public static function permissionType($type) { if ($type == Teamspeak::PERM_TYPE_SERVERGROUP) { return "Server Group"; } if ($type == Teamspeak::PERM_TYPE_CLIENT) { return "Client"; } if ($type == Teamspeak::PERM_TYPE_CHANNEL) { return "Channel"; } if ($type == Teamspeak::PERM_TYPE_CHANNELGROUP) { return "Channel Group"; } if ($type == Teamspeak::PERM_TYPE_CHANNELCLIENT) { return "Channel Client"; } return "Unknown"; }
[ "public", "static", "function", "permissionType", "(", "$", "type", ")", "{", "if", "(", "$", "type", "==", "Teamspeak", "::", "PERM_TYPE_SERVERGROUP", ")", "{", "return", "\"Server Group\"", ";", "}", "if", "(", "$", "type", "==", "Teamspeak", "::", "PERM_TYPE_CLIENT", ")", "{", "return", "\"Client\"", ";", "}", "if", "(", "$", "type", "==", "Teamspeak", "::", "PERM_TYPE_CHANNEL", ")", "{", "return", "\"Channel\"", ";", "}", "if", "(", "$", "type", "==", "Teamspeak", "::", "PERM_TYPE_CHANNELGROUP", ")", "{", "return", "\"Channel Group\"", ";", "}", "if", "(", "$", "type", "==", "Teamspeak", "::", "PERM_TYPE_CHANNELCLIENT", ")", "{", "return", "\"Channel Client\"", ";", "}", "return", "\"Unknown\"", ";", "}" ]
Converts a given permission type ID to a human readable name. @param integer $type @return string
[ "Converts", "a", "given", "permission", "type", "ID", "to", "a", "human", "readable", "name", "." ]
d60e36553241db05cb05ef19e749866cc977437c
https://github.com/theomessin/ts-framework/blob/d60e36553241db05cb05ef19e749866cc977437c/src/Helper/Convert.php#L148-L167
train
railken/lem
src/Validator.php
Validator.validateUniqueness
public function validateUniqueness($entity, $parameters) { $errors = new Collection(); foreach ($this->getManager()->getUnique() as $name => $attributes) { // Check if attribute exists... $q = $this->getManager()->getRepository()->getQuery(); $where = collect(); foreach ($attributes as $attribute) { $attribute = explode(':', $attribute); $col = count($attribute) > 1 ? $attribute[1] : $attribute[0]; $attribute = $attribute[0]; $value = $parameters->get($attribute, $entity->$attribute); if ($value) { $where[$col] = is_object($value) && $value instanceof EntityContract ? $value->id : $value; } } if ($entity->exists) { $q->where('id', '!=', $entity->id); } if ($where->count() > 0 && $q->where($where->toArray())->count() > 0) { $exception = $this->getManager()->getException(Tokens::NOT_UNIQUE); $errors->push(new $exception($where)); } } return $errors; }
php
public function validateUniqueness($entity, $parameters) { $errors = new Collection(); foreach ($this->getManager()->getUnique() as $name => $attributes) { // Check if attribute exists... $q = $this->getManager()->getRepository()->getQuery(); $where = collect(); foreach ($attributes as $attribute) { $attribute = explode(':', $attribute); $col = count($attribute) > 1 ? $attribute[1] : $attribute[0]; $attribute = $attribute[0]; $value = $parameters->get($attribute, $entity->$attribute); if ($value) { $where[$col] = is_object($value) && $value instanceof EntityContract ? $value->id : $value; } } if ($entity->exists) { $q->where('id', '!=', $entity->id); } if ($where->count() > 0 && $q->where($where->toArray())->count() > 0) { $exception = $this->getManager()->getException(Tokens::NOT_UNIQUE); $errors->push(new $exception($where)); } } return $errors; }
[ "public", "function", "validateUniqueness", "(", "$", "entity", ",", "$", "parameters", ")", "{", "$", "errors", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "this", "->", "getManager", "(", ")", "->", "getUnique", "(", ")", "as", "$", "name", "=>", "$", "attributes", ")", "{", "// Check if attribute exists...", "$", "q", "=", "$", "this", "->", "getManager", "(", ")", "->", "getRepository", "(", ")", "->", "getQuery", "(", ")", ";", "$", "where", "=", "collect", "(", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "$", "attribute", "=", "explode", "(", "':'", ",", "$", "attribute", ")", ";", "$", "col", "=", "count", "(", "$", "attribute", ")", ">", "1", "?", "$", "attribute", "[", "1", "]", ":", "$", "attribute", "[", "0", "]", ";", "$", "attribute", "=", "$", "attribute", "[", "0", "]", ";", "$", "value", "=", "$", "parameters", "->", "get", "(", "$", "attribute", ",", "$", "entity", "->", "$", "attribute", ")", ";", "if", "(", "$", "value", ")", "{", "$", "where", "[", "$", "col", "]", "=", "is_object", "(", "$", "value", ")", "&&", "$", "value", "instanceof", "EntityContract", "?", "$", "value", "->", "id", ":", "$", "value", ";", "}", "}", "if", "(", "$", "entity", "->", "exists", ")", "{", "$", "q", "->", "where", "(", "'id'", ",", "'!='", ",", "$", "entity", "->", "id", ")", ";", "}", "if", "(", "$", "where", "->", "count", "(", ")", ">", "0", "&&", "$", "q", "->", "where", "(", "$", "where", "->", "toArray", "(", ")", ")", "->", "count", "(", ")", ">", "0", ")", "{", "$", "exception", "=", "$", "this", "->", "getManager", "(", ")", "->", "getException", "(", "Tokens", "::", "NOT_UNIQUE", ")", ";", "$", "errors", "->", "push", "(", "new", "$", "exception", "(", "$", "where", ")", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Validate uniqueness. @param \Railken\Lem\Contracts\EntityContract $entity @param Bag $parameters @return Collection
[ "Validate", "uniqueness", "." ]
cff1efcd090a9504b2faf5594121885786dea67a
https://github.com/railken/lem/blob/cff1efcd090a9504b2faf5594121885786dea67a/src/Validator.php#L51-L86
train
Fenzland/http-api-gluer
src/Gluer/THoldsSerializers.php
THoldsSerializers.achieveSerializer
protected function achieveSerializer( string$mime ):S\ASerializer { $this->checkSerializerSupported( $mime ); $serializer= $this->getSerializer( $mime ); return static::instantiateSerializer_( $serializer ); }
php
protected function achieveSerializer( string$mime ):S\ASerializer { $this->checkSerializerSupported( $mime ); $serializer= $this->getSerializer( $mime ); return static::instantiateSerializer_( $serializer ); }
[ "protected", "function", "achieveSerializer", "(", "string", "$", "mime", ")", ":", "S", "\\", "ASerializer", "{", "$", "this", "->", "checkSerializerSupported", "(", "$", "mime", ")", ";", "$", "serializer", "=", "$", "this", "->", "getSerializer", "(", "$", "mime", ")", ";", "return", "static", "::", "instantiateSerializer_", "(", "$", "serializer", ")", ";", "}" ]
Static method achieveSerializer @access protected @param string $mime @return S\ASerializer
[ "Static", "method", "achieveSerializer" ]
3488de28b7f54fb444ec47f84034473a7d86e17e
https://github.com/Fenzland/http-api-gluer/blob/3488de28b7f54fb444ec47f84034473a7d86e17e/src/Gluer/THoldsSerializers.php#L126-L133
train
eureka-framework/component-error
src/Error/ErrorHandler.php
ErrorHandler.handler
public function handler($severity, $message, $file, $line) { throw new ErrorException($message, 0, $severity, $file, $line); }
php
public function handler($severity, $message, $file, $line) { throw new ErrorException($message, 0, $severity, $file, $line); }
[ "public", "function", "handler", "(", "$", "severity", ",", "$", "message", ",", "$", "file", ",", "$", "line", ")", "{", "throw", "new", "ErrorException", "(", "$", "message", ",", "0", ",", "$", "severity", ",", "$", "file", ",", "$", "line", ")", ";", "}" ]
Error handler. Throw new Eureka ErrorException @param int $severity Severity code Error. @param string $message Error message. @param string $file File name for Error. @param int $line File line for Error. @return void @throws ErrorException
[ "Error", "handler", ".", "Throw", "new", "Eureka", "ErrorException" ]
0c27be21d6623ffdf2f7a0591e76dad478b45832
https://github.com/eureka-framework/component-error/blob/0c27be21d6623ffdf2f7a0591e76dad478b45832/src/Error/ErrorHandler.php#L54-L57
train
mullanaphy/variable
src/PHY/Variable/Arr.php
Arr.toObject
public function toObject() { $array = $this->get(); foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = (new \PHY\Variable\Arr($value))->toObject(); } } return (object)$array; }
php
public function toObject() { $array = $this->get(); foreach ($array as $key => $value) { if (is_array($value)) { $array[$key] = (new \PHY\Variable\Arr($value))->toObject(); } } return (object)$array; }
[ "public", "function", "toObject", "(", ")", "{", "$", "array", "=", "$", "this", "->", "get", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "array", "[", "$", "key", "]", "=", "(", "new", "\\", "PHY", "\\", "Variable", "\\", "Arr", "(", "$", "value", ")", ")", "->", "toObject", "(", ")", ";", "}", "}", "return", "(", "object", ")", "$", "array", ";", "}" ]
Recursively convert our array into a stdClass. @return \stdClass
[ "Recursively", "convert", "our", "array", "into", "a", "stdClass", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Arr.php#L50-L59
train
mullanaphy/variable
src/PHY/Variable/Arr.php
Arr.offsetGet
public function offsetGet($offset) { $get = $this->chaining ? 'chain' : 'current'; return array_key_exists($offset, $this->$get) ? $this->$get[$offset] : null; }
php
public function offsetGet($offset) { $get = $this->chaining ? 'chain' : 'current'; return array_key_exists($offset, $this->$get) ? $this->$get[$offset] : null; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "$", "get", "=", "$", "this", "->", "chaining", "?", "'chain'", ":", "'current'", ";", "return", "array_key_exists", "(", "$", "offset", ",", "$", "this", "->", "$", "get", ")", "?", "$", "this", "->", "$", "get", "[", "$", "offset", "]", ":", "null", ";", "}" ]
Grab an offset if it's defined. @param scalar $offset @return mixed
[ "Grab", "an", "offset", "if", "it", "s", "defined", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Arr.php#L158-L166
train
mullanaphy/variable
src/PHY/Variable/Arr.php
Arr.offsetSet
public function offsetSet($offset, $value) { $get = $this->chaining ? 'chain' : 'current'; $this->$get[$offset] = $value; }
php
public function offsetSet($offset, $value) { $get = $this->chaining ? 'chain' : 'current'; $this->$get[$offset] = $value; }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "$", "get", "=", "$", "this", "->", "chaining", "?", "'chain'", ":", "'current'", ";", "$", "this", "->", "$", "get", "[", "$", "offset", "]", "=", "$", "value", ";", "}" ]
Set an offset. @param scalar $offset @param mixed $value
[ "Set", "an", "offset", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Arr.php#L174-L180
train
mullanaphy/variable
src/PHY/Variable/Arr.php
Arr.sort
public function sort($sort_flags = SORT_REGULAR) { $array = $this->get(); sort($array, $sort_flags); $this->update($array); return $this; }
php
public function sort($sort_flags = SORT_REGULAR) { $array = $this->get(); sort($array, $sort_flags); $this->update($array); return $this; }
[ "public", "function", "sort", "(", "$", "sort_flags", "=", "SORT_REGULAR", ")", "{", "$", "array", "=", "$", "this", "->", "get", "(", ")", ";", "sort", "(", "$", "array", ",", "$", "sort_flags", ")", ";", "$", "this", "->", "update", "(", "$", "array", ")", ";", "return", "$", "this", ";", "}" ]
Sort our Array. @param int $sort_flags @return \PHY\Variable\Arr
[ "Sort", "our", "Array", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Arr.php#L238-L244
train
mullanaphy/variable
src/PHY/Variable/Arr.php
Arr.slice
public function slice($offset = 0, $length = null, $preserve_keys = false) { $array = array_slice($this->get(), $offset, $length, $preserve_keys); $this->update($array); return $this; }
php
public function slice($offset = 0, $length = null, $preserve_keys = false) { $array = array_slice($this->get(), $offset, $length, $preserve_keys); $this->update($array); return $this; }
[ "public", "function", "slice", "(", "$", "offset", "=", "0", ",", "$", "length", "=", "null", ",", "$", "preserve_keys", "=", "false", ")", "{", "$", "array", "=", "array_slice", "(", "$", "this", "->", "get", "(", ")", ",", "$", "offset", ",", "$", "length", ",", "$", "preserve_keys", ")", ";", "$", "this", "->", "update", "(", "$", "array", ")", ";", "return", "$", "this", ";", "}" ]
Slice an Array. @param int $offset @param int|null $length @param boolean $preserve_keys @return \PHY\Variable\Arr
[ "Slice", "an", "Array", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Arr.php#L254-L259
train
mullanaphy/variable
src/PHY/Variable/Arr.php
Arr.splice
public function splice($offset = 0, $length = 0, $replacement = null) { $array = $this->get(); if (null !== $replacement) { array_splice($array, $offset, $length, $replacement); } else { array_splice($array, $offset, $length); } $this->update($array); return $this; }
php
public function splice($offset = 0, $length = 0, $replacement = null) { $array = $this->get(); if (null !== $replacement) { array_splice($array, $offset, $length, $replacement); } else { array_splice($array, $offset, $length); } $this->update($array); return $this; }
[ "public", "function", "splice", "(", "$", "offset", "=", "0", ",", "$", "length", "=", "0", ",", "$", "replacement", "=", "null", ")", "{", "$", "array", "=", "$", "this", "->", "get", "(", ")", ";", "if", "(", "null", "!==", "$", "replacement", ")", "{", "array_splice", "(", "$", "array", ",", "$", "offset", ",", "$", "length", ",", "$", "replacement", ")", ";", "}", "else", "{", "array_splice", "(", "$", "array", ",", "$", "offset", ",", "$", "length", ")", ";", "}", "$", "this", "->", "update", "(", "$", "array", ")", ";", "return", "$", "this", ";", "}" ]
Splice an array. @param int $offset @param int $length @param mixed $replacement @return \PHY\Variable\Arr
[ "Splice", "an", "array", "." ]
e4eb274a1799a25e33e5e21cd260603c74628031
https://github.com/mullanaphy/variable/blob/e4eb274a1799a25e33e5e21cd260603c74628031/src/PHY/Variable/Arr.php#L269-L279
train
Xsaven/laravel-intelect-admin
src/Addons/Scaffold/ModelCreator.php
ModelCreator.create
public function create($keyName = 'id', $route_key_name = 'id', $timestamps = true, $softDeletes = false, $fields=[]) { $path = $this->getpath($this->name); if ($this->files->exists($path)) { throw new \Exception("Model [$this->name] already exists!"); } $stub = $this->files->get($this->getStub()); $stub = $this->replaceClass($stub, $this->name) ->replaceNamespace($stub, $this->name) ->replaceSoftDeletes($stub, $softDeletes) ->replaceTable($stub, $this->name) ->replaceTimestamp($stub, $timestamps) ->replacePrimaryKey($stub, $keyName) ->replaceFillable($stub, $fields) ->replaceGuarded($stub, $fields) ->replaceCasts($stub, $fields) ->replaceRouteKeyName($stub, $route_key_name) ->replaceSpace($stub); $this->files->put($path, $stub); return $path; }
php
public function create($keyName = 'id', $route_key_name = 'id', $timestamps = true, $softDeletes = false, $fields=[]) { $path = $this->getpath($this->name); if ($this->files->exists($path)) { throw new \Exception("Model [$this->name] already exists!"); } $stub = $this->files->get($this->getStub()); $stub = $this->replaceClass($stub, $this->name) ->replaceNamespace($stub, $this->name) ->replaceSoftDeletes($stub, $softDeletes) ->replaceTable($stub, $this->name) ->replaceTimestamp($stub, $timestamps) ->replacePrimaryKey($stub, $keyName) ->replaceFillable($stub, $fields) ->replaceGuarded($stub, $fields) ->replaceCasts($stub, $fields) ->replaceRouteKeyName($stub, $route_key_name) ->replaceSpace($stub); $this->files->put($path, $stub); return $path; }
[ "public", "function", "create", "(", "$", "keyName", "=", "'id'", ",", "$", "route_key_name", "=", "'id'", ",", "$", "timestamps", "=", "true", ",", "$", "softDeletes", "=", "false", ",", "$", "fields", "=", "[", "]", ")", "{", "$", "path", "=", "$", "this", "->", "getpath", "(", "$", "this", "->", "name", ")", ";", "if", "(", "$", "this", "->", "files", "->", "exists", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Model [$this->name] already exists!\"", ")", ";", "}", "$", "stub", "=", "$", "this", "->", "files", "->", "get", "(", "$", "this", "->", "getStub", "(", ")", ")", ";", "$", "stub", "=", "$", "this", "->", "replaceClass", "(", "$", "stub", ",", "$", "this", "->", "name", ")", "->", "replaceNamespace", "(", "$", "stub", ",", "$", "this", "->", "name", ")", "->", "replaceSoftDeletes", "(", "$", "stub", ",", "$", "softDeletes", ")", "->", "replaceTable", "(", "$", "stub", ",", "$", "this", "->", "name", ")", "->", "replaceTimestamp", "(", "$", "stub", ",", "$", "timestamps", ")", "->", "replacePrimaryKey", "(", "$", "stub", ",", "$", "keyName", ")", "->", "replaceFillable", "(", "$", "stub", ",", "$", "fields", ")", "->", "replaceGuarded", "(", "$", "stub", ",", "$", "fields", ")", "->", "replaceCasts", "(", "$", "stub", ",", "$", "fields", ")", "->", "replaceRouteKeyName", "(", "$", "stub", ",", "$", "route_key_name", ")", "->", "replaceSpace", "(", "$", "stub", ")", ";", "$", "this", "->", "files", "->", "put", "(", "$", "path", ",", "$", "stub", ")", ";", "return", "$", "path", ";", "}" ]
Create a new migration file. @param string $keyName @param bool|true $timestamps @param bool|false $softDeletes @throws \Exception @return string
[ "Create", "a", "new", "migration", "file", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/ModelCreator.php#L57-L82
train
Xsaven/laravel-intelect-admin
src/Addons/Scaffold/ModelCreator.php
ModelCreator.replaceFillable
protected function replaceFillable(&$stub, $fields){ $fillable = []; foreach ($fields as $f){ if($f['add_to']=='fillable') $fillable[] = "\"{$f['name']}\""; } if(count($fillable)) $fillable = "protected \$fillable = [".implode(',',$fillable)."];"; else $fillable = ""; $stub = str_replace('DummyFillable', $fillable, $stub); return $this; }
php
protected function replaceFillable(&$stub, $fields){ $fillable = []; foreach ($fields as $f){ if($f['add_to']=='fillable') $fillable[] = "\"{$f['name']}\""; } if(count($fillable)) $fillable = "protected \$fillable = [".implode(',',$fillable)."];"; else $fillable = ""; $stub = str_replace('DummyFillable', $fillable, $stub); return $this; }
[ "protected", "function", "replaceFillable", "(", "&", "$", "stub", ",", "$", "fields", ")", "{", "$", "fillable", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "f", ")", "{", "if", "(", "$", "f", "[", "'add_to'", "]", "==", "'fillable'", ")", "$", "fillable", "[", "]", "=", "\"\\\"{$f['name']}\\\"\"", ";", "}", "if", "(", "count", "(", "$", "fillable", ")", ")", "$", "fillable", "=", "\"protected \\$fillable = [\"", ".", "implode", "(", "','", ",", "$", "fillable", ")", ".", "\"];\"", ";", "else", "$", "fillable", "=", "\"\"", ";", "$", "stub", "=", "str_replace", "(", "'DummyFillable'", ",", "$", "fillable", ",", "$", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace fillable dummy. @param string $stub @param array $fields @return $this
[ "Replace", "fillable", "dummy", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/ModelCreator.php#L226-L238
train
Xsaven/laravel-intelect-admin
src/Addons/Scaffold/ModelCreator.php
ModelCreator.replaceGuarded
protected function replaceGuarded(&$stub, $fields){ $guarded = []; foreach ($fields as $f){ if($f['add_to']=='guarded') $guarded[] = "\"{$f['name']}\""; } if(count($guarded)) $guarded = "protected \$guarded = [".implode(',',$guarded)."];"; else $guarded = ""; $stub = str_replace('DummyGuarded', $guarded, $stub); return $this; }
php
protected function replaceGuarded(&$stub, $fields){ $guarded = []; foreach ($fields as $f){ if($f['add_to']=='guarded') $guarded[] = "\"{$f['name']}\""; } if(count($guarded)) $guarded = "protected \$guarded = [".implode(',',$guarded)."];"; else $guarded = ""; $stub = str_replace('DummyGuarded', $guarded, $stub); return $this; }
[ "protected", "function", "replaceGuarded", "(", "&", "$", "stub", ",", "$", "fields", ")", "{", "$", "guarded", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "f", ")", "{", "if", "(", "$", "f", "[", "'add_to'", "]", "==", "'guarded'", ")", "$", "guarded", "[", "]", "=", "\"\\\"{$f['name']}\\\"\"", ";", "}", "if", "(", "count", "(", "$", "guarded", ")", ")", "$", "guarded", "=", "\"protected \\$guarded = [\"", ".", "implode", "(", "','", ",", "$", "guarded", ")", ".", "\"];\"", ";", "else", "$", "guarded", "=", "\"\"", ";", "$", "stub", "=", "str_replace", "(", "'DummyGuarded'", ",", "$", "guarded", ",", "$", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace guarded dummy. @param string $stub @param array $fields @return $this
[ "Replace", "guarded", "dummy", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/ModelCreator.php#L248-L260
train
Xsaven/laravel-intelect-admin
src/Addons/Scaffold/ModelCreator.php
ModelCreator.replaceCasts
protected function replaceCasts(&$stub, $fields){ $casts = []; foreach ($fields as $f){ if(!empty($f['casts'])) $casts[] = "\"{$f['name']}\"=>\"{$f['casts']}\""; } if(count($casts)) $casts = "protected \$casts = [".implode(',',$casts)."];"; else $casts = ""; $stub = str_replace('DummyCasts', $casts, $stub); return $this; }
php
protected function replaceCasts(&$stub, $fields){ $casts = []; foreach ($fields as $f){ if(!empty($f['casts'])) $casts[] = "\"{$f['name']}\"=>\"{$f['casts']}\""; } if(count($casts)) $casts = "protected \$casts = [".implode(',',$casts)."];"; else $casts = ""; $stub = str_replace('DummyCasts', $casts, $stub); return $this; }
[ "protected", "function", "replaceCasts", "(", "&", "$", "stub", ",", "$", "fields", ")", "{", "$", "casts", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "f", ")", "{", "if", "(", "!", "empty", "(", "$", "f", "[", "'casts'", "]", ")", ")", "$", "casts", "[", "]", "=", "\"\\\"{$f['name']}\\\"=>\\\"{$f['casts']}\\\"\"", ";", "}", "if", "(", "count", "(", "$", "casts", ")", ")", "$", "casts", "=", "\"protected \\$casts = [\"", ".", "implode", "(", "','", ",", "$", "casts", ")", ".", "\"];\"", ";", "else", "$", "casts", "=", "\"\"", ";", "$", "stub", "=", "str_replace", "(", "'DummyCasts'", ",", "$", "casts", ",", "$", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace casts dummy. @param string $stub @param array $fields @return $this
[ "Replace", "casts", "dummy", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/ModelCreator.php#L270-L281
train
Xsaven/laravel-intelect-admin
src/Addons/Scaffold/ModelCreator.php
ModelCreator.replaceRouteKeyName
protected function replaceRouteKeyName(&$stub, $route_key_name){ if($route_key_name=='id') $replace = ""; else{ $replace = "public function getRouteKeyName(){ return \"{$route_key_name}\"; }"; } $stub = str_replace('DummyRouteKeyName', $replace, $stub); return $this; }
php
protected function replaceRouteKeyName(&$stub, $route_key_name){ if($route_key_name=='id') $replace = ""; else{ $replace = "public function getRouteKeyName(){ return \"{$route_key_name}\"; }"; } $stub = str_replace('DummyRouteKeyName', $replace, $stub); return $this; }
[ "protected", "function", "replaceRouteKeyName", "(", "&", "$", "stub", ",", "$", "route_key_name", ")", "{", "if", "(", "$", "route_key_name", "==", "'id'", ")", "$", "replace", "=", "\"\"", ";", "else", "{", "$", "replace", "=", "\"public function getRouteKeyName(){ return \\\"{$route_key_name}\\\"; }\"", ";", "}", "$", "stub", "=", "str_replace", "(", "'DummyRouteKeyName'", ",", "$", "replace", ",", "$", "stub", ")", ";", "return", "$", "this", ";", "}" ]
Replace RouteKeyName dummy. @param string $stub @param array $fields @return $this
[ "Replace", "RouteKeyName", "dummy", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/ModelCreator.php#L291-L302
train
craig-mcmahon/google-helper
src/GoogleHelper/Drive/FilesHelper.php
FilesHelper.getFileByName
public function getFileByName( $folderName, $mimeType, $includeTrash = false, \Google_Service_Drive_DriveFile $parent = null, $createIfNotFound = false ) { $query = 'title = \'' . $folderName . '\' and mimeType = \'' . $mimeType . '\''; if (!$includeTrash) { $query .= ' and trashed = false'; } if ($parent !== null) { $query .= ' and \'' . $parent->getId() . '\' in parents'; } $fileList = $this->service->files->listFiles(array('q' => $query)); $folders = $fileList->getItems(); if (isset($folders[0])) { return $folders[0]; } if ($createIfNotFound) { $this->helper->getLogger()->debug('Creating Folder ' . $folderName); return $this->createFolder($folderName, $parent); } return null; }
php
public function getFileByName( $folderName, $mimeType, $includeTrash = false, \Google_Service_Drive_DriveFile $parent = null, $createIfNotFound = false ) { $query = 'title = \'' . $folderName . '\' and mimeType = \'' . $mimeType . '\''; if (!$includeTrash) { $query .= ' and trashed = false'; } if ($parent !== null) { $query .= ' and \'' . $parent->getId() . '\' in parents'; } $fileList = $this->service->files->listFiles(array('q' => $query)); $folders = $fileList->getItems(); if (isset($folders[0])) { return $folders[0]; } if ($createIfNotFound) { $this->helper->getLogger()->debug('Creating Folder ' . $folderName); return $this->createFolder($folderName, $parent); } return null; }
[ "public", "function", "getFileByName", "(", "$", "folderName", ",", "$", "mimeType", ",", "$", "includeTrash", "=", "false", ",", "\\", "Google_Service_Drive_DriveFile", "$", "parent", "=", "null", ",", "$", "createIfNotFound", "=", "false", ")", "{", "$", "query", "=", "'title = \\''", ".", "$", "folderName", ".", "'\\' and mimeType = \\''", ".", "$", "mimeType", ".", "'\\''", ";", "if", "(", "!", "$", "includeTrash", ")", "{", "$", "query", ".=", "' and trashed = false'", ";", "}", "if", "(", "$", "parent", "!==", "null", ")", "{", "$", "query", ".=", "' and \\''", ".", "$", "parent", "->", "getId", "(", ")", ".", "'\\' in parents'", ";", "}", "$", "fileList", "=", "$", "this", "->", "service", "->", "files", "->", "listFiles", "(", "array", "(", "'q'", "=>", "$", "query", ")", ")", ";", "$", "folders", "=", "$", "fileList", "->", "getItems", "(", ")", ";", "if", "(", "isset", "(", "$", "folders", "[", "0", "]", ")", ")", "{", "return", "$", "folders", "[", "0", "]", ";", "}", "if", "(", "$", "createIfNotFound", ")", "{", "$", "this", "->", "helper", "->", "getLogger", "(", ")", "->", "debug", "(", "'Creating Folder '", ".", "$", "folderName", ")", ";", "return", "$", "this", "->", "createFolder", "(", "$", "folderName", ",", "$", "parent", ")", ";", "}", "return", "null", ";", "}" ]
Get a file @param $folderName @param $mimeType @param bool $includeTrash @param \Google_Service_Drive_DriveFile $parent @param bool $createIfNotFound @return \Google_Service_Drive_DriveFile|null
[ "Get", "a", "file" ]
6b877efd7c9827555ecac65ee01e337849db6611
https://github.com/craig-mcmahon/google-helper/blob/6b877efd7c9827555ecac65ee01e337849db6611/src/GoogleHelper/Drive/FilesHelper.php#L17-L42
train
craig-mcmahon/google-helper
src/GoogleHelper/Drive/FilesHelper.php
FilesHelper.downloadFileFromURL
public function downloadFileFromURL($url) { $request = new \Google_Http_Request($url, 'GET', null, null); $httpRequest = $this->service->getClient() ->getAuth() ->authenticatedRequest($request); if ($httpRequest->getResponseHttpCode() == 200) { return $httpRequest->getResponseBody(); } else { // An error occurred. return null; } }
php
public function downloadFileFromURL($url) { $request = new \Google_Http_Request($url, 'GET', null, null); $httpRequest = $this->service->getClient() ->getAuth() ->authenticatedRequest($request); if ($httpRequest->getResponseHttpCode() == 200) { return $httpRequest->getResponseBody(); } else { // An error occurred. return null; } }
[ "public", "function", "downloadFileFromURL", "(", "$", "url", ")", "{", "$", "request", "=", "new", "\\", "Google_Http_Request", "(", "$", "url", ",", "'GET'", ",", "null", ",", "null", ")", ";", "$", "httpRequest", "=", "$", "this", "->", "service", "->", "getClient", "(", ")", "->", "getAuth", "(", ")", "->", "authenticatedRequest", "(", "$", "request", ")", ";", "if", "(", "$", "httpRequest", "->", "getResponseHttpCode", "(", ")", "==", "200", ")", "{", "return", "$", "httpRequest", "->", "getResponseBody", "(", ")", ";", "}", "else", "{", "// An error occurred.", "return", "null", ";", "}", "}" ]
Download a file from a url @param $url @return string|null
[ "Download", "a", "file", "from", "a", "url" ]
6b877efd7c9827555ecac65ee01e337849db6611
https://github.com/craig-mcmahon/google-helper/blob/6b877efd7c9827555ecac65ee01e337849db6611/src/GoogleHelper/Drive/FilesHelper.php#L138-L150
train
craig-mcmahon/google-helper
src/GoogleHelper/Drive/FilesHelper.php
FilesHelper.getFilesInFolder
public function getFilesInFolder(\Google_Service_Drive_DriveFile $folder) { $query = 'trashed = false and \'' . $folder->getId() . '\' in parents'; $fileList = $this->service->files->listFiles(array('q' => $query)); return $fileList; }
php
public function getFilesInFolder(\Google_Service_Drive_DriveFile $folder) { $query = 'trashed = false and \'' . $folder->getId() . '\' in parents'; $fileList = $this->service->files->listFiles(array('q' => $query)); return $fileList; }
[ "public", "function", "getFilesInFolder", "(", "\\", "Google_Service_Drive_DriveFile", "$", "folder", ")", "{", "$", "query", "=", "'trashed = false and \\''", ".", "$", "folder", "->", "getId", "(", ")", ".", "'\\' in parents'", ";", "$", "fileList", "=", "$", "this", "->", "service", "->", "files", "->", "listFiles", "(", "array", "(", "'q'", "=>", "$", "query", ")", ")", ";", "return", "$", "fileList", ";", "}" ]
Get Files in a folder @param \Google_Service_Drive_DriveFile $folder @return \Google_Service_Drive_FileList
[ "Get", "Files", "in", "a", "folder" ]
6b877efd7c9827555ecac65ee01e337849db6611
https://github.com/craig-mcmahon/google-helper/blob/6b877efd7c9827555ecac65ee01e337849db6611/src/GoogleHelper/Drive/FilesHelper.php#L157-L165
train
leapt/im-bundle
Manager.php
Manager.checkImage
private function checkImage($path) { if (!file_exists($this->getWebDirectory() . '/' . $path) && !file_exists($path)) { throw new NotFoundException(sprintf("Unable to find the image \"%s\" to cache", $path)); } if (!is_file($this->getWebDirectory() . '/' . $path) && !is_file($path)) { throw new HttpException(400, sprintf('[ImBundle] "%s" is no file', $path)); } }
php
private function checkImage($path) { if (!file_exists($this->getWebDirectory() . '/' . $path) && !file_exists($path)) { throw new NotFoundException(sprintf("Unable to find the image \"%s\" to cache", $path)); } if (!is_file($this->getWebDirectory() . '/' . $path) && !is_file($path)) { throw new HttpException(400, sprintf('[ImBundle] "%s" is no file', $path)); } }
[ "private", "function", "checkImage", "(", "$", "path", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "getWebDirectory", "(", ")", ".", "'/'", ".", "$", "path", ")", "&&", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "NotFoundException", "(", "sprintf", "(", "\"Unable to find the image \\\"%s\\\" to cache\"", ",", "$", "path", ")", ")", ";", "}", "if", "(", "!", "is_file", "(", "$", "this", "->", "getWebDirectory", "(", ")", ".", "'/'", ".", "$", "path", ")", "&&", "!", "is_file", "(", "$", "path", ")", ")", "{", "throw", "new", "HttpException", "(", "400", ",", "sprintf", "(", "'[ImBundle] \"%s\" is no file'", ",", "$", "path", ")", ")", ";", "}", "}" ]
Validates that an image exists @param string $path @throws NotFoundException @throws HttpException
[ "Validates", "that", "an", "image", "exists" ]
0d2bad7b68611cbf745f606c404a415274d78104
https://github.com/leapt/im-bundle/blob/0d2bad7b68611cbf745f606c404a415274d78104/Manager.php#L265-L274
train
phata/widgetfy
src/Core.php
Core.translate
public static function translate($url, $options=array()) { if (($embed = \Phata\Widgetfy\Site::translate($url, $options)) != NULL) { return $embed; } elseif (($embed = \Phata\Widgetfy\MediaFile::translate($url, $options)) != NULL) { return $embed; } return NULL; }
php
public static function translate($url, $options=array()) { if (($embed = \Phata\Widgetfy\Site::translate($url, $options)) != NULL) { return $embed; } elseif (($embed = \Phata\Widgetfy\MediaFile::translate($url, $options)) != NULL) { return $embed; } return NULL; }
[ "public", "static", "function", "translate", "(", "$", "url", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "(", "$", "embed", "=", "\\", "Phata", "\\", "Widgetfy", "\\", "Site", "::", "translate", "(", "$", "url", ",", "$", "options", ")", ")", "!=", "NULL", ")", "{", "return", "$", "embed", ";", "}", "elseif", "(", "(", "$", "embed", "=", "\\", "Phata", "\\", "Widgetfy", "\\", "MediaFile", "::", "translate", "(", "$", "url", ",", "$", "options", ")", ")", "!=", "NULL", ")", "{", "return", "$", "embed", ";", "}", "return", "NULL", ";", "}" ]
simplified interface to translate a url into embed code @param string $url URL to be translated @return mixed array of embed information or NULL if not translatable
[ "simplified", "interface", "to", "translate", "a", "url", "into", "embed", "code" ]
00102c35ec5267b42c627f1e34b8e64a7dd3590c
https://github.com/phata/widgetfy/blob/00102c35ec5267b42c627f1e34b8e64a7dd3590c/src/Core.php#L49-L58
train
libreworks/caridea-validate
src/Rule/Length.php
Length.between
public static function between(int $min, int $max, string $encoding = 'UTF-8'): Length { $length = [$min, $max]; sort($length); return new Length('bt', $length, $encoding); }
php
public static function between(int $min, int $max, string $encoding = 'UTF-8'): Length { $length = [$min, $max]; sort($length); return new Length('bt', $length, $encoding); }
[ "public", "static", "function", "between", "(", "int", "$", "min", ",", "int", "$", "max", ",", "string", "$", "encoding", "=", "'UTF-8'", ")", ":", "Length", "{", "$", "length", "=", "[", "$", "min", ",", "$", "max", "]", ";", "sort", "(", "$", "length", ")", ";", "return", "new", "Length", "(", "'bt'", ",", "$", "length", ",", "$", "encoding", ")", ";", "}" ]
Gets a rule that requires strings to have a minimum and maximum length. @param int $min The minimum length, inclusive @param int $max The maximum length, inclusive @param string $encoding The string encoding @return \Caridea\Validate\Rule\Length the created rule
[ "Gets", "a", "rule", "that", "requires", "strings", "to", "have", "a", "minimum", "and", "maximum", "length", "." ]
625835694d34591bfb1e3b2ce60c2cc28a28d006
https://github.com/libreworks/caridea-validate/blob/625835694d34591bfb1e3b2ce60c2cc28a28d006/src/Rule/Length.php#L133-L138
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.BeforeGather
protected function BeforeGather() { if ($this->IsTriggered() && $this->Elements()->Check(Request::MethodArray($this->Method()))) { return $this->OnSuccess(); } return parent::BeforeGather(); }
php
protected function BeforeGather() { if ($this->IsTriggered() && $this->Elements()->Check(Request::MethodArray($this->Method()))) { return $this->OnSuccess(); } return parent::BeforeGather(); }
[ "protected", "function", "BeforeGather", "(", ")", "{", "if", "(", "$", "this", "->", "IsTriggered", "(", ")", "&&", "$", "this", "->", "Elements", "(", ")", "->", "Check", "(", "Request", "::", "MethodArray", "(", "$", "this", "->", "Method", "(", ")", ")", ")", ")", "{", "return", "$", "this", "->", "OnSuccess", "(", ")", ";", "}", "return", "parent", "::", "BeforeGather", "(", ")", ";", "}" ]
Overrides the template module method to realize form logic @return boolean
[ "Overrides", "the", "template", "module", "method", "to", "realize", "form", "logic" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L90-L97
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.SetRequired
protected function SetRequired($name, $errorPrefix = '') { $field = $this->GetElement($name); if (!$field instanceof FormField) { throw new \InvalidArgumentException("$name is not a field in the form elements"); } if (!$errorPrefix) { $errorPrefix = $this->ErrorPrefix($name); } $field->SetRequired($errorPrefix); }
php
protected function SetRequired($name, $errorPrefix = '') { $field = $this->GetElement($name); if (!$field instanceof FormField) { throw new \InvalidArgumentException("$name is not a field in the form elements"); } if (!$errorPrefix) { $errorPrefix = $this->ErrorPrefix($name); } $field->SetRequired($errorPrefix); }
[ "protected", "function", "SetRequired", "(", "$", "name", ",", "$", "errorPrefix", "=", "''", ")", "{", "$", "field", "=", "$", "this", "->", "GetElement", "(", "$", "name", ")", ";", "if", "(", "!", "$", "field", "instanceof", "FormField", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"$name is not a field in the form elements\"", ")", ";", "}", "if", "(", "!", "$", "errorPrefix", ")", "{", "$", "errorPrefix", "=", "$", "this", "->", "ErrorPrefix", "(", "$", "name", ")", ";", "}", "$", "field", "->", "SetRequired", "(", "$", "errorPrefix", ")", ";", "}" ]
Sets the field as required @param string $name The name of the required field @param string $errorPrefix The label prefix, auto calculated if omitted
[ "Sets", "the", "field", "as", "required" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L176-L188
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.GetElement
public function GetElement($name) { $element = $this->Elements()->GetElement($name); if (!$element) { throw new \Exception(Trans('Core.Form.Error.ElementNotFound.Name_{0}', $name)); } return $element; }
php
public function GetElement($name) { $element = $this->Elements()->GetElement($name); if (!$element) { throw new \Exception(Trans('Core.Form.Error.ElementNotFound.Name_{0}', $name)); } return $element; }
[ "public", "function", "GetElement", "(", "$", "name", ")", "{", "$", "element", "=", "$", "this", "->", "Elements", "(", ")", "->", "GetElement", "(", "$", "name", ")", ";", "if", "(", "!", "$", "element", ")", "{", "throw", "new", "\\", "Exception", "(", "Trans", "(", "'Core.Form.Error.ElementNotFound.Name_{0}'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Gets the element with the given name @param string $name @return IFormElement
[ "Gets", "the", "element", "with", "the", "given", "name" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L194-L202
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.AddValidator
protected function AddValidator($name, Validator $validator, $errorPrefix = '') { $field = $this->GetElement($name); if (!$errorPrefix) { $errorPrefix = $this->ErrorPrefix($name); } $validator->SetErrorLabelPrefix($errorPrefix); $field->AddValidator($validator); }
php
protected function AddValidator($name, Validator $validator, $errorPrefix = '') { $field = $this->GetElement($name); if (!$errorPrefix) { $errorPrefix = $this->ErrorPrefix($name); } $validator->SetErrorLabelPrefix($errorPrefix); $field->AddValidator($validator); }
[ "protected", "function", "AddValidator", "(", "$", "name", ",", "Validator", "$", "validator", ",", "$", "errorPrefix", "=", "''", ")", "{", "$", "field", "=", "$", "this", "->", "GetElement", "(", "$", "name", ")", ";", "if", "(", "!", "$", "errorPrefix", ")", "{", "$", "errorPrefix", "=", "$", "this", "->", "ErrorPrefix", "(", "$", "name", ")", ";", "}", "$", "validator", "->", "SetErrorLabelPrefix", "(", "$", "errorPrefix", ")", ";", "$", "field", "->", "AddValidator", "(", "$", "validator", ")", ";", "}" ]
Adds a validator to the name @param string $name @param Validator $validator @param string $errorPrefix A custom error prefix
[ "Adds", "a", "validator", "to", "the", "name" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L210-L219
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.AddSubmit
protected function AddSubmit($name = '', $label = '') { $defaultLabel = $this->Label('Submit'); if (!$name) { //html attributes better without dot $name = str_replace('.', '-', $defaultLabel); } if (!$label) { $label = Worder::Replace($defaultLabel); } $this->triggerName = $name; $field = new Submit($name, $label); $this->Elements()->AddField($field); return $field; }
php
protected function AddSubmit($name = '', $label = '') { $defaultLabel = $this->Label('Submit'); if (!$name) { //html attributes better without dot $name = str_replace('.', '-', $defaultLabel); } if (!$label) { $label = Worder::Replace($defaultLabel); } $this->triggerName = $name; $field = new Submit($name, $label); $this->Elements()->AddField($field); return $field; }
[ "protected", "function", "AddSubmit", "(", "$", "name", "=", "''", ",", "$", "label", "=", "''", ")", "{", "$", "defaultLabel", "=", "$", "this", "->", "Label", "(", "'Submit'", ")", ";", "if", "(", "!", "$", "name", ")", "{", "//html attributes better without dot", "$", "name", "=", "str_replace", "(", "'.'", ",", "'-'", ",", "$", "defaultLabel", ")", ";", "}", "if", "(", "!", "$", "label", ")", "{", "$", "label", "=", "Worder", "::", "Replace", "(", "$", "defaultLabel", ")", ";", "}", "$", "this", "->", "triggerName", "=", "$", "name", ";", "$", "field", "=", "new", "Submit", "(", "$", "name", ",", "$", "label", ")", ";", "$", "this", "->", "Elements", "(", ")", "->", "AddField", "(", "$", "field", ")", ";", "return", "$", "field", ";", "}" ]
Adds a submit button that triggers the form logic on submit @param name The button name; if omitted, a name is generated by bundle and module name @param label The visible button label; if omitted, a label is generated @return Submit Returns the added submit button
[ "Adds", "a", "submit", "button", "that", "triggers", "the", "form", "logic", "on", "submit" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L226-L242
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.Value
protected function Value($name, $trim = true) { $value = Request::MethodData($this->Method(), $name); if ($trim) { return Str::Trim($value); } return $value; }
php
protected function Value($name, $trim = true) { $value = Request::MethodData($this->Method(), $name); if ($trim) { return Str::Trim($value); } return $value; }
[ "protected", "function", "Value", "(", "$", "name", ",", "$", "trim", "=", "true", ")", "{", "$", "value", "=", "Request", "::", "MethodData", "(", "$", "this", "->", "Method", "(", ")", ",", "$", "name", ")", ";", "if", "(", "$", "trim", ")", "{", "return", "Str", "::", "Trim", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
The form value as submitted @param string $name The field name @param boolean $trim If false, no string trimming is performed @return string Returns the submitted field value
[ "The", "form", "value", "as", "submitted" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L251-L259
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.FindSnippet
protected function FindSnippet(IFormField $field) { if ($field instanceof Input && ($field->GetType() == Input::TypeText || $field->GetType() == Input::TypePassword || $field->GetType() == Input::TypeColor)) { return new FormFields\TextInputField($field); } if ($field instanceof Input && $field->GetType() == Input::TypeHidden) { return new FormFields\HiddenInputField($field); } if ($field instanceof Input && $field->GetType() == Input::TypeFile) { return new FormFields\FileInputField($field); } if ($field instanceof Custom) { return new FormFields\CustomField($field); } if ($field instanceof Select) { return new FormFields\SelectField($field); } if ($field instanceof Textarea) { return new FormFields\TextareaField($field); } if ($field instanceof Checkbox) { return new FormFields\CheckboxField($field); } if ($field instanceof CheckList) { return new FormFields\CheckListField($field); } if ($field instanceof Submit) { return new FormFields\SubmitField($field); } if ($field instanceof Radio) { return new FormFields\RadioField($field); } }
php
protected function FindSnippet(IFormField $field) { if ($field instanceof Input && ($field->GetType() == Input::TypeText || $field->GetType() == Input::TypePassword || $field->GetType() == Input::TypeColor)) { return new FormFields\TextInputField($field); } if ($field instanceof Input && $field->GetType() == Input::TypeHidden) { return new FormFields\HiddenInputField($field); } if ($field instanceof Input && $field->GetType() == Input::TypeFile) { return new FormFields\FileInputField($field); } if ($field instanceof Custom) { return new FormFields\CustomField($field); } if ($field instanceof Select) { return new FormFields\SelectField($field); } if ($field instanceof Textarea) { return new FormFields\TextareaField($field); } if ($field instanceof Checkbox) { return new FormFields\CheckboxField($field); } if ($field instanceof CheckList) { return new FormFields\CheckListField($field); } if ($field instanceof Submit) { return new FormFields\SubmitField($field); } if ($field instanceof Radio) { return new FormFields\RadioField($field); } }
[ "protected", "function", "FindSnippet", "(", "IFormField", "$", "field", ")", "{", "if", "(", "$", "field", "instanceof", "Input", "&&", "(", "$", "field", "->", "GetType", "(", ")", "==", "Input", "::", "TypeText", "||", "$", "field", "->", "GetType", "(", ")", "==", "Input", "::", "TypePassword", "||", "$", "field", "->", "GetType", "(", ")", "==", "Input", "::", "TypeColor", ")", ")", "{", "return", "new", "FormFields", "\\", "TextInputField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Input", "&&", "$", "field", "->", "GetType", "(", ")", "==", "Input", "::", "TypeHidden", ")", "{", "return", "new", "FormFields", "\\", "HiddenInputField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Input", "&&", "$", "field", "->", "GetType", "(", ")", "==", "Input", "::", "TypeFile", ")", "{", "return", "new", "FormFields", "\\", "FileInputField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Custom", ")", "{", "return", "new", "FormFields", "\\", "CustomField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Select", ")", "{", "return", "new", "FormFields", "\\", "SelectField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Textarea", ")", "{", "return", "new", "FormFields", "\\", "TextareaField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Checkbox", ")", "{", "return", "new", "FormFields", "\\", "CheckboxField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "CheckList", ")", "{", "return", "new", "FormFields", "\\", "CheckListField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Submit", ")", "{", "return", "new", "FormFields", "\\", "SubmitField", "(", "$", "field", ")", ";", "}", "if", "(", "$", "field", "instanceof", "Radio", ")", "{", "return", "new", "FormFields", "\\", "RadioField", "(", "$", "field", ")", ";", "}", "}" ]
Finds the snippet for a form field; can be overriden for customization @param IFormField $field @return TemplateSnippet Returns the associated snippet renderer
[ "Finds", "the", "snippet", "for", "a", "form", "field", ";", "can", "be", "overriden", "for", "customization" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L267-L320
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.SetTransAttribute
protected function SetTransAttribute($name, $attribute) { $field = $this->GetElement($name); $field->SetHtmlAttribute($attribute, Worder::Replace($this->AttributePlaceholder($name, $attribute))); }
php
protected function SetTransAttribute($name, $attribute) { $field = $this->GetElement($name); $field->SetHtmlAttribute($attribute, Worder::Replace($this->AttributePlaceholder($name, $attribute))); }
[ "protected", "function", "SetTransAttribute", "(", "$", "name", ",", "$", "attribute", ")", "{", "$", "field", "=", "$", "this", "->", "GetElement", "(", "$", "name", ")", ";", "$", "field", "->", "SetHtmlAttribute", "(", "$", "attribute", ",", "Worder", "::", "Replace", "(", "$", "this", "->", "AttributePlaceholder", "(", "$", "name", ",", "$", "attribute", ")", ")", ")", ";", "}" ]
Sets a translatable attribute of the field to a default placeholder @param string $name The field name @param string $attribute The attribute name
[ "Sets", "a", "translatable", "attribute", "of", "the", "field", "to", "a", "default", "placeholder" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L346-L351
train
agentmedia/phine-core
src/Core/Logic/Module/Traits/Form.php
Form.SetTransDescription
protected function SetTransDescription($name) { $field = $this->GetElement($name); $field->SetDescription(Worder::Replace($this->FieldDescription($name))); }
php
protected function SetTransDescription($name) { $field = $this->GetElement($name); $field->SetDescription(Worder::Replace($this->FieldDescription($name))); }
[ "protected", "function", "SetTransDescription", "(", "$", "name", ")", "{", "$", "field", "=", "$", "this", "->", "GetElement", "(", "$", "name", ")", ";", "$", "field", "->", "SetDescription", "(", "Worder", "::", "Replace", "(", "$", "this", "->", "FieldDescription", "(", "$", "name", ")", ")", ")", ";", "}" ]
Sets a description with a default placeholder for translation @param string $name The field name
[ "Sets", "a", "description", "with", "a", "default", "placeholder", "for", "translation" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/Traits/Form.php#L358-L362
train
essence/dom
src/Document/Native.php
Native._loadDocument
protected function _loadDocument() { $this->_Document = new DOMDocument(); $reporting = error_reporting(0); $loaded = $this->_Document->loadHTML($this->_html); error_reporting($reporting); if (!$loaded) { throw new Exception('Unable to load HTML document.'); } }
php
protected function _loadDocument() { $this->_Document = new DOMDocument(); $reporting = error_reporting(0); $loaded = $this->_Document->loadHTML($this->_html); error_reporting($reporting); if (!$loaded) { throw new Exception('Unable to load HTML document.'); } }
[ "protected", "function", "_loadDocument", "(", ")", "{", "$", "this", "->", "_Document", "=", "new", "DOMDocument", "(", ")", ";", "$", "reporting", "=", "error_reporting", "(", "0", ")", ";", "$", "loaded", "=", "$", "this", "->", "_Document", "->", "loadHTML", "(", "$", "this", "->", "_html", ")", ";", "error_reporting", "(", "$", "reporting", ")", ";", "if", "(", "!", "$", "loaded", ")", "{", "throw", "new", "Exception", "(", "'Unable to load HTML document.'", ")", ";", "}", "}" ]
Builds a DOMDocument from the HTML source.
[ "Builds", "a", "DOMDocument", "from", "the", "HTML", "source", "." ]
e5776d2286f4ccbd048d160c28ac77ccc6d68f3a
https://github.com/essence/dom/blob/e5776d2286f4ccbd048d160c28ac77ccc6d68f3a/src/Document/Native.php#L70-L80
train
spoom-php/core
src/extension/File.php
File.path
public static function path( string $path ): string { if( !isset( self::$cache[ $path ] ) ) { // deep normalization if the path contains one-dir-up segment (clean multiple separators) $_path = preg_replace( '#\\' . static::DIRECTORY_SEPARATOR . '+#', static::DIRECTORY_SEPARATOR, ltrim( $path, static::DIRECTORY_SEPARATOR ) ); $tmp = explode( static::DIRECTORY_SEPARATOR, $_path ); $segments = []; foreach( $tmp as $segment ) { if( $segment != static::DIRECTORY_CURRENT ) { $last = empty( $segments ) ? '' : $segments[ count( $segments ) - 1 ]; if( $segment != static::DIRECTORY_PREVIOUS || in_array( $last, [ '', static::DIRECTORY_PREVIOUS ] ) ) $segments[] = $segment; else array_pop( $segments ); } } $_path = implode( static::DIRECTORY_SEPARATOR, $segments ); // check for root voilation if( preg_match( addcslashes( '#^' . static::DIRECTORY_PREVIOUS . '(' . static::DIRECTORY_SEPARATOR . '|$)#', './' ), $_path ) ) { throw new FilePathInvalidException( $path ); } self::$cache[ $path ] = $_path; } return self::$cache[ $path ]; }
php
public static function path( string $path ): string { if( !isset( self::$cache[ $path ] ) ) { // deep normalization if the path contains one-dir-up segment (clean multiple separators) $_path = preg_replace( '#\\' . static::DIRECTORY_SEPARATOR . '+#', static::DIRECTORY_SEPARATOR, ltrim( $path, static::DIRECTORY_SEPARATOR ) ); $tmp = explode( static::DIRECTORY_SEPARATOR, $_path ); $segments = []; foreach( $tmp as $segment ) { if( $segment != static::DIRECTORY_CURRENT ) { $last = empty( $segments ) ? '' : $segments[ count( $segments ) - 1 ]; if( $segment != static::DIRECTORY_PREVIOUS || in_array( $last, [ '', static::DIRECTORY_PREVIOUS ] ) ) $segments[] = $segment; else array_pop( $segments ); } } $_path = implode( static::DIRECTORY_SEPARATOR, $segments ); // check for root voilation if( preg_match( addcslashes( '#^' . static::DIRECTORY_PREVIOUS . '(' . static::DIRECTORY_SEPARATOR . '|$)#', './' ), $_path ) ) { throw new FilePathInvalidException( $path ); } self::$cache[ $path ] = $_path; } return self::$cache[ $path ]; }
[ "public", "static", "function", "path", "(", "string", "$", "path", ")", ":", "string", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "cache", "[", "$", "path", "]", ")", ")", "{", "// deep normalization if the path contains one-dir-up segment (clean multiple separators)", "$", "_path", "=", "preg_replace", "(", "'#\\\\'", ".", "static", "::", "DIRECTORY_SEPARATOR", ".", "'+#'", ",", "static", "::", "DIRECTORY_SEPARATOR", ",", "ltrim", "(", "$", "path", ",", "static", "::", "DIRECTORY_SEPARATOR", ")", ")", ";", "$", "tmp", "=", "explode", "(", "static", "::", "DIRECTORY_SEPARATOR", ",", "$", "_path", ")", ";", "$", "segments", "=", "[", "]", ";", "foreach", "(", "$", "tmp", "as", "$", "segment", ")", "{", "if", "(", "$", "segment", "!=", "static", "::", "DIRECTORY_CURRENT", ")", "{", "$", "last", "=", "empty", "(", "$", "segments", ")", "?", "''", ":", "$", "segments", "[", "count", "(", "$", "segments", ")", "-", "1", "]", ";", "if", "(", "$", "segment", "!=", "static", "::", "DIRECTORY_PREVIOUS", "||", "in_array", "(", "$", "last", ",", "[", "''", ",", "static", "::", "DIRECTORY_PREVIOUS", "]", ")", ")", "$", "segments", "[", "]", "=", "$", "segment", ";", "else", "array_pop", "(", "$", "segments", ")", ";", "}", "}", "$", "_path", "=", "implode", "(", "static", "::", "DIRECTORY_SEPARATOR", ",", "$", "segments", ")", ";", "// check for root voilation", "if", "(", "preg_match", "(", "addcslashes", "(", "'#^'", ".", "static", "::", "DIRECTORY_PREVIOUS", ".", "'('", ".", "static", "::", "DIRECTORY_SEPARATOR", ".", "'|$)#'", ",", "'./'", ")", ",", "$", "_path", ")", ")", "{", "throw", "new", "FilePathInvalidException", "(", "$", "path", ")", ";", "}", "self", "::", "$", "cache", "[", "$", "path", "]", "=", "$", "_path", ";", "}", "return", "self", "::", "$", "cache", "[", "$", "path", "]", ";", "}" ]
Normalize the given path Remove multiple (consecutive) separators and resolve static::DIRECTORY_CURRENT / static::DIRECTORY_PREVIOUS. This will remove the leading separator but keep the trailing one @param string $path Standard path string @return string @throws FilePathInvalidException The path begins with static::DIRECTORY_PREVIOUS, which will voilate the root
[ "Normalize", "the", "given", "path" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/File.php#L656-L685
train
spoom-php/core
src/extension/File.php
File.directory
public static function directory( string $path ): string { return ltrim( rtrim( $path, static::DIRECTORY_SEPARATOR ) . static::DIRECTORY_SEPARATOR, static::DIRECTORY_SEPARATOR ); }
php
public static function directory( string $path ): string { return ltrim( rtrim( $path, static::DIRECTORY_SEPARATOR ) . static::DIRECTORY_SEPARATOR, static::DIRECTORY_SEPARATOR ); }
[ "public", "static", "function", "directory", "(", "string", "$", "path", ")", ":", "string", "{", "return", "ltrim", "(", "rtrim", "(", "$", "path", ",", "static", "::", "DIRECTORY_SEPARATOR", ")", ".", "static", "::", "DIRECTORY_SEPARATOR", ",", "static", "::", "DIRECTORY_SEPARATOR", ")", ";", "}" ]
Force path to be a directory ..and ensure the trailing separator (except for root path) @param string $path @return string
[ "Force", "path", "to", "be", "a", "directory" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/File.php#L695-L697
train
OxfordInfoLabs/kinikit-core
src/Util/ObjectUtils.php
ObjectUtils.setNestedObjectProperty
public static function setNestedObjectProperty($value, &$object, $memberPath) { // Explode the path on . firstly $explodedPath = explode(".", $memberPath); // Pop the final entry $finalBit = array_pop($explodedPath); // Now call above function to get down to the point we need if (sizeof($explodedPath) > 0) { $nestedProperty = ObjectUtils::getNestedObjectProperty($object, implode(".", $explodedPath)); $immediateObject = &$nestedProperty; } else { $immediateObject = &$object; }; $explodedMemberName = explode("[", $finalBit); $memberName = $explodedMemberName[0]; if (is_array($immediateObject) || ($immediateObject instanceof AssociativeArray)) { $immediateObject[$memberName] = $value; } else if ($immediateObject instanceof SerialisableObject) { $immediateObject->__setSerialisablePropertyValue($memberName, $value); } }
php
public static function setNestedObjectProperty($value, &$object, $memberPath) { // Explode the path on . firstly $explodedPath = explode(".", $memberPath); // Pop the final entry $finalBit = array_pop($explodedPath); // Now call above function to get down to the point we need if (sizeof($explodedPath) > 0) { $nestedProperty = ObjectUtils::getNestedObjectProperty($object, implode(".", $explodedPath)); $immediateObject = &$nestedProperty; } else { $immediateObject = &$object; }; $explodedMemberName = explode("[", $finalBit); $memberName = $explodedMemberName[0]; if (is_array($immediateObject) || ($immediateObject instanceof AssociativeArray)) { $immediateObject[$memberName] = $value; } else if ($immediateObject instanceof SerialisableObject) { $immediateObject->__setSerialisablePropertyValue($memberName, $value); } }
[ "public", "static", "function", "setNestedObjectProperty", "(", "$", "value", ",", "&", "$", "object", ",", "$", "memberPath", ")", "{", "// Explode the path on . firstly", "$", "explodedPath", "=", "explode", "(", "\".\"", ",", "$", "memberPath", ")", ";", "// Pop the final entry", "$", "finalBit", "=", "array_pop", "(", "$", "explodedPath", ")", ";", "// Now call above function to get down to the point we need", "if", "(", "sizeof", "(", "$", "explodedPath", ")", ">", "0", ")", "{", "$", "nestedProperty", "=", "ObjectUtils", "::", "getNestedObjectProperty", "(", "$", "object", ",", "implode", "(", "\".\"", ",", "$", "explodedPath", ")", ")", ";", "$", "immediateObject", "=", "&", "$", "nestedProperty", ";", "}", "else", "{", "$", "immediateObject", "=", "&", "$", "object", ";", "}", ";", "$", "explodedMemberName", "=", "explode", "(", "\"[\"", ",", "$", "finalBit", ")", ";", "$", "memberName", "=", "$", "explodedMemberName", "[", "0", "]", ";", "if", "(", "is_array", "(", "$", "immediateObject", ")", "||", "(", "$", "immediateObject", "instanceof", "AssociativeArray", ")", ")", "{", "$", "immediateObject", "[", "$", "memberName", "]", "=", "$", "value", ";", "}", "else", "if", "(", "$", "immediateObject", "instanceof", "SerialisableObject", ")", "{", "$", "immediateObject", "->", "__setSerialisablePropertyValue", "(", "$", "memberName", ",", "$", "value", ")", ";", "}", "}" ]
Set a nested object property value on an object using a member path to locate it. @param $value @param $object @param $memberPath
[ "Set", "a", "nested", "object", "property", "value", "on", "an", "object", "using", "a", "member", "path", "to", "locate", "it", "." ]
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/ObjectUtils.php#L95-L126
train