CRX Framework PHP - Documentation.

Last update : 05/2019
 

Architecture of CRX php framework 

CRX Framework work for scripting on service mode or on webmode, 

on webmode it can provide librairies and also tools for CRX Cms witch a CMS with MVC organisation. 

CMS or SCRIPT have the same design: 

html /     ( HTML folder is the application folder content )

[app-php] / [module] / 

[app-js] / [module] / 

So each folder represent a module, for example in web mode :   forum, mail, directory,

Exemple for from CLI service mode : dxClusterServer ( witch work with socket/thread/shared memory ) or dxClusterMailAlert witch is an alerting daemon. 

Of course in same application it's possible to mix server mode and web mode ( server mode = script mode here ). 

Inside each module you have these folders : 

conf_files   ( containt module xml conf file ) 

handler_files

lang_files 

models_files

templates

view_files

 

On parent level , we have : 

conf /  (configuration folder contain VHOST configuration and registry of crx application ). 

logs /  ( can contain APACHE log but also CRX Framework log )

 

Example of script application : 

#!/usr/bin/php
<?php 
require_once('/home/hosting/www_root/common.crx.cloud/conf/env.php');
require_once('/home/hosting/www_root/ham.crx.cloud/conf/global.php');
require_once($FMPATH.'/loader/bootScript.php');

bootScript::boot(
   'bootScript',
   array(
	
	'appli_web_uri'			=>	$APPWEBURI,
	'appli_name'			=>	$APPNAME,	
	'appli_webmaster_email'	=>  $APPWEBMASTERMAIL,

	'appli_reg_path'		=>	$APPFSPATH.'/conf/', 								//registry folder 
	'appli_path'			=>	$APPFSPATH.'/html/',								//_APPLI_MAIN_PATH_	
    'appli_path_root'		=>	$APPFSPATH,
	'appli_secret_key'		=>	$APPSECKEY,											//_APPLI_SEC_KEY_
	'error_handling'		=>  array(
		'PhpDisplay'		=>	$error
	), 	 
	'server_os'				=>	'LINUX',			//_SERVER_TYPE_
	'current_path'			=>	$APPFSPATH.'/html',	//_SERVER_EXEC_PATH_
	'framework_debug_mode'			=>  'nothing',	//view/nothing/log
	'framework_error_mode'			=>  'nothing',	//view/nothing/log
	'framework_path'				=>	$FMPATH.'/',
	'framework_conf'				=>  array(
		'time_zone_set'							=>	'Europe/Paris',		
		'framework_debug_console'				=>  NULL,		//view/nothing/log
		'app_main_ds'							=>  'mysql',
		'load_user_module'						=>	1,
		'load_user_authentification_module'		=>	1,
		'available_languages'					=>	array('fr','en'),
		'default_language'						=>	'fr', //can be fr,en  OR auto (detect from user browser_info)
		'default_loaded_module'						=>	'dxClusterWeb',
		'process_options_for_module_to_load'	=>  array('action'	=>	'CRON__updateUserProfileNumberOfSpots')
      )
  )
);

?>

As you can see this instance will call the module "dxClusterWeb" and the class method "CRON__doSpotArchiving", arguments to the script can  be transmit via process_options_for_module_to_load  array. 

 

Example of web call : 

This example call CRX-CMS from the index.php file. 

Here we call the cms module dxClusterWeb when user is login-in. 

<?php
require_once('/home/hosting/www_root/common.crx.cloud/conf/env.php');
require_once('/home/hosting/www_root/ham.crx.cloud/conf/global.php');
require_once($FMPATH.'/loader/bootWeb.php');

bootWeb::boot(

   'bootWeb',

   array(
	
	'appli_web_uri'			=>	$APPWEBURI,//_WEBSITE_URL_
	'appli_name'			=>	$APPNAME,		//_APPLI_NAME_
	'appli_webmaster_email'	=>  $APPWEBMASTERMAIL,		//_APPLI_WEBMASTER_MAIL_

	'appli_reg_path'		=>	$APPFSPATH.'/conf/', 	//registry folder 
	'appli_path'			=>	$APPFSPATH.'/html/',	//_APPLI_MAIN_PATH_
	'appli_path_root'		=>	$APPFSPATH,				//path outside html/www folder using for registry and log(s). 
	'appli_secret_key'		=>	$APPSECKEY,											//_APPLI_SEC_KEY_

	'error_handling'		=>  array(
		'PhpDisplay'		=>	$error
	),

	'server_os'			=>	'LINUX',				//_SERVER_TYPE_
	'current_path'		=>	getcwd(),				//_SERVER_EXEC_PATH_

	'framework_debug_mode'			=>  $fmer,				//view/nothing/log
	'framework_error_mode'			=>  $fmer,				//view/nothing/log

	'framework_path'				=>	$FMPATH.'/',
	'framework_conf'				=>  array(

		'caching_xml_to_memcached'			=>	1, // 0 disable // default 1 => use for module configuration XML.
		'caching_xml_to_php'				=>	1, // 0 disable // default 1 => use for modules global conf/list.

		'caching_ini_to_php'				=>	1, // default 1 => use for languages ini files.
		'caching_ini_to_user_session'			=>  1, // default 1 => use for languages ini files.

		'time_zone_set'					=>	'Europe/Paris',

		//'framework_debug_console'				=>  '',		//view/nothing/log

		//'app_main_ds'							=>  'mysql', // default 'll be mysql !

		'load_user_module'				=>	1,
		'load_user_authentification_module'		=>	1,

		'set_user_authentification_method'		=>	'webUserAuthentification',

		'load_stats_visitor_module'			=>	0,
		'load_common_module'				=>	1,

		'display_modules_output'			=>	1,

		'available_languages'				=>	array('fr','en','it','es'),
		'default_language'					=>	'fr', //can be fr,en  OR auto (detect from user browser_info)

		'if_access_to_unknow_module'		=>	'load_default_module',// or view_404, load_default_module,print_error, do_nothing, die.
		'define_404_page'					=>	getcwd().'/404.php',
		'common_module_name'				=>	'common',

		'default_loaded_module'				=>	'index',
		'on_user_login_in_module'			=>	'dxClusterWeb',//dxClusterWeb

		'maintenance_mode'				=>	0,

		'loadCommondModuleConfiguration'		=>	1,

		//runMain
		'enforceUriSecurityMode'			=> 	$urlmode, //b64id (require in AJAX mode), normal

		'saveUriEncodingIntoMemCache'			=>	0, //TODO 1

		'cachingDataSource'				=>	'memcached-localhost'

	  )

  )
);

?>

Module env : 

Inside a module, you can use pre defined method : 

$this->showVars();     // display framework constant defined. 

$this->loadIco();        // load HTML Ico picture. 

$this->_currentModuleConfiguration   // current module XML configuration :     /html/app-php/[MODULE_NAME]/conf_files/configuration_module.xml

Module configuration format : 

Configuration module is defined via XML configuration file like this : 

<?xml version="1.0" encoding="ISO-8859-1"?>
<module>
	<conf>
		<node_name>F4EYQ-1</node_name>
		<node_uri_sch>https</node_uri_sch>
		<node_uri>ham.crx.cloud</node_uri>
		<node_uri_mobile>m.crx.cloud</node_uri_mobile>
		<node_uri_telnet>ham.crx.cloud</node_uri_telnet>
		<node_uri_telnet_port>7300</node_uri_telnet_port>
		<node_linked>ik5zuk.dyndns.org,ik6xmi.homepc.it,n6ws.no-ip.org</node_linked>
		<node_uri_wbs>wbsham.crx.cloud</node_uri_wbs>
		<dxcluster_scheduler_path>/home/spider/dxcluster_scheduler_path>
		<mail_admin_send>webmaster@crx.cloud</mail_admin_send>
		<mail_admin_send_test>f4eyq@crx.cloud</mail_admin_send_test>
		<mail_admin_send_test_ob>CRXHAM - testingmail</mail_admin_send_test_ob>
		<flags_folder>public/html-app/dxClusterWeb/flags/</flags_folder>	
		<display_chat_messages_date_format_html_interface>h:i</display_chat_messages_date_format_html_interface>
		<enable_paypal_donation>1</enable_paypal_donation>
	</conf>
</module>

As you can see, you must use the following tag:    module, conf   and you can put what ever you want inside conf xml tag. 

=> To apply new  configuration for module, you must  login/logout and before restart your memcached service. 

Debug something into a module : 

Here we debug $cmd var into a debug log file ( witch is located into log folder on root ) :

//to debug $cmd content :
crxFramework::debugFile(dumper($cmd));

Of course, we can also debug to output via this method :

into the script loader ( boot script / web script ), we configure the display with this directive set to "view" :

//default is nothing

bootScript::boot(
...
'framework_debug_mode'			=>  'view',				//view/nothing/log

Now into the controller module, we can use this function "debugAndContinue", this function take the message and a boolean :

Here is it's a mail alert service process witch run in background :

	function handle__startDxclusterMailAlertProcess(){
		
		debugAndContinue('[INFO] '.mktime()."  Now Starting mailler alert processus.",DEBUG_MAIL_PROCESS);
		
		$mailling_spots=array();
		
		$i=0;
		$count_burst=0;
		
		
		while(TRUE){
			
			debugAndContinue('[INFO] '.mktime()."  Check if there is new spot to send.",DEBUG_MAIL_PROCESS);	

Framework env :

All constant php are define here :

[FRAMEWORK PATH] / loader / constant.php

You can ajust some value, if you need advanced debug for example.
 

define('DEBUG_LNG_LAYER',0);
define('DEBUG_FRMW_MODULE_LOADER_LAYER',0);
define('DEBUG_URL_BUILD_LAYER',0);
define('DEBUG_MODULE_ENGINE_LAYER',0);
define('DEBUG_WEBSERVICE_CRX_LAYER',0);//See crxFrameworkWebserviceCrx
define('ENABLE_LOG_DEBUG',0);//See crxFrameworkWebserviceCrx
define('_DEBUG_LOG_FILE_','/tmp/debug_php.log');//Set debug path
define('DEBUG_crxUploadFiles',0);

To view framework content you can use :  

crxBootLoader::showConstantAsHtmlArray()


Using database classe 

CRX Framework, purpose a powerfull object to SQL mapper, and various method to generate SQL and create schema from object class properties : 

$this->_dataAccess = crxDataSource::getDs('mysql_local');    


First inside object, you must define the table schema you want, example : 

    var $_userDonationTableShema = array(
      'donation_id'=>'pk',
      'donation_date',
      'donation_user_id',
      'donation_amount',
      'donation_type'
    );


Example 1 , return data with a filter ( similar to SELECT request ) : 

$this->_dataAccess->formatSqlQuery('',$this->_table_users_donation,'DISPLAY','',array('filter_key'=>'donation_id','filter_key_value'=>$id));        

$this->_dataAccess    -> ExecSql();

return $this->_dataAccess -> returnLineAsso();

Example 2, insert data : 
 

            $this->_dataAccess    ->    defineTableShema($this->_userDonationTableShema);
            $this->_dataAccess    ->    formatSqlQuery($updatedata,$this->_table_users_donation,'INSERT');
            $this->_dataAccess    ->    execSql();   

 
Example 3, update data : 

            $this->_dataAccess    ->    defineTableShema($this->_userDonationTableShema);
            $this->_dataAccess    ->    formatSqlQuery($updatedata,$this->_table_users_donation,'UPDATE',array('donation_id'=>$donation_id));
            $this->_dataAccess    ->    execSql();    

If error, you can extract it via this command :    ( execSql return FALSE ) 

$this->_dataAccess    ->    getExecSqlError();     


Developping module, use ini file languages

To disable cache, during developpement use :     

$this->disableLngCache();