1. Go to this page and download the library: Download lorenzo/piping-bag 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/ */
// in app/src/Di/Module/MyModule.php
namespace App\Di\Module;
use Ray\Di\AbstractModule;
class MyModule extends AbstractModule
{
public function configure()
{
$this->bind('MovieApp\FinderInterface')->to('MovieApp\Finder');
$this->bind('MovieApp\HttpClientInterface')->to('Guzzle\HttpClient');
$this->install(new OtherModule()); // Modules can install other modules
}
}
use PipingBag\Di\PipingBag;
$httpClient = PipingBag::get('MovieApp\HttpClientInterface');
// in src/Controller/ArticlesController.php
use App\Controller\AppController;
use MovieApp\HttpClientInterface;
use Ray\Di\Di\Inject; // This is important
class ArticlesController extends AppController
{
/**
* @Inject
*/
public function setHttpClient(HttpClientInterface $connection)
{
$this->httpClient = $connection;
}
}
// in src/Controller/ArticlesController.php
use App\Controller\AppController;
use MovieApp\HttpClientInterface;
use PipingBag\Annotation\Assisted; // This is important
class ArticlesController extends AppController
{
/**
* @Assisted
*/
public function edit($id, HttpClientInterface $connection = null)
{
$article = $this->Articles->get($id)
$connection->post(...);
}
}
use Cake\Console\Shell;
use Ray\Di\Di\Inject; // This is important
class MyShell extends Shell
{
/**
* @Inject
*/
public function setHttpClient(HttpClientInterface $connection)
{
$this->httpClient = $connection;
}
}
bash
// bin/cake.php
...
exit(PipingBag\Console\ShellDispatcher::run($argv)); // Changed namespace of ShellDispatcher
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.