Commit 254d709b authored by webchick's avatar webchick

Issue #1903784 by linclark, damiankloip, effulgentsia: Move serialization to own module.

parent e72ff704
......@@ -12,7 +12,6 @@
use Drupal\Core\DependencyInjection\Compiler\RegisterMatchersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterRouteFiltersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterRouteEnhancersPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterSerializationClassesPass;
use Drupal\Core\DependencyInjection\Compiler\RegisterParamConvertersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -268,20 +267,6 @@ public function build(ContainerBuilder $container) {
$container
->register('transliteration', 'Drupal\Core\Transliteration\PHPTransliteration');
// Add Serializer with arguments to be replaced in the compiler pass.
$container->register('serializer', 'Symfony\Component\Serializer\Serializer')
->addArgument(array())
->addArgument(array());
$container->register('serializer.normalizer.complex_data', 'Drupal\Core\Serialization\ComplexDataNormalizer')->addTag('normalizer');
$container->register('serializer.normalizer.list', 'Drupal\Core\Serialization\ListNormalizer')->addTag('normalizer');
$container->register('serializer.normalizer.typed_data', 'Drupal\Core\Serialization\TypedDataNormalizer')->addTag('normalizer');
$container->register('serializer.encoder.json', 'Drupal\Core\Serialization\JsonEncoder')
->addTag('encoder', array('format' => array('json' => 'JSON')));
$container->register('serializer.encoder.xml', 'Drupal\Core\Serialization\XmlEncoder')
->addTag('encoder', array('format' => array('xml' => 'XML')));
$container->register('flood', 'Drupal\Core\Flood\DatabaseBackend')
->addArgument(new Reference('database'));
......@@ -289,8 +274,6 @@ public function build(ContainerBuilder $container) {
$container->addCompilerPass(new RegisterRouteFiltersPass());
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
// Add a compiler pass for adding Normalizers and Encoders to Serializer.
$container->addCompilerPass(new RegisterSerializationClassesPass());
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new RegisterAccessChecksPass());
......
......@@ -4,3 +4,4 @@ package = Core
version = VERSION
core = 8.x
dependencies[] = rdf
dependencies[] = serialization
......@@ -5,4 +5,5 @@ version = VERSION
core = 8.x
; @todo Remove this dependency once hard coding to JSON-LD is gone.
dependencies[] = jsonld
dependencies[] = serialization
configure = admin/config/services/rest
......@@ -2,10 +2,10 @@
/**
* @file
* Contains Drupal\Core\Serialization\JsonEncoder.
* Contains \Drupal\serialization\Encoder\JsonEncoder.
*/
namespace Drupal\Core\Serialization;
namespace Drupal\serialization\Encoder;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Encoder\JsonEncoder as BaseJsonEncoder;
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\Core\Serialization\XmlEncoder.
* Contains \Drupal\serialization\Encoder\XmlEncoder.
*/
namespace Drupal\Core\Serialization;
namespace Drupal\serialization\Encoder;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
......
......@@ -2,12 +2,11 @@
/**
* @file
* Contains \Drupal\Core\Serialization\ComplexDataNormalizer.
* Contains \Drupal\serialization\Normalizer\ComplexDataNormalizer.
*/
namespace Drupal\Core\Serialization;
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Serialization\NormalizerBase;
use Symfony\Component\Serializer\Exception\RuntimeException;
/**
......
......@@ -2,12 +2,11 @@
/**
* @file
* Contains \Drupal\Core\Serialization\ListNormalizer.
* Contains \Drupal\serialization\Normalizer\ListNormalizer.
*/
namespace Drupal\Core\Serialization;
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Serialization\NormalizerBase;
use Symfony\Component\Serializer\Exception\RuntimeException;
/**
......
......@@ -2,12 +2,11 @@
/**
* @file
* Contains Drupal\Core\Serialization\NormalizerBase.
* Contains \Drupal\serialization\Normalizer\NormalizerBase.
*/
namespace Drupal\Core\Serialization;
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
......
......@@ -2,12 +2,11 @@
/**
* @file
* Contains \Drupal\Core\Serialization\TypedDataNormalizer.
* Contains \Drupal\serialization\Normalizer\TypedDataNormalizer.
*/
namespace Drupal\Core\Serialization;
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Serialization\NormalizerBase;
use Symfony\Component\Serializer\Exception\RuntimeException;
/**
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains Drupal\serialization\RegisterSerializationClassesPass.
* Contains \Drupal\serialization\RegisterSerializationClassesCompilerPass.
*/
namespace Drupal\Core\DependencyInjection\Compiler;
namespace Drupal\serialization;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
......@@ -14,7 +14,7 @@
/**
* Adds services tagged 'normalizer' and 'encoder' to the Serializer.
*/
class RegisterSerializationClassesPass implements CompilerPassInterface {
class RegisterSerializationClassesCompilerPass implements CompilerPassInterface {
/**
* Adds services to the Serializer.
......
<?php
/**
* @file
* Contains \Drupal\serialization\SerializationBundle.
*/
namespace Drupal\serialization;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Serialization dependency injection container.
*/
class SerializationBundle extends Bundle {
/**
* Overrides \Symfony\Component\HttpKernel\Bundle\Bundle::build().
*/
public function build(ContainerBuilder $container) {
// Add Serializer with arguments to be replaced in the compiler pass.
$container->register('serializer', 'Symfony\Component\Serializer\Serializer')
->addArgument(array())
->addArgument(array());
$container->register('serializer.normalizer.complex_data', 'Drupal\serialization\Normalizer\ComplexDataNormalizer')->addTag('normalizer');
$container->register('serializer.normalizer.list', 'Drupal\serialization\Normalizer\ListNormalizer')->addTag('normalizer');
$container->register('serializer.normalizer.typed_data', 'Drupal\serialization\Normalizer\TypedDataNormalizer')->addTag('normalizer');
$container->register('serializer.encoder.json', 'Drupal\serialization\Encoder\JsonEncoder')
->addTag('encoder', array('format' => array('json' => 'JSON')));
$container->register('serializer.encoder.xml', 'Drupal\serialization\Encoder\XmlEncoder')
->addTag('encoder', array('format' => array('xml' => 'XML')));
// Add a compiler pass for adding Normalizers and Encoders to Serializer.
$container->addCompilerPass(new RegisterSerializationClassesCompilerPass());
}
}
......@@ -2,16 +2,16 @@
/**
* @file
* Contains \Drupal\system\Tests\Serialization\EntitySerializationTest.
* Contains \Drupal\serialization\Tests\EntitySerializationTest.
*/
namespace Drupal\system\Tests\Serialization;
namespace Drupal\serialization\Tests;
use Drupal\serialization\Encoder\JsonEncoder;
use Drupal\serialization\Normalizer\ComplexDataNormalizer;
use Drupal\serialization\Normalizer\TypedDataNormalizer;
use Drupal\simpletest\WebTestBase;
use Symfony\Component\Serializer\Serializer;
use Drupal\Core\Serialization\JsonEncoder;
use Drupal\Core\Serialization\ComplexDataNormalizer;
use Drupal\Core\Serialization\TypedDataNormalizer;
/**
* Tests entity normalization and serialization of supported core formats.
......@@ -23,7 +23,7 @@ class EntitySerializationTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('entity_test');
public static $modules = array('entity_test', 'serialization');
/**
* The test values.
......
......@@ -2,10 +2,10 @@
/**
* @file
* Definition of Drupal\system\Tests\Serialization\SerializationTest.
* Contains \Drupal\serialization\Tests\SerializationTest.
*/
namespace Drupal\system\Tests\Serialization;
namespace Drupal\serialization\Tests;
use Drupal\simpletest\WebTestBase;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
......@@ -17,12 +17,12 @@ class SerializationTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('serialization_test');
public static $modules = array('serialization', 'serialization_test');
/**
* The serializer service to test.
*
* @var Symfony\Component\Serializer\SerializerInterface
* @var \Symfony\Component\Serializer\SerializerInterface
*/
protected $serializer;
......
name = Serialization
description = Provides a service for (de)serializing data to/from formats such as JSON and XML
package = Core
core = 8.x
......@@ -2,14 +2,13 @@
/**
* @file
* Definition of Drupal\serialization_test\SerializationTestBundle.
* Contains \Drupal\serialization_test\SerializationTestBundle.
*/
namespace Drupal\serialization_test;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\Serializer\Serializer;
/**
* SerializationTest dependency injection container.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\serialization_test\SerializationTestEncoder.
* Contains \Drupal\serialization_test\SerializationTestEncoder.
*/
namespace Drupal\serialization_test;
......@@ -19,15 +19,7 @@ class SerializationTestEncoder implements EncoderInterface {
static protected $format = 'serialization_test';
/**
* Encodes data into the requested format.
*
* @param mixed $data
* Data to encode.
* @param string $format
* Format name.
*
* @return string
* A string representation of $data in the requested format.
* Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::encode().
*/
public function encode($data, $format, array $context = array()) {
// @see Drupal\serialization_test\SerializationTestNormalizer::normalize().
......@@ -35,13 +27,7 @@ public function encode($data, $format, array $context = array()) {
}
/**
* Checks whether this encoder can encode to the requested format.
*
* @param string $format
* The short name of the format.
*
* @return bool
* Returns TRUE if this encoder can encode to the requested format.
* Implements \Symfony\Component\Serializer\Encoder\EncoderInterface::supportsEncoding().
*/
public function supportsEncoding($format) {
return static::$format === $format;
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\serialization_test\SerializationTestNormalizer.
* Contains \Drupal\serialization_test\SerializationTestNormalizer.
*/
namespace Drupal\serialization_test;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment