From d7e191fef7a44f9e07e96d590e66ef448160ce32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sat, 3 Oct 2015 17:54:04 +0200 Subject: [PATCH 1/8] Fixed serialization for ProfilerExtension to prevent serialize() of closures --- Twig/ProfilerExtension.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Twig/ProfilerExtension.php b/Twig/ProfilerExtension.php index 43da92b..3478b68 100644 --- a/Twig/ProfilerExtension.php +++ b/Twig/ProfilerExtension.php @@ -6,6 +6,7 @@ use Asm89\Twig\CacheExtension\Extension as Asm89_Extension; use EmanueleMinotto\TwigCacheBundle\Strategy\ProfilerStrategy; use Exception; +use Serializable; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; @@ -13,7 +14,7 @@ /** * {@inheritdoc} */ -class ProfilerExtension extends Asm89_Extension implements DataCollectorInterface +class ProfilerExtension extends Asm89_Extension implements DataCollectorInterface, Serializable { /** * Data about fetchBlock requests. @@ -108,4 +109,37 @@ public function getData() 'strategyClass' => $this->strategyClass, ]; } + + /** + * String representation of object + * @link http://php.net/manual/en/serializable.serialize.php + * @return string the string representation of the object or null + * @since 5.1.0 + */ + public function serialize() + { + return $this->getData(); + } + + /** + * Constructs the object + * @link http://php.net/manual/en/serializable.unserialize.php + * @param string $serialized

+ * The string representation of the object. + *

+ * @return void + * @since 5.1.0 + */ + public function unserialize($serialized) + { + $data = unserialize($serialized); + + if(is_array($data)) { + $this->fetchBlock = $data['fetchBlock']; + $this->generateKey = $data['generateKey']; + $this->hits = $data['hits']; + $this->strategyClass = $data['strategyClass']; + } + } + } From a8f47c67eac5a86fe1844606b6d19c61bdaac576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sat, 3 Oct 2015 18:39:50 +0200 Subject: [PATCH 2/8] fixed missing serialize --- Twig/ProfilerExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Twig/ProfilerExtension.php b/Twig/ProfilerExtension.php index 3478b68..9cb433d 100644 --- a/Twig/ProfilerExtension.php +++ b/Twig/ProfilerExtension.php @@ -118,7 +118,7 @@ public function getData() */ public function serialize() { - return $this->getData(); + return serialize( $this->getData() ); } /** From f46938c3f9452bd0762957ce673923fdb2301e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sat, 3 Oct 2015 18:40:57 +0200 Subject: [PATCH 3/8] Added Tests for ProfilerExtension --- .../ProfilerExtensionTest.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Tests/ProfilerExtension/ProfilerExtensionTest.php diff --git a/Tests/ProfilerExtension/ProfilerExtensionTest.php b/Tests/ProfilerExtension/ProfilerExtensionTest.php new file mode 100644 index 0000000..ff1635e --- /dev/null +++ b/Tests/ProfilerExtension/ProfilerExtensionTest.php @@ -0,0 +1,54 @@ +kernel = new AppKernel('TwigCacheExtensionTest', true); + $this->kernel->boot(); + } + + /** + * @covers ::load + */ + public function testSerialization() + { + $container = $this->kernel->getContainer(); + + $cacheStrategy = $container->get('twig_cache.strategy.generational'); + $extension = new ProfilerExtension($cacheStrategy); + + $extension->addFetchBlock('foo', true); + $extension->addGenerateKey('generation_key', 123); + + $data = $extension->getData(); + + $serializedData = serialize( $extension ); + + /** @var ProfilerExtension $unserialized */ + $unserialized = unserialize($serializedData); + + $this->assertInstanceOf('EmanueleMinotto\TwigCacheBundle\Twig\ProfilerExtension', $unserialized); + $dataUnserialized = $unserialized->getData(); + + $this->assertEquals($data, $dataUnserialized); + } + +} From 444d75f405c8b5283c98e1c477328b7082e3fc43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sat, 3 Oct 2015 18:55:16 +0200 Subject: [PATCH 4/8] applied code style-patch from StyleCI --- .../ProfilerExtensionTest.php | 3 +-- Twig/ProfilerExtension.php | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Tests/ProfilerExtension/ProfilerExtensionTest.php b/Tests/ProfilerExtension/ProfilerExtensionTest.php index ff1635e..737e356 100644 --- a/Tests/ProfilerExtension/ProfilerExtensionTest.php +++ b/Tests/ProfilerExtension/ProfilerExtensionTest.php @@ -40,7 +40,7 @@ public function testSerialization() $data = $extension->getData(); - $serializedData = serialize( $extension ); + $serializedData = serialize($extension); /** @var ProfilerExtension $unserialized */ $unserialized = unserialize($serializedData); @@ -50,5 +50,4 @@ public function testSerialization() $this->assertEquals($data, $dataUnserialized); } - } diff --git a/Twig/ProfilerExtension.php b/Twig/ProfilerExtension.php index 9cb433d..affd975 100644 --- a/Twig/ProfilerExtension.php +++ b/Twig/ProfilerExtension.php @@ -111,35 +111,41 @@ public function getData() } /** - * String representation of object + * String representation of object. + * * @link http://php.net/manual/en/serializable.serialize.php + * * @return string the string representation of the object or null + * * @since 5.1.0 */ public function serialize() { - return serialize( $this->getData() ); + return serialize($this->getData()); } /** - * Constructs the object + * Constructs the object. + * * @link http://php.net/manual/en/serializable.unserialize.php + * * @param string $serialized

- * The string representation of the object. - *

+ * The string representation of the object. + *

+ * * @return void + * * @since 5.1.0 */ public function unserialize($serialized) { $data = unserialize($serialized); - if(is_array($data)) { + if (is_array($data)) { $this->fetchBlock = $data['fetchBlock']; $this->generateKey = $data['generateKey']; $this->hits = $data['hits']; $this->strategyClass = $data['strategyClass']; } } - } From 53dfb4f2af219da918b078626cafed04d1fc88e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sun, 4 Oct 2015 00:04:21 +0200 Subject: [PATCH 5/8] removed the html-code in docs --- Twig/ProfilerExtension.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Twig/ProfilerExtension.php b/Twig/ProfilerExtension.php index affd975..d2ac5bd 100644 --- a/Twig/ProfilerExtension.php +++ b/Twig/ProfilerExtension.php @@ -129,10 +129,7 @@ public function serialize() * * @link http://php.net/manual/en/serializable.unserialize.php * - * @param string $serialized

- * The string representation of the object. - *

- * + * @param string $serialized * @return void * * @since 5.1.0 From e6136794072666f98ff8485bd9049f251ae0cd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sun, 4 Oct 2015 00:05:56 +0200 Subject: [PATCH 6/8] changed travis-related code --- Tests/ProfilerExtension/ProfilerExtensionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/ProfilerExtension/ProfilerExtensionTest.php b/Tests/ProfilerExtension/ProfilerExtensionTest.php index 737e356..ab00a8f 100644 --- a/Tests/ProfilerExtension/ProfilerExtensionTest.php +++ b/Tests/ProfilerExtension/ProfilerExtensionTest.php @@ -26,7 +26,8 @@ protected function setUp() } /** - * @covers ::load + * @covers ::serialize + * @covers ::unserialize */ public function testSerialization() { From 33ddd3304b4a6390afd2fa4e56d3c388b173175a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sun, 4 Oct 2015 00:18:24 +0200 Subject: [PATCH 7/8] StyleCI ... --- Twig/ProfilerExtension.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Twig/ProfilerExtension.php b/Twig/ProfilerExtension.php index d2ac5bd..5e9713a 100644 --- a/Twig/ProfilerExtension.php +++ b/Twig/ProfilerExtension.php @@ -114,9 +114,7 @@ public function getData() * String representation of object. * * @link http://php.net/manual/en/serializable.serialize.php - * * @return string the string representation of the object or null - * * @since 5.1.0 */ public function serialize() @@ -131,7 +129,6 @@ public function serialize() * * @param string $serialized * @return void - * * @since 5.1.0 */ public function unserialize($serialized) From 9c38d0503dba89cd5837da49290dac2de6f9be6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hagen=20H=C3=BCbel?= Date: Sun, 4 Oct 2015 10:53:09 +0200 Subject: [PATCH 8/8] StyleCI changed its oppinion regarding empty lines in doc blocks --- Twig/ProfilerExtension.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Twig/ProfilerExtension.php b/Twig/ProfilerExtension.php index 5e9713a..d1f1be2 100644 --- a/Twig/ProfilerExtension.php +++ b/Twig/ProfilerExtension.php @@ -114,7 +114,9 @@ public function getData() * String representation of object. * * @link http://php.net/manual/en/serializable.serialize.php + * * @return string the string representation of the object or null + * * @since 5.1.0 */ public function serialize() @@ -128,7 +130,9 @@ public function serialize() * @link http://php.net/manual/en/serializable.unserialize.php * * @param string $serialized + * * @return void + * * @since 5.1.0 */ public function unserialize($serialized)