-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
380 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...lewares/Handler/Resolver/HandlerMethodName/MethodWithShortObjectNameAndSuffixResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Cubiche package. | ||
* | ||
* Copyright (c) Cubiche | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName; | ||
|
||
/** | ||
* MethodWithShortObjectNameAndSuffixResolver class. | ||
* | ||
* Examples: | ||
* - Cubiche\Application\Command\ChangeTitleCommand => $fooTaskCommandHandler->changeTitleHandler() | ||
* - Cubiche\Application\Query\PostListQuery => $postListQueryHandler->postListHandler() | ||
* | ||
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com> | ||
*/ | ||
class MethodWithShortObjectNameAndSuffixResolver extends MethodWithObjectNameResolver | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $suffixToRemove; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $suffixToAdd; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $suffixLength; | ||
|
||
/** | ||
* @param string $suffixToRemove The string to remove from end of each class name | ||
* @param string $suffixToAdd The string to add to the end of each class name | ||
*/ | ||
public function __construct($suffixToRemove = 'Message', $suffixToAdd = 'Handler') | ||
{ | ||
$this->suffixToRemove = $suffixToRemove; | ||
$this->suffixToAdd = $suffixToAdd; | ||
$this->suffixLength = strlen($suffixToRemove); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolve($className) | ||
{ | ||
$methodName = parent::resolve($className); | ||
if (substr($methodName, $this->suffixLength * -1) !== $this->suffixToRemove) { | ||
throw new \Exception(sprintf('Invalid suffix %s', $this->suffixToRemove)); | ||
} | ||
|
||
return substr($methodName, 0, strlen($methodName) - $this->suffixLength).$this->suffixToAdd; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Cubiche package. | ||
* | ||
* Copyright (c) Cubiche | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cubiche\Core\Bus\Tests\Fixtures\Message; | ||
|
||
use Cubiche\Core\Bus\MessageInterface; | ||
use Cubiche\Core\Validator\Assert; | ||
use Cubiche\Core\Validator\Mapping\ClassMetadata; | ||
|
||
/** | ||
* RemoveUserMessage class. | ||
* | ||
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com> | ||
*/ | ||
class RemoveUserMessage implements MessageInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $email; | ||
|
||
/** | ||
* RemoveUserMessage constructor. | ||
* | ||
* @param $email | ||
*/ | ||
public function __construct($email) | ||
{ | ||
$this->setEmail($email); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function email() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
*/ | ||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function loadValidatorMetadata(ClassMetadata $classMetadata) | ||
{ | ||
$classMetadata->addPropertyConstraint( | ||
'email', | ||
Assert::email() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Cubiche package. | ||
* | ||
* Copyright (c) Cubiche | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cubiche\Core\Bus\Tests\Fixtures\Message; | ||
|
||
use Cubiche\Core\Validator\Assert; | ||
use Cubiche\Core\Validator\Exception\ValidationException; | ||
use Cubiche\Core\Validator\Validator; | ||
|
||
/** | ||
* UserMessageValidator class. | ||
* | ||
* @author Ivannis Suárez Jerez <ivannis.suarez@gmail.com> | ||
*/ | ||
class UserMessageValidator | ||
{ | ||
/** | ||
* @param LoginUserMessage $event | ||
* | ||
* @return bool | ||
*/ | ||
public function loginUserValidator(LoginUserMessage $event) | ||
{ | ||
Validator::assert($event->email(), Assert::email()->contains('gmail.com')); | ||
} | ||
|
||
/** | ||
* @param LogoutUserMessage $event | ||
* | ||
* @return bool | ||
*/ | ||
public function logoutUserValidator(LogoutUserMessage $event) | ||
{ | ||
throw new ValidationException('The email is invalid'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.