2017 © Pedro Peláez
 

library zf-annotated-forms

image

phpro/zf-annotated-forms

  • Thursday, April 2, 2015
  • by phpro
  • Repository
  • 4 Watchers
  • 0 Stars
  • 856 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 6 % Grown

The README.md

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., (*1)

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., (*2)

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., (*3)

listeners: Array of service manager keys, which return EventListenerAggregateInterface. These listeners can be used to adjust the form., (*4)

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., (*5)

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., (*6)

entity: The name of the class which contains the form annotations., (*7)

Load the form

You can now use the serviceManager to retrieve your form. In the config example above, you can use:, (*8)

$serviceManager->get('form-key');

Configure cache

While configuring a cache storage, there are some things to keep in mind:, (*9)

  • 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:, (*10)

'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',
        ],
    ],
],

The Versions