symfony2에서 "security.context"를 인수로 사용하여 새 서비스를 만들었습니다. 그러나 사용자 지정 클래스 나 컨트롤러가 아닌 클래스에서 서비스를 호출하면 항상 누락 된 인수 오류가 반환됩니다. 이 코드가 무엇이 잘못되었는지 알 수 있습니까?맞춤 클래스에서 서비스를 호출하면 symfony에서 Catchable Fatal Error가 반환됩니다.
내 서비스입니다.
appbundle.common.services.loggeduserservice:
class: Makubex\Pim\AppBundle\Common\Services\LoggedUserService
arguments: ["@security.context"]
여기 내 서비스 클래스입니다.
use Symfony\Component\Security\Core\SecurityContext;
class LoggedUserService{
private $context;
public function __construct(AppContext $context)
{
$this->context = $context;
}
public function getCurrentUser()
{
return $this->context;
}
}
내 맞춤 클래스.
class makubex{
public function getUser(){
$user = new LoggedUserService();
echo $user->getId();
}
}
정확한 오류 메시지는 다음과 같습니다. Catchable Fatal Error : Makubex \ Pim \ AppBundle \ Common \ Services \ LoggedUserService :: __ construct()에 전달 된 인수 1이 Cubic \ Wamp \ www \ pim에서 호출 된 Makubex \ InfrastructureBundle \ Application \ AppContext의 인스턴스 여야합니다. 28 번째 줄에 있고 C : \ Wamp \ www \ pim \ src \ Makubex \ Pim \ AppBundle \ Common \ Services \ LoggedUserService.php 줄에 정의 된 \ src \ Makubex \ Pim \ AppBundle \ Backoffice \ CommandCustomAttributeCommandProcessor.php 줄 19 내부 서버 오류) – Makubex