/** * @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; }
/** * {@inheritdoc} */ public function bind(string $key, Data $data) : BindResult { if (!$data->hasKey($key)) { return BindResult::fromFormErrors(new FormError($key, 'error.required')); } return BindResult::fromValue($data->getValue($key)); }
/** * {@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); }
/** * {@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)); }
/** * {@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((double) $data->getValue($key)); }
/** * {@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)); }
/** * {@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)); }