Skip to content

Commit a433a3e

Browse files
committed
Added Component::removeAttributes().
1 parent 892d388 commit a433a3e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/HTMLServerComponent.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ public function setAttributes(array $attributes)
9898
}
9999
}
100100

101+
/**
102+
* Removes the attributes specified.
103+
*
104+
* @param array $attributes An array containing the names of the attributes to remove.
105+
* @return void
106+
*/
107+
public function removeAttributes(array $attributes)
108+
{
109+
foreach ($attributes as $name) {
110+
$name = strtolower($name);
111+
if (isset($this->attributes[$name])) {
112+
unset($this->attributes[$name]);
113+
}
114+
}
115+
}
116+
101117
/**
102118
* Provides access to the component attributes via properties.
103119
*

tests/Test.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ public function testComponentSetAttributes()
197197
$this->assertTrue($result === $expectedResult);
198198
}
199199

200+
/**
201+
*
202+
*/
203+
public function testComponentRemoveAttributes()
204+
{
205+
206+
$component = new \IvoPetkov\HTMLServerComponent();
207+
$component->setAttributes(['aTTR1' => 'value1', 'attr2' => 'value2', 'attr3' => 'value3']);
208+
$component->removeAttributes(['attr1', 'Attr3']);
209+
$result = (string) $component;
210+
$expectedResult = '<component attr2="value2"></component>';
211+
$this->assertTrue($result === $expectedResult);
212+
}
213+
200214
/**
201215
*
202216
*/

0 commit comments

Comments
 (0)