diff --git a/config/services.yaml b/config/services.yaml index 6163bad..6ec73c1 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -16,8 +16,8 @@ services: tags: ['app.gateway.gateway'] App\Library\Economy\Currency\ExchangeInterface: tags: ['app.lib.economy.currency.exchange'] - App\Matchfunding\MatchStrategy\MatchStrategyInterface: - tags: ['app.matchfunding.strategy.strategy'] + App\Matchfunding\Formula\FormulaInterface: + tags: ['app.matchfunding.formula.formula'] App\Service\Embed\Filter\EmbedFilterInterface: tags: ['app.embed.embed_filter'] App\Service\Embed\Provider\EmbedProviderFactoryInterface: @@ -61,9 +61,9 @@ services: - '%env(STRIPE_API_KEY)%' - '%env(STRIPE_WEBHOOK_SECRET)%' - App\Matchfunding\MatchStrategy\MatchStrategyLocator: + App\Matchfunding\Formula\FormulaLocator: arguments: - - !tagged 'app.matchfunding.strategy.strategy' + - !tagged 'app.matchfunding.formula.formula' App\Service\Auth\AuthService: arguments: diff --git a/src/ApiResource/Matchfunding/FormulaApiResource.php b/src/ApiResource/Matchfunding/FormulaApiResource.php new file mode 100644 index 0000000..1fd0ae6 --- /dev/null +++ b/src/ApiResource/Matchfunding/FormulaApiResource.php @@ -0,0 +1,22 @@ +getMatchCall(); - $strategy = $this->matchStrategyLocator->getForCall($call); - $match = $strategy->match($transaction); + // $call = $submission->getCall(); + // $strategy = $this->formulaLocator->get($call->getFormulaName()); + // $match = $strategy->match($transaction->getMoney()); - if ($match->getId() !== null) { - return; - } + // if ($match->getId() !== null) { + // return; + // } - $event->getObjectManager()->persist($match); - $event->getObjectManager()->flush(); + // $event->getObjectManager()->persist($match); + // $event->getObjectManager()->flush(); } } } diff --git a/src/Matchfunding/MatchStrategy/Exception/MatchStrategyDuplicatedException.php b/src/Matchfunding/Formula/Exception/FormulaDuplicatedException.php similarity index 51% rename from src/Matchfunding/MatchStrategy/Exception/MatchStrategyDuplicatedException.php rename to src/Matchfunding/Formula/Exception/FormulaDuplicatedException.php index df54fb6..6cb3e1d 100644 --- a/src/Matchfunding/MatchStrategy/Exception/MatchStrategyDuplicatedException.php +++ b/src/Matchfunding/Formula/Exception/FormulaDuplicatedException.php @@ -1,22 +1,22 @@ */ + private array $strategiesByName = []; + + public function __construct( + iterable $strategies, + ) { + foreach ($strategies as $Formula) { + $FormulaName = $Formula::getName(); + + if (\array_key_exists($FormulaName, $this->strategiesByName)) { + throw new FormulaDuplicatedException( + $FormulaName, + $Formula::class, + $this->strategiesByName[$FormulaName]::class + ); + } + + $this->strategiesByName[$FormulaName] = $Formula; + } + } + + /** + * @return array + */ + public function getAll(): array + { + return $this->strategiesByName; + } + + public function get(string $FormulaName): ?FormulaInterface + { + if (!array_key_exists($FormulaName, $this->strategiesByName)) { + throw new FormulaNotFoundException($FormulaName); + } + + return $this->strategiesByName[$FormulaName]; + } +} diff --git a/src/Matchfunding/MatchStrategy/MatchStrategyInterface.php b/src/Matchfunding/MatchStrategy/MatchStrategyInterface.php deleted file mode 100644 index f373224..0000000 --- a/src/Matchfunding/MatchStrategy/MatchStrategyInterface.php +++ /dev/null @@ -1,22 +0,0 @@ - */ - private array $strategiesByName = []; - - public function __construct( - iterable $strategies, - ) { - foreach ($strategies as $strategy) { - $strategyName = $strategy::getName(); - - if (\array_key_exists($strategyName, $this->strategiesByName)) { - throw new MatchStrategyDuplicatedException( - $strategyName, - $strategy::class, - $this->strategiesByName[$strategyName]::class - ); - } - - $this->strategiesByName[$strategyName] = $strategy; - } - } - - /** - * @return array - */ - public function getAll(): array - { - return $this->strategiesByName; - } - - public function get(string $strategyName): ?MatchStrategyInterface - { - if (!array_key_exists($strategyName, $this->strategiesByName)) { - throw new MatchStrategyNotFoundException($strategyName); - } - - return $this->strategiesByName[$strategyName]; - } - - public function getForCall(MatchCall $call): ?MatchStrategyInterface - { - return $this->get($call->getStrategyName()); - } -} diff --git a/src/State/Matchfunding/FormulaStateProvider.php b/src/State/Matchfunding/FormulaStateProvider.php new file mode 100644 index 0000000..566e81d --- /dev/null +++ b/src/State/Matchfunding/FormulaStateProvider.php @@ -0,0 +1,47 @@ +formulaLocator->get($uriVariables['name']); + + return $this->getApiResource($formula); + } catch (FormulaNotFoundException $e) { + return null; + } + } + + $strategies = $this->formulaLocator->getAll(); + + $resources = []; + foreach ($strategies as $formula) { + $resources[] = $this->getApiResource($formula); + } + + return $resources; + } + + private function getApiResource(FormulaInterface $formula): FormulaApiResource + { + $resource = new FormulaApiResource(); + $resource->name = $formula::getName(); + + return $resource; + } +} diff --git a/src/State/Matchfunding/MatchStrategyStateProvider.php b/src/State/Matchfunding/MatchStrategyStateProvider.php deleted file mode 100644 index 338c2fb..0000000 --- a/src/State/Matchfunding/MatchStrategyStateProvider.php +++ /dev/null @@ -1,47 +0,0 @@ -matchStrategyLocator->get($uriVariables['name']); - - return $this->getApiResource($strategy); - } catch (MatchStrategyNotFoundException $e) { - return null; - } - } - - $strategies = $this->matchStrategyLocator->getAll(); - - $resources = []; - foreach ($strategies as $strategy) { - $resources[] = $this->getApiResource($strategy); - } - - return $resources; - } - - private function getApiResource(MatchStrategyInterface $strategy): MatchStrategyApiResource - { - $resource = new MatchStrategyApiResource(); - $resource->name = $strategy::getName(); - - return $resource; - } -}