Core and composer updates

This commit is contained in:
Rob Davies 2017-07-03 16:47:07 +01:00
parent a82634bb98
commit 62cac30480
1118 changed files with 21770 additions and 6306 deletions

View file

@ -23,14 +23,14 @@ use \Drupal\Component\Annotation\Plugin;
class RestResource extends Plugin {
/**
* The resource plugin ID.
* The REST resource plugin ID.
*
* @var string
*/
public $id;
/**
* The human-readable name of the resource plugin.
* The human-readable name of the REST resource plugin.
*
* @ingroup plugin_translatable
*
@ -41,8 +41,22 @@ class RestResource extends Plugin {
/**
* The serialization class to deserialize serialized data into.
*
* @see \Symfony\Component\Serializer\SerializerInterface's "type" parameter.
*
* @var string (optional)
*/
public $serialization_class;
/**
* The URI paths that this REST resource plugin provides.
*
* Key-value pairs, with link relation type plugin IDs as keys, and URL
* templates as values.
*
* @see core/core.link_relation_types.yml
*
* @var string[]
*/
public $uri_paths = [];
}

View file

@ -111,16 +111,6 @@ abstract class ResourceBase extends PluginBase implements ContainerFactoryPlugin
switch ($method) {
case 'POST':
$route->setPath($create_path);
// Restrict the incoming HTTP Content-type header to the known
// serialization formats.
$route->addRequirements(['_content_type_format' => implode('|', $this->serializerFormats)]);
$collection->add("$route_name.$method", $route);
break;
case 'PATCH':
// Restrict the incoming HTTP Content-type header to the known
// serialization formats.
$route->addRequirements(['_content_type_format' => implode('|', $this->serializerFormats)]);
$collection->add("$route_name.$method", $route);
break;

View file

@ -11,7 +11,6 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
/**
@ -89,29 +88,19 @@ class RequestHandler implements ContainerAwareInterface, ContainerInjectionInter
if (!empty($received)) {
$format = $request->getContentType();
// Only allow serialization formats that are explicitly configured. If no
// formats are configured allow all and hope that the serializer knows the
// format. If the serializer cannot handle it an exception will be thrown
// that bubbles up to the client.
$request_method = $request->getMethod();
if (in_array($format, $resource_config->getFormats($request_method))) {
$definition = $resource->getPluginDefinition();
try {
if (!empty($definition['serialization_class'])) {
$unserialized = $serializer->deserialize($received, $definition['serialization_class'], $format, ['request_method' => $method]);
}
// If the plugin does not specify a serialization class just decode
// the received data.
else {
$unserialized = $serializer->decode($received, $format, ['request_method' => $method]);
}
$definition = $resource->getPluginDefinition();
try {
if (!empty($definition['serialization_class'])) {
$unserialized = $serializer->deserialize($received, $definition['serialization_class'], $format, ['request_method' => $method]);
}
catch (UnexpectedValueException $e) {
throw new BadRequestHttpException($e->getMessage());
// If the plugin does not specify a serialization class just decode
// the received data.
else {
$unserialized = $serializer->decode($received, $format, ['request_method' => $method]);
}
}
else {
throw new UnsupportedMediaTypeHttpException();
catch (UnexpectedValueException $e) {
throw new BadRequestHttpException($e->getMessage());
}
}

View file

@ -113,8 +113,15 @@ class ResourceRoutes extends RouteSubscriberBase {
continue;
}
// The configuration seems legit at this point, so we set the
// authentication provider and add the route.
// The configuration has been validated, so we update the route to:
// - set the allowed request body content types/formats for methods that
// allow request bodies to be sent
// - set the allowed authentication providers
if (in_array($method, ['POST', 'PATCH', 'PUT'], TRUE)) {
// Restrict the incoming HTTP Content-type header to the allowed
// formats.
$route->addRequirements(['_content_type_format' => implode('|', $rest_resource_config->getFormats($method))]);
}
$route->setOption('_auth', $rest_resource_config->getAuthenticationProviders($method));
$route->setDefault('_rest_resource_config', $rest_resource_config->id());
$collection->add("rest.$name", $route);