2015-08-18 13:40:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Repository;
|
|
|
|
|
2015-08-18 14:08:27 +00:00
|
|
|
use Composer\Config;
|
|
|
|
use Composer\IO\IOInterface;
|
2015-08-18 13:40:48 +00:00
|
|
|
use Composer\Json\JsonFile;
|
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
2015-08-25 21:06:48 +00:00
|
|
|
use Composer\Package\Loader\LoaderInterface;
|
2015-08-18 14:08:27 +00:00
|
|
|
use Composer\Package\Version\VersionGuesser;
|
|
|
|
use Composer\Package\Version\VersionParser;
|
|
|
|
use Composer\Util\ProcessExecutor;
|
2015-08-18 13:40:48 +00:00
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This repository allows installing local packages that are not necessarily under their own VCS.
|
|
|
|
*
|
|
|
|
* The local packages will be symlinked when possible, else they will be copied.
|
|
|
|
*
|
|
|
|
* @code
|
|
|
|
* "require": {
|
|
|
|
* "<vendor>/<local-package>": "*"
|
|
|
|
* },
|
|
|
|
* "repositories": [
|
|
|
|
* {
|
|
|
|
* "type": "path",
|
|
|
|
* "url": "../../relative/path/to/package/"
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* "type": "path",
|
|
|
|
* "url": "/absolute/path/to/package/"
|
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* @author Samuel Roze <samuel.roze@gmail.com>
|
|
|
|
* @author Johann Reinke <johann.reinke@gmail.com>
|
|
|
|
*/
|
|
|
|
class PathRepository extends ArrayRepository
|
|
|
|
{
|
2015-08-18 14:08:27 +00:00
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
2015-08-18 13:40:48 +00:00
|
|
|
/**
|
|
|
|
* @var Filesystem
|
|
|
|
*/
|
|
|
|
private $fileSystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ArrayLoader
|
|
|
|
*/
|
|
|
|
private $loader;
|
|
|
|
|
2015-08-18 14:08:27 +00:00
|
|
|
/**
|
|
|
|
* @var VersionGuesser
|
|
|
|
*/
|
|
|
|
private $versionGuesser;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $packageConfig;
|
|
|
|
|
2015-08-18 13:40:48 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $path;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes path repository.
|
|
|
|
*
|
2015-08-18 14:08:27 +00:00
|
|
|
* @param array $packageConfig
|
|
|
|
* @param IOInterface $io
|
|
|
|
* @param Config $config
|
2015-08-25 21:06:48 +00:00
|
|
|
* @param LoaderInterface $loader
|
|
|
|
* @param Filesystem $filesystem
|
|
|
|
* @param VersionGuesser $versionGuesser
|
2015-08-18 13:40:48 +00:00
|
|
|
*/
|
2015-08-25 21:06:48 +00:00
|
|
|
public function __construct(array $packageConfig, IOInterface $io, Config $config, LoaderInterface $loader = null, Filesystem $filesystem = null, VersionGuesser $versionGuesser = null)
|
2015-08-18 13:40:48 +00:00
|
|
|
{
|
2015-08-18 14:08:27 +00:00
|
|
|
if (!isset($packageConfig['url'])) {
|
2015-08-18 13:40:48 +00:00
|
|
|
throw new \RuntimeException('You must specify the `url` configuration for the path repository');
|
|
|
|
}
|
|
|
|
|
2015-08-25 21:06:48 +00:00
|
|
|
$this->fileSystem = $filesystem ?: new Filesystem();
|
|
|
|
$this->loader = $loader ?: new ArrayLoader();
|
2015-08-18 14:08:27 +00:00
|
|
|
$this->config = $config;
|
|
|
|
$this->packageConfig = $packageConfig;
|
|
|
|
$this->path = realpath(rtrim($packageConfig['url'], '/')) . '/';
|
2015-08-25 21:06:48 +00:00
|
|
|
$this->versionGuesser = $versionGuesser ?: new VersionGuesser(new ProcessExecutor($io), new VersionParser(), $this->path);
|
2015-08-18 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes path repository.
|
|
|
|
*
|
|
|
|
* This method will basically read the folder and add the found package.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function initialize()
|
|
|
|
{
|
|
|
|
parent::initialize();
|
|
|
|
|
|
|
|
$composerFilePath = $this->path.'composer.json';
|
|
|
|
if (!$this->fileSystem->exists($composerFilePath)) {
|
|
|
|
throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $this->path));
|
|
|
|
}
|
|
|
|
|
|
|
|
$json = file_get_contents($composerFilePath);
|
|
|
|
$package = JsonFile::parseJson($json, $composerFilePath);
|
|
|
|
$package['dist'] = array(
|
2015-08-18 14:08:27 +00:00
|
|
|
'type' => 'path',
|
2015-08-18 13:40:48 +00:00
|
|
|
'url' => $this->path,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!isset($package['version'])) {
|
2015-08-18 14:08:27 +00:00
|
|
|
$package['version'] = $this->versionGuesser->guessVersion($this->config, $this->packageConfig) ?: 'dev-master';
|
2015-08-18 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$package = $this->loader->load($package);
|
|
|
|
$this->addPackage($package);
|
|
|
|
}
|
|
|
|
}
|