2011-09-25 17:59:10 +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;
|
|
|
|
|
2011-10-01 13:01:33 +00:00
|
|
|
use Composer\Json\JsonFile;
|
2011-09-25 17:59:10 +00:00
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
|
|
|
use Composer\Package\Dumper\ArrayDumper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filesystem repository.
|
|
|
|
*
|
|
|
|
* @author Konstantin Kudryashov <ever.zet@gmail.com>
|
|
|
|
*/
|
|
|
|
class FilesystemRepository extends ArrayRepository implements WritableRepositoryInterface
|
|
|
|
{
|
|
|
|
private $file;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes filesystem repository.
|
|
|
|
*
|
2011-10-01 13:01:33 +00:00
|
|
|
* @param JsonFile $repositoryFile repository json file
|
2011-09-25 17:59:10 +00:00
|
|
|
*/
|
2011-10-01 13:01:33 +00:00
|
|
|
public function __construct(JsonFile $repositoryFile)
|
2011-09-25 17:59:10 +00:00
|
|
|
{
|
|
|
|
$this->file = $repositoryFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes repository (reads file, or remote address).
|
|
|
|
*/
|
|
|
|
protected function initialize()
|
|
|
|
{
|
|
|
|
parent::initialize();
|
|
|
|
|
2011-10-01 13:01:33 +00:00
|
|
|
$packages = $this->file->read();
|
2011-09-25 17:59:10 +00:00
|
|
|
if (is_array($packages)) {
|
|
|
|
$loader = new ArrayLoader();
|
|
|
|
foreach ($packages as $package) {
|
|
|
|
$this->addPackage($loader->load($package));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes writable repository.
|
|
|
|
*/
|
|
|
|
public function write()
|
|
|
|
{
|
|
|
|
$packages = array();
|
|
|
|
$dumper = new ArrayDumper();
|
|
|
|
foreach ($this->getPackages() as $package) {
|
|
|
|
$packages[] = $dumper->dump($package);
|
|
|
|
}
|
|
|
|
|
2011-10-01 13:01:33 +00:00
|
|
|
$this->file->write($packages);
|
2011-09-25 17:59:10 +00:00
|
|
|
}
|
|
|
|
}
|