Source of file HelperAbstract.php

Size: 1,988 Bytes - Last Modified: 2015-12-22T09:12:14-05:00

../src/View/HelperAbstract.php

1234567891011121314151617181920212223242526272829303132333435363738394041
Covered by 7 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
  • MvcLite\ViewHelperAbstractTest::testGetHtmlAttribs with data set #0
42
Covered by 6 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
43
Covered by 6 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
44
Covered by 6 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
45
Covered by 6 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
46
Covered by 7 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
  • MvcLite\ViewHelperAbstractTest::testGetHtmlAttribs with data set #0
4748
Covered by 7 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
  • MvcLite\ViewHelperAbstractTest::testGetHtmlAttribs with data set #0
49
Covered by 1 test(s):
  • MvcLite\ViewHelperAbstractTest::testGetHtmlAttribs with data set #0
50515253
Covered by 6 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSelectTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
  • MvcLite\ViewHelperInputTextTest::testRender with data set #0
  • MvcLite\ViewHelperInputTextareaTest::testRender with data set #0
5455565758596061626364656667
Covered by 1 test(s):
  • MvcLite\ViewHelperInputCheckboxTest::testRender with data set #0
686970717273747576777879
Covered by 2 test(s):
  • MvcLite\ViewHelperInputPasswordTest::testRender with data set #0
  • MvcLite\ViewHelperInputSubmitTest::testRender with data set "empty atttribs array test"
808182
<?php
/**
 * Base View Helper
 *
 * @category    MvcLite
 * @package     Lib
 * @subpackage  View_Helper
 * @since       File available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */

namespace MvcLite\View;

use MvcLite;
use MvcLite\Traits\View as ViewTrait;
use MvcLite\ObjectAbstract as ObjectAbstract;

/**
 * Base View Helper class
 *
 * @category    MvcLite
 * @package     Lib
 * @subpackage  View_Helper
 * @since       Class available since release 1.1.x
 * @author      Cory Collier <corycollier@corycollier.com>
 */
abstract class HelperAbstract extends ObjectAbstract
{
    use ViewTrait;

    /**
     * Method to return a string of key=value pairs.
     *
     * @param array $attribs An array of attributes.
     *
     * @return string The resulting string of attributes.
     */
    protected function getHtmlAttribs($attribs = [])
    {
        // iterate over the attribs provided
        foreach ($attribs as $key => $value) {
            unset($attribs[$key]);
            if ($this->isValidAttribute($key)) {
                $attribs[] = "{$key}=\"{$value}\"";
            }
        }

        if (!count($attribs)) {
            return '';
        }

        // return the pairs, imploded by a single space
        return ' ' . implode(' ', $attribs);
    }

    /**
     * Gets any additional classes that might be required from the attributes.
     *
     * This method is better left to chidl classes to implement.
     *
     * @param array $attribs The array of attributes.
     *
     * @return string The resulting string of css classes
     */
    protected function getAdditionalClasses($attribs = [])
    {
        return '';
    }

    /**
     * Checks an attribute name to see if it's valid.
     *
     * @param string $name The name of the attribute.
     *
     * @return boolean True if the attribute is ok, false if not.
     */
    protected function isValidAttribute($name)
    {
        return true;
    }
}