src/Factory.php
public static function load($instance_identifier) {
		$args = func_get_args();

		$instance_identifier	= array_shift($args);
		$factory_args			= $args;

		// get factory config
		$instance_identifier = explode(':', $instance_identifier);
		
		// create a fully namespaced class path
		$classname = $instance_identifier[0];
		if ($classname{0} != '\\') {
			$classname = '\\Morrow\\' . $classname;
		}

		// set the instancename we need to get possible parameters from prepare
		$instancename = (isset($instance_identifier[1])) ? $instance_identifier[1] : '_morrow_default';

		// if there were no constructor parameters passed look for prepared parameters
		if (count($factory_args) === 0) {
			if (isset(self::$_params[$classname][$instancename])) {
				$classname = self::$_params[$classname][$instancename]['classname'];
				$factory_args = self::$_params[$classname][$instancename]['args'];
			} else {
				$factory_args = [];
			}
		}
		
		// if the instance was already instantiated return it, otherwise create it
		$instance =& self::$_instances[$classname][$instancename];
		
		if (isset($instance)) {
			if ($instance instanceof $classname) return $instance;
			else {
				throw new \Exception('instance "'.$instancename.'" already defined of class "'.get_class($instance).'"');
				return false;
			}
		}

		// create object
		if (empty($factory_args)) {
			$instance = new $classname;
		} else {
			// check the parameters for instances of class Factoryproxy
			$factory_args = array_map(function($param){
				if (!is_object($param) || get_class($param) !== 'Morrow\\Factory') return $param;
				return call_user_func_array('\\Morrow\\Factory::load', $param->_getProxyParameters());
			}, $factory_args);

			// use reflection class to inject the args as single parameters
			$ref = new \ReflectionClass($classname);
			$instance = $ref->newInstanceArgs($factory_args);
		}

		// first execute onload callback for all instances, then for the specific instance
		if (isset(self::$_onload_callbacks[$classname])) {
			foreach (self::$_onload_callbacks[$classname] as $callback) {
				call_user_func($callback, $instance);
			}
		}
		if (isset(self::$_onload_callbacks[$classname . ':' . $instancename])) {
			foreach (self::$_onload_callbacks[$classname . ':' . $instancename] as $callback) {
				call_user_func($callback, $instance);
			}
		}

		return $instance;
	}
public static function load($instance_identifier) {
		$args = func_get_args();

		$instance_identifier	= array_shift($args);
		$factory_args			= $args;

		// get factory config
		$instance_identifier = explode(':', $instance_identifier);
		
		// create a fully namespaced class path
		$classname = $instance_identifier[0];
		if ($classname{0} != '\\') {
			$classname = '\\Morrow\\' . $classname;
		}

		// set the instancename we need to get possible parameters from prepare
		$instancename = (isset($instance_identifier[1])) ? $instance_identifier[1] : '_morrow_default';

		// if there were no constructor parameters passed look for prepared parameters
		if (count($factory_args) === 0) {
			if (isset(self::$_params[$classname][$instancename])) {
				$classname = self::$_params[$classname][$instancename]['classname'];
				$factory_args = self::$_params[$classname][$instancename]['args'];
			} else {
				$factory_args = [];
			}
		}
		
		// if the instance was already instantiated return it, otherwise create it
		$instance =& self::$_instances[$classname][$instancename];
		
		if (isset($instance)) {
			if ($instance instanceof $classname) return $instance;
			else {
				throw new \Exception('instance "'.$instancename.'" already defined of class "'.get_class($instance).'"');
				return false;
			}
		}

		// create object
		if (empty($factory_args)) {
			$instance = new $classname;
		} else {
			// check the parameters for instances of class Factoryproxy
			$factory_args = array_map(function($param){
				if (!is_object($param) || get_class($param) !== 'Morrow\\Factory') return $param;
				return call_user_func_array('\\Morrow\\Factory::load', $param->_getProxyParameters());
			}, $factory_args);

			// use reflection class to inject the args as single parameters
			$ref = new \ReflectionClass($classname);
			$instance = $ref->newInstanceArgs($factory_args);
		}

		// first execute onload callback for all instances, then for the specific instance
		if (isset(self::$_onload_callbacks[$classname])) {
			foreach (self::$_onload_callbacks[$classname] as $callback) {
				call_user_func($callback, $instance);
			}
		}
		if (isset(self::$_onload_callbacks[$classname . ':' . $instancename])) {
			foreach (self::$_onload_callbacks[$classname . ':' . $instancename] as $callback) {
				call_user_func($callback, $instance);
			}
		}

		return $instance;
	}
public static function load ( $ instance_identifier ) { $ args = func_get_args ( ) ; $ instance_identifier = array_shift ( $ args ) ; $ factory_args = $ args ; // get factory config $ instance_identifier = explode ( ':' , $ instance_identifier ) ; // create a fully namespaced class path $ classname = $ instance_identifier [ 0 ] ; if ( $ classname { 0 } != '\\' ) { $ classname = '\\Morrow\\' . $ classname ; } // set the instancename we need to get possible parameters from prepare $ instancename = ( isset ( $ instance_identifier [ 1 ] ) ) ? $ instance_identifier [ 1 ] : '_morrow_default' ; // if there were no constructor parameters passed look for prepared parameters if ( count ( $ factory_args ) === 0 ) { if ( isset ( self :: $ _params [ $ classname ] [ $ instancename ] ) ) { $ classname = self :: $ _params [ $ classname ] [ $ instancename ] [ 'classname' ] ; $ factory_args = self :: $ _params [ $ classname ] [ $ instancename ] [ 'args' ] ; } else { $ factory_args = [ ] ; } } // if the instance was already instantiated return it, otherwise create it $ instance = & self :: $ _instances [ $ classname ] [ $ instancename ] ; if ( isset ( $ instance ) ) { if ( $ instance instanceof $ classname ) return $ instance ; else { throw new \ Exception ( 'instance "' . $ instancename . '" already defined of class "' . get_class ( $ instance ) . '"' ) ; return false ; } } // create object if ( empty ( $ factory_args ) ) { $ instance = new $ classname ; } else { // check the parameters for instances of class Factoryproxy $ factory_args = array_map ( function ( $ param ) { if ( ! is_object ( $ param ) || get_class ( $ param ) !== 'Morrow\\Factory' ) return $ param ; return call_user_func_array ( '\\Morrow\\Factory::load' , $ param -> _getProxyParameters ( ) ) ; } , $ factory_args ) ; // use reflection class to inject the args as single parameters $ ref = new \ ReflectionClass ( $ classname ) ; $ instance = $ ref -> newInstanceArgs ( $ factory_args ) ; } // first execute onload callback for all instances, then for the specific instance if ( isset ( self :: $ _onload_callbacks [ $ classname ] ) ) { foreach ( self :: $ _onload_callbacks [ $ classname ] as $ callback ) { call_user_func ( $ callback , $ instance ) ; } } if ( isset ( self :: $ _onload_callbacks [ $ classname . ':' . $ instancename ] ) ) { foreach ( self :: $ _onload_callbacks [ $ classname . ':' . $ instancename ] as $ callback ) { call_user_func ( $ callback , $ instance ) ; } } return $ instance ; }
Initializes a class with optionally prepared constructor parameters and returns the instance.
@param	string	$instance_identifier The instance identifier.
@return	object
Initializes a class with optionally prepared constructor parameters and returns the instance .