ext_php_rs/describe/
mod.rs

1//! Types used to describe downstream extensions. Used by the `cargo-php`
2//! CLI application to generate PHP stub files used by IDEs.
3
4pub mod abi;
5mod stub;
6
7use crate::flags::DataType;
8use abi::*;
9
10pub use stub::ToStub;
11
12#[repr(C)]
13pub struct Description {
14    /// Extension description.
15    pub module: Module,
16    /// ext-php-rs version.
17    pub version: &'static str,
18}
19
20impl Description {
21    /// Creates a new description.
22    ///
23    /// # Parameters
24    ///
25    /// * `module` - The extension module representation.
26    pub fn new(module: Module) -> Self {
27        Self {
28            module,
29            version: crate::VERSION,
30        }
31    }
32}
33
34/// Represents an extension containing a set of exports.
35#[repr(C)]
36pub struct Module {
37    pub name: Str,
38    pub functions: Vec<Function>,
39    pub classes: Vec<Class>,
40    pub constants: Vec<Constant>,
41}
42
43/// Represents a set of comments on an export.
44#[repr(C)]
45pub struct DocBlock(pub Vec<Str>);
46
47/// Represents an exported function.
48#[repr(C)]
49pub struct Function {
50    pub name: Str,
51    pub docs: DocBlock,
52    pub ret: Option<Retval>,
53    pub params: Vec<Parameter>,
54}
55
56/// Represents a parameter attached to an exported function or method.
57#[repr(C)]
58pub struct Parameter {
59    pub name: Str,
60    pub ty: Option<DataType>,
61    pub nullable: bool,
62    pub default: Option<Str>,
63}
64
65/// Represents an exported class.
66#[repr(C)]
67pub struct Class {
68    pub name: Str,
69    pub docs: DocBlock,
70    pub extends: Option<Str>,
71    pub implements: Vec<Str>,
72    pub properties: Vec<Property>,
73    pub methods: Vec<Method>,
74    pub constants: Vec<Constant>,
75}
76
77/// Represents a property attached to an exported class.
78#[repr(C)]
79pub struct Property {
80    pub name: Str,
81    pub docs: DocBlock,
82    pub ty: Option<DataType>,
83    pub vis: Visibility,
84    pub static_: bool,
85    pub nullable: bool,
86    pub default: Option<Str>,
87}
88
89/// Represents a method attached to an exported class.
90#[repr(C)]
91pub struct Method {
92    pub name: Str,
93    pub docs: DocBlock,
94    pub ty: MethodType,
95    pub params: Vec<Parameter>,
96    pub retval: Option<Retval>,
97    pub _static: bool,
98    pub visibility: Visibility,
99}
100
101/// Represents a value returned from a function or method.
102#[repr(C)]
103pub struct Retval {
104    pub ty: DataType,
105    pub nullable: bool,
106}
107
108/// Enumerator used to differentiate between methods.
109#[repr(C)]
110#[derive(Clone, Copy)]
111pub enum MethodType {
112    Member,
113    Static,
114    Constructor,
115}
116
117/// Enumerator used to differentiate between different method and property
118/// visibilties.
119#[repr(C)]
120#[derive(Clone, Copy)]
121pub enum Visibility {
122    Private,
123    Protected,
124    Public,
125}
126
127/// Represents an exported constant, stand alone or attached to a class.
128#[repr(C)]
129pub struct Constant {
130    pub name: Str,
131    pub docs: DocBlock,
132    pub value: Option<Str>,
133}