Permalink
Browse files

Call Controller and README tweaks

  • Loading branch information...
1 parent 11f0e9e commit 0fb4442638f8b715b4674357341a2abb2445ff96 @dchill42 committed Sep 4, 2012
Showing with 67 additions and 52 deletions.
  1. +28 −27 system/README.md
  2. +37 −23 system/core/CodeIgniter.php
  3. +2 −2 system/core/Loader.php
View
@@ -95,51 +95,52 @@ detail-minded, here is the sequence of events:
* Assess environment, paths, and overrides (routing and assign_to_config)
in index.php and set constants (just as always)
+* Define CI version
* Read config.php and autoload.php files from the application path
* Apply assign_to_config overrides if present
-* Apply autoload package paths
+* Autoload package paths
* Load CodeIgniter extension class (from application or autoloaded package
paths) if present
* Instantiate the CodeIgniter object
* Register the exception handler
* Disable magic quotes for PHP < 5.4
-* Load Benchmark class
-* Mark total execution start time
-* Mark base class loading start time
-* Load Config class and pass the core config items established during
+* Load _Benchmark_ class
+* *Mark total execution start time*
+* *Mark base class loading start time*
+* Load _Config_ class and pass the core config items established during
bootloading (including assign_to_config overrides)
* Read constants.php file(s) from all the application/package paths
-* Load autoload config files
-* Load Hooks class
-* Call pre-system hook
-* Load Loader class and pass the base and application path lists with
+* Autoload config files
+* Load _Hooks_ class
+* *Call pre-system hook*
+* Load _Loader_ class and pass the base and application path lists with
autoloaded package paths applied
-* Load Utf8 class
-* Load URI class
-* Load Output class (to be prepared for 404 output)
-* Load Router class, set routing, and apply routing overrides
-* Call cache-override hook, and if not overridden, check for cache
+* Load _Utf8_ class
+* Load _URI_ class
+* Load _Output_ class (to be prepared for 404 output)
+* Load _Router_ class, set routing, and apply routing overrides
+* *Call cache-override hook*, and if not overridden, check for cache
* If a valid cache is found, send it to Output and jump to the
display-override hook below
-* Load Security class
-* Load Input class
-* Load Lang class
+* Load _Security_ class
+* Load _Input_ class
+* Load _Lang_ class
* Load autoload helpers, languages, libraries, drivers, controllers, and models
(in that order, and don't run controllers)
-* Mark base class loading end time
-* Call pre-controller hook
-* Mark controller execution start time
+* *Mark base class loading end time*
+* *Call pre-controller hook*
+* *Mark controller execution start time*
* Load the routed controller (or 404 if not found)
-* Call post-controller-constructor hook
+* *Call post-controller-constructor hook*
* Call routed controller method (or remap) (or 404 if not found)
-* THE CONTROLLER RUNS
-* Mark controller execution end time
-* Call post-controller hook
-* Call display-override hook, and if not overridden, display output
-* Call post-system hook
+* _THE CONTROLLER RUNS_
+* *Mark controller execution end time*
+* *Call post-controller hook*
+* *Call display-override hook*, and if not overridden, display output
+* *Call post-system hook*
All core classes (now including Log) may be extended by classes with the
-configured subclass prefix existing anywhere in the package paths.
+configured subclass prefix existing anywhere in the autoloaded package paths.
The Log class no longer reads its own config items directly, but rather is
passed all core config items starting with "log" found in config.php during
@@ -99,6 +99,13 @@ class CodeIgniter {
protected static $instance = NULL;
/**
+ * call_controller return scheme constants
+ */
+ const RET_SUCCESS = 0;
+ const RET_RESULT = 1;
+ const RET_OUTPUT = 2;
+
+ /**
* Constructor
*
* This constructor is protected in order to force instantiation
@@ -486,49 +493,56 @@ public function is_callable($class, $method)
* Requires that controller already be loaded, validates method name, and calls
* _remap if available.
*
- * @param string class name
- * @param string method
- * @param array arguments
- * @param string optional object name
- * @param bool TRUE to return output
- * @return mixed Output if $return, TRUE on success, otherwise FALSE
+ * @param string Class name
+ * @param string Method
+ * @param array Arguments
+ * @param string Optional object name
+ * @param int Return scheme (RET_SUCCESS|RET_RESULT|RET_OUTPUT)
+ * @return mixed Success (TRUE|FALSE), call result, or output
*/
- public function call_controller($class, $method, array $args = array(), $name = '', $return = FALSE)
+ public function call_controller($class, $method, array $args = array(), $name = '', $return = self::RET_SUCCESS)
{
// Default name if not provided
if (empty($name))
{
$name = strtolower($class);
}
+ // Track whether it ran and what it returned
+ $ran = FALSE;
+ $result = NULL;
+
+ // Capture output if requested
+ if ($return === self::RET_OUTPUT)
+ {
+ $this->output->stack_push();
+ }
+
// Class must be loaded, and method cannot start with underscore, nor be a member of the base class
if (isset($this->$name) && strncmp($method, '_', 1) != 0 && ! $this->is_callable('CI_Controller', $method))
{
// Check for _remap
if ($this->is_callable($class, '_remap'))
{
- // Call _remap, capturing output if requested
- if ($return)
- {
- $this->output->fork_output();
- }
- $this->$name->_remap($method, $args);
- return $return ? $this->output->get_forked() : TRUE;
+ // Call _remap
+ $result = $this->$name->_remap($method, $args);
+ $ran = TRUE;
}
else if ($this->is_callable($class, $method))
{
- // Call method, capturing output if requested
- if ($return)
- {
- $this->output->fork_output();
- }
- call_user_func_array(array(&$this->$name, $method), $args);
- return $return ? $this->output->get_forked() : TRUE;
+ // Call method
+ $result = call_user_func_array(array(&$this->$name, $method), $args);
+ $ran = TRUE;
}
}
- // Neither _remap nor method could be called
- return FALSE;
+ // Return according to scheme
+ switch ($return)
+ {
+ case self::RET_RESULT: return $result;
+ case self::RET_OUTPUT: return $this->output->stack_pop();
+ default: return $ran;
+ }
}
/**
View
@@ -245,10 +245,10 @@ public function library($library = '', $params = NULL, $object_name = NULL)
* @param string the name of the class
* @param string name for the controller
* @param bool FALSE to skip calling controller method
- * @param bool TRUE to return output (depends on $call == TRUE)
+ * @param int Return scheme (RET_SUCCESS|RET_RESULT|RET_OUTPUT)
* @return mixed Output if $return, TRUE on success, otherwise FALSE
*/
- public function controller($route, $name = NULL, $call = TRUE, $return = FALSE)
+ public function controller($route, $name = NULL, $call = TRUE, $return = CodeIgniter::RET_SUCCESS)
{
// Check for missing class
if (empty($route))

0 comments on commit 0fb4442

Please sign in to comment.