piotrpress / accessor
This library provides an access to protected/private, also static, methods/properties of an object/class.
v1.0.0
2021-01-24 15:47 UTC
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2024-10-25 00:35:58 UTC
README
This library provides an access to protected/private, also static, methods/properties of an object/class.
Installation
composer require piotrpress/accessor
Usage
Example class
class Example { private $privateProperty = 'privateProperty'; protected $protectedProperty = 'protectedProperty'; static private $staticPrivateProperty = 'staticPrivateProperty'; static protected $staticProtectedProperty = 'staticProtectedProperty'; private function privateMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; } protected function protectedMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; } static private function staticPrivateMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; } static protected function staticProtectedMethod( $arg1, $arg2 ) { echo $arg1 . $arg2; } }
Including library
require __DIR__ . '/vendor/autoload.php'; use PiotrPress\Accessor;
Calling methods
$accessor = new Accessor( new Example() ); $accessor->privateMethod( 'arg1', 'arg2' ); $accessor->protectedMethod( 'arg1', 'arg2' );
Calling static methods
$accessor = new Accessor( 'Example' ); $accessor->staticPrivateMethod( 'arg1', 'arg2' ); $accessor->staticProtectedMethod( 'arg1', 'arg2' );
Getting properties
$accessor = new Accessor( new Example() ); echo $accessor->privateProperty; echo $accessor->protectedProperty;
Getting static properties
$accessor = new Accessor( 'Example' ); echo $accessor->staticPrivateProperty; echo $accessor->staticProtectedProperty;
Setting properties
$accessor = new Accessor( new Example() ); $accessor->privateProperty = 'newPrivateProperty'; $accessor->protectedProperty = 'newProtectedProperty';
Setting static properties
$accessor = new Accessor( 'Example' ); $accessor->staticPrivateProperty = 'newStaticPrivateProperty'; $accessor->staticProtectedProperty = 'newStaticProtectedProperty';
License
GPL3.0