Skip to content

Commit

Permalink
Merge b6b98fe into 117d8af
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed May 28, 2013
2 parents 117d8af + b6b98fe commit fb8534a
Show file tree
Hide file tree
Showing 56 changed files with 678 additions and 359 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
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
language: php

php:
- 5.3.3
- 5.3
- 5.4
- 5.5

matrix:
allow_failures:
- php: 5.5

before_script:
- composer self-update
- composer update --prefer-source
- composer update --prefer-source --dev

script:
- phpunit
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Performance
- ./vendor/bin/phpunit --group=Functional
- ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/

after_script:
- php vendor/bin/coveralls -v

notifications:
irc: "irc.freenode.org#zftalk.modules"
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
"doctrine/doctrine-module": "~0.8"
},
"require-dev": {
"doctrine/doctrine-orm-module": "~0.8"
"doctrine/doctrine-orm-module": "~0.8",
"phpunit/phpunit": "~3.7",
"squizlabs/php_codesniffer": "1.4.*",
"satooshi/php-coveralls": "~0.6"
},
"autoload": {
"psr-0": {
Expand Down
3 changes: 2 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@

'factories' => array(
'ZfrRest\Mvc\View\Http\SelectModelListener' => 'ZfrRest\Factory\SelectModelListenerFactory',
'ZfrRest\Mvc\View\Http\CreateResourcePayloadListener' => 'ZfrRest\Factory\CreateResourcePayloadListenerFactory',
'ZfrRest\Options\ModuleOptions' => 'ZfrRest\Factory\ModuleOptionsFactory',
'ZfrRest\Resource\Metadata\CacheProvider' => 'ZfrRest\Factory\ResourceMetadataCacheFactory',
'ZfrRest\Resource\Metadata\MetadataFactory' => 'ZfrRest\Factory\ResourceMetadataFactoryFactory',
'ZfrRest\Serializer\DecoderPluginManager' => 'ZfrRest\Factory\DecoderPluginManagerFactory',
'ZfrRest\View\Model\ModelPluginManager' => 'ZfrRest\Factory\ModelPluginManagerFactory',
'ZfrRest\Mvc\View\Http\CreateResourcePayloadListener'
=> 'ZfrRest\Factory\CreateResourcePayloadListenerFactory',
)
),

Expand Down
4 changes: 2 additions & 2 deletions src/ZfrRest/Controller/CacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function clearCacheAction()
try {
/** @var $cache \Doctrine\Common\Cache\CacheProvider */
$cache = $this->serviceLocator->get('ZfrRest\Resource\Metadata\CacheProvider');
} catch(Exception $e) {
} catch (Exception $e) {
return "\nNo cache to clear. Are you sure you set ZfrRest cache correctly?\n\n";
}

if($cache->flushAll()) {
if ($cache->flushAll()) {
return "\nThe cache were successfully cleared\n\n";
}

Expand Down
5 changes: 4 additions & 1 deletion src/ZfrRest/Factory/CreateResourcePayloadListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class CreateResourcePayloadListenerFactory implements FactoryInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return new CreateResourcePayloadListener($serviceLocator->get('HydratorManager'));
/* @var $hydratorManager \Zend\Stdlib\Hydrator\HydratorPluginManager */
$hydratorManager = $serviceLocator->get('HydratorManager');

return new CreateResourcePayloadListener($hydratorManager);
}
}
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
81 changes: 81 additions & 0 deletions src/ZfrRest/Factory/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

namespace ZfrRest\Factory\Exception;

use Exception;
use RuntimeException as BaseRuntimeException;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfrRest\Exception\ExceptionInterface;

/**
Expand All @@ -29,4 +31,83 @@
*/
class RuntimeException extends BaseRuntimeException implements ExceptionInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
*
* @return self
*/
public static function pluginManagerExpected(ServiceLocatorInterface $serviceLocator)
{
return new self(
sprintf('A hydrator plugin manager was expected, but "%s" was given', get_class($serviceLocator))
);
}

/**
* @param string $resourceName
* @param Exception|null $previous
*
* @return self
*/
public static function missingResource($resourceName, Exception $previous = null)
{
return new self(sprintf('Resource "%s" cannot be found in the service locator', $resourceName), 0, $previous);
}

/**
* @param string $serviceName
* @param Exception|null $previous
*
* @return self
*/
public static function missingObjectManager($serviceName, Exception $previous = null)
{
return new self(sprintf('The object manager key is not valid, "%s" given', $serviceName), 0, $previous);
}

/**
* @param string $serviceName
* @param mixed $objectManager
*
* @return self
*/
public static function invalidObjectManager($serviceName, $objectManager)
{
return new self(
sprintf(
'Invalid ObjectManager retrieved for service "%s", instance of "%s" found',
$serviceName,
is_object($objectManager) ? get_class($objectManager) : gettype($objectManager)
)
);
}

/**
* @param string $serviceName
* @param mixed $cache
*
* @return self
*/
public static function invalidCache($serviceName, $cache)
{
return new self(
sprintf(
'Invalid CacheInterface retrieved for service "%s", instance of "%s" found',
$serviceName,
is_object($cache) ? get_class($cache) : gettype($cache)
)
);
}

/**
* @param string $driverClass
*
* @return self
*/
public static function invalidDriverClass($driverClass)
{
return new self(
sprintf('Unrecognized driver class "%s" given', $driverClass)
);
}
}
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']);
}
}
12 changes: 7 additions & 5 deletions src/ZfrRest/Factory/PaginatorHydratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Stdlib\Hydrator\HydratorPluginManager;
use ZfrRest\Stdlib\Hydrator\PaginatorHydrator;
use ZfrRest\Factory\Exception\RuntimeException;

/**
* PaginatorHydratorFactory
Expand All @@ -33,14 +34,15 @@ class PaginatorHydratorFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*
* @return PaginatorHydrator
*
* @throws RuntimeException
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
if (!$serviceLocator instanceof HydratorPluginManager) {
throw new Exception\RuntimeException(sprintf(
'A hydrator plugin manager was expected, but "%s" was given',
get_class($serviceLocator)
));
if (! $serviceLocator instanceof HydratorPluginManager) {
throw RuntimeException::pluginManagerExpected($serviceLocator);
}

return new PaginatorHydrator($serviceLocator);
Expand Down
32 changes: 21 additions & 11 deletions src/ZfrRest/Factory/ResourceGraphRouteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@

namespace ZfrRest\Factory;

use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\MutableCreationOptionsInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfrRest\Factory\Exception\RuntimeException;
use ZfrRest\Mvc\Router\Http\ResourceGraphRoute;

/**
* Factory responsible of instantiating an {@see \ZfrRest\Mvc\Router\Http\ResourceGraphRoute}
*/
class ResourceGraphRouteFactory implements FactoryInterface, MutableCreationOptionsInterface
{
/**
Expand All @@ -50,23 +55,28 @@ public function setCreationOptions(array $creationOptions)

/**
* {@inheritDoc}
*
* @return ResourceGraphRoute
*
* @throws RuntimeException
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var $parentLocator \Zend\ServiceManager\ServiceManager */
if (! $serviceLocator instanceof AbstractPluginManager) {
throw RuntimeException::pluginManagerExpected($serviceLocator);
}

$parentLocator = $serviceLocator->getServiceLocator();

if (!$parentLocator->has($this->creationOptions['resource'])) {
throw new RuntimeException(sprintf(
'Resource "%s" cannot be found from service locator',
$this->creationOptions['resource']
));
try {
$resource = $parentLocator->get($this->creationOptions['resource']);
} catch (ServiceNotFoundException $exception) {
throw RuntimeException::missingResource($this->creationOptions['resource'], $exception);
}

return new ResourceGraphRoute(
$parentLocator->get('ZfrRest\Resource\Metadata\MetadataFactory'),
$parentLocator->get($this->creationOptions['resource']),
$this->creationOptions['route']
);
/* @var $metadataFactory \Metadata\MetadataFactoryInterface */
$metadataFactory = $parentLocator->get('ZfrRest\Resource\Metadata\MetadataFactory');

return new ResourceGraphRoute($metadataFactory, $resource, $this->creationOptions['route']);
}
}
3 changes: 3 additions & 0 deletions src/ZfrRest/Factory/ResourceMetadataCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Factory responsible of instantiating a doctrine cache for metadata
*/
class ResourceMetadataCacheFactory implements FactoryInterface
{
/**
Expand Down
Loading

0 comments on commit fb8534a

Please sign in to comment.