本文整理汇总了PHP中PHPParser::parseFile方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPParser::parseFile方法的具体用法?PHP PHPParser::parseFile怎么用?PHP PHPParser::parseFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPParser
的用法示例。
在下文中一共展示了PHPParser::parseFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleInput
//.........这里部分代码省略.........
if (isset($this->httpRequest->headers['Range'])) {
$this->httpRequest->SERVER['HTTP_RANGE'] = $this->httpRequest->headers['Range'];
}
if (isset($this->httpRequest->headers['Cookie'])) {
$this->httpRequest->SERVER['HTTP_COOKIE'] = $this->httpRequest->headers['Cookie'];
}
if (isset($this->httpRequest->headers['Authorization'])) {
$this->httpRequest->SERVER['HTTP_AUTHORIZATION'] = $this->httpRequest->headers['Authorization'];
}
$this->httpRequest->SERVER['REQUEST_TIME'] = time();
// Check if we have to match siteDomain
if ($this->http->getSiteDomain() != '' && $this->http->getSiteDomain() != $this->httpRequest->SERVER['SERVER_NAME']) {
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 404);
$r->addBody($this->createErrorPage(404));
$this->write($r->getHeaders());
$this->write($r->getBody());
$errNo = 404;
$this->logRequest($r->getResponseCode(), $r->getHeader('Content-Length') ? $r->getHeader('Content-Length') : 0);
return false;
}
// HTTP Authorisation?
if ($this->http->getHttpAuthPath() != '') {
$scriptPath = pathinfo($this->httpRequest->SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME);
// Check if path must be auth'd and if HTTP_AUTHORIZATION header exists and if so, validate it
if (isDirInDir($this->http->getHttpAuthPath(), $this->http->getDocRoot() . $scriptPath) && (!isset($this->httpRequest->SERVER['HTTP_AUTHORIZATION']) || !$this->validateAuthorization())) {
// Not validated - send 401 Unauthorized
do {
$nonce = createRandomString(17, RAND_HEX);
if (!$this->http->getNonceInfo($nonce)) {
break;
}
} while (true);
$opaque = $this->http->addNewNonce($nonce);
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 401);
if ($this->http->getHttpAuthType() == 'Digest') {
$r->addHeader('WWW-Authenticate: Digest realm="' . HTTP_AUTH_REALM . '", qop="auth", nonce="' . $nonce . '", opaque="' . $opaque . '"');
} else {
$r->addHeader('WWW-Authenticate: Basic realm="' . HTTP_AUTH_REALM . '"');
}
$r->addBody($this->createErrorPage(401, '', true));
$this->write($r->getHeaders());
$this->write($r->getBody());
$errNo = 401;
$this->logRequest($r->getResponseCode(), $r->getHeader('Content-Length') ? $r->getHeader('Content-Length') : 0);
$this->httpRequest = null;
return true;
// we return true this time because we may stay connected
}
}
//var_dump($this->httpRequest->headers);
//var_dump($this->httpRequest->SERVER);
//var_dump($this->httpRequest->GET);
//var_dump($this->httpRequest->POST);
//var_dump($this->httpRequest->COOKIE);
// Rewrite script name? (keep it internal - don't rewrite SERVER header
$scriptName = $this->httpRequest->SERVER['SCRIPT_NAME'] == '/' ? '/index.php' : $this->httpRequest->SERVER['SCRIPT_NAME'];
if (file_exists($this->http->getDocRoot() . $scriptName)) {
// Should we serve a file or pass the request to PHPParser for page generation?
if (preg_match('/^.*\\.php$/', $scriptName)) {
if ($this->httpRequest->SERVER['REQUEST_METHOD'] == 'HEAD') {
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 200);
$this->write($r->getHeaders());
} else {
// 'Parse' the php file
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 200);
$html = PHPParser::parseFile($r, $scriptName, $this->httpRequest->SERVER, $this->httpRequest->GET, $this->httpRequest->POST, $this->httpRequest->COOKIE, $this->httpRequest->FILES);
$r->addBody($html);
$this->write($r->getHeaders());
$this->write($r->getBody());
}
} else {
if (is_dir($this->http->getDocRoot() . $this->httpRequest->SERVER['SCRIPT_NAME'])) {
// 403 - not allowed to view folder contents
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 403);
$r->addBody($this->createErrorPage(403));
$this->write($r->getHeaders());
$this->write($r->getBody());
} else {
// Send a file
if ($this->httpRequest->SERVER['REQUEST_METHOD'] == 'HEAD') {
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 200);
$this->write($r->getHeaders());
} else {
$r = $this->serveFile();
}
}
}
} else {
// 404
$r = new HttpResponse($this->httpRequest->SERVER['httpVersion'], 404);
$r->addBody($this->createErrorPage(404));
$this->write($r->getHeaders());
$this->write($r->getBody());
}
// log line
$this->logRequest($r->getResponseCode(), $r->getHeader('Content-Length') ? $r->getHeader('Content-Length') : 0);
// Reset httpRequest
$this->httpRequest = null;
return true;
}