Exemplo n.º 1
0
 public static function initialize($sf_symfony_lib_dir)
 {
     self::$class_paths = array();
     self::register($sf_symfony_lib_dir, '.class.php');
     self::register($sf_symfony_lib_dir . '/vendor/propel', '.php');
     self::register($sf_symfony_lib_dir . '/vendor/creole', '.php');
     self::register('lib/model', '.php');
     self::register('plugins', '.php');
 }
Exemplo n.º 2
0
function run_doctrine_generate_crud($task, $args)
{
    if (count($args) < 2) {
        throw new Exception('You must provide your module name.');
    }
    if (count($args) < 3) {
        throw new Exception('You must provide your model class name.');
    }
    $app = $args[0];
    $module = $args[1];
    $model_class = $args[2];
    $theme = isset($args[3]) ? $args[3] : 'crud';
    // function variables
    $doctrineModelDir = sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR;
    $sf_root_dir = sfConfig::get('sf_root_dir');
    $sf_symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir');
    $pluginDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
    $doctrineLibDir = $pluginDir . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR . 'Doctrine' . DIRECTORY_SEPARATOR;
    $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true));
    sfConfig::set('sf_module_cache_dir', $tmp_dir);
    sfConfig::set('sf_app_dir', $tmp_dir);
    // add classes to autoload function
    pake_echo_action('PluginDir', $pluginDir);
    simpleAutoloader::registerCallable(array('Doctrine', 'autoload'));
    // generate module
    $generator_manager = new sfGeneratorManager();
    $generator_manager->initialize();
    $generator_manager->generate('sfDoctrineAdminGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme));
    $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module;
    // copy our generated module
    $finder = pakeFinder::type('any');
    pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir);
    // change module name
    pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module));
    try {
        $author_name = $task->get_property('author', 'symfony');
    } catch (pakeException $e) {
        $author_name = 'Your name here';
    }
    $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name);
    // customize php files
    $finder = pakeFinder::type('file')->name('*.php');
    pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
    // delete temp files
    $finder = pakeFinder::type('any');
    pake_remove($finder, $tmp_dir);
    // for some reason the above does not remove the tmp dir as it should.
    // delete temp dir
    @rmdir($tmp_dir);
    // delete cache/tmp
    @rmdir(sfConfig::get('sf_cache_dir') . 'tmp');
}