Overview

Namespaces

  • Autarky
    • Config
      • Loaders
    • Console
    • Container
      • Exception
      • Factory
      • Proxy
    • Database
    • Errors
    • Events
    • Files
    • Http
    • Logging
    • Providers
    • Routing
      • Events
    • Testing
    • TwigTemplating
      • Extensions
    • Utils

Classes

  • Container
  • ContainerProvider

Interfaces

  • CallableInvokerInterface
  • ClassResolverInterface
  • ContainerAwareInterface
  • ContainerInterface

Traits

  • ContainerAwareTrait
  • Overview
  • Namespace
  • Class

Class Container

Default implementation of the container.

Autarky\Container\Container implements Autarky\Container\ContainerInterface
Namespace: Autarky\Container
Located at Container.php
Methods summary
public
# __construct( )

Create a new instance of the container.

Create a new instance of the container.

On instantiation, the container instance will bind itself onto itself, and alias the ContainerInterface to the class name.

public
# define( string $class, callable $factory, array $params = array() )

Define a factory for a given class.

Define a factory for a given class.

Parameters

$class
$factory
$params
See ContainerInterface::params()

Implementation of

Autarky\Container\ContainerInterface::define()
public mixed
# invoke( callable $callable, array $params = array() )

Execute a function, closure or class method, resolving type-hinted arguments as necessary.

Execute a function, closure or class method, resolving type-hinted arguments as necessary.

Parameters

$callable
$params
See ContainerInterface::params()

Returns

mixed

Implementation of

Autarky\Container\CallableInvokerInterface::invoke()
public mixed
# resolve( string $class, array $params = array() )

Resolve a class from the container. Dependencies of the resolved object will be resolved recursively.

Resolve a class from the container. Dependencies of the resolved object will be resolved recursively.

Parameters

$class
$params
See ContainerInterface::params()

Returns

mixed

Implementation of

Autarky\Container\ContainerInterface::resolve()
protected object
# callFactory( Autarky\Container\Factory\FactoryInterface $factory, array $params = array() )

Call a factory.

Call a factory.

Parameters

$factory
$params

Returns

object
public Autarky\Container\Factory\Definition
# makeFactory( callable $callable, boolean $reflect = false )

Make a new factory definition for a class.

Make a new factory definition for a class.

Parameters

$callable
$reflect
Optional, default false - Whether to use reflection to find the arguments to the callable. If false, you will need to add arguments to the definition object yourself

Returns

Autarky\Container\Factory\Definition
public Autarky\Container\Factory\FactoryInterface
# getFactory( string $class, array $params = array() )

Get the existing factory for a class. If a factory is not already defined a default one will be created via reflection.

Get the existing factory for a class. If a factory is not already defined a default one will be created via reflection.

Parameters

$class
Name of the class
$params
Optional

Returns

Autarky\Container\Factory\FactoryInterface
protected array
# getFunctionArguments( ReflectionFunctionAbstract $func, array $params = array() )

Get an array of arguments to a function, resolving type-hinted arguments automatically on the way.

Get an array of arguments to a function, resolving type-hinted arguments automatically on the way.

Parameters

$func
$params

Returns

array

Throws

Autarky\Container\Exception\UnresolvableArgumentException
If any of the arguments are not type-hinted, does not have a default value and is not specified in $params
protected object|null
# resolveClassArg( ReflectionClass $class, ReflectionParameter $param, array $params )

Resolve a class type-hinted argument for a funtion.

Resolve a class type-hinted argument for a funtion.

Parameters

$class
$param
$params

Returns

object|null
protected mixed
# resolveNonClassArg( ReflectionParameter $param, array $params, ReflectionFunctionAbstract $func )

Resolve a non-class function argument.

Resolve a non-class function argument.

Parameters

$param
$params
$func

Returns

mixed
public
# resolving( string|array $classOrClasses, callable $callback )

Register a callback for whenever the given class is resolved.

Register a callback for whenever the given class is resolved.

Parameters

$classOrClasses
$callback

Implementation of

Autarky\Container\ContainerInterface::resolving()
public
# resolvingAny( callable $callback )

Register a callback for whenever anything is resolved.

Register a callback for whenever anything is resolved.

Parameters

$callback

Implementation of

Autarky\Container\ContainerInterface::resolvingAny()
protected
# callResolvingCallbacks( string $key, object $object )

Call resolving callbacks for an object.

Call resolving callbacks for an object.

Parameters

$key
Container key - usually the class name
$object
public
# setAutowire( boolean $autowire )

Enable or disable autowiring.

Enable or disable autowiring.

Parameters

$autowire
public boolean
# isBound( string $class )

Determine if a class is bound onto the container or not.

Determine if a class is bound onto the container or not.

Parameters

$class

Returns

boolean

Implementation of

Autarky\Container\ContainerInterface::isBound()
public
# instance( string $class, object $instance )

Place an already instantiated object into the container. This will make it available as a shared instance.

Place an already instantiated object into the container. This will make it available as a shared instance.

Parameters

$class
$instance

Implementation of

Autarky\Container\ContainerInterface::instance()
public
# share( string|array $classOrClasses )

Tell the container that a given class should be a shared instance, i.e. only constructed once. No matter time how many times that class is resolved out of the container, it will be the same instance.

Tell the container that a given class should be a shared instance, i.e. only constructed once. No matter time how many times that class is resolved out of the container, it will be the same instance.

Parameters

$classOrClasses

Implementation of

Autarky\Container\ContainerInterface::share()
public
# internal( string|array $classOrClasses )

Define a class or classes as internal.

Define a class or classes as internal.

Parameters

$classOrClasses

Implementation of

Autarky\Container\ContainerInterface::internal()
public
# alias( string $original, string|array $aliasOrAliases )

Define an alias.

Define an alias.

Parameters

$original
$aliasOrAliases

Implementation of

Autarky\Container\ContainerInterface::alias()
public
# params( string|array $keys, array $params )

Define a set of constructor arguments for a specific class.

Define a set of constructor arguments for a specific class.

Parameters

$keys
$classOrClasses
$params

Implementation of

Autarky\Container\ContainerInterface::params()
protected boolean
# isShared( string $class )

Determine if a class is shared or not.

Determine if a class is shared or not.

Parameters

$class

Returns

boolean
protected
# checkProtected( string $class, string|null $alias )

Check if a class and its alias (optionally) are protected, and throw an exception if they are.

Check if a class and its alias (optionally) are protected, and throw an exception if they are.

Parameters

$class
$alias

Throws

Autarky\Container\Exception\ResolvingInternalException
If class or alias is internal
protected boolean
# isProtected( string $class )

Determine if a class is protected or not.

Determine if a class is protected or not.

Parameters

$class

Returns

boolean
Properties summary
protected array $instances

Resolved instances.

Resolved instances.

# []
protected array $factories

Factories.

Factories.

# []
protected array $shared

Classes that should be shared instances.

Classes that should be shared instances.

# []
protected array $aliases

Aliases.

Aliases.

# []
protected array $params

Parameter specifications.

Parameter specifications.

# []
protected array $resolvingCallbacks

Resolving callbacks.

Resolving callbacks.

# []
protected array $resolvingAnyCallbacks

More resolving callbacks.

More resolving callbacks.

# []
protected array $internals

Internal classes.

Internal classes.

# []
protected boolean $protectInternals

Whether internal classes should be protected from resolving or not.

Whether internal classes should be protected from resolving or not.

# true
protected boolean $autowire

Whether to "autowire" classes or not.

Whether to "autowire" classes or not.

# true
Autarky Framework API documentation generated by ApiGen