keradus / traits
Traits: general usage traits
v1.0
2014-11-19 21:50 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- fabpot/php-cs-fixer: ~1.0@dev
This package is auto-updated.
Last update: 2024-10-21 20:05:52 UTC
README
Traits - general usage traits.
Traits List
InaccessiblePropertiesProtectorTrait
Trait, that protects accessing inaccessible (unknown) properties to help keeping code clean and safe.
class Foo { public $baz; } $foo = new Foo(); $foo->vaz = 123; // PHP claims that code is OK, even if you misspelled variable name! class Bar { use InaccessiblePropertiesProtectorTrait; public $baz; } $bar = new Bar(); $bar->vaz = 123; // now PHP throws \LogicException
InnerClassCacheTrait
Trait, that adds functionality of inner class cache.
class Foo { use InnerClassCacheTrait; public function square($x) { if (!isset($this->cache[$x])) { $this->cache[$x] = $x * $x; } return $this->cache[$x]; } }
InstanceCreationDisallowerTrait
Trait, that disallow to create instance of class. Use for protecting static classes (only static members).
class Foo { use InstanceCreationDisallowerTrait; public static function createInstance() { return new static(); } } $foo = new Foo(); // PHP throws fatal error $foo = Foo::createInstance(); // PHP throws \LogicException
PropertyTrait
Property trait.
SingletonTrait
StaticPropertyTrait
Property trait in static way.