From 9b480bda32961f540c81a8445b1cde61b2611092 Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 4 Jul 2011 15:36:11 -0700 Subject: [PATCH 1/3] Some necessary adjustments to JCli --- libraries/joomla/application/cli.php | 16 ++++++++++++---- libraries/joomla/application/cli/daemon.php | 10 ++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libraries/joomla/application/cli.php b/libraries/joomla/application/cli.php index ad6126790b..6a83328cea 100644 --- a/libraries/joomla/application/cli.php +++ b/libraries/joomla/application/cli.php @@ -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'); @@ -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(); @@ -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; diff --git a/libraries/joomla/application/cli/daemon.php b/libraries/joomla/application/cli/daemon.php index e257b608b3..3ccbfc8697 100644 --- a/libraries/joomla/application/cli/daemon.php +++ b/libraries/joomla/application/cli/daemon.php @@ -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 */ @@ -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; @@ -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(); From f1584721960ce9e8a105d699e948abda70c5290b Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 4 Jul 2011 18:02:16 -0700 Subject: [PATCH 2/3] Fixing an error in the JHtml test where a directory is being created when it already exists. These tests need to be seriously looked over at some point but this is a bandaid. --- tests/suite/joomla/html/JHtmlTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/suite/joomla/html/JHtmlTest.php b/tests/suite/joomla/html/JHtmlTest.php index 3d18921611..25fe07e88d 100644 --- a/tests/suite/joomla/html/JHtmlTest.php +++ b/tests/suite/joomla/html/JHtmlTest.php @@ -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 From d3f5c3d9c8dea8fa7312db4b47e0d1658e1c9301 Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 4 Jul 2011 18:55:40 -0700 Subject: [PATCH 3/3] Some minor modifications to JURI and associated tests as well as a new README. --- README | 4 - README.markdown | 27 +++++++ libraries/joomla/environment/uri.php | 83 ++++++++++++++------- tests/suite/joomla/environment/JURITest.php | 9 +++ 4 files changed, 93 insertions(+), 30 deletions(-) delete mode 100644 README create mode 100644 README.markdown diff --git a/README b/README deleted file mode 100644 index 5149b0264b..0000000000 --- a/README +++ /dev/null @@ -1,4 +0,0 @@ -Joomla Platform - -Please ensure you add the following path to your local .gitignore file: -tests/test_application/cache \ No newline at end of file diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000000..a66694b486 --- /dev/null +++ b/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_ + diff --git a/libraries/joomla/environment/uri.php b/libraries/joomla/environment/uri.php index 6bdf2ee3ef..cc0686f578 100644 --- a/libraries/joomla/environment/uri.php +++ b/libraries/joomla/environment/uri.php @@ -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. @@ -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). @@ -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]; } /** @@ -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" @@ -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']; } /** @@ -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']; } /** @@ -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 = ''; } /** diff --git a/tests/suite/joomla/environment/JURITest.php b/tests/suite/joomla/environment/JURITest.php index 104f1f1f3b..1ba496017d 100644 --- a/tests/suite/joomla/environment/JURITest.php +++ b/tests/suite/joomla/environment/JURITest.php @@ -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; }