Documentation / Naming conventions

Namespaces

Every class in the Orion Framework must respect the standard namespace file/class naming convention.

Let's take the Upload core class as an example :

  • This class is part of Orion's core classes, which means that it's located in the orion/core/ directory.
  • This also means that it must be part of the Orion\Core namespace.
  • That way, we have a file path of orion/core/upload.php and a corresponding namespaced class name of Orion\Core\Upload.

This straight-forward namespaced naming convention permits a very fast class name parsing and autoloading.

Let's get back to our Upload class. Say you want to instantiate this class in one of your controllers. All you have to do is use the new constructor and provide the full name spaced class name :

$uploader = new \Orion\Core\Upload();

Or if you are going to use more than one core class instance, you can also use a namespace alias to shorten your class name calls :

use \Orion\Core\;
[…] 
$uploader = new Core\Upload();
$form = new Core\Form(); // etc.

This also means that all your global models located inside the orion/models/ directory must follow the same namespaced naming convention.

Let's take another example with a model located in /orion/models/auth/user.php. If you translate this file's path into its corresponding namespace, you will see that it must be contained within the Orion\Models\Auth namespace. So your model file will be similar to :

namespace Orion\Models\Auth;
use \Orion\Core;
class User extends Core\Model {
[…]
}

And after that, if you want to use this model inside one of your controllers, all you have to do is :

use \Orion\Models;
[…] 
// Retrieve all users. Using a custom model static method.
// Will return an array of Models\Auth\User objects.
$users = Models\Auth\User::getList(); 

Class names

By convention, Orion's class names follow the CamelCase naming standard. This means that any class name must start with an upper case and each word's first letter is also uppercased.

The same thing goes for namespaces, except that it is recommended to use only one-word namespaces like All\My\Classes and not All\MyClasses.

Note that this is only a convention, and the only mandatory thing is the first upper-cased letter of classes and namespaces. Apart from that, feel free to use any other naming convention you like. For example, the following class will successfully be parsed by Orion's autoloader :

\Orion\My\Class

This class path will produce the following file path :

orion/my/class.php

But this class name would also be parsed successfully :

\Orion\My_Name_Space\My_Class

Producing the following file path :

orion/my_name_space/my_class.php

Specific classes

While Orion classes follow a fairly simple namespaced naming convention, some specific class types need to follow a few rules.

Module names

Module's controller names must follow the following convention :

  • File name : orion/modules/[module]/[module].[mode].php
  • Class name : [Module][Mode]
  • Namespace : Orion\Modules\[Module]

For example, the default controller class of a 'Users' module will be located in orion/modules/users/users.default.php and have the following class declaration :

namespace Orion\Modules\Users;
use \Orion\Core;
class UsersDefault extends Core\Controller {
[…] 
}

More information about this process is available in Modules and Controller.

Back to top