]> git.sesse.net Git - xml-template/commitdiff
Create php-xml-template debian package. master
authorSebastian Bugge <vsbugge@samfundet.no>
Fri, 6 Sep 2024 09:30:31 +0000 (11:30 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 17 Sep 2024 19:59:45 +0000 (21:59 +0200)
48 files changed:
php/Makefile [new file with mode: 0644]
php/attribute-empty.php [moved from php4/attribute-empty.php with 77% similarity]
php/attribute.php [moved from php4/attribute.php with 85% similarity]
php/clone.php [moved from php5-swig/clone.php with 79% similarity]
php/debian/changelog [new file with mode: 0644]
php/debian/compat [new file with mode: 0644]
php/debian/control [new file with mode: 0644]
php/debian/postinst [new file with mode: 0644]
php/debian/prerm [new file with mode: 0644]
php/debian/rules [new file with mode: 0755]
php/debian/xml-template.ini [new file with mode: 0644]
php/include.php [moved from php5-swig/include.php with 91% similarity]
php/namespace.php [moved from php5/namespace.php with 75% similarity]
php/namespace2.php [moved from php4/namespace2.php with 67% similarity]
php/passthru.php [moved from php5-swig/passthru.php with 51% similarity]
php/simple.php [moved from php5-swig/simple.php with 89% similarity]
php/structure.php [moved from php5/structure.php with 74% similarity]
php/xml-template.php [moved from php5-swig/xml-template.php with 100% similarity]
php/xml-template.swig [moved from php5-swig/xml-template.swig with 91% similarity]
php4/attribute2.php [deleted file]
php4/attribute3.php [deleted file]
php4/clone.php [deleted file]
php4/include.php [deleted file]
php4/namespace.php [deleted file]
php4/passthru.php [deleted file]
php4/simple.php [deleted file]
php4/structure.php [deleted file]
php4/xml-template.php [deleted file]
php5-swig/Makefile [deleted file]
php5-swig/attribute-empty.php [deleted file]
php5-swig/attribute.php [deleted file]
php5-swig/attribute2.php [deleted file]
php5-swig/attribute3.php [deleted file]
php5-swig/namespace.php [deleted file]
php5-swig/namespace2.php [deleted file]
php5-swig/structure.php [deleted file]
php5/attribute-empty.php [deleted file]
php5/attribute.php [deleted file]
php5/attribute2.php [deleted file]
php5/attribute3.php [deleted file]
php5/attribute4.php [deleted file]
php5/clone.php [deleted file]
php5/include.php [deleted file]
php5/namespace2.php [deleted file]
php5/passthru.php [deleted file]
php5/simple.php [deleted file]
php5/xml-template.php [deleted file]
tests/test.sh

diff --git a/php/Makefile b/php/Makefile
new file mode 100644 (file)
index 0000000..02c73ce
--- /dev/null
@@ -0,0 +1,22 @@
+CPPFLAGS=$(shell php-config --includes)
+CXXFLAGS=-std=gnu++0x $(shell xml2-config --cflags) -fPIC -g
+LDFLAGS=-shared
+LIBS=../c++11/xml-template.o
+EXT_DIR=$(DESTDIR)$(shell php-config --extension-dir)/
+
+XML_Template.so: xml-template_wrap.o $(LIBS)
+       $(CXX) $(LDFLAGS) -o $@ $< $(LIBS)
+
+xml-template_wrap.cxx XML_Template_SWIG.php php_XML_Template_SWIG.h : xml-template.swig
+       swig -c++ -php7 $<
+
+clean:
+       $(RM) XML_Template.so xml-template_wrap.o
+       $(RM) xml-template_wrap.cxx xml-template_wrap.cpp XML_Template_SWIG.php php_XML_Template_SWIG.h 
+
+install:
+       mkdir -p $(EXT_DIR)
+       install XML_Template.so $(EXT_DIR)
+
+xml-template_wrap.cpp: xml-template_wrap.cxx
+       cp xml-template_wrap.cxx xml-template_wrap.cpp
similarity index 77%
rename from php4/attribute-empty.php
rename to php/attribute-empty.php
index d4611404f0503d755f5f2ed56c4f93b669a1bf87..d7d232c40812258b894cddb5458986d6a5ec0c88 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-require('xml-template.php');
 
 # NULL values are ignored, but having one helps pointing out that
 # the array given is non-associative
@@ -7,6 +6,6 @@ require('xml-template.php');
 $doc = XML_Template_process_file('../xml/clone.xml', array(
        'color' => 'blue',
        '#things' => array(NULL)
-));
-print $doc->dump_mem();
+), true);
+print XML_Template_convert_doc_to_string($doc, true);
 ?>
similarity index 85%
rename from php4/attribute.php
rename to php/attribute.php
index 626812ec9227cb5a7097db944e965940bcf6b7b3..04fd37a55787d6a9216b710533750e4e4ee5f6b6 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-require('xml-template.php');
-
 $doc = XML_Template_process_file('../xml/clone.xml', array(
        'color' => 'red',
        '#things' => array(
@@ -9,6 +7,6 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Bright copper kettles', 'li/class' => 'odd' ),
                array( 'li' => 'Warm, woolen mittens',  'li/class' => 'even' )
        )
-));
-print $doc->dump_mem();
+), true);
+print XML_Template_convert_doc_to_string($doc, true);
 ?>
similarity index 79%
rename from php5-swig/clone.php
rename to php/clone.php
index 20444db54ebfd4147f5cc5110aef4da50e63384a..ac38f39643a261f183b828f03e206f4aff7ab50f 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-include("xml-template.php");
-
 $doc = XML_Template_process_file('../xml/clone.xml', array( 
        'color' => 'blue',
        '#things' => array(
@@ -10,7 +8,7 @@ $doc = XML_Template_process_file('../xml/clone.xml', array(
                array( 'li' => 'Warm, woolen mittens' ) 
        )
 ), true);
-print XML_Template_convert_doc_to_string($doc);
+print XML_Template_convert_doc_to_string($doc, true);
 
 ?>
 
diff --git a/php/debian/changelog b/php/debian/changelog
new file mode 100644 (file)
index 0000000..839869f
--- /dev/null
@@ -0,0 +1,5 @@
+php-xml-template (1.0) unstable; urgency=medium
+
+  * Initial release.
+
+ -- Sebastian Bugge <vsbugge@samfundet.no>  Fri, 06 Sep 2024 11:20:14 +0200
diff --git a/php/debian/compat b/php/debian/compat
new file mode 100644 (file)
index 0000000..f599e28
--- /dev/null
@@ -0,0 +1 @@
+10
diff --git a/php/debian/control b/php/debian/control
new file mode 100644 (file)
index 0000000..b35afb6
--- /dev/null
@@ -0,0 +1,12 @@
+Source: php-xml-template
+Priority: extra
+Maintainer: Steinar H. Gunderson <sesse@samfundet.no>
+Build-Depends: debhelper (>= 13.3.4~)
+Standards-Version: 3.9.1
+Section: php
+
+Package: php-xml-template
+Section: php
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, ${php:Depends}
+Description: PHP package that provides xml-template for use in PHP.
diff --git a/php/debian/postinst b/php/debian/postinst
new file mode 100644 (file)
index 0000000..9b6c119
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+phpenmod xml-template
diff --git a/php/debian/prerm b/php/debian/prerm
new file mode 100644 (file)
index 0000000..4662253
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+phpdismod xml-template
diff --git a/php/debian/rules b/php/debian/rules
new file mode 100755 (executable)
index 0000000..f10f0bd
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+
+MODS_AVAILBALE=$(shell php-config --ini-path)/../mods-available
+DESTDIR=debian/php-xml-template
+
+clean:
+       dh_testdir
+       dh_clean
+       $(MAKE) clean
+
+build:
+       dh_testdir
+       $(MAKE)
+
+binary-indep:
+
+binary-arch:
+       dh_testroot
+       dh_prep
+       dh_installdirs
+       $(MAKE) install DESTDIR=$(DESTDIR)
+       install -D -m 644 -o root -g root debian/xml-template.ini $(DESTDIR)$(MODS_AVAILBALE)/xml-template.ini
+       dh_installdocs
+       dh_installchangelogs
+       dh_compress
+       dh_fixperms
+       dh_strip
+       dh_makeshlibs
+       dh_shlibdeps
+       echo "php:Depends=phpapi-$(shell php-config --phpapi)" >> debian/php-xml-template.substvars
+       dh_installdeb
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-arch
diff --git a/php/debian/xml-template.ini b/php/debian/xml-template.ini
new file mode 100644 (file)
index 0000000..4d27e33
--- /dev/null
@@ -0,0 +1,2 @@
+; configuration for php xml-template module
+extension=XML_Template.so
similarity index 91%
rename from php5-swig/include.php
rename to php/include.php
index 6845d50711a67b36d7bc795fc62677f0bfc65c70..5dd22a155b7f323a6ab66cd403d3a25f143cf384 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-include("xml-template.php");
-
 $doc = XML_Template_process_file('../xml/included.xml', array(
        'color' => 'red'
 ), false);
similarity index 75%
rename from php5/namespace.php
rename to php/namespace.php
index 023671182e7021e6a41fab2105275f3f852c478d..acdaf4d42542a964a8bd4064143dd16d51b5cdcb 100644 (file)
@@ -1,12 +1,10 @@
 <?php
-require('xml-template.php');
-
 $doc = XML_Template_process_file('../xml/namespace.xml', array( 
        'title' => 'Namespace tests',
        '#hello' => 'Hello world!',
        '#test' => 'Replaced.',
        'tagname' => 'foo',
        '#moretest' => 'bar'
-));
-print $doc->saveXML();
+), true);
+print XML_Template_convert_doc_to_string($doc, true);
 ?>
similarity index 67%
rename from php4/namespace2.php
rename to php/namespace2.php
index 6ff09fd07da50c651fdd5c25b0efe1a7e10feb93..799c2ea1f8012b568132d72b096ef3036c87af75 100644 (file)
@@ -1,9 +1,7 @@
 <?php
-require('xml-template.php');
-
 $doc = XML_Template_process_file('../xml/namespace2.xml', array( 
        'title' => 'Namespace tests',
        '#hello' => 'Replaced.',
-));
-print $doc->dump_mem();
+), true);
+print XML_Template_convert_doc_to_string($doc, true);
 ?>
similarity index 51%
rename from php5-swig/passthru.php
rename to php/passthru.php
index 91f1f56bddae6d385764918744d2c23bbc98e36b..85a7d0ea320eb4485b98a785ae6524b577dc2b17 100644 (file)
@@ -1,8 +1,6 @@
 <?php
-include("xml-template.php");
-
 $doc = XML_Template_process_file('../xml/passthru.xml', array(), true);
-print XML_Template_convert_doc_to_string($doc);
+print XML_Template_convert_doc_to_string($doc, true);
 
 ?>
 
similarity index 89%
rename from php5-swig/simple.php
rename to php/simple.php
index 919d9ee13532ba561e1801010a2f0c15a0c9439f..742a1c960b0a84134ffba218a35573c0479c33c6 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-include("xml-template.php");
-
 $doc = XML_Template_process_file('../xml/simple.xml', array( 
        'title' => 'A very basic example',
        '#hello' => 'Hello world!'
similarity index 74%
rename from php5/structure.php
rename to php/structure.php
index ebf72354d61d1e2a703d55c8b2f7bdb81c6ceb1b..a8b374f3c3a3c02d5f326550cd68bb3dd78a5f4e 100644 (file)
@@ -1,12 +1,10 @@
 <?php
-require('xml-template.php');
-
 $doc = XML_Template_process_file('../xml/structure.xml', array(
        '#outer' => array(
                array( '#inner' => 'One' ),
                array( '#inner' => 'Two' ),
                array( '#inner' => 'Three' ),
        )
-));
-print $doc->saveXML();
+), true);
+print XML_Template_convert_doc_to_string($doc, true);
 ?>
similarity index 91%
rename from php5-swig/xml-template.swig
rename to php/xml-template.swig
index 458296ef994e6d782a6f854854d57c921816298d..3c0573c26028da6a03bd277757d9e60465f7a2c4 100644 (file)
@@ -38,38 +38,34 @@ Directive* convert_php_objects_to_directive(zval *obj)
                HashTable *ht = Z_ARRVAL_P(obj);
                if (is_associative_array(ht)) {
                        std::unordered_map<std::string, Directive *> my_map;
-                       for (zend_hash_internal_pointer_reset(ht); zend_hash_has_more_elements(ht) == SUCCESS; zend_hash_move_forward(ht)) {
-                               char *str_key;
-                               ulong num_key;
-                               zend_hash_get_current_key(ht, &str_key, &num_key, 0);
-
+                       zend_string *str_key;
+                       zval *zv;
+                       ulong num_key;
+                       ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, zv) {
                                std::string key;
-                               if (zend_hash_get_current_key_type(ht) == HASH_KEY_IS_STRING) {
-                                       key = str_key;
+                               if (str_key) {
+                                       key.assign(str_key->val, str_key->len);
                                } else {
                                        char buf[32];
                                        sprintf(buf, "%lu", num_key);
                                        key = buf;
                                }
 
-                               zval **data;
-                               zend_hash_get_current_data(ht, (void **)&data);
-                               my_map.insert(make_pair(key, convert_php_objects_to_directive(*data)));
-                       }
+                               my_map.insert(make_pair(key, convert_php_objects_to_directive(zv)));
+                       } ZEND_HASH_FOREACH_END();
                        return new Substitute(my_map);
                } else {
                        std::vector<Directive *> subdirectives;
                        for (unsigned i = 0; i < ht->nNumOfElements; ++i) {
-                               zval **data;
-                               zend_hash_index_find(ht, i, (void **)&data);
-                               subdirectives.push_back(convert_php_objects_to_directive(*data));
+                               zval *data = zend_hash_index_find(ht, i);
+                               subdirectives.push_back(convert_php_objects_to_directive(data));
                        }
                        return new Clone(subdirectives);
                }
                break;
        }
        case IS_STRING: {
-               char *str = Z_STRVAL_P(obj);
+               std::string str(Z_STRVAL_P(obj), Z_STRLEN_P(obj));
                return new Replace(str);
        }
        case IS_LONG: {
@@ -82,13 +78,15 @@ Directive* convert_php_objects_to_directive(zval *obj)
                snprintf(str, sizeof(str), "%f", Z_DVAL_P(obj));
                return new Replace(str);
        }
-       case IS_RESOURCE: {
+       case IS_OBJECT: {
                XmlDocPtrWrapper *doc;
                if (SWIG_ConvertPtr(obj, (void **)&doc, SWIGTYPE_p_XmlDocPtrWrapper, 0) < 0 || doc == NULL) {
                        return NULL;
                }
                return new ReplaceInclude(xmlCopyDoc((*doc)->ptr, 1));
        }
+       case IS_REFERENCE:
+               return convert_php_objects_to_directive(&Z_REF_P(obj)->val);
        case IS_NULL:
                return new Replace { "" };
        default:
@@ -243,7 +241,7 @@ void XML_Template_clean_whitespace(XmlDocPtrWrapper doc, bool aggressive)
 %}
 
 %typemap(in) Directive* {
-       $1 = convert_php_objects_to_directive(*$input);
+       $1 = convert_php_objects_to_directive(&$input);
 }
 
 XmlDocPtrWrapper XML_Template_process_file(const std::string &input_filename, Directive *root_directive, bool clean);
diff --git a/php4/attribute2.php b/php4/attribute2.php
deleted file mode 100644 (file)
index 186828f..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => XML_Template_alternate('li/class', array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ),
-       ), array('odd', 'even'))
-));
-print $doc->dump_mem();
-?>
diff --git a/php4/attribute3.php b/php4/attribute3.php
deleted file mode 100644 (file)
index f4fa718..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => XML_Template_alternate('li/class', array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               NULL,
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ),
-       ), array('odd', 'even'))
-));
-print $doc->dump_mem();
-?>
diff --git a/php4/clone.php b/php4/clone.php
deleted file mode 100644 (file)
index 2bbd266..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ) 
-       )
-));
-print $doc->dump_mem();
-?>
diff --git a/php4/include.php b/php4/include.php
deleted file mode 100644 (file)
index 8819ef7..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/included.xml', array(
-       'color' => 'red'
-), 0);
-$master = XML_Template_process_file('../xml/master.xml', array(
-       'title' => 'Main HTML title',
-       'h1' => 'Nice heading here',
-       'contents' => $doc
-));
-print $master->dump_mem();
-?>
diff --git a/php4/namespace.php b/php4/namespace.php
deleted file mode 100644 (file)
index 35bb707..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/namespace.xml', array( 
-       'title' => 'Namespace tests',
-       '#hello' => 'Hello world!',
-       '#test' => 'Replaced.',
-       'tagname' => 'foo',
-       '#moretest' => 'bar'
-));
-print $doc->dump_mem();
-?>
diff --git a/php4/passthru.php b/php4/passthru.php
deleted file mode 100644 (file)
index 95dd1be..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/passthru.xml', array()); 
-print $doc->dump_mem();
-?>
diff --git a/php4/simple.php b/php4/simple.php
deleted file mode 100644 (file)
index 10e73f1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/simple.xml', array( 
-       'title' => 'A very basic example',
-       '#hello' => 'Hello world!'
-));
-print $doc->dump_mem();
-?>
diff --git a/php4/structure.php b/php4/structure.php
deleted file mode 100644 (file)
index adb153e..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/structure.xml', array(
-       '#outer' => array(
-               array( '#inner' => 'One' ),
-               array( '#inner' => 'Two' ),
-               array( '#inner' => 'Three' ),
-       )
-));
-print $doc->dump_mem();
-?>
diff --git a/php4/xml-template.php b/php4/xml-template.php
deleted file mode 100644 (file)
index 6fbf4bf..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-<?php
-
-function XML_Template_process_file($filename, $obj, $clean = 1)
-{
-       $doc = domxml_open_file($filename);
-       XML_Template_process($doc, $obj, $clean);
-       return $doc;
-}
-
-function XML_Template_process($node, $obj, $clean = 1)
-{
-       if (is_a($obj, 'domnode')) {                          # overwrite
-               foreach ($node->child_nodes() as $child) {
-                       $node->remove_child($child);
-               }
-
-               if (is_a($obj, 'domdocument')) {
-                       $obj = $obj->document_element();
-               }
-
-               $newobj = own_clone_node($obj, $node->owner_document());
-               $node->append_child($newobj);
-
-               XML_Template_process($newobj, array(), $clean);
-       } else if (!is_array($obj)) {                         # overwrite
-               foreach ($node->child_nodes() as $child) {
-                       $node->remove_child($child);
-               }
-               $doc = $node->owner_document();
-               $node->add_child($doc->create_text_node($obj));
-       } else if (is_associative_array($obj)) {              # substitute
-               foreach ($node->child_nodes() as $child) {
-                       $processed = false;
-
-                       if ($child->node_type() == XML_ELEMENT_NODE) {
-                               unset($id);
-
-                               $tag = $child->node_name();
-                               $attrs = $child->attributes();
-                               if (isset($attrs)) {
-                                       foreach ($child->attributes() as $attr) {
-                                               if ($attr->namespace_uri() == 'http://template.sesse.net/' && $attr->name() == 'id') {
-                                                       $id = $attr->value();
-                                                       if ($clean) {
-                                                               $attr->unlink_node();
-                                                       }
-                                               }
-                                       }
-                               }
-                       
-                               # check all substitutions to see if we found anything
-                               # appropriate
-                               foreach (array_keys($obj) as $key) {
-                                       # FIXME: we would want something like \Q and \E here...
-                                       if (preg_match('/^' . $tag . '\/(.*)$/', $key, $matches) ||
-                                           (isset($id) && preg_match('/^#' . $id . '\/(.*)$/', $key, $matches))) {
-                                               $child->set_attribute($matches[1], $obj[$key]);
-                                       }
-
-                                       if ($processed) {
-                                               continue;
-                                       }
-                                       if ($key == $tag || (isset($id) && $key == ('#'.$id))) {
-                                               XML_Template_process($child, $obj[$key], $clean);
-                                               $processed = true;
-                                       }
-                               }
-                       }
-
-                       if (!$processed) {
-                               XML_Template_process($child, $obj, $clean);
-                       }
-               }
-       } else {                                                # repeat
-               $doc = $node->owner_document();
-               $frag = $doc->create_element("temporary-fragment");    # ugh
-
-               foreach ($node->child_nodes() as $child) {
-                       $frag->append_child($child);
-                       $node->remove_child($child);
-               }
-
-               foreach ($obj as $instance) {
-                       if (!isset($instance)) {
-                               continue;
-                       }
-
-                       $newnode = own_clone_node($frag, $frag->owner_document());
-                       $node->append_child($newnode);
-                       XML_Template_process($newnode, $instance, $clean);
-                       if ($clean) {
-                               XML_Template_clean($newnode);
-                       }
-               }
-
-               # remove all the <fragment> tags
-
-               foreach ($node->child_nodes() as $child) {
-                       if ($child->name() != 'temporary-fragment') {
-                               continue;
-                       }
-                       foreach ($child->child_nodes() as $child2) {
-                               $node->append_child($child2);
-                       }
-                       $node->remove_child($child);
-               }       
-       }
-
-       if ($clean) {
-               XML_Template_clean($node);
-       }
-}
-
-function XML_Template_clean($node)
-{
-       if ($node->node_type() == XML_ELEMENT_NODE) {
-               if ($node->namespace_uri() != 'http://template.sesse.net/') {
-                       return;
-               }
-
-               # as this is a dummy node, we want to remove it and move everything further up
-               # after we've done any required replacements
-               $doc = $node->owner_document();
-               $parent = $node->parent_node();
-               foreach ($node->child_nodes() as $child) {
-                       $node->remove_child($child);
-                       $node->insert_before($child, $node);
-               }
-               $parent->remove_child($node);
-       }
-}
-
-# FIXME: use varargs here
-function XML_Template_alternate($tag, $array, $elems)
-{
-       $num = count($elems);
-
-       for ($i = 0, $j = 0; $i < count($array); $i++) {
-               if (isset($array[$i])) {
-                       $array[$i][$tag] = $elems[$j++ % $num];
-               }
-       }
-
-       return $array;
-}
-               
-# Ideally, this would be "return $obj->clone_node(true)". But surprise, surprise,
-# PHP is buggy (at least PHP4); it removes the prefix information from all attributes
-# during a clone. IOW, we'll have to clone evverything ourselves.
-function own_clone_node($node, $doc)
-{
-       // we only need these two
-       if ($node->node_type() == XML_ELEMENT_NODE) {
-               $nsuri = $node->namespace_uri();
-               if (isset($nsuri)) {
-                       $newnode = $doc->create_element_ns($node->namespace_uri(), $node->node_name(), $node->prefix());
-               } else {
-                       $newnode = $doc->create_element($node->node_name());
-               }
-               
-               $attrs = $node->attributes();
-               if (isset($attrs)) {
-                       foreach ($node->attributes() as $attr) {
-                               $attr2 = $doc->create_attribute($attr->name(), $attr->value());
-                               $nsuri = $attr->namespace_uri();
-                               if (isset($nsuri)) {
-                                       $attr2->set_namespace($nsuri, $attr->prefix());
-                               }
-                               $newnode->append_child($attr2);
-                       }
-               }
-               foreach ($node->child_nodes() as $child) {
-                       $newnode->append_child(own_clone_node($child, $doc));
-               }
-               return $newnode;
-       } else {
-               return $node->clone_node(true);
-       }
-}
-
-function is_associative_array($arr)
-{
-       if (!is_array($arr)) {
-               return false;
-       }
-       $diff = array_diff(range(0, count($arr) - 1), array_keys($arr));
-       return (count($diff) > 0);
-}
-?>
diff --git a/php5-swig/Makefile b/php5-swig/Makefile
deleted file mode 100644 (file)
index cc90f0a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-CPPFLAGS=$(shell php-config --includes)
-CXXFLAGS=-std=gnu++0x $(shell xml2-config --cflags) -fPIC -g
-LDFLAGS=-shared
-LIBS=../c++11/xml-template.o
-
-XML_Template_SWIG.so: xml-template_wrap.o $(LIBS)
-       $(CXX) $(LDFLAGS) -o $@ $< $(LIBS)
-
-xml-template_wrap.cpp XML_Template_SWIG.php php_XML_Template_SWIG.h : xml-template.swig
-       swig -c++ -php $<
-
-clean:
-       $(RM) XML_Template_SWIG.so xml-template_wrap.o
-       $(RM) xml-template_wrap.cpp XML_Template_SWIG.php php_XML_Template_SWIG.h 
-
diff --git a/php5-swig/attribute-empty.php b/php5-swig/attribute-empty.php
deleted file mode 100644 (file)
index ce4e532..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-include("xml-template.php");
-
-# NULL values are ignored, but having one helps pointing out that
-# the array given is non-associative
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => array(NULL)
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5-swig/attribute.php b/php5-swig/attribute.php
deleted file mode 100644 (file)
index 8087dc7..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-include("xml-template.php");
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'red',
-       '#things' => array(
-               array( 'li' => 'Raindrops on roses',    'li/class' => 'odd' ),
-               array( 'li' => 'Whiskers on kittens',   'li/class' => 'even' ),
-               array( 'li' => 'Bright copper kettles', 'li/class' => 'odd' ),
-               array( 'li' => 'Warm, woolen mittens',  'li/class' => 'even' )
-       )
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5-swig/attribute2.php b/php5-swig/attribute2.php
deleted file mode 100644 (file)
index 8d6c99b..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-include("xml-template.php");
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => XML_Template_alternate('li/class', array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ),
-       ), array('odd', 'even'))
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5-swig/attribute3.php b/php5-swig/attribute3.php
deleted file mode 100644 (file)
index 1262a90..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-include("xml-template.php");
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => XML_Template_alternate('li/class', array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               NULL,
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ),
-       ), array('odd', 'even'))
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5-swig/namespace.php b/php5-swig/namespace.php
deleted file mode 100644 (file)
index 04d2fac..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-include("xml-template.php");
-
-$doc = XML_Template_process_file('../xml/namespace.xml', array( 
-       'title' => 'Namespace tests',
-       '#hello' => 'Hello world!',
-       '#test' => 'Replaced.',
-       'tagname' => 'foo',
-       '#moretest' => 'bar'
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5-swig/namespace2.php b/php5-swig/namespace2.php
deleted file mode 100644 (file)
index 998cf66..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-include("xml-template.php");
-
-$doc = XML_Template_process_file('../xml/namespace2.xml', array( 
-       'title' => 'Namespace tests',
-       '#hello' => 'Replaced.',
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5-swig/structure.php b/php5-swig/structure.php
deleted file mode 100644 (file)
index de2e3ab..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-include("xml-template.php");
-
-$doc = XML_Template_process_file('../xml/structure.xml', array(
-       '#outer' => array(
-               array( '#inner' => 'One' ),
-               array( '#inner' => 'Two' ),
-               array( '#inner' => 'Three' ),
-       )
-), true);
-print XML_Template_convert_doc_to_string($doc);
-?>
diff --git a/php5/attribute-empty.php b/php5/attribute-empty.php
deleted file mode 100644 (file)
index 3818141..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?php
-require('xml-template.php');
-
-# NULL values are ignored, but having one helps pointing out that
-# the array given is non-associative
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => array(NULL)
-));
-print $doc->saveXML();
-?>
diff --git a/php5/attribute.php b/php5/attribute.php
deleted file mode 100644 (file)
index df0f5f5..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'red',
-       '#things' => array(
-               array( 'li' => 'Raindrops on roses',    'li/class' => 'odd' ),
-               array( 'li' => 'Whiskers on kittens',   'li/class' => 'even' ),
-               array( 'li' => 'Bright copper kettles', 'li/class' => 'odd' ),
-               array( 'li' => 'Warm, woolen mittens',  'li/class' => 'even' )
-       )
-));
-print $doc->saveXML();
-?>
diff --git a/php5/attribute2.php b/php5/attribute2.php
deleted file mode 100644 (file)
index f58b4ad..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => XML_Template_alternate('li/class', array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ),
-       ), array('odd', 'even'))
-));
-print $doc->saveXML();
-?>
diff --git a/php5/attribute3.php b/php5/attribute3.php
deleted file mode 100644 (file)
index 0fbfba7..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => XML_Template_alternate('li/class', array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               NULL,
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ),
-       ), array('odd', 'even'))
-));
-print $doc->saveXML();
-?>
diff --git a/php5/attribute4.php b/php5/attribute4.php
deleted file mode 100644 (file)
index 1251aa3..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/attribute4.xml', array(
-       '#foo/value' => 'bar',
-));
-print $doc->saveXML();
-?>
diff --git a/php5/clone.php b/php5/clone.php
deleted file mode 100644 (file)
index 28b4442..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/clone.xml', array(
-       'color' => 'blue',
-       '#things' => array(
-               array( 'li' => 'Raindrops on roses' ),
-               array( 'li' => 'Whiskers on kittens' ),
-               array( 'li' => 'Bright copper kettles' ),
-               array( 'li' => 'Warm, woolen mittens' ) 
-       )
-));
-print $doc->saveXML();
-?>
diff --git a/php5/include.php b/php5/include.php
deleted file mode 100644 (file)
index 79b15c3..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/included.xml', array(
-       'color' => 'red'
-), 0);
-$master = XML_Template_process_file('../xml/master.xml', array(
-       'title' => 'Main HTML title',
-       'h1' => 'Nice heading here',
-       'contents' => $doc
-));
-print $master->saveXML();
-?>
diff --git a/php5/namespace2.php b/php5/namespace2.php
deleted file mode 100644 (file)
index 57c2778..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/namespace2.xml', array( 
-       'title' => 'Namespace tests',
-       '#hello' => 'Replaced.',
-));
-print $doc->saveXML();
-?>
diff --git a/php5/passthru.php b/php5/passthru.php
deleted file mode 100644 (file)
index 49e1b61..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/passthru.xml', array()); 
-print $doc->saveXML();
-?>
diff --git a/php5/simple.php b/php5/simple.php
deleted file mode 100644 (file)
index afcdc34..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-require('xml-template.php');
-
-$doc = XML_Template_process_file('../xml/simple.xml', array( 
-       'title' => 'A very basic example',
-       '#hello' => 'Hello world!'
-));
-print $doc->saveXML();
-?>
diff --git a/php5/xml-template.php b/php5/xml-template.php
deleted file mode 100644 (file)
index e6a4e19..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-<?php
-
-function XML_Template_process_file($filename, $obj, $clean = 1)
-{
-       $doc = new DOMDocument;
-       $doc->load($filename);
-       XML_Template_process($doc, $obj, $clean);
-       return $doc;
-}
-
-function XML_Template_process($node, $obj, $clean = 1)
-{
-       if (is_a($obj, 'DOMNode')) {                          # overwrite
-               while ($node->childNodes->length > 0) {
-                       $child = $node->childNodes->item(0);
-                       $node->removeChild($child);
-               }
-
-               if (is_a($obj, 'DOMDocument')) {
-                       $obj = $obj->documentElement;
-               }
-
-               $frag = $node->ownerDocument->createDocumentFragment();
-               $frag->appendChild($node->ownerDocument->importNode($obj, true));
-               XML_Template_process($frag, array(), $clean);
-               $node->appendChild($frag);
-       } else if (!is_array($obj)) {                         # overwrite
-               while ($node->childNodes->length > 0) {
-                       $node->removeChild($node->firstChild);
-               }
-               $doc = $node->ownerDocument;
-               $node->appendChild($doc->createTextNode($obj));
-       } else if (is_associative_array($obj)) {              # substitute
-               $num_children = ($node->childNodes == null) ? 0 : $node->childNodes->length;
-               $children = array();
-               for ($i = 0; $i < $num_children; ++$i) {
-                       $children[] = $node->childNodes->item($i);
-               }
-
-               for ($i = 0; $i < $num_children; ++$i) {
-                       $child = $children[$i];
-                       $processed = false;
-
-                       if ($child->nodeType == XML_ELEMENT_NODE) {
-                               unset($id);
-
-                               $tag = $child->localName;
-                               $attrs = $child->attributes;
-
-                               if (isset($attrs)) {
-                                       $replace_child = 0;
-                                       $id_node = $child->getAttributeNodeNS('http://template.sesse.net/', 'id');
-                                       if (isset($id_node)) {
-                                               $id = $id_node->value;
-                                               if ($clean) {
-                                                       $child->removeAttributeNode($id_node);
-                                                       $replace_child = 1;
-                                               }       
-                                       }
-
-                                       # This seems to be the only way to reliably get rid of the excess
-                                       # XML namespace declarations.
-                                       if ($replace_child == 1) {
-                                               $newchild = own_clone_element($child, $child->ownerDocument);
-                                               while ($child->childNodes->length > 0) {
-                                                       $newchild->appendChild($child->firstChild);
-                                               }
-                                               $node->replaceChild($newchild, $child);
-                                               $child = $newchild;
-                                       }
-                               }
-                       
-                               # check all substitutions to see if we found anything
-                               # appropriate
-                               foreach (array_keys($obj) as $key) {
-                                       # FIXME: we would want something like \Q and \E here...
-                                       if (preg_match('/^' . $tag . '\/(.*)$/', $key, $matches) ||
-                                           (isset($id) && preg_match('/^#' . $id . '\/(.*)$/', $key, $matches))) {
-                                               $child->setAttribute($matches[1], $obj[$key]);
-                                       }
-
-                                       if ($processed) {
-                                               continue;
-                                       }
-                                       if ($key == $tag || (isset($id) && $key == ('#'.$id))) {
-                                               XML_Template_process($child, $obj[$key], $clean);
-                                               $processed = true;
-                                       }
-                               }
-                       }
-
-                       if (!$processed) {
-                               XML_Template_process($child, $obj, $clean);
-                       }
-               }
-       } else {                                                # repeat
-               $doc = $node->ownerDocument;
-               $frag = $doc->createDocumentFragment();
-
-               while ($node->childNodes->length > 0) {
-                       $child = $node->childNodes->item(0);
-                       $node->removeChild($child);
-                       $frag->appendChild($child);
-               }
-
-               foreach ($obj as $instance) {
-                       if (!isset($instance)) {
-                               continue;
-                       }
-
-                       $newnode = own_clone_node($frag, $frag->ownerDocument);
-                       XML_Template_process($newnode, $instance, $clean);
-
-                       $node->appendChild($newnode);
-                       if ($clean) {
-                               XML_Template_clean($newnode);
-                       }
-               }
-       }
-
-       if ($clean) {
-               XML_Template_clean($node);
-       }
-}
-
-function XML_Template_clean($node)
-{
-       if ($node->nodeType == XML_ELEMENT_NODE) {
-               if ($node->namespaceURI != 'http://template.sesse.net/') {
-                       return;
-               }
-
-               # as this is a dummy node, we want to remove it and move everything further up
-               # after we've done any required replacements
-               $doc = $node->ownerDocument;
-               $parent = $node->parentNode;
-
-               while ($node->childNodes->length > 0) {
-                       $child = $node->childNodes->item(0);
-                       $node->removeChild($child);
-                       $parent->insertBefore(own_clone_node($child, $doc), $node);
-               }
-               $parent->removeChild($node);
-       }
-}
-
-# FIXME: use varargs here
-function XML_Template_alternate($tag, $array, $elems)
-{
-       $num = count($elems);
-
-       for ($i = 0, $j = 0; $i < count($array); $i++) {
-               if (isset($array[$i])) {
-                       $array[$i][$tag] = $elems[$j++ % $num];
-               }
-       }
-
-       return $array;
-}
-               
-# Ideally, this would be "return $obj->clone_node(true)". But surprise,
-# surprise, PHP is buggy; it does not preserve the prefix information on
-# attributes properly during a clone. (PHP4 and PHP5 are broken in different
-# ways here...) IOW, we'll have to clone everything ourselves.
-function own_clone_node($node, $doc)
-{
-       // we only need these two
-       if ($node->nodeType == XML_DOCUMENT_FRAG_NODE) {
-               $newnode = $doc->createDocumentFragment();
-
-               for ($i = 0; $i < $node->childNodes->length; ++$i) {
-                       $child = $node->childNodes->item($i);
-                       $newnode->appendChild(own_clone_node($child, $doc));
-               }
-               return $newnode;
-       } else if ($node->nodeType == XML_ELEMENT_NODE) {
-               $newnode = own_clone_element($node, $doc);
-               for ($i = 0; $i < $node->childNodes->length; ++$i) {
-                       $child = $node->childNodes->item($i);
-                       $newnode->appendChild(own_clone_node($child, $doc));
-               }
-               return $newnode;
-       } else {
-               return $node->cloneNode(true);
-       }
-}
-               
-function own_clone_element($node, $doc)
-{
-       $nsuri = $node->namespaceURI;
-       if (isset($nsuri) && $node->prefix != "default") {
-               $newnode = $doc->createElementNS($node->namespaceURI, $node->nodeName, $node->prefix);
-       
-               // remove useless empty text child
-               $newnode->removeChild($newnode->firstChild);
-       } else {
-               $newnode = $doc->createElement($node->localName);
-       }
-       
-       $attrs = $node->attributes;
-       if (isset($attrs)) {
-               foreach ($node->attributes as $attr) {
-                       $nsuri = $attr->namespaceURI;
-                       if (isset($nsuri) && $attr->prefix != "default") {
-                               $attr2 = $doc->createAttributeNS($nsuri, $attr->prefix . ":" . $attr->name);
-                       } else {
-                               $attr2 = $doc->createAttribute($attr->localName);
-                       }
-
-                       # You've got to be kidding me...
-                       $attr2->value = preg_replace("/&/", "&amp;", $attr->value);
-                       $newnode->appendChild($attr2);
-               }
-       }
-       return $newnode;
-}
-
-function is_associative_array($arr)
-{
-       if (!is_array($arr)) {
-               return false;
-       }
-       $diff = array_diff(range(0, count($arr) - 1), array_keys($arr));
-       return (count($diff) > 0);
-}
-?>
index 1b66e17498ad17243d196a41a99c155e8ca81e0e..bf92fca9f74ed15c64322361eb3208cca3724024 100755 (executable)
@@ -24,8 +24,8 @@ for L in $LANGUAGES; do
                if [ "$L" = "php5" ]; then
                        php5-cgi -q ../php5/$T.php > $TEMPFILE
                fi
-               if [ "$L" = "php5-swig" ]; then
-                       ( cd ../c++11 && make -s && cd ../php5-swig && make -s && sudo cp XML_Template_SWIG.so /usr/lib/php5/20090626+lfs ) && php5-cgi -q ../php5-swig/$T.php > $TEMPFILE
+               if [ "$L" = "php7-swig" ]; then
+                       ( cd ../c++11 && make -s && cd ../php7-swig && make -s && sudo cp XML_Template_SWIG.so /usr/lib/php/20151012 ) && php7-cgi -q ../php7-swig/$T.php > $TEMPFILE
                fi
                if [ "$L" = "python" ]; then
                        python2 ../python/$T.py > $TEMPFILE