public function __construct() { $this->setBag(Container::getInstance()); if ($this->getBag()->has('eventManager') && static::class != 'Mizzencms\\Core\\EventManager') { $this->triggerEvent('construct' . ucfirst(StringHelper::toCamelCase(get_class($this), '\\')), array('class' => $this)); } /** * BC break, withheld */ // $this->init(); }
public function setUp() { $this->bag = Container::getInstance(); }
/** * @todo redo * @param Directory $basePath */ public function init(\Directory $basePath) { /** * @todo create a default bag and only override if something * special needed */ $bag = Container::getInstance(); $bag->add('basePath', function () use($basePath) { return $basePath; }); /** * @todo move to config class and create a set up */ $bag->add('config', function () use($basePath) { $configPath = $basePath->path . '/config/config.json'; if (is_readable($configPath)) { $config = ArrayHelper::configArrayToObject(json_decode(file_get_contents($configPath), true)); if (!isset($config->baseDir)) { $config->baseDir = ''; } } else { $config = new \StdClass(); $config->url = isset($_SERVER['SERVER_NAME']) ? 'http://' . $_SERVER['SERVER_NAME'] . '/' : 'http://mizzencms.net/'; $config->siteName = 'MizzenLite'; $config->baseDir = ''; } return $config; }); $bag->add('url', function () use($bag) { $url = Url::createFromServer($_SERVER); /** * Remove index.php if exists */ $url->getPath()->remove('index.php'); /** * remove base dir (for when we are installed in a dir) */ if (!empty($bag->get('config')->baseDir)) { $url->getPath()->remove($bag->get('config')->baseDir); } /** * home needs to be converted to index */ if ((string) $url->getPath() === '') { $url->setPath('index'); } return $url; }); $bag->add('metaParser', function () { return new MetaParser(); }); $bag->add('pageRepository', function () { $prp = new PageRepositoryGenerator(new PageRepository(), new Finder()); $prp->populateRepository(); return $prp->getPageRepository(); }); $bag->add('navigation', function () { return (new Navigation())->createPageMenu(); }); $bag->add('eventManager', function () { return new EventManager(); }); $bag->add('view', function () { return new View(); }); }