isholao / callableresolver
PHP callable resolver
1.0
2017-11-21 05:05 UTC
Requires
- php: >=7.1.0
Requires (Dev)
- phpunit/phpunit: v6.4
This package is not auto-updated.
Last update: 2025-05-11 05:59:04 UTC
README
Install
To install with composer:
composer require isholao/callableresolver
Requires PHP 7.1 or newer.
Usage
Here's a basic usage example:
<?php require '/path/to/vendor/autoload.php'; class Dummy { function methodToCall(){ return 'methodToCall'; } } $resolver = new \Isholao\CallableResolver\Resolver(); $resolved = $resolver->resolve(Dummy::class.'->methodToCall'); \\or $resolved = $resolver->resolve(function(){ return 'methodToCall'; }); $resolved(); // 'methodToCall'
The library provides a helper useful for using a valid PHP string to call the class for example 'Class->method'
<?php require '/path/to/vendor/autoload.php'; class Dummy { function methodToCall($name){ return $name; } } $dc = new \Isholao\CallableResolver\DeferredCallable(Dummy::class.'->methodToCall'); $dc('methodToCall'); // 'methodToCall' //or $dc = new \Isholao\CallableResolver\DeferredCallable(Dummy::class.'->methodToCall', new \CallableResolver\Resolver()); $dc('methodToCall'); // 'methodToCall'