本文整理汇总了PHP中Composer\Package\Loader\ArrayLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ArrayLoader类的具体用法?PHP ArrayLoader怎么用?PHP ArrayLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayLoader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!$this->file->exists()) {
return;
}
$packages = $this->file->read();
if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
}
$loader = new ArrayLoader();
foreach ($packages as $packageData) {
$package = $loader->load($packageData);
// package was installed as alias, so we only add the alias
if ($this instanceof InstalledRepositoryInterface && !empty($packageData['installed-as-alias'])) {
$alias = $packageData['installed-as-alias'];
$package->setAlias($alias);
$package->setPrettyAlias($alias);
$package->setInstalledAsAlias(true);
$this->addPackage($this->createAliasPackage($package, $alias, $alias));
} else {
// only add regular package - if it's not an installed repo the alias will be created on the fly
$this->addPackage($package);
}
}
}
开发者ID:nlegoff,项目名称:composer,代码行数:29,代码来源:FilesystemRepository.php
示例2: prepareController
/**
* Mock the controller.
*
* @return \PHPUnit_Framework_MockObject_MockObject|PackageController
*/
private function prepareController()
{
$manager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->setMethods(null)->getMock();
$config = new Config();
$config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config);
$rootPackage = $loader->load(json_decode($this->readFixture('composer.json'), true));
$loader = new ArrayLoader();
$json = json_decode($this->readFixture('installed.json'), true);
$packages = [];
foreach ($json as $package) {
$packages[] = $loader->load($package);
}
$manager->setLocalRepository(new WritableArrayRepository($packages));
$composer = $this->getMockBuilder(Composer::class)->setMethods(['getPackage', 'getRepositoryManager'])->getMock();
$composer->method('getPackage')->willReturn($rootPackage);
$composer->method('getRepositoryManager')->willReturn($manager);
$controller = $this->getMockBuilder(PackageController::class)->setMethods(['getComposer', 'forward'])->getMock();
$controller->method('getComposer')->willReturn($composer);
$home = $this->getMock(HomePathDeterminator::class, ['homeDir']);
$home->method('homeDir')->willReturn($this->getTempDir());
$composerJson = $this->provideFixture('composer.json');
$this->provideFixture('composer.lock');
$this->provideFixture('installed.json', 'vendor/composer/installed.json');
$container = new Container();
$container->set('tenside.home', $home);
$container->set('tenside.composer_json', new ComposerJson($composerJson));
/** @var PackageController $controller */
$controller->setContainer($container);
return $controller;
}
开发者ID:tenside,项目名称:core-bundle,代码行数:36,代码来源:PackageControllerTest.php
示例3: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
$loader = new ArrayLoader();
foreach ($this->config as $package) {
$package = $loader->load($package);
$this->addPackage($package);
}
}
开发者ID:nlegoff,项目名称:composer,代码行数:12,代码来源:PackageRepository.php
示例4: convert
/**
* Convert json to Package.
*
* @param array $json
*
* @return \Composer\Package\CompletePackage
*
* @throws \Arcanedev\Composer\Exceptions\InvalidPackageException
*/
public static function convert(array $json)
{
$loader = new ArrayLoader();
$package = $loader->load($json);
if ($package instanceof CompletePackage) {
return $package;
}
// @codeCoverageIgnoreStart
throw new InvalidPackageException('Expected instance of CompletePackage, got ' . get_class($package));
// @codeCoverageIgnoreEnd
}
开发者ID:arcanedev,项目名称:composer,代码行数:20,代码来源:PackageJson.php
示例5: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!is_numeric(key($this->config))) {
$this->config = array($this->config);
}
$loader = new ArrayLoader();
foreach ($this->config as $package) {
$package = $loader->load($package);
$this->addPackage($package);
}
}
开发者ID:natxet,项目名称:composer,代码行数:15,代码来源:PackageRepository.php
示例6: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!$this->file->exists()) {
return;
}
$packages = $this->file->read();
if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
}
$loader = new ArrayLoader();
foreach ($packages as $package) {
$this->addPackage($loader->load($package));
}
}
开发者ID:natxet,项目名称:composer,代码行数:18,代码来源:FilesystemRepository.php
示例7: initialize
protected function initialize()
{
parent::initialize();
$json = new JsonFile($this->url . '/packages.json');
$packages = $json->read();
if (!$packages) {
throw new \UnexpectedValueException('Could not parse package list from the ' . $this->url . ' repository');
}
$loader = new ArrayLoader();
foreach ($packages as $data) {
foreach ($data['versions'] as $rev) {
$this->addPackage($loader->load($rev));
}
}
}
开发者ID:natxet,项目名称:composer,代码行数:15,代码来源:ComposerRepository.php
示例8: initialize
protected function initialize()
{
parent::initialize();
$loader = new ArrayLoader(null, true);
$directories = glob($this->directory . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR | GLOB_NOSORT);
foreach ($directories as $directory) {
if (!file_exists($directory . DIRECTORY_SEPARATOR . 'composer.json')) {
continue;
}
$jsonFile = new JsonFile($directory . DIRECTORY_SEPARATOR . 'composer.json');
$packageData = $jsonFile->read();
$packageData['version'] = '1.0';
$package = $loader->load($packageData);
$this->addPackage($package);
}
}
开发者ID:cvo-technologies,项目名称:composer-directory-repository,代码行数:16,代码来源:DirectoryRepository.php
示例9: loadRepository
protected function loadRepository(ArrayLoader $loader, $data)
{
// legacy repo handling
if (!isset($data['packages']) && !isset($data['includes'])) {
foreach ($data as $pkg) {
foreach ($pkg['versions'] as $metadata) {
$this->addPackage($loader->load($metadata));
}
}
return;
}
if (isset($data['packages'])) {
foreach ($data['packages'] as $package => $versions) {
foreach ($versions as $version => $metadata) {
$this->addPackage($loader->load($metadata));
}
}
}
if (isset($data['includes'])) {
foreach ($data['includes'] as $include => $metadata) {
if ($this->cache->sha1($include) === $metadata['sha1']) {
$includedData = json_decode($this->cache->read($include), true);
} else {
$json = new JsonFile($this->url . '/' . $include, new RemoteFilesystem($this->io));
$includedData = $json->read();
$this->cache->write($include, json_encode($includedData));
}
$this->loadRepository($loader, $includedData);
}
}
}
开发者ID:nlegoff,项目名称:composer,代码行数:31,代码来源:ComposerRepository.php
示例10: findRecommendedRequireVersion
/**
* Given a concrete version, this returns a ~ constraint (when possible)
* that should be used, for example, in composer.json.
*
* For example:
* * 1.2.1 -> ~1.2
* * 1.2 -> ~1.2
* * v3.2.1 -> ~3.2
* * 2.0-beta.1 -> ~2.0@beta
* * dev-master -> ~2.1@dev (dev version with alias)
* * dev-master -> dev-master (dev versions are untouched)
*
* @param PackageInterface $package
* @return string
*/
public function findRecommendedRequireVersion(PackageInterface $package)
{
$version = $package->getVersion();
if (!$package->isDev()) {
return $this->transformVersion($version, $package->getPrettyVersion(), $package->getStability());
}
$loader = new ArrayLoader($this->getParser());
$dumper = new ArrayDumper();
$extra = $loader->getBranchAlias($dumper->dump($package));
if ($extra) {
$extra = preg_replace('{^(\\d+\\.\\d+\\.\\d+)(\\.9999999)-dev$}', '$1.0', $extra, -1, $count);
if ($count) {
$extra = str_replace('.9999999', '.0', $extra);
return $this->transformVersion($extra, $extra, 'dev');
}
}
return $package->getPrettyVersion();
}
开发者ID:composer-fork,项目名称:composer,代码行数:33,代码来源:VersionSelector.php
示例11: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!$this->file->exists()) {
return;
}
try {
$packages = $this->file->read();
if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the repository');
}
} catch (\Exception $e) {
throw new InvalidRepositoryException('Invalid repository data in ' . $this->file->getPath() . ', packages could not be loaded: [' . get_class($e) . '] ' . $e->getMessage());
}
$loader = new ArrayLoader(null, true);
foreach ($packages as $packageData) {
$package = $loader->load($packageData);
$this->addPackage($package);
}
}
开发者ID:alancleaver,项目名称:composer,代码行数:23,代码来源:FilesystemRepository.php
示例12: getVendorDir
/**
* Retrieves the given package's vendor directory, where it's installed.
*/
public function getVendorDir(array $package)
{
// The root package vendor directory is not handled by getInstallPath().
if (isset($package['is-root']) && $package['is-root'] === true) {
// @todo Handle cases where the working directory is not where the
// root package is installed.
return getcwd();
}
$loader = new ArrayLoader();
$completePackage = $loader->load($package);
return $this->installationManager->getInstallPath($completePackage);
}
开发者ID:alexBLR,项目名称:firmware,代码行数:15,代码来源:CopyProcess.php
示例13: testGetComponentPath
/**
* Tests the Installer's getComponentPath function.
*
* @param $expected
* The expected install path for the package.
* @param $package
* The package to test upon.
*
* @dataProvider providerGetComponentPath
*
* @see \ComponentInstaller\Installer::getComponentPath()
*/
public function testGetComponentPath($expected, $package)
{
// Construct the mock objects.
$installer = new Installer($this->io, $this->composer, 'component');
$loader = new ArrayLoader();
// Test the results.
$result = $installer->getComponentPath($loader->load($package));
$this->assertEquals($this->componentDir . '/' . $expected, $result);
}
开发者ID:ICHydro,项目名称:anaconda,代码行数:21,代码来源:InstallerTest.php
示例14: extractDevPackages
/**
* Extracts the dev packages out of the localRepo
*
* This works by faking the operations so we can see what the dev packages
* would be at the end of the operation execution. This lets us then remove
* the dev packages from the list of operations accordingly if we are in a
* --no-dev install or update.
*
* @return array
*/
private function extractDevPackages(array $operations, RepositoryInterface $localRepo, PlatformRepository $platformRepo, array $aliases)
{
if (!$this->package->getDevRequires()) {
return array();
}
// fake-apply all operations to this clone of the local repo so we see the complete set of package we would end up with
$tempLocalRepo = clone $localRepo;
foreach ($operations as $operation) {
switch ($operation->getJobType()) {
case 'install':
case 'markAliasInstalled':
if (!$tempLocalRepo->hasPackage($operation->getPackage())) {
$tempLocalRepo->addPackage(clone $operation->getPackage());
}
break;
case 'uninstall':
case 'markAliasUninstalled':
$tempLocalRepo->removePackage($operation->getPackage());
break;
case 'update':
$tempLocalRepo->removePackage($operation->getInitialPackage());
if (!$tempLocalRepo->hasPackage($operation->getTargetPackage())) {
$tempLocalRepo->addPackage(clone $operation->getTargetPackage());
}
break;
default:
throw new \LogicException('Unknown type: ' . $operation->getJobType());
}
}
// we have to reload the local repo to handle aliases properly
// but as it is not persisted on disk we use a loader/dumper
// to reload it in memory
$localRepo = new InstalledArrayRepository(array());
$loader = new ArrayLoader(null, true);
$dumper = new ArrayDumper();
foreach ($tempLocalRepo->getCanonicalPackages() as $pkg) {
$localRepo->addPackage($loader->load($dumper->dump($pkg)));
}
unset($tempLocalRepo, $loader, $dumper);
$policy = $this->createPolicy();
$pool = $this->createPool();
$installedRepo = $this->createInstalledRepo($localRepo, $platformRepo);
$pool->addRepository($installedRepo, $aliases);
// creating requirements request without dev requirements
$request = $this->createRequest($this->package, $platformRepo);
$request->updateAll();
foreach ($this->package->getRequires() as $link) {
$request->install($link->getTarget(), $link->getConstraint());
}
// solve deps to see which get removed
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request);
$solver = new Solver($policy, $pool, $installedRepo, $this->io);
$ops = $solver->solve($request, $this->ignorePlatformReqs);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops);
$devPackages = array();
foreach ($ops as $op) {
if ($op->getJobType() === 'uninstall') {
$devPackages[] = $op->getPackage();
}
}
return $devPackages;
}
开发者ID:Rudloff,项目名称:composer,代码行数:72,代码来源:Installer.php
示例15: getComposerPackage
/**
*
* @param string $packageName
* @return CompletePackage
*/
public function getComposerPackage($packageName)
{
if ($this->composerCache->has($packageName)) {
return $this->composerCache->get($packageName);
}
$package = $this->loader->load($this->getJson($this->getFile($packageName)));
$this->composerCache->set($packageName, $package);
return $package;
}
开发者ID:keeko,项目名称:framework,代码行数:14,代码来源:PackageManager.php
示例16: initialize
/**
* Initializes path repository.
*
* This method will basically read the folder and add the found package.
*/
protected function initialize()
{
parent::initialize();
foreach ($this->getUrlMatches() as $url) {
$path = realpath($url) . DIRECTORY_SEPARATOR;
$composerFilePath = $path . 'composer.json';
if (!file_exists($composerFilePath)) {
continue;
}
$json = file_get_contents($composerFilePath);
$package = JsonFile::parseJson($json, $composerFilePath);
$package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => sha1($json));
$package['transport-options'] = $this->options;
if (!isset($package['version'])) {
$versionData = $this->versionGuesser->guessVersion($package, $path);
$package['version'] = $versionData['version'] ?: 'dev-master';
}
$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
}
$package = $this->loader->load($package);
$this->addPackage($package);
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:30,代码来源:PathRepository.php
示例17: testPluginApiVersionDoesSupportSelfVersion
public function testPluginApiVersionDoesSupportSelfVersion()
{
$links = $this->loader->parseLinks('Plugin', '6.6.6', '', array('composer-plugin-api' => 'self.version'));
$this->assertArrayHasKey('composer-plugin-api', $links);
$this->assertSame('6.6.6', $links['composer-plugin-api']->getConstraint()->getPrettyString());
}
开发者ID:ncusoho,项目名称:composer,代码行数:7,代码来源:ArrayLoaderTest.php
示例18: initialize
/**
* Initializes path repository.
*
* This method will basically read the folder and add the found package.
*/
protected function initialize()
{
parent::initialize();
foreach ($this->getUrlMatches() as $url) {
$path = realpath($url) . DIRECTORY_SEPARATOR;
$composerFilePath = $path . 'composer.json';
if (!file_exists($composerFilePath)) {
continue;
}
$json = file_get_contents($composerFilePath);
$package = JsonFile::parseJson($json, $composerFilePath);
$package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => '');
if (!isset($package['version'])) {
$package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
}
$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
} else {
$package['dist']['reference'] = Locker::getContentHash($json);
}
$package = $this->loader->load($package);
$this->addPackage($package);
}
if (count($this->getPackages()) == 0) {
throw new \RuntimeException(sprintf('No `composer.json` file found in any path repository in "%s"', $this->url));
}
}
开发者ID:AppChecker,项目名称:composer,代码行数:33,代码来源:PathRepository.php
示例19: load
public function load($config)
{
if (!isset($config['name'])) {
$config['name'] = '__root__';
}
if (!isset($config['version'])) {
$config['version'] = '1.0.0';
}
$package = parent::load($config);
if (isset($config['repositories'])) {
foreach ($config['repositories'] as $index => $repo) {
if (isset($repo['packagist']) && $repo['packagist'] === false) {
continue;
}
if (!is_array($repo)) {
throw new \UnexpectedValueException('Repository ' . $index . ' should be an array, ' . gettype($repo) . ' given');
}
if (!isset($repo['type'])) {
throw new \UnexpectedValueException('Repository ' . $index . ' must have a type defined');
}
$repository = $this->manager->createRepository($repo['type'], $repo);
$this->manager->addRepository($repository);
}
$package->setRepositories($config['repositories']);
}
return $package;
}
开发者ID:natxet,项目名称:composer,代码行数:27,代码来源:RootPackageLoader.php
示例20: load
public function load($config)
{
if (!isset($config['name'])) {
$config['name'] = '__root__';
}
if (!isset($config['version'])) {
$version = '1.0.0';
// try to fetch current version from git branch
if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output)) {
foreach ($this->process->splitLines($output) as $branch) {
if ($branch && preg_match('{^(?:\\* ) *(?:[^/ ]+?/)?(\\S+) *[a-f0-9]+ .*$}', $branch, $match)) {
$version = 'dev-' . $match[1];
}
}
}
// override with env var if available
if (getenv('COMPOSER_ROOT_VERSION')) {
$version = getenv('COMPOSER_ROOT_VERSION');
}
$config['version'] = $version;
} else {
$version = $config['version'];
}
$package = parent::load($config);
$aliases = array();
$stabilityFlags = array();
$references = array();
foreach (array('require', 'require-dev') as $linkType) {
if (isset($config[$linkType])) {
$aliases = $this->extractAliases($config[$linkType], $aliases);
$stabilityFlags = $this->extractStabilityFlags($config[$linkType], $stabilityFlags);
$references = $this->extractReferences($config[$linkType], $references);
}
}
$package->setAliases($aliases);
$package->setStabilityFlags($stabilityFlags);
$package->setReferences($references);
if (isset($config['minimum-stability'])) {
$package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
}
if (isset($config['repositories'])) {
foreach ($config['repositories'] as $index => $repo) {
if (isset($repo['packagist']) && $repo['packagist'] === false) {
continue;
}
if (!is_array($repo)) {
throw new \UnexpectedValueException('Repository ' . $index . ' should be an array, ' . gettype($repo) . ' given');
}
if (!isset($repo['type'])) {
throw new \UnexpectedValueException('Repository ' . $index . ' (' . json_encode($repo) . ') must have a type defined');
}
$repository = $this->manager->createRepository($repo['type'], $repo);
$this->manager->addRepository($repository);
}
$package->setRepositories($config['repositories']);
}
return $package;
}
开发者ID:romainneutron,项目名称:composer,代码行数:58,代码来源:RootPackageLoader.php
注:本文中的Composer\Package\Loader\ArrayLoader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论