コード例 #1
0
ファイル: Spec.php プロジェクト: chromabits/nucleus
 /**
  * Get all the constraints for a single field.
  *
  * @param string $fieldName
  *
  * @return Iterable
  */
 public function getFieldConstraints($fieldName)
 {
     $maybeConstraints = $this->annotations->lookupIn([$fieldName, static::ANNOTATION_CONSTRAINTS]);
     if ($maybeConstraints->isNothing()) {
         return ArrayList::zero();
     }
     $constraints = Maybe::fromJust($maybeConstraints);
     if (is_array($constraints)) {
         return ArrayList::of($constraints);
     } elseif ($constraints instanceof Iterable) {
         return $constraints;
     }
     return ArrayList::of([$constraints]);
 }
コード例 #2
0
ファイル: ArrayListTest.php プロジェクト: chromabits/nucleus
 public function testZero()
 {
     $instance = ArrayList::zero();
     $this->assertEquals([], $instance->toArray());
 }
コード例 #3
0
ファイル: SpecFactory.php プロジェクト: chromabits/nucleus
 /**
  * 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;
 }