1. Go to this page and download the library: Download niirrty/niirrty.dynprop library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
niirrty / niirrty.dynprop example snippets
/**
* …
*
* @property-read string $foo Description of the property…
*/
# use Niirrty\DynProp\ExplicitGetter;
/**
* @property-read string $foo …
* @property-read bool $bar …
*/
class MyClass extends ExplicitGetter
{
private $properties = [
'foo' => 'foo',
'bar' => true
];
public function getFoo() : string
{
return $this->properties[ 'foo' ];
}
public function getBar() : bool
{
return $this->properties[ 'bar' ];
}
}
#
use Niirrty\DynProp\ExplicitGetterSetter;
/**
* @property string $foo …
* @property-read bool $bar …
*/
class MyClass extends ExplicitGetterSetter
{
private $properties = [
'foo' => 'foo',
'bar' => true
];
public function getFoo() : string
{
return $this->properties[ 'foo' ];
}
public function getBar() : bool
{
return $this->properties[ 'bar' ];
}
public function setFoo( string $value ) : MyClass
{
if ( \strlen( $value ) < 1 )
{
throw new \LogicException( 'Foo can not use an empty string' );
}
$this->properties[ 'foo' ] = $value;
return $this;
}
}
public function __construct()
{
// ignore the getBar() method
$this->ignoreGetProperties = [ 'bar' ];
// If the class extends from ExplicitGetterSetter you can also
// Define the setters that should be ignored. e.g.: ignore setFoo()
$this->ignoreSetProperties = [ 'foo' ];
}