Ejemplo n.º 1
0
 /**
  * Loads a package from a given directory.
  *
  * This function returns the string of the primary package class.
  *
  * @throws InvalidPathException Thrown when the package directory
  *                              does not exist.
  * @throws NewUpException
  * @param  $directory
  * @return string
  */
 public function loadPackage($directory)
 {
     if (!$this->files->exists($directory)) {
         throw new InvalidPathException("The directory {$directory} does not exist.");
     }
     if (!$this->files->exists($directory . '/composer.json')) {
         throw new InvalidPathException("There is no composer.json file in {$directory}");
     }
     if (!$this->files->exists($directory . '/_newup')) {
         throw new InvalidPathException("There is no _newup directory in {$directory}");
     }
     if (!$this->files->exists($directory . '/_newup/Package.php')) {
         throw new InvalidPathException("A Package.php file must be present in in \"_newup\" directory.");
     }
     $package = Package::fromFile($directory . '/composer.json', user_config('configuration.strictComposerValues', true));
     $namespace = package_vendor_namespace($package->getVendor(), $package->getPackage(), true);
     add_psr4($namespace, $directory . '/_newup');
     if (!class_exists($namespace . 'Package', true)) {
         throw new NewUpException("A valid reachable class named 'Package' must be defined.");
     }
     if (!is_subclass_of($namespace . 'Package', BasePackageTemplate::class)) {
         throw new NewUpException("The 'Package' class must extend " . BasePackageTemplate::class);
     }
     return $namespace . 'Package';
 }
Ejemplo n.º 2
0
 public function testPackageFromFileSetsDataCorrectly()
 {
     $package = Package::fromFile(getFixturePath('Package/composer.json'));
     $this->assertEquals($package->getVendor(), 'vendor');
     $this->assertEquals($package->getPackage(), 'package');
     $this->assertEquals($package->getDescription(), 'An example');
     $this->assertEquals($package->getLicense(), 'MIT');
     $this->assertCount(1, $package->getAuthors());
 }
Ejemplo n.º 3
0
 /**
  * Gets the details for a given package, based on a given path.
  *
  * @param $path
  * @return array
  */
 private function getPackageDetails($path)
 {
     $packagePath = $this->normalizePath($path);
     $packageName = explode(DIRECTORY_SEPARATOR, $packagePath);
     $packageName = end($packageName);
     $packageVersion = null;
     if (Str::endsWith($packageName, '}')) {
         // Version, handle it specially.
         $packageName = str_replace('_{updating_in_progress}', '', $packageName);
         $parts = null;
         $parts = explode('{', $packageName, 2);
         $packageName = rtrim($parts[0], '_');
         if (isset($parts[1])) {
             $packageVersion = rtrim($parts[1], '}');
         }
     }
     $packageDetails = ['package' => $packageName, 'version' => $packageVersion, 'instance' => Package::fromFile($path . DIRECTORY_SEPARATOR . 'composer.json', false), 'path' => $packagePath];
     return $packageDetails;
 }