-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compiler pass to set philkra to null (#4)
* compiler init * use dependency version compatible with sf 3.4 * set argument philkra agent * get proper apm enabled parameter * syntax * comment purpose of engine pass * prevent bundles instantiation if apm disabled * class ids syntax * remove references to enabled parameter
- Loading branch information
1 parent
3f14891
commit 799256f
Showing
8 changed files
with
142 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* @author Wizacha DevTeam <[email protected]> | ||
* @copyright Copyright (c) Wizacha | ||
* @license Proprietary | ||
*/ | ||
|
||
namespace Wizacha\ElasticApmBundle\DependencyInjection\Compiler; | ||
|
||
use PhilKra\Agent; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Wizacha\ElasticApm\Service\AgentService; | ||
use Wizacha\ElasticApmBundle\ElasticApmSubscriber; | ||
|
||
class ElasticApmEnginePass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (false === $container->resolveEnvPlaceholders($container->getParameter('elastic_apm.enabled'), true)) { | ||
$container->removeDefinition(AgentService::class); | ||
$container->removeDefinition(ElasticApmSubscriber::class); | ||
$container->removeDefinition(Agent::class); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* @author Wizacha DevTeam <[email protected]> | ||
* @copyright Copyright (c) Wizacha | ||
* @license Proprietary | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Wizacha\ElasticApmBundle\Tests; | ||
|
||
use PhilKra\Agent; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Wizacha\ElasticApm\Service\AgentService; | ||
use Wizacha\ElasticApmBundle\DependencyInjection\Compiler\ElasticApmEnginePass; | ||
use Wizacha\ElasticApmBundle\ElasticApmSubscriber; | ||
|
||
class ElasticApmEnginePassTest extends TestCase | ||
{ | ||
/** | ||
* @var ContainerBuilder | ||
*/ | ||
protected $container; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->container = new ContainerBuilder(); | ||
$this->container->getCompilerPassConfig()->setOptimizationPasses([]); | ||
$this->container->getCompilerPassConfig()->setRemovingPasses([]); | ||
$this->container->getCompilerPassConfig()->setAfterRemovingPasses([]); | ||
$this->container->addCompilerPass(new ElasticApmEnginePass()); | ||
|
||
$loader = new YamlFileLoader( | ||
$this->container, | ||
new FileLocator(__DIR__ . '/../config') | ||
); | ||
|
||
$loader->load(__DIR__ . '/../config/services.yml'); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$this->container = null; | ||
} | ||
|
||
public function testEnabledConfiguration(): void | ||
{ | ||
$this->setParameter('elastic_apm.enabled', true); | ||
$this->container->compile(); | ||
|
||
static::assertContains(AgentService::class, $this->container->getServiceIds()); | ||
static::assertContains(ElasticApmSubscriber::class, $this->container->getServiceIds()); | ||
static::assertContains(Agent::class, $this->container->getServiceIds()); | ||
} | ||
|
||
public function testDisabledConfiguration(): void | ||
{ | ||
$this->setParameter('elastic_apm.enabled', false); | ||
$this->container->compile(); | ||
|
||
static::assertNotContains(AgentService::class, $this->container->getServiceIds()); | ||
static::assertNotContains(ElasticApmSubscriber::class, $this->container->getServiceIds()); | ||
static::assertNotContains(Agent::class, $this->container->getServiceIds()); | ||
} | ||
|
||
/** | ||
* Shortcut for quickly defining services. The returned Definition object can be further modified if necessary. | ||
*/ | ||
final protected function registerService(string $serviceId, string $class): Definition | ||
{ | ||
$definition = new Definition($class); | ||
|
||
$this->container->setDefinition($serviceId, $definition); | ||
|
||
return $definition; | ||
} | ||
|
||
/** | ||
* Set a service definition you manually created. | ||
*/ | ||
final protected function setDefinition(string $serviceId, Definition $definition): void | ||
{ | ||
$this->container->setDefinition($serviceId, $definition); | ||
} | ||
|
||
/** | ||
* Set a parameter. | ||
* | ||
* @param mixed $parameterValue | ||
*/ | ||
final protected function setParameter(string $parameterId, $parameterValue): void | ||
{ | ||
$this->container->setParameter($parameterId, $parameterValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters