Packages and Extending
A NaluzPHP package is an ordinary Composer package. To be picked up automatically after composer require, list your
service providers in its composer.json:
{ "name": "acme/blog", "require": { "naluz/framework": "^1.2.2" }, "autoload": { "psr-4": { "Acme\\Blog\\": "src/" } }, "extra": { "naluz": { "providers": ["Acme\\Blog\\BlogServiceProvider"] } }}final class BlogServiceProvider extends Naluz\Foundation\ServiceProvider{ public function register(): void { $this->app->singleton(Blog::class, fn ($c) => new Blog($c->make(Connection::class))); } public function boot(): void { $router = $this->app->make(Naluz\Routing\Router::class); $router->get('/blog', [BlogController::class, 'index']); }}Packages can ship middleware (any PSR-15 middleware works), routes, migrations (run them with Migrator pointed at your path), model factories, jobs and event listeners. The naluz command has a fixed set of commands today, so packages cannot add CLI commands.
Controlling discovery
Section titled “Controlling discovery”- Opt a package out in your app’s
composer.json:"extra": {"naluz": {"dont-discover": ["acme/blog"]}}(or['*']for none), or setapp.dont_discoverinconfig/app.php. - Only classes extending
ServiceProviderare ever instantiated from package metadata; anything else is ignored.
Community
Section titled “Community”Contribution guidelines, a code of conduct and a security policy live in the application repository. Publish packages with the naluz keyword on Packagist so they are easy to find.
Extending the framework
Section titled “Extending the framework”- Swap any service by binding it in a service provider:
$this->app->singleton(CacheInterface::class, fn () => new MyRedisCache()). - Use any PSR-15 middleware from Packagist in route or global stacks.
- Add database drivers by extending
Query\GrammarandSchema\Schemaand registering a factory. - Implement
Naluz\Mail\Transportfor another mail provider,Naluz\Storage\Filesystemfor another disk, orNaluz\Logchannels through acustomdriver.