1. Go to this page and download the library: Download level-2/dice 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/ */
level-2 / dice example snippets
class A {
public $b;
public function __construct(B $b) {
$this->b = $b;
}
}
class B {
}
$rule = [];
$rule['shared'] = true;
$dice->addRule('MyClass', $rule);
$rule = [];
$rule['instanceOf'] = 'MyClass';
$rule['constructParams'] = ['Foo', 'Bar'];
//Prevent the named instance inheriting rules from the class named in `instanceOf`:
$rule['inherit'] = false;
$dice->addRule('$MyNamedInstance', $rule);
$rule->substitutions['A'] = function() {
return new A;
};
$rule->call[] = ['someMethod', function() {
// '2' will be provided as the first argument when someMethod is called
return 2;
}];
$rule->constructParams[] = function() {
//'abc' will be providedas the first constructor parameter
return 'abc';
};
$rule->substitutions['A'] = ['instance' => function() {
return new A;
}];
$rule->call[] = ['someMethod', ['instance' => function() {
// '2' will be provided as the first argument when someMethod is called
return 2;
}]]);
$rule->constructParams[] = ['instance' => function() { {
//'abc' will be providedas the first constructor parameter
return 'abc';
}]);
new Dice => new \Dice\Dice
new DiceInstance => new \Dice\Instance
new DiceRule => new \Dice\Rule
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.