final class IPF
{
- public static function run($project_root, $document_root)
+ public static function boot($project_root, $document_root)
{
- IPF::configure($project_root, $document_root);
+ $settings = IPF::configure($project_root, $document_root);
+ $container = self::createContainer($settings);
+ self::run($container);
+ }
+ /**
+ * @param IPF_Settings $settings
+ * @return Container
+ */
+ public static function createContainer(IPF_Settings $settings)
+ {
$container = new Container();
-
$container['ipf_version'] = '0.7';
- $container['settings'] = IPF::$settings;
+ $container['settings'] = $settings;
$container->register(new BootstrapProvider());
+ self::$container = $container;
+ return $container;
+ }
- if (IPF::get('debug')) {
- error_reporting(E_ALL);
- }
-
+ /**
+ * @param Container $container
+ */
+ private static function run(Container $container)
+ {
if (php_sapi_name() === 'cli') {
$container['cli']->run();
} else {
}
}
- /** @var IPF_Settings */
- public static $settings = null;
-
private static function checkSettings(IPF_Settings $settings)
{
$db = $settings->get('database');
die('Specify site url routes');
}
+ /**
+ * @param string $project_root
+ * @param string $document_root
+ * @return IPF_Settings
+ */
public static function configure($project_root, $document_root)
{
$project_root = realpath($project_root);
$document_root = realpath($document_root);
- self::$settings = IPF_Settings::create()
+ $settings = IPF_Settings::create()
->apply(array(
'app_base' => '',
'debug' => false,
->applyFile($project_root.'/project/settings.php')
->tryApplyFile($project_root.'/project/settings_local.php');
- self::checkSettings(self::$settings);
+ IPF::checkSettings($settings);
+
+ if ($settings->get('debug')) {
+ error_reporting(E_ALL);
+ }
- date_default_timezone_set(self::$settings->get('time_zone'));
+ date_default_timezone_set($settings->get('time_zone'));
+
+ return $settings;
}
private function __construct() {}
+
private function __clone() {}
+ /** @var Container */
+ private static $container;
+
public static function get($name, $default=null)
{
- return self::$settings->get($name, $default);
+ return self::$container['settings']->get($name, $default);
}
public static function getUploadPath()
{
public function testApps()
{
- $apps = IPF_Project::getInstance()->appList();
- $this->assertEquals(array('IPF_Session', 'IPF_Auth', 'IPF_Admin'), array_keys($apps));
+ $container = (new ProjectMock())->createProject();
+
+ $apps = $container['apps'];
+ $this->assertEquals(array('session', 'auth', 'admin'), array_keys($apps));
}
public function testMiddlewares()
{
+ $container = (new ProjectMock())->createProject();
+
$middlewares = array();
- $middleware = $this->callMethod(IPF_Project::getInstance(), 'chainMiddlewares');
+ $middleware = $container['pipeline'];
while ($middleware != null) {
$middlewares[] = $middleware;
$middleware = $this->getProperty($middleware, 'next');
$property->setAccessible(true);
return $property->getValue($obj);
}
-
- protected function callMethod($obj, $method, $args=array())
- {
- $cls = new ReflectionClass($obj);
- $method = $cls->getMethod($method);
- $method->setAccessible(true);
- return $method->invokeArgs($obj, $args);
- }
}