8000 Enhance GAE compat by removing some realpath() by nicolas-grekas · Pull Request #20292 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Enhance GAE compat by removing some realpath() #20292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ protected function setMappingDriverConfig(array $mappingConfig, $mappingName)
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks BC, because Doctrine does not follow symlinks when reading mapping

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to get what you mean. Does this need a fix? (can you send it please?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, I looked at it too fast and missed the fact that it was not removed entirely but only when realpath fails.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function updateValidatorMappingFiles(ContainerBuilder $container, $mappi
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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function extract($resource, MessageCatalogue $catalogue)
if ($file instanceof SplFileInfo) {
$e->setTemplateName($file->getRelativePathname());
} elseif ($file instanceof \SplFileInfo) {
$e->setTemplateName($file->getRealPath());
$e->setTemplateName($file->getRealPath() ?: $file->getPathname());
}

throw $e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Copy link
Member
@javiereguiluz javiereguiluz Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking: is this kind of change needed to solve the GAE issues? I agree with @xabbuh that dirname(__DIR__) is less readable than ../ (and it also introduces a function call).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a DI extension, we don't care about perf :) And yes it is: realpath removes these .., but if we don't call realpath anymore, we have to clean the path ourselves.


$loader->load('web.xml');
$loader->load('services.xml');
Expand Down Expand Up @@ -689,7 +689,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
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) {
Expand Down Expand Up @@ -811,21 +811,21 @@ private function getValidatorMappingFiles(ContainerBuilder $container)
$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));
Expand Down Expand Up @@ -926,15 +926,15 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$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;
$container->addResource(new FileResource($file));
}

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;
Expand All @@ -943,13 +943,13 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder

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;
Expand Down Expand Up @@ -996,7 +996,7 @@ private function getKernelRootHash(ContainerBuilder $container)
*/
public function getXsdValidationBasePath()
{
return __DIR__.'/../Resources/config/schema';
return dirname(__DIR__).'/Resources/config/schema';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really care about a realpath here though (unless GAE also does not support .. in paths, but then they should reallt rework there filesystem)

}

public function getNamespace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ public function testValidationPaths()
// 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
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
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ClassLoader/ClassMapGenerator.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function createMap($dir)
continue;
}

$path = $file->getRealPath();
$path = $file->getRealPath() ?: $file->getPathname();

if (pathinfo($path, PATHINFO_EXTENSION) !== 'php') {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Resource/FileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function accept()
{
$fileinfo = $this->current();

if (!file_exists($fileinfo->getRealPath())) {
if (!file_exists($fileinfo->getPathname())) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Finder/Iterator/SortableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(\Traversable $iterator, $sort)

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) {
Expand All @@ -51,7 +51,7 @@ public function __construct(\Traversable $iterator, $sort)
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Intl/Intl.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static function getIcuStubVersion()
*/
public static function getDataDirectory()
{
return realpath(__DIR__.'/Resources/data');
return __DIR__.'/Resources/data';
}

/**
Expand Down
0