PageRenderTime 29ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/Phrozn/Twig/Loader/String.php

http://github.com/farazdagi/phrozn
PHP | 50 lines | 15 code | 2 blank | 33 comment | 1 complexity | b42e7100117c0e2a3472ac32ac5108f4 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /**
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. *
  15. * @category Phrozn
  16. * @package Phrozn\Twig
  17. * @author Victor Farazdagi
  18. * @license http://www.apache.org/licenses/LICENSE-2.0
  19. */
  20. namespace Phrozn\Twig\Loader;
  21. /**
  22. * Twig String Loader
  23. *
  24. * @category Phrozn
  25. * @package Phrozn\Processor
  26. * @author Victor Farazdagi
  27. */
  28. class String
  29. extends \Twig_Loader_String
  30. implements \Twig_LoaderInterface
  31. {
  32. /**
  33. * Gets the source code of a template, given its name.
  34. *
  35. * @param string $name Template content
  36. *
  37. * @return string The template source code
  38. */
  39. public function getSource($name)
  40. {
  41. // strip front-matter
  42. $parts = preg_split('/[\n]*[-]{3}[\n]/', $name, 2);
  43. if (count($parts) === 2) {
  44. return ltrim($parts[1]);
  45. }
  46. return $name;
  47. }
  48. }