큰 코드 때문에 내 파일을 gist에 넣었습니다.심포니 폼 빌더는 컨테이너를 사용합니까?
설명 : 내 API를 번들의
BankController 은행에서 POST 요청을들을 수 있습니다. 컨트롤러가 필요한 변수를 얻으면 HalykType을 사용하여 HalykEntity 양식을 작성하려고 시도합니다.
모든 것이 확인되고 폼의 유효성이 확인되면 컨트롤러는 작업 유형 (자금 지원/환불)에 따라 적절한 메소드 (makeFunding/makeRefunding)를 호출하는 HalykEntity의 makeOperation 메소드를 호출하려고합니다.
두 가지 (makeFunding/makeRefunding 메소드)는 은행 번들의 뱅킹 서비스 메소드를 호출 할 수 있습니다.
문제 :
{
"error": {
"code": 500,
"message": "Internal Server Error",
"exception": [
{
"message": "Call to a member function get() on null",
"class": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "src\\ApiBundle\\v1\\Entity\\HalykEntity.php",
"line": 308,
"args": []
},
{
"namespace": "ApiBundle\\v1\\Entity",
"short_class": "HalykEntity",
"class": "ApiBundle\\v1\\Entity\\HalykEntity",
"type": "->",
"function": "makeFunding",
"file": "src\\ApiBundle\\v1\\Entity\\HalykEntity.php",
"line": 274,
"args": []
},
{
"namespace": "ApiBundle\\v1\\Entity",
"short_class": "HalykEntity",
"class": "ApiBundle\\v1\\Entity\\HalykEntity",
"type": "->",
"function": "makeOperation",
"file": "src\\ApiBundle\\v1\\Controller\\BankController.php",
"line": 34,
"args": []
},
{
"namespace": "ApiBundle\\v1\\Controller",
"short_class": "BankController",
"class": "ApiBundle\\v1\\Controller\\BankController",
"type": "->",
"function": "indexAction",
"file": null,
"line": null,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
},
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "call_user_func_array",
"file": "vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\HttpKernel.php",
"line": 153,
"args": [
[
"array",
[
[
"object",
"ApiBundle\\v1\\Controller\\BankController"
],
[
"string",
"indexAction"
]
]
],
[
"array",
[
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handleRaw",
"file": "vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\HttpKernel.php",
"line": 68,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handle",
"file": "vendor\\symfony\\symfony\\src\\Symfony\\Component\\HttpKernel\\Kernel.php",
"line": 171,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
],
[
"boolean",
true
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "Kernel",
"class": "Symfony\\Component\\HttpKernel\\Kernel",
"type": "->",
"function": "handle",
"file": "web\\app_dev.php",
"line": 29,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
}
]
}
]
}
}
생각 :
내가 은행에서 전화를 시뮬레이션하기 위해 노력하고 있어요 (POST 요청 ..AMOUNT=5201&CURRENCY=KZT&TIMESTAMP=20170906173539&TRTYPE=1..
를 보내) 나는 오류를 얻을 폼 빌더가 DI 컨테이너를 사용하지 않는다는 것이 문제라고 생각합니다. 내가 잘못? 그렇지 않다면 어떻게 은행 서비스 방법을 호출 할 수 있습니까?
P.
죄송합니다. 2 개의 링크를 더 추가할만한 충분한 평판이 없습니다. 그래서, 클래스에 대한 링크를 제거해야합니다. 그러나 그들 모두는 당신이 나의 요지의 레포에서 찾을 수 있습니다.
흥미 롭습니다. 그런 식으로 포맷 된 오류 메시지를 보지 않았습니다. 어떤 경우에도 HalykEntity 컨테이너를 인식했기 때문에 컨테이너가 자동으로 컨테이너에 삽입된다는 의미는 아닙니다. 일반적으로 엔티티가 컨테이너에 액세스하는 것을 원하지 않습니다. 리팩토링에 대한 다양한 접근법. Banking :: makeRefunding ($ 엔티티)를 고려하면 대부분의 처리를 은행 서비스로 옮길 수 있습니다. – Cerad
그리고 제목 질문에 대답하기 위해 네, 폼 빌더는 컨테이너를 사용하여 다른 폼 유형을로드합니다.하지만 빌더는 엔티티에 대해 아무것도 모르고 새로운 컨테이너를 작성해야하는 경우 간단한 새 작업을 수행합니다. 컨트롤러에 엔티티를 만들고 폼 빌더에 전달하기 전에 setContainer를 호출하여 문제를 해결할 수 있습니다. 권장하지는 않지만 특정 문제를 해결할 수 있습니다. – Cerad
@Cerad 네, 맞습니다. Banking :: makeRefunding ($ entity)를 호출 할 수 있습니다. 그러나 언젠가 은행 업무를 리팩터링해야한다면 어떨까요? 이 서비스에 대한 모든 전화를 검색하고 리팩터링해야합니까? 제 생각에는 디 용기의 목적은 이런 종류의 변화를 남기는 것입니다. –