/** * @param array $parameters * @param array $options * * @return bool */ public function setAssetsVersion(array &$parameters, array $options) { $assetsVersion = null; $assetsVersionExists = false; $assetsVersionStrategy = null; $assetsVersionStrategyExists = false; if (array_key_exists(self::ASSETS_VERSION, $parameters)) { $assetsVersion = $parameters[self::ASSETS_VERSION]; $assetsVersionExists = true; } if (array_key_exists(self::ASSETS_VERSION_STRATEGY, $parameters)) { $assetsVersionStrategy = $parameters[self::ASSETS_VERSION_STRATEGY]; $assetsVersionStrategyExists = true; } $hasChanges = false; if (!$assetsVersionExists || !$this->isEnvironmentVariable($options, self::ASSETS_VERSION)) { $assetsVersion = $this->generateAssetsVersion($assetsVersionStrategy, $assetsVersion); if (!$assetsVersionExists || null !== $assetsVersion) { $hasChanges = true; $this->io->write(sprintf('<info>Updating the "%s" parameter</info>', self::ASSETS_VERSION)); $parameters[self::ASSETS_VERSION] = $assetsVersion; } } if (!$assetsVersionStrategyExists) { $hasChanges = true; $this->io->write(sprintf('<info>Initializing the "%s" parameter</info>', self::ASSETS_VERSION_STRATEGY)); $parameters[self::ASSETS_VERSION_STRATEGY] = $assetsVersionStrategy; } return $hasChanges; }
/** * Iterate over all files in the given directory searching for classes. * * @param \Iterator|string $path The path to search in or an iterator * @param string $whitelist Regex that matches against the file path * @param \Composer\IO\IOInterface $io * * @throws \RuntimeException When the path is neither an existing file nor directory * * @return array A class map array */ public static function createMap($path, $whitelist = null, IOInterface $io = null) { if (is_string($path)) { if (is_file($path)) { $path = array(new \SplFileInfo($path)); } elseif (is_dir($path)) { $path = Finder::create()->files()->followLinks()->name('/\\.(' . implode('|', self::$extensions) . ')$/')->in($path); } else { throw new \RuntimeException('Could not scan for classes inside "' . $path . '" which does not appear to be a file nor a folder'); } } $map = array(); /** @var \Symfony\Component\Finder\SplFileInfo $file */ foreach ($path as $file) { $filePath = $file->getRealPath(); if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), self::$extensions)) { continue; } if ($whitelist && !preg_match($whitelist, strtr($filePath, '\\', '/'))) { continue; } $classes = self::findClasses($filePath); foreach ($classes as $class) { if (!isset($map[$class])) { $map[$class] = $filePath; } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) { $io->write('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>'); } } } return $map; }
/** * @param string $targetPath * @param string $installPath * @param array $map * @param bool $isSymlink * @param bool $isRelative * * @throws IOException * @throws \InvalidArgumentException * * @api * * @quality:method [B] */ public function publish($targetPath, $installPath, array $map, $isSymlink, $isRelative) { $targetPath = rtrim($targetPath, '/'); $installPath = rtrim($installPath, '/'); $this->filesystem->mkdir($targetPath, 0777); foreach ($map as $from => $to) { $targetDir = realpath($targetPath) . '/' . $to; $sourceDir = realpath($installPath) . '/' . $from; $this->filesystem->remove($targetDir); if ($isSymlink) { $this->io->write(sprintf('Trying to install AdminLTE %s assets as symbolic links.', $from)); $originDir = $sourceDir; if ($isRelative) { $originDir = $this->filesystem->makePathRelative($sourceDir, realpath($targetPath)); } try { $this->filesystem->symlink($originDir, $targetDir); $this->io->write(sprintf('The AdminLTE %s assets were installed using symbolic links.', $from)); } catch (IOException $e) { $this->hardCopy($sourceDir, $targetDir); $this->io->write(sprintf('It looks like your system doesn\'t support symbolic links, so the AdminLTE %s assets were installed by copying them.', $from)); } } else { $this->io->write(sprintf('Installing AdminLTE %s assets as <comment>hard copies</comment>.', $from)); $this->hardCopy($sourceDir, $targetDir); } } }
public function process(Config\Template $tmpl) { /* process template if condition is not set or condition is valid */ if ($tmpl->getCondition() == null || $this->conditionValidator->isValid($tmpl->getCondition(), $this->vars)) { /* load source file */ if (is_file($tmpl->getSource())) { $content = file_get_contents($tmpl->getSource()); /* replace all vars by values */ if (is_array($this->vars)) { foreach ($this->vars as $key => $value) { $content = str_replace('${' . $key . '}', $value, $content); } } /* save destination file */ if (is_file($tmpl->getDestination()) && !$tmpl->isCanRewrite()) { $this->io->write(__CLASS__ . ": <comment>Destination file '{$tmpl->getDestination()}' is already exist and cannot be rewrote (rewrite = false).</comment>"); } else { $this->fileSaver->save($tmpl->getDestination(), $content); $this->io->write(__CLASS__ . ": <info>Destination file '{$tmpl->getDestination()}' is created from source template '{$tmpl->getSource()}'.</info>"); } } else { $this->io->writeError(__CLASS__ . ": <error>Cannot open source template ({$tmpl->getSource()}).</error>"); } } else { /* there is wrong condition for template */ $outSrc = $tmpl->getSource(); $cond = $tmpl->getCondition(); $outCond = '${' . $cond->getVar() . '}' . $cond->getOperation() . $cond->getValue(); $this->io->write(__CLASS__ . ": <comment>Skip processing of the template ({$outSrc}) because condition ({$outCond}) is 'false'.</comment>"); } }
/** * Set globally writable permissions on the "tmp" and "logs" directory. * * This is not the most secure default, but it gets people up and running quickly. * * @param string $dir The application's root directory. * @param \Composer\IO\IOInterface $io IO interface to write to console. * @return void */ public static function setFolderPermissions($dir, $io) { // Change the permissions on a path and output the results. $changePerms = function ($path, $perms, $io) { // Get current permissions in decimal format so we can bitmask it. $currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4)); if (($currentPerms & $perms) == $perms) { return; } $res = chmod($path, $currentPerms | $perms); if ($res) { $io->write('Permissions set on ' . $path); } else { $io->write('Failed to set permissions on ' . $path); } }; $walker = function ($dir, $perms, $io) use(&$walker, $changePerms) { $files = array_diff(scandir($dir), ['.', '..']); foreach ($files as $file) { $path = $dir . '/' . $file; if (!is_dir($path)) { continue; } $changePerms($path, $perms, $io); $walker($path, $perms, $io); } }; $worldWritable = bindec('0000000111'); $walker($dir . '/tmp', $worldWritable, $io); $changePerms($dir . '/tmp', $worldWritable, $io); $changePerms($dir . '/logs', $worldWritable, $io); }
/** * Return the output from the buffer io, if any is set. * * @return string|null */ protected function getOutput() { if ($this->inputOutput instanceof BufferIO) { return $this->inputOutput->getOutput(); } return null; }
protected function selectPackage(IOInterface $io, $packageName, $version = null) { $io->writeError('<info>Searching for the specified package.</info>'); if ($composer = $this->getComposer(false)) { $localRepo = $composer->getRepositoryManager()->getLocalRepository(); $repos = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories())); } else { $defaultRepos = Factory::createDefaultRepositories($this->getIO()); $io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos))); $repos = new CompositeRepository($defaultRepos); } $pool = new Pool(); $pool->addRepository($repos); $parser = new VersionParser(); $constraint = $version ? $parser->parseConstraints($version) : null; $packages = $pool->whatProvides($packageName, $constraint, true); if (count($packages) > 1) { $package = reset($packages); $io->writeError('<info>Found multiple matches, selected ' . $package->getPrettyString() . '.</info>'); $io->writeError('Alternatives were ' . implode(', ', array_map(function ($p) { return $p->getPrettyString(); }, $packages)) . '.'); $io->writeError('<comment>Please use a more specific constraint to pick a different package.</comment>'); } elseif ($packages) { $package = reset($packages); $io->writeError('<info>Found an exact match ' . $package->getPrettyString() . '.</info>'); } else { $io->writeError('<error>Could not find a package matching ' . $packageName . '.</error>'); return false; } return $package; }
/** * @static * * @param \Composer\IO\IOInterface $io * @param string $destination * * @return bool */ private static function download(\Composer\IO\IOInterface $io, $destination) { $io->write('<info>Installing jackrabbit</info>'); if (false === ($urls = self::getDownloadUrl())) { $io->write('Invalid URLs'); } else { reset($urls); $r = new RemoteFilesystem($io); do { try { $url = current($urls); $file = $destination . '/' . basename(parse_url($url, PHP_URL_PATH)); $io->write(sprintf('Retrieving Jackrabbit from "%s"', $url), true); $result = $r->copy('', $url, $file, true); } catch (\Composer\Downloader\TransportException $ex) { $io->write('', true); $result = false; $file = null; } } while (false === $result && next($urls)); if (is_null($file)) { throw new \Exception('Invalid file name'); } return $file; } return false; }
protected function handleDeprecatedType(PackageInterface $package) { $this->io->write("<warning>Package type 'patches' is deprecated ({$package}):</warning>" . " Use 'metapackage' instead."); if (method_exists($package, 'setType')) { $package->setType('metapackage'); } }
/** * @test */ public function aliasMapConfigIsExtractedFromDeprecatedKey() { $this->packageMock->expects($this->any())->method('getExtra')->willReturn(array('helhum/class-alias-loader' => array('class-alias-maps' => array('path/map.php')))); $this->IOMock->expects($this->once())->method('writeError'); $subject = new Config($this->packageMock, $this->IOMock); $this->assertSame(array('path/map.php'), $subject->get('class-alias-maps')); }
/** * The 'logical'-operation of this Installer. * PHPCS does not define constants for the config options, * doing so ourself would only lead to outdated intel. * * @see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options */ public function execute() { if ($this->io->isVerbose()) { $this->io->write('Configured phpcs to use Hostnet standard'); } self::configure(); }
public function writeToOutput() { $this->processPackages(); foreach ($this->minPackageLinks as $packageLink) { $this->io->write($this->formatPackageLink($packageLink)); } }
/** * Iterate over all files in the given directory searching for classes * * @param \Iterator|string $path The path to search in or an iterator * @param string $blacklist Regex that matches against the file path that exclude from the classmap. * @param IOInterface $io IO object * @param string $namespace Optional namespace prefix to filter by * * @throws \RuntimeException When the path is neither an existing file nor directory * @return array A class map array */ public static function createMap($path, $blacklist = null, IOInterface $io = null, $namespace = null) { if (is_string($path)) { if (is_file($path)) { $path = array(new \SplFileInfo($path)); } elseif (is_dir($path)) { $path = Finder::create()->files()->followLinks()->name('/\\.(php|inc|hh)$/')->in($path); } else { throw new \RuntimeException('Could not scan for classes inside "' . $path . '" which does not appear to be a file nor a folder'); } } $map = array(); foreach ($path as $file) { $filePath = $file->getRealPath(); if (!in_array(pathinfo($filePath, PATHINFO_EXTENSION), array('php', 'inc', 'hh'))) { continue; } if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) { continue; } $classes = self::findClasses($filePath); foreach ($classes as $class) { // skip classes not within the given namespace prefix if (null !== $namespace && 0 !== strpos($class, $namespace)) { continue; } if (!isset($map[$class])) { $map[$class] = $filePath; } elseif ($io && $map[$class] !== $filePath && !preg_match('{/(test|fixture|example|stub)s?/}i', strtr($map[$class] . ' ' . $filePath, '\\', '/'))) { $io->writeError('<warning>Warning: Ambiguous class resolution, "' . $class . '"' . ' was found in both "' . $map[$class] . '" and "' . $filePath . '", the first will be used.</warning>'); } } } return $map; }
private static function installDependencies(IOInterface $io, $folder) { $io->write("[0;32mInstalling front end dependencies from package.json[0m"); $proc = new ProcessExecutor(); $proc->execute('cd ' . $folder . ' && npm install'); $io->write("[0;32mFront end dependencies installed[0m"); }
/** * Update the main config * * @param IOInterface $io * @param string $projectName * @param string $configuredAppPath */ private static function updateMainConfig(IOInterface $io, $projectName, $configuredAppPath) { $replacements = ["#> session_name <#" => $projectName . "_session", "#> project_name <#" => $projectName]; $io->write(["<fg=cyan>Updating the main configuration</fg=cyan>", "The installer is now updating your main configuration according to your project name.", "You can change everything later by manually editing <fg=yellow>{$configuredAppPath}/config/config.yml</fg=yellow>.", "", "The following settings are updated:", "-> <fg=yellow>framework.session.name</fg=yellow>: {$replacements['#> session_name <#']}", "-> <fg=yellow>monolog.handlers.swift</fg=yellow> (prod): Plus address and mail subject to: {$replacements['#> project_name <#']}"]); self::replaceInAppFile("config/config.yml", $replacements); self::replaceInAppFile("config/config_prod.yml", $replacements); }
/** * @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}"); } } }
public static function createConfig(IOInterface $io = null, $cwd = null) { $cwd = $cwd ?: getcwd(); $home = self::getHomeDir(); $cacheDir = self::getCacheDir($home); foreach (array($home, $cacheDir) as $dir) { if (!file_exists($dir . '/.htaccess')) { if (!is_dir($dir)) { @mkdir($dir, 0777, true); } @file_put_contents($dir . '/.htaccess', 'Deny from all'); } } $config = new Config(true, $cwd); $config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir))); $file = new JsonFile($config->get('home') . '/config.json'); if ($file->exists()) { if ($io && $io->isDebug()) { $io->writeError('Loading config file ' . $file->getPath()); } $config->merge($file->read()); } $config->setConfigSource(new JsonConfigSource($file)); $file = new JsonFile($config->get('home') . '/auth.json'); if ($file->exists()) { if ($io && $io->isDebug()) { $io->writeError('Loading config file ' . $file->getPath()); } $config->merge(array('config' => $file->read())); } $config->setAuthConfigSource(new JsonConfigSource($file, true)); return $config; }
/** * Just add the \ComposerSymlinker\LocalInstaller new installer * * @param \Composer\Composer $composer * @param \Composer\IO\IOInterface $io */ public function activate(Composer $composer, IOInterface $io) { if (!empty(getenv('DISABLE_SYMLINKER'))) { $io->write('Found DISABLE_SYMLINKER envvar, disabling symlinker...'); return; } $composer->getInstallationManager()->addInstaller(new LocalInstaller($io, $composer)); }
public function __construct(array $repoConfig, IOInterface $io, Config $config = null, array $drivers = null) { $this->drivers = $drivers ?: array('github' => 'Composer\\Repository\\Vcs\\GitHubDriver', 'git-bitbucket' => 'Composer\\Repository\\Vcs\\GitBitbucketDriver', 'git' => 'Composer\\Repository\\Vcs\\GitDriver', 'svn' => 'Composer\\Repository\\Vcs\\SvnDriver', 'hg-bitbucket' => 'Composer\\Repository\\Vcs\\HgBitbucketDriver', 'hg' => 'Composer\\Repository\\Vcs\\HgDriver'); $this->url = $repoConfig['url']; $this->io = $io; $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs'; $this->verbose = $io->isVerbose(); }
/** * @param IOInterface $io * @param PhpLint $phpLint * * @return PhpLint */ public static function configure(IOInterface $io, PhpLint $phpLint) { if (true === $phpLint->isUndefined()) { $answer = $io->ask(HookQuestions::PHPLINT_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER); $phpLint = $phpLint->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer))); } return $phpLint; }
/** * @param IOInterface $io * @param Composer $composer * * @return Composer */ public static function configure(IOInterface $io, Composer $composer) { if (true === $composer->isUndefined()) { $answer = $io->ask(HookQuestions::COMPOSER_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER); $composer = $composer->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer))); } return $composer; }
/** * Register all managed paths with Composer. * * This function configures Composer to treat all Studio-managed paths as local path repositories, so that packages * therein will be symlinked directly. */ public function registerStudioPackages() { $repoManager = $this->composer->getRepositoryManager(); $composerConfig = $this->composer->getConfig(); foreach ($this->getManagedPaths() as $path) { $this->io->writeError("[Studio] Loading path {$path}"); $repoManager->prependRepository(new PathRepository(['url' => $path], $this->io, $composerConfig)); } }
/** * @param IOInterface $io * @param CommitMsg $commitMsg * * @return CommitMsg */ public static function configure(IOInterface $io, CommitMsg $commitMsg) { $answer = $io->ask(HookQuestions::COMMIT_MSG_HOOK, HookQuestions::DEFAULT_TOOL_ANSWER); $commitMsg = $commitMsg->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer))); if (true === $commitMsg->isEnabled()) { $regularExpressionAnswer = $io->ask(HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION, HookQuestions::COMMIT_MSG_REGULAR_EXPRESSION_ANSWER); $commitMsg = $commitMsg->addRegularExpression(new RegularExpression($regularExpressionAnswer)); } return $commitMsg; }
/** * Copy the /config/recaptcha.default.php file from plugin to /config/recaptcha.php * file in root app. Copy only if the file does not exists. * * @param string $dir The application's root directory. * @param string $pluginDir The plugin's directory. * @param \Composer\IO\IOInterface $io IO interface to write to console. * @return void */ public static function createPluginConfig($dir, $pluginDir, $io) { // copy the file $pluginConfig = $dir . '/config/recaptcha.php'; $pluginDefaultConfig = $pluginDir . '/config/recaptcha.default.php'; if (!file_exists($pluginConfig)) { copy($pluginDefaultConfig, $pluginConfig); $io->write('Created `config/recaptcha.php` file'); } }
public function activate(Composer $composer, IOInterface $io) { $io->write("<info>[ComposerSharedInstaller]</info> activate"); // remove library installer $manager = $composer->getInstallationManager(); $libraryInstaller = $manager->getInstaller('library'); $manager->removeInstaller($libraryInstaller); // add shared installer $installer = new Installer($io, $composer); $manager->addInstaller($installer); }
/** * @param IOInterface $io * @param PhpMd $phpMd * * @return PhpMd */ public static function configure(IOInterface $io, PhpMd $phpMd) { if (true === $phpMd->isUndefined()) { $answer = $io->ask(HookQuestions::PHPMD_TOOL, HookQuestions::DEFAULT_TOOL_ANSWER); $phpMd = $phpMd->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer))); $optionsAnswer = $io->ask(HookQuestions::PHPMD_OPTIONS, null); $options = new PhpMdOptions($optionsAnswer); $phpMd = $phpMd->setOptions($options); } return $phpMd; }
public function doDeploy() { $this->sortPackages(); /** @var Entry $package */ foreach ($this->packages as $package) { if ($this->io->isDebug()) { $this->io->write('start magento deploy for ' . $package->getPackageName()); } $package->getDeployStrategy()->deploy(); } }
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null) { parent::__construct(); $this->drivers = $drivers ?: array('github' => 'Composer\\Repository\\Vcs\\GitHubDriver', 'gitlab' => 'Composer\\Repository\\Vcs\\GitLabDriver', 'git-bitbucket' => 'Composer\\Repository\\Vcs\\GitBitbucketDriver', 'git' => 'Composer\\Repository\\Vcs\\GitDriver', 'hg-bitbucket' => 'Composer\\Repository\\Vcs\\HgBitbucketDriver', 'hg' => 'Composer\\Repository\\Vcs\\HgDriver', 'perforce' => 'Composer\\Repository\\Vcs\\PerforceDriver', 'fossil' => 'Composer\\Repository\\Vcs\\FossilDriver', 'svn' => 'Composer\\Repository\\Vcs\\SvnDriver'); $this->url = $repoConfig['url']; $this->io = $io; $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs'; $this->verbose = $io->isVeryVerbose(); $this->config = $config; $this->repoConfig = $repoConfig; }
public static function configure(IOInterface $input, PrePush $prePush) { $answer = $input->ask(HookQuestions::PRE_PUSH_HOOK_QUESTION, HookQuestions::DEFAULT_TOOL_ANSWER); $prePush = $prePush->setEnabled(new Enabled(HookQuestions::DEFAULT_TOOL_ANSWER === strtoupper($answer))); if (true === $prePush->isEnabled()) { $rightMessageAnswer = $input->ask(HookQuestions::PRE_PUSH_RIGHT_MESSAGE, HookQuestions::PRE_PUSH_RIGHT_MESSAGE_DEFAULT); $errorMessageAnswer = $input->ask(HookQuestions::PRE_PUSH_ERROR_MESSAGE, HookQuestions::PRE_PUSH_ERROR_MESSAGE_DEFAULT); $prePush = $prePush->setMessages(new Messages(new Message($rightMessageAnswer), new Message($errorMessageAnswer))); } return $prePush; }
/** * Write a message * * @param string $message */ protected function log($message) { if (method_exists($this->inputOutput, 'writeError')) { $this->inputOutput->writeError($message); } else { // @codeCoverageIgnoreStart // Backwards compatiblity for Composer before cb336a5 $this->inputOutput->write($message); // @codeCoverageIgnoreEnd } }