<?php
class Services
{
protected $services = [];
public function getService($id, callback $creator)
{
// Нет в кэше? Берём из creator'а
// Возвращаем кэш
}
}
class Framework extends Services
{
protected $instance = null;
public function __construct()
{
// Что-то
}
public static function getInstance()
{
if (is_null(static::$instance)) {
throw new \Exception('Не инициализировано');
}
return static::$instance;
}
public static function getRouter()
{
return static::getInstance()->getService('framework.router', function() use ($something) {
return new Router($something);
})
}
public static function init()
{
static::$instance = new static;
}
public function run()
{
// Маршрутизация => Контроллер => Выполнение Response
}
}
class CMS extends Framework
{
public static function getModulesManager()
{
return static::getInstance()->getService('cms.modulesmanager', function() use ($a, $b, $c) {
return new ModulesManager($a, $b, $c)
}
}
public function run()
{
// Маршрутизация => Встроенные контроллеры/Модули => Выполнение Response
}
}
// based on framework
Framework::init() && Framework::run();
// based on CMS
CMS::init() && CMS::run();