Package | system.gii |
---|---|
Inheritance | class CCodeFile » CComponent |
Since | 1.1.2 |
Source Code | framework/gii/CCodeFile.php |
Property | Type | Description | Defined By |
---|---|---|---|
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 |
Method | Description | Defined By |
---|---|---|
__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 |
the newly generated code. If this is null, it means path should be treated as a directory.
the error occurred when saving the code into a file
the operation to be performed
the file path that the new code should be saved to.
the code file path relative to the application base path.
the code file extension (e.g. php, txt)
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 |
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.
public string getRelativePath()
| ||
{return} | string | the code file path relative to the application base path. |
public function getRelativePath()
{
if(strpos($this->path,Yii::app()->basePath)===0)
return substr($this->path,strlen(Yii::app()->basePath)+1);
else
return $this->path;
}
public string getType()
| ||
{return} | string | the code file extension (e.g. php, txt) |
public function getType()
{
if(($pos=strrpos($this->path,'.'))!==false)
return substr($this->path,$pos+1);
else
return 'unknown';
}
public void save()
|
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.
Signup or Login in order to comment.