diff --git a/CHANGELOG.md b/CHANGELOG.md index 0432329c..f042deda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Examples: ## [Unreleased] * [PR #51](https://github.com/SonsOfPHP/sonsofphp/pull/51) Added new Filesystem component +* [PR #54](https://github.com/SonsOfPHP/sonsofphp/pull/54) Queue Component ## [0.3.8] diff --git a/bard.json b/bard.json index c8b735a2..968f6c36 100644 --- a/bard.json +++ b/bard.json @@ -53,6 +53,10 @@ "path": "src/SonsOfPHP/Component/Money", "repository": "git@github.com:SonsOfPHP/money.git" }, + { + "path": "src/SonsOfPHP/Component/Queue", + "repository": "git@github.com:SonsOfPHP/queue.git" + }, { "path": "src/SonsOfPHP/Component/Version", "repository": "git@github.com:SonsOfPHP/version.git" diff --git a/composer.json b/composer.json index 3a3bfe51..5c26c7bf 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,8 @@ "symfony/dependency-injection": "^5|^6", "symfony/http-kernel": "^5|^6", "symfony/security-bundle": "^6", - "symfony/messenger": "^5|^6" + "symfony/messenger": "^5|^6", + "psr/clock": "^1.0" }, "replace": { "sonsofphp/bard": "self.version", @@ -65,7 +66,9 @@ "sonsofphp/json": "self.version", "sonsofphp/money": "self.version", "sonsofphp/version": "self.version", - "sonsofphp/cqrs-bundle": "self.version" + "sonsofphp/cqrs-bundle": "self.version", + "sonsofphp/filesystem": "self.version", + "sonsofphp/queue": "self.version" }, "autoload": { "psr-4": { @@ -79,10 +82,11 @@ "SonsOfPHP\\Component\\EventSourcing\\": "src/SonsOfPHP/Component/EventSourcing", "SonsOfPHP\\Bridge\\Doctrine\\EventSourcing\\": "src/SonsOfPHP/Bridge/Doctrine/EventSourcing", "SonsOfPHP\\Component\\FeatureToggle\\": "src/SonsOfPHP/Component/FeatureToggle", + "SonsOfPHP\\Component\\Filesystem\\": "src/SonsOfPHP/Component/Filesystem", "SonsOfPHP\\Component\\Json\\": "src/SonsOfPHP/Component/Json", "SonsOfPHP\\Component\\Money\\": "src/SonsOfPHP/Component/Money", - "SonsOfPHP\\Component\\Version\\": "src/SonsOfPHP/Component/Version", - "SonsOfPHP\\Component\\Filesystem\\": "src/SonsOfPHP/Component/Filesystem" + "SonsOfPHP\\Component\\Queue\\": "src/SonsOfPHP/Component/Queue", + "SonsOfPHP\\Component\\Version\\": "src/SonsOfPHP/Component/Version" }, "exclude-from-classmap": [ "src/SonsOfPHP/Bard/Tests", @@ -95,10 +99,11 @@ "src/SonsOfPHP/Component/EventSourcing/Tests", "src/SonsOfPHP/Bridge/Doctrine/EventSourcing/Tests", "src/SonsOfPHP/Component/FeatureToggle/Tests", + "src/SonsOfPHP/Component/Filesystem/Tests", "src/SonsOfPHP/Component/Json/Tests", "src/SonsOfPHP/Component/Money/Tests", - "src/SonsOfPHP/Component/Version/Tests", - "src/SonsOfPHP/Component/Filesystem/Tests" + "src/SonsOfPHP/Component/Queue/Tests", + "src/SonsOfPHP/Component/Version/Tests" ] }, "extra": { @@ -121,4 +126,4 @@ "SonsOfPHP\\Bridge\\Symfony\\Cqrs\\Tests\\": "src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests" } } -} +} \ No newline at end of file diff --git a/docs/components/queue/index.md b/docs/components/queue/index.md new file mode 100644 index 00000000..8206a96b --- /dev/null +++ b/docs/components/queue/index.md @@ -0,0 +1,14 @@ +--- +title: Queue +--- + +# Queue Component + +The queue component allows you low level access to send a variety of messages +into a queue such as Amazon SQS. + +## Installation + +```shell +composer require sonsofphp/queue +``` diff --git a/mkdocs.yml b/mkdocs.yml index eb2dac5d..e947245e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -93,6 +93,7 @@ nav: - Currency Providers: components/money/currency-providers.md - Operators: components/money/operators.md - Queries: components/money/queries.md + - Queue: components/queue/index.md - Version: components/version/index.md - Bard: - bard/index.md diff --git a/src/SonsOfPHP/Component/Queue/.gitattributes b/src/SonsOfPHP/Component/Queue/.gitattributes new file mode 100644 index 00000000..84c7add0 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/.gitattributes @@ -0,0 +1,4 @@ +/Tests export-ignore +/phpunit.xml.dist export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Component/Queue/.gitignore b/src/SonsOfPHP/Component/Queue/.gitignore new file mode 100644 index 00000000..5414c2c6 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/.gitignore @@ -0,0 +1,3 @@ +composer.lock +phpunit.xml +vendor/ diff --git a/src/SonsOfPHP/Component/Queue/Broker/Broker.php b/src/SonsOfPHP/Component/Queue/Broker/Broker.php new file mode 100644 index 00000000..7cc3a130 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/Broker/Broker.php @@ -0,0 +1,42 @@ + + */ +class Broker implements BrokerInterface +{ + private array $queues = []; + + public function __construct( + array $queues = [], + ) { + foreach ($queues as $queue) { + $this->add($queue); + } + } + + public function get(string $name): QueueInterface + { + if (!array_key_exists($queue->getName(), $this->queues)) { + throw new QueueException(); + } + + return $this->queues[$queue->getName()]; + } + + public function add(QueueInterface $queue): void + { + if (array_key_exists($queue->getName(), $this->queues)) { + throw new QueueException(); + } + + $this->queues[$queue->getName()] = $queue; + } +} diff --git a/src/SonsOfPHP/Component/Queue/Broker/BrokerInterface.php b/src/SonsOfPHP/Component/Queue/Broker/BrokerInterface.php new file mode 100644 index 00000000..e06822fa --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/Broker/BrokerInterface.php @@ -0,0 +1,20 @@ +add($queue); + * $broker->get('queue.name')->publish($message); + * + * @author Joshua Estes + */ +interface BrokerInterface +{ + public function get(string $name): QueueInterface; + + public function add(QueueInterface $queue): void; +} diff --git a/src/SonsOfPHP/Component/Queue/Exception/QueueException.php b/src/SonsOfPHP/Component/Queue/Exception/QueueException.php new file mode 100644 index 00000000..c3fc9a72 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/Exception/QueueException.php @@ -0,0 +1,10 @@ + + */ +class QueueException extends \Exception {} diff --git a/src/SonsOfPHP/Component/Queue/LICENSE b/src/SonsOfPHP/Component/Queue/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/LICENSE @@ -0,0 +1,19 @@ +Copyright 2022 to Present Joshua Estes + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/SonsOfPHP/Component/Queue/Message/MessageInterface.php b/src/SonsOfPHP/Component/Queue/Message/MessageInterface.php new file mode 100644 index 00000000..fb6b8639 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/Message/MessageInterface.php @@ -0,0 +1,12 @@ + + */ +interface MessageInterface extends \Serializable, \JsonSerializable +{ +} diff --git a/src/SonsOfPHP/Component/Queue/MessageQueue/QueueInterface.php b/src/SonsOfPHP/Component/Queue/MessageQueue/QueueInterface.php new file mode 100644 index 00000000..5df2c1c8 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/MessageQueue/QueueInterface.php @@ -0,0 +1,23 @@ + + */ +interface QueueInterface // or TransportInterface? +{ + public function getName(): string; + + public function publish(MessageInterface $message): void; + + public function receive(): iterable; + + public function delete(MessageInterface $message): void; + + public function purge(): void; +} diff --git a/src/SonsOfPHP/Component/Queue/README.md b/src/SonsOfPHP/Component/Queue/README.md new file mode 100644 index 00000000..c990b578 --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/README.md @@ -0,0 +1,18 @@ +Sons of PHP - Queue +=================== + +Library for working with multiple queues + +## Learn More + +* [Documentation][docs] +* [Contributing][contributing] +* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the [Mother Repository][mother-repo] +* Get Help & Support using [Discussions][discussions] + +[discussions]: https://github.com/orgs/SonsOfPHP/discussions +[mother-repo]: https://github.com/SonsOfPHP/sonsofphp +[contributing]: https://docs.sonsofphp.com/contributing/ +[docs]: https://docs.sonsofphp.com/components/queue/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AQueue +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AQueue diff --git a/src/SonsOfPHP/Component/Queue/composer.json b/src/SonsOfPHP/Component/Queue/composer.json new file mode 100644 index 00000000..d8a9cdef --- /dev/null +++ b/src/SonsOfPHP/Component/Queue/composer.json @@ -0,0 +1,54 @@ +{ + "name": "sonsofphp/queue", + "type": "library", + "description": "Library to send messages into multiple different message queues", + "keywords": [ + "message-queue", + "broker", + "file-queue", + "queue" + ], + "homepage": "https://github.com/SonsOfPHP/queue", + "license": "MIT", + "authors": [ + { + "name": "Joshua Estes", + "email": "joshua@sonsofphp.com" + } + ], + "support": { + "issues": "https://github.com/SonsOfPHP/sonsofphp/issues", + "forum": "https://github.com/orgs/SonsOfPHP/discussions", + "docs": "https://docs.sonsofphp.com", + "chat": "https://discord.gg/sdVxNhFqND" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Component\\Queue\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": ">=8.1" + }, + "extra": { + "sort-packages": true, + "branch-alias": { + "dev-main": "0.3.x-dev" + } + }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/JoshuaEstes" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" + } + ] +}