# imagify/2.2/classes/Dependencies/League/Container/ContainerAwareTrait.php

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

- Page: https://pluginprobe.com/plugins/imagify/2.2/code/classes/Dependencies/League/Container/ContainerAwareTrait.php
- Raw: https://pluginprobe.com/plugins/imagify/2.2/raw/classes/Dependencies/League/Container/ContainerAwareTrait.php
- Modified: 2024-03-06T17:27:56+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/2.2/code/classes/Dependencies/League/Container/ContainerAwareTrait.php#L10-L20`.

```php
<?php declare(strict_types=1);

namespace Imagify\Dependencies\League\Container;

use Imagify\Dependencies\League\Container\Exception\ContainerException;
use Imagify\Dependencies\Psr\Container\ContainerInterface;

trait ContainerAwareTrait
{
    /**
     * @var ContainerInterface
     */
    protected $container;

    /**
     * @var Container
     */
    protected $leagueContainer;

    /**
     * Set a container.
     *
     * @param ContainerInterface $container
     *
     * @return ContainerAwareInterface
     */
    public function setContainer(ContainerInterface $container) : ContainerAwareInterface
    {
        $this->container = $container;

        return $this;
    }

    /**
     * Get the container.
     *
     * @return ContainerInterface
     */
    public function getContainer() : ContainerInterface
    {
        if ($this->container instanceof ContainerInterface) {
            return $this->container;
        }

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

    /**
     * Set a container.
     *
     * @param Container $container
     *
     * @return self
     */
    public function setLeagueContainer(Container $container) : ContainerAwareInterface
    {
        $this->container = $container;
        $this->leagueContainer = $container;

        return $this;
    }

    /**
     * Get the container.
     *
     * @return Container
     */
    public function getLeagueContainer() : Container
    {
        if ($this->leagueContainer instanceof Container) {
            return $this->leagueContainer;
        }

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

```
