root/trunk/framework/interfaces.php

Revision 2482, 9.0 kB (checked in by knut, 4 months ago)

updated copyright

  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * Core interfaces essential for TApplication class.
4 *
5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link http://www.pradosoft.com/
7 * @copyright Copyright &copy; 2005-2008 PradoSoft
8 * @license http://www.pradosoft.com/license/
9 * @version $Id$
10 * @package System
11 */
12
13/**
14 * IModule interface.
15 *
16 * This interface must be implemented by application modules.
17 *
18 * @author Qiang Xue <qiang.xue@gmail.com>
19 * @version $Id$
20 * @package System
21 * @since 3.0
22 */
23interface IModule
24{
25    /**
26     * Initializes the module.
27     * @param TXmlElement the configuration for the module
28     */
29    public function init($config);
30    /**
31     * @return string ID of the module
32     */
33    public function getID();
34    /**
35     * @param string ID of the module
36     */
37    public function setID($id);
38}
39
40/**
41 * IService interface.
42 *
43 * This interface must be implemented by services.
44 *
45 * @author Qiang Xue <qiang.xue@gmail.com>
46 * @version $Id$
47 * @package System
48 * @since 3.0
49 */
50interface IService
51{
52    /**
53     * Initializes the service.
54     * @param TXmlElement the configuration for the service
55     */
56    public function init($config);
57    /**
58     * @return string ID of the service
59     */
60    public function getID();
61    /**
62     * @param string ID of the service
63     */
64    public function setID($id);
65    /**
66     * @return boolean whether the service is enabled
67     */
68    public function getEnabled();
69    /**
70     * @param boolean whether the service is enabled
71     */
72    public function setEnabled($value);
73    /**
74     * Runs the service.
75     */
76    public function run();
77}
78
79/**
80 * ITextWriter interface.
81 *
82 * This interface must be implemented by writers.
83 *
84 * @author Qiang Xue <qiang.xue@gmail.com>
85 * @version $Id$
86 * @package System
87 * @since 3.0
88 */
89interface ITextWriter
90{
91    /**
92     * Writes a string.
93     * @param string string to be written
94     */
95    public function write($str);
96    /**
97     * Flushes the content that has been written.
98     */
99    public function flush();
100}
101
102
103/**
104 * IUser interface.
105 *
106 * This interface must be implemented by user objects.
107 *
108 * @author Qiang Xue <qiang.xue@gmail.com>
109 * @version $Id$
110 * @package System
111 * @since 3.0
112 */
113interface IUser
114{
115    /**
116     * @return string username
117     */
118    public function getName();
119    /**
120     * @param string username
121     */
122    public function setName($value);
123    /**
124     * @return boolean if the user is a guest
125     */
126    public function getIsGuest();
127    /**
128     * @param boolean if the user is a guest
129     */
130    public function setIsGuest($value);
131    /**
132     * @return array list of roles that the user is of
133     */
134    public function getRoles();
135    /**
136     * @return array|string list of roles that the user is of. If it is a string, roles are assumed by separated by comma
137     */
138    public function setRoles($value);
139    /**
140     * @param string role to be tested
141     * @return boolean whether the user is of this role
142     */
143    public function isInRole($role);
144    /**
145     * @return string user data that is serialized and will be stored in session
146     */
147    public function saveToString();
148    /**
149     * @param string user data that is serialized and restored from session
150     * @return IUser the user object
151     */
152    public function loadFromString($string);
153}
154
155/**
156 * IStatePersister class.
157 *
158 * This interface must be implemented by all state persister classes (such as
159 * {@link TPageStatePersister}, {@link TApplicationStatePersister}.
160 *
161 * @author Qiang Xue <qiang.xue@gmail.com>
162 * @version $Id$
163 * @package System
164 * @since 3.0
165 */
166interface IStatePersister
167{
168    /**
169     * Loads state from a persistent storage.
170     * @return mixed the state
171     */
172    public function load();
173    /**
174     * Saves state into a persistent storage.
175     * @param mixed the state to be saved
176     */
177    public function save($state);
178}
179
180
181/**
182 * ICache interface.
183 *
184 * This interface must be implemented by cache managers.
185 *
186 * @author Qiang Xue <qiang.xue@gmail.com>
187 * @version $Id$
188 * @package System
189 * @since 3.0
190 */
191interface ICache
192{
193    /**
194     * Retrieves a value from cache with a specified key.
195     * @param string a key identifying the cached value
196     * @return mixed the value stored in cache, false if the value is not in the cache or expired.
197     */
198    public function get($id);
199    /**
200     * Stores a value identified by a key into cache.
201     * If the cache already contains such a key, the existing value and
202     * expiration time will be replaced with the new ones.
203     *
204     * @param string the key identifying the value to be cached
205     * @param mixed the value to be cached
206     * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
207     * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
208     * @return boolean true if the value is successfully stored into cache, false otherwise
209     */
210    public function set($id,$value,$expire=0,$dependency=null);
211    /**
212     * Stores a value identified by a key into cache if the cache does not contain this key.
213     * Nothing will be done if the cache already contains the key.
214     * @param string the key identifying the value to be cached
215     * @param mixed the value to be cached
216     * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
217     * @param ICacheDependency dependency of the cached item. If the dependency changes, the item is labelled invalid.
218     * @return boolean true if the value is successfully stored into cache, false otherwise
219     */
220    public function add($id,$value,$expire=0,$dependency=null);
221    /**
222     * Deletes a value with the specified key from cache
223     * @param string the key of the value to be deleted
224     * @return boolean if no error happens during deletion
225     */
226    public function delete($id);
227    /**
228     * Deletes all values from cache.
229     * Be careful of performing this operation if the cache is shared by multiple applications.
230     */
231    public function flush();
232}
233
234/**
235 * ICacheDependency interface.
236 *
237 * This interface must be implemented by classes meant to be used as
238 * cache dependencies.
239 *
240 * Classes implementing this interface must support serialization and unserialization.
241 *
242 * @author Qiang Xue <qiang.xue@gmail.com>
243 * @version $Id$
244 * @package System
245 * @since 3.0
246 */
247interface ICacheDependency
248{
249    /**
250     * @return boolean whether the dependency has changed. Defaults to false.
251     */
252    public function getHasChanged();
253}
254
255/**
256 * IRenderable interface.
257 *
258 * This interface must be implemented by classes that can be rendered
259 * to end-users.
260 *
261 * @author Qiang Xue <qiang.xue@gmail.com>
262 * @version $Id$
263 * @package System
264 * @since 3.0
265 */
266interface IRenderable
267{
268    /**
269     * Renders the component to end-users.
270     * @param ITextWriter writer for the rendering purpose
271     */
272    public function render($writer);
273}
274
275/**
276 * IBindable interface.
277 *
278 * This interface must be implemented by classes that are capable of performing databinding.
279 *
280 * @author Qiang Xue <qiang.xue@gmail.com>
281 * @version $Id$
282 * @package System
283 * @since 3.0
284 */
285interface IBindable
286{
287    /**
288     * Performs databinding.
289     */
290    public function dataBind();
291}
292
293/**
294 * IStyleable interface.
295 *
296 * This interface should be implemented by classes that support CSS styles.
297 *
298 * @author Qiang Xue <qiang.xue@gmail.com>
299 * @version $Id$
300 * @package System
301 * @since 3.1.0
302 */
303interface IStyleable
304{
305    /**
306     * @return boolean whether the object has defined any style information
307     */
308    public function getHasStyle();
309    /**
310     * @return TStyle the object representing the css style of the object
311     */
312    public function getStyle();
313    /**
314     * Removes all styles associated with the object
315     */
316    public function clearStyle();
317}
318
319/**
320 * IActiveControl interface.
321 *
322 * Active controls must implement IActiveControl interface.
323 *
324 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
325 * @version $Id$
326 * @package System
327 * @since 3.1
328 */
329interface IActiveControl
330{
331    /**
332     * @return TBaseActiveControl Active control properties.
333     */
334    public function getActiveControl();
335}
336
337/**
338 * ICallbackEventHandler interface.
339 *
340 * If a control wants to respond to callback event, it must implement this
341 * interface.
342 *
343 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
344 * @version $Id$
345 * @package System
346 * @since 3.1
347 */
348interface ICallbackEventHandler
349{
350    /**
351     * Raises callback event. The implementation of this function should raise
352     * appropriate event(s) (e.g. OnClick, OnCommand) indicating the component
353     * is responsible for the callback event.
354     * @param TCallbackEventParameter the parameter associated with the callback event
355     */
356    public function raiseCallbackEvent($eventArgument);
357}
358
359/**
360 * IDataRenderer interface.
361 *
362 * If a control wants to be used a renderer for another data-bound control,
363 * this interface must be implemented.
364 *
365 * @author Qiang Xue <qiang.xue@gmail.com>
366 * @version $Id$
367 * @package System
368 * @since 3.1
369 */
370interface IDataRenderer
371{
372    /**
373     * @return mixed the data bound to this object
374     */
375    public function getData();
376
377    /**
378     * @param mixed the data to be bound to this object
379     */
380    public function setData($value);
381}
382?>
Note: See TracBrowser for help on using the browser.