repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
JBZoo/Path
src/Path.php
Path.prefix
public function prefix($path) { $path = $this->cleanPath($path); return preg_match('|^(?P<prefix>([a-zA-Z]+:)?//?)|', $path, $matches) ? $matches['prefix'] : null; }
php
public function prefix($path) { $path = $this->cleanPath($path); return preg_match('|^(?P<prefix>([a-zA-Z]+:)?//?)|', $path, $matches) ? $matches['prefix'] : null; }
[ "public", "function", "prefix", "(", "$", "path", ")", "{", "$", "path", "=", "$", "this", "->", "cleanPath", "(", "$", "path", ")", ";", "return", "preg_match", "(", "'|^(?P<prefix>([a-zA-Z]+:)?//?)|'", ",", "$", "path", ",", "$", "matches", ")", "?", "$", "matches", "[", "'prefix'", "]", ":", "null", ";", "}" ]
Get path prefix. @param string $path (example: "C:\server\test.dev\file.txt") @return null
[ "Get", "path", "prefix", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L300-L304
train
JBZoo/Path
src/Path.php
Path.remove
public function remove($fromSource, $paths): bool { $paths = (array)$paths; $fromSource = $this->cleanSource($fromSource); list($alias) = $this->parse($fromSource); $return = false; foreach ($paths as $origPath) { $path = $this->cleanPathInternal($this->cleanPath($origPath)); $key = array_search($path, $this->paths[$alias], true); if (false !== $key) { unset($this->paths[$alias][$key]); $return = true; } } return $return; }
php
public function remove($fromSource, $paths): bool { $paths = (array)$paths; $fromSource = $this->cleanSource($fromSource); list($alias) = $this->parse($fromSource); $return = false; foreach ($paths as $origPath) { $path = $this->cleanPathInternal($this->cleanPath($origPath)); $key = array_search($path, $this->paths[$alias], true); if (false !== $key) { unset($this->paths[$alias][$key]); $return = true; } } return $return; }
[ "public", "function", "remove", "(", "$", "fromSource", ",", "$", "paths", ")", ":", "bool", "{", "$", "paths", "=", "(", "array", ")", "$", "paths", ";", "$", "fromSource", "=", "$", "this", "->", "cleanSource", "(", "$", "fromSource", ")", ";", "list", "(", "$", "alias", ")", "=", "$", "this", "->", "parse", "(", "$", "fromSource", ")", ";", "$", "return", "=", "false", ";", "foreach", "(", "$", "paths", "as", "$", "origPath", ")", "{", "$", "path", "=", "$", "this", "->", "cleanPathInternal", "(", "$", "this", "->", "cleanPath", "(", "$", "origPath", ")", ")", ";", "$", "key", "=", "array_search", "(", "$", "path", ",", "$", "this", "->", "paths", "[", "$", "alias", "]", ",", "true", ")", ";", "if", "(", "false", "!==", "$", "key", ")", "{", "unset", "(", "$", "this", "->", "paths", "[", "$", "alias", "]", "[", "$", "key", "]", ")", ";", "$", "return", "=", "true", ";", "}", "}", "return", "$", "return", ";", "}" ]
Remove path from registered paths for source @param string $fromSource (example: "default:file.txt") @param string|array $paths @return bool
[ "Remove", "path", "from", "registered", "paths", "for", "source" ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L313-L332
train
JBZoo/Path
src/Path.php
Path.setRoot
public function setRoot($dir) { if (!is_dir($dir)) { throw new Exception(sprintf('Not found directory: %s', $dir)); } $this->root = $this->cleanPath($dir); }
php
public function setRoot($dir) { if (!is_dir($dir)) { throw new Exception(sprintf('Not found directory: %s', $dir)); } $this->root = $this->cleanPath($dir); }
[ "public", "function", "setRoot", "(", "$", "dir", ")", "{", "if", "(", "!", "is_dir", "(", "$", "dir", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Not found directory: %s'", ",", "$", "dir", ")", ")", ";", "}", "$", "this", "->", "root", "=", "$", "this", "->", "cleanPath", "(", "$", "dir", ")", ";", "}" ]
Setup root directory. @param string $dir @throws Exception
[ "Setup", "root", "directory", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L340-L347
train
JBZoo/Path
src/Path.php
Path.rel
public function rel($source) { $fullpath = (string)$this->get($source); return FS::getRelative($fullpath, $this->root, '/'); }
php
public function rel($source) { $fullpath = (string)$this->get($source); return FS::getRelative($fullpath, $this->root, '/'); }
[ "public", "function", "rel", "(", "$", "source", ")", "{", "$", "fullpath", "=", "(", "string", ")", "$", "this", "->", "get", "(", "$", "source", ")", ";", "return", "FS", "::", "getRelative", "(", "$", "fullpath", ",", "$", "this", "->", "root", ",", "'/'", ")", ";", "}" ]
Get relative path to file or directory @param string $source (example: "default:file.txt") @return null|string
[ "Get", "relative", "path", "to", "file", "or", "directory" ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L382-L386
train
JBZoo/Path
src/Path.php
Path.relGlob
public function relGlob($source) { $list = (array)$this->glob($source); foreach ($list as $key => $item) { $list[$key] = FS::getRelative($item, $this->root, '/'); } return $list; }
php
public function relGlob($source) { $list = (array)$this->glob($source); foreach ($list as $key => $item) { $list[$key] = FS::getRelative($item, $this->root, '/'); } return $list; }
[ "public", "function", "relGlob", "(", "$", "source", ")", "{", "$", "list", "=", "(", "array", ")", "$", "this", "->", "glob", "(", "$", "source", ")", ";", "foreach", "(", "$", "list", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "list", "[", "$", "key", "]", "=", "FS", "::", "getRelative", "(", "$", "item", ",", "$", "this", "->", "root", ",", "'/'", ")", ";", "}", "return", "$", "list", ";", "}" ]
Get list of relative path to file or directory @param string $source (example: "default:*.txt") @return null|string
[ "Get", "list", "of", "relative", "path", "to", "file", "or", "directory" ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L394-L402
train
JBZoo/Path
src/Path.php
Path.addNewPath
protected function addNewPath($path, $alias, $mode) { if ($cleanPath = $this->cleanPathInternal($path)) { if ($mode === self::MOD_PREPEND) { array_unshift($this->paths[$alias], $cleanPath); } if ($mode === self::MOD_APPEND) { $this->paths[$alias][] = $cleanPath; } } }
php
protected function addNewPath($path, $alias, $mode) { if ($cleanPath = $this->cleanPathInternal($path)) { if ($mode === self::MOD_PREPEND) { array_unshift($this->paths[$alias], $cleanPath); } if ($mode === self::MOD_APPEND) { $this->paths[$alias][] = $cleanPath; } } }
[ "protected", "function", "addNewPath", "(", "$", "path", ",", "$", "alias", ",", "$", "mode", ")", "{", "if", "(", "$", "cleanPath", "=", "$", "this", "->", "cleanPathInternal", "(", "$", "path", ")", ")", "{", "if", "(", "$", "mode", "===", "self", "::", "MOD_PREPEND", ")", "{", "array_unshift", "(", "$", "this", "->", "paths", "[", "$", "alias", "]", ",", "$", "cleanPath", ")", ";", "}", "if", "(", "$", "mode", "===", "self", "::", "MOD_APPEND", ")", "{", "$", "this", "->", "paths", "[", "$", "alias", "]", "[", "]", "=", "$", "cleanPath", ";", "}", "}", "}" ]
Add path to hold. @param string|array $path (example: "default:file.txt" or "C:/Server/public_html/index.php") @param string $alias @param string|bool $mode @return void
[ "Add", "path", "to", "hold", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L412-L423
train
JBZoo/Path
src/Path.php
Path.find
protected function find($paths, $file, $isGlob = false) { $paths = (array)$paths; $file = ltrim($file, "\\/"); foreach ($paths as $path) { $fullPath = $this->clean($path . '/' . $file); if ($isGlob) { $paths = glob($fullPath, GLOB_BRACE); $paths = array_filter((array)$paths); return $paths ?: []; } if (file_exists($fullPath) || is_dir($fullPath)) { return $fullPath; } } return null; }
php
protected function find($paths, $file, $isGlob = false) { $paths = (array)$paths; $file = ltrim($file, "\\/"); foreach ($paths as $path) { $fullPath = $this->clean($path . '/' . $file); if ($isGlob) { $paths = glob($fullPath, GLOB_BRACE); $paths = array_filter((array)$paths); return $paths ?: []; } if (file_exists($fullPath) || is_dir($fullPath)) { return $fullPath; } } return null; }
[ "protected", "function", "find", "(", "$", "paths", ",", "$", "file", ",", "$", "isGlob", "=", "false", ")", "{", "$", "paths", "=", "(", "array", ")", "$", "paths", ";", "$", "file", "=", "ltrim", "(", "$", "file", ",", "\"\\\\/\"", ")", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "$", "fullPath", "=", "$", "this", "->", "clean", "(", "$", "path", ".", "'/'", ".", "$", "file", ")", ";", "if", "(", "$", "isGlob", ")", "{", "$", "paths", "=", "glob", "(", "$", "fullPath", ",", "GLOB_BRACE", ")", ";", "$", "paths", "=", "array_filter", "(", "(", "array", ")", "$", "paths", ")", ";", "return", "$", "paths", "?", ":", "[", "]", ";", "}", "if", "(", "file_exists", "(", "$", "fullPath", ")", "||", "is_dir", "(", "$", "fullPath", ")", ")", "{", "return", "$", "fullPath", ";", "}", "}", "return", "null", ";", "}" ]
Find actual file or directory in the paths. @param string|array $paths @param string $file @param bool $isGlob @return null|string|array
[ "Find", "actual", "file", "or", "directory", "in", "the", "paths", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L445-L465
train
JBZoo/Path
src/Path.php
Path.cleanPathInternal
protected function cleanPathInternal($path) { if ($this->isVirtual($path)) { return $this->cleanPath($path); } if ($this->hasCDBack($path)) { $realpath = $this->cleanPath(realpath($path)); return $realpath ?: null; } return $this->cleanPath($path); }
php
protected function cleanPathInternal($path) { if ($this->isVirtual($path)) { return $this->cleanPath($path); } if ($this->hasCDBack($path)) { $realpath = $this->cleanPath(realpath($path)); return $realpath ?: null; } return $this->cleanPath($path); }
[ "protected", "function", "cleanPathInternal", "(", "$", "path", ")", "{", "if", "(", "$", "this", "->", "isVirtual", "(", "$", "path", ")", ")", "{", "return", "$", "this", "->", "cleanPath", "(", "$", "path", ")", ";", "}", "if", "(", "$", "this", "->", "hasCDBack", "(", "$", "path", ")", ")", "{", "$", "realpath", "=", "$", "this", "->", "cleanPath", "(", "realpath", "(", "$", "path", ")", ")", ";", "return", "$", "realpath", "?", ":", "null", ";", "}", "return", "$", "this", "->", "cleanPath", "(", "$", "path", ")", ";", "}" ]
Get add path. @param string $path (example: "default:file.txt" or "C:/Server/public_html/index.php") @param string $path @return null|string
[ "Get", "add", "path", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L474-L486
train
JBZoo/Path
src/Path.php
Path.getUrlPath
protected function getUrlPath($path, $exitsFile = false): string { $this->checkRoot(); $path = $this->cleanPathInternal($path); if ($this->isVirtual($path)) { $path = $this->get($path); } $subject = $path; $pattern = '/^' . preg_quote($this->root, '/') . '/i'; if ($exitsFile && !$this->isVirtual($path) && !file_exists($path)) { $subject = null; } return ltrim(preg_replace($pattern, '', $subject), '/'); }
php
protected function getUrlPath($path, $exitsFile = false): string { $this->checkRoot(); $path = $this->cleanPathInternal($path); if ($this->isVirtual($path)) { $path = $this->get($path); } $subject = $path; $pattern = '/^' . preg_quote($this->root, '/') . '/i'; if ($exitsFile && !$this->isVirtual($path) && !file_exists($path)) { $subject = null; } return ltrim(preg_replace($pattern, '', $subject), '/'); }
[ "protected", "function", "getUrlPath", "(", "$", "path", ",", "$", "exitsFile", "=", "false", ")", ":", "string", "{", "$", "this", "->", "checkRoot", "(", ")", ";", "$", "path", "=", "$", "this", "->", "cleanPathInternal", "(", "$", "path", ")", ";", "if", "(", "$", "this", "->", "isVirtual", "(", "$", "path", ")", ")", "{", "$", "path", "=", "$", "this", "->", "get", "(", "$", "path", ")", ";", "}", "$", "subject", "=", "$", "path", ";", "$", "pattern", "=", "'/^'", ".", "preg_quote", "(", "$", "this", "->", "root", ",", "'/'", ")", ".", "'/i'", ";", "if", "(", "$", "exitsFile", "&&", "!", "$", "this", "->", "isVirtual", "(", "$", "path", ")", "&&", "!", "file_exists", "(", "$", "path", ")", ")", "{", "$", "subject", "=", "null", ";", "}", "return", "ltrim", "(", "preg_replace", "(", "$", "pattern", ",", "''", ",", "$", "subject", ")", ",", "'/'", ")", ";", "}" ]
Get url path. @param string $path (example: "default:file.txt" or "C:/Server/public_html/index.php") @param bool $exitsFile @return string @throws Exception
[ "Get", "url", "path", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L496-L513
train
JBZoo/Path
src/Path.php
Path.parse
protected function parse($source): array { $path = null; list($alias, $path) = explode(':', $source, 2); $path = ltrim($path, "\\/"); $paths = $this->resolvePaths($alias); return [$alias, $paths, $path]; }
php
protected function parse($source): array { $path = null; list($alias, $path) = explode(':', $source, 2); $path = ltrim($path, "\\/"); $paths = $this->resolvePaths($alias); return [$alias, $paths, $path]; }
[ "protected", "function", "parse", "(", "$", "source", ")", ":", "array", "{", "$", "path", "=", "null", ";", "list", "(", "$", "alias", ",", "$", "path", ")", "=", "explode", "(", "':'", ",", "$", "source", ",", "2", ")", ";", "$", "path", "=", "ltrim", "(", "$", "path", ",", "\"\\\\/\"", ")", ";", "$", "paths", "=", "$", "this", "->", "resolvePaths", "(", "$", "alias", ")", ";", "return", "[", "$", "alias", ",", "$", "paths", ",", "$", "path", "]", ";", "}" ]
Parse source string. @param string $source (example: "default:file.txt") @return array
[ "Parse", "source", "string", "." ]
98f8427340ba3f55a999e1ea99f41a526fe2ee90
https://github.com/JBZoo/Path/blob/98f8427340ba3f55a999e1ea99f41a526fe2ee90/src/Path.php#L533-L542
train
agentmedia/phine-core
src/Core/Modules/Backend/ContainerForm.php
ContainerForm.Init
protected function Init() { $this->container = new Container(Request::GetData('container')); $this->containerRights = new ContainerRights($this->container->GetUserGroupRights()); $this->AddNameField(); $this->AddUserGroupField(); $this->AddSubmit(); return parent::Init(); }
php
protected function Init() { $this->container = new Container(Request::GetData('container')); $this->containerRights = new ContainerRights($this->container->GetUserGroupRights()); $this->AddNameField(); $this->AddUserGroupField(); $this->AddSubmit(); return parent::Init(); }
[ "protected", "function", "Init", "(", ")", "{", "$", "this", "->", "container", "=", "new", "Container", "(", "Request", "::", "GetData", "(", "'container'", ")", ")", ";", "$", "this", "->", "containerRights", "=", "new", "ContainerRights", "(", "$", "this", "->", "container", "->", "GetUserGroupRights", "(", ")", ")", ";", "$", "this", "->", "AddNameField", "(", ")", ";", "$", "this", "->", "AddUserGroupField", "(", ")", ";", "$", "this", "->", "AddSubmit", "(", ")", ";", "return", "parent", "::", "Init", "(", ")", ";", "}" ]
Initializes the container form @return boolea True if processing shall continue
[ "Initializes", "the", "container", "form" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/ContainerForm.php#L39-L47
train
agentmedia/phine-core
src/Core/Modules/Backend/ContainerForm.php
ContainerForm.OnSuccess
protected function OnSuccess() { $action = Action::Update(); if (!$this->container->Exists()) { $action = Action::Create(); $this->container->SetUser(self::Guard()->GetUser()); } $this->container->SetName($this->Value('Name')); $this->container->Save(); $logger = new Logger(self::Guard()->GetUser()); $logger->ReportContainerAction($this->container, $action); if ($this->CanAssignGroup()) { $this->SaveRights(); } Response::Redirect(BackendRouter::ModuleUrl(new ContainerList())); }
php
protected function OnSuccess() { $action = Action::Update(); if (!$this->container->Exists()) { $action = Action::Create(); $this->container->SetUser(self::Guard()->GetUser()); } $this->container->SetName($this->Value('Name')); $this->container->Save(); $logger = new Logger(self::Guard()->GetUser()); $logger->ReportContainerAction($this->container, $action); if ($this->CanAssignGroup()) { $this->SaveRights(); } Response::Redirect(BackendRouter::ModuleUrl(new ContainerList())); }
[ "protected", "function", "OnSuccess", "(", ")", "{", "$", "action", "=", "Action", "::", "Update", "(", ")", ";", "if", "(", "!", "$", "this", "->", "container", "->", "Exists", "(", ")", ")", "{", "$", "action", "=", "Action", "::", "Create", "(", ")", ";", "$", "this", "->", "container", "->", "SetUser", "(", "self", "::", "Guard", "(", ")", "->", "GetUser", "(", ")", ")", ";", "}", "$", "this", "->", "container", "->", "SetName", "(", "$", "this", "->", "Value", "(", "'Name'", ")", ")", ";", "$", "this", "->", "container", "->", "Save", "(", ")", ";", "$", "logger", "=", "new", "Logger", "(", "self", "::", "Guard", "(", ")", "->", "GetUser", "(", ")", ")", ";", "$", "logger", "->", "ReportContainerAction", "(", "$", "this", "->", "container", ",", "$", "action", ")", ";", "if", "(", "$", "this", "->", "CanAssignGroup", "(", ")", ")", "{", "$", "this", "->", "SaveRights", "(", ")", ";", "}", "Response", "::", "Redirect", "(", "BackendRouter", "::", "ModuleUrl", "(", "new", "ContainerList", "(", ")", ")", ")", ";", "}" ]
Saves the container
[ "Saves", "the", "container" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/ContainerForm.php#L76-L95
train
agentmedia/phine-core
src/Core/Modules/Backend/ContainerForm.php
ContainerForm.SaveRights
private function SaveRights() { $groupID = $this->Value('UserGroup'); $userGroup = Usergroup::Schema()->ByID($groupID); $this->container->SetUserGroup($userGroup); if (!$userGroup) { $oldRights = $this->container->GetUserGroupRights(); if ($oldRights) { $oldRights->GetContentRights()->Delete(); } $this->container->SetUserGroupRights(null); } else { $this->container->SetUserGroup($userGroup); $this->containerRights->Save(); $this->container->SetUserGroupRights($this->containerRights->Rights()); } $this->container->Save(); }
php
private function SaveRights() { $groupID = $this->Value('UserGroup'); $userGroup = Usergroup::Schema()->ByID($groupID); $this->container->SetUserGroup($userGroup); if (!$userGroup) { $oldRights = $this->container->GetUserGroupRights(); if ($oldRights) { $oldRights->GetContentRights()->Delete(); } $this->container->SetUserGroupRights(null); } else { $this->container->SetUserGroup($userGroup); $this->containerRights->Save(); $this->container->SetUserGroupRights($this->containerRights->Rights()); } $this->container->Save(); }
[ "private", "function", "SaveRights", "(", ")", "{", "$", "groupID", "=", "$", "this", "->", "Value", "(", "'UserGroup'", ")", ";", "$", "userGroup", "=", "Usergroup", "::", "Schema", "(", ")", "->", "ByID", "(", "$", "groupID", ")", ";", "$", "this", "->", "container", "->", "SetUserGroup", "(", "$", "userGroup", ")", ";", "if", "(", "!", "$", "userGroup", ")", "{", "$", "oldRights", "=", "$", "this", "->", "container", "->", "GetUserGroupRights", "(", ")", ";", "if", "(", "$", "oldRights", ")", "{", "$", "oldRights", "->", "GetContentRights", "(", ")", "->", "Delete", "(", ")", ";", "}", "$", "this", "->", "container", "->", "SetUserGroupRights", "(", "null", ")", ";", "}", "else", "{", "$", "this", "->", "container", "->", "SetUserGroup", "(", "$", "userGroup", ")", ";", "$", "this", "->", "containerRights", "->", "Save", "(", ")", ";", "$", "this", "->", "container", "->", "SetUserGroupRights", "(", "$", "this", "->", "containerRights", "->", "Rights", "(", ")", ")", ";", "}", "$", "this", "->", "container", "->", "Save", "(", ")", ";", "}" ]
Saves group and rights
[ "Saves", "group", "and", "rights" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/ContainerForm.php#L110-L131
train
fiiSoft/fiisoft-basics
src/Tools/Configuration/AbstractConfiguration.php
AbstractConfiguration.mergeCopyWith
public function mergeCopyWith($other, $notNull = true) { $copy = clone $this; if ($other === $this) { return $copy; } if ($other instanceof self) { foreach ($other->toArray($notNull) as $key => $value) { if (property_exists($copy, $key)) { $copy->$key = $value; } } } elseif (is_array($other) || $other instanceof \Traversable) { foreach ($other as $key => $value) { if (($notNull === false || $value !== null) && property_exists($copy, $key)) { $copy->$key = $value; } } } else if ($other instanceof \ArrayAccess) { foreach (array_keys(get_object_vars($copy)) as $key) { if (isset($other[$key])) { $value = $other[$key]; if ($notNull === false || $value !== null) { $copy->$key = $value; } } } } else { throw new \InvalidArgumentException('Invalid type of param other'); } return $copy; }
php
public function mergeCopyWith($other, $notNull = true) { $copy = clone $this; if ($other === $this) { return $copy; } if ($other instanceof self) { foreach ($other->toArray($notNull) as $key => $value) { if (property_exists($copy, $key)) { $copy->$key = $value; } } } elseif (is_array($other) || $other instanceof \Traversable) { foreach ($other as $key => $value) { if (($notNull === false || $value !== null) && property_exists($copy, $key)) { $copy->$key = $value; } } } else if ($other instanceof \ArrayAccess) { foreach (array_keys(get_object_vars($copy)) as $key) { if (isset($other[$key])) { $value = $other[$key]; if ($notNull === false || $value !== null) { $copy->$key = $value; } } } } else { throw new \InvalidArgumentException('Invalid type of param other'); } return $copy; }
[ "public", "function", "mergeCopyWith", "(", "$", "other", ",", "$", "notNull", "=", "true", ")", "{", "$", "copy", "=", "clone", "$", "this", ";", "if", "(", "$", "other", "===", "$", "this", ")", "{", "return", "$", "copy", ";", "}", "if", "(", "$", "other", "instanceof", "self", ")", "{", "foreach", "(", "$", "other", "->", "toArray", "(", "$", "notNull", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "property_exists", "(", "$", "copy", ",", "$", "key", ")", ")", "{", "$", "copy", "->", "$", "key", "=", "$", "value", ";", "}", "}", "}", "elseif", "(", "is_array", "(", "$", "other", ")", "||", "$", "other", "instanceof", "\\", "Traversable", ")", "{", "foreach", "(", "$", "other", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "(", "$", "notNull", "===", "false", "||", "$", "value", "!==", "null", ")", "&&", "property_exists", "(", "$", "copy", ",", "$", "key", ")", ")", "{", "$", "copy", "->", "$", "key", "=", "$", "value", ";", "}", "}", "}", "else", "if", "(", "$", "other", "instanceof", "\\", "ArrayAccess", ")", "{", "foreach", "(", "array_keys", "(", "get_object_vars", "(", "$", "copy", ")", ")", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "other", "[", "$", "key", "]", ")", ")", "{", "$", "value", "=", "$", "other", "[", "$", "key", "]", ";", "if", "(", "$", "notNull", "===", "false", "||", "$", "value", "!==", "null", ")", "{", "$", "copy", "->", "$", "key", "=", "$", "value", ";", "}", "}", "}", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid type of param other'", ")", ";", "}", "return", "$", "copy", ";", "}" ]
Create copy of this configuration with merged other data. @param AbstractConfiguration|\Traversable|\ArrayAccess|array $other @param bool $notNull @throws \InvalidArgumentException if cannot merge $other to $this @return AbstractConfiguration copy of $this configuration with merged $other data
[ "Create", "copy", "of", "this", "configuration", "with", "merged", "other", "data", "." ]
cf0e56a9abf646fae075f16e65eced282601c193
https://github.com/fiiSoft/fiisoft-basics/blob/cf0e56a9abf646fae075f16e65eced282601c193/src/Tools/Configuration/AbstractConfiguration.php#L76-L110
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.setWidth
public final function setWidth( int $width ) : Size { $this->triggerFixedErrorByNeed( 'width-change' ); $this->_width = \max( $width, 0 ); return $this; }
php
public final function setWidth( int $width ) : Size { $this->triggerFixedErrorByNeed( 'width-change' ); $this->_width = \max( $width, 0 ); return $this; }
[ "public", "final", "function", "setWidth", "(", "int", "$", "width", ")", ":", "Size", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'width-change'", ")", ";", "$", "this", "->", "_width", "=", "\\", "max", "(", "$", "width", ",", "0", ")", ";", "return", "$", "this", ";", "}" ]
Sets the width. @param int $width @return Size @throws \Beluga\BelugaError If the instance is set to fixed
[ "Sets", "the", "width", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L154-L163
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.setHeight
public final function setHeight( int $height ) : Size { $this->triggerFixedErrorByNeed( 'height-change' ); $this->_height = \max( $height, 0 ); return $this; }
php
public final function setHeight( int $height ) : Size { $this->triggerFixedErrorByNeed( 'height-change' ); $this->_height = \max( $height, 0 ); return $this; }
[ "public", "final", "function", "setHeight", "(", "int", "$", "height", ")", ":", "Size", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'height-change'", ")", ";", "$", "this", "->", "_height", "=", "\\", "max", "(", "$", "height", ",", "0", ")", ";", "return", "$", "this", ";", "}" ]
Sets the height. @param int $height @return Size @throws \Beluga\BelugaError If the instance is set to fixed
[ "Sets", "the", "height", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L172-L181
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.contains
public final function contains( Size $size ) : bool { return ( ( $size->_width <= $this->_width ) && ( $size->_height <= $this->_height ) ); }
php
public final function contains( Size $size ) : bool { return ( ( $size->_width <= $this->_width ) && ( $size->_height <= $this->_height ) ); }
[ "public", "final", "function", "contains", "(", "Size", "$", "size", ")", ":", "bool", "{", "return", "(", "(", "$", "size", "->", "_width", "<=", "$", "this", "->", "_width", ")", "&&", "(", "$", "size", "->", "_height", "<=", "$", "this", "->", "_height", ")", ")", ";", "}" ]
Returns if the current size can contain the size dimensions of the defined size. @param \Beluga\Drawing\Size $size @return bool
[ "Returns", "if", "the", "current", "size", "can", "contain", "the", "size", "dimensions", "of", "the", "defined", "size", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L206-L215
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.isNearQuadratic
public final function isNearQuadratic( float $maxDifference = 0.15 ) : bool { if ( $this->isQuadratic() ) { return true; } if ( $maxDifference >= 0.01 && $maxDifference <= 0.3 ) { $diff = 1.0 + $maxDifference; } else { $diff = 1.15; } if ( $this->isPortrait() ) { return ( ( 0.0 + $this->_height ) / $this->_width ) <= $diff; } return ( ( 0.0 + $this->_width ) / $this->_height ) <= $diff; }
php
public final function isNearQuadratic( float $maxDifference = 0.15 ) : bool { if ( $this->isQuadratic() ) { return true; } if ( $maxDifference >= 0.01 && $maxDifference <= 0.3 ) { $diff = 1.0 + $maxDifference; } else { $diff = 1.15; } if ( $this->isPortrait() ) { return ( ( 0.0 + $this->_height ) / $this->_width ) <= $diff; } return ( ( 0.0 + $this->_width ) / $this->_height ) <= $diff; }
[ "public", "final", "function", "isNearQuadratic", "(", "float", "$", "maxDifference", "=", "0.15", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "isQuadratic", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "maxDifference", ">=", "0.01", "&&", "$", "maxDifference", "<=", "0.3", ")", "{", "$", "diff", "=", "1.0", "+", "$", "maxDifference", ";", "}", "else", "{", "$", "diff", "=", "1.15", ";", "}", "if", "(", "$", "this", "->", "isPortrait", "(", ")", ")", "{", "return", "(", "(", "0.0", "+", "$", "this", "->", "_height", ")", "/", "$", "this", "->", "_width", ")", "<=", "$", "diff", ";", "}", "return", "(", "(", "0.0", "+", "$", "this", "->", "_width", ")", "/", "$", "this", "->", "_height", ")", "<=", "$", "diff", ";", "}" ]
Returns if the current size uses a near quadratic format. It means, if width and height difference is lower or equal to ?? percent. @param double $maxDifference If you want to change the allowed difference percent value you can do it here. Valid values here are 0.01 (means 1%) to 0.3 (means 30%) default is 0.15 @return boolean
[ "Returns", "if", "the", "current", "size", "uses", "a", "near", "quadratic", "format", ".", "It", "means", "if", "width", "and", "height", "difference", "is", "lower", "or", "equal", "to", "??", "percent", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L261-L285
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.reduceToMaxSize
public final function reduceToMaxSize( Size $maxSize ) : bool { $this->triggerFixedErrorByNeed( 'reduceToMaxSize' ); if ( ( $this->_width < $maxSize->_width ) && ( $this->_height < $maxSize->_height ) ) { return false; } if ( ( $this->_width === $maxSize->_width ) && ( $this->_height === $maxSize->_height ) ) { return true; } $dw = $this->_width / $maxSize->_width; $dh = $this->_height / $maxSize->_height; if ( $dw < $dh ) { $this->_width = \intval( \floor( ( $this->_width * $maxSize->_height ) / $this->_height ) ); $this->_height = $maxSize->_height; } else if ( $dw > $dh ) { $this->_height = \intval( \floor( ( $maxSize->_width * $this->_height ) / $this->_width ) ); $this->_width = $maxSize->_width; } else # ($dw == $dh) { $this->_width = $maxSize->_width; $this->_height = $maxSize->_height; } return true; }
php
public final function reduceToMaxSize( Size $maxSize ) : bool { $this->triggerFixedErrorByNeed( 'reduceToMaxSize' ); if ( ( $this->_width < $maxSize->_width ) && ( $this->_height < $maxSize->_height ) ) { return false; } if ( ( $this->_width === $maxSize->_width ) && ( $this->_height === $maxSize->_height ) ) { return true; } $dw = $this->_width / $maxSize->_width; $dh = $this->_height / $maxSize->_height; if ( $dw < $dh ) { $this->_width = \intval( \floor( ( $this->_width * $maxSize->_height ) / $this->_height ) ); $this->_height = $maxSize->_height; } else if ( $dw > $dh ) { $this->_height = \intval( \floor( ( $maxSize->_width * $this->_height ) / $this->_width ) ); $this->_width = $maxSize->_width; } else # ($dw == $dh) { $this->_width = $maxSize->_width; $this->_height = $maxSize->_height; } return true; }
[ "public", "final", "function", "reduceToMaxSize", "(", "Size", "$", "maxSize", ")", ":", "bool", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'reduceToMaxSize'", ")", ";", "if", "(", "(", "$", "this", "->", "_width", "<", "$", "maxSize", "->", "_width", ")", "&&", "(", "$", "this", "->", "_height", "<", "$", "maxSize", "->", "_height", ")", ")", "{", "return", "false", ";", "}", "if", "(", "(", "$", "this", "->", "_width", "===", "$", "maxSize", "->", "_width", ")", "&&", "(", "$", "this", "->", "_height", "===", "$", "maxSize", "->", "_height", ")", ")", "{", "return", "true", ";", "}", "$", "dw", "=", "$", "this", "->", "_width", "/", "$", "maxSize", "->", "_width", ";", "$", "dh", "=", "$", "this", "->", "_height", "/", "$", "maxSize", "->", "_height", ";", "if", "(", "$", "dw", "<", "$", "dh", ")", "{", "$", "this", "->", "_width", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "this", "->", "_width", "*", "$", "maxSize", "->", "_height", ")", "/", "$", "this", "->", "_height", ")", ")", ";", "$", "this", "->", "_height", "=", "$", "maxSize", "->", "_height", ";", "}", "else", "if", "(", "$", "dw", ">", "$", "dh", ")", "{", "$", "this", "->", "_height", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "maxSize", "->", "_width", "*", "$", "this", "->", "_height", ")", "/", "$", "this", "->", "_width", ")", ")", ";", "$", "this", "->", "_width", "=", "$", "maxSize", "->", "_width", ";", "}", "else", "# ($dw == $dh)", "{", "$", "this", "->", "_width", "=", "$", "maxSize", "->", "_width", ";", "$", "this", "->", "_height", "=", "$", "maxSize", "->", "_height", ";", "}", "return", "true", ";", "}" ]
Decrease the current size to fit the defined Size, by holding its proportions. @param \Beluga\Drawing\Size $maxSize @return bool TRUE on success, or FALSE, if current size is already smaller than defined size. @throws \Beluga\BelugaError If the instance is set to fixed.
[ "Decrease", "the", "current", "size", "to", "fit", "the", "defined", "Size", "by", "holding", "its", "proportions", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L347-L393
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.reduceMinSideTo
public final function reduceMinSideTo( int $newShortSideLength ) : bool { $this->triggerFixedErrorByNeed( 'reduceMinSideTo' ); if ( $this->isPortrait() ) { if ( $newShortSideLength >= $this->_width ) { return false; } $resultPercent = ( 100 * $newShortSideLength ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newShortSideLength; } else { if ( $newShortSideLength >= $this->_height ) { return false; } $resultPercent = ( 100 * $newShortSideLength ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newShortSideLength; } return true; }
php
public final function reduceMinSideTo( int $newShortSideLength ) : bool { $this->triggerFixedErrorByNeed( 'reduceMinSideTo' ); if ( $this->isPortrait() ) { if ( $newShortSideLength >= $this->_width ) { return false; } $resultPercent = ( 100 * $newShortSideLength ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newShortSideLength; } else { if ( $newShortSideLength >= $this->_height ) { return false; } $resultPercent = ( 100 * $newShortSideLength ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newShortSideLength; } return true; }
[ "public", "final", "function", "reduceMinSideTo", "(", "int", "$", "newShortSideLength", ")", ":", "bool", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'reduceMinSideTo'", ")", ";", "if", "(", "$", "this", "->", "isPortrait", "(", ")", ")", "{", "if", "(", "$", "newShortSideLength", ">=", "$", "this", "->", "_width", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newShortSideLength", ")", "/", "$", "this", "->", "_width", ";", "$", "this", "->", "_height", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_height", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_width", "=", "$", "newShortSideLength", ";", "}", "else", "{", "if", "(", "$", "newShortSideLength", ">=", "$", "this", "->", "_height", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newShortSideLength", ")", "/", "$", "this", "->", "_height", ";", "$", "this", "->", "_width", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_width", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_height", "=", "$", "newShortSideLength", ";", "}", "return", "true", ";", "}" ]
Decrease the shortest side to the defined length and also contracts the longer side to hold the proportion of this size. If the current size defines a quadratic size, it is also decreased but with searching the longer side. @param int $newShortSideLength @return bool TRUE on success, or FALSE if shortest side is already shorter or equal to $newShortSideLength. @throws \Beluga\BelugaError If the instance is set to fixed.
[ "Decrease", "the", "shortest", "side", "to", "the", "defined", "length", "and", "also", "contracts", "the", "longer", "side", "to", "hold", "the", "proportion", "of", "this", "size", ".", "If", "the", "current", "size", "defines", "a", "quadratic", "size", "it", "is", "also", "decreased", "but", "with", "searching", "the", "longer", "side", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L513-L557
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.reduceMinSideTo2
public final function reduceMinSideTo2( int $newLandscapeMaxHeight, int $newPortraitMaxWidth ) : bool { $this->triggerFixedErrorByNeed( 'reduceMinSideTo2' ); if ( $this->isPortrait() ) { if ( $newPortraitMaxWidth >= $this->_width ) { return false; } $resultPercent = ( 100 * $newPortraitMaxWidth ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newPortraitMaxWidth; } else { if ( $newLandscapeMaxHeight >= $this->_height ) { return false; } $resultPercent = ( 100 * $newLandscapeMaxHeight ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newLandscapeMaxHeight; } return true; }
php
public final function reduceMinSideTo2( int $newLandscapeMaxHeight, int $newPortraitMaxWidth ) : bool { $this->triggerFixedErrorByNeed( 'reduceMinSideTo2' ); if ( $this->isPortrait() ) { if ( $newPortraitMaxWidth >= $this->_width ) { return false; } $resultPercent = ( 100 * $newPortraitMaxWidth ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newPortraitMaxWidth; } else { if ( $newLandscapeMaxHeight >= $this->_height ) { return false; } $resultPercent = ( 100 * $newLandscapeMaxHeight ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newLandscapeMaxHeight; } return true; }
[ "public", "final", "function", "reduceMinSideTo2", "(", "int", "$", "newLandscapeMaxHeight", ",", "int", "$", "newPortraitMaxWidth", ")", ":", "bool", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'reduceMinSideTo2'", ")", ";", "if", "(", "$", "this", "->", "isPortrait", "(", ")", ")", "{", "if", "(", "$", "newPortraitMaxWidth", ">=", "$", "this", "->", "_width", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newPortraitMaxWidth", ")", "/", "$", "this", "->", "_width", ";", "$", "this", "->", "_height", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_height", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_width", "=", "$", "newPortraitMaxWidth", ";", "}", "else", "{", "if", "(", "$", "newLandscapeMaxHeight", ">=", "$", "this", "->", "_height", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newLandscapeMaxHeight", ")", "/", "$", "this", "->", "_height", ";", "$", "this", "->", "_width", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_width", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_height", "=", "$", "newLandscapeMaxHeight", ";", "}", "return", "true", ";", "}" ]
Decrease the shortest side to the defined length and also contracts the longer side to hold the proportion of this size. The value, used as max side length is depending to the current size format. $newLandscapeMaxHeight is used if the current size uses a landscape ord quadratic format. Otherwise the $newPortraitMaxWidth is used. @param int $newLandscapeMaxHeight The max height, used if size has landscape or quadratic format. @param int $newPortraitMaxWidth The max width, used if size has portrait format. @return bool @throws \Beluga\BelugaError If the instance is set to fixed.
[ "Decrease", "the", "shortest", "side", "to", "the", "defined", "length", "and", "also", "contracts", "the", "longer", "side", "to", "hold", "the", "proportion", "of", "this", "size", ".", "The", "value", "used", "as", "max", "side", "length", "is", "depending", "to", "the", "current", "size", "format", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L571-L611
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.expandMaxSideTo
public final function expandMaxSideTo( int $newMaxSideLength ) : bool { $this->triggerFixedErrorByNeed( 'expandMaxSideTo' ); if ( $this->isPortrait() ) { if ( $newMaxSideLength < $this->_height ) { return false; } $resultPercent = ( 100 * $newMaxSideLength ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newMaxSideLength; } else { if ( $newMaxSideLength < $this->_width ) { return false; } $resultPercent = ( 100 * $newMaxSideLength ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newMaxSideLength; } return true; }
php
public final function expandMaxSideTo( int $newMaxSideLength ) : bool { $this->triggerFixedErrorByNeed( 'expandMaxSideTo' ); if ( $this->isPortrait() ) { if ( $newMaxSideLength < $this->_height ) { return false; } $resultPercent = ( 100 * $newMaxSideLength ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newMaxSideLength; } else { if ( $newMaxSideLength < $this->_width ) { return false; } $resultPercent = ( 100 * $newMaxSideLength ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newMaxSideLength; } return true; }
[ "public", "final", "function", "expandMaxSideTo", "(", "int", "$", "newMaxSideLength", ")", ":", "bool", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'expandMaxSideTo'", ")", ";", "if", "(", "$", "this", "->", "isPortrait", "(", ")", ")", "{", "if", "(", "$", "newMaxSideLength", "<", "$", "this", "->", "_height", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newMaxSideLength", ")", "/", "$", "this", "->", "_height", ";", "$", "this", "->", "_width", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_width", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_height", "=", "$", "newMaxSideLength", ";", "}", "else", "{", "if", "(", "$", "newMaxSideLength", "<", "$", "this", "->", "_width", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newMaxSideLength", ")", "/", "$", "this", "->", "_width", ";", "$", "this", "->", "_height", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_height", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_width", "=", "$", "newMaxSideLength", ";", "}", "return", "true", ";", "}" ]
Expands the longest side to the defined length and also expands the shorter side to hold the proportion of this size. If the current size defines a quadratic size, its also expanded but without searching the longer side. @param integer $newMaxSideLength @return boolean TRUE on success, or FALSE if longest side is already longer than $newMaxSideLength. @throws \Beluga\BelugaError If the instance is set to fixed.
[ "Expands", "the", "longest", "side", "to", "the", "defined", "length", "and", "also", "expands", "the", "shorter", "side", "to", "hold", "the", "proportion", "of", "this", "size", ".", "If", "the", "current", "size", "defines", "a", "quadratic", "size", "its", "also", "expanded", "but", "without", "searching", "the", "longer", "side", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L646-L686
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.expandMaxSideTo2
public final function expandMaxSideTo2( int $newLandscapeMaxWidth, int $newPortraitMaxHeight ) : bool { $this->triggerFixedErrorByNeed( 'expandMaxSideTo2' ); if ( $this->isPortrait() ) { if ( $newPortraitMaxHeight <= $this->_height ) { return false; } $resultPercent = ( 100 * $newPortraitMaxHeight ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newPortraitMaxHeight; } else { if ( $newLandscapeMaxWidth <= $this->_width ) { return false; } $resultPercent = ( 100 * $newLandscapeMaxWidth ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newLandscapeMaxWidth; } return true; }
php
public final function expandMaxSideTo2( int $newLandscapeMaxWidth, int $newPortraitMaxHeight ) : bool { $this->triggerFixedErrorByNeed( 'expandMaxSideTo2' ); if ( $this->isPortrait() ) { if ( $newPortraitMaxHeight <= $this->_height ) { return false; } $resultPercent = ( 100 * $newPortraitMaxHeight ) / $this->_height; $this->_width = \intval( \floor( ( $resultPercent * $this->_width ) / 100 ) ); $this->_height = $newPortraitMaxHeight; } else { if ( $newLandscapeMaxWidth <= $this->_width ) { return false; } $resultPercent = ( 100 * $newLandscapeMaxWidth ) / $this->_width; $this->_height = \intval( \floor( ( $resultPercent * $this->_height ) / 100 ) ); $this->_width = $newLandscapeMaxWidth; } return true; }
[ "public", "final", "function", "expandMaxSideTo2", "(", "int", "$", "newLandscapeMaxWidth", ",", "int", "$", "newPortraitMaxHeight", ")", ":", "bool", "{", "$", "this", "->", "triggerFixedErrorByNeed", "(", "'expandMaxSideTo2'", ")", ";", "if", "(", "$", "this", "->", "isPortrait", "(", ")", ")", "{", "if", "(", "$", "newPortraitMaxHeight", "<=", "$", "this", "->", "_height", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newPortraitMaxHeight", ")", "/", "$", "this", "->", "_height", ";", "$", "this", "->", "_width", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_width", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_height", "=", "$", "newPortraitMaxHeight", ";", "}", "else", "{", "if", "(", "$", "newLandscapeMaxWidth", "<=", "$", "this", "->", "_width", ")", "{", "return", "false", ";", "}", "$", "resultPercent", "=", "(", "100", "*", "$", "newLandscapeMaxWidth", ")", "/", "$", "this", "->", "_width", ";", "$", "this", "->", "_height", "=", "\\", "intval", "(", "\\", "floor", "(", "(", "$", "resultPercent", "*", "$", "this", "->", "_height", ")", "/", "100", ")", ")", ";", "$", "this", "->", "_width", "=", "$", "newLandscapeMaxWidth", ";", "}", "return", "true", ";", "}" ]
Expands the longest side to the defined length and also expands the shorter side to hold the proportion of this size. The value, used as max side length is depending to the current size format. $newLandscapeMaxWidth is used if the current size uses a landscape ord quadratic format. Otherwise the $newPortraitMaxHeight is used. @param int $newLandscapeMaxWidth The max width, used if size has landscape or quadratic format. @param int $newPortraitMaxHeight The max height, used if size has portrait format. @return bool @throws \Beluga\BelugaError If the instance is set to fixed.
[ "Expands", "the", "longest", "side", "to", "the", "defined", "length", "and", "also", "expands", "the", "shorter", "side", "to", "hold", "the", "proportion", "of", "this", "size", ".", "The", "value", "used", "as", "max", "side", "length", "is", "depending", "to", "the", "current", "size", "format", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L700-L740
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.resizeMaxSideTo2
public final function resizeMaxSideTo2( int $newLandscapeWidth, int $newPortraitHeight ) : bool { if ( $this->isPortrait() ) { // Portrait format if ( $newPortraitHeight == $this->_height ) { // No resizing required return false; } if ( $newPortraitHeight < $this->_height ) { // Decrease the current size return $this->reduceMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); } // Expand the current size return $this->expandMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); } // Landscape format if ( $newLandscapeWidth == $this->_width ) { // No resizing required return false; } if ( $newPortraitHeight < $this->_width ) { // Decrease the current size return $this->reduceMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); } // Expand the current size return $this->expandMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); }
php
public final function resizeMaxSideTo2( int $newLandscapeWidth, int $newPortraitHeight ) : bool { if ( $this->isPortrait() ) { // Portrait format if ( $newPortraitHeight == $this->_height ) { // No resizing required return false; } if ( $newPortraitHeight < $this->_height ) { // Decrease the current size return $this->reduceMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); } // Expand the current size return $this->expandMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); } // Landscape format if ( $newLandscapeWidth == $this->_width ) { // No resizing required return false; } if ( $newPortraitHeight < $this->_width ) { // Decrease the current size return $this->reduceMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); } // Expand the current size return $this->expandMaxSideTo2( $newLandscapeWidth, $newPortraitHeight ); }
[ "public", "final", "function", "resizeMaxSideTo2", "(", "int", "$", "newLandscapeWidth", ",", "int", "$", "newPortraitHeight", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "isPortrait", "(", ")", ")", "{", "// Portrait format", "if", "(", "$", "newPortraitHeight", "==", "$", "this", "->", "_height", ")", "{", "// No resizing required", "return", "false", ";", "}", "if", "(", "$", "newPortraitHeight", "<", "$", "this", "->", "_height", ")", "{", "// Decrease the current size", "return", "$", "this", "->", "reduceMaxSideTo2", "(", "$", "newLandscapeWidth", ",", "$", "newPortraitHeight", ")", ";", "}", "// Expand the current size", "return", "$", "this", "->", "expandMaxSideTo2", "(", "$", "newLandscapeWidth", ",", "$", "newPortraitHeight", ")", ";", "}", "// Landscape format", "if", "(", "$", "newLandscapeWidth", "==", "$", "this", "->", "_width", ")", "{", "// No resizing required", "return", "false", ";", "}", "if", "(", "$", "newPortraitHeight", "<", "$", "this", "->", "_width", ")", "{", "// Decrease the current size", "return", "$", "this", "->", "reduceMaxSideTo2", "(", "$", "newLandscapeWidth", ",", "$", "newPortraitHeight", ")", ";", "}", "// Expand the current size", "return", "$", "this", "->", "expandMaxSideTo2", "(", "$", "newLandscapeWidth", ",", "$", "newPortraitHeight", ")", ";", "}" ]
Resize the longest side to the defined length and also resize the shorter side to hold the proportion of this size. The value, used as max side length is depending to the current size format. $newLandscapeWidth is used if the current size uses a landscape ord quadratic format. Otherwise the $newPortraitHeight is used. @param int $newLandscapeWidth Max. width for landscape format or quadratic format. @param int $newPortraitHeight Max. height for portrait format. @return bool @throws \Beluga\BelugaError If the instance is set to fixed.
[ "Resize", "the", "longest", "side", "to", "the", "defined", "length", "and", "also", "resize", "the", "shorter", "side", "to", "hold", "the", "proportion", "of", "this", "size", ".", "The", "value", "used", "as", "max", "side", "length", "is", "depending", "to", "the", "current", "size", "format", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L819-L861
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.TryParse
public static function TryParse( $value, &$size, bool $fixed = false ) : bool { $size = null; if ( \is_int( $value ) ) { // An single integer value will result in an quadratic size $size = new Size( $value, $value, $fixed ); return true; } if ( \is_double( $value ) ) { // Double|Float in converted to integer $size = new Size( (int) $value, (int) $value, $fixed ); return true; } if ( \is_array( $value ) ) { // Array get parsed by FromArray return ( false !== ( $size = self::FromArray( $value, $fixed ) ) ); } if ( \is_string( $value ) ) { // String get parsed by FromString return ( false !== ( $size = self::FromString( $value, $fixed ) ) ); } if ( \is_resource( $value ) && \get_resource_type( $value ) === 'gd' ) { try { $size = new Size( \imagesx( $value ), \imagesy( $value ), $fixed ); return true; } catch ( \Throwable $ex ) { $ex = null; return false; } } return false; }
php
public static function TryParse( $value, &$size, bool $fixed = false ) : bool { $size = null; if ( \is_int( $value ) ) { // An single integer value will result in an quadratic size $size = new Size( $value, $value, $fixed ); return true; } if ( \is_double( $value ) ) { // Double|Float in converted to integer $size = new Size( (int) $value, (int) $value, $fixed ); return true; } if ( \is_array( $value ) ) { // Array get parsed by FromArray return ( false !== ( $size = self::FromArray( $value, $fixed ) ) ); } if ( \is_string( $value ) ) { // String get parsed by FromString return ( false !== ( $size = self::FromString( $value, $fixed ) ) ); } if ( \is_resource( $value ) && \get_resource_type( $value ) === 'gd' ) { try { $size = new Size( \imagesx( $value ), \imagesy( $value ), $fixed ); return true; } catch ( \Throwable $ex ) { $ex = null; return false; } } return false; }
[ "public", "static", "function", "TryParse", "(", "$", "value", ",", "&", "$", "size", ",", "bool", "$", "fixed", "=", "false", ")", ":", "bool", "{", "$", "size", "=", "null", ";", "if", "(", "\\", "is_int", "(", "$", "value", ")", ")", "{", "// An single integer value will result in an quadratic size", "$", "size", "=", "new", "Size", "(", "$", "value", ",", "$", "value", ",", "$", "fixed", ")", ";", "return", "true", ";", "}", "if", "(", "\\", "is_double", "(", "$", "value", ")", ")", "{", "// Double|Float in converted to integer", "$", "size", "=", "new", "Size", "(", "(", "int", ")", "$", "value", ",", "(", "int", ")", "$", "value", ",", "$", "fixed", ")", ";", "return", "true", ";", "}", "if", "(", "\\", "is_array", "(", "$", "value", ")", ")", "{", "// Array get parsed by FromArray", "return", "(", "false", "!==", "(", "$", "size", "=", "self", "::", "FromArray", "(", "$", "value", ",", "$", "fixed", ")", ")", ")", ";", "}", "if", "(", "\\", "is_string", "(", "$", "value", ")", ")", "{", "// String get parsed by FromString", "return", "(", "false", "!==", "(", "$", "size", "=", "self", "::", "FromString", "(", "$", "value", ",", "$", "fixed", ")", ")", ")", ";", "}", "if", "(", "\\", "is_resource", "(", "$", "value", ")", "&&", "\\", "get_resource_type", "(", "$", "value", ")", "===", "'gd'", ")", "{", "try", "{", "$", "size", "=", "new", "Size", "(", "\\", "imagesx", "(", "$", "value", ")", ",", "\\", "imagesy", "(", "$", "value", ")", ",", "$", "fixed", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "Throwable", "$", "ex", ")", "{", "$", "ex", "=", "null", ";", "return", "false", ";", "}", "}", "return", "false", ";", "}" ]
Tries to parse the the defined values as a size and returns the success state. If parsing was successful (TRUE is returned) the resulting Beluga\Drawing\Size is returned by the $size parameter. @param mixed $value int|double|array|string|image-resource @param \Beluga\Drawing\Size $size The resulting {@see \Beluga\Drawing\Size} instance. @param bool $fixed Is this instance fixed? (fixed is the read-only mode). @return boolean
[ "Tries", "to", "parse", "the", "the", "defined", "values", "as", "a", "size", "and", "returns", "the", "success", "state", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L1065-L1112
train
SagittariusX/Beluga.Drawing
src/Beluga/Drawing/Size.php
Size.Empty
public static function Empty( bool $fixed = false ) : Size { if ( $fixed ) { return \is_null( static::$emptyFixed ) ? ( static::$emptyFixed = new Size( 0, 0, true ) ) : static::$emptyFixed; } return new Size( 0, 0, $fixed ); }
php
public static function Empty( bool $fixed = false ) : Size { if ( $fixed ) { return \is_null( static::$emptyFixed ) ? ( static::$emptyFixed = new Size( 0, 0, true ) ) : static::$emptyFixed; } return new Size( 0, 0, $fixed ); }
[ "public", "static", "function", "Empty", "(", "bool", "$", "fixed", "=", "false", ")", ":", "Size", "{", "if", "(", "$", "fixed", ")", "{", "return", "\\", "is_null", "(", "static", "::", "$", "emptyFixed", ")", "?", "(", "static", "::", "$", "emptyFixed", "=", "new", "Size", "(", "0", ",", "0", ",", "true", ")", ")", ":", "static", "::", "$", "emptyFixed", ";", "}", "return", "new", "Size", "(", "0", ",", "0", ",", "$", "fixed", ")", ";", "}" ]
Gets a empty Size instance. @param bool $fixed Is this instance fixed? (fixed is the read-only mode). @return \Beluga\Drawing\Size
[ "Gets", "a", "empty", "Size", "instance", "." ]
9c82874cf4ec68cb0af78757b65f19783540004a
https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Size.php#L1168-L1180
train
togucms/ApplicationModelsBundle
Document/BasePage.php
BasePage.getAllSections
public function getAllSections() { $sections = array(); $section = $this->section; do { $sections[] = $section; } while($section = $section->getSectionConfig()->getParentSection()); return array_reverse($sections); }
php
public function getAllSections() { $sections = array(); $section = $this->section; do { $sections[] = $section; } while($section = $section->getSectionConfig()->getParentSection()); return array_reverse($sections); }
[ "public", "function", "getAllSections", "(", ")", "{", "$", "sections", "=", "array", "(", ")", ";", "$", "section", "=", "$", "this", "->", "section", ";", "do", "{", "$", "sections", "[", "]", "=", "$", "section", ";", "}", "while", "(", "$", "section", "=", "$", "section", "->", "getSectionConfig", "(", ")", "->", "getParentSection", "(", ")", ")", ";", "return", "array_reverse", "(", "$", "sections", ")", ";", "}" ]
Recursively gets all the sections @return array
[ "Recursively", "gets", "all", "the", "sections" ]
125ab47e0327d17afdedb8db074c9d7e211e6417
https://github.com/togucms/ApplicationModelsBundle/blob/125ab47e0327d17afdedb8db074c9d7e211e6417/Document/BasePage.php#L118-L126
train
RudyMas/xml_json
src/XML_JSON/XML_JSON.php
XML_JSON.xml2array
public function xml2array(): void { $this->xml2json(); $this->arrayData = json_decode($this->jsonData, TRUE); }
php
public function xml2array(): void { $this->xml2json(); $this->arrayData = json_decode($this->jsonData, TRUE); }
[ "public", "function", "xml2array", "(", ")", ":", "void", "{", "$", "this", "->", "xml2json", "(", ")", ";", "$", "this", "->", "arrayData", "=", "json_decode", "(", "$", "this", "->", "jsonData", ",", "TRUE", ")", ";", "}" ]
Convert XML to Array
[ "Convert", "XML", "to", "Array" ]
b27edf82f838e587caa0a93a46402dd0e45b5372
https://github.com/RudyMas/xml_json/blob/b27edf82f838e587caa0a93a46402dd0e45b5372/src/XML_JSON/XML_JSON.php#L74-L78
train
RudyMas/xml_json
src/XML_JSON/XML_JSON.php
XML_JSON.array2xml
public function array2xml(string $xmlField = '', ?string $dataField = null): void { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><' . $xmlField . '/>'); $this->createXml($xml, $this->arrayData, $dataField); $this->xmlData = $xml->asXML(); }
php
public function array2xml(string $xmlField = '', ?string $dataField = null): void { $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><' . $xmlField . '/>'); $this->createXml($xml, $this->arrayData, $dataField); $this->xmlData = $xml->asXML(); }
[ "public", "function", "array2xml", "(", "string", "$", "xmlField", "=", "''", ",", "?", "string", "$", "dataField", "=", "null", ")", ":", "void", "{", "$", "xml", "=", "new", "SimpleXMLElement", "(", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?><'", ".", "$", "xmlField", ".", "'/>'", ")", ";", "$", "this", "->", "createXml", "(", "$", "xml", ",", "$", "this", "->", "arrayData", ",", "$", "dataField", ")", ";", "$", "this", "->", "xmlData", "=", "$", "xml", "->", "asXML", "(", ")", ";", "}" ]
Convert Array to XML @param string $xmlField The opening tag for the XML file @param string|null $dataField
[ "Convert", "Array", "to", "XML" ]
b27edf82f838e587caa0a93a46402dd0e45b5372
https://github.com/RudyMas/xml_json/blob/b27edf82f838e587caa0a93a46402dd0e45b5372/src/XML_JSON/XML_JSON.php#L86-L91
train
RudyMas/xml_json
src/XML_JSON/XML_JSON.php
XML_JSON.createXml
private function createXml(SimpleXMLElement $obj, array $array, ?string $prevKey = 'data'): void { foreach ($array as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { $node = $obj->addChild($prevKey); $this->createXml($node, $value); } elseif ($key == '@attributes') { foreach ($value as $k => $v) { $obj->addAttribute($k, $v); } } else { if ($prevKey != '' && !is_numeric($key)) $node = $obj->addChild($prevKey); else $node = $obj; $this->createXml($node, $value, $key); } } else { if (is_numeric($key)) { $obj->addChild($prevKey, $value); } else { $obj->addChild($key, $value); } } } }
php
private function createXml(SimpleXMLElement $obj, array $array, ?string $prevKey = 'data'): void { foreach ($array as $key => $value) { if (is_array($value)) { if (is_numeric($key)) { $node = $obj->addChild($prevKey); $this->createXml($node, $value); } elseif ($key == '@attributes') { foreach ($value as $k => $v) { $obj->addAttribute($k, $v); } } else { if ($prevKey != '' && !is_numeric($key)) $node = $obj->addChild($prevKey); else $node = $obj; $this->createXml($node, $value, $key); } } else { if (is_numeric($key)) { $obj->addChild($prevKey, $value); } else { $obj->addChild($key, $value); } } } }
[ "private", "function", "createXml", "(", "SimpleXMLElement", "$", "obj", ",", "array", "$", "array", ",", "?", "string", "$", "prevKey", "=", "'data'", ")", ":", "void", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "node", "=", "$", "obj", "->", "addChild", "(", "$", "prevKey", ")", ";", "$", "this", "->", "createXml", "(", "$", "node", ",", "$", "value", ")", ";", "}", "elseif", "(", "$", "key", "==", "'@attributes'", ")", "{", "foreach", "(", "$", "value", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "obj", "->", "addAttribute", "(", "$", "k", ",", "$", "v", ")", ";", "}", "}", "else", "{", "if", "(", "$", "prevKey", "!=", "''", "&&", "!", "is_numeric", "(", "$", "key", ")", ")", "$", "node", "=", "$", "obj", "->", "addChild", "(", "$", "prevKey", ")", ";", "else", "$", "node", "=", "$", "obj", ";", "$", "this", "->", "createXml", "(", "$", "node", ",", "$", "value", ",", "$", "key", ")", ";", "}", "}", "else", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "obj", "->", "addChild", "(", "$", "prevKey", ",", "$", "value", ")", ";", "}", "else", "{", "$", "obj", "->", "addChild", "(", "$", "key", ",", "$", "value", ")", ";", "}", "}", "}", "}" ]
Private method to create XML output @param SimpleXMLElement $obj @param array $array @param null|string $prevKey
[ "Private", "method", "to", "create", "XML", "output" ]
b27edf82f838e587caa0a93a46402dd0e45b5372
https://github.com/RudyMas/xml_json/blob/b27edf82f838e587caa0a93a46402dd0e45b5372/src/XML_JSON/XML_JSON.php#L100-L123
train
RudyMas/xml_json
src/XML_JSON/XML_JSON.php
XML_JSON.xml2json
public function xml2json(): void { $xml = simplexml_load_string($this->xmlData, NULL, LIBXML_NOCDATA); $this->jsonData = json_encode($xml); }
php
public function xml2json(): void { $xml = simplexml_load_string($this->xmlData, NULL, LIBXML_NOCDATA); $this->jsonData = json_encode($xml); }
[ "public", "function", "xml2json", "(", ")", ":", "void", "{", "$", "xml", "=", "simplexml_load_string", "(", "$", "this", "->", "xmlData", ",", "NULL", ",", "LIBXML_NOCDATA", ")", ";", "$", "this", "->", "jsonData", "=", "json_encode", "(", "$", "xml", ")", ";", "}" ]
Convert XML to JSON
[ "Convert", "XML", "to", "JSON" ]
b27edf82f838e587caa0a93a46402dd0e45b5372
https://github.com/RudyMas/xml_json/blob/b27edf82f838e587caa0a93a46402dd0e45b5372/src/XML_JSON/XML_JSON.php#L144-L148
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.indexAction
public function indexAction() { $em = $this->getDoctrineManager(); $entities = $em->getRepository('BisonLabSakonninBundle:MessageType')->findAll(); $parents = $em->createQueryBuilder() ->select('mt') ->from('BisonLab\SakonninBundle\Entity\MessageType', 'mt') ->where('mt.parent is null') ->orderBy('mt.name', 'ASC') ->getQuery() ->getResult(); $entities = array(); foreach ($parents as $p) { $entities[] = $p; if ($p->getChildren()->count() > 0) $entities = array_merge($entities, (array)$p->getChildren()->toArray()); } return $this->render( 'BisonLabSakonninBundle:MessageType:index.html.twig', array('entities' => $entities)); }
php
public function indexAction() { $em = $this->getDoctrineManager(); $entities = $em->getRepository('BisonLabSakonninBundle:MessageType')->findAll(); $parents = $em->createQueryBuilder() ->select('mt') ->from('BisonLab\SakonninBundle\Entity\MessageType', 'mt') ->where('mt.parent is null') ->orderBy('mt.name', 'ASC') ->getQuery() ->getResult(); $entities = array(); foreach ($parents as $p) { $entities[] = $p; if ($p->getChildren()->count() > 0) $entities = array_merge($entities, (array)$p->getChildren()->toArray()); } return $this->render( 'BisonLabSakonninBundle:MessageType:index.html.twig', array('entities' => $entities)); }
[ "public", "function", "indexAction", "(", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrineManager", "(", ")", ";", "$", "entities", "=", "$", "em", "->", "getRepository", "(", "'BisonLabSakonninBundle:MessageType'", ")", "->", "findAll", "(", ")", ";", "$", "parents", "=", "$", "em", "->", "createQueryBuilder", "(", ")", "->", "select", "(", "'mt'", ")", "->", "from", "(", "'BisonLab\\SakonninBundle\\Entity\\MessageType'", ",", "'mt'", ")", "->", "where", "(", "'mt.parent is null'", ")", "->", "orderBy", "(", "'mt.name'", ",", "'ASC'", ")", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "$", "entities", "=", "array", "(", ")", ";", "foreach", "(", "$", "parents", "as", "$", "p", ")", "{", "$", "entities", "[", "]", "=", "$", "p", ";", "if", "(", "$", "p", "->", "getChildren", "(", ")", "->", "count", "(", ")", ">", "0", ")", "$", "entities", "=", "array_merge", "(", "$", "entities", ",", "(", "array", ")", "$", "p", "->", "getChildren", "(", ")", "->", "toArray", "(", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'BisonLabSakonninBundle:MessageType:index.html.twig'", ",", "array", "(", "'entities'", "=>", "$", "entities", ")", ")", ";", "}" ]
Lists all MessageType entities. @Route("/", name="messagetype", methods={"GET"})
[ "Lists", "all", "MessageType", "entities", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L32-L54
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.createAction
public function createAction(Request $request) { $entity = new MessageType(); $form = $this->createCreateForm($entity); $form->handleRequest($request); $data = $form->getData(); if (!$data->getParent() && !isset($request->request->get($form->getName())['create_group'])) { throw new \InvalidArgumentException('You must either check "This is a new group" to verify that you want a new group or choose a group in the drop down.'); } if ($form->isValid()) { $em = $this->getDoctrineManager(); $em->persist($entity); $em->flush(); return $this->redirectToRoute('messagetype_show', array('id' => $entity->getId())); } return $this->render( 'BisonLabSakonninBundle:MessageType:edit.html.twig', array( 'entity' => $entity, 'form' => $form->createView(), )); }
php
public function createAction(Request $request) { $entity = new MessageType(); $form = $this->createCreateForm($entity); $form->handleRequest($request); $data = $form->getData(); if (!$data->getParent() && !isset($request->request->get($form->getName())['create_group'])) { throw new \InvalidArgumentException('You must either check "This is a new group" to verify that you want a new group or choose a group in the drop down.'); } if ($form->isValid()) { $em = $this->getDoctrineManager(); $em->persist($entity); $em->flush(); return $this->redirectToRoute('messagetype_show', array('id' => $entity->getId())); } return $this->render( 'BisonLabSakonninBundle:MessageType:edit.html.twig', array( 'entity' => $entity, 'form' => $form->createView(), )); }
[ "public", "function", "createAction", "(", "Request", "$", "request", ")", "{", "$", "entity", "=", "new", "MessageType", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateForm", "(", "$", "entity", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "$", "data", "=", "$", "form", "->", "getData", "(", ")", ";", "if", "(", "!", "$", "data", "->", "getParent", "(", ")", "&&", "!", "isset", "(", "$", "request", "->", "request", "->", "get", "(", "$", "form", "->", "getName", "(", ")", ")", "[", "'create_group'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'You must either check \"This is a new group\" to verify that you want a new group or choose a group in the drop down.'", ")", ";", "}", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrineManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "entity", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirectToRoute", "(", "'messagetype_show'", ",", "array", "(", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'BisonLabSakonninBundle:MessageType:edit.html.twig'", ",", "array", "(", "'entity'", "=>", "$", "entity", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Creates a new MessageType entity. @Route("/", name="messagetype_create", methods={"POST"})
[ "Creates", "a", "new", "MessageType", "entity", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L61-L83
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.createCreateForm
private function createCreateForm(MessageType $entity) { $form = $this->createForm(MessageTypeType::class, $entity, array( 'action' => $this->generateUrl('messagetype_create'), 'method' => 'POST', )); $this->_addFunctionsToForm($form); $form->add('create_group', CheckboxType::class, array('label' => "This is a new group.", 'mapped' => false, 'required' => false)); $form->add('submit', SubmitType::class, array('label' => 'Create')); return $form; }
php
private function createCreateForm(MessageType $entity) { $form = $this->createForm(MessageTypeType::class, $entity, array( 'action' => $this->generateUrl('messagetype_create'), 'method' => 'POST', )); $this->_addFunctionsToForm($form); $form->add('create_group', CheckboxType::class, array('label' => "This is a new group.", 'mapped' => false, 'required' => false)); $form->add('submit', SubmitType::class, array('label' => 'Create')); return $form; }
[ "private", "function", "createCreateForm", "(", "MessageType", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "MessageTypeType", "::", "class", ",", "$", "entity", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'messagetype_create'", ")", ",", "'method'", "=>", "'POST'", ",", ")", ")", ";", "$", "this", "->", "_addFunctionsToForm", "(", "$", "form", ")", ";", "$", "form", "->", "add", "(", "'create_group'", ",", "CheckboxType", "::", "class", ",", "array", "(", "'label'", "=>", "\"This is a new group.\"", ",", "'mapped'", "=>", "false", ",", "'required'", "=>", "false", ")", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "SubmitType", "::", "class", ",", "array", "(", "'label'", "=>", "'Create'", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to create a MessageType entity. @param MessageType $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "create", "a", "MessageType", "entity", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L92-L104
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.newAction
public function newAction() { $entity = new MessageType(); $form = $this->createCreateForm($entity); return $this->render( 'BisonLabSakonninBundle:MessageType:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $form->createView(), )); }
php
public function newAction() { $entity = new MessageType(); $form = $this->createCreateForm($entity); return $this->render( 'BisonLabSakonninBundle:MessageType:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $form->createView(), )); }
[ "public", "function", "newAction", "(", ")", "{", "$", "entity", "=", "new", "MessageType", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateForm", "(", "$", "entity", ")", ";", "return", "$", "this", "->", "render", "(", "'BisonLabSakonninBundle:MessageType:edit.html.twig'", ",", "array", "(", "'entity'", "=>", "$", "entity", ",", "'edit_form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Displays a form to create a new MessageType entity. @Route("/new", name="messagetype_new", methods={"GET"})
[ "Displays", "a", "form", "to", "create", "a", "new", "MessageType", "entity", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L111-L121
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.createEditForm
private function createEditForm(MessageType $entity) { $form = $this->createForm(MessageTypeType::class, $entity, array( 'action' => $this->generateUrl('messagetype_update', array('id' => $entity->getId())), 'method' => 'PUT', )); $this->_addFunctionsToForm($form); $form->add('submit', SubmitType::class, array('label' => 'Update')); return $form; }
php
private function createEditForm(MessageType $entity) { $form = $this->createForm(MessageTypeType::class, $entity, array( 'action' => $this->generateUrl('messagetype_update', array('id' => $entity->getId())), 'method' => 'PUT', )); $this->_addFunctionsToForm($form); $form->add('submit', SubmitType::class, array('label' => 'Update')); return $form; }
[ "private", "function", "createEditForm", "(", "MessageType", "$", "entity", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "MessageTypeType", "::", "class", ",", "$", "entity", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'messagetype_update'", ",", "array", "(", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", ")", ")", ",", "'method'", "=>", "'PUT'", ",", ")", ")", ";", "$", "this", "->", "_addFunctionsToForm", "(", "$", "form", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "SubmitType", "::", "class", ",", "array", "(", "'label'", "=>", "'Update'", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to edit a MessageType entity. @param MessageType $entity The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "edit", "a", "MessageType", "entity", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L179-L189
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.updateAction
public function updateAction(Request $request, $id) { $em = $this->getDoctrineManager(); $entity = $em->getRepository('BisonLabSakonninBundle:MessageType')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find MessageType entity.'); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); if ($editForm->isValid()) { $em->flush(); return $this->redirectToRoute('messagetype_show', array('id' => $entity->getId())); } return $this->render( 'BisonLabSakonninBundle:MessageType:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); }
php
public function updateAction(Request $request, $id) { $em = $this->getDoctrineManager(); $entity = $em->getRepository('BisonLabSakonninBundle:MessageType')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find MessageType entity.'); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($entity); $editForm->handleRequest($request); if ($editForm->isValid()) { $em->flush(); return $this->redirectToRoute('messagetype_show', array('id' => $entity->getId())); } return $this->render( 'BisonLabSakonninBundle:MessageType:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); }
[ "public", "function", "updateAction", "(", "Request", "$", "request", ",", "$", "id", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrineManager", "(", ")", ";", "$", "entity", "=", "$", "em", "->", "getRepository", "(", "'BisonLabSakonninBundle:MessageType'", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "entity", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Unable to find MessageType entity.'", ")", ";", "}", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "id", ")", ";", "$", "editForm", "=", "$", "this", "->", "createEditForm", "(", "$", "entity", ")", ";", "$", "editForm", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "editForm", "->", "isValid", "(", ")", ")", "{", "$", "em", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirectToRoute", "(", "'messagetype_show'", ",", "array", "(", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'BisonLabSakonninBundle:MessageType:edit.html.twig'", ",", "array", "(", "'entity'", "=>", "$", "entity", ",", "'edit_form'", "=>", "$", "editForm", "->", "createView", "(", ")", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Edits an existing MessageType entity. @Route("/{id}", name="messagetype_update", methods={"PUT"})
[ "Edits", "an", "existing", "MessageType", "entity", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L196-L220
train
thomasez/BisonLabSakonninBundle
Controller/MessageTypeController.php
MessageTypeController.deleteAction
public function deleteAction(Request $request, $id) { $form = $this->createDeleteForm($id); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrineManager(); $entity = $em->getRepository('BisonLabSakonninBundle:MessageType')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find MessageType entity.'); } $em->remove($entity); $em->flush(); } return $this->redirectToRoute('messagetype'); }
php
public function deleteAction(Request $request, $id) { $form = $this->createDeleteForm($id); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrineManager(); $entity = $em->getRepository('BisonLabSakonninBundle:MessageType')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find MessageType entity.'); } $em->remove($entity); $em->flush(); } return $this->redirectToRoute('messagetype'); }
[ "public", "function", "deleteAction", "(", "Request", "$", "request", ",", "$", "id", ")", "{", "$", "form", "=", "$", "this", "->", "createDeleteForm", "(", "$", "id", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrineManager", "(", ")", ";", "$", "entity", "=", "$", "em", "->", "getRepository", "(", "'BisonLabSakonninBundle:MessageType'", ")", "->", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "entity", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Unable to find MessageType entity.'", ")", ";", "}", "$", "em", "->", "remove", "(", "$", "entity", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "}", "return", "$", "this", "->", "redirectToRoute", "(", "'messagetype'", ")", ";", "}" ]
Deletes a MessageType entity. @Route("/{id}", name="messagetype_delete", methods={"DELETE"})
[ "Deletes", "a", "MessageType", "entity", "." ]
45ca7ce9874c4a2be7b503d7067b3d11d2b518cb
https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/MessageTypeController.php#L227-L244
train
mossphp/moss-storage
Moss/Storage/Query/EventDispatcher/EventDispatcher.php
EventDispatcher.register
public function register($event, callable $listener, $priority = null) { foreach ((array) $event as $e) { $this->registerListener($e, $listener, $priority); } return $this; }
php
public function register($event, callable $listener, $priority = null) { foreach ((array) $event as $e) { $this->registerListener($e, $listener, $priority); } return $this; }
[ "public", "function", "register", "(", "$", "event", ",", "callable", "$", "listener", ",", "$", "priority", "=", "null", ")", "{", "foreach", "(", "(", "array", ")", "$", "event", "as", "$", "e", ")", "{", "$", "this", "->", "registerListener", "(", "$", "e", ",", "$", "listener", ",", "$", "priority", ")", ";", "}", "return", "$", "this", ";", "}" ]
Adds listener to single event or array of events @param string|array $event @param callable $listener @param null|int $priority @return $this
[ "Adds", "listener", "to", "single", "event", "or", "array", "of", "events" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/EventDispatcher/EventDispatcher.php#L36-L43
train
phossa/phossa-di
src/Phossa/Di/Factory/ServiceFactoryTrait.php
ServiceFactoryTrait.resolvePseudoCallable
protected function resolvePseudoCallable($callableOrArray) { if (is_array($callableOrArray)) { $this->dereferenceArray($callableOrArray); } // normal callable if (is_callable($callableOrArray)) { return $callableOrArray; } else { throw new LogicException( Message::get(Message::CALLABLE_INVALID, $callableOrArray), Message::CALLABLE_INVALID ); } }
php
protected function resolvePseudoCallable($callableOrArray) { if (is_array($callableOrArray)) { $this->dereferenceArray($callableOrArray); } // normal callable if (is_callable($callableOrArray)) { return $callableOrArray; } else { throw new LogicException( Message::get(Message::CALLABLE_INVALID, $callableOrArray), Message::CALLABLE_INVALID ); } }
[ "protected", "function", "resolvePseudoCallable", "(", "$", "callableOrArray", ")", "{", "if", "(", "is_array", "(", "$", "callableOrArray", ")", ")", "{", "$", "this", "->", "dereferenceArray", "(", "$", "callableOrArray", ")", ";", "}", "// normal callable", "if", "(", "is_callable", "(", "$", "callableOrArray", ")", ")", "{", "return", "$", "callableOrArray", ";", "}", "else", "{", "throw", "new", "LogicException", "(", "Message", "::", "get", "(", "Message", "::", "CALLABLE_INVALID", ",", "$", "callableOrArray", ")", ",", "Message", "::", "CALLABLE_INVALID", ")", ";", "}", "}" ]
Resolve a fake callable to a real one fake callable like `[ '@cache@', 'setLogger' ]` or `[ new ServiceReference('cache'), 'setLogger' ]` @param callable|array $callableOrArray @return callable @throws LogicException @throws NotFoundException @access protected
[ "Resolve", "a", "fake", "callable", "to", "a", "real", "one" ]
bbe1e95b081068e2bc49c6cd465f38aab0374be5
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Factory/ServiceFactoryTrait.php#L68-L83
train
phossa/phossa-di
src/Phossa/Di/Factory/ServiceFactoryTrait.php
ServiceFactoryTrait.resolveCallableArguments
protected function resolveCallableArguments( callable $callable, array $providedArguments )/*# : array */ { // object with __invoke defined or \Closure if (is_object($callable) && !$callable instanceof \Closure) { $reflector = new \ReflectionClass($callable); $method = $reflector->getMethod('__invoke'); // array-like callable } elseif (is_array($callable)) { $reflector = new \ReflectionClass($callable[0]); $method = $reflector->getMethod($callable[1]); // simple function } else { $method = new \ReflectionFunction($callable); } // dereference the provided arguments $this->dereferenceArray($providedArguments); // match provided arguments with method parameter definitions return $this->matchMethodArguments( $method->getParameters(), $providedArguments ); }
php
protected function resolveCallableArguments( callable $callable, array $providedArguments )/*# : array */ { // object with __invoke defined or \Closure if (is_object($callable) && !$callable instanceof \Closure) { $reflector = new \ReflectionClass($callable); $method = $reflector->getMethod('__invoke'); // array-like callable } elseif (is_array($callable)) { $reflector = new \ReflectionClass($callable[0]); $method = $reflector->getMethod($callable[1]); // simple function } else { $method = new \ReflectionFunction($callable); } // dereference the provided arguments $this->dereferenceArray($providedArguments); // match provided arguments with method parameter definitions return $this->matchMethodArguments( $method->getParameters(), $providedArguments ); }
[ "protected", "function", "resolveCallableArguments", "(", "callable", "$", "callable", ",", "array", "$", "providedArguments", ")", "/*# : array */", "{", "// object with __invoke defined or \\Closure", "if", "(", "is_object", "(", "$", "callable", ")", "&&", "!", "$", "callable", "instanceof", "\\", "Closure", ")", "{", "$", "reflector", "=", "new", "\\", "ReflectionClass", "(", "$", "callable", ")", ";", "$", "method", "=", "$", "reflector", "->", "getMethod", "(", "'__invoke'", ")", ";", "// array-like callable", "}", "elseif", "(", "is_array", "(", "$", "callable", ")", ")", "{", "$", "reflector", "=", "new", "\\", "ReflectionClass", "(", "$", "callable", "[", "0", "]", ")", ";", "$", "method", "=", "$", "reflector", "->", "getMethod", "(", "$", "callable", "[", "1", "]", ")", ";", "// simple function", "}", "else", "{", "$", "method", "=", "new", "\\", "ReflectionFunction", "(", "$", "callable", ")", ";", "}", "// dereference the provided arguments", "$", "this", "->", "dereferenceArray", "(", "$", "providedArguments", ")", ";", "// match provided arguments with method parameter definitions", "return", "$", "this", "->", "matchMethodArguments", "(", "$", "method", "->", "getParameters", "(", ")", ",", "$", "providedArguments", ")", ";", "}" ]
Resolve arguments for a callable @param callable $callable @param array $providedArguments the provided arguments @return array the resolved arguments @throws LogicException @throws NotFoundException @access protected
[ "Resolve", "arguments", "for", "a", "callable" ]
bbe1e95b081068e2bc49c6cd465f38aab0374be5
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Factory/ServiceFactoryTrait.php#L95-L122
train
phossa/phossa-di
src/Phossa/Di/Factory/ServiceFactoryTrait.php
ServiceFactoryTrait.getObjectByClassname
protected function getObjectByClassname(/*# string */ $classname) { // mapping exists if (isset($this->mappings[$classname])) { $classname = $this->mappings[$classname]; // is it a reference ? #changed if (false !== ($ref = $this->isReference($classname))) { $classname = $this->getReferenceValue($ref); // got a service object if (is_object($classname)) { return $classname; } } } // try get service by $classname from container return $this->delegatedGet($classname); }
php
protected function getObjectByClassname(/*# string */ $classname) { // mapping exists if (isset($this->mappings[$classname])) { $classname = $this->mappings[$classname]; // is it a reference ? #changed if (false !== ($ref = $this->isReference($classname))) { $classname = $this->getReferenceValue($ref); // got a service object if (is_object($classname)) { return $classname; } } } // try get service by $classname from container return $this->delegatedGet($classname); }
[ "protected", "function", "getObjectByClassname", "(", "/*# string */", "$", "classname", ")", "{", "// mapping exists", "if", "(", "isset", "(", "$", "this", "->", "mappings", "[", "$", "classname", "]", ")", ")", "{", "$", "classname", "=", "$", "this", "->", "mappings", "[", "$", "classname", "]", ";", "// is it a reference ? #changed", "if", "(", "false", "!==", "(", "$", "ref", "=", "$", "this", "->", "isReference", "(", "$", "classname", ")", ")", ")", "{", "$", "classname", "=", "$", "this", "->", "getReferenceValue", "(", "$", "ref", ")", ";", "// got a service object", "if", "(", "is_object", "(", "$", "classname", ")", ")", "{", "return", "$", "classname", ";", "}", "}", "}", "// try get service by $classname from container", "return", "$", "this", "->", "delegatedGet", "(", "$", "classname", ")", ";", "}" ]
Get an object base on provided classname @param string $classname class name @return object @throws LogicException @access protected @api
[ "Get", "an", "object", "base", "on", "provided", "classname" ]
bbe1e95b081068e2bc49c6cd465f38aab0374be5
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Factory/ServiceFactoryTrait.php#L243-L262
train
phossa/phossa-di
src/Phossa/Di/Factory/ServiceFactoryTrait.php
ServiceFactoryTrait.createServiceObject
protected function createServiceObject(/*# string */ $id, array $arguments) { // class definition $def = &$this->services[$id]['class']; $class = $def[0]; // prepare constructor arguments $args = empty($arguments) ? (isset($def[1]) ? $def[1] : []) : $arguments; try { // objects if (is_object($class)) { // closure with arguments if ($class instanceof \Closure) { return $this->executeCallable($class, $args); // other object } else { return $class; } // (pseudo) callable with arguments } elseif (is_array($class[0])) { return $this->executeCallable($class[0], $args); // instantiation with arguments } else { // reference value #changed if (false !== ($ref = $this->isReference($class))) { $class = $this->getReferenceValue($ref); if (is_object($class)) { return $class; } } return $this->constructObject($class, $args); } } catch (\Exception $e) { throw new LogicException($e->getMessage(), $e->getCode(), $e); } }
php
protected function createServiceObject(/*# string */ $id, array $arguments) { // class definition $def = &$this->services[$id]['class']; $class = $def[0]; // prepare constructor arguments $args = empty($arguments) ? (isset($def[1]) ? $def[1] : []) : $arguments; try { // objects if (is_object($class)) { // closure with arguments if ($class instanceof \Closure) { return $this->executeCallable($class, $args); // other object } else { return $class; } // (pseudo) callable with arguments } elseif (is_array($class[0])) { return $this->executeCallable($class[0], $args); // instantiation with arguments } else { // reference value #changed if (false !== ($ref = $this->isReference($class))) { $class = $this->getReferenceValue($ref); if (is_object($class)) { return $class; } } return $this->constructObject($class, $args); } } catch (\Exception $e) { throw new LogicException($e->getMessage(), $e->getCode(), $e); } }
[ "protected", "function", "createServiceObject", "(", "/*# string */", "$", "id", ",", "array", "$", "arguments", ")", "{", "// class definition", "$", "def", "=", "&", "$", "this", "->", "services", "[", "$", "id", "]", "[", "'class'", "]", ";", "$", "class", "=", "$", "def", "[", "0", "]", ";", "// prepare constructor arguments", "$", "args", "=", "empty", "(", "$", "arguments", ")", "?", "(", "isset", "(", "$", "def", "[", "1", "]", ")", "?", "$", "def", "[", "1", "]", ":", "[", "]", ")", ":", "$", "arguments", ";", "try", "{", "// objects", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "// closure with arguments", "if", "(", "$", "class", "instanceof", "\\", "Closure", ")", "{", "return", "$", "this", "->", "executeCallable", "(", "$", "class", ",", "$", "args", ")", ";", "// other object", "}", "else", "{", "return", "$", "class", ";", "}", "// (pseudo) callable with arguments", "}", "elseif", "(", "is_array", "(", "$", "class", "[", "0", "]", ")", ")", "{", "return", "$", "this", "->", "executeCallable", "(", "$", "class", "[", "0", "]", ",", "$", "args", ")", ";", "// instantiation with arguments", "}", "else", "{", "// reference value #changed", "if", "(", "false", "!==", "(", "$", "ref", "=", "$", "this", "->", "isReference", "(", "$", "class", ")", ")", ")", "{", "$", "class", "=", "$", "this", "->", "getReferenceValue", "(", "$", "ref", ")", ";", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "return", "$", "class", ";", "}", "}", "return", "$", "this", "->", "constructObject", "(", "$", "class", ",", "$", "args", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "LogicException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Create service object from service definition @param string $id service id @param array $arguments @return object @throws LogicException if something goes wrong @access protected
[ "Create", "service", "object", "from", "service", "definition" ]
bbe1e95b081068e2bc49c6cd465f38aab0374be5
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Factory/ServiceFactoryTrait.php#L273-L314
train
phossa/phossa-di
src/Phossa/Di/Factory/ServiceFactoryTrait.php
ServiceFactoryTrait.runDefinedMethods
protected function runDefinedMethods(/*# string */ $id, $service) { try { if (isset($this->services[$id]['methods'])) { $methods = $this->services[$id]['methods']; foreach ($methods as $method) { if (!is_array($method) || !isset($method[0]) || !is_string($method[0]) ) { throw new LogicException( Message::get( Message::SERVICE_METHOD_ERROR, $id, isset($method[0]) ? $method[0] : '' ), Message::SERVICE_METHOD_ERROR ); } // execute with arguments $this->executeCallable( [ $service, $method[0] ], isset($method[1]) ? (array) $method[1] : [] ); } } } catch (\Exception $e) { throw new LogicException($e->getMessage(), $e->getCode(), $e); } }
php
protected function runDefinedMethods(/*# string */ $id, $service) { try { if (isset($this->services[$id]['methods'])) { $methods = $this->services[$id]['methods']; foreach ($methods as $method) { if (!is_array($method) || !isset($method[0]) || !is_string($method[0]) ) { throw new LogicException( Message::get( Message::SERVICE_METHOD_ERROR, $id, isset($method[0]) ? $method[0] : '' ), Message::SERVICE_METHOD_ERROR ); } // execute with arguments $this->executeCallable( [ $service, $method[0] ], isset($method[1]) ? (array) $method[1] : [] ); } } } catch (\Exception $e) { throw new LogicException($e->getMessage(), $e->getCode(), $e); } }
[ "protected", "function", "runDefinedMethods", "(", "/*# string */", "$", "id", ",", "$", "service", ")", "{", "try", "{", "if", "(", "isset", "(", "$", "this", "->", "services", "[", "$", "id", "]", "[", "'methods'", "]", ")", ")", "{", "$", "methods", "=", "$", "this", "->", "services", "[", "$", "id", "]", "[", "'methods'", "]", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "!", "is_array", "(", "$", "method", ")", "||", "!", "isset", "(", "$", "method", "[", "0", "]", ")", "||", "!", "is_string", "(", "$", "method", "[", "0", "]", ")", ")", "{", "throw", "new", "LogicException", "(", "Message", "::", "get", "(", "Message", "::", "SERVICE_METHOD_ERROR", ",", "$", "id", ",", "isset", "(", "$", "method", "[", "0", "]", ")", "?", "$", "method", "[", "0", "]", ":", "''", ")", ",", "Message", "::", "SERVICE_METHOD_ERROR", ")", ";", "}", "// execute with arguments", "$", "this", "->", "executeCallable", "(", "[", "$", "service", ",", "$", "method", "[", "0", "]", "]", ",", "isset", "(", "$", "method", "[", "1", "]", ")", "?", "(", "array", ")", "$", "method", "[", "1", "]", ":", "[", "]", ")", ";", "}", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "LogicException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Initialize service object by runing its defined methods @param string $id service id @param object $service service object @return void @throws LogicException @access protected
[ "Initialize", "service", "object", "by", "runing", "its", "defined", "methods" ]
bbe1e95b081068e2bc49c6cd465f38aab0374be5
https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Factory/ServiceFactoryTrait.php#L377-L408
train
sil-project/Contact
Model/Group.php
Group.addMember
public function addMember(GroupMemberInterface $member) { if ($this->members->contains($member)) { throw new \InvalidArgumentException('This entity is already a member of this group'); } $this->members->add($member); }
php
public function addMember(GroupMemberInterface $member) { if ($this->members->contains($member)) { throw new \InvalidArgumentException('This entity is already a member of this group'); } $this->members->add($member); }
[ "public", "function", "addMember", "(", "GroupMemberInterface", "$", "member", ")", "{", "if", "(", "$", "this", "->", "members", "->", "contains", "(", "$", "member", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'This entity is already a member of this group'", ")", ";", "}", "$", "this", "->", "members", "->", "add", "(", "$", "member", ")", ";", "}" ]
Add a member to the collection. @param GroupMemberInterface $member
[ "Add", "a", "member", "to", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Group.php#L92-L99
train
sil-project/Contact
Model/Group.php
Group.removeMember
public function removeMember(GroupMemberInterface $member) { if (!$this->hasMember($member)) { throw new \InvalidArgumentException('Trying to remove a member that is not in that group'); } $this->members->removeElement($member); }
php
public function removeMember(GroupMemberInterface $member) { if (!$this->hasMember($member)) { throw new \InvalidArgumentException('Trying to remove a member that is not in that group'); } $this->members->removeElement($member); }
[ "public", "function", "removeMember", "(", "GroupMemberInterface", "$", "member", ")", "{", "if", "(", "!", "$", "this", "->", "hasMember", "(", "$", "member", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Trying to remove a member that is not in that group'", ")", ";", "}", "$", "this", "->", "members", "->", "removeElement", "(", "$", "member", ")", ";", "}" ]
Remove a member from the collection. @param GroupMemberInterface $member
[ "Remove", "a", "member", "from", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Group.php#L106-L113
train
sil-project/Contact
Model/Group.php
Group.addChild
public function addChild(GroupInterface $child) { if ($this->children->contains($child)) { throw new \InvalidArgumentException('This entity is already a child of this group'); } $this->children->add($child); }
php
public function addChild(GroupInterface $child) { if ($this->children->contains($child)) { throw new \InvalidArgumentException('This entity is already a child of this group'); } $this->children->add($child); }
[ "public", "function", "addChild", "(", "GroupInterface", "$", "child", ")", "{", "if", "(", "$", "this", "->", "children", "->", "contains", "(", "$", "child", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'This entity is already a child of this group'", ")", ";", "}", "$", "this", "->", "children", "->", "add", "(", "$", "child", ")", ";", "}" ]
Add a child group to the collection. @param GroupInterface $child
[ "Add", "a", "child", "group", "to", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Group.php#L162-L169
train
sil-project/Contact
Model/Group.php
Group.removeChild
public function removeChild(GroupInterface $child) { if (!$this->hasChild($child)) { throw new \InvalidArgumentException('Trying to remove a non existing child group'); } $this->children->removeElement($child); }
php
public function removeChild(GroupInterface $child) { if (!$this->hasChild($child)) { throw new \InvalidArgumentException('Trying to remove a non existing child group'); } $this->children->removeElement($child); }
[ "public", "function", "removeChild", "(", "GroupInterface", "$", "child", ")", "{", "if", "(", "!", "$", "this", "->", "hasChild", "(", "$", "child", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Trying to remove a non existing child group'", ")", ";", "}", "$", "this", "->", "children", "->", "removeElement", "(", "$", "child", ")", ";", "}" ]
Remove a child group from the collection. @param GroupInterface $child
[ "Remove", "a", "child", "group", "from", "the", "collection", "." ]
ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9
https://github.com/sil-project/Contact/blob/ead863b5dc4ee7a6a2e3f0f181d1a0874b4969b9/Model/Group.php#L176-L183
train
Raphhh/puppy-application
src/Route/RouteFinder.php
RouteFinder.find
public function find(Request $request, array $routes) { foreach ($routes as $route) { if(!$this->matchMethod($request, $route)){ continue; } if(!$this->matchContentType($request, $route)){ continue; } if(!$this->matchFilters($route)){ continue; } $routeMatches = $this->matchPattern($request, $route); if ($routeMatches) { $route->setMatches($routeMatches); return $route; } } throw new RouteException( sprintf('No route found for uri "%s"', $request->getRequestUri()), $request, $routes ); }
php
public function find(Request $request, array $routes) { foreach ($routes as $route) { if(!$this->matchMethod($request, $route)){ continue; } if(!$this->matchContentType($request, $route)){ continue; } if(!$this->matchFilters($route)){ continue; } $routeMatches = $this->matchPattern($request, $route); if ($routeMatches) { $route->setMatches($routeMatches); return $route; } } throw new RouteException( sprintf('No route found for uri "%s"', $request->getRequestUri()), $request, $routes ); }
[ "public", "function", "find", "(", "Request", "$", "request", ",", "array", "$", "routes", ")", "{", "foreach", "(", "$", "routes", "as", "$", "route", ")", "{", "if", "(", "!", "$", "this", "->", "matchMethod", "(", "$", "request", ",", "$", "route", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "this", "->", "matchContentType", "(", "$", "request", ",", "$", "route", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "this", "->", "matchFilters", "(", "$", "route", ")", ")", "{", "continue", ";", "}", "$", "routeMatches", "=", "$", "this", "->", "matchPattern", "(", "$", "request", ",", "$", "route", ")", ";", "if", "(", "$", "routeMatches", ")", "{", "$", "route", "->", "setMatches", "(", "$", "routeMatches", ")", ";", "return", "$", "route", ";", "}", "}", "throw", "new", "RouteException", "(", "sprintf", "(", "'No route found for uri \"%s\"'", ",", "$", "request", "->", "getRequestUri", "(", ")", ")", ",", "$", "request", ",", "$", "routes", ")", ";", "}" ]
Finds a route in matching its pattern with a uri. @param Request $request @param Route[] $routes @return Route
[ "Finds", "a", "route", "in", "matching", "its", "pattern", "with", "a", "uri", "." ]
9291543cd28e19a2986abd7fb146898ca5f5f5da
https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Route/RouteFinder.php#L37-L64
train
valu-digital/valusetup
src/ValuSetup/Service/AbstractSetupService.php
AbstractSetupService.getName
public function getName() { if (!$this->name) { $this->name = $this->utils()->whichModule($this); } return $this->name; }
php
public function getName() { if (!$this->name) { $this->name = $this->utils()->whichModule($this); } return $this->name; }
[ "public", "function", "getName", "(", ")", "{", "if", "(", "!", "$", "this", "->", "name", ")", "{", "$", "this", "->", "name", "=", "$", "this", "->", "utils", "(", ")", "->", "whichModule", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "name", ";", "}" ]
Retrieve module name for setup service @return string @ValuService\Context({"cli", "http", "http-get"}) @ValuServiceAcl\Superuser
[ "Retrieve", "module", "name", "for", "setup", "service" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AbstractSetupService.php#L64-L71
train
valu-digital/valusetup
src/ValuSetup/Service/AbstractSetupService.php
AbstractSetupService.install
public function install($version = null, array $options = array()) { $module = $this->utils()->whichModule($this); if ($version === null) { $version = $this->utils()->getModuleVersion($module); if (!$version) { throw new MissingParameterException( 'Parameter version is missing and cannot be autodetected'); } } return $this->utils()->install($module, $version, $options); }
php
public function install($version = null, array $options = array()) { $module = $this->utils()->whichModule($this); if ($version === null) { $version = $this->utils()->getModuleVersion($module); if (!$version) { throw new MissingParameterException( 'Parameter version is missing and cannot be autodetected'); } } return $this->utils()->install($module, $version, $options); }
[ "public", "function", "install", "(", "$", "version", "=", "null", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "module", "=", "$", "this", "->", "utils", "(", ")", "->", "whichModule", "(", "$", "this", ")", ";", "if", "(", "$", "version", "===", "null", ")", "{", "$", "version", "=", "$", "this", "->", "utils", "(", ")", "->", "getModuleVersion", "(", "$", "module", ")", ";", "if", "(", "!", "$", "version", ")", "{", "throw", "new", "MissingParameterException", "(", "'Parameter version is missing and cannot be autodetected'", ")", ";", "}", "}", "return", "$", "this", "->", "utils", "(", ")", "->", "install", "(", "$", "module", ",", "$", "version", ",", "$", "options", ")", ";", "}" ]
Install module and its dependencies @param array $options Setup options @return boolean True on success @ValuService\Context({"cli", "http", "http-put"}) @ValuServiceAcl\Superuser
[ "Install", "module", "and", "its", "dependencies" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AbstractSetupService.php#L94-L107
train
valu-digital/valusetup
src/ValuSetup/Service/AbstractSetupService.php
AbstractSetupService.update
public function update(array $options = array()) { $module = $this->utils()->whichModule($this); return $this->utils()->update($module, $options); }
php
public function update(array $options = array()) { $module = $this->utils()->whichModule($this); return $this->utils()->update($module, $options); }
[ "public", "function", "update", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "module", "=", "$", "this", "->", "utils", "(", ")", "->", "whichModule", "(", "$", "this", ")", ";", "return", "$", "this", "->", "utils", "(", ")", "->", "update", "(", "$", "module", ",", "$", "options", ")", ";", "}" ]
Update module and its dependencies @param array $options Setup options @return boolean True on success @ValuService\Context({"cli", "http", "http-post"}) @ValuServiceAcl\Superuser
[ "Update", "module", "and", "its", "dependencies" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AbstractSetupService.php#L118-L122
train
valu-digital/valusetup
src/ValuSetup/Service/AbstractSetupService.php
AbstractSetupService.upgrade
public function upgrade($from, array $options = array()){ $to = $this->utils()->getModuleVersion($this->getName()); if(SoftwareVersion::compare($to, $from) <= 0){ throw new Exception\IllegalVersionException( sprintf('Unable to upgrade %s to version %s', $this->getName().' '.$to, $from) ); } return true; }
php
public function upgrade($from, array $options = array()){ $to = $this->utils()->getModuleVersion($this->getName()); if(SoftwareVersion::compare($to, $from) <= 0){ throw new Exception\IllegalVersionException( sprintf('Unable to upgrade %s to version %s', $this->getName().' '.$to, $from) ); } return true; }
[ "public", "function", "upgrade", "(", "$", "from", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "to", "=", "$", "this", "->", "utils", "(", ")", "->", "getModuleVersion", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "if", "(", "SoftwareVersion", "::", "compare", "(", "$", "to", ",", "$", "from", ")", "<=", "0", ")", "{", "throw", "new", "Exception", "\\", "IllegalVersionException", "(", "sprintf", "(", "'Unable to upgrade %s to version %s'", ",", "$", "this", "->", "getName", "(", ")", ".", "' '", ".", "$", "to", ",", "$", "from", ")", ")", ";", "}", "return", "true", ";", "}" ]
Upgrade module from previous version This method should be invoked only after the new version has been loaded. This method should also ignore any values of $from that indicate version number that is greater than or equal to current version. This method should ensure backwards compatibility and prepare data from previous version for the current version. @param string $from Version information @param array $options @return boolean True on success @ValuService\Context({"cli", "http", "http-post"}) @ValuServiceAcl\Superuser
[ "Upgrade", "module", "from", "previous", "version" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AbstractSetupService.php#L157-L168
train
valu-digital/valusetup
src/ValuSetup/Service/AbstractSetupService.php
AbstractSetupService.utils
protected function utils() { if(!$this->utils){ $this->utils = $this->getServiceLocator()->get('valu_setup.setup_utils'); } return $this->utils; }
php
protected function utils() { if(!$this->utils){ $this->utils = $this->getServiceLocator()->get('valu_setup.setup_utils'); } return $this->utils; }
[ "protected", "function", "utils", "(", ")", "{", "if", "(", "!", "$", "this", "->", "utils", ")", "{", "$", "this", "->", "utils", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'valu_setup.setup_utils'", ")", ";", "}", "return", "$", "this", "->", "utils", ";", "}" ]
Direct access to service utilities @return \ValuSetup\Setup\SetupUtils
[ "Direct", "access", "to", "service", "utilities" ]
db1a0bfe1262d555eb11cd0d99625b9ee43d6744
https://github.com/valu-digital/valusetup/blob/db1a0bfe1262d555eb11cd0d99625b9ee43d6744/src/ValuSetup/Service/AbstractSetupService.php#L240-L247
train
squareproton/Bond
src/Bond/Pg.php
Pg.listen
public function listen( $channels ) { $channels = is_array( $channels ) ? $channels : array( $channels ); foreach( $channels as $channel ) { // clean up channel - it doesn't require quoting (not sure why) // make safe with whitelist of chars $channel = preg_replace( "/[^a-zA-Z\._:]/", '', $channel ); $this->query( new Raw( "LISTEN {$channel}" ) ); } }
php
public function listen( $channels ) { $channels = is_array( $channels ) ? $channels : array( $channels ); foreach( $channels as $channel ) { // clean up channel - it doesn't require quoting (not sure why) // make safe with whitelist of chars $channel = preg_replace( "/[^a-zA-Z\._:]/", '', $channel ); $this->query( new Raw( "LISTEN {$channel}" ) ); } }
[ "public", "function", "listen", "(", "$", "channels", ")", "{", "$", "channels", "=", "is_array", "(", "$", "channels", ")", "?", "$", "channels", ":", "array", "(", "$", "channels", ")", ";", "foreach", "(", "$", "channels", "as", "$", "channel", ")", "{", "// clean up channel - it doesn't require quoting (not sure why)", "// make safe with whitelist of chars", "$", "channel", "=", "preg_replace", "(", "\"/[^a-zA-Z\\._:]/\"", ",", "''", ",", "$", "channel", ")", ";", "$", "this", "->", "query", "(", "new", "Raw", "(", "\"LISTEN {$channel}\"", ")", ")", ";", "}", "}" ]
Subscribe to a postgres channel
[ "Subscribe", "to", "a", "postgres", "channel" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg.php#L203-L212
train
squareproton/Bond
src/Bond/Pg.php
Pg.quote
public function quote( $value, array $modifiers = [] ) { if( is_null( $value ) ) { $value = 'NULL'; } elseif( is_bool( $value ) ) { $value = $value ? 'TRUE' : 'FALSE'; } elseif( is_int( $value ) ) { $value = (string) $value; } elseif( $value instanceof SqlInterface ) { $value = $value->parse( $this ); } else { $value = "'" . pg_escape_string( $this->resource->get(), $value ) . "'"; } foreach( $modifiers as $modifier ) { $modifier( $value ); } return $value; }
php
public function quote( $value, array $modifiers = [] ) { if( is_null( $value ) ) { $value = 'NULL'; } elseif( is_bool( $value ) ) { $value = $value ? 'TRUE' : 'FALSE'; } elseif( is_int( $value ) ) { $value = (string) $value; } elseif( $value instanceof SqlInterface ) { $value = $value->parse( $this ); } else { $value = "'" . pg_escape_string( $this->resource->get(), $value ) . "'"; } foreach( $modifiers as $modifier ) { $modifier( $value ); } return $value; }
[ "public", "function", "quote", "(", "$", "value", ",", "array", "$", "modifiers", "=", "[", "]", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "value", "=", "'NULL'", ";", "}", "elseif", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "value", "?", "'TRUE'", ":", "'FALSE'", ";", "}", "elseif", "(", "is_int", "(", "$", "value", ")", ")", "{", "$", "value", "=", "(", "string", ")", "$", "value", ";", "}", "elseif", "(", "$", "value", "instanceof", "SqlInterface", ")", "{", "$", "value", "=", "$", "value", "->", "parse", "(", "$", "this", ")", ";", "}", "else", "{", "$", "value", "=", "\"'\"", ".", "pg_escape_string", "(", "$", "this", "->", "resource", "->", "get", "(", ")", ",", "$", "value", ")", ".", "\"'\"", ";", "}", "foreach", "(", "$", "modifiers", "as", "$", "modifier", ")", "{", "$", "modifier", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Return a value made safe for insertion into a database @param array $modifiers Array of \Closures to be applied before returning @return string
[ "Return", "a", "value", "made", "safe", "for", "insertion", "into", "a", "database" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg.php#L220-L239
train
squareproton/Bond
src/Bond/Pg.php
Pg.getParameter
public function getParameter( $parameter ) { self::isParameterAllowed( $parameter ); $value = $this->query(new Raw("SHOW {$parameter}"))->fetch( Result::FETCH_SINGLE ); return ( $value === 'true' or $value === 'false' ) ? \Bond\boolval( $value ) : $value; }
php
public function getParameter( $parameter ) { self::isParameterAllowed( $parameter ); $value = $this->query(new Raw("SHOW {$parameter}"))->fetch( Result::FETCH_SINGLE ); return ( $value === 'true' or $value === 'false' ) ? \Bond\boolval( $value ) : $value; }
[ "public", "function", "getParameter", "(", "$", "parameter", ")", "{", "self", "::", "isParameterAllowed", "(", "$", "parameter", ")", ";", "$", "value", "=", "$", "this", "->", "query", "(", "new", "Raw", "(", "\"SHOW {$parameter}\"", ")", ")", "->", "fetch", "(", "Result", "::", "FETCH_SINGLE", ")", ";", "return", "(", "$", "value", "===", "'true'", "or", "$", "value", "===", "'false'", ")", "?", "\\", "Bond", "\\", "boolval", "(", "$", "value", ")", ":", "$", "value", ";", "}" ]
Get a postgres runtime parameter @return string
[ "Get", "a", "postgres", "runtime", "parameter" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg.php#L272-L283
train
squareproton/Bond
src/Bond/Pg.php
Pg.setParameter
public function setParameter( $parameter, $value, $restorePoint = self::PREVIOUS, $type = self::SESSION ) { if (!is_scalar($value)) { throw new BadTypeException($value, 'scalar'); } self::isParameterAllowed( $parameter ); if( !in_array( $type, array( self::SESSION, self::LOCAL ) ) ) { throw new \InvalidArgumentException("WTF!"); } if( $restorePoint and !is_scalar($restorePoint) ) { throw new \InvalidArgumentException( "RestorePoint has to be a scalar."); } // manage previous and original stores $currentValue = $this->getParameter( $parameter ); if( !isset( $this->parameterStore[$parameter][self::ORIGINAL] ) ) { $this->parameterStore[$parameter][self::ORIGINAL] = $currentValue; } $this->parameterStore[$parameter][self::PREVIOUS] = $currentValue; // we can't quote a parameter value so regex /* if( preg_match_all('/[^a-zA-Z0-9_]/', $value, $matches ) ) { $badChars = implode('', $matches[0]); throw new \Exception( "We can't quote parameter values. Bad characters `{$badChars}`" ); } */ // bool if( $value === true ) { $value = 'true'; } elseif( $value === false ) { $value = 'false'; } // parameters if( $restorePoint !== self::PREVIOUS ) { $this->parameterStore[$parameter][$restorePoint] = $value; } $value = $this->query( new Raw("SET {$parameter} TO {$value}") ); return $this; }
php
public function setParameter( $parameter, $value, $restorePoint = self::PREVIOUS, $type = self::SESSION ) { if (!is_scalar($value)) { throw new BadTypeException($value, 'scalar'); } self::isParameterAllowed( $parameter ); if( !in_array( $type, array( self::SESSION, self::LOCAL ) ) ) { throw new \InvalidArgumentException("WTF!"); } if( $restorePoint and !is_scalar($restorePoint) ) { throw new \InvalidArgumentException( "RestorePoint has to be a scalar."); } // manage previous and original stores $currentValue = $this->getParameter( $parameter ); if( !isset( $this->parameterStore[$parameter][self::ORIGINAL] ) ) { $this->parameterStore[$parameter][self::ORIGINAL] = $currentValue; } $this->parameterStore[$parameter][self::PREVIOUS] = $currentValue; // we can't quote a parameter value so regex /* if( preg_match_all('/[^a-zA-Z0-9_]/', $value, $matches ) ) { $badChars = implode('', $matches[0]); throw new \Exception( "We can't quote parameter values. Bad characters `{$badChars}`" ); } */ // bool if( $value === true ) { $value = 'true'; } elseif( $value === false ) { $value = 'false'; } // parameters if( $restorePoint !== self::PREVIOUS ) { $this->parameterStore[$parameter][$restorePoint] = $value; } $value = $this->query( new Raw("SET {$parameter} TO {$value}") ); return $this; }
[ "public", "function", "setParameter", "(", "$", "parameter", ",", "$", "value", ",", "$", "restorePoint", "=", "self", "::", "PREVIOUS", ",", "$", "type", "=", "self", "::", "SESSION", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "BadTypeException", "(", "$", "value", ",", "'scalar'", ")", ";", "}", "self", "::", "isParameterAllowed", "(", "$", "parameter", ")", ";", "if", "(", "!", "in_array", "(", "$", "type", ",", "array", "(", "self", "::", "SESSION", ",", "self", "::", "LOCAL", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"WTF!\"", ")", ";", "}", "if", "(", "$", "restorePoint", "and", "!", "is_scalar", "(", "$", "restorePoint", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"RestorePoint has to be a scalar.\"", ")", ";", "}", "// manage previous and original stores", "$", "currentValue", "=", "$", "this", "->", "getParameter", "(", "$", "parameter", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "parameterStore", "[", "$", "parameter", "]", "[", "self", "::", "ORIGINAL", "]", ")", ")", "{", "$", "this", "->", "parameterStore", "[", "$", "parameter", "]", "[", "self", "::", "ORIGINAL", "]", "=", "$", "currentValue", ";", "}", "$", "this", "->", "parameterStore", "[", "$", "parameter", "]", "[", "self", "::", "PREVIOUS", "]", "=", "$", "currentValue", ";", "// we can't quote a parameter value so regex", "/*\n if( preg_match_all('/[^a-zA-Z0-9_]/', $value, $matches ) ) {\n $badChars = implode('', $matches[0]);\n throw new \\Exception( \"We can't quote parameter values. Bad characters `{$badChars}`\" );\n }\n */", "// bool", "if", "(", "$", "value", "===", "true", ")", "{", "$", "value", "=", "'true'", ";", "}", "elseif", "(", "$", "value", "===", "false", ")", "{", "$", "value", "=", "'false'", ";", "}", "// parameters", "if", "(", "$", "restorePoint", "!==", "self", "::", "PREVIOUS", ")", "{", "$", "this", "->", "parameterStore", "[", "$", "parameter", "]", "[", "$", "restorePoint", "]", "=", "$", "value", ";", "}", "$", "value", "=", "$", "this", "->", "query", "(", "new", "Raw", "(", "\"SET {$parameter} TO {$value}\"", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set a postgres runtime parameter @param string @param mixed @param scalar @param string self::SESSION | self::LOCAL @return $this
[ "Set", "a", "postgres", "runtime", "parameter" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Pg.php#L293-L342
train
dmj/PicaRecord
src/HAB/Pica/Record/Record.php
Record.factory
public static function factory (array $record) { if (!array_key_exists('fields', $record)) { throw new InvalidArgumentException("Missing 'fields' index in record array"); } $fields = array_map(array('HAB\Pica\Record\Field', 'factory'), $record['fields']); $type = null; $typePredicate = Field::match('002@/00'); foreach ($fields as $field) { if ($typePredicate($field)) { $typeSubfield = $field->getNthSubfield('0', 0); if ($typeSubfield) { $type = $typeSubfield->getValue(); break; } } } if ($type === null) { throw new InvalidArgumentException("Missing type field (002@/00$0)"); } if ($type[0] === 'T') { return new AuthorityRecord($fields); } else { return new TitleRecord($fields); } }
php
public static function factory (array $record) { if (!array_key_exists('fields', $record)) { throw new InvalidArgumentException("Missing 'fields' index in record array"); } $fields = array_map(array('HAB\Pica\Record\Field', 'factory'), $record['fields']); $type = null; $typePredicate = Field::match('002@/00'); foreach ($fields as $field) { if ($typePredicate($field)) { $typeSubfield = $field->getNthSubfield('0', 0); if ($typeSubfield) { $type = $typeSubfield->getValue(); break; } } } if ($type === null) { throw new InvalidArgumentException("Missing type field (002@/00$0)"); } if ($type[0] === 'T') { return new AuthorityRecord($fields); } else { return new TitleRecord($fields); } }
[ "public", "static", "function", "factory", "(", "array", "$", "record", ")", "{", "if", "(", "!", "array_key_exists", "(", "'fields'", ",", "$", "record", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Missing 'fields' index in record array\"", ")", ";", "}", "$", "fields", "=", "array_map", "(", "array", "(", "'HAB\\Pica\\Record\\Field'", ",", "'factory'", ")", ",", "$", "record", "[", "'fields'", "]", ")", ";", "$", "type", "=", "null", ";", "$", "typePredicate", "=", "Field", "::", "match", "(", "'002@/00'", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "$", "typePredicate", "(", "$", "field", ")", ")", "{", "$", "typeSubfield", "=", "$", "field", "->", "getNthSubfield", "(", "'0'", ",", "0", ")", ";", "if", "(", "$", "typeSubfield", ")", "{", "$", "type", "=", "$", "typeSubfield", "->", "getValue", "(", ")", ";", "break", ";", "}", "}", "}", "if", "(", "$", "type", "===", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Missing type field (002@/00$0)\"", ")", ";", "}", "if", "(", "$", "type", "[", "0", "]", "===", "'T'", ")", "{", "return", "new", "AuthorityRecord", "(", "$", "fields", ")", ";", "}", "else", "{", "return", "new", "TitleRecord", "(", "$", "fields", ")", ";", "}", "}" ]
Return a new record based on its array representation. Returns either a {@link TitleRecord} or a {@link AuthorityRecord} depending on the field 002@ which encodes the record type. @throws InvalidArgumentException Missing type field @throws InvalidArgumentException Missing `fields' index @param array $record Array representation of a record @return TitleRecord|AuthorityRecord New record instance
[ "Return", "a", "new", "record", "based", "on", "its", "array", "representation", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Record.php#L51-L76
train
dmj/PicaRecord
src/HAB/Pica/Record/Record.php
Record.append
public function append (Field $field) { if (in_array($field, $this->_fields, true)) { throw new InvalidArgumentException("{$this} already contains {$field}"); } $this->_fields []= $field; }
php
public function append (Field $field) { if (in_array($field, $this->_fields, true)) { throw new InvalidArgumentException("{$this} already contains {$field}"); } $this->_fields []= $field; }
[ "public", "function", "append", "(", "Field", "$", "field", ")", "{", "if", "(", "in_array", "(", "$", "field", ",", "$", "this", "->", "_fields", ",", "true", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"{$this} already contains {$field}\"", ")", ";", "}", "$", "this", "->", "_fields", "[", "]", "=", "$", "field", ";", "}" ]
Append a field to the record. @throws InvalidArgumentException Field already in record @param \HAB\Pica\Record\Field $field Field to append @return void
[ "Append", "a", "field", "to", "the", "record", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Record.php#L136-L142
train
dmj/PicaRecord
src/HAB/Pica/Record/Record.php
Record.sort
public function sort () { usort($this->_fields, function (Field $fieldA, Field $fieldB) { return strcmp($fieldA->getShorthand(), $fieldB->getShorthand()); }); }
php
public function sort () { usort($this->_fields, function (Field $fieldA, Field $fieldB) { return strcmp($fieldA->getShorthand(), $fieldB->getShorthand()); }); }
[ "public", "function", "sort", "(", ")", "{", "usort", "(", "$", "this", "->", "_fields", ",", "function", "(", "Field", "$", "fieldA", ",", "Field", "$", "fieldB", ")", "{", "return", "strcmp", "(", "$", "fieldA", "->", "getShorthand", "(", ")", ",", "$", "fieldB", "->", "getShorthand", "(", ")", ")", ";", "}", ")", ";", "}" ]
Sort the fields of the record. Fields are sorted by their shorthand. @see \HAB\Pica\Record\Field::getShorthand() @return void
[ "Sort", "the", "fields", "of", "the", "record", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Record.php#L153-L159
train
dmj/PicaRecord
src/HAB/Pica/Record/Record.php
Record.setFields
public function setFields (array $fields) { $this->_fields = array(); foreach ($fields as $field) { $this->append($field); } }
php
public function setFields (array $fields) { $this->_fields = array(); foreach ($fields as $field) { $this->append($field); } }
[ "public", "function", "setFields", "(", "array", "$", "fields", ")", "{", "$", "this", "->", "_fields", "=", "array", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "this", "->", "append", "(", "$", "field", ")", ";", "}", "}" ]
Set the record fields. Removes the current set of fields and replaces it with the fields in argument. @param array $fields Fields @return void
[ "Set", "the", "record", "fields", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Record.php#L170-L176
train
dmj/PicaRecord
src/HAB/Pica/Record/Record.php
Record.getMaximumOccurrenceOf
public function getMaximumOccurrenceOf ($tag) { if (!preg_match(Field::TAG_RE, $tag)) { throw new InvalidArgumentException("Invalid field tag: {$tag}"); } return array_reduce($this->getFields($tag), function ($maxOccurrence, Field $field) { if ($field->getOccurrence() > $maxOccurrence || $maxOccurrence === null) { return $field->getOccurrence(); } else { return $maxOccurrence; } }, null); }
php
public function getMaximumOccurrenceOf ($tag) { if (!preg_match(Field::TAG_RE, $tag)) { throw new InvalidArgumentException("Invalid field tag: {$tag}"); } return array_reduce($this->getFields($tag), function ($maxOccurrence, Field $field) { if ($field->getOccurrence() > $maxOccurrence || $maxOccurrence === null) { return $field->getOccurrence(); } else { return $maxOccurrence; } }, null); }
[ "public", "function", "getMaximumOccurrenceOf", "(", "$", "tag", ")", "{", "if", "(", "!", "preg_match", "(", "Field", "::", "TAG_RE", ",", "$", "tag", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Invalid field tag: {$tag}\"", ")", ";", "}", "return", "array_reduce", "(", "$", "this", "->", "getFields", "(", "$", "tag", ")", ",", "function", "(", "$", "maxOccurrence", ",", "Field", "$", "field", ")", "{", "if", "(", "$", "field", "->", "getOccurrence", "(", ")", ">", "$", "maxOccurrence", "||", "$", "maxOccurrence", "===", "null", ")", "{", "return", "$", "field", "->", "getOccurrence", "(", ")", ";", "}", "else", "{", "return", "$", "maxOccurrence", ";", "}", "}", ",", "null", ")", ";", "}" ]
Return the maximum occurrence value of a field. @throws InvalidArgumentException Invalid field tag @param string $tag Field tag @return int|null Maximum occurrence of field or NULL if field does not exist
[ "Return", "the", "maximum", "occurrence", "value", "of", "a", "field", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Record.php#L187-L200
train
dmj/PicaRecord
src/HAB/Pica/Record/Record.php
Record.getFirstMatchingField
public function getFirstMatchingField ($selector) { $fields = $this->getFields($selector); if (empty($fields)) { return null; } else { return reset($fields); } }
php
public function getFirstMatchingField ($selector) { $fields = $this->getFields($selector); if (empty($fields)) { return null; } else { return reset($fields); } }
[ "public", "function", "getFirstMatchingField", "(", "$", "selector", ")", "{", "$", "fields", "=", "$", "this", "->", "getFields", "(", "$", "selector", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", ")", "{", "return", "null", ";", "}", "else", "{", "return", "reset", "(", "$", "fields", ")", ";", "}", "}" ]
Return the first field that matches a selector. @param string $selector Body of regular expression @return Field|null The first matching field or NULL if no match
[ "Return", "the", "first", "field", "that", "matches", "a", "selector", "." ]
bd5577b9a4333aa6156398b94cc870a9377061b8
https://github.com/dmj/PicaRecord/blob/bd5577b9a4333aa6156398b94cc870a9377061b8/src/HAB/Pica/Record/Record.php#L254-L262
train
FuzeWorks/Core
src/FuzeWorks/Helpers.php
Helpers.load
public function load($helperName, $directory = null): bool { // First determine the name of the helper $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName).'_helper'); // Determine what directories should be checked $directories = (is_null($directory) ? $this->helperPaths : array($directory)); // Check it is already loaded if (isset($this->helpers[$helperName])) { Logger::log("Helper '".$helperName."' is already loaded. Skipping"); return false; } // First check if there is an 'extension' class $extendedHelper = Factory::getInstance()->config->get('main')->application_prefix . $helperName; $extendedHelperLoaded = false; foreach ($directories as $helperPath) { $file = $helperPath . DS . $extendedHelper . '.php'; if (file_exists($file)) { $extendedHelperLoaded = true; $extendedHelperFile = $file; } } // If an extension is loaded there needs to be a base helper if ($extendedHelperLoaded) { $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName.'.php'; if (!file_exists($baseHelper)) { throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1); } // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once($event->extendedHelperFile); include_once($event->helperFile); $this->helpers[$event->helperName] = true; Logger::log("Loading base helper '".$event->helperName."' and extended helper '".$event->extendedHelperName."'"); return true; } // If no extension exists, try loading a regular helper foreach ($directories as $helperPath) { $file = $helperPath . DS . $helperName . '.php'; if (file_exists($file)) { // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $file); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once($event->helperFile); $this->helpers[$event->helperName] = true; Logger::log("Loading helper '".$event->helperName."'"); return true; } } throw new HelperException("Could not load helper. Helper not found.", 1); }
php
public function load($helperName, $directory = null): bool { // First determine the name of the helper $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName).'_helper'); // Determine what directories should be checked $directories = (is_null($directory) ? $this->helperPaths : array($directory)); // Check it is already loaded if (isset($this->helpers[$helperName])) { Logger::log("Helper '".$helperName."' is already loaded. Skipping"); return false; } // First check if there is an 'extension' class $extendedHelper = Factory::getInstance()->config->get('main')->application_prefix . $helperName; $extendedHelperLoaded = false; foreach ($directories as $helperPath) { $file = $helperPath . DS . $extendedHelper . '.php'; if (file_exists($file)) { $extendedHelperLoaded = true; $extendedHelperFile = $file; } } // If an extension is loaded there needs to be a base helper if ($extendedHelperLoaded) { $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName.'.php'; if (!file_exists($baseHelper)) { throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1); } // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once($event->extendedHelperFile); include_once($event->helperFile); $this->helpers[$event->helperName] = true; Logger::log("Loading base helper '".$event->helperName."' and extended helper '".$event->extendedHelperName."'"); return true; } // If no extension exists, try loading a regular helper foreach ($directories as $helperPath) { $file = $helperPath . DS . $helperName . '.php'; if (file_exists($file)) { // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $file); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once($event->helperFile); $this->helpers[$event->helperName] = true; Logger::log("Loading helper '".$event->helperName."'"); return true; } } throw new HelperException("Could not load helper. Helper not found.", 1); }
[ "public", "function", "load", "(", "$", "helperName", ",", "$", "directory", "=", "null", ")", ":", "bool", "{", "// First determine the name of the helper", "$", "helperName", "=", "strtolower", "(", "str_replace", "(", "array", "(", "'_helper'", ",", "'.php'", ")", ",", "''", ",", "$", "helperName", ")", ".", "'_helper'", ")", ";", "// Determine what directories should be checked", "$", "directories", "=", "(", "is_null", "(", "$", "directory", ")", "?", "$", "this", "->", "helperPaths", ":", "array", "(", "$", "directory", ")", ")", ";", "// Check it is already loaded", "if", "(", "isset", "(", "$", "this", "->", "helpers", "[", "$", "helperName", "]", ")", ")", "{", "Logger", "::", "log", "(", "\"Helper '\"", ".", "$", "helperName", ".", "\"' is already loaded. Skipping\"", ")", ";", "return", "false", ";", "}", "// First check if there is an 'extension' class", "$", "extendedHelper", "=", "Factory", "::", "getInstance", "(", ")", "->", "config", "->", "get", "(", "'main'", ")", "->", "application_prefix", ".", "$", "helperName", ";", "$", "extendedHelperLoaded", "=", "false", ";", "foreach", "(", "$", "directories", "as", "$", "helperPath", ")", "{", "$", "file", "=", "$", "helperPath", ".", "DS", ".", "$", "extendedHelper", ".", "'.php'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "extendedHelperLoaded", "=", "true", ";", "$", "extendedHelperFile", "=", "$", "file", ";", "}", "}", "// If an extension is loaded there needs to be a base helper", "if", "(", "$", "extendedHelperLoaded", ")", "{", "$", "baseHelper", "=", "Core", "::", "$", "coreDir", ".", "DS", ".", "'Helpers'", ".", "DS", ".", "$", "helperName", ".", "'.php'", ";", "if", "(", "!", "file_exists", "(", "$", "baseHelper", ")", ")", "{", "throw", "new", "HelperException", "(", "\"Could not load helper. Base Helper not found while Extension loaded\"", ",", "1", ")", ";", "}", "// Fire the associated event", "$", "event", "=", "Events", "::", "fireEvent", "(", "'helperLoadEvent'", ",", "$", "helperName", ",", "$", "baseHelper", ",", "$", "extendedHelper", ",", "$", "extendedHelperFile", ")", ";", "if", "(", "$", "event", "->", "isCancelled", "(", ")", ")", "{", "Logger", "::", "log", "(", "\"Not loading helper. Aborted by event\"", ")", ";", "return", "false", ";", "}", "include_once", "(", "$", "event", "->", "extendedHelperFile", ")", ";", "include_once", "(", "$", "event", "->", "helperFile", ")", ";", "$", "this", "->", "helpers", "[", "$", "event", "->", "helperName", "]", "=", "true", ";", "Logger", "::", "log", "(", "\"Loading base helper '\"", ".", "$", "event", "->", "helperName", ".", "\"' and extended helper '\"", ".", "$", "event", "->", "extendedHelperName", ".", "\"'\"", ")", ";", "return", "true", ";", "}", "// If no extension exists, try loading a regular helper", "foreach", "(", "$", "directories", "as", "$", "helperPath", ")", "{", "$", "file", "=", "$", "helperPath", ".", "DS", ".", "$", "helperName", ".", "'.php'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "// Fire the associated event", "$", "event", "=", "Events", "::", "fireEvent", "(", "'helperLoadEvent'", ",", "$", "helperName", ",", "$", "file", ")", ";", "if", "(", "$", "event", "->", "isCancelled", "(", ")", ")", "{", "Logger", "::", "log", "(", "\"Not loading helper. Aborted by event\"", ")", ";", "return", "false", ";", "}", "include_once", "(", "$", "event", "->", "helperFile", ")", ";", "$", "this", "->", "helpers", "[", "$", "event", "->", "helperName", "]", "=", "true", ";", "Logger", "::", "log", "(", "\"Loading helper '\"", ".", "$", "event", "->", "helperName", ".", "\"'\"", ")", ";", "return", "true", ";", "}", "}", "throw", "new", "HelperException", "(", "\"Could not load helper. Helper not found.\"", ",", "1", ")", ";", "}" ]
Load a helper. Supply the name and the helper will be loaded from the supplied directory, or from one of the helperPaths (which you can add). @param string $helperName Name of the helper @param string|null $directory Directory to load the helper from, will ignore $helperPaths @return bool Whether the helper was succesfully loaded (true if yes)
[ "Load", "a", "helper", "." ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Helpers.php#L92-L167
train
FuzeWorks/Core
src/FuzeWorks/Helpers.php
Helpers.removeHelperPath
public function removeHelperPath($directory) { if (($key = array_search($directory, $this->helperPaths)) !== false) { unset($this->helperPaths[$key]); } }
php
public function removeHelperPath($directory) { if (($key = array_search($directory, $this->helperPaths)) !== false) { unset($this->helperPaths[$key]); } }
[ "public", "function", "removeHelperPath", "(", "$", "directory", ")", "{", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "directory", ",", "$", "this", "->", "helperPaths", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "helperPaths", "[", "$", "key", "]", ")", ";", "}", "}" ]
Remove a path where helpers can be found @param string $directory The directory @return void
[ "Remove", "a", "path", "where", "helpers", "can", "be", "found" ]
051c64fdaa3a648174cbd54557d05ad553dd826b
https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Helpers.php#L202-L208
train
joegreen88/zf1-component-validate
src/Zend/Validate/Isbn.php
Zend_Validate_Isbn.setType
public function setType($type) { // check type if (!in_array($type, array(self::AUTO, self::ISBN10, self::ISBN13))) { /** * @see Zend_Validate_Exception */ throw new Zend_Validate_Exception('Invalid ISBN type'); } $this->_type = $type; return $this; }
php
public function setType($type) { // check type if (!in_array($type, array(self::AUTO, self::ISBN10, self::ISBN13))) { /** * @see Zend_Validate_Exception */ throw new Zend_Validate_Exception('Invalid ISBN type'); } $this->_type = $type; return $this; }
[ "public", "function", "setType", "(", "$", "type", ")", "{", "// check type", "if", "(", "!", "in_array", "(", "$", "type", ",", "array", "(", "self", "::", "AUTO", ",", "self", "::", "ISBN10", ",", "self", "::", "ISBN13", ")", ")", ")", "{", "/**\n * @see Zend_Validate_Exception\n */", "throw", "new", "Zend_Validate_Exception", "(", "'Invalid ISBN type'", ")", ";", "}", "$", "this", "->", "_type", "=", "$", "type", ";", "return", "$", "this", ";", "}" ]
Set allowed ISBN type. @param string $type @throws Zend_Validate_Exception When $type is not valid @return Zend_Validate_Isbn Provides a fluent interface
[ "Set", "allowed", "ISBN", "type", "." ]
88d9ea016f73d48ff0ba7d06ecbbf28951fd279e
https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Isbn.php#L255-L268
train
RudyMas/Emvc_Menu
src/Menu.php
Menu.setBootstrapBrandImage
public function setBootstrapBrandImage(string $link, int $size = 30): void { $this->bootstrapOptions['brand']['image']['link'] = $link; $this->bootstrapOptions['brand']['image']['size'] = $size; }
php
public function setBootstrapBrandImage(string $link, int $size = 30): void { $this->bootstrapOptions['brand']['image']['link'] = $link; $this->bootstrapOptions['brand']['image']['size'] = $size; }
[ "public", "function", "setBootstrapBrandImage", "(", "string", "$", "link", ",", "int", "$", "size", "=", "30", ")", ":", "void", "{", "$", "this", "->", "bootstrapOptions", "[", "'brand'", "]", "[", "'image'", "]", "[", "'link'", "]", "=", "$", "link", ";", "$", "this", "->", "bootstrapOptions", "[", "'brand'", "]", "[", "'image'", "]", "[", "'size'", "]", "=", "$", "size", ";", "}" ]
Set Bootstrap brand image @param string $link @param int $size
[ "Set", "Bootstrap", "brand", "image" ]
5765ec7e7193866de19e7a039a347ac4ed3bf952
https://github.com/RudyMas/Emvc_Menu/blob/5765ec7e7193866de19e7a039a347ac4ed3bf952/src/Menu.php#L174-L178
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/ContainerBuilder.php
ContainerBuilder.getReflectionClass
public function getReflectionClass($class, $throw = true) { if (!$class = $this->getParameterBag()->resolveValue($class)) { return; } if (isset(self::$internalTypes[$class])) { return null; } $resource = null; try { if (isset($this->classReflectors[$class])) { $classReflector = $this->classReflectors[$class]; } elseif ($this->trackResources) { $resource = new ClassExistenceResource($class, false); $classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class); } else { $classReflector = new \ReflectionClass($class); } } catch (\ReflectionException $e) { if ($throw) { throw $e; } $classReflector = false; } if ($this->trackResources) { if (!$classReflector) { $this->addResource($resource ?: new ClassExistenceResource($class, false)); } elseif (!$classReflector->isInternal()) { $path = $classReflector->getFileName(); if (!$this->inVendors($path)) { $this->addResource(new ReflectionClassResource($classReflector, $this->vendors)); } } $this->classReflectors[$class] = $classReflector; } return $classReflector ?: null; }
php
public function getReflectionClass($class, $throw = true) { if (!$class = $this->getParameterBag()->resolveValue($class)) { return; } if (isset(self::$internalTypes[$class])) { return null; } $resource = null; try { if (isset($this->classReflectors[$class])) { $classReflector = $this->classReflectors[$class]; } elseif ($this->trackResources) { $resource = new ClassExistenceResource($class, false); $classReflector = $resource->isFresh(0) ? false : new \ReflectionClass($class); } else { $classReflector = new \ReflectionClass($class); } } catch (\ReflectionException $e) { if ($throw) { throw $e; } $classReflector = false; } if ($this->trackResources) { if (!$classReflector) { $this->addResource($resource ?: new ClassExistenceResource($class, false)); } elseif (!$classReflector->isInternal()) { $path = $classReflector->getFileName(); if (!$this->inVendors($path)) { $this->addResource(new ReflectionClassResource($classReflector, $this->vendors)); } } $this->classReflectors[$class] = $classReflector; } return $classReflector ?: null; }
[ "public", "function", "getReflectionClass", "(", "$", "class", ",", "$", "throw", "=", "true", ")", "{", "if", "(", "!", "$", "class", "=", "$", "this", "->", "getParameterBag", "(", ")", "->", "resolveValue", "(", "$", "class", ")", ")", "{", "return", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "internalTypes", "[", "$", "class", "]", ")", ")", "{", "return", "null", ";", "}", "$", "resource", "=", "null", ";", "try", "{", "if", "(", "isset", "(", "$", "this", "->", "classReflectors", "[", "$", "class", "]", ")", ")", "{", "$", "classReflector", "=", "$", "this", "->", "classReflectors", "[", "$", "class", "]", ";", "}", "elseif", "(", "$", "this", "->", "trackResources", ")", "{", "$", "resource", "=", "new", "ClassExistenceResource", "(", "$", "class", ",", "false", ")", ";", "$", "classReflector", "=", "$", "resource", "->", "isFresh", "(", "0", ")", "?", "false", ":", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "}", "else", "{", "$", "classReflector", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "}", "}", "catch", "(", "\\", "ReflectionException", "$", "e", ")", "{", "if", "(", "$", "throw", ")", "{", "throw", "$", "e", ";", "}", "$", "classReflector", "=", "false", ";", "}", "if", "(", "$", "this", "->", "trackResources", ")", "{", "if", "(", "!", "$", "classReflector", ")", "{", "$", "this", "->", "addResource", "(", "$", "resource", "?", ":", "new", "ClassExistenceResource", "(", "$", "class", ",", "false", ")", ")", ";", "}", "elseif", "(", "!", "$", "classReflector", "->", "isInternal", "(", ")", ")", "{", "$", "path", "=", "$", "classReflector", "->", "getFileName", "(", ")", ";", "if", "(", "!", "$", "this", "->", "inVendors", "(", "$", "path", ")", ")", "{", "$", "this", "->", "addResource", "(", "new", "ReflectionClassResource", "(", "$", "classReflector", ",", "$", "this", "->", "vendors", ")", ")", ";", "}", "}", "$", "this", "->", "classReflectors", "[", "$", "class", "]", "=", "$", "classReflector", ";", "}", "return", "$", "classReflector", "?", ":", "null", ";", "}" ]
Retrieves the requested reflection class and registers it for resource tracking. @param string $class @param bool $throw @return \ReflectionClass|null @throws \ReflectionException when a parent class/interface/trait is not found and $throw is true @final
[ "Retrieves", "the", "requested", "reflection", "class", "and", "registers", "it", "for", "resource", "tracking", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/ContainerBuilder.php#L353-L395
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/ContainerBuilder.php
ContainerBuilder.fileExists
public function fileExists($path, $trackContents = true) { $exists = file_exists($path); if (!$this->trackResources || $this->inVendors($path)) { return $exists; } if (!$exists) { $this->addResource(new FileExistenceResource($path)); return $exists; } if (is_dir($path)) { if ($trackContents) { $this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null)); } else { $this->addResource(new GlobResource($path, '/*', false)); } } elseif ($trackContents) { $this->addResource(new FileResource($path)); } return $exists; }
php
public function fileExists($path, $trackContents = true) { $exists = file_exists($path); if (!$this->trackResources || $this->inVendors($path)) { return $exists; } if (!$exists) { $this->addResource(new FileExistenceResource($path)); return $exists; } if (is_dir($path)) { if ($trackContents) { $this->addResource(new DirectoryResource($path, is_string($trackContents) ? $trackContents : null)); } else { $this->addResource(new GlobResource($path, '/*', false)); } } elseif ($trackContents) { $this->addResource(new FileResource($path)); } return $exists; }
[ "public", "function", "fileExists", "(", "$", "path", ",", "$", "trackContents", "=", "true", ")", "{", "$", "exists", "=", "file_exists", "(", "$", "path", ")", ";", "if", "(", "!", "$", "this", "->", "trackResources", "||", "$", "this", "->", "inVendors", "(", "$", "path", ")", ")", "{", "return", "$", "exists", ";", "}", "if", "(", "!", "$", "exists", ")", "{", "$", "this", "->", "addResource", "(", "new", "FileExistenceResource", "(", "$", "path", ")", ")", ";", "return", "$", "exists", ";", "}", "if", "(", "is_dir", "(", "$", "path", ")", ")", "{", "if", "(", "$", "trackContents", ")", "{", "$", "this", "->", "addResource", "(", "new", "DirectoryResource", "(", "$", "path", ",", "is_string", "(", "$", "trackContents", ")", "?", "$", "trackContents", ":", "null", ")", ")", ";", "}", "else", "{", "$", "this", "->", "addResource", "(", "new", "GlobResource", "(", "$", "path", ",", "'/*'", ",", "false", ")", ")", ";", "}", "}", "elseif", "(", "$", "trackContents", ")", "{", "$", "this", "->", "addResource", "(", "new", "FileResource", "(", "$", "path", ")", ")", ";", "}", "return", "$", "exists", ";", "}" ]
Checks whether the requested file or directory exists and registers the result for resource tracking. @param string $path The file or directory path for which to check the existence @param bool|string $trackContents Whether to track contents of the given resource. If a string is passed, it will be used as pattern for tracking contents of the requested directory @return bool @final
[ "Checks", "whether", "the", "requested", "file", "or", "directory", "exists", "and", "registers", "the", "result", "for", "resource", "tracking", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/ContainerBuilder.php#L408-L433
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/ContainerBuilder.php
ContainerBuilder.getServiceConditionals
public static function getServiceConditionals($value) { $services = array(); if (is_array($value)) { foreach ($value as $v) { $services = array_unique(array_merge($services, self::getServiceConditionals($v))); } } elseif ($value instanceof Reference && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) { $services[] = (string) $value; } return $services; }
php
public static function getServiceConditionals($value) { $services = array(); if (is_array($value)) { foreach ($value as $v) { $services = array_unique(array_merge($services, self::getServiceConditionals($v))); } } elseif ($value instanceof Reference && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) { $services[] = (string) $value; } return $services; }
[ "public", "static", "function", "getServiceConditionals", "(", "$", "value", ")", "{", "$", "services", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "$", "services", "=", "array_unique", "(", "array_merge", "(", "$", "services", ",", "self", "::", "getServiceConditionals", "(", "$", "v", ")", ")", ")", ";", "}", "}", "elseif", "(", "$", "value", "instanceof", "Reference", "&&", "ContainerInterface", "::", "IGNORE_ON_INVALID_REFERENCE", "===", "$", "value", "->", "getInvalidBehavior", "(", ")", ")", "{", "$", "services", "[", "]", "=", "(", "string", ")", "$", "value", ";", "}", "return", "$", "services", ";", "}" ]
Returns the Service Conditionals. @param mixed $value An array of conditionals to return @return array An array of Service conditionals @internal since version 3.4
[ "Returns", "the", "Service", "Conditionals", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/ContainerBuilder.php#L1506-L1519
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/ContainerBuilder.php
ContainerBuilder.getInitializedConditionals
public static function getInitializedConditionals($value) { $services = array(); if (is_array($value)) { foreach ($value as $v) { $services = array_unique(array_merge($services, self::getInitializedConditionals($v))); } } elseif ($value instanceof Reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior()) { $services[] = (string) $value; } return $services; }
php
public static function getInitializedConditionals($value) { $services = array(); if (is_array($value)) { foreach ($value as $v) { $services = array_unique(array_merge($services, self::getInitializedConditionals($v))); } } elseif ($value instanceof Reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior()) { $services[] = (string) $value; } return $services; }
[ "public", "static", "function", "getInitializedConditionals", "(", "$", "value", ")", "{", "$", "services", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "$", "services", "=", "array_unique", "(", "array_merge", "(", "$", "services", ",", "self", "::", "getInitializedConditionals", "(", "$", "v", ")", ")", ")", ";", "}", "}", "elseif", "(", "$", "value", "instanceof", "Reference", "&&", "ContainerInterface", "::", "IGNORE_ON_UNINITIALIZED_REFERENCE", "===", "$", "value", "->", "getInvalidBehavior", "(", ")", ")", "{", "$", "services", "[", "]", "=", "(", "string", ")", "$", "value", ";", "}", "return", "$", "services", ";", "}" ]
Returns the initialized conditionals. @param mixed $value An array of conditionals to return @return array An array of uninitialized conditionals @internal
[ "Returns", "the", "initialized", "conditionals", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/ContainerBuilder.php#L1530-L1543
train
zhaoxianfang/tools
src/Symfony/Component/DependencyInjection/ContainerBuilder.php
ContainerBuilder.hash
public static function hash($value) { $hash = substr(base64_encode(hash('sha256', serialize($value), true)), 0, 7); return str_replace(array('/', '+'), array('.', '_'), strtolower($hash)); }
php
public static function hash($value) { $hash = substr(base64_encode(hash('sha256', serialize($value), true)), 0, 7); return str_replace(array('/', '+'), array('.', '_'), strtolower($hash)); }
[ "public", "static", "function", "hash", "(", "$", "value", ")", "{", "$", "hash", "=", "substr", "(", "base64_encode", "(", "hash", "(", "'sha256'", ",", "serialize", "(", "$", "value", ")", ",", "true", ")", ")", ",", "0", ",", "7", ")", ";", "return", "str_replace", "(", "array", "(", "'/'", ",", "'+'", ")", ",", "array", "(", "'.'", ",", "'_'", ")", ",", "strtolower", "(", "$", "hash", ")", ")", ";", "}" ]
Computes a reasonably unique hash of a value. @param mixed $value A serializable value @return string
[ "Computes", "a", "reasonably", "unique", "hash", "of", "a", "value", "." ]
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/ContainerBuilder.php#L1552-L1557
train
facile-it/sentry-common
src/StackTrace/StackTrace.php
StackTrace.getExceptions
public function getExceptions(\Throwable $exception): array { $exc = $exception; do { $exc_data = [ 'value' => $this->serializer->serialize($exc->getMessage()), 'type' => get_class($exc), ]; /**'exception' * Exception::getTrace doesn't store the point at where the exception * was thrown, so we have to stuff it in ourselves. Ugh. */ $trace = $exc->getTrace(); $frame_where_exception_thrown = [ 'file' => $exc->getFile(), 'line' => $exc->getLine(), ]; array_unshift($trace, $frame_where_exception_thrown); $exc_data['stacktrace'] = [ 'frames' => $this->getStackTraceFrames($trace), ]; $exceptions[] = $exc_data; } while ($exc = $exc->getPrevious()); return array_reverse($exceptions); }
php
public function getExceptions(\Throwable $exception): array { $exc = $exception; do { $exc_data = [ 'value' => $this->serializer->serialize($exc->getMessage()), 'type' => get_class($exc), ]; /**'exception' * Exception::getTrace doesn't store the point at where the exception * was thrown, so we have to stuff it in ourselves. Ugh. */ $trace = $exc->getTrace(); $frame_where_exception_thrown = [ 'file' => $exc->getFile(), 'line' => $exc->getLine(), ]; array_unshift($trace, $frame_where_exception_thrown); $exc_data['stacktrace'] = [ 'frames' => $this->getStackTraceFrames($trace), ]; $exceptions[] = $exc_data; } while ($exc = $exc->getPrevious()); return array_reverse($exceptions); }
[ "public", "function", "getExceptions", "(", "\\", "Throwable", "$", "exception", ")", ":", "array", "{", "$", "exc", "=", "$", "exception", ";", "do", "{", "$", "exc_data", "=", "[", "'value'", "=>", "$", "this", "->", "serializer", "->", "serialize", "(", "$", "exc", "->", "getMessage", "(", ")", ")", ",", "'type'", "=>", "get_class", "(", "$", "exc", ")", ",", "]", ";", "/**'exception'\n * Exception::getTrace doesn't store the point at where the exception\n * was thrown, so we have to stuff it in ourselves. Ugh.\n */", "$", "trace", "=", "$", "exc", "->", "getTrace", "(", ")", ";", "$", "frame_where_exception_thrown", "=", "[", "'file'", "=>", "$", "exc", "->", "getFile", "(", ")", ",", "'line'", "=>", "$", "exc", "->", "getLine", "(", ")", ",", "]", ";", "array_unshift", "(", "$", "trace", ",", "$", "frame_where_exception_thrown", ")", ";", "$", "exc_data", "[", "'stacktrace'", "]", "=", "[", "'frames'", "=>", "$", "this", "->", "getStackTraceFrames", "(", "$", "trace", ")", ",", "]", ";", "$", "exceptions", "[", "]", "=", "$", "exc_data", ";", "}", "while", "(", "$", "exc", "=", "$", "exc", "->", "getPrevious", "(", ")", ")", ";", "return", "array_reverse", "(", "$", "exceptions", ")", ";", "}" ]
Generate exceptions data for Sentry @param \Throwable $exception @return array
[ "Generate", "exceptions", "data", "for", "Sentry" ]
63ca40700e19363e6af94c69ef8f0f889ba031bd
https://github.com/facile-it/sentry-common/blob/63ca40700e19363e6af94c69ef8f0f889ba031bd/src/StackTrace/StackTrace.php#L66-L95
train
facile-it/sentry-common
src/StackTrace/StackTrace.php
StackTrace.getStackTraceFrames
public function getStackTraceFrames(array $trace): array { return \Raven_Stacktrace::get_stack_info( $trace, $this->client->trace, [], $this->client->message_limit, $this->client->getPrefixes(), $this->client->getAppPath(), $this->client->getExcludedAppPaths(), $this->serializer, $this->reprSerializer ); }
php
public function getStackTraceFrames(array $trace): array { return \Raven_Stacktrace::get_stack_info( $trace, $this->client->trace, [], $this->client->message_limit, $this->client->getPrefixes(), $this->client->getAppPath(), $this->client->getExcludedAppPaths(), $this->serializer, $this->reprSerializer ); }
[ "public", "function", "getStackTraceFrames", "(", "array", "$", "trace", ")", ":", "array", "{", "return", "\\", "Raven_Stacktrace", "::", "get_stack_info", "(", "$", "trace", ",", "$", "this", "->", "client", "->", "trace", ",", "[", "]", ",", "$", "this", "->", "client", "->", "message_limit", ",", "$", "this", "->", "client", "->", "getPrefixes", "(", ")", ",", "$", "this", "->", "client", "->", "getAppPath", "(", ")", ",", "$", "this", "->", "client", "->", "getExcludedAppPaths", "(", ")", ",", "$", "this", "->", "serializer", ",", "$", "this", "->", "reprSerializer", ")", ";", "}" ]
Generate StackTrace frames for Sentry @param array $trace @return array
[ "Generate", "StackTrace", "frames", "for", "Sentry" ]
63ca40700e19363e6af94c69ef8f0f889ba031bd
https://github.com/facile-it/sentry-common/blob/63ca40700e19363e6af94c69ef8f0f889ba031bd/src/StackTrace/StackTrace.php#L103-L116
train
facile-it/sentry-common
src/StackTrace/StackTrace.php
StackTrace.cleanBacktrace
public function cleanBacktrace(array $trace): array { // find first not removable index $firstNotRemovable = 0; foreach ($trace as $index => $item) { if (! $this->shouldRemoveStack($item)) { $firstNotRemovable = $index; break; } } $trace = array_slice($trace, $firstNotRemovable ?: 0); return $trace; }
php
public function cleanBacktrace(array $trace): array { // find first not removable index $firstNotRemovable = 0; foreach ($trace as $index => $item) { if (! $this->shouldRemoveStack($item)) { $firstNotRemovable = $index; break; } } $trace = array_slice($trace, $firstNotRemovable ?: 0); return $trace; }
[ "public", "function", "cleanBacktrace", "(", "array", "$", "trace", ")", ":", "array", "{", "// find first not removable index", "$", "firstNotRemovable", "=", "0", ";", "foreach", "(", "$", "trace", "as", "$", "index", "=>", "$", "item", ")", "{", "if", "(", "!", "$", "this", "->", "shouldRemoveStack", "(", "$", "item", ")", ")", "{", "$", "firstNotRemovable", "=", "$", "index", ";", "break", ";", "}", "}", "$", "trace", "=", "array_slice", "(", "$", "trace", ",", "$", "firstNotRemovable", "?", ":", "0", ")", ";", "return", "$", "trace", ";", "}" ]
Remove stacks until the stack is from outside the logging context based on namespaces to ignore. @param array $trace @return array
[ "Remove", "stacks", "until", "the", "stack", "is", "from", "outside", "the", "logging", "context", "based", "on", "namespaces", "to", "ignore", "." ]
63ca40700e19363e6af94c69ef8f0f889ba031bd
https://github.com/facile-it/sentry-common/blob/63ca40700e19363e6af94c69ef8f0f889ba031bd/src/StackTrace/StackTrace.php#L124-L138
train
facile-it/sentry-common
src/StackTrace/StackTrace.php
StackTrace.shouldRemoveStack
private function shouldRemoveStack(array $stack): bool { if (empty($stack['class'])) { return false; } foreach ($this->ignoreBacktraceNamespaces as $namespace) { if (0 === strpos($stack['class'], $namespace)) { return true; } } return false; }
php
private function shouldRemoveStack(array $stack): bool { if (empty($stack['class'])) { return false; } foreach ($this->ignoreBacktraceNamespaces as $namespace) { if (0 === strpos($stack['class'], $namespace)) { return true; } } return false; }
[ "private", "function", "shouldRemoveStack", "(", "array", "$", "stack", ")", ":", "bool", "{", "if", "(", "empty", "(", "$", "stack", "[", "'class'", "]", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "ignoreBacktraceNamespaces", "as", "$", "namespace", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "stack", "[", "'class'", "]", ",", "$", "namespace", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Should the stack be removed? @param array $stack @return bool
[ "Should", "the", "stack", "be", "removed?" ]
63ca40700e19363e6af94c69ef8f0f889ba031bd
https://github.com/facile-it/sentry-common/blob/63ca40700e19363e6af94c69ef8f0f889ba031bd/src/StackTrace/StackTrace.php#L146-L159
train
ddvphp/weibo
src/Weibo/SaeTOAuthV2.php
SaeTOAuthV2.post
function post($url, $parameters = array(), $multi = false) { $response = $this->oAuthRequest($url, 'POST', $parameters, $multi ); if ($this->format === 'json' && $this->decode_json) { return json_decode($response, true); } return $response; }
php
function post($url, $parameters = array(), $multi = false) { $response = $this->oAuthRequest($url, 'POST', $parameters, $multi ); if ($this->format === 'json' && $this->decode_json) { return json_decode($response, true); } return $response; }
[ "function", "post", "(", "$", "url", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "multi", "=", "false", ")", "{", "$", "response", "=", "$", "this", "->", "oAuthRequest", "(", "$", "url", ",", "'POST'", ",", "$", "parameters", ",", "$", "multi", ")", ";", "if", "(", "$", "this", "->", "format", "===", "'json'", "&&", "$", "this", "->", "decode_json", ")", "{", "return", "json_decode", "(", "$", "response", ",", "true", ")", ";", "}", "return", "$", "response", ";", "}" ]
POST wreapper for oAuthRequest. @return mixed
[ "POST", "wreapper", "for", "oAuthRequest", "." ]
4940f27fbb88e0a1e419ee56399715ad1658f31c
https://github.com/ddvphp/weibo/blob/4940f27fbb88e0a1e419ee56399715ad1658f31c/src/Weibo/SaeTOAuthV2.php#L283-L289
train
ddvphp/weibo
src/Weibo/SaeTOAuthV2.php
SaeTOAuthV2.delete
function delete($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'DELETE', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response, true); } return $response; }
php
function delete($url, $parameters = array()) { $response = $this->oAuthRequest($url, 'DELETE', $parameters); if ($this->format === 'json' && $this->decode_json) { return json_decode($response, true); } return $response; }
[ "function", "delete", "(", "$", "url", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "$", "response", "=", "$", "this", "->", "oAuthRequest", "(", "$", "url", ",", "'DELETE'", ",", "$", "parameters", ")", ";", "if", "(", "$", "this", "->", "format", "===", "'json'", "&&", "$", "this", "->", "decode_json", ")", "{", "return", "json_decode", "(", "$", "response", ",", "true", ")", ";", "}", "return", "$", "response", ";", "}" ]
DELTE wrapper for oAuthReqeust. @return mixed
[ "DELTE", "wrapper", "for", "oAuthReqeust", "." ]
4940f27fbb88e0a1e419ee56399715ad1658f31c
https://github.com/ddvphp/weibo/blob/4940f27fbb88e0a1e419ee56399715ad1658f31c/src/Weibo/SaeTOAuthV2.php#L296-L302
train
modulusphp/utility
Variable.php
Variable.has
public static function has(string $name, ?string $syntax = null) { if (isset($_SESSION['application']['with'][$name])) { $_SESSION['application']['flash']['used'] = true; $name = $_SESSION['application']['with'][$name]; return $syntax ? str_replace(':message', $name, $syntax) : true; } return isset(Variable::$data[$name]) ? ($syntax ? str_replace(':message', Variable::$data[$name], $syntax) : true) : false; }
php
public static function has(string $name, ?string $syntax = null) { if (isset($_SESSION['application']['with'][$name])) { $_SESSION['application']['flash']['used'] = true; $name = $_SESSION['application']['with'][$name]; return $syntax ? str_replace(':message', $name, $syntax) : true; } return isset(Variable::$data[$name]) ? ($syntax ? str_replace(':message', Variable::$data[$name], $syntax) : true) : false; }
[ "public", "static", "function", "has", "(", "string", "$", "name", ",", "?", "string", "$", "syntax", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'application'", "]", "[", "'with'", "]", "[", "$", "name", "]", ")", ")", "{", "$", "_SESSION", "[", "'application'", "]", "[", "'flash'", "]", "[", "'used'", "]", "=", "true", ";", "$", "name", "=", "$", "_SESSION", "[", "'application'", "]", "[", "'with'", "]", "[", "$", "name", "]", ";", "return", "$", "syntax", "?", "str_replace", "(", "':message'", ",", "$", "name", ",", "$", "syntax", ")", ":", "true", ";", "}", "return", "isset", "(", "Variable", "::", "$", "data", "[", "$", "name", "]", ")", "?", "(", "$", "syntax", "?", "str_replace", "(", "':message'", ",", "Variable", "::", "$", "data", "[", "$", "name", "]", ",", "$", "syntax", ")", ":", "true", ")", ":", "false", ";", "}" ]
Check if variables exists @param string $name @param null|string $syntax @return mixed
[ "Check", "if", "variables", "exists" ]
c1e127539b13d3ec8381e41c64b881e0701807f5
https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Variable.php#L25-L36
train
Raphhh/puppy-application
src/Service/ServiceContainer.php
ServiceContainer.getService
public function getService($service) { if (!isset($this->services[$service])) { throw new \InvalidArgumentException(sprintf('Service %s not found', $service)); } return $this->services[$service]; }
php
public function getService($service) { if (!isset($this->services[$service])) { throw new \InvalidArgumentException(sprintf('Service %s not found', $service)); } return $this->services[$service]; }
[ "public", "function", "getService", "(", "$", "service", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "services", "[", "$", "service", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Service %s not found'", ",", "$", "service", ")", ")", ";", "}", "return", "$", "this", "->", "services", "[", "$", "service", "]", ";", "}" ]
Getter of a service @param string $service @throws \InvalidArgumentException @return mixed
[ "Getter", "of", "a", "service" ]
9291543cd28e19a2986abd7fb146898ca5f5f5da
https://github.com/Raphhh/puppy-application/blob/9291543cd28e19a2986abd7fb146898ca5f5f5da/src/Service/ServiceContainer.php#L44-L50
train
RSQueue/RSQueue
src/RSQueue/Services/Consumer.php
Consumer.consume
public function consume($queueAlias, $timeout = 0) { $queues = is_array($queueAlias) ? $this ->queueAliasResolver ->getQueues($queueAlias) : $this ->queueAliasResolver ->getQueue($queueAlias); $payloadArray = $this ->redis ->blPop( $queues, $timeout ); if (empty($payloadArray)) { return []; } list($givenQueue, $payloadSerialized) = $payloadArray; $payload = $this->serializer->revert($payloadSerialized); $givenQueueAlias = $this ->queueAliasResolver ->getQueueAliasByQueueName($givenQueue); /* * Dispatching consumer event... */ $consumerEvent = new RSQueueConsumerEvent( $payload, $payloadSerialized, $givenQueue, $this->redis ); $this ->eventDispatcher ->dispatch(RSQueueEvents::RSQUEUE_CONSUMER, $consumerEvent); return [$givenQueueAlias, $payload]; }
php
public function consume($queueAlias, $timeout = 0) { $queues = is_array($queueAlias) ? $this ->queueAliasResolver ->getQueues($queueAlias) : $this ->queueAliasResolver ->getQueue($queueAlias); $payloadArray = $this ->redis ->blPop( $queues, $timeout ); if (empty($payloadArray)) { return []; } list($givenQueue, $payloadSerialized) = $payloadArray; $payload = $this->serializer->revert($payloadSerialized); $givenQueueAlias = $this ->queueAliasResolver ->getQueueAliasByQueueName($givenQueue); /* * Dispatching consumer event... */ $consumerEvent = new RSQueueConsumerEvent( $payload, $payloadSerialized, $givenQueue, $this->redis ); $this ->eventDispatcher ->dispatch(RSQueueEvents::RSQUEUE_CONSUMER, $consumerEvent); return [$givenQueueAlias, $payload]; }
[ "public", "function", "consume", "(", "$", "queueAlias", ",", "$", "timeout", "=", "0", ")", "{", "$", "queues", "=", "is_array", "(", "$", "queueAlias", ")", "?", "$", "this", "->", "queueAliasResolver", "->", "getQueues", "(", "$", "queueAlias", ")", ":", "$", "this", "->", "queueAliasResolver", "->", "getQueue", "(", "$", "queueAlias", ")", ";", "$", "payloadArray", "=", "$", "this", "->", "redis", "->", "blPop", "(", "$", "queues", ",", "$", "timeout", ")", ";", "if", "(", "empty", "(", "$", "payloadArray", ")", ")", "{", "return", "[", "]", ";", "}", "list", "(", "$", "givenQueue", ",", "$", "payloadSerialized", ")", "=", "$", "payloadArray", ";", "$", "payload", "=", "$", "this", "->", "serializer", "->", "revert", "(", "$", "payloadSerialized", ")", ";", "$", "givenQueueAlias", "=", "$", "this", "->", "queueAliasResolver", "->", "getQueueAliasByQueueName", "(", "$", "givenQueue", ")", ";", "/*\n * Dispatching consumer event...\n */", "$", "consumerEvent", "=", "new", "RSQueueConsumerEvent", "(", "$", "payload", ",", "$", "payloadSerialized", ",", "$", "givenQueue", ",", "$", "this", "->", "redis", ")", ";", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "RSQueueEvents", "::", "RSQUEUE_CONSUMER", ",", "$", "consumerEvent", ")", ";", "return", "[", "$", "givenQueueAlias", ",", "$", "payload", "]", ";", "}" ]
Retrieve queue value, with a defined timeout. This method accepts a single queue alias or an array with alias Every new element will be popped from one of defined queue Also, new Consumer event is triggered everytime a new element is popped @param mixed $queueAlias Alias of queue to consume from ( Can be an array of alias ) @param int $timeout Timeout. By default, 0 @return array
[ "Retrieve", "queue", "value", "with", "a", "defined", "timeout", "." ]
1a8d72a2b025ed65684644febf9493d4f6ac9333
https://github.com/RSQueue/RSQueue/blob/1a8d72a2b025ed65684644febf9493d4f6ac9333/src/RSQueue/Services/Consumer.php#L44-L86
train
spartan/console
src/MultiChoice.php
MultiChoice.isSelected
protected function isSelected(): bool { $key = $this->choices[$this->line]['key']; return array_key_exists($key, $this->selections); }
php
protected function isSelected(): bool { $key = $this->choices[$this->line]['key']; return array_key_exists($key, $this->selections); }
[ "protected", "function", "isSelected", "(", ")", ":", "bool", "{", "$", "key", "=", "$", "this", "->", "choices", "[", "$", "this", "->", "line", "]", "[", "'key'", "]", ";", "return", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "selections", ")", ";", "}" ]
Check for current line @return bool
[ "Check", "for", "current", "line" ]
66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838
https://github.com/spartan/console/blob/66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838/src/MultiChoice.php#L140-L144
train
spartan/console
src/MultiChoice.php
MultiChoice.checkMissingParentsDependencies
protected function checkMissingParentsDependencies(array $choice): array { $missing = []; $depends = (array)$choice['depends']; foreach ($depends as $dependency) { if (!isset($this->selections[$dependency])) { foreach ($this->choices as $choice) { if (is_array($choice) && $choice['key'] == $dependency) { $missing[] = $choice['name']; break; } } } } return $missing; }
php
protected function checkMissingParentsDependencies(array $choice): array { $missing = []; $depends = (array)$choice['depends']; foreach ($depends as $dependency) { if (!isset($this->selections[$dependency])) { foreach ($this->choices as $choice) { if (is_array($choice) && $choice['key'] == $dependency) { $missing[] = $choice['name']; break; } } } } return $missing; }
[ "protected", "function", "checkMissingParentsDependencies", "(", "array", "$", "choice", ")", ":", "array", "{", "$", "missing", "=", "[", "]", ";", "$", "depends", "=", "(", "array", ")", "$", "choice", "[", "'depends'", "]", ";", "foreach", "(", "$", "depends", "as", "$", "dependency", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "selections", "[", "$", "dependency", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "choices", "as", "$", "choice", ")", "{", "if", "(", "is_array", "(", "$", "choice", ")", "&&", "$", "choice", "[", "'key'", "]", "==", "$", "dependency", ")", "{", "$", "missing", "[", "]", "=", "$", "choice", "[", "'name'", "]", ";", "break", ";", "}", "}", "}", "}", "return", "$", "missing", ";", "}" ]
Make sure all dependencies are already selected @param array $choice Checked choice @return array
[ "Make", "sure", "all", "dependencies", "are", "already", "selected" ]
66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838
https://github.com/spartan/console/blob/66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838/src/MultiChoice.php#L251-L266
train
Kris-Kuiper/sFire-Framework
autoload.php
Autoloader.addPsr4
public static function addPsr4($prefix, $base_dir, $prepend = false) { //Normalize namespace prefix $prefix = trim($prefix, '\\') . '\\'; //Normalize the base directory with a trailing separator $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; //Initialize the namespace prefix array if(false === isset(static :: $psr4[$prefix])) { static :: $psr4[$prefix] = []; } //Retain the base directory for the namespace prefix if(true === $prepend) { array_unshift(static :: $psr4[$prefix], $base_dir); } else { array_push(static :: $psr4[$prefix], $base_dir); } }
php
public static function addPsr4($prefix, $base_dir, $prepend = false) { //Normalize namespace prefix $prefix = trim($prefix, '\\') . '\\'; //Normalize the base directory with a trailing separator $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; //Initialize the namespace prefix array if(false === isset(static :: $psr4[$prefix])) { static :: $psr4[$prefix] = []; } //Retain the base directory for the namespace prefix if(true === $prepend) { array_unshift(static :: $psr4[$prefix], $base_dir); } else { array_push(static :: $psr4[$prefix], $base_dir); } }
[ "public", "static", "function", "addPsr4", "(", "$", "prefix", ",", "$", "base_dir", ",", "$", "prepend", "=", "false", ")", "{", "//Normalize namespace prefix\r", "$", "prefix", "=", "trim", "(", "$", "prefix", ",", "'\\\\'", ")", ".", "'\\\\'", ";", "//Normalize the base directory with a trailing separator\r", "$", "base_dir", "=", "rtrim", "(", "$", "base_dir", ",", "DIRECTORY_SEPARATOR", ")", ".", "'/'", ";", "//Initialize the namespace prefix array\r", "if", "(", "false", "===", "isset", "(", "static", "::", "$", "psr4", "[", "$", "prefix", "]", ")", ")", "{", "static", "::", "$", "psr4", "[", "$", "prefix", "]", "=", "[", "]", ";", "}", "//Retain the base directory for the namespace prefix\r", "if", "(", "true", "===", "$", "prepend", ")", "{", "array_unshift", "(", "static", "::", "$", "psr4", "[", "$", "prefix", "]", ",", "$", "base_dir", ")", ";", "}", "else", "{", "array_push", "(", "static", "::", "$", "psr4", "[", "$", "prefix", "]", ",", "$", "base_dir", ")", ";", "}", "}" ]
Adds a base directory for a namespace prefix using the PSR-4 standard. @param string $prefix @param string $base_dir @param bool $prepend
[ "Adds", "a", "base", "directory", "for", "a", "namespace", "prefix", "using", "the", "PSR", "-", "4", "standard", "." ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/autoload.php#L53-L72
train
Kris-Kuiper/sFire-Framework
autoload.php
Autoloader.add
public static function add($prefix, $base_dir, $prepend = false) { //Normalize namespace prefix $prefix = trim($prefix, '\\') . '\\'; //Normalize the base directory with a trailing separator $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; //Initialize the namespace prefix array if(false === isset(static :: $psr0[$prefix])) { static :: $psr0[$prefix] = []; } //Retain the base directory for the namespace prefix if(true === $prepend) { array_unshift(static :: $psr0[$prefix], $base_dir); } else { array_push(static :: $psr0[$prefix], $base_dir); } }
php
public static function add($prefix, $base_dir, $prepend = false) { //Normalize namespace prefix $prefix = trim($prefix, '\\') . '\\'; //Normalize the base directory with a trailing separator $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; //Initialize the namespace prefix array if(false === isset(static :: $psr0[$prefix])) { static :: $psr0[$prefix] = []; } //Retain the base directory for the namespace prefix if(true === $prepend) { array_unshift(static :: $psr0[$prefix], $base_dir); } else { array_push(static :: $psr0[$prefix], $base_dir); } }
[ "public", "static", "function", "add", "(", "$", "prefix", ",", "$", "base_dir", ",", "$", "prepend", "=", "false", ")", "{", "//Normalize namespace prefix\r", "$", "prefix", "=", "trim", "(", "$", "prefix", ",", "'\\\\'", ")", ".", "'\\\\'", ";", "//Normalize the base directory with a trailing separator\r", "$", "base_dir", "=", "rtrim", "(", "$", "base_dir", ",", "DIRECTORY_SEPARATOR", ")", ".", "'/'", ";", "//Initialize the namespace prefix array\r", "if", "(", "false", "===", "isset", "(", "static", "::", "$", "psr0", "[", "$", "prefix", "]", ")", ")", "{", "static", "::", "$", "psr0", "[", "$", "prefix", "]", "=", "[", "]", ";", "}", "//Retain the base directory for the namespace prefix\r", "if", "(", "true", "===", "$", "prepend", ")", "{", "array_unshift", "(", "static", "::", "$", "psr0", "[", "$", "prefix", "]", ",", "$", "base_dir", ")", ";", "}", "else", "{", "array_push", "(", "static", "::", "$", "psr0", "[", "$", "prefix", "]", ",", "$", "base_dir", ")", ";", "}", "}" ]
Adds a base directory for a namespace prefix using the PSR-0 standard. @param string $prefix @param string $base_dir @param bool $prepend
[ "Adds", "a", "base", "directory", "for", "a", "namespace", "prefix", "using", "the", "PSR", "-", "0", "standard", "." ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/autoload.php#L81-L100
train
ingro/Rest
src/Ingruz/Rest/Repositories/AbstractRestEloquentRepository.php
AbstractRestEloquentRepository.getFirstBy
public function getFirstBy($key, $value, array $with = array()) { return $this->make($with)->where($key, '=', $value)->first(); }
php
public function getFirstBy($key, $value, array $with = array()) { return $this->make($with)->where($key, '=', $value)->first(); }
[ "public", "function", "getFirstBy", "(", "$", "key", ",", "$", "value", ",", "array", "$", "with", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "make", "(", "$", "with", ")", "->", "where", "(", "$", "key", ",", "'='", ",", "$", "value", ")", "->", "first", "(", ")", ";", "}" ]
Find an item by a key value @param string $key [description] @param mixed $value [description] @param array $with [description] @return \Illuminate\Database\Eloquent\Model
[ "Find", "an", "item", "by", "a", "key", "value" ]
922bed071b8ea41feb067d97a3e283f944a86cb8
https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Repositories/AbstractRestEloquentRepository.php#L140-L143
train
ingro/Rest
src/Ingruz/Rest/Repositories/AbstractRestEloquentRepository.php
AbstractRestEloquentRepository.getManyBy
public function getManyBy($key, $value, array $with = array()) { return $this->make($with)->where($key, '=', $value)->get(); }
php
public function getManyBy($key, $value, array $with = array()) { return $this->make($with)->where($key, '=', $value)->get(); }
[ "public", "function", "getManyBy", "(", "$", "key", ",", "$", "value", ",", "array", "$", "with", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "make", "(", "$", "with", ")", "->", "where", "(", "$", "key", ",", "'='", ",", "$", "value", ")", "->", "get", "(", ")", ";", "}" ]
Return many items by a key value @param string $key @param mixed $value @param array $with @return \Illuminate\Database\Eloquent\Collection
[ "Return", "many", "items", "by", "a", "key", "value" ]
922bed071b8ea41feb067d97a3e283f944a86cb8
https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Repositories/AbstractRestEloquentRepository.php#L153-L156
train
ingro/Rest
src/Ingruz/Rest/Repositories/AbstractRestEloquentRepository.php
AbstractRestEloquentRepository.has
public function has($relation, array $with = array()) { $query = $this->make($with); return $query->has($relation)->get(); }
php
public function has($relation, array $with = array()) { $query = $this->make($with); return $query->has($relation)->get(); }
[ "public", "function", "has", "(", "$", "relation", ",", "array", "$", "with", "=", "array", "(", ")", ")", "{", "$", "query", "=", "$", "this", "->", "make", "(", "$", "with", ")", ";", "return", "$", "query", "->", "has", "(", "$", "relation", ")", "->", "get", "(", ")", ";", "}" ]
Return items that have a defined relation @param string $relation @param array $with @return \Illuminate\Database\Eloquent\Collection
[ "Return", "items", "that", "have", "a", "defined", "relation" ]
922bed071b8ea41feb067d97a3e283f944a86cb8
https://github.com/ingro/Rest/blob/922bed071b8ea41feb067d97a3e283f944a86cb8/src/Ingruz/Rest/Repositories/AbstractRestEloquentRepository.php#L165-L170
train
stubbles/stubbles-peer
src/main/php/http/HttpRequest.php
HttpRequest.get
public function get( int $timeout = 30, $version = HttpVersion::HTTP_1_1 ): HttpResponse { $socket = $this->httpUri->openSocket($timeout); $this->processHeader($socket, Http::GET, $version); return HttpResponse::create($socket); }
php
public function get( int $timeout = 30, $version = HttpVersion::HTTP_1_1 ): HttpResponse { $socket = $this->httpUri->openSocket($timeout); $this->processHeader($socket, Http::GET, $version); return HttpResponse::create($socket); }
[ "public", "function", "get", "(", "int", "$", "timeout", "=", "30", ",", "$", "version", "=", "HttpVersion", "::", "HTTP_1_1", ")", ":", "HttpResponse", "{", "$", "socket", "=", "$", "this", "->", "httpUri", "->", "openSocket", "(", "$", "timeout", ")", ";", "$", "this", "->", "processHeader", "(", "$", "socket", ",", "Http", "::", "GET", ",", "$", "version", ")", ";", "return", "HttpResponse", "::", "create", "(", "$", "socket", ")", ";", "}" ]
initializes a get request @param int $timeout optional connection timeout, defaults to 30 seconds @param string|\stubbles\peer\http\HttpVersion $version optional http version, defaults to HTTP/1.1 @return \stubbles\peer\http\HttpResponse
[ "initializes", "a", "get", "request" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpRequest.php#L66-L73
train
stubbles/stubbles-peer
src/main/php/http/HttpRequest.php
HttpRequest.head
public function head( int $timeout = 30, $version = HttpVersion::HTTP_1_1 ): HttpResponse { $socket = $this->httpUri->openSocket($timeout); $this->headers->put('Connection', 'close'); $this->processHeader($socket, Http::HEAD, $version); return HttpResponse::create($socket); }
php
public function head( int $timeout = 30, $version = HttpVersion::HTTP_1_1 ): HttpResponse { $socket = $this->httpUri->openSocket($timeout); $this->headers->put('Connection', 'close'); $this->processHeader($socket, Http::HEAD, $version); return HttpResponse::create($socket); }
[ "public", "function", "head", "(", "int", "$", "timeout", "=", "30", ",", "$", "version", "=", "HttpVersion", "::", "HTTP_1_1", ")", ":", "HttpResponse", "{", "$", "socket", "=", "$", "this", "->", "httpUri", "->", "openSocket", "(", "$", "timeout", ")", ";", "$", "this", "->", "headers", "->", "put", "(", "'Connection'", ",", "'close'", ")", ";", "$", "this", "->", "processHeader", "(", "$", "socket", ",", "Http", "::", "HEAD", ",", "$", "version", ")", ";", "return", "HttpResponse", "::", "create", "(", "$", "socket", ")", ";", "}" ]
initializes a head request @param int $timeout optional connection timeout, defaults to 30 seconds @param string|\stubbles\peer\http\HttpVersion $version optional http version, defaults to HTTP/1.1 @return \stubbles\peer\http\HttpResponse
[ "initializes", "a", "head", "request" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpRequest.php#L82-L90
train
stubbles/stubbles-peer
src/main/php/http/HttpRequest.php
HttpRequest.post
public function post( $body, int $timeout = 30, $version = HttpVersion::HTTP_1_1 ): HttpResponse { if (is_array($body)) { $body = $this->transformPostValues($body); $this->headers->put('Content-Type', 'application/x-www-form-urlencoded'); } $this->headers->put('Content-Length', strlen($body)); $socket = $this->httpUri->openSocket($timeout); $this->processHeader($socket, Http::POST, $version); $socket->write($body); return HttpResponse::create($socket); }
php
public function post( $body, int $timeout = 30, $version = HttpVersion::HTTP_1_1 ): HttpResponse { if (is_array($body)) { $body = $this->transformPostValues($body); $this->headers->put('Content-Type', 'application/x-www-form-urlencoded'); } $this->headers->put('Content-Length', strlen($body)); $socket = $this->httpUri->openSocket($timeout); $this->processHeader($socket, Http::POST, $version); $socket->write($body); return HttpResponse::create($socket); }
[ "public", "function", "post", "(", "$", "body", ",", "int", "$", "timeout", "=", "30", ",", "$", "version", "=", "HttpVersion", "::", "HTTP_1_1", ")", ":", "HttpResponse", "{", "if", "(", "is_array", "(", "$", "body", ")", ")", "{", "$", "body", "=", "$", "this", "->", "transformPostValues", "(", "$", "body", ")", ";", "$", "this", "->", "headers", "->", "put", "(", "'Content-Type'", ",", "'application/x-www-form-urlencoded'", ")", ";", "}", "$", "this", "->", "headers", "->", "put", "(", "'Content-Length'", ",", "strlen", "(", "$", "body", ")", ")", ";", "$", "socket", "=", "$", "this", "->", "httpUri", "->", "openSocket", "(", "$", "timeout", ")", ";", "$", "this", "->", "processHeader", "(", "$", "socket", ",", "Http", "::", "POST", ",", "$", "version", ")", ";", "$", "socket", "->", "write", "(", "$", "body", ")", ";", "return", "HttpResponse", "::", "create", "(", "$", "socket", ")", ";", "}" ]
initializes a post request The body can either be given as string or as array, which is considered to be a map of key-value pairs denoting post request parameters. If the latter is the case an post form submit content type will be added to the request. @param string|array $body post request body @param int $timeout optional connection timeout, defaults to 30 seconds @param string|\stubbles\peer\http\HttpVersion $version optional http version, defaults to HTTP/1.1 @return \stubbles\peer\http\HttpResponse
[ "initializes", "a", "post", "request" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpRequest.php#L105-L120
train
stubbles/stubbles-peer
src/main/php/http/HttpRequest.php
HttpRequest.transformPostValues
private function transformPostValues(array $postValues): string { $body = ''; foreach ($postValues as $key => $value) { $body .= urlencode($key) . '=' . urlencode($value) . '&'; } return $body; }
php
private function transformPostValues(array $postValues): string { $body = ''; foreach ($postValues as $key => $value) { $body .= urlencode($key) . '=' . urlencode($value) . '&'; } return $body; }
[ "private", "function", "transformPostValues", "(", "array", "$", "postValues", ")", ":", "string", "{", "$", "body", "=", "''", ";", "foreach", "(", "$", "postValues", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "body", ".=", "urlencode", "(", "$", "key", ")", ".", "'='", ".", "urlencode", "(", "$", "value", ")", ".", "'&'", ";", "}", "return", "$", "body", ";", "}" ]
transforms post values to post body @param array $postValues @return string
[ "transforms", "post", "values", "to", "post", "body" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpRequest.php#L166-L174
train
stubbles/stubbles-peer
src/main/php/http/HttpRequest.php
HttpRequest.processHeader
private function processHeader(Stream $socket, string $method, $version) { $version = HttpVersion::castFrom($version); if (!$version->equals(HttpVersion::HTTP_1_0) && !$version->equals(HttpVersion::HTTP_1_1)) { throw new \InvalidArgumentException( 'Invalid HTTP version ' . $version . ', please use either ' . HttpVersion::HTTP_1_0 . ' or ' . HttpVersion::HTTP_1_1 ); } $path = $this->httpUri->path(); if ($this->httpUri->hasQueryString() && $this->methodAllowsQueryString($method)) { $path .= '?' . $this->httpUri->queryString(); } $socket->write(Http::line($method . ' ' . $path . ' ' . $version)); $socket->write(Http::line('Host: ' . $this->httpUri->hostname())); foreach ($this->headers as $key => $value) { $socket->write(Http::line($key . ': ' . $value)); } $socket->write(Http::emptyLine()); }
php
private function processHeader(Stream $socket, string $method, $version) { $version = HttpVersion::castFrom($version); if (!$version->equals(HttpVersion::HTTP_1_0) && !$version->equals(HttpVersion::HTTP_1_1)) { throw new \InvalidArgumentException( 'Invalid HTTP version ' . $version . ', please use either ' . HttpVersion::HTTP_1_0 . ' or ' . HttpVersion::HTTP_1_1 ); } $path = $this->httpUri->path(); if ($this->httpUri->hasQueryString() && $this->methodAllowsQueryString($method)) { $path .= '?' . $this->httpUri->queryString(); } $socket->write(Http::line($method . ' ' . $path . ' ' . $version)); $socket->write(Http::line('Host: ' . $this->httpUri->hostname())); foreach ($this->headers as $key => $value) { $socket->write(Http::line($key . ': ' . $value)); } $socket->write(Http::emptyLine()); }
[ "private", "function", "processHeader", "(", "Stream", "$", "socket", ",", "string", "$", "method", ",", "$", "version", ")", "{", "$", "version", "=", "HttpVersion", "::", "castFrom", "(", "$", "version", ")", ";", "if", "(", "!", "$", "version", "->", "equals", "(", "HttpVersion", "::", "HTTP_1_0", ")", "&&", "!", "$", "version", "->", "equals", "(", "HttpVersion", "::", "HTTP_1_1", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid HTTP version '", ".", "$", "version", ".", "', please use either '", ".", "HttpVersion", "::", "HTTP_1_0", ".", "' or '", ".", "HttpVersion", "::", "HTTP_1_1", ")", ";", "}", "$", "path", "=", "$", "this", "->", "httpUri", "->", "path", "(", ")", ";", "if", "(", "$", "this", "->", "httpUri", "->", "hasQueryString", "(", ")", "&&", "$", "this", "->", "methodAllowsQueryString", "(", "$", "method", ")", ")", "{", "$", "path", ".=", "'?'", ".", "$", "this", "->", "httpUri", "->", "queryString", "(", ")", ";", "}", "$", "socket", "->", "write", "(", "Http", "::", "line", "(", "$", "method", ".", "' '", ".", "$", "path", ".", "' '", ".", "$", "version", ")", ")", ";", "$", "socket", "->", "write", "(", "Http", "::", "line", "(", "'Host: '", ".", "$", "this", "->", "httpUri", "->", "hostname", "(", ")", ")", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "socket", "->", "write", "(", "Http", "::", "line", "(", "$", "key", ".", "': '", ".", "$", "value", ")", ")", ";", "}", "$", "socket", "->", "write", "(", "Http", "::", "emptyLine", "(", ")", ")", ";", "}" ]
helper method to send the headers @param \stubbles\peer\Stream $socket output stream to write request to @param string $method http method @param string|\stubbles\peer\http\HttpVersion $version http version @throws \InvalidArgumentException
[ "helper", "method", "to", "send", "the", "headers" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpRequest.php#L184-L206
train
stubbles/stubbles-peer
src/main/php/http/HttpRequest.php
HttpRequest.methodAllowsQueryString
private function methodAllowsQueryString(string $method): bool { return (Http::GET === $method || Http::HEAD === $method); }
php
private function methodAllowsQueryString(string $method): bool { return (Http::GET === $method || Http::HEAD === $method); }
[ "private", "function", "methodAllowsQueryString", "(", "string", "$", "method", ")", ":", "bool", "{", "return", "(", "Http", "::", "GET", "===", "$", "method", "||", "Http", "::", "HEAD", "===", "$", "method", ")", ";", "}" ]
checks if given method allows a query string @param string $method @return bool
[ "checks", "if", "given", "method", "allows", "a", "query", "string" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpRequest.php#L214-L217
train
madesst/MadesstSecurityExtraBundle
Common/RequestMatcher.php
RequestMatcher.matchPath
public function matchPath($regexp) { if (substr($regexp, 0, 1) == '@') { $this->route_name = substr($regexp, 1); } else { parent::matchPath($regexp); } }
php
public function matchPath($regexp) { if (substr($regexp, 0, 1) == '@') { $this->route_name = substr($regexp, 1); } else { parent::matchPath($regexp); } }
[ "public", "function", "matchPath", "(", "$", "regexp", ")", "{", "if", "(", "substr", "(", "$", "regexp", ",", "0", ",", "1", ")", "==", "'@'", ")", "{", "$", "this", "->", "route_name", "=", "substr", "(", "$", "regexp", ",", "1", ")", ";", "}", "else", "{", "parent", "::", "matchPath", "(", "$", "regexp", ")", ";", "}", "}" ]
Adds a check for the route name. @param string $regexp A Regexp
[ "Adds", "a", "check", "for", "the", "route", "name", "." ]
d856e5c2ade3c6cc9faf294d0ba95088133cf9bb
https://github.com/madesst/MadesstSecurityExtraBundle/blob/d856e5c2ade3c6cc9faf294d0ba95088133cf9bb/Common/RequestMatcher.php#L25-L32
train
SlabPHP/router
src/Route.php
Route.initializeFromHardcodedObject
private function initializeFromHardcodedObject($object) { //Typecast arrays to objects if (is_array($object)) $object = (object)$object; if (!empty($object->path)) { $this->path = $object->path; } if (!empty($object->name)) { $this->name = $object->name; } if (!empty($object->class)) { $this->class = $object->class; } if (!empty($object->priority)) { $this->priority = $object->priority; } if (!empty($object->pattern)) { if ($object->pattern instanceof Pattern) { $this->patternString = $object->pattern->getPatternString(); $this->pattern = $object->pattern; } else { $this->patternString = $object->pattern; $this->pattern = new Pattern($this->path, $this->patternString); } } if (!empty($object->parameters)) { if (is_array($object->parameters)) { $this->parameters = (object)$object->parameters; } else { $this->parameters = $object->parameters; } } }
php
private function initializeFromHardcodedObject($object) { //Typecast arrays to objects if (is_array($object)) $object = (object)$object; if (!empty($object->path)) { $this->path = $object->path; } if (!empty($object->name)) { $this->name = $object->name; } if (!empty($object->class)) { $this->class = $object->class; } if (!empty($object->priority)) { $this->priority = $object->priority; } if (!empty($object->pattern)) { if ($object->pattern instanceof Pattern) { $this->patternString = $object->pattern->getPatternString(); $this->pattern = $object->pattern; } else { $this->patternString = $object->pattern; $this->pattern = new Pattern($this->path, $this->patternString); } } if (!empty($object->parameters)) { if (is_array($object->parameters)) { $this->parameters = (object)$object->parameters; } else { $this->parameters = $object->parameters; } } }
[ "private", "function", "initializeFromHardcodedObject", "(", "$", "object", ")", "{", "//Typecast arrays to objects", "if", "(", "is_array", "(", "$", "object", ")", ")", "$", "object", "=", "(", "object", ")", "$", "object", ";", "if", "(", "!", "empty", "(", "$", "object", "->", "path", ")", ")", "{", "$", "this", "->", "path", "=", "$", "object", "->", "path", ";", "}", "if", "(", "!", "empty", "(", "$", "object", "->", "name", ")", ")", "{", "$", "this", "->", "name", "=", "$", "object", "->", "name", ";", "}", "if", "(", "!", "empty", "(", "$", "object", "->", "class", ")", ")", "{", "$", "this", "->", "class", "=", "$", "object", "->", "class", ";", "}", "if", "(", "!", "empty", "(", "$", "object", "->", "priority", ")", ")", "{", "$", "this", "->", "priority", "=", "$", "object", "->", "priority", ";", "}", "if", "(", "!", "empty", "(", "$", "object", "->", "pattern", ")", ")", "{", "if", "(", "$", "object", "->", "pattern", "instanceof", "Pattern", ")", "{", "$", "this", "->", "patternString", "=", "$", "object", "->", "pattern", "->", "getPatternString", "(", ")", ";", "$", "this", "->", "pattern", "=", "$", "object", "->", "pattern", ";", "}", "else", "{", "$", "this", "->", "patternString", "=", "$", "object", "->", "pattern", ";", "$", "this", "->", "pattern", "=", "new", "Pattern", "(", "$", "this", "->", "path", ",", "$", "this", "->", "patternString", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "object", "->", "parameters", ")", ")", "{", "if", "(", "is_array", "(", "$", "object", "->", "parameters", ")", ")", "{", "$", "this", "->", "parameters", "=", "(", "object", ")", "$", "object", "->", "parameters", ";", "}", "else", "{", "$", "this", "->", "parameters", "=", "$", "object", "->", "parameters", ";", "}", "}", "}" ]
Allow programmatic initialization of a route @param \stdClass $object @throws \Exception
[ "Allow", "programmatic", "initialization", "of", "a", "route" ]
3e95fa07f694c0e2288a9e9a0ca106117f501a6e
https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Route.php#L106-L147
train
SlabPHP/router
src/Route.php
Route.initializeFromSimpleXML
private function initializeFromSimpleXML($xmlObject) { $this->path = !empty($xmlObject->path) ? trim($xmlObject->path) : '/'; $this->name = !empty($xmlObject->name) ? trim($xmlObject->name) : ''; $this->class = !empty($xmlObject->class) ? trim($xmlObject->class) : ''; $this->priority = !empty($xmlObject->priority) ? intval($xmlObject->priority) : 0; $this->patternString = !empty($xmlObject->pattern) ? (string)$xmlObject->pattern : null; $this->pattern = !empty($this->patternString) ? new Pattern($this->path, $this->patternString) : null; $this->parameters = new \stdClass(); //Build route parameters into an object because SimpleXMLElements can't be memcached if (!empty($xmlObject->parameters) && $xmlObject->parameters->children()) { foreach ($xmlObject->parameters->children() as $parameter) { $parameterName = (string)$parameter->getName(); $parameterValue = (string)$parameter; $parameterAttributes = []; $attributes = $parameter->attributes(); foreach ($attributes as $attributeName => $attributeValue) { $parameterAttributes[(string)$attributeName] = (string)$attributeValue; } $parameterObject = new \Slab\Router\Parameter($parameterName, $parameterValue, $parameterAttributes); if (!empty($this->parameters->$parameterName)) { if (is_array($this->parameters->$parameterName)) { $this->parameters->{$parameterName}[] = $parameterObject; } else { $this->parameters->$parameterName = array($this->parameters->$parameterName, $parameterObject); } } else { $this->parameters->$parameterName = $parameterObject; } } } }
php
private function initializeFromSimpleXML($xmlObject) { $this->path = !empty($xmlObject->path) ? trim($xmlObject->path) : '/'; $this->name = !empty($xmlObject->name) ? trim($xmlObject->name) : ''; $this->class = !empty($xmlObject->class) ? trim($xmlObject->class) : ''; $this->priority = !empty($xmlObject->priority) ? intval($xmlObject->priority) : 0; $this->patternString = !empty($xmlObject->pattern) ? (string)$xmlObject->pattern : null; $this->pattern = !empty($this->patternString) ? new Pattern($this->path, $this->patternString) : null; $this->parameters = new \stdClass(); //Build route parameters into an object because SimpleXMLElements can't be memcached if (!empty($xmlObject->parameters) && $xmlObject->parameters->children()) { foreach ($xmlObject->parameters->children() as $parameter) { $parameterName = (string)$parameter->getName(); $parameterValue = (string)$parameter; $parameterAttributes = []; $attributes = $parameter->attributes(); foreach ($attributes as $attributeName => $attributeValue) { $parameterAttributes[(string)$attributeName] = (string)$attributeValue; } $parameterObject = new \Slab\Router\Parameter($parameterName, $parameterValue, $parameterAttributes); if (!empty($this->parameters->$parameterName)) { if (is_array($this->parameters->$parameterName)) { $this->parameters->{$parameterName}[] = $parameterObject; } else { $this->parameters->$parameterName = array($this->parameters->$parameterName, $parameterObject); } } else { $this->parameters->$parameterName = $parameterObject; } } } }
[ "private", "function", "initializeFromSimpleXML", "(", "$", "xmlObject", ")", "{", "$", "this", "->", "path", "=", "!", "empty", "(", "$", "xmlObject", "->", "path", ")", "?", "trim", "(", "$", "xmlObject", "->", "path", ")", ":", "'/'", ";", "$", "this", "->", "name", "=", "!", "empty", "(", "$", "xmlObject", "->", "name", ")", "?", "trim", "(", "$", "xmlObject", "->", "name", ")", ":", "''", ";", "$", "this", "->", "class", "=", "!", "empty", "(", "$", "xmlObject", "->", "class", ")", "?", "trim", "(", "$", "xmlObject", "->", "class", ")", ":", "''", ";", "$", "this", "->", "priority", "=", "!", "empty", "(", "$", "xmlObject", "->", "priority", ")", "?", "intval", "(", "$", "xmlObject", "->", "priority", ")", ":", "0", ";", "$", "this", "->", "patternString", "=", "!", "empty", "(", "$", "xmlObject", "->", "pattern", ")", "?", "(", "string", ")", "$", "xmlObject", "->", "pattern", ":", "null", ";", "$", "this", "->", "pattern", "=", "!", "empty", "(", "$", "this", "->", "patternString", ")", "?", "new", "Pattern", "(", "$", "this", "->", "path", ",", "$", "this", "->", "patternString", ")", ":", "null", ";", "$", "this", "->", "parameters", "=", "new", "\\", "stdClass", "(", ")", ";", "//Build route parameters into an object because SimpleXMLElements can't be memcached", "if", "(", "!", "empty", "(", "$", "xmlObject", "->", "parameters", ")", "&&", "$", "xmlObject", "->", "parameters", "->", "children", "(", ")", ")", "{", "foreach", "(", "$", "xmlObject", "->", "parameters", "->", "children", "(", ")", "as", "$", "parameter", ")", "{", "$", "parameterName", "=", "(", "string", ")", "$", "parameter", "->", "getName", "(", ")", ";", "$", "parameterValue", "=", "(", "string", ")", "$", "parameter", ";", "$", "parameterAttributes", "=", "[", "]", ";", "$", "attributes", "=", "$", "parameter", "->", "attributes", "(", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "attributeName", "=>", "$", "attributeValue", ")", "{", "$", "parameterAttributes", "[", "(", "string", ")", "$", "attributeName", "]", "=", "(", "string", ")", "$", "attributeValue", ";", "}", "$", "parameterObject", "=", "new", "\\", "Slab", "\\", "Router", "\\", "Parameter", "(", "$", "parameterName", ",", "$", "parameterValue", ",", "$", "parameterAttributes", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "parameters", "->", "$", "parameterName", ")", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "parameters", "->", "$", "parameterName", ")", ")", "{", "$", "this", "->", "parameters", "->", "{", "$", "parameterName", "}", "[", "]", "=", "$", "parameterObject", ";", "}", "else", "{", "$", "this", "->", "parameters", "->", "$", "parameterName", "=", "array", "(", "$", "this", "->", "parameters", "->", "$", "parameterName", ",", "$", "parameterObject", ")", ";", "}", "}", "else", "{", "$", "this", "->", "parameters", "->", "$", "parameterName", "=", "$", "parameterObject", ";", "}", "}", "}", "}" ]
Initialize from a simple XML object @param \SimpleXMLElement $xmlObject @throws \Exception
[ "Initialize", "from", "a", "simple", "XML", "object" ]
3e95fa07f694c0e2288a9e9a0ca106117f501a6e
https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Route.php#L156-L194
train
SlabPHP/router
src/Route.php
Route.validateRoute
private function validateRoute($logReference) { $valid = true; if (empty($this->name)) { if ($logReference) $logReference->error('Route does not specify a name. Path(' . $this->path . ') Class(' . $this->class . ')'); $valid = false; } if (empty($this->path)) { if ($logReference) $logReference->error('Route does not specify a path. Name(' . $this->name . ') Class(' . $this->class . ')'); $valid = false; } else { if ($this->path != '/' && $this->path[0] != '/') { if ($logReference) $logReference->error('Path ' . $this->path . ' must start with a forward slash. eg. /testing'); $valid = false; } if ($this->path[mb_strlen($this->path) - 1] == '/') { $this->path = mb_substr($this->path, 0, mb_strlen($this->path) - 1); } } if (empty($this->class)) { if ($logReference) $logReference->error('Route does not specify a class. Name(' . $this->name . ') Path(' . $this->path . ')'); $valid = false; } $this->validRoute = $valid; }
php
private function validateRoute($logReference) { $valid = true; if (empty($this->name)) { if ($logReference) $logReference->error('Route does not specify a name. Path(' . $this->path . ') Class(' . $this->class . ')'); $valid = false; } if (empty($this->path)) { if ($logReference) $logReference->error('Route does not specify a path. Name(' . $this->name . ') Class(' . $this->class . ')'); $valid = false; } else { if ($this->path != '/' && $this->path[0] != '/') { if ($logReference) $logReference->error('Path ' . $this->path . ' must start with a forward slash. eg. /testing'); $valid = false; } if ($this->path[mb_strlen($this->path) - 1] == '/') { $this->path = mb_substr($this->path, 0, mb_strlen($this->path) - 1); } } if (empty($this->class)) { if ($logReference) $logReference->error('Route does not specify a class. Name(' . $this->name . ') Path(' . $this->path . ')'); $valid = false; } $this->validRoute = $valid; }
[ "private", "function", "validateRoute", "(", "$", "logReference", ")", "{", "$", "valid", "=", "true", ";", "if", "(", "empty", "(", "$", "this", "->", "name", ")", ")", "{", "if", "(", "$", "logReference", ")", "$", "logReference", "->", "error", "(", "'Route does not specify a name. Path('", ".", "$", "this", "->", "path", ".", "') Class('", ".", "$", "this", "->", "class", ".", "')'", ")", ";", "$", "valid", "=", "false", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "path", ")", ")", "{", "if", "(", "$", "logReference", ")", "$", "logReference", "->", "error", "(", "'Route does not specify a path. Name('", ".", "$", "this", "->", "name", ".", "') Class('", ".", "$", "this", "->", "class", ".", "')'", ")", ";", "$", "valid", "=", "false", ";", "}", "else", "{", "if", "(", "$", "this", "->", "path", "!=", "'/'", "&&", "$", "this", "->", "path", "[", "0", "]", "!=", "'/'", ")", "{", "if", "(", "$", "logReference", ")", "$", "logReference", "->", "error", "(", "'Path '", ".", "$", "this", "->", "path", ".", "' must start with a forward slash. eg. /testing'", ")", ";", "$", "valid", "=", "false", ";", "}", "if", "(", "$", "this", "->", "path", "[", "mb_strlen", "(", "$", "this", "->", "path", ")", "-", "1", "]", "==", "'/'", ")", "{", "$", "this", "->", "path", "=", "mb_substr", "(", "$", "this", "->", "path", ",", "0", ",", "mb_strlen", "(", "$", "this", "->", "path", ")", "-", "1", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "this", "->", "class", ")", ")", "{", "if", "(", "$", "logReference", ")", "$", "logReference", "->", "error", "(", "'Route does not specify a class. Name('", ".", "$", "this", "->", "name", ".", "') Path('", ".", "$", "this", "->", "path", ".", "')'", ")", ";", "$", "valid", "=", "false", ";", "}", "$", "this", "->", "validRoute", "=", "$", "valid", ";", "}" ]
Validates the route @param \Psr\Log\LoggerInterface $logReference
[ "Validates", "the", "route" ]
3e95fa07f694c0e2288a9e9a0ca106117f501a6e
https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Route.php#L200-L229
train
SlabPHP/router
src/Route.php
Route.getRoutingPath
public function getRoutingPath() { $tempPath = substr($this->path, 1); if (strpos($tempPath, '/') !== false) { $pathPieces = explode('/', $tempPath); return $pathPieces; } else if ($tempPath) { return array($tempPath); } else { return array(); } }
php
public function getRoutingPath() { $tempPath = substr($this->path, 1); if (strpos($tempPath, '/') !== false) { $pathPieces = explode('/', $tempPath); return $pathPieces; } else if ($tempPath) { return array($tempPath); } else { return array(); } }
[ "public", "function", "getRoutingPath", "(", ")", "{", "$", "tempPath", "=", "substr", "(", "$", "this", "->", "path", ",", "1", ")", ";", "if", "(", "strpos", "(", "$", "tempPath", ",", "'/'", ")", "!==", "false", ")", "{", "$", "pathPieces", "=", "explode", "(", "'/'", ",", "$", "tempPath", ")", ";", "return", "$", "pathPieces", ";", "}", "else", "if", "(", "$", "tempPath", ")", "{", "return", "array", "(", "$", "tempPath", ")", ";", "}", "else", "{", "return", "array", "(", ")", ";", "}", "}" ]
Returns an array of the routing path @return array
[ "Returns", "an", "array", "of", "the", "routing", "path" ]
3e95fa07f694c0e2288a9e9a0ca106117f501a6e
https://github.com/SlabPHP/router/blob/3e95fa07f694c0e2288a9e9a0ca106117f501a6e/src/Route.php#L254-L266
train