Beispiel #1
0
 /**
  * @return \Nette\Security\User
  */
 private function getUser()
 {
     if (!$this->user) {
         $this->user = $this->container->getByType(User::class);
     }
     return $this->user;
 }
Beispiel #2
0
 public function configure(Template $template)
 {
     // translator
     if (($translator = $this->container->getByType('Nette\\Localization\\ITranslator', FALSE)) !== NULL) {
         $template->setTranslator($translator);
     }
     $template->registerHelperLoader(array($this->container->venne->helpers, "loader"));
 }
 /**
  * @param \SystemContainer $container
  * @return EntityManager
  */
 public function createDatabase(\SystemContainer $container)
 {
     // Create database
     $em = $container->getByType('\\Doctrine\\ORM\\EntityManager');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $metadatas = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool->createSchema($metadatas);
     return $em;
 }
 protected function refreshContainer()
 {
     $container = $this->getContainer();
     /** @var Session $session */
     if (($session = $container->getByType('Nette\\Http\\Session')) && $session->isStarted()) {
         $session->close();
     }
     $this->container = new $container();
     $this->container->initialize();
 }
Beispiel #5
0
 /**
  * @return User
  */
 protected function getUser()
 {
     if (!$this->_user) {
         $this->_user = $this->container->getByType('Nette\\Security\\User');
     }
     return $this->_user;
 }
 /**
  * Loads service from DI container
  * Triggers the listeners of an event.
  *
  * This method can be overridden to add functionality that is executed
  * for each listener.
  *
  * @param array[callback] $listeners The event listeners.
  * @param string          $eventName The name of the event to dispatch.
  * @param Event           $event     The event object to pass to the event handlers/listeners.
  */
 protected function doDispatch($listeners, $eventName, Event $event)
 {
     foreach ($listeners as $listenerParams) {
         $subscriber = $listenerParams[0];
         $method = $listenerParams[1];
         $service = $subscriber;
         if (is_string($subscriber)) {
             $service = $this->container->getService($subscriber);
         }
         $listener = [$service, $method];
         call_user_func($listener, $event);
         if ($event->isPropagationStopped()) {
             break;
         }
     }
 }
Beispiel #7
0
 /**
  * Uninstallation of package.
  *
  * @param \Venne\Packages\IPackage $package
  */
 public function uninstall(IPackage $package)
 {
     if ($this->getStatus($package) === self::STATUS_UNINSTALLED) {
         throw new InvalidArgumentException(sprintf('Package \'%s\' is already uninstalled', $package->getName()));
     }
     $dependencyResolver = $this->createSolver();
     $dependencyResolver->testUninstall($package);
     foreach ($package->getInstallers() as $class) {
         try {
             $installer = $this->context->createInstance($class);
             $installer->uninstall($package);
         } catch (Exception $e) {
             foreach ($package->getInstallers() as $class2) {
                 if ($class === $class2) {
                     break;
                 }
                 $installer = $this->context->createInstance($class2);
                 $installer->install($package);
             }
             throw new InvalidStateException($e->getMessage());
         }
     }
     $this->setStatus($package, self::STATUS_UNINSTALLED);
     $this->reloadInfo();
     $this->onUninstall($this, $package);
 }
Beispiel #8
0
 /**
  * @param $presenter
  * @return string
  */
 public function formatPresenterFile($presenter)
 {
     $service = $this->formatPresenterFromServiceName($presenter);
     if ($this->container->hasService($service)) {
         return get_class($this->container->getService($service));
     }
     return parent::formatPresenterFile($presenter);
 }
Beispiel #9
0
 public function reloadContainer()
 {
     $this->presenterFactory = NULL;
     $container = $this->getContainer();
     $configurator = $this->getConfigurator();
     $class = $container->parameters['container']['class'] . '_test_' . $this->containerCounter++;
     \Nette\Utils\LimitedScope::evaluate($configurator->buildContainer($dependencies, $class));
     $this->container = new $class();
     $this->container->initialize();
     $this->container->addService('configurator', $configurator);
 }
Beispiel #10
0
 /**
  * @return array
  */
 protected function getModulesForUnregister()
 {
     $ret = array();
     foreach ($this->modules as $name => $args) {
         $path = $this->context->expand($args[self::MODULE_PATH]);
         if (!file_exists($path)) {
             $ret[$name] = $args;
         }
     }
     return $ret;
 }
Beispiel #11
0
 /**
  * @deprecated
  */
 public function getService($name)
 {
     trigger_error(__METHOD__ . '() is deprecated; use dependency injection instead.', E_USER_DEPRECATED);
     return $this->context->getService($name);
 }
 /**
  * @return Nette\Security\User
  */
 public function getUser()
 {
     return $this->context->getByType('Nette\\Security\\User');
 }
Beispiel #13
0
 /**
  * Return database connection prameters
  * @param \SystemContainer $netteContainer
  * @return \stdClass Connection parameters
  */
 private function getDatabaseConnectionParameters($netteContainer)
 {
     $config = \Nette\Neon\Neon::decode(\Bruha\Generator\Utils\File::read(static::$settings->netteRoot . '/app/config/config.local.neon'));
     unset($config['nette']['database']);
     \Nette\Utils\FileSystem::write(static::$settings->netteRoot . '/app/config/config.local.neon', preg_replace('~(^[\\r\\n]*|[\\r\\n]+)[\\s\\t]*[\\r\\n]+~', "\n", (new \Nette\Neon\Encoder())->encode($config, \Nette\Neon\Encoder::BLOCK)));
     try {
         $databaseConnection = $netteContainer->getByType('\\Nette\\Database\\Connection');
         $databaseConnection->connect();
         $databaseReflectionProperty = (new \ReflectionClass('\\Nette\\Database\\Connection'))->getProperty('params');
         $databaseReflectionProperty->setAccessible(TRUE);
         $database = $databaseReflectionProperty->getValue($databaseConnection);
         CLI::write('Verifying database configuration:', 1, TRUE, FALSE);
         CLI::write('SUCCESS', 0, FALSE);
         preg_match('~=(.*);~', $database[0], $hostname);
         return (object) ['hostname' => $hostname[1], 'username' => $database[1], 'password' => $database[2], 'database' => mb_substr($database[0], mb_strpos($database[0], ';dbname=') + 8)];
     } catch (\PDOException $e) {
         $database = $e->getTrace()[0]['args'];
         preg_match('~=(.*);~', $database[0], $hostname);
         $database = (object) ['hostname' => $hostname[1], 'username' => $database[1], 'password' => $database[2], 'database' => mb_substr($database[0], mb_strpos($database[0], ';dbname=') + 8)];
         return $this->repairDatabaseConfiguration($database);
     }
 }
Beispiel #14
0
	/**
	 * @return NUser
	 */
	public function getUser()
	{
		return $this->context->getByType('NUser');
	}
Beispiel #15
0
 function __construct(SystemContainer $container)
 {
     $this->container = $container;
     $this->user = $container->getService('user');
     $this->parameters = $container->parameters;
 }
Beispiel #16
0
 /**
  * @deprecated
  */
 public final function getService($name)
 {
     return $this->context->getService($name);
 }