PHP Класс BaseCCodeModel

Each code generator should have at least one code model class that extends from this class. The purpose of a code model is to represent user-supplied parameters and use them to generate customized code. Derived classes should implement the {@link prepare} method whose main task is to fill up the {@link files} property based on the user parameters. The {@link files} property should be filled with a set of {@link CCodeFile} instances, each representing a single code file to be generated. CCodeModel implements the feature of "sticky attributes". A sticky attribute is an attribute that can remember its last valid value, even if the user closes his browser window and reopen it. To declare an attribute is sticky, simply list it in a validation rule with the validator name being "sticky".
С версии: 1.1.2
Автор: Qiang Xue ([email protected])
Наследование: extends CFormModel
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$answers user confirmations on whether to overwrite existing code files with the newly generated ones. The value of this property is internally managed by this class and {@link CCodeGenerator}.
$files a list of {@link CCodeFile} objects that represent the code files to be generated. The {@link prepare()} method is responsible to populate this property.
$status the status of this model. T The value of this property is internally managed by {@link CCodeGenerator}.
$template the name of the code template that the user has selected. The value of this property is internally managed by this class and {@link CCodeGenerator}.

Открытые методы

Метод Описание
attributeLabels ( ) : array Declares the model attribute labels.
class2id ( string $name ) : string Converts a class name into a HTML ID.
class2name ( string $name, boolean $ucwords = true ) : string Converts a class name into space-separated words.
class2var ( string $name ) : string Converts a class name into a variable name with the first letter in lower case.
classExists ( string $name ) : boolean Checks if the named class exists (in a case sensitive manner).
confirmed ( CCodeFile $file )
errorMessage ( ) : string Returns the message to be displayed when some error occurred during code file saving.
getStickyFile ( ) : string
getTemplatePath ( ) : string
getTemplates ( ) : array Returns a list of available code templates (name=>directory).
loadStickyAttributes ( ) Loads sticky attributes from a file and populates them into the model.
pluralize ( string $name ) : string Converts a word to its plural form.
prepare ( ) Prepares the code files to be generated.
render ( string $templateFile, array $_params_ = null ) : string Generates the code using the specified code template file.
renderResults ( ) : string
requiredTemplates ( ) : array Returns a list of code templates that are required.
rules ( ) : array Declares the model validation rules.
save ( ) Saves the generated code into files.
saveStickyAttributes ( ) Saves sticky attributes into a file.
sticky ( string $attribute, array $params ) The "sticky" validator.
successMessage ( ) : string Returns the message to be displayed when the newly generated code is saved successfully.
validateReservedWord ( string $attribute, array $params ) Validates an attribute to make sure it is not taking a PHP reserved keyword.
validateTemplate ( string $attribute, array $params ) Validates the template selection.

Описание методов

attributeLabels() публичный Метод

Child classes must override this method in the following format:
return array_merge(parent::attributeLabels(), array(
    ...labels for the child class attributes...
));
.
public attributeLabels ( ) : array
Результат array the attribute labels

class2id() публичный Метод

For example, 'PostTag' will be converted as 'post-tag'.
public class2id ( string $name ) : string
$name string the string to be converted
Результат string the resulting ID

class2name() публичный Метод

For example, 'PostTag' will be converted as 'Post Tag'.
public class2name ( string $name, boolean $ucwords = true ) : string
$name string the string to be converted
$ucwords boolean whether to capitalize the first letter in each word
Результат string the resulting words

class2var() публичный Метод

This method is provided because lcfirst() PHP function is only available for PHP 5.3+.
С версии: 1.1.4
public class2var ( string $name ) : string
$name string the class name
Результат string the variable name converted from the class name

classExists() публичный Метод

Checks if the named class exists (in a case sensitive manner).
public classExists ( string $name ) : boolean
$name string class name to be checked
Результат boolean whether the class exists

confirmed() публичный Метод

public confirmed ( CCodeFile $file )
$file CCodeFile whether the code file should be saved

errorMessage() публичный Метод

Child classes should override this method if the message needs to be customized.
public errorMessage ( ) : string
Результат string the message to be displayed when some error occurred during code file saving.

getStickyFile() публичный Метод

public getStickyFile ( ) : string
Результат string the file path that stores the sticky attribute values.

getTemplatePath() публичный Метод

public getTemplatePath ( ) : string
Результат string the directory that contains the template files.

getTemplates() публичный Метод

This method simply returns the {@link CCodeGenerator::templates} property value.
public getTemplates ( ) : array
Результат array a list of available code templates (name=>directory).

loadStickyAttributes() публичный Метод

Loads sticky attributes from a file and populates them into the model.

pluralize() публичный Метод

Note that this is for English only! For example, 'apple' will become 'apples', and 'child' will become 'children'.
public pluralize ( string $name ) : string
$name string the word to be pluralized
Результат string the pluralized word

prepare() абстрактный публичный Метод

This is the main method that child classes should implement. It should contain the logic that populates the {@link files} property with a list of code files to be generated.
abstract public prepare ( )

render() публичный Метод

This method is manly used in {@link generate} to generate code.
public render ( string $templateFile, array $_params_ = null ) : string
$templateFile string the code template file path
$_params_ array a set of parameters to be extracted and made available in the code template
Результат string the generated code

renderResults() публичный Метод

public renderResults ( ) : string
Результат string the code generation result log.

requiredTemplates() публичный Метод

Derived classes usually should override this method.
public requiredTemplates ( ) : array
Результат array list of code templates that are required. They should be file paths relative to {@link templatePath}.

rules() публичный Метод

Child classes must override this method in the following format:
return array_merge(parent::rules(), array(
    ...rules for the child class...
));
.
public rules ( ) : array
Результат array validation rules

save() публичный Метод

Saves the generated code into files.
public save ( )

saveStickyAttributes() публичный Метод

Saves sticky attributes into a file.

sticky() публичный Метод

This validator does not really validate the attributes. It actually saves the attribute value in a file to make it sticky.
public sticky ( string $attribute, array $params )
$attribute string the attribute to be validated
$params array the validation parameters

successMessage() публичный Метод

Child classes should override this method if the message needs to be customized.
public successMessage ( ) : string
Результат string the message to be displayed when the newly generated code is saved successfully.

validateReservedWord() публичный Метод

Validates an attribute to make sure it is not taking a PHP reserved keyword.
public validateReservedWord ( string $attribute, array $params )
$attribute string the attribute to be validated
$params array validation parameters

validateTemplate() публичный Метод

This method validates whether the user selects an existing template and the template contains all required template files as specified in {@link requiredTemplates}.
public validateTemplate ( string $attribute, array $params )
$attribute string the attribute to be validated
$params array validation parameters

Описание свойств

$answers публичное свойство

user confirmations on whether to overwrite existing code files with the newly generated ones. The value of this property is internally managed by this class and {@link CCodeGenerator}.
public $answers

$files публичное свойство

a list of {@link CCodeFile} objects that represent the code files to be generated. The {@link prepare()} method is responsible to populate this property.
public $files

$status публичное свойство

the status of this model. T The value of this property is internally managed by {@link CCodeGenerator}.
public $status

$template публичное свойство

the name of the code template that the user has selected. The value of this property is internally managed by this class and {@link CCodeGenerator}.
public $template