Exemplo n.º 1
0
 public function testConfigInheritsFromBaseConfig()
 {
     $baseConfig = new Config();
     $packageFile = new RootPackageFile(null, null, $baseConfig);
     $this->assertNotSame($baseConfig, $packageFile->getConfig());
     $baseConfig->set(Config::PULI_DIR, 'puli-dir');
     $this->assertSame('puli-dir', $packageFile->getConfig()->get(Config::PULI_DIR));
 }
Exemplo n.º 2
0
 protected function initEnvironment($homeDir, $rootDir, $mockDispatcher = true)
 {
     if (!$this->baseConfig) {
         $this->baseConfig = new DefaultConfig();
     }
     $this->homeDir = $homeDir;
     $this->rootDir = $rootDir;
     $this->configFile = new ConfigFile($homeDir . '/config.json', $this->baseConfig);
     $this->rootPackageFile = new RootPackageFile('vendor/root', $rootDir . '/puli.json', $this->baseConfig);
     $this->dispatcher = $mockDispatcher ? $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface') : new EventDispatcher();
     $this->repo = $this->getMock('Puli\\Repository\\Api\\EditableRepository');
     $this->discovery = $this->getMock('Puli\\Discovery\\Api\\EditableDiscovery');
     $this->environment = new ProjectEnvironment($this->homeDir, $this->rootDir, $this->rootPackageFile->getConfig(), $this->rootPackageFile, $this->configFile, $this->dispatcher);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getConfig()
 {
     return $this->rootPackageFile->getConfig();
 }
 public function testWriteRootPackageFile()
 {
     $installInfo1 = new InstallInfo('vendor/package1', '/path/to/package1');
     $installInfo1->setInstallerName('composer');
     $installInfo1->addEnabledBindingUuid(Uuid::fromString('a54e5668-2b36-43f4-a32c-2d175092b77d'));
     $installInfo1->addDisabledBindingUuid(Uuid::fromString('4d02ee67-d845-4789-a9c1-8301351c6f5a'));
     $installInfo2 = new InstallInfo('vendor/package2', '/path/to/package2');
     $baseConfig = new Config();
     $packageFile = new RootPackageFile(null, null, $baseConfig);
     $packageFile->setPackageName('my/application');
     $packageFile->addPathMapping(new PathMapping('/app', 'res'));
     $packageFile->addBindingDescriptor(new BindingDescriptor('/app/config*.yml', 'my/type', array(), 'glob', Uuid::fromString(self::BINDING_UUID1)));
     $packageFile->addTypeDescriptor(new BindingTypeDescriptor('my/type', 'Description of my type.', array(new BindingParameterDescriptor('param', BindingParameterDescriptor::OPTIONAL, 1234, 'Description of the parameter.'))));
     $packageFile->setOverriddenPackages(array('acme/blog'));
     $packageFile->setOverrideOrder(array('acme/blog-extension1', 'acme/blog-extension2'));
     $packageFile->addPluginClass('Puli\\Manager\\Tests\\Api\\Package\\Fixtures\\TestPlugin');
     $packageFile->getConfig()->merge(array(Config::PULI_DIR => 'puli-dir', Config::FACTORY_OUT_CLASS => 'Puli\\MyFactory', Config::FACTORY_OUT_FILE => '{$puli-dir}/MyFactory.php', Config::REPOSITORY_TYPE => 'my-type', Config::REPOSITORY_PATH => '{$puli-dir}/my-repo', Config::DISCOVERY_STORE_TYPE => 'my-store-type'));
     $packageFile->addInstallInfo($installInfo1);
     $packageFile->addInstallInfo($installInfo2);
     $packageFile->setExtraKeys(array('extra1' => 'value', 'extra2' => array('key' => 'value')));
     $this->writer->writePackageFile($packageFile, $this->tempFile);
     $this->assertFileExists($this->tempFile);
     $this->assertJsonFileEquals(__DIR__ . '/Fixtures/json/full-root.json', $this->tempFile);
 }
Exemplo n.º 5
0
 /**
  * Creates the context of a Puli project.
  *
  * The home directory is read from the context variable "PULI_HOME".
  * If this variable is not set, the home directory defaults to:
  *
  *  * `$HOME/.puli` on Linux, where `$HOME` is the context variable
  *    "HOME".
  *  * `$APPDATA/Puli` on Windows, where `$APPDATA` is the context
  *    variable "APPDATA".
  *
  * If none of these variables can be found, an exception is thrown.
  *
  * A .htaccess file is put into the home directory to protect it from web
  * access.
  *
  * @param string $rootDir The path to the project.
  *
  * @return ProjectContext The project context.
  */
 private function createProjectContext($rootDir, $env)
 {
     Assert::fileExists($rootDir, 'Could not load Puli context: The root %s does not exist.');
     Assert::directory($rootDir, 'Could not load Puli context: The root %s is a file. Expected a directory.');
     $baseConfig = new DefaultConfig();
     $homeDir = self::parseHomeDirectory();
     if (null !== ($configFile = $this->loadConfigFile($homeDir, $baseConfig))) {
         $baseConfig = $configFile->getConfig();
     }
     // Create a storage without the factory manager
     $packageFileStorage = new PackageFileStorage($this->getStorage(), $this->getPackageFileSerializer());
     $rootDir = Path::canonicalize($rootDir);
     $rootFilePath = $this->rootDir . '/puli.json';
     try {
         $rootPackageFile = $packageFileStorage->loadRootPackageFile($rootFilePath, $baseConfig);
     } catch (FileNotFoundException $e) {
         $rootPackageFile = new RootPackageFile(null, $rootFilePath, $baseConfig);
     }
     $config = new EnvConfig($rootPackageFile->getConfig());
     return new ProjectContext($homeDir, $rootDir, $config, $rootPackageFile, $configFile, $this->dispatcher, $env);
 }
Exemplo n.º 6
0
 private function addRootConfig(array &$jsonData, RootPackageFile $packageFile)
 {
     $overrideOrder = $packageFile->getOverrideOrder();
     $installInfos = $packageFile->getInstallInfos();
     // Pass false to exclude base configuration values
     $configValues = $packageFile->getConfig()->toRawArray(false);
     if (count($overrideOrder) > 0) {
         $jsonData['override-order'] = $overrideOrder;
     }
     if (count($configValues) > 0) {
         $jsonData['config'] = (object) $configValues;
     }
     if (array() !== $packageFile->getPluginClasses(false)) {
         $jsonData['plugins'] = $packageFile->getPluginClasses();
         sort($jsonData['plugins']);
     }
     if (count($installInfos) > 0) {
         $packagesData = array();
         foreach ($installInfos as $installInfo) {
             $installData = new stdClass();
             $installData->{'install-path'} = $installInfo->getInstallPath();
             if (InstallInfo::DEFAULT_INSTALLER_NAME !== $installInfo->getInstallerName()) {
                 $installData->installer = $installInfo->getInstallerName();
             }
             if ($installInfo->hasEnabledBindingUuids()) {
                 $installData->{'enabled-bindings'} = array();
                 foreach ($installInfo->getEnabledBindingUuids() as $uuid) {
                     $installData->{'enabled-bindings'}[] = $uuid->toString();
                 }
                 sort($installData->{'enabled-bindings'});
             }
             if ($installInfo->hasDisabledBindingUuids()) {
                 $installData->{'disabled-bindings'} = array();
                 foreach ($installInfo->getDisabledBindingUuids() as $uuid) {
                     $installData->{'disabled-bindings'}[] = $uuid->toString();
                 }
                 sort($installData->{'disabled-bindings'});
             }
             $packagesData[$installInfo->getPackageName()] = $installData;
         }
         ksort($packagesData);
         $jsonData['packages'] = (object) $packagesData;
     }
 }
Exemplo n.º 7
0
 private function populateRootConfig(RootPackageFile $packageFile, \stdClass $jsonData)
 {
     if (isset($jsonData->{'override-order'})) {
         $packageFile->setOverrideOrder((array) $jsonData->{'override-order'});
     }
     if (isset($jsonData->plugins)) {
         $packageFile->setPluginClasses($jsonData->plugins);
     }
     if (isset($jsonData->config)) {
         $config = $packageFile->getConfig();
         foreach ($this->objectsToArrays($jsonData->config) as $key => $value) {
             $config->set($key, $value);
         }
     }
     if (isset($jsonData->packages)) {
         foreach ($jsonData->packages as $packageName => $packageData) {
             $installInfo = new InstallInfo($packageName, $packageData->{'install-path'});
             if (isset($packageData->installer)) {
                 $installInfo->setInstallerName($packageData->installer);
             }
             if (isset($packageData->{'enabled-bindings'})) {
                 foreach ($packageData->{'enabled-bindings'} as $uuid) {
                     $installInfo->addEnabledBindingUuid(Uuid::fromString($uuid));
                 }
             }
             if (isset($packageData->{'disabled-bindings'})) {
                 foreach ($packageData->{'disabled-bindings'} as $uuid) {
                     $installInfo->addDisabledBindingUuid(Uuid::fromString($uuid));
                 }
             }
             $packageFile->addInstallInfo($installInfo);
         }
     }
 }