public function testConfigureExposurePullRequestWithExplicitExpose() { $routeMetaData = new RouteMetaData(); $explicit_expose = array('username', 'email'); $routeMetaData->setExpose($explicit_expose); $expose = ExposeFields::create($routeMetaData); $request = new Request(); $request->setPost('expose', 'username|address'); $expose->configurePullRequest(array(Configuration::EXPOSE_REQUEST_PARAM_POST => 'expose'), $request); $this->assertEquals($explicit_expose, $expose->toArray()); }
/** * Check if the client has requested the CG classes with an OPTIONS call * @return bool */ protected function doCGOptionsCheck() { $genClasses = $this->request->getHeaders(ClassGenerator::HEADER_PARAM); if ($this->request->getHttpMethod() != Request::METHOD_OPTIONS || empty($genClasses)) { return false; } $classGenerator = new ClassGenerator($this->em); $classMetadatas = array(); if (!empty($genClasses)) { foreach ($this->metadataFactory->getAllClassNames() as $className) { $metaData = $this->getClassMetadata($className); foreach ($metaData->getRoutesMetaData() as $route) { /* @var RouteMetaData $route */ $route->setExpose(Query\ExposeFields::create($route)->configureExposeDepth($this->em, $this->config->getExposureDepth(), $this->config->getExposureRelationsFetchType())->toArray()); } $classMetadatas[] = $metaData; } } $classGenerator->create($classMetadatas); $this->response->setBody($classGenerator->serialize()); return true; }
/** * Handle a push requests' exposure configuration (POST/PUT/PATCH) * @param RouteMetaData $route - the matched route * @param AbstractRepresentation $representation - the representation class to be used * @return AbstractRepresentation $representation */ protected function handlePushExposureConfiguration(RouteMetaData $route, AbstractRepresentation $representation) { $representation = $representation::createFromString($this->request->getBody()); // Write the filtered expose data $representation->write(ExposeFields::create($route)->configureExposeDepth($this->emr, $this->config->getExposureDepth(), $this->config->getExposureRelationsFetchType())->configurePushRequest($representation->toArray())); return $representation; }