Merge branch '2.8'
* 2.8: [Finder] Fix recursive filter iterator [Translator][FileDumper] deprecated format method in favor of formatCatalogue. bug #15811 use of twig deprecated sameas test Improve the structure of the Finder testsuite Remove minimum width for web profiler content view [VarDumper] Fix HtmlDumper constructor calling CliDumper's [Finder] Handle filtering of recursive iterators and use it to skip looping over excluded directories Validate the extended type for lazy-loaded type extensions Exclude files based on path before applying the sorting fixed composer.json [Console] fix phpdoc of DialogHelper [Translation][Dumper] added XLIFF 2.0 support. [XLIFF 2.0] added support for target attributes. apply some fixes. update changelog. [Translation][Loader] added XLIFF 2.0 support. Allowed extensions to inline compiler passes Conflicts: UPGRADE-2.8.md src/Symfony/Component/Console/Helper/DialogHelper.php src/Symfony/Component/Form/composer.json
This commit is contained in:
commit
8ad2c38a9f
@ -644,7 +644,7 @@
|
||||
<th>{{ option }}</th>
|
||||
<td>{{ value }}</td>
|
||||
<td>
|
||||
{% if data.resolved_options[option] is sameas(value) %}
|
||||
{% if data.resolved_options[option] is same as(value) %}
|
||||
<em class="font-normal text-muted">same as passed value</em>
|
||||
{% else %}
|
||||
{{ data.resolved_options[option] }}
|
||||
|
@ -357,7 +357,6 @@ tr.status-warning td {
|
||||
{# Layout
|
||||
========================================================================= #}
|
||||
.container {
|
||||
min-width: 960px;
|
||||
max-width: 1300px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* A pass to automatically process extensions if they implement
|
||||
* CompilerPassInterface.
|
||||
*
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class ExtensionCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
foreach ($container->getExtensions() as $extension) {
|
||||
if (!$extension instanceof CompilerPassInterface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$extension->process($container);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,6 +45,7 @@ class PassConfig
|
||||
$this->mergePass = new MergeExtensionConfigurationPass();
|
||||
|
||||
$this->optimizationPasses = array(
|
||||
new ExtensionCompilerPass(),
|
||||
new ResolveDefinitionTemplatesPass(),
|
||||
new DecoratorServicePass(),
|
||||
new ResolveParameterPlaceHoldersPass(),
|
||||
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\ExtensionCompilerPass;
|
||||
|
||||
/**
|
||||
* @author Wouter J <wouter@wouterj.nl>
|
||||
*/
|
||||
class ExtensionCompilerPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $container;
|
||||
private $pass;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||
$this->pass = new ExtensionCompilerPass();
|
||||
}
|
||||
|
||||
public function testProcess()
|
||||
{
|
||||
$extension1 = $this->createExtensionMock(true);
|
||||
$extension1->expects($this->once())->method('process');
|
||||
$extension2 = $this->createExtensionMock(false);
|
||||
$extension3 = $this->createExtensionMock(false);
|
||||
$extension4 = $this->createExtensionMock(true);
|
||||
$extension4->expects($this->once())->method('process');
|
||||
|
||||
$this->container->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array($extension1, $extension2, $extension3, $extension4)))
|
||||
;
|
||||
|
||||
$this->pass->process($this->container);
|
||||
}
|
||||
|
||||
private function createExtensionMock($hasInlineCompile)
|
||||
{
|
||||
return $this->getMock('Symfony\Component\DependencyInjection\\'.(
|
||||
$hasInlineCompile
|
||||
? 'Compiler\CompilerPassInterface'
|
||||
: 'Extension\ExtensionInterface'
|
||||
));
|
||||
}
|
||||
}
|
@ -31,10 +31,13 @@ class PhpAdapter extends AbstractAdapter
|
||||
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
|
||||
}
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator(
|
||||
new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
|
||||
\RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
$iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
|
||||
|
||||
if ($this->exclude) {
|
||||
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
||||
}
|
||||
|
||||
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
|
||||
$iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
|
||||
@ -44,10 +47,6 @@ class PhpAdapter extends AbstractAdapter
|
||||
$iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
|
||||
}
|
||||
|
||||
if ($this->exclude) {
|
||||
$iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
|
||||
}
|
||||
|
||||
if ($this->names || $this->notNames) {
|
||||
$iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
|
||||
}
|
||||
@ -68,15 +67,15 @@ class PhpAdapter extends AbstractAdapter
|
||||
$iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
|
||||
}
|
||||
|
||||
if ($this->paths || $this->notPaths) {
|
||||
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
|
||||
}
|
||||
|
||||
if ($this->sort) {
|
||||
$iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
|
||||
$iterator = $iteratorAggregate->getIterator();
|
||||
}
|
||||
|
||||
if ($this->paths || $this->notPaths) {
|
||||
$iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
|
||||
}
|
||||
|
||||
return $iterator;
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,9 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ExcludeDirectoryFilterIterator extends FilterIterator
|
||||
class ExcludeDirectoryFilterIterator extends FilterIterator implements \RecursiveIterator
|
||||
{
|
||||
private $isRecursive;
|
||||
private $patterns = array();
|
||||
|
||||
/**
|
||||
@ -28,6 +29,7 @@ class ExcludeDirectoryFilterIterator extends FilterIterator
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $directories)
|
||||
{
|
||||
$this->isRecursive = $iterator instanceof \RecursiveIterator;
|
||||
foreach ($directories as $directory) {
|
||||
$this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#';
|
||||
}
|
||||
@ -52,4 +54,17 @@ class ExcludeDirectoryFilterIterator extends FilterIterator
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasChildren()
|
||||
{
|
||||
return $this->isRecursive && $this->getInnerIterator()->hasChildren();
|
||||
}
|
||||
|
||||
public function getChildren()
|
||||
{
|
||||
$children = new self($this->getInnerIterator()->getChildren(), array());
|
||||
$children->patterns = $this->patterns;
|
||||
|
||||
return $children;
|
||||
}
|
||||
}
|
||||
|
28
src/Symfony/Component/Finder/Tests/BsdFinderTest.php
Normal file
28
src/Symfony/Component/Finder/Tests/BsdFinderTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Finder\Tests;
|
||||
|
||||
use Symfony\Component\Finder\Adapter\BsdFindAdapter;
|
||||
|
||||
class BsdFinderTest extends FinderTest
|
||||
{
|
||||
protected function getAdapter()
|
||||
{
|
||||
$adapter = new BsdFindAdapter();
|
||||
|
||||
if (!$adapter->isSupported()) {
|
||||
$this->markTestSkipped(get_class($adapter).' is not supported.');
|
||||
}
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
}
|
@ -11,8 +11,10 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Tests;
|
||||
|
||||
use Symfony\Component\Finder\Adapter\AdapterInterface;
|
||||
use Symfony\Component\Finder\Adapter\GnuFindAdapter;
|
||||
use Symfony\Component\Finder\Adapter\PhpAdapter;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\Adapter;
|
||||
|
||||
class FinderTest extends Iterator\RealIteratorTestCase
|
||||
{
|
||||
@ -21,109 +23,94 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertInstanceOf('Symfony\Component\Finder\Finder', Finder::create());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testDirectories($adapter)
|
||||
public function testDirectories()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->directories());
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->directories();
|
||||
$finder->files();
|
||||
$finder->directories();
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'toto')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testFiles($adapter)
|
||||
public function testFiles()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->files());
|
||||
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->files();
|
||||
$finder->directories();
|
||||
$finder->files();
|
||||
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'test.py', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testDepth($adapter)
|
||||
public function testDepth()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->depth('< 1'));
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->depth('<= 0'));
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->depth('>= 1'));
|
||||
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->depth('< 1')->depth('>= 1');
|
||||
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testName($adapter)
|
||||
public function testName()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->name('*.php'));
|
||||
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name('test.ph*');
|
||||
$finder->name('test.py');
|
||||
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name('~^test~i');
|
||||
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name('~\\.php$~i');
|
||||
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name('test.p{hp,y}');
|
||||
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testNotName($adapter)
|
||||
public function testNotName()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->notName('*.php'));
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->notName('*.php');
|
||||
$finder->notName('*.py');
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name('test.ph*');
|
||||
$finder->name('test.py');
|
||||
$finder->notName('*.php');
|
||||
$finder->notName('*.py');
|
||||
$this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name('test.ph*');
|
||||
$finder->name('test.py');
|
||||
$finder->notName('*.p{hp,y}');
|
||||
@ -133,228 +120,186 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
/**
|
||||
* @dataProvider getRegexNameTestData
|
||||
*/
|
||||
public function testRegexName($adapter, $regex)
|
||||
public function testRegexName($regex)
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->name($regex);
|
||||
$this->assertIterator($this->toAbsolute(array('test.py', 'test.php')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSize($adapter)
|
||||
public function testSize()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->files()->size('< 1K')->size('> 500'));
|
||||
$this->assertIterator($this->toAbsolute(array('test.php')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testDate($adapter)
|
||||
public function testDate()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->files()->date('until last month'));
|
||||
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testExclude($adapter)
|
||||
public function testExclude()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->exclude('foo'));
|
||||
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testIgnoreVCS($adapter)
|
||||
public function testIgnoreVCS()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->ignoreVCS(false)->ignoreDotFiles(false));
|
||||
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->ignoreVCS(false)->ignoreVCS(false)->ignoreDotFiles(false);
|
||||
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
$this->assertIterator($this->toAbsolute(array('.git', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->ignoreVCS(true)->ignoreDotFiles(false));
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testIgnoreDotFiles($adapter)
|
||||
public function testIgnoreDotFiles()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
|
||||
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
|
||||
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', '.foo/bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'toto/.git', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSortByName($adapter)
|
||||
public function testSortByName()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->sortByName());
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSortByType($adapter)
|
||||
public function testSortByType()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->sortByType());
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'toto', 'foo/bar.tmp', 'test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSortByAccessedTime($adapter)
|
||||
public function testSortByAccessedTime()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->sortByAccessedTime());
|
||||
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSortByChangedTime($adapter)
|
||||
public function testSortByChangedTime()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->sortByChangedTime());
|
||||
$this->assertIterator($this->toAbsolute(array('toto', 'test.py', 'test.php', 'foo/bar.tmp', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSortByModifiedTime($adapter)
|
||||
public function testSortByModifiedTime()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->sortByModifiedTime());
|
||||
$this->assertIterator($this->toAbsolute(array('foo/bar.tmp', 'test.php', 'toto', 'test.py', 'foo', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testSort($adapter)
|
||||
public function testSort()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->sort(function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }));
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo bar', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testFilter($adapter)
|
||||
public function testFilter()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->filter(function (\SplFileInfo $f) { return false !== strpos($f, 'test'); }));
|
||||
$this->assertIterator($this->toAbsolute(array('test.php', 'test.py')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testFollowLinks($adapter)
|
||||
public function testFollowLinks()
|
||||
{
|
||||
if ('\\' == DIRECTORY_SEPARATOR) {
|
||||
return;
|
||||
$this->markTestSkipped('symlinks are not supported on Windows');
|
||||
}
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertSame($finder, $finder->followLinks());
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto', 'foo bar')), $finder->in(self::$tmpDir)->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testIn($adapter)
|
||||
public function testIn()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
try {
|
||||
$finder->in('foobar');
|
||||
$this->fail('->in() throws a \InvalidArgumentException if the directory does not exist');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('InvalidArgumentException', $e, '->in() throws a \InvalidArgumentException if the directory does not exist');
|
||||
}
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();
|
||||
|
||||
$this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php'), $iterator);
|
||||
$expected = array(
|
||||
self::$tmpDir.DIRECTORY_SEPARATOR.'test.php',
|
||||
__DIR__.DIRECTORY_SEPARATOR.'BsdFinderTest.php',
|
||||
__DIR__.DIRECTORY_SEPARATOR.'FinderTest.php',
|
||||
__DIR__.DIRECTORY_SEPARATOR.'GnuFinderTest.php',
|
||||
__DIR__.DIRECTORY_SEPARATOR.'GlobTest.php',
|
||||
);
|
||||
|
||||
$this->assertIterator($expected, $iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInWithGlob($adapter)
|
||||
public function testInWithNonExistentDirectory()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = new Finder();
|
||||
$finder->in('foobar');
|
||||
}
|
||||
|
||||
public function testInWithGlob()
|
||||
{
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(array(__DIR__.'/Fixtures/*/B/C', __DIR__.'/Fixtures/*/*/B/C'))->getIterator();
|
||||
|
||||
$this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInWithNonDirectoryGlob($adapter)
|
||||
public function testInWithNonDirectoryGlob()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = new Finder();
|
||||
$finder->in(__DIR__.'/Fixtures/A/a*');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testInWithGlobBrace($adapter)
|
||||
public function testInWithGlobBrace()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(array(__DIR__.'/Fixtures/{A,copy/A}/B/C'))->getIterator();
|
||||
|
||||
$this->assertIterator($this->toAbsoluteFixtures(array('A/B/C/abc.dat', 'copy/A/B/C/abc.dat.copy')), $finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testGetIterator($adapter)
|
||||
public function testGetIteratorWithoutIn()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
try {
|
||||
$finder->getIterator();
|
||||
$this->fail('->getIterator() throws a \LogicException if the in() method has not been called');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertInstanceOf('LogicException', $e, '->getIterator() throws a \LogicException if the in() method has not been called');
|
||||
}
|
||||
$finder = Finder::create();
|
||||
$finder->getIterator();
|
||||
}
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
public function testGetIterator()
|
||||
{
|
||||
$finder = $this->buildFinder();
|
||||
$dirs = array();
|
||||
foreach ($finder->directories()->in(self::$tmpDir) as $dir) {
|
||||
$dirs[] = (string) $dir;
|
||||
@ -367,22 +312,19 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
|
||||
$this->assertEquals($expected, $dirs, 'implements the \IteratorAggregate interface');
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$this->assertEquals(2, iterator_count($finder->directories()->in(self::$tmpDir)), 'implements the \IteratorAggregate interface');
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$a = iterator_to_array($finder->directories()->in(self::$tmpDir));
|
||||
$a = array_values(array_map(function ($a) { return (string) $a; }, $a));
|
||||
sort($a);
|
||||
$this->assertEquals($expected, $a, 'implements the \IteratorAggregate interface');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testRelativePath($adapter)
|
||||
public function testRelativePath()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter)->in(self::$tmpDir);
|
||||
$finder = $this->buildFinder()->in(self::$tmpDir);
|
||||
|
||||
$paths = array();
|
||||
|
||||
@ -398,12 +340,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertEquals($ref, $paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testRelativePathname($adapter)
|
||||
public function testRelativePathname()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter)->in(self::$tmpDir)->sortByName();
|
||||
$finder = $this->buildFinder()->in(self::$tmpDir)->sortByName();
|
||||
|
||||
$paths = array();
|
||||
|
||||
@ -419,15 +358,12 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertEquals($ref, $paths);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testAppendWithAFinder($adapter)
|
||||
public function testAppendWithAFinder()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
|
||||
|
||||
$finder1 = $this->buildFinder($adapter);
|
||||
$finder1 = $this->buildFinder();
|
||||
$finder1->directories()->in(self::$tmpDir);
|
||||
|
||||
$finder = $finder->append($finder1);
|
||||
@ -435,12 +371,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testAppendWithAnArray($adapter)
|
||||
public function testAppendWithAnArray()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->files()->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
|
||||
|
||||
$finder->append($this->toAbsolute(array('foo', 'toto')));
|
||||
@ -448,20 +381,14 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testAppendReturnsAFinder($adapter)
|
||||
public function testAppendReturnsAFinder()
|
||||
{
|
||||
$this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', $this->buildFinder($adapter)->append(array()));
|
||||
$this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', Finder::create()->append(array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testAppendDoesNotRequireIn($adapter)
|
||||
public function testAppendDoesNotRequireIn()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo');
|
||||
|
||||
$finder1 = Finder::create()->append($finder);
|
||||
@ -505,9 +432,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
/**
|
||||
* @dataProvider getContainsTestData
|
||||
*/
|
||||
public function testContains($adapter, $matchPatterns, $noMatchPatterns, $expected)
|
||||
public function testContains($matchPatterns, $noMatchPatterns, $expected)
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')
|
||||
->name('*.txt')->sortByName()
|
||||
->contains($matchPatterns)
|
||||
@ -516,12 +443,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testContainsOnDirectory(Adapter\AdapterInterface $adapter)
|
||||
public function testContainsOnDirectory()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(__DIR__)
|
||||
->directories()
|
||||
->name('Fixtures')
|
||||
@ -529,12 +453,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertIterator(array(), $finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testNotContainsOnDirectory(Adapter\AdapterInterface $adapter)
|
||||
public function testNotContainsOnDirectory()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(__DIR__)
|
||||
->directories()
|
||||
->name('Fixtures')
|
||||
@ -547,10 +468,8 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
* with inner FilesystemIterator in an invalid state.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
*
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testMultipleLocations(Adapter\AdapterInterface $adapter)
|
||||
public function testMultipleLocations()
|
||||
{
|
||||
$locations = array(
|
||||
self::$tmpDir.'/',
|
||||
@ -558,36 +477,57 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
);
|
||||
|
||||
// it is expected that there are test.py test.php in the tmpDir
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in($locations)->depth('< 1')->name('test.php');
|
||||
|
||||
$this->assertCount(1, $finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator keys must be the file pathname.
|
||||
* Searching in multiple locations with sub directories involves
|
||||
* AppendIterator which does an unnecessary rewind which leaves
|
||||
* FilterIterator with inner FilesystemIterator in an invalid state.
|
||||
*
|
||||
* @dataProvider getAdaptersTestData
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
*/
|
||||
public function testIteratorKeys(Adapter\AdapterInterface $adapter)
|
||||
public function testMultipleLocationsWithSubDirectories()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter)->in(self::$tmpDir);
|
||||
$locations = array(
|
||||
__DIR__.'/Fixtures/one',
|
||||
self::$tmpDir.DIRECTORY_SEPARATOR.'toto',
|
||||
);
|
||||
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in($locations)->depth('< 10')->name('*.neon');
|
||||
|
||||
$expected = array(
|
||||
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
|
||||
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
|
||||
);
|
||||
|
||||
$this->assertIterator($expected, $finder);
|
||||
$this->assertIteratorInForeach($expected, $finder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator keys must be the file pathname.
|
||||
*/
|
||||
public function testIteratorKeys()
|
||||
{
|
||||
$finder = $this->buildFinder()->in(self::$tmpDir);
|
||||
foreach ($finder as $key => $file) {
|
||||
$this->assertEquals($file->getPathname(), $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag(Adapter\AdapterInterface $adapter)
|
||||
public function testRegexSpecialCharsLocationWithPathRestrictionContainingStartFlag()
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'r+e.gex[c]a(r)s')
|
||||
->path('/^dir/');
|
||||
|
||||
$expected = array('r+e.gex[c]a(r)s'.DIRECTORY_SEPARATOR.'dir',
|
||||
'r+e.gex[c]a(r)s'.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'bar.dat',);
|
||||
'r+e.gex[c]a(r)s'.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'bar.dat',);
|
||||
$this->assertIterator($this->toAbsoluteFixtures($expected), $finder);
|
||||
}
|
||||
|
||||
@ -603,7 +543,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
|
||||
$this->assertEquals(
|
||||
array('c', 'e', 'a', 'd', 'b'),
|
||||
array_map(function (Adapter\AdapterInterface $adapter) {
|
||||
array_map(function (AdapterInterface $adapter) {
|
||||
return $adapter->getName();
|
||||
}, $finder->getAdapters())
|
||||
);
|
||||
@ -626,17 +566,9 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
$this->assertIterator($filenames, $finder->in(sys_get_temp_dir())->getIterator());
|
||||
}
|
||||
|
||||
public function getAdaptersTestData()
|
||||
{
|
||||
return array_map(
|
||||
function ($adapter) { return array($adapter); },
|
||||
$this->getValidAdapters()
|
||||
);
|
||||
}
|
||||
|
||||
public function getContainsTestData()
|
||||
{
|
||||
$tests = array(
|
||||
return array(
|
||||
array('', '', array()),
|
||||
array('foo', 'bar', array()),
|
||||
array('', 'foobar', array('dolor.txt', 'ipsum.txt', 'lorem.txt')),
|
||||
@ -648,26 +580,22 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
array('', 'lorem', array('dolor.txt', 'ipsum.txt')),
|
||||
array('ipsum dolor sit amet', '/^IPSUM/m', array('lorem.txt')),
|
||||
);
|
||||
|
||||
return $this->buildTestData($tests);
|
||||
}
|
||||
|
||||
public function getRegexNameTestData()
|
||||
{
|
||||
$tests = array(
|
||||
return array(
|
||||
array('~.+\\.p.+~i'),
|
||||
array('~t.*s~i'),
|
||||
);
|
||||
|
||||
return $this->buildTestData($tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestPathData
|
||||
*/
|
||||
public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, array $expected)
|
||||
public function testPath($matchPatterns, $noMatchPatterns, array $expected)
|
||||
{
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures')
|
||||
->path($matchPatterns)
|
||||
->notPath($noMatchPatterns);
|
||||
@ -679,20 +607,20 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
{
|
||||
// test that by default, PhpAdapter is selected
|
||||
$adapters = Finder::create()->getAdapters();
|
||||
$this->assertTrue($adapters[0] instanceof Adapter\PhpAdapter);
|
||||
$this->assertTrue($adapters[0] instanceof PhpAdapter);
|
||||
|
||||
// test another adapter selection
|
||||
$adapters = Finder::create()->setAdapter('gnu_find')->getAdapters();
|
||||
$this->assertTrue($adapters[0] instanceof Adapter\GnuFindAdapter);
|
||||
$this->assertTrue($adapters[0] instanceof GnuFindAdapter);
|
||||
|
||||
// test that useBestAdapter method removes selection
|
||||
$adapters = Finder::create()->useBestAdapter()->getAdapters();
|
||||
$this->assertFalse($adapters[0] instanceof Adapter\PhpAdapter);
|
||||
$this->assertFalse($adapters[0] instanceof PhpAdapter);
|
||||
}
|
||||
|
||||
public function getTestPathData()
|
||||
{
|
||||
$tests = array(
|
||||
return array(
|
||||
array('', '', array()),
|
||||
array('/^A\/B\/C/', '/C$/',
|
||||
array('A'.DIRECTORY_SEPARATOR.'B'.DIRECTORY_SEPARATOR.'C'.DIRECTORY_SEPARATOR.'abc.dat'),
|
||||
@ -733,20 +661,15 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->buildTestData($tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testAccessDeniedException(Adapter\AdapterInterface $adapter)
|
||||
public function testAccessDeniedException()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('chmod is not supported on Windows');
|
||||
}
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->files()->in(self::$tmpDir);
|
||||
|
||||
// make 'foo' directory non-readable
|
||||
@ -776,16 +699,13 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getAdaptersTestData
|
||||
*/
|
||||
public function testIgnoredAccessDeniedException(Adapter\AdapterInterface $adapter)
|
||||
public function testIgnoredAccessDeniedException()
|
||||
{
|
||||
if ('\\' === DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('chmod is not supported on Windows');
|
||||
}
|
||||
|
||||
$finder = $this->buildFinder($adapter);
|
||||
$finder = $this->buildFinder();
|
||||
$finder->files()->ignoreUnreadableDirs()->in(self::$tmpDir);
|
||||
|
||||
// make 'foo' directory non-readable
|
||||
@ -805,62 +725,18 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
}
|
||||
}
|
||||
|
||||
private function buildTestData(array $tests)
|
||||
/**
|
||||
* @return AdapterInterface
|
||||
*/
|
||||
protected function getAdapter()
|
||||
{
|
||||
$data = array();
|
||||
foreach ($this->getValidAdapters() as $adapter) {
|
||||
foreach ($tests as $test) {
|
||||
$data[] = array_merge(array($adapter), $test);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
return new PhpAdapter();
|
||||
}
|
||||
|
||||
private function buildFinder(Adapter\AdapterInterface $adapter)
|
||||
private function buildFinder()
|
||||
{
|
||||
return Finder::create()
|
||||
->removeAdapters()
|
||||
->addAdapter($adapter);
|
||||
}
|
||||
|
||||
private function getValidAdapters()
|
||||
{
|
||||
return array_filter(
|
||||
array(
|
||||
new Adapter\BsdFindAdapter(),
|
||||
new Adapter\GnuFindAdapter(),
|
||||
new Adapter\PhpAdapter(),
|
||||
),
|
||||
function (Adapter\AdapterInterface $adapter) {
|
||||
return $adapter->isSupported();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searching in multiple locations with sub directories involves
|
||||
* AppendIterator which does an unnecessary rewind which leaves
|
||||
* FilterIterator with inner FilesystemIterator in an invalid state.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
*/
|
||||
public function testMultipleLocationsWithSubDirectories()
|
||||
{
|
||||
$locations = array(
|
||||
__DIR__.'/Fixtures/one',
|
||||
self::$tmpDir.DIRECTORY_SEPARATOR.'toto',
|
||||
);
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->in($locations)->depth('< 10')->name('*.neon');
|
||||
|
||||
$expected = array(
|
||||
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
|
||||
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
|
||||
);
|
||||
|
||||
$this->assertIterator($expected, $finder);
|
||||
$this->assertIteratorInForeach($expected, $finder);
|
||||
->addAdapter($this->getAdapter());
|
||||
}
|
||||
}
|
||||
|
28
src/Symfony/Component/Finder/Tests/GnuFinderTest.php
Normal file
28
src/Symfony/Component/Finder/Tests/GnuFinderTest.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Finder\Tests;
|
||||
|
||||
use Symfony\Component\Finder\Adapter\GnuFindAdapter;
|
||||
|
||||
class GnuFinderTest extends FinderTest
|
||||
{
|
||||
protected function getAdapter()
|
||||
{
|
||||
$adapter = new GnuFindAdapter();
|
||||
|
||||
if (!$adapter->isSupported()) {
|
||||
$this->markTestSkipped(get_class($adapter).' is not supported.');
|
||||
}
|
||||
|
||||
return $adapter;
|
||||
}
|
||||
}
|
@ -39,6 +39,7 @@ class DateRangeFilterIteratorTest extends RealIteratorTestCase
|
||||
'foo/bar.tmp',
|
||||
'test.php',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'.bar',
|
||||
'.foo',
|
||||
'.foo/.bar',
|
||||
@ -51,6 +52,7 @@ class DateRangeFilterIteratorTest extends RealIteratorTestCase
|
||||
'test.py',
|
||||
'foo',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'.bar',
|
||||
'.foo',
|
||||
'.foo/.bar',
|
||||
|
@ -50,6 +50,7 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
|
||||
'foo/bar.tmp',
|
||||
'test.php',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'.foo',
|
||||
'.foo/.bar',
|
||||
'.bar',
|
||||
@ -58,12 +59,14 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
|
||||
);
|
||||
|
||||
$graterThanOrEqualTo1 = array(
|
||||
'toto/.git',
|
||||
'foo/bar.tmp',
|
||||
'.foo/.bar',
|
||||
'.foo/bar',
|
||||
);
|
||||
|
||||
$equalTo1 = array(
|
||||
'toto/.git',
|
||||
'foo/bar.tmp',
|
||||
'.foo/.bar',
|
||||
'.foo/bar',
|
||||
|
@ -39,6 +39,7 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
|
||||
'test.py',
|
||||
'test.php',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'foo bar',
|
||||
);
|
||||
|
||||
@ -53,6 +54,7 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
|
||||
'foo/bar.tmp',
|
||||
'test.php',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'foo bar',
|
||||
);
|
||||
|
||||
|
@ -43,6 +43,7 @@ class FileTypeFilterIteratorTest extends RealIteratorTestCase
|
||||
'.git',
|
||||
'foo',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'.foo',
|
||||
);
|
||||
|
||||
|
@ -16,7 +16,7 @@ abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
|
||||
protected function assertIterator($expected, \Traversable $iterator)
|
||||
{
|
||||
// set iterator_to_array $use_key to false to avoid values merge
|
||||
// this made FinderTest::testAppendWithAnArray() failed with GnuFinderAdapter
|
||||
// this made FinderTest::testAppendWithAnArray() fail with GnuFinderAdapter
|
||||
$values = array_map(function (\SplFileInfo $fileinfo) { return str_replace('/', DIRECTORY_SEPARATOR, $fileinfo->getPathname()); }, iterator_to_array($iterator, false));
|
||||
|
||||
$expected = array_map(function ($path) { return str_replace('/', DIRECTORY_SEPARATOR, $path); }, $expected);
|
||||
|
@ -31,6 +31,7 @@ abstract class RealIteratorTestCase extends IteratorTestCase
|
||||
'foo/bar.tmp',
|
||||
'test.php',
|
||||
'toto/',
|
||||
'toto/.git/',
|
||||
'foo bar',
|
||||
);
|
||||
|
||||
|
@ -36,6 +36,7 @@ class SizeRangeFilterIteratorTest extends RealIteratorTestCase
|
||||
'foo',
|
||||
'test.php',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
);
|
||||
|
||||
return array(
|
||||
|
@ -85,6 +85,7 @@ class SortableIteratorTest extends RealIteratorTestCase
|
||||
'test.php',
|
||||
'test.py',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
);
|
||||
|
||||
$sortByType = array(
|
||||
@ -92,6 +93,7 @@ class SortableIteratorTest extends RealIteratorTestCase
|
||||
'.git',
|
||||
'foo',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'.bar',
|
||||
'.foo/.bar',
|
||||
'.foo/bar',
|
||||
@ -113,6 +115,7 @@ class SortableIteratorTest extends RealIteratorTestCase
|
||||
'test.php',
|
||||
'test.py',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
);
|
||||
|
||||
$sortByAccessedTime = array(
|
||||
@ -127,6 +130,7 @@ class SortableIteratorTest extends RealIteratorTestCase
|
||||
'test.py',
|
||||
'foo',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'foo bar',
|
||||
),
|
||||
// This file was accessed after sleeping for 1 sec
|
||||
@ -143,6 +147,7 @@ class SortableIteratorTest extends RealIteratorTestCase
|
||||
'foo',
|
||||
'foo/bar.tmp',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'foo bar',
|
||||
),
|
||||
array('test.php'),
|
||||
@ -159,6 +164,7 @@ class SortableIteratorTest extends RealIteratorTestCase
|
||||
'foo',
|
||||
'foo/bar.tmp',
|
||||
'toto',
|
||||
'toto/.git',
|
||||
'foo bar',
|
||||
),
|
||||
array('test.php'),
|
||||
|
@ -19,6 +19,7 @@ CHANGELOG
|
||||
* deprecated the "cascade_validation" option in favor of setting "constraints"
|
||||
with the Valid constraint
|
||||
* moved data trimming logic of TrimListener into StringUtil
|
||||
* [BC BREAK] When registering a type extension through the DI extension, the tag alias has to match the actual extended type.
|
||||
|
||||
2.7.0
|
||||
-----
|
||||
|
@ -68,7 +68,18 @@ class DependencyInjectionExtension implements FormExtensionInterface
|
||||
|
||||
if (isset($this->typeExtensionServiceIds[$name])) {
|
||||
foreach ($this->typeExtensionServiceIds[$name] as $serviceId) {
|
||||
$extensions[] = $this->container->get($serviceId);
|
||||
$extensions[] = $extension = $this->container->get($serviceId);
|
||||
|
||||
// validate result of getExtendedType() to ensure it is consistent with the service definition
|
||||
if ($extension->getExtendedType() !== $name) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".',
|
||||
$serviceId,
|
||||
$name,
|
||||
$extension->getExtendedType()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Tests\Extension\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension;
|
||||
|
||||
class DependencyInjectionExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGetTypeExtensions()
|
||||
{
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
|
||||
$typeExtension1 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
$typeExtension1->expects($this->any())
|
||||
->method('getExtendedType')
|
||||
->willReturn('test');
|
||||
$typeExtension2 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
$typeExtension2->expects($this->any())
|
||||
->method('getExtendedType')
|
||||
->willReturn('test');
|
||||
$typeExtension3 = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
$typeExtension3->expects($this->any())
|
||||
->method('getExtendedType')
|
||||
->willReturn('other');
|
||||
|
||||
$services = array(
|
||||
'extension1' => $typeExtension1,
|
||||
'extension2' => $typeExtension2,
|
||||
'extension3' => $typeExtension3,
|
||||
);
|
||||
|
||||
$container->expects($this->any())
|
||||
->method('get')
|
||||
->willReturnCallback(function ($id) use ($services) {
|
||||
if (isset($services[$id])) {
|
||||
return $services[$id];
|
||||
}
|
||||
|
||||
throw new ServiceNotFoundException($id);
|
||||
});
|
||||
|
||||
$extension = new DependencyInjectionExtension($container, array(), array('test' => array('extension1', 'extension2'), 'other' => array('extension3')), array());
|
||||
|
||||
$this->assertTrue($extension->hasTypeExtensions('test'));
|
||||
$this->assertFalse($extension->hasTypeExtensions('unknown'));
|
||||
$this->assertSame(array($typeExtension1, $typeExtension2), $extension->getTypeExtensions('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testThrowExceptionForInvalidExtendedType()
|
||||
{
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
|
||||
$typeExtension = $this->getMock('Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
$typeExtension->expects($this->any())
|
||||
->method('getExtendedType')
|
||||
->willReturn('unmatched');
|
||||
|
||||
$container->expects($this->any())
|
||||
->method('get')
|
||||
->with('extension')
|
||||
->willReturn($typeExtension);
|
||||
|
||||
$extension = new DependencyInjectionExtension($container, array(), array('test' => array('extension')), array());
|
||||
|
||||
$extension->getTypeExtensions('test');
|
||||
}
|
||||
}
|
@ -9,9 +9,11 @@ CHANGELOG
|
||||
2.8.0
|
||||
-----
|
||||
|
||||
* deprecated FileDumper::format(), overwrite FileDumper::formatCatalogue() instead.
|
||||
* deprecated Translator::getMessages(), rely on TranslatorBagInterface::getCatalogue() instead.
|
||||
* added option `json_encoding` to JsonFileDumper
|
||||
* added options `as_tree`, `inline` to YamlFileDumper
|
||||
* added support for XLIFF 2.0.
|
||||
* added support for XLIFF target and tool attributes.
|
||||
* added message parameters to DataCollectorTranslator.
|
||||
* [DEPRECATION] The `DiffOperation` class has been deprecated and
|
||||
|
@ -27,6 +27,16 @@ class CsvFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$handle = fopen('php://memory', 'rb+');
|
||||
|
||||
|
@ -99,6 +99,8 @@ abstract class FileDumper implements DumperInterface
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method will replace the format method in 3.0. You should overwritten it instead of overwriting format instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->format($messages, $domain);
|
||||
}
|
||||
|
||||
@ -109,6 +111,8 @@ abstract class FileDumper implements DumperInterface
|
||||
* @param string $domain
|
||||
*
|
||||
* @return string representation
|
||||
*
|
||||
* @deprecated since version 2.8, to be removed in 3.0. Overwrite formatCatalogue() instead.
|
||||
*/
|
||||
abstract protected function format(MessageCatalogue $messages, $domain);
|
||||
|
||||
|
@ -29,6 +29,16 @@ class IcuResFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$data = $indexes = $resources = '';
|
||||
|
||||
|
@ -24,6 +24,16 @@ class IniFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = '';
|
||||
|
||||
|
@ -25,6 +25,8 @@ class JsonFileDumper extends FileDumper
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,16 @@ class MoFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
|
||||
$offsets = array();
|
||||
|
@ -24,6 +24,16 @@ class PhpFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
|
||||
|
||||
|
@ -24,6 +24,16 @@ class PoFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = 'msgid ""'."\n";
|
||||
$output .= 'msgstr ""'."\n";
|
||||
|
@ -24,6 +24,16 @@ class QtFileDumper extends FileDumper
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'utf-8');
|
||||
$dom->formatOutput = true;
|
||||
|
@ -25,12 +25,47 @@ class XliffFileDumper extends FileDumper
|
||||
*/
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$xliffVersion = '1.2';
|
||||
if (array_key_exists('xliff_version', $options)) {
|
||||
$xliffVersion = $options['xliff_version'];
|
||||
}
|
||||
|
||||
if (array_key_exists('default_locale', $options)) {
|
||||
$defaultLocale = $options['default_locale'];
|
||||
} else {
|
||||
$defaultLocale = \Locale::getDefault();
|
||||
}
|
||||
|
||||
if ('1.2' === $xliffVersion) {
|
||||
return $this->dumpXliff1($defaultLocale, $messages, $domain, $options);
|
||||
}
|
||||
if ('2.0' === $xliffVersion) {
|
||||
return $this->dumpXliff2($defaultLocale, $messages, $domain, $options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExtension()
|
||||
{
|
||||
return 'xlf';
|
||||
}
|
||||
|
||||
private function dumpXliff1($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$toolInfo = array('tool-id' => 'symfony', 'tool-name' => 'Symfony');
|
||||
if (array_key_exists('tool_info', $options)) {
|
||||
$toolInfo = array_merge($toolInfo, $options['tool_info']);
|
||||
@ -103,20 +138,46 @@ class XliffFileDumper extends FileDumper
|
||||
return $dom->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
$dom = new \DOMDocument('1.0', 'utf-8');
|
||||
$dom->formatOutput = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExtension()
|
||||
{
|
||||
return 'xlf';
|
||||
$xliff = $dom->appendChild($dom->createElement('xliff'));
|
||||
$xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:2.0');
|
||||
$xliff->setAttribute('version', '2.0');
|
||||
$xliff->setAttribute('srcLang', str_replace('_', '-', $defaultLocale));
|
||||
$xliff->setAttribute('trgLang', str_replace('_', '-', $messages->getLocale()));
|
||||
|
||||
$xliffFile = $xliff->appendChild($dom->createElement('file'));
|
||||
$xliffFile->setAttribute('id', $domain.'.'.$messages->getLocale());
|
||||
|
||||
foreach ($messages->all($domain) as $source => $target) {
|
||||
$translation = $dom->createElement('unit');
|
||||
$translation->setAttribute('id', md5($source));
|
||||
|
||||
$segment = $translation->appendChild($dom->createElement('segment'));
|
||||
|
||||
$s = $segment->appendChild($dom->createElement('source'));
|
||||
$s->appendChild($dom->createTextNode($source));
|
||||
|
||||
// Does the target contain characters requiring a CDATA section?
|
||||
$text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
|
||||
|
||||
$targetElement = $dom->createElement('target');
|
||||
$metadata = $messages->getMetadata($source, $domain);
|
||||
if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) {
|
||||
foreach ($metadata['target-attributes'] as $name => $value) {
|
||||
$targetElement->setAttribute($name, $value);
|
||||
}
|
||||
}
|
||||
$t = $segment->appendChild($targetElement);
|
||||
$t->appendChild($text);
|
||||
|
||||
$xliffFile->appendChild($translation);
|
||||
}
|
||||
|
||||
return $dom->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,8 @@ class YamlFileDumper extends FileDumper
|
||||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
|
@ -41,10 +41,49 @@ class XliffFileLoader implements LoaderInterface
|
||||
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
|
||||
}
|
||||
|
||||
list($xml, $encoding) = $this->parseFile($resource);
|
||||
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
|
||||
|
||||
$catalogue = new MessageCatalogue($locale);
|
||||
$this->extract($resource, $catalogue, $domain);
|
||||
|
||||
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
|
||||
$catalogue->addResource(new FileResource($resource));
|
||||
}
|
||||
|
||||
return $catalogue;
|
||||
}
|
||||
|
||||
private function extract($resource, MessageCatalogue $catalogue, $domain)
|
||||
{
|
||||
try {
|
||||
$dom = XmlUtils::loadFile($resource);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $resource, $e->getMessage()), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$xliffVersion = $this->getVersionNumber($dom);
|
||||
$this->validateSchema($xliffVersion, $dom, $this->getSchema($xliffVersion));
|
||||
|
||||
if ('1.2' === $xliffVersion) {
|
||||
$this->extractXliff1($dom, $catalogue, $domain);
|
||||
}
|
||||
|
||||
if ('2.0' === $xliffVersion) {
|
||||
$this->extractXliff2($dom, $catalogue, $domain);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract messages and metadata from DOMDocument into a MessageCatalogue.
|
||||
*
|
||||
* @param \DOMDocument $dom Source to extract messages and metadata
|
||||
* @param MessageCatalogue $catalogue Catalogue where we'll collect messages and metadata
|
||||
* @param string $domain The domain
|
||||
*/
|
||||
private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
|
||||
{
|
||||
$xml = simplexml_import_dom($dom);
|
||||
$encoding = strtoupper($dom->encoding);
|
||||
|
||||
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
|
||||
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
||||
$attributes = $translation->attributes();
|
||||
|
||||
@ -64,17 +103,47 @@ class XliffFileLoader implements LoaderInterface
|
||||
$metadata['notes'] = $notes;
|
||||
}
|
||||
if (isset($translation->target) && $translation->target->attributes()) {
|
||||
$metadata['target-attributes'] = $translation->target->attributes();
|
||||
$metadata['target-attributes'] = array();
|
||||
foreach ($translation->target->attributes() as $key => $value) {
|
||||
$metadata['target-attributes'][$key] = (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
$catalogue->setMetadata((string) $source, $metadata, $domain);
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
|
||||
$catalogue->addResource(new FileResource($resource));
|
||||
/**
|
||||
* @param \DOMDocument $dom
|
||||
* @param MessageCatalogue $catalogue
|
||||
* @param string $domain
|
||||
*/
|
||||
private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
|
||||
{
|
||||
$xml = simplexml_import_dom($dom);
|
||||
$encoding = strtoupper($dom->encoding);
|
||||
|
||||
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
|
||||
|
||||
foreach ($xml->xpath('//xliff:unit/xliff:segment') as $segment) {
|
||||
$source = $segment->source;
|
||||
|
||||
// If the xlf file has another encoding specified, try to convert it because
|
||||
// simple_xml will always return utf-8 encoded values
|
||||
$target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding);
|
||||
|
||||
$catalogue->set((string) $source, $target, $domain);
|
||||
|
||||
$metadata = array();
|
||||
if (isset($segment->target) && $segment->target->attributes()) {
|
||||
$metadata['target-attributes'] = array();
|
||||
foreach ($segment->target->attributes() as $key => $value) {
|
||||
$metadata['target-attributes'][$key] = (string) $value;
|
||||
}
|
||||
}
|
||||
|
||||
$catalogue->setMetadata((string) $source, $metadata, $domain);
|
||||
}
|
||||
|
||||
return $catalogue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,42 +172,17 @@ class XliffFileLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and parses the given file into a SimpleXMLElement.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*
|
||||
* @return \SimpleXMLElement
|
||||
* @param string $file
|
||||
* @param \DOMDocument $dom
|
||||
* @param string $schema source of the schema
|
||||
*
|
||||
* @throws InvalidResourceException
|
||||
*/
|
||||
private function parseFile($file)
|
||||
private function validateSchema($file, \DOMDocument $dom, $schema)
|
||||
{
|
||||
try {
|
||||
$dom = XmlUtils::loadFile($file);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $file, $e->getMessage()), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$internalErrors = libxml_use_internal_errors(true);
|
||||
|
||||
$location = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
|
||||
$parts = explode('/', $location);
|
||||
if (0 === stripos($location, 'phar://')) {
|
||||
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
|
||||
if ($tmpfile) {
|
||||
copy($location, $tmpfile);
|
||||
$parts = explode('/', str_replace('\\', '/', $tmpfile));
|
||||
}
|
||||
}
|
||||
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
|
||||
$location = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
|
||||
|
||||
$source = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
|
||||
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
|
||||
|
||||
if (!@$dom->schemaValidateSource($source)) {
|
||||
if (!@$dom->schemaValidateSource($schema)) {
|
||||
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors))));
|
||||
}
|
||||
|
||||
@ -146,8 +190,46 @@ class XliffFileLoader implements LoaderInterface
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
}
|
||||
|
||||
return array(simplexml_import_dom($dom), strtoupper($dom->encoding));
|
||||
private function getSchema($xliffVersion)
|
||||
{
|
||||
if ('1.2' === $xliffVersion) {
|
||||
$schemaSource = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
|
||||
$xmlUri = 'http://www.w3.org/2001/xml.xsd';
|
||||
} elseif ('2.0' === $xliffVersion) {
|
||||
$schemaSource = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-2.0.xsd');
|
||||
$xmlUri = 'informativeCopiesOf3rdPartySchemas/w3c/xml.xsd';
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('No support implemented for loading XLIFF version "%s".', $xliffVersion));
|
||||
}
|
||||
|
||||
return $this->fixXmlLocation($schemaSource, $xmlUri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internally changes the URI of a dependent xsd to be loaded locally.
|
||||
*
|
||||
* @param string $schemaSource Current content of schema file
|
||||
* @param string $xmlUri External URI of XML to convert to local
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function fixXmlLocation($schemaSource, $xmlUri)
|
||||
{
|
||||
$newPath = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
|
||||
$parts = explode('/', $newPath);
|
||||
if (0 === stripos($newPath, 'phar://')) {
|
||||
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
|
||||
if ($tmpfile) {
|
||||
copy($newPath, $tmpfile);
|
||||
$parts = explode('/', str_replace('\\', '/', $tmpfile));
|
||||
}
|
||||
}
|
||||
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
|
||||
$newPath = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
|
||||
|
||||
return str_replace($xmlUri, $newPath, $schemaSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,6 +260,39 @@ class XliffFileLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets xliff file version based on the root "version" attribute.
|
||||
* Defaults to 1.2 for backwards compatibility.
|
||||
*
|
||||
* @param \DOMDocument $dom
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getVersionNumber(\DOMDocument $dom)
|
||||
{
|
||||
/** @var \DOMNode $xliff */
|
||||
foreach ($dom->getElementsByTagName('xliff') as $xliff) {
|
||||
$version = $xliff->attributes->getNamedItem('version');
|
||||
if ($version) {
|
||||
return $version->nodeValue;
|
||||
}
|
||||
|
||||
$namespace = $xliff->attributes->getNamedItem('xmlns');
|
||||
if ($namespace) {
|
||||
if (substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34) !== 0) {
|
||||
throw new \InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s"', $namespace));
|
||||
}
|
||||
|
||||
return substr($namespace, 34);
|
||||
}
|
||||
}
|
||||
|
||||
// Falls back to v1.2
|
||||
return '1.2';
|
||||
}
|
||||
|
||||
/*
|
||||
* @param \SimpleXMLElement|null $noteElement
|
||||
* @param string|null $encoding
|
||||
*
|
||||
|
@ -0,0 +1,411 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
XLIFF Version 2.0
|
||||
OASIS Standard
|
||||
05 August 2014
|
||||
Copyright (c) OASIS Open 2014. All rights reserved.
|
||||
Source: http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/schemas/
|
||||
-->
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="qualified"
|
||||
xmlns:xlf="urn:oasis:names:tc:xliff:document:2.0"
|
||||
targetNamespace="urn:oasis:names:tc:xliff:document:2.0">
|
||||
|
||||
<!-- Import -->
|
||||
|
||||
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
||||
schemaLocation="informativeCopiesOf3rdPartySchemas/w3c/xml.xsd"/>
|
||||
|
||||
<!-- Element Group -->
|
||||
|
||||
<xs:group name="inline">
|
||||
<xs:choice>
|
||||
<xs:element ref="xlf:cp"/>
|
||||
<xs:element ref="xlf:ph"/>
|
||||
<xs:element ref="xlf:pc"/>
|
||||
<xs:element ref="xlf:sc"/>
|
||||
<xs:element ref="xlf:ec"/>
|
||||
<xs:element ref="xlf:mrk"/>
|
||||
<xs:element ref="xlf:sm"/>
|
||||
<xs:element ref="xlf:em"/>
|
||||
</xs:choice>
|
||||
</xs:group>
|
||||
|
||||
<!-- Attribute Types -->
|
||||
|
||||
<xs:simpleType name="yesNo">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="yes"/>
|
||||
<xs:enumeration value="no"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="yesNoFirstNo">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="yes"/>
|
||||
<xs:enumeration value="firstNo"/>
|
||||
<xs:enumeration value="no"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="dirValue">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="ltr"/>
|
||||
<xs:enumeration value="rtl"/>
|
||||
<xs:enumeration value="auto"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="appliesTo">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="source"/>
|
||||
<xs:enumeration value="target"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="userDefinedValue">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[^\s:]+:[^\s:]+"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="attrType_type">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="fmt"/>
|
||||
<xs:enumeration value="ui"/>
|
||||
<xs:enumeration value="quote"/>
|
||||
<xs:enumeration value="link"/>
|
||||
<xs:enumeration value="image"/>
|
||||
<xs:enumeration value="other"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="typeForMrkValues">
|
||||
<xs:restriction base="xs:NMTOKEN">
|
||||
<xs:enumeration value="generic"/>
|
||||
<xs:enumeration value="comment"/>
|
||||
<xs:enumeration value="term"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="attrType_typeForMrk">
|
||||
<xs:union memberTypes="xlf:typeForMrkValues xlf:userDefinedValue"/>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="priorityValue">
|
||||
<xs:restriction base="xs:positiveInteger">
|
||||
<xs:minInclusive value="1"/>
|
||||
<xs:maxInclusive value="10"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="stateType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="initial"/>
|
||||
<xs:enumeration value="translated"/>
|
||||
<xs:enumeration value="reviewed"/>
|
||||
<xs:enumeration value="final"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<!-- Structural Elements -->
|
||||
|
||||
<xs:element name="xliff">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="1" maxOccurs="unbounded" ref="xlf:file"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="version" use="required"/>
|
||||
<xs:attribute name="srcLang" use="required"/>
|
||||
<xs:attribute name="trgLang" use="optional"/>
|
||||
<xs:attribute ref="xml:space" use="optional" default="default"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="file">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:skeleton"/>
|
||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||
processContents="lax"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:notes"/>
|
||||
<xs:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element ref="xlf:unit"/>
|
||||
<xs:element ref="xlf:group"/>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="original" use="optional"/>
|
||||
<xs:attribute name="translate" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="srcDir" use="optional" type="xlf:dirValue" default="auto"/>
|
||||
<xs:attribute name="trgDir" use="optional" type="xlf:dirValue" default="auto"/>
|
||||
<xs:attribute ref="xml:space" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="skeleton">
|
||||
<xs:complexType mixed="true">
|
||||
<xs:sequence>
|
||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||
processContents="lax"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="href" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="group">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||
processContents="lax"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:notes"/>
|
||||
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xs:element ref="xlf:unit"/>
|
||||
<xs:element ref="xlf:group"/>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="name" use="optional"/>
|
||||
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="srcDir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:attribute name="trgDir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:userDefinedValue"/>
|
||||
<xs:attribute ref="xml:space" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="unit">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||
processContents="lax"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:notes"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:originalData"/>
|
||||
<xs:choice minOccurs="1" maxOccurs="unbounded">
|
||||
<xs:element ref="xlf:segment"/>
|
||||
<xs:element ref="xlf:ignorable"/>
|
||||
</xs:choice>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="name" use="optional"/>
|
||||
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="srcDir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:attribute name="trgDir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:attribute ref="xml:space" use="optional"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:userDefinedValue"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="segment">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="1" maxOccurs="1" ref="xlf:source"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:target"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="state" use="optional" type="xlf:stateType" default="initial"/>
|
||||
<xs:attribute name="subState" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="ignorable">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="1" maxOccurs="1" ref="xlf:source"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:target"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="notes">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="1" maxOccurs="unbounded" ref="xlf:note"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="note">
|
||||
<xs:complexType mixed="true">
|
||||
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="appliesTo" use="optional" type="xlf:appliesTo"/>
|
||||
<xs:attribute name="category" use="optional"/>
|
||||
<xs:attribute name="priority" use="optional" type="xlf:priorityValue" default="1"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="originalData">
|
||||
<xs:complexType mixed="false">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="1" maxOccurs="unbounded" ref="xlf:data"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="data">
|
||||
<xs:complexType mixed="true">
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="xlf:cp"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dir" use="optional" type="xlf:dirValue" default="auto"/>
|
||||
<xs:attribute ref="xml:space" use="optional" fixed="preserve"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="source">
|
||||
<xs:complexType mixed="true">
|
||||
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:attribute ref="xml:lang" use="optional"/>
|
||||
<xs:attribute ref="xml:space" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="target">
|
||||
<xs:complexType mixed="true">
|
||||
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:attribute ref="xml:lang" use="optional"/>
|
||||
<xs:attribute ref="xml:space" use="optional"/>
|
||||
<xs:attribute name="order" use="optional" type="xs:positiveInteger"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<!-- Inline Elements -->
|
||||
|
||||
<xs:element name="cp">
|
||||
<!-- Code Point -->
|
||||
<xs:complexType mixed="false">
|
||||
<xs:attribute name="hex" use="required" type="xs:hexBinary"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="ph">
|
||||
<!-- Placeholder -->
|
||||
<xs:complexType mixed="false">
|
||||
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="disp" use="optional"/>
|
||||
<xs:attribute name="equiv" use="optional"/>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dataRef" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="subFlows" use="optional" type="xs:NMTOKENS"/>
|
||||
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="pc">
|
||||
<!-- Paired Code -->
|
||||
<xs:complexType mixed="true">
|
||||
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canOverlap" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dispEnd" use="optional"/>
|
||||
<xs:attribute name="dispStart" use="optional"/>
|
||||
<xs:attribute name="equivEnd" use="optional"/>
|
||||
<xs:attribute name="equivStart" use="optional"/>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dataRefEnd" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dataRefStart" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="subFlowsEnd" use="optional" type="xs:NMTOKENS"/>
|
||||
<xs:attribute name="subFlowsStart" use="optional" type="xs:NMTOKENS"/>
|
||||
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||
<xs:attribute name="dir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="sc">
|
||||
<!-- Start Code -->
|
||||
<xs:complexType mixed="false">
|
||||
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canOverlap" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dataRef" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:attribute name="disp" use="optional"/>
|
||||
<xs:attribute name="equiv" use="optional"/>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="isolated" use="optional" type="xlf:yesNo" default="no"/>
|
||||
<xs:attribute name="subFlows" use="optional" type="xs:NMTOKENS"/>
|
||||
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="ec">
|
||||
<!-- End Code -->
|
||||
<xs:complexType mixed="false">
|
||||
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canOverlap" use="optional" type="xlf:yesNo" default="yes"/>
|
||||
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dataRef" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="dir" use="optional" type="xlf:dirValue"/>
|
||||
<xs:attribute name="disp" use="optional"/>
|
||||
<xs:attribute name="equiv" use="optional"/>
|
||||
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="isolated" use="optional" type="xlf:yesNo" default="no"/>
|
||||
<xs:attribute name="startRef" use="optional" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="subFlows" use="optional" type="xs:NMTOKENS"/>
|
||||
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="mrk">
|
||||
<!-- Annotation Marker -->
|
||||
<xs:complexType mixed="true">
|
||||
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:attrType_typeForMrk"/>
|
||||
<xs:attribute name="ref" use="optional" type="xs:anyURI"/>
|
||||
<xs:attribute name="value" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="sm">
|
||||
<!-- Start Annotation Marker -->
|
||||
<xs:complexType mixed="false">
|
||||
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||
<xs:attribute name="type" use="optional" type="xlf:attrType_typeForMrk"/>
|
||||
<xs:attribute name="ref" use="optional" type="xs:anyURI"/>
|
||||
<xs:attribute name="value" use="optional"/>
|
||||
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="em">
|
||||
<!-- End Annotation Marker -->
|
||||
<xs:complexType mixed="false">
|
||||
<xs:attribute name="startRef" use="required" type="xs:NMTOKEN"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
</xs:schema>
|
@ -58,11 +58,16 @@ class FileDumperTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
class ConcreteFileDumper extends FileDumper
|
||||
{
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
protected function getExtension()
|
||||
{
|
||||
return 'concrete';
|
||||
|
@ -45,6 +45,27 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
|
||||
unlink($this->tempDir.'/messages.en_US.xlf');
|
||||
}
|
||||
|
||||
public function testDumpXliff2()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en_US');
|
||||
$catalogue->add(array(
|
||||
'foo' => 'bar',
|
||||
'key' => '',
|
||||
'key.with.cdata' => '<source> & <target>',
|
||||
));
|
||||
$catalogue->setMetadata('key', array('target-attributes' => array('order' => 1)));
|
||||
|
||||
$dumper = new XliffFileDumper();
|
||||
$dumper->dump($catalogue, array('path' => $this->tempDir, 'default_locale' => 'fr_FR', 'xliff_version' => '2.0'));
|
||||
|
||||
$this->assertEquals(
|
||||
file_get_contents(__DIR__.'/../fixtures/resources-2.0-clean.xlf'),
|
||||
file_get_contents($this->tempDir.'/messages.en_US.xlf')
|
||||
);
|
||||
|
||||
unlink($this->tempDir.'/messages.en_US.xlf');
|
||||
}
|
||||
|
||||
public function testDumpWithCustomToolInfo()
|
||||
{
|
||||
$options = array(
|
||||
|
@ -149,4 +149,22 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
// message with empty target
|
||||
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1'));
|
||||
}
|
||||
|
||||
public function testLoadVersion2()
|
||||
{
|
||||
$loader = new XliffFileLoader();
|
||||
$resource = __DIR__.'/../fixtures/resources-2.0.xlf';
|
||||
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||
$this->assertSame(array(), libxml_get_errors());
|
||||
|
||||
$domains = $catalogue->all();
|
||||
$this->assertCount(3, $domains['domain1']);
|
||||
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
||||
|
||||
// target attributes
|
||||
$this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1'));
|
||||
}
|
||||
}
|
||||
|
23
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf
vendored
Normal file
23
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US">
|
||||
<file id="messages.en_US">
|
||||
<unit id="acbd18db4cc2f85cedef654fccc4a4d8">
|
||||
<segment>
|
||||
<source>foo</source>
|
||||
<target>bar</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="3c6e0b8a9c15224a8228b9a98ca1531d">
|
||||
<segment>
|
||||
<source>key</source>
|
||||
<target order="1"></target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="18e6a493872558d949b4c16ea1fa6ab6">
|
||||
<segment>
|
||||
<source>key.with.cdata</source>
|
||||
<target><![CDATA[<source> & <target>]]></target>
|
||||
</segment>
|
||||
</unit>
|
||||
</file>
|
||||
</xliff>
|
25
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0.xlf
vendored
Normal file
25
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0.xlf
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="ja-JP">
|
||||
<file id="f1" original="Graphic Example.psd">
|
||||
<skeleton href="Graphic Example.psd.skl"/>
|
||||
<unit id="1">
|
||||
<segment>
|
||||
<source>Quetzal</source>
|
||||
<target>Quetzal</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<group id="1">
|
||||
<unit id="2">
|
||||
<segment>
|
||||
<source>foo</source>
|
||||
<target>XLIFF 文書を編集、または処理 するアプリケーションです。</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="3">
|
||||
<segment>
|
||||
<source>bar</source>
|
||||
<target order="1">XLIFF データ・マネージャ</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</group>
|
||||
</file>
|
||||
</xliff>
|
@ -50,7 +50,7 @@ class HtmlDumper extends CliDumper
|
||||
*/
|
||||
public function __construct($output = null, $charset = null)
|
||||
{
|
||||
parent::__construct($output, $charset);
|
||||
AbstractDumper::__construct($output, $charset);
|
||||
$this->dumpId = 'sf-dump-'.mt_rand();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user