CCodeFile
包 | system.gii |
---|---|
继承 | class CCodeFile » CComponent |
可用自 | 1.1.2 |
源码 | framework/gii/CCodeFile.php |
CCodeFile represents a code file being generated.
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
content | mixed | the newly generated code. | CCodeFile |
error | string | the error occurred when saving the code into a file | CCodeFile |
operation | string | the operation to be performed | CCodeFile |
path | string | the file path that the new code should be saved to. | CCodeFile |
relativePath | string | the code file path relative to the application base path. | CCodeFile |
type | string | the code file extension (e.g. php, txt) | CCodeFile |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CCodeFile |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getRelativePath() | Returns the code file path relative to the application base path. | CCodeFile |
getType() | Returns the code file extension (e.g. php, txt) | CCodeFile |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
raiseEvent() | Raises an event. | CComponent |
save() | Saves the code into the file path. | CCodeFile |
属性详情
content
属性
public mixed $content;
the newly generated code. If this is null, it means path should be treated as a directory.
error
属性
public string $error;
the error occurred when saving the code into a file
operation
属性
public string $operation;
the operation to be performed
path
属性
public string $path;
the file path that the new code should be saved to.
relativePath
属性
只读
public string getRelativePath()
the code file path relative to the application base path.
type
属性
只读
public string getType()
the code file extension (e.g. php, txt)
方法详情
__construct()
方法
public void __construct(string $path, string $content)
| ||
$path | string | the file path that the new code should be saved to. |
$content | string | the newly generated code |
源码: framework/gii/CCodeFile.php#50 (显示)
public function __construct($path,$content)
{
$this->path=strtr($path,array('/'=>DIRECTORY_SEPARATOR,'\\'=>DIRECTORY_SEPARATOR));
$this->content=$content;
if(is_file($path))
$this->operation=file_get_contents($path)===$content ? self::OP_SKIP : self::OP_OVERWRITE;
elseif($content===null) // is dir
$this->operation=is_dir($path) ? self::OP_SKIP : self::OP_NEW;
else
$this->operation=self::OP_NEW;
}
Constructor.
getRelativePath()
方法
public string getRelativePath()
| ||
{return} | string | the code file path relative to the application base path. |
源码: framework/gii/CCodeFile.php#116 (显示)
public function getRelativePath()
{
if(strpos($this->path,Yii::app()->basePath)===0)
return substr($this->path,strlen(Yii::app()->basePath)+1);
else
return $this->path;
}
getType()
方法
public string getType()
| ||
{return} | string | the code file extension (e.g. php, txt) |
源码: framework/gii/CCodeFile.php#127 (显示)
public function getType()
{
if(($pos=strrpos($this->path,'.'))!==false)
return substr($this->path,$pos+1);
else
return 'unknown';
}
save()
方法
public void save()
|
源码: framework/gii/CCodeFile.php#65 (显示)
public function save()
{
$module=Yii::app()->controller->module;
if($this->content===null) // a directory
{
if(!is_dir($this->path))
{
$oldmask=@umask(0);
$result=@mkdir($this->path,$module->newDirMode,true);
@umask($oldmask);
if(!$result)
{
$this->error="Unable to create the directory '{$this->path}'.";
return false;
}
}
return true;
}
if($this->operation===self::OP_NEW)
{
$dir=dirname($this->path);
if(!is_dir($dir))
{
$oldmask=@umask(0);
$result=@mkdir($dir,$module->newDirMode,true);
@umask($oldmask);
if(!$result)
{
$this->error="Unable to create the directory '$dir'.";
return false;
}
}
}
if(@file_put_contents($this->path,$this->content)===false)
{
$this->error="Unable to write the file '{$this->path}'.";
return false;
}
else
{
$oldmask=@umask(0);
@chmod($this->path,$module->newFileMode);
@umask($oldmask);
}
return true;
}
Saves the code into the file path.