@@ -22,29 +22,29 @@ discard block |
||
| 22 | 22 | private readonly ReaderInterface $reader, |
| 23 | 23 | private readonly ListenerFactoryInterface $factory, |
| 24 | 24 | private readonly ?ListenerRegistryInterface $registry = null, |
| 25 | - ) { |
|
| 25 | + ){ |
|
| 26 | 26 | // Look for Spiral\Events\Attribute\Listener attribute only when ListenerRegistry provided by container |
| 27 | - if ($this->registry !== null) { |
|
| 27 | + if ($this->registry !== null){ |
|
| 28 | 28 | $listenerRegistry->addListener($this); |
| 29 | 29 | } |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function process(): void |
| 33 | 33 | { |
| 34 | - if ($this->registry === null) { |
|
| 34 | + if ($this->registry === null){ |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - if (!$this->collected) { |
|
| 38 | + if (!$this->collected){ |
|
| 39 | 39 | throw new \RuntimeException(\sprintf('Tokenizer did not finalize %s listener.', self::class)); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - foreach ($this->attributes as $listener => $attributes) { |
|
| 43 | - foreach ($attributes as $attribute) { |
|
| 42 | + foreach ($this->attributes as $listener => $attributes){ |
|
| 43 | + foreach ($attributes as $attribute){ |
|
| 44 | 44 | $method = $this->getMethod($listener, $attribute->method ?? '__invoke'); |
| 45 | 45 | |
| 46 | 46 | $events = (array)($attribute->event ?? $this->getEventFromTypeDeclaration($method)); |
| 47 | - foreach ($events as $event) { |
|
| 47 | + foreach ($events as $event){ |
|
| 48 | 48 | $this->registry->addListener( |
| 49 | 49 | event: $event, |
| 50 | 50 | listener: $this->factory->create($listener, $method->getName()), |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | $attrs = $this->reader->getClassMetadata($class, Listener::class); |
| 61 | 61 | |
| 62 | - foreach ($attrs as $attr) { |
|
| 62 | + foreach ($attrs as $attr){ |
|
| 63 | 63 | $this->attributes[$class->getName()][] = $attr; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - foreach ($class->getMethods() as $method) { |
|
| 66 | + foreach ($class->getMethods() as $method){ |
|
| 67 | 67 | $attrs = $this->reader->getFunctionMetadata($method, Listener::class); |
| 68 | 68 | |
| 69 | - foreach ($attrs as $attr) { |
|
| 69 | + foreach ($attrs as $attr){ |
|
| 70 | 70 | $attr->method = $method->getName(); |
| 71 | 71 | $this->attributes[$class->getName()][] = $attr; |
| 72 | 72 | } |
@@ -24,27 +24,33 @@ discard block |
||
| 24 | 24 | private readonly ?ListenerRegistryInterface $registry = null, |
| 25 | 25 | ) { |
| 26 | 26 | // Look for Spiral\Events\Attribute\Listener attribute only when ListenerRegistry provided by container |
| 27 | - if ($this->registry !== null) { |
|
| 27 | + if ($this->registry !== null) |
|
| 28 | + { |
|
| 28 | 29 | $listenerRegistry->addListener($this); |
| 29 | 30 | } |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | public function process(): void |
| 33 | 34 | { |
| 34 | - if ($this->registry === null) { |
|
| 35 | + if ($this->registry === null) |
|
| 36 | + { |
|
| 35 | 37 | return; |
| 36 | 38 | } |
| 37 | 39 | |
| 38 | - if (!$this->collected) { |
|
| 40 | + if (!$this->collected) |
|
| 41 | + { |
|
| 39 | 42 | throw new \RuntimeException(\sprintf('Tokenizer did not finalize %s listener.', self::class)); |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | - foreach ($this->attributes as $listener => $attributes) { |
|
| 43 | - foreach ($attributes as $attribute) { |
|
| 45 | + foreach ($this->attributes as $listener => $attributes) |
|
| 46 | + { |
|
| 47 | + foreach ($attributes as $attribute) |
|
| 48 | + { |
|
| 44 | 49 | $method = $this->getMethod($listener, $attribute->method ?? '__invoke'); |
| 45 | 50 | |
| 46 | 51 | $events = (array)($attribute->event ?? $this->getEventFromTypeDeclaration($method)); |
| 47 | - foreach ($events as $event) { |
|
| 52 | + foreach ($events as $event) |
|
| 53 | + { |
|
| 48 | 54 | $this->registry->addListener( |
| 49 | 55 | event: $event, |
| 50 | 56 | listener: $this->factory->create($listener, $method->getName()), |
@@ -59,14 +65,17 @@ discard block |
||
| 59 | 65 | { |
| 60 | 66 | $attrs = $this->reader->getClassMetadata($class, Listener::class); |
| 61 | 67 | |
| 62 | - foreach ($attrs as $attr) { |
|
| 68 | + foreach ($attrs as $attr) |
|
| 69 | + { |
|
| 63 | 70 | $this->attributes[$class->getName()][] = $attr; |
| 64 | 71 | } |
| 65 | 72 | |
| 66 | - foreach ($class->getMethods() as $method) { |
|
| 73 | + foreach ($class->getMethods() as $method) |
|
| 74 | + { |
|
| 67 | 75 | $attrs = $this->reader->getFunctionMetadata($method, Listener::class); |
| 68 | 76 | |
| 69 | - foreach ($attrs as $attr) { |
|
| 77 | + foreach ($attrs as $attr) |
|
| 78 | + { |
|
| 70 | 79 | $attr->method = $method->getName(); |
| 71 | 80 | $this->attributes[$class->getName()][] = $attr; |
| 72 | 81 | } |