protected function renderWindow($window) { if (is_callable($window)) { return call_user_func_array($window, array($this->helper)); } elseif (is_array($window)) { $options = isset($window['options_param']) ? $this->serviceContainer->getParameter($window['options_param']) : array(); if (isset($options['callback'])) { $window['options'] = $options; return call_user_func_array($window, array($this->helper)); } else { $can = true; if (isset($options['credentials'])) { $can = $this->user->can($options['credentials']); } return $can ? $this->helper->renderComponent($window['module'], $window['component'], array_merge(array('options' => $options), $window['params'])) : ''; } } return ''; }
/** * Returns the form field associated with the name (implements the ArrayAccess interface). * * @param string $name The offset of the value to get * * @return dmFormField A form field instance */ public function offsetGet($name) { if (!isset($this->formFields[$name])) { if (!($widget = $this->widgetSchema[$name])) { throw new InvalidArgumentException(sprintf('Widget "%s" does not exist.', $name)); } if ($this->isBound) { $value = isset($this->taintedValues[$name]) ? $this->taintedValues[$name] : null; } else { if (isset($this->defaults[$name])) { $value = $this->defaults[$name]; } else { $value = $widget instanceof sfWidgetFormSchema ? $widget->getDefaults() : $widget->getDefault(); } } $class = $widget instanceof sfWidgetFormSchema ? 'dmFormFieldSchema' : self::$serviceContainer->getParameter('form_field.class'); $this->formFields[$name] = new $class($widget, $this->getFormFieldSchema(), $name, $value, $this->errorSchema[$name]); if ($this->formFields[$name] instanceof dmFormField && ($validator = $this->getValidatorSchema()->offsetGet($name))) { $this->formFields[$name]->setIsRequired($validator->getOption('required')); } } return $this->formFields[$name]; }
$t->is($sc->getParameters(), array('foo' => 'bar'), '__construct() takes an array of parameters as its first argument'); // ->setParameters() ->getParameters() $t->diag('->setParameters() ->getParameters()'); $sc = new sfServiceContainer(); $t->is($sc->getParameters(), array(), '->getParameters() returns an empty array if no parameter has been defined'); $sc->setParameters(array('foo' => 'bar')); $t->is($sc->getParameters(), array('foo' => 'bar'), '->setParameters() sets the parameters'); $sc->setParameters(array('bar' => 'foo')); $t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() overrides the previous defined parameters'); $sc->setParameters(array('Bar' => 'foo')); $t->is($sc->getParameters(), array('bar' => 'foo'), '->setParameters() converts the key to lowercase'); // ->setParameter() ->getParameter() $t->diag('->setParameter() ->getParameter() '); $sc = new sfServiceContainer(array('foo' => 'bar')); $sc->setParameter('bar', 'foo'); $t->is($sc->getParameter('bar'), 'foo', '->setParameter() sets the value of a new parameter'); $t->is($sc->getParameter('bar'), 'foo', '->getParameter() gets the value of a parameter'); $sc->setParameter('foo', 'baz'); $t->is($sc->getParameter('foo'), 'baz', '->setParameter() overrides previously set parameter'); $sc->setParameter('Foo', 'baz1'); $t->is($sc->getParameter('foo'), 'baz1', '->setParameter() converts the key to lowercase'); $t->is($sc->getParameter('FOO'), 'baz1', '->getParameter() converts the key to lowercase'); try { $sc->getParameter('baba'); $t->fail('->getParameter() thrown an InvalidArgumentException if the key does not exist'); } catch (InvalidArgumentException $e) { $t->pass('->getParameter() thrown an InvalidArgumentException if the key does not exist'); } // ->hasParameter() $t->diag('->hasParameter()'); $sc = new sfServiceContainer(array('foo' => 'bar'));