Skip to content

Commit

Permalink
Fix "CI_" prefix issue when loading a custom library
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed May 9, 2016
1 parent 2f880c9 commit 1ce63e3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
- `Spark Plug` library
22 changes: 22 additions & 0 deletions CONDUCT.md
Original file line number Diff line number Diff line change
@@ -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/)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
23 changes: 12 additions & 11 deletions src/SparkPlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 1ce63e3

Please sign in to comment.