onion/swoole

支持Onion应用程序的Swoole兼容包

1.0.0 2018-06-02 16:59 UTC

This package is auto-updated.

Last update: 2024-08-29 04:54:23 UTC


README

这是一个最小的包装器,用于处理创建Swoole\Http\Server以及其初始化,并允许任何已经使用onion/framework编写的应用程序与应用程序服务器“直接工作”。

配置

此包的默认工厂需要添加一些基本的配置才能启动

配置

<?php
### Configuration
return [
    'application' => [
        'server' => [
            'address' => '', // The address on which to bind the app server. Binds on '0.0.0.0' if none is provided
            'port' => 1234, // The port on which the server to listen. A random one will be used if none is provided
            'options' => [ // A list of options that is being passed directly to `Swoole\Http\Server::set()` for configuration

            ]
        ]
    ]
];

依赖项

<?php
return [
    'factories' => [
        // ... Definitions
        // The base application is still in use, just make sure to register it directly as class name
        \Onion\Framework\Application\Application::class => \Onion\Framework\Application\Factory\ApplicationFactory::class,
        // The app server
        \Swoole\Http\Server::class => \Onion\Extra\Swoole\Factory\HttpServerFactory::class,
        // The definition of the application wrapper
        \Onion\Framework\Application\Interfaces\ApplicationInterface::class => \Onion\Framework\Application\Factory\SwooleApplicationFactory::class,
        // ... More definitions
    ],
];

请注意,我们假设您在index.php文件中有类似以下的内容

<?php

// Bootstrap

/**
 * Note the usage of the ApplicationInterface to fetch the application instance,
 * this (or your equivalent) key should be changed to return the SwooleApplication
 * instance
 */
$container->get(\Onion\Framework\Application\Interfaces\ApplicationInterface::class)
    ->run(); // Note the ServerRequest::fromGlobals() is not necessary here, so it can be omitted