Skip to content

Commit 6d8a9f6

Browse files
committed
merged 2.0 branch
2 parents e226e52 + 1fdca56 commit 6d8a9f6

File tree

4 files changed

+118
-3
lines changed

4 files changed

+118
-3
lines changed

Command/AssetsInstallCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818
use Symfony\Component\Console\Output\Output;
19+
use Symfony\Component\Finder\Finder;
1920

2021
/**
2122
* Command that places bundle web assets into a given directory.
@@ -85,7 +86,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8586
$filesystem->symlink($originDir, $targetDir);
8687
} else {
8788
$filesystem->mkdir($targetDir, 0777);
88-
$filesystem->mirror($originDir, $targetDir);
89+
// We use a custom iterator to ignore VCS files
90+
$filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir));
8991
}
9092
}
9193
}

ContainerAwareEventDispatcher.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@ public function addListenerService($eventName, $callback, $priority = 0)
7171
$this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
7272
}
7373

74+
/**
75+
* @see EventDispatcherInterface::hasListeners
76+
*/
77+
public function hasListeners($eventName = null)
78+
{
79+
if (null === $eventName) {
80+
return (Boolean) count($this->listenerIds) || (Boolean) count($this->listeners);
81+
}
82+
83+
if (isset($this->listenerIds[$eventName])) {
84+
return true;
85+
}
86+
87+
return parent::hasListeners($eventName);
88+
}
89+
90+
/**
91+
* @see EventDispatcherInterface::getListeners
92+
*/
93+
public function getListeners($eventName = null)
94+
{
95+
if (null === $eventName) {
96+
foreach ($this->listenerIds as $serviceEventName => $listners) {
97+
$this->lazyLoad($serviceEventName);
98+
}
99+
} else {
100+
$this->lazyLoad($eventName);
101+
}
102+
103+
return parent::getListeners($eventName);
104+
}
105+
74106
/**
75107
* {@inheritDoc}
76108
*
@@ -80,6 +112,21 @@ public function addListenerService($eventName, $callback, $priority = 0)
80112
* @throws \InvalidArgumentException if the service is not defined
81113
*/
82114
public function dispatch($eventName, Event $event = null)
115+
{
116+
$this->lazyLoad($eventName);
117+
118+
parent::dispatch($eventName, $event);
119+
}
120+
121+
/**
122+
* Lazily loads listeners for this event from the dependency injection
123+
* container.
124+
*
125+
* @param string $eventName The name of the event to dispatch. The name of
126+
* the event is the name of the method that is
127+
* invoked on listeners.
128+
*/
129+
protected function lazyLoad($eventName)
83130
{
84131
if (isset($this->listenerIds[$eventName])) {
85132
foreach ($this->listenerIds[$eventName] as $args) {
@@ -97,7 +144,5 @@ public function dispatch($eventName, Event $event = null)
97144
$this->listeners[$eventName][$key] = $listener;
98145
}
99146
}
100-
101-
parent::dispatch($eventName, $event);
102147
}
103148
}

Resources/translations/validators.fr.xliff

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@
142142
<source>This value should be a valid number</source>
143143
<target>Cette valeur doit être un nombre</target>
144144
</trans-unit>
145+
<trans-unit id="36">
146+
<source>This file is not a valid image</source>
147+
<target>Ce fichier n'est pas une image valide</target>
148+
</trans-unit>
149+
<trans-unit id="37">
150+
<source>This is not a valid IP address</source>
151+
<target>Cette adresse IP n'est pas valide</target>
152+
</trans-unit>
153+
<trans-unit id="38">
154+
<source>This value is not a valid language</source>
155+
<target>Cette langue n'est pas valide</target>
156+
</trans-unit>
157+
<trans-unit id="39">
158+
<source>This value is not a valid locale</source>
159+
<target>Ce paramètre régional n'est pas valide</target>
160+
</trans-unit>
161+
<trans-unit id="40">
162+
<source>This value is not a valid country</source>
163+
<target>Ce pays n'est pas valide</target>
164+
</trans-unit>
165+
<trans-unit id="41">
166+
<source>This value is already used</source>
167+
<target>Cette valeur est déjà utilisée</target>
168+
</trans-unit>
145169
</body>
146170
</file>
147171
</xliff>

Tests/ContainerAwareEventDispatcherTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,50 @@ public function testReEnteringAScope()
122122

123123
$dispatcher->dispatch('onEvent');
124124
}
125+
126+
public function testHasListenersOnLazyLoad()
127+
{
128+
$event = new Event();
129+
130+
$service = $this->getMock('Symfony\Bundle\FrameworkBundle\Tests\Service');
131+
132+
$service
133+
->expects($this->once())
134+
->method('onEvent')
135+
->with($event)
136+
;
137+
138+
$container = new Container();
139+
$container->set('service.listener', $service);
140+
141+
$dispatcher = new ContainerAwareEventDispatcher($container);
142+
$dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
143+
144+
$this->assertTrue($dispatcher->hasListeners());
145+
146+
if ($dispatcher->hasListeners('onEvent')) {
147+
$dispatcher->dispatch('onEvent');
148+
}
149+
}
150+
151+
public function testGetListenersOnLazyLoad()
152+
{
153+
$event = new Event();
154+
155+
$service = $this->getMock('Symfony\Bundle\FrameworkBundle\Tests\Service');
156+
157+
$container = new Container();
158+
$container->set('service.listener', $service);
159+
160+
$dispatcher = new ContainerAwareEventDispatcher($container);
161+
$dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
162+
163+
$listeners = $dispatcher->getListeners();
164+
165+
$this->assertTrue(isset($listeners['onEvent']));
166+
167+
$this->assertEquals(1, count($dispatcher->getListeners('onEvent')));
168+
}
125169
}
126170

127171
class Service

0 commit comments

Comments
 (0)