本文整理汇总了PHP中Composer\IO\IOInterface::write方法的典型用法代码示例。如果您正苦于以下问题:PHP IOInterface::write方法的具体用法?PHP IOInterface::write怎么用?PHP IOInterface::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\IO\IOInterface
的用法示例。
在下文中一共展示了IOInterface::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setFolderPermissions
/**
* 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);
}
示例2: download
/**
* @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;
}
示例3: activate
/**
* @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}");
}
}
}
示例4: writeToOutput
public function writeToOutput()
{
$this->processPackages();
foreach ($this->minPackageLinks as $packageLink) {
$this->io->write($this->formatPackageLink($packageLink));
}
}
示例5: handleDeprecatedType
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');
}
}
示例6: selectPackage
protected function selectPackage(IOInterface $io, $packageName, $version = null)
{
$io->write('<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->write('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->write('<info>Found multiple matches, selected ' . $package->getPrettyString() . '.</info>');
$io->write('Alternatives were ' . implode(', ', array_map(function ($p) {
return $p->getPrettyString();
}, $packages)) . '.');
$io->write('<comment>Please use a more specific constraint to pick a different package.</comment>');
} elseif ($packages) {
$package = reset($packages);
$io->write('<info>Found an exact match ' . $package->getPrettyString() . '.</info>');
} else {
$io->write('<error>Could not find a package matching ' . $packageName . '.</error>');
return false;
}
return $package;
}
示例7: installDependencies
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");
}
示例8: execute
/**
* 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();
}
示例9: setAssetsVersion
/**
* @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;
}
示例10: publish
/**
* @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);
}
}
}
示例11: process
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>");
}
}
示例12: doDeploy
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();
}
}
示例13: onPostPackageUpdate
/**
* Prints a links to package changelog on the post-package-update event.
*
* @param PackageEvent $event
*/
public function onPostPackageUpdate(PackageEvent $event)
{
$operation = $event->getOperation();
if ($operation instanceof UpdateOperation) {
try {
$changelog = self::getChangelog($operation->getInitialPackage(), $operation->getTargetPackage());
} catch (Exception\CouldNotCalculateChangelog $e) {
$changelog = $e->getMessage();
}
$this->io->write(self::PAD_STR . 'CHANGELOG: ' . $changelog);
}
}
示例14: postAutoloadDump
public function postAutoloadDump(Event $event)
{
// This method is called twice. Run it only once.
if (!$this->runPostAutoloadDump) {
return;
}
$this->runPostAutoloadDump = false;
$config = $this->composer->getConfig();
$suffix = $config->get('autoloader-suffix');
$vendorDir = $config->get('vendor-dir');
$binDir = $config->get('bin-dir');
$autoloadFile = $vendorDir . '/autoload.php';
if (!file_exists($autoloadFile)) {
throw new \RuntimeException(sprintf('Could not adjust autoloader: The file %s was not found.', $autoloadFile));
}
if (!$suffix && !$config->get('autoloader-suffix') && is_readable($autoloadFile)) {
$content = file_get_contents($vendorDir . '/autoload.php');
if (preg_match('{' . self::COMPOSER_AUTOLOADER_BASE . '([^:\\s]+)::}', $content, $match)) {
$suffix = $match[1];
}
}
$contents = file_get_contents($autoloadFile);
$constant = '';
$values = array('AUTOLOAD_CLASS' => var_export(self::COMPOSER_AUTOLOADER_BASE . $suffix, true));
foreach ($values as $key => $value) {
$this->io->write('<info>Generating ' . $this->constantPrefix . $key . ' constant</info>');
$constant .= "if (!defined('{$this->constantPrefix}{$key}')) {\n";
$constant .= sprintf(" define('{$this->constantPrefix}{$key}', %s);\n", $value);
$constant .= "}\n\n";
}
$values = array_map(function ($value) {
return var_export($value, true);
}, array('BASE_DIR' => Path::makeRelative(getcwd(), $vendorDir), 'BIN_DIR' => Path::makeRelative($binDir, $vendorDir), 'FILE' => Path::makeRelative(realpath(Factory::getComposerFile()), $vendorDir)));
foreach ($values as $key => $value) {
$this->io->write('<info>Generating ' . $this->constantPrefix . $key . ' constant</info>');
$constant .= "if (!defined('{$this->constantPrefix}{$key}')) {\n";
$constant .= sprintf(" define('{$this->constantPrefix}{$key}', realpath(__DIR__ . DIRECTORY_SEPARATOR . %s));\n", $value);
$constant .= "}\n\n";
}
$values = array('VENDOR_DIR' => $vendorDir);
foreach ($values as $key => $value) {
$this->io->write('<info>Generating ' . $this->constantPrefix . $key . ' constant</info>');
$constant .= "if (!defined('{$this->constantPrefix}{$key}')) {\n";
$constant .= sprintf(" define('{$this->constantPrefix}{$key}', realpath(__DIR__));\n");
$constant .= "}\n\n";
}
// Regex modifiers:
// "m": \s matches newlines
// "D": $ matches at EOF only
// Translation: insert before the last "return" in the file
$contents = preg_replace('/\\n(?=return [^;]+;\\s*$)/mD', "\n" . $constant, $contents);
file_put_contents($autoloadFile, $contents);
}
示例15: getComposer
/**
* @param bool $required Not used
* @param array|string|null $config either a configuration array or a filename to read from,
* if null it will read from the default filename
*
* @return Composer
*/
public function getComposer($required = true, $config = null)
{
if (null === $this->composer) {
try {
$this->composer = Factory::create($this->io, $config);
} catch (\InvalidArgumentException $e) {
$this->io->write($e->getMessage());
exit(1);
}
}
return $this->composer;
}