/** * The constructor * * @throws \Exception */ public function __construct() { if (self::$instance !== null) { throw new \Exception('App already constructed'); } self::$instance =& $this; $this->container = new App\Container(); $this->container->set('app.config', App\Config::class); $this->container->set('app.request', App\Request::class); $this->container->set('app.routes', App\Routes::class); $this->container->set('app.logger', App\Logger::class); $this->container->set('app.addons', App\Addons::class); $this->container->set('app.hooks', App\Hooks::class); $this->container->set('app.assets', App\Assets::class); $this->container->set('app.data', App\Data::class); $this->container->set('app.cache', App\Cache::class); $this->container->set('app.classes', App\Classes::class); $this->container->set('app.urls', App\Urls::class); $this->container->set('app.images', App\Images::class); $this->defineProperty('config', ['get' => function () { return $this->container->get('app.config'); }, 'readonly' => true]); $this->defineProperty('request', ['get' => function () { return $this->container->get('app.request'); }, 'readonly' => true]); $this->defineProperty('routes', ['get' => function () { return $this->container->get('app.routes'); }, 'readonly' => true]); $this->defineProperty('logger', ['get' => function () { return $this->container->get('app.logger'); }, 'readonly' => true]); $this->defineProperty('addons', ['get' => function () { return $this->container->get('app.addons'); }, 'readonly' => true]); $this->defineProperty('hooks', ['get' => function () { return $this->container->get('app.hooks'); }, 'readonly' => true]); $this->defineProperty('assets', ['get' => function () { return $this->container->get('app.assets'); }, 'readonly' => true]); $this->defineProperty('data', ['get' => function () { return $this->container->get('app.data'); }, 'readonly' => true]); $this->defineProperty('cache', ['get' => function () { return $this->container->get('app.cache'); }, 'readonly' => true]); $this->defineProperty('classes', ['get' => function () { return $this->container->get('app.classes'); }, 'readonly' => true]); $this->defineProperty('urls', ['get' => function () { return $this->container->get('app.urls'); }, 'readonly' => true]); $this->defineProperty('images', ['get' => function () { return $this->container->get('app.images'); }, 'readonly' => true]); }
/** * Returns an object from the dependency injection container * * @param string $name The service name * @return object Object from the dependency injection container * @throws \Exception */ public function __get($name) { if ($this->container->exists($name)) { return $this->container->get($name); } throw new \Exception('Invalid property name'); }