PHP code example of robotusers / cakephp-di

1. Go to this page and download the library: Download robotusers/cakephp-di 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/ */

    

robotusers / cakephp-di example snippets


class Application extends \Robotusers\DI\Http\BaseApplication
{
    protected function createContainer()
    {
        $container = new SomeContainer();

        //configure your services

        return $container;
    }
}

//ArticlesController.php

public function view($id, ArticlesServiceInterface $service)
{
    //code
}

...

use App\Application;
use Cake\Console\CommandRunner;
use Robotusers\Di\Console\CommandFactory;

$application = new Application(dirname(__DIR__) . '/config');
$factory = new CommandFactory($application);
$runner = new CommandRunner($application, 'cake', $factory);
exit($runner->run($argv));

protected function createTableLocator()
{
    $factory = function($options) {
        // retrieve a table from your DIC

        return $table;
    };

    return new \Robotusers\Di\ORM\Locator\TableLocator($factory);
}