예제 #1
0
 /**
  * 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;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function __construct($name)
 {
     parent::__construct($name);
     $this->addRule(new FloatRule());
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function __construct($name)
 {
     parent::__construct($name);
     $this->addRules([new FloatRule(), new MinValueRule(-180), new MaxValueRule(180)]);
 }
예제 #4
0
 /**
  * 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;
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function __construct($name)
 {
     parent::__construct($name);
     $this->addRules([new MaxValueCountRule(1), new BooleanRule()]);
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function __construct($name)
 {
     parent::__construct($name);
     $this->addRule(new DateStringRule());
 }