# imagify/trunk/vendor/league/container/src/ContainerAwareTrait.php

Imagify Image Optimization: Optimize Images | Compress &amp; Convert to WebP/AVIF, version trunk. 41 lines.

- Page: https://pluginprobe.com/plugins/imagify/trunk/code/vendor/league/container/src/ContainerAwareTrait.php
- Raw: https://pluginprobe.com/plugins/imagify/trunk/raw/vendor/league/container/src/ContainerAwareTrait.php
- Modified: 2026-05-25T15:55:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/imagify/trunk/code/vendor/league/container/src/ContainerAwareTrait.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Imagify\Dependencies\League\Container;

use BadMethodCallException;
use Imagify\Dependencies\League\Container\Exception\ContainerException;

trait ContainerAwareTrait
{
    /**
     * @var ?DefinitionContainerInterface
     */
    protected $container;

    public function setContainer(DefinitionContainerInterface $container): ContainerAwareInterface
    {
        $this->container = $container;

        if ($this instanceof ContainerAwareInterface) {
            return $this;
        }

        throw new BadMethodCallException(sprintf(
            'Attempt to use (%s) while not implementing (%s)',
            ContainerAwareTrait::class,
            ContainerAwareInterface::class
        ));
    }

    public function getContainer(): DefinitionContainerInterface
    {
        if ($this->container instanceof DefinitionContainerInterface) {
            return $this->container;
        }

        throw new ContainerException('No container implementation has been set.');
    }
}

```
