Skip to content

Commit

Permalink
Some minor modifications to JURI and associated tests as well as a new
Browse files Browse the repository at this point in the history
README.
  • Loading branch information
LouisLandry committed Jul 5, 2011
1 parent f158472 commit d3f5c3d
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 30 deletions.
4 changes: 0 additions & 4 deletions README

This file was deleted.

27 changes: 27 additions & 0 deletions README.markdown
@@ -0,0 +1,27 @@
Joomla Platform
===============

The *Joomla Platform* is a platform for writing Web and command line applications in PHP. It is free and open source software,
distributed under the GNU General Public License version 2 or later. The Joomla Content Management System (CMS) is built on
top of the *Joomla Platform*. For more information about the Joomla CMS visit: http://www.joomla.org/about-joomla.html

You can find out more about Joomla development *(though not platform specific)* at: http://docs.joomla.org/Developers

You can discuss *Joomla Platform* development at: http://groups.google.com/group/joomla-dev-framework


Requirements
------------

* PHP 5.3+


Installation
------------

Get the source code from GIT:

git clone git://github.com/joomla/joomla-platform.git

_Please ensure you add the following path to your local .gitignore file: tests/test_application/cache_

83 changes: 57 additions & 26 deletions libraries/joomla/environment/uri.php
Expand Up @@ -84,6 +84,30 @@ class JURI extends JObject
*/
protected $_vars = array ();

/**
* @var array An array of JURI instances.
* @since 11.1
*/
protected static $instances = array();

/**
* @var array The current calculated base url segments.
* @since 11.1
*/
protected static $base = array();

/**
* @var array The current calculated root url segments.
* @since 11.1
*/
protected static $root = array();

/**
* @var string The current url.
* @since 11.1
*/
protected static $current;

/**
* Constructor.
* You can pass a URI string to the constructor to initialise a specific URI.
Expand Down Expand Up @@ -121,9 +145,8 @@ public function __toString()
*/
public static function getInstance($uri = 'SERVER')
{
static $instances = array();

if (!isset($instances[$uri])) {
if (empty(self::$instances[$uri])) {
// Are we obtaining the URI from the server?
if ($uri == 'SERVER') {
// Determine if the request was over SSL (HTTPS).
Expand Down Expand Up @@ -163,9 +186,9 @@ public static function getInstance($uri = 'SERVER')
}

// Create the new JURI instance
$instances[$uri] = new JURI($theURI);
self::$instances[$uri] = new JURI($theURI);
}
return $instances[$uri];
return self::$instances[$uri];
}

/**
Expand All @@ -178,24 +201,22 @@ public static function getInstance($uri = 'SERVER')
*/
public static function base($pathonly = false)
{
static $base;

// Get the base request path.
if (!isset($base)) {
if (empty(self::$base)) {
$config = JFactory::getConfig();
$live_site = $config->get('live_site');
if (trim($live_site) != '') {
$uri = self::getInstance($live_site);
$base['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
$base['path'] = rtrim($uri->toString(array('path')), '/\\');
self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
self::$base['path'] = rtrim($uri->toString(array('path')), '/\\');

if (JPATH_BASE == JPATH_ADMINISTRATOR) {
$base['path'] .= '/administrator';
self::$base['path'] .= '/administrator';
}
}
else {
$uri = self::getInstance();
$base['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port'));

if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) {
// PHP-CGI on Apache with "cgi.fix_pathinfo = 0"
Expand All @@ -209,11 +230,11 @@ public static function base($pathonly = false)
$script_name = $_SERVER['SCRIPT_NAME'];
}

$base['path'] = rtrim(dirname($script_name), '/\\');
self::$base['path'] = rtrim(dirname($script_name), '/\\');
}
}

return $pathonly === false ? $base['prefix'].$base['path'].'/' : $base['path'];
return $pathonly === false ? self::$base['prefix'].self::$base['path'].'/' : self::$base['path'];
}

/**
Expand All @@ -226,21 +247,19 @@ public static function base($pathonly = false)
*/
public static function root($pathonly = false, $path = null)
{
static $root;

// Get the scheme
if (!isset($root)) {
$uri = self::getInstance(self::base());
$root['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
$root['path'] = rtrim($uri->toString(array('path')), '/\\');
if (empty(self::$root)) {
$uri = self::getInstance(self::base());
self::$root['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
self::$root['path'] = rtrim($uri->toString(array('path')), '/\\');
}

// Get the scheme
if (isset($path)) {
$root['path'] = $path;
self::$root['path'] = $path;
}

return $pathonly === false ? $root['prefix'].$root['path'].'/' : $root['path'];
return $pathonly === false ? self::$root['prefix'].self::$root['path'].'/' : self::$root['path'];
}

/**
Expand All @@ -251,15 +270,27 @@ public static function root($pathonly = false, $path = null)
*/
public static function current()
{
static $current;

// Get the current URL.
if (!isset($current)) {
if (empty(self::$current)) {
$uri = self::getInstance();
$current = $uri->toString(array('scheme', 'host', 'port', 'path'));
self::$current = $uri->toString(array('scheme', 'host', 'port', 'path'));
}

return $current;
return self::$current;
}

/**
* Method to reset class static members for testing and other various issues.
*
* @return void
* @since 11.1
*/
public static function reset()
{
self::$instances = array();
self::$base = array();
self::$root = array();
self::$current = '';
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/suite/joomla/environment/JURITest.php
Expand Up @@ -30,6 +30,15 @@ class JURITest extends PHPUnit_Framework_TestCase
*/
protected function setUp()
{
parent::setUp();

JURI::reset();

$_SERVER['HTTP_HOST'] = 'www.example.com:80';
$_SERVER['SCRIPT_NAME'] = '/joomla/index.php';
$_SERVER['PHP_SELF'] = '/joomla/index.php';
$_SERVER['REQUEST_URI'] = '/joomla/index.php?var=value 10';

$this->object = new JURI;
}

Expand Down

0 comments on commit d3f5c3d

Please sign in to comment.