This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from TomHAnderson/feature/create-filter
Added Query Create Filters
- Loading branch information
Showing
9 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace ZF\Apigility\Doctrine\Server\Query\CreateFilter; | ||
|
||
use ZF\Apigility\Doctrine\Server\Query\CreateFilter\QueryCreateFilterInterface; | ||
use DoctrineModule\Persistence\ObjectManagerAwareInterface; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
use ZF\ApiProblem\ApiProblem; | ||
use ZF\Rest\ResourceEvent; | ||
|
||
/** | ||
* Class DefaultCreateFilter | ||
* | ||
* @package ZF\Apigility\Doctrine\Server\Query\CreateFilter | ||
*/ | ||
class DefaultCreateFilter implements ObjectManagerAwareInterface, QueryCreateFilterInterface | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
protected $objectManager; | ||
|
||
/** | ||
* Set the object manager | ||
* | ||
* @param ObjectManager $objectManager | ||
*/ | ||
public function setObjectManager(ObjectManager $objectManager) | ||
{ | ||
$this->objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* Get the object manager | ||
* | ||
* @return ObjectManager | ||
*/ | ||
public function getObjectManager() | ||
{ | ||
return $this->objectManager; | ||
} | ||
|
||
/** | ||
* @param string $entityClass | ||
* @param array $data | ||
* | ||
* @return array | ||
*/ | ||
public function filter(ResourceEvent $event, $entityClass, $data) | ||
{ | ||
return $data; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Server/Query/CreateFilter/QueryCreateFilterInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace ZF\Apigility\Doctrine\Server\Query\CreateFilter; | ||
|
||
use DoctrineModule\Persistence\ObjectManagerAwareInterface; | ||
use ZF\Rest\ResourceEvent; | ||
|
||
interface QueryCreateFilterInterface extends ObjectManagerAwareInterface | ||
{ | ||
/** | ||
* @param string $entityClass | ||
* @param array $data | ||
* | ||
* @return array | ||
*/ | ||
public function filter(ResourceEvent $event, $entityClass, $data); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Server/Query/CreateFilter/Service/QueryCreateFilterManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace ZF\Apigility\Doctrine\Server\Query\CreateFilter\Service; | ||
|
||
use ZF\Apigility\Doctrine\Server\Query\CreateFilter\QueryCreateFilterInterface; | ||
use Zend\ServiceManager\AbstractPluginManager; | ||
use Zend\ServiceManager\Exception; | ||
|
||
class QueryCreateFilterManager extends AbstractPluginManager | ||
{ | ||
protected $invokableClasses = array(); | ||
|
||
/** | ||
* @param mixed $plugin | ||
* | ||
* @return void | ||
* @throws Exception\RuntimeException | ||
*/ | ||
public function validatePlugin($plugin) | ||
{ | ||
if ($plugin instanceof QueryCreateFilterInterface) { | ||
// we're okay | ||
return; | ||
} | ||
|
||
// @codeCoverageIgnoreStart | ||
throw new Exception\RuntimeException( | ||
sprintf( | ||
'Plugin of type %s is invalid; must implement QueryCreateFilterInterface', | ||
(is_object($plugin) ? get_class($plugin) : gettype($plugin)) | ||
) | ||
); | ||
// @codeCoverageIgnoreEnd | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Server/Query/CreateFilter/Service/QueryCreateFilterManagerFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace ZF\Apigility\Doctrine\Server\Query\CreateFilter\Service; | ||
|
||
use Zend\Mvc\Service\AbstractPluginManagerFactory; | ||
|
||
class QueryCreateFilterManagerFactory extends AbstractPluginManagerFactory | ||
{ | ||
const PLUGIN_MANAGER_CLASS = 'ZF\Apigility\Doctrine\Server\Query\CreateFilter\Service\QueryCreateFilterManager'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters