uw Thu Mar 29 13:26:53 2001 EDT
Modified files:
/php4/pear/Experimental/XML fo2pdf.php sql2xml.php sql2xml_ext.php
Log:
- added basic phpdoc doc comments
- lots of whitespaces
- renamed functions from get_xy to the PEAR getXY
Chregu, sorry for this commit in case it breaks your code, I don't like all of the
coding guides myself but we should follow them, even if they break the code in our
companies.
Index: php4/pear/Experimental/XML/fo2pdf.php
diff -u php4/pear/Experimental/XML/fo2pdf.php:1.3
php4/pear/Experimental/XML/fo2pdf.php:1.4
--- php4/pear/Experimental/XML/fo2pdf.php:1.3 Thu Mar 29 02:13:50 2001
+++ php4/pear/Experimental/XML/fo2pdf.php Thu Mar 29 13:26:53 2001
@@ -15,7 +15,7 @@
// | Authors: Christian Stocker <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: fo2pdf.php,v 1.3 2001/03/29 10:13:50 chregu Exp $
+// $Id: fo2pdf.php,v 1.4 2001/03/29 21:26:53 uw Exp $
/**
@@ -62,9 +62,9 @@
* $fop = new xml_fo2pdf("simple.fo");
* //print pdf to the outputbuffer,
* // including correct Header ("Content-type: application/pdf")
-* $fop->print_pdf();
+* $fop->printPDF();
* //delete the temporary pdf file
-* $fop->delete_pdf();
+* $fop->deletePDF();
*
* With Cache:
* require_once("XML/fo2pdf.php");
@@ -79,12 +79,12 @@
* die();
* }
* $fop = new xml_fo2pdf("simple.fo");
-* $fop->print_pdf();
-* $fop->delete_pdf();
+* $fop->printPDF();
+* $fop->deletePDF();
* print $cache->end("+30");
*
* @author Christian Stocker <[EMAIL PROTECTED]>
-* @version $Id: fo2pdf.php,v 1.3 2001/03/29 10:13:50 chregu Exp $
+* @version $Id: fo2pdf.php,v 1.4 2001/03/29 21:26:53 uw Exp $
* @package XML
*/
@@ -95,14 +95,14 @@
*
* @var string
*/
- var $fo;
+ var $fo = "";
/**
* pdf-file used in this class
*
* @var string
*/
- var $pdf;
+ var $pdf = "";
/**
* Where the temporary fo and pdf files should be stored
@@ -122,22 +122,21 @@
/**
* constructor
* One can pass an input fo-file already here (the other possibility
- * is with the run or run_from_string method).
+ * is with the run or runFromString method).
* and if the pdf should be stored permanently, a filename/path for
* that can also be passed here.
*
- * @params string file input fo-file
- * @params string file output pdf-file
- * @return Null
- * @see run(), run_from_string(), run_from_file()
+ * @param string file input fo-file
+ * @param string file output pdf-file
+ * @see run(), runFromString(), runFromFile()
*/
- function xml_fo2pdf($fo="", $pdf="")
+ function xml_fo2pdf($fo = "", $pdf = "")
{
-
if ($fo) {
$this->run($fo, $pdf);
}
}
+
/**
* Calls the Main Fop-Java-Programm
*
@@ -147,14 +146,12 @@
* if the pdf is not passed or empty/false, a temporary pdf-file
* will be created
*
- * @params string file input fo-file
- * @params string file output pdf-file
- * @params Boolean if the fo should be deleted after execution
- * @return Null
- * @see run_from_string()
+ * @param string file input fo-file
+ * @param string file output pdf-file
+ * @param boolean if the fo should be deleted after execution
+ * @see runFromString()
*/
-
- function run($fo, $pdf="", $DelFo=False)
+ function run($fo, $pdf = "", $DelFo = False)
{
if (!$pdf)
$pdf = tempnam($this->tmpdir, $this->tmppdfprefix);
@@ -165,7 +162,7 @@
$java = new Java("org.apache.fop.apps.CommandLine", $options);
$java->run();
if ($DelFo) {
- $this->delete_fo ($fo);
+ $this->deleteFo($fo);
}
}
@@ -179,12 +176,11 @@
* temporary fo-file is created here (and will be deleted
* in the run() function.)
*
- * @params string fo input fo-string
- * @params string file output pdf-file
- * @return Null
+ * @param string fo input fo-string
+ * @param string file output pdf-file
* @see run()
*/
- function run_from_string($fostring, $pdf="")
+ function runFromString($fostring, $pdf = "")
{
$fo = tempnam($this->tmpdir, $this->tmppdfprefix);
$fp = fopen($fo, "w+");
@@ -197,12 +193,11 @@
*
* This method just calls run....
*
- * @params string fo input fo-string
- * @params string file output pdf-file
- * @return Null
+ * @param string fo input fo-string
+ * @param string file output pdf-file
* @see run()
*/
- function run_from_file($fo, $pdf="")
+ function runFromFile($fo, $pdf = "")
{
return $this->run($fo, $pdf);
}
@@ -214,10 +209,9 @@
* for example in a Cache, you don't need it afterwards.
* If no pdf is given, the one generated in run() is deleted
*
- * @params string file output pdf-file
- * @return Null
+ * @param string file output pdf-file
*/
- function delete_pdf($pdf="")
+ function deletePDF($pdf = "")
{
if (!$pdf)
$pdf = $this->pdf;
@@ -230,10 +224,9 @@
* If you dynamically create fos, you don't need it afterwards.
* If no fo-file is given, the one generated in run() is deleted
*
- * @params string file input fo-file
- * @return Null
+ * @param string file input fo-file
*/
- function delete_fo($fo="")
+ function deleteFo($fo = "")
{
if (!$fo)
$fo = $this->fo;
@@ -248,14 +241,13 @@
* to the browser, use this.
* If no pdf-file is given, the generated from run() is taken.
*
- * @params string file output pdf-file
- * @return Null
- * @see return_pdf()
+ * @param string file output pdf-file
+ * @see returnPDF()
*/
- function print_pdf($pdf="")
+ function printPDF($pdf = "")
{
- Header("Content-type: application/pdf\nContent-Length: ".strlen($pdf));
- print $this->return_pdf($pdf);
+ Header("Content-type: application/pdf\nContent-Length: " .
+strlen($pdf));
+ print $this->returnPDF($pdf);
}
/**
@@ -263,21 +255,20 @@
*
* If no pdf-file is given, the generated from run() is taken.
*
- * @params string file output pdf-file
- * @return string pdf
+ * @param string file output pdf-file
+ * @return string pdf
* @see run()
*/
- function return_pdf($pdf="")
+ function returnPDF($pdf = "")
{
if (!$pdf)
$pdf = $this->pdf;
- $fd = fopen( $pdf, "r" );
- $content = fread( $fd, filesize( $pdf ) );
- fclose( $fd );
+ $fd = fopen($pdf, "r");
+ $content = fread( $fd, filesize($pdf) );
+ fclose($fd);
return $content;
}
}
-
-?>
+?>
\ No newline at end of file
Index: php4/pear/Experimental/XML/sql2xml.php
diff -u php4/pear/Experimental/XML/sql2xml.php:1.1
php4/pear/Experimental/XML/sql2xml.php:1.2
--- php4/pear/Experimental/XML/sql2xml.php:1.1 Sat Mar 24 12:00:02 2001
+++ php4/pear/Experimental/XML/sql2xml.php Thu Mar 29 13:26:53 2001
@@ -15,7 +15,7 @@
// | Authors: Christian Stocker <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: sql2xml.php,v 1.1 2001/03/24 20:00:02 chregu Exp $
+// $Id: sql2xml.php,v 1.2 2001/03/29 21:26:53 uw Exp $
/**
* This class takes a PEAR::DB-Result Object (or more than one)
@@ -30,14 +30,14 @@
* $db = DB::connect("mysql://root@localhost/xmltest");
* $xml = new xml_sql2xml;
* $result = $db->query("select * from bands");
-* $xmlstring = $xml->getxml($result,$options));
+* $xmlstring = $xml->getXML($result,$options));
*
* more examples and outputs on
* http://www.nomad.ch/php/sql2xml
* for the time being
*
* @author Christian Stocker <[EMAIL PROTECTED]>
-* @version $Id: sql2xml.php,v 1.1 2001/03/24 20:00:02 chregu Exp $
+* @version $Id: sql2xml.php,v 1.2 2001/03/29 21:26:53 uw Exp $
*/
class XML_sql2xml {
@@ -91,47 +91,52 @@
* @return string xml
* @access public
*/
- function add_result($result, $options = False)
+ function addResult($result, $options = False)
{
- $this->do_sql2xml($result, $options);
+ $this->doSql2Xml($result, $options);
}
/**
- * Returns an xml-string with a xml-representation of the resultsets.
- *
- * The resultset can be directly provided here, or if you need more than one
- * in your xml, then you have to provide each of them with add_result befor
getxml
- *
- * @param Object result result from a DB-query
- * @param array mixed options to be passed (does it need that?)
- * @return string xml
- * @access public
- */
-
+ * Returns an xml-string with a xml-representation of the resultsets.
+ *
+ * The resultset can be directly provided here, or if you need more than one
+ * in your xml, then you have to provide each of them with addResult befor getXML
+ *
+ * @param Object result result from a DB-query
+ * @param array mixed options to be passed (does it need that?)
+ * @return string xml
+ * @access public
+ */
function getxml($result = False, $options = False)
{
- return domxml_dumpmem($this->getxmlObject($result, $options));
+ return domxml_dumpmem($this->getXMLObject($result, $options));
}
/**
* Returns an xml DomDocument Object with a xml-representation of the resultsets.
*
* The resultset can be directly provided here, or if you need more than one
- * in your xml, then you have to provide each of them with add_result befor
getxml
+ * in your xml, then you have to provide each of them with addResult befor getXML
*
* @param Object result result from a DB-query
* @param array mixed options to be passed (does it need that?)
* @return Object DomDocument
* @access public
*/
- function getxmlObject($result = False, $options = False) {
+ function getXMLObject($result = False, $options = False) {
if ($result) {
- $this->do_sql2xml($result, $options);
+ $this->doSql2Xml($result, $options);
}
return $this->xmldoc;
}
- function do_sql2xml($result, $options = False)
+ /**
+ *
+ * @param
+ * @param boolean
+ * @return object DomDocument
+ */
+ function doSql2Xml($result, $options = False)
{
//set options
@@ -153,8 +158,8 @@
while (list($key, $val) = each($res))
{
- $tableInfo[$i][table]= "result";
- $tableInfo[$i][name] = $key;
+ $tableInfo[$i]["table"]= "result";
+ $tableInfo[$i]["name"] = $key;
$resFirstRow[$i] = $val;
$i++;
}
@@ -169,24 +174,24 @@
// initialize db hierarchy...
$parenttable = "root";
- $tableInfo[parent_key][root] = 0;
+ $tableInfo["parent_key"]["root"] = 0;
foreach ($tableInfo as $key => $value)
{
if (is_int($key))
{
- if (is_null($tableInfo[parent_table][$value[table]]))
+ if (is_null($tableInfo["parent_table"][$value["table"]]))
{
- $tableInfo[parent_key][$value[table]] = $key;
- $tableInfo[parent_table][$value[table]] = $parenttable;
- $parenttable = $value[table] ;
+ $tableInfo["parent_key"][$value["table"]] = $key;
+ $tableInfo["parent_table"][$value["table"]] = $parenttable;
+ $parenttable = $value["table"] ;
}
}
- //if you need more tableInfo for later use you can write a function
add_tableInfo..
- $this->add_tableInfo($key, $value, &$tableInfo);
+ //if you need more tableInfo for later use you can write a function
+addTableInfo..
+ $this->addTableInfo($key, $value, &$tableInfo);
}
// end initialize
- $parent[root] = $this->insert_new_result(&$tableInfo);
+ $parent[root] = $this->insertNewResult(&$tableInfo);
while ($FirstFetchDone || $res = $result->FetchRow($fetchmode))
{
@@ -195,32 +200,32 @@
while (list($key, $val) = each($res))
{
- if ($resold[$tableInfo[parent_key][$tableInfo[$key][table]]] !=
$res[$tableInfo[parent_key][$tableInfo[$key][table]]] || !$this->nested)
+ if ($resold[$tableInfo["parent_key"][$tableInfo[$key]["table"]]] !=
+$res[$tableInfo["parent_key"][$tableInfo[$key]["table"]]] || !$this->nested)
{
- if ($tableInfo[parent_key][$tableInfo[$key][table]] == $key )
+ if ($tableInfo["parent_key"][$tableInfo[$key]["table"]] == $key )
{
if ($this->nested || $key == 0)
{
- $parent[$tableInfo[$key][table]] =
$this->insert_new_row($parent[$tableInfo[parent_table][$tableInfo[$key][table]]],$res,$key,&$tableInfo);
+ $parent[$tableInfo[$key]["table"]] =
+$this->insertNewRow($parent[$tableInfo["parent_table"][$tableInfo[$key]["table"]]],
+$res, $key, &$tableInfo);
}
else
{
- $parent[$tableInfo[$key][table]]=
$parent[$tableInfo[parent_table][$tableInfo[$key][table]]];
+ $parent[$tableInfo[$key]["table"]]=
+$parent[$tableInfo["parent_table"][$tableInfo[$key]["table"]]];
}
//set all children entries to somethin stupid
- foreach($tableInfo[parent_table] as $pkey => $pvalue)
+ foreach($tableInfo["parent_table"] as $pkey => $pvalue)
{
- if ($pvalue == $tableInfo[$key][table])
+ if ($pvalue == $tableInfo[$key]["table"])
{
- $resold[$tableInfo[parent_key][$pkey]]=
"ThisIsJustAPlaceHolder";
+ $resold[$tableInfo["parent_key"][$pkey]]=
+"ThisIsJustAPlaceHolder";
}
}
}
-
$this->insert_new_element($parent[$tableInfo[$key][table]],$res,$key,&$tableInfo,&$subrow);
+ $this->insertNewElement($parent[$tableInfo[$key]["table"]], $res,
+$key, &$tableInfo, &$subrow);
}
@@ -232,6 +237,13 @@
return $this->xmldoc;
}
+
+ /**
+ *
+ * @param
+ * @param
+ * @return
+ */
function setOption($option, $value)
{
if (isset($this->$option)) {
@@ -245,25 +257,60 @@
// this are the functions, which are intended to be overriden in user classes
- function insert_new_result (&$metadata)
+ /**
+ *
+ * @param
+ * @return object DomNode
+ * @abstract
+ */
+ function insertNewResult(&$metadata)
{
if ($this->xmlroot)
- return $this->xmlroot->new_child("result",Null);
+ return $this->xmlroot->new_child("result", NULL);
else
return $this->xmldoc->add_root("result");
}
- function insert_new_row ($parent_row, $res, $key, &$metadata)
+
+ /**
+ *
+ * @param object DomNode
+ * @param
+ * @param
+ * @param
+ * @return
+ * @abstract
+ */
+ function insertNewRow($parent_row, $res, $key, &$metadata)
{
- return $parent_row->new_child("row",Null);
+ return $parent_row->new_child("row", NULL);
}
- function insert_new_element ($parent, $res, $key, &$metadata, &$subrow)
+
+ /**
+ *
+ * @param object DomNode
+ * @param
+ * @param
+ * @param
+ * @param
+ * @return
+ * @abstract
+ */
+ function insertNewElement($parent, $res, $key, &$metadata, &$subrow)
{
- return $parent->new_child($metadata[$key][name], utf8_encode($res[$key]));
+ return $parent->new_child($metadata[$key]["name"], utf8_encode($res[$key]));
}
- function add_tableInfo ($key, $value, &$metadata) {
+
+ /**
+ *
+ * @param
+ * @param
+ * @param
+ * @abstract
+ */
+ function addTableInfo($key, $value, &$metadata) {
}
}
Index: php4/pear/Experimental/XML/sql2xml_ext.php
diff -u php4/pear/Experimental/XML/sql2xml_ext.php:1.1
php4/pear/Experimental/XML/sql2xml_ext.php:1.2
--- php4/pear/Experimental/XML/sql2xml_ext.php:1.1 Sat Mar 24 12:00:02 2001
+++ php4/pear/Experimental/XML/sql2xml_ext.php Thu Mar 29 13:26:53 2001
@@ -15,8 +15,9 @@
// | Authors: Christian Stocker <[EMAIL PROTECTED]> |
// +----------------------------------------------------------------------+
//
-// $Id: sql2xml_ext.php,v 1.1 2001/03/24 20:00:02 chregu Exp $
+// $Id: sql2xml_ext.php,v 1.2 2001/03/29 21:26:53 uw Exp $
+require_once ("XML/sql2xml.php");
/**
* This class shows with one example, how the base sql2xml-class
@@ -40,83 +41,81 @@
* for the time being
*
* @author Christian Stocker <[EMAIL PROTECTED]>
- * @version $Id: sql2xml_ext.php,v 1.1 2001/03/24 20:00:02 chregu Exp $
+ * @version $Id: sql2xml_ext.php,v 1.2 2001/03/29 21:26:53 uw Exp $
*/
-
-require_once ("XML/sql2xml.php");
-
-
class XML_sql2xml_ext extends XML_sql2xml {
- function insert_new_row ($parent_row,$res,$key,&$tableInfo)
+ function insertNewRow($parent_row, $res, $key, &$tableInfo)
{
- $new_row= $parent_row->new_child("row",Null);
+ $new_row = $parent_row->new_child("row", NULL);
/* make an unique ID attribute in the row element with tablename.id if
there's an id
otherwise just make an unique id with the php-function, just that
there's a unique id for this row.
CAUTION: This ID changes every time ;) (if no id from db-table)
*/
- if ($res[$tableInfo[id][$tableInfo[$key][table]]])
+ if ($res[$tableInfo["id"][$tableInfo[$key]["table"]]])
{
- if ($res[$tableInfo[id][$tableInfo[$key][table]]] ==
$this->user_options[id])
+ if ($res[$tableInfo["id"][$tableInfo[$key]["table"]]] ==
+$this->user_options[id])
{
- $new_row->set_attribute("selected","selected");
+ $new_row->set_attribute("selected", "selected");
}
-
$new_row->set_attribute("ID",utf8_encode($tableInfo[$key][table].$res[$tableInfo[id][$tableInfo[$key][table]]]));
+ $new_row->set_attribute("ID", utf8_encode($tableInfo[$key]["table"] .
+$res[$tableInfo["id"][$tableInfo[$key]["table"]]]));
}
else
{
- $new_row->set_attribute("ID", uniqid($tableInfo[$key][table]));
+ $new_row->set_attribute("ID", uniqid($tableInfo[$key]["table"]));
}
return $new_row;
}
- function insert_new_result (&$tableInfo) {
+ function insertNewResult(&$tableInfo) {
- if ($this->xmlroot)
- $xmlroot=$this->xmlroot->new_child($tableInfo[0][table],Null);
+ if ($this->xmlroot)
+ $xmlroot=$this->xmlroot->new_child($tableInfo[0]["table"], NULL);
else
- $xmlroot= $this->xmldoc->add_root($tableInfo[0][table]);
- $xmlroot->set_attribute("type","Database");
- return $xmlroot;
+ $xmlroot= $this->xmldoc->add_root($tableInfo[0]["table"]);
+
+ $xmlroot->set_attribute("type", "Database");
-
+ return $xmlroot;
}
+
- function insert_new_element ($parent,$res,$key,&$tableInfo,&$subrow) {
+ function insertNewElement($parent, $res, $key, &$tableInfo, &$subrow) {
- if ($this->user_options[xml_seperator])
+ if ($this->user_options["xml_seperator"])
{
//the preg should be only done once....
- $i=0;
-
preg_match_all("/([^".$this->user_options[xml_seperator]."]+)".$this->user_options[xml_seperator]."*/",$tableInfo[$key][name],$regs);
- $subrow[$regs[1][-1]]= $parent;
+ $i = 0;
+ preg_match_all("/([^" . $this->user_options["xml_seperator"] . "]+)" .
+$this->user_options[xml_seperator] . "*/", $tableInfo[$key]["name"], $regs);
+ $subrow[$regs[1][-1]] = $parent;
// here we separate db fields to subtags.
- for ($i=0;$i<(count($regs[1])-1);$i++)
+ for ($i = 0; $i < (count($regs[1]) - 1); $i++)
{
if ( ! $subrow[$regs[1][$i]]) {
- $subrow[$regs[1][$i]]=
$subrow[$regs[1][$i-1]]->new_child($regs[1][$i],Null);
+ $subrow[$regs[1][$i]] = $subrow[$regs[1][$i -
+1]]->new_child($regs[1][$i], NULL);
}
}
-
$subrows=$subrow[$regs[1][$i-1]]->new_child($regs[1][$i],utf8_encode($res[$key]));
+ $subrows = $subrow[$regs[1][$i - 1]]->new_child($regs[1][$i],
+utf8_encode($res[$key]));
}
else
{
- $regs[1][0] = $tableInfo[$key][name];
- $i=0;
- $subrow=$parent->new_child($regs[1][$i],utf8_encode($res[$key]));
+ $regs[1][0] = $tableInfo[$key]["name"];
+ $i = 0;
+ $subrow=$parent->new_child($regs[1][$i], utf8_encode($res[$key]));
}
}
- function add_tableInfo ($key,$value,&$tableInfo) {
- if (!$metdata[id][$value[table]] && $value[name] ==
$this->user_options[element_id] )
+ function addTableinfo($key, $value, &$tableInfo) {
+
+ if (!$metdata["id"][$value[table]] && $value[name] ==
+$this->user_options["element_id"] )
{
- $tableInfo[id][$value[table]]= $key;
+ $tableInfo["id"][$value["table"]] = $key;
}
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]