bug #20292 Enhance GAE compat by removing some realpath() (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

Enhance GAE compat by removing some realpath()

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20241
| License       | MIT
| Doc PR        | -

The remaining ones are in test folders, or in things that don't run/have to run on GAE directly (e.g. commands).

Commits
-------

f2f232d Enhance GAE compat by removing some realpath()
This commit is contained in:
Fabien Potencier 2016-10-27 08:37:53 -07:00
commit 0572866184
11 changed files with 23 additions and 26 deletions

View File

@ -134,10 +134,7 @@ abstract class AbstractDoctrineExtension extends Extension
throw new \InvalidArgumentException(sprintf('Invalid Doctrine mapping path given. Cannot load Doctrine mapping/bundle named "%s".', $mappingName));
}
if (substr($mappingDirectory, 0, 7) !== 'phar://') {
$mappingDirectory = realpath($mappingDirectory);
}
$this->drivers[$mappingConfig['type']][$mappingConfig['prefix']] = $mappingDirectory;
$this->drivers[$mappingConfig['type']][$mappingConfig['prefix']] = realpath($mappingDirectory) ?: $mappingDirectory;
}
/**

View File

@ -61,7 +61,7 @@ class DoctrineValidationPass implements CompilerPassInterface
foreach ($container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
if (is_file($file = dirname($reflection->getFileName()).'/'.$validationPath)) {
$files[] = realpath($file);
$files[] = $file;
$container->addResource(new FileResource($file));
}
}

View File

@ -64,7 +64,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
if ($file instanceof SplFileInfo) {
$e->setTemplateName($file->getRelativePathname());
} elseif ($file instanceof \SplFileInfo) {
$e->setTemplateName($file->getRealPath());
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
}
throw $e;

View File

@ -52,7 +52,7 @@ class FrameworkExtension extends Extension
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
$loader->load('web.xml');
$loader->load('services.xml');
@ -689,7 +689,7 @@ class FrameworkExtension extends Extension
if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) {
$r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException');
$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
$dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations';
}
$rootDir = $container->getParameter('kernel.root_dir');
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
@ -811,21 +811,21 @@ class FrameworkExtension extends Extension
$dirname = dirname($reflection->getFileName());
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
$files[0][] = realpath($file);
$files[0][] = $file;
$container->addResource(new FileResource($file));
}
if (is_file($file = $dirname.'/Resources/config/validation.yml')) {
$files[1][] = realpath($file);
$files[1][] = $file;
$container->addResource(new FileResource($file));
}
if (is_dir($dir = $dirname.'/Resources/config/validation')) {
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
$files[0][] = $file->getRealPath();
$files[0][] = $file->getPathname();
}
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
$files[1][] = $file->getRealPath();
$files[1][] = $file->getPathname();
}
$container->addResource(new DirectoryResource($dir));
@ -926,7 +926,7 @@ class FrameworkExtension extends Extension
$dirname = dirname($reflection->getFileName());
if (is_file($file = $dirname.'/Resources/config/serialization.xml')) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array(realpath($file)));
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array($file));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
@ -934,7 +934,7 @@ class FrameworkExtension extends Extension
}
if (is_file($file = $dirname.'/Resources/config/serialization.yml')) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader', array(realpath($file)));
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader', array($file));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
@ -943,13 +943,13 @@ class FrameworkExtension extends Extension
if (is_dir($dir = $dirname.'/Resources/config/serialization')) {
foreach (Finder::create()->files()->in($dir)->name('*.xml') as $file) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array($file->getRealPath()));
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader', array($file->getPathname()));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
}
foreach (Finder::create()->files()->in($dir)->name('*.yml') as $file) {
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader', array($file->getRealPath()));
$definition = new Definition('Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader', array($file->getPathname()));
$definition->setPublic(false);
$serializerLoaders[] = $definition;
@ -996,7 +996,7 @@ class FrameworkExtension extends Extension
*/
public function getXsdValidationBasePath()
{
return __DIR__.'/../Resources/config/schema';
return dirname(__DIR__).'/Resources/config/schema';
}
public function getNamespace()

View File

@ -363,11 +363,11 @@ abstract class FrameworkExtensionTest extends TestCase
// Testing symfony/framework-bundle with deps=high
$this->assertStringEndsWith('symfony'.DIRECTORY_SEPARATOR.'form/Resources/config/validation.xml', $xmlMappings[0]);
}
$this->assertStringEndsWith('TestBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'validation.xml', $xmlMappings[1]);
$this->assertStringEndsWith('TestBundle/Resources/config/validation.xml', $xmlMappings[1]);
$yamlMappings = $calls[4][1][0];
$this->assertCount(1, $yamlMappings);
$this->assertStringEndsWith('TestBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'validation.yml', $yamlMappings[0]);
$this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlMappings[0]);
}
public function testValidationNoStaticMethod()

View File

@ -62,7 +62,7 @@ class ClassCollectionLoader
if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
throw new \RuntimeException(sprintf('Class Collection Loader was not able to create directory "%s"', $cacheDir));
}
$cacheDir = rtrim(realpath($cacheDir), '/'.DIRECTORY_SEPARATOR);
$cacheDir = rtrim(realpath($cacheDir) ?: $cacheDir, '/'.DIRECTORY_SEPARATOR);
$cache = $cacheDir.DIRECTORY_SEPARATOR.$name.$extension;
// auto-reload

View File

@ -64,7 +64,7 @@ class ClassMapGenerator
continue;
}
$path = $file->getRealPath();
$path = $file->getRealPath() ?: $file->getPathname();
if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') {
continue;

View File

@ -32,7 +32,7 @@ class FileResource implements ResourceInterface, \Serializable
*/
public function __construct($resource)
{
$this->resource = realpath($resource);
$this->resource = realpath($resource) ?: (file_exists($resource) ? $resource : false);
}
/**

View File

@ -44,7 +44,7 @@ class DateRangeFilterIterator extends FilterIterator
{
$fileinfo = $this->current();
if (!file_exists($fileinfo->getRealPath())) {
if (!file_exists($fileinfo->getPathname())) {
return false;
}

View File

@ -41,7 +41,7 @@ class SortableIterator implements \IteratorAggregate
if (self::SORT_BY_NAME === $sort) {
$this->sort = function ($a, $b) {
return strcmp($a->getRealpath(), $b->getRealpath());
return strcmp($a->getRealpath() ?: $a->getPathname(), $b->getRealpath() ?: $b->getPathname());
};
} elseif (self::SORT_BY_TYPE === $sort) {
$this->sort = function ($a, $b) {
@ -51,7 +51,7 @@ class SortableIterator implements \IteratorAggregate
return 1;
}
return strcmp($a->getRealpath(), $b->getRealpath());
return strcmp($a->getRealpath() ?: $a->getPathname(), $b->getRealpath() ?: $b->getPathname());
};
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
$this->sort = function ($a, $b) {

View File

@ -244,7 +244,7 @@ final class Intl
*/
public static function getDataDirectory()
{
return realpath(__DIR__.'/Resources/data');
return __DIR__.'/Resources/data';
}
/**