Advertisement
eniine

MarkdownTransformer.php

Aug 26th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: eni
  5. * Date: 17-08-25
  6. * Time: 11.12.PD
  7. */
  8.  
  9. namespace AppBundle\Service;
  10.  
  11.  
  12. use Doctrine\Common\Cache\Cache;
  13. use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
  14.  
  15.  
  16. class MarkdownTransformer
  17. {
  18. private $markdownParser;
  19. private $cache;
  20. public function __construct(MarkdownParserInterface $markdownParser,Cache $cache)
  21. {
  22. $this->markdownParser = $markdownParser;
  23. $this->cache = $cache;
  24. }
  25. public function parse($str)
  26. {
  27. $cache = $this->cache;
  28. $key = md5($str);
  29. if ($cache->contains($key)) {
  30. return $cache->fetch($key);
  31. }
  32. sleep(1);
  33. $str = $this->markdownParser
  34. ->transformMarkdown($str);
  35. $cache->save($key, $str);
  36. return $str;
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement