/** * {@inheritdoc} */ public function activate(Composer $composer, IOInterface $io) { foreach (static::$types as $type) { $installer = new WordpressInstaller($io, $composer, $type); $composer->getInstallationManager()->addInstaller($installer); } }
public function processCopy(array $config) { $config = $this->processConfig($config); $project_path = \realpath($this->composer->getConfig()->get('vendor-dir') . '/../') . '/'; $debug = $config['debug']; if ($debug) { $this->io->write('[sasedev/composer-plugin-filecopier] basepath : ' . $project_path); } $destination = $config['destination']; if (\strlen($destination) == 0 || \strlen($destination) != 0 && !$this->startsWith($destination, '/')) { $destination = $project_path . $destination; } if (false === \realpath($destination)) { mkdir($destination, 0755, true); } $destination = \realpath($destination); $source = $config['source']; if ($debug) { $this->io->write('[sasedev/composer-plugin-filecopier] init source : ' . $source); $this->io->write('[sasedev/composer-plugin-filecopier] init destination : ' . $destination); } $sources = \glob($source, GLOB_MARK); if (!empty($sources)) { foreach ($sources as $newsource) { $this->copyr($newsource, $destination, $project_path, $debug); } } }
/** * Runs the project configurator. * * @return void */ public function run() { $namespace = $this->ask('Namespace', function ($namespace) { return $this->validateNamespace($namespace); }, 'App'); $packageName = $this->ask('Package name', function ($packageName) { return $this->validatePackageName($packageName); }, $this->suggestPackageName($namespace)); $license = $this->ask('License', function ($license) { return trim($license); }, 'proprietary'); $description = $this->ask('Description', function ($description) { return trim($description); }, ''); $file = new JsonFile('./composer.json'); $config = $file->read(); $config['name'] = $packageName; $config['license'] = $license; $config['description'] = $description; $config['autoload']['psr-4'] = [$namespace . '\\' => 'src/']; $config['autoload-dev']['psr-4'] = [$namespace . '\\Tests\\' => 'tests/']; unset($config['scripts']['post-root-package-install']); $config['extra']['branch-alias']['dev-master'] = '1.0-dev'; $file->write($config); $this->composer->setPackage(Factory::create($this->io, null, true)->getPackage()); // reload root package $filesystem = new Filesystem(); $filesystem->removeDirectory('./app/Distribution'); }
public function activate(Composer $composer, IOInterface $io) { $this->io = $io; $vendor = $composer->getConfig()->get('vendor-dir', '/'); $this->vendor = $vendor; $this->root = dirname($vendor); }
public function setUp() { $this->config = $this->getMock('Composer\Config'); $this->config->expects($this->any()) ->method('get') ->will($this->returnCallback(function ($key) { switch ($key) { case 'cache-repo-dir': return sys_get_temp_dir() . '/composer-test-repo-cache'; case 'vendor-dir': return sys_get_temp_dir() . '/composer-test/vendor'; } return null; })); $this->rootPackage = $this->getMock('Composer\Package\RootPackageInterface'); $this->package = $this->getMock('Composer\Package\PackageInterface'); $this->package->expects($this->any()) ->method('getName') ->will($this->returnValue('foo-asset/foo')); $this->composer = $this->getMock('Composer\Composer'); $this->composer->expects($this->any()) ->method('getPackage') ->will($this->returnValue($this->rootPackage)); $this->composer->expects($this->any()) ->method('getConfig') ->will($this->returnValue($this->config)); }
public function testSetGetInstallationManager() { $composer = new Composer(); $manager = $this->getMock('Composer\\Installer\\InstallationManager'); $composer->setInstallationManager($manager); $this->assertSame($manager, $composer->getInstallationManager()); }
/** * @param Composer $composer * @param IOInterface $io */ public function activate(Composer $composer, IOInterface $io) { $repositoryManager = $composer->getRepositoryManager(); $extra = $composer->getPackage()->getExtra(); if (!isset($extra['connect-packages'])) { return; } $versionParser = new VersionParser(); $links = []; foreach ($extra['connect-packages'] as $connectPackage => $version) { try { $releases = $this->getVersionsForPackage($connectPackage); } catch (InvalidArgumentException $e) { $message = '<error>Could not find release manifest for module with extension key: "%s". '; $message .= 'Did you get the casing right? Error: "%s"</error>'; $io->writeError(sprintf($message, $connectPackage, $e->getMessage()), true); continue; } catch (UnexpectedValueException $e) { $message = '<error>Non valid XML return from connect for module with extension key: "%s".</error>'; $message .= $e->getMessage(); $io->writeError(sprintf($message, $connectPackage), true); continue; } $repository = $this->addPackages($releases, $connectPackage); $repositoryManager->addRepository($repository); $constraint = $versionParser->parseConstraints($version); $links[] = new Link($composer->getPackage()->getName(), $connectPackage, $constraint); } if (!empty($links)) { $requires = $composer->getPackage()->getRequires(); $requires = array_merge($requires, $links); $composer->getPackage()->setRequires($requires); } }
/** * {@inheritDoc} */ public function activate(Composer $composer, IOInterface $io) { $pluginInstaller = new PluginInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($pluginInstaller); //$themeInstaller = new ThemeInstaller($io, $composer); //$composer->getInstallationManager()->addInstaller($themeInstaller); }
/** * Test getLocations returning appropriate values based on CakePHP version * */ public function testGetLocations() { $package = new RootPackage('CamelCased', '1.0', '1.0'); $composer = new Composer(); $rm = new RepositoryManager($this->getMock('Composer\\IO\\IOInterface'), $this->getMock('Composer\\Config')); $composer->setRepositoryManager($rm); $installer = new CakePHPInstaller($package, $composer); // 2.0 < cakephp < 3.0 $this->setCakephpVersion($rm, '2.0.0'); $result = $installer->getLocations(); $this->assertContains('Plugin/', $result['plugin']); $this->setCakephpVersion($rm, '2.5.9'); $result = $installer->getLocations(); $this->assertContains('Plugin/', $result['plugin']); $this->setCakephpVersion($rm, '~2.5'); $result = $installer->getLocations(); $this->assertContains('Plugin/', $result['plugin']); // special handling for 2.x versions when 3.x is still in development $this->setCakephpVersion($rm, 'dev-master'); $result = $installer->getLocations(); $this->assertContains('Plugin/', $result['plugin']); $this->setCakephpVersion($rm, '>=2.5'); $result = $installer->getLocations(); $this->assertContains('Plugin/', $result['plugin']); // cakephp >= 3.0 $this->setCakephpVersion($rm, '3.0.*-dev'); $result = $installer->getLocations(); $this->assertContains('plugins/', $result['plugin']); $this->setCakephpVersion($rm, '~8.8'); $result = $installer->getLocations(); $this->assertContains('plugins/', $result['plugin']); }
public function activate(Composer $composer, IOInterface $io) { // Add the Innomatic legacy platform installer $composer->getInstallationManager()->addInstaller(new LegacyPlatformInstaller($io, $composer)); // Add the Innomatic legacy application installer $composer->getInstallationManager()->addInstaller(new LegacyApplicationInstaller($io, $composer)); }
/** * @param \Composer\Composer $composer * @param \Composer\Util\Filesystem $filesystem */ public function __construct(\Composer\Composer $composer, \Composer\Util\Filesystem $filesystem = NULL) { $this->composer = $composer; $this->downloadManager = $composer->getDownloadManager(); $this->filesystem = $filesystem ?: new \Composer\Util\Filesystem(); $this->extensionDir = self::TYPO3_CONF_DIR . DIRECTORY_SEPARATOR . self::TYPO3_EXT_DIR; }
private function createComposerInstance() { $composer = new Composer(); $config = new Config(); $composer->setConfig($config); return $composer; }
public static function getPackageInstallPath(PackageInterface $package, Composer $composer) { $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $availableVars = compact('name', 'vendor'); $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $availableVars['name'] = $extra['installer-name']; } if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['installer-paths'])) { $customPath = self::mapCustomInstallPaths($extra['installer-paths'], $prettyName); if (false !== $customPath) { return self::templatePath($customPath, $availableVars); } } } return NULL; }
/** * Call extra recursive * @param Composer $composer * @param IExtra $extra */ private function callRecursive(Composer $composer, IExtra $extra) { $extra->run($composer->getPackage(), true); foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) { $extra->run($package, false); } }
/** * @param PackageEvent $event */ public function __invoke(PackageEvent $event) { $publicPath = sprintf('%s/public', $this->projectPath); if (!is_dir($publicPath)) { // No public path in the project; nothing to remove return; } $gitignoreFile = sprintf('%s/.gitignore', $publicPath); if (!file_exists($gitignoreFile)) { // No .gitignore rules; nothing to remove return; } $package = $event->getOperation()->getPackage(); $installer = $this->composer->getInstallationManager(); $packagePath = $installer->getInstallPath($package); $packageConfigPath = sprintf('%s/config/module.config.php', $packagePath); if (!file_exists($packageConfigPath)) { // No module configuration defined; nothing to remove return; } $packageConfig = (include $packageConfigPath); if (!is_array($packageConfig) || !isset($packageConfig['asset_manager']['resolver_configs']['paths']) || !is_array($packageConfig['asset_manager']['resolver_configs']['paths'])) { // No assets defined; nothing to remove return; } $this->gitignore = $this->fetchIgnoreRules($gitignoreFile); $paths = $packageConfig['asset_manager']['resolver_configs']['paths']; foreach ($paths as $path) { $this->removeAssets($path, $publicPath); } file_put_contents($gitignoreFile, implode("\n", $this->gitignore)); }
public function activate(Composer $composer, IO\IOInterface $io) { $this->composer = $composer; $this->config = $composer->getConfig(); $this->io = $io; $this->pluginConfig = $this->setPluginConfig(); }
public static function getConsoleCommands(Composer $composer) { $commands = array(array('yiic', 'migrate')); if ($composer->getPackage()) { $extra = $composer->getPackage()->getExtra(); if (!empty($extra['yiicomposer-console-commands'])) { $tmp = $extra['yiicomposer-console-commands']; } if (!empty($tmp)) { $commands = array(); foreach ($tmp as $c) { $command = array(); $command[] = 'yiic'; $command[] = $c['controller']; if (!empty($c['action'])) { $command[] = $c['action']; } if (!empty($c['params'])) { $command = array_merge($command, $c['params']); } if (!empty($c['params'])) { foreach ($c['params'] as $k => $v) { $command[] = '--' . $k . '=' . $v; } } $commands[] = $command; } } } return $commands; }
public function __construct(PackageInterface $package = null, Composer $composer = null, IOInterface $io = null) { if (null === $package) { $package = $composer->getPackage(); } $extraOxidRoot = $extraModuleVendor = false; if (null !== $package) { $extra = $package->getExtra(); if (isset($extra['oxid-root'])) { foreach ($this->locations as $name => $location) { $this->locations[$name] = "{$extra['oxid-root']}/{$location}"; } $extraOxidRoot = true; } if (isset($extra['module-vendor'])) { $this->locations['module'] = str_replace('modules/', "modules/{$extra['module-vendor']}/", $this->locations['module']); $extraModuleVendor = true; } } $composerPackage = $composer->getPackage(); if (null !== $composerPackage) { $extra = $composerPackage->getExtra(); if (isset($extra['oxid-root']) && !$extraOxidRoot) { foreach ($this->locations as $name => $location) { $this->locations[$name] = "{$extra['oxid-root']}/{$location}"; } } if (isset($extra['module-vendor']) && !$extraModuleVendor) { $this->locations['module'] = str_replace('modules/', "modules/{$extra['module-vendor']}/", $this->locations['module']); } } parent::__construct($package, $composer, $io); }
/** * Apply plugin modifications to composer * TODO: If we get updated by composer there will be 2 instances afterwards. * The old as Xinc\Composer\Plugin and the new one as Xinc\Composer\Plugin_composer_tmp0 * So we activate 2 Installer. * * @param Composer $composer * @param IOInterface $io * @return void */ public function activate(Composer $composer, IOInterface $io) { // Register our own installer $composer->getInstallationManager()->addInstaller(new Installer($io, $composer)); $this->composer = $composer; $this->io = $io; }
/** * @param \Composer\Composer * @param string * @param string */ public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer') { $installationManager = $composer->getInstallationManager(); $localRepo = $composer->getRepositoryManager()->getLocalRepository(); $mainPackage = $composer->getPackage(); $config = $composer->getConfig(); $filesystem = new Filesystem(); $basePath = $filesystem->normalizePath(realpath(getcwd())); $vendorPath = $filesystem->normalizePath(realpath($config->get('vendor-dir'))); $targetDir = $vendorPath . '/' . $targetDir; $vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true); $vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode); $appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true); $appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode); $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages()); $autoloads = $this->parseAutoloads($packageMap, $mainPackage); $paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage); $autoloads['files'] = array_merge($paths, $autoloads['files']); $includeFilesFilePath = $targetDir . '/autoload_files.php'; if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { file_put_contents($includeFilesFilePath, $includeFilesFileContents); } elseif (file_exists($includeFilesFilePath)) { unlink($includeFilesFilePath); } }
/** * Returns the PhantomJS version number. * * Firstly, we search for a version number in the local repository, * secondly, in the root package. * A version specification of "dev-master#<commit-reference>" is disallowed. * * @param Composer $composer * @return string $version Version */ public static function getVersion($composer) { $packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages(); $os = self::getOS(); foreach ($packages as $package) { if ($package->getName() === 'triplekdev/phantomjs-installer') { $version = $package->getPrettyVersion(); } } // version was not found in the local repository, let's take a look at the root package if ($version == null) { $version = self::getRequiredVersion($composer->getPackage(), 'triplekdev/phantomjs-installer'); } // fallback to a hardcoded version number, if "dev-master" was set if ($version === 'dev-master') { return $os === 'macosx' ? '2.0.1' : '1.9.8'; } // grab version from commit-reference, e.g. "dev-master#<commit-ref> as version" if (preg_match('/dev-master#(?:.*)(\\d.\\d.\\d)/i', $version, $matches)) { return $matches[1]; } // grab version from a git version tag with a patch level, like "1.9.8-2" if (preg_match('/(\\d.\\d.\\d)(?:(?:-\\d)?)/i', $version, $matches)) { return $matches[1]; } // grab version from a Composer patch version tag with a patch level, like "1.9.8-p02" if (preg_match('/(\\d.\\d.\\d)(?:(?:-p\\d{2})?)/i', $version, $matches)) { return $matches[1]; } return $version; }
/** * Activate Wordpress plugin * * @param Composer $composer Composer * @param IOInterface $io IO * * @return void */ public function activate(Composer $composer, IOInterface $io) { $this->package = $composer->getPackage(); $this->io = $io; // TODO: get the project root - must be a better way to do this $this->projectRoot = realpath(dirname($composer->getConfig()->get('vendor-dir'))); }
/** * @inheritdoc */ public function activate(Composer $composer, IOInterface $io) { $this->io = $io; //Extend download manager $dm = $composer->getDownloadManager(); $executor = new ProcessExecutor($io); $fs = new Filesystem($executor); $config = $composer->getConfig(); $dm->setDownloader('svn-export', new Downloader($io, $config, $executor, $fs)); //Extend RepositoryManager Classes $rm = $composer->getRepositoryManager(); $rm->setRepositoryClass('svn-export', 'LinearSoft\\Composer\\SvnExport\\Repository\\VcsRepository'); $rm->setRepositoryClass('svn-export-composer', 'LinearSoft\\Composer\\SvnExport\\Repository\\ComposerRepository'); //Load Extra Data $extra = $composer->getPackage()->getExtra(); if (isset($extra['svn-export-repositories']) && is_array($extra['svn-export-repositories'])) { foreach ($extra['svn-export-repositories'] as $index => $repoConfig) { $this->validateRepositories($index, $repoConfig); if (isset($repoConfig['name'])) { $name = $repoConfig['name']; } else { $name = is_int($index) ? preg_replace('{^https?://}i', '', $repoConfig['url']) : $index; } if ($repoConfig['type'] === 'svn') { $repoConfig['type'] = 'svn-export'; } else { $repoConfig['type'] = 'svn-export-composer'; } $repo = $rm->createRepository($repoConfig['type'], $repoConfig); $rm->addRepository($repo); $this->io->write("Added SvnExport repo: {$name}"); } } }
/** * Initializes library installer. * * @param IOInterface $io * @param Composer $composer * @param Filesystem $filesystem */ public function __construct(IOInterface $io, Composer $composer, Filesystem $filesystem = null) { $this->composer = $composer; $this->downloadManager = $composer->getDownloadManager(); $this->io = $io; $this->filesystem = $filesystem ?: new Filesystem(); }
public function setUp() { $composer = new Composer(); $composer->setConfig(new Config()); $io = $this->getMock('Composer\\IO\\IOInterface'); $this->installer = new Installer($io, $composer); }
public function activate(Composer $composer, IO\IOInterface $io) { // @codeCoverageIgnoreStart // guard for self-update problem if (__CLASS__ !== 'Hirak\\Prestissimo\\Plugin') { return $this->disable(); } // @codeCoverageIgnoreEnd // load all classes foreach (self::$pluginClasses as $class) { class_exists(__NAMESPACE__ . '\\' . $class); } $this->io = $io; $this->config = $composer->getConfig(); $this->package = $composer->getPackage(); if (array_key_exists('argv', $GLOBALS)) { foreach ($GLOBALS['argv'] as $arg) { switch ($arg) { case 'create-project': case 'update': case 'outdated': case 'require': $this->prefetchComposerRepositories(); break 2; case 'install': if (file_exists('composer.json') && !file_exists('composer.lock')) { $this->prefetchComposerRepositories(); } break 2; } } } }
/** * Activates plugin and registers installer. * * @param Composer $composer Composer instance. * @param IOInterface $ioc I/O controller * * @return void * @since 0.1.0 */ public function activate(Composer $composer, IOInterface $ioc) { $installer = new Installer($ioc, $composer); /** @type InstallationManager $manager */ $manager = $composer->getInstallationManager(); $manager->addInstaller($installer); }
/** * Get the installation directory of the package. * * @param Composer $composer The composer instance * @param PackageInterface $package The package instance * @param string|null $installDir The custom installation directory * * @return string The installation directory */ protected static function getInstallDir(Composer $composer, PackageInterface $package, $installDir = null) { if (null === $installDir) { $installDir = rtrim($composer->getConfig()->get('vendor-dir'), '/') . '/' . $package->getName(); } return rtrim($installDir, '/'); }
/** * finds a list of packages which depend on another package * * @param InputInterface $input * @param OutputInterface $output * @param Composer $composer * @return array * @throws \InvalidArgumentException */ private function getReferences(InputInterface $input, OutputInterface $output, Composer $composer) { $needle = $input->getArgument('package'); $references = array(); $verbose = (bool) $input->getOption('verbose'); $repos = $composer->getRepositoryManager()->getRepositories(); $types = $input->getOption('link-type'); foreach ($repos as $repository) { foreach ($repository->getPackages() as $package) { foreach ($types as $type) { $type = rtrim($type, 's'); if (!isset($this->linkTypes[$type])) { throw new \InvalidArgumentException('Unexpected link type: ' . $type . ', valid types: ' . implode(', ', array_keys($this->linkTypes))); } foreach ($package->{'get' . $this->linkTypes[$type]}() as $link) { if ($link->getTarget() === $needle) { if ($verbose) { $references[] = array($type, $package, $link); } else { $references[$package->getName()] = $package->getPrettyName(); } } } } } } return $references; }
/** * @param string $packageName * @param boolean $expected * @dataProvider isMagentoRootDataProvider */ public function testIsMagentoRoot($packageName, $expected) { $rootPackageMock = $this->getMockForAbstractClass(\Composer\Package\RootPackageInterface::class); $this->composerMock->expects($this->once())->method('getPackage')->willReturn($rootPackageMock); $rootPackageMock->method('getName')->willReturn($packageName); $this->assertEquals($expected, $this->composerInformation->isMagentoRoot()); }