/** * Renders a field by name. * * @param string $name The field name * @param string $value The field value * @param array $attributes An array of HTML attributes to be merged with the current HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML string representing the rendered widget * * @throws \InvalidArgumentException when the widget not exist */ public function renderField($name, $value = null, $attributes = array(), $errors = array()) { if (null === ($widget = $this[$name])) { throw new \InvalidArgumentException(sprintf('The field named "%s" does not exist.', $name)); } if ($widget instanceof Schema && $errors && !$errors instanceof ErrorSchema) { $errors = new ErrorSchema($errors->getValidator(), array($errors)); } // we clone the widget because we want to change the id format temporarily $clone = clone $widget; $clone->setIdFormat($this->options['id_format']); return $clone->render($this->generateName($name), $value, array_merge($clone->getAttributes(), $attributes), $errors); }
/** * Returns the form field associated with the name (implements the \ArrayAccess interface). * * @param string $name The offset of the value to get * * @return sfFormField A form field instance */ public function offsetGet($name) { if (!isset($this->fields[$name])) { if (null === ($widget = $this->widget[$name])) { throw new \InvalidArgumentException(sprintf('Widget "%s" does not exist.', $name)); } $error = isset($this->error[$name]) ? $this->error[$name] : null; if ($widget instanceof WidgetSchema) { $class = 'Bundle\\sfFormBundle\\FieldSchema'; if ($error && !$error instanceof ValidatorErrorSchema) { $error = new ValidatorErrorSchema($error->getValidator(), array($error)); } } else { $class = 'Bundle\\sfFormBundle\\Field'; } $this->fields[$name] = new $class($widget, $this, $name, isset($this->value[$name]) ? $this->value[$name] : null, $error); } return $this->fields[$name]; }
$t->diag('implements \\Serializable'); class NotSerializable implements \Serializable { public function serialize() { throw new \Exception('Not serializable'); } public function unserialize($serialized) { throw new \Exception('Not serializable'); } } function will_crash($a) { return serialize(new ErrorSchema(new String())); } $a = new NotSerializable(); try { $serialized = will_crash($a); $t->pass('ErrorSchema implements \\Serializable'); } catch (Exception $e) { $t->fail('ErrorSchema implements \\Serializable'); } $e = new ErrorSchema($v1); $e1 = unserialize($serialized); $t->is($e1->getMessage(), $e->getMessage(), 'ErrorSchema implements \\Serializable'); $t->is($e1->getCode(), $e->getCode(), 'ErrorSchema implements \\Serializable'); $t->is(get_class($e1->getValidator()), get_class($e->getValidator()), 'ErrorSchema implements \\Serializable'); $t->is($e1->getArguments(), $e->getArguments(), 'ErrorSchema implements \\Serializable'); $t->is($e1->getNamedErrors(), $e->getNamedErrors(), 'ErrorSchema implements \\Serializable'); $t->is($e1->getGlobalErrors(), $e->getGlobalErrors(), 'ErrorSchema implements \\Serializable');