/** * @param Database $db * @param string $propertyType * @param string $searchBy * @return Collection|CodepointAssigned[] * @throws UnexpectedValueException */ private function resolveCodepoints(Database $db, $propertyType, $searchBy) { switch ($propertyType) { case self::PROPERTY_BLOCK: $block = Block::fromValue($searchBy); return $db->getByBlock($block); case self::PROPERTY_CATEGORY: $category = GeneralCategory::fromValue($searchBy); return $db->getByCategory($category); case self::PROPERTY_SCRIPT: $script = Script::fromValue($searchBy); return $db->getByScript($script); } throw new UnexpectedValueException(); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $start = microtime(true); $encoding = $input->getOption(self::OPTION_ENCODING); $codepointValue = $input->getArgument(self::ARGUMENT_CODEPOINT); $codepoint = $this->valueToCodepoint($codepointValue, $encoding); $from = $input->getOption(self::OPTION_FROM); $repository = $this->getRepositoryByName($from); $db = new Database($repository); $exporter = new Exporter(); try { $character = $db->getCharacterByCodepoint($codepoint); } catch (CharacterNotFoundException $e) { $output->writeln('<error>Character Not Found</error>'); return 1; } $output->writeln('<info>Character Found</info>'); $output->writeln(sprintf('Export: %s', $exporter->export($character))); $output->writeln(sprintf('UTF-8: %s', $codepoint->toUTF8())); $output->writeln(sprintf('Memory peak: %.5f MB', memory_get_peak_usage() / 1048576)); $output->writeln(sprintf('Took: %.5f seconds', microtime(true) - $start)); return 0; }