PHP code example of jclaveau / php-deferred-callchain
1. Go to this page and download the library: Download jclaveau/php-deferred-callchain 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/ */
jclaveau / php-deferred-callchain example snippets
// having
class MyClass
{
protected $name = 'unnamed';
public function setName($name)
{
$this->name = $name;
return $this;
}
public function nameEntries()
{
return [
'my_entry_1' => $this->name . " 1",
'my_entry_2' => $this->name . " 2",
];
}
}
// We can define some chained calls (none is executed)
$doDummyCallsLater = DeferredCallChain::new_( MyClass::class ) // Targets must be MyClass instances
->nameEntries()['my_entry_2'] // access array entry
->strtoupper() // apply strtoupper() to it
;
// do whatever we want
// ...
// Get your targets
$myInstance1 = (new MyClass)->setName('foo');
$myInstance2 = (new MyClass)->setName('bar');
// Execute the callchain
echo $doDummyCallsLater( $myInstance1 ); // => FOO 2
echo $doDummyCallsLater( $myInstance2 ); // => BAR 2
$nameRobert = (new DeferredCallChain(Human::class))->...