Code Monkey home page Code Monkey logo

framework's People

Contributors

dkraczkowski avatar garak avatar oshdev avatar roquie avatar smalot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

framework's Issues

Last router method with same name is overwrite previous with other http method

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.

Can i disable log

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。

Howto to use mysql queries (coroutine) in controller

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 ?

In the middleware request attributes does not parsed and filled to the object

How to reproduce?

  1. Register middleware with following code:
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);
  1. Register container or callback with route attribute, like /user/{user_id}
  2. Dump the $request->getAttribute('user_id') in the middleware and in the destination controller.
  3. Run it.

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? :)

How to call registered Module for each request?

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.

In tests not possible to pass attributes by example

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.

Workerman support

@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?

How I can register my additional services in the service provider?

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?

Router use private properties which disable any route listing

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" ?

Switch router to Symfony

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.

Exception handling

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?

Create custom ErrorMiddleware to support Rest

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 ?

PHP 7.3 support

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?

  1. clone framework repo
  2. install composer deps
  3. 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.