/** * @param boolean $useRequirejsRc * @param string $jsonFilePath * @param array $options * @param array $extend * * @return string */ protected function generateConfig($useRequirejsRc, $jsonFilePath, array $options, array $extend = []) { $jsonFile = $this->getSrcFileName($jsonFilePath); if (!file_exists($jsonFile)) { throw new \UnexpectedValueException('Not found file: ' . $jsonFile); } $json = json_decode(file_get_contents($jsonFile), true); if (!is_array($json)) { throw new \UnexpectedValueException('File ' . $jsonFile . ' is invalid.'); } if ($useRequirejsRc) { $rcFile = $this->getRequirejsRcFile(); if (!file_exists($rcFile)) { throw new \UnexpectedValueException('Not found file: ' . $rcFile); } $rcData = json_decode(file_get_contents($rcFile), true); if (!is_array($rcData)) { throw new \UnexpectedValueException('File ' . $rcFile . ' is invalid.'); } } else { $rcData = []; } $params = $this->resolver->resolve($options); $basePath = $this->appPaths->getBasePath(); $defaults = ['timeout' => (int) $this->params['resources_loading_timeout'], 'res' => $params['resources'], 'translations' => $params['translations'], 'locale' => $this->request->getCurrentRequest()->getLocale(), 'theme_name' => $this->theme->getName(), 'path' => ['base' => $basePath, 'theme' => $this->appPaths->url('web_theme'), 'resources' => $this->appPaths->url('web_resources'), 'lib' => $this->appPaths->url('web_resources') . '/lib', 'cdn_javascript' => $this->params['cdn_enable'] ? $this->params['cdn_javascript'] : '', 'cdn_css' => $this->params['cdn_enable'] ? $this->params['cdn_css'] : '', 'cdn_image' => $this->params['cdn_enable'] ? $this->params['cdn_image'] : ''], 'requirejs' => ['baseUrl' => $basePath . '/js']]; $config = array_merge_recursive($defaults, ['requirejs' => $rcData], $json, $extend); return json_encode($config, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS); }
/** * @param object $obj * @param string $fieldName * * @return ImageResourcesLoader */ protected function getLoader($obj, $fieldName) { $accessor = PropertyAccess::createPropertyAccessor(); $hash = spl_object_hash($obj); if (is_null($accessor->getValue($this->loaders, "[{$hash}][{$fieldName}]"))) { $locator = new FileLocator($this->appPaths->absolute('kernel_root') . ImagesMappingService::CONFIG_DIR); $loader = new ImageResourcesLoader($locator, ['images_root_dir' => $this->appPaths->absolute('web'), 'images_output_dir' => $this->appPaths->absolute('web'), 'baseurl' => $this->appPaths->getBasePath(), 'cache_dir' => $this->appPaths->absolute('kernel_cache') . ImagesMappingService::CACHE_IMAGES_DIR, 'cache_refresh' => $this->environment === 'dev']); $accessor->setValue($this->loaders, "[{$hash}][{$fieldName}]", $loader); } return $this->loaders[$hash][$fieldName]; }
/** * @param array $params * @param array $custom * * @return HtmlResourcesUtility */ public function getUtility(array $params, array $custom = []) { $preprocessorData = $this->getPreprocessorData(); return new HtmlResourcesUtility(array_merge(['cache_dir' => $this->appPaths->absolute('kernel_cache') . '/vsymfo_document/resources', 'cache_db_dir' => $this->appPaths->absolute('kernel_cache') . '/../document/' . $this->appPaths->getThemeName(), 'cache_refresh' => $this->env == 'dev', 'cache_lifetime' => $params['resources_cache_lifetime'], 'web_dir' => $this->appPaths->getPrivateDir(), 'web_url' => $this->appPaths->getBasePath(), 'web_cache_dir' => $this->appPaths->absolute('web_cache') . '/' . $this->appPaths->getThemeName(), 'web_cache_url' => $this->appPaths->url('web_cache') . '/' . $this->appPaths->getThemeName(), 'less_import_dirs' => $preprocessorData['import_dirs'], 'less_variables' => $preprocessorData['variables'], 'scss_import_dirs' => array_keys($preprocessorData['import_dirs']), 'scss_variables' => $preprocessorData['variables'], 'versioning_enable' => $params['versioning_enable'], 'versioning_version' => $params['versioning_version'], 'versioning_timestamp' => $params['versioning_timestamp'], 'cdn_enable' => $params['cdn_enable'], 'cdn_javascript' => $params['cdn_javascript'], 'cdn_css' => $params['cdn_css']], $custom)); }