-
Notifications
You must be signed in to change notification settings - Fork 31
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 #179 from zf-fr/id
Add coalesce filtering
- Loading branch information
Showing
11 changed files
with
330 additions
and
5 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
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,42 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrRest\Factory; | ||
|
||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
use ZfrRest\Mvc\Controller\MethodHandler\GetHandler; | ||
use ZfrRest\Mvc\Controller\MethodHandler\PostHandler; | ||
|
||
/** | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
class GetHandlerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function createService(ServiceLocatorInterface $serviceLocator) | ||
{ | ||
/** @var ServiceLocatorInterface $parentLocator */ | ||
$parentLocator = $serviceLocator->getServiceLocator(); | ||
|
||
return new GetHandler($parentLocator->get('ZfrRest\Options\ModuleOptions')); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
namespace ZfrRest\Options; | ||
|
||
use Zend\Stdlib\AbstractOptions; | ||
use ZfrRest\Exception\InvalidArgumentException; | ||
|
||
/** | ||
* @author Michaël Gallego <[email protected]> | ||
|
@@ -61,6 +62,23 @@ class ModuleOptions extends AbstractOptions | |
*/ | ||
protected $registerHttpMethodOverrideListener = false; | ||
|
||
/** | ||
* Is the enable coalesce filtering enabled? | ||
* | ||
* If enabled, it allows the REST router to filter a collection list by identifiers. For instance, considering | ||
* a query /customers?$ids[]=1&$ids[]=2, it will be able to return a filtered collections | ||
* | ||
* @var bool | ||
*/ | ||
protected $enableCoalesceFiltering = false; | ||
|
||
/** | ||
* The coalesce filtering query key | ||
* | ||
* @var string | ||
*/ | ||
protected $coalesceFilteringQueryKey = '$ids'; | ||
|
||
/** | ||
* @param array|null $options | ||
*/ | ||
|
@@ -160,4 +178,41 @@ public function getRegisterHttpMethodOverrideListener() | |
{ | ||
return $this->registerHttpMethodOverrideListener; | ||
} | ||
|
||
/** | ||
* @param boolean $enableCoalesceFiltering | ||
*/ | ||
public function setEnableCoalesceFiltering($enableCoalesceFiltering) | ||
{ | ||
$this->enableCoalesceFiltering = (bool) $enableCoalesceFiltering; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isEnableCoalesceFiltering() | ||
{ | ||
return $this->enableCoalesceFiltering; | ||
} | ||
|
||
/** | ||
* @param string $coalesceFilteringQueryKey | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function setCoalesceFilteringQueryKey($coalesceFilteringQueryKey) | ||
{ | ||
if (empty($coalesceFilteringQueryKey)) { | ||
throw new InvalidArgumentException('Coalesce filtering key cannot be an empty value'); | ||
} | ||
|
||
$this->coalesceFilteringQueryKey = (string) $coalesceFilteringQueryKey; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getCoalesceFilteringQueryKey() | ||
{ | ||
return $this->coalesceFilteringQueryKey; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. | ||
*/ | ||
|
||
namespace ZfrRestTest\Factory; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Zend\ServiceManager\ServiceManager; | ||
use ZfrRest\Factory\GetHandlerFactory; | ||
use ZfrRest\Mvc\Controller\MethodHandler\MethodHandlerPluginManager; | ||
use ZfrRest\Options\ModuleOptions; | ||
|
||
/** | ||
* @licence MIT | ||
* @author Michaël Gallego <[email protected]> | ||
* | ||
* @group Coverage | ||
* @covers \ZfrRest\Factory\GetHandlerFactory | ||
*/ | ||
class GetHandlerFactoryTest extends PHPUnit_Framework_TestCase | ||
{ | ||
public function testCreateFromFactory() | ||
{ | ||
$serviceManager = new ServiceManager(); | ||
|
||
$pluginManager = new MethodHandlerPluginManager(); | ||
$pluginManager->setServiceLocator($serviceManager); | ||
|
||
$serviceManager->setService('ZfrRest\Options\ModuleOptions', new ModuleOptions()); | ||
|
||
$factory = new GetHandlerFactory(); | ||
$result = $factory->createService($pluginManager); | ||
|
||
$this->assertInstanceOf('ZfrRest\Mvc\Controller\MethodHandler\GetHandler', $result); | ||
} | ||
} |
Oops, something went wrong.