leongrdic/smplang
SMPLang is a small PHP language/parser package for defining and evaluating simple expressions in your app. Useful for lightweight DSLs, rules, filters, or templating-like syntax, with an emphasis on minimal setup and easy integration into Laravel projects.
eval() for user-provided input (e.g., admin-defined formulas, plugin scripts) with a safer, constrained alternative to mitigate security risks (e.g., arbitrary code execution).if-else logic in legacy PHP with maintainable expressions.Adopt if:
user.score > 100 && user.is_premium).eval() for untrusted input (though validate inputs rigorously—this is not a security silver bullet).Look Elsewhere if:
"This package lets us embed simple, safe ‘mini-programs’ into our product—like letting admins define rules for discounts ('price * 0.9') or workflows ('user.tier == 'gold')—without writing code. It’s like a lightweight ‘if-then’ editor for power users. Since it avoids eval(), it’s safer than letting users run arbitrary PHP, and it’s ready to ship now (last updated 2022). The trade-off? We’re limited to basic math/logic, but that covers 80% of our dynamic rule needs. For complex cases, we’d build a custom solution later."
ROI:
eval() risks for untrusted input.*"This is a minimalist expression evaluator for PHP 8.0+, designed to replace eval() for simple cases. Key pros:
eval(): Uses a parser to avoid arbitrary code execution (though still validate inputs!).Use Cases:
user.orders > 5 ? 'vip' : 'standard').concat(user.name, ' (', user.id, ')')).if-else with expressions (e.g., max(0, user.balance - order.amount)).Limitations:
Alternatives to Compare:
Proposal: Start with this for MVP dynamic rules. If we hit limits (e.g., need loops), we can migrate to Symfony’s component later. For now, it’s a low-risk, high-reward way to add flexibility without security debt."*
How can I help you explore Laravel packages today?