caremillc/caremi-pro-mvc

The skeleton application for the Caremi framework.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:project

pkg:composer/caremillc/caremi-pro-mvc

2.0.4 2025-10-05 17:00 UTC

This package is auto-updated.

Last update: 2025-10-06 16:56:14 UTC


README

The skeleton application for the Caremi-pro framework.

Its use and look is very similar to the Laravel framework.

The initial purpose of Caremi was to create a PHP framework and then make a course out of it and teach developers all around the world, how to create a PHP framework from scratch.

You can learn how this framework was create step by step from here.

Careminate Framework - Request Documentation

request.md - Full Guide

Careminate Framework – Request Guide

Overview

The Request class in Careminate provides a production-ready HTTP request abstraction. It normalizes PHP superglobals ($_GET, $_POST, $_SERVER, $_FILES, $_COOKIE) into a structured object, making it easy to interact with request data, headers, and HTTP methods.

Creating a Request

1. From Global Variables (Recommended)

use Careminate\Http\Requests\Request;

$request = Request::createFromGlobals();
  • Converts superglobals into a normalized object.
  • Parses raw input (JSON or form-encoded).
  • Handles HTTP method spoofing (_method parameter or X-HTTP-Method-Override header).

2. Manual Construction (Optional)

$request = new Request(
    $_GET,
    $_POST,
    file_get_contents('php://input'), // raw body
    $_COOKIE,
    $_FILES,
    $_SERVER,
    $inputParams, // parsed JSON or raw input array
    file_get_contents('php://input') // raw string
);

Accessing Request Data

1. Query Parameters (GET)

$name = $request->query('name', 'default');

2. POST Parameters

$email = $request->post('email');

3. Combined Input

$all = $request->all(); // merges GET, POST, and JSON body
$value = $request->input('key', 'default');

4. Helpers

$request->has('key');       // check if key exists
$request->only(['a','b']);  // get only specific keys
$request->except(['password']); // get all except some keys

Raw Input

$rawBody = $request->raw();       // raw body as string
$bodyParam = $request->input('param'); // parsed from JSON or form data

Files

$file = $request->file('avatar');
if ($request->hasFile('avatar')) {
    // process uploaded file
}
$allFiles = $request->allFiles(); // array of uploaded files

Cookies

$token = $request->cookie('session_token', null);

Headers

$userAgent = $request->header('User-Agent');
$accept = $request->header('Accept');
  • Normalizes $_SERVER headers (e.g., HTTP_ACCEPTAccept).

HTTP Method & Spoofing

$method = $request->getMethod(); // GET, POST, PUT, PATCH, DELETE
$request->isPost();   // true if POST
$request->isPut();    // true if PUT
$request->isAjax();   // true if XMLHttpRequest
  • Spoofed methods supported via:

    • _method form field
    • X-HTTP-Method-Override header

Path & URL

$path = $request->getPathInfo(); // e.g., /users/123
$url  = $request->fullUrl();     // full URL with host, scheme, path

User Info

$ip = $request->ip();           // Client IP
$ua = $request->userAgent();    // User-Agent string

JSON Requests

if ($request->isJson()) {
    $data = $request->json();  // decode JSON body into array
}

if ($request->wantsJson()) {
    // Accept header includes application/json
}

Validation

$request->validate([
    'name' => 'required|string',
    'age'  => 'required|numeric|min:18',
    'email'=> 'required|email',
]);
  • Throws a RuntimeException if validation fails.
  • Use $request->errors() to get an array of validation errors.

Old Input

$oldName = $request->old('name'); // Previously submitted input

Example Usage in a Controller

public function store(Request $request) {
    // Validate request
    $request->validate([
        'username' => 'required|string',
        'email'    => 'required|email',
    ]);

    // Access input
    $username = $request->input('username');
    $email = $request->input('email');

    // Access headers
    $ua = $request->userAgent();

    // Return response
    return response()->json(['status' => 'ok']);
}

request-quick-reference.md - Cheat Sheet

Create Request

$request = Request::createFromGlobals();
$request = new Request($_GET, $_POST, file_get_contents('php://input'), $_COOKIE, $_FILES, $_SERVER, $inputParams, file_get_contents('php://input'));

Input / Query

$request->all();
$request->input('key', $default);
$request->get('key', $default);
$request->query('key', $default);
$request->post('key', $default);
$request->only(['a','b']);
$request->except(['password']);
$request->has('key');

Cookies

$request->cookie('session_token', null);

Files

$request->file('avatar');
$request->hasFile('avatar');
$request->allFiles();

Headers

$request->header('User-Agent');
$request->headers();
$request->isAjax();
$request->wantsJson();

HTTP Method & Spoofing

$request->getMethod();
$request->isGet(); $request->isPost();
$request->isPut(); $request->isPatch(); $request->isDelete();
$request->isHead(); $request->isOptions();

Path & URL

$request->getPathInfo();
$request->fullUrl();

User Info

$request->ip();
$request->userAgent();

Raw / JSON Body

$request->raw();
$request->json();
$request->isJson();

Validation

$request->validate([...]);
$request->errors();

Old Input

$request->old('username');

Example Usage

if ($request->isPost() && $request->has('username')) {
    $username = $request->input('username');
    $email = $request->input('email');
    $ip = $request->ip();
}