private function populateConfig(PackageFile $packageFile, \stdClass $jsonData)
 {
     if (isset($jsonData->name)) {
         $packageFile->setPackageName($jsonData->name);
     }
     if (isset($jsonData->{'path-mappings'})) {
         foreach ($jsonData->{'path-mappings'} as $path => $relativePaths) {
             $packageFile->addPathMapping(new PathMapping($path, (array) $relativePaths));
         }
     }
     if (isset($jsonData->bindings)) {
         foreach ($jsonData->bindings as $uuid => $bindingData) {
             $packageFile->addBindingDescriptor(new BindingDescriptor($bindingData->query, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), isset($bindingData->language) ? $bindingData->language : 'glob', Uuid::fromString($uuid)));
         }
     }
     if (isset($jsonData->{'binding-types'})) {
         foreach ((array) $jsonData->{'binding-types'} as $typeName => $data) {
             $parameters = array();
             if (isset($data->parameters)) {
                 foreach ((array) $data->parameters as $paramName => $paramData) {
                     $required = isset($paramData->required) ? $paramData->required : false;
                     $parameters[] = new BindingParameterDescriptor($paramName, $required ? BindingParameterDescriptor::REQUIRED : BindingParameterDescriptor::OPTIONAL, isset($paramData->default) ? $paramData->default : null, isset($paramData->description) ? $paramData->description : null);
                 }
             }
             $packageFile->addTypeDescriptor(new BindingTypeDescriptor($typeName, isset($data->description) ? $data->description : null, $parameters));
         }
     }
     if (isset($jsonData->override)) {
         $packageFile->setOverriddenPackages((array) $jsonData->override);
     }
     if (isset($jsonData->extra)) {
         $packageFile->setExtraKeys((array) $jsonData->extra);
     }
 }
Beispiel #2
0
 /**
  * Creates a new package.
  *
  * @param PackageFile|null $packageFile The package file or `null` if the
  *                                      package file could not be loaded.
  * @param string           $installPath The absolute install path.
  * @param InstallInfo|null $installInfo The install info of this package.
  * @param Exception[]      $loadErrors  The errors that happened during
  *                                      loading of the package, if any.
  */
 public function __construct(PackageFile $packageFile = null, $installPath, InstallInfo $installInfo = null, array $loadErrors = array())
 {
     Assert::absoluteSystemPath($installPath);
     Assert::true($packageFile || $loadErrors, 'The load errors must be passed if the package file is null.');
     Assert::allIsInstanceOf($loadErrors, 'Exception');
     // If a package name was set during installation, that name wins over
     // the predefined name in the puli.json file (if any)
     $this->name = $installInfo && null !== $installInfo->getPackageName() ? $installInfo->getPackageName() : ($packageFile ? $packageFile->getPackageName() : null);
     if (null === $this->name) {
         $this->name = $this->getDefaultName();
     }
     // The path is stored both here and in the install info. While the
     // install info contains the path as it is stored in the install file
     // (i.e. relative or absolute), the install path of the package is
     // always an absolute path.
     $this->installPath = $installPath;
     $this->installInfo = $installInfo;
     $this->packageFile = $packageFile;
     $this->loadErrors = $loadErrors;
     if (!file_exists($installPath)) {
         $this->state = PackageState::NOT_FOUND;
     } elseif (count($loadErrors) > 0) {
         $this->state = PackageState::NOT_LOADABLE;
     } else {
         $this->state = PackageState::ENABLED;
     }
 }
 /**
  * @expectedException \Puli\Manager\Api\InvalidConfigException
  */
 public function testInstallPackageFailsIfNoNameFound()
 {
     $this->initDefaultManager();
     $this->packageFile3->setPackageName(null);
     $this->packageFileStorage->expects($this->never())->method('saveRootPackageFile');
     $this->manager->installPackage($this->packageDir3);
 }
 public function testBuildDiscoveryEmitsWarningsForDuplicatedTypes()
 {
     $this->initDefaultManager();
     $this->packageFile1->addTypeDescriptor(new BindingTypeDescriptor('my/type'));
     $this->packageFile2->addTypeDescriptor(new BindingTypeDescriptor('my/type'));
     $this->discovery->expects($this->never())->method('defineType');
     $this->logger->expects($this->once())->method('warning');
     $this->manager->buildDiscovery();
 }
 public function testPreBuildRepositoryEventSupportsSkipping()
 {
     $testResource = new FileResource(__FILE__);
     $this->initEnvironment($this->homeDir, $this->rootDir, false);
     $this->initDefaultManager();
     $this->packageFile1->addPathMapping(new PathMapping('/path', 'resources'));
     $this->repo->expects($this->never())->method('add');
     $this->dispatcher->addListener(PuliEvents::PRE_BUILD_REPOSITORY, function (BuildRepositoryEvent $event) {
         $event->skipBuild();
     });
     $this->dispatcher->addListener(PuliEvents::POST_BUILD_REPOSITORY, function (BuildRepositoryEvent $event) use($testResource) {
         // The post event is not executed if the build is skipped
         $event->getRepositoryManager()->getRepository()->add('/post', $testResource);
     });
     $this->manager->buildRepository();
 }
Beispiel #6
0
 /**
  * Creates a new root package file.
  *
  * The file's configuration will inherit its settings from the base
  * configuration passed to the constructor.
  *
  * @param string|null $packageName The package name. Optional.
  * @param string|null $path        The path where the configuration is
  *                                 stored or `null` if this configuration is
  *                                 not stored on the file system.
  * @param Config      $baseConfig  The configuration that the package will
  *                                 inherit its configuration values from.
  */
 public function __construct($packageName = null, $path = null, Config $baseConfig = null)
 {
     parent::__construct($packageName, $path);
     $this->config = new Config($baseConfig);
 }
 /**
  * @dataProvider provideInvalidPaths
  * @expectedException \Puli\Manager\Api\IOException
  */
 public function testWriteConfigExpectsValidPath($invalidPath)
 {
     $packageFile = new PackageFile();
     $packageFile->setPackageName('my/application');
     $this->writer->writePackageFile($packageFile, $invalidPath);
 }
 private function addConfig(array &$jsonData, PackageFile $packageFile)
 {
     $mappings = $packageFile->getPathMappings();
     $bindings = $packageFile->getBindingDescriptors();
     $bindingTypes = $packageFile->getTypeDescriptors();
     $overrides = $packageFile->getOverriddenPackages();
     $extra = $packageFile->getExtraKeys();
     $jsonData['version'] = '1.0';
     if (null !== $packageFile->getPackageName()) {
         $jsonData['name'] = $packageFile->getPackageName();
     }
     if (count($mappings) > 0) {
         $jsonData['path-mappings'] = new stdClass();
         foreach ($mappings as $mapping) {
             $puliPath = $mapping->getRepositoryPath();
             $localPaths = $mapping->getPathReferences();
             $jsonData['path-mappings']->{$puliPath} = count($localPaths) > 1 ? $localPaths : reset($localPaths);
         }
     }
     if (count($bindings) > 0) {
         uasort($bindings, array('Puli\\Manager\\Api\\Discovery\\BindingDescriptor', 'compare'));
         $jsonData['bindings'] = new stdClass();
         foreach ($bindings as $binding) {
             $bindingData = new stdClass();
             $bindingData->query = $binding->getQuery();
             if ('glob' !== $binding->getLanguage()) {
                 $bindingData->language = $binding->getLanguage();
             }
             $bindingData->type = $binding->getTypeName();
             // Don't include the default values of the binding type
             if ($binding->hasParameterValues(false)) {
                 $bindingData->parameters = $binding->getParameterValues(false);
                 ksort($bindingData->parameters);
             }
             $jsonData['bindings']->{$binding->getUuid()->toString()} = $bindingData;
         }
     }
     if (count($bindingTypes) > 0) {
         $bindingTypesData = array();
         foreach ($bindingTypes as $bindingType) {
             $typeData = new stdClass();
             if ($bindingType->getDescription()) {
                 $typeData->description = $bindingType->getDescription();
             }
             if (count($bindingType->getParameters()) > 0) {
                 $parametersData = array();
                 foreach ($bindingType->getParameters() as $parameter) {
                     $paramData = new stdClass();
                     if ($parameter->getDescription()) {
                         $paramData->description = $parameter->getDescription();
                     }
                     if ($parameter->isRequired()) {
                         $paramData->required = true;
                     }
                     if (null !== $parameter->getDefaultValue()) {
                         $paramData->default = $parameter->getDefaultValue();
                     }
                     $parametersData[$parameter->getName()] = $paramData;
                 }
                 ksort($parametersData);
                 $typeData->parameters = (object) $parametersData;
             }
             $bindingTypesData[$bindingType->getName()] = $typeData;
         }
         ksort($bindingTypesData);
         $jsonData['binding-types'] = (object) $bindingTypesData;
     }
     if (count($overrides) > 0) {
         $jsonData['override'] = count($overrides) > 1 ? $overrides : reset($overrides);
     }
     if (count($extra) > 0) {
         $jsonData['extra'] = (object) $extra;
     }
 }
 protected function populateRootManager()
 {
     $this->rootPackageFile->setExtraKey(AssetPlugin::INSTALLERS_KEY, (object) array('symlink' => (object) array('class' => 'SymlinkInstaller'), 'copy' => (object) array('class' => 'CopyInstaller')));
     $this->packageFile1->setExtraKey(AssetPlugin::INSTALLERS_KEY, (object) array('rsync' => (object) array('class' => 'RsyncInstaller')));
 }
 private function assertMinimalConfig(PackageFile $packageFile)
 {
     $this->assertNull($packageFile->getPackageName());
     $this->assertSame(array(), $packageFile->getPathMappings());
     $this->assertSame(array(), $packageFile->getBindingDescriptors());
     $this->assertSame(array(), $packageFile->getOverriddenPackages());
 }
Beispiel #11
0
 public function testHasExtraKeys()
 {
     $packageFile = new PackageFile();
     $this->assertFalse($packageFile->hasExtraKeys());
     $packageFile->setExtraKey('key', null);
     $this->assertTrue($packageFile->hasExtraKey('key'));
     $packageFile->clearExtraKeys();
     $this->assertFalse($packageFile->hasExtraKeys());
 }
 protected function populateRootManager()
 {
     $this->rootPackageFile->setExtraKey(PackageFileInstallerManager::INSTALLERS_KEY, (object) array('custom-symlink' => (object) array('class' => 'CustomSymlinkInstaller'), 'custom-copy' => (object) array('class' => 'CustomCopyInstaller')));
     $this->packageFile1->setExtraKey(PackageFileInstallerManager::INSTALLERS_KEY, (object) array('rsync' => (object) array('class' => 'RsyncInstaller')));
 }
 private function jsonToPackageFile(stdClass $jsonData, PackageFile $packageFile)
 {
     if (isset($jsonData->name)) {
         $packageFile->setPackageName($jsonData->name);
     }
     if (isset($jsonData->{'path-mappings'})) {
         foreach ($jsonData->{'path-mappings'} as $path => $relativePaths) {
             $packageFile->addPathMapping(new PathMapping($path, (array) $relativePaths));
         }
     }
     if (isset($jsonData->bindings)) {
         foreach ($jsonData->bindings as $uuid => $bindingData) {
             $binding = null;
             $class = isset($bindingData->_class) ? $bindingData->_class : 'Puli\\Discovery\\Binding\\ResourceBinding';
             // Move this code to external classes to allow use of custom
             // bindings
             switch ($class) {
                 case 'Puli\\Discovery\\Binding\\ClassBinding':
                     $binding = new ClassBinding($bindingData->class, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), Uuid::fromString($uuid));
                     break;
                 case 'Puli\\Discovery\\Binding\\ResourceBinding':
                     $binding = new ResourceBinding($bindingData->query, $bindingData->type, isset($bindingData->parameters) ? (array) $bindingData->parameters : array(), isset($bindingData->language) ? $bindingData->language : 'glob', Uuid::fromString($uuid));
                     break;
                 default:
                     continue;
             }
             $packageFile->addBindingDescriptor(new BindingDescriptor($binding));
         }
     }
     if (isset($jsonData->{'binding-types'})) {
         foreach ((array) $jsonData->{'binding-types'} as $typeName => $data) {
             $parameters = array();
             $parameterDescriptions = array();
             if (isset($data->parameters)) {
                 foreach ((array) $data->parameters as $parameterName => $parameterData) {
                     $required = isset($parameterData->required) ? $parameterData->required : false;
                     $parameters[] = new BindingParameter($parameterName, $required ? BindingParameter::REQUIRED : BindingParameter::OPTIONAL, isset($parameterData->default) ? $parameterData->default : null);
                     if (isset($parameterData->description)) {
                         $parameterDescriptions[$parameterName] = $parameterData->description;
                     }
                 }
             }
             $packageFile->addTypeDescriptor(new BindingTypeDescriptor(new BindingType($typeName, $parameters), isset($data->description) ? $data->description : null, $parameterDescriptions));
         }
     }
     if (isset($jsonData->override)) {
         $packageFile->setOverriddenPackages((array) $jsonData->override);
     }
     if (isset($jsonData->extra)) {
         $packageFile->setExtraKeys((array) $jsonData->extra);
     }
 }