MongobenchController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. use Phalcon\Mvc\View,
  3. Phalcon\Mvc\Model\Resultset;
  4. class MongobenchController extends BenchController
  5. {
  6. protected function getRandomWorld()
  7. {
  8. return WorldsCollection::findFirst(array(array('_id' => mt_rand(1, 10000))));
  9. }
  10. protected function getFortunesArray()
  11. {
  12. return FortunesCollection::find();
  13. }
  14. protected function buildFortune()
  15. {
  16. $fortune = parent::buildFortune();
  17. $newFortune = new FortunesCollection();
  18. $newFortune->_id = $fortune['id'];
  19. $newFortune->message = $fortune['message'];
  20. return $newFortune;
  21. }
  22. protected function sortFortunes($fortunes)
  23. {
  24. usort($fortunes,
  25. function($left, $right) {
  26. $l = $left->message;
  27. $r = $right->message;
  28. if ($l === $r) {
  29. return 0;
  30. } else {
  31. if ($l > $r) {
  32. return 1;
  33. } else {
  34. return -1;
  35. }
  36. }
  37. });
  38. return $fortunes;
  39. }
  40. }