{"id":16429844,"url":"https://github.com/mpalourdio/mpacustomdoctrinehydrator","last_synced_at":"2026-01-10T21:24:07.392Z","repository":{"id":10965762,"uuid":"13280306","full_name":"mpalourdio/MpaCustomDoctrineHydrator","owner":"mpalourdio","description":"Module that helps you deal with dates for DoctrineModule \u0026 ZF2 : filtering, hydration, Locale etc.","archived":false,"fork":false,"pushed_at":"2018-12-29T09:08:56.000Z","size":144,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T01:12:23.860Z","etag":null,"topics":["date","doctrine2","doctrineormmodule","hydration","zf2","zf2-module"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpalourdio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-02T19:13:11.000Z","updated_at":"2020-09-09T15:35:43.000Z","dependencies_parsed_at":"2022-08-28T17:02:36.249Z","dependency_job_id":null,"html_url":"https://github.com/mpalourdio/MpaCustomDoctrineHydrator","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpalourdio%2FMpaCustomDoctrineHydrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpalourdio%2FMpaCustomDoctrineHydrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpalourdio%2FMpaCustomDoctrineHydrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpalourdio%2FMpaCustomDoctrineHydrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpalourdio","download_url":"https://codeload.github.com/mpalourdio/MpaCustomDoctrineHydrator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238412980,"owners_count":19467933,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","doctrine2","doctrineormmodule","hydration","zf2","zf2-module"],"created_at":"2024-10-11T08:24:38.102Z","updated_at":"2025-10-26T23:31:31.030Z","avatar_url":"https://github.com/mpalourdio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mpalourdio/MpaCustomDoctrineHydrator.png?branch=master)](https://travis-ci.org/mpalourdio/MpaCustomDoctrineHydrator)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mpalourdio/MpaCustomDoctrineHydrator/badges/quality-score.png?s=2c109f8b765d059d4b33cb1f6195eae07b2fdb1c)](https://scrutinizer-ci.com/g/mpalourdio/MpaCustomDoctrineHydrator/)\n[![Code Coverage](https://scrutinizer-ci.com/g/mpalourdio/MpaCustomDoctrineHydrator/badges/coverage.png?s=b249873714b3c85f08dfcd9306bd4c6b9cb19ba0)](https://scrutinizer-ci.com/g/mpalourdio/MpaCustomDoctrineHydrator/)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/58b40eee-e087-4489-b169-71434b8c2879/mini.png)](https://insight.sensiolabs.com/projects/58b40eee-e087-4489-b169-71434b8c2879)\n[![PHP 7.0+][ico-engine]][lang]\n[![MIT Licensed][ico-license]][license]\n\n[ico-engine]: http://img.shields.io/badge/php-7.0+-8892BF.svg\n[lang]: http://php.net\n[ico-license]: http://img.shields.io/packagist/l/adlawson/veval.svg\n[license]: LICENSE\n\nMpaCustomDoctrineHydrator\n=========================\n\nModule that helps you deal with date/datetime/time for DoctrineORMModule \u0026 ZF2 : filtering, hydration, Locale etc.\nExtends and replace the ZF2 Date Element, ZF2 DateTime Element, ZF2 Time Element to make them compliant 'out-of-the-box' with doctrine hydration.\n\nProvides an extension of the DoctrineORMModule ```AnnotationBuilder``` and a factory for more ease. The ```ElementAnnotationsListener``` is overridden too in order to better suit needs regarding filtering and validation.\n\nThe filters and the elements can be used as standalone. Using the provided elements via the ```FormElementManager``` adds automatic conversion formats for date/date and time/time strings to ```DateTime```.\nAutomatic filtering and validation are provided regarding the date format (Y-m-d, Y-m-d H:i:s, H:i:s, etc.) that depends of the ```Locale```. A placeholder is added to your form element too when rendered.\n\nThe hydrator service adds a strategy to every date column in your entity for extraction and hydration.\n\nRequirements\n============\nPHP 7.0+ - Only Composer installation supported\n\n\nInstallation\n============\nRun the command below to install via Composer\n\n```shell\ncomposer require mpalourdio/mpa-custom-doctrine-hydrator\n```\n\nAdd \"MpaCustomDoctrineHydrator\" to your **modules list** in **application.config.php**\n\n\nConfiguration\n=============\nCopy **mpacustomdoctrinehydrator.config.global.php.dist** in your **autoload folder** and rename it by removing the .dist\nextension.\n\nAdd your own date / time formats (if needed) that are compliant with php ```DateTime```\n\nsee http://www.php.net/manual/fr/datetime.createfromformat.php\n\nUsage (the easy and lazy way)\n=============================\n\nCreate your forms with the provided annotation builder.\n\n```php\n$builder       = new \\MpaCustomDoctrineHydrator\\Form\\Annotation\\AnnotationBuilder($this-\u003eentityManager, $this-\u003eformElementManager);\n$form = $builder-\u003ecreateForm('Application\\Entity\\Myentity');\n```\n\nOr with the factory\n\n```php\n$form = $this-\u003esm-\u003eget('annotationbuilder')-\u003ecreateForm('Application\\Entity\\Myentity');\n```\n\nThen, hydrate your form\n\n```php\n$hydrator = $this-\u003esm-\u003eget('hydrator')-\u003esetEntity('Application\\Entity\\Myentity');\n$form-\u003esetHydrator($hydrator);\n```\n\nYou're done! Date/Date \u0026 Time/ Time colums will be hydrated/extracted, filtered and validated automatically, without providing anything else in your entities.\nYour form elements will be rendered with a placeholder.\n\n\nUsage (the hard and decoupled way)\n==================================\n\n```php\n$hydrator = $this-\u003esm-\u003eget('hydrator')-\u003esetEntity('Application\\Entity\\Myentity');\n$form-\u003esetHydrator($hydrator);\n```\nIn your forms classes, when not using the ```FormElementManager``` :\n```php\n\n$this-\u003eadd(\n            [\n                'name'       =\u003e 'mydate',\n                'type'       =\u003e 'MpaCustomDoctrineHydrator\\Form\\Element\\Date',\n                'attributes' =\u003e [\n                    'id'    =\u003e 'mydate',\n                ],\n                'options'    =\u003e [\n                    'label'  =\u003e 'My date',\n                    'format' =\u003e 'd/m/Y' // format needed\n                ],\n            ]\n        );\n```\n\nIf you pull your forms from the ```FEM```, just grab the element as a ```'Date'``` or ```'Zend\\Form\\Element\\Date'```. The format option is not needed here, config will be pulled from service config.\n\n```php\n$this-\u003eadd(\n            [\n                'name'       =\u003e 'mydate',\n                'type'       =\u003e 'Date',\n                'attributes' =\u003e [\n                    'id'    =\u003e 'mydate',\n                ],\n                'options'    =\u003e [\n                    'label'  =\u003e 'My date',\n                ],\n            ]\n        );\n```\n\nYou can too use the filter as standalone on other form elements with custom formats, if needed. For this, use the filter FQCN.\n\nIf you use the filter shortname (```DateToDateTime ```), the config will be pulled from the service config (ie. The options array will be ignored).\n\n```php\npublic function getInputFilterSpecification()\n{\n        $filters = [\n            'otherdate' =\u003e [\n                'filters' =\u003e [\n                    [\n                        'name' =\u003e 'MpaCustomDoctrineHydrator\\Filter\\DateToDateTime',\n                        'options' =\u003e [\n                            'format' =\u003e 'd/m/Y' ('date_format' key is also accepted)\n                        ]\n                    ],\n                ],\n            ],\n        ];\n        return $filters;\n}\n```\n\nor simply\n\n```php\npublic function getInputFilterSpecification()\n{\n        $filters = [\n            'otherdate' =\u003e [\n                'filters' =\u003e [\n                    [\n                        'name' =\u003e 'DateToDateTime',\n                    ], // no options needed here, would be ignored anyway\n                ],\n            ],\n        ];\n        return $filters;\n}\n```\n\n/!\\ If you don't create your fieldsets/forms via the ```FormElementManager```, you must manually inject the SL so the ```Date``` element can fetch the configuration\n```php\n$this-\u003egetFormFactory()-\u003egetFormElementManager()-\u003esetServiceLocator($this-\u003esm);\n```\n\n/!\\ Tip : To use the ```'DateToDateTime'``` filter short name in a form grabbed without the ```FEM```, you must do the following :\n```php\n$plugins = $this-\u003esm -\u003eget('FilterManager');\n$chain   = new FilterChain;\n$chain-\u003esetPluginManager($plugins);\n$myForm-\u003egetFormFactory()-\u003egetInputFilterFactory()-\u003esetDefaultFilterChain($chain);\n```\n\nYou can use the provided strategy as standalone with your hydrators too. **Date Time and Time handling work the same way as the example above**, with only few changes, like the 'format' keys names.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpalourdio%2Fmpacustomdoctrinehydrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpalourdio%2Fmpacustomdoctrinehydrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpalourdio%2Fmpacustomdoctrinehydrator/lists"}