当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_CodeGenerator_Php_Class::generate方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: testToString

    public function testToString()
    {
        $codeGenClass = new Zend_CodeGenerator_Php_Class(array('abstract' => true, 'name' => 'SampleClass', 'extendedClass' => 'ExtendedClassName', 'implementedInterfaces' => array('Iterator', 'Traversable'), 'properties' => array(array('name' => 'foo'), array('name' => 'bar')), 'methods' => array(array('name' => 'baz'))));
        $expectedOutput = <<<EOS
abstract class SampleClass extends ExtendedClassName implements Iterator, Traversable
{

    public \$foo = null;

    public \$bar = null;

    public function baz()
    {
    }


}

EOS;
        $output = $codeGenClass->generate();
        $this->assertEquals($expectedOutput, $output, $output);
    }
开发者ID:vicfryzel,项目名称:zf,代码行数:22,代码来源:ClassTest.php

示例7: 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

示例8: 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

示例9: 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


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