teamneusta / pimcore-website-settings-bundle
Typed, documented and audited website settings for Pimcore
Package info
github.com/teamneusta/pimcore-website-settings-bundle
Type:pimcore-bundle
pkg:composer/teamneusta/pimcore-website-settings-bundle
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- doctrine/dbal: ^3.8 || ^4.0
- doctrine/migrations: ^3.5
- pimcore/pimcore: ^11.5 || ^12.3 || ^2026.1
- psr/log: ^1.1 || ^2.0 || ^3.0
- symfony/config: ^6.4 || ^7.4
- symfony/console: ^6.4 || ^7.4
- symfony/dependency-injection: ^6.4 || ^7.4
- symfony/event-dispatcher: ^6.4 || ^7.4
- symfony/filesystem: ^6.4 || ^7.4
- symfony/http-foundation: ^6.4 || ^7.4
- symfony/http-kernel: ^6.4 || ^7.4
- symfony/routing: ^6.4 || ^7.4
- symfony/translation-contracts: ^3.0
- twig/twig: ^3.21
Requires (Dev)
- dama/doctrine-test-bundle: ^8.8
- ergebnis/composer-normalize: ^2.58
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.3.7
- phpstan/phpstan-phpunit: ^2.1.2
- phpstan/phpstan-symfony: ^2.1.1
- phpunit/phpunit: ^12.5 || ^13.4
- symfony/framework-bundle: ^6.4 || ^7.4
- symfony/polyfill-php85: ^1.33
- symfony/translation: ^6.4 || ^7.4
- teamneusta/pimcore-testing-framework: ^0.15.2
Suggests
- teamneusta/pimcore-testing-framework: To set website settings in tests with #[WithWebsiteSetting]
Provides
None
Conflicts
- teamneusta/pimcore-testing-framework: <0.15.2
Replaces
None
README
Typed, documented and audited website settings for Pimcore.
- A typed reader with one getter per Pimcore type, and formats for numbers, lists, dates, enums, URLs, e-mail addresses and elements of a class, also in templates
- A writer that saves and deletes settings for exactly one site and language
- Descriptions of the settings on an enum of your project: type, format, default, environments, deprecation and more
- Checks at runtime: getter verification, environment restriction, defaults, deprecations and a read event
- An audit of the stored settings, also in CI, and their validation on save
- A documentation page for editors in the Pimcore backend
- A panel in the Symfony profiler with the settings read and written
- Migrations that add website settings
- A PHPStan extension that checks the reads while analysing
- Helpers for tests of your project
Requirements
- PHP 8.3, 8.4 or 8.5
- Pimcore 11.5, 12.3 or 2026, with Symfony 6.4 or 7.4
- The backend documentation needs the Admin UI Classic (Pimcore 11 and 12)
- Optional: the Symfony WebProfilerBundle for the profiler panel, PHPStan 2 for the static analysis and
teamneusta/pimcore-testing-framework 0.15.2 or later
for
#[Test\WithWebsiteSetting]
Installation
-
Require the bundle
composer require teamneusta/pimcore-website-settings-bundle
-
Enable the bundle
Add the bundle to your
config/bundles.php:Neusta\Pimcore\WebsiteSettingsBundle\NeustaPimcoreWebsiteSettingsBundle::class => ['all' => true],
The bundle works without configuration. Its checks, the audit and the documentation need the descriptions of your settings; all options are listed in Configuration.
Reading website settings
Inject Neusta\Pimcore\WebsiteSettingsBundle\Reader\WebsiteSettingReader (service id neusta_pimcore_website_settings.reader).
It has one getter per Pimcore type, so the type is stated once, at the call site:
use Neusta\Pimcore\WebsiteSettingsBundle\Reader\WebsiteSettingReader; final class MaintenanceService { public function __construct( private readonly WebsiteSettingReader $websiteSettings, ) { } public function isMaintenanceMode(): bool { return $this->websiteSettings->getBool('maintenance_mode') ?? false; } }
The getters are getBool(), getString(), getAsset(), getDocument() and getObject().
Each returns null if the setting does not exist and throws Exception\TypeMismatch if it is stored with another type.
Like Pimcore, they read a bool or text stored without value as false or as an empty text.
The name may also be a case of a string-backed enum, resolved via ->value:
enum WebsiteSetting: string { case MaintenanceMode = 'maintenance_mode'; } $this->websiteSettings->getBool(WebsiteSetting::MaintenanceMode);
Formats
A stored value often means more than its Pimcore type, e.g. a text holding a number or a list of ids.
Read it with get() and a ValueFormat:
use Neusta\Pimcore\WebsiteSettingsBundle\Format\DateValue; use Neusta\Pimcore\WebsiteSettingsBundle\Format\IntList; use Neusta\Pimcore\WebsiteSettingsBundle\Format\IntValue; use Neusta\Pimcore\WebsiteSettingsBundle\Format\ObjectOf; use Pimcore\Model\DataObject\Folder; $maxItems = $this->websiteSettings->get('max_items', new IntValue()); // ?int $productIds = $this->websiteSettings->get('featured_product_ids', new IntList()); // ?list<int> $saleEnd = $this->websiteSettings->get('sale_end', new DateValue('d.m.Y')); // ?DateTimeImmutable $folder = $this->websiteSettings->get('product_folder', new ObjectOf(Folder::class)); // ?Folder
| Format | Stored as | Result | Example value |
|---|---|---|---|
IntValue |
text |
int |
42 |
FloatValue |
text |
float |
19.5 |
StringList($separator) |
text |
list<string> |
foo, bar |
IntList($separator) |
text |
list<int> |
1, 2, 3 |
DateValue($format) |
text |
DateTimeImmutable |
2026-11-26 |
EnumValue($enum) |
text |
case of the backed enum | grid |
UrlValue($schemes) |
text |
string |
https://example.com/terms |
EmailValue |
text |
string |
shop@example.com |
AssetOf($class) |
asset |
instance of $class |
|
DocumentOf($class) |
document |
instance of $class |
|
ObjectOf($class) |
object |
instance of $class |
get() returns null if the setting does not exist or holds an empty text; a described setting with a default
returns that instead (see Describing website settings). It throws
Exception\TypeMismatch if the setting is stored with another type than the format's, and Exception\InvalidValue
if the format cannot convert the value at all (a non-numeric text for IntValue, an element of another class for
ObjectOf).
Converting is lenient where a meaningful value remains: IntValue cuts off decimals, IntList drops parts that are
not numeric, DateValue lets an overflowing date like 31.02.2026 roll over.
All exceptions of the bundle implement Exception\WebsiteSettingException.
Your own formats are classes implementing ValueFormat:
type() is the stored Pimcore type, convert() interprets the value, validate() checks it strictly
and accepts() tells which declared formats it can read.
Site and language
Every getter takes the same optional arguments $language, $siteId and $fallbackLanguage:
$this->websiteSettings->getString('shop_name', language: 'de'); $this->websiteSettings->get('max_items', new IntValue(), siteId: 3);
- Without
$siteId, the setting is read from Pimcore's cached website config of the current site (Pimcore\Config::getWebsiteConfigValue()), including Pimcore's handling of the edit mode; so is the$fallbackLanguage, if the language has no value. - With
$siteId, the setting is looked up directly (WebsiteSetting::getByName()), so another site's settings can be read.
Both read a setting alike: a bool or text without value as false or as an empty text, an element that no longer
exists as null.
Note
The direct lookup bypasses Pimcore's cache: the first read of a setting with $siteId in a request queries the
database.
In templates
The Twig function website_settings() reads website settings through the reader service, with all its checks.
A language you pass is always used, whether the setting is localized or not. Without one, a setting is read in the
language of the current request (Pimcore's LocaleServiceInterface), or without language if it is described and
not localized:
{{ website_settings().get('max_items') }}
{{ website_settings().get(enum('App\\WebsiteSetting').ShopName, 'de') }}
{{ website_settings().get('product_folder', siteId: 3).key }}
<a href="{{ website_settings().document('imprint').fullPath }}">…</a>
get()reads a described setting as declared: in its format (e.g. anintforIntValue), or else as its type, with its default. It throws for a setting without description.bool(),string(),asset(),document()andobject()read a setting as the given type, described or not. Their return types are known to the IDE, so prefer them for elements whose methods you call in the template.
Tip
With the Symfony plugin of PhpStorm, website_settings() and the return types of its methods are completed,
also in chains like website_settings().document('imprint').fullPath. A variable assigned with {% set %}
does not keep the type; declare it with {# @var imprint \Pimcore\Model\Document #}.
Unlike Pimcore's pimcore_website_config(), the function applies the defaults, the environment restriction and
the read event. To determine the current language differently, replace the service
neusta_pimcore_website_settings.current_language with an implementation of Twig\CurrentLanguage.
To move templates away from Pimcore's function, deprecate it in favor of website_settings(), so each call
triggers a deprecation when the template is compiled, or remove it, so each call fails then
(and bin/console lint:twig finds it):
neusta_pimcore_website_settings: pimcore_website_config: deprecate # or: remove; default: allow
Writing website settings
Inject Neusta\Pimcore\WebsiteSettingsBundle\Writer\WebsiteSettingWriter (service id neusta_pimcore_website_settings.writer):
use Neusta\Pimcore\WebsiteSettingsBundle\Writer\Data; use Neusta\Pimcore\WebsiteSettingsBundle\Writer\Identifier; use Neusta\Pimcore\WebsiteSettingsBundle\Writer\WebsiteSetting; $this->writer->save(new WebsiteSetting( new Identifier('maintenance_mode', siteId: null, language: null), Data::bool(true), )); $this->writer->delete(new Identifier('maintenance_mode', siteId: null, language: null));
Data has one named constructor per type: bool(), text(), asset(), document() and object().
Site and language of the Identifier are matched exactly: saving a site-specific setting never overwrites the global
one, even though reading falls back from one to the other.
Saving and deleting clear Pimcore's runtime caches, so a read within the same request sees the change. Saving a described setting with an invalid value fails, see Validation on save.
Describing website settings
Describe every setting of your project on a string-backed enum. Each case gets a #[Setting] attribute,
the enum implements DescribedWebsiteSetting with the trait DescribedByAttribute:
use Neusta\Pimcore\WebsiteSettingsBundle\Format\IntValue; use Neusta\Pimcore\WebsiteSettingsBundle\Metadata\DescribedByAttribute; use Neusta\Pimcore\WebsiteSettingsBundle\Metadata\DescribedWebsiteSetting; use Neusta\Pimcore\WebsiteSettingsBundle\Metadata\LocalizedText; use Neusta\Pimcore\WebsiteSettingsBundle\Metadata\Setting; use Neusta\Pimcore\WebsiteSettingsBundle\Type; use Symfony\Component\Translation\TranslatableMessage; enum SettingGroup { case General; } enum WebsiteSetting: string implements DescribedWebsiteSetting { use DescribedByAttribute; #[Setting( description: 'Shows the maintenance page instead of the shop.', type: Type::Bool, group: SettingGroup::General, environments: ['prod'], )] case MaintenanceMode = 'maintenance_mode'; #[Setting( description: new LocalizedText(en: 'The name of the shop.', de: 'Der Name des Shops.'), type: Type::Text, localized: true, )] case ShopName = 'shop_name'; #[Setting( description: new TranslatableMessage('website_settings.max_items', domain: 'admin'), format: new IntValue(), required: true, )] case MaxItems = 'max_items'; }
| Argument | Meaning |
|---|---|
description |
For editors, who cannot see the code; state the fallback if the setting is missing. |
type |
The stored Pimcore type; may be omitted if a format is given. |
format |
The ValueFormat the setting is read with, see Formats. |
group |
Any enum case to group the settings by topic. |
localized |
One value per language is expected. |
siteSpecific |
Values per site are expected. |
required |
A missing or empty value is an error, there is no fallback. |
environments |
The kernel environments the setting may be active in, empty for all. |
default |
Read if no value or an empty text is stored: a bool, or a text (numbers are taken as text). |
deprecated |
Why the setting should not be used anymore; reading it triggers a deprecation. |
A default must fit the type and the format, e.g. default: 20 for new IntValue(), and is not possible for a
required setting or an element. get() converts it with its format, like a stored value. A bool stored without value
is read as false, not as its default, since Pimcore's cache cannot tell it from false.
The description is a plain string, a LocalizedText with one text per locale (named arguments, falling back from
de_CH to de to the first text), or any other TranslatableInterface like Symfony's TranslatableMessage.
Then list the enum in the bundle configuration:
# config/packages/neusta_pimcore_website_settings.yaml neusta_pimcore_website_settings: enums: - App\WebsiteSetting # optional: validates the environments of the settings against this list environments: [dev, test, prod]
The enums are validated when the container is built (e.g. by cache:warmup or lint:container): every enum must
implement DescribedWebsiteSetting and be backed by string, every case needs a valid #[Setting],
a name must not be used twice and the environments must be listed in environments (if given).
Attributes of your project
Mark settings for your own needs with your own attributes on the cases, next to #[Setting].
attribute() returns them, e.g. in a listener or a decorator of your own:
#[\Attribute(\Attribute::TARGET_CLASS_CONSTANT)] final class WithoutCacheTag { } enum WebsiteSetting: string implements DescribedWebsiteSetting { use DescribedByAttribute; #[Setting(description: 'The number of products per page.', format: new IntValue(), default: 20)] #[WithoutCacheTag] case PageSize = 'page_size'; } // in a listener of the WebsiteSettingReadEvent if ($event->context->attribute(WithoutCacheTag::class)) { return; }
They are created when the container is built, so their errors show up there as well.
Checks and events
The reader is decorated with the following decorators, from the outside in. They use the description of a setting, whether it is read with an enum case or by its name; settings without a description pass unchanged.
| Decorator | Configuration | Does |
|---|---|---|
| Getter verification | verify_getters (kernel.debug) |
Throws Exception\GetterMismatch if a setting is read with a getter or format that does not fit its declaration, even if it does not exist. |
| Event | events (true) |
Dispatches a Reader\WebsiteSettingReadEvent with every value read, if anyone listens. |
| Defaults | always | Returns the default of a setting if no value or an empty text is read, also outside of its environments. |
| Environment restriction | restrict_environments (true) |
Returns null for a setting outside of its environments and logs a warning once if a value would have taken effect. |
| Deprecations | always | Triggers a deprecation when a deprecated setting is read. |
A getter fits a declaration of its type. A format given to get() fits only a declared format it accepts
(see ValueFormat::accepts()): FloatValue reads a setting declared as IntValue, ObjectOf(DataObject::class)
one declared as ObjectOf(Folder::class), but no format reads a setting declared without one.
neusta_pimcore_website_settings: verify_getters: true # default: %kernel.debug% restrict_environments: true events: true
Tip
The getter verification runs in debug mode only, so a wrong getter fails in development and tests, but not in production.
The event carries the value as the reader returns it, after the defaults and the environment restriction, along with
a ReadContext (name, getter, format, language, site and the described setting):
use Neusta\Pimcore\WebsiteSettingsBundle\Reader\WebsiteSettingReadEvent; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; #[AsEventListener] final class TagWebsiteSettingsListener { public function __invoke(WebsiteSettingReadEvent $event): void { // e.g. tag the response with $event->context->name for the HTTP cache } }
To reject a read or replace a value, decorate neusta_pimcore_website_settings.reader with your own implementation
of Reader\WebsiteSettingReader.
Auditing the stored settings
bin/console neusta:website-settings:audit # errors and warnings bin/console neusta:website-settings:audit --errors-only # errors only
The command compares the stored website settings with their descriptions and fails if there are errors.
Run it in the environment to audit (--env).
| Severity | Finding |
|---|---|
| error | A required setting is not stored or empty. |
| error | A setting is stored with another type, or a value is invalid for its format (ValueFormat::validate()). |
| error | A setting is active (a true bool or any other value) outside of its environments. |
| error | A setting has values per language, but is not localized, so templates do not read them. |
| warning | An optional setting is not stored or empty, or references a deleted element (naming its default). |
| warning | A deprecated setting is still stored. |
| warning | A setting has values per site, but is not siteSpecific. |
| warning | A localized setting has no value for a language of the system settings, on a site or globally. |
| warning | A site-specific setting has values for sites only, so other sites get none. |
| warning | A stored setting is not described. |
Like Pimcore, the audit lets a value for all languages cover every language, and a global value every site.
The descriptions themselves are not its concern: they are checked when the container is built (see
Describing website settings), and by Test\WebsiteSettingAssertions.
In CI
A pipeline has no real data, but usually a fresh database with your migrations applied, e.g. for the integration
tests. The audit then checks that the migrations add what the descriptions require: a new required setting without
a migration fails the pipeline instead of the deployment. Pass --errors-only there, since every optional setting
that no migration adds is a warning.
--format writes the findings as a code quality report for GitLab (gitlab) or as annotations for GitHub Actions
(github), so a merge request shows them at the case of the setting in the enum; findings of settings without
description point to the first enum. Their paths are relative to the root of the Git repository, as GitLab and GitHub
expect them, also if the project lives in a subdirectory; pass --base-path for another base.
The command fails on errors in every format.
# .gitlab-ci.yml, in a job with a database website-settings:audit: script: - bin/console doctrine:migrations:migrate --no-interaction - bin/console neusta:website-settings:audit --errors-only --format=gitlab > gl-code-quality-report.json artifacts: when: always reports: codequality: gl-code-quality-report.json
# steps of a GitHub Actions job with a database - run: bin/console doctrine:migrations:migrate --no-interaction - run: bin/console neusta:website-settings:audit --errors-only --format=github
Against real data
Only the stored settings of an environment show what editors entered: run the audit there, e.g. as a step of the
deployment on the target environment, or as a scheduled job against staging or production. The table (the default)
suits a log, --format=json a monitoring.
bin/console neusta:website-settings:audit --env=prod --format=json
Validation on save
Saving a described setting fails with Exception\InvalidWebsiteSetting if the audit would report an error for its
value: another type, a value that is invalid for its format, an active value outside of its environments, or a
language for a setting that is not localized.
This applies to every save through Pimcore's WebsiteSetting::save(): in the backend, in migrations, in imports and
with the WebsiteSettingWriter. The exception is a Pimcore ValidationException, so the backend responds with its
message. With the Admin UI Classic, the website settings grid then reverts the changes that were not saved,
instead of showing them and sending them again with the next change.
An empty value passes, since the backend creates a setting before its value is entered; a missing required value is left to the audit. Settings without a description and the warnings of the audit never block saving.
neusta_pimcore_website_settings: validate_on_save: false # default: true
Documentation in the Pimcore backend
With the Admin UI Classic (Pimcore 11 and 12), editors with the permission website_settings find the entry
"Website Settings Documentation" in the "Settings" menu, below "Website Settings". It lists every setting with its
type and format, whether it is required, localized or site-specific, its default, its environments, the stored
languages and sites, the description in the editor's language (marked if deprecated) and the findings of the audit,
grouped by group. Columns that no setting uses are hidden, e.g. the environments if no setting is restricted;
the columns about languages and sites only if no setting is localized or site-specific and none is stored for a
language or site either. The column menu shows them again.
The page needs the assets of the bundle (bin/console assets:install) and reads a JSON endpoint at
/admin/neusta/website-settings/docs. Pimcore loads its route automatically from config/pimcore/routing.php;
below /admin, it is within the firewall of the Admin UI Classic.
The endpoint requires a backend user with the permission website_settings.
Important
Pimcore 2026 has no Admin UI Classic: there is no documentation page there, and the endpoint stays inaccessible until the bundle supports Pimcore Studio.
The format is shown with its arguments, e.g. ObjectOf(Folder) or DateValue("d.m.Y"); for your own formats,
the scalar properties are shown. A TranslatableMessage without text in the editor's language is reported
as a finding.
Symfony profiler
With the Symfony profiler enabled, e.g. in the dev environment, the toolbar and the profiler show a
"Website Settings" panel for each request, and with Symfony 7.3 or later also for a console command run with
--profile. It lists:
- the settings read, each once with its description, declared type and format, and the number of reads,
- every read with its getter or format, language, site and fallback language, the value, and where it was read,
e.g.
src/Controller/HomeController.php:12orhome.html.twig:5; the methods of your own reader marked with#[ReadsWebsiteSetting]are skipped, so their callers are shown, and a read while a template is rendered, e.g. in a Twig extension, shows the template, e.g.home.html.twig:5 (via src/Twig/AppExtension.php:20), - every save and delete through Pimcore, by the writer, the backend, a migration or Pimcore's API, and whether it completed; a write that did not complete was rejected, e.g. by the validation on save.
Each read gets hints from the description of its setting: rejected reads (e.g. by the getter verification) and missing required values are errors, deprecated settings and missing values are warnings, and the panel also notes settings without description, the default of a setting, settings ignored in the current environment and a setting read more than once at the same place, e.g. in a loop.
Elements are shown as their class without namespace, id and path, e.g. Page · #12 · /en/home; hovering shows the full
class name. The first 1000 reads and writes are kept in detail, beyond that they are only counted. Without a profiler,
nothing is traced.
Migrations
To add website settings in a Doctrine migration, extend Migration\AddWebsiteSettingsMigration and list the values:
the description, up() and down() follow from them.
use Neusta\Pimcore\WebsiteSettingsBundle\Migration\AddWebsiteSettingsMigration; use Neusta\Pimcore\WebsiteSettingsBundle\Migration\WebsiteSettingValue; final class Version20261126000000 extends AddWebsiteSettingsMigration { protected function websiteSettings(): iterable { yield new WebsiteSettingValue(WebsiteSetting::MaxItems, 42); yield new WebsiteSettingValue(WebsiteSetting::ShopName, 'Foo Laden', language: 'de'); yield new WebsiteSettingValue('legacy_flag', true, siteId: 3); } }
Adds the website settings "max_items", "shop_name" (language "de"), "legacy_flag" (site 3).
- The type is taken from the
#[Setting]of a described setting, or else from the value (bool, a scalar fortext, or the element). Only an empty value of a setting without description needstype:. - Without a value, a described setting gets its
default. An empty text would be read as the default as well. - A value that does not fit the type, or that the format of the setting rejects (
ValueFormat::validate()), throws. up()adds a setting only if it is not stored yet for exactly this site and language, so values changed by editors are kept.down()deletes only the settings that still have the value of the migration, so it keeps values changed since, and those that were stored with another value before. A setting that was stored with the same value before cannot be told apart from an added one, sodown()deletes it as well.
For other cases, e.g. deleting settings or mixing them with other changes, use the trait
Migration\MigratesWebsiteSettings in any migration: it offers addWebsiteSetting($name, $value, language:, siteId:, type:)
and deleteWebsiteSetting($name, language:, siteId:). Outside of migrations, use the WebsiteSettingWriter.
Caution
deleteWebsiteSetting() deletes the setting whatever its value, also one an editor changed.
Only down() of AddWebsiteSettingsMigration keeps changed values.
Static analysis with PHPStan
The bundle comes with an extension for PHPStan 2 that reports, while analysing, what the getter verification and the
deprecations report at runtime. With phpstan/extension-installer it is loaded automatically, otherwise include it:
includes: - vendor/teamneusta/pimcore-website-settings-bundle/extension.neon
| Identifier | Reports |
|---|---|
websiteSetting.getterMismatch |
A described setting is read with a getter or format that does not fit its declaration. |
websiteSetting.deprecated |
A deprecated setting is read. |
websiteSetting.intBackedName |
A setting is read with an enum case backed by int. |
websiteSetting.pimcoreApi |
Pimcore's API for website settings is used, which bypasses the bundle (opt-in). |
websiteSetting.invalidAttribute |
A #[ReadsWebsiteSetting] is invalid or names a classParameter the method lacks. |
It checks the reads of every WebsiteSettingReader, also of Test\InMemoryWebsiteSettingReader and your own
decorators, if the name is an enum case or a string. Configure it with the same enums as the bundle, so it finds names
given as strings in them and removes null from the reads of their settings with a default (see below):
parameters: neustaWebsiteSettings: enums: - App\WebsiteSetting
A format given to get() is checked if it is created right there with constant arguments, e.g. new DateValue('d.m.Y');
for any other format, only a setting declared without a format is reported. To do so, the extension loads the enums of
your project and creates the formats while analysing, as the bundle does when the container is built.
A project with its own reader, e.g. with getters of its own or another parameter for the language, marks its methods
with #[Reader\ReadsWebsiteSetting], giving the type or the format a method reads. The extension then checks their
calls like those of the getters, taking the name from the first argument:
use Neusta\Pimcore\WebsiteSettingsBundle\Format\IntValue; use Neusta\Pimcore\WebsiteSettingsBundle\Reader\ReadsWebsiteSetting; use Neusta\Pimcore\WebsiteSettingsBundle\Type; interface ShopSettingReader { #[ReadsWebsiteSetting(Type::Bool)] public function isEnabled(ShopSetting $setting, ?Locale $locale = null): ?bool; #[ReadsWebsiteSetting(format: new IntValue())] public function getInt(ShopSetting $setting, ?Locale $locale = null): ?int; /** * @param class-string<Document> $type */ #[ReadsWebsiteSetting(Type::Document, classParameter: 'type')] public function getTypedDocument(ShopSetting $setting, string $type, ?Locale $locale = null): ?Document; }
A method that takes the class of the asset, document or object it reads names that parameter as classParameter.
For a setting declared with AssetOf, DocumentOf or ObjectOf, a call with a class name, e.g.
getTypedDocument(ShopSetting::Imprint, Page::class), must then read the declared class or a parent class of it,
as with get() and new DocumentOf(Page::class). A setting declared by its type only fits any class.
The attribute only informs the static analysis; implement the methods with the WebsiteSettingReader, so its checks
and events apply at runtime as well.
A setting with a default is never read as null (if the getter or format reads its type), so the extension removes
null from the type of its reads, e.g. int instead of ?int for get(WebsiteSetting::PageSize, new IntValue()).
It does so only for the settings of the enums configured for it, since only the enums configured in the bundle get
their defaults at runtime. This applies to the WebsiteSettingReader service and to methods marked with
#[ReadsWebsiteSetting], which are expected to return what the reader returns; not to
Test\InMemoryWebsiteSettingReader, which applies defaults only with the enums. From level 4 on, PHPStan then reports
a ?? left behind such a read (nullCoalesce.expr), so a fallback like ?? 20 at the call sites can move into the
default of the setting.
Note
PHPStan's result cache does not know that a read depends on the description of its setting: after changing a
#[Setting], e.g. its default, run phpstan clear-result-cache to analyse the reads by a string name again.
So that nobody reads or saves website settings past the bundle by accident, the extension also reports the use of
Pimcore's API for them: Config::getWebsiteConfig(), Config::getWebsiteConfigValue(), WebsiteSetting::getByName()
and getById(), and save() and delete() of a WebsiteSetting. It is off by default, since it reports all existing
code; turn it on once the project uses the bundle throughout:
parameters: neustaWebsiteSettings: forbidPimcoreApi: true
Templates are not analysed by PHPStan, so pimcore_website_config() in Twig is not reported.
Tip
Turn off a rule for the whole project with its identifier:
parameters: ignoreErrors: - identifier: websiteSetting.deprecated
Testing
For unit tests of your own code, Test\InMemoryWebsiteSettingReader reads website settings from memory, without
database or kernel. Set the values as stored; they are read like from Pimcore, including types, formats and the
fallbacks of site and language. Given your enums, it also applies their defaults and deprecations and verifies
the getters:
use Neusta\Pimcore\WebsiteSettingsBundle\Test\InMemoryWebsiteSettingReader; $websiteSettings = (new InMemoryWebsiteSettingReader([WebsiteSetting::class])) ->set(WebsiteSetting::MaintenanceMode, true) ->set(WebsiteSetting::ShopName, 'Foo Laden', language: 'de'); $service = new MaintenanceService($websiteSettings);
Test\WebsiteSettingAssertions checks your enums like the container build does, but in a plain unit test:
use Neusta\Pimcore\WebsiteSettingsBundle\Test\WebsiteSettingAssertions; final class WebsiteSettingTest extends TestCase { use WebsiteSettingAssertions; public function testEveryWebsiteSettingIsDescribed(): void { self::assertDescribedWebsiteSettings([WebsiteSetting::class], ['dev', 'test', 'prod']); } }
For kernel tests with teamneusta/pimcore-testing-framework
(0.15.2 or later), #[Test\WithWebsiteSetting] stores a website setting for a test, on the class or the method,
and restores the previous one afterwards. The type is taken from the description of the setting, or else from the
value, as in migrations; the value is validated like on save:
use Neusta\Pimcore\TestingFramework\ConfigurablePimcore; use Neusta\Pimcore\WebsiteSettingsBundle\Test\WithWebsiteSetting; final class CheckoutTest extends KernelTestCase { use ConfigurablePimcore; #[WithWebsiteSetting(WebsiteSetting::MaxItems, 5)] #[WithWebsiteSetting('greeting', 'Hallo', language: 'de')] public function testTheCartIsLimited(): void { self::bootKernel(); // ... } }
A value that needs the booted kernel, e.g. an element, is returned by a closure (PHP 8.5) or a callable array like
[self::class, 'productFolder'], called when the test runs. A string is never called, since it may name a function:
#[WithWebsiteSetting(WebsiteSetting::ProductFolder, [self::class, 'productFolder'])] #[WithWebsiteSetting(WebsiteSetting::Imprint, static fn () => Document::getByPath('/en/imprint'))] // PHP 8.5 public function testTheProductsAreListed(): void { // ... } public static function productFolder(): ?DataObject\Folder { return DataObject\Folder::getByPath('/products'); }
Configuration
All options with their defaults; each is explained in its section. bin/console config:dump-reference neusta_pimcore_website_settings shows them as well.
# config/packages/neusta_pimcore_website_settings.yaml neusta_pimcore_website_settings: # the enums describing your website settings, see "Describing website settings" enums: [] # the kernel environments the settings may be restricted to; validated if given environments: [] # throws if a described setting is read with a getter or format that does not fit it verify_getters: '%kernel.debug%' # ignores a described setting outside of its environments restrict_environments: true # dispatches a WebsiteSettingReadEvent with every value read events: true # rejects saving a described setting with an error of the audit, see "Validation on save" validate_on_save: true # Pimcore's Twig function pimcore_website_config(): allow, deprecate or remove, see "In templates" pimcore_website_config: allow
Contribution
Feel free to open issues for any bug, feature request, or other ideas.
Please remember to create an issue before creating large pull requests.
Local Development
To develop on your local machine, the vendor dependencies are required.
bin/composer install
We use composer scripts for our main quality tools. They can be executed via the bin/composer file as well.
bin/composer cs:fix bin/composer phpstan bin/run-tests
The tests run against Pimcore 2026 by default. Pimcore 12 and 2026 need a license: copy compose.override.yaml.dist
to compose.override.yaml and fill in your values. To switch the Pimcore version:
bin/switch-pimcore-version 11 # or 12, 2026