From 97fcea1e51f8cf936bb9aa97800c18543744963e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 28 Jan 2012 14:55:08 -0600 Subject: [PATCH] cleaned up paths. --- application/bundle.php | 8 ++--- artisan | 6 ++-- 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 | 14 ++++---- laravel/config.php | 2 +- laravel/cookie.php | 2 +- laravel/core.php | 10 +++--- laravel/crypter.php | 2 +- laravel/database/connectors/sqlite.php | 2 +- laravel/file.php | 4 +-- laravel/helpers.php | 13 +------ laravel/laravel.php | 2 +- laravel/log.php | 2 +- laravel/session.php | 2 +- laravel/view.php | 2 +- paths.php | 34 ++++++++++++++----- phpunit.php | 12 +++---- public/index.php | 4 +-- 29 files changed, 86 insertions(+), 81 deletions(-) diff --git a/application/bundle.php b/application/bundle.php index 8e7507f4..f9b925c9 100644 --- a/application/bundle.php +++ b/application/bundle.php @@ -16,8 +16,8 @@ */ Autoloader::psr(array( - $GLOBALS['APP_PATH'].'models', - $GLOBALS['APP_PATH'].'libraries', + path('app').'models', + path('app').'libraries', )); /* @@ -37,6 +37,6 @@ Autoloader::psr(array( */ Autoloader::map(array( - //'User' => $GLOBALS['APP_PATH'].'models/user.php', - //'Role' => $GLOBALS['APP_PATH'].'models/role.php', + //'User' => path('app').'models/user.php', + //'Role' => path('app').'models/role.php', )); \ No newline at end of file diff --git a/artisan b/artisan index 0d827f8c..53bd0a67 100644 --- a/artisan +++ b/artisan @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 2.2.0 (Beta 1) + * @version 3.0.0 * @author Taylor Otwell * @link http://laravel.com */ @@ -16,9 +16,9 @@ require 'paths.php'; // -------------------------------------------------------------- // Bootstrap the Laravel core. // -------------------------------------------------------------- -require $GLOBALS['SYS_PATH'].'core.php'; +require path('sys').'core.php'; // -------------------------------------------------------------- // Launch the Laravel "Artisan" CLI. // -------------------------------------------------------------- -require $GLOBALS['SYS_PATH'].'cli/artisan'.EXT; \ No newline at end of file +require path('sys').'cli/artisan'.EXT; \ No newline at end of file diff --git a/laravel/asset.php b/laravel/asset.php index e2ccd23e..dea24519 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -1,4 +1,4 @@ - * // Register a class mapping with the Autoloader - * Autoloader::map(array('User' => $GLOBALS['APP_PATH'].'models/user.php')); + * Autoloader::map(array('User' => path('app').'models/user.php')); * * * @param array $mappings diff --git a/laravel/blade.php b/laravel/blade.php index 15cf20d5..535e2736 100644 --- a/laravel/blade.php +++ b/laravel/blade.php @@ -1,4 +1,4 @@ - * @@ -182,7 +182,7 @@ class Bundle { */ public static function path($bundle) { - return ($bundle == DEFAULT_BUNDLE) ? $GLOBALS['APP_PATH'] : static::$bundles[$bundle]['location']; + return ($bundle == DEFAULT_BUNDLE) ? path('app') : static::$bundles[$bundle]['location']; } /** diff --git a/laravel/cache.php b/laravel/cache.php index 2c532d5d..a27db042 100644 --- a/laravel/cache.php +++ b/laravel/cache.php @@ -1,4 +1,4 @@ -get($bundles) as $bundle) { - if (is_dir($GLOBALS['BUNDLE_PATH'].$bundle['name'])) + if (is_dir(path('bundle').$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 e2a36087..0ccb2ca5 100644 --- a/laravel/cli/tasks/bundle/providers/github.php +++ b/laravel/cli/tasks/bundle/providers/github.php @@ -17,7 +17,7 @@ class Github implements Provider { // 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($GLOBALS['BUNDLE_PATH']).'/'; + $path = basename(path('bundle')).'/'; 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 d15effdb..209e8345 100644 --- a/laravel/cli/tasks/bundle/publisher.php +++ b/laravel/cli/tasks/bundle/publisher.php @@ -16,7 +16,7 @@ class Publisher { { $path = Bundle::path($bundle); - $this->move($path.'public', $GLOBALS['PUBLIC_PATH'].'bundles'.DS.$bundle); + $this->move($path.'public', path('public').'bundles'.DS.$bundle); echo "Assets published for bundle [$bundle].".PHP_EOL; } @@ -41,7 +41,7 @@ class Publisher { */ protected function to($bundle) { - return $GLOBALS['PUBLIC_PATH'].'bundles'.DS.$bundle.DS; + return path('public').'bundles'.DS.$bundle.DS; } /** diff --git a/laravel/cli/tasks/key.php b/laravel/cli/tasks/key.php index 8b336171..883f1e22 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 = $GLOBALS['APP_PATH'].'config/application'.EXT; + $this->path = path('app').'config/application'.EXT; } /** diff --git a/laravel/cli/tasks/migrate/migrator.php b/laravel/cli/tasks/migrate/migrator.php index 4cdf9710..32248527 100644 --- a/laravel/cli/tasks/migrate/migrator.php +++ b/laravel/cli/tasks/migrate/migrator.php @@ -222,7 +222,7 @@ class Migrator extends Task { */ protected function stub($bundle, $migration) { - $stub = File::get($GLOBALS['SYS_PATH'].'cli/tasks/migrate/stub'.EXT); + $stub = File::get(path('sys').'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 ba6f6136..739ff79b 100644 --- a/laravel/cli/tasks/session/manager.php +++ b/laravel/cli/tasks/session/manager.php @@ -34,7 +34,7 @@ class Manager extends Task { // generated on the database. $migration = $migrator->make(array('create_session_table')); - $stub = $GLOBALS['SYS_PATH'].'cli/tasks/session/migration'.EXT; + $stub = path('sys').'cli/tasks/session/migration'.EXT; File::put($migration, File::get($stub)); @@ -42,7 +42,7 @@ class Manager extends Task { // 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($GLOBALS['APP_PATH'].'config/session'.EXT); + $config = File::get(path('app').'config/session'.EXT); $config = str_replace( "'driver' => '',", @@ -50,7 +50,7 @@ class Manager extends Task { $config ); - File::put($GLOBALS['APP_PATH'].'config/session'.EXT, $config); + File::put(path('app').'config/session'.EXT, $config); echo PHP_EOL; diff --git a/laravel/cli/tasks/test/runner.php b/laravel/cli/tasks/test/runner.php index 60a2ec4b..06066c26 100644 --- a/laravel/cli/tasks/test/runner.php +++ b/laravel/cli/tasks/test/runner.php @@ -23,7 +23,7 @@ class Runner extends Task { */ public function core() { - if ( ! is_dir($GLOBALS['BUNDLE_PATH'].'laravel-tests')) + if ( ! is_dir(path('bundle').'laravel-tests')) { throw new \Exception("The bundle [laravel-tests] has not been installed!"); } @@ -31,9 +31,9 @@ class Runner extends Task { // 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($GLOBALS['BUNDLE_PATH'].'laravel-tests/cases'); + $this->stub(path('bundle').'laravel-tests/cases'); - $path = $GLOBALS['BUNDLE_PATH'].'laravel-tests/'; + $path = path('bundle').'laravel-tests/'; $this->test(); } @@ -76,9 +76,9 @@ class Runner extends Task { // 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 '.$GLOBALS['BASE_PATH'].'phpunit.xml'); + passthru('phpunit -c '.path('base').'phpunit.xml'); - @unlink($GLOBALS['BASE_PATH'].'phpunit.xml'); + @unlink(path('base').'phpunit.xml'); } /** @@ -89,11 +89,11 @@ class Runner extends Task { */ protected function stub($directory) { - $stub = File::get($GLOBALS['SYS_PATH'].'cli/tasks/test/stub.xml'); + $stub = File::get(path('sys').'cli/tasks/test/stub.xml'); $stub = str_replace('{{directory}}', $directory, $stub); - File::put($GLOBALS['BASE_PATH'].'phpunit.xml', $stub); + File::put(path('base').'phpunit.xml', $stub); } } \ No newline at end of file diff --git a/laravel/config.php b/laravel/config.php index 72e3dbb7..909e4222 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 4ad37ece..6ddea304 100644 --- a/laravel/crypter.php +++ b/laravel/crypter.php @@ -1,4 +1,4 @@ - * // Get the contents of a file - * $contents = File::get($GLOBALS['APP_PATH'].'routes'.EXT); + * $contents = File::get(path('app').'routes'.EXT); * * // Get the contents of a file or return a default value if it doesn't exist - * $contents = File::get($GLOBALS['APP_PATH'].'routes'.EXT, 'Default Value'); + * $contents = File::get(path('app').'routes'.EXT, 'Default Value'); * * * @param string $path diff --git a/laravel/helpers.php b/laravel/helpers.php index 720f3ea0..dc887317 100644 --- a/laravel/helpers.php +++ b/laravel/helpers.php @@ -1,16 +1,5 @@ diff --git a/laravel/laravel.php b/laravel/laravel.php index 58514985..9e6d6b56 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -12,8 +12,8 @@ require 'core.php'; * default timezone used by all date / timezone functions throughout * the entire application. */ - date_default_timezone_set(Config::get('application.timezone')); + /** * Register the PHP exception handler. The framework throws exceptions * on every error that cannot be handled. All of those exceptions will diff --git a/laravel/log.php b/laravel/log.php index ad1fda81..2d6bf49d 100644 --- a/laravel/log.php +++ b/laravel/log.php @@ -43,7 +43,7 @@ class Log { { $message = date('Y-m-d H:i:s').' '.Str::upper($type)." - {$message}".PHP_EOL; - File::append($GLOBALS['STORAGE_PATH'].'logs/'.date('Y-m-d').'.log', $message); + File::append(path('storage').'logs/'.date('Y-m-d').'.log', $message); } /** diff --git a/laravel/session.php b/laravel/session.php index 744b0ca6..b108772d 100644 --- a/laravel/session.php +++ b/laravel/session.php @@ -52,7 +52,7 @@ class Session { return new Session\Drivers\Database(Database::connection()); case 'file': - return new Session\Drivers\File($GLOBALS['STORAGE_PATH'].'sessions'.DS); + return new Session\Drivers\File(path('storage').'sessions'.DS); case 'memcached': return new Session\Drivers\Memcached(Cache::driver('memcached')); diff --git a/laravel/view.php b/laravel/view.php index 1dfba4fc..3aa3f733 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -261,7 +261,7 @@ class View implements ArrayAccess { // hash of their path. This allows us to easily store the views in // the directory without worrying about re-creating the entire // application view directory structure. - $compiled = $GLOBALS['STORAGE_PATH'].'views/'.md5($this->path); + $compiled = path('storage').'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 bcbfd294..f4b0f451 100644 --- a/paths.php +++ b/paths.php @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 2.2.0 (Beta 1) + * @version 3.0.0 * @author Taylor Otwell * @link http://laravel.com */ @@ -24,38 +24,38 @@ if ( ! defined('DS')) // -------------------------------------------------------------- // Define the path to the base directory. // -------------------------------------------------------------- -$GLOBALS['BASE_PATH'] = __DIR__.DS; +$GLOBALS['laravel_paths']['base'] = __DIR__.DS; // -------------------------------------------------------------- // The path to the application directory. // -------------------------------------------------------------- -$paths['APP_PATH'] = 'application'; +$paths['app'] = 'application'; // -------------------------------------------------------------- // The path to the Laravel directory. // -------------------------------------------------------------- -$paths['SYS_PATH'] = 'laravel'; +$paths['sys'] = 'laravel'; // -------------------------------------------------------------- // The path to the bundles directory. // -------------------------------------------------------------- -$paths['BUNDLE_PATH'] = 'bundles'; +$paths['bundle'] = 'bundles'; // -------------------------------------------------------------- // The path to the storage directory. // -------------------------------------------------------------- -$paths['STORAGE_PATH'] = 'storage'; +$paths['storage'] = 'storage'; // -------------------------------------------------------------- // The path to the public directory. // -------------------------------------------------------------- if ($web) { - $GLOBALS['PUBLIC_PATH'] = realpath('').DS; + $GLOBALS['laravel_paths']['public'] = realpath('').DS; } else { - $paths['PUBLIC'] = 'public'; + $paths['public'] = 'public'; } // -------------------------------------------------------------- @@ -65,5 +65,21 @@ foreach ($paths as $name => $path) { if ($web) $path = "../{$path}"; - $GLOBALS[$name] = realpath($path).DS; + $GLOBALS['laravel_paths'][$name] = realpath($path).DS; +} + +// -------------------------------------------------------------- +// Define a global path helper function. +// -------------------------------------------------------------- +function path($path) +{ + return $GLOBALS['laravel_paths'][$path]; +} + +// -------------------------------------------------------------- +// Define a global path setter function. +// -------------------------------------------------------------- +function set_path($path, $value) +{ + $GLOBALS['laravel_paths'][$path] = $value; } \ No newline at end of file diff --git a/phpunit.php b/phpunit.php index 1bdb1619..4db1ea94 100644 --- a/phpunit.php +++ b/phpunit.php @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 2.2.0 (Beta 1) + * @version 3.0.0 * @author Taylor Otwell * @link http://laravel.com */ @@ -25,19 +25,19 @@ $config = file_get_contents('phpunit.xml'); if (strpos($config, 'laravel-tests') !== false) { - $path = $GLOBALS['BUNDLE_PATH'].'laravel-tests'.DS; + $path = path('bundle').'laravel-tests'.DS; - $GLOBALS['APP_PATH'] = $path.'application'.DS; + set_path('app', $path.'application'.DS); - $GLOBALS['BUNDLE_PATH'] = $path.'bundles'.DS; + set_path('bundle', $path.'bundles'.DS); - $GLOBALS['STORAGE_PATH'] = $path.'storage'.DS; + set_path('storage', $path.'storage'.DS); } // -------------------------------------------------------------- // Bootstrap the Laravel core. // -------------------------------------------------------------- -require $GLOBALS['SYS_PATH'].'core.php'; +require path('sys').'core.php'; // -------------------------------------------------------------- // Start the default bundle. diff --git a/public/index.php b/public/index.php index 910c07b0..e326a3e2 100644 --- a/public/index.php +++ b/public/index.php @@ -3,7 +3,7 @@ * Laravel - A PHP Framework For Web Artisans * * @package Laravel - * @version 3.0.0 (Beta 2) + * @version 3.0.0 * @author Taylor Otwell * @link http://laravel.com */ @@ -31,4 +31,4 @@ unset($web); // -------------------------------------------------------------- // Launch Laravel. // -------------------------------------------------------------- -require $GLOBALS['SYS_PATH'].'laravel.php'; \ No newline at end of file +require path('sys').'laravel.php'; \ No newline at end of file