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
파일 보기 프로젝트 열기: openeyes/openeyes 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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