Jump to content

Execution Controller V1.0.0


ckrudelux

Recommended Posts

This is a simple script I put to gether for my own needs and I thought I should share it. I'm not sure how to discribe this but as I wrote in the comments:

The purpose of the Execution Controller is to collectscripts and request to one place.With the Execution Controller you can make POST/GET requestto classes and functions. Load lib's needed to the project and execute maintainingbackground scripts.
Sorry for no example but in time I will make one. Suggestions and feedback are welcome.
<?php session_start(); ## Execution Controller# Version: 1.0.0 (Version.FeatureUpdate.BugFix)# Author: ckrudelux# Website: www.ckrudelux.com# Contact-info: www.ckrudelux.com# Release Date: 2011-09-12 (Y-m-d)### This program is distributed under the terms of the GNU General Public License.# Copyright 2011 ckrudelux# # [License]/** This program is free software: you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by	* the Free Software Foundation, either version 3 of the License, or	* (at your option) any later version.	*	* This program is distributed in the hope that it will be useful,	* but WITHOUT ANY WARRANTY; without even the implied warranty of	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	* GNU General Public License for more details.	*	* You should have received a copy of the GNU General Public License	* along with this program.  If not, see <http://www.gnu.org/licenses/>.*/ /** The purpose of the Execution Controller is to collect* scripts and request to one place.* With the Execution Controller you can make POST/GET request* to classes and functions.** Load lib's needed to the project and execute maintaining* background scripts.*/   # [Defenition]/** What does Program mean?* A program in this context means a file with code what will* execute on load.** What is a Lib:* Callable code is called a libery (lib) which could be a* function or a class and needs to be called to execute.*/   # [install]/** Installing, rename this file index.php or what ever your* main file is called on the server.** if including this file into the index.php you may need* to remove session_start() at the top from this file and add* it to your index.php unless this is included at the top of* your file.*/   # [pree.ini]/** The pree.ini file job is to tell Execution Controller* what to execute before main program.* Note! That the Exection Controller works without a* pree.ini file.** Where are different types categories depending on the* file content.** The different categories are: Lib, Construct and* Program.* Each entry in these categories points to a file the* Execution Controller runs, the categories only tells* what order they will be runed in.* So what type of scripts do you put in what category?** In the lib category goes all callable scripts, like* functions and classes.** In the construct category goes scripts what don't* need any kind of connection to databases.** In the program category goes any kind of script which* needs to run before the main program.** Order in which category loads is as follows:* Lib, Construct and Program.** Creating a pree.ini file:* Each line you add will be a path to a script-file,* the order you put them does matter depending on which* file you want to run first, this does not apply to the* categories.** Expamle:* lib[] = path/to/libery.php* construct[] = path/to/construct.php* lib[] = another/path/to/libery.php* program[] = path/to/program.php** Note! The [] brakets after each categroy name don't* forget them.*/   # [Call]/** The Call function allows to make http request to a* file, class or function.** The idea of this method is to avoid redirections,* then submiting data.* This makes it easier to reuse the data submited later* on if anything would go wrong.** This method can be called by using POST and GET* method, as a note mixing methods won't work.** Setup a call:* First of you need to set the "call" key.** If calling to a file set the "call" key value to the* path where the file in question is.* For sequrity only on dot is allowed in the path for* the file extension.** Calling a Function, set the name of the function to* the "func" key.** Calling a class, set the name of the class to the* "class" key.** Calling a method, set the name of the method to the* "method" key. Need to be combined with the "class"* key.** Calling a static method, add the "static" key to the* query.** Add parameters/arguments to a funtion or class with* the "params" key. Multiple parameters/arguments is* comma seperated.** If you want to make a call without invoking the main* program add "!main" key.*/   # [Main]/** The last thing the Execution Controller look for is* the main program called main.php the file it self* you have to write your self. The only importent thing* is what it's called main.php the rest is up to you.** One option exists and that is to prevent the main* program to execute, this is done by adding the* "!main" key to the query of the http request. This can* be useful when using the call function.*/   ## Safe Execution# Executes a file inside a function to protect taken variable names# from being overwritten.# function sexe($file){  if(file_exists($file)){   include $file;  }} ## Pre Execution (pree.ini)# if(file_exists('pree.ini') && $pree = parse_ini_file('pree.ini')){  if(array_key_exists('lib', $pree)){   foreach($pree['lib'] as $lib){	sexe($lib);   }  }   if(array_key_exists('construct', $pree)){   foreach($pree['construct'] as $program){	sexe($program);   }  }   if(array_key_exists('program', $pree)){   foreach($pree['program'] as $program){	sexe($program);   }  }  unset($pree);} ## Call function# if(isset($_POST['call'])){  if($_POST['call'] != null && count(explode('.', $_POST['call'])) == 1){   sexe($_POST['call']);  }else if(isset($_POST['class'])){   if(isset($_POST['method'])){	if($_POST['static']){	 if(isset($_POST['params'])){	  $params = explode(',', $_POST['params']);	  call_user_func(array($_POST['class'], $_POST['method']), $params);	 }else{	  call_user_func(array($_POST['class'], $_POST['method']));	 }	}else{	 if(isset($_POST['params'])){	  $params = explode(',', $_POST['params']);	  $class = new $_POST['class'];	  call_user_func(array($class, $_POST['method']),$params);	 }else{	  $class = new $_POST['class'];	  call_user_func(array($class, $_POST['method']));	 }	}   }else{	if(isset($_POST['params'])){	 $params = explode(',', $_POST['params']);	 if(empty($params)){	  new $_POST['class'];	 }else{	  $ref = new ReflectionClass($_POST['class']);	  $ref->newInstanceArgs($params);	 }	}else{	 new $_POST['class'];	}   }  }else if(isset($_POST['func'])){   if(isset($_POST['params'])){	$params = explode(',', $_POST['params']);	call_user_func_array($_POST['func'], $params);   }else{	call_user_func($_POST['class']);   }  }} if(isset($_GET['call'])){  if($_GET['call'] != null && count(explode('.', $_GET['call'])) == 1){   sexe($_GET['call']);  }else if(isset($_GET['class'])){   if(isset($_GET['method'])){	if($_GET['static']){	 if(isset($_GET['params'])){	  $params = explode(',', $_GET['params']);	  call_user_func_array(array($_GET['class'], $_GET['method']), $params);	 }else{	  call_user_func(array($_GET['class'], $_GET['method']));	 }	}else{	 if(isset($_GET['params'])){	  $params = explode(',', $_GET['params']);	  $class = new $_GET['class'];	  call_user_func_array(array($class, $_GET['method']),$params);	 }else{	  $class = new $_GET['class'];	  call_user_func(array($class, $_GET['method']));	 }	}   }else{	if(isset($_GET['params'])){	 $params = explode(',', $_GET['params']);	 if(empty($params)){	  new $_GET['class'];	 }else{	  $ref = new ReflectionClass($_GET['class']);	  $ref->newInstanceArgs($params);	 }	}else{	 new $_GET['class'];	}     }  }else if(isset($_GET['func'])){   if(isset($_GET['params'])){	$params = explode(',', $_GET['params']);	call_user_func_array($_GET['func'], $params);   }else{	call_user_func($_GET['class']);   }  }} ## Main Program execution.# if(!isset($_POST['!main']) && !isset($_GET['!main'])){  sexe("main.php");}?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...