comparison core/modules/rest/src/RequestHandler.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
67 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match 67 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
68 * The route match. 68 * The route match.
69 * @param \Symfony\Component\HttpFoundation\Request $request 69 * @param \Symfony\Component\HttpFoundation\Request $request
70 * The HTTP request object. 70 * The HTTP request object.
71 * @param \Drupal\rest\RestResourceConfigInterface $_rest_resource_config 71 * @param \Drupal\rest\RestResourceConfigInterface $_rest_resource_config
72 * REST resource config entity ID. 72 * The REST resource config entity.
73 * 73 *
74 * @return \Drupal\rest\ResourceResponseInterface|\Symfony\Component\HttpFoundation\Response 74 * @return \Drupal\rest\ResourceResponseInterface|\Symfony\Component\HttpFoundation\Response
75 * The REST resource response. 75 * The REST resource response.
76 */ 76 */
77 public function handle(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config) { 77 public function handle(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config) {
78 $response = $this->delegateToRestResourcePlugin($route_match, $request, $_rest_resource_config->getResourcePlugin()); 78 $resource = $_rest_resource_config->getResourcePlugin();
79 79 $unserialized = $this->deserialize($route_match, $request, $resource);
80 $response = $this->delegateToRestResourcePlugin($route_match, $request, $unserialized, $resource);
81 return $this->prepareResponse($response, $_rest_resource_config);
82 }
83
84 /**
85 * Handles a REST API request without deserializing the request body.
86 *
87 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
88 * The route match.
89 * @param \Symfony\Component\HttpFoundation\Request $request
90 * The HTTP request object.
91 * @param \Drupal\rest\RestResourceConfigInterface $_rest_resource_config
92 * The REST resource config entity.
93 *
94 * @return \Symfony\Component\HttpFoundation\Response|\Drupal\rest\ResourceResponseInterface
95 * The REST resource response.
96 */
97 public function handleRaw(RouteMatchInterface $route_match, Request $request, RestResourceConfigInterface $_rest_resource_config) {
98 $resource = $_rest_resource_config->getResourcePlugin();
99 $response = $this->delegateToRestResourcePlugin($route_match, $request, NULL, $resource);
100 return $this->prepareResponse($response, $_rest_resource_config);
101 }
102
103 /**
104 * Prepares the REST resource response.
105 *
106 * @param \Drupal\rest\ResourceResponseInterface $response
107 * The REST resource response.
108 * @param \Drupal\rest\RestResourceConfigInterface $resource_config
109 * The REST resource config entity.
110 *
111 * @return \Drupal\rest\ResourceResponseInterface
112 * The prepared REST resource response.
113 */
114 protected function prepareResponse($response, RestResourceConfigInterface $resource_config) {
80 if ($response instanceof CacheableResponseInterface) { 115 if ($response instanceof CacheableResponseInterface) {
81 $response->addCacheableDependency($_rest_resource_config); 116 $response->addCacheableDependency($resource_config);
82 // Add global rest settings config's cache tag, for BC flags. 117 // Add global rest settings config's cache tag, for BC flags.
83 // @see \Drupal\rest\Plugin\rest\resource\EntityResource::permissions() 118 // @see \Drupal\rest\Plugin\rest\resource\EntityResource::permissions()
84 // @see \Drupal\rest\EventSubscriber\RestConfigSubscriber 119 // @see \Drupal\rest\EventSubscriber\RestConfigSubscriber
85 // @todo Remove in https://www.drupal.org/node/2893804 120 // @todo Remove in https://www.drupal.org/node/2893804
86 $response->addCacheableDependency($this->configFactory->get('rest.settings')); 121 $response->addCacheableDependency($this->configFactory->get('rest.settings'));
179 * 214 *
180 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match 215 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
181 * The route match. 216 * The route match.
182 * @param \Symfony\Component\HttpFoundation\Request $request 217 * @param \Symfony\Component\HttpFoundation\Request $request
183 * The HTTP request object. 218 * The HTTP request object.
219 * @param mixed|null $unserialized
220 * The unserialized request body, if any.
184 * @param \Drupal\rest\Plugin\ResourceInterface $resource 221 * @param \Drupal\rest\Plugin\ResourceInterface $resource
185 * The REST resource plugin. 222 * The REST resource plugin.
186 * 223 *
187 * @return \Symfony\Component\HttpFoundation\Response|\Drupal\rest\ResourceResponseInterface 224 * @return \Symfony\Component\HttpFoundation\Response|\Drupal\rest\ResourceResponseInterface
188 * The REST resource response. 225 * The REST resource response.
189 */ 226 */
190 protected function delegateToRestResourcePlugin(RouteMatchInterface $route_match, Request $request, ResourceInterface $resource) { 227 protected function delegateToRestResourcePlugin(RouteMatchInterface $route_match, Request $request, $unserialized, ResourceInterface $resource) {
191 $unserialized = $this->deserialize($route_match, $request, $resource);
192 $method = static::getNormalizedRequestMethod($route_match); 228 $method = static::getNormalizedRequestMethod($route_match);
193 229
194 // Determine the request parameters that should be passed to the resource 230 // Determine the request parameters that should be passed to the resource
195 // plugin. 231 // plugin.
196 $argument_resolver = $this->createArgumentResolver($route_match, $unserialized, $request); 232 $argument_resolver = $this->createArgumentResolver($route_match, $unserialized, $request);