Download the PHP package cryonighter/formula-doctrine-bundle without Composer

On this page you can find all versions of the php package cryonighter/formula-doctrine-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package formula-doctrine-bundle

Formula Doctrine Bundle

Latest Version on Packagist Total Downloads

Symfony bundle for integrating cryonighter/formula-doctrine into Symfony applications.

It enables Hibernate-style #[Formula] computed fields for Doctrine ORM entities and wires the required Doctrine metadata listeners, SQL walker configuration and DBAL middleware automatically through Symfony's dependency injection container.

Use it when you want read-only entity properties whose values are computed by DQL/SQL expressions, subqueries, aggregations or joins — without adding physical database columns and without introducing N+1 queries.

Example with native SQL subquery – must be enclosed in parentheses:

Example using DQL subquery – should not be enclosed in parentheses:

With this bundle installed, formula fields are populated automatically when entities are loaded through Doctrine in a Symfony application. The bundle keeps your entity code focused on the #[Formula] attributes while taking care of registering the integration services needed by cryonighter/formula-doctrine.

Requirements

Install

Via Composer

The bundle will be automatically registered in config/bundles.php:

Bundle Registration Order

If you use other bundles that extend Doctrine ORM with custom SQL walkers (e.g. Gedmo DoctrineExtensions, API Platform), register FormulaDoctrineBundle last in config/bundles.php:

FormulaDoctrineBundle automatically detects and chains with any previously registered output walker, so both transformations are applied to every query.

If another bundle is registered after FormulaDoctrineBundle and also sets a custom output walker globally, you may need to manually call FormulaDoctrineConfigurator::configure() in your application's bundle.

Usage

Basic example

Add #[Formula] to any property on a Doctrine entity. The property must not be mapped with #[ORM\Column].

Fetching entities

No changes to your query code are needed. Formula fields are populated automatically on every DQL SELECT:

A single SQL query is executed — no N+1:

QueryBuilder

Works with QueryBuilder too:

And in the repositories too:

Methods find(), findBy(), findOneBy() and findAll() are also supported:

Using formula fields in queries

Formula fields can be used in WHERE, ORDER BY, GROUP BY and HAVING clauses just like regular entity properties:

WHERE clause

Filter entities by computed values:

ORDER BY clause

Sort by formula fields:

GROUP BY and HAVING clauses

Aggregate and filter by computed values:

Combined example

All clauses together in a single query:

Note: Formula fields work transparently in all query clauses. The SQL subquery is embedded only once per query, not per clause usage.

Aggregate functions

All DQL aggregate functions (e.g. COUNT, SUM, AVG, MIN, MAX) work with formula fields out of the box:

Note: MIN and MAX ignore NULL values — so nullable formula fields (e.g. ?float $maxOrderTotal) behave correctly even when some entities have no related records.

CASE WHEN expressions

Formula fields can be used inside CASE WHEN ... THEN ... END expressions directly in DQL — for categorisation, conditional sorting and custom labels:

Nullable fields

If a formula can return NULL (e.g. MAX on an empty set), declare the property as nullable — the type is inferred automatically:

The {this} placeholder

Use {this} to reference the root entity's table alias in the native SQL expression or root entity itself in the DQL expression.

In native SQL, {this} is resolved to the actual Doctrine-generated table alias (e.g. c0_):

In DQL, {this} refers to the root entity itself, so you compare against the entity reference directly — without a field suffix:

Do not hardcode the table name or alias directly — it will break when Doctrine generates a different alias.

Custom SELECT alias

By default the SQL column alias matches the property name. Override it with the alias parameter:

Use a custom alias only when you need to control the raw SQL column name, e.g. for compatibility with a specific reporting tool.

Nested Formulas

A #[Formula] expression can reference a formula field of another entity. The entire chain is resolved into a single SQL query.

Note: In a native SQL expression, reference another formula field by its alias if one is declared (e.g. c.total), or by the property name otherwise. In a DQL expression, always use the property name (e.g. c.orderCount).

UPDATE queries

Formula fields can be used in the WHERE clause of DQL UPDATE queries — filter which entities to update based on computed values:

Note: Formula fields are read-only and are never written to the database. They can only appear in WHERE clauses of UPDATE/DELETE — not in the SET clause.

DELETE queries

Formula fields work identically in DQL DELETE queries:

How it works

You can read about this in the description of the base package cryonighter/formula-doctrine.

Limitations

Limitation Notes
Read-only fields Formula fields must not have #[ORM\Column]. They are registered internally by the library and must never be written to the database.
Scalar types only Supported PHP types: int, float, string, bool, \DateTime, \DateTimeImmutable, \DateTimeInterface and their nullable variants. Always provide a default value for non-nullable formula properties (e.g. public int $orderCount = 0).
Native SQL $em->getConnection()->executeQuery(...) bypasses both Walker and Middleware entirely — formula fields will hold their default PHP values.
Schema Tool doctrine:schema:create and doctrine:schema:update do not create columns for formula fields — they have no physical column in the database. This is correct behaviour.
Walker Chaining order FormulaDoctrineBundle must be registered last in config/bundles.php among Doctrine-extending bundles to ensure correct Walker Chaining. See Bundle Registration Order.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

Contributing

Please see CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of formula-doctrine-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
cryonighter/formula-doctrine Version ^1.4.0
symfony/dependency-injection Version >=6.4
symfony/http-kernel Version >=6.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cryonighter/formula-doctrine-bundle contains the following files

Loading the files please wait ...