Ex1: $config = \Webiny\Components\Config\Config::getInstance()->ini('path/to/file.ini'); Ex2: $config = $this->config()->ini('path/to/file.ini');
Inheritance: use trait Webiny\Component\StdLib\StdLibTrait, use trait Webiny\Component\StdLib\SingletonTrait
Example #1
0
 public function testParseResource()
 {
     $resource = ['application' => 'development'];
     $config = Config::getInstance()->parseResource($resource);
     $this->assertInstanceOf('\\Webiny\\Component\\Config\\ConfigObject', $config);
     $this->assertEquals('development', $config->application);
 }
Example #2
0
 /**
  * Base constructor.
  *
  * @param string $config Path to the MaxMind configuration.
  *
  * @throws \Webiny\Component\StdLib\Exception\Exception
  */
 public function __construct($config)
 {
     $config = \Webiny\Component\Config\Config::getInstance()->yaml($config);
     // bootstrap
     Mongo::setConfig(['Mongo' => $config->get('Mongo', null, true)]);
     Entity::setConfig(['Entity' => $config->get('Entity', null, true)]);
 }
Example #3
0
 public function firewallProvider()
 {
     Security::setConfig(__DIR__ . '/../../../ExampleConfig.yaml');
     $config = Config::getInstance()->yaml(__DIR__ . '/../../../ExampleConfig.yaml');
     $firewallConfig = $config->Security->Firewalls->Admin;
     $userProviderMock = new UserProviderMock();
     $encoder = new Encoder($config->Security->Encoders->MockEncoder->Driver, []);
     $firewall = new Firewall('Admin', $firewallConfig, [$userProviderMock], $encoder);
     return [[$firewall]];
 }
Example #4
0
 /**
  * Runs the installation.
  *
  * @throws \Webiny\Component\StdLib\Exception\Exception
  */
 public function runInstaller($configFile)
 {
     // bootstrap
     $this->config = Config::getInstance()->yaml($configFile);
     Mongo::setConfig(['Mongo' => $this->config->get('Mongo', null, true)]);
     Entity::setConfig(['Entity' => $this->config->get('Entity', null, true)]);
     /**
      * @var $mongo Mongo
      */
     $this->mongo = $this->mongo($this->config->Entity->Database);
     // import process
     $this->downloadDatabase();
     $this->unpackDatabase();
     $this->importLocations();
     //$this->importIp4CityBlock();
     //$this->importIp6CityBlock();
     echo "\nImport has finished.";
     die;
 }
Example #5
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();
 }
Example #6
0
 /**
  * Merge current config with given config
  *
  * @param array|ArrayObject|ConfigObject $config ConfigObject or array of ConfigObject to merge with
  *
  * @throws ConfigException
  * @return $this
  */
 public function mergeWith($config)
 {
     if ($this->isArray($config) || $this->isArrayObject($config)) {
         $configs = StdObjectWrapper::toArray($config);
         // Make sure it's an array of ConfigObject
         if (!$this->isInstanceOf($this->arr($configs)->first()->val(), $this)) {
             $configs = [Config::getInstance()->php($configs)];
         }
     } elseif ($this->isInstanceOf($config, $this)) {
         $configs = [$config];
     } else {
         throw new ConfigException('Invalid parameter passed to ConfigObject mergeWith($config) method! Expecting a ConfigObject or array.');
     }
     /** @var ConfigObject $value */
     foreach ($configs as $config) {
         // If it's a PHP array or ArrayObject, convert it to ConfigObject
         if ($this->isArray($config) || $this->isArrayObject($config)) {
             $config = Config::getInstance()->php($config);
         }
         foreach ($config as $key => $value) {
             if ($this->data->keyExists($key)) {
                 if ($this->isNumber($key)) {
                     $this->data[] = $value;
                 } elseif ($this->isInstanceOf($value, $this) && $this->isInstanceOf($this->data[$key], $this)) {
                     $this->data[$key]->mergeWith($value);
                 } else {
                     if ($this->isInstanceOf($value, $this)) {
                         $this->data[$key] = new static($value->toArray(), false);
                     } else {
                         $this->data[$key] = $value;
                     }
                 }
             } else {
                 if ($this->isInstanceOf($value, $this)) {
                     $this->data[$key] = new static($value->toArray(), false);
                 } else {
                     $this->data[$key] = $value;
                 }
             }
         }
     }
     return $this;
 }
Example #7
0
 public function setUp()
 {
     Router::getInstance()->prependRoutes(Config::getInstance()->yaml(__DIR__ . '/ExampleConfig.yaml')->get('Router.Routes'));
     Request::getInstance()->setCurrentUrl('http://www.webiny.com/');
 }
Example #8
0
<?php

require_once '../vendor/autoload.php';
\Webiny\Component\Security\Security::setConfig('./securityConfig.yaml');
\Webiny\Component\Mongo\Mongo::setConfig('./mongoConfig.yaml');
\Webiny\Component\Entity\Entity::setConfig('./entityConfig.yaml');
$security = \Webiny\Component\Security\Security::getInstance();
$loginConfig = \Webiny\Component\Config\Config::getInstance()->yaml('./loginConfig.yaml');
$login = new \Webiny\Login\Login($security, $loginConfig);