Change to package to be a PHP-extention
This commit is contained in:
parent
e579bc5a66
commit
3697975728
1539
Cargo.lock
generated
1539
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -3,5 +3,12 @@ name = "parse"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
ext-php-rs = "*"
|
||||
nom = "7.*"
|
||||
|
||||
[profile.release]
|
||||
strip = "debuginfo"
|
||||
|
||||
47
src/lib.rs
Normal file
47
src/lib.rs
Normal file
@ -0,0 +1,47 @@
|
||||
#![cfg_attr(windows, feature(abi_vectorcall))]
|
||||
use ext_php_rs::prelude::*;
|
||||
use ext_php_rs::boxed::ZBox;
|
||||
use ext_php_rs::types::ZendObject;
|
||||
|
||||
mod model;
|
||||
mod parser;
|
||||
|
||||
#[php_class]
|
||||
#[php(name = "SamiAndAlex\\TrackerApp\\Parser")]
|
||||
struct Parser {
|
||||
}
|
||||
|
||||
#[php_impl]
|
||||
impl Parser {
|
||||
pub fn __construct() -> Self {
|
||||
Self {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_feed(&self, input: &str) -> PhpResult<Option<ZBox<ZendObject>>> {
|
||||
let (unparsed, fed) = crate::parser::parse_feed(input)
|
||||
.map_err(|e| format!("nom parsing failed: {}", e))?;
|
||||
if fed.formula.is_some() || fed.whole_milk.is_some() || fed.left.is_some() {
|
||||
let mut result = ZendObject::new_stdclass();
|
||||
result.set_property("unparsed", unparsed)?;
|
||||
if fed.formula.is_some() {
|
||||
result.set_property("formula", fed.formula.unwrap().volume)?;
|
||||
}
|
||||
if fed.whole_milk.is_some() {
|
||||
result.set_property("whole_milk", fed.whole_milk.unwrap().volume)?;
|
||||
}
|
||||
if fed.left.is_some() {
|
||||
result.set_property("left", fed.left.unwrap().volume)?;
|
||||
}
|
||||
Ok(Some(result))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[php_module]
|
||||
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
|
||||
module
|
||||
.class::<Parser>()
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user