1: <?php namespace Khill\Fontawesome;
2:
3: /**
4: * FontAwesomeStack builds icon stacks
5: *
6: * @package FontAwesomePHP
7: * @author Kevin Hill <kevinkhill@gmail.com>
8: * @version 1.0b1
9: * @access public
10: * @see http://kevinkhill.github.io/FontAwesomePHP
11: */
12:
13: use Khill\Fontawesome\Exceptions\BadLabelException;
14: use Khill\Fontawesome\Exceptions\CollectionIconException;
15: use Khill\Fontawesome\Exceptions\IncompleteStackException;
16:
17: class FontAwesomeStack {
18:
19: /**
20: * Html string template to build the icon
21: */
22: const ICON_HTML = '<i class="fa fa-%s %s"></i>';
23:
24: /**
25: * Html string template to build the icon stack
26: */
27: const STACK_HTML = '<span class="%s">%s%s</span>';
28:
29: /**
30: * Classes to be applied to the stack
31: *
32: * @var array
33: */
34: private $classes = array();
35:
36: /**
37: * Stores top icon in a stack
38: *
39: * @var string
40: */
41: public $topIcon = '';
42:
43: /**
44: * Stores bottom icon in a stack
45: *
46: * @var string
47: */
48: public $bottomIcon = '';
49:
50: /**
51: * Outputs the FontAwesome object as an HTML string
52: *
53: * @access public
54: * @return string HTML string of icon or stack
55: */
56: public function output()
57: {
58: $classes = 'fa-stack';
59:
60: if(count($this->classes) > 0)
61: {
62: foreach($this->classes as $class)
63: {
64: $classes .= ' ' . $class;
65: }
66: }
67:
68: return sprintf(self::STACK_HTML, $classes, $this->topIcon, $this->bottomIcon);
69: }
70:
71: /**
72: * Sets the top icon to be used in a stack
73: *
74: * @access public
75: * @param string $icon Icon label
76: * @throws Khill\Fontawesome\Exceptions\BadLabelException If $icon is not a string
77: * @return Khill\Fontawesome\FontAwesomeStack FontAwesomeStack object
78: */
79: public function setTopIcon($icon)
80: {
81: $this->topIcon = sprintf(self::ICON_HTML, $icon, 'fa-stack-2x');
82: }
83:
84: /**
85: * Sets the bottom icon to be used in a stack
86: *
87: * @access public
88: * @param string $icon Icon label
89: * @throws Khill\Fontawesome\Exceptions\BadLabelException If $icon is not a string
90: * @throws Khill\Fontawesome\Exceptions\IncompleteStackException If The on() method was called without the stack() method
91: * @return Khill\Fontawesome\FontAwesomeStack FontAwesomeStack object
92: */
93: public function setBottomIcon($icon)
94: {
95: $this->bottomIcon = sprintf(self::ICON_HTML, $icon, 'fa-stack-1x');
96: }
97:
98: /**
99: * Add extra classes to the stack
100: *
101: * @access public
102: * @param string $class CSS class
103: * @throws Khill\Fontawesome\Exceptions\BadLabelException If $class is not a string
104: * @return Khill\Fontawesome\FontAwesomeStack FontAwesomeStack object
105: */
106: public function addClass($class)
107: {
108: $this->classes[] = $class;
109: }
110:
111: }
112: