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
kreta/SimpleApiDocBundle
src/Kreta/SimpleApiDocBundle/Annotation/ApiDoc.php
ApiDoc.buildStatusCodes
protected function buildStatusCodes(array $data) { if (isset($data['statusCodes'])) { $this->initializeStatusCodes(); foreach ($data['statusCodes'] as $key => $element) { if ((int) $key < 200) { $this->statusCodes($element); } else { $this->statusCodes($key, $element); } } } return $this; }
php
protected function buildStatusCodes(array $data) { if (isset($data['statusCodes'])) { $this->initializeStatusCodes(); foreach ($data['statusCodes'] as $key => $element) { if ((int) $key < 200) { $this->statusCodes($element); } else { $this->statusCodes($key, $element); } } } return $this; }
[ "protected", "function", "buildStatusCodes", "(", "array", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'statusCodes'", "]", ")", ")", "{", "$", "this", "->", "initializeStatusCodes", "(", ")", ";", "foreach", "(", "$", "data", "[", "'statusCodes'", "]", "as", "$", "key", "=>", "$", "element", ")", "{", "if", "(", "(", "int", ")", "$", "key", "<", "200", ")", "{", "$", "this", "->", "statusCodes", "(", "$", "element", ")", ";", "}", "else", "{", "$", "this", "->", "statusCodes", "(", "$", "key", ",", "$", "element", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Loads data given status codes. @param array $data Array that contains all the data @return self
[ "Loads", "data", "given", "status", "codes", "." ]
786aa9310cdf087253f65f68165a0a0c8ad5c816
https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Annotation/ApiDoc.php#L69-L83
train
kreta/SimpleApiDocBundle
src/Kreta/SimpleApiDocBundle/Annotation/ApiDoc.php
ApiDoc.statusCodes
protected function statusCodes($statusCode, $customDescription = null) { if ($customDescription) { $description = $customDescription; } if ($customDescription !== null || array_key_exists($statusCode, $this->defaultStatusCodes)) { if (!isset($description)) { $description = $this->defaultStatusCodes[$statusCode]; } $description = !is_array($description) ? [$description] : $description; $this->addStatusCode($statusCode, $description); } return $this; }
php
protected function statusCodes($statusCode, $customDescription = null) { if ($customDescription) { $description = $customDescription; } if ($customDescription !== null || array_key_exists($statusCode, $this->defaultStatusCodes)) { if (!isset($description)) { $description = $this->defaultStatusCodes[$statusCode]; } $description = !is_array($description) ? [$description] : $description; $this->addStatusCode($statusCode, $description); } return $this; }
[ "protected", "function", "statusCodes", "(", "$", "statusCode", ",", "$", "customDescription", "=", "null", ")", "{", "if", "(", "$", "customDescription", ")", "{", "$", "description", "=", "$", "customDescription", ";", "}", "if", "(", "$", "customDescription", "!==", "null", "||", "array_key_exists", "(", "$", "statusCode", ",", "$", "this", "->", "defaultStatusCodes", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "description", ")", ")", "{", "$", "description", "=", "$", "this", "->", "defaultStatusCodes", "[", "$", "statusCode", "]", ";", "}", "$", "description", "=", "!", "is_array", "(", "$", "description", ")", "?", "[", "$", "description", "]", ":", "$", "description", ";", "$", "this", "->", "addStatusCode", "(", "$", "statusCode", ",", "$", "description", ")", ";", "}", "return", "$", "this", ";", "}" ]
Method that allows to choose between status code passing the code and optional description. @param int $statusCode The status code @param string|null $customDescription The description @return self
[ "Method", "that", "allows", "to", "choose", "between", "status", "code", "passing", "the", "code", "and", "optional", "description", "." ]
786aa9310cdf087253f65f68165a0a0c8ad5c816
https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Annotation/ApiDoc.php#L94-L108
train
kreta/SimpleApiDocBundle
src/Kreta/SimpleApiDocBundle/Annotation/ApiDoc.php
ApiDoc.initializeStatusCodes
protected function initializeStatusCodes() { $annotationReflection = new \ReflectionClass('Nelmio\ApiDocBundle\Annotation\ApiDoc'); $statusCodesReflection = $annotationReflection->getProperty('statusCodes'); $statusCodesReflection->setAccessible(true); $statusCodesReflection->setValue($this, []); return $this; }
php
protected function initializeStatusCodes() { $annotationReflection = new \ReflectionClass('Nelmio\ApiDocBundle\Annotation\ApiDoc'); $statusCodesReflection = $annotationReflection->getProperty('statusCodes'); $statusCodesReflection->setAccessible(true); $statusCodesReflection->setValue($this, []); return $this; }
[ "protected", "function", "initializeStatusCodes", "(", ")", "{", "$", "annotationReflection", "=", "new", "\\", "ReflectionClass", "(", "'Nelmio\\ApiDocBundle\\Annotation\\ApiDoc'", ")", ";", "$", "statusCodesReflection", "=", "$", "annotationReflection", "->", "getProperty", "(", "'statusCodes'", ")", ";", "$", "statusCodesReflection", "->", "setAccessible", "(", "true", ")", ";", "$", "statusCodesReflection", "->", "setValue", "(", "$", "this", ",", "[", "]", ")", ";", "return", "$", "this", ";", "}" ]
Purges the statusCodes array to populate with the new way. This method is required because the $statusCodes is a private field, and the reflection is necessary. @return self
[ "Purges", "the", "statusCodes", "array", "to", "populate", "with", "the", "new", "way", "." ]
786aa9310cdf087253f65f68165a0a0c8ad5c816
https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Annotation/ApiDoc.php#L118-L126
train
ZendExperts/phpids
lib/IDS/Report.php
IDS_Report.setCentrifuge
public function setCentrifuge($centrifuge = array()) { if (is_array($centrifuge) && $centrifuge) { $this->centrifuge = $centrifuge; return true; } throw new InvalidArgumentException('Invalid argument given'); }
php
public function setCentrifuge($centrifuge = array()) { if (is_array($centrifuge) && $centrifuge) { $this->centrifuge = $centrifuge; return true; } throw new InvalidArgumentException('Invalid argument given'); }
[ "public", "function", "setCentrifuge", "(", "$", "centrifuge", "=", "array", "(", ")", ")", "{", "if", "(", "is_array", "(", "$", "centrifuge", ")", "&&", "$", "centrifuge", ")", "{", "$", "this", "->", "centrifuge", "=", "$", "centrifuge", ";", "return", "true", ";", "}", "throw", "new", "InvalidArgumentException", "(", "'Invalid argument given'", ")", ";", "}" ]
This method sets the centrifuge property @param array $centrifuge the centrifuge data @throws InvalidArgumentException if argument is illegal @return boolean true is arguments were valid
[ "This", "method", "sets", "the", "centrifuge", "property" ]
f30df04eea47b94d056e2ae9ec8fea1c626f1c03
https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Report.php#L275-L282
train
congraphcms/core
Repositories/TrunkCache.php
TrunkCache.put
public function put($data) { if( ! $data instanceof DataTransferObject) { throw new Exception('You are trying to put invalid object to trunk.'); } if( ! array_key_exists($data->getType(), $this->storage) ) { $this->storage[$data->getType()] = []; } $storageKey = $this->storageKey($data->getParams()); $this->storage[$data->getType()][$storageKey] = $data; }
php
public function put($data) { if( ! $data instanceof DataTransferObject) { throw new Exception('You are trying to put invalid object to trunk.'); } if( ! array_key_exists($data->getType(), $this->storage) ) { $this->storage[$data->getType()] = []; } $storageKey = $this->storageKey($data->getParams()); $this->storage[$data->getType()][$storageKey] = $data; }
[ "public", "function", "put", "(", "$", "data", ")", "{", "if", "(", "!", "$", "data", "instanceof", "DataTransferObject", ")", "{", "throw", "new", "Exception", "(", "'You are trying to put invalid object to trunk.'", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "data", "->", "getType", "(", ")", ",", "$", "this", "->", "storage", ")", ")", "{", "$", "this", "->", "storage", "[", "$", "data", "->", "getType", "(", ")", "]", "=", "[", "]", ";", "}", "$", "storageKey", "=", "$", "this", "->", "storageKey", "(", "$", "data", "->", "getParams", "(", ")", ")", ";", "$", "this", "->", "storage", "[", "$", "data", "->", "getType", "(", ")", "]", "[", "$", "storageKey", "]", "=", "$", "data", ";", "}" ]
Add item or collection to trunk @param mixed $data @return void
[ "Add", "item", "or", "collection", "to", "trunk" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/TrunkCache.php#L50-L64
train
congraphcms/core
Repositories/TrunkCache.php
TrunkCache.has
public function has($key, $type) { if(is_array($key)) { return $this->hasItem($this->storageKey($key), $type); } if(is_string($key)) { return $this->hasItem($key, $type); } if(is_int($key)) { return $this->hasItem($this->storageKey([$key]), $type); } return false; }
php
public function has($key, $type) { if(is_array($key)) { return $this->hasItem($this->storageKey($key), $type); } if(is_string($key)) { return $this->hasItem($key, $type); } if(is_int($key)) { return $this->hasItem($this->storageKey([$key]), $type); } return false; }
[ "public", "function", "has", "(", "$", "key", ",", "$", "type", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "hasItem", "(", "$", "this", "->", "storageKey", "(", "$", "key", ")", ",", "$", "type", ")", ";", "}", "if", "(", "is_string", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "hasItem", "(", "$", "key", ",", "$", "type", ")", ";", "}", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "hasItem", "(", "$", "this", "->", "storageKey", "(", "[", "$", "key", "]", ")", ",", "$", "type", ")", ";", "}", "return", "false", ";", "}" ]
Check cache for item or collection @param mixed $key @param string $type @return boolean
[ "Check", "cache", "for", "item", "or", "collection" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/TrunkCache.php#L74-L92
train
congraphcms/core
Repositories/TrunkCache.php
TrunkCache.hasItem
protected function hasItem($key, $type) { if(array_key_exists($type, $this->storage) && array_key_exists($key, $this->storage[$type])) { return true; } return false; }
php
protected function hasItem($key, $type) { if(array_key_exists($type, $this->storage) && array_key_exists($key, $this->storage[$type])) { return true; } return false; }
[ "protected", "function", "hasItem", "(", "$", "key", ",", "$", "type", ")", "{", "if", "(", "array_key_exists", "(", "$", "type", ",", "$", "this", "->", "storage", ")", "&&", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "storage", "[", "$", "type", "]", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if item exists in cache @param string $key @param string $type @return boolean
[ "Check", "if", "item", "exists", "in", "cache" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/TrunkCache.php#L102-L110
train
congraphcms/core
Repositories/TrunkCache.php
TrunkCache.get
public function get($key, $type) { if(is_array($key)) { return $this->getItem($this->storageKey($key), $type); } if(is_string($key)) { return $this->getItem($key, $type); } if(is_int($key)) { return $this->getItem($this->storageKey([$key]), $type); } return null; }
php
public function get($key, $type) { if(is_array($key)) { return $this->getItem($this->storageKey($key), $type); } if(is_string($key)) { return $this->getItem($key, $type); } if(is_int($key)) { return $this->getItem($this->storageKey([$key]), $type); } return null; }
[ "public", "function", "get", "(", "$", "key", ",", "$", "type", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "getItem", "(", "$", "this", "->", "storageKey", "(", "$", "key", ")", ",", "$", "type", ")", ";", "}", "if", "(", "is_string", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "getItem", "(", "$", "key", ",", "$", "type", ")", ";", "}", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "getItem", "(", "$", "this", "->", "storageKey", "(", "[", "$", "key", "]", ")", ",", "$", "type", ")", ";", "}", "return", "null", ";", "}" ]
Get item or collection from cache @param mixed $key @param string $type @return DataTransferObject | null
[ "Get", "item", "or", "collection", "from", "cache" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/TrunkCache.php#L120-L138
train
congraphcms/core
Repositories/TrunkCache.php
TrunkCache.getItem
protected function getItem($key, $type) { if(array_key_exists($type, $this->storage) && array_key_exists($key, $this->storage[$type])) { return $this->storage[$type][$key]; } return null; }
php
protected function getItem($key, $type) { if(array_key_exists($type, $this->storage) && array_key_exists($key, $this->storage[$type])) { return $this->storage[$type][$key]; } return null; }
[ "protected", "function", "getItem", "(", "$", "key", ",", "$", "type", ")", "{", "if", "(", "array_key_exists", "(", "$", "type", ",", "$", "this", "->", "storage", ")", "&&", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "storage", "[", "$", "type", "]", ")", ")", "{", "return", "$", "this", "->", "storage", "[", "$", "type", "]", "[", "$", "key", "]", ";", "}", "return", "null", ";", "}" ]
Get item by id and type @param string $key @param string $type @return DataTransferObject | null
[ "Get", "item", "by", "id", "and", "type" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/TrunkCache.php#L148-L156
train
SlabPHP/controllers
src/Traits/RouteReference.php
RouteReference.getRoutedParameter
protected function getRoutedParameter($parameter, $default = null) { $output = $default; $parameters = $this->route->getParameters(); if (!empty($parameters->$parameter)) { $output = $parameters->$parameter; } $validatedData = $this->route->getValidatedData(); if (!empty($validatedData->$parameter)) { $output = $validatedData->$parameter; } return $output; }
php
protected function getRoutedParameter($parameter, $default = null) { $output = $default; $parameters = $this->route->getParameters(); if (!empty($parameters->$parameter)) { $output = $parameters->$parameter; } $validatedData = $this->route->getValidatedData(); if (!empty($validatedData->$parameter)) { $output = $validatedData->$parameter; } return $output; }
[ "protected", "function", "getRoutedParameter", "(", "$", "parameter", ",", "$", "default", "=", "null", ")", "{", "$", "output", "=", "$", "default", ";", "$", "parameters", "=", "$", "this", "->", "route", "->", "getParameters", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "parameters", "->", "$", "parameter", ")", ")", "{", "$", "output", "=", "$", "parameters", "->", "$", "parameter", ";", "}", "$", "validatedData", "=", "$", "this", "->", "route", "->", "getValidatedData", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "validatedData", "->", "$", "parameter", ")", ")", "{", "$", "output", "=", "$", "validatedData", "->", "$", "parameter", ";", "}", "return", "$", "output", ";", "}" ]
Function for retrieving routed parameter data from the stored Route reference @param $parameter @param null $default @return null
[ "Function", "for", "retrieving", "routed", "parameter", "data", "from", "the", "stored", "Route", "reference" ]
a1c4fded0265100a85904dd664b972a7f8687652
https://github.com/SlabPHP/controllers/blob/a1c4fded0265100a85904dd664b972a7f8687652/src/Traits/RouteReference.php#L36-L55
train
jabernardo/lollipop-php
Library/Session/Session.php
Session.exists
public function exists($key) { $key = $this->secureKey($key); if (isset($_SESSION[$key])) return true; return false; }
php
public function exists($key) { $key = $this->secureKey($key); if (isset($_SESSION[$key])) return true; return false; }
[ "public", "function", "exists", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "secureKey", "(", "$", "key", ")", ";", "if", "(", "isset", "(", "$", "_SESSION", "[", "$", "key", "]", ")", ")", "return", "true", ";", "return", "false", ";", "}" ]
Checks if a session variable exists @access public @param string $key Session variable name @return bool
[ "Checks", "if", "a", "session", "variable", "exists" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Session/Session.php#L73-L79
train
jabernardo/lollipop-php
Library/Session/Session.php
Session.set
public function set($key, $value) { $key = $this->secureKey($key); $_SESSION[$key] = $this->secureValue($value); return $key; }
php
public function set($key, $value) { $key = $this->secureKey($key); $_SESSION[$key] = $this->secureValue($value); return $key; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "$", "key", "=", "$", "this", "->", "secureKey", "(", "$", "key", ")", ";", "$", "_SESSION", "[", "$", "key", "]", "=", "$", "this", "->", "secureValue", "(", "$", "value", ")", ";", "return", "$", "key", ";", "}" ]
Creates a new session or sets an existing sesssion @access public @param string $key Session variable name @param string $value Session variable value @return string Session encrypted key
[ "Creates", "a", "new", "session", "or", "sets", "an", "existing", "sesssion" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Session/Session.php#L90-L95
train
jabernardo/lollipop-php
Library/Session/Session.php
Session.get
public function get($key) { $key = $this->secureKey($key); if (isset($_SESSION[$key])) { return trim(Text::unlock($_SESSION[$key], $this->sugar())); } else { return ''; } }
php
public function get($key) { $key = $this->secureKey($key); if (isset($_SESSION[$key])) { return trim(Text::unlock($_SESSION[$key], $this->sugar())); } else { return ''; } }
[ "public", "function", "get", "(", "$", "key", ")", "{", "$", "key", "=", "$", "this", "->", "secureKey", "(", "$", "key", ")", ";", "if", "(", "isset", "(", "$", "_SESSION", "[", "$", "key", "]", ")", ")", "{", "return", "trim", "(", "Text", "::", "unlock", "(", "$", "_SESSION", "[", "$", "key", "]", ",", "$", "this", "->", "sugar", "(", ")", ")", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Gets session variable's value @access public @param string $key Session variable name @return string
[ "Gets", "session", "variable", "s", "value" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Session/Session.php#L105-L113
train
dmitrya2e/filtration-bundle
Filter/Filter/AbstractNumberFilter.php
AbstractNumberFilter.appendSingleFormFields
protected function appendSingleFormFields(FormBuilderInterface $formBuilder) { $defaultOptions = [ 'label' => $this->getTitle(), 'required' => false, ]; $userOptions = array_key_exists('single', $this->getFormOptions()) ? $this->getFormOptions()['single'] : []; if (count($userOptions) > 0) { $defaultOptions = array_merge($defaultOptions, $userOptions); } $defaultOptions['property_path'] = 'value'; $formBuilder->add($this->getValuePropertyName(), $this->getFormFieldType(), $defaultOptions); return $this; }
php
protected function appendSingleFormFields(FormBuilderInterface $formBuilder) { $defaultOptions = [ 'label' => $this->getTitle(), 'required' => false, ]; $userOptions = array_key_exists('single', $this->getFormOptions()) ? $this->getFormOptions()['single'] : []; if (count($userOptions) > 0) { $defaultOptions = array_merge($defaultOptions, $userOptions); } $defaultOptions['property_path'] = 'value'; $formBuilder->add($this->getValuePropertyName(), $this->getFormFieldType(), $defaultOptions); return $this; }
[ "protected", "function", "appendSingleFormFields", "(", "FormBuilderInterface", "$", "formBuilder", ")", "{", "$", "defaultOptions", "=", "[", "'label'", "=>", "$", "this", "->", "getTitle", "(", ")", ",", "'required'", "=>", "false", ",", "]", ";", "$", "userOptions", "=", "array_key_exists", "(", "'single'", ",", "$", "this", "->", "getFormOptions", "(", ")", ")", "?", "$", "this", "->", "getFormOptions", "(", ")", "[", "'single'", "]", ":", "[", "]", ";", "if", "(", "count", "(", "$", "userOptions", ")", ">", "0", ")", "{", "$", "defaultOptions", "=", "array_merge", "(", "$", "defaultOptions", ",", "$", "userOptions", ")", ";", "}", "$", "defaultOptions", "[", "'property_path'", "]", "=", "'value'", ";", "$", "formBuilder", "->", "add", "(", "$", "this", "->", "getValuePropertyName", "(", ")", ",", "$", "this", "->", "getFormFieldType", "(", ")", ",", "$", "defaultOptions", ")", ";", "return", "$", "this", ";", "}" ]
Appends form fields for "single" mode. @param FormBuilderInterface $formBuilder @return static
[ "Appends", "form", "fields", "for", "single", "mode", "." ]
fed5764af4e43871835744fb84957b2a76e9a215
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractNumberFilter.php#L136-L156
train
dmitrya2e/filtration-bundle
Filter/Filter/AbstractNumberFilter.php
AbstractNumberFilter.appendRangedFormFields
protected function appendRangedFormFields(FormBuilderInterface $formBuilder) { // "From" options $fromDefaultOptions = [ 'label' => 'da2e.filtration.number_filter.ranged.from.label', 'required' => false, ]; $fromUserOptions = array_key_exists('ranged_from', $this->getFormOptions()) ? $this->getFormOptions()['ranged_from'] : []; if (count($fromUserOptions) > 0) { $fromDefaultOptions = array_merge($fromDefaultOptions, $fromUserOptions); } $fromDefaultOptions['property_path'] = 'fromValue'; // "To" options $toDefaultOptions = [ 'label' => 'da2e.filtration.number_filter.ranged.to.label', 'required' => false, ]; $toUserOptions = array_key_exists('ranged_to', $this->getFormOptions()) ? $this->getFormOptions()['ranged_to'] : []; if (count($toUserOptions) > 0) { $toDefaultOptions = array_merge($toDefaultOptions, $toUserOptions); } $toDefaultOptions['property_path'] = 'toValue'; $formBuilder->add($this->getFromValuePropertyName(), $this->getFormFieldTypeRangedFrom(), $fromDefaultOptions); $formBuilder->add($this->getToValuePropertyName(), $this->getFormFieldTypeRangedTo(), $toDefaultOptions); return $this; }
php
protected function appendRangedFormFields(FormBuilderInterface $formBuilder) { // "From" options $fromDefaultOptions = [ 'label' => 'da2e.filtration.number_filter.ranged.from.label', 'required' => false, ]; $fromUserOptions = array_key_exists('ranged_from', $this->getFormOptions()) ? $this->getFormOptions()['ranged_from'] : []; if (count($fromUserOptions) > 0) { $fromDefaultOptions = array_merge($fromDefaultOptions, $fromUserOptions); } $fromDefaultOptions['property_path'] = 'fromValue'; // "To" options $toDefaultOptions = [ 'label' => 'da2e.filtration.number_filter.ranged.to.label', 'required' => false, ]; $toUserOptions = array_key_exists('ranged_to', $this->getFormOptions()) ? $this->getFormOptions()['ranged_to'] : []; if (count($toUserOptions) > 0) { $toDefaultOptions = array_merge($toDefaultOptions, $toUserOptions); } $toDefaultOptions['property_path'] = 'toValue'; $formBuilder->add($this->getFromValuePropertyName(), $this->getFormFieldTypeRangedFrom(), $fromDefaultOptions); $formBuilder->add($this->getToValuePropertyName(), $this->getFormFieldTypeRangedTo(), $toDefaultOptions); return $this; }
[ "protected", "function", "appendRangedFormFields", "(", "FormBuilderInterface", "$", "formBuilder", ")", "{", "// \"From\" options\r", "$", "fromDefaultOptions", "=", "[", "'label'", "=>", "'da2e.filtration.number_filter.ranged.from.label'", ",", "'required'", "=>", "false", ",", "]", ";", "$", "fromUserOptions", "=", "array_key_exists", "(", "'ranged_from'", ",", "$", "this", "->", "getFormOptions", "(", ")", ")", "?", "$", "this", "->", "getFormOptions", "(", ")", "[", "'ranged_from'", "]", ":", "[", "]", ";", "if", "(", "count", "(", "$", "fromUserOptions", ")", ">", "0", ")", "{", "$", "fromDefaultOptions", "=", "array_merge", "(", "$", "fromDefaultOptions", ",", "$", "fromUserOptions", ")", ";", "}", "$", "fromDefaultOptions", "[", "'property_path'", "]", "=", "'fromValue'", ";", "// \"To\" options\r", "$", "toDefaultOptions", "=", "[", "'label'", "=>", "'da2e.filtration.number_filter.ranged.to.label'", ",", "'required'", "=>", "false", ",", "]", ";", "$", "toUserOptions", "=", "array_key_exists", "(", "'ranged_to'", ",", "$", "this", "->", "getFormOptions", "(", ")", ")", "?", "$", "this", "->", "getFormOptions", "(", ")", "[", "'ranged_to'", "]", ":", "[", "]", ";", "if", "(", "count", "(", "$", "toUserOptions", ")", ">", "0", ")", "{", "$", "toDefaultOptions", "=", "array_merge", "(", "$", "toDefaultOptions", ",", "$", "toUserOptions", ")", ";", "}", "$", "toDefaultOptions", "[", "'property_path'", "]", "=", "'toValue'", ";", "$", "formBuilder", "->", "add", "(", "$", "this", "->", "getFromValuePropertyName", "(", ")", ",", "$", "this", "->", "getFormFieldTypeRangedFrom", "(", ")", ",", "$", "fromDefaultOptions", ")", ";", "$", "formBuilder", "->", "add", "(", "$", "this", "->", "getToValuePropertyName", "(", ")", ",", "$", "this", "->", "getFormFieldTypeRangedTo", "(", ")", ",", "$", "toDefaultOptions", ")", ";", "return", "$", "this", ";", "}" ]
Appends form fields for "range" mode. @param FormBuilderInterface $formBuilder @return static
[ "Appends", "form", "fields", "for", "range", "mode", "." ]
fed5764af4e43871835744fb84957b2a76e9a215
https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Filter/AbstractNumberFilter.php#L165-L203
train
jenskooij/cloudcontrol
src/storage/storage/SitemapStorage.php
SitemapStorage.addSitemapItem
public function addSitemapItem($postValues) { $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues); $sitemap = $this->repository->sitemap; $sitemap[] = $sitemapObject; $this->repository->sitemap = $sitemap; $this->save(); }
php
public function addSitemapItem($postValues) { $sitemapObject = SitemapItemFactory::createSitemapItemFromPostValues($postValues); $sitemap = $this->repository->sitemap; $sitemap[] = $sitemapObject; $this->repository->sitemap = $sitemap; $this->save(); }
[ "public", "function", "addSitemapItem", "(", "$", "postValues", ")", "{", "$", "sitemapObject", "=", "SitemapItemFactory", "::", "createSitemapItemFromPostValues", "(", "$", "postValues", ")", ";", "$", "sitemap", "=", "$", "this", "->", "repository", "->", "sitemap", ";", "$", "sitemap", "[", "]", "=", "$", "sitemapObject", ";", "$", "this", "->", "repository", "->", "sitemap", "=", "$", "sitemap", ";", "$", "this", "->", "save", "(", ")", ";", "}" ]
Add a sitemap item @param $postValues @throws \Exception
[ "Add", "a", "sitemap", "item" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/SitemapStorage.php#L30-L37
train
jenskooij/cloudcontrol
src/storage/storage/SitemapStorage.php
SitemapStorage.getSitemapItemBySlug
public function getSitemapItemBySlug($slug) { $sitemap = $this->repository->sitemap; foreach ($sitemap as $sitemapItem) { if ($sitemapItem->slug == $slug) { return $sitemapItem; } } return null; }
php
public function getSitemapItemBySlug($slug) { $sitemap = $this->repository->sitemap; foreach ($sitemap as $sitemapItem) { if ($sitemapItem->slug == $slug) { return $sitemapItem; } } return null; }
[ "public", "function", "getSitemapItemBySlug", "(", "$", "slug", ")", "{", "$", "sitemap", "=", "$", "this", "->", "repository", "->", "sitemap", ";", "foreach", "(", "$", "sitemap", "as", "$", "sitemapItem", ")", "{", "if", "(", "$", "sitemapItem", "->", "slug", "==", "$", "slug", ")", "{", "return", "$", "sitemapItem", ";", "}", "}", "return", "null", ";", "}" ]
Get a sitemap item by its slug @param $slug @return mixed
[ "Get", "a", "sitemap", "item", "by", "its", "slug" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/SitemapStorage.php#L111-L121
train
AnonymPHP/Anonym-Route
RouteCollector.php
RouteCollector.addRoute
private function addRoute($types = '', $uri, $action = []) { if (is_string($action)) { $action = ['_controller' => $action]; } if (is_array($action)) { if (isset($action['as'])) { AsCollector::addAs($action['as'], $uri); } } $types = (array)$types; foreach ($types as $type) { $type = mb_convert_case($type, MB_CASE_UPPER); $add = [ 'uri' => isset(static::$firing['when']) ? $this->createWhenUri($uri) : $uri, 'action' => $action ];; // add group parameter to action variable if (isset(static::$firing['group'])) { $add['group'] = static::$firing['group']; } // add to collection static::$routes[$type][] = $add; } return $this; }
php
private function addRoute($types = '', $uri, $action = []) { if (is_string($action)) { $action = ['_controller' => $action]; } if (is_array($action)) { if (isset($action['as'])) { AsCollector::addAs($action['as'], $uri); } } $types = (array)$types; foreach ($types as $type) { $type = mb_convert_case($type, MB_CASE_UPPER); $add = [ 'uri' => isset(static::$firing['when']) ? $this->createWhenUri($uri) : $uri, 'action' => $action ];; // add group parameter to action variable if (isset(static::$firing['group'])) { $add['group'] = static::$firing['group']; } // add to collection static::$routes[$type][] = $add; } return $this; }
[ "private", "function", "addRoute", "(", "$", "types", "=", "''", ",", "$", "uri", ",", "$", "action", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "action", ")", ")", "{", "$", "action", "=", "[", "'_controller'", "=>", "$", "action", "]", ";", "}", "if", "(", "is_array", "(", "$", "action", ")", ")", "{", "if", "(", "isset", "(", "$", "action", "[", "'as'", "]", ")", ")", "{", "AsCollector", "::", "addAs", "(", "$", "action", "[", "'as'", "]", ",", "$", "uri", ")", ";", "}", "}", "$", "types", "=", "(", "array", ")", "$", "types", ";", "foreach", "(", "$", "types", "as", "$", "type", ")", "{", "$", "type", "=", "mb_convert_case", "(", "$", "type", ",", "MB_CASE_UPPER", ")", ";", "$", "add", "=", "[", "'uri'", "=>", "isset", "(", "static", "::", "$", "firing", "[", "'when'", "]", ")", "?", "$", "this", "->", "createWhenUri", "(", "$", "uri", ")", ":", "$", "uri", ",", "'action'", "=>", "$", "action", "]", ";", ";", "// add group parameter to action variable", "if", "(", "isset", "(", "static", "::", "$", "firing", "[", "'group'", "]", ")", ")", "{", "$", "add", "[", "'group'", "]", "=", "static", "::", "$", "firing", "[", "'group'", "]", ";", "}", "// add to collection", "static", "::", "$", "routes", "[", "$", "type", "]", "[", "]", "=", "$", "add", ";", "}", "return", "$", "this", ";", "}" ]
Add a route with type, uri and action parameters @param string|array $types @param array $uri @param array $action @return $this
[ "Add", "a", "route", "with", "type", "uri", "and", "action", "parameters" ]
bb7f8004fbbd2998af8b0061f404f026f11466ab
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/RouteCollector.php#L58-L90
train
AnonymPHP/Anonym-Route
RouteCollector.php
RouteCollector.createWhenUri
protected function createWhenUri($uri) { $when = static::$firing['when']; if (substr($when, -1) !== '/') { $when .= '/'; } if(substr($uri, 0,1) === '/'){ $uri = substr($uri, 1, strlen($uri)); } return $when.$uri; }
php
protected function createWhenUri($uri) { $when = static::$firing['when']; if (substr($when, -1) !== '/') { $when .= '/'; } if(substr($uri, 0,1) === '/'){ $uri = substr($uri, 1, strlen($uri)); } return $when.$uri; }
[ "protected", "function", "createWhenUri", "(", "$", "uri", ")", "{", "$", "when", "=", "static", "::", "$", "firing", "[", "'when'", "]", ";", "if", "(", "substr", "(", "$", "when", ",", "-", "1", ")", "!==", "'/'", ")", "{", "$", "when", ".=", "'/'", ";", "}", "if", "(", "substr", "(", "$", "uri", ",", "0", ",", "1", ")", "===", "'/'", ")", "{", "$", "uri", "=", "substr", "(", "$", "uri", ",", "1", ",", "strlen", "(", "$", "uri", ")", ")", ";", "}", "return", "$", "when", ".", "$", "uri", ";", "}" ]
prapare uri to merge with when url, and return it. @param string $uri @return string
[ "prapare", "uri", "to", "merge", "with", "when", "url", "and", "return", "it", "." ]
bb7f8004fbbd2998af8b0061f404f026f11466ab
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/RouteCollector.php#L98-L111
train
AnonymPHP/Anonym-Route
RouteCollector.php
RouteCollector.group
public function group($name, $action, Closure $callback) { static::$groups[$name] = [ 'action' => $action, 'callback' => $callback ]; return $this; }
php
public function group($name, $action, Closure $callback) { static::$groups[$name] = [ 'action' => $action, 'callback' => $callback ]; return $this; }
[ "public", "function", "group", "(", "$", "name", ",", "$", "action", ",", "Closure", "$", "callback", ")", "{", "static", "::", "$", "groups", "[", "$", "name", "]", "=", "[", "'action'", "=>", "$", "action", ",", "'callback'", "=>", "$", "callback", "]", ";", "return", "$", "this", ";", "}" ]
register a new group collection @param string $name @param array $action @param Closure $callback @return $this
[ "register", "a", "new", "group", "collection" ]
bb7f8004fbbd2998af8b0061f404f026f11466ab
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/RouteCollector.php#L234-L242
train
t-kanstantsin/fileupload
src/formatter/File.php
File.triggerEvent
public function triggerEvent(string $event): void { // TODO: use event library and allow attach events to IFile and ICacheStateful. // cache triggers if ($this->file instanceof ICacheStateful) { switch ($event) { case self::EVENT_CACHED: $this->file->setCachedAt($this->name, time()); break; case self::EVENT_EMPTY: case self::EVENT_ERROR: case self::EVENT_NOT_FOUND: // TODO: split those and save different cases of cache state. $this->file->setCachedAt($this->name, null); break; } $this->file->saveState(); } // other triggers }
php
public function triggerEvent(string $event): void { // TODO: use event library and allow attach events to IFile and ICacheStateful. // cache triggers if ($this->file instanceof ICacheStateful) { switch ($event) { case self::EVENT_CACHED: $this->file->setCachedAt($this->name, time()); break; case self::EVENT_EMPTY: case self::EVENT_ERROR: case self::EVENT_NOT_FOUND: // TODO: split those and save different cases of cache state. $this->file->setCachedAt($this->name, null); break; } $this->file->saveState(); } // other triggers }
[ "public", "function", "triggerEvent", "(", "string", "$", "event", ")", ":", "void", "{", "// TODO: use event library and allow attach events to IFile and ICacheStateful.", "// cache triggers", "if", "(", "$", "this", "->", "file", "instanceof", "ICacheStateful", ")", "{", "switch", "(", "$", "event", ")", "{", "case", "self", "::", "EVENT_CACHED", ":", "$", "this", "->", "file", "->", "setCachedAt", "(", "$", "this", "->", "name", ",", "time", "(", ")", ")", ";", "break", ";", "case", "self", "::", "EVENT_EMPTY", ":", "case", "self", "::", "EVENT_ERROR", ":", "case", "self", "::", "EVENT_NOT_FOUND", ":", "// TODO: split those and save different cases of cache state.", "$", "this", "->", "file", "->", "setCachedAt", "(", "$", "this", "->", "name", ",", "null", ")", ";", "break", ";", "}", "$", "this", "->", "file", "->", "saveState", "(", ")", ";", "}", "// other triggers", "}" ]
Call user function after saving cached file @param string $event
[ "Call", "user", "function", "after", "saving", "cached", "file" ]
d6317a9b9b36d992f09affe3900ef7d7ddfd855f
https://github.com/t-kanstantsin/fileupload/blob/d6317a9b9b36d992f09affe3900ef7d7ddfd855f/src/formatter/File.php#L126-L147
train
linpax/microphp-framework
src/filter/XssFilter.php
XssFilter.doXssClean
private function doXssClean($data) { if (is_array($data) && count($data)) { foreach ($data as $k => &$v) { $v = $this->doXssClean($data[$k]); } return $data; } if (trim($data) === '') { return $data; } // xss_clean function from Kohana framework 2.3.1 $data = str_replace(['&amp;', '&lt;', '&gt;'], ['&amp;amp;', '&amp;lt;', '&amp;gt;'], $data); $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data); $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data); /** @noinspection CallableParameterUseCaseInTypeContextInspection */ $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8'); // Remove any attribute starting with "on" or xmlns $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data); // Remove javascript: and vbscript: protocols $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data); $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data); $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data); // Only works in IE: <span style="width: expression(alert('Ping!'));"></span> $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data); $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data); $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data); // Remove namespaced elements (we do not need them) $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data); do { // Remove really unwanted tags $old_data = $data; $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data); } while ($old_data !== $data); return $data; }
php
private function doXssClean($data) { if (is_array($data) && count($data)) { foreach ($data as $k => &$v) { $v = $this->doXssClean($data[$k]); } return $data; } if (trim($data) === '') { return $data; } // xss_clean function from Kohana framework 2.3.1 $data = str_replace(['&amp;', '&lt;', '&gt;'], ['&amp;amp;', '&amp;lt;', '&amp;gt;'], $data); $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data); $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data); /** @noinspection CallableParameterUseCaseInTypeContextInspection */ $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8'); // Remove any attribute starting with "on" or xmlns $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data); // Remove javascript: and vbscript: protocols $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data); $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data); $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data); // Only works in IE: <span style="width: expression(alert('Ping!'));"></span> $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data); $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data); $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data); // Remove namespaced elements (we do not need them) $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data); do { // Remove really unwanted tags $old_data = $data; $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data); } while ($old_data !== $data); return $data; }
[ "private", "function", "doXssClean", "(", "$", "data", ")", "{", "if", "(", "is_array", "(", "$", "data", ")", "&&", "count", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "k", "=>", "&", "$", "v", ")", "{", "$", "v", "=", "$", "this", "->", "doXssClean", "(", "$", "data", "[", "$", "k", "]", ")", ";", "}", "return", "$", "data", ";", "}", "if", "(", "trim", "(", "$", "data", ")", "===", "''", ")", "{", "return", "$", "data", ";", "}", "// xss_clean function from Kohana framework 2.3.1", "$", "data", "=", "str_replace", "(", "[", "'&amp;'", ",", "'&lt;'", ",", "'&gt;'", "]", ",", "[", "'&amp;amp;'", ",", "'&amp;lt;'", ",", "'&amp;gt;'", "]", ",", "$", "data", ")", ";", "$", "data", "=", "preg_replace", "(", "'/(&#*\\w+)[\\x00-\\x20]+;/u'", ",", "'$1;'", ",", "$", "data", ")", ";", "$", "data", "=", "preg_replace", "(", "'/(&#x*[0-9A-F]+);*/iu'", ",", "'$1;'", ",", "$", "data", ")", ";", "/** @noinspection CallableParameterUseCaseInTypeContextInspection */", "$", "data", "=", "html_entity_decode", "(", "$", "data", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ";", "// Remove any attribute starting with \"on\" or xmlns", "$", "data", "=", "preg_replace", "(", "'#(<[^>]+?[\\x00-\\x20\"\\'])(?:on|xmlns)[^>]*+>#iu'", ",", "'$1>'", ",", "$", "data", ")", ";", "// Remove javascript: and vbscript: protocols", "$", "data", "=", "preg_replace", "(", "'#([a-z]*)[\\x00-\\x20]*=[\\x00-\\x20]*([`\\'\"]*)[\\x00-\\x20]*j[\\x00-\\x20]*a[\\x00-\\x20]*v[\\x00-\\x20]*a[\\x00-\\x20]*s[\\x00-\\x20]*c[\\x00-\\x20]*r[\\x00-\\x20]*i[\\x00-\\x20]*p[\\x00-\\x20]*t[\\x00-\\x20]*:#iu'", ",", "'$1=$2nojavascript...'", ",", "$", "data", ")", ";", "$", "data", "=", "preg_replace", "(", "'#([a-z]*)[\\x00-\\x20]*=([\\'\"]*)[\\x00-\\x20]*v[\\x00-\\x20]*b[\\x00-\\x20]*s[\\x00-\\x20]*c[\\x00-\\x20]*r[\\x00-\\x20]*i[\\x00-\\x20]*p[\\x00-\\x20]*t[\\x00-\\x20]*:#iu'", ",", "'$1=$2novbscript...'", ",", "$", "data", ")", ";", "$", "data", "=", "preg_replace", "(", "'#([a-z]*)[\\x00-\\x20]*=([\\'\"]*)[\\x00-\\x20]*-moz-binding[\\x00-\\x20]*:#u'", ",", "'$1=$2nomozbinding...'", ",", "$", "data", ")", ";", "// Only works in IE: <span style=\"width: expression(alert('Ping!'));\"></span>", "$", "data", "=", "preg_replace", "(", "'#(<[^>]+?)style[\\x00-\\x20]*=[\\x00-\\x20]*[`\\'\"]*.*?expression[\\x00-\\x20]*\\([^>]*+>#i'", ",", "'$1>'", ",", "$", "data", ")", ";", "$", "data", "=", "preg_replace", "(", "'#(<[^>]+?)style[\\x00-\\x20]*=[\\x00-\\x20]*[`\\'\"]*.*?behaviour[\\x00-\\x20]*\\([^>]*+>#i'", ",", "'$1>'", ",", "$", "data", ")", ";", "$", "data", "=", "preg_replace", "(", "'#(<[^>]+?)style[\\x00-\\x20]*=[\\x00-\\x20]*[`\\'\"]*.*?s[\\x00-\\x20]*c[\\x00-\\x20]*r[\\x00-\\x20]*i[\\x00-\\x20]*p[\\x00-\\x20]*t[\\x00-\\x20]*:*[^>]*+>#iu'", ",", "'$1>'", ",", "$", "data", ")", ";", "// Remove namespaced elements (we do not need them)", "$", "data", "=", "preg_replace", "(", "'#</*\\w+:\\w[^>]*+>#i'", ",", "''", ",", "$", "data", ")", ";", "do", "{", "// Remove really unwanted tags", "$", "old_data", "=", "$", "data", ";", "$", "data", "=", "preg_replace", "(", "'#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i'", ",", "''", ",", "$", "data", ")", ";", "}", "while", "(", "$", "old_data", "!==", "$", "data", ")", ";", "return", "$", "data", ";", "}" ]
Do XSS Clean @access private @param array $data data for check @return mixed
[ "Do", "XSS", "Clean" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/filter/XssFilter.php#L47-L98
train
ciims/ciims-modules-hybridauth
HybridauthModule.php
HybridauthModule.getConfig
public function getConfig() { return array( 'baseUrl' => Yii::app()->getBaseUrl(true), 'base_url' => Yii::app()->getBaseUrl(true) . '/hybridauth/callback', // URL for Hybrid_Auth callback 'debug_mode' => YII_DEBUG, 'debug_file' => Yii::getPathOfAlias('application.runtime.hybridauth').'.log', 'providers' => CMap::mergeArray($this->providers, Cii::getHybridAuthProviders()), ); }
php
public function getConfig() { return array( 'baseUrl' => Yii::app()->getBaseUrl(true), 'base_url' => Yii::app()->getBaseUrl(true) . '/hybridauth/callback', // URL for Hybrid_Auth callback 'debug_mode' => YII_DEBUG, 'debug_file' => Yii::getPathOfAlias('application.runtime.hybridauth').'.log', 'providers' => CMap::mergeArray($this->providers, Cii::getHybridAuthProviders()), ); }
[ "public", "function", "getConfig", "(", ")", "{", "return", "array", "(", "'baseUrl'", "=>", "Yii", "::", "app", "(", ")", "->", "getBaseUrl", "(", "true", ")", ",", "'base_url'", "=>", "Yii", "::", "app", "(", ")", "->", "getBaseUrl", "(", "true", ")", ".", "'/hybridauth/callback'", ",", "// URL for Hybrid_Auth callback", "'debug_mode'", "=>", "YII_DEBUG", ",", "'debug_file'", "=>", "Yii", "::", "getPathOfAlias", "(", "'application.runtime.hybridauth'", ")", ".", "'.log'", ",", "'providers'", "=>", "CMap", "::", "mergeArray", "(", "$", "this", "->", "providers", ",", "Cii", "::", "getHybridAuthProviders", "(", ")", ")", ",", ")", ";", "}" ]
Convert configuration to an array for Hybrid_Auth, rather than object properties as supplied by Yii @return array
[ "Convert", "configuration", "to", "an", "array", "for", "Hybrid_Auth", "rather", "than", "object", "properties", "as", "supplied", "by", "Yii" ]
417b2682bf3468dd509164a9b773d886359a7aec
https://github.com/ciims/ciims-modules-hybridauth/blob/417b2682bf3468dd509164a9b773d886359a7aec/HybridauthModule.php#L33-L42
train
gangachris/potato-orm
src/Connection.php
Connection.db
public static function db() { self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return self::$conn; }
php
public static function db() { self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return self::$conn; }
[ "public", "static", "function", "db", "(", ")", "{", "self", "::", "$", "conn", "->", "setAttribute", "(", "PDO", "::", "ATTR_ERRMODE", ",", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "return", "self", "::", "$", "conn", ";", "}" ]
Get an instance of the db connection @return SQLite3 connection
[ "Get", "an", "instance", "of", "the", "db", "connection" ]
12bb25ca31716aac97bbe78596810220e39626b0
https://github.com/gangachris/potato-orm/blob/12bb25ca31716aac97bbe78596810220e39626b0/src/Connection.php#L53-L57
train
miknatr/grace-dbal
lib/Grace/SQLBuilder/SelectBuilder.php
SelectBuilder.fields
public function fields(array $fields) { $newFields = array(); $this->fields = ''; $this->fieldsArguments = array(); foreach ($fields as $field) { if (is_scalar($field)) { $newFields[] = '?f:alias:.?f'; $this->fieldsArguments[] = $field; } else { if (!isset($field[0]) or !isset($field[1]) or !is_array($field[1])) { throw new \BadMethodCallException('Must be exist 0 and 1 index in array and second one must be an array'); } $newFields[] = $field[0]; $this->fieldsArguments = array_merge($this->fieldsArguments, $field[1]); } } $this->fields = implode(', ', $newFields); return $this; }
php
public function fields(array $fields) { $newFields = array(); $this->fields = ''; $this->fieldsArguments = array(); foreach ($fields as $field) { if (is_scalar($field)) { $newFields[] = '?f:alias:.?f'; $this->fieldsArguments[] = $field; } else { if (!isset($field[0]) or !isset($field[1]) or !is_array($field[1])) { throw new \BadMethodCallException('Must be exist 0 and 1 index in array and second one must be an array'); } $newFields[] = $field[0]; $this->fieldsArguments = array_merge($this->fieldsArguments, $field[1]); } } $this->fields = implode(', ', $newFields); return $this; }
[ "public", "function", "fields", "(", "array", "$", "fields", ")", "{", "$", "newFields", "=", "array", "(", ")", ";", "$", "this", "->", "fields", "=", "''", ";", "$", "this", "->", "fieldsArguments", "=", "array", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "if", "(", "is_scalar", "(", "$", "field", ")", ")", "{", "$", "newFields", "[", "]", "=", "'?f:alias:.?f'", ";", "$", "this", "->", "fieldsArguments", "[", "]", "=", "$", "field", ";", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "field", "[", "0", "]", ")", "or", "!", "isset", "(", "$", "field", "[", "1", "]", ")", "or", "!", "is_array", "(", "$", "field", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "'Must be exist 0 and 1 index in array and second one must be an array'", ")", ";", "}", "$", "newFields", "[", "]", "=", "$", "field", "[", "0", "]", ";", "$", "this", "->", "fieldsArguments", "=", "array_merge", "(", "$", "this", "->", "fieldsArguments", ",", "$", "field", "[", "1", "]", ")", ";", "}", "}", "$", "this", "->", "fields", "=", "implode", "(", "', '", ",", "$", "newFields", ")", ";", "return", "$", "this", ";", "}" ]
Sets fields statement @param $fields array('id', array('AsText(?f) AS ?f', array('coords', 'coords'))) @throws \BadMethodCallException @return $this
[ "Sets", "fields", "statement" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/SQLBuilder/SelectBuilder.php#L53-L75
train
miknatr/grace-dbal
lib/Grace/SQLBuilder/SelectBuilder.php
SelectBuilder.join
public function join($tableName, $alias = null) { $this->joins[] = ' LEFT JOIN ?f as ?f'; $this->lastJoinAlias = $alias; $this->joinArguments[] = $tableName; $this->joinArguments[] = $alias; return $this; }
php
public function join($tableName, $alias = null) { $this->joins[] = ' LEFT JOIN ?f as ?f'; $this->lastJoinAlias = $alias; $this->joinArguments[] = $tableName; $this->joinArguments[] = $alias; return $this; }
[ "public", "function", "join", "(", "$", "tableName", ",", "$", "alias", "=", "null", ")", "{", "$", "this", "->", "joins", "[", "]", "=", "' LEFT JOIN ?f as ?f'", ";", "$", "this", "->", "lastJoinAlias", "=", "$", "alias", ";", "$", "this", "->", "joinArguments", "[", "]", "=", "$", "tableName", ";", "$", "this", "->", "joinArguments", "[", "]", "=", "$", "alias", ";", "return", "$", "this", ";", "}" ]
Sets one field in fields statement @param string $tableName @param string $alias @return $this
[ "Sets", "one", "field", "in", "fields", "statement" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/SQLBuilder/SelectBuilder.php#L106-L113
train
miknatr/grace-dbal
lib/Grace/SQLBuilder/SelectBuilder.php
SelectBuilder.orderByDirection
protected function orderByDirection($field, $direction, $prefixWithTableAlias = true) { $aliasInsert = $prefixWithTableAlias ? '?f:alias:.' : ''; if ($this->orderSql == '') { $this->orderSql = " ORDER BY {$aliasInsert}?f {$direction}"; } else { $this->orderSql .= ", {$aliasInsert}?f {$direction}"; } $this->orderArguments[] = $field; }
php
protected function orderByDirection($field, $direction, $prefixWithTableAlias = true) { $aliasInsert = $prefixWithTableAlias ? '?f:alias:.' : ''; if ($this->orderSql == '') { $this->orderSql = " ORDER BY {$aliasInsert}?f {$direction}"; } else { $this->orderSql .= ", {$aliasInsert}?f {$direction}"; } $this->orderArguments[] = $field; }
[ "protected", "function", "orderByDirection", "(", "$", "field", ",", "$", "direction", ",", "$", "prefixWithTableAlias", "=", "true", ")", "{", "$", "aliasInsert", "=", "$", "prefixWithTableAlias", "?", "'?f:alias:.'", ":", "''", ";", "if", "(", "$", "this", "->", "orderSql", "==", "''", ")", "{", "$", "this", "->", "orderSql", "=", "\" ORDER BY {$aliasInsert}?f {$direction}\"", ";", "}", "else", "{", "$", "this", "->", "orderSql", ".=", "\", {$aliasInsert}?f {$direction}\"", ";", "}", "$", "this", "->", "orderArguments", "[", "]", "=", "$", "field", ";", "}" ]
Sets order by statement @param string $field @param string $direction @param bool $prefixWithTableAlias @return $this
[ "Sets", "order", "by", "statement" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/SQLBuilder/SelectBuilder.php#L213-L223
train
WellCommerce/AdminBundle
Importer/XmlImporter.php
XmlImporter.importItems
protected function importItems(\DOMDocument $xml) { foreach ($xml->documentElement->getElementsByTagName('item') as $item) { $dom = simplexml_import_dom($item); $this->addMenuItem($dom); } }
php
protected function importItems(\DOMDocument $xml) { foreach ($xml->documentElement->getElementsByTagName('item') as $item) { $dom = simplexml_import_dom($item); $this->addMenuItem($dom); } }
[ "protected", "function", "importItems", "(", "\\", "DOMDocument", "$", "xml", ")", "{", "foreach", "(", "$", "xml", "->", "documentElement", "->", "getElementsByTagName", "(", "'item'", ")", "as", "$", "item", ")", "{", "$", "dom", "=", "simplexml_import_dom", "(", "$", "item", ")", ";", "$", "this", "->", "addMenuItem", "(", "$", "dom", ")", ";", "}", "}" ]
Parses DOM element and adds it as an admin menu item @param \DOMDocument $xml
[ "Parses", "DOM", "element", "and", "adds", "it", "as", "an", "admin", "menu", "item" ]
5721f0b9a506023ed6beb6bdf79e4ccbbe546516
https://github.com/WellCommerce/AdminBundle/blob/5721f0b9a506023ed6beb6bdf79e4ccbbe546516/Importer/XmlImporter.php#L67-L73
train
WellCommerce/AdminBundle
Importer/XmlImporter.php
XmlImporter.addMenuItem
protected function addMenuItem(\SimpleXMLElement $item) { $em = $this->doctrineHelper->getEntityManager(); $adminMenuItem = $this->adminMenuRepository->findOneBy(['identifier' => (string)$item->identifier]); $parent = $this->adminMenuRepository->findOneBy(['identifier' => (string)$item->parent]); if (null === $adminMenuItem) { $adminMenuItem = new AdminMenu(); $adminMenuItem->setCssClass((string)$item->css_class); $adminMenuItem->setIdentifier((string)$item->identifier); $adminMenuItem->setName((string)$item->name); $adminMenuItem->setRouteName((string)$item->route_name); $adminMenuItem->setHierarchy((int)$item->hierarchy); $adminMenuItem->setParent($parent); $em->persist($adminMenuItem); $em->flush(); } }
php
protected function addMenuItem(\SimpleXMLElement $item) { $em = $this->doctrineHelper->getEntityManager(); $adminMenuItem = $this->adminMenuRepository->findOneBy(['identifier' => (string)$item->identifier]); $parent = $this->adminMenuRepository->findOneBy(['identifier' => (string)$item->parent]); if (null === $adminMenuItem) { $adminMenuItem = new AdminMenu(); $adminMenuItem->setCssClass((string)$item->css_class); $adminMenuItem->setIdentifier((string)$item->identifier); $adminMenuItem->setName((string)$item->name); $adminMenuItem->setRouteName((string)$item->route_name); $adminMenuItem->setHierarchy((int)$item->hierarchy); $adminMenuItem->setParent($parent); $em->persist($adminMenuItem); $em->flush(); } }
[ "protected", "function", "addMenuItem", "(", "\\", "SimpleXMLElement", "$", "item", ")", "{", "$", "em", "=", "$", "this", "->", "doctrineHelper", "->", "getEntityManager", "(", ")", ";", "$", "adminMenuItem", "=", "$", "this", "->", "adminMenuRepository", "->", "findOneBy", "(", "[", "'identifier'", "=>", "(", "string", ")", "$", "item", "->", "identifier", "]", ")", ";", "$", "parent", "=", "$", "this", "->", "adminMenuRepository", "->", "findOneBy", "(", "[", "'identifier'", "=>", "(", "string", ")", "$", "item", "->", "parent", "]", ")", ";", "if", "(", "null", "===", "$", "adminMenuItem", ")", "{", "$", "adminMenuItem", "=", "new", "AdminMenu", "(", ")", ";", "$", "adminMenuItem", "->", "setCssClass", "(", "(", "string", ")", "$", "item", "->", "css_class", ")", ";", "$", "adminMenuItem", "->", "setIdentifier", "(", "(", "string", ")", "$", "item", "->", "identifier", ")", ";", "$", "adminMenuItem", "->", "setName", "(", "(", "string", ")", "$", "item", "->", "name", ")", ";", "$", "adminMenuItem", "->", "setRouteName", "(", "(", "string", ")", "$", "item", "->", "route_name", ")", ";", "$", "adminMenuItem", "->", "setHierarchy", "(", "(", "int", ")", "$", "item", "->", "hierarchy", ")", ";", "$", "adminMenuItem", "->", "setParent", "(", "$", "parent", ")", ";", "$", "em", "->", "persist", "(", "$", "adminMenuItem", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "}", "}" ]
Creates new admin menu item @param \SimpleXMLElement $item
[ "Creates", "new", "admin", "menu", "item" ]
5721f0b9a506023ed6beb6bdf79e4ccbbe546516
https://github.com/WellCommerce/AdminBundle/blob/5721f0b9a506023ed6beb6bdf79e4ccbbe546516/Importer/XmlImporter.php#L80-L98
train
codeblanche/Web
src/Web/Route/Router.php
Router.resolveRulePrototype
private function resolveRulePrototype() { if (!isset($this->routeTypeRulePrototypeMap[$this->routeType])) { throw new RuntimeException("Unable to resolve rule for route type '$this->routeType'. Route type is not supported."); } $prototypeClass = $this->routeTypeRulePrototypeMap[$this->routeType]; $prototype = $this->dependencyManager->get($prototypeClass); if (!($prototype instanceof AbstractRule)) { $givenType = get_class($prototype); throw new RuntimeException("The resolved rule prototype must inherit from Web\Route\Rule. Rule of type '$givenType' is not valid."); } $this->rulePrototype = $prototype; }
php
private function resolveRulePrototype() { if (!isset($this->routeTypeRulePrototypeMap[$this->routeType])) { throw new RuntimeException("Unable to resolve rule for route type '$this->routeType'. Route type is not supported."); } $prototypeClass = $this->routeTypeRulePrototypeMap[$this->routeType]; $prototype = $this->dependencyManager->get($prototypeClass); if (!($prototype instanceof AbstractRule)) { $givenType = get_class($prototype); throw new RuntimeException("The resolved rule prototype must inherit from Web\Route\Rule. Rule of type '$givenType' is not valid."); } $this->rulePrototype = $prototype; }
[ "private", "function", "resolveRulePrototype", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "routeTypeRulePrototypeMap", "[", "$", "this", "->", "routeType", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Unable to resolve rule for route type '$this->routeType'. Route type is not supported.\"", ")", ";", "}", "$", "prototypeClass", "=", "$", "this", "->", "routeTypeRulePrototypeMap", "[", "$", "this", "->", "routeType", "]", ";", "$", "prototype", "=", "$", "this", "->", "dependencyManager", "->", "get", "(", "$", "prototypeClass", ")", ";", "if", "(", "!", "(", "$", "prototype", "instanceof", "AbstractRule", ")", ")", "{", "$", "givenType", "=", "get_class", "(", "$", "prototype", ")", ";", "throw", "new", "RuntimeException", "(", "\"The resolved rule prototype must inherit from Web\\Route\\Rule. Rule of type '$givenType' is not valid.\"", ")", ";", "}", "$", "this", "->", "rulePrototype", "=", "$", "prototype", ";", "}" ]
Resolve the rule prototype object for the current routeType @throws \Web\Exception\RuntimeException
[ "Resolve", "the", "rule", "prototype", "object", "for", "the", "current", "routeType" ]
3e9ebf1943d3ea468f619ba99f7cc10714cb16e9
https://github.com/codeblanche/Web/blob/3e9ebf1943d3ea468f619ba99f7cc10714cb16e9/src/Web/Route/Router.php#L70-L86
train
codeblanche/Web
src/Web/Route/Router.php
Router.define
public function define($pattern, $controller, $filters = array()) { $rule = clone $this->rulePrototype; $rule->setPattern($pattern)->setController($controller)->setFilters($filters); array_push($this->rules, $rule); return $this; }
php
public function define($pattern, $controller, $filters = array()) { $rule = clone $this->rulePrototype; $rule->setPattern($pattern)->setController($controller)->setFilters($filters); array_push($this->rules, $rule); return $this; }
[ "public", "function", "define", "(", "$", "pattern", ",", "$", "controller", ",", "$", "filters", "=", "array", "(", ")", ")", "{", "$", "rule", "=", "clone", "$", "this", "->", "rulePrototype", ";", "$", "rule", "->", "setPattern", "(", "$", "pattern", ")", "->", "setController", "(", "$", "controller", ")", "->", "setFilters", "(", "$", "filters", ")", ";", "array_push", "(", "$", "this", "->", "rules", ",", "$", "rule", ")", ";", "return", "$", "this", ";", "}" ]
Define a routing rule with corresponding controller @param string $pattern @param string $controller Class name or alias @param array $filters @return $this
[ "Define", "a", "routing", "rule", "with", "corresponding", "controller" ]
3e9ebf1943d3ea468f619ba99f7cc10714cb16e9
https://github.com/codeblanche/Web/blob/3e9ebf1943d3ea468f619ba99f7cc10714cb16e9/src/Web/Route/Router.php#L109-L118
train
Aviogram/Common
src/ClassUtils.php
ClassUtils.parseClass
protected static function parseClass($class) { static $cache = array(); if (array_key_exists($class, $cache) === false) { // Make reference for original input $string = $class; if ($string[0] === '\\') { $string = substr($string, 1); } if (preg_match('/^(?<namespace>.*)\\\\(?<className>.+?)$/', $string, $matches)) { $cache[$class] = array($matches['namespace'], $matches['className']); } else { $cache[$class] = array(null, $class); } } return $cache[$class]; }
php
protected static function parseClass($class) { static $cache = array(); if (array_key_exists($class, $cache) === false) { // Make reference for original input $string = $class; if ($string[0] === '\\') { $string = substr($string, 1); } if (preg_match('/^(?<namespace>.*)\\\\(?<className>.+?)$/', $string, $matches)) { $cache[$class] = array($matches['namespace'], $matches['className']); } else { $cache[$class] = array(null, $class); } } return $cache[$class]; }
[ "protected", "static", "function", "parseClass", "(", "$", "class", ")", "{", "static", "$", "cache", "=", "array", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "class", ",", "$", "cache", ")", "===", "false", ")", "{", "// Make reference for original input", "$", "string", "=", "$", "class", ";", "if", "(", "$", "string", "[", "0", "]", "===", "'\\\\'", ")", "{", "$", "string", "=", "substr", "(", "$", "string", ",", "1", ")", ";", "}", "if", "(", "preg_match", "(", "'/^(?<namespace>.*)\\\\\\\\(?<className>.+?)$/'", ",", "$", "string", ",", "$", "matches", ")", ")", "{", "$", "cache", "[", "$", "class", "]", "=", "array", "(", "$", "matches", "[", "'namespace'", "]", ",", "$", "matches", "[", "'className'", "]", ")", ";", "}", "else", "{", "$", "cache", "[", "$", "class", "]", "=", "array", "(", "null", ",", "$", "class", ")", ";", "}", "}", "return", "$", "cache", "[", "$", "class", "]", ";", "}" ]
Parse the class to a namespace and className part @param string $class @return array array(<namespace>, <className>)
[ "Parse", "the", "class", "to", "a", "namespace", "and", "className", "part" ]
bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5
https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/ClassUtils.php#L71-L91
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.requestHandler
public static function requestHandler($type) { if (! self::validateRequest($type)) { return false; } App::setCurrentID(self::$config['app']); self::loadRemoteComplements(); switch (self::$config['request']) { case 'load-complements': self::complementsLoadRequest(); break; case 'change-state': self::changeStateRequest(); break; case 'install': self::installRequest(); break; case 'update': self::installRequest(true); break; case 'uninstall': self::uninstallRequest(); break; default: self::$errors[] = [ 'message' => 'Unknown request: ' . self::$config['request'], ]; echo json_encode(['errors' => self::$errors]); break; } if (empty(App::getOption('development-environment'))) { die; } }
php
public static function requestHandler($type) { if (! self::validateRequest($type)) { return false; } App::setCurrentID(self::$config['app']); self::loadRemoteComplements(); switch (self::$config['request']) { case 'load-complements': self::complementsLoadRequest(); break; case 'change-state': self::changeStateRequest(); break; case 'install': self::installRequest(); break; case 'update': self::installRequest(true); break; case 'uninstall': self::uninstallRequest(); break; default: self::$errors[] = [ 'message' => 'Unknown request: ' . self::$config['request'], ]; echo json_encode(['errors' => self::$errors]); break; } if (empty(App::getOption('development-environment'))) { die; } }
[ "public", "static", "function", "requestHandler", "(", "$", "type", ")", "{", "if", "(", "!", "self", "::", "validateRequest", "(", "$", "type", ")", ")", "{", "return", "false", ";", "}", "App", "::", "setCurrentID", "(", "self", "::", "$", "config", "[", "'app'", "]", ")", ";", "self", "::", "loadRemoteComplements", "(", ")", ";", "switch", "(", "self", "::", "$", "config", "[", "'request'", "]", ")", "{", "case", "'load-complements'", ":", "self", "::", "complementsLoadRequest", "(", ")", ";", "break", ";", "case", "'change-state'", ":", "self", "::", "changeStateRequest", "(", ")", ";", "break", ";", "case", "'install'", ":", "self", "::", "installRequest", "(", ")", ";", "break", ";", "case", "'update'", ":", "self", "::", "installRequest", "(", "true", ")", ";", "break", ";", "case", "'uninstall'", ":", "self", "::", "uninstallRequest", "(", ")", ";", "break", ";", "default", ":", "self", "::", "$", "errors", "[", "]", "=", "[", "'message'", "=>", "'Unknown request: '", ".", "self", "::", "$", "config", "[", "'request'", "]", ",", "]", ";", "echo", "json_encode", "(", "[", "'errors'", "=>", "self", "::", "$", "errors", "]", ")", ";", "break", ";", "}", "if", "(", "empty", "(", "App", "::", "getOption", "(", "'development-environment'", ")", ")", ")", "{", "die", ";", "}", "}" ]
HTTP request handler. @param string $type → complement type @uses \Eliasis\Framework\App::setCurrentID()
[ "HTTP", "request", "handler", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L34-L71
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.sanitizeParams
public static function sanitizeParams() { self::$config['remote'] = []; $remote = is_array($_POST['remote']) ? $_POST['remote'] : []; foreach ($remote as $complement => $url) { $url = filter_var($url, FILTER_VALIDATE_URL); if ($url === false) { return false; } self::$config['remote'][$complement] = $url; } $params = ['id', 'app', 'request', 'filter', 'sort', 'nonce', 'complement']; foreach ($params as $param) { $value = filter_var($_POST[$param], FILTER_SANITIZE_STRING); if ($value === false) { return false; } self::$config[$param] = $value; } return true; }
php
public static function sanitizeParams() { self::$config['remote'] = []; $remote = is_array($_POST['remote']) ? $_POST['remote'] : []; foreach ($remote as $complement => $url) { $url = filter_var($url, FILTER_VALIDATE_URL); if ($url === false) { return false; } self::$config['remote'][$complement] = $url; } $params = ['id', 'app', 'request', 'filter', 'sort', 'nonce', 'complement']; foreach ($params as $param) { $value = filter_var($_POST[$param], FILTER_SANITIZE_STRING); if ($value === false) { return false; } self::$config[$param] = $value; } return true; }
[ "public", "static", "function", "sanitizeParams", "(", ")", "{", "self", "::", "$", "config", "[", "'remote'", "]", "=", "[", "]", ";", "$", "remote", "=", "is_array", "(", "$", "_POST", "[", "'remote'", "]", ")", "?", "$", "_POST", "[", "'remote'", "]", ":", "[", "]", ";", "foreach", "(", "$", "remote", "as", "$", "complement", "=>", "$", "url", ")", "{", "$", "url", "=", "filter_var", "(", "$", "url", ",", "FILTER_VALIDATE_URL", ")", ";", "if", "(", "$", "url", "===", "false", ")", "{", "return", "false", ";", "}", "self", "::", "$", "config", "[", "'remote'", "]", "[", "$", "complement", "]", "=", "$", "url", ";", "}", "$", "params", "=", "[", "'id'", ",", "'app'", ",", "'request'", ",", "'filter'", ",", "'sort'", ",", "'nonce'", ",", "'complement'", "]", ";", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "$", "value", "=", "filter_var", "(", "$", "_POST", "[", "$", "param", "]", ",", "FILTER_SANITIZE_STRING", ")", ";", "if", "(", "$", "value", "===", "false", ")", "{", "return", "false", ";", "}", "self", "::", "$", "config", "[", "$", "param", "]", "=", "$", "value", ";", "}", "return", "true", ";", "}" ]
Sanitize request parameters. @since 1.1.0 @return bool
[ "Sanitize", "request", "parameters", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L121-L145
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.loadRemoteComplements
private static function loadRemoteComplements() { $currentID = App::getCurrentID(); $complement = self::getType(); $remote = self::$config['remote']; $complements = array_keys(self::$instances[$currentID][$complement]); foreach ($remote as $complement => $url) { if (! in_array($complement, $complements, true)) { self::load($url); } self::$complement()->setOption('config-url', $url); } }
php
private static function loadRemoteComplements() { $currentID = App::getCurrentID(); $complement = self::getType(); $remote = self::$config['remote']; $complements = array_keys(self::$instances[$currentID][$complement]); foreach ($remote as $complement => $url) { if (! in_array($complement, $complements, true)) { self::load($url); } self::$complement()->setOption('config-url', $url); } }
[ "private", "static", "function", "loadRemoteComplements", "(", ")", "{", "$", "currentID", "=", "App", "::", "getCurrentID", "(", ")", ";", "$", "complement", "=", "self", "::", "getType", "(", ")", ";", "$", "remote", "=", "self", "::", "$", "config", "[", "'remote'", "]", ";", "$", "complements", "=", "array_keys", "(", "self", "::", "$", "instances", "[", "$", "currentID", "]", "[", "$", "complement", "]", ")", ";", "foreach", "(", "$", "remote", "as", "$", "complement", "=>", "$", "url", ")", "{", "if", "(", "!", "in_array", "(", "$", "complement", ",", "$", "complements", ",", "true", ")", ")", "{", "self", "::", "load", "(", "$", "url", ")", ";", "}", "self", "::", "$", "complement", "(", ")", "->", "setOption", "(", "'config-url'", ",", "$", "url", ")", ";", "}", "}" ]
Load remote complements. @uses \Eliasis\Complement\Complement->$instances @uses \Eliasis\Complement\Complement::load() @uses \Eliasis\Complement\Complement::$errors
[ "Load", "remote", "complements", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L154-L169
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.complementsLoadRequest
private static function complementsLoadRequest() { $complements = self::getList(self::$config['filter'], self::$config['sort']); $response = [ 'complements' => array_values($complements), 'errors' => self::$errors, ]; echo json_encode($response); }
php
private static function complementsLoadRequest() { $complements = self::getList(self::$config['filter'], self::$config['sort']); $response = [ 'complements' => array_values($complements), 'errors' => self::$errors, ]; echo json_encode($response); }
[ "private", "static", "function", "complementsLoadRequest", "(", ")", "{", "$", "complements", "=", "self", "::", "getList", "(", "self", "::", "$", "config", "[", "'filter'", "]", ",", "self", "::", "$", "config", "[", "'sort'", "]", ")", ";", "$", "response", "=", "[", "'complements'", "=>", "array_values", "(", "$", "complements", ")", ",", "'errors'", "=>", "self", "::", "$", "errors", ",", "]", ";", "echo", "json_encode", "(", "$", "response", ")", ";", "}" ]
Complements load request. @uses \Eliasis\Complement\Complement::getList() @uses \Eliasis\Complement\Complement::$errors
[ "Complements", "load", "request", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L177-L187
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.changeStateRequest
private static function changeStateRequest() { self::$id = self::$config['id']; $that = self::getInstance(); $state = $that->changeState(); $response = [ 'state' => $state, 'errors' => self::$errors, ]; echo json_encode($response); }
php
private static function changeStateRequest() { self::$id = self::$config['id']; $that = self::getInstance(); $state = $that->changeState(); $response = [ 'state' => $state, 'errors' => self::$errors, ]; echo json_encode($response); }
[ "private", "static", "function", "changeStateRequest", "(", ")", "{", "self", "::", "$", "id", "=", "self", "::", "$", "config", "[", "'id'", "]", ";", "$", "that", "=", "self", "::", "getInstance", "(", ")", ";", "$", "state", "=", "$", "that", "->", "changeState", "(", ")", ";", "$", "response", "=", "[", "'state'", "=>", "$", "state", ",", "'errors'", "=>", "self", "::", "$", "errors", ",", "]", ";", "echo", "json_encode", "(", "$", "response", ")", ";", "}" ]
Change state request. @uses \Eliasis\Complement\Complement::getInstance() @uses \Eliasis\Complement\Traits\ComplementState->changeState() @uses \Eliasis\Complement\Complement::$errors
[ "Change", "state", "request", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L196-L208
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.installRequest
private static function installRequest($isUpdate = false) { self::$id = self::$config['id']; $that = self::getInstance(); $that->install(); $that->setState($isUpdate ? 'active' : 'inactive'); $complements = self::getList(self::$config['filter'], self::$config['sort']); $complement = $complements[self::$id]; $response = [ 'complement' => $complement, 'errors' => self::$errors, ]; echo json_encode($response); }
php
private static function installRequest($isUpdate = false) { self::$id = self::$config['id']; $that = self::getInstance(); $that->install(); $that->setState($isUpdate ? 'active' : 'inactive'); $complements = self::getList(self::$config['filter'], self::$config['sort']); $complement = $complements[self::$id]; $response = [ 'complement' => $complement, 'errors' => self::$errors, ]; echo json_encode($response); }
[ "private", "static", "function", "installRequest", "(", "$", "isUpdate", "=", "false", ")", "{", "self", "::", "$", "id", "=", "self", "::", "$", "config", "[", "'id'", "]", ";", "$", "that", "=", "self", "::", "getInstance", "(", ")", ";", "$", "that", "->", "install", "(", ")", ";", "$", "that", "->", "setState", "(", "$", "isUpdate", "?", "'active'", ":", "'inactive'", ")", ";", "$", "complements", "=", "self", "::", "getList", "(", "self", "::", "$", "config", "[", "'filter'", "]", ",", "self", "::", "$", "config", "[", "'sort'", "]", ")", ";", "$", "complement", "=", "$", "complements", "[", "self", "::", "$", "id", "]", ";", "$", "response", "=", "[", "'complement'", "=>", "$", "complement", ",", "'errors'", "=>", "self", "::", "$", "errors", ",", "]", ";", "echo", "json_encode", "(", "$", "response", ")", ";", "}" ]
Install request. @param string $isUpdate → if it is an update @uses \Eliasis\Complement\Complement::getInstance() @uses \Eliasis\Complement\Traits\ComplementImport->install() @uses \Eliasis\Complement\Complement::$errors
[ "Install", "request", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L219-L239
train
eliasis-framework/complement
src/Traits/ComplementRequest.php
ComplementRequest.uninstallRequest
private static function uninstallRequest() { self::$id = self::$config['id']; $that = self::getInstance(); $that->remove(); $state = 'uninstalled'; $response = [ 'state' => $state, 'errors' => self::$errors, ]; echo json_encode($response); }
php
private static function uninstallRequest() { self::$id = self::$config['id']; $that = self::getInstance(); $that->remove(); $state = 'uninstalled'; $response = [ 'state' => $state, 'errors' => self::$errors, ]; echo json_encode($response); }
[ "private", "static", "function", "uninstallRequest", "(", ")", "{", "self", "::", "$", "id", "=", "self", "::", "$", "config", "[", "'id'", "]", ";", "$", "that", "=", "self", "::", "getInstance", "(", ")", ";", "$", "that", "->", "remove", "(", ")", ";", "$", "state", "=", "'uninstalled'", ";", "$", "response", "=", "[", "'state'", "=>", "$", "state", ",", "'errors'", "=>", "self", "::", "$", "errors", ",", "]", ";", "echo", "json_encode", "(", "$", "response", ")", ";", "}" ]
Uninstall request. @uses \Eliasis\Complement\Complement::getInstance() @uses \string ComplementImport->remove() @uses \Eliasis\Complement\Complement::$errors
[ "Uninstall", "request", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementRequest.php#L248-L261
train
AndyDune/DateTime
src/Action/WorkingDaysTrait.php
WorkingDaysTrait.setNoWorkingDays
public function setNoWorkingDays(array $days, $format = null) { $this->noWorkingDays = $days; if ($format) { $this->formatNoWorkingDays = $format; } return $this; }
php
public function setNoWorkingDays(array $days, $format = null) { $this->noWorkingDays = $days; if ($format) { $this->formatNoWorkingDays = $format; } return $this; }
[ "public", "function", "setNoWorkingDays", "(", "array", "$", "days", ",", "$", "format", "=", "null", ")", "{", "$", "this", "->", "noWorkingDays", "=", "$", "days", ";", "if", "(", "$", "format", ")", "{", "$", "this", "->", "formatNoWorkingDays", "=", "$", "format", ";", "}", "return", "$", "this", ";", "}" ]
Set official no working days for your country. Format: ['j-m', 'j-m', ...] @param $days @param $format @return $this
[ "Set", "official", "no", "working", "days", "for", "your", "country", "." ]
4f49f449b23072ac6d2ae0f1ea4b8e34804b760f
https://github.com/AndyDune/DateTime/blob/4f49f449b23072ac6d2ae0f1ea4b8e34804b760f/src/Action/WorkingDaysTrait.php#L53-L60
train
AndyDune/DateTime
src/Action/WorkingDaysTrait.php
WorkingDaysTrait.setWorkingDays
public function setWorkingDays(array $days, $format = null) { $this->workingDays = $days; if ($format) { $this->formatWorkingDays = $format; } return $this; }
php
public function setWorkingDays(array $days, $format = null) { $this->workingDays = $days; if ($format) { $this->formatWorkingDays = $format; } return $this; }
[ "public", "function", "setWorkingDays", "(", "array", "$", "days", ",", "$", "format", "=", "null", ")", "{", "$", "this", "->", "workingDays", "=", "$", "days", ";", "if", "(", "$", "format", ")", "{", "$", "this", "->", "formatWorkingDays", "=", "$", "format", ";", "}", "return", "$", "this", ";", "}" ]
Set working days as exclusion. @param array $days @param null $format @return $this
[ "Set", "working", "days", "as", "exclusion", "." ]
4f49f449b23072ac6d2ae0f1ea4b8e34804b760f
https://github.com/AndyDune/DateTime/blob/4f49f449b23072ac6d2ae0f1ea4b8e34804b760f/src/Action/WorkingDaysTrait.php#L69-L76
train
inetstudio/widgets
src/Models/Traits/HasWidgets.php
HasWidgets.bootHasWidgets
public static function bootHasWidgets() { static::created(function (Model $widgetableModel) { if ($widgetableModel->queuedWidgets) { $widgetableModel->attachWidgets($widgetableModel->queuedWidgets); $widgetableModel->queuedWidgets = []; } }); static::deleted(function (Model $widgetableModel) { $widgetableModel->syncWidgets(null); }); }
php
public static function bootHasWidgets() { static::created(function (Model $widgetableModel) { if ($widgetableModel->queuedWidgets) { $widgetableModel->attachWidgets($widgetableModel->queuedWidgets); $widgetableModel->queuedWidgets = []; } }); static::deleted(function (Model $widgetableModel) { $widgetableModel->syncWidgets(null); }); }
[ "public", "static", "function", "bootHasWidgets", "(", ")", "{", "static", "::", "created", "(", "function", "(", "Model", "$", "widgetableModel", ")", "{", "if", "(", "$", "widgetableModel", "->", "queuedWidgets", ")", "{", "$", "widgetableModel", "->", "attachWidgets", "(", "$", "widgetableModel", "->", "queuedWidgets", ")", ";", "$", "widgetableModel", "->", "queuedWidgets", "=", "[", "]", ";", "}", "}", ")", ";", "static", "::", "deleted", "(", "function", "(", "Model", "$", "widgetableModel", ")", "{", "$", "widgetableModel", "->", "syncWidgets", "(", "null", ")", ";", "}", ")", ";", "}" ]
Boot the widgetable trait for a model. @return void
[ "Boot", "the", "widgetable", "trait", "for", "a", "model", "." ]
bc9357a1183a028f93f725b55b9db2867b7ec731
https://github.com/inetstudio/widgets/blob/bc9357a1183a028f93f725b55b9db2867b7ec731/src/Models/Traits/HasWidgets.php#L65-L77
train
inetstudio/widgets
src/Models/Traits/HasWidgets.php
HasWidgets.scopeWithAllWidgets
public function scopeWithAllWidgets(Builder $query, $widgets, string $column = 'id'): Builder { $widgets = static::isWidgetsStringBased($widgets) ? $widgets : static::hydrateWidgets($widgets)->pluck($column); collect($widgets)->each(function ($widget) use ($query, $column) { $query->whereHas('widgets', function (Builder $query) use ($widget, $column) { return $query->where($column, $widget); }); }); return $query; }
php
public function scopeWithAllWidgets(Builder $query, $widgets, string $column = 'id'): Builder { $widgets = static::isWidgetsStringBased($widgets) ? $widgets : static::hydrateWidgets($widgets)->pluck($column); collect($widgets)->each(function ($widget) use ($query, $column) { $query->whereHas('widgets', function (Builder $query) use ($widget, $column) { return $query->where($column, $widget); }); }); return $query; }
[ "public", "function", "scopeWithAllWidgets", "(", "Builder", "$", "query", ",", "$", "widgets", ",", "string", "$", "column", "=", "'id'", ")", ":", "Builder", "{", "$", "widgets", "=", "static", "::", "isWidgetsStringBased", "(", "$", "widgets", ")", "?", "$", "widgets", ":", "static", "::", "hydrateWidgets", "(", "$", "widgets", ")", "->", "pluck", "(", "$", "column", ")", ";", "collect", "(", "$", "widgets", ")", "->", "each", "(", "function", "(", "$", "widget", ")", "use", "(", "$", "query", ",", "$", "column", ")", "{", "$", "query", "->", "whereHas", "(", "'widgets'", ",", "function", "(", "Builder", "$", "query", ")", "use", "(", "$", "widget", ",", "$", "column", ")", "{", "return", "$", "query", "->", "where", "(", "$", "column", ",", "$", "widget", ")", ";", "}", ")", ";", "}", ")", ";", "return", "$", "query", ";", "}" ]
Scope query with all the given widgets. @param \Illuminate\Database\Eloquent\Builder $query @param int|string|array|\ArrayAccess|WidgetModelContract $widgets @param string $column @return \Illuminate\Database\Eloquent\Builder
[ "Scope", "query", "with", "all", "the", "given", "widgets", "." ]
bc9357a1183a028f93f725b55b9db2867b7ec731
https://github.com/inetstudio/widgets/blob/bc9357a1183a028f93f725b55b9db2867b7ec731/src/Models/Traits/HasWidgets.php#L100-L112
train
inetstudio/widgets
src/Models/Traits/HasWidgets.php
HasWidgets.scopeWithoutWidgets
public function scopeWithoutWidgets(Builder $query, $widgets, string $column = 'id'): Builder { $widgets = static::isWidgetsStringBased($widgets) ? $widgets : static::hydrateWidgets($widgets)->pluck($column); return $query->whereDoesntHave('widgets', function (Builder $query) use ($widgets, $column) { $query->whereIn($column, (array) $widgets); }); }
php
public function scopeWithoutWidgets(Builder $query, $widgets, string $column = 'id'): Builder { $widgets = static::isWidgetsStringBased($widgets) ? $widgets : static::hydrateWidgets($widgets)->pluck($column); return $query->whereDoesntHave('widgets', function (Builder $query) use ($widgets, $column) { $query->whereIn($column, (array) $widgets); }); }
[ "public", "function", "scopeWithoutWidgets", "(", "Builder", "$", "query", ",", "$", "widgets", ",", "string", "$", "column", "=", "'id'", ")", ":", "Builder", "{", "$", "widgets", "=", "static", "::", "isWidgetsStringBased", "(", "$", "widgets", ")", "?", "$", "widgets", ":", "static", "::", "hydrateWidgets", "(", "$", "widgets", ")", "->", "pluck", "(", "$", "column", ")", ";", "return", "$", "query", "->", "whereDoesntHave", "(", "'widgets'", ",", "function", "(", "Builder", "$", "query", ")", "use", "(", "$", "widgets", ",", "$", "column", ")", "{", "$", "query", "->", "whereIn", "(", "$", "column", ",", "(", "array", ")", "$", "widgets", ")", ";", "}", ")", ";", "}" ]
Scope query without the given widgets. @param \Illuminate\Database\Eloquent\Builder $query @param int|string|array|\ArrayAccess|WidgetModelContract $widgets @param string $column @return \Illuminate\Database\Eloquent\Builder
[ "Scope", "query", "without", "the", "given", "widgets", "." ]
bc9357a1183a028f93f725b55b9db2867b7ec731
https://github.com/inetstudio/widgets/blob/bc9357a1183a028f93f725b55b9db2867b7ec731/src/Models/Traits/HasWidgets.php#L156-L164
train
inetstudio/widgets
src/Models/Traits/HasWidgets.php
HasWidgets.hasWidget
public function hasWidget($widgets): bool { // Single Widget id if (is_string($widgets)) { return $this->widgets->contains('id', $widgets); } // Single Widget id if (is_int($widgets)) { return $this->widgets->contains('id', $widgets); } // Single Widget model if ($widgets instanceof WidgetModelContract) { return $this->widgets->contains('id', $widgets->id); } // Array of Widget ids if (is_array($widgets) && isset($widgets[0]) && is_string($widgets[0])) { return ! $this->widgets->pluck('id')->intersect($widgets)->isEmpty(); } // Array of Widget ids if (is_array($widgets) && isset($widgets[0]) && is_int($widgets[0])) { return ! $this->widgets->pluck('id')->intersect($widgets)->isEmpty(); } // Collection of Widget models if ($widgets instanceof Collection) { return ! $widgets->intersect($this->widgets->pluck('id'))->isEmpty(); } return false; }
php
public function hasWidget($widgets): bool { // Single Widget id if (is_string($widgets)) { return $this->widgets->contains('id', $widgets); } // Single Widget id if (is_int($widgets)) { return $this->widgets->contains('id', $widgets); } // Single Widget model if ($widgets instanceof WidgetModelContract) { return $this->widgets->contains('id', $widgets->id); } // Array of Widget ids if (is_array($widgets) && isset($widgets[0]) && is_string($widgets[0])) { return ! $this->widgets->pluck('id')->intersect($widgets)->isEmpty(); } // Array of Widget ids if (is_array($widgets) && isset($widgets[0]) && is_int($widgets[0])) { return ! $this->widgets->pluck('id')->intersect($widgets)->isEmpty(); } // Collection of Widget models if ($widgets instanceof Collection) { return ! $widgets->intersect($this->widgets->pluck('id'))->isEmpty(); } return false; }
[ "public", "function", "hasWidget", "(", "$", "widgets", ")", ":", "bool", "{", "// Single Widget id", "if", "(", "is_string", "(", "$", "widgets", ")", ")", "{", "return", "$", "this", "->", "widgets", "->", "contains", "(", "'id'", ",", "$", "widgets", ")", ";", "}", "// Single Widget id", "if", "(", "is_int", "(", "$", "widgets", ")", ")", "{", "return", "$", "this", "->", "widgets", "->", "contains", "(", "'id'", ",", "$", "widgets", ")", ";", "}", "// Single Widget model", "if", "(", "$", "widgets", "instanceof", "WidgetModelContract", ")", "{", "return", "$", "this", "->", "widgets", "->", "contains", "(", "'id'", ",", "$", "widgets", "->", "id", ")", ";", "}", "// Array of Widget ids", "if", "(", "is_array", "(", "$", "widgets", ")", "&&", "isset", "(", "$", "widgets", "[", "0", "]", ")", "&&", "is_string", "(", "$", "widgets", "[", "0", "]", ")", ")", "{", "return", "!", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", "->", "intersect", "(", "$", "widgets", ")", "->", "isEmpty", "(", ")", ";", "}", "// Array of Widget ids", "if", "(", "is_array", "(", "$", "widgets", ")", "&&", "isset", "(", "$", "widgets", "[", "0", "]", ")", "&&", "is_int", "(", "$", "widgets", "[", "0", "]", ")", ")", "{", "return", "!", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", "->", "intersect", "(", "$", "widgets", ")", "->", "isEmpty", "(", ")", ";", "}", "// Collection of Widget models", "if", "(", "$", "widgets", "instanceof", "Collection", ")", "{", "return", "!", "$", "widgets", "->", "intersect", "(", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", ")", "->", "isEmpty", "(", ")", ";", "}", "return", "false", ";", "}" ]
Determine if the model has any the given widgets. @param int|string|array|\ArrayAccess|WidgetModelContract $widgets @return bool
[ "Determine", "if", "the", "model", "has", "any", "the", "given", "widgets", "." ]
bc9357a1183a028f93f725b55b9db2867b7ec731
https://github.com/inetstudio/widgets/blob/bc9357a1183a028f93f725b55b9db2867b7ec731/src/Models/Traits/HasWidgets.php#L227-L260
train
inetstudio/widgets
src/Models/Traits/HasWidgets.php
HasWidgets.hasAllWidgets
public function hasAllWidgets($widgets): bool { // Single widget id if (is_string($widgets)) { return $this->widgets->contains('id', $widgets); } // Single widget id if (is_int($widgets)) { return $this->widgets->contains('id', $widgets); } // Single widget model if ($widgets instanceof WidgetModelContract) { return $this->widgets->contains('id', $widgets->id); } // Array of widget ids if (is_array($widgets) && isset($widgets[0]) && is_string($widgets[0])) { return $this->widgets->pluck('id')->count() === count($widgets) && $this->widgets->pluck('id')->diff($widgets)->isEmpty(); } // Array of widget ids if (is_array($widgets) && isset($widgets[0]) && is_int($widgets[0])) { return $this->widgets->pluck('id')->count() === count($widgets) && $this->widgets->pluck('id')->diff($widgets)->isEmpty(); } // Collection of widget models if ($widgets instanceof Collection) { return $this->widgets->count() === $widgets->count() && $this->widgets->diff($widgets)->isEmpty(); } return false; }
php
public function hasAllWidgets($widgets): bool { // Single widget id if (is_string($widgets)) { return $this->widgets->contains('id', $widgets); } // Single widget id if (is_int($widgets)) { return $this->widgets->contains('id', $widgets); } // Single widget model if ($widgets instanceof WidgetModelContract) { return $this->widgets->contains('id', $widgets->id); } // Array of widget ids if (is_array($widgets) && isset($widgets[0]) && is_string($widgets[0])) { return $this->widgets->pluck('id')->count() === count($widgets) && $this->widgets->pluck('id')->diff($widgets)->isEmpty(); } // Array of widget ids if (is_array($widgets) && isset($widgets[0]) && is_int($widgets[0])) { return $this->widgets->pluck('id')->count() === count($widgets) && $this->widgets->pluck('id')->diff($widgets)->isEmpty(); } // Collection of widget models if ($widgets instanceof Collection) { return $this->widgets->count() === $widgets->count() && $this->widgets->diff($widgets)->isEmpty(); } return false; }
[ "public", "function", "hasAllWidgets", "(", "$", "widgets", ")", ":", "bool", "{", "// Single widget id", "if", "(", "is_string", "(", "$", "widgets", ")", ")", "{", "return", "$", "this", "->", "widgets", "->", "contains", "(", "'id'", ",", "$", "widgets", ")", ";", "}", "// Single widget id", "if", "(", "is_int", "(", "$", "widgets", ")", ")", "{", "return", "$", "this", "->", "widgets", "->", "contains", "(", "'id'", ",", "$", "widgets", ")", ";", "}", "// Single widget model", "if", "(", "$", "widgets", "instanceof", "WidgetModelContract", ")", "{", "return", "$", "this", "->", "widgets", "->", "contains", "(", "'id'", ",", "$", "widgets", "->", "id", ")", ";", "}", "// Array of widget ids", "if", "(", "is_array", "(", "$", "widgets", ")", "&&", "isset", "(", "$", "widgets", "[", "0", "]", ")", "&&", "is_string", "(", "$", "widgets", "[", "0", "]", ")", ")", "{", "return", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", "->", "count", "(", ")", "===", "count", "(", "$", "widgets", ")", "&&", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", "->", "diff", "(", "$", "widgets", ")", "->", "isEmpty", "(", ")", ";", "}", "// Array of widget ids", "if", "(", "is_array", "(", "$", "widgets", ")", "&&", "isset", "(", "$", "widgets", "[", "0", "]", ")", "&&", "is_int", "(", "$", "widgets", "[", "0", "]", ")", ")", "{", "return", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", "->", "count", "(", ")", "===", "count", "(", "$", "widgets", ")", "&&", "$", "this", "->", "widgets", "->", "pluck", "(", "'id'", ")", "->", "diff", "(", "$", "widgets", ")", "->", "isEmpty", "(", ")", ";", "}", "// Collection of widget models", "if", "(", "$", "widgets", "instanceof", "Collection", ")", "{", "return", "$", "this", "->", "widgets", "->", "count", "(", ")", "===", "$", "widgets", "->", "count", "(", ")", "&&", "$", "this", "->", "widgets", "->", "diff", "(", "$", "widgets", ")", "->", "isEmpty", "(", ")", ";", "}", "return", "false", ";", "}" ]
Determine if the model has all of the given widgets. @param int|string|array|\ArrayAccess|WidgetModelContract $widgets @return bool
[ "Determine", "if", "the", "model", "has", "all", "of", "the", "given", "widgets", "." ]
bc9357a1183a028f93f725b55b9db2867b7ec731
https://github.com/inetstudio/widgets/blob/bc9357a1183a028f93f725b55b9db2867b7ec731/src/Models/Traits/HasWidgets.php#L281-L316
train
inetstudio/widgets
src/Models/Traits/HasWidgets.php
HasWidgets.hydrateWidgets
protected function hydrateWidgets($widgets) { $isWidgetsStringBased = static::isWidgetsStringBased($widgets); $isWidgetsIntBased = static::isWidgetsIntBased($widgets); $field = $isWidgetsStringBased ? 'id' : 'id'; $className = static::getWidgetClassName(); return $isWidgetsStringBased || $isWidgetsIntBased ? $className::query()->whereIn($field, (array) $widgets)->get() : collect($widgets); }
php
protected function hydrateWidgets($widgets) { $isWidgetsStringBased = static::isWidgetsStringBased($widgets); $isWidgetsIntBased = static::isWidgetsIntBased($widgets); $field = $isWidgetsStringBased ? 'id' : 'id'; $className = static::getWidgetClassName(); return $isWidgetsStringBased || $isWidgetsIntBased ? $className::query()->whereIn($field, (array) $widgets)->get() : collect($widgets); }
[ "protected", "function", "hydrateWidgets", "(", "$", "widgets", ")", "{", "$", "isWidgetsStringBased", "=", "static", "::", "isWidgetsStringBased", "(", "$", "widgets", ")", ";", "$", "isWidgetsIntBased", "=", "static", "::", "isWidgetsIntBased", "(", "$", "widgets", ")", ";", "$", "field", "=", "$", "isWidgetsStringBased", "?", "'id'", ":", "'id'", ";", "$", "className", "=", "static", "::", "getWidgetClassName", "(", ")", ";", "return", "$", "isWidgetsStringBased", "||", "$", "isWidgetsIntBased", "?", "$", "className", "::", "query", "(", ")", "->", "whereIn", "(", "$", "field", ",", "(", "array", ")", "$", "widgets", ")", "->", "get", "(", ")", ":", "collect", "(", "$", "widgets", ")", ";", "}" ]
Hydrate widgets. @param int|string|array|\ArrayAccess|WidgetModelContract $widgets @return \Illuminate\Support\Collection
[ "Hydrate", "widgets", "." ]
bc9357a1183a028f93f725b55b9db2867b7ec731
https://github.com/inetstudio/widgets/blob/bc9357a1183a028f93f725b55b9db2867b7ec731/src/Models/Traits/HasWidgets.php#L351-L360
train
AndyDune/ConditionalExecution
src/CheckValue.php
CheckValue.isHaveValue
public function isHaveValue($checkValue) { $this->checkFunctions[] = function ($value) use ($checkValue) { if (!is_array($value)) { return false; } return in_array($checkValue, $value); }; return $this; }
php
public function isHaveValue($checkValue) { $this->checkFunctions[] = function ($value) use ($checkValue) { if (!is_array($value)) { return false; } return in_array($checkValue, $value); }; return $this; }
[ "public", "function", "isHaveValue", "(", "$", "checkValue", ")", "{", "$", "this", "->", "checkFunctions", "[", "]", "=", "function", "(", "$", "value", ")", "use", "(", "$", "checkValue", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "return", "in_array", "(", "$", "checkValue", ",", "$", "value", ")", ";", "}", ";", "return", "$", "this", ";", "}" ]
Use it if verifiable value is array For more correction @param $checkValue @return $this
[ "Use", "it", "if", "verifiable", "value", "is", "array", "For", "more", "correction" ]
c92c964bda607644ccc313edb2d59b288f7b7890
https://github.com/AndyDune/ConditionalExecution/blob/c92c964bda607644ccc313edb2d59b288f7b7890/src/CheckValue.php#L101-L110
train
sil-project/SeedBatchBundle
src/Entity/Certification.php
Certification.setPlot
public function setPlot(\Librinfo\SeedBatchBundle\Entity\Plot $plot = null) { $this->plot = $plot; return $this; }
php
public function setPlot(\Librinfo\SeedBatchBundle\Entity\Plot $plot = null) { $this->plot = $plot; return $this; }
[ "public", "function", "setPlot", "(", "\\", "Librinfo", "\\", "SeedBatchBundle", "\\", "Entity", "\\", "Plot", "$", "plot", "=", "null", ")", "{", "$", "this", "->", "plot", "=", "$", "plot", ";", "return", "$", "this", ";", "}" ]
Set plot. @param \Librinfo\SeedBatchBundle\Entity\Plot $plot @return Certification
[ "Set", "plot", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Certification.php#L245-L250
train
sil-project/SeedBatchBundle
src/Entity/Certification.php
Certification.setCertifyingBody
public function setCertifyingBody(\Librinfo\SeedBatchBundle\Entity\CertifyingBody $certifyingBody = null) { $this->certifyingBody = $certifyingBody; return $this; }
php
public function setCertifyingBody(\Librinfo\SeedBatchBundle\Entity\CertifyingBody $certifyingBody = null) { $this->certifyingBody = $certifyingBody; return $this; }
[ "public", "function", "setCertifyingBody", "(", "\\", "Librinfo", "\\", "SeedBatchBundle", "\\", "Entity", "\\", "CertifyingBody", "$", "certifyingBody", "=", "null", ")", "{", "$", "this", "->", "certifyingBody", "=", "$", "certifyingBody", ";", "return", "$", "this", ";", "}" ]
Set certifyingBody. @param \Librinfo\SeedBatchBundle\Entity\CertifyingBody $certifyingBody @return Certification
[ "Set", "certifyingBody", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Certification.php#L269-L274
train
zarathustra323/modlr-data
src/Zarathustra/ModlrData/Metadata/Cache/FileCache.php
FileCache.writeFile
protected function writeFile(EntityMetadata $metadata, $contents) { $file = $this->getCacheFile($metadata->type); $tmpFile = tempnam($this->dir, 'metadata-cache'); file_put_contents($tmpFile, $contents); chmod($tmpFile, 0666 & ~umask()); $this->renameFile($tmpFile, $file); }
php
protected function writeFile(EntityMetadata $metadata, $contents) { $file = $this->getCacheFile($metadata->type); $tmpFile = tempnam($this->dir, 'metadata-cache'); file_put_contents($tmpFile, $contents); chmod($tmpFile, 0666 & ~umask()); $this->renameFile($tmpFile, $file); }
[ "protected", "function", "writeFile", "(", "EntityMetadata", "$", "metadata", ",", "$", "contents", ")", "{", "$", "file", "=", "$", "this", "->", "getCacheFile", "(", "$", "metadata", "->", "type", ")", ";", "$", "tmpFile", "=", "tempnam", "(", "$", "this", "->", "dir", ",", "'metadata-cache'", ")", ";", "file_put_contents", "(", "$", "tmpFile", ",", "$", "contents", ")", ";", "chmod", "(", "$", "tmpFile", ",", "0666", "&", "~", "umask", "(", ")", ")", ";", "$", "this", "->", "renameFile", "(", "$", "tmpFile", ",", "$", "file", ")", ";", "}" ]
Writes the cache file. @param EntityMetadata $metadata @param string $contents
[ "Writes", "the", "cache", "file", "." ]
7c2c767216055f75abf8cf22e2200f11998ed24e
https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Cache/FileCache.php#L91-L98
train
zarathustra323/modlr-data
src/Zarathustra/ModlrData/Metadata/Cache/FileCache.php
FileCache.getCacheFile
private function getCacheFile($type) { $type = str_replace(EntityMetadata::NAMESPACE_DELIM, '_', $type); return $this->dir.'/ModlrData.'.$this->cachePrefix.'.'.$type.'.'.$this->extension; }
php
private function getCacheFile($type) { $type = str_replace(EntityMetadata::NAMESPACE_DELIM, '_', $type); return $this->dir.'/ModlrData.'.$this->cachePrefix.'.'.$type.'.'.$this->extension; }
[ "private", "function", "getCacheFile", "(", "$", "type", ")", "{", "$", "type", "=", "str_replace", "(", "EntityMetadata", "::", "NAMESPACE_DELIM", ",", "'_'", ",", "$", "type", ")", ";", "return", "$", "this", "->", "dir", ".", "'/ModlrData.'", ".", "$", "this", "->", "cachePrefix", ".", "'.'", ".", "$", "type", ".", "'.'", ".", "$", "this", "->", "extension", ";", "}" ]
Gets the cache file from the entity type. @param string $type @return string
[ "Gets", "the", "cache", "file", "from", "the", "entity", "type", "." ]
7c2c767216055f75abf8cf22e2200f11998ed24e
https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Cache/FileCache.php#L118-L122
train
zarathustra323/modlr-data
src/Zarathustra/ModlrData/Metadata/Cache/FileCache.php
FileCache.renameFile
private function renameFile($source, $target) { if (false === @rename($source, $target)) { throw new RuntimeException(sprintf('Could not write new cache file to %s.', $target)); } }
php
private function renameFile($source, $target) { if (false === @rename($source, $target)) { throw new RuntimeException(sprintf('Could not write new cache file to %s.', $target)); } }
[ "private", "function", "renameFile", "(", "$", "source", ",", "$", "target", ")", "{", "if", "(", "false", "===", "@", "rename", "(", "$", "source", ",", "$", "target", ")", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Could not write new cache file to %s.'", ",", "$", "target", ")", ")", ";", "}", "}" ]
Renames a file @param string $source @param string $target @throws \RuntimeException
[ "Renames", "a", "file" ]
7c2c767216055f75abf8cf22e2200f11998ed24e
https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/Cache/FileCache.php#L131-L136
train
netbull/CoreBundle
Command/JSRoutingCommand.php
JSRoutingCommand.doDump
private function doDump(OutputInterface $output) { if (!is_dir($dir = dirname($this->targetPath))) { $output->writeln('<info>[dir+]</info> ' . $dir); if (false === @mkdir($dir, 0777, true)) { throw new \RuntimeException('Unable to create directory ' . $dir); } } $output->writeln('<info>[file+]</info> ' . $this->targetPath); $templates = [ 'js' => "this.%s = route('%s');\n", 'es6' => "\t\t\t'%s': '%s',\n" ]; $type = $this->parameterBag->get('netbull_core.js_type'); $routes = ''; foreach ($this->extractor->getRoutes() as $name => $route) { preg_match_all("/{(.*?)}/i", $route->getPath(), $routeParams); if (0 < count($routeParams)) { $parameters = array_flip($routeParams[1]); $normalizedRoute = preg_replace_callback("/{(.*?)}/i", function($m) use($parameters) { return ':' . ($parameters[$m[1]] + 1); }, $route->getPath()); $routes .= sprintf($templates[$type], $name, $normalizedRoute); } } $source = file_get_contents(__DIR__ . '/../Resources/js/router.' . $type . '.js'); $content = str_replace('//<ROUTES>', $routes, $source); if (false === @file_put_contents($this->targetPath, $content)) { throw new \RuntimeException('Unable to write file ' . $this->targetPath); } }
php
private function doDump(OutputInterface $output) { if (!is_dir($dir = dirname($this->targetPath))) { $output->writeln('<info>[dir+]</info> ' . $dir); if (false === @mkdir($dir, 0777, true)) { throw new \RuntimeException('Unable to create directory ' . $dir); } } $output->writeln('<info>[file+]</info> ' . $this->targetPath); $templates = [ 'js' => "this.%s = route('%s');\n", 'es6' => "\t\t\t'%s': '%s',\n" ]; $type = $this->parameterBag->get('netbull_core.js_type'); $routes = ''; foreach ($this->extractor->getRoutes() as $name => $route) { preg_match_all("/{(.*?)}/i", $route->getPath(), $routeParams); if (0 < count($routeParams)) { $parameters = array_flip($routeParams[1]); $normalizedRoute = preg_replace_callback("/{(.*?)}/i", function($m) use($parameters) { return ':' . ($parameters[$m[1]] + 1); }, $route->getPath()); $routes .= sprintf($templates[$type], $name, $normalizedRoute); } } $source = file_get_contents(__DIR__ . '/../Resources/js/router.' . $type . '.js'); $content = str_replace('//<ROUTES>', $routes, $source); if (false === @file_put_contents($this->targetPath, $content)) { throw new \RuntimeException('Unable to write file ' . $this->targetPath); } }
[ "private", "function", "doDump", "(", "OutputInterface", "$", "output", ")", "{", "if", "(", "!", "is_dir", "(", "$", "dir", "=", "dirname", "(", "$", "this", "->", "targetPath", ")", ")", ")", "{", "$", "output", "->", "writeln", "(", "'<info>[dir+]</info> '", ".", "$", "dir", ")", ";", "if", "(", "false", "===", "@", "mkdir", "(", "$", "dir", ",", "0777", ",", "true", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to create directory '", ".", "$", "dir", ")", ";", "}", "}", "$", "output", "->", "writeln", "(", "'<info>[file+]</info> '", ".", "$", "this", "->", "targetPath", ")", ";", "$", "templates", "=", "[", "'js'", "=>", "\"this.%s = route('%s');\\n\"", ",", "'es6'", "=>", "\"\\t\\t\\t'%s': '%s',\\n\"", "]", ";", "$", "type", "=", "$", "this", "->", "parameterBag", "->", "get", "(", "'netbull_core.js_type'", ")", ";", "$", "routes", "=", "''", ";", "foreach", "(", "$", "this", "->", "extractor", "->", "getRoutes", "(", ")", "as", "$", "name", "=>", "$", "route", ")", "{", "preg_match_all", "(", "\"/{(.*?)}/i\"", ",", "$", "route", "->", "getPath", "(", ")", ",", "$", "routeParams", ")", ";", "if", "(", "0", "<", "count", "(", "$", "routeParams", ")", ")", "{", "$", "parameters", "=", "array_flip", "(", "$", "routeParams", "[", "1", "]", ")", ";", "$", "normalizedRoute", "=", "preg_replace_callback", "(", "\"/{(.*?)}/i\"", ",", "function", "(", "$", "m", ")", "use", "(", "$", "parameters", ")", "{", "return", "':'", ".", "(", "$", "parameters", "[", "$", "m", "[", "1", "]", "]", "+", "1", ")", ";", "}", ",", "$", "route", "->", "getPath", "(", ")", ")", ";", "$", "routes", ".=", "sprintf", "(", "$", "templates", "[", "$", "type", "]", ",", "$", "name", ",", "$", "normalizedRoute", ")", ";", "}", "}", "$", "source", "=", "file_get_contents", "(", "__DIR__", ".", "'/../Resources/js/router.'", ".", "$", "type", ".", "'.js'", ")", ";", "$", "content", "=", "str_replace", "(", "'//<ROUTES>'", ",", "$", "routes", ",", "$", "source", ")", ";", "if", "(", "false", "===", "@", "file_put_contents", "(", "$", "this", "->", "targetPath", ",", "$", "content", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to write file '", ".", "$", "this", "->", "targetPath", ")", ";", "}", "}" ]
Performs the routes dump. @param OutputInterface $output The command output
[ "Performs", "the", "routes", "dump", "." ]
0bacc1d9e4733b6da613027400c48421e5a14645
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Command/JSRoutingCommand.php#L101-L139
train
bseddon/XPath20
ExtFuncs.php
ExtFuncs.PrepareRegexFlags
private static function PrepareRegexFlags( $flagString ) { // The flag string can only contain s,m,i and/or x $result = preg_match( "/[^smix]+/", $flagString); if ( $result ) { throw XPath2Exception::withErrorCodeAndParam( "FORX0001", Resources::InvalidRegularExpr, "$flagString" ); } return $flagString; }
php
private static function PrepareRegexFlags( $flagString ) { // The flag string can only contain s,m,i and/or x $result = preg_match( "/[^smix]+/", $flagString); if ( $result ) { throw XPath2Exception::withErrorCodeAndParam( "FORX0001", Resources::InvalidRegularExpr, "$flagString" ); } return $flagString; }
[ "private", "static", "function", "PrepareRegexFlags", "(", "$", "flagString", ")", "{", "// The flag string can only contain s,m,i and/or x\r", "$", "result", "=", "preg_match", "(", "\"/[^smix]+/\"", ",", "$", "flagString", ")", ";", "if", "(", "$", "result", ")", "{", "throw", "XPath2Exception", "::", "withErrorCodeAndParam", "(", "\"FORX0001\"", ",", "Resources", "::", "InvalidRegularExpr", ",", "\"$flagString\"", ")", ";", "}", "return", "$", "flagString", ";", "}" ]
Check the flag string contents @param string $flagString @return string
[ "Check", "the", "flag", "string", "contents" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/ExtFuncs.php#L1314-L1324
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.names
final public static function names() { $result = []; $classes = self::hierarchy(\get_called_class()); /* @var $class ReflectionClass */ foreach ($classes as $class) { $result = \array_merge(self::namesFor($class->name), $result); } return $result; }
php
final public static function names() { $result = []; $classes = self::hierarchy(\get_called_class()); /* @var $class ReflectionClass */ foreach ($classes as $class) { $result = \array_merge(self::namesFor($class->name), $result); } return $result; }
[ "final", "public", "static", "function", "names", "(", ")", "{", "$", "result", "=", "[", "]", ";", "$", "classes", "=", "self", "::", "hierarchy", "(", "\\", "get_called_class", "(", ")", ")", ";", "/* @var $class ReflectionClass */", "foreach", "(", "$", "classes", "as", "$", "class", ")", "{", "$", "result", "=", "\\", "array_merge", "(", "self", "::", "namesFor", "(", "$", "class", "->", "name", ")", ",", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns an array containing the names of the enumeration constants of this enumeration type, in the order they are declared. This method may be used to iterate over the names of the enumerated constants as follows: /---code php foreach (ConcreteEnum::names() as $name) { echo $name, \PHP_EOL; } \--- @return string[] An array containing the names of the constants of this enumeration type, in the order they are declared.
[ "Returns", "an", "array", "containing", "the", "names", "of", "the", "enumeration", "constants", "of", "this", "enumeration", "type", "in", "the", "order", "they", "are", "declared", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L299-L310
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.namesFor
private static function namesFor($enumType) { $result = []; $methods = ReflectionUtils::methodsForClassWithoutInheritedMethods( $enumType, [ ReflectionMethod::IS_FINAL, ReflectionMethod::IS_STATIC, ReflectionMethod::IS_PUBLIC ] ); /* @var $method ReflectionMethod */ foreach ($methods as $method) { if ($method->name === \strtoupper($method->name)) { $result[] = $method->name; } } return $result; }
php
private static function namesFor($enumType) { $result = []; $methods = ReflectionUtils::methodsForClassWithoutInheritedMethods( $enumType, [ ReflectionMethod::IS_FINAL, ReflectionMethod::IS_STATIC, ReflectionMethod::IS_PUBLIC ] ); /* @var $method ReflectionMethod */ foreach ($methods as $method) { if ($method->name === \strtoupper($method->name)) { $result[] = $method->name; } } return $result; }
[ "private", "static", "function", "namesFor", "(", "$", "enumType", ")", "{", "$", "result", "=", "[", "]", ";", "$", "methods", "=", "ReflectionUtils", "::", "methodsForClassWithoutInheritedMethods", "(", "$", "enumType", ",", "[", "ReflectionMethod", "::", "IS_FINAL", ",", "ReflectionMethod", "::", "IS_STATIC", ",", "ReflectionMethod", "::", "IS_PUBLIC", "]", ")", ";", "/* @var $method ReflectionMethod */", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "$", "method", "->", "name", "===", "\\", "strtoupper", "(", "$", "method", "->", "name", ")", ")", "{", "$", "result", "[", "]", "=", "$", "method", "->", "name", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns an array containing the names of the enumeration constants of the specified enumeration type. The returned array does **not** contain enumeration constant names from the subclasses of the specified enumeration type. @param string $enumType The enumeration type @return string[] An array containing the names of the constants of this enumeration type, in the order they are declared.
[ "Returns", "an", "array", "containing", "the", "names", "of", "the", "enumeration", "constants", "of", "the", "specified", "enumeration", "type", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L340-L361
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.values
final public static function values() { $names = self::names(); $result = []; foreach ($names as $name) { $result[] = static::$name(); } return $result; }
php
final public static function values() { $names = self::names(); $result = []; foreach ($names as $name) { $result[] = static::$name(); } return $result; }
[ "final", "public", "static", "function", "values", "(", ")", "{", "$", "names", "=", "self", "::", "names", "(", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "names", "as", "$", "name", ")", "{", "$", "result", "[", "]", "=", "static", "::", "$", "name", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns an array containing the enumeration constants of this enumeration type, in the order they are declared. This method may be used to iterate over the enumeration constants as follows: /---code php foreach (ConcreteEnum::values() as $constant) { // Same as "echo $constant->__toString(), \PHP_EOL"; echo $constant, \PHP_EOL; } \--- @return EnumAbstract[] An array containing the enumeration constants of this enumeration type, in the order they are declared.
[ "Returns", "an", "array", "containing", "the", "enumeration", "constants", "of", "this", "enumeration", "type", "in", "the", "order", "they", "are", "declared", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L381-L391
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.valueOf
final public static function valueOf($name) { $result = null; try { /* @var $constant EnumAbstract */ foreach (self::values() as $constant) { if ($constant->name === $name) { $result = $constant; break; } } } catch (InvalidArgumentException $ex) { // Empty block. } return $result; }
php
final public static function valueOf($name) { $result = null; try { /* @var $constant EnumAbstract */ foreach (self::values() as $constant) { if ($constant->name === $name) { $result = $constant; break; } } } catch (InvalidArgumentException $ex) { // Empty block. } return $result; }
[ "final", "public", "static", "function", "valueOf", "(", "$", "name", ")", "{", "$", "result", "=", "null", ";", "try", "{", "/* @var $constant EnumAbstract */", "foreach", "(", "self", "::", "values", "(", ")", "as", "$", "constant", ")", "{", "if", "(", "$", "constant", "->", "name", "===", "$", "name", ")", "{", "$", "result", "=", "$", "constant", ";", "break", ";", "}", "}", "}", "catch", "(", "InvalidArgumentException", "$", "ex", ")", "{", "// Empty block.", "}", "return", "$", "result", ";", "}" ]
Returns the enumeration constant with the specified name from this enumeration type. The string must match exactly an identifier used to declare an enumeration constant in this enumeration type. (Extraneous whitespace characters are not permitted.) @param string $name The name of the enumeration constant to return. @return EnumAbstract|null The enumeration constant with the specified name on success; `null` on failure.
[ "Returns", "the", "enumeration", "constant", "with", "the", "specified", "name", "from", "this", "enumeration", "type", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L406-L423
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.getInstance
final protected static function getInstance() { $backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); $className = self::retrieveNameOfSuperclassFor( $backtrace[1]['class'] ); $constantName = $backtrace[1]['function']; $constantOrdinal = self::retrieveOrdinalFor($constantName); $constructorArguments = \func_get_args(); return $className::getMultitonInstance( $constantName, $constantOrdinal, $constructorArguments ); }
php
final protected static function getInstance() { $backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS); $className = self::retrieveNameOfSuperclassFor( $backtrace[1]['class'] ); $constantName = $backtrace[1]['function']; $constantOrdinal = self::retrieveOrdinalFor($constantName); $constructorArguments = \func_get_args(); return $className::getMultitonInstance( $constantName, $constantOrdinal, $constructorArguments ); }
[ "final", "protected", "static", "function", "getInstance", "(", ")", "{", "$", "backtrace", "=", "\\", "debug_backtrace", "(", "\\", "DEBUG_BACKTRACE_IGNORE_ARGS", ")", ";", "$", "className", "=", "self", "::", "retrieveNameOfSuperclassFor", "(", "$", "backtrace", "[", "1", "]", "[", "'class'", "]", ")", ";", "$", "constantName", "=", "$", "backtrace", "[", "1", "]", "[", "'function'", "]", ";", "$", "constantOrdinal", "=", "self", "::", "retrieveOrdinalFor", "(", "$", "constantName", ")", ";", "$", "constructorArguments", "=", "\\", "func_get_args", "(", ")", ";", "return", "$", "className", "::", "getMultitonInstance", "(", "$", "constantName", ",", "$", "constantOrdinal", ",", "$", "constructorArguments", ")", ";", "}" ]
Creates and returns an enumeration constant for the specified enumeration type with the specified name. This method implements the *Lazy Load* implementation pattern. Use this method as follows in a subclass of this class: /---code php final class ConcreteEnum extends FlorianWolters\Component\Core\Enum\EnumAbstract { /** @return ConcreteEnum {@*} final public static function CONSTANT() { return self::getInstance(); } } \--- @return EnumAbstract The enumeration constant of the specified enumeration type with the specified name. @throws InvalidArgumentException If the specified enumeration type has no enumeration constant with the specified name, or the specified class name does not represent an enumeration type.
[ "Creates", "and", "returns", "an", "enumeration", "constant", "for", "the", "specified", "enumeration", "type", "with", "the", "specified", "name", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L452-L467
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.retrieveNameOfSuperclassFor
private static function retrieveNameOfSuperclassFor($className) { $parents = self::hierarchy($className); return (true === empty($parents)) ? $className : $parents[count($parents) - 1]->name; }
php
private static function retrieveNameOfSuperclassFor($className) { $parents = self::hierarchy($className); return (true === empty($parents)) ? $className : $parents[count($parents) - 1]->name; }
[ "private", "static", "function", "retrieveNameOfSuperclassFor", "(", "$", "className", ")", "{", "$", "parents", "=", "self", "::", "hierarchy", "(", "$", "className", ")", ";", "return", "(", "true", "===", "empty", "(", "$", "parents", ")", ")", "?", "$", "className", ":", "$", "parents", "[", "count", "(", "$", "parents", ")", "-", "1", "]", "->", "name", ";", "}" ]
Returns the superclass name for the specified classname. @param string $className The name of the class, which superclass name to return. @return string The name of the superclass.
[ "Returns", "the", "superclass", "name", "for", "the", "specified", "classname", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L477-L484
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.retrieveOrdinalFor
private static function retrieveOrdinalFor($name) { $result = null; foreach (self::names() as $key => $value) { if ($name === $value) { $result = $key; break; } } return $result; }
php
private static function retrieveOrdinalFor($name) { $result = null; foreach (self::names() as $key => $value) { if ($name === $value) { $result = $key; break; } } return $result; }
[ "private", "static", "function", "retrieveOrdinalFor", "(", "$", "name", ")", "{", "$", "result", "=", "null", ";", "foreach", "(", "self", "::", "names", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "name", "===", "$", "value", ")", "{", "$", "result", "=", "$", "key", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns the ordinal of the enumeration constant with the specified name in this enumeration type. @param string $name The name of the enumeration constant, which is the identifier used to declare it. @return integer The ordinal of the enumeration constant (its position in the enumeration declaration, where the initial enumeration constant is assigned an ordinal of zero).
[ "Returns", "the", "ordinal", "of", "the", "enumeration", "constant", "with", "the", "specified", "name", "in", "this", "enumeration", "type", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L497-L509
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.invokeConstructorIfDeclared
private function invokeConstructorIfDeclared(array $arguments) { $methodName = 'construct'; try { $method = new ReflectionMethod($this, $methodName); if (true === $method->isPublic()) { throw new RuntimeException( 'The constructor of an enumeration type may not be public.' ); } $method->setAccessible(true); $method->invokeArgs($this, $arguments); } catch (ReflectionException $ex) { // empty block. } }
php
private function invokeConstructorIfDeclared(array $arguments) { $methodName = 'construct'; try { $method = new ReflectionMethod($this, $methodName); if (true === $method->isPublic()) { throw new RuntimeException( 'The constructor of an enumeration type may not be public.' ); } $method->setAccessible(true); $method->invokeArgs($this, $arguments); } catch (ReflectionException $ex) { // empty block. } }
[ "private", "function", "invokeConstructorIfDeclared", "(", "array", "$", "arguments", ")", "{", "$", "methodName", "=", "'construct'", ";", "try", "{", "$", "method", "=", "new", "ReflectionMethod", "(", "$", "this", ",", "$", "methodName", ")", ";", "if", "(", "true", "===", "$", "method", "->", "isPublic", "(", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The constructor of an enumeration type may not be public.'", ")", ";", "}", "$", "method", "->", "setAccessible", "(", "true", ")", ";", "$", "method", "->", "invokeArgs", "(", "$", "this", ",", "$", "arguments", ")", ";", "}", "catch", "(", "ReflectionException", "$", "ex", ")", "{", "// empty block.", "}", "}" ]
Invokes the constructor of this enumeration constant with the specified arguments. @param mixed[] $arguments The constructor arguments. @return void
[ "Invokes", "the", "constructor", "of", "this", "enumeration", "constant", "with", "the", "specified", "arguments", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L539-L557
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php
EnumAbstract.compareTo
final public function compareTo(ComparableInterface $other) { if (false === ($other instanceof self)) { throw new ClassCastException( 'The specified object\'s type is not an instance of ' . __CLASS__ . '.' ); } if (false === ($this instanceof $other)) { throw new ClassCastException( 'The specified object\'s type is not an instance of ' . \get_class($this) . '.' ); } return ($this->ordinal - $other->ordinal); }
php
final public function compareTo(ComparableInterface $other) { if (false === ($other instanceof self)) { throw new ClassCastException( 'The specified object\'s type is not an instance of ' . __CLASS__ . '.' ); } if (false === ($this instanceof $other)) { throw new ClassCastException( 'The specified object\'s type is not an instance of ' . \get_class($this) . '.' ); } return ($this->ordinal - $other->ordinal); }
[ "final", "public", "function", "compareTo", "(", "ComparableInterface", "$", "other", ")", "{", "if", "(", "false", "===", "(", "$", "other", "instanceof", "self", ")", ")", "{", "throw", "new", "ClassCastException", "(", "'The specified object\\'s type is not an instance of '", ".", "__CLASS__", ".", "'.'", ")", ";", "}", "if", "(", "false", "===", "(", "$", "this", "instanceof", "$", "other", ")", ")", "{", "throw", "new", "ClassCastException", "(", "'The specified object\\'s type is not an instance of '", ".", "\\", "get_class", "(", "$", "this", ")", ".", "'.'", ")", ";", "}", "return", "(", "$", "this", "->", "ordinal", "-", "$", "other", "->", "ordinal", ")", ";", "}" ]
Compares this enumeration constant with the specified enumeration constant for order. Enumeration constants are only comparable to other enumeration constants of the same enumeration type. The natural order implemented by this method is the order in which the enumeration constants are declared. @param ComparableInterface $other The other enumeration constant to compare this enumeration constant to. @return integer A negative integer, zero, or a positive integer as this enumeration constant is less than, equal to, or greater than the specified enumeration constant. @throws ClassCastException If `$other` is not an enumeration type. @throws ClassCastException If `$other` is not an enumeration constant of the same enumeration type.
[ "Compares", "this", "enumeration", "constant", "with", "the", "specified", "enumeration", "constant", "for", "order", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumAbstract.php#L648-L665
train
staticka/staticka
src/Layout.php
Layout.render
public function render($name, $content) { list($data, $content) = (array) Matter::parse($content); $data = array_merge($data, (array) $this->data); $data['title'] = isset($data['title']) ? $data['title'] : ''; $output = $this->website->content()->make($content); if ($data['title'] === '') { preg_match('/<h1>(.*?)<\/h1>/', $output, $matches); isset($matches[1]) && $data['title'] = $matches[1]; } $data['content'] = (string) $output; return $this->renderer->render($name, $data); }
php
public function render($name, $content) { list($data, $content) = (array) Matter::parse($content); $data = array_merge($data, (array) $this->data); $data['title'] = isset($data['title']) ? $data['title'] : ''; $output = $this->website->content()->make($content); if ($data['title'] === '') { preg_match('/<h1>(.*?)<\/h1>/', $output, $matches); isset($matches[1]) && $data['title'] = $matches[1]; } $data['content'] = (string) $output; return $this->renderer->render($name, $data); }
[ "public", "function", "render", "(", "$", "name", ",", "$", "content", ")", "{", "list", "(", "$", "data", ",", "$", "content", ")", "=", "(", "array", ")", "Matter", "::", "parse", "(", "$", "content", ")", ";", "$", "data", "=", "array_merge", "(", "$", "data", ",", "(", "array", ")", "$", "this", "->", "data", ")", ";", "$", "data", "[", "'title'", "]", "=", "isset", "(", "$", "data", "[", "'title'", "]", ")", "?", "$", "data", "[", "'title'", "]", ":", "''", ";", "$", "output", "=", "$", "this", "->", "website", "->", "content", "(", ")", "->", "make", "(", "$", "content", ")", ";", "if", "(", "$", "data", "[", "'title'", "]", "===", "''", ")", "{", "preg_match", "(", "'/<h1>(.*?)<\\/h1>/'", ",", "$", "output", ",", "$", "matches", ")", ";", "isset", "(", "$", "matches", "[", "1", "]", ")", "&&", "$", "data", "[", "'title'", "]", "=", "$", "matches", "[", "1", "]", ";", "}", "$", "data", "[", "'content'", "]", "=", "(", "string", ")", "$", "output", ";", "return", "$", "this", "->", "renderer", "->", "render", "(", "$", "name", ",", "$", "data", ")", ";", "}" ]
Renders the specified HTML content with a template. @param string $name @param string $content @return string
[ "Renders", "the", "specified", "HTML", "content", "with", "a", "template", "." ]
6e3b814c391ed03b0bd409803e11579bae677ce4
https://github.com/staticka/staticka/blob/6e3b814c391ed03b0bd409803e11579bae677ce4/src/Layout.php#L56-L75
train
aztech-digital/phinject
src/DefaultReferenceResolver.php
DefaultReferenceResolver.resolve
public function resolve($reference) { if (empty($reference)) { return $reference; } if ($this->isResolvableAnonymousReference($reference)) { return $this->resolveAnonymousReference($reference); } return $this->resolveInternal($reference); }
php
public function resolve($reference) { if (empty($reference)) { return $reference; } if ($this->isResolvableAnonymousReference($reference)) { return $this->resolveAnonymousReference($reference); } return $this->resolveInternal($reference); }
[ "public", "function", "resolve", "(", "$", "reference", ")", "{", "if", "(", "empty", "(", "$", "reference", ")", ")", "{", "return", "$", "reference", ";", "}", "if", "(", "$", "this", "->", "isResolvableAnonymousReference", "(", "$", "reference", ")", ")", "{", "return", "$", "this", "->", "resolveAnonymousReference", "(", "$", "reference", ")", ";", "}", "return", "$", "this", "->", "resolveInternal", "(", "$", "reference", ")", ";", "}" ]
Return the resolved value of the given reference. @param mixed $reference @return mixed
[ "Return", "the", "resolved", "value", "of", "the", "given", "reference", "." ]
1bb2fb3b5ef44e62f168af71134c613c48b58d95
https://github.com/aztech-digital/phinject/blob/1bb2fb3b5ef44e62f168af71134c613c48b58d95/src/DefaultReferenceResolver.php#L81-L92
train
aztech-digital/phinject
src/DefaultReferenceResolver.php
DefaultReferenceResolver.resolveMany
public function resolveMany(array $references) { $convertedParameters = array(); foreach ($references as $reference) { $convertedValue = $this->resolve($reference); $convertedParameters[] = $convertedValue; } return $convertedParameters; }
php
public function resolveMany(array $references) { $convertedParameters = array(); foreach ($references as $reference) { $convertedValue = $this->resolve($reference); $convertedParameters[] = $convertedValue; } return $convertedParameters; }
[ "public", "function", "resolveMany", "(", "array", "$", "references", ")", "{", "$", "convertedParameters", "=", "array", "(", ")", ";", "foreach", "(", "$", "references", "as", "$", "reference", ")", "{", "$", "convertedValue", "=", "$", "this", "->", "resolve", "(", "$", "reference", ")", ";", "$", "convertedParameters", "[", "]", "=", "$", "convertedValue", ";", "}", "return", "$", "convertedParameters", ";", "}" ]
Resolves an array of references @param array $references @return mixed
[ "Resolves", "an", "array", "of", "references" ]
1bb2fb3b5ef44e62f168af71134c613c48b58d95
https://github.com/aztech-digital/phinject/blob/1bb2fb3b5ef44e62f168af71134c613c48b58d95/src/DefaultReferenceResolver.php#L134-L144
train
SergioMadness/pwf-helpers
src/SystemHelpers.php
SystemHelpers.call
public static function call($function, \Closure $callback = null) { $result = null; if (is_array($function)) { $result = self::methodDI($function, $callback); } elseif (is_callable($function, true)) { $result = self::functionDI($function, $callback); } return $result; }
php
public static function call($function, \Closure $callback = null) { $result = null; if (is_array($function)) { $result = self::methodDI($function, $callback); } elseif (is_callable($function, true)) { $result = self::functionDI($function, $callback); } return $result; }
[ "public", "static", "function", "call", "(", "$", "function", ",", "\\", "Closure", "$", "callback", "=", "null", ")", "{", "$", "result", "=", "null", ";", "if", "(", "is_array", "(", "$", "function", ")", ")", "{", "$", "result", "=", "self", "::", "methodDI", "(", "$", "function", ",", "$", "callback", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "function", ",", "true", ")", ")", "{", "$", "result", "=", "self", "::", "functionDI", "(", "$", "function", ",", "$", "callback", ")", ";", "}", "return", "$", "result", ";", "}" ]
Call function with dependency injection @param mixed $function @param \Closure $callback @return mixed
[ "Call", "function", "with", "dependency", "injection" ]
d6cd44807c120356d60618cb08f237841c35e293
https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/SystemHelpers.php#L15-L24
train
SergioMadness/pwf-helpers
src/SystemHelpers.php
SystemHelpers.functionDI
public static function functionDI(\Closure $function, \Closure $callback = null) { $reflection = new \ReflectionFunction($function); $functionParams = $reflection->getParameters(); $inputParams = []; if ($callback !== null) { foreach ($functionParams as $functionParam) { $param = $callback($functionParam->name); if (!empty($param)) { $inputParams[] = $param; } } } return call_user_func_array($function, $inputParams); }
php
public static function functionDI(\Closure $function, \Closure $callback = null) { $reflection = new \ReflectionFunction($function); $functionParams = $reflection->getParameters(); $inputParams = []; if ($callback !== null) { foreach ($functionParams as $functionParam) { $param = $callback($functionParam->name); if (!empty($param)) { $inputParams[] = $param; } } } return call_user_func_array($function, $inputParams); }
[ "public", "static", "function", "functionDI", "(", "\\", "Closure", "$", "function", ",", "\\", "Closure", "$", "callback", "=", "null", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionFunction", "(", "$", "function", ")", ";", "$", "functionParams", "=", "$", "reflection", "->", "getParameters", "(", ")", ";", "$", "inputParams", "=", "[", "]", ";", "if", "(", "$", "callback", "!==", "null", ")", "{", "foreach", "(", "$", "functionParams", "as", "$", "functionParam", ")", "{", "$", "param", "=", "$", "callback", "(", "$", "functionParam", "->", "name", ")", ";", "if", "(", "!", "empty", "(", "$", "param", ")", ")", "{", "$", "inputParams", "[", "]", "=", "$", "param", ";", "}", "}", "}", "return", "call_user_func_array", "(", "$", "function", ",", "$", "inputParams", ")", ";", "}" ]
Call closure with dependency injection @param \Closure $function @param \Closure $callback @return mixed
[ "Call", "closure", "with", "dependency", "injection" ]
d6cd44807c120356d60618cb08f237841c35e293
https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/SystemHelpers.php#L33-L48
train
SergioMadness/pwf-helpers
src/SystemHelpers.php
SystemHelpers.methodDI
public static function methodDI(array $objectInfo, \Closure $callback = null) { $reflection = new \ReflectionObject($objectInfo[0]); $methods = $reflection->getMethods(); $inputParams = []; $functionParams = []; foreach ($methods as $method) { if ($objectInfo[1] == $method->name) { $functionParams = $method->getParameters(); break; } } foreach ($functionParams as $functionParam) { $param = $callback($functionParam->name); if (!empty($param)) { $inputParams[] = $param; } } return call_user_func_array($objectInfo, $inputParams); }
php
public static function methodDI(array $objectInfo, \Closure $callback = null) { $reflection = new \ReflectionObject($objectInfo[0]); $methods = $reflection->getMethods(); $inputParams = []; $functionParams = []; foreach ($methods as $method) { if ($objectInfo[1] == $method->name) { $functionParams = $method->getParameters(); break; } } foreach ($functionParams as $functionParam) { $param = $callback($functionParam->name); if (!empty($param)) { $inputParams[] = $param; } } return call_user_func_array($objectInfo, $inputParams); }
[ "public", "static", "function", "methodDI", "(", "array", "$", "objectInfo", ",", "\\", "Closure", "$", "callback", "=", "null", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionObject", "(", "$", "objectInfo", "[", "0", "]", ")", ";", "$", "methods", "=", "$", "reflection", "->", "getMethods", "(", ")", ";", "$", "inputParams", "=", "[", "]", ";", "$", "functionParams", "=", "[", "]", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "$", "objectInfo", "[", "1", "]", "==", "$", "method", "->", "name", ")", "{", "$", "functionParams", "=", "$", "method", "->", "getParameters", "(", ")", ";", "break", ";", "}", "}", "foreach", "(", "$", "functionParams", "as", "$", "functionParam", ")", "{", "$", "param", "=", "$", "callback", "(", "$", "functionParam", "->", "name", ")", ";", "if", "(", "!", "empty", "(", "$", "param", ")", ")", "{", "$", "inputParams", "[", "]", "=", "$", "param", ";", "}", "}", "return", "call_user_func_array", "(", "$", "objectInfo", ",", "$", "inputParams", ")", ";", "}" ]
Call method with dependency injection @param array $objectInfo @param \Closure $callback @return mixed
[ "Call", "method", "with", "dependency", "injection" ]
d6cd44807c120356d60618cb08f237841c35e293
https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/SystemHelpers.php#L57-L76
train
SergioMadness/pwf-helpers
src/SystemHelpers.php
SystemHelpers.createObject
public static function createObject($className, array $params = []) { $result = new $className; foreach ($params as $key => $val) { $methodName = 'set'.ucfirst($key); if (method_exists($result, $methodName)) { $result->$methodName($val); } } return $result; }
php
public static function createObject($className, array $params = []) { $result = new $className; foreach ($params as $key => $val) { $methodName = 'set'.ucfirst($key); if (method_exists($result, $methodName)) { $result->$methodName($val); } } return $result; }
[ "public", "static", "function", "createObject", "(", "$", "className", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "result", "=", "new", "$", "className", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "methodName", "=", "'set'", ".", "ucfirst", "(", "$", "key", ")", ";", "if", "(", "method_exists", "(", "$", "result", ",", "$", "methodName", ")", ")", "{", "$", "result", "->", "$", "methodName", "(", "$", "val", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Create object and set params @param string $className @param array $params @return \pwf\helpers\className
[ "Create", "object", "and", "set", "params" ]
d6cd44807c120356d60618cb08f237841c35e293
https://github.com/SergioMadness/pwf-helpers/blob/d6cd44807c120356d60618cb08f237841c35e293/src/SystemHelpers.php#L99-L109
train
Wedeto/HTTP
src/Result.php
Result.setHeader
public function setHeader(string $header, $value) { if (!is_scalar($value)) throw new \InvalidArgumentException("Value should be a scalar"); $header = static::normalizeHeader($header); $this->headers[$header] = $value; return $this; }
php
public function setHeader(string $header, $value) { if (!is_scalar($value)) throw new \InvalidArgumentException("Value should be a scalar"); $header = static::normalizeHeader($header); $this->headers[$header] = $value; return $this; }
[ "public", "function", "setHeader", "(", "string", "$", "header", ",", "$", "value", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "value", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Value should be a scalar\"", ")", ";", "$", "header", "=", "static", "::", "normalizeHeader", "(", "$", "header", ")", ";", "$", "this", "->", "headers", "[", "$", "header", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set a header on the result @param string $header The name of the header. Will be normalized @param scalar $value The value for the header. @return $this Provides fluent interface
[ "Set", "a", "header", "on", "the", "result" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Result.php#L51-L59
train
Wedeto/HTTP
src/Result.php
Result.unsetHeader
public function unsetHeader(string $header) { $header = static::normalizeHeader($header); unset($this->headers[$header]); return $this; }
php
public function unsetHeader(string $header) { $header = static::normalizeHeader($header); unset($this->headers[$header]); return $this; }
[ "public", "function", "unsetHeader", "(", "string", "$", "header", ")", "{", "$", "header", "=", "static", "::", "normalizeHeader", "(", "$", "header", ")", ";", "unset", "(", "$", "this", "->", "headers", "[", "$", "header", "]", ")", ";", "return", "$", "this", ";", "}" ]
Remove a header from the list of headers to send to the client @param string $header The header to unset. @return $this Provides fluent interface
[ "Remove", "a", "header", "from", "the", "list", "of", "headers", "to", "send", "to", "the", "client" ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Result.php#L67-L72
train
Wedeto/HTTP
src/Result.php
Result.getCachePolicy
public function getCachePolicy() { if (!empty($this->response)) { $policy = $this->response->getCachePolicy(); if (!empty($policy)) return $policy; } return $this->cache_policy; }
php
public function getCachePolicy() { if (!empty($this->response)) { $policy = $this->response->getCachePolicy(); if (!empty($policy)) return $policy; } return $this->cache_policy; }
[ "public", "function", "getCachePolicy", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "response", ")", ")", "{", "$", "policy", "=", "$", "this", "->", "response", "->", "getCachePolicy", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "policy", ")", ")", "return", "$", "policy", ";", "}", "return", "$", "this", "->", "cache_policy", ";", "}" ]
Returns the cache policy for this result. If the response has a cache policy, it is used. Otherwise, any cache policy set on the result itself is used. @return CachePolicy The cache policy
[ "Returns", "the", "cache", "policy", "for", "this", "result", ".", "If", "the", "response", "has", "a", "cache", "policy", "it", "is", "used", ".", "Otherwise", "any", "cache", "policy", "set", "on", "the", "result", "itself", "is", "used", "." ]
7318eff1b81a3c103c4263466d09b7f3593b70b9
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Result.php#L215-L224
train
asaokamei/ScoreSql
src/Sql/Where.php
Where.set
public function set( $where, $andOr=null ) { if( $where instanceof Where ) { if( $where->countCriteria() > 1 ) { $where->parenthesis(); } $where->setParent( $this ); return $this->where( '', false, $where, $andOr ); } return $this->where( '', false, Sql::raw($where), $andOr ); }
php
public function set( $where, $andOr=null ) { if( $where instanceof Where ) { if( $where->countCriteria() > 1 ) { $where->parenthesis(); } $where->setParent( $this ); return $this->where( '', false, $where, $andOr ); } return $this->where( '', false, Sql::raw($where), $andOr ); }
[ "public", "function", "set", "(", "$", "where", ",", "$", "andOr", "=", "null", ")", "{", "if", "(", "$", "where", "instanceof", "Where", ")", "{", "if", "(", "$", "where", "->", "countCriteria", "(", ")", ">", "1", ")", "{", "$", "where", "->", "parenthesis", "(", ")", ";", "}", "$", "where", "->", "setParent", "(", "$", "this", ")", ";", "return", "$", "this", "->", "where", "(", "''", ",", "false", ",", "$", "where", ",", "$", "andOr", ")", ";", "}", "return", "$", "this", "->", "where", "(", "''", ",", "false", ",", "Sql", "::", "raw", "(", "$", "where", ")", ",", "$", "andOr", ")", ";", "}" ]
set the where string as is. @param Where $where @param null|string $andOr @return Where
[ "set", "the", "where", "string", "as", "is", "." ]
f1fce28476629e98b3c4c1216859c7f5309de7a1
https://github.com/asaokamei/ScoreSql/blob/f1fce28476629e98b3c4c1216859c7f5309de7a1/src/Sql/Where.php#L308-L318
train
squareproton/Bond
lib/php-ref/ref.php
ref.timeFunc
public static function timeFunc($iterations, $function, &$output = null){ $time = 0; for($i = 0; $i < $iterations; $i++){ $start = microtime(true); $output = call_user_func($function); $time += microtime(true) - $start; } return round($time, 4); }
php
public static function timeFunc($iterations, $function, &$output = null){ $time = 0; for($i = 0; $i < $iterations; $i++){ $start = microtime(true); $output = call_user_func($function); $time += microtime(true) - $start; } return round($time, 4); }
[ "public", "static", "function", "timeFunc", "(", "$", "iterations", ",", "$", "function", ",", "&", "$", "output", "=", "null", ")", "{", "$", "time", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "iterations", ";", "$", "i", "++", ")", "{", "$", "start", "=", "microtime", "(", "true", ")", ";", "$", "output", "=", "call_user_func", "(", "$", "function", ")", ";", "$", "time", "+=", "microtime", "(", "true", ")", "-", "$", "start", ";", "}", "return", "round", "(", "$", "time", ",", "4", ")", ";", "}" ]
Executes a function the given number of times and returns the elapsed time. Keep in mind that the returned time includes function call overhead (including microtime calls) x iteration count. This is why this is better suited for determining which of two or more functions is the fastest, rather than finding out how fast is a single function. @param int $iterations Number of times the function will be executed @param callable $function Function to execute @param mixed &$output If given, last return value will be available in this variable @return double Elapsed time
[ "Executes", "a", "function", "the", "given", "number", "of", "times", "and", "returns", "the", "elapsed", "time", "." ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/lib/php-ref/ref.php#L277-L288
train
squareproton/Bond
lib/php-ref/ref.php
ref.config
public static function config($key, $value = null){ if(!array_key_exists($key, static::$config)) throw new \Exception(sprintf('Unrecognized option: "%s". Valid options are: %s', $key, implode(', ', array_keys(static::$config)))); if($value === null) return static::$config[$key]; if(is_array(static::$config[$key])) return static::$config[$key] = (array)$value; return static::$config[$key] = $value; }
php
public static function config($key, $value = null){ if(!array_key_exists($key, static::$config)) throw new \Exception(sprintf('Unrecognized option: "%s". Valid options are: %s', $key, implode(', ', array_keys(static::$config)))); if($value === null) return static::$config[$key]; if(is_array(static::$config[$key])) return static::$config[$key] = (array)$value; return static::$config[$key] = $value; }
[ "public", "static", "function", "config", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "static", "::", "$", "config", ")", ")", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Unrecognized option: \"%s\". Valid options are: %s'", ",", "$", "key", ",", "implode", "(", "', '", ",", "array_keys", "(", "static", "::", "$", "config", ")", ")", ")", ")", ";", "if", "(", "$", "value", "===", "null", ")", "return", "static", "::", "$", "config", "[", "$", "key", "]", ";", "if", "(", "is_array", "(", "static", "::", "$", "config", "[", "$", "key", "]", ")", ")", "return", "static", "::", "$", "config", "[", "$", "key", "]", "=", "(", "array", ")", "$", "value", ";", "return", "static", "::", "$", "config", "[", "$", "key", "]", "=", "$", "value", ";", "}" ]
Set or get configuration options @param string $key @param mixed|null $value @return mixed
[ "Set", "or", "get", "configuration", "options" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/lib/php-ref/ref.php#L713-L725
train
squareproton/Bond
lib/php-ref/ref.php
ref.linkify
protected function linkify(\Reflector $reflector, $constant = null){ static $docRefRoot = null, $docRefExt = null; // most people don't have this set if(!$docRefRoot) $docRefRoot = ($docRefRoot = rtrim(ini_get('docref_root'), '/')) ? $docRefRoot : 'http://php.net/manual/en'; if(!$docRefExt) $docRefExt = ($docRefExt = ini_get('docref_ext')) ? $docRefExt : '.php'; $phpNetSchemes = array( 'class' => $docRefRoot . '/class.%s' . $docRefExt, 'function' => $docRefRoot . '/function.%s' . $docRefExt, 'method' => $docRefRoot . '/%2$s.%1$s' . $docRefExt, 'property' => $docRefRoot . '/class.%2$s' . $docRefExt . '#%2$s.props.%1$s', 'constant' => $docRefRoot . '/class.%2$s' . $docRefExt . '#%2$s.constants.%1$s', ); $url = null; $args = array(); // determine scheme if($constant !== null){ $type = 'constant'; $args[] = $constant; }else{ $type = explode('\\', get_class($reflector)); $type = strtolower(ltrim(end($type), 'Reflection')); if($type === 'object') $type = 'class'; } // properties don't have the internal flag; // also note that many internal classes use some kind of magic as properties (eg. DateTime); // these will only get linkifed if the declared class is internal one, and not an extension :( $parent = ($type !== 'property') ? $reflector : $reflector->getDeclaringClass(); // internal function/method/class/property/constant if($parent->isInternal()){ $args[] = $reflector->name; if(in_array($type, array('method', 'property'), true)) $args[] = $reflector->getDeclaringClass()->getName(); $args = array_map(function($text){ return str_replace('_', '-', ltrim(strtolower($text), '\\_')); }, $args); // check for some special cases that have no links $valid = (($type === 'method') || (strcasecmp($parent->name, 'stdClass') !== 0)) && (($type !== 'method') || (($reflector->name === '__construct') || strpos($reflector->name, '__') !== 0)); if($valid) $url = vsprintf($phpNetSchemes[$type], $args); // custom }else{ switch(true){ // WordPress function; // like pretty much everything else in WordPress, API links are inconsistent as well; // so we're using queryposts.com as doc source for API case ($type === 'function') && class_exists('WP') && defined('ABSPATH') && defined('WPINC'): if(strpos($reflector->getFileName(), realpath(ABSPATH . WPINC)) === 0){ $url = sprintf('http://queryposts.com/function/%s', urlencode(strtolower($reflector->getName()))); break; } // @todo: handle more apps } } return $url; }
php
protected function linkify(\Reflector $reflector, $constant = null){ static $docRefRoot = null, $docRefExt = null; // most people don't have this set if(!$docRefRoot) $docRefRoot = ($docRefRoot = rtrim(ini_get('docref_root'), '/')) ? $docRefRoot : 'http://php.net/manual/en'; if(!$docRefExt) $docRefExt = ($docRefExt = ini_get('docref_ext')) ? $docRefExt : '.php'; $phpNetSchemes = array( 'class' => $docRefRoot . '/class.%s' . $docRefExt, 'function' => $docRefRoot . '/function.%s' . $docRefExt, 'method' => $docRefRoot . '/%2$s.%1$s' . $docRefExt, 'property' => $docRefRoot . '/class.%2$s' . $docRefExt . '#%2$s.props.%1$s', 'constant' => $docRefRoot . '/class.%2$s' . $docRefExt . '#%2$s.constants.%1$s', ); $url = null; $args = array(); // determine scheme if($constant !== null){ $type = 'constant'; $args[] = $constant; }else{ $type = explode('\\', get_class($reflector)); $type = strtolower(ltrim(end($type), 'Reflection')); if($type === 'object') $type = 'class'; } // properties don't have the internal flag; // also note that many internal classes use some kind of magic as properties (eg. DateTime); // these will only get linkifed if the declared class is internal one, and not an extension :( $parent = ($type !== 'property') ? $reflector : $reflector->getDeclaringClass(); // internal function/method/class/property/constant if($parent->isInternal()){ $args[] = $reflector->name; if(in_array($type, array('method', 'property'), true)) $args[] = $reflector->getDeclaringClass()->getName(); $args = array_map(function($text){ return str_replace('_', '-', ltrim(strtolower($text), '\\_')); }, $args); // check for some special cases that have no links $valid = (($type === 'method') || (strcasecmp($parent->name, 'stdClass') !== 0)) && (($type !== 'method') || (($reflector->name === '__construct') || strpos($reflector->name, '__') !== 0)); if($valid) $url = vsprintf($phpNetSchemes[$type], $args); // custom }else{ switch(true){ // WordPress function; // like pretty much everything else in WordPress, API links are inconsistent as well; // so we're using queryposts.com as doc source for API case ($type === 'function') && class_exists('WP') && defined('ABSPATH') && defined('WPINC'): if(strpos($reflector->getFileName(), realpath(ABSPATH . WPINC)) === 0){ $url = sprintf('http://queryposts.com/function/%s', urlencode(strtolower($reflector->getName()))); break; } // @todo: handle more apps } } return $url; }
[ "protected", "function", "linkify", "(", "\\", "Reflector", "$", "reflector", ",", "$", "constant", "=", "null", ")", "{", "static", "$", "docRefRoot", "=", "null", ",", "$", "docRefExt", "=", "null", ";", "// most people don't have this set", "if", "(", "!", "$", "docRefRoot", ")", "$", "docRefRoot", "=", "(", "$", "docRefRoot", "=", "rtrim", "(", "ini_get", "(", "'docref_root'", ")", ",", "'/'", ")", ")", "?", "$", "docRefRoot", ":", "'http://php.net/manual/en'", ";", "if", "(", "!", "$", "docRefExt", ")", "$", "docRefExt", "=", "(", "$", "docRefExt", "=", "ini_get", "(", "'docref_ext'", ")", ")", "?", "$", "docRefExt", ":", "'.php'", ";", "$", "phpNetSchemes", "=", "array", "(", "'class'", "=>", "$", "docRefRoot", ".", "'/class.%s'", ".", "$", "docRefExt", ",", "'function'", "=>", "$", "docRefRoot", ".", "'/function.%s'", ".", "$", "docRefExt", ",", "'method'", "=>", "$", "docRefRoot", ".", "'/%2$s.%1$s'", ".", "$", "docRefExt", ",", "'property'", "=>", "$", "docRefRoot", ".", "'/class.%2$s'", ".", "$", "docRefExt", ".", "'#%2$s.props.%1$s'", ",", "'constant'", "=>", "$", "docRefRoot", ".", "'/class.%2$s'", ".", "$", "docRefExt", ".", "'#%2$s.constants.%1$s'", ",", ")", ";", "$", "url", "=", "null", ";", "$", "args", "=", "array", "(", ")", ";", "// determine scheme", "if", "(", "$", "constant", "!==", "null", ")", "{", "$", "type", "=", "'constant'", ";", "$", "args", "[", "]", "=", "$", "constant", ";", "}", "else", "{", "$", "type", "=", "explode", "(", "'\\\\'", ",", "get_class", "(", "$", "reflector", ")", ")", ";", "$", "type", "=", "strtolower", "(", "ltrim", "(", "end", "(", "$", "type", ")", ",", "'Reflection'", ")", ")", ";", "if", "(", "$", "type", "===", "'object'", ")", "$", "type", "=", "'class'", ";", "}", "// properties don't have the internal flag;", "// also note that many internal classes use some kind of magic as properties (eg. DateTime);", "// these will only get linkifed if the declared class is internal one, and not an extension :(", "$", "parent", "=", "(", "$", "type", "!==", "'property'", ")", "?", "$", "reflector", ":", "$", "reflector", "->", "getDeclaringClass", "(", ")", ";", "// internal function/method/class/property/constant", "if", "(", "$", "parent", "->", "isInternal", "(", ")", ")", "{", "$", "args", "[", "]", "=", "$", "reflector", "->", "name", ";", "if", "(", "in_array", "(", "$", "type", ",", "array", "(", "'method'", ",", "'property'", ")", ",", "true", ")", ")", "$", "args", "[", "]", "=", "$", "reflector", "->", "getDeclaringClass", "(", ")", "->", "getName", "(", ")", ";", "$", "args", "=", "array_map", "(", "function", "(", "$", "text", ")", "{", "return", "str_replace", "(", "'_'", ",", "'-'", ",", "ltrim", "(", "strtolower", "(", "$", "text", ")", ",", "'\\\\_'", ")", ")", ";", "}", ",", "$", "args", ")", ";", "// check for some special cases that have no links", "$", "valid", "=", "(", "(", "$", "type", "===", "'method'", ")", "||", "(", "strcasecmp", "(", "$", "parent", "->", "name", ",", "'stdClass'", ")", "!==", "0", ")", ")", "&&", "(", "(", "$", "type", "!==", "'method'", ")", "||", "(", "(", "$", "reflector", "->", "name", "===", "'__construct'", ")", "||", "strpos", "(", "$", "reflector", "->", "name", ",", "'__'", ")", "!==", "0", ")", ")", ";", "if", "(", "$", "valid", ")", "$", "url", "=", "vsprintf", "(", "$", "phpNetSchemes", "[", "$", "type", "]", ",", "$", "args", ")", ";", "// custom", "}", "else", "{", "switch", "(", "true", ")", "{", "// WordPress function;", "// like pretty much everything else in WordPress, API links are inconsistent as well;", "// so we're using queryposts.com as doc source for API", "case", "(", "$", "type", "===", "'function'", ")", "&&", "class_exists", "(", "'WP'", ")", "&&", "defined", "(", "'ABSPATH'", ")", "&&", "defined", "(", "'WPINC'", ")", ":", "if", "(", "strpos", "(", "$", "reflector", "->", "getFileName", "(", ")", ",", "realpath", "(", "ABSPATH", ".", "WPINC", ")", ")", "===", "0", ")", "{", "$", "url", "=", "sprintf", "(", "'http://queryposts.com/function/%s'", ",", "urlencode", "(", "strtolower", "(", "$", "reflector", "->", "getName", "(", ")", ")", ")", ")", ";", "break", ";", "}", "// @todo: handle more apps", "}", "}", "return", "$", "url", ";", "}" ]
Generates an URL that points to the documentation page relevant for the requested context For internal functions and classes, the URI will point to the local PHP manual if installed and configured, otherwise to php.net/manual (the english one) @param Reflector $reflector Reflector object (used to determine the URL scheme for internal stuff) @param string|null $constant Constant name, if this is a request to linkify a constant @return string|null URL
[ "Generates", "an", "URL", "that", "points", "to", "the", "documentation", "page", "relevant", "for", "the", "requested", "context" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/lib/php-ref/ref.php#L978-L1055
train
squareproton/Bond
lib/php-ref/ref.php
ref.strLen
protected static function strLen($string){ $encoding = function_exists('mb_detect_encoding') ? mb_detect_encoding($string) : false; return $encoding ? mb_strlen($string, $encoding) : strlen($string); }
php
protected static function strLen($string){ $encoding = function_exists('mb_detect_encoding') ? mb_detect_encoding($string) : false; return $encoding ? mb_strlen($string, $encoding) : strlen($string); }
[ "protected", "static", "function", "strLen", "(", "$", "string", ")", "{", "$", "encoding", "=", "function_exists", "(", "'mb_detect_encoding'", ")", "?", "mb_detect_encoding", "(", "$", "string", ")", ":", "false", ";", "return", "$", "encoding", "?", "mb_strlen", "(", "$", "string", ",", "$", "encoding", ")", ":", "strlen", "(", "$", "string", ")", ";", "}" ]
Calculates real string length @param string $string @return int
[ "Calculates", "real", "string", "length" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/lib/php-ref/ref.php#L1944-L1947
train
squareproton/Bond
lib/php-ref/ref.php
ref.strPad
protected static function strPad($input, $padLen, $padStr = ' ', $padType = STR_PAD_RIGHT){ $diff = strlen($input) - static::strLen($input); return str_pad($input, $padLen + $diff, $padStr, $padType); }
php
protected static function strPad($input, $padLen, $padStr = ' ', $padType = STR_PAD_RIGHT){ $diff = strlen($input) - static::strLen($input); return str_pad($input, $padLen + $diff, $padStr, $padType); }
[ "protected", "static", "function", "strPad", "(", "$", "input", ",", "$", "padLen", ",", "$", "padStr", "=", "' '", ",", "$", "padType", "=", "STR_PAD_RIGHT", ")", "{", "$", "diff", "=", "strlen", "(", "$", "input", ")", "-", "static", "::", "strLen", "(", "$", "input", ")", ";", "return", "str_pad", "(", "$", "input", ",", "$", "padLen", "+", "$", "diff", ",", "$", "padStr", ",", "$", "padType", ")", ";", "}" ]
Safe str_pad alternative @param string $string @param int $padLen @param string $padStr @param int $padType @return string
[ "Safe", "str_pad", "alternative" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/lib/php-ref/ref.php#L1960-L1963
train
larapulse/support
src/Handlers/Arr.php
Arr.flatten
public static function flatten(array $array, $depth = INF) : array { $depth = is_int($depth) ? max($depth, 0) : INF; return array_reduce($array, function ($result, $item) use ($depth) { if (!is_array($item) || $depth === 0) { return array_merge($result, [$item]); } elseif ($depth === 1) { return array_merge($result, array_values($item)); } else { return array_merge($result, self::flatten($item, $depth - 1)); } }, []); }
php
public static function flatten(array $array, $depth = INF) : array { $depth = is_int($depth) ? max($depth, 0) : INF; return array_reduce($array, function ($result, $item) use ($depth) { if (!is_array($item) || $depth === 0) { return array_merge($result, [$item]); } elseif ($depth === 1) { return array_merge($result, array_values($item)); } else { return array_merge($result, self::flatten($item, $depth - 1)); } }, []); }
[ "public", "static", "function", "flatten", "(", "array", "$", "array", ",", "$", "depth", "=", "INF", ")", ":", "array", "{", "$", "depth", "=", "is_int", "(", "$", "depth", ")", "?", "max", "(", "$", "depth", ",", "0", ")", ":", "INF", ";", "return", "array_reduce", "(", "$", "array", ",", "function", "(", "$", "result", ",", "$", "item", ")", "use", "(", "$", "depth", ")", "{", "if", "(", "!", "is_array", "(", "$", "item", ")", "||", "$", "depth", "===", "0", ")", "{", "return", "array_merge", "(", "$", "result", ",", "[", "$", "item", "]", ")", ";", "}", "elseif", "(", "$", "depth", "===", "1", ")", "{", "return", "array_merge", "(", "$", "result", ",", "array_values", "(", "$", "item", ")", ")", ";", "}", "else", "{", "return", "array_merge", "(", "$", "result", ",", "self", "::", "flatten", "(", "$", "item", ",", "$", "depth", "-", "1", ")", ")", ";", "}", "}", ",", "[", "]", ")", ";", "}" ]
Flatten a multi-dimensional array into a single level @param array $array @param int $depth @return array
[ "Flatten", "a", "multi", "-", "dimensional", "array", "into", "a", "single", "level" ]
601ee3fd6967be669afe081322340c82c7edf32d
https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Handlers/Arr.php#L16-L29
train
larapulse/support
src/Handlers/Arr.php
Arr.flattenAssoc
public static function flattenAssoc(array $array, $depth = INF) : array { $result = []; $depth = is_int($depth) ? max($depth, 0) : INF; foreach ($array as $key => $value) { if (is_array($value) && $depth >= 1) { $result = self::flattenAssoc($value, $depth - 1) + $result; } else { $result[$key] = $value; } } return $result; }
php
public static function flattenAssoc(array $array, $depth = INF) : array { $result = []; $depth = is_int($depth) ? max($depth, 0) : INF; foreach ($array as $key => $value) { if (is_array($value) && $depth >= 1) { $result = self::flattenAssoc($value, $depth - 1) + $result; } else { $result[$key] = $value; } } return $result; }
[ "public", "static", "function", "flattenAssoc", "(", "array", "$", "array", ",", "$", "depth", "=", "INF", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "$", "depth", "=", "is_int", "(", "$", "depth", ")", "?", "max", "(", "$", "depth", ",", "0", ")", ":", "INF", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "$", "depth", ">=", "1", ")", "{", "$", "result", "=", "self", "::", "flattenAssoc", "(", "$", "value", ",", "$", "depth", "-", "1", ")", "+", "$", "result", ";", "}", "else", "{", "$", "result", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "result", ";", "}" ]
Flatten a multi-dimensional array into a single level with saving keys @param array $array @param int $depth @return array
[ "Flatten", "a", "multi", "-", "dimensional", "array", "into", "a", "single", "level", "with", "saving", "keys" ]
601ee3fd6967be669afe081322340c82c7edf32d
https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Handlers/Arr.php#L39-L53
train
larapulse/support
src/Handlers/Arr.php
Arr.depth
public static function depth(array $array) : int { $maxDepth = 1; foreach ($array as $value) { if (is_array($value)) { $depth = self::depth($value) + 1; if ($depth > $maxDepth) { $maxDepth = $depth; } } } return $maxDepth; }
php
public static function depth(array $array) : int { $maxDepth = 1; foreach ($array as $value) { if (is_array($value)) { $depth = self::depth($value) + 1; if ($depth > $maxDepth) { $maxDepth = $depth; } } } return $maxDepth; }
[ "public", "static", "function", "depth", "(", "array", "$", "array", ")", ":", "int", "{", "$", "maxDepth", "=", "1", ";", "foreach", "(", "$", "array", "as", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "depth", "=", "self", "::", "depth", "(", "$", "value", ")", "+", "1", ";", "if", "(", "$", "depth", ">", "$", "maxDepth", ")", "{", "$", "maxDepth", "=", "$", "depth", ";", "}", "}", "}", "return", "$", "maxDepth", ";", "}" ]
Get depth of array @param array $array @return int
[ "Get", "depth", "of", "array" ]
601ee3fd6967be669afe081322340c82c7edf32d
https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Handlers/Arr.php#L62-L77
train
t3v/t3v_datamapper
Classes/ViewHelpers/Page/HiddenViewHelper.php
HiddenViewHelper.evaluateCondition
protected static function evaluateCondition($arguments = null): bool { $uid = intval($arguments['uid']); $languageUid = isset($arguments['languageUid']) ? intval($arguments['languageUid']) : self::getLanguageService()->getLanguageUid(); $page = self::getPageService()->getPageByUid($uid, $languageUid); $hidden = (boolean) $page['hidden']; return $hidden; }
php
protected static function evaluateCondition($arguments = null): bool { $uid = intval($arguments['uid']); $languageUid = isset($arguments['languageUid']) ? intval($arguments['languageUid']) : self::getLanguageService()->getLanguageUid(); $page = self::getPageService()->getPageByUid($uid, $languageUid); $hidden = (boolean) $page['hidden']; return $hidden; }
[ "protected", "static", "function", "evaluateCondition", "(", "$", "arguments", "=", "null", ")", ":", "bool", "{", "$", "uid", "=", "intval", "(", "$", "arguments", "[", "'uid'", "]", ")", ";", "$", "languageUid", "=", "isset", "(", "$", "arguments", "[", "'languageUid'", "]", ")", "?", "intval", "(", "$", "arguments", "[", "'languageUid'", "]", ")", ":", "self", "::", "getLanguageService", "(", ")", "->", "getLanguageUid", "(", ")", ";", "$", "page", "=", "self", "::", "getPageService", "(", ")", "->", "getPageByUid", "(", "$", "uid", ",", "$", "languageUid", ")", ";", "$", "hidden", "=", "(", "boolean", ")", "$", "page", "[", "'hidden'", "]", ";", "return", "$", "hidden", ";", "}" ]
Evaluates the condition. @param array|null $arguments The arguments @return bool Whether the condition is fulfilled
[ "Evaluates", "the", "condition", "." ]
bab2de90f467936fbe4270cd133cb4109d1108eb
https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/ViewHelpers/Page/HiddenViewHelper.php#L34-L41
train
t3v/t3v_datamapper
Classes/ViewHelpers/Page/HiddenViewHelper.php
HiddenViewHelper.getLanguageService
protected static function getLanguageService(): LanguageService { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $languageService = $objectManager->get(LanguageService::class); return $languageService; }
php
protected static function getLanguageService(): LanguageService { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $languageService = $objectManager->get(LanguageService::class); return $languageService; }
[ "protected", "static", "function", "getLanguageService", "(", ")", ":", "LanguageService", "{", "$", "objectManager", "=", "GeneralUtility", "::", "makeInstance", "(", "ObjectManager", "::", "class", ")", ";", "$", "languageService", "=", "$", "objectManager", "->", "get", "(", "LanguageService", "::", "class", ")", ";", "return", "$", "languageService", ";", "}" ]
Gets the language service. @return \T3v\T3vCore\Service\LanguageService The language service
[ "Gets", "the", "language", "service", "." ]
bab2de90f467936fbe4270cd133cb4109d1108eb
https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/ViewHelpers/Page/HiddenViewHelper.php#L48-L53
train
t3v/t3v_datamapper
Classes/ViewHelpers/Page/HiddenViewHelper.php
HiddenViewHelper.getPageService
protected static function getPageService(): PageService { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $pageService = $objectManager->get(PageService::class); return $pageService; }
php
protected static function getPageService(): PageService { $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $pageService = $objectManager->get(PageService::class); return $pageService; }
[ "protected", "static", "function", "getPageService", "(", ")", ":", "PageService", "{", "$", "objectManager", "=", "GeneralUtility", "::", "makeInstance", "(", "ObjectManager", "::", "class", ")", ";", "$", "pageService", "=", "$", "objectManager", "->", "get", "(", "PageService", "::", "class", ")", ";", "return", "$", "pageService", ";", "}" ]
Gets the page service. @return \T3v\T3vDataMapper\Service\PageService The page service
[ "Gets", "the", "page", "service", "." ]
bab2de90f467936fbe4270cd133cb4109d1108eb
https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/ViewHelpers/Page/HiddenViewHelper.php#L60-L65
train
nirou8/php-multiple-saml
lib/Saml2/Auth.php
OneLogin_Saml2_Auth.processResponse
public function processResponse($requestId = null) { $this->_errors = array(); $this->_errorReason = null; if (isset($_POST) && isset($_POST['SAMLResponse'])) { // AuthnResponse -- HTTP_POST Binding $response = new OneLogin_Saml2_Response($this->_settings, $_POST['SAMLResponse']); $this->_lastResponse = $response->getXMLDocument(); if ($response->isValid($requestId)) { $this->_attributes = $response->getAttributes(); $this->_attributesWithFriendlyName = $response->getAttributesWithFriendlyName(); $this->_nameid = $response->getNameId(); $this->_nameidFormat = $response->getNameIdFormat(); $this->_nameidNameQualifier = $response->getNameIdNameQualifier(); $this->_authenticated = true; $this->_sessionIndex = $response->getSessionIndex(); $this->_sessionExpiration = $response->getSessionNotOnOrAfter(); $this->_lastMessageId = $response->getId(); $this->_lastAssertionId = $response->getAssertionId(); $this->_lastAssertionNotOnOrAfter = $response->getAssertionNotOnOrAfter(); } else { $this->_errors[] = 'invalid_response'; $this->_errorReason = $response->getError(); } } else { $this->_errors[] = 'invalid_binding'; throw new OneLogin_Saml2_Error( 'SAML Response not found, Only supported HTTP_POST Binding', OneLogin_Saml2_Error::SAML_RESPONSE_NOT_FOUND ); } }
php
public function processResponse($requestId = null) { $this->_errors = array(); $this->_errorReason = null; if (isset($_POST) && isset($_POST['SAMLResponse'])) { // AuthnResponse -- HTTP_POST Binding $response = new OneLogin_Saml2_Response($this->_settings, $_POST['SAMLResponse']); $this->_lastResponse = $response->getXMLDocument(); if ($response->isValid($requestId)) { $this->_attributes = $response->getAttributes(); $this->_attributesWithFriendlyName = $response->getAttributesWithFriendlyName(); $this->_nameid = $response->getNameId(); $this->_nameidFormat = $response->getNameIdFormat(); $this->_nameidNameQualifier = $response->getNameIdNameQualifier(); $this->_authenticated = true; $this->_sessionIndex = $response->getSessionIndex(); $this->_sessionExpiration = $response->getSessionNotOnOrAfter(); $this->_lastMessageId = $response->getId(); $this->_lastAssertionId = $response->getAssertionId(); $this->_lastAssertionNotOnOrAfter = $response->getAssertionNotOnOrAfter(); } else { $this->_errors[] = 'invalid_response'; $this->_errorReason = $response->getError(); } } else { $this->_errors[] = 'invalid_binding'; throw new OneLogin_Saml2_Error( 'SAML Response not found, Only supported HTTP_POST Binding', OneLogin_Saml2_Error::SAML_RESPONSE_NOT_FOUND ); } }
[ "public", "function", "processResponse", "(", "$", "requestId", "=", "null", ")", "{", "$", "this", "->", "_errors", "=", "array", "(", ")", ";", "$", "this", "->", "_errorReason", "=", "null", ";", "if", "(", "isset", "(", "$", "_POST", ")", "&&", "isset", "(", "$", "_POST", "[", "'SAMLResponse'", "]", ")", ")", "{", "// AuthnResponse -- HTTP_POST Binding", "$", "response", "=", "new", "OneLogin_Saml2_Response", "(", "$", "this", "->", "_settings", ",", "$", "_POST", "[", "'SAMLResponse'", "]", ")", ";", "$", "this", "->", "_lastResponse", "=", "$", "response", "->", "getXMLDocument", "(", ")", ";", "if", "(", "$", "response", "->", "isValid", "(", "$", "requestId", ")", ")", "{", "$", "this", "->", "_attributes", "=", "$", "response", "->", "getAttributes", "(", ")", ";", "$", "this", "->", "_attributesWithFriendlyName", "=", "$", "response", "->", "getAttributesWithFriendlyName", "(", ")", ";", "$", "this", "->", "_nameid", "=", "$", "response", "->", "getNameId", "(", ")", ";", "$", "this", "->", "_nameidFormat", "=", "$", "response", "->", "getNameIdFormat", "(", ")", ";", "$", "this", "->", "_nameidNameQualifier", "=", "$", "response", "->", "getNameIdNameQualifier", "(", ")", ";", "$", "this", "->", "_authenticated", "=", "true", ";", "$", "this", "->", "_sessionIndex", "=", "$", "response", "->", "getSessionIndex", "(", ")", ";", "$", "this", "->", "_sessionExpiration", "=", "$", "response", "->", "getSessionNotOnOrAfter", "(", ")", ";", "$", "this", "->", "_lastMessageId", "=", "$", "response", "->", "getId", "(", ")", ";", "$", "this", "->", "_lastAssertionId", "=", "$", "response", "->", "getAssertionId", "(", ")", ";", "$", "this", "->", "_lastAssertionNotOnOrAfter", "=", "$", "response", "->", "getAssertionNotOnOrAfter", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_errors", "[", "]", "=", "'invalid_response'", ";", "$", "this", "->", "_errorReason", "=", "$", "response", "->", "getError", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "_errors", "[", "]", "=", "'invalid_binding'", ";", "throw", "new", "OneLogin_Saml2_Error", "(", "'SAML Response not found, Only supported HTTP_POST Binding'", ",", "OneLogin_Saml2_Error", "::", "SAML_RESPONSE_NOT_FOUND", ")", ";", "}", "}" ]
Process the SAML Response sent by the IdP. @param string|null $requestId The ID of the AuthNRequest sent by this SP to the IdP @throws OneLogin_Saml2_Error
[ "Process", "the", "SAML", "Response", "sent", "by", "the", "IdP", "." ]
7eb5786e678db7d45459ce3441fa187946ae9a3b
https://github.com/nirou8/php-multiple-saml/blob/7eb5786e678db7d45459ce3441fa187946ae9a3b/lib/Saml2/Auth.php#L181-L213
train
nirou8/php-multiple-saml
lib/Saml2/Auth.php
OneLogin_Saml2_Auth.login
public function login($indexAcs, $returnTo = null, $parameters = array(), $forceAuthn = false, $isPassive = false, $stay = false, $setNameIdPolicy = true) { assert('is_array($parameters)'); $authnRequest = new OneLogin_Saml2_AuthnRequest($indexAcs, $this->_settings, $forceAuthn, $isPassive, $setNameIdPolicy); $this->_lastRequest = $authnRequest->getXML(); $this->_lastRequestID = $authnRequest->getId(); $samlRequest = $authnRequest->getRequest(); $parameters['SAMLRequest'] = $samlRequest; if (!empty($returnTo)) { $parameters['RelayState'] = $returnTo; } else { $parameters['RelayState'] = OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery(); } $security = $this->_settings->getSecurityData(); if (isset($security['authnRequestsSigned']) && $security['authnRequestsSigned']) { $signature = $this->buildRequestSignature($samlRequest, $parameters['RelayState'], $security['signatureAlgorithm']); $parameters['SigAlg'] = $security['signatureAlgorithm']; $parameters['Signature'] = $signature; } return $this->redirectTo($this->getSSOurl(), $parameters, $stay); }
php
public function login($indexAcs, $returnTo = null, $parameters = array(), $forceAuthn = false, $isPassive = false, $stay = false, $setNameIdPolicy = true) { assert('is_array($parameters)'); $authnRequest = new OneLogin_Saml2_AuthnRequest($indexAcs, $this->_settings, $forceAuthn, $isPassive, $setNameIdPolicy); $this->_lastRequest = $authnRequest->getXML(); $this->_lastRequestID = $authnRequest->getId(); $samlRequest = $authnRequest->getRequest(); $parameters['SAMLRequest'] = $samlRequest; if (!empty($returnTo)) { $parameters['RelayState'] = $returnTo; } else { $parameters['RelayState'] = OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery(); } $security = $this->_settings->getSecurityData(); if (isset($security['authnRequestsSigned']) && $security['authnRequestsSigned']) { $signature = $this->buildRequestSignature($samlRequest, $parameters['RelayState'], $security['signatureAlgorithm']); $parameters['SigAlg'] = $security['signatureAlgorithm']; $parameters['Signature'] = $signature; } return $this->redirectTo($this->getSSOurl(), $parameters, $stay); }
[ "public", "function", "login", "(", "$", "indexAcs", ",", "$", "returnTo", "=", "null", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "forceAuthn", "=", "false", ",", "$", "isPassive", "=", "false", ",", "$", "stay", "=", "false", ",", "$", "setNameIdPolicy", "=", "true", ")", "{", "assert", "(", "'is_array($parameters)'", ")", ";", "$", "authnRequest", "=", "new", "OneLogin_Saml2_AuthnRequest", "(", "$", "indexAcs", ",", "$", "this", "->", "_settings", ",", "$", "forceAuthn", ",", "$", "isPassive", ",", "$", "setNameIdPolicy", ")", ";", "$", "this", "->", "_lastRequest", "=", "$", "authnRequest", "->", "getXML", "(", ")", ";", "$", "this", "->", "_lastRequestID", "=", "$", "authnRequest", "->", "getId", "(", ")", ";", "$", "samlRequest", "=", "$", "authnRequest", "->", "getRequest", "(", ")", ";", "$", "parameters", "[", "'SAMLRequest'", "]", "=", "$", "samlRequest", ";", "if", "(", "!", "empty", "(", "$", "returnTo", ")", ")", "{", "$", "parameters", "[", "'RelayState'", "]", "=", "$", "returnTo", ";", "}", "else", "{", "$", "parameters", "[", "'RelayState'", "]", "=", "OneLogin_Saml2_Utils", "::", "getSelfRoutedURLNoQuery", "(", ")", ";", "}", "$", "security", "=", "$", "this", "->", "_settings", "->", "getSecurityData", "(", ")", ";", "if", "(", "isset", "(", "$", "security", "[", "'authnRequestsSigned'", "]", ")", "&&", "$", "security", "[", "'authnRequestsSigned'", "]", ")", "{", "$", "signature", "=", "$", "this", "->", "buildRequestSignature", "(", "$", "samlRequest", ",", "$", "parameters", "[", "'RelayState'", "]", ",", "$", "security", "[", "'signatureAlgorithm'", "]", ")", ";", "$", "parameters", "[", "'SigAlg'", "]", "=", "$", "security", "[", "'signatureAlgorithm'", "]", ";", "$", "parameters", "[", "'Signature'", "]", "=", "$", "signature", ";", "}", "return", "$", "this", "->", "redirectTo", "(", "$", "this", "->", "getSSOurl", "(", ")", ",", "$", "parameters", ",", "$", "stay", ")", ";", "}" ]
Initiates the SSO process. @param string|null $returnTo The target URL the user should be returned to after login. @param array $parameters Extra parameters to be added to the GET @param bool $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true' @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true' @param bool $stay True if we want to stay (returns the url string) False to redirect @param bool $setNameIdPolicy When true the AuthNReuqest will set a nameIdPolicy element @return string|null If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
[ "Initiates", "the", "SSO", "process", "." ]
7eb5786e678db7d45459ce3441fa187946ae9a3b
https://github.com/nirou8/php-multiple-saml/blob/7eb5786e678db7d45459ce3441fa187946ae9a3b/lib/Saml2/Auth.php#L464-L489
train
nirou8/php-multiple-saml
lib/Saml2/Auth.php
OneLogin_Saml2_Auth.logout
public function logout($application_index = null, $returnTo = null, $parameters = array(), $nameId = null, $sessionIndex = null, $stay = false, $nameIdFormat = null, $nameIdNameQualifier = null) { assert('is_array($parameters)'); $sloUrl = $this->getSLOurl($application_index); if (empty($sloUrl)) { throw new OneLogin_Saml2_Error( 'The IdP does not support Single Log Out', OneLogin_Saml2_Error::SAML_SINGLE_LOGOUT_NOT_SUPPORTED ); } if (empty($nameId) && !empty($this->_nameid)) { $nameId = $this->_nameid; } if (empty($nameIdFormat) && !empty($this->_nameidFormat)) { $nameIdFormat = $this->_nameidFormat; } $logoutRequest = new OneLogin_Saml2_LogoutRequest($application_index, $this->_settings, null, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier); $this->_lastRequest = $logoutRequest->getXML(); $this->_lastRequestID = $logoutRequest->id; $samlRequest = $logoutRequest->getRequest(); $parameters['SAMLRequest'] = $samlRequest; if (!empty($returnTo)) { $parameters['RelayState'] = $returnTo; } else { $parameters['RelayState'] = OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery(); } $security = $this->_settings->getSecurityData(); if (isset($security['logoutRequestSigned']) && $security['logoutRequestSigned']) { $signature = $this->buildRequestSignature($samlRequest, $parameters['RelayState'], $security['signatureAlgorithm']); $parameters['SigAlg'] = $security['signatureAlgorithm']; $parameters['Signature'] = $signature; } return $this->redirectTo($sloUrl, $parameters, $stay); }
php
public function logout($application_index = null, $returnTo = null, $parameters = array(), $nameId = null, $sessionIndex = null, $stay = false, $nameIdFormat = null, $nameIdNameQualifier = null) { assert('is_array($parameters)'); $sloUrl = $this->getSLOurl($application_index); if (empty($sloUrl)) { throw new OneLogin_Saml2_Error( 'The IdP does not support Single Log Out', OneLogin_Saml2_Error::SAML_SINGLE_LOGOUT_NOT_SUPPORTED ); } if (empty($nameId) && !empty($this->_nameid)) { $nameId = $this->_nameid; } if (empty($nameIdFormat) && !empty($this->_nameidFormat)) { $nameIdFormat = $this->_nameidFormat; } $logoutRequest = new OneLogin_Saml2_LogoutRequest($application_index, $this->_settings, null, $nameId, $sessionIndex, $nameIdFormat, $nameIdNameQualifier); $this->_lastRequest = $logoutRequest->getXML(); $this->_lastRequestID = $logoutRequest->id; $samlRequest = $logoutRequest->getRequest(); $parameters['SAMLRequest'] = $samlRequest; if (!empty($returnTo)) { $parameters['RelayState'] = $returnTo; } else { $parameters['RelayState'] = OneLogin_Saml2_Utils::getSelfRoutedURLNoQuery(); } $security = $this->_settings->getSecurityData(); if (isset($security['logoutRequestSigned']) && $security['logoutRequestSigned']) { $signature = $this->buildRequestSignature($samlRequest, $parameters['RelayState'], $security['signatureAlgorithm']); $parameters['SigAlg'] = $security['signatureAlgorithm']; $parameters['Signature'] = $signature; } return $this->redirectTo($sloUrl, $parameters, $stay); }
[ "public", "function", "logout", "(", "$", "application_index", "=", "null", ",", "$", "returnTo", "=", "null", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "nameId", "=", "null", ",", "$", "sessionIndex", "=", "null", ",", "$", "stay", "=", "false", ",", "$", "nameIdFormat", "=", "null", ",", "$", "nameIdNameQualifier", "=", "null", ")", "{", "assert", "(", "'is_array($parameters)'", ")", ";", "$", "sloUrl", "=", "$", "this", "->", "getSLOurl", "(", "$", "application_index", ")", ";", "if", "(", "empty", "(", "$", "sloUrl", ")", ")", "{", "throw", "new", "OneLogin_Saml2_Error", "(", "'The IdP does not support Single Log Out'", ",", "OneLogin_Saml2_Error", "::", "SAML_SINGLE_LOGOUT_NOT_SUPPORTED", ")", ";", "}", "if", "(", "empty", "(", "$", "nameId", ")", "&&", "!", "empty", "(", "$", "this", "->", "_nameid", ")", ")", "{", "$", "nameId", "=", "$", "this", "->", "_nameid", ";", "}", "if", "(", "empty", "(", "$", "nameIdFormat", ")", "&&", "!", "empty", "(", "$", "this", "->", "_nameidFormat", ")", ")", "{", "$", "nameIdFormat", "=", "$", "this", "->", "_nameidFormat", ";", "}", "$", "logoutRequest", "=", "new", "OneLogin_Saml2_LogoutRequest", "(", "$", "application_index", ",", "$", "this", "->", "_settings", ",", "null", ",", "$", "nameId", ",", "$", "sessionIndex", ",", "$", "nameIdFormat", ",", "$", "nameIdNameQualifier", ")", ";", "$", "this", "->", "_lastRequest", "=", "$", "logoutRequest", "->", "getXML", "(", ")", ";", "$", "this", "->", "_lastRequestID", "=", "$", "logoutRequest", "->", "id", ";", "$", "samlRequest", "=", "$", "logoutRequest", "->", "getRequest", "(", ")", ";", "$", "parameters", "[", "'SAMLRequest'", "]", "=", "$", "samlRequest", ";", "if", "(", "!", "empty", "(", "$", "returnTo", ")", ")", "{", "$", "parameters", "[", "'RelayState'", "]", "=", "$", "returnTo", ";", "}", "else", "{", "$", "parameters", "[", "'RelayState'", "]", "=", "OneLogin_Saml2_Utils", "::", "getSelfRoutedURLNoQuery", "(", ")", ";", "}", "$", "security", "=", "$", "this", "->", "_settings", "->", "getSecurityData", "(", ")", ";", "if", "(", "isset", "(", "$", "security", "[", "'logoutRequestSigned'", "]", ")", "&&", "$", "security", "[", "'logoutRequestSigned'", "]", ")", "{", "$", "signature", "=", "$", "this", "->", "buildRequestSignature", "(", "$", "samlRequest", ",", "$", "parameters", "[", "'RelayState'", "]", ",", "$", "security", "[", "'signatureAlgorithm'", "]", ")", ";", "$", "parameters", "[", "'SigAlg'", "]", "=", "$", "security", "[", "'signatureAlgorithm'", "]", ";", "$", "parameters", "[", "'Signature'", "]", "=", "$", "signature", ";", "}", "return", "$", "this", "->", "redirectTo", "(", "$", "sloUrl", ",", "$", "parameters", ",", "$", "stay", ")", ";", "}" ]
Initiates the SLO process. @param string|null $returnTo The target URL the user should be returned to after logout. @param array $parameters Extra parameters to be added to the GET @param string|null $nameId The NameID that will be set in the LogoutRequest. @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process). @param bool $stay True if we want to stay (returns the url string) False to redirect @param string|null $nameIdFormat The NameID Format will be set in the LogoutRequest. @param string|null $nameIdNameQualifier The NameID NameQualifier will be set in the LogoutRequest. @return string|null If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters @throws OneLogin_Saml2_Error
[ "Initiates", "the", "SLO", "process", "." ]
7eb5786e678db7d45459ce3441fa187946ae9a3b
https://github.com/nirou8/php-multiple-saml/blob/7eb5786e678db7d45459ce3441fa187946ae9a3b/lib/Saml2/Auth.php#L506-L547
train
ekyna/Resource
Event/ResourceMessage.php
ResourceMessage.validateType
public static function validateType($type) { if (!in_array($type, [self::TYPE_INFO, self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_ERROR])) { throw new \InvalidArgumentException('Invalid resource message type "%s".', $type); } }
php
public static function validateType($type) { if (!in_array($type, [self::TYPE_INFO, self::TYPE_SUCCESS, self::TYPE_WARNING, self::TYPE_ERROR])) { throw new \InvalidArgumentException('Invalid resource message type "%s".', $type); } }
[ "public", "static", "function", "validateType", "(", "$", "type", ")", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "[", "self", "::", "TYPE_INFO", ",", "self", "::", "TYPE_SUCCESS", ",", "self", "::", "TYPE_WARNING", ",", "self", "::", "TYPE_ERROR", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid resource message type \"%s\".'", ",", "$", "type", ")", ";", "}", "}" ]
Validates the type. @param string $type @throws \InvalidArgumentException
[ "Validates", "the", "type", "." ]
96ee3d28e02bd9513705408e3bb7f88a76e52f56
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Event/ResourceMessage.php#L92-L97
train
zeageorge/php-object
src/Object/Object.php
Object.__isset
public function __isset($name) { $dtp = new \stdClass(); $dtp->propertyName = $name; $dtp->continue = TRUE; $dtp->results = FALSE; $this->triggerEvent(self::EVENT_ON_BEFORE_ISSET_PROPERTY, $dtp); if ($dtp->continue == TRUE) { $getter = $this->public_function_prefix . 'get' . $dtp->propertyName; if ($this->hasMethod($getter)) { $dtp->results = $this->$getter() !== NULL; } else { $dtp->results = FALSE; } } $this->triggerEvent(self::EVENT_ON_AFTER_ISSET_PROPERTY, $dtp); return $dtp->results; }
php
public function __isset($name) { $dtp = new \stdClass(); $dtp->propertyName = $name; $dtp->continue = TRUE; $dtp->results = FALSE; $this->triggerEvent(self::EVENT_ON_BEFORE_ISSET_PROPERTY, $dtp); if ($dtp->continue == TRUE) { $getter = $this->public_function_prefix . 'get' . $dtp->propertyName; if ($this->hasMethod($getter)) { $dtp->results = $this->$getter() !== NULL; } else { $dtp->results = FALSE; } } $this->triggerEvent(self::EVENT_ON_AFTER_ISSET_PROPERTY, $dtp); return $dtp->results; }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "$", "dtp", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "dtp", "->", "propertyName", "=", "$", "name", ";", "$", "dtp", "->", "continue", "=", "TRUE", ";", "$", "dtp", "->", "results", "=", "FALSE", ";", "$", "this", "->", "triggerEvent", "(", "self", "::", "EVENT_ON_BEFORE_ISSET_PROPERTY", ",", "$", "dtp", ")", ";", "if", "(", "$", "dtp", "->", "continue", "==", "TRUE", ")", "{", "$", "getter", "=", "$", "this", "->", "public_function_prefix", ".", "'get'", ".", "$", "dtp", "->", "propertyName", ";", "if", "(", "$", "this", "->", "hasMethod", "(", "$", "getter", ")", ")", "{", "$", "dtp", "->", "results", "=", "$", "this", "->", "$", "getter", "(", ")", "!==", "NULL", ";", "}", "else", "{", "$", "dtp", "->", "results", "=", "FALSE", ";", "}", "}", "$", "this", "->", "triggerEvent", "(", "self", "::", "EVENT_ON_AFTER_ISSET_PROPERTY", ",", "$", "dtp", ")", ";", "return", "$", "dtp", "->", "results", ";", "}" ]
Checks if a property is set, i.e. defined and not NULL. Do not call this method directly as it is a PHP magic method that will be implicitly called when executing `isset($object->property)`. Note that if the property is not defined, FALSE will be returned. @param string $name the property name or the event name @return boolean whether the named property is set (not NULL). @see http://php.net/manual/en/function.isset.php
[ "Checks", "if", "a", "property", "is", "set", "i", ".", "e", ".", "defined", "and", "not", "NULL", "." ]
760bffd226c67ea3b9d898f0c6d76fb209ade72f
https://github.com/zeageorge/php-object/blob/760bffd226c67ea3b9d898f0c6d76fb209ade72f/src/Object/Object.php#L356-L375
train
Saritasa/php-eloquent-custom
src/Traits/SlugTrait.php
SlugTrait.setNameAttribute
public function setNameAttribute(string $name) { $this->attributes['name'] = $name; $this->slug = $slug = str_slug($name); if ($this instanceof Model && self::sameSlugs($this, $slug)->exists()) { $similarSlugs = self::similarSlugs($this, $slug); $postfix = 1; $this->slug = $slug.$postfix; while ($similarSlugs->has($this->slug)) { $postfix++; $this->slug = $slug.$postfix; } } }
php
public function setNameAttribute(string $name) { $this->attributes['name'] = $name; $this->slug = $slug = str_slug($name); if ($this instanceof Model && self::sameSlugs($this, $slug)->exists()) { $similarSlugs = self::similarSlugs($this, $slug); $postfix = 1; $this->slug = $slug.$postfix; while ($similarSlugs->has($this->slug)) { $postfix++; $this->slug = $slug.$postfix; } } }
[ "public", "function", "setNameAttribute", "(", "string", "$", "name", ")", "{", "$", "this", "->", "attributes", "[", "'name'", "]", "=", "$", "name", ";", "$", "this", "->", "slug", "=", "$", "slug", "=", "str_slug", "(", "$", "name", ")", ";", "if", "(", "$", "this", "instanceof", "Model", "&&", "self", "::", "sameSlugs", "(", "$", "this", ",", "$", "slug", ")", "->", "exists", "(", ")", ")", "{", "$", "similarSlugs", "=", "self", "::", "similarSlugs", "(", "$", "this", ",", "$", "slug", ")", ";", "$", "postfix", "=", "1", ";", "$", "this", "->", "slug", "=", "$", "slug", ".", "$", "postfix", ";", "while", "(", "$", "similarSlugs", "->", "has", "(", "$", "this", "->", "slug", ")", ")", "{", "$", "postfix", "++", ";", "$", "this", "->", "slug", "=", "$", "slug", ".", "$", "postfix", ";", "}", "}", "}" ]
Override set name - also updates slug @param string $name New name value
[ "Override", "set", "name", "-", "also", "updates", "slug" ]
54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a
https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Traits/SlugTrait.php#L22-L36
train
Hnto/nuki
src/Handlers/Http/Output/Response.php
Response.send
public function send($template = false) { if ($template !== false) { $this->setContent(new Content($template)); } $this->renderer->render($template); }
php
public function send($template = false) { if ($template !== false) { $this->setContent(new Content($template)); } $this->renderer->render($template); }
[ "public", "function", "send", "(", "$", "template", "=", "false", ")", "{", "if", "(", "$", "template", "!==", "false", ")", "{", "$", "this", "->", "setContent", "(", "new", "Content", "(", "$", "template", ")", ")", ";", "}", "$", "this", "->", "renderer", "->", "render", "(", "$", "template", ")", ";", "}" ]
Send output to use with template path optional @param mixed $template
[ "Send", "output", "to", "use", "with", "template", "path", "optional" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Output/Response.php#L55-L61
train
Hnto/nuki
src/Handlers/Http/Output/Response.php
Response.redirect
public function redirect($to, int $delay = 0) { $host = $this->server()->get('HTTP_HOST'); $protocol = 'http'; if ($this->server()->get('HTTPS')) { $protocol = 'https'; } $domain = $protocol . '://' . $host; if ($delay !== 0) { header('Refresh: ' . $delay . '; url=' . $domain . '/' . $to); return true; } header('Location: ' . $domain . '/' . $to); exit; }
php
public function redirect($to, int $delay = 0) { $host = $this->server()->get('HTTP_HOST'); $protocol = 'http'; if ($this->server()->get('HTTPS')) { $protocol = 'https'; } $domain = $protocol . '://' . $host; if ($delay !== 0) { header('Refresh: ' . $delay . '; url=' . $domain . '/' . $to); return true; } header('Location: ' . $domain . '/' . $to); exit; }
[ "public", "function", "redirect", "(", "$", "to", ",", "int", "$", "delay", "=", "0", ")", "{", "$", "host", "=", "$", "this", "->", "server", "(", ")", "->", "get", "(", "'HTTP_HOST'", ")", ";", "$", "protocol", "=", "'http'", ";", "if", "(", "$", "this", "->", "server", "(", ")", "->", "get", "(", "'HTTPS'", ")", ")", "{", "$", "protocol", "=", "'https'", ";", "}", "$", "domain", "=", "$", "protocol", ".", "'://'", ".", "$", "host", ";", "if", "(", "$", "delay", "!==", "0", ")", "{", "header", "(", "'Refresh: '", ".", "$", "delay", ".", "'; url='", ".", "$", "domain", ".", "'/'", ".", "$", "to", ")", ";", "return", "true", ";", "}", "header", "(", "'Location: '", ".", "$", "domain", ".", "'/'", ".", "$", "to", ")", ";", "exit", ";", "}" ]
Redirect to another page with additional delay @param string $to @param int $delay @return boolean
[ "Redirect", "to", "another", "page", "with", "additional", "delay" ]
c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c
https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Output/Response.php#L89-L106
train
AnonymPHP/Anonym-Database
Managers/BuildManager.php
BuildManager.resolvePreparedStatement
private function resolvePreparedStatement($query = '', array $parameters = []) { // the instance of database connection $connection = $this->getConnection(); $prepare = $connection->prepare($query); if ($prepare instanceof PDOStatement) { $resolved = $this->resolvePdoPreparedStatement($prepare, $parameters); } elseif ($prepare instanceof mysqli_stmt) { $resolved = $this->resolveMysqliPreparedStatement($prepare, $parameters); } return [$prepare, $resolved]; }
php
private function resolvePreparedStatement($query = '', array $parameters = []) { // the instance of database connection $connection = $this->getConnection(); $prepare = $connection->prepare($query); if ($prepare instanceof PDOStatement) { $resolved = $this->resolvePdoPreparedStatement($prepare, $parameters); } elseif ($prepare instanceof mysqli_stmt) { $resolved = $this->resolveMysqliPreparedStatement($prepare, $parameters); } return [$prepare, $resolved]; }
[ "private", "function", "resolvePreparedStatement", "(", "$", "query", "=", "''", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "// the instance of database connection", "$", "connection", "=", "$", "this", "->", "getConnection", "(", ")", ";", "$", "prepare", "=", "$", "connection", "->", "prepare", "(", "$", "query", ")", ";", "if", "(", "$", "prepare", "instanceof", "PDOStatement", ")", "{", "$", "resolved", "=", "$", "this", "->", "resolvePdoPreparedStatement", "(", "$", "prepare", ",", "$", "parameters", ")", ";", "}", "elseif", "(", "$", "prepare", "instanceof", "mysqli_stmt", ")", "{", "$", "resolved", "=", "$", "this", "->", "resolveMysqliPreparedStatement", "(", "$", "prepare", ",", "$", "parameters", ")", ";", "}", "return", "[", "$", "prepare", ",", "$", "resolved", "]", ";", "}" ]
resolve the query @param string $query @param array $parameters @return true or false
[ "resolve", "the", "query" ]
4d034219e0e3eb2833fa53204e9f52a74a9a7e4b
https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Managers/BuildManager.php#L131-L145
train
AnonymPHP/Anonym-Database
Managers/BuildManager.php
BuildManager.resolveMysqliPreparedStatement
private function resolveMysqliPreparedStatement(mysqli_stmt $prepare, array $parameters = []) { $s = ""; foreach ($parameters as $param) { if (is_string($param)) { $s .= "s"; } elseif (is_integer($param)) { $s .= "i"; } } if (count($parameters) < 1) { $paramArray = []; } else { $paramArray = array_merge([$s], $parameters); } call_user_func_array([$prepare, 'bind_param'], $this->refValues($paramArray)); return $prepare->execute(); }
php
private function resolveMysqliPreparedStatement(mysqli_stmt $prepare, array $parameters = []) { $s = ""; foreach ($parameters as $param) { if (is_string($param)) { $s .= "s"; } elseif (is_integer($param)) { $s .= "i"; } } if (count($parameters) < 1) { $paramArray = []; } else { $paramArray = array_merge([$s], $parameters); } call_user_func_array([$prepare, 'bind_param'], $this->refValues($paramArray)); return $prepare->execute(); }
[ "private", "function", "resolveMysqliPreparedStatement", "(", "mysqli_stmt", "$", "prepare", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "s", "=", "\"\"", ";", "foreach", "(", "$", "parameters", "as", "$", "param", ")", "{", "if", "(", "is_string", "(", "$", "param", ")", ")", "{", "$", "s", ".=", "\"s\"", ";", "}", "elseif", "(", "is_integer", "(", "$", "param", ")", ")", "{", "$", "s", ".=", "\"i\"", ";", "}", "}", "if", "(", "count", "(", "$", "parameters", ")", "<", "1", ")", "{", "$", "paramArray", "=", "[", "]", ";", "}", "else", "{", "$", "paramArray", "=", "array_merge", "(", "[", "$", "s", "]", ",", "$", "parameters", ")", ";", "}", "call_user_func_array", "(", "[", "$", "prepare", ",", "'bind_param'", "]", ",", "$", "this", "->", "refValues", "(", "$", "paramArray", ")", ")", ";", "return", "$", "prepare", "->", "execute", "(", ")", ";", "}" ]
resolve the mysql prepared statement @param mysqli_stmt $prepare @param array $parameters @return bool
[ "resolve", "the", "mysql", "prepared", "statement" ]
4d034219e0e3eb2833fa53204e9f52a74a9a7e4b
https://github.com/AnonymPHP/Anonym-Database/blob/4d034219e0e3eb2833fa53204e9f52a74a9a7e4b/Managers/BuildManager.php#L167-L187
train
pluf/tenant
src/Tenant/Views/Setting.php
Tenant_Views_Setting.get
public function get($request, $match) { // Set the default $model = $this->internalGet($request, $match); if (! isset($model)) { throw new Pluf_Exception_DoesNotExist('Setting not found'); } return $model; }
php
public function get($request, $match) { // Set the default $model = $this->internalGet($request, $match); if (! isset($model)) { throw new Pluf_Exception_DoesNotExist('Setting not found'); } return $model; }
[ "public", "function", "get", "(", "$", "request", ",", "$", "match", ")", "{", "// Set the default", "$", "model", "=", "$", "this", "->", "internalGet", "(", "$", "request", ",", "$", "match", ")", ";", "if", "(", "!", "isset", "(", "$", "model", ")", ")", "{", "throw", "new", "Pluf_Exception_DoesNotExist", "(", "'Setting not found'", ")", ";", "}", "return", "$", "model", ";", "}" ]
Getting system setting Anonymous are allowed to get Publich properties from the system. @param Pluf_HTTP_Request $request @param array $match
[ "Getting", "system", "setting" ]
a06359c52b9a257b5a0a186264e8770acfc54b73
https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/Views/Setting.php#L38-L45
train
duncan3dc/serial
src/ArrayObject.php
ArrayObject.make
public static function make(array $data) { # Convert values to ArrayObject instances foreach ($data as &$value) { if (is_array($value)) { $value = static::make($value); } } unset($value); return new self($data, \ArrayObject::ARRAY_AS_PROPS); }
php
public static function make(array $data) { # Convert values to ArrayObject instances foreach ($data as &$value) { if (is_array($value)) { $value = static::make($value); } } unset($value); return new self($data, \ArrayObject::ARRAY_AS_PROPS); }
[ "public", "static", "function", "make", "(", "array", "$", "data", ")", "{", "# Convert values to ArrayObject instances", "foreach", "(", "$", "data", "as", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "static", "::", "make", "(", "$", "value", ")", ";", "}", "}", "unset", "(", "$", "value", ")", ";", "return", "new", "self", "(", "$", "data", ",", "\\", "ArrayObject", "::", "ARRAY_AS_PROPS", ")", ";", "}" ]
Create a new instance from a basic array. @param array $data The array to convert @return self
[ "Create", "a", "new", "instance", "from", "a", "basic", "array", "." ]
2e40127a0a364ee1bd6f655b0f5b5d4a035a5716
https://github.com/duncan3dc/serial/blob/2e40127a0a364ee1bd6f655b0f5b5d4a035a5716/src/ArrayObject.php#L18-L29
train
duncan3dc/serial
src/ArrayObject.php
ArrayObject.asArray
public function asArray() { $array = []; foreach ($this as $key => $val) { if ($val instanceof self) { $val = $val->asArray(); } $array[$key] = $val; } return $array; }
php
public function asArray() { $array = []; foreach ($this as $key => $val) { if ($val instanceof self) { $val = $val->asArray(); } $array[$key] = $val; } return $array; }
[ "public", "function", "asArray", "(", ")", "{", "$", "array", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "$", "val", "instanceof", "self", ")", "{", "$", "val", "=", "$", "val", "->", "asArray", "(", ")", ";", "}", "$", "array", "[", "$", "key", "]", "=", "$", "val", ";", "}", "return", "$", "array", ";", "}" ]
Convert the current instance to a basic array. @return array
[ "Convert", "the", "current", "instance", "to", "a", "basic", "array", "." ]
2e40127a0a364ee1bd6f655b0f5b5d4a035a5716
https://github.com/duncan3dc/serial/blob/2e40127a0a364ee1bd6f655b0f5b5d4a035a5716/src/ArrayObject.php#L37-L49
train
sil-project/VarietyBundle
src/Admin/SpeciesAdmin.php
SpeciesAdmin.validateSpeciesCode
public function validateSpeciesCode(ErrorElement $errorElement, $object) { $generator = $this->getConfigurationPool()->getContainer()->get('librinfo_varieties.code_generator.species'); if (!$generator->validate($object->getCode())) { $errorElement ->with('code') ->addViolation('Wrong species code format') ->end(); } }
php
public function validateSpeciesCode(ErrorElement $errorElement, $object) { $generator = $this->getConfigurationPool()->getContainer()->get('librinfo_varieties.code_generator.species'); if (!$generator->validate($object->getCode())) { $errorElement ->with('code') ->addViolation('Wrong species code format') ->end(); } }
[ "public", "function", "validateSpeciesCode", "(", "ErrorElement", "$", "errorElement", ",", "$", "object", ")", "{", "$", "generator", "=", "$", "this", "->", "getConfigurationPool", "(", ")", "->", "getContainer", "(", ")", "->", "get", "(", "'librinfo_varieties.code_generator.species'", ")", ";", "if", "(", "!", "$", "generator", "->", "validate", "(", "$", "object", "->", "getCode", "(", ")", ")", ")", "{", "$", "errorElement", "->", "with", "(", "'code'", ")", "->", "addViolation", "(", "'Wrong species code format'", ")", "->", "end", "(", ")", ";", "}", "}" ]
Species code validator. @param ErrorElement $errorElement @param Species $object
[ "Species", "code", "validator", "." ]
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Admin/SpeciesAdmin.php#L39-L48
train