Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Translation][Extractor] Allow extracting an array of files besides e…
…xtracting a directory
- Loading branch information
1 parent
1a4d7d7
commit 9d6596c
Showing
11 changed files
with
219 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/Symfony/Bridge/Twig/Tests/Fixtures/extractor/with_translations.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>{{ 'Hi!'|trans }}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Symfony/Component/Translation/Extractor/AbstractFileExtractor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?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\Translation\Extractor; | ||
|
||
/** | ||
* Base class used by classes that extract translation messages from files. | ||
* | ||
* @author Marcos D. Sánchez <marcosdsanchez@gmail.com> | ||
*/ | ||
abstract class AbstractFileExtractor | ||
{ | ||
/** | ||
* @param string|array $resource files, a file or a directory | ||
* | ||
* @return array | ||
*/ | ||
protected function extractFiles($resource) | ||
{ | ||
if (is_array($resource) || $resource instanceof \Traversable) { | ||
$files = array(); | ||
foreach ($resource as $file) { | ||
if ($this->canBeExtracted($file)) { | ||
$files[] = $this->toSplFileInfo($file); | ||
} | ||
} | ||
} elseif (is_file($resource)) { | ||
$files = $this->canBeExtracted($resource) ? array($this->toSplFileInfo($resource)) : array(); | ||
} else { | ||
$files = $this->extractFromDirectory($resource); | ||
} | ||
|
||
return $files; | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* | ||
* @return \SplFileInfo | ||
*/ | ||
private function toSplFileInfo($file) | ||
{ | ||
return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file); | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* | ||
* @throws \InvalidArgumentException | ||
* | ||
* @return bool | ||
*/ | ||
protected function isFile($file) | ||
{ | ||
if (!is_file($file)) { | ||
throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $file)); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* | ||
* @return bool | ||
*/ | ||
abstract protected function canBeExtracted($file); | ||
|
||
/** | ||
* @param string|array $resource files, a file or a directory | ||
* | ||
* @return array files to be extracted | ||
*/ | ||
abstract protected function extractFromDirectory($resource); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters