1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 
<?php
namespace Omeka\Form\Initializer;

use Interop\Container\ContainerInterface;
use Zend\Form\Form;
use Zend\ServiceManager\Initializer\InitializerInterface;

class Csrf implements InitializerInterface
{
    public function __invoke(ContainerInterface $container, $form)
    {
        if (!$form instanceof Form) {
            return;
        }

        // All forms should have CSRF protection. Must add this before building
        // the form so getInputFilter() knows about it.
        $name = $form->getName();
        $form->add([
            'type' => 'csrf',
            'name' => $name ? $name . '_csrf' : 'csrf',
            'options' => [
                'label' => 'CSRF',
                'csrf_options' => [
                    'timeout' => 3600,
                ],
            ],
        ]);
    }
}