/** * @see sfWebRequest */ public function initialize(sfEventDispatcher $dispatcher, $parameters = array(), $attributes = array(), $options = array()) { parent::initialize($dispatcher, $parameters, $attributes, $options); $this->parameterHolder = new opParameterHolder(); $this->attributeHolder = new opParameterHolder(); $this->parameterHolder->add($parameters); $this->attributeHolder->add($attributes); // POST parameters $this->getParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_GET) : $_GET; $this->parameterHolder->add($this->getParameters); // POST parameters $this->postParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_POST) : $_POST; $this->parameterHolder->add($this->postParameters); if ($this->isMethod(sfWebRequest::POST)) { $this->parameterHolder->remove('sf_method'); } // additional parameters $this->requestParameters = $this->parseRequestParameters(); $this->parameterHolder->add($this->requestParameters); $this->fixParameters(); }
/** * Gets a cookie value. * * @param string $name Cookie name * @param string $defaultValue Default value returned when no cookie with given name is found * * @return mixed */ public function getCookie($name, $defaultValue = null) { $retval = $defaultValue; if (isset($_COOKIE[$name])) { $retval = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_COOKIE[$name]) : $_COOKIE[$name]; } return $retval; }
/** * Parses a URL to find a matching route. * * Returns null if no route match the URL. * * @param string URL to be parsed * * @return array An array of parameters */ public function parse($url) { // an URL should start with a '/', mod_rewrite doesn't respect that, but no-mod_rewrite version does. if ($url && '/' != $url[0]) { $url = '/' . $url; } // we remove the query string if ($pos = strpos($url, '?')) { $url = substr($url, 0, $pos); } // we remove multiple / $url = preg_replace('#/+#', '/', $url); foreach ($this->routes as $route_name => $route) { $out = array(); $r = null; list($route, $regexp, $names, $names_hash, $defaults, $requirements, $suffix) = $route; $break = false; if (preg_match($regexp, $url, $r)) { $break = true; // remove the first element, which is the url array_shift($r); // hack, pre-fill the default route names foreach ($names as $name) { $out[$name] = null; } // defaults foreach ($defaults as $name => $value) { if (preg_match('#[a-z_\\-]#i', $name)) { $out[$name] = urldecode($value); } else { $out[$value] = true; } } $pos = 0; foreach ($r as $found) { // if $found is a named url element (i.e. ':action') if (isset($names[$pos])) { $out[$names[$pos]] = urldecode($found); } else { $pass = explode('/', $found); $found = ''; for ($i = 0, $max = count($pass); $i < $max; $i += 2) { if (!isset($pass[$i + 1])) { continue; } $found .= $pass[$i] . '=' . $pass[$i + 1] . '&'; } parse_str($found, $pass); if (get_magic_quotes_gpc()) { $pass = sfToolkit::stripslashesDeep((array) $pass); } foreach ($pass as $key => $value) { // we add this parameters if not in conflict with named url element (i.e. ':action') if (!isset($names_hash[$key])) { $out[$key] = $value; } } } $pos++; } // we must have found all :var stuffs in url? except if default values exists foreach ($names as $name) { if ($out[$name] == null) { $break = false; } } if ($break) { // we store route name $this->setCurrentRouteName($route_name); if (sfConfig::get('sf_logging_enabled')) { sfLogger::getInstance()->info('{sfRouting} match route [' . $route_name . '] "' . $route . '"'); } break; } } } // no route found if (!$break) { if (sfConfig::get('sf_logging_enabled')) { sfLogger::getInstance()->info('{sfRouting} no matching route found'); } return null; } return $out; }
protected function loadParameters() { if (get_magic_quotes_gpc()) { $_GET = sfToolkit::stripslashesDeep($_GET); } $this->getParameterHolder()->addByRef($_GET); $pathInfo = $this->getPathInfo(); if ($pathInfo) { $r = sfRouting::getInstance(); if ($r->hasRoutes()) { $results = $r->parse($pathInfo); if ($results !== null) { $this->getParameterHolder()->addByRef($results); } else { $this->setParameter('module', sfConfig::get('sf_error_404_module')); $this->setParameter('action', sfConfig::get('sf_error_404_action')); } } else { $array = explode('/', trim($pathInfo, '/')); $count = count($array); for ($i = 0; $i < $count; $i++) { if ($count > $i + 1) { $this->getParameterHolder()->setByRef($array[$i], $array[++$i]); } } } } if (get_magic_quotes_gpc()) { $_POST = sfToolkit::stripslashesDeep((array) $_POST); } $this->getParameterHolder()->addByRef($_POST); foreach ($this->getParameterHolder()->getAll() as $key => $value) { if (0 === stripos($key, '_sf_')) { $this->getParameterHolder()->remove($key); $this->setParameter($key, $value, 'symfony/request/sfWebRequest'); unset($_GET[$key]); } } if (sfConfig::get('sf_logging_enabled')) { $this->getContext()->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); } }
$php = <<<EOF <?php \$pluginDirs = '/*/modules/lib/helper'; \$pluginDirs = '/*/lib/helper'; EOF; $t->is(sfToolkit::stripComments($php), $php, '::stripComments() correctly handles comments within strings'); // ::stripslashesDeep() $t->diag('::stripslashesDeep()'); $t->is(sfToolkit::stripslashesDeep('foo'), 'foo', '::stripslashesDeep() strip slashes on string'); $t->is(sfToolkit::stripslashesDeep(addslashes("foo's bar")), "foo's bar", '::stripslashesDeep() strip slashes on array'); $t->is(sfToolkit::stripslashesDeep(array(addslashes("foo's bar"), addslashes("foo's bar"))), array("foo's bar", "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays'); $t->is(sfToolkit::stripslashesDeep(array(array('foo' => addslashes("foo's bar")), addslashes("foo's bar"))), array(array('foo' => "foo's bar"), "foo's bar"), '::stripslashesDeep() strip slashes on deep arrays'); // ::clearDirectory() $t->diag('::clearDirectory()'); $tmp_dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'symfony_tests_'.rand(1, 999); mkdir($tmp_dir); file_put_contents($tmp_dir.DIRECTORY_SEPARATOR.'test', 'ok'); mkdir($tmp_dir.DIRECTORY_SEPARATOR.'foo'); file_put_contents($tmp_dir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar', 'ok'); sfToolkit::clearDirectory($tmp_dir); $t->ok(!is_dir($tmp_dir.DIRECTORY_SEPARATOR.'foo'), '::clearDirectory() removes all directories from the directory parameter'); $t->ok(!is_file($tmp_dir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar'), '::clearDirectory() removes all directories from the directory parameter'); $t->ok(!is_file($tmp_dir.DIRECTORY_SEPARATOR.'test'), '::clearDirectory() removes all directories from the directory parameter'); rmdir($tmp_dir); // ::clearGlob()
/** * Loads GET, PATH_INFO and POST data into the parameter list. * */ protected function loadParameters() { // GET parameters $this->getParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_GET) : $_GET; $this->parameterHolder->add($this->getParameters); // additional parameters $this->requestParameters = $this->parseRequestParameters(); $this->parameterHolder->add($this->requestParameters); // POST parameters $this->postParameters = get_magic_quotes_gpc() ? sfToolkit::stripslashesDeep($_POST) : $_POST; $this->parameterHolder->add($this->postParameters); // move symfony parameters to attributes (parameters prefixed with _sf_) foreach ($this->parameterHolder->getAll() as $key => $value) { if (0 === stripos($key, '_sf_')) { $this->parameterHolder->remove($key); $this->setAttribute($key, $value); } } if (sfConfig::get('sf_logging_enabled')) { $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))))); } }