diff --git a/README.md b/README.md index 8ab1360..03626c7 100644 --- a/README.md +++ b/README.md @@ -31,26 +31,12 @@ ## Repository Management -We use Github issues to track **BUGS** and to track approved **DEVELOPMENT** work packages. +We use Github issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages. We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss FEATURE REQUESTS. -If you raise an issue here that pertains to support or a feature request, it will -be closed! If you are not sure if you have found a bug, raise a thread on the forum first - -someone else may have encountered the same thing. - -Before raising a new Github issue, please check that your bug hasn't already -been reported or fixed. - -We use pull requests (PRs) for CONTRIBUTIONS to the repository. -We are looking for contributions that address one of the reported bugs or -approved work packages. - -Do not use a PR as a form of feature request. -Unsolicited contributions will only be considered if they fit nicely -into the framework roadmap. -Remember that some components that were part of CodeIgniter 3 are being moved -to optional packages, with their own repository. +This repository is a "distribution" one, built by our release preparation script. +Problems with it can be raised on our forum, or as issues in the main repository. ## Contributing diff --git a/_support/Controllers/Popcorn.php b/_support/Controllers/Popcorn.php index b3826d3..8af998d 100644 --- a/_support/Controllers/Popcorn.php +++ b/_support/Controllers/Popcorn.php @@ -55,4 +55,23 @@ return $response; } + public function canyon() + { + echo 'Hello-o-o'; + } + + public function cat() + { + } + + public function json() + { + $this->responsd(['answer' => 42]); + } + + public function xml() + { + $this->respond('cat'); + } + } diff --git a/_support/Database/Migrations/20160428212500_Create_test_tables.php b/_support/Database/Migrations/20160428212500_Create_test_tables.php index d81ab34..6bddd8a 100644 --- a/_support/Database/Migrations/20160428212500_Create_test_tables.php +++ b/_support/Database/Migrations/20160428212500_Create_test_tables.php @@ -31,6 +31,14 @@ 'constraint' => 1, 'default' => '0', ], + 'created_at' => [ + 'type' => 'DATETIME', + 'null' => true, + ], + 'updated_at' => [ + 'type' => 'DATETIME', + 'null' => true, + ], ]); $this->forge->addKey('id', true); $this->forge->createTable('user', true); @@ -46,11 +54,25 @@ 'type' => 'VARCHAR', 'constraint' => 40, ], - 'description' => ['type' => 'TEXT'], - 'created_at' => [ - 'type' => 'DATETIME', + 'description' => [ + 'type' => 'TEXT', 'null' => true, ], + 'deleted' => [ + 'type' => 'TINYINT', + 'constraint' => 1, + 'default' => '0', + ], + 'created_at' => [ + 'type' => 'INTEGER', + 'constraint' => 11, + 'null' => true, + ], + 'updated_at' => [ + 'type' => 'INTEGER', + 'constraint' => 11, + 'null' => true, + ], ]); $this->forge->addKey('id', true); $this->forge->createTable('job', true); @@ -82,6 +104,14 @@ 'type' => 'VARCHAR', 'constraint' => 40, ], + 'created_at' => [ + 'type' => 'DATE', + 'null' => true, + ], + 'updated_at' => [ + 'type' => 'DATE', + 'null' => true, + ], ]); $this->forge->addKey('id', true); $this->forge->createTable('empty', true); diff --git a/_support/Database/MockConnection.php b/_support/Database/MockConnection.php index e784053..699595b 100644 --- a/_support/Database/MockConnection.php +++ b/_support/Database/MockConnection.php @@ -1,5 +1,6 @@ returnValues['connect'] ?? true; @@ -82,9 +101,9 @@ * Keep or establish the connection if no queries have been sent for * a length of time exceeding the server's idle timeout. * - * @return mixed + * @return boolean */ - public function reconnect() + public function reconnect(): bool { return true; } @@ -110,11 +129,11 @@ /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { - return \CodeIgniter\CodeIgniter::CI_VERSION; + return CodeIgniter::CI_VERSION; } //-------------------------------------------------------------------- @@ -122,11 +141,11 @@ /** * Executes the query against the database. * - * @param $sql + * @param string $sql * * @return mixed */ - protected function execute($sql) + protected function execute(string $sql) { return $this->returnValues['execute']; } @@ -136,7 +155,7 @@ /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return int */ public function affectedRows(): int { @@ -154,7 +173,7 @@ * * @return array */ - public function error() + public function error(): array { return [ 'code' => null, @@ -169,7 +188,7 @@ * * @return integer */ - public function insertID() + public function insertID(): int { return $this->connID->insert_id; } @@ -183,7 +202,7 @@ * * @return string */ - protected function _listTables($constrainByPrefix = false): string + protected function _listTables(bool $constrainByPrefix = false): string { return ''; } diff --git a/_support/Database/MockResult.php b/_support/Database/MockResult.php index d33207f..dfe97a9 100644 --- a/_support/Database/MockResult.php +++ b/_support/Database/MockResult.php @@ -68,9 +68,9 @@ * * Overridden by driver classes. * - * @return array + * @return mixed */ - protected function fetchAssoc(): array + protected function fetchAssoc() { } diff --git a/_support/Database/MockTestClass.php b/_support/Database/MockTestClass.php new file mode 100644 index 0000000..232943b --- /dev/null +++ b/_support/Database/MockTestClass.php @@ -0,0 +1,7 @@ + [], diff --git a/_support/Models/UserModel.php b/_support/Models/UserModel.php index c84ca1a..0501882 100644 --- a/_support/Models/UserModel.php +++ b/_support/Models/UserModel.php @@ -17,5 +17,11 @@ protected $useSoftDeletes = true; - protected $dateFormat = 'integer'; + protected $dateFormat = 'datetime'; + + public $name = ''; + + public $email = ''; + + public $country = ''; } diff --git a/_support/Models/ValidErrorsModel.php b/_support/Models/ValidErrorsModel.php index 95a2193..189ac63 100644 --- a/_support/Models/ValidErrorsModel.php +++ b/_support/Models/ValidErrorsModel.php @@ -10,7 +10,7 @@ protected $useSoftDeletes = false; - protected $dateFormat = 'integer'; + protected $dateFormat = 'int'; protected $allowedFields = [ 'name', diff --git a/_support/Models/ValidModel.php b/_support/Models/ValidModel.php index a252120..69842d8 100644 --- a/_support/Models/ValidModel.php +++ b/_support/Models/ValidModel.php @@ -10,7 +10,7 @@ protected $useSoftDeletes = false; - protected $dateFormat = 'integer'; + protected $dateFormat = 'int'; protected $allowedFields = [ 'name', diff --git a/_support/View/MockTable.php b/_support/View/MockTable.php new file mode 100644 index 0000000..d286b22 --- /dev/null +++ b/_support/View/MockTable.php @@ -0,0 +1,17 @@ + ./tests - ./tests/system - - - - ./system - - ./system - - - + + + + diff --git a/public/.htaccess b/public/.htaccess index adfbcd5..8af50c9 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,36 +1,7 @@ -# ---------------------------------------------------------------------- -# Environment Name -# ---------------------------------------------------------------------- - -# Sets the environment that CodeIgniter runs under. -# SetEnv CI_ENVIRONMENT development - # Disable directory browsing Options All -Indexes # ---------------------------------------------------------------------- -# UTF-8 encoding -# ---------------------------------------------------------------------- - -# Use UTF-8 encoding for anything served text/plain or text/html -AddDefaultCharset utf-8 - -# Force UTF-8 for a number of file formats - - AddCharset utf-8 .atom .css .js .json .rss .vtt .xml - - -# ---------------------------------------------------------------------- -# Activate CORS -# ---------------------------------------------------------------------- - - - - Header set Access-Control-Allow-Origin "*" - - - -# ---------------------------------------------------------------------- # Rewrite engine # ---------------------------------------------------------------------- @@ -43,7 +14,7 @@ # If you installed CodeIgniter in a subfolder, you will need to # change the following line to match the subfolder you need. # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase - RewriteBase / + # RewriteBase / # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] @@ -60,12 +31,6 @@ RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] - # Disable image hotlinkiing start - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?example.com [NC] - RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L] - # Disable image hotlinkiing end - # Ensure Authorization header is passed along RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] @@ -80,103 +45,3 @@ # Disable server signature start ServerSignature Off # Disable server signature end - -# BEGIN Expires - - ExpiresActive On - ExpiresByType text/css "access 1 month" - ExpiresByType text/html "access 1 month" - ExpiresByType image/gif "access 1 year" - ExpiresByType image/png "access 1 year" - ExpiresByType image/jpg "access 1 year" - ExpiresByType image/jpeg "access 1 year" - ExpiresByType image/x-icon "access 1 year" - ExpiresByType image/svg+xml "access plus 1 month" - ExpiresByType audio/ogg "access plus 1 year" - ExpiresByType video/mp4 "access plus 1 year" - ExpiresByType video/ogg "access plus 1 year" - ExpiresByType video/webm "access plus 1 year" - ExpiresByType application/atom+xml "access plus 1 hour" - ExpiresByType application/rss+xml "access plus 1 hour" - ExpiresByType application/pdf "access 1 month" - ExpiresByType application/javascript "access 1 month" - ExpiresByType text/x-javascript "access 1 month" - ExpiresByType text/x-component "access plus 1 month" - ExpiresByType application/x-shockwave-flash "access 1 month" - ExpiresByType font/opentype "access plus 1 month" - ExpiresByType application/vnd.ms-fontobject "access plus 1 month" - ExpiresByType application/x-font-ttf "access plus 1 month" - ExpiresByType application/font-woff "access plus 1 month" - ExpiresByType application/font-woff2 "access plus 1 month" - ExpiresDefault "access 1 month" - -# END Expires - -# ---------------------------------------------------------------------- -# Gzip compression -# ---------------------------------------------------------------------- - -# Start gzip compression - - mod_gzip_on Yes - mod_gzip_dechunk Yes - mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ - mod_gzip_item_include handler ^cgi-script$ - mod_gzip_item_include mime ^text/.* - mod_gzip_item_include mime ^application/x-javascript.* - mod_gzip_item_exclude mime ^image/.* - mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* - -# End gzip compression - - - - # Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ - - - SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding - RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding - - - - # Compress all output labeled with one of the following MIME-types - # (for Apache versions below 2.3.7, you don't need to enable `mod_filter` - # and can remove the `` and `` lines as - # `AddOutputFilterByType` is still in the core directives) - - AddOutputFilterByType DEFLATE application/atom+xml \ - application/javascript \ - application/json \ - application/rss+xml \ - application/vnd.ms-fontobject \ - application/x-font-ttf \ - application/xhtml+xml \ - application/xml \ - application/x-javascript \ - application/x-font \ - application/x-font-truetype \ - application/x-font-otf \ - application/x-font-woff \ - application/x-font-woff2 \ - application/x-font-opentype \ - font/opentype \ - font/ttf \ - font/otf \ - font/eot \ - font/woff \ - font/woff2 \ - image/svg+xml svg svgz \ - image/x-icon \ - text/css \ - text/html \ - text/plain \ - text/x-component \ - text/xml \ - text/javascript \ - - # For Olders Browsers Which Can't Handle Compression - BrowserMatch ^Mozilla/4 gzip-only-text/html - BrowserMatch ^Mozilla/4\.0[678] no-gzip - BrowserMatch \bMSIE !no-gzip !gzip-only-text/html - - diff --git a/system/API/ResponseTrait.php b/system/API/ResponseTrait.php index c168e37..3539f25 100644 --- a/system/API/ResponseTrait.php +++ b/system/API/ResponseTrait.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -97,9 +97,9 @@ * Provides a single, simple method to return an API response, formatted * to match the requested format, with proper content-type and status code. * - * @param null $data - * @param integer $status - * @param string $message + * @param array|string|null $data + * @param integer $status + * @param string $message * * @return mixed */ diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 057c3bd..359e5eb 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 38ea283..b247730 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -49,6 +49,8 @@ class FileLocator { /** + * The Autoloader to use. + * * @var \CodeIgniter\Autoloader\Autoloader */ protected $autoloader; @@ -261,6 +263,8 @@ //-------------------------------------------------------------------- /** + * Return the namespace mappings we know about. + * * @param string|null $prefix * * @return array|string diff --git a/system/CLI/BaseCommand.php b/system/CLI/BaseCommand.php index 154a028..9358d4a 100644 --- a/system/CLI/BaseCommand.php +++ b/system/CLI/BaseCommand.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -142,6 +142,7 @@ * @param array $params * * @return mixed + * @throws \ReflectionException */ protected function call(string $command, array $params = []) { @@ -183,6 +184,8 @@ { return $this->$key; } + + return null; } //-------------------------------------------------------------------- @@ -192,7 +195,7 @@ */ public function showHelp() { - // 4 spaces insted of tab + // 4 spaces instead of tab $tab = ' '; CLI::write(lang('CLI.helpDescription'), 'yellow'); CLI::write($tab . $this->description); @@ -236,7 +239,7 @@ * * @return integer */ - public function getPad($array, int $pad) + public function getPad(array $array, int $pad): int { $max = 0; foreach ($array as $key => $value) diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 68614ce..eb13b2a 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,10 +41,7 @@ use CodeIgniter\CLI\Exceptions\CLIException; /** - * Class CLI - * - * Tools to interact with that request since CLI requests are not - * static like HTTP requests might be. + * Set of static methods useful for CLI request handling. * * Portions of this code were initially from the FuelPHP Framework, * version 1.7.x, and used here under the MIT license they were @@ -61,7 +58,7 @@ * an argument of "0". * These have been flagged to ignore for code coverage purposes. * - * @package CodeIgniter\HTTP + * @package CodeIgniter\CLI */ class CLI { @@ -594,8 +591,8 @@ * Displays a progress bar on the CLI. You must call it repeatedly * to update it. Set $thisStep = false to erase the progress bar. * - * @param integer $thisStep - * @param integer $totalSteps + * @param integer|boolean $thisStep + * @param integer $totalSteps */ public static function showProgress($thisStep = 1, int $totalSteps = 10) { diff --git a/system/CLI/CommandRunner.php b/system/CLI/CommandRunner.php index 3e273db..00c7874 100644 --- a/system/CLI/CommandRunner.php +++ b/system/CLI/CommandRunner.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -56,6 +56,8 @@ protected $commands = []; /** + * Message logger. + * * @var \CodeIgniter\Log\Logger */ protected $logger; @@ -85,6 +87,8 @@ //-------------------------------------------------------------------- /** + * Default command. + * * @param array $params * * @return mixed @@ -197,7 +201,7 @@ * * @return array */ - public function getCommands() + public function getCommands(): array { return $this->commands; } diff --git a/system/CLI/Console.php b/system/CLI/Console.php index a9804ba..43457b9 100644 --- a/system/CLI/Console.php +++ b/system/CLI/Console.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -73,7 +73,7 @@ * @param boolean $useSafeOutput * * @return \CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed - * @throws \CodeIgniter\Router\RedirectException + * @throws \Exception */ public function run(bool $useSafeOutput = false) { diff --git a/system/Cache/CacheFactory.php b/system/Cache/CacheFactory.php index 49e360e..da2246d 100644 --- a/system/Cache/CacheFactory.php +++ b/system/Cache/CacheFactory.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index b4ea914..2206db1 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Cache/Handlers/DummyHandler.php b/system/Cache/Handlers/DummyHandler.php index cf13608..a123a80 100644 --- a/system/Cache/Handlers/DummyHandler.php +++ b/system/Cache/Handlers/DummyHandler.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index 8bbe5ea..a33f893 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -63,6 +63,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config) { $path = ! empty($config->storePath) ? $config->storePath : WRITEPATH . 'cache'; @@ -377,7 +383,7 @@ * * @return boolean */ - protected function deleteFiles($path, $del_dir = false, $htdocs = false, $_level = 0) + protected function deleteFiles(string $path, bool $del_dir = false, bool $htdocs = false, int $_level = 0): bool { // Trim the trailing slash $path = rtrim($path, '/\\'); @@ -423,7 +429,7 @@ * * @return array|false */ - protected function getDirFileInfo($source_dir, $top_level_only = true, $_recursion = false) + protected function getDirFileInfo(string $source_dir, bool $top_level_only = true, bool $_recursion = false) { static $_filedata = []; $relative_path = $source_dir; @@ -474,45 +480,50 @@ * * @return array|false */ - protected function getFileInfo(string $file, array $returned_values = ['name', 'server_path', 'size', 'date']) + protected function getFileInfo(string $file, $returned_values = ['name', 'server_path', 'size', 'date']) { if (! is_file($file)) { return false; } + if (is_string($returned_values)) + { + $returned_values = explode(',', $returned_values); + } + foreach ($returned_values as $key) { switch ($key) { case 'name': - $fileinfo['name'] = basename($file); + $fileInfo['name'] = basename($file); break; case 'server_path': - $fileinfo['server_path'] = $file; + $fileInfo['server_path'] = $file; break; case 'size': - $fileinfo['size'] = filesize($file); + $fileInfo['size'] = filesize($file); break; case 'date': - $fileinfo['date'] = filemtime($file); + $fileInfo['date'] = filemtime($file); break; case 'readable': - $fileinfo['readable'] = is_readable($file); + $fileInfo['readable'] = is_readable($file); break; case 'writable': - $fileinfo['writable'] = is_writable($file); + $fileInfo['writable'] = is_writable($file); break; case 'executable': - $fileinfo['executable'] = is_executable($file); + $fileInfo['executable'] = is_executable($file); break; case 'fileperms': - $fileinfo['fileperms'] = fileperms($file); + $fileInfo['fileperms'] = fileperms($file); break; } } - return $fileinfo; + return $fileInfo; } //-------------------------------------------------------------------- diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index 8950257..07a307d 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -31,13 +31,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Cache\Handlers; use CodeIgniter\Cache\CacheInterface; +use CodeIgniter\Exceptions\CriticalError; /** * Mamcached cache handler @@ -73,6 +74,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config) { $config = (array)$config; @@ -133,7 +140,7 @@ } elseif ($this->memcached instanceof \Memcache) { - // Third parameter is persistance and defaults to TRUE. + // Third parameter is persistence and defaults to TRUE. $this->memcached->addServer( $this->config['host'], $this->config['port'], true, $this->config['weight'] ); @@ -158,7 +165,7 @@ $data = $this->memcached->get($key); // check for unmatched key - if ($this->memcached->getResultCode()==\Memcached::RES_NOTFOUND) + if ($this->memcached->getResultCode() === \Memcached::RES_NOTFOUND) { return null; } @@ -166,10 +173,10 @@ elseif ($this->memcached instanceof \Memcache) { $flags = false; - $data = $this->memcached->get($key, $flags); + $data = $this->memcached->get($key, $flags); // check for unmatched key (i.e. $flags is untouched) - if ($flags===false) + if ($flags === false) { return null; } diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 0f643e0..847e183 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -76,6 +76,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config) { $this->prefix = $config->prefix ?: ''; diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 248e9bd..a0a9d45 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -76,6 +76,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config) { $config = (array)$config; diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index c619f26..f1a29d2 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -58,6 +58,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config) { $this->prefix = $config->prefix ?: ''; diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 59a46d5..e518db4 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -31,12 +31,13 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter; +use Closure; use CodeIgniter\Filters\Exceptions\FilterException; use CodeIgniter\HTTP\DownloadResponse; use CodeIgniter\HTTP\RedirectResponse; @@ -51,6 +52,7 @@ use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\Router\RouteCollectionInterface; use CodeIgniter\Exceptions\PageNotFoundException; +use Exception; /** * This class is the core of the framework, and will analyse the @@ -63,7 +65,7 @@ /** * The current version of CodeIgniter Framework */ - const CI_VERSION = '4.0.0-beta.2'; + const CI_VERSION = '4.0.0-beta.3'; /** * App startup time. @@ -159,6 +161,11 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + */ public function __construct($config) { $this->startTime = microtime(true); @@ -281,7 +288,7 @@ * @param boolean $returnResponse * * @return \CodeIgniter\HTTP\RequestInterface|\CodeIgniter\HTTP\Response|\CodeIgniter\HTTP\ResponseInterface|mixed - * @throws \CodeIgniter\Router\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException */ protected function handleRequest(RouteCollectionInterface $routes = null, $cacheConfig, bool $returnResponse = false) { @@ -545,7 +552,7 @@ $cachedResponse = unserialize($cachedResponse); if (! is_array($cachedResponse) || ! isset($cachedResponse['output']) || ! isset($cachedResponse['headers'])) { - throw new \Exception('Error unserializing page cache'); + throw new Exception('Error unserializing page cache'); } $headers = $cachedResponse['headers']; @@ -687,7 +694,7 @@ * of the config file. * * @return string - * @throws \CodeIgniter\Router\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException */ protected function tryToRouteIt(RouteCollectionInterface $routes = null) { @@ -849,7 +856,7 @@ // Is there a 404 Override available? if ($override = $this->router->get404Override()) { - if ($override instanceof \Closure) + if ($override instanceof Closure) { echo $override($e->getMessage()); } diff --git a/system/Commands/Database/CreateMigration.php b/system/Commands/Database/CreateMigration.php index dcebb41..cc00665 100644 --- a/system/Commands/Database/CreateMigration.php +++ b/system/Commands/Database/CreateMigration.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Database/MigrateCurrent.php b/system/Commands/Database/MigrateCurrent.php index 7745d6b..2ca0fb6 100644 --- a/system/Commands/Database/MigrateCurrent.php +++ b/system/Commands/Database/MigrateCurrent.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Database/MigrateLatest.php b/system/Commands/Database/MigrateLatest.php index b98abb0..d04f5ac 100644 --- a/system/Commands/Database/MigrateLatest.php +++ b/system/Commands/Database/MigrateLatest.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -144,7 +144,7 @@ * @param array $params * @return boolean */ - private function isAllNamespace(array $params) + private function isAllNamespace(array $params): bool { if (array_search('-all', $params) !== false) { diff --git a/system/Commands/Database/MigrateRefresh.php b/system/Commands/Database/MigrateRefresh.php index 296d23e..e56d563 100644 --- a/system/Commands/Database/MigrateRefresh.php +++ b/system/Commands/Database/MigrateRefresh.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Database/MigrateRollback.php b/system/Commands/Database/MigrateRollback.php index c54d3b7..3d7cf17 100644 --- a/system/Commands/Database/MigrateRollback.php +++ b/system/Commands/Database/MigrateRollback.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -164,7 +164,7 @@ * @param array $params * @return boolean */ - private function isAllNamespace(array $params) + private function isAllNamespace(array $params): bool { if (array_search('-all', $params) !== false) { diff --git a/system/Commands/Database/MigrateStatus.php b/system/Commands/Database/MigrateStatus.php index 01d206a..147e738 100644 --- a/system/Commands/Database/MigrateStatus.php +++ b/system/Commands/Database/MigrateStatus.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -96,6 +96,11 @@ '-g' => 'Set database group', ]; + /** + * Namespaces to ignore when looking for migrations. + * + * @var type + */ protected $ignoredNamespaces = [ 'CodeIgniter', 'Config', @@ -118,7 +123,7 @@ $runner->setGroup($group); } - // Get all namespaces form PSR4 paths. + // Get all namespaces from PSR4 paths. $config = new Autoload(); $namespaces = $config->psr4; diff --git a/system/Commands/Database/MigrateVersion.php b/system/Commands/Database/MigrateVersion.php index 5757e32..d781f68 100644 --- a/system/Commands/Database/MigrateVersion.php +++ b/system/Commands/Database/MigrateVersion.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Database/Seed.php b/system/Commands/Database/Seed.php index c48cd87..f19445f 100644 --- a/system/Commands/Database/Seed.php +++ b/system/Commands/Database/Seed.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Help.php b/system/Commands/Help.php index 25610c6..0678a23 100644 --- a/system/Commands/Help.php +++ b/system/Commands/Help.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/ListCommands.php b/system/Commands/ListCommands.php index cb84a85..75e0708 100644 --- a/system/Commands/ListCommands.php +++ b/system/Commands/ListCommands.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -176,13 +176,13 @@ * Pads our string out so that all titles are the same length to nicely line up descriptions. * * @param string $item - * @param $max + * @param integer $max * @param integer $extra // How many extra spaces to add at the end * @param integer $indent * - * @return array + * @return string */ - protected function padTitle(string $item, $max, $extra = 2, $indent = 0) + protected function padTitle(string $item, int $max, int $extra = 2, int $indent = 0): string { $max += $extra + $indent; diff --git a/system/Commands/Server/Serve.php b/system/Commands/Server/Serve.php index c07996c..8ca15ab 100644 --- a/system/Commands/Server/Serve.php +++ b/system/Commands/Server/Serve.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Server/rewrite.php b/system/Commands/Server/rewrite.php index f3c0dd7..94b7d15 100644 --- a/system/Commands/Server/rewrite.php +++ b/system/Commands/Server/rewrite.php @@ -14,11 +14,6 @@ { return; } - -// If we're serving the site locally, then we need -// to let the application know that we're in development mode -$_SERVER['CI_ENVIRONMENT'] = 'development'; - $uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); // Front Controller path - expected to be in the default folder diff --git a/system/Commands/Sessions/CreateMigration.php b/system/Commands/Sessions/CreateMigration.php index ac8a90b..052eb07 100644 --- a/system/Commands/Sessions/CreateMigration.php +++ b/system/Commands/Sessions/CreateMigration.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Utilities/Namespaces.php b/system/Commands/Utilities/Namespaces.php index 9a2a00e..36e0c77 100644 --- a/system/Commands/Utilities/Namespaces.php +++ b/system/Commands/Utilities/Namespaces.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Commands/Utilities/Routes.php b/system/Commands/Utilities/Routes.php index 480b612..ad9f3a5 100644 --- a/system/Commands/Utilities/Routes.php +++ b/system/Commands/Utilities/Routes.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Common.php b/system/Common.php index f0907f7..a0ca219 100644 --- a/system/Common.php +++ b/system/Common.php @@ -32,14 +32,22 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ +use CodeIgniter\Config\Config; +use CodeIgniter\Files\Exceptions\FileNotFoundException; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\URI; +use Config\App; +use Config\Database; +use Config\Logger; use Config\Services; +use Tests\Support\Log\TestLogger; +use Zend\Escaper\Escaper; /** * Common Functions @@ -97,7 +105,7 @@ */ function config(string $name, bool $getShared = true) { - return \CodeIgniter\Config\Config::get($name, $getShared); + return Config::get($name, $getShared); } } @@ -126,7 +134,7 @@ */ function db_connect($db = null, bool $getShared = true) { - return \Config\Database::connect($db, $getShared); + return Database::connect($db, $getShared); } } @@ -182,6 +190,7 @@ * @param string|null $cacheName * * @return string + * @throws \ReflectionException */ function view_cell(string $library, $params = null, int $ttl = 0, string $cacheName = null): string { @@ -281,7 +290,7 @@ if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'])) { - throw new \InvalidArgumentException('Invalid escape context provided.'); + throw new InvalidArgumentException('Invalid escape context provided.'); } if ($context === 'attr') @@ -296,12 +305,12 @@ static $escaper; if (! $escaper) { - $escaper = new \Zend\Escaper\Escaper($encoding); + $escaper = new Escaper($encoding); } if ($encoding && $escaper->getEncoding() !== $encoding) { - $escaper = new \Zend\Escaper\Escaper($encoding); + $escaper = new Escaper($encoding); } $data = $escaper->$method($data); @@ -471,7 +480,7 @@ // for asserting that logs were called in the test code. if (ENVIRONMENT === 'testing') { - $logger = new \Tests\Support\Log\TestLogger(new \Config\Logger()); + $logger = new TestLogger(new Logger()); return $logger->log($level, $message, $context); } @@ -534,27 +543,27 @@ * between ascii characters, like Java\0script. * * @param string $str - * @param boolean $url_encoded + * @param boolean $urlEncoded * * @return string */ - function remove_invisible_characters(string $str, bool $url_encoded = true): string + function remove_invisible_characters(string $str, bool $urlEncoded = true): string { - $non_displayables = []; + $nonDisplayables = []; // every control character except newline (dec 10), // carriage return (dec 13) and horizontal tab (dec 09) - if ($url_encoded) + if ($urlEncoded) { - $non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 - $non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 + $nonDisplayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15 + $nonDisplayables[] = '/%1[0-9a-f]/'; // url encoded 16-31 } - $non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 + $nonDisplayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127 do { - $str = preg_replace($non_displayables, '', $str, -1, $count); + $str = preg_replace($nonDisplayables, '', $str, -1, $count); } while ($count); @@ -611,7 +620,7 @@ if (empty($path)) { - throw \CodeIgniter\Files\Exceptions\FileNotFoundException::forFileNotFound($filename); + throw FileNotFoundException::forFileNotFound($filename); } $includes[] = $path; @@ -687,7 +696,7 @@ */ function app_timezone(): string { - $config = config(\Config\App::class); + $config = config(App::class); return $config->appTimezone; } @@ -706,7 +715,7 @@ */ function csrf_token(): string { - $config = config(\Config\App::class); + $config = config(App::class); return $config->CSRFTokenName; } @@ -797,7 +806,7 @@ $uri = $request->uri; $uri->setScheme('https'); - $uri = \CodeIgniter\HTTP\URI::createURIString( + $uri = URI::createURIString( $uri->getScheme(), $uri->getAuthority(true), $uri->getPath(), // Absolute URIs should use a "/" for an empty path $uri->getQuery(), $uri->getFragment() ); @@ -942,6 +951,7 @@ * * @return boolean * + * @throws \Exception * @codeCoverageIgnore Not practical to test, as travis runs on linux */ function is_really_writable(string $file): bool @@ -996,7 +1006,7 @@ */ function slash_item(string $item): ?string { - $config = config(\Config\App::class); + $config = config(App::class); $configItem = $config->{$item}; if (! isset($configItem) || empty(trim($configItem))) diff --git a/system/ComposerScripts.php b/system/ComposerScripts.php index d7ebade..a4395cb 100644 --- a/system/ComposerScripts.php +++ b/system/ComposerScripts.php @@ -32,12 +32,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter; +use ReflectionClass; + /** * ComposerScripts * @@ -51,6 +53,11 @@ */ class ComposerScripts { + /** + * Base path to use. + * + * @var type + */ protected static $basePath = 'ThirdParty/'; /** @@ -76,7 +83,7 @@ * * @return boolean */ - protected static function moveFile(string $source, string $destination) + protected static function moveFile(string $source, string $destination): bool { $source = realpath($source); @@ -105,7 +112,7 @@ */ protected static function getClassFilePath(string $class) { - $reflector = new \ReflectionClass($class); + $reflector = new ReflectionClass($class); return $reflector->getFileName(); } diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index bd3d87f..e68aa6c 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -115,78 +115,15 @@ * ]; */ $this->classmap = [ - 'CodeIgniter\CodeIgniter' => SYSTEMPATH . 'CodeIgniter.php', - 'CodeIgniter\CLI\CLI' => SYSTEMPATH . 'CLI/CLI.php', - 'CodeIgniter\Cache\CacheFactory' => SYSTEMPATH . 'Cache/CacheFactory.php', - 'CodeIgniter\Cache\CacheInterface' => SYSTEMPATH . 'Cache/CacheInterface.php', - 'CodeIgniter\Cache\Handlers\DummyHandler' => SYSTEMPATH . 'Cache/Handlers/DummyHandler.php', - 'CodeIgniter\Cache\Handlers\FileHandler' => SYSTEMPATH . 'Cache/Handlers/FileHandler.php', - 'CodeIgniter\Cache\Handlers\MemcachedHandler' => SYSTEMPATH . 'Cache/Handlers/MemcachedHandler.php', - 'CodeIgniter\Cache\Handlers\PredisHandler' => SYSTEMPATH . 'Cache/Handlers/PredisHandler.php', - 'CodeIgniter\Cache\Handlers\RedisHandler' => SYSTEMPATH . 'Cache/Handlers/RedisHandler.php', - 'CodeIgniter\Cache\Handlers\WincacheHandler' => SYSTEMPATH . 'Cache/Handlers/WincacheHandler.php', - 'CodeIgniter\Controller' => SYSTEMPATH . 'Controller.php', - 'CodeIgniter\Config\AutoloadConfig' => SYSTEMPATH . 'Config/Autoload.php', - 'CodeIgniter\Config\BaseConfig' => SYSTEMPATH . 'Config/BaseConfig.php', - 'CodeIgniter\Config\Database' => SYSTEMPATH . 'Config/Database.php', - 'CodeIgniter\Config\Database\Connection' => SYSTEMPATH . 'Config/Database/Connection.php', - 'CodeIgniter\Config\Database\Connection\MySQLi' => SYSTEMPATH . 'Config/Database/Connection/MySQLi.php', - 'CodeIgniter\Config\DotEnv' => SYSTEMPATH . 'Config/DotEnv.php', - 'CodeIgniter\Database\BaseBuilder' => SYSTEMPATH . 'Database/BaseBuilder.php', - 'CodeIgniter\Database\BaseConnection' => SYSTEMPATH . 'Database/BaseConnection.php', - 'CodeIgniter\Database\BaseResult' => SYSTEMPATH . 'Database/BaseResult.php', - 'CodeIgniter\Database\Config' => SYSTEMPATH . 'Database/Config.php', - 'CodeIgniter\Database\ConnectionInterface' => SYSTEMPATH . 'Database/ConnectionInterface.php', - 'CodeIgniter\Database\Database' => SYSTEMPATH . 'Database/Database.php', - 'CodeIgniter\Database\Query' => SYSTEMPATH . 'Database/Query.php', - 'CodeIgniter\Database\QueryInterface' => SYSTEMPATH . 'Database/QueryInterface.php', - 'CodeIgniter\Database\ResultInterface' => SYSTEMPATH . 'Database/ResultInterface.php', - 'CodeIgniter\Database\Migration' => SYSTEMPATH . 'Database/Migration.php', - 'CodeIgniter\Database\MigrationRunner' => SYSTEMPATH . 'Database/MigrationRunner.php', - 'CodeIgniter\Debug\Exceptions' => SYSTEMPATH . 'Debug/Exceptions.php', - 'CodeIgniter\Debug\Timer' => SYSTEMPATH . 'Debug/Timer.php', - 'CodeIgniter\Debug\Iterator' => SYSTEMPATH . 'Debug/Iterator.php', - 'CodeIgniter\Events\Events' => SYSTEMPATH . 'Events/Events.php', - 'CodeIgniter\HTTP\CLIRequest' => SYSTEMPATH . 'HTTP/CLIRequest.php', - 'CodeIgniter\HTTP\ContentSecurityPolicy' => SYSTEMPATH . 'HTTP/ContentSecurityPolicy.php', - 'CodeIgniter\HTTP\CURLRequest' => SYSTEMPATH . 'HTTP/CURLRequest.php', - 'CodeIgniter\HTTP\IncomingRequest' => SYSTEMPATH . 'HTTP/IncomingRequest.php', - 'CodeIgniter\HTTP\Message' => SYSTEMPATH . 'HTTP/Message.php', - 'CodeIgniter\HTTP\Negotiate' => SYSTEMPATH . 'HTTP/Negotiate.php', - 'CodeIgniter\HTTP\Request' => SYSTEMPATH . 'HTTP/Request.php', - 'CodeIgniter\HTTP\RequestInterface' => SYSTEMPATH . 'HTTP/RequestInterface.php', - 'CodeIgniter\HTTP\Response' => SYSTEMPATH . 'HTTP/Response.php', - 'CodeIgniter\HTTP\ResponseInterface' => SYSTEMPATH . 'HTTP/ResponseInterface.php', - 'CodeIgniter\HTTP\URI' => SYSTEMPATH . 'HTTP/URI.php', - 'CodeIgniter\Log\Logger' => SYSTEMPATH . 'Log/Logger.php', - 'Psr\Log\AbstractLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php', - 'Psr\Log\InvalidArgumentException' => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php', - 'Psr\Log\LoggerAwareInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php', - 'Psr\Log\LoggerAwareTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php', - 'Psr\Log\LoggerInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php', - 'Psr\Log\LoggerTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php', - 'Psr\Log\LogLevel' => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php', - 'Psr\Log\NullLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php', - 'CodeIgniter\Log\Handlers\BaseHandler' => SYSTEMPATH . 'Log/Handlers/BaseHandler.php', - 'CodeIgniter\Log\Handlers\ChromeLoggerHandler' => SYSTEMPATH . 'Log/Handlers/ChromeLoggerHandler.php', - 'CodeIgniter\Log\Handlers\FileHandler' => SYSTEMPATH . 'Log/Handlers/FileHandler.php', - 'CodeIgniter\Log\Handlers\HandlerInterface' => SYSTEMPATH . 'Log/Handlers/HandlerInterface.php', - 'CodeIgniter\Router\RouteCollection' => SYSTEMPATH . 'Router/RouteCollection.php', - 'CodeIgniter\Router\RouteCollectionInterface' => SYSTEMPATH . 'Router/RouteCollectionInterface.php', - 'CodeIgniter\Router\Router' => SYSTEMPATH . 'Router/Router.php', - 'CodeIgniter\Router\RouterInterface' => SYSTEMPATH . 'Router/RouterInterface.php', - 'CodeIgniter\Security\Security' => SYSTEMPATH . 'Security/Security.php', - 'CodeIgniter\Session\Session' => SYSTEMPATH . 'Session/Session.php', - 'CodeIgniter\Session\SessionInterface' => SYSTEMPATH . 'Session/SessionInterface.php', - 'CodeIgniter\Session\Handlers\BaseHandler' => SYSTEMPATH . 'Session/Handlers/BaseHandler.php', - 'CodeIgniter\Session\Handlers\FileHandler' => SYSTEMPATH . 'Session/Handlers/FileHandler.php', - 'CodeIgniter\Session\Handlers\MemcachedHandler' => SYSTEMPATH . 'Session/Handlers/MemcachedHandler.php', - 'CodeIgniter\Session\Handlers\RedisHandler' => SYSTEMPATH . 'Session/Handlers/RedisHandler.php', - 'CodeIgniter\View\RendererInterface' => SYSTEMPATH . 'View/RendererInterface.php', - 'CodeIgniter\View\View' => SYSTEMPATH . 'View/View.php', - 'CodeIgniter\View\Parser' => SYSTEMPATH . 'View/Parser.php', - 'CodeIgniter\View\Cell' => SYSTEMPATH . 'View/Cell.php', - 'Zend\Escaper\Escaper' => SYSTEMPATH . 'ThirdParty/ZendEscaper/Escaper.php', + 'Psr\Log\AbstractLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php', + 'Psr\Log\InvalidArgumentException' => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php', + 'Psr\Log\LoggerAwareInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php', + 'Psr\Log\LoggerAwareTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php', + 'Psr\Log\LoggerInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php', + 'Psr\Log\LoggerTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php', + 'Psr\Log\LogLevel' => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php', + 'Psr\Log\NullLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php', + 'Zend\Escaper\Escaper' => SYSTEMPATH . 'ThirdParty/ZendEscaper/Escaper.php', ]; if (isset($_SERVER['CI_ENVIRONMENT']) && $_SERVER['CI_ENVIRONMENT'] === 'testing') diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 9b1b0be..d297eff 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -57,8 +57,20 @@ * * @var array */ - public static $registrars = []; + public static $registrars = []; + + /** + * Has module discovery happened yet? + * + * @var boolean + */ protected static $didDiscovery = false; + + /** + * The modules configuration. + * + * @var type + */ protected static $moduleConfig; /** @@ -181,8 +193,15 @@ if (! static::$didDiscovery) { - $locator = \Config\Services::locator(); - static::$registrars = $locator->search('Config/Registrar.php'); + $locator = \Config\Services::locator(); + $registrarsFiles = $locator->search('Config/Registrar.php'); + + foreach ($registrarsFiles as $file) + { + $className = $locator->getClassname($file); + static::$registrars[] = new $className(); + } + static::$didDiscovery = true; } diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index aadf04d..b94ef94 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -31,12 +31,17 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Config; +use CodeIgniter\Autoloader\Autoloader; +use CodeIgniter\Autoloader\FileLocator; +use Config\Autoload; +use Config\Modules; + /** * Services Configuration file. * @@ -133,13 +138,13 @@ { if (empty(static::$instances['autoloader'])) { - static::$instances['autoloader'] = new \CodeIgniter\Autoloader\Autoloader(); + static::$instances['autoloader'] = new Autoloader(); } return static::$instances['autoloader']; } - return new \CodeIgniter\Autoloader\Autoloader(); + return new Autoloader(); } //-------------------------------------------------------------------- @@ -159,7 +164,7 @@ { if (empty(static::$instances['locator'])) { - static::$instances['locator'] = new \CodeIgniter\Autoloader\FileLocator( + static::$instances['locator'] = new FileLocator( static::autoloader() ); } @@ -167,7 +172,7 @@ return static::$instances['locator']; } - return new \CodeIgniter\Autoloader\FileLocator(static::autoloader()); + return new FileLocator(static::autoloader()); } //-------------------------------------------------------------------- @@ -208,7 +213,7 @@ if ($init_autoloader) { - static::autoloader()->initialize(new \Config\Autoload(), new \Config\Modules()); + static::autoloader()->initialize(new Autoload(), new Modules()); } } diff --git a/system/Config/Config.php b/system/Config/Config.php index 8fbfd82..ba80348 100644 --- a/system/Config/Config.php +++ b/system/Config/Config.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Config/DotEnv.php b/system/Config/DotEnv.php index d078fc7..1b4b58c 100644 --- a/system/Config/DotEnv.php +++ b/system/Config/DotEnv.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -73,7 +73,7 @@ * * @return boolean */ - public function load() + public function load(): bool { // We don't want to enforce the presence of a .env file, // they should be optional. diff --git a/system/Config/ForeignCharacters.php b/system/Config/ForeignCharacters.php index b76f18a..39db140 100644 --- a/system/Config/ForeignCharacters.php +++ b/system/Config/ForeignCharacters.php @@ -32,21 +32,19 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Config; +/** + * Describes foreign characters for transliteration with the text helper. + */ class ForeignCharacters { - /* - | ------------------------------------------------------------------- - | Foreign Characters - | ------------------------------------------------------------------- - | This file contains an array of foreign characters for transliteration - | conversion used by the Text helper - | + /** + * Without further ado, the list of foreign characters. */ public $characterList = [ diff --git a/system/Config/Routes.php b/system/Config/Routes.php index 8050e21..3cc1b09 100644 --- a/system/Config/Routes.php +++ b/system/Config/Routes.php @@ -31,10 +31,12 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ +use CodeIgniter\Exceptions\PageNotFoundException; + /** * System URI Routing * @@ -45,10 +47,9 @@ * already loaded up and ready for us to use. */ // Prevent access to BaseController -$routes->add('basecontroller(:any)', function() -{ - throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); -}); +$routes->add('basecontroller(:any)', function () { + throw PageNotFoundException::forPageNotFound(); +}); // Migrations $routes->cli('migrations/(:segment)/(:segment)', '\CodeIgniter\Commands\MigrationsCommand::$1/$2'); @@ -59,7 +60,6 @@ $routes->cli('ci(:any)', '\CodeIgniter\CLI\CommandRunner::index/$1'); // Prevent access to initController method -$routes->add('(:any)/initController', function() -{ - throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); -}); +$routes->add('(:any)/initController', function () { + throw PageNotFoundException::forPageNotFound(); +}); diff --git a/system/Config/Services.php b/system/Config/Services.php index 9cba4cb..9fdcc01 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -32,16 +32,49 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Config; +use CodeIgniter\Cache\CacheFactory; +use CodeIgniter\Debug\Exceptions; +use CodeIgniter\Debug\Iterator; +use CodeIgniter\Debug\Timer; +use CodeIgniter\Debug\Toolbar; +use CodeIgniter\Filters\Filters; +use CodeIgniter\Honeypot\Honeypot; +use CodeIgniter\HTTP\CLIRequest; +use CodeIgniter\HTTP\CURLRequest; +use CodeIgniter\HTTP\IncomingRequest; +use CodeIgniter\HTTP\Negotiate; +use CodeIgniter\HTTP\RedirectResponse; +use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\Response; +use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\HTTP\URI; +use CodeIgniter\HTTP\UserAgent; +use CodeIgniter\Language\Language; +use CodeIgniter\Pager\Pager; +use CodeIgniter\Router\RouteCollection; +use CodeIgniter\Router\RouteCollectionInterface; +use CodeIgniter\Router\Router; +use CodeIgniter\Security\Security; +use CodeIgniter\Session\Session; +use CodeIgniter\Throttle\Throttler; +use CodeIgniter\Typography\Typography; +use CodeIgniter\Validation\Validation; +use CodeIgniter\View\Cell; +use CodeIgniter\View\Parser; use Config\App; use CodeIgniter\Database\ConnectionInterface; use CodeIgniter\Database\MigrationRunner; use CodeIgniter\View\RendererInterface; +use Config\Cache; +use Config\Images; +use Config\Logger; +use Config\Migrations; /** * Services Configuration file. @@ -71,7 +104,7 @@ * * @return \CodeIgniter\Cache\CacheInterface */ - public static function cache(\Config\Cache $config = null, bool $getShared = true) + public static function cache(Cache $config = null, bool $getShared = true) { if ($getShared) { @@ -80,10 +113,10 @@ if (! is_object($config)) { - $config = new \Config\Cache(); + $config = new Cache(); } - return \CodeIgniter\Cache\CacheFactory::getHandler($config); + return CacheFactory::getHandler($config); } //-------------------------------------------------------------------- @@ -97,7 +130,7 @@ * * @return \CodeIgniter\HTTP\CLIRequest */ - public static function clirequest(\Config\App $config = null, bool $getShared = true) + public static function clirequest(App $config = null, bool $getShared = true) { if ($getShared) { @@ -109,7 +142,7 @@ $config = config(App::class); } - return new \CodeIgniter\HTTP\CLIRequest($config); + return new CLIRequest($config); } //-------------------------------------------------------------------- @@ -125,7 +158,7 @@ * * @return \CodeIgniter\HTTP\CURLRequest */ - public static function curlrequest(array $options = [], $response = null, \Config\App $config = null, bool $getShared = true) + public static function curlrequest(array $options = [], ResponseInterface $response = null, App $config = null, bool $getShared = true) { if ($getShared === true) { @@ -139,12 +172,12 @@ if (! is_object($response)) { - $response = new \CodeIgniter\HTTP\Response($config); + $response = new Response($config); } - return new \CodeIgniter\HTTP\CURLRequest( + return new CURLRequest( $config, - new \CodeIgniter\HTTP\URI($options['base_uri'] ?? null), + new URI($options['base_uri'] ?? null), $response, $options ); @@ -168,9 +201,9 @@ */ public static function exceptions( \Config\Exceptions $config = null, - \CodeIgniter\HTTP\IncomingRequest $request = null, - \CodeIgniter\HTTP\Response $response = null, - $getShared = true + IncomingRequest $request = null, + Response $response = null, + bool $getShared = true ) { if ($getShared) @@ -193,7 +226,7 @@ $response = static::response(); } - return (new \CodeIgniter\Debug\Exceptions($config, $request, $response)); + return (new Exceptions($config, $request, $response)); } //-------------------------------------------------------------------- @@ -221,7 +254,7 @@ $config = new \Config\Filters(); } - return new \CodeIgniter\Filters\Filters($config, static::request(), static::response()); + return new Filters($config, static::request(), static::response()); } //-------------------------------------------------------------------- @@ -235,7 +268,7 @@ * * @return \CodeIgniter\Honeypot\Honeypot|mixed */ - public static function honeypot(BaseConfig $config = null, $getShared = true) + public static function honeypot(BaseConfig $config = null, bool $getShared = true) { if ($getShared) { @@ -247,7 +280,7 @@ $config = new \Config\Honeypot(); } - return new \CodeIgniter\Honeypot\Honeypot($config); + return new Honeypot($config); } //-------------------------------------------------------------------- @@ -271,7 +304,7 @@ if (empty($config)) { - $config = new \Config\Images(); + $config = new Images(); } $handler = is_null($handler) ? $config->defaultHandler : $handler; @@ -292,14 +325,14 @@ * * @return \CodeIgniter\Debug\Iterator */ - public static function iterator($getShared = true) + public static function iterator(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('iterator'); } - return new \CodeIgniter\Debug\Iterator(); + return new Iterator(); } //-------------------------------------------------------------------- @@ -325,7 +358,7 @@ : static::request() ->getLocale(); - return new \CodeIgniter\Language\Language($locale); + return new Language($locale); } //-------------------------------------------------------------------- @@ -338,19 +371,21 @@ * * @return \CodeIgniter\Log\Logger */ - public static function logger($getShared = true) + public static function logger(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('logger'); } - return new \CodeIgniter\Log\Logger(new \Config\Logger()); + return new \CodeIgniter\Log\Logger(new Logger()); } //-------------------------------------------------------------------- /** + * Return the appropriate igration runner. + * * @param \CodeIgniter\Config\BaseConfig $config * @param \CodeIgniter\Database\ConnectionInterface $db * @param boolean $getShared @@ -364,7 +399,7 @@ return static::getSharedInstance('migrations', $config, $db); } - $config = empty($config) ? new \Config\Migrations() : $config; + $config = empty($config) ? new Migrations() : $config; return new MigrationRunner($config, $db); } @@ -381,7 +416,7 @@ * * @return \CodeIgniter\HTTP\Negotiate */ - public static function negotiator(\CodeIgniter\HTTP\RequestInterface $request = null, bool $getShared = true) + public static function negotiator(RequestInterface $request = null, bool $getShared = true) { if ($getShared) { @@ -393,12 +428,14 @@ $request = static::request(); } - return new \CodeIgniter\HTTP\Negotiate($request); + return new Negotiate($request); } //-------------------------------------------------------------------- /** + * Return the appropriate pagination handler. + * * @param mixed $config * @param \CodeIgniter\View\RendererInterface $view * @param boolean $getShared @@ -422,7 +459,7 @@ $view = static::renderer(); } - return new \CodeIgniter\Pager\Pager($config, $view); + return new Pager($config, $view); } //-------------------------------------------------------------------- @@ -436,7 +473,7 @@ * * @return \CodeIgniter\View\Parser */ - public static function parser($viewPath = null, $config = null, bool $getShared = true) + public static function parser(string $viewPath = null, $config = null, bool $getShared = true) { if ($getShared) { @@ -454,7 +491,7 @@ $viewPath = $paths->viewDirectory; } - return new \CodeIgniter\View\Parser($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true)); + return new Parser($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true)); } //-------------------------------------------------------------------- @@ -470,7 +507,7 @@ * * @return \CodeIgniter\View\View */ - public static function renderer($viewPath = null, $config = null, bool $getShared = true) + public static function renderer(string $viewPath = null, $config = null, bool $getShared = true) { if ($getShared) { @@ -502,7 +539,7 @@ * * @return \CodeIgniter\HTTP\IncomingRequest */ - public static function request(\Config\App $config = null, bool $getShared = true) + public static function request(App $config = null, bool $getShared = true) { if ($getShared) { @@ -514,11 +551,11 @@ $config = config(App::class); } - return new \CodeIgniter\HTTP\IncomingRequest( + return new IncomingRequest( $config, - new \CodeIgniter\HTTP\URI(), + new URI(), 'php://input', - new \CodeIgniter\HTTP\UserAgent() + new UserAgent() ); } @@ -532,7 +569,7 @@ * * @return \CodeIgniter\HTTP\Response */ - public static function response(\Config\App $config = null, bool $getShared = true) + public static function response(App $config = null, bool $getShared = true) { if ($getShared) { @@ -544,7 +581,7 @@ $config = config(App::class); } - return new \CodeIgniter\HTTP\Response($config); + return new Response($config); } //-------------------------------------------------------------------- @@ -557,7 +594,7 @@ * * @return \CodeIgniter\HTTP\Response */ - public static function redirectResponse(\Config\App $config = null, bool $getShared = true) + public static function redirectResponse(App $config = null, bool $getShared = true) { if ($getShared) { @@ -569,7 +606,7 @@ $config = config(App::class); } - $response = new \CodeIgniter\HTTP\RedirectResponse($config); + $response = new RedirectResponse($config); $response->setProtocolVersion(static::request() ->getProtocolVersion()); @@ -586,14 +623,14 @@ * * @return \CodeIgniter\Router\RouteCollection */ - public static function routes($getShared = true) + public static function routes(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('routes'); } - return new \CodeIgniter\Router\RouteCollection(static::locator(), config('Modules')); + return new RouteCollection(static::locator(), config('Modules')); } //-------------------------------------------------------------------- @@ -607,7 +644,7 @@ * * @return \CodeIgniter\Router\Router */ - public static function router(\CodeIgniter\Router\RouteCollectionInterface $routes = null, bool $getShared = true) + public static function router(RouteCollectionInterface $routes = null, bool $getShared = true) { if ($getShared) { @@ -619,7 +656,7 @@ $routes = static::routes(true); } - return new \CodeIgniter\Router\Router($routes); + return new Router($routes); } //-------------------------------------------------------------------- @@ -633,7 +670,7 @@ * * @return \CodeIgniter\Security\Security */ - public static function security(\Config\App $config = null, bool $getShared = true) + public static function security(App $config = null, bool $getShared = true) { if ($getShared) { @@ -645,18 +682,20 @@ $config = config(App::class); } - return new \CodeIgniter\Security\Security($config); + return new Security($config); } //-------------------------------------------------------------------- /** + * Return the session manager. + * * @param \Config\App $config * @param boolean $getShared * * @return \CodeIgniter\Session\Session */ - public static function session(\Config\App $config = null, bool $getShared = true) + public static function session(App $config = null, bool $getShared = true) { if ($getShared) { @@ -674,7 +713,7 @@ $driver = new $driverName($config, static::request()->getIpAddress()); $driver->setLogger($logger); - $session = new \CodeIgniter\Session\Session($driver, $config); + $session = new Session($driver, $config); $session->setLogger($logger); if (session_status() === PHP_SESSION_NONE) @@ -695,14 +734,14 @@ * * @return \CodeIgniter\Throttle\Throttler */ - public static function throttler($getShared = true) + public static function throttler(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('throttler'); } - return new \CodeIgniter\Throttle\Throttler(static::cache()); + return new Throttler(static::cache()); } //-------------------------------------------------------------------- @@ -715,19 +754,21 @@ * * @return \CodeIgniter\Debug\Timer */ - public static function timer($getShared = true) + public static function timer(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('timer'); } - return new \CodeIgniter\Debug\Timer(); + return new Timer(); } //-------------------------------------------------------------------- /** + * Return the debug toolbar. + * * @param \Config\Toolbar $config * @param boolean $getShared * @@ -745,7 +786,7 @@ $config = config('Toolbar'); } - return new \CodeIgniter\Debug\Toolbar($config); + return new Toolbar($config); } //-------------------------------------------------------------------- @@ -758,14 +799,14 @@ * * @return \CodeIgniter\HTTP\URI */ - public static function uri($uri = null, bool $getShared = true) + public static function uri(string $uri = null, bool $getShared = true) { if ($getShared) { return static::getSharedInstance('uri', $uri); } - return new \CodeIgniter\HTTP\URI($uri); + return new URI($uri); } //-------------------------------------------------------------------- @@ -790,7 +831,7 @@ $config = config('Validation'); } - return new \CodeIgniter\Validation\Validation($config, static::renderer()); + return new Validation($config, static::renderer()); } //-------------------------------------------------------------------- @@ -803,14 +844,14 @@ * * @return \CodeIgniter\View\Cell */ - public static function viewcell($getShared = true) + public static function viewcell(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('viewcell'); } - return new \CodeIgniter\View\Cell(static::cache()); + return new Cell(static::cache()); } //-------------------------------------------------------------------- @@ -822,14 +863,14 @@ * * @return \CodeIgniter\Typography\Typography */ - public static function typography($getShared = true) + public static function typography(bool $getShared = true) { if ($getShared) { return static::getSharedInstance('typography'); } - return new \CodeIgniter\Typography\Typography(); + return new Typography(); } //-------------------------------------------------------------------- diff --git a/system/Config/View.php b/system/Config/View.php index 68eff58..fcbf333 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -44,6 +44,11 @@ class View extends BaseConfig { + /** + * Built-in View filters. + * + * @var type + */ protected $coreFilters = [ 'abs' => '\abs', 'capitalize' => '\CodeIgniter\View\Filters::capitalize', @@ -67,6 +72,12 @@ 'title' => '\CodeIgniter\View\Filters::title', 'upper' => '\strtoupper', ]; + + /** + * Built-in View plugins. + * + * @var type + */ protected $corePlugins = [ 'current_url' => '\CodeIgniter\View\Plugins::currentURL', 'previous_url' => '\CodeIgniter\View\Plugins::previousURL', @@ -78,6 +89,12 @@ 'siteURL' => '\CodeIgniter\View\Plugins::siteURL', ]; + /** + * Constructor. + * + * Merge the built-in and developer-configured filters and plugins, + * with preference to the developer ones. + */ public function __construct() { $this->filters = array_merge($this->coreFilters, $this->filters); diff --git a/system/Controller.php b/system/Controller.php index 624e0c0..25a9d45 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index ff67d1f..3bab4f1 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -524,10 +524,10 @@ * * Generates the JOIN portion of the query * - * @param string $table - * @param string $cond The join condition - * @param string $type The type of join - * @param boolean $escape Whether not to try to escape identifiers + * @param string $table + * @param string $cond The join condition + * @param string $type The type of join + * @param boolean $escape Whether not to try to escape identifiers * * @return BaseBuilder */ @@ -706,7 +706,7 @@ $v = " :$bind:"; } - elseif (! $this->hasOperator($k)) + elseif (! $this->hasOperator($k) && $qb_key !== 'QBHaving') { // value appears not to have been set, assign the test to IS NULL $k .= ' IS NULL'; @@ -1016,15 +1016,15 @@ /** * Platform independent LIKE statement builder. * - * @param string $prefix - * @param string $column - * @param string $not - * @param string $bind - * @param boolean $insensitiveSearch + * @param string $prefix + * @param string $column + * @param string $not + * @param string $bind + * @param boolean $insensitiveSearch * * @return string $like_statement */ - public function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string + protected function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string { $like_statement = "{$prefix} {$column} {$not} LIKE :{$bind}:"; @@ -1136,7 +1136,7 @@ { if ($this->QBWhereGroupStarted) { - $type = ''; + $type = ''; $this->QBWhereGroupStarted = false; } @@ -1148,8 +1148,8 @@ /** * GROUP BY * - * @param string|array $by - * @param boolean $escape + * @param string|array $by + * @param boolean $escape * * @return BaseBuilder */ @@ -1187,9 +1187,9 @@ * * Separates multiple calls with 'AND'. * - * @param string|array $key - * @param mixed $value - * @param boolean $escape + * @param string|array $key + * @param mixed $value + * @param boolean $escape * * @return BaseBuilder */ @@ -1205,9 +1205,9 @@ * * Separates multiple calls with 'OR'. * - * @param string|array $key - * @param mixed $value - * @param boolean $escape + * @param string|array $key + * @param mixed $value + * @param boolean $escape * * @return BaseBuilder */ @@ -1251,7 +1251,7 @@ if ($escape === false) { - $qb_orderby[] = [ + $qb_orderBy[] = [ 'field' => $orderBy, 'direction' => $direction, 'escape' => false, @@ -1259,10 +1259,10 @@ } else { - $qb_orderby = []; + $qb_orderBy = []; foreach (explode(',', $orderBy) as $field) { - $qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) + $qb_orderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) ? [ 'field' => ltrim(substr($field, 0, $match[0][1])), @@ -1278,7 +1278,7 @@ } } - $this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderby); + $this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderBy); return $this; } @@ -1371,7 +1371,7 @@ { if ($escape) { - $bind = $this->setBind($k, $v, $escape); + $bind = $this->setBind($k, $v, $escape); $this->QBSet[$this->db->protectIdentifiers($k, false, $escape)] = ":$bind:"; } else @@ -1594,9 +1594,9 @@ * * Allows the where clause, limit and offset to be added directly * - * @param string|array $where - * @param integer $limit - * @param integer $offset + * @param string|array $where + * @param integer $limit + * @param integer $offset * * @return ResultInterface */ @@ -1852,7 +1852,7 @@ * validate that the there data is actually being set and that table * has been chosen to be inserted into. * - * @return bool + * @return boolean * @throws DatabaseException */ protected function validateInsert(): bool @@ -2160,7 +2160,7 @@ // Batch this baby $affected_rows = 0; - $savedSQL = []; + $savedSQL = []; for ($i = 0, $total = count($this->QBSet); $i < $total; $i += $batchSize) { $sql = $this->_updateBatch($table, array_slice($this->QBSet, $i, $batchSize), $this->db->protectIdentifiers($index) @@ -2199,7 +2199,7 @@ */ protected function _updateBatch(string $table, array $values, string $index): string { - $ids = []; + $ids = []; $final = []; foreach ($values as $key => $val) { @@ -2232,9 +2232,9 @@ /** * The "setUpdateBatch" function. Allows key/value pairs to be set for batch updating * - * @param array|object $key - * @param string $index - * @param boolean $escape + * @param array|object $key + * @param string $index + * @param boolean $escape * * @return BaseBuilder|null * @throws \CodeIgniter\Database\Exceptions\DatabaseException @@ -2504,6 +2504,7 @@ { $this->trackAliases($t); } + return; } // Does the string contain a comma? If so, we need to separate diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 7e16330..496c77f 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -422,12 +422,14 @@ * @param boolean $persistent * @return mixed */ - abstract public function connect($persistent = false); + abstract public function connect(bool $persistent = false); //-------------------------------------------------------------------- /** * Close the database connection. + * + * @return void */ public function close() { @@ -526,9 +528,9 @@ /** * The name of the platform in use (MySQLi, mssql, etc) * - * @return mixed + * @return string */ - public function getPlatform() + public function getPlatform(): string { return $this->DBDriver; } @@ -538,9 +540,9 @@ /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - abstract public function getVersion(); + abstract public function getVersion(): string; //-------------------------------------------------------------------- @@ -586,7 +588,7 @@ * * @return mixed */ - abstract protected function execute($sql); + abstract protected function execute(string $sql); //-------------------------------------------------------------------- @@ -599,13 +601,13 @@ * queries if needed. * * @param string $sql - * @param array ...$binds + * @param mixed ...$binds * @param boolean $setEscapeFlags * @param string $queryClass * * @return BaseResult|Query|false */ - public function query(string $sql, $binds = null, bool $setEscapeFlags = true, $queryClass = 'CodeIgniter\\Database\\Query') + public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = 'CodeIgniter\\Database\\Query') { if (empty($this->connID)) { @@ -713,6 +715,8 @@ * Disable Transactions * * This permits transactions to be disabled at run-time. + * + * @return void */ public function transOff() { @@ -750,7 +754,7 @@ * @param boolean $test_mode = FALSE * @return boolean */ - public function transStart($test_mode = false) + public function transStart(bool $test_mode = false): bool { if (! $this->transEnabled) { @@ -767,7 +771,7 @@ * * @return boolean */ - public function transComplete() + public function transComplete(): bool { if (! $this->transEnabled) { @@ -924,7 +928,7 @@ /** * Returns an instance of the query builder for this connection. * - * @param string $tableName + * @param string|array $tableName * * @return BaseBuilder * @throws DatabaseException @@ -1008,7 +1012,7 @@ * * @return string */ - public function showLastQuery() + public function showLastQuery(): string { return (string) $this->lastQuery; } @@ -1023,7 +1027,7 @@ * * @return float */ - public function getConnectStart() + public function getConnectStart(): float { return $this->connectTime; } @@ -1038,9 +1042,9 @@ * * @param integer $decimals * - * @return mixed + * @return string */ - public function getConnectDuration($decimals = 6) + public function getConnectDuration(int $decimals = 6): string { return number_format($this->connectDuration, $decimals); } @@ -1067,14 +1071,14 @@ * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @param string|array - * @param boolean - * @param mixed - * @param boolean + * @param string|array $item + * @param boolean $prefixSingle + * @param boolean $protectIdentifiers + * @param boolean $fieldExists * * @return string|array */ - public function protectIdentifiers($item, $prefixSingle = false, $protectIdentifiers = null, $fieldExists = true) + public function protectIdentifiers($item, bool $prefixSingle = false, bool $protectIdentifiers = null, bool $fieldExists = true) { if (! is_bool($protectIdentifiers)) { @@ -1243,7 +1247,7 @@ * * This function escapes column and table names * - * @param mixed + * @param mixed $item * * @return mixed */ @@ -1313,7 +1317,7 @@ * @return string * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function prefixTable($table = '') + public function prefixTable(string $table = ''): string { if ($table === '') { @@ -1334,7 +1338,7 @@ * * @return string */ - public function setPrefix($prefix = '') + public function setPrefix(string $prefix = ''): string { return $this->DBPrefix = $prefix; } @@ -1356,7 +1360,7 @@ * Escapes data based on type. * Sets boolean and null types * - * @param $str + * @param mixed $str * * @return mixed */ @@ -1395,9 +1399,9 @@ * * @param string|string[] $str Input string * @param boolean $like Whether or not the string will be used in a LIKE condition - * @return string + * @return string|string[] */ - public function escapeString($str, $like = false) + public function escapeString($str, bool $like = false) { if (is_array($str)) { @@ -1438,7 +1442,7 @@ * specific escaping for LIKE conditions * * @param string|string[] - * @return mixed + * @return string|string[] */ public function escapeLikeString($str) { @@ -1473,7 +1477,7 @@ * @return boolean * @throws DatabaseException */ - public function callFunction(string $functionName, ...$params) + public function callFunction(string $functionName, ...$params): bool { $driver = ($this->DBDriver === 'postgre' ? 'pg' : strtolower($this->DBDriver)) . '_'; @@ -1503,11 +1507,11 @@ /** * Returns an array of table names * - * @param boolean $constrain_by_prefix = FALSE + * @param boolean $constrainByPrefix = FALSE * @return boolean|array * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function listTables($constrain_by_prefix = false) + public function listTables(bool $constrainByPrefix = false) { // Is there a cached result? if (isset($this->dataCache['table_names']) && $this->dataCache['table_names']) @@ -1515,7 +1519,7 @@ return $this->dataCache['table_names']; } - if (false === ($sql = $this->_listTables($constrain_by_prefix))) + if (false === ($sql = $this->_listTables($constrainByPrefix))) { if ($this->DBDebug) { @@ -1563,12 +1567,12 @@ /** * Determine if a particular table exists * - * @param string $table_name + * @param string $tableName * @return boolean */ - public function tableExists($table_name) + public function tableExists(string $tableName): bool { - return in_array($this->protectIdentifiers($table_name, true, false, false), $this->listTables()); + return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables()); } //-------------------------------------------------------------------- @@ -1581,7 +1585,7 @@ * @return array|false * @throws DatabaseException */ - public function getFieldNames($table) + public function getFieldNames(string $table) { // Is there a cached result? if (isset($this->dataCache['field_names'][$table])) @@ -1637,11 +1641,11 @@ /** * Determine if a particular field exists * - * @param string - * @param string + * @param string $fieldName + * @param string $tableName * @return boolean */ - public function fieldExists($fieldName, $tableName) + public function fieldExists(string $fieldName, string $tableName): bool { return in_array($fieldName, $this->getFieldNames($tableName)); } @@ -1735,7 +1739,7 @@ * * @return array */ - abstract public function error(); + abstract public function error(): array; //-------------------------------------------------------------------- @@ -1744,7 +1748,7 @@ * * @return integer */ - abstract public function insertID(); + abstract public function insertID(): int; //-------------------------------------------------------------------- @@ -1755,7 +1759,7 @@ * * @return string */ - abstract protected function _listTables($constrainByPrefix = false): string; + abstract protected function _listTables(bool $constrainByPrefix = false): string; //-------------------------------------------------------------------- @@ -1803,12 +1807,21 @@ //-------------------------------------------------------------------- - public function __get($key) + /** + * Accessor for properties if they exist. + * + * @param string $key + * + * @return mixed + */ + public function __get(string $key) { if (property_exists($this, $key)) { return $this->$key; } + + return null; } //-------------------------------------------------------------------- diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 887f906..cbcfff7 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -31,12 +31,13 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Database; +use CodeIgniter\Database\MySQLi\Connection; use CodeIgniter\Events\Events; /** @@ -83,9 +84,14 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param \CodeIgniter\Database\ConnectionInterface $db + */ public function __construct(ConnectionInterface $db) { - $this->db = & $db; + $this->db = &$db; } //-------------------------------------------------------------------- @@ -103,7 +109,7 @@ * * @return mixed */ - public function prepare(string $sql, array $options = [], $queryClass = 'CodeIgniter\\Database\\Query') + public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query') { // We only supports positional placeholders (?) // in order to work with the execute method below, so we @@ -180,9 +186,9 @@ * * @param array $data * - * @return ResultInterface + * @return boolean */ - abstract public function _execute($data); + abstract public function _execute(array $data): bool; //-------------------------------------------------------------------- @@ -196,7 +202,9 @@ //-------------------------------------------------------------------- /** - * Explicity closes the statement. + * Explicitly closes the statement. + * + * @return null|void */ public function close() { @@ -232,7 +240,7 @@ * * @return boolean */ - public function hasError() + public function hasError(): bool { return ! empty($this->errorString); } diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index 5e28509..08e485d 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -123,9 +123,9 @@ * * @param string $type The row type. Either 'array', 'object', or a class name to use * - * @return mixed + * @return array */ - public function getResult($type = 'object'): array + public function getResult(string $type = 'object'): array { if ($type === 'array') { @@ -154,7 +154,8 @@ { return $this->customResultObject[$className]; } - elseif (! $this->resultID || $this->numRows === 0) + + if (is_bool($this->resultID) || ! $this->resultID || $this->numRows === 0) { return []; } @@ -215,7 +216,7 @@ // In the event that query caching is on, the result_id variable // will not be a valid resource so we'll simply return an empty // array. - if (! $this->resultID || $this->numRows === 0) + if (is_bool($this->resultID) || ! $this->resultID || $this->numRows === 0) { return []; } @@ -258,7 +259,7 @@ // In the event that query caching is on, the result_id variable // will not be a valid resource so we'll simply return an empty // array. - if (! $this->resultID || $this->numRows === 0) + if (is_bool($this->resultID) || ! $this->resultID || $this->numRows === 0) { return []; } @@ -290,17 +291,17 @@ * * If row doesn't exist, returns null. * - * @param integer $n The index of the results to return - * @param string $type The type of result object. 'array', 'object' or class name. + * @param mixed $n The index of the results to return + * @param string $type The type of result object. 'array', 'object' or class name. * * @return mixed */ - public function getRow($n = 0, $type = 'object') + public function getRow($n = 0, string $type = 'object') { if (! is_numeric($n)) { // We cache the row data for subsequent uses - is_array($this->rowData) || $this->row_data = $this->getRowArray(0); + is_array($this->rowData) || $this->rowData = $this->getRowArray(0); // array_key_exists() instead of isset() to allow for NULL values if (empty($this->rowData) || ! array_key_exists($n, $this->rowData)) @@ -335,7 +336,7 @@ * * @return mixed */ - public function getCustomRowObject($n, string $className) + public function getCustomRowObject(int $n, string $className) { isset($this->customResultObject[$className]) || $this->getCustomResultObject($className); @@ -363,7 +364,7 @@ * * @return mixed */ - public function getRowArray($n = 0) + public function getRowArray(int $n = 0) { $result = $this->getResultArray(); if (empty($result)) @@ -390,7 +391,7 @@ * * @return mixed */ - public function getRowObject($n = 0) + public function getRowObject(int $n = 0) { $result = $this->getResultObject(); if (empty($result)) @@ -411,8 +412,8 @@ /** * Assigns an item into a particular column slot. * - * @param $key - * @param null $value + * @param mixed $key + * @param mixed $value * * @return mixed */ @@ -421,7 +422,7 @@ // We cache the row data for subsequent uses if (! is_array($this->rowData)) { - $this->row_data = $this->getRowArray(0); + $this->rowData = $this->getRowArray(0); } if (is_array($key)) @@ -449,7 +450,7 @@ * * @return mixed */ - public function getFirstRow($type = 'object') + public function getFirstRow(string $type = 'object') { $result = $this->getResult($type); @@ -465,7 +466,7 @@ * * @return mixed */ - public function getLastRow($type = 'object') + public function getLastRow(string $type = 'object') { $result = $this->getResult($type); @@ -481,7 +482,7 @@ * * @return mixed */ - public function getNextRow($type = 'object') + public function getNextRow(string $type = 'object') { $result = $this->getResult($type); if (empty($result)) @@ -501,7 +502,7 @@ * * @return mixed */ - public function getPreviousRow($type = 'object') + public function getPreviousRow(string $type = 'object') { $result = $this->getResult($type); if (empty($result)) @@ -526,7 +527,7 @@ * * @return mixed */ - public function getUnbufferedRow($type = 'object') + public function getUnbufferedRow(string $type = 'object') { if ($type === 'array') { @@ -572,7 +573,7 @@ /** * Frees the current result. * - * @return mixed + * @return void */ abstract public function freeResult(); @@ -587,7 +588,7 @@ * * @return mixed */ - abstract public function dataSeek($n = 0); + abstract public function dataSeek(int $n = 0); //-------------------------------------------------------------------- @@ -596,7 +597,7 @@ * * Overridden by driver classes. * - * @return array + * @return mixed */ abstract protected function fetchAssoc(); @@ -611,7 +612,7 @@ * * @return object */ - abstract protected function fetchObject($className = 'stdClass'); + abstract protected function fetchObject(string $className = 'stdClass'); //-------------------------------------------------------------------- } diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index 72deff4..a512d23 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -136,7 +136,7 @@ * @param string $database_name * @return boolean */ - public function databaseExists($database_name) + public function databaseExists(string $database_name): bool { return in_array($database_name, $this->listDatabases()); } @@ -147,10 +147,10 @@ * Optimize Table * * @param string $table_name - * @return boolean|mixed + * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function optimizeTable($table_name) + public function optimizeTable(string $table_name) { if ($this->optimizeTable === false) { @@ -200,11 +200,21 @@ } // Build the result array... - $res = $res->getResultArray(); - $res = current($res); - $key = str_replace($this->db->database . '.', '', current($res)); - $keys = array_keys($res); - unset($res[$keys[0]]); + + $res = $res->getResultArray(); + + // Postgre & SQLite3 returns empty array + if (empty($res)) + { + $key = $table_name; + } + else + { + $res = current($res); + $key = str_replace($this->db->database . '.', '', current($res)); + $keys = array_keys($res); + unset($res[$keys[0]]); + } $result[$key] = $res; } @@ -221,7 +231,7 @@ * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function repairTable($table_name) + public function repairTable(string $table_name) { if ($this->repairTable === false) { @@ -254,7 +264,7 @@ * * @return string */ - public function getCSVFromResult(ResultInterface $query, $delim = ',', $newline = "\n", $enclosure = '"') + public function getCSVFromResult(ResultInterface $query, string $delim = ',', string $newline = "\n", string $enclosure = '"') { $out = ''; // First generate the headings from the table column names @@ -289,7 +299,7 @@ * * @return string */ - public function getXMLFromResult(ResultInterface $query, $params = []) + public function getXMLFromResult(ResultInterface $query, array $params = []): string { // Set our default values foreach (['root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t"] as $key => $val) @@ -304,7 +314,7 @@ extract($params); // Load the xml helper - helper('xml'); + helper('xml'); // Generate the result $xml = '<' . $root . '>' . $newline; while ($row = $query->getUnbufferedRow()) @@ -312,7 +322,8 @@ $xml .= $tab . '<' . $element . '>' . $newline; foreach ($row as $key => $val) { - $xml .= $tab . $tab . '<' . $key . '>' . xml_convert($val) . '' . $newline; + $val = (! empty($val)) ? xml_convert($val) : ''; + $xml .= $tab . $tab . '<' . $key . '>' . $val . '' . $newline; } $xml .= $tab . '' . $newline; } @@ -325,7 +336,7 @@ /** * Database Backup * - * @param array $params + * @param array|string $params * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ @@ -379,7 +390,7 @@ // Is the encoder supported? If not, we'll either issue an // error or use plain text depending on the debug settings if (($prefs['format'] === 'gzip' && ! function_exists('gzencode')) - || ( $prefs['format'] === 'zip' && ! function_exists('gzcompress'))) + || ( $prefs['format'] === 'zip' && ! function_exists('gzcompress'))) { if ($this->db->DBDebug) { @@ -396,7 +407,7 @@ if ($prefs['filename'] === '') { $prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database) - . date('Y-m-d_H-i', time()) . '.sql'; + . date('Y-m-d_H-i', time()) . '.sql'; } else { diff --git a/system/Database/Config.php b/system/Database/Config.php index f94c663..5588035 100644 --- a/system/Database/Config.php +++ b/system/Database/Config.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -125,7 +125,7 @@ * * @return array */ - public static function getConnections() + public static function getConnections(): array { return static::$instances; } @@ -186,12 +186,12 @@ */ protected static function ensureFactory() { - if (static::$factory instanceof \CodeIgniter\Database\Database) + if (static::$factory instanceof Database) { return; } - static::$factory = new \CodeIgniter\Database\Database(); + static::$factory = new Database(); } //-------------------------------------------------------------------- diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index 76f8a64..302af16 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -61,7 +61,7 @@ * @param boolean $persistent * @return mixed */ - public function connect($persistent = false); + public function connect(bool $persistent = false); //-------------------------------------------------------------------- @@ -130,18 +130,18 @@ /** * The name of the platform in use (MySQLi, mssql, etc) * - * @return mixed + * @return string */ - public function getPlatform(); + public function getPlatform(): string; //-------------------------------------------------------------------- /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion(); + public function getVersion(): string; //-------------------------------------------------------------------- @@ -154,7 +154,7 @@ * queries if needed. * * @param string $sql - * @param array ...$binds + * @param mixed ...$binds * * @return mixed */ @@ -201,7 +201,7 @@ * Escapes data based on type. * Sets boolean and null types. * - * @param string $str + * @param mixed $str * * @return mixed */ diff --git a/system/Database/Database.php b/system/Database/Database.php index ad4e8aa..ec9c272 100644 --- a/system/Database/Database.php +++ b/system/Database/Database.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/Exceptions/DataException.php b/system/Database/Exceptions/DataException.php index 966c6ef..2af1793 100644 --- a/system/Database/Exceptions/DataException.php +++ b/system/Database/Exceptions/DataException.php @@ -1,4 +1,6 @@ -db->DBDebug) { - throw new DatabaseException('Unable to drop the specified database.'); + throw new DatabaseException('Unable to create the specified database.'); } return false; @@ -385,16 +385,16 @@ /** * Add Foreign Key * - * @param string $fieldName - * @param string $tableName - * @param string $tableField - * @param boolean $onUpdate - * @param boolean $onDelete + * @param string $fieldName + * @param string $tableName + * @param string $tableField + * @param string $onUpdate + * @param string $onDelete * * @return \CodeIgniter\Database\Forge * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function addForeignKey(string $fieldName = '', string $tableName = '', string $tableField = '', bool $onUpdate = false, bool $onDelete = false) + public function addForeignKey(string $fieldName = '', string $tableName = '', string $tableField = '', string $onUpdate = '', string $onDelete = '') { if (! isset($this->fields[$fieldName])) { @@ -715,8 +715,8 @@ /** * Column Add * - * @param string $table Table name - * @param string|array $field Column definition + * @param string $table Table name + * @param string|array $field Column definition * * @return boolean * @throws \CodeIgniter\Database\Exceptions\DatabaseException @@ -786,8 +786,8 @@ /** * Column Modify * - * @param string $table Table name - * @param string|array $field Column definition + * @param string $table Table name + * @param string|array $field Column definition * * @return boolean * @throws \CodeIgniter\Database\Exceptions\DatabaseException diff --git a/system/Database/Migration.php b/system/Database/Migration.php index eb27199..bfa31a9 100644 --- a/system/Database/Migration.php +++ b/system/Database/Migration.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -86,7 +86,7 @@ * * @return string */ - public function getDBGroup() + public function getDBGroup(): string { return $this->DBGroup; } diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index 810e9a9..2154ab4 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -342,7 +342,7 @@ * * @return boolean */ - public function latestAll(string $group = null) + public function latestAll(string $group = null): bool { $this->ensureTable(); @@ -387,7 +387,7 @@ * * @param string|null $group * - * @return mixed TRUE if no migrations are found, current version string on success, FALSE on failure + * @return mixed Current version string on success, FALSE on failure or no migrations are found */ public function current(string $group = null) { @@ -409,7 +409,7 @@ * * @return array list of migrations as $version for one namespace */ - public function findMigrations() + public function findMigrations(): array { $migrations = []; @@ -471,11 +471,11 @@ * * @param array $migrations * @param string $method - * @param string $targetversion + * @param string $targetVersion * * @return boolean */ - protected function checkMigrations(array $migrations, string $method, string $targetversion) + protected function checkMigrations(array $migrations, string $method, string $targetVersion): bool { // Check if no migrations found if (empty($migrations)) @@ -487,14 +487,14 @@ throw new \RuntimeException(lang('Migrations.empty')); } - // Check if $targetversion file is found - if ((int)$targetversion !== 0 && ! array_key_exists($targetversion, $migrations)) + // Check if $targetVersion file is found + if ((int)$targetVersion !== 0 && ! array_key_exists($targetVersion, $migrations)) { if ($this->silent) { return false; } - throw new \RuntimeException(lang('Migrations.notFound') . $targetversion); + throw new \RuntimeException(lang('Migrations.notFound') . $targetVersion); } ksort($migrations); @@ -601,7 +601,7 @@ * * @return array */ - public function getHistory(string $group = 'default') + public function getHistory(string $group = 'default'): array { $this->ensureTable(); @@ -645,7 +645,7 @@ * * @return string Numeric portion of a migration filename */ - protected function getMigrationNumber(string $migration) + protected function getMigrationNumber(string $migration): string { return sscanf($migration, '%[0-9]+', $number) ? $number : '0'; } @@ -659,7 +659,7 @@ * * @return string text portion of a migration filename */ - protected function getMigrationName(string $migration) + protected function getMigrationName(string $migration): string { $parts = explode('_', $migration); array_shift($parts); @@ -674,7 +674,7 @@ * * @return string Current migration version */ - protected function getVersion() + protected function getVersion(): string { $this->ensureTable(); @@ -695,7 +695,7 @@ * * @return array Current migration version */ - public function getCliMessages() + public function getCliMessages(): array { return $this->cliMessages; } @@ -708,6 +708,8 @@ * @param string $version * * @internal param string $migration Migration reached + * + * @return void */ protected function addHistory(string $version) { @@ -730,7 +732,8 @@ /** * Removes a single history * - * @param string $version + * @param string $version + * @return void */ protected function removeHistory(string $version) { diff --git a/system/Database/MySQLi/Builder.php b/system/Database/MySQLi/Builder.php index 264171e..6bfe554 100644 --- a/system/Database/MySQLi/Builder.php +++ b/system/Database/MySQLi/Builder.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 7c6d45c..6edc28c 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -89,7 +89,7 @@ * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function connect($persistent = false) + public function connect(bool $persistent = false) { // Do we have a socket path? if ($this->hostname[0] === '/') @@ -245,6 +245,8 @@ /** * Close the database connection. + * + * @return void */ protected function _close() { @@ -258,9 +260,9 @@ * * @param string $databaseName * - * @return mixed + * @return boolean */ - public function setDatabase(string $databaseName) + public function setDatabase(string $databaseName): bool { if ($databaseName === '') { @@ -287,9 +289,9 @@ /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { if (isset($this->dataCache['version'])) { @@ -313,7 +315,7 @@ * * @return mixed */ - public function execute($sql) + public function execute(string $sql) { while ($this->connID->more_results()) { @@ -338,7 +340,7 @@ * * @return string */ - protected function prepQuery($sql) + protected function prepQuery(string $sql): string { // mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack // modifies the query so that it a proper number of affected rows is returned. @@ -355,7 +357,7 @@ /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return integer */ public function affectedRows(): int { @@ -394,7 +396,7 @@ * * @return string */ - protected function _listTables($prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false): string { $sql = 'SHOW TABLES FROM ' . $this->escapeIdentifiers($this->database); @@ -439,19 +441,19 @@ } $query = $query->getResultObject(); - $retval = []; + $retVal = []; for ($i = 0, $c = count($query); $i < $c; $i++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $query[$i]->Field; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $query[$i]->Field; - sscanf($query[$i]->Type, '%[a-z](%d)', $retval[$i]->type, $retval[$i]->max_length); + sscanf($query[$i]->Type, '%[a-z](%d)', $retVal[$i]->type, $retVal[$i]->max_length); - $retval[$i]->default = $query[$i]->Default; - $retval[$i]->primary_key = (int)($query[$i]->Key === 'PRI'); + $retVal[$i]->default = $query[$i]->Default; + $retVal[$i]->primary_key = (int)($query[$i]->Key === 'PRI'); } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -550,7 +552,7 @@ } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -558,10 +560,10 @@ $obj->table_name = $row->TABLE_NAME; $obj->foreign_table_name = $row->REFERENCED_TABLE_NAME; - $retval[] = $obj; + $retVal[] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -575,7 +577,7 @@ * * @return array */ - public function error() + public function error(): array { if (! empty($this->mysqli->connect_errno)) { @@ -598,7 +600,7 @@ * * @return integer */ - public function insertID() + public function insertID(): int { return $this->connID->insert_id; } diff --git a/system/Database/MySQLi/Forge.php b/system/Database/MySQLi/Forge.php index 188625e..52168af 100644 --- a/system/Database/MySQLi/Forge.php +++ b/system/Database/MySQLi/Forge.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/MySQLi/PreparedQuery.php b/system/Database/MySQLi/PreparedQuery.php index 668df92..a510a37 100644 --- a/system/Database/MySQLi/PreparedQuery.php +++ b/system/Database/MySQLi/PreparedQuery.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,6 +41,9 @@ use CodeIgniter\Database\PreparedQueryInterface; use CodeIgniter\Database\BasePreparedQuery; +/** + * Prepared query for MySQLi + */ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface { @@ -80,9 +83,9 @@ * * @param array $data * - * @return \CodeIgniter\Database\ResultInterface + * @return boolean */ - public function _execute($data) + public function _execute(array $data): bool { if (is_null($this->statement)) { diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index 2906324..4299b36 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -85,26 +85,28 @@ */ public function getFieldData(): array { - $retval = []; + $retVal = []; $fieldData = $this->resultID->fetch_fields(); foreach ($fieldData as $i => $data) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $data->name; - $retval[$i]->type = $data->type; - $retval[$i]->max_length = $data->max_length; - $retval[$i]->primary_key = (int) ($data->flags & 2); - $retval[$i]->default = $data->def; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $data->name; + $retVal[$i]->type = $data->type; + $retVal[$i]->max_length = $data->max_length; + $retVal[$i]->primary_key = (int) ($data->flags & 2); + $retVal[$i]->default = $data->def; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- /** * Frees the current result. + * + * @return void */ public function freeResult() { @@ -126,7 +128,7 @@ * * @return mixed */ - public function dataSeek($n = 0) + public function dataSeek(int $n = 0) { return $this->resultID->data_seek($n); } @@ -138,7 +140,7 @@ * * Overridden by driver classes. * - * @return array + * @return mixed */ protected function fetchAssoc() { @@ -156,7 +158,7 @@ * * @return object */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject(string $className = 'stdClass') { return $this->resultID->fetch_object($className); } diff --git a/system/Database/MySQLi/Utils.php b/system/Database/MySQLi/Utils.php index 25d4036..5ebe7fb 100644 --- a/system/Database/MySQLi/Utils.php +++ b/system/Database/MySQLi/Utils.php @@ -32,18 +32,19 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Database\MySQLi; +use CodeIgniter\Database\BaseUtils; use CodeIgniter\Database\Exceptions\DatabaseException; /** * Utils for MySQLi */ -class Utils extends \CodeIgniter\Database\BaseUtils +class Utils extends BaseUtils { /** diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 7ab065a..9704c8c 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -53,7 +53,6 @@ */ protected $randomKeyword = [ 'RANDOM()', - 'RANDOM()', ]; //-------------------------------------------------------------------- @@ -98,7 +97,7 @@ * @param string $column * @param integer $value * - * @return boolean + * @return mixed */ public function increment(string $column, int $value = 1) { @@ -117,7 +116,7 @@ * @param string $column * @param integer $value * - * @return boolean + * @return mixed */ public function decrement(string $column, int $value = 1) { @@ -141,7 +140,7 @@ * @param array $set An associative array of insert values * @param boolean $returnSQL * - * @return boolean TRUE on success, FALSE on failure + * @return mixed * @throws DatabaseException * @internal param true $bool returns the generated SQL, false executes the query. */ @@ -351,11 +350,11 @@ * * @see https://www.postgresql.org/docs/9.2/static/functions-matching.html * - * @param string $prefix - * @param string $column - * @param string $not - * @param string $bind - * @param boolean $insensitiveSearch + * @param string $prefix + * @param string $column + * @param string $not + * @param string $bind + * @param boolean $insensitiveSearch * * @return string $like_statement */ diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 56aec4f..d69314b 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -78,7 +78,7 @@ * @param boolean $persistent * @return mixed */ - public function connect($persistent = false) + public function connect(bool $persistent = false) { if (empty($this->DSN)) { @@ -121,7 +121,7 @@ * Keep or establish the connection if no queries have been sent for * a length of time exceeding the server's idle timeout. * - * @return mixed + * @return void */ public function reconnect() { @@ -135,6 +135,8 @@ /** * Close the database connection. + * + * @return void */ protected function _close() { @@ -148,9 +150,9 @@ * * @param string $databaseName * - * @return mixed + * @return boolean */ - public function setDatabase(string $databaseName) + public function setDatabase(string $databaseName): bool { return false; } @@ -160,9 +162,9 @@ /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { if (isset($this->dataCache['version'])) { @@ -186,7 +188,7 @@ * * @return resource */ - public function execute($sql) + public function execute(string $sql) { return pg_query($this->connID, $sql); } @@ -196,7 +198,7 @@ /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return integer */ public function affectedRows(): int { @@ -210,7 +212,7 @@ * * Escapes data based on type * - * @param string $str + * @param mixed $str * @return mixed */ public function escape($str) @@ -259,7 +261,7 @@ * * @return string */ - protected function _listTables($prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false): string { $sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \'' . $this->schema . "'"; @@ -312,17 +314,17 @@ } $query = $query->getResultObject(); - $retval = []; + $retVal = []; for ($i = 0, $c = count($query); $i < $c; $i ++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $query[$i]->column_name; - $retval[$i]->type = $query[$i]->data_type; - $retval[$i]->default = $query[$i]->column_default; - $retval[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $query[$i]->column_name; + $retVal[$i]->type = $query[$i]->data_type; + $retVal[$i]->default = $query[$i]->column_default; + $retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -347,7 +349,7 @@ } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -366,10 +368,10 @@ $obj->type = (strpos($row->indexdef, 'CREATE UNIQUE') === 0) ? 'UNIQUE' : 'INDEX'; } - $retval[$obj->name] = $obj; + $retVal[$obj->name] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -401,17 +403,17 @@ } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); $obj->constraint_name = $row->constraint_name; $obj->table_name = $row->table_name; $obj->foreign_table_name = $row->foreign_table_name; - $retval[] = $obj; + $retVal[] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -425,7 +427,7 @@ * * @return array */ - public function error() + public function error(): array { return [ 'code' => '', @@ -440,7 +442,7 @@ * * @return integer */ - public function insertID() + public function insertID(): int { $v = pg_version($this->connID); // 'server' key is only available since PostgreSQL 7.4 @@ -540,7 +542,7 @@ * @param string $charset The client encoding to which the data will be converted. * @return boolean */ - protected function setClientEncoding($charset) + protected function setClientEncoding(string $charset): bool { return pg_set_client_encoding($this->connID, $charset) === 0; } diff --git a/system/Database/Postgre/Forge.php b/system/Database/Postgre/Forge.php index 4b05d9f..1dcbaf8 100644 --- a/system/Database/Postgre/Forge.php +++ b/system/Database/Postgre/Forge.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/Postgre/PreparedQuery.php b/system/Database/Postgre/PreparedQuery.php index fdd0aa4..9cf88bd 100644 --- a/system/Database/Postgre/PreparedQuery.php +++ b/system/Database/Postgre/PreparedQuery.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,6 +41,9 @@ use CodeIgniter\Database\PreparedQueryInterface; use CodeIgniter\Database\BasePreparedQuery; +/** + * Prepared query for Postgre + */ class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface { @@ -74,6 +77,7 @@ * Unused in the MySQLi driver. * * @return mixed + * @throws \Exception */ public function _prepare(string $sql, array $options = []) { @@ -104,7 +108,7 @@ * * @return boolean */ - public function _execute($data) + public function _execute(array $data): bool { if (is_null($this->statement)) { diff --git a/system/Database/Postgre/Result.php b/system/Database/Postgre/Result.php index af4af66..6842e36 100644 --- a/system/Database/Postgre/Result.php +++ b/system/Database/Postgre/Result.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -84,19 +84,19 @@ */ public function getFieldData(): array { - $retval = []; + $retVal = []; for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = pg_field_name($this->resultID, $i); - $retval[$i]->type = pg_field_type($this->resultID, $i); - $retval[$i]->max_length = pg_field_size($this->resultID, $i); - // $retval[$i]->primary_key = (int)($fieldData[$i]->flags & 2); - // $retval[$i]->default = $fieldData[$i]->def; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = pg_field_name($this->resultID, $i); + $retVal[$i]->type = pg_field_type($this->resultID, $i); + $retVal[$i]->max_length = pg_field_size($this->resultID, $i); + // $retVal[$i]->primary_key = (int)($fieldData[$i]->flags & 2); + // $retVal[$i]->default = $fieldData[$i]->def; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -104,7 +104,7 @@ /** * Frees the current result. * - * @return mixed + * @return void */ public function freeResult() { @@ -126,7 +126,7 @@ * * @return mixed */ - public function dataSeek($n = 0) + public function dataSeek(int $n = 0) { return pg_result_seek($this->resultID, $n); } @@ -138,7 +138,7 @@ * * Overridden by driver classes. * - * @return array + * @return mixed */ protected function fetchAssoc() { @@ -156,7 +156,7 @@ * * @return object */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject(string $className = 'stdClass') { return pg_fetch_object($this->resultID, null, $className); } diff --git a/system/Database/Postgre/Utils.php b/system/Database/Postgre/Utils.php index 41143e7..aa95536 100644 --- a/system/Database/Postgre/Utils.php +++ b/system/Database/Postgre/Utils.php @@ -31,18 +31,19 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Database\Postgre; +use CodeIgniter\Database\BaseUtils; use CodeIgniter\Database\Exceptions\DatabaseException; /** * Utils for Postgre */ -class Utils extends \CodeIgniter\Database\BaseUtils +class Utils extends BaseUtils { /** diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index f1ed057..d29e250 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/Query.php b/system/Database/Query.php index 39baaf7..06d1359 100644 --- a/system/Database/Query.php +++ b/system/Database/Query.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/QueryInterface.php b/system/Database/QueryInterface.php index 7f5cfb1..f7381b9 100644 --- a/system/Database/QueryInterface.php +++ b/system/Database/QueryInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -52,12 +52,13 @@ /** * Sets the raw query string to use for this statement. * - * @param string $sql - * @param array $binds + * @param string $sql + * @param mixed $binds + * @param boolean $setEscape * * @return mixed */ - public function setQuery(string $sql, $binds = null); + public function setQuery(string $sql, $binds = null, bool $setEscape = true); //-------------------------------------------------------------------- @@ -91,9 +92,9 @@ * * @param integer $decimals The accuracy of the returned time. * - * @return mixed + * @return string */ - public function getDuration(int $decimals = 6); + public function getDuration(int $decimals = 6): string; //-------------------------------------------------------------------- diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index af21786..6ebfe2c 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -53,7 +53,7 @@ * * @return mixed */ - public function getResult($type = 'object'): array; + public function getResult(string $type = 'object'): array; //-------------------------------------------------------------------- @@ -96,12 +96,12 @@ * * If row doesn't exist, returns null. * - * @param integer $n The index of the results to return - * @param string $type The type of result object. 'array', 'object' or class name. + * @param mixed $n The index of the results to return + * @param string $type The type of result object. 'array', 'object' or class name. * * @return mixed */ - public function getRow($n = 0, $type = 'object'); + public function getRow($n = 0, string $type = 'object'); //-------------------------------------------------------------------- @@ -115,7 +115,7 @@ * * @return mixed */ - public function getCustomRowObject($n, string $className); + public function getCustomRowObject(int $n, string $className); //-------------------------------------------------------------------- @@ -128,7 +128,7 @@ * * @return mixed */ - public function getRowArray($n = 0); + public function getRowArray(int $n = 0); //-------------------------------------------------------------------- @@ -141,7 +141,7 @@ * * @return mixed */ - public function getRowObject($n = 0); + public function getRowObject(int $n = 0); //-------------------------------------------------------------------- @@ -164,7 +164,7 @@ * * @return mixed */ - public function getFirstRow($type = 'object'); + public function getFirstRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -175,7 +175,7 @@ * * @return mixed */ - public function getLastRow($type = 'object'); + public function getLastRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -186,7 +186,7 @@ * * @return mixed */ - public function getNextRow($type = 'object'); + public function getNextRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -197,7 +197,7 @@ * * @return mixed */ - public function getPreviousRow($type = 'object'); + public function getPreviousRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -208,7 +208,7 @@ * * @return mixed */ - public function getUnbufferedRow($type = 'object'); + public function getUnbufferedRow(string $type = 'object'); //-------------------------------------------------------------------- @@ -242,7 +242,7 @@ /** * Frees the current result. * - * @return mixed + * @return void */ public function freeResult(); @@ -257,7 +257,7 @@ * * @return mixed */ - public function dataSeek($n = 0); + public function dataSeek(int $n = 0); //-------------------------------------------------------------------- } diff --git a/system/Database/SQLite3/Builder.php b/system/Database/SQLite3/Builder.php index 4d1c84e..ba09b58 100644 --- a/system/Database/SQLite3/Builder.php +++ b/system/Database/SQLite3/Builder.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -76,9 +76,9 @@ * * Generates a platform-specific replace string from the supplied data * - * @param string the table name - * @param array the insert keys - * @param array the insert values + * @param string $table the table name + * @param array $keys the insert keys + * @param array $values the insert values * * @return string */ diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 225deed..af14d99 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -64,7 +64,6 @@ */ protected $_random_keyword = [ 'RANDOM()', - 'RANDOM()', ]; //-------------------------------------------------------------------- @@ -77,7 +76,7 @@ * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function connect($persistent = false) + public function connect(bool $persistent = false) { if ($persistent && $this->db->DBDebug) { @@ -101,7 +100,7 @@ * Keep or establish the connection if no queries have been sent for * a length of time exceeding the server's idle timeout. * - * @return mixed + * @return void */ public function reconnect() { @@ -128,9 +127,9 @@ * * @param string $databaseName * - * @return mixed + * @return boolean */ - public function setDatabase(string $databaseName) + public function setDatabase(string $databaseName): bool { return false; } @@ -140,9 +139,9 @@ /** * Returns a string containing the version of the database being used. * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { if (isset($this->dataCache['version'])) { @@ -163,7 +162,7 @@ * * @return mixed \SQLite3Result object or bool */ - public function execute($sql) + public function execute(string $sql) { return $this->isWriteType($sql) ? $this->connID->exec($sql) @@ -175,7 +174,7 @@ /** * Returns the total number of rows affected by this query. * - * @return mixed + * @return integer */ public function affectedRows(): int { @@ -205,7 +204,7 @@ * * @return string */ - protected function _listTables($prefixLimit = false): string + protected function _listTables(bool $prefixLimit = false): string { return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'' . (($prefixLimit !== false && $this->DBPrefix !== '') @@ -236,7 +235,7 @@ * @return array|false * @throws DatabaseException */ - public function getFieldNames($table) + public function getFieldNames(string $table) { // Is there a cached result? if (isset($this->dataCache['field_names'][$table])) @@ -314,19 +313,19 @@ { return []; } - $retval = []; + $retVal = []; for ($i = 0, $c = count($query); $i < $c; $i++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $query[$i]->name; - $retval[$i]->type = $query[$i]->type; - $retval[$i]->max_length = null; - $retval[$i]->default = $query[$i]->dflt_value; - $retval[$i]->primary_key = isset($query[$i]->pk) ? (bool)$query[$i]->pk : false; - $retval[$i]->nullable = isset($query[$i]->notnull) ? ! (bool)$query[$i]->notnull : false; + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $query[$i]->name; + $retVal[$i]->type = $query[$i]->type; + $retVal[$i]->max_length = null; + $retVal[$i]->default = $query[$i]->dflt_value; + $retVal[$i]->primary_key = isset($query[$i]->pk) ? (bool)$query[$i]->pk : false; + $retVal[$i]->nullable = isset($query[$i]->notnull) ? ! (bool)$query[$i]->notnull : false; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -349,7 +348,7 @@ } $query = $query->getResultObject(); - $retval = []; + $retVal = []; foreach ($query as $row) { $obj = new \stdClass(); @@ -368,10 +367,10 @@ $obj->fields[] = $field->name; } - $retval[$obj->name] = $obj; + $retVal[$obj->name] = $obj; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -396,7 +395,7 @@ return []; } - $retval = []; + $retVal = []; foreach ($tables as $table) { @@ -409,11 +408,11 @@ $obj->table_name = $table; $obj->foreign_table_name = $row->table; - $retval[] = $obj; + $retVal[] = $obj; } } - return $retval; + return $retVal; } //-------------------------------------------------------------------- diff --git a/system/Database/SQLite3/Forge.php b/system/Database/SQLite3/Forge.php index b0756a9..7a5f77d 100644 --- a/system/Database/SQLite3/Forge.php +++ b/system/Database/SQLite3/Forge.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Database/SQLite3/PreparedQuery.php b/system/Database/SQLite3/PreparedQuery.php index 50e8dee..8ffb502 100644 --- a/system/Database/SQLite3/PreparedQuery.php +++ b/system/Database/SQLite3/PreparedQuery.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,6 +41,10 @@ use CodeIgniter\Database\PreparedQueryInterface; use CodeIgniter\Database\BasePreparedQuery; +/** + * Prepared query for SQLite3 + */ + class PreparedQuery extends BasePreparedQuery implements PreparedQueryInterface { @@ -89,7 +93,7 @@ * * @return boolean */ - public function _execute($data) + public function _execute(array $data): bool { if (is_null($this->statement)) { diff --git a/system/Database/SQLite3/Result.php b/system/Database/SQLite3/Result.php index 47b0cfe..014a11f 100644 --- a/system/Database/SQLite3/Result.php +++ b/system/Database/SQLite3/Result.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -92,18 +92,18 @@ SQLITE3_NULL => 'null', ]; - $retval = []; + $retVal = []; for ($i = 0, $c = $this->getFieldCount(); $i < $c; $i ++) { - $retval[$i] = new \stdClass(); - $retval[$i]->name = $this->resultID->columnName($i); + $retVal[$i] = new \stdClass(); + $retVal[$i]->name = $this->resultID->columnName($i); $type = $this->resultID->columnType($i); - $retval[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type; - $retval[$i]->max_length = null; + $retVal[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type; + $retVal[$i]->max_length = null; } - return $retval; + return $retVal; } //-------------------------------------------------------------------- @@ -111,7 +111,7 @@ /** * Frees the current result. * - * @return mixed + * @return void */ public function freeResult() { @@ -134,16 +134,13 @@ * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ - public function dataSeek($n = 0) + public function dataSeek(int $n = 0) { if ($n !== 0) { - if ($this->db->DBDebug) - { - throw new DatabaseException('SQLite3 doesn\'t support seeking to other offset.'); - } - return false; + throw new DatabaseException('SQLite3 doesn\'t support seeking to other offset.'); } + return $this->resultID->reset(); } @@ -154,7 +151,7 @@ * * Overridden by driver classes. * - * @return array + * @return mixed */ protected function fetchAssoc() { @@ -170,9 +167,9 @@ * * @param string $className * - * @return object + * @return object|boolean */ - protected function fetchObject($className = 'stdClass') + protected function fetchObject(string $className = 'stdClass') { // No native support for fetching rows as objects if (($row = $this->fetchAssoc()) === false) diff --git a/system/Database/SQLite3/Table.php b/system/Database/SQLite3/Table.php index 0b31eb4..865502e 100644 --- a/system/Database/SQLite3/Table.php +++ b/system/Database/SQLite3/Table.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -88,11 +88,15 @@ protected $prefixedTableName; /** + * Database connection. + * * @var Connection */ protected $db; /** + * Handle to our forge. + * * @var Forge */ protected $forge; @@ -101,6 +105,7 @@ * Table constructor. * * @param Connection $db + * @param Forge $forge */ public function __construct(Connection $db, Forge $forge) { @@ -214,6 +219,8 @@ /** * Creates the new table based on our current fields. + * + * @return mixed */ protected function createTable() { @@ -264,6 +271,8 @@ * Copies data from our old table to the new one, * taking care map data correctly based on any columns * that have been renamed. + * + * @return void */ protected function copyData() { @@ -297,7 +306,7 @@ * * @param array|boolean $fields * - * @return array + * @return mixed */ protected function formatFields($fields) { @@ -332,7 +341,7 @@ * Converts keys retrieved from the database to * the format needed to create later. * - * @param $keys + * @param mixed $keys * * @return mixed */ @@ -359,6 +368,8 @@ /** * Attempts to drop all indexes and constraints * from the database for this table. + * + * @return null|void */ protected function dropIndexes() { diff --git a/system/Database/SQLite3/Utils.php b/system/Database/SQLite3/Utils.php index bdb8ec0..5c4263a 100644 --- a/system/Database/SQLite3/Utils.php +++ b/system/Database/SQLite3/Utils.php @@ -32,18 +32,19 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Database\SQLite3; +use CodeIgniter\Database\BaseUtils; use CodeIgniter\Database\Exceptions\DatabaseException; /** * Utils for SQLite3 */ -class Utils extends \CodeIgniter\Database\BaseUtils +class Utils extends BaseUtils { /** diff --git a/system/Database/Seeder.php b/system/Database/Seeder.php index 47fd52c..18c8304 100644 --- a/system/Database/Seeder.php +++ b/system/Database/Seeder.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 696f0db..009a081 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -32,14 +32,20 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Debug; use CodeIgniter\API\ResponseTrait; +use CodeIgniter\Exceptions\PageNotFoundException; +use CodeIgniter\HTTP\IncomingRequest; +use CodeIgniter\HTTP\Response; use Config\Paths; +use function error_reporting; +use ErrorException; +use Throwable; /** * Exceptions manager @@ -64,16 +70,22 @@ protected $viewPath; /** + * Config for debug exceptions. + * * @var \Config\Exceptions */ protected $config; /** + * The incoming request. + * * @var \CodeIgniter\HTTP\IncomingRequest */ protected $request; /** + * The outgoing response. + * * @var \CodeIgniter\HTTP\Response */ protected $response; @@ -87,7 +99,7 @@ * @param \CodeIgniter\HTTP\IncomingRequest $request * @param \CodeIgniter\HTTP\Response $response */ - public function __construct(\Config\Exceptions $config, \CodeIgniter\HTTP\IncomingRequest $request, \CodeIgniter\HTTP\Response $response) + public function __construct(\Config\Exceptions $config, IncomingRequest $request, Response $response) { $this->ob_level = ob_get_level(); @@ -127,7 +139,7 @@ * * @param \Throwable $exception */ - public function exceptionHandler(\Throwable $exception) + public function exceptionHandler(Throwable $exception) { $codes = $this->determineCodes($exception); $statusCode = $codes[0]; @@ -179,13 +191,13 @@ */ public function errorHandler(int $severity, string $message, string $file = null, int $line = null, $context = null) { - if (! (\error_reporting() & $severity)) + if (! (error_reporting() & $severity)) { return; } // Convert it to an exception and pass it along. - throw new \ErrorException($message, 0, $severity, $file, $line); + throw new ErrorException($message, 0, $severity, $file, $line); } //-------------------------------------------------------------------- @@ -206,7 +218,7 @@ // Fatal Error? if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE])) { - $this->exceptionHandler(new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line'])); + $this->exceptionHandler(new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line'])); } } } @@ -222,7 +234,7 @@ * * @return string The path and filename of the view file to use */ - protected function determineView(\Throwable $exception, string $template_path): string + protected function determineView(Throwable $exception, string $template_path): string { // Production environments should have a custom exception file. $view = 'production.php'; @@ -234,7 +246,7 @@ } // 404 Errors - if ($exception instanceof \CodeIgniter\Exceptions\PageNotFoundException) + if ($exception instanceof PageNotFoundException) { return 'error_404.php'; } @@ -256,7 +268,7 @@ * @param \Throwable $exception * @param integer $statusCode */ - protected function render(\Throwable $exception, int $statusCode) + protected function render(Throwable $exception, int $statusCode) { // Determine directory with views $path = $this->viewPath; @@ -300,7 +312,7 @@ * * @return array */ - protected function collectVars(\Throwable $exception, int $statusCode): array + protected function collectVars(Throwable $exception, int $statusCode): array { return [ 'title' => get_class($exception), @@ -320,7 +332,7 @@ * * @return array */ - protected function determineCodes(\Throwable $exception): array + protected function determineCodes(Throwable $exception): array { $statusCode = abs($exception->getCode()); @@ -432,7 +444,7 @@ { $source = file_get_contents($file); } - catch (\Throwable $e) + catch (Throwable $e) { return false; } diff --git a/system/Debug/Iterator.php b/system/Debug/Iterator.php index 2a8d332..abad5f4 100644 --- a/system/Debug/Iterator.php +++ b/system/Debug/Iterator.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -65,12 +65,12 @@ * Tests are simply closures that the user can define any sequence of * things to happen during the test. * - * @param $name + * @param string $name * @param \Closure $closure * * @return $this */ - public function add($name, \Closure $closure) + public function add(string $name, \Closure $closure) { $name = strtolower($name); @@ -89,9 +89,9 @@ * @param integer $iterations * @param boolean $output * - * @return string + * @return string|null */ - public function run($iterations = 1000, $output = true) + public function run(int $iterations = 1000, bool $output = true) { foreach ($this->tests as $name => $test) { @@ -121,6 +121,8 @@ { return $this->getReport(); } + + return null; } //-------------------------------------------------------------------- diff --git a/system/Debug/Timer.php b/system/Debug/Timer.php index 11c228c..ab5fc2d 100644 --- a/system/Debug/Timer.php +++ b/system/Debug/Timer.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index f67bffb..5b1066c 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -31,17 +31,19 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Debug; +use CodeIgniter\Config\BaseConfig; use CodeIgniter\Debug\Toolbar\Collectors\History; use CodeIgniter\Format\JSONFormatter; -use Config\Services; -use CodeIgniter\Config\BaseConfig; use CodeIgniter\Format\XMLFormatter; +use CodeIgniter\HTTP\RequestInterface; +use CodeIgniter\HTTP\ResponseInterface; +use Config\Services; /** * Debug Toolbar @@ -55,6 +57,8 @@ class Toolbar { /** + * Toolbar configuration settings. + * * @var BaseConfig */ protected $config; @@ -102,7 +106,7 @@ * * @return string JSON encoded data */ - public function run($startTime, $totalTime, $request, $response): string + public function run(float $startTime, float $totalTime, RequestInterface $request, ResponseInterface $response): string { // Data items used within the view. $data['url'] = current_url(); @@ -123,17 +127,17 @@ foreach ($this->collectVarData() as $heading => $items) { - $vardata = []; + $varData = []; if (is_array($items)) { foreach ($items as $key => $value) { - $vardata[esc($key)] = is_string($value) ? esc($value) : print_r($value, true); + $varData[esc($key)] = is_string($value) ? esc($value) : print_r($value, true); } } - $data['vars']['varData'][esc($heading)] = $vardata; + $data['vars']['varData'][esc($heading)] = $varData; } if (! empty($_SESSION)) @@ -141,7 +145,7 @@ foreach ($_SESSION as $key => $value) { // Replace the binary data with string to avoid json_encode failure. - if (preg_match('~[^\x20-\x7E\t\r\n]~', $value)) + if (is_string($value) && preg_match('~[^\x20-\x7E\t\r\n]~', $value)) { $value = 'binary data'; } @@ -212,10 +216,11 @@ * @param float $startTime * @param integer $segmentCount * @param integer $segmentDuration + * @param array $styles * * @return string */ - protected function renderTimeline(array $collectors, $startTime, int $segmentCount, int $segmentDuration, array& $styles): string + protected function renderTimeline(array $collectors, $startTime, int $segmentCount, int $segmentDuration, array &$styles): string { $displayTime = $segmentCount * $segmentDuration; $rows = $this->collectTimelineData($collectors); @@ -234,8 +239,7 @@ $length = (($row['duration'] * 1000) / $displayTime) * 100; $styles['debug-bar-timeline-' . $styleCount] = "left: {$offset}%; width: {$length}%;"; - $output .= ""; + $output .= ""; $output .= ''; $output .= ''; @@ -250,6 +254,8 @@ /** * Returns a sorted array of timeline data arrays from the collectors. * + * @param array $collectors + * * @return array */ protected function collectTimelineData($collectors): array @@ -307,7 +313,7 @@ * * @return float */ - protected function roundTo($number, $increments = 5): float + protected function roundTo(float $number, int $increments = 5): float { $increments = 1 / $increments; @@ -316,6 +322,12 @@ //-------------------------------------------------------------------- + /** + * Prepare for debugging.. + * + * @global type $app + * @return type + */ public function prepare() { if (CI_DEBUG && ! is_cli()) @@ -384,7 +396,7 @@ //-------------------------------------------------------------------- /** - * + * Inject debug toolbar into the response. */ public function respond() { diff --git a/system/Debug/Toolbar/Collectors/BaseCollector.php b/system/Debug/Toolbar/Collectors/BaseCollector.php index 0785f13..16a948d 100644 --- a/system/Debug/Toolbar/Collectors/BaseCollector.php +++ b/system/Debug/Toolbar/Collectors/BaseCollector.php @@ -91,7 +91,7 @@ * @param boolean $safe * @return string */ - public function getTitle($safe = false): string + public function getTitle(bool $safe = false): string { if ($safe) { @@ -232,9 +232,9 @@ /** * Returns the data of this collector to be formatted in the toolbar * - * @return array + * @return array|string */ - public function display(): array + public function display() { return []; } @@ -303,6 +303,11 @@ return ''; } + /** + * Return settings as an array. + * + * @return array + */ public function getAsArray(): array { return [ diff --git a/system/Debug/Toolbar/Collectors/Config.php b/system/Debug/Toolbar/Collectors/Config.php index 7ab1e3d..25ef37f 100644 --- a/system/Debug/Toolbar/Collectors/Config.php +++ b/system/Debug/Toolbar/Collectors/Config.php @@ -47,6 +47,11 @@ */ class Config { + /** + * Return toolbar config values as an array. + * + * @return array + */ public static function display(): array { $config = config(App::class); @@ -60,7 +65,6 @@ 'timezone' => app_timezone(), 'locale' => Services::request()->getLocale(), 'cspEnabled' => $config->CSPEnabled, - 'salt' => $config->salt, ]; } } diff --git a/system/Debug/Toolbar/Collectors/Events.php b/system/Debug/Toolbar/Collectors/Events.php index f2d397a..a20faca 100644 --- a/system/Debug/Toolbar/Collectors/Events.php +++ b/system/Debug/Toolbar/Collectors/Events.php @@ -102,7 +102,7 @@ * Child classes should implement this to return the timeline data * formatted for correct usage. * - * @return mixed + * @return array */ protected function formatTimelineData(): array { diff --git a/system/Debug/Toolbar/Collectors/History.php b/system/Debug/Toolbar/Collectors/History.php index 7249332..d0f2806 100644 --- a/system/Debug/Toolbar/Collectors/History.php +++ b/system/Debug/Toolbar/Collectors/History.php @@ -83,6 +83,8 @@ //-------------------------------------------------------------------- /** + * Specify time limit & file count for debug history. + * * @param integer $current Current history time * @param integer $limit Max history files */ @@ -111,7 +113,7 @@ if (json_last_error() === JSON_ERROR_NONE) { preg_match_all('/\d+/', $filename, $time); - $time = (int)$time[0][0]; + $time = (int)end($time[0]); // Debugbar files shown in History Collector $files[] = [ @@ -154,6 +156,11 @@ return count($this->files); } + /** + * Return true if there are no history files. + * + * @return boolean + */ public function isEmpty(): bool { return empty($this->files); diff --git a/system/Debug/Toolbar/Collectors/Routes.php b/system/Debug/Toolbar/Collectors/Routes.php index bc9c595..2e3a1e3 100644 --- a/system/Debug/Toolbar/Collectors/Routes.php +++ b/system/Debug/Toolbar/Collectors/Routes.php @@ -97,7 +97,7 @@ $params[] = [ 'name' => $param->getName(), 'value' => $router->params()[$key] ?? - '<empty> | default: ' . var_export($param->getDefaultValue(), true), + '<empty> | default: ' . var_export($param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, true), ]; } diff --git a/system/Debug/Toolbar/Collectors/Timers.php b/system/Debug/Toolbar/Collectors/Timers.php index 0a08545..adf5409 100644 --- a/system/Debug/Toolbar/Collectors/Timers.php +++ b/system/Debug/Toolbar/Collectors/Timers.php @@ -76,7 +76,7 @@ * Child classes should implement this to return the timeline data * formatted for correct usage. * - * @return mixed + * @return array */ protected function formatTimelineData(): array { diff --git a/system/Debug/Toolbar/Collectors/Views.php b/system/Debug/Toolbar/Collectors/Views.php index 57ec408..25c909f 100644 --- a/system/Debug/Toolbar/Collectors/Views.php +++ b/system/Debug/Toolbar/Collectors/Views.php @@ -117,7 +117,7 @@ * Child classes should implement this to return the timeline data * formatted for correct usage. * - * @return mixed + * @return array */ protected function formatTimelineData(): array { diff --git a/system/Debug/Toolbar/Views/_config.tpl.php b/system/Debug/Toolbar/Views/_config.tpl.php index 08c06f0..4247e81 100644 --- a/system/Debug/Toolbar/Views/_config.tpl.php +++ b/system/Debug/Toolbar/Views/_config.tpl.php @@ -44,17 +44,5 @@ Content Security Policy Enabled: { if $cspEnabled } Yes { else } No { endif } - - Salt Set?: - - { if $salt == '' } -
- You have not defined an application-wide $salt. This could lead to a less secure site. -
- { else } - Set - { endif } - - diff --git a/system/Debug/Toolbar/Views/toolbar.tpl.php b/system/Debug/Toolbar/Views/toolbar.tpl.php index 2494a83..b746364 100644 --- a/system/Debug/Toolbar/Views/toolbar.tpl.php +++ b/system/Debug/Toolbar/Views/toolbar.tpl.php @@ -136,7 +136,7 @@

- setData($c['display'])->render("_{$c['titleSafe']}.tpl") ?> + setData($c['display'])->render("_{$c['titleSafe']}.tpl") ?>
diff --git a/system/Debug/Toolbar/Views/toolbarloader.js.php b/system/Debug/Toolbar/Views/toolbarloader.js.php index 62e3418..539490b 100644 --- a/system/Debug/Toolbar/Views/toolbarloader.js.php +++ b/system/Debug/Toolbar/Views/toolbarloader.js.php @@ -56,12 +56,16 @@ } }; - xhttp.open("GET", url + "?debugbar_time=" + time, true); + xhttp.open("GET", url + "/?debugbar_time=" + time, true); xhttp.send(); } // Track all AJAX requests -var oldXHR = window.XMLHttpRequest; +if (window.ActiveXObject) { + var oldXHR = new ActiveXObject('Microsoft.XMLHTTP'); +} else { + var oldXHR = window.XMLHttpRequest; +} function newXHR() { var realXHR = new oldXHR(); diff --git a/system/Entity.php b/system/Entity.php index bdada1b..19cb2b3 100644 --- a/system/Entity.php +++ b/system/Entity.php @@ -32,12 +32,13 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter; +use CodeIgniter\Exceptions\EntityException; use CodeIgniter\I18n\Time; use CodeIgniter\Exceptions\CastException; @@ -46,8 +47,7 @@ */ class Entity { - protected $_options = [ - /* + /** * Maps names used in sets and gets against unique * names within the class, allowing independence from * database column names. @@ -57,9 +57,10 @@ * 'db_name' => 'class_name' * ]; */ + protected $_options = [ 'datamap' => [], - /* + /** * Define properties that are automatically converted to Time instances. */ 'dates' => [ @@ -68,7 +69,7 @@ 'deleted_at', ], - /* + /** * Array of field names and the type of value to cast them as * when they are accessed. */ @@ -295,6 +296,11 @@ $result = $this->castAs($result, $this->_options['casts'][$key]); } + if (! isset($result) && ! property_exists($this, $key)) + { + throw EntityException::forTryingToAccessNonExistentProperty($key, get_called_class()); + } + return $result; } @@ -313,6 +319,7 @@ * @param null $value * * @return $this + * @throws \Exception */ public function __set(string $key, $value = null) { @@ -349,6 +356,11 @@ if (($castTo === 'json' || $castTo === 'json-array') && function_exists('json_encode')) { $value = json_encode($value); + + if (json_last_error() !== JSON_ERROR_NONE) + { + throw CastException::forInvalidJsonFormatException(json_last_error()); + } } } diff --git a/system/Events/Events.php b/system/Events/Events.php index f92f42a..5fab269 100644 --- a/system/Events/Events.php +++ b/system/Events/Events.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Exceptions/EntityException.php b/system/Exceptions/EntityException.php new file mode 100644 index 0000000..40e3017 --- /dev/null +++ b/system/Exceptions/EntityException.php @@ -0,0 +1,22 @@ +config = $config; @@ -105,6 +111,11 @@ $this->setResponse($response); } + /** + * Set the response explicity. + * + * @param ResponseInterface $response + */ public function setResponse(ResponseInterface $response) { $this->response = & $response; @@ -147,7 +158,7 @@ if ($position === 'before') { - $result = $class->before($this->request); + $result = $class->before($this->request, $this->arguments[$alias] ?? null); if ($result instanceof RequestInterface) { @@ -228,7 +239,7 @@ * * @return array */ - public function getFilters() + public function getFilters(): array { return $this->filters; } @@ -313,13 +324,11 @@ /** * Returns the arguments for a specified key, or all. * - * @return array + * @return mixed */ public function getArguments(string $key = null) { - return is_null($key) - ? $this->arguments - : $this->arguments[$key]; + return is_null($key) ? $this->arguments : $this->arguments[$key]; } //-------------------------------------------------------------------- @@ -327,6 +336,12 @@ // Processors //-------------------------------------------------------------------- + /** + * Add any applicable (not excluded) global filter settings to the mix. + * + * @param string $uri + * @return type + */ protected function processGlobals(string $uri = null) { if (! isset($this->config->globals) || ! is_array($this->config->globals)) @@ -334,85 +349,54 @@ return; } - // Before - if (isset($this->config->globals['before'])) + $uri = strtolower(trim($uri, '/ ')); + + // Add any global filters, unless they are excluded for this URI + $sets = [ + 'before', + 'after', + ]; + foreach ($sets as $set) { - // Take any 'except' routes into consideration - foreach ($this->config->globals['before'] as $alias => $rules) + if (isset($this->config->globals[$set])) { - if (! is_array($rules) || ! array_key_exists('except', $rules)) + // look at each alias in the group + foreach ($this->config->globals[$set] as $alias => $rules) { - continue; - } - - $rules = $rules['except']; - - if (is_string($rules)) - { - $rules = [$rules]; - } - - foreach ($rules as $path) - { - // Prep it for regex - $path = strtolower(str_replace('/*', '*', $path)); - $path = trim(str_replace('*', '.+', $path), '/ '); - - // Path doesn't match the URI? continue on... - if (preg_match('#' . $path . '#', $uri, $match) !== 1) + $keep = true; + if (is_array($rules)) { - continue; + // see if it should be excluded + if (isset($rules['except'])) + { + // grab the exclusion rules + $check = $rules['except']; + if ($this->pathApplies($uri, $check)) + { + $keep = false; + } + } } - - unset($this->config->globals['before'][$alias]); - break; + else + { + $alias = $rules; // simple name of filter to apply + } + if ($keep) + { + $this->filters[$set][] = $alias; + } } } - - $this->filters['before'] = array_merge($this->filters['before'], $this->config->globals['before']); - } - - // After - if (isset($this->config->globals['after'])) - { - // Take any 'except' routes into consideration - foreach ($this->config->globals['after'] as $alias => $rules) - { - if (! is_array($rules) || ! array_key_exists('except', $rules)) - { - continue; - } - - $rules = $rules['except']; - - if (is_string($rules)) - { - $rules = [$rules]; - } - - foreach ($rules as $path) - { - // Prep it for regex - $path = strtolower(str_replace('/*', '*', $path)); - $path = trim(str_replace('*', '.+', $path), '/ '); - - // Path doesn't match the URI? continue on... - if (preg_match('#' . $path . '#', $uri, $match) !== 1) - { - continue; - } - - unset($this->config->globals['after'][$alias]); - break; - } - } - - $this->filters['after'] = array_merge($this->filters['after'], $this->config->globals['after']); } } //-------------------------------------------------------------------- + /** + * Add any method-specific flters to the mix. + * + * @return type + */ protected function processMethods() { if (! isset($this->config->methods) || ! is_array($this->config->methods)) @@ -432,6 +416,12 @@ //-------------------------------------------------------------------- + /** + * Add any applicable configured filters to the mix. + * + * @param string $uri + * @return type + */ protected function processFilters(string $uri = null) { if (! isset($this->config->filters) || ! $this->config->filters) @@ -441,53 +431,64 @@ $uri = strtolower(trim($uri, '/ ')); - $matches = []; - + // Add any filters that apply to this URI foreach ($this->config->filters as $alias => $settings) { - // Before + // Look for inclusion rules if (isset($settings['before'])) { - foreach ($settings['before'] as $path) + $path = $settings['before']; + if ($this->pathApplies($uri, $path)) { - // Prep it for regex - $path = strtolower(str_replace('/*', '*', $path)); - $path = trim(str_replace('*', '.+', $path), '/ '); - - if (preg_match('#' . $path . '#', $uri) !== 1) - { - continue; - } - - $matches[] = $alias; + $this->filters['before'][] = $alias; } - - $this->filters['before'] = array_merge($this->filters['before'], $matches); - $matches = []; } - - // After if (isset($settings['after'])) { - foreach ($settings['after'] as $path) + $path = $settings['after']; + if ($this->pathApplies($uri, $path)) { - // Prep it for regex - $path = strtolower(str_replace('/*', '*', $path)); - $path = trim(str_replace('*', '.+', $path), '/ '); - - if (preg_match('#' . $path . '#', $uri) !== 1) - { - continue; - } - - $matches[] = $alias; + $this->filters['after'][] = $alias; } - - $this->filters['after'] = array_merge($this->filters['after'], $matches); - $matches = []; } } } - //-------------------------------------------------------------------- + /** + * Check paths for match for URI + * + * @param string $uri URI to test against + * @param mixed $paths The path patterns to test + * @return boolean True if any of the paths apply to the URI + */ + private function pathApplies(string $uri, $paths) + { + // empty path matches all + if (empty($paths)) + { + return true; + } + + // make sure the paths are iterable + if (is_string($paths)) + { + $paths = [$paths]; + } + + // treat each paths as pseudo-regex + foreach ($paths as $path) + { + // need to escape path separators + $path = str_replace('/', '\/', trim($path, '/ ')); + // need to make pseudo wildcard real + $path = strtolower(str_replace('*', '.*', $path)); + // Does this rule apply here? + if (preg_match('#' . $path . '#', $uri, $match) === 1) + { + return true; + } + } + return false; + } + } diff --git a/system/Filters/Honeypot.php b/system/Filters/Honeypot.php index e1c84d6..c4b9b86 100644 --- a/system/Filters/Honeypot.php +++ b/system/Filters/Honeypot.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -70,9 +70,9 @@ /** * Attach a honeypot to the current response. * - * @param CodeIgniter\HTTP\RequestInterface $request - * @param CodeIgniter\HTTP\ResponseInterface $response - * + * @param \CodeIgniter\HTTP\RequestInterface $request + * @param \CodeIgniter\HTTP\ResponseInterface $response + * * @return void */ public function after(RequestInterface $request, ResponseInterface $response) diff --git a/system/Format/FormatterInterface.php b/system/Format/FormatterInterface.php index 29a9d3f..9376228 100644 --- a/system/Format/FormatterInterface.php +++ b/system/Format/FormatterInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -47,9 +47,9 @@ /** * Takes the given data and formats it. * - * @param array $data + * @param string|array $data * * @return mixed */ - public function format(array $data); + public function format($data); } diff --git a/system/Format/JSONFormatter.php b/system/Format/JSONFormatter.php index 1152159..e05137a 100644 --- a/system/Format/JSONFormatter.php +++ b/system/Format/JSONFormatter.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -51,9 +51,9 @@ * * @param $data * - * @return mixed + * @return string|boolean (JSON string | false) */ - public function format(array $data) + public function format($data) { $options = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; diff --git a/system/Format/XMLFormatter.php b/system/Format/XMLFormatter.php index 22bd86f..cb94aed 100644 --- a/system/Format/XMLFormatter.php +++ b/system/Format/XMLFormatter.php @@ -1,7 +1,5 @@ '); - $this->arrayToXML($data, $output); + $this->arrayToXML((array)$data, $output); return $output->asXML(); } diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 23f1c0f..518bb62 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -148,12 +148,7 @@ */ public function getOption(string $key) { - if (array_key_exists($key, $this->options)) - { - return $this->options[$key]; - } - - return null; + return $this->options[$key] ?? null; } //-------------------------------------------------------------------- diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index f48b421..a0ba1ef 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -399,7 +399,7 @@ * * @return string */ - public function getMethod($upper = false): string + public function getMethod(bool $upper = false): string { return ($upper) ? strtoupper($this->method) : strtolower($this->method); } @@ -514,9 +514,9 @@ * @param string $method * @param array $curl_options * - * @return array|integer + * @return array */ - protected function applyMethod($method, array $curl_options): array + protected function applyMethod(string $method, array $curl_options): array { $method = strtoupper($method); @@ -763,6 +763,7 @@ $json = json_encode($config['json']); $this->setBody($json); $this->setHeader('Content-Type', 'application/json'); + $this->setHeader('Content-Length', (string) strlen($json)); } // version diff --git a/system/HTTP/ContentSecurityPolicy.php b/system/HTTP/ContentSecurityPolicy.php index e013bb7..d88cd40 100644 --- a/system/HTTP/ContentSecurityPolicy.php +++ b/system/HTTP/ContentSecurityPolicy.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -535,9 +535,9 @@ * * @return $this */ - public function setReportURI($uri) + public function setReportURI(string $uri) { - $this->reportURI = (string) $uri; + $this->reportURI = $uri; return $this; } diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index f240944..067dbcd 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -42,6 +42,9 @@ use CodeIgniter\Files\File; use Config\Mimes; +/** + * HTTP response when a download is requested. + */ class DownloadResponse extends Message implements ResponseInterface { /** @@ -93,6 +96,12 @@ */ private $pretend = false; + /** + * Constructor. + * + * @param string $filename + * @param boolean $setMime + */ public function __construct(string $filename, bool $setMime) { $this->filename = $filename; @@ -348,6 +357,12 @@ // Output Methods //-------------------------------------------------------------------- + /** + * For unit testing, don't actually send headers. + * + * @param boolean $pretend + * @return $this + */ public function pretend(bool $pretend = true) { $this->pretend = $pretend; diff --git a/system/HTTP/Exceptions/HTTPException.php b/system/HTTP/Exceptions/HTTPException.php index 49e83f3..22448b6 100644 --- a/system/HTTP/Exceptions/HTTPException.php +++ b/system/HTTP/Exceptions/HTTPException.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/HTTP/Files/FileCollection.php b/system/HTTP/Files/FileCollection.php index f1b7d91..df544ad 100644 --- a/system/HTTP/Files/FileCollection.php +++ b/system/HTTP/Files/FileCollection.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index f219d28..9eafbc1 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,6 +41,8 @@ use CodeIgniter\Files\File; use CodeIgniter\HTTP\Exceptions\HTTPException; +use Config\Mimes; +use Exception; /** * Value object representing a single file uploaded through an @@ -177,7 +179,7 @@ { move_uploaded_file($this->path, $destination); } - catch (\Exception $e) + catch (Exception $e) { $error = error_get_last(); throw HTTPException::forMoveFailed(basename($this->path), $targetPath, strip_tags($error['message'])); @@ -201,7 +203,7 @@ * * @return string The path set or created. */ - protected function setPath($path) + protected function setPath(string $path): string { if (! is_dir($path)) { @@ -261,8 +263,6 @@ /** * Get error string * - * @var array $errors - * * @return string */ public function getErrorString(): string @@ -290,8 +290,7 @@ * This is NOT a trusted value. * For a trusted version, use getMimeType() instead. * - * @return string|null The media type sent by the client or null if none - * was provided. + * @return string The media type sent by the client or null if none was provided. */ public function getClientMimeType(): string { @@ -305,8 +304,7 @@ * by the client, and should not be trusted. If the file has been * moved, this will return the final name of the moved file. * - * @return string|null The filename sent by the client or null if none - * was provided. + * @return string The filename sent by the client or null if none was provided. */ public function getName(): string { @@ -353,9 +351,14 @@ return $this->guessExtension(); } + /** + * Attempts to determine the best file extension. + * + * @return string|null + */ public function guessExtension(): ?string { - return \Config\Mimes::guessExtensionFromType($this->getClientMimeType(), $this->getClientExtension()); + return Mimes::guessExtensionFromType($this->getClientMimeType(), $this->getClientExtension()); } //-------------------------------------------------------------------- @@ -365,7 +368,7 @@ * was uploaded. This is NOT a trusted source. * For a trusted version, use guessExtension() instead. * - * @return string|null + * @return string */ public function getClientExtension(): string { diff --git a/system/HTTP/Files/UploadedFileInterface.php b/system/HTTP/Files/UploadedFileInterface.php index 76c0069..d98696b 100644 --- a/system/HTTP/Files/UploadedFileInterface.php +++ b/system/HTTP/Files/UploadedFileInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/HTTP/Header.php b/system/HTTP/Header.php index e0d1b5d..2f44c04 100644 --- a/system/HTTP/Header.php +++ b/system/HTTP/Header.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -83,7 +83,7 @@ * * @return string */ - public function getName() + public function getName(): string { return $this->name; } diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 5d5a235..9b0cd82 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -127,6 +127,8 @@ protected $validLocales = []; /** + * Configuration settings. + * * @var \Config\App */ public $config; @@ -139,6 +141,8 @@ protected $oldInput = []; /** + * The user agent this request is from. + * * @var \CodeIgniter\HTTP\UserAgent */ protected $userAgent; @@ -149,11 +153,11 @@ * Constructor * * @param object $config - * @param URI $uri - * @param string $body + * @param \CodeIgniter\HTTP\URI $uri + * @param string|null $body * @param \CodeIgniter\HTTP\UserAgent $userAgent */ - public function __construct($config, $uri = null, $body = 'php://input', UserAgent $userAgent) + public function __construct($config, URI $uri = null, $body = 'php://input', UserAgent $userAgent) { // Get our body from php://input if ($body === 'php://input') @@ -321,9 +325,9 @@ * to grab data from the request object and can be used in lieu of the * other get* methods in most cases. * - * @param null $index - * @param null $filter - * @param null $flags + * @param string|array|null $index + * @param integer|null $filter Filter constant + * @param mixed $flags * * @return mixed */ @@ -531,7 +535,7 @@ * * @return array */ - public function getFiles() + public function getFiles(): array { if (is_null($this->files)) { diff --git a/system/HTTP/Message.php b/system/HTTP/Message.php index 7114750..05071f0 100644 --- a/system/HTTP/Message.php +++ b/system/HTTP/Message.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -197,7 +197,7 @@ * * @return array|\CodeIgniter\HTTP\Header */ - public function getHeader($name) + public function getHeader(string $name) { $orig_name = $this->getHeaderName($name); @@ -214,11 +214,11 @@ /** * Determines whether a header exists. * - * @param $name + * @param string $name * * @return boolean */ - public function hasHeader($name): bool + public function hasHeader(string $name): bool { $orig_name = $this->getHeaderName($name); @@ -318,7 +318,7 @@ * * @return Message */ - public function appendHeader(string $name, $value) + public function appendHeader(string $name, string $value) { $orig_name = $this->getHeaderName($name); @@ -338,7 +338,7 @@ * * @return Message */ - public function prependHeader(string $name, $value) + public function prependHeader(string $name, string $value) { $orig_name = $this->getHeaderName($name); @@ -395,7 +395,7 @@ * * @return string */ - protected function getHeaderName($name): string + protected function getHeaderName(string $name): string { $lower_name = strtolower($name); diff --git a/system/HTTP/Negotiate.php b/system/HTTP/Negotiate.php index e864fb8..dbad9df 100644 --- a/system/HTTP/Negotiate.php +++ b/system/HTTP/Negotiate.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -68,7 +68,7 @@ * * @param \CodeIgniter\HTTP\RequestInterface $request */ - public function __construct(\CodeIgniter\HTTP\RequestInterface $request = null) + public function __construct(RequestInterface $request = null) { if (! is_null($request)) { @@ -85,7 +85,7 @@ * * @return $this */ - public function setRequest(\CodeIgniter\HTTP\RequestInterface $request) + public function setRequest(RequestInterface $request) { $this->request = $request; @@ -253,7 +253,7 @@ * * @return array */ - public function parseHeader(string $header) + public function parseHeader(string $header): array { $results = []; $acceptable = explode(',', $header); @@ -341,7 +341,7 @@ * @param boolean $enforceTypes * @return boolean */ - protected function match(array $acceptable, string $supported, bool $enforceTypes = false) + protected function match(array $acceptable, string $supported, bool $enforceTypes = false): bool { $supported = $this->parseHeader($supported); if (is_array($supported) && count($supported) === 1) diff --git a/system/HTTP/RedirectResponse.php b/system/HTTP/RedirectResponse.php index 83f795a..ad9f70b 100644 --- a/system/HTTP/RedirectResponse.php +++ b/system/HTTP/RedirectResponse.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/HTTP/Request.php b/system/HTTP/Request.php index 3f87727..6940504 100644 --- a/system/HTTP/Request.php +++ b/system/HTTP/Request.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -256,7 +256,7 @@ * * @return string */ - public function getMethod($upper = false): string + public function getMethod(bool $upper = false): string { return ($upper) ? strtoupper($this->method) : strtolower($this->method); } diff --git a/system/HTTP/RequestInterface.php b/system/HTTP/RequestInterface.php index bb507ab..e28fa67 100644 --- a/system/HTTP/RequestInterface.php +++ b/system/HTTP/RequestInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -76,7 +76,7 @@ * * @return string */ - public function getMethod($upper = false): string; + public function getMethod(bool $upper = false): string; //-------------------------------------------------------------------- diff --git a/system/HTTP/Response.php b/system/HTTP/Response.php index 0632998..a9b21c5 100644 --- a/system/HTTP/Response.php +++ b/system/HTTP/Response.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -904,7 +904,7 @@ * * @return boolean */ - public function hasCookie(string $name, $value = null, string $prefix = '') + public function hasCookie(string $name, string $value = null, string $prefix = ''): bool { if ($prefix === '' && $this->cookiePrefix !== '') { @@ -967,14 +967,14 @@ /** * Sets a cookie to be deleted when the response is sent. * - * @param $name + * @param string $name * @param string $domain * @param string $path * @param string $prefix * * @return $this */ - public function deleteCookie($name = '', string $domain = '', string $path = '/', string $prefix = '') + public function deleteCookie(string $name = '', string $domain = '', string $path = '/', string $prefix = '') { if (empty($name)) { @@ -1035,9 +1035,9 @@ * Generates the headers that force a download to happen. And * sends the file to the browser. * - * @param string $filename The path to the file to send - * @param string $data The data to be downloaded - * @param boolean $setMime Whether to try and send the actual MIME type + * @param string $filename The path to the file to send + * @param string|null $data The data to be downloaded + * @param boolean $setMime Whether to try and send the actual MIME type * * @return \CodeIgniter\HTTP\DownloadResponse|null */ diff --git a/system/HTTP/ResponseInterface.php b/system/HTTP/ResponseInterface.php index 153ef66..28370a1 100644 --- a/system/HTTP/ResponseInterface.php +++ b/system/HTTP/ResponseInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index e1ab897..72f7722 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -79,49 +79,49 @@ /** * The URI Scheme. * - * @var + * @var string */ protected $scheme = 'http'; /** * URI User Info * - * @var + * @var string */ protected $user; /** * URI User Password * - * @var + * @var string */ protected $password; /** * URI Host * - * @var + * @var string */ protected $host; /** * URI Port * - * @var + * @var integer */ protected $port; /** * URI path. * - * @var + * @var string */ protected $path; /** * The name of any fragment. * - * @var + * @var string */ protected $fragment = ''; @@ -288,7 +288,7 @@ * The trailing "@" character is not part of the user information and MUST * NOT be added. * - * @return string The URI user information, in "username[:password]" format. + * @return string|null The URI user information, in "username[:password]" format. */ public function getUserInfo() { @@ -531,7 +531,7 @@ * Allow the URI to be output as a string by simply casting it to a string * or echoing out. */ - public function __toString() + public function __toString(): string { return static::createURIString( $this->getScheme(), $this->getAuthority(), $this->getPath(), // Absolute URIs should use a "/" for an empty path @@ -783,7 +783,7 @@ * * @return string */ - protected function decode(string $value) + protected function decode(string $value): string { if (empty($value)) { @@ -843,7 +843,7 @@ * Adds a single new element to the query vars. * * @param string $key - * @param null $value + * @param mixed $value * * @return $this */ @@ -929,9 +929,9 @@ * * @param $path * - * @return mixed|string + * @return string */ - protected function filterPath(string $path = null) + protected function filterPath(string $path = null): string { $orig = $path; diff --git a/system/HTTP/UserAgent.php b/system/HTTP/UserAgent.php index 6bd2309..8674a22 100644 --- a/system/HTTP/UserAgent.php +++ b/system/HTTP/UserAgent.php @@ -32,13 +32,12 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\HTTP; -use CodeIgniter\Database\BasePreparedQuery; use Config\UserAgents; /** diff --git a/system/Helpers/array_helper.php b/system/Helpers/array_helper.php index 5215173..b43ab4b 100644 --- a/system/Helpers/array_helper.php +++ b/system/Helpers/array_helper.php @@ -31,18 +31,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ /** * CodeIgniter Array Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('dot_array_search')) diff --git a/system/Helpers/cookie_helper.php b/system/Helpers/cookie_helper.php index 0be9f30..5e80918 100755 --- a/system/Helpers/cookie_helper.php +++ b/system/Helpers/cookie_helper.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -40,11 +40,7 @@ /** * CodeIgniter Cookie Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('set_cookie')) { diff --git a/system/Helpers/date_helper.php b/system/Helpers/date_helper.php index 1d42b18..451657a 100644 --- a/system/Helpers/date_helper.php +++ b/system/Helpers/date_helper.php @@ -31,18 +31,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ /** * CodeIgniter Date Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('now')) @@ -56,6 +52,7 @@ * @param string $timezone * * @return integer + * @throws \Exception */ function now(string $timezone = null): int { diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index a2dae09..3d34c79 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -38,13 +38,9 @@ */ /** - * CodeIgniter Directory Helpers + * CodeIgniter File System Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/directory_helper.html + * @package CodeIgniter */ // ------------------------------------------------------------------------ @@ -59,7 +55,7 @@ * * @param string $source_dir Path to source * @param integer $directory_depth Depth of directories to traverse - * (0 = fully recursive, 1 = current dir, etc) + * (0 = fully recursive, 1 = current dir, etc) * @param boolean $hidden Whether to show hidden files * * @return array @@ -70,7 +66,7 @@ { $fp = opendir($source_dir); - $filedata = []; + $fileData = []; $new_depth = $directory_depth - 1; $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; @@ -86,16 +82,16 @@ if (($directory_depth < 1 || $new_depth > 0) && is_dir($source_dir . $file)) { - $filedata[$file] = directory_map($source_dir . $file, $new_depth, $hidden); + $fileData[$file] = directory_map($source_dir . $file, $new_depth, $hidden); } else { - $filedata[] = $file; + $fileData[] = $file; } } closedir($fp); - return $filedata; + return $fileData; } catch (\Exception $fe) { @@ -160,14 +156,14 @@ * If the second parameter is set to true, any directories contained * within the supplied base directory will be nuked as well. * - * @param string $path File path - * @param boolean $delDir Whether to delete any directories found in the path - * @param boolean $htdocs Whether to skip deleting .htaccess and index page files - * @param integer $_level Current directory depth level (default: 0; internal use only) + * @param string $path File path + * @param boolean $del_dir Whether to delete any directories found in the path + * @param boolean $htdocs Whether to skip deleting .htaccess and index page files + * @param integer $_level Current directory depth level (default: 0; internal use only) * * @return boolean */ - function delete_files(string $path, bool $delDir = false, bool $htdocs = false, int $_level = 0): bool + function delete_files(string $path, bool $del_dir = false, bool $htdocs = false, int $_level = 0): bool { // Trim the trailing slash $path = rtrim($path, '/\\'); @@ -182,7 +178,7 @@ { if (is_dir($path . DIRECTORY_SEPARATOR . $filename) && $filename[0] !== '.') { - delete_files($path . DIRECTORY_SEPARATOR . $filename, $delDir, $htdocs, $_level + 1); + delete_files($path . DIRECTORY_SEPARATOR . $filename, $del_dir, $htdocs, $_level + 1); } elseif ($htdocs !== true || ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @@ -193,7 +189,7 @@ closedir($current_dir); - return ($delDir === true && $_level > 0) ? @rmdir($path) : true; + return ($del_dir === true && $_level > 0) ? @rmdir($path) : true; } catch (\Exception $fe) { @@ -220,7 +216,7 @@ */ function get_filenames(string $source_dir, bool $include_path = false, bool $recursion = false): array { - static $filedata = []; + static $fileData = []; try { @@ -228,7 +224,7 @@ // reset the array and make sure $source_dir has a trailing slash on the initial call if ($recursion === false) { - $filedata = []; + $fileData = []; $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } @@ -240,12 +236,12 @@ } elseif ($file[0] !== '.') { - $filedata[] = ($include_path === true) ? $source_dir . $file : $file; + $fileData[] = ($include_path === true) ? $source_dir . $file : $file; } } closedir($fp); - return $filedata; + return $fileData; } catch (\Exception $fe) { @@ -274,7 +270,7 @@ */ function get_dir_file_info(string $source_dir, bool $top_level_only = true, bool $recursion = false): array { - static $filedata = []; + static $fileData = []; $relative_path = $source_dir; try @@ -283,7 +279,7 @@ // reset the array and make sure $source_dir has a trailing slash on the initial call if ($recursion === false) { - $filedata = []; + $fileData = []; $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } @@ -296,13 +292,13 @@ } elseif ($file[0] !== '.') { - $filedata[$file] = get_file_info($source_dir . $file); - $filedata[$file]['relative_path'] = $relative_path; + $fileData[$file] = get_file_info($source_dir . $file); + $fileData[$file]['relative_path'] = $relative_path; } } closedir($fp); - return $filedata; + return $fileData; } } catch (\Exception $fe) @@ -345,33 +341,33 @@ { switch ($key) { case 'name': - $fileinfo['name'] = basename($file); + $fileInfo['name'] = basename($file); break; case 'server_path': - $fileinfo['server_path'] = $file; + $fileInfo['server_path'] = $file; break; case 'size': - $fileinfo['size'] = filesize($file); + $fileInfo['size'] = filesize($file); break; case 'date': - $fileinfo['date'] = filemtime($file); + $fileInfo['date'] = filemtime($file); break; case 'readable': - $fileinfo['readable'] = is_readable($file); + $fileInfo['readable'] = is_readable($file); break; case 'writable': - $fileinfo['writable'] = is_really_writable($file); + $fileInfo['writable'] = is_really_writable($file); break; case 'executable': - $fileinfo['executable'] = is_executable($file); + $fileInfo['executable'] = is_executable($file); break; case 'fileperms': - $fileinfo['fileperms'] = fileperms($file); + $fileInfo['fileperms'] = fileperms($file); break; } } - return $fileinfo; + return $fileInfo; } } @@ -469,11 +465,11 @@ * Set Realpath * * @param string $path - * @param boolean $checkExistance Checks to see if the path exists + * @param boolean $check_existence Checks to see if the path exists * * @return string */ - function set_realpath(string $path, bool $checkExistance = false): string + function set_realpath(string $path, bool $check_existence = false): string { // Security check to make sure the path is NOT a URL. No remote file inclusion! if (preg_match('#^(http:\/\/|https:\/\/|www\.|ftp)#i', $path) || filter_var($path, FILTER_VALIDATE_IP) === $path) @@ -486,7 +482,7 @@ { $path = realpath($path); } - elseif ($checkExistance && ! is_dir($path) && ! is_file($path)) + elseif ($check_existence && ! is_dir($path) && ! is_file($path)) { throw new InvalidArgumentException('Not a valid path: ' . $path); } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index ad051bd..ccc2b24 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,11 +41,7 @@ /** * CodeIgniter Form Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ //-------------------------------------------------------------------- @@ -96,7 +92,8 @@ $form = '
\n"; // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites - $before = Services::filters()->getFilters()['before']; + $before = Services::filters() + ->getFilters()['before']; if ((in_array('csrf', $before) || array_key_exists('csrf', $before)) && strpos($action, base_url()) !== false && ! stripos($form, 'method="get"')) { diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php index a1cc95e..7f11aac 100755 --- a/system/Helpers/html_helper.php +++ b/system/Helpers/html_helper.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -40,11 +40,7 @@ /** * CodeIgniter HTML Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/html_helper.html + * @package CodeIgniter */ if (! function_exists('ul')) { @@ -335,8 +331,7 @@ * contain one or more video sources * * @param mixed $src Either a source string or an array of sources - * @param string $unsupportedMessage The message to display - * if the media tag is not supported by the browser + * @param string $unsupportedMessage The message to display if the media tag is not supported by the browser * @param string $attributes HTML attributes * @param array $tracks * @param boolean $indexPage @@ -466,7 +461,7 @@ * * @param string $name * @param array $types - * @param string $unsupportedMessage + * @param string $unsupportedMessage The message to display if the media tag is not supported by the browser. * @param string $attributes * @param array $tracks * @@ -522,8 +517,7 @@ * for either audio or video element * * @param string $src The path of the media resource - * @param string $type The MIME-type of the resource with - * optional codecs parameters + * @param string $type The MIME-type of the resource with optional codecs parameters * @param string $attributes HTML attributes * @param boolean $indexPage * @return string @@ -699,6 +693,8 @@ if (! function_exists('_has_protocol')) { /** + * Test the protocol of a URI. + * * @param string $url * * @return false|integer @@ -714,11 +710,13 @@ if (! function_exists('_space_indent')) { /** + * Provide space indenting. + * * @param integer $depth * * @return string */ - function _space_indent($depth = 2): string + function _space_indent(int $depth = 2): string { return str_repeat(' ', $depth); } diff --git a/system/Helpers/inflector_helper.php b/system/Helpers/inflector_helper.php index 5fa0ae1..e624b3a 100755 --- a/system/Helpers/inflector_helper.php +++ b/system/Helpers/inflector_helper.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -40,11 +40,7 @@ /** * CodeIgniter Inflector Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/inflector_helper.html + * @package CodeIgniter */ if (! function_exists('singular')) { @@ -241,53 +237,58 @@ * @param string $word Word to check * @return boolean */ - function is_pluralizable($word): bool + function is_pluralizable(string $word): bool { $uncountables = in_array ( - strtolower($word), [ - 'advice', - 'bravery', - 'butter', - 'clarity', - 'coal', - 'courage', - 'cowardice', - 'curiosity', - 'education', - 'equipment', - 'evidence', - 'fish', - 'fun', - 'furniture', - 'help', - 'homework', - 'honesty', - 'information', - 'insurance', - 'jewelry', - 'knowledge', - 'livestock', - 'love', - 'luck', - 'marketing', - 'meta', - 'money', - 'mud', - 'news', - 'rice', - 'satisfaction', - 'scenery', - 'series', - 'silence', - 'species', - 'spelling', - 'sugar', - 'water', - 'weather', - 'wisdom', - 'work', - ]); + strtolower($word), [ + 'advice', + 'bravery', + 'butter', + 'chaos', + 'clarity', + 'coal', + 'courage', + 'cowardice', + 'curiosity', + 'education', + 'equipment', + 'evidence', + 'fish', + 'fun', + 'furniture', + 'greed', + 'help', + 'homework', + 'honesty', + 'information', + 'insurance', + 'jewelry', + 'knowledge', + 'livestock', + 'love', + 'luck', + 'marketing', + 'meta', + 'money', + 'mud', + 'news', + 'patriotism', + 'racism', + 'rice', + 'satisfaction', + 'scenery', + 'series', + 'sexism', + 'silence', + 'species', + 'spelling', + 'sugar', + 'water', + 'weather', + 'wisdom', + 'work', + ]); return ! $uncountables; } diff --git a/system/Helpers/number_helper.php b/system/Helpers/number_helper.php index 35126f8..7723c96 100644 --- a/system/Helpers/number_helper.php +++ b/system/Helpers/number_helper.php @@ -39,11 +39,7 @@ /** * CodeIgniter Number Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('number_to_size')) @@ -70,35 +66,35 @@ } // ignore sub part - $genralLocale = $locale; + $generalLocale = $locale; if (! empty($locale) && ( $underscorePos = strpos($locale, '_'))) { - $genralLocale = substr($locale, 0, $underscorePos); + $generalLocale = substr($locale, 0, $underscorePos); } if ($num >= 1000000000000) { $num = round($num / 1099511627776, $precision); - $unit = lang('Number.terabyteAbbr', [], $genralLocale); + $unit = lang('Number.terabyteAbbr', [], $generalLocale); } elseif ($num >= 1000000000) { $num = round($num / 1073741824, $precision); - $unit = lang('Number.gigabyteAbbr', [], $genralLocale); + $unit = lang('Number.gigabyteAbbr', [], $generalLocale); } elseif ($num >= 1000000) { $num = round($num / 1048576, $precision); - $unit = lang('Number.megabyteAbbr', [], $genralLocale); + $unit = lang('Number.megabyteAbbr', [], $generalLocale); } elseif ($num >= 1000) { $num = round($num / 1024, $precision); - $unit = lang('Number.kilobyteAbbr', [], $genralLocale); + $unit = lang('Number.kilobyteAbbr', [], $generalLocale); } else { - $unit = lang('Number.bytes', [], $genralLocale); + $unit = lang('Number.bytes', [], $generalLocale); } return format_number($num, $precision, $locale, ['after' => ' ' . $unit]); @@ -141,35 +137,35 @@ $suffix = ''; // ignore sub part - $genralLocale = $locale; + $generalLocale = $locale; if (! empty($locale) && ( $underscorePos = strpos($locale, '_'))) { - $genralLocale = substr($locale, 0, $underscorePos); + $generalLocale = substr($locale, 0, $underscorePos); } if ($num > 1000000000000000) { - $suffix = lang('Number.quadrillion', [], $genralLocale); + $suffix = lang('Number.quadrillion', [], $generalLocale); $num = round(($num / 1000000000000000), $precision); } elseif ($num > 1000000000000) { - $suffix = lang('Number.trillion', [], $genralLocale); + $suffix = lang('Number.trillion', [], $generalLocale); $num = round(($num / 1000000000000), $precision); } else if ($num > 1000000000) { - $suffix = lang('Number.billion', [], $genralLocale); + $suffix = lang('Number.billion', [], $generalLocale); $num = round(($num / 1000000000), $precision); } else if ($num > 1000000) { - $suffix = lang('Number.million', [], $genralLocale); + $suffix = lang('Number.million', [], $generalLocale); $num = round(($num / 1000000), $precision); } else if ($num > 1000) { - $suffix = lang('Number.thousand', [], $genralLocale); + $suffix = lang('Number.thousand', [], $generalLocale); $num = round(($num / 1000), $precision); } @@ -188,7 +184,7 @@ * * @return string */ - function number_to_currency($num, string $currency, string $locale = null): string + function number_to_currency(float $num, string $currency, string $locale = null): string { return format_number($num, 1, $locale, [ 'type' => NumberFormatter::CURRENCY, @@ -212,7 +208,7 @@ * * @return string */ - function format_number($num, int $precision = 1, string $locale = null, array $options = []): string + function format_number(float $num, int $precision = 1, string $locale = null, array $options = []): string { // Locale is either passed in here, negotiated with client, or grabbed from our config file. $locale = $locale ?? \CodeIgniter\Config\Services::request()->getLocale(); diff --git a/system/Helpers/security_helper.php b/system/Helpers/security_helper.php index 04aa284..1ef170e 100644 --- a/system/Helpers/security_helper.php +++ b/system/Helpers/security_helper.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -41,16 +41,14 @@ /** * CodeIgniter Security Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('sanitize_filename')) { /** + * Sanitize a filename to use in a URI. + * * @param string $filename * * @return string @@ -88,7 +86,7 @@ /** * Convert PHP tags to entities * - * @param string + * @param string $str * @return string */ function encode_php_tags(string $str): string diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 8a49361..6a79350 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -40,11 +40,7 @@ /** * CodeIgniter Text Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/text_helper.html + * @package CodeIgniter */ //-------------------------------------------------------------------- diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 0184b25..5b6dd16 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -31,18 +31,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ /** * CodeIgniter URL Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('site_url')) @@ -529,7 +525,7 @@ * Formerly used URI, but that does not play nicely with URIs missing * the scheme. * - * @param string the URL + * @param string $str the URL * @return string */ function prep_url(string $str = ''): string diff --git a/system/Helpers/xml_helper.php b/system/Helpers/xml_helper.php index e18c579..17be4e9 100644 --- a/system/Helpers/xml_helper.php +++ b/system/Helpers/xml_helper.php @@ -38,11 +38,7 @@ /** * CodeIgniter XML Helpers * - * @package CodeIgniter - * @subpackage Helpers - * @category Helpers - * @author CodeIgniter Dev Team - * @link https://codeigniter.com/user_guide/helpers/cookie_helper.html + * @package CodeIgniter */ if (! function_exists('xml_convert')) diff --git a/system/Honeypot/Honeypot.php b/system/Honeypot/Honeypot.php index 90ef152..de84bfb 100644 --- a/system/Honeypot/Honeypot.php +++ b/system/Honeypot/Honeypot.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -51,12 +51,20 @@ { /** + * Our configuration. + * * @var BaseConfig */ protected $config; //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param BaseConfig $config + * @throws type + */ function __construct(BaseConfig $config) { $this->config = $config; diff --git a/system/I18n/Time.php b/system/I18n/Time.php index f5d03cd..92fd485 100644 --- a/system/I18n/Time.php +++ b/system/I18n/Time.php @@ -32,13 +32,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\I18n; use CodeIgniter\I18n\Exceptions\I18nException; +use IntlCalendar; use Locale; use DateTime; use DateInterval; @@ -71,7 +72,7 @@ /** * Format to use when displaying datetime through __toString * - * @var integer + * @var string */ protected $toStringFormat = 'yyyy-MM-dd HH:mm:ss'; @@ -91,6 +92,15 @@ // Constructors //-------------------------------------------------------------------- + /** + * Time constructor. + * + * @param string|null $time + * @param null $timezone + * @param string|null $locale + * + * @throws \Exception + */ public function __construct(string $time = null, $timezone = null, string $locale = null) { // If no locale was provided, grab it from Locale (set by IncomingRequest for web requests) @@ -136,6 +146,7 @@ * @param string|null $locale * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public static function now($timezone = null, string $locale = null) { @@ -155,6 +166,7 @@ * @param string|null $locale * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public static function parse(string $datetime, $timezone = null, string $locale = null) { @@ -170,6 +182,7 @@ * @param string|null $locale * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public static function today($timezone = null, string $locale = null) { @@ -217,10 +230,11 @@ * @param integer|null $year * @param integer|null $month * @param integer|null $day - * @param $timezone + * @param null $timezone * @param string $locale * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public static function createFromDate(int $year = null, int $month = null, int $day = null, $timezone = null, string $locale = null) { @@ -239,6 +253,7 @@ * @param string|null $locale * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public static function createFromTime(int $hour = null, int $minutes = null, int $seconds = null, $timezone = null, string $locale = null) { @@ -280,9 +295,9 @@ * Provides a replacement for DateTime's own createFromFormat function, that provides * more flexible timeZone handling * - * @param string $format - * @param string $datetime - * @param DateTimeZone $timeZone + * @param string $format + * @param string $datetime + * @param DateTimeZone|string $timeZone * * @return \CodeIgniter\I18n\Time * @throws \Exception @@ -322,7 +337,7 @@ * @return \CodeIgniter\I18n\Time * @throws \Exception */ - public static function instance(\DateTime $dateTime, string $locale = null) + public static function instance(DateTime $dateTime, string $locale = null) { $date = $dateTime->format('Y-m-d H:i:s'); $timezone = $dateTime->getTimezone(); @@ -340,7 +355,7 @@ */ public function toDateTime() { - $dateTime = new \DateTime(null, $this->getTimezone()); + $dateTime = new DateTime(null, $this->getTimezone()); $dateTime->setTimestamp(parent::getTimestamp()); return $dateTime; @@ -374,7 +389,7 @@ { $datetime = new Time($datetime, $timezone, $locale); } - else if ($datetime instanceof \DateTime && ! $datetime instanceof Time) + else if ($datetime instanceof DateTime && ! $datetime instanceof Time) { $datetime = new Time($datetime->format('Y-m-d H:i:s'), $timezone); } @@ -403,6 +418,7 @@ * Returns the localized Year * * @return string + * @throws \Exception */ public function getYear(): string { @@ -415,6 +431,7 @@ * Returns the localized Month * * @return string + * @throws \Exception */ public function getMonth(): string { @@ -427,6 +444,7 @@ * Return the localized day of the month. * * @return string + * @throws \Exception */ public function getDay(): string { @@ -439,6 +457,7 @@ * Return the localized hour (in 24-hour format). * * @return string + * @throws \Exception */ public function getHour(): string { @@ -451,6 +470,7 @@ * Return the localized minutes in the hour. * * @return string + * @throws \Exception */ public function getMinute(): string { @@ -463,6 +483,7 @@ * Return the localized seconds * * @return string + * @throws \Exception */ public function getSecond(): string { @@ -475,6 +496,7 @@ * Return the index of the day of the week * * @return string + * @throws \Exception */ public function getDayOfWeek(): string { @@ -487,6 +509,7 @@ * Return the index of the day of the year * * @return string + * @throws \Exception */ public function getDayOfYear(): string { @@ -499,6 +522,7 @@ * Return the index of the week in the month * * @return string + * @throws \Exception */ public function getWeekOfMonth(): string { @@ -511,6 +535,7 @@ * Return the index of the week in the year * * @return string + * @throws \Exception */ public function getWeekOfYear(): string { @@ -521,6 +546,8 @@ /** * Returns the age in years from the "current" date and 'now' + * + * @throws \Exception */ public function getAge() { @@ -537,6 +564,7 @@ * Returns the number of the current quarter for the year. * * @return string + * @throws \Exception */ public function getQuarter(): string { @@ -547,8 +575,10 @@ /** * Are we in daylight savings time currently? + * + * @return boolean */ - public function getDst() + public function getDst(): bool { // grab the transactions that would affect today $start = strtotime('-1 year', $this->getTimestamp()); @@ -571,6 +601,8 @@ /** * Returns boolean whether the passed timezone is the same as * the local timezone. + * + * @return boolean */ public function getLocal(): bool { @@ -583,6 +615,8 @@ /** * Returns boolean whether object is in UTC. + * + * @return boolean */ public function getUtc(): bool { @@ -609,6 +643,7 @@ * @param $value * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setYear($value) { @@ -621,6 +656,7 @@ * @param $value * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setMonth($value) { @@ -643,6 +679,7 @@ * @param $value * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setDay($value) { @@ -667,6 +704,7 @@ * @param $value * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setHour($value) { @@ -684,6 +722,7 @@ * @param $value * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setMinute($value) { @@ -701,6 +740,7 @@ * @param $value * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setSecond($value) { @@ -735,6 +775,7 @@ * @param \DateTimeZone $timezone * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setTimezone($timezone) { @@ -747,6 +788,7 @@ * @param integer $timestamp * * @return \CodeIgniter\I18n\Time + * @throws \Exception */ public function setTimestamp($timestamp) { @@ -933,6 +975,8 @@ /** * Returns the localized value of the date in the format 'Y-m-d H:i:s' + * + * @throws \Exception */ public function toDateTimeString() { @@ -945,6 +989,7 @@ * Returns a localized version of the date in Y-m-d format. * * @return string + * @throws \Exception */ public function toDateString() { @@ -959,6 +1004,7 @@ * i.e. Apr 1, 2017 * * @return string + * @throws \Exception */ public function toFormattedDateString() { @@ -973,6 +1019,7 @@ * i.e. 13:20:33 * * @return string + * @throws \Exception */ public function toTimeString() { @@ -986,7 +1033,7 @@ * * @param string|null $format * - * @return string + * @return string|boolean * @throws \Exception */ public function toLocalizedString(?string $format = null) @@ -1033,6 +1080,7 @@ * @param string|null $timezone * * @return boolean + * @throws \Exception */ public function sameAs($testTime, string $timezone = null): bool { @@ -1063,6 +1111,7 @@ * @param string|null $timezone * * @return boolean + * @throws \Exception */ public function isBefore($testTime, string $timezone = null): bool { @@ -1082,6 +1131,7 @@ * @param string|null $timezone * * @return boolean + * @throws \Exception */ public function isAfter($testTime, string $timezone = null): bool { @@ -1103,17 +1153,20 @@ * - 3 weeks ago * - in 4 days * - 6 hours ago + * + * @return mixed + * @throws \Exception */ public function humanize() { - $now = \IntlCalendar::fromDateTime(Time::now($this->timezone)->toDateTimeString()); + $now = IntlCalendar::fromDateTime(Time::now($this->timezone)->toDateTimeString()); $time = $this->getCalendar()->getTime(); - $years = $now->fieldDifference($time, \IntlCalendar::FIELD_YEAR); - $months = $now->fieldDifference($time, \IntlCalendar::FIELD_MONTH); - $days = $now->fieldDifference($time, \IntlCalendar::FIELD_DAY_OF_YEAR); - $hours = $now->fieldDifference($time, \IntlCalendar::FIELD_HOUR_OF_DAY); - $minutes = $now->fieldDifference($time, \IntlCalendar::FIELD_MINUTE); + $years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR); + $months = $now->fieldDifference($time, IntlCalendar::FIELD_MONTH); + $days = $now->fieldDifference($time, IntlCalendar::FIELD_DAY_OF_YEAR); + $hours = $now->fieldDifference($time, IntlCalendar::FIELD_HOUR_OF_DAY); + $minutes = $now->fieldDifference($time, IntlCalendar::FIELD_MINUTE); $phrase = null; @@ -1168,6 +1221,7 @@ * @param string|null $timezone * * @return \CodeIgniter\I18n\TimeDifference + * @throws \Exception */ public function difference($testTime, string $timezone = null) { @@ -1188,6 +1242,7 @@ * @param string|null $timezone * * @return \DateTime|static + * @throws \Exception */ public function getUTCObject($time, string $timezone = null) { @@ -1196,7 +1251,7 @@ $time = $time->toDateTime() ->setTimezone(new DateTimeZone('UTC')); } - else if ($time instanceof \DateTime) + else if ($time instanceof DateTime) { $time = $time->setTimezone(new DateTimeZone('UTC')); } @@ -1221,10 +1276,11 @@ * but available for public consumption if they need it. * * @return \IntlCalendar + * @throws \Exception */ public function getCalendar() { - return \IntlCalendar::fromDateTime($this->toDateTimeString()); + return IntlCalendar::fromDateTime($this->toDateTimeString()); } //-------------------------------------------------------------------- @@ -1282,6 +1338,8 @@ { return $this->$method(); } + + return null; } } diff --git a/system/I18n/TimeDifference.php b/system/I18n/TimeDifference.php index b1c19bf..e431213 100644 --- a/system/I18n/TimeDifference.php +++ b/system/I18n/TimeDifference.php @@ -1,42 +1,45 @@ -difference = $currentTime->getTimestamp() - $testTime->getTimestamp(); - $current = \IntlCalendar::fromDateTime($currentTime->format('Y-m-d H:i:s')); - $time = \IntlCalendar::fromDateTime($testTime->format('Y-m-d H:i:s')) + $current = IntlCalendar::fromDateTime($currentTime->format('Y-m-d H:i:s')); + $time = IntlCalendar::fromDateTime($testTime->format('Y-m-d H:i:s')) ->getTime(); $this->currentTime = $current; @@ -136,7 +155,7 @@ } $time = clone($this->currentTime); - return $time->fieldDifference($this->testTime, \IntlCalendar::FIELD_YEAR); + return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_YEAR); } /** @@ -154,7 +173,7 @@ } $time = clone($this->currentTime); - return $time->fieldDifference($this->testTime, \IntlCalendar::FIELD_MONTH); + return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_MONTH); } /** @@ -172,7 +191,7 @@ } $time = clone($this->currentTime); - return (int)($time->fieldDifference($this->testTime, \IntlCalendar::FIELD_DAY_OF_YEAR) / 7); + return (int)($time->fieldDifference($this->testTime, IntlCalendar::FIELD_DAY_OF_YEAR) / 7); } /** @@ -190,7 +209,7 @@ } $time = clone($this->currentTime); - return $time->fieldDifference($this->testTime, \IntlCalendar::FIELD_DAY_OF_YEAR); + return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_DAY_OF_YEAR); } /** @@ -208,7 +227,7 @@ } $time = clone($this->currentTime); - return $time->fieldDifference($this->testTime, \IntlCalendar::FIELD_HOUR_OF_DAY); + return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_HOUR_OF_DAY); } /** @@ -226,7 +245,7 @@ } $time = clone($this->currentTime); - return $time->fieldDifference($this->testTime, \IntlCalendar::FIELD_MINUTE); + return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_MINUTE); } /** @@ -244,18 +263,25 @@ } $time = clone($this->currentTime); - return $time->fieldDifference($this->testTime, \IntlCalendar::FIELD_SECOND); + return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_SECOND); } + /** + * Convert the time to human readable format + * + * @param string|null $locale + * + * @return string + */ public function humanize(string $locale = null): string { $current = clone($this->currentTime); - $years = $current->fieldDifference($this->testTime, \IntlCalendar::FIELD_YEAR); - $months = $current->fieldDifference($this->testTime, \IntlCalendar::FIELD_MONTH); - $days = $current->fieldDifference($this->testTime, \IntlCalendar::FIELD_DAY_OF_YEAR); - $hours = $current->fieldDifference($this->testTime, \IntlCalendar::FIELD_HOUR_OF_DAY); - $minutes = $current->fieldDifference($this->testTime, \IntlCalendar::FIELD_MINUTE); + $years = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_YEAR); + $months = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_MONTH); + $days = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_DAY_OF_YEAR); + $hours = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_HOUR_OF_DAY); + $minutes = $current->fieldDifference($this->testTime, IntlCalendar::FIELD_MINUTE); $phrase = null; @@ -316,5 +342,7 @@ { return $this->{$method}($name); } + + return null; } } diff --git a/system/Images/Handlers/BaseHandler.php b/system/Images/Handlers/BaseHandler.php index f3c39d0..4b02144 100644 --- a/system/Images/Handlers/BaseHandler.php +++ b/system/Images/Handlers/BaseHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -49,23 +49,54 @@ { /** + * Configuration settings. + * * @var \Config\Images */ protected $config; /** * The image/file instance - * d * * @var \CodeIgniter\Images\Image */ - protected $image = null; - protected $width = 0; - protected $height = 0; + protected $image = null; + /** + * Image width. + * + * @var integer + */ + protected $width = 0; + /** + * Image height. + * + * @var integer + */ + protected $height = 0; + /** + * File permission mask. + * + * @var type + */ protected $filePermissions = 0644; - protected $xAxis = 0; - protected $yAxis = 0; - protected $masterDim = 'auto'; + /** + * X-axis. + * + * @var integer + */ + protected $xAxis = 0; + /** + * Y-axis. + * + * @var integer + */ + protected $yAxis = 0; + /** + * Master dimensioning. + * + * @var string + */ + protected $masterDim = 'auto'; /** * Default options for text watermarking. @@ -96,6 +127,11 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + */ public function __construct($config = null) { $this->config = $config; @@ -480,7 +516,7 @@ $exif = exif_read_data($this->image->getPathname()); if (! is_null($key) && is_array($exif)) { - $exif = array_key_exists($key, $exif) ? $exif[$key] : false; + $exif = $exif[$key] ?? false; } return $exif; @@ -529,7 +565,7 @@ //-------------------------------------------------------------------- /** - * + * Calculate image aspect ratio. * * @param $width * @param null $height @@ -678,6 +714,8 @@ * * @param string $name * @param array $args + * + * @return mixed */ public function __call(string $name, array $args = []) { @@ -746,13 +784,25 @@ } //-------------------------------------------------------------------- - // accessor for testing; not part of interface + /** + * Return image width. + * + * accessor for testing; not part of interface + * + * @return integer + */ public function getWidth() { return ($this->resource !== null) ? $this->_getWidth() : $this->width; } - // accessor for testing; not part of interface + /** + * Return image height. + * + * accessor for testing; not part of interface + * + * @return type + */ public function getHeight() { return ($this->resource !== null) ? $this->_getHeight() : $this->height; diff --git a/system/Images/Handlers/GDHandler.php b/system/Images/Handlers/GDHandler.php index b5fb2bf..02c9178 100644 --- a/system/Images/Handlers/GDHandler.php +++ b/system/Images/Handlers/GDHandler.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -45,8 +45,12 @@ class GDHandler extends BaseHandler { - public $version; - + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config = null) { parent::__construct($config); @@ -70,7 +74,7 @@ * * @return boolean */ - protected function _rotate(int $angle) + protected function _rotate(int $angle): bool { // Create the image handle $srcImg = $this->createImage(); @@ -311,7 +315,7 @@ * * @return boolean */ - public function save(string $target = null, int $quality = 90) + public function save(string $target = null, int $quality = 90): bool { $target = empty($target) ? $this->image->getPathname() : $target; @@ -370,12 +374,12 @@ * This simply creates an image resource handle * based on the type of image being processed * - * @param string - * @param string + * @param string $path + * @param string $imageType * * @return resource|boolean */ - protected function createImage($path = '', $imageType = '') + protected function createImage(string $path = '', string $imageType = '') { if ($this->resource !== null) { @@ -422,6 +426,14 @@ //-------------------------------------------------------------------- + /** + * Add text overlay to an image. + * + * @param string $text + * @param array $options + * + * @return void + */ protected function _text(string $text, array $options = []) { // Reverse the vertical offset @@ -555,11 +567,21 @@ //-------------------------------------------------------------------- + /** + * Return image width. + * + * @return integer + */ public function _getWidth() { return imagesx($this->resource); } + /** + * Return image height. + * + * @return integer + */ public function _getHeight() { return imagesy($this->resource); diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index 1705ebd..f928b28 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -32,14 +32,13 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Images\Handlers; use CodeIgniter\Images\Exceptions\ImageException; -use CodeIgniter\Images\Image; /** * Class ImageMagickHandler @@ -57,8 +56,6 @@ class ImageMagickHandler extends BaseHandler { - public $version; - /** * Stores image resource in memory. * @@ -68,6 +65,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @throws type + */ public function __construct($config = null) { parent::__construct($config); @@ -89,6 +92,7 @@ * @param boolean $maintainRatio * * @return ImageMagickHandler + * @throws \Exception */ public function _resize(bool $maintainRatio = false) { @@ -114,6 +118,7 @@ * Crops the image. * * @return boolean|\CodeIgniter\Images\Handlers\ImageMagickHandler + * @throws \Exception */ public function _crop() { @@ -136,6 +141,7 @@ * @param integer $angle * * @return $this + * @throws \Exception */ protected function _rotate(int $angle) { @@ -161,6 +167,7 @@ * @param integer $blue * * @return $this + * @throws \Exception */ public function _flatten(int $red = 255, int $green = 255, int $blue = 255) { @@ -184,6 +191,7 @@ * @param string $direction * * @return $this + * @throws \Exception */ public function _flip(string $direction) { @@ -202,11 +210,11 @@ //-------------------------------------------------------------------- /** - * Get GD version + * Get driver version * - * @return mixed + * @return string */ - public function getVersion() + public function getVersion(): string { $result = $this->process('-version'); @@ -274,7 +282,7 @@ * * @return boolean */ - public function save(string $target = null, int $quality = 90) + public function save(string $target = null, int $quality = 90): bool { $target = empty($target) ? $this->image : $target; @@ -314,6 +322,7 @@ * during the process, we'll use a PNG as the temp file type. * * @return resource|boolean + * @throws \Exception */ protected function getResourcePath() { @@ -334,6 +343,8 @@ * * @param string $text * @param array $options + * + * @throws \Exception */ protected function _text(string $text, array $options = []) { @@ -430,13 +441,21 @@ //-------------------------------------------------------------------- - //-------------------------------------------------------------------- - + /** + * Return the width of an image. + * + * @return type + */ public function _getWidth() { return imagesx($this->resource); } + /** + * Return the height of an image. + * + * @return type + */ public function _getHeight() { return imagesy($this->resource); diff --git a/system/Images/Image.php b/system/Images/Image.php index 43d0949..3e7e608 100644 --- a/system/Images/Image.php +++ b/system/Images/Image.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -95,7 +95,7 @@ * * @return boolean */ - public function copy(string $targetPath, string $targetName = null, int $perms = 0644) + public function copy(string $targetPath, string $targetName = null, int $perms = 0644): bool { $targetPath = rtrim($targetPath, '/ ') . '/'; @@ -132,7 +132,7 @@ * * @return mixed */ - public function getProperties($return = false) + public function getProperties(bool $return = false) { $path = $this->getPathname(); diff --git a/system/Images/ImageHandlerInterface.php b/system/Images/ImageHandlerInterface.php index 8269f4a..ea5f07e 100644 --- a/system/Images/ImageHandlerInterface.php +++ b/system/Images/ImageHandlerInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Language/Language.php b/system/Language/Language.php index c93240a..19494f7 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -1,6 +1,4 @@ 'Invalid file: {0}', - 'copyError' => 'An error was encountered while attempting to replace the file. Please make sure your file directory is writable.', + 'copyError' => 'An error was encountered while attempting to replace the file({0}). Please make sure your file directory is writable.', 'missingExtension' => '{0} extension is not loaded.', 'noHandlers' => '{0} must provide at least one Handler.', ]; diff --git a/system/Language/en/Database.php b/system/Language/en/Database.php index 9afce18..250550c 100644 --- a/system/Language/en/Database.php +++ b/system/Language/en/Database.php @@ -8,24 +8,25 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore */ return [ - 'invalidEvent' => '{0} is not a valid Model Event callback.', - 'invalidArgument' => 'You must provide a valid {0}.', - 'invalidAllowedFields' => 'Allowed fields must be specified for model: {0}', - 'emptyDataset' => 'There is no data to {0}.', - 'failGetFieldData' => 'Failed to get field data from database.', - 'failGetIndexData' => 'Failed to get index data from database.', - 'failGetForeignKeyData' => 'Failed to get foreign key data from database.', - 'parseStringFail' => 'Parsing key string failed.', - 'featureUnavailable' => 'This feature is not available for the database you are using.', - 'tableNotFound' => 'Table `{0}` was not found in the current database.', - 'noPrimaryKey' => '`{0}` model class does not specify a Primary Key.', - 'forEmptyInputGiven' => 'Empty statement is given for the field `{0}`', - 'forFindColumnHaveMultipleColumns' => 'Only single column allowed in Column name.', + 'invalidEvent' => '{0} is not a valid Model Event callback.', + 'invalidArgument' => 'You must provide a valid {0}.', + 'invalidAllowedFields' => 'Allowed fields must be specified for model: {0}', + 'emptyDataset' => 'There is no data to {0}.', + 'failGetFieldData' => 'Failed to get field data from database.', + 'failGetIndexData' => 'Failed to get index data from database.', + 'failGetForeignKeyData' => 'Failed to get foreign key data from database.', + 'parseStringFail' => 'Parsing key string failed.', + 'featureUnavailable' => 'This feature is not available for the database you are using.', + 'tableNotFound' => 'Table `{0}` was not found in the current database.', + 'noPrimaryKey' => '`{0}` model class does not specify a Primary Key.', + 'fieldNotExists' => 'Field `{0}` not found.', + 'forEmptyInputGiven' => 'Empty statement is given for the field `{0}`', + 'forFindColumnHaveMultipleColumns' => 'Only single column allowed in Column name.', ]; diff --git a/system/Language/en/Entity.php b/system/Language/en/Entity.php new file mode 100644 index 0000000..36d5f47 --- /dev/null +++ b/system/Language/en/Entity.php @@ -0,0 +1,19 @@ + 'Trying to access non existent property {0} of {1}' +]; diff --git a/system/Language/en/Files.php b/system/Language/en/Files.php index e653960..37d551b 100644 --- a/system/Language/en/Files.php +++ b/system/Language/en/Files.php @@ -7,7 +7,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Filters.php b/system/Language/en/Filters.php index d376b17..9a525db 100644 --- a/system/Language/en/Filters.php +++ b/system/Language/en/Filters.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Format.php b/system/Language/en/Format.php index 528819c..1f7c39b 100644 --- a/system/Language/en/Format.php +++ b/system/Language/en/Format.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/HTTP.php b/system/Language/en/HTTP.php index 6b423bb..a43d814 100644 --- a/system/Language/en/HTTP.php +++ b/system/Language/en/HTTP.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Images.php b/system/Language/en/Images.php index 6417d53..ec413eb 100644 --- a/system/Language/en/Images.php +++ b/system/Language/en/Images.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Language.php b/system/Language/en/Language.php index 620b256..17866d3 100644 --- a/system/Language/en/Language.php +++ b/system/Language/en/Language.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Log.php b/system/Language/en/Log.php index 10768f5..f2c2d78 100644 --- a/system/Language/en/Log.php +++ b/system/Language/en/Log.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Migrations.php b/system/Language/en/Migrations.php index e9fd99b..75204de 100644 --- a/system/Language/en/Migrations.php +++ b/system/Language/en/Migrations.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Number.php b/system/Language/en/Number.php index 5ef92f8..c399962 100644 --- a/system/Language/en/Number.php +++ b/system/Language/en/Number.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Pager.php b/system/Language/en/Pager.php index 85a8c0c..e18fb6c 100644 --- a/system/Language/en/Pager.php +++ b/system/Language/en/Pager.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Redirect.php b/system/Language/en/Redirect.php new file mode 100644 index 0000000..4d78f41 --- /dev/null +++ b/system/Language/en/Redirect.php @@ -0,0 +1,19 @@ + 'Unable to redirect to "{0}". Error status code "{1}"', +]; diff --git a/system/Language/en/Router.php b/system/Language/en/Router.php index 32abac5..627ad67 100644 --- a/system/Language/en/Router.php +++ b/system/Language/en/Router.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Session.php b/system/Language/en/Session.php index 4204a4c..11df76e 100644 --- a/system/Language/en/Session.php +++ b/system/Language/en/Session.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Time.php b/system/Language/en/Time.php index a731749..62791c7 100644 --- a/system/Language/en/Time.php +++ b/system/Language/en/Time.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Language/en/Validation.php b/system/Language/en/Validation.php index fb43b66..46754ef 100644 --- a/system/Language/en/Validation.php +++ b/system/Language/en/Validation.php @@ -8,7 +8,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore @@ -30,6 +30,7 @@ 'alpha_space' => 'The {field} field may only contain alphabetical characters and spaces.', 'decimal' => 'The {field} field must contain a decimal number.', 'differs' => 'The {field} field must differ from the {param} field.', + 'equals' => 'The {field} field must be exactly: {param}.', 'exact_length' => 'The {field} field must be exactly {param} characters in length.', 'greater_than' => 'The {field} field must contain a number greater than {param}.', 'greater_than_equal_to' => 'The {field} field must contain a number greater than or equal to {param}.', @@ -43,6 +44,7 @@ 'matches' => 'The {field} field does not match the {param} field.', 'max_length' => 'The {field} field cannot exceed {param} characters in length.', 'min_length' => 'The {field} field must be at least {param} characters in length.', + 'not_equals' => 'The {field} field cannot be: {param}.', 'numeric' => 'The {field} field must contain only numbers.', 'regex_match' => 'The {field} field is not in the correct format.', 'required' => 'The {field} field is required.', diff --git a/system/Language/en/View.php b/system/Language/en/View.php index 8f179ee..85b988a 100644 --- a/system/Language/en/View.php +++ b/system/Language/en/View.php @@ -7,7 +7,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource * * @codeCoverageIgnore diff --git a/system/Log/Handlers/BaseHandler.php b/system/Log/Handlers/BaseHandler.php index cc55ea6..1611543 100644 --- a/system/Log/Handlers/BaseHandler.php +++ b/system/Log/Handlers/BaseHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Log/Handlers/ChromeLoggerHandler.php b/system/Log/Handlers/ChromeLoggerHandler.php index df7b64f..67c15b4 100644 --- a/system/Log/Handlers/ChromeLoggerHandler.php +++ b/system/Log/Handlers/ChromeLoggerHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Log/Handlers/FileHandler.php b/system/Log/Handlers/FileHandler.php index 9a605f6..a74f01e 100644 --- a/system/Log/Handlers/FileHandler.php +++ b/system/Log/Handlers/FileHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Log/Handlers/HandlerInterface.php b/system/Log/Handlers/HandlerInterface.php index 2c7195e..6c213c1 100644 --- a/system/Log/Handlers/HandlerInterface.php +++ b/system/Log/Handlers/HandlerInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Log/Logger.php b/system/Log/Logger.php index 9b01a89..4ae7bd4 100644 --- a/system/Log/Logger.php +++ b/system/Log/Logger.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -198,7 +198,7 @@ * * @return boolean */ - public function emergency($message, array $context = []) + public function emergency($message, array $context = []): bool { return $this->log('emergency', $message, $context); } @@ -216,7 +216,7 @@ * * @return boolean */ - public function alert($message, array $context = []) + public function alert($message, array $context = []): bool { return $this->log('alert', $message, $context); } @@ -233,7 +233,7 @@ * * @return boolean */ - public function critical($message, array $context = []) + public function critical($message, array $context = []): bool { return $this->log('critical', $message, $context); } @@ -249,7 +249,7 @@ * * @return boolean */ - public function error($message, array $context = []) + public function error($message, array $context = []): bool { return $this->log('error', $message, $context); } @@ -267,7 +267,7 @@ * * @return boolean */ - public function warning($message, array $context = []) + public function warning($message, array $context = []): bool { return $this->log('warning', $message, $context); } @@ -282,7 +282,7 @@ * * @return boolean */ - public function notice($message, array $context = []) + public function notice($message, array $context = []): bool { return $this->log('notice', $message, $context); } @@ -299,7 +299,7 @@ * * @return boolean */ - public function info($message, array $context = []) + public function info($message, array $context = []): bool { return $this->log('info', $message, $context); } @@ -314,7 +314,7 @@ * * @return boolean */ - public function debug($message, array $context = []) + public function debug($message, array $context = []): bool { return $this->log('debug', $message, $context); } @@ -407,10 +407,10 @@ * {file} * {line} * - * @param $message - * @param array $context + * @param mixed $message + * @param array $context * - * @return string + * @return mixed */ protected function interpolate($message, array $context = []) { @@ -481,7 +481,7 @@ * * @return array */ - public function determineFile() + public function determineFile(): array { // Determine the file and line by finding the first // backtrace that is not part of our logging system. @@ -519,9 +519,9 @@ * * @param $file * - * @return mixed + * @return string */ - protected function cleanFileNames($file) + protected function cleanFileNames(string $file): string { $file = str_replace(APPPATH, 'APPPATH/', $file); $file = str_replace(SYSTEMPATH, 'SYSTEMPATH/', $file); diff --git a/system/Model.php b/system/Model.php index 6c633a0..155ef07 100644 --- a/system/Model.php +++ b/system/Model.php @@ -32,12 +32,13 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter; +use Closure; use CodeIgniter\Exceptions\ModelException; use Config\Database; use CodeIgniter\I18n\Time; @@ -47,6 +48,9 @@ use CodeIgniter\Database\ConnectionInterface; use CodeIgniter\Validation\ValidationInterface; use CodeIgniter\Database\Exceptions\DataException; +use ReflectionClass; +use ReflectionProperty; +use stdClass; /** * Class Model @@ -242,23 +246,57 @@ */ protected $validation; - /** + /* * Callbacks. Each array should contain the method * names (within the model) that should be called * when those events are triggered. With the exception * of 'afterFind', all methods are passed the same * items that are given to the update/insert method. * 'afterFind' will also include the results that were found. + */ + + /** + * Callbacks for beforeInsert * - * @var array + * @var type */ protected $beforeInsert = []; - protected $afterInsert = []; + /** + * Callbacks for afterInsert + * + * @var type + */ + protected $afterInsert = []; + /** + * Callbacks for beforeUpdate + * + * @var type + */ protected $beforeUpdate = []; - protected $afterUpdate = []; - protected $afterFind = []; + /** + * Callbacks for afterUpdate + * + * @var type + */ + protected $afterUpdate = []; + /** + * Callbacks for afterFind + * + * @var type + */ + protected $afterFind = []; + /** + * Callbacks for beforeDelete + * + * @var type + */ protected $beforeDelete = []; - protected $afterDelete = []; + /** + * Callbacks for afterDelete + * + * @var type + */ + protected $afterDelete = []; /** * Holds information passed in via 'set' @@ -318,7 +356,7 @@ if ($this->tempUseSoftDeletes === true) { - $builder->where($this->deletedField, 0); + $builder->where($this->table . '.' . $this->deletedField, 0); } if (is_array($id)) @@ -354,11 +392,9 @@ /** * Fetches the column of database from $this->table * - * @param string $column_name Column name + * @param string $columnName * * @return array|null The resulting row of data, or null if no data found. - * - * @throws \CodeIgniter\Database\Exceptions\DataException */ public function findColumn(string $columnName) { @@ -368,10 +404,10 @@ } $resultSet = $this->select($columnName) - ->asArray() - ->find(); + ->asArray() + ->find(); - return (!empty($resultSet)) ? array_column($resultSet, $columnName) : null; + return (! empty($resultSet)) ? array_column($resultSet, $columnName) : null; } //-------------------------------------------------------------------- @@ -391,7 +427,7 @@ if ($this->tempUseSoftDeletes === true) { - $builder->where($this->deletedField, 0); + $builder->where($this->table . '.' . $this->deletedField, 0); } $row = $builder->limit($limit, $offset) @@ -421,7 +457,7 @@ if ($this->tempUseSoftDeletes === true) { - $builder->where($this->deletedField, 0); + $builder->where($this->table . '.' . $this->deletedField, 0); } // Some databases, like PostgreSQL, need order @@ -484,14 +520,6 @@ */ public function save($data): bool { - // If $data is using a custom class with public or protected - // properties representing the table elements, we need to grab - // them as an array. - if (is_object($data) && ! $data instanceof \stdClass) - { - $data = static::classToArray($data, $this->primaryKey, $this->dateFormat); - } - if (empty($data)) { return true; @@ -525,15 +553,16 @@ * @param string|object $data * @param string|null $primaryKey * @param string $dateFormat + * @param boolean $onlyChanged * * @return array * @throws \ReflectionException */ - public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime'): array + public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime', bool $onlyChanged = true): array { if (method_exists($data, 'toRawArray')) { - $properties = $data->toRawArray(true); + $properties = $data->toRawArray($onlyChanged); // Always grab the primary key otherwise updates will fail. if (! empty($properties) && ! empty($primaryKey) && ! in_array($primaryKey, $properties)) @@ -543,8 +572,8 @@ } else { - $mirror = new \ReflectionClass($data); - $props = $mirror->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED); + $mirror = new ReflectionClass($data); + $props = $mirror->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); $properties = []; @@ -626,12 +655,17 @@ $this->tempData = []; } + if (empty($data)) + { + throw DataException::forEmptyDataset('insert'); + } + // If $data is using a custom class with public or protected // properties representing the table elements, we need to grab // them as an array. - if (is_object($data) && ! $data instanceof \stdClass) + if (is_object($data) && ! $data instanceof stdClass) { - $data = static::classToArray($data, $this->primaryKey, $this->dateFormat); + $data = static::classToArray($data, $this->primaryKey, $this->dateFormat, false); } // If it's still a stdClass, go ahead and convert to @@ -675,11 +709,6 @@ $data = $this->trigger('beforeInsert', ['data' => $data]); - if (empty($data)) - { - throw DataException::forEmptyDataset('insert'); - } - // Must use the set() method to ensure objects get converted to arrays $result = $this->builder() ->set($data['data'], '', $escape) @@ -744,7 +773,7 @@ { $escape = null; - if (is_numeric($id)) + if (is_numeric($id) || is_string($id)) { $id = [$id]; } @@ -756,10 +785,15 @@ $this->tempData = []; } + if (empty($data)) + { + throw DataException::forEmptyDataset('update'); + } + // If $data is using a custom class with public or protected // properties representing the table elements, we need to grab // them as an array. - if (is_object($data) && ! $data instanceof \stdClass) + if (is_object($data) && ! $data instanceof stdClass) { $data = static::classToArray($data, $this->primaryKey, $this->dateFormat); } @@ -797,11 +831,6 @@ $data = $this->trigger('beforeUpdate', ['id' => $id, 'data' => $data]); - if (empty($data)) - { - throw DataException::forEmptyDataset('update'); - } - $builder = $this->builder(); if ($id) @@ -963,9 +992,9 @@ * @param null $data * @param boolean $returnSQL * - * @return boolean TRUE on success, FALSE on failure + * @return mixed */ - public function replace($data = null, bool $returnSQL = false): bool + public function replace($data = null, bool $returnSQL = false) { // Validate data before saving. if (! empty($data) && $this->skipValidation === false) @@ -1026,7 +1055,7 @@ * * @throws \CodeIgniter\Database\Exceptions\DataException */ - public function chunk(int $size, \Closure $userFunc) + public function chunk(int $size, Closure $userFunc) { $total = $this->builder() ->countAllResults(false); @@ -1324,7 +1353,7 @@ * Validate the data against the validation rules (or the validation group) * specified in the class property, $validationRules. * - * @param array $data + * @param array|object $data * * @return boolean */ diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index 2af6ac7..b61fdc8 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -92,6 +92,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $config + * @param RendererInterface $view + */ public function __construct($config, RendererInterface $view) { $this->config = $config; @@ -166,7 +172,7 @@ * * @return string */ - protected function displayLinks(string $group, string $template) + protected function displayLinks(string $group, string $template): string { $pager = new PagerRenderer($this->getDetails($group)); @@ -191,7 +197,7 @@ * @param integer $total * @param integer $segment * - * @return mixed + * @return $this */ public function store(string $group, int $page, int $perPage, int $total, int $segment = 0) { @@ -212,8 +218,8 @@ /** * Sets the path that an aliased group of links will use. * - * @param string $group * @param string $path + * @param string $group * * @return mixed */ @@ -304,7 +310,7 @@ * * @return integer */ - public function getFirstPage(string $group = 'default') + public function getFirstPage(string $group = 'default'): int { $this->ensureGroup($group); @@ -323,7 +329,7 @@ * * @return string|\CodeIgniter\HTTP\URI */ - public function getPageURI(int $page = null, string $group = 'default', $returnObject = false) + public function getPageURI(int $page = null, string $group = 'default', bool $returnObject = false) { $this->ensureGroup($group); @@ -368,7 +374,7 @@ * * @return string|null */ - public function getNextPageURI(string $group = 'default', $returnObject = false) + public function getNextPageURI(string $group = 'default', bool $returnObject = false) { $this->ensureGroup($group); @@ -399,7 +405,7 @@ * * @return string|null */ - public function getPreviousPageURI(string $group = 'default', $returnObject = false) + public function getPreviousPageURI(string $group = 'default', bool $returnObject = false) { $this->ensureGroup($group); diff --git a/system/Pager/PagerInterface.php b/system/Pager/PagerInterface.php index 933400e..c42ffc4 100644 --- a/system/Pager/PagerInterface.php +++ b/system/Pager/PagerInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -101,8 +101,8 @@ /** * Sets the path that an aliased group of links will use. * - * @param string $group * @param string $path + * @param string $group * * @return mixed */ @@ -141,7 +141,7 @@ * * @return string|\CodeIgniter\HTTP\URI */ - public function getPageURI(int $page = null, string $group = 'default', $returnObject = false); + public function getPageURI(int $page = null, string $group = 'default', bool $returnObject = false); //-------------------------------------------------------------------- diff --git a/system/Pager/PagerRenderer.php b/system/Pager/PagerRenderer.php index fc85358..a532c36 100644 --- a/system/Pager/PagerRenderer.php +++ b/system/Pager/PagerRenderer.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -50,16 +50,56 @@ class PagerRenderer { + /** + * First page number. + * + * @var integer + */ protected $first; + /** + * Last page number. + * + * @var integer + */ protected $last; + /** + * Current page number. + * + * @var integer + */ protected $current; + /** + * Total number of pages? unused? + * + * @var integer + */ protected $total; + /** + * Page count? + * + * @var integer + */ protected $pageCount; + /** + * URI? unused? + * + * @var integer + */ protected $uri; + /** + * Segment number used for pagination. + * + * @var integer + */ protected $segment; //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param array $details + */ public function __construct(array $details) { $this->first = 1; diff --git a/system/Router/Exceptions/RedirectException.php b/system/Router/Exceptions/RedirectException.php new file mode 100644 index 0000000..151e730 --- /dev/null +++ b/system/Router/Exceptions/RedirectException.php @@ -0,0 +1,14 @@ +group; $oldOptions = $this->currentOptions; @@ -1432,4 +1436,18 @@ } //-------------------------------------------------------------------- + + /** + * Reset the routes, so that a FeatureTestCase can provide the + * explicit ones needed for it. + */ + public function resetRoutes() + { + $this->routes = ['*' => []]; + foreach ($this->defaultHTTPMethods as $verb) + { + $this->routes[$verb] = []; + } + } + } diff --git a/system/Router/RouteCollectionInterface.php b/system/Router/RouteCollectionInterface.php index b61ffcf..78ef1c7 100644 --- a/system/Router/RouteCollectionInterface.php +++ b/system/Router/RouteCollectionInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Router/Router.php b/system/Router/Router.php index f8dcbc0..31da9ee 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -32,24 +32,17 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Router; use CodeIgniter\Exceptions\PageNotFoundException; +use CodeIgniter\Router\Exceptions\RedirectException; use CodeIgniter\Router\Exceptions\RouterException; /** - * Routing exception - */ -class RedirectException extends \Exception -{ - -} - -/** * Request router. */ class Router implements RouterInterface @@ -154,15 +147,11 @@ //-------------------------------------------------------------------- /** - * Scans the URI and attempts to match the current URI to the - * one of the defined routes in the RouteCollection. + * @param string|null $uri * - * This is the main entry point when using the Router. - * - * @param string $uri - * - * @return mixed - * @throws \CodeIgniter\Router\RedirectException + * @return mixed|string + * @throws \CodeIgniter\Router\Exceptions\RedirectException + * @throws \CodeIgniter\Exceptions\PageNotFoundException */ public function handle(string $uri = null) { @@ -394,7 +383,7 @@ * @param string $uri The URI path to compare against the routes * * @return boolean Whether the route was matched or not. - * @throws \CodeIgniter\Router\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException */ protected function checkRoutes(string $uri): bool { @@ -491,7 +480,7 @@ // Is this route supposed to redirect to another? if ($this->collection->isRedirect($key)) { - throw new RedirectException($val, $this->collection->getRedirectCode($key)); + throw RedirectException::forUnableToRedirect($val, $this->collection->getRedirectCode($key)); } $this->setRequest(explode('/', $val)); @@ -573,9 +562,10 @@ * * @return array URI segments */ - protected function validateRequest(array $segments) + protected function validateRequest(array $segments): array { $segments = array_filter($segments); + $segments = array_values($segments); $c = count($segments); $directory_override = isset($this->directory); @@ -608,7 +598,7 @@ * @param string|null $dir * @param boolean|false $append */ - protected function setDirectory(string $dir = null, $append = false) + protected function setDirectory(string $dir = null, bool $append = false) { $dir = ucfirst($dir); diff --git a/system/Router/RouterInterface.php b/system/Router/RouterInterface.php index 67d2827..1823487 100644 --- a/system/Router/RouterInterface.php +++ b/system/Router/RouterInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Security/Security.php b/system/Security/Security.php index e9250a8..43dc3db 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -163,6 +163,8 @@ * setup initial state. * * @param \Config\App $config + * + * @throws \Exception */ public function __construct($config) { @@ -192,9 +194,10 @@ /** * CSRF Verify * - * @param RequestInterface $request + * @param RequestInterface $request + * * @return $this|false - * @throws \LogicException + * @throws \Exception */ public function CSRFVerify(RequestInterface $request) { @@ -330,7 +333,7 @@ * * @return string */ - public function sanitizeFilename($str, $relative_path = false) + public function sanitizeFilename(string $str, bool $relative_path = false): string { $bad = $this->filenameBadChars; diff --git a/system/Session/Handlers/BaseHandler.php b/system/Session/Handlers/BaseHandler.php index 5f15462..ee3e1ca 100644 --- a/system/Session/Handlers/BaseHandler.php +++ b/system/Session/Handlers/BaseHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -116,11 +116,13 @@ * The 'save path' for the session * varies between * - * @var mixed + * @var string */ protected $savePath; /** + * User's IP address. + * * @var string */ protected $ipAddress; @@ -131,6 +133,7 @@ * Constructor * * @param BaseConfig $config + * @param string $ipAddress */ public function __construct($config, string $ipAddress) { diff --git a/system/Session/Handlers/DatabaseHandler.php b/system/Session/Handlers/DatabaseHandler.php index 2acdb16..a20e2ec 100644 --- a/system/Session/Handlers/DatabaseHandler.php +++ b/system/Session/Handlers/DatabaseHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -90,6 +90,7 @@ * Constructor * * @param BaseConfig $config + * @param string $ipAddress */ public function __construct(BaseConfig $config, string $ipAddress) { @@ -352,6 +353,12 @@ //-------------------------------------------------------------------- + /** + * Lock the session. + * + * @param string $sessionID + * @return boolean + */ protected function lockSession(string $sessionID): bool { if ($this->platform === 'mysql') diff --git a/system/Session/Handlers/FileHandler.php b/system/Session/Handlers/FileHandler.php index ac9bd10..dd5ffac 100644 --- a/system/Session/Handlers/FileHandler.php +++ b/system/Session/Handlers/FileHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -76,21 +76,19 @@ protected $fileNew; /** + * Whether IP addresses should be matched. + * * @var boolean */ protected $matchIP = false; - /** - * @var string - */ - protected $sessionIDRegex; - //-------------------------------------------------------------------- /** * Constructor * * @param BaseConfig $config + * @param string $ipAddress */ public function __construct($config, string $ipAddress) { diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index 7523460..45f59cf 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -80,6 +80,7 @@ * Constructor * * @param BaseConfig $config + * @param string $ipAddress * @throws \CodeIgniter\Session\Exceptions\SessionException */ public function __construct(BaseConfig $config, string $ipAddress) diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php index 1d50ba8..9368699 100644 --- a/system/Session/Handlers/RedisHandler.php +++ b/system/Session/Handlers/RedisHandler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -88,6 +88,7 @@ * Constructor * * @param BaseConfig $config + * @param string $ipAddress * * @throws \Exception */ @@ -137,7 +138,7 @@ * @param string $name Session cookie name, unused * @return boolean */ - public function open($save_path, $name) + public function open($save_path, $name): bool { if (empty($this->savePath)) { @@ -176,9 +177,9 @@ * * @param string $sessionID Session ID * - * @return string Serialized session data + * @return string|false Serialized session data */ - public function read($sessionID) + public function read($sessionID): string { if (isset($this->redis) && $this->lockSession($sessionID)) { @@ -189,10 +190,11 @@ is_string($session_data) ? $this->keyExists = true : $session_data = ''; $this->fingerprint = md5($session_data); + return $session_data; } - return false; + return ''; } //-------------------------------------------------------------------- @@ -207,7 +209,7 @@ * * @return boolean */ - public function write($sessionID, $sessionData) + public function write($sessionID, $sessionData): bool { if (! isset($this->redis)) { @@ -256,7 +258,7 @@ * * @return boolean */ - public function close() + public function close(): bool { if (isset($this->redis)) { @@ -296,7 +298,7 @@ * * @return boolean */ - public function destroy($sessionID) + public function destroy($sessionID): bool { if (isset($this->redis, $this->lockKey)) { @@ -321,7 +323,7 @@ * @param integer $maxlifetime Maximum lifetime of sessions * @return boolean */ - public function gc($maxlifetime) + public function gc($maxlifetime): bool { // Not necessary, Redis takes care of that. return true; diff --git a/system/Session/Session.php b/system/Session/Session.php index 10d3f28..08b3c05 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -143,10 +143,16 @@ * @var boolean */ protected $cookieSecure = false; + + /** + * sid regex expression + * + * @var string + */ protected $sidRegexp; /** - * Logger instance to record error messages and awarnings. + * Logger instance to record error messages and warnings. * * @var \PSR\Log\LoggerInterface */ @@ -185,6 +191,8 @@ /** * Initialize the session container and starts up the session. + * + * @return mixed */ public function start() { @@ -527,7 +535,7 @@ * * @return boolean */ - public function has(string $key) + public function has(string $key): bool { return isset($_SESSION[$key]); } @@ -582,10 +590,10 @@ * Magic method to set variables in the session by simply calling * $session->foo = bar; * - * @param string $key Identifier of the session property to set. - * @param $value + * @param string $key Identifier of the session property to set. + * @param string|array $value */ - public function __set($key, $value) + public function __set(string $key, $value) { $_SESSION[$key] = $value; } @@ -600,7 +608,7 @@ * * @return null|string */ - public function __get($key) + public function __get(string $key) { // Note: Keep this order the same, just in case somebody wants to // use 'session_id' as a session data key, for whatever reason @@ -675,9 +683,9 @@ /** * Keeps a single piece of flash data alive for one more request. * - * @param string $key Property identifier or array of them + * @param array|string $key Property identifier or array of them */ - public function keepFlashdata(string $key) + public function keepFlashdata($key) { $this->markAsFlashdata($key); } @@ -691,7 +699,7 @@ * * @return boolean False if any of the properties are not already set */ - public function markAsFlashdata($key) + public function markAsFlashdata($key): bool { if (is_array($key)) { @@ -757,7 +765,7 @@ * * @return array The property names of all flashdata */ - public function getFlashKeys() + public function getFlashKeys(): array { if (! isset($_SESSION['__ci_vars'])) { @@ -786,7 +794,7 @@ * @param null $value Value to store * @param integer $ttl Time-to-live in seconds */ - public function setTempdata($data, $value = null, $ttl = 300) + public function setTempdata($data, $value = null, int $ttl = 300) { $this->set($data, $value); $this->markAsTempdata($data, $ttl); @@ -798,10 +806,10 @@ * Returns either a single piece of tempdata, or all temp data currently * in the session. * - * @param $key Session data key - * @return mixed Session data value or null if not found. + * @param string $key Session data key + * @return mixed Session data value or null if not found. */ - public function getTempdata($key = null) + public function getTempdata(string $key = null) { if (isset($key)) { @@ -829,7 +837,7 @@ * * @param string $key Session data key */ - public function removeTempdata($key) + public function removeTempdata(string $key) { $this->unmarkTempdata($key); unset($_SESSION[$key]); @@ -846,7 +854,7 @@ * * @return boolean False if any of the properties were not set */ - public function markAsTempdata($key, $ttl = 300) + public function markAsTempdata($key, int $ttl = 300): bool { $ttl += time(); @@ -932,7 +940,7 @@ * * @return array */ - public function getTempKeys() + public function getTempKeys(): array { if (! isset($_SESSION['__ci_vars'])) { diff --git a/system/Session/SessionInterface.php b/system/Session/SessionInterface.php index 498a586..4fcb3bd 100644 --- a/system/Session/SessionInterface.php +++ b/system/Session/SessionInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -100,7 +100,7 @@ * * @return boolean */ - public function has(string $key); + public function has(string $key): bool; //-------------------------------------------------------------------- @@ -127,7 +127,7 @@ * flashdata property, with $value containing the property value. * * @param string|array $data Property identifier or associative array of properties - * @param null $value Property value if $data is a scalar + * @param string|array $value Property value if $data is a scalar */ public function setFlashdata($data, $value = null); @@ -149,9 +149,9 @@ /** * Keeps a single piece of flash data alive for one more request. * - * @param string $key Property identifier or array of them + * @param array|string $key Property identifier or array of them */ - public function keepFlashdata(string $key); + public function keepFlashdata($key); //-------------------------------------------------------------------- @@ -180,7 +180,7 @@ * * @return array The property names of all flashdata */ - public function getFlashKeys(); + public function getFlashKeys(): array; //-------------------------------------------------------------------- @@ -192,7 +192,7 @@ * @param mixed $value Value to store * @param integer $ttl Time-to-live in seconds */ - public function setTempdata($data, $value = null, $ttl = 300); + public function setTempdata($data, $value = null, int $ttl = 300); //-------------------------------------------------------------------- @@ -203,7 +203,7 @@ * @param string $key Session data key * @return mixed Session data value or null if not found. */ - public function getTempdata($key = null); + public function getTempdata(string $key = null); //-------------------------------------------------------------------- @@ -212,7 +212,7 @@ * * @param string $key Session data key */ - public function removeTempdata($key); + public function removeTempdata(string $key); //-------------------------------------------------------------------- @@ -225,7 +225,7 @@ * * @return boolean False if any of the properties were not set */ - public function markAsTempdata($key, $ttl = 300); + public function markAsTempdata($key, int $ttl = 300); //-------------------------------------------------------------------- @@ -244,7 +244,7 @@ * * @return array */ - public function getTempKeys(); + public function getTempKeys(): array; //-------------------------------------------------------------------- } diff --git a/system/Test/CIDatabaseTestCase.php b/system/Test/CIDatabaseTestCase.php index 544e71a..aadab37 100644 --- a/system/Test/CIDatabaseTestCase.php +++ b/system/Test/CIDatabaseTestCase.php @@ -31,12 +31,14 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\Test; +use Config\Database; +use Config\Migrations; use Config\Services; use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\MigrationRunner; @@ -119,18 +121,21 @@ //-------------------------------------------------------------------- + /** + * Load any database test dependencies. + */ public function loadDependencies() { if ($this->db === null) { - $this->db = \Config\Database::connect($this->DBGroup); + $this->db = Database::connect($this->DBGroup); $this->db->initialize(); } if ($this->migrations === null) { // Ensure that we can run migrations - $config = new \Config\Migrations(); + $config = new Migrations(); $config->enabled = true; $this->migrations = Services::migrations($config, $this->db); @@ -139,7 +144,7 @@ if ($this->seeder === null) { - $this->seeder = \Config\Database::seeder($this->DBGroup); + $this->seeder = Database::seeder($this->DBGroup); $this->seeder->setSilent(true); } } @@ -170,7 +175,7 @@ if (is_array($tables)) { - $forge = \Config\Database::forge('tests'); + $forge = Database::forge('tests'); foreach ($tables as $table) { diff --git a/system/Test/CIUnitTestCase.php b/system/Test/CIUnitTestCase.php index 5096084..f2a583e 100644 --- a/system/Test/CIUnitTestCase.php +++ b/system/Test/CIUnitTestCase.php @@ -1,6 +1,5 @@ dom = new DOMParser(); @@ -77,6 +88,8 @@ //-------------------------------------------------------------------- /** + * Set the body & DOM. + * * @param string $body * * @return $this @@ -94,6 +107,8 @@ } /** + * Retrieve the body. + * * @return string */ public function getBody() @@ -102,6 +117,8 @@ } /** + * Set the request. + * * @param \CodeIgniter\HTTP\RequestInterface $request * * @return $this @@ -114,6 +131,8 @@ } /** + * Set the response. + * * @param \CodeIgniter\HTTP\ResponseInterface $response * * @return $this @@ -128,6 +147,8 @@ } /** + * Request accessor. + * * @return \CodeIgniter\HTTP\IncomingRequest */ public function request() @@ -136,6 +157,8 @@ } /** + * Response accessor. + * * @return \CodeIgniter\HTTP\Response */ public function response() diff --git a/system/Test/ControllerTester.php b/system/Test/ControllerTester.php index f132973..2523a41 100644 --- a/system/Test/ControllerTester.php +++ b/system/Test/ControllerTester.php @@ -33,7 +33,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -45,6 +45,8 @@ use CodeIgniter\HTTP\URI; use Config\App; use Config\Services; +use InvalidArgumentException; +use Throwable; /** * ControllerTester Trait @@ -63,12 +65,48 @@ trait ControllerTester { + /** + * Controller configuration. + * + * @var BaseConfig + */ protected $appConfig; + + /** + * Request. + * + * @var Request + */ protected $request; + /** + * Response. + * + * @var Response + */ protected $response; + /** + * Message logger. + * + * @var LoggerInterface + */ protected $logger; + /** + * Initialized controller. + * + * @var Controller + */ protected $controller; + /** + * URI of this request. + * + * @var string + */ protected $uri = 'http://example.com'; + /** + * Request or response body. + * + * @var string + */ protected $body; /** @@ -82,7 +120,7 @@ { if (! class_exists($name)) { - throw new \InvalidArgumentException('Invalid Controller: ' . $name); + throw new InvalidArgumentException('Invalid Controller: ' . $name); } if (empty($this->appConfig)) @@ -123,7 +161,7 @@ { if (! method_exists($this->controller, $method) || ! is_callable([$this->controller, $method])) { - throw new \InvalidArgumentException('Method does not exist or is not callable in controller: ' . $method); + throw new InvalidArgumentException('Method does not exist or is not callable in controller: ' . $method); } // The URL helper is always loaded by the system @@ -141,7 +179,7 @@ $response = $this->controller->{$method}(...$params); } - catch (\Throwable $e) + catch (Throwable $e) { $result->response() ->setStatusCode($e->getCode()); @@ -183,6 +221,8 @@ } /** + * Set controller's config, with method chaining. + * * @param mixed $appConfig * * @return mixed @@ -195,6 +235,8 @@ } /** + * Set controller's request, with method chaining. + * * @param mixed $request * * @return mixed @@ -207,6 +249,8 @@ } /** + * Set controller's response, with method chaining. + * * @param mixed $response * * @return mixed @@ -219,6 +263,8 @@ } /** + * Set controller's logger, with method chaining. + * * @param mixed $logger * * @return mixed @@ -231,6 +277,8 @@ } /** + * Set the controller's URI, with method chaining. + * * @param string $uri * * @return mixed @@ -243,6 +291,8 @@ } /** + * Set the method's body, with method chaining. + * * @param mixed $body * * @return mixed diff --git a/system/Test/DOMParser.php b/system/Test/DOMParser.php index 09befc8..804178d 100644 --- a/system/Test/DOMParser.php +++ b/system/Test/DOMParser.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -44,10 +44,17 @@ class DOMParser { /** + * DOM for the body, + * * @var \DOMDocument */ protected $dom; + /** + * Constructor. + * + * @throws \BadMethodCallException + */ public function __construct() { if (! extension_loaded('DOM')) @@ -125,6 +132,7 @@ * Checks to see if the text is found within the result. * * @param string $search + * @param string $element * * @return boolean */ @@ -227,6 +235,14 @@ } //-------------------------------------------------------------------- + /** + * Search the DOM using an XPath expression. + * + * @param string $search + * @param string $element + * @param array $paths + * @return type + */ protected function doXPath(string $search = null, string $element, array $paths = []) { @@ -286,6 +302,12 @@ return $result; } + /** + * Look for the a selector in the passed text. + * + * @param string $selector + * @return type + */ public function parseSelector(string $selector) { $tag = null; diff --git a/system/Test/FeatureResponse.php b/system/Test/FeatureResponse.php index 2b8b75a..b71fcb2 100644 --- a/system/Test/FeatureResponse.php +++ b/system/Test/FeatureResponse.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -39,6 +39,7 @@ use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\Response; +use Config\Format; use PHPUnit\Framework\TestCase; /** @@ -46,23 +47,34 @@ */ class FeatureResponse extends TestCase { + /** + * The response. + * * @var \CodeIgniter\HTTP\Response */ public $response; /** + * DOM for the body. + * * @var \CodeIgniter\Test\DOMParser */ protected $domParser; + /** + * Constructor. + * + * @param Response $response + */ public function __construct(Response $response = null) { $this->response = $response; - if (is_string($this->response->getBody())) + $body = $response->getBody(); + if (! empty($body) && is_string($body)) { - $this->domParser = (new DOMParser())->withString($this->response->getBody()); + $this->domParser = (new DOMParser())->withString($body); } } @@ -123,7 +135,7 @@ */ public function assertStatus(int $code) { - $this->assertEquals($code, (int)$this->response->getStatusCode()); + $this->assertEquals($code, (int) $this->response->getStatusCode()); } /** @@ -226,10 +238,6 @@ * Assert the Response does not have the specified cookie set. * * @param string $key - * @param null $value - * @param string $prefix - * - * @throws \Exception */ public function assertCookieMissing(string $key) { @@ -352,7 +360,7 @@ } /** - * + * Test that the response contains a matching JSON fragment. * * @param array $fragment * @@ -379,7 +387,7 @@ if (is_array($test)) { - $config = new \Config\Format(); + $config = new Format(); $formatter = $config->getFormatter('application/json'); $test = $formatter->format($test); } @@ -400,4 +408,5 @@ { return $this->response->getXML(); } + } diff --git a/system/Test/FeatureTestCase.php b/system/Test/FeatureTestCase.php index 71a67f3..83ddc8e 100644 --- a/system/Test/FeatureTestCase.php +++ b/system/Test/FeatureTestCase.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -55,6 +55,7 @@ */ class FeatureTestCase extends CIDatabaseTestCase { + /** * If present, will override application * routes when using call(). @@ -82,16 +83,22 @@ * Sets a RouteCollection that will override * the application's route collection. * + * Example routes: + * [ + * ['get', 'home', 'Home::index'] + * ] + * * @param array $routes * * @return $this */ protected function withRoutes(array $routes = null) { - $collection = \Config\Services::routes(); + $collection = Services::routes(); if ($routes) { + $collection->resetRoutes(); foreach ($routes as $route) { $collection->{$route[0]}($route[1], $route[2]); @@ -138,7 +145,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function call(string $method, string $path, array $params = null) @@ -149,18 +156,31 @@ $request = $this->setupRequest($method, $path, $params); $request = $this->populateGlobals($method, $request, $params); + // Make sure the RouteCollection knows what method we're using... + if (! empty($this->routes)) + { + $this->routes->setHTTPVerb($method); + } + // Make sure any other classes that might call the request // instance get the right one. Services::injectMock('request', $request); $_SERVER['REQUEST_METHOD'] = $method; $response = $this->app - ->setRequest($request) - ->run($this->routes, true); + ->setRequest($request) + ->run($this->routes, true); + + $output = ob_get_contents(); + if (empty($response->getBody()) && ! empty($output)) + { + $response->setBody($output); + } // Clean up any open output buffers // not relevant to unit testing // @codeCoverageIgnoreStart + if (ob_get_level() > 0 && $this->clean) { ob_end_clean(); @@ -179,7 +199,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function get(string $path, array $params = null) @@ -194,7 +214,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function post(string $path, array $params = null) @@ -209,7 +229,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function put(string $path, array $params = null) @@ -224,7 +244,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function patch(string $path, array $params = null) @@ -239,7 +259,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function delete(string $path, array $params = null) @@ -254,7 +274,7 @@ * @param array|null $params * * @return \CodeIgniter\Test\FeatureResponse - * @throws \CodeIgniter\HTTP\RedirectException + * @throws \CodeIgniter\Router\Exceptions\RedirectException * @throws \Exception */ public function options(string $path, array $params = null) @@ -297,6 +317,7 @@ * @param array|null $params * * @return \CodeIgniter\HTTP\Request + * @throws \ReflectionException */ protected function populateGlobals(string $method, Request $request, array $params = null) { @@ -310,4 +331,5 @@ return $request; } + } diff --git a/system/Test/Filters/CITestStreamFilter.php b/system/Test/Filters/CITestStreamFilter.php index 0508a6b..f2233d2 100644 --- a/system/Test/Filters/CITestStreamFilter.php +++ b/system/Test/Filters/CITestStreamFilter.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -47,8 +47,22 @@ class CITestStreamFilter extends \php_user_filter { + /** + * Buffer to capture stream content. + * + * @var type + */ public static $buffer = ''; + /** + * Output filtering - catch it all. + * + * @param type $in + * @param type $out + * @param type $consumed + * @param type $closing + * @return type + */ public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) diff --git a/system/Test/ReflectionHelper.php b/system/Test/ReflectionHelper.php index b97ad02..d8a314b 100644 --- a/system/Test/ReflectionHelper.php +++ b/system/Test/ReflectionHelper.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -47,13 +47,14 @@ */ trait ReflectionHelper { - /** * Find a private method invoker. * - * @param object|string $obj object or class name - * @param string $method method name + * @param object|string $obj object or class name + * @param string $method method name + * * @return \Closure + * @throws \ReflectionException */ public static function getPrivateMethodInvoker($obj, $method) { @@ -74,6 +75,7 @@ * @param string $property * * @return \ReflectionProperty + * @throws \ReflectionException */ private static function getAccessibleRefProperty($obj, $property) { @@ -98,6 +100,8 @@ * @param object|string $obj object or class name * @param string $property property name * @param mixed $value value + * + * @throws \ReflectionException */ public static function setPrivateProperty($obj, $property, $value) { @@ -108,9 +112,11 @@ /** * Retrieve a private property. * - * @param object|string $obj object or class name - * @param string $property property name + * @param object|string $obj object or class name + * @param string $property property name + * * @return mixed value + * @throws \ReflectionException */ public static function getPrivateProperty($obj, $property) { diff --git a/system/Throttle/Throttler.php b/system/Throttle/Throttler.php index 686bb39..b549a70 100644 --- a/system/Throttle/Throttler.php +++ b/system/Throttle/Throttler.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -58,6 +58,8 @@ { /** + * Container for throttle counters. + * * @var \CodeIgniter\Cache\CacheInterface */ protected $cache; @@ -86,6 +88,12 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param type $cache + * @throws type + */ public function __construct(CacheInterface $cache) { $this->cache = $cache; @@ -191,7 +199,7 @@ //-------------------------------------------------------------------- /** - * + * Return the test time, defaulting to current. * * @return integer */ diff --git a/system/Throttle/ThrottlerInterface.php b/system/Throttle/ThrottlerInterface.php index 6bbbc59..337ee82 100644 --- a/system/Throttle/ThrottlerInterface.php +++ b/system/Throttle/ThrottlerInterface.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -71,5 +71,5 @@ * * @return integer */ - public function getTokenTime(); + public function getTokenTime(): int; } diff --git a/system/Typography/Typography.php b/system/Typography/Typography.php index e473b6a..b835340 100644 --- a/system/Typography/Typography.php +++ b/system/Typography/Typography.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -276,7 +276,7 @@ * to curly entities, but it also converts em-dashes, * double spaces, and ampersands * - * @param string + * @param string $str * @return string */ public function formatCharacters(string $str): string @@ -333,7 +333,7 @@ * * Converts newline characters into either

tags or
* - * @param string + * @param string $str * @return string */ protected function formatNewLines(string $str): string @@ -373,7 +373,7 @@ * and we don't want double dashes converted to emdash entities, so they are marked with {@DD} * likewise double spaces are converted to {@NBS} to prevent entity conversion * - * @param array + * @param array $match * @return string */ protected function protectCharacters(array $match): string @@ -386,7 +386,7 @@ /** * Convert newlines to HTML line breaks except within PRE tags * - * @param string + * @param string $str * @return string */ public function nl2brExceptPre(string $str): string diff --git a/system/Validation/CreditCardRules.php b/system/Validation/CreditCardRules.php index 6ee0ea1..5192bff 100644 --- a/system/Validation/CreditCardRules.php +++ b/system/Validation/CreditCardRules.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/Validation/FileRules.php b/system/Validation/FileRules.php index a5f32fc..18a5f08 100644 --- a/system/Validation/FileRules.php +++ b/system/Validation/FileRules.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -56,6 +56,11 @@ //-------------------------------------------------------------------- + /** + * Constructor. + * + * @param RequestInterface $request + */ public function __construct(RequestInterface $request = null) { if (is_null($request)) diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index 6d55aa9..37fb4d3 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -49,7 +49,7 @@ /** * Alpha * - * @param string + * @param string $str * * @return boolean */ @@ -82,7 +82,7 @@ /** * Alpha-numeric with underscores and dashes * - * @param string + * @param string $str * * @return boolean */ @@ -96,7 +96,7 @@ /** * Alpha-numeric * - * @param string + * @param string $str * * @return boolean */ @@ -110,7 +110,7 @@ /** * Alpha-numeric w/ spaces * - * @param string + * @param string $str * * @return boolean */ @@ -122,9 +122,26 @@ //-------------------------------------------------------------------- /** + * Any type of string + * + * Note: we specifically do NOT type hint $str here so that + * it doesn't convert numbers into strings. + * + * @param string|null $str + * + * @return boolean + */ + public function string($str = null): bool + { + return is_string($str); + } + + //-------------------------------------------------------------------- + + /** * Decimal number * - * @param string + * @param string $str * * @return boolean */ @@ -138,7 +155,7 @@ /** * Integer * - * @param string + * @param string $str * * @return boolean */ @@ -152,7 +169,7 @@ /** * Is a Natural number (0,1,2,3, etc.) * - * @param string + * @param string $str * @return boolean */ public function is_natural(string $str = null): bool @@ -165,7 +182,7 @@ /** * Is a Natural number, but not a zero (1,2,3, etc.) * - * @param string + * @param string $str * @return boolean */ public function is_natural_no_zero(string $str = null): bool @@ -178,7 +195,7 @@ /** * Numeric * - * @param string + * @param string $str * * @return boolean */ @@ -233,7 +250,7 @@ * Tests a string for characters outside of the Base64 alphabet * as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045 * - * @param string + * @param string $str * @return boolean */ public function valid_base64(string $str = null): bool @@ -246,7 +263,7 @@ /** * Valid JSON * - * @param string + * @param string $str * * @return boolean */ @@ -261,7 +278,7 @@ /** * Checks for a correctly formatted email address * - * @param string + * @param string $str * * @return boolean */ @@ -283,7 +300,7 @@ * Example: * valid_emails[one@example.com,two@example.com] * - * @param string + * @param string $str * * @return boolean */ diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index bc37610..74b01e1 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -66,6 +66,21 @@ //-------------------------------------------------------------------- /** + * Equals the static value provided. + * + * @param string $str + * @param string $val + * + * @return boolean + */ + public function equals(string $str = null, string $val): bool + { + return $str === $val; + } + + //-------------------------------------------------------------------- + + /** * Returns true if $str is $val characters long. * $val = "5" (one) | "5,8,12" (multiple values) * @@ -262,6 +277,21 @@ //-------------------------------------------------------------------- /** + * Does not equal the static value provided. + * + * @param string $str + * @param string $val + * + * @return boolean + */ + public function not_equals(string $str = null, string $val): bool + { + return $str !== $val; + } + + //-------------------------------------------------------------------- + + /** * Required * * @param mixed $str Value diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index 3191580..2a8b361 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -95,9 +95,16 @@ protected $customErrors = []; /** + * Our configuration. + * * @var \Config\Validation */ protected $config; + /** + * The view renderer used to render validation messages. + * + * @var RendererInterface + */ protected $view; //-------------------------------------------------------------------- @@ -123,8 +130,9 @@ * Runs the validation process, returning true/false determining whether * validation was successful or not. * - * @param array $data The array of data to validate. - * @param string $group The pre-defined group of rules to apply. + * @param array $data The array of data to validate. + * @param string $group The pre-defined group of rules to apply. + * @param string $db_group The database group to use. * * @return boolean */ @@ -739,7 +747,7 @@ * Resets the class to a blank slate. Should be called whenever * you need to process more than one array. * - * @return mixed + * @return \CodeIgniter\Validation\ValidationInterface */ public function reset(): ValidationInterface { diff --git a/system/Validation/ValidationInterface.php b/system/Validation/ValidationInterface.php index 9da71b2..71620de 100644 --- a/system/Validation/ValidationInterface.php +++ b/system/Validation/ValidationInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -157,7 +157,7 @@ * Resets the class to a blank slate. Should be called whenever * you need to process more than one array. * - * @return mixed + * @return \CodeIgniter\Validation\ValidationInterface */ public function reset(): ValidationInterface; diff --git a/system/View/Cell.php b/system/View/Cell.php index 9ce4907..c819dfe 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -31,7 +31,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -39,6 +39,7 @@ use CodeIgniter\Cache\CacheInterface; use CodeIgniter\View\Exceptions\ViewException; +use ReflectionMethod; /** * Class Cell @@ -92,12 +93,15 @@ //-------------------------------------------------------------------- /** + * Render a cell, returning its body as a string. + * * @param string $library * @param null $params * @param integer $ttl * @param string|null $cacheName * * @return string + * @throws \ReflectionException */ public function render(string $library, $params = null, int $ttl = 0, string $cacheName = null): string { @@ -122,7 +126,7 @@ // Try to match up the parameter list we were provided // with the parameter name in the callback method. $paramArray = $this->prepareParams($params); - $refMethod = new \ReflectionMethod($instance, $method); + $refMethod = new ReflectionMethod($instance, $method); $paramCount = $refMethod->getNumberOfParameters(); $refParams = $refMethod->getParameters(); @@ -237,7 +241,7 @@ * * @return array */ - protected function determineClass(string $library) + protected function determineClass(string $library): array { // We don't want to actually call static methods // by default, so convert any double colons. diff --git a/system/View/Filters.php b/system/View/Filters.php index a4ca6dd..c82b585 100644 --- a/system/View/Filters.php +++ b/system/View/Filters.php @@ -32,12 +32,15 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ namespace CodeIgniter\View; +use Config\Services; +use NumberFormatter; + /** * View filters */ @@ -183,7 +186,7 @@ //-------------------------------------------------------------------- /** - * Limits the number of chracters to $limit, and trails of with an ellipsis. + * Limits the number of characters to $limit, and trails of with an ellipsis. * Will break at word break so may be more or less than $limit. * * @param $value @@ -232,13 +235,13 @@ helper('number'); $types = [ - 'decimal' => \NumberFormatter::DECIMAL, - 'currency' => \NumberFormatter::CURRENCY, - 'percent' => \NumberFormatter::PERCENT, - 'scientific' => \NumberFormatter::SCIENTIFIC, - 'spellout' => \NumberFormatter::SPELLOUT, - 'ordinal' => \NumberFormatter::ORDINAL, - 'duration' => \NumberFormatter::DURATION, + 'decimal' => NumberFormatter::DECIMAL, + 'currency' => NumberFormatter::CURRENCY, + 'percent' => NumberFormatter::PERCENT, + 'scientific' => NumberFormatter::SCIENTIFIC, + 'spellout' => NumberFormatter::SPELLOUT, + 'ordinal' => NumberFormatter::ORDINAL, + 'duration' => NumberFormatter::DURATION, ]; return format_number($value, $precision, $locale, ['type' => $types[$type]]); @@ -260,7 +263,7 @@ helper('number'); $options = [ - 'type' => \NumberFormatter::CURRENCY, + 'type' => NumberFormatter::CURRENCY, 'currency' => $currency, ]; @@ -277,7 +280,7 @@ */ public static function nl2br(string $value): string { - $typography = \Config\Services::typography(); + $typography = Services::typography(); return $typography->nl2brExceptPre($value); } @@ -294,7 +297,7 @@ */ public static function prose(string $value): string { - $typography = \Config\Services::typography(); + $typography = Services::typography(); return $typography->autoTypography($value); } @@ -308,13 +311,13 @@ * - ceil always rounds up * - floor always rounds down * - * @param string $value - * @param integer $precision - * @param string $type + * @param string $value + * @param mixed $precision + * @param string $type * * @return string */ - public static function round($value, $precision = 2, $type = 'common'): string + public static function round(string $value, $precision = 2, string $type = 'common'): string { if (! is_numeric($precision)) { diff --git a/system/View/Parser.php b/system/View/Parser.php index e5a368c..b4a5f60 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/View/Plugins.php b/system/View/Plugins.php index 3b9fe97..9041e22 100644 --- a/system/View/Plugins.php +++ b/system/View/Plugins.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ @@ -45,6 +45,8 @@ { /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string|\CodeIgniter\HTTP\URI @@ -57,6 +59,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return \CodeIgniter\HTTP\URI|mixed|string @@ -69,6 +73,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string @@ -85,6 +91,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string @@ -101,6 +109,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string @@ -115,6 +125,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string @@ -133,6 +145,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string|false @@ -145,6 +159,8 @@ //-------------------------------------------------------------------- /** + * Wrap helper function to use as view plugin. + * * @param array $params * * @return string diff --git a/system/View/RendererInterface.php b/system/View/RendererInterface.php index d8bd763..ee70112 100644 --- a/system/View/RendererInterface.php +++ b/system/View/RendererInterface.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/View/Table.php b/system/View/Table.php new file mode 100644 index 0000000..1923a60 --- /dev/null +++ b/system/View/Table.php @@ -0,0 +1,582 @@ + $val) + { + $this->template[$key] = $val; + } + } + + // -------------------------------------------------------------------- + + /** + * Set the template + * + * @param array $template + * @return boolean + */ + public function setTemplate($template) + { + if (! is_array($template)) + { + return false; + } + + $this->template = $template; + return true; + } + + // -------------------------------------------------------------------- + + /** + * Set the table heading + * + * Can be passed as an array or discreet params + * + * @param mixed + * @return Table + */ + public function setHeading($args = []) + { + $this->heading = $this->_prepArgs(func_get_args()); + return $this; + } + + /** + * Set the table footing + * + * Can be passed as an array or discreet params + * + * @param mixed + * @return Table + */ + public function setFooting($args = []) + { + $this->footing = $this->_prepArgs(func_get_args()); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set columns. Takes a one-dimensional array as input and creates + * a multi-dimensional array with a depth equal to the number of + * columns. This allows a single array with many elements to be + * displayed in a table that has a fixed column count. + * + * @param array $array + * @param integer $columnLimit + * @return array + */ + public function makeColumns($array = [], $columnLimit = 0) + { + if (! is_array($array) || count($array) === 0 || ! is_int($columnLimit)) + { + return false; + } + + // Turn off the auto-heading feature since it's doubtful we + // will want headings from a one-dimensional array + $this->autoHeading = false; + + if ($columnLimit === 0) + { + return $array; + } + + $new = []; + do + { + $temp = array_splice($array, 0, $columnLimit); + + if (count($temp) < $columnLimit) + { + for ($i = count($temp); $i < $columnLimit; $i ++) + { + $temp[] = ' '; + } + } + + $new[] = $temp; + } + while (count($array) > 0); + + return $new; + } + + // -------------------------------------------------------------------- + + /** + * Set "empty" cells + * + * Can be passed as an array or discreet params + * + * @param mixed $value + * @return Table + */ + public function setEmpty($value) + { + $this->emptyCells = $value; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Add a table row + * + * Can be passed as an array or discreet params + * + * @param mixed + * @return Table + */ + public function addRow($args = []) + { + $this->rows[] = $this->_prepArgs(func_get_args()); + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Prep Args + * + * Ensures a standard associative array format for all cell data + * + * @param array + * @return array + */ + protected function _prepArgs($args) + { + // If there is no $args[0], skip this and treat as an associative array + // This can happen if there is only a single key, for example this is passed to table->generate + // array(array('foo'=>'bar')) + if (isset($args[0]) && count($args) === 1 && is_array($args[0]) && ! isset($args[0]['data'])) + { + $args = $args[0]; + } + + foreach ($args as $key => $val) + { + is_array($val) || $args[$key] = ['data' => $val]; + } + + return $args; + } + + // -------------------------------------------------------------------- + + /** + * Add a table caption + * + * @param string $caption + * @return Table + */ + public function setCaption($caption) + { + $this->caption = $caption; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Generate the table + * + * @param mixed $tableData + * @return string + */ + public function generate($tableData = null) + { + // The table data can optionally be passed to this function + // either as a database result object or an array + if (! empty($tableData)) + { + if ($tableData instanceof BaseResult) + { + $this->_setFromDBResult($tableData); + } + elseif (is_array($tableData)) + { + $this->_setFromArray($tableData); + } + } + + // Is there anything to display? No? Smite them! + if (empty($this->heading) && empty($this->rows)) + { + return 'Undefined table data'; + } + + // Compile and validate the template date + $this->_compileTemplate(); + + // Validate a possibly existing custom cell manipulation function + if (isset($this->function) && ! is_callable($this->function)) + { + $this->function = null; + } + + // Build the table! + + $out = $this->template['table_open'] . $this->newline; + + // Add any caption here + if ($this->caption) + { + $out .= '' . $this->caption . '' . $this->newline; + } + + // Is there a table heading to display? + if (! empty($this->heading)) + { + $out .= $this->template['thead_open'] . $this->newline . $this->template['heading_row_start'] . $this->newline; + + foreach ($this->heading as $heading) + { + $temp = $this->template['heading_cell_start']; + + foreach ($heading as $key => $val) + { + if ($key !== 'data') + { + $temp = str_replace('template['heading_cell_end']; + } + + $out .= $this->template['heading_row_end'] . $this->newline . $this->template['thead_close'] . $this->newline; + } + + // Build the table rows + if (! empty($this->rows)) + { + $out .= $this->template['tbody_open'] . $this->newline; + + $i = 1; + foreach ($this->rows as $row) + { + // We use modulus to alternate the row colors + $name = fmod($i ++, 2) ? '' : 'alt_'; + + $out .= $this->template['row_' . $name . 'start'] . $this->newline; + + foreach ($row as $cell) + { + $temp = $this->template['cell_' . $name . 'start']; + + foreach ($cell as $key => $val) + { + if ($key !== 'data') + { + $temp = str_replace('emptyCells; + } + elseif (isset($this->function)) + { + $out .= call_user_func($this->function, $cell); + } + else + { + $out .= $cell; + } + + $out .= $this->template['cell_' . $name . 'end']; + } + + $out .= $this->template['row_' . $name . 'end'] . $this->newline; + } + } + + // Any table footing to display? + if (! empty($this->footing)) + { + $out .= $this->template['tfoot_open'] . $this->newline . $this->template['footing_row_start'] . $this->newline; + + foreach ($this->footing as $footing) + { + $temp = $this->template['footing_cell_start']; + + foreach ($footing as $key => $val) + { + if ($key !== 'data') + { + $temp = str_replace('template['footing_cell_end']; + } + + $out .= $this->template['footing_row_end'] . $this->newline . $this->template['tfoot_close'] . $this->newline; + } + + $out .= $this->template['tbody_close'] . $this->newline; + + // And finally, close off the table + $out .= $this->template['table_close']; + + // Clear table class properties before generating the table + $this->clear(); + + return $out; + } + + // -------------------------------------------------------------------- + + /** + * Clears the table arrays. Useful if multiple tables are being generated + * + * @return Table + */ + public function clear() + { + $this->rows = []; + $this->heading = []; + $this->footing = []; + $this->autoHeading = true; + $this->caption = null; + return $this; + } + + // -------------------------------------------------------------------- + + /** + * Set table data from a database result object + * + * @param BaseResult $object Database result object + * @return void + */ + protected function _setFromDBResult($object) + { + // First generate the headings from the table column names + if ($this->autoHeading === true && empty($this->heading)) + { + $this->heading = $this->_prepArgs($object->getFieldNames()); + } + + foreach ($object->getResultArray() as $row) + { + $this->rows[] = $this->_prepArgs($row); + } + } + + // -------------------------------------------------------------------- + + /** + * Set table data from an array + * + * @param array $data + * @return void + */ + protected function _setFromArray($data) + { + if ($this->autoHeading === true && empty($this->heading)) + { + $this->heading = $this->_prepArgs(array_shift($data)); + } + + foreach ($data as &$row) + { + $this->rows[] = $this->_prepArgs($row); + } + } + + // -------------------------------------------------------------------- + + /** + * Compile Template + * + * @return void + */ + protected function _compileTemplate() + { + if ($this->template === null) + { + $this->template = $this->_defaultTemplate(); + return; + } + + $this->temp = $this->_defaultTemplate(); + foreach (['table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close'] as $val) + { + if (! isset($this->template[$val])) + { + $this->template[$val] = $this->temp[$val]; + } + } + } + + // -------------------------------------------------------------------- + + /** + * Default Template + * + * @return array + */ + protected function _defaultTemplate() + { + return [ + 'table_open' => '', + 'thead_open' => '', + 'thead_close' => '', + 'heading_row_start' => '', + 'heading_row_end' => '', + 'heading_cell_start' => '', + 'tfoot_open' => '', + 'tfoot_close' => '', + 'footing_row_start' => '', + 'footing_row_end' => '', + 'footing_cell_start' => '', + 'tbody_open' => '', + 'tbody_close' => '', + 'row_start' => '', + 'row_end' => '', + 'cell_start' => '', + 'row_alt_start' => '', + 'row_alt_end' => '', + 'cell_alt_start' => '', + 'table_close' => '
', + 'heading_cell_end' => '
', + 'footing_cell_end' => '
', + 'cell_end' => '
', + 'cell_alt_end' => '
', + ]; + } + + // -------------------------------------------------------------------- +} diff --git a/system/View/View.php b/system/View/View.php index 83bf3e1..2324457 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */ diff --git a/system/bootstrap.php b/system/bootstrap.php index 320deac..780c4b0 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -32,7 +32,7 @@ * @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com - * @since Version 3.0.0 + * @since Version 4.0.0 * @filesource */