-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(history): allow
#[TagStamp]
to be added to parent classes/inte…
…rfaces
- Loading branch information
Showing
7 changed files
with
82 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Stamp; | ||
|
||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Stamp\StampInterface; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
abstract class AttributeStamp implements StampInterface | ||
{ | ||
/** | ||
* @internal | ||
* | ||
* @return static[] | ||
*/ | ||
final public static function from(Envelope $envelope): iterable | ||
{ | ||
foreach ($envelope->all(static::class) as $stamp) { | ||
yield $stamp; // @phpstan-ignore generator.valueType | ||
} | ||
|
||
$original = $reflection = new \ReflectionClass($envelope->getMessage()); | ||
|
||
while (false !== $reflection) { | ||
|
||
foreach ($reflection->getAttributes(static::class) as $attribute) { | ||
yield $attribute->newInstance(); | ||
} | ||
|
||
$reflection = $reflection->getParentClass(); | ||
} | ||
|
||
foreach ($original->getInterfaces() as $refInterface) { | ||
foreach ($refInterface->getAttributes(static::class) as $attribute) { | ||
yield $attribute->newInstance(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final public static function firstFrom(Envelope $envelope): ?static | ||
{ | ||
foreach (self::from($envelope) as $stamp) { | ||
return $stamp; | ||
} | ||
|
||
return null; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,41 +11,13 @@ | |
|
||
namespace Zenstruck\Messenger\Monitor\Stamp; | ||
|
||
use Symfony\Component\Messenger\Stamp\StampInterface; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class DisableMonitoringStamp implements StampInterface | ||
final class DisableMonitoringStamp extends AttributeStamp | ||
{ | ||
public function __construct(public readonly bool $onlyWhenNoHandler = false) | ||
{ | ||
} | ||
|
||
/** | ||
* @internal | ||
* | ||
* @param class-string $class | ||
*/ | ||
public static function getFor(string $class): ?self | ||
{ | ||
$original = $reflection = new \ReflectionClass($class); | ||
|
||
while (false !== $reflection) { | ||
if ($attributes = $reflection->getAttributes(self::class)) { | ||
return $attributes[0]->newInstance(); | ||
} | ||
|
||
$reflection = $reflection->getParentClass(); | ||
} | ||
|
||
foreach ($original->getInterfaces() as $refInterface) { | ||
if ($attributes = $refInterface->getAttributes(self::class)) { | ||
return $attributes[0]->newInstance(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,15 +11,14 @@ | |
|
||
namespace Zenstruck\Messenger\Monitor\Stamp; | ||
|
||
use Symfony\Component\Messenger\Stamp\StampInterface; | ||
use Symfony\Component\Scheduler\Messenger\ScheduledStamp; | ||
use Zenstruck\Messenger\Monitor\Schedule\TaskInfo; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] | ||
final class TagStamp implements StampInterface, \Stringable | ||
final class TagStamp extends AttributeStamp implements \Stringable | ||
{ | ||
public function __construct( | ||
public readonly string $value, | ||
|
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