diff --git a/phalcon/Db/Column.zep b/phalcon/Db/Column.zep index 3331c3a49f6..0818f5d2e0a 100644 --- a/phalcon/Db/Column.zep +++ b/phalcon/Db/Column.zep @@ -356,12 +356,14 @@ class Column implements ColumnInterface */ if fetch scale, definition["scale"] { switch type { - - case self::TYPE_INTEGER: - case self::TYPE_FLOAT: + case self::TYPE_BIGINTEGER: case self::TYPE_DECIMAL: case self::TYPE_DOUBLE: - case self::TYPE_BIGINTEGER: + case self::TYPE_FLOAT: + case self::TYPE_INTEGER: + case self::TYPE_MEDIUMINTEGER: + case self::TYPE_SMALLINTEGER: + case self::TYPE_TINYINTEGER: let this->scale = scale; break; diff --git a/phalcon/Http/Request.zep b/phalcon/Http/Request.zep index 2925c71b387..88918dc6605 100644 --- a/phalcon/Http/Request.zep +++ b/phalcon/Http/Request.zep @@ -10,7 +10,6 @@ namespace Phalcon\Http; -use Phalcon\Collection\Collection; use Phalcon\DiInterface; use Phalcon\Filter\FilterInterface; use Phalcon\Http\Request\File; @@ -67,24 +66,11 @@ class Request implements RequestInterface, InjectionAwareInterface private rawBody; - /** - * @var Collection - */ - private server; - /** * @var bool */ private strictHostCheck = false; - /** - * Constructor - */ - public function __construct() - { - $this->init(); - } - /** * Gets a variable from the $_REQUEST superglobal applying filters if * needed. If no parameters are given the $_REQUEST superglobal is returned @@ -174,15 +160,15 @@ class Request implements RequestInterface, InjectionAwareInterface * Proxies uses this IP */ if trustForwardedHeader { - let address = this->server->get("HTTP_X_FORWARDED_FOR", null); + fetch address, _SERVER["HTTP_X_FORWARDED_FOR"]; if address === null { - let address = this->getServer("HTTP_CLIENT_IP"); + fetch address, _SERVER["HTTP_CLIENT_IP"]; } } if address === null { - let address = this->getServer("REMOTE_ADDR"); + fetch address, _SERVER["REMOTE_ADDR"]; } if typeof address != "string" { @@ -214,7 +200,13 @@ class Request implements RequestInterface, InjectionAwareInterface */ public function getContentType() -> string | null { - return this->server->get("CONTENT_TYPE", null); + var contentType; + + if !fetch contentType, _SERVER["CONTENT_TYPE"] { + return null; + } + + return contentType; } @@ -235,10 +227,9 @@ class Request implements RequestInterface, InjectionAwareInterface var digest, matches, match; array auth; - let auth = [], - digest = this->server->get("PHP_AUTH_DIGEST", null); + let auth = []; - if null !== digest { + if fetch digest, _SERVER["PHP_AUTH_DIGEST"] { let matches = []; if !preg_match_all("#(\\w+)=(['\"]?)([^'\" ,]+)\\2#", digest, matches, 2) { @@ -320,18 +311,18 @@ class Request implements RequestInterface, InjectionAwareInterface */ final public function getHeader(string! header) -> string { - var name; + var value, name; let name = strtoupper( strtr(header, "-", "_") ); - if this->hasServer(name) { - return this->getServer(name); + if fetch value, _SERVER[name] { + return value; } - if this->hasServer("HTTP_" . name) { - return this->getServer("HTTP_" . name); + if fetch value, _SERVER["HTTP_" . name] { + return value; } return ""; @@ -340,7 +331,7 @@ class Request implements RequestInterface, InjectionAwareInterface /** * Returns the available headers in the request * - * ```php + * * $_SERVER = [ * "PHP_AUTH_USER" => "phalcon", * "PHP_AUTH_PW" => "secret", @@ -349,11 +340,11 @@ class Request implements RequestInterface, InjectionAwareInterface * $headers = $request->getHeaders(); * * echo $headers["Authorization"]; // Basic cGhhbGNvbjpzZWNyZXQ= - * ``` + * */ public function getHeaders() -> array { - var authHeaders, name, server, value; + var name, value, authHeaders; array headers = []; @@ -363,9 +354,7 @@ class Request implements RequestInterface, InjectionAwareInterface "CONTENT_MD5": true ]; - let server = this->server->toArray(); - - for name, value in server { + for name, value in _SERVER { // Note: The starts_with uses case insensitive search here if starts_with(name, "HTTP_") { let name = ucwords( @@ -497,13 +486,19 @@ class Request implements RequestInterface, InjectionAwareInterface */ public function getHTTPReferer() -> string { - return this->server->get("HTTP_REFERER", ""); + var httpReferer; + + if !fetch httpReferer, _SERVER["HTTP_REFERER"] { + return ""; + } + + return httpReferer; } /** * Gets decoded JSON HTTP raw request body */ - public function getJsonRawBody(bool associative = false) -> | array | bool + public function getJsonRawBody(bool associative = false) -> <\stdClass> | array | bool { var rawBody; @@ -733,7 +728,13 @@ class Request implements RequestInterface, InjectionAwareInterface */ public function getServer(string! name) -> string | null { - return this->server->get(name, null); + var serverValue; + + if !fetch serverValue, _SERVER[name] { + return null; + } + + return serverValue; } /** @@ -741,7 +742,13 @@ class Request implements RequestInterface, InjectionAwareInterface */ public function getServerAddress() -> string { - return this->server->get("SERVER_NAME", gethostbyname("localhost")); + var serverAddr; + + if !fetch serverAddr, _SERVER["SERVER_ADDR"] { + return gethostbyname("localhost"); + } + + return serverAddr; } /** @@ -749,7 +756,13 @@ class Request implements RequestInterface, InjectionAwareInterface */ public function getServerName() -> string { - return this->server->get("SERVER_NAME", "localhost"); + var serverName; + + if !fetch serverName, _SERVER["SERVER_NAME"] { + return "localhost"; + } + + return serverName; } /** @@ -817,7 +830,13 @@ class Request implements RequestInterface, InjectionAwareInterface */ final public function getURI() -> string { - return this->server->get("REQUEST_URI", ""); + var requestURI; + + if !fetch requestURI, _SERVER["REQUEST_URI"] { + return ""; + } + + return requestURI; } /** @@ -825,7 +844,13 @@ class Request implements RequestInterface, InjectionAwareInterface */ public function getUserAgent() -> string { - return this->server->get("HTTP_USER_AGENT", ""); + var userAgent; + + if !fetch userAgent, _SERVER["HTTP_USER_AGENT"] { + return ""; + } + + return userAgent; } /** @@ -917,24 +942,7 @@ class Request implements RequestInterface, InjectionAwareInterface */ final public function hasServer(string! name) -> bool { - return this->server->has(name); - } - - /** - * Initializes the interal $_SERVER array. If no array is passed then it - * uses the $_SERVER superglobal - */ - public function init(array! data = []) - { - var server; - - if empty(data) { - let server = _SERVER; - } else { - let server = data; - } - - let this->server = new Collection(server); + return isset _SERVER[name]; } /** @@ -1337,7 +1345,7 @@ class Request implements RequestInterface, InjectionAwareInterface "request:beforeAuthorizationResolve", this, [ - "server": this->server->toArray() + "server": _SERVER ] ); @@ -1348,7 +1356,7 @@ class Request implements RequestInterface, InjectionAwareInterface if this->hasServer("PHP_AUTH_USER") && this->hasServer("PHP_AUTH_PW") { let headers["Php-Auth-User"] = this->getServer("PHP_AUTH_USER"), - headers["Php-Auth-Pw"] = this->getServer("PHP_AUTH_PW"); + headers["Php-Auth-Pw"] = this->getServer("PHP_AUTH_PW"); } else { if this->hasServer("HTTP_AUTHORIZATION") { let authHeader = this->getServer("HTTP_AUTHORIZATION"); @@ -1392,7 +1400,7 @@ class Request implements RequestInterface, InjectionAwareInterface this, [ "headers": headers, - "server": this->server->toArray() + "server": _SERVER ] ); diff --git a/tests/_data/fixtures/Traits/Db/MysqlTrait.php b/tests/_data/fixtures/Traits/Db/MysqlTrait.php index bd90161d98c..114abdcc573 100644 --- a/tests/_data/fixtures/Traits/Db/MysqlTrait.php +++ b/tests/_data/fixtures/Traits/Db/MysqlTrait.php @@ -15,6 +15,8 @@ use Phalcon\Db\Column; use Phalcon\Db\Index; use Phalcon\Db\Reference; +use function array_flip; +use function array_shift; trait MysqlTrait { @@ -71,7 +73,8 @@ protected function getExpectedColumns(): array $columns = $this->getColumns(); foreach ($columns as $index => $array) { - $result[$index] = Column::__set_state($array); + $name = array_shift($array); + $result[$index] = new Column($name, $array); } return $result; @@ -106,7 +109,6 @@ protected function getColumns(): array 'type' => Column::TYPE_BLOB, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -121,7 +123,6 @@ protected function getColumns(): array 'type' => Column::TYPE_BIT, 'isNumeric' => false, 'size' => 1, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -136,7 +137,6 @@ protected function getColumns(): array 'type' => Column::TYPE_BIT, 'isNumeric' => false, 'size' => 1, - 'scale' => 0, 'default' => "b'1'", 'unsigned' => false, 'notNull' => false, @@ -181,7 +181,6 @@ protected function getColumns(): array 'type' => Column::TYPE_BOOLEAN, 'isNumeric' => true, 'size' => 1, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -196,7 +195,6 @@ protected function getColumns(): array 'type' => Column::TYPE_BOOLEAN, 'isNumeric' => true, 'size' => 1, - 'scale' => 0, 'default' => 1, 'unsigned' => false, 'notNull' => false, @@ -211,7 +209,6 @@ protected function getColumns(): array 'type' => Column::TYPE_CHAR, 'isNumeric' => false, 'size' => 10, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -226,7 +223,6 @@ protected function getColumns(): array 'type' => Column::TYPE_CHAR, 'isNumeric' => false, 'size' => 10, - 'scale' => 0, 'default' => 'ABC', 'unsigned' => false, 'notNull' => false, @@ -271,7 +267,6 @@ protected function getColumns(): array 'type' => Column::TYPE_ENUM, 'isNumeric' => false, 'size' => "'xs','s','m','l','xl'", - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -316,7 +311,6 @@ protected function getColumns(): array 'type' => Column::TYPE_JSON, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -361,7 +355,6 @@ protected function getColumns(): array 'type' => Column::TYPE_DATE, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -376,7 +369,6 @@ protected function getColumns(): array 'type' => Column::TYPE_DATE, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => '2018-10-01', 'unsigned' => false, 'notNull' => false, @@ -391,7 +383,6 @@ protected function getColumns(): array 'type' => Column::TYPE_DATETIME, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -406,7 +397,6 @@ protected function getColumns(): array 'type' => Column::TYPE_DATETIME, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => '2018-10-01 12:34:56', 'unsigned' => false, 'notNull' => false, @@ -421,7 +411,6 @@ protected function getColumns(): array 'type' => Column::TYPE_TIME, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -436,7 +425,6 @@ protected function getColumns(): array 'type' => Column::TYPE_TIME, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => '12:34:56', 'unsigned' => false, 'notNull' => false, @@ -451,7 +439,6 @@ protected function getColumns(): array 'type' => Column::TYPE_TIMESTAMP, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -466,7 +453,6 @@ protected function getColumns(): array 'type' => Column::TYPE_TIMESTAMP, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => '2018-10-01 12:34:56', 'unsigned' => false, 'notNull' => false, @@ -571,7 +557,6 @@ protected function getColumns(): array 'type' => Column::TYPE_LONGTEXT, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -586,7 +571,6 @@ protected function getColumns(): array 'type' => Column::TYPE_MEDIUMTEXT, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -601,7 +585,6 @@ protected function getColumns(): array 'type' => Column::TYPE_TINYTEXT, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -616,7 +599,6 @@ protected function getColumns(): array 'type' => Column::TYPE_TEXT, 'isNumeric' => false, 'size' => 0, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -631,7 +613,6 @@ protected function getColumns(): array 'type' => Column::TYPE_VARCHAR, 'isNumeric' => false, 'size' => 10, - 'scale' => 0, 'default' => null, 'unsigned' => false, 'notNull' => false, @@ -646,7 +627,6 @@ protected function getColumns(): array 'type' => Column::TYPE_VARCHAR, 'isNumeric' => false, 'size' => 10, - 'scale' => 0, 'default' => 'D', 'unsigned' => false, 'notNull' => false, diff --git a/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php b/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php index ad20cb63e81..bcdd93f11d3 100644 --- a/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php +++ b/tests/_data/fixtures/Traits/Db/PostgresqlTrait.php @@ -12,8 +12,10 @@ namespace Phalcon\Test\Fixtures\Traits\Db; +use Phalcon\Db\Column; use Phalcon\Db\Index; use Phalcon\Db\Reference; +use function array_shift; trait PostgresqlTrait { @@ -70,7 +72,8 @@ protected function getExpectedColumns(): array $columns = $this->getColumns(); foreach ($columns as $index => $array) { - $result[$index] = Column::__set_state($array); + $name = array_shift($array); + $result[$index] = new Column($name, $array); } return $result; @@ -105,7 +108,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TEXT, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -120,7 +122,6 @@ protected function getColumns(): array '_type' => Column::TYPE_BIT, '_isNumeric' => false, '_size' => null, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -135,7 +136,6 @@ protected function getColumns(): array '_type' => Column::TYPE_BIT, '_isNumeric' => false, '_size' => null, - '_scale' => 0, '_default' => "B'1'::\"bit\"", '_unsigned' => false, '_notNull' => false, @@ -180,7 +180,6 @@ protected function getColumns(): array '_type' => Column::TYPE_BOOLEAN, '_isNumeric' => true, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -195,7 +194,6 @@ protected function getColumns(): array '_type' => Column::TYPE_BOOLEAN, '_isNumeric' => true, '_size' => 0, - '_scale' => 0, '_default' => 'true', '_unsigned' => false, '_notNull' => false, @@ -210,7 +208,6 @@ protected function getColumns(): array '_type' => Column::TYPE_CHAR, '_isNumeric' => false, '_size' => 10, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -225,7 +222,6 @@ protected function getColumns(): array '_type' => Column::TYPE_CHAR, '_isNumeric' => false, '_size' => 10, - '_scale' => 0, '_default' => 'ABC', '_unsigned' => false, '_notNull' => false, @@ -270,7 +266,6 @@ protected function getColumns(): array '_type' => Column::TYPE_VARCHAR, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -315,7 +310,6 @@ protected function getColumns(): array '_type' => Column::TYPE_JSON, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -360,7 +354,6 @@ protected function getColumns(): array '_type' => Column::TYPE_DATE, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -375,7 +368,6 @@ protected function getColumns(): array '_type' => Column::TYPE_DATE, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => '2018-10-01', '_unsigned' => false, '_notNull' => false, @@ -390,7 +382,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TIMESTAMP, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -405,7 +396,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TIMESTAMP, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => '2018-10-01 12:34:56', '_unsigned' => false, '_notNull' => false, @@ -420,7 +410,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TIME, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -435,7 +424,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TIME, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => '12:34:56', '_unsigned' => false, '_notNull' => false, @@ -450,7 +438,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TIMESTAMP, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -465,7 +452,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TIMESTAMP, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => '2018-10-01 12:34:56', '_unsigned' => false, '_notNull' => false, @@ -570,7 +556,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TEXT, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -585,7 +570,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TEXT, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -600,7 +584,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TEXT, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -615,7 +598,6 @@ protected function getColumns(): array '_type' => Column::TYPE_TEXT, '_isNumeric' => false, '_size' => 0, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -630,7 +612,6 @@ protected function getColumns(): array '_type' => Column::TYPE_VARCHAR, '_isNumeric' => false, '_size' => 10, - '_scale' => 0, '_default' => null, '_unsigned' => false, '_notNull' => false, @@ -645,7 +626,6 @@ protected function getColumns(): array '_type' => Column::TYPE_VARCHAR, '_isNumeric' => false, '_size' => 10, - '_scale' => 0, '_default' => 'D', '_unsigned' => false, '_notNull' => false,