resolveWebPath() public method

('images/test.png') => web/images/webtest.png
public resolveWebPath ( string $path ) : string
$path string
return string
コード例 #1
0
ファイル: AdminAssets.php プロジェクト: jarves/jarves
 public function addMainResources($options = array())
 {
     $response = $this->pageStack->getPageResponse();
     $request = $this->pageStack->getRequest();
     $options['noJs'] = isset($options['noJs']) ? $options['noJs'] : false;
     $prefix = substr($this->jarves->getAdminPrefix(), 1);
     $response->addJs('
     window._path = window._baseUrl = ' . json_encode($request->getBasePath() . '/') . '
     window._pathAdmin = ' . json_encode($request->getBaseUrl() . '/' . $prefix . '/'), 3001);
     if ($this->jarves->isDebugMode()) {
         foreach ($this->jarves->getConfigs() as $bundleConfig) {
             foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
                 if ($options['noJs'] && $assetInfo->isJavaScript()) {
                     continue;
                 }
                 $response->addAsset($assetInfo);
             }
         }
     } else {
         $response->addCssFile($prefix . '/admin/backend/css');
         if (!$options['noJs']) {
             $response->addJsFile($prefix . '/admin/backend/script', 3000);
         }
         foreach ($this->jarves->getConfigs() as $bundleConfig) {
             foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
                 if ($options['noJs'] && $assetInfo->isJavaScript()) {
                     continue;
                 }
                 if ($assetInfo->getPath()) {
                     // load javascript files, that are not accessible (means those point to a controller)
                     // because those can't be compressed
                     $path = $this->jarves->resolveWebPath($assetInfo->getPath());
                     if (!file_exists($path)) {
                         $response->addAsset($assetInfo);
                         continue;
                     }
                 }
                 if ($assetInfo->getContent()) {
                     // load inline assets because we can't compress those
                     $response->addAsset($assetInfo);
                     continue;
                 }
                 if (!$assetInfo->isCompressionAllowed()) {
                     $response->addAsset($assetInfo);
                 }
             }
         }
     }
     $response->setDocType('JarvesBundle:Admin:index.html.twig');
     $response->addHeader('<meta name="viewport" content="initial-scale=1.0" >');
     $response->addHeader('<meta name="apple-mobile-web-app-capable" content="yes">');
     $response->setResourceCompression(false);
 }
コード例 #2
0
ファイル: BackendController.php プロジェクト: jarves/jarves
 /**
  * @ApiDoc(
  *  section="Backend",
  *  description="Prints all JavaScript files combined"
  * )
  *
  * @Rest\QueryParam(name="printSourceMap", requirements=".+", description="If the sourceMap should printed")
  *
  * @Rest\Get("/admin/backend/script")
  *
  * @return string javascript
  */
 public function loadJsAction()
 {
     $assets = array();
     $md5String = '';
     $newestMTime = 0;
     $jsContent = '';
     foreach ($this->jarves->getConfigs() as $bundleConfig) {
         foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
             if (!$assetInfo->isJavaScript()) {
                 continue;
             }
             if (!$assetInfo->isCompressionAllowed()) {
                 continue;
             }
             $path = $this->jarves->resolveWebPath($assetInfo->getPath());
             if (file_exists($path)) {
                 $assets[] = $assetInfo->getPath();
                 $mtime = filemtime($path);
                 $newestMTime = max($newestMTime, $mtime);
                 $md5String .= ">{$path}.{$mtime}<";
                 $content = file_get_contents($path);
                 $jsContent .= "\n/* file: {$assetInfo->getPath()} */\n{$content}\n";
             }
         }
     }
     $ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since');
     if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $newestMTime) {
         // Client's cache IS current, so we just respond '304 Not Modified'.
         $response = new Response();
         $response->setStatusCode(304);
         $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $newestMTime) . ' GMT');
         return $response;
     }
     $expires = 60 * 60 * 24 * 14;
     //2 weeks
     $response = new Response();
     $response->headers->set('Content-Type', 'application/javascript');
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Cache-Control', 'max-age=' . $expires);
     $response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
     //        $content = implode($files);
     $response->setContent($jsContent);
     return $response;
 }
コード例 #3
0
ファイル: PageResponse.php プロジェクト: jarves/jarves
 /**
  * Builds the html container tag for the favicon.
  *
  * @return string
  */
 public function getFaviconTag()
 {
     if ($this->getFavicon()) {
         return sprintf('<link rel="shortcut icon" type="image/x-icon" href="%s">' . PHP_EOL, $this->jarves->resolveWebPath($this->getFavicon()));
     }
 }
コード例 #4
0
ファイル: Utils.php プロジェクト: jarves/jarves
 public function compressJs(array $assets, $targetPath)
 {
     $oFile = $targetPath;
     $files = [];
     $md5String = '';
     $newestMTime = 0;
     foreach ($assets as $assetPath) {
         $path = $this->jarves->resolveWebPath($assetPath);
         $files[] = '--js ' . escapeshellarg($path);
         $mtime = filemtime($path);
         $newestMTime = max($newestMTime, $mtime);
         $md5String .= ">{$path}.{$mtime}<";
     }
     $sourceMap = $oFile . '.map';
     $cmdTest = 'java -version 2>&1';
     $closure = 'vendor/google/closure-compiler/compiler.jar';
     $compiler = escapeshellarg(realpath('../' . $closure));
     $cmd = 'java -jar ' . $compiler . ' --js_output_file ' . escapeshellarg('web/' . $oFile);
     $returnVal = 0;
     $debugMode = false;
     $handle = @fopen($oFile, 'r');
     $fileUpToDate = false;
     $md5Line = '//' . md5($md5String) . "\n";
     if ($handle) {
         $line = fgets($handle);
         fclose($handle);
         if ($line === $md5Line) {
             $fileUpToDate = true;
         }
     }
     if ($fileUpToDate) {
         return true;
     } else {
         if (!$debugMode) {
             exec($cmdTest, $outputTest, $returnVal);
         }
         if (0 === $returnVal) {
             $cmd .= ' --create_source_map ' . escapeshellarg('web/' . $sourceMap);
             $cmd .= ' --source_map_format=V3';
             $cmd .= ' ' . implode(' ', $files);
             $cmd .= ' 2>&1';
             $output = [];
             exec($cmd, $output, $returnVal);
             if (0 === $returnVal) {
                 //                    if (false === strpos($output, 'ERROR - Parse error')) {
                 $content = file_get_contents('web/' . $oFile);
                 $sourceMapUrl = '//@ sourceMappingURL=' . basename($sourceMap);
                 $content = $md5Line . $content . $sourceMapUrl;
                 file_put_contents('web/' . $oFile, $content);
                 return true;
                 //                    }
             }
         }
         $content = '';
         foreach ($assets as $assetPath) {
             $content .= "\n/* {$assetPath} */\n\n";
             $path = $this->jarves->resolveWebPath($assetPath);
             $content .= file_get_contents($path);
         }
         if ($content) {
             $this->webFilesystem->write($oFile, $content);
             return true;
         }
         return false;
     }
 }