Skip to content

Latest commit

 

History

History
308 lines (222 loc) · 6.77 KB

File metadata and controls

308 lines (222 loc) · 6.77 KB

AngeTools Framework

Framework PHP moderne inspiré de Laravel. À installer via Composer – les sites utilisent les fonctions du framework sans jamais le modifier directement.

Organisation

  • Le framework (ce dépôt) : code dans src/ installé dans vendor/angetools/framework
  • L'application : config, routes, vues dans le projet (skeleton fourni dans skeleton/)

Features

  • 🚀 Modern PHP 8.4+ - Built with the latest PHP features
  • 🎯 MVC Architecture - Clean separation of concerns
  • 🔒 Authentication & Authorization - Built-in auth system with role-based permissions
  • 📦 File System Abstraction - Multiple disk types (encrypted, versioned, cached)
  • 🛣️ Flexible Routing - RESTful routes with middleware support
  • Validation - Powerful validation system
  • 🎨 View System - Template engine with layouts
  • 🧪 Testing - PHPUnit integration
  • 🛠️ Artisan CLI - Command-line tools for development
  • 🏗️ Service Container - Dependency injection container
  • 🔌 Service Providers - Modular service registration
  • 📢 Event System - Event dispatcher for decoupled architecture
  • 📝 Logging - Advanced logging system with multiple levels
  • 🗄️ Query Builder - Fluent database query builder
  • 📊 Collections - Powerful array manipulation utilities
  • 💾 Cache Manager - Advanced caching system
  • 📄 Pagination - Built-in pagination support

Installation

composer require angetools/framework

Nouveau projet

  1. Créer le projet : copiez le contenu de skeleton/ à la racine de votre projet, ou exécutez :
cd mon-projet
php vendor/angetools/framework/bin/install-skeleton.php
  1. Configurer : copiez .env.example vers .env et configurez votre application.

  2. Démarrer : php artisan serve

Structure de l'application (skeleton)

mon-projet/
├── app/           # Votre code (controllers, models, etc.)
├── bootstrap/     # Bootstrap de l'application
├── config/        # Configuration
├── public/        # Point d'entrée HTTP
├── resources/     # Vues, assets
├── routes/        # Définition des routes
├── storage/       # Logs, cache, sessions
├── vendor/        # Composer (angetools/framework ici)
├── artisan
└── .env

Le framework dans vendor/ n'est jamais modifié. Toute personnalisation se fait via config, routes, vues de votre projet.

Quick Start

1. Bootstrap (déjà dans skeleton)

// bootstrap/app.php
$basePath = dirname(__DIR__);
require $basePath . '/vendor/autoload.php';

Application::setBasePath($basePath);
// ... providers, router, dispatch

2. Routes

// routes/web.php
Route::setRouter(app('router'));
Route::get('/', fn($r) => response('Accueil'), [], 'home');

3. Controllers

<?php
namespace App\Controllers;

use framework\Core\Controller;
use framework\Http\Request;
use framework\Http\Response;

class HomeController extends Controller {
    public function index(Request $request): Response {
        return new Response('Hello, World!');
    }
}

Artisan Commands

The framework includes a powerful CLI tool called Artisan:

php artisan list                    # List all available commands
php artisan make:controller Name    # Create a new controller
php artisan make:model Name         # Create a new model
php artisan make:middleware Name    # Create a new middleware
php artisan cache:clear             # Clear the application cache
php artisan config:cache            # Cache configuration files
php artisan phpunit                 # Run PHPUnit tests

Configuration

Configuration files are stored in the config/ directory. Each file returns an array of settings:

// config/app.php
return [
    'name' => 'My Application',
    'env' => 'production',
    'debug' => false,
];

Access configuration values:

use framework\Core\Config;

$config = new Config(__DIR__ . '/config');
$appName = $config->get('app.name');

File System

The framework provides a flexible file system abstraction:

use framework\FileSystem\Storage;

// Public disk
$public = Storage::disk('public');
$public->put('file.txt', 'content');

// Encrypted disk
$private = Storage::disk('private');
$private->put('secret.txt', 'sensitive data');

// Cached disk
$cache = Storage::disk('cache');
$cache->put('key', 'value');

Authentication

use framework\Auth\Auth;

// Check if user is authenticated
if (Auth::check()) {
    $user = Auth::user();
    $userId = Auth::id();
}

// Login
Auth::login($email, $password);

// Logout
Auth::logout();

Validation

use framework\Validation\Validator;

$validator = new Validator($data, [
    'email' => 'required|email',
    'age' => 'required|integer|min:18',
]);

if ($validator->passes()) {
    // Process valid data
} else {
    $errors = $validator->errors();
}

Advanced Features

Service Container

use framework\Core\Application;

// Bind a service
Application::bind('service', fn() => new MyService());

// Bind as singleton
Application::singleton('service', fn() => new MyService());

// Resolve
$service = Application::make('service');

Events

use framework\Events\EventDispatcher;

$dispatcher = new EventDispatcher();

// Listen to event
$dispatcher->listen('user.created', function($event, $user) {
    // Handle event
});

// Dispatch event
$dispatcher->dispatch('user.created', $user);

Collections

use framework\Support\Collection;

$collection = Collection::make([1, 2, 3, 4, 5]);

$filtered = $collection
    ->filter(fn($item) => $item > 2)
    ->map(fn($item) => $item * 2)
    ->values();

Query Builder

use framework\Database\DB;

$users = DB::table('users')
    ->where('active', '=', 1)
    ->where('age', '>', 18)
    ->orderBy('name', 'ASC')
    ->limit(10)
    ->get();

Pagination

use framework\Support\Paginator;

$paginator = Paginator::make($items, $total, $perPage, $currentPage);

$paginator->items(); // Get items
$paginator->currentPage(); // Current page
$paginator->hasMorePages(); // Check if has more
$paginator->nextPageUrl(); // Next page URL

Cache

// Get
$value = cache('key');

// Put
cache('key', 'value', 3600); // TTL in seconds

// Remember
$value = cache()->remember('key', fn() => expensiveOperation(), 3600);

Logging

logger()->info('User logged in', ['user_id' => 1]);
logger()->error('Something went wrong', ['error' => $exception]);

Testing

Run tests with PHPUnit:

php artisan phpunit
# or
composer test

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Author

Dumont-Julien - dumontj357@icloud.com