Download the PHP package suvera/winter-doctrine without Composer

On this page you can find all versions of the php package suvera/winter-doctrine. 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 winter-doctrine

WinterBoot Module - Doctrine

Winter Doctrine is a module that provides easy configuration and access to Doctrine orm/dbal functionality from WinterBoot applications.

About Doctrine:

Setup

To enable Doctrine module in applications, append following code to application.yml

application.yml

in your application.yml file you might already have setup datasources like this.

In below example, there are two datasources configured here with names.

  1. defaultdb (isPrimary: true)
  2. admindb

Datasource url

url is a PDO-style DSN whose prefix selects the DBAL driver:

url prefix DBAL driver
mysql: pdo_mysql
oci: pdo_oci
sqlite: sqlite3 (or pdo_sqlite when ext-sqlite3 is missing); sqlite::memory: for in-memory
any DBAL driver name (pdo_mysql:, mysqli:, pdo_pgsql:, pgsql:, pdo_sqlsrv:, ...) used as is

The key=value;... pairs after the prefix become DBAL connection parameters (host, port, dbname, charset, ...). Any doctrine.* key other than entityPaths/isDevMode (for example doctrine.driver, doctrine.charset, doctrine.serverVersion, doctrine.driverOptions) overrides the parameter of the same name; empty values are ignored. username/password override credentials embedded in the DSN.

ORM/DBAL beans can be Autowired. No need to created them manually.

Bean names are suffixed as following way. Autowired code should input bean name.

Bean Type Bean Name
ORM EntityManager {name}-doctrine-em
ORM Tranaction Manager {name}-doctrine-emtxn
DBAL Connection {name}-doctrine-dbal
DBAL Tranaction Manager {name}-doctrine-dbaltxn

Examples below

ORM EntityManager

ORM Transaction Managers

DBAL Connection

DBAL Transaction Managers

Coroutine-scoped EntityManagers (Swoole)

Think of the EntityManager as a notebook. It remembers every database row your code has touched, so it does not have to ask the database twice. That is great inside one request — and dangerous on a Swoole server, where one worker handles hundreds of requests one after another. Without protection, request number 2 would read request number 1's old notes instead of fresh data from the database. Worse, two requests running at the same time would scribble in the same notebook and corrupt each other's unflushed changes.

This library fixes that for you, automatically. Under Swoole, every request (or job, or message) silently gets its own blank notebook with its own database connection. When the request finishes, its notebook is thrown away. You change nothing in your code.

Your existing code keeps working exactly as it is:

Bean names, instanceof EntityManager checks, type-hints, and both transaction styles (#[Transactional] and EmTransactionManager) all work unchanged. Code paths that never touch the database allocate nothing, and short-lived CLI scripts behave exactly as before.

You can turn the whole thing off with one flag (it is on under Swoole and off without it):

With false, every datasource has one EntityManager per worker, shared by every request the worker serves. That is only safe when a worker runs one request at a time (no Swoole coroutine hooks, enable_coroutine off). With coroutines on, concurrent requests share one transaction and one notebook, and find() can hand one tenant an entity another tenant's request loaded, straight from memory, without any tenant filter running. The library logs a warning at boot when the flag is false while Swoole is loaded.

Four rules to stay out of trouble:

  1. Always use the injected EntityManager itself. Do NOT save things it gives you (getRepository() results, query builders) into a property and reuse them later — those belong to one request's notebook, which gets thrown away. Fetch them fresh from the EntityManager every time:

  2. Keep event listeners stateless. One shared event dispatcher serves all requests, so a listener that stores things in its own properties will mix up requests. Compute from the event, store nothing.

  3. Long-running loops are the one exception. A daemon or scheduler that processes 10,000 items inside a single never-ending task reuses one notebook for all 10,000 items — and it keeps growing. Wrap each round so it gets a blank notebook, and you never have to think about it again:

    You do NOT need this helper for normal controllers, services, SQS/Kafka consumers, or scheduled jobs. Those already get a fresh notebook per run. Only loops that never end need it.

  4. One database connection per concurrent request, with a safety cap. A blank notebook is useless without its own pen: every request that touches the database opens its own real database connection, so two requests can never share (and corrupt) one. Requests that never touch the database open none, and every connection is closed when its request finishes. The log line Doctrine open DB connections: {...} shows you the live count per pool — watch it after deploys.

    To stop a runaway fan-out from exhausting the database, each pool is capped at 50 open connections. When all 50 are busy, the next request waits up to 5 seconds for one to free up; if none does, it fails fast with a clear PoolExhaustedException instead of silently sharing (sharing would bring back the corruption bug). Tune both in application.yml:

    A single datasource can override both caps in its own connection block (the override wins over the global defaults):

    How to size the cap: add up every pool (one EntityManager pool plus one DBAL pool per datasource, per tenant — using each datasource's override where one is set), multiply by your Swoole worker count, and keep the total below the database's max_connections (MySQL defaults to 151, Postgres to 100). When in doubt, keep 50 and raise the database limit first — a loud PoolExhaustedException telling you to raise the cap is always better than a cryptic "too many connections" from the database at 3 AM.

    Failures fail closed: if a request cannot get its own connection (pool exhausted, connection cannot be created), the error is thrown rather than handing the request a shared connection.

    REQUIRES_NEW and NOT_SUPPORTED transactions run on their own, dedicated connection, which counts toward maxConnections like any other. A REQUIRES_NEW call inside a transaction therefore needs two free connections; with maxConnections: 1 it waits and then throws PoolExhaustedException.

How to use Transactions

Declarative Transactions (AOP)

Executing something under ORM/DBAL transaction is easy by just using #[Transactional] annotation:

Always name the Doctrine transaction manager. A bare #[Transactional] resolves winter-boot's default PlatformTransactionManager (the PDBC datasource manager), which runs on a different connection: EntityManager writes would not be part of that transaction.

Propagation behaves as in winter-boot:

Programmatic Transactions

For fine-grained control, use EmTransactionManager (ORM) or DbalTransactionManager (DBAL) with the getTransaction()/commit()/rollback() pattern.

ORM Example — UserService with EmTransactionManager

DBAL Example — UserDbalService with DbalTransactionManager


Distributed Locking (DbalLockManager)

DbalLockManager makes #[Lockable] exclusive across every pod that uses the same database, through a Doctrine DBAL connection. It needs Winter Boot 2.1.6 or later.

How it works:

Multi-Tenant Support

Winter Doctrine provides native support for multi-tenancy via MultiTenantManager and TenantDataSourceProvider (from winter-boot), allowing per-tenant EntityManager, Connection, and transaction manager instances.

Configuration via application.yml

You can configure multi-tenant data sources directly in your application.yml by registering a provider class:

providerClass must implement TenantDataSourceProvider and be a bean of that class (e.g. a #[Component]). Each tenant's DataSourceConfig::getUrl() uses the same DSN format as standard datasources (see Datasource url). doctrine.entityPaths / doctrine.isDevMode apply to every tenant of this manager; all tenants share one ORM configuration.

When configured, Winter Doctrine automatically initializes and registers a MultiTenantManager bean named <name>-manager (e.g. tenantdb-manager) in the application context.

Step 1: Implement TenantDataSourceProvider

Create a bean class that implements TenantDataSourceProvider and point providerClass at it.

Step 2: Use in Business Classes

With Multiple MultiTenantManagers

If you have multiple multi-tenant data sources:

API Reference

MultiTenantManager

The MultiTenantManager class manages tenant-specific Doctrine connections and entity managers.

getEntityManager

Returns a cached per-tenant EntityManager.

Input Parameter Type Description
$tenantId string The unique identifier of the tenant
Output Type Description
Return EntityManager Per-tenant EntityManager instance

getConnection

Returns a cached per-tenant Connection.

Input Parameter Type Description
$tenantId string The unique identifier of the tenant
Output Type Description
Return Connection Per-tenant Connection instance

getEmTransactionManager

Returns a cached per-tenant EmTransactionManager.

Input Parameter Type Description
$tenantId string The unique identifier of the tenant
Output Type Description
Return EmTransactionManager Per-tenant ORM transaction manager instance

getDbalTransactionManager

Returns a cached per-tenant DbalTransactionManager.

Input Parameter Type Description
$tenantId string The unique identifier of the tenant
Output Type Description
Return DbalTransactionManager Per-tenant DBAL transaction manager instance

Helper Methods

Row-Level Tenant Filters (ParameterizedFilter)

When tenants share tables (a tenant_id column) rather than databases, register a Doctrine SQLFilter per datasource and every query, find(), repository call, lazy load and collection is limited to the current tenant.

Listed filters are registered and enabled on every EntityManager. A filter that implements ParameterizedFilter supplies its own parameters from request state:


All versions of winter-doctrine with dependencies

PHP Build Version
Package Version
Requires php Version >=8.5
doctrine/orm Version ^4.0
symfony/cache Version 8.1.x
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 suvera/winter-doctrine contains the following files

Loading the files please wait ...