/** * @param $ramlResource * @param $ramlAction * @param $uriParameters * @param $resource * @param $method * @param Spec $spec * @param $reflector */ protected function addPostSchema(&$ramlResource, &$ramlAction, &$uriParameters, $resource, $method, Spec $spec, $reflector) { if (Arr::has($ramlAction, 'body')) { $ramlAction['body'] = []; } $parameters = $reflector->getMethodParameters($resource, $method); $fields = array_unique(array_merge(array_keys($spec->getConstraints()), array_keys($spec->getDefaults()), $spec->getRequired())); $specFields = []; foreach ($fields as $field) { if (in_array($field, $parameters)) { $uriParameters[$field] = $this->specFieldToParameter($spec, $field); continue; } $specFields[] = $field; } $filteredSpec = new Spec(Arr::only($spec->getConstraints(), $specFields), Arr::only($spec->getDefaults(), $specFields), Std::filter(function ($element) use($specFields) { return in_array($element, $specFields); }, $spec->getRequired())); $ramlAction['body']['schema'] = (new SpecSchemaEncoder())->encode($filteredSpec); }
/** * Get a copy of the provided array excluding the specified values. * * @param array $input * @param array $excluded * * @return array * @throws InvalidArgumentException */ public static function exceptValues(array $input, $excluded = []) { Arguments::define(Boa::arrOf(Boa::either(Boa::string(), Boa::integer())))->check($excluded); return Std::filter(function ($value, $_) use($excluded) { return !in_array($value, $excluded); }, $input); }
/** * Render the sidebar for this module. * * If null is returned, we won't display one. * * @param ConferenceContext $context * * @return SafeHtmlWrapper */ public function renderSidebar(ConferenceContext $context) { return Html::safe((new UnorderedList(['class' => 'nav nav-pills nav-stacked'], Std::map(function (Method $method, $methodName) use($context) { return new ListItem(['class' => 'nav-item'], [new Anchor(['href' => $context->method($this->getName(), $methodName), 'class' => 'nav-link'], Std::coalesce($method->getLabel(), $methodName))]); }, Std::filter(function (Method $method) { return !$method->isHidden(); }, $this->getMethods()))))->render()); }
/** * Get all the API ResourceFactories for this application. * * @return ResourceFactory[] */ public function getApiResources() { return Std::filter(function (ResourceFactory $resource) { foreach ($this->getApiPrefixes() as $prefix) { if (Str::beginsWith($resource->getPrefix(), $prefix)) { return true; } } return false; }, $this->getResources()); }
/** * Get all the relationships a model has with another model. * * An optional type containing the relation class name can be passed to * narrow down the search by relationship type (BelongsTo::class, etc). * * @param string $modelClass * @param null|string $type * * @return array|Relation[] */ public function getRelationsTo($modelClass, $type = null) { $relations = $this->discoverRelations(); $relations = Std::filter(function (Relation $relation) use($modelClass) { return get_class($relation->getRelated()) === $modelClass; }, $relations); if ($type !== null) { $relations = Std::filter(function (Relation $relation) use($type) { return get_class($relation) === $type; }, $relations); } return $relations; }
public function testFilter() { $odd = function ($item) { return $item % 2 != 0; }; $list = new SplDoublyLinkedList(); $list->push(1); $list->push(3); $list->push(4); $list->push(5); $this->assertEqualsMatrix([[[1, 3, 5], array_values(Std::filter($odd, [1, 3, 4, 5]))], [[1, 3, 5], array_values(Std::filter($odd, $list))]]); }