Inheritance: use trait Nette\SmartObject
コード例 #1
0
ファイル: Compiler.php プロジェクト: kukulich/di
 /**
  * Adds new configuration from file.
  * @return self
  */
 public function loadConfig(string $file) : self
 {
     $loader = new Config\Loader();
     $this->addConfig($loader->load($file));
     $this->addDependencies($loader->getDependencies());
     return $this;
 }
コード例 #2
0
ファイル: CompilerExtension.php プロジェクト: Northys/di
 /**
  * Reads configuration from file.
  * @param  string  file name
  * @return array
  */
 public function loadFromFile($file)
 {
     $loader = new Config\Loader();
     $res = $loader->load($file);
     $this->compiler->addDependencies($loader->getDependencies());
     return $res;
 }
コード例 #3
0
ファイル: Compiler.php プロジェクト: nette/di
 /**
  * Adds new configuration from file.
  * @return self
  */
 public function loadConfig($file)
 {
     $loader = new Config\Loader();
     $this->addConfig($loader->load($file));
     $this->dependencies->add($loader->getDependencies());
     return $this;
 }
コード例 #4
0
 /**
  * Reads configuration from file.
  * @param  string  file name
  * @return array
  */
 public function loadFromFile($file)
 {
     $loader = new Config\Loader();
     $res = $loader->load($file);
     $container = $this->compiler->getContainerBuilder();
     foreach ($loader->getDependencies() as $file) {
         $container->addDependency($file);
     }
     return $res;
 }
コード例 #5
0
ファイル: Factory.php プロジェクト: netis-cms/netis
 /**
  * Factory for settings db host.
  * @param  class Translator
  * @param  callable
  * @return Form
  */
 public function databaseHostFactory($translator, callable $onSuccess)
 {
     $form = $this->forms->create($translator);
     $form->addText('host', 'install.db.host')->setRequired('install.form.empty');
     $form->addText('user', 'install.db.user')->setRequired('install.form.empty');
     $form->addText('password', 'install.db.pass');
     $form->addText('database', 'install.db.name')->setRequired('install.form.empty');
     $form->addText('prefix', 'install.db.prefix')->setAttribute('placeholder', 'ns_');
     // Database drivers.
     $drivers = ['mysql' => 'MySQL', 'mysqli' => 'MySQLi'];
     $form->addSelect('driver', 'install.db.driver', $drivers)->setRequired();
     $form->addSubmit('send', 'install.db.send');
     $form->onSuccess[] = function (Form $form, $values) use($onSuccess) {
         try {
             // Testing database connection.
             if (\dibi::connect($values)) {
                 // Parameters for generate config neon file.
                 $arr = ['extensions' => ['dibi' => 'Dibi\\Bridges\\Nette\\DibiExtension22'], 'dibi' => ['host' => $values->host, 'username' => $values->user, 'password' => $values->password, 'database' => $values->database, 'driver' => $values->driver, 'lazy' => TRUE, 'substitutes' => ['prefix' => $values->prefix]]];
                 // Generate and save the configuration file
                 $this->loader->save($arr, $this->dirs->getAppDir() . '/modules/app.db.neon');
                 // Removing the old cache for updating the configuration file.
                 FileSystem::delete($this->dirs->getTempDir() . '/cache/Nette.Configurator');
                 // Save the installation step into the cache.
                 $this->steps->setToCache(Steps::Step1, rand(1, 9));
                 // Save db prefix.
                 if ($values->prefix) {
                     $this->sessions->getSessionSection()->prefix = $values->prefix;
                 }
             }
         } catch (\Dibi\Exception $e) {
             // Server database type error.
             if ($e->getCode() == 0) {
                 $form->addError('install.db.driver.catch');
                 // Host server not found.
             } elseif ($e->getCode() == 2002) {
                 $form->addError('install.db.host.catch');
                 // The user or password was not verified.
             } elseif ($e->getCode() == 1045) {
                 $form->addError('install.db.auth.catch');
                 // The database name was not found
             } elseif ($e->getCode() == 1049) {
                 $form->addError('install.db.name.catch');
             }
             return;
         }
         $onSuccess();
     };
     return $form;
 }
コード例 #6
0
 /**
  * Adds configuration file.
  * @return self
  */
 public function addConfig($file, $section = NULL)
 {
     if ($section === NULL && $this->parameters['debugMode']) {
         // back compatibility
         try {
             $loader = new DI\Config\Loader();
             $loader->load($file, $this->parameters['environment']);
             trigger_error("Config file '{$file}' has sections, call addConfig() with second parameter Configurator::AUTO.", E_USER_WARNING);
             $section = $this->parameters['environment'];
         } catch (\Exception $e) {
         }
     }
     $this->files[] = array($file, $section === self::AUTO ? $this->parameters['environment'] : $section);
     return $this;
 }
コード例 #7
0
ファイル: Configurator.php プロジェクト: phalette/pidic
 /**
  * @param Compiler $compiler
  * @return string
  */
 public function generateContainer(Compiler $compiler)
 {
     // Load configs
     $loader = new Loader();
     $compiler->addConfig(['parameters' => $this->parameters]);
     foreach ($this->configs as $config) {
         $compiler->addConfig($loader->load($config));
     }
     $compiler->addDependencies($loader->getDependencies());
     // Exclude classes
     $builder = $compiler->getContainerBuilder();
     $builder->addExcludedClasses($this->excludedClasses);
     // Fire events
     foreach ($this->onCompile as $cb) {
         call_user_func_array($cb, [$compiler]);
     }
     // Compile container
     $classes = $compiler->compile();
     $classes[0]->setExtends(PiDiContainer::class);
     return implode("\n", []) . "\n\n" . implode("\n\n\n", $classes);
 }