Yii 1.1: gimport

Recursive directory import with caching
4 followers

GImport class implements recursive import of directories with caching.

Import is performed recursively for specified path alias. Classes found are cached, so the import process can be slow only first time.

Requirements

Tested on Yii 1.1.10

Usage

Download and extract archive into protected/components directory.

Basic usage example:

$importer = new GImport;
$importer->add('modules.myModule.*');

This code will import all clasees from modules/myModule/ directory.

GImport can also be configured as application component. Add following code into the application config:

return array(
  ...
  'preload' => array('log', 'import'),
  ...
  'components' => array(
    'import' => array(
        'class'=>'GImport',
        'import' => array(
             // add directories to import and
             // put 'import' component to preload to trigger import 
             // on application initialization
             'application.extensions.*',
         ),
    ),
   ...

To import additional classes in runtime use following code:

Yii::app()->import->add('modules.myModule.*');

Class names and paths will be added to Yii::$classMap and available for autoload. Import performed only once for each alias. Class cache is saved into file in the (by default)runtime/classes directory. During development clean 'runtime/classes' after changing files structure or set '$cacheEnabled' property to false to disable file cache.

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: seb
  • Category: Others
  • Votes: +1
  • Downloaded: 138 times
  • Created on: Oct 10, 2012
  • Last updated: Oct 10, 2012
  • Tags: import