PHP code example of texthtml / docker-links

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

    

texthtml / docker-links example snippets


$links = \TH\Docker\Links::buildFrom($_ENV);

// $links can be used as an array
echo count($links), PHP_EOL; // 2
foreach ($links as $name => $link) {
    echo $name, PHP_EOL; // /romantic_lumiere/db, /romantic_lumiere/db
}

// each link is an instanceof [Link](test)
$link = $links['/romantic_lumiere/db'];

echo $link->mainPort()->address(), PHP_EOL; // 172.17.0.5
echo $link->mainPort()->protocol(), PHP_EOL; // TCP
echo $link->mainPort()->number(), PHP_EOL; // 6379

echo $link->env()['USERNAME'], PHP_EOL; // username
echo $link->env('PASSWORD'), PHP_EOL; // password
echo $link->env('SOMETHING_ELSE'), PHP_EOL; // NULL
echo $link->env('SOMETHING', 'default value'), PHP_EOL; // default value