Skip to content

Commit

Permalink
Making module options strict, removing need for custom ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed May 28, 2013
1 parent 22ef93b commit 84b8744
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ phpunit.xml
clover.xml
tmp/
vendor/

composer.lock
composer.phar
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions ruleset.xml

This file was deleted.

6 changes: 3 additions & 3 deletions src/ZfrRest/Factory/DecoderPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/ZfrRest/Factory/ModelPluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/ZfrRest/Factory/ModuleOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ModuleOptionsFactory implements FactoryInterface
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Config');

return new ModuleOptions($config['zfr_rest']);
}
}
59 changes: 54 additions & 5 deletions src/ZfrRest/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
*/
class ModuleOptions extends AbstractOptions
{
/**
* {@inheritDoc}
*/
protected $__strictMode__ = false;

/**
* Key of the object manager fetched from the service locator
*
Expand Down Expand Up @@ -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)
Expand All @@ -80,6 +90,7 @@ public function getObjectManager()

/**
* @param array $options
*
* @return void
*/
public function setListeners(array $options)
Expand All @@ -97,6 +108,7 @@ public function getListeners()

/**
* @param array $options
*
* @return void
*/
public function setControllerBehaviours(array $options)
Expand All @@ -114,6 +126,7 @@ public function getControllerBehaviours()

/**
* @param array $options
*
* @return void
*/
public function setResourceMetadata(array $options)
Expand All @@ -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;
}
}
4 changes: 3 additions & 1 deletion tests/ZfrRestTest/Serializer/DecoderPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');

Expand Down
3 changes: 2 additions & 1 deletion tests/ZfrRestTest/View/Model/ModelPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit 84b8744

Please sign in to comment.