BenchController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Apps\Controllers;
  3. use Cygnite\Mvc\Controller\AbstractBaseController;
  4. use Apps\Models\Fortune;
  5. use Apps\Models\World;
  6. class BenchController extends AbstractBaseController
  7. {
  8. public function __construct()
  9. {
  10. parent::__construct();
  11. }
  12. public function indexAction()
  13. {
  14. echo 'Hello World!';
  15. }
  16. public function dbAction($queries = 1)
  17. {
  18. $worlds = array();
  19. $world = null;
  20. for ($i = 0; $i < $queries; ++$i) {
  21. $world = World::find(mt_rand(1, 10000));
  22. $worlds[] = $world->asArray();
  23. }
  24. if ($queries == 1) {
  25. $worlds = $worlds[0];
  26. }
  27. header('Content-type: application/json');
  28. echo json_encode($worlds);
  29. }
  30. public function fortunesAction()
  31. {
  32. echo "Fortunes";exit;
  33. $allFortunes = array();
  34. $allFortunes = Fortune::all();
  35. $fortunes = $allFortunes->asArray();
  36. $runtimeFortune = new Fortune();
  37. $runtimeFortune->id = 0;
  38. $runtimeFortune->message = 'Additional fortune added at request time.';
  39. $fortunes[] = $runtimeFortune;
  40. usort($fortunes, function($left, $right) {
  41. if ($left->message === $right->message) {
  42. return 0;
  43. } else if ($left->message > $right->message) {
  44. return 1;
  45. } else {
  46. return -1;
  47. }
  48. });
  49. $this->render('fortunes', array(
  50. 'fortunes' => $fortunes
  51. ));
  52. }
  53. }