Skip to content

Commit

Permalink
feat: fix null value
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Dec 6, 2023
1 parent 16e7462 commit ca88067
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/Core/Facades/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function __construct(Application $application)
/**
* Eksekusi controller.
*
* @param object $controller
* @param object|null $controller
* @param string|null $function
* @return Closure
*/
private function coreMiddleware(object $controller, string|null $function = null): Closure
private function coreMiddleware(object|null $controller = null, string|null $function = null): Closure
{
return function () use ($controller, $function): mixed {
if ($function === null) {
if ($function === null || $controller === null) {
return null;
}

Expand Down Expand Up @@ -76,16 +76,20 @@ private function process(array $route): Respond|Stream
$function = '__invoke';
}

$controller = $this->app->singleton($controller);
if (!($controller instanceof Controller)) {
throw new Exception(sprintf('Class "%s" is not extends BaseController.', get_class($controller)));
if ($controller) {
$controller = $this->app->singleton($controller);
if (!($controller instanceof Controller)) {
throw new Exception(sprintf('Class "%s" is not extends BaseController.', get_class($controller)));
}
}

$attributeMiddleware = [];
if ($function) {
if ($controller && $function) {
foreach ($this->app->getAttribute($controller, $function) as $value) {
if ($this->app->make($value->getName()) instanceof MiddlewareInterface) {
$attributeMiddleware[] = $value->getName();
$object = $this->app->make($value->getName());

if ($object instanceof MiddlewareInterface) {
$attributeMiddleware[] = $object;
}

$this->app->clean($value->getName());
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class Middleware
/**
* Buat objek middleware.
*
* @param array<int, MiddlewareInterface> $layers
* @param array<int, class-string<MiddlewareInterface>|MiddlewareInterface> $layers
* @return void
*/
public function __construct(array $layers = [])
{
for ($i = (count($layers) - 1); $i >= 0; $i--) {
$this->layers[] = new $layers[$i];
$this->layers[] = is_object($layers[$i]) ? $layers[$i] : new $layers[$i];
}
}

Expand Down

0 comments on commit ca88067

Please sign in to comment.