示例#1
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;
     }
 }
 /**
  * Adds support for interceptors to an atomic operation.
  *
  * @param AtomicOperation                             $operation    The operation.
  * @param OperationInterceptor|OperationInterceptor[] $interceptors The interceptor(s).
  */
 public function __construct(AtomicOperation $operation, $interceptors)
 {
     $interceptors = is_array($interceptors) ? $interceptors : array($interceptors);
     Assert::allIsInstanceOf($interceptors, __NAMESPACE__ . '\\OperationInterceptor');
     $this->operation = $operation;
     $this->interceptors = $interceptors;
 }
 /**
  * Creates a new migration manager.
  *
  * @param JsonMigration[] $migrations
  */
 public function __construct(array $migrations)
 {
     Assert::allIsInstanceOf($migrations, __NAMESPACE__ . '\\JsonMigration');
     foreach ($migrations as $migration) {
         $this->migrationsByOriginVersion[$migration->getOriginVersion()] = $migration;
         $this->migrationsByTargetVersion[$migration->getTargetVersion()] = $migration;
     }
     uksort($this->migrationsByOriginVersion, 'version_compare');
     uksort($this->migrationsByTargetVersion, 'version_compare');
 }
 /**
  * Creates a binding type descriptor.
  *
  * @param string                       $name        The name of the type.
  * @param string|null                  $description A human-readable
  *                                                  description of the type.
  * @param BindingParameterDescriptor[] $parameters  The parameters.
  *
  * @see BindingType
  */
 public function __construct($name, $description = null, array $parameters = array())
 {
     Assert::typeName($name);
     Assert::nullOrString($description, 'The description must be a string or null. Got: %s');
     Assert::nullOrNotEmpty($description, 'The description must not be empty.');
     Assert::allIsInstanceOf($parameters, __NAMESPACE__ . '\\BindingParameterDescriptor');
     $this->name = $name;
     $this->description = $description;
     foreach ($parameters as $parameter) {
         $this->parameters[$parameter->getName()] = $parameter;
     }
 }
示例#5
0
 /**
  * Creates a new installer descriptor.
  *
  * @param string               $name        The installer name.
  * @param string               $className   The fully-qualified class name
  *                                          of the installer.
  * @param string|null          $description The description of the installer.
  * @param InstallerParameter[] $parameters  The installer parameters.
  */
 public function __construct($name, $className, $description = null, array $parameters = array())
 {
     Assert::stringNotEmpty($name, 'The installer name must be a non-empty string. Got: %s');
     Assert::stringNotEmpty($className, 'The installer class must be a non-empty string. Got: %s');
     Assert::nullOrStringNotEmpty($description, 'The installer description must be a non-empty string or null. Got: %s');
     Assert::allIsInstanceOf($parameters, __NAMESPACE__ . '\\InstallerParameter');
     $this->name = $name;
     $this->className = $className;
     $this->description = $description;
     foreach ($parameters as $parameter) {
         $this->parameters[$parameter->getName()] = $parameter;
     }
 }