├── .editorconfig ├── phpstan.neon ├── src ├── helpers.php ├── Instance.php ├── Controller.php └── SparkPlug.php ├── LICENSE.md ├── .github └── workflows │ └── build.yml ├── composer.json ├── phpstyle.php ├── CHANGELOG.md └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | level: 9 3 | paths: 4 | - src 5 | - tests 6 | excludePaths: 7 | analyse: 8 | - tests/Application/views 9 | - tests/Codeigniter/application/views 10 | scanDirectories: 11 | - vendor/rougin/codeigniter/src 12 | ignoreErrors: 13 | - '#^Constant APPPATH not found\.$#' 14 | - '#^Constant BASEPATH not found\.$#' 15 | - '#^Constant ENVIRONMENT not found\.$#' -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class Instance 11 | { 12 | /** 13 | * Creates a Codeigniter instance based on the application path. 14 | * 15 | * @param string $path 16 | * @param array $server 17 | * @param array $globals 18 | * 19 | * @return \Rougin\SparkPlug\Controller 20 | */ 21 | public static function create($path = '', array $server = array(), array $globals = array()) 22 | { 23 | $globals = empty($globals) ? $GLOBALS : $globals; 24 | 25 | $server = empty($server) ? $_SERVER : $server; 26 | 27 | $sparkplug = new SparkPlug($globals, $server, $path); 28 | 29 | return $sparkplug->getCodeIgniter(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rougin Gutib 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [ 'master' ] 4 | pull_request: 5 | branches: [ 'master' ] 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | run: 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | php-versions: [ '5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] 18 | 19 | name: Run Unit Test on PHP ${{ matrix.php-versions }} 20 | 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v3 24 | 25 | - name: Install PHP 26 | uses: shivammathur/setup-php@v2 27 | with: 28 | php-version: ${{ matrix.php-versions }} 29 | 30 | - name: Check the PHP version 31 | run: php -v 32 | 33 | - name: Validate composer.json and composer.lock 34 | run: composer validate --strict 35 | 36 | - name: Install dependencies 37 | run: composer install --prefer-dist --no-progress 38 | 39 | - name: Run test suite 40 | run: vendor/bin/phpunit --coverage-clover=coverage.clover 41 | 42 | - name: Upload coverage to Codecov 43 | uses: codecov/codecov-action@v4-beta 44 | env: 45 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} -------------------------------------------------------------------------------- /src/Controller.php: -------------------------------------------------------------------------------- 1 | 38 | */ 39 | class Controller extends \CI_Controller 40 | { 41 | } 42 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rougin/spark-plug", 3 | "description": "Codeigniter 3 in a single variable.", 4 | "keywords": [ "codeigniter", "php", "spark-plug" ], 5 | "homepage": "https://roug.in/spark-plug/", 6 | "license": "MIT", 7 | "authors": 8 | [ 9 | { 10 | "email": "rougingutib@gmail.com", 11 | "homepage": "https://roug.in/", 12 | "name": "Rougin Gutib", 13 | "role": "Software Engineer" 14 | } 15 | ], 16 | "require": 17 | { 18 | "php": ">=5.3.0" 19 | }, 20 | "require-dev": 21 | { 22 | "phpunit/phpunit": "~4.2|~5.7|~6.0|~7.0|~8.0|~9.0", 23 | "rougin/codeigniter": "~3.0", 24 | "sanmai/phpunit-legacy-adapter": "~6.1|~8.0" 25 | }, 26 | "autoload": 27 | { 28 | "psr-4": 29 | { 30 | "Rougin\\SparkPlug\\": "src" 31 | } 32 | }, 33 | "autoload-dev": 34 | { 35 | "psr-4": 36 | { 37 | "Rougin\\SparkPlug\\": "tests" 38 | } 39 | }, 40 | "scripts": 41 | { 42 | "test": "phpunit" 43 | }, 44 | "extra": 45 | { 46 | "branch-alias": 47 | { 48 | "dev-master": "1.0-dev" 49 | } 50 | }, 51 | "suggest": 52 | { 53 | "rougin/codeigniter": "A Composer-based Codeigniter 3.", 54 | "rougin/combustor": "MVC code generator for Codeigniter 3.", 55 | "rougin/credo": "A Doctrine ORM wrapper for Codeigniter 3.", 56 | "rougin/ignite": "A Composer-based Codeigniter 3 project.", 57 | "rougin/refinery": "\"Ready-to-eat\" migrations for Codeigniter 3.", 58 | "rougin/wildfire": "A Query Builder wrapper for Codeigniter 3." 59 | } 60 | } -------------------------------------------------------------------------------- /phpstyle.php: -------------------------------------------------------------------------------- 1 | true); 11 | 12 | $cscp = 'control_structure_continuation_position'; 13 | $rules[$cscp] = ['position' => 'next_line']; 14 | 15 | $braces = array(); 16 | $braces['control_structures_opening_brace'] = 'next_line_unless_newline_at_signature_end'; 17 | $braces['functions_opening_brace'] = 'next_line_unless_newline_at_signature_end'; 18 | $braces['anonymous_functions_opening_brace'] = 'next_line_unless_newline_at_signature_end'; 19 | $braces['anonymous_classes_opening_brace'] = 'next_line_unless_newline_at_signature_end'; 20 | $braces['allow_single_line_empty_anonymous_classes'] = false; 21 | $braces['allow_single_line_anonymous_functions'] = false; 22 | $rules['braces_position'] = $braces; 23 | 24 | $visibility = array('elements' => array()); 25 | $visibility['elements'] = array('method', 'property'); 26 | $rules['visibility_required'] = $visibility; 27 | 28 | $rules['phpdoc_var_annotation_correct_order'] = true; 29 | 30 | $rules['single_quote'] = ['strings_containing_single_quote_chars' => true]; 31 | 32 | $rules['no_unused_imports'] = true; 33 | 34 | $rules['align_multiline_comment'] = true; 35 | 36 | $rules['trim_array_spaces'] = true; 37 | 38 | $order = ['case_sensitive' => true]; 39 | $order['null_adjustment'] = 'always_last'; 40 | $rules['phpdoc_types_order'] = $order; 41 | 42 | $rules['new_with_parentheses'] = ['named_class' => false]; 43 | 44 | $rules['concat_space'] = ['spacing' => 'one']; 45 | 46 | $rules['no_empty_phpdoc'] = true; 47 | 48 | $groups = []; 49 | $groups[] = ['template', 'extends']; 50 | $groups[] = ['deprecated', 'link', 'see', 'since', 'codeCoverageIgnore']; 51 | $groups[] = ['property', 'property-read', 'property-write']; 52 | $groups[] = ['method']; 53 | $groups[] = ['author', 'copyright', 'license']; 54 | $groups[] = ['category', 'package', 'subpackage']; 55 | $groups[] = ['param']; 56 | $groups[] = ['return', 'throws']; 57 | $rules['phpdoc_separation'] = ['groups' => $groups]; 58 | 59 | $align = ['align' => 'vertical']; 60 | $align['tags'] = ['method', 'param', 'property', 'throws', 'type', 'var']; 61 | $rules['phpdoc_align'] = $align; 62 | 63 | $rules['statement_indentation'] = false; 64 | 65 | $rules['align_multiline_comment'] = true; 66 | // ----------------------------------------------- 67 | 68 | $finder = new \PhpCsFixer\Finder; 69 | 70 | $finder->in((array) $paths); 71 | 72 | $config = new \PhpCsFixer\Config; 73 | 74 | $config->setRules($rules); 75 | 76 | return $config->setFinder($finder); 77 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `Spark Plug` will be documented in this file. 4 | 5 | ## [0.6.3](https://github.com/rougin/spark-plug/compare/v0.6.2...v0.6.3) - 2024-10-21 6 | 7 | ### Changed 8 | - Minimum PHP version to `v5.3.0` 9 | 10 | ## [0.6.2](https://github.com/rougin/spark-plug/compare/v0.6.1...v0.6.2) - 2024-09-29 11 | 12 | ### Added 13 | - `Controller` for type-hinting `Codeigniter 3`'s libraries 14 | 15 | ### Changed 16 | - Code documentation by `php-cs-fixer`, code quality by `phpstan` 17 | - Workflow from `Travis CI` to `Github Actions` 18 | - Code coverage from `Scrutinizer CI` to `Codecov` 19 | 20 | ## [0.6.1](https://github.com/rougin/spark-plug/compare/v0.6.0...v0.6.1) - 2018-12-11 21 | 22 | ### Added 23 | - Loaded `Output` class 24 | 25 | ## [0.6.0](https://github.com/rougin/spark-plug/compare/v0.5.0...v0.6.0) - 2018-01-12 26 | 27 | ### Added 28 | - `SparkPlug::instance` method (replaces `getCodeIgniter` method) 29 | - `SparkPlug::set` method for specifying constants manually (e.g `APPPATH`) 30 | 31 | ### Changed 32 | - Code quality (renaming all protected methods into one word) 33 | - Renamed `get_instance.php` to `helpers.php` 34 | 35 | ### Removed 36 | - `bin` directory 37 | - `CONDUCT.md` 38 | - `CONTRIBUTING.md` 39 | 40 | ## [0.5.0](https://github.com/rougin/spark-plug/compare/v0.4.4...v0.5.0) - 2016-10-23 41 | 42 | ### Changed 43 | - Code quality 44 | 45 | ## [0.4.4](https://github.com/rougin/spark-plug/compare/v0.4.3...v0.4.4) - 2016-09-10 46 | 47 | ### Added 48 | - StyleCI for conforming code to PSR standards 49 | 50 | ## [0.4.3](https://github.com/rougin/spark-plug/compare/v0.4.2...v0.4.3) - 2016-05-13 51 | 52 | ### Changed 53 | - Version of `rougin/codeigniter` to `^3.0.0` 54 | 55 | ## [0.4.2](https://github.com/rougin/spark-plug/compare/v0.4.1...v0.4.2) - 2016-05-09 56 | 57 | ### Fixed 58 | - `CI_` prefix issue when loading a library from `application/libraries` 59 | 60 | ## [0.4.1](https://github.com/rougin/spark-plug/compare/v0.4.0...v0.4.1) - 2016-04-29 61 | 62 | ### Fixed 63 | - `MB_ENABLED` issue when using `Inflector` helper 64 | 65 | ## [0.4.0](https://github.com/rougin/spark-plug/compare/v0.3.0...v0.4.0) - 2016-04-25 66 | 67 | ### Added 68 | - `Instance::create` 69 | 70 | ## [0.3.0](https://github.com/rougin/spark-plug/compare/v0.2.0...v0.3.0) - 2016-03-22 71 | 72 | ### Added 73 | - `$path` in constructor for setting test application directory (useful for unit testing) 74 | - Tests 75 | 76 | ## [0.2.0](https://github.com/rougin/spark-plug/compare/v0.1.2...v0.2.0) - 2015-10-23 77 | 78 | ### Changed 79 | - `Instance` to `SparkPlug` 80 | - Code structure 81 | 82 | ## [0.1.2](https://github.com/rougin/spark-plug/compare/v0.1.1...v0.1.2) - 2015-09-18 83 | 84 | ### Fixed 85 | - Issues on defined constants 86 | 87 | ## [0.1.1](https://github.com/rougin/spark-plug/compare/v0.1.0...v0.1.1) - 2015-09-15 88 | 89 | ### Added 90 | - Namespaces 91 | 92 | ### Changed 93 | - Documentation 94 | 95 | ## 0.1.0 - 2015-06-25 96 | 97 | ### Added 98 | - `Spark Plug` library -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spark Plug 2 | 3 | [![Latest Version on Packagist][ico-version]][link-packagist] 4 | [![Software License][ico-license]][link-license] 5 | [![Build Status][ico-build]][link-build] 6 | [![Coverage Status][ico-coverage]][link-coverage] 7 | [![Total Downloads][ico-downloads]][link-downloads] 8 | 9 | A special package that returns an application based on [Codeigniter 3](https://codeigniter.com/) as a single variable. Might be useful when testing a `Codeigniter 3` project to frameworks such as [PHPUnit](https://phpunit.de/). 10 | 11 | ## Installation 12 | 13 | Install `Spark Plug` through [Composer](https://getcomposer.org/): 14 | 15 | ``` bash 16 | $ composer require rougin/spark-plug 17 | ``` 18 | 19 | ## Basic Usage 20 | 21 | ### Using the `Instance` helper 22 | 23 | ``` php 24 | $ci = Rougin\SparkPlug\Instance::create(); 25 | 26 | // You can now use the CI_Controller instance 27 | $ci->load->helper('inflector'); 28 | ``` 29 | 30 | > [!NOTE] 31 | > Instead of `CI_Controller`, it returns `Rougin\SparkPlug\Controller` for type-hinting its helpers and libraries. 32 | 33 | ### Using the `SparkPlug` class 34 | 35 | ``` php 36 | use Rougin\SparkPlug\SparkPlug; 37 | 38 | $sparkplug = new SparkPlug($GLOBALS, $_SERVER); 39 | 40 | $ci = $sparkplug->instance(); 41 | 42 | // The Inflector helper is now loaded --- 43 | $ci->load->helper('inflector'); 44 | // -------------------------------------- 45 | ``` 46 | 47 | ### Modify constants to be defined 48 | 49 | ``` php 50 | use Rougin\SparkPlug\SparkPlug; 51 | 52 | $sparkplug = new SparkPlug($GLOBALS, $_SERVER); 53 | 54 | // Set the value of the APPPATH constant --- 55 | $sparkplug->set('APPPATH', '/path/to/app'); 56 | // ----------------------------------------- 57 | 58 | $ci = $sparkplug->instance(); 59 | ``` 60 | 61 | Available constants that can be modified: 62 | 63 | * `APPPATH` 64 | * `VENDOR` 65 | * `VIEWPATH` 66 | 67 | > [!NOTE] 68 | > If setting a new `APPPATH` value, the value of `VIEWPATH` will be set to `APPPATH/views`. 69 | 70 | ### Mock `CI_Controller` for unit testing 71 | 72 | ``` php 73 | use Rougin\SparkPlug\Instance; 74 | 75 | class SampleTest extends \PHPUnit_Framework_TestCase 76 | { 77 | public function testCodeigniterInstance() 78 | { 79 | // Directory path to the test application 80 | $application = __DIR__ . '/TestApp'; 81 | 82 | // Instance::create($path, $_SERVER, $GLOBALS) 83 | $ci = Instance::create($application); 84 | 85 | $this->assertInstanceOf('CI_Controller', $ci); 86 | } 87 | } 88 | ``` 89 | 90 | ## Changelog 91 | 92 | Please see [CHANGELOG][link-changelog] for more information what has changed recently. 93 | 94 | ## Testing 95 | 96 | ``` bash 97 | $ composer test 98 | ``` 99 | 100 | ## Credits 101 | 102 | - [All contributors][link-contributors] 103 | 104 | ## License 105 | 106 | The MIT License (MIT). Please see [LICENSE][link-license] for more information. 107 | 108 | [ico-build]: https://img.shields.io/github/actions/workflow/status/rougin/spark-plug/build.yml?style=flat-square 109 | [ico-coverage]: https://img.shields.io/codecov/c/github/rougin/spark-plug?style=flat-square 110 | [ico-downloads]: https://img.shields.io/packagist/dt/rougin/spark-plug.svg?style=flat-square 111 | [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square 112 | [ico-version]: https://img.shields.io/packagist/v/rougin/spark-plug.svg?style=flat-square 113 | 114 | [link-build]: https://github.com/rougin/spark-plug/actions 115 | [link-changelog]: https://github.com/rougin/spark-plug/blob/master/CHANGELOG.md 116 | [link-contributors]: https://github.com/rougin/spark-plug/contributors 117 | [link-coverage]: https://app.codecov.io/gh/rougin/spark-plug 118 | [link-downloads]: https://packagist.org/packages/rougin/spark-plug 119 | [link-license]: https://github.com/rougin/spark-plug/blob/master/LICENSE.md 120 | [link-packagist]: https://packagist.org/packages/rougin/spark-plug -------------------------------------------------------------------------------- /src/SparkPlug.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class SparkPlug 11 | { 12 | /** 13 | * @var array 14 | */ 15 | protected $consts = array(); 16 | 17 | /** 18 | * @var array 19 | */ 20 | protected $globals = array(); 21 | 22 | /** 23 | * @var array 24 | */ 25 | protected $server = array(); 26 | 27 | /** 28 | * @param array $globals 29 | * @param array $server 30 | * @param string|null $root 31 | */ 32 | public function __construct(array $globals, array $server, $root = null) 33 | { 34 | $this->globals = & $globals; 35 | 36 | /** @var string */ 37 | $root = $root ? $root : getcwd(); 38 | 39 | $this->server = $server; 40 | 41 | $app = ((string) realpath($root)) . '/'; 42 | 43 | if (is_dir($root . '/application')) 44 | { 45 | $app = $root . '/application/'; 46 | } 47 | 48 | $this->consts['APPPATH'] = $app; 49 | 50 | $this->consts['ENVIRONMENT'] = 'development'; 51 | 52 | $this->consts['VIEWPATH'] = $app . 'views/'; 53 | 54 | $this->consts['VENDOR'] = $root . '/vendor/'; 55 | } 56 | 57 | /** 58 | * @deprecated since ~0.6, use "instance" instead. 59 | * 60 | * Returns the Codeigniter singleton. 61 | * 62 | * @return \Rougin\SparkPlug\Controller 63 | */ 64 | public function getCodeIgniter() 65 | { 66 | return $this->instance(); 67 | } 68 | 69 | /** 70 | * Returns the Codeigniter singleton. 71 | * 72 | * @return \Rougin\SparkPlug\Controller 73 | */ 74 | public function instance() 75 | { 76 | $this->setPaths(); 77 | 78 | $this->environment($this->consts['ENVIRONMENT']); 79 | 80 | $this->constants(); 81 | 82 | $this->common(); 83 | 84 | $this->config(); 85 | 86 | require 'helpers.php'; 87 | 88 | /** @var \Rougin\SparkPlug\Controller|null */ 89 | $instance = Controller::get_instance(); 90 | 91 | if (empty($instance)) 92 | { 93 | $instance = new Controller; 94 | } 95 | 96 | return $instance; 97 | } 98 | 99 | /** 100 | * Sets the constant with a value. 101 | * 102 | * @param string $key 103 | * @param string $value 104 | * 105 | * @return self 106 | */ 107 | public function set($key, $value) 108 | { 109 | $this->consts[$key] = $value; 110 | 111 | $path = $this->consts[$key] . '/views/'; 112 | 113 | if ($key === 'APPPATH') 114 | { 115 | $this->consts['VIEWPATH'] = $path; 116 | } 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * Sets the base path. 123 | * 124 | * @return void 125 | */ 126 | protected function basepath() 127 | { 128 | $path = (string) getcwd(); 129 | 130 | $path = new \RecursiveDirectoryIterator($path); 131 | 132 | /** @var \SplFileInfo[] */ 133 | $items = new \RecursiveIteratorIterator($path); 134 | 135 | $slash = DIRECTORY_SEPARATOR; 136 | 137 | foreach ($items as $item) 138 | { 139 | $core = 'core' . $slash . 'CodeIgniter.php'; 140 | 141 | $path = $item->getPathname(); 142 | 143 | $exists = strpos($path, $core) !== false; 144 | 145 | $path = str_replace($core, '', $path); 146 | 147 | if ($exists && ! defined('BASEPATH')) 148 | { 149 | define('BASEPATH', (string) $path); 150 | } 151 | } 152 | } 153 | 154 | /** 155 | * Sets up important charset-related stuff. 156 | * 157 | * @return void 158 | */ 159 | protected function charset() 160 | { 161 | /** @var string */ 162 | $charset = config_item('charset'); 163 | 164 | $charset = strtoupper($charset); 165 | 166 | ini_set('default_charset', $charset); 167 | 168 | if (! defined('MB_ENABLED')) 169 | { 170 | define('MB_ENABLED', extension_loaded('mbstring')); 171 | } 172 | 173 | $encoding = 'mbstring.internal_encoding'; 174 | 175 | if (! is_php('5.6') && ! ini_get($encoding)) 176 | { 177 | ini_set($encoding, $charset); 178 | } 179 | 180 | $this->iconv(); 181 | } 182 | 183 | /** 184 | * Loads the Common and the Base Controller class. 185 | * 186 | * @return void 187 | */ 188 | protected function common() 189 | { 190 | require BASEPATH . 'core/Common.php'; 191 | 192 | if (! class_exists('CI_Controller')) 193 | { 194 | require BASEPATH . 'core/Controller.php'; 195 | } 196 | 197 | $this->charset(); 198 | } 199 | 200 | /** 201 | * Sets global configurations. 202 | * 203 | * @return void 204 | */ 205 | protected function config() 206 | { 207 | /** @var string */ 208 | $config = load_class('Config', 'core'); 209 | 210 | $this->globals['CFG'] = & $config; 211 | 212 | /** @var string */ 213 | $utf8 = load_class('Utf8', 'core'); 214 | 215 | $this->globals['UNI'] = & $utf8; 216 | 217 | /** @var string */ 218 | $security = load_class('Security', 'core'); 219 | 220 | $this->globals['SEC'] = & $security; 221 | 222 | $this->core(); 223 | } 224 | 225 | /** 226 | * Loads the framework constants. 227 | * 228 | * @return void 229 | */ 230 | protected function constants() 231 | { 232 | $config = APPPATH . 'config/'; 233 | 234 | $consts = $config . ENVIRONMENT . '/constants.php'; 235 | 236 | $filename = $config . 'constants.php'; 237 | 238 | if (file_exists($consts)) 239 | { 240 | $filename = $consts; 241 | } 242 | 243 | if (! defined('FILE_READ_MODE')) 244 | { 245 | require $filename; 246 | } 247 | } 248 | 249 | /** 250 | * Loads the CodeIgniter's core classes. 251 | * 252 | * @return void 253 | */ 254 | protected function core() 255 | { 256 | load_class('Loader', 'core'); 257 | 258 | load_class('Router', 'core'); 259 | 260 | load_class('Input', 'core'); 261 | 262 | load_class('Lang', 'core'); 263 | 264 | load_class('Output', 'core'); 265 | } 266 | 267 | /** 268 | * Sets up the current environment. 269 | * 270 | * @param string $value 271 | * 272 | * @return void 273 | */ 274 | protected function environment($value = 'development') 275 | { 276 | if (isset($this->server['CI_ENV'])) 277 | { 278 | $value = $this->server['CI_ENV']; 279 | } 280 | 281 | if (! defined('ENVIRONMENT')) 282 | { 283 | define('ENVIRONMENT', $value); 284 | } 285 | } 286 | 287 | /** 288 | * Sets the ICONV constants. 289 | * 290 | * @param boolean $enabled 291 | * 292 | * @return void 293 | */ 294 | protected function iconv($enabled = false) 295 | { 296 | if (mb_substitute_character('none') === true) 297 | { 298 | $enabled = defined('ICONV_ENABLED'); 299 | } 300 | 301 | if (! $enabled) 302 | { 303 | define('ICONV_ENABLED', extension_loaded('iconv')); 304 | } 305 | } 306 | 307 | /** 308 | * Sets up the APPPATH, VENDOR, and BASEPATH constants. 309 | * 310 | * @return void 311 | */ 312 | protected function setPaths() 313 | { 314 | $paths = array('APPPATH' => $this->consts['APPPATH']); 315 | 316 | $paths['VENDOR'] = $this->consts['VENDOR']; 317 | 318 | $paths['VIEWPATH'] = $this->consts['VIEWPATH']; 319 | 320 | foreach ($paths as $key => $value) 321 | { 322 | if (! defined($key)) 323 | { 324 | define($key, $value); 325 | } 326 | } 327 | 328 | if (! defined('BASEPATH')) 329 | { 330 | $this->basepath(); 331 | } 332 | } 333 | } 334 | --------------------------------------------------------------------------------