Source of file InputText.php

Size: 1,637 Bytes - Last Modified: 2015-12-22T09:42:40-05:00

../src/View/Helper/InputText.php

123456789101112131415161718192021222324252627282930313233343536
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
37
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
38
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
3940
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
41
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
42
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
43
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
44
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
4546474849505152535455565758
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
5960
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
61
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
6263
Covered by 1 test(s):
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
646566
<?php
/**
 * Text Input View Helper
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  View\Helper
 * @since       File available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite\View\Helper;

use MvcLite\View\Helper\InputElementAbstract as InputElementAbstract;

/**
 * Text Input View Helper class
 *
 * @category    PHP
 * @package     MvcLite
 * @subpackage  View\Helper
 * @since       Class available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
class InputText extends InputElementAbstract
{
    /**
     * Render a input[type=text] element.
     *
     * @param string $name The name of the text element.
     * @param array $attribs An array of attributes.
     * @return string The resulting HTML.
     */
    public function render($name, $attribs = [])
    {
        $defaults = $this->getDefaultAttribs($name, 'text');
        $attribs  = array_merge($defaults, $attribs);
        $template = $template = $this->getStandardTemplate();

        return strtr($template, [
            '!label'    => $attribs['label'],
            '!id'       => $name,
            '!attribs'  => $this->getHtmlAttribs($attribs),
        ]);
    }

    /**
     * Local override of the isValidAttribute method.
     *
     * @param string $name The name of the attribute.
     *
     * @return boolean True if valid, false if not.
     */
    protected function isValidAttribute($name)
    {
        $no = [
            'label'
        ];

        if (in_array($name, $no)) {
            return false;
        }
        return true;
    }
}