diff --git a/readme.md b/readme.md index 53c24d2..5aa59d5 100644 --- a/readme.md +++ b/readme.md @@ -97,7 +97,7 @@ $documentRegistory->register($cXml); ### Process incoming cXML documents ```php -$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry); +$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry, $credentialRegistry); $cXmlProcessor = new \CXml\Processor\Processor( $headerProcessor, @@ -119,7 +119,7 @@ $handlerRegistry = new \CXml\Handler\HandlerRegistry(); $builder = \CXml\Builder::create(); -$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry); +$headerProcessor = new \CXml\Processor\HeaderProcessor($credentialRegistry, $credentialRegistry, $credentialRegistry); $cXmlProcessor = new \CXml\Processor\Processor( $headerProcessor, $handlerRegistry, diff --git a/src/CXml/Credential/CredentialValidatorInterface.php b/src/CXml/Credential/CredentialValidatorInterface.php new file mode 100644 index 0000000..224d3c1 --- /dev/null +++ b/src/CXml/Credential/CredentialValidatorInterface.php @@ -0,0 +1,14 @@ +getCredentialByDomainAndId( + $credential->getDomain(), + $credential->getIdentity() + ); + } } diff --git a/src/CXml/Processor/HeaderProcessor.php b/src/CXml/Processor/HeaderProcessor.php index a72168f..1c69f78 100644 --- a/src/CXml/Processor/HeaderProcessor.php +++ b/src/CXml/Processor/HeaderProcessor.php @@ -5,19 +5,24 @@ use CXml\Authentication\AuthenticatorInterface; use CXml\Context; use CXml\Credential\CredentialRepositoryInterface; +use CXml\Credential\CredentialValidatorInterface; use CXml\Exception\CXmlAuthenticationInvalidException; use CXml\Exception\CXmlCredentialInvalidException; -use CXml\Model\Credential; use CXml\Model\Header; class HeaderProcessor { private CredentialRepositoryInterface $credentialRepository; + private CredentialValidatorInterface $credentialValidator; private AuthenticatorInterface $authenticator; - public function __construct(CredentialRepositoryInterface $credentialRepository, AuthenticatorInterface $authenticator) - { + public function __construct( + CredentialRepositoryInterface $credentialRepository, + CredentialValidatorInterface $credentialValidator, + AuthenticatorInterface $authenticator + ) { $this->credentialRepository = $credentialRepository; + $this->credentialValidator = $credentialValidator; $this->authenticator = $authenticator; } @@ -37,22 +42,10 @@ public function process(Header $header, Context $context): void */ private function validatePartys(Header $header): void { - $this->checkCredentialIsValid($header->getFrom()->getCredential()); - - $this->checkCredentialIsValid($header->getTo()->getCredential()); + $this->credentialValidator->validate($header->getFrom()->getCredential()); - $this->checkCredentialIsValid($header->getSender()->getCredential()); - } + $this->credentialValidator->validate($header->getTo()->getCredential()); - /** - * @throws CXmlCredentialInvalidException - */ - private function checkCredentialIsValid(Credential $testCredential): void - { - // provoke an exception if credential was not found - $this->credentialRepository->getCredentialByDomainAndId( - $testCredential->getDomain(), - $testCredential->getIdentity() - ); + $this->credentialValidator->validate($header->getSender()->getCredential()); } }