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) {
13 if (!zend_hash_index_exists(ht, i)) {
20 Directive* convert_php_objects_to_directive(zval *obj)
22 switch (Z_TYPE_P(obj)) {
24 HashTable *ht = Z_ARRVAL_P(obj);
25 if (is_associative_array(ht)) {
26 std::unordered_map<std::string, Directive *> my_map;
27 for (zend_hash_internal_pointer_reset(ht); zend_hash_has_more_elements(ht) == SUCCESS; zend_hash_move_forward(ht)) {
30 zend_hash_get_current_key(ht, &str_key, &num_key, 0);
33 if (zend_hash_get_current_key_type(ht) == HASH_KEY_IS_STRING) {
37 sprintf(buf, "%lu", num_key);
42 zend_hash_get_current_data(ht, (void **)&data);
43 my_map.insert(make_pair(key, convert_php_objects_to_directive(*data)));
45 return new Substitute(my_map);
52 char *str = Z_STRVAL_P(obj);
53 return new Replace(str);
56 printf("WARNING: Unknown type %d!\n", Z_TYPE_P(obj));
65 %typemap(in) Directive* {
66 $1 = convert_php_objects_to_directive(*$input);
69 xmlDocPtr process_file(const char *input_filename, Directive *root_directive, bool clean);
70 void output_to_fd_and_free(xmlDocPtr doc, int fd);