本文整理匯總了PHP中Zend\Code\Generator\MethodGenerator::addFlag方法的典型用法代碼示例。如果您正苦於以下問題:PHP MethodGenerator::addFlag方法的具體用法?PHP MethodGenerator::addFlag怎麽用?PHP MethodGenerator::addFlag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\MethodGenerator
的用法示例。
在下文中一共展示了MethodGenerator::addFlag方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addSelectWithMethod
/**
* Add a selectWith() method if table has an external dependency
*
* @return MethodGenerator
*/
protected function addSelectWithMethod()
{
$foreignKeys = $this->loadedTables[$this->tableName]['foreignKeys'];
if (empty($foreignKeys)) {
return true;
}
$body = [];
/** @var ConstraintObject $foreignKey */
foreach ($foreignKeys as $foreignKey) {
$refTableName = $foreignKey->getReferencedTableName();
$refTableColumns = $this->loadedTables[$refTableName]['columns'];
$body[] = '$select->join(';
$body[] = ' \'' . $refTableName . '\',';
$body[] = ' \'' . $this->tableName . '.' . $foreignKey->getColumns()[0] . ' = ' . $refTableName . '.' . $foreignKey->getReferencedColumns()[0] . '\',';
$body[] = ' [';
/** @var ColumnObject $column */
foreach ($refTableColumns as $column) {
$body[] = ' \'' . $refTableName . '.' . $column->getName() . '\' => \'' . $column->getName() . '\',';
}
$body[] = ' ]';
$body[] = ');';
$body[] = '';
}
$body[] = 'return parent::selectWith($select);';
$body = implode(AbstractGenerator::LINE_FEED, $body);
$this->addUse('Zend\\Db\\ResultSet\\ResultSetInterface');
$this->addUse('Zend\\Db\\Sql\\Select');
$selectMethod = new MethodGenerator('selectWith');
$selectMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
$selectMethod->setParameter(new ParameterGenerator('select', 'Select'));
$selectMethod->setDocBlock(new DocBlockGenerator('Add join tables', null, [['name' => 'param', 'description' => 'Select $select'], ['name' => 'return', 'description' => 'ResultSetInterface']]));
$selectMethod->setBody($body);
$this->addMethodFromGenerator($selectMethod);
return true;
}
示例2: addGetOptionsMethod
/**
* Add a getOptions() method if table has an external dependency
*
* @param $moduleName
*
* @return MethodGenerator
*/
protected function addGetOptionsMethod($moduleName)
{
$entityClass = $this->filterUnderscoreToCamelCase($this->tableName) . 'Entity';
/** @var ConstraintObject $primaryKey */
$primaryKey = $this->loadedTables[$this->tableName]['primaryKey'];
$body = [];
$body[] = '$options = [];';
$body[] = '';
$body[] = '/** @var ' . $entityClass . ' $entity */';
$body[] = 'foreach ($this->fetchAllEntities() as $entity) {';
$body[] = ' $columns = [';
foreach ($this->loadedTables[$this->tableName]['columns'] as $columnName => $columnType) {
if (in_array($columnName, $primaryKey->getColumns())) {
continue;
}
$getMethod = 'get' . ucfirst($this->filterUnderscoreToCamelCase($columnName));
$body[] = ' $entity->' . $getMethod . '(),';
}
$body[] = ' ];';
$body[] = '';
$body[] = ' $options[$entity->getIdentifier()] = implode(\' \', $columns);';
$body[] = '}';
$body[] = '';
$body[] = 'return $options;';
$body = implode(AbstractGenerator::LINE_FEED, $body);
$this->addUse($moduleName . '\\' . $this->config['namespaceEntity'] . '\\' . $entityClass);
$selectMethod = new MethodGenerator('getOptions');
$selectMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
$selectMethod->setDocBlock(new DocBlockGenerator('Get option list', null, [['name' => 'return', 'description' => 'array']]));
$selectMethod->setBody($body);
$this->addMethodFromGenerator($selectMethod);
return true;
}
示例3: addOptionsSetter
/**
* @param string $columnName
* @param ConstraintObject $foreignKey
*/
protected function addOptionsSetter($columnName, ConstraintObject $foreignKey)
{
$body = '$this->' . $columnName . 'Options = $' . $columnName . 'Options;';
$parameter = new ParameterGenerator($columnName . 'Options', 'array');
$setMethodName = 'set' . ucfirst($columnName) . 'Options';
$setMethod = new MethodGenerator($setMethodName);
$setMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
$setMethod->setParameter($parameter);
$setMethod->setDocBlock(new DocBlockGenerator('Set ' . $columnName . ' options', null, [['name' => 'param', 'description' => 'array $' . $columnName . 'Options']]));
$setMethod->setBody($body);
$this->addMethodFromGenerator($setMethod);
}
示例4: generateNormalToStringMethod
/**
* @return MethodGenerator
*/
protected function generateNormalToStringMethod()
{
$body = ['return $this->__toString();'];
$body = implode(AbstractGenerator::LINE_FEED, $body);
$toStringMethod = new MethodGenerator('toString');
$toStringMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
$toStringMethod->setDocBlock(new DocBlockGenerator('Output entity', null, [['name' => 'return', 'description' => 'string']]));
$toStringMethod->setBody($body);
return $toStringMethod;
}
示例5: addSelectWithMethod
/**
* Add a selectWith() method if table has an external dependency
*
* @return MethodGenerator
*/
protected function addSelectWithMethod()
{
/** @var TableObject $currentTable */
$currentTable = $this->tableObjects[$this->tableName];
$foreignKeys = array();
/** @var $tableConstraint ConstraintObject */
foreach ($currentTable->getConstraints() as $tableConstraint) {
if (!$tableConstraint->isForeignKey()) {
continue;
}
$foreignKeys[] = $tableConstraint;
}
if (empty($foreignKeys)) {
return true;
}
$body = array();
/** @var ConstraintObject $foreignKey */
foreach ($foreignKeys as $foreignKey) {
$refTableName = $foreignKey->getReferencedTableName();
/** @var TableObject $refTableObject */
$refTableObject = $this->tableObjects[$refTableName];
$body[] = '$select->join(';
$body[] = ' \'' . $refTableName . '\',';
$body[] = ' \'' . $this->tableName . '.' . $foreignKey->getColumns()[0] . ' = ' . $refTableName . '.' . $foreignKey->getReferencedColumns()[0] . '\',';
$body[] = ' array(';
/** @var ColumnObject $column */
foreach ($refTableObject->getColumns() as $column) {
$body[] = ' \'' . $refTableName . '.' . $column->getName() . '\' => \'' . $column->getName() . '\',';
}
$body[] = ' )';
$body[] = ');';
$body[] = '';
}
$body[] = 'return parent::selectWith($select);';
$body = implode(AbstractGenerator::LINE_FEED, $body);
$this->addUse('Zend\\Db\\ResultSet\\ResultSetInterface');
$this->addUse('Zend\\Db\\Sql\\Select');
$selectMethod = new MethodGenerator('selectWith');
$selectMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
$selectMethod->setParameter(new ParameterGenerator('select', 'Select'));
$selectMethod->setDocBlock(new DocBlockGenerator('Add join tables', null, array(array('name' => 'param', 'description' => 'Select $select'), array('name' => 'return', 'description' => 'ResultSetInterface'))));
$selectMethod->setBody($body);
$this->addMethodFromGenerator($selectMethod);
return true;
}
示例6: addDeleteControllerAction
/**
* Add indexAction() method for DeleteController
*
* @param $repositoryClass
* @param $formClass
*/
protected function addDeleteControllerAction($repositoryClass, $formClass)
{
// prepare some params
$formParam = lcfirst($formClass);
$underscoredParam = strtolower(StaticFilter::execute(str_replace('Entity', '', $this->entityClass), 'WordCamelCaseToUnderscore'));
$dashedParam = strtolower(StaticFilter::execute($this->paramModule, 'WordCamelCaseToDash'));
$dashedModule = strtolower(StaticFilter::execute($this->paramModule, 'WordCamelCaseToUnderscore'));
$noFoundMessage = $dashedModule . '_message_' . $underscoredParam . '_not_found';
$deleteMessage = $dashedModule . '_message_' . $underscoredParam . '_deleting_possible';
$successMessage = $dashedModule . '_message_' . $underscoredParam . '_deleting_success';
$failedMessage = $dashedModule . '_message_' . $underscoredParam . '_deleting_failed';
// prepare entity params
$entityParam = lcfirst($this->entityClass);
$body = ['$id = $this->params()->fromRoute(\'id\');', '', 'if (!$id) {', ' $this->flashMessenger()->addErrorMessage(\'' . $noFoundMessage . '\');', ' ', ' return $this->redirect()->toRoute(\'' . $dashedParam . '\');', '}', '', '$' . $entityParam . ' = $this->' . lcfirst($repositoryClass) . '->getEntityById($id);', '', 'if (!$' . $entityParam . ') {', ' $this->flashMessenger()->addErrorMessage(\'' . $noFoundMessage . '\');', ' ', ' return $this->redirect()->toRoute(\'' . $dashedParam . '\');', '}', '', '$' . $formParam . ' = $this->' . $formParam . ';', '', 'if ($this->params()->fromPost(\'delete_' . $underscoredParam . '\')) {', ' if ($this->' . lcfirst($repositoryClass) . '->removeEntity($' . $entityParam . ')) {', ' $this->flashMessenger()->addSuccessMessage(\'' . $successMessage . '\');', ' ', ' return $this->redirect()->toRoute(\'' . $dashedParam . '\');', ' } else {', ' $this->flashMessenger()->addErrorMessage(\'' . $failedMessage . '\');', ' }', '} else {', ' $this->flashMessenger()->addInfoMessage(\'' . $deleteMessage . '\');', '}', '', '$viewModel = new ViewModel(', ' [', ' \'' . $entityParam . '\' => $' . $entityParam . ',', ' \'' . $formParam . '\' => $' . $formParam . ',', ' ]', ');', '', 'return $viewModel;'];
$body = implode(AbstractGenerator::LINE_FEED, $body);
$indexAction = new MethodGenerator('indexAction');
$indexAction->addFlag(MethodGenerator::FLAG_PUBLIC);
$indexAction->setDocBlock(new DocBlockGenerator('Index action for DeleteController', null, [new ReturnTag(['ViewModel'])]));
$indexAction->setBody($body);
$this->addMethodFromGenerator($indexAction);
}
示例7: generateConstructor
/**
* generates propertiy, getter, setter and other methods...
*
* @param \Zend\Code\Generator\ClassGenerator $class
* @param \VisioCrudModeler\Descriptor\Db\DbDataSetDescriptor $dataSet
*/
protected function generateConstructor(ClassGenerator $class, \VisioCrudModeler\Descriptor\AbstractDataSetDescriptor $dataSet)
{
$constructor = new MethodGenerator("__construct");
$constructor->addFlag(MethodGenerator::FLAG_PUBLIC);
$methodBody = $this->codeLibrary()->get("filter.constructor.body.begin");
foreach ($dataSet->listGenerator() as $column) {
$methodBody .= $this->generateFilterForColumn($column);
}
$constructor->setBody($methodBody);
$class->addMethodFromGenerator($constructor);
}
示例8: generateGetMethod
/**
* @param $columnName
* @param $columnType
*
* @return MethodGenerator
*/
protected function generateGetMethod($columnName, $columnType)
{
$getMethodName = 'get' . ucfirst($columnName);
$getMethod = new MethodGenerator($getMethodName);
$getMethod->addFlag(MethodGenerator::FLAG_PUBLIC);
$getMethod->setDocBlock(new DocBlockGenerator('Get ' . $columnName, null, array(array('name' => 'return', 'description' => $columnType))));
$getMethod->setBody('return $this->' . $columnName . ';');
return $getMethod;
}