bug #15369 [TwigBridge] type-dependent path discovery (marcosdsanchez, xabbuh)
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBridge] type-dependent path discovery | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15340 | License | MIT | Doc PR | With the introduction of the `AbstractFileExtractor` in Symfony 2.7, the `extract()` method in the `TwigExtractor` class does not necessarily deal with `SplFileInfo` instances from the Finder component, but also receives `\SplFileInfo` objects initialized by the base extractor class. Commits -------1e15761
[TwigBridge] type-dependent path discovery2bf78e5
Resources as string have the same problemaa7cbbd
Introduce failing test case when a SplFileInfo object is passed to the extract() method in the TwigExtractor.
This commit is contained in:
commit
6bb0c4898e
@ -73,15 +73,28 @@ class TwigExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Twig_Error
|
* @expectedException \Twig_Error
|
||||||
* @expectedExceptionMessageRegExp /Unclosed "block" in "extractor(\/|\\)syntax_error\.twig" at line 1/
|
* @expectedExceptionMessageRegExp /Unclosed "block" in ".*extractor(\/|\\)syntax_error\.twig" at line 1/
|
||||||
|
* @dataProvider resourcesWithSyntaxErrorsProvider
|
||||||
*/
|
*/
|
||||||
public function testExtractSyntaxError()
|
public function testExtractSyntaxError($resources)
|
||||||
{
|
{
|
||||||
$twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
|
$twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
|
||||||
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
|
$twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface')));
|
||||||
|
|
||||||
$extractor = new TwigExtractor($twig);
|
$extractor = new TwigExtractor($twig);
|
||||||
$extractor->extract(__DIR__.'/../Fixtures', new MessageCatalogue('en'));
|
$extractor->extract($resources, new MessageCatalogue('en'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function resourcesWithSyntaxErrorsProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(__DIR__.'/../Fixtures'),
|
||||||
|
array(__DIR__.'/../Fixtures/extractor/syntax_error.twig'),
|
||||||
|
array(new \SplFileInfo(__DIR__.'/../Fixtures/extractor/syntax_error.twig')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bridge\Twig\Translation;
|
namespace Symfony\Bridge\Twig\Translation;
|
||||||
|
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
|
use Symfony\Component\Translation\Extractor\AbstractFileExtractor;
|
||||||
use Symfony\Component\Translation\Extractor\ExtractorInterface;
|
use Symfony\Component\Translation\Extractor\ExtractorInterface;
|
||||||
use Symfony\Component\Translation\MessageCatalogue;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
@ -60,7 +61,11 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
|||||||
try {
|
try {
|
||||||
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (\Twig_Error $e) {
|
||||||
$e->setTemplateFile($file->getRelativePathname());
|
if ($file instanceof SplFileInfo) {
|
||||||
|
$e->setTemplateFile($file->getRelativePathname());
|
||||||
|
} elseif ($file instanceof \SplFileInfo) {
|
||||||
|
$e->setTemplateFile($file->getRealPath());
|
||||||
|
}
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user