master

laravel/framework

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

CookieServiceProvider.php

TLDR

This file is a service provider for managing cookies in the Illuminate framework.

Methods

register

This method registers the cookie service in the application container. It creates a singleton instance of the cookie service, which is responsible for managing cookies. The method retrieves the session configuration from the application container, sets the default path and domain for cookies using the configuration values, and returns a new instance of the CookieJar class.

Classes

CookieServiceProvider

The CookieServiceProvider class extends the ServiceProvider class from the Illuminate framework. It is a service provider for managing cookies in the application. It registers the cookie service in the application container.

<?php

namespace Illuminate\Cookie;

use Illuminate\Support\ServiceProvider;

class CookieServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('cookie', function ($app) {
            $config = $app->make('config')->get('session');

            return (new CookieJar)->setDefaultPathAndDomain(
                $config['path'], $config['domain'], $config['secure'], $config['same_site'] ?? null
            );
        });
    }
}