Symfony \ Component \ Translation \ TranslatorInterface不可实例化

时间:2014-06-19 05:13:52

标签: laravel laravel-4

我正在研究一个Laravel软件包,试图注入" Illuminate \ Validation \ Factory"到__construct():

namespace Extensions\Tpp\Forms;


   use Illuminate\Validation\Validator as ValidatorInstance;
   use Illuminate\Validation\Factory as Validator;

   abstract class FormValidator {

    /**
     * @var Validator
     */
    protected $validator;

    /**
     * @var ValidatorInstance
     */
    protected $validation;

    function __construct(Validator $validator)
    {
        $this->validator = $validator;
    }

但是得到了以下错误:

    Illuminate \ Container \ BindingResolutionException
Target [Symfony\Component\Translation\TranslatorInterface] is not instantiable.

据我所知,这意味着Laravel不知道Symfony \ Component \ Translation \ TranslatorInterface的实现方式。我的问题是为什么在正常的Laravel应用程序中可以绑定Symfony \ Component \ Translation \ TranslatorInterface,但是在Laravel包中,它不是。

谢谢

1 个答案:

答案 0 :(得分:0)

  

我的问题是为什么在正常的Laravel应用程序中   可以绑定Symfony \ Component \ Translation \ TranslatorInterface

这是因为Laravel专门使用Symfony个组件,Validator类依赖于跟随Symfony组件(检查Illuminate\Validation\Validator)以及其他Illuminate {1}}组件:

Symfony\Component\HttpFoundation\File\File;
Symfony\Component\Translation\TranslatorInterface;
Symfony\Component\HttpFoundation\File\UploadedFile;

您将使用此功能(删除use语句):

function __construct(\Validator $validator)
{
    $this->validator = $validator;
}