Permalink
Browse files

Update to be compatible with Symfony 2.3

The CRUD generator hasn't been updated yet. Just some minor fixes were made.
  • Loading branch information...
lanthaler committed Jun 6, 2013
1 parent c5ddd58 commit b8b73462662f8d113f3cebb3e5b22dc00d016ee7
Showing with 20 additions and 19 deletions.
  1. +7 −10 Command/GenerateDoctrineCrudCommand.php
  2. +4 −2 DatatypeNormalizer/DateTimeNormalizer.php
  3. +9 −7 Serializer/Serializer.php
@@ -39,7 +39,8 @@ protected function configure()
->setDefinition(array(
new InputOption('entity', '', InputOption::VALUE_REQUIRED, 'The entity class name to initialize (shortcut notation)'),
new InputOption('route-prefix', '', InputOption::VALUE_REQUIRED, 'The route prefix'),
new InputOption('with-write', '', InputOption::VALUE_NONE, 'Whether or not to generate create, new and delete actions')
new InputOption('with-write', '', InputOption::VALUE_NONE, 'Whether or not to generate create, new and delete actions'),
new InputOption('overwrite', '', InputOption::VALUE_NONE, 'Do not stop the generation if crud controller already exist, thus overwriting all generated files')
))
->setDescription('Generates a Hydra controller for a Doctrine entity supporting CRUD operations')
->setHelp(<<<EOT
@@ -83,15 +84,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$format = 'annotation';
$prefix = $this->getRoutePrefix($input, $entity);
$withWrite = $input->getOption('with-write');
$forceOverwrite = $input->getOption('overwrite');
$dialog->writeSection($output, 'CRUD generation');
$entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle).'\\'.$entity;
$entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle).'\\'.$entity;
$metadata = $this->getEntityMetadata($entityClass);
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
$generator = $this->getGenerator();
$generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite);
$generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite, $forceOverwrite);
$output->writeln('Generating the CRUD code: <info>OK</info>');
@@ -124,7 +126,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
list($bundle, $entity) = $this->parseShortcutNotation($entity);
// Entity exists?
$entityClass = $this->getContainer()->get('doctrine')->getEntityNamespace($bundle).'\\'.$entity;
$entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle).'\\'.$entity;
$metadata = $this->getEntityMetadata($entityClass);
// write?
@@ -160,17 +162,12 @@ protected function interact(InputInterface $input, OutputInterface $output)
));
}
protected function getGenerator()
protected function getGenerator($bundle = null)
{
if (null === $this->generator) {
$this->generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud');
}
return $this->generator;
}
public function setGenerator(SensioDoctrineCrudGenerator $generator)
{
$this->generator = $generator;
}
}
@@ -51,10 +51,11 @@ public function getTypeIri()
*
* @param object $object object to normalize
* @param string $format format the normalization result will be encoded as
* @param array $context Context options for the normalizer
*
* @return string
*/
public function normalize($object, $format = null)
public function normalize($object, $format = null, array $context = array())
{
$dt = clone $object;
$dt->setTimezone(new \DateTimeZone('UTC'));
@@ -81,12 +82,13 @@ public function supportsNormalization($data, $format = null)
* @param mixed $data data to restore
* @param string $class the expected class to instantiate
* @param string $format format the given data was extracted from
* @param array $context options available to the denormalizer
*
* @return DateTime
*
* @throws RuntimeException If the data can't be denormalized
*/
public function denormalize($data, $class, $format = null)
public function denormalize($data, $class, $format = null, array $context = array())
{
$value = $data;
@@ -10,7 +10,7 @@
namespace ML\HydraBundle\Serializer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Form\Util\PropertyPath;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
@@ -42,12 +42,13 @@ public function __construct(DocumentationGenerator $documentationGenerator, Rout
/**
* Serializes data in the appropriate format
*
* @param mixed $data any data
* @param string $format format name
* @param mixed $data any data
* @param string $format format name
* @param array $context options normalizers/encoders have access to
*
* @return string
*/
public function serialize($data, $format)
public function serialize($data, $format, array $context = array())
{
if ('jsonld' !== $format) {
throw new UnexpectedValueException('Serialization for the format ' . $format . ' is not supported');
@@ -220,10 +221,11 @@ private function doSerialize($data, $include = false)
* @param mixed $data
* @param string $type
* @param string $format
* @param array $context
*
* @return object
*/
public function deserialize($data, $type, $format)
public function deserialize($data, $type, $format, array $context = array())
{
if ('jsonld' !== $format) {
throw new UnexpectedValueException('Deserialization for the format ' . $format . ' is not supported');
@@ -331,8 +333,8 @@ private function doDeserialize($data, $entity)
// TODO Recurse!?
$propertyPath = new PropertyPath($definition['element']);
$propertyPath->setValue($entity, $node->getProperty($vocabBase . $definition['iri'])); // TODO Fix IRI construction
$accessor = PropertyAccess::createPropertyAccessor();
$accessor->setValue($entity, $definition['element'], $node->getProperty($vocabBase . $definition['iri'])); // TODO Fix IRI construction
//$this->setValue($data, $definition, $node->getProperty($vocabBase . $definition['iri_fragment']));

0 comments on commit b8b7346

Please sign in to comment.