PHP code example of gemvc / framework

1. Go to this page and download the library: Download gemvc/framework library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gemvc / framework example snippets


// Clean layered architecture
Frontend Request
    → Service (Authentication & Validation)
        → Controller (Business Logic)
            → Model (Data Logic & Response)
                → Table (Database Operations)

class ClassroomModel extends ClassroomTable {
    /** @var array<PlannedTeacherModel> */
    public array $_classroom_teachers;
    
    public function getWithTeachers(): self {
        $classroom = $this->findOrFail($this->id);
        $classroom->_classroom_teachers = (new PlannedTeacherModel())
            ->byClassroom($classroom->id);
        return $classroom;
    }
}

class UserModel extends UserTable {
    // Database columns
    public int $id;
    public string $name;
    
    // Non-database properties (note the underscore)
    /** @var array<RoleModel> */
    public array $_roles;
}

class UserService extends AuthService {
    public function create(): JsonResponse {
        $this->auth->authorize(['admin']);
        $this->validatePosts(['name' => 'string']);
        return (new UserController($this->request))->create();
    }
}

// From complex, error-prone code...
$stmt = $pdo->prepare("SELECT u.id, u.name FROM users WHERE status = ?");
$stmt->execute(['active']);

// To elegant, secure simplicity! 😍
$users = QueryBuilder::select('u.id', 'u.name')
    ->from('users')
    ->whereEqual('status', 'active')
    ->run($pdoQuery);

// Automatic protection against:
// ✓ SQL Injection
// ✓ XSS Attacks
// ✓ Path Traversal
// ✓ Shell Injection
// ✓ File Upload Vulnerabilities

// Military-grade file encryption in just 3 lines!
$file = new FileHelper($_FILES['upload']['tmp_name'], 'secure/file.dat');
$file->secret = $encryptionKey;
$file->moveAndEncrypt();  // AES-256-CBC + HMAC verification 🔐

// Modern image processing in one line
$image = new ImageHelper($uploadedFile)->convertToWebP(80);

// Clean API responses
$response = new JsonResponse()->success($data)->show();

// Type-safe database queries
QueryBuilder::select('id', 'name')
    ->from('users')
    ->whereEqual('status', 'active')
    ->limit(10)
    ->run($pdoQuery);

// index.php
load(__DIR__.'/app/.env');
$webserver = new ApacheRequest();
$bootstrap = new Bootstrap($webserver->request);

// Create an API endpoint
class Classroom extends APIService {
   public function __construct(Request $request)
    {
        parent::__construct($request);
    }
    public function create(): JsonResponse
    {
        $this->auth->authorize(['company-admin']);
        $this->validatePostWithCompany(['name'=>'string','course_id'=>'int','subject_id'=>'int','start_date'=>'date','end_date'=>'date','?  location'=>'string','?description'=>'string']);
        return (new ClassroomController($this->request))->create();
    }
}

// index.php
ore\Bootstrap;
use Gemvc\Http\ApacheRequest;
use Gemvc\Http\NoCors;
use Symfony\Component\Dotenv\Dotenv;

// Configure CORS
NoCors::NoCors();

// Load environment configuration
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/app/.env');

// Initialize framework
$webserver = new ApacheRequest();
$bootstrap = new Bootstrap($webserver->request);