-
-
Save samayo/bc4e77cf96bd64285aca to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* foo | A fast PHP microframework | |
* | |
* @author Sim. Daniel <samayo@gmail.com> | |
* @link https://github.com/foo/foo | |
* @copyright Copyright (c) 2013 SD | |
* @license http://www.opensource.org/licenses/mit-license.html MIT License | |
*/ | |
namespace foo; | |
/** | |
* A Container Class | |
* | |
* @category foo | |
* @package Container | |
* @version 0.1.0 | |
*/ | |
use foo\Request; | |
use foo\Response; | |
use foo\Router; | |
use foo\Session; | |
use foo\Database; | |
use foo\Template; | |
use foo\Autolog as Autolog; | |
class Container implements \ArrayAccess{ | |
private $container = array(); | |
public function boot(){ | |
$this['route'] = $this->store(function(){ | |
return new Router; | |
}); | |
$this['view'] = $this->store(function($conf){ | |
return new Template($conf['path'], $this); | |
}); | |
$this['request'] = $this->store(function(){ | |
return new Request( | |
$_GET, $_POST, $_FILES, $_SERVER, $_COOKIE | |
); | |
}); | |
$this['response'] = $this->store(function(){ | |
return new Response(); | |
}); | |
$this['session'] = $this->store(function($conf){ | |
return new Session($conf['session']); | |
}); | |
} | |
public function offsetUnset($offset){} | |
public function offsetGet($offset){ | |
if(array_key_exists($offset, $this->container)){ | |
return $this->container[$offset]; | |
} | |
} | |
public function offsetExists($offset){ | |
return array_key_exists($id, $this->container); | |
} | |
public function offsetSet($offset, $value){ | |
$this->container[$offset] = $value; | |
} | |
public function store(Callable $callable){ | |
return function () use ($callable){ | |
static $object; | |
if(null == $object){ | |
$object = $callable($this->container); | |
} | |
return $object; | |
}; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment