PHP code example of timetoogo / php-generics

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

    

timetoogo / php-generics example snippets


$Configuration = new \Generics\Configuration();
$Configuration->SetIsDevelopmentMode(true);
$Configuration->SetRootPath(__DIR__);
$Configuration->SetCachePath(__DIR__ . '/Cache');
//Register the generic auto loader
\Generics\Loader::Register($Configuration);

class Maybe {
    private $MaybeValue;
    
    public function __construct(__TYPE__ $Value = null) {
        $this->MaybeValue = $Value;
    }
    
    public function HasValue() {
        return $this->MaybeValue !== null;
    }
    
    public function GetValue() {
        return $this->MaybeValue;
    }
    
    public function SetValue(__TYPE__ $Value = null) {
        $this->MaybeValue = $Value;
    }
}

$Maybe = new Maybe\stdClass();
$Maybe->HasValue(); //false
$Maybe->SetValue(new stdClass());
$Maybe->HasValue(); //true
$Maybe->SetValue(new DateTime()); //ERROR

 
$Tuple = new TupleOf\stdClass\_\DateTime();

$Tuple = new TupleOf\Foo\Bar\SomeClass\_\DateTime();

class TupleOfBarAndBaz extends TupleOf\Bar\_\Baz {
    //...
}

interface IHaveOne {
    public function GetOne();
    public function SetOne(__TYPE__ $One);
}

class User implements IHaveOne\Account {
    private $One;
    
    public function GetOne(){
        return $this->One;
    }
    public function SetOne(Account $One) {
        $this->One = $One;
    }
}

$ArrayOfArrayOfStandardClasses = new ArrayOf\ArrayOf\stdClass();

class Example extends __TYPE1__ implements __TYPE2__, __TYPE3__ {
    use __TYPE4__, __TYPE5__;
}
javascript
{
    "/php-generics": "0.2.4"
    }
}