public function beforeCompile()
{
$builder = $this->getContainerBuilder();
$this->compiledFile = NULL;
$namespace = 'Container_' . substr(md5(serialize([$builder->parameters, $this->compiler->exportDependencies(), PHP_VERSION_ID - PHP_RELEASE_VERSION])), 0, 10);
$file = new Code\PhpFile();
$cg = $file->addNamespace('Kdyby\\Aop_CG\\' . $namespace);
$cg->addUse('Kdyby\\Aop\\Pointcut\\Matcher\\Criteria');
$cg->addUse('Symfony\\Component\\PropertyAccess\\PropertyAccess');
foreach ($this->findAdvisedMethods() as $serviceId => $pointcuts) {
$service = $this->getWrappedDefinition($serviceId);
$advisedClass = AdvisedClassType::fromServiceDefinition($service, $cg);
$constructorInject = FALSE;
foreach ($pointcuts as $methodAdvices) {
/** @var Pointcut\Method $targetMethod */
$targetMethod = reset($methodAdvices)->getTargetMethod();
$newMethod = $targetMethod->getPointcutCode();
AdvisedClassType::setMethodInstance($advisedClass, $newMethod);
AdvisedClassType::generatePublicProxyMethod($advisedClass, $targetMethod->getCode());
$constructorInject = $constructorInject || strtolower($newMethod->getName()) === '__construct';
/** @var AdviceDefinition[] $methodAdvices */
foreach ($methodAdvices as $adviceDef) {
$newMethod->addAdvice($adviceDef);
}
}
$this->patchService($serviceId, $advisedClass, $cg, $constructorInject);
}
if (!$cg->getClasses()) {
return;
}
require_once $this->compiledFile = $this->writeGeneratedCode($file, $cg);
}