abstract.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * Abstract methods that might be redefined by user
  4. * Do not include this file in your app: it only aims to provide documentation
  5. * about those functions.
  6. *
  7. * @package limonade
  8. * @subpackage abstract
  9. */
  10. /**
  11. * It will be called when app is launched (at the begining of the run function).
  12. * You can define options inside it, a connection to a database ...
  13. *
  14. * @abstract this function might be redefined by user
  15. * @return void
  16. */
  17. function configure()
  18. {
  19. return;
  20. }
  21. /**
  22. * Called in run() just after session start, and before checking request method
  23. * and output buffer start.
  24. *
  25. * @abstract this function might be redefined by user
  26. * @return void
  27. */
  28. function initialize()
  29. {
  30. return;
  31. }
  32. /**
  33. * Called in run() just after the route matching, in order to load controllers.
  34. * If not specfied, the default function is called:
  35. *
  36. * <code>
  37. * function autoload_controller($callback)
  38. * {
  39. * require_once_dir(option('controllers_dir'));
  40. * }
  41. * </code>
  42. *
  43. *
  44. * @param string $callback the callback defined in matching route
  45. * @return void
  46. */
  47. function autoload_controller($callback)
  48. {
  49. return;
  50. }
  51. /**
  52. * Called before each request.
  53. * This is very useful to define a default layout or passing common variables
  54. * to the templates.
  55. *
  56. * @abstract this function might be redefined by user
  57. * @param array() $route array (like returned by {@link route_build()},
  58. * with keys "method", "pattern", "names", "callback", "options")
  59. * @return void
  60. */
  61. function before($route)
  62. {
  63. }
  64. /**
  65. * An `after` output filter
  66. *
  67. * Called after each request and can apply a transformation to the output
  68. * (except for `render_file` outputs which are sent directly to the output buffer).
  69. *
  70. * @abstract this function might be redefined by user
  71. * @param string $output
  72. * @param array() $route array (like returned by {@link route_find()},
  73. * with keys "method", "pattern", "names", "callback", "params", "options")
  74. * @return string
  75. */
  76. function after($output, $route)
  77. {
  78. # Call functions...
  79. # .. modifies $output...
  80. return $output;
  81. }
  82. /**
  83. * Not found error output
  84. *
  85. * @abstract this function might be redefined by user
  86. * @param string $errno
  87. * @param string $errstr
  88. * @param string $errfile
  89. * @param string $errline
  90. * @return string "not found" output string
  91. */
  92. function not_found($errno, $errstr, $errfile=null, $errline=null)
  93. {
  94. }
  95. /**
  96. * Server error output
  97. *
  98. * @abstract this function might be redefined by user
  99. * @param string $errno
  100. * @param string $errstr
  101. * @param string $errfile
  102. * @param string $errline
  103. * @return string "server error" output string
  104. */
  105. function server_error($errno, $errstr, $errfile=null, $errline=null)
  106. {
  107. }
  108. /**
  109. * Called when a route is not found.
  110. *
  111. *
  112. * @abstract this function might be redefined by user
  113. * @param string $request_method
  114. * @param string $request_uri
  115. * @return void
  116. */
  117. function route_missing($request_method, $request_uri)
  118. {
  119. halt(NOT_FOUND, "($request_method) $request_uri"); # by default
  120. }
  121. /**
  122. * Called before stoppping and exiting application.
  123. *
  124. * @abstract this function might be redefined by user
  125. * @param boolean exit or not
  126. * @return void
  127. */
  128. function before_exit($exit)
  129. {
  130. }
  131. /**
  132. * Rendering prefilter.
  133. * Useful if you want to transform your views before rendering.
  134. * The first three parameters are the same as those provided
  135. * to the `render` function.
  136. *
  137. * @abstract this function might be redefined by user
  138. * @param string $content_or_func a function, a file in current views dir or a string
  139. * @param string $layout
  140. * @param array $locals
  141. * @param array $view_path (by default <code>file_path(option('views_dir'),$content_or_func);</code>)
  142. * @return array with, in order, $content_or_func, $layout, $locals vars
  143. * and the calculated $view_path
  144. */
  145. function before_render($content_or_func, $layout, $locals, $view_path)
  146. {
  147. # transform $content_or_func, $layout, $locals or $view_path…
  148. return array($content_or_func, $layout, $locals, $view_path);
  149. }
  150. /**
  151. * Called only if rendering $output is_null,
  152. * like in a controller with no return statement.
  153. *
  154. * @abstract this function might be defined by user
  155. * @param array() $route array (like returned by {@link route_build()},
  156. * with keys "method", "pattern", "names", "callback", "options")
  157. * @return string
  158. */
  159. function autorender($route)
  160. {
  161. # process output depending on $route
  162. return $output;
  163. }
  164. /**
  165. * Called if a header is about to be sent
  166. *
  167. * @abstract this function might be defined by user
  168. * @param string the headers that limonade will send
  169. * @return void
  170. */
  171. function before_sending_header($header)
  172. {
  173. }