Skip to content

Commit

Permalink
fix matcher array pattern bug and nullable pattern bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirHkrg committed Jun 16, 2024
1 parent 2a4cb4a commit dc1d692
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
13 changes: 0 additions & 13 deletions index.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ class Container implements ContainerContract, ArrayAccess
protected array $resolvingCallbacks = [];
protected array $afterResolvingCallbacks = [];

public function __construct()
{
static::setInstance($this);
Facade::setFacadeApplication($this);
}

public function when($concrete): ContextualBindingBuilder|array
{
$aliases = [];
Expand Down
6 changes: 5 additions & 1 deletion src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use LaraGram\Container\Container;
use LaraGram\Contracts\Application as ApplicationContract;
use Illuminate\Database\Capsule\Manager as Capsule;
use LaraGram\Request\Request;
use LaraGram\Support\Facades\Facade;

class Application extends Container implements ApplicationContract
{
Expand All @@ -33,7 +35,8 @@ class Application extends Container implements ApplicationContract

public function __construct(string $basePath = null)
{
parent::__construct();
static::setInstance($this);
Facade::setFacadeApplication($this);

$this->setBasePath($basePath)
->loadEnv();
Expand Down Expand Up @@ -534,6 +537,7 @@ private function loadResources(): void
$files = array_filter(scandir($directory), function ($file) use ($directory) {
return is_file($directory . DIRECTORY_SEPARATOR . $file);
});

foreach ($files as $file) {
require_once $directory . DIRECTORY_SEPARATOR . $file;
}
Expand Down
8 changes: 6 additions & 2 deletions src/Listener/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace LaraGram\Listener;

use LaraGram\Request\Request;

class Matcher
{
/** @var Request $request */
private mixed $request;

public function match(string $type, callable $action, string|array|null $pattern)
Expand All @@ -26,7 +29,7 @@ private function execute_regex($pattern, $action, $input = null)
$matches = array_filter($matches, function ($value, $key) {
return !is_numeric($key) && $value !== "" && $value !== null;
}, ARRAY_FILTER_USE_BOTH);
return call_user_func_array($action, [$this->request, $matches]);
return call_user_func_array($action, [$this->request, ...$matches]);
}

return false;
Expand All @@ -36,8 +39,9 @@ private function match_text(callable $action, string|array $pattern)
{
if (is_array($pattern)) {
foreach ($pattern as $value) {
return $this->execute_regex($value, $action);
$result = $this->execute_regex($value, $action);
}
return $result;
} else {
return $this->execute_regex($pattern, $action);
}
Expand Down

0 comments on commit dc1d692

Please sign in to comment.