我正在使用Laravel 4.2,調用表單提交和控制器響應之間的付款流程。如果支付被接受,一堆工作是由類PaymentProcessor將應用程序對象傳遞給Laravel中的函數/類
use MyProject\libraries\payment\PaymentProcessor;
class MyFirstController extends \Controller {
protected $paymentProcessor;
public function __construct(
PaymentProcessor $paymentProcessor
) {
$this->paymentProcessor = $paymentProcessor;
}
public function postFormSubmit() {
//DO SOME STUFF
$paymentResult = $this->paymentProcessor->makePayment($paymentDetails);
}
}
PaymentProcessor是在不同的命名空間在幕後做的,我能夠調用使用App所需庫::使
<?php namespace MyProject\libraries\payment;
use MyProject\DataObjects\PaymentDetails;
class PaymentProcessor {
public function makePayment(PaymentDetails $paymentData) {
$doFirstStep = \App::make('amazingLibrary')->doImportantThings();
但是,出於測試目的我想刪除所有實例,並直接從PaymentProcessor調用其它類,所以我試着做以下注:
<?php namespace MyProject\libraries\payment;
use MyProject\DataObjects\PaymentDetails;
class PaymentProcessor {
private $app;
public function __construct(\App $app) {
$this->app = $app;
}
並試圖:
public function makePayment(PaymentDetails $paymentData) {
$doFirstStep = $this->app::make('amazingLibrary')->doImportantThings();
但它會導致:
FatalErrorException(E_PARSE)語法錯誤,意想不到的 '::'(T_PAAMAYIM_NEKUDOTAYIM)
我是在正確的道路?
更新:
我也試着稱呼其爲:$this->app->make
這導致:
調用未定義的方法照亮的\ Support \外立面\ APP ::使()
註釋掉私人應用資源。我想看下一個結果 – 2014-09-23 07:00:52
結果是一樣的 – 2014-09-23 07:03:03
'$ this-> app :: make()'是無效的代碼。當使用'::'時,你必須用方法所屬類的名稱來限定它(例如'SomeClass :: make()'。 – 2014-09-23 07:03:20