1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
<?php
/**
* Handles the "setup".
*
* This class provides all methods neccessary to "setup" Phpdoc and check the
* current setup.
*
* @version 0.2alpha
* @author Ulf Wendel <ulf@redsys.de>
*/
class PhpdocSetupHandler extends PhpdocArgvHandler {
/**
* Name of the target directory.
* @var string $target
* @access private
*/
var $target = "";
/**
* Name of the application parsed
* @var string $application
* @see setApplication()
*/
var $application = "PHPDoc";
/**
* Basedir for all file operations
* @var string $basedir
* @see setApplication(), setBasedir()
*/
var $basedir = "";
/**
* Suffix of all source code files in the application
* If you used other file suffixes than ".php" in you have to override this
* variable using setSourceFileSuffix()
* @var array sourceFileSuffix
* @see setSourceFileSuffix()
*/
var $sourceFileSuffix = array ( "php" );
/**
* Directory with the php sources to parse.
* @var string
* @see setSourceDir()
*/
var $sourceDirectory = "";
/**
* Directory with the templates.
* @var string
* @see setTemplateDirectory()
*/
/**
* Sets the name of the directory with the source to scan.
* @param string
* @access public
*/
function setSourceDirectory($sourcedir) {
$this->sourceDirectory = $this->getCheckedDirname($sourcedir);
} // end end func setSourceDirectory
/**
* Sets the name of the directory with the templates.
* @param string
* @access public
*/
function setTemplateDirectory($sourcedir) {
$this->templateRoot = $this->getCheckedDirname($sourcedir);
} // end func setTemplateDirectory
/**
* Sets the name of your application.
*
* The application name gets used on many places in the default templates.
*
* @param string $application name of the application
* @return bool $ok
* @throws PhpdocError
* @access public
*/
function setApplication($application) {
if (""==$application) {
$this->err[] = new PhpdocError("No application name given.", __FILE__, __LINE__);
return false;
}
$this->application = $application;
return true;
} // end func setApplication
/**
* Suffix of all source code files in the application
* By default only files with the suffix ".php" are recognized as
* php source code files and parsed. If you used other
* suffixes such as ".inc" you have to tell phpdoc to parse
* them.
*
* @param mixed $suffix string with one suffix or array of suffixes
* @return bool $ok
* @throws PhpdocError
* @access private
* @see sourceFileSuffix
*/
function setSourceFileSuffix($suffix) {
if ( (!is_array($suffix) && ""==$suffix) || (is_array($suffix) && 0==count($suffix)) ) {
$this->err[] = new PhpdocError("No suffix specified.", __FILE__, __LINE__);
return false;
}
if (!is_array($suffix))
$suffix = array($suffix);
$this->sourceFileSuffix = $suffix;
return true;
} // end func setSourceFileSuffix
/**
* Sets the target where the generated files are saved.
*
* @param string $target
* @return bool $ok
* @throws PhpdocError
* @access public
*/
function setTarget($target) {
if (""==$target) {
$this->err[] = new PhpdocError("No target specified.", __FILE__, __LINE__);
return false;
}
if (!is_dir($target)) {
$ok = @mkdir($target, 0755);
if (!$ok) {
$this->err[] = new PhpdocError("setTarget(), can't create a directory '$target'.", __FILE__, __LINE__);
return false;
}
}
$this->target = $this->getCheckedDirname($target);
return true;
} // end func setTarget
/**
* Checks the current status of the object. Are all necessary informations
* to start parsing available?
* @param array $errors
* @access private
* @return array $errors
*/
function checkStatus($errors="") {
if (!is_array($errors))
$errors = array();
/*
if (0==count($this->files) && ""==$this->directory)
$errors[] = array (
"msg" => "No source files or source directory specified.",
"type" => "misconfiguration",
"errno" => 6
);
if (0!=count($this->files) && ""!=$this->directory)
$errors[] = array(
"msg" => "Define eighter some files or a diretory.",
"type" => "misconfiguration",
"errno" => 7
);
*/
return $errors;
} // end func checkStatus
/**
* Adds a slash at the end of the given filename if neccessary.
*
* @param string Directoryname
* @return string Directoryname
*/
function getCheckedDirname($dirname) {
if (""!=$dirname && "/"!=substr($dirname, -1))
$dirname.="/";
return $dirname;
} // end func getCheckedDirname
} // end class PhpdocSetupHandler
?>
|