Skip to content

Commit 9162779

Browse files
authored
Merge pull request #44 from hypervel/improve/route-definition-cache
improve: cache resolved definitions in RouteDependency to cover routes with arguments
2 parents 10d01d5 + 05e52be commit 9162779

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/foundation/src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Application extends Container implements ApplicationContract
3131
*
3232
* @var string
3333
*/
34-
public const VERSION = '0.1.5';
34+
public const VERSION = '0.1.6';
3535

3636
/**
3737
* The base path for the Hypervel installation.

src/http/src/RouteDependency.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
class RouteDependency
1717
{
1818
/**
19-
* All of the resolved dependencies by dispatched routes.
19+
* All of the resolved definitions by dispatched routes.
2020
*/
21-
protected array $resolvedDependencies = [];
21+
protected array $resolvedDefinitions = [];
2222

2323
/**
2424
* All of the after resolving callbacks by class type.
@@ -105,22 +105,11 @@ public function getAfterResolvingCallbacks(object $object): array
105105
*/
106106
public function getMethodParameters(string $controller, string $action, array $arguments): array
107107
{
108-
$signature = "{$controller}::{$action}";
109-
if (! $arguments && isset($this->resolvedDependencies[$signature])) {
110-
return $this->resolvedDependencies[$signature];
111-
}
112-
113-
$dependencies = $this->getDependencies(
114-
$this->methodDefinitionCollector->getParameters($controller, $action),
108+
return $this->getDependencies(
109+
$this->getMethodDefinitions($controller, $action),
115110
"{$controller}::{$action}",
116111
$arguments
117112
);
118-
119-
if (! $arguments) {
120-
$this->resolvedDependencies[$signature] = $dependencies;
121-
}
122-
123-
return $dependencies;
124113
}
125114

126115
/**
@@ -130,22 +119,33 @@ public function getMethodParameters(string $controller, string $action, array $a
130119
*/
131120
public function getClosureParameters(Closure $closure, array $arguments): array
132121
{
133-
$signature = spl_object_hash($closure);
134-
if (! $arguments && isset($this->resolvedDependencies[$signature])) {
135-
return $this->resolvedDependencies[$signature];
136-
}
137-
138-
$dependencies = $this->getDependencies(
139-
$this->closureDefinitionCollector->getParameters($closure),
122+
return $this->getDependencies(
123+
$this->getClosureDefinitions($closure),
140124
'Closure',
141125
$arguments
142126
);
127+
}
143128

144-
if (! $arguments) {
145-
$this->resolvedDependencies[$signature] = $dependencies;
146-
}
129+
/**
130+
* Parse the parameters of method definitions.
131+
*/
132+
public function getMethodDefinitions(string $controller, string $action): array
133+
{
134+
$signature = "{$controller}::{$action}";
147135

148-
return $dependencies;
136+
return $this->resolvedDefinitions[$signature]
137+
?? $this->resolvedDefinitions[$signature] = $this->methodDefinitionCollector->getParameters($controller, $action);
138+
}
139+
140+
/**
141+
* Parse the parameters of closure definitions.
142+
*/
143+
public function getClosureDefinitions(Closure $closure): array
144+
{
145+
$signature = spl_object_hash($closure);
146+
147+
return $this->resolvedDefinitions[$signature]
148+
?? $this->resolvedDefinitions[$signature] = $this->closureDefinitionCollector->getParameters($closure);
149149
}
150150

151151
/**

0 commit comments

Comments
 (0)