示例#1
0
 /**
  * Attempt to set a field using the provided updater function.
  *
  * @param string $key
  * @param callable $updater
  * @param mixed|null $default
  *
  * @return static
  */
 public function update($key, callable $updater, $default = null)
 {
     return $this->insert($key, $updater(Maybe::fromMaybe($default, $this->lookup($key))));
 }
示例#2
0
 /**
  * Get the type annotation for a field.
  *
  * @param string $fieldName
  *
  * @return AbstractTypeConstraint
  */
 public function getFieldType($fieldName)
 {
     return Maybe::fromMaybe(Boa::any(), $this->getFieldAnnotation($fieldName, static::ANNOTATION_TYPE));
 }
示例#3
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;
 }
示例#4
0
 /**
  * @param string $fieldName
  *
  * @return bool
  */
 public function getFieldRequired($fieldName)
 {
     return Maybe::fromMaybe(false, $this->getFieldAnnotation($fieldName, static::ANNOTATION_REQUIRED));
 }
示例#5
0
 public function testFromMaybe()
 {
     $just = Maybe::of('doge');
     $nothing = Maybe::nothing();
     $this->assertEqualsMatrix([['doge', Maybe::fromMaybe('default', $just)], ['default', Maybe::fromMaybe('default', $nothing)]]);
 }