-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 69dca3c
Showing
5 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Rougin Gutib | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Spark Plug | ||
|
||
Another way to access CodeIgniter's instance | ||
|
||
# Installation | ||
|
||
Install ```Spark Plug``` via [Composer](https://getcomposer.org): | ||
|
||
```$ composer require rougin/spark-plug``` | ||
|
||
# Why | ||
|
||
The purpose of this library is to provide an access to the CodeIgniter's instance that is based on this [link](codeinphp.github.io/post/codeigniter-tip-accessing-codeigniter-instance-outside/). I just created a [Composer](https://getcomposer.org/) package for easy access. This may help you in developing libraries for CodeIgniter that does not go through ```index.php```. | ||
|
||
I used this package as a dependency for [Combustor](https://github.com/rougin/combustor) and [Refinery](https://github.com/rougin/refinery). | ||
|
||
# Getting Started | ||
|
||
```php | ||
require 'vendor/autoload.php'; | ||
|
||
use Rougin\SparkPlug\Instance; | ||
|
||
$instance = new Instance(); | ||
$codeigniter = $instance->get(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "rougin/spark-plug", | ||
"description": "Another way to access CodeIgniter's instance", | ||
"keywords": ["codeigniter", "instance", "php"], | ||
"require": { | ||
"php": ">=5.3.0" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Rougin Gutib", | ||
"email": "rougingutib@gmail.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Rougin\\SparkPlug\\": "src/" | ||
} | ||
}, | ||
"suggest": { | ||
"rougin/codeigniter": "Yet another way to install CodeIgniter via Composer", | ||
"rougin/combustor": "A tool for speeding up web development in CodeIgniter", | ||
"rougin/refinery": "A command line interface for Migrations Class in CodeIgniter" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
function &get_instance() | ||
{ | ||
return \CI_Controller::get_instance(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php namespace Rougin\SparkPlug; | ||
|
||
/** | ||
* Instance Class | ||
* | ||
* @package SparkPlug | ||
* @author Rougin Royce Gutib <rougingutib@gmail.com> | ||
*/ | ||
class Instance | ||
{ | ||
|
||
/** | ||
* Set some definitions and load required classes | ||
*/ | ||
public function __construct() | ||
{ | ||
/** | ||
* Define the APPPATH, VENDOR, and BASEPATH paths | ||
*/ | ||
|
||
if ( ! defined('VENDOR')) { | ||
define('VENDOR', realpath('vendor') . '/'); | ||
} | ||
|
||
define('APPPATH', realpath('application') . '/'); | ||
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); | ||
define('VIEWPATH', APPPATH . '/views/'); | ||
|
||
/** | ||
* Search for the directory and defined it as the BASEPATH | ||
*/ | ||
|
||
$directory = new \RecursiveDirectoryIterator(getcwd(), \FilesystemIterator::SKIP_DOTS); | ||
$slash = (strpos(PHP_OS, 'WIN') !== FALSE) ? '\\' : '/'; | ||
|
||
foreach (new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST) as $path) { | ||
if (strpos($path->__toString(), 'core' . $slash . 'CodeIgniter.php') !== FALSE) { | ||
$basepath = str_replace('core' . $slash . 'CodeIgniter.php', '', $path->__toString()); | ||
define('BASEPATH', $basepath); | ||
|
||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Load the Common and Base Controller class | ||
*/ | ||
|
||
require BASEPATH . 'core/Common.php'; | ||
require BASEPATH . 'core/Controller.php'; | ||
|
||
/** | ||
* Load the framework constants | ||
*/ | ||
|
||
if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/constants.php')) { | ||
require APPPATH . 'config/' . ENVIRONMENT . '/constants.php'; | ||
} else { | ||
require APPPATH . 'config/constants.php'; | ||
} | ||
|
||
/** | ||
* Important charset-related stuff | ||
*/ | ||
|
||
$charset = strtoupper(config_item('charset')); | ||
ini_set('default_charset', $charset); | ||
|
||
if (extension_loaded('mbstring')) { | ||
define('MB_ENABLED', TRUE); | ||
// mbstring.internal_encoding is deprecated starting with PHP 5.6 | ||
// and it's usage triggers E_DEPRECATED messages. | ||
@ini_set('mbstring.internal_encoding', $charset); | ||
// This is required for mb_convert_encoding() to strip invalid characters. | ||
// That's utilized by CI_Utf8, but it's also done for consistency with iconv. | ||
mb_substitute_character('none'); | ||
} else { | ||
define('MB_ENABLED', FALSE); | ||
} | ||
|
||
// There's an ICONV_IMPL constant, but the PHP manual says that using | ||
// iconv's predefined constants is "strongly discouraged". | ||
if (extension_loaded('iconv')) { | ||
define('ICONV_ENABLED', TRUE); | ||
// iconv.internal_encoding is deprecated starting with PHP 5.6 | ||
// and it's usage triggers E_DEPRECATED messages. | ||
@ini_set('iconv.internal_encoding', $charset); | ||
} else { | ||
define('ICONV_ENABLED', FALSE); | ||
} | ||
|
||
if (is_php('5.6')) { | ||
ini_set('php.internal_encoding', $charset); | ||
} | ||
|
||
/** | ||
* Set global configurations | ||
*/ | ||
|
||
$GLOBALS['CFG'] = & load_class('Config', 'core'); | ||
$GLOBALS['UNI'] = & load_class('Utf8', 'core'); | ||
$GLOBALS['SEC'] = & load_class('Security', 'core'); | ||
|
||
/** | ||
* Load the CodeIgniter's core classes | ||
*/ | ||
|
||
load_class('Loader', 'core'); | ||
load_class('Router', 'core'); | ||
load_class('Input', 'core'); | ||
load_class('Lang', 'core'); | ||
} | ||
|
||
/** | ||
* Get the instance of CodeIgniter | ||
* | ||
* @return CodeIgniter | ||
*/ | ||
public function get() | ||
{ | ||
require 'GetInstance.php'; | ||
|
||
return new \CI_Controller(); | ||
} | ||
|
||
} |