Step 14 — App provider

Package authors and advanced app teams register boot logic in a Provider — one class instead of many INI fragments.

What you will learn

  • Scaffold AppProvider with make:provider
  • Move middleware/auth registration from INI into PHP hooks
  • Register a custom CLI command
Before you start

Generate provider

php pionia make:provider AppProvider

This creates providers/AppProvider.php and adds an entry under [app_providers] in settings.ini.

Wire DeskFlow hooks

namespace Application\Providers;

use Application\Middlewares\RequestIdMiddleware;
use Pionia\Base\Provider\Provider;
use Pionia\Middlewares\MiddlewareChain;

class AppProvider extends Provider
{
    public function middlewares(MiddlewareChain $chain): MiddlewareChain
    {
        return $chain->add(RequestIdMiddleware::class);
    }

    public function commands(): array
    {
        return [
            'deskflow:stats' => \Application\Commands\DeskflowStatsCommand::class,
        ];
    }
}

You can remove duplicate [app_middlewares] entries once the provider registers them.

Alternative registration in bootstrap/application.php:

pionia()->addAppProvider(\Application\Providers\AppProvider::class);

Full hook list: App providers. Publishing reusable packages: Composer packages.

Common mistakes

  • Registering the same middleware twice — INI + provider duplicates work.
  • Provider routes before switches — app switches still belong in [app_switches] unless you intentionally mount package APIs.