diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8fa1a3b0..244f95ee 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,35 +1,22 @@ -/.github @JoshuaEstes -/tools @JoshuaEstes -/docs @JoshuaEstes +* @sonsofphp/Members + +# Make Documentation Team +docs/ @sonsofphp/Members + +# Each project needs a Team /src/SonsOfPHP/Bard @JoshuaEstes -/src/SonsOfPHP/Bridge/Doctrine/EventSourcing @JoshuaEstes -/src/SonsOfPHP/Bridge/Doctrine/FeatureToggle @JoshuaEstes -/src/SonsOfPHP/Bridge/Doctrine/Money @JoshuaEstes -/src/SonsOfPHP/Bridge/Symfony/Cqrs @JoshuaEstes -/src/SonsOfPHP/Bridge/Symfony/EventSourcing @JoshuaEstes -/src/SonsOfPHP/Bridge/Symfony/Filesystem @JoshuaEstes -/src/SonsOfPHP/Bundle/Cqrs @JoshuaEstes -/src/SonsOfPHP/Bundle/FeatureToggle @JoshuaEstes -/src/SonsOfPHP/Bundle/Filesystem @JoshuaEstes -/src/SonsOfPHP/Component/Autoloader @JoshuaEstes -/src/SonsOfPHP/Component/Cache @JoshuaEstes -/src/SonsOfPHP/Component/Clock @JoshuaEstes -/src/SonsOfPHP/Component/Cqrs @JoshuaEstes -/src/SonsOfPHP/Component/Cvs @JoshuaEstes -/src/SonsOfPHP/Component/EventDispatcher @JoshuaEstes -/src/SonsOfPHP/Component/EventSourcing @JoshuaEstes -/src/SonsOfPHP/Component/FeatureToggle @JoshuaEstes -/src/SonsOfPHP/Component/Faker @JoshuaEstes -/src/SonsOfPHP/Component/Filesystem @JoshuaEstes -/src/SonsOfPHP/Component/HttpClient @JoshuaEstes -/src/SonsOfPHP/Component/HttpFactory @JoshuaEstes -/src/SonsOfPHP/Component/HttpHandler @JoshuaEstes -/src/SonsOfPHP/Component/HttpMessage @JoshuaEstes -/src/SonsOfPHP/Component/Json @JoshuaEstes -/src/SonsOfPHP/Component/Logger @JoshuaEstes -/src/SonsOfPHP/Component/Money @JoshuaEstes -/src/SonsOfPHP/Component/Pdf @JoshuaEstes -/src/SonsOfPHP/Component/PhoneNumber @JoshuaEstes -/src/SonsOfPHP/Component/Queue @JoshuaEstes -/src/SonsOfPHP/Component/Version @JoshuaEstes -/src/SonsOfPHP/Contract/Core @JoshuaEstes + +# Each project/component/contract needs a Team +/src/SonsOfPHP/**/Cache @JoshuaEstes +/src/SonsOfPHP/**/Clock @JoshuaEstes +/src/SonsOfPHP/**/Common @JoshuaEstes +/src/SonsOfPHP/**/Cqrs @JoshuaEstes +/src/SonsOfPHP/**/EventDispatcher @JoshuaEstes +/src/SonsOfPHP/**/EventSourcing @JoshuaEstes +/src/SonsOfPHP/**/FeatureToggle @JoshuaEstes +/src/SonsOfPHP/**/Filesystem @JoshuaEstes +/src/SonsOfPHP/**/HttpFactory @JoshuaEstes +/src/SonsOfPHP/**/HttpMessage @JoshuaEstes +/src/SonsOfPHP/**/HttpJson @JoshuaEstes +/src/SonsOfPHP/**/Money @JoshuaEstes +/src/SonsOfPHP/**/Version @JoshuaEstes diff --git a/.github/labeler.yml b/.github/labeler.yml index 19f9df10..9e514c2d 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -8,7 +8,11 @@ Cache: Clock: - docs/components/clock/* - - src/SonsOfPHP/Component/Clock/* + - src/SonsOfPHP/**/Clock/* + +Common: + - docs/components/common/* + - src/SonsOfPHP/**/Common/* CQRS: - docs/components/cqrs/* diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 5030033b..6b1a5e68 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,13 +1,8 @@ ## Description - -## Checklist - -- [ ] Updated the correct CHANGELOG file -- [ ] Updated documentation +## Checklist +- [ ] Updated CHANGELOG files +- [ ] Updated Documentation +- [ ] Unit Tests Created diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index ed83daeb..864c0678 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -37,10 +37,10 @@ jobs: key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} restore-keys: | ${{ runner.os }}-php- - - run: make install - - run: php tools/phpunit/vendor/bin/phpunit --coverage-clover coverage.xml + - run: make install phpunit env: XDEBUG_MODE: coverage + PHPUNIT_OPTIONS: --coverage-clover coverage.xml - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v3 env: diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 5adc73c1..4b24932c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -16,5 +16,6 @@ // Rules 'no_unused_imports' => true, + 'ordered_imports' => true, 'php_unit_test_class_requires_covers' => true, ])->setFinder($finder); diff --git a/Makefile b/Makefile index fc89c623..7ec3c69b 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,10 @@ BARD = src/SonsOfPHP/Bard/bin/bard COVERAGE_DIR = docs/coverage +XDEBUG_MODE ?= off +PHPUNIT_TESTSUITE ?= all +PHPUNIT_OPTIONS ?= + .DEFAULT_GOAL = help .PHONY = help @@ -39,16 +43,27 @@ purge: # Purge vendor and lock files rm -rf vendor/ src/SonsOfPHP/Component/*/vendor/ src/SonsOfPHP/Component/*/composer.lock rm -rf vendor/ src/SonsOfPHP/Contract/*/vendor/ src/SonsOfPHP/Contract/*/composer.lock -test: ## Run PHPUnit Tests - XDEBUG_MODE=off \ +test: phpunit ## Run PHPUnit Tests + +test-cache: PHPUNIT_TESTSUITE=cache +test-cache: phpunit + +test-clock: PHPUNIT_TESTSUITE=clock +test-clock: phpunit + +test-cqrs: PHPUNIT_TESTSUITE=cqrs +test-cqrs: phpunit + +phpunit: + XDEBUG_MODE=$(XDEBUG_MODE) \ $(PHP) \ - -dxdebug.mode=off \ + -dxdebug.mode=$(XDEBUG_MODE) \ -dapc.enable_cli=1 \ $(PHPUNIT) \ --cache-result \ - --order-by=defects - -phpunit: test + --order-by=defects \ + --testsuite=$(PHPUNIT_TESTSUITE) \ + $(PHPUNIT_OPTIONS) phpunit-install: XDEBUG_MODE=off $(COMPOSER) install --working-dir=tools/phpunit --no-interaction --prefer-dist --optimize-autoloader @@ -61,23 +76,18 @@ lint: lint-php ## Lint files lint-php: # lint php files find src -name "*.php" -not -path "src/**/vendor/*" | xargs -I{} $(PHP) -l '{}' -coverage: ## Build Code Coverage Report - XDEBUG_MODE=coverage \ - $(PHP) \ - -dxdebug.mode=coverage \ - -dapc.enable_cli=1 \ - $(PHPUNIT) \ - --cache-result \ - --coverage-html $(COVERAGE_DIR) +coverage: XDEBUG_MODE=coverage +coverage: PHPUNIT_OPTIONS=--coverage-html $(COVERAGE_DIR) +coverage: phpunit ## Build Code Coverage Report -coverage-cache: - XDEBUG_MODE=coverage $(PHP) -dxdebug.mode=coverage $(PHPUNIT) --testsuite cache --coverage-html $(COVERAGE_DIR) +coverage-cache: PHPUNIT_TESTSUITE=cache +coverage-cache: coverage -coverage-clock: - XDEBUG_MODE=coverage $(PHP) -dxdebug.mode=coverage $(PHPUNIT) --testsuite clock --coverage-html $(COVERAGE_DIR) +coverage-clock: PHPUNIT_TESTSUITE=clock +coverage-clock: coverage -coverage-cqrs: - XDEBUG_MODE=coverage $(PHP) -dxdebug.mode=coverage $(PHPUNIT) --testsuite cqrs --coverage-html $(COVERAGE_DIR) +coverage-cqrs: PHPUNIT_TESTSUITE=cqrs +coverage-cqrs: coverage coverage-event-dispatcher: XDEBUG_MODE=coverage $(PHP) -dxdebug.mode=coverage $(PHPUNIT) --testsuite event-dispatcher --coverage-html $(COVERAGE_DIR) diff --git a/bard.json b/bard.json index cddcb915..1b2131d0 100644 --- a/bard.json +++ b/bard.json @@ -71,8 +71,32 @@ "repository": "git@github.com:SonsOfPHP/version.git" }, { - "path": "src/SonsOfPHP/Contract/Core", - "repository": "git@github.com:SonsOfPHP/core-contract.git" + "path": "src/SonsOfPHP/Contract/Common", + "repository": "git@github.com:SonsOfPHP/common-contract.git" + }, + { + "path": "src/SonsOfPHP/Contract/Cqrs", + "repository": "git@github.com:SonsOfPHP/cqrs-contract.git" + }, + { + "path": "src/SonsOfPHP/Contract/EventSourcing", + "repository": "git@github.com:SonsOfPHP/event-sourcing-contract.git" + }, + { + "path": "src/SonsOfPHP/Contract/FeatureToggle", + "repository": "git@github.com:SonsOfPHP/feature-toggle-contract.git" + }, + { + "path": "src/SonsOfPHP/Contract/Filesystem", + "repository": "git@github.com:SonsOfPHP/filesystem-contract.git" + }, + { + "path": "src/SonsOfPHP/Contract/Money", + "repository": "git@github.com:SonsOfPHP/money-contract.git" + }, + { + "path": "src/SonsOfPHP/Contract/Version", + "repository": "git@github.com:SonsOfPHP/version-contract.git" } ] } diff --git a/composer.json b/composer.json index 482f7dec..f32a4830 100644 --- a/composer.json +++ b/composer.json @@ -34,30 +34,36 @@ "provide": { "psr/event-dispatcher-implementation": "1.0", "psr/clock-implementation": "1.0", - "psr/http-message-implementation": "^1.0|^2.0", + "psr/http-message-implementation": "^1.0 || ^2.0", "psr/http-factory-implementation": "^1.0", - "psr/cache-implementation": "^2.0|^3.0", - "psr/simple-cache-implementation": "^1.0|^2.0|^3.0" + "psr/cache-implementation": "^2.0 || ^3.0", + "psr/simple-cache-implementation": "^1.0 || ^2.0 || ^3.0", + "sonsofphp/cqrs-implementation": "0.3.x-dev", + "sonsofphp/event-sourcing-implementation": "0.3.x-dev", + "sonsofphp/feature-toggle-implementation": "0.3.x-dev", + "sonsofphp/filesystem-implementation": "0.3.x-dev", + "sonsofphp/money-implementation": "0.3.x-dev", + "sonsofphp/version-implementation": "0.3.x-dev" }, "require": { "php": ">=8.1", "ext-json": "*", "psr/event-dispatcher": "^1.0", "doctrine/dbal": "^3", - "symfony/options-resolver": "^5|^6", - "symfony/uid": "^5|^6", - "symfony/console": "^4|^5|^6", - "symfony/dotenv": "^5|^6", - "symfony/finder": "^5|^6", - "symfony/process": "^5|^6", - "symfony/dependency-injection": "^5|^6", - "symfony/http-kernel": "^5|^6", + "symfony/options-resolver": "^5 || ^6", + "symfony/uid": "^5 || ^6", + "symfony/console": "^4 || ^5 || ^6", + "symfony/dotenv": "^5 || ^6", + "symfony/finder": "^5 || ^6", + "symfony/process": "^5 || ^6", + "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", - "psr/http-message": "^1.0|^2.0", + "psr/http-message": "^1.0 || ^2.0", "psr/http-factory": "^1.0", - "psr/cache": "^2.0|^3.0", + "psr/cache": "^2.0 || ^3.0", "psr/simple-cache": "^3.0" }, "replace": { @@ -78,7 +84,14 @@ "sonsofphp/http-message": "self.version", "sonsofphp/http-factory": "self.version", "sonsofphp/core-contract": "self.version", - "sonsofphp/cache": "self.version" + "sonsofphp/cache": "self.version", + "sonsofphp/cqrs-contract": "self.version", + "sonsofphp/event-sourcing-contract": "self.version", + "sonsofphp/feature-toggle-contract": "self.version", + "sonsofphp/filesystem-contract": "self.version", + "sonsofphp/money-contract": "self.version", + "sonsofphp/version-contract": "self.version", + "sonsofphp/common-contract": "self.version" }, "autoload": { "psr-4": { @@ -99,7 +112,13 @@ "SonsOfPHP\\Component\\Json\\": "src/SonsOfPHP/Component/Json", "SonsOfPHP\\Component\\Money\\": "src/SonsOfPHP/Component/Money", "SonsOfPHP\\Component\\Version\\": "src/SonsOfPHP/Component/Version", - "SonsOfPHP\\Contract\\Core\\": "src/SonsOfPHP/Contract/Core" + "SonsOfPHP\\Contract\\Common\\": "src/SonsOfPHP/Contract/Common", + "SonsOfPHP\\Contract\\Cqrs\\": "src/SonsOfPHP/Contract/Cqrs", + "SonsOfPHP\\Contract\\EventSourcing\\": "src/SonsOfPHP/Contract/EventSourcing", + "SonsOfPHP\\Contract\\FeatureToggle\\": "src/SonsOfPHP/Contract/FeatureToggle", + "SonsOfPHP\\Contract\\Filesystem\\": "src/SonsOfPHP/Contract/Filesystem", + "SonsOfPHP\\Contract\\Money\\": "src/SonsOfPHP/Contract/Money", + "SonsOfPHP\\Contract\\Version\\": "src/SonsOfPHP/Contract/Version" }, "exclude-from-classmap": [ "src/SonsOfPHP/Bard/Tests", @@ -118,8 +137,7 @@ "src/SonsOfPHP/Component/HttpMessage/Tests", "src/SonsOfPHP/Component/Json/Tests", "src/SonsOfPHP/Component/Money/Tests", - "src/SonsOfPHP/Component/Version/Tests", - "src/SonsOfPHP/Contract/Core/Tests" + "src/SonsOfPHP/Component/Version/Tests" ] }, "extra": { @@ -129,13 +147,13 @@ } }, "require-dev": { - "symfony/http-foundation": "^5|^6", - "symfony/serializer": "^5|^6", + "symfony/http-foundation": "^5 || ^6", + "symfony/serializer": "^5 || ^6", "symfony/phpunit-bridge": "^6", "symfony/error-handler": "^6", - "symfony/messenger": "^5|^6", + "symfony/messenger": "^5 || ^6", "phpunit/phpunit": "^10.4", - "psr/simple-cache": "^1.0|^2.0|^3.0" + "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" }, "autoload-dev": { "psr-4": { diff --git a/docs/components/cqrs/command-handlers.md b/docs/components/cqrs/command-handlers.md deleted file mode 100644 index 445bca84..00000000 --- a/docs/components/cqrs/command-handlers.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: Command Handlers ---- - -# Command Handlers - -Once you create a Command, you need to create a Command Handler to handle that -command. Command Handlers do NOT return any results. - -```php -dispatch($command); - -// If you need to apply one or more stamps, this must be done -// before the command is dispatched. -$commandBus - ->withStamps([$stamp]) - ->dispatch($command); -``` diff --git a/docs/components/cqrs/commands.md b/docs/components/cqrs/commands.md deleted file mode 100644 index e5a9a0f9..00000000 --- a/docs/components/cqrs/commands.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Commands ---- - -# Commands - -All Commands must implement the [`CommandMessageInterface`][CommandMessageInterface]. - -## Basic Command - -Simple Commands can be created quickly and easily. - -```php -userId = $userId; - } -} -``` - -## Options Resolver Command - -!!! attention - The `AbstractOptionsResolverCommand` reqires the `sonsofphp/cqrs-symfony` - package. - -The Options Resolver Command allows you to create more complex commands. For -example. - -```php -define('user_id') - ->required() - ->allowedTypes('int') - ->allowedValues(function ($value) { - return $value > 0; - }); - - } -} -``` - -To use the command, you just create a new instance of the command. - -```php - 1234]); - -// ... - -// Get an option -$userId = $command->getOption('user_id'); - -// Get ALL options -$options = $command->getOptions(): - -// Check if option exists -$command->hasOption('user_id'); -``` - -[CommandMessageInterface]: https://github.com/SonsOfPHP/sonsofphp/blob/main/packages/cqrs/Command/CommandMessageInterface.php diff --git a/docs/components/cqrs/index.md b/docs/components/cqrs/index.md index a5063479..80a93123 100644 --- a/docs/components/cqrs/index.md +++ b/docs/components/cqrs/index.md @@ -1,5 +1,5 @@ --- -title: CQRS +title: Cqrs Component --- Command Query Responsibility Segregation is a simple concept. When you want @@ -10,28 +10,158 @@ An over simplified example of this would be if you need to write to a database, you would use a Command. If you need results from a database, you would use a Query. -# Installation +## Installation ```shell composer require sonsofphp/cqrs ``` -!!! success "Symfony Bridge" - Installing the Symfony Bridge will add additional functionality to the CQRS - component. This can be done quickly and easily. The documentation will point - out where this is required. +## Basic Usage - ```shell - composer require sonsofphp/cqrs-symfony - ``` +### Command Bus -!!! tip - This component pairs well with the `sonsofphp/event-sourcing` component. +```php +addHandler(CreateUser::class, $handler); -[messenger]: https://symfony.com/doc/current/components/messenger.html -[options_resolver]: https://symfony.com/doc/current/components/options_resolver.html +$command = new CreateUser(); +$commandBus->dispatch($command); +``` + +!!! success "Symfony CQRS Bridge" + Once the CQRS Symfony Bridge is installed, you can use the Command Bus that + comes with that to gain access to additional features and functionality. + +### Query Bus + +```php +addHandler(GetUser::class, $handler); + +$query = (new GetUser())->with('id', 123); +$user = $queryBus->handle($query); + +!!! success "Symfony CQRS Bridge" + Once the CQRS Symfony Bridge is installed, you can use the Query Bus that + comes with that to gain addition features and functionality. +``` + +## Messages + +Both Commands and Queries are considered to be messages. It is HIGHLY +recommended to use the `AbstractMessage` class for both Commands and Queries. +For all examples I will assume you have extended this class. + +```php +with('id', 123); +$command = $command->with('email', 'joshua@sonsofphp.com'); + +$userId = $command->get('id'); // $userId = 123 +``` + +```php +with('id', 123); + +$userId = $query->get('id'); // $userId = 123 +``` + +!!! note + `AbstractMessage` treats the message as a value object. So using `with` will + return a new instance of the class. + +### Additional `AbstractMessage` API + +```php +with([ + 'key' => 'value', + 'another' => 'value', + // ... +]); + +// Getting all the paramters of the message +$parameters = $message->get(); + +// Get a single paramter value +// WARNING: If the parameter is not found, an exception will be thrown +$userId = $message->get('user.id'); +``` + +## Message Handlers + +Both Command and Query Handers are assumed to just be message handlers. + +### Command Handlers + +```php +handle($query); -``` diff --git a/docs/contracts/common/index.md b/docs/contracts/common/index.md new file mode 100644 index 00000000..cc1e0a7d --- /dev/null +++ b/docs/contracts/common/index.md @@ -0,0 +1,21 @@ +--- +title: Common Contracts - Overview +--- + +# Common Contracts + +Common Contracts are generic contracts that are not specific to any one package or +project. + +## Installation + +```shell +composer require sonsofphp/common-contract +``` + +## Includes Interfaces + +* ArrayableInterface +* ComparableInterface +* EquatableInterface +* JsonableInterface diff --git a/docs/contracts/core/index.md b/docs/contracts/core/index.md deleted file mode 100644 index fabe74f4..00000000 --- a/docs/contracts/core/index.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: Core Contracts - Overview ---- - -# Core Contracts - -Core Contracts are generic contracts that are not specific to any one package or -project. - -## Installation - -```shell -composer require sonsofphp/core-contract -``` - -## Includes Interfaces - -* ComparableInterface -* EquatableInterface diff --git a/docs/contracts/cqrs/index.md b/docs/contracts/cqrs/index.md new file mode 100644 index 00000000..8ae01810 --- /dev/null +++ b/docs/contracts/cqrs/index.md @@ -0,0 +1,33 @@ +--- +title: Cqrs Contract +--- + +In a nut shell, with CQRS you have Commands that will change the state of your +application and Queries that will return information about the state of your +application. + +## Installation + +```shell +composer require sonsofphp/cqrs-contract +``` + +## Messages + +Both Commands and Queries are considered Messages and are handled by Message +Handlers. + +## Message Handlers + +When a message is dispatched/handled, it is handled by a message handler. + +## Message Bus + +The Message Bus is given a Message and will use a Message Handler to handle the +message. If it's a Query Message, the bus will return a result and for Command +Messages, it will not return anything. + +## Message Handler Provider + +Returns the Handler that will handle the Message. They do not actually handle or +process the message. diff --git a/mkdocs.yml b/mkdocs.yml index 2aebec9f..34ffbf2e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,4 +1,4 @@ -site_name: Sons of PHP - Documentation +site_name: Sons of PHP site_url: https://docs.sonsofphp.com/ site_author: Joshua Estes site_description: Sons of PHP creates and maintains helpful packages for PHP. @@ -81,10 +81,6 @@ nav: - Clock: components/clock/index.md - CQRS: - components/cqrs/index.md - - Commands: components/cqrs/commands.md - - Command Handlers: components/cqrs/command-handlers.md - - Queries: components/cqrs/queries.md - - Query Handlers: components/cqrs/query-handlers.md - Event Dispatcher: components/event-dispatcher/index.md - Event Sourcing: - components/event-sourcing/index.md @@ -118,4 +114,5 @@ nav: - Version: components/version/index.md - Contracts: - contracts/index.md - - Core: contracts/core/index.md + - Common: contracts/common/index.md + - Cqrs: contracts/cqrs/index.md diff --git a/src/SonsOfPHP/Bard/composer.json b/src/SonsOfPHP/Bard/composer.json index cc2c2a3a..f1d905b6 100644 --- a/src/SonsOfPHP/Bard/composer.json +++ b/src/SonsOfPHP/Bard/composer.json @@ -16,10 +16,10 @@ "sonsofphp/event-dispatcher": "^0.3.x-dev", "sonsofphp/json": "^0.3.x-dev", "sonsofphp/version": "^0.3.x-dev", - "symfony/console": "^4|^5|^6", - "symfony/dotenv": "^5|^6", - "symfony/finder": "^5|^6", - "symfony/process": "^5|^6" + "symfony/console": "^4 || ^5 || ^6", + "symfony/dotenv": "^5 || ^6", + "symfony/finder": "^5 || ^6", + "symfony/process": "^5 || ^6" }, "license": "MIT", "autoload": { diff --git a/src/SonsOfPHP/Bridge/Symfony/Cqrs/Command/AbstractOptionsResolverCommandMessage.php b/src/SonsOfPHP/Bridge/Symfony/Cqrs/Command/AbstractOptionsResolverCommandMessage.php index 80e0ce16..cb0a40bd 100644 --- a/src/SonsOfPHP/Bridge/Symfony/Cqrs/Command/AbstractOptionsResolverCommandMessage.php +++ b/src/SonsOfPHP/Bridge/Symfony/Cqrs/Command/AbstractOptionsResolverCommandMessage.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Bridge\Symfony\Cqrs\Command; -use SonsOfPHP\Component\Cqrs\Command\CommandMessageInterface; +use SonsOfPHP\Component\Cqrs\AbstractCommandMessage; +use SonsOfPHP\Contract\Cqrs\CommandMessageInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -20,7 +21,7 @@ * * @author Joshua Estes */ -abstract class AbstractOptionsResolverCommandMessage implements CommandMessageInterface +abstract class AbstractOptionsResolverCommandMessage extends AbstractCommandMessage implements CommandMessageInterface { private array $options = []; diff --git a/src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests/Command/AbstractOptionsResolverCommandMessageTest.php b/src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests/Command/AbstractOptionsResolverCommandMessageTest.php index bf2178e8..b78eb38d 100644 --- a/src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests/Command/AbstractOptionsResolverCommandMessageTest.php +++ b/src/SonsOfPHP/Bridge/Symfony/Cqrs/Tests/Command/AbstractOptionsResolverCommandMessageTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Bridge\Symfony\Cqrs\Command\AbstractOptionsResolverCommandMessage; use SonsOfPHP\Bridge\Symfony\Cqrs\Tests\DummyCommand; -use SonsOfPHP\Component\Cqrs\Command\CommandMessageInterface; +use SonsOfPHP\Contract\Cqrs\CommandMessageInterface; /** * @coversDefaultClass \SonsOfPHP\Bridge\Symfony\Cqrs\Command\AbstractOptionsResolverCommandMessage diff --git a/src/SonsOfPHP/Bridge/Symfony/Cqrs/composer.json b/src/SonsOfPHP/Bridge/Symfony/Cqrs/composer.json index bbd0db81..4e1d571f 100644 --- a/src/SonsOfPHP/Bridge/Symfony/Cqrs/composer.json +++ b/src/SonsOfPHP/Bridge/Symfony/Cqrs/composer.json @@ -39,10 +39,10 @@ "require": { "php": ">=8.1", "sonsofphp/cqrs": "^0.3.x-dev", - "symfony/options-resolver": "^5|^6" + "symfony/options-resolver": "^5 || ^6" }, "require-dev": { - "symfony/messenger": "^5|^6" + "symfony/messenger": "^5 || ^6" }, "extra": { "sort-packages": true, @@ -63,4 +63,4 @@ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" } ] -} +} \ No newline at end of file diff --git a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UlidEventIdMessageEnricherHandlerTest.php b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UlidEventIdMessageEnricherHandlerTest.php index 07cf8c84..2ddc7905 100644 --- a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UlidEventIdMessageEnricherHandlerTest.php +++ b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UlidEventIdMessageEnricherHandlerTest.php @@ -38,7 +38,7 @@ public function testItWillGenerateUlid(): void $message = $this->createMock(MessageInterface::class); $message->expects($this->once()) ->method('withMetadata') - ->with($this->callback(fn ($metadata) => Ulid::isValid($metadata[Metadata::EVENT_ID]))) + ->with($this->callback(fn($metadata) => Ulid::isValid($metadata[Metadata::EVENT_ID]))) ; $handler->enrich($message); diff --git a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UuidEventIdMessageEnricherHandlerTest.php b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UuidEventIdMessageEnricherHandlerTest.php index 13fd82c3..7cf2678a 100644 --- a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UuidEventIdMessageEnricherHandlerTest.php +++ b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/Tests/Message/Enricher/Handler/UuidEventIdMessageEnricherHandlerTest.php @@ -38,7 +38,7 @@ public function testItWillGenerateUuid(): void $message = $this->createMock(MessageInterface::class); $message->expects($this->once()) ->method('withMetadata') - ->with($this->callback(fn ($metadata) => Uuid::isValid($metadata[Metadata::EVENT_ID]))) + ->with($this->callback(fn($metadata) => Uuid::isValid($metadata[Metadata::EVENT_ID]))) ; $handler->enrich($message); diff --git a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/composer.json b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/composer.json index 7a301dff..df70e14d 100644 --- a/src/SonsOfPHP/Bridge/Symfony/EventSourcing/composer.json +++ b/src/SonsOfPHP/Bridge/Symfony/EventSourcing/composer.json @@ -31,13 +31,13 @@ "require": { "php": ">=8.1", "sonsofphp/event-sourcing": "^0.3.x-dev", - "symfony/uid": "^5|^6", + "symfony/uid": "^5 || ^6", "symfony/security-bundle": "^6" }, "require-dev": { - "symfony/http-foundation": "^5|^6", - "symfony/messenger": "^5|^6", - "symfony/serializer": "^5|^6" + "symfony/http-foundation": "^5 || ^6", + "symfony/messenger": "^5 || ^6", + "symfony/serializer": "^5 || ^6" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Bundle/Cqrs/composer.json b/src/SonsOfPHP/Bundle/Cqrs/composer.json index 573f10a6..a8724774 100644 --- a/src/SonsOfPHP/Bundle/Cqrs/composer.json +++ b/src/SonsOfPHP/Bundle/Cqrs/composer.json @@ -39,9 +39,9 @@ "require": { "php": ">=8.1", "sonsofphp/cqrs": "^0.3.x-dev", - "symfony/dependency-injection": "^5|^6", - "symfony/http-kernel": "^5|^6", - "symfony/messenger": "^5|^6" + "symfony/dependency-injection": "^5 || ^6", + "symfony/http-kernel": "^5 || ^6", + "symfony/messenger": "^5 || ^6" }, "suggest": { "sonsofphp/event-sourcing": "Get some of that sweet ass event sourcing action" diff --git a/src/SonsOfPHP/Component/Cache/Adapter/ApcuAdapter.php b/src/SonsOfPHP/Component/Cache/Adapter/ApcuAdapter.php index bc872955..e38b4800 100644 --- a/src/SonsOfPHP/Component/Cache/Adapter/ApcuAdapter.php +++ b/src/SonsOfPHP/Component/Cache/Adapter/ApcuAdapter.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\Cache\Adapter; -use SonsOfPHP\Component\Cache\CacheItem; use Psr\Cache\CacheItemInterface; +use SonsOfPHP\Component\Cache\CacheItem; use SonsOfPHP\Component\Cache\Exception\CacheException; /** diff --git a/src/SonsOfPHP/Component/Cache/Adapter/ChainAdapter.php b/src/SonsOfPHP/Component/Cache/Adapter/ChainAdapter.php index 63b1a3f8..fb36dae2 100644 --- a/src/SonsOfPHP/Component/Cache/Adapter/ChainAdapter.php +++ b/src/SonsOfPHP/Component/Cache/Adapter/ChainAdapter.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\Cache\Adapter; -use SonsOfPHP\Component\Cache\CacheItem; use Psr\Cache\CacheItemInterface; +use SonsOfPHP\Component\Cache\CacheItem; use SonsOfPHP\Component\Cache\Exception\CacheException; /** diff --git a/src/SonsOfPHP/Component/Cache/Adapter/NullAdapter.php b/src/SonsOfPHP/Component/Cache/Adapter/NullAdapter.php index 926b507d..c0a50e0b 100644 --- a/src/SonsOfPHP/Component/Cache/Adapter/NullAdapter.php +++ b/src/SonsOfPHP/Component/Cache/Adapter/NullAdapter.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\Cache\Adapter; -use SonsOfPHP\Component\Cache\CacheItem; use Psr\Cache\CacheItemInterface; +use SonsOfPHP\Component\Cache\CacheItem; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Cache/SimpleCache.php b/src/SonsOfPHP/Component/Cache/SimpleCache.php index c30f3d1d..0452031d 100644 --- a/src/SonsOfPHP/Component/Cache/SimpleCache.php +++ b/src/SonsOfPHP/Component/Cache/SimpleCache.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\Cache; -use Psr\SimpleCache\CacheInterface; use Psr\Cache\CacheItemPoolInterface; +use Psr\SimpleCache\CacheInterface; /** * PSR-16 Simple Cache diff --git a/src/SonsOfPHP/Component/Cache/Tests/Adapter/ApcuAdapterTest.php b/src/SonsOfPHP/Component/Cache/Tests/Adapter/ApcuAdapterTest.php index 2b47512d..4d1e6560 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/Adapter/ApcuAdapterTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/Adapter/ApcuAdapterTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\Cache\Tests\Adapter; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Cache\Adapter\ApcuAdapter; -use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; -use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemInterface; +use Psr\Cache\CacheItemPoolInterface; +use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; +use SonsOfPHP\Component\Cache\Adapter\ApcuAdapter; /** * @requires extension apcu diff --git a/src/SonsOfPHP/Component/Cache/Tests/Adapter/ArrayAdapterTest.php b/src/SonsOfPHP/Component/Cache/Tests/Adapter/ArrayAdapterTest.php index 49c9d73b..ebd61dbf 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/Adapter/ArrayAdapterTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/Adapter/ArrayAdapterTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\Cache\Tests\Adapter; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Cache\Adapter\ArrayAdapter; -use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; -use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemInterface; +use Psr\Cache\CacheItemPoolInterface; +use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; +use SonsOfPHP\Component\Cache\Adapter\ArrayAdapter; /** * @coversDefaultClass \SonsOfPHP\Component\Cache\Adapter\ArrayAdapter diff --git a/src/SonsOfPHP/Component/Cache/Tests/Adapter/ChainAdapterTest.php b/src/SonsOfPHP/Component/Cache/Tests/Adapter/ChainAdapterTest.php index e60d2537..bea92ee9 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/Adapter/ChainAdapterTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/Adapter/ChainAdapterTest.php @@ -5,11 +5,11 @@ namespace SonsOfPHP\Component\Cache\Tests\Adapter; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Cache\Adapter\ChainAdapter; -use SonsOfPHP\Component\Cache\Adapter\ArrayAdapter; -use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; -use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemInterface; +use Psr\Cache\CacheItemPoolInterface; +use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; +use SonsOfPHP\Component\Cache\Adapter\ArrayAdapter; +use SonsOfPHP\Component\Cache\Adapter\ChainAdapter; use SonsOfPHP\Component\Cache\Exception\CacheException; /** diff --git a/src/SonsOfPHP/Component/Cache/Tests/Adapter/NullAdapterTest.php b/src/SonsOfPHP/Component/Cache/Tests/Adapter/NullAdapterTest.php index 421c9cf9..5e7a54e0 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/Adapter/NullAdapterTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/Adapter/NullAdapterTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\Cache\Tests\Adapter; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Cache\Adapter\NullAdapter; -use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; -use Psr\Cache\CacheItemPoolInterface; use Psr\Cache\CacheItemInterface; +use Psr\Cache\CacheItemPoolInterface; +use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; +use SonsOfPHP\Component\Cache\Adapter\NullAdapter; /** * @coversDefaultClass \SonsOfPHP\Component\Cache\Adapter\NullAdapter diff --git a/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php b/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php index 25bb979a..7f719e67 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/CacheItemTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\Cache\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Cache\CacheItem; use Psr\Cache\CacheItemInterface; +use SonsOfPHP\Component\Cache\CacheItem; use SonsOfPHP\Component\Cache\Exception\InvalidArgumentException; /** diff --git a/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php b/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php index 7d7880ae..dfa828f6 100644 --- a/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php +++ b/src/SonsOfPHP/Component/Cache/Tests/SimpleCacheTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\Cache\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Cache\SimpleCache; +use Psr\Cache\CacheItemInterface; use Psr\SimpleCache\CacheInterface; use SonsOfPHP\Component\Cache\Adapter\AdapterInterface; -use Psr\Cache\CacheItemInterface; +use SonsOfPHP\Component\Cache\SimpleCache; /** * @coversDefaultClass \SonsOfPHP\Component\Cache\SimpleCache diff --git a/src/SonsOfPHP/Component/Cache/composer.json b/src/SonsOfPHP/Component/Cache/composer.json index dd1bbc8e..5126f2e8 100644 --- a/src/SonsOfPHP/Component/Cache/composer.json +++ b/src/SonsOfPHP/Component/Cache/composer.json @@ -33,17 +33,17 @@ "prefer-stable": true, "require": { "php": ">=8.1", - "psr/cache": "^2.0|^3.0" + "psr/cache": "^2.0 || ^3.0" }, "require-dev": { - "psr/simple-cache": "^1.0|^2.0|^3.0" + "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" }, "suggest": { "sonsofphp/filesystem": "Stores cache files using virtual filesystem" }, "provide": { - "psr/cache-implementation": "^2.0|^3.0", - "psr/simple-cache-implementation": "^1.0|^2.0|^3.0" + "psr/cache-implementation": "^2.0 || ^3.0", + "psr/simple-cache-implementation": "^1.0 || ^2.0 || ^3.0" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Component/Clock/FixedClock.php b/src/SonsOfPHP/Component/Clock/FixedClock.php index b68d20c9..409831df 100644 --- a/src/SonsOfPHP/Component/Clock/FixedClock.php +++ b/src/SonsOfPHP/Component/Clock/FixedClock.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\Clock; -use SonsOfPHP\Component\Clock\Exception\ClockException; use Psr\Clock\ClockInterface; +use SonsOfPHP\Component\Clock\Exception\ClockException; /** * Fixed Clock. diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractBus.php b/src/SonsOfPHP/Component/Cqrs/AbstractBus.php new file mode 100644 index 00000000..908fedec --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/AbstractBus.php @@ -0,0 +1,22 @@ + + */ +abstract class AbstractBus +{ + public function __construct( + protected MessageHandlerProviderInterface $provider = new MessageHandlerProvider(), + ) {} + + public function addHandler(object|string $message, callable $handler): void + { + $this->provider->add($message, $handler); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessage.php b/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessage.php new file mode 100644 index 00000000..d8930a7e --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessage.php @@ -0,0 +1,12 @@ + + */ +abstract class AbstractCommandMessage extends AbstractMessage implements CommandMessageInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php b/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php new file mode 100644 index 00000000..28c73466 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/AbstractCommandMessageHandler.php @@ -0,0 +1,13 @@ + + */ +abstract class AbstractCommandMessageHandler implements CommandMessageHandlerInterface +{ + abstract public function __invoke(CommandMessageInterface $message): void; +} diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php b/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php new file mode 100644 index 00000000..06de1337 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/AbstractMessage.php @@ -0,0 +1,103 @@ + + */ +abstract class AbstractMessage implements MessageInterface, \JsonSerializable, \Serializable, \IteratorAggregate +{ + private array $payload = []; + + public function with(string|array $key, mixed $value = null): static + { + if (is_object($value) && !$value instanceof \Stringable) { + throw new \InvalidArgumentException('$value is invalid'); + } + + if (is_array($key) && null !== $value) { + throw new \InvalidArgumentException('$key is invalid, you cannot pass in $value when $key is an array'); + } + + if ($value instanceof \Stringable) { + $value = (string) $value; + } + + if (is_array($key)) { + $that = clone $this; + foreach ($key as $k => $v) { + if (is_object($v) && !$v instanceof \Stringable) { + throw new \InvalidArgumentException('The array contains invalid values'); + } + + if ($v instanceof \Stringable) { + $v = (string) $v; + } + + $that->payload[$k] = $v; + } + + return $that; + } + + if (array_key_exists($key, $this->payload) && $value === $this->payload[$key]) { + return $this; + } + + $that = clone $this; + $that->payload[$key] = $value; + + return $that; + } + + public function get(?string $key = null): mixed + { + if (null === $key) { + return $this->payload; + } + + if (!array_key_exists($key, $this->payload)) { + throw new \Exception(sprintf('The key "%s" does not exist.', $key)); + } + + return $this->payload[$key]; + } + + public function serialize(): ?string + { + if (false === $json = json_encode($this)) { + throw new \RuntimeException('Unable to serialize object'); + } + + return $json; + } + + public function unserialize(string $data): void + { + $this->payload = json_decode($data, true); + } + + public function __serialize(): array + { + return $this->payload; + } + + public function __unserialize(array $data): void + { + $this->payload = $data; + } + + public function jsonSerialize(): array + { + return $this->payload; + } + + public function getIterator(): \Traversable + { + return new \ArrayIterator($this->payload); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessage.php b/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessage.php new file mode 100644 index 00000000..f3f48eee --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessage.php @@ -0,0 +1,12 @@ + + */ +abstract class AbstractQueryMessage extends AbstractMessage implements QueryMessageInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php b/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php new file mode 100644 index 00000000..e4b76bf6 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/AbstractQueryMessageHandler.php @@ -0,0 +1,13 @@ + + */ +abstract class AbstractQueryMessageHandler implements QueryMessageHandlerInterface +{ + abstract public function __invoke(QueryMessageInterface $message): mixed; +} diff --git a/src/SonsOfPHP/Component/Cqrs/Attribute/AsMessageHandler.php b/src/SonsOfPHP/Component/Cqrs/Attribute/AsMessageHandler.php new file mode 100644 index 00000000..52abcdde --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Attribute/AsMessageHandler.php @@ -0,0 +1,22 @@ + + */ +#[Attribute(Attribute::TARGET_PROPERTY)] +final class AsMessageHandler +{ + public function __construct( + public readonly string $messageClass, + ) {} +} diff --git a/src/SonsOfPHP/Component/Cqrs/CommandBus.php b/src/SonsOfPHP/Component/Cqrs/CommandBus.php new file mode 100644 index 00000000..00962e7e --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/CommandBus.php @@ -0,0 +1,20 @@ + + */ +class CommandBus extends AbstractBus implements CommandBusInterface +{ + public function dispatch(object $command): void + { + $handler = $this->provider->getHandlerForMessage($command); + + $handler($command, $this); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/Exception/CqrsException.php b/src/SonsOfPHP/Component/Cqrs/Exception/CqrsException.php new file mode 100644 index 00000000..ecd28dc7 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Exception/CqrsException.php @@ -0,0 +1,12 @@ + + */ +class CqrsException extends \Exception implements CqrsExceptionInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/Exception/NoHandlerFoundException.php b/src/SonsOfPHP/Component/Cqrs/Exception/NoHandlerFoundException.php new file mode 100644 index 00000000..78972fe7 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Exception/NoHandlerFoundException.php @@ -0,0 +1,12 @@ + + */ +class NoHandlerFoundException extends \Exception implements NoHandlerFoundExceptionInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/MessageHandlerInterface.php b/src/SonsOfPHP/Component/Cqrs/MessageHandlerInterface.php deleted file mode 100644 index 8832cad5..00000000 --- a/src/SonsOfPHP/Component/Cqrs/MessageHandlerInterface.php +++ /dev/null @@ -1,10 +0,0 @@ - - */ -interface MessageHandlerInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/MessageHandlerProvider.php b/src/SonsOfPHP/Component/Cqrs/MessageHandlerProvider.php new file mode 100644 index 00000000..c78ea597 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/MessageHandlerProvider.php @@ -0,0 +1,54 @@ + + */ +class MessageHandlerProvider implements MessageHandlerProviderInterface +{ + private array $handlers = []; + + /** + * Register a command with a command handler + * + * Usage: + * $cmd = new CreateUser(); + * $handler = new CreateUserHandler(); + * $provider->register($cmd, $handler); + * --- + * $handler = new CreateUserHandler(); + * $provider->register(CreateUser::class, $handler); + * --- + * $provider->register(CreateUser::class, function (CreateUser $cmd) {}); + */ + public function add(string|object $message, callable $handler): void + { + if (is_object($message)) { + $message = $message::class; + } + + $this->handlers[$message] = $handler; + } + + /** + * {@inheritdoc} + */ + public function getHandlerForMessage(string|object $message): callable + { + if (is_object($message)) { + $message = $message::class; + } + + if (!array_key_exists($message, $this->handlers)) { + throw new NoHandlerFoundException(sprintf('No handler for message "%s" found.', $message)); + } + + return $this->handlers[$message]; + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/MessageInterface.php b/src/SonsOfPHP/Component/Cqrs/MessageInterface.php deleted file mode 100644 index 1a6cdc52..00000000 --- a/src/SonsOfPHP/Component/Cqrs/MessageInterface.php +++ /dev/null @@ -1,12 +0,0 @@ - - */ -interface MessageInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/Query/QueryMessageHandlerInterface.php b/src/SonsOfPHP/Component/Cqrs/Query/QueryMessageHandlerInterface.php deleted file mode 100644 index 1fdb7a7a..00000000 --- a/src/SonsOfPHP/Component/Cqrs/Query/QueryMessageHandlerInterface.php +++ /dev/null @@ -1,12 +0,0 @@ - - */ -interface QueryMessageHandlerInterface extends MessageHandlerInterface {} diff --git a/src/SonsOfPHP/Component/Cqrs/QueryBus.php b/src/SonsOfPHP/Component/Cqrs/QueryBus.php new file mode 100644 index 00000000..80325ebc --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/QueryBus.php @@ -0,0 +1,20 @@ + + */ +class QueryBus extends AbstractBus implements QueryBusInterface +{ + public function handle(object $command): mixed + { + $handler = $this->provider->getHandlerForMessage($command); + + return $handler($command, $this); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/Tests/AbstractMessageTest.php b/src/SonsOfPHP/Component/Cqrs/Tests/AbstractMessageTest.php new file mode 100644 index 00000000..d328c146 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Tests/AbstractMessageTest.php @@ -0,0 +1,212 @@ +getMockForAbstractClass(AbstractMessage::class); + + $this->assertInstanceOf(MessageInterface::class, $msg); + } + + /** + * @covers ::with + */ + public function testWithWhenKeyIsAnArrayThatContainsAStringableValue(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with([ + 'key' => new class () implements \Stringable { + public function __toString(): string + { + return 'value'; + } + }, + ]); + + $this->assertSame('value', $msg->get('key')); + } + + /** + * @covers ::with + */ + public function testWithWhenKeyIsAnArrayThatContainsAnInvalidValue(): void + { + $this->expectException('InvalidArgumentException'); + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with([ + 'key' => new \stdClass(), + ]); + } + + /** + * @covers ::with + */ + public function testWithWhenKeyIsAnArrayAndValueIsNotNull(): void + { + $this->expectException('InvalidArgumentException'); + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with([ + 'key' => 'value', + ], 'value'); + } + + /** + * @covers ::with + */ + public function testWithWhenKeyIsAnArray(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with([ + 'key' => 'value', + ]); + + $this->assertSame('value', $msg->get('key')); + } + + /** + * @covers ::with + */ + public function testWithWillReturnANewInstanceIfNewData(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('value', 'key'); + + $this->assertNotSame($msg, $msg->with('key', 'value')); + $this->assertSame($msg, $msg->with('value', 'key')); + } + + /** + * @covers ::with + * + * @dataProvider invalidValueProvider + */ + public function testWithWillThrowInvalidArgumentExceptionWhenValueIsInvalid(mixed $value): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class); + + $this->expectException('InvalidArgumentException'); + $msg->with('key', $value); + } + + /** + * @covers ::with + */ + public function testWithWorksAsExpectedWhenValueIsStringable(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class); + + $value = new class () implements \Stringable { + public function __toString(): string + { + return 'value'; + } + }; + + $message = $msg->with('key', $value); + + $this->assertNotSame($msg, $message); + $this->assertSame('value', $message->get('key')); + } + + /** + * @covers ::get + */ + public function testGet(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $this->assertSame('value', $msg->get('key')); + } + + /** + * @covers ::get + */ + public function testGetWillReturnAllWhenNoArgument(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $this->assertArrayHasKey('key', $msg->get()); + } + + /** + * @covers ::get + */ + public function testGetWillThrowExceptionWhenKeyNotFound(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $this->expectException('Exception'); + $msg->get('nope'); + } + + /** + * @covers ::__serialize + */ + public function testSerializeMagicMethod(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $this->assertArrayHasKey('key', $msg->__serialize()); + } + + /** + * @covers ::__unserialize + */ + public function testUnserializeMagicMethod(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $message = unserialize(serialize($msg)); + + $this->assertArrayHasKey('key', $message->get()); + } + + /** + * @covers ::serialize + */ + public function testSerialize(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $this->assertSame('{"key":"value"}', $msg->serialize()); + } + + /** + * @covers ::unserialize + */ + public function testUnserialize(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + $msg->unserialize('{"key":"other value"}'); + + $this->assertSame('other value', $msg->get('key')); + } + + /** + * @covers ::jsonSerialize + */ + public function testjsonSerialize(): void + { + $msg = $this->getMockForAbstractClass(AbstractMessage::class)->with('key', 'value'); + + $this->assertArrayHasKey('key', $msg->jsonSerialize()); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/Tests/CommandBusTest.php b/src/SonsOfPHP/Component/Cqrs/Tests/CommandBusTest.php new file mode 100644 index 00000000..f935828b --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Tests/CommandBusTest.php @@ -0,0 +1,56 @@ +provider = $this->createMock(MessageHandlerProvider::class); + } + + /** + * @covers ::__construct + */ + public function testItHasTheCorrectInterface(): void + { + $bus = new CommandBus(); + + $this->assertInstanceOf(CommandBusInterface::class, $bus); + } + + /** + * @covers ::addHandler + */ + public function testAddHandler(): void + { + $this->provider->expects($this->once())->method('add'); + $bus = new CommandBus($this->provider); + $bus->addHandler(new \stdClass(), function (): void {}); + } + + /** + * @covers ::dispatch + */ + public function testDispatch(): void + { + $this->provider->expects($this->once())->method('getHandlerForMessage')->willReturn(function (): void {}); + $bus = new CommandBus($this->provider); + $bus->dispatch(new \stdClass()); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/Tests/MessageHandlerProviderTest.php b/src/SonsOfPHP/Component/Cqrs/Tests/MessageHandlerProviderTest.php new file mode 100644 index 00000000..6313d073 --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Tests/MessageHandlerProviderTest.php @@ -0,0 +1,117 @@ +assertInstanceOf(MessageHandlerProviderInterface::class, $provider); + } + + /** + * @covers ::add + */ + public function testAddWithHandlerClass(): void + { + $provider = new MessageHandlerProvider(); + $provider->add(new \stdClass(), new class () { + public function __invoke(): void {} + }); + + $property = new \ReflectionProperty($provider, 'handlers'); + $handlers = $property->getValue($provider); + + $this->assertArrayHasKey('stdClass', $handlers); + } + + /** + * @covers ::add + */ + public function testAddWithObject(): void + { + $provider = new MessageHandlerProvider(); + $provider->add(new \stdClass(), function (): void {}); + + $property = new \ReflectionProperty($provider, 'handlers'); + $handlers = $property->getValue($provider); + + $this->assertArrayHasKey('stdClass', $handlers); + } + + /** + * @covers ::add + */ + public function testAddWithString(): void + { + $provider = new MessageHandlerProvider(); + $provider->add('stdClass', function (): void {}); + + $property = new \ReflectionProperty($provider, 'handlers'); + $handlers = $property->getValue($provider); + + $this->assertArrayHasKey('stdClass', $handlers); + } + + /** + * @covers ::getHandlerForMessage + */ + public function testGetHandlerForMessageWhenClassIsInvokable(): void + { + $provider = new MessageHandlerProvider(); + $provider->add(new \stdClass(), new class () { + public function __invoke(): void {} + }); + + $this->assertNotNull($provider->getHandlerForMessage('stdClass')); + } + + /** + * @covers ::getHandlerForMessage + */ + public function testGetHandlerForMessageWhenNoHandlerExists(): void + { + $provider = new MessageHandlerProvider(); + $this->expectException(NoHandlerFoundExceptionInterface::class); + $this->assertNotNull($provider->getHandlerForMessage('stdClass')); + } + + /** + * @covers ::getHandlerForMessage + */ + public function testGetHandlerForMessageWhenStringIsPassedIn(): void + { + $provider = new MessageHandlerProvider(); + $provider->add(new \stdClass(), function (): void {}); + + $this->assertNotNull($provider->getHandlerForMessage('stdClass')); + } + + /** + * @covers ::getHandlerForMessage + */ + public function testGetHandlerForMessageWhenObjectIsPassedIn(): void + { + $provider = new MessageHandlerProvider(); + $provider->add(new \stdClass(), function (): void {}); + + $this->assertNotNull($provider->getHandlerForMessage(new \stdClass())); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/Tests/QueryBusTest.php b/src/SonsOfPHP/Component/Cqrs/Tests/QueryBusTest.php new file mode 100644 index 00000000..e970164b --- /dev/null +++ b/src/SonsOfPHP/Component/Cqrs/Tests/QueryBusTest.php @@ -0,0 +1,56 @@ +provider = $this->createMock(MessageHandlerProvider::class); + } + + /** + * @covers ::__construct + */ + public function testItHasTheCorrectInterface(): void + { + $bus = new QueryBus(); + + $this->assertInstanceOf(QueryBusInterface::class, $bus); + } + + /** + * @covers ::addHandler + */ + public function testAddHandler(): void + { + $this->provider->expects($this->once())->method('add'); + $bus = new QueryBus($this->provider); + $bus->addHandler(new \stdClass(), function (): void {}); + } + + /** + * @covers ::handle + */ + public function testHandle(): void + { + $this->provider->expects($this->once())->method('getHandlerForMessage')->willReturn(fn() => 'testing'); + $bus = new QueryBus($this->provider); + $this->assertSame('testing', $bus->handle(new \stdClass())); + } +} diff --git a/src/SonsOfPHP/Component/Cqrs/composer.json b/src/SonsOfPHP/Component/Cqrs/composer.json index d1cf7abd..daad3e72 100644 --- a/src/SonsOfPHP/Component/Cqrs/composer.json +++ b/src/SonsOfPHP/Component/Cqrs/composer.json @@ -33,10 +33,14 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.1", + "sonsofphp/cqrs-contract": "0.3.x-dev" }, "require-dev": { - "symfony/messenger": "^5|^6" + "symfony/messenger": "^5 || ^6" + }, + "provide": { + "sonsofphp/cqrs-implementation": "0.3.x-dev" }, "suggest": { "sonsofphp/event-sourcing": "Use with event sourcing", diff --git a/src/SonsOfPHP/Component/EventDispatcher/Tests/EventDispatcherTest.php b/src/SonsOfPHP/Component/EventDispatcher/Tests/EventDispatcherTest.php index be28da70..9a760b6a 100644 --- a/src/SonsOfPHP/Component/EventDispatcher/Tests/EventDispatcherTest.php +++ b/src/SonsOfPHP/Component/EventDispatcher/Tests/EventDispatcherTest.php @@ -7,8 +7,8 @@ use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\EventDispatcherInterface; use SonsOfPHP\Component\EventDispatcher\EventDispatcher; -use SonsOfPHP\Component\EventDispatcher\ListenerProvider; use SonsOfPHP\Component\EventDispatcher\EventSubscriberInterface; +use SonsOfPHP\Component\EventDispatcher\ListenerProvider; /** * @coversDefaultClass \SonsOfPHP\Component\EventDispatcher\EventDispatcher diff --git a/src/SonsOfPHP/Component/EventDispatcher/Tests/ListenerProviderTest.php b/src/SonsOfPHP/Component/EventDispatcher/Tests/ListenerProviderTest.php index 4928d144..53badc17 100644 --- a/src/SonsOfPHP/Component/EventDispatcher/Tests/ListenerProviderTest.php +++ b/src/SonsOfPHP/Component/EventDispatcher/Tests/ListenerProviderTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use Psr\EventDispatcher\ListenerProviderInterface; -use SonsOfPHP\Component\EventDispatcher\ListenerProvider; use SonsOfPHP\Component\EventDispatcher\EventSubscriberInterface; +use SonsOfPHP\Component\EventDispatcher\ListenerProvider; /** * @coversDefaultClass \SonsOfPHP\Component\EventDispatcher\ListenerProvider diff --git a/src/SonsOfPHP/Component/EventSourcing/Tests/Test/CountEventsRaisedTest.php b/src/SonsOfPHP/Component/EventSourcing/Tests/Test/CountEventsRaisedTest.php index f00bfdb7..69a764ca 100644 --- a/src/SonsOfPHP/Component/EventSourcing/Tests/Test/CountEventsRaisedTest.php +++ b/src/SonsOfPHP/Component/EventSourcing/Tests/Test/CountEventsRaisedTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\EventSourcing\Tests\Test; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\EventSourcing\Test\CountEventsRaised; use SonsOfPHP\Component\EventSourcing\Aggregate\AggregateInterface; +use SonsOfPHP\Component\EventSourcing\Test\CountEventsRaised; /** * @coversDefaultClass \SonsOfPHP\Component\EventSourcing\Test\CountEventsRaised diff --git a/src/SonsOfPHP/Component/EventSourcing/Tests/Test/EventRaisedTest.php b/src/SonsOfPHP/Component/EventSourcing/Tests/Test/EventRaisedTest.php index 7ec7f41f..006792c4 100644 --- a/src/SonsOfPHP/Component/EventSourcing/Tests/Test/EventRaisedTest.php +++ b/src/SonsOfPHP/Component/EventSourcing/Tests/Test/EventRaisedTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\EventSourcing\Tests\Test; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\EventSourcing\Test\EventRaised; use SonsOfPHP\Component\EventSourcing\Aggregate\AggregateInterface; +use SonsOfPHP\Component\EventSourcing\Test\EventRaised; /** * @coversDefaultClass \SonsOfPHP\Component\EventSourcing\Test\EventRaised diff --git a/src/SonsOfPHP/Component/EventSourcing/composer.json b/src/SonsOfPHP/Component/EventSourcing/composer.json index 8781c64c..bd6f9f36 100644 --- a/src/SonsOfPHP/Component/EventSourcing/composer.json +++ b/src/SonsOfPHP/Component/EventSourcing/composer.json @@ -30,11 +30,15 @@ "prefer-stable": true, "require": { "php": ">=8.1", + "sonsofphp/event-sourcing-contract": "^0.3.x-dev", "sonsofphp/event-dispatcher": "^0.3.x-dev" }, "require-dev": { "phpunit/phpunit": "^10.4" }, + "provide": { + "sonsofphp/event-sourcing-implementation": "0.3.x-dev" + }, "suggest": { "sonsofphp/event-sourcing-doctrine": "Adds additional functionality using Doctrine", "sonsofphp/event-sourcing-symfony": "Adds additional functionality using Symfony Components" diff --git a/src/SonsOfPHP/Component/FeatureToggle/Context.php b/src/SonsOfPHP/Component/FeatureToggle/Context.php index c00767ab..162147c0 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Context.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Context.php @@ -4,6 +4,8 @@ namespace SonsOfPHP\Component\FeatureToggle; +use SonsOfPHP\Contract\FeatureToggle\ContextInterface; + /** * @author Joshua Estes */ @@ -11,54 +13,28 @@ final class Context implements ContextInterface { public function __construct(private array $data = []) {} - public function offsetSet($offset, $value): void + public function get(?string $key = null, mixed $default = null): mixed { - if (null === $offset) { - throw new \Exception('Requires a key'); + if (null === $key) { + return $this->data; } - $this->data[$offset] = $value; - } - - public function offsetExists($offset): bool - { - return \array_key_exists($offset, $this->data); - } - - public function offsetUnset($offset): void - { - unset($this->data[$offset]); - } - - public function offsetGet($offset): mixed - { - return $this->data[$offset] ?? null; - } - - public function getIterator(): \Traversable - { - return new \ArrayIterator($this->data); - } - - public function jsonSerialize(): mixed - { - return $this->data; - } + if (!$this->has($key)) { + return $default; + } - public function get(string $key): mixed - { - return $this->offsetGet($key); + return $this->data[$key]; } - public function set(string $key, $value): ContextInterface + public function set(string $key, mixed $value): ContextInterface { - $this->offsetSet($key, $value); + $this->data[$key] = $value; return $this; } public function has(string $key): bool { - return $this->offsetExists($key); + return \array_key_exists($key, $this->data); } } diff --git a/src/SonsOfPHP/Component/FeatureToggle/ContextInterface.php b/src/SonsOfPHP/Component/FeatureToggle/ContextInterface.php deleted file mode 100644 index 1613f015..00000000 --- a/src/SonsOfPHP/Component/FeatureToggle/ContextInterface.php +++ /dev/null @@ -1,17 +0,0 @@ - - */ -interface ContextInterface extends \ArrayAccess, \IteratorAggregate, \JsonSerializable -{ - public function get(string $key); - - public function set(string $key, $value): self; - - public function has(string $key): bool; -} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Exception/FeatureToggleException.php b/src/SonsOfPHP/Component/FeatureToggle/Exception/FeatureToggleException.php index f4336826..4e4cb5fc 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Exception/FeatureToggleException.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Exception/FeatureToggleException.php @@ -4,7 +4,9 @@ namespace SonsOfPHP\Component\FeatureToggle\Exception; +use SonsOfPHP\Contract\FeatureToggle\Exception\FeatureToggleExceptionInterface; + /** * @author Joshua Estes */ -class FeatureToggleException extends \Exception {} +class FeatureToggleException extends \Exception implements FeatureToggleExceptionInterface {} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Feature.php b/src/SonsOfPHP/Component/FeatureToggle/Feature.php index c95c0e7a..893aa02a 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Feature.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Feature.php @@ -4,6 +4,10 @@ namespace SonsOfPHP\Component\FeatureToggle; +use SonsOfPHP\Contract\FeatureToggle\ContextInterface; +use SonsOfPHP\Contract\FeatureToggle\FeatureInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; + /** * Feature. * diff --git a/src/SonsOfPHP/Component/FeatureToggle/Provider/InMemoryFeatureToggleProvider.php b/src/SonsOfPHP/Component/FeatureToggle/Provider/InMemoryFeatureToggleProvider.php index 9f6a84e3..4879521d 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Provider/InMemoryFeatureToggleProvider.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Provider/InMemoryFeatureToggleProvider.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\FeatureToggle\Provider; -use SonsOfPHP\Component\FeatureToggle\FeatureInterface; +use SonsOfPHP\Contract\FeatureToggle\FeatureInterface; +use SonsOfPHP\Contract\FeatureToggle\FeatureToggleProviderInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/ContextTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/ContextTest.php index d89491ea..38bb3642 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Tests/ContextTest.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/ContextTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\FeatureToggle\Context; -use SonsOfPHP\Component\FeatureToggle\ContextInterface; +use SonsOfPHP\Contract\FeatureToggle\ContextInterface; /** * @coversDefaultClass \SonsOfPHP\Component\FeatureToggle\Context @@ -25,19 +25,87 @@ public function testItHasTheCorrectInterface(): void $this->assertInstanceOf(ContextInterface::class, $context); } + /** + * @covers ::__construct + */ + public function testConstruct(): void + { + $context = new Context([ + 'key' => 'value', + ]); + $this->assertSame('value', $context->get('key')); + } + /** * @covers ::get - * @covers ::has + */ + public function testGetWhenThereIsValueForKey(): void + { + $context = new Context([ + 'key' => 'value', + ]); + $this->assertSame('value', $context->get('key')); + } + + /** + * @covers ::get + */ + public function testGetWhenThereIsNoValueForKey(): void + { + $context = new Context(); + $this->assertNull($context->get('test')); + } + + /** + * @covers ::get + */ + public function testGetWhenThereIsNoValueForKeyAndDefaultValueIsProvided(): void + { + $context = new Context(); + $this->assertTrue($context->get('test', true)); + } + + /** + * @covers ::get + */ + public function testGetWithNoArgumentsWillReturnAll(): void + { + $context = new Context(); + $context->set('key', 'value'); + $parameters = $context->get(); + $this->assertIsArray($parameters); + $this->assertArrayHasKey('key', $parameters); + } + + /** * @covers ::set */ - public function testItWorksCorrectly(): void + public function testWorksAsExpected(): void { $context = new Context(); + $context->set('key', 'value'); + $this->assertSame('value', $context->get('key')); + } - $this->assertFalse($context->has('test')); - $this->assertNull($context->get('test'), 'Assert NULL is returned if not set'); + /** + * @covers ::has + */ + public function testHasWillReturnTrueWhenKeyExists(): void + { + $context = new Context([ + 'key' => 'value', + ]); + $this->assertTrue($context->has('key')); + } - $context->set('test', 'value'); - $this->assertSame('value', $context->get('test')); + /** + * @covers ::has + */ + public function testHasWillReturnFalseWhenKeyExists(): void + { + $context = new Context([ + 'key' => 'value', + ]); + $this->assertFalse($context->has('value')); } } diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/FeatureTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/FeatureTest.php index fee35644..90d03805 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Tests/FeatureTest.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/FeatureTest.php @@ -7,8 +7,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\FeatureToggle\Context; use SonsOfPHP\Component\FeatureToggle\Feature; -use SonsOfPHP\Component\FeatureToggle\FeatureInterface; -use SonsOfPHP\Component\FeatureToggle\ToggleInterface; +use SonsOfPHP\Contract\FeatureToggle\FeatureInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; /** * @coversDefaultClass \SonsOfPHP\Component\FeatureToggle\Feature diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Provider/InMemoryFeatureToggleProviderTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Provider/InMemoryFeatureToggleProviderTest.php index 4d8fa666..2c311417 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Tests/Provider/InMemoryFeatureToggleProviderTest.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Provider/InMemoryFeatureToggleProviderTest.php @@ -4,12 +4,12 @@ namespace SonsOfPHP\Component\FeatureToggle\Tests\Provider; +use PHPUnit\Framework\MockObject; use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\FeatureToggle\Feature; -use SonsOfPHP\Component\FeatureToggle\Provider\FeatureToggleProviderInterface; use SonsOfPHP\Component\FeatureToggle\Provider\InMemoryFeatureToggleProvider; -use SonsOfPHP\Component\FeatureToggle\ToggleInterface; -use PHPUnit\Framework\MockObject; +use SonsOfPHP\Contract\FeatureToggle\FeatureToggleProviderInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; /** * @coversDefaultClass \SonsOfPHP\Component\FeatureToggle\Provider\InMemoryFeatureToggleProvider diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AffirmativeToggleTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AffirmativeToggleTest.php new file mode 100644 index 00000000..4cb35df4 --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AffirmativeToggleTest.php @@ -0,0 +1,58 @@ +assertInstanceOf(ToggleInterface::class, $toggle); + } + + /** + * @covers ::isEnabled + */ + public function testIsEnabledWhenAllTogglesAreEnabled(): void + { + $toggle = new AffirmativeToggle([ + new MockToggle(enabled: true), + new MockToggle(enabled: true), + new MockToggle(enabled: true), + ]); + + $this->assertTrue($toggle->isEnabled()); + } + + /** + * @covers ::isEnabled + */ + public function testIsEnabledWhenOneToggleIsDisabled(): void + { + $toggle = new AffirmativeToggle([ + new MockToggle(enabled: true), + new MockToggle(enabled: false), + new MockToggle(enabled: true), + ]); + + $this->assertFalse($toggle->isEnabled()); + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysDisabledToggleTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysDisabledToggleTest.php index 4aaa4e3f..2f305a63 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysDisabledToggleTest.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysDisabledToggleTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\FeatureToggle\Context; use SonsOfPHP\Component\FeatureToggle\Toggle\AlwaysDisabledToggle; -use SonsOfPHP\Component\FeatureToggle\ToggleInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; /** * @coversDefaultClass \SonsOfPHP\Component\FeatureToggle\Toggle\AlwaysDisabledToggle diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysEnabledToggleTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysEnabledToggleTest.php index 87bd194b..bb74dc88 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysEnabledToggleTest.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/AlwaysEnabledToggleTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\FeatureToggle\Context; use SonsOfPHP\Component\FeatureToggle\Toggle\AlwaysEnabledToggle; -use SonsOfPHP\Component\FeatureToggle\ToggleInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; /** * @coversDefaultClass \SonsOfPHP\Component\FeatureToggle\Toggle\AlwaysEnabledToggle diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/ChainToggleTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/ChainToggleTest.php new file mode 100644 index 00000000..291a635a --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/ChainToggleTest.php @@ -0,0 +1,58 @@ +assertInstanceOf(ToggleInterface::class, $toggle); + } + + /** + * @covers ::isEnabled + */ + public function testIsEnabledWhenAtLeastOneIsEnabled(): void + { + $toggle = new ChainToggle([ + new MockToggle(enabled: false), + new MockToggle(enabled: false), + new MockToggle(enabled: true), + ]); + + $this->assertTrue($toggle->isEnabled()); + } + + /** + * @covers ::isEnabled + */ + public function testIsEnabledWhenAllTogglesAreDisabled(): void + { + $toggle = new ChainToggle([ + new MockToggle(enabled: false), + new MockToggle(enabled: false), + new MockToggle(enabled: false), + ]); + + $this->assertFalse($toggle->isEnabled()); + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/DateRangeToggleTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/DateRangeToggleTest.php new file mode 100644 index 00000000..006c67ff --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/DateRangeToggleTest.php @@ -0,0 +1,57 @@ +assertInstanceOf(ToggleInterface::class, $toggle); + } + + /** + * @covers ::isEnabled + */ + public function testIsEnabledWorksAsExpected(): void + { + $toggle = new DateRangeToggle( + start: new \DateTimeImmutable('-90 days'), + stop: new \DateTimeImmutable('+90 days'), + ); + + $this->assertTrue($toggle->isEnabled()); + } + + /** + * @covers ::isEnabled + */ + public function testIsEnabledWorksAsExpectedWhenOutsideDateRange(): void + { + $toggle = new DateRangeToggle( + start: new \DateTimeImmutable('-90 days'), + stop: new \DateTimeImmutable('-30 days'), + ); + + $this->assertFalse($toggle->isEnabled()); + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/MockToggleTest.php b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/MockToggleTest.php new file mode 100644 index 00000000..2a761c39 --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Tests/Toggle/MockToggleTest.php @@ -0,0 +1,60 @@ +assertInstanceOf(ToggleInterface::class, $toggle); + } + + /** + * @covers ::__construct + * @covers ::isEnabled + */ + public function testIsEnabledWillReturnTrueByDefault(): void + { + $toggle = new MockToggle(); + + $this->assertTrue($toggle->isEnabled()); + } + + /** + * @covers ::__construct + * @covers ::isEnabled + */ + public function testIsEnabledWillReturnTrueWhenEnabledIsSetToTrue(): void + { + $toggle = new MockToggle(enabled: true); + + $this->assertTrue($toggle->isEnabled()); + } + + /** + * @covers ::__construct + * @covers ::isEnabled + */ + public function testIsEnabledWillReturnFalseWhenEnabledIsSetToFalse(): void + { + $toggle = new MockToggle(enabled: false); + + $this->assertFalse($toggle->isEnabled()); + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Toggle/AffirmativeToggle.php b/src/SonsOfPHP/Component/FeatureToggle/Toggle/AffirmativeToggle.php new file mode 100644 index 00000000..e15235e1 --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Toggle/AffirmativeToggle.php @@ -0,0 +1,32 @@ + + */ +class AffirmativeToggle implements ToggleInterface +{ + public function __construct( + private array $toggles, + ) {} + + public function isEnabled(?ContextInterface $context = null): bool + { + foreach ($this->toggles as $toggle) { + if (!$toggle->isEnabled($context)) { + return false; + } + } + + return true; + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysDisabledToggle.php b/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysDisabledToggle.php index 77181c9e..ff536a6a 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysDisabledToggle.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysDisabledToggle.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\FeatureToggle\Toggle; -use SonsOfPHP\Component\FeatureToggle\ContextInterface; -use SonsOfPHP\Component\FeatureToggle\ToggleInterface; +use SonsOfPHP\Contract\FeatureToggle\ContextInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; /** * Always Disabled. diff --git a/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysEnabledToggle.php b/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysEnabledToggle.php index 3e80255d..05991445 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysEnabledToggle.php +++ b/src/SonsOfPHP/Component/FeatureToggle/Toggle/AlwaysEnabledToggle.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\FeatureToggle\Toggle; -use SonsOfPHP\Component\FeatureToggle\ContextInterface; -use SonsOfPHP\Component\FeatureToggle\ToggleInterface; +use SonsOfPHP\Contract\FeatureToggle\ContextInterface; +use SonsOfPHP\Contract\FeatureToggle\ToggleInterface; /** * Always enabled. diff --git a/src/SonsOfPHP/Component/FeatureToggle/Toggle/ChainToggle.php b/src/SonsOfPHP/Component/FeatureToggle/Toggle/ChainToggle.php new file mode 100644 index 00000000..35d90d33 --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Toggle/ChainToggle.php @@ -0,0 +1,32 @@ + + */ +class ChainToggle implements ToggleInterface +{ + public function __construct( + private array $toggles, + ) {} + + public function isEnabled(?ContextInterface $context = null): bool + { + foreach ($this->toggles as $toggle) { + if ($toggle->isEnabled($context)) { + return true; + } + } + + return false; + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Toggle/DateRangeToggle.php b/src/SonsOfPHP/Component/FeatureToggle/Toggle/DateRangeToggle.php new file mode 100644 index 00000000..99be2729 --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Toggle/DateRangeToggle.php @@ -0,0 +1,28 @@ + + */ +class DateRangeToggle implements ToggleInterface +{ + public function __construct( + private \DateTimeImmutable $start, + private \DateTimeImmutable $stop, + ) {} + + public function isEnabled(?ContextInterface $context = null): bool + { + $now = new \DateTimeImmutable(); + + return ($this->start <= $now && $now <= $this->stop); + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/Toggle/MockToggle.php b/src/SonsOfPHP/Component/FeatureToggle/Toggle/MockToggle.php new file mode 100644 index 00000000..11626ca3 --- /dev/null +++ b/src/SonsOfPHP/Component/FeatureToggle/Toggle/MockToggle.php @@ -0,0 +1,23 @@ + + */ +class MockToggle implements ToggleInterface +{ + public function __construct( + private bool $enabled = true, + ) {} + + public function isEnabled(?ContextInterface $context = null): bool + { + return $this->enabled; + } +} diff --git a/src/SonsOfPHP/Component/FeatureToggle/composer.json b/src/SonsOfPHP/Component/FeatureToggle/composer.json index e42d64e8..dd1ed776 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/composer.json +++ b/src/SonsOfPHP/Component/FeatureToggle/composer.json @@ -35,7 +35,11 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.1", + "sonsofphp/feature-toggle-contract": "0.3.x-dev" + }, + "provide": { + "sonsofphp/feature-toggle-implementation": "0.3.x-dev" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/AdapterInterface.php b/src/SonsOfPHP/Component/Filesystem/Adapter/AdapterInterface.php index 84872081..e91e54e2 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/AdapterInterface.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/AdapterInterface.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\Filesystem\Adapter; use SonsOfPHP\Component\Filesystem\ContextInterface; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; +use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * Base Adapter Interface that all adapters implement. diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/CopyAwareInterface.php b/src/SonsOfPHP/Component/Filesystem/Adapter/CopyAwareInterface.php index 76f0b86b..0a9236fe 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/CopyAwareInterface.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/CopyAwareInterface.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\Filesystem\Adapter; use SonsOfPHP\Component\Filesystem\ContextInterface; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; +use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * If an adapter supports the ability to copy a file from one place to another diff --git a/src/SonsOfPHP/Component/Filesystem/Adapter/MoveAwareInterface.php b/src/SonsOfPHP/Component/Filesystem/Adapter/MoveAwareInterface.php index 5fd83db4..ee10d296 100644 --- a/src/SonsOfPHP/Component/Filesystem/Adapter/MoveAwareInterface.php +++ b/src/SonsOfPHP/Component/Filesystem/Adapter/MoveAwareInterface.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\Filesystem\Adapter; use SonsOfPHP\Component\Filesystem\ContextInterface; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; +use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * If an adapter supports the ability to move a file from one place to another diff --git a/src/SonsOfPHP/Component/Filesystem/Filesystem.php b/src/SonsOfPHP/Component/Filesystem/Filesystem.php index bd589823..bdfe3fe7 100644 --- a/src/SonsOfPHP/Component/Filesystem/Filesystem.php +++ b/src/SonsOfPHP/Component/Filesystem/Filesystem.php @@ -4,10 +4,10 @@ namespace SonsOfPHP\Component\Filesystem; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; use SonsOfPHP\Component\Filesystem\Adapter\CopyAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\MoveAwareInterface; +use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php index c67ce9b6..75b8c36c 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ChainAdapterTest.php @@ -6,11 +6,11 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; +use SonsOfPHP\Component\Filesystem\Adapter\ChainAdapter; use SonsOfPHP\Component\Filesystem\Adapter\CopyAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\DirectoryAwareInterface; -use SonsOfPHP\Component\Filesystem\Adapter\MoveAwareInterface; -use SonsOfPHP\Component\Filesystem\Adapter\ChainAdapter; use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; +use SonsOfPHP\Component\Filesystem\Adapter\MoveAwareInterface; use SonsOfPHP\Component\Filesystem\Exception\FileNotFoundException; /** diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php index 18278733..939058de 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/ReadOnlyAdapterTest.php @@ -4,12 +4,12 @@ namespace SonsOfPHP\Component\Filesystem\Tests; -use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; -use PHPUnit\Framework\TestCase; use PHPUnit\Framework\MockObject; +use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; use SonsOfPHP\Component\Filesystem\Adapter\CopyAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\DirectoryAwareInterface; +use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; use SonsOfPHP\Component\Filesystem\Adapter\MoveAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\ReadOnlyAdapter; use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php index 55daa3ae..dbaae807 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/Adapter/WormAdapterTest.php @@ -4,14 +4,14 @@ namespace SonsOfPHP\Component\Filesystem\Tests; -use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Filesystem\Adapter\AdapterInterface; use SonsOfPHP\Component\Filesystem\Adapter\CopyAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\DirectoryAwareInterface; +use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; use SonsOfPHP\Component\Filesystem\Adapter\MoveAwareInterface; use SonsOfPHP\Component\Filesystem\Adapter\WormAdapter; +use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * @coversDefaultClass \SonsOfPHP\Component\Filesystem\Adapter\WormAdapter diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php index 98c78e1b..e61dc5a2 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/ContextTest.php @@ -4,10 +4,10 @@ namespace SonsOfPHP\Component\Filesystem\Tests; -use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Filesystem\ContextInterface; use SonsOfPHP\Component\Filesystem\Context; +use SonsOfPHP\Component\Filesystem\ContextInterface; +use SonsOfPHP\Component\Filesystem\Exception\FilesystemException; /** * @coversDefaultClass \SonsOfPHP\Component\Filesystem\Context diff --git a/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php b/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php index 4f2e3327..47250795 100644 --- a/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/SonsOfPHP/Component/Filesystem/Tests/FilesystemTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\Filesystem\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Filesystem\FilesystemInterface; -use SonsOfPHP\Component\Filesystem\Filesystem; use SonsOfPHP\Component\Filesystem\Adapter\InMemoryAdapter; +use SonsOfPHP\Component\Filesystem\Filesystem; +use SonsOfPHP\Component\Filesystem\FilesystemInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Filesystem\Filesystem diff --git a/src/SonsOfPHP/Component/Filesystem/composer.json b/src/SonsOfPHP/Component/Filesystem/composer.json index 83cf02d1..758f58ca 100644 --- a/src/SonsOfPHP/Component/Filesystem/composer.json +++ b/src/SonsOfPHP/Component/Filesystem/composer.json @@ -31,7 +31,11 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.1", + "sonsofphp/filesystem-contract": "0.3.x-dev" + }, + "provide": { + "sonsofphp/filesystem-implementation": "0.3.x-dev" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php index f78e92a0..16709f7e 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/RequestFactoryTraitTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\RequestFactoryTrait; use Psr\Http\Message\RequestInterface; +use SonsOfPHP\Component\HttpFactory\RequestFactoryTrait; /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\RequestFactoryTrait diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php index cd669429..13bb0373 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/ResponseFactoryTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\ResponseFactory; -use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Http\Message\ResponseInterface; +use SonsOfPHP\Component\HttpFactory\ResponseFactory; /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\ResponseFactory diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php index 7a0208e0..da7cecd6 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/ServerRequestFactoryTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\ServerRequestFactory; -use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestFactoryInterface; +use Psr\Http\Message\ServerRequestInterface; +use SonsOfPHP\Component\HttpFactory\ServerRequestFactory; /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\ServerRequestFactory diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php index e41b82ed..dd47d3ca 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/StreamFactoryTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\StreamFactory; -use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\StreamInterface; +use SonsOfPHP\Component\HttpFactory\StreamFactory; /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\StreamFactory diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php index a92e83d7..67acc772 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/UploadedFileFactoryTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\UploadedFileFactory; -use Psr\Http\Message\UploadedFileInterface; -use Psr\Http\Message\UploadedFileFactoryInterface; use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileFactoryInterface; +use Psr\Http\Message\UploadedFileInterface; +use SonsOfPHP\Component\HttpFactory\UploadedFileFactory; /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\UploadedFileFactory diff --git a/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php b/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php index e8a242a7..b3d4b5ca 100644 --- a/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php +++ b/src/SonsOfPHP/Component/HttpFactory/Tests/UriFactoryTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\HttpFactory\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpFactory\UriFactory; -use Psr\Http\Message\UriInterface; use Psr\Http\Message\UriFactoryInterface; +use Psr\Http\Message\UriInterface; +use SonsOfPHP\Component\HttpFactory\UriFactory; /** * @coversDefaultClass \SonsOfPHP\Component\HttpFactory\UriFactory diff --git a/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php b/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php index 23dc0f83..e7ce2181 100644 --- a/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php +++ b/src/SonsOfPHP/Component/HttpFactory/UploadedFileFactoryTrait.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\HttpFactory; -use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileInterface; use SonsOfPHP\Component\HttpMessage\UploadedFile; /** diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/MessageTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/MessageTest.php index 7562d5d0..c743e621 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/MessageTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/MessageTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpMessage\Message; use Psr\Http\Message\MessageInterface; use Psr\Http\Message\StreamInterface; +use SonsOfPHP\Component\HttpMessage\Message; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\Message diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/RequestTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/RequestTest.php index 689536e0..cdfd6742 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/RequestTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/RequestTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpMessage\Request; -use SonsOfPHP\Component\HttpMessage\Uri; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\UriInterface; +use SonsOfPHP\Component\HttpMessage\Request; +use SonsOfPHP\Component\HttpMessage\Uri; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\Request diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/ResponseTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/ResponseTest.php index 1a8e2ae4..0bc2b50c 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/ResponseTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/ResponseTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpMessage\Response; use Psr\Http\Message\ResponseInterface; +use SonsOfPHP\Component\HttpMessage\Response; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\Response diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/ServerRequestTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/ServerRequestTest.php index 936e032a..5d6208bb 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/ServerRequestTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/ServerRequestTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpMessage\ServerRequest; use Psr\Http\Message\ServerRequestInterface; +use SonsOfPHP\Component\HttpMessage\ServerRequest; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\ServerRequest diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/StreamTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/StreamTest.php index 8244525e..513d8c05 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/StreamTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/StreamTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpMessage\Stream; use Psr\Http\Message\StreamInterface; +use SonsOfPHP\Component\HttpMessage\Stream; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\Stream diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/UploadedFileTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/UploadedFileTest.php index d1fd1306..d1fde08e 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/UploadedFileTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/UploadedFileTest.php @@ -5,10 +5,10 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; +use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileInterface; use SonsOfPHP\Component\HttpMessage\UploadedFile; use SonsOfPHP\Component\HttpMessage\UploadedFileError; -use Psr\Http\Message\UploadedFileInterface; -use Psr\Http\Message\StreamInterface; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\UploadedFile diff --git a/src/SonsOfPHP/Component/HttpMessage/Tests/UriTest.php b/src/SonsOfPHP/Component/HttpMessage/Tests/UriTest.php index a323d9b9..d3ba5379 100644 --- a/src/SonsOfPHP/Component/HttpMessage/Tests/UriTest.php +++ b/src/SonsOfPHP/Component/HttpMessage/Tests/UriTest.php @@ -5,8 +5,8 @@ namespace SonsOfPHP\Component\HttpMessage\Tests; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\HttpMessage\Uri; use Psr\Http\Message\UriInterface; +use SonsOfPHP\Component\HttpMessage\Uri; /** * @coversDefaultClass \SonsOfPHP\Component\HttpMessage\Uri diff --git a/src/SonsOfPHP/Component/HttpMessage/UploadedFile.php b/src/SonsOfPHP/Component/HttpMessage/UploadedFile.php index ac963011..48563905 100644 --- a/src/SonsOfPHP/Component/HttpMessage/UploadedFile.php +++ b/src/SonsOfPHP/Component/HttpMessage/UploadedFile.php @@ -4,8 +4,8 @@ namespace SonsOfPHP\Component\HttpMessage; -use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileInterface; /** * {@inheritdoc} diff --git a/src/SonsOfPHP/Component/HttpMessage/composer.json b/src/SonsOfPHP/Component/HttpMessage/composer.json index 6b95b118..2aa5b69f 100644 --- a/src/SonsOfPHP/Component/HttpMessage/composer.json +++ b/src/SonsOfPHP/Component/HttpMessage/composer.json @@ -32,14 +32,14 @@ "prefer-stable": true, "require": { "php": ">=8.1", - "psr/http-message": "^1.0|^2.0" + "psr/http-message": "^1.0 || ^2.0" }, "suggest": { "sonsofphp/filesystem": "Managing Uploaded files", "sonsofphp/http-factory": "Create various HTTP Messages using factories (PSR-17)" }, "provide": { - "psr/http-message-implementation": "^1.0|^2.0" + "psr/http-message-implementation": "^1.0 || ^2.0" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Component/Money/Amount.php b/src/SonsOfPHP/Component/Money/Amount.php index d0d65e26..5fe7cecd 100644 --- a/src/SonsOfPHP/Component/Money/Amount.php +++ b/src/SonsOfPHP/Component/Money/Amount.php @@ -5,11 +5,9 @@ namespace SonsOfPHP\Component\Money; use SonsOfPHP\Component\Money\Operator\Amount\AddAmountOperator; -use SonsOfPHP\Component\Money\Operator\Amount\AmountOperatorInterface; use SonsOfPHP\Component\Money\Operator\Amount\DivideAmountOperator; use SonsOfPHP\Component\Money\Operator\Amount\MultiplyAmountOperator; use SonsOfPHP\Component\Money\Operator\Amount\SubtractAmountOperator; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsEqualToAmountQuery; use SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanAmountQuery; use SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanOrEqualToAmountQuery; @@ -18,6 +16,9 @@ use SonsOfPHP\Component\Money\Query\Amount\IsNegativeAmountQuery; use SonsOfPHP\Component\Money\Query\Amount\IsPositiveAmountQuery; use SonsOfPHP\Component\Money\Query\Amount\IsZeroAmountQuery; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Currency.php b/src/SonsOfPHP/Component/Money/Currency.php index b384e1e1..470536db 100644 --- a/src/SonsOfPHP/Component/Money/Currency.php +++ b/src/SonsOfPHP/Component/Money/Currency.php @@ -4,8 +4,9 @@ namespace SonsOfPHP\Component\Money; -use SonsOfPHP\Component\Money\Query\Currency\CurrencyQueryInterface; use SonsOfPHP\Component\Money\Query\Currency\IsEqualToCurrencyQuery; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php b/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php index 87dbae0a..ca077e69 100644 --- a/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php +++ b/src/SonsOfPHP/Component/Money/CurrencyProvider/AbstractCurrencyProvider.php @@ -4,10 +4,11 @@ namespace SonsOfPHP\Component\Money\CurrencyProvider; -use SonsOfPHP\Component\Money\CurrencyInterface; -use SonsOfPHP\Component\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; use SonsOfPHP\Component\Money\Query\CurrencyProvider\GetCurrencyQuery; use SonsOfPHP\Component\Money\Query\CurrencyProvider\HasCurrencyQuery; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; +use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/CurrencyProvider/ChainCurrencyProvider.php b/src/SonsOfPHP/Component/Money/CurrencyProvider/ChainCurrencyProvider.php index 27179923..cbfa2172 100644 --- a/src/SonsOfPHP/Component/Money/CurrencyProvider/ChainCurrencyProvider.php +++ b/src/SonsOfPHP/Component/Money/CurrencyProvider/ChainCurrencyProvider.php @@ -4,6 +4,8 @@ namespace SonsOfPHP\Component\Money\CurrencyProvider; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; + /** * Chain Currency Provider. * diff --git a/src/SonsOfPHP/Component/Money/Exception/ArithmeticException.php b/src/SonsOfPHP/Component/Money/Exception/ArithmeticException.php index f929511b..1d227d81 100644 --- a/src/SonsOfPHP/Component/Money/Exception/ArithmeticException.php +++ b/src/SonsOfPHP/Component/Money/Exception/ArithmeticException.php @@ -4,7 +4,7 @@ namespace SonsOfPHP\Component\Money\Exception; -use Exception; +use SonsOfPHP\Contract\Money\Exception\ArithmeticExceptionInterface; /** * Arithmetic Exception. @@ -13,4 +13,4 @@ * * @author Joshua Estes */ -class ArithmeticException extends \Exception {} +class ArithmeticException extends \Exception implements ArithmeticExceptionInterface {} diff --git a/src/SonsOfPHP/Component/Money/Exception/MoneyException.php b/src/SonsOfPHP/Component/Money/Exception/MoneyException.php index 67ffac7d..523a4eb3 100644 --- a/src/SonsOfPHP/Component/Money/Exception/MoneyException.php +++ b/src/SonsOfPHP/Component/Money/Exception/MoneyException.php @@ -4,11 +4,11 @@ namespace SonsOfPHP\Component\Money\Exception; -use Exception; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; /** * Money Exception. * * @author Joshua Estes */ -class MoneyException extends \Exception {} +class MoneyException extends \Exception implements MoneyExceptionInterface {} diff --git a/src/SonsOfPHP/Component/Money/Exception/UnknownCurrencyException.php b/src/SonsOfPHP/Component/Money/Exception/UnknownCurrencyException.php index 51501995..28ce70d1 100644 --- a/src/SonsOfPHP/Component/Money/Exception/UnknownCurrencyException.php +++ b/src/SonsOfPHP/Component/Money/Exception/UnknownCurrencyException.php @@ -4,7 +4,9 @@ namespace SonsOfPHP\Component\Money\Exception; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; + /** * @author Joshua Estes */ -class UnknownCurrencyException extends \Exception {} +class UnknownCurrencyException extends \Exception implements MoneyExceptionInterface {} diff --git a/src/SonsOfPHP/Component/Money/Money.php b/src/SonsOfPHP/Component/Money/Money.php index 7fb8f243..b4e57beb 100644 --- a/src/SonsOfPHP/Component/Money/Money.php +++ b/src/SonsOfPHP/Component/Money/Money.php @@ -6,7 +6,6 @@ use SonsOfPHP\Component\Money\Operator\Money\AddMoneyOperator; use SonsOfPHP\Component\Money\Operator\Money\DivideMoneyOperator; -use SonsOfPHP\Component\Money\Operator\Money\MoneyOperatorInterface; use SonsOfPHP\Component\Money\Operator\Money\MultiplyMoneyOperator; use SonsOfPHP\Component\Money\Operator\Money\SubtractMoneyOperator; use SonsOfPHP\Component\Money\Query\Money\IsEqualToMoneyQuery; @@ -17,7 +16,11 @@ use SonsOfPHP\Component\Money\Query\Money\IsNegativeMoneyQuery; use SonsOfPHP\Component\Money\Query\Money\IsPositiveMoneyQuery; use SonsOfPHP\Component\Money\Query\Money\IsZeroMoneyQuery; -use SonsOfPHP\Component\Money\Query\Money\MoneyQueryInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php index 153c4148..2d5cbce2 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Amount/AddAmountOperator.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Operator\Amount; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php index c5b82ebd..689f59b3 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Amount/DivideAmountOperator.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Operator\Amount; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php index 217dafd6..70120c86 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Amount/MultiplyAmountOperator.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Operator\Amount; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php b/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php index 86de4083..7881fad3 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Amount/SubtractAmountOperator.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Operator\Amount; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php index 7682418c..9a54ccf1 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Money/AddMoneyOperator.php @@ -6,7 +6,8 @@ use SonsOfPHP\Component\Money\Exception\MoneyException; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php index fbb5c3af..224760c3 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Money/DivideMoneyOperator.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Operator\Money; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php index a0d57984..2e1d0302 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Money/MultiplyMoneyOperator.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Operator\Money; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php b/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php index e35ce0e1..5822b388 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php +++ b/src/SonsOfPHP/Component/Money/Operator/Money/SubtractMoneyOperator.php @@ -6,7 +6,8 @@ use SonsOfPHP\Component\Money\Exception\MoneyException; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/AmountQueryInterface.php b/src/SonsOfPHP/Component/Money/Query/Amount/AmountQueryInterface.php deleted file mode 100644 index 64d72009..00000000 --- a/src/SonsOfPHP/Component/Money/Query/Amount/AmountQueryInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -interface AmountQueryInterface extends QueryInterface -{ - /** - * @throws MoneyException - */ - public function queryFrom(AmountInterface $amount); -} diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php index 0ed67802..f6e86581 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsEqualToAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php index 83068f36..6fba3d12 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php index ce298398..15204625 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsGreaterThanOrEqualToAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php index d5e0740d..dee98c25 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php index ed393a86..c27ae797 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsLessThanOrEqualToAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php index 8ef5f27f..82fbf59f 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsNegativeAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php index 577603a1..d5d16881 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsPositiveAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php b/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php index 9c17f271..34baf643 100644 --- a/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Amount/IsZeroAmountQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Currency/CurrencyQueryInterface.php b/src/SonsOfPHP/Component/Money/Query/Currency/CurrencyQueryInterface.php deleted file mode 100644 index 94f73036..00000000 --- a/src/SonsOfPHP/Component/Money/Query/Currency/CurrencyQueryInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -interface CurrencyQueryInterface extends QueryInterface -{ - /** - * @throws MoneyException - */ - public function queryFrom(CurrencyInterface $currency); -} diff --git a/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php b/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php index 9cb1c1b2..94746b7a 100644 --- a/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Currency/IsEqualToCurrencyQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Currency; -use SonsOfPHP\Component\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php deleted file mode 100644 index 27f0e18e..00000000 --- a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -interface CurrencyProviderQueryInterface extends QueryInterface -{ - /** - * @throws MoneyException - */ - public function queryFrom(CurrencyProviderInterface $provider); -} diff --git a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php index b4b39ac0..6e978295 100644 --- a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/GetCurrencyQuery.php @@ -5,9 +5,10 @@ namespace SonsOfPHP\Component\Money\Query\CurrencyProvider; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\CurrencyInterface; -use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProviderInterface; use SonsOfPHP\Component\Money\Exception\MoneyException; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; +use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php index cf289917..1e4fbb1a 100644 --- a/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/CurrencyProvider/HasCurrencyQuery.php @@ -5,9 +5,10 @@ namespace SonsOfPHP\Component\Money\Query\CurrencyProvider; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\CurrencyInterface; -use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProviderInterface; use SonsOfPHP\Component\Money\Exception\MoneyException; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; +use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php index e5be0531..cd8334eb 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsEqualToMoneyQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php index b8f312ba..dd8ac01e 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanMoneyQuery.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php index d8f87449..76ea907d 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsGreaterThanOrEqualToMoneyQuery.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php index 09bd36d6..a79fc4ed 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanMoneyQuery.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php index 95748d0c..38f88b9b 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsLessThanOrEqualToMoneyQuery.php @@ -5,7 +5,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php index 7096b1a4..441e4602 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsNegativeMoneyQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php index 43cc9e52..b1597f44 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsPositiveMoneyQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php b/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php index 2f235f33..9d7f29d6 100644 --- a/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php +++ b/src/SonsOfPHP/Component/Money/Query/Money/IsZeroMoneyQuery.php @@ -4,7 +4,8 @@ namespace SonsOfPHP\Component\Money\Query\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Component/Money/Query/Money/MoneyQueryInterface.php b/src/SonsOfPHP/Component/Money/Query/Money/MoneyQueryInterface.php deleted file mode 100644 index afd22840..00000000 --- a/src/SonsOfPHP/Component/Money/Query/Money/MoneyQueryInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -interface MoneyQueryInterface extends QueryInterface -{ - /** - * @throws MoneyException - */ - public function queryFrom(MoneyInterface $money); -} diff --git a/src/SonsOfPHP/Component/Money/Query/QueryInterface.php b/src/SonsOfPHP/Component/Money/Query/QueryInterface.php deleted file mode 100644 index 50098562..00000000 --- a/src/SonsOfPHP/Component/Money/Query/QueryInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - - */ -interface QueryInterface -{ - /* - * All Query classes should define queryFrom - */ - // public function queryFrom(mixed $input); -} diff --git a/src/SonsOfPHP/Component/Money/Tests/AmountTest.php b/src/SonsOfPHP/Component/Money/Tests/AmountTest.php index df62570f..700bf28c 100644 --- a/src/SonsOfPHP/Component/Money/Tests/AmountTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/AmountTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\AmountInterface; +use SonsOfPHP\Contract\Money\AmountInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Amount diff --git a/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/ChainCurrencyProviderTest.php b/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/ChainCurrencyProviderTest.php index 1226c078..2d3f25e2 100644 --- a/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/ChainCurrencyProviderTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/ChainCurrencyProviderTest.php @@ -6,12 +6,12 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\CurrencyInterface; use SonsOfPHP\Component\Money\CurrencyProvider\ChainCurrencyProvider; use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProvider; -use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProviderInterface; use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider; -use SonsOfPHP\Component\Money\Exception\MoneyException; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\CurrencyProvider\ChainCurrencyProvider @@ -124,7 +124,7 @@ public function testHasCurrencyWithInvalidInput(): void new XCurrencyProvider(), ]); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $this->assertFalse($provider->hasCurrency('xxxxxx')); } @@ -173,7 +173,7 @@ public function testGetCurrencyWithUnknowCurrency(): void new XCurrencyProvider(), ]); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $provider->getCurrency('zzz'); } @@ -188,7 +188,7 @@ public function testGetCurrencyWithValueError(): void new XCurrencyProvider(), ]); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $provider->getCurrency('xxxxxxxx'); } } diff --git a/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/CurrencyProviderTest.php b/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/CurrencyProviderTest.php index 87da7fa2..0d450167 100644 --- a/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/CurrencyProviderTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/CurrencyProviderTest.php @@ -6,10 +6,10 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\CurrencyInterface; use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProvider; -use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProviderInterface; -use SonsOfPHP\Component\Money\Exception\MoneyException; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProvider @@ -91,7 +91,7 @@ public function testHasCurrencyWithInvalidInput(): void { $provider = new CurrencyProvider(); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $this->assertFalse($provider->hasCurrency('xxxxxx')); } @@ -131,7 +131,7 @@ public function testGetCurrencyWithUnknowCurrency(): void { $provider = new CurrencyProvider(); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $provider->getCurrency('xxx'); } @@ -143,7 +143,7 @@ public function testGetCurrencyWithValueError(): void { $provider = new CurrencyProvider(); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $provider->getCurrency('xxxxxxxx'); } } diff --git a/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/XCurrencyProviderTest.php b/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/XCurrencyProviderTest.php index 140b4f95..60e312b6 100644 --- a/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/XCurrencyProviderTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/CurrencyProvider/XCurrencyProviderTest.php @@ -5,9 +5,9 @@ namespace SonsOfPHP\Component\Money\Tests\CurrencyProvider; use PHPUnit\Framework\TestCase; -use SonsOfPHP\Component\Money\CurrencyInterface; -use SonsOfPHP\Component\Money\CurrencyProvider\CurrencyProviderInterface; use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider; +use SonsOfPHP\Contract\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyProviderInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider diff --git a/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php b/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php index c0ff7716..299e6ccc 100644 --- a/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/CurrencyTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\CurrencyInterface; +use SonsOfPHP\Contract\Money\CurrencyInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Currency diff --git a/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php b/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php index 1b84961c..8f8ab3ad 100644 --- a/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/MoneyTest.php @@ -6,9 +6,9 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\Exception\MoneyException; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Money @@ -143,7 +143,7 @@ public function testGreaterThanWithDifferentCurrencies(): void $money1 = Money::USD(100); $money2 = Money::EUR(100); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $money1->isGreaterThan($money2); } @@ -171,7 +171,7 @@ public function testGreaterThanOrEqualsWithDifferentCurrencies(): void $money1 = Money::USD(100); $money2 = Money::EUR(100); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $money1->isGreaterThanOrEqualTo($money2); } @@ -198,7 +198,7 @@ public function testLessThanWithDifferentCurrencies(): void $money1 = Money::USD(100); $money2 = Money::EUR(100); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $money1->isLessThan($money2); } @@ -226,7 +226,7 @@ public function testLessThanOrEqualsWithDifferentCurrencies(): void $money1 = Money::USD(100); $money2 = Money::EUR(100); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $money1->isLessThanOrEqualTo($money2); } @@ -297,7 +297,7 @@ public function testAddWithDifferenctCurrencies(): void $money1 = Money::USD(100); $money2 = Money::EUR(100); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $money1->add($money2); } @@ -323,7 +323,7 @@ public function testSubtractWithDifferenctCurrencies(): void $money1 = Money::USD(100); $money2 = Money::EUR(100); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $money1->subtract($money2); } diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php index 63f2aea6..b593eeed 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/AddAmountOperatorTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; use SonsOfPHP\Component\Money\Operator\Amount\AddAmountOperator; -use SonsOfPHP\Component\Money\Operator\Amount\AmountOperatorInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\AddAmountOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php index d6d3b01c..e143641e 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/DivideAmountOperatorTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Operator\Amount\AmountOperatorInterface; use SonsOfPHP\Component\Money\Operator\Amount\DivideAmountOperator; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\DivideAmountOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php index 5bf7fe67..21844e66 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/MultiplyAmountOperatorTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Operator\Amount\AmountOperatorInterface; use SonsOfPHP\Component\Money\Operator\Amount\MultiplyAmountOperator; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\MultiplyAmountOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php index 47914fe7..0f5cc314 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Amount/SubtractAmountOperatorTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Operator\Amount\AmountOperatorInterface; use SonsOfPHP\Component\Money\Operator\Amount\SubtractAmountOperator; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Amount\SubtractAmountOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php index adef34e9..e3f29f50 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/AddMoneyOperatorTest.php @@ -9,7 +9,7 @@ use SonsOfPHP\Component\Money\Exception\MoneyException; use SonsOfPHP\Component\Money\Money; use SonsOfPHP\Component\Money\Operator\Money\AddMoneyOperator; -use SonsOfPHP\Component\Money\Operator\Money\MoneyOperatorInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\AddMoneyOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php index 2b58087c..7948d979 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/DivideMoneyOperatorTest.php @@ -8,7 +8,7 @@ use SonsOfPHP\Component\Money\Currency; use SonsOfPHP\Component\Money\Money; use SonsOfPHP\Component\Money\Operator\Money\DivideMoneyOperator; -use SonsOfPHP\Component\Money\Operator\Money\MoneyOperatorInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\DivideMoneyOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php index 23807632..4ca68b93 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/MultiplyMoneyOperatorTest.php @@ -7,8 +7,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\Operator\Money\MoneyOperatorInterface; use SonsOfPHP\Component\Money\Operator\Money\MultiplyMoneyOperator; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\MultiplyMoneyOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php index 9eff15d2..5bbc6b9a 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Operator/Money/SubtractMoneyOperatorTest.php @@ -8,8 +8,8 @@ use SonsOfPHP\Component\Money\Currency; use SonsOfPHP\Component\Money\Exception\MoneyException; use SonsOfPHP\Component\Money\Money; -use SonsOfPHP\Component\Money\Operator\Money\MoneyOperatorInterface; use SonsOfPHP\Component\Money\Operator\Money\SubtractMoneyOperator; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Operator\Money\SubtractMoneyOperator diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php index cc246051..669e8a85 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsEqualToAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsEqualToAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsEqualToAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php index 199d3f94..fc17a297 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php index ff30813b..c975fe43 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsGreaterThanOrEqualToAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanOrEqualToAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsGreaterThanOrEqualToAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php index a563774c..1318ed67 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsLessThanAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsLessThanAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php index eaed30d4..6f422fc4 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsLessThanOrEqualToAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsLessThanOrEqualToAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsLessThanOrEqualToAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php index c0328815..f5ed3247 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsNegativeAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsNegativeAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsNegativeAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php index 0074a75b..28944e8e 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsPositiveAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsPositiveAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsPositiveAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php index 75f4cd1a..87e66965 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Amount/IsZeroAmountQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Amount; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; use SonsOfPHP\Component\Money\Query\Amount\IsZeroAmountQuery; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Amount\IsZeroAmountQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php index badb655c..055424b6 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Currency/IsEqualToCurrencyQueryTest.php @@ -6,8 +6,8 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; -use SonsOfPHP\Component\Money\Query\Currency\CurrencyQueryInterface; use SonsOfPHP\Component\Money\Query\Currency\IsEqualToCurrencyQuery; +use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\Currency\IsEqualToCurrencyQuery diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php index 08d14e5c..31ca2e67 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/GetCurrencyQueryTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider; -use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; use SonsOfPHP\Component\Money\Query\CurrencyProvider\GetCurrencyQuery; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; +use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\CurrencyProvider\GetCurrencyQuery @@ -64,7 +64,7 @@ public function testConstructWithCurrencyString(): void */ public function testConstructWithInvalidValue(): void { - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $query = new GetCurrencyQuery('1234'); } @@ -75,7 +75,7 @@ public function testQueryFromWillThrowExceptionWhenCurrencyNotFound(): void { $query = new GetCurrencyQuery('usd'); - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $output = $query->queryFrom(new XCurrencyProvider()); } } diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php index 842d99d2..9c2681d2 100644 --- a/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php +++ b/src/SonsOfPHP/Component/Money/Tests/Query/CurrencyProvider/HasCurrencyQueryTest.php @@ -7,9 +7,9 @@ use PHPUnit\Framework\TestCase; use SonsOfPHP\Component\Money\Currency; use SonsOfPHP\Component\Money\CurrencyProvider\XCurrencyProvider; -use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; use SonsOfPHP\Component\Money\Query\CurrencyProvider\HasCurrencyQuery; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; +use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; /** * @coversDefaultClass \SonsOfPHP\Component\Money\Query\CurrencyProvider\HasCurrencyQuery @@ -64,7 +64,7 @@ public function testConstructWithCurrencyString(): void */ public function testConstructWithInvalidValue(): void { - $this->expectException(MoneyException::class); + $this->expectException(MoneyExceptionInterface::class); $query = new HasCurrencyQuery('1234'); } diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php new file mode 100644 index 00000000..b1ca02df --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsEqualToMoneyQueryTest.php @@ -0,0 +1,44 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsEqualToMoneyQuery(new Money(100, Currency::USD())); + + $this->assertTrue($query->queryFrom(new Money(100, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php new file mode 100644 index 00000000..4df2f9de --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanMoneyQueryTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsGreaterThanMoneyQuery(new Money(100, Currency::USD())); + + $this->assertTrue($query->queryFrom(new Money(200, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php new file mode 100644 index 00000000..674fdaaf --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsGreaterThanOrEqualToMoneyQueryTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsGreaterThanOrEqualToMoneyQuery(new Money(100, Currency::USD())); + + $this->assertTrue($query->queryFrom(new Money(2000, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php new file mode 100644 index 00000000..196d6fec --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanMoneyQueryTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsLessThanMoneyQuery(new Money(100, Currency::USD())); + + $this->assertTrue($query->queryFrom(new Money(50, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php new file mode 100644 index 00000000..59f3ad0e --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsLessThanOrEqualToMoneyQueryTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsLessThanOrEqualToMoneyQuery(new Money(100, Currency::USD())); + + $this->assertTrue($query->queryFrom(new Money(10, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php new file mode 100644 index 00000000..d2b6fbda --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsNegativeMoneyQueryTest.php @@ -0,0 +1,43 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsNegativeMoneyQuery(); + + $this->assertTrue($query->queryFrom(new Money(-10, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php new file mode 100644 index 00000000..8f9ee2e0 --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsPositiveMoneyQueryTest.php @@ -0,0 +1,43 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsPositiveMoneyQuery(); + + $this->assertTrue($query->queryFrom(new Money(10, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php new file mode 100644 index 00000000..cd7f8991 --- /dev/null +++ b/src/SonsOfPHP/Component/Money/Tests/Query/Money/IsZeroMoneyQueryTest.php @@ -0,0 +1,43 @@ +assertInstanceOf(MoneyQueryInterface::class, $query); + } + + /** + * @covers ::queryFrom + */ + public function testQuery(): void + { + $query = new IsZeroMoneyQuery(); + + $this->assertTrue($query->queryFrom(new Money(0, Currency::USD()))); + } +} diff --git a/src/SonsOfPHP/Component/Money/composer.json b/src/SonsOfPHP/Component/Money/composer.json index 4ad74183..8e8e44d9 100644 --- a/src/SonsOfPHP/Component/Money/composer.json +++ b/src/SonsOfPHP/Component/Money/composer.json @@ -32,7 +32,11 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.1", + "sonsofphp/money-contract": "0.3.x-dev" + }, + "provide": { + "sonsofphp/money-implementation": "0.3.x-dev" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Component/Version/composer.json b/src/SonsOfPHP/Component/Version/composer.json index 4dc1a71f..cfe72c9e 100644 --- a/src/SonsOfPHP/Component/Version/composer.json +++ b/src/SonsOfPHP/Component/Version/composer.json @@ -30,7 +30,11 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=8.1" + "php": ">=8.1", + "sonsofphp/version-contract": "0.3.x-dev" + }, + "provide": { + "sonsofphp/version-implementation": "0.3.x-dev" }, "extra": { "sort-packages": true, diff --git a/src/SonsOfPHP/Contract/Core/.gitattributes b/src/SonsOfPHP/Contract/Common/.gitattributes similarity index 100% rename from src/SonsOfPHP/Contract/Core/.gitattributes rename to src/SonsOfPHP/Contract/Common/.gitattributes diff --git a/src/SonsOfPHP/Contract/Core/.gitignore b/src/SonsOfPHP/Contract/Common/.gitignore similarity index 100% rename from src/SonsOfPHP/Contract/Core/.gitignore rename to src/SonsOfPHP/Contract/Common/.gitignore diff --git a/src/SonsOfPHP/Contract/Common/ArrayableInterface.php b/src/SonsOfPHP/Contract/Common/ArrayableInterface.php new file mode 100644 index 00000000..1771476a --- /dev/null +++ b/src/SonsOfPHP/Contract/Common/ArrayableInterface.php @@ -0,0 +1,15 @@ + + */ +interface ArrayableInterface +{ + /** + */ + public function toArray(): array; +} diff --git a/src/SonsOfPHP/Contract/Core/ComparableInterface.php b/src/SonsOfPHP/Contract/Common/ComparableInterface.php similarity index 91% rename from src/SonsOfPHP/Contract/Core/ComparableInterface.php rename to src/SonsOfPHP/Contract/Common/ComparableInterface.php index c28e2ffe..a3e4811a 100644 --- a/src/SonsOfPHP/Contract/Core/ComparableInterface.php +++ b/src/SonsOfPHP/Contract/Common/ComparableInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Contract\Core; +namespace SonsOfPHP\Contract\Common; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Contract/Core/EquatableInterface.php b/src/SonsOfPHP/Contract/Common/EquatableInterface.php similarity index 95% rename from src/SonsOfPHP/Contract/Core/EquatableInterface.php rename to src/SonsOfPHP/Contract/Common/EquatableInterface.php index 295eb59a..c171bca9 100644 --- a/src/SonsOfPHP/Contract/Core/EquatableInterface.php +++ b/src/SonsOfPHP/Contract/Common/EquatableInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Contract\Core; +namespace SonsOfPHP\Contract\Common; /** * Equatable Interface is used for objects that can be checked to see if they diff --git a/src/SonsOfPHP/Contract/Common/JsonableInterface.php b/src/SonsOfPHP/Contract/Common/JsonableInterface.php new file mode 100644 index 00000000..431c4203 --- /dev/null +++ b/src/SonsOfPHP/Contract/Common/JsonableInterface.php @@ -0,0 +1,18 @@ + + */ +interface JsonableInterface +{ + /** + * Returns a json string of the object + * + * @see https://www.php.net/json_encode + */ + public function toJson(int $flags = 0, int $depth = 512): string; +} diff --git a/src/SonsOfPHP/Contract/Core/LICENSE b/src/SonsOfPHP/Contract/Common/LICENSE similarity index 100% rename from src/SonsOfPHP/Contract/Core/LICENSE rename to src/SonsOfPHP/Contract/Common/LICENSE diff --git a/src/SonsOfPHP/Contract/Core/README.md b/src/SonsOfPHP/Contract/Common/README.md similarity index 77% rename from src/SonsOfPHP/Contract/Core/README.md rename to src/SonsOfPHP/Contract/Common/README.md index 9f91994c..b27823ec 100644 --- a/src/SonsOfPHP/Contract/Core/README.md +++ b/src/SonsOfPHP/Contract/Common/README.md @@ -1,7 +1,7 @@ -Sons of PHP - Core Contract -=========================== +Sons of PHP - Common Contract +============================= -Core Contracts include very generic interfaces that can be used across many +Common Contracts include very generic interfaces that can be used across many different libraries. These would be the missing PHP interfaces that would be helpful. @@ -16,5 +16,5 @@ helpful. [mother-repo]: https://github.com/SonsOfPHP/sonsofphp [contributing]: https://docs.sonsofphp.com/contributing/ [docs]: https://docs.sonsofphp.com/components/http-message/ -[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ACore -[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ACore +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ACommon +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ACommon diff --git a/src/SonsOfPHP/Contract/Core/composer.json b/src/SonsOfPHP/Contract/Common/composer.json similarity index 78% rename from src/SonsOfPHP/Contract/Core/composer.json rename to src/SonsOfPHP/Contract/Common/composer.json index f8626186..9fcbe5dc 100644 --- a/src/SonsOfPHP/Contract/Core/composer.json +++ b/src/SonsOfPHP/Contract/Common/composer.json @@ -1,7 +1,7 @@ { - "name": "sonsofphp/core-contract", + "name": "sonsofphp/common-contract", "type": "library", - "description": "Core Contracts that are not specific to any one library", + "description": "Common Contracts that are not specific to any one library", "keywords": [ "abstractions", "contracts", @@ -10,7 +10,7 @@ "interoperability", "standards" ], - "homepage": "https://github.com/SonsOfPHP/core-contract", + "homepage": "https://github.com/SonsOfPHP/common-contract", "license": "MIT", "authors": [ { @@ -25,11 +25,8 @@ }, "autoload": { "psr-4": { - "SonsOfPHP\\Contract\\Core\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + "SonsOfPHP\\Contract\\Common\\": "" + } }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/src/SonsOfPHP/Contract/Cqrs/.gitattributes b/src/SonsOfPHP/Contract/Cqrs/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/Cqrs/.gitignore b/src/SonsOfPHP/Contract/Cqrs/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/Cqrs/CommandBusInterface.php b/src/SonsOfPHP/Contract/Cqrs/CommandBusInterface.php new file mode 100644 index 00000000..bef1755a --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/CommandBusInterface.php @@ -0,0 +1,23 @@ + + */ +interface CommandBusInterface +{ + /** + * A command will never return any data. It can be handled syncrhonously or + * asyncrhonously. + * + * @throws \SonsOfPHP\Contract\Cqrs\Exception\NoHandlerExceptionInterface + * Exception is thrown if there is no handler for the given command + * + * @throws \SonsOfPHP\Contract\Cqrs\Exception\CqrsExceptionInterface + * If something fucks up, this will be thrown + */ + public function dispatch(object $command): void; +} diff --git a/src/SonsOfPHP/Component/Cqrs/Command/CommandMessageHandlerInterface.php b/src/SonsOfPHP/Contract/Cqrs/CommandMessageHandlerInterface.php similarity index 56% rename from src/SonsOfPHP/Component/Cqrs/Command/CommandMessageHandlerInterface.php rename to src/SonsOfPHP/Contract/Cqrs/CommandMessageHandlerInterface.php index 4fa7b7f5..a896b956 100644 --- a/src/SonsOfPHP/Component/Cqrs/Command/CommandMessageHandlerInterface.php +++ b/src/SonsOfPHP/Contract/Cqrs/CommandMessageHandlerInterface.php @@ -2,11 +2,12 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Cqrs\Command; - -use SonsOfPHP\Component\Cqrs\MessageHandlerInterface; +namespace SonsOfPHP\Contract\Cqrs; /** * @author Joshua Estes */ -interface CommandMessageHandlerInterface extends MessageHandlerInterface {} +interface CommandMessageHandlerInterface extends MessageHandlerInterface +{ + //public function __invoke(CommandMessageInterface $message): void; +} diff --git a/src/SonsOfPHP/Component/Cqrs/Command/CommandMessageInterface.php b/src/SonsOfPHP/Contract/Cqrs/CommandMessageInterface.php similarity index 62% rename from src/SonsOfPHP/Component/Cqrs/Command/CommandMessageInterface.php rename to src/SonsOfPHP/Contract/Cqrs/CommandMessageInterface.php index 4e5aa504..67807bd8 100644 --- a/src/SonsOfPHP/Component/Cqrs/Command/CommandMessageInterface.php +++ b/src/SonsOfPHP/Contract/Cqrs/CommandMessageInterface.php @@ -2,9 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Cqrs\Command; - -use SonsOfPHP\Component\Cqrs\MessageInterface; +namespace SonsOfPHP\Contract\Cqrs; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Contract/Cqrs/Exception/CqrsExceptionInterface.php b/src/SonsOfPHP/Contract/Cqrs/Exception/CqrsExceptionInterface.php new file mode 100644 index 00000000..2e1c8e6f --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/Exception/CqrsExceptionInterface.php @@ -0,0 +1,12 @@ + + */ +interface CqrsExceptionInterface {} diff --git a/src/SonsOfPHP/Contract/Cqrs/Exception/NoHandlerFoundExceptionInterface.php b/src/SonsOfPHP/Contract/Cqrs/Exception/NoHandlerFoundExceptionInterface.php new file mode 100644 index 00000000..8c014242 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/Exception/NoHandlerFoundExceptionInterface.php @@ -0,0 +1,13 @@ + + */ +interface NoHandlerFoundExceptionInterface extends CqrsExceptionInterface {} diff --git a/src/SonsOfPHP/Contract/Cqrs/LICENSE b/src/SonsOfPHP/Contract/Cqrs/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/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/Contract/Cqrs/MessageHandlerProviderInterface.php b/src/SonsOfPHP/Contract/Cqrs/MessageHandlerProviderInterface.php new file mode 100644 index 00000000..ccfdd1c4 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/MessageHandlerProviderInterface.php @@ -0,0 +1,28 @@ + + */ +interface MessageHandlerProviderInterface +{ + /** + * Returns the handler for a given object + * + * Message is the Message that needs to be handled. This can either + * be the message class name or the message object + * + * @throws \SonsOfPHP\Contract\Cqrs\Exception\NoHandlerExceptionInterface + * When no handler is available for the message + * + * Usage: + * $msg = new CreateUser(); + * $handler = $provider->getHandlerForMessage($msg); + * --- + * $handler = $provider->getHandlerForMessage(CreateUser::class); + */ + public function getHandlerForMessage(string|object $message): callable; +} diff --git a/src/SonsOfPHP/Contract/Cqrs/MessageInterface.php b/src/SonsOfPHP/Contract/Cqrs/MessageInterface.php new file mode 100644 index 00000000..fb35ac9a --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/MessageInterface.php @@ -0,0 +1,66 @@ + + */ +interface MessageInterface +{ + /** + * Adds a new value for a given key. + * + * If a value already exists, this will overwrite that value. + * + * If the value for key exists, and the values are equal, this should + * not return a new object. + * + * If the $key is an array, it should be a key => value array and will overwrite + * all the existing values + * + * @param mixed $value + * - If an object is passed in, it must be able to be converted to a + * string. If it's unable to be converted to string, an exception + * is thrown. + * + * @throws \InvalidArgumentException + * - If the given key or value is invalid + * + * Examples: + * $message = $message->with('user_id', 42); + * $message = $message->with([ + * 'user_id' => 42, + * 'account_id' => 2131, + * ]); + */ + public function with(string|array $key, mixed $value = null): static; + + /** + * Returns the value stored for a given key. + * + * If no key is passed in or if null is passed in, it will return + * all the values + * + * @throws \SonsOfPHP\Contract\Cqrs\Exception\CqrsExceptionInterface + * - If the given key is not part of this message + * + * Examples: + * $userId = $message->get('user_id'); + * $payload = $message->get(); + */ + public function get(?string $key = null): mixed; +} diff --git a/src/SonsOfPHP/Contract/Cqrs/QueryBusInterface.php b/src/SonsOfPHP/Contract/Cqrs/QueryBusInterface.php new file mode 100644 index 00000000..03d98336 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/QueryBusInterface.php @@ -0,0 +1,17 @@ + + */ +interface QueryBusInterface +{ + /** + * @throws \SonsOfPHP\Contract\Cqrs\Exception\NoHandlerExceptionInterface + * @throws \SonsOfPHP\Contract\Cqrs\Exception\CqrsExceptionInterface + */ + public function handle(QueryMessageInterface $query): mixed; +} diff --git a/src/SonsOfPHP/Contract/Cqrs/QueryMessageHandlerInterface.php b/src/SonsOfPHP/Contract/Cqrs/QueryMessageHandlerInterface.php new file mode 100644 index 00000000..fba60f67 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/QueryMessageHandlerInterface.php @@ -0,0 +1,18 @@ + + */ +interface QueryMessageHandlerInterface extends MessageHandlerInterface +{ + /** + * @throws \SonsOfPHP\Contract\Cqrs\Exception\CqrsExceptionInterface + * When something really fucks up and the handler is unable to handle + * it's shit + */ + public function __invoke(QueryMessageInterface $message): mixed; +} diff --git a/src/SonsOfPHP/Component/Cqrs/Query/QueryMessageInterface.php b/src/SonsOfPHP/Contract/Cqrs/QueryMessageInterface.php similarity index 62% rename from src/SonsOfPHP/Component/Cqrs/Query/QueryMessageInterface.php rename to src/SonsOfPHP/Contract/Cqrs/QueryMessageInterface.php index 4381f434..5ccdfeb4 100644 --- a/src/SonsOfPHP/Component/Cqrs/Query/QueryMessageInterface.php +++ b/src/SonsOfPHP/Contract/Cqrs/QueryMessageInterface.php @@ -2,9 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Cqrs\Query; - -use SonsOfPHP\Component\Cqrs\MessageInterface; +namespace SonsOfPHP\Contract\Cqrs; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Contract/Cqrs/README.md b/src/SonsOfPHP/Contract/Cqrs/README.md new file mode 100644 index 00000000..dfdabe92 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/README.md @@ -0,0 +1,16 @@ +Sons of PHP - CQRS Contract +=========================== + +## 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/contracts/cqrs/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3ACqrs +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3ACqrs diff --git a/src/SonsOfPHP/Contract/Cqrs/composer.json b/src/SonsOfPHP/Contract/Cqrs/composer.json new file mode 100644 index 00000000..fec7bbd4 --- /dev/null +++ b/src/SonsOfPHP/Contract/Cqrs/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/cqrs-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/cqrs-contract", + "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" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\Cqrs\\": "" + } + }, + "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" + } + ] +} \ No newline at end of file diff --git a/src/SonsOfPHP/Contract/EventSourcing/.gitattributes b/src/SonsOfPHP/Contract/EventSourcing/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/EventSourcing/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/EventSourcing/.gitignore b/src/SonsOfPHP/Contract/EventSourcing/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/EventSourcing/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/EventSourcing/LICENSE b/src/SonsOfPHP/Contract/EventSourcing/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/EventSourcing/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/Contract/EventSourcing/README.md b/src/SonsOfPHP/Contract/EventSourcing/README.md new file mode 100644 index 00000000..7ab66b11 --- /dev/null +++ b/src/SonsOfPHP/Contract/EventSourcing/README.md @@ -0,0 +1,16 @@ +Sons of PHP - Event Sourcing Contract +===================================== + +## 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/contracts/event-sourcing/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AEventSourcing +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AEventSourcing diff --git a/src/SonsOfPHP/Contract/EventSourcing/composer.json b/src/SonsOfPHP/Contract/EventSourcing/composer.json new file mode 100644 index 00000000..e800175c --- /dev/null +++ b/src/SonsOfPHP/Contract/EventSourcing/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/event-sourcing-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/event-sourcing-contract", + "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" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\EventSourcing\\": "" + } + }, + "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" + } + ] +} \ No newline at end of file diff --git a/src/SonsOfPHP/Contract/FeatureToggle/.gitattributes b/src/SonsOfPHP/Contract/FeatureToggle/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/FeatureToggle/.gitignore b/src/SonsOfPHP/Contract/FeatureToggle/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/FeatureToggle/ContextInterface.php b/src/SonsOfPHP/Contract/FeatureToggle/ContextInterface.php new file mode 100644 index 00000000..14e44063 --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/ContextInterface.php @@ -0,0 +1,41 @@ + + */ +interface ContextInterface // extends \ArrayAccess, \IteratorAggregate, \JsonSerializable +{ + /** + * Get Context Parameters + * + * If the key does not exist, the $default should be returned + * + * @throws \InvalidArgumentException if key or default is invalid + */ + public function get(string $key, mixed $default = null); + + /** + * @throws \InvalidArgumentException if key or value is invalid + */ + public function set(string $key, mixed $value): self; + + /** + * If Context is a value object, with should be used instead. + * + * If key and value are the same, no need to clone, just return the same + * object as nothing has changed + * + * @throws \InvalidArgumentException if key or value is invalid + */ + //public function with(array|string $key, mixed $value = null): static; + + /** + */ + public function has(string $key): bool; +} diff --git a/src/SonsOfPHP/Contract/FeatureToggle/Exception/FeatureToggleExceptionInterface.php b/src/SonsOfPHP/Contract/FeatureToggle/Exception/FeatureToggleExceptionInterface.php new file mode 100644 index 00000000..ee18cef0 --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/Exception/FeatureToggleExceptionInterface.php @@ -0,0 +1,10 @@ + + */ +interface FeatureToggleExceptionInterface {} diff --git a/src/SonsOfPHP/Component/FeatureToggle/FeatureInterface.php b/src/SonsOfPHP/Contract/FeatureToggle/FeatureInterface.php similarity index 90% rename from src/SonsOfPHP/Component/FeatureToggle/FeatureInterface.php rename to src/SonsOfPHP/Contract/FeatureToggle/FeatureInterface.php index c3a8ce2a..05add3fd 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/FeatureInterface.php +++ b/src/SonsOfPHP/Contract/FeatureToggle/FeatureInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\FeatureToggle; +namespace SonsOfPHP\Contract\FeatureToggle; /** * Feature Interface. diff --git a/src/SonsOfPHP/Component/FeatureToggle/Provider/FeatureToggleProviderInterface.php b/src/SonsOfPHP/Contract/FeatureToggle/FeatureToggleProviderInterface.php similarity index 77% rename from src/SonsOfPHP/Component/FeatureToggle/Provider/FeatureToggleProviderInterface.php rename to src/SonsOfPHP/Contract/FeatureToggle/FeatureToggleProviderInterface.php index afbed491..fe361aee 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/Provider/FeatureToggleProviderInterface.php +++ b/src/SonsOfPHP/Contract/FeatureToggle/FeatureToggleProviderInterface.php @@ -2,9 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\FeatureToggle\Provider; - -use SonsOfPHP\Component\FeatureToggle\FeatureInterface; +namespace SonsOfPHP\Contract\FeatureToggle; /** * Feature Toggle Provider Interface. diff --git a/src/SonsOfPHP/Contract/FeatureToggle/LICENSE b/src/SonsOfPHP/Contract/FeatureToggle/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/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/Contract/FeatureToggle/README.md b/src/SonsOfPHP/Contract/FeatureToggle/README.md new file mode 100644 index 00000000..f6b6297c --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/README.md @@ -0,0 +1,16 @@ +Sons of PHP - Feature Toggle Contract +===================================== + +## 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/contracts/feature-toggle/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AFeatureToggle +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AFeatureToggle diff --git a/src/SonsOfPHP/Component/FeatureToggle/ToggleInterface.php b/src/SonsOfPHP/Contract/FeatureToggle/ToggleInterface.php similarity index 85% rename from src/SonsOfPHP/Component/FeatureToggle/ToggleInterface.php rename to src/SonsOfPHP/Contract/FeatureToggle/ToggleInterface.php index 5ca4d68f..bf26fd85 100644 --- a/src/SonsOfPHP/Component/FeatureToggle/ToggleInterface.php +++ b/src/SonsOfPHP/Contract/FeatureToggle/ToggleInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\FeatureToggle; +namespace SonsOfPHP\Contract\FeatureToggle; /** * @author Joshua Estes diff --git a/src/SonsOfPHP/Contract/FeatureToggle/composer.json b/src/SonsOfPHP/Contract/FeatureToggle/composer.json new file mode 100644 index 00000000..9a31921f --- /dev/null +++ b/src/SonsOfPHP/Contract/FeatureToggle/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/feature-toggle-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/feature-toggle-contract", + "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" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\FeatureToggle\\": "" + } + }, + "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" + } + ] +} \ No newline at end of file diff --git a/src/SonsOfPHP/Contract/Filesystem/.gitattributes b/src/SonsOfPHP/Contract/Filesystem/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/Filesystem/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/Filesystem/.gitignore b/src/SonsOfPHP/Contract/Filesystem/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/Filesystem/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/Filesystem/LICENSE b/src/SonsOfPHP/Contract/Filesystem/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/Filesystem/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/Contract/Filesystem/README.md b/src/SonsOfPHP/Contract/Filesystem/README.md new file mode 100644 index 00000000..f0fe3bf8 --- /dev/null +++ b/src/SonsOfPHP/Contract/Filesystem/README.md @@ -0,0 +1,16 @@ +Sons of PHP - Filesystem Contract +================================= + +## 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/contracts/filesystem/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AFilesystem +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AFilesystem diff --git a/src/SonsOfPHP/Contract/Filesystem/composer.json b/src/SonsOfPHP/Contract/Filesystem/composer.json new file mode 100644 index 00000000..a0540438 --- /dev/null +++ b/src/SonsOfPHP/Contract/Filesystem/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/filesystem-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/filesystem-contract", + "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" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\Filesystem\\": "" + } + }, + "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" + } + ] +} \ No newline at end of file diff --git a/src/SonsOfPHP/Contract/Money/.gitattributes b/src/SonsOfPHP/Contract/Money/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/Money/.gitignore b/src/SonsOfPHP/Contract/Money/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Component/Money/AmountInterface.php b/src/SonsOfPHP/Contract/Money/AmountInterface.php similarity index 92% rename from src/SonsOfPHP/Component/Money/AmountInterface.php rename to src/SonsOfPHP/Contract/Money/AmountInterface.php index 2d590862..f5f7a456 100644 --- a/src/SonsOfPHP/Component/Money/AmountInterface.php +++ b/src/SonsOfPHP/Contract/Money/AmountInterface.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Money; +namespace SonsOfPHP\Contract\Money; -use SonsOfPHP\Component\Money\Operator\Amount\AmountOperatorInterface; -use SonsOfPHP\Component\Money\Query\Amount\AmountQueryInterface; +use SonsOfPHP\Contract\Money\Operator\Amount\AmountOperatorInterface; +use SonsOfPHP\Contract\Money\Query\Amount\AmountQueryInterface; /** * Amount. diff --git a/src/SonsOfPHP/Component/Money/CurrencyInterface.php b/src/SonsOfPHP/Contract/Money/CurrencyInterface.php similarity index 91% rename from src/SonsOfPHP/Component/Money/CurrencyInterface.php rename to src/SonsOfPHP/Contract/Money/CurrencyInterface.php index c89ddbb9..c1d55275 100644 --- a/src/SonsOfPHP/Component/Money/CurrencyInterface.php +++ b/src/SonsOfPHP/Contract/Money/CurrencyInterface.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Money; +namespace SonsOfPHP\Contract\Money; -use SonsOfPHP\Component\Money\Query\Currency\CurrencyQueryInterface; +use SonsOfPHP\Contract\Money\Query\Currency\CurrencyQueryInterface; /** * Currency Interface. diff --git a/src/SonsOfPHP/Component/Money/CurrencyProvider/CurrencyProviderInterface.php b/src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php similarity index 64% rename from src/SonsOfPHP/Component/Money/CurrencyProvider/CurrencyProviderInterface.php rename to src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php index cd09bc9c..d3684399 100644 --- a/src/SonsOfPHP/Component/Money/CurrencyProvider/CurrencyProviderInterface.php +++ b/src/SonsOfPHP/Contract/Money/CurrencyProviderInterface.php @@ -2,12 +2,10 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Money\CurrencyProvider; +namespace SonsOfPHP\Contract\Money; -use SonsOfPHP\Component\Money\CurrencyInterface; -use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\Exception\UnknownCurrencyException; -use SonsOfPHP\Component\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; +use SonsOfPHP\Contract\Money\Query\CurrencyProvider\CurrencyProviderQueryInterface; /** * Currency Provider. @@ -19,8 +17,9 @@ interface CurrencyProviderInterface /** * Returns all of the currencies this Currency Provide will provide. * - * @throw MoneyException This method may throw an exception if, for example it's making queries - * to a database, if it's unable to return any currencies + * @throw MoneyExceptionInterface + * This method may throw an exception if, for example it's making queries + * to a database, if it's unable to return any currencies * * @return CurrencyInterface[] */ @@ -35,7 +34,7 @@ public function getCurrencies(): iterable; * @throw MoneyException * @throw UnknownCurrencyException */ - public function hasCurrency($currency): bool; + public function hasCurrency(CurrencyInterface|string $currency): bool; /** * Returns the currency or thows MoneyException is currency does not @@ -46,7 +45,7 @@ public function hasCurrency($currency): bool; * @throw MoneyException * @throw UnknownCurrencyException */ - public function getCurrency($currency): CurrencyInterface; + public function getCurrency(CurrencyInterface|string $currency): CurrencyInterface; /** * In case you need to run your own queries against this provider the query diff --git a/src/SonsOfPHP/Contract/Money/Exception/ArithmeticExceptionInterface.php b/src/SonsOfPHP/Contract/Money/Exception/ArithmeticExceptionInterface.php new file mode 100644 index 00000000..19237aaf --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Exception/ArithmeticExceptionInterface.php @@ -0,0 +1,14 @@ + + */ +interface ArithmeticExceptionInterface extends MoneyExceptionInterface {} diff --git a/src/SonsOfPHP/Contract/Money/Exception/MoneyExceptionInterface.php b/src/SonsOfPHP/Contract/Money/Exception/MoneyExceptionInterface.php new file mode 100644 index 00000000..63ff1041 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Exception/MoneyExceptionInterface.php @@ -0,0 +1,12 @@ + + */ +interface MoneyExceptionInterface {} diff --git a/src/SonsOfPHP/Contract/Money/Exception/UnknownCurrencyExceptionInterface.php b/src/SonsOfPHP/Contract/Money/Exception/UnknownCurrencyExceptionInterface.php new file mode 100644 index 00000000..b287b2d4 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Exception/UnknownCurrencyExceptionInterface.php @@ -0,0 +1,10 @@ + + */ +interface UnknownCurrencyExceptionInterface extends MoneyExceptionInterface {} diff --git a/src/SonsOfPHP/Contract/Money/LICENSE b/src/SonsOfPHP/Contract/Money/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/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/Money/MoneyInterface.php b/src/SonsOfPHP/Contract/Money/MoneyInterface.php similarity index 90% rename from src/SonsOfPHP/Component/Money/MoneyInterface.php rename to src/SonsOfPHP/Contract/Money/MoneyInterface.php index a4881a01..70f3ebfb 100644 --- a/src/SonsOfPHP/Component/Money/MoneyInterface.php +++ b/src/SonsOfPHP/Contract/Money/MoneyInterface.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Money; +namespace SonsOfPHP\Contract\Money; -use SonsOfPHP\Component\Money\Operator\Money\MoneyOperatorInterface; -use SonsOfPHP\Component\Money\Query\Money\MoneyQueryInterface; +use SonsOfPHP\Contract\Money\Operator\Money\MoneyOperatorInterface; +use SonsOfPHP\Contract\Money\Query\Money\MoneyQueryInterface; /** * Money Interface. diff --git a/src/SonsOfPHP/Component/Money/Operator/Amount/AmountOperatorInterface.php b/src/SonsOfPHP/Contract/Money/Operator/Amount/AmountOperatorInterface.php similarity index 51% rename from src/SonsOfPHP/Component/Money/Operator/Amount/AmountOperatorInterface.php rename to src/SonsOfPHP/Contract/Money/Operator/Amount/AmountOperatorInterface.php index ed5f0ecd..be298f24 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Amount/AmountOperatorInterface.php +++ b/src/SonsOfPHP/Contract/Money/Operator/Amount/AmountOperatorInterface.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Money\Operator\Amount; +namespace SonsOfPHP\Contract\Money\Operator\Amount; -use SonsOfPHP\Component\Money\AmountInterface; -use SonsOfPHP\Component\Money\Exception\MoneyException; +use SonsOfPHP\Contract\Money\AmountInterface; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; /** * @author Joshua Estes @@ -13,7 +13,7 @@ interface AmountOperatorInterface { /** - * @throws MoneyException + * @throws MoneyExceptionInterface */ public function apply(AmountInterface $amount): AmountInterface; } diff --git a/src/SonsOfPHP/Component/Money/Operator/Money/MoneyOperatorInterface.php b/src/SonsOfPHP/Contract/Money/Operator/Money/MoneyOperatorInterface.php similarity index 51% rename from src/SonsOfPHP/Component/Money/Operator/Money/MoneyOperatorInterface.php rename to src/SonsOfPHP/Contract/Money/Operator/Money/MoneyOperatorInterface.php index bc62a726..df17d9d3 100644 --- a/src/SonsOfPHP/Component/Money/Operator/Money/MoneyOperatorInterface.php +++ b/src/SonsOfPHP/Contract/Money/Operator/Money/MoneyOperatorInterface.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace SonsOfPHP\Component\Money\Operator\Money; +namespace SonsOfPHP\Contract\Money\Operator\Money; -use SonsOfPHP\Component\Money\Exception\MoneyException; -use SonsOfPHP\Component\Money\MoneyInterface; +use SonsOfPHP\Contract\Money\Exception\MoneyExceptionInterface; +use SonsOfPHP\Contract\Money\MoneyInterface; /** * @author Joshua Estes @@ -13,7 +13,7 @@ interface MoneyOperatorInterface { /** - * @throws MoneyException + * @throws MoneyExceptionInterface */ public function apply(MoneyInterface $money): MoneyInterface; } diff --git a/src/SonsOfPHP/Contract/Money/Query/Amount/AmountQueryInterface.php b/src/SonsOfPHP/Contract/Money/Query/Amount/AmountQueryInterface.php new file mode 100644 index 00000000..ae4e8272 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Query/Amount/AmountQueryInterface.php @@ -0,0 +1,19 @@ + + */ +interface AmountQueryInterface +{ + /** + * @throws MoneyExceptionInterface + */ + public function queryFrom(AmountInterface $amount); +} diff --git a/src/SonsOfPHP/Contract/Money/Query/Currency/CurrencyQueryInterface.php b/src/SonsOfPHP/Contract/Money/Query/Currency/CurrencyQueryInterface.php new file mode 100644 index 00000000..bd253722 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Query/Currency/CurrencyQueryInterface.php @@ -0,0 +1,19 @@ + + */ +interface CurrencyQueryInterface +{ + /** + * @throws MoneyExceptionInterface + */ + public function queryFrom(CurrencyInterface $currency); +} diff --git a/src/SonsOfPHP/Contract/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php b/src/SonsOfPHP/Contract/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php new file mode 100644 index 00000000..f13d949b --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Query/CurrencyProvider/CurrencyProviderQueryInterface.php @@ -0,0 +1,19 @@ + + */ +interface CurrencyProviderQueryInterface +{ + /** + * @throws MoneyExceptionInterface + */ + public function queryFrom(CurrencyProviderInterface $provider); +} diff --git a/src/SonsOfPHP/Contract/Money/Query/Money/MoneyQueryInterface.php b/src/SonsOfPHP/Contract/Money/Query/Money/MoneyQueryInterface.php new file mode 100644 index 00000000..b7a3cfaf --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/Query/Money/MoneyQueryInterface.php @@ -0,0 +1,19 @@ + + */ +interface MoneyQueryInterface +{ + /** + * @throws MoneyExceptionInterface + */ + public function queryFrom(MoneyInterface $money); +} diff --git a/src/SonsOfPHP/Contract/Money/README.md b/src/SonsOfPHP/Contract/Money/README.md new file mode 100644 index 00000000..b56a2c10 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/README.md @@ -0,0 +1,16 @@ +Sons of PHP - Money Contract +============================ + +## 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/contracts/money/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AMoney +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AMoney diff --git a/src/SonsOfPHP/Contract/Money/composer.json b/src/SonsOfPHP/Contract/Money/composer.json new file mode 100644 index 00000000..9b352f32 --- /dev/null +++ b/src/SonsOfPHP/Contract/Money/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/money-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/money-contract", + "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" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\Money\\": "" + } + }, + "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" + } + ] +} \ No newline at end of file diff --git a/src/SonsOfPHP/Contract/Version/.gitattributes b/src/SonsOfPHP/Contract/Version/.gitattributes new file mode 100644 index 00000000..3a01b372 --- /dev/null +++ b/src/SonsOfPHP/Contract/Version/.gitattributes @@ -0,0 +1,2 @@ +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Contract/Version/.gitignore b/src/SonsOfPHP/Contract/Version/.gitignore new file mode 100644 index 00000000..d8a7996a --- /dev/null +++ b/src/SonsOfPHP/Contract/Version/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor/ diff --git a/src/SonsOfPHP/Contract/Version/LICENSE b/src/SonsOfPHP/Contract/Version/LICENSE new file mode 100644 index 00000000..39238382 --- /dev/null +++ b/src/SonsOfPHP/Contract/Version/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/Contract/Version/README.md b/src/SonsOfPHP/Contract/Version/README.md new file mode 100644 index 00000000..2ef00a3a --- /dev/null +++ b/src/SonsOfPHP/Contract/Version/README.md @@ -0,0 +1,16 @@ +Sons of PHP - Version Contract +=============================== + +## 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/contracts/version/ +[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AVersion +[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AVersion diff --git a/src/SonsOfPHP/Contract/Version/composer.json b/src/SonsOfPHP/Contract/Version/composer.json new file mode 100644 index 00000000..c2aa9834 --- /dev/null +++ b/src/SonsOfPHP/Contract/Version/composer.json @@ -0,0 +1,52 @@ +{ + "name": "sonsofphp/version-contract", + "type": "library", + "description": "", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "homepage": "https://github.com/SonsOfPHP/version-contract", + "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" + }, + "autoload": { + "psr-4": { + "SonsOfPHP\\Contract\\Version\\": "" + } + }, + "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" + } + ] +} \ No newline at end of file