本文整理汇总了PHP中Symfony\Component\Routing\Generator\UrlGenerator::getRelativePath方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlGenerator::getRelativePath方法的具体用法?PHP UrlGenerator::getRelativePath怎么用?PHP UrlGenerator::getRelativePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Routing\Generator\UrlGenerator
的用法示例。
在下文中一共展示了UrlGenerator::getRelativePath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$container->setParameter('hearsay_require_js.require_js_src', $config['require_js_src']);
$container->setParameter('hearsay_require_js.initialize_template', $config['initialize_template']);
$container->setParameter('hearsay_require_js.base_url', $config['base_url']);
$container->setParameter('hearsay_require_js.base_dir', $this->getRealPath($config['base_dir'], $container));
// Add the base directory as an empty namespace
$config['paths'][''] = array('location' => $config['base_dir'], 'external' => false);
$hideUnoptimizedAssets = !isset($config['optimizer']['hide_unoptimized_assets']) ? false : $config['optimizer']['hide_unoptimized_assets'];
// By using this flag as true, defines will be declared as their module names
$declareModuleName = !isset($config['optimizer']['declare_module_name']) ? false : $config['optimizer']['declare_module_name'];
$container->setParameter('hearsay_require_js.declare_module_name', $declareModuleName);
foreach ($config['paths'] as $path => $settings) {
$location = $settings['location'];
if ($settings['external']) {
$this->addExternalNamespaceMapping($location, $path, $container);
} else {
is_array($location) && ($location = array_shift($location));
$this->addNamespaceMapping($location, $path, $container, !$hideUnoptimizedAssets);
}
}
$container->setParameter('hearsay_require_js.shim', $config['shim']);
$configurationBuilder = $container->getDefinition('hearsay_require_js.configuration_builder');
foreach ($config['options'] as $option => $settings) {
$configurationBuilder->addMethodCall('addOption', array($option, $settings['value']));
}
if (!isset($config['optimizer'])) {
// If the r.js optimizer config isn't provided, don't provide the Assetic filter
$container->removeDefinition('hearsay_require_js.optimizer_filter');
} else {
$container->setParameter('hearsay_require_js.r.path', $this->getRealPath($config['optimizer']['path'], $container));
$filter = $container->getDefinition('hearsay_require_js.optimizer_filter');
if ($config['optimizer']['almond_path']) {
// Makes almond path relative to base directory for r.js optimization
$almondPath = UrlGenerator::getRelativePath($container->getParameter('hearsay_require_js.base_dir'), $this->getRealPath($config['optimizer']['almond_path'], $container));
// Removes file extension if it exists
$almondPath = preg_replace('/\\.js$/', '', $almondPath);
$filter->addMethodCall('setAlmondPath', array($almondPath));
$configurationBuilder->addMethodCall('setUseAlmond', array(true));
}
$filter->addMethodCall('setShim', array($config['shim']));
$filter->addMethodCall('setTimeout', array($config['optimizer']['timeout']));
foreach ($config['optimizer']['exclude'] as $exclude) {
$filter->addMethodCall('addExclude', array($exclude));
}
foreach ($config['optimizer']['modules'] as $name => $module) {
$filter->addMethodCall('addModule', array($name, $module));
}
foreach ($config['optimizer']['options'] as $name => $settings) {
$filter->addMethodCall('addOption', array($name, $settings['value']));
}
}
}
示例2: testGetRelativePath
/**
* @dataProvider provideRelativePaths
*/
public function testGetRelativePath($sourcePath, $targetPath, $expectedPath)
{
$this->assertSame($expectedPath, UrlGenerator::getRelativePath($sourcePath, $targetPath));
}
示例3: getRelativePath
/**
* Returns the target path as relative reference from the base path.
*
* @param string $basePath The base path
* @param string $targetPath The target path
*
* @return string The relative target path
*/
protected function getRelativePath($basePath, $targetPath)
{
return UrlGenerator::getRelativePath($basePath, $targetPath);
}
示例4: getUrlOrPathForType
/**
* @param string $pathInfo
* @param bool|string $referenceType
*
* @return string
*/
protected function getUrlOrPathForType($pathInfo, $referenceType)
{
$url = $pathInfo;
$scheme = $this->context->getScheme();
if (self::NETWORK_PATH !== $referenceType && ($scheme === 'http' && $this->sslEnabled === true || $scheme === 'https' && $this->sslEnabled === false)) {
$referenceType = self::ABSOLUTE_URL;
}
switch ($referenceType) {
case self::ABSOLUTE_URL:
case self::NETWORK_PATH:
$url = $this->buildUrl($pathInfo, $referenceType);
break;
case self::ABSOLUTE_PATH:
$url = $pathInfo;
break;
case self::RELATIVE_PATH:
$url = UrlGenerator::getRelativePath($this->context->getPathInfo(), $pathInfo);
break;
}
return $url;
}