bootstrap.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2016 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. require dirname(__FILE__) . '/../vendor/yaml/lib/sfYamlParser.php';
  14. /**
  15. * Minimal stream wrapper to test protocol-based access to templates
  16. */
  17. class TestStream
  18. {
  19. private $filehandle;
  20. /**
  21. * Always returns false
  22. *
  23. * @param string $path
  24. * @param int $flags
  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. * @return bool
  37. */
  38. public function stream_open($path, $mode)
  39. {
  40. $path = preg_replace('-^test://-', '', $path);
  41. $this->filehandle = fopen($path, $mode);
  42. return $this->filehandle !== false;
  43. }
  44. /**
  45. * @return array
  46. */
  47. public function stream_stat()
  48. {
  49. return [];
  50. }
  51. /**
  52. * @param int $count
  53. * @return string
  54. */
  55. public function stream_read($count)
  56. {
  57. return fgets($this->filehandle, $count);
  58. }
  59. /**
  60. * @return bool
  61. */
  62. public function stream_eof()
  63. {
  64. return feof($this->filehandle);
  65. }
  66. /**
  67. * @return bool
  68. */
  69. public function stream_close()
  70. {
  71. return fclose($this->filehandle);
  72. }
  73. }
  74. stream_wrapper_register('test', TestStream::class)
  75. || die('Failed to register protocol');