phper/
macros.rs

1// Copyright (c) 2022 PHPER Framework Team
2// PHPER is licensed under Mulan PSL v2.
3// You can use this software according to the terms and conditions of the Mulan
4// PSL v2. You may obtain a copy of Mulan PSL v2 at:
5//          http://license.coscl.org.cn/MulanPSL2
6// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
7// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
8// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9// See the Mulan PSL v2 for more details.
10
11/// PHP echo.
12///
13/// # Examples
14///
15/// ```no_test
16/// phper::echo!("Hello, {}!", message)
17/// ```
18#[macro_export]
19macro_rules! echo {
20    ($($arg:tt)*) => ({
21        $crate::output::echo(std::format!($($arg)*))
22    })
23}
24
25/// PHP error logging, will exit the request.
26///
27/// # Examples
28///
29/// ```no_test
30/// phper::errro!("Hello, {}!", message)
31/// ```
32#[macro_export]
33macro_rules! error {
34    ($($arg:tt)*) => ({
35        $crate::output::log($crate::output::LogLevel::Error, std::format!($($arg)*))
36    })
37}
38
39/// PHP warning logging.
40///
41/// # Examples
42///
43/// ```no_test
44/// phper::warning!("Hello, {}!", message)
45/// ```
46#[macro_export]
47macro_rules! warning {
48    ($($arg:tt)*) => ({
49        $crate::output::log($crate::output::LogLevel::Warning, std::format!($($arg)*))
50    })
51}
52
53/// PHP notice logging.
54///
55/// # Examples
56///
57/// ```no_test
58/// phper::notice!("Hello, {}!", message)
59/// ```
60#[macro_export]
61macro_rules! notice {
62    ($($arg:tt)*) => ({
63        $crate::output::log($crate::output::LogLevel::Notice, std::format!($($arg)*))
64    })
65}
66
67/// PHP deprecated logging.
68///
69/// # Examples
70///
71/// ```no_test
72/// phper::deprecated!("Hello, {}!", message)
73/// ```
74#[macro_export]
75macro_rules! deprecated {
76    ($($arg:tt)*) => ({
77        $crate::output::log($crate::output::LogLevel::Deprecated, std::format!($($arg)*))
78    })
79}
80
81/// Equivalent to the php `CG`.
82#[macro_export]
83macro_rules! cg {
84    ($x:ident) => {
85        $crate::sys::compiler_globals.$x
86    };
87}
88
89/// Equivalent to the php `EG`.
90#[macro_export]
91macro_rules! eg {
92    ($x:ident) => {
93        $crate::sys::executor_globals.$x
94    };
95}
96
97/// Equivalent to the php `PG`.
98#[macro_export]
99macro_rules! pg {
100    ($x:ident) => {
101        $crate::sys::core_globals.$x
102    };
103}
104
105/// Equivalent to the php `SG`.
106#[macro_export]
107macro_rules! sg {
108    ($x:ident) => {
109        $crate::sys::sapi_globals.$x
110    };
111}