mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-25 02:22:57 +01:00
Adding alias support to service builders
This commit is contained in:
parent
6fa131581a
commit
2d2637ce11
@ -128,6 +128,12 @@ class ServiceBuilder extends AbstractHasDispatcher implements ServiceBuilderInte
|
||||
public function get($name, $throwAway = false)
|
||||
{
|
||||
if (!isset($this->builderConfig[$name])) {
|
||||
// Check aliases and return a match if found
|
||||
foreach ($this->builderConfig as $actualName => $config) {
|
||||
if (isset($config['alias']) && $config['alias'] == $name) {
|
||||
return $this->get($actualName, $throwAway);
|
||||
}
|
||||
}
|
||||
throw new ServiceNotFoundException('No service is registered as ' . $name);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ class ServiceBuilderTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
),
|
||||
),
|
||||
'billy.mock' => array(
|
||||
'alias' => 'Hello!',
|
||||
'class' => 'Guzzle\Tests\Service\Mock\MockClient',
|
||||
'params' => array(
|
||||
'username' => 'billy',
|
||||
@ -294,4 +295,10 @@ class ServiceBuilderTest extends \Guzzle\Tests\GuzzleTestCase
|
||||
$this->assertEquals($this->arrayData['michael.mock'], $b->getData('michael.mock'));
|
||||
$this->assertNull($b->getData('ewofweoweofe'));
|
||||
}
|
||||
|
||||
public function testCanGetByAlias()
|
||||
{
|
||||
$b = new ServiceBuilder($this->arrayData);
|
||||
$this->assertSame($b->get('billy.mock'), $b->get('Hello!'));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user