/** * Build an entity from an properties array. * * @param array $input * * @return BaseEntity */ public function makeFromArray(array $input) { $product = new SearchProduct(); $product->setCatalog(Arr::dotGet($input, 'catalog')); $product->setAsin(Arr::dotGet($input, 'productId')); $product->setEan(Arr::dotGet($input, 'ean')); $product->setName(Arr::dotGet($input, 'title')); $product->setImageUrl(Arr::dotGet($input, 'image')); $product->setType(Arr::dotGet($input, 'type')); $product->setWeight(Arr::dotGet($input, 'weight')); if (Arr::has($input, 'rank')) { $rank = $input['rank']; if (Arr::has($rank, 'Rank')) { $product->setRank($rank['Rank']); if (Arr::has($rank, 'rankings')) { // Populate rankings $product->setRankings(array_map(function ($ranking) { return new Ranking($ranking); }, $rank['rankings'])); } } else { $product->setRank(null); } if (Arr::has($rank, 'ProductCategoryId')) { $product->setCategoryId($rank['ProductCategoryId']); } else { $product->setCategoryId(null); } if (Arr::has($input, 'relationships')) { $relationships = new RelationshipBag($input['relationships']); $product->setRelationships($relationships); } } return $product; }
/** * Parse items out of a body * * @param array $body * * @return array */ protected function parseItems($body) { $items = Arr::dotGet($body, 'ItemSearchResponse.Items.Item', []); return array_map(function ($item) { return new Item($item); }, $items); }
/** * 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', []))); }
/** * Parse and build a rich response object from an HTTP response. * * @param ResponseInterface $response * * @return TokenResponse * @throws CoreException */ public function makeFromResponse(ResponseInterface $response) { $body = $this->parse($response); $tokenResponse = new TokenResponse(); $tokenResponse->setAccessToken(Arr::dotGet($body, 'access_token')); $tokenResponse->setRefreshToken(Arr::dotGet($body, 'refresh_token')); $tokenResponse->setExpiresIn(Arr::dotGet($body, 'expires_in')); $tokenResponse->setTokenType(Arr::dotGet($body, 'token_type')); $tokenResponse->setScope(Arr::dotGet($body, 'scope')); return $tokenResponse; }
/** * RelationshipBag constructor. * * @param array $relationships */ public function __construct(array $relationships) { $parents = Arr::dotGet($relationships, 'parents', []); $children = Arr::dotGet($relationships, 'children', []); if (is_array($parents) && !$this->isAssoc($parents)) { $this->setParents($parents); } if (is_array($children) && !$this->isAssoc($children)) { $this->setChildren($children); } }
/** * Parse and build a rich response object from an HTTP response. * * @param ResponseInterface $response * * @return BaseResponse * @throws WhoamiResponse */ public function makeFromResponse(ResponseInterface $response) { $body = $this->parse($response); $whoamiResponse = new WhoamiResponse(); $user = new User(); $user->fill(Arr::dotGet($body, 'user')); $whoamiResponse->setUser($user); $organization = new Organization(); $organization->fill(Arr::dotGet($body, 'organization')); $whoamiResponse->setOrganization($organization); return $whoamiResponse; }
/** * Parse and build a rich response object from an HTTP response. * * @param ResponseInterface $response * * @return SubscriptionResponse * @throws CoreException */ public function makeFromResponse(ResponseInterface $response) { $body = $this->parse($response); $subscriptionsResponse = new SubscriptionResponse(); $subscriptionsResponse->setSubscriptions(Std::map(function ($s) { $subscription = new Subscription(); // Maps from the new subscription format from SLAPP // to the legacy format. $subscription->fill(['id' => Arr::dotGet($s, 'stripe_plan.id'), 'plan_id' => $s['stripe_plan_id'], 'cycle_length' => sprintf('%s %s', Arr::dotGet($s, 'stripe_plan.interval_count'), Arr::dotGet($s, 'stripe_plan.interval')), 'created_at' => $s['current_period_start'], 'expires_at' => $s['current_period_end'], 'autorenew' => !$s['cancel_at_period_end'], 'cancelled_at' => $s['canceled_at'], 'status' => $s['status']]); return $subscription; }, Arr::dotGet($body, 'subscriptions', []))); return $subscriptionsResponse; }
/** * Get a method in this module by its name. * * @param string $methodName * * @return mixed */ public function getMethod($methodName) { return Arr::dotGet($this->getMethods(), $methodName); }
/** * 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); }
/** * 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); }
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))])]); }
/** * Safely get a key from the raw response * * @param string $key * @param mixed $default * * @return mixed */ protected function get($key, $default = null) { return Arr::dotGet($this->raw, $key, $default); }
/** * @param string $key * @param mixed|null $default * * @return mixed */ public function get($key, $default = null) { return Arr::dotGet($this->content, $key, $default); }
/** * Get an arbitrary attribute from this item attributes set. * * @param string $key * * @return mixed */ public function attr($key) { return Arr::dotGet($this->attributes, ucfirst($key)); }
/** * @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()); }