id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
241,200
netis-pl/yii2-relauth
AuthManagerTrait.php
AuthManagerTrait.getPath
public function getPath($userId, $permissionName, $params = [], $allowCaching = true) { if ($allowCaching && empty($params) && isset($this->paths[$userId][$permissionName])) { return $this->paths[$userId][$permissionName]; } $this->checkAccess($userId, $permissionName, $params); if ($allowCaching && empty($params)) { $this->paths[$userId][$permissionName] = $this->currentPath; } return $this->currentPath; }
php
public function getPath($userId, $permissionName, $params = [], $allowCaching = true) { if ($allowCaching && empty($params) && isset($this->paths[$userId][$permissionName])) { return $this->paths[$userId][$permissionName]; } $this->checkAccess($userId, $permissionName, $params); if ($allowCaching && empty($params)) { $this->paths[$userId][$permissionName] = $this->currentPath; } return $this->currentPath; }
[ "public", "function", "getPath", "(", "$", "userId", ",", "$", "permissionName", ",", "$", "params", "=", "[", "]", ",", "$", "allowCaching", "=", "true", ")", "{", "if", "(", "$", "allowCaching", "&&", "empty", "(", "$", "params", ")", "&&", "isset", "(", "$", "this", "->", "paths", "[", "$", "userId", "]", "[", "$", "permissionName", "]", ")", ")", "{", "return", "$", "this", "->", "paths", "[", "$", "userId", "]", "[", "$", "permissionName", "]", ";", "}", "$", "this", "->", "checkAccess", "(", "$", "userId", ",", "$", "permissionName", ",", "$", "params", ")", ";", "if", "(", "$", "allowCaching", "&&", "empty", "(", "$", "params", ")", ")", "{", "$", "this", "->", "paths", "[", "$", "userId", "]", "[", "$", "permissionName", "]", "=", "$", "this", "->", "currentPath", ";", "}", "return", "$", "this", "->", "currentPath", ";", "}" ]
Returns a list of auth items between the one checked and the one assigned to the user. @param string|integer $userId the user ID. This should be either an integer or a string representing the unique identifier of a user. See [[\yii\web\User::id]]. @param string $permissionName the name of the permission to be checked against @param array $params name-value pairs that will be passed to the rules associated with the roles and permissions assigned to the user. @param boolean $allowCaching whether to allow caching the accessed path. When this parameter is true (default), if the access check of an operation was performed before, traversed path will be directly returned when calling this method to check the same operation. If this parameter is false, this method will always call [[\yii\rbac\ManagerInterface::checkAccess()]] to obtain the up-to-date traversed path. Note that this caching is effective only within the same request and only works when `$params = []`. @return array
[ "Returns", "a", "list", "of", "auth", "items", "between", "the", "one", "checked", "and", "the", "one", "assigned", "to", "the", "user", "." ]
d4561e2be2d6014071a2e8104b2f7920e55bf20e
https://github.com/netis-pl/yii2-relauth/blob/d4561e2be2d6014071a2e8104b2f7920e55bf20e/AuthManagerTrait.php#L36-L46
241,201
eix/core
src/php/main/Eix/Core/Settings.php
Settings.loadFromLocation
private function loadFromLocation($location) { Logger::get()->debug('Loading settings...'); // Add the trailing slash to the folder if it is missing. if (substr($location, -1) != DIRECTORY_SEPARATOR) { $location .= DIRECTORY_SEPARATOR; } $settingsLocation = $location . 'settings.json'; if (!is_readable($settingsLocation)) { Logger::get()->error( 'Settings file %s cannot be read.', $settingsLocation ); throw new Settings\Exception("Settings file $settingsLocation is unavailable."); } // Load the settings. $settings = json_decode(file_get_contents($settingsLocation), true); if (empty($settings)) { throw new Settings\Exception('Settings file cannot be parsed.'); } // Load settings customised for the current environment. $environmentSettings = null; $environment = self::getEnvironment(); if ($environment) { $environmentSettingsLocation = sprintf( '%ssettings-%s.json', $location, strtolower($environment) ); if (is_readable($environmentSettingsLocation)) { $environmentSettings = json_decode(file_get_contents($environmentSettingsLocation), true); if (!empty($environmentSettings)) { $settings = self::mergeSettings($settings, $environmentSettings); } } } $this->settings = self::objectify($settings); }
php
private function loadFromLocation($location) { Logger::get()->debug('Loading settings...'); // Add the trailing slash to the folder if it is missing. if (substr($location, -1) != DIRECTORY_SEPARATOR) { $location .= DIRECTORY_SEPARATOR; } $settingsLocation = $location . 'settings.json'; if (!is_readable($settingsLocation)) { Logger::get()->error( 'Settings file %s cannot be read.', $settingsLocation ); throw new Settings\Exception("Settings file $settingsLocation is unavailable."); } // Load the settings. $settings = json_decode(file_get_contents($settingsLocation), true); if (empty($settings)) { throw new Settings\Exception('Settings file cannot be parsed.'); } // Load settings customised for the current environment. $environmentSettings = null; $environment = self::getEnvironment(); if ($environment) { $environmentSettingsLocation = sprintf( '%ssettings-%s.json', $location, strtolower($environment) ); if (is_readable($environmentSettingsLocation)) { $environmentSettings = json_decode(file_get_contents($environmentSettingsLocation), true); if (!empty($environmentSettings)) { $settings = self::mergeSettings($settings, $environmentSettings); } } } $this->settings = self::objectify($settings); }
[ "private", "function", "loadFromLocation", "(", "$", "location", ")", "{", "Logger", "::", "get", "(", ")", "->", "debug", "(", "'Loading settings...'", ")", ";", "// Add the trailing slash to the folder if it is missing.", "if", "(", "substr", "(", "$", "location", ",", "-", "1", ")", "!=", "DIRECTORY_SEPARATOR", ")", "{", "$", "location", ".=", "DIRECTORY_SEPARATOR", ";", "}", "$", "settingsLocation", "=", "$", "location", ".", "'settings.json'", ";", "if", "(", "!", "is_readable", "(", "$", "settingsLocation", ")", ")", "{", "Logger", "::", "get", "(", ")", "->", "error", "(", "'Settings file %s cannot be read.'", ",", "$", "settingsLocation", ")", ";", "throw", "new", "Settings", "\\", "Exception", "(", "\"Settings file $settingsLocation is unavailable.\"", ")", ";", "}", "// Load the settings.", "$", "settings", "=", "json_decode", "(", "file_get_contents", "(", "$", "settingsLocation", ")", ",", "true", ")", ";", "if", "(", "empty", "(", "$", "settings", ")", ")", "{", "throw", "new", "Settings", "\\", "Exception", "(", "'Settings file cannot be parsed.'", ")", ";", "}", "// Load settings customised for the current environment.", "$", "environmentSettings", "=", "null", ";", "$", "environment", "=", "self", "::", "getEnvironment", "(", ")", ";", "if", "(", "$", "environment", ")", "{", "$", "environmentSettingsLocation", "=", "sprintf", "(", "'%ssettings-%s.json'", ",", "$", "location", ",", "strtolower", "(", "$", "environment", ")", ")", ";", "if", "(", "is_readable", "(", "$", "environmentSettingsLocation", ")", ")", "{", "$", "environmentSettings", "=", "json_decode", "(", "file_get_contents", "(", "$", "environmentSettingsLocation", ")", ",", "true", ")", ";", "if", "(", "!", "empty", "(", "$", "environmentSettings", ")", ")", "{", "$", "settings", "=", "self", "::", "mergeSettings", "(", "$", "settings", ",", "$", "environmentSettings", ")", ";", "}", "}", "}", "$", "this", "->", "settings", "=", "self", "::", "objectify", "(", "$", "settings", ")", ";", "}" ]
Load settings from a file. @param string $location The location of the settings file. @throws Settings\Exception
[ "Load", "settings", "from", "a", "file", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Settings.php#L53-L96
241,202
eix/core
src/php/main/Eix/Core/Settings.php
Settings.objectify
private static function objectify( array $array ) { foreach ($array as &$item) { if (is_array($item)) { $item = self::objectify($item); } } return (object)$array; }
php
private static function objectify( array $array ) { foreach ($array as &$item) { if (is_array($item)) { $item = self::objectify($item); } } return (object)$array; }
[ "private", "static", "function", "objectify", "(", "array", "$", "array", ")", "{", "foreach", "(", "$", "array", "as", "&", "$", "item", ")", "{", "if", "(", "is_array", "(", "$", "item", ")", ")", "{", "$", "item", "=", "self", "::", "objectify", "(", "$", "item", ")", ";", "}", "}", "return", "(", "object", ")", "$", "array", ";", "}" ]
Converts an array to an object recursively. @param array $array the array to convert @return object the converted array
[ "Converts", "an", "array", "to", "an", "object", "recursively", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Settings.php#L152-L162
241,203
eix/core
src/php/main/Eix/Core/Settings.php
Settings.getEnvironment
public static function getEnvironment() { if (empty(self::$environment)) { self::$environment = getenv(self::ENV) ?: @$_SERVER[self::ENV] ?: @$_ENV[self::ENV]; // If the environment cannot be inferred, assume production. if (empty(self::$environment)) { self::$environment = self::ENV_PRODUCTION; } } return self::$environment; }
php
public static function getEnvironment() { if (empty(self::$environment)) { self::$environment = getenv(self::ENV) ?: @$_SERVER[self::ENV] ?: @$_ENV[self::ENV]; // If the environment cannot be inferred, assume production. if (empty(self::$environment)) { self::$environment = self::ENV_PRODUCTION; } } return self::$environment; }
[ "public", "static", "function", "getEnvironment", "(", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "environment", ")", ")", "{", "self", "::", "$", "environment", "=", "getenv", "(", "self", "::", "ENV", ")", "?", ":", "@", "$", "_SERVER", "[", "self", "::", "ENV", "]", "?", ":", "@", "$", "_ENV", "[", "self", "::", "ENV", "]", ";", "// If the environment cannot be inferred, assume production.", "if", "(", "empty", "(", "self", "::", "$", "environment", ")", ")", "{", "self", "::", "$", "environment", "=", "self", "::", "ENV_PRODUCTION", ";", "}", "}", "return", "self", "::", "$", "environment", ";", "}" ]
Find out the current environment. @return string the current environment.
[ "Find", "out", "the", "current", "environment", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Settings.php#L182-L196
241,204
eix/core
src/php/main/Eix/Core/Settings.php
Settings.mergeSettings
public static function mergeSettings( $generalSettings, $environmentSettings ) { $mergedSettings = $generalSettings; foreach ($environmentSettings as $key => &$value) { if ( is_array($value) && isset($mergedSettings[$key]) && is_array($mergedSettings [$key]) ) { $mergedSettings[$key] = self::mergeSettings($mergedSettings[$key], $value); } else { $mergedSettings[$key] = $value; } } return $mergedSettings; }
php
public static function mergeSettings( $generalSettings, $environmentSettings ) { $mergedSettings = $generalSettings; foreach ($environmentSettings as $key => &$value) { if ( is_array($value) && isset($mergedSettings[$key]) && is_array($mergedSettings [$key]) ) { $mergedSettings[$key] = self::mergeSettings($mergedSettings[$key], $value); } else { $mergedSettings[$key] = $value; } } return $mergedSettings; }
[ "public", "static", "function", "mergeSettings", "(", "$", "generalSettings", ",", "$", "environmentSettings", ")", "{", "$", "mergedSettings", "=", "$", "generalSettings", ";", "foreach", "(", "$", "environmentSettings", "as", "$", "key", "=>", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "isset", "(", "$", "mergedSettings", "[", "$", "key", "]", ")", "&&", "is_array", "(", "$", "mergedSettings", "[", "$", "key", "]", ")", ")", "{", "$", "mergedSettings", "[", "$", "key", "]", "=", "self", "::", "mergeSettings", "(", "$", "mergedSettings", "[", "$", "key", "]", ",", "$", "value", ")", ";", "}", "else", "{", "$", "mergedSettings", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "mergedSettings", ";", "}" ]
Merges two arrays, just like array_merge_recursive, but the second array overwrites the first one's values if there is a match. @param array $generalSettings the base array @param array $environmentSettings the overwriting array @return array the merged settings.
[ "Merges", "two", "arrays", "just", "like", "array_merge_recursive", "but", "the", "second", "array", "overwrites", "the", "first", "one", "s", "values", "if", "there", "is", "a", "match", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Settings.php#L207-L226
241,205
FlorianWolters/PHP-Component-Core-Equality
src/main/php/EqualityUtils.php
EqualityUtils.isEqual
public static function isEqual( EqualityInterface $first = null, EqualityInterface $second = null ) { $result = false; if (null === $first) { $result = (null === $second) ? true : false; } else { $result = $first->equals($second); } return $result; }
php
public static function isEqual( EqualityInterface $first = null, EqualityInterface $second = null ) { $result = false; if (null === $first) { $result = (null === $second) ? true : false; } else { $result = $first->equals($second); } return $result; }
[ "public", "static", "function", "isEqual", "(", "EqualityInterface", "$", "first", "=", "null", ",", "EqualityInterface", "$", "second", "=", "null", ")", "{", "$", "result", "=", "false", ";", "if", "(", "null", "===", "$", "first", ")", "{", "$", "result", "=", "(", "null", "===", "$", "second", ")", "?", "true", ":", "false", ";", "}", "else", "{", "$", "result", "=", "$", "first", "->", "equals", "(", "$", "second", ")", ";", "}", "return", "$", "result", ";", "}" ]
Indicates whether the two specified objects are "equal". @param EqualityInterface|null $first The first reference object with which to compare. @param EqualityInterface|null $second The second reference object with which to compare. @return bool `true` if the two specified objects are the same; `false` otherwise.
[ "Indicates", "whether", "the", "two", "specified", "objects", "are", "equal", "." ]
6c152ce6032674c7103a456e5e3ff7f622aa8e03
https://github.com/FlorianWolters/PHP-Component-Core-Equality/blob/6c152ce6032674c7103a456e5e3ff7f622aa8e03/src/main/php/EqualityUtils.php#L51-L64
241,206
FlorianWolters/PHP-Component-Core-Equality
src/main/php/EqualityUtils.php
EqualityUtils.isNotEqual
public static function isNotEqual( EqualityInterface $first = null, EqualityInterface $second = null ) { return false === self::isEqual($first, $second); }
php
public static function isNotEqual( EqualityInterface $first = null, EqualityInterface $second = null ) { return false === self::isEqual($first, $second); }
[ "public", "static", "function", "isNotEqual", "(", "EqualityInterface", "$", "first", "=", "null", ",", "EqualityInterface", "$", "second", "=", "null", ")", "{", "return", "false", "===", "self", "::", "isEqual", "(", "$", "first", ",", "$", "second", ")", ";", "}" ]
Indicates whether the two specified objects are not "equal". @param EqualityInterface|null $first The first reference object with which to compare. @param EqualityInterface|null $second The second reference object with which to compare. @return bool `true` if the two specified objects are not the same; `false` otherwise.
[ "Indicates", "whether", "the", "two", "specified", "objects", "are", "not", "equal", "." ]
6c152ce6032674c7103a456e5e3ff7f622aa8e03
https://github.com/FlorianWolters/PHP-Component-Core-Equality/blob/6c152ce6032674c7103a456e5e3ff7f622aa8e03/src/main/php/EqualityUtils.php#L77-L82
241,207
phlexible/phlexible
src/Phlexible/Bundle/MediaTemplateBundle/Controller/FormController.php
FormController.loadAction
public function loadAction(Request $request) { $repository = $this->get('phlexible_media_template.template_manager'); $templateKey = $request->get('template_key'); $template = $repository->find($templateKey); $parameters = $template->getParameters(); if (isset($parameters['method'])) { $parameters['xmethod'] = $parameters['method']; unset($parameters['method']); } return new JsonResponse(['success' => true, 'data' => $parameters]); }
php
public function loadAction(Request $request) { $repository = $this->get('phlexible_media_template.template_manager'); $templateKey = $request->get('template_key'); $template = $repository->find($templateKey); $parameters = $template->getParameters(); if (isset($parameters['method'])) { $parameters['xmethod'] = $parameters['method']; unset($parameters['method']); } return new JsonResponse(['success' => true, 'data' => $parameters]); }
[ "public", "function", "loadAction", "(", "Request", "$", "request", ")", "{", "$", "repository", "=", "$", "this", "->", "get", "(", "'phlexible_media_template.template_manager'", ")", ";", "$", "templateKey", "=", "$", "request", "->", "get", "(", "'template_key'", ")", ";", "$", "template", "=", "$", "repository", "->", "find", "(", "$", "templateKey", ")", ";", "$", "parameters", "=", "$", "template", "->", "getParameters", "(", ")", ";", "if", "(", "isset", "(", "$", "parameters", "[", "'method'", "]", ")", ")", "{", "$", "parameters", "[", "'xmethod'", "]", "=", "$", "parameters", "[", "'method'", "]", ";", "unset", "(", "$", "parameters", "[", "'method'", "]", ")", ";", "}", "return", "new", "JsonResponse", "(", "[", "'success'", "=>", "true", ",", "'data'", "=>", "$", "parameters", "]", ")", ";", "}" ]
List variables. @param Request $request @return JsonResponse @Route("/load", name="mediatemplates_form_load")
[ "List", "variables", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/MediaTemplateBundle/Controller/FormController.php#L38-L53
241,208
phlexible/phlexible
src/Phlexible/Bundle/MediaTemplateBundle/Controller/FormController.php
FormController.saveAction
public function saveAction(Request $request) { $repository = $this->get('phlexible_media_template.template_manager'); $templateKey = $request->get('template_key'); $params = $request->request->all(); unset($params['template_key'], $params['module'], $params['controller'], $params['action']); $template = $repository->find($templateKey); $params = $this->fixParams($params); foreach ($params as $key => $value) { $template->setParameter($key, $value); } $repository->updateTemplate($template); return new ResultResponse(true, 'Media template "'.$template->getKey().'" saved.'); }
php
public function saveAction(Request $request) { $repository = $this->get('phlexible_media_template.template_manager'); $templateKey = $request->get('template_key'); $params = $request->request->all(); unset($params['template_key'], $params['module'], $params['controller'], $params['action']); $template = $repository->find($templateKey); $params = $this->fixParams($params); foreach ($params as $key => $value) { $template->setParameter($key, $value); } $repository->updateTemplate($template); return new ResultResponse(true, 'Media template "'.$template->getKey().'" saved.'); }
[ "public", "function", "saveAction", "(", "Request", "$", "request", ")", "{", "$", "repository", "=", "$", "this", "->", "get", "(", "'phlexible_media_template.template_manager'", ")", ";", "$", "templateKey", "=", "$", "request", "->", "get", "(", "'template_key'", ")", ";", "$", "params", "=", "$", "request", "->", "request", "->", "all", "(", ")", ";", "unset", "(", "$", "params", "[", "'template_key'", "]", ",", "$", "params", "[", "'module'", "]", ",", "$", "params", "[", "'controller'", "]", ",", "$", "params", "[", "'action'", "]", ")", ";", "$", "template", "=", "$", "repository", "->", "find", "(", "$", "templateKey", ")", ";", "$", "params", "=", "$", "this", "->", "fixParams", "(", "$", "params", ")", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "template", "->", "setParameter", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "repository", "->", "updateTemplate", "(", "$", "template", ")", ";", "return", "new", "ResultResponse", "(", "true", ",", "'Media template \"'", ".", "$", "template", "->", "getKey", "(", ")", ".", "'\" saved.'", ")", ";", "}" ]
Save variables. @param Request $request @return ResultResponse @Route("/save", name="mediatemplates_form_save")
[ "Save", "variables", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/MediaTemplateBundle/Controller/FormController.php#L63-L86
241,209
matryoshka-model/mongo-wrapper
library/Hydrator/Strategy/MongoIdStrategy.php
MongoIdStrategy.hydrate
public function hydrate($value) { if ($value instanceof MongoId) { return (string)$value; } if ($this->nullable && $value === null) { return null; } throw new Exception\InvalidArgumentException(sprintf( 'Invalid value: must be an instance of MongoId, "%s" given.', is_object($value) ? get_class($value) : gettype($value) )); }
php
public function hydrate($value) { if ($value instanceof MongoId) { return (string)$value; } if ($this->nullable && $value === null) { return null; } throw new Exception\InvalidArgumentException(sprintf( 'Invalid value: must be an instance of MongoId, "%s" given.', is_object($value) ? get_class($value) : gettype($value) )); }
[ "public", "function", "hydrate", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "MongoId", ")", "{", "return", "(", "string", ")", "$", "value", ";", "}", "if", "(", "$", "this", "->", "nullable", "&&", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid value: must be an instance of MongoId, \"%s\" given.'", ",", "is_object", "(", "$", "value", ")", "?", "get_class", "(", "$", "value", ")", ":", "gettype", "(", "$", "value", ")", ")", ")", ";", "}" ]
Ensure the value extracted is typed as string or null @param mixed $value The original value. @return null|string Returns the value that should be hydrated.
[ "Ensure", "the", "value", "extracted", "is", "typed", "as", "string", "or", "null" ]
d69511d7f7fc58e708c771ea0cd3c8ba7e8a155a
https://github.com/matryoshka-model/mongo-wrapper/blob/d69511d7f7fc58e708c771ea0cd3c8ba7e8a155a/library/Hydrator/Strategy/MongoIdStrategy.php#L30-L44
241,210
matryoshka-model/mongo-wrapper
library/Hydrator/Strategy/MongoIdStrategy.php
MongoIdStrategy.extract
public function extract($value) { if (is_string($value)) { return new MongoId($value); } if ($this->nullable && $value === null) { return null; } throw new Exception\InvalidArgumentException(sprintf( 'Invalid value: must be a string containing a valid mongo ID, "%s" given.', is_object($value) ? get_class($value) : gettype($value) )); }
php
public function extract($value) { if (is_string($value)) { return new MongoId($value); } if ($this->nullable && $value === null) { return null; } throw new Exception\InvalidArgumentException(sprintf( 'Invalid value: must be a string containing a valid mongo ID, "%s" given.', is_object($value) ? get_class($value) : gettype($value) )); }
[ "public", "function", "extract", "(", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "return", "new", "MongoId", "(", "$", "value", ")", ";", "}", "if", "(", "$", "this", "->", "nullable", "&&", "$", "value", "===", "null", ")", "{", "return", "null", ";", "}", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid value: must be a string containing a valid mongo ID, \"%s\" given.'", ",", "is_object", "(", "$", "value", ")", "?", "get_class", "(", "$", "value", ")", ":", "gettype", "(", "$", "value", ")", ")", ")", ";", "}" ]
Ensure the value extracted is typed as MongoId or null @param mixed $value The original value. @return null|MongoId Returns the value that should be extracted.
[ "Ensure", "the", "value", "extracted", "is", "typed", "as", "MongoId", "or", "null" ]
d69511d7f7fc58e708c771ea0cd3c8ba7e8a155a
https://github.com/matryoshka-model/mongo-wrapper/blob/d69511d7f7fc58e708c771ea0cd3c8ba7e8a155a/library/Hydrator/Strategy/MongoIdStrategy.php#L53-L67
241,211
FuturaSoft/Pabana
src/Mvc/Layout.php
Layout.element
public function element($elementName) { if (Configuration::read('mvc.autoload_shared_var') === true && empty($this->variableList) === false) { foreach ($this->variableList as $varName => $varValue) { ${$varName} = $varValue; } } $layoutDirectory = $this->getDirectory() . '/' . $this->getName(); $elementPath = $layoutDirectory . '/' . $elementName . '.' . $this->getExtension(); if (!file_exists($elementPath)) { trigger_error('Element file "' . $elementPath . '" doesn\'t exist.', E_USER_ERROR); return false; } ob_start(); require($elementPath); echo PHP_EOL; $bodyContent = ob_get_clean(); return $bodyContent; }
php
public function element($elementName) { if (Configuration::read('mvc.autoload_shared_var') === true && empty($this->variableList) === false) { foreach ($this->variableList as $varName => $varValue) { ${$varName} = $varValue; } } $layoutDirectory = $this->getDirectory() . '/' . $this->getName(); $elementPath = $layoutDirectory . '/' . $elementName . '.' . $this->getExtension(); if (!file_exists($elementPath)) { trigger_error('Element file "' . $elementPath . '" doesn\'t exist.', E_USER_ERROR); return false; } ob_start(); require($elementPath); echo PHP_EOL; $bodyContent = ob_get_clean(); return $bodyContent; }
[ "public", "function", "element", "(", "$", "elementName", ")", "{", "if", "(", "Configuration", "::", "read", "(", "'mvc.autoload_shared_var'", ")", "===", "true", "&&", "empty", "(", "$", "this", "->", "variableList", ")", "===", "false", ")", "{", "foreach", "(", "$", "this", "->", "variableList", "as", "$", "varName", "=>", "$", "varValue", ")", "{", "$", "{", "$", "varName", "}", "=", "$", "varValue", ";", "}", "}", "$", "layoutDirectory", "=", "$", "this", "->", "getDirectory", "(", ")", ".", "'/'", ".", "$", "this", "->", "getName", "(", ")", ";", "$", "elementPath", "=", "$", "layoutDirectory", ".", "'/'", ".", "$", "elementName", ".", "'.'", ".", "$", "this", "->", "getExtension", "(", ")", ";", "if", "(", "!", "file_exists", "(", "$", "elementPath", ")", ")", "{", "trigger_error", "(", "'Element file \"'", ".", "$", "elementPath", ".", "'\" doesn\\'t exist.'", ",", "E_USER_ERROR", ")", ";", "return", "false", ";", "}", "ob_start", "(", ")", ";", "require", "(", "$", "elementPath", ")", ";", "echo", "PHP_EOL", ";", "$", "bodyContent", "=", "ob_get_clean", "(", ")", ";", "return", "$", "bodyContent", ";", "}" ]
Load part of Layout Load Html code of part @since 1.0 @param string $elementName Element or part name @return string|bool Return Element content if success or false if error
[ "Load", "part", "of", "Layout" ]
b3a95eeb976042ac2a393cc10755a7adbc164c24
https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Mvc/Layout.php#L147-L165
241,212
FuturaSoft/Pabana
src/Mvc/Layout.php
Layout.setVar
public function setVar($varName, $varValue, $force = false) { if (isset($this->variableList[$varName]) && $force === false) { trigger_error('Variable "' . $varName . '" is already defined in Layout.', E_USER_WARNING); return false; } $this->variableList[$varName] = $varValue; return true; }
php
public function setVar($varName, $varValue, $force = false) { if (isset($this->variableList[$varName]) && $force === false) { trigger_error('Variable "' . $varName . '" is already defined in Layout.', E_USER_WARNING); return false; } $this->variableList[$varName] = $varValue; return true; }
[ "public", "function", "setVar", "(", "$", "varName", ",", "$", "varValue", ",", "$", "force", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "variableList", "[", "$", "varName", "]", ")", "&&", "$", "force", "===", "false", ")", "{", "trigger_error", "(", "'Variable \"'", ".", "$", "varName", ".", "'\" is already defined in Layout.'", ",", "E_USER_WARNING", ")", ";", "return", "false", ";", "}", "$", "this", "->", "variableList", "[", "$", "varName", "]", "=", "$", "varValue", ";", "return", "true", ";", "}" ]
Set var to Layout @since 1.0 @param string $varName Name of var send to View @param string $varValue Value of var send to View @param bool $force Force change of var value if var already exist @return bool Return true
[ "Set", "var", "to", "Layout" ]
b3a95eeb976042ac2a393cc10755a7adbc164c24
https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Mvc/Layout.php#L295-L303
241,213
shizhice/support
src/Arr.php
Arr.except
static public function except(array $input, $keys) { $keys = is_array($keys) ? $keys : array_slice(func_get_args(),1); foreach ($keys as $key) { unset($input[$key]); } return $input; }
php
static public function except(array $input, $keys) { $keys = is_array($keys) ? $keys : array_slice(func_get_args(),1); foreach ($keys as $key) { unset($input[$key]); } return $input; }
[ "static", "public", "function", "except", "(", "array", "$", "input", ",", "$", "keys", ")", "{", "$", "keys", "=", "is_array", "(", "$", "keys", ")", "?", "$", "keys", ":", "array_slice", "(", "func_get_args", "(", ")", ",", "1", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "unset", "(", "$", "input", "[", "$", "key", "]", ")", ";", "}", "return", "$", "input", ";", "}" ]
return except key data from array @param array $input @param $keys @return array
[ "return", "except", "key", "data", "from", "array" ]
75b05fb28840767979396d6693120a8d5c22bdbc
https://github.com/shizhice/support/blob/75b05fb28840767979396d6693120a8d5c22bdbc/src/Arr.php#L31-L40
241,214
shizhice/support
src/Arr.php
Arr.extend
static public function extend(array $to, array $from) { foreach ($from as $key => $value) { if (is_array($value)) { $to[$key] = self::extend((array) (isset($to[$key]) ? $to[$key] : []),$value); }else{ $to[$key] = $value; } } return $to; }
php
static public function extend(array $to, array $from) { foreach ($from as $key => $value) { if (is_array($value)) { $to[$key] = self::extend((array) (isset($to[$key]) ? $to[$key] : []),$value); }else{ $to[$key] = $value; } } return $to; }
[ "static", "public", "function", "extend", "(", "array", "$", "to", ",", "array", "$", "from", ")", "{", "foreach", "(", "$", "from", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "to", "[", "$", "key", "]", "=", "self", "::", "extend", "(", "(", "array", ")", "(", "isset", "(", "$", "to", "[", "$", "key", "]", ")", "?", "$", "to", "[", "$", "key", "]", ":", "[", "]", ")", ",", "$", "value", ")", ";", "}", "else", "{", "$", "to", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "to", ";", "}" ]
extend a array @param array $to @param array $from @return array
[ "extend", "a", "array" ]
75b05fb28840767979396d6693120a8d5c22bdbc
https://github.com/shizhice/support/blob/75b05fb28840767979396d6693120a8d5c22bdbc/src/Arr.php#L48-L58
241,215
shizhice/support
src/Arr.php
Arr.xmlToArray
static public function xmlToArray($xml) { //禁止引用外部xml实体 libxml_disable_entity_loader(true); $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $values; }
php
static public function xmlToArray($xml) { //禁止引用外部xml实体 libxml_disable_entity_loader(true); $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); return $values; }
[ "static", "public", "function", "xmlToArray", "(", "$", "xml", ")", "{", "//禁止引用外部xml实体", "libxml_disable_entity_loader", "(", "true", ")", ";", "$", "values", "=", "json_decode", "(", "json_encode", "(", "simplexml_load_string", "(", "$", "xml", ",", "'SimpleXMLElement'", ",", "LIBXML_NOCDATA", ")", ")", ",", "true", ")", ";", "return", "$", "values", ";", "}" ]
xml to array @param $xml @return mixed
[ "xml", "to", "array" ]
75b05fb28840767979396d6693120a8d5c22bdbc
https://github.com/shizhice/support/blob/75b05fb28840767979396d6693120a8d5c22bdbc/src/Arr.php#L85-L91
241,216
shizhice/support
src/Arr.php
Arr.replaceArrayKey
static public function replaceArrayKey($arr = [],$field = '') { $newArr = []; if($arr){ foreach ($arr as $value) { $newArr[$value[$field]] = $value; } } return $newArr; }
php
static public function replaceArrayKey($arr = [],$field = '') { $newArr = []; if($arr){ foreach ($arr as $value) { $newArr[$value[$field]] = $value; } } return $newArr; }
[ "static", "public", "function", "replaceArrayKey", "(", "$", "arr", "=", "[", "]", ",", "$", "field", "=", "''", ")", "{", "$", "newArr", "=", "[", "]", ";", "if", "(", "$", "arr", ")", "{", "foreach", "(", "$", "arr", "as", "$", "value", ")", "{", "$", "newArr", "[", "$", "value", "[", "$", "field", "]", "]", "=", "$", "value", ";", "}", "}", "return", "$", "newArr", ";", "}" ]
replace array key @param array $arr @param string $field @return array
[ "replace", "array", "key" ]
75b05fb28840767979396d6693120a8d5c22bdbc
https://github.com/shizhice/support/blob/75b05fb28840767979396d6693120a8d5c22bdbc/src/Arr.php#L146-L155
241,217
shizhice/support
src/Arr.php
Arr.replaceArrayKeyWithArray
static public function replaceArrayKeyWithArray($arr = [],$field = '') { $newArr = []; if($arr){ foreach ($arr as $value) { $newArr[$value[$field]][] = $value; } } return $newArr; }
php
static public function replaceArrayKeyWithArray($arr = [],$field = '') { $newArr = []; if($arr){ foreach ($arr as $value) { $newArr[$value[$field]][] = $value; } } return $newArr; }
[ "static", "public", "function", "replaceArrayKeyWithArray", "(", "$", "arr", "=", "[", "]", ",", "$", "field", "=", "''", ")", "{", "$", "newArr", "=", "[", "]", ";", "if", "(", "$", "arr", ")", "{", "foreach", "(", "$", "arr", "as", "$", "value", ")", "{", "$", "newArr", "[", "$", "value", "[", "$", "field", "]", "]", "[", "]", "=", "$", "value", ";", "}", "}", "return", "$", "newArr", ";", "}" ]
replace array key with array @param array $arr @param string $field @return array
[ "replace", "array", "key", "with", "array" ]
75b05fb28840767979396d6693120a8d5c22bdbc
https://github.com/shizhice/support/blob/75b05fb28840767979396d6693120a8d5c22bdbc/src/Arr.php#L163-L172
241,218
monolyth-php/formulaic
src/JsonSerialize.php
JsonSerialize.jsonSerialize
public function jsonSerialize() { $copy = []; foreach ((array)$this as $key => $value) { if (!is_string($value)) { $element = $value->getElement(); if (is_object($element) and method_exists($element, 'name') and $name = $element->name() ) { $copy[$name] = $value instanceof JsonSerializable ? $value->jsonSerialize() : $value; } $copy[$key] = $value instanceof JsonSerializable ? $value->jsonSerialize() : $value; } else { $copy[$key] = $value; } } return $copy; }
php
public function jsonSerialize() { $copy = []; foreach ((array)$this as $key => $value) { if (!is_string($value)) { $element = $value->getElement(); if (is_object($element) and method_exists($element, 'name') and $name = $element->name() ) { $copy[$name] = $value instanceof JsonSerializable ? $value->jsonSerialize() : $value; } $copy[$key] = $value instanceof JsonSerializable ? $value->jsonSerialize() : $value; } else { $copy[$key] = $value; } } return $copy; }
[ "public", "function", "jsonSerialize", "(", ")", "{", "$", "copy", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "this", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", ")", "{", "$", "element", "=", "$", "value", "->", "getElement", "(", ")", ";", "if", "(", "is_object", "(", "$", "element", ")", "and", "method_exists", "(", "$", "element", ",", "'name'", ")", "and", "$", "name", "=", "$", "element", "->", "name", "(", ")", ")", "{", "$", "copy", "[", "$", "name", "]", "=", "$", "value", "instanceof", "JsonSerializable", "?", "$", "value", "->", "jsonSerialize", "(", ")", ":", "$", "value", ";", "}", "$", "copy", "[", "$", "key", "]", "=", "$", "value", "instanceof", "JsonSerializable", "?", "$", "value", "->", "jsonSerialize", "(", ")", ":", "$", "value", ";", "}", "else", "{", "$", "copy", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "copy", ";", "}" ]
Returns a `json_encode`able hash. @return array
[ "Returns", "a", "json_encode", "able", "hash", "." ]
4bf7853a0c29cc17957f1b26c79f633867742c14
https://github.com/monolyth-php/formulaic/blob/4bf7853a0c29cc17957f1b26c79f633867742c14/src/JsonSerialize.php#L14-L32
241,219
AnonymPHP/Anonym-Library
src/Anonym/Constructors/RequestConstructor.php
RequestConstructor.register
public function register() { $this->singleton( 'validation', function () { return new Validation(); } ); $app = &$this->app; // register the request $this->singleton( 'http.request', function () use (&$app) { $request = new Request($app['validation']); $request->header('X-FRAMEWORK-NAME', $app->getName()); $request->header('X-FRAMEWORK-VERSION', $app->getVersion()); return $request; }, true ); // register the response $this->bind( 'http.response', function () use (&$app) { return $app->make('http.request')->getResponse(); }, true ); }
php
public function register() { $this->singleton( 'validation', function () { return new Validation(); } ); $app = &$this->app; // register the request $this->singleton( 'http.request', function () use (&$app) { $request = new Request($app['validation']); $request->header('X-FRAMEWORK-NAME', $app->getName()); $request->header('X-FRAMEWORK-VERSION', $app->getVersion()); return $request; }, true ); // register the response $this->bind( 'http.response', function () use (&$app) { return $app->make('http.request')->getResponse(); }, true ); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "singleton", "(", "'validation'", ",", "function", "(", ")", "{", "return", "new", "Validation", "(", ")", ";", "}", ")", ";", "$", "app", "=", "&", "$", "this", "->", "app", ";", "// register the request", "$", "this", "->", "singleton", "(", "'http.request'", ",", "function", "(", ")", "use", "(", "&", "$", "app", ")", "{", "$", "request", "=", "new", "Request", "(", "$", "app", "[", "'validation'", "]", ")", ";", "$", "request", "->", "header", "(", "'X-FRAMEWORK-NAME'", ",", "$", "app", "->", "getName", "(", ")", ")", ";", "$", "request", "->", "header", "(", "'X-FRAMEWORK-VERSION'", ",", "$", "app", "->", "getVersion", "(", ")", ")", ";", "return", "$", "request", ";", "}", ",", "true", ")", ";", "// register the response", "$", "this", "->", "bind", "(", "'http.response'", ",", "function", "(", ")", "use", "(", "&", "$", "app", ")", "{", "return", "$", "app", "->", "make", "(", "'http.request'", ")", "->", "getResponse", "(", ")", ";", "}", ",", "true", ")", ";", "}" ]
add the request and response to container
[ "add", "the", "request", "and", "response", "to", "container" ]
c967ad804f84e8fb204593a0959cda2fed5ae075
https://github.com/AnonymPHP/Anonym-Library/blob/c967ad804f84e8fb204593a0959cda2fed5ae075/src/Anonym/Constructors/RequestConstructor.php#L30-L65
241,220
xinc-develop/xinc-core
src/Plugin/Property/SetTask.php
SetTask.setName
public function setName($name, $build) { $this->_name = (string) $name; if (isset($this->_name) && isset($this->_value)) { $build->getProperties()->set($this->_name, $this->_value); } }
php
public function setName($name, $build) { $this->_name = (string) $name; if (isset($this->_name) && isset($this->_value)) { $build->getProperties()->set($this->_name, $this->_value); } }
[ "public", "function", "setName", "(", "$", "name", ",", "$", "build", ")", "{", "$", "this", "->", "_name", "=", "(", "string", ")", "$", "name", ";", "if", "(", "isset", "(", "$", "this", "->", "_name", ")", "&&", "isset", "(", "$", "this", "->", "_value", ")", ")", "{", "$", "build", "->", "getProperties", "(", ")", "->", "set", "(", "$", "this", "->", "_name", ",", "$", "this", "->", "_value", ")", ";", "}", "}" ]
sets the name of the property. @param string $name
[ "sets", "the", "name", "of", "the", "property", "." ]
4bb69a6afe19e1186950a3122cbfe0989823e0d6
https://github.com/xinc-develop/xinc-core/blob/4bb69a6afe19e1186950a3122cbfe0989823e0d6/src/Plugin/Property/SetTask.php#L64-L70
241,221
xinc-develop/xinc-core
src/Plugin/Property/SetTask.php
SetTask.setValue
public function setValue($value, $build) { $this->_value = (string) $value; if (isset($this->_name) && isset($this->_value)) { $build->setProperty($this->_name, $this->_value); } }
php
public function setValue($value, $build) { $this->_value = (string) $value; if (isset($this->_name) && isset($this->_value)) { $build->setProperty($this->_name, $this->_value); } }
[ "public", "function", "setValue", "(", "$", "value", ",", "$", "build", ")", "{", "$", "this", "->", "_value", "=", "(", "string", ")", "$", "value", ";", "if", "(", "isset", "(", "$", "this", "->", "_name", ")", "&&", "isset", "(", "$", "this", "->", "_value", ")", ")", "{", "$", "build", "->", "setProperty", "(", "$", "this", "->", "_name", ",", "$", "this", "->", "_value", ")", ";", "}", "}" ]
sets the value of the property. @param string $value
[ "sets", "the", "value", "of", "the", "property", "." ]
4bb69a6afe19e1186950a3122cbfe0989823e0d6
https://github.com/xinc-develop/xinc-core/blob/4bb69a6afe19e1186950a3122cbfe0989823e0d6/src/Plugin/Property/SetTask.php#L77-L83
241,222
xinc-develop/xinc-core
src/Plugin/Property/SetTask.php
SetTask.validate
public function validate(&$msg = null) { if (!isset($this->_name) && !isset($this->_value) && !isset($this->_file)) { return false; } elseif (isset($this->_file) && (isset($this->_name) || isset($this->_value))) { return false; } elseif ((isset($this->_name) && !isset($this->_value)) || (!isset($this->_name) && isset($this->_value))) { return false; } else { return true; } }
php
public function validate(&$msg = null) { if (!isset($this->_name) && !isset($this->_value) && !isset($this->_file)) { return false; } elseif (isset($this->_file) && (isset($this->_name) || isset($this->_value))) { return false; } elseif ((isset($this->_name) && !isset($this->_value)) || (!isset($this->_name) && isset($this->_value))) { return false; } else { return true; } }
[ "public", "function", "validate", "(", "&", "$", "msg", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_name", ")", "&&", "!", "isset", "(", "$", "this", "->", "_value", ")", "&&", "!", "isset", "(", "$", "this", "->", "_file", ")", ")", "{", "return", "false", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "_file", ")", "&&", "(", "isset", "(", "$", "this", "->", "_name", ")", "||", "isset", "(", "$", "this", "->", "_value", ")", ")", ")", "{", "return", "false", ";", "}", "elseif", "(", "(", "isset", "(", "$", "this", "->", "_name", ")", "&&", "!", "isset", "(", "$", "this", "->", "_value", ")", ")", "||", "(", "!", "isset", "(", "$", "this", "->", "_name", ")", "&&", "isset", "(", "$", "this", "->", "_value", ")", ")", ")", "{", "return", "false", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Validates if a task can run by checking configs, directries and so on. @return bool Is true if task can run
[ "Validates", "if", "a", "task", "can", "run", "by", "checking", "configs", "directries", "and", "so", "on", "." ]
4bb69a6afe19e1186950a3122cbfe0989823e0d6
https://github.com/xinc-develop/xinc-core/blob/4bb69a6afe19e1186950a3122cbfe0989823e0d6/src/Plugin/Property/SetTask.php#L100-L111
241,223
unimatrix/cake
src/Model/Behavior/UploadableBehavior.php
UploadableBehavior.beforeMarshal
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { // configuration set? $this->check(); // load validator and add our custom upload validator $validator = $this->_table->getValidator(); $validator->setProvider('upload', UploadValidation::class); // go through each field foreach($this->_config['fields'] as $field => $path) { // add validators $validator->add($field, [ 'isUnderPhpSizeLimit' => ['rule' => 'isUnderPhpSizeLimit', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'This file is too large')], 'isUnderFormSizeLimit' => ['rule' => 'isUnderFormSizeLimit', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'This file is too large')], 'isCompletedUpload' => ['rule' => 'isCompletedUpload', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'This file was only partially uploaded')], 'isTemporaryDirectory' => ['rule' => 'isTemporaryDirectory', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'Missing a temporary folder')], 'isSuccessfulWrite' => ['rule' => 'isSuccessfulWrite', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'Failed to write file to disk')], 'isNotStoppedByExtension' => ['rule' => 'isNotStoppedByExtension', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'Upload was stopped by extension')], ]); // empty allowed? && no file uploaded? unset field if($validator->isEmptyAllowed($field, false) && isset($data[$field]['error']) && $data[$field]['error'] === UPLOAD_ERR_NO_FILE) unset($data[$field]); } }
php
public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { // configuration set? $this->check(); // load validator and add our custom upload validator $validator = $this->_table->getValidator(); $validator->setProvider('upload', UploadValidation::class); // go through each field foreach($this->_config['fields'] as $field => $path) { // add validators $validator->add($field, [ 'isUnderPhpSizeLimit' => ['rule' => 'isUnderPhpSizeLimit', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'This file is too large')], 'isUnderFormSizeLimit' => ['rule' => 'isUnderFormSizeLimit', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'This file is too large')], 'isCompletedUpload' => ['rule' => 'isCompletedUpload', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'This file was only partially uploaded')], 'isTemporaryDirectory' => ['rule' => 'isTemporaryDirectory', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'Missing a temporary folder')], 'isSuccessfulWrite' => ['rule' => 'isSuccessfulWrite', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'Failed to write file to disk')], 'isNotStoppedByExtension' => ['rule' => 'isNotStoppedByExtension', 'provider' => 'upload', 'message' => __d('Unimatrix/cake', 'Upload was stopped by extension')], ]); // empty allowed? && no file uploaded? unset field if($validator->isEmptyAllowed($field, false) && isset($data[$field]['error']) && $data[$field]['error'] === UPLOAD_ERR_NO_FILE) unset($data[$field]); } }
[ "public", "function", "beforeMarshal", "(", "Event", "$", "event", ",", "ArrayObject", "$", "data", ",", "ArrayObject", "$", "options", ")", "{", "// configuration set?", "$", "this", "->", "check", "(", ")", ";", "// load validator and add our custom upload validator", "$", "validator", "=", "$", "this", "->", "_table", "->", "getValidator", "(", ")", ";", "$", "validator", "->", "setProvider", "(", "'upload'", ",", "UploadValidation", "::", "class", ")", ";", "// go through each field", "foreach", "(", "$", "this", "->", "_config", "[", "'fields'", "]", "as", "$", "field", "=>", "$", "path", ")", "{", "// add validators", "$", "validator", "->", "add", "(", "$", "field", ",", "[", "'isUnderPhpSizeLimit'", "=>", "[", "'rule'", "=>", "'isUnderPhpSizeLimit'", ",", "'provider'", "=>", "'upload'", ",", "'message'", "=>", "__d", "(", "'Unimatrix/cake'", ",", "'This file is too large'", ")", "]", ",", "'isUnderFormSizeLimit'", "=>", "[", "'rule'", "=>", "'isUnderFormSizeLimit'", ",", "'provider'", "=>", "'upload'", ",", "'message'", "=>", "__d", "(", "'Unimatrix/cake'", ",", "'This file is too large'", ")", "]", ",", "'isCompletedUpload'", "=>", "[", "'rule'", "=>", "'isCompletedUpload'", ",", "'provider'", "=>", "'upload'", ",", "'message'", "=>", "__d", "(", "'Unimatrix/cake'", ",", "'This file was only partially uploaded'", ")", "]", ",", "'isTemporaryDirectory'", "=>", "[", "'rule'", "=>", "'isTemporaryDirectory'", ",", "'provider'", "=>", "'upload'", ",", "'message'", "=>", "__d", "(", "'Unimatrix/cake'", ",", "'Missing a temporary folder'", ")", "]", ",", "'isSuccessfulWrite'", "=>", "[", "'rule'", "=>", "'isSuccessfulWrite'", ",", "'provider'", "=>", "'upload'", ",", "'message'", "=>", "__d", "(", "'Unimatrix/cake'", ",", "'Failed to write file to disk'", ")", "]", ",", "'isNotStoppedByExtension'", "=>", "[", "'rule'", "=>", "'isNotStoppedByExtension'", ",", "'provider'", "=>", "'upload'", ",", "'message'", "=>", "__d", "(", "'Unimatrix/cake'", ",", "'Upload was stopped by extension'", ")", "]", ",", "]", ")", ";", "// empty allowed? && no file uploaded? unset field", "if", "(", "$", "validator", "->", "isEmptyAllowed", "(", "$", "field", ",", "false", ")", "&&", "isset", "(", "$", "data", "[", "$", "field", "]", "[", "'error'", "]", ")", "&&", "$", "data", "[", "$", "field", "]", "[", "'error'", "]", "===", "UPLOAD_ERR_NO_FILE", ")", "unset", "(", "$", "data", "[", "$", "field", "]", ")", ";", "}", "}" ]
If a field is allowed to be empty as defined in the validation it should be unset to prevent processing @param \Cake\Event\Event $event Event instance @param ArrayObject $data Data to process @return void
[ "If", "a", "field", "is", "allowed", "to", "be", "empty", "as", "defined", "in", "the", "validation", "it", "should", "be", "unset", "to", "prevent", "processing" ]
23003aba497822bd473fdbf60514052dda1874fc
https://github.com/unimatrix/cake/blob/23003aba497822bd473fdbf60514052dda1874fc/src/Model/Behavior/UploadableBehavior.php#L92-L117
241,224
sebardo/ecommerce
EcommerceBundle/Controller/PlanController.php
PlanController.newAction
public function newAction(Request $request) { $entity = new Plan(); $form = $this->createForm('EcommerceBundle\Form\PlanType', $entity); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $checkoutManager = $this->get('checkout_manager'); $checkoutManager->createPaypalPlan($entity); $checkoutManager->activePaypalPlan($entity); //if come from popup if ($request->isXMLHttpRequest()) { return new JsonResponse(array( 'id' => $entity->getId(), 'name' => $entity->getName() )); } $this->get('session')->getFlashBag()->add('success', 'plan.created'); return $this->redirectToRoute('ecommerce_plan_show', array('id' => $entity->getId())); } return array( 'entity' => $entity, 'form' => $form->createView(), ); }
php
public function newAction(Request $request) { $entity = new Plan(); $form = $this->createForm('EcommerceBundle\Form\PlanType', $entity); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($entity); $checkoutManager = $this->get('checkout_manager'); $checkoutManager->createPaypalPlan($entity); $checkoutManager->activePaypalPlan($entity); //if come from popup if ($request->isXMLHttpRequest()) { return new JsonResponse(array( 'id' => $entity->getId(), 'name' => $entity->getName() )); } $this->get('session')->getFlashBag()->add('success', 'plan.created'); return $this->redirectToRoute('ecommerce_plan_show', array('id' => $entity->getId())); } return array( 'entity' => $entity, 'form' => $form->createView(), ); }
[ "public", "function", "newAction", "(", "Request", "$", "request", ")", "{", "$", "entity", "=", "new", "Plan", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createForm", "(", "'EcommerceBundle\\Form\\PlanType'", ",", "$", "entity", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isSubmitted", "(", ")", "&&", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "entity", ")", ";", "$", "checkoutManager", "=", "$", "this", "->", "get", "(", "'checkout_manager'", ")", ";", "$", "checkoutManager", "->", "createPaypalPlan", "(", "$", "entity", ")", ";", "$", "checkoutManager", "->", "activePaypalPlan", "(", "$", "entity", ")", ";", "//if come from popup", "if", "(", "$", "request", "->", "isXMLHttpRequest", "(", ")", ")", "{", "return", "new", "JsonResponse", "(", "array", "(", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", ",", "'name'", "=>", "$", "entity", "->", "getName", "(", ")", ")", ")", ";", "}", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'success'", ",", "'plan.created'", ")", ";", "return", "$", "this", "->", "redirectToRoute", "(", "'ecommerce_plan_show'", ",", "array", "(", "'id'", "=>", "$", "entity", "->", "getId", "(", ")", ")", ")", ";", "}", "return", "array", "(", "'entity'", "=>", "$", "entity", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Creates a new Plan entity. @Route("/new") @Method({"GET", "POST"}) @Template()
[ "Creates", "a", "new", "Plan", "entity", "." ]
3e17545e69993f10a1df17f9887810c7378fc7f9
https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/PlanController.php#L68-L99
241,225
sebardo/ecommerce
EcommerceBundle/Controller/PlanController.php
PlanController.showAction
public function showAction(Plan $plan) { $deleteForm = $this->createDeleteForm($plan); //get plan $paypalPlan = $this->get('checkout_manager')->getPaypalPlan($plan); return array( 'entity' => $plan, 'delete_form' => $deleteForm->createView(), 'paypalPlan' => $paypalPlan ); }
php
public function showAction(Plan $plan) { $deleteForm = $this->createDeleteForm($plan); //get plan $paypalPlan = $this->get('checkout_manager')->getPaypalPlan($plan); return array( 'entity' => $plan, 'delete_form' => $deleteForm->createView(), 'paypalPlan' => $paypalPlan ); }
[ "public", "function", "showAction", "(", "Plan", "$", "plan", ")", "{", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "plan", ")", ";", "//get plan", "$", "paypalPlan", "=", "$", "this", "->", "get", "(", "'checkout_manager'", ")", "->", "getPaypalPlan", "(", "$", "plan", ")", ";", "return", "array", "(", "'entity'", "=>", "$", "plan", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", "'paypalPlan'", "=>", "$", "paypalPlan", ")", ";", "}" ]
Finds and displays a Plan entity. @Route("/{id}") @Method("GET") @Template()
[ "Finds", "and", "displays", "a", "Plan", "entity", "." ]
3e17545e69993f10a1df17f9887810c7378fc7f9
https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/PlanController.php#L108-L119
241,226
sebardo/ecommerce
EcommerceBundle/Controller/PlanController.php
PlanController.createDeleteForm
private function createDeleteForm(Plan $plan) { return $this->createFormBuilder() ->setAction($this->generateUrl('ecommerce_plan_delete', array('id' => $plan->getId()))) ->setMethod('DELETE') ->getForm() ; }
php
private function createDeleteForm(Plan $plan) { return $this->createFormBuilder() ->setAction($this->generateUrl('ecommerce_plan_delete', array('id' => $plan->getId()))) ->setMethod('DELETE') ->getForm() ; }
[ "private", "function", "createDeleteForm", "(", "Plan", "$", "plan", ")", "{", "return", "$", "this", "->", "createFormBuilder", "(", ")", "->", "setAction", "(", "$", "this", "->", "generateUrl", "(", "'ecommerce_plan_delete'", ",", "array", "(", "'id'", "=>", "$", "plan", "->", "getId", "(", ")", ")", ")", ")", "->", "setMethod", "(", "'DELETE'", ")", "->", "getForm", "(", ")", ";", "}" ]
Creates a form to delete a Plan entity. @param Plan $plan The Plan entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "delete", "a", "Plan", "entity", "." ]
3e17545e69993f10a1df17f9887810c7378fc7f9
https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/PlanController.php#L182-L189
241,227
dbtlr/php-env-builder
src/ComposerScriptRunner.php
ComposerScriptRunner.getEnvFile
public function getEnvFile() { $basePath = $this->getBasePath(); $envFile = $this->get('envFile'); $startsWith = substr($envFile, 0, 1); if (!$startsWith !== '/' && $startsWith !== '~' && $startsWith !== '\\') { $envFile = $basePath . DIRECTORY_SEPARATOR . $envFile; } return $envFile; }
php
public function getEnvFile() { $basePath = $this->getBasePath(); $envFile = $this->get('envFile'); $startsWith = substr($envFile, 0, 1); if (!$startsWith !== '/' && $startsWith !== '~' && $startsWith !== '\\') { $envFile = $basePath . DIRECTORY_SEPARATOR . $envFile; } return $envFile; }
[ "public", "function", "getEnvFile", "(", ")", "{", "$", "basePath", "=", "$", "this", "->", "getBasePath", "(", ")", ";", "$", "envFile", "=", "$", "this", "->", "get", "(", "'envFile'", ")", ";", "$", "startsWith", "=", "substr", "(", "$", "envFile", ",", "0", ",", "1", ")", ";", "if", "(", "!", "$", "startsWith", "!==", "'/'", "&&", "$", "startsWith", "!==", "'~'", "&&", "$", "startsWith", "!==", "'\\\\'", ")", "{", "$", "envFile", "=", "$", "basePath", ".", "DIRECTORY_SEPARATOR", ".", "$", "envFile", ";", "}", "return", "$", "envFile", ";", "}" ]
Get the full path to the env file. @return mixed|null|string
[ "Get", "the", "full", "path", "to", "the", "env", "file", "." ]
94b78bcd308d58dc7994164a87e80fe39ed871c7
https://github.com/dbtlr/php-env-builder/blob/94b78bcd308d58dc7994164a87e80fe39ed871c7/src/ComposerScriptRunner.php#L91-L101
241,228
dbtlr/php-env-builder
src/ComposerScriptRunner.php
ComposerScriptRunner.verifyExtras
protected function verifyExtras(array $extras) { if (!isset($extras['php-env-builder'])) { throw new \InvalidArgumentException( 'The parameter handler needs to be configured through the ' . 'extra.php-env-builder setting.' ); } if (!is_array($extras['php-env-builder'])) { throw new \InvalidArgumentException( 'The extra.php-env-builder setting must be an array or a configuration object.' ); } if (!isset($extras['php-env-builder']['questions']) || !is_array($extras['php-env-builder']['questions'])) { throw new \InvalidArgumentException( 'The extra.php-env-builder.questions setting must be an array of questions.' ); } }
php
protected function verifyExtras(array $extras) { if (!isset($extras['php-env-builder'])) { throw new \InvalidArgumentException( 'The parameter handler needs to be configured through the ' . 'extra.php-env-builder setting.' ); } if (!is_array($extras['php-env-builder'])) { throw new \InvalidArgumentException( 'The extra.php-env-builder setting must be an array or a configuration object.' ); } if (!isset($extras['php-env-builder']['questions']) || !is_array($extras['php-env-builder']['questions'])) { throw new \InvalidArgumentException( 'The extra.php-env-builder.questions setting must be an array of questions.' ); } }
[ "protected", "function", "verifyExtras", "(", "array", "$", "extras", ")", "{", "if", "(", "!", "isset", "(", "$", "extras", "[", "'php-env-builder'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The parameter handler needs to be configured through the '", ".", "'extra.php-env-builder setting.'", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "extras", "[", "'php-env-builder'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The extra.php-env-builder setting must be an array or a configuration object.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "extras", "[", "'php-env-builder'", "]", "[", "'questions'", "]", ")", "||", "!", "is_array", "(", "$", "extras", "[", "'php-env-builder'", "]", "[", "'questions'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The extra.php-env-builder.questions setting must be an array of questions.'", ")", ";", "}", "}" ]
Verify that the extras a formatted properly and throw an exception if not. @throws \InvalidArgumentException @param array $extras
[ "Verify", "that", "the", "extras", "a", "formatted", "properly", "and", "throw", "an", "exception", "if", "not", "." ]
94b78bcd308d58dc7994164a87e80fe39ed871c7
https://github.com/dbtlr/php-env-builder/blob/94b78bcd308d58dc7994164a87e80fe39ed871c7/src/ComposerScriptRunner.php#L127-L147
241,229
dbtlr/php-env-builder
src/ComposerScriptRunner.php
ComposerScriptRunner.build
public static function build(Event $event, Builder $builder = null) { $runner = new ComposerScriptRunner($event, $builder); $runner->run(); }
php
public static function build(Event $event, Builder $builder = null) { $runner = new ComposerScriptRunner($event, $builder); $runner->run(); }
[ "public", "static", "function", "build", "(", "Event", "$", "event", ",", "Builder", "$", "builder", "=", "null", ")", "{", "$", "runner", "=", "new", "ComposerScriptRunner", "(", "$", "event", ",", "$", "builder", ")", ";", "$", "runner", "->", "run", "(", ")", ";", "}" ]
Build the config based on a composer's package.json file. @throws ConfigurationException @throws AskException @param Event $event @param Builder $builder
[ "Build", "the", "config", "based", "on", "a", "composer", "s", "package", ".", "json", "file", "." ]
94b78bcd308d58dc7994164a87e80fe39ed871c7
https://github.com/dbtlr/php-env-builder/blob/94b78bcd308d58dc7994164a87e80fe39ed871c7/src/ComposerScriptRunner.php#L183-L187
241,230
dbtlr/php-env-builder
src/ComposerScriptRunner.php
ComposerScriptRunner.askQuestions
protected function askQuestions(array $questons) { foreach ($questons as $question) { $this->verifyQuestion($question); $name = $question['name']; $prompt = $question['prompt']; $default = isset($question['default']) ? $question['default'] : ''; $required = isset($question['required']) ? (bool) $question['required'] : false; $this->builder->ask($name, $prompt, $default, $required); } }
php
protected function askQuestions(array $questons) { foreach ($questons as $question) { $this->verifyQuestion($question); $name = $question['name']; $prompt = $question['prompt']; $default = isset($question['default']) ? $question['default'] : ''; $required = isset($question['required']) ? (bool) $question['required'] : false; $this->builder->ask($name, $prompt, $default, $required); } }
[ "protected", "function", "askQuestions", "(", "array", "$", "questons", ")", "{", "foreach", "(", "$", "questons", "as", "$", "question", ")", "{", "$", "this", "->", "verifyQuestion", "(", "$", "question", ")", ";", "$", "name", "=", "$", "question", "[", "'name'", "]", ";", "$", "prompt", "=", "$", "question", "[", "'prompt'", "]", ";", "$", "default", "=", "isset", "(", "$", "question", "[", "'default'", "]", ")", "?", "$", "question", "[", "'default'", "]", ":", "''", ";", "$", "required", "=", "isset", "(", "$", "question", "[", "'required'", "]", ")", "?", "(", "bool", ")", "$", "question", "[", "'required'", "]", ":", "false", ";", "$", "this", "->", "builder", "->", "ask", "(", "$", "name", ",", "$", "prompt", ",", "$", "default", ",", "$", "required", ")", ";", "}", "}" ]
Run through each of the questions and ask each one. @param array $questons
[ "Run", "through", "each", "of", "the", "questions", "and", "ask", "each", "one", "." ]
94b78bcd308d58dc7994164a87e80fe39ed871c7
https://github.com/dbtlr/php-env-builder/blob/94b78bcd308d58dc7994164a87e80fe39ed871c7/src/ComposerScriptRunner.php#L211-L223
241,231
dbtlr/php-env-builder
src/ComposerScriptRunner.php
ComposerScriptRunner.shouldCancelOnClobber
protected function shouldCancelOnClobber() { $fullPath = $this->getEnvFile(); if (!$this->get('clobber') && file_exists($fullPath)) { $this->event->getIO()->write(sprintf('Env file `%s` already exists, skipping...', $fullPath)); return true; } return false; }
php
protected function shouldCancelOnClobber() { $fullPath = $this->getEnvFile(); if (!$this->get('clobber') && file_exists($fullPath)) { $this->event->getIO()->write(sprintf('Env file `%s` already exists, skipping...', $fullPath)); return true; } return false; }
[ "protected", "function", "shouldCancelOnClobber", "(", ")", "{", "$", "fullPath", "=", "$", "this", "->", "getEnvFile", "(", ")", ";", "if", "(", "!", "$", "this", "->", "get", "(", "'clobber'", ")", "&&", "file_exists", "(", "$", "fullPath", ")", ")", "{", "$", "this", "->", "event", "->", "getIO", "(", ")", "->", "write", "(", "sprintf", "(", "'Env file `%s` already exists, skipping...'", ",", "$", "fullPath", ")", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
If we're clobbering and we're not supposed to, should we cancel? @return bool
[ "If", "we", "re", "clobbering", "and", "we", "re", "not", "supposed", "to", "should", "we", "cancel?" ]
94b78bcd308d58dc7994164a87e80fe39ed871c7
https://github.com/dbtlr/php-env-builder/blob/94b78bcd308d58dc7994164a87e80fe39ed871c7/src/ComposerScriptRunner.php#L251-L260
241,232
unrealization/php-tcpconnection
src/TCPConnection.php
TCPConnection.disconnect
public function disconnect(): void { if ($this->connected() === true) { fclose($this->connection); $this->connection = false; } }
php
public function disconnect(): void { if ($this->connected() === true) { fclose($this->connection); $this->connection = false; } }
[ "public", "function", "disconnect", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "connected", "(", ")", "===", "true", ")", "{", "fclose", "(", "$", "this", "->", "connection", ")", ";", "$", "this", "->", "connection", "=", "false", ";", "}", "}" ]
Disconnect from the server. @return void
[ "Disconnect", "from", "the", "server", "." ]
6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283
https://github.com/unrealization/php-tcpconnection/blob/6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283/src/TCPConnection.php#L77-L84
241,233
unrealization/php-tcpconnection
src/TCPConnection.php
TCPConnection.setBlocking
public function setBlocking(int $mode): bool { if ($this->connected() === false) { throw new \Exception('Not connected'); } return stream_set_blocking($this->connection, $mode); }
php
public function setBlocking(int $mode): bool { if ($this->connected() === false) { throw new \Exception('Not connected'); } return stream_set_blocking($this->connection, $mode); }
[ "public", "function", "setBlocking", "(", "int", "$", "mode", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "connected", "(", ")", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Not connected'", ")", ";", "}", "return", "stream_set_blocking", "(", "$", "this", "->", "connection", ",", "$", "mode", ")", ";", "}" ]
Set the mode of stream-blocking. @param int $mode @return bool @throws \Exception
[ "Set", "the", "mode", "of", "stream", "-", "blocking", "." ]
6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283
https://github.com/unrealization/php-tcpconnection/blob/6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283/src/TCPConnection.php#L118-L126
241,234
unrealization/php-tcpconnection
src/TCPConnection.php
TCPConnection.read
public function read(): string { if ($this->connected() === false) { throw new \Exception('Not connected'); } $response = ''; $continue = true; while ($continue == true) { $data = null; try { $data = $this->readLine(); } catch (\Exception $e) { $continue = false; } if (!is_null($data)) { $response .= $data; } } return $response; }
php
public function read(): string { if ($this->connected() === false) { throw new \Exception('Not connected'); } $response = ''; $continue = true; while ($continue == true) { $data = null; try { $data = $this->readLine(); } catch (\Exception $e) { $continue = false; } if (!is_null($data)) { $response .= $data; } } return $response; }
[ "public", "function", "read", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "connected", "(", ")", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Not connected'", ")", ";", "}", "$", "response", "=", "''", ";", "$", "continue", "=", "true", ";", "while", "(", "$", "continue", "==", "true", ")", "{", "$", "data", "=", "null", ";", "try", "{", "$", "data", "=", "$", "this", "->", "readLine", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "continue", "=", "false", ";", "}", "if", "(", "!", "is_null", "(", "$", "data", ")", ")", "{", "$", "response", ".=", "$", "data", ";", "}", "}", "return", "$", "response", ";", "}" ]
Read all data from the stream. @return string @throws \Exception
[ "Read", "all", "data", "from", "the", "stream", "." ]
6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283
https://github.com/unrealization/php-tcpconnection/blob/6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283/src/TCPConnection.php#L133-L163
241,235
unrealization/php-tcpconnection
src/TCPConnection.php
TCPConnection.readLine
public function readLine(): string { if ($this->connected() === false) { throw new \Exception('Not connected'); } $response = fgets($this->connection); if ($response === false) { throw new \Exception('Nothing to read'); } return $response; }
php
public function readLine(): string { if ($this->connected() === false) { throw new \Exception('Not connected'); } $response = fgets($this->connection); if ($response === false) { throw new \Exception('Nothing to read'); } return $response; }
[ "public", "function", "readLine", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "connected", "(", ")", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Not connected'", ")", ";", "}", "$", "response", "=", "fgets", "(", "$", "this", "->", "connection", ")", ";", "if", "(", "$", "response", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Nothing to read'", ")", ";", "}", "return", "$", "response", ";", "}" ]
Read a line of data from the stream. @return string @throws \Exception
[ "Read", "a", "line", "of", "data", "from", "the", "stream", "." ]
6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283
https://github.com/unrealization/php-tcpconnection/blob/6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283/src/TCPConnection.php#L170-L185
241,236
unrealization/php-tcpconnection
src/TCPConnection.php
TCPConnection.readBytes
public function readBytes(int $bytes): string { if ($this->connected() === false) { throw new \Exception('Not connected'); } $response = fread($this->connection, $bytes); if ($response === false) { throw new \Exception('Nothing to read'); } return $response; }
php
public function readBytes(int $bytes): string { if ($this->connected() === false) { throw new \Exception('Not connected'); } $response = fread($this->connection, $bytes); if ($response === false) { throw new \Exception('Nothing to read'); } return $response; }
[ "public", "function", "readBytes", "(", "int", "$", "bytes", ")", ":", "string", "{", "if", "(", "$", "this", "->", "connected", "(", ")", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Not connected'", ")", ";", "}", "$", "response", "=", "fread", "(", "$", "this", "->", "connection", ",", "$", "bytes", ")", ";", "if", "(", "$", "response", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Nothing to read'", ")", ";", "}", "return", "$", "response", ";", "}" ]
Read a number of bytes from the stream. @param int $bytes @return string @throws \Exception
[ "Read", "a", "number", "of", "bytes", "from", "the", "stream", "." ]
6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283
https://github.com/unrealization/php-tcpconnection/blob/6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283/src/TCPConnection.php#L193-L208
241,237
unrealization/php-tcpconnection
src/TCPConnection.php
TCPConnection.writeLine
public function writeLine(string $data): void { try { $this->write($data."\r\n"); } catch (\Exception $e) { throw $e; } }
php
public function writeLine(string $data): void { try { $this->write($data."\r\n"); } catch (\Exception $e) { throw $e; } }
[ "public", "function", "writeLine", "(", "string", "$", "data", ")", ":", "void", "{", "try", "{", "$", "this", "->", "write", "(", "$", "data", ".", "\"\\r\\n\"", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "$", "e", ";", "}", "}" ]
Write a line of data to the stream. @param string $data @return void @throws \Exception
[ "Write", "a", "line", "of", "data", "to", "the", "stream", "." ]
6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283
https://github.com/unrealization/php-tcpconnection/blob/6ebb0cbfdee9b4bc0c3738faed317b35e7fe1283/src/TCPConnection.php#L232-L242
241,238
fabsgc/framework
Core/Http/Request/Auth.php
Auth.role
public function role($src, $value = '') { if (isset($this->_config->config['firewall']['' . $src . ''])) { if ($value == '') { $role = explode('.', $this->_config->config['firewall']['' . $src . '']['roles']['name']); return $this->_getSession($role); } else { $role = explode('.', $this->_config->config['firewall']['' . $src . '']['roles']['name']); $this->_setSession($role, $value); } } else { throw new MissingConfigException('the module ' . $src . ' doesn\'t exist'); } return false; }
php
public function role($src, $value = '') { if (isset($this->_config->config['firewall']['' . $src . ''])) { if ($value == '') { $role = explode('.', $this->_config->config['firewall']['' . $src . '']['roles']['name']); return $this->_getSession($role); } else { $role = explode('.', $this->_config->config['firewall']['' . $src . '']['roles']['name']); $this->_setSession($role, $value); } } else { throw new MissingConfigException('the module ' . $src . ' doesn\'t exist'); } return false; }
[ "public", "function", "role", "(", "$", "src", ",", "$", "value", "=", "''", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_config", "->", "config", "[", "'firewall'", "]", "[", "''", ".", "$", "src", ".", "''", "]", ")", ")", "{", "if", "(", "$", "value", "==", "''", ")", "{", "$", "role", "=", "explode", "(", "'.'", ",", "$", "this", "->", "_config", "->", "config", "[", "'firewall'", "]", "[", "''", ".", "$", "src", ".", "''", "]", "[", "'roles'", "]", "[", "'name'", "]", ")", ";", "return", "$", "this", "->", "_getSession", "(", "$", "role", ")", ";", "}", "else", "{", "$", "role", "=", "explode", "(", "'.'", ",", "$", "this", "->", "_config", "->", "config", "[", "'firewall'", "]", "[", "''", ".", "$", "src", ".", "''", "]", "[", "'roles'", "]", "[", "'name'", "]", ")", ";", "$", "this", "->", "_setSession", "(", "$", "role", ",", "$", "value", ")", ";", "}", "}", "else", "{", "throw", "new", "MissingConfigException", "(", "'the module '", ".", "$", "src", ".", "' doesn\\'t exist'", ")", ";", "}", "return", "false", ";", "}" ]
Get and Set the value of any role attribute @access public @param $src string @param $value string : new value @return mixed @throws \Gcs\Framework\Core\Exception\MissingConfigException @since 3.0 @package Gcs\Framework\Core\Http\Request
[ "Get", "and", "Set", "the", "value", "of", "any", "role", "attribute" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Http/Request/Auth.php#L127-L144
241,239
fabsgc/framework
Core/Http/Request/Auth.php
Auth.logged
public function logged($src, $value = '') { if (isset($this->_config->config['firewall']['' . $src . ''])) { if ($value == '') { $logged = explode('.', $this->_config->config['firewall']['' . $src . '']['logged']['name']); $data = $this->_getSession($logged); if ($data != '') { return $data; } else { return false; } } else { $logged = explode('.', $this->_config->config['firewall']['' . $src . '']['logged']['name']); $this->_setSession($logged, $value); } } else { throw new MissingConfigException('the module ' . $src . ' doesn\'t exist'); } return false; }
php
public function logged($src, $value = '') { if (isset($this->_config->config['firewall']['' . $src . ''])) { if ($value == '') { $logged = explode('.', $this->_config->config['firewall']['' . $src . '']['logged']['name']); $data = $this->_getSession($logged); if ($data != '') { return $data; } else { return false; } } else { $logged = explode('.', $this->_config->config['firewall']['' . $src . '']['logged']['name']); $this->_setSession($logged, $value); } } else { throw new MissingConfigException('the module ' . $src . ' doesn\'t exist'); } return false; }
[ "public", "function", "logged", "(", "$", "src", ",", "$", "value", "=", "''", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_config", "->", "config", "[", "'firewall'", "]", "[", "''", ".", "$", "src", ".", "''", "]", ")", ")", "{", "if", "(", "$", "value", "==", "''", ")", "{", "$", "logged", "=", "explode", "(", "'.'", ",", "$", "this", "->", "_config", "->", "config", "[", "'firewall'", "]", "[", "''", ".", "$", "src", ".", "''", "]", "[", "'logged'", "]", "[", "'name'", "]", ")", ";", "$", "data", "=", "$", "this", "->", "_getSession", "(", "$", "logged", ")", ";", "if", "(", "$", "data", "!=", "''", ")", "{", "return", "$", "data", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "$", "logged", "=", "explode", "(", "'.'", ",", "$", "this", "->", "_config", "->", "config", "[", "'firewall'", "]", "[", "''", ".", "$", "src", ".", "''", "]", "[", "'logged'", "]", "[", "'name'", "]", ")", ";", "$", "this", "->", "_setSession", "(", "$", "logged", ",", "$", "value", ")", ";", "}", "}", "else", "{", "throw", "new", "MissingConfigException", "(", "'the module '", ".", "$", "src", ".", "' doesn\\'t exist'", ")", ";", "}", "return", "false", ";", "}" ]
Get and Set the value of any logged attribute @access public @param $src string @param $value string : new value @throws \Gcs\Framework\Core\Exception\MissingConfigException @return mixed @since 3.0 @package Gcs\Framework\Core\Http\Request
[ "Get", "and", "Set", "the", "value", "of", "any", "logged", "attribute" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Http/Request/Auth.php#L157-L181
241,240
ARCANESOFT/Tracker
src/ViewComposers/Dashboard/DevicesRatioComposer.php
DevicesRatioComposer.getDevicesFromSessions
protected function getDevicesFromSessions(Carbon $start, Carbon $end) { return $this->getVisitorsFilteredByDateRange($start, $end) ->filter(function (Visitor $session) { return $session->hasDevice(); }) ->transform(function (Visitor $session) { return $session->device; }) ->groupBy('kind') ->transform(function (Collection $items, $key) { return [ 'kind' => trans("tracker::devices.kinds.$key"), 'count' => $items->count(), ]; }); }
php
protected function getDevicesFromSessions(Carbon $start, Carbon $end) { return $this->getVisitorsFilteredByDateRange($start, $end) ->filter(function (Visitor $session) { return $session->hasDevice(); }) ->transform(function (Visitor $session) { return $session->device; }) ->groupBy('kind') ->transform(function (Collection $items, $key) { return [ 'kind' => trans("tracker::devices.kinds.$key"), 'count' => $items->count(), ]; }); }
[ "protected", "function", "getDevicesFromSessions", "(", "Carbon", "$", "start", ",", "Carbon", "$", "end", ")", "{", "return", "$", "this", "->", "getVisitorsFilteredByDateRange", "(", "$", "start", ",", "$", "end", ")", "->", "filter", "(", "function", "(", "Visitor", "$", "session", ")", "{", "return", "$", "session", "->", "hasDevice", "(", ")", ";", "}", ")", "->", "transform", "(", "function", "(", "Visitor", "$", "session", ")", "{", "return", "$", "session", "->", "device", ";", "}", ")", "->", "groupBy", "(", "'kind'", ")", "->", "transform", "(", "function", "(", "Collection", "$", "items", ",", "$", "key", ")", "{", "return", "[", "'kind'", "=>", "trans", "(", "\"tracker::devices.kinds.$key\"", ")", ",", "'count'", "=>", "$", "items", "->", "count", "(", ")", ",", "]", ";", "}", ")", ";", "}" ]
Get the devices from sessions. @param \Carbon\Carbon $start @param \Carbon\Carbon $end @return \Illuminate\Support\Collection
[ "Get", "the", "devices", "from", "sessions", "." ]
d106209b32ddbb192066715f0ef99afccfc22dcb
https://github.com/ARCANESOFT/Tracker/blob/d106209b32ddbb192066715f0ef99afccfc22dcb/src/ViewComposers/Dashboard/DevicesRatioComposer.php#L60-L76