master

laravel/framework

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

ContextualBindingBuilder.php

TLDR

This file contains the ContextualBindingBuilder interface, which defines methods for defining contextual bindings in the container.

Methods

needs

This method is used to define the abstract target that depends on the context. It takes a string $abstract as a parameter and returns an instance of $this.

give

This method is used to define the implementation for the contextual binding. It takes a closure, string, or an array $implementation as a parameter and doesn't return anything.

giveTagged

This method is used to define tagged services to be used as the implementation for the contextual binding. It takes a string $tag as a parameter and doesn't return anything.

giveConfig

This method is used to specify the configuration item to bind as a primitive. It takes a string $key and an optional mixed $default parameter as inputs and doesn't return anything.

<?php

namespace Illuminate\Contracts\Container;

interface ContextualBindingBuilder
{
    /**
     * Define the abstract target that depends on the context.
     *
     * @param  string  $abstract
     * @return $this
     */
    public function needs($abstract);

    /**
     * Define the implementation for the contextual binding.
     *
     * @param  \Closure|string|array  $implementation
     * @return void
     */
    public function give($implementation);

    /**
     * Define tagged services to be used as the implementation for the contextual binding.
     *
     * @param  string  $tag
     * @return void
     */
    public function giveTagged($tag);

    /**
     * Specify the configuration item to bind as a primitive.
     *
     * @param  string  $key
     * @param  mixed  $default
     * @return void
     */
    public function giveConfig($key, $default = null);
}