|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * PHP REST SQL JSON renderer class |
| 5 | + * This class renders the REST response data as JSON. |
| 6 | +
|
| 7 | + This program is free software; you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation; either version 2 of the License, or |
| 10 | + (at your option) any later version. |
| 11 | +
|
| 12 | + This program is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with this program; if not, write to the Free Software |
| 19 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | +
|
| 21 | +*/ |
| 22 | +class PHPRestSQLRenderer { |
| 23 | + |
| 24 | + /** |
| 25 | + * @var PHPRestSQL PHPRestSQL |
| 26 | + */ |
| 27 | + var $PHPRestSQL; |
| 28 | + |
| 29 | + /** |
| 30 | + * Constructor. |
| 31 | + * @param PHPRestSQL PHPRestSQL |
| 32 | + */ |
| 33 | + function render($PHPRestSQL) { |
| 34 | + $this->PHPRestSQL = $PHPRestSQL; |
| 35 | + switch($PHPRestSQL->display) { |
| 36 | + case 'database': |
| 37 | + $this->database(); |
| 38 | + break; |
| 39 | + case 'table': |
| 40 | + $this->table(); |
| 41 | + break; |
| 42 | + case 'row': |
| 43 | + $this->row(); |
| 44 | + break; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Output the top level table listing. |
| 50 | + */ |
| 51 | + function database() { |
| 52 | + header('Content-Type: application/json'); |
| 53 | + if (isset($this->PHPRestSQL->output['database'])) { |
| 54 | + echo json_encode($this->PHPRestSQL->output['database']); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Output the rows within a table. |
| 60 | + */ |
| 61 | + function table() { |
| 62 | + header('Content-Type: application/json'); |
| 63 | + if (isset($this->PHPRestSQL->output['table'])) { |
| 64 | + echo json_encode($this->PHPRestSQL->output['table']); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Output the entry in a table row. |
| 70 | + */ |
| 71 | + function row() { |
| 72 | + header('Content-Type: application/json'); |
| 73 | + if (isset($this->PHPRestSQL->output['row'])) { |
| 74 | + echo json_encode($this->PHPRestSQL->output['row']); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments