This commit is contained in:
Fabien Potencier 2011-10-29 12:05:45 +02:00
parent 99a96d35b5
commit d34d50f0b0
34 changed files with 198 additions and 192 deletions

View File

@ -204,4 +204,4 @@ class DbalSessionStorage extends NativeSessionStorage
return true;
}
}
}

View File

@ -36,4 +36,4 @@ final class DbalSessionStorageSchema extends Schema
$table->addColumn('sess_time', 'integer')->setNotNull(true)->setUnsigned(true);
$table->setPrimaryKey(array('sess_id'));
}
}
}

View File

@ -37,6 +37,7 @@ class RouterApacheDumperCommand extends ContainerAwareCommand
if (!$router instanceof RouterInterface) {
return false;
}
return parent::isEnabled();
}

View File

@ -36,6 +36,7 @@ class RouterDebugCommand extends ContainerAwareCommand
if (!$router instanceof RouterInterface) {
return false;
}
return parent::isEnabled();
}

View File

@ -36,6 +36,7 @@ class RouterMatchCommand extends ContainerAwareCommand
if (!$router instanceof RouterInterface) {
return false;
}
return parent::isEnabled();
}

View File

@ -81,6 +81,7 @@ EOF
// check presence of force or dump-message
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
return;
}
@ -90,6 +91,7 @@ EOF
if (!in_array($input->getOption('output-format'), $supportedFormats)) {
$output->writeln('<error>Wrong output format</error>');
$output->writeln('Supported formats are '.implode(', ', $supportedFormats).'.');
return;
}

View File

@ -27,7 +27,7 @@ class TranslatorPass implements CompilerPassInterface
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
$loaders[$id] = $attributes[0]['alias'];
}
if ($container->hasDefinition('translation.loader')) {
$definition = $container->getDefinition('translation.loader');
foreach ($loaders as $id => $format) {

View File

@ -99,9 +99,9 @@
<service id="translation.extractor.php" class="%translation.extractor.php.class%">
<tag name="translation.extractor" alias="php" />
</service>
<service id="translation.loader" class="%translation.loader.class%"/>
<service id="translation.extractor" class="%translation.extractor.class%"/>
<service id="translation.writer" class="%translation.writer.class%"/>

View File

@ -23,10 +23,10 @@ class PhpExtractorTest extends TestCase
$extractor = new PhpExtractor();
$extractor->setPrefix('prefix');
$catalogue = new MessageCatalogue('en');
// Act
$extractor->extract(__DIR__.'/../Fixtures/Resources/views/', $catalogue);
// Assert
$this->assertEquals(1, count($catalogue->all('messages')), '->extract() should find 1 translation');
$this->assertTrue($catalogue->has('new key'), '->extract() should find at leat "new key" message');

View File

@ -17,14 +17,14 @@ use Symfony\Component\Translation\Extractor\ExtractorInterface;
/**
* PhpExtractor extracts translation messages from a php template.
*
*
* @author Michel Salib <michelsalib@hotmail.com>
*/
class PhpExtractor implements ExtractorInterface
{
const MESSAGE_TOKEN = 300;
const IGNORE_TOKEN = 400;
/**
* Prefix for new found message.
*
@ -34,8 +34,8 @@ class PhpExtractor implements ExtractorInterface
/**
* The sequence that captures translation messages.
*
* @var array
*
* @var array
*/
protected $sequences = array(
array(
@ -63,7 +63,7 @@ class PhpExtractor implements ExtractorInterface
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
}
}
/**
* {@inheritDoc}
*/
@ -74,24 +74,24 @@ class PhpExtractor implements ExtractorInterface
/**
* Normalizes a token.
*
*
* @param mixed $token
* @return string
* @return string
*/
protected function normalizeToken($token)
{
if (is_array($token)) {
return $token[1];
}
return $token;
}
/**
* Extracts trans message from php tokens.
*
*
* @param array $tokens
* @param MessageCatalogue $catalog
* @param MessageCatalogue $catalog
*/
protected function parseTokens($tokens, MessageCatalogue $catalog)
{
@ -112,7 +112,7 @@ class PhpExtractor implements ExtractorInterface
}
$message = trim($message, '\'');
if ($message) {
$catalog->set($message, $this->prefix.$message);
break;

View File

@ -384,6 +384,7 @@ class Application
if (!$command->isEnabled()) {
$command->setApplication(null);
return;
}

View File

@ -242,16 +242,16 @@ class ParameterBag
{
return (int) $this->get($key, $default, $deep);
}
/**
* Filter key.
*
*
* @param string $key Key.
* @param mixed $default Default = null.
* @param boolean $deep Default = false.
* @param integer $filter FILTER_* constant.
* @param mixed $options Filter options.
*
*
* @see http://php.net/manual/en/function.filter-var.php
*
* @return mixed
@ -259,17 +259,17 @@ class ParameterBag
public function filter($key, $default = null, $deep = false, $filter=FILTER_DEFAULT, $options=array())
{
$value = $this->get($key, $default, $deep);
// Always turn $options into an array - this allows filter_var option shortcuts.
if (!is_array($options) && $options) {
$options = array('flags' => $options);
}
// Add a convenience check for arrays.
if (is_array($value) && !isset($options['flags'])) {
$options['flags'] = FILTER_REQUIRE_ARRAY;
}
return filter_var($value, $filter, $options);
}
}

View File

@ -52,7 +52,7 @@ class CsvFileDumper extends FileDumper
$this->delimiter = $delimiter;
$this->enclosure = $enclosure;
}
/**
* {@inheritDoc}
*/

View File

@ -16,14 +16,14 @@ use Symfony\Component\Translation\MessageCatalogue;
/**
* FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
* Performs backup of already existing files.
*
*
* Options:
* - path (mandatory): the directory where the files should be saved
*
* @author Michel Salib <michelsalib@hotmail.com>
*/
abstract class FileDumper implements DumperInterface
{
{
/**
* {@inheritDoc}
*/
@ -32,7 +32,7 @@ abstract class FileDumper implements DumperInterface
if (!array_key_exists('path', $options)) {
throw new \InvalidArgumentException('The file dumper need a path options.');
}
// save a file for each domain
foreach ($messages->getDomains() as $domain) {
$file = $domain.'.'.$messages->getLocale().'.'.$this->getExtension();
@ -44,17 +44,17 @@ abstract class FileDumper implements DumperInterface
file_put_contents($options['path'].'/'.$file, $this->format($messages, $domain));
}
}
/**
* Transforms a domain of a message catalogue to its string representation.
*
*
* @return The string representation
*/
abstract protected function format(MessageCatalogue $messages, $domain);
/**
* Gets the file extension of the dumper.
*
*
* @return The file extension
*/
abstract protected function getExtension();

View File

@ -29,7 +29,7 @@ class PhpFileDumper extends FileDumper
return $output;
}
/**
* {@inheritDoc}
*/

View File

@ -39,7 +39,7 @@ class QtFileDumper extends FileDumper
return $dom->saveXML();
}
/**
* {@inheritDoc}
*/

View File

@ -49,7 +49,7 @@ class XliffFileDumper extends FileDumper
return $dom->saveXML();
}
/**
* {@inheritDoc}
*/

View File

@ -28,7 +28,7 @@ class YamlFileDumper extends FileDumper
{
return Yaml::dump($messages->all($domain));
}
/**
* {@inheritDoc}
*/

View File

@ -15,21 +15,21 @@ use Symfony\Component\Translation\MessageCatalogue;
/**
* ChainExtractor extracts translation messages from template files.
*
*
* @author Michel Salib <michelsalib@hotmail.com>
*/
class ChainExtractor implements ExtractorInterface
{
/**
* The extractors.
*
*
* @var array
*/
private $extractors = array();
/**
* Adds a loader to the translation extractor.
*
*
* @param string $format The format of the loader
* @param ExtractorInterface $extractor The loader
*/
@ -47,7 +47,7 @@ class ChainExtractor implements ExtractorInterface
$extractor->setPrefix($prefix);
}
}
/**
* {@inheritDoc}
*/

View File

@ -16,22 +16,22 @@ use Symfony\Component\Translation\MessageCatalogue;
/**
* Extracts translation messages from a template directory to the catalogue.
* New found messages are injected to the catalogue using the prefix.
*
*
* @author Michel Salib <michelsalib@hotmail.com>
*/
interface ExtractorInterface
{
/**
* Extracts translation messages from a template directory to the catalogue.
*
*
* @param string $directory The path to look into
* @param MessageCatalogue $catalogue The catalogue
*/
function extract($directory, MessageCatalogue $catalogue);
/**
* Sets the prefix that should be used for new found messages.
*
*
* @param string $prefix The prefix
*/
public function setPrefix($prefix);

View File

@ -82,4 +82,4 @@ class QtTranslationsLoader implements LoaderInterface
return $errors;
}
}
}

View File

@ -16,42 +16,42 @@ use Symfony\Component\Translation\Dumper\DumperInterface;
/**
* TranslationWriter writes translation messages.
*
*
* @author Michel Salib <michelsalib@hotmail.com>
*/
class TranslationWriter
{
/**
* Dumpers used for export.
*
*
* @var array
*/
private $dumpers = array();
/**
* Adds a dumper to the writer.
*
*
* @param string $format The format of the dumper
* @param DumperInterface $dumper The dumper
* @param DumperInterface $dumper The dumper
*/
public function addDumper($format, DumperInterface $dumper)
{
$this->dumpers[$format] = $dumper;
}
/**
* Obtains the list of supported formats.
*
* @return array
*
* @return array
*/
public function getFormats()
{
return array_keys($this->dumpers);
}
/**
* Writes translation from the catalogue according to the selected format.
*
*
* @param MessageCatalogue $catalogue The message catalogue to dump
* @param type $format The format to use to dump the messages
* @param array $options Options that are passed to the dumper
@ -61,7 +61,7 @@ class TranslationWriter
if (!isset($this->dumpers[$format])) {
throw new \InvalidArgumentException('There is no dumper associated with this format.');
}
// get the right dumper
$dumper = $this->dumpers[$format];

View File

@ -124,7 +124,7 @@ class FileValidator extends ConstraintValidator
$valid = true;
break;
}
}
}
}
if (false === $valid) {

View File

@ -1,113 +1,113 @@
<?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\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
* Validates whether a value is a valid image file and is valid
* against minWidth, maxWidth, minHeight and maxHeight constraints
*
* @author Benjamin Dulau <benjamin.dulau@gmail.com>
*/
class ImageValidator extends FileValidator
{
public function isValid($value, Constraint $constraint)
{
$isValid = parent::isValid($value, $constraint);
if (!$isValid) {
return false;
}
if (null === $value || '' === $value) {
return true;
}
if (null === $constraint->minWidth && null === $constraint->maxWidth
&& null === $constraint->minHeight && null === $constraint->maxHeight) {
return true;
}
$size = @getimagesize($value);
if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
$this->setMessage($constraint->sizeNotDetectedMessage);
return false;
}
$width = $size[0];
$height = $size[1];
if ($constraint->minWidth) {
if (!ctype_digit((string) $constraint->minWidth)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width', $constraint->minWidth));
}
if ($width < $constraint->minWidth) {
$this->setMessage($constraint->minWidthMessage, array(
'{{ width }}' => $width,
'{{ min_width }}' => $constraint->minWidth
));
return false;
}
}
if ($constraint->maxWidth) {
if (!ctype_digit((string) $constraint->maxWidth)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width', $constraint->maxWidth));
}
if ($width > $constraint->maxWidth) {
$this->setMessage($constraint->maxWidthMessage, array(
'{{ width }}' => $width,
'{{ max_width }}' => $constraint->maxWidth
));
return false;
}
}
if ($constraint->minHeight) {
if (!ctype_digit((string) $constraint->minHeight)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum height', $constraint->minHeight));
}
if ($height < $constraint->minHeight) {
$this->setMessage($constraint->minHeightMessage, array(
'{{ height }}' => $height,
'{{ min_height }}' => $constraint->minHeight
));
return false;
}
}
if ($constraint->maxHeight) {
if (!ctype_digit((string) $constraint->maxHeight)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum height', $constraint->maxHeight));
}
if ($height > $constraint->maxHeight) {
$this->setMessage($constraint->maxHeightMessage, array(
'{{ height }}' => $height,
'{{ max_height }}' => $constraint->maxHeight
));
return false;
}
}
return true;
}
}
<?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\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
* Validates whether a value is a valid image file and is valid
* against minWidth, maxWidth, minHeight and maxHeight constraints
*
* @author Benjamin Dulau <benjamin.dulau@gmail.com>
*/
class ImageValidator extends FileValidator
{
public function isValid($value, Constraint $constraint)
{
$isValid = parent::isValid($value, $constraint);
if (!$isValid) {
return false;
}
if (null === $value || '' === $value) {
return true;
}
if (null === $constraint->minWidth && null === $constraint->maxWidth
&& null === $constraint->minHeight && null === $constraint->maxHeight) {
return true;
}
$size = @getimagesize($value);
if (empty($size) || ($size[0] === 0) || ($size[1] === 0)) {
$this->setMessage($constraint->sizeNotDetectedMessage);
return false;
}
$width = $size[0];
$height = $size[1];
if ($constraint->minWidth) {
if (!ctype_digit((string) $constraint->minWidth)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width', $constraint->minWidth));
}
if ($width < $constraint->minWidth) {
$this->setMessage($constraint->minWidthMessage, array(
'{{ width }}' => $width,
'{{ min_width }}' => $constraint->minWidth
));
return false;
}
}
if ($constraint->maxWidth) {
if (!ctype_digit((string) $constraint->maxWidth)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width', $constraint->maxWidth));
}
if ($width > $constraint->maxWidth) {
$this->setMessage($constraint->maxWidthMessage, array(
'{{ width }}' => $width,
'{{ max_width }}' => $constraint->maxWidth
));
return false;
}
}
if ($constraint->minHeight) {
if (!ctype_digit((string) $constraint->minHeight)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum height', $constraint->minHeight));
}
if ($height < $constraint->minHeight) {
$this->setMessage($constraint->minHeightMessage, array(
'{{ height }}' => $height,
'{{ min_height }}' => $constraint->minHeight
));
return false;
}
}
if ($constraint->maxHeight) {
if (!ctype_digit((string) $constraint->maxHeight)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum height', $constraint->maxHeight));
}
if ($height > $constraint->maxHeight) {
$this->setMessage($constraint->maxHeightMessage, array(
'{{ height }}' => $height,
'{{ max_height }}' => $constraint->maxHeight
));
return false;
}
}
return true;
}
}

View File

@ -1 +1 @@
stub file that won't be parsed
stub file that won't be parsed

View File

@ -162,15 +162,15 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(123, $bag->getInt('digits'), '->getInt() gets a value of parameter as integer');
$this->assertEquals(0, $bag->getInt('unknown'), '->getInt() returns zero if a parameter is not defined');
}
/**
* @covers Symfony\Component\HttpFoundation\ParameterBag::filter
*/
public function testFilter()
{
$bag = new ParameterBag(array(
'digits' => '0123ab',
'email' => 'example@example.com',
'digits' => '0123ab',
'email' => 'example@example.com',
'url' => 'http://example.com/foo',
'dec' => '256',
'hex' => '0x100',
@ -178,28 +178,28 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
));
$this->assertEmpty($bag->filter('nokey'), '->filter() should return empty by default if no key is found');
$this->assertEquals('0123', $bag->filter('digits', '', false, FILTER_SANITIZE_NUMBER_INT), '->filter() gets a value of parameter as integer filtering out invalid characters');
$this->assertEquals('example@example.com', $bag->filter('email', '', false, FILTER_VALIDATE_EMAIL), '->filter() gets a value of parameter as email');
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', false, FILTER_VALIDATE_URL, array('flags' => FILTER_FLAG_PATH_REQUIRED)), '->filter() gets a value of parameter as url with a path');
// This test is repeated for code-coverage
$this->assertEquals('http://example.com/foo', $bag->filter('url', '', false, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED), '->filter() gets a value of parameter as url with a path');
$this->assertFalse($bag->filter('dec', '', false, FILTER_VALIDATE_INT, array(
'flags' => FILTER_FLAG_ALLOW_HEX,
'options' => array('min_range' => 1, 'max_range' => 0xff))
), '->filter() gets a value of parameter as integer between boundaries');
$this->assertFalse($bag->filter('hex', '', false, FILTER_VALIDATE_INT, array(
'flags' => FILTER_FLAG_ALLOW_HEX,
'options' => array('min_range' => 1, 'max_range' => 0xff))
), '->filter() gets a value of parameter as integer between boundaries');
$this->assertEquals(array('bang'), $bag->filter('array', '', false), '->filter() gets a value of parameter as an array');
}
}

View File

@ -27,7 +27,7 @@ foo', 'foo;foo' => 'bar'));
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/valid.csv'), file_get_contents($tempDir.'/messages.en.csv'));
unlink($tempDir.'/messages.en.csv');
}
}

View File

@ -26,7 +26,7 @@ class IniFileDumperTest extends \PHPUnit_Framework_TestCase
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ini'), file_get_contents($tempDir.'/messages.en.ini'));
unlink($tempDir.'/messages.en.ini');
}
}

View File

@ -26,7 +26,7 @@ class PhpFileDumperTest extends \PHPUnit_Framework_TestCase
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.php'), file_get_contents($tempDir.'/messages.en.php'));
unlink($tempDir.'/messages.en.php');
}
}

View File

@ -26,7 +26,7 @@ class QtFileDumperTest extends \PHPUnit_Framework_TestCase
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.ts'), file_get_contents($tempDir.'/resources.en.ts'));
unlink($tempDir.'/resources.en.ts');
}
}
}

View File

@ -26,7 +26,7 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.xliff'), file_get_contents($tempDir.'/messages.en.xliff'));
unlink($tempDir.'/messages.en.xliff');
}
}

View File

@ -26,7 +26,7 @@ class YamlFileDumperTest extends \PHPUnit_Framework_TestCase
$dumperString = $dumper->dump($catalogue, array('path' => $tempDir));
$this->assertEquals(file_get_contents(__DIR__.'/../fixtures/resources.yml'), file_get_contents($tempDir.'/messages.en.yml'));
unlink($tempDir.'/messages.en.yml');
}
}

View File

@ -19,4 +19,4 @@ abstract class LocalizedTestCase extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('The "intl" extension is not available');
}
}
}
}

View File

@ -160,4 +160,4 @@ class ImageValidatorTest extends \PHPUnit_Framework_TestCase
$this->validator->isValid($this->image, $constraint);
}
}
}