Webiny\Component\ClassLoader\ClassLoader::getInstance PHP 메소드

getInstance() 공개 정적인 메소드

Get an instance of ClassLoader.
public static getInstance ( )
    public static function getInstance()
    {
        if (self::$instance !== null) {
            return self::$instance;
        }
        self::$instance = new static();
        self::registerAutoloader();
        return self::$instance;
    }

Usage Example

예제 #1
0
 /**
  * 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();
 }
All Usage Examples Of Webiny\Component\ClassLoader\ClassLoader::getInstance