2017 © Pedro Peláez
 

library pidic

Nette Dependency Injection/Container for Phalcon

image

phalette/pidic

Nette Dependency Injection/Container for Phalcon

  • Friday, March 9, 2018
  • by f3l1x
  • Repository
  • 1 Watchers
  • 3 Stars
  • 15,492 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

PiDiC

Phalconist Build Status Code coverage Downloads this Month Latest stable HHVM Status, (*1)

PiDiC is an adapter over Nette\Di\Container., (*2)

Install

$ composer require phalette/pidic:dev-master

Dependencies

Configuration

use Nette\DI\Compiler;
use Phalette\Pidic\Configurator;
use Phalette\Pidic\Environment;
use Phalette\Pidic\Extensions\PhalconDefaultsExtension;
use Phalette\Pidic\Extensions\PhalconExtension;
use Phalette\Pidic\PiDi;

$configurator = new Configurator();
$configurator->setMode(Environment::DEVELOPMENT);
$configurator->setCacheDir(__DIR__ . '/cache');
$configurator->onCompile[] = function (Compiler $compiler) {
    $compiler->addExtension('phalcon', new PhalconExtension());
    $compiler->addExtension('phalconDefaults', new PhalconDefaultsExtension());
};

$container = $configurator->createContainer();
$pidi = $container->getService('pidi');

Learn by working example

This is based on official tutorial., (*3)

use Nette\DI\Compiler;
use Phalette\Pidic\Configurator;
use Phalette\Pidic\Environment;
use Phalette\Pidic\Extensions\PhalconDefaultsExtension;
use Phalette\Pidic\Extensions\PhalconExtension;
use Phalette\Pidic\PiDi;

use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;

try {

    // Register an autoloader
    $loader = new Loader();
    $loader->registerDirs(array(
        '../app/controllers/',
        '../app/models/'
    ))->register();

    // Create a DI
    $configurator = new Configurator();
    $configurator->setMode(Environment::DEVELOPMENT);
    $configurator->setCacheDir(__DIR__ . '/cache');
    $configurator->onCompile[] = function (Compiler $compiler) {
        $compiler->addExtension('phalcon', new PhalconExtension());
        $compiler->addExtension('phalconDefaults', new PhalconDefaultsExtension());
    };
    $container = $configurator->createContainer();
    $di = $container->getService('pidi');

    // Setup the view component
    $di->set('view', function () {
        $view = new View();
        $view->setViewsDir('../app/views/');
        return $view;
    });

    // Setup a base URI so that all generated URIs include the "tutorial" folder
    $di->set('url', function () {
        $url = new UrlProvider();
        $url->setBaseUri('/tutorial/');
        return $url;
    });

    // Handle the request
    $application = new Application($di);

    echo $application->handle()->getContent();

} catch (\Exception $e) {
     echo "PhalconException: ", $e->getMessage();
}

PhalconExtension

It sets self-instance over static Phalcon\Di::setDefault(). Every object extending from Phalcon\Di\InjectionAwareInterface can access PiDiC from $this->getDI()., (*4)

PhalconDefaultsExtension

This extension replace Phalcon\DI\FactoryDefault. It register to the container 22 base services (more in docs)., (*5)

Phalcon\Di

PiDiC implements Phalcon\DiInterface and then you can change DI without any changes., (*6)

How to work with DI in Phalcon, you can read here., (*7)

Nette\DI

Please read articles at Nette documentation:, (*8)

But the main article is:, (*9)

The Versions

09/03 2018

dev-master

9999999-dev https://github.com/phalette/pidic

Nette Dependency Injection/Container for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container nette dependency injection phalcon

27/09 2015

0.1

0.1.0.0 https://github.com/phalette/pidic

Nette Dependency Injection/Container for Phalcon

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

container nette dependency injection phalcon