getRelativePath() 공개 정적인 메소드

Returns a relative path from $path to $current.
public static getRelativePath ( string $from, string $to ) : string
$from string
$to string relative to this
리턴 string relative path without trailing slash
예제 #1
0
파일: ToolsTest.php 프로젝트: jarves/jarves
 public function testRelativePath()
 {
     $relative = Tools::getRelativePath('/anotherroot/web/file', '/root/web/other/dir');
     $this->assertEquals('../../../../anotherroot/web/file', $relative);
     $relative = Tools::getRelativePath('/root/web/file', '/root/web/other/dir');
     $this->assertEquals('../../file', $relative);
     $relative = Tools::getRelativePath('/root/web/dir/file/', '/root/web/dir');
     $this->assertEquals('file', $relative);
     $relative = Tools::getRelativePath('/root/web/other/file/', '/root/web/dir');
     $this->assertEquals('../other/file', $relative);
 }
예제 #2
0
 /**
  * This is a try to increase initial loading performance, but I wasn't lucky.
  *
  * @ApiDoc(
  *  section="Backend",
  *  description="Prints all typscript modules combined"
  * )
  *
  * @Rest\Get("/admin/backend/typescript-modules.ts")
  *
  * @return string CCS
  */
 public function loadTypescriptModules()
 {
     $newestMTime = 0;
     $jsContent = '';
     foreach ($this->jarves->getConfigs() as $bundleConfig) {
         $path = $bundleConfig->getBundleClass()->getPath();
         $assetInfos = $bundleConfig->getAdminPreloadTypescriptModulesInfo();
         foreach ($assetInfos as $assetInfo) {
             $localPath = $this->jarves->resolveInternalPublicPath($assetInfo->getPath());
             $mtime = filemtime($localPath);
             $newestMTime = max($newestMTime, $mtime);
             $content = file_get_contents($localPath);
             $moduleName = sprintf('./bundles/%s/%s', $bundleConfig->getName(), Tools::getRelativePath($localPath, $path . '/Resources/public/'));
             $jsContent .= "\n/* ts file {$moduleName} */\ndeclare module \"{$moduleName}\" {\n{$content}\n};\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
 /**
  * {@inheritDoc}
  */
 public function getBranch($pk = null, Condition $condition = null, $depth = 1, $scope = null, $options = null)
 {
     $result = null;
     $path = $pk['path'];
     if ($depth === null) {
         $depth = 1;
     }
     if ($path) {
         $path = '@' . trim($path, '/@');
         $path = str_replace(':', '/', $path);
     }
     $c = 0;
     $offset = $options['offset'];
     $limit = $options['limit'];
     $result = array();
     if (!$path) {
         $result = array();
         $bundles = array_keys($this->jarves->getBundles());
         foreach ($bundles as $bundleName) {
             $directory = $this->jarves->resolvePath('@' . $bundleName, 'Resources/views', true);
             if (!$this->localFilesystem->has($directory)) {
                 continue;
             }
             $file = $this->localFilesystem->getFile($directory);
             if (!$file) {
                 $result[] = $directory;
                 continue;
             }
             $file = $file->toArray();
             $file['name'] = $bundleName;
             $file['path'] = $bundleName;
             if ($offset && $offset > $c) {
                 continue;
             }
             if ($limit && $limit < $c) {
                 continue;
             }
             if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $file)) {
                 $result[] = $directory;
                 continue;
             }
             $c++;
             if ($depth > 0) {
                 $children = self::getBranch(array('path' => $bundleName), $condition, $depth - 1);
                 $file['_childrenCount'] = count($children);
                 if ($depth > 1 && $file['type'] == 'dir') {
                     $file['_children'] = $children;
                 }
             }
         }
     } else {
         if (!($bundleName = $this->jarves->getBundleFromPath($path))) {
             return [];
         }
         $directory = $this->jarves->resolvePath($path, 'Resources/views', true) . '/';
         if (!$this->localFilesystem->has($directory)) {
             return [];
         }
         $files = $this->localFilesystem->getFiles($directory);
         foreach ($files as $file) {
             $item = $file->toArray();
             if ($condition && $condition->hasRules() && !$this->conditionOperator->satisfy($condition, $item, 'jarves/file')) {
                 continue;
             }
             $c++;
             if ($offset && $offset >= $c) {
                 continue;
             }
             if ($limit && $limit < $c) {
                 continue;
             }
             $item = array('name' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)), 'path' => $this->buildPath($path . '/' . Tools::getRelativePath($item['path'], $directory)));
             if ($file->isDir()) {
                 $children = self::getBranch(array('path' => $item['path']), $condition, $depth - 1);
                 foreach ($children as $child) {
                     //                        $child['name'] = $item['name'] . '/' . $child['name'];
                     $result[] = $child;
                 }
             }
             if ($file->isFile()) {
                 $result[] = $item;
             }
         }
     }
     return $result;
 }
예제 #4
0
파일: Jarves.php 프로젝트: jarves/jarves
 /**
  * ('@JarvesBundle/Resources/public/test.png') => /var/www/jarves/src/Jarves/Resources/public/test.png
  * ('@JarvesBundle/Resources/public/test.png', '', true) => src/Jarves/Resources/public/test.png
  *
  * ('@JarvesBundle/test.png', 'Resources/public/') => /var/www/jarves/src/Jarves/Resources/public/test.png
  * ('@JarvesBundle/test.png') => /var/www/jarves/src/Jarves/test.png
  *
  * ('images/test.png') => /var/www/jarves/images/webtest.png
  *
  * @param string $path
  * @param string $suffix
  * @param bool $relativePath
  *
  * @return string without trailing slash when relative
  *
  * @throws Exceptions\BundleNotFoundException
  */
 public function resolvePath($path, $suffix = '', $relativePath = false)
 {
     $path = preg_replace('/:+/', '/', $path);
     $root = realpath($this->rootDir . '/../');
     if ($bundle = $this->getBundleFromPath($path, $bundleName)) {
         $path = substr($path, strlen($bundleName) + 1);
         $bundlePath = $bundle->getPath();
         $suffix = trim($suffix, '/');
         $path = trim($path, '/');
         $bundlePath = '/' . trim($bundlePath, '/');
         $path = $bundlePath . ($suffix ? '/' . $suffix : '') . '/' . $path;
     } else {
         $path = $root . $path;
     }
     if ($relativePath) {
         return Tools::getRelativePath($path, $root);
     }
     return $path;
 }
예제 #5
0
 /**
  * @param string $from scss path
  * @param string $to css path
  * @param string $content
  * @return string
  */
 protected function replaceRelativePaths($from, $to, $content)
 {
     $relative = Tools::getRelativePath(dirname($from), dirname($to)) . '/';
     $content = preg_replace('/@import \'(?!.*:\\/\\/)([^\\/].*)\'/', '@import \'' . $relative . '$1\'', $content);
     $content = preg_replace('/@import "(?!.*:\\/\\/)([^\\/].*)"/', '@import "' . $relative . '$1"', $content);
     $content = preg_replace('/url\\(\'(?!.*:\\/\\/)([^\\/][^\\)]*)\'\\)/', 'url(\'' . $relative . '$1\')', $content);
     $content = preg_replace('/url\\(\\"(?!.*:\\/\\/)([^\\/][^\\)]*)\\"\\)/', 'url(\\"' . $relative . '$1\\")', $content);
     $content = preg_replace('/url\\((?!.*data:image)(?!.*:\\/\\/)([^\\/\'].*)\\)/', 'url(' . $relative . '$1)', $content);
     return $content;
 }
예제 #6
0
파일: Bundle.php 프로젝트: jarves/jarves
 /**
  * @param \DOMNode $node
  * @param string $file
  */
 public function import(\DOMNode $node, $file = null)
 {
     if ('bundle' === $node->nodeName) {
         $imported = $this->importNode($node);
         $root = realpath($this->getJarves()->getRootDir() . '/../');
         foreach ($imported as $property) {
             $this->imported[$property] = Tools::getRelativePath($file, $root);
         }
     }
 }