*/ trait MethodAttribute { /** * * @var string */ private $method = 'POST'; /** * HTML method attribute of the tag * @return string */ public function method() { return $this->method; } /** * * @return boolean */ public function isPost() { return $this->method === 'POST'; } /** * * @return boolean */ public function isGet() { return $this->method === 'GET'; } /** * * @param string $newMethod * @return $this */ public function setMethod($newMethod) { self::checkMethod($newMethod); $this->method = self::normalizeMethod($newMethod); return $this; } protected function appendMethodAttribute(array & $attributes) { $attributes['method'] = $this->method; } public static function checkMethod($method) { if (!self::isCorrectMethod($method)) { throw new AttributeException('Incorrect method value: `' . strval($method) . '`'); } } public static function isCorrectMethod($method) { if (!is_string($method)) { return false; } $corrected = self::normalizeMethod($method); return $corrected === 'POST' || $corrected === 'GET'; } private static function normalizeMethod($method) { return strtoupper(trim($method)); } }