PHP code example of insidestyles / swoole-bridge

1. Go to this page and download the library: Download insidestyles/swoole-bridge library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

insidestyles / swoole-bridge example snippets



   $kernel = new Kernel($env, $debug);//App\Kernel or AppKernel;
   $psr15Kernel = new \Insidestyles\SwooleBridge\Adapter\Kernel\Psr15SymfonyKernel($kernel);
   
   //Laravel: $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
   //$psr15Kernel = new \Insidestyles\SwooleBridge\Adapter\Kernel\Psr15IlluminateKernel($kernel);
   
   //Zend Expressive: $psr15Kernel = $container->get(\Zend\Expressive\Application::class);
   
   $host = '127.0.0.1';
   $port = 8080;
   
   $http = new \swoole_http_server($host, $port);
   $responseEmitter = new \Insidestyles\SwooleBridge\Emiter\SwooleResponseEmitter();
   $requestBuilderFactory = new \Insidestyles\SwooleBridge\Builder\RequestBuilderFactory();
   $factory = new \Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory();
   $adapter = new \Insidestyles\SwooleBridge\Adapter\SymfonyAdapter($responseEmitter, $psr15Kernel, $requestBuilderFactory);
   $logger = new \Psr\Log\NullLogger();
   $handler = new \Insidestyles\SwooleBridge\Handler($adapter, $logger);
   
   $http->on(
       'request',
       function (\Swoole\Http\Request $request, \Swoole\Http\Response $response) use ($handler) {
           $handler->handle($request, $response);
       }
   );
   
   $http->start();