_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q242400
MessageParser.getMessage
validation
public function getMessage($attribute, $rule, $parameters) { $data = $this->fakeValidationData($attribute, $rule, $parameters); $message = $this->validator->getMessage($attribute, $rule); $message = $this->validator->makeReplacements($message, $attribute, $rule, $parameters); $this->validator->setData($data); return $message; }
php
{ "resource": "" }
q242401
MessageParser.fakeValidationData
validation
protected function fakeValidationData($attribute, $rule, $parameters) { $data = $this->validator->getData(); $this->fakeFileData($data, $attribute); $this->fakeRequiredIfData($data, $rule, $parameters); return $data; }
php
{ "resource": "" }
q242402
MessageParser.fakeRequiredIfData
validation
private function fakeRequiredIfData($data, $rule, $parameters) { if ($rule !== 'RequiredIf') { return; } $newData = $data; $newData[$parameters[0]] = $parameters[1]; $this->validator->setData($newData); }
php
{ "resource": "" }
q242403
MessageParser.fakeFileData
validation
private function fakeFileData($data, $attribute) { if (! $this->validator->hasRule($attribute, ['Mimes', 'Image'])) { return; } $newFiles = $data; $newFiles[$attribute] = $this->createUploadedFile(); $this->validator->setData($newFiles); }
php
{ "resource": "" }
q242404
Validator.validate
validation
public function validate($field, $parameters = []) { $attribute = $this->parseAttributeName($field); $validationParams = $this->parseParameters($parameters); $validationResult = $this->validateJsRemoteRequest($attribute, $validationParams); $this->throwValidationException($validationResult, $this->validator); }
php
{ "resource": "" }
q242405
Validator.throwValidationException
validation
protected function throwValidationException($result, $validator) { $response = new JsonResponse($result, 200); if ($result !== true && class_exists(ValidationException::class)) { throw new ValidationException($validator, $response); } throw new HttpResponseException($response); }
php
{ "resource": "" }
q242406
Validator.parseAttributeName
validation
protected function parseAttributeName($data) { parse_str($data, $attrParts); $attrParts = is_null($attrParts) ? [] : $attrParts; $newAttr = array_keys(array_dot($attrParts)); return array_pop($newAttr); }
php
{ "resource": "" }
q242407
Validator.parseParameters
validation
protected function parseParameters($parameters) { $newParams = ['validate_all' => false]; if (isset($parameters[0])) { $newParams['validate_all'] = ($parameters[0] === 'true') ? true : false; } return $newParams; }
php
{ "resource": "" }
q242408
Validator.validateJsRemoteRequest
validation
protected function validateJsRemoteRequest($attribute, $parameters) { $this->setRemoteValidation($attribute, $parameters['validate_all']); $validator = $this->validator; if ($validator->passes()) { return true; } return $validator->messages()->get($attribute); }
php
{ "resource": "" }
q242409
Validator.setRemoteValidation
validation
protected function setRemoteValidation($attribute, $validateAll = false) { $validator = $this->validator; $rules = $validator->getRules(); $rules = isset($rules[$attribute]) ? $rules[$attribute] : []; if (in_array('no_js_validation', $rules)) { $validator->setRules([$attribute => []]); return; } if (! $validateAll) { $rules = $this->purgeNonRemoteRules($rules, $validator); } $validator->setRules([$attribute => $rules]); }
php
{ "resource": "" }
q242410
Validator.purgeNonRemoteRules
validation
protected function purgeNonRemoteRules($rules, $validator) { $protectedValidator = $this->createProtectedCaller($validator); foreach ($rules as $i => $rule) { $parsedRule = ValidationRuleParser::parse([$rule]); if (! $this->isRemoteRule($parsedRule[0])) { unset($rules[$i]); } } return $rules; }
php
{ "resource": "" }
q242411
AccessProtectedTrait.createProtectedCaller
validation
protected function createProtectedCaller($instance) { $closure = function ($method, $args) { $callable = [$this, $method]; return call_user_func_array($callable, $args); }; return $closure->bindTo($instance, $instance); }
php
{ "resource": "" }
q242412
AccessProtectedTrait.getProtected
validation
protected function getProtected($instance, $property) { $closure = function ($property) { return $this->$property; }; $callback = $closure->bindTo($instance, $instance); return $callback($property); }
php
{ "resource": "" }
q242413
AccessProtectedTrait.callProtected
validation
protected function callProtected($instance, $method, $args = []) { if (! ($instance instanceof Closure)) { $instance = $this->createProtectedCaller($instance); } return call_user_func($instance, $method, $args); }
php
{ "resource": "" }
q242414
ValidatorHandler.setDelegatedValidator
validation
public function setDelegatedValidator(DelegatedValidator $validator) { $this->validator = $validator; $this->rules->setDelegatedValidator($validator); $this->messages->setDelegatedValidator($validator); }
php
{ "resource": "" }
q242415
ValidatorHandler.generateJavascriptValidations
validation
protected function generateJavascriptValidations() { $jsValidations = []; foreach ($this->validator->getRules() as $attribute => $rules) { if (! $this->jsValidationEnabled($attribute)) { continue; } $newRules = $this->jsConvertRules($attribute, $rules, $this->remote); $jsValidations = array_merge($jsValidations, $newRules); } return $jsValidations; }
php
{ "resource": "" }
q242416
ValidatorHandler.jsConvertRules
validation
protected function jsConvertRules($attribute, $rules, $includeRemote) { $jsRules = []; foreach ($rules as $rawRule) { list($rule, $parameters) = $this->validator->parseRule($rawRule); list($jsAttribute, $jsRule, $jsParams) = $this->rules->getRule($attribute, $rule, $parameters, $rawRule); if ($this->isValidatable($jsRule, $includeRemote)) { $jsRules[$jsAttribute][$jsRule][] = [$rule, $jsParams, $this->messages->getMessage($attribute, $rule, $parameters), $this->validator->isImplicit($rule), ]; } } return $jsRules; }
php
{ "resource": "" }
q242417
ValidatorHandler.sometimes
validation
public function sometimes($attribute, $rules = []) { $callback = function () { return true; }; $this->validator->sometimes($attribute, $rules, $callback); $this->rules->addConditionalRules($attribute, (array) $rules); }
php
{ "resource": "" }
q242418
JsValidatorFactory.make
validation
public function make(array $rules, array $messages = [], array $customAttributes = [], $selector = null) { $validator = $this->getValidatorInstance($rules, $messages, $customAttributes); return $this->validator($validator, $selector); }
php
{ "resource": "" }
q242419
JsValidatorFactory.getValidatorInstance
validation
protected function getValidatorInstance(array $rules, array $messages = [], array $customAttributes = []) { $factory = $this->app->make(ValidationFactory::class); $data = $this->getValidationData($rules, $customAttributes); $validator = $factory->make($data, $rules, $messages, $customAttributes); $validator->addCustomAttributes($customAttributes); return $validator; }
php
{ "resource": "" }
q242420
JsValidatorFactory.getValidationData
validation
protected function getValidationData(array $rules, array $customAttributes = []) { $attributes = array_filter(array_keys($rules), function ($attribute) { return $attribute !== '' && mb_strpos($attribute, '*') !== false; }); $attributes = array_merge(array_keys($customAttributes), $attributes); $data = array_reduce($attributes, function ($data, $attribute) { Arr::set($data, $attribute, true); return $data; }, []); return $data; }
php
{ "resource": "" }
q242421
JsValidatorFactory.formRequest
validation
public function formRequest($formRequest, $selector = null) { if (! is_object($formRequest)) { $formRequest = $this->createFormRequest($formRequest); } $rules = method_exists($formRequest, 'rules') ? $formRequest->rules() : []; $validator = $this->getValidatorInstance($rules, $formRequest->messages(), $formRequest->attributes()); return $this->validator($validator, $selector); }
php
{ "resource": "" }
q242422
JsValidatorFactory.createFormRequest
validation
protected function createFormRequest($class) { /* * @var $formRequest \Illuminate\Foundation\Http\FormRequest * @var $request Request */ list($class, $params) = $this->parseFormRequestName($class); $request = $this->app->__get('request'); $formRequest = $this->app->build($class, $params); if ($session = $request->getSession()) { $formRequest->setLaravelSession($session); } $formRequest->setUserResolver($request->getUserResolver()); $formRequest->setRouteResolver($request->getRouteResolver()); $formRequest->setContainer($this->app); $formRequest->query = $request->query; return $formRequest; }
php
{ "resource": "" }
q242423
JsValidatorFactory.jsValidator
validation
protected function jsValidator(Validator $validator, $selector = null) { $remote = ! $this->options['disable_remote_validation']; $view = $this->options['view']; $selector = is_null($selector) ? $this->options['form_selector'] : $selector; $delegated = new DelegatedValidator($validator, new ValidationRuleParserProxy()); $rules = new RuleParser($delegated, $this->getSessionToken()); $messages = new MessageParser($delegated); $jsValidator = new ValidatorHandler($rules, $messages); $manager = new JavascriptValidator($jsValidator, compact('view', 'selector', 'remote')); return $manager; }
php
{ "resource": "" }
q242424
JsValidatorFactory.getSessionToken
validation
protected function getSessionToken() { $token = null; if ($session = $this->app->__get('session')) { $token = $session->token(); } if ($encrypter = $this->app->__get('encrypter')) { $token = $encrypter->encrypt($token); } return $token; }
php
{ "resource": "" }
q242425
RemoteValidationMiddleware.wrapValidator
validation
protected function wrapValidator() { $resolver = new Resolver($this->factory); $this->factory->resolver($resolver->resolver($this->field)); $this->factory->extend(RemoteValidator::EXTENSION_NAME, $resolver->validatorClosure()); }
php
{ "resource": "" }
q242426
Resolver.resolver
validation
public function resolver($field) { return function ($translator, $data, $rules, $messages, $customAttributes) use ($field) { return $this->resolve($translator, $data, $rules, $messages, $customAttributes, $field); }; }
php
{ "resource": "" }
q242427
Resolver.resolve
validation
protected function resolve($translator, $data, $rules, $messages, $customAttributes, $field) { $validateAll = Arr::get($data, $field.'_validate_all', false); $validationRule = 'bail|'.Validator::EXTENSION_NAME.':'.$validateAll; $rules = [$field => $validationRule] + $rules; $validator = $this->createValidator($translator, $data, $rules, $messages, $customAttributes); return $validator; }
php
{ "resource": "" }
q242428
Resolver.createValidator
validation
protected function createValidator($translator, $data, $rules, $messages, $customAttributes) { if (is_null($this->resolver)) { return new BaseValidator($translator, $data, $rules, $messages, $customAttributes); } return call_user_func($this->resolver, $translator, $data, $rules, $messages, $customAttributes); }
php
{ "resource": "" }
q242429
Resolver.validatorClosure
validation
public function validatorClosure() { return function ($attribute, $value, $parameters, BaseValidator $validator) { $remoteValidator = new Validator($validator); $remoteValidator->validate($value, $parameters); return $attribute; }; }
php
{ "resource": "" }
q242430
RuleListTrait.isImplemented
validation
protected function isImplemented($rule) { return in_array($rule, $this->clientRules) || in_array($rule, $this->serverRules); }
php
{ "resource": "" }
q242431
RuleListTrait.isRemoteRule
validation
protected function isRemoteRule($rule) { return in_array($rule, $this->serverRules) || ! in_array($rule, $this->clientRules); }
php
{ "resource": "" }
q242432
Purifier.addCustomDefinition
validation
private function addCustomDefinition(array $definitionConfig, HTMLPurifier_Config $configObject = null) { if (!$configObject) { $configObject = HTMLPurifier_Config::createDefault(); $configObject->loadArray($this->getConfig()); } // Setup the custom definition $configObject->set('HTML.DefinitionID', $definitionConfig['id']); $configObject->set('HTML.DefinitionRev', $definitionConfig['rev']); // Enable debug mode if (!isset($definitionConfig['debug']) || $definitionConfig['debug']) { $configObject->set('Cache.DefinitionImpl', null); } // Start configuring the definition if ($def = $configObject->maybeGetRawHTMLDefinition()) { // Create the definition attributes if (!empty($definitionConfig['attributes'])) { $this->addCustomAttributes($definitionConfig['attributes'], $def); } // Create the definition elements if (!empty($definitionConfig['elements'])) { $this->addCustomElements($definitionConfig['elements'], $def); } } return $configObject; }
php
{ "resource": "" }
q242433
Purifier.addCustomAttributes
validation
private function addCustomAttributes(array $attributes, HTMLPurifier_HTMLDefinition $definition) { foreach ($attributes as $attribute) { // Get configuration of attribute $required = !empty($attribute[3]) ? true : false; $onElement = $attribute[0]; $attrName = $required ? $attribute[1] . '*' : $attribute[1]; $validValues = $attribute[2]; $definition->addAttribute($onElement, $attrName, $validValues); } return $definition; }
php
{ "resource": "" }
q242434
Purifier.addCustomElements
validation
private function addCustomElements(array $elements, HTMLPurifier_HTMLDefinition $definition) { foreach ($elements as $element) { // Get configuration of element $name = $element[0]; $contentSet = $element[1]; $allowedChildren = $element[2]; $attributeCollection = $element[3]; $attributes = isset($element[4]) ? $element[4] : null; if (!empty($attributes)) { $definition->addElement($name, $contentSet, $allowedChildren, $attributeCollection, $attributes); } else { $definition->addElement($name, $contentSet, $allowedChildren, $attributeCollection); } } }
php
{ "resource": "" }
q242435
RouteVoter.setRequest
validation
public function setRequest(Request $request) { @trigger_error(sprintf('The %s() method is deprecated since version 2.3 and will be removed in 3.0. Pass a RequestStack in the constructor instead.', __METHOD__), E_USER_DEPRECATED); $this->request = $request; }
php
{ "resource": "" }
q242436
MenuFactory.getExtensions
validation
private function getExtensions() { if (null === $this->sorted) { krsort($this->extensions); $this->sorted = !empty($this->extensions) ? call_user_func_array('array_merge', $this->extensions) : array(); } return $this->sorted; }
php
{ "resource": "" }
q242437
Renderer.renderHtmlAttribute
validation
protected function renderHtmlAttribute($name, $value) { if (true === $value) { return sprintf('%s="%s"', $name, $this->escape($name)); } return sprintf('%s="%s"', $name, $this->escape($value)); }
php
{ "resource": "" }
q242438
Renderer.htmlAttributesCallback
validation
private function htmlAttributesCallback($name, $value) { if (false === $value || null === $value) { return ''; } return ' '.$this->renderHtmlAttribute($name, $value); }
php
{ "resource": "" }
q242439
Renderer.escape
validation
protected function escape($value) { return $this->fixDoubleEscape(htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset)); }
php
{ "resource": "" }
q242440
Matcher.addVoter
validation
public function addVoter(VoterInterface $voter) { @trigger_error(sprintf('The %s() method is deprecated since version 2.3 and will be removed in 3.0. Pass voters in the constructor instead.', __METHOD__), E_USER_DEPRECATED); if ($this->voters instanceof \Traversable) { $this->voters = iterator_to_array($this->voters); } $this->voters[] = $voter; }
php
{ "resource": "" }
q242441
Helper.get
validation
public function get($menu, array $path = array(), array $options = array()) { if (!$menu instanceof ItemInterface) { if (null === $this->menuProvider) { throw new \BadMethodCallException('A menu provider must be set to retrieve a menu'); } $menuName = $menu; $menu = $this->menuProvider->get($menuName, $options); if (!$menu instanceof ItemInterface) { throw new \LogicException(sprintf('The menu "%s" exists, but is not a valid menu item object. Check where you created the menu to be sure it returns an ItemInterface object.', $menuName)); } } foreach ($path as $child) { $menu = $menu->getChild($child); if (null === $menu) { throw new \InvalidArgumentException(sprintf('The menu has no child named "%s"', $child)); } } return $menu; }
php
{ "resource": "" }
q242442
MenuExtension.isCurrent
validation
public function isCurrent(ItemInterface $item) { if (null === $this->matcher) { throw new \BadMethodCallException('The matcher must be set to get the breadcrumbs array'); } return $this->matcher->isCurrent($item); }
php
{ "resource": "" }
q242443
CoreExtension.buildItem
validation
public function buildItem(ItemInterface $item, array $options) { $item ->setUri($options['uri']) ->setLabel($options['label']) ->setAttributes($options['attributes']) ->setLinkAttributes($options['linkAttributes']) ->setChildrenAttributes($options['childrenAttributes']) ->setLabelAttributes($options['labelAttributes']) ->setCurrent($options['current']) ->setDisplay($options['display']) ->setDisplayChildren($options['displayChildren']) ; $this->buildExtras($item, $options); }
php
{ "resource": "" }
q242444
CoreExtension.buildExtras
validation
private function buildExtras(ItemInterface $item, array $options) { if (!empty($options['extras'])) { foreach ($options['extras'] as $key => $value) { $item->setExtra($key, $value); } } }
php
{ "resource": "" }
q242445
ListRenderer.renderChildren
validation
protected function renderChildren(ItemInterface $item, array $options) { // render children with a depth - 1 if (null !== $options['depth']) { $options['depth'] = $options['depth'] - 1; } if (null !== $options['matchingDepth'] && $options['matchingDepth'] > 0) { $options['matchingDepth'] = $options['matchingDepth'] - 1; } $html = ''; foreach ($item->getChildren() as $child) { $html .= $this->renderItem($child, $options); } return $html; }
php
{ "resource": "" }
q242446
ListRenderer.renderItem
validation
protected function renderItem(ItemInterface $item, array $options) { // if we don't have access or this item is marked to not be shown if (!$item->isDisplayed()) { return ''; } // create an array than can be imploded as a class list $class = (array) $item->getAttribute('class'); if ($this->matcher->isCurrent($item)) { $class[] = $options['currentClass']; } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) { $class[] = $options['ancestorClass']; } if ($item->actsLikeFirst()) { $class[] = $options['firstClass']; } if ($item->actsLikeLast()) { $class[] = $options['lastClass']; } if ($item->hasChildren() && $options['depth'] !== 0) { if (null !== $options['branch_class'] && $item->getDisplayChildren()) { $class[] = $options['branch_class']; } } elseif (null !== $options['leaf_class']) { $class[] = $options['leaf_class']; } // retrieve the attributes and put the final class string back on it $attributes = $item->getAttributes(); if (!empty($class)) { $attributes['class'] = implode(' ', $class); } // opening li tag $html = $this->format('<li'.$this->renderHtmlAttributes($attributes).'>', 'li', $item->getLevel(), $options); // render the text/link inside the li tag //$html .= $this->format($item->getUri() ? $item->renderLink() : $item->renderLabel(), 'link', $item->getLevel()); $html .= $this->renderLink($item, $options); // renders the embedded ul $childrenClass = (array) $item->getChildrenAttribute('class'); $childrenClass[] = 'menu_level_'.$item->getLevel(); $childrenAttributes = $item->getChildrenAttributes(); $childrenAttributes['class'] = implode(' ', $childrenClass); $html .= $this->renderList($item, $childrenAttributes, $options); // closing li tag $html .= $this->format('</li>', 'li', $item->getLevel(), $options); return $html; }
php
{ "resource": "" }
q242447
ListRenderer.renderLink
validation
protected function renderLink(ItemInterface $item, array $options = array()) { if ($item->getUri() && (!$item->isCurrent() || $options['currentAsLink'])) { $text = $this->renderLinkElement($item, $options); } else { $text = $this->renderSpanElement($item, $options); } return $this->format($text, 'link', $item->getLevel(), $options); }
php
{ "resource": "" }
q242448
MenuManipulator.moveToPosition
validation
public function moveToPosition(ItemInterface $item, $position) { $this->moveChildToPosition($item->getParent(), $item, $position); }
php
{ "resource": "" }
q242449
MenuManipulator.moveChildToPosition
validation
public function moveChildToPosition(ItemInterface $item, ItemInterface $child, $position) { $name = $child->getName(); $order = array_keys($item->getChildren()); $oldPosition = array_search($name, $order); unset($order[$oldPosition]); $order = array_values($order); array_splice($order, $position, 0, $name); $item->reorderChildren($order); }
php
{ "resource": "" }
q242450
MenuManipulator.slice
validation
public function slice(ItemInterface $item, $offset, $length = null) { $names = array_keys($item->getChildren()); if ($offset instanceof ItemInterface) { $offset = $offset->getName(); } if (!is_numeric($offset)) { $offset = array_search($offset, $names); } if (null !== $length) { if ($length instanceof ItemInterface) { $length = $length->getName(); } if (!is_numeric($length)) { $index = array_search($length, $names); $length = ($index < $offset) ? 0 : $index - $offset; } } $slicedItem = $item->copy(); $children = array_slice($slicedItem->getChildren(), $offset, $length); $slicedItem->setChildren($children); return $slicedItem; }
php
{ "resource": "" }
q242451
MenuManipulator.split
validation
public function split(ItemInterface $item, $length) { return array( 'primary' => $this->slice($item, 0, $length), 'secondary' => $this->slice($item, $length), ); }
php
{ "resource": "" }
q242452
MenuManipulator.callRecursively
validation
public function callRecursively(ItemInterface $item, $method, $arguments = array()) { call_user_func_array(array($item, $method), $arguments); foreach ($item->getChildren() as $child) { $this->callRecursively($child, $method, $arguments); } }
php
{ "resource": "" }
q242453
Utils.isTruthy
validation
public static function isTruthy($value) { if (!$value) { return $value === 0 || $value === '0'; } elseif ($value instanceof \stdClass) { return (bool) get_object_vars($value); } elseif ($value instanceof JmesPathableArrayInterface) { return Utils::isTruthy(iterator_to_array($value)); } elseif ($value instanceof JmesPathableObjectInterface) { return (bool) $value->toArray(); } else { return true; } }
php
{ "resource": "" }
q242454
Utils.type
validation
public static function type($arg) { $type = gettype($arg); if (isset(self::$typeMap[$type])) { return self::$typeMap[$type]; } elseif ($type === 'array') { if (empty($arg)) { return 'array'; } reset($arg); return key($arg) === 0 ? 'array' : 'object'; } elseif ($arg instanceof \stdClass) { return 'object'; } elseif ($arg instanceof JmesPathableObjectInterface) { return 'object'; } elseif ($arg instanceof \Closure) { return 'expression'; } elseif ($arg instanceof \ArrayAccess && $arg instanceof \Countable ) { return count($arg) == 0 || $arg->offsetExists(0) ? 'array' : 'object'; } elseif (method_exists($arg, '__toString')) { return 'string'; } throw new \InvalidArgumentException( 'Unable to determine JMESPath type from ' . get_class($arg) ); }
php
{ "resource": "" }
q242455
Utils.isObject
validation
public static function isObject($value) { if (is_array($value)) { return !$value || array_keys($value)[0] !== 0; } // Handle array-like values. Must be empty or offset 0 does not exist return $value instanceof \Countable && $value instanceof \ArrayAccess ? count($value) == 0 || !$value->offsetExists(0) : $value instanceof \stdClass || $value instanceof JmesPathableObjectInterface; }
php
{ "resource": "" }
q242456
Utils.isEqual
validation
public static function isEqual($a, $b) { if ($a === $b) { return true; } elseif ($a instanceof \stdClass) { return self::isEqual((array) $a, $b); } elseif ($b instanceof \stdClass) { return self::isEqual($a, (array) $b); } elseif ($a instanceof JmesPathableArrayInterface) { return Utils::isEqual(iterator_to_array($a), $b); } elseif ($b instanceof JmesPathableArrayInterface) { return Utils::isEqual($a, iterator_to_array($b)); } elseif ($a instanceof JmesPathableObjectInterface) { return Utils::isEqual($a->toArray(), $b); } elseif ($b instanceof JmesPathableObjectInterface) { return Utils::isEqual($a, $b->toArray()); } else { return false; } }
php
{ "resource": "" }
q242457
Utils.stableSort
validation
public static function stableSort(array $data, callable $sortFn) { // Decorate each item by creating an array of [value, index] array_walk($data, function (&$v, $k) { $v = [$v, $k]; }); // Sort by the sort function and use the index as a tie-breaker uasort($data, function ($a, $b) use ($sortFn) { return $sortFn($a[0], $b[0]) ?: ($a[1] < $b[1] ? -1 : 1); }); // Undecorate each item and return the resulting sorted array return array_map(function ($v) { return $v[0]; }, array_values($data)); }
php
{ "resource": "" }
q242458
Utils.slice
validation
public static function slice($value, $start = null, $stop = null, $step = 1) { if (!Utils::isArray($value) && !is_string($value)) { throw new \InvalidArgumentException('Expects string or array'); } return self::sliceIndices($value, $start, $stop, $step); }
php
{ "resource": "" }
q242459
BaseRestService.setConfig
validation
public function setConfig(array $configuration) { $this->config = Functions\arrayMergeDeep( $this->config, $this->resolver->resolveOptions($configuration) ); }
php
{ "resource": "" }
q242460
BaseRestService.debugRequest
validation
private function debugRequest($url, array $headers, $body) { $str = $url.PHP_EOL; $str .= array_reduce(array_keys($headers), function ($str, $key) use ($headers) { $str .= $key.': '.$headers[$key].PHP_EOL; return $str; }, ''); $str .= $body; $this->debug($str); }
php
{ "resource": "" }
q242461
FnDispatcher.validateSeq
validation
private function validateSeq($from, array $types, $a, $b) { $ta = Utils::type($a); $tb = Utils::type($b); if ($ta !== $tb) { $msg = "encountered a type mismatch in sequence: {$ta}, {$tb}"; $this->typeError($from, $msg); } $typeMatch = ($types && $types[0] == 'any') || in_array($ta, $types); if (!$typeMatch) { $msg = 'encountered a type error in sequence. The argument must be ' . 'an array of ' . implode('|', $types) . ' types. ' . "Found {$ta}, {$tb}."; $this->typeError($from, $msg); } }
php
{ "resource": "" }
q242462
FnDispatcher.reduce
validation
private function reduce($from, array $values, array $types, callable $reduce) { $i = -1; return array_reduce( $values, function ($carry, $item) use ($from, $types, $reduce, &$i) { if (++$i > 0) { $this->validateSeq($from, $types, $carry, $item); } return $reduce($carry, $item, $i); } ); }
php
{ "resource": "" }
q242463
FnDispatcher.wrapExpression
validation
private function wrapExpression($from, callable $expr, array $types) { list($fn, $pos) = explode(':', $from); $from = "The expression return value of argument {$pos} of {$fn}"; return function ($value) use ($from, $expr, $types) { $value = $expr($value); $this->validateType($from, $value, $types); return $value; }; }
php
{ "resource": "" }
q242464
UriResolver.resolve
validation
public function resolve($uri, $version, $resource, array $paramDefs, array $paramValues) { foreach ($paramValues as $param => $value) { if (!array_key_exists($param, $paramDefs)) { throw new \InvalidArgumentException("Unknown uri parameter \"$param\" provided"); } } foreach ($paramDefs as $key => $def) { if (!isset($paramValues[$key])) { if (isset($def['default'])) { $paramValues[$key] = is_callable($def['default']) ? $def['default']($paramValues) : $def['default']; } elseif (empty($def['required'])) { continue; } else { $this->throwRequired($paramDefs, $paramValues); } } $this->checkType($def['valid'], $key, $paramValues[$key]); if (isset($def['fn'])) { $def['fn']($paramValues[$key], $paramValues); } } return ( "$uri/". "$version/". $this->fillPathParams($resource, $paramValues). $this->buildQueryParameters($paramValues) ); }
php
{ "resource": "" }
q242465
UriResolver.fillPathParams
validation
private function fillPathParams($uri, array &$paramValues) { return preg_replace_callback('/{(\S+)}/U', function ($matches) use (&$paramValues) { $path = $matches[1]; if (array_key_exists($path, $paramValues)) { $value = $paramValues[$path]; unset($paramValues[$path]); } else { $value = $path; } return $value; }, $uri); }
php
{ "resource": "" }
q242466
UriResolver.buildQueryParameters
validation
private function buildQueryParameters(array $paramValues) { if (empty($paramValues)) { return ''; } $query = []; foreach ($paramValues as $param => $value) { if (is_array($value)) { $value = join(',', $value); } elseif (is_bool($value)) { $value = $value ? 'true' : 'false'; } elseif (is_callable($value)) { $value = $value(); } $query[] = $param.'='.urlencode($value); } return '?'.join('&', $query); }
php
{ "resource": "" }
q242467
Lexer.inside
validation
private function inside(array &$chars, $delim, $type) { $position = key($chars); $current = next($chars); $buffer = ''; while ($current !== $delim) { if ($current === '\\') { $buffer .= '\\'; $current = next($chars); } if ($current === false) { // Unclosed delimiter return [ 'type' => self::T_UNKNOWN, 'value' => $buffer, 'pos' => $position ]; } $buffer .= $current; $current = next($chars); } next($chars); return ['type' => $type, 'value' => $buffer, 'pos' => $position]; }
php
{ "resource": "" }
q242468
Lexer.parseJson
validation
private function parseJson(array $token) { $value = json_decode($token['value'], true); if ($error = json_last_error()) { // Legacy support for elided quotes. Try to parse again by adding // quotes around the bad input value. $value = json_decode('"' . $token['value'] . '"', true); if ($error = json_last_error()) { $token['type'] = self::T_UNKNOWN; return $token; } } $token['value'] = $value; return $token; }
php
{ "resource": "" }
q242469
Parser.parse
validation
public function parse($expression) { $this->expression = $expression; $this->tokens = $this->lexer->tokenize($expression); $this->tpos = -1; $this->next(); $result = $this->expr(); if ($this->token['type'] === T::T_EOF) { return $result; } throw $this->syntax('Did not reach the end of the token stream'); }
php
{ "resource": "" }
q242470
Parser.expr
validation
private function expr($rbp = 0) { $left = $this->{"nud_{$this->token['type']}"}(); while ($rbp < self::$bp[$this->token['type']]) { $left = $this->{"led_{$this->token['type']}"}($left); } return $left; }
php
{ "resource": "" }
q242471
ConfigurationResolver.resolve
validation
public function resolve(array $configuration) { foreach ($this->definitions as $key => $def) { if (!isset($configuration[$key])) { if (isset($def['default'])) { $configuration[$key] = is_callable($def['default']) ? $def['default']($configuration) : $def['default']; } elseif (empty($def['required'])) { continue; } else { $this->throwRequired($configuration); } } $this->checkType($def['valid'], $key, $configuration[$key]); if (isset($def['fn'])) { $def['fn']($configuration[$key], $configuration); } } return $configuration; }
php
{ "resource": "" }
q242472
ConfigurationResolver.resolveOptions
validation
public function resolveOptions(array $configuration) { foreach ($configuration as $key => $value) { if (isset($this->definitions[$key])) { $def = $this->definitions[$key]; $this->checkType($def['valid'], $key, $value); if (isset($def['fn'])) { $def['fn']($configuration[$key], $configuration); } } } return $configuration; }
php
{ "resource": "" }
q242473
RepeatableType.offsetSet
validation
public function offsetSet($offset, $value) { self::ensurePropertyType($value); if (is_null($offset)) { $this->data[] = $value; } else { $this->data[$offset] = $value; } }
php
{ "resource": "" }
q242474
RepeatableType.ensurePropertyType
validation
private function ensurePropertyType($value) { $actualType = gettype($value); if ('object' === $actualType) { $actualType = get_class($value); } $valid = explode('|', $this->expectedType); $isValid = false; foreach ($valid as $check) { if ($check !== 'any' && \DTS\eBaySDK\checkPropertyType($check)) { if ($check === $actualType) { return; } $isValid = false; } else { $isValid = true; } } if (!$isValid) { throw new Exceptions\InvalidPropertyTypeException($this->property, $this->expectedType, $actualType); } }
php
{ "resource": "" }
q242475
BaseType.toXml
validation
private function toXml($elementName, $rootElement = false) { return sprintf( '%s<%s%s%s>%s</%s>', $rootElement ? "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" : '', $elementName, $this->attributesToXml(), array_key_exists(get_class($this), self::$xmlNamespaces) ? sprintf(' %s', self::$xmlNamespaces[get_class($this)]) : '', $this->propertiesToXml(), $elementName ); }
php
{ "resource": "" }
q242476
BaseType.elementMeta
validation
public function elementMeta($elementName) { $class = get_class($this); if (array_key_exists($elementName, self::$properties[$class])) { $info = self::$properties[$class][$elementName]; $nameKey = $info['attribute'] ? 'attributeName' : 'elementName'; if (array_key_exists($nameKey, $info)) { if ($info[$nameKey] === $elementName) { $meta = new \stdClass(); $meta->propertyName = $elementName; $meta->phpType = $info['type']; $meta->repeatable = $info['repeatable']; $meta->attribute = $info['attribute']; $meta->elementName = $info[$nameKey]; $meta->strData = ''; return $meta; } } } return null; }
php
{ "resource": "" }
q242477
BaseType.attachment
validation
public function attachment($data = null, $mimeType = 'application/octet-stream') { if ($data !== null) { if (is_array($data)) { $this->attachment['data'] = array_key_exists('data', $data) ? $data['data'] : null; $this->attachment['mimeType'] = array_key_exists('mimeType', $data) ? $data['mimeType'] : 'application/octet-stream'; } else { $this->attachment['data'] = $data; $this->attachment['mimeType'] = $mimeType; } } return $this->attachment; }
php
{ "resource": "" }
q242478
BaseType.set
validation
private function set($class, $name, $value) { self::ensurePropertyExists($class, $name); self::ensurePropertyType($class, $name, $value); $this->setValue($class, $name, $value); }
php
{ "resource": "" }
q242479
BaseType.ensurePropertyType
validation
private static function ensurePropertyType($class, $name, $value) { $isValid = false; $info = self::propertyInfo($class, $name); $actualType = self::getActualType($value); $valid = explode('|', $info['type']); foreach ($valid as $check) { if ($check !== 'any' && \DTS\eBaySDK\checkPropertyType($check)) { if ($check === $actualType || 'array' === $actualType) { return; } $isValid = false; } else { $isValid = true; } } if (!$isValid) { $expectedType = $info['type']; throw new Exceptions\InvalidPropertyTypeException($name, $expectedType, $actualType); } }
php
{ "resource": "" }
q242480
BaseType.getActualType
validation
private static function getActualType($value) { $actualType = gettype($value); if ('object' === $actualType) { $actualType = get_class($value); } return $actualType; }
php
{ "resource": "" }
q242481
BaseType.propertyToXml
validation
private static function propertyToXml($name, $value) { if (is_subclass_of($value, '\DTS\eBaySDK\Types\BaseType', false)) { return $value->toXml($name); } else { return sprintf('<%s>%s</%s>', $name, self::encodeValueXml($value), $name); } }
php
{ "resource": "" }
q242482
BaseType.encodeValueXml
validation
private static function encodeValueXml($value) { if ($value instanceof \DateTime) { return $value->format('Y-m-d\TH:i:s.000\Z'); } elseif (is_bool($value)) { return $value ? 'true' : 'false'; } else { return htmlspecialchars($value, ENT_QUOTES, 'UTF-8', true); } }
php
{ "resource": "" }
q242483
BaseType.determineActualValueToAssign
validation
private static function determineActualValueToAssign($class, $property, $value) { if (!array_key_exists($property, self::$properties[$class])) { return $value; } $info = self::propertyInfo($class, $property); if ($info['repeatable'] && is_array($value)) { $values = []; foreach ($value as $val) { $values[] = self::actualValue($info, $val); } return $values; } return self::actualValue($info, $value); }
php
{ "resource": "" }
q242484
BaseType.actualValue
validation
private static function actualValue(array $info, $value) { /** * Shortcut. Objects can be assigned as is. */ if (is_object($value)) { return $value; } $types = explode('|', $info['type']); foreach ($types as $type) { switch ($type) { case 'integer': case 'string': case 'double': case 'boolean': case 'any': return $value; case 'DateTime': return new \DateTime($value, new \DateTimeZone('UTC')); } } return new $info['type']($value); }
php
{ "resource": "" }
q242485
CredentialsProvider.memoize
validation
public static function memoize(callable $provider) { return function () use ($provider) { static $result; static $isConstant; if ($isConstant) { return $result; } $isConstant = true; return $result = $provider(); }; }
php
{ "resource": "" }
q242486
CredentialsProvider.chain
validation
public static function chain() { $providers = func_get_args(); if (empty($providers)) { throw new \InvalidArgumentException('No providers in chain'); } return function () use ($providers) { $provider = array_shift($providers); $credentials = $provider(); while (($provider = array_shift($providers)) && !($credentials instanceof Credentials) ) { $credentials = $provider(); } return $credentials; }; }
php
{ "resource": "" }
q242487
CredentialsProvider.env
validation
public static function env() { return function () { $appId = getenv(self::ENV_APP_ID); $certId = getenv(self::ENV_CERT_ID); $devId = getenv(self::ENV_DEV_ID); if ($appId && $certId && $devId) { return new Credentials($appId, $certId, $devId); } else { return new \InvalidArgumentException( 'Could not find environment variable ' . 'credentials in '. self::ENV_APP_ID . '/' . self::ENV_CERT_ID . '/' . self::ENV_DEV_ID ); } }; }
php
{ "resource": "" }
q242488
CredentialsProvider.ini
validation
public static function ini($profile = null, $filename = null) { $filename = $filename ?: (self::getHomeDir() . '/.ebay_sdk/credentials'); $profile = $profile ?: (getenv(self::ENV_PROFILE) ?: 'default'); return function () use ($filename, $profile) { if (!is_readable($filename)) { return new \InvalidArgumentException("Cannot read credentials from $filename"); } $data = parse_ini_file($filename, true); if ($data === false) { return new \InvalidArgumentException("Invalid credentials file $filename"); } if (!isset($data[$profile])) { return new \InvalidArgumentException("'$profile' not found in credentials file"); } if (!isset($data[$profile]['ebay_app_id']) || !isset($data[$profile]['ebay_cert_id']) || !isset($data[$profile]['ebay_dev_id'])) { return new \InvalidArgumentException("No credentials present in INI profile '$profile' ($filename)"); } return new Credentials( $data[$profile]['ebay_app_id'], $data[$profile]['ebay_cert_id'], $data[$profile]['ebay_dev_id'] ); }; }
php
{ "resource": "" }
q242489
CredentialsProvider.getHomeDir
validation
private static function getHomeDir() { // Linux/Unix-like systems. if ($homeDir = getenv('HOME')) { return $homeDir; } $homeDrive = getenv('HOMEDRIVE'); $homePath = getenv('HOMEPATH'); return ($homeDrive && $homePath) ? $homeDrive . $homePath : null; }
php
{ "resource": "" }
q242490
Sdk.createService
validation
public function createService($namespace, array $config = []) { $configuration = $this->config; if (isset($this->config[$namespace])) { $configuration = arrayMergeDeep($configuration, $this->config[$namespace]); } $configuration = arrayMergeDeep($configuration, $config); $service = "DTS\\eBaySDK\\{$namespace}\\Services\\{$namespace}Service"; return new $service($configuration); }
php
{ "resource": "" }
q242491
XmlParser.parse
validation
public function parse($xml) { $parser = xml_parser_create_ns('UTF-8', '@'); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_set_object($parser, $this); xml_set_element_handler($parser, 'startElement', 'endElement'); xml_set_character_data_handler($parser, 'cdata'); xml_parse($parser, $xml, true); xml_parser_free($parser); return $this->rootObject; }
php
{ "resource": "" }
q242492
XmlParser.startElement
validation
private function startElement($parser, $name, array $attributes) { $this->metaStack->push($this->getPhpMeta($this->normalizeElementName($name), $attributes)); }
php
{ "resource": "" }
q242493
XmlParser.normalizeElementName
validation
private function normalizeElementName($name) { $nsElement = explode('@', $name); if (count($nsElement) > 1) { array_shift($nsElement); return $nsElement[0]; } else { return $name; } }
php
{ "resource": "" }
q242494
XmlParser.newPhpObject
validation
private function newPhpObject(\stdClass $meta) { $phpTypes = explode('|', $meta->phpType); foreach ($phpTypes as $phpType) { switch ($phpType) { case 'integer': case 'string': case 'double': case 'boolean': case 'DateTime': continue; default: return $meta->phpType !== '' ? new $phpType() : null; } } return null; }
php
{ "resource": "" }
q242495
XmlParser.isSimplePhpType
validation
private function isSimplePhpType(\stdClass $meta) { $phpTypes = explode('|', $meta->phpType); foreach ($phpTypes as $phpType) { switch ($phpType) { case 'integer': case 'string': case 'double': case 'boolean': case 'DateTime': continue; default: return false; } } return true; }
php
{ "resource": "" }
q242496
XmlParser.getValueToAssignToValue
validation
private function getValueToAssignToValue(\stdClass $meta) { if (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\Base64BinaryType', false)) { return $meta->strData; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\BooleanType', false)) { return strtolower($meta->strData) === 'true'; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\DecimalType', false)) { return is_int(0 + $meta->strData) ? (integer)$meta->strData : (double)$meta->strData; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\DoubleType', false)) { return (double)$meta->strData; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\IntegerType', false)) { return (integer)$meta->strData; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\StringType', false)) { return $meta->strData; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\TokenType', false)) { return $meta->strData; } elseif (is_subclass_of($meta->phpObject, '\DTS\eBaySDK\Types\URIType', false)) { return $meta->strData; } return $meta->strData; }
php
{ "resource": "" }
q242497
Env.search
validation
public static function search($expression, $data) { static $runtime; if (!$runtime) { $runtime = Env::createRuntime(); } return $runtime($expression, $data); }
php
{ "resource": "" }
q242498
Env.createRuntime
validation
public static function createRuntime() { switch ($compileDir = getenv(self::COMPILE_DIR)) { case false: return new AstRuntime(); case 'on': return new CompilerRuntime(); default: return new CompilerRuntime($compileDir); } }
php
{ "resource": "" }
q242499
TreeCompiler.makeVar
validation
private function makeVar($prefix) { if (!isset($this->vars[$prefix])) { $this->vars[$prefix] = 0; return '$' . $prefix; } return '$' . $prefix . ++$this->vars[$prefix]; }
php
{ "resource": "" }