Пример #1
0
 public function testReturnDefaultIfNotSet()
 {
     $default = new Config();
     $default->set(Config::PULI_DIR, 'default');
     $config = new EnvConfig($default);
     $this->assertSame('default', $config->get(Config::PULI_DIR));
 }
Пример #2
0
 /**
  * Creates the configuration.
  *
  * @param Config $baseConfig The base configuration to use for unset values.
  */
 public function __construct(Config $baseConfig = null)
 {
     parent::__construct($baseConfig);
     if (false !== ($puliDir = getenv('PULI_DIR'))) {
         $this->set(Config::PULI_DIR, $puliDir);
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function refreshFactoryClass($path = null, $className = null)
 {
     Assert::nullOrStringNotEmpty($path, 'The path to the generated factory file must be a non-empty string or null. Got: %s');
     Assert::nullOrStringNotEmpty($className, 'The class name of the generated factory must be a non-empty string or null. Got: %s');
     $path = Path::makeAbsolute($path ?: $this->config->get(Config::FACTORY_OUT_FILE), $this->rootDir);
     $className = $className ?: $this->config->get(Config::FACTORY_OUT_CLASS);
     if (!$this->config->get(Config::FACTORY_AUTO_GENERATE)) {
         return;
     }
     if (!file_exists($path)) {
         $this->generateFactoryClass($path, $className);
         return;
     }
     $rootModuleFile = $this->context->getRootModuleFile()->getPath();
     if (!file_exists($rootModuleFile)) {
         return;
     }
     // Regenerate file if the configuration has changed and
     // auto-generation is enabled
     clearstatcache(true, $rootModuleFile);
     $lastConfigChange = filemtime($rootModuleFile);
     $configFile = $this->context->getConfigFile() ? $this->context->getConfigFile()->getPath() : '';
     if (file_exists($configFile)) {
         clearstatcache(true, $configFile);
         $lastConfigChange = max(filemtime($configFile), $lastConfigChange);
     }
     clearstatcache(true, $path);
     $lastFactoryUpdate = filemtime($path);
     if ($lastConfigChange > $lastFactoryUpdate) {
         $this->generateFactoryClass($path, $className);
     }
 }
 public function testFindConfigKeysReturnsParsedValuesIfEnabled()
 {
     $this->baseConfig->set(Config::FACTORY_AUTO_GENERATE, true);
     $this->configFile->getConfig()->set(Config::PULI_DIR, 'my-puli-dir');
     $this->configFile->getConfig()->set(Config::FACTORY_IN_CLASS, 'MyFactory');
     $this->configFile->getConfig()->set(Config::FACTORY_IN_FILE, '{$puli-dir}/MyFactory.php');
     $this->assertSame(array(Config::FACTORY_IN_CLASS => 'MyFactory', Config::FACTORY_IN_FILE => 'my-puli-dir/MyFactory.php'), $this->manager->findConfigKeys(Expr::startsWith('factory.'), false, false, false));
 }
Пример #5
0
 /**
  * Creates the default configuration.
  */
 public function __construct()
 {
     parent::__construct(null, array(self::PULI_DIR => '.puli', self::FACTORY_AUTO_GENERATE => true, self::FACTORY_OUT_CLASS => 'Puli\\GeneratedPuliFactory', self::FACTORY_OUT_FILE => '{$puli-dir}/GeneratedPuliFactory.php', self::FACTORY_IN_CLASS => '{$factory.out.class}', self::FACTORY_IN_FILE => '{$factory.out.file}', self::REPOSITORY_TYPE => 'json', self::REPOSITORY_PATH => '{$puli-dir}/path-mappings.json', self::REPOSITORY_SYMLINK => true, self::REPOSITORY_OPTIMIZE => false, self::REPOSITORY_STORE_CACHE => true, self::CHANGE_STREAM_TYPE => 'json', self::CHANGE_STREAM_PATH => '{$puli-dir}/change-stream.json', self::CHANGE_STREAM_STORE_CACHE => true, self::DISCOVERY_TYPE => 'json', self::DISCOVERY_PATH => '{$puli-dir}/bindings.json', self::DISCOVERY_STORE_CACHE => true));
 }
Пример #6
0
 /**
  * Returns whether the configuration is empty.
  *
  * @param bool $includeFallback Whether to include values set in the base
  *                              configuration passed to {@link __construct()}.
  *
  * @return bool Returns `true` if no key is set and `false` otherwise.
  */
 public function isEmpty($includeFallback = true)
 {
     if (!empty($this->values)) {
         return false;
     }
     return $includeFallback && $this->baseConfig ? $this->baseConfig->isEmpty(true) : true;
 }
 public function testWriteRootPackageFileDoesNotWriteBaseConfigValues()
 {
     $baseConfig = new Config();
     $baseConfig->set(Config::PULI_DIR, 'puli-dir');
     $packageFile = new RootPackageFile(null, null, $baseConfig);
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/minimal.json', $this->tempFile);
 }
Пример #8
0
 public function testIsEmptyWithoutFallback()
 {
     $baseConfig = new Config();
     $config = new Config($baseConfig);
     $this->assertTrue($config->isEmpty(false));
     $baseConfig->set(Config::PULI_DIR, 'my-puli-dir');
     $this->assertTrue($config->isEmpty(false));
     $config->set(Config::PULI_DIR, 'my-puli-dir');
     $this->assertFalse($config->isEmpty(false));
 }
 public function testGetConfigKeysWithAllKeys()
 {
     $this->baseConfig->set(Config::FACTORY_IN_CLASS, 'My\\Class');
     $this->rootPackageFile->getConfig()->set(Config::PULI_DIR, 'my-puli-dir');
     $this->rootPackageFile->getConfig()->set(Config::FACTORY_IN_FILE, '{$puli-dir}/MyFactory.php');
     $values = $this->manager->getConfigKeys(false, true);
     $this->assertSame(Config::getKeys(), array_keys($values));
     $this->assertSame('my-puli-dir', $values[Config::PULI_DIR]);
     $this->assertSame('{$puli-dir}/MyFactory.php', $values[Config::FACTORY_IN_FILE]);
     $this->assertNull($values[Config::DISCOVERY_STORE_PATH]);
     $this->assertNull($values[Config::FACTORY_AUTO_GENERATE]);
 }
Пример #10
0
 public function testRootPackageFileInheritsBaseConfig()
 {
     $packageFile = $this->serializer->unserializeRootPackageFile(self::MINIMAL_JSON, null, $this->baseConfig);
     $this->baseConfig->set(Config::PULI_DIR, 'my-puli-dir');
     $this->assertSame('my-puli-dir', $packageFile->getConfig()->get(Config::PULI_DIR));
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 public function getConfigKeys($includeFallback = false, $includeUnset = false, $raw = true)
 {
     Assert::boolean($includeFallback, 'The argument $includeFallback must be a boolean.');
     Assert::boolean($includeUnset, 'The argument $includeUnset must be a boolean.');
     $values = $raw ? $this->getConfig()->toFlatRawArray($includeFallback) : $this->getConfig()->toFlatArray($includeFallback);
     // Reorder the returned values
     $keysInDefaultOrder = Config::getKeys();
     $defaultValues = array_fill_keys($keysInDefaultOrder, null);
     if (!$includeUnset) {
         $defaultValues = array_intersect_key($defaultValues, $values);
     }
     return array_replace($defaultValues, $values);
 }
Пример #12
0
 /**
  * Creates the default configuration.
  */
 public function __construct()
 {
     parent::__construct(null, array(self::PULI_DIR => '.puli', self::FACTORY_AUTO_GENERATE => true, self::FACTORY_OUT_CLASS => 'Puli\\GeneratedPuliFactory', self::FACTORY_OUT_FILE => '{$puli-dir}/GeneratedPuliFactory.php', self::FACTORY_IN_CLASS => '{$factory.out.class}', self::FACTORY_IN_FILE => '{$factory.out.file}', self::REPOSITORY_TYPE => 'filesystem', self::REPOSITORY_PATH => '{$puli-dir}/repository', self::REPOSITORY_SYMLINK => true, self::DISCOVERY_TYPE => 'key-value-store', self::DISCOVERY_STORE_TYPE => 'json-file', self::DISCOVERY_STORE_PATH => '{$puli-dir}/bindings.json', self::DISCOVERY_STORE_CACHE => true));
 }
Пример #13
0
 public function testRootPackageFileInheritsBaseConfig()
 {
     $packageFile = $this->reader->readRootPackageFile(__DIR__ . '/Fixtures/json/minimal.json', $this->baseConfig);
     $this->baseConfig->set(Config::PULI_DIR, 'my-puli-dir');
     $this->assertSame('my-puli-dir', $packageFile->getConfig()->get(Config::PULI_DIR));
 }