Beispiel #1
0
 /**
  * Escape the provided string.
  *
  * @param SafeHtmlWrapper|SafeHtmlProducerInterface|string $string
  *
  * @throws CoreException
  * @throws InvalidArgumentException
  * @return SafeHtmlWrapper|string
  */
 public static function escape($string)
 {
     Arguments::define(Boa::either(Boa::either(Boa::instance(SafeHtmlWrapper::class), Boa::instance(SafeHtmlProducerInterface::class)), Boa::string()))->check($string);
     if ($string instanceof SafeHtmlWrapper) {
         return $string;
     } elseif ($string instanceof SafeHtmlProducerInterface) {
         $result = $string->getSafeHtml();
         if ($result instanceof SafeHtmlWrapper) {
             return $result;
         } elseif ($result instanceof SafeHtmlProducerInterface) {
             return static::escape($result);
         }
         throw new CoreException(vsprintf('Object of class %s implements SafeHtmlProducerInterface' . ' but it returned an unsafe type: %s', [get_class($string), TypeHound::fetch($result)]));
     }
     return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
 }
 /**
  * Add a offer to the response.
  *
  * @param string $type
  * @param string $condition
  * @param Offer $offer
  *
  * @throws InvalidArgumentException
  */
 public function addOffer($type, $condition, Offer $offer)
 {
     Arguments::contain(Boa::in(OfferType::getValues()), Boa::in(OfferCondition::getValues()), Boa::instance(Offer::class))->check($type, $condition, $offer);
     if ($type === OfferType::TYPE_FBA) {
         if ($condition === OfferCondition::CONDITION_NEW) {
             $this->fbaNewOffers[] = $offer;
         } elseif ($condition === OfferCondition::CONDITION_USED) {
             $this->fbaUsedOffers[] = $offer;
         }
     } elseif ($type === OfferType::TYPE_MERCHANT_FULFILLED) {
         if ($condition === OfferCondition::CONDITION_NEW) {
             $this->merchantNewOffers[] = $offer;
         } elseif ($condition === OfferCondition::CONDITION_USED) {
             $this->merchantUsedOffers[] = $offer;
         }
     }
 }
 /**
  * Set a relationship of the model explicitly.
  *
  * @param string $relationName
  * @param Model|Model[] $related
  *
  * @throws LackOfCoffeeException
  * @throws InvalidArgumentException
  * @return $this
  */
 public function withFixed($relationName, $related)
 {
     $inspector = $this->getInspector($this->getModelInstance());
     $relation = $inspector->getRelation($relationName);
     $relationModelClass = get_class($relation->getRelated());
     Arguments::contain(Boa::string(), Boa::either(Boa::instance($relationModelClass), Boa::arrOf(Boa::instance($relationModelClass))))->check($relationName, $related);
     $this->relations[$relationName] = $relation;
     $this->relationsGenerators[$relationName] = $related;
     return $this;
 }
Beispiel #4
0
 /**
  * @param RamlParameter[] $formParameters
  *
  * @return RamlBody
  */
 public function setFormParameters($formParameters)
 {
     Arguments::define(Boa::arrOf(Boa::instance(RamlParameter::class)))->check($formParameters);
     $new = clone $this;
     $new->formParameters = $formParameters;
     return $new;
 }
Beispiel #5
0
 /**
  * Add one or more constraints to a field.
  *
  * @param string $field
  * @param AbstractConstraint|AbstractConstraint[] $constraint
  *
  * @throws MismatchedArgumentTypesException
  * @return $this
  */
 public function let($field, $constraint)
 {
     Arguments::define(Boa::string(), Boa::either(Boa::instance(AbstractConstraint::class), Boa::arrOf(Boa::instance(AbstractConstraint::class))))->check($field, $constraint);
     if (!$this->constraints->member($field)) {
         $this->constraints = $this->constraints->insert($field, ArrayList::zero());
     }
     if (!is_array($constraint)) {
         $constraint = [$constraint];
     }
     $this->constraints = $this->constraints->insert($field, Maybe::fromMaybe(ArrayList::zero(), $this->constraints->lookup($field))->append(ArrayList::of($constraint)));
     return $this;
 }
Beispiel #6
0
 /**
  * A shortcut for building mocks.
  *
  * @param string $type
  * @param Closure|CallExpectation[] $definition
  *
  * @return $this
  */
 public function mock($type, $definition)
 {
     Arguments::define(Boa::string(), Boa::either(Boa::func(), Boa::arrOf(Boa::instance(CallExpectation::class))))->check($type, $definition);
     if (is_array($definition)) {
         $this->provide(static::expectationsToMock($type, $definition));
         return $this;
     }
     $this->provide(Mockery::mock($type, $definition));
     return $this;
 }