Skip to content

Commit

Permalink
update file
Browse files Browse the repository at this point in the history
  • Loading branch information
juancristobalgd1 authored Mar 27, 2024
1 parent f04d09a commit 67086c1
Showing 1 changed file with 9 additions and 36 deletions.
45 changes: 9 additions & 36 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ class Controller
public function __construct()
{
$app = app();
$this->request = $app->request;
$this->request = $app->request;
$this->response = $app->response;
$this->view = $app->view;
$this->view = $app->view;

$this->registerDefaultMiddleware();
}

/**
* Execute the registered middlewares.
* @return void
*/
private function registerDefaultMiddleware()
{
Expand All @@ -82,9 +81,6 @@ private function registerDefaultMiddleware()

/**
* Set the layout for the current controller.
*
* @param string $layout
* @return void
*/
public function setLayout(string $layout): void
{
Expand All @@ -93,7 +89,6 @@ public function setLayout(string $layout): void

/**
* Get the current layout.
* @return string
*/
public function getLayout(): string
{
Expand All @@ -102,9 +97,6 @@ public function getLayout(): string

/**
* Set the path for the current view.
*
* @param string $path
* @return void
*/
public function setPathView(string $path)
{
Expand All @@ -113,9 +105,6 @@ public function setPathView(string $path)

/**
* Add an action to the controller.
*
* @param string|null $action
* @return void
*/
public function addAction(?string $action): void
{
Expand All @@ -124,7 +113,6 @@ public function addAction(?string $action): void

/**
* Get the current controller action.
* @return string
*/
public function getAction(): string
{
Expand All @@ -133,12 +121,6 @@ public function getAction(): string

/**
* Render the view.
*
* @param string $view
* @param array|null $params
* @param bool $buffer
* @param string $ext
* @return string|null
*/
public function renderView(string $view, string|array $params = null, bool $withLayout = true, string $ext = '.php'): ?string
{
Expand All @@ -147,7 +129,6 @@ public function renderView(string $view, string|array $params = null, bool $with

/**
* Get the view object associated with this controller.
* @return View|null.
*/
public function view(): ?View
{
Expand All @@ -156,9 +137,6 @@ public function view(): ?View

/**
* Register a middleware in the controller.
*
* @param BaseMiddleware $middleware
* @return void
*/
public function registerMiddleware(BaseMiddleware $middleware): void
{
Expand All @@ -175,12 +153,8 @@ public function getMiddlewares(): array

/**
* Register and execute the AuthMiddleware for access control to the specified actions.
*
* @param array $actions Actions requiring authorization.
* @param bool $allowedAction Indicates whether access to other actions than those specified is allowed.
* @return void
*/
public function accessControl(array $actions, bool $allowedAction = false)
public function accessControl(array $actions, bool $allowedAction = false): void
{
$middleware = new AuthMiddleware($actions, $allowedAction);
$this->registerMiddleware($middleware);
Expand All @@ -204,14 +178,13 @@ public function request(): ?Request

/**
* Handle calls to methods that do not exist.
*
* @param string $name
* @param array $arguments
* @throws RuntimeException
* @return void
*/
public function __call($name, $arguments)
public function __call(string $name, array $params)
{
throw new \RuntimeException(sprintf('Method [ %s ] does not exist', $name));
if (method_exists($this, $name)) {
return $this->$name(...$params);
}

throw new BadMethodCallException(sprintf('Method [%s] does not exist', $name));
}
}

0 comments on commit 67086c1

Please sign in to comment.