Ness PHP Project Configuration
Required Namespace
  • Ness
    • Configuration

You can include this library to your code file by typing the below code;

use Ness\Configuration


About Configuration #top

Ness PHP controls all system configurations from one point. This will help you manage your configurations easily and quickly. You can manage all configurations from one point and start as quickly as possible to write the main logic of your project and get rid of unneccesary configurations. Ness PHP also supports multi-config files, write configuration files as your needs and switch between them according your needs.


Configuration File #top

While a request made to Ness PHP, the framework initially loads the configuration file which is app_config.php by default. You can manage all Url security, app description and title or global variable definitions here.In next topic you can see a sample configuration file which is created by default installation of the framework. Please keep reading the documentation for understanding all basics for the configuration file.


Example Configuration File #top

Default app_config.php content and the basic changes you need to made in your installation;


<?php
/**
    * Ness PHP Framework.
    * A solid php framework for fast and secure web applications.
    *
    * @author Sinan SALIH
    * @license MIT License
    * @copyright Copyright (C) 2018-2019 Sinan SALIH
    */

use Ness\Configuration;

/*
    * === [Environment Configuration ] ===
    * This configuration is used to set the
    * development environment for your project.
    * You can set 2 types of environments;
    * "development" OR "publish"
    */
Configuration::setEnvironment('development');

/*
    * === [Application Folder ] ===
    * This configuration is generally for security.
    * If you need to change the folder name of your
    * application you must set it here.
    */
Configuration::setApplicationFolder('Application');

/*
    * === [Application Resource Files ] ===
    * This function is used to set the
    * path of the resource.xml file which is used
    * to store static values for your projects(ex; strings, image paths etc)
    * Note; the core app location ('Application' by default) is excluded from the value.
    */
Configuration::setResourceFile('Resources.xml');

/*
    * === [Application URL ] ===
    * This configuration is used to set your
    * web sites url. For example if you create a
    * application that will be run in root set url to: "http://www.examplesite.com/"
    * If your application will be a sub module/application of other application set it like:
    * "http://www.examplesite.com/my_module".
    */
Configuration::setApplicationUrl('http://localhost/nessphp');

/*
    * === [Is Application Root ] ===
    * If your application's url is not accessable by "www.siteexample.com"
    * set this false.
    */
Configuration::setRoot(false);

/*
    * === [ Application Name ] ===
    * This configuration is used to set name of your application.
    */
Configuration::setTitle('Hello World');

/*
    * === [ Application Version ] ===
    * This configuration is used to set version number of your application.
    */
Configuration::setVersion('1.0.0');

/*
    * === [ Application Description ] ===
    * This configuration is used to set description of your application.
    */
Configuration::setDescription('Ness PHP is a solid web framework for fast and secure web applications.');

/*
    * === [ Application Maintenance Mode ] ===
    * This configuration is used to set maintenance mode of your application.
    * if Maintenance Mode is enabled user will see a message on screen like 
    * 'Under Maintenance'
    */
Configuration::enableMaintenance(false);

/**
    *  === [ Application Url Protection ] ===
    * Protect your website from unwanted parameters, You can enable 
    * this feature for preventing visit with unwanted parameters 
    * supplied in array below.
    */
Configuration::setUrlProtected(false);
Configuration::UnwantedParameters(array("'"));


/**---------------------------------------------------------*/
/**                  Application Class                      */
/**---------------------------------------------------------*/
class Application
{
    /**
        * This method is called when your application is loaded. You can register
        * your object mappers or do other configurations.
        */
    public function Register()
    {

    }
}
                                
                        


Application Register #top

Application Class is an entry point for your code, after the installation of core framework modules the function(s) in this class will be run. You must define this class in a configuration file and only acceptable and auto run function is Register() function. This function is used to register globally variables, set object mappers, set pin checkers etc. For example; Your app needs a database connection and you do not want to write username and password in each connection. You can define a object mapper in register function and access globally this variable in every place of your code.


<?php
use Ness\Configuration;
use Ness\Tool\ObjectMapper as omap;

...


/**---------------------------------------------------------*/
/**                  Application Class                      */
/**---------------------------------------------------------*/
class Application
{
    /**
        * This method is called when your application is loaded. You can register
        * your object mappers or do other configurations.
        */
    public function Register()
    {
        omap::MapNew("database", array(
                        "username"=>"db_user_name",
                        "password"=>"db_pass",
                        "host"=>"localhost"
        ));
    }
}
                                        
                                
                                


Class Methods #top

setEnvironment
Configuration::setEnvironment(string $param);
This function is used to set development environment.Accepted values: "development", "publish", "default".
Return void
Parameters $param String



setApplicationFolder & getApplicationFolder
Configuration::setApplicationFolder(string $param);
This function is used to set application folder for Ness framework's current config.
Return void
Parameters $param String

Configuration::getApplicationFolder();
This function is used to return application folder for Ness framework's current config.
Return String
Parameters None



setRoot() & isRoot()
Configuration::setRoot(Boolean $param);
This function is used to determine if your application in server is in root directory or not. Set true if your app will run in root directory
Return void
Parameters $param Boolean

Configuration::isRoot();
you can use isRoot() to check the option;
Return Boolean
Parameters None



setApplicationUrl() & getApplicationUrl()
Configuration::setApplicationUrl(string $prm="http://localhost/");
This function is very important, when you use response and route class your redirect url will be get from here.
Return void
Parameters $prm String

Configuration::getApplicationUrl();
you can use getApplicationUrl() to return this value;
Return String
Parameters None



setResourceFile() & getResourceFile()
Set resource file location of Ness framework.
Configuration::setResourceFile(string $prm);
Return void
Parameters $prm String

Get the value with
Configuration::getResourceFile() : string



setUrlProtected() & isUrlProtected()
This function is used to prevent web site from unwanted url parameters.
Configuration::setUrlProtected(Boolean $prm);
Return void
Parameters $prm Boolean

This is a security setting. This setting must be activated in order to protect your web address from the parameters you do not want, and these special characters must be set by the method that follows
Configuration::isUrlProtected() : Boolean



UnwantedParameters()
Set an array for unwanted characters or words
Configuration::UnwantedParameters(Array $prm);
Return void
Parameters $prm Array

Example
Configuration::UnwantedParameters(array("'", "_", "~"));
That means if your website gets visited with one of this three parameters user will be redirected.


setTitle() & getTitle()
This function is used to set a title/name for your project.
Configuration::setTitle(string $prm);
Return void
Parameters $prm String

Get the value with
Configuration::getTitle() : string



setVersion() & getVersion()
This function is used to set a version numer for your project.
Configuration::setVersion(string $prm);
Return void
Parameters $prm String

Get the value with
Configuration::getVersion() : string



setDescription() & getDescription()
This function is used to set a description for your project.
Configuration::setDescription(string $prm);
Return void
Parameters $prm String

Get the value with
Configuration::getDescription() : string




Enable & Design Maintenance Mode #top

This configuration is used to set maintenance mode of your application.if Maintenance Mode is enabled user will see a message on screen like 'Under Maintenance'.

Find in your configuration file the line;
Configuration::enableMaintenance(true);
and set true.
Design This Page;
The view file for the 'Maintenance Mode' can be found in; [project_folder]/Application/View/systemArea/maintenancemodeView.php
and the controller for managing the maintenance mode can be found in[project_folder]/Application/Controller/ErrorManagement/MaintenanceMode.php