phpro / zf-annotated-forms
Installs: 1 086
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 1
Open Issues: 0
Requires
Requires (Dev)
- fabpot/php-cs-fixer: *
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2023-06-12 06:10:27 UTC
README
Repository abandoned 2020-11-27
This repository has been archived since we are not using it anymore internally. Feel free to use it AS-IS, we won't be providing any support anymore.
Installation
Add to composer.json
"phpro/zf-annotated-forms": "dev-master"
Add to application config
return array( 'modules' => array( 'Phpro\\AnnotatedForms', // other libs... ), // Other config );
Configuration files
Copy module.zf-annotated-forms-global.dist.php
to your application configuration autoload directory.
You can adjust this file and set the default values. The annotated_forms
can also be declared in your module config.
Form configuration
return array( 'annotated_forms' => array( 'form-key' => array( 'initializers' => array(), 'listeners' => array(), 'cache' => null, 'cache_key' => 'cached-form-key', 'entity' => '', ), ), );
initializers
:
Array of service manager keys, which return InitializerInterfaces. These initializers are used to inject dependencies in form elements.
listeners
:
Array of service manager keys, which return EventListenerAggregateInterface. These listeners can be used to adjust the form.
cache
:
Service manager key, which return Cache\StorageInterface. This cache storage is used to save parsed annotations.
This can be left null
if you do not want to be using cache.
cache_key
:
The cache key where the parsed configuration is being saved in the cache locator.
This can be left null
if you do not want to be using cache.
entity
:
The name of the class which contains the form annotations.
Load the form
You can now use the serviceManager to retrieve your form. In the config example above, you can use:
$serviceManager->get('form-key');
Configure cache
While configuring a cache storage, there are some things to keep in mind:
- Disable the exceptions by default
- Add a serializer
- The ttl of the forms can be infinite if you clear the cache after building your application
Sample configuration:
'caches' => [ 'Cache\AnnotatedForms' => [ 'adapter' => [ 'name' => 'redis', 'options' => [ 'namespace' => 'zf-annotated-forms', 'server' => [ 'host' => '127.0.0.1', 'port' => '6379', ], 'ttl' => 86400 // 1 day ], ], 'plugins' => [ 'exception_handler' => [ 'throw_exceptions' => false, ], 'serializer', ], ], ],