1 %module XML_Template_SWIG
5 #include "../c++11/xml-template.h"
7 bool is_associative_array(HashTable *ht)
9 if (ht->nNumOfElements == 0) {
12 for (unsigned i = 0; i < ht->nNumOfElements; ++i) {
14 sprintf(buf, "%u", i);
15 if (!zend_hash_exists(ht, buf, strlen(buf))) {
22 Directive* convert_php_objects_to_directive(zval *obj)
24 switch (Z_TYPE_P(obj)) {
26 HashTable *ht = Z_ARRVAL_P(obj);
27 if (is_associative_array(ht)) {
28 std::unordered_map<std::string, Directive *> my_map;
29 for (zend_hash_internal_pointer_reset(ht); zend_hash_has_more_elements(ht) == SUCCESS; zend_hash_move_forward(ht)) {
32 zend_hash_get_current_key(ht, &str_key, &num_key, 0);
35 if (zend_hash_get_current_key_type(ht) == HASH_KEY_IS_STRING) {
39 sprintf(buf, "%lu", num_key);
44 zend_hash_get_current_data(ht, (void **)&data);
45 my_map.insert(make_pair(key, convert_php_objects_to_directive(*data)));
47 return new Substitute(my_map);
54 char *str = Z_STRVAL_P(obj);
55 return new Replace(str);
58 printf("WARNING: Unknown type %d!\n", Z_TYPE_P(obj));
67 %typemap(in) Directive* {
68 $1 = convert_php_objects_to_directive(*$input);
71 xmlDocPtr process_file(const char *input_filename, Directive *root_directive, bool clean);
72 void output_to_fd_and_free(xmlDocPtr doc, int fd);