<commit_before><?php
namespace Vivo\UI;

use Vivo\Service\Initializer\RequestAwareInterface;
use Vivo\Service\Initializer\RedirectorAwareInterface;
use Vivo\Util\Redirector;

use Zend\Form\FormInterface;
use Zend\Form\Form as ZfForm;
use Zend\Http\PhpEnvironment\Request;
use Zend\Stdlib\RequestInterface;

/**
 * Form
 * Base abstract Vivo Form
 */
abstract class AbstractForm extends ComponentContainer implements RequestAwareInterface, RedirectorAwareInterface
{
    /**
     * @var ZfForm
     */
    private $form;

    /**
     * @var Request
     */
    protected $request;

    /**
     * Redirector instance
     * @var Redirector
     */
    protected $redirector;

    /**
     * Has the data been loaded from request?
     * @var bool
     */
    protected $dataLoaded           = false;

    /**
     * When set to true, the form will be automatically prepared in view() method
     * Redefine in descendant if necessary
     * @var bool
     */
    protected $autoPrepareForm      = true;

    /**
     * When set to true, CSRF protection will be automatically added to the form
     * Redefine in descendant if necessary
     * @var bool
     */
    protected $autoAddCsrf          = true;

    /**
     * When set to true, data will be automatically loaded to the form from request
     * Redefine in descendant if necessary
     * @var bool
     */
    protected $autoLoadFromRequest  = true;

    /**
     * TTL for CSRF token
     * Redefine in descendant if necessary
     * @var int|null
     */
    protected $csrfTimeout          = 300;

    public function init()
    {
        parent::init();
        //Load form data from request
        if ($this->autoLoadFromRequest) {
            $this->loadFromRequest();
        }
    }

    /**
     * Returns view model or string to display directly
     * @return \Zend\View\Model\ModelInterface|string
     */
    public function view()
    {
        $form   = $this->getForm();
        //Prepare the form
        if ($this->autoPrepareForm) {
            $form->prepare();
        }
        //Set form to view
        $this->view->form   = $form;
        return parent::view();
    }

    /**
     * Get ZF form
     * @return ZfForm
     */
    protected function getForm()
    {
        if($this->form == null) {
            $this->form = $this->doGetForm();
            if ($this->autoAddCsrf) {
                //Add CSRF field
                $this->form->add(array(
                    'type'      => 'Vivo\Form\Element\Csrf',
                    'name'      => 'csrf',
                    'options'   => array(
                        'csrf_options'  => array(<commit_msg>Use ->getView() instead of ->view in view method<commit_after><?php
namespace Vivo\UI;

use Vivo\Service\Initializer\RequestAwareInterface;
use Vivo\Service\Initializer\RedirectorAwareInterface;
use Vivo\Util\Redirector;

use Zend\Form\FormInterface;
use Zend\Form\Form as ZfForm;
use Zend\Http\PhpEnvironment\Request;
use Zend\Stdlib\RequestInterface;

/**
 * Form
 * Base abstract Vivo Form
 */
abstract class AbstractForm extends ComponentContainer implements RequestAwareInterface, RedirectorAwareInterface
{
    /**
     * @var ZfForm
     */
    private $form;

    /**
     * @var Request
     */
    protected $request;

    /**
     * Redirector instance
     * @var Redirector
     */
    protected $redirector;

    /**
     * Has the data been loaded from request?
     * @var bool
     */
    protected $dataLoaded           = false;

    /**
     * When set to true, the form will be automatically prepared in view() method
     * Redefine in descendant if necessary
     * @var bool
     */
    protected $autoPrepareForm      = true;

    /**
     * When set to true, CSRF protection will be automatically added to the form
     * Redefine in descendant if necessary
     * @var bool
     */
    protected $autoAddCsrf          = true;

    /**
     * When set to true, data will be automatically loaded to the form from request
     * Redefine in descendant if necessary
     * @var bool
     */
    protected $autoLoadFromRequest  = true;

    /**
     * TTL for CSRF token
     * Redefine in descendant if necessary
     * @var int|null
     */
    protected $csrfTimeout          = 300;

    public function init()
    {
        parent::init();
        //Load form data from request
        if ($this->autoLoadFromRequest) {
            $this->loadFromRequest();
        }
    }

    /**
     * Returns view model or string to display directly
     * @return \Zend\View\Model\ModelInterface|string
     */
    public function view()
    {
        $form = $this->getForm();
        //Prepare the form
        if ($this->autoPrepareForm) {
            $form->prepare();
        }
        //Set form to view
        $this->getView()->form = $form;
        return parent::view();
    }

    /**
     * Get ZF form
     * @return ZfForm
     */
    protected function getForm()
    {
        if($this->form == null) {
            $this->form = $this->doGetForm();
            if ($this->autoAddCsrf) {
                //Add CSRF field
                $this->form->add(array(
                    'type'      => 'Vivo\Form\Element\Csrf',
                    'name'      => 'csrf',
                    'options'   => array(
                        'csrf_options'  => array(
{'fraction_non_alphanumeric': 0.10798650168728909, 'fraction_numerical': 0.0011248593925759281, 'mean_word_length': 1.834750265674814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1997909', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1495, 'n_words': 424}