This article describes the structure of X-Cart classes. Also, it describes how to generate namespaces correctly.
All X-Cart classes are located in the
<X-Cart>/classes/ directory. Let us walk through each type of X-Cart classes:
<X-Cart>/classes/XLite.phpis the class of the whole application; you will never use it in new modules;
<X-Cart>/classes/Base/directory contains definitions of basic X-Cart interfaces including Decorator interface that allows applying changes to every part of X-Cart store without modifying core classes;
<X-Cart>/classes/Controller/directory contains definitions of classes that handle requests to X-Cart (controllers). Check general X-Cart workflow article in order to learn more about controller classes;
<X-Cart>/classes/Core/directory contains definitions of core X-Cart entities, such as database, HTTP request, Mailer etc;
<X-Cart>/classes/DataSet/directory includes the classes that defines different data structures; they are seldom used in the modules;
<X-Cart>/classes/Logic/folder contains the classes that describe the business logic of complex routines: order calculation, import/export, etc;
<X-Cart>/classes/Model/directory includes the classes that describe different X-Cart entities, such as products, orders, users, shipping and payment methods, menus etc;
<X-Cart>/classes/Module/folder contains files added by modules (default and 3rd party ones); if you write the module, you will put your files into this folder only; all module files (except templates) are stored in the
<X-Cart>/classes/Upgrade/directory contains classes that are used during upgrade procedure;
<X-Cart>/classes/View/folder contains classes that manage X-Cart's output.
Namespaces are widely used constructions in OOP languages (PHP in particular). They allow to save time and not mix up different classes with the same name.
Namespace notation in X-Cart is straight-forward: it repeats the class' sub-path of the .php file in the
- PHP class defined in the
<X-Cart>/classes/XLite/Controller/Customer/Product.phpfile will have namespace
XLite\Controller\Customer; i.e. namespace includes all names of folders after
<X-Cart>/classes/separated by backslash (****)
- The same way, PHP class defined in the
<X-Cart>/classes/XLite/View/Header.phpfile will have namespace
- Namespace can be quite long, e.g. if the class is located in the
<X-Cart>/classes/XLite/Module/CDev/AustraliaPost/Model/Shipping/Processor/AustraliaPost.phpfile, then its namespace will be
- PHP class defined in the
<X-Cart>/classes/XLite.phpfile will have no namespace.
Important note: if you have PHP class MyClass, it must be placed into the MyClass.php file. Name of the class must be the same as the name of the .php file it contains.