Skip to content

Commit 8fa0dd6

Browse files
committed
merge conflicts
1 parent 5be2d76 commit 8fa0dd6

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

ServiceLocator.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,40 @@ private function createServiceNotFoundMessage($id)
9494
$class = isset($class[2]['object']) ? \get_class($class[2]['object']) : null;
9595
$externalId = $this->externalId ?: $class;
9696

97-
$msg = sprintf('Service "%s" not found: ', $id);
97+
$msg = array();
98+
$msg[] = sprintf('Service "%s" not found:', $id);
9899

99100
if (!$this->container) {
100101
$class = null;
101102
} elseif ($this->container->has($id) || isset($this->container->getRemovedIds()[$id])) {
102-
$msg .= 'even though it exists in the app\'s container, ';
103+
$msg[] = 'even though it exists in the app\'s container,';
103104
} else {
104105
try {
105106
$this->container->get($id);
106107
$class = null;
107108
} catch (ServiceNotFoundException $e) {
108109
if ($e->getAlternatives()) {
109-
$msg .= sprintf(' did you mean %s? Anyway, ', $this->formatAlternatives($e->getAlternatives(), 'or'));
110+
$msg[] = sprintf('did you mean %s? Anyway,', $this->formatAlternatives($e->getAlternatives(), 'or'));
110111
} else {
111112
$class = null;
112113
}
113114
}
114115
}
115116
if ($externalId) {
116-
$msg .= sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives());
117+
$msg[] = sprintf('the container inside "%s" is a smaller service locator that %s', $externalId, $this->formatAlternatives());
117118
} else {
118-
$msg .= sprintf('the current service locator %s', $this->formatAlternatives());
119+
$msg[] = sprintf('the current service locator %s', $this->formatAlternatives());
119120
}
120121

121122
if (!$class) {
122123
// no-op
123124
} elseif (is_subclass_of($class, ServiceSubscriberInterface::class)) {
124-
$msg .= sprintf(' Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', preg_replace('/([^\\\\]++\\\\)++/', '', $class));
125+
$msg[] = sprintf('Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "%s::getSubscribedServices()".', preg_replace('/([^\\\\]++\\\\)++/', '', $class));
125126
} else {
126-
$msg .= 'Try using dependency injection instead.';
127+
$msg[] = 'Try using dependency injection instead.';
127128
}
128129

129-
return $msg;
130+
return implode(' ', $msg);
130131
}
131132

132133
private function formatAlternatives(array $alternatives = null, $separator = 'and')

Tests/ServiceLocatorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ public function testThrowsInServiceSubscriber()
115115
$subscriber->getFoo();
116116
}
117117

118+
/**
119+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
120+
* @expectedExceptionMessage Service "foo" not found: even though it exists in the app's container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead.
121+
*/
122+
public function testGetThrowsServiceNotFoundException()
123+
{
124+
$container = new Container();
125+
$container->set('foo', new \stdClass());
126+
127+
$locator = new ServiceLocator(array());
128+
$locator = $locator->withContext('foo', $container);
129+
$locator->get('foo');
130+
}
131+
118132
public function testInvoke()
119133
{
120134
$locator = new ServiceLocator(array(

0 commit comments

Comments
 (0)