Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
CRAP
98.61% covered (success)
98.61%
71 / 72
PropertyAccessDecorator
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
36
98.61% covered (success)
98.61%
71 / 72
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getDecoratedFactory
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 createListFromChoices
100.00% covered (success)
100.00%
1 / 1
10
100.00% covered (success)
100.00%
16 / 16
 createListFromLoader
100.00% covered (success)
100.00%
1 / 1
10
100.00% covered (success)
100.00%
16 / 16
 createView
100.00% covered (success)
100.00%
1 / 1
13
100.00% covered (success)
100.00%
36 / 36
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Form\ChoiceList\Factory;
13
14use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
15use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
16use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
17use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
18use Symfony\Component\PropertyAccess\PropertyAccess;
19use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
20use Symfony\Component\PropertyAccess\PropertyPath;
21
22/**
23 * Adds property path support to a choice list factory.
24 *
25 * Pass the decorated factory to the constructor:
26 *
27 *     $decorator = new PropertyAccessDecorator($factory);
28 *
29 * You can now pass property paths for generating choice values, labels, view
30 * indices, HTML attributes and for determining the preferred choices and the
31 * choice groups:
32 *
33 *     // extract values from the $value property
34 *     $list = $createListFromChoices($objects, 'value');
35 *
36 * @author Bernhard Schussek <bschussek@gmail.com>
37 */
38class PropertyAccessDecorator implements ChoiceListFactoryInterface
39{
40    private $decoratedFactory;
41    private $propertyAccessor;
42
43    public function __construct(ChoiceListFactoryInterface $decoratedFactory, PropertyAccessorInterface $propertyAccessor = null)
44    {
45        $this->decoratedFactory = $decoratedFactory;
46        $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();