当前位置: 首页>>代码示例>>PHP>>正文


PHP Composer\Factory类代码示例

本文整理汇总了PHP中Composer\Factory的典型用法代码示例。如果您正苦于以下问题:PHP Factory类的具体用法?PHP Factory怎么用?PHP Factory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: preUpdate

 /**
  * Merge repositories and requirements from a separate composer-local.json.
  *
  * This allows static development dependencies to be shipped with Vanilla, but can be customized with a
  * composer-local.json file that specifies additional dependencies such as plugins or compatibility libraries.
  *
  * @param Event $event The event being fired.
  */
 public static function preUpdate(Event $event)
 {
     self::clearAddonManagerCache();
     // Check for a composer-local.json.
     $composerLocalPath = './composer-local.json';
     if (!file_exists($composerLocalPath)) {
         return;
     }
     $composer = $event->getComposer();
     $factory = new Factory();
     $localComposer = $factory->createComposer($event->getIO(), $composerLocalPath, true, null, false);
     // Merge repositories.
     $localRepositories = $localComposer->getRepositoryManager()->getRepositories();
     foreach ($localRepositories as $repository) {
         /* @var \Composer\Repository\RepositoryInterface $repository */
         if (method_exists($repository, 'getRepoConfig')) {
             $config = $repository->getRepoConfig();
         } else {
             $config = ['url' => ''];
         }
         // Skip the packagist repo.
         if (strpos($config['url'], 'packagist.org') !== false) {
             continue;
         }
         $composer->getRepositoryManager()->addRepository($repository);
     }
     // Merge requirements.
     $requires = array_merge($composer->getPackage()->getRequires(), $localComposer->getPackage()->getRequires());
     $composer->getPackage()->setRequires($requires);
     $devRequires = array_merge($composer->getPackage()->getDevRequires(), $localComposer->getPackage()->getDevRequires());
     $composer->getPackage()->setDevRequires($devRequires);
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:40,代码来源:ComposerHelper.php

示例2: dump

 /**
  * Builds the archives of the repository.
  *
  * @param array $packages List of packages to dump
  */
 public function dump(array $packages)
 {
     $helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
     $directory = $helper->getDirectory($this->outputDir);
     $this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
     $format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
     $endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
     $includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
     $composerConfig = Factory::createConfig();
     $factory = new Factory();
     $io = new ConsoleIO($this->input, $this->output, $this->helperSet);
     $io->loadConfiguration($composerConfig);
     /* @var \Composer\Downloader\DownloadManager $downloadManager */
     $downloadManager = $factory->createDownloadManager($io, $composerConfig);
     /* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
     $archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
     $archiveManager->setOverwriteFiles(false);
     shuffle($packages);
     /* @var \Composer\Package\CompletePackage $package */
     foreach ($packages as $package) {
         if ($helper->isSkippable($package)) {
             continue;
         }
         $this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
         try {
             if ('pear-library' === $package->getType()) {
                 // PEAR packages are archives already
                 $filesystem = new Filesystem();
                 $packageName = $archiveManager->getPackageFilename($package);
                 $path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
                 if (!file_exists($path)) {
                     $downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
                     $filesystem->ensureDirectoryExists($downloadDir);
                     $downloadManager->download($package, $downloadDir, false);
                     $filesystem->ensureDirectoryExists($directory);
                     $filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
                     $filesystem->removeDirectory($downloadDir);
                 }
                 // Set archive format to `file` to tell composer to download it as is
                 $archiveFormat = 'file';
             } else {
                 $path = $archiveManager->archive($package, $format, $directory);
                 $archiveFormat = $format;
             }
             $archive = basename($path);
             $distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
             $package->setDistType($archiveFormat);
             $package->setDistUrl($distUrl);
             if ($includeArchiveChecksum) {
                 $package->setDistSha1Checksum(hash_file('sha1', $path));
             }
             $package->setDistReference($package->getSourceReference());
         } catch (\Exception $exception) {
             if (!$this->skipErrors) {
                 throw $exception;
             }
             $this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
         }
     }
 }
开发者ID:robertgit,项目名称:satis,代码行数:65,代码来源:ArchiveBuilder.php

示例3: testInjectCoreBundles

 /**
  * Test that the core bundles get correctly injected.
  *
  * @return void
  */
 public function testInjectCoreBundles()
 {
     $inOut = $this->getMock('Composer\\IO\\IOInterface');
     $factory = new Factory();
     $composer = $factory->createComposer($inOut, $this->config);
     $plugin = new Plugin();
     $local = $composer->getRepositoryManager()->getLocalRepository();
     if ($core = $local->findPackages('contao/core')) {
         $this->fail('Contao core has already been injected, found version ' . $core[0]->getVersion());
     }
     $plugin->activate($composer, $inOut);
     if (!($core = $local->findPackages('contao/core'))) {
         $this->fail('Contao core has not been injected.');
     }
     $core = $core[0];
     $constraint = new Constraint('=', $core->getVersion());
     $pool = new Pool('dev');
     $pool->addRepository($local);
     $this->assertNotNull($core = $pool->whatProvides('contao/core', $constraint));
     // bundle names + 'contao-community-alliance/composer-client'
     $this->assertCount(8, $core[0]->getRequires());
     foreach (array('contao/calendar-bundle', 'contao/comments-bundle', 'contao/core-bundle', 'contao/faq-bundle', 'contao/listing-bundle', 'contao/news-bundle', 'contao/newsletter-bundle') as $bundleName) {
         $this->assertNotNull($matches = $pool->whatProvides($bundleName, $constraint));
         $this->assertCount(1, $matches);
         $this->assertEquals('metapackage', $matches[0]->getType());
     }
 }
开发者ID:Jobu,项目名称:core,代码行数:32,代码来源:InjectCoreBundlesTest.php

示例4: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $factory = new Factory();
     $file = $factory->getComposerFile();
     if (!file_exists($file)) {
         $output->writeln('<error>' . $file . ' not found.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     $dialog = $this->getHelperSet()->get('dialog');
     $json = new JsonFile($file);
     $composer = $json->read();
     $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
     $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
     $baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array();
     $requirements = $this->formatRequirements($requirements);
     if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey)) {
         foreach ($requirements as $package => $version) {
             $baseRequirements[$package] = $version;
         }
         $composer[$requireKey] = $baseRequirements;
         $json->write($composer);
     }
     $output->writeln('<info>' . $file . ' has been updated</info>');
     // Update packages
     $composer = $this->getComposer();
     $io = $this->getIO();
     $install = Installer::create($io, $composer);
     $install->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setDevMode($input->getOption('dev'))->setUpdate(true)->setUpdateWhitelist($requirements);
     return $install->run() ? 0 : 1;
 }
开发者ID:nicodmf,项目名称:composer,代码行数:34,代码来源:RequireCommand.php

示例5: setUp

 public function setUp()
 {
     parent::setUp();
     $factory = new Factory();
     $this->manager = $factory->createArchiveManager($factory->createConfig());
     $this->targetDir = $this->testDir . '/composer_archiver_tests';
 }
开发者ID:alancleaver,项目名称:composer,代码行数:7,代码来源:ArchiveManagerTest.php

示例6: getComposer

 /**
  * @return Composer
  */
 protected function getComposer()
 {
     $dir = Module::getRootDir();
     $path = $dir . '/composer.json';
     \Dotenv::setEnvironmentVariable('COMPOSER', $path);
     $factory = new Factory();
     return $factory->createComposer(new NullIO(), $path, false, $dir);
 }
开发者ID:NullRefExcep,项目名称:yii2-core,代码行数:11,代码来源:ComposerController.php

示例7: getComposer

 /**
  * @return \Composer\Composer
  */
 public static function getComposer()
 {
     if (!self::$composer) {
         $factory = new Factory();
         self::$composer = $factory->createComposer(new NullIO(), Yii::getAlias(self::$composerConfigFile), false, Yii::getAlias(self::$composerConfigFilePath));
     }
     return self::$composer;
 }
开发者ID:bookin,项目名称:yii2-composer-web,代码行数:11,代码来源:ComposerComponent.php

示例8: testIssue30LoadHousekeeper

 /**
  * When the plugin is loaded, the event listeners are registered which require the Housekeeper.
  *
  * When the plugin gets uninstalled the housekeeper does not exist anymore and a "Housekeeper class not found" is
  * thrown.
  *
  * Test for https://github.com/contao-community-alliance/composer-plugin/issues/30
  *
  * Situation:
  *  - plugin is installed.
  *  - plugin get uninstalled.
  *
  * Result:
  *  - Housekeeper class not found.
  *
  * @return void
  */
 public function testIssue30LoadHousekeeper()
 {
     $inOut = $this->getMock('Composer\\IO\\IOInterface');
     $factory = new Factory();
     $composer = $factory->createComposer($inOut);
     $plugin = new Plugin();
     $plugin->activate($composer, $inOut);
     $this->assertTrue(class_exists('ContaoCommunityAlliance\\Composer\\Plugin\\Housekeeper', false));
 }
开发者ID:Jobu,项目名称:core,代码行数:26,代码来源:IssuesTest.php

示例9: getDownloadManager

 private function getDownloadManager()
 {
     if (!$this->downloadManager) {
         $config = Factory::createConfig();
         $factory = new Factory();
         $this->downloadManager = $factory->createDownloadManager($this->getIO(), $config);
     }
     return $this->downloadManager;
 }
开发者ID:stof,项目名称:packanalyst,代码行数:9,代码来源:RunCommand.php

示例10: directories

 /**
  * Returns a list of directory paths in which scaffold files
  * are to be searched for, in order to build an index
  *
  * @return string[]
  */
 public function directories()
 {
     $composerConfig = Factory::createConfig(null, getcwd());
     $vendorDir = $composerConfig->get('vendor-dir');
     $globalVendorDir = Factory::createConfig(null, $composerConfig->get('home'))->get('vendor-dir');
     return [$globalVendorDir, $vendorDir, getcwd() . DIRECTORY_SEPARATOR];
 }
开发者ID:aedart,项目名称:scaffold,代码行数:13,代码来源:DirectoriesToIndex.php

示例11: initialize

 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if ($input->getOption('global') && 'composer.json' !== $input->getOption('file')) {
         throw new \RuntimeException('--file and --global can not be combined');
     }
     $this->config = Factory::createConfig($this->getIO());
     $configFile = $input->getOption('global') ? $this->config->get('home') . '/config.json' : $input->getOption('file');
     $this->configFile = new JsonFile($configFile);
     $this->configSource = new JsonConfigSource($this->configFile);
     $authConfigFile = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($input->getOption('file'))) . '/auth.json';
     $this->authConfigFile = new JsonFile($authConfigFile);
     $this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
     if ($input->getOption('global') && !$this->configFile->exists()) {
         touch($this->configFile->getPath());
         $this->configFile->write(array('config' => new \ArrayObject()));
         @chmod($this->configFile->getPath(), 0600);
     }
     if ($input->getOption('global') && !$this->authConfigFile->exists()) {
         touch($this->authConfigFile->getPath());
         $this->authConfigFile->write(array('http-basic' => new \ArrayObject(), 'github-oauth' => new \ArrayObject()));
         @chmod($this->authConfigFile->getPath(), 0600);
     }
     if (!$this->configFile->exists()) {
         throw new \RuntimeException(sprintf('File "%s" cannot be found in the current directory', $configFile));
     }
 }
开发者ID:VicDeo,项目名称:poc,代码行数:27,代码来源:ConfigCommand.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $baseUrl = (extension_loaded('openssl') ? 'https' : 'http') . '://' . self::HOMEPAGE;
     $config = Factory::createConfig();
     $remoteFilesystem = new RemoteFilesystem($this->getIO(), $config);
     $cacheDir = $config->get('cache-dir');
     $rollbackDir = $config->get('home');
     $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
     // check if current dir is writable and if not try the cache dir from settings
     $tmpDir = is_writable(dirname($localFilename)) ? dirname($localFilename) : $cacheDir;
     // check for permissions in local filesystem before start connection process
     if (!is_writable($tmpDir)) {
         throw new FilesystemException('Composer update failed: the "' . $tmpDir . '" directory used to download the temp file could not be written');
     }
     if (!is_writable($localFilename)) {
         throw new FilesystemException('Composer update failed: the "' . $localFilename . '" file could not be written');
     }
     if ($input->getOption('rollback')) {
         return $this->rollback($output, $rollbackDir, $localFilename);
     }
     $latestVersion = trim($remoteFilesystem->getContents(self::HOMEPAGE, $baseUrl . '/version', false));
     $updateVersion = $input->getArgument('version') ?: $latestVersion;
     if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
         $output->writeln('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
         return 1;
     }
     if (Composer::VERSION === $updateVersion) {
         $output->writeln('<info>You are already using composer version ' . $updateVersion . '.</info>');
         return 0;
     }
     $tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
     $backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
     $output->writeln(sprintf("Updating to version <info>%s</info>.", $updateVersion));
     $remoteFilename = $baseUrl . (preg_match('{^[0-9a-f]{40}$}', $updateVersion) ? '/composer.phar' : "/download/{$updateVersion}/composer.phar");
     $remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename);
     if (!file_exists($tempFilename)) {
         $output->writeln('<error>The download of the new composer version failed for an unexpected reason</error>');
         return 1;
     }
     // remove saved installations of composer
     if ($input->getOption('clean-backups')) {
         $finder = $this->getOldInstallationFinder($rollbackDir);
         $fs = new Filesystem();
         foreach ($finder as $file) {
             $file = (string) $file;
             $output->writeln('<info>Removing: ' . $file . '</info>');
             $fs->remove($file);
         }
     }
     if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
         $output->writeln('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
         $output->writeln('<error>Please re-run the self-update command to try again.</error>');
         return 1;
     }
     if (file_exists($backupFile)) {
         $output->writeln('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
     } else {
         $output->writeln('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
     }
 }
开发者ID:aminembarki,项目名称:composer,代码行数:60,代码来源:SelfUpdateCommand.php

示例13: execute

 /**
  * Search for packages.
  *
  * @param array   $packages Indexed array of package names to search for
  * @param boolean $onlyname True for name only search, false for full text
  *
  * @throws PackageManagerException
  *
  * @return array List of matching packages
  */
 public function execute($packages, $onlyname = true)
 {
     /** @var $composer \Composer\Composer */
     $composer = $this->getComposer();
     $io = $this->getIO();
     $platformRepo = new PlatformRepository();
     if ($composer) {
         $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         $installedRepo = new CompositeRepository([$localRepo, $platformRepo]);
         $repos = new CompositeRepository(array_merge([$installedRepo], $composer->getRepositoryManager()->getRepositories()));
     } else {
         $defaultRepos = Factory::createDefaultRepositories($io);
         //No composer.json found in the current directory, showing packages from local repo
         $installedRepo = $platformRepo;
         $repos = new CompositeRepository(array_merge([$installedRepo], $defaultRepos));
     }
     $flags = $onlyname ? RepositoryInterface::SEARCH_NAME : RepositoryInterface::SEARCH_FULLTEXT;
     try {
         return $repos->search(implode(' ', $packages), $flags);
     } catch (\Exception $e) {
         $msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
         $this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);
         throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:atiarda,项目名称:bolt,代码行数:35,代码来源:SearchPackage.php

示例14: __construct

 /**
  * Constructor.
  *
  * @param IOInterface      $io               The IO instance
  * @param Config           $config           The composer configuration
  * @param ProcessExecutor  $process          Process instance, injectable for mocking
  * @param RemoteFilesystem $remoteFilesystem Remote Filesystem, injectable for mocking
  */
 public function __construct(IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
 {
     $this->io = $io;
     $this->config = $config;
     $this->process = $process ?: new ProcessExecutor();
     $this->remoteFilesystem = $remoteFilesystem ?: Factory::createRemoteFilesystem($this->io, $config);
 }
开发者ID:dazzle-libraries,项目名称:composer,代码行数:15,代码来源:Bitbucket.php

示例15: __construct

 /**
  * @param string $url
  * @param string $token
  * @param bool   $cacheDir
  * @param null   $bufferIO
  *
  * @throws \Exception
  */
 public function __construct($url, $token = '', $cacheDir = false, $bufferIO = null)
 {
     $this->url = $url;
     $this->io = new NullIO();
     $this->log = $bufferIO ? $bufferIO : new BufferIO();
     $config = Factory::createConfig();
     $cfg = ['config' => []];
     if ($cacheDir) {
         $cfg['config']['cache-dir'] = $cacheDir;
     }
     if ($token) {
         $cfg['config']['github-oauth'] = ['github.com' => $token];
     }
     $config->merge($cfg);
     $this->cacheDir = $cacheDir;
     $this->io->loadConfiguration($config);
     $this->repository = new Repository\VcsRepository(['url' => $url, 'no-api' => false], $this->io, $config);
     $driver = $this->vcsDriver = $this->repository->getDriver();
     if (!$driver) {
         throw new \Exception('No driver found for <' . $url . '>');
     }
     $this->driver = $driver;
     $composerInfoMaster = $this->driver->getComposerInformation($this->driver->getRootIdentifier());
     if (!$composerInfoMaster) {
         throw new \Exception('master must have a valid composer.json');
     }
     $this->name = $composerInfoMaster['name'];
     list($this->vendorName, $this->packageName) = explode('/', $this->name);
     preg_match('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\\.git|/)?$#', $this->url, $match);
     $this->gitHubVendorName = $match[3];
     $this->gitHubRepositoryName = $match[4];
     $client = new \Github\Client();
     $client->authenticate($token, null, \GitHub\Client::AUTH_URL_TOKEN);
     $this->client = $client;
 }
开发者ID:Doanlmit,项目名称:pickleweb,代码行数:43,代码来源:Github.php


注:本文中的Composer\Factory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。