sFire PHP Framework

app.php

The app.php is a config file where the project configuration and services are defined. The app.php is located in the "config" directory. Within this file, you can add delete and modify your project configuration.

In this section we will handle:

  • Blueprint
  • Salt
  • Module loading
  • PSR-4 and PSR-0 autoloading classes
  • File extensions
  • Prefixes
  • Default directories
  • Debugging options
  • Cache settings
  • Form tokens
  • Services
  • Adding custom configurations

Blueprint

The app.php uses "sFire\Application\Application".

use sFire\Application\Application;

Application :: add($key, $value);

Salt

The salt can be used to encrypt data or hash passwords, but is also used to encrypt cookies. It's value is default null and is recommended that you change this to a unique value.

Application :: add('salt', 'this-should-be-a-unique-value'); //Edit the value to a unique value for your application

Module loading

You can define multiple modules for sFire to load. sFire will try to retrieve the module list by the modules key name in the app.php: In the example below the module App with it's config.php will be loaded.

Application :: add('modules', ['App']);

PSR-4 and PSR-0 autoloading classes

PSR-4 describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification.

Note: if you installed sFire via composer, all your namespaces and class file paths are defined in the composer.json. sFire detects if it is loaded via composer or not. If you load sFire without composer, you can add the namespaces and class file paths to the app.conf

PSR-4 / PSR-0

When loading external classes, you can add the namespace and filepath to the folder in the psr4 and psr0 options:

//Add namespace "foo" to the PSR-4 autoloaded
Application :: add('psr4', ['foo' => 'foo/path/to/source/']);

//Add namespace "foo" to the PSR-0 autoloaded
Application :: add('psr0', ['foo' => 'foo/path/to/source/']);

File extensions

If you wish to change the default file extensions for the translation, view and cache files, you can do so by changing the extensions array.

Application :: add('extensions', [

    'translation'   => '.lg',
    'view'          => '.tpl',
    'cache'         => '.ch'
]);

Prefixes

Below is a list with all the prefixes and their description. You may edit the prefixes to your wishes.

Prefix Default Description
controller Controller File and class name for controllers. Example: ControllerHome
helper Helper File and class name for helpers. Example: HelperConvert
model Model Holds all the entities, mappers and dbtables
entity Entity File and class name for entities. Example: EntityProduct
validator Validator File and class name for validators. Example: ValidatorProduct
mapper Mapper File and class name for mappers. Example: MapperProduct
dbtable DBTable File and class name for database tables. Example: MapperProduct
schedule Schedule File and class name for schedules. Example: ScheduleImport
action action Method name for controller actions. Example: actionIndex
middleware Middleware File and class name for middleware. Example: MiddlewareAuthentication

Default directories

Here you can define all the directories. The defaults are config, controller, model, entity, mapper, dbtable, helper, translation, validator and the view directory, but you can add new directories.

Application :: add('directory', [

    'config'        => 'config'         . DIRECTORY_SEPARATOR,
    'controller'    => 'controllers'    . DIRECTORY_SEPARATOR,
    'model'         => 'models'         . DIRECTORY_SEPARATOR,
    'entity'        => 'models'         . DIRECTORY_SEPARATOR . 'entity' . DIRECTORY_SEPARATOR,
    'mapper'        => 'models'         . DIRECTORY_SEPARATOR . 'mapper' . DIRECTORY_SEPARATOR,
    'dbtable'       => 'models'         . DIRECTORY_SEPARATOR . 'dbtable' . DIRECTORY_SEPARATOR,
    'helper'        => 'helpers'        . DIRECTORY_SEPARATOR,
    'translation'   => 'translations'   . DIRECTORY_SEPARATOR,
    'validator'     => 'validators'     . DIRECTORY_SEPARATOR,
    'view'          => 'views'          . DIRECTORY_SEPARATOR,
    'middleware'    => 'middleware'     . DIRECTORY_SEPARATOR
]);

Debugging options

To define all the debugging options, you may use the debug Array. The debug Array has multiple options:

Application :: add('debug', [

    'display'   => [

        //Whenever to show the error on screen
        'enabled'   => true,

        //An Array with IP addresses to white list to show the error
        'ip'        => []
    ],

    'write'     => [

        //Whenever to enable or disable to log the error to file
        'enabled'   => true,

        //Log rotating in hour, day, week, month or year
        'rotate'    => 'day' 
    ]
]);

Cache settings

The cache settings will be used to define the configuration for sFire\Cache\Adapter\Filesystem. It has only one key named probability and is used to determine the probability to sweep through cache folder deleting old/expired files. The default value is 5, therefor the change is 1 on 5 that old cache will be cleared.

Application :: add('cache', [
    'probability' => 5
]);

Form tokens

The form tokens lets you determine how many tokens will be saved in the session before the oldest token makes room for a newer token. Form tokens prevents Cross Site Request Forgery.

Application :: add('token', [

    //Amount of saved tokens per session
    'amount' => 25
]);

Services

Services like caching, database and ACL interfaces can be defined in the "services" key. To create a new service, just add a new key with callable function that returns a new instance:

Application :: add('services', [

    'acl' => function() {
        return new sFire\Permissions\ACL();
    }
]);

To retrieve this instance, you can call the "services" method from within a controller or mapper:

public function actionIndex() {

    $acl = $this -> service('acl');

    print_r($acl);
}

Adding custom configurations

You may add new configurations by calling the add method:

Application :: add('foo', 'bar');

To retrieve this configuration you can call the get method.

use Application;

Application :: get('foo'); //Outputs "bar"