blob: c33289827c47f5aaf191bd807002a23f7152dc3a (
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
|
/**
* Eval.cpp
*
* This file holds the implementation for the Php::eval() function
*
* @author andot <https://github.com/andot>
*/
/**
* Dependencies
*/
#include "includes.h"
/**
* Open PHP namespace
*/
namespace Php {
/**
* Evaluate a PHP string
* @param phpCode The PHP code to evaluate
* @return Value The result of the evaluation
*/
Value eval(const std::string &phpCode)
{
// we have a script for this
return Script(phpCode).execute();
}
/**
* Include a file
* @param filename
* @return Value
*/
Value include(const std::string &filename)
{
// we can simply execute a file
return File(filename).execute();
}
/**
* Include a file only once
* @param filename
* @return Value
*/
Value include_once(const std::string &filename)
{
// we can simply execute a file
return File(filename).once();
}
/**
* Require a file
* This causes a fatal error if the file does not exist
* @param filename
* @return Value
*/
Value require(const std::string &filename)
{
// create the file
File file(filename);
// execute if it exists
if (file.exists()) return file.execute();
// trigger fatal error
error << filename << " does not exist" << std::flush;
// unreachable
return nullptr;
}
/**
* Require a file only once
* This causes a fatal error if the file does not exist
* @param filename
* @return Value
*/
Value require_once(const std::string &filename)
{
// create the file
File file(filename);
// execute if it exists
if (file.exists()) return file.once();
// trigger fatal error
error << filename << " does not exist" << std::flush;
// unreachable
return nullptr;
}
/**
* End of namespace
*/
}
|