fork download
  1. <?php
  2.  
  3.  
  4. class Console
  5. {
  6. public $lastLineClosed = true;
  7. public function __construct($closeLine=true) {
  8. $this->lastLineClosed = $closeLine;
  9.  
  10. }
  11. public function __destruct() {
  12. if (!$this->lastLineClosed) {
  13. echo PHP_EOL;
  14. }
  15. }
  16.  
  17. public function __call($name, $arguments) { //немного больше магии
  18. call_user_func_array($name,$arguments);
  19. return $this;
  20. }
  21.  
  22. public function log($text)
  23. {
  24. if ($this->lastLineClosed) {
  25. echo 'out says: ';
  26. $text=ucfirst ($text);
  27. } else {
  28. $text=" ".$text;
  29. }
  30. echo $text;
  31. if ($this->lastLineClosed) {
  32. return new Console(false);
  33. }
  34. return $this;
  35. }
  36. }
  37.  
  38. echo "---------\n";
  39. $console = new Console;
  40. $console ->log('Hello');
  41. $console ->log('world');
  42.  
  43. $console ->log('Hello')->log('world');
  44. $console ->log('Hello')->log('world')->magic_run(" magic! ")->log(2);
  45. echo "---------\n";
  46.  
  47.  
  48. function magic_run($arg) {
  49. sleep(3);
  50. echo " -==$arg==-";
  51.  
  52. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
---------
out says: Hello
out says: World
out says: Hello world
out says: Hello world -== magic! ==- 2
---------