Browse Source

adds support for Sequence classes to allow for lazy-initialization

Johannes M. Schmitt 12 years ago
parent
commit
c7f70c7e83
3 changed files with 40 additions and 31 deletions
  1. 1 1
      composer.json
  2. 28 28
      composer.lock
  3. 11 2
      src/JMS/Serializer/Exclusion/DisjunctExclusionStrategy.php

+ 1 - 1
composer.json

@@ -16,7 +16,7 @@
         "jms/metadata": ">=1.1.0,<1.3-dev",
         "jms/parser-lib": "1.*",
         "phpcollection/phpcollection": ">=0.1,<0.3-dev",
-        "doctrine/common": "2.*"
+        "doctrine/annotations": "1.*"
     },
     "suggest": {
         "symfony/yaml": "Required if you'd like to serialize data to YAML format."

+ 28 - 28
composer.lock

@@ -1,5 +1,5 @@
 {
-    "hash": "0599f6f9e4a017f1c8f8109e6f65b2e7",
+    "hash": "5473f12acced6bf3f3da3dd99decfe65",
     "packages": [
         {
             "name": "doctrine/annotations",
@@ -472,12 +472,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/schmittjoh/php-collection.git",
-                "reference": "2b9f71b9261930b05c3cd1d6ee2baa423b830e39"
+                "reference": "7a4daeec1cc3ac3900cfd8a77ded4bea9ed5ed66"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/2b9f71b9261930b05c3cd1d6ee2baa423b830e39",
-                "reference": "2b9f71b9261930b05c3cd1d6ee2baa423b830e39",
+                "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/7a4daeec1cc3ac3900cfd8a77ded4bea9ed5ed66",
+                "reference": "7a4daeec1cc3ac3900cfd8a77ded4bea9ed5ed66",
                 "shasum": ""
             },
             "require": {
@@ -502,7 +502,7 @@
                 {
                     "name": "Johannes M. Schmitt",
                     "email": "schmittjoh@gmail.com",
-                    "homepage": "http://jmsyst.com",
+                    "homepage": "https://github.com/schmittjoh",
                     "role": "Developer of wrapped JMSSerializerBundle"
                 }
             ],
@@ -514,7 +514,7 @@
                 "sequence",
                 "set"
             ],
-            "time": "2013-02-20 19:38:18"
+            "time": "2013-02-25 09:55:06"
         },
         {
             "name": "phpoption/phpoption",
@@ -702,12 +702,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/EventDispatcher.git",
-                "reference": "e1d18ff0ff6f3e45ac82f000bc221135df635527"
+                "reference": "v2.1.8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/e1d18ff0ff6f3e45ac82f000bc221135df635527",
-                "reference": "e1d18ff0ff6f3e45ac82f000bc221135df635527",
+                "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.1.8",
+                "reference": "v2.1.8",
                 "shasum": ""
             },
             "require": {
@@ -798,12 +798,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Form.git",
-                "reference": "b711596ffd136b372ac74bdbabd818a42afe3003"
+                "reference": "v2.1.8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Form/zipball/b711596ffd136b372ac74bdbabd818a42afe3003",
-                "reference": "b711596ffd136b372ac74bdbabd818a42afe3003",
+                "url": "https://api.github.com/repos/symfony/Form/zipball/v2.1.8",
+                "reference": "v2.1.8",
                 "shasum": ""
             },
             "require": {
@@ -851,12 +851,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Locale.git",
-                "reference": "v2.1.7"
+                "reference": "v2.1.8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Locale/zipball/v2.1.7",
-                "reference": "v2.1.7",
+                "url": "https://api.github.com/repos/symfony/Locale/zipball/v2.1.8",
+                "reference": "v2.1.8",
                 "shasum": ""
             },
             "require": {
@@ -896,12 +896,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/OptionsResolver.git",
-                "reference": "v2.1.7"
+                "reference": "v2.1.8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/OptionsResolver/zipball/v2.1.7",
-                "reference": "v2.1.7",
+                "url": "https://api.github.com/repos/symfony/OptionsResolver/zipball/v2.1.8",
+                "reference": "v2.1.8",
                 "shasum": ""
             },
             "require": {
@@ -943,12 +943,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Translation.git",
-                "reference": "v2.1.7"
+                "reference": "v2.1.8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Translation/zipball/v2.1.7",
-                "reference": "v2.1.7",
+                "url": "https://api.github.com/repos/symfony/Translation/zipball/v2.1.8",
+                "reference": "v2.1.8",
                 "shasum": ""
             },
             "require": {
@@ -993,12 +993,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Validator.git",
-                "reference": "974a4ceb6cc0fc38ead35962a884b6af6b0ac762"
+                "reference": "v2.1.8"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Validator/zipball/974a4ceb6cc0fc38ead35962a884b6af6b0ac762",
-                "reference": "974a4ceb6cc0fc38ead35962a884b6af6b0ac762",
+                "url": "https://api.github.com/repos/symfony/Validator/zipball/v2.1.8",
+                "reference": "v2.1.8",
                 "shasum": ""
             },
             "require": {
@@ -1091,12 +1091,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/fabpot/Twig.git",
-                "reference": "15336c154c960f7e55e8b9fc1043ce7764ed7edc"
+                "reference": "4458a2cb66a016440543ef34a07f540e14bee92e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/fabpot/Twig/zipball/15336c154c960f7e55e8b9fc1043ce7764ed7edc",
-                "reference": "15336c154c960f7e55e8b9fc1043ce7764ed7edc",
+                "url": "https://api.github.com/repos/fabpot/Twig/zipball/4458a2cb66a016440543ef34a07f540e14bee92e",
+                "reference": "4458a2cb66a016440543ef34a07f540e14bee92e",
                 "shasum": ""
             },
             "require": {
@@ -1132,7 +1132,7 @@
             "keywords": [
                 "templating"
             ],
-            "time": "2013-02-21 06:47:52"
+            "time": "2013-02-25 06:01:12"
         }
     ],
     "aliases": [

+ 11 - 2
src/JMS/Serializer/Exclusion/DisjunctExclusionStrategy.php

@@ -21,6 +21,8 @@ namespace JMS\Serializer\Exclusion;
 use JMS\Serializer\Context;
 use JMS\Serializer\Metadata\ClassMetadata;
 use JMS\Serializer\Metadata\PropertyMetadata;
+use PhpCollection\Sequence;
+use PhpCollection\SequenceInterface;
 
 /**
  * Disjunct Exclusion Strategy.
@@ -31,13 +33,18 @@ use JMS\Serializer\Metadata\PropertyMetadata;
  */
 class DisjunctExclusionStrategy implements ExclusionStrategyInterface
 {
+    /** @var \PhpCollection\SequenceInterface */
     private $delegates;
 
     /**
-     * @param ExclusionStrategyInterface[] $delegates
+     * @param ExclusionStrategyInterface[]|SequenceInterface $delegates
      */
-    public function __construct(array $delegates)
+    public function __construct($delegates)
     {
+        if ( ! $delegates instanceof SequenceInterface) {
+            $delegates = new Sequence($delegates);
+        }
+
         $this->delegates = $delegates;
     }
 
@@ -52,6 +59,7 @@ class DisjunctExclusionStrategy implements ExclusionStrategyInterface
     public function shouldSkipClass(ClassMetadata $metadata, Context $context)
     {
         foreach ($this->delegates as $delegate) {
+            /** @var $delegate ExclusionStrategyInterface */
             if ($delegate->shouldSkipClass($metadata, $context)) {
                 return true;
             }
@@ -71,6 +79,7 @@ class DisjunctExclusionStrategy implements ExclusionStrategyInterface
     public function shouldSkipProperty(PropertyMetadata $property, Context $context)
     {
         foreach ($this->delegates as $delegate) {
+            /** @var $delegate ExclusionStrategyInterface */
             if ($delegate->shouldSkipProperty($property, $context)) {
                 return true;
             }