summaryrefslogtreecommitdiff
path: root/scripts/ext_skel_ng/php_resource.php
blob: 92949da5417049fb720eb2156f95176c721d8360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

	class php_resource extends php_element {
		function php_resource($name, $payload, $destruct, $description) {
			$this->name = $name;
			$this->payload = $payload;
			$this->destruct = $destruct;
			$this->description = $description;

			if (empty($this->destruct) && strstr($this->payload, "*")) {
				$this->destruct = "  free(resource);\n";
			}

			if(empty($this->payload)) {
				$this->payload = "int";
			}
		} 
		
		function docbook_xml($base) {
			return "
    <section id='$base.resources.{$this->name}'>
     <title><literal>{$this->name}</literal></title>
     <para>
      {$this->description}
     </para>
    </section>
";
		}

		function minit_code() {
			return "
le_{$this->name} = zend_register_list_destructors_ex({$this->name}_dtor, 
                                                     NULL, 
                                                     \"{$this->name}\", 
                                                     module_number);

";
		}

		function c_code() {
			return "
int le_{$this->name};

void {$this->name}_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
  {$this->payload} resource = ({$this->payload})(rsrc->ptr);

  {$this->destruct}
}
";
		}

		function h_code() {
      $upname = strtoupper($this->name);

			return "
#define {$upname}_FETCH(r, z)   ZEND_FETCH_RESOURCE(r, {$this->payload}, z, -1, ${$this->name}, le_{$this->name }); \
                                    if(!r) { RETURN_FALSE; }

#define {$upname}_REGISTER(r)   ZEND_REGISTER_RESOURCE(return_value, r, le_{$this->name });
";
		}
	}

?>