The first step would be for us to create a bootstrap file. This file is where we will initialize our application,
and add the service providers containing the services we want the application to load into the container. In this example, we will use/bootstrap/app.php. After the entrypoint file has been created, we will want to create a new$appinstance so that we may build and configure the application.
<?php
// import the library:
// let's first bring in the FrameworkFactory application manager
use FrameworkFactory\Application;
// create the app instance:
// the basePath argument is required, and should point to the
// main directory of your project
$app = Application::build(basePath: __DIR__ . '/../');
// configure the application:
// continue reading to see how to manage app configuration
// ...
// adding providers:
// continue reading to see how to manage service providers
// ...
// fire the app up:
// this final step will get everything bootstrapped and finalize
// the initialization process
$app->fire();Once the bootstrap file has been created, the application is almost ready to go. Next we will have to create and add service providers to the application in order to register them within the container.
Once we have created our Service Classes and Service Providers, we can add them to our application. This can be done by calling the
withProviders()method on the$appinstance. ThewithProvidersmethod accepts an array of service providers that we want to load into our application.
<?php
use App\Providers\MessageServiceProvider;
$app->withProviders([
MessageServiceProvider::class
]);Service Providers can be auto-discovered and do not need be added to the
withProviders()method, and thewithProviders()method can be omitted. In order to achieve this, all auto-discoverable providers need to live within theApp\Providersnamespace. Any auto-discoverable providers must either end withServiceProvider, orProviderto be properly discovered - EG:LoggerServiceProviderorLoggerProvider. Any classes that do not contain either suffix will be ignored by the application bootstrap process and will not be added to the providers list.The main application namespace and its corresponding directory can be customized upon the creation of the
$appinstance. It is important to note that theappDirectoryparameter is relative to the assignedbaseDirpath.
<?php
use FrameworkFactory\Application;
$app = Application::build(basePath: __DIR__ . '/../', appNamespace: 'MyApp', appDirectory: 'my-app');Now any classes within the
MyApp\Providersdirectory that end with eitherProviderorServiceProviderwill be automatically added and their services will be loaded into the container - EG:MyApp\Providers\LoggerServiceProviderorMyApp\Providers\LoggerProvider.
- See Also: Service Providers
- See Also: Installation