PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

http://github.com/radiosilence/Ham
Markdown | 185 lines | 128 code | 57 blank | 0 comment | 0 complexity | 3c3e5ec801e066bd64fb8e55ee01183f MD5 | raw file
Possible License(s): BSD-2-Clause
  1. Ham
  2. ===
  3. *Now includes tests!*
  4. PHP Microframework for use with whatever you like. Basically just a fast router
  5. with nice syntax, and a cache singleton. Will add more things as I go, like
  6. perhaps an extension system, autoloader and some other stuff to make developing
  7. in PHP less irritating than it currently is.
  8. Routes are converted to regex and cached so this process does not need to
  9. happen every request. Furthermore, the resolved route for a given URI is also
  10. cached so on most requests thare is no regex matching involved.
  11. There is also now the ability to mount apps on routes within apps, so one could
  12. make an administrator app, then mount it on the main app at /admin.
  13. PHP presents an interesting challenge because due to it's architecture,
  14. everything has to be re-done each request, which is why I'm leveraging caching
  15. with tiny TTLs to share the results of operations like route resolution
  16. between requests.
  17. Note: PHP already has many of the features that many microframeworks have, such
  18. as session handling, cookies, and templating. An aim of this project is to
  19. encourage the use of native functionality where possible or where it is good,
  20. but make some parts nicer or extend upon them to bring it up to scratch with
  21. the way I like things.
  22. Note: For maximum speed gains, use the XCache extension because that supports
  23. caching of closures, unlike APC.
  24. Goals
  25. -----
  26. * Make pretty much anything I/O related cached with XCache/APC
  27. (whichever is installed) in order to prevent excessive disk usage or path
  28. searching on lots of requests.
  29. * Provide a succinct syntax that means less magic and less code to read
  30. through and learn, without compromising speed or code length, by using native
  31. PHP methods and features.
  32. * Promote a simple, flat way of building applications that don't need
  33. massive levels of abstraction.
  34. * Encourage use of excellent third-party libraries such as Doctrine to prevent
  35. developers writing convoluted, unmaintainable code that people like me have to
  36. pick up and spend hours poring over just to get an idea of what on earth is
  37. going on.
  38. * Define and document development patterns that allow for new developers to
  39. get up to speed quickly and write new code that isn't hacky.
  40. Inspired entirely by Flask.
  41. Requirements
  42. ------------
  43. * PHP 5.3
  44. * XCache (preferred) or APC (still optional)
  45. * Requests pointed at file that you put the app in (eg.
  46. index.php).
  47. Hello World
  48. -----------
  49. ```php
  50. require '../ham/ham.php';
  51. $app = new Ham('example');
  52. $app->route('/', function($app) {
  53. return 'Hello, world!';
  54. });
  55. $app->run();
  56. ```
  57. More Interesting Example
  58. ------------------------
  59. ```php
  60. require '../ham/ham.php';
  61. $app = new Ham('example');
  62. $app->config_from_file('settings.php');
  63. $app->route('/pork', function($app) {
  64. return "Delicious pork.";
  65. });
  66. $hello = function($app, $name='world') {
  67. return $app->render('hello.html', array(
  68. 'name' => $name
  69. ));
  70. };
  71. $app->route('/hello/<string>', $hello);
  72. $app->route('/', $hello);
  73. $app->run();
  74. ```
  75. Multiple apps mounted on routes!
  76. --------------------------------
  77. ```php
  78. require '../ham/ham.php';
  79. $beans = new Ham('beans');
  80. $beans->route('/', function($app) {
  81. return "Beans home.";
  82. });
  83. $beans->route('/baked', function($app) {
  84. return "Yum!";
  85. });
  86. $app = new Ham('example');
  87. $app->route('/', function($app) {
  88. return "App home.";
  89. });
  90. $app->route('/beans', $beans);
  91. $app->run();
  92. ```
  93. Custom Error Handeling
  94. --------------------------------
  95. ```php
  96. require 'ham/ham.php';
  97. $beans = new Ham('beans');
  98. $beans->route('/', function($app) {
  99. return "Beans home.";
  100. });
  101. $app->onError(function(){
  102. return "Burnt Bacon.";
  103. }, "Error message can go here.");
  104. $app->run();
  105. ```
  106. Output:
  107. #### /beans/
  108. Beans home.
  109. #### /beans/baked
  110. Yum!
  111. #### /
  112. App home.
  113. #### /definitely_not_the_page_you_were_looking_for
  114. Burnt Bacon.
  115. Have a gander at the example application for more details.
  116. To-Dos
  117. ------
  118. * Nice logging class and logging support with error levels, e-mailing, etc.
  119. * Sub-application mounting (ala Flask "Blueprints").
  120. * Sanitisation solution.
  121. * CSRF tokens
  122. * Extension API
  123. Extension Ideas
  124. ---------------
  125. * Form generation (3rd-party? Phorms)
  126. * ORM integration (most likely Doctrine)
  127. * Auth module (using scrypt or something)
  128. * Admin extension