cvs: phd /phpdotnet/phd/Package/PHP Functions.php
| From: | Moacir de Oliveira Miranda Júnior | Date: | Mon, 06 Jul 2009 06:49:17 +0000 |
| Subject: | cvs: phd /phpdotnet/phd/Package/PHP Functions.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4343@lists.php.net to get a copy of this message | ||
moacir Mon Jul 6 06:49:17 2009 UTC
Added files:
/phd/phpdotnet/phd/Package/PHP Functions.php
Log:
new class Package_PHP_Functions
http://cvs.php.net/viewvc.cgi/phd/phpdotnet/phd/Package/PHP/Functions.php?view=markup&rev=1.1
Index: phd/phpdotnet/phd/Package/PHP/Functions.php
+++ phd/phpdotnet/phd/Package/PHP/Functions.php
<?php
namespace phpdotnet\phd;
class Package_PHP_Functions extends Package_Default_Manpage {
const OPEN_CHUNK = 0x01;
const CLOSE_CHUNK = 0x02;
const OPENED_CHUNK = 0x03;
protected $formatname = "PHP-Functions";
protected $title = "PHP Manual";
protected $elementmap = array(
'set' => 'format_set',
'refentry' => 'format_refentry',
'refname' => 'format_refname',
);
protected $textmap = array(
'pubdate' => 'format_pubdate',
'refname' => 'format_refname_text',
'title' => array(
/* DEFAULT */ false,
'set' => array(
/* DEFAULT */ 'format_bookname',
'set' => false,
),
),
);
protected $CURRENT_ID = "";
/* Current Chunk settings */
protected $cchunk = array();
/* Default Chunk settings */
protected $dchunk = array(
"funcname" => array(),
"firstrefname" => true,
);
/* Common properties for all functions pages */
protected $bookName = "";
protected $date = "";
protected $isFunctionRefSet = false;
protected $isChunk = false;
public function __construct() {
parent::__construct();
parent::registerFormatName($this->formatname);
$this->dchunk = array_merge(parent::getDefaultChunkInfo(),
static::getDefaultChunkInfo());
$this->ext = "3.gz";
$this->chunked = true;
}
public function __destruct() {
$this->close();
}
public function update($event, $val = null) {
switch($event) {
case Render::CHUNK:
$this->isChunk = $val;
break;
case Render::STANDALONE:
if ($val) {
$this->registerElementMap(array_merge(parent::getDefaultElementMap(),
$this->elementmap));
$this->registerTextMap(array_merge(parent::getDefaultTextMap(),
$this->textmap));
} else {
$this->registerElementMap(static::getDefaultElementMap());
$this->registerTextMap(static::getDefaultTextMap());
}
break;
case Render::INIT:
$this->outputdir = $tmp = Config::output_dir() .
strtolower($this->getFormatName()) . '/';
if (file_exists($tmp)) {
if (!is_dir($tmp)) {
v("Output directory is a file?", E_USER_ERROR);
}
} else {
if (!mkdir($tmp)) {
v("Can't create output directory", E_USER_ERROR);
}
}
break;
case Render::VERBOSE:
v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING);
break;
}
}
public function header($index) {
return ".TH " . strtoupper($this->cchunk["funcname"][$index]) .
" 3 \"" . $this->date . "\" \"PHP Documentation Group\"
\"" . $this->bookName . "\"";
}
public function writeChunk($stream) {
if (!isset($this->cchunk["funcname"][0]))
return;
$index = 0;
rewind($stream);
$filename = $this->cchunk["funcname"][$index] . '.' .$this->ext;
$gzfile = gzopen($this->outputdir . $filename, "w9");
gzwrite($gzfile, $this->header($index));
gzwrite($gzfile, stream_get_contents($stream));
gzclose($gzfile);
v("Wrote %s", $this->outputdir . $filename, VERBOSE_CHUNK_WRITING);
while(isset($this->cchunk["funcname"][++$index])) {
$filename = $this->cchunk["funcname"][$index] . '.' .
$this->ext;
rewind($stream);
// Replace the default function name by the alternative one
$content =
preg_replace('/'.$this->cchunk["funcname"][0].'/',
$this->cchunk["funcname"][$index], stream_get_contents($stream), 1);
$gzfile = gzopen($this->outputdir . $filename, "w9");
gzwrite($gzfile, $this->header($index));
gzwrite($gzfile, $content);
gzclose($gzfile);
v("Wrote %s", $this->outputdir . $filename, VERBOSE_CHUNK_WRITING);
}
}
public function close() {
foreach ($this->fp as $fp) {
fclose($fp);
}
}
public function appendData($data) {
if (!$this->isFunctionRefSet)
return 0;
switch($this->isChunk) {
case self::CLOSE_CHUNK:
$stream = array_pop($this->fp);
$retval = (trim($data) === "") ? false : fwrite($stream, $data);
$this->writeChunk($stream);
fclose($stream);
$this->isChunk = null;
$this->cchunk = array();
return $retval;
break;
case self::OPEN_CHUNK:
$this->fp[] = fopen("php://temp/maxmemory", "r+");
$this->isChunk = self::OPENED_CHUNK;
case self::OPENED_CHUNK:
$stream = end($this->fp);
// Remove whitespace nodes
$retval = ($data != "\n" && trim($data) === "") ? false :
fwrite($stream, $data);
return $retval;
default:
return 0;
}
}
public function format_bookname($value, $tag) {
$this->bookName = $value;
return false;
}
public function format_pubdate($value, $tag) {
$this->date = $value;
return false;
}
public function format_set($open, $name, $attrs, $props) {
if (isset($attrs[Reader::XMLNS_XML]["id"]) &&
$attrs[Reader::XMLNS_XML]["id"] == "funcref") {
$this->isFunctionRefSet = $open;
}
return false;
}
public function format_refentry($open, $name, $attrs, $props) {
if (!$this->isFunctionRefSet)
return false;
if ($open) {
$this->notify(Render::CHUNK, self::OPEN_CHUNK);
$this->newChunk();
$this->cchunk = $this->dchunk;
} else {
$this->notify(Render::CHUNK, self::CLOSE_CHUNK);
$this->closeChunk();
}
return false;
}
public function format_refname($open, $name, $attrs, $props) {
if ($open) {
return (isset($this->cchunk["firstrefname"]) &&
$this->cchunk["firstrefname"]) ? false : "";
} else {
if (isset($this->cchunk["firstrefname"]) &&
$this->cchunk["firstrefname"]) {
$this->cchunk["firstrefname"] = false;
return false;
}
return "";
}
}
public function format_refname_text($value, $tag) {
$this->cchunk["funcname"][] = $this->toValidName(trim($value));
if (isset($this->cchunk["firstrefname"]) &&
$this->cchunk["firstrefname"]) {
return false;
}
return "";
}
}
?>