Server Functions, Exposed Securely
Call PHP functions from your frontend as if they were local JavaScript functions.
Protected by the #[Exposed] attribute.
Attribute Security
Functions are private by default. You must explicitly opt-in using PHP 8 Attributes to expose them to the client.
Built-in Auth Checks
Stop writing if (!$user) return;. Just add requiresAuth: true and the framework handles the guard.
Role Based Access
Granular control. Restrict execution to specific roles like ['admin', 'editor'] directly in the function signature.
Security & Authentication
Control who can access your backend logic using PHP Attributes.
use PP\Attributes\Exposed; // Only logged in users can call this #[Exposed(requiresAuth: true)] function getUserProfile() { return Auth::user(); }
use PP\Attributes\Exposed; // Implies requiresAuth: true #[Exposed(allowedRoles: ['admin', 'editor'])] function deletePost($args) { // Safe to perform admin action Post::delete($args->id); }
requiresAuth fails.
Data Flow Example
<?php use PP\Attributes\Exposed; #[Exposed] function updateUser($data) { // $data is an object automatically $email = $data->email; return [ 'success' => true, 'msg' => "Updated $email" ]; } ?>
<script> async function save() { const res = await pp.fetchFunction( 'updateUser', { email: 'john@doe.com' } ); if (res.success) { console.log(res.msg); } } </script>
Client API Reference
fetchFunction<T = any>( functionName: string, data: Record<string, any> = {}, abortPrevious: boolean = false ): Promise<T | string>
-
functionNameThe exact name of the PHP function. Support namespaces for static methods (e.g.,User::update). -
dataObject containing arguments. Supports nested objects, arrays, andFileobjects (automatically handled as multipart/form-data). -
abortPreviousBoolean. Iftrue, cancels any pending requests from this caller. Perfect for search inputs or filters to prevent race conditions.
Zero-Config File Uploads
Prisma detects File objects in your payload and automatically switches the content-type. No need for FormData construction.
Auto-Response Parsing
PHP arrays are automatically converted to JSON objects on the frontend. Strings and booleans are preserved.