jeyroik / i-have-attributes
Simple attributes implementation
Installs: 518
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/jeyroik/i-have-attributes
Requires (Dev)
- phpstan/phpstan: 0.*
- phpunit/phpunit: ^12
README
Simple attributes implementation.
Usage
See tests for details.
$ composer test
$something = new class ([ 'p1' => 'v1', 'p2' => 'v2' ]) implements IHaveAttributes { use THasAttributes; }; $this->assertEquals('v1', $something->getAttribute('p1')); $this->assertEquals('v1', $something->getAttributeString('p1')); $this->assertEquals('v1', $something['p1']); $this->assertEquals('{"p1":"v1","p2":"v2"}', json_encode($something)); foreach($something as $name => $value) { if ($name == 'p2') { $this->assertEquals('v2', $value); } } $this->assertTrue(isset($something['p1'])); unset($something['p1']); $this->assertFalse(isset($something['p1']));; $something->__merge(['p2' => 'v2.1', 'p3' => 'v3']); $this->assertEquals( ['p2' => 'v2.1', 'p3' => 'v3'], $something->__toArray() );