PHP code example of konsulting / exposer
1. Go to this page and download the library: Download konsulting/exposer 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/ */
konsulting / exposer example snippets
class ClassUnderTest
{
protected $secret = 'My secret';
protected static $anotherSecret = 'My static secret';
protected function add($number1, $number2)
{
return $number1 + $number2;
}
protected static function multiply($number1, $number2)
{
return $number1 * $number2;
}
}
use Konsulting\Exposer\BaseExposer;
// With an instance
BaseExposer::hasMethod(new ClassUnderTest, 'add'); // true
BaseExposer::invokeMethod(new ClassUnderTest, 'add', [1, 1]); // 2
BaseExposer::getProperty(new ClassUnderTest, 'secret'); // 'My secret'
// Static context
BaseExposer::hasMethod(ClassUnderTest::class, 'multiply'); // true
BaseExposer::invokeMethod(ClassUnderTest::class, 'multiply', [2,2]); // 4
BaseExposer::getProperty(ClassUnderTest::class, 'anotherSecret'); // 'My static secret'
use Konsulting\Exposer\Exposer;
$exposer = Exposer::make(new ClassUnderTest);
$exposer->add(1, 1); // 2
$exposer->multiply(2, 2); // 4
$exposer->secret; // 'My secret'
$exposer->anotherSecret; // 'My static secret'
// These non-magic methods are also available
$exposer->invokeMethod('add', [1, 1]); // 2
$exposer->getProperty('secret'); // 'My secret'
use Konsulting\Exposer\Exposer;
$exposer = Exposer::make(ClassUnderTest::class);
$exposer->multiply(2, 2); // 4
$exposer->anotherSecret; // 'My static secret'
$exposer->invokeMethod('multiply', [2, 2]); // 4
$exposer->getProperty('anotherSecret'); // 'My static secret'