diff --git a/src/nano/.gitattributes b/src/nano/.gitattributes deleted file mode 100644 index bdd4ea29c..000000000 --- a/src/nano/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -/tests export-ignore \ No newline at end of file diff --git a/src/nano/LICENSE b/src/nano/LICENSE deleted file mode 100644 index c35d3f5a8..000000000 --- a/src/nano/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) Hyperf - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/src/nano/README.md b/src/nano/README.md deleted file mode 100644 index 3b864804a..000000000 --- a/src/nano/README.md +++ /dev/null @@ -1,252 +0,0 @@ -# nano - -Scaling Hyperf down to a single file. - -## Example - -```php -get('/', function () { - - $user = $this->request->input('user', 'nano'); - $method = $this->request->getMethod(); - - return [ - 'message' => "hello {$user}", - 'method' => $method, - ]; - -}); - -$app->run(); -``` - -Run - -```bash -php index.php start -``` - -That's all you need. - -## Feature - -* No skeleton. -* Fast startup. -* Zero config. -* Closure style. -* Support all Hyperf features except annotations. -* Compatible with all Hyperf components. - -## More Examples - -### Routing - -$app inherits all methods from hyperf router. - -```php -addGroup('/nano', function () use ($app) { - $app->addRoute(['GET', 'POST'], '/{id:\d+}', function($id) { - return '/nano/'.$id; - }); - $app->put('/{name:.+}', function($name) { - return '/nano/'.$name; - }); -}); - -$app->run(); -``` - -### DI Container -```php -getContainer()->set(Foo::class, new Foo()); - -$app->get('/', function () { - /** @var ContainerProxy $this */ - $foo = $this->get(Foo::class); - return $foo->bar(); -}); - -$app->run(); -``` -> As a convention, $this is bind to ContainerProxy in all closures managed by nano, including middleware, exception handler and more. - -### Middleware -```php -get('/', function () { - return $this->request->getAttribute('key'); -}); - -$app->addMiddleware(function ($request, $handler) { - $request = $request->withAttribute('key', 'value'); - return $handler->handle($request); -}); - -$app->run(); -``` - -> In addition to closure, all $app->addXXX() methods also accept class name as argument. You can pass any corresponding hyperf classes. - -### ExceptionHandler - -```php -get('/', function () { - throw new \Exception(); -}); - -$app->addExceptionHandler(function ($throwable, $response) { - return $response->withStatus('418') - ->withBody(new SwooleStream('I\'m a teapot')); -}); - -$app->run(); -``` - -### Custom Command - -```php -addCommand('echo', function(){ - $this->get(StdoutLoggerInterface::class)->info('A new command called echo!'); -}); - -$app->run(); -``` - -To run this command, execute -```bash -php index.php echo -``` - -### Event Listener -```php -addListener(BootApplication::class, function($event){ - $this->get(StdoutLoggerInterface::class)->info('App started'); -}); - -$app->run(); -``` - -### Custom Process -```php -addProcess(function(){ - while (true) { - sleep(1); - $this->get(StdoutLoggerInterface::class)->info('Processing...'); - } -}); - -$app->run(); -``` - -### Crontab - -```php -addCrontab('* * * * * *', function(){ - $this->get(StdoutLoggerInterface::class)->info('execute every second!'); -}); - -$app->run(); -``` - -### Use Hyperf Component. - -```php -config([ - 'db.default' => [ - 'host' => env('DB_HOST', 'localhost'), - 'port' => env('DB_PORT', 3306), - 'database' => env('DB_DATABASE', 'hyperf'), - 'username' => env('DB_USERNAME', 'root'), - 'password' => env('DB_PASSWORD', ''), - ] -]); - -$app->get('/', function(){ - return DB::query('SELECT * FROM `user` WHERE gender = ?;', [1]); -}); - -$app->run(); -``` diff --git a/src/nano/composer.json b/src/nano/composer.json deleted file mode 100644 index b16a77f60..000000000 --- a/src/nano/composer.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "hyperf/nano", - "type": "library", - "license": "MIT", - "keywords": [ - "php", - "hyperf" - ], - "description": "Scale Hyperf application down to a single file", - "autoload": { - "psr-4": { - "Hyperf\\Nano\\": "src/" - } - }, - "require": { - "php": ">=7.2", - "ext-swoole": ">=4.4", - "hyperf/command": "^1.1", - "hyperf/config": "^1.1", - "hyperf/di": "1.1.*", - "hyperf/framework": "^1.1", - "hyperf/http-server": "^1.1", - "hyperf/utils": "^1.1" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "hyperf/crontab": "^1.1", - "hyperf/db": "^1.1", - "hyperf/process": "^1.1", - "hyperf/testing": "1.1.*", - "phpstan/phpstan": "^0.10.5", - "swoft/swoole-ide-helper": "dev-master" - }, - "suggest": { - "hyperf/crontab": "Required to use closure crontab", - "hyperf/process": "Required to use closure process" - }, - "config": { - "sort-packages": true - }, - "scripts": { - "test": "co-phpunit -c phpunit.xml --colors=always", - "analyse": "phpstan analyse --memory-limit 300M -l 5 ./src", - "cs-fix": "php-cs-fixer fix $1" - }, - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - }, - "hyperf": { - "config": "Hyperf\\Nano\\ConfigProvider" - } - } -} diff --git a/src/nano/example/index.php b/src/nano/example/index.php deleted file mode 100644 index 2d463a87e..000000000 --- a/src/nano/example/index.php +++ /dev/null @@ -1,106 +0,0 @@ -get('/', function () { - $user = $this->request->input('user', 'nano'); - $method = $this->request->getMethod(); - return [ - 'message' => "hello {$user}", - 'method' => $method, - ]; -}); - -$app->addGroup('/route', function () use ($app) { - $app->addRoute(['GET', 'POST'], '/{id:\d+}', function ($id) { - return '/route/' . $id; - }); - $app->put('/{name:.+}', function ($name) { - return '/route/' . $name; - }); -}); - -$app->get('/di', function () { - /** @var ContainerProxy $this */ - $foo = $this->get(Foo::class); - return $foo->bar(); -}); - -$app->get('/middleware', function () { - return $this->request->getAttribute('key'); -}); - -$app->addMiddleware(function ($request, $handler) { - $request = $request->withAttribute('key', 'value'); - return $handler->handle($request); -}); - -$app->get('/exception', function () { - throw new \Exception(); -}); - -$app->addExceptionHandler(function ($throwable, $response) { - return $response->withStatus('418')->withBody(new SwooleStream('I\'m a teapot')); -}); - -$app->addCommand('echo', function () { - $this->get(StdoutLoggerInterface::class)->info('A new command called echo!'); -}); - -$app->addListener(BootApplication::class, function ($event) { - $this->get(StdoutLoggerInterface::class)->info('App started'); -}); - -$app->addProcess(function () { - while (true) { - sleep(1); - $this->get(StdoutLoggerInterface::class)->info('Processing...'); - } -}); - -$app->addCrontab('* * * * * *', function () { - $this->get(StdoutLoggerInterface::class)->info('execute every second!'); -}); - -$app->config([ - 'db.default' => [ - 'host' => env('DB_HOST', 'localhost'), - 'port' => env('DB_PORT', 3306), - 'database' => env('DB_DATABASE', 'hyperf'), - 'username' => env('DB_USERNAME', 'root'), - 'password' => env('DB_PASSWORD', ''), - ], -]); - -$app->get('/db', function () { - return DB::query('SELECT * FROM `user` WHERE gender = ?;', [1]); -}); - -$app->run(); diff --git a/src/nano/src/App.php b/src/nano/src/App.php deleted file mode 100644 index d5ae0fcd3..000000000 --- a/src/nano/src/App.php +++ /dev/null @@ -1,331 +0,0 @@ -container = $container; - $this->config = $this->container->get(ConfigInterface::class); - $this->dispatcherFactory = $this->container->get(DispatcherFactory::class); - $this->bound = $this->container->has(BoundInterface::class) - ? $this->container->get(BoundInterface::class) - : new ContainerProxy($this->container); - } - - public function __call($name, $arguments) - { - $router = $this->dispatcherFactory->getRouter($this->serverName); - if ($arguments[1] instanceof \Closure) { - $arguments[1] = $arguments[1]->bindTo($this->bound, $this->bound); - } - return $router->{$name}(...$arguments); - } - - /** - * Run the application. - */ - public function run() - { - $application = $this->container->get(\Hyperf\Contract\ApplicationInterface::class); - $application->run(); - } - - /** - * Config the application using arrays. - */ - public function config(array $configs) - { - foreach ($configs as $key => $value) { - $this->addConfig($key, $value); - } - } - - /** - * Get the dependency injection container. - */ - public function getContainer(): ContainerInterface - { - return $this->container; - } - - /** - * Add a middleware globally. - * @param callable|MiddlewareInterface|string $middleware - */ - public function addMiddleware($middleware) - { - if ($middleware instanceof MiddlewareInterface || is_string($middleware)) { - $this->appendConfig('middlewares.' . $this->serverName, $middleware); - return; - } - - $middleware = Closure::fromCallable($middleware); - $middlewareFactory = $this->container->get(MiddlewareFactory::class); - $this->appendConfig( - 'middlewares.' . $this->serverName, - $middlewareFactory->create($middleware->bindTo($this->bound, $this->bound)) - ); - } - - /** - * Add an exception handler globally. - * @param callable|string $exceptionHandler - */ - public function addExceptionHandler($exceptionHandler) - { - if (is_string($exceptionHandler)) { - $this->appendConfig('exceptions.handler.' . $this->serverName, $exceptionHandler); - return; - } - - $exceptionHandler = Closure::fromCallable($exceptionHandler); - $exceptionHandlerFactory = $this->container->get(ExceptionHandlerFactory::class); - $handler = $exceptionHandlerFactory->create($exceptionHandler->bindTo($this->bound, $this->bound)); - $handlerId = spl_object_hash($handler); - $this->container->set($handlerId, $handler); - $this->appendConfig( - 'exceptions.handler.' . $this->serverName, - $handlerId - ); - } - - /** - * Add an listener globally. - * @param null|callable|string $listener - */ - public function addListener(string $event, $listener = null, int $priority = 1) - { - if ($listener === null) { - $listener = $event; - } - - if (is_string($listener)) { - $this->appendConfig('listeners', $listener); - return; - } - - $listener = Closure::fromCallable($listener); - $listener = $listener->bindTo($this->bound, $this->bound); - $provider = $this->container->get(ListenerProviderInterface::class); - $provider->on($event, $listener, $priority); - } - - /** - * Add a route group. - * @param array|string $prefix - */ - public function addGroup($prefix, callable $callback, array $options = []) - { - $router = $this->dispatcherFactory->getRouter($this->serverName); - if (isset($options['middleware'])) { - $this->convertClosureToMiddleware($options['middleware']); - } - return $router->addGroup($prefix, $callback, $options); - } - - /** - * Add a new command. - * @param null|callable|string $command - */ - public function addCommand(string $name, $command = null) - { - if ($command === null) { - $command = $name; - } - - if (is_string($command)) { - $this->appendConfig('command' . $this->serverName, $command); - return; - } - - $command = Closure::fromCallable($command); - $commandFactory = $this->container->get(CommandFactory::class); - $handler = $commandFactory->create($name, $command->bindTo($this->bound, $this->bound)); - $handlerId = spl_object_hash($handler); - $this->container->set($handlerId, $handler); - $this->appendConfig( - 'commands', - $handlerId - ); - } - - /** - * Add a new crontab. - * @param callable | string $crontab - */ - public function addCrontab(string $rule, $crontab) - { - $this->config->set('crontab.enable', true); - $this->ensureConfigHasValue('processes', CrontabDispatcherProcess::class); - - if ($crontab instanceof Crontab) { - $this->appendConfig('crontab.crontab', $crontab); - return; - } - - $callback = \Closure::fromCallable($crontab); - $callback = $callback->bindTo($this->bound, $this->bound); - $callbackId = spl_object_hash($callback); - $this->container->set($callbackId, $callback); - $this->ensureConfigHasValue('processes', CrontabDispatcherProcess::class); - $this->config->set('crontab.enable', true); - - $this->appendConfig( - 'crontab.crontab', - (new Crontab()) - ->setName(uniqid()) - ->setRule($rule) - ->setCallback([CronFactory::class, 'execute', [$callbackId]]) - ); - } - - /** - * Add a new process. - * @param callable | string $process - */ - public function addProcess($process) - { - if (is_string($process)) { - $this->appendConfig('processes', $process); - return; - } - - $callback = \Closure::fromCallable($process); - $callback = $callback->bindTo($this->bound, $this->bound); - $processFactory = $this->container->get(ProcessFactory::class); - $process = $processFactory->create($callback); - $processId = spl_object_hash($process); - $this->container->set($processId, $process); - $this->appendConfig( - 'processes', - $processId - ); - } - - /** - * Add a new route. - * @param mixed $httpMethod - * @param mixed $handler - */ - public function addRoute($httpMethod, string $route, $handler, array $options = []) - { - $router = $this->dispatcherFactory->getRouter($this->serverName); - if (isset($options['middleware'])) { - $this->convertClosureToMiddleware($options['middleware']); - } - if ($handler instanceof \Closure) { - $handler = $handler->bindTo($this->bound, $this->bound); - } - return $router->addRoute($httpMethod, $route, $handler, $options = []); - } - - /** - * Add a server. - */ - public function addServer(string $serverName, callable $callback) - { - $this->serverName = $serverName; - call($callback, [$this]); - $this->serverName = 'http'; - } - - private function appendConfig(string $key, $configValues) - { - $configs = $this->config->get($key, []); - array_push($configs, $configValues); - $this->config->set($key, $configs); - } - - private function ensureConfigHasValue(string $key, $configValues) - { - $config = $this->config->get($key, []); - if (! is_array($config)) { - return; - } - - if (in_array($configValues, $config)) { - return; - } - - array_push($config, $configValues); - $this->config->set($key, $config); - } - - private function addConfig(string $key, $configValues) - { - $config = $this->config->get($key); - - if (! is_array($config)) { - $this->config->set($key, $configValues); - return; - } - - $this->config->set($key, array_merge_recursive($config, $configValues)); - } - - private function convertClosureToMiddleware(array &$middlewares) - { - $middlewareFactory = $this->container->get(MiddlewareFactory::class); - foreach ($middlewares as &$middleware) { - if ($middleware instanceof \Closure) { - $middleware = $middleware->bindTo($this->bound, $this->bound); - $middleware = $middlewareFactory->create($middleware); - } - } - } -} diff --git a/src/nano/src/BoundInterface.php b/src/nano/src/BoundInterface.php deleted file mode 100644 index aa7a3a590..000000000 --- a/src/nano/src/BoundInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - [ - BoundInterface::class => ContainerProxy::class, - ], - 'commands' => [ - ], - 'annotations' => [ - 'scan' => [ - 'paths' => [ - __DIR__, - ], - ], - ], - ]; - } -} diff --git a/src/nano/src/ContainerProxy.php b/src/nano/src/ContainerProxy.php deleted file mode 100644 index b539764d1..000000000 --- a/src/nano/src/ContainerProxy.php +++ /dev/null @@ -1,71 +0,0 @@ -container = $container; - $this->request = $container->get(RequestInterface::class); - $this->response = $container->get(ResponseInterface::class); - } - - public function __call($name, $arguments) - { - return $this->container->{$name}(...$arguments); - } - - public function get($id) - { - return $this->container->get($id); - } - - public function define(string $name, $definition) - { - return $this->container->define($name, $definition); - } - - public function has($id) - { - return $this->container->has($id); - } - - public function make(string $name, array $parameters = []) - { - return $this->container->make($name, $parameters); - } - - public function set(string $name, $entry) - { - return $this->container->set($name, $entry); - } -} diff --git a/src/nano/src/Factory/AppFactory.php b/src/nano/src/Factory/AppFactory.php deleted file mode 100644 index 96b4add08..000000000 --- a/src/nano/src/Factory/AppFactory.php +++ /dev/null @@ -1,111 +0,0 @@ -config([ - 'server' => Preset::default(), - 'server.servers.0.host' => $host, - 'server.servers.0.port' => $port, - ]); - return $app; - } - - /** - * Create a single worker application in base mode, with max_requests = 0. - */ - public static function createBase(string $host = '0.0.0.0', int $port = 9501): App - { - $app = self::createApp(); - $app->config([ - 'server' => Preset::base(), - 'server.servers.0.host' => $host, - 'server.servers.0.port' => $port, - ]); - return $app; - } - - protected static function prepareContainer(): ContainerInterface - { - $config = new Config(ProviderConfig::load()); - $config->set(StdoutLoggerInterface::class, [ - 'log_level' => [ - LogLevel::ALERT, - LogLevel::CRITICAL, - LogLevel::DEBUG, - LogLevel::EMERGENCY, - LogLevel::ERROR, - LogLevel::INFO, - LogLevel::NOTICE, - LogLevel::WARNING, - ], - ]); - $container = new Container(new DefinitionSource($config->get('dependencies'), new ScanConfig())); - $container->set(ConfigInterface::class, $config); - $container->define(DispatcherFactory::class, DispatcherFactory::class); - $container->define(BoundInterface::class, ContainerProxy::class); - - ApplicationContext::setContainer($container); - return $container; - } - - /** - * Setup flags, ini settings and constants. - */ - protected static function prepareFlags(int $hookFlags = SWOOLE_HOOK_ALL) - { - ini_set('display_errors', 'on'); - ini_set('display_startup_errors', 'on'); - error_reporting(E_ALL); - $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); - } - - /** - * Create an application with a chosen preset. - */ - protected static function createApp(): App - { - // Setting ini and flags - self::prepareFlags(); - - // Prepare container - $container = self::prepareContainer(); - - return new App($container); - } -} diff --git a/src/nano/src/Factory/CommandFactory.php b/src/nano/src/Factory/CommandFactory.php deleted file mode 100644 index 30d2fc6be..000000000 --- a/src/nano/src/Factory/CommandFactory.php +++ /dev/null @@ -1,35 +0,0 @@ -closure = $closure; - } - - public function handle() - { - call($this->closure); - } - }; - } -} diff --git a/src/nano/src/Factory/CronFactory.php b/src/nano/src/Factory/CronFactory.php deleted file mode 100644 index 956093057..000000000 --- a/src/nano/src/Factory/CronFactory.php +++ /dev/null @@ -1,33 +0,0 @@ -container = $container; - } - - public function execute($name) - { - $callback = $this->container->get($name); - $callback(); - } -} diff --git a/src/nano/src/Factory/ExceptionHandlerFactory.php b/src/nano/src/Factory/ExceptionHandlerFactory.php deleted file mode 100644 index c345062da..000000000 --- a/src/nano/src/Factory/ExceptionHandlerFactory.php +++ /dev/null @@ -1,44 +0,0 @@ -closure = $closure; - } - - public function handle(Throwable $throwable, ResponseInterface $response) - { - return call($this->closure, [$throwable, $response]); - } - - public function isValid(Throwable $throwable): bool - { - return true; - } - }; - } -} diff --git a/src/nano/src/Factory/MiddlewareFactory.php b/src/nano/src/Factory/MiddlewareFactory.php deleted file mode 100644 index 49b98dbe6..000000000 --- a/src/nano/src/Factory/MiddlewareFactory.php +++ /dev/null @@ -1,40 +0,0 @@ -closure = $closure; - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - return call($this->closure, [$request, $handler]); - } - }; - } -} diff --git a/src/nano/src/Factory/ProcessFactory.php b/src/nano/src/Factory/ProcessFactory.php deleted file mode 100644 index 44eb75035..000000000 --- a/src/nano/src/Factory/ProcessFactory.php +++ /dev/null @@ -1,38 +0,0 @@ -closure = $closure; - } - - public function handle(): void - { - call($this->closure); - } - }; - } -} diff --git a/src/nano/src/Preset/Base.php b/src/nano/src/Preset/Base.php deleted file mode 100644 index ee5021ecd..000000000 --- a/src/nano/src/Preset/Base.php +++ /dev/null @@ -1,45 +0,0 @@ - SWOOLE_BASE, - 'servers' => [ - [ - 'name' => 'http', - 'type' => Server::SERVER_HTTP, - 'host' => '0.0.0.0', - 'port' => 9501, - 'sock_type' => SWOOLE_SOCK_TCP, - 'callbacks' => [ - SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'], - ], - ], - ], - 'settings' => [ - 'enable_coroutine' => true, - 'worker_num' => 1, - 'open_tcp_nodelay' => true, - 'max_coroutine' => 100000, - 'open_http2_protocol' => true, - 'max_request' => 0, - 'socket_buffer_size' => 2 * 1024 * 1024, - 'buffer_output_size' => 2 * 1024 * 1024, - ], - 'callbacks' => [ - SwooleEvent::ON_BEFORE_START => [Hyperf\Framework\Bootstrap\ServerStartCallback::class, 'beforeStart'], - SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], - SwooleEvent::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], - SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], - ], -]; diff --git a/src/nano/src/Preset/Default.php b/src/nano/src/Preset/Default.php deleted file mode 100644 index e2a1e1b28..000000000 --- a/src/nano/src/Preset/Default.php +++ /dev/null @@ -1,56 +0,0 @@ - SWOOLE_PROCESS, - 'servers' => [ - [ - 'name' => 'http', - 'type' => Server::SERVER_HTTP, - 'host' => '0.0.0.0', - 'port' => 9501, - 'sock_type' => SWOOLE_SOCK_TCP, - 'callbacks' => [ - SwooleEvent::ON_REQUEST => [\Hyperf\HttpServer\Server::class, 'onRequest'], - ], - ], - ], - 'settings' => [ - 'enable_coroutine' => true, - 'worker_num' => swoole_cpu_num(), - 'open_tcp_nodelay' => true, - 'max_coroutine' => 100000, - 'open_http2_protocol' => true, - 'max_request' => 100000, - 'socket_buffer_size' => 2 * 1024 * 1024, - 'buffer_output_size' => 2 * 1024 * 1024, - ], - 'callbacks' => [ - SwooleEvent::ON_BEFORE_START => [\Hyperf\Framework\Bootstrap\ServerStartCallback::class, 'beforeStart'], - SwooleEvent::ON_WORKER_START => [\Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], - SwooleEvent::ON_WORKER_EXIT => [\Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], - SwooleEvent::ON_PIPE_MESSAGE => [\Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], - ], -]; diff --git a/src/nano/src/Preset/Preset.php b/src/nano/src/Preset/Preset.php deleted file mode 100644 index 6c033927c..000000000 --- a/src/nano/src/Preset/Preset.php +++ /dev/null @@ -1,31 +0,0 @@ -=7.2", - "hyperf/contract": "~1.1.0", - "hyperf/utils": "~1.1.0", - "psr/container": "^1.0", - "psr/http-server-middleware": "^1.0", - "psr/log": "^1.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.9", - "malukenho/docheader": "^0.1.6", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^7.0" - }, - "suggest": { - }, - "autoload": { - "psr-4": { - "Hyperf\\SwooleEnterprise\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - } - }, - "config": { - "sort-packages": true - }, - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - }, - "hyperf": { - "config": "Hyperf\\SwooleEnterprise\\ConfigProvider" - } - }, - "bin": [ - ], - "scripts": { - "cs-fix": "php-cs-fixer fix $1", - "test": "phpunit --colors=always" - } -} diff --git a/src/swoole-enterprise/src/ConfigProvider.php b/src/swoole-enterprise/src/ConfigProvider.php deleted file mode 100644 index fcd9ac546..000000000 --- a/src/swoole-enterprise/src/ConfigProvider.php +++ /dev/null @@ -1,28 +0,0 @@ - [ - 'scan' => [ - 'paths' => [ - __DIR__, - ], - ], - ], - ]; - } -} diff --git a/src/swoole-enterprise/src/Middleware/HttpServerMiddleware.php b/src/swoole-enterprise/src/Middleware/HttpServerMiddleware.php deleted file mode 100644 index 5c61b2476..000000000 --- a/src/swoole-enterprise/src/Middleware/HttpServerMiddleware.php +++ /dev/null @@ -1,53 +0,0 @@ -name = $config->get('app_name', 'hyperf-skeleton'); - } - - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface - { - if (class_exists(StatsCenter::class)) { - $path = $request->getUri()->getPath(); - $ip = current(swoole_get_local_ip()); - - $tick = StatsCenter::beforeExecRpc($path, $this->name, $ip); - try { - $response = $handler->handle($request); - StatsCenter::afterExecRpc($tick, true, $response->getStatusCode()); - } catch (\Throwable $exception) { - StatsCenter::afterExecRpc($tick, false, $exception->getCode()); - throw $exception; - } - } else { - $response = $handler->handle($request); - } - - return $response; - } -}