/** * Get an error instance * * @return sndsgd\field\Error */ public function getError() { $error = new Error($this->getMessage()); $error->setValue($this->value); if ($this->field !== null) { $error->setName($this->field->getName()); } if ($this->valueIndex !== null) { $error->setIndex($this->valueIndex); } return $error; }
/** * {@inheritdoc} */ public function __construct($name) { parent::__construct($name); $this->addRule(new FloatRule()); }
/** * {@inheritdoc} */ public function __construct($name) { parent::__construct($name); $this->addRules([new FloatRule(), new MinValueRule(-180), new MaxValueRule(180)]); }
/** * Define a field * * @param sndsgd\Field $field The field to define * @return sndsgd\field\Collection */ public function addField(Field $field) { $name = $field->getName(); if (array_key_exists($name, $this->fields)) { throw new DuplicateFieldNameException($name); } $this->fields[$name] = $field; foreach ($field->getAliases() as $alias) { if (array_key_exists($alias, $this->fieldAliases)) { throw new DuplicateFieldAliasException($alias); } $this->fieldAliases[$alias] = $name; } return $this; }
/** * Create usage instructions for a field * * @param sndsgd\Field $field * @return string */ private function createFieldUsage(Field $field) { $name = $field->getName(); $opts = array_merge(["--{$name}"], $field->getAliases()); $isBoolean = $field instanceof BooleanField; $hint = $field->getData('short-hint', $name); array_walk($opts, function (&$v) use($isBoolean, $hint) { $isName = substr($v, 0, 2) === '--'; if ($isName) { if (!$isBoolean) { $v .= '='; } } else { if (!$isName) { $v = "-{$v} "; } } if (!$isBoolean) { $v .= "<{$hint}>"; } $v = trim($v); }); $opts = implode('|', $opts); $isRequired = $field->hasRule('sndsgd\\field\\rule\\Required'); if (!$isRequired) { $opts = "[{$opts}]"; } return $opts; }
/** * {@inheritdoc} */ public function __construct($name) { parent::__construct($name); $this->addRules([new MaxValueCountRule(1), new BooleanRule()]); }
/** * {@inheritdoc} */ public function __construct($name) { parent::__construct($name); $this->addRule(new DateStringRule()); }