symfony2服务为什么注入param是字符串?

时间:2014-01-21 10:25:16

标签: php symfony service

您好我创建了一项服务,当我尝试使用它时,我收到了一个错误 ContextErrorException: Catchable Fatal Error: Argument 1 passed to Project\MyDriveBundle\Storage\LocalAdapter::__construct() must be an instance of Project\MainBundle\Manager\UserManager, string given, called in E:\wamp\www\project\src\Project\MyDriveBundle\Storage\LocalAdapter.php on line 41 and defined in E:\wamp\www\project\src\Project\MyDriveBundle\Storage\LocalAdapter.php line 38

为什么? 这是我的服务:

/**
 * @Service("local_adapter")
 */
class LocalAdapter
{

    /**
     * @var Filesystem
     */
    private $filesytem;

    /**
     * @var Adapter
     */
    private $adapter;

    /**
     * @var UserManager
     */
    protected $userManager;

    /**
     * @InjectParams({
     *      "userManager" = @Inject("manager.user")
     * })
     */
    public function __construct(UserManager $userManager)
    {
        $this->userManager = $userManager;
        $this->adapter = new LocalAdapter('/' . $this->userManager->getUsername() . '/');
        $this->filesytem = new Filesystem($this->adapter);
    }

    public function getFilesytem()
    {
        return $this->filesytem;
    }

}

1 个答案:

答案 0 :(得分:0)

尝试在页面顶部使用此包含:

use JMS\DiExtraBundle\Annotation\Inject;
use JMS\DiExtraBundle\Annotation\InjectParams;
use JMS\DiExtraBundle\Annotation\Service;

/**
 * @Service("local_adapter")
 */
class LocalAdapter
{
    // other your code