/** * @param ResourceFactory $factory * @param ResourceMethod $method * * @return ReflectionParameter[] */ public function getMethodArgumentTypes(ResourceFactory $factory, ResourceMethod $method) { $classReflector = new ReflectionClass($factory->getController()); $methodReflector = $classReflector->getMethod($method->getMethod()); return $methodReflector->getParameters(); }
/** * @param ConferenceContext $context * @param ResourceFactory $factory * @param bool $reflect * @param int $id * * @return Div */ protected function renderResource(ConferenceContext $context, ResourceFactory $factory, $reflect = false, $id = 0) { return new Div([], [new Card([], [new CardHeader([], [Std::coalesce($factory->getPrefix(), '/'), ' ', new Italic(['class' => ['fa', 'fa-arrow-circle-right ']]), ' ', new Anchor(['href' => $context->method('illuminated.conference.application', 'single', ['resource' => $id])], new Bold([], $factory->getController()))]), new CardBlock([], [new Paragraph([], [new Bold([], 'Middleware: '), implode(', ', $factory->getMiddleware())]), new Div([], Std::map(function (ResourceMethod $method) use($factory, $reflect) { return $this->renderRoute($factory, $method, $reflect); }, $factory->getMethods()))])])]); }
protected function encodeResource(ResourceFactory $resource, RamlEncoderOptions $options) { $controller = $this->app->make($resource->getController()); $ramlResource = ['displayName' => $resource->getName(), 'description' => $resource->getDescription()]; foreach ($resource->getMethods() as $method) { $ramlAction = ['securedBy' => $this->middlewareToSecuritySchemes($options, $resource->getMiddleware())]; if ($controller instanceof AnnotatedControllerInterface) { $ramlAction['description'] = $controller->getMethodDescription($method->getMethod()); $ramlAction['body'] = $this->requestsToBody($controller->getMethodExampleRequests($method->getMethod()))->toArray(); $ramlAction['responses'] = $this->responsesToGroup($controller->getMethodExampleResponses($method->getMethod()))->toArray(); } else { $ramlAction['description'] = 'This method does not provide a description'; } $reflector = new ResourceReflector($this->app); $request = $reflector->getMethodRequest($resource, $method); $uriParameters = []; $queryParameters = []; if ($request instanceof ApiCheckableRequest) { $spec = $request->getCheckable(); if ($spec instanceof Validator) { $spec = $spec->getSpec(); } if ($spec instanceof Spec) { if ($method->getVerb() == HttpMethods::POST || $method->getVerb() == HttpMethods::PUT || $method->getVerb() == HttpMethods::DELETE) { $this->addPostSchema($ramlResource, $ramlAction, $uriParameters, $resource, $method, $spec, $reflector); } else { $parameters = $reflector->getMethodParameters($resource, $method); $fields = array_unique(array_merge(array_keys($spec->getConstraints()), array_keys($spec->getDefaults()), $spec->getRequired())); foreach ($fields as $field) { if (in_array($field, $parameters)) { $uriParameters[$field] = $this->specFieldToParameter($spec, $field); continue; } $queryParameters[$field] = $this->specFieldToParameter($spec, $field); } } } } if (!Arr::has($ramlResource, $method->getPath())) { $ramlResource[$method->getPath()] = []; } $ramlResource[$method->getPath()]['uriParameters'] = $uriParameters; $ramlAction['queryParameters'] = $queryParameters; $verb = strtolower($method->getVerb()); $ramlResource[$method->getPath()][$verb] = RamlUtils::filterEmptyValues($ramlAction); $ramlResource[$method->getPath()] = RamlUtils::filterEmptyValues($ramlResource[$method->getPath()]); } return RamlUtils::filterEmptyValues($ramlResource); }