doctrine / DoctrineORMModule

Doctrine ORM Module for Laminas
https://www.doctrine-project.org/projects/doctrine-orm-module.html
MIT License
439 stars 229 forks source link

@Annotation\InputFilter not working #692

Closed cbichis closed 2 years ago

cbichis commented 2 years ago

InputFilter annotation seems not to be working:

/**
 * @ORM\Entity(repositoryClass="\Catalog\Repo\EventRepo")
 * @ORM\EntityListeners({"\Catalog\Entity\EventListener"})
 * @ORM\Table(name="catalog_event")
 * @Annotation\Name("catalog_event")
 * @Annotation\InputFilter("Laminas\InputFilter\InputFilter")
 */
class Event
{
.....
}

ERR (3): Object of class ArrayObject could not be converted to string {"file":"/home/myproject/vendor/doctrine/doctrine-orm-module/src/DoctrineORMModule/Form/Annotation/AnnotationBuilder.php","line":80

If I am checking what's the content of the $inputFilter it's just the class name... Somehow the input filter is not created and just the class name is passed.

Of course I used a dummy Laminas\InputFilter\InputFilter in the above sample but in my app I have another class, derived from Laminas\InputFilter\InputFilter, with the inputs added within init() method ... The same error...

Here is how the AB is injected:

$entityManager = $container->get('doctrine.entitymanager.orm_default');

$inputFilterFactory = new \Laminas\InputFilter\Factory(
    $container->get('InputFilterManager')
);

$formFactory = new \Laminas\Form\Factory(
    $container->get(FormElementManager::class)
);
$formFactory->setInputFilterFactory($inputFilterFactory);

$annotationBuilder = new AnnotationBuilder($entityManager);
$annotationBuilder->setFormFactory($formFactory);
driehle commented 2 years ago

@cbichis Could you please provide your full file (i.e. including use statements) and the package versions you are using (i.e. the output of composer show)?

My first guess would be that you haven't added a version constraint to laminas-form in your application. The most recent version of DoctrineORMModule supports either laminas-form 2.0 or 3.0, as written in the release notes: https://github.com/doctrine/DoctrineORMModule/releases/tag/4.1.0.

If you are upgrading laminas-form, please read the migration guide for laminas-form: https://docs.laminas.dev/laminas-form/v3/migration/v2-to-v3/.

cbichis commented 2 years ago
acelaya/zf2-acmailer                              v7.5.0             Mail sending module for Zend Framework and Zend Expressive
bacon/bacon-qr-code                               2.0.4              BaconQrCode is a QR code generator for PHP.
beberlei/doctrineextensions                       v1.3.0             A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL, Oracle, PostgreSQL and SQLite.
brick/varexporter                                 0.3.5              A powerful alternative to var_export(), which can export closures and objects without __set_state()
composer/package-versions-deprecated              1.11.99.4          Composer plugin that provides efficient querying for installed package versions (no runtime IO)
container-interop/container-interop               1.2.0              Promoting the interoperability of container objects (DIC, SL, etc.)
dasprid/enum                                      1.0.3              PHP 7.1 enum implementation
doctrine/annotations                              1.13.2             Docblock Annotations Parser
doctrine/cache                                    1.12.1             PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, m...
doctrine/collections                              1.6.8              PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                                   3.2.0              PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as be...
doctrine/dbal                                     2.13.5             Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/deprecations                             v0.5.3             A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively...
doctrine/doctrine-laminas-hydrator                2.1.1              Doctrine hydrators for Laminas applications
doctrine/doctrine-module                          4.1.3              Laminas Module that provides Doctrine basic functionality required for ORM and ODM modules
doctrine/doctrine-orm-module                      3.2.2              Laminas Module that provides Doctrine ORM functionality
doctrine/event-manager                            1.1.1              The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                                2.0.4              PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plura...
doctrine/instantiator                             1.4.0              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.3.2              PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning you...
doctrine/orm                                      2.10.2             Object-Relational-Mapper for PHP
doctrine/persistence                              2.2.3              The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
endroid/qr-code                                   3.9.7              Endroid QR Code
firebase/php-jwt                                  v5.5.1             A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
friendsofphp/proxy-manager-lts                    v1.0.1             Adding support for a wider range of PHP versions to ocramius/proxy-manager
geocoder-php/common-http                          4.4.0              Common files for HTTP based Geocoders
geocoder-php/google-maps-provider                 4.6.0              Geocoder GoogleMaps adapter
google/apiclient                                  v2.11.0            Client library for Google APIs
google/apiclient-services                         v0.222.0           Client library for Google APIs
google/auth                                       v1.18.0            Google Auth Library for PHP
guzzlehttp/guzzle                                 6.5.5              Guzzle is a PHP HTTP client library
guzzlehttp/promises                               1.5.1              Guzzle promises library
guzzlehttp/psr7                                   1.8.3              PSR-7 message implementation that also provides common utility methods
imagine/imagine                                   1.2.4              Image processing for PHP 5.3
intervention/image                                2.7.0              Image handling and manipulation library with support for Laravel integration
jield-webdev/zf3-bootstrap4                       dev-master 055afe5 Laminas Module that provides helper functions for Bootstrap 4
khanamiryan/qrcode-detector-decoder               1.0.5.2            QR code decoder / reader
laminas/laminas-authentication                    2.8.0              provides an API for authentication and includes concrete authentication adapters for common use case scenarios
laminas/laminas-cache                             2.10.3             Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output
laminas/laminas-cache-storage-adapter-apc         1.0.1              Laminas cache adapter
laminas/laminas-cache-storage-adapter-apcu        1.1.0              Laminas cache adapter for apcu
laminas/laminas-cache-storage-adapter-blackhole   1.2.1              Laminas cache adapter for blackhole
laminas/laminas-cache-storage-adapter-dba         1.0.1              Laminas cache adapter for dba
laminas/laminas-cache-storage-adapter-ext-mongodb 1.2.0              Laminas cache adapter for ext-mongodb
laminas/laminas-cache-storage-adapter-filesystem  1.1.1              Laminas cache adapter for filesystem
laminas/laminas-cache-storage-adapter-memcache    1.1.0              Laminas cache adapter for memcache
laminas/laminas-cache-storage-adapter-memcached   1.2.0              Laminas cache adapter for memcached
laminas/laminas-cache-storage-adapter-memory      1.1.0              Laminas cache adapter for memory
laminas/laminas-cache-storage-adapter-mongodb     1.0.1              Laminas cache adapter for mongodb
laminas/laminas-cache-storage-adapter-redis       1.2.0              Laminas cache adapter for redis
laminas/laminas-cache-storage-adapter-session     1.1.0              Laminas cache adapter for session
laminas/laminas-cache-storage-adapter-wincache    1.0.1              Laminas cache adapter for wincache
laminas/laminas-cache-storage-adapter-xcache      1.0.1              Laminas cache adapter for xcache
laminas/laminas-cache-storage-adapter-zend-server 1.0.1              Laminas cache adapter for zend-server
laminas/laminas-code                              3.5.1              Extensions to the PHP Reflection API, static code scanning, and code generation
laminas/laminas-component-installer               1.1.1              Composer plugin for automating component registration in laminas-mvc and Mezzio applications
laminas/laminas-config                            3.6.0              provides a nested object property based user interface for accessing this configuration data within application code
laminas/laminas-console                           2.8.0              Build console applications using getopt syntax or routing, complete with prompts
laminas/laminas-crypt                             3.4.0              Strong cryptography tools and password hashing
laminas/laminas-db                                2.12.0             Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations
laminas/laminas-dependency-plugin                 1.0.4              Replace zendframework and zfcampus packages with their Laminas Project equivalents.
laminas/laminas-development-mode                  3.5.0              Laminas development mode script
laminas/laminas-di                                2.6.1             
laminas/laminas-diactoros                         1.8.7p2            PSR HTTP Message implementations
laminas/laminas-escaper                           2.9.0              Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs
laminas/laminas-eventmanager                      3.3.1              Trigger and listen to events within a PHP application
laminas/laminas-filter                            2.12.0             Programmatically filter and normalize data and files
laminas/laminas-form                              2.17.0             Validate and display simple and complex forms, casting forms to business objects and vice versa
laminas/laminas-http                              2.14.3             Provides an easy interface for performing Hyper-Text Transfer Protocol (HTTP) requests
laminas/laminas-hydrator                          4.3.1              Serialize objects to arrays, and vice versa
laminas/laminas-i18n                              2.11.3             Provide translations for your application, and filter and validate internationalized values
laminas/laminas-inputfilter                       2.12.0             Normalize and validate input sets from the web, APIs, the CLI, and more, including files
laminas/laminas-json                              3.3.0              provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP
laminas/laminas-loader                            2.8.0              Autoloading and plugin loading strategies
laminas/laminas-log                               2.13.1             Robust, composite logger with filtering, formatting, and PSR-3 support
laminas/laminas-mail                              2.14.3             Provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages
laminas/laminas-math                              3.4.0              Create cryptographically secure pseudo-random numbers, and manage big integers
laminas/laminas-mime                              2.9.1              Create and parse MIME messages and parts
laminas/laminas-modulemanager                     2.10.2             Modular application system for laminas-mvc applications
laminas/laminas-mvc                               3.2.0              Laminas's event-driven MVC layer, including MVC Applications, Controllers, and Plugins
laminas/laminas-mvc-console                       1.3.0              Integration between laminas-mvc and laminas-console
laminas/laminas-mvc-form                          1.2.0              Metapackage with all requirements needed to use laminas-form with laminas-mvc.
laminas/laminas-mvc-i18n                          1.1.1              Integration between laminas-mvc and laminas-i18n
laminas/laminas-mvc-plugin-fileprg                1.2.0              Post/Redirect/Get plugin with file upload handling for laminas-mvc controllers
laminas/laminas-mvc-plugin-flashmessenger         1.3.0              Plugin for creating and exposing flash messages via laminas-mvc controllers
laminas/laminas-mvc-plugin-identity               1.3.0              Plugin for retrieving the current authenticated identity within laminas-mvc controllers
laminas/laminas-mvc-plugin-prg                    1.3.0              Post/Redirect/Get plugin for laminas-mvc controllers
laminas/laminas-mvc-plugins                       1.1.0              Collection of all stable laminas-mvc plugins served via separate packages.
laminas/laminas-navigation                        2.11.1             Manage trees of pointers to web pages in order to build navigation systems
laminas/laminas-paginator                         2.10.0             Paginate collections of data from arbitrary sources
laminas/laminas-permissions-acl                   2.8.0              Provides a lightweight and flexible access control list (ACL) implementation for privileges management
laminas/laminas-progressbar                       2.8.0              Create and update progress bars in different environments
laminas/laminas-psr7bridge                        0.2.2              PSR-7 <-> Laminas\Http bridge
laminas/laminas-router                            3.4.5              Flexible routing system for HTTP and console applications
laminas/laminas-serializer                        2.11.0             Serialize and deserialize PHP structures to a variety of representations
laminas/laminas-servicemanager                    3.5.2              Factory-Driven Dependency Injection Container
laminas/laminas-servicemanager-di                 1.2.1              laminas-di integration for laminas-servicemanager
laminas/laminas-session                           2.11.0             Object-oriented interface to PHP sessions and storage
laminas/laminas-stdlib                            3.4.0              SPL extensions, array utilities, error handlers, and more
laminas/laminas-text                              2.8.1              Create FIGlets and text-based tables
laminas/laminas-uri                               2.8.1              A component that aids in manipulating and validating » Uniform Resource Identifiers (URIs)
laminas/laminas-validator                         2.14.6             Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria
laminas/laminas-view                              2.12.1             Flexible view layer supporting and providing multiple view layers, helpers, and more
laminas/laminas-zendframework-bridge              1.4.0              Alias legacy ZF class names to Laminas Project equivalents.
monolog/monolog                                   2.3.5              Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                                 1.10.2             Create deep copies (clones) of your objects
myclabs/php-enum                                  1.8.3              PHP Enum implementation
neilime/zf-twbs-helper-module                     v3.3.0             Laminas (formerly Zend Framework) module for easy integration of Twitter Bootstrap
nikic/php-parser                                  v4.13.1            A PHP parser written in PHP
oro/doctrine-extensions                           2.0.1              Doctrine Extensions for MySQL and PostgreSQL.
paragonie/constant_time_encoding                  v2.4.0             Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
paragonie/random_compat                           v9.99.100          PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                                  1.0.1              Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                                   1.0.1              Library for handling version information and constraints
php-http/discovery                                1.14.1             Finds installed HTTPlug implementations and PSR-7 message factories
php-http/guzzle6-adapter                          v2.0.2             Guzzle 6 HTTP Adapter
php-http/httplug                                  2.2.0              HTTPlug, the HTTP client abstraction for PHP
php-http/message-factory                          v1.0.2             Factory interfaces for PSR-7 HTTP Message
php-http/promise                                  1.1.0              Promise used for asynchronous HTTP requests
phpdocumentor/reflection-common                   2.2.0              Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock                 5.3.0              With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedd...
phpdocumentor/type-resolver                       1.5.1              A PSR-5 based resolver of Class names, Types and Structural Element Names
phpseclib/phpseclib                               3.0.11             PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
phpspec/prophecy                                  v1.10.3            Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage                         5.3.2              Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator                         1.4.5              FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template                         1.2.1              Simple template engine.
phpunit/php-timer                                 1.0.9              Utility class for timing
phpunit/php-token-stream                          2.0.2              Wrapper around PHP's tokenizer extension.
phpunit/phpunit                                   6.5.14             The PHP Unit Testing framework.
phpunit/phpunit-mock-objects                      5.0.10             Mock Object library for PHPUnit
psr/cache                                         1.0.1              Common interface for caching libraries
psr/container                                     1.1.2              Common Container Interface (PHP FIG PSR-11)
psr/http-client                                   1.0.1              Common interface for HTTP clients
psr/http-message                                  1.0.1              Common interface for HTTP messages
psr/log                                           1.1.4              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.
scienta/doctrine-json-functions                   4.4.0              A set of extensions to Doctrine 2 that add support for json query functions.
sebastian/code-unit-reverse-lookup                1.0.2              Looks up which function or method a line of code belongs to
sebastian/comparator                              2.1.3              Provides the functionality to compare PHP values for equality
sebastian/diff                                    2.0.1              Diff implementation
sebastian/environment                             3.1.0              Provides functionality to handle HHVM/PHP environments
sebastian/exporter                                3.1.4              Provides the functionality to export PHP variables for visualization
sebastian/global-state                            2.0.0              Snapshotting of global state
sebastian/object-enumerator                       3.0.4              Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector                        1.1.2              Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context                       3.0.1              Provides functionality to recursively process PHP variables
sebastian/resource-operations                     1.0.0              Provides a list of PHP built-in functions that operate on resources
sebastian/version                                 2.0.1              Library that helps with managing the version number of Git-hosted PHP projects
symfony/console                                   v5.3.10            Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts                     v2.4.0             A generic function and convention to trigger deprecation notices
symfony/filesystem                                v5.3.4             Provides basic utilities for the filesystem
symfony/options-resolver                          v5.3.7             Provides an improved replacement for the array_replace PHP function
symfony/polyfill-ctype                            v1.23.0            Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme                    v1.23.1            Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn                         v1.23.0            Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer                  v1.23.0            Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                         v1.23.1            Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                            v1.23.0            Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73                            v1.23.0            Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80                            v1.23.1            Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/property-access                           v5.3.8             Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                             v5.3.8             Extracts information about PHP class' properties using metadata of popular sources
symfony/service-contracts                         v2.4.0             Generic abstractions related to writing services
symfony/stopwatch                                 v5.3.4             Provides a way to profile code
symfony/string                                    v5.3.10            Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
tecnickcom/tcpdf                                  6.4.2              TCPDF is a PHP class for generating PDF documents and barcodes.
theseer/tokenizer                                 1.2.1              A small library for converting tokenized PHP source code into XML and potentially other formats
true/punycode                                     v2.1.1             A Bootstring encoding of Unicode for Internationalized Domain Names in Applications (IDNA)
webimpress/safe-writer                            2.2.0              Tool to write files safely, to avoid race conditions
webmozart/assert                                  1.10.0             Assertions to validate method input/output with nice error messages.
willdurand/geocoder                               4.4.0              Common files for PHP Geocoder
<?php declare(strict_types=1);

namespace Catalog\Entity;

use Catalog\Entity\Traits\EventProductsForEventTrait;
use Catalog\Entity\Traits\FilenameForEventTrait;
use Catalog\Entity\Traits\OrderingTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Laminas\Form\Annotation;

/**
 * @ORM\Entity(repositoryClass="\Catalog\Repo\EventRepo")
 * @ORM\EntityListeners({"\Catalog\Entity\EventListener"})
 * @ORM\Table(name="catalog_event")
 * @Annotation\Name("catalog_event")
 * @Annotation\InputFilter("Laminas\InputFilter\InputFilter")
 */
class Event
{
.......................
}

And AB setup:

use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
use Interop\Container\ContainerInterface;
use Laminas\Form\FormElementManager;
use Laminas\Mvc\Controller\PluginManager;
use Laminas\Mvc\Plugin\FlashMessenger\FlashMessenger;
use Laminas\ServiceManager\Factory\FactoryInterface;
$entityManager = $container->get('doctrine.entitymanager.orm_default');

$inputFilterFactory = new \Laminas\InputFilter\Factory(
    $container->get('InputFilterManager')
);

$formFactory = new \Laminas\Form\Factory(
    $container->get(FormElementManager::class)
);
$formFactory->setInputFilterFactory($inputFilterFactory);

$annotationBuilder = new AnnotationBuilder($entityManager);
$annotationBuilder->setFormFactory($formFactory);
driehle commented 2 years ago

Ok, you are using DoctrineORMModule 3.2.2. Please note that the 3.x branch is not supported anymore, you should upgrade to the 4.x series of DoctrineORMModule. I am aware of #666, we'll see if we can re-enable that, but likely this will only work for laminas-form 3.x then, not for 2.x anymore.

cbichis commented 2 years ago

It's quite complicated as basically a migration to DoctrineORMModule v4 requires:

Also Laminas Forms v3 are supporting DockBlock annotations, but DoctrineORMModule v4 does not...

driehle commented 2 years ago

DoctrineORMModule v4 has php: ^7.3 || ~8.0.0 || ~8.1.0, so no PHP upgrade should be requried unless you are still running 7.2, which is end of life in a few days. Further, laminas-forms supports both DocBlock annotations and PHP 8 attributes, so no need to migrate from DocBlock annotations to attributes either.

I think the only show-stopper here is the support by DoctrineORMModule for annotation-based form generation from entity classes.

cbichis commented 2 years ago

Yeah, I understand your idea. I just reviewed the migration path for my case (I am running PHP 7.4.x)... Quite complicated...

driehle commented 2 years ago

As DoctrineORMModule 3.x is not supported anymore, there will be no fix for that issue in the 3.x series. However, once #694 is merged an 4.2.0 released, upgrading to 4.2.0 should be quite smooth. Feel free to update this issue if the bug is still present in the upcoming 4.2.0 release.

cbichis commented 2 years ago

I'll recheck/test in couple days.

driehle commented 2 years ago

694 is merged, you can now give it a try with

    "require": {
        "doctrine/doctrine-orm-module": "4.2.x-dev",
        ....
    },
driehle commented 2 years ago

@cbichis Have you found time looking into 4.2.x-dev?

cbichis commented 2 years ago

Should be fine, I think. As far as I tested it works.

driehle commented 2 years ago

Good, I think we'll then proceed with the release of 4.2.0, because 5.0.0 follow in not to far future.