Nette\PhpGenerator\PhpFile::addNamespace PHP Метод

addNamespace() публичный Метод

public addNamespace ( $name ) : PhpNamespace
Результат PhpNamespace
    public function addNamespace($name)
    {
        if (!isset($this->namespaces[$name])) {
            $this->namespaces[$name] = new PhpNamespace($name);
        }
        return $this->namespaces[$name];
    }

Usage Example

Пример #1
0
 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);
 }
All Usage Examples Of Nette\PhpGenerator\PhpFile::addNamespace