michel/michel-package-starter
Composer 安装命令:
composer require michel/michel-package-starter
包简介
The core interface required for creating and integrating packages into the Michel framework.
README 文档
README
This package provides the core interfaces needed to create and integrate packages into the Michel Framework.
A Michel Package is a modular extension that hooks into the core application to register services, routes, commands, and listeners automatically.
Keep it simple, keep it clean!
1. Installation
Install the starter via Composer in your package's repository:
composer require michel/michel-package-starter
2. The Core: PackageInterface
Every package must have a main class that implements Michel\Package\PackageInterface. This is where you declare everything your package provides to the framework.
<?php
namespace MyCustomPackage;
use Michel\Package\PackageInterface;
final class MyPackage implements PackageInterface
{
public function getDefinitions(): array
{
// 1. Register services (Dependency Injection)
return [];
}
public function getParameters(): array
{
// 2. Provide default parameters
return [];
}
public function getRoutes(): array
{
// 3. Define manual routes
return [];
}
public function getControllerSources(): array
{
// 4. Register directories to scan for #[Route] attributes
return [__DIR__ . '/Controller'];
}
public function getCommandSources(): array
{
// 5. Register console commands
return [];
}
public function getListeners(): array
{
// 6. Register event listeners
return [];
}
}
3. Installation Hook (Optional): InstallablePackageInterface
If your package needs to perform setup tasks upon installation (like creating required directories, publishing assets, or configuring external resources), you should also implement the InstallablePackageInterface.
<?php
namespace MyCustomPackage;
use Michel\Package\InstallablePackageInterface;
use Michel\Package\PackageInterface;
use Psr\Container\ContainerInterface;
final class MyPackage implements PackageInterface, InstallablePackageInterface
{
// ... PackageInterface methods ...
public function install(ContainerInterface $container, ?callable $output = null): void
{
$sessionDir = $container->get('michel.project_dir') . '/var/session';
if (!is_dir($sessionDir)) {
mkdir($sessionDir, 0755, true);
if ($output) {
$output(' ✔ Created: /var/session');
}
} else {
if ($output) {
$output(' – Already exists: /var/session');
}
}
}
}
Note: The
install()method is triggered automatically by the framework when users runcomposer require,composer install, or manually viaphp bin/michel package:init. Always ensure your installation logic is idempotent (safe to execute multiple times).
4. Activation
To activate the package in a Michel project, the user simply adds it to their config/packages.php file, along with the environments where it should run:
<?php
// config/packages.php
return [
\MyCustomPackage\MyPackage::class => ['dev', 'prod'],
];
You are good to go!
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-15