PHP code example of sroze / argument-resolver

1. Go to this page and download the library: Download sroze/argument-resolver 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/ */

    

sroze / argument-resolver example snippets


use ArgumentResolver\ArgumentResolverFactory;

$argumentResolver = ArgumentResolverFactory::create();

$closures = [
    function(MyClass $object) {
        return $object instanceof MyClass;
    },
    function($bar, array $list) {
        return count($list);
    }
];

foreach ($closures as $callable) {
    $arguments = $argumentResolver->resolveArguments($callable, [
        'classObject' => new MyClass(),
        'bar' => 'foo',
        'list' => ['an', 'array']
    ]);
    
    // ...
}

class Foo
{
    public function method($foo, $bar)
    {
    }
}

$argumentResolver->resolveArguments([new Foo(), 'method'], [
    'bar' => 1,
    'foo' => 2,
    'baz' => 3
]);

// Which returns: [2, 1]

$runner = new CallableRunner($argumentResolver);
$runner->run($callable, $availableArguments);

$instantiator = new Instantiator($argumentResolver);
$instantiator->instantiate(YourClassName::class, $availableArguments);