Пример #1
0
 /**
  * @return array[]
  */
 public function getNestedValues() : array
 {
     $values = [];
     foreach ($this->data->getIndexes($this->key) as $index) {
         $key = $this->key . '[' . $index . ']';
         if ($this->data->hasKey($key)) {
             $values[] = $this->data->getValue($key);
         }
     }
     return $values;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function bind(string $key, Data $data) : BindResult
 {
     if (!$data->hasKey($key)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.required'));
     }
     $value = $data->getValue($key);
     if (!is_numeric($value)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.float'));
     }
     return BindResult::fromValue($data->getValue($key));
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function bind(string $key, Data $data) : BindResult
 {
     if (!$data->hasKey($key)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.required'));
     }
     $value = $data->getValue($key);
     if (!preg_match('(^-?[1-9]*\\d+$)', $value)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.integer'));
     }
     return BindResult::fromValue((int) $data->getValue($key));
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function bind(string $key, Data $data) : BindResult
 {
     switch ($data->getValue($key, 'false')) {
         case 'true':
             return BindResult::fromValue(true);
         case 'false':
             return BindResult::fromValue(false);
     }
     return BindResult::fromFormErrors(new FormError($key, 'error.boolean'));
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function bind(string $key, Data $data) : BindResult
 {
     if (!$data->hasKey($key)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.required'));
     }
     $dateTime = DateTimeImmutable::createFromFormat('!Y-m-d', $data->getValue($key), $this->timeZone);
     if (false === $dateTime) {
         return BindResult::fromFormErrors(new FormError($key, 'error.date'));
     }
     return BindResult::fromValue($dateTime);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function bind(string $key, Data $data) : BindResult
 {
     if (!$data->hasKey($key)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.required'));
     }
     // Technically, seconds must always be present, according to the spec, but at least Chrome seems to ommit them.
     if (!preg_match('(^(?<hour>\\d{2}):(?<minute>\\d{2})(?::(?<second>\\d{2})(?:\\.(?<microsecond>\\d{1,6}))?)?$)', $data->getValue($key), $matches)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.time'));
     }
     return BindResult::fromValue(DateTimeImmutable::createFromFormat('!H:i:s.u', sprintf('%s:%s:%s.%s', $matches['hour'], $matches['minute'], $matches['second'] ?? '00', $matches['microsecond'] ?? '0'), $this->timeZone));
 }
Пример #7
0
 /**
  * {@inheritdoc}
  */
 public function bind(string $key, Data $data) : BindResult
 {
     if (!$data->hasKey($key)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.required'));
     }
     // Technically, seconds must always be present, according to the spec, but at least Chrome seems to ommit them.
     if (!preg_match('(^
             (?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})[Tt]
             (?<hour>\\d{2}):(?<minute>\\d{2})(?::(?<second>\\d{2})(?:\\.(?<microsecond>\\d{1,6}))?)?
             (?<timezone>[Zz]|[+-]\\d{2}:\\d{2})?
         $)x', $data->getValue($key), $matches)) {
         return BindResult::fromFormErrors(new FormError($key, 'error.date-time'));
     }
     return BindResult::fromValue(DateTimeImmutable::createFromFormat('!Y-m-d\\TH:i:s.u' . ($this->localTime ? '' : 'P'), sprintf('%s-%s-%sT%s:%s:%s.%s%s', $matches['year'], $matches['month'], $matches['day'], $matches['hour'], $matches['minute'], !empty($matches['second']) ? $matches['second'] : '00', !empty($matches['microsecond']) ? $matches['microsecond'] : '00', $matches['timezone'] ?? ''), $this->timeZone)->setTimezone($this->timeZone));
 }
Пример #8
0
 public function getField(string $key) : Field
 {
     return new Field($key, $this->data->getValue($key, ''), $this->errors->collect($key), $this->data);
 }