コード例 #1
0
ファイル: PackageLoader.php プロジェクト: newup/core
 /**
  * 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';
 }
コード例 #2
0
ファイル: HelpersTest.php プロジェクト: newup/core
 public function testAddingPsr4AddsEntry()
 {
     $loader = get_composer_loader();
     $currentPsr4Count = count($loader->getPrefixesPsr4());
     add_psr4('Test\\Test\\', '.');
     $newPsr4Count = count($loader->getPrefixesPsr4());
     $this->assertNotEquals($currentPsr4Count, $newPsr4Count);
     $this->assertArrayHasKey('Test\\Test\\', $loader->getPrefixesPsr4());
 }