This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zendframework/zendframework#5029 from jas-/Origin
Support for Origin header
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Http\Header; | ||
|
||
use \Zend\Uri\UriFactory; | ||
|
||
/** | ||
* @throws Exception\InvalidArgumentException | ||
* @see http://tools.ietf.org/id/draft-abarth-origin-03.html#rfc.section.2 | ||
*/ | ||
class Origin implements HeaderInterface | ||
{ | ||
|
||
public static function fromString($headerLine) | ||
{ | ||
$header = new static(); | ||
|
||
list($name, $value) = explode(': ', $headerLine, 2); | ||
|
||
// check to ensure proper header type for this factory | ||
if (strtolower($name) !== 'origin') { | ||
throw new Exception\InvalidArgumentException('Invalid header line for Origin string: "' . $name . '"'); | ||
} | ||
|
||
$uri = UriFactory::factory($value); | ||
if (!$uri->isValid()) { | ||
throw new Exception\InvalidArgumentException('Invalid header value for Origin key: "' . $name . '"'); | ||
} | ||
|
||
// @todo implementation details | ||
$header->value = $value; | ||
|
||
return $header; | ||
} | ||
|
||
public function getFieldName() | ||
{ | ||
return 'Origin'; | ||
} | ||
|
||
public function getFieldValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function toString() | ||
{ | ||
return 'Origin: ' . $this->getFieldValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Http\Header; | ||
|
||
use Zend\Http\Header\Origin; | ||
|
||
class OriginTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testOriginFromStringCreatesValidOriginHeader() | ||
{ | ||
$OriginHeader = Origin::fromString('Origin: http://zend.org'); | ||
$this->assertInstanceOf('Zend\Http\Header\HeaderInterface', $OriginHeader); | ||
$this->assertInstanceOf('Zend\Http\Header\Origin', $OriginHeader); | ||
} | ||
|
||
public function testOriginGetFieldNameReturnsHeaderName() | ||
{ | ||
$OriginHeader = new Origin(); | ||
$this->assertEquals('Origin', $OriginHeader->getFieldName()); | ||
} | ||
|
||
public function testOriginGetFieldValueReturnsProperValue() | ||
{ | ||
$this->markTestIncomplete('Origin needs to be completed'); | ||
|
||
$OriginHeader = new Origin(); | ||
$this->assertEquals('http://zend.org', $OriginHeader->getFieldValue()); | ||
} | ||
|
||
public function testOriginToStringReturnsHeaderFormattedString() | ||
{ | ||
$this->markTestIncomplete('Origin needs to be completed'); | ||
|
||
$OriginHeader = new Origin(); | ||
|
||
// @todo set some values, then test output | ||
$this->assertEmpty('Origin: http://zend.org', $OriginHeader->toString()); | ||
} | ||
|
||
/** Implmentation specific tests here */ | ||
|
||
} |