Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Smplang Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Dynamic Rule Engines: Build a lightweight, customizable rule evaluation system for business logic (e.g., pricing tiers, eligibility checks, or workflow triggers) without exposing users to raw PHP.
  • Low-Code/No-Code Extensions: Enable non-technical users to define simple expressions (e.g., for validation, filtering, or conditional UI logic) via a controlled DSL (Domain-Specific Language) instead of hardcoding PHP.
  • Sandboxed Evaluation: Replace 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).
  • Roadmap Trade-offs: Buy vs. Build – Justify adopting this package over building a custom parser/compiler for simple expressions, especially if the team lacks expertise in language design or parsing libraries.
  • Use Cases:
    • Internal Tools: Dynamic configuration for CLI tools or admin dashboards (e.g., "If X > 10, trigger Y").
    • APIs/Microservices: Runtime expression evaluation for feature flags, A/B testing rules, or dynamic response transformations.
    • Legacy System Modernization: Replace hardcoded if-else logic in legacy PHP with maintainable expressions.

When to Consider This Package

  • Adopt if:

    • Your use case requires simple arithmetic, comparisons, or basic object property access (e.g., user.score > 100 && user.is_premium).
    • You need a safer alternative to eval() for untrusted input (though validate inputs rigorously—this is not a security silver bullet).
    • Your team lacks resources to build/maintain a full-fledged expression parser (e.g., no budget for libraries like PHP-Parser or Laravel’s Expression Builder).
    • You’re targeting PHP 8.0+ and can tolerate the package’s niche feature set (e.g., no loops, limited control flow).
  • Look Elsewhere if:

    • You need complex logic (loops, functions, custom operators, or recursive expressions). Consider:
    • Security is critical: This package is minimal and lacks sandboxing features like PHP-Sandbox. Use only for trusted input or pair with additional validation.
    • You require performance-critical evaluation (this is a pure-PHP interpreter, not compiled bytecode).
    • Your expressions need custom functions or namespace support (limited in this package).

How to Pitch It (Stakeholders)

For Executives:

"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:

  • Speed: Ship dynamic features faster (no parser dev work).
  • Safety: Reduce eval() risks for untrusted input.
  • Cost: Free (MIT license), low maintenance.

For Engineering:

*"This is a minimalist expression evaluator for PHP 8.0+, designed to replace eval() for simple cases. Key pros:

  • No eval(): Uses a parser to avoid arbitrary code execution (though still validate inputs!).
  • Lightweight: ~100 LOC, no dependencies (except PHP 8.0+).
  • Laravel-friendly: Works standalone or with Laravel’s service container.

Use Cases:

  1. Admin-defined rules: Let non-devs configure logic (e.g., user.orders > 5 ? 'vip' : 'standard').
  2. API response tweaks: Dynamically modify JSON outputs (e.g., concat(user.name, ' (', user.id, ')')).
  3. Legacy cleanup: Replace nested if-else with expressions (e.g., max(0, user.balance - order.amount)).

Limitations:

  • No loops/functions: Only basic arithmetic, comparisons, and object property access.
  • No sandboxing: Treat input as semi-trusted (validate rigorously).
  • PHP 8.0+ only: Won’t work on older stacks.

Alternatives to Compare:

  • Laravel Expressions: More powerful but heavier (for Laravel apps).
  • Symfony ExpressionLanguage: Enterprise-grade but overkill for simple cases.
  • Custom Parser: Only worth it if you need loops/functions.

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."*

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views