PHP code example of iidestiny / dependency-injection
1. Go to this page and download the library: Download iidestiny/dependency-injection 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/ */
iidestiny / dependency-injection example snippets
// register class
di_register(Tools::class)
// Call a method in a class
di_register(Tools::class)->generate($param, $param, $param)
// more
di_register(Tools::class)->foo($bar)
namespace App\Services;
use App\Tools;
use App\User;
use Cache;
use Petstore30\Order;
class OrderService
{
/**
* place order
*
* @param User $user
* @param $goods
* @param $address
* @param Cache $cache
* @param Tools $tools
*/
public function placeOrder(User $user, $goods, $address, Cache $cache, Tools $tools)
{
// code something
}
/**
* pay
*
* @param Order $order
* @param Cache $cache
* @param Tools $tools
*/
public function pay(Order $order, Cache $cache, Tools $tools)
{
// code something
}
}
/**
* store
*/
public function store()
{
di_register(OrderService::class)->placeOrder($user, $goods, $address);
}
/**
* store
*/
public function store()
{
$orderService = di_register(OrderService::class);
$orderService->placeOrder($user, $goods, $address);
$orderService->pay($order);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.