Пример #1
0
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * Make some assertions on whether this response is valid and successful.
  * Throws an exception if it's not.
  *
  * @param array $body
  *
  * @throws EmptyResultsException
  * @throws InvalidFormatException
  */
 protected function assertIsSuccessful(array $body)
 {
     if (Arr::has($body, 'Error')) {
         throw new EmptyResultsException('Got error: ' . $body['Error']);
     }
     if (!Arr::has($body, 'searchCatalogs')) {
         throw new InvalidFormatException('The `searchCatalogs` property is missing from the' . ' response.');
     }
 }
Пример #4
0
 /**
  * Construct an instance of a Row.
  *
  * @param array $attributes
  * @param \string[] $content
  * @param bool|false $fluid
  */
 public function __construct(array $attributes, $content, $fluid = false)
 {
     if (Arr::has($attributes, 'class')) {
         $attributes['class'] = implode(' ', ['row', $attributes['class']]);
     } else {
         $attributes['class'] = 'row';
     }
     parent::__construct('div', $attributes, $content, false);
 }
Пример #5
0
 /**
  * @param int $code
  * @param RamlResponse $response
  *
  * @return RamlResponseGroup
  */
 public function addResponse($code, RamlResponse $response)
 {
     $new = clone $this;
     if (Arr::has($this->responses, $code)) {
         $new->responses[$code] = $this->responses[$code]->append($response);
         return $new;
     }
     $new->responses[$code] = $response;
     return $new;
 }
Пример #6
0
 /**
  * Construct an instance of a Container.
  *
  * @param array $attributes
  * @param \string[] $content
  * @param bool|false $fluid
  */
 public function __construct(array $attributes, $content, $fluid = false)
 {
     $this->fluid = $fluid;
     if (Arr::has($attributes, 'class')) {
         $attributes['class'] = implode(' ', [$this->fluid ? 'container-fluid' : 'container', $attributes['class']]);
     } else {
         $attributes['class'] = $this->fluid ? 'container-fluid' : 'container';
     }
     parent::__construct('div', $attributes, $content, false);
 }
 /**
  * Get the display name of a method.
  *
  * @param string $methodName
  *
  * @return string
  */
 public function getMethodName($methodName)
 {
     $propertyName = vsprintf('%sName', [$methodName]);
     if (property_exists($this, $propertyName)) {
         return $this->{$propertyName};
     }
     if (property_exists($this, 'methodNames') && Arr::has($this->methodNames, $methodName)) {
         return $this->methodNames[$methodName];
     }
     return 'Unknown';
 }
 /**
  * Build an entity from an properties array.
  *
  * @param array $input
  *
  * @return CategoryMapping
  */
 public function makeFromArray(array $input)
 {
     $mapping = new CategoryMapping();
     if (Arr::has($input, 'main')) {
         $mapping->setMainCategory($input['main']);
     }
     if (Arr::has($input, 'categoryId')) {
         $mapping->setCategoryId($input['categoryId']);
     }
     if (Arr::has($input, 'category')) {
         $mapping->setCategory($input['category']);
     }
     return $mapping;
 }
Пример #9
0
 /**
  * Attempt to encode a Spec into a JSON schema.
  *
  * @param Spec $spec
  * @param string $title
  *
  * @throws CoreException
  * @return string
  */
 public function encode(Spec $spec, $title = 'root')
 {
     $schema = ['$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $title, 'type' => CompoundTypes::COMPOUND_OBJECT, 'required' => $spec->getRequired()];
     $properties = [];
     foreach ($spec->getConstraints() as $key => $constraints) {
         $properties[$key] = $this->encodeConstraints($spec, $constraints, $key);
     }
     foreach ($spec->getDefaults() as $key => $default) {
         if (!Arr::has($properties, $key)) {
             $properties[$key] = [];
         }
         $properties[$key]['default'] = $default;
     }
     $schema['properties'] = $properties;
     return json_encode($schema, JSON_PRETTY_PRINT);
 }
Пример #10
0
 /**
  * Build an entity from an properties array.
  *
  * @param array $input
  *
  * @return FeesSet
  */
 public function makeFromArray(array $input)
 {
     $set = new FeesSet();
     $set->setPrice((double) $input['price']);
     $set->setRevenue((double) $input['revenue']);
     $set->setAmazonCommission((double) $input['azComm']);
     $set->setAmazonVar((double) $input['azVar']);
     $set->setFeesTotal((double) $input['feesTotal']);
     $set->setNetIncome((double) $input['netIncome']);
     $set->setCategory($input['category']);
     if (Arr::has($input, 'fbaWeight')) {
         $set->setFbaWeight((double) $input['fbaWeight']);
     }
     if (Arr::has($input, 'fbaPick')) {
         $set->setFbaPick((double) $input['fbaPick']);
     }
     if (Arr::has($input, 'fbaOrder')) {
         $set->setFbaOrder((double) $input['fbaOrder']);
     }
     return $set;
 }
 /**
  * Parse most properties from the response.
  *
  * @param FeesResponse $feesResponse
  * @param array $body
  *
  * @throws InvalidFormatException
  */
 protected function parseProperties(FeesResponse $feesResponse, array $body)
 {
     if (!Arr::has($body, 'data')) {
         throw new InvalidFormatException('The `data` property is missing from the response object.');
     }
     $data = $body['data'];
     $factory = new FeesSetFactory();
     if (Arr::has($data, 'sizeTier')) {
         $feesResponse->setSizeTier($data['sizeTier']);
     }
     if (Arr::has($data, 'fbaFees')) {
         $set = $factory->makeFromArray($data['fbaFees']);
         $set->setType(FeesSetType::TYPE_FBA);
         $feesResponse->setFbaFees($set);
     }
     if (Arr::has($data, 'mfnFees')) {
         $set = $factory->makeFromArray($data['mfnFees']);
         $set->setType(FeesSetType::TYPE_MERCHANT_FULFILLED);
         $feesResponse->setMerchantFees($set);
     }
 }
Пример #12
0
 /**
  * @param string $key
  *
  * @return bool
  */
 public function hasProperty($key)
 {
     return Arr::has($this->getProperties(), $key);
 }
Пример #13
0
 /**
  * Attempt to automatically mock the arguments of a function.
  *
  * @param ReflectionParameter[] $parameters
  * @param array $overrides
  *
  * @return array
  * @throws ResolutionException
  */
 protected function mockArguments(array $parameters, $overrides = [])
 {
     $resolved = [];
     foreach ($parameters as $parameter) {
         $hint = $parameter->getClass();
         $name = $parameter->getName();
         if (Arr::has($overrides, $name)) {
             $resolved[] = $overrides[$name];
             continue;
         }
         if (is_null($hint)) {
             throw new ResolutionException();
         }
         $mock = $this->resolveMock($hint);
         $resolved[] = $mock;
     }
     return $resolved;
 }
Пример #14
0
 /**
  * Get a RAML parameter definition from a Spec field.
  *
  * @param Spec $spec
  * @param string $field
  *
  * @return array
  */
 protected function specFieldToParameter(Spec $spec, $field)
 {
     $constraints = $spec->getConstraints();
     $defaults = $spec->getDefaults();
     $required = $spec->getRequired();
     $parameter = [];
     if (Arr::has($constraints, $field)) {
         $input = $constraints[$field];
         if (is_array($input) || $input instanceof Spec) {
             if ($input instanceof Spec) {
                 $input = [$input];
             }
             foreach ($input as $constraint) {
                 if ($constraint instanceof PrimitiveTypeConstraint) {
                     switch ($constraint->toString()) {
                         case ScalarTypes::SCALAR_STRING:
                             $parameter['type'] = 'string';
                             break;
                         case ScalarTypes::SCALAR_FLOAT:
                         case ScalarTypes::SCALAR_INTEGER:
                             $parameter['type'] = 'number';
                             break;
                         case ScalarTypes::SCALAR_BOOLEAN:
                             $parameter['type'] = 'boolean';
                             break;
                     }
                 }
             }
         }
     }
     if (Arr::has($defaults, $field)) {
         $parameter['default'] = $defaults[$field];
     }
     $parameter['required'] = in_array($field, $required);
     return $parameter;
 }
 /**
  * Assert that the response is valid and successful.
  *
  * @param array $body
  *
  * @throws InvalidFormatException
  */
 protected function assertIsSuccessful(array $body)
 {
     if (!Arr::has($body, 'categoryMappings')) {
         throw new InvalidFormatException('The `categoryMappings` property is missing from the response.');
     }
 }
Пример #16
0
 /**
  * Get a specific relationship by its name.
  *
  * @param string $name
  *
  * @throws LackOfCoffeeException
  * @return Relation
  */
 public function getRelation($name)
 {
     $relations = $this->discoverRelations();
     if (!Arr::has($relations, $name)) {
         throw new LackOfCoffeeException(vsprintf('The model does not declare a dependency named "%s".', [$name]));
     }
     return $relations[$name];
 }
Пример #17
0
 /**
  * Resolve a module by name.
  *
  * @param null $moduleName
  *
  * @throws ModuleNotFoundException
  * @return Module
  */
 protected function resolveModule($moduleName = null)
 {
     $selected = $moduleName;
     if ($moduleName === null) {
         $selected = static::DEFAULT_MODULE;
     }
     if (!Arr::has($this->modules, $selected)) {
         throw new ModuleNotFoundException($selected);
     }
     return $this->modules[$selected];
 }
Пример #18
0
 /**
  * Return whether or not a method exists in this module.
  *
  * @param string $methodName
  *
  * @return bool
  */
 public function hasMethod($methodName)
 {
     return Arr::has($this->getMethods(), $methodName);
 }
 /**
  * Parse extras array provided by the API.
  *
  * @param OffersResponse $offersResponse
  * @param array $body
  */
 protected function parseExtras(OffersResponse $offersResponse, array $body)
 {
     if (Arr::has($body, 'extras')) {
         $offersResponse->setExtras($body['extras']);
     }
 }