Best way to define paths?

This is my piece of code

define('BASE_PATH', realpath(\_\_DIR\_\_) . DIRECTORY_SEPARATOR);

define(‘LIB’, BASE_PATH . ‘lib’ . DIRECTORY_SEPARATOR);
define(‘FRAMEWORK’, LIB . ‘framework’ . DIRECTORY_SEPARATOR);
define(‘DATABASE’, FRAMEWORK . ‘database’ . DIRECTORY_SEPARATOR);
define(‘DATETIME’, FRAMEWORK . ‘datetime’ . DIRECTORY_SEPARATOR);
define(‘AUTOLOADER’, FRAMEWORK . ‘autoloader’ . DIRECTORY_SEPARATOR);
define(‘FUNCTIONS’, FRAMEWORK . ‘functions’ . DIRECTORY_SEPARATOR);
define(‘ROUTER’, FRAMEWORK . ‘router’ . DIRECTORY_SEPARATOR);

define(‘INC’, BASE_PATH . ‘inc’ . DIRECTORY_SEPARATOR);
define(‘ADMIN’, BASE_PATH . ‘admin’ . DIRECTORY_SEPARATOR);
define(‘EXT’, BASE_PATH . ‘ext’ . DIRECTORY_SEPARATOR);
define(‘MODULES’, EXT . ‘modules’ . DIRECTORY_SEPARATOR);
define(‘PLUGINS’, EXT . ‘plugins’ . DIRECTORY_SEPARATOR);
define(‘THEMES’, EXT . ‘themes’ . DIRECTORY_SEPARATOR);

class Path {
public $paths = array(
‘Cymos’ => BASE_PATH,
‘Cymos\Lib’ => LIB,
‘Cymos\Framework’ => FRAMEWORK,
‘Cymos\Framework\Database’ => DATABASE,
‘Cymos\Framework\Datetime’ => DATETIME,
‘Cymos\Framework\Functions’ => FUNCTIONS
);
}

Because PHP doesn’t allow function or even concatenating string in the property value , I use a constant defined first, then assign it to the property of path…
Is it right to do this ? Is there any better solution ?
I know I can do it with global variable, but I think OOP design is better.

P.S. I use the class Path to give the base path to each namespaces (I want to use it on PSR-4 Autoloader)
And, I don’t just call the autoloader to register the namespace because I think it’s better to separate it… So, if Client wants to change the path, he doesn’t need to see the business logic

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.