/** * Get container * * @return Container */ public function getContainer() { if (!is_object($this->container)) { return $this->container = Container::getInstance(); } return $this->container; }
/** * Init application * * @throws BaseException * @throws DependencyInjection\Exception */ protected function init() { $error = new ErrorHandler(); $error->setHandler(new JsonHandler())->setDebug(true)->register(); DotEnv::load(ROOT_DIR); if (!getenv('RAD_ENVIRONMENT')) { putenv('RAD_ENVIRONMENT=production'); } $this->container = Container::getInstance(); Config::set('environment', getenv('RAD_ENVIRONMENT')); Config::set('debug', (bool) getenv('RAD_DEBUG')); Bundles::loadAll($this->registerBundles()); $this->container->setShared('event_manager', new EventManager(), true); $this->loadConfig(); $this->loadService(); $this->loadServicesFromConfig(); $this->container->setShared('router', new Router()); $this->bundleStartup(); }
/** * If user has at least ONE resource of the resources, return TRUE * @param $resources * * @return bool */ private static function userHasResource($resources) { if (!is_array($resources)) { $resources = [$resources]; } $container = Container::getInstance(); /** @var Rbac $rbac */ $rbac = $container->get('rbac'); /** @var Auth $auth */ $auth = $container->get('auth'); foreach ($resources as $resource) { foreach ($auth->getStorage()->read()['roles'] as $roleName) { if (true === $rbac->isGranted($roleName, $resource)) { return true; } } } return false; }