jefero/bot_common

安装: 10

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:项目


README

为多个平台方便创建机器人的库

安装

使用Composer安装bot_common

  composer require jefero/bot_common

配置

class Kernel extends BaseKernel
{
    //Path to library
    private const COMMON_PATH = 'vendor/jefero/bot_common';

    use MicroKernelTrait;

    //Import bot containers
    protected function configureContainer(ContainerConfigurator $container): void
    {
        $container->import('../' . self::COMMON_PATH . '/config/{packages}/*.yaml');
        $container->import('../' . self::COMMON_PATH . '/config/{packages}/' . (string)$this->environment . '/*.yaml');
        $container->import('../' . self::COMMON_PATH . '/config/services.yaml');
        $container->import('../' . self::COMMON_PATH . '/config/{services}_' . (string)$this->environment . '.yaml');

        //...other settings
    }

    //Import bot routes
    protected function configureRoutes(RoutingConfigurator $routes): void
    {

        $routes->import('../' . self::COMMON_PATH . '/config/{routes}/' . (string)$this->environment . '/*.yaml');
        $routes->import('../' . self::COMMON_PATH . '/config/{routes}/*.yaml');

        //...other settings
    }

    //Add method for register bot bundles
    public function registerBundles(): iterable
    {
        /** @psalm-suppress UnresolvableInclude */
        $commonBundles = require $this->getProjectDir() . '/' . self::COMMON_PATH . '/config/bundles.php';
        /** @psalm-suppress UnresolvableInclude */
        $currentBundles = require $this->getProjectDir() . '/config/bundles.php';
        $bundles = array_merge($commonBundles, $currentBundles);

        foreach ($bundles as $class => $envs) {
            /** @psalm-suppress UndefinedClass */
            yield new $class();
        }
    }
}

将jefero_common_dir参数添加到您的services.yaml文件中

parameters:
    jefero_common_dir: '%kernel.project_dir%/vendor/jefero/bot_common'
    #...other params