fork download
  1. <?php
  2.  
  3. function orm_for($type) {
  4. return strtolower($type);
  5. }
  6.  
  7. function peer_for($type) {
  8. return ucfirst($type)."Peer";
  9. }
  10.  
  11. function exception_for($type) {
  12. return ucfirst($type)."Exception";
  13. }
  14.  
  15. function query($type, $data) {
  16. $peer = $peer_for($type);
  17. $exception = $exception_for($type);
  18. $obj = null;
  19. $criteria = new Criteria();
  20. $criteria->add($peer::CONTRACTNR, $data["contractnr"]);
  21. $result = $peer::doSelect($criteria);
  22. if(count($result) > 1) {
  23. throw new $exception("status: more than one row with the specified contractnr.");
  24. } else if(count($result) == 0) {
  25. $obj = $this->factory->createORM(orm_for($type));
  26. $obj->setCreatedAt(time());
  27. } else {
  28. $obj = $result[0];
  29. }
  30. }
  31.  
  32. class FoobarPeer {
  33. static function print_self() {
  34. echo 'FoobarPeer::print_self()';
  35. }
  36. };
  37.  
  38. class FoobarException extends Exception {
  39.  
  40. };
  41.  
  42.  
  43. $foobar = "foobar";
  44. $foobar_peer = peer_for($foobar);
  45. $foobar_exception = exception_for($foobar);
  46.  
  47. echo "Peer for ".$foobar." : ".$foobar_peer."\n";
  48. echo "Exception for ".$foobar." : ".$foobar_exception."\n";
  49. $foobar_peer::print_self();
  50.  
  51. throw new $foobar_exception("blah");
  52.  
  53. ?>
Runtime error #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
Peer for foobar : FoobarPeer
Exception for foobar : FoobarException
FoobarPeer::print_self()
stderr
PHP Fatal error:  Uncaught exception 'FoobarException' with message 'blah' in /home/p3b4Cb/prog.php:51
Stack trace:
#0 {main}
  thrown in /home/p3b4Cb/prog.php on line 51