My FIU Curriculum Class Reference. Yii Framework

# DocsCommand

Package | system.build
Inheritance | class DocsCommand » CConsoleCommand » CComponent
Since | 1.0
Version | $Id: ApiCommand.php 2942 2011-02-08 11:42:22Z mdomba $
Source Code |

## Public Properties

Hide inherited properties

Property | Type | Description | Defined By
--- | --- | --- | ---
appOptions |  |  | DocsCommand
baseSourceUrl |  |  | DocsCommand
classes |  |  | DocsCommand
commandRunner | CConsoleCommandRunner | the command runner instance | CConsoleCommand
currentClass |  |  | DocsCommand
currentView |  |  | DocsCommand
defaultAction | string | the name of the default action. | CConsoleCommand
enableViews |  |  | DocsCommand
frameworkSourceUrl |  |  | DocsCommand
help |  |  | DocsCommand
name | string | the command name. | CConsoleCommand
optionHelp | array | Provides the command option help information. | CConsoleCommand
packages |  |  | DocsCommand
pageTitle |  |  | DocsCommand
themePath |  |  | DocsCommand
version |  |  | DocsCommand
views |  |  | DocsCommand
yiiOptions |  |  | DocsCommand

## Public Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
__call() | Calls the named method which is not a class method. | CComponent
__construct() | Constructor. | CConsoleCommand
__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
behaviors() | Returns a list of behaviors that this command should behave as. | CConsoleCommand
buildFileList() | Builds the file list of a directory. | CConsoleCommand
canGetProperty() | Determines whether a property can be read. | CComponent
canSetProperty() | Determines whether a property can be set. | CComponent
confirm() | Asks user to confirm by typing y or n. | CConsoleCommand
copyFiles() | Copies a list of files from one place to another. | CConsoleCommand
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
ensureDirectory() | Creates all parent directories if they do not exist. | CConsoleCommand
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent
fixMethodAnchor() |  | DocsCommand
getCommandRunner() | Returns the command runner instance | CConsoleCommand
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent
getHelp() |  | DocsCommand
getName() | Returns the command name. | CConsoleCommand
getOptionHelp() | Provides the command option help information. | CConsoleCommand
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
highlight() |  | DocsCommand
init() | Initializes the command object. | CConsoleCommand
onAfterAction() | This event is raised after an action finishes execution. | CConsoleCommand
onBeforeAction() | This event is raised before an action is to be executed. | CConsoleCommand
pluralize() | Converts a word to its plural form. | CConsoleCommand
prompt() | Reads input via the readline PHP extension if that's available, or fgets() if readline is not installed. | CConsoleCommand
raiseEvent() | Raises an event. | CComponent
render() |  | DocsCommand
renderFile() | Renders a view file. | CConsoleCommand
renderImplements() |  | DocsCommand
renderInheritance() |  | DocsCommand
renderPartial() |  | DocsCommand
renderPropertySignature() |  | DocsCommand
renderSourceLink() |  | DocsCommand
renderSubclasses() |  | DocsCommand
renderSubjectUrl() |  | DocsCommand
renderTypeUrl() |  | DocsCommand
renderViews() |  | DocsCommand
run() | Execute the action. | DocsCommand
usageError() | Displays a usage error. | CConsoleCommand

## Protected Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
afterAction() | This method is invoked right after an action finishes execution. | CConsoleCommand
beforeAction() | This method is invoked right before an action is to be executed. | CConsoleCommand
buildKeywords() |  | DocsCommand
buildModel() |  | DocsCommand
buildOfflinePages() |  | DocsCommand
buildOnlinePages() |  | DocsCommand
buildPackages() |  | DocsCommand
fixOfflineLink() |  | DocsCommand
fixOnlineLink() |  | DocsCommand
resolveRequest() | Parses the command line arguments and determines which action to perform. | CConsoleCommand

## Events

Hide inherited events

Event | Description | Defined By
--- | --- | ---
onBeforeAction | This event is raised before an action is to be executed. | CConsoleCommand
onAfterAction | This event is raised after an action finishes execution. | CConsoleCommand

## Property Details

appOptions property
public $appOptions;

baseSourceUrl property
public $baseSourceUrl;

classes property
public $classes;

currentClass property
public $currentClass;

currentView property
public $currentView;

enableViews property
public $enableViews;

frameworkSourceUrl property
public $frameworkSourceUrl;

help property read-only
public void getHelp()

packages property
public $packages;

pageTitle property
public $pageTitle;

themePath property
public $themePath;

version property
public $version;

views property
public $views;

yiiOptions property
public $yiiOptions;

## Method Details

buildKeywords() method

protected void buildKeywords($docPath)
$docPath |  |

Source Code: (show)
`protected function buildKeywords($docPath)
{
$keywords=array();
foreach($this->classes as $class)
$keywords[]=$class->name;
foreach($this->classes as $class)
{
$name=$class->name;
foreach($class->properties as $property)
{
if(!$property->isInherited)
$keywords[]=$name.'.'.$property->name;
}
foreach($class->methods as $method)
{
if(!$method->isInherited)
$keywords[]=$name.'.'.$method->name.'()';
}
}
file_put_contents($docPath.'/api/keywords.txt',implode(',',$keywords));
}`

buildModel() method

protected void buildModel($sourcePath)
$sourcePath |  |

Source Code: (show)
`protected function buildModel($sourcePath)
{
$files=CFileHelper::findFiles($sourcePath,$this->appOptions);
foreach(CFileHelper::findFiles(YII_PATH,$this->yiiOptions) as $file) {
$files[] = $file;
}
if ($this->enableViews) {
$viewFiles = CFileHelper::findFiles($sourcePath."/views", array('fileTypes'=>array('php')));
}
else {
$viewFiles = array();
}
$model=new DocsModel;
$model->build($files, $viewFiles);
return $model;
}`

buildOfflinePages() method

protected void buildOfflinePages($docPath, $themePath)
$docPath |  |
$themePath |  |

Source Code: (show)
`protected function buildOfflinePages($docPath,$themePath)
{
$this->themePath=$themePath;
@mkdir($docPath);
$content=$this->render('index',null,true);
$content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
file_put_contents($docPath.'/index.html',$content);
foreach($this->classes as $name=>$class)
{
$this->currentClass=$name;
$this->pageTitle=$name;
$content=$this->render('class',array('class'=>$class),true);
$content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
file_put_contents($docPath.'/'.$name.'.html',$content);
}
if ($this->enableViews) {
foreach($this->views as $path=>$view)
{
$this->currentView=$path;
$this->pageTitle=$view->name;
$content=$this->render('view',array('view'=>$view),true);
$content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOfflineLink'),$content);
file_put_contents($docPath.'/'.$view->package.".".$view->name.'.html',$content);
}
}
CFileHelper::copyDirectory($this->themePath.'/assets',$docPath,array('exclude'=>array('.svn')));
$content=$this->renderPartial('chmProject',null,true);
file_put_contents($docPath.'/manual.hhp',$content);
$content=$this->renderPartial('chmIndex',null,true);
file_put_contents($docPath.'/manual.hhk',$content);
$content=$this->renderPartial('chmContents',null,true);
file_put_contents($docPath.'/manual.hhc',$content);
}`

buildOnlinePages() method

protected void buildOnlinePages($docPath, $themePath)
$docPath |  |
$themePath |  |

Source Code: (show)
`protected function buildOnlinePages($docPath,$themePath)
{
$this->themePath=$themePath;
@mkdir($docPath);
$content=$this->renderPartial('index',null,true);
$content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOnlineLink'),$content);
file_put_contents($docPath.'/index.html',$content);
foreach($this->classes as $name=>$class)
{
$this->currentClass=$name;
$this->pageTitle=$name;
$content=$this->renderPartial('class',array('class'=>$class),true);
$content=preg_replace_callback(self::URL_PATTERN,array($this,'fixOnlineLink'),$content);
file_put_contents($docPath.'/'.$name.'.html',$content);
}
}`

buildPackages() method

protected void buildPackages($docPath)
$docPath |  |

Source Code: (show)
`protected function buildPackages($docPath)
{
file_put_contents($docPath.'/api/packages.txt',serialize($this->packages));
}`

fixMethodAnchor() method

public void fixMethodAnchor($class, $name)
$class |  |
$name |  |

Source Code: (show)
`public function fixMethodAnchor($class,$name)
{
if(isset($this->classes[$class]->properties[$name]))
return $name."()";
else
return $name;
}`

fixOfflineLink() method

protected void fixOfflineLink($matches)
$matches |  |

Source Code: (show)
`protected function fixOfflineLink($matches)
{
if(($pos=strpos($matches[1],'::'))!==false)
{
$className=substr($matches[1],0,$pos);
$method=substr($matches[1],$pos+2);
return "<a href=\"{$className}.html#{$method}\">{$matches[2]}</a>";
}
else
return "<a href=\"{$matches[1]}.html\">{$matches[2]}</a>";
}`

fixOnlineLink() method

protected void fixOnlineLink($matches)
$matches |  |

Source Code: (show)
`protected function fixOnlineLink($matches)
{
if(($pos=strpos($matches[1],'::'))!==false)
{
$className=substr($matches[1],0,$pos);
$method=substr($matches[1],$pos+2);
if($className==='index')
return "<a href=\"/doc/api/#{$method}\">{$matches[2]}</a>";
else
return "<a href=\"/doc/api/{$className}#{$method}\">{$matches[2]}</a>";
}
else
{
if($matches[1]==='index')
return "<a href=\"/doc/api/\">{$matches[2]}</a>";
else
return "<a href=\"/doc/api/{$matches[1]}\">{$matches[2]}</a>";
}
}`

getHelp() method

public void getHelp()

Source Code: (show)
`public function getHelp()
{
return <<<EOD
USAGE
yiic docs <output-path> [mode]
yiic docs check
DESCRIPTION
This command generates offline API documentation for the Yii framework.
PARAMETERS
* output-path: required, the directory where the generated documentation would be saved.
* mode: optional, either 'online' or 'offline' (default).
Indicates whether the generated documentation are for online or offline use.
* check: check PHPDoc for proper @param syntax
EXAMPLES
* yiic docs yii/doc - builds api documentation in folder yii/doc
* yiic docs yii/doc noviews - disables documentation of views
* yiic docs check - cheks PHPDoc @param directives
EOD;
}`

highlight() method

public void highlight($code, $limit=20)
$code |  |
$limit |  |

Source Code: (show)
`public function highlight($code,$limit=20)
{
$code=preg_replace("/^ /m",'',rtrim(str_replace("\t"," ",$code)));
$code=highlight_string("<?php\n".$code,true);
return preg_replace('/&lt;\\?php<br \\/>/','',$code,1);
}`

render() method

public void render($view, $data=NULL, $return=false, $layout='main')
$view |  |
$data |  |
$return |  |
$layout |  |

Source Code: (show)
`public function render($view,$data=null,$return=false,$layout='main')
{
$viewFile=$this->themePath."/views/{$view}.php";
$layoutFile=$this->themePath."/layouts/{$layout}.php";
$content=$this->renderFile($viewFile,$data,true);
return $this->renderFile($layoutFile,array('content'=>$content),$return);
}`

renderImplements() method

public void renderImplements($class)
$class |  |

Source Code: (show)
`public function renderImplements($class)
{
$interfaces=array();
foreach($class->interfaces as $interface)
{
if(isset($this->classes[$interface]))
$interfaces[]='.$interface.'.html">'.$interface.'';
else
$interfaces[]=$interface;
}
return implode(', ',$interfaces);
}`

renderInheritance() method

public void renderInheritance($class)
$class |  |

Source Code: (show)
`public function renderInheritance($class)
{
$parents=array($class->signature);
foreach($class->parentClasses as $parent)
{
if(isset($this->classes[$parent]))
$parents[]='.$parent.'.html">'.$parent.'';
else
$parents[]=$parent;
}
return implode(" &raquo;\n",$parents);
}`

renderPartial() method

public void renderPartial($view, $data=NULL, $return=false)
$view |  |
$data |  |
$return |  |

Source Code: (show)
`public function renderPartial($view,$data=null,$return=false)
{
$viewFile=$this->themePath."/views/{$view}.php";
return $this->renderFile($viewFile,$data,$return);
}`

renderPropertySignature() method

public void renderPropertySignature($property)
$property |  |

Source Code: (show)
`public function renderPropertySignature($property)
{
if(!empty($property->signature))
return $property->signature;
$sig='';
if(!empty($property->getter))
$sig=$property->getter->signature;
if(!empty($property->setter))
{
if($sig!=='')
$sig.='<br/>';
$sig.=$property->setter->signature;
}
return $sig;
}`

renderSourceLink() method

public void renderSourceLink($sourcePath, $line=NULL)
$sourcePath |  |
$line |  |

Source Code: (show)
`public function renderSourceLink($sourcePath,$line=null)
{
if (file_exists(BUILD_PATH.$sourcePath)) {
if ($this->baseSourceUrl === false) {
if($line===null)
return 'app'.$sourcePath;
else
return 'app'.$sourcePath.'#'.$line;
}
else {
if($line===null)
return CHtml::link('app'.$sourcePath,$this->baseSourceUrl.$sourcePath,array('class'=>'sourceLink'));
else
return CHtml::link('app'.$sourcePath.'#'.$line, $this->baseSourceUrl.$sourcePath.'#'.$line,array('class'=>'sourceLink'));
}
}
else {
if($line===null)
return CHtml::link('framework'.$sourcePath,$this->frameworkSourceUrl.$sourcePath,array('class'=>'sourceLink'));
else
return CHtml::link('framework'.$sourcePath.'#'.$line, $this->frameworkSourceUrl.$sourcePath.'#'.$line,array('class'=>'sourceLink'));
}
}`

renderSubclasses() method

public void renderSubclasses($class)
$class |  |

Source Code: (show)
`public function renderSubclasses($class)
{
$subclasses=array();
foreach($class->subclasses as $subclass)
{
if(isset($this->classes[$subclass]))
$subclasses[]='.$subclass.'.html">'.$subclass.'';
else
$subclasses[]=$subclass;
}
return implode(', ',$subclasses);
}`

renderSubjectUrl() method

public void renderSubjectUrl($type, $subject, $text=NULL)
$type |  |
$subject |  |
$text |  |

Source Code: (show)
`public function renderSubjectUrl($type,$subject,$text=null)
{
if($text===null)
$text=$subject;
if(isset($this->classes[$type]) || isset($this->views[$type])) {
return '.$type.'.html#'.$subject.'-detail'.'">'.$text.'';
}
else
return $text;
}`

renderTypeUrl() method

public void renderTypeUrl($type)
$type |  |

Source Code: (show)
`public function renderTypeUrl($type)
{
if (stristr($type,"[]")) {
$type = substr($type,0,-2);
if(isset($this->classes[$type]) && $type!==$this->currentClass)
return '.$type.'.html">'.$type.'[]';
else
return $type."[]";
}
if(isset($this->classes[$type]) && $type!==$this->currentClass)
return '.$type.'.html">'.$type.'';
else
return $type;
}`

renderViews() method

public void renderViews($class)
$class |  |

Source Code: (show)
`public function renderViews($class)
{
$views=array();
foreach($class->views as $view)
{
if(isset($this->views[$view]))
$views[]='.$view.'.html">'.array_pop(explode(".",$view)).'';
else
$views[]=$view;
}
return implode(', ',$views);
}`

run() method

public void run(array $args)
$args | array | command line parameters specific for this command

Source Code: (show)
`public function run($args)
{
$this->appOptions=array(
'fileTypes'=>array('php'),
'exclude'=>array(
'.svn',
'/yiic.php',
'/commands/docs',
'/commands/DocsCommand',
'/messages',
'/vendors',
'/extensions',
'views',
'/vendors',
'/config',
'/tests',
'/controllers/ManageController',
),
);
$this->yiiOptions=array(
'fileTypes'=>array('php'),
'exclude'=>array(
'.svn',
'/yiilite.php',
'/yiit.php',
'/cli',
'/i18n/data',
'/messages',
'/vendors',
'/views',
'/web/js',
'/web/widgets/views',
'/utils/mimeTypes.php',
'/gii/assets',
'/gii/components',
'/gii/controllers',
'/gii/generators',
'/gii/models',
'/gii/views',
'/test',
),
);
if(!isset($args[0]))
$this->usageError('the output directory is not specified.');
if($args[0]=='check') {
$checkFiles = CFileHelper::findFiles(BUILD_PATH,$this->appOptions);
$model=new DocsModel;
$model->check($checkFiles);
exit();
}
if(!is_dir($docPath=$args[0]))
$this->usageError("the output directory {$docPath} does not exist.");
if (isset($args[1]) && $args[1] == "noviews") {
$this->enableViews = false;
}
/*$offline=true;
if(isset($args[1]) && $args[1]==='online')
$offline=false;
*/
$this->version=Yii::getVersion();
/*
* development version - link to trunk
* release version link to tags
*/
if(substr($this->version,-3)=='dev')
$this->frameworkSourceUrl .= '/trunk/framework';
else
$this->frameworkSourceUrl .= '/tags/'.$this->version.'/framework';
$this->pageTitle=Yii::app()->name.' Class Reference';
$themePath=dirname(__FILE__).'/docs';
echo "\nBuilding.. : " . $this->pageTitle."\n";
echo "Version... : " . $this->version."\n";
echo "Source URL : " . $this->baseSourceUrl."\n\n";
echo "Building model...\n";
$model=$this->buildModel(BUILD_PATH);
$this->classes=$model->classes;
$this->packages=$model->packages;
$this->views = $model->views;
echo "Building pages...\n";
$this->buildOfflinePages($docPath.DIRECTORY_SEPARATOR.'api',$themePath);
$this->buildKeywords($docPath);
$this->buildPackages($docPath);
echo "Done.\n\n";
}`

Execute the action.

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.