Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test for swoole v4.8.11 #47

Merged
merged 3 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os: [ ubuntu-latest ]
php-version: [ '8.0', '8.1' ]
engine: [ 'swoole' ]
swoole-version: [ 'v4.6.7', 'v4.7.1', 'v4.8.10', 'master' ]
swoole-version: [ 'v4.6.7', 'v4.7.1', 'v4.8.11', 'master' ]
exclude:
- php-version: '8.1'
swoole-version: 'v4.6.7'
Expand Down
16 changes: 9 additions & 7 deletions src/Factory/ParameterParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@
namespace Hyperf\Nano\Factory;

use Closure;
use Hyperf\Utils\Str;
use Psr\Container\ContainerInterface;
use Hyperf\Contract\NormalizerInterface;
use Hyperf\Di\ClosureDefinitionCollectorInterface;
use Hyperf\Di\MethodDefinitionCollectorInterface;
use Psr\Container\ContainerInterface;
use Hyperf\Di\ClosureDefinitionCollectorInterface;

class ParameterParser
{
private ContainerInterface $container;

private NormalizerInterface $normalizer;

private ?ClosureDefinitionCollectorInterface $closureDefinitionCollector = null;

private ?MethodDefinitionCollectorInterface $methodDefinitionCollector = null;

public function __construct(ContainerInterface $container)
public function __construct(private ContainerInterface $container)
{
$this->container = $container;
$this->normalizer = $this->container->get(NormalizerInterface::class);

if ($this->container->has(ClosureDefinitionCollectorInterface::class)) {
Expand Down Expand Up @@ -57,6 +55,10 @@ public function parseClosureParameters(Closure $closure, array $arguments): arra

public function parseMethodParameters(string $class, string $method, array $arguments): array
{
if (! $this->methodDefinitionCollector) {
return [];
}

$definitions = $this->methodDefinitionCollector->getParameters($class, $method);
return $this->getInjections($definitions, "{$class}::{$method}", $arguments);
}
Expand All @@ -69,7 +71,7 @@ private function getInjections(array $definitions, string $callableName, array $
$injections = [];

foreach ($definitions as $pos => $definition) {
$value = $arguments[$pos] ?? $arguments[$definition->getMeta('name')] ?? null;
$value = $arguments[$pos] ?? $arguments[$definition->getMeta('name')] ?? $arguments[Str::snake($definition->getMeta('name'), '-')] ?? null;
huangdijia marked this conversation as resolved.
Show resolved Hide resolved
if ($value === null) {
if ($definition->getMeta('defaultValueAvailable')) {
$injections[] = $definition->getMeta('defaultValue');
Expand Down