/** * @param mixed $source * @param string|\DateTimeZone|null $timezone * * @return Date|DateTime */ public static function from($source, $timezone = null) { if ($source === null) { return static::none(); } return parent::from($source, $timezone); }
/** * @inheritdoc */ public function cast_value($value, $type = null) { if ($value instanceof \DateTimeInterface) { $value = DateTime::from($value); return $value->utc->as_db; } if ($value === false) { return 0; } if ($value === true) { return 1; } return $value; }
/** * If the date returned by the parent is empty the method returns a date created from * {@link DEFAULT_EXPIRES}. * * @return DateTime|Headers\Date */ protected function get_expires() { $expires = parent::get_expires(); if (!$expires->is_empty) { return $expires; } return DateTime::from(self::DEFAULT_EXPIRES); }
/** * Parse the conditions for the {@link where()} and {@link having()} methods. * * {@link \DateTimeInterface} conditions are converted to strings. * * @return array An array made of the condition string and its arguments. */ private function deferred_parse_conditions() { $args = debug_backtrace(0, 2)[1]['args']; $conditions = array_shift($args); if (is_array($conditions)) { $c = ''; $conditions_args = []; foreach ($conditions as $column => $arg) { if (is_array($arg) || $arg instanceof self) { $joined = ''; if (is_array($arg)) { foreach ($arg as $value) { $joined .= ',' . (is_numeric($value) ? $value : $this->model->quote($value)); } $joined = substr($joined, 1); } else { $joined = (string) $arg; $conditions_args = array_merge($conditions_args, $arg->args); } $c .= ' AND `' . ($column[0] == '!' ? substr($column, 1) . '` NOT' : $column . '`') . ' IN(' . $joined . ')'; } else { $conditions_args[] = $arg; $c .= ' AND `' . ($column[0] == '!' ? substr($column, 1) . '` !' : $column . '` ') . '= ?'; } } $conditions = substr($c, 5); } else { $conditions_args = []; if ($args) { if (is_array($args[0])) { $conditions_args = $args[0]; } else { # # We dereference values otherwise the caller would get a corrupted array. # foreach ($args as $key => $value) { $conditions_args[$key] = $value; } } } } foreach ($conditions_args as &$value) { if ($value instanceof \DateTimeInterface) { $value = DateTime::from($value)->utc->as_db; } } return [$conditions ? '(' . $conditions . ')' : null, $conditions_args]; }
protected function validate(\ICanboogie\Errors $errors) { global $core; $email = $this->request['email']; if (!$email) { $errors['email'] = new FormattedString('The field %field is required!', array('%field' => 'Votre adresse E-Mail')); return false; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors['email'] = new FormattedString("Invalid email address: %email.", array('%email' => $email)); return false; } $user = $this->record; if (!$user) { $errors['email'] = new FormattedString("Unknown email address."); return false; } if ($user->language) { $core->locale = $user->language; } $expire_at = null; $ticket = $this->module->model->filter_by_uid($user->uid)->one; if ($ticket) { $expire_at = $ticket->expire_at; } if ($expire_at && time() + Module::FRESH_PERIOD - $expire_at->timestamp < Module::COOLOFF_DELAY) { throw new PermissionRequired(new FormattedString("nonce_login_request.operation.already_sent", array(':time' => DateTime::from('@' . ($expire_at->timestamp - Module::FRESH_PERIOD + Module::COOLOFF_DELAY), 'utc')->local->format('H:i'))), 403); } return true; }