pedrotroller/symfony-integration-checker

断言您的bundle与symfony的集成仍然有效。

v3.0.0 2020-01-31 10:29 UTC

This package is auto-updated.

Last update: 2024-08-29 04:19:27 UTC


README

安装

$ composer require pedrotroller/symfony-integration-checker --dev

使用

您只需要创建一个 .symfony_checker 文件。这个脚本应该返回一个回调。这个回调将有一个 PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel 实例作为参数。

use PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel;

return function (ConfigurableKernel $kernel) {
    // Your configuration
};

启动检查器

$ ./bin/symfony-integration-checker check

可用的内核定制

$kernel->addBundle(BundleInterface $bundle): 您可以将bundle动态注入到内核中。

$kernel->setConfig(array $config): 注入配置。

$kernel->setContainerBuilder(ContainerBuilder $container): 注入自己的容器。

$kernel->afterBoot(callable $callable): 注入一个可调用的函数。这个函数将在内核启动后执行。

示例

<?php

use PedroTroller\Symfony\IntegrationChecker\ConfigurableKernel;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Translation\TranslatorInterface;

$config = array(
    'framework' => array(
        'translator' => array(
            'enabled' => true,
        ),
    ),
);

$test = function (KernelInterface $kernel) {
    if (false === $kernel->getContainer()->get('translator') instanceof TranslatorInterface) {
        throw new \Exception('Oups, there is a problem !');
    }
};

return function (ConfigurableKernel $kernel) use ($config, $test) {
    $container = new ContainerBuilder();
    $container->setParameter('kernel.secret', md5(time()));

    $kernel
        ->setContainerBuilder($container)
        ->setConfig($config)
        ->addBundle(new FrameworkBundle())
        ->afterBoot($test)
    ;
};