Environment Builder
An environment builder creates a State instance describing a
fully bootstrapped TYPO3 environment for a given State.
The build context
The State is a small, immutable DTO describing what
environment should be built:
use FGTCLB\EnvironmentStateManager\StateBuildContext;
use TYPO3\CMS\Core\Http\ApplicationType;
$stateBuildContext = new StateBuildContext(
applicationType: ApplicationType::FRONTEND,
pageId: 1,
languageId: 0,
);
The factory
The concrete builder differs between the supported TYPO3 core versions. Use the
Environment to retrieve a TYPO3 core version
compatible builder for the given context. The factory is registered as a public
service and can be injected through dependency injection:
use FGTCLB\EnvironmentStateManager\EnvironmentBuilderFactoryInterface;
use FGTCLB\EnvironmentStateManager\StateBuildContext;
use FGTCLB\EnvironmentStateManager\StateInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
final class MyService
{
public function __construct(
private readonly EnvironmentBuilderFactoryInterface $environmentBuilderFactory,
) {}
public function buildState(int $pageId): StateInterface
{
$stateBuildContext = new StateBuildContext(
applicationType: ApplicationType::FRONTEND,
pageId: $pageId,
languageId: 0,
);
$environmentBuilder = $this->environmentBuilderFactory->create($stateBuildContext);
return $environmentBuilder->build($stateBuildContext);
}
}
The returned State holds the bootstrapped environment elements,
for example the Server, the
Typo, the Page and the
Context.
Note
Always type-hint the Environment,
Environment and State, never the
concrete Core12* or Core13* classes. The dependency injection
container resolves the implementation for the running TYPO3 core version. See
Public API and stability for the full public API surface.
Note
Currently only the Application application type is
implemented, provided by the Frontend. Support for
Application is planned to be added later; until then a
Runtime is thrown for it. A
FGTCLBEnvironment
exception is thrown when no builder is available for the current TYPO3 core
version.
In most cases you do not interact with the builder directly but use the state manager, which uses the factory internally.