-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checker for check requirements before run consumer
- Loading branch information
Showing
15 changed files
with
503 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
Next release | ||
------------ | ||
|
||
* Add run checker (check before run consumer). | ||
|
||
v2.0.3 | ||
------ | ||
|
||
|
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
47 changes: 47 additions & 0 deletions
47
src/Consumer/Checker/ContainerRunConsumerCheckerRegistry.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,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FiveLab Amqp package | ||
* | ||
* (c) FiveLab | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace FiveLab\Component\Amqp\Consumer\Checker; | ||
|
||
use FiveLab\Component\Amqp\Exception\RunConsumerCheckerNotFoundException; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* Registry based on PSR container. | ||
*/ | ||
readonly class ContainerRunConsumerCheckerRegistry implements RunConsumerCheckerRegistryInterface | ||
{ | ||
/** | ||
* Constructor. | ||
* | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct(private ContainerInterface $container) | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get(string $key): RunConsumerCheckerInterface | ||
{ | ||
if ($this->container->has($key)) { | ||
return $this->container->get($key); | ||
} | ||
|
||
throw new RunConsumerCheckerNotFoundException(\sprintf( | ||
'The checker for consumer "%s" was not found.', | ||
$key | ||
)); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FiveLab Amqp package | ||
* | ||
* (c) FiveLab | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace FiveLab\Component\Amqp\Consumer\Checker; | ||
|
||
use FiveLab\Component\Amqp\Exception\CannotRunConsumerException; | ||
|
||
/** | ||
* All consumer checkers should implement this interface. | ||
*/ | ||
interface RunConsumerCheckerInterface | ||
{ | ||
/** | ||
* Call to this method before run consumer. | ||
* | ||
* @throws CannotRunConsumerException | ||
*/ | ||
public function checkBeforeRun(): void; | ||
} |
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,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FiveLab Amqp package | ||
* | ||
* (c) FiveLab | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace FiveLab\Component\Amqp\Consumer\Checker; | ||
|
||
use FiveLab\Component\Amqp\Exception\RunConsumerCheckerNotFoundException; | ||
|
||
/** | ||
* Simple registry for run consumer checker | ||
*/ | ||
class RunConsumerCheckerRegistry implements RunConsumerCheckerRegistryInterface | ||
{ | ||
/** | ||
* @var array<string, RunConsumerCheckerInterface> | ||
*/ | ||
private array $checkers = []; | ||
|
||
/** | ||
* Add checker for consumer to registry | ||
* | ||
* @param string $key | ||
* @param RunConsumerCheckerInterface $checker | ||
*/ | ||
public function add(string $key, RunConsumerCheckerInterface $checker): void | ||
{ | ||
$this->checkers[$key] = $checker; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get(string $key): RunConsumerCheckerInterface | ||
{ | ||
return $this->checkers[$key] ?? throw new RunConsumerCheckerNotFoundException(\sprintf( | ||
'The checker for consumer "%s" was not found.', | ||
$key | ||
)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Consumer/Checker/RunConsumerCheckerRegistryInterface.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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FiveLab Amqp package | ||
* | ||
* (c) FiveLab | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace FiveLab\Component\Amqp\Consumer\Checker; | ||
|
||
use FiveLab\Component\Amqp\Exception\RunConsumerCheckerNotFoundException; | ||
|
||
/** | ||
* All run consumer checker registries should implement this interface. | ||
*/ | ||
interface RunConsumerCheckerRegistryInterface | ||
{ | ||
/** | ||
* Get checker for consumer | ||
* | ||
* @param string $key | ||
* | ||
* @return RunConsumerCheckerInterface | ||
* | ||
* @throws RunConsumerCheckerNotFoundException | ||
*/ | ||
public function get(string $key): RunConsumerCheckerInterface; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FiveLab Amqp package | ||
* | ||
* (c) FiveLab | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace FiveLab\Component\Amqp\Exception; | ||
|
||
/** | ||
* Throw this error if consumer can't be runned. | ||
*/ | ||
class CannotRunConsumerException extends \Exception | ||
{ | ||
} |
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,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FiveLab Amqp package | ||
* | ||
* (c) FiveLab | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code | ||
*/ | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace FiveLab\Component\Amqp\Exception; | ||
|
||
class RunConsumerCheckerNotFoundException extends \Exception | ||
{ | ||
} |
Oops, something went wrong.