This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

[PropertyAccess] Extracted PropertyAccess component out of Form

  • Loading branch information...
1 parent 6f00b5f commit 259b654bef07808d744a7788b2e98a60a8bbd37f @webmozart webmozart committed Jan 7, 2013
View
@@ -5,6 +5,9 @@ CHANGELOG
-----
* added a collection type for the I18n behavior
+ * added an optional PropertyAccessorInterface parameter to ModelType and
+ ModelChoiceList
+ * [BC BREAK] ModelType now has a constructor
2.1.0
-----
@@ -18,6 +18,7 @@
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\StringCastException;
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
+use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
/**
* Widely inspired by the EntityChoiceList.
@@ -69,16 +70,17 @@ class ModelChoiceList extends ObjectChoiceList
*
* @see Symfony\Bridge\Propel1\Form\Type\ModelType How to use the preferred choices.
*
- * @param string $class The FQCN of the model class to be loaded.
- * @param string $labelPath A property path pointing to the property used for the choice labels.
- * @param array $choices An optional array to use, rather than fetching the models.
- * @param ModelCriteria $queryObject The query to use retrieving model data from database.
- * @param string $groupPath A property path pointing to the property used to group the choices.
- * @param array|ModelCriteria $preferred The preferred items of this choice.
- * Either an array if $choices is given,
- * or a ModelCriteria to be merged with the $queryObject.
+ * @param string $class The FQCN of the model class to be loaded.
+ * @param string $labelPath A property path pointing to the property used for the choice labels.
+ * @param array $choices An optional array to use, rather than fetching the models.
+ * @param ModelCriteria $queryObject The query to use retrieving model data from database.
+ * @param string $groupPath A property path pointing to the property used to group the choices.
+ * @param array|ModelCriteria $preferred The preferred items of this choice.
+ * Either an array if $choices is given,
+ * or a ModelCriteria to be merged with the $queryObject.
+ * @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
*/
- public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null, $preferred = array())
+ public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null, $preferred = array(), PropertyAccessorInterface $propertyAccessor = null)
{
$this->class = $class;
@@ -104,7 +106,7 @@ public function __construct($class, $labelPath = null, $choices = null, $queryOb
$this->identifierAsIndex = true;
}
- parent::__construct($choices, $labelPath, $preferred, $groupPath);
+ parent::__construct($choices, $labelPath, $preferred, $groupPath, null, $propertyAccessor);
}
/**
View
@@ -12,6 +12,7 @@
namespace Symfony\Bridge\Propel1\Form;
use Symfony\Component\Form\AbstractExtension;
+use Symfony\Component\PropertyAccess\PropertyAccess;
/**
* Represents the Propel form extension, which loads the Propel functionality.
@@ -23,7 +24,7 @@ class PropelExtension extends AbstractExtension
protected function loadTypes()
{
return array(
- new Type\ModelType(),
+ new Type\ModelType(PropertyAccess::getPropertyAccessor()),
new Type\TranslationCollectionType(),
new Type\TranslationType()
);
View
@@ -17,6 +17,8 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+use Symfony\Component\PropertyAccess\PropertyAccess;
+use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
/**
* ModelType class.
@@ -48,6 +50,16 @@
*/
class ModelType extends AbstractType
{
+ /**
+ * @var PropertyAccessorInterface
+ */
+ private $propertyAccessor;
+
+ public function __construct(PropertyAccessorInterface $propertyAccessor = null)
+ {
+ $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::getPropertyAccessor();
+ }
+
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['multiple']) {
@@ -57,14 +69,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
- $choiceList = function (Options $options) {
+ $propertyAccessor = $this->propertyAccessor;
+
+ $choiceList = function (Options $options) use ($propertyAccessor) {
return new ModelChoiceList(
$options['class'],
$options['property'],
$options['choices'],
$options['query'],
$options['group_by'],
- $options['preferred_choices']
+ $options['preferred_choices'],
+ $propertyAccessor
);
};
@@ -26,6 +26,10 @@ protected function setUp()
if (!class_exists('Symfony\Component\Form\Form')) {
$this->markTestSkipped('The "Form" component is not available');
}
+
+ if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
+ $this->markTestSkipped('The "PropertyAccessor" component is not available');
+ }
}
public function testEmptyChoicesReturnsEmpty()

0 comments on commit 259b654

Please sign in to comment.