-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to register handlers on a specific transport (and get rid of t…
…his handler alias)
- Loading branch information
Showing
23 changed files
with
426 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/Symfony/Component/Messenger/Handler/HandlerDescriptor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Handler; | ||
|
||
/** | ||
* Describes a handler and the possible associated options, such as `from_transport`, `bus`, etc. | ||
* | ||
* @author Samuel Roze <samuel.roze@gmail.com> | ||
* | ||
* @experimental in 4.3 | ||
*/ | ||
final class HandlerDescriptor | ||
{ | ||
private $handler; | ||
private $options; | ||
|
||
public function __construct(callable $handler, array $options = []) | ||
{ | ||
$this->handler = $handler; | ||
$this->options = $options; | ||
} | ||
|
||
public function getHandler(): callable | ||
{ | ||
return $this->handler; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
$name = $this->callableName($this->handler); | ||
$alias = $this->options['alias'] ?? null; | ||
|
||
if (null !== $alias) { | ||
$name .= '@'.$alias; | ||
} | ||
|
||
return $name; | ||
} | ||
|
||
public function getOption(string $option) | ||
{ | ||
return $this->options[$option] ?? null; | ||
} | ||
|
||
private function callableName(callable $handler) | ||
{ | ||
if (\is_array($handler)) { | ||
if (\is_object($handler[0])) { | ||
return \get_class($handler[0]).'::'.$handler[1]; | ||
} | ||
|
||
return $handler[0].'::'.$handler[1]; | ||
} | ||
|
||
if (\is_string($handler)) { | ||
return $handler; | ||
} | ||
|
||
if ($handler instanceof \Closure) { | ||
$r = new \ReflectionFunction($handler); | ||
if (false !== strpos($r->name, '{closure}')) { | ||
return 'Closure'; | ||
} | ||
if ($class = $r->getClosureScopeClass()) { | ||
return $class->name.'::'.$r->name; | ||
} | ||
|
||
return $r->name; | ||
} | ||
|
||
return \get_class($handler).'::__invoke'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.