当前位置: 首页>>代码示例>>PHP>>正文


PHP File::getMTime方法代码示例

本文整理汇总了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;
 }
开发者ID:ambroisemaupate,项目名称:intervention-request,代码行数:35,代码来源:FileCache.php

示例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;
 }
开发者ID:tifabien,项目名称:symfony,代码行数:8,代码来源:BinaryFileResponse.php

示例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();
 }
开发者ID:gisostallenberg,项目名称:file-serving,代码行数:25,代码来源:FileServer.php

示例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');
开发者ID:renyunhuang,项目名称:nodephp,代码行数:31,代码来源:front.example.com.php


注:本文中的Symfony\Component\HttpFoundation\File\File::getMTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。