1 | <?php |
---|
2 | /** |
---|
3 | * Copyright 2011 Bas de Nooijer. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions are met: |
---|
7 | * |
---|
8 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
9 | * this list of conditions and the following disclaimer. |
---|
10 | * |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | * this listof conditions and the following disclaimer in the documentation |
---|
13 | * and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | * |
---|
27 | * The views and conclusions contained in the software and documentation are |
---|
28 | * those of the authors and should not be interpreted as representing official |
---|
29 | * policies, either expressed or implied, of the copyright holder. |
---|
30 | * |
---|
31 | * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> |
---|
32 | * @license http://github.com/basdenooijer/solarium/raw/master/COPYING |
---|
33 | * @link http://www.solarium-project.org/ |
---|
34 | * |
---|
35 | * @package Solarium |
---|
36 | * @subpackage Query |
---|
37 | */ |
---|
38 | |
---|
39 | /** |
---|
40 | * Base class for all query types, not intended for direct usage |
---|
41 | * |
---|
42 | * @package Solarium |
---|
43 | * @subpackage Query |
---|
44 | */ |
---|
45 | abstract class Solarium_Query extends Solarium_Configurable |
---|
46 | { |
---|
47 | |
---|
48 | /** |
---|
49 | * Helper instance |
---|
50 | * |
---|
51 | * @var Solarium_Query_Helper |
---|
52 | */ |
---|
53 | protected $_helper; |
---|
54 | |
---|
55 | /** |
---|
56 | * Extra query params (e.g. dereferenced params) |
---|
57 | * |
---|
58 | * @var array |
---|
59 | */ |
---|
60 | protected $_params = array(); |
---|
61 | |
---|
62 | /** |
---|
63 | * Get type for this query |
---|
64 | * |
---|
65 | * @return string |
---|
66 | */ |
---|
67 | abstract public function getType(); |
---|
68 | |
---|
69 | /** |
---|
70 | * Set handler option |
---|
71 | * |
---|
72 | * @param string $handler |
---|
73 | * @return Solarium_Query Provides fluent interface |
---|
74 | */ |
---|
75 | public function setHandler($handler) |
---|
76 | { |
---|
77 | return $this->_setOption('handler', $handler); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Get handler option |
---|
82 | * |
---|
83 | * @return string |
---|
84 | */ |
---|
85 | public function getHandler() |
---|
86 | { |
---|
87 | return $this->getOption('handler'); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * Set resultclass option |
---|
92 | * |
---|
93 | * If you set a custom result class it must be available through autoloading |
---|
94 | * or a manual require before calling this method. This is your |
---|
95 | * responsibility. |
---|
96 | * |
---|
97 | * Also you need to make sure it extends the orginal result class of the |
---|
98 | * query or has an identical API. |
---|
99 | * |
---|
100 | * @param string $classname |
---|
101 | * @return Solarium_Query Provides fluent interface |
---|
102 | */ |
---|
103 | public function setResultClass($classname) |
---|
104 | { |
---|
105 | return $this->_setOption('resultclass', $classname); |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Get resultclass option |
---|
110 | * |
---|
111 | * @return string |
---|
112 | */ |
---|
113 | public function getResultClass() |
---|
114 | { |
---|
115 | return $this->getOption('resultclass'); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Get a helper instance |
---|
120 | * |
---|
121 | * Uses lazy loading: the helper is instantiated on first use |
---|
122 | * |
---|
123 | * @return Solarium_Query_Helper |
---|
124 | */ |
---|
125 | public function getHelper() |
---|
126 | { |
---|
127 | if (null === $this->_helper) { |
---|
128 | $this->_helper = new Solarium_Query_Helper($this); |
---|
129 | } |
---|
130 | |
---|
131 | return $this->_helper; |
---|
132 | } |
---|
133 | |
---|
134 | /** |
---|
135 | * Add extra params to the request |
---|
136 | * |
---|
137 | * Only intended for internal use, for instance with dereferenced params. |
---|
138 | * Therefore the params are limited in functionality. Only add and get |
---|
139 | * |
---|
140 | * @param string $name |
---|
141 | * @param string $value |
---|
142 | * @return self Provides fluent interface |
---|
143 | */ |
---|
144 | public function addParam($name, $value) |
---|
145 | { |
---|
146 | $this->_params[$name] = $value; |
---|
147 | return $this; |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * Get extra params |
---|
152 | * |
---|
153 | * @return array |
---|
154 | */ |
---|
155 | public function getParams() |
---|
156 | { |
---|
157 | return $this->_params; |
---|
158 | } |
---|
159 | |
---|
160 | } |
---|