PHP code example of 00f100 / fcphp-provider

1. Go to this page and download the library: Download 00f100/fcphp-provider 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/ */

    

00f100 / fcphp-provider example snippets




namespace Some\Example
{
    use FcPhp\Di\Interfaces\IDi;
    use FcPhp\Provider\Interfaces\IProviderClient;

    class ProviderClientExample implements IProviderClient
    {
        /**
         * Method to configure Di in providers
         *
         * @param FcPhp\Di\Interfaces\IDi $di Di Instance
         * @return void
         */
        public function getProviders(IDi $di) :IDi
        {
            $di->set('Class', '\Class', [], ['SetConfiguration', => ['item1', 'item2', 'item3']]);
            $di->set('Class2', '\Class', ['instance' => $this->get('Class')]);
            return $di;
        }
    }
}



use FcPhp\Di\Facades\DiFacade;
use FcPhp\Provider\Facades\ProviderFacade;

$PathCache = 'tests/var/cache';
$pathToAutoload = 'tests/*/*/config';

$provider = ProviderFacade::getInstance($pathToAutoload, $PathCache);
$di = DiFacade::getInstance();

// Add new provider to process
$provider->addProviders(['Some\Example\ProviderClientExample']);

// Execute ...
$provider->make();

// Now instance of di have configuration ...
$di->make('Class2'); // Return new \Class(new \Class()) ....