Mecha CMS

Mecha CMS blog and documentation.

Class Autoloader

Updated: Sunday, 07 August 2016

Comparison of class name pattern with its file name.

I created a simple logic for automatic loading of classes in the engine\kernel folder. If you want to develop this CMS to your own interests, you can do it so by taking into account some of the provisions of the patterns I created:

  1. Name your file with lower-cased letters. For example, name the file contains a class Foo with foo.php and Foo_Bar with foo_bar.php
  2. Namespaces are replaced by a dot. For example, name the file contains a class Foo\Bar with and Foo\Bar_Baz with foo.bar_baz.php
  3. Minus sign should be avoided in file name.
└── kernel/
    ├── foo.php → loading `Foo` class
    ├── foo_bar.php → loading `Foo_Bar` class
    ├── foo.bar_baz.php → loading `Foo\Bar_Baz` class
    └── …

In foo.php we have:


class Foo extends __ { … }

In foo_bar.php we have:


class Foo_Bar extends __ { … }

In foo.bar_baz.php we have:

<?php namespace Foo;

class Bar_Baz extends __ { … }
Donation and Email Subscription