addNamespace() public method

public addNamespace ( $name ) : PhpNamespace
return PhpNamespace
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);
 }
Example #2
0
 /**
  * @param string $json
  * @param string $full_class_name
  *
  * @return PhpFile
  */
 public function process($json, $full_class_name = 'stdClass')
 {
     $object = json_decode($json);
     list($class, $namespace) = $this->determineNames($full_class_name);
     $file = new PhpFile();
     $namespace = $file->addNamespace($namespace);
     $this->object($namespace, $class, $object);
     return $file;
 }
 /**
  *
  * @param \App\TableEntity $tableEntity
  */
 private function generateEntityFile(TableEntity $tableEntity)
 {
     $phpFile = new PhpFile();
     $namespaceName = empty($this->namespaceDb) ? $this->namespaceRoot : $this->namespaceRoot . '\\' . $this->namespaceDb;
     $namespace = $phpFile->addNamespace($namespaceName);
     $class = $namespace->addClass(StringHelper::toPascalCase($tableEntity->tableName));
     $class->addExtend("\\" . $this->namespaceRoot . "\\AbstractDBEntity");
     $mGetTableName = $class->addMethod("getTableName");
     $mGetTableName->addDocument("@return string")->setVisibility("public")->setStatic(true)->addBody("return '" . $this->getName($tableEntity->tableName) . "';");
     foreach ($tableEntity->columns as $name => $attributes) {
         $class->addConst(StringHelper::toConstCase($name), $this->getName($name));
     }
     if ($this->generateAbsoluteConstants) {
         foreach ($tableEntity->columns as $name => $attributes) {
             $class->addConst('__' . StringHelper::toConstCase($name), $this->getName($tableEntity->tableName) . '.' . $this->getName($name));
         }
     }
     $mappingBody = array();
     foreach ($tableEntity->columns as $name => $attributes) {
         $prop = $class->addProperty(StringHelper::toCamelCase($name));
         $prop->addDocument("@var {$attributes}")->setVisibility("public");
         $mappingBody[] = "\tself::" . StringHelper::toConstCase($name) . ' => &$this->' . StringHelper::toCamelCase($name) . ",";
     }
     $mGetMappingArray = $class->addMethod("getMappingArray");
     $mGetMappingArray->addDocument("@return array")->setVisibility("protected")->addBody('return array(' . "\n" . implode("\n", $mappingBody) . "\n" . ');');
     $this->writeFile($phpFile, $tableEntity->tableName);
 }