master

laravel/framework

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

MaintenanceModeManager.php

TLDR

The MaintenanceModeManager.php file is a part of the Illuminate\Foundation namespace in the Demo Projects project. It extends the Illuminate\Support\Manager class and contains methods for creating instances of different types of maintenance mode drivers and getting the default driver name.

Methods

createFileDriver

This method creates an instance of the file-based maintenance mode driver.

createCacheDriver

This method creates an instance of the cache-based maintenance mode driver. It uses the cache service from the container and the app.maintenance.store configuration value or the cache.default configuration value as the cache store. It also sets the cache key to 'illuminate:foundation:down'.

getDefaultDriver

This method returns the default driver name for the maintenance mode. It retrieves the configuration value for the key app.maintenance.driver and uses 'file' as the default value if the configuration value is not set.

<?php

namespace Illuminate\Foundation;

use Illuminate\Support\Manager;

class MaintenanceModeManager extends Manager
{
    /**
     * Create an instance of the file based maintenance driver.
     *
     * @return \Illuminate\Foundation\FileBasedMaintenanceMode
     */
    protected function createFileDriver(): FileBasedMaintenanceMode
    {
        return new FileBasedMaintenanceMode();
    }

    /**
     * Create an instance of the cache based maintenance driver.
     *
     * @return \Illuminate\Foundation\CacheBasedMaintenanceMode
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    protected function createCacheDriver(): CacheBasedMaintenanceMode
    {
        return new CacheBasedMaintenanceMode(
            $this->container->make('cache'),
            $this->config->get('app.maintenance.store') ?: $this->config->get('cache.default'),
            'illuminate:foundation:down'
        );
    }

    /**
     * Get the default driver name.
     *
     * @return string
     */
    public function getDefaultDriver(): string
    {
        return $this->config->get('app.maintenance.driver', 'file');
    }
}