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

Update dependences #60

Merged
merged 7 commits into from
Apr 27, 2023
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 @@ -22,7 +22,7 @@ jobs:
swoole-version: 'v4.6.7'
- php-version: '8.1'
swoole-version: 'v4.7.1'
max-parallel: 12
max-parallel: 16
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
'concat_space' => [
'spacing' => 'one'
],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => null,
huangdijia marked this conversation as resolved.
Show resolved Hide resolved
],
'blank_line_before_statement' => [
'statements' => [
'declare',
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
"php": ">=8.0",
"hyperf/command": "^3.0.0",
"hyperf/config": "^3.0.0",
"hyperf/context": "^3.0.16",
"hyperf/contract": "^3.0.0",
"hyperf/di": "^3.0.0",
"hyperf/framework": "^3.0.0",
"hyperf/http-server": "^3.0.0",
"hyperf/utils": "^3.0.0"
"hyperf/stringable": "^3.0.0",
"hyperf/support": "^3.0.0",
"hyperf/tappable": "^3.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
Expand Down
5 changes: 4 additions & 1 deletion example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
*/
namespace Hyperf\Nano;

use Exception;
use Hyperf\Command\Command;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\DB\DB;
use Hyperf\Framework\Event\BootApplication;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\Nano\Factory\AppFactory;

use function Hyperf\Support\env;

require_once __DIR__ . '/../vendor/autoload.php';

interface FooInterface
Expand Down Expand Up @@ -83,7 +86,7 @@ public function bar(): string
});

$app->get('/exception', function () {
throw new \Exception();
throw new Exception();
});

$app->addExceptionHandler(function ($throwable, $response) {
Expand Down
13 changes: 8 additions & 5 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use Psr\EventDispatcher\ListenerProviderInterface;
use Psr\Http\Server\MiddlewareInterface;

use function Hyperf\Support\call;
use function Hyperf\Tappable\tap;

/**
* @method get($route, $handler, array $options = [])
* @method post($route, $handler, array $options = [])
Expand Down Expand Up @@ -58,7 +61,7 @@ public function __construct(protected ContainerInterface $container)
public function __call($name, $arguments)
{
$router = $this->dispatcherFactory->getRouter($this->serverName);
if ($arguments[1] instanceof \Closure) {
if ($arguments[1] instanceof Closure) {
$arguments[1] = $arguments[1]->bindTo($this->bound, $this->bound);
}
return $router->{$name}(...$arguments);
Expand Down Expand Up @@ -209,7 +212,7 @@ public function addCrontab(string $rule, callable|string $crontab): Crontab
return $crontab;
}

$callback = \Closure::fromCallable($crontab);
$callback = Closure::fromCallable($crontab);
$callback = $callback->bindTo($this->bound, $this->bound);
$callbackId = spl_object_hash($callback);
$this->container->set($callbackId, $callback);
Expand Down Expand Up @@ -240,7 +243,7 @@ public function addProcess(callable|string $process): AbstractProcess|ClosurePro
return $this->container->get($process);
}

$callback = \Closure::fromCallable($process);
$callback = Closure::fromCallable($process);
$callback = $callback->bindTo($this->bound, $this->bound);
$processFactory = $this->container->get(ProcessFactory::class);

Expand All @@ -265,7 +268,7 @@ public function addRoute($httpMethod, string $route, $handler, array $options =
if (isset($options['middleware'])) {
$this->convertClosureToMiddleware($options['middleware']);
}
if ($handler instanceof \Closure) {
if ($handler instanceof Closure) {
$handler = $handler->bindTo($this->bound, $this->bound);
}
$router->addRoute($httpMethod, $route, $handler, $options);
Expand Down Expand Up @@ -323,7 +326,7 @@ private function convertClosureToMiddleware(array &$middlewares): void
{
$middlewareFactory = $this->container->get(MiddlewareFactory::class);
foreach ($middlewares as &$middleware) {
if ($middleware instanceof \Closure) {
if ($middleware instanceof Closure) {
$middleware = $middleware->bindTo($this->bound, $this->bound);
$middleware = $middlewareFactory->create($middleware);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Factory/AppFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Dotenv\Repository\RepositoryBuilder;
use Hyperf\Config\Config;
use Hyperf\Config\ProviderConfig;
use Hyperf\Context\ApplicationContext;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\ContainerInterface;
use Hyperf\Contract\StdoutLoggerInterface;
Expand All @@ -27,8 +28,10 @@
use Hyperf\Nano\BoundInterface;
use Hyperf\Nano\ContainerProxy;
use Hyperf\Nano\Preset\Preset;
use Hyperf\Utils\ApplicationContext;
use Psr\Log\LogLevel;
use ReflectionClass;

use function Hyperf\Support\env;

class AppFactory
{
Expand Down Expand Up @@ -138,7 +141,7 @@ protected static function prepareFlags(int $hookFlags = SWOOLE_HOOK_ALL): void
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(E_ALL);
$reflection = new \ReflectionClass(\Composer\Autoload\ClassLoader::class);
$reflection = new ReflectionClass(\Composer\Autoload\ClassLoader::class);
$projectRootPath = dirname($reflection->getFileName(), 3);
! defined('BASE_PATH') && define('BASE_PATH', $projectRootPath);
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', $hookFlags);
Expand Down
5 changes: 4 additions & 1 deletion src/Factory/ClosureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
*/
namespace Hyperf\Nano\Factory;

use Closure;
use Hyperf\Command\Command;
use Psr\Container\ContainerInterface;

use function Hyperf\Support\call;

class ClosureCommand extends Command
{
protected ParameterParser $parameterParser;

public function __construct(protected ContainerInterface $container, protected ?string $signature, private \Closure $closure)
public function __construct(protected ContainerInterface $container, protected ?string $signature, private Closure $closure)
{
$this->parameterParser = $container->get(ParameterParser::class);
parent::__construct();
Expand Down
5 changes: 4 additions & 1 deletion src/Factory/ClosureProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
*/
namespace Hyperf\Nano\Factory;

use Closure;
use Hyperf\Process\AbstractProcess;
use Psr\Container\ContainerInterface;

use function Hyperf\Support\call;

class ClosureProcess extends AbstractProcess
{
/**
* @var bool|callable
*/
private $enable;

public function __construct(ContainerInterface $container, private \Closure $closure)
public function __construct(ContainerInterface $container, private Closure $closure)
{
parent::__construct($container);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Factory/CommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
*/
namespace Hyperf\Nano\Factory;

use Closure;
use Hyperf\Command\Command;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Context\ApplicationContext;

class CommandFactory
{
public function create(string $signature, \Closure $closure): Command
public function create(string $signature, Closure $closure): Command
{
$container = ApplicationContext::getContainer();

Expand Down
9 changes: 6 additions & 3 deletions src/Factory/ExceptionHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@
*/
namespace Hyperf\Nano\Factory;

use Closure;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Psr\Http\Message\ResponseInterface;
use Throwable;

use function Hyperf\Support\call;

class ExceptionHandlerFactory
{
public function create(\Closure $closure): ExceptionHandler
public function create(Closure $closure): ExceptionHandler
{
return new class($closure) extends ExceptionHandler {
/**
* @var \Closure
* @var Closure
*/
private $closure;

public function __construct(\Closure $closure)
public function __construct(Closure $closure)
{
$this->closure = $closure;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Factory/MiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@
*/
namespace Hyperf\Nano\Factory;

use Closure;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function Hyperf\Support\call;

class MiddlewareFactory
{
public function create(\Closure $closure): MiddlewareInterface
public function create(Closure $closure): MiddlewareInterface
{
return new class($closure) implements MiddlewareInterface {
/**
* @var \Closure
* @var Closure
*/
private $closure;

public function __construct(\Closure $closure)
public function __construct(Closure $closure)
{
$this->closure = $closure;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Factory/ParameterParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use Hyperf\Contract\NormalizerInterface;
use Hyperf\Di\ClosureDefinitionCollectorInterface;
use Hyperf\Di\MethodDefinitionCollectorInterface;
use Hyperf\Utils\Str;
use Hyperf\Stringable\Str;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;

class ParameterParser
Expand All @@ -40,7 +41,7 @@ public function __construct(private ContainerInterface $container)
}

/**
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function parseClosureParameters(Closure $closure, array $arguments): array
{
Expand All @@ -64,7 +65,7 @@ public function parseMethodParameters(string $class, string $method, array $argu
}

/**
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
private function getInjections(array $definitions, string $callableName, array $arguments): array
{
Expand All @@ -80,7 +81,7 @@ private function getInjections(array $definitions, string $callableName, array $
} elseif ($definition->allowsNull()) {
$injections[] = null;
} else {
throw new \InvalidArgumentException("Parameter '{$definition->getMeta('name')}' "
throw new InvalidArgumentException("Parameter '{$definition->getMeta('name')}' "
. "of {$callableName} should not be null");
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/Factory/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
*/
namespace Hyperf\Nano\Factory;

use Hyperf\Utils\ApplicationContext;
use Closure;
use Hyperf\Context\ApplicationContext;

class ProcessFactory
{
public function create(\Closure $closure): ClosureProcess
public function create(Closure $closure): ClosureProcess
{
$container = ApplicationContext::getContainer();

Expand Down