Submit
Path:
~
/
/
opt
/
alt
/
php55
/
usr
/
share
/
pear
/
Symfony
/
Component
/
Form
/
File Content:
FormBuilder.php
<?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\Exception\BadMethodCallException; use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * A builder for creating {@link Form} instances. * * @author Bernhard Schussek <bschussek@gmail.com> */ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormBuilderInterface { /** * The children of the form builder. * * @var FormBuilderInterface[] */ private $children = array(); /** * The data of children who haven't been converted to form builders yet. * * @var array */ private $unresolvedChildren = array(); /** * Creates a new form builder. * * @param string $name * @param string $dataClass * @param EventDispatcherInterface $dispatcher * @param FormFactoryInterface $factory * @param array $options */ public function __construct($name, $dataClass, EventDispatcherInterface $dispatcher, FormFactoryInterface $factory, array $options = array()) { parent::__construct($name, $dataClass, $dispatcher, $options); $this->setFormFactory($factory); } /** * {@inheritdoc} */ public function add($child, $type = null, array $options = array()) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } if ($child instanceof self) { $this->children[$child->getName()] = $child; // In case an unresolved child with the same name exists unset($this->unresolvedChildren[$child->getName()]); return $this; } if (!is_string($child) && !is_int($child)) { throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormBuilder'); } if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) { throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\FormTypeInterface'); } // Add to "children" to maintain order $this->children[$child] = null; $this->unresolvedChildren[$child] = array( 'type' => $type, 'options' => $options, ); return $this; } /** * {@inheritdoc} */ public function create($name, $type = null, array $options = array()) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } if (null === $type && null === $this->getDataClass()) { $type = 'text'; } if (null !== $type) { return $this->getFormFactory()->createNamedBuilder($name, $type, null, $options); } return $this->getFormFactory()->createBuilderForProperty($this->getDataClass(), $name, null, $options); } /** * {@inheritdoc} */ public function get($name) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } if (isset($this->unresolvedChildren[$name])) { return $this->resolveChild($name); } if (isset($this->children[$name])) { return $this->children[$name]; } throw new InvalidArgumentException(sprintf('The child with the name "%s" does not exist.', $name)); } /** * {@inheritdoc} */ public function remove($name) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } unset($this->unresolvedChildren[$name]); if (array_key_exists($name, $this->children)) { unset($this->children[$name]); } return $this; } /** * {@inheritdoc} */ public function has($name) { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } if (isset($this->unresolvedChildren[$name])) { return true; } if (isset($this->children[$name])) { return true; } return false; } /** * {@inheritdoc} */ public function all() { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } $this->resolveChildren(); return $this->children; } /** * {@inheritdoc} */ public function count() { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } return count($this->children); } /** * {@inheritdoc} */ public function getFormConfig() { $config = parent::getFormConfig(); $config->children = array(); $config->unresolvedChildren = array(); return $config; } /** * {@inheritdoc} */ public function getForm() { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } $this->resolveChildren(); $form = new Form($this->getFormConfig()); foreach ($this->children as $child) { // Automatic initialization is only supported on root forms $form->add($child->setAutoInitialize(false)->getForm()); } if ($this->getAutoInitialize()) { // Automatically initialize the form if it is configured so $form->initialize(); } return $form; } /** * {@inheritdoc} */ public function getIterator() { if ($this->locked) { throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.'); } return new \ArrayIterator($this->children); } /** * Converts an unresolved child into a {@link FormBuilder} instance. * * @param string $name The name of the unresolved child. * * @return FormBuilder The created instance. */ private function resolveChild($name) { $info = $this->unresolvedChildren[$name]; $child = $this->create($name, $info['type'], $info['options']); $this->children[$name] = $child; unset($this->unresolvedChildren[$name]); return $child; } /** * Converts all unresolved children into {@link FormBuilder} instances. */ private function resolveChildren() { foreach ($this->unresolvedChildren as $name => $info) { $this->children[$name] = $this->create($name, $info['type'], $info['options']); } $this->unresolvedChildren = array(); } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
Exception
---
0755
Extension
---
0755
Guess
---
0755
Resources
---
0755
Test
---
0755
Util
---
0755
AbstractExtension.php
4885 bytes
0644
AbstractRendererEngine.php
7634 bytes
0644
AbstractType.php
1080 bytes
0644
AbstractTypeExtension.php
993 bytes
0644
Button.php
8826 bytes
0644
ButtonBuilder.php
18523 bytes
0644
ButtonTypeInterface.php
462 bytes
0644
CallbackTransformer.php
2138 bytes
0644
ClickableInterface.php
559 bytes
0644
DataMapperInterface.php
1130 bytes
0644
DataTransformerInterface.php
3159 bytes
0644
Form.php
34865 bytes
0644
FormBuilder.php
7871 bytes
0644
FormBuilderInterface.php
2335 bytes
0644
FormConfigBuilder.php
21680 bytes
0644
FormConfigBuilderInterface.php
8666 bytes
0644
FormConfigInterface.php
6437 bytes
0644
FormError.php
2563 bytes
0644
FormEvent.php
1247 bytes
0644
FormEvents.php
1140 bytes
0644
FormExtensionInterface.php
1668 bytes
0644
FormFactory.php
5225 bytes
0644
FormFactoryBuilder.php
3609 bytes
0644
FormFactoryBuilderInterface.php
3058 bytes
0644
FormFactoryInterface.php
4244 bytes
0644
FormInterface.php
8328 bytes
0644
FormRegistry.php
4753 bytes
0644
FormRegistryInterface.php
1442 bytes
0644
FormRenderer.php
11954 bytes
0644
FormRendererEngineInterface.php
7063 bytes
0644
FormRendererInterface.php
3279 bytes
0644
FormTypeExtensionInterface.php
2125 bytes
0644
FormTypeGuesserChain.php
2880 bytes
0644
FormTypeGuesserInterface.php
2170 bytes
0644
FormTypeInterface.php
3222 bytes
0644
FormView.php
3524 bytes
0644
Forms.php
5899 bytes
0644
NativeRequestHandler.php
5612 bytes
0644
PreloadedExtension.php
2317 bytes
0644
RequestHandlerInterface.php
668 bytes
0644
ResolvedFormType.php
7662 bytes
0644
ResolvedFormTypeFactory.php
658 bytes
0644
ResolvedFormTypeFactoryInterface.php
1302 bytes
0644
ResolvedFormTypeInterface.php
3307 bytes
0644
ReversedTransformer.php
1256 bytes
0644
SubmitButton.php
1137 bytes
0644
SubmitButtonBuilder.php
624 bytes
0644
SubmitButtonTypeInterface.php
474 bytes
0644
autoloader.php
334 bytes
0644
N4ST4R_ID | Naxtarrr