Factory method for the Annotation Driver

@param  array|string     $paths
@param  Reader           $reader
@return AnnotationDriver
496214
public static function create($paths = array(), Reader $reader = null)
    {
        if ($reader == null) {
            $reader = new AnnotationReader();
        }

        return new self($reader, $paths);
    }
1299413
public function parseFiles(
        Finder $finder,
        Reader $reader,
        WorkerCollection $workerCollection
    )
    {

        /**
         * Every file found is parsed
         */
        foreach ($finder as $file) {

            /**
             * File is accepted to be parsed
             */
            $classNamespace = $this->getFileClassNamespace($file->getRealpath());
            $reflectionClass = new ReflectionClass($classNamespace);
            $classAnnotations = $reader->getClassAnnotations($reflectionClass);

            /**
             * Every annotation found is parsed
             */
            foreach ($classAnnotations as $annotation) {

                /**
                 * Annotation is only laoded if is typeof WorkAnnotation
                 */
                if ($annotation instanceof WorkAnnotation) {

                    /**
                     * Creates new Worker element with all its Job data
                     */
                    $worker = new Worker($annotation, $reflectionClass, $reader, $this->servers, $this->defaultSettings);
                    $workerCollection->add($worker);
                }
            }
        }

        return $this;
    }
1178168
private function findReader(ReflectionClass $class): Reader
    {
        $className = $class->getName();
        foreach ($this->chainDriver->getDrivers() as $namespace => $driver) {
            if (mb_stripos($className, $namespace) === 0) {
                if ($driver instanceof AnnotationDriver) {
                    return $driver->getReader();
                }
            }
        }

        if ($this->chainDriver->getDefaultDriver() instanceof AnnotationDriver) {
            return $this->chainDriver->getDefaultDriver()->getReader();
        }

        throw new Exception('graphql-doctrine requires ' . $className . ' entity to be configured with a `' . AnnotationDriver::class . '`.');
    }
41797
private static function getReader(): Reader
    {
        if (self::$annotationReader === null) {
            self::$annotationReader = AspectKernel::getInstance()->getContainer()->get('aspect.annotation.reader');
        }

        return self::$annotationReader;
    }
1099571
private function initAnnotationReader()
    {
        AnnotationRegistry::registerFile(
            $this->getVendorDir().'/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
        );

        // annotations require custom autoloading
        AnnotationRegistry::registerAutoloadNamespaces([
            'JMS\Serializer\Annotation' => $this->getVendorDir().'/jms/serializer/src/',
        ]);

        AnnotationRegistry::registerLoader(function ($classname) {
            if (0 === strpos($classname, 'BackBee')) {
                return class_exists($classname);
            }

            if (0 === strpos($classname, 'Symfony\Component\Validator\Constraints')) {
                return class_exists($classname);
            }

            return false;
        });
    }
722526
public static function createFromReader(Reader $reader) : Styler
    {
        $classname = \get_called_class(); // para permitir abstração
        $instance = new $classname;
        $instance->reader = $reader;

        return $instance;
    }
1332479
public function newDefaultAnnotationDriver(array $paths = array())
    {
        $reader = new \Doctrine\Common\Annotations\AnnotationReader();

        return new \Doctrine\Search\Mapping\Driver\AnnotationDriver($reader, $paths);
    }
662566
private function configureMetadataDriver(array $config, ContainerBuilder $container)
    {
        $container->register('doctrine.key_value.metadata.annotation.reader', 'Doctrine\Common\Annotations\AnnotationReader')
            ->setPublic(false);

        $container->register('doctrine.key_value.metadata.annotation', 'Doctrine\KeyValueStore\Mapping\AnnotationDriver')
            ->setPublic(false)
            ->addArgument(new Reference('doctrine.key_value.metadata.annotation.reader'));
    }
1278466
public function tokenize(Reader $reader)
    {
        $stream = new TokenStream();

        while (!$reader->isEOF()) {
            foreach ($this->handlers as $handler) {
                if ($handler->handle($reader, $stream)) {
                    continue 2;
                }
            }

            $stream->push(new Token(Token::TYPE_DELIMITER, $reader->getSubstring(1), $reader->getPosition()));
            $reader->moveForward(1);
        }

        return $stream
            ->push(new Token(Token::TYPE_FILE_END, null, $reader->getPosition()))
            ->freeze();
    }
1290762
public function createAnnotationReader($simple = TRUE, Array $ignoredAnnotations = array()) {
    if ($simple) {
      $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
      $reader->addNamespace('Doctrine\ORM\Mapping');
    } else {
      $reader = new \Doctrine\Common\Annotations\AnnotationReader();
    }

    foreach ($ignoredAnnotations as $ignore) {
      $reader->addGlobalIgnoredName($ignore);
    }

    $reader = new \Doctrine\Common\Annotations\CachedReader($reader, $this->getCache());

    return $reader;
  }
276614
private function readerOperation(\XmlReader $reader, $method, array $args = [])
    {
        // clear any previous errors
        libxml_clear_errors();

        // remember current settings
        $errors = libxml_use_internal_errors(true);
        $entities = libxml_disable_entity_loader(true);

        // perform the operation
        $retval = call_user_func_array([$reader, $method], $args);

        // get the last error, if any
        $error = $this->getXmlError();

        // reset everything, clear the error buffer again
        libxml_clear_errors();
        libxml_use_internal_errors($errors);
        libxml_disable_entity_loader($entities);

        if (!empty($error)) {
            throw new ReadException($error);
        }

        return $retval;
    }
275652
protected function addIgnoredNames(AnnotationReader $reader)
    {
        foreach ($this->ignoredNames as $name) {
            $reader->addGlobalIgnoredName($name);
        }

        return $reader;
    }
179967
private function buildRouteDefinition(CachedReader $reader, \ReflectionClass $controllerReflClass)
    {
        $routeDefinitions = [];

        if ($controllerReflClass->isInstantiable()) {
            $annotations = $reader->getClassAnnotations($controllerReflClass);
            foreach ($annotations as $annotation) {
                if ($annotation instanceof Route) {
                    $annotation->controller = $controllerReflClass->getName();
                    $this->autoDetectEntity($annotation);
                    $routeDefinitions[] = (array)$annotation;
                }
            }

            foreach ($controllerReflClass->getMethods() as $method) {
                $annotations = $reader->getMethodAnnotations($method);
                foreach ($annotations as $annotation) {
                    if ($annotation instanceof Route) {
                        $annotation->controller = $controllerReflClass->getName();
                        $annotation->method = $method->getName();
                        $this->autoDetectEntity($annotation);
                        $routeDefinitions[] = (array)$annotation;
                    }
                }
            }
        }

        return $routeDefinitions;
    }
1024528
protected function getAnnotationReader()
    {
        if ($this->packageSupportsLegacyCore()) {
            $reader = $this->getLegacyAnnotationReader();
        } else {
            $reader = $this->getStandardAnnotationReader();
        }
        return $reader;
    }
770754
final function FetchFromReader(DBInterfaces\IDatabaseReader $reader)
    {
        $objects = array();
        while($reader->Read())
        {
            $object = $this->CreateInstance($reader->ByName($this->KeyField()));
            $object->InitFromReader($reader);
            $objects[] = $object;
        }
        $reader->Close();
        return $objects;
    }
126944
public function createDriver($options = [])
    {
        $options = $this->optionsResolver->resolve($options);

        return new CollectionDriver($this->extensions, $options['collection'], $options['criteria']);
    }
237344
@Override
  public MtasTokenCollection createTokenCollection(Reader reader)
      throws MtasParserException, MtasConfigException {
    AtomicInteger position = new AtomicInteger(0);
    MtasCRMAncestors unknownAncestors = new MtasCRMAncestors();

    Map<String, Set<Integer>> idPositions = new HashMap<>();
    Map<String, Integer[]> idOffsets = new HashMap<>();

    Map<String, Map<Integer, Set<String>>> updateList = createUpdateList();
    Map<String, List<MtasParserObject>> currentList = createCurrentList();

    tokenCollection = new MtasTokenCollection();
    MtasTokenIdFactory mtasTokenIdFactory = new MtasTokenIdFactory();
    try (MtasBufferedReader br = new MtasBufferedReader(reader)) {
      String line;
      int currentOffset;
      int previousOffset = br.getPosition();
      MtasParserObject currentObject;
      Pattern headerPattern = Pattern.compile("^@ @ @(.*)$");
      Pattern regularPattern = Pattern.compile(
          "^([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)$");
      Matcher matcherHeader;
      Matcher matcherRegular = null;
      Set<MtasParserObject> newPreviousSentence = new HashSet<>();
      Set<MtasParserObject> previousSentence = new HashSet<>();
      Set<MtasParserObject> newPreviousClause = new HashSet<>();
      Set<MtasParserObject> previousClause = new HashSet<>(); 
      String[] matcherList = new String[8];
      while ((line = br.readLine()) != null) {
        currentOffset = br.getPosition();
        matcherHeader = headerPattern.matcher(line.trim());
        matcherRegular = regularPattern.matcher(line.trim());
        if (matcherRegular.matches()) {
          newPreviousSentence.clear();
          matcherList = createMatcherList(matcherRegular); 
          for (int i = 4; i < 8; i++) {
            List<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
            Set<MtasParserObject> tmpList = processCRMSentence(
                mtasTokenIdFactory, String.valueOf(i),
                matcherList[i], currentOffset,
                functionOutputList, unknownAncestors, currentList, updateList,
                idPositions, idOffsets, previousSentence, previousClause);
            if (tmpList != null) {
              newPreviousSentence.addAll(tmpList);
            }
            for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
              tmpList = processCRMSentence(mtasTokenIdFactory,
                  functionOutput.name, functionOutput.value, currentOffset,
                  functionOutputList, unknownAncestors, currentList, updateList,
                  idPositions, idOffsets, previousSentence, previousClause);
              if (tmpList != null) {
                newPreviousSentence.addAll(tmpList);
              }
            }
          }
          if (!newPreviousSentence.isEmpty()) {
            previousSentence.clear();
            previousSentence.addAll(newPreviousSentence);
          }
          newPreviousClause.clear();
          for (int i = 4; i < 8; i++) {
            ArrayList<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
            Set<MtasParserObject> tmpList = processCRMClause(mtasTokenIdFactory,
                String.valueOf(i), matcherList[i], currentOffset,
                functionOutputList, unknownAncestors, currentList, updateList,
                idPositions, idOffsets, previousClause);
            if (tmpList != null) {
              newPreviousClause.addAll(tmpList);
            }
            for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
              tmpList = processCRMClause(mtasTokenIdFactory,
                  functionOutput.name, functionOutput.value, currentOffset,
                  functionOutputList, unknownAncestors, currentList, updateList,
                  idPositions, idOffsets, previousClause);
              if (tmpList != null) {
                newPreviousClause.addAll(tmpList);
              }
            }
          }
          if (!newPreviousClause.isEmpty()) {
            previousClause.clear();
            previousClause.addAll(newPreviousClause);
          }
        }

        if (matcherRegular.matches() && !matcherHeader.matches()) {
          matcherRegular = regularPattern.matcher(line.trim());
          if (matcherRegular.matches()) {
            // regular line - start word
            currentObject = new MtasParserObject(wordType);
            currentObject.setOffsetStart(previousOffset);
            currentObject.setRealOffsetStart(previousOffset);
            currentObject.setUnknownAncestorNumber(unknownAncestors.unknown);
            if (!prevalidateObject(currentObject, currentList)) {
              unknownAncestors.unknown++;
            } else {
              int p = position.getAndIncrement();
              currentObject.addPosition(p);
              currentObject.objectId = "word_" + p;
              currentList.get(MAPPING_TYPE_WORD).add(currentObject);
              unknownAncestors.unknown = 0;
              // check for crmPair
              for (int i = 0; i < 8; i++) {
                List<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
                processCRMPair(mtasTokenIdFactory, p, String.valueOf(i),
                    matcherList[i], currentOffset,
                    functionOutputList, unknownAncestors, currentList,
                    updateList, idPositions, idOffsets);
                for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
                  processCRMPair(mtasTokenIdFactory, p, functionOutput.name,
                      functionOutput.value, currentOffset, functionOutputList,
                      unknownAncestors, currentList, updateList, idPositions,
                      idOffsets);
                }
              }
              // compute word annotations
              for (int i = 0; i < 8; i++) {
                ArrayList<MtasCRMParserFunctionOutput> functionOutputList = new ArrayList<>();
                functionOutputList
                    .addAll(processWordAnnotation(mtasTokenIdFactory,
                        String.valueOf(i), matcherList[i],
                        previousOffset, currentOffset, unknownAncestors,
                        currentList, updateList, idPositions, idOffsets));
                for (MtasCRMParserFunctionOutput functionOutput : functionOutputList) {
                  processWordAnnotation(mtasTokenIdFactory, functionOutput.name,
                      functionOutput.value, previousOffset, currentOffset,
                      unknownAncestors, currentList, updateList, idPositions,
                      idOffsets);
                }
              }
            }
            // finish word
            if (unknownAncestors.unknown > 0) {
              unknownAncestors.unknown--;
            } else {
              currentObject = currentList.get(MAPPING_TYPE_WORD)
                  .remove(currentList.get(MAPPING_TYPE_WORD).size() - 1);
              assert unknownAncestors.unknown == 0 : "error in administration "
                  + currentObject.getType().getName();
              currentObject.setText(null);
              currentObject.setOffsetEnd(currentOffset - 1);
              currentObject.setRealOffsetEnd(currentOffset - 1);
              // update ancestor groups with position and offset
              for (MtasParserObject currentGroup : currentList
                  .get(MAPPING_TYPE_GROUP)) {
                currentGroup.addPositions(currentObject.getPositions());
                currentGroup.addOffsetStart(currentObject.getOffsetStart());
                currentGroup.addOffsetEnd(currentObject.getOffsetEnd());
              }
              idPositions.put(currentObject.getId(),
                  currentObject.getPositions());
              idOffsets.put(currentObject.getId(), currentObject.getOffset());
              currentObject.updateMappings(idPositions, idOffsets);
              unknownAncestors.unknown = currentObject
                  .getUnknownAncestorNumber();
              computeMappingsFromObject(mtasTokenIdFactory, currentObject,
                  currentList, updateList);
            }

          } else {
            // System.out.println("PROBLEM: " + line);
          }
        }
        previousOffset = br.getPosition();
      }
      closePrevious(mtasTokenIdFactory, previousSentence, previousOffset,
          unknownAncestors, currentList, updateList, idPositions, idOffsets);
      closePrevious(mtasTokenIdFactory, previousClause, previousOffset,
          unknownAncestors, currentList, updateList, idPositions, idOffsets);
    } catch (IOException e) {
      log.debug(e);
      throw new MtasParserException(e.getMessage());
    }
    // final check
    tokenCollection.check(autorepair, makeunique);
    return tokenCollection;

  }