VOOZH about

URL: https://deepwiki.com/hypervel/container/8-api-reference

⇱ API Reference | hypervel/container | DeepWiki


Loading...
Menu

API Reference

This page provides comprehensive method-level documentation for the Hypervel Container public APIs. It covers method signatures, parameters, return types, and usage patterns for the Container class and BoundMethod utility.

For conceptual information about container operations, see Container System. For details on service binding patterns, see Service Binding. For resolution pipeline mechanics, see Dependency Resolution.


Container Class Overview

The Container class is the primary entry point for dependency injection operations. It extends Hyperf's base container and implements both the Hypervel Container contract and PHP's ArrayAccess interface.


Sources: src/Container.php17 src/Contracts/Container.php13


Resolution Methods

Methods for retrieving and resolving dependencies from the container.

make()

Resolves a service from the container with factory behavior. Creates a new instance on each call, even for singletons.


Signature:






















ParameterTypeDescription
$namestringService name, class name, or alias
$parametersarrayOptional parameters for construction

Returns: Resolved service instance

Throws: Hyperf\Di\Exception\NotFoundException if service not found

Sources: src/Container.php109-132


get()

PSR-11 compliant method for retrieving services. Respects singleton bindings and caches instances.

Signature:

















ParameterTypeDescription
$idstringIdentifier of the entry to retrieve

Returns: Entry from the container

Sources: src/Container.php139-146 src/Contracts/Container.php33


has()

Checks if the container can return an entry for the given identifier. Returns true for bound services and registered aliases.

Signature:

















ParameterTypeDescription
$idmixed|stringIdentifier to check

Returns: true if entry exists, false otherwise

Sources: src/Container.php211-214 src/Contracts/Container.php26-33


bound()

Determines if the given abstract type has been bound in the container.

Signature:

















ParameterTypeDescription
$abstractstringAbstract type or service name

Returns: true if bound, false otherwise

Sources: src/Container.php194-201 src/Contracts/Container.php23


resolved()

Checks if the given abstract type has already been resolved and cached.

Signature:

















ParameterTypeDescription
$abstractstringAbstract type to check

Returns: true if resolved, false otherwise

Sources: src/Container.php219-226 src/Contracts/Container.php38


set()

Binds an arbitrary resolved entry to an identifier. Primarily used for testing.

Signature:






















ParameterTypeDescription
$namestringService identifier
$entrymixedEntry to bind

Sources: src/Container.php153-160


unbind()

Removes a resolved entry from the instance cache.

Signature:

















ParameterTypeDescription
$namestringService to unbind

Sources: src/Container.php165-172 src/Contracts/Container.php18


remove()

Completely removes a binding, including its definition and resolved instances.

Signature:

















ParameterTypeDescription
$namestringService to remove

Sources: src/Container.php178-189


Binding Methods

Methods for registering services and their implementations.


Sources: src/Container.php243-349


bind()

Registers a binding with the container. If no concrete implementation is provided, the abstract name is used.

Signature:






















ParameterTypeDescription
$abstractstringService interface or abstract name
$concretenull|Closure|stringImplementation, closure, or null for self-binding

Throws: TypeError if concrete type is invalid

Sources: src/Container.php243-259 src/Contracts/Container.php46-52


bindIf()

Registers a binding only if it hasn't already been registered.

Signature:






















ParameterTypeDescription
$abstractstringService interface or abstract name
$concretenull|Closure|stringImplementation or null

Sources: src/Container.php302-307 src/Contracts/Container.php70-74


instance()

Registers an existing instance as a shared singleton in the container.

Signature:






















ParameterTypeDescription
$abstractstringService name
$instancemixedPre-constructed instance

Returns: The registered instance

Sources: src/Container.php329-349 src/Contracts/Container.php86


Alias Methods

Methods for managing service aliases (alternate names for the same service).

alias()

Creates an alias for a service, allowing it to be resolved by multiple names.

Signature:






















ParameterTypeDescription
$abstractstringOriginal service name
$aliasstringAlternate name

Throws: LogicException if attempting to alias to itself

Sources: src/Container.php374-383 src/Contracts/Container.php89-93


isAlias()

Checks if a given name is an alias.

Signature:

















ParameterTypeDescription
$namestringName to check

Returns: true if the name is an alias

Sources: src/Container.php231-234 src/Contracts/Container.php43


getAlias()

Recursively resolves an alias to its underlying abstract name.

Signature:

















ParameterTypeDescription
$abstractstringName or alias to resolve

Returns: The underlying abstract name

Sources: src/Container.php622-627 src/Contracts/Container.php158


Method Binding

Special binding system for controlling how specific methods are invoked.


Sources: src/Container.php264-295


bindMethod()

Binds a callback to be used when resolving a specific method via Container::call().

Signature:






















ParameterTypeDescription
$methodarray|stringMethod in Class@method format or [Class, method] array
$callbackClosureCallback receiving ($instance, $container)

Sources: src/Container.php272-275 src/Contracts/Container.php62


hasMethodBinding()

Checks if a method binding exists for the given method.

Signature:

















ParameterTypeDescription
$methodstringMethod in Class@method format

Returns: true if binding exists

Sources: src/Container.php264-267 src/Contracts/Container.php57


callMethodBinding()

Invokes a registered method binding.

Signature:






















ParameterTypeDescription
$methodstringMethod identifier
$instancemixedInstance to pass to callback

Returns: Result of the bound callback

Sources: src/Container.php292-295 src/Contracts/Container.php67


Lifecycle Callbacks

Registration methods for hooking into the resolution lifecycle.

Callback Types and Execution Order


Sources: src/Container.php467-578


beforeResolving()

Registers a callback to execute before a service is resolved.

Signature:






















ParameterTypeDescription
$abstractClosure|stringService type or global closure
$callback?ClosureCallback receiving ($abstract, $parameters, $container)

Callback Signature: function(string $abstract, array $parameters, Container $container): void

Sources: src/Container.php467-478 src/Contracts/Container.php130-134


resolving()

Registers a callback to execute during service resolution, after instance creation but during the resolution phase.

Signature:






















ParameterTypeDescription
$abstractClosure|stringService type or global closure
$callback?ClosureCallback receiving ($instance, $container)

Callback Signature: function(mixed $instance, Container $container): void

Sources: src/Container.php485-496 src/Contracts/Container.php136-141


afterResolving()

Registers a callback to execute after a service has been fully resolved.

Signature:






















ParameterTypeDescription
$abstractClosure|stringService type or global closure
$callback?ClosureCallback receiving ($instance, $container)

Callback Signature: function(mixed $instance, Container $container): void

Sources: src/Container.php503-514 src/Contracts/Container.php143-148


Extenders and Decorators

extend()

Extends a service by wrapping it with additional functionality. Applies to future resolutions and immediately to already-resolved instances.

Signature:






















ParameterTypeDescription
$abstractstringService to extend
$closureClosureDecorator receiving ($instance, $container)

Throws: InvalidArgumentException if service type is invalid

Sources: src/Container.php314-324 src/Contracts/Container.php77-81


forgetExtenders()

Removes all extender callbacks for a given service type.

Signature:

















ParameterTypeDescription
$abstractstringService to clear extenders for

Sources: src/Container.php640-643 src/Contracts/Container.php163


Rebinding and Refresh

Methods for managing service lifecycle when bindings change.

rebinding()

Registers a callback to execute when a service is rebound (re-registered).

Signature:






















ParameterTypeDescription
$abstractstringService to watch
$callbackClosureCallback receiving ($container, $instance)

Returns: Current instance if already bound, null otherwise

Sources: src/Container.php388-397 src/Contracts/Container.php98


refresh()

Convenience method to refresh a specific property when a service is rebound.

Signature:



























ParameterTypeDescription
$abstractstringService to watch
$targetmixedObject to update
$methodstringMethod to call on rebind

Returns: Result of rebinding()

Sources: src/Container.php402-407 src/Contracts/Container.php103


Invocation Methods

Methods for calling functions and methods with automatic dependency injection.


Sources: src/BoundMethod.php25-74


call()

Invokes a callable with automatic dependency injection for its parameters.

Signature:



























ParameterTypeDescription
$callbackcallable|stringCallable, closure, or Class@method string
$parametersarrayOptional parameters to override dependency resolution
$defaultMethod?stringDefault method name if not specified

Returns: Result of the invoked callable

Throws: BindingResolutionException if callable is invalid or dependencies cannot be resolved

Supported Callback Formats:

  • Closure: function($dep1, $dep2) { ... }
  • Class@method: "App\\Service@handle"
  • Array: [$instance, 'method'] or [ClassName::class, 'method']
  • Static: "ClassName::method"
  • Invokable: $objectWithInvokeMethod

Sources: src/Container.php437-440 src/Contracts/Container.php106-113


factory()

Returns a closure that resolves the given service when invoked.

Signature:

















ParameterTypeDescription
$abstractstringService to create factory for

Returns: Closure that returns resolved instance

Sources: src/Container.php445-448 src/Contracts/Container.php118


makeWith()

Alias for make() with a different name for compatibility.

Signature:






















ParameterTypeDescription
$abstractcallable|stringService to resolve
$parametersarrayConstruction parameters

Returns: Resolved instance

Throws: Hyperf\Di\Exception\NotFoundException if not found

Sources: src/Container.php457-460 src/Contracts/Container.php121-127


Instance Management

Methods for managing resolved instances and clearing caches.

MethodPurposeScope
forgetInstance(string)Remove specific instance from cacheSingle service
forgetInstances()Clear all resolved instancesAll instances
flush()Clear instances, aliases, and abstract aliasesComplete reset

forgetInstance()

Removes a specific resolved instance from the cache.

Signature:


Sources: src/Container.php656-659 src/Contracts/Container.php168


forgetInstances()

Clears all resolved instances from the cache.

Signature:


Sources: src/Container.php664-667 src/Contracts/Container.php173


flush()

Completely flushes the container, removing all aliases and resolved instances.

Signature:


Sources: src/Container.php672-677 src/Contracts/Container.php178


Container Information

Methods for introspecting container state.

getBindings()

Returns all registered service bindings.

Signature:


Returns: Array of all definitions from the definition source

Sources: src/Container.php614-617 src/Contracts/Container.php153


Static Container Access

Methods for managing the global container instance.

getInstance()

Retrieves the globally available container instance. Creates one if it doesn't exist.

Signature:


Returns: The global container instance

Sources: src/Container.php682-692 src/Contracts/Container.php183


setInstance()

Sets the shared global container instance.

Signature:

















ParameterTypeDescription
$containerContainerContractContainer to set as global

Returns: The container that was set

Sources: src/Container.php697-701 src/Contracts/Container.php188


ArrayAccess Implementation

The container implements ArrayAccess, allowing array-style access to services.


Sources: src/Container.php703-738

Array Syntax Examples

OperationMethod CalledEquivalent
isset($container['service'])offsetExists()bound()$container->bound('service')
$service = $container['service']offsetGet()get()$container->get('service')
$container['service'] = $imploffsetSet()define()$container->define('service', $impl)
unset($container['service'])offsetUnset()remove()$container->remove('service')

BoundMethod Class

Static utility class for invoking callables with automatic dependency injection.


Sources: src/BoundMethod.php15-222


BoundMethod::call()

Primary static method for invoking callables with dependency injection.

Signature:
































ParameterTypeDescription
$containerContainerContractContainer for dependency resolution
$callbackcallable|stringCallable to invoke
$parametersarrayOverride parameters
$defaultMethod?stringDefault method if not specified

Returns: Result of the invoked callable

Throws:

  • ReflectionException if reflection fails
  • BindingResolutionException if dependencies cannot be resolved

Parameter Resolution Priority:

  1. Explicitly provided in $parameters by parameter name
  2. Explicitly provided by parameter position
  3. Explicitly provided by type name
  4. Parameter default value if available
  5. Resolved from container by type
  6. null if parameter allows null
  7. Exception if required parameter cannot be resolved

Sources: src/BoundMethod.php25-74


Dependency Resolution in BoundMethod


Sources: src/BoundMethod.php76-115


Code Entity Map

This table maps high-level concepts to specific code entities for easy reference.

ConceptPrimary ClassKey MethodsFile Reference
Service ResolutionContainermake(), get(), has()src/Container.php109-214
Service RegistrationContainerbind(), bindIf(), instance()src/Container.php243-349
AliasingContaineralias(), isAlias(), getAlias()src/Container.php231-383
Method BindingContainerbindMethod(), hasMethodBinding(), callMethodBinding()src/Container.php264-295
Lifecycle HooksContainerbeforeResolving(), resolving(), afterResolving()src/Container.php467-514
Service DecorationContainerextend(), forgetExtenders()src/Container.php314-324 src/Container.php640-643
RebindingContainerrebinding(), refresh()src/Container.php388-419
Method InvocationContainer, BoundMethodcall(), BoundMethod::call()src/Container.php437-440 src/BoundMethod.php25-74
Factory PatternContainerfactory(), makeWith()src/Container.php445-460
Cache ManagementContainerforgetInstance(), forgetInstances(), flush()src/Container.php656-677
Global AccessContainergetInstance(), setInstance()src/Container.php682-701
Array AccessContaineroffsetExists(), offsetGet(), offsetSet(), offsetUnset()src/Container.php703-721
Interface ContractContainerContractAll interface methodssrc/Contracts/Container.php13-189
Parameter ResolutionBoundMethodgetDependencyParameters(), getMethodDependencies(), getClosureDependencies()src/BoundMethod.php76-211

Sources: src/Container.php src/Contracts/Container.php src/BoundMethod.php