@nicolx 덕분에 지금 무슨 일이 일어나고 있는지 자세히 설명하고 몇 가지 추가 지침을 제공 할 수 있습니다.
@nicolx에 의해 언급 된 바와 같이 $request->getContentType()
은 HTTP_ 접두사없이 HTTP 헤더를 찾고 있습니다 (sfWebRequest
의 163-173 행 참조). 그러나 sfBrowserBase는 항상 모든 머리글에 HTTP_ 접두사를 추가합니다. 그래서이 모드에서 추가 ContentType
헤더가 당신의 행동에 설정하고 감지되고 다룰 것이다
foreach($this->headers as $header => $value)
{
if(strotolower($header) == 'content-type' || strtolower($header) == 'content_type')
{
$_SERVER[strtoupper(str_replace('-','_',$header))] = $value;
} else {
$_SERVER['HTTP_'.strtoupper(str_replace('-','_',$header))] = $value;
}
}
. HTTP_
접두사를 포함하지 않으면 다른 헤더가 작동하지 않습니다 (예 : $request->isXmlHtttpHeader()
). 테스트 파일에이 메시지를 설정하더라도 실패합니다.
테스트 방법 isFormat()
은 ContentType 헤더를 테스트하지 않지만 Symfony 경로 설정은 sf_format입니다. 경로를 구체적으로 설정하면 sf_format: json
입니다.
some_route:
url: /something/to/do
param: {module: top, action: index, sf_format: json}
다음 테스트
with('request')->begin()->
isFormat('json')->
end()->
true를 반환합니다.
헤더 설정을 테스트하기 위해 isContentType()
이라는 새 테스터 메서드를 sfTesterRequest에 추가했습니다. 이 방법에 대한 코드는 다음과 같습니다
public function isContentType($type)
{
$this->tester->is($this->request->getContentType(),$type, sprintf('request method is "%s"',strtoupper($type)));
return $this->getObjectToReturn();
}
이 테스트는 간단하게 호출 : 실제로 다른 헤더를 나누기
with('request')->begin()->
isContentType('Application/Json')->
end()->
합니다. '$ request-> getContentType()'이 HTTP없이 헤더를 찾고 있기 때문에 '$ request-> isXmlHttpRequest()'와 같이 HTTP_ 접두어가 필요하므로 ContentType에 예외를 두어야합니다. 따라서 foreach 루프는 다음과 같이됩니다 : foreach ($ this-> headers to $ header => value) {if (strtolower ($ header) == 'content-type'|| strtolower ($ header) == 'content_type') { $ _SERVER [strtoupper (str_replace ('-', '_', $ header))] = $ 값; } else {$ _SERVER [ 'HTTP_'.strtoupper (str_replace ('-', '_', $ header))] = $ value; }' –