CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.4 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.4
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Container
      • Argument
      • Definition
      • Exception
      • Inflector
      • ServiceProvider
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class Container

Namespace: Cake\Container

Property Summary

  • $defaultToShared protected
    bool
  • $delegates protected
    array<Psr\Container\ContainerInterface>

Method Summary

  • __construct() public
  • add() public
  • addDefinitions() public

    Add multiple definitions at once.

  • addServiceProvider() public
  • addShared() public
  • defaultToShared() public
  • delegate() public
  • disableAutoWiring() public
  • enableAutoWiring() public
  • extend() public
  • get() public

    Finds an entry of the container by its identifier and returns it.

  • getNew() public
  • has() public

    Returns true if the container can return an entry for the given identifier. Returns false otherwise.

  • hasDefinition() public

    Check if the container has a registered definition for the given id.

  • inflector() public
  • make() public

    Resolve an entry with specific constructor arguments.

  • resolve() protected

Method Detail

__construct() ¶ public

__construct(Cake\Container\Definition\DefinitionAggregateInterface $definitions = new DefinitionAggregate(), Cake\Container\ServiceProvider\ServiceProviderAggregateInterface $providers = new ServiceProviderAggregate(), Cake\Container\Inflector\InflectorAggregateInterface $inflectors = new InflectorAggregate())
Parameters
Cake\Container\Definition\DefinitionAggregateInterface $definitions optional
Cake\Container\ServiceProvider\ServiceProviderAggregateInterface $providers optional
Cake\Container\Inflector\InflectorAggregateInterface $inflectors optional

add() ¶ public

add(string $id, mixed $concrete = null): Cake\Container\Definition\DefinitionInterface
Parameters
string $id
mixed $concrete optional
Returns
Cake\Container\Definition\DefinitionInterface

addDefinitions() ¶ public

addDefinitions(array<int|string, array<class-string>|class-string> $definitions): Cake\Container\DefinitionContainerInterface

Add multiple definitions at once.

Examples:

$container->addDefinitions([
    Foo::class,
    Bar::class
]);
$container->addDefinitions([
    Foo::class => [Bar::class],
    Bar::class
]);
$container->addDefinitions([
   'foo' => Foo::class,
   'bar' => Bar::class
]);
Parameters
array<int|string, array<class-string>|class-string> $definitions
Returns
Cake\Container\DefinitionContainerInterface

addServiceProvider() ¶ public

addServiceProvider(Cake\Container\ServiceProvider\ServiceProviderInterface $provider): DefinitionContainerInterface
Parameters
Cake\Container\ServiceProvider\ServiceProviderInterface $provider
Returns
DefinitionContainerInterface

addShared() ¶ public

addShared(string $id, mixed $concrete = null): Cake\Container\Definition\DefinitionInterface
Parameters
string $id
mixed $concrete optional
Returns
Cake\Container\Definition\DefinitionInterface

defaultToShared() ¶ public

defaultToShared(bool $shared = true): Psr\Container\ContainerInterface
Parameters
bool $shared optional
Returns
Psr\Container\ContainerInterface

delegate() ¶ public

delegate(Psr\Container\ContainerInterface $container): $this
Parameters
Psr\Container\ContainerInterface $container
Returns
$this

disableAutoWiring() ¶ public

disableAutoWiring(): void
Returns
void

enableAutoWiring() ¶ public

enableAutoWiring(bool $cache = true): void
Parameters
bool $cache optional
Returns
void

extend() ¶ public

extend(string $id): Cake\Container\Definition\DefinitionInterface
Parameters
string $id
Returns
Cake\Container\Definition\DefinitionInterface

get() ¶ public

get(string $id): RequestedType|mixed

Finds an entry of the container by its identifier and returns it.

Templates
RequestedType
Parameters
string $id
Returns
RequestedType|mixed
Throws
Psr\Container\ContainerExceptionInterface

Psr\Container\NotFoundExceptionInterface

getNew() ¶ public

getNew(mixed $id): RequestedType|mixed
Templates
RequestedType
Parameters
mixed $id
Returns
RequestedType|mixed
Throws
Psr\Container\ContainerExceptionInterface

Psr\Container\NotFoundExceptionInterface

has() ¶ public

has(string $id): bool

Returns true if the container can return an entry for the given identifier. Returns false otherwise.

has($id) returning true does not mean that get($id) will not throw an exception. It does however mean that get($id) will not throw a NotFoundExceptionInterface.

Parameters
string $id
Returns
bool

hasDefinition() ¶ public

hasDefinition(string $id): bool

Check if the container has a registered definition for the given id.

Unlike has(), this only checks explicit definitions, not service providers or delegate containers.

Parameters
string $id
Returns
bool

inflector() ¶ public

inflector(string $type, callable|null $callback = null): Cake\Container\Inflector\InflectorInterface
Parameters
string $type
callable|null $callback optional
Returns
Cake\Container\Inflector\InflectorInterface

make() ¶ public

make(class-string<RequestedType>|string $id, array<string, mixed> $args = []): RequestedType|mixed

Resolve an entry with specific constructor arguments.

Unlike get(), this method allows passing specific constructor arguments that will be used during autowiring. Arguments can be passed by name.

Example:

$container->make(MyService::class, ['configValue' => 'foo']);
Templates
RequestedType
Parameters
class-string<RequestedType>|string $id
array<string, mixed> $args optional

Named arguments to pass to the constructor

Returns
RequestedType|mixed
Throws
Psr\Container\ContainerExceptionInterface

Psr\Container\NotFoundExceptionInterface

resolve() ¶ protected

resolve(mixed $id, bool $new = false, array<string, mixed> $args = []): mixed|object|array|null|void
Parameters
mixed $id
bool $new optional
array<string, mixed> $args optional
Returns
mixed|object|array|null|void
Throws
Psr\Container\ContainerExceptionInterface

Psr\Container\NotFoundExceptionInterface

Property Detail

$defaultToShared ¶ protected

Type
bool

$delegates ¶ protected

Type
array<Psr\Container\ContainerInterface>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs