Skip to content

Commit

Permalink
Merge pull request #231 from doctrine/disable-deprecations
Browse files Browse the repository at this point in the history
deprecations warning only for new versions
  • Loading branch information
dbu committed Nov 12, 2015
2 parents 89c9f3a + bcaaf13 commit 3222283
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 65 deletions.
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ php:
- hhvm

env:
- SYMFONY_VERSION="~2.3||~3.0"
- SYMFONY_VERSION="2.7.*,>2.7.6"

sudo: false

matrix:
include:
- php: 5.3
env: SYMFONY_VERSION=2.3.* COMPOSER_FLAGS="--prefer-lowest"
- php: 5.5
env: SYMFONY_VERSION=2.3.*
- php: 5.5
env: SYMFONY_VERSION=2.6.*
- php: 5.5
env: SYMFONY_VERSION=2.7.*
- php: 5.5
env: SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: SYMFONY_VERSION=2.3.* SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=3.0.*
allow_failures:
- php: 5.6
env: SYMFONY_VERSION=3.0.*

before_install:
- composer self-update || true
Expand Down
52 changes: 32 additions & 20 deletions Form/PhpcrOdmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ class PhpcrOdmTypeGuesser implements FormTypeGuesserInterface

private $cache = array();

/**
* Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0.
*/
private $legacy = true;

/**
* Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0.
*/
private $entryTypeOption = 'type';

public function __construct(ManagerRegistry $registry, $typeGuess = array())
{
$this->registry = $registry;
$this->typeGuess = $typeGuess;
$this->legacy = !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
$this->entryTypeOption = $this->legacy ? 'type' : 'entry_type';
}

/**
Expand All @@ -61,7 +73,7 @@ public function __construct(ManagerRegistry $registry, $typeGuess = array())
public function guessType($class, $property)
{
if (!$ret = $this->getMetadata($class)) {
return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
return new TypeGuess($this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType', array(), Guess::LOW_CONFIDENCE);
}

/** @var ClassMetadata $metadata */
Expand All @@ -73,18 +85,18 @@ public function guessType($class, $property)

switch ($mapping['type']) {
case 'parent':
return new TypeGuess('phpcr_odm_path', array(), Guess::MEDIUM_CONFIDENCE);
return new TypeGuess($this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', array(), Guess::MEDIUM_CONFIDENCE);

case 'mixedreferrers':
$options = array(
'attr' => array('readonly' => 'readonly'),
'type' => 'phpcr_odm_path',
$this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType',
);

return new TypeGuess('collection', $options, Guess::LOW_CONFIDENCE);
return new TypeGuess($this->legacy ? 'collection' : 'Symfony\Component\Form\Extension\Core\Type\CollectionType', $options, Guess::LOW_CONFIDENCE);

case 'referrers':
return new TypeGuess('phpcr_document', array(
return new TypeGuess($this->legacy ? 'phpcr_document' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType', array(
'class' => $mapping['referringDocument'],
'multiple' => true,
),
Expand All @@ -100,29 +112,29 @@ public function guessType($class, $property)
$options['class'] = $mapping['targetDocument'];
}

return new TypeGuess('phpcr_document', $options, Guess::HIGH_CONFIDENCE);
return new TypeGuess($this->legacy ? 'phpcr_document' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\DocumentType', $options, Guess::HIGH_CONFIDENCE);

case 'child':
$options = array(
'attr' => array('readonly' => 'readonly'),
);

return new TypeGuess('phpcr_odm_path', $options, Guess::LOW_CONFIDENCE);
return new TypeGuess($this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType', $options, Guess::LOW_CONFIDENCE);

case 'children':
$options = array(
'attr' => array('readonly' => 'readonly'),
'type' => 'phpcr_odm_path',
$this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType',
);

return new TypeGuess('collection', $options, Guess::LOW_CONFIDENCE);
return new TypeGuess($this->legacy ? 'collection' : 'Symfony\Component\Form\Extension\Core\Type\CollectionType', $options, Guess::LOW_CONFIDENCE);

default:
return;
}
}

$mapping = $metadata->getField($property);
$mapping = $metadata->getFieldMapping($property);

if (!empty($mapping['assoc'])) {
if (isset($this->typeGuess['assoc'])) {
Expand All @@ -137,7 +149,7 @@ public function guessType($class, $property)
$options = array();
switch ($metadata->getTypeOfField($property)) {
case 'boolean':
$type = 'checkbox';
$type = $this->legacy ? 'checkbox' : 'Symfony\Component\Form\Extension\Core\Type\CheckboxType';
break;
case 'binary':
// the file type only works on documents like the File document,
Expand All @@ -147,43 +159,43 @@ public function guessType($class, $property)
// editing the phpcr node has no meaning
return;
case 'date':
$type = 'datetime';
$type = $this->legacy ? 'datetime' : 'Symfony\Component\Form\Extension\Core\Type\DateTimeType';
break;
case 'double':
$type = 'number';
$type = $this->legacy ? 'number' : 'Symfony\Component\Form\Extension\Core\Type\NumberType';
break;
case 'long':
case 'integer':
$type = 'integer';
$type = $this->legacy ? 'integer' : 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
break;
case 'string':
if ($metadata->isIdentifier($property)
|| $metadata->isUuid($property)
) {
$options['attr'] = array('readonly' => 'readonly');
}
$type = 'text';
$type = $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType';
break;
case 'nodename':
$type = 'text';
$type = $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType';
break;
case 'locale':
$locales = $documentManager->getLocaleChooserStrategy();
$type = 'choice';
$type = $this->legacy ? 'choice' : 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
$options['choices'] = array_combine($locales->getDefaultLocalesOrder(), $locales->getDefaultLocalesOrder());
break;
case 'versionname':
case 'versioncreated':
default:
$options['attr'] = array('readonly' => 'readonly');
$options['required'] = false;
$type = 'text';
$type = $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType';
break;
}

if (!empty($mapping['multivalue'])) {
$options['type'] = $type;
$type = 'collection';
$options[$this->entryTypeOption] = $type;
$type = $this->legacy ? 'collection' : 'Symfony\Component\Form\Extension\Core\Type\CollectionType';
}

if (!empty($mapping['translated'])) {
Expand Down
11 changes: 11 additions & 0 deletions Form/Type/DocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@ public function getLoader(ObjectManager $manager, $queryBuilder, $class)
);
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'phpcr_document';
}
Expand Down
25 changes: 24 additions & 1 deletion Form/Type/PHPCRReferenceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function __construct(SessionInterface $session)
$this->session = $session;
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch (strtolower($options['transformer_type'])) {
Expand All @@ -47,24 +50,44 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->addModelTransformer($transformer);
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'transformer_type' => 'uuid',
));
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return 'text';
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text';
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'phpcr_reference';
}
Expand Down
13 changes: 12 additions & 1 deletion Form/Type/PathType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@ public function __construct(ManagerRegistry $registry)

public function getParent()
{
return 'text';
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\TextType' : 'text';
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'phpcr_odm_path';
}
Expand Down
32 changes: 23 additions & 9 deletions Tests/Functional/Form/PHPCRTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Bundle\PHPCRBundle\Tests\Functional\Form;

use Doctrine\ODM\PHPCR\DocumentManager;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
use Doctrine\Bundle\PHPCRBundle\Tests\Resources\Document\TestDocument;
Expand All @@ -24,8 +25,21 @@ class PHPCRTypeGuesserTest extends BaseTestCase
*/
private $referrer;

/**
* Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0.
*/
private $legacy;

/**
* Work with 2.3-2.7 and 3.0 at the same time. drop once we switch to symfony 3.0.
*/
private $entryTypeOption;

public function setUp()
{
$this->legacy = !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
$this->entryTypeOption = $this->legacy ? 'type' : 'entry_type';

$this->db('PHPCR')->loadFixtures(array(
'Doctrine\Bundle\PHPCRBundle\Tests\Resources\DataFixtures\PHPCR\LoadData',
));
Expand All @@ -41,7 +55,7 @@ public function setUp()
*/
private function createFormBuilder($data, $options = array())
{
return $this->container->get('form.factory')->createBuilder('form', $data, $options);
return $this->container->get('form.factory')->createBuilder($this->legacy ? 'form' : 'Symfony\Component\Form\Extension\Core\Type\FormType', $data, $options);
}

public function testFields()
Expand Down Expand Up @@ -126,7 +140,7 @@ public function testMultivalueFields()
$formBuilder->get('mbool'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'checkbox',
$this->entryTypeOption => $this->legacy ? 'checkbox' : 'Symfony\Component\Form\Extension\Core\Type\CheckboxType',
'required' => false,
)
);
Expand All @@ -135,7 +149,7 @@ public function testMultivalueFields()
$formBuilder->get('mdate'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'datetime',
$this->entryTypeOption => $this->legacy ? 'datetime' : 'Symfony\Component\Form\Extension\Core\Type\DateTimeType',
'required' => false,
)
);
Expand All @@ -144,7 +158,7 @@ public function testMultivalueFields()
$formBuilder->get('mtext'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'text',
$this->entryTypeOption => $this->legacy ? 'text' : 'Symfony\Component\Form\Extension\Core\Type\TextType',
'required' => false,
)
);
Expand All @@ -153,7 +167,7 @@ public function testMultivalueFields()
$formBuilder->get('mnumber'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'number',
$this->entryTypeOption => $this->legacy ? 'number' : 'Symfony\Component\Form\Extension\Core\Type\NumberType',
'required' => false,
)
);
Expand All @@ -162,7 +176,7 @@ public function testMultivalueFields()
$formBuilder->get('minteger'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'integer',
$this->entryTypeOption => $this->legacy ? 'integer' : 'Symfony\Component\Form\Extension\Core\Type\IntegerType',
'required' => false,
)
);
Expand All @@ -171,7 +185,7 @@ public function testMultivalueFields()
$formBuilder->get('mlong'),
'\Symfony\Component\Form\Extension\Core\Type\CollectionType',
array(
'type' => 'integer',
$this->entryTypeOption => $this->legacy ? 'integer' : 'Symfony\Component\Form\Extension\Core\Type\IntegerType',
'required' => false,
)
);
Expand Down Expand Up @@ -241,7 +255,7 @@ public function testHierarchy()
array(
'attr' => array('readonly' => 'readonly'),
'required' => false,
'type' => 'phpcr_odm_path',
$this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType',
)
);

Expand Down Expand Up @@ -325,7 +339,7 @@ public function testReferrers()
array(
'attr' => array('readonly' => 'readonly'),
'required' => false,
'type' => 'phpcr_odm_path',
$this->entryTypeOption => $this->legacy ? 'phpcr_odm_path' : 'Doctrine\Bundle\PHPCRBundle\Form\Type\PathType',
)
);

Expand Down
Loading

0 comments on commit 3222283

Please sign in to comment.