Code Monkey home page Code Monkey logo

Comments (5)

roquie avatar roquie commented on May 21, 2024 1

If a 35'th PR will be accepted the answer to my question will follow this:

use Igni\Application\Http\MiddlewareAggregator;
use Igni\Application\Providers\MiddlewareProvider;
use Igni\Application\Providers\ServiceProvider;
use Microparts\Configuration\Configuration;
use Microparts\I18n\I18nInterface;
use Microparts\I18n\Manager;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface;

class I18nModule implements MiddlewareProvider
{
    /**
     * @param \Igni\Application\Http\MiddlewareAggregator $aggregate
     */
    public function provideMiddleware(MiddlewareAggregator $aggregate): void
    {
        /** @var \Igni\Container\ServiceLocator $container */
        $container = $aggregate->getContainer();

        $aggregate->use(function (ServerRequestInterface $request, callable $next) use ($container) {
            $container->share(I18nInterface::class, function (ContainerInterface $container) use ($request) {
                $manager = new Manager($container->get(Configuration::class));
                return $manager->withMessage($request)->load();
            });

            return $next($request);
        });
    }
}

I don't think that this a pretty solution, because the method does not, contains the second argument with the application container... but it works.

from framework.

roquie avatar roquie commented on May 21, 2024

My task is a register following service to the Igni ServiceLocator. This service depends on other class which registered in ServiceLocator and depends on SwooleHttpRequest (wrapped in the Igni ServerRequest).

Following method won't work because globals vars not filled when Swoole the starts own server:
https://github.com/microparts/igni-support-php/blob/master/src/Modules/I18nModule.php#L27

For the better understanding similar cases )

from framework.

roquie avatar roquie commented on May 21, 2024

I found some bugs, good time to create a PR

from framework.

roquie avatar roquie commented on May 21, 2024

First igniphp/network#6

from framework.

roquie avatar roquie commented on May 21, 2024

Second #35 :)

from framework.

Related Issues (20)

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.