• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Zend_CodeGenerator_Php_Class类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Zend_CodeGenerator_Php_Class的典型用法代码示例。如果您正苦于以下问题:PHP Zend_CodeGenerator_Php_Class类的具体用法?PHP Zend_CodeGenerator_Php_Class怎么用?PHP Zend_CodeGenerator_Php_Class使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Zend_CodeGenerator_Php_Class类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * 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));
     }
 }
开发者ID:NixFifty,项目名称:XenForo-XDT,代码行数:32,代码来源:Listener.php


示例2: getContents

 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();
 }
开发者ID:uglide,项目名称:zfcore-transition,代码行数:14,代码来源:MigrationFile.php


示例3: addSuccess

 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());
     }
 }
开发者ID:Konstnantin,项目名称:zf-app,代码行数:15,代码来源:ResourcesController.php


示例4: _getForm

 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;
 }
开发者ID:nuxwin,项目名称:losolib,代码行数:9,代码来源:Form.php


示例5: generate

 /**
  * Генерирует класс модели
  * @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());
 }
开发者ID:Konstnantin,项目名称:zf-app,代码行数:34,代码来源:Generator.php


示例6: insertControl

 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;
 }
开发者ID:s-kalaus,项目名称:zkernel,代码行数:43,代码来源:Generator.php


示例7: generateFile

 /**
  * 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();
     }
 }
开发者ID:Marcosdbras,项目名称:zend-form-generator,代码行数:48,代码来源:Creator.php


示例8: die

            }
        }
        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 = "";
开发者ID:jaybill,项目名称:Bolts,代码行数:31,代码来源:crudify.php


示例9: getContents

 /**
  * 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();
 }
开发者ID:bizanto,项目名称:Hooked,代码行数:20,代码来源:ProjectProviderFile.php


示例10: create

 /**
  * 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;
 }
开发者ID:uglide,项目名称:zfcore-transition,代码行数:54,代码来源:Manager.php


示例11: testAction

    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();

    }
开发者ID:reith2004,项目名称:frapi,代码行数:42,代码来源:ActionController.php


示例12: testAllowsClassConstantToHaveSameNameAsClassProperty

    /**
     * @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());
    }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:25,代码来源:ClassTest.php


示例13: create_action

    /**
     *
     * @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());
        }
    }
开发者ID:BGCX262,项目名称:zupal-svn-to-git,代码行数:96,代码来源:MVC.php


示例14: table_file

 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;
 }
开发者ID:BGCX262,项目名称:zupal-svn-to-git,代码行数:16,代码来源:CodeGenerator.php


示例15: testSetextendedclassShouldNotIgnoreNonEmptyClassnameOnGenerate

    /**
     * @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());
    }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:17,代码来源:ClassTest.php


示例16: testClassFromReflectionDiscardParentImplementedInterfaces

 /**
  * @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);
 }
开发者ID:vicfryzel,项目名称:zf,代码行数:16,代码来源:ClassTest.php


示例17: insertControl

    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;
    }
开发者ID:s-kalaus,项目名称:zkernel,代码行数:96,代码来源:Generatormodel.php


示例18: gen

 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 [email protected]'))));
         //$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}"))));
//.........这里部分代码省略.........
开发者ID:hugi2002,项目名称:mylibrary,代码行数:101,代码来源:GenModel.php


示例19: createModel

 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;
 }
开发者ID:NeonPaul,项目名称:abode,代码行数:24,代码来源:ModelManager.php


示例20: setClass

 /**
  * 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;
 }
开发者ID:travisj,项目名称:zf,代码行数:21,代码来源:File.php



注:本文中的Zend_CodeGenerator_Php_Class类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Zend_CodeGenerator_Php_Docblock类代码示例发布时间:2022-05-23
下一篇:
PHP Zend_CodeGenerator_Php_Abstract类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap