Online Merchant v2.4 Joli

Framework OSC\OM

Introduction

OSC\OM is a framework utilizing new features in PHP v5.5 to improve the performance, security, and modularity of the codebase. Taking advantage of namespaces and autoloading, it is now even easier to add new features and extend existing features without the need to edit core source code files.

The base framework is located in the includes/OSC directory:

Framework Namespace Location
Core OSC\OM includes/OSC/OM
Sites OSC\Sites includes/OSC/Sites
Apps OSC\Apps includes/OSC/Apps

Namespaces/Autoloader

The framework is built utilizing the PSR-4 standard for autoloading classes from matching namespaces and file paths. Classes are automatically loaded on demand and don't need to be included/required manually.

The base namespace the autoloader watches for is OSC\ and loads the class files located in the includes/OSC/ directory.

Examples

Class File Location
OSC\OM\OSCOM includes/OSC/OM/OSCOM.php
OSC\OM\Db includes/OSC/OM/Db.php
OSC\OM\Registry includes/OSC/OM/Registry.php
OSC\Sites\Shop\Shop includes/OSC/Sites/Shop/Shop.php
OSC\Apps\VENDOR\APP\APP includes/OSC/Apps/VENDOR/APP/APP.php

Classes in the framework must declare their namespace as the first PHP code in the file.

Example:

<?php
namespace OSC\OM;

class NewClass
{
    ....
}

The full namespace to the above example would be:

OSC\OM\NewClass

and the location of the file would be:

includes/OSC/OM/NewClass.php

For another class to be able to load OSC\OM\NewClass automatically, it needs to be declared with PHP's use keyword after the namespace of the class and before any other PHP code.

Example:

<?php
namespace OSC\OM;

use OSC\OM\NewClass;

class AnotherNewClass
{
    public function __construct()
    {
        $NewClass = new NewClass();
    }
}

The framework autoloader (OSC\OM\OSCOM::autoload()) is registered as an autoloader in includes/application_top.php and is automatically initialized in all main PHP files that include the application_top.php file.

Template files do not need to have a namespace set, but still need to reference framework classes that it uses:

<?php
use OSC\OM\HTML;

echo HTML::outputProtected('Hello World!');
?>
More information about namespaces can be found at the PHP Namespace documentation page.

Sites

Sites are registered in the framework to initialize and apply environment parameters specific to that site.

The available sites in the core are:

Site Controller
Shop (default) OSC\Sites\Shop\Shop
Admin OSC\Sites\Admin\Admin

Sites are registered and retrieved as follows:

use OSC\OM\OSCOM;

OSCOM::initialize();
OSCOM::loadSite('Shop');

$site = OSCOM::getSite();

Apps

Apps are self-contained packages that add new or extend existing features through modules and hooks. Apps reside in their own directory and do not need to edit core source code files.

Apps are located in the following directory:

Namespace Location
OSC\Apps\VENDOR\APP includes/OSC/Apps/VENDOR/APP

Apps also have a public directory for public accessible files such as stylesheets, javascript, and images, located at:

public/Apps/VENDOR/APP

More information is available in the Apps chapter.

Coding Standards

The framework is coded with the PSR-2 coding style guide.