PHP code example of insidestyles / swoole-bridge-bundle

1. Go to this page and download the library: Download insidestyles/swoole-bridge-bundle 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-bundle example snippets


     Insidestyles\SwooleBridgeBundle\SwooleBridgeBundle::class => ['all' => true],

class CustomHandler implements SwooleBridgeInterface
{    
    /**
     * @var SwooleBridgeInterface
     */
    private $swooleBridge;

    /**
     * @var RegistryInterface
     */
    private $doctrineRegistry;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * Handler constructor.
     * @param SwooleBridgeInterface $swooleBridge
     * @param null|LoggerInterface $logger
     */
    public function __construct(
        SwooleBridgeInterface $swooleBridge,
        RegistryInterface $doctrineRegistry,
        ?LoggerInterface $logger = null
    ) {
        $this->swooleBridge = $swooleBridge;
        $this->doctrineRegistry = $doctrineRegistry;
        $this->logger = $logger ?? new NullLogger();
    }

    /**
     * @inheritdoc
     */
    public function handle(
        SwooleRequest $swooleRequest,
        SwooleResponse $swooleResponse
    ): void {
        try {
            $this->swooleBridge->handle($swooleRequest, $swooleResponse);
        } catch (PDOException $e) {
            $this->logger->error($e->getMessage());
            /** @var Connection $connection */
            $connection = $this->doctrineRegistry->getConnection();
            if (!$connection->ping()) {
                $connection->close();
                $connection->connect();
            }
            $em = $this->doctrineRegistry->getEntityManager();
            if (!$em->isOpen()){
                $this->doctrineRegistry->resetManager();
            }
        } catch (\Throwable $e) {
            $this->logger->error($e->getMessage());
        }
    }
}