Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #35 from stefliekens/extra-crud-events
Browse files Browse the repository at this point in the history
Added a before data hydration event
  • Loading branch information
veewee committed Jan 19, 2016
2 parents 0d2558e + c9818c3 commit 76eec59
Show file tree
Hide file tree
Showing 17 changed files with 29 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ nbproject
.DS_Store
composer.phar
composer.lock
build
build
.php_cs.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"symfony/console": "2.*"
},
"require-dev": {
"phpspec/phpspec": "2.0.*@dev",
"fabpot/PHP-CS-Fixer": "*",
"phpspec/phpspec": "~2.0.1",
"fabpot/PHP-CS-Fixer": "~1.5.0",

"doctrine/doctrine-orm-module": "0.8.*",
"doctrine/doctrine-mongo-odm-module":"0.8.*",
Expand Down
8 changes: 5 additions & 3 deletions spec/Phpro/SmartCrud/Controller/CrudControllerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ public function it_should_handle_a_valid_post_to_an_update_action($request, $mvc
$action = 'update';
$smartResult->isSuccessFull()->shouldBeCalled()->willReturn(true);
$smartService->run(Argument::any(), Argument::exact($postParameters))->shouldBeCalled()->willReturn($smartResult);
$pluginManager->get(Argument::exact('params'), null)->shouldBeCalled()->willReturn($params);
$params->fromRoute(Argument::exact('id'), null)->shouldBeCalled()->willReturn(1);
$params->__invoke()->willReturn($params);
$params->fromRoute('id', null)->willReturn(1);
$pluginManager->get('params', Argument::cetera())->willReturn($params);
$pluginManager->get(Argument::exact('redirect'), null)->shouldBeCalled()->willReturn($redirectPlugin);
$redirectPlugin->toRoute(Argument::exact(null), Argument::exact(array('action' => 'update', 'id' => '1')), true)->shouldBeCalled();
$redirectPlugin->toRoute(Argument::exact(null), array('action' => 'update', 'id' => '1'), true)->willReturn('mockRedirect');
Expand Down Expand Up @@ -233,8 +234,9 @@ public function it_should_handle_valid_post_to_a_delete_action($request, $mvcEve
$action = 'delete';
$smartResult->isSuccessFull()->shouldBeCalled()->willReturn(true);
$smartService->run(Argument::any(), Argument::exact($postParameters))->shouldBeCalled()->willReturn($smartResult);
$params->fromRoute(Argument::exact('id'), null)->shouldBeCalled()->willReturn(1);
$pluginManager->get(Argument::exact('params'), null)->shouldBeCalled()->willReturn($params);
$params->__invoke()->willReturn($params);
$params->fromRoute(Argument::exact('id'), null)->shouldBeCalled()->willReturn(1);
$pluginManager->get(Argument::exact('redirect'), null)->shouldBeCalled()->willReturn($redirectPlugin);
$redirectPlugin->toRoute(Argument::exact(null), Argument::exact(array('action' => 'list')), true)
->shouldBeCalled()
Expand Down
5 changes: 4 additions & 1 deletion spec/Phpro/SmartCrud/Service/CreateServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function it_should_handle_no_data($gateway, $eventManager, $form, $result
$this->setForm($form);

$this->run(null, null)->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');
;

$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_CREATE))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_CREATE))->shouldNotBeCalled();
Expand Down Expand Up @@ -85,6 +86,7 @@ public function it_should_handle_invalid_data($gateway, $eventManager, $form, $r

$this->run(null, $this->getMockPostData())->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');
;
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_CREATE))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_CREATE))->shouldNotBeCalled();
Expand Down Expand Up @@ -122,6 +124,7 @@ public function it_should_handle_valid_data($gateway, $eventManager, $form, $res

$this->run(null, $this->getMockPostData())->shouldReturn($result);
;
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_CREATE))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_CREATE))->shouldBeCalled();
Expand Down
5 changes: 4 additions & 1 deletion spec/Phpro/SmartCrud/Service/UpdateServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function it_should_handle_no_data($gateway, $eventManager, $form, $result

$this->run($entity->id, null)->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');
;
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_UPDATE))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_UPDATE))->shouldNotBeCalled();
Expand Down Expand Up @@ -92,7 +93,8 @@ public function it_should_handle_invalid_data($gateway, $eventManager, $form, $r
$this->setForm($form);

$this->run($entity->id, $this->getMockPostData())->shouldReturn($result);
;

$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_UPDATE))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_UPDATE))->shouldNotBeCalled();
Expand Down Expand Up @@ -131,6 +133,7 @@ public function it_should_handle_valid_data($gateway, $eventManager, $form, $res

$this->run($entity->id, $this->getMockPostData())->shouldReturn($result);

$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_UPDATE))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_UPDATE))->shouldBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
*
* @package Phpro\SmartCrud\Controller
*/
class AbstractCrudControllerFactory
implements AbstractFactoryInterface, ServiceLocatorAwareInterface
class AbstractCrudControllerFactory implements AbstractFactoryInterface, ServiceLocatorAwareInterface
{
const FACTORY_NAMESPACE = 'phpro-smartcrud-controller';
const CONFIG_DEFAULT = 'default';
Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Controller/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
/**
* Class CrudController
*/
class CrudController extends AbstractActionController
implements CrudControllerInterface
class CrudController extends AbstractActionController implements CrudControllerInterface
{
/**
* @var SmartServiceInterface
Expand Down
1 change: 1 addition & 0 deletions src/Phpro/SmartCrud/Event/CrudEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CrudEvent extends Event
{
const BEFORE_LIST = 'before-list';
const AFTER_LIST = 'after-list';
const BEFORE_DATA_HYDRATION = 'before-data-hydration';
const BEFORE_DATA_VALIDATION = 'before-data-validation';
const BEFORE_CREATE = 'before-create';
const AFTER_CREATE = 'after-create';
Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Gateway/AbstractGatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\ServiceLocatorInterface;

class AbstractGatewayFactory
implements AbstractFactoryInterface
class AbstractGatewayFactory implements AbstractFactoryInterface
{
const FACTORY_NAMESPACE = 'phpro-smartcrud-gateway';

Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Gateway/DoctrineCrudGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
*
* @package Phpro\SmartCrud\Gateway
*/
class DoctrineCrudGateway
implements ObjectManagerAwareInterface, CrudGatewayInterface
class DoctrineCrudGateway implements ObjectManagerAwareInterface, CrudGatewayInterface
{
const TYPE_ORM = 'ORM';
const TYPE_ODM = 'ODM';
Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Listener/BjyAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
*
* @package Phpro\SmartCrud\Listener
*/
class BjyAuthorize extends AbstractListenerAggregate
implements FactoryInterface
class BjyAuthorize extends AbstractListenerAggregate implements FactoryInterface
{
/**
* Set the priority of the listeners
Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Listener/FlashMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*
* @package Phpro\SmartCrud
*/
class FlashMessenger extends AbstractListenerAggregate
implements FactoryInterface
class FlashMessenger extends AbstractListenerAggregate implements FactoryInterface
{
/**
* Set the priority of the listeners
Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Service/AbstractSmartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*
* @package Phpro\SmartCrud\Service
*/
abstract class AbstractSmartService
implements SmartServiceInterface
abstract class AbstractSmartService implements SmartServiceInterface
{
/**
* @var ParametersService
Expand Down
3 changes: 1 addition & 2 deletions src/Phpro/SmartCrud/Service/AbstractSmartServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
*
* @package Phpro\SmartCrud\Service
*/
class AbstractSmartServiceFactory
implements AbstractFactoryInterface, ServiceLocatorAwareInterface
class AbstractSmartServiceFactory implements AbstractFactoryInterface, ServiceLocatorAwareInterface
{
/**
* The config key in the service manager
Expand Down
1 change: 1 addition & 0 deletions src/Phpro/SmartCrud/Service/CreateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function run($id = null, $data = null)
if ($data === null) {
$result->setSuccess(true);
} else {
$em->trigger($this->createEvent(CrudEvent::BEFORE_DATA_HYDRATION, $entity, $data));
$form->setData($data);
$em->trigger($this->createEvent(CrudEvent::BEFORE_DATA_VALIDATION, $form, array('postData' => $data)));
if ($form->isValid()) {
Expand Down
5 changes: 1 addition & 4 deletions src/Phpro/SmartCrud/Service/ListService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*
* @package Phpro\SmartCrud\Service
*/
class ListService extends AbstractSmartService
implements
PaginatorFactoryAwareInterface,
QueryProviderAwareInterface
class ListService extends AbstractSmartService implements PaginatorFactoryAwareInterface, QueryProviderAwareInterface
{
/**
* @var PaginatorServiceFactory
Expand Down
1 change: 1 addition & 0 deletions src/Phpro/SmartCrud/Service/UpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function run($id = null, $data = null)
if ($data === null) {
$result->setSuccess(true);
} else {
$em->trigger($this->createEvent(CrudEvent::BEFORE_DATA_HYDRATION, $entity, $data));
$form->setData($data);
$em->trigger($this->createEvent(CrudEvent::BEFORE_DATA_VALIDATION, $form, array('postData' => $data)));
if ($form->isValid()) {
Expand Down

0 comments on commit 76eec59

Please sign in to comment.