Move application structure paths to a config file so it can be loaded from CLI tool also.

This commit is contained in:
Lonnie Ezell 2017-01-15 23:35:14 -06:00
parent f1e6671fcf
commit 144cc2b1ae
No known key found for this signature in database
GPG Key ID: 88F86F2034554774
5 changed files with 104 additions and 82 deletions

View File

@ -0,0 +1,64 @@
<?php namespace Config;
/**
* Holds the paths that are used by the system to
* locate the main directories, application, system, etc.
* Modifying these allows you to re-structure your application,
* share a system folder between multiple applications, and more.
*
* All paths are relative to the application's front controller, index.php
*/
class Paths
{
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
*/
public $systemDirectory = '../system';
/*
*---------------------------------------------------------------
* APPLICATION FOLDER NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* folder than the default one you can set its name here. The folder
* can also be renamed or relocated anywhere on your getServer. If
* you do, use a full getServer path. For more info please see the user guide:
* http://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*/
public $applicationDirectory = '../application';
/*
* ---------------------------------------------------------------
* WRITABLE DIRECTORY NAME
* ---------------------------------------------------------------
*
* This variable must contain the name of your "writable" directory.
* The writable directory allows you to group all directories that
* need write permission to a single place that can be tucked away
* for maximum security, keeping it out of the application and/or
* system directories.
*/
public $writableDirectory = '../writable';
/*
* ---------------------------------------------------------------
* TESTS DIRECTORY NAME
* ---------------------------------------------------------------
*
* This variable must contain the name of your "tests" directory.
* The writable directory allows you to group all directories that
* need write permission to a single place that can be tucked away
* for maximum security, keeping it out of the application and/or
* system directories.
*/
public $testsDirectory = '../tests';
}

View File

@ -1,56 +1,9 @@
<?php
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
*/
$system_directory = '../system';
/*
*---------------------------------------------------------------
* APPLICATION FOLDER NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* folder than the default one you can set its name here. The folder
* can also be renamed or relocated anywhere on your getServer. If
* you do, use a full getServer path. For more info please see the user guide:
* http://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*/
$application_directory = '../application';
/*
* ---------------------------------------------------------------
* WRITABLE DIRECTORY NAME
* ---------------------------------------------------------------
*
* This variable must contain the name of your "writable" directory.
* The writable directory allows you to group all directories that
* need write permission to a single place that can be tucked away
* for maximum security, keeping it out of the application and/or
* system directories.
*/
$writable_directory = '../writable';
/*
* ---------------------------------------------------------------
* TESTS DIRECTORY NAME
* ---------------------------------------------------------------
*
* This variable must contain the name of your "tests" directory.
* The writable directory allows you to group all directories that
* need write permission to a single place that can be tucked away
* for maximum security, keeping it out of the application and/or
* system directories.
*/
$tests_directory = '../tests';
// Location to the Paths config file.
// This should be the only line you need to
// edit in this file.
$pathsPath = '../application/Config/Paths.php';
// Path to the front controller (this file)
define('FCPATH', __DIR__.DIRECTORY_SEPARATOR);
@ -67,7 +20,11 @@ define('FCPATH', __DIR__.DIRECTORY_SEPARATOR);
// Ensure the current directory is pointing to the front controller's directory
chdir(__DIR__);
$app = require rtrim($system_directory,'/ ').'/bootstrap.php';
// Load our paths config file
require $pathsPath;
$paths = new Config\Paths();
$app = require rtrim($paths->systemDirectory,'/ ').'/bootstrap.php';
/*
*---------------------------------------------------------------

View File

@ -1,15 +1,20 @@
<?php namespace CodeIgniter;
use CodeIgniter\Config\DotEnv;
use CodeIgniter\Debug\Timer;
use CodeIgniter\Hooks\Hooks;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\URI;
use CodeIgniter\Router\RouteCollectionInterface;
use Config\Cache;
use Config\Services;
use CodeIgniter\HTTP\URI;
use CodeIgniter\Debug\Timer;
use CodeIgniter\Hooks\Hooks;
use CodeIgniter\Config\DotEnv;
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\CLIRequest;
use CodeIgniter\Router\RouteCollectionInterface;
/**
* This class is the core of the framework, and will analyse the
* request, route it to a controller, and send back the response.
* Of course, there are variations to that flow, but this is the brains.
*/
class CodeIgniter
{
/**

View File

@ -10,21 +10,21 @@
* so they are available in the config files that are loaded.
*/
// Path to the system folder
define('BASEPATH', realpath($system_directory).DIRECTORY_SEPARATOR);
// Path to code root folder (just up from public)
$pos = strrpos(FCPATH, 'public'.DIRECTORY_SEPARATOR);
define('ROOTPATH', substr_replace(FCPATH, '', $pos, strlen('public'.DIRECTORY_SEPARATOR)));
// Path to the writable directory.
define('WRITEPATH', realpath($writable_directory).DIRECTORY_SEPARATOR);
// The path to the "application" folder
define('APPPATH', realpath($application_directory).DIRECTORY_SEPARATOR);
define('APPPATH', realpath($paths->applicationDirectory).DIRECTORY_SEPARATOR);
// Path to the system folder
define('BASEPATH', realpath($paths->systemDirectory).DIRECTORY_SEPARATOR);
// Path to the writable directory.
define('WRITEPATH', realpath($paths->writableDirectory).DIRECTORY_SEPARATOR);
// The path to the "tests" directory
define('TESTPATH', realpath($tests_directory).DIRECTORY_SEPARATOR);
define('TESTPATH', realpath($paths->testsDirectory).DIRECTORY_SEPARATOR);
/*
* ---------------------------------------------------------------

View File

@ -1,12 +1,8 @@
<?php
$system_directory = 'system';
$application_directory = 'application';
$writable_directory = 'writable';
$tests_directory = 'tests';
// Set current working directory to ROOT.\
chdir(__DIR__.'/../../');
// Get our system paths
require 'application/Config/Paths.php';
$paths = new \Config\Paths();
// Path to the front controller (this file)
define('FCPATH', getcwd().'/public'.DIRECTORY_SEPARATOR);
@ -24,21 +20,21 @@ $_SERVER['CI_ENV'] = 'testing';
* so they are available in the config files that are loaded.
*/
// Path to the system folder
define('BASEPATH', realpath($system_directory).DIRECTORY_SEPARATOR);
// Path to code root folder (just up from public)
$pos = strrpos(FCPATH, 'public'.DIRECTORY_SEPARATOR);
define('ROOTPATH', substr_replace(FCPATH, '', $pos, strlen('public'.DIRECTORY_SEPARATOR)));
// Path to the writable directory.
define('WRITEPATH', realpath($writable_directory).DIRECTORY_SEPARATOR);
// The path to the "application" folder
define('APPPATH', realpath($application_directory).DIRECTORY_SEPARATOR);
define('APPPATH', realpath(FCPATH.$paths->applicationDirectory).DIRECTORY_SEPARATOR);
// Path to the system folder
define('BASEPATH', realpath(FCPATH.$paths->systemDirectory).DIRECTORY_SEPARATOR);
// Path to the writable directory.
define('WRITEPATH', realpath(FCPATH.$paths->writableDirectory).DIRECTORY_SEPARATOR);
// The path to the "tests" directory
define('TESTPATH', realpath($tests_directory).DIRECTORY_SEPARATOR);
define('TESTPATH', realpath(FCPATH.$paths->testsDirectory).DIRECTORY_SEPARATOR);
define('SUPPORTPATH', realpath(TESTPATH.'_support/').'/');