doctrine / DoctrineMigrationsBundle

Symfony integration for the doctrine/migrations library
MIT License
4.2k stars 214 forks source link

Issue with custom Migration Factory and Symfony's `lint:container` #352

Closed Kocal closed 3 years ago

Kocal commented 4 years ago

Hi,

I've followed this comment (https://github.com/doctrine/DoctrineMigrationsBundle/issues/336#issuecomment-648786565) to re-implement Container aware migrations.

It's working fine, but I have an issue when running bin/console lint:container:

image

Here are the files I've added:

services.yaml:

services:
    # ...

    Doctrine\Migrations\Version\DbalMigrationFactory: ~
    App\Doctrine\Migrations\Version\MigrationFactory:
        decorates: Doctrine\Migrations\Version\DbalMigrationFactory
        arguments: ['@.inner', '@service_container']

config/packages/doctrine_migrations.yaml:

doctrine_migrations:
    migrations_paths:
        'DoctrineMigrations': '%kernel.project_dir%/src/Migrations'
    storage:
        table_storage:
            table_name: 'migration_versions'
    services:
        'Doctrine\Migrations\Version\MigrationFactory': 'App\Doctrine\Migrations\Version\MigrationFactory'

src/Doctrine/Migrations/Version/MigrationFactory.php:

<?php

declare(strict_types=1);

namespace App\Doctrine\Migrations\Version;

use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class MigrationFactory implements \Doctrine\Migrations\Version\MigrationFactory
{
    private \Doctrine\Migrations\Version\MigrationFactory $migrationFactory;
    private ContainerInterface $container;

    public function __construct(\Doctrine\Migrations\Version\MigrationFactory $migrationFactory, ContainerInterface $container)
    {
        $this->migrationFactory = $migrationFactory;
        $this->container        = $container;
    }

    public function createVersion(string $migrationClassName): AbstractMigration
    {
        $instance = $this->migrationFactory->createVersion($migrationClassName);

        if ($instance instanceof ContainerAwareInterface) {
            $instance->setContainer($this->container);
        }

        return $instance;
    }
}

Here is my composer show, if it can helps:

api-platform/api-pack                  v1.2.2      A pack for API Platform
api-platform/core                      v2.5.6      Build a fully-featured hypermedia or GraphQL API in minutes
brick/math                             0.8.15      Arbitrary-precision arithmetic library
clue/stream-filter                     v1.4.1      A simple and modern approach to stream filtering in PHP
composer/semver                        1.5.1       Semver library that offers utilities, version constraint parsing and validation.
composer/xdebug-handler                1.4.2       Restarts a process without Xdebug.
defuse/php-encryption                  v2.2.1      Secure PHP Encryption Library
doctrine/annotations                   1.10.3      Docblock Annotations Parser
doctrine/cache                         1.10.1      PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                   1.6.5       PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                        2.13.3      PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, persistence interfaces, proxies, eve...
doctrine/data-fixtures                 1.4.3       Data Fixtures for all Doctrine Object Managers
doctrine/dbal                          2.10.2      Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/doctrine-bundle               2.1.0       Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle    3.0.1       Symfony DoctrineMigrationsBundle
doctrine/event-manager                 1.1.0       The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                     1.4.3       PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator                  1.3.1       A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                         1.2.1       PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                    3.0.1       PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a...
doctrine/orm                           v2.7.3      Object-Relational-Mapper for PHP
doctrine/persistence                   1.3.7       The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/reflection                    1.2.1       The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional functionality on top of the reflection functionality that comes with PHP....
doctrine/sql-formatter                 1.1.0       a PHP SQL highlighting library
egulias/email-validator                2.1.18      A library for validating emails against several RFCs
ekino/newrelic-bundle                  2.2.0       Integrate New Relic into Symfony2
escapestudios/symfony2-coding-standard 3.11.0      CodeSniffer ruleset for the Symfony 2+ coding standard
fig/link-util                          1.1.1       Common utility implementations for HTTP links
friendsofphp/php-cs-fixer              v2.16.4     A tool to automatically fix PHP code style
friendsofsymfony/jsrouting-bundle      2.6.0       A pretty nice way to expose your Symfony2 routing to client applications.
fzaninotto/faker                       v1.9.1      Faker is a PHP library that generates fake data for you.
guzzlehttp/guzzle                      6.5.5       Guzzle is a PHP HTTP client library
guzzlehttp/promises                    v1.3.1      Guzzle promises library
guzzlehttp/psr7                        1.6.1       PSR-7 message implementation that also provides common utility methods
hautelook/alice-bundle                 2.7.2       Symfony bundle to manage fixtures with Alice and Faker.
http-interop/http-factory-guzzle       1.0.0       An HTTP Factory using Guzzle PSR7
jean85/pretty-package-versions         1.2         A wrapper for ocramius/package-versions to get pretty versions strings
knplabs/doctrine-behaviors             v2.0.6      Doctrine Behavior Traits
knplabs/knp-time-bundle                v1.11.0     Knplabs time bundle makes your dates look sensible and descriptive
kocal/symfony-mailer-testing           v1.0.0-BETA Test your emails with Behat and Cypress, when using the Symfony Mailer component.
laminas/laminas-code                   3.4.1       Extensions to the PHP Reflection API, static code scanning, and code generation
laminas/laminas-eventmanager           3.2.1       Trigger and listen to events within a PHP application
laminas/laminas-zendframework-bridge   1.0.4       Alias legacy ZF class names to Laminas Project equivalents.
lcobucci/jwt                           3.3.2       A simple library to work with JSON Web Token and JSON Web Signature
league/uri                             5.3.0       URI manipulation library
league/uri-components                  1.8.2       URI components manipulation library
league/uri-hostname-parser             1.1.1       ICANN base hostname parsing implemented in PHP.
league/uri-interfaces                  1.1.1       Common interface for URI representation
league/uri-manipulations               1.5.0       URI manipulation library
league/uri-parser                      1.4.1       userland URI parser RFC 3986 compliant
league/uri-schemes                     1.2.1       URI manipulation library
lexik/jwt-authentication-bundle        v2.8.0      This bundle provides JWT authentication for your Symfony REST API
lorenzo/pinky                          1.0.5       A Foundation for Emails (Inky) template transpiler
mheap/phpunit-github-actions-printer   v1.2.0      PHPUnit Printer for adding test failures as annotations on GitHub Actions
monolog/monolog                        2.1.0       Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                      1.10.1      Create deep copies (clones) of your objects
namshi/jose                            7.2.3       JSON Object Signing and Encryption library for PHP.
nelmio/alice                           3.7.1       Expressive fixtures generator
nelmio/cors-bundle                     2.0.1       Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application
nette/finder                           v2.5.2      🔍 Nette Finder: find files and directories with an intuitive API.
nette/utils                            v3.1.2      🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
nikic/php-parser                       v4.5.0      A PHP parser written in PHP
nyholm/nsa                             1.2.0       See everything and do whatever you want. No privacy rule will stop us. Used in tests, debugging and fixtures to access properties and methods.
nyholm/psr7                            1.3.0       A fast PHP7 implementation of PSR-7
ocramius/package-versions              1.9.0       Composer plugin that provides efficient querying for installed package versions (no runtime IO)
ocramius/proxy-manager                 2.8.0       A library providing utilities to generate, instantiate and generally operate with Object Proxies
payum/core                             1.6.0       One million downloads of Payum already! Payum offers everything you need to work with payments. Friendly for all PHP frameworks (Symfony, Laravel, Zend, Yii, Silex). Check more visiting site.
payum/iso4217                          1.0.1       ISO 4217 PHP Library
payum/offline                          1.6.0       The Payum extension. It provides Offline payment integration.
payum/payum-bundle                     2.4.1       One million downloads of Payum already! Payum offers everything you need to work with payments. Check more visiting site.
php-cs-fixer/diff                      v1.3.0      sebastian/diff v2 backport support for PHP5.6
php-http/client-common                 2.1.0       Common HTTP Client implementations and tools for HTTPlug
php-http/curl-client                   2.1.0       PSR-18 and HTTPlug Async client with cURL
php-http/discovery                     1.8.0       Finds installed HTTPlug implementations and PSR-7 message factories
php-http/guzzle6-adapter               v2.0.1      Guzzle 6 HTTP Adapter
php-http/httplug                       2.1.0       HTTPlug, the HTTP client abstraction for PHP
php-http/httplug-bundle                1.18.0      Symfony integration for HTTPlug
php-http/httplug-pack                  1.2.0       A pack to install HTTP clients in a Symfony Flex application
php-http/logger-plugin                 1.1.0       PSR-3 Logger plugin for HTTPlug
php-http/message                       1.8.0       HTTP Message related tools
php-http/message-factory               v1.0.2      Factory interfaces for PSR-7 HTTP Message
php-http/mock-client                   1.3.1       Mock HTTP client
php-http/promise                       v1.0.0      Promise used for asynchronous HTTP requests
php-http/stopwatch-plugin              1.3.0       Symfony Stopwatch plugin for HTTPlug
php-translation/common                 3.0.1       Common translation stuff
php-translation/extractor              2.0.2       Extract translations form the source code
php-translation/symfony-bundle         0.12.1     
php-translation/symfony-storage        2.2.0       A translation file storage using Symfony translation component.
phpdocumentor/reflection-common        2.2.0       Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock      5.1.0       With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver            1.3.0       A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/php-diff                       v1.1.0      A comprehensive library for generating differences between two hashable objects (strings or arrays).
phpspec/phpspec                        6.2.0       Specification-oriented BDD framework for PHP 7.1+
phpspec/prophecy                       v1.10.3     Highly opinionated mocking framework for PHP 5.3+
phpstan/phpstan                        0.12.31     PHPStan - PHP Static Analysis Tool
phpstan/phpstan-doctrine               0.12.17     Doctrine extensions for PHPStan
phpstan/phpstan-strict-rules           0.12.2      Extra strict and opinionated rules for PHPStan
phpstan/phpstan-symfony                0.12.6      Symfony Framework extensions and rules for PHPStan
predis/predis                          v1.1.1      Flexible and feature-complete Redis client for PHP and HHVM
psr/cache                              1.0.1       Common interface for caching libraries
psr/container                          1.0.0       Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                   1.0.0       Standard interfaces for event handling.
psr/http-client                        1.0.1       Common interface for HTTP clients
psr/http-factory                       1.0.1       Common interfaces for PSR-7 HTTP message factories
psr/http-message                       1.0.1       Common interface for HTTP messages
psr/link                               1.0.0       Common interfaces for HTTP links
psr/log                                1.1.3       Common interface for logging libraries
psr/simple-cache                       1.0.1       Common interfaces for simple caching
ralouphie/getallheaders                3.0.3       A polyfill for getallheaders.
ramsey/collection                      1.0.1       A PHP 7.2+ library for representing and manipulating collections.
ramsey/uuid                            4.0.1       A PHP library for generating and working with universally unique identifiers (UUIDs).
sebastian/comparator                   4.0.3       Provides the functionality to compare PHP values for equality
sebastian/diff                         4.0.2       Diff implementation
sebastian/exporter                     4.0.2       Provides the functionality to export PHP variables for visualization
sebastian/recursion-context            4.0.2       Provides functionality to recursively process PHP variables
sensio/framework-extra-bundle          v5.5.6      This bundle provides a way to configure your controllers with annotations
sensiolabs/security-checker            v6.0.3      A security checker for your composer.lock
sentry/sdk                             2.1.0       This is a metapackage shipping sentry/sentry with a recommended http client.
sentry/sentry                          2.4.0       A PHP SDK for Sentry (http://sentry.io)
sentry/sentry-symfony                  3.5.1       Symfony integration for Sentry (http://getsentry.com)
snc/redis-bundle                       3.2.3       A Redis bundle for Symfony
squizlabs/php_codesniffer              3.5.5       PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
symfony/apache-pack                    v1.0.1      A pack for Apache support in Symfony
symfony/asset                          v5.1.2      Symfony Asset Component
symfony/browser-kit                    v5.1.2      Symfony BrowserKit Component
symfony/cache                          v5.1.2      Symfony Cache component with PSR-6, PSR-16, and tags
symfony/cache-contracts                v2.1.2      Generic abstractions related to caching
symfony/config                         v5.1.2      Symfony Config Component
symfony/console                        v5.1.2      Symfony Console Component
symfony/css-selector                   v5.1.2      Symfony CssSelector Component
symfony/debug-bundle                   v5.1.2      Symfony DebugBundle
symfony/debug-pack                     v1.0.8      A debug pack for Symfony projects
symfony/dependency-injection           v5.1.2      Symfony DependencyInjection Component
symfony/deprecation-contracts          v2.1.2      A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge                v5.1.2      Symfony Doctrine Bridge
symfony/dom-crawler                    v5.1.2      Symfony DomCrawler Component
symfony/dotenv                         v5.1.2      Registers environment variables from a .env file
symfony/error-handler                  v5.1.2      Symfony ErrorHandler Component
symfony/event-dispatcher               v5.1.2      Symfony EventDispatcher Component
symfony/event-dispatcher-contracts     v2.1.2      Generic abstractions related to dispatching event
symfony/expression-language            v5.1.2      Symfony ExpressionLanguage Component
symfony/filesystem                     v5.1.2      Symfony Filesystem Component
symfony/finder                         v5.1.2      Symfony Finder Component
symfony/flex                           v1.8.4      Composer plugin for Symfony
symfony/form                           v5.1.2      Symfony Form Component
symfony/framework-bundle               v5.1.2      Symfony FrameworkBundle
symfony/http-client                    v5.1.2      Symfony HttpClient component
symfony/http-client-contracts          v2.1.2      Generic abstractions related to HTTP clients
symfony/http-foundation                v5.1.2      Symfony HttpFoundation Component
symfony/http-kernel                    v5.1.2      Symfony HttpKernel Component
symfony/inflector                      v5.1.2      Symfony Inflector Component
symfony/intl                           v5.1.2      A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/mailer                         v5.1.2      Symfony Mailer Component
symfony/mailgun-mailer                 v5.1.2      Symfony Mailgun Mailer Bridge
symfony/maker-bundle                   v1.19.0     Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/mime                           v5.1.2      A library to manipulate MIME messages
symfony/monolog-bridge                 v5.1.2      Symfony Monolog Bridge
symfony/monolog-bundle                 v3.5.0      Symfony MonologBundle
symfony/options-resolver               v5.1.2      Symfony OptionsResolver Component
symfony/orm-pack                       v1.0.8      A pack for the Doctrine ORM
symfony/phpunit-bridge                 v5.1.2      Symfony PHPUnit Bridge
symfony/polyfill-intl-grapheme         v1.17.1     Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu              v1.17.1     Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn              v1.17.1     Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer       v1.17.1     Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring              v1.17.1     Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                 v1.17.0     Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73                 v1.17.1     Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80                 v1.17.1     Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-uuid                  v1.17.1     Symfony polyfill for uuid functions
symfony/process                        v5.1.2      Symfony Process Component
symfony/profiler-pack                  v1.0.4      A pack for the Symfony web profiler
symfony/property-access                v5.1.2      Symfony PropertyAccess Component
symfony/property-info                  v5.1.2      Symfony Property Info Component
symfony/proxy-manager-bridge           v5.1.2      Symfony ProxyManager Bridge
symfony/psr-http-message-bridge        v2.0.1      PSR HTTP message bridge
symfony/routing                        v5.1.2      Symfony Routing Component
symfony/security-bundle                v5.1.2      Symfony SecurityBundle
symfony/security-core                  v5.1.2      Symfony Security Component - Core Library
symfony/security-csrf                  v5.1.2      Symfony Security Component - CSRF Library
symfony/security-guard                 v5.1.2      Symfony Security Component - Guard
symfony/security-http                  v5.1.2      Symfony Security Component - HTTP Integration
symfony/serializer                     v5.1.2      Symfony Serializer Component
symfony/serializer-pack                v1.0.3      A pack for the Symfony serializer
symfony/service-contracts              v2.1.2      Generic abstractions related to writing services
symfony/stopwatch                      v5.1.2      Symfony Stopwatch Component
symfony/string                         v5.1.2      Symfony String component
symfony/templating                     v5.1.2      Symfony Templating Component
symfony/test-pack                      v1.0.6      A pack for functional and end-to-end testing within a Symfony app
symfony/translation                    v5.1.2      Symfony Translation Component
symfony/translation-contracts          v2.1.2      Generic abstractions related to translation
symfony/twig-bridge                    v5.1.2      Symfony Twig Bridge
symfony/twig-bundle                    v5.1.2      Symfony TwigBundle
symfony/validator                      v5.1.2      Symfony Validator Component
symfony/var-dumper                     v5.1.2      Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter                   v5.1.2      A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-link                       v5.1.2      Symfony WebLink Component
symfony/web-profiler-bundle            v5.1.2      Symfony WebProfilerBundle
symfony/webpack-encore-bundle          v1.7.3      Integration with your Symfony app & Webpack Encore!
symfony/yaml                           v5.1.2      Symfony Yaml Component
symplify/package-builder               v8.1.2      Dependency Injection, Console and Kernel toolkit for Symplify packages.
theofidry/alice-data-fixtures          1.2.0       Nelmio alice extension to persist the loaded fixtures.
tijsverkoyen/css-to-inline-styles      2.2.2       CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.
twig/cssinliner-extra                  v3.0.3      A Twig extension to allow inlining CSS
twig/extra-bundle                      v3.0.3      A Symfony bundle for extra Twig extensions
twig/inky-extra                        v3.0.3      A Twig extension for the inky email templating engine
twig/intl-extra                        v3.0.3      A Twig extension for Intl
twig/twig                              v2.12.5     Twig, the flexible, fast, and secure template language for PHP
webimpress/safe-writer                 2.0.1       Tool to write files safely, to avoid race conditions
webmozart/assert                       1.9.0       Assertions to validate method input/output with nice error messages.
willdurand/js-translation-bundle       3.0.1       A pretty nice way to expose your translation messages to your JavaScript.
willdurand/jsonp-callback-validator    v1.1.0      JSONP callback validator.
willdurand/negotiation                 v2.3.1      Content Negotiation tools for PHP provided as a standalone library.
yproximite/payum-system-pay            v1.1.0      SP Plus gateway for Payum

Do you know what can happens?

Thanks!

jacquesbh commented 4 years ago

This issue is blocking a bunch of softwares during the container lint operation.

goetas commented 4 years ago

This will be solved by https://github.com/doctrine/DoctrineMigrationsBundle/pull/368

Kocal commented 4 years ago

Great, thanks.

massimilianobraglia commented 3 years ago

Hello everybody, any news on this?

goetas commented 3 years ago

https://github.com/doctrine/DoctrineMigrationsBundle/pull/368 has been merged and it will be released (hopefully next week as 3.1.0)

Kocal commented 3 years ago

Nice, thanks!

gusdecool commented 3 years ago

I just upgraded to v3.1.0. The same issue still exist. Downgrading to v3.0.3 work at the moment..

jdelaune commented 3 years ago

I have also updated to 3.1.1 and still getting the error:

[ERROR] Invalid definition for service "doctrine.migrations.dependency_factory": argument 2 of                         
"Doctrine\Migrations\DependencyFactory::setDefinition()" accepts "callable",                                   
"App\Migrations\Factory\MigrationFactoryDecorator" passed. 

Is there anything else we are meant to be doing?

derrabus commented 3 years ago

Please see #413 and symfony/symfony#40773