summaryrefslogtreecommitdiff
path: root/include/file.h
blob: 4fab1c59c662c45fdc01628224e664c85643d5cc (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
101
102
103
104
105
106
107
108
109
110
/**
 *  File.h
 *
 *  Extended script, a PHP source file name can be passed to a Php::File object
 *  to have it evaluated.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2014 Copernica BV
 */

/**
 *  Forward declarations
 */
struct _zend_string;

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Class definition
 */
class PHPCPP_EXPORT File
{
public:
    /**
     *  Constructor
     *
     *  The constructor receives a filename as parameter. It uses the normal
     *  PHP include path resolve algorithms to find the location of the file.
     *
     *  @param  name        the filename
     *  @param  size        size of the filename
     */
    File(const char *name, size_t size);

    /**
     *  Alternative constructor with just a filename
     *
     *  @param  name        the filename
     */
    File(const char *name) : File(name, ::strlen(name)) {}

    /**
     *  Alternative constructor with a string object
     *  @param  name        the filename
     */
    File(const std::string &name) : File(name.c_str(), name.size()) {}

    /**
     *  Alternative constructor with a Value object
     *  @param  name        the filename
     */
    File(const Value &value) : File(value.stringValue()) {}

    /**
     *  Destructor
     */
    virtual ~File();

    /**
     *  Does the file exist?
     *  @return boolean
     */
    bool exists();

    /**
     *  Is this a valid file?
     *  @return boolean
     */
    bool valid();

    /**
     *  Execute the file once (do nothing if the file already was executed)
     *  @return Php::Value
     */
    Value once();

    /**
     *  Execute the file
     *  @return Php::Value
     */
    Value execute();

private:
    /**
     *  The full resolved path name
     *  @var struct _zend_string*
     */
    struct _zend_string *_path = nullptr;

    /**
     *  The opcodes of this file
     *  @var std::unique_ptr<Opcodes>
     */
    std::unique_ptr<Opcodes> _opcodes;

    /**
     *  Compile the file
     *  @return bool
     */
    bool compile();

};

/**
 *  End of namespace
 */
}