PluginProbe
Depicter — Popup & Slider Builder / 1.3.3
Depicter — Popup & Slider Builder v1.3.3
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / htmlburger / wpemerge / src / Helpers / HasAttributesTrait.php

HasAttributesTrait.php in Depicter — Popup & Slider Builder 1.3.3, at vendor/htmlburger/wpemerge/src/Helpers/HasAttributesTrait.php

97 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package WPEmerge
4 * @author Atanas Angelov <hi@atanas.dev>
5 * @copyright 2017-2019 Atanas Angelov
6 * @license https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7 * @link https://wpemerge.com/
8 */
9
10 namespace WPEmerge\Helpers;
11
12 use WPEmerge\Support\Arr;
13
14 /**
15 * Represent an object which has an array of attributes.
16 */
17 trait HasAttributesTrait {
18 /**
19 * Attributes.
20 *
21 * @var array<string, mixed>
22 */
23 protected $attributes = [];
24
25 /**
26 * Get attribute.
27 *
28 * @param string $attribute
29 * @param mixed $default
30 * @return mixed
31 */
32 public function getAttribute( $attribute, $default = '' ) {
33 return Arr::get( $this->getAttributes(), $attribute, $default );
34 }
35
36 /**
37 * Get all attributes.
38 *
39 * @return array<string, mixed>
40 */
41 public function getAttributes() {
42 return $this->attributes;
43 }
44
45 /**
46 * Set attribute.
47 *
48 * @param string $attribute
49 * @param mixed $value
50 * @return void
51 */
52 public function setAttribute( $attribute, $value ) {
53 $this->setAttributes( array_merge(
54 $this->getAttributes(),
55 [$attribute => $value]
56 ) );
57 }
58
59 /**
60 * Fluent alias for setAttribute().
61 *
62 * @codeCoverageIgnore
63 * @param string $attribute
64 * @param mixed $value
65 * @return static $this
66 */
67 public function attribute( $attribute, $value ) {
68 $this->setAttribute( $attribute, $value );
69
70 return $this;
71 }
72
73 /**
74 * Set all attributes.
75 * No attempt to merge attributes is done - this is a direct overwrite operation.
76 *
77 * @param array<string, mixed> $attributes
78 * @return void
79 */
80 public function setAttributes( $attributes ) {
81 $this->attributes = $attributes;
82 }
83
84 /**
85 * Fluent alias for setAttributes().
86 *
87 * @codeCoverageIgnore
88 * @param array<string, mixed> $attributes
89 * @return static $this
90 */
91 public function attributes( $attributes ) {
92 $this->setAttributes( $attributes );
93
94 return $this;
95 }
96 }
97