SHARE
TWEET

Untitled

a guest Oct 17th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $app = new TestApplication;
  4. $app->run();
  5.  
  6. class TestApplication
  7. {
  8.     public function run()
  9.     {
  10.  
  11.         $post = new Post("Tutorial membuat CRUD dengan Laravel: [youtube id=HmV4gXIkP6k]");
  12.         echo $post->getHtmlContent();
  13.  
  14.         $post = new Post("Tutorial membuat CRUD dengan Laravel: [youtube id=HmV4gXIkP6k]" .
  15.                          "Contoh kode bisa dilihat di bawah ini: [gist id=9fdb82372bd10b5627e0]");
  16.  
  17.         echo $post->getHtmlContent();
  18.  
  19.     }
  20. }
  21.  
  22. class Post
  23. {
  24.     protected $content;
  25.  
  26.     public function __construct($content)
  27.     {
  28.         $this->content = $content;  
  29.  
  30.         $methods = get_class_methods($this);
  31.        
  32.         foreach ($methods as $method) {
  33.             if ($method == '__construct' || $method == 'getHtmlContent') {
  34.                 continue;
  35.             }
  36.            
  37.             $this->{$method}();
  38.         }
  39.  
  40.     }
  41.  
  42.     public function getHtmlContent()
  43.     {
  44.         return $this->content;// YOUR CODE HERE
  45.     }
  46.  
  47.     public function shortYoutube()
  48.     {
  49.         if (strpos($this->content, '[youtube id=')) {
  50.             return str_replace('number link', 'embeded link', $this->content);
  51.         }
  52.        
  53.     }
  54.  
  55.     public function shortGist()
  56.     {
  57.         if (strpos($this->content, 'gist id=')) {
  58.             return str_replace('number link', 'embeded link', $this->content);
  59.         }
  60.     }
  61.  
  62.     // JUST WRITE OTHER FUNCTION IF NEED TO TRANSLATE NEW SHORTTAG
  63. }
  64.  
  65.  
  66.  
  67. // OR HERE, IF YOU REALLY NEED TO WRITE ANOTHER FUNCTION OR CLASS OR INTERFACE OR TRAIT
RAW Paste Data
Top