PHP code example of holgerk / jiggle

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

    

holgerk / jiggle example snippets


$jiggle = new Jiggle;
$jiggle->d1 = 42;
echo $jiggle->d1; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = function() {
    return 42;
};
echo $jiggle->d1; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 42;
$jiggle->d2 = function() use($jiggle) {
    return $jiggle->d1;
};
echo $jiggle->d2; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 42;
$jiggle->d2 = function($d1) {
    return $d1;
};
echo $jiggle->d2; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$result = $jiggle->inject(function($d1, $d2) {
    return $d1 + $d2;
});
echo $result; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 20;
$jiggle->d2 = 1000;
$result = $jiggle->inject(function($d1, $d2, $d3) {
    return $d1 + $d2 + $d3;
}, array('d2' => 20, 'd3' => 2));
echo $result; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$jiggle->d3 = function() use($jiggle) {
    return new D3($jiggle->d1, $jiggle->d2);
};
echo $jiggle->d3->sum(); // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$jiggle->d3 = function() use($jiggle) {
    return $jiggle->create('D3');
};
echo $jiggle->d3->sum(); // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$jiggle->d3 = $jiggle->singleton('D3');
echo $jiggle->d3->sum(); // => 42

$jiggle = new Jiggle;
$jiggle->d1 = function() {
    return function() {
        return 42;
    };
};
echo $jiggle->d1(); // => 42

$jiggle = new Jiggle;
$jiggle->a = true;
$jiggle->a = false; // <- throws an exception

$jiggle = new Jiggle;
$jiggle->d1 = 21;
$jiggle->replace('d1', 42);
echo $jiggle->d1; // => 42

$jiggle = new Jiggle;
$jiggle->d1 = 42;
$this->assertTrue(isset($jiggle->d1));
$this->assertFalse(isset($jiggle->d2));

$jiggle = new Jiggle;
$jiggle->resolver(function($dependencyName) {
    if ($dependencyName == 'd2') {
        return 42;
    }
    throw new Exception("Could not resolve dependency: $dependencyName!");
});
$jiggle->d1 = function($d2) { return $d2; };
echo $jiggle->d1; // => 42