bootstrap.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2017 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. require dirname(__FILE__) . '/../src/Mustache/Autoloader.php';
  11. Mustache_Autoloader::register();
  12. Mustache_Autoloader::register(dirname(__FILE__) . '/../test');
  13. /**
  14. * Minimal stream wrapper to test protocol-based access to templates.
  15. */
  16. class TestStream
  17. {
  18. private $filehandle;
  19. /**
  20. * Always returns false.
  21. *
  22. * @param string $path
  23. * @param int $flags
  24. *
  25. * @return array
  26. */
  27. public function url_stat($path, $flags)
  28. {
  29. return false;
  30. }
  31. /**
  32. * Open the file.
  33. *
  34. * @param string $path
  35. * @param string $mode
  36. *
  37. * @return bool
  38. */
  39. public function stream_open($path, $mode)
  40. {
  41. $path = preg_replace('-^test://-', '', $path);
  42. $this->filehandle = fopen($path, $mode);
  43. return $this->filehandle !== false;
  44. }
  45. /**
  46. * @return array
  47. */
  48. public function stream_stat()
  49. {
  50. return array();
  51. }
  52. /**
  53. * @param int $count
  54. *
  55. * @return string
  56. */
  57. public function stream_read($count)
  58. {
  59. return fgets($this->filehandle, $count);
  60. }
  61. /**
  62. * @return bool
  63. */
  64. public function stream_eof()
  65. {
  66. return feof($this->filehandle);
  67. }
  68. /**
  69. * @return bool
  70. */
  71. public function stream_close()
  72. {
  73. return fclose($this->filehandle);
  74. }
  75. }
  76. if (!stream_wrapper_register('test', 'TestStream')) {
  77. die('Failed to register protocol');
  78. }