Esempio 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';
 }
Esempio n. 2
0
 public function testPackageVendorNamespaceCombinesPartsCorrectlyForAutoloaders()
 {
     $this->assertEquals('Test\\Test\\', package_vendor_namespace('Test', 'Test', true));
     $this->assertEquals('Acme\\Package\\', package_vendor_namespace('Acme', 'Package', true));
 }
Esempio n. 3
0
 /**
  * Gets the namespaced package name.
  *
  * @return string
  */
 private function getNamespacedPackageName()
 {
     $path = $this->getTemplateArgumentPath();
     $templateName = json_decode(file_get_contents($path . 'composer.json'))->name;
     $parts = explode('/', $templateName);
     return package_vendor_namespace($parts[0], $parts[1]) . '\\Package';
 }