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


PHP Zend_CodeGenerator_Php_Class::setProperties方法代码示例

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


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

示例1: testPropertyAccessors

 public function testPropertyAccessors()
 {
     $codeGenClass = new Zend_CodeGenerator_Php_Class();
     $codeGenClass->setProperties(array(array('name' => 'propOne'), new Zend_CodeGenerator_Php_Property(array('name' => 'propTwo'))));
     $properties = $codeGenClass->getProperties();
     $this->assertEquals(count($properties), 2);
     $this->isInstanceOf(current($properties), 'Zend_CodeGenerator_Php_Property');
     $property = $codeGenClass->getProperty('propTwo');
     $this->isInstanceOf($property, 'Zend_CodeGenerator_Php_Property');
     $this->assertEquals($property->getName(), 'propTwo');
     // add a new property
     $codeGenClass->setProperty(array('name' => 'prop3'));
     $this->assertEquals(count($codeGenClass->getProperties()), 3);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:14,代码来源:ClassTest.php

示例2: generateAction

    /**
     * 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 <frapi@getfrapi.com>'));
        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();
    }
开发者ID:rjack,项目名称:frapi,代码行数:73,代码来源:Action.php

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

示例4: gen

 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/>";
     }
 }
开发者ID:hugi2002,项目名称:mylibrary,代码行数:58,代码来源:GenController.php

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


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