Skip to content

Commit

Permalink
Merge pull request #39 from Lomkit/fix/phpdoc
Browse files Browse the repository at this point in the history
💡 added most php docs missing
  • Loading branch information
GautierDele authored Sep 10, 2023
2 parents 6effe03 + f001f1a commit 2728103
Show file tree
Hide file tree
Showing 76 changed files with 2,494 additions and 104 deletions.
62 changes: 31 additions & 31 deletions config/rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,40 @@
'url' => '/', // Relative to current
'description' => 'The current server',
],
// [
// 'url' => '"https://my-server.com:{port}/{basePath}"',
// 'description' => 'Production server',
// 'variables' => [
// 'port' => [
// 'enum' => ['80', '443'],
// 'default' => '443'
// ],
// 'basePath' => [
// 'default' => 'v2',
// 'enum' => ['v1', 'v2'],
// ]
// ]
// ]
// [
// 'url' => '"https://my-server.com:{port}/{basePath}"',
// 'description' => 'Production server',
// 'variables' => [
// 'port' => [
// 'enum' => ['80', '443'],
// 'default' => '443'
// ],
// 'basePath' => [
// 'default' => 'v2',
// 'enum' => ['v1', 'v2'],
// ]
// ]
// ]
],
// See https://spec.openapis.org/oas/v3.1.0#security-scheme-object
'security' => [
// [
// 'type' => 'http',
// 'description' => 'description',
// 'scheme' => 'Bearer',
// 'bearerFormat' => 'JWT'
// ],
// [
// 'type' => 'oauth2',
// 'flows' => [
// 'authorizationCode' => [
// 'scopes' => ['write:pets'],
// 'tokenUrl' => 'https://example.com/api/oauth/token',
// 'authorizationUrl' => 'https://example.com/api/oauth/dialog',
// 'refreshUrl' => 'https://example.com/api/oauth/refresh',
// ]
// ]
// ]
// [
// 'type' => 'http',
// 'description' => 'description',
// 'scheme' => 'Bearer',
// 'bearerFormat' => 'JWT'
// ],
// [
// 'type' => 'oauth2',
// 'flows' => [
// 'authorizationCode' => [
// 'scopes' => ['write:pets'],
// 'tokenUrl' => 'https://example.com/api/oauth/token',
// 'authorizationUrl' => 'https://example.com/api/oauth/dialog',
// 'refreshUrl' => 'https://example.com/api/oauth/refresh',
// ]
// ]
// ]
],
],
];
25 changes: 11 additions & 14 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="SwaggerUI"
/>
<meta name="description" content="SwaggerUI" />
<title>SwaggerUI</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/[email protected]/swagger-ui-bundle.js" crossorigin></script>
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: '/vendor/rest/openapi.json',
dom_id: '#swagger-ui',
});
};
</script>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/[email protected]/swagger-ui-bundle.js" crossorigin></script>
<script>
window.onload = () => {
window.ui = SwaggerUIBundle({
url: '/vendor/rest/openapi.json',
dom_id: '#swagger-ui',
});
};
</script>
</body>
</html>
16 changes: 16 additions & 0 deletions src/Actions/Actionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public function actions(RestRequest $request): array
return [];
}

/**
* Check if a specific action exists.
*
* @param RestRequest $request
* @param string $actionKey
*
* @return bool
*/
public function actionExists(RestRequest $request, string $actionKey): bool
{
return collect($this->actions($request))
Expand All @@ -26,6 +34,14 @@ public function actionExists(RestRequest $request, string $actionKey): bool
});
}

/**
* Get a specific action instance.
*
* @param RestRequest $request
* @param string $actionKey
*
* @return Action
*/
public function action(RestRequest $request, string $actionKey): Action
{
return collect($this->actions($request))
Expand Down
50 changes: 50 additions & 0 deletions src/Concerns/PerformsRestOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

trait PerformsRestOperations
{
/**
* Retrieve details of a resource.
*
* @param DetailRequest $request
*
* @return array
*/
public function detail(DetailRequest $request)
{
$request->resource($resource = static::newResource());
Expand All @@ -25,6 +32,13 @@ public function detail(DetailRequest $request)
];
}

/**
* Search for resources based on the given criteria.
*
* @param SearchRequest $request
*
* @return mixed
*/
public function search(SearchRequest $request)
{
$request->resource($resource = static::newResource());
Expand All @@ -39,6 +53,13 @@ public function search(SearchRequest $request)
);
}

/**
* Mutate resources based on the given request data.
*
* @param MutateRequest $request
*
* @return mixed
*/
public function mutate(MutateRequest $request)
{
$request->resource($resource = static::newResource());
Expand All @@ -56,6 +77,14 @@ public function mutate(MutateRequest $request)
return $operations;
}

/**
* Perform a specific action on the resource.
*
* @param OperateRequest $request
* @param string $action
*
* @return mixed
*/
public function operate(OperateRequest $request, $action)
{
$request->resource($resource = static::newResource());
Expand All @@ -71,6 +100,13 @@ public function operate(OperateRequest $request, $action)
]);
}

/**
* Delete resources based on the given request.
*
* @param DestroyRequest $request
*
* @return mixed
*/
public function destroy(DestroyRequest $request)
{
$request->resource($resource = static::newResource());
Expand All @@ -92,6 +128,13 @@ public function destroy(DestroyRequest $request)
->responsable($models);
}

/**
* Restore resources based on the given request.
*
* @param RestoreRequest $request
*
* @return mixed
*/
public function restore(RestoreRequest $request)
{
$request->resource($resource = static::newResource());
Expand All @@ -114,6 +157,13 @@ public function restore(RestoreRequest $request)
->responsable($models);
}

/**
* Force delete resources based on the given request.
*
* @param ForceDestroyRequest $request
*
* @return mixed
*/
public function forceDelete(ForceDestroyRequest $request)
{
$request->resource($resource = static::newResource());
Expand Down
21 changes: 21 additions & 0 deletions src/Concerns/Relations/HasPivotFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,37 @@ trait HasPivotFields
protected array $pivotFields = [];
protected array $pivotRules = [];

/**
* Get the pivot fields.
*
* @return array
*/
public function getPivotFields()
{
return $this->pivotFields;
}

/**
* Set the pivot fields.
*
* @param array $pivotFields
*
* @return $this
*/
public function withPivotFields(array $pivotFields)
{
return tap($this, function () use ($pivotFields) {
$this->pivotFields = $pivotFields;
});
}

/**
* Set the pivot rules.
*
* @param array $pivotRules
*
* @return $this
*/
public function withPivotRules(array $pivotRules)
{
return tap($this, function () use ($pivotRules) {
Expand All @@ -27,6 +46,8 @@ public function withPivotRules(array $pivotRules)
}

/**
* Get the pivot rules.
*
* @return array
*/
public function getPivotRules(): array
Expand Down
10 changes: 9 additions & 1 deletion src/Concerns/Resource/ConfiguresRestParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public function fields(RestRequest $request): array
return [];
}

/**
* Get nested fields by prefixing them with a given prefix.
*
* @param RestRequest $request
* @param string $prefix
* @param array $loadedRelations
*
* @return array
*/
public function getNestedFields(RestRequest $request, string $prefix = '', array $loadedRelations = [])
{
if ($prefix !== '') {
Expand Down Expand Up @@ -45,7 +54,6 @@ function ($field) use ($prefix) {
// We push the pivot fields if they exists
...collect(method_exists($relation, 'getPivotFields') ? $relation->getPivotFields() : [])
->map(function ($field) use ($relation, $prefix) { return $prefix.$relation->relation.'.pivot.'.$field; })

);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Concerns/Resource/DisableAuthorizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

trait DisableAuthorizations
{
/**
* Check if authorizations are enabled.
*
* @return bool
*/
public function isAuthorizingEnabled(): bool
{
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/Concerns/Resource/DisableAutomaticGates.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

trait DisableAutomaticGates
{
/**
* Check if automatic gating is enabled.
*
* @return bool
*/
public function isAutomaticGatingEnabled(): bool
{
return false;
Expand Down
8 changes: 8 additions & 0 deletions src/Concerns/Resource/Paginable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

trait Paginable
{
/**
* Paginate the results of a query.
*
* @param Builder $query
* @param RestRequest $request
*
* @return mixed
*/
public function paginate(Builder $query, RestRequest $request)
{
return $query->paginate($request->input('limit', 50));
Expand Down
Loading

0 comments on commit 2728103

Please sign in to comment.