00f100/fcphp-provider

There is no license information available for the latest version (0.3.1) of this package.

Provider Manager for FcPHP

0.3.1 2018-08-04 19:25 UTC

This package is auto-updated.

Last update: 2024-11-18 05:46:12 UTC


README

Package do manage providers. This package use FcPhp Di to inject dependency.

Build Status codecov Total Downloads

How to install

Composer:

$ composer require 00f100/fcphp-provider

or composer.json

{
    "require": {
        "00f100/fcphp-provider": "*"
    }
}

How to use

Create class extends IProviderClient to inject dependencies of your application

<?php

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;
        }
    }
}

Create new instance of IProvider to process providers

<?php

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()) ....