Skip to content

Commit

Permalink
Refactor code to use parameter, return type hints
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jan 14, 2024
1 parent c493ad1 commit 9482487
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/ApiResources/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Categories extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Currencies extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class Customers extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/DiningTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class DiningTables extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Locations extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/MenuItemOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class MenuItemOptions extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/MenuOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class MenuOptions extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Menus extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Orders extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Reservations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Reservations extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
2 changes: 1 addition & 1 deletion src/ApiResources/Reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class Reviews extends ApiController
{
public $implement = [\Igniter\Api\Http\Actions\RestController::class];
public array $implement = [\Igniter\Api\Http\Actions\RestController::class];

public $restConfig = [
'actions' => [
Expand Down
36 changes: 34 additions & 2 deletions src/Classes/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,52 @@
use Igniter\Admin\Traits\ValidatesForm;
use Igniter\Api\Traits\AuthorizesRequest;
use Igniter\Api\Traits\CreatesResponse;
use Igniter\Flame\Support\Extendable;
use Igniter\Flame\Traits\EventEmitter;
use Igniter\System\Classes\BaseController;
use Illuminate\Contracts\Support\Responsable;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

class ApiController extends BaseController
class ApiController extends Extendable
{
use AuthorizesRequest;
use CreatesResponse;
use ValidatesForm;
use EventEmitter;

public $allowedActions = [];
public array $allowedActions = [];

/**
* @var array Default actions which cannot be called as actions.
*/
public $hiddenActions = [
'checkAction',
'execPageAction',
'handleError',
];

/**
* @var array Token abilities required to access methods on this controller.
* ex. ['orders.*']
*/
protected $requiredAbilities;

/**
* @var int Response status code
*/
protected $statusCode = 200;

/**
* Class constructor
*/
public function __construct()
{
$this->extendableConstruct();

$this->fireSystemEvent('api.controller.beforeConstructor', [$this]);
}

public function getAbilities()
{
return $this->requiredAbilities;
Expand Down Expand Up @@ -67,6 +94,11 @@ public function checkAction($action)
return $methodExists;
}

public function setStatusCode($code)
{
$this->statusCode = $code;
}

protected function authorizeToken()
{
if (!$ability = $this->getAbilities()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Console/stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Igniter\Api\Classes\ApiController;
*/
class {{studly_name}} extends ApiController
{
public $implement = [
public array $implement = [
\Igniter\Api\Http\Actions\RestController::class
];

Expand Down
4 changes: 2 additions & 2 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function boot()
$this->sanctumConfigureMiddleware();
}

public function registerNavigation()
public function registerNavigation(): array
{
return [
'tools' => [
Expand All @@ -76,7 +76,7 @@ public function registerNavigation()
];
}

public function registerPermissions()
public function registerPermissions(): array
{
return [
'Igniter.Api.Manage' => [
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Actions/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RestController extends ControllerAction
/**
* {@inheritdoc}
*/
protected $requiredProperties = ['restConfig'];
protected array $requiredProperties = ['restConfig'];

/**
* @var array Configuration values that must exist when applying the primary config file.
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Controllers/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
class Resources extends \Igniter\Admin\Classes\AdminController
{
public $implement = [
public array $implement = [
\Igniter\Admin\Http\Actions\FormController::class,
\Igniter\Admin\Http\Actions\ListController::class,
];

public $listConfig = [
public array $listConfig = [
'list' => [
'model' => \Igniter\Api\Models\Resource::class,
'title' => 'APIs',
Expand All @@ -24,7 +24,7 @@ class Resources extends \Igniter\Admin\Classes\AdminController
],
];

public $formConfig = [
public array $formConfig = [
'name' => 'APIs',
'model' => \Igniter\Api\Models\Resource::class,
'request' => \Igniter\Api\Requests\ResourceRequest::class,
Expand All @@ -43,7 +43,7 @@ class Resources extends \Igniter\Admin\Classes\AdminController
'configFile' => 'resource',
];

protected $requiredPermissions = 'Igniter.Api.*';
protected null|string|array $requiredPermissions = 'Igniter.Api.*';

public function __construct()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
class Tokens extends \Igniter\Admin\Classes\AdminController
{
public $implement = [
public array $implement = [
\Igniter\Admin\Http\Actions\ListController::class,
];

public $listConfig = [
public array $listConfig = [
'list' => [
'model' => \Igniter\Api\Models\Token::class,
'title' => 'igniter.api::default.text_tokens_title',
Expand All @@ -27,7 +27,7 @@ class Tokens extends \Igniter\Admin\Classes\AdminController
],
];

protected $requiredPermissions = 'Igniter.Api.*';
protected null|string|array $requiredPermissions = 'Igniter.Api.*';

public function __construct()
{
Expand Down

0 comments on commit 9482487

Please sign in to comment.