summaryrefslogtreecommitdiff
path: root/tests/simple/simple.cpp
blob: 39e615a1a79e99ac3128c1556c1f7d0d2cb08bd2 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
 *  Simple.h
 *
 *  A very simple extension that does almost nothing
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */
#include <string>
#include <iostream>
#include <phpcpp.h>

/**
 *  Namespace to use
 */
using namespace std;

/**
 *  Our own "my_plus" function that will be available in PHP
 *  @param  environment
 *  @param  params
 *  @return Value
 */
static Php::Value my_plus(Php::Environment &env, Php::Parameters &params)
{
    string p1 = params[0];
    string p2 = params[1];
    
    cout << "global g1: " << env["g1"].stringValue() << endl;
    cout << "global g2: " << env["g2"].stringValue() << endl;
    
    Php::Global g(env["g3"]);
    
    g = "zo kan het ook";
    
    string output = env.call("strtoupper","test in lowercase");
    
    cout << "output: " << output << endl;
    
    return p1 + p2;
}

/**
 *  Custom class that will be available in PHP
 */
class MyCustomClass : public Php::Base
{
private:
    int _x;
    
public:
    MyCustomClass()
    {
    }
    
    virtual void __construct()
    {
        
    }

    virtual void __destruct()
    {
        
        
    }
    
    void myMethod(Php::Parameters &params)
    {
        
        
    }


};

// 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("simple","1.0");

        // define the functionsnm 
        extension.add("my_plus", my_plus, {
			Php::ByVal("a", Php::stringType),
			Php::ByVal("b", Php::arrayType),
			Php::ByVal("c", "MyClass"),
			Php::ByRef("d", Php::stringType)
		});
		
        // define classes
        extension.add("my_class", Php::Class<MyCustomClass>());
        
        // return the module entry
        return extension.module();
    }
}