本文整理汇总了PHP中Zend_CodeGenerator_Php_Class::setMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_CodeGenerator_Php_Class::setMethod方法的具体用法?PHP Zend_CodeGenerator_Php_Class::setMethod怎么用?PHP Zend_CodeGenerator_Php_Class::setMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_CodeGenerator_Php_Class
的用法示例。
在下文中一共展示了Zend_CodeGenerator_Php_Class::setMethod方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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;
}
示例2: testHasMethod
/**
* @group ZF-7361
*/
public function testHasMethod()
{
$method = new Zend_CodeGenerator_Php_Method();
$method->setName('methodOne');
$codeGenClass = new Zend_CodeGenerator_Php_Class();
$codeGenClass->setMethod($method);
$this->assertTrue($codeGenClass->hasMethod('methodOne'));
}
示例3: array
$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 = "";
$data_validation_string = "";
$error_view_variables = "";
$view_variables = "";
foreach ($columns as $colname => $column) {
if ($colname != $identity_col) {
$error_view_variables .= "\t\t\$" . "this->view->" . $colname . " = \$request->" . $colname . ";\n";
$data_array_string .= "\t\t\t\t\"" . $colname . "\" => \$request->" . $colname . ",\n";
}
$view_variables .= "\t\t\$" . "this->view->" . $colname . " = \$" . $row_object_var . "->" . $colname . ";\n";
if (in_array($colname, $required)) {
$data_validation_string .= "\t\$request->addValidator(\"" . $colname . "\");\n";
示例4: 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;
}
示例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}"))));
//.........这里部分代码省略.........
示例6: 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;
}