bootstrap.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. *
  26. * @return array
  27. */
  28. public function url_stat($path, $flags)
  29. {
  30. return false;
  31. }
  32. /**
  33. * Open the file.
  34. *
  35. * @param string $path
  36. * @param string $mode
  37. *
  38. * @return bool
  39. */
  40. public function stream_open($path, $mode)
  41. {
  42. $path = preg_replace('-^test://-', '', $path);
  43. $this->filehandle = fopen($path, $mode);
  44. return $this->filehandle !== false;
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function stream_stat()
  50. {
  51. return [];
  52. }
  53. /**
  54. * @param int $count
  55. *
  56. * @return string
  57. */
  58. public function stream_read($count)
  59. {
  60. return fgets($this->filehandle, $count);
  61. }
  62. /**
  63. * @return bool
  64. */
  65. public function stream_eof()
  66. {
  67. return feof($this->filehandle);
  68. }
  69. /**
  70. * @return bool
  71. */
  72. public function stream_close()
  73. {
  74. return fclose($this->filehandle);
  75. }
  76. }
  77. stream_wrapper_register('test', TestStream::class)
  78. || die('Failed to register protocol');