Knotwerk: a collection of reusable OO PHP5 code

Note that this library is under development. The codebase is stable and of production quality, but the documentation is still catching up. You are welcome to use the code and follow updates using git, but a proper versioned release schedule is yet to be implemented.

The code forms a "full stack framework" in that no dependencies are required and the existing codebase forms a full MVC implementation: URL to controller mapping, template views and a collection of common model functionality.

  • MVC implementation with RESTful single URL to controller mapping.
  • Primary library focus is on simple form generation, validation and rendering.
  • User formatted input is accepted using a wiki-format lexer and rendering engine.
  • ACL functionality is included with user roles and authentication.
  • Based on the MySQL, SQLite or PostgreSQL database engines, and utilises a master-slave separation wrapper around the PDO extension.
  • Heavily utilises the concept of dependency injection to add flex points and ease of extension to the codebase (almost zero static methods!).
  • As far as possible code is unit tested using an in-built testing suite.

Some tempting code?

  1. <?php
  2. define('DEMO','Simple Enquiry Form');
  3. require dirname(__FILE__).'/inc/header.php';
  4. // CREATE FORM
  5. $form = new T_Form_Post('contact','Send Enquiry');
  6. $fieldset = new T_Form_Fieldset('details','Your Details');
  7. $form->addChild($fieldset);
  8. $fieldset->addChild(new T_Form_Text('name','Name'));
  9. $email = new T_Form_Text('email','Email');
  10. $email->attachFilter(new T_Validate_Email());
  11. $fieldset->addChild($email);
  12. $fieldset = new T_Form_Fieldset('enquiry','Your Question');
  13. $form->addChild($fieldset);
  14. $comment = new T_Form_TextArea('msg','Message');
  15. $fieldset->addChild($comment);
  16. $form->setForward($env->getRequestUrl());
  17. // VALIDATE FORM
  18. if ($env->isMethod('POST')) {
  19. $form->validate($env->input('POST'));
  20. }
  21. // ACTION FORM
  22. if ($form->isPresent() && $form->isValid()) {
  23. // action (e.g. email, etc.)
  24. echo '<p>Thanks for your submission <a href="mailto:',
  25. $form->search('email')->getValue(new T_Filter_Xhtml()),
  26. '">',$form->search('name')->getValue(new T_Filter_Xhtml()),
  27. '</a>!</p>';
  28. } else {
  29. // render form
  30. $error = new T_Form_XhtmlError();
  31. $render = new Demo_Form_Xhtml();
  32. $form->accept($error)
  33. ->accept($render);
  34. echo $error,$render;
  35. }
  36. require dirname(__FILE__).'/inc/footer.php';

Like it? See this code working ›

Not sure where to start?

If you're new to the library it's probably best to start in the How To section.

Want to see the code?

If you want to poke around the code itself, you can use git to grab yourself a copy.

Reference

If you're already familar with the codebase but simply want to look something up, best to head over to the code reference.

Interested? There are plenty of ways to get started: