Passed
Push — 2.x ( ebb523...c128f2 )
by Hari
08:19 queued 06:54
created

AbstractElement::raw()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Html\Helper;
10
11
/**
12
 *
13
 * Helper to generate a complete element.
14
 *
15
 * @package Aura.Html
16
 *
17
 */
18
abstract class AbstractElement extends AbstractHelper
19
{
20
21
22
    abstract public function __invoke($tag, $content, array $attr = array());
23
24
    /**
25
     *
26
     * Returns any kind of complete HTML element with attributes and escaped content.
27
     *
28
     * @param string $tag The tag to generate.
29
     *
30
     * @param string $content The element content
31
     *
32
     * @param array $attr Attributes for the tag.
33
     *
34
     * @return string
35
     *
36
     */
37
    protected function escaped($tag, $content, array $attr = array())
38
    {
39
        $attr = $this->escaper->attr($attr);
40
        $out = $attr ? "<{$tag} $attr>" : "<{$tag}>";
41
        $out .= $this->escaper->html($content);
42
        $out .= "</$tag>";
43
        return $out;
44
    }
45
46
    /**
47
     *
48
     * Returns any kind of complete HTML element with attributes.
49
     *
50
     * @param string $tag The tag to generate.
51
     *
52
     * @param string $content The content of the element.
53
     *
54
     * @param array $attr Attributes for the tag.
55
     *
56
     * @return string
57
     *
58
     */
59
    public function raw($tag, $content, array $attr = array())
60
    {
61
        $attr = $this->escaper->attr($attr);
62
        $out = $attr ? "<{$tag} $attr>" : "<{$tag}>";
63
        $out .= $content;
64
        $out .= "</$tag>";
65
        return $out;
66
    }
67
}
68