merged 2.0

This commit is contained in:
Fabien Potencier 2012-03-15 15:47:03 +01:00
commit 7a54fe41ca
10 changed files with 72 additions and 43 deletions

View File

@ -146,7 +146,11 @@ class HttpKernel extends BaseHttpKernel
} }
} else { } else {
$options['attributes']['_controller'] = $controller; $options['attributes']['_controller'] = $controller;
$options['attributes']['_format'] = $request->getRequestFormat();
if (!isset($options['attributes']['_format'])) {
$options['attributes']['_format'] = $request->getRequestFormat();
}
$options['attributes']['_route'] = '_internal'; $options['attributes']['_route'] = '_internal';
$subRequest = $request->duplicate($options['query'], null, $options['attributes']); $subRequest = $request->duplicate($options['query'], null, $options['attributes']);
} }

View File

@ -277,7 +277,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
if (count($value) && !$this->ignoreExtraKeys) { if (count($value) && !$this->ignoreExtraKeys) {
$msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', array_keys($value)), $this->getPath()); $msg = sprintf('Unrecognized options "%s" under "%s"', implode(', ', array_keys($value)), $this->getPath());
$ex = new InvalidConfigurationException($msg); $ex = new InvalidConfigurationException($msg);
$ex->setPath($this->getPath().'.'.reset($value)); $ex->setPath($this->getPath());
throw $ex; throw $ex;
} }

View File

@ -310,6 +310,19 @@ class Command
return $this->definition; return $this->definition;
} }
/**
* Gets the InputDefinition to be used to create XML and Text representations of this Command.
*
* Can be overridden to provide the original command representation when it would otherwise
* be changed by merging with the application InputDefinition.
*
* @return InputDefinition An InputDefinition instance
*/
protected function getNativeDefinition()
{
return $this->getDefinition();
}
/** /**
* Adds an argument. * Adds an argument.
* *
@ -543,7 +556,7 @@ class Command
$messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $this->getAliases()).'</info>'; $messages[] = '<comment>Aliases:</comment> <info>'.implode(', ', $this->getAliases()).'</info>';
} }
$messages[] = $this->definition->asText(); $messages[] = $this->getNativeDefinition()->asText();
if ($help = $this->getProcessedHelp()) { if ($help = $this->getProcessedHelp()) {
$messages[] = '<comment>Help:</comment>'; $messages[] = '<comment>Help:</comment>';
@ -584,7 +597,7 @@ class Command
$aliasXML->appendChild($dom->createTextNode($alias)); $aliasXML->appendChild($dom->createTextNode($alias));
} }
$definition = $this->definition->asXml(true); $definition = $this->getNativeDefinition()->asXml(true);
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('arguments')->item(0), true)); $commandXML->appendChild($dom->importNode($definition->getElementsByTagName('arguments')->item(0), true));
$commandXML->appendChild($dom->importNode($definition->getElementsByTagName('options')->item(0), true)); $commandXML->appendChild($dom->importNode($definition->getElementsByTagName('options')->item(0), true));

View File

@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output; use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
/** /**
* ListCommand displays the list of all available commands for the application. * ListCommand displays the list of all available commands for the application.
@ -31,11 +32,7 @@ class ListCommand extends Command
protected function configure() protected function configure()
{ {
$this $this
->setDefinition(array( ->setDefinition($this->createDefinition())
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list')
))
->setName('list') ->setName('list')
->setDescription('Lists commands') ->setDescription('Lists commands')
->setHelp(<<<EOF ->setHelp(<<<EOF
@ -58,6 +55,14 @@ EOF
); );
} }
/**
* {@inheritdoc}
*/
protected function getNativeDefinition()
{
return $this->createDefinition();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -69,4 +74,13 @@ EOF
$output->writeln($this->getApplication()->asText($input->getArgument('namespace'), $input->getOption('raw'))); $output->writeln($this->getApplication()->asText($input->getArgument('namespace'), $input->getOption('raw')));
} }
} }
private function createDefinition()
{
return new InputDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
));
}
} }

View File

@ -73,7 +73,9 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
} }
try { try {
$dateTime = new \DateTime(sprintf("@%s %s", $value, $this->outputTimezone)); $dateTime = new \DateTime();
$dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
$dateTime->setTimestamp($value);
if ($this->inputTimezone !== $this->outputTimezone) { if ($this->inputTimezone !== $this->outputTimezone) {
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone)); $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));

View File

@ -16,7 +16,6 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder; use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\ReversedTransformer; use Symfony\Component\Form\ReversedTransformer;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain; use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
@ -41,10 +40,6 @@ class DateTimeType extends AbstractType
$timeParts[] = 'second'; $timeParts[] = 'second';
} }
if ($options['date_widget'] !== $options['time_widget']) {
throw new FormException(sprintf('Options "date_widget" and "time_widget" need to be identical. Used: "date_widget" = "%s" and "time_widget" = "%s".', $options['date_widget'] ?: 'choice', $options['time_widget'] ?: 'choice'));
}
if ('single_text' === $options['widget']) { if ('single_text' === $options['widget']) {
$builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format)); $builder->appendClientTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['user_timezone'], $format));
} else { } else {

View File

@ -32,7 +32,7 @@ interface CacheInterface
* *
* @param string $class Class Name * @param string $class Class Name
* *
* @return ClassMetadata * @return ClassMetadata|false A ClassMetadata instance or false on miss
*/ */
function read($class); function read($class);

View File

@ -74,6 +74,28 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
} }
} }
return $this->loadedClasses[$class]; if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
return $this->loadedClasses[$class];
}
$metadata = new ClassMetadata($class);
// Include constraints from the parent class
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
$metadata->mergeConstraints($this->getClassMetadata($parent->getName()));
}
// Include constraints from all implemented interfaces
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
$metadata->mergeConstraints($this->getClassMetadata($interface->getName()));
}
$this->loader->loadClassMetadata($metadata);
if ($this->cache !== null) {
$this->cache->write($metadata);
}
return $this->loadedClasses[$class] = $metadata;
} }
} }

View File

@ -193,27 +193,6 @@ class DateTimeTypeTest extends LocalizedTestCase
$this->assertEquals('2010-06-02 03:04:00', $form->getClientData()); $this->assertEquals('2010-06-02 03:04:00', $form->getClientData());
} }
/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
public function testDifferentWidgets()
{
$form = $this->factory->create('datetime', null, array(
'date_widget' => 'single_text',
'time_widget' => 'choice',
));
}
/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
public function testDefinedOnlyOneWidget()
{
$form = $this->factory->create('datetime', null, array(
'date_widget' => 'single_text',
));
}
public function testSubmit_differentPattern() public function testSubmit_differentPattern()
{ {
$form = $this->factory->create('datetime', null, array( $form = $this->factory->create('datetime', null, array(

View File

@ -74,8 +74,10 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
new ConstraintA(array('groups' => array('Default', 'EntityParent'))), new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
); );
$cache->expects($this->never())
->method('has');
$cache->expects($this->once()) $cache->expects($this->once())
->method('has') ->method('read')
->with($this->equalTo(self::PARENTCLASS)) ->with($this->equalTo(self::PARENTCLASS))
->will($this->returnValue(false)); ->will($this->returnValue(false));
$cache->expects($this->once()) $cache->expects($this->once())
@ -103,10 +105,8 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
$loader->expects($this->never()) $loader->expects($this->never())
->method('loadClassMetadata'); ->method('loadClassMetadata');
$cache->expects($this->once()) $cache->expects($this->never())
->method('has') ->method('has');
->with($this->equalTo(self::PARENTCLASS))
->will($this->returnValue(true));
$cache->expects($this->once()) $cache->expects($this->once())
->method('read') ->method('read')
->will($this->returnValue($metadata)); ->will($this->returnValue($metadata));