igniphp / framework Goto Github PK
View Code? Open in Web Editor NEWSwoole, PSR-15, PSR-7, PSR-11 lightweight modular anti-framework for REST micro-services.
License: MIT License
Swoole, PSR-15, PSR-7, PSR-11 lightweight modular anti-framework for REST micro-services.
License: MIT License
How to reproduce?
<?php
// Setup server
$server = new HttpServer(new Configuration('0.0.0.0', 8080));
// Setup application and routes
$application = new HttpApplication();
$application->put('/user/{id}', function (ServerRequestInterface $request) : ResponseInterface {
return Response::asText("updated");
});
$application->delete('/user/{id}', function (ServerRequestInterface $request) : ResponseInterface {
return Response::asText("destroyed");
});
// Run the server, it should listen on localhost:8080
$application->run($server);
Two routes contains same name and latest route (with delete method) is overwrite the previous. This leads to the following error:
This uri `/user/5` allows only DELETE http methods.
It's a bug.
I don’t want print log like:
[2019-01-29 01:23:43][INFO] - Client Igni\Network\Server\Client[2] connected
[2019-01-29 01:23:43][INFO] - Client Igni\Network\Server\Client[1] connected
[2019-01-29 01:23:55][INFO] - Client Igni\Network\Server\Client[2] closed connection
[2019-01-29 01:23:55][INFO] - Client Igni\Network\Server\Client[3] connected
I think the event is enough,develop can print log by her self。
I'm desperately trying to use Swoole\Mysql
or Swoole\Coroutine\Mysql
but I'm always failing.
I tried to use Coroutine::create
function and so many other things without any result (like yield syntax).
My goal is to write a 'sync' like code to avoid the classic nested callback functions wtih 'mysql::connect', 'mysql::query' ...
Any suggest ?
Please add benchmark
How to reproduce?
class Test implements \Psr\Http\Server\MiddlewareInterface {
/**
* Process an incoming server request and return a response, optionally delegating
* response creation to a handler.
*/
public function process(
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Server\RequestHandlerInterface $handler
): \Psr\Http\Message\ResponseInterface {
dump($request->getAttribute('user_id'));
return $handler->handle($request);
}
};
$app->use(Test::class);
/user/{user_id}
$request->getAttribute('user_id')
in the middleware and in the destination controller.Attribute user_id
allows use only in the controller handler (__invoke
). In the middleware attribute value will be equals null
.
This is a bug or feature? :)
How I can validate incoming route attributes? :)
Any documentation for test unit ?
I would like to use database connection per-request or use connection pool for choosing available before register object in Container.
Any ideas? OnRequestListener
does not work for the application.
P.S. My server-app throws a lot of many database errors when parallel requests send from JS (like "General error 7" and "PDO statement not found"). And I'm trying to elegant resolve this problem.
https://github.com/igniphp/framework/tree/master/docs#testing
In the following example, name
attribute does not correctly passing to ServerRequest
object.
public function testWelcome(): void
{
$controller = new WelcomeUserController();
$response = $controller(new ServerRequest('/hi/Tom'));
self::assertSame('Hi Tom!', (string) $response->getBody());
self::assertSame(200, $response->getStatusCode());
}
Solution:
public function testWelcome(): void
{
$controller = new WelcomeUserController();
$response = $controller((new ServerRequest('/hi/Tom'))->withAttribute('name', 'Tom'));
self::assertSame('Hi Tom!', (string) $response->getBody());
self::assertSame(200, $response->getStatusCode());
}
P.S. This is a WIP issue. I will update it soon.
@dkraczkowski What you think if framework to make independent from http server?
For example, use Workerman (similar performance) or ReactPHP to replace Swoole if needs?
Igni\Application\Providers\ServiceProvider
has one method with PSR ContainerInterface and I can't register additional there services because has
and get
methods not enough for this.
My goal is a create the re-usable module for PDO connection:
// ...
$serviceLocator = new ServiceLocator();
$serviceLocator->share(PDO::class, function () use ($conf) {
$dsn = "pgsql:dbname={$conf->get('db.name')};host={$conf->get('db.host')}";
$pdo = new PDO($dsn, $conf->get('db.user'), $conf->get('db.pwd'));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
});
// Setup application and routes
$app = new HttpApplication($serviceLocator);
// ...
But it's impossible with the current ServiceProvider interface. Or I'm wrong?
I'm looking for exposing all available routes for debug purpose or may be to create a swagger file.
Because route collection is a private property, I'm not able to override the Router class to handle it.
Can you change property scope for "protected" ?
Your current dependency injection implementation allow to use the symfony/dependency-injection package.
But It could be interesting to explain how to integrate it properly into the project in the documentation:
According to Symfony blog, its router is now faster than FastRoute.
You should consider a change in your requirements.
As alternative, you should remove mention to "fastest router" in README.
At the time\Igni\Application\Config
uses arrays only, would be good to add support for yml, ini, json, xml formats- so config can be factored out of any of this formats.
From the documentation, it is not clear how to handle exception occurred in business logic.
Since Swool does not support set_exception_handler
function, where is the central error handler in igni framework and what is the preferred way to handle exceptions and provide pretty output to the client?
Thanks!
p.s.
I managed to find this ErrorMiddleware
which by default catches any exception (and converts errors to exceptions). I guess error handling is something to be done via that middleware, right?
Pretty format on json response is useful for debug, but increase network payload.
It should not be enabled by default
If you want to create a full Rest API, you need to override the ErrorMiddleware
.
But this suppose to override the Application
too because de ErrorMiddleware
is added by default with too many code overriden due to "private" properties and methods.
It should be a good thing to restrict "private" properties and methods only when realy needed for security reasons or to forced code override in case of inheritance.
What's your point of view ?
Ideal solution would be to have ApplicationFactory
class that accepts configuration file of any type: ini, json, yml, and build instance of application with set up right modules, middleware, routes and services.
How I can register service in the Container (for auto-wiring) if service depends on Swoole ServerRequest?
If run framework with PHP 7.3 and Swoole, I got the following error:
roquie@roquies-MBP:~/google_drive/experiments/igni-framework-test/examples$ php build_in_server_example.php
[2019-03-02 11:02:42][INFO] - Server is listening 0.0.0.0:8080
[2019-03-02 11:02:45][INFO] - Client Igni\Network\Server\Client[1] connected
[2019-03-02 14:02:45 $81920.0] WARNING swManager_check_exit_status: worker#6 abnormal exit, status=0, signal=11
A bug occurred in Swoole-v4.2.13, please report it.
The Swoole developers probably don't know about it,
and unless you report it, chances are it won't be fixed.
You can read How to report a bug doc before submitting any bug reports:
>> https://github.com/swoole/swoole-src/issues/2000
Please do not send bug reports in the mailing list or personal letters.
The issue page is also suitable to submit feature requests.
PHP Fatal error: Uncaught Igni\Network\Exception\ClientException: Client with id 1 was not connected or is already disconnected. in /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Exception/ClientException.php:22
Stack trace:
#0 /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Server.php(101): Igni\Network\Exception\ClientException::forInactiveClient(1)
#1 /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Server.php(243): Igni\Network\Server->getClient(1)
#2 {main}
thrown in /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Exception/ClientException.php on line 22
Fatal error: Uncaught Igni\Network\Exception\ClientException: Client with id 1 was not connected or is already disconnected. in /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Exception/ClientException.php:22
Stack trace:
#0 /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Server.php(101): Igni\Network\Exception\ClientException::forInactiveClient(1)
#1 /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Server.php(243): Igni\Network\Server->getClient(1)
#2 {main}
thrown in /Users/roquie/google_drive/experiments/igni-framework-test/vendor/igniphp/network/src/Exception/ClientException.php on line 22
[2019-03-02 14:02:46 $81920.0] WARNING swManager_check_exit_status: worker#6 abnormal exit, status=255, signal=0
[2019-03-02 11:02:46][INFO] - Client Igni\Network\Server\Client[2] connected
[2019-03-02 14:02:46 $81920.0] WARNING swManager_check_exit_status: worker#7 abnormal exit, status=0, signal=11
A bug occurred in Swoole-v4.2.13, please report it.
The Swoole developers probably don't know about it,
and unless you report it, chances are it won't be fixed.
You can read How to report a bug doc before submitting any bug reports:
>> https://github.com/swoole/swoole-src/issues/2000
Please do not send bug reports in the mailing list or personal letters.
The issue page is also suitable to submit feature requests.
How to reproduce?
cd examples && php build_in_server_example.php
I watch this behavior from PHP 7.3.0 version and Swoole 4.2.7. Probably this bug is a framework bug.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.