Home  >  Article  >  PHP Framework  >  Laravel facade contracts (facades) and contracts (contracts)

Laravel facade contracts (facades) and contracts (contracts)

藏色散人
藏色散人forward
2020-12-18 08:56:272672browse

The following tutorial column of Laravel Framework will introduce laravel facades and contracts to you. I hope it will be helpful to friends in need!

1. How to define Laravel’s facade?

All facades are defined in the Illuminate\Support\Facades namespace.

2. Understanding of facades

What are facades?

Facades (pronounced: /fəˈsäd/) provide a "static" interface for classes available in the application's service container. You don't have to use a long list of namespaces or instantiate the object to access the object's specific methods.

facades How to register?

Same facades need to be registered and activated.

laravel I like it very much, register (register) start (bootstrap)

The startup guide of Facade is in Illuminate\Foundation\Bootstrap\RegisterFacades Registered.

    /**
     * Prepend the load method to the auto-loader stack.
     *
     * @return void
     */
    protected function register()
    {
        if (! $this->registered) {
            spl_autoload_register([$this, 'load'], true, true);

            $this->registered = true;
        }
    }

For specific implementation logic, you can view the original text: Laravel Facade loading process and principle

3. Explain the concept of contract in Laravel

They are a collection of interfaces of the Laravel framework. These contracts provide core services. Contracts in Laravel include corresponding framework implementations.

Thinking

  1. How to read facades Contracts?
  2. How are facades registered and loaded?
  3. What operations do facades facilitate for us?

The above is the detailed content of Laravel facade contracts (facades) and contracts (contracts). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete