first commit
This commit is contained in:
37
wp-content/plugins/sitepress-multilingual-cms/vendor/otgs/auryn/examples/delegate_params.php
vendored
Normal file
37
wp-content/plugins/sitepress-multilingual-cms/vendor/otgs/auryn/examples/delegate_params.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . "/../vendor/autoload.php";
|
||||
|
||||
class A {
|
||||
private $a;
|
||||
private $b;
|
||||
|
||||
public function __construct(stdClass $a, stdClass $b) {
|
||||
$this->a = $a;
|
||||
$this->b = $b;
|
||||
}
|
||||
|
||||
public function print() {
|
||||
print $this->a->foo;
|
||||
print $this->b->foo;
|
||||
print PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$injector = new WPML\Auryn\Injector;
|
||||
|
||||
$injector->define(A::class, [
|
||||
"+a" => function () {
|
||||
$std = new stdClass;
|
||||
$std->foo = "foo";
|
||||
return $std;
|
||||
},
|
||||
"+b" => function () {
|
||||
$std = new stdClass;
|
||||
$std->foo = "bar";
|
||||
return $std;
|
||||
},
|
||||
]);
|
||||
|
||||
$a = $injector->make(A::class);
|
||||
$a->print();
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Auryn\Injector;
|
||||
|
||||
require __DIR__ . "/../vendor/autoload.php";
|
||||
|
||||
$injector = new Injector;
|
||||
|
||||
class A {
|
||||
public $std;
|
||||
|
||||
public function __construct(stdClass $std) {
|
||||
$this->std = $std;
|
||||
}
|
||||
}
|
||||
|
||||
$stdClass = new stdClass;
|
||||
$stdClass->foo = "foobar";
|
||||
|
||||
$a = $injector->make(A::class, [
|
||||
":std" => $stdClass,
|
||||
]);
|
||||
|
||||
print $a->std->foo . PHP_EOL;
|
||||
Reference in New Issue
Block a user