Download the PHP package uk/dynamic-properties without Composer
On this page you can find all versions of the php package uk/dynamic-properties. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uk/dynamic-properties
More information about uk/dynamic-properties
Files in uk/dynamic-properties
Package dynamic-properties
Short Description Helping classes to use dynamic properties declared by get*() and set*() methods
License LGPLv3
Informations about the package dynamic-properties
UK.DynamicProperties
This is an PHP7 implementation to easy generate an little bit of "magic" extra functionality to you're PHP classes.
If you extend you're class from one of the classes of \UK\DynamicProperties
so it adds dynamic class instance
properties with read or read+write access. It requires only the presence of some get() and/or set() methods.
Status
Installation
Usage
The usage is really simple.
Why should I use dynamic properties?
You should not use it but you can, if you see the advantages.
Most modern IDE's like PHPStorm or Netbeans supports the dynamic properties with the code completion feature if the Properties have the correct PHP-Doc tag notation.
It means for example, if you provide a dynamic readonly property with the name $foo
of type string
For read + write access you only have to replace @property-read
with @property
.
Dynamic property read access
If you have an class that define methods for getting some instance properties and they are with an name format
like getPropertyName1()
or getPropertyName2()
etc. pp. You only must extend the class from the
\UK\DynamicProperties\ExplicitGetter
class and you can access the Properties directly like
$myClassInstance->propertyName1
or $myClassInstance->propertyName2
for read access.
The class will always work like before but with the extra properties.
Remember to do not forget to write the required class documentation for the dynamic available read only properties, like in the example docblock below.
Dynamic property read+write access
If you also need write access to the properties you must replace the UK\DynamicProperties\ExplicitGetter
with the UK\DynamicProperties\ExplicitGetterSetter
class an implement the required set???() methods
Special cases: Ignore Getters and/or Setters
Often not all get and/or set methods should be usable as dynamic properties.
For this cases you can explicit declare the names of the properties that should not be accessible by the dynamic way.
Fo it you have to define this dynamic property names inside the constructor of the extending class:
End of document :-)