Skip to content

Commit

Permalink
Merge pull request joomla#72 from LouisLandry/master
Browse files Browse the repository at this point in the history
Some modifications to fix unit tests, etc.
  • Loading branch information
LouisLandry committed Jul 5, 2011
2 parents 21a0433 + d3f5c3d commit ecf6ffa
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 39 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_

16 changes: 12 additions & 4 deletions libraries/joomla/application/cli.php
Expand Up @@ -10,7 +10,7 @@
defined('JPATH_PLATFORM') or die;

jimport('joomla.application.applicationexception');
jimport('joomla.application.input.cli');
jimport('joomla.application.input');
jimport('joomla.event.dispatcher');
jimport('joomla.log.log');
jimport('joomla.registry.registry');
Expand Down Expand Up @@ -57,7 +57,9 @@ protected function __construct()
}

// Get the command line options
$this->input = new JInputCli();
if (class_exists('JInput')) {
$this->input = new JInputCli();
}

// Create the registry with a default namespace of config
$this->config = new JRegistry();
Expand All @@ -80,13 +82,19 @@ protected function __construct()
* This method must be invoked as: $cli = JCli::getInstance();
*
* @return JCli A JCli object
*
* @since 11.1
*/
public static function & getInstance()
public static function & getInstance($name = null)
{
// Only create the object if it doesn't exist.
if (empty(self::$instance)) {
self::$instance = new JCli();
if (class_exists($name) && ($name instanceof JCli)) {
self::$instance = new $name();
}
else {
self::$instance = new JCli();
}
}

return self::$instance;
Expand Down
10 changes: 6 additions & 4 deletions libraries/joomla/application/cli/daemon.php
Expand Up @@ -19,7 +19,7 @@
* @package Joomla.Platform
* @subpackage Application
* @since 11.1
*
*
* @see http://www.php.net/manual/en/book.pcntl.php
* @see http://php.net/manual/en/features.commandline.php
*/
Expand All @@ -40,8 +40,8 @@ class JDaemon extends JCli
/**
* Exiting status
* True if the daemon is in the process of exiting.
*
* @var boolean
*
* @var boolean
* @since 11.1
*/
protected $exiting = false;
Expand Down Expand Up @@ -87,7 +87,9 @@ protected function __construct()

// Set some system limits.
set_time_limit($this->config->get('max_execution_time', 0));
ini_set('memory_limit',isset($config['max_memory_limit']) ? $config['max_memory_limit'] : $this->config->get('max_memory_limit', '256M'));
if ($this->config->get('max_memory_limit') !== null) {
ini_set('memory_limit', $this->config->get('max_memory_limit', '256M'));
}

// Flush content immediatly.
ob_implicit_flush();
Expand Down
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
4 changes: 3 additions & 1 deletion tests/suite/joomla/html/JHtmlTest.php
Expand Up @@ -309,7 +309,9 @@ public function testImage()
rmdir(JPATH_THEMES .'/'. $template);

// we create the file that JHtml::image will look for
mkdir(JPATH_ROOT .'/media/'. $urlpath .'images', 0777, true);
if (!is_dir(JPATH_ROOT .'/media/'. $urlpath .'images')) {
mkdir(JPATH_ROOT .'/media/'. $urlpath .'images', 0777, true);
}
file_put_contents(JPATH_ROOT .'/media/'. $urlpath .'images/'. $urlfilename, 'test');

// we do a test for the case that the image is in the templates directory
Expand Down

0 comments on commit ecf6ffa

Please sign in to comment.