/**
  * Set the configuration file.
  * The root of your yaml config file must match the component class name, or an exception will be thrown.
  * If you wish to define a default config, just create a static array called $defaultConfig.
  * When setting/updating a config, it is always merged with the default config and current loaded config.
  *
  * @param string|ConfigObject $componentConfig Path to the configuration YAML file or ConfigObject instance
  *
  * @throws Exception\Exception
  */
 public static function setConfig($componentConfig)
 {
     // get component name
     $component = new StringObject(__CLASS__);
     $component = $component->explode('\\')->last();
     // check if we already have a config
     /*if (!self::$componentConfig) {
                 $defaultConfigArray = [];
     
                 // check if we have default config
                 if (isset(self::$defaultConfig)) {
                     $defaultConfigArray = self::$defaultConfig;
                 }
     
                 self::$componentConfig = new ConfigObject($defaultConfigArray);
             }*/
     // check if we have default config
     if (isset(self::$defaultConfig)) {
         self::$componentConfig = new ConfigObject(self::$defaultConfig);
     } else {
         self::$componentConfig = new ConfigObject([]);
     }
     // validate config
     if ($componentConfig instanceof ConfigObject) {
         $config = $componentConfig;
     } else {
         $config = Config::getInstance()->yaml($componentConfig)->get($component, false);
     }
     if (!$config) {
         throw new Exception\Exception('Invalid configuration file for ' . $component . ' component.');
     }
     // merge current config with new config
     self::$componentConfig->mergeWith($config);
     // automatically assign parameters to ServiceManager
     if (self::$componentConfig->get('Parameters', false)) {
         ServiceManager::getInstance()->registerParameters(self::$componentConfig->get('Parameters'));
     }
     // automatically register services
     if (self::$componentConfig->get('Services', false)) {
         ServiceManager::getInstance()->registerServices($component, self::$componentConfig->get('Services'), true);
     }
     // automatically register class loader libraries
     if (self::$componentConfig->get('ClassLoader', false)) {
         ClassLoader::getInstance()->registerMap(self::$componentConfig->get('ClassLoader')->toArray());
     }
     // trigger callback
     self::postSetConfig();
 }
Exemple #2
0
 /**
  * Sets the class name. Note, this will overwrite the current class name, also valid in case of MVC callback.
  *
  * @param string $className Fully qualified class name.
  *
  * @throws \Exception | BootstrapException
  */
 public function setClassName($className)
 {
     try {
         $classFilename = ClassLoader::getInstance()->findClass($className);
         if (!file_exists($classFilename)) {
             throw new BootstrapException('The provided callback class "' . $className . '" does not exist.');
         } else {
             $this->className = $className;
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }
Exemple #3
0
 public function testFindClassCaseThree()
 {
     ClassLoader::getInstance()->registerMap(['Zend' => ['Path' => '/usr/includes/Zend/', 'Psr' => 0]]);
     $classPath = ClassLoader::getInstance()->findClass('\\Zend\\Acl');
     $this->assertSame('/usr/includes/Zend/Acl.php', $classPath);
 }
 public function testFindClass()
 {
     ClassLoader::getInstance()->registerMap(['Webiny\\Component\\ClassLoader' => realpath(__DIR__ . '/../')]);
     $class = ClassLoader::getInstance()->findClass('Webiny\\Component\\ClassLoader\\ClassLoader');
     $this->assertSame(realpath(__DIR__ . '/../ClassLoader.php'), $class);
 }
Exemple #5
0
 /**
  * Registers the application namespace with the ClassLoader component.
  *
  * @throws BootstrapException
  */
 private function registerAppNamespace()
 {
     // get app namespace
     $namespace = $this->applicationConfig->get('Application.Namespace', false);
     if (!$namespace) {
         throw new BootstrapException('Unable to register application namespace. You must define the application namespace in your App.yaml config file.');
     }
     try {
         // register the namespace
         ClassLoader::getInstance()->registerMap([$namespace => $this->applicationAbsolutePath . 'App']);
     } catch (\Exception $e) {
         throw new BootstrapException('Unable to register application (' . $namespace . ' => ' . $this->applicationAbsolutePath . 'App' . ') namespace with ClassLoader.');
     }
 }
Exemple #6
0
 public function testFindClassCaseTwo()
 {
     ClassLoader::getInstance()->registerMap(['Smarty_' => ['Path' => '/var/www/Vendors/Smarty/libs/sysplugins', 'Normalize' => false, 'Case' => 'lower']]);
     $classPath = ClassLoader::getInstance()->findClass('Smarty_Internal_Compile_Call');
     $this->assertSame('/var/www/Vendors/Smarty/libs/sysplugins/smarty_internal_compile_call.php', $classPath);
 }
Exemple #7
0
 public function setUp()
 {
     // make sure we unregister the class loader map, can cause a conflict with the composer
     ClassLoader::getInstance()->unregisterMap('Smarty_');
     TemplateEngine::setConfig(__DIR__ . '/../../ExampleConfig.yaml');
 }