Browse Source

Changed the raw fortune test to doctrine orm.

Now it's possible to "compare" twig with raw php templates. Yeah, the
raw php template doesn't use includes to mimic the extend which twig
offers, but I'm too lazy to change that right now. ;o)
Skamander 12 years ago
parent
commit
9ead750c9a

+ 10 - 8
php-symfony2/src/Skamander/BenchmarkBundle/Controller/BenchController.php

@@ -75,18 +75,20 @@ class BenchController extends Controller
 
     public function fortunesRawAction()
     {
-        $conn = $this->get('database_connection');
-        $fortunes = $conn->fetchAll('SELECT * FROM Fortune');
+        $repo = $this->getDoctrine()
+            ->getRepository('SkamanderBenchmarkBundle:Fortune');
+        $fortunes = $repo->findAll();
 
-        $fortunes[] = [
-            'id' => 0,
-            'message' => 'Additional fortune added at request time.'
-        ];
+        $runtimeFortune = new Fortune();
+        $runtimeFortune->setId(0)
+            ->setMessage('Additional fortune added at request time.');
+
+        $fortunes[] = $runtimeFortune;
 
         usort($fortunes, function($left, $right) {
-            if ($left['message'] === $right['message']) {
+            if ($left->message === $right->message) {
                 return 0;
-            } else if ($left['message'] > $right['message']) {
+            } else if ($left->message > $right->message) {
                 return 1;
             } else {
                 return -1;

+ 2 - 2
php-symfony2/src/Skamander/BenchmarkBundle/Resources/views/Bench/fortunes.html.php

@@ -14,8 +14,8 @@
 
     <?php foreach($fortunes as $fortune): ?>
         <tr>
-            <td><?php echo $fortune['id']; ?></td>
-            <td><?php echo htmlspecialchars($fortune['message'], ENT_QUOTES, "UTF-8", false); ?></td>
+            <td><?php echo $fortune->id; ?></td>
+            <td><?php echo htmlspecialchars($fortune->message, ENT_QUOTES, "UTF-8", false); ?></td>
         </tr>
     <?php endforeach; ?>