PHP code example of psr-discovery / container-implementations

1. Go to this page and download the library: Download psr-discovery/container-implementations 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/ */

    

psr-discovery / container-implementations example snippets


use PsrDiscovery\Discover;

// Return an instance of the first discovered PSR-11 Container implementation.
$container = Discover::container();

$container->get(...)

use PsrDiscovery\Discover;

$container = Discover::container();

if ($container === null) {
    // No suitable Container implementation was discovered.
    // Fall back to a default implementation.
    $container = new DefaultContainer();
}

use PsrDiscovery\Discover;

// $container1 !== $container2 (default)
$container1 = Discover::container();
$container2 = Discover::container();

// $container1 === $container2
$container1 = Discover::container(singleton: true);
$container2 = Discover::container(singleton: true);

use PsrDiscovery\Discover;
use PsrDiscovery\Implementations\Psr11\Containers;

// Prefer the a specific implementation of PSR-11 over others.
Containers::prefer('league/container');

// Return an instance of League\Container\Container,
// or the next available from the list of candidates,
// Returns null if none are discovered.
$container = Discover::container();

use PsrDiscovery\Discover;
use PsrDiscovery\Implementations\Psr11\Containers;

// Only discover a specific implementation of PSR-11.
Containers::use('league/container');

// Return an instance of League\Container\Container,
// or null if it is not available.
$container = Discover::container();