achttienvijftien/wp-twig-bundle
Composer 安装命令:
composer require achttienvijftien/wp-twig-bundle
包简介
Bridges a host-owned Twig environment (Timber, ...) into the 1815 service container as the twig service
README 文档
README
Bridges a host-owned Twig environment (Timber, ...) into the
1815 service container
as the twig service.
What it does
- The
twigservice: the container exposes the host's Twig environment (captured via aTwigEnvironmentHolder) astwig/Twig\Environment, so container services render with the SAME instance the host renders with. - A LOAD-BEARING bundle name: the bundle class is named
TwigBundleon purpose.Bundle::getName()returns the short class name, and packages such as ux-twig-component refuse to load unlesskernel.bundlescontains a'TwigBundle'key. Registering this bundle satisfies that check honestly: this IS the bundle that provides thetwigservice in this stack. Symfony's own TwigBundle cannot be registered alongside it (duplicate name), which is correct: the two architectures are mutually exclusive. - The adapter seam:
TwigAdapterabstracts who owns the environment. A Timber adapter is included; for Tile or plain Twig, implementTwigAdapterand alias it in your container. - The configurator tag: other bundles contribute environment setup
(lexers, escaper safe-classes, ...) by implementing
EnvironmentConfiguratorInterface, autoconfigured with thewp_twig.configuratortag. The bundle also consumes the standardtwig.extensionandtwig.runtimetags, like Symfony's TwigBundle would. - Auto
@BundleNametemplate namespaces: on boot, every registered bundle's<path>/templatesdirectory is registered on the host loader as@<BundleName minus the Bundle suffix>(e.g. ux-turbo's templates become@Turbo), mirroring symfony/twig-bundle's convention so templates and component resolution written against the native bundle work unchanged.
Usage
The package self-registers its bundle through composer autoload.files
(filter achttienvijftien/container_bundles). Once the container boots:
$twig = apply_filters( 'achttienvijftien/container', null )->get( 'twig' ); // Same environment Timber renders with, after Timber built it.
Contribute environment setup from another bundle:
class MyConfigurator implements \AchttienVijftien\Bundle\WpTwigBundle\EnvironmentConfiguratorInterface { public function configure( \Twig\Environment $environment ): void { // runs once per host environment instance } }
Timber adapter included; Tile/other hosts: implement TwigAdapter.
Compatibility
This package is service-id + tag level compatible with code written against symfony/twig-bundle:
- the
twigservice /Twig\Environmentalias and the lazytwig.loaderservice exist with the expected semantics; - the
twig.extensionandtwig.runtimetags are consumed; @Bundletemplate namespaces auto-register per the same convention.
It is NOT FQCN-level compatible: class_exists gates on
Symfony\Bundle\TwigBundle\... classes cannot be satisfied, because that
package is deliberately not installed.
Future: native symfony/twig-bundle
The door stays open, but environment OWNERSHIP is the blocker: Timber owns
its Twig environment (and its autoescape defaults differ from the native
bundle's), so the container cannot simply build a second, authoritative
environment without splitting rendering in two. Adoption is viable per-host
through the TwigAdapter seam: a container-first host could invert the
bridge and hand the container's environment to the host instead, at which
point the native bundle could own the twig service.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2026-06-12