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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/**
*
* An example file to show the working of using a C++ class in PHP.
*/
#include <string>
#include <iostream>
#include <phpcpp.h>
// Test includes
#include "include/ValueIterator.h"
#include "include/MyCustomClass.h"
#include "include/variables.h"
// Symbols are exported according to the "C" language
extern "C"
{
// export the "get_module" function that will be called by the Zend engine
PHPCPP_EXPORT void *get_module()
{
// create extension
static Php::Extension extension("extension_for_tests","0.1");
// build an interface
//Php::Interface interface("MyInterface");
// add methods to the interface
//interface.method("method1");
//interface.method("method2");
// add the interface to the extension
//extension.add(interface);
// we are going to define a class
Php::Class<TestBaseClass::MyCustomClass> customClass("TestBaseClass\\MyClass");
// add methods to it
customClass.method("myMethod", &TestBaseClass::MyCustomClass::myMethod, Php::Final, {});
customClass.property("property1", "prop1");
customClass.property("property2", "prop2", Php::Protected);
// add the class to the extension
extension.add(customClass);
/**
* tests for Iterators
*
*/
// add function to extension
//extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue/*, {
extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue);
extension.add("TestValueIterator\\loopArray", TestValueIterator::loopArray);
/**
* tests for variables
*
*/
extension.add("TestVariables\\process_globals", TestVariables::process_globals);
extension.add("TestVariables\\get_complex_array", TestVariables::get_complex_array);
extension.add("TestVariables\\value_types", TestVariables::value_types);
extension.add("TestVariables\\scalar_store", TestVariables::scalar_store);
extension.add("TestVariables\\value_casting", TestVariables::value_casting);
extension.add("TestVariables\\value_cast2double", TestVariables::value_cast2double);
extension.add("TestVariables\\value_cast2str", TestVariables::value_cast2str);
extension.add("TestVariables\\overloaded_op", TestVariables::overloaded_op);
extension.add("TestVariables\\value_arrays", TestVariables::value_arrays);
extension.add("TestVariables\\value_object1", TestVariables::value_object1);
extension.add("TestVariables\\value_object2", TestVariables::value_object2);
// A sample class, with methods to cast objects to scalars
Php::Class<TestVariables::Obj2Scalar> cObj2Scalar("Obj2Scalar");
extension.add(std::move(cObj2Scalar));
// return the extension module
return extension;
}
}
|