/** * Construct an instance of a Container. * * @param array $attributes * @param string|RenderableInterface|string[]|RenderableInterface[] $content */ public function __construct(array $attributes, $content) { $classes = []; $this->extraSmall = (int) Arr::dotGet($attributes, 'extraSmall', 0); $this->small = (int) Arr::dotGet($attributes, 'small', 0); $this->medium = (int) Arr::dotGet($attributes, 'medium', 0); $this->large = (int) Arr::dotGet($attributes, 'large', 0); if ($this->extraSmall > 0) { $classes[] = 'col-xs-' . $this->extraSmall; } if ($this->small > 0) { $classes[] = 'col-sm-' . $this->small; } if ($this->medium > 0) { $classes[] = 'col-md-' . $this->medium; } if ($this->large > 0) { $classes[] = 'col-lg-' . $this->large; } if (Arr::has($attributes, 'class')) { $classes[] = $attributes['class']; } $attributes['class'] = implode(' ', $classes); parent::__construct('div', $attributes, $content, false); }
/** * Parse each product in the response and add it to the rich response. * * @param SearchResponse $searchResponse * @param array $body */ protected function parseProducts(SearchResponse $searchResponse, array $body) { $factory = new SearchProductFactory(); $searchResponse->setSearchProducts(Std::map(function ($rawProduct) use($factory) { return $factory->makeFromArray($rawProduct); }, Arr::dotGet($body, 'searchCatalogs.result', []))); }
public function getReferenceSingle(HandlerResolverInterface $resolver, ConferenceContext $context, Request $request) { $taskName = $request->query->get('id'); $handler = $resolver->instantiate($taskName); $defaults = $handler->getDefaults(); $types = $handler->getTypes(); return new Card([], [new CardHeader([], 'Reference for task:'), new CardBlock([], [new HeaderOne(['class' => 'display-one'], $taskName), new Paragraph(['class' => 'lead'], $handler->getDescription())]), new SimpleTable(['Field Name', 'Type', 'Default', 'Description'], Std::map(function ($description, $field) use($types, $defaults) { return [$field, Arr::dotGet($types, $field, '-'), (string) Arr::dotGet($defaults, $field, '-'), $description]; }, $handler->getReference())), new CardBlock([], [new HeaderSix([], 'Example usage:'), new PreformattedText([], json_encode($defaults, JSON_PRETTY_PRINT))])]); }
/** * Build out the models for a relation. * * @param string $name * * @return Model|Collection */ protected function generateRelation($name) { $count = Arr::dotGet($this->relationsCount, $name, 1); if (!$this->relationsGenerators[$name] instanceof ModelGenerator) { return $this->relationsGenerators[$name]; } if ($count === 1) { return $this->relationsGenerators[$name]->make(); } return $this->relationsGenerators[$name]->makeMany($count); }
/** * Get the failed constrains for a specific field. * * Dot notation is supported. * * @param string $fieldName * * @return AbstractConstraint[] */ public function getFailedForField($fieldName) { return Arr::dotGet($this->failed, $fieldName); }
/** * @param string $key * @param mixed|null $default * * @return mixed */ public function get($key, $default = null) { return Arr::dotGet($this->content, $key, $default); }
/** * Get a method in this module by its name. * * @param string $methodName * * @return mixed */ public function getMethod($methodName) { return Arr::dotGet($this->getMethods(), $methodName); }
/** * @param string $key * * @return mixed */ public function getProperty($key) { return Arr::dotGet($this->getProperties(), $key); }
/** * Check that the spec matches and overlay help messaged. * * The resulting SpecResult instance should have more user-friendly * messages. This allows one to use Specs for validation on a website or * even an API. * * @param array $input * * @return SpecResult */ public function check(array $input) { $result = $this->spec->check($input); return new SpecResult($result->getMissing(), Arr::walkCopy($result->getFailed(), function ($key, $value, &$array, $path) { $array[$key] = Std::coalesce(Std::firstBias(Arr::dotGet($this->messages, Std::nonempty($path, $key)) !== null, [Arr::dotGet($this->messages, Std::nonempty($path, $key))], null), Std::firstBias($value instanceof AbstractConstraint, function () use($value) { return $value->getDescription(); }, null), Std::firstBias(is_array($value), function () use($value) { return array_map(function (AbstractConstraint $item) { return $item->getDescription(); }, $value); }, $value)); }, true, '', false), $result->getStatus()); }