<?php /** * A configuration file for DI containers */ namespace Tinker; ///// Application Plugin ////// Di\IoCRegistry::register('ApplicationController', function () use($Router, $Theme, $view) { $plugin = $Router->getPlugin(true); $model = $Router->getPlugin(true); $controller = $Router->getController(true) . 'Controller'; $class = "\\{$plugin}\\Controller\\{$controller}"; $model = "\\{$plugin}\\Model\\{$model}"; $controller = new $class($Theme, $view); $controller->inject(new $model()); return $controller; }); ///// Custom Containers //////
//Load and instantiate, loader and register the auto loader. require 'vendor' . DS . 'PhpFig' . DS . 'src' . DS . 'Loader.php'; $Loader = new \PhpFig\Loader(); $Loader->register(); //Autoload all files in the Tinker namespace $Loader->addNamespace("\\MvcInterface", 'Tinker' . DS . 'src' . DS . 'Mvc' . DS . 'Interfaces'); //Autoload all files in the Tinker namespace $Loader->addNamespace("\\Tinker", 'Tinker' . DS . 'src'); //Load the runtime configuration require 'configure.php'; //Router Di\IoCRegistry::register('Router', function () { $Router = new Mvc\Router('/tinker_plugin/tinker_plugin/index/e1/e2/e3/e4:1'); return $Router; }); $Router = Di\IoCRegistry::resolve('Router'); //View Di\IoCRegistry::register('View', function () use($Router, $BuildTime, $Loader) { $view = new Mvc\View($Router, $BuildTime, $Loader); return $view; }); $view = Di\IoCRegistry::resolve('View'); //Theme Di\IoCRegistry::register('Theme', function () use($Router, $view, $Loader) { $view = new \Tinker\Mvc\Theme($Router, $view, $Loader); return $view; }); $Theme = Di\IoCRegistry::resolve('Theme'); //Load custom containers require 'containers.php';
///// Application Plugin ////// Di\IoCRegistry::register('ApplicationController', function () use($Router, $Theme, $View) { $plugin = $Router->getPlugin(true); $model = $Router->getPlugin(true); $controller = $Router->getController(true) . 'Controller'; $class = "\\{$plugin}\\Controller\\{$controller}"; $Model = "\\{$plugin}\\Model\\{$model}"; $Controller = new $class($Theme, $View); $Controller->inject(new $Model()); return $Controller; }); ///// Custom Containers ////// Di\IoCRegistry::register('PostsController', function () use($Theme, $View) { $Controller = new \Content\Controller\PostsController($Theme, $View); $config = Configure::read(); $Controller->inject(new \Content\Model\Post($config)); return $Controller; }); Di\IoCRegistry::register('PagesController', function () use($Theme, $View) { $Controller = new \Content\Controller\PagesController($Theme, $View); return $Controller; }); Di\IoCRegistry::register('ToolsController', function () use($Theme, $View, $Loader) { //Autoload the Jsc lib $Loader->addNamespace("\\Jsc", APP . DS . 'vendor' . DS . 'Jsc' . DS . 'src'); $Controller = new \Tools\Controller\ToolsController($Theme, $View); $Controller->inject(new \Jsc\Jibirish()); $Controller->inject(new \Jsc\Security()); return $Controller; });