neunerlei / lockpick-bundle
一个将我的lockpick包无缝集成到Symfony的包
0.0.5
2023-03-16 07:56 UTC
Requires
- neunerlei/lockpick: ^0.0.10
README
这是一个将neunerlei/lockpick无缝集成到您的Symfony项目的包。
注意事项:如果您使用此包,请确保您理解其使用不当可能带来的影响和潜在问题。
安装
使用composer安装此包
composer require neunerlei/lockpick-bundle
此包已在Symfony 5.4和6.1上进行了测试。
配置
遗憾的是,由于“类覆盖”魔法深入系统,我们无法可靠地使用Symfony兼容的“配置”结构定义方式。(例如,当您想要覆盖框架类,或者因为某些包在配置加载之前已经加载了类)。
因此,我们提供了一种可靠的方式来配置您的symfony应用程序中的类覆盖。
对于配置,将\Neunerlei\LockpickBundle\ClassOverridesKernelTrait
特质添加到您的应用程序的Kernel
类中;通常位于App\Kernel
。现在您可以覆盖boot
方法,以在您的应用程序中注册所需的覆盖。
<?php namespace App; use App\Override\NotSoFinalUrlHelper; use Neunerlei\LockpickBundle\ClassOverridesKernelTrait; use Neunerlei\LockpickBundle\Overrides\OverrideGeneratorConfig; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Component\HttpFoundation\UrlHelper; use Symfony\Component\HttpKernel\Kernel as BaseKernel; class Kernel extends BaseKernel { use MicroKernelTrait; // Add this trait to your kernel use ClassOverridesKernelTrait; /** * @inheritDoc */ public function boot(): void { // The configureOverrideGenerator accepts a closure as parameter, which will receive an instance of // {@see OverrideGeneratorConfig} you can use to configure all facets of the override generator... $this->configureOverrideGenerator(static function (OverrideGeneratorConfig $config): void { // You can add your overrides through the speaking configuration interface, // take a look at the code documentation if you feel lost. $config->registerOverride(UrlHelper::class, NotSoFinalUrlHelper::class); // You can also chain multiple overrides $config ->registerOverride(AcmeBundle\ClassToOverride::class, YourBundle\ClassToOverrideWith::class) ->registerOverride(AnotherAcmeBundle\AnotherClassToOverride::class, YourBundle\AnotherClassToOverrideWith::class); // Those options are optional and will be automatically set if omitted: // The absolute path to your composer autoload.php. If omitted the script tries to find the autoloader itself $config->setComposerAutoloadPath('/...'); // The path where the generated class copies should be stored $config->setStoragePath('/...') }); // IMPORTANT! Configure the override generator BEFORE calling parent::boot()! parent::boot(); } }
覆盖其他包的小贴士
为了覆盖其他包的文件,我强烈建议您手动修改/config/bundles.php
。确保Neunerlei\LockpickBundle\LockpickBundle::class
在列表顶部加载,以便魔法在容器处理源之前发生。
<?php return [ Neunerlei\LockpickBundle\LockpickBundle::class => ['all' => true], // <- The bundle should be loaded here... Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], ];
需要帮助 如果您知道如何说服Symfony在所有其他包之前预加载此包,除了手动调整bundles.php
之外,请告诉我!:)
注意事项
- 由于Symfony架构,无法轻松覆盖大多数框架核心类。您可以尝试,但不要期望在没有问题的情况下工作。
明信片软件
您可以使用此包,但如果它进入了您的生产环境,我将非常感激您从您的家乡寄给我一张明信片,提及您正在使用我们的哪些包。
您可以在这里找到我的地址。
谢谢 :D