Skip to content

Commit

Permalink
Added addLink and removeLink to Configuration Source Interface
Browse files Browse the repository at this point in the history
 * Added addLink() and removeLink() to `ConfigSourceInterface`
 * Added addLink() and removeLink() implementations to `JsonConfigSource`
 * Added tests (+ a ton of fixtures) for `JsonConfigSource`
 * Added additional docblocks
 * Minor PSR-1/PSR-2 fixes here and there
  • Loading branch information
simensen committed Nov 14, 2012
1 parent 172414a commit 752fa64
Show file tree
Hide file tree
Showing 48 changed files with 1,069 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/Composer/Config/ConfigSourceInterface.php
Expand Up @@ -13,15 +13,57 @@
namespace Composer\Config;

/**
* Configuration Source Interface
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Beau Simensen <beau@dflydev.com>
*/
interface ConfigSourceInterface
{
/**
* Add a repository
*
* @param string $name Name
* @param array $config Configuration
*/
public function addRepository($name, $config);

/**
* Remove a repository
*
* @param string $name
*/
public function removeRepository($name);

/**
* Add a config setting
*
* @param string $name Name
* @param string $value Value
*/
public function addConfigSetting($name, $value);

/**
* Remove a config setting
*
* @param string $name
*/
public function removeConfigSetting($name);

/**
* Add a package link
*
* @param string $type Type (require, require-dev, provide, suggest, replace, conflict)
* @param string $name Name
* @param string $value Value
*/
public function addLink($type, $name, $value);

/**
* Remove a package link
*
* @param string $type Type (require, require-dev, provide, suggest, replace, conflict)
* @param string $name Name
*/
public function removeLink($type, $name);
}
42 changes: 41 additions & 1 deletion src/Composer/Config/JsonConfigSource.php
Expand Up @@ -12,50 +12,90 @@

namespace Composer\Config;

use Composer\Json\JsonManipulator;
use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator;

/**
* JSON Configuration Source
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Beau Simensen <beau@dflydev.com>
*/
class JsonConfigSource implements ConfigSourceInterface
{
private $file;
private $manipulator;

/**
* Constructor
*
* @param JsonFile $file
*/
public function __construct(JsonFile $file)
{
$this->file = $file;
}

/**
* {@inheritdoc}
*/
public function addRepository($name, $config)
{
$this->manipulateJson('addRepository', $name, $config, function (&$config, $repo, $repoConfig) {
$config['repositories'][$repo] = $repoConfig;
});
}

/**
* {@inheritdoc}
*/
public function removeRepository($name)
{
$this->manipulateJson('removeRepository', $name, function (&$config, $repo) {
unset($config['repositories'][$repo]);
});
}

/**
* {@inheritdoc}
*/
public function addConfigSetting($name, $value)
{
$this->manipulateJson('addConfigSetting', $name, $value, function (&$config, $key, $val) {
$config['config'][$key] = $val;
});
}

/**
* {@inheritdoc}
*/
public function removeConfigSetting($name)
{
$this->manipulateJson('removeConfigSetting', $name, function (&$config, $key) {
unset($config['config'][$key]);
});
}

/**
* {@inheritdoc}
*/
public function addLink($type, $name, $value)
{
$this->manipulateJson('addLink', $type, $name, $value, function (&$config, $key) {
$config[$type][$name] = $value;
});
}

/**
* {@inheritdoc}
*/
public function removeLink($type, $name)
{
$this->manipulateJson('removeSubNode', $type, $name, function (&$config, $key) {
unset($config[$type][$name]);
});
}

protected function manipulateJson($method, $args, $fallback)
{
$args = func_get_args();
Expand Down
@@ -0,0 +1,7 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"conflict": {
"my-vend/my-old-app": "1.*"
}
}
@@ -0,0 +1,23 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*",
"my-vend/my-old-app": "1.*"
}
}
@@ -0,0 +1,29 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*",
"my-vend/my-yet-another-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*",
"my-vend/my-yet-another-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*",
"my-vend/my-yet-another-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*",
"my-vend/my-yet-another-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*",
"other-vend/yet-another-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*",
"my-vend/my-yet-another-old-app": "1.*",
"my-vend/my-old-app": "1.*"
}
}
@@ -0,0 +1,7 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"provide": {
"my-vend/my-lib-interface": "1.*"
}
}
@@ -0,0 +1,23 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*",
"my-vend/my-lib-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*"
}
}
@@ -0,0 +1,29 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*",
"my-vend/my-yet-another-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*",
"my-vend/my-yet-another-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*",
"my-vend/my-yet-another-interface": "1.*",
"my-vend/my-lib-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*",
"my-vend/my-yet-another-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*",
"other-vend/yet-another-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*",
"my-vend/my-yet-another-old-app": "1.*"
}
}
@@ -0,0 +1,7 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"replace": {
"my-vend/other-app": "1.*"
}
}
@@ -0,0 +1,23 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*",
"my-vend/other-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*"
}
}
@@ -0,0 +1,29 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*",
"my-vend/my-yet-another-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*",
"my-vend/my-yet-another-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*",
"my-vend/my-yet-another-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*",
"my-vend/my-yet-another-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*",
"other-vend/yet-another-app": "1.*",
"my-vend/other-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*",
"my-vend/my-yet-another-old-app": "1.*"
}
}
@@ -0,0 +1,7 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require-dev": {
"my-vend/my-lib-tests": "1.*"
}
}
@@ -0,0 +1,23 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*",
"my-vend/my-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*"
}
}
@@ -0,0 +1,29 @@
{
"name": "my-vend/my-app",
"license": "MIT",
"require": {
"my-vend/my-other-lib": "1.*",
"my-vend/my-yet-another-lib": "1.*"
},
"require-dev": {
"my-vend/my-other-lib-tests": "1.*",
"my-vend/my-yet-another-lib-tests": "1.*",
"my-vend/my-lib-tests": "1.*"
},
"provide": {
"my-vend/my-other-interface": "1.*",
"my-vend/my-yet-another-interface": "1.*"
},
"suggest": {
"my-vend/my-other-optional-extension": "1.*",
"my-vend/my-yet-another-optional-extension": "1.*"
},
"replace": {
"other-vend/other-app": "1.*",
"other-vend/yet-another-app": "1.*"
},
"conflict": {
"my-vend/my-other-old-app": "1.*",
"my-vend/my-yet-another-old-app": "1.*"
}
}

0 comments on commit 752fa64

Please sign in to comment.