codemonster-ru/annabel
最新稳定版本:v1.14.1
Composer 安装命令:
composer require codemonster-ru/annabel
包简介
Elegant and lightweight PHP framework for modern web applications
README 文档
README
Elegant and lightweight PHP framework for modern web applications.
Installation
composer require codemonster-ru/annabel
Quick Start
// public/index.php require __DIR__ . '/../vendor/autoload.php'; $app = require __DIR__ . '/../bootstrap/app.php'; $app->run(); // bootstrap/app.php use Codemonster\Annabel\Application; $baseDir = __DIR__ . '/..'; $app = new Application($baseDir); require "$baseDir/routes/web.php"; return $app; // routes/web.php router()->get('/', fn() => view('home', ['title' => 'Welcome to Annabel']));
CLI
Annabel ships with a lightweight CLI similar to Laravel's artisan. It already supports:
about- show version, base path, and loaded providersroute:list- list registered routesconfig:get key- read a config valuecontainer:list- show container bindings/instancesserve- run PHP built-in server (default 127.0.0.1:8000)- With
codemonster-ru/databaseinstalled:make:migration,migrate,migrate:rollback,migrate:status,make:seed,seed(appear inannabel list; connection is checked when commands run)
php vendor/bin/annabel php vendor/bin/annabel help php vendor/bin/annabel help list
Database Integration
Annabel ships with first-class integration for
codemonster-ru/database.
1. Create config/database.php
return [ 'default' => 'mysql', 'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => 3306, 'database' => env('DB_NAME'), 'username' => env('DB_USER'), 'password' => env('DB_PASS'), 'charset' => 'utf8mb4', ], 'sqlite' => [ 'driver' => 'sqlite', 'database' => base_path('database/database.sqlite'), ], ], ];
2. Usage
// Query builder $users = db()->table('users')->where('active', 1)->get(); // Schema builder schema()->create('posts', function ($table) { $table->id(); $table->string('title'); }); // Transactions transaction(function () { db()->table('logs')->insert(['type' => 'created']); });
Helpers
| Function | Description |
|---|---|
app() |
Access the application container |
base_path() |
Resolve base project paths |
config() |
Get or set configuration values |
env() |
Read environment variables |
dump() / dd() |
Debugging utilities |
request() |
Get current HTTP request |
response() / json() |
Create HTTP response |
router() / route() |
Access router instance |
view() |
Render or return view instance |
session() |
Access session store |
db() |
Get the active database connection |
schema() |
Get the schema builder |
transaction() |
Execute a DB transaction |
All helpers are autoloaded automatically.
Container parameters
You can pass named constructor parameters when resolving classes or closure bindings:
$user = app(User::class, ['name' => 'Annabel']); app()->bind(User::class, fn($container, array $params) => new User($params['name'])); $user = app(User::class, ['name' => 'Annabel']); // Same for Application::make() $user = $app->make(User::class, ['name' => 'Annabel']);
Note: for singleton bindings, passing parameters after the instance is resolved throws an exception.
Note: Application::serve() will throw if an instance already exists; call Application::resetInstance() first.
Testing
composer test
Author
License
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-12