Skip to content

Commit

Permalink
minor #27087 [HttpFoundation] Rename HeaderUtils methods (c960657)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.1-dev branch.

Discussion
----------

[HttpFoundation] Rename HeaderUtils methods

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27026
| License       | MIT
| Doc PR        |

Rename new HeaderUtils methods as discussed in #27026.

Commits
-------

484d1fb [HttpFoundation] Rename HeaderUtils methods
  • Loading branch information
fabpot committed Apr 30, 2018
2 parents 5a5b925 + 484d1fb commit 295eaed
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/AcceptHeader.php
Expand Up @@ -56,7 +56,7 @@ public static function fromString($headerValue)

return new self(array_map(function ($subParts) use (&$index) {
$part = array_shift($subParts);
$attributes = HeaderUtils::combineParts($subParts);
$attributes = HeaderUtils::combine($subParts);

$item = new AcceptHeaderItem($part[0], $attributes);
$item->setIndex($index++);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php
Expand Up @@ -43,7 +43,7 @@ public static function fromString($itemValue)
$parts = HeaderUtils::split($itemValue, ';=');

$part = array_shift($parts);
$attributes = HeaderUtils::combineParts($parts);
$attributes = HeaderUtils::combine($parts);

return new self($part[0], $attributes);
}
Expand All @@ -57,7 +57,7 @@ public function __toString()
{
$string = $this->value.($this->quality < 1 ? ';q='.$this->quality : '');
if (count($this->attributes) > 0) {
$string .= '; '.HeaderUtils::joinAssoc($this->attributes, ';');
$string .= '; '.HeaderUtils::toString($this->attributes, ';');
}

return $string;
Expand Down
Expand Up @@ -219,7 +219,7 @@ public function prepare(Request $request)
// Do X-Accel-Mapping substitutions.
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
$mappings = HeaderUtils::combineParts($parts);
$mappings = HeaderUtils::combine($parts);
foreach ($mappings as $pathPrefix => $location) {
if (substr($path, 0, strlen($pathPrefix)) === $pathPrefix) {
$path = $location.substr($path, strlen($pathPrefix));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Cookie.php
Expand Up @@ -57,7 +57,7 @@ public static function fromString($cookie, $decode = false)
$name = $decode ? urldecode($part[0]) : $part[0];
$value = isset($part[1]) ? ($decode ? urldecode($part[1]) : $part[1]) : null;

$data = HeaderUtils::combineParts($parts) + $data;
$data = HeaderUtils::combine($parts) + $data;

if (isset($data['max-age'])) {
$data['expires'] = time() + (int) $data['max-age'];
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/HeaderBag.php
Expand Up @@ -296,7 +296,7 @@ protected function getCacheControlHeader()
{
ksort($this->cacheControl);

return HeaderUtils::joinAssoc($this->cacheControl, ',');
return HeaderUtils::toString($this->cacheControl, ',');
}

/**
Expand All @@ -310,6 +310,6 @@ protected function parseCacheControl($header)
{
$parts = HeaderUtils::split($header, ',=');

return HeaderUtils::combineParts($parts);
return HeaderUtils::combine($parts);
}
}
8 changes: 4 additions & 4 deletions src/Symfony/Component/HttpFoundation/HeaderUtils.php
Expand Up @@ -75,10 +75,10 @@ public static function split(string $header, string $separators): array
*
* Example:
*
* HeaderUtils::combineParts(array(array("foo", "abc"), array("bar")))
* HeaderUtils::combine(array(array("foo", "abc"), array("bar")))
* // => array("foo" => "abc", "bar" => true)
*/
public static function combineParts(array $parts): array
public static function combine(array $parts): array
{
$assoc = array();
foreach ($parts as $part) {
Expand All @@ -99,10 +99,10 @@ public static function combineParts(array $parts): array
*
* Example:
*
* HeaderUtils::joinAssoc(array("foo" => "abc", "bar" => true, "baz" => "a b c"), ",")
* HeaderUtils::toString(array("foo" => "abc", "bar" => true, "baz" => "a b c"), ",")
* // => 'foo=abc, bar, baz="a b c"'
*/
public static function joinAssoc(array $assoc, string $separator): string
public static function toString(array $assoc, string $separator): string
{
$parts = array();
foreach ($assoc as $name => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1949,7 +1949,7 @@ private function getTrustedValues($type, $ip = null)
$forwardedValues = array();
$param = self::$forwardedParams[$type];
foreach ($parts as $subParts) {
$assoc = HeaderUtils::combineParts($subParts);
$assoc = HeaderUtils::combine($subParts);
if (isset($assoc[$param])) {
$forwardedValues[] = $assoc[$param];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php
Expand Up @@ -295,7 +295,7 @@ public function makeDisposition($disposition, $filename, $filenameFallback = '')
$params['filename*'] = "utf-8''".rawurlencode($filename);
}

return $disposition.'; '.HeaderUtils::joinAssoc($params, ';');
return $disposition.'; '.HeaderUtils::toString($params, ';');
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/Symfony/Component/HttpFoundation/Tests/HeaderUtilsTest.php
Expand Up @@ -45,21 +45,21 @@ public function testSplit()
$this->assertSame(array('foo', 'bar, baz\\'), HeaderUtils::split('foo, "bar, baz\\\\', ','));
}

public function testCombineAssoc()
public function testCombine()
{
$this->assertSame(array('foo' => '123'), HeaderUtils::combineParts(array(array('foo', '123'))));
$this->assertSame(array('foo' => true), HeaderUtils::combineParts(array(array('foo'))));
$this->assertSame(array('foo' => true), HeaderUtils::combineParts(array(array('Foo'))));
$this->assertSame(array('foo' => '123', 'bar' => true), HeaderUtils::combineParts(array(array('foo', '123'), array('bar'))));
$this->assertSame(array('foo' => '123'), HeaderUtils::combine(array(array('foo', '123'))));
$this->assertSame(array('foo' => true), HeaderUtils::combine(array(array('foo'))));
$this->assertSame(array('foo' => true), HeaderUtils::combine(array(array('Foo'))));
$this->assertSame(array('foo' => '123', 'bar' => true), HeaderUtils::combine(array(array('foo', '123'), array('bar'))));
}

public function testJoinAssoc()
public function testToString()
{
$this->assertSame('foo', HeaderUtils::joinAssoc(array('foo' => true), ','));
$this->assertSame('foo; bar', HeaderUtils::joinAssoc(array('foo' => true, 'bar' => true), ';'));
$this->assertSame('foo=123', HeaderUtils::joinAssoc(array('foo' => '123'), ','));
$this->assertSame('foo="1 2 3"', HeaderUtils::joinAssoc(array('foo' => '1 2 3'), ','));
$this->assertSame('foo="1 2 3", bar', HeaderUtils::joinAssoc(array('foo' => '1 2 3', 'bar' => true), ','));
$this->assertSame('foo', HeaderUtils::toString(array('foo' => true), ','));
$this->assertSame('foo; bar', HeaderUtils::toString(array('foo' => true, 'bar' => true), ';'));
$this->assertSame('foo=123', HeaderUtils::toString(array('foo' => '123'), ','));
$this->assertSame('foo="1 2 3"', HeaderUtils::toString(array('foo' => '1 2 3'), ','));
$this->assertSame('foo="1 2 3", bar', HeaderUtils::toString(array('foo' => '1 2 3', 'bar' => true), ','));
}

public function testQuote()
Expand Down

0 comments on commit 295eaed

Please sign in to comment.