Ejemplo n.º 1
0
 /**
  * Get the configuration file to use.
  *
  * @param Script\Event $event The Composer event that is being handled.
  *
  * @return Config\ConfigInterface Configuration file to use.
  */
 protected static function getConfig(Script\Event $event)
 {
     $key = static::getExtraKey();
     $extra = $event->getComposer()->getPackage()->getExtra();
     $configFile = isset($extra[$key]) && isset($extra[$key]['config-file']) ? $extra[$key]['config-file'] : '_config/defaults.php';
     $configPrefix = isset($extra[$key]) && isset($extra[$key]['config-prefix']) ? $extra[$key]['config-prefix'] : 'BrightNucleus/Boilerplate';
     return Config\ConfigFactory::create(dirname(__DIR__) . "/{$configFile}")->getSubConfig($configPrefix);
 }
Ejemplo n.º 2
0
 /**
  * Instantiate a ChainMail object.
  *
  * @since 1.0.0
  *
  * @param ConfigInterface|null $config Optional. Configuration settings.
  */
 public function __construct(ConfigInterface $config = null)
 {
     $defaults = ConfigFactory::create(include self::DEFAULT_CONFIG);
     if (!$config) {
         $this->config = $defaults;
         return;
     }
     $this->config = ConfigFactory::create(array_replace_recursive((array) $defaults, (array) $config));
 }
Ejemplo n.º 3
0
 /**
  * Initialize and return the configuration data.
  *
  * @since 0.1.0
  */
 protected static function initData()
 {
     if (!self::$data) {
         self::$data = ConfigFactory::create(self::getLocation() . '.php');
     }
     return self::$data;
 }
Ejemplo n.º 4
0
 public function testInjectionChainValue()
 {
     $fn = function (InjectionChain $ic) {
         if ($ic->getByIndex(-2) === 'BrightNucleus\\Injector\\Test\\InjectionChainTestDependency') {
             return new InjectionChainValue('Value for dependency');
         } else {
             if ($ic->getByIndex(-2) === 'BrightNucleus\\Injector\\Test\\InjectionChainTest') {
                 return new InjectionChainValue('Value for parent');
             }
         }
         return new InjectionChainValue('unknown value');
     };
     $injector = new Injector(ConfigFactory::create([]));
     $injector->share($injector);
     $injector->delegate('BrightNucleus\\Injector\\Test\\InjectionChainValue', $fn);
     $injector->delegate('BrightNucleus\\Injector\\InjectionChain', [$injector, 'getInjectionChain']);
     $object = $injector->make('BrightNucleus\\Injector\\Test\\InjectionChainTest');
     $this->assertEquals($object->icv->value, 'Value for parent');
     $this->assertEquals($object->dependency->icv->value, 'Value for dependency');
 }
Ejemplo n.º 5
0
 /**
  * Get the configuration to use in the ViewBuilder.
  *
  * @since 0.2.0
  *
  * @return ConfigInterface Configuration passed in through the constructor.
  */
 protected function getConfig($config = null)
 {
     $defaults = ConfigFactory::create(__DIR__ . '/../../config/defaults.php', $config);
     $config = $config ? ConfigFactory::createFromArray(array_merge_recursive($defaults->getArrayCopy(), $config->getArrayCopy())) : $defaults;
     return $config->getSubConfig('BrightNucleus\\View');
 }
Ejemplo n.º 6
0
 /**
  * Test merging using invalid files.
  *
  * @covers \BrightNucleus\Config\ConfigFactory::merge
  *
  * @since  0.3.0
  */
 public function testMergeUsingInvalidFiles()
 {
     $config = ConfigFactory::merge('nonsense_file.php', 'still_nonsense.txt', __DIR__ . '/fixtures/config_file.php');
     $this->assertInstanceOf('\\BrightNucleus\\Config\\ConfigInterface', $config);
     $this->assertInstanceOf('\\BrightNucleus\\Config\\AbstractConfig', $config);
     $this->assertInstanceOf('\\BrightNucleus\\Config\\Config', $config);
     $this->assertTrue($config->hasKey('random_string'));
 }
Ejemplo n.º 7
0
 /**
  * Get a configuration from a specified $file.
  *
  * If file is not accessible or readable, returns an empty Config.
  *
  * @since 0.4.2
  *
  * @return ConfigInterface Configuration settings to use.
  */
 protected function fetchConfig($configFile)
 {
     if (is_string($configFile) && !is_readable($configFile)) {
         $configFile = [];
     }
     return ConfigFactory::create($configFile);
 }
Ejemplo n.º 8
0
 public function testCustomConfig()
 {
     $viewBuilder = new ViewBuilder(ConfigFactory::create(['BrightNucleus' => ['View' => ['EngineFinder' => ['Engines' => ['TestEngine' => 'BrightNucleus\\View\\Tests\\TestEngine']]]]]));
     $viewBuilder->addLocation(new FilesystemLocation(__DIR__ . '/fixtures', ['.test']));
     $view = $viewBuilder->create('custom.engine');
     $result = $view->render(['testdata' => 'testvalue']);
     $this->assertEquals('Test Data = testvalue', $result);
 }