### Initialize Fleact Project Source: https://context7.com/flightphp/fleact/llms.txt Commands to bootstrap a new Fleact project using Composer, degit, or Git. These commands install necessary dependencies and start the development server. ```bash # Using Composer (recommended) composer create-project flightphp/fleact my-app cd my-app npm install composer install npm run dev # Using degit npx degit flightphp/fleact my-app cd my-app npm install composer install npm run dev # Using Git git clone https://github.com/flightphp/fleact my-app cd my-app npm install composer install npm run dev ``` -------------------------------- ### GET /api/versions - Get Framework Versions Source: https://context7.com/flightphp/fleact/llms.txt Retrieves the current versions of FlightPHP and React used in the project by reading from composer.json and package.json. ```APIDOC ## GET /api/versions ### Description Retrieves the current versions of FlightPHP and React used in the project by reading from composer.json and package.json files. ### Method GET ### Endpoint /api/versions ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash curl http://localhost:8000/api/versions ``` ### Response #### Success Response (200) - **Array** (array) - An array containing the FlightPHP version and the React version. #### Response Example ```json ["^3.15", "^19.0.0"] ``` ``` -------------------------------- ### Initialize FlightPHP Application Source: https://context7.com/flightphp/fleact/llms.txt This PHP script serves as the main entry point for the FlightPHP application. It sets the path for views and includes all route files before starting the application. It requires the Composer autoloader for dependency management. ```php // app/index.php 1, 'name' => 'John Doe'], ['id' => 2, 'name' => 'Jane Smith'] ]; Flight::json($users); }); // POST endpoint with request data Flight::route('POST /api/users', function (): void { $data = Flight::request()->data; // Validate and save user $newUser = [ 'id' => uniqid(), 'name' => $data->name, 'email' => $data->email ]; Flight::json($newUser, 201); }); // Route with URL parameters Flight::route('GET /api/users/@id', function (string $id): void { Flight::json(['id' => $id, 'name' => 'User ' . $id]); }); ``` -------------------------------- ### GET /api/users Source: https://context7.com/flightphp/fleact/llms.txt Retrieves a list of all users from the system. ```APIDOC ## GET /api/users ### Description Returns a JSON array containing all registered users. ### Method GET ### Endpoint /api/users ### Response #### Success Response (200) - **users** (array) - List of user objects #### Response Example [ {"id": 1, "name": "John Doe"}, {"id": 2, "name": "Jane Smith"} ] ``` -------------------------------- ### GET /api/users/@id Source: https://context7.com/flightphp/fleact/llms.txt Retrieves details for a specific user by ID. ```APIDOC ## GET /api/users/@id ### Description Fetches a single user record based on the provided ID parameter. ### Method GET ### Endpoint /api/users/@id ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the user ### Response #### Success Response (200) - **id** (string) - The ID of the user - **name** (string) - The name of the user #### Response Example { "id": "1", "name": "User 1" } ``` -------------------------------- ### GET /api/auth - Check Authentication Status Source: https://context7.com/flightphp/fleact/llms.txt Checks the current user's authentication status and email from the PHP session. This endpoint is typically called by the React frontend. ```APIDOC ## GET /api/auth ### Description Checks the current user's authentication status and email from the PHP session. This endpoint is called by the React frontend to determine if a user is logged in. ### Method GET ### Endpoint /api/auth ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash curl http://localhost:8000/api/auth ``` ### Response #### Success Response (200) - **Object** - An object containing the authentication status and user email. - **isLogged** (boolean) - Indicates if the user is logged in. - **email** (string|null) - The email of the logged-in user, or null if not logged in. #### Response Example ```json // Not logged in {"isLogged":false,"email":null} // Logged in {"isLogged":true,"email":"user@example.com"} ``` ``` -------------------------------- ### GET /logout - User Logout Source: https://context7.com/flightphp/fleact/llms.txt Clears the user session data and redirects back to the previous page. This endpoint removes authentication tokens from the session. ```APIDOC ## GET /logout ### Description Clears the user session data and redirects back to the previous page. This endpoint removes authentication tokens from the session. ### Method GET ### Endpoint /logout ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash curl http://localhost:8000/logout ``` ### Response #### Success Response (302 Redirect) Redirects to the referrer page. #### Response Example ``` 302 Redirect to referrer ``` ``` -------------------------------- ### POST /login - User Login Source: https://context7.com/flightphp/fleact/llms.txt Handles user login by accepting email and password, storing credentials in the PHP session, and redirecting to the home page. ```APIDOC ## POST /login ### Description Handles user login by storing credentials in the PHP session. The route accepts form data with email and password fields, then redirects to the home page. ### Method POST ### Endpoint /login ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **email** (string) - Required - The user's email address. - **password** (string) - Required - The user's password. ### Request Example ```bash curl -X POST http://localhost:8000/login \ -d "email=user@example.com" \ -d "password=secret123" ``` ### Response #### Success Response (302 Redirect) Redirects to the home page ('/'). #### Response Example ``` 302 Redirect to / ``` ``` -------------------------------- ### Handle User Login Source: https://context7.com/flightphp/fleact/llms.txt A POST route that processes login credentials and initializes a PHP session. Upon success, it redirects the user to the home page. ```php Flight::route('POST /login', function (): void { // TODO: verify credentials if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } $_SESSION['auth.user.id'] = uniqid('USER_'); $_SESSION['auth.user.email'] = Flight::request()->data->email; Flight::redirect('/'); }); ``` ```bash curl -X POST http://localhost:8000/login \ -d "email=user@example.com" \ -d "password=secret123" ``` -------------------------------- ### POST /api/users Source: https://context7.com/flightphp/fleact/llms.txt Creates a new user in the system. ```APIDOC ## POST /api/users ### Description Accepts user data to create a new user record. ### Method POST ### Endpoint /api/users ### Request Body - **name** (string) - Required - The name of the user - **email** (string) - Required - The email address of the user ### Request Example { "name": "Alice", "email": "alice@example.com" } ### Response #### Success Response (201) - **id** (string) - The unique ID of the created user - **name** (string) - The name of the created user - **email** (string) - The email of the created user #### Response Example { "id": "64f1a2b3c4d5e", "name": "Alice", "email": "alice@example.com" } ``` -------------------------------- ### Esbuild Configuration - Build System Source: https://context7.com/flightphp/fleact/llms.txt Configuration script for esbuild that handles bundling, CSS modules, and asset copying. It also automates environment variable parsing and generates TypeScript declarations. ```javascript import { readFileSync, existsSync, copyFileSync, writeFileSync } from 'node:fs' import { parse } from 'dotenv' /** @type {import('esbuild').BuildOptions} */ export const commonOptions = { bundle: true, entryPoints: ['src/index.tsx'], format: 'esm', jsx: 'automatic', loader: { '.module.css': 'local-css', '.ttf': 'copy', '.woff': 'copy', '.woff2': 'copy', '.svg': 'dataurl' }, outfile: 'app/build/bundle.js', target: ['es2018'], conditions: ['main'] } if (!existsSync('.env')) { copyFileSync('.env.dist', '.env') } const env = parse(readFileSync('.env')) let declarations = '' for (const variable in env) { env[variable] = `"${env[variable]}"` declarations += `declare const ${variable}: string\n` } writeFileSync('src/env.d.ts', declarations) export { env } ``` -------------------------------- ### Retrieve Framework Versions API Source: https://context7.com/flightphp/fleact/llms.txt An API endpoint that reads composer.json and package.json to return the current versions of FlightPHP and React. It demonstrates how to access project configuration files from the backend. ```php Flight::route('/api/versions', function (): void { $composerJson = json_decode(file_get_contents(ROOT . '/composer.json'), true); $packageJson = json_decode(file_get_contents(ROOT . '/package.json'), true); echo json_encode([ $composerJson['require']['flightphp/core'], $packageJson['devDependencies']['react'] ]); }); ``` ```bash curl http://localhost:8000/api/versions ``` -------------------------------- ### Create Production Build with esbuild Minification Source: https://context7.com/flightphp/fleact/llms.txt This script builds minified production-ready bundles using esbuild. It disables source maps and sets the 'isDevelopment' environment variable to 'false'. It utilizes common esbuild configurations and environment variables from './config.mjs'. ```javascript // scripts/build.mjs import esbuild from 'esbuild' import { commonOptions, env } from './config.mjs' await esbuild.build({ ...commonOptions, define: { ...env, isDevelopment: 'false' }, minify: true }) console.info('Compiled successfully') ``` -------------------------------- ### Run Development Server with esbuild Watch Mode Source: https://context7.com/flightphp/fleact/llms.txt This script uses esbuild to run a development server in watch mode. It enables source maps for easier debugging and sets the 'isDevelopment' environment variable to 'true'. It relies on common esbuild configurations and environment variables defined in './config.mjs'. ```javascript // scripts/dev.mjs import esbuild from 'esbuild' import { commonOptions, env } from './config.mjs' const context = await esbuild.context({ ...commonOptions, define: { ...env, isDevelopment: 'true' }, sourcemap: 'external' }) await context.watch() console.info('Compiled successfully...') console.info('Watching files...') ``` -------------------------------- ### Load FlightPHP Route Files Source: https://context7.com/flightphp/fleact/llms.txt This PHP script automatically loads all route files from the 'src/routes' directory that are prefixed with an underscore. This allows for modular route definition. ```php // src/routes/index.php {loggedUser.isLogged &&
Visit the FlightPHP tutorial to learn how to build FlightPHP APIs.
Visit the React docs to learn how to build React apps.
> ) } ``` -------------------------------- ### Base HTML Layout for React Application Source: https://context7.com/flightphp/fleact/llms.txt This HTML template serves as the base layout for the React application. It includes meta tags, title, favicon, CSS, and the bundled JavaScript file. It dynamically sets the base URL to handle subdirectory deployments correctly. ```html