本文整理汇总了PHP中Zend_CodeGenerator_Php_File类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_CodeGenerator_Php_File类的具体用法?PHP Zend_CodeGenerator_Php_File怎么用?PHP Zend_CodeGenerator_Php_File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_CodeGenerator_Php_File类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getContents
/**
* Creates contets for this model
*
* @see Zend_Tool_Project_Context_Filesystem_File::getContents()
*/
public function getContents()
{
$className = ucfirst($this->_modelName);
$tableName = $this->camelCaseToUnderscore($this->_modelName);
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'App_Model', 'properties' => array(new Zend_CodeGenerator_Php_Property(array('name' => '_primary', 'visibility' => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED, 'defaultValue' => 'id')), new Zend_CodeGenerator_Php_Property(array('name' => '_name', 'visibility' => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED, 'defaultValue' => $tableName)), new Zend_CodeGenerator_Php_Property(array('name' => '_rowClass', 'visibility' => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED, 'defaultValue' => 'App_Table_' . $className))))))));
return $codeGenFile->generate();
}
开发者ID:omusico,项目名称:logica,代码行数:12,代码来源:ZfsModelFile.php
示例2: scaffold
public function scaffold()
{
$form = $this->_getForm();
$file = new Zend_CodeGenerator_Php_File();
$file->setClass($form);
return $file->generate();
}
开发者ID:nuxwin,项目名称:losolib,代码行数:7,代码来源:Form.php
示例3: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$codeGenerator = new Zend_CodeGenerator_Php_File(array('body' => <<<EOS
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
\$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
\$application->bootstrap()
->run();
EOS
));
return $codeGenerator->generate();
}
开发者ID:hjr3,项目名称:zf2,代码行数:36,代码来源:PublicIndexFile.php
示例4: getContents
/**
* Creates contets for this form
*
* @see Zend_Tool_Project_Context_Filesystem_File::getContents()
*/
public function getContents()
{
$className = ucfirst($this->_formName);
$moduleName = ucfirst($this->_moduleName);
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'App_' . $moduleName . '_Form', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'init', 'body' => 'parent::init();', 'visibility' => Zend_CodeGenerator_Php_Method::VISIBILITY_PUBLIC))))))));
return $codeGenFile->generate();
}
开发者ID:omusico,项目名称:logica,代码行数:12,代码来源:ZfsFormFile.php
示例5: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$filter = new Zend_Filter_Word_DashToCamelCase();
$className = $filter->filter($this->_forControllerName) . 'ControllerTest';
$codeGenFile = new Zend_CodeGenerator_Php_File(array('requiredFiles' => array('PHPUnit/Framework/TestCase.php'), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'PHPUnit_Framework_TestCase', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'setUp', 'body' => ' /* Setup Routine */')), new Zend_CodeGenerator_Php_Method(array('name' => 'tearDown', 'body' => ' /* Tear Down Routine */'))))))));
return $codeGenFile->generate();
}
开发者ID:travisj,项目名称:zf,代码行数:12,代码来源:TestApplicationControllerFile.php
示例6: getContents
/**
* Generates the content of the model file
*
* @return string
*/
public function getContents()
{
$className = $this->getFullClassName($this->_modelName, 'Model');
$properties = count($this->_fields) ? $this->getProperties($this->_fields) : array();
$methods = count($this->_fields) ? $this->getMethods($this->_fields, $this->_modelName) : array();
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'properties' => $properties, 'methods' => $methods)))));
return $codeGenFile->generate();
}
开发者ID:phpspec,项目名称:phpspec-zend,代码行数:13,代码来源:ModelFile.php
示例7: generate
/**
* Generate class
* @return string generated source code
*/
public function generate()
{
$table = new ModelGenerator_Table_Table($this->_options['tableName']);
$className = $this->_getNamer()->formatClassName($this->_config->classname);
$baseModelClassName = $this->_getNamer()->formatClassName($this->_config->base->classname);
$templates = array('tags' => array());
foreach ($this->_options['docblock'] as $tag => $value) {
$templates['tags'][] = array('name' => $tag, 'description' => $value);
}
$mapperTable = new Zend_CodeGenerator_Php_Class(array('name' => $className, 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => $className . PHP_EOL . 'Put your custom methods in this file.', 'tags' => array_merge($templates['tags']))), 'extendedClass' => $baseModelClassName));
$mapperTableFile = new Zend_CodeGenerator_Php_File(array('classes' => array($mapperTable)));
return $mapperTableFile->generate();
}
开发者ID:redpmorg,项目名称:Zend-Model-Generator,代码行数:17,代码来源:Model.php
示例8: registerFileCodeGenerator
public static function registerFileCodeGenerator(Zend_CodeGenerator_Php_File $fileCodeGenerator, $fileName = null)
{
if ($fileName == null) {
$fileName = $fileCodeGenerator->getFilename();
}
if ($fileName == '') {
throw new Zend_CodeGenerator_Php_Exception('FileName does not exist.');
}
// cannot use realpath since the file might not exist, but we do need to have the index
// in the same DIRECTORY_SEPARATOR that realpath would use:
$fileName = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $fileName);
self::$_fileCodeGenerators[$fileName] = $fileCodeGenerator;
}
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:13,代码来源:File.php
示例9: 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
示例10: generate
/**
* Generate class
* @return string generated source code
*/
public function generate()
{
$table = new ModelGenerator_Table_Table($this->_options['tableName']);
$className = $this->_getNamer()->formatClassName($this->_config->baseMapper->classname);
$templates = array('tags' => array());
foreach ($this->_options['docblock'] as $tag => $value) {
$templates['tags'][] = array('name' => $tag, 'description' => $value);
}
$methods = array();
$tableReferences = array();
foreach ($table->getUniqueKeys() as $key) {
$methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'findBy' . $this->_getNamer()->formatMethodName($key), 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(new Zend_CodeGenerator_Php_Docblock_Tag_Param(array('paramName' => $key, 'dataType' => 'mixed')), array('name' => 'return', 'description' => $this->_getNamer()->formatClassName($this->_config->classname))))), 'parameters' => array(array('name' => $key)), 'body' => 'return $this->findOne(array(\'' . $key . ' = ?\' => $' . $key . '));'));
}
$modelTableBase = new Zend_CodeGenerator_Php_Class(array('name' => $className, 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => $className . PHP_EOL . '*DO NOT* edit this file.', 'tags' => array_merge($templates['tags']))), 'extendedClass' => 'Zend_Db_Table_Abstract', 'properties' => array(array('name' => '_name', 'visiblity' => 'protected', 'defaultValue' => $table->getName()), array('name' => '_primary', 'visiblity' => 'protected', 'defaultValue' => $table->getPrimary()), array('name' => '_dependantTables', 'visiblity' => 'protected', 'defaultValue' => $table->getDependantTables())), 'methods' => $methods));
$modelTableBaseFile = new Zend_CodeGenerator_Php_File(array('classes' => array($modelTableBase)));
return $modelTableBaseFile->generate();
}
开发者ID:redpmorg,项目名称:Zend-Model-Generator,代码行数:21,代码来源:BaseMapper.php
示例11: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$profile = $this->_resource->getProfile();
$vendor = $profile->getAttribute('vendor');
$name = $profile->getAttribute('name');
$className = sprintf($this->getClassPath(), $vendor, $name, ucfirst($this->_className));
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => $this->getExtends(), 'methods' => array())))));
// store the generator into the registry so that the addAction command can use the same object later
Zend_CodeGenerator_Php_File::registerFileCodeGenerator($codeGenFile);
// REQUIRES filename to be set
return $codeGenFile->generate();
}
开发者ID:CEMD-CN,项目名称:MageTool,代码行数:17,代码来源:AbstractFile.php
示例12: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$codeGenerator = new Zend_CodeGenerator_Php_File(array('body' => <<<EOS
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
Zend_Loader_Autoloader::getInstance();
EOS
));
return $codeGenerator->generate();
}
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:28,代码来源:TestPHPUnitBootstrapFile.php
示例13: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$filter = new Zend_Filter_Word_DashToCamelCase();
$moduleName = ucfirst($this->_moduleName);
$className = ucfirst($this->_controllerName) . 'Controller';
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'App_' . $moduleName . '_Controller', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'init', 'body' => '/* Initialize action controller here */'))))))));
if ($className == 'ErrorController') {
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'App_' . $moduleName . '_Controller', 'properties' => array(new Zend_CodeGenerator_Php_Property(array('name' => '_dispatch404s', 'visibility' => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED, 'defaultValue' => array(Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE, Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER, Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION)))), 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'init', 'body' => <<<EOS
parent::init();
\$this->_helper->layout()->setLayout('layout');
EOS
)), new Zend_CodeGenerator_Php_Method(array('name' => 'errorAction', 'body' => <<<EOS
\$errorInfo = \$this->_getParam('error_handler');
if (in_array(\$errorInfo->type, \$this->_dispatch404s)) {
\t\$this->_dispatch404();
\treturn;
}
\$this->getResponse()->setRawHeader('HTTP/1.1 500 Internal Server Error');
\$this->title = 'Internal Server Error';
\$this->view->exception = \$errorInfo->exception;
EOS
)), new Zend_CodeGenerator_Php_Method(array('name' => 'flagflippersAction', 'body' => <<<EOS
if (Zend_Registry::get('IS_DEVELOPMENT')) {
\t\$this->title = 'Flag and Flipper not found';
\t\$this->view->originalController = \$this->_getParam('originalController');
\t\$this->view->originalAction = \$this->_getParam('originalAction');
} else {
\t\$this->_dispatch404();
}
EOS
)), new Zend_CodeGenerator_Php_Method(array('name' => 'forbiddenAction', 'body' => '$this->title = \'Forbidden\';')), new Zend_CodeGenerator_Php_Method(array('name' => '_dispatch404', 'visibility' => Zend_CodeGenerator_Php_Method::VISIBILITY_PROTECTED, 'body' => <<<EOS
\$this->title = 'Page not found';
\$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
\$this->render('error-404');
EOS
))))))));
}
// store the generator into the registry so that the addAction command can use the same object later
Zend_CodeGenerator_Php_File::registerFileCodeGenerator($codeGenFile);
// REQUIRES filename to be set
return $codeGenFile->generate();
}
开发者ID:omusico,项目名称:logica,代码行数:54,代码来源:ZfsControllerFile.php
示例14: indexAction
public function indexAction()
{
$this->_helper->layout()->title = 'PHP Persistent Class Generator';
$form = new Form_ClassGenerator_Class();
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$formToClass = Model_ClassGenerator_FormToClass::createInstance($formData);
$class = $formToClass->toClass();
$file = new Zend_CodeGenerator_Php_File();
if ($formData['class'][Model_ClassGenerator_FormToClass::$withPersistenceKey]) {
$persistence = Model_ClassGenerator_Persistence::createInstance($class);
$persistentClass = $persistence->createPersistence();
$file->setClass($persistentClass);
} else {
$file->setClass($class);
}
$this->view->resultCode = htmlentities($file->generate());
} else {
$form->populate($formData);
}
}
$this->view->form = $form;
}
开发者ID:JPustkuchen,项目名称:phppcg,代码行数:24,代码来源:IndexController.php
示例15: getContents
public function getContents()
{
$className = $this->getFullClassName($this->_dbTableName, 'Model_DbTable');
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Db_Table_Abstract', 'properties' => array(new Zend_CodeGenerator_Php_Property(array('name' => '_name', 'visibility' => Zend_CodeGenerator_Php_Property::VISIBILITY_PROTECTED, 'defaultValue' => $this->_actualTableName))))))));
return $codeGenFile->generate();
}
开发者ID:bizanto,项目名称:Hooked,代码行数:6,代码来源:DbTableFile.php
示例16: testNewMethodKeepTwoDocBlock
/**
* @group ZF-11703
*/
public function testNewMethodKeepTwoDocBlock()
{
$codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName(dirname(__FILE__) . '/_files/zf-11703_1.php', true, true);
$target = <<<EOS
<?php
/**
* For manipulating files.
*/
/**
* Class Foo1
*/
class Foo1
{
public function bar()
{
// action body
}
public function bar2()
{
// action body
}
}
EOS;
$codeGenFile->getClass()->setMethod(array('name' => 'bar2', 'body' => '// action body'));
$this->assertEquals($target, $codeGenFile->generate());
}
开发者ID:crodriguezn,项目名称:crossfit-milagro,代码行数:37,代码来源:FileTest.php
示例17: generate
/**
* Generate class
* @return string generated source code
*/
public function generate()
{
$table = new ModelGenerator_Table_Table($this->_options['tableName']);
$className = $this->_getNamer()->formatClassName($this->_config->base->classname);
$templates = array('tags' => array());
foreach ($this->_options['docblock'] as $tag => $value) {
$templates['tags'][] = array('name' => $tag, 'description' => $value);
}
////////////////////////////////////////////
// create model base
////////////////////////////////////////////
$methods = array();
$properties = array();
$tmp = array();
foreach ($table->getProperties() as $property) {
$tmp[] = array('name' => 'property', 'description' => $property['type'] . ' $' . $property['name'] . ' ' . $property['desc']);
switch ($property['type']) {
case 'string':
$property['defaultValue'] = '';
break;
case 'int':
case 'float':
case 'double':
$property['defaultValue'] = null;
break;
default:
$property['defaultValue'] = '';
break;
}
$properties[] = new Zend_CodeGenerator_Php_Property(array('name' => '_' . $property['name'], 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'var', 'description' => $property['type'])))), 'defaultValue' => $property['defaultValue'], 'visibility' => 'private'));
// getters and setters
if (false !== strpos($property['desc'], 'enum')) {
$types = rtrim(str_replace(array('enum('), '', $property['desc']), ')');
$types = explode(',', $types);
$typesImploded = implode(', ', $types);
$enumBody = 'in_array($' . $property['name'] . ', array(' . $typesImploded . ')) ? $' . $property['name'] . ' : ' . $types[0];
$body = '$' . $property['name'] . ' = (' . $property['type'] . ') $' . $property['name'] . ';' . PHP_EOL . '$this->_' . $property['name'] . ' = ' . $enumBody . ';' . PHP_EOL . 'return $this;';
} else {
$body = '$this->_' . $property['name'] . ' = (' . $property['type'] . ') $' . $property['name'] . ';' . PHP_EOL . 'return $this;';
}
$methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'set' . $this->_getNamer()->formatMethodName($property['name']), 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'Set ' . $property['name'] . ' (' . $property['desc'] . ')', 'tags' => array(new Zend_CodeGenerator_Php_Docblock_Tag_Param(array('paramName' => $property['name'], 'dataType' => $property['type'])), array('name' => 'return', 'description' => $className)))), 'parameters' => array(array('name' => $property['name'])), 'body' => $body));
$methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'get' . $this->_getNamer()->formatMethodName($property['name']), 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'Get ' . $property['name'] . ' (' . $property['desc'] . ')', 'tags' => array(array('name' => 'return', 'description' => $property['type'])))), 'parameters' => array(), 'body' => 'return $this->_' . $property['name'] . ';'));
}
$toArrayBody[] = '$data = array(';
foreach ($table->getProperties() as $property) {
$toArrayBody[] = "\t" . '\'' . $property['name'] . '\' => $this->_' . $property['name'] . ',';
}
$toArrayBody[] = ');';
$toArrayBody[] = '';
$toArrayBody[] = 'return $data;';
$methods[] = new Zend_CodeGenerator_Php_Method(array('name' => 'toArray', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => 'Convert entity properties to array and return it', 'tags' => array(array('name' => 'return', 'description' => 'array')))), 'parameters' => array(), 'body' => implode(PHP_EOL, $toArrayBody)));
$modelBase = new Zend_CodeGenerator_Php_Class(array('name' => $className, 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('shortDescription' => $className . PHP_EOL . '*DO NOT* edit this file.', 'tags' => array_merge($tmp, $templates['tags']))), 'methods' => $methods, 'properties' => $properties));
$modelBaseFile = new Zend_CodeGenerator_Php_File(array('classes' => array($modelBase)));
return $modelBaseFile->generate();
}
开发者ID:redpmorg,项目名称:Zend-Model-Generator,代码行数:59,代码来源:BaseModel.php
示例18: getContents
/**
* getContents()
*
* @return array
*/
public function getContents()
{
$codeGenFile = new Zend_CodeGenerator_Php_File(array('classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => 'Bootstrap', 'extendedClass' => 'Zend_Application_Bootstrap_Bootstrap')))));
return $codeGenFile->generate();
}
开发者ID:c12g,项目名称:stratos-php,代码行数:10,代码来源:BootstrapFile.php
示例19: getContents
/**
* getContents()
*
* @return string
*/
public function getContents()
{
$filter = new Zend_Filter_Word_DashToCamelCase();
$className = $filter->filter($this->_forControllerName) . 'ControllerTest';
/* @var $controllerDirectoryResource Zend_Tool_Project_Profile_Resource */
$controllerDirectoryResource = $this->_resource->getParentResource();
if ($controllerDirectoryResource->getParentResource()->getName() == 'TestApplicationModuleDirectory') {
$className = $filter->filter(ucfirst($controllerDirectoryResource->getParentResource()->getForModuleName())) . '_' . $className;
}
$codeGenFile = new Zend_CodeGenerator_Php_File(array('classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $className, 'extendedClass' => 'Zend_Test_PHPUnit_ControllerTestCase', 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'setUp', 'body' => <<<EOS
\$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
parent::setUp();
EOS
))))))));
return $codeGenFile->generate();
}
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:21,代码来源:TestApplicationControllerFile.php
示例20: getContents
/**
* @return string
*/
public function getContents()
{
$classMapperName = $this->getFullClassName($this->_modelName, 'Model_Mapper');
$className = $this->getFullClassName($this->_modelName, 'Model');
$classDbTableName = $this->getFullClassName($this->_modelName, 'Model_DbTable');
$codeGenFile = new Zend_CodeGenerator_Php_File(array('fileName' => $this->getPath(), 'classes' => array(new Zend_CodeGenerator_Php_Class(array('name' => $classMapperName, 'properties' => array(array('name' => '_dbTable', 'visibility' => 'protected')), 'methods' => array(new Zend_CodeGenerator_Php_Method(array('name' => 'setDbTable', 'parameters' => array(array('name' => 'dbTable')), 'body' => 'if (is_string($dbTable))' . "\n\t" . '$dbTable = new $dbTable();' . "\n\n" . 'if (!$dbTable instanceof Zend_Db_Table_Abstract)' . "\n\t" . 'throw new Exception(\'Invalid table data gateway provided\');' . "\n\n" . '$this->_dbTable = $dbTable;' . "\n\n" . 'return $this;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => '$dbTable'), array('name' => 'return', 'description' => '$this'), array('name' => 'throws', 'description' => 'Exception')))))), new Zend_CodeGenerator_Php_Method(array('name' => 'getDbTable', 'body' => 'if (null === $this->_dbTable)' . "\n\t" . '$this->setDbTable(\'' . $classDbTableName . '\');' . "\n\n" . 'return $this->_dbTable;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'return', 'description' => $classDbTableName)))))), new Zend_CodeGenerator_Php_Method(array('name' => 'save', 'parameters' => array(array('name' => strtolower($this->_modelName), 'type' => $className)), 'body' => '$data = $this->_getDbData($' . strtolower($this->_modelName) . ');' . "\n\n" . 'if (null == ($id = $' . strtolower($this->_modelName) . '->getId())) {' . "\n\t" . 'unset($data[$this->_getDbPrimary()]);' . "\n\t" . '$this->getDbTable()->insert($data);' . "\n" . '} else {' . "\n\t" . '$this->getDbTable()->update($data, array($this->_getDbPrimary(). \' = ?\' => $id));' . "\n" . '}' . "\n\n" . 'return $this;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => $className . ' $' . strtolower($this->_modelName)), array('name' => 'return', 'description' => '$this')))))), new Zend_CodeGenerator_Php_Method(array('name' => 'find', 'parameters' => array(array('name' => 'id'), array('name' => strtolower($this->_modelName), 'type' => $className)), 'body' => '$result = $this->getDbTable()->find($id);' . "\n\n" . 'if (0 == count($result)) {' . "\n\t" . 'return null;' . "\n" . '}' . "\n\n" . '$row = $result->current();' . "\n" . '$entry = $this->_setDbData($row, $' . strtolower($this->_modelName) . ');' . "\n\n" . 'return $entry;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => '$id'), array('name' => 'param', 'description' => $className . ' $' . strtolower($this->_modelName)), array('name' => 'return', 'description' => $className . '|null')))))), new Zend_CodeGenerator_Php_Method(array('name' => 'fetchAll', 'parameters' => array(array('name' => 'select', 'defaultValue' => null)), 'body' => '$resultSet = $this->getDbTable()->fetchAll($select);' . "\n\n" . '$entries = array();' . "\n" . 'foreach ($resultSet as $row) {' . "\n\t" . '$entry = new ' . $className . '();' . "\n\t" . '$entry = $this->_setDbData($row, $entry);' . "\n\t" . '$entries[] = $entry;' . "\n" . '}' . "\n\n" . 'return $entries;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => 'null $select'), array('name' => 'return', 'description' => 'array')))))), new Zend_CodeGenerator_Php_Method(array('name' => '_getDbPrimary', 'visibility' => 'protected', 'body' => '$primaryKey = $this->getDbTable()->info(\'primary\');' . "\n\n" . 'return $primaryKey[1];', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'return', 'description' => 'mixed')))))), new Zend_CodeGenerator_Php_Method(array('name' => '_getDbData', 'parameters' => array(array('name' => strtolower($this->_modelName), 'type' => $className)), 'visibility' => 'protected', 'body' => '$info = $this->getDbTable()->info();' . "\n" . '$properties = $info[\'cols\'];' . "\n\n" . '$data = array();' . "\n" . 'foreach ($properties as $property) {' . "\n\t" . '$name = $this->_normaliseName($property);' . "\n\n\t" . 'if($property != $this->_getDbPrimary())' . "\n\t\t" . '$data[$property] = $' . strtolower($this->_modelName) . '->__get($name);' . "\n" . '}' . "\n\n" . 'return $data;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => $className . ' $' . strtolower($this->_modelName)), array('name' => 'return', 'description' => 'array')))))), new Zend_CodeGenerator_Php_Method(array('name' => '_setDbData', 'parameters' => array(array('name' => 'row'), array('name' => 'entry', 'type' => $className)), 'visibility' => 'protected', 'body' => '$info = $this->getDbTable()->info();' . "\n" . '$properties = $info[\'cols\'];' . "\n\n" . 'foreach ($properties as $property) {' . "\n\t" . '$entry->__set($this->_normaliseName($property), $row->$property);' . "\n" . '}' . "\n\n" . 'return $entry;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => 'Zend_Db_Table_Rowset $row'), array('name' => 'param', 'description' => $className . ' $entry'), array('name' => 'return', 'description' => $className)))))), new Zend_CodeGenerator_Php_Method(array('name' => '_normaliseName', 'parameters' => array(array('name' => 'property')), 'visibility' => 'protected', 'body' => '$name = preg_split(\'~_~\', $property);' . "\n" . '$normaliseName = implode(array_map(\'ucwords\', $name));' . "\n\n" . 'return $normaliseName;', 'docblock' => new Zend_CodeGenerator_Php_Docblock(array('tags' => array(array('name' => 'param', 'description' => '$property string'), array('name' => 'return', 'description' => 'string'))))))))))));
return $codeGenFile->generate();
}
开发者ID:vladmeh,项目名称:zftool,代码行数:11,代码来源:ModelMapperFile.php
注:本文中的Zend_CodeGenerator_Php_File类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论