【发布时间】:2015-02-03 23:27:11
【问题描述】:
据我所知,我应该能够在我的类的构造函数中键入提示我的类实例参数,我只能在服务提供者的帮助下实例化。不幸的是,我收到关于缺少参数的错误。
Tracker.php
function __construct($query, Tracker\Shipment $shipment) {
$this->query = $query;
$this->shipment = $shipment;
}
TrackerServiceProvider.php
class TrackerServiceProvider extends \Illuminate\Support\ServiceProvider {
public function register() {
$this->app->bind('TrackerAPI', function($app, $shipment_number) {
return new Tracker\API($shipment_number); // omitting Shipment argument should resolve on its own?
});
}
}
类 API 正在扩展 Tracker,因此使用了它的构造函数。为什么没有隐含的类类型提示就无法解决?
【问题讨论】:
标签: php laravel inversion-of-control laravel-5