rmrevin /
yii2-fontawesome
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Icon.php |
||
| 4 | * @author Revin Roman |
||
| 5 | * @link https://rmrevin.ru |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace rmrevin\yii\fontawesome\component; |
||
| 9 | |||
| 10 | use rmrevin\yii\fontawesome\FA; |
||
| 11 | use yii\helpers\ArrayHelper; |
||
| 12 | use yii\helpers\Html; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Class Icon |
||
| 16 | * @package rmrevin\yii\fontawesome\component |
||
| 17 | */ |
||
| 18 | class Icon |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @deprecated |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | public static $defaultTag = 'i'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @deprecated |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $tag; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | private $options = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string $name |
||
| 40 | * @param array $options |
||
| 41 | */ |
||
| 42 | 10 | public function __construct($name, $options = []) |
|
| 43 | { |
||
| 44 | 10 | Html::addCssClass($options, FA::$cssPrefix); |
|
| 45 | |||
| 46 | 10 | if (!empty($name)) { |
|
| 47 | 10 | Html::addCssClass($options, FA::$cssPrefix . '-' . $name); |
|
| 48 | 10 | } |
|
| 49 | |||
| 50 | 10 | $this->options = $options; |
|
| 51 | 10 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | 6 | public function __toString() |
|
| 57 | { |
||
| 58 | 6 | $options = $this->options; |
|
| 59 | |||
| 60 | 6 | $tag = ArrayHelper::remove($options, 'tag', 'i'); |
|
| 61 | |||
| 62 | 6 | return Html::tag($tag, null, $options); |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return self |
||
| 67 | */ |
||
| 68 | 1 | public function inverse() |
|
| 69 | { |
||
| 70 | 1 | return $this->addCssClass(FA::$cssPrefix . '-inverse'); |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return self |
||
| 75 | */ |
||
| 76 | 3 | public function spin() |
|
| 77 | { |
||
| 78 | 3 | return $this->addCssClass(FA::$cssPrefix . '-spin'); |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return self |
||
| 83 | */ |
||
| 84 | 1 | public function fixedWidth() |
|
| 85 | { |
||
| 86 | 1 | return $this->addCssClass(FA::$cssPrefix . '-fw'); |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @return self |
||
| 91 | */ |
||
| 92 | 3 | public function li() |
|
| 93 | { |
||
| 94 | 3 | return $this->addCssClass(FA::$cssPrefix . '-li'); |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @return self |
||
| 99 | */ |
||
| 100 | 1 | public function border() |
|
| 101 | { |
||
| 102 | 1 | return $this->addCssClass(FA::$cssPrefix . '-border'); |
|
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return self |
||
| 107 | */ |
||
| 108 | 1 | public function pullLeft() |
|
| 109 | { |
||
| 110 | 1 | return $this->addCssClass(FA::$cssPrefix . '-pull-left'); |
|
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return self |
||
| 115 | */ |
||
| 116 | public function pullRight() |
||
| 117 | { |
||
| 118 | return $this->addCssClass(FA::$cssPrefix . '-pull-right'); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param string $value |
||
| 123 | * @return self |
||
| 124 | * @throws \yii\base\InvalidConfigException |
||
| 125 | */ |
||
| 126 | 3 | public function size($value) |
|
| 127 | { |
||
| 128 | 3 | return $this->addCssClass( |
|
| 129 | 3 | FA::$cssPrefix . '-' . $value, |
|
| 130 | 3 | in_array((string)$value, [FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X], true), |
|
| 131 | 3 | sprintf( |
|
| 132 | 3 | '%s - invalid value. Use one of the constants: %s.', |
|
| 133 | 3 | 'FA::size()', |
|
| 134 | 'FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X' |
||
| 135 | 3 | ) |
|
| 136 | 3 | ); |
|
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param string $value |
||
| 141 | * @return self |
||
| 142 | * @throws \yii\base\InvalidConfigException |
||
| 143 | */ |
||
| 144 | 1 | View Code Duplication | public function rotate($value) |
| 145 | { |
||
| 146 | 1 | return $this->addCssClass( |
|
| 147 | 1 | FA::$cssPrefix . '-rotate-' . $value, |
|
| 148 | 1 | in_array((string)$value, [FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270], true), |
|
| 149 | 1 | sprintf( |
|
| 150 | 1 | '%s - invalid value. Use one of the constants: %s.', |
|
| 151 | 1 | 'FA::rotate()', |
|
| 152 | 'FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270' |
||
| 153 | 1 | ) |
|
| 154 | 1 | ); |
|
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $value |
||
| 159 | * @return self |
||
| 160 | * @throws \yii\base\InvalidConfigException |
||
| 161 | */ |
||
| 162 | 1 | View Code Duplication | public function flip($value) |
| 163 | { |
||
| 164 | 1 | return $this->addCssClass( |
|
| 165 | 1 | FA::$cssPrefix . '-flip-' . $value, |
|
| 166 | 1 | in_array((string)$value, [FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL], true), |
|
| 167 | 1 | sprintf( |
|
| 168 | 1 | '%s - invalid value. Use one of the constants: %s.', |
|
| 169 | 1 | 'FA::flip()', |
|
| 170 | 'FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL' |
||
| 171 | 1 | ) |
|
| 172 | 1 | ); |
|
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @deprecated |
||
| 177 | * Change html tag. |
||
| 178 | * @param string $tag |
||
| 179 | * @return static |
||
| 180 | * @throws \yii\base\InvalidParamException |
||
| 181 | */ |
||
| 182 | 2 | public function tag($tag) |
|
| 183 | { |
||
| 184 | 2 | $this->tag = $tag; |
|
|
0 ignored issues
–
show
|
|||
| 185 | |||
| 186 | 2 | $this->options['tag'] = $tag; |
|
| 187 | |||
| 188 | 2 | return $this; |
|
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $class |
||
| 193 | * @param bool $condition |
||
| 194 | * @param string|bool $throw |
||
| 195 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
| 196 | * @throws \yii\base\InvalidConfigException |
||
| 197 | * @codeCoverageIgnore |
||
| 198 | */ |
||
| 199 | public function addCssClass($class, $condition = true, $throw = false) |
||
| 200 | { |
||
| 201 | if ($condition === false) { |
||
| 202 | if (!empty($throw)) { |
||
| 203 | $message = !is_string($throw) |
||
| 204 | ? 'Condition is false' |
||
| 205 | : $throw; |
||
| 206 | |||
| 207 | throw new \yii\base\InvalidConfigException($message); |
||
| 208 | } |
||
| 209 | } else { |
||
| 210 | Html::addCssClass($this->options, $class); |
||
| 211 | } |
||
| 212 | |||
| 213 | return $this; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @deprecated |
||
| 218 | * @param string|null $tag |
||
| 219 | * @param string|null $content |
||
| 220 | * @param array $options |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | View Code Duplication | public function render($tag = null, $content = null, $options = []) |
|
| 224 | { |
||
| 225 | $tag = empty($tag) |
||
| 226 | ? (empty($this->tag) ? static::$defaultTag : $this->tag) |
||
|
0 ignored issues
–
show
The property
rmrevin\yii\fontawesome\component\Icon::$tag has been deprecated.
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead. Loading history...
The property
rmrevin\yii\fontawesome\...onent\Icon::$defaultTag has been deprecated.
This property has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead. Loading history...
|
|||
| 227 | : $tag; |
||
| 228 | |||
| 229 | $options = array_merge($this->options, $options); |
||
| 230 | |||
| 231 | return Html::tag($tag, $content, $options); |
||
| 232 | } |
||
| 233 | } |
||
| 234 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.