diff --git a/README.md b/README.md index 5591856..8ab1360 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # CodeIgniter 4 Framework ## What is CodeIgniter? + CodeIgniter is a PHP full-stack web framework that is light, fast, flexible, and secure. More information can be found at the [official site](http://codeigniter.com). @@ -29,6 +30,7 @@ The user guide updating and deployment is a bit awkward at the moment, but we are working on it! ## Repository Management + We use Github issues 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. @@ -51,12 +53,14 @@ to optional packages, with their own repository. ## Contributing + We welcome contributions from the community. Please read the [*Contributing to CodeIgniter*](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing.md) section in the development repository. ## Server Requirements -PHP version 7.1 or higher is required, with the following extensions installed: + +PHP version 7.2 or higher is required, with the following extensions installed: - [intl](http://php.net/manual/en/intl.requirements.php) - [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index 77e78a0..af0e201 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -36,7 +36,7 @@ * to their location on the file system. These are used by the * Autoloader to locate files the first time they have been instantiated. * - * The '/application' and '/system' directories are already mapped for + * The '/app' and '/system' directories are already mapped for * you. You may change the name of the 'App' namespace if you wish, * but this should be done prior to creating any namespaced classes, * else you will need to modify all of those classes for this to work. diff --git a/app/Config/Email.php b/app/Config/Email.php deleted file mode 100644 index 4566124..0000000 --- a/app/Config/Email.php +++ /dev/null @@ -1,161 +0,0 @@ - \App\Filters\CSRF::class, - 'toolbar' => \App\Filters\DebugToolbar::class, - 'honeypot' => \App\Filters\Honeypot::class, + 'csrf' => \CodeIgniter\Filters\CSRF::class, + 'toolbar' => \CodeIgniter\Filters\DebugToolbar::class, + 'honeypot' => \CodeIgniter\Filters\Honeypot::class, ]; // Always applied before every request diff --git a/app/Config/Modules.php b/app/Config/Modules.php index 2dcd22b..28bbc7d 100644 --- a/app/Config/Modules.php +++ b/app/Config/Modules.php @@ -15,6 +15,16 @@ public $enabled = true; /* + |-------------------------------------------------------------------------- + | Auto-Discovery Within Composer Packages Enabled? + |-------------------------------------------------------------------------- + | + | If true, then auto-discovery will happen across all namespaces loaded + | by Composer, as well as the namespaces configured locally. + */ + public $discoverInComposer = true; + + /* |-------------------------------------------------------------------------- | Auto-discover Rules |-------------------------------------------------------------------------- diff --git a/app/Config/Paths.php b/app/Config/Paths.php index 5ddbdad..5ef168c 100644 --- a/app/Config/Paths.php +++ b/app/Config/Paths.php @@ -2,7 +2,7 @@ /** * Holds the paths that are used by the system to - * locate the main directories, application, system, etc. + * locate the main directories, app, system, etc. * Modifying these allows you to re-structure your application, * share a system folder between multiple applications, and more. * @@ -35,7 +35,7 @@ * * NO TRAILING SLASH! */ - public $appDirectory = __DIR__ . '/../../app'; + public $appDirectory = __DIR__ . '/..'; /* * --------------------------------------------------------------- @@ -45,7 +45,7 @@ * This variable must contain the name of your "writable" directory. * The writable directory allows you to group all directories that * need write permission to a single place that can be tucked away - * for maximum security, keeping it out of the application and/or + * for maximum security, keeping it out of the app and/or * system directories. */ public $writableDirectory = __DIR__ . '/../../writable'; @@ -58,7 +58,7 @@ * This variable must contain the name of your "tests" directory. * The writable directory allows you to group all directories that * need write permission to a single place that can be tucked away - * for maximum security, keeping it out of the application and/or + * for maximum security, keeping it out of the app and/or * system directories. */ public $testsDirectory = __DIR__ . '/../../tests'; @@ -70,8 +70,8 @@ * * This variable must contain the name of the directory that * contains the view files used by your application. By - * default this is in `application/Views`. This value + * default this is in `app/Views`. This value * is used when no value is provided to `Services::renderer()`. */ - public $viewDirectory = __DIR__ . '/../../app/Views'; + public $viewDirectory = __DIR__ . '/../Views'; } diff --git a/app/Config/Services.php b/app/Config/Services.php index 3eab915..79a2afb 100644 --- a/app/Config/Services.php +++ b/app/Config/Services.php @@ -30,20 +30,4 @@ // // return new \CodeIgniter\Example(); // } - - public static function honeypot(BaseConfig $config = null, $getShared = true) - { - if ($getShared) - { - return static::getSharedInstance('honeypot', $config); - } - - if (is_null($config)) - { - $config = new \Config\Honeypot(); - } - - return new \CodeIgniter\Honeypot\Honeypot($config); - } - } diff --git a/app/Config/Toolbar.php b/app/Config/Toolbar.php index fb51f56..8af156e 100644 --- a/app/Config/Toolbar.php +++ b/app/Config/Toolbar.php @@ -26,6 +26,43 @@ \CodeIgniter\Debug\Toolbar\Collectors\Routes::class, \CodeIgniter\Debug\Toolbar\Collectors\Events::class, ]; + + /* + |-------------------------------------------------------------------------- + | Max History + |-------------------------------------------------------------------------- + | The Toolbar allows you to view recent requests that have been made to + | the application while the toolbar is active. This allows you to quickly + | view and compare multiple requests. + | + | $maxHistory sets a limit on the number of past requests that are stored, + | helping to conserve file space used to store them. You can set it to + | 0 (zero) to not have any history stored, or -1 for unlimited history. + | + */ public $maxHistory = 20; - public $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/'; + + /* + |-------------------------------------------------------------------------- + | Toolbar Views Path + |-------------------------------------------------------------------------- + | The full path to the the views that are used by the toolbar. + | MUST have a trailing slash. + | + */ + public $viewsPath = SYSTEMPATH . 'Debug/Toolbar/Views/'; + + /* + |-------------------------------------------------------------------------- + | Max Queries + |-------------------------------------------------------------------------- + | If the Database Collector is enabled, it will log every query that the + | the system generates so they can be displayed on the toolbar's timeline + | and in the query log. This can lead to memory issues in some instances + | with hundreds of queries. + | + | $maxQueries defines the maximum amount of queries that will be stored. + | + */ + public $maxQueries = 100; } diff --git a/app/Filters/CSRF.php b/app/Filters/CSRF.php deleted file mode 100644 index a535555..0000000 --- a/app/Filters/CSRF.php +++ /dev/null @@ -1,64 +0,0 @@ -isCLI()) - { - return; - } - - $security = Services::security(); - - try - { - $security->CSRFVerify($request); - } - catch (SecurityException $e) - { - if (config('App')->CSRFRedirect && ! $request->isAJAX()) - { - return redirect()->back()->with('error', $e->getMessage()); - } - - throw $e; - } - } - - //-------------------------------------------------------------------- - - /** - * We don't have anything to do here. - * - * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request - * @param ResponseInterface|\CodeIgniter\HTTP\Response $response - * - * @return mixed - */ - public function after(RequestInterface $request, ResponseInterface $response) - { - } - - //-------------------------------------------------------------------- -} diff --git a/app/Filters/DebugToolbar.php b/app/Filters/DebugToolbar.php deleted file mode 100644 index 8616bc3..0000000 --- a/app/Filters/DebugToolbar.php +++ /dev/null @@ -1,38 +0,0 @@ -prepare(); - } - - //-------------------------------------------------------------------- -} diff --git a/app/Filters/Honeypot.php b/app/Filters/Honeypot.php deleted file mode 100644 index a16a55c..0000000 --- a/app/Filters/Honeypot.php +++ /dev/null @@ -1,44 +0,0 @@ -hasContent($request)) - { - throw HoneypotException::isBot(); - } - } - - /** - * Attach a honypot to the current response. - * - * @param CodeIgniter\HTTP\RequestInterface $request - * @param CodeIgniter\HTTP\ResponseInterface $response - * @return mixed - */ - public function after(RequestInterface $request, ResponseInterface $response) - { - $honeypot = Services::honeypot(new \Config\Honeypot()); - $honeypot->attachHoneypot($response); - } - -} diff --git a/app/Filters/Throttle.php b/app/Filters/Throttle.php deleted file mode 100644 index b2659e5..0000000 --- a/app/Filters/Throttle.php +++ /dev/null @@ -1,46 +0,0 @@ -check($request->getIPAddress(), 60, MINUTE) === false) - { - return Services::response()->setStatusCode(429); - } - } - - //-------------------------------------------------------------------- - - /** - * We don't have anything to do here. - * - * @param RequestInterface|\CodeIgniter\HTTP\IncomingRequest $request - * @param ResponseInterface|\CodeIgniter\HTTP\Response $response - * - * @return mixed - */ - public function after(RequestInterface $request, ResponseInterface $response) - { - } - - //-------------------------------------------------------------------- -} diff --git a/app/Views/welcome_message.php b/app/Views/welcome_message.php index 0c3281a..2939098 100644 --- a/app/Views/welcome_message.php +++ b/app/Views/welcome_message.php @@ -111,7 +111,7 @@
 				
-					application/Views/welcome_message.php
+					app/Views/welcome_message.php
 				
 				
@@ -119,7 +119,7 @@
 				
-					application/Controllers/Home.php
+					app/Controllers/Home.php
 				
 				
diff --git a/composer.json b/composer.json index 672c5f1..a6844b5 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "homepage": "https://codeigniter.com", "license": "MIT", "require": { - "php": ">=7.1", + "php": ">=7.2", "ext-curl": "*", "ext-intl": "*", "kint-php/kint": "^2.1", diff --git a/contributing.md b/contributing.md index 8e236f0..78593e2 100644 --- a/contributing.md +++ b/contributing.md @@ -35,7 +35,7 @@ ### Compatibility -CodeIgniter4 requires PHP 7.1. +CodeIgniter4 requires PHP 7.2. ### Branching diff --git a/license.txt b/license.txt index b41fa19..6808958 100644 --- a/license.txt +++ b/license.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2018 British Columbia Institute of Technology +Copyright (c) 2014-2019 British Columbia Institute of Technology Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/public/index.php b/public/index.php index cd38b91..5b9e912 100644 --- a/public/index.php +++ b/public/index.php @@ -1,7 +1,7 @@ classmap = $config->classmap; } - unset($config); + // Should we load through Composer's namespaces, also? + if ($moduleConfig->discoverInComposer) + { + $this->discoverComposerNamespaces(); + } return $this; } @@ -303,8 +310,8 @@ /** * Attempts to load the class from common locations in previous - * version of CodeIgniter, namely 'application/libraries', and - * 'application/Models'. + * version of CodeIgniter, namely 'app/Libraries', and + * 'app/Models'. * * @param string $class The class name. This typically should NOT have a namespace. * @@ -391,5 +398,37 @@ return $filename; } + //-------------------------------------------------------------------- + + /** + * Locates all PSR4 compatible namespaces from Composer. + */ + protected function discoverComposerNamespaces() + { + if (! is_file(COMPOSER_PATH)) + { + return false; + } + + $composer = include COMPOSER_PATH; + + $paths = $composer->getPrefixesPsr4(); + unset($composer); + + // Get rid of CodeIgniter so we don't have duplicates + if (isset($paths['CodeIgniter\\'])) + { + unset($paths['CodeIgniter\\']); + } + + // Composer stores paths with trailng slash. We don't. + $newPaths = []; + foreach ($paths as $key => $value) + { + $newPaths[rtrim($key, '\\ ')] = $value; + } + + $this->prefixes = array_merge($this->prefixes, $newPaths); + } } diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 9cc714a..5e59c91 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -119,7 +119,8 @@ { continue; } - $path = $this->getNamespaces($prefix); + $path = $this->getNamespaces($prefix); + $filename = implode('/', $segments); break; } @@ -201,8 +202,8 @@ * $locator->search('Config/Routes.php'); * // Assuming PSR4 namespaces include foo and bar, might return: * [ - * 'application/modules/foo/Config/Routes.php', - * 'application/modules/bar/Config/Routes.php', + * 'app/Modules/foo/Config/Routes.php', + * 'app/Modules/bar/Config/Routes.php', * ] * * @param string $path @@ -268,7 +269,9 @@ { $path = $this->autoloader->getNamespace($prefix); - return isset($path[0]) ? $path[0] : ''; + return isset($path[0]) + ? rtrim($path[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR + : ''; } $namespaces = []; @@ -279,7 +282,7 @@ { $namespaces[] = [ 'prefix' => $prefix, - 'path' => $path, + 'path' => rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR, ]; } } diff --git a/system/CLI/BaseCommand.php b/system/CLI/BaseCommand.php index eceabb4..5b46d7d 100644 --- a/system/CLI/BaseCommand.php +++ b/system/CLI/BaseCommand.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 0f189be..93f24a6 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/CLI/CommandRunner.php b/system/CLI/CommandRunner.php index bca0980..012c037 100644 --- a/system/CLI/CommandRunner.php +++ b/system/CLI/CommandRunner.php @@ -8,7 +8,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,7 +30,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -136,7 +136,11 @@ // If no matching command files were found, bail if (empty($files)) { + // This should never happen in unit testing. + // if it does, we have far bigger problems! + // @codeCoverageIgnoreStart return; + // @codeCoverageIgnoreEnd } // Loop over each file checking to see if a command with that diff --git a/system/CLI/Console.php b/system/CLI/Console.php index 1b7f546..8b596b0 100644 --- a/system/CLI/Console.php +++ b/system/CLI/Console.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/CacheFactory.php b/system/Cache/CacheFactory.php index 9a5563f..b66e9f5 100644 --- a/system/Cache/CacheFactory.php +++ b/system/Cache/CacheFactory.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index 82e1cf6..3e99883 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/Handlers/DummyHandler.php b/system/Cache/Handlers/DummyHandler.php index 282e752..d19563f 100644 --- a/system/Cache/Handlers/DummyHandler.php +++ b/system/Cache/Handlers/DummyHandler.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index 689289d..3e8b5e6 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index 94e5875..704a8a7 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index dd20efb..f1b1c00 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 0498de8..57792e7 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index cbeda5f..3040a51 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 81d4acb..31aa4b8 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -61,7 +61,7 @@ /** * The current version of CodeIgniter Framework */ - const CI_VERSION = '4.0.0-alpha.4'; + const CI_VERSION = '4.0.0-alpha.5'; /** * App startup time. diff --git a/system/Commands/Database/CreateMigration.php b/system/Commands/Database/CreateMigration.php index bc60018..5a3a75b 100644 --- a/system/Commands/Database/CreateMigration.php +++ b/system/Commands/Database/CreateMigration.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Database/MigrateCurrent.php b/system/Commands/Database/MigrateCurrent.php index 7d3f92f..80f5c2e 100644 --- a/system/Commands/Database/MigrateCurrent.php +++ b/system/Commands/Database/MigrateCurrent.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Database/MigrateLatest.php b/system/Commands/Database/MigrateLatest.php index 2a9084e..3954412 100644 --- a/system/Commands/Database/MigrateLatest.php +++ b/system/Commands/Database/MigrateLatest.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Database/MigrateRefresh.php b/system/Commands/Database/MigrateRefresh.php index d6ab6c8..bff24ad 100644 --- a/system/Commands/Database/MigrateRefresh.php +++ b/system/Commands/Database/MigrateRefresh.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Database/MigrateRollback.php b/system/Commands/Database/MigrateRollback.php index 4d242a7..10475f5 100644 --- a/system/Commands/Database/MigrateRollback.php +++ b/system/Commands/Database/MigrateRollback.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -117,7 +117,7 @@ } try { - if (! $this->isAllNamespace()) + if (! $this->isAllNamespace($params)) { $namespace = $params['-n'] ?? CLI::getOption('n'); $runner->version(0, $namespace); diff --git a/system/Commands/Database/MigrateStatus.php b/system/Commands/Database/MigrateStatus.php index a4199de..b973b3f 100644 --- a/system/Commands/Database/MigrateStatus.php +++ b/system/Commands/Database/MigrateStatus.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Database/MigrateVersion.php b/system/Commands/Database/MigrateVersion.php index 5b4d67f..fd5bb21 100644 --- a/system/Commands/Database/MigrateVersion.php +++ b/system/Commands/Database/MigrateVersion.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Database/Seed.php b/system/Commands/Database/Seed.php index 6e8d16f..45e3be5 100644 --- a/system/Commands/Database/Seed.php +++ b/system/Commands/Database/Seed.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Help.php b/system/Commands/Help.php index fd774db..19852a8 100644 --- a/system/Commands/Help.php +++ b/system/Commands/Help.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/ListCommands.php b/system/Commands/ListCommands.php index 831bc54..118783b 100644 --- a/system/Commands/ListCommands.php +++ b/system/Commands/ListCommands.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Server/Serve.php b/system/Commands/Server/Serve.php index 0cd23f7..9691e97 100644 --- a/system/Commands/Server/Serve.php +++ b/system/Commands/Server/Serve.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -48,7 +48,7 @@ */ class Serve extends BaseCommand { - protected $minPHPVersion = '7.1'; + protected $minPHPVersion = '7.2'; protected $group = 'CodeIgniter'; protected $name = 'serve'; diff --git a/system/Commands/Sessions/CreateMigration.php b/system/Commands/Sessions/CreateMigration.php index 54a5397..0a9391e 100644 --- a/system/Commands/Sessions/CreateMigration.php +++ b/system/Commands/Sessions/CreateMigration.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Utilities/Namespaces.php b/system/Commands/Utilities/Namespaces.php index 1db06b9..ccb07c0 100644 --- a/system/Commands/Utilities/Namespaces.php +++ b/system/Commands/Utilities/Namespaces.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Commands/Utilities/Routes.php b/system/Commands/Utilities/Routes.php index 517d85a..f8c8092 100644 --- a/system/Commands/Utilities/Routes.php +++ b/system/Commands/Utilities/Routes.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Common.php b/system/Common.php index 7cda2ee..8c887e3 100644 --- a/system/Common.php +++ b/system/Common.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -102,6 +102,35 @@ //-------------------------------------------------------------------- +if (! function_exists('db_connnect')) +{ + /** + * Grabs a database connection and returns it to the user. + * + * This is a convenience wrapper for \Config\Database::connect() + * and supports the same parameters. Namely: + * + * When passing in $db, you may pass any of the following to connect: + * - group name + * - existing connection instance + * - array of database configuration values + * + * If $getShared === false then a new connection instance will be provided, + * otherwise it will all calls will return the same instance. + * + * @param \CodeIgniter\Database\ConnectionInterface|array|string $db + * @param boolean $getShared + * + * @return \CodeIgniter\Database\BaseConnection + */ + function db_connect($db = null, bool $getShared = true) + { + return \Config\Database::connect($db, $getShared); + } +} + +//-------------------------------------------------------------------- + if (! function_exists('view')) { /** @@ -540,7 +569,7 @@ * both in and out of the 'helpers' directory of a namespaced directory. * * Will load ALL helpers of the matching name, in the following order: - * 1. application/Helpers + * 1. app/Helpers * 2. {namespace}/Helpers * 3. system/Helpers * diff --git a/system/ComposerScripts.php b/system/ComposerScripts.php index 7cd91e3..fb86d20 100644 --- a/system/ComposerScripts.php +++ b/system/ComposerScripts.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index 61ef260..39e4a1c 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index a21ce44..095bd74 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -1,4 +1,5 @@ -getEnvValue("{$property}.{$key}", $prefix, $shortPrefix)) { - if (is_null($value)) + if (! is_null($value)) { - continue; - } + if ($value === 'false') + { + $value = false; + } + elseif ($value === 'true') + { + $value = true; + } + $this->$property[$key] = $value; + } + } + } + } + else + { + if (($value = $this->getEnvValue($property, $prefix, $shortPrefix)) !== false) + { + if (! is_null($value)) + { if ($value === 'false') { $value = false; @@ -97,38 +113,18 @@ $value = true; } - $this->$property[$key] = $value; + $this->$property = is_bool($value) ? $value : trim($value, '\'"'); } } } - else - { - if (($value = $this->getEnvValue($property, $prefix, $shortPrefix)) !== false) - { - if (is_null($value)) - { - continue; - } - - if ($value === 'false') - { - $value = false; - } - elseif ($value === 'true') - { - $value = true; - } - - $this->$property = is_bool($value) - ? $value - : trim($value, '\'"'); - } - } } if (defined('ENVIRONMENT') && ENVIRONMENT !== 'testing') { + // well, this won't happen during unit testing + // @codeCoverageIgnoreStart $this->registerProperties(); + // @codeCoverageIgnoreEnd } } diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index a9e5bba..62929ce 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -184,7 +184,7 @@ { $name = strtolower($name); - if (method_exists(__CLASS__, $name)) + if (method_exists(Services::class, $name)) { return Services::$name(...$arguments); } @@ -207,7 +207,7 @@ if ($init_autoloader) { - static::autoloader()->initialize(new \Config\Autoload()); + static::autoloader()->initialize(new \Config\Autoload(), new \Config\Modules()); } } diff --git a/system/Config/Config.php b/system/Config/Config.php index 12167d0..1750867 100644 --- a/system/Config/Config.php +++ b/system/Config/Config.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Config/DotEnv.php b/system/Config/DotEnv.php index 74b7a49..1a8af97 100644 --- a/system/Config/DotEnv.php +++ b/system/Config/DotEnv.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Config/ForeignCharacters.php b/system/Config/ForeignCharacters.php index ace76ef..e37f81a 100644 --- a/system/Config/ForeignCharacters.php +++ b/system/Config/ForeignCharacters.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Config/Routes.php b/system/Config/Routes.php index 2640fa1..8bf7b76 100644 --- a/system/Config/Routes.php +++ b/system/Config/Routes.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Config/Services.php b/system/Config/Services.php index 3815d80..adbc19c 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -151,34 +151,6 @@ //-------------------------------------------------------------------- /** - * The Email class allows you to send email via mail, sendmail, SMTP. - * - * @param null $config - * @param boolean $getShared - * - * @return \CodeIgniter\Email\Email|mixed - */ - public static function email($config = null, bool $getShared = true) - { - if ($getShared) - { - return static::getSharedInstance('email', $config); - } - - if (empty($config)) - { - $config = new \Config\Email(); - } - - $email = new \CodeIgniter\Email\Email($config); - $email->setLogger(static::logger(true)); - - return $email; - } - - //-------------------------------------------------------------------- - - /** * The Exceptions class holds the methods that handle: * * - set_exception_handler @@ -253,6 +225,32 @@ //-------------------------------------------------------------------- /** + * The Honeypot provides a secret input on forms that bots should NOT + * fill in, providing an additional safeguard when accepting user input. + * + * @param \CodeIgniter\Config\BaseConfig|null $config + * @param boolean $getShared + * + * @return \CodeIgniter\Honeypot\Honeypot|mixed + */ + public static function honeypot(BaseConfig $config = null, $getShared = true) + { + if ($getShared) + { + return static::getSharedInstance('honeypot', $config); + } + + if (is_null($config)) + { + $config = new \Config\Honeypot(); + } + + return new \CodeIgniter\Honeypot\Honeypot($config); + } + + //-------------------------------------------------------------------- + + /** * Acts as a factory for ImageHandler classes and returns an instance * of the handler. Used like Services::image()->withFile($path)->rotate(90)->save(); * @@ -736,7 +734,7 @@ if (! is_object($config)) { - $config = config(\Config\Toolbar::class); + $config = config('Toolbar'); } return new \CodeIgniter\Debug\Toolbar($config); diff --git a/system/Config/View.php b/system/Config/View.php index 142bb02..2e31683 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 @@ -75,8 +75,8 @@ public function __construct() { - $this->filters = array_merge($this->filters, $this->coreFilters); - $this->plugins = array_merge($this->plugins, $this->corePlugins); + $this->filters = array_merge($this->coreFilters, $this->filters); + $this->plugins = array_merge($this->corePlugins, $this->plugins); parent::__construct(); } diff --git a/system/Controller.php b/system/Controller.php index c0016fe..269e78b 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index fbfa3ed..23a2c25 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -227,6 +227,9 @@ $this->db = $db; + // turn off automatic escape flags + $this->db->setEscapeFlags(false); + $this->from($tableName); if (! empty($options)) @@ -664,7 +667,7 @@ $op = $this->getOperator($k); $k = trim(str_replace($op, '', $k)); - $bind = $this->setBind($k, $v); + $bind = $this->setBind($k, $v, $escape); if (empty($op)) { @@ -813,8 +816,8 @@ $not = ($not) ? ' NOT' : ''; - $where_in = array_values($values); - $this->binds[$ok] = $where_in; + $where_in = array_values($values); + $ok = $this->setBind($ok, $where_in, $escape); $prefix = empty($this->QBWhere) ? $this->groupGetType('') : $this->groupGetType($type); @@ -955,19 +958,19 @@ if ($side === 'none') { - $bind = $this->setBind($k, $v); + $bind = $this->setBind($k, $v, $escape); } elseif ($side === 'before') { - $bind = $this->setBind($k, "%$v"); + $bind = $this->setBind($k, "%$v", $escape); } elseif ($side === 'after') { - $bind = $this->setBind($k, "$v%"); + $bind = $this->setBind($k, "$v%", $escape); } else { - $bind = $this->setBind($k, "%$v%"); + $bind = $this->setBind($k, "%$v%", $escape); } $like_statement = $this->_like_statement($prefix, $k, $not, $bind, $insensitiveSearch); @@ -1345,7 +1348,7 @@ { if ($escape) { - $bind = $this->setBind($k, $v); + $bind = $this->setBind($k, $v, $escape); $this->QBSet[$this->db->protectIdentifiers($k, false, $escape)] = ":$bind:"; } else @@ -1399,12 +1402,33 @@ $this->resetSelect(); } - return $select; + return $this->compileFinalQuery($select); } //-------------------------------------------------------------------- /** + * Returns a finalized, compiled query string with the bindings + * inserted and prefixes swapped out. + * + * @param string $sql + * + * @return mixed|string + */ + protected function compileFinalQuery(string $sql): string + { + $query = new Query($this->db); + $query->setQuery($sql, $this->binds, false); + + if (! empty($this->db->swapPre) && ! empty($this->db->DBPrefix)) + { + $query->swapPrefix($this->db->DBPrefix, $this->db->swapPre); + } + + return $query->getQuery(); + } + + /** * Get * * Compiles the select statement based on the other functions called @@ -1423,6 +1447,7 @@ { $this->limit($limit, $offset); } + $result = $returnSQL ? $this->getCompiledSelect() : $this->db->query($this->compileSelect(), $this->binds); if ($reset === true) @@ -1696,7 +1721,7 @@ $clean = []; foreach ($row as $k => $value) { - $clean[] = ':' . $this->setBind($k, $value) . ':'; + $clean[] = ':' . $this->setBind($k, $value, $escape) . ':'; } $row = $clean; @@ -1741,7 +1766,7 @@ $this->resetWrite(); } - return $sql; + return $this->compileFinalQuery($sql); } //-------------------------------------------------------------------- @@ -1931,7 +1956,7 @@ $this->resetWrite(); } - return $sql; + return $this->compileFinalQuery($sql); } //-------------------------------------------------------------------- @@ -2203,7 +2228,7 @@ $index_set = true; } - $bind = $this->setBind($k2, $v2); + $bind = $this->setBind($k2, $v2, $escape); $clean[$this->db->protectIdentifiers($k2, false, $escape)] = ":$bind:"; } @@ -2312,7 +2337,7 @@ $sql = $this->delete($table, '', null, $reset); $this->returnDeleteSQL = false; - return $sql; + return $this->compileFinalQuery($sql); } //-------------------------------------------------------------------- @@ -2918,17 +2943,24 @@ /** * Stores a bind value after ensuring that it's unique. + * While it might be nicer to have named keys for our binds array + * with PHP 7+ we get a huge memory/performance gain with indexed + * arrays instead, so lets take advantage of that here. * - * @param string $key - * @param null $value + * @param string $key + * @param null $value + * @param boolean $escape * * @return string */ - protected function setBind(string $key, $value = null) + protected function setBind(string $key, $value = null, bool $escape = true) { if (! array_key_exists($key, $this->binds)) { - $this->binds[$key] = $value; + $this->binds[$key] = [ + $value, + $escape, + ]; return $key; } @@ -2937,10 +2969,13 @@ while (array_key_exists($key . $count, $this->binds)) { - ++ $count; + ++$count; } - $this->binds[$key . $count] = $value; + $this->binds[$key . $count] = [ + $value, + $escape, + ]; return $key . $count; } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 18ab6e6..323425a 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -327,6 +327,16 @@ */ protected $aliasedTables = []; + /** + * Should the bindings be collected with a default escape value? + * The Builder will automatically set this to false, so that any + * $db->query('...', [binds]); Will result in bindings being + * automatically escaped. + * + * @var boolean + */ + protected $setEscapeFlags = true; + //-------------------------------------------------------------------- /** @@ -578,6 +588,20 @@ } /** + * Should query() automatically attach escape flags to each bound var? + * + * @param boolean $setFlags + * + * @return $this + */ + public function setEscapeFlags(bool $setFlags) + { + $this->setEscapeFlags = $setFlags; + + return $this; + } + + /** * Executes the query against the database. * * @param $sql @@ -596,9 +620,11 @@ * Should automatically handle different connections for read/write * queries if needed. * - * @param string $sql - * @param array ...$binds - * @param string $queryClass + * @param string $sql + * @param array ...$binds + * @param string $queryClass + * @param boolean $setEscape + * * @return BaseResult|Query|false */ public function query(string $sql, $binds = null, $queryClass = 'CodeIgniter\\Database\\Query') @@ -609,13 +635,12 @@ } $resultClass = str_replace('Connection', 'Result', get_class($this)); - /** * @var Query $query */ $query = new $queryClass($this); - $query->setQuery($sql, $binds); + $query->setQuery($sql, $binds, $this->setEscapeFlags); if (! empty($this->swapPre) && ! empty($this->DBPrefix)) { diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index 355fd14..9c9681f 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index a08f232..b4ea569 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index 81fe474..1d84381 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Config.php b/system/Database/Config.php index c283b6e..f986df7 100644 --- a/system/Database/Config.php +++ b/system/Database/Config.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -74,6 +74,12 @@ */ public static function connect($group = null, bool $getShared = true) { + // If a DB connection is passed in, just pass it back + if ($group instanceof BaseConnection) + { + return $group; + } + if (is_array($group)) { $config = $group; @@ -129,34 +135,13 @@ * Loads and returns an instance of the Forge for the specified * database group, and loads the group if it hasn't been loaded yet. * - * @param string|null $group + * @param string|array|null $group * * @return Forge */ - public static function forge(string $group = null) + public static function forge($group = null) { - $config = new \Config\Database(); - - static::ensureFactory(); - - if (empty($group)) - { - $group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup; - } - - if (! isset($config->$group)) - { - throw new \InvalidArgumentException($group . ' is not a valid database connection group.'); - } - - if (! isset(static::$instances[$group])) - { - $db = static::connect($group); - } - else - { - $db = static::$instances[$group]; - } + $db = static::connect($group); return static::$factory->loadForge($db); } @@ -166,34 +151,13 @@ /** * Returns a new instance of the Database Utilities class. * - * @param string|null $group + * @param string|array|null $group * * @return BaseUtils */ - public static function utils(string $group = null) + public static function utils($group = null) { - $config = new \Config\Database(); - - static::ensureFactory(); - - if (empty($group)) - { - $group = $config->defaultGroup; - } - - if (! isset($config->group)) - { - throw new \InvalidArgumentException($group . ' is not a valid database connection group.'); - } - - if (! isset(static::$instances[$group])) - { - $db = static::connect($group); - } - else - { - $db = static::$instances[$group]; - } + $db = static::connect($group); return static::$factory->loadUtils($db); } @@ -209,7 +173,7 @@ */ public static function seeder(string $group = null) { - $config = new \Config\Database(); + $config = config('Database'); return new Seeder($config, static::connect($group)); } diff --git a/system/Database/ConnectionInterface.php b/system/Database/ConnectionInterface.php index ac055be..3a54be8 100644 --- a/system/Database/ConnectionInterface.php +++ b/system/Database/ConnectionInterface.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Database.php b/system/Database/Database.php index c6fddab..df18aad 100644 --- a/system/Database/Database.php +++ b/system/Database/Database.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index b74d0ac..4597ba8 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -9,7 +9,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,7 +31,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 88cc304..b84557c 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Migration.php b/system/Database/Migration.php index 88a5002..3efef03 100644 --- a/system/Database/Migration.php +++ b/system/Database/Migration.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/MigrationRunner.php b/system/Database/MigrationRunner.php index be7c50a..89672e3 100644 --- a/system/Database/MigrationRunner.php +++ b/system/Database/MigrationRunner.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -126,17 +126,37 @@ */ protected $cliMessages = []; + /** + * Tracks whether we have already ensured + * the table exists or not. + * + * @var boolean + */ + protected $tableChecked = false; + + /** + * The full path to locate migration files. + * + * @var string + */ + protected $path; + //-------------------------------------------------------------------- /** * Constructor. * - * @param BaseConfig $config - * @param \CodeIgniter\Database\ConnectionInterface $db + * When passing in $db, you may pass any of the following to connect: + * - group name + * - existing connection instance + * - array of database configuration values + * + * @param BaseConfig $config + * @param \CodeIgniter\Database\ConnectionInterface|array|string $db * * @throws ConfigException */ - public function __construct(BaseConfig $config, ConnectionInterface $db = null) + public function __construct(BaseConfig $config, $db = null) { $this->enabled = $config->enabled ?? false; $this->type = $config->type ?? 'timestamp'; @@ -147,15 +167,10 @@ $this->namespace = APP_NAMESPACE; // get default database group - $config = new \Config\Database(); + $config = config('Database'); $this->group = $config->defaultGroup; unset($config); - if (empty($this->table)) - { - throw ConfigException::forMissingMigrationsTable(); - } - if (! in_array($this->type, ['sequential', 'timestamp'])) { throw ConfigException::forInvalidMigrationType($this->type); @@ -166,9 +181,7 @@ // If no db connection passed in, use // default database group. - $this->db = ! empty($db) ? $db : \Config\Database::connect(); - - $this->ensureTable(); + $this->db = db_connect($db); } //-------------------------------------------------------------------- @@ -192,6 +205,9 @@ { throw ConfigException::forDisabledMigrations(); } + + $this->ensureTable(); + // Set Namespace if not null if (! is_null($namespace)) { @@ -204,6 +220,12 @@ $this->setGroup($group); } + // Sequential versions need adjusting to 3 places so they can be found later. + if ($this->type === 'sequential') + { + $targetVersion = str_pad($targetVersion, 3, '0', STR_PAD_LEFT); + } + $migrations = $this->findMigrations(); if (empty($migrations)) @@ -284,6 +306,8 @@ */ public function latest(string $namespace = null, string $group = null) { + $this->ensureTable(); + // Set Namespace if not null if (! is_null($namespace)) { @@ -315,6 +339,8 @@ */ public function latestAll(string $group = null) { + $this->ensureTable(); + // Set database group if not null if (! is_null($group)) { @@ -322,7 +348,7 @@ } // Get all namespaces form PSR4 paths. - $config = new Autoload(); + $config = config('Autoload'); $namespaces = $config->psr4; foreach ($namespaces as $namespace => $path) @@ -361,6 +387,8 @@ */ public function current(string $group = null) { + $this->ensureTable(); + // Set database group if not null if (! is_null($group)) { @@ -380,27 +408,51 @@ public function findMigrations() { $migrations = []; - // Get namespace location form PSR4 paths. - $config = new Autoload(); + helper('filesystem'); - $location = $config->psr4[$this->namespace]; + // If $this->path contains a valid directory use it. + if (! empty($this->path)) + { + $dir = rtrim($this->path, DIRECTORY_SEPARATOR) . '/'; + } + // Otherwise, get namespace location form PSR4 paths + // and add Database/Migrations for a standard loation. + else + { + $config = config('Autoload'); - // Setting migration directories. - $dir = rtrim($location, DIRECTORY_SEPARATOR) . '/Database/Migrations/'; + $location = $config->psr4[$this->namespace]; + + // Setting migration directories. + $dir = rtrim($location, DIRECTORY_SEPARATOR) . '/Database/Migrations/'; + } // Load all *_*.php files in the migrations path - foreach (glob($dir . '*_*.php') as $file) + // We can't use glob if we want it to be testable.... + $files = get_filenames($dir, true); + + foreach ($files as $file) { + if (substr($file, -4) !== '.php') + { + continue; + } + + // Remove the extension $name = basename($file, '.php'); + // Filter out non-migration files if (preg_match($this->regex, $name)) { // Create migration object using stdClass $migration = new \stdClass(); + // Get migration version number $migration->version = $this->getMigrationNumber($name); $migration->name = $this->getMigrationName($name); - $migration->path = $file; + $migration->path = ! empty($this->path) && strpos($file, $this->path) !== 0 + ? $this->path . $file + : $file; // Add to migrations[version] $migrations[$migration->version] = $migration; @@ -436,7 +488,7 @@ } // Check if $targetversion file is found - if ($targetversion !== '0' && ! array_key_exists($targetversion, $migrations)) + if ((int)$targetversion !== 0 && ! array_key_exists($targetversion, $migrations)) { if ($this->silent) { @@ -458,14 +510,14 @@ { if ($this->type === 'sequential' && abs($migration->version - $loop) > 1) { - throw new \RuntimeException(lang('Migration.gap') . ' ' . $migration->version); + throw new \RuntimeException(lang('Migrations.gap') . ' ' . $migration->version); } // Check if all old migration files are all available to do downgrading if ($method === 'down') { if ($loop <= $history_size && $history_migrations[$loop]['version'] !== $migration->version) { - throw new \RuntimeException(lang('Migration.gap') . ' ' . $migration->version); + throw new \RuntimeException(lang('Migrations.gap') . ' ' . $migration->version); } } $loop ++; @@ -477,6 +529,22 @@ //-------------------------------------------------------------------- /** + * Sets the path to the base directory that will be used + * when locating migrations. If left null, the value will + * be chosen from $this->namespace's directory. + * + * @param string|null $path + * + * @return $this + */ + public function setPath(string $path = null) + { + $this->path = $path; + + return $this; + } + + /** * Set namespace. * Allows other scripts to modify on the fly as needed. * @@ -514,10 +582,14 @@ * Set migration Name. * * @param string $name + * + * @return \CodeIgniter\Database\MigrationRunner */ public function setName(string $name) { $this->name = $name; + + return $this; } //-------------------------------------------------------------------- @@ -531,6 +603,8 @@ */ public function getHistory(string $group = 'default') { + $this->ensureTable(); + $query = $this->db->table($this->table) ->where('group', $group) ->where('namespace', $this->namespace) @@ -602,6 +676,8 @@ */ protected function getVersion() { + $this->ensureTable(); + $row = $this->db->table($this->table) ->select('version') ->where('group', $this->group) @@ -675,14 +751,14 @@ * Ensures that we have created our migrations table * in the database. */ - protected function ensureTable() + public function ensureTable() { - if ($this->db->tableExists($this->table)) + if ($this->tableChecked || $this->db->tableExists($this->table)) { return; } - $forge = \Config\Database::forge(); + $forge = \Config\Database::forge($this->db); $forge->addField([ 'version' => [ @@ -713,6 +789,8 @@ ]); $forge->createTable($this->table, true); + + $this->tableChecked = true; } //-------------------------------------------------------------------- diff --git a/system/Database/MySQLi/Builder.php b/system/Database/MySQLi/Builder.php index 1d370a0..07cd6c4 100644 --- a/system/Database/MySQLi/Builder.php +++ b/system/Database/MySQLi/Builder.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 3fc4968..2e8af1c 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/MySQLi/Forge.php b/system/Database/MySQLi/Forge.php index 15adc2b..bd5be18 100644 --- a/system/Database/MySQLi/Forge.php +++ b/system/Database/MySQLi/Forge.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/MySQLi/PreparedQuery.php b/system/Database/MySQLi/PreparedQuery.php index c470a15..d17e5b5 100644 --- a/system/Database/MySQLi/PreparedQuery.php +++ b/system/Database/MySQLi/PreparedQuery.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index cb9caf6..6f131f4 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/MySQLi/Utils.php b/system/Database/MySQLi/Utils.php index fb27f81..6876ec8 100644 --- a/system/Database/MySQLi/Utils.php +++ b/system/Database/MySQLi/Utils.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 0cb11b9..8102fb7 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -162,7 +162,14 @@ $table = $this->QBFrom[0]; - $set = $this->binds; + $set = $this->binds; + + // We need to grab out the actual values from + // the way binds are stored with escape flag. + array_walk($set, function (&$item) { + $item = $item[0]; + }); + $keys = array_keys($set); $values = array_values($set); diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 5de0914..1c046e9 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Postgre/Forge.php b/system/Database/Postgre/Forge.php index a66f460..e94845a 100644 --- a/system/Database/Postgre/Forge.php +++ b/system/Database/Postgre/Forge.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Postgre/PreparedQuery.php b/system/Database/Postgre/PreparedQuery.php index d28de33..2864985 100644 --- a/system/Database/Postgre/PreparedQuery.php +++ b/system/Database/Postgre/PreparedQuery.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Postgre/Result.php b/system/Database/Postgre/Result.php index 545ccb1..73141cd 100644 --- a/system/Database/Postgre/Result.php +++ b/system/Database/Postgre/Result.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Postgre/Utils.php b/system/Database/Postgre/Utils.php index 67f6188..cbe83c5 100644 --- a/system/Database/Postgre/Utils.php +++ b/system/Database/Postgre/Utils.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/PreparedQueryInterface.php b/system/Database/PreparedQueryInterface.php index db3a750..6e633b5 100644 --- a/system/Database/PreparedQueryInterface.php +++ b/system/Database/PreparedQueryInterface.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Query.php b/system/Database/Query.php index 2a382c4..561bc1f 100644 --- a/system/Database/Query.php +++ b/system/Database/Query.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 @@ -129,17 +129,32 @@ /** * Sets the raw query string to use for this statement. * - * @param string $sql - * @param array $binds + * @param string $sql + * @param array $binds + * @param boolean $setEscape * * @return mixed */ - public function setQuery(string $sql, $binds = null) + public function setQuery(string $sql, $binds = null, bool $setEscape = true) { $this->originalQueryString = $sql; if (! is_null($binds)) { + if (! is_array($binds)) + { + $binds = [$binds]; + } + + if ($setEscape) + { + array_walk($binds, function (&$item) { + $item = [ + $item, + true, + ]; + }); + } $this->binds = $binds; } @@ -407,12 +422,13 @@ foreach ($binds as $placeholder => $value) { - $escapedValue = $this->db->escape($value); + // $value[1] contains the boolean whether should be escaped or not + $escapedValue = $value[1] ? $this->db->escape($value[0]) : $value[0]; // In order to correctly handle backlashes in saved strings // we will need to preg_quote, so remove the wrapping escape characters // otherwise it will get escaped. - if (is_array($value)) + if (is_array($value[0])) { $escapedValue = '(' . implode(',', $escapedValue) . ')'; } @@ -460,7 +476,7 @@ do { $c --; - $escapedValue = $this->db->escape($binds[$c]); + $escapedValue = $binds[$c][1] ? $this->db->escape($binds[$c][0]) : $binds[$c[0]]; if (is_array($escapedValue)) { $escapedValue = '(' . implode(',', $escapedValue) . ')'; diff --git a/system/Database/QueryInterface.php b/system/Database/QueryInterface.php index e158bae..fe24a8c 100644 --- a/system/Database/QueryInterface.php +++ b/system/Database/QueryInterface.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/ResultInterface.php b/system/Database/ResultInterface.php index da3f0b0..0016276 100644 --- a/system/Database/ResultInterface.php +++ b/system/Database/ResultInterface.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/SQLite3/Builder.php b/system/Database/SQLite3/Builder.php index 9ffe98f..757adbe 100644 --- a/system/Database/SQLite3/Builder.php +++ b/system/Database/SQLite3/Builder.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2017 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/SQLite3/Connection.php b/system/Database/SQLite3/Connection.php index 367945d..16a6645 100644 --- a/system/Database/SQLite3/Connection.php +++ b/system/Database/SQLite3/Connection.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2017 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/SQLite3/Forge.php b/system/Database/SQLite3/Forge.php index a6f9a58..9e2630d 100644 --- a/system/Database/SQLite3/Forge.php +++ b/system/Database/SQLite3/Forge.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2017 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/SQLite3/PreparedQuery.php b/system/Database/SQLite3/PreparedQuery.php index b0dd1a9..ff194aa 100644 --- a/system/Database/SQLite3/PreparedQuery.php +++ b/system/Database/SQLite3/PreparedQuery.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2017 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/SQLite3/Result.php b/system/Database/SQLite3/Result.php index 5737bf3..c32dec5 100644 --- a/system/Database/SQLite3/Result.php +++ b/system/Database/SQLite3/Result.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2017 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/SQLite3/Utils.php b/system/Database/SQLite3/Utils.php index 23eaec1..5de29fb 100644 --- a/system/Database/SQLite3/Utils.php +++ b/system/Database/SQLite3/Utils.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2017 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2017 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Database/Seeder.php b/system/Database/Seeder.php index c57e7e0..7947d18 100644 --- a/system/Database/Seeder.php +++ b/system/Database/Seeder.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index cb69f49..0ea00b6 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Debug/Iterator.php b/system/Debug/Iterator.php index 442aad4..a8c0e33 100644 --- a/system/Debug/Iterator.php +++ b/system/Debug/Iterator.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Debug/Timer.php b/system/Debug/Timer.php index 9710101..b124a38 100644 --- a/system/Debug/Timer.php +++ b/system/Debug/Timer.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index b4ecf54..2cf3e70 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 diff --git a/system/Debug/Toolbar/Collectors/BaseCollector.php b/system/Debug/Toolbar/Collectors/BaseCollector.php index 3a5889d..dd06de6 100644 --- a/system/Debug/Toolbar/Collectors/BaseCollector.php +++ b/system/Debug/Toolbar/Collectors/BaseCollector.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 diff --git a/system/Debug/Toolbar/Collectors/Database.php b/system/Debug/Toolbar/Collectors/Database.php index 319d943..f1d31fd 100644 --- a/system/Debug/Toolbar/Collectors/Database.php +++ b/system/Debug/Toolbar/Collectors/Database.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 @@ -109,7 +109,15 @@ */ public static function collect(Query $query) { - static::$queries[] = $query; + $config = config('Toolbar'); + + // Provide default in case it's not set + $max = $config->maxQueries ?: 100; + + if (count(static::$queries) < $max) + { + static::$queries[] = $query; + } } //-------------------------------------------------------------------- diff --git a/system/Debug/Toolbar/Collectors/Events.php b/system/Debug/Toolbar/Collectors/Events.php index f6587d3..9ad73cb 100644 --- a/system/Debug/Toolbar/Collectors/Events.php +++ b/system/Debug/Toolbar/Collectors/Events.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 diff --git a/system/Debug/Toolbar/Collectors/Files.php b/system/Debug/Toolbar/Collectors/Files.php index 5ecf23c..34c6fc5 100644 --- a/system/Debug/Toolbar/Collectors/Files.php +++ b/system/Debug/Toolbar/Collectors/Files.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 diff --git a/system/Debug/Toolbar/Collectors/History.php b/system/Debug/Toolbar/Collectors/History.php index 8be0f2a..062d160 100644 --- a/system/Debug/Toolbar/Collectors/History.php +++ b/system/Debug/Toolbar/Collectors/History.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 diff --git a/system/Debug/Toolbar/Collectors/Logs.php b/system/Debug/Toolbar/Collectors/Logs.php index 26aab0e..5e0c7e9 100644 --- a/system/Debug/Toolbar/Collectors/Logs.php +++ b/system/Debug/Toolbar/Collectors/Logs.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 @@ -84,15 +84,8 @@ */ public function display(): array { - $logs = $this->collectLogs(); - - if (empty($logs) || ! is_array($logs)) - { - $logs = []; - } - return [ - 'logs' => $logs, + 'logs' => $this->collectLogs(), ]; } @@ -131,11 +124,10 @@ { if (! is_null($this->data)) { - return; + return $this->data; } - $logger = Services::logger(true); - $this->data = $logger->logCache; + return $this->data = Services::logger(true)->logCache ?? []; } //-------------------------------------------------------------------- diff --git a/system/Debug/Toolbar/Collectors/Routes.php b/system/Debug/Toolbar/Collectors/Routes.php index 917978d..b4176dc 100644 --- a/system/Debug/Toolbar/Collectors/Routes.php +++ b/system/Debug/Toolbar/Collectors/Routes.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 diff --git a/system/Debug/Toolbar/Collectors/Timers.php b/system/Debug/Toolbar/Collectors/Timers.php index a7ff971..3c5e1c1 100644 --- a/system/Debug/Toolbar/Collectors/Timers.php +++ b/system/Debug/Toolbar/Collectors/Timers.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 diff --git a/system/Debug/Toolbar/Collectors/Views.php b/system/Debug/Toolbar/Collectors/Views.php index 5dc87e8..d1ec285 100644 --- a/system/Debug/Toolbar/Collectors/Views.php +++ b/system/Debug/Toolbar/Collectors/Views.php @@ -7,7 +7,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014-2018 British Columbia Institute of Technology + * Copyright (c) 2014-2019 British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * * @package CodeIgniter * @author CodeIgniter Dev Team - * @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/) + * @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 4.0.0 @@ -106,7 +106,7 @@ */ public function __construct() { - $this->viewer = Services::renderer(null, true); + $this->viewer = Services::renderer(); } //-------------------------------------------------------------------- diff --git a/system/Email/Email.php b/system/Email/Email.php deleted file mode 100644 index 87f5c82..0000000 --- a/system/Email/Email.php +++ /dev/null @@ -1,2542 +0,0 @@ - '1 (Highest)', - 2 => '2 (High)', - 3 => '3 (Normal)', - 4 => '4 (Low)', - 5 => '5 (Lowest)', - ]; - - /** - * mbstring.func_overload flag - * - * @var boolean - */ - protected static $func_overload; - - /** - * Logger instance to record error messages and awarnings. - * - * @var \PSR\Log\LoggerInterface - */ - protected $logger; - - //-------------------------------------------------------------------- - - /** - * Constructor - Sets Email Preferences - * - * The constructor can be passed an array of config values - * - * @param array|null $config - */ - public function __construct($config = null) - { - $this->initialize($config); - - isset(static::$func_overload) || static::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); - - log_message('info', 'Email Class Initialized'); - } - - //-------------------------------------------------------------------- - - /** - * Initialize preferences - * - * @param array|\Config\Email $config - * - * @return Email - */ - public function initialize($config) - { - $this->clear(); - - if ($config instanceof \Config\Email) - { - $config = get_object_vars($config); - } - - foreach (get_class_vars(get_class($this)) as $key => $value) - { - if (property_exists($this, $key) && isset($config[$key])) - { - $method = 'set' . ucfirst($key); - - if (method_exists($this, $method)) - { - $this->$method($config[$key]); - } - else - { - $this->$key = $config[$key]; - } - } - } - - $this->charset = strtoupper($this->charset); - $this->SMTPAuth = isset($this->SMTPUser[0], $this->SMTPPass[0]); - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Initialize the Email Data - * - * @param boolean $clearAttachments - * - * @return Email - */ - public function clear($clearAttachments = false) - { - $this->subject = ''; - $this->body = ''; - $this->finalBody = ''; - $this->headerStr = ''; - $this->replyToFlag = false; - $this->recipients = []; - $this->CCArray = []; - $this->BCCArray = []; - $this->headers = []; - $this->debugMessage = []; - - $this->setHeader('Date', $this->setDate()); - - if ($clearAttachments !== false) - { - $this->attachments = []; - } - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set FROM - * - * @param string $from - * @param string $name - * @param string|null $returnPath Return-Path - * - * @return Email - */ - public function setFrom($from, $name = '', $returnPath = null) - { - if (preg_match('/\<(.*)\>/', $from, $match)) - { - $from = $match[1]; - } - - if ($this->validate) - { - $this->validateEmail($this->stringToArray($from)); - if ($returnPath) - { - $this->validateEmail($this->stringToArray($returnPath)); - } - } - - // prepare the display name - if ($name !== '') - { - // only use Q encoding if there are characters that would require it - if (! preg_match('/[\200-\377]/', $name)) - { - // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes - $name = '"' . addcslashes($name, "\0..\37\177'\"\\") . '"'; - } - else - { - $name = $this->prepQEncoding($name); - } - } - - $this->setHeader('From', $name . ' <' . $from . '>'); - - isset($returnPath) || $returnPath = $from; - $this->setHeader('Return-Path', '<' . $returnPath . '>'); - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Reply-to - * - * @param string $replyto - * @param string $name - * - * @return Email - */ - public function setReplyTo($replyto, $name = '') - { - if (preg_match('/\<(.*)\>/', $replyto, $match)) - { - $replyto = $match[1]; - } - - if ($this->validate) - { - $this->validateEmail($this->stringToArray($replyto)); - } - - if ($name !== '') - { - // only use Q encoding if there are characters that would require it - if (! preg_match('/[\200-\377]/', $name)) - { - // add slashes for non-printing characters, slashes, and double quotes, and surround it in double quotes - $name = '"' . addcslashes($name, "\0..\37\177'\"\\") . '"'; - } - else - { - $name = $this->prepQEncoding($name); - } - } - - $this->setHeader('Reply-To', $name . ' <' . $replyto . '>'); - $this->replyToFlag = true; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Recipients - * - * @param string $to - * - * @return Email - */ - public function setTo($to) - { - $to = $this->stringToArray($to); - $to = $this->cleanEmail($to); - - if ($this->validate) - { - $this->validateEmail($to); - } - - if ($this->getProtocol() !== 'mail') - { - $this->setHeader('To', implode(', ', $to)); - } - - $this->recipients = $to; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set CC - * - * @param string $cc - * - * @return Email - */ - public function setCC($cc) - { - $cc = $this->cleanEmail($this->stringToArray($cc)); - - if ($this->validate) - { - $this->validateEmail($cc); - } - - $this->setHeader('Cc', implode(', ', $cc)); - - if ($this->getProtocol() === 'smtp') - { - $this->CCArray = $cc; - } - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set BCC - * - * @param string $bcc - * @param string $limit - * - * @return Email - */ - public function setBCC($bcc, $limit = '') - { - if ($limit !== '' && is_numeric($limit)) - { - $this->BCCBatchMode = true; - $this->BCCBatchSize = $limit; - } - - $bcc = $this->cleanEmail($this->stringToArray($bcc)); - - if ($this->validate) - { - $this->validateEmail($bcc); - } - - if ($this->getProtocol() === 'smtp' || ($this->BCCBatchMode && count($bcc) > $this->BCCBatchSize)) - { - $this->BCCArray = $bcc; - } - else - { - $this->setHeader('Bcc', implode(', ', $bcc)); - } - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Email Subject - * - * @param string $subject - * - * @return Email - */ - public function setSubject($subject) - { - $subject = $this->prepQEncoding($subject); - $this->setHeader('Subject', $subject); - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Body - * - * @param string $body - * - * @return Email - */ - public function setMessage($body) - { - $this->body = rtrim(str_replace("\r", '', $body)); - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Assign file attachments - * - * @param string $file Can be local path, URL or buffered content - * @param string $disposition 'attachment' - * @param string|null $newname - * @param string $mime - * - * @return Email - */ - public function attach($file, $disposition = '', $newname = null, $mime = '') - { - if ($mime === '') - { - if (strpos($file, '://') === false && ! is_file($file)) - { - $this->setErrorMessage(lang('Email.attachmentMissing', [$file])); - - return false; - } - - if (! $fp = @fopen($file, 'rb')) - { - $this->setErrorMessage(lang('Email.attachmentUnreadable', [$file])); - - return false; - } - - $fileContent = stream_get_contents($fp); - $mime = $this->mimeTypes(pathinfo($file, PATHINFO_EXTENSION)); - fclose($fp); - } - else - { - $fileContent = & $file; // buffered file - } - - // declare names on their own, to make phpcbf happy - $namesAttached = [ - $file, - $newname, - ]; - $this->attachments[] = [ - 'name' => $namesAttached, - 'disposition' => empty($disposition) ? 'attachment' : $disposition, - // Can also be 'inline' Not sure if it matters - 'type' => $mime, - 'content' => chunk_split(base64_encode($fileContent)), - 'multipart' => 'mixed', - ]; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set and return attachment Content-ID - * - * Useful for attached inline pictures - * - * @param string $filename - * - * @return string - */ - public function setAttachmentCID($filename) - { - for ($i = 0, $c = count($this->attachments); $i < $c; $i ++) - { - if ($this->attachments[$i]['name'][0] === $filename) - { - $this->attachments[$i]['multipart'] = 'related'; - $this->attachments[$i]['cid'] = uniqid(basename($this->attachments[$i]['name'][0]) . '@', true); - - return $this->attachments[$i]['cid']; - } - } - - return false; - } - - //-------------------------------------------------------------------- - - /** - * Add a Header Item - * - * @param string $header - * @param string $value - * - * @return Email - */ - public function setHeader($header, $value) - { - $this->headers[$header] = str_replace(["\n", "\r"], '', $value); - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Convert a String to an Array - * - * @param string $email - * - * @return array - */ - protected function stringToArray($email) - { - if (! is_array($email)) - { - return (strpos($email, ',') !== false) ? preg_split('/[\s,]/', $email, -1, PREG_SPLIT_NO_EMPTY) : (array) trim($email); - } - - return $email; - } - - //-------------------------------------------------------------------- - - /** - * Set Multipart Value - * - * @param string $str - * - * @return Email - */ - public function setAltMessage($str) - { - $this->altMessage = (string) $str; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Mailtype - * - * @param string $type - * - * @return Email - */ - public function setMailType($type = 'text') - { - $this->mailType = ($type === 'html') ? 'html' : 'text'; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Wordwrap - * - * @param boolean $wordWrap - * - * @return Email - */ - public function setWordWrap($wordWrap = true) - { - $this->wordWrap = (bool) $wordWrap; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Protocol - * - * @param string $protocol - * - * @return Email - */ - public function setProtocol($protocol = 'mail') - { - $this->protocol = in_array($protocol, $this->protocols, true) ? strtolower($protocol) : 'mail'; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Priority - * - * @param integer $n - * - * @return Email - */ - public function setPriority($n = 3) - { - $this->priority = preg_match('/^[1-5]$/', $n) ? (int) $n : 3; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set Newline Character - * - * @param string $newline - * - * @return Email - */ - public function setNewline($newline = "\n") - { - $this->newline = in_array($newline, ["\n", "\r\n", "\r"]) ? $newline : "\n"; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Set CRLF - * - * @param string $CRLF - * - * @return Email - */ - public function setCRLF($CRLF = "\n") - { - $this->CRLF = ($CRLF !== "\n" && $CRLF !== "\r\n" && $CRLF !== "\r") ? "\n" : $CRLF; - - return $this; - } - - //-------------------------------------------------------------------- - - /** - * Get the Message ID - * - * @return string - */ - protected function getMessageID() - { - $from = str_replace(['>', '<'], '', $this->headers['Return-Path']); - - return '<' . uniqid('', true) . strstr($from, '@') . '>'; - } - - //-------------------------------------------------------------------- - - /** - * Get Mail Protocol - * - * @return string - */ - protected function getProtocol() - { - $this->protocol = strtolower($this->protocol); - in_array($this->protocol, $this->protocols, true) || $this->protocol = 'mail'; - - return $this->protocol; - } - - //-------------------------------------------------------------------- - - /** - * Get Mail Encoding - * - * @return string - */ - protected function getEncoding() - { - in_array($this->encoding, $this->bitDepths) || $this->encoding = '8bit'; - - foreach ($this->baseCharsets as $charset) - { - if (strpos($this->charset, $charset) === 0) - { - $this->encoding = '7bit'; - break; - } - } - - return $this->encoding; - } - - //-------------------------------------------------------------------- - - /** - * Get content type (text/html/attachment) - * - * @return string - */ - protected function getContentType() - { - if ($this->mailType === 'html') - { - return empty($this->attachments) ? 'html' : 'html-attach'; - } - elseif ($this->mailType === 'text' && ! empty($this->attachments)) - { - return 'plain-attach'; - } - else - { - return 'plain'; - } - } - - //-------------------------------------------------------------------- - - /** - * Set RFC 822 Date - * - * @return string - */ - protected function setDate() - { - $timezone = date('Z'); - $operator = ($timezone[0] === '-') ? '-' : '+'; - $timezone = abs($timezone); - $timezone = floor($timezone / 3600) * 100 + ($timezone % 3600) / 60; - - return sprintf('%s %s%04d', date('D, j M Y H:i:s'), $operator, $timezone); - } - - //-------------------------------------------------------------------- - - /** - * Mime message - * - * @return string - */ - protected function getMimeMessage() - { - return 'This is a multi-part message in MIME format.' . $this->newline . 'Your email application may not support this format.'; - } - - //-------------------------------------------------------------------- - - /** - * Validate Email Address - * - * @param string $email - * - * @return boolean - */ - public function validateEmail($email) - { - if (! is_array($email)) - { - $this->setErrorMessage(lang('Email.mustBeArray')); - - return false; - } - - foreach ($email as $val) - { - if (! $this->isValidEmail($val)) - { - $this->setErrorMessage(lang('Email.invalidAddress', $val)); - - return false; - } - } - - return true; - } - - //-------------------------------------------------------------------- - - /** - * Email Validation - * - * @param string $email - * - * @return boolean - */ - public function isValidEmail($email) - { - if (function_exists('idn_to_ascii') && defined('INTL_IDNA_VARIANT_UTS46') && $atpos = strpos($email, '@')) - { - $email = static::substr($email, 0, ++ $atpos) . idn_to_ascii( - static::substr($email, $atpos), 0, INTL_IDNA_VARIANT_UTS46 - ); - } - - return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); - } - - //-------------------------------------------------------------------- - - /** - * Clean Extended Email Address: Joe Smith - * - * @param string $email - * - * @return string - */ - public function cleanEmail($email) - { - if (! is_array($email)) - { - return preg_match('/\<(.*)\>/', $email, $match) ? $match[1] : $email; - } - - $cleanEmail = []; - - foreach ($email as $addy) - { - $cleanEmail[] = preg_match('/\<(.*)\>/', $addy, $match) ? $match[1] : $addy; - } - - return $cleanEmail; - } - - //-------------------------------------------------------------------- - - /** - * Build alternative plain text message - * - * Provides the raw message for use in plain-text headers of - * HTML-formatted emails. - * If the user hasn't specified his own alternative message - * it creates one by stripping the HTML - * - * @return string - */ - protected function getAltMessage() - { - if (! empty($this->altMessage)) - { - return ($this->wordWrap) ? $this->wordWrap($this->altMessage, 76) : $this->altMessage; - } - - $body = preg_match('/\(.*)\<\/body\>/si', $this->body, $match) ? $match[1] : $this->body; - $body = str_replace("\t", '', preg_replace('#