How To Force Inclusion By Config Entry?

When specifiying what to import in config file, doesn’t seem to exist the possibility of forcing it for specific files or dirs.

Then, how can an import be forced by application initial config?

My target is to override an extension models and components,

that’s why I want to force declaring my overridden classes.

I think boostrap patter is the correct one for doing this.

Then is there any other better way?

Thanks anyone

I think I must use preload entry for putting some responsive code… i’ll give a try and tell

You could specify by rooting alias.

for example

instead of

‘cache’ => array(

        'class' => 'CDbCache',

),

use

‘cache’ => array(

        'class' => 'application.components.CDbCache',

),

and write your own class CDbCache into protected/components/CDbCache

either or not extending the core CDbCache

Thanks, but this wasn’t the solution for the exposed problem.

I already knew that a class can be expressed as a path.

Finally, I adopted that solution




'preload'=>array('log','phpdefinedfunctions','yumuseridentity'),


// and later

'components'=>array(

		'phpdefinedfunctions'=>array(			

			'class' => 'application.extensions.phpDefinedFunctions'

	

		),

		'yumuseridentity'=>array(

			'class'=>'application.components.YumUserIdentity',

		),		



This code helped to load at import process a class that replaced YumUserIdentity.

The trick has this appearance:

protected/extensions/phpDefinedFunctions.php





class phpDefinedFunctions extends CApplicationComponent{


}


if (!array_key_exists('tmp_files',$GLOBALS))

	$GLOBALS['tmp_files'] = array();	


if (!function_exists('destruct_tmp_files')){

	function destruct_tmp_files(){

		while (count($GLOBALS['tmp_files']))	

			file_exists($file=array_shift($GLOBALS['tmp_files'])) && @unlink($file);		

	}

	register_shutdown_function("destruct_tmp_files"); 

}




if (!function_exists('include_code')){

	function include_code($code){

		$temp = tmpfile();

		$GLOBALS['tmp_files'][] = array_search('uri', @array_flip(stream_get_meta_data($temp)));

		fwrite($temp, $code);

		

		include(end($GLOBALS['tmp_files']));

		fclose($temp);

	}

}



protected/components/YumUserIdentity.php




$parent_class = Yii::getPathOfAlias('application.modules.user.components.YumUserIdentity').'.php';

if (file_exists($parent_class)){

	$parent_class=file_get_contents($parent_class);

	$parent_class=preg_replace('/class YumUserIdentity/','class YumUserIdentityOld',$parent_class);	

	if (!class_exists('YumUserIdentityOld',$autoload=false)){

		include_code($parent_class);		

		class YumUserIdentity extends YumUserIdentityOld{

			

			public function __construct($username=null,$password=null)

			{	

				parent::__construct($username,$password);

			}


			public function init(){

				Yii::import('application.models.YumEncrypt',$forceInclude=true);

				return true;

			}

			

		}	

		

	}

}