Giter Site home page Giter Site logo

stackci's Introduction

Codeigniter stackPHP(HttpKernelInterface) Implementation

Latest Stable Version Total 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:

use StackCI\Application as CIApplication;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

require_once __DIR__.'/vendor/autoload.php';

$session = new Session();
$session->start();

$request = Request::createFromGlobals();
$request->setSession($session);


$ciApp = (new CIApplication(__DIR__, 'development'))->init();

$app = (new Stack\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 here

        define('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 = (new CIApplication(__DIR__, 'development'))
    ->beforeKernelLoad(function(){
        //load Datamapper's bootstrap
        require_once APPPATH.'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.

stackci's People

Contributors

lightsuner avatar

Stargazers

Andrew Smith avatar Rodrigo Cosme avatar Tom Kita avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.