Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

17 Commits

Repository files navigation

Codeigniter stackPHP(HttpKernelInterface) Implementation

Latest Stable VersionTotal Downloads

StackPHP

##About This is a wrapper for Codeigniter. It implements HttpKernelInterface that allows you to use Codeigniter with other frameworks using StackPHP.

This implementation has got much dirty code. I would be glad if you help clean it.

##Install

Add stack-codeigniter in your composer.json:

{
"require": {
"lightsuner/stack-codeigniter": "dev-develop"
}
}

Now tell composer to download the component by running the command:

$ php composer.phar update lightsuner/stack-codeigniter

Composer will install the component to your project's vendor/lightsuner directory.

##Usage

Replace index.php with this:

useStackCI\ApplicationasCIApplication;
useSymfony\Component\HttpFoundation\Request;
useSymfony\Component\HttpFoundation\Session\Session;
require_once__DIR__.'/vendor/autoload.php';
$session = newSession();
$session->start();
$request = Request::createFromGlobals();
$request->setSession($session);
$ciApp = (newCIApplication(__DIR__, 'development'))->init();
$app = (newStack\Builder())
->resolve($ciApp);
$response = $app->handle($request);
$response->send();
$app->terminate($request, $response);

You can also execute some code before Codeigniter will initialized. Use StackCI\Application::beforeKernelLoad():

$ciApp = (new \StackCI\Application(__DIR__, 'development'))
->beforeKernelLoad(function(){
//... some code goes heredefine('PUBPATH', FCPATH."public");
if( ! ini_get('date.timezone')) {
date_default_timezone_set('GMT');
}
//... some other code
})
->init();

Use with WanWizard's datamapper:

To make it work correctly you should add STACKCIEXTPATH to third_party/datamapper/bootstrap.php

....
if ( ! function_exists('load_class'))
{
function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
......
foreach (array(STACKCIEXTPATH, BASEPATH, APPPATH) as$path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
$name = $prefix.$class;
if (class_exists($name) === FALSE)
{
require($path.$directory.'/'.$class.'.php');
}
break;
}
}
.....

and then load datamapper's bootstrap

$ciApp = (newCIApplication(__DIR__, 'development'))
->beforeKernelLoad(function(){
//load Datamapper's bootstraprequire_onceAPPPATH.'third_party/datamapper/bootstrap.php';
})
->init();

##Details

There is a BaseApplication and two folders - Ext and Orig.

  1. BaseApplication do the same thing than default Codeigniters's index.php - load and run Kernel.
  2. Orig contains original files of Codeigniter such as Router, Input, Output, Loader and etc.
  3. Ext contains extended files

####New functional: Libraries/Session - new method migrate:

$this->session->migrate($destroy, $lifetime);

Core/Input - new method getRequest:

$this->input->getRequest();

##Advices

  • Use LazyHttpKernel to use stack-codeigniter in conjunction with other frameworks through stackPHP.

About

StackPHP implementation for CodeIgniter 2

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages