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 #29 from veewee/feature-query-provider
Browse files Browse the repository at this point in the history
Feature query provider
  • Loading branch information
veewee committed Sep 12, 2014
2 parents b55f18e + faab6dd commit 2b5a70d
Show file tree
Hide file tree
Showing 63 changed files with 314 additions and 129 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ php:
- 5.5
- hhvm

before_script:
- pecl install -f mongo-1.4.1

matrix:
allow_failures:
- php: hhvm
Expand Down
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ that are listed in `composer.json`

## Documentation

### Configuration

It is possible to configure the smartcrud services on multiple places.
e.g. For the list service, the configuration will be merged as followed:

- phpro-smartcrud-service['default']
- phpro-smartcrud-service['default-list']
- service_manager['my-custom-smartcrud-service']['default']
- service_manager['my-custom-smartcrud-service']['list']

This means it is possible to specify some default configuration and overwrite it for custom services.

### SmartCrud Configuration

### Gateways
Expand Down Expand Up @@ -55,6 +67,42 @@ Those gateways are being used by the services to load and save the data.
),
```

##### List Service

The list service has some extra configurable options.
It is required to specify a paginator and it is optional to add a query provider to filter / sort lists.

**Paginator**

```php
'phpro-smartcrud-service' => array(
'default-list' => array(
'options' => array(
'paginator' => array(
'adapter_class' => '\Zend\Paginator\Adapter\ArrayAdapter',
'page_size' => 50,
'page_key' => 'page',
),
)
)
),
```

**Query Provider**

A query provider implements the `QueryProviderInterface`.
It is possible to add your own query provider to a List Service:

```php
'phpro-smartcrud-service' => array(
'default-list' => array(
'options' => array(
'query-provider' => 'servicemanager.key.my-custom-query-provider',
),
)
),
```

##### listeners:

Array of service manager keys, which return EventListenerAggregateInterface. These listeners can be used listen to SmartCrud events on entities.
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"phpspec/phpspec": "2.0.*@dev",
"fabpot/PHP-CS-Fixer": "*",

"doctrine/doctrine-orm-module": "0.8.*@dev",
"doctrine/doctrine-orm-module": "0.8.*",
"doctrine/doctrine-mongo-odm-module":"0.8.*",
"zendframework/zend-db": "2.*",

"zendframework/zend-permissions-acl":"2.*",
Expand All @@ -46,7 +47,8 @@
},
"suggest": {
"rwoverdijk/assetmanager": "~1.3.5",
"doctrine/doctrine-orm-module": "If you want to use the Doctrine Gateway",
"doctrine/doctrine-orm-module": "If you want to use the Doctrine ORM Gateway",
"doctrine/doctrine-mongo-odm-module": "If you want to use the Doctrine ODM Gateway",
"zendframework/zend-db": "If you want to use the Zend DB Gateway"
},
"autoload": {
Expand Down
1 change: 0 additions & 1 deletion spec/Phpro/SmartCrud/Console/ApplicationFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function it_should_extend_Symfony_Console_Application()
{
$this->shouldHaveType('\Zend\ServiceManager\FactoryInterface');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function it_should_extend_Symfony_Console_Command()
{
$this->shouldBeAnInstanceOf('Symfony\Component\Console\Command\Command');
}

}
2 changes: 0 additions & 2 deletions spec/Phpro/SmartCrud/Console/Helper/AbstractHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

abstract class AbstractHelperSpec extends ObjectBehavior
{

public function it_should_extend_from_symfony_helper()
{
$this->shouldBeAnInstanceOf('Symfony\Component\Console\Helper\Helper');
Expand All @@ -34,5 +33,4 @@ protected function mockConfig($config)
$helperSet->get('Config')->willReturn($helper);
$this->setHelperSet($helperSet);
}

}
1 change: 0 additions & 1 deletion spec/Phpro/SmartCrud/Console/Helper/ConfigHelperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,4 @@ public function it_should_load_application_config_from_servicemanager()
$this->mockApplicationConfig('ApplicationConfig', $config);
$this->getApplicationConfig()->shouldBe($config);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ public function it_should_know_the_default_gateway()
);
$this->getDefault()->shouldBe('default.key');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public function it_should_load_a_modules_list()
$list->shouldBeArray();
$list[0]->shouldBe('SampleModule');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class ServiceManagerHelperSpec extends AbstractHelperSpec
{

/**
* @param \Zend\ServiceManager\ServiceManager $serviceManager
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class AbstractCrudControllerFactorySpec extends ObjectBehavior
{

/**
* @param \Zend\Mvc\Controller\ControllerManager $controllerManager
* @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
Expand Down Expand Up @@ -193,5 +192,4 @@ public function it_should_throw_exception_when_service_does_not_exist($controlle
$this->shouldThrow('Phpro\SmartCrud\Exception\SmartCrudException')
->duringCreateServiceWithName($controllerManager, $name, $name);
}

}
1 change: 0 additions & 1 deletion spec/Phpro/SmartCrud/Controller/CrudControllerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class CrudControllerSpec extends ObjectBehavior
{

public function let()
{
$this->setIdentifierName('id');
Expand Down
1 change: 0 additions & 1 deletion spec/Phpro/SmartCrud/Event/CrudEventSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
class CrudEventSpec extends ObjectBehavior
{

/**
* @param \stdClass $entity
*/
Expand Down
2 changes: 0 additions & 2 deletions spec/Phpro/SmartCrud/Gateway/AbstractGatewayFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function mockBaseGateway($serviceLocator, $gateway)
*/
public function it_should_be_able_to_create_gateway_services($serviceLocator)
{

$this->mockConfiguration($serviceLocator);
$name = 'custom-gateway';
$this->canCreateServiceWithName($serviceLocator, $name, $name)->shouldReturn(true);
Expand Down Expand Up @@ -107,5 +106,4 @@ public function it_should_throw_exception_when_base_gateway_does_not_exist($serv
$this->shouldThrow('Phpro\SmartCrud\Exception\SmartCrudException')
->duringCreateServiceWithName($serviceLocator, $name, $name);
}

}
13 changes: 7 additions & 6 deletions spec/Phpro/SmartCrud/Gateway/DoctrineCrudGatewaySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
class DoctrineCrudGatewaySpec extends ObjectBehavior
{

public function it_is_initializable()
{
$this->shouldHaveType('Phpro\SmartCrud\Gateway\DoctrineCrudGateway');
Expand All @@ -36,7 +35,7 @@ public function it_should_implement_Doctrine_ObjectManagerAwareInterface()
}

/**
* @param \Doctrine\Common\Persistence\ObjectManager $objectManager Make sure to use the wrapped / revealed object
* @param \Doctrine\ORM\EntityManager $objectManager Make sure to use the wrapped / revealed object
*/
public function let($objectManager)
{
Expand Down Expand Up @@ -87,13 +86,16 @@ public function it_should_load_an_entity($objectManager, $repository, $entity)
* @param \Doctrine\Common\Persistence\ObjectManager $objectManager
* @param \Doctrine\Common\Persistence\ObjectRepository $repository
* @param \stdClass $entity
* @param \Phpro\SmartCrud\Query\QueryProviderInterface $queryProvider
* @param \Doctrine\ORM\AbstractQuery $query
*/
public function it_should_generate_list($objectManager, $repository, $entity)
public function it_should_generate_list($objectManager, $repository, $entity, $queryProvider, $query)
{
$objectManager->getRepository(Argument::type('string'))->willReturn($repository);
$queryProvider->createQuery(array())->willReturn($query);
$query->getResult()->willReturn(array());

$this->getList($entity, array());
$repository->findAll()->shouldBeCalled();
$this->getList($entity, array(), $queryProvider)->shouldReturn(array());
}

/**
Expand Down Expand Up @@ -177,5 +179,4 @@ public function it_should_not_delete_invalid_entity($objectManager, $entity)

$this->delete($entity, array())->shouldReturn(false);
}

}
1 change: 0 additions & 1 deletion spec/Phpro/SmartCrud/Gateway/ZendDbCrudGatewaySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function it_should_implement_Phpro_SmartCrud_CrudGatewayInterface()
{
$this->shouldBeAnInstanceOf('Phpro\SmartCrud\Gateway\CrudGatewayInterface');
}

}
1 change: 0 additions & 1 deletion spec/Phpro/SmartCrud/Listener/BjyAuthorizeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class BjyAuthorizeSpec extends ObjectBehavior
{

/**
* @param \BjyAuthorize\Service\Authorize $authorizeService
*/
Expand Down
3 changes: 0 additions & 3 deletions spec/Phpro/SmartCrud/Listener/FlashMessengerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class FlashMessengerSpec extends ObjectBehavior
{

/**
* Mock the flashmessenger
*
Expand Down Expand Up @@ -125,7 +124,6 @@ public function it_should_add_delete_succeeded_message($flashMessenger, $event)

$this->deleteSucceeded($event);
$flashMessenger->addSuccessMessage(Argument::type('string'))->shouldBeCalled();

}

/**
Expand Down Expand Up @@ -163,5 +161,4 @@ public function it_should_add_delete_failed_message($flashMessenger, $event)
$this->deleteFailed($event);
$flashMessenger->addErrorMessage(Argument::type('string'))->shouldBeCalled();
}

}
2 changes: 0 additions & 2 deletions spec/Phpro/SmartCrud/ModuleSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class ModuleSpec extends ObjectBehavior
{

public function it_is_initializable()
{
$this->shouldHaveType('Phpro\SmartCrud\Module');
Expand Down Expand Up @@ -71,5 +70,4 @@ public function it_should_configure_cli($event, $cli, $serviceManager, $helperSe
$cli->addCommands(Argument::type('array'))->shouldBeCalled();
$helperSet->set(Argument::cetera())->shouldBeCalled();
}

}
40 changes: 40 additions & 0 deletions spec/Phpro/SmartCrud/Query/DoctrineProviderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace spec\Phpro\SmartCrud\Query;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class DoctrineProviderSpec extends ObjectBehavior
{
/**
* @param \Doctrine\ORM\EntityRepository $repository
*/
public function let($repository)
{
$this->beConstructedWith($repository);
}

public function it_is_initializable()
{
$this->shouldHaveType('Phpro\SmartCrud\Query\DoctrineProvider');
}

public function it_should_be_a_queryProvider()
{
$this->shouldImplement('Phpro\SmartCrud\Query\QueryProviderInterface');
}

/**
* @param \Doctrine\ORM\EntityRepository $repository
* @param \Doctrine\ORM\QueryBuilder $queryBuilder
* @param \Doctrine\ORM\Query Query $query
*/
public function it_should_create_a_list($repository, $queryBuilder, $query)
{
$repository->createQueryBuilder()->willReturn($queryBuilder);
$queryBuilder->getQuery()->willReturn($query);

$this->createQuery(array())->shouldReturn($query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ public function it_should_check_if_service_can_be_created($serviceLocator)
public function it_should_create_a_service_and_inject_the_dependencies(
$serviceLocator, $smartService, $eventManager, $listener, $crudGateway, $form, $parameterService)
{

$name = "Create service";
$requestedName = 'key_in_configuration';
$serviceKey = 'module/service';
Expand Down Expand Up @@ -205,7 +204,5 @@ public function it_should_create_a_service_and_inject_the_dependencies(

$eventManager->attach($listener)->shouldBeCalled();
$this->createServiceWithName($serviceLocator, $name, $requestedName . '::' . 'create')->shouldReturn($smartService);

}

}
2 changes: 0 additions & 2 deletions spec/Phpro/SmartCrud/Service/AbstractSmartServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
abstract class AbstractSmartServiceSpec extends ObjectBehavior
{

/**
* @param array $paramsData
*
Expand Down Expand Up @@ -127,5 +126,4 @@ public function it_should_create_crud_event($entity)
$crudEvent->getTarget()->shouldReturn($entity);
$crudEvent->getParams()->shouldReturn($this->getParameters());
}

}
10 changes: 6 additions & 4 deletions spec/Phpro/SmartCrud/Service/CreateServiceSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
class CreateServiceSpec extends AbstractSmartServiceSpec
{

public function it_is_initializable()
{
$this->shouldHaveType('Phpro\SmartCrud\Service\CreateService');
Expand Down Expand Up @@ -53,7 +52,8 @@ public function it_should_handle_no_data($gateway, $eventManager, $form, $result
$this->setGateway($gateway);
$this->setForm($form);

$this->run(null,null)->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');;
$this->run(null,null)->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');
;
$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 @@ -83,7 +83,8 @@ public function it_should_handle_invalid_data($gateway, $eventManager, $form, $r
$this->setGateway($gateway);
$this->setForm($form);

$this->run(null,$this->getMockPostData())->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');;
$this->run(null,$this->getMockPostData())->shouldReturnAnInstanceOf('Phpro\SmartCrud\Service\SmartServiceResult');
;
$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 @@ -119,7 +120,8 @@ public function it_should_handle_valid_data($gateway, $eventManager, $form, $res
$this->setResult($result);
$this->setForm($form);

$this->run(null,$this->getMockPostData())->shouldReturn($result);;
$this->run(null,$this->getMockPostData())->shouldReturn($result);
;
$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
Loading

0 comments on commit 2b5a70d

Please sign in to comment.