master

laravel/framework

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

HashServiceProvider.php

TLDR

This file is a service provider class for the Hashing component in the Illuminate namespace. It registers the hash and hash.driver services and provides them to the application.

Methods (if applicable)

register

The register method is responsible for registering the hash and hash.driver services. It uses the singleton method to bind the services to their respective closures. The hash service is bound to a closure that returns a new instance of the HashManager class, passing the application instance as an argument. The hash.driver service is bound to a closure that retrieves the driver method from the hash service.

provides

The provides method returns an array containing the names of the services provided by the service provider. In this case, it returns ['hash', 'hash.driver'].

<?php

namespace Illuminate\Hashing;

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

class HashServiceProvider extends ServiceProvider implements DeferrableProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('hash', function ($app) {
            return new HashManager($app);
        });

        $this->app->singleton('hash.driver', function ($app) {
            return $app['hash']->driver();
        });
    }

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