From 84b874433835d5f6a08571dcb09160281af95cc7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 28 May 2013 14:42:07 +0200 Subject: [PATCH] Making module options strict, removing need for custom ruleset --- .gitignore | 3 +- .travis.yml | 2 +- ruleset.xml | 9 --- .../Factory/DecoderPluginManagerFactory.php | 6 +- .../Factory/ModelPluginManagerFactory.php | 6 +- src/ZfrRest/Factory/ModuleOptionsFactory.php | 1 + src/ZfrRest/Options/ModuleOptions.php | 59 +++++++++++++++++-- .../Serializer/DecoderPluginManagerTest.php | 4 +- .../View/Model/ModelPluginManagerTest.php | 3 +- 9 files changed, 69 insertions(+), 24 deletions(-) delete mode 100644 ruleset.xml diff --git a/.gitignore b/.gitignore index bdfc625..93344bf 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ phpunit.xml clover.xml tmp/ vendor/ - +composer.lock +composer.phar diff --git a/.travis.yml b/.travis.yml index dab4a8a..01e2d49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ before_script: script: - ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Performance - ./vendor/bin/phpunit --group=Functional - - ./vendor/bin/phpcs --standard=./ruleset.xml ./src/ ./tests/ + - ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/ after_script: - php vendor/bin/coveralls -v diff --git a/ruleset.xml b/ruleset.xml deleted file mode 100644 index f21fbc0..0000000 --- a/ruleset.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - */.travis/* - */docs/* - - - - - diff --git a/src/ZfrRest/Factory/DecoderPluginManagerFactory.php b/src/ZfrRest/Factory/DecoderPluginManagerFactory.php index 038e440..e89e2e1 100644 --- a/src/ZfrRest/Factory/DecoderPluginManagerFactory.php +++ b/src/ZfrRest/Factory/DecoderPluginManagerFactory.php @@ -36,10 +36,10 @@ class DecoderPluginManagerFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); - $config = $config['zfr_rest']['decoders']; + /* @var $options \ZfrRest\Options\ModuleOptions */ + $options = $serviceLocator->get('ZfrRest\Options\ModuleOptions'); - $decoderPluginManager = new DecoderPluginManager(new Config($config)); + $decoderPluginManager = new DecoderPluginManager(new Config($options->getDecoders())); $decoderPluginManager->setServiceLocator($serviceLocator); return $decoderPluginManager; diff --git a/src/ZfrRest/Factory/ModelPluginManagerFactory.php b/src/ZfrRest/Factory/ModelPluginManagerFactory.php index 9a0586d..4608d4b 100644 --- a/src/ZfrRest/Factory/ModelPluginManagerFactory.php +++ b/src/ZfrRest/Factory/ModelPluginManagerFactory.php @@ -36,10 +36,10 @@ class ModelPluginManagerFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $config = $serviceLocator->get('Config'); - $config = $config['zfr_rest']['models']; + /* @var $options \ZfrRest\Options\ModuleOptions */ + $options = $serviceLocator->get('ZfrRest\Options\ModuleOptions'); - $modelPluginManager = new ModelPluginManager(new Config($config)); + $modelPluginManager = new ModelPluginManager(new Config($options->getModels())); $modelPluginManager->setServiceLocator($serviceLocator); return $modelPluginManager; diff --git a/src/ZfrRest/Factory/ModuleOptionsFactory.php b/src/ZfrRest/Factory/ModuleOptionsFactory.php index 01c76da..0b7c7f0 100644 --- a/src/ZfrRest/Factory/ModuleOptionsFactory.php +++ b/src/ZfrRest/Factory/ModuleOptionsFactory.php @@ -36,6 +36,7 @@ class ModuleOptionsFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config'); + return new ModuleOptions($config['zfr_rest']); } } diff --git a/src/ZfrRest/Options/ModuleOptions.php b/src/ZfrRest/Options/ModuleOptions.php index 0602b5d..e490480 100644 --- a/src/ZfrRest/Options/ModuleOptions.php +++ b/src/ZfrRest/Options/ModuleOptions.php @@ -28,11 +28,6 @@ */ class ModuleOptions extends AbstractOptions { - /** - * {@inheritDoc} - */ - protected $__strictMode__ = false; - /** * Key of the object manager fetched from the service locator * @@ -61,8 +56,23 @@ class ModuleOptions extends AbstractOptions */ protected $resourceMetadataOptions; + /** + * Plugin manager configuration for the content decoders + * + * @var array + */ + protected $decoders = array(); + + /** + * Plugin manager configuration for the view models + * + * @var array + */ + protected $models = array(); + /** * @param string $objectManager + * * @return void */ public function setObjectManager($objectManager) @@ -80,6 +90,7 @@ public function getObjectManager() /** * @param array $options + * * @return void */ public function setListeners(array $options) @@ -97,6 +108,7 @@ public function getListeners() /** * @param array $options + * * @return void */ public function setControllerBehaviours(array $options) @@ -114,6 +126,7 @@ public function getControllerBehaviours() /** * @param array $options + * * @return void */ public function setResourceMetadata(array $options) @@ -128,4 +141,40 @@ public function getResourceMetadata() { return $this->resourceMetadataOptions; } + + /** + * @param array $decoders + * + * @return void + */ + public function setDecoders(array $decoders) + { + $this->decoders = $decoders; + } + + /** + * @return array + */ + public function getDecoders() + { + return $this->decoders; + } + + /** + * @param array $models + * + * @return void + */ + public function setModels(array $models) + { + $this->models = $models; + } + + /** + * @return array + */ + public function getModels() + { + return $this->models; + } } diff --git a/tests/ZfrRestTest/Serializer/DecoderPluginManagerTest.php b/tests/ZfrRestTest/Serializer/DecoderPluginManagerTest.php index 8714a64..95cafce 100644 --- a/tests/ZfrRestTest/Serializer/DecoderPluginManagerTest.php +++ b/tests/ZfrRestTest/Serializer/DecoderPluginManagerTest.php @@ -21,6 +21,7 @@ use PHPUnit_Framework_TestCase as TestCase; use Zend\ServiceManager\ServiceManager; use Zend\Mvc\Service\ServiceManagerConfig; +use ZfrRest\Options\ModuleOptions; use ZfrRest\Serializer\DecoderPluginManager; class DecoderPluginManagerTest extends TestCase @@ -59,7 +60,8 @@ public function testCanRetrievePluginManagerWithServiceManager() ) ) ); - $serviceManager->setService('Config', array('zfr_rest' => array('decoders' => array()))); + + $serviceManager->setService('ZfrRest\Options\ModuleOptions', new ModuleOptions()); $decoderPluginManager = $serviceManager->get('DecoderPluginManager'); diff --git a/tests/ZfrRestTest/View/Model/ModelPluginManagerTest.php b/tests/ZfrRestTest/View/Model/ModelPluginManagerTest.php index 18d3cb2..a49d122 100644 --- a/tests/ZfrRestTest/View/Model/ModelPluginManagerTest.php +++ b/tests/ZfrRestTest/View/Model/ModelPluginManagerTest.php @@ -21,6 +21,7 @@ use PHPUnit_Framework_TestCase as TestCase; use Zend\ServiceManager\ServiceManager; use Zend\Mvc\Service\ServiceManagerConfig; +use ZfrRest\Options\ModuleOptions; use ZfrRest\View\Model\ModelPluginManager; class ModelPluginManagerTest extends TestCase @@ -57,7 +58,7 @@ public function testCanRetrievePluginManagerWithServiceManager() ) ) ); - $serviceManager->setService('Config', array('zfr_rest' => array('models' => array()))); + $serviceManager->setService('ZfrRest\Options\ModuleOptions', new ModuleOptions()); $modelPluginManager = $serviceManager->get('ModelPluginManager');