Ver código fonte

merged branch everzet/translation-phar-support (PR #1366)

Commits
-------

a664a60 [Translation] support phar archives by XLIFF loader

Discussion
----------

[Translation] support phar archives by XLIFF loader

Support XLIFF translation files usage from phar package.

---------------------------------------------------------------------------

by fabpot at 2011/06/19 03:06:50 -0700

phar support is complex as not everything in PHP supports it. This patch only solves one area where phar is not supported. So, we need a solution that makes the entire framework phar-compatible, which is far from easy (realpath for instance cannot be used anywhere). So, I'm closing this PR and let's revisit the global phar support for 2.1.

---------------------------------------------------------------------------

by everzet at 2011/06/19 04:47:49 -0700

I'm not trying to package Symfony2 into phar :-) As it's indeed, very complex task even for 2.1. What i'm trying to do - i'm trying to package Behat in *.phar. And the only thing that blocks it - this PR. So, i'm not interested in full-stack phar support for entire Symfony2 framework right now, but as Symfony2 Components were created as stand-alone libs, this PR is enough to make Translation component itself supporting phar packaging. I use Translation component and XLIFF translations in Behat heavily and this PR gives me ability to create fully-working behat.phar package (tested).

Also, this PR doesn't breaks anything and even more - it's exactly the same piece of code, that we have in DependencyInjection component now: https://github.com/symfony/DependencyInjection/blob/master/Loader/XmlFileLoader.php#L327.

I'll be happy to work on phar support for 2.1. But for now, i can't see real reasons why Translation component can't already support it ;-)
Fabien Potencier 14 anos atrás
pai
commit
86347a94c1

+ 10 - 1
src/Symfony/Component/Translation/Loader/XliffFileLoader.php

@@ -56,7 +56,16 @@ class XliffFileLoader implements LoaderInterface
             throw new \Exception(implode("\n", $this->getXmlErrors()));
         }
 
-        $parts = explode('/', str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd');
+        $location = str_replace('\\', '/', __DIR__) . '/schema/dic/xliff-core/xml.xsd';
+        $parts = explode('/', $location);
+        if (preg_match('#^phar://#i', $location)) {
+            $tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
+            if ($tmpfile) {
+                file_put_contents($tmpfile, file_get_contents($location));
+                $tmpfiles[] = $tmpfile;
+                $parts = explode('/', str_replace('\\', '/', $tmpfile));
+            }
+        }
         $drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
         $location = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));