@@ -51,11 +51,83 @@ macro_rules! _info_table_row {
5151///
5252/// # Parameters
5353///
54- /// * `$fn` - The 'function' to call. Can be an [`Arg`] or a [`Zval`].
55- /// * ...`$param` - The parameters to pass to the function. Must be able to be converted into a [`Zval`].
54+ /// * `$fn` - The 'function' to call. Can be an [Arg](crate::php::args::Arg) or a
55+ /// [Zval](crate::php::types::zval::Zval).
56+ /// * ...`$param` - The parameters to pass to the function. Must be able to be converted into a
57+ /// (crate::php::types::zval::Zval).
5658#[ macro_export]
5759macro_rules! call_user_func {
5860 ( $fn: expr, $( $param: expr) ,* ) => {
5961 $fn. try_call( vec![ $( $param. into( ) ) ,* ] )
6062 } ;
6163}
64+
65+ /// Parses a given list of arguments using the [ArgParser](crate::php::args::ArgParser) class.
66+ ///
67+ /// # Examples
68+ ///
69+ /// This example parses all of the arguments. If one is invalid, execution of the function will
70+ /// stop at the `parse_args!` macro invocation. The user is notified via PHP's argument parsing
71+ /// system.
72+ ///
73+ /// In this case, all of the arguments are required.
74+ ///
75+ /// ```
76+ /// # #[macro_use] extern crate ext_php_rs;
77+ /// use ext_php_rs::{
78+ /// parse_args,
79+ /// php::{args::Arg, enums::DataType, execution_data::ExecutionData, types::zval::Zval},
80+ /// };
81+ ///
82+ /// pub extern "C" fn example_fn(execute_data: &mut ExecutionData, _: &mut Zval) {
83+ /// let mut x = Arg::new("x", DataType::Long);
84+ /// let mut y = Arg::new("y", DataType::Long);
85+ /// let mut z = Arg::new("z", DataType::Long);
86+ ///
87+ /// parse_args!(execute_data, x, y, z);
88+ /// }
89+ /// ```
90+ ///
91+ /// This example is similar to the one above, apart from the fact that the `z` argument is not
92+ /// required. Note the semicolon seperating the first two arguments from the second.
93+ ///
94+ /// ```
95+ /// use ext_php_rs::{
96+ /// parse_args,
97+ /// php::{args::Arg, enums::DataType, execution_data::ExecutionData, types::zval::Zval},
98+ /// };
99+ ///
100+ /// pub extern "C" fn example_fn(execute_data: &mut ExecutionData, _: &mut Zval) {
101+ /// let mut x = Arg::new("x", DataType::Long);
102+ /// let mut y = Arg::new("y", DataType::Long);
103+ /// let mut z = Arg::new("z", DataType::Long);
104+ ///
105+ /// parse_args!(execute_data, x, y; z);
106+ /// }
107+ /// ```
108+ #[ macro_export]
109+ macro_rules! parse_args {
110+ ( $ed: expr, $( $arg: expr) ,* ) => { {
111+ use $crate:: php:: args:: ArgParser ;
112+
113+ let parser = ArgParser :: new( $ed)
114+ $( . arg( & mut $arg) ) *
115+ . parse( ) ;
116+ if parser. is_err( ) {
117+ return ;
118+ }
119+ } } ;
120+
121+ ( $ed: expr, $( $arg: expr) ,* ; $( $opt: expr) ,* ) => { {
122+ use $crate:: php:: args:: ArgParser ;
123+
124+ let parser = ArgParser :: new( $ed)
125+ $( . arg( & mut $arg) ) *
126+ . not_required( )
127+ $( . arg( & mut $opt) ) *
128+ . parse( ) ;
129+ if parser. is_err( ) {
130+ return ;
131+ }
132+ } } ;
133+ }
0 commit comments