Allow bin key to receive string

main
Gabriel Caruso 7 years ago
parent 6717cf1956
commit 2ad6f611d7

@ -368,8 +368,8 @@
"description": "If set to true, stable packages will be preferred to dev packages when possible, even if the minimum-stability allows unstable packages." "description": "If set to true, stable packages will be preferred to dev packages when possible, even if the minimum-stability allows unstable packages."
}, },
"bin": { "bin": {
"type": ["array"], "type": ["string", "array"],
"description": "A set of files that should be treated as binaries and symlinked into bin-dir (from config).", "description": "A set of files, or a single file, that should be treated as binaries and symlinked into bin-dir (from config).",
"items": { "items": {
"type": "string" "type": "string"
} }
@ -776,8 +776,8 @@
} }
}, },
"bin": { "bin": {
"type": ["array"], "type": ["string", "array"],
"description": "A set of files that should be treated as binaries and symlinked into bin-dir (from config).", "description": "A set of files, or a single file, that should be treated as binaries and symlinked into bin-dir (from config).",
"items": { "items": {
"type": "string" "type": "string"
} }

@ -65,13 +65,10 @@ class ArrayLoader implements LoaderInterface
} }
if (isset($config['bin'])) { if (isset($config['bin'])) {
if (!is_array($config['bin'])) { foreach ((array) $config['bin'] as $key => $bin) {
throw new \UnexpectedValueException('Package '.$config['name'].'\'s bin key should be an array, '.gettype($config['bin']).' given.');
}
foreach ($config['bin'] as $key => $bin) {
$config['bin'][$key] = ltrim($bin, '/'); $config['bin'][$key] = ltrim($bin, '/');
} }
$package->setBinaries($config['bin']); $package->setBinaries((array) $config['bin']);
} }
if (isset($config['installation-source'])) { if (isset($config['installation-source'])) {

@ -77,7 +77,15 @@ class ValidatingArrayLoader implements LoaderInterface
$this->validateRegex('type', '[A-Za-z0-9-]+'); $this->validateRegex('type', '[A-Za-z0-9-]+');
$this->validateString('target-dir'); $this->validateString('target-dir');
$this->validateArray('extra'); $this->validateArray('extra');
$this->validateFlatArray('bin');
if (isset($this->config['bin'])) {
if (is_string($this->config['bin'])) {
$this->validateString('bin');
} else {
$this->validateFlatArray('bin');
}
}
$this->validateArray('scripts'); // TODO validate event names & listener syntax $this->validateArray('scripts'); // TODO validate event names & listener syntax
$this->validateString('description'); $this->validateString('description');
$this->validateUrl('homepage'); $this->validateUrl('homepage');

@ -47,7 +47,7 @@
"autoload-dev": { "autoload-dev": {
"psr-0": { "Composer\\Test": "tests/" } "psr-0": { "Composer\\Test": "tests/" }
}, },
"bin": ["bin/composer"], "bin": "bin/composer",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0-dev" "dev-master": "1.0-dev"

@ -151,12 +151,18 @@ class ValidatingArrayLoaderTest extends TestCase
'transport-options' => array('ssl' => array('local_cert' => '/opt/certs/test.pem')), 'transport-options' => array('ssl' => array('local_cert' => '/opt/certs/test.pem')),
), ),
), ),
array( // test as array array( // test licenses as array
array( array(
'name' => 'foo/bar', 'name' => 'foo/bar',
'license' => array('MIT', 'WTFPL'), 'license' => array('MIT', 'WTFPL'),
), ),
), ),
array( // test bin as string
array(
'name' => 'foo/bar',
'bin' => 'bin1',
),
),
); );
} }

Loading…
Cancel
Save