Helpers.trait.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Encapsulate all the helper functions into a trait that we can apply to multiple classes.
  4. * PHP 5.4 Functionality
  5. * @author ironpilot
  6. *
  7. */
  8. trait Staple_Trait_Helpers
  9. {
  10. /**
  11. * Generate a relative link within the framework.
  12. * @param mixed $route
  13. * @param array $get
  14. * @return string
  15. */
  16. public function link($route, array $get = array())
  17. {
  18. return Staple_Link::get($route,$get);
  19. }
  20. /**
  21. * Function accepts a string and returns the htmlentities version of the string. The
  22. * optional bool $strip will also return the string with HTML tags stripped.
  23. * @param string $str
  24. * @param bool $strip
  25. * @return string
  26. */
  27. public function escape($str, $strip = false)
  28. {
  29. if($str instanceof DateTime)
  30. {
  31. return htmlentities($str->format('Y-m-d H:i:s'));
  32. }
  33. elseif($strip === true)
  34. {
  35. $estring = htmlentities(strip_tags($estring));
  36. }
  37. else
  38. {
  39. return htmlentities($str);
  40. }
  41. }
  42. /**
  43. * Encapsulate object instantiation to enable chaining. Given a class this function simply returns the class reference.
  44. * @param stdClass $obj
  45. * @return stdClass
  46. */
  47. public function with(stdClass $obj)
  48. {
  49. return $obj;
  50. }
  51. public function dump()
  52. {
  53. Staple_Dev::Dump(func_get_args());
  54. }
  55. }
  56. ?>