Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Broken development commit. Introducing proper content negotiation fac…
…ilities.
- Loading branch information
1 parent
7d6bea6
commit b032776
Showing
7 changed files
with
122 additions
and
6 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
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,43 @@ | ||
<?php | ||
class ContentNegotiation { | ||
|
||
protected $headers; | ||
|
||
public function __construct($httpHeaders) { | ||
$this->headers = $httpHeaders; | ||
} | ||
|
||
public function nextFormat() { | ||
return 'html'; | ||
} | ||
|
||
public function resetFormats() { | ||
|
||
} | ||
|
||
public function nextLanguage() { | ||
return 'en'; | ||
} | ||
|
||
public function resetLanguages() { | ||
|
||
} | ||
|
||
public function nextEncoding() { | ||
return 'gzip'; | ||
} | ||
|
||
public function resetEncodings() { | ||
|
||
} | ||
|
||
public function nextCharset() { | ||
return 'utf-8'; | ||
} | ||
|
||
public function resetCharset() { | ||
|
||
} | ||
|
||
} | ||
?> |
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,35 @@ | ||
<?php | ||
abstract class MimeType { | ||
|
||
static function init() { | ||
// TODO: Cache the MIME Type Data Structure | ||
MimeType::registerMany(array( | ||
array('all', '*/*'), | ||
array('text', 'text/plain', array(), array('txt')), | ||
array('html', 'text/html', array('application/xhtml+xml'), array('xhtml')), | ||
array('js', 'text/javascript', array('application/javascript', 'application/x-javascript')), | ||
array('css', 'text/css'), | ||
array('ics', 'text/calendar'), | ||
array('csv', 'text/csv'), | ||
array('xml', 'application/xml', array('text/xml', 'application/x-xml')), | ||
array('rss', 'application/rss+xml'), | ||
array('atom', 'application/atom+xml'), | ||
array('yaml', 'application/x-yaml', array('text/yaml')), | ||
array('multipart_form', 'multipart/form-data'), | ||
array('url_encoded_form', 'application/x-www-form-urlencoded'), | ||
array('json', 'application/json', array('text/x-json','application/jsonrequest')), | ||
)); | ||
} | ||
|
||
static function register($type, $extension, $synonyms = array()) { | ||
self::registerMany(array(array($type,$extension,$synonyms))); | ||
} | ||
|
||
static function registerMany($array) { | ||
|
||
} | ||
|
||
} | ||
|
||
MimeType::init(); | ||
?> |
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 |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
*/ | ||
class Request { | ||
|
||
public $accepts; | ||
|
||
public $format; | ||
public $headers; | ||
public $resource; | ||
|
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,22 @@ | ||
<?php | ||
Library::import('recess.http.ContentNegotiation'); | ||
|
||
class ContentNegotiationTest extends PHPUnit_Framework_TestCase { | ||
|
||
function testAccepts() { | ||
$negotiator = | ||
new ContentNegotiation( | ||
array( 'ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | ||
'ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', | ||
'ACCEPT_ENCODING' => 'gzip,deflate', | ||
'ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7') | ||
); | ||
|
||
$this->assertEquals('things', Inflector::toPlural('thing')); | ||
$this->assertEquals('persons', Inflector::toPlural('person')); | ||
$this->assertEquals('oxs', Inflector::toPlural('ox')); | ||
} | ||
|
||
} | ||
|
||
?> |
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,16 @@ | ||
<?php | ||
require_once 'PHPUnit/Framework.php'; | ||
require_once 'recess/http/ContentNegotiationTest.php'; | ||
|
||
class RecessHttpAllTests | ||
{ | ||
public static function suite() | ||
{ | ||
$suite = new PHPUnit_Framework_TestSuite('recess.http'); | ||
|
||
$suite->addTestSuite('ContentNegotiationTest'); | ||
|
||
return $suite; | ||
} | ||
} | ||
?> |