From f44c565ee46109cba060af962c3ebd5f991c050e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 27 Jan 2012 16:17:43 -0600 Subject: [PATCH] converted path constants to $GLOBALS. --- application/bundle.php | 8 +++---- artisan | 4 ++-- laravel/asset.php | 2 +- laravel/autoloader.php | 6 ++--- laravel/blade.php | 2 +- laravel/bundle.php | 8 +++---- laravel/cache.php | 4 ++-- laravel/cli/artisan.php | 4 ++-- laravel/cli/tasks/bundle/bundler.php | 4 ++-- laravel/cli/tasks/bundle/providers/github.php | 2 +- laravel/cli/tasks/bundle/publisher.php | 4 ++-- laravel/cli/tasks/key.php | 2 +- laravel/cli/tasks/migrate/migrator.php | 2 +- laravel/cli/tasks/session/manager.php | 6 ++--- laravel/cli/tasks/test/runner.php | 24 ++++++++++++++----- laravel/config.php | 2 +- laravel/cookie.php | 2 +- laravel/core.php | 13 ++++------ laravel/crypter.php | 2 +- laravel/database/connectors/sqlite.php | 2 +- laravel/file.php | 4 ++-- laravel/helpers.php | 13 +++++++++- laravel/log.php | 2 +- laravel/session.php | 2 +- laravel/view.php | 2 +- paths.php | 18 ++++---------- phpunit.php | 17 +------------ public/index.php | 2 +- 28 files changed, 80 insertions(+), 83 deletions(-) diff --git a/application/bundle.php b/application/bundle.php index d1b9e362..8e7507f4 100644 --- a/application/bundle.php +++ b/application/bundle.php @@ -16,8 +16,8 @@ */ Autoloader::psr(array( - APP_PATH.'models', - APP_PATH.'libraries', + $GLOBALS['APP_PATH'].'models', + $GLOBALS['APP_PATH'].'libraries', )); /* @@ -37,6 +37,6 @@ */ Autoloader::map(array( - //'User' => APP_PATH.'models/user.php', - //'Role' => APP_PATH.'models/role.php', + //'User' => $GLOBALS['APP_PATH'].'models/user.php', + //'Role' => $GLOBALS['APP_PATH'].'models/role.php', )); \ No newline at end of file diff --git a/artisan b/artisan index b46f317b..0d827f8c 100644 --- a/artisan +++ b/artisan @@ -16,9 +16,9 @@ require 'paths.php'; // -------------------------------------------------------------- // Bootstrap the Laravel core. // -------------------------------------------------------------- -require SYS_PATH.'core.php'; +require $GLOBALS['SYS_PATH'].'core.php'; // -------------------------------------------------------------- // Launch the Laravel "Artisan" CLI. // -------------------------------------------------------------- -require SYS_PATH.'cli/artisan'.EXT; \ No newline at end of file +require $GLOBALS['SYS_PATH'].'cli/artisan'.EXT; \ No newline at end of file diff --git a/laravel/asset.php b/laravel/asset.php index b8aeb448..e2ccd23e 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -1,4 +1,4 @@ - * // Register a class mapping with the Autoloader - * Autoloader::map(array('User' => APP_PATH.'models/user.php')); + * Autoloader::map(array('User' => $GLOBALS['APP_PATH'].'models/user.php')); * * * @param array $mappings diff --git a/laravel/blade.php b/laravel/blade.php index ad30fbcb..15cf20d5 100644 --- a/laravel/blade.php +++ b/laravel/blade.php @@ -1,4 +1,4 @@ - * @@ -182,7 +182,7 @@ public static function class_prefix($bundle) */ public static function path($bundle) { - return ($bundle == DEFAULT_BUNDLE) ? APP_PATH : static::$bundles[$bundle]['location']; + return ($bundle == DEFAULT_BUNDLE) ? $GLOBALS['APP_PATH'] : static::$bundles[$bundle]['location']; } /** diff --git a/laravel/cache.php b/laravel/cache.php index cc044373..2c532d5d 100644 --- a/laravel/cache.php +++ b/laravel/cache.php @@ -1,4 +1,4 @@ -get($bundles) as $bundle) { - if (is_dir(BUNDLE_PATH.$bundle['name'])) + if (is_dir($GLOBALS['BUNDLE_PATH'].$bundle['name'])) { echo "Bundle {$bundle['name']} is already installed."; diff --git a/laravel/cli/tasks/bundle/providers/github.php b/laravel/cli/tasks/bundle/providers/github.php index be8de72c..e2a36087 100644 --- a/laravel/cli/tasks/bundle/providers/github.php +++ b/laravel/cli/tasks/bundle/providers/github.php @@ -17,7 +17,7 @@ public function install($bundle) // a location outside of the Git repository, so we don't need // the full bundle path. We'll just take the basename in case // the bundle directory has been renamed. - $path = basename(BUNDLE_PATH).'/'; + $path = basename($GLOBALS['BUNDLE_PATH']).'/'; passthru('git submodule add '.$repository.' '.$path.$bundle['name']); diff --git a/laravel/cli/tasks/bundle/publisher.php b/laravel/cli/tasks/bundle/publisher.php index 5fc30c84..d15effdb 100644 --- a/laravel/cli/tasks/bundle/publisher.php +++ b/laravel/cli/tasks/bundle/publisher.php @@ -16,7 +16,7 @@ public function publish($bundle) { $path = Bundle::path($bundle); - $this->move($path.'public', PUBLIC_PATH.'bundles'.DS.$bundle); + $this->move($path.'public', $GLOBALS['PUBLIC_PATH'].'bundles'.DS.$bundle); echo "Assets published for bundle [$bundle].".PHP_EOL; } @@ -41,7 +41,7 @@ protected function move($source, $destination) */ protected function to($bundle) { - return PUBLIC_PATH.'bundles'.DS.$bundle.DS; + return $GLOBALS['PUBLIC_PATH'].'bundles'.DS.$bundle.DS; } /** diff --git a/laravel/cli/tasks/key.php b/laravel/cli/tasks/key.php index 91c89239..8b336171 100644 --- a/laravel/cli/tasks/key.php +++ b/laravel/cli/tasks/key.php @@ -19,7 +19,7 @@ class Key extends Task { */ public function __construct() { - $this->path = APP_PATH.'config/application'.EXT; + $this->path = $GLOBALS['APP_PATH'].'config/application'.EXT; } /** diff --git a/laravel/cli/tasks/migrate/migrator.php b/laravel/cli/tasks/migrate/migrator.php index 44dc56d4..4cdf9710 100644 --- a/laravel/cli/tasks/migrate/migrator.php +++ b/laravel/cli/tasks/migrate/migrator.php @@ -222,7 +222,7 @@ public function make($arguments = array()) */ protected function stub($bundle, $migration) { - $stub = File::get(SYS_PATH.'cli/tasks/migrate/stub'.EXT); + $stub = File::get($GLOBALS['SYS_PATH'].'cli/tasks/migrate/stub'.EXT); // The class name is formatted simialrly to tasks and controllers, // where the bundle name is prefixed to the class if it is not in diff --git a/laravel/cli/tasks/session/manager.php b/laravel/cli/tasks/session/manager.php index 7c7dba99..ba6f6136 100644 --- a/laravel/cli/tasks/session/manager.php +++ b/laravel/cli/tasks/session/manager.php @@ -34,7 +34,7 @@ public function install($arguments = array()) // generated on the database. $migration = $migrator->make(array('create_session_table')); - $stub = SYS_PATH.'cli/tasks/session/migration'.EXT; + $stub = $GLOBALS['SYS_PATH'].'cli/tasks/session/migration'.EXT; File::put($migration, File::get($stub)); @@ -42,7 +42,7 @@ public function install($arguments = array()) // Since the developer is requesting that the session table be // created on the database, we'll set the driver to database // to save an extra step for the developer. - $config = File::get(APP_PATH.'config/session'.EXT); + $config = File::get($GLOBALS['APP_PATH'].'config/session'.EXT); $config = str_replace( "'driver' => '',", @@ -50,7 +50,7 @@ public function install($arguments = array()) $config ); - File::put(APP_PATH.'config/session'.EXT, $config); + File::put($GLOBALS['APP_PATH'].'config/session'.EXT, $config); echo PHP_EOL; diff --git a/laravel/cli/tasks/test/runner.php b/laravel/cli/tasks/test/runner.php index 09c39688..02307b9c 100644 --- a/laravel/cli/tasks/test/runner.php +++ b/laravel/cli/tasks/test/runner.php @@ -23,7 +23,7 @@ public function run() */ public function core() { - if ( ! is_dir(BUNDLE_PATH.'laravel-tests')) + if ( ! is_dir($GLOBALS['BUNDLE_PATH'].'laravel-tests')) { throw new \Exception("The bundle [laravel-tests] has not been installed!"); } @@ -31,7 +31,19 @@ public function core() // When testing the Laravel core, we will just stub the path directly // so the test bundle is not required to be registered in the bundle // configuration, as it is kind of a unique bundle. - $this->stub(BUNDLE_PATH.'laravel-tests/cases'); + $this->stub($GLOBALS['BUNDLE_PATH'].'laravel-tests/cases'); + + $path = $GLOBALS['BUNDLE_PATH'].'laravel-tests/'; + + // When testing the framework, we will swap out the application + // and other core paths to stub out the application portion of + // the framework for testing. This allows us to create dummy + // controllers, views, models, etc. + $GLOBALS['APP_PATH'] = $path.'application'.DS; + + $GLOBALS['BUNDLE_PATH'] = $path.'bundles'.DS; + + $GLOBALS['STORAGE_PATH'] = $path.'storage'.DS; $this->test(); } @@ -74,9 +86,9 @@ protected function test() // We'll simply fire off PHPUnit with the configuration switch // pointing to our temporary configuration file. This allows // us to flexibly run tests for any setup. - passthru('phpunit -c '.BASE_PATH.'phpunit.xml'); + passthru('phpunit -c '.$GLOBALS['BASE_PATH'].'phpunit.xml'); - @unlink(BASE_PATH.'phpunit.xml'); + @unlink($GLOBALS['BASE_PATH'].'phpunit.xml'); } /** @@ -87,11 +99,11 @@ protected function test() */ protected function stub($directory) { - $stub = File::get(SYS_PATH.'cli/tasks/test/stub.xml'); + $stub = File::get($GLOBALS['SYS_PATH'].'cli/tasks/test/stub.xml'); $stub = str_replace('{{directory}}', $directory, $stub); - File::put(BASE_PATH.'phpunit.xml', $stub); + File::put($GLOBALS['BASE_PATH'].'phpunit.xml', $stub); } } \ No newline at end of file diff --git a/laravel/config.php b/laravel/config.php index 1d9da14f..72e3dbb7 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -1,4 +1,4 @@ - $value) { diff --git a/laravel/crypter.php b/laravel/crypter.php index eb45a518..4ad37ece 100644 --- a/laravel/crypter.php +++ b/laravel/crypter.php @@ -1,4 +1,4 @@ - * // Get the contents of a file - * $contents = File::get(APP_PATH.'routes'.EXT); + * $contents = File::get($GLOBALS['APP_PATH'].'routes'.EXT); * * // Get the contents of a file or return a default value if it doesn't exist - * $contents = File::get(APP_PATH.'routes'.EXT, 'Default Value'); + * $contents = File::get($GLOBALS['APP_PATH'].'routes'.EXT, 'Default Value'); * * * @param string $path diff --git a/laravel/helpers.php b/laravel/helpers.php index f533999f..720f3ea0 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -1,5 +1,16 @@ path); + $compiled = $GLOBALS['STORAGE_PATH'].'views/'.md5($this->path); // The view will only be re-compiled if the view has been modified // since the last compiled version of the view was created or no diff --git a/paths.php b/paths.php index d21cc45e..bcbfd294 100644 --- a/paths.php +++ b/paths.php @@ -24,7 +24,7 @@ // -------------------------------------------------------------- // Define the path to the base directory. // -------------------------------------------------------------- -define('BASE_PATH', __DIR__.DS); +$GLOBALS['BASE_PATH'] = __DIR__.DS; // -------------------------------------------------------------- // The path to the application directory. @@ -46,21 +46,16 @@ // -------------------------------------------------------------- $paths['STORAGE_PATH'] = 'storage'; -// -------------------------------------------------------------- -// The path to the tests directory. -// -------------------------------------------------------------- -$paths['TESTS_PATH'] = 'tests'; - // -------------------------------------------------------------- // The path to the public directory. // -------------------------------------------------------------- if ($web) { - define('PUBLIC_PATH', realpath('').DS); + $GLOBALS['PUBLIC_PATH'] = realpath('').DS; } else { - $paths['PUBLIC_PATH'] = 'public'; + $paths['PUBLIC'] = 'public'; } // -------------------------------------------------------------- @@ -68,10 +63,7 @@ // -------------------------------------------------------------- foreach ($paths as $name => $path) { - if ( ! defined($name)) - { - if ($web) $path = "../{$path}"; + if ($web) $path = "../{$path}"; - define($name, realpath($path).DS); - } + $GLOBALS[$name] = realpath($path).DS; } \ No newline at end of file diff --git a/phpunit.php b/phpunit.php index e1a1ebd6..d9ea9d46 100644 --- a/phpunit.php +++ b/phpunit.php @@ -13,21 +13,6 @@ // -------------------------------------------------------------- define('DS', DIRECTORY_SEPARATOR); -// -------------------------------------------------------------- -// Override the framework paths if testing Laravel. -// -------------------------------------------------------------- -foreach ($_SERVER['argv'] as $argument) -{ - if (strpos($argument, 'build.xml') !== false) - { - define('APP_PATH', realpath('bundles/laravel-tests/application').DS); - - define('BUNDLE_PATH', realpath('bundles/laravel-tests/bundles').DS); - - define('STORAGE_PATH', realpath('bundles/laravel-tests/storage').DS); - } -} - // -------------------------------------------------------------- // Set the core Laravel path constants. // -------------------------------------------------------------- @@ -36,7 +21,7 @@ // -------------------------------------------------------------- // Bootstrap the Laravel core. // -------------------------------------------------------------- -require SYS_PATH.'core.php'; +require $GLOBALS['SYS_PATH'].'core.php'; // -------------------------------------------------------------- // Start the default bundle. diff --git a/public/index.php b/public/index.php index a683d732..910c07b0 100644 --- a/public/index.php +++ b/public/index.php @@ -31,4 +31,4 @@ // -------------------------------------------------------------- // Launch Laravel. // -------------------------------------------------------------- -require SYS_PATH.'laravel.php'; \ No newline at end of file +require $GLOBALS['SYS_PATH'].'laravel.php'; \ No newline at end of file