예제 #1
0
 /**
  * Default run method
  * TODO: Needs more work
  * @return	void
  */
 public function run()
 {
     $this->printMessage('Generating code event listener...');
     $config = XDT_CLI_Application::getConfig();
     $namespace = $config['namespace'] . '_';
     $className = $namespace . 'Listener';
     if (!$namespace) {
         $namespace = '';
     }
     if (!XDT_CLI_Helper::classExists($className, false)) {
         //$extendName = 'XenForo_Controller' . XfCli_Helpers::camelcaseString($type, false) . '_Abstract';
         $class = new Zend_CodeGenerator_Php_Class();
         $class->setName($className);
         //$class->setExtendedClass($extendName);
         XDT_CLI_ClassGenerator::create($className, $class);
         $this->printMessage('ok');
     } else {
         $this->printMessage('skipped (already exists)');
     }
     $this->printMessage($namespace);
     if (!empty($config['name'])) {
         $this->printMessage($this->colorText('Active Add-on: ', XDT_CLI_Abstract::BROWN), false);
         $this->printMessage($config['name']);
     } else {
         $this->printMessage($this->colorText('No add-on selected.', XDT_CLI_Abstract::RED));
     }
 }
예제 #2
0
 public function getContents()
 {
     // Configuring after instantiation
     $methodUp = new Zend_CodeGenerator_Php_Method();
     $methodUp->setName('up')->setBody('// upgrade');
     // Configuring after instantiation
     $methodDown = new Zend_CodeGenerator_Php_Method();
     $methodDown->setName('down')->setBody('// degrade');
     $class = new Zend_CodeGenerator_Php_Class();
     $class->setName('Migration_' . $this->getMigrationName())->setExtendedClass('Core_Migration_Abstract')->setMethod($methodUp)->setMethod($methodDown);
     $file = new Zend_CodeGenerator_Php_File();
     $file->setClass($class)->setFilename($this->getPath());
     return $file->generate();
 }
예제 #3
0
 public function addSuccess($param)
 {
     if ($param['resourceId'] && $param['model']) {
         $nameExploded = explode('_', $param['resourceId']);
         $nameExploded = array_map('ucfirst', $nameExploded);
         $controllerName = $nameExploded[count($nameExploded) - 1];
         unset($nameExploded[count($nameExploded) - 1]);
         $ds = DIRECTORY_SEPARATOR;
         $path = APPLICATION_PATH . $ds . 'modules' . $ds . $this->getRequest()->getModuleName() . $ds . 'controllers' . (($pathAdd = implode($ds, $nameExploded)) ? $ds . $pathAdd : '');
         $fileName = $controllerName . 'Controller.php';
         $controllerName = ucfirst($this->getRequest()->getModuleName()) . '_' . (($filePrefix = implode('_', $nameExploded)) ? $filePrefix . '_' : '') . $controllerName . 'Controller';
         $class_file = new Zend_CodeGenerator_Php_Class(array('name' => $controllerName, 'extendedclass' => 'Z_Admin_Controller_Datacontrol_Abstract'));
         Z_Fs::create_file($path . $ds . $fileName, "<?\n" . $class_file->generate());
     }
 }
예제 #4
0
파일: Form.php 프로젝트: nuxwin/losolib
 protected function _getForm()
 {
     $form = new Zend_CodeGenerator_Php_Class();
     $form->setName('{%moduleNamespace}_Form_{%entity}');
     $form->setExtendedClass('Zend_Form');
     $form->setMethod($this->_getInitMethod());
     $form->setMethod($this->_getPopulateMethod());
     return $form;
 }
예제 #5
0
 /**
  * Генерирует класс модели
  * @param string $className
  * Название класса (без префикса)
  * @param string $tableName
  * Название таблицы в БД
  * @param array $params
  * Параметры для переопределения настроек по умолчанию
  * @return string
  */
 public static function generate($className, $tableName = NULL, $params = array())
 {
     if (strpos($className, 'z_') === 0 && Z_Auth::getInstance()->getUser()->getRole() == 'root') {
         $path_prefix = APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'Z' . DIRECTORY_SEPARATOR . 'Model';
         self::$_classPrefix = isset($params['prefixz']) ? $params['prefixz'] : self::$_classPrefixZ;
     } else {
         $path_prefix = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'models';
         self::$_classPrefix = isset($params['prefix']) ? $params['prefix'] : self::$_classPrefix;
     }
     if ($tableName == NULL) {
         $tableName = strtolower($className);
     }
     $className = explode('_', $className);
     $className = array_map('ucfirst', $className);
     $path = $className;
     unset($path[count($path) - 1]);
     $path = implode(DIRECTORY_SEPARATOR, $path);
     $filename = $className[count($className) - 1] . '.php';
     $className = implode('_', $className);
     $filepath = $path_prefix . DIRECTORY_SEPARATOR . $path;
     $generator = new Zend_CodeGenerator_Php_Class();
     $generator->setName(self::$_classPrefix . $className)->setExtendedClass(self::$_extendedClass)->setProperty(array('name' => '_name', 'visibility' => 'protected', 'defaultValue' => $tableName));
     Z_Fs::create_file($filepath . DIRECTORY_SEPARATOR . $filename, "<?\n" . $generator->generate());
 }
예제 #6
0
 public function insertControl($data)
 {
     $ok = true;
     $name = ucfirst(strtolower($data['name']));
     $controller = new Zend_CodeGenerator_Php_Class();
     $controller->setName($name . 'Controller');
     if ($data['parent']) {
         $controller->setExtendedClass($data['parent']);
     }
     if ($data['action']) {
         $ml = explode(',', str_replace(array(' '), array(''), trim($data['action'])));
         $act = array();
         foreach ($ml as $el) {
             $el = strtolower($el);
             $act[] = array('name' => $el . 'Action');
         }
         if ($act) {
             $controller->setMethods($act);
         }
     }
     $doc['tags'] = array();
     if ($data['zk_title']) {
         $doc['tags'][] = array('name' => 'zk_title', 'description' => $data['zk_title']);
     }
     if (!$data['zk_routable']) {
         $doc['tags'][] = array('name' => 'zk_routable', 'description' => 0);
     }
     if (!$data['zk_config']) {
         $doc['tags'][] = array('name' => 'zk_config', 'description' => 0);
     }
     if ($data['zk_routes']) {
         $doc['tags'][] = array('name' => 'zk_routes', 'description' => $data['zk_routes']);
     }
     if ($doc['tags']) {
         $controller->setDocblock(new Zend_CodeGenerator_Php_Docblock($doc));
     }
     $c = '<?php' . "\n\n" . $controller->generate();
     $ok = file_put_contents(APPLICATION_PATH . '/controllers/' . $name . 'Controller.php', $c);
     if ($ok) {
         @chmod(APPLICATION_PATH . '/controllers/' . $name . 'Controller.php', 0777);
     }
     return $ok;
 }
예제 #7
0
 /**
  * Method for generate the file form.
  * 
  * @param string $table
  * @param string $schema
  * @param array $column
  * @return string
  */
 public function generateFile($table, $schema, $columns)
 {
     try {
         $className = $fileName = $formName = $this->adjustsName($table);
         if (is_null($this->getNamespace())) {
             $className = $this->getClassPrefix() . $className;
         }
         $extendedClass = 'Zend_Form';
         if (!is_null($this->getNamespace())) {
             $extendedClass = $this->getNamespaceCharacter() . $extendedClass;
         }
         $class = new \Zend_CodeGenerator_Php_Class();
         $class->setExtendedClass($extendedClass);
         $class->setName($className);
         $class->setDocblock(new \Zend_CodeGenerator_Php_Docblock(array('shortDescription' => $className . ' form file.')));
         $constructBody = 'parent::__construct($options);' . PHP_EOL . PHP_EOL;
         $constructBody .= '$this->setName(\'frm' . $formName . '\');' . PHP_EOL;
         $constructBody .= '$this->setMethod(\'post\');' . PHP_EOL . PHP_EOL;
         $this->resetConstructParameters();
         foreach ($columns as $columnName => $params) {
             if ($params['primaryKey'] === true && $this->getGeneratePrimaryKeys() === false) {
                 continue;
             }
             $elementName = $this->adjustsName($columnName, true);
             $constructBody .= $this->createContentOfElementColumn($elementName, $columnName, $params);
         }
         $constructBody .= $this->createContentSubmit();
         $this->addConstructorParameters(array('name' => 'options', 'defaultValue' => null));
         $class->setMethods(array(array('name' => '__construct', 'parameters' => $this->getConstructorParameters(), 'body' => $constructBody)));
         $code = $class->generate();
         if (!is_null($this->getNamespace())) {
             $code = 'namespace ' . $this->getNamespace() . ';' . PHP_EOL . PHP_EOL . $code;
         }
         $code = '<?php' . PHP_EOL . PHP_EOL . $code;
         file_put_contents($this->getFileDestination() . '/' . $fileName . $this->getFileExtension(), $code);
         return 'Generated file ' . $fileName . $this->getFileExtension() . '...' . PHP_EOL;
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
예제 #8
0
파일: crudify.php 프로젝트: jaybill/Bolts
            }
        }
        if (!$column['NULLABLE'] and !in_array($key, $required) and !$column['IDENTITY']) {
            $required[] = $key;
        }
    }
} else {
    die("Table " . $table_name . " does not exist.\n");
}
// create new model class
$model_class = new Zend_CodeGenerator_Php_Class();
$model_class->setName($object_name)->setExtendedClass($abstract_table_object_name)->setProperties(array(array('name' => '_name', 'visibility' => 'protected', 'defaultValue' => $table_name), array('name' => '_primary', 'visibility' => 'protected', 'defaultValue' => $pk)));
$model_file = new Zend_CodeGenerator_Php_File();
$model_file->setClass($model_class);
// create new controller class
$controller_class = new Zend_CodeGenerator_Php_Class();
if ($is_admin) {
    $controller_class->setName($controller_name)->setExtendedClass("Bolts_Controller_Action_Admin");
} else {
    $controller_class->setName($controller_name)->setExtendedClass("Bolts_Controller_Action_Abstract");
}
if (!is_array($pk)) {
    // init method - required for all Communitas controller classes
    $init_method = new Zend_CodeGenerator_Php_Method();
    $init_method_body = "\t\tparent::init();";
    $init_method->setName('init')->setBody($init_method_body);
    $controller_class->setMethod($init_method);
    // edit action
    $edit_method = new Zend_CodeGenerator_Php_Method();
    $edit_method_body = file_get_contents($basepath . "/modules/bolts/extras/crudify_templates/editAction.txt");
    $data_array_string = "";
예제 #9
0
 /**
  * getContents()
  *
  * @return string
  */
 public function getContents()
 {
     $filter = new Zend_Filter_Word_DashToCamelCase();
     $className = $filter->filter($this->_projectProviderName) . 'Provider';
     $class = new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Tool_Project_Provider_Abstract'));
     $methods = array();
     foreach ($this->_actionNames as $actionName) {
         $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => $actionName, 'body' => '        /** @todo Implementation */'));
     }
     if ($methods) {
         $class->setMethods($methods);
     }
     $codeGenFile = new Zend_CodeGenerator_Php_File(array('requiredFiles' => array('Zend/Tool/Project/Provider/Abstract.php', 'Zend/Tool/Project/Provider/Exception.php'), 'classes' => array($class)));
     return $codeGenFile->generate();
 }
예제 #10
0
 /**
  * Method create's new migration file
  *
  * @param  string $module Module name
  * @param null    $migrationBody
  * @param string  $label
  * @param string  $desc
  * @return string Migration name
  */
 public function create($module = null, $migrationBody = null, $label = '', $desc = '')
 {
     $path = $this->getMigrationsDirectoryPath($module);
     list($sec, $msec) = explode(".", microtime(true));
     $_migrationName = date('Ymd_His_') . substr($msec, 0, 2);
     if (!empty($label)) {
         $_migrationName .= '_' . $label;
     }
     // Configuring after instantiation
     $methodUp = new Zend_CodeGenerator_Php_Method();
     $methodUp->setName('up')->setBody('// upgrade');
     // Configuring after instantiation
     $methodDown = new Zend_CodeGenerator_Php_Method();
     $methodDown->setName('down')->setBody('// degrade');
     //add description
     if (!empty($desc)) {
         $methodDesc = new Zend_CodeGenerator_Php_Method();
         $methodDesc->setName('getDescription')->setBody("return '" . addslashes($desc) . "'; ");
     }
     if ($migrationBody) {
         if (isset($migrationBody['up'])) {
             $upBody = '';
             foreach ($migrationBody['up'] as $query) {
                 $upBody .= '$this->query(\'' . $query . '\');' . PHP_EOL;
             }
             $methodUp->setBody($upBody);
         }
         if (isset($migrationBody['down'])) {
             $downBody = '';
             foreach ($migrationBody['down'] as $query) {
                 $downBody .= '$this->query(\'' . $query . '\');' . PHP_EOL;
             }
             $methodDown->setBody($downBody);
         }
     }
     $class = new Zend_CodeGenerator_Php_Class();
     $className = (null !== $module ? ucfirst($module) . '_' : '') . 'Migration_' . $_migrationName;
     $class->setName($className)->setExtendedClass('Core_Migration_Abstract')->setMethod($methodUp)->setMethod($methodDown);
     if (isset($methodDesc)) {
         $class->setMethod($methodDesc);
     }
     $file = new Zend_CodeGenerator_Php_File();
     $file->setClass($class)->setFilename($path . '/' . $_migrationName . '.php')->write();
     return $_migrationName;
 }
예제 #11
0
    public function testAction()
    {
        $name = 'Testing1';
        $dir  = ROOT_PATH . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . 'Action';
        $file = $dir . DIRECTORY_SEPARATOR . $name . '.php';
        require_once $file;

        $class = Zend_CodeGenerator_Php_Class::fromReflection(
            new Zend_Reflection_Class('Action_' . $name)
        );

        $error  = array();
        $errors = array();

        foreach ($class->getMethods() as $key => $method) {
            $body = $method->getBody();
            $methodName = $method->getName();

            $toks = token_get_all('<?' . 'php ' . $body . '?>');

            $it = new ArrayIterator($toks);

            for ($it->rewind(); $it->valid(); $it->next()) {
                $current = $it->current();
                $key = $it->key();

                $item = (double)$current[0];

                if ($item == T_STRING && stristr('frapi_error', $current[1]) !== false) {
                    if ($error = $this->getErrors($it, $methodName)) {
                        $errors[] = $error;
                    }
                }

            }
        }

        //print_r($errors);

        die();

    }
예제 #12
0
파일: ClassTest.php 프로젝트: jsnshrmn/Suma
    /**
     * @group ZF-11513
     */
    public function testAllowsClassConstantToHaveSameNameAsClassProperty()
    {
        $const = new Zend_CodeGenerator_Php_Property();
        $const->setName('name')->setDefaultValue('constant')->setConst(true);
        $property = new Zend_CodeGenerator_Php_Property();
        $property->setName('name')->setDefaultValue('property');
        $codeGenClass = new Zend_CodeGenerator_Php_Class();
        $codeGenClass->setName('My_Class')->setProperties(array($const, $property));
        $expected = <<<CODE
class My_Class
{

    const name = 'constant';

    public \$name = 'property';


}

CODE;
        $this->assertEquals($expected, $codeGenClass->generate());
    }
예제 #13
0
    /**
     *
     * @param string $pAction
     * @return string
     */
    public function create_action($pAction = NULL, $pParams = NULL)
    {
        $action = $pAction ? $pAction : $this->get_action();
        if ($pParams && array_key_exists('view_body', $pParams)) {
            $view_body = $pParams['view_body'];
            unset($pParams['view_body']);
        } else {
            $view_body = '';
            if ($pParams && is_array($pParams) && count($pParams)) {
                foreach ($pParams as $param) {
                    if (is_array($param)) {
                        list($name, $alias, $default) = $param;
                        $default = trim($default);
                    } elseif (!trim($param)) {
                        continue;
                    } else {
                        $name = $alias = trim($param);
                        $default = NULL;
                    }
                    $name = trim($name);
                    if (!$name) {
                        continue;
                    }
                    ob_start();
                    ?>
    $this-><?php 
                    echo $name;
                    ?>
;
    
<?php 
                    $view_body .= ob_get_clean();
                }
            }
        }
        $file = $this->controller_reflection();
        $c = $file->getClass($this->controller_class_name());
        $aname = "{$action}Action";
        $class = Zend_CodeGenerator_Php_Class::fromReflection($c);
        if (!$class->hasMethod($aname)) {
            $body = '';
            $reflect = '';
            if ($pParams && is_array($pParams) && count($pParams)) {
                ob_start();
                foreach ($pParams as $param) {
                    if (!trim($param)) {
                        continue;
                    } elseif (is_array($param)) {
                        list($name, $alias, $default) = $param;
                        $default = trim($default);
                    } else {
                        $name = $alias = trim($param);
                        $default = NULL;
                    }
                    $name = trim($name);
                    if (!$name) {
                        continue;
                    }
                    printf('$%s = $this->_getParam("%s", %s); ', $name, $alias, is_null($default) ? ' NULL ' : "'{$default}'");
                    ob_start();
                    printf('$this->view->%s = $%s;', $name, $name);
                    ?>
    
<?php 
                    $reflect .= ob_get_clean();
                    ?>
    <?php 
                }
                $body = ob_get_clean() . "\n" . $reflect;
            }
            $old = $this->backup_controller();
            $method = new Zend_CodeGenerator_Php_Method();
            $method->setName($aname)->setBody($body);
            $class->setMethod($method);
            $file = new Zend_CodeGenerator_Php_File();
            $file->setClass($class);
            $new_file = preg_replace('~[\\r\\n][\\s]*[\\r\\n]~', "\r", $file->generate());
            file_put_contents($this->controller_path(), $new_file);
            $view_path = $this->view_path($action);
            if (!file_exists($view_path)) {
                $dir = dirname($view_path);
                if (!is_dir($dir)) {
                    mkdir($dir, 0775, TRUE);
                }
                file_put_contents($view_path, "<?\n\$this->placeholder('page_title')->set('');\n{$view_body}\n");
            }
            $exec = "diff {$this->_backup_path} {$this->controller_path()} ";
            $diff = shell_exec($exec);
            return array('old' => $old, 'new' => $new_file, 'diff' => $diff, 'backup_path' => $this->_backup_path, 'controller_path' => $this->controller_path());
        }
    }
예제 #14
0
 public function table_file()
 {
     $cs = $this->create_sql();
     $create_method = new Zend_CodeGenerator_Php_Method(array('name' => 'create_table', 'visibility' => 'public', 'static' => TRUE, 'body' => "\$this->getInstance()->getAdapter()->query(\"{$cs}\");"));
     $create_method->setStatic(TRUE);
     $init_method = new Zend_CodeGenerator_Php_Method(array('name' => 'init', 'visibility' => 'protected', 'body' => '     $create_method->setStatic(TRUE);'));
     $id_prop = new Zend_CodeGenerator_Php_Property(array('name' => '_id_field', 'defaultValue' => $this->get_id_field(), 'visibility' => 'protected'));
     $name_prop = new Zend_CodeGenerator_Php_Property(array('name' => '_name', 'defaultValue' => $this->get_table_name(), 'visibility' => 'protected'));
     $class = new Zend_CodeGenerator_Php_Class(array('name' => $this->get_table_class_name(), 'extendedClass' => 'Zupal_Table_Abstract', 'methods' => array($create_method), 'properties' => array($id_prop, $name_prop)));
     if ($this->get_database_name()) {
         $const = new Zend_CodeGenerator_Php_Method(array('name' => '__construct', 'body' => '        parent::__construct(array("db" => Zupal_Module_Manager::getInstance()->database("' . $this->get_database_name() . '")));'));
         $class->setMethod($const);
     }
     $file = new Zend_CodeGenerator_Php_File(array('classes' => array($class)));
     return $file;
 }
    /**
     * @group ZF-9602
     */
    public function testSetextendedclassShouldNotIgnoreNonEmptyClassnameOnGenerate()
    {
        $codeGenClass = new Zend_CodeGenerator_Php_Class();
        $codeGenClass->setName('MyClass')->setExtendedClass('ParentClass');
        $expected = <<<CODE
class MyClass extends ParentClass
{


}

CODE;
        $this->assertEquals($expected, $codeGenClass->generate());
    }
예제 #16
0
파일: ClassTest.php 프로젝트: vicfryzel/zf
 /**
  * @group ZF-7909
  */
 public function testClassFromReflectionDiscardParentImplementedInterfaces()
 {
     if (!class_exists('Zend_CodeGenerator_Php_ClassWithInterface')) {
         require_once dirname(__FILE__) . "/_files/ClassAndInterfaces.php";
     }
     require_once "Zend/Reflection/Class.php";
     $reflClass = new Zend_Reflection_Class('Zend_CodeGenerator_Php_NewClassWithInterface');
     $codeGen = Zend_CodeGenerator_Php_Class::fromReflection($reflClass);
     $codeGen->setSourceDirty(true);
     $code = $codeGen->generate();
     $expectedClassDef = 'class Zend_CodeGenerator_Php_NewClassWithInterface extends Zend_CodeGenerator_Php_ClassWithInterface implements Zend_Code_Generator_Php_ThreeInterface';
     $this->assertContains($expectedClassDef, $code);
 }
예제 #17
0
    public function insertControl($data)
    {
        $ok = true;
        $name = ucfirst($data['parentid']);
        $model = new Zend_CodeGenerator_Php_Class();
        $model->setName('Default_Model_' . $name);
        if ($data['parent']) {
            $model->setExtendedClass($data['parent']);
        }
        $prop = array();
        if ($data['table']) {
            $prop[] = array('name' => '_name', 'visibility' => 'protected', 'defaultValue' => trim($data['table']));
        }
        if ($data['multilang']) {
            $ml = explode(',', str_replace(array(' '), array(''), trim($data['multilang'])));
            $prop[] = array('name' => '_multilang_field', 'visibility' => 'protected', 'defaultValue' => $ml);
        }
        if ($prop) {
            $model->setProperties($prop);
        }
        if ($data['method']) {
            $met = array();
            foreach ($data['method'] as $el) {
                $mn = $mb = '';
                $mp = array();
                switch ($el) {
                    case 'list':
                        $mn = 'fetchList';
                        $mb = 'return $this->fetchAll();';
                        break;
                    case 'list_join':
                        $mn = 'fetchList';
                        $mb = '$m = new Default_Model_Temp();
$s = $this->getAdapter()->select()
	->from(array(\'i\' => $this->info(\'name\')))
	->join(array(\'m\' => $m->info(\'name\')), \'i.parentid = m.id\', array(
		\'temp\' => \'o.title\'
	))
	->group(\'i.id\')
	->order(\'i.orderid\');
return $this->fetchAll($s);';
                        break;
                    case 'card':
                        $mn = 'fetchCard';
                        $mp = array(array('name' => 'id'));
                        $mb = 'return $this->fetchRow(array(\'`stitle` = ?\' => $id));';
                        break;
                    case 'card_join':
                        $mn = 'fetchCard';
                        $mp = array(array('name' => 'id'));
                        $mb = '$m = new Default_Model_Temp();
$s = $this->getAdapter()->select()
	->from(array(\'i\' => $this->info(\'name\')))
	->join(array(\'m\' => $m->info(\'name\')), \'i.parentid = m.id\', array(
		\'temp\' => \'o.title\'
	))
	->group(\'i.id\')
	->where(\'`stitle` = ?\', $id);
return $this->fetchRow($s);';
                        break;
                    case 'idtitle':
                        $mn = 'fetchIdTitle';
                        $mb = 'return $this->fetchPairs(\'id\', \'title\', null, \'orderid\');';
                        break;
                }
                if ($mn) {
                    $met[] = array('name' => $mn, 'body' => $mb, 'parameters' => $mp);
                }
            }
            if ($met) {
                $model->setMethods($met);
            }
        }
        $c = '<?php' . "\n\n" . $model->generate();
        $ok = file_put_contents(APPLICATION_PATH . '/models/' . $name . '.php', $c);
        if ($ok) {
            @chmod(APPLICATION_PATH . '/models/' . $name . '.php', 0777);
        }
        if ($data['table'] && $data['table_create']) {
            $n = substr($data['table_create'], 3);
            $model = new Default_Model_Page();
            switch (substr($data['table_create'], 0, 3)) {
                case '_e_':
                    $model->getAdapter()->query('CREATE TABLE `' . $data['table'] . '` LIKE `' . $n . '`');
                    break;
                case '_t_':
                    $c = file_get_contents(APPLICATION_PATH . '/../library/Zkernel/Other/Template/Db/' . $n);
                    if ($c) {
                        $c = str_replace(array('%name%'), array($data['table']), $c);
                        $model->getAdapter()->query($c);
                    }
                    break;
            }
        }
        return $ok;
    }
예제 #18
0
 function gen($package)
 {
     ini_set('display_errors', 1);
     $xml = App_Model_Config::getConfigFilePath($package);
     //   APPLICATION_PATH . '/configs/' . $package . '-model-config.xml';
     $configFileName = basename($xml);
     $data = $config = new Zend_Config_Xml($xml, 'production');
     $classList = $data->classes;
     $project = $data->project;
     $createPackageFolder = true;
     $destinationFolder = $data->destinationDirectory;
     if ('application' == $project) {
         $createPackageFolder = false;
         $destinationFolder = APPLICATION_PATH . "/" . $destinationFolder;
     } elseif ('global' == $project) {
         $createPackageFolder = true;
         $destinationFolder = GLOBAL_PROJECT_PATH . "/" . $destinationFolder;
     } else {
         $createPackageFolder = true;
         $destinationFolder = realpath(APPLICATION_PATH . "/../library");
     }
     // die($destinationFolder);
     $bodyConstruct = '';
     foreach ($classList as $modelName => $attr) {
         $class = new Zend_CodeGenerator_Php_Class();
         //$class->isAbstract();
         $class->setAbstract(true);
         $class2 = new Zend_CodeGenerator_Php_Class();
         $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => $modelName, 'longDescription' => 'This is a class generated with Zend_CodeGenerator.', 'tags' => array(array('name' => 'uses', 'description' => $package . '_Model_Abstract'), array('name' => 'package', 'description' => $package), array('name' => 'subpackage', 'description' => 'Model'), array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'update', 'description' => date('d/m/Y')), array('name' => 'license', 'description' => 'licensed By Patiwat Wisedsukol patiwat.wi@gmail.com'))));
         //$docblock2 = new Zend_CodeGenerator_Php_Docblock();
         echo "create ", $modelName, "<br/>";
         $class->setName($modelName . "_Abstract");
         $class2->setName($modelName);
         if ('' == trim($attr->extendedClass)) {
             $class->setExtendedClass($package . '_Model_Abstract');
         } else {
             $class->setExtendedClass($attr->extendedClass);
         }
         $class2->setExtendedClass($modelName . '_Abstract');
         $Prop = array();
         $Methods = array();
         $PropertyData = array();
         $columsToPropsList = array();
         $propsToColumsList = array();
         foreach ($attr->prop as $prop) {
             $name = $prop->name;
             $Prop[] = array('name' => "_" . $name, 'visibility' => 'protected', 'defaultValue' => null);
             $pdata = array();
             $PropertyData[$name] = $this->process_data_array($prop);
             $columsToPropsList[$prop->column] = $prop->name;
             $propsToColumsList[$prop->name] = $prop->column;
             $Methods[] = $name;
         }
         // print_r($PropertyData);
         // exit();
         $PropertyDataString = $this->gen_array($PropertyData);
         //$p = new Zend_CodeGenerator_Php_Property_DefaultValue(array('value'=>$PropertyDataString ,'type'=>Zend_CodeGenerator_Php_Property_DefaultValue::TYPE_ARRAY));
         $Prop[] = array('name' => "propertyData", 'visibility' => 'public', 'defaultValue' => $PropertyDataString);
         if (isset($attr->config)) {
             $configDataString = $this->gen_array($attr->config->toArray());
         } else {
             $configDataString = null;
         }
         $Prop[] = array('name' => "CONFIG_FILE_NAME", 'visibility' => 'public', 'const' => true, 'defaultValue' => $configFileName);
         $Prop[] = array('name' => "COLUMS_TO_PROPS_LIST", 'visibility' => 'public', 'defaultValue' => $this->gen_array($columsToPropsList));
         $Prop[] = array('name' => "PROPS_TO_COLUMS_LIST", 'visibility' => 'public', 'defaultValue' => $this->gen_array($propsToColumsList));
         $Prop[] = array('name' => "configData", 'visibility' => 'public', 'defaultValue' => $configDataString);
         $configSQLString = isset($attr->config->sql) ? (string) $attr->config->sql : '';
         $Prop[] = array('name' => "_baseSQL", 'visibility' => 'public', 'defaultValue' => $configSQLString);
         $class->setDocblock($docblock);
         $class->setProperties($Prop);
         /*	
         $Property = new Zend_CodeGenerator_Php_Property();
         $pv = new Zend_CodeGenerator_Php_Property_DefaultValue($PropertyDataString);
         $pv->setType(Zend_CodeGenerator_Php_Property_DefaultValue::TYPE_ARRAY);
             $Property->setDefaultValue($pv);
              $Property->setName('_propertyData');
             
         
         $class->setProperty($Property);
         */
         $method = new Zend_CodeGenerator_Php_Method();
         $method->setName('__construct');
         $method->setBody("parent::__construct ( \$options, '{$modelName}');");
         $method->setParameters(array(array('name' => 'options', 'type' => 'array', 'defaultValue' => null)));
         $class->setMethod($method);
         foreach ($Methods as $name) {
             $method = new Zend_CodeGenerator_Php_Method();
             $method->setName('set' . strtoupper(substr($name, 0, 1)) . substr($name, 1, strlen($name)));
             $method->setBody(" \n  \n\t\t \$this->_{$name} = \${$name};  \n\n\t\treturn \$this; \n ");
             $method->setParameter(array('name' => $name));
             $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => "Set the {$name} property", 'tags' => array(array('name' => 'param', 'description' => "\${$name} the \${$name} to set"), array('name' => 'return', 'description' => $modelName))));
             $method->setDocblock($docblock);
             $class->setMethod($method);
         }
         foreach ($Methods as $name) {
             $method = new Zend_CodeGenerator_Php_Method();
             $method->setName('get' . strtoupper(substr($name, 0, 1)) . substr($name, 1, strlen($name)));
             $method->setBody(" \n  \n\t\treturn  \$this->_{$name}; \n\n\t\t\n\t\t");
             $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => "get the {$name} property", 'tags' => array(array('name' => 'return', 'description' => "the {$name}"))));
             $method->setDocblock($docblock);
             $class->setMethod($method);
         }
         $method = new Zend_CodeGenerator_Php_Method();
         $method->setParameter(array('name' => 'id'));
         $method->setStatic(true);
         $method->setName('getObjectByID');
         $method->setBody("\n           \n            \n \$obj = new {$modelName}();\n\t\t    \n \$obj->find(\$id);\n\t\t    \n return \$obj;\n\t\t    ");
         $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => "get Singleton  {$modelName}", 'tags' => array(array('name' => 'return', 'description' => "{$modelName}"))));
         $method->setDocblock($docblock);
         $class->setMethod($method);
         ////////////Gen Method Form Config/////////////////
         $tostringCreated = false;
         if (isset($attr->method->name)) {
             $this->addMethod($attr->method, $class);
         } else {
             if (is_array($attr->method)) {
                 foreach ($attr->method as $methodConfig) {
                     $this->addMethod($methodConfig, $class);
                 }
             }
         }
         //ถ้ายังไม่มี __tostrint จะ เพิ่มให้ แต่จะ return ค่าว่าง
         if (false == $this->_isTostringCreated()) {
             $method = new Zend_CodeGenerator_Php_Method();
             $method->setName('__toString');
             $method->setBody("\n\n\t\t    \n return '';\n\t\t    ");
             $class->setMethod($method);
         }
         ///////////////////////END GEN METHOD///////////////////////////////
         $file = new Zend_CodeGenerator_Php_File();
         $file->setClass($class);
         $package = ucfirst(strtolower($package));
         //  Acc/Model/
         if (false == $createPackageFolder) {
             $modelPath = str_replace(ucfirst(strtolower($package)) . "_Model_", "", $modelName);
         } else {
             $modelPath = $modelName;
         }
         $modelPath = str_replace("_", "/", $modelPath);
         //$structure = dirname ( __FILE__ )."/{$modelName}";
         echo $destinationFolder . "/" . $modelPath;
         $structure = realpath($destinationFolder) . "/" . $modelPath;
         //"D:\workspaces\privatework\jiranan\private\library/"."/{$modelName}";
         if (!is_dir($structure)) {
             mkdir($structure, 0777, true);
         }
         $filecontent = $this->filecontentfix($file->generate());
         file_put_contents($structure . "/Abstract.php", $filecontent);
         echo "create [ ", $structure, "/Abstract.php ] complete <br/>";
         // $structure2 =  dirname ( __FILE__ )."/".$modelName.".php";
         $structure2 = realpath($destinationFolder) . "/{$modelPath}.php";
         //"D:\workspaces\privatework\jiranan\private\library/".$modelName.".php";
         //	echo file_exists ($structure2 ==true)? 'true' : 'false';
         echo "<br/>";
         if (file_exists($structure2)) {
             print "The file {$structure2} exists<br/>";
         } else {
             print "The file {$structure2} does not exist<br/>";
             echo "<br/>";
             $file2 = new Zend_CodeGenerator_Php_File();
             $file2->setClass($class2);
             //mkdir($structure, 0777, true);
             file_put_contents($structure2, $this->filecontentfix($file2->generate()));
             echo "create [ ", $structure2, " ] complete <br/>";
         }
         echo "===================================================<br/>";
     }
     // Render the generated file
     //echo $file;
 }
예제 #19
0
 function createModel($namespace, $class, $location)
 {
     $columns = $this->getColumnsProperty('COLUMN_NAME', $this->getTableForClass($class));
     $relationships = array();
     $methods = array();
     foreach ($columns as $col_name) {
         if (strstr($col_name, "_id")) {
             $class_name = substr($col_name, 0, -3);
             $table_name = $this->getTableForClass($class_name);
             // Todo: Get a proper pluralisation library
             if ($this->tableExists($table_name)) {
                 $methods[] = new \Zend_CodeGenerator_Php_Method(array('name' => $class_name, 'body' => 'return $this->belongs_to(\'' . ucfirst($class_name) . '\', \'' . $col_name . '\');'));
                 $relationships[] = $class_name;
             }
         }
     }
     $cols = new \Zend_CodeGenerator_Php_Property(array("name" => "columns", "static" => true, "defaultValue" => $this->getColumnsProperty('COLUMN_NAME', $class)));
     $links = new \Zend_CodeGenerator_Php_Property(array("name" => "links", "static" => true, "defaultValue" => $relationships));
     $table_name = new \Zend_CodeGenerator_Php_Property(array("name" => "_table", "static" => true, "defaultValue" => $this->getTableForClass($class)));
     $cls = new \Zend_CodeGenerator_Php_Class(array('name' => ucfirst($class), 'extendedClass' => '\\Model', 'properties' => array($cols, $table_name, $links), 'methods' => $methods));
     file_put_contents($location, "<?php namespace {$namespace};\n" . $cls->generate());
     include $location;
     return $class;
 }
예제 #20
0
파일: File.php 프로젝트: travisj/zf
 /**
  * setClass()
  *
  * @param Zend_CodeGenerator_Php_Class|array $class
  * @return Zend_CodeGenerator_Php_File
  */
 public function setClass($class)
 {
     if (is_array($class)) {
         $class = new Zend_CodeGenerator_Php_Class($class);
         $className = $class->getName();
     } elseif ($class instanceof Zend_CodeGenerator_Php_Class) {
         $className = $class->getName();
     } else {
         require_once 'Zend/CodeGenerator/Php/Exception.php';
         throw new Zend_CodeGenerator_Php_Exception('Expecting either an array or an instance of Zend_CodeGenerator_Php_Class');
     }
     // @todo check for dup here
     $this->_classes[$className] = $class;
     return $this;
 }
예제 #21
0
 function gen($module, $controllerClassName, $label, $extendController, $defaultModel)
 {
     ini_set('display_errors', 1);
     // $xml =  App_Model_Config::getConfigFilePath($package) ;//   APPLICATION_PATH . '/configs/' . $package . '-model-config.xml';
     // $configFileName = basename($xml);
     // $data = $config = new Zend_Config_Xml($xml, 'production');
     // $classList = $data->classes;
     // $project = $data->project;
     //$createPackageFolder = true;
     //$destinationFolder = $data->destinationDirectory;
     if ('application' == $project) {
         $createPackageFolder = false;
         $destinationFolder = APPLICATION_PATH . "/" . $destinationFolder;
     } elseif ('global' == $project) {
         $createPackageFolder = true;
         $destinationFolder = GLOBAL_PROJECT_PATH . "/" . $destinationFolder;
     } else {
         $createPackageFolder = true;
         $destinationFolder = realpath(APPLICATION_PATH . "/../library");
     }
     $class = new Zend_CodeGenerator_Php_Class();
     // $class->setAbstract(true);
     $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => $modelName, 'longDescription' => 'This is a class generated with Zend_CodeGenerator.', 'tags' => array(array('name' => 'uses', 'description' => $extendController), array('name' => 'package', 'description' => $package), array('name' => 'subpackage', 'description' => 'Model'), array('name' => 'version', 'description' => '$Rev:$'), array('name' => 'update', 'description' => date('d/m/Y')), array('name' => 'license', 'description' => 'licensed By Patiwat Wisedsukol patiwat.wi@gmail.com'))));
     //$docblock2 = new Zend_CodeGenerator_Php_Docblock();
     $class->setDocblock($docblock);
     $moduleClassName = ucfirst(preg_replace("/\\-(.)/e", "strtoupper('\\1')", $module));
     $className = "{$moduleClassName}_{$controllerClassName}Controller";
     $class->setName($className);
     if ($extendController != '') {
         $class->setExtendedClass($extendController);
     }
     if (trim($defaultModel) != '') {
         //protected $_model = 'Hrm_Model_Personal';
         $Prop[] = array('name' => "_model", 'visibility' => 'protected', 'defaultValue' => $defaultModel);
         $class->setProperties($Prop);
     }
     $structure = APPLICATION_PATH . "/modules/" . $module . "/controllers/" . $controllerClassName . "Controller.php";
     $tmp = explode("", $destinationFolder);
     //  foreach (){
     // }
     $controllerClassName2 = strtolower(preg_replace('/(?<=\\w)(?=[A-Z])/', "-\$1", $controllerClassName));
     $structureView = APPLICATION_PATH . "/modules/" . $module . "/views/scripts/" . $controllerClassName2;
     if (file_exists($structure)) {
         print "The file {$structure} exists<br/>";
     } else {
         print "The file {$structure} does not exist<br/>";
         echo "<br/>";
         $file = new Zend_CodeGenerator_Php_File();
         $file->setClass($class);
         //mkdir($structure, 0777, true);
         file_put_contents($structure, $this->filecontentfix($file->generate()));
         mkdir($structureView, 0, true);
         $objFopen = fopen($structureView . "/index.phtml", "w");
         fwrite($objFopen, "Index View");
         fclose($objFopen);
         echo "create [ ", $structure, " ] complete <br/>";
     }
 }
예제 #22
0
파일: Action.php 프로젝트: rjack/frapi
    /**
     * Generate the action
     *
     * This is a gigantic method used to generate the actual Action code. It
     * uses the properties, description, name, and routes passed to it.
     *
     * This method uses the Zend_CodeGenerator_Php_* family to identify and create the
     * new files.
     *
     * @param string $name  The name of the action
     * @param array $properties An array of properties related to an action
     * @param string $description A description for an action. Default false.
     * @param string $route The custom route for that action. Default false.
     *
     * @return string A generated file.
     */
    private function generateAction($name, $properties, $description = false, $route = false)
    {
        $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'Required parameters', 'tags' => array(new Zend_CodeGenerator_Php_Docblock_Tag(array('name' => 'var', 'datatype' => 'array', 'description' => 'An array of required parameters.')))));
        $class = new Zend_CodeGenerator_Php_Class();
        $class->setName('Action_' . $name);
        $class->setExtendedClass('Frapi_Action');
        $class->setImplementedInterfaces(array('Frapi_Action_Interface'));
        $tags = array(array('name' => 'link', 'description' => 'http://getfrapi.com'), array('name' => 'author', 'description' => 'Frapi <*****@*****.**>'));
        if ($route !== false) {
            $tags[] = array('name' => 'link', 'description' => $route);
        }
        $classDocblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'Action ' . $name . ' ', 'longDescription' => $description !== false ? $description : 'A class generated by Frapi', 'tags' => $tags));
        $class->setDocblock($classDocblock);
        $class->setProperties(array(array('name' => 'requiredParams', 'visibility' => 'protected', 'defaultValue' => $properties, 'docblock' => $docblock), array('name' => 'data', 'visibility' => 'private', 'defaultValue' => array(), 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'The data container to use in toArray()', 'tags' => array(new Zend_CodeGenerator_Php_Docblock_Tag(array('name' => 'var', 'datatype' => 'array', 'description' => 'A container of data to fill and return in toArray()'))))))));
        $methods = array();
        $docblock = new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'To Array', 'longDescription' => "This method returns the value found in the database \n" . 'into an associative array.', 'tags' => array(new Zend_CodeGenerator_Php_Docblock_Tag_Return(array('datatype' => 'array')))));
        $toArrayBody = '        ' . "\n";
        if (!empty($properties)) {
            foreach ($properties as $p) {
                $toArrayBody .= '$this->data[\'' . $p . '\'] = ' . '$this->getParam(\'' . $p . '\', self::TYPE_OUTPUT);' . "\n";
            }
        }
        $toArrayBody .= 'return $this->data;';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'toArray', 'body' => $toArrayBody, 'docblock' => $docblock));
        $executeActionBody = '';
        if (!empty($properties)) {
            $executeActionBody = '        $valid = $this->hasRequiredParameters($this->requiredParams);
if ($valid instanceof Frapi_Error) {
    return $valid;
}';
        }
        $executeActionBody .= "\n\n" . 'return $this->toArray();';
        $docblockArray = array('shortDescription' => '', 'longDescription' => '', 'tags' => array(new Zend_CodeGenerator_Php_Docblock_Tag_Return(array('datatype' => 'array'))));
        $docblock = new Zend_CodeGenerator_Php_Docblock(array());
        $docblockArray['shortDescription'] = 'Default Call Method';
        $docblockArray['longDescription'] = 'This method is called when no specific ' . 'request handler has been found';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'executeAction', 'body' => $executeActionBody, 'docblock' => $docblockArray));
        $docblockArray['shortDescription'] = 'Get Request Handler';
        $docblockArray['longDescription'] = 'This method is called when a request is a GET';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'executeGet', 'body' => $executeActionBody, 'docblock' => $docblockArray));
        $docblockArray['shortDescription'] = 'Post Request Handler';
        $docblockArray['longDescription'] = 'This method is called when a request is a POST';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'executePost', 'body' => $executeActionBody, 'docblock' => $docblockArray));
        $docblockArray['shortDescription'] = 'Put Request Handler';
        $docblockArray['longDescription'] = 'This method is called when a request is a PUT';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'executePut', 'body' => $executeActionBody, 'docblock' => $docblockArray));
        $docblockArray['shortDescription'] = 'Delete Request Handler';
        $docblockArray['longDescription'] = 'This method is called when a request is a DELETE';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'executeDelete', 'body' => $executeActionBody, 'docblock' => $docblockArray));
        $docblockArray['shortDescription'] = 'Head Request Handler';
        $docblockArray['longDescription'] = 'This method is called when a request is a HEAD';
        $methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'executeHead', 'body' => $executeActionBody, 'docblock' => $docblockArray));
        $class->setMethods($methods);
        $file = new Zend_CodeGenerator_Php_File();
        $file->setClass($class);
        return $file->generate();
    }
예제 #23
0
 /**
  * Create (or modify) given class
  *
  * @param	string							$className
  * @param	Zend_CodeGenerator_Php_Class	$class
  *
  * @return	Zend_CodeGenerator_Php_Class
  */
 public static function create($className, Zend_CodeGenerator_Php_Class $class = null)
 {
     // If no class data is given and the class already exists there's no point in "creating" it
     if ($class == null and XDT_CLI_Helper::classExists($className)) {
         return self::get($className);
     }
     // Only create class if the file is available or we have class data
     $filePath = self::getClassPath($className);
     $fileContents = file_exists($filePath) ? file_get_contents($filePath) : false;
     if (empty($fileContents) or $class != null) {
         // Load blank CodeGenerator file
         $file = new Zend_CodeGenerator_Php_File();
         // Create CodeGenerato Class if it wasn't provided as a parm
         if ($class == null) {
             $class = new Zend_CodeGenerator_Php_Class();
             $class->setName($className);
         }
         // Append class to file
         $file->setClass($class);
         // Write to file
         XDT_CLI_Helper::writeToFile($filePath, $file->generate(), true);
         XDT_CLI_Abstract::getInstance()->printMessage("File: " . $filePath);
     } else {
         XDT_CLI_Abstract::getInstance()->bail("File already exists: " . $filePath);
     }
     return self::get($className);
 }