From 1ce63e3e87d9b1fd93cf0c9daccef8b03f03c368 Mon Sep 17 00:00:00 2001 From: Rougin Gutib Date: Mon, 9 May 2016 13:58:41 +0800 Subject: [PATCH] Fix "CI_" prefix issue when loading a custom library --- CHANGELOG.md | 9 +++++++-- CONDUCT.md | 22 ++++++++++++++++++++++ README.md | 6 +++--- src/SparkPlug.php | 23 ++++++++++++----------- 4 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 CONDUCT.md diff --git a/CHANGELOG.md b/CHANGELOG.md index ba45cf5..488d7e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -All Notable changes to `Spark Plug` will be documented in this file +All Notable changes to `Spark Plug` will be documented in this file. + +## [0.4.2](https://github.com/rougin/spark-plug/compare/v0.4.1...v0.4.2) - 2016-05-09 + +### Fixed +- `CI_` prefix issue when loading a library from `application/libraries` ## [0.4.1](https://github.com/rougin/spark-plug/compare/v0.4.0...v0.4.1) - 2016-04-29 @@ -40,4 +45,4 @@ All Notable changes to `Spark Plug` will be documented in this file ## 0.1.0 - 2015-06-25 ### Added -- `Spark Plug` library \ No newline at end of file +- `Spark Plug` library diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 0000000..6ff94ca --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,22 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, such as physical or electronic addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community in a direct capacity. Personal views, beliefs and values of individuals do not necessarily reflect those of the organisation or affiliated individuals and organisations. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/README.md b/README.md index 23b5740..49cd53d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Quality Score][ico-code-quality]][link-code-quality] [![Total Downloads][ico-downloads]][link-downloads] -Another way to access [CodeIgniter](https://codeigniter.com/)'s instance +Obtains an instance of [CodeIgniter](https://codeigniter.com/) gracefully. ## Install @@ -51,7 +51,7 @@ class SparkPlugTest extends \PHPUnit_Framework_TestCase } ``` -**NOTE**: To create a mock instance, [rougin/codeigniter](https://github.com/rougin/codeigniter) and a test application directory are required. Kindly check the [tests](https://github.com/rougin/spark-plug/tree/master/tests) directory for more examples. +**NOTE**: To create a mock instance, a [rougin/codeigniter](https://github.com/rougin/codeigniter) package and a test application directory are required. Kindly check the [tests](https://github.com/rougin/spark-plug/tree/master/tests) directory for more examples. ## Change Log @@ -65,7 +65,7 @@ $ composer test ## Contributing -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. +Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details. ## Security diff --git a/src/SparkPlug.php b/src/SparkPlug.php index ad99fbd..4832069 100644 --- a/src/SparkPlug.php +++ b/src/SparkPlug.php @@ -42,21 +42,21 @@ public function __construct(array &$globals, array $server, $path = '') $this->globals =& $globals; $this->server = $server; $this->path = $path; - - $this->setPaths(); - $this->setEnvironment(); - $this->loadConstants(); - $this->loadClasses(); - $this->setCharSet(); } /** * Returns a CodeIgniter instance. * - * @return CodeIgniter + * @return \CI_Controller */ public function getCodeIgniter() { + $this->setPaths(); + $this->setEnvironment(); + $this->loadConstants(); + $this->loadClasses(); + $this->setCharSet(); + // Sets global configurations $this->globals['CFG'] =& load_class('Config', 'core'); $this->globals['UNI'] =& load_class('Utf8', 'core'); @@ -71,7 +71,9 @@ public function getCodeIgniter() // Loads the get_instance.php for loading libraries require 'get_instance.php'; - return new CI_Controller; + $ci = CI_Controller::get_instance(); + + return (empty($ci)) ? new CI_Controller : $ci; } /** @@ -191,9 +193,8 @@ protected function setPaths() return; } - $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator(getcwd()) - ); + $directory = new RecursiveDirectoryIterator(getcwd()); + $iterator = new RecursiveIteratorIterator($directory); foreach ($iterator as $file) { $core = 'core' . DIRECTORY_SEPARATOR . 'CodeIgniter.php';