本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::getMTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getMTime方法的具體用法?PHP File::getMTime怎麽用?PHP File::getMTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::getMTime方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getResponse
/**
* @param Closure $callback
* @param InterventionRequest $interventionRequest
* @return Response
*/
public function getResponse(Closure $callback, InterventionRequest $interventionRequest)
{
try {
$this->cacheFile = new File($this->cacheFilePath);
$response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $this->cacheFile->getMimeType(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-Cached' => true]);
$response->setLastModified(new \DateTime(date("Y-m-d H:i:s", $this->cacheFile->getMTime())));
} catch (FileNotFoundException $e) {
if (is_callable($callback)) {
$image = $callback($interventionRequest);
if ($image instanceof Image) {
$this->saveImage($image);
$this->cacheFile = new File($this->cacheFilePath);
if (null !== $this->dispatcher) {
// create the ImageSavedEvent and dispatch it
$event = new ImageSavedEvent($image, $this->cacheFile);
$this->dispatcher->dispatch(ImageSavedEvent::NAME, $event);
}
// send HTTP header and output image data
$response = new Response(file_get_contents($this->cacheFile->getPathname()), Response::HTTP_OK, ['Content-Type' => $image->mime(), 'Content-Disposition' => 'filename="' . $this->realImage->getFilename() . '"', 'X-Generator-First-Render' => true]);
$response->setLastModified(new \DateTime('now'));
} else {
throw new \RuntimeException("Image is not a valid InterventionImage instance.", 1);
}
} else {
throw new \RuntimeException("No image handle closure defined", 1);
}
}
$this->initializeGarbageCollection();
return $response;
}
示例2: setAutoLastModified
/**
* Automatically sets the Last-Modified header according the file modification date.
*/
public function setAutoLastModified()
{
$this->setLastModified(\DateTime::createFromFormat('U', $this->file->getMTime()));
return $this;
}
示例3: getResponse
/**
* Creates the response object.
*
* @return Response
*/
public function getResponse()
{
$requestPath = parse_url($this->request->server->get('REQUEST_URI'), PHP_URL_PATH);
foreach ($this->from as $from) {
$filePath = $from . substr($requestPath, strlen($this->to));
if (!$this->isAllowedExtension(pathinfo($filePath, PATHINFO_EXTENSION))) {
continue;
}
if (is_file($filePath)) {
$file = new File($filePath);
$response = Response::create()->setExpires(new DateTime('+1 week'))->setLastModified(DateTime::createFromFormat('U', $file->getMTime()));
if ($response->isNotModified($this->request)) {
return $response;
}
$this->setContentType($file, $response);
return $response->setContent(file_get_contents($file->getPathname()));
}
}
return $this->getNotFoundResponse();
}
示例4: Response
}
$css = file_get_contents(APP_FRONT_RESOURCE_PATH . $request->getPathInfo(), false, null, -1);
$response = new Response($css);
$response->headers->set('Content-Type', 'text/css');
//200 OK(BFCache)
$response->setExpires(new \DateTime('2019-01-01'));
return $response;
}), array('_method' => 'GET', '_format' => 'css|min.css', 'path' => 'dist/css|assets/css|app/css')));
#.js config
$routes->add('front_js', new Route('/{path}/{file}.{_format}', array('file' => null, '_controller' => function (Request $request) {
$js = new File(APP_FRONT_RESOURCE_PATH . $request->getPathInfo(), true);
# check file exists
$jsContent = file_get_contents(APP_FRONT_RESOURCE_PATH . $request->getPathInfo(), false, null, -1);
$response = new Response($jsContent);
$response->headers->set('Content-Type', 'text/javascript');
$jsLastModified = $js->getMTime();
$date = new \DateTime('now');
//UTC
$date->setTimestamp($jsLastModified);
$response->setLastModified($date);
$response->isNotModified($request);
return $response;
}), array('_method' => 'GET', '_format' => 'js|min.js|11.3.min.js', 'path' => 'dist/js|assets/js|assets/js/vendor|app/js')));
#.jpeg config
$routes->add('img', new Route('/img/{params}', array('params' => null, '_controller' => function (Request $request) {
if (!file_exists(APP_FRONT_RESOURCE_PATH . $request->getPathInfo())) {
throw new ResourceNotFoundException(APP_FRONT_RESOURCE_PATH . $request->getPathInfo());
}
$img = file_get_contents(APP_FRONT_RESOURCE_PATH . $request->getPathInfo(), false, null, -1);
$response = new Response($img);
$response->headers->set('Content-Type', 'image/jpeg');