class-style-builder.php
1.21 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Store and output the css.
*
* @file
* @package Learndash_Certificate_Builer
*/
namespace LearnDash_Certificate_Builder\Component\Pdf\Builder;
/**
* Class Style_Builder
*
* @package LearnDash_Certificate_Builder\Component\Pdf\Builder
*/
class Style_Builder implements Builder {
/**
* Contains all the css.
*
* @var array
*/
protected $styles = array();
/**
* Output the content
*
* @return string
*/
public function output() {
$string = '';
foreach ( $this->styles as $id => $style ) {
$el = '#' . $id . ' {';
if ( 'body' === $id || strpos( $id, '.' ) === 0 ) {
$el = $id . ' {';
}
foreach ( $style as $key => $val ) {
$el .= $key . ': ' . $val . ';' . PHP_EOL;
}
$el .= '}';
$string .= $el . PHP_EOL;
}
return $string;
}
/**
* Adding a style to an element
*
* @param string $element The element id or class.
* @param string $key The css name.
* @param string $value The css value.
*
* @return Builder
*/
public function add( $element, $key = null, $value = null ) {
if ( ! isset( $this->styles[ $element ] ) ) {
$this->styles[ $element ] = array();
}
$this->styles[ $element ][ $key ] = $value;
return $this;
}
}