Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5029 from jas-/Origin
Browse files Browse the repository at this point in the history
Support for Origin header
  • Loading branch information
weierophinney committed Oct 22, 2013
2 parents 365f27a + ab3a4f5 commit 1891c75
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/Header/Origin.php
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();
}
}
1 change: 1 addition & 0 deletions src/HeaderLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class HeaderLoader extends PluginClassLoader
'lastmodified' => 'Zend\Http\Header\LastModified',
'location' => 'Zend\Http\Header\Location',
'maxforwards' => 'Zend\Http\Header\MaxForwards',
'Origin' => 'Zend\Http\Header\Origin',
'pragma' => 'Zend\Http\Header\Pragma',
'proxyauthenticate' => 'Zend\Http\Header\ProxyAuthenticate',
'proxyauthorization' => 'Zend\Http\Header\ProxyAuthorization',
Expand Down
50 changes: 50 additions & 0 deletions test/Header/OriginTest.php
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 */

}

0 comments on commit 1891c75

Please sign in to comment.