Skip to content

vs the PHP CGWebFramework ​

This starter is the Rust implementation of the PHP project: the browser's JavaScript, CSS and component HTML are the same files (brought over by the sync script), and the server-side protocol (endpoints, fields, error shapes, action names) is rewritten after the PHP version. If you already know the PHP version, most of that knowledge carries over; the differences are mostly "what PHP declares with attributes, Rust writes in code".

The whole picture ​

PHP versionRust starter
Back-end frameworkLaravelLaravel for Rust 0.1.4 (beta)
TemplatesBlade (@renderObject, @linker…)MiniJinja + Rust builders; runtime attributes produced by handlers
ComponentsDozens (Badge, Button, Modal, Table, Chart, FileDrop…)Badge, Button, Icon
Fragment allow listControllers using CanRenderCallSafelyNames registered with render::register("name", async fn)
Linker method allow list#[Computable]The METHODS constant
Argument validation#[Validate([...])]; undeclared keys are rejectedRead and validate them yourself in call; args is the whole map
Login#[RequiresAuth]; anonymous possibleAlways required (401 without a user)
Email verification#[RequiresVerified]Check in call, return LinkerResponse::policy(messages::UNVERIFIED)
Authorization#[Authorize('view', Model::class, arg: 'id')]user.authorize(Policy::view, &model).await?
Referer allow listallowsRefererUrls(): paths or route names; require_referer configurableALLOWS_REFERER_URLS: path patterns only; requests without a Referer are always allowed
Lifetimesconfig/linker.php + environment variablesConstants: 30 min idle, 90 s renewal, 8 h maximum, 0.8 s minimum interval
Instance lockConfigurable lease and waitFixed 60 s lease, 3 s wait
Caching method results#[Computable(cache: true)]None; use cache::remember yourself, and the key must include the user
Fragment fingerprintsxxh128SHA-256 (first 16 bytes); the browser only compares strings, so behavior is the same
Endpoint metaAbsolute URLsRelative paths; no difference for same-origin use
Pagination rebase, HTML minificationYesNo
dump() / dd() debug panelYesNo; use eprintln! or tracing
@renderInlineYesNo; call your render function in the handler and put the HTML in the template
Adding actionsmake:linker-action generates both PHP and JSAction::new("name", args) + register in JS; see Actions
CLI auditphp artisan linker:listNone; see the grep audits in Commands

What stays the same ​

  • The browser side is identical. The meaning of data-render-*, data-state-* and data-linker-*, state.js, linker.js and the JS implementations of the action table are the PHP project's own files.
  • The error kinds are the same. validation, policy, expired, conflict, service, fatal, with one handler in the browser.
  • The two modes are the same. Stateful (the server stores the instance, the browser has only uuid + rev) and Stateless (signed URLs).
  • The render token and fingerprint protocol is the same. One-time tokens, a pool of 16, unchanged when the content hasn't changed.
  • The endpoint prefix is derived the same way. HMAC-SHA256 of APP_KEY; PHP and Rust with the same key get the same prefix.

The same Linker written both ways ​

PHP:

php
#[RequiresAuth]
class CounterLinker extends LinkerComponent
{
    public static string $alias = 'counter';

    #[Computable]
    #[Validate(['step' => 'required|integer|between:1,100'])]
    public function setStep(array $args): LinkerResponse
    {
        $this->set('step', (int) $args['step']);

        return $this->ok(['step' => $this->get('step')]);
    }
}

Rust:

rust
#[derive(Default, Serialize, Deserialize)]
pub struct Counter {
    pub count: i64,
    pub step: i64,
}

impl LinkerComponent for Counter {
    const ALIAS: &'static str = "counter";
    const METHODS: &'static [&'static str] = &["increment", "reset", "setStep"];

    async fn call(&mut self, _: &LinkerContext, method: &str, args: Args) -> laravel::Result<LinkerResponse> {
        match method {
            "setStep" => {
                let step = args
                    .get("step")
                    .and_then(|v| v.as_str()?.parse::<i64>().ok().or(v.as_i64()));
                match step {
                    Some(step) if (1..=100).contains(&step) => self.step = step,
                    _ => return Ok(LinkerResponse::validation([("step", "The step must be an integer from 1 to 100.")])),
                }
            }
            // …
            _ => unreachable!("METHODS lists every method"),
        }
        Ok(LinkerResponse::ok().data("step", self.step))
    }
}

The differences:

  • State is the struct's fields (Serialize + Deserialize), not key-value pairs through $this->set().
  • METHODS replaces #[Computable]; methods not in the list are blocked before call, so the _ arm of the match can be unreachable!.
  • Validation is inside the method; on failure return LinkerResponse::validation with messages you write.

Which one ​

  • The team works mainly in PHP and needs the full component library → the PHP version.
  • The back end is already Rust, you need only a few components and are willing to port the missing ones → this starter.
  • Sharing screens between both: the same snapshots are the single source of truth for both, and the Rust parity tests tell you whether they match.