Skip to content

Commit

Permalink
Use ConfigObj
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Aug 4, 2014
1 parent dea278a commit 4924dd7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
12 changes: 6 additions & 6 deletions src/Core/ConfigObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
namespace Gt\Core;

/**
* @property-read string $api_prefix
* @property-read string $api_default_type
* @property-read bool $pageview_html_extension
* @property-read bool $pageview_trailing_directory_slash
* @property-read string $index_filename
* @property-read bool $index_force
* @property string $api_prefix
* @property string $api_default_type
* @property bool $pageview_html_extension
* @property bool $pageview_trailing_directory_slash
* @property string $index_filename
* @property bool $index_force
*/
class ConfigObj extends Obj {}#
27 changes: 16 additions & 11 deletions src/Request/Standardiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses
*/
namespace Gt\Request;
use Gt\Core\Obj;
use Gt\Core\ConfigObj;

class Standardiser {

/**
* Takes a URL and fixes it according to the configuration properties
* @param string $uri The request URI
* @param Obj $config Object containing request configuration properties
* @param ConfigObj $config Object containing request configuration properties
*
* @return string The new URI, standardised to configuration options
*/
public function fixUri($uri, Obj $config) {
public function fixUri($uri, ConfigObj $config) {
$fixed = $uri;
$pathinfo = pathinfo($fixed);
$file = strtok($pathinfo["filename"], "?");
Expand All @@ -41,10 +42,11 @@ public function fixUri($uri, Obj $config) {
* @param string $uri The request URI
* @param string $file The requested file name, with no path.
* @param string $ext The requested file extension, or null.
* @param Obj $config The provided configuration options object.
* @param ConfigObj $config The provided configuration options object.
*
* @return string The fixed URI.
*/
public function fixHtmlExtension($uri, $file, $ext, $config) {
public function fixHtmlExtension($uri, $file, $ext, ConfigObj $config) {
if(!isset($config->pageview_html_extension)) {
return $uri;
}
Expand Down Expand Up @@ -79,10 +81,11 @@ public function fixHtmlExtension($uri, $file, $ext, $config) {
* @param string $uri The request URI
* @param string $file The requested file name, with no path.
* @param string $ext The requested file extension, or null.
* @param Obj $config The provided configuration options object.
* @param ConfigObj $config The provided configuration options object.
*
* @return string The fixed URI.
*/
public function fixIndexFilename($uri, $file, $ext, $config) {
public function fixIndexFilename($uri, $file, $ext, ConfigObj $config) {
if(!isset($config->index_force)
|| !isset($config->index_filename)) {
return $uri;
Expand Down Expand Up @@ -119,10 +122,11 @@ public function fixIndexFilename($uri, $file, $ext, $config) {
* @param string $uri The request URI
* @param string $file The requested file name, with no path.
* @param string $ext The requested file extension, or null.
* @param Obj $config The provided configuration options object.
* @param ConfigObj $config The provided configuration options object.
*
* @return string The fixed URI.
*/
public function fixTrailingSlash($uri, $file, $ext, $config) {
public function fixTrailingSlash($uri, $file, $ext, ConfigObj $config) {
if(!isset($config->pageview_trailing_directory_slash)) {
return $uri;
}
Expand Down Expand Up @@ -153,10 +157,11 @@ public function fixTrailingSlash($uri, $file, $ext, $config) {
* @param string $uri The request URI
* @param string $file The requested file name, with no path.
* @param string $ext The requested file extension, or null.
* @param Obj $config The provided configuration options object.
* @param ConfigObj $config The provided configuration options object.
*
* @return string The fixed URI.
*/
public function fixTrailingExtSlash($uri, $file, $ext, $config) {
public function fixTrailingExtSlash($uri, $file, $ext, ConfigObj $config) {
$lastChar = substr($uri, -1);
if(!empty($ext) && $lastChar === "/") {
$uri = substr($uri, 0, strrpos($uri, "/"));
Expand Down
27 changes: 14 additions & 13 deletions test/Unit/Request/Standardiser.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @license Apache Version 2.0, January 2004. http://www.apache.org/licenses
*/
namespace Gt\Request;
use \Gt\Core\Obj;
use \Gt\Core\ConfigObj;

class Standardiser_Test extends \PHPUnit_Framework_TestCase {

Expand Down Expand Up @@ -71,15 +71,15 @@ public function testFixHtmlExtension($uri) {
$standardiser = new Standardiser();

$this->assertEquals($uri, $standardiser->fixHtmlExtension(
$uri, $file, $ext, new Obj()) );
$uri, $file, $ext, new ConfigObj()) );

$config = new Obj();
$config = new ConfigObj();
$config->pageview_html_extension = false;

$fixed = $standardiser->fixHtmlExtension($uri, $file, $ext, $config);
$this->assertNotRegexp("/\.html.?$/", $fixed);

$config = new Obj();
$config = new ConfigObj();
$config->pageview_html_extension = true;

$fixed = $standardiser->fixHtmlExtension($uri, $file, $ext, $config);
Expand Down Expand Up @@ -107,7 +107,7 @@ public function testFixHtmlExtension($uri) {
public function testFixIndexFilenameForce($uri, $index) {
$this->pathinfo($uri, $file, $ext);

$config = new Obj();
$config = new ConfigObj();
$config->index_force = true;
$config->index_filename = $index;

Expand All @@ -127,9 +127,9 @@ public function testFixIndexFilenameNoForce($uri, $index) {
$this->pathinfo($uri, $file, $ext);
$standardiser = new Standardiser();
$this->assertEquals($uri,
$standardiser->fixIndexFilename($uri, $file, $ext, new Obj()) );
$standardiser->fixIndexFilename($uri, $file, $ext, new ConfigObj()) );

$config = new Obj();
$config = new ConfigObj();
$config->index_force = false;
$config->index_filename = $index;

Expand All @@ -149,9 +149,9 @@ public function testFixTrailingSlash($uri) {
$this->pathinfo($uri, $file, $ext);
$standardiser = new Standardiser();
$this->assertEquals($uri,
$standardiser->fixTrailingSlash($uri, $file, $ext, new Obj()));
$standardiser->fixTrailingSlash($uri, $file, $ext, new ConfigObj()));

$config = new Obj();
$config = new ConfigObj();
$config->pageview_trailing_directory_slash = true;

$fixed = $standardiser->fixTrailingSlash($uri, $file, $ext, $config);
Expand All @@ -174,9 +174,9 @@ public function testFixNoTrailingSlash($uri) {
$this->pathinfo($uri, $file, $ext);
$standardiser = new Standardiser();
$this->assertEquals($uri,
$standardiser->fixTrailingSlash($uri, $file, $ext, new Obj()));
$standardiser->fixTrailingSlash($uri, $file, $ext, new ConfigObj()));

$config = new Obj();
$config = new ConfigObj();
$config->pageview_trailing_directory_slash = false;

$fixed = $standardiser->fixTrailingSlash($uri, $file, $ext, $config);
Expand All @@ -198,7 +198,8 @@ public function testFixNoTrailingSlash($uri) {
public function testFixTrailingExtSlash($uri) {
$this->pathinfo($uri, $file, $ext);
$standardiser = new Standardiser();
$fixed = $standardiser->fixTrailingExtSlash($uri, $file, $ext, new Obj());
$fixed = $standardiser->fixTrailingExtSlash(
$uri, $file, $ext, new ConfigObj());

if(!empty($ext)) {
$this->assertStringEndsNotWith("/", $fixed);
Expand All @@ -214,7 +215,7 @@ public function testFixTrailingExtSlash($uri) {
*/
public function testFixUri($uri) {
$standardiser = new Standardiser();
$fixed = $standardiser->fixUri($uri, new Obj());
$fixed = $standardiser->fixUri($uri, new ConfigObj());
$this->assertInternalType("string", $fixed);
}

Expand Down

0 comments on commit 4924dd7

Please sign in to comment.