SHARE
TWEET

MarkdownTransformer.php

eniine Aug 26th, 2017 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top