Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for the Zend\Filter\Encrypt and Zend\Filter\Compress adapters #181

Merged
merged 1 commit into from

2 participants

@ezimuel
Owner

This PR fix the issue #163 and also the Zend\Filter\Compress\* adapters. I attached a new event in Module.php during the EVENT_ROUTE that transform a Zend\Filter\[Encrypt|Compress]\x adapter in Zend\Filter\[Encrypt|Compress] with the option 'adapters' -> 'x'.

@weierophinney weierophinney commented on the diff
Module.php
((5 lines not shown))
}
-
+
+ /**
+ * Adjust the filter options in presence of adapters of Zend\Filter
+ *
+ * @param \Zend\Mvc\MvcEvent $e
+ */
+ public function onRoute(MvcEvent $e)
+ {
+ $request = $e->getRequest();
+ if (!$request->isPut()) {
+ return;
+ }
+ $data = json_decode($request->getContent());
@weierophinney Owner

If we do this after ContentNegotiation has run, we can just grab the parameter container; I'll take care of that during merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney merged commit 4f8c23d into zfcampus:master

1 check failed

Details continuous-integration/travis-ci The Travis CI build failed
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#181] Refactor to standalone listener class
Per discussion with @ezimuel, refactored listener to its own class. In doing so,
also altered it to operate inside the content negotiation -> content validation
workflow, pulling and operating on the data discovered by content negotiation.

Also wrote unit tests for the listener to ensure the expected behavior is
honored for all possible request scenarios.
c59a5f7
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/181'
Close #181
Fixes #163
7201cc8
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/181' into develop
Forward port #181
a96f21f
@weierophinney weierophinney added this to the 1.0.2 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 1 deletion.
  1. +3 −0  .gitignore
  2. +37 −1 Module.php
View
3  .gitignore
@@ -19,3 +19,6 @@ vendor/sebastian/
vendor/symfony/
vendor/zendframework/
vendor/zfcampus/
+.project
+.buildpath
+.settings
View
38 Module.php
@@ -14,6 +14,7 @@
use ZF\Hal\Entity;
use ZF\Hal\View\HalJsonModel;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
+use ReflectionClass;
class Module
{
@@ -39,8 +40,43 @@ public function onBootstrap(MvcEvent $e)
$events = $app->getEventManager();
$events->attach(MvcEvent::EVENT_RENDER, array($this, 'onRender'), 100);
$events->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish'), 1000);
+ $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute'), 600);
}
-
+
+ /**
+ * Adjust the filter options in presence of adapters of Zend\Filter
+ *
+ * @param \Zend\Mvc\MvcEvent $e
+ */
+ public function onRoute(MvcEvent $e)
+ {
+ $request = $e->getRequest();
+ if (!$request->isPut()) {
+ return;
+ }
+ $data = json_decode($request->getContent());
@weierophinney Owner

If we do this after ContentNegotiation has run, we can just grab the parameter container; I'll take care of that during merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (!isset($data[0]->filters)) {
+ return;
+ }
+ for ($i=0; $i < count($data[0]->filters); $i++) {
+ if (!isset($data[0]->filters[$i]->name)) {
+ continue;
+ }
+ $filter = $data[0]->filters[$i]->name;
+ $class = new ReflectionClass($filter);
+ // if filter implements CompressionAlgorithmInterface or EncryptionAlgorithmInterface
+ // we change the filter's name to the parent and we add the adapter param to filter's name
+ if ($class->implementsInterface('Zend\Filter\Compress\CompressionAlgorithmInterface') ||
+ $class->implementsInterface('Zend\Filter\Encrypt\EncryptionAlgorithmInterface')) {
+ $name = substr($filter, 0, strrpos($filter, '\\'));
+ $adapter = substr($filter, strrpos($filter, '\\') + 1);
+ $data[0]->filters[$i]->name = $name;
+ $data[0]->filters[$i]->options->adapter = $adapter;
+ }
+ }
+ $request->setContent(json_encode($data));
+ }
+
public function getAutoloaderConfig()
{
$this->disableOpCache();
Something went wrong with that request. Please try again.