Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time

渚濊禆娉ㄥ叆

PhpBoot 浣跨敤寮婧愰」鐩 PHP-DI 浣滀负渚濊禆娉ㄥ叆鐨勫熀纭瀹炵幇銆

1. 鎵嬪姩娉ㄥ叆

鎵嬪姩娉ㄥ叆鏄彧閫氳繃閰嶇疆鏂囦欢鏄惧紡鐨勬寚瀹氭敞鍏ユ柟寮忋傝瑙PHP-DI鏂囨。

2. 鑷姩娉ㄥ叆

2.1. 鏋勯犲嚱鏁版敞鍏

class Books
{
    /**
     * @param LoggerInterface $logger 閫氳繃渚濊禆娉ㄥ叆浼犲叆
     */
    public function __construct(LoggerInterface $logger)
    {
        $this->logger;
    }
    ...
}

2.2. 灞炴ф敞鍏

class Books
{
    use EnableDIAnnotations; //鍚敤閫氳繃@inject鏍囪娉ㄥ叆渚濊禆
    /**
     * @inject 
     * @var DB
     */
    private $db;
}

娉ㄦ剰锛歅hpBoot 绂佺敤浜哖HP-DI鐨 Annotation 娉ㄥ叆鏂瑰紡锛孈inject 鏂瑰紡鏄 PhpBoot 瀹炵幇鐨