public function &getAll($isStripNullbyte = true) { if ($isStripNullbyte) { $value = opToolkit::stripNullByteDeep(parent::getAll()); } else { $value =& parent::getAll(); } return $value; }
/** * Returns a parameter holder as an array. * * @param sfParameterHolder $parameterHolder A sfParameterHolder instance * @param boolean $removeObjects when set to true, objects are removed. default is false for BC. * * @return array The parameter holder as an array */ public static function flattenParameterHolder($parameterHolder, $removeObjects = false) { $values = array(); if ($parameterHolder instanceof sfNamespacedParameterHolder) { foreach ($parameterHolder->getNamespaces() as $ns) { $values[$ns] = array(); foreach ($parameterHolder->getAll($ns) as $key => $value) { $values[$ns][$key] = $value; } ksort($values[$ns]); } } else { foreach ($parameterHolder->getAll() as $key => $value) { $values[$key] = $value; } } if ($removeObjects) { $values = self::removeObjects($values); } ksort($values); return $values; }
// ->setByRef() $t->diag('->setByRef()'); $foo = 'bar'; $ph = new sfParameterHolder(); $ph->setByRef('foo', $foo); $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key'); $foo = 'foo'; $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key as a reference'); // ->add() $t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters'); // ->serialize() ->unserialize() $t->diag('->serialize() ->unserialize()'); $t->ok($ph == unserialize(serialize($ph)), 'sfParameterHolder implements the Serializable interface');
$t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters'); // ->serialize() ->unserialize() $t->diag('->serialize() ->unserialize()'); $t->ok($ph == unserialize(serialize($ph)), 'sfParameterHolder implements the Serializable interface'); // Array path as a key $t->diag('Array path as a key'); $ph = new sfParameterHolder(); $ph->add(array('foo' => array('bar' => 'foo'))); $t->is($ph->has('foo[bar]'), true, '->has() can takes a multi-array key'); $t->is($ph->get('foo[bar]'), 'foo', '->has() can takes a multi-array key'); $t->is($ph->remove('foo[bar]'), 'foo', '->remove() can takes a multi-array key'); $t->is($ph->getAll(), array('foo' => array()), '->remove() can takes a multi-array key');
/** * Simulates a click on a link or button. * * @param string $name The link or button text * @param array $arguments * * @return sfBrowser */ public function click($name, $arguments = array()) { $dom = $this->getResponseDom(); if (!$dom) { throw new sfException('Cannot click because there is no current page in the browser.'); } $xpath = new DomXpath($dom); // text link if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item(0)) { return $this->get($link->getAttribute('href')); } // image link if ($link = $xpath->query(sprintf('//a/img[@alt="%s"]/ancestor::a', $name))->item(0)) { return $this->get($link->getAttribute('href')); } // form if (!($form = $xpath->query(sprintf('//input[((@type="submit" or @type="button") and @value="%s") or (@type="image" and @alt="%s")]/ancestor::form', $name, $name))->item(0))) { if (!($form = $xpath->query(sprintf('//button[.="%s" or @id="%s" or @name="%s"]/ancestor::form', $name, $name, $name))->item(0))) { throw new sfException(sprintf('Cannot find the "%s" link or button.', $name)); } } // form attributes $url = $form->getAttribute('action'); $method = $form->getAttribute('method') ? strtolower($form->getAttribute('method')) : 'get'; // merge form default values and arguments $defaults = array(); $arguments = sfToolkit::arrayDeepMerge($this->fields, $arguments); foreach ($xpath->query('descendant::input | descendant::textarea | descendant::select', $form) as $element) { $elementName = $element->getAttribute('name'); $nodeName = $element->nodeName; $value = null; if ($nodeName == 'input' && ($element->getAttribute('type') == 'checkbox' || $element->getAttribute('type') == 'radio')) { if ($element->getAttribute('checked')) { $value = $element->getAttribute('value'); } } else { if ($nodeName == 'input' && $element->getAttribute('type') == 'file') { $ph = new sfParameterHolder(); $ph->add($arguments); $filename = $ph->get($elementName, ''); if (is_readable($filename)) { $fileError = UPLOAD_ERR_OK; $fileSize = filesize($filename); } else { $fileError = UPLOAD_ERR_NO_FILE; $fileSize = 0; } $ph->remove($elementName); $arguments = $ph->getAll(); $this->parseArgumentAsArray($elementName, array('name' => basename($filename), 'type' => '', 'tmp_name' => $filename, 'error' => $fileError, 'size' => $fileSize), $this->files); } else { if ($nodeName == 'input' && ($element->getAttribute('type') != 'submit' && $element->getAttribute('type') != 'button' || $element->getAttribute('value') == $name) && ($element->getAttribute('type') != 'image' || $element->getAttribute('alt') == $name)) { $value = $element->getAttribute('value'); } else { if ($nodeName == 'textarea') { $value = ''; foreach ($element->childNodes as $el) { $value .= $dom->saveXML($el); } } else { if ($nodeName == 'select') { if ($multiple = $element->hasAttribute('multiple')) { $elementName = str_replace('[]', '', $elementName); $value = array(); } else { $value = null; } $found = false; foreach ($xpath->query('descendant::option', $element) as $option) { if ($option->getAttribute('selected')) { $found = true; if ($multiple) { $value[] = $option->getAttribute('value'); } else { $value = $option->getAttribute('value'); } } } // if no option is selected and if it is a simple select box, take the first option as the value if (!$found && !$multiple) { $value = $xpath->query('descendant::option', $element)->item(0)->getAttribute('value'); } } } } } } if (null !== $value) { $this->parseArgumentAsArray($elementName, $value, $defaults); } } // create request parameters $arguments = sfToolkit::arrayDeepMerge($defaults, $arguments); if ('post' == $method) { return $this->post($url, $arguments); } else { $query_string = http_build_query($arguments, null, '&'); $sep = false === strpos($url, '?') ? '?' : '&'; return $this->get($url . ($query_string ? $sep . $query_string : '')); } }
public function __construct($colName, $columnDescription = array(), $translatePropel = false) { // sometimes we get null if the yml line is empty if ($columnDescription == null) { $columnDescription = array(); } // for the short syntax type(size) if (is_string($columnDescription)) { $columnDescription = array('type' => $columnDescription); } $this->setName($colName); $columnInfo = new sfParameterHolder(); $columnInfo->add($columnDescription); if ($translatePropel) { // we translate the propel types to doctrine ones $propelType = strtolower($columnInfo->get('type')); if (array_key_exists($propelType, self::$propel2docDictionary['types'])) { $columnInfo->set('type', self::$propel2docDictionary['types'][$propelType]); } else { $columnInfo->set('type', $propelType); } // we store it in lowercase // if there is a default propel size we set it if (!$columnInfo->get('size')) { if (isset(self::$defaultPropelSize[$propelType])) { $columnInfo->set('size', self::$defaultPropelSize[$propelType]); } } // we translate the constraints foreach ($columnInfo->getAll() as $key => $value) { if (array_key_exists($key, self::$propel2docDictionary['constraints'])) { $columnInfo->set(self::$propel2docDictionary['constraints'][$key], $columnInfo->get($key)); } } } // we store the raw description, only used in setUpForeignRelation $this->columnInfo = $columnInfo; // name $this->setProperty('name', $colName); $this->setProperty('columnName', $columnInfo->get('columnName')); // type if (!($type = $columnInfo->get('type'))) { // we try to figure out the type // FIXME: write a method to detect relations? if ($columnInfo->get('foreignClass') || $columnInfo->get('foreignTable')) { $type = 'integer'; } else { $type = 'string'; } // default type } elseif (is_string($type)) { preg_match('/([^\\(\\s]+)\\s*\\([\\s]*([\\d]+)[\\s]*\\)/', $type, $matches); if (!empty($matches)) { $type = $matches[1]; $columnInfo->set('size', $matches[2]); } } $this->setProperty('type', $type); // size if (!($size = $columnInfo->get('size'))) { if (is_string($type)) { if (isset(self::$defaultDoctrineSize[$type])) { $size = self::$defaultDoctrineSize[$type]; } // we have a default size for this type } } if (!$size) { $size = 'null'; } $this->setProperty('size', $size); // constraints if ($constraints = array_intersect_key($columnDescription, array_flip(self::$allowedConstraints))) { $this->properties = array_merge($this->properties, $constraints); } }
$ph->setByRef('foo', $foo); $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key'); $foo = 'foo'; $t->is($ph->get('foo'), $foo, '->setByRef() sets the value for a key as a reference'); $myfoo = 'bar'; $ph->setByRef('myfoo', $myfoo, 'symfony/mynamespace'); $t->is($ph->get('myfoo', null, 'symfony/mynamespace'), $myfoo, '->setByRef() takes a namespace as its third parameter'); // ->add() $t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $ph->add($myparameters, 'symfony/mynamespace'); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $t->is($ph->getAll('symfony/mynamespace'), $myparameters, '->add() takes a namespace as its second argument'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $ph->addByRef($myparameters, 'symfony/mynamespace'); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $t->is($myparameters, $ph->getAll('symfony/mynamespace'), '->add() takes a namespace as its second argument'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters');