Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,14 @@
<?php
/**
* @file
* Contains \Drupal\Component\Serialization\Exception\InvalidDataTypeException.
*/
namespace Drupal\Component\Serialization\Exception;
/**
* Exception thrown when a data type is invalid.
*/
class InvalidDataTypeException extends \InvalidArgumentException {
}

View file

@ -0,0 +1,41 @@
<?php
/**
* @file
* Contains \Drupal\Component\Serialization\Json.
*/
namespace Drupal\Component\Serialization;
/**
* Default serialization for JSON.
*
* @ingroup third_party
*/
class Json implements SerializationInterface {
/**
* {@inheritdoc}
*
* Uses HTML-safe strings, with several characters escaped.
*/
public static function encode($variable) {
// Encode <, >, ', &, and ".
return json_encode($variable, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
}
/**
* {@inheritdoc}
*/
public static function decode($string) {
return json_decode($string, TRUE);
}
/**
* {@inheritdoc}
*/
public static function getFileExtension() {
return 'json';
}
}

View file

@ -0,0 +1,36 @@
<?php
/**
* @file
* Contains \Drupal\Component\Serialization\PhpSerialize.
*/
namespace Drupal\Component\Serialization;
/**
* Default serialization for serialized PHP.
*/
class PhpSerialize implements SerializationInterface {
/**
* {@inheritdoc}
*/
public static function encode($data) {
return serialize($data);
}
/**
* {@inheritdoc}
*/
public static function decode($raw) {
return unserialize($raw);
}
/**
* {@inheritdoc}
*/
public static function getFileExtension() {
return 'serialized';
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* @file
* Contains \Drupal\Component\Serialization\SerializationInterface.
*/
namespace Drupal\Component\Serialization;
/**
* Defines an interface for serialization formats.
*/
interface SerializationInterface {
/**
* Encodes data into the serialization format.
*
* @param mixed $data
* The data to encode.
*
* @return string
* The encoded data.
*/
public static function encode($data);
/**
* Decodes data from the serialization format.
*
* @param string $raw
* The raw data string to decode.
*
* @return mixed
* The decoded data.
*/
public static function decode($raw);
/**
* Gets the file extension for this serialization format.
*
* @return string
* The file extension, without leading dot.
*/
public static function getFileExtension();
}

View file

@ -0,0 +1,55 @@
<?php
/**
* @file
* Contains \Drupal\Component\Serialization\Yaml.
*/
namespace Drupal\Component\Serialization;
use Drupal\Component\Serialization\Exception\InvalidDataTypeException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;
/**
* Default serialization for YAML using the Symfony component.
*/
class Yaml implements SerializationInterface {
/**
* {@inheritdoc}
*/
public static function encode($data) {
try {
$yaml = new Dumper();
$yaml->setIndentation(2);
return $yaml->dump($data, PHP_INT_MAX, 0, TRUE, FALSE);
}
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* {@inheritdoc}
*/
public static function decode($raw) {
try {
$yaml = new Parser();
// Make sure we have a single trailing newline. A very simple config like
// 'foo: bar' with no newline will fail to parse otherwise.
return $yaml->parse($raw, TRUE, FALSE);
}
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* {@inheritdoc}
*/
public static function getFileExtension() {
return 'yml';
}
}