Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
Update codeigniter
Browse files Browse the repository at this point in the history
  • Loading branch information
deathart committed Jun 2, 2018
1 parent 68f4723 commit 0f16c0d
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 142 deletions.
15 changes: 15 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const uglify = require('gulp-uglify');
const gulpSequence = require('gulp-sequence');
const path = require('path');
const rev = require('gulp-rev');
const revFormat = require('gulp-rev-format');
const revdel = require('gulp-rev-delete-original');
const postcss = require('gulp-postcss');
const image = require('gulp-image');
Expand Down Expand Up @@ -76,6 +77,9 @@ gulp.task('revisioning', function() {
.pipe(gulp.dest(config.output))
.pipe(rev())
.pipe(override())
.pipe(revFormat({
suffix: '-' + randomString(5),
}))
.pipe(gulp.dest(config.output))
.pipe(revdel())
.pipe(rev.manifest())
Expand All @@ -90,3 +94,14 @@ gulp.task('revisioning', function() {

gulp.task('build', gulpSequence('clean', ['scss', 'js', 'image', 'fonts'], ['cleancss', 'cleanjs'], 'revisioning'));
gulp.task('default', ['scss', 'js' ]);


function randomString(len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomString = '';
for (var i = 0; i < len; i++) {
var randomPoz = Math.floor(Math.random() * charSet.length);
randomString += charSet.substring(randomPoz,randomPoz+1);
}
return randomString;
}
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"gulp-rev": "^8.1.1",
"gulp-rev-css-url": "^0.1.0",
"gulp-rev-delete-original": "^0.2.3",
"gulp-rev-format": "^1.0.4",
"gulp-sass": "^4.0.1",
"gulp-sequence": "^1.0.0",
"gulp-uglify": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

// Location of the framework bootstrap file.
// This is the second of two lines that might need to be changed, depending on your folder structure.
$app = require FCPATH . '../system//bootstrap.php';
$app = require FCPATH . '../system/bootstrap.php';

/*
*---------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions system/Config/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ public function __construct()
'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\Encryption\EncrypterInterface' => BASEPATH . 'Encryption/EncrypterInterface.php',
'CodeIgniter\Encryption\Handlers\BaseHandler' => BASEPATH . 'Encryption/Handlers/BaseHandler.php',
'CodeIgniter\Encryption\Handlers\OpenSSLHandler' => BASEPATH . 'Encryption/Handlers/OpenSSLHandler.php',
'CodeIgniter\Events\Events' => BASEPATH . 'Events/Events.php',
'CodeIgniter\HTTP\CLIRequest' => BASEPATH . 'HTTP/CLIRequest.php',
'CodeIgniter\HTTP\ContentSecurityPolicy' => BASEPATH . 'HTTP/ContentSecurityPolicy.php',
Expand Down
263 changes: 263 additions & 0 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
<?php namespace CodeIgniter\Config;

/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014-2018 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
* 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 2014-2018 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
* @filesource
*/

/**
* 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 bool
*/
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];
}

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

/**
* 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(__CLASS__, $name))
{
return Services::$name(...$arguments);
}

return static::discoverServices($name, $arguments);
}

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

/**
* Reset shared instances and mocks for testing.
*/
public static function reset()
{
static::$mocks = [];

static::$instances = [];
}

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

/**
* 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
*/
protected static function discoverServices(string $name, array $arguments)
{
if (! static::$discovered)
{
$locator = static::locator();
$files = $locator->search('Config/Services');

if (empty($files))
{
return;
}

// Get instances of all service classes and cache them locally.
foreach ($files as $file)
{
$classname = static::getClassName($file);

if (! in_array($classname, ['Config\\Services', 'CodeIgniter\\Config\\Services']))
{
static::$services[] = new $classname();
}
}
}

if (! count(static::$services))
{
return;
}

// Try to find the desired service method
foreach (static::$services as $class)
{
if (method_exists($class, $name))
{
return $class::$name(...$arguments);
}
}
}

/**
* Examines a file and returns the fully qualified domain name.
*
* @param string $file
*
* @return string
*/
private static function getClassname(string $file)
{
$php = file_get_contents($file);
$tokens = token_get_all($php);
$count = count($tokens);
$dlm = false;
$namespace = '';
$class_name = '';

for ($i = 2; $i < $count; $i++)
{
if ((isset($tokens[$i-2][1]) && ($tokens[$i-2][1] == "phpnamespace" || $tokens[$i-2][1] == "namespace")) || ($dlm && $tokens[$i-1][0] == T_NS_SEPARATOR && $tokens[$i][0] == T_STRING))
{
if (! $dlm)
{
$namespace = 0;
}
if (isset($tokens[$i][1]))
{
$namespace = $namespace ? $namespace."\\".$tokens[$i][1] : $tokens[$i][1];
$dlm = true;
}
}
elseif ($dlm && ($tokens[$i][0] != T_NS_SEPARATOR) && ($tokens[$i][0] != T_STRING))
{
$dlm = false;
}
if (($tokens[$i-2][0] == T_CLASS || (isset($tokens[$i-2][1]) && $tokens[$i-2][1] == "phpclass"))
&& $tokens[$i-1][0] == T_WHITESPACE
&& $tokens[$i][0] == T_STRING)
{
$class_name = $tokens[$i][1];
break;
}
}

return $namespace .'\\'. $class_name;
}
}
Loading

0 comments on commit 0f16c0d

Please sign in to comment.