Skip to content

Commit

Permalink
Copy Container trait (from core-bundle)
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Mar 28, 2024
1 parent 055caac commit a7da356
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Symfony/DependencyInjection/Container/ContainerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the datatables-bundle package.
*
* (c) 2018 WEBEWEB
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WBW\Bundle\DataTablesBundle\Symfony\DependencyInjection\Container;

use Psr\Container\ContainerInterface;

/**
* Container trait.
*
* @author webeweb <https://github.com/webeweb>
* @package WBW\Bundle\DataTablesBundle\Symfony\DependencyInjection\Container
*/
trait ContainerTrait {

/**
* Container.
*
* @var ContainerInterface|null
*/
private $container;

/**
* Get the container.
*
* @return ContainerInterface|null Returns the container.
*/
public function getContainer(): ?ContainerInterface {
return $this->container;
}

/**
* Set the container.
*
* @param ContainerInterface|null $container The container.
* @return self Returns this instance.
*/
protected function setContainer(?ContainerInterface $container): self {
$this->container = $container;
return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the datatables-bundle package.
*
* (c) 2018 WEBEWEB
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WBW\Bundle\DataTablesBundle\Tests\Fixtures\Symfony\DependencyInjection\Container;

use WBW\Bundle\DataTablesBundle\Symfony\DependencyInjection\Container\ContainerTrait;

/**
* Test container trait.
*
* @author webeweb <https://github.com/webeweb>
* @package WBW\Bundle\DataTablesBundle\Tests\Fixtures\Symfony\DependencyInjection\Container
*/
class TestContainerTrait {

use ContainerTrait {
setContainer as public;
}
}
37 changes: 37 additions & 0 deletions Tests/Symfony/DependencyInjection/Container/ContainerTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the datatables-bundle package.
*
* (c) 2018 WEBEWEB
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WBW\Bundle\DataTablesBundle\Tests\Symfony\DependencyInjection\Container;

use WBW\Bundle\DataTablesBundle\Tests\AbstractTestCase;
use WBW\Bundle\DataTablesBundle\Tests\Fixtures\Symfony\DependencyInjection\Container\TestContainerTrait;

/**
* Container trait test.
*
* @author webeweb <https://github.com/webeweb>
* @package WBW\Bundle\DataTablesBundle\Tests\Symfony\DependencyInjection\Container
*/
class ContainerTraitTest extends AbstractTestCase {

/**
* Test setContainer()
*
* @return void
*/
public function testSetContainer(): void {

$obj = new TestContainerTrait();

$obj->setContainer($this->containerBuilder);
$this->assertSame($this->containerBuilder, $obj->getContainer());
}
}

0 comments on commit a7da356

Please sign in to comment.