master

laravel/framework

Last updated at: 29/12/2023 09:23

ComposerServiceProvider.php

TLDR

This file is the ComposerServiceProvider class, which is a service provider in the Illuminate\Foundation\Providers namespace. It extends the ServiceProvider class and implements the DeferrableProvider interface. It provides a method to register the service and another method to specify the service it provides.

Methods

register

This method is used to register the composer service. It creates a singleton instance of the Composer class by passing the application's files service and its base path as arguments.

provides

This method specifies the service provided by the provider. It returns an array with the string 'composer'.

<?php

namespace Illuminate\Foundation\Providers;

use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Composer;
use Illuminate\Support\ServiceProvider;

class ComposerServiceProvider extends ServiceProvider implements DeferrableProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('composer', function ($app) {
            return new Composer($app['files'], $app->basePath());
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return ['composer'];
    }
}