This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project

Overview

psr-container-doctrine: Doctrine Factories for PSR-11 Containers

Latest Stable Version Total Downloads Build Status

Doctrine factories for PSR-11 containers.

This package provides a set of factories to be used with containers using the PSR-11 standard for an easy Doctrine integration in a project. This project was originally written by @DASPRiD but maintenance has been taken over by Roave.

Installation

The easiest way to install this package is through composer:

$ composer require roave/psr-container-doctrine

Configuration

In the general case where you are only using a single connection, it's enough to define the entity manager factory:

return [
    'dependencies' => [
        'factories' => [
            'doctrine.entity_manager.orm_default' => \Roave\PsrContainerDoctrine\EntityManagerFactory::class,
        ],
    ],
];

If you want to add a second connection, or use another name than "orm_default", you can do so by using the static variants of the factories:

return [
    'dependencies' => [
        'factories' => [
            'doctrine.entity_manager.orm_other' => [\Roave\PsrContainerDoctrine\EntityManagerFactory::class, 'orm_other'],
        ],
    ],
];

You can also define an alias to retrieve an entity manager instance using ::class capability:

return [
    'aliases' => [
        'doctrine.entity_manager.orm_default' => Doctrine\ORM\EntityManagerInterface::class,
    ],
];

Each factory supplied by this package will by default look for a registered factory in the container. If it cannot find one, it will automatically pull its dependencies from on-the-fly created factories. This saves you the hassle of registering factories in your container which you may not need at all. Of course, you can always register those factories when required. The following additional factories are available:

  • \Roave\PsrContainerDoctrine\CacheFactory (doctrine.cache.*)
  • \Roave\PsrContainerDoctrine\ConnectionFactory (doctrine.connection.*)
  • \Roave\PsrContainerDoctrine\ConfigurationFactory (doctrine.configuration.*)
  • \Roave\PsrContainerDoctrine\DriverFactory (doctrine.driver.*)
  • \Roave\PsrContainerDoctrine\EventManagerFactory (doctrine.event_manager.*)

Each of those factories supports the same static behavior as the entity manager factory. For container specific configurations, there are a few examples provided in the example directory:

Example configuration

A complete example configuration can be found in example/full-config.php. Please note that the values in there are the defaults, and don't have to be supplied when you are not changing them. Keep your own configuration as minimal as possible. A minimal configuration can be found in example/minimal-config.php

Migrations

If you want to expose the migration commands, you have to map the command name to CommandFactory. This factory needs migrations config setup. For ExecuteCommand example:

return [
    'dependencies' => [
        'factories' => [
            \Doctrine\Migrations\Tools\Console\Command\ExecuteCommand::class => \Roave\PsrContainerDoctrine\Migrations\CommandFactory::class,

            // Optionally, you could make your container aware of additional factories as of migrations release v3.0:
            \Doctrine\Migrations\Configuration\Migration\ConfigurationLoader::class => \Roave\PsrContainerDoctrine\Migrations\ConfigurationLoaderFactory::class,
            \Doctrine\Migrations\DependencyFactory::class => \Roave\PsrContainerDoctrine\Migrations\DependencyFactoryFactory::class,
        ],
    ],
];

You can find a full list of available commands in example/full-config.php.

Using the Doctrine CLI

In order to be able to use the CLI tool of Doctrine, you need to set-up a cli-config.php file in your project directory. That file is generally quite short, and should look something like this for you:


$container = require 'config/container.php';

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(
    $container->get('doctrine.entity_manager.orm_default')
);

After that, you can simply invoke php vendor/bin/doctrine.

Multiple connections

It gets a little trickier when you have multiple entity managers. Doctrine itself has no way to handle that itself, so a possible way would be to have two separate directories with two unique cli-config.php files. You then invoke the doctrine CLI from each respective directory. Since the CLI is looking for the config file in the current working directory, it will then always use the one from the directory you are currently in.

The following code can be used for multiple connections, but it got the drawback, that you won't see the --em=... option within the help section of each command.


$container = require 'config/container.php';

$input = new \Symfony\Component\Console\Input\ArgvInput();

/** @var string $em */
$em = $input->getParameterOption('--em', 'orm_default');

// hack to remove the --em option, cause it's not supported by the original ConsoleRunner.
foreach ($_SERVER['argv'] as $i => $arg) {
    if (0 === strpos($arg, '--em=')) {
        unset($_SERVER['argv'][$i]);
    }
}

try {
    $entityManager = $this->container->get('doctrine.entity_manager.'.$em);
} catch (\Psr\Container\NotFoundExceptionInterface $serviceNotFoundException) {
    throw new \InvalidArgumentException(sprintf('Missing entity manager with name "%s"', $entityManagerName));
}

return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
Comments
Releases(3.8.0)
Owner
Roave, LLC
Roave, LLC
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Minibase 16 Jun 7, 2022
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.

Net A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package. Features: No hard dependencies; Favours

Minibase 16 Jun 7, 2022
A wrapper around symplify/config-transformer used to update recipes and using easy coding standard for generating readable config files.

Symfony Recipes Yaml to PHP Converter This is a wrapper around the symplify/config-transformer used to convert Symfony core recipes which uses .yaml c

Alexander Schranz 3 Nov 24, 2022
Coding-standard - Magento PHP CodeSniffer Coding Standard

ECG Magento Code Sniffer Coding Standard ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool. It allows aut

Magento ECG 309 Jan 3, 2023
Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

Nuber is an open source container management platform it provides a front end to manage your own cloud infrastructure, using Linux Containers virtualization technology

null 33 Dec 14, 2022
Main ABRouter product repository that contains docker-compose file and orchestrates the project containers.

ABRouter-Compose ?? ABRouter is the open-source tool to perform and track A/B tests which is also known as the experiments. Additionally, feature flag

ABRouter 29 Dec 22, 2022
Testing utilities for the psr/log package that backs the PSR-3 specification.

FIG - Log Test Testing utilities for the psr/log package that backs the PSR-3 specification. Psr\Log\Test\LoggerInterfaceTest provides a base test cla

PHP-FIG 3 Nov 19, 2022
A complete stack for running Symfony 5 into Docker containers using docker-compose tool and with Certbot for the HTTPS certificate.

?? Docker + PHP 7.4 + MySQL8.0 + Nginx + Certbot(HTTPS) + Symfony 5 Boilerplate ?? Edited from https://github.com/ger86/symfony-docker version -> http

null 6 Nov 9, 2022
Enforce that your classes get only instantiated by the factories you define!

Enforce that your classes get only instantiated by the factories you define!

null 3 Nov 15, 2021
A Simple MVC PHP Framework, integrated with lot of features such as Session, Cookies, Migrations, Database, Factories, Seeding, Bootstrap and Tailwind CSS

Navite A Simple MVC PHP Framework, integrated with lot of features such as Session, Cookies, Migrations, Database, Factories, Seeding, Bootstrap and T

Celionatti 2 Aug 22, 2022
uses laravel breeze , CRUD, soft delete, Factories

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Roman Hossain Shaon 2 Sep 27, 2022
Naive Bayes works by looking at a training set and making a guess based on that set.

Naive Bayes Naive Bayes works by looking at a training set and making a guess based on that set. It uses simple statistics and a bit of math to calcul

Assisted Mindfulness 29 Nov 27, 2022
Easy Coding Standard configurations for Craft CMS projects.

Easy Coding Standard config for Craft CMs This package provides Easy Coding Standard configurations for Craft CMS plugins and projects. In general, we

Craft CMS 10 Dec 18, 2022
The task of this package is to manage module dotnev-files used by the Laravel integration of phpdotenv.

Warning This Package is still work in progress! Warning The package is basically functional, but there is no logic to handle the files in a repo. Modu

RedFreak_ 2 Nov 17, 2022
Easily install PHP extension in Docker containers

Easy installation of PHP extensions in official PHP Docker images This repository contains a script that can be used to easily install a PHP extension

Michele Locati 2.8k Jan 4, 2023
Docker-magento2 - 🐳 Docker containers with all required Magento 2 dependencies installed available as FPM through Nginx and CLI

Magento 2 Docker A collection of Docker images for running Magento 2 through nginx and on the command line. Quick Start cp composer.env.sample compose

Meanbee 454 Dec 27, 2022
A Magento Development Environment Made of Docker Containers

Docker for Magento 1 Extension Development Tl;dr How do I use this? Clone it. Type docker-compose up -d. Install a Magento Mount your file share. Deve

Michael A. Smith 99 May 10, 2021
OSX/Linux Docker containers installer for Magento 2

Magento 2 OSX/Linux Docker Requirements MacOS: Docker, docker-sync, Git Linux: Docker, Docker-compose, Git on Debian based OS (Example: Ubuntu, Linux

Osiozekhai Aliu 54 Dec 10, 2022