PHP code example of infocyph / intermix

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

    

infocyph / intermix example snippets


use function Infocyph\InterMix\container;

$c = container();
$c->definitions()->bind('now', fn () => new DateTimeImmutable());

echo $c->get('now')->format('c');

$c->options()->setOptions(
    injection: true,
    methodAttributes: true,
    propertyAttributes: true
);

$c->definitions()->bind('a', A::class, tags: ['service']);
$c->definitions()->bind('b', B::class, tags: ['service']);

foreach ($c->findByTag('service') as $svc) {
    $svc()->handle();
}

MacroTest::mix(new class {
    public function hello($name) {
        return "Hey, $name!";
    }
});

echo (new MacroTest)->hello('Ali'); // Hey, Ali!

use function Infocyph\InterMix\Remix\once;

$value = once(fn() => rand(1000, 9999)); // Only runs once per file+line