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

[PHP]: hleb2-workerman added #8042

Merged
merged 3 commits into from
Dec 12, 2024
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
14 changes: 14 additions & 0 deletions php/hleb2-workerman/app/Bootstrap/BaseContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Bootstrap;

use Hleb\Constructor\Containers\CoreContainer;

final class BaseContainer extends CoreContainer implements ContainerInterface
{
#[\Override]
final public function get(string $id): mixed
{
return parent::get($id);
}
}
13 changes: 13 additions & 0 deletions php/hleb2-workerman/app/Bootstrap/ContainerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Bootstrap;

use Hleb\Constructor\Containers\BaseContainerFactory;

final class ContainerFactory extends BaseContainerFactory
{
#[\Override]
public static function rollback(): void
{
}
}
9 changes: 9 additions & 0 deletions php/hleb2-workerman/app/Bootstrap/ContainerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Bootstrap;

use Hleb\Constructor\Containers\CoreContainerInterface;

interface ContainerInterface extends CoreContainerInterface
{
}
12 changes: 12 additions & 0 deletions php/hleb2-workerman/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"require": {
"php": ">=8.2.0",
"phphleb/framework": "~2.0.0",
"workerman/workerman": "@stable"
},
"autoload": {
"classmap": [
"app/"
]
}
}
14 changes: 14 additions & 0 deletions php/hleb2-workerman/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
framework:
website: hleb2framework.ru
github: phphleb/hleb
version: 2.0

files:
- console

bootstrap:
- php console --generate-key
- php console --routes-upd

engines:
- workerman
21 changes: 21 additions & 0 deletions php/hleb2-workerman/config/common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

return [
'debug' => false,
'log.enabled' => false,
'max.log.level' => 'info',
'max.cli.log.level' => 'info',
'log.level.in-cli' => false,
'error.reporting' => E_ALL,
'log.sort' => true,
'log.stream' => false,
'log.format' => 'row',
'log.db.excess' => 0,
'timezone' => 'UTC',
'routes.auto-update' => false,
'container.mock.allowed' => false,
'app.cache.on' => false,
'show.request.id' => false,
'max.log.size' => 0,
'max.cache.size' => 0,
];
6 changes: 6 additions & 0 deletions php/hleb2-workerman/config/database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'base.db.type' => 'mysql.name',
'db.settings.list' => []
];
9 changes: 9 additions & 0 deletions php/hleb2-workerman/config/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [
'default.lang' => 'en',
'allowed.languages' => ['en'],
'session.enabled' => false,
'db.log.enabled' => false,
'session.options' => [],
];
20 changes: 20 additions & 0 deletions php/hleb2-workerman/config/system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

return [
'project.paths' => ['logs' => '/storage/logs'],
'classes.autoload' => true,
'origin.request' => false,
'ending.slash.url' => 0,
'ending.url.methods' => ['get'],
'url.validation' => false,
'session.name' => 'PHPSESSID',
'max.session.lifetime' => 0,
'allowed.route.paths' => [],
'allowed.structure.parts' => [],
'page.external.access' => true,
'module.dir.name' => 'modules',
'custom.function.files' => [],
'custom.setting.files' => [],
'events.used' => false,
'async.clear.state' => false,
];
5 changes: 5 additions & 0 deletions php/hleb2-workerman/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

define('HLEB_PUBLIC_DIR', realpath(__DIR__ . '/public'));

require realpath(__DIR__ . '/vendor/phphleb/framework/console.php');
21 changes: 21 additions & 0 deletions php/hleb2-workerman/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Response;

include __DIR__ . "/../vendor/autoload.php";

$framework = new Hleb\HlebAsyncBootstrap(__DIR__);

$server = new Worker( 'http://0.0.0.0:3000');

$server->count = shell_exec('nproc') ?: 32;

$server->onMessage = function (TcpConnection $connection, $request) use ($framework) {
$res = $framework->load($request)->getResponse();

$connection->send(new Response($res->getStatus(), $res->getHeaders(), $res->getBody()));
};

Worker::runAll();
5 changes: 5 additions & 0 deletions php/hleb2-workerman/routes/map.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

Route::get('/', '');
Route::get('/user/{id}', preview('{%id%}'));
Route::post('/user', '');
Loading