0

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(
        'CMS' => BASE_PATH,
        'CMS\Lib' => LIB,
        'CMS\Framework' => FRAMEWORK,
        'CMS\Framework\Database' => DATABASE,
        'CMS\Framework\Datetime' => DATETIME,
        'CMS\Framework\Functions' => FUNCTIONS
    );
}

As I can't use function or even concatenating string in the class Path property (PHP don't allow this), I define the path first, then using the definition on the array values of property.

Is it right to do this ? Is there any better solution ?
P.S. I use the class Path to give the base path to each namespaces (I want to use it on PSR4 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

Terry Djony
  • 1,975
  • 4
  • 23
  • 41

1 Answers1

0

You can create a config file, i think that the syntax is a lot more friendly

Config files in php

Community
  • 1
  • 1
Diogo Cunha
  • 1,194
  • 11
  • 23