Make Method Extendable

This commit is contained in:
Bradley Schofield
2025-01-22 11:08:23 +09:00
parent cf8da3495c
commit 5123cf5f8e
3 changed files with 19 additions and 9 deletions
+17 -7
View File
@@ -57,12 +57,12 @@ class Method
}
}
private function getRouteName(): string
protected function getRouteName(): string
{
return $this->namespace . '.' . $this->name;
}
private function validateMethod(string $name, string $namespace): void
protected function validateMethod(string $name, string $namespace): void
{
if (\in_array($this->getRouteName(), self::$processed)) {
self::$errors[] = "Error with {$this->getRouteName()} method: Method already exists in namespace {$namespace}";
@@ -71,7 +71,7 @@ class Method
self::$processed[] = $this->getRouteName();
}
private function validateAuthTypes(array $authTypes): void
protected function validateAuthTypes(array $authTypes): void
{
foreach ($authTypes as $authType) {
if (!($authType instanceof AuthType)) {
@@ -80,14 +80,14 @@ class Method
}
}
private function validateDesc(string $desc): void
protected function validateDesc(string $desc): void
{
if (empty($desc)) {
self::$errors[] = "Error with {$this->getRouteName()} method: Description label is empty";
return;
}
$descPath = \realpath(__DIR__ . '/../../../' . $desc);
$descPath = $this->getDescriptionFilePath();
if (!\file_exists($descPath)) {
self::$errors[] = "Error with {$this->getRouteName()} method: Description file not found at {$desc}";
@@ -95,7 +95,7 @@ class Method
}
}
private function validateResponseModel(string|array $responseModel): void
protected function validateResponseModel(string|array $responseModel): void
{
$response = new Response(new HttpResponse());
@@ -112,7 +112,7 @@ class Method
}
}
private function validateNoContent(SDKResponse $response): void
protected function validateNoContent(SDKResponse $response): void
{
if ($response->getCode() === 204) {
if ($response->getModel() !== Response::MODEL_NONE) {
@@ -136,6 +136,16 @@ class Method
return $this->description;
}
/**
* This method returns the absolute path to the description file returning null if the file does not exist.
*
* @return string|null
*/
public function getDescriptionFilePath(): ?string
{
return \realpath(__DIR__ . '/../../../' . $this->getDescription()) ?: null;
}
public function getAuth(): array
{
return $this->auth;
@@ -148,7 +148,7 @@ class OpenAPI3 extends Format
$method = array_keys($method)[0];
}
$desc = (!empty($sdk->getDescription())) ? \realpath(__DIR__ . '/../../../../' . $sdk->getDescription()) : null;
$desc = $sdk->getDescriptionFilePath();
$produces = ($sdk->getContentType())->value;
$routeSecurity = $sdk->getAuth() ?? [];
$sdkPlatforms = [];
@@ -144,7 +144,7 @@ class Swagger2 extends Format
$method = array_keys($method)[0];
}
$desc = (!empty($sdk->getDescription())) ? \realpath(__DIR__ . '/../../../../' . $sdk->getDescription()) : null;
$desc = $sdk->getDescriptionFilePath();
$produces = ($sdk->getContentType())->value;
$routeSecurity = $sdk->getAuth() ?? [];
$sdkPlatforms = [];