Write the stub ServiceProvider for the package.

@param  \Fly\Workbench\Package  $package
@param  string  $directory
@return void
430566
public function writeServiceProvider(Package $package, $directory, $plain)
	{
		// Once we have the service provider stub, we will need to format it and make
		// the necessary replacements to the class, namespaces, etc. Then we'll be
		// able to write it out into the package's workbench directory for them.
		$stub = $this->getProviderStub($package, $plain);

		$this->writeProviderStub($package, $directory, $stub);
	}
230528
public static function enablePackage(PackageInterface $package)
    {
        $packageRepository = Factory::makePackageRepository($package);
        $bundleFactory = Factory::makeBundleFactory();
        $kernelManipulator = Factory::makeKernelManipulator();

        $composerPackage = $packageRepository->findOneByName($package->getName());
        $bundle = $bundleFactory->make($composerPackage->namespace);

        $kernelManipulator->addBundle($bundle->fullyQualifiedClassname);
    }
1278591
protected function processPackage(Package $package)
    {
        $extra = $package->getExtra();
        $files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
        $this->originalFiles[$package->getPrettyName()] = $files;

        if (is_array($files)) {
            $this->addFiles($package, $files);
        }
        if ($package->isRoot()) {
            $this->loadDotEnv($package);
            if (!empty($extra[self::EXTRA_DEV_OPTION_NAME])) {
                $this->addFiles($package, $extra[self::EXTRA_DEV_OPTION_NAME]);
            }
        }

        $aliases = $package->collectAliases();

        $this->builder->mergeAliases($aliases);
        $this->builder->setPackage($package->getPrettyName(), array_filter([
            'name' => $package->getPrettyName(),
            'version' => $package->getVersion(),
            'reference' => $package->getSourceReference() ?: $package->getDistReference(),
            'aliases' => $aliases,
        ]));
    }
559820
public function updatePackage(PackageInterface $package, InstallerInterface $installer)
    {
        if (!$this->isPackageInstalled($package)) {
            throw new RuntimeException(sprintf('Package %s is not installed.', $package->getName()));
        }
        if (is_null($package->getRequiredVersion())) {
            $decode = $this->config->getBowerFileContent();
            if (empty($decode['dependencies']) || empty($decode['dependencies'][$package->getName()])) {
                throw new InvalidArgumentException(sprintf('Package %s not found in bower.json', $package->getName()));
            }
            $package->setRequiredVersion($decode['dependencies'][$package->getName()]);
        }

        $bower = $this->config->getPackageBowerFileContent($package);
        $package->setInfo($bower);
        $package->setVersion($bower['version']);
        $package->setRequires(isset($bower['dependencies']) ? $bower['dependencies'] : null);

        $packageTag = $this->getPackageTag($package);
        $this->output->writelnInfoPackage($package, 'validate', sprintf('%s against %s#%s', $packageTag, $package->getName(), $package->getRequiredVersion()));

        $package->setRepository($this->repository);
        if ($packageTag == $package->getVersion()) {
            // if version is fully matching, there's no need to update
            return;
        }
        $package->setVersion($packageTag);

        $this->cachePackage($package);

        $this->output->writelnUpdatingPackage($package);
        $installer->update($package);

        $overrides = $this->config->getOverrideFor($package->getName());
        if (array_key_exists('dependencies', $overrides)) {
            $dependencies = $overrides['dependencies'];
        } else {
            $dependencies = $package->getRequires();
        }
        if (!empty($dependencies)) {
            foreach ($dependencies as $name => $requiredVersion) {
                $depPackage = new Package($name, $requiredVersion);
                if (!$this->isPackageInstalled($depPackage)) {
                    $this->installPackage($depPackage, $installer, true);
                } elseif ($this->isNeedUpdate($depPackage)) {
                    $this->updatePackage($depPackage, $installer);
                }
            }
        }
    }
496201
protected function writeSupportDirectory(Package $package, $support, $directory)
	{
		// Once we create the source directory, we will write an empty file to the
		// directory so that it will be kept in source control allowing the dev
		// to go ahead and push these components to Github right on creation.
		$path = $directory.'/src/'.$support;

		$this->files->makeDirectory($path, 0777, true);

		$this->files->put($path.'/.gitkeep', '');
	}
789028
private function checkInstallationDirectory($directory)
    {
        if ($this->installationAttempts >= $this->breakAtInstallationAttempt) {
            $this->log->error('Installation directory checks failed at max attempts', ['attempts' => $this->installationAttempts]);
            throw new PackageInstallationException(null, "The package template could not be installed.");
        }

        $files       = $this->files->allFiles($directory);
        $directories = $this->files->directories($directory);

        if (count($files) == 0 && count($directories) == 0) {
            return;
        }

        $directoriesReadable = true;
        $filesReadable       = true;

        foreach ($directories as $directory) {
            if (!$this->files->isReadable($directory)) {
                $this->log->error('Unreadable directory preventing Composer install', ['directory' => $directory]);
                $directoriesReadable = false;
            }
        }

        foreach ($files as $file) {
            if (!$this->files->isReadable($file->getPathname())) {
                $this->log->error('Unreadable file preventing Composer install', ['file' => $file]);
                $filesReadable = false;
            }
        }

        if (!$directoriesReadable || !$filesReadable) {
            $this->log->critical('Unreadable files/directories, cannot proceed with install.');
            throw new InvalidInstallationDirectoryException(null,
                "The installation directory ({$directory}) is not empty and could not be cleared due to a permissions issue. Please manually remove all files from the directory and try again.");
        }

        if (!$this->files->isWritable($directory)) {
            $this->log->critical('Installation directory is not writeable by NewUp. Cannot proceed with install.', ['directory' => $directory, 'permissions' => fileperms($directory)]);
            throw new InvalidInstallationDirectoryException(null,
                "The installation directory ({$directory}) is not writeable by the NewUp process.");
        }

        // At this point, there is no clear reason why the preparation
        // did not succeed. Because of this, we will try again.
        $this->installationAttempts++;
        $this->log->debug('Installation attempt incremented', ['directory' => $directory, 'attempt' => $this->installationAttempts]);
        $this->prepareInstallationDirectory($directory);
    }
355314
protected function installNodePackage( $directory, OutputInterface $output, $package, $version = null, $dev = false ) {
		$package_manager = new Proxy();

		if ( $package_manager->installed( $directory, $package ) ) {
			throw new RuntimeException( 'Package is already installed.' );
		}

		$package_manager->install( $directory, $output, $package, $version, $dev );
	}
352343
public function package($package, $hint = null, $namespace = null)
    {
        $namespace = $this->getPackageNamespace($package, $namespace);
        $hint = $hint ? $hint : $package->getPackagePath() . '/' . DIRNAME_CONFIG;
        $this->packages[] = $namespace;
        $this->addNamespace($namespace, $hint);
    }
334105
protected function publishAssets($package)
    {
        if (! $this->dispatcher->hasNamespace($package)) {
            return $this->error('Package does not exist.');
        }

        if ( ! is_null($path = $this->getPath())) {
            $this->publisher->publish($package, $path);
        } else {
            $path = $this->dispatcher->getPackagePath($package);

            $this->publisher->publishPackage($package, $path);
        }

        $this->output->writeln('<info>Assets published for package:</info> ' .$package);
    }
577892
public function addComposerPackageFromDirectory(Dir $dir) {
    $package = $this->getComposerPackageReader()->fromDirectory($dir);
    
    $this->addPackage($package);
    
    return $package;
  }
846699
protected function iteratePackage(Package $package, $includingDev = false)
    {
        $name = $package->getPrettyName();

        /// prevent infinite loop in case of circular dependencies
        static $processed = [];
        if (isset($processed[$name])) {
            return;
        } else {
            $processed[$name] = 1;
        }

        /// package depth in dependency hierarchy
        static $depth = 0;
        ++$depth;

        $this->iterateDependencies($package);
        if ($includingDev) {
            $this->iterateDependencies($package, true);
        }
        if (!isset($this->orderedList[$name])) {
            $this->orderedList[$name] = $depth;
        }

        --$depth;
    }
1356432
private function getFileMap(PackageInterface $package, $directory)
    {
        $files = [];
        $root  = $this->getInstallPath($package);

        if (!file_exists($root . '/' . $directory)) {
            return [];
        }

        $iterator = new RecursiveDirectoryIterator($root . '/' . $directory, RecursiveDirectoryIterator::SKIP_DOTS);

        /** @var SplFileInfo $file */
        foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            if ($file->isFile()) {
                $path = str_replace($root . '/' . $directory . '/', '', $file->getPathname());

                $files[$directory . '/' . $path] = $path;
            }
        }

        return $files;
    }
1012276
protected function removePackageVendorSymlink(PackageInterface $package)
    {
        if (
            $this->config->isSymlinkEnabled()
            && $this->filesystem->removeSymlink($this->getPackageVendorSymlink($package))
        ) {
            $this->io->write(array(
                '  - Deleting symlink for <info>' . $package->getPrettyName() . '</info> '
                . '(<fg=yellow>' . $package->getPrettyVersion() . '</fg=yellow>)',
                ''
            ));

            $symlinkParentDirectory = dirname($this->getPackageVendorSymlink($package));
            $this->filesystem->removeEmptyDirectory($symlinkParentDirectory);
        }
    }
19978
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';
    }
1259713
protected function addRunonces(PackageInterface $package, array $files)
    {
        $rootDir = $this->getInstallPath($package);

        foreach ($files as $file) {
            $this->runonceManager->addFile($this->filesystem->normalizePath($rootDir . '/' . $file));
        }
    }
1237212
protected function runCreator($package)
	{
		$path = $this->flyphp['path.base'].'/workbench';

		$plain = ! $this->option('resources');

		return $this->creator->create($package, $path, $plain);
	}
1133967
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) {
        parent::install($repo, $package);
        $instructions = $this->getInstructions($package);
        if (!$instructions || empty($instructions['install'])) { return; }
        $this->handleInstructions($package, $instructions['install']);
    }