some more work on serializer
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 17 Feb 2009 18:52:01 +0000 (18:52 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Tue, 17 Feb 2009 18:52:01 +0000 (18:52 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@271 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

woc/phpout.cpp
woc/phpout.h

index 8a817cd..9ac9ae5 100644 (file)
@@ -248,10 +248,17 @@ void WocPHPServerOut::newClass(const WocClass&cls)
        //implement serializers
        k=cls.serializers();
        for(int i=0;i<k.size();i++){
+               //toString function (wraps toXml)
                code+="\nfunction toString"+k[i]+"(){\n\t$xml=new DomDocument;\n";
                code+="\t$xml->appendChild($this->toXml"+k[i]+"($xml));\n\treturn $xml->saveXml();\n}\n";
-               code+="function toXml"+k[i]+"($xml){\n\t$root=$xml->createElement(\""+cls.name()+k[i]+"\");\n";
-               //TODO: add properties
+               //toXml function:
+               code+="function toXml"+k[i]+"($xml){\n";
+               code+="\t$root=$xml->createElement(\""+cls.name()+k[i]+"\");\n";
+               //add properties
+               QStringList p=cls.serializerProperties(k[i]);
+               for(int j=0;j<p.size();j++)
+                       code+=propertyToXml(cls,p[j]);
+               //return result
                code+="\treturn $root;\n}\n";
        }
        
@@ -277,6 +284,8 @@ void WocPHPServerOut::newClass(const WocClass&cls)
        tf.close();
 }
 
+QString WocPHPServerOut::propertyToXml(const WocClass&,QString){return "";}
+
 void WocPHPServerOut::newTransaction(const WocTransaction&)
 {
 }
index 18da2bd..de94af0 100644 (file)
@@ -30,7 +30,11 @@ class WocPHPServerOut:public WocOutput
                QString m_basedir,m_subdir,m_fileext;
                QFile m_loader,m_schema;
                
-               void addLoad(QString,QString);
+               /**helper: adds a loader line for a class to autoload.php*/
+               void addLoad(QString classname,QString filename);
+               
+               /**helper: generates PHP code to transform a class property to XML*/
+               QString propertyToXml(const WocClass&,QString);
 };
 
 #endif