瀏覽代碼

Merge pull request #2 from lsmith77/group

merged master .. fixed some small issues noted by @schmittjoh
Christian Stocker 13 年之前
父節點
當前提交
e642916f89

+ 17 - 4
Resources/doc/cookbook/custom_handlers.rst

@@ -1,5 +1,8 @@
 Custom De-/Serialization Handlers
----------------------------------
+=================================
+
+Introduction
+------------
 This allows you to change the way of how a specifc type is being de-/serialized.
 
 Any handler must implement either the ``SerializationHandlerInterface``, or
@@ -10,18 +13,26 @@ can use as a starting point.
 Custom handlers are normal services, and thus can have dependencies on any
 other service available in the dependency injection container.
 
+Configuration
+-------------
 After you have written your handler, you can write a service definition. Such
-as the following::
+as the following:
+
+.. code-block :: xml
 
     <service id="acme_foo.serializer.my_handler"
              class="Acme\FooBundle\Serializer\MyHandler"
              public="false"
              />
              
+The Handler Factory
+-------------------
 What is left to do is to publish our new handler to this bundle. So it gets
 picked up, and wired correctly. In order to do this, this bundle uses a 
 configuration system similar to that of the SecurityBundle. Each handler needs 
-a corresponding definition factory::
+a corresponding definition factory:
+
+.. code-block :: php
 
     <?php
     
@@ -62,7 +73,9 @@ in the ``addConfiguration`` method, and then process that configuration in the
 ``getHandlerId`` method. 
 
 The last thing left to do, is to add this factory to this bundle. This is
-done by adding a ``configureSerializerExtension`` to your bundle class::
+done by adding a ``configureSerializerExtension`` to your bundle class:
+
+.. code-block :: php
 
     <?php
     

+ 5 - 3
Resources/doc/cookbook/versioning_objects.rst

@@ -4,7 +4,7 @@ JMSSerializerBundle comes by default with a very neat feature which allows
 you to add versioning support to your objects, e.g. if you want to
 expose them via an API that is consumed by a third-party:
 
-::
+.. code-block :: php
 
     <?php
 
@@ -27,9 +27,11 @@ expose them via an API that is consumed by a third-party:
     ``@Until``, and ``@Since`` both accept a standardized PHP version number.
 
 If you have annotated your objects like above, you can serializing different
-versions like this::
+versions like this:
+
+.. code-block :: php
 
     <?php
 
     $serializer->setVersion('1.0');
-    $serializer->serialize(new VersionObject(), 'json');
+    $serializer->serialize(new VersionObject(), 'json');

+ 2 - 2
Resources/doc/installation.rst

@@ -14,13 +14,13 @@ To install JMSSerializerBundle with Composer just add the following to your
         // ...
         require: {
             // ...
-            "jms/serializer-bundle": "master-dev"
+            "jms/serializer-bundle": "dev-master"
         }
     }
     
 .. note ::
 
-    Please replace `master-dev` in the snippet above with the latest stable
+    Please replace `dev-master` in the snippet above with the latest stable
     branch, for example ``1.0.*``.
     
 Then, you can install the new dependencies by running Composer's ``update``

+ 32 - 12
Resources/doc/reference/annotations.rst

@@ -50,7 +50,11 @@ PHP's ``version_compare`` function.
 ~~~~~~~~~~~
 This annotation can be defined on a property, or a class to specify in which way
 the properties should be accessed. By default, the serializer will retrieve, or
-set the value via reflection, but you may change this to use a public method instead::
+set the value via reflection, but you may change this to use a public method instead:
+
+.. code-block :: php
+
+    <?php
 
     /** @AccessType("public_method") */
     class User
@@ -71,7 +75,11 @@ set the value via reflection, but you may change this to use a public method ins
 @Accessor
 ~~~~~~~~~
 This annotation can be defined on a property to specify which public method should
-be called to retrieve, or set the value of the given property::
+be called to retrieve, or set the value of the given property:
+
+.. code-block :: php
+
+    <?php
 
     class User
     {
@@ -98,7 +106,9 @@ This annotation can be defined on a class to control the order of properties. By
 default the order is undefined, but you may change it to either "alphabetical", or
 "custom".
 
-::
+.. code-block :: php
+    
+    <?php
 
     /** 
      * @AccessorOrder("alphabetical") 
@@ -191,7 +201,9 @@ Available Types:
 |                           | into Doctrine's ArrayCollection class.           |
 +---------------------------+--------------------------------------------------+
 
-Examples::
+Examples:
+
+.. code-block :: php
 
     <?php
 
@@ -236,7 +248,7 @@ Examples::
 ~~~~~~~~
 This allows you to specify the name of the top-level element.
 
-::
+.. code-block :: php
 
     <?php
 
@@ -248,7 +260,9 @@ This allows you to specify the name of the top-level element.
         private $name = 'Johannes';
     }
 
-Resulting XML::
+Resulting XML:
+
+.. code-block :: xml
 
     <user>
         <name><![CDATA[Johannes]]></name>
@@ -259,7 +273,7 @@ Resulting XML::
 This allows you to mark properties which should be set as attributes,
 and not as child elements.
 
-::
+.. code-block :: php
 
     <?php
 
@@ -272,7 +286,9 @@ and not as child elements.
         private $name = 'Johannes';
     }
 
-Resulting XML::
+Resulting XML:
+
+.. code-block :: xml
 
     <result id="1">
         <name><![CDATA[Johannes]]></name>
@@ -284,7 +300,7 @@ This allows you to mark properties which should be set as the value of the
 current element. Note that this has the limitation that any additional 
 properties of that object must have the @XmlAttribute annotation.
 
-::
+.. code-block :: php
 
     <?php
     
@@ -302,7 +318,9 @@ properties of that object must have the @XmlAttribute annotation.
         private $amount = 1.23;
     }
     
-Resulting XML::
+Resulting XML:
+
+.. code-block :: xml
 
     <price currency="EUR">1.23</price>
 
@@ -312,7 +330,7 @@ This allows you to define several properties of how arrays should be
 serialized. This is very similar to @XmlMap, and should be used if the
 keys of the array are not important.
 
-::
+.. code-block :: php
 
     <?php
 
@@ -341,7 +359,9 @@ keys of the array are not important.
         }
     }
 
-Resulting XML::
+Resulting XML:
+
+.. code-block :: xml
 
     <post>
         <comment>

+ 6 - 2
Serializer/Exclusion/GroupsExclusionStrategy.php

@@ -20,6 +20,7 @@ namespace JMS\SerializerBundle\Serializer\Exclusion;
 
 use JMS\SerializerBundle\Metadata\ClassMetadata;
 use JMS\SerializerBundle\Metadata\PropertyMetadata;
+use JMS\SerializerBundle\Exception\RuntimeException;
 
 class GroupsExclusionStrategy implements ExclusionStrategyInterface
 {
@@ -27,6 +28,10 @@ class GroupsExclusionStrategy implements ExclusionStrategyInterface
 
     public function __construct(array $groups)
     {
+        if (empty($groups)) {
+            throw new RuntimeException('Empty group array may not be configured for GroupsExclusionStrategy');
+        }
+
         foreach ($groups as $group) {
             $this->groups[$group] = true;
         }
@@ -42,7 +47,6 @@ class GroupsExclusionStrategy implements ExclusionStrategyInterface
      */
     public function shouldSkipProperty(PropertyMetadata $property)
     {
-        
         if (!$property->groups) {
             return true;
         }
@@ -55,4 +59,4 @@ class GroupsExclusionStrategy implements ExclusionStrategyInterface
 
         return true;
     }
-}
+}

+ 1 - 1
Serializer/Serializer.php

@@ -63,7 +63,7 @@ class Serializer implements SerializerInterface
             return;
         }
 
-        $this->exclusionStrategy = new GroupsExclusionStrategy($groups);
+        $this->exclusionStrategy = new GroupsExclusionStrategy((array) $groups);
     }
 
     public function serialize($data, $format)

+ 0 - 2
Tests/Serializer/BaseSerializationTest.php

@@ -422,7 +422,6 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
     {
         $serializer =  $this->getSerializer();
 
-                
         $groupsObject = new GroupsObject();
         
         $this->assertEquals($this->getContent('groups_all'), $serializer->serialize($groupsObject, $this->getFormat()));
@@ -438,7 +437,6 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
 
         $serializer->setGroups(array());
         $this->assertEquals($this->getContent('groups_all'), $serializer->serialize($groupsObject, $this->getFormat()));
-
     }
 
     abstract protected function getContent($key);

+ 0 - 1
Tests/Serializer/JsonSerializationTest.php

@@ -64,7 +64,6 @@ class JsonSerializationTest extends BaseSerializationTest
             $outputs['groups_all'] = '{"foo":"foo","foobar":"foobar","bar":"bar","none":"none"}';
             $outputs['groups_foo'] = '{"foo":"foo","foobar":"foobar"}';
             $outputs['groups_foobar'] = '{"foo":"foo","foobar":"foobar","bar":"bar"}';
-            
         }
 
         if (!isset($outputs[$key])) {

+ 2 - 1
composer.json

@@ -3,7 +3,8 @@
     "type": "symfony-bundle",
     "description": "Allows you to easily serialize, and deserialize object graphs of any complexity",
     "keywords": ["serialization", "deserialization", "json", "jaxb", "xml"],
-    "license": "Apache",
+    "homepage": "http://jmsyst.com/bundles/JMSSerializerBundle",
+    "license": "Apache2",
     "authors": [
         {
             "name": "Johannes M. Schmitt",