/**
  * @param ClassMetadataInfo $metadata
  * @param string $outputDir
  * @param Closure $collectionNameBuilder
  */
 public function generate(ClassMetadataInfo $metadata, $outputDir, Closure $collectionNameBuilder)
 {
     $tpl = file_get_contents(CodeGeneratorHelper::absPath(EntityCollectionTemplate::class, RootPath::path()));
     $tplNs = CodeGeneratorHelper::ns(EntityCollectionTemplate::class);
     $tplSimpleName = CodeGeneratorHelper::simpleName(EntityCollectionTemplate::class);
     $entityFqcn = CodeGeneratorHelper::simpleName(EntityFqcn::class);
     $collectionClassName = $collectionNameBuilder($metadata->getName());
     $code = CodeGeneratorHelper::render($tpl, array($tplNs => CodeGeneratorHelper::ns($collectionClassName), $tplSimpleName => CodeGeneratorHelper::simpleName($collectionClassName), $entityFqcn => CodeGeneratorHelper::fqn($metadata->getName())));
     CodeGeneratorHelper::save($collectionClassName, $code, $outputDir);
 }
 public function generate($fullClassName, $outputDir)
 {
     $fqn = CodeGeneratorHelper::fqn($fullClassName);
     $reflectionClass = new ReflectionClass($fullClassName);
     $ns = $reflectionClass->getName();
     $methods = $reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC);
     $code = [];
     foreach ($methods as $method) {
         /** @var ReflectionMethod $method */
         $name = $method->getName();
         if ($this->accept($method)) {
             list($hints, $uses, $applies) = $this->prepareHintUseApply($method);
             if ($method->isStatic()) {
                 $code[] = sprintf(static::$fnStaticMethodTemplate, $name, $hints, $uses, $fqn, $name, $applies);
             } else {
                 $code[] = sprintf(static::$fnInstanceMethodTemplate, $name, $hints, $fqn, $uses, $name, $applies);
             }
         }
     }
     $body = sprintf(static::$bodyTemplate, $ns, implode("\n", $code));
     CodeGeneratorHelper::save("{$fullClassName}/Fn", $body, $outputDir);
 }
 protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
 {
     $methodName = $type . Inflector::classify($fieldName);
     $variableName = Inflector::camelize($fieldName);
     if (in_array($type, array("add", "remove"))) {
         $methodName = Inflector::singularize($methodName);
         $variableName = Inflector::singularize($variableName);
     }
     if ($this->hasMethod($methodName, $metadata)) {
         return '';
     }
     $this->staticReflection[$metadata->name]['methods'][] = strtolower($methodName);
     $var = sprintf('%sMethodTemplate', $type);
     $template = static::${$var};
     $methodTypeHint = null;
     $types = Type::getTypesMap();
     $variableType = $typeHint ? $this->getType($typeHint) : null;
     if ($typeHint && !isset($types[$typeHint])) {
         $variableType = '\\' . ltrim($variableType, '\\');
         $methodTypeHint = '\\' . $typeHint . ' ';
     }
     $replacements = array('<description>' => ucfirst($type) . ' ' . $variableName, '<methodTypeHint>' => $methodTypeHint, '<variableType>' => $variableType, '<variableName>' => $variableName, '<methodName>' => $methodName, '<fieldName>' => $fieldName, '<variableDefault>' => $defaultValue !== null ? ' = ' . $defaultValue : '', '<entity>' => CodeGeneratorHelper::fqn($metadata->getName()));
     $method = str_replace(array_keys($replacements), array_values($replacements), $template);
     return $this->prefixCodeWithSpaces($method);
 }
 protected function generateCondCodeBody($metadatas, ClassMetadataInfo $metadata)
 {
     $methods = [];
     foreach ($metadata->fieldMappings as $fieldMapping) {
         $columnName = $fieldMapping['columnName'];
         if (in_array($fieldMapping['type'], ['integer', 'datetime', 'boolean'])) {
             $methods[] = CodeGeneratorHelper::render($this->getMethodCodeByName(CondMethodBody::class, '____fieldNameScalar____'), array('fieldNameScalar' => $fieldMapping['fieldName'], 'ColumnName' => $columnName, 'OP' => '='), self::KEY_TEMPLATE);
         }
         if (in_array($fieldMapping['type'], ['string', 'guid', 'text'])) {
             $methods[] = CodeGeneratorHelper::render($this->getMethodCodeByName(CondMethodBody::class, '____fieldNameScalar____'), array('fieldNameScalar' => $fieldMapping['fieldName'], 'ColumnName' => $columnName, 'OP' => 'LIKE'), self::KEY_TEMPLATE);
         }
     }
     foreach ($metadata->embeddedClasses as $fieldName => $embeddedClass) {
     }
     foreach ($metadata->associationMappings as $associationMapping) {
         switch ($associationMapping['type']) {
             case ClassMetadataInfo::MANY_TO_ONE:
                 $fieldName = $associationMapping['fieldName'];
                 $targetEntity = CodeGeneratorHelper::fqn($associationMapping['targetEntity']);
                 $columnName = $associationMapping['joinColumns'][0]['name'];
                 $referenceColumnName = $associationMapping['joinColumns'][0]['referencedColumnName'];
                 $targetQueryCollection = CodeGeneratorHelper::fqn($this->helper->getQueryCollectionClassNameByEntityClass($targetEntity));
                 $getterName = CodeGeneratorHelper::getGetterNameByFieldName($this->getFieldNameByColumnName($metadatas, $targetEntity, $referenceColumnName));
                 $targetMetadata = CodeGeneratorHelper::findMetadataByClassName($metadatas, $targetEntity);
                 $methods[] = CodeGeneratorHelper::render($this->getMethodCodeByName(CondMethodBody::class, '____fieldNameManyToOne____'), array('fieldNameManyToOne' => $fieldName, 'ColumnName' => $columnName, 'FilterByEntityFullQualifiedClassName' => $targetEntity, 'QueryCollectionSimpleClassName' => $targetQueryCollection, 'OP' => '=', 'getterName' => $getterName, 'primaryKey' => CodeGeneratorHelper::getPrimaryKeyName($targetMetadata)), self::KEY_TEMPLATE);
                 break;
             case ClassMetadataInfo::ONE_TO_MANY:
                 break;
             case ClassMetadataInfo::MANY_TO_MANY:
                 break;
         }
     }
     return implode("\n", $methods);
 }
 public function getBaseQueryCollectionClassNameFqn()
 {
     return CodeGeneratorHelper::fqn(BaseQueryCollection::class);
 }