Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:bcit-ci/CodeIgniter4 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Jul 13, 2017
2 parents 829567e + f32d557 commit a5b6d93
Show file tree
Hide file tree
Showing 20 changed files with 2,011 additions and 253 deletions.
10 changes: 0 additions & 10 deletions application/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,6 @@ class App extends BaseConfig
*/
public $errorViewPath = APPPATH.'Views/errors';

/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class you must set
| an encryption key. See the user guide for more info.
*/
public $encryptionKey = '';

/*
|--------------------------------------------------------------------------
| Application Salt
Expand Down
56 changes: 56 additions & 0 deletions application/Config/Encryption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

/**
* Encryption configuration.
*
* These are the settings used for encryption, if you don't pass a parameter
* array to the encrypter for creation/initialization.
*
*/
class Encryption extends BaseConfig
{
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class you must set an encryption key.
| You need to ensure it is long enough for the cipher and mode you plan to use.
| See the user guide for more info.
*/

public $key = '';

/*
|--------------------------------------------------------------------------
| Encryption driver to use
|--------------------------------------------------------------------------
|
| One of the supported drivers, eg 'openssl' or 'mcrypt'.
| The default driver, if you don't specify one, is 'openssl'.
*/
public $driver = 'openssl';

/*
|--------------------------------------------------------------------------
| Encryption Cipher
|--------------------------------------------------------------------------
|
| Name of the encryption cipher to use, eg 'aes-256' or 'blowfish'
*/
public $cipher = 'aes-256';

/*
|--------------------------------------------------------------------------
| Encryption mode
|--------------------------------------------------------------------------
|
| The encryption mode to use, eg 'cbc' or 'stream'
*/
public $mode = 'cbc';

}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"require": {
"php": ">=7.0",
"zendframework/zend-escaper": "^2.5"
"zendframework/zend-escaper": "^2.5",
"paragonie/sodium_compat": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
Expand Down
27 changes: 13 additions & 14 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,15 @@ public function register()
// Now prepend another loader for the files in our class map.
$config = is_array($this->classmap) ? $this->classmap : [];

spl_autoload_register(function ($class) use ($config)
{
spl_autoload_register(function ($class) use ($config) {
if ( ! array_key_exists($class, $config))
{
return false;
}

include_once $config[$class];
},
true, // Throw exception
true // Prepend
}, true, // Throw exception
true // Prepend
);
}

Expand Down Expand Up @@ -257,11 +255,13 @@ protected function loadInNamespace($class)
{
$directory = rtrim($directory, '/');

if (strpos($class, $namespace) === 0) {
if (strpos($class, $namespace) === 0)
{
$filePath = $directory . str_replace('\\', '/', substr($class, strlen($namespace))) . '.php';
$filename = $this->requireFile($filePath);

if ($filename) {
if ($filename)
{
return $filename;
}
}
Expand All @@ -287,22 +287,22 @@ protected function loadLegacy($class)
{
// If there is a namespace on this class, then
// we cannot load it from traditional locations.
if (strpos('\\', $class) !== false)
if (strpos($class, '\\') !== false)
{
return false;
}

$paths = [
APPPATH.'Controllers/',
APPPATH.'Libraries/',
APPPATH.'Models/',
APPPATH . 'Controllers/',
APPPATH . 'Libraries/',
APPPATH . 'Models/',
];

$class = str_replace('\\', '/', $class).'.php';
$class = str_replace('\\', '/', $class) . '.php';

foreach ($paths as $path)
{
if ($file = $this->requireFile($path.$class))
if ($file = $this->requireFile($path . $class))
{
return $file;
}
Expand Down Expand Up @@ -368,5 +368,4 @@ public function sanitizeFilename(string $filename): string
}

//--------------------------------------------------------------------

}
78 changes: 34 additions & 44 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @since Version 3.0.0
* @filesource
*/

use Config\Autoload;

/**
Expand Down Expand Up @@ -87,17 +86,15 @@ public function __construct(Autoload $autoload)
*
* @return string The path to the file if found, or an empty string.
*/
public function locateFile(string $file, string $folder=null, string $ext = 'php'): string
public function locateFile(string $file, string $folder = null, string $ext = 'php'): string
{
// Ensure the extension is on the filename
$file = strpos($file, '.'.$ext) !== false
? $file
: $file.'.'.$ext;
$file = strpos($file, '.' . $ext) !== false ? $file : $file . '.' . $ext;

// Clean the folder name from the filename
if (! empty($folder))
if ( ! empty($folder))
{
$file = str_replace($folder.'/', '', $file);
$file = str_replace($folder . '/', '', $file);
}

// No namespaceing? Try the application folder.
Expand All @@ -112,24 +109,23 @@ public function locateFile(string $file, string $folder=null, string $ext = 'php
$segments = explode('\\', $file);

// The first segment will be empty if a slash started the filename.
if (empty($segments[0])) unset($segments[0]);
if (empty($segments[0]))
unset($segments[0]);

$path = '';
$prefix = '';
$path = '';
$prefix = '';
$filename = '';

while (! empty($segments))
while ( ! empty($segments))
{
$prefix .= empty($prefix)
? ucfirst(array_shift($segments))
: '\\'. ucfirst(array_shift($segments));
$prefix .= empty($prefix) ? ucfirst(array_shift($segments)) : '\\' . ucfirst(array_shift($segments));

if (! array_key_exists($prefix, $this->namespaces))
if ( ! array_key_exists($prefix, $this->namespaces))
{
continue;
}

$path = $this->namespaces[$prefix].'/';
$path = $this->namespaces[$prefix] . '/';
$filename = implode('/', $segments);
break;
}
Expand All @@ -138,14 +134,14 @@ public function locateFile(string $file, string $folder=null, string $ext = 'php
// expects this file to be within that folder, like 'Views',
// or 'libraries'.
// @todo Allow it to check with and without the nested folder.
if (! empty($folder) && strpos($filename, $folder) === false)
if ( ! empty($folder) && strpos($filename, $folder) === false)
{
$filename = $folder.'/'.$filename;
$filename = $folder . '/' . $filename;
}

$path .= $filename;

if (! $this->requireFile($path))
if ( ! $this->requireFile($path))
{
$path = '';
}
Expand Down Expand Up @@ -178,17 +174,15 @@ public function search(string $path, string $ext = 'php'): array
$foundPaths = [];

// Ensure the extension is on the filename
$path = strpos($path, '.'.$ext) !== false
? $path
: $path.'.'.$ext;
$path = strpos($path, '.' . $ext) !== false ? $path : $path . '.' . $ext;

foreach ($this->namespaces as $name => $folder)
{
$folder = rtrim($folder, '/').'/';
$folder = rtrim($folder, '/') . '/';

if (file_exists($folder.$path))
if (file_exists($folder . $path))
{
$foundPaths[] = $folder.$path;
$foundPaths[] = $folder . $path;
}
}

Expand All @@ -213,20 +207,21 @@ public function findQualifiedNameFromPath(string $path)
{
$path = realpath($path);

if (! $path)
if ( ! $path)
{
return;
}

foreach ($this->namespaces as $namespace => $nsPath)
{
$nsPath = realpath($nsPath);
if (is_numeric($namespace)||empty($nsPath)) continue;
if (is_numeric($namespace) || empty($nsPath))
continue;

if (mb_strpos($path,$nsPath) === 0)
if (mb_strpos($path, $nsPath) === 0)
{
$className = '\\'.$namespace.'\\'.
ltrim(str_replace('/', '\\', mb_substr($path, mb_strlen($nsPath))), '\\');
$className = '\\' . $namespace . '\\' .
ltrim(str_replace('/', '\\', mb_substr($path, mb_strlen($nsPath))), '\\');
// Remove the file extension (.php)
$className = mb_substr($className, 0, -4);

Expand All @@ -247,26 +242,24 @@ public function findQualifiedNameFromPath(string $path)
*/
public function listFiles(string $path): array
{
if (empty($path)) return [];
if (empty($path))
return [];

$files = [];
helper('filesystem');

foreach ($this->namespaces as $namespace => $nsPath)
{
$fullPath = realpath(rtrim($nsPath, '/') .'/'. $path);
$fullPath = realpath(rtrim($nsPath, '/') . '/' . $path);

if (! is_dir($fullPath)) continue;
if ( ! is_dir($fullPath))
continue;

$tempFiles = get_filenames($fullPath, true);
//CLI::newLine($tempFiles);

if (! count($tempFiles))
{
continue;
}

$files = array_merge($files, $tempFiles);
if (count($tempFiles))
$files = array_merge($files, $tempFiles);
}

return $files;
Expand All @@ -283,15 +276,13 @@ public function listFiles(string $path): array
* @internal param string $ext
*
*/
protected function legacyLocate(string $file, string $folder=null): string
protected function legacyLocate(string $file, string $folder = null): string
{
$paths = [APPPATH, BASEPATH];

foreach ($paths as $path)
{
$path .= empty($folder)
? $file
: $folder.'/'.$file;
$path .= empty($folder) ? $file : $folder . '/' . $file;

if ($this->requireFile($path) === true)
{
Expand Down Expand Up @@ -319,5 +310,4 @@ protected function requireFile(string $path): bool
}

//--------------------------------------------------------------------

}
26 changes: 14 additions & 12 deletions system/Config/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ public function __construct()
'CodeIgniter\Database\Database' => BASEPATH.'Database/Database.php',
'CodeIgniter\Database\Query' => BASEPATH.'Database/Query.php',
'CodeIgniter\Database\QueryInterface' => BASEPATH.'Database/QueryInterface.php',
'CodeIgniter\Database\ResultInterface' => BASEPATH.'Database/ResultInterface.php',
'CodeIgniter\Database\Migration' => BASEPATH.'Database/Migration.php',
'CodeIgniter\Database\MigrationRunner' => BASEPATH.'Database/MigrationRunner.php',
'CodeIgniter\Debug\Timer' => BASEPATH.'Debug/Timer.php',
'CodeIgniter\Debug\Iterator' => BASEPATH.'Debug/Iterator.php',
'CodeIgniter\Events\Events' => BASEPATH.'Events/Events.php',
'CodeIgniter\HTTP\CLIRequest' => BASEPATH.'HTTP/CLIRequest.php',
'CodeIgniter\HTTP\ContentSecurityPolicy' => BASEPATH.'HTTP/ContentSecurityPolicy.php',
'CodeIgniter\HTTP\CURLRequest' => BASEPATH.'HTTP/CURLRequest.php',
'CodeIgniter\HTTP\IncomingRequest' => BASEPATH.'HTTP/IncomingRequest.php',
'CodeIgniter\HTTP\Message' => BASEPATH.'HTTP/Message.php',
'CodeIgniter\HTTP\Negotiate' => BASEPATH.'HTTP/Negotiate.php',
'CodeIgniter\Database\ResultInterface' => BASEPATH.'Database/ResultInterface.php',
'CodeIgniter\Database\Migration' => BASEPATH.'Database/Migration.php',
'CodeIgniter\Database\MigrationRunner' => BASEPATH.'Database/MigrationRunner.php',
'CodeIgniter\Debug\Exceptions' => BASEPATH.'Debug/Exceptions.php',
'CodeIgniter\Debug\Timer' => BASEPATH.'Debug/Timer.php',
'CodeIgniter\Debug\Iterator' => BASEPATH.'Debug/Iterator.php',
'CodeIgniter\Encryption\Encryption' => BASEPATH.'Encryption/Encryption.php',
'CodeIgniter\Events\Events' => BASEPATH.'Events/Events.php',
'CodeIgniter\HTTP\CLIRequest' => BASEPATH.'HTTP/CLIRequest.php',
'CodeIgniter\HTTP\ContentSecurityPolicy' => BASEPATH.'HTTP/ContentSecurityPolicy.php',
'CodeIgniter\HTTP\CURLRequest' => BASEPATH.'HTTP/CURLRequest.php',
'CodeIgniter\HTTP\IncomingRequest' => BASEPATH.'HTTP/IncomingRequest.php',
'CodeIgniter\HTTP\Message' => BASEPATH.'HTTP/Message.php',
'CodeIgniter\HTTP\Negotiate' => BASEPATH.'HTTP/Negotiate.php',
'CodeIgniter\HTTP\Request' => BASEPATH.'HTTP/Request.php',
'CodeIgniter\HTTP\RequestInterface' => BASEPATH.'HTTP/RequestInterface.php',
'CodeIgniter\HTTP\Response' => BASEPATH.'HTTP/Response.php',
Expand Down
Loading

0 comments on commit a5b6d93

Please sign in to comment.