/** * @param \Protobuf\Stream $stream * * @return \Protobuf\Stream */ public function compile(Stream $stream) { // Parse the request $request = CodeGeneratorRequest::fromStream($stream, $this->config); $response = new CodeGeneratorResponse(); $context = $this->createContext($request); $entities = $context->getEntities(); $options = $context->getOptions(); $generator = new Generator($context); // whether or not it will renegerate classes with new extensions $regenerate = false; $hasExtension = $context->hasProtobufExtension(); // Run each entity foreach ($entities as $key => $entity) { $generateImported = $options->getGenerateImported(); $isFileToGenerate = $entity->isFileToGenerate(); // Only compile those given to generate, not the imported ones if (!$generateImported && !$isFileToGenerate) { $this->logger->debug(sprintf('Skipping generation of imported class "%s"', $entity->getClass())); continue; } $this->logger->info(sprintf('Generating class "%s"', $entity->getClass())); $generator->visit($entity); $file = new File(); $path = $entity->getPath(); $content = $entity->getContent(); $file->setName($path); $file->setContent($content); $response->addFile($file); if ($hasExtension && $this->loadEntityClass($entity)) { $regenerate = true; } } if ($regenerate) { $this->logger->info('Regenerating classes with new extensions'); $stream->seek(0); // Renegerate classes with new extensions return $this->compile($stream); } $this->logger->info('Generation completed.'); // Finally serialize the response object return $response->toStream($this->config); }