2012-07-01 07:52:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Form;
|
|
|
|
|
|
|
|
use Symfony\Component\Form\Util\PropertyPath;
|
2012-07-22 17:38:00 +00:00
|
|
|
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
|
2012-07-01 07:52:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A read-only form configuration.
|
|
|
|
*
|
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*/
|
2012-07-22 17:38:00 +00:00
|
|
|
class ImmutableFormConfig implements FormConfigInterface
|
2012-07-01 07:52:20 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
|
|
|
*/
|
|
|
|
private $dispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PropertyPath
|
|
|
|
*/
|
|
|
|
private $propertyPath;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $mapped;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $byReference;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $virtual;
|
|
|
|
|
2012-07-15 12:56:31 +00:00
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $compound;
|
|
|
|
|
2012-07-01 07:52:20 +00:00
|
|
|
/**
|
2012-07-16 19:40:19 +00:00
|
|
|
* @var ResolvedFormTypeInterface
|
2012-07-01 07:52:20 +00:00
|
|
|
*/
|
2012-07-16 19:40:19 +00:00
|
|
|
private $type;
|
2012-07-01 07:52:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
private $viewTransformers;
|
2012-07-01 07:52:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2012-07-15 12:56:31 +00:00
|
|
|
private $modelTransformers;
|
2012-07-01 07:52:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var DataMapperInterface
|
|
|
|
*/
|
|
|
|
private $dataMapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var FormValidatorInterface
|
|
|
|
*/
|
|
|
|
private $validators;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $required;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $disabled;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $errorBubbling;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
private $emptyData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $attributes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var mixed
|
|
|
|
*/
|
|
|
|
private $data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $dataClass;
|
|
|
|
|
2012-07-16 19:40:19 +00:00
|
|
|
/**
|
|
|
|
* @var Boolean
|
|
|
|
*/
|
|
|
|
private $dataLocked;
|
|
|
|
|
2012-07-01 07:52:20 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $options;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an unmodifiable copy of a given configuration.
|
|
|
|
*
|
|
|
|
* @param FormConfigInterface $config The configuration to copy.
|
|
|
|
*/
|
|
|
|
public function __construct(FormConfigInterface $config)
|
|
|
|
{
|
|
|
|
$dispatcher = $config->getEventDispatcher();
|
2012-07-22 17:38:00 +00:00
|
|
|
if (!$dispatcher instanceof ImmutableEventDispatcher) {
|
|
|
|
$dispatcher = new ImmutableEventDispatcher($dispatcher);
|
2012-07-01 07:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->dispatcher = $dispatcher;
|
|
|
|
$this->name = $config->getName();
|
|
|
|
$this->propertyPath = $config->getPropertyPath();
|
|
|
|
$this->mapped = $config->getMapped();
|
|
|
|
$this->byReference = $config->getByReference();
|
|
|
|
$this->virtual = $config->getVirtual();
|
2012-07-15 12:56:31 +00:00
|
|
|
$this->compound = $config->getCompound();
|
2012-07-16 19:40:19 +00:00
|
|
|
$this->type = $config->getType();
|
2012-07-15 12:56:31 +00:00
|
|
|
$this->viewTransformers = $config->getViewTransformers();
|
|
|
|
$this->modelTransformers = $config->getModelTransformers();
|
2012-07-01 07:52:20 +00:00
|
|
|
$this->dataMapper = $config->getDataMapper();
|
|
|
|
$this->validators = $config->getValidators();
|
|
|
|
$this->required = $config->getRequired();
|
|
|
|
$this->disabled = $config->getDisabled();
|
|
|
|
$this->errorBubbling = $config->getErrorBubbling();
|
|
|
|
$this->emptyData = $config->getEmptyData();
|
|
|
|
$this->attributes = $config->getAttributes();
|
|
|
|
$this->data = $config->getData();
|
|
|
|
$this->dataClass = $config->getDataClass();
|
2012-07-16 19:40:19 +00:00
|
|
|
$this->dataLocked = $config->getDataLocked();
|
2012-07-01 07:52:20 +00:00
|
|
|
$this->options = $config->getOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getEventDispatcher()
|
|
|
|
{
|
|
|
|
return $this->dispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getPropertyPath()
|
|
|
|
{
|
|
|
|
return $this->propertyPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getMapped()
|
|
|
|
{
|
|
|
|
return $this->mapped;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getByReference()
|
|
|
|
{
|
|
|
|
return $this->byReference;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getVirtual()
|
|
|
|
{
|
|
|
|
return $this->virtual;
|
|
|
|
}
|
|
|
|
|
2012-07-15 12:56:31 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getCompound()
|
|
|
|
{
|
|
|
|
return $this->compound;
|
|
|
|
}
|
|
|
|
|
2012-07-01 07:52:20 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2012-07-16 19:40:19 +00:00
|
|
|
public function getType()
|
2012-07-01 07:52:20 +00:00
|
|
|
{
|
2012-07-16 19:40:19 +00:00
|
|
|
return $this->type;
|
2012-07-01 07:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getViewTransformers()
|
|
|
|
{
|
2012-07-15 12:56:31 +00:00
|
|
|
return $this->viewTransformers;
|
2012-07-01 07:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getModelTransformers()
|
|
|
|
{
|
2012-07-15 12:56:31 +00:00
|
|
|
return $this->modelTransformers;
|
2012-07-01 07:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data mapper of the form.
|
|
|
|
*
|
|
|
|
* @return DataMapperInterface The data mapper.
|
|
|
|
*/
|
|
|
|
public function getDataMapper()
|
|
|
|
{
|
|
|
|
return $this->dataMapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getValidators()
|
|
|
|
{
|
|
|
|
return $this->validators;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getRequired()
|
|
|
|
{
|
|
|
|
return $this->required;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getDisabled()
|
|
|
|
{
|
|
|
|
return $this->disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getErrorBubbling()
|
|
|
|
{
|
|
|
|
return $this->errorBubbling;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getEmptyData()
|
|
|
|
{
|
|
|
|
return $this->emptyData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getAttributes()
|
|
|
|
{
|
|
|
|
return $this->attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function hasAttribute($name)
|
|
|
|
{
|
|
|
|
return isset($this->attributes[$name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getAttribute($name, $default = null)
|
|
|
|
{
|
|
|
|
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getData()
|
|
|
|
{
|
|
|
|
return $this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getDataClass()
|
|
|
|
{
|
|
|
|
return $this->dataClass;
|
|
|
|
}
|
|
|
|
|
2012-07-16 19:40:19 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getDataLocked()
|
|
|
|
{
|
|
|
|
return $this->dataLocked;
|
|
|
|
}
|
|
|
|
|
2012-07-01 07:52:20 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getOptions()
|
|
|
|
{
|
|
|
|
return $this->options;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function hasOption($name)
|
|
|
|
{
|
|
|
|
return isset($this->options[$name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getOption($name, $default = null)
|
|
|
|
{
|
|
|
|
return isset($this->options[$name]) ? $this->options[$name] : $default;
|
|
|
|
}
|
|
|
|
}
|