source: trunk/prototype/rest/hypermedia/collection.php @ 6528

Revision 6528, 1.8 KB checked in by gustavo, 12 years ago (diff)

Ticket #2766 - Merge do branch das novas funcionalidaes para o trunk

  • Property svn:executable set to *
Line 
1<?php
2
3include_once('item.php');
4include_once('link.php');
5include_once('data.php');
6include_once('template.php');
7include_once('query.php');
8include_once('error.php');
9/*
10Valores padrão
11
12Números são enviados como números, sem aspas;
13Atributos não obrigatórios sem valor serão nulos;
14Strings vazias serão nulos;
15Todos os indices / chaves estarão sempre presentes na mensagem;
16Arrays vazios serão nulos;
17Objetos vazios serão nulos;
18Números sem valor serão nulos;
19valores booleanos são escritos como booleanos (sem aspas);
20*/
21class Collection {
22
23    public $itens;
24    public $href;
25    public $error;
26    public $pagination;
27    public $queries;
28    public $template;
29    public $type;
30    public $data;
31    public $links;
32
33    function __construct($config, $className, $id = null) {
34        foreach ($config as $key => $value) {
35            if ($value['class'] == $className) {
36                $uri = ($id ? (preg_replace('/\/[:][a-zA-Z-0-9]+/', '', $key).'/'.$id ) : $key);
37                break;
38            }
39        }
40        $this->href = $uri;
41    }
42
43        function addLink($link) {
44        $this->links[] = $link;
45    }
46       
47    function addItem($item) {
48        $this->itens[] = $item;
49    }
50       
51        function addData($data) {
52        $this->data[] = $data;
53    }
54
55    function getData() {
56        return $this->data;
57    }
58   
59    function setTemplate($template) {
60        $this->template = $template;
61    }
62
63    function getTemplate() {
64        return $this->template;
65    }
66
67    function setType($type) {
68        $this->type = $type;
69    }
70
71    function getType() {
72        return $this->type;
73    }
74
75    function addQueries($queries) {
76        $this->queries[] = $queries;
77    }
78
79    function getQueries() {
80        return $this->queries;
81    }
82
83    function setError($error) {
84        $this->error = $error;
85    }
86
87    function getError() {
88        return $this->error;
89    }
90
91    function setPagination($pagination) {
92        $this->pagination = $pagination;
93    }
94
95    function getPagination() {
96        return $this->pagination;
97    }
98
99}
100
101?>
Note: See TracBrowser for help on using the repository browser.