本文整理汇总了PHP中Composer\Factory::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::create方法的具体用法?PHP Factory::create怎么用?PHP Factory::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Factory
的用法示例。
在下文中一共展示了Factory::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Executes composer for the extension.
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$name = $this->argument('extension');
$update = $this->option('update');
if (!is_dir($path = $this->pagekit['path.extensions'] . "/{$name}") && file_exists("{$path}/extension.json")) {
$this->error("Extension not exists '{$path}'");
exit;
}
$package = json_decode(file_get_contents("{$path}/extension.json"), true);
if (!isset($package['composer']) || empty($package['composer'])) {
$this->error("Composer not defined in '{$path}/extension.json'");
exit;
}
$this->loadComposer($path);
$io = new ConsoleIO($input, $output, $this->getHelperSet());
$composer = Factory::create($io, $package['composer']);
$lockFile = new JsonFile("{$path}/extension.lock");
$locker = new Locker($io, $lockFile, $composer->getRepositoryManager(), $composer->getInstallationManager(), md5(json_encode($package['composer'])));
$composer->setLocker($locker);
$installed = new JsonFile($this->pagekit['path'] . '/vendor/composer/installed.json');
$internal = new CompositeRepository([]);
$internal->addRepository(new InstalledFilesystemRepository($installed));
$installer = Installer::create($io, $composer);
$installer->setAdditionalInstalledRepository($internal);
$installer->setUpdate($update);
return $installer->run();
}
示例2: create
/**
* Create \Composer\Composer
*
* @return \Composer\Composer
* @throws \Exception
*/
public function create()
{
if (!getenv('COMPOSER_HOME')) {
putenv('COMPOSER_HOME=' . $this->directoryList->getPath(DirectoryList::COMPOSER_HOME));
}
return \Composer\Factory::create(new BufferIO(), $this->composerJsonFinder->findComposerJson());
}
示例3: getComposer
public function getComposer()
{
if ($this->composer === null) {
$this->composer = Factory::create($this->io, null, false);
}
return $this->composer;
}
示例4: run
/**
* 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');
}
示例5: main
/**
* Removes patched packages.
*/
public function main()
{
// Check if all required data is present.
$this->checkRequirements();
$composer = Factory::create(new NullIO(), $this->composerJsonPath);
// Force discarding of changes, these packages are patched after all.
// @todo Make this configurable with a "force" flag.
$config = $composer->getConfig();
$config->merge(['config' => ['discard-changes' => TRUE]]);
// Get the list of patches.
$extra = $composer->getPackage()->getExtra();
if (!empty($extra['patches'])) {
$repository = $composer->getRepositoryManager()->getLocalRepository();
$installation_manager = $composer->getInstallationManager();
// Loop over the patched packages.
foreach (array_keys($extra['patches']) as $package_name) {
foreach ($repository->findPackages($package_name) as $package) {
// Skip aliases, only remove the actual packages.
if (!$package instanceof AliasPackage) {
// Remove the package.
$this->log("Removing patched package '{$package_name}'.");
$operation = new UninstallOperation($package, 'Uninstalling patched package so it can be reinstalled.');
$installation_manager->uninstall($repository, $operation);
}
}
}
// Re-generate the autoloader to get rid of stale class definitions.
$generator = $composer->getAutoloadGenerator();
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$package = $composer->getPackage();
$installationManager = $composer->getInstallationManager();
$generator->dump($config, $localRepo, $package, $installationManager, 'composer');
}
}
示例6: prepareCommand
/**
* {@inheritDoc}
*/
protected function prepareCommand()
{
RuntimeHelper::setupHome($this->file->get(self::SETTING_HOME));
$command = new UpdateCommand();
$command->setComposer(Factory::create($this->getIO()));
return $command;
}
示例7: getComposer
/**
* Retrieve a composer instance.
*
* @param null|IOInterface $inputOutput The input/output handler to use.
*
* @return Composer
*/
public function getComposer(IOInterface $inputOutput = null)
{
if (null === $inputOutput) {
$inputOutput = $this->getInputOutput();
}
RuntimeHelper::setupHome($this->getTensideHome());
return ComposerFactory::create($inputOutput);
}
示例8: getAvailable
/**
* @return PackageInterface[]
*/
public function getAvailable()
{
$plugins = array();
$composer = Factory::create(new NullIO(), $this->config);
foreach ($composer->getPackage()->getSuggests() as $id => $version) {
$plugins[$id] = new Package($id, $version, $version);
}
return $plugins;
}
示例9: __construct
/**
* Constructor
*
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
$vendor = $filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath('vendor_path.php');
$vendorPath = $filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath() . (include $vendor);
// Create Composer
$io = new \Composer\IO\BufferIO();
$this->composer = ComposerFactory::create($io, $vendorPath . '/../composer.json');
$this->locker = $this->composer->getLocker();
}
示例10: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
$io = $this->getIO();
if (!file_exists($file)) {
$io->writeError('<error>' . $file . ' not found.</error>');
return 1;
}
if (!is_readable($file)) {
$io->writeError('<error>' . $file . ' is not readable.</error>');
return 1;
}
$validator = new ConfigValidator($io);
$checkAll = $input->getOption('no-check-all') ? 0 : ValidatingArrayLoader::CHECK_ALL;
$checkPublish = !$input->getOption('no-check-publish');
list($errors, $publishErrors, $warnings) = $validator->validate($file, $checkAll);
$checkLock = !$input->getOption('no-check-lock');
$lockErrors = array();
$composer = Factory::create($io, $file);
$locker = $composer->getLocker();
if ($locker->isLocked() && !$locker->isFresh()) {
$lockErrors[] = 'The lock file is not up to date with the latest changes in composer.json.';
}
// output errors/warnings
if (!$errors && !$publishErrors && !$warnings) {
$io->write('<info>' . $file . ' is valid</info>');
} elseif (!$errors && !$publishErrors) {
$io->writeError('<info>' . $file . ' is valid, but with a few warnings</info>');
$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
} elseif (!$errors) {
$io->writeError('<info>' . $file . ' is valid for simple usage with composer but has</info>');
$io->writeError('<info>strict errors that make it unable to be published as a package:</info>');
$io->writeError('<warning>See https://getcomposer.org/doc/04-schema.md for details on the schema</warning>');
} else {
$io->writeError('<error>' . $file . ' is invalid, the following errors/warnings were found:</error>');
}
$messages = array('error' => $errors, 'warning' => $warnings);
// If checking publish errors, display them as errors, otherwise just show them as warnings
if ($checkPublish) {
$messages['error'] = array_merge($messages['error'], $publishErrors);
} else {
$messages['warning'] = array_merge($messages['warning'], $publishErrors);
}
// If checking lock errors, display them as errors, otherwise just show them as warnings
if ($checkLock) {
$messages['error'] = array_merge($messages['error'], $lockErrors);
} else {
$messages['warning'] = array_merge($messages['warning'], $lockErrors);
}
foreach ($messages as $style => $msgs) {
foreach ($msgs as $msg) {
$io->writeError('<' . $style . '>' . $msg . '</' . $style . '>');
}
}
return $errors || $publishErrors && $checkPublish || $lockErrors && $checkLock ? 1 : 0;
}
示例11: __construct
public function __construct($binDir, $jsonDir)
{
\Phar::loadPhar($binDir . '/composer.phar', 'composer.phar');
require 'phar://composer.phar/src/bootstrap.php';
$this->io = new \Composer\IO\NullIO();
$this->composer = \Composer\Factory::create($this->io, $jsonDir . '/composer.json');
$vendorDir = $this->composer->getConfig()->get('vendor-dir');
$jsonFile = new \Composer\Json\JsonFile($vendorDir . '/composer/installed.json');
$this->composer->getRepositoryManager()->setLocalRepository(new \Composer\Repository\InstalledFilesystemRepository($jsonFile));
}
示例12: createComposer
/**
* @param IOInterface $io
* @param mixed $config
* @param bool $disablePlugins
* @return Composer\Composer
* @throws \Exception|\InvalidArgumentException
*/
public static function createComposer(IOInterface $io = null, $config = null, $disablePlugins = false)
{
try {
if (null === $io) {
$io = static::createConsoleIO();
}
return Composer\Factory::create($io, $config, $disablePlugins);
} catch (\InvalidArgumentException $e) {
throw $e;
}
}
示例13: getAvailable
/**
* @return CompletePackageInterface[]
*/
public function getAvailable()
{
$composer = Factory::create(new NullIO(), $this->config);
//transform to complete packages
$availablePackages = array();
foreach ($this->packageLocatorStrategy->getAvailable() as $id => $availablePackage) {
$completePackage = $composer->getRepositoryManager()->findPackage($availablePackage->getName(), $availablePackage->getVersion());
$availablePackages[$id] = $completePackage;
}
return $availablePackages;
}
示例14: attachComposerFactory
/**
* Attach the composer factory to the command.
*
* @param BaseCommand $command The command to patch.
*
* @return BaseCommand
*
* @throws \InvalidArgumentException When no setComposerFactory method is declared.
*/
protected function attachComposerFactory(BaseCommand $command)
{
if (!method_exists($command, 'setComposerFactory')) {
throw new \InvalidArgumentException('The passed command does not implement method setComposerFactory()');
}
/** @var WrappedCommandTrait $command */
$command->setComposerFactory(function () {
return Factory::create($this->getIO());
});
return $command;
}
示例15: getComposer
/**
* @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;
}