First Local Commit - After Clean up.

Signed-off-by: Rick Hays <rhays@haysgang.com>
This commit is contained in:
2019-12-02 14:54:38 -06:00
commit 10412ab7f6
486 changed files with 123242 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
/**
* AUTO-LOADER
*
* This file defines the namespaces and class maps so the Autoloader
* can find the files as needed.
*/
class AutoloadConfig
{
/**
* Array of namespaces for autoloading.
*
* @var array
*/
public $psr4 = [];
/**
* Map of class names and locations
*
* @var array
*/
public $classmap = [];
//--------------------------------------------------------------------
/**
* Constructor.
*/
public function __construct()
{
/**
* -------------------------------------------------------------------
* Namespaces
* -------------------------------------------------------------------
* This maps the locations of any namespaces in your application
* 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
* 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.
*
* DO NOT change the name of the CodeIgniter namespace or your application
* WILL break. *
* Prototype:
*
* $Config['psr4'] = [
* 'CodeIgniter' => SYSPATH
* `];
*/
$this->psr4 = [
'CodeIgniter' => realpath(SYSTEMPATH),
];
if (isset($_SERVER['CI_ENVIRONMENT']) && $_SERVER['CI_ENVIRONMENT'] === 'testing')
{
$this->psr4['Tests\Support'] = SUPPORTPATH;
}
/**
* -------------------------------------------------------------------
* Class Map
* -------------------------------------------------------------------
* The class map provides a map of class names and their exact
* location on the drive. Classes loaded in this manner will have
* slightly faster performance because they will not have to be
* searched for within one or more directories as they would if they
* were being autoloaded through a namespace.
*
* Prototype:
*
* $Config['classmap'] = [
* 'MyClass' => '/path/to/class/file.php'
* ];
*/
$this->classmap = [
'Psr\Log\AbstractLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php',
'Psr\Log\InvalidArgumentException' => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php',
'Psr\Log\LoggerAwareInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php',
'Psr\Log\LoggerAwareTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php',
'Psr\Log\LoggerInterface' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php',
'Psr\Log\LoggerTrait' => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php',
'Psr\Log\LogLevel' => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php',
'Psr\Log\NullLogger' => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php',
'Zend\Escaper\Escaper' => SYSTEMPATH . 'ThirdParty/ZendEscaper/Escaper.php',
];
if (isset($_SERVER['CI_ENVIRONMENT']) && $_SERVER['CI_ENVIRONMENT'] === 'testing')
{
$this->classmap['CodeIgniter\Log\TestLogger'] = SUPPORTPATH . 'Log/TestLogger.php';
$this->classmap['CIDatabaseTestCase'] = SUPPORTPATH . 'CIDatabaseTestCase.php';
}
}
//--------------------------------------------------------------------
}

View File

@@ -0,0 +1,245 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
/**
* Class BaseConfig
*
* Not intended to be used on its own, this class will attempt to
* automatically populate the child class' properties with values
* from the environment.
*
* These can be set within the .env file.
*/
class BaseConfig
{
/**
* An optional array of classes that will act as Registrars
* for rapidly setting config class properties.
*
* @var array
*/
public static $registrars = [];
/**
* Has module discovery happened yet?
*
* @var boolean
*/
protected static $didDiscovery = false;
/**
* The modules configuration.
*
* @var type
*/
protected static $moduleConfig;
/**
* Will attempt to get environment variables with names
* that match the properties of the child class.
*
* The "shortPrefix" is the lowercase-only config class name.
*/
public function __construct()
{
static::$moduleConfig = config('Modules');
$properties = array_keys(get_object_vars($this));
$prefix = get_class($this);
$slashAt = strrpos($prefix, '\\');
$shortPrefix = strtolower(substr($prefix, $slashAt === false ? 0 : $slashAt + 1));
foreach ($properties as $property)
{
$this->initEnvValue($this->$property, $property, $prefix, $shortPrefix);
}
if (defined('ENVIRONMENT') && ENVIRONMENT !== 'testing')
{
// well, this won't happen during unit testing
// @codeCoverageIgnoreStart
$this->registerProperties();
// @codeCoverageIgnoreEnd
}
}
//--------------------------------------------------------------------
/**
* Initialization an environment-specific configuration setting
*
* @param mixed &$property
* @param string $name
* @param string $prefix
* @param string $shortPrefix
*
* @return mixed
*/
protected function initEnvValue(&$property, string $name, string $prefix, string $shortPrefix)
{
if (is_array($property))
{
foreach ($property as $key => $val)
{
$this->initEnvValue($property[$key], "{$name}.{$key}", $prefix, $shortPrefix);
}
}
else
{
if (($value = $this->getEnvValue($name, $prefix, $shortPrefix)) !== false)
{
if (! is_null($value))
{
if ($value === 'false')
{
$value = false;
}
elseif ($value === 'true')
{
$value = true;
}
$property = is_bool($value) ? $value : trim($value, '\'"');
}
}
}
return $property;
}
//--------------------------------------------------------------------
/**
* Retrieve an environment-specific configuration setting
*
* @param string $property
* @param string $prefix
* @param string $shortPrefix
*
* @return mixed
*/
protected function getEnvValue(string $property, string $prefix, string $shortPrefix)
{
$shortPrefix = ltrim($shortPrefix, '\\');
switch (true)
{
case array_key_exists("{$shortPrefix}.{$property}", $_ENV):
return $_ENV["{$shortPrefix}.{$property}"];
break;
case array_key_exists("{$shortPrefix}.{$property}", $_SERVER):
return $_SERVER["{$shortPrefix}.{$property}"];
break;
case array_key_exists("{$prefix}.{$property}", $_ENV):
return $_ENV["{$prefix}.{$property}"];
break;
case array_key_exists("{$prefix}.{$property}", $_SERVER):
return $_SERVER["{$prefix}.{$property}"];
break;
default:
$value = getenv($property);
return $value === false ? null : $value;
}
}
//--------------------------------------------------------------------
/**
* Provides external libraries a simple way to register one or more
* options into a config file.
*
* @throws \ReflectionException
*/
protected function registerProperties()
{
if (! static::$moduleConfig->shouldDiscover('registrars'))
{
return;
}
if (! static::$didDiscovery)
{
$locator = \Config\Services::locator();
$registrarsFiles = $locator->search('Config/Registrar.php');
foreach ($registrarsFiles as $file)
{
$className = $locator->getClassname($file);
static::$registrars[] = new $className();
}
static::$didDiscovery = true;
}
$shortName = (new \ReflectionClass($this))->getShortName();
// Check the registrar class for a method named after this class' shortName
foreach (static::$registrars as $callable)
{
// ignore non-applicable registrars
if (! method_exists($callable, $shortName))
{
continue;
}
$properties = $callable::$shortName();
if (! is_array($properties))
{
throw new \RuntimeException('Registrars must return an array of properties and their values.');
}
foreach ($properties as $property => $value)
{
if (isset($this->$property) && is_array($this->$property) && is_array($value))
{
$this->$property = array_merge($this->$property, $value);
}
else
{
$this->$property = $value;
}
}
}
}
//--------------------------------------------------------------------
}

View File

@@ -0,0 +1,297 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
use CodeIgniter\Autoloader\Autoloader;
use CodeIgniter\Autoloader\FileLocator;
use Config\Autoload;
use Config\Modules;
/**
* Services Configuration file.
*
* Services are simply other classes/libraries that the system uses
* to do its job. This is used by CodeIgniter to allow the core of the
* framework to be swapped out easily without affecting the usage within
* the rest of your application.
*
* This is used in place of a Dependency Injection container primarily
* due to its simplicity, which allows a better long-term maintenance
* of the applications built on top of CodeIgniter. A bonus side-effect
* is that IDEs are able to determine what class you are calling
* whereas with DI Containers there usually isn't a way for them to do this.
*
* @see http://blog.ircmaxell.com/2015/11/simple-easy-risk-and-change.html
* @see http://www.infoq.com/presentations/Simple-Made-Easy
*/
class BaseService
{
/**
* Cache for instance of any services that
* have been requested as a "shared" instance.
*
* @var array
*/
static protected $instances = [];
/**
* Mock objects for testing which are returned if exist.
*
* @var array
*/
static protected $mocks = [];
/**
* Have we already discovered other Services?
*
* @var boolean
*/
static protected $discovered = false;
/**
* A cache of other service classes we've found.
*
* @var array
*/
static protected $services = [];
//--------------------------------------------------------------------
/**
* Returns a shared instance of any of the class' services.
*
* $key must be a name matching a service.
*
* @param string $key
* @param array ...$params
*
* @return mixed
*/
protected static function getSharedInstance(string $key, ...$params)
{
// Returns mock if exists
if (isset(static::$mocks[$key]))
{
return static::$mocks[$key];
}
if (! isset(static::$instances[$key]))
{
// Make sure $getShared is false
array_push($params, false);
static::$instances[$key] = static::$key(...$params);
}
return static::$instances[$key];
}
//--------------------------------------------------------------------
/**
* The Autoloader class is the central class that handles our
* spl_autoload_register method, and helper methods.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Autoloader\Autoloader
*/
public static function autoloader(bool $getShared = true)
{
if ($getShared)
{
if (empty(static::$instances['autoloader']))
{
static::$instances['autoloader'] = new Autoloader();
}
return static::$instances['autoloader'];
}
return new Autoloader();
}
//--------------------------------------------------------------------
/**
* The file locator provides utility methods for looking for non-classes
* within namespaced folders, as well as convenience methods for
* loading 'helpers', and 'libraries'.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Autoloader\FileLocator
*/
public static function locator(bool $getShared = true)
{
if ($getShared)
{
if (empty(static::$instances['locator']))
{
static::$instances['locator'] = new FileLocator(
static::autoloader()
);
}
return static::$instances['locator'];
}
return new FileLocator(static::autoloader());
}
//--------------------------------------------------------------------
/**
* Provides the ability to perform case-insensitive calling of service
* names.
*
* @param string $name
* @param array $arguments
*
* @return mixed
*/
public static function __callStatic(string $name, array $arguments)
{
$name = strtolower($name);
if (method_exists(Services::class, $name))
{
return Services::$name(...$arguments);
}
return static::discoverServices($name, $arguments);
}
//--------------------------------------------------------------------
/**
* Reset shared instances and mocks for testing.
*
* @param boolean $init_autoloader Initializes autoloader instance
*/
public static function reset(bool $init_autoloader = false)
{
static::$mocks = [];
static::$instances = [];
if ($init_autoloader)
{
static::autoloader()->initialize(new Autoload(), new Modules());
}
}
//--------------------------------------------------------------------
/**
* Inject mock object for testing.
*
* @param string $name
* @param $mock
*/
public static function injectMock(string $name, $mock)
{
$name = strtolower($name);
static::$mocks[$name] = $mock;
}
//--------------------------------------------------------------------
/**
* Will scan all psr4 namespaces registered with system to look
* for new Config\Services files. Caches a copy of each one, then
* looks for the service method in each, returning an instance of
* the service, if available.
*
* @param string $name
* @param array $arguments
*
* @return mixed
*/
protected static function discoverServices(string $name, array $arguments)
{
if (! static::$discovered)
{
$config = config('Modules');
if ($config->shouldDiscover('services'))
{
$locator = static::locator();
$files = $locator->search('Config/Services');
if (empty($files))
{
// no files at all found - this would be really, really bad
return null;
}
// Get instances of all service classes and cache them locally.
foreach ($files as $file)
{
$classname = $locator->getClassname($file);
if (! in_array($classname, ['CodeIgniter\\Config\\Services']))
{
static::$services[] = new $classname();
}
}
}
static::$discovered = true;
}
if (! static::$services)
{
// we found stuff, but no services - this would be really bad
return null;
}
// Try to find the desired service method
foreach (static::$services as $class)
{
if (method_exists(get_class($class), $name))
{
return $class::$name(...$arguments);
}
}
return null;
}
}

161
system/Config/Config.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
/**
* Class Config
*
* @package CodeIgniter\Config
*/
class Config
{
/**
* Cache for instance of any configurations that
* have been requested as "shared" instance.
*
* @var array
*/
static private $instances = [];
//--------------------------------------------------------------------
/**
* Create new configuration instances or return
* a shared instance
*
* @param string $name Configuration name
* @param boolean $getShared Use shared instance
*
* @return mixed|null
*/
public static function get(string $name, bool $getShared = true)
{
$class = $name;
if (($pos = strrpos($name, '\\')) !== false)
{
$class = substr($name, $pos + 1);
}
if (! $getShared)
{
return self::createClass($name);
}
if (! isset( self::$instances[$class] ))
{
self::$instances[$class] = self::createClass($name);
}
return self::$instances[$class];
}
//--------------------------------------------------------------------
/**
* Helper method for injecting mock instances while testing.
*
* @param string $class
* @param $instance
*/
public static function injectMock(string $class, $instance)
{
self::$instances[$class] = $instance;
}
//--------------------------------------------------------------------
/**
* Resets the instances array
*/
public static function reset()
{
static::$instances = [];
}
//--------------------------------------------------------------------
/**
* Find configuration class and create instance
*
* @param string $name Classname
*
* @return mixed|null
*/
private static function createClass(string $name)
{
if (class_exists($name))
{
return new $name();
}
$locator = Services::locator();
$file = $locator->locateFile($name, 'Config');
if (empty($file))
{
// No file found - check if the class was namespaced
if (strpos($name, '\\') !== false)
{
// Class was namespaced and locateFile couldn't find it
return null;
}
// Check all namespaces
$files = $locator->search('Config/' . $name);
if (empty($files))
{
return null;
}
// Get the first match (prioritizes user and framework)
$file = reset($files);
}
$name = $locator->getClassname($file);
if (empty($name))
{
return null;
}
return new $name();
}
//--------------------------------------------------------------------
}

307
system/Config/DotEnv.php Normal file
View File

@@ -0,0 +1,307 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
/**
* Environment-specific configuration
*/
class DotEnv
{
/**
* The directory where the .env file can be located.
*
* @var string
*/
protected $path;
//--------------------------------------------------------------------
/**
* Builds the path to our file.
*
* @param string $path
* @param string $file
*/
public function __construct(string $path, string $file = '.env')
{
$this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
}
//--------------------------------------------------------------------
/**
* The main entry point, will load the .env file and process it
* so that we end up with all settings in the PHP environment vars
* (i.e. getenv(), $_ENV, and $_SERVER)
*
* @return boolean
*/
public function load(): bool
{
// We don't want to enforce the presence of a .env file,
// they should be optional.
if (! is_file($this->path))
{
return false;
}
// Ensure file is readable
if (! is_readable($this->path))
{
throw new \InvalidArgumentException("The .env file is not readable: {$this->path}");
}
$lines = file($this->path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line)
{
// Is it a comment?
if (strpos(trim($line), '#') === 0)
{
continue;
}
// If there is an equal sign, then we know we
// are assigning a variable.
if (strpos($line, '=') !== false)
{
$this->setVariable($line);
}
}
return true; // for success
}
//--------------------------------------------------------------------
/**
* Sets the variable into the environment. Will parse the string
* first to look for {name}={value} pattern, ensure that nested
* variables are handled, and strip it of single and double quotes.
*
* @param string $name
* @param string $value
*/
protected function setVariable(string $name, string $value = '')
{
list($name, $value) = $this->normaliseVariable($name, $value);
if (! getenv($name, true))
{
putenv("$name=$value");
}
if (empty($_ENV[$name]))
{
$_ENV[$name] = $value;
}
if (empty($_SERVER[$name]))
{
$_SERVER[$name] = $value;
}
}
//--------------------------------------------------------------------
/**
* Parses for assignment, cleans the $name and $value, and ensures
* that nested variables are handled.
*
* @param string $name
* @param string $value
*
* @return array
*/
public function normaliseVariable(string $name, string $value = ''): array
{
// Split our compound string into it's parts.
if (strpos($name, '=') !== false)
{
list($name, $value) = explode('=', $name, 2);
}
$name = trim($name);
$value = trim($value);
// Sanitize the name
$name = str_replace(['export', '\'', '"'], '', $name);
// Sanitize the value
$value = $this->sanitizeValue($value);
$value = $this->resolveNestedVariables($value);
return [
$name,
$value,
];
}
//--------------------------------------------------------------------
/**
* Strips quotes from the environment variable value.
*
* This was borrowed from the excellent phpdotenv with very few changes.
* https://github.com/vlucas/phpdotenv
*
* @param string $value
*
* @return string
* @throws \InvalidArgumentException
*/
protected function sanitizeValue(string $value): string
{
if (! $value)
{
return $value;
}
// Does it begin with a quote?
if (strpbrk($value[0], '"\'') !== false)
{
// value starts with a quote
$quote = $value[0];
$regexPattern = sprintf(
'/^
%1$s # match a quote at the start of the value
( # capturing sub-pattern used
(?: # we do not need to capture this
[^%1$s\\\\] # any character other than a quote or backslash
|\\\\\\\\ # or two backslashes together
|\\\\%1$s # or an escaped quote e.g \"
)* # as many characters that match the previous rules
) # end of the capturing sub-pattern
%1$s # and the closing quote
.*$ # and discard any string after the closing quote
/mx', $quote
);
$value = preg_replace($regexPattern, '$1', $value);
$value = str_replace("\\$quote", $quote, $value);
$value = str_replace('\\\\', '\\', $value);
}
else
{
$parts = explode(' #', $value, 2);
$value = trim($parts[0]);
// Unquoted values cannot contain whitespace
if (preg_match('/\s+/', $value) > 0)
{
throw new \InvalidArgumentException('.env values containing spaces must be surrounded by quotes.');
}
}
return $value;
}
//--------------------------------------------------------------------
/**
* Resolve the nested variables.
*
* Look for ${varname} patterns in the variable value and replace with an existing
* environment variable.
*
* This was borrowed from the excellent phpdotenv with very few changes.
* https://github.com/vlucas/phpdotenv
*
* @param $value
*
* @return string
*/
protected function resolveNestedVariables(string $value): string
{
if (strpos($value, '$') !== false)
{
$loader = $this;
$value = preg_replace_callback(
'/\${([a-zA-Z0-9_]+)}/',
function ($matchedPatterns) use ($loader) {
$nestedVariable = $loader->getVariable($matchedPatterns[1]);
if (is_null($nestedVariable))
{
return $matchedPatterns[0];
}
return $nestedVariable;
},
$value
);
}
return $value;
}
//--------------------------------------------------------------------
/**
* Search the different places for environment variables and return first value found.
*
* This was borrowed from the excellent phpdotenv with very few changes.
* https://github.com/vlucas/phpdotenv
*
* @param string $name
*
* @return string|null
*/
protected function getVariable(string $name)
{
switch (true)
{
case array_key_exists($name, $_ENV):
return $_ENV[$name];
break;
case array_key_exists($name, $_SERVER):
return $_SERVER[$name];
break;
default:
$value = getenv($name);
// switch getenv default to null
return $value === false ? null : $value;
}
}
//--------------------------------------------------------------------
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
/**
* Describes foreign characters for transliteration with the text helper.
*/
class ForeignCharacters
{
/**
* Without further ado, the list of foreign characters.
*/
public $characterList = [
'/ä|æ|ǽ/' => 'ae',
'/ö|œ/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A',
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a',
'/Б/' => 'B',
'/б/' => 'b',
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
'/ç|ć|ĉ|ċ|č/' => 'c',
'/Д/' => 'D',
'/д/' => 'd',
'/Ð|Ď|Đ|Δ/' => 'Dj',
'/ð|ď|đ|δ/' => 'dj',
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E',
'/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e',
'/Ф/' => 'F',
'/ф/' => 'f',
'/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G',
'/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g',
'/Ĥ|Ħ/' => 'H',
'/ĥ|ħ/' => 'h',
'/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I',
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i',
'/Ĵ/' => 'J',
'/ĵ/' => 'j',
'/Ķ|Κ|К/' => 'K',
'/ķ|κ|к/' => 'k',
'/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L',
'/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l',
'/М/' => 'M',
'/м/' => 'm',
'/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N',
'/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n',
'/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O',
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o',
'/П/' => 'P',
'/п/' => 'p',
'/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R',
'/ŕ|ŗ|ř|ρ|р/' => 'r',
'/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S',
'/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's',
'/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T',
'/ț|ţ|ť|ŧ|т/' => 't',
'/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U',
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u',
'/Ƴ|Ɏ|Ỵ|Ẏ|Ӳ|Ӯ|Ў|Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y',
'/ẙ|ʏ|ƴ|ɏ|ỵ|ẏ|ӳ|ӯ|ў|ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y',
'/В/' => 'V',
'/в/' => 'v',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
'/Ź|Ż|Ž|Ζ|З/' => 'Z',
'/ź|ż|ž|ζ|з/' => 'z',
'/Æ|Ǽ/' => 'AE',
'/ß/' => 'ss',
'/IJ/' => 'IJ',
'/ij/' => 'ij',
'/Œ/' => 'OE',
'/ƒ/' => 'f',
'/ξ/' => 'ks',
'/π/' => 'p',
'/β/' => 'v',
'/μ/' => 'm',
'/ψ/' => 'ps',
'/Ё/' => 'Yo',
'/ё/' => 'yo',
'/Є/' => 'Ye',
'/є/' => 'ye',
'/Ї/' => 'Yi',
'/Ж/' => 'Zh',
'/ж/' => 'zh',
'/Х/' => 'Kh',
'/х/' => 'kh',
'/Ц/' => 'Ts',
'/ц/' => 'ts',
'/Ч/' => 'Ch',
'/ч/' => 'ch',
'/Ш/' => 'Sh',
'/ш/' => 'sh',
'/Щ/' => 'Shch',
'/щ/' => 'shch',
'/Ъ|ъ|Ь|ь/' => '',
'/Ю/' => 'Yu',
'/ю/' => 'yu',
'/Я/' => 'Ya',
'/я/' => 'ya',
];
}

66
system/Config/Routes.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
use CodeIgniter\Exceptions\PageNotFoundException;
/**
* System URI Routing
*
* This file contains any routing to system tools, such as command-line
* tools for migrations, etc.
*
* It is called by Config\Routes, and has the $routes RouteCollection
* already loaded up and ready for us to use.
*/
// Prevent access to BaseController
$routes->add('basecontroller(:any)', function () {
throw PageNotFoundException::forPageNotFound();
});
// Migrations
$routes->cli('migrations/(:segment)/(:segment)', '\CodeIgniter\Commands\MigrationsCommand::$1/$2');
$routes->cli('migrations/(:segment)', '\CodeIgniter\Commands\MigrationsCommand::$1');
$routes->cli('migrations', '\CodeIgniter\Commands\MigrationsCommand::index');
// CLI Catchall - uses a _remap to call Commands
$routes->cli('ci(:any)', '\CodeIgniter\CLI\CommandRunner::index/$1');
// Prevent access to initController method
$routes->add('(:any)/initController', function () {
throw PageNotFoundException::forPageNotFound();
});

930
system/Config/Services.php Normal file
View File

@@ -0,0 +1,930 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
use CodeIgniter\Cache\CacheFactory;
use CodeIgniter\Debug\Exceptions;
use CodeIgniter\Debug\Iterator;
use CodeIgniter\Debug\Timer;
use CodeIgniter\Debug\Toolbar;
use CodeIgniter\Encryption\EncrypterInterface;
use CodeIgniter\Encryption\Encryption;
use CodeIgniter\Filters\Filters;
use CodeIgniter\Honeypot\Honeypot;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\CURLRequest;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\Negotiate;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\Request;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\URI;
use CodeIgniter\HTTP\UserAgent;
use CodeIgniter\Language\Language;
use CodeIgniter\Pager\Pager;
use CodeIgniter\Router\RouteCollection;
use CodeIgniter\Router\RouteCollectionInterface;
use CodeIgniter\Router\Router;
use CodeIgniter\Security\Security;
use CodeIgniter\Session\Session;
use CodeIgniter\Throttle\Throttler;
use CodeIgniter\Typography\Typography;
use CodeIgniter\Validation\Validation;
use CodeIgniter\View\Cell;
use CodeIgniter\View\Parser;
use Config\App;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Database\MigrationRunner;
use CodeIgniter\View\RendererInterface;
use Config\Cache;
use Config\Images;
use Config\Logger;
use Config\Migrations;
/**
* Services Configuration file.
*
* Services are simply other classes/libraries that the system uses
* to do its job. This is used by CodeIgniter to allow the core of the
* framework to be swapped out easily without affecting the usage within
* the rest of your application.
*
* This is used in place of a Dependency Injection container primarily
* due to its simplicity, which allows a better long-term maintenance
* of the applications built on top of CodeIgniter. A bonus side-effect
* is that IDEs are able to determine what class you are calling
* whereas with DI Containers there usually isn't a way for them to do this.
*
* @see http://blog.ircmaxell.com/2015/11/simple-easy-risk-and-change.html
* @see http://www.infoq.com/presentations/Simple-Made-Easy
*/
class Services extends BaseService
{
/**
* The cache class provides a simple way to store and retrieve
* complex data for later.
*
* @param \Config\Cache $config
* @param boolean $getShared
*
* @return \CodeIgniter\Cache\CacheInterface
*/
public static function cache(Cache $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('cache', $config);
}
if (! is_object($config))
{
$config = new Cache();
}
return CacheFactory::getHandler($config);
}
//--------------------------------------------------------------------
/**
* The CLI Request class provides for ways to interact with
* a command line request.
*
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\CLIRequest
*/
public static function clirequest(App $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('clirequest', $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
return new CLIRequest($config);
}
//--------------------------------------------------------------------
/**
* The CURL Request class acts as a simple HTTP client for interacting
* with other servers, typically through APIs.
*
* @param array $options
* @param \CodeIgniter\HTTP\ResponseInterface $response
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\CURLRequest
*/
public static function curlrequest(array $options = [], ResponseInterface $response = null, App $config = null, bool $getShared = true)
{
if ($getShared === true)
{
return static::getSharedInstance('curlrequest', $options, $response, $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
if (! is_object($response))
{
$response = new Response($config);
}
return new CURLRequest(
$config,
new URI($options['base_uri'] ?? null),
$response,
$options
);
}
//--------------------------------------------------------------------
/**
* 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 Encryption class provides two-way encryption.
*
* @param mixed $config
* @param boolean $getShared
*
* @return EncrypterInterface Encryption handler
*/
public static function encrypter($config = null, $getShared = false)
{
if ($getShared === true)
{
return static::getSharedInstance('encrypter', $config);
}
if (empty($config))
{
$config = new \Config\Encryption();
}
$encryption = new Encryption($config);
$encrypter = $encryption->initialize($config);
return $encrypter;
}
//--------------------------------------------------------------------
/**
* The Exceptions class holds the methods that handle:
*
* - set_exception_handler
* - set_error_handler
* - register_shutdown_function
*
* @param \Config\Exceptions $config
* @param \CodeIgniter\HTTP\IncomingRequest $request
* @param \CodeIgniter\HTTP\Response $response
* @param boolean $getShared
*
* @return \CodeIgniter\Debug\Exceptions
*/
public static function exceptions(
\Config\Exceptions $config = null,
IncomingRequest $request = null,
Response $response = null,
bool $getShared = true
)
{
if ($getShared)
{
return static::getSharedInstance('exceptions', $config, $request, $response);
}
if (empty($config))
{
$config = new \Config\Exceptions();
}
if (empty($request))
{
$request = static::request();
}
if (empty($response))
{
$response = static::response();
}
return (new Exceptions($config, $request, $response));
}
//--------------------------------------------------------------------
/**
* Filters allow you to run tasks before and/or after a controller
* is executed. During before filters, the request can be modified,
* and actions taken based on the request, while after filters can
* act on or modify the response itself before it is sent to the client.
*
* @param mixed $config
* @param boolean $getShared
*
* @return \CodeIgniter\Filters\Filters
*/
public static function filters($config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('filters', $config);
}
if (empty($config))
{
$config = new \Config\Filters();
}
return new Filters($config, static::request(), static::response());
}
//--------------------------------------------------------------------
/**
* 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, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('honeypot', $config);
}
if (is_null($config))
{
$config = new \Config\Honeypot();
}
return new 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();
*
* @param string $handler
* @param mixed $config
* @param boolean $getShared
*
* @return \CodeIgniter\Images\Handlers\BaseHandler
*/
public static function image(string $handler = null, $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('image', $handler, $config);
}
if (empty($config))
{
$config = new Images();
}
$handler = is_null($handler) ? $config->defaultHandler : $handler;
$class = $config->handlers[$handler];
return new $class($config);
}
//--------------------------------------------------------------------
/**
* The Iterator class provides a simple way of looping over a function
* and timing the results and memory usage. Used when debugging and
* optimizing applications.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Debug\Iterator
*/
public static function iterator(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('iterator');
}
return new Iterator();
}
//--------------------------------------------------------------------
/**
* Responsible for loading the language string translations.
*
* @param string $locale
* @param boolean $getShared
*
* @return \CodeIgniter\Language\Language
*/
public static function language(string $locale = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('language', $locale)
->setLocale($locale);
}
$locale = ! empty($locale) ? $locale : static::request()
->getLocale();
return new Language($locale);
}
//--------------------------------------------------------------------
/**
* The Logger class is a PSR-3 compatible Logging class that supports
* multiple handlers that process the actual logging.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Log\Logger
*/
public static function logger(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('logger');
}
return new \CodeIgniter\Log\Logger(new Logger());
}
//--------------------------------------------------------------------
/**
* Return the appropriate igration runner.
*
* @param \CodeIgniter\Config\BaseConfig $config
* @param \CodeIgniter\Database\ConnectionInterface $db
* @param boolean $getShared
*
* @return \CodeIgniter\Database\MigrationRunner
*/
public static function migrations(BaseConfig $config = null, ConnectionInterface $db = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('migrations', $config, $db);
}
$config = empty($config) ? new Migrations() : $config;
return new MigrationRunner($config, $db);
}
//--------------------------------------------------------------------
/**
* The Negotiate class provides the content negotiation features for
* working the request to determine correct language, encoding, charset,
* and more.
*
* @param \CodeIgniter\HTTP\RequestInterface $request
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\Negotiate
*/
public static function negotiator(RequestInterface $request = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('negotiator', $request);
}
if (is_null($request))
{
$request = static::request();
}
return new Negotiate($request);
}
//--------------------------------------------------------------------
/**
* Return the appropriate pagination handler.
*
* @param mixed $config
* @param \CodeIgniter\View\RendererInterface $view
* @param boolean $getShared
*
* @return \CodeIgniter\Pager\Pager
*/
public static function pager($config = null, RendererInterface $view = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('pager', $config, $view);
}
if (empty($config))
{
$config = new \Config\Pager();
}
if (! $view instanceof RendererInterface)
{
$view = static::renderer();
}
return new Pager($config, $view);
}
//--------------------------------------------------------------------
/**
* The Parser is a simple template parser.
*
* @param string $viewPath
* @param mixed $config
* @param boolean $getShared
*
* @return \CodeIgniter\View\Parser
*/
public static function parser(string $viewPath = null, $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('parser', $viewPath, $config);
}
if (is_null($config))
{
$config = new \Config\View();
}
if (is_null($viewPath))
{
$paths = config('Paths');
$viewPath = $paths->viewDirectory;
}
return new Parser($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true));
}
//--------------------------------------------------------------------
/**
* The Renderer class is the class that actually displays a file to the user.
* The default View class within CodeIgniter is intentionally simple, but this
* service could easily be replaced by a template engine if the user needed to.
*
* @param string $viewPath
* @param mixed $config
* @param boolean $getShared
*
* @return \CodeIgniter\View\View
*/
public static function renderer(string $viewPath = null, $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('renderer', $viewPath, $config);
}
if (is_null($config))
{
$config = new \Config\View();
}
if (is_null($viewPath))
{
$paths = config('Paths');
$viewPath = $paths->viewDirectory;
}
return new \CodeIgniter\View\View($config, $viewPath, static::locator(true), CI_DEBUG, static::logger(true));
}
//--------------------------------------------------------------------
/**
* The Request class models an HTTP request.
*
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\IncomingRequest
*/
public static function request(App $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('request', $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
return new IncomingRequest(
$config,
new URI(),
'php://input',
new UserAgent()
);
}
//--------------------------------------------------------------------
/**
* The Response class models an HTTP response.
*
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\Response
*/
public static function response(App $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('response', $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
return new Response($config);
}
//--------------------------------------------------------------------
/**
* The Redirect class provides nice way of working with redirects.
*
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\Response
*/
public static function redirectResponse(App $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('redirectResponse', $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
$response = new RedirectResponse($config);
$response->setProtocolVersion(static::request()
->getProtocolVersion());
return $response;
}
//--------------------------------------------------------------------
/**
* The Routes service is a class that allows for easily building
* a collection of routes.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Router\RouteCollection
*/
public static function routes(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('routes');
}
return new RouteCollection(static::locator(), config('Modules'));
}
//--------------------------------------------------------------------
/**
* The Router class uses a RouteCollection's array of routes, and determines
* the correct Controller and Method to execute.
*
* @param \CodeIgniter\Router\RouteCollectionInterface $routes
* @param \CodeIgniter\HTTP\Request $request
* @param boolean $getShared
*
* @return \CodeIgniter\Router\Router
*/
public static function router(RouteCollectionInterface $routes = null, Request $request = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('router', $routes, $request);
}
if (empty($routes))
{
$routes = static::routes(true);
}
return new Router($routes, $request);
}
//--------------------------------------------------------------------
/**
* The Security class provides a few handy tools for keeping the site
* secure, most notably the CSRF protection tools.
*
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\Security\Security
*/
public static function security(App $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('security', $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
return new Security($config);
}
//--------------------------------------------------------------------
/**
* Return the session manager.
*
* @param \Config\App $config
* @param boolean $getShared
*
* @return \CodeIgniter\Session\Session
*/
public static function session(App $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('session', $config);
}
if (! is_object($config))
{
$config = config(App::class);
}
$logger = static::logger(true);
$driverName = $config->sessionDriver;
$driver = new $driverName($config, static::request()->getIpAddress());
$driver->setLogger($logger);
$session = new Session($driver, $config);
$session->setLogger($logger);
if (session_status() === PHP_SESSION_NONE)
{
$session->start();
}
return $session;
}
//--------------------------------------------------------------------
/**
* The Throttler class provides a simple method for implementing
* rate limiting in your applications.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Throttle\Throttler
*/
public static function throttler(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('throttler');
}
return new Throttler(static::cache());
}
//--------------------------------------------------------------------
/**
* The Timer class provides a simple way to Benchmark portions of your
* application.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Debug\Timer
*/
public static function timer(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('timer');
}
return new Timer();
}
//--------------------------------------------------------------------
/**
* Return the debug toolbar.
*
* @param \Config\Toolbar $config
* @param boolean $getShared
*
* @return \CodeIgniter\Debug\Toolbar
*/
public static function toolbar(\Config\Toolbar $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('toolbar', $config);
}
if (! is_object($config))
{
$config = config('Toolbar');
}
return new Toolbar($config);
}
//--------------------------------------------------------------------
/**
* The URI class provides a way to model and manipulate URIs.
*
* @param string $uri
* @param boolean $getShared
*
* @return \CodeIgniter\HTTP\URI
*/
public static function uri(string $uri = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('uri', $uri);
}
return new URI($uri);
}
//--------------------------------------------------------------------
/**
* The Validation class provides tools for validating input data.
*
* @param \Config\Validation $config
* @param boolean $getShared
*
* @return \CodeIgniter\Validation\Validation
*/
public static function validation(\Config\Validation $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('validation', $config);
}
if (is_null($config))
{
$config = config('Validation');
}
return new Validation($config, static::renderer());
}
//--------------------------------------------------------------------
/**
* View cells are intended to let you insert HTML into view
* that has been generated by any callable in the system.
*
* @param boolean $getShared
*
* @return \CodeIgniter\View\Cell
*/
public static function viewcell(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('viewcell');
}
return new Cell(static::cache());
}
//--------------------------------------------------------------------
/**
* The Typography class provides a way to format text in semantically relevant ways.
*
* @param boolean $getShared
*
* @return \CodeIgniter\Typography\Typography
*/
public static function typography(bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('typography');
}
return new Typography();
}
//--------------------------------------------------------------------
}

107
system/Config/View.php Normal file
View File

@@ -0,0 +1,107 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2019 British Columbia Institute of Technology
* Copyright (c) 2019 CodeIgniter Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2019 CodeIgniter Foundation
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 4.0.0
* @filesource
*/
namespace CodeIgniter\Config;
/**
* View configuration
*/
class View extends BaseConfig
{
/**
* Built-in View filters.
*
* @var type
*/
protected $coreFilters = [
'abs' => '\abs',
'capitalize' => '\CodeIgniter\View\Filters::capitalize',
'date' => '\CodeIgniter\View\Filters::date',
'date_modify' => '\CodeIgniter\View\Filters::date_modify',
'default' => '\CodeIgniter\View\Filters::default',
'esc' => '\CodeIgniter\View\Filters::esc',
'excerpt' => '\CodeIgniter\View\Filters::excerpt',
'highlight' => '\CodeIgniter\View\Filters::highlight',
'highlight_code' => '\CodeIgniter\View\Filters::highlight_code',
'limit_words' => '\CodeIgniter\View\Filters::limit_words',
'limit_chars' => '\CodeIgniter\View\Filters::limit_chars',
'local_currency' => '\CodeIgniter\View\Filters::local_currency',
'local_number' => '\CodeIgniter\View\Filters::local_number',
'lower' => '\strtolower',
'nl2br' => '\CodeIgniter\View\Filters::nl2br',
'number_format' => '\number_format',
'prose' => '\CodeIgniter\View\Filters::prose',
'round' => '\CodeIgniter\View\Filters::round',
'strip_tags' => '\strip_tags',
'title' => '\CodeIgniter\View\Filters::title',
'upper' => '\strtoupper',
];
/**
* Built-in View plugins.
*
* @var type
*/
protected $corePlugins = [
'current_url' => '\CodeIgniter\View\Plugins::currentURL',
'previous_url' => '\CodeIgniter\View\Plugins::previousURL',
'mailto' => '\CodeIgniter\View\Plugins::mailto',
'safe_mailto' => '\CodeIgniter\View\Plugins::safeMailto',
'lang' => '\CodeIgniter\View\Plugins::lang',
'validation_errors' => '\CodeIgniter\View\Plugins::validationErrors',
'route' => '\CodeIgniter\View\Plugins::route',
'siteURL' => '\CodeIgniter\View\Plugins::siteURL',
];
/**
* Constructor.
*
* Merge the built-in and developer-configured filters and plugins,
* with preference to the developer ones.
*/
public function __construct()
{
$this->filters = array_merge($this->coreFilters, $this->filters);
$this->plugins = array_merge($this->corePlugins, $this->plugins);
parent::__construct();
}
}