Lines Matching refs:attribute

55      * Add an attribute and its values.
57 * @param string|Attribute $attribute
61 public function add($attribute, ...$values)
63 $attribute = $attribute instanceof Attribute ? $attribute : new Attribute($attribute, ...$values);
65 if (($exists = $this->get($attribute, true)) !== null) {
66 $exists->add(...$attribute->getValues());
68 $this->attributes[] = $attribute;
70 $this->changes->add(Change::add(clone $attribute));
76 * Remove an attribute's value(s).
78 * @param string|Attribute $attribute
82 public function remove($attribute, ...$values)
84 $attribute = $attribute instanceof Attribute ? $attribute : new Attribute($attribute, ...$values);
86 if (count($attribute->getValues()) !== 0) {
87 if (($exists = $this->get($attribute, true)) !== null) {
88 $exists->remove(...$attribute->getValues());
90 $this->changes->add(Change::delete(clone $attribute));
97 * Reset an attribute, which removes any values it may have.
104 foreach ($attributes as $attribute) {
105 $attribute = $attribute instanceof Attribute ? $attribute : new Attribute($attribute);
107 if ($attr->equals($attribute, true)) {
112 $this->changes()->add(Change::reset(clone $attribute));
119 * Set an attribute on the entry, replacing any value(s) that may exist on it.
121 * @param string|Attribute $attribute
125 public function set($attribute, ...$values)
127 $attribute = $attribute instanceof Attribute ? $attribute : new Attribute($attribute, ...$values);
131 if ($attr->equals($attribute, true)) {
133 $this->attributes[$i] = $attribute;
138 $this->attributes[] = $attribute;
140 $this->changes->add(Change::replace(clone $attribute));
146 * Get a specific attribute by name (or Attribute object).
148 * @param string|Attribute $attribute
149 * @param bool $strict If set to true, then options on the attribute must also match.
152 public function get($attribute, bool $strict = false): ?Attribute
154 $attribute = $attribute instanceof Attribute ? $attribute : new Attribute($attribute);
157 if ($attr->equals($attribute, $strict)) {
166 * Check if a specific attribute exists on the entry.
168 * @param string|Attribute $attribute
172 public function has($attribute, bool $strict = false): bool
174 $attribute = $attribute instanceof Attribute ? $attribute : new Attribute($attribute);
176 return (bool) $this->get($attribute, $strict);
214 foreach ($this->attributes as $attribute) {
215 $attributes[$attribute->getDescription()] = $attribute->getValues();
291 foreach ($attributes as $attribute => $value) {
292 $entryAttr[] = new Attribute($attribute, ...(is_array($value) ? $value : [$value]));