Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Add type-hints RequestContext and Route classes. #32181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Routing] Add type-hints RequestContext and Route classes.
  • Loading branch information
derrabus committed Jun 28, 2019
commit 614e8248c354b60ba74b18224d81139e3c67868f
49 changes: 14 additions & 35 deletions 49 src/Symfony/Component/Routing/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ public function getBaseUrl()
/**
* Sets the base URL.
*
* @param string $baseUrl The base URL
*
* @return $this
*/
public function setBaseUrl($baseUrl)
public function setBaseUrl(string $baseUrl)
Tobion marked this conversation as resolved.
Show resolved Hide resolved
{
$this->baseUrl = $baseUrl;

Expand All @@ -101,11 +99,9 @@ public function getPathInfo()
/**
* Sets the path info.
*
* @param string $pathInfo The path info
*
* @return $this
*/
public function setPathInfo($pathInfo)
public function setPathInfo(string $pathInfo)
{
$this->pathInfo = $pathInfo;

Expand All @@ -127,11 +123,9 @@ public function getMethod()
/**
* Sets the HTTP method.
*
* @param string $method The HTTP method
*
* @return $this
*/
public function setMethod($method)
public function setMethod(string $method)
{
$this->method = strtoupper($method);

Expand All @@ -153,11 +147,9 @@ public function getHost()
/**
* Sets the HTTP host.
*
* @param string $host The HTTP host
*
* @return $this
*/
public function setHost($host)
public function setHost(string $host)
{
$this->host = strtolower($host);

Expand All @@ -177,11 +169,9 @@ public function getScheme()
/**
* Sets the HTTP scheme.
*
* @param string $scheme The HTTP scheme
*
* @return $this
*/
public function setScheme($scheme)
public function setScheme(string $scheme)
{
$this->scheme = strtolower($scheme);

Expand All @@ -201,13 +191,11 @@ public function getHttpPort()
/**
* Sets the HTTP port.
*
* @param int $httpPort The HTTP port
*
* @return $this
*/
public function setHttpPort($httpPort)
public function setHttpPort(int $httpPort)
{
$this->httpPort = (int) $httpPort;
$this->httpPort = $httpPort;

return $this;
}
Expand All @@ -225,13 +213,11 @@ public function getHttpsPort()
/**
* Sets the HTTPS port.
*
* @param int $httpsPort The HTTPS port
*
* @return $this
*/
public function setHttpsPort($httpsPort)
public function setHttpsPort(int $httpsPort)
{
$this->httpsPort = (int) $httpsPort;
$this->httpsPort = $httpsPort;

return $this;
}
Expand All @@ -249,11 +235,9 @@ public function getQueryString()
/**
* Sets the query string.
*
* @param string $queryString The query string (after "?")
*
* @return $this
*/
public function setQueryString($queryString)
public function setQueryString(?string $queryString)
{
// string cast to be fault-tolerant, accepting null
$this->queryString = (string) $queryString;
Expand Down Expand Up @@ -288,36 +272,31 @@ public function setParameters(array $parameters)
/**
* Gets a parameter value.
*
* @param string $name A parameter name
*
* @return mixed The parameter value or null if nonexistent
*/
public function getParameter($name)
public function getParameter(string $name)
{
return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
}

/**
* Checks if a parameter value is set for the given parameter.
*
* @param string $name A parameter name
*
* @return bool True if the parameter value is set, false otherwise
*/
public function hasParameter($name)
public function hasParameter(string $name)
{
return \array_key_exists($name, $this->parameters);
}

/**
* Sets a parameter value.
*
* @param string $name A parameter name
* @param mixed $parameter The parameter value
* @param mixed $parameter The parameter value
*
* @return $this
*/
public function setParameter($name, $parameter)
public function setParameter(string $name, $parameter)
{
$this->parameters[$name] = $parameter;

Expand Down
61 changes: 16 additions & 45 deletions 61 src/Symfony/Component/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,9 @@ public function getPath()
*
* This method implements a fluent interface.
*
* @param string $pattern The path pattern
*
* @return $this
*/
public function setPath($pattern)
public function setPath(string $pattern)
{
if (false !== strpbrk($pattern, '?<')) {
$pattern = preg_replace_callback('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
Expand Down Expand Up @@ -168,11 +166,9 @@ public function getHost()
*
* This method implements a fluent interface.
*
* @param string $pattern The host pattern
*
* @return $this
*/
public function setHost($pattern)
public function setHost(?string $pattern)
Tobion marked this conversation as resolved.
Show resolved Hide resolved
{
$this->host = (string) $pattern;
$this->compiled = null;
Expand Down Expand Up @@ -212,11 +208,9 @@ public function setSchemes($schemes)
/**
* Checks if a scheme requirement has been set.
*
* @param string $scheme
*
* @return bool true if the scheme requirement exists, otherwise false
*/
public function hasScheme($scheme)
public function hasScheme(string $scheme)
{
return \in_array(strtolower($scheme), $this->schemes, true);
}
Expand Down Expand Up @@ -302,12 +296,11 @@ public function addOptions(array $options)
*
* This method implements a fluent interface.
*
* @param string $name An option name
* @param mixed $value The option value
* @param mixed $value The option value
*
* @return $this
*/
public function setOption($name, $value)
public function setOption(string $name, $value)
{
$this->options[$name] = $value;
$this->compiled = null;
Expand All @@ -318,23 +311,19 @@ public function setOption($name, $value)
/**
* Get an option value.
*
* @param string $name An option name
*
* @return mixed The option value or null when not given
*/
public function getOption($name)
public function getOption(string $name)
{
return isset($this->options[$name]) ? $this->options[$name] : null;
}

/**
* Checks if an option has been set.
*
* @param string $name An option name
*
* @return bool true if the option is set, false otherwise
*/
public function hasOption($name)
public function hasOption(string $name)
{
return \array_key_exists($name, $this->options);
}
Expand Down Expand Up @@ -387,36 +376,31 @@ public function addDefaults(array $defaults)
/**
* Gets a default value.
*
* @param string $name A variable name
*
* @return mixed The default value or null when not given
*/
public function getDefault($name)
public function getDefault(string $name)
{
return isset($this->defaults[$name]) ? $this->defaults[$name] : null;
}

/**
* Checks if a default value is set for the given variable.
*
* @param string $name A variable name
*
* @return bool true if the default value is set, false otherwise
*/
public function hasDefault($name)
public function hasDefault(string $name)
{
return \array_key_exists($name, $this->defaults);
}

/**
* Sets a default value.
*
* @param string $name A variable name
* @param mixed $default The default value
* @param mixed $default The default value
*
* @return $this
*/
public function setDefault($name, $default)
public function setDefault(string $name, $default)
{
$this->defaults[$name] = $default;
$this->compiled = null;
Expand Down Expand Up @@ -472,36 +456,29 @@ public function addRequirements(array $requirements)
/**
* Returns the requirement for the given key.
*
* @param string $key The key
*
* @return string|null The regex or null when not given
*/
public function getRequirement($key)
public function getRequirement(string $key)
{
return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
}

/**
* Checks if a requirement is set for the given key.
*
* @param string $key A variable name
*
* @return bool true if a requirement is specified, false otherwise
*/
public function hasRequirement($key)
public function hasRequirement(string $key)
{
return \array_key_exists($key, $this->requirements);
}

/**
* Sets a requirement for the given key.
*
* @param string $key The key
* @param string $regex The regex
*
* @return $this
*/
public function setRequirement($key, $regex)
public function setRequirement(string $key, string $regex)
{
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
$this->compiled = null;
Expand All @@ -524,11 +501,9 @@ public function getCondition()
*
* This method implements a fluent interface.
*
* @param string $condition The condition
*
* @return $this
*/
public function setCondition($condition)
public function setCondition(?string $condition)
{
$this->condition = (string) $condition;
$this->compiled = null;
Expand Down Expand Up @@ -557,12 +532,8 @@ public function compile()
return $this->compiled = $class::compile($this);
}

private function sanitizeRequirement($key, $regex)
private function sanitizeRequirement(string $key, string $regex)
{
if (!\is_string($regex)) {
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.', $key));
}

if ('' !== $regex && '^' === $regex[0]) {
$regex = (string) substr($regex, 1); // returns false for a single character
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.