Jarves\Jarves::resolveWebPath PHP Méthode

resolveWebPath() public méthode

('images/test.png') => web/images/webtest.png
public resolveWebPath ( string $path ) : string
$path string
Résultat string
    public function resolveWebPath($path)
    {
        if ($path && '@' !== $path[0]) {
            return 'web/' . $path;
        }
        preg_match('/(\\@?[a-zA-Z0-9\\-_\\.\\\\]+)/', $path, $matches);
        if ($matches && isset($matches[1])) {
            try {
                $bundle = $this->getBundle(str_replace('@', '', $matches[1]));
            } catch (\InvalidArgumentException $e) {
                throw new BundleNotFoundException(sprintf('Bundle for `%s` (%s) not found.', $matches[1], $path), 0, $e);
            }
            $targetDir = 'web/bundles/' . $this->getShortBundleName($bundle->getName());
            return $targetDir . substr($path, strlen($matches[0]));
        }
        return 'web/' . $path;
    }

Usage Example

Exemple #1
0
 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);
 }
All Usage Examples Of Jarves\Jarves::resolveWebPath