source: branches/version-2/data/module/Net/UserAgent/Mobile/Common.php @ 18561

Revision 18561, 10.5 KB checked in by kajiwara, 14 years ago (diff)

Ver2.4.3にアップデート

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4/**
5 * PHP versions 4 and 5
6 *
7 * LICENSE: This source file is subject to version 3.0 of the PHP license
8 * that is available through the world-wide-web at the following URI:
9 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
10 * the PHP License and are unable to obtain it through the web, please
11 * send a note to license@php.net so we can mail you a copy immediately.
12 *
13 * @category   Networking
14 * @package    Net_UserAgent_Mobile
15 * @author     KUBO Atsuhiro <iteman@users.sourceforge.net>
16 * @copyright  2003-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>
17 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
18 * @version    CVS: $Id$
19 * @since      File available since Release 0.1
20 */
21
22require_once dirname(__FILE__) . '/../Mobile.php';
23
24// {{{ Net_UserAgent_Mobile_Common
25
26/**
27 * Base class that is extended by each user agents implementor
28 *
29 * Net_UserAgent_Mobile_Common is a class for mobile user agent
30 * abstraction layer on Net_UserAgent_Mobile.
31 *
32 * @category   Networking
33 * @package    Net_UserAgent_Mobile
34 * @author     KUBO Atsuhiro <iteman@users.sourceforge.net>
35 * @copyright  2003-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>
36 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
37 * @version    Release: 0.31.0
38 * @since      Class available since Release 0.1
39 */
40class Net_UserAgent_Mobile_Common extends PEAR
41{
42
43    // {{{ properties
44
45    /**#@+
46     * @access public
47     */
48
49    /**
50     * User-Agent name like 'DoCoMo'
51     * @var string
52     */
53    var $name;
54
55    /**
56     * User-Agent version number like '1.0'
57     * @var string
58     */
59    var $version;
60
61    /**#@-*/
62
63    /**#@+
64     * @access private
65     */
66
67    /**
68     * {@link Net_UserAgent_Mobile_Display} object
69     * @var object {@link Net_UserAgent_Mobile_Display}
70     */
71    var $_display;
72
73    /**
74     * {@link Net_UserAgent_Mobile_Error} object for error handling in the
75     *     constructor
76     * @var object
77     **/
78    var $_error;
79
80    /**
81     * The User-Agent string.
82     * @var string
83     * @since Property available since Release 0.31.0
84     **/
85    var $_userAgent;
86
87    /**
88     * The model name of the user agent.
89     *
90     * @var string
91     * @since Property available since Release 0.31.0
92     */
93    var $_model;
94
95    /**
96     * The raw model name of the user agent.
97     *
98     * @var string
99     * @since Property available since Release 0.31.0
100     */
101    var $_rawModel;
102
103    /**#@-*/
104
105    /**#@+
106     * @access public
107     */
108
109    // }}}
110    // {{{ constructor
111
112    /**
113     * constructor
114     *
115     * @param string $userAgent User-Agent string
116     */
117    function Net_UserAgent_Mobile_Common($userAgent)
118    {
119        parent::PEAR('Net_UserAgent_Mobile_Error');
120
121        $result = $this->parse($userAgent);
122        if (Net_UserAgent_Mobile::isError($result)) {
123            $this->isError($result);
124        }
125
126        $this->_userAgent = $userAgent;
127    }
128
129    // }}}
130    // {{{ isError
131
132    /**
133     * Returns/set an error when the instance couldn't initialize properly
134     *
135     * @param object {@link Net_UserAgent_Mobile_Error} object when setting
136     *     an error
137     * @return object {@link Net_UserAgent_Mobile_Error} object
138     */
139    function &isError($error = null)
140    {
141        if ($error !== null) {
142            $this->_error = &$error;
143        }
144
145        return $this->_error;
146    }
147
148    // }}}
149    // {{{ raiseError()
150
151    /**
152     * This method is used to communicate an error and invoke error
153     * callbacks etc. Basically a wrapper for PEAR::raiseError without
154     * the message string.
155     *
156     * @param mixed $code integer error code, or a PEAR error object (all
157     *     other parameters are ignored if this parameter is an object
158     * @param int $mode error mode, see PEAR_Error docs
159     * @param mixed $options If error mode is PEAR_ERROR_TRIGGER, this is the
160     *     error level (E_USER_NOTICE etc). If error mode is
161     *     PEAR_ERROR_CALLBACK, this is the callback function, either as a
162     *     function name, or as an array of an object and method name. For
163     *     other error modes this parameter is ignored.
164     * @param string $userinfo Extra debug information. Defaults to the last
165     *     query and native error code.
166     * @return object a PEAR error object
167     * @see PEAR_Error
168     */
169    function &raiseError($code = NET_USERAGENT_MOBILE_ERROR, $mode = null,
170                         $options = null, $userinfo = null
171                         )
172    {
173
174        // The error is yet a Net_UserAgent_Mobile error object
175        if (is_object($code)) {
176            $error = &PEAR::raiseError($code, null, null, null, null, null,
177                                       true
178                                       );
179            return $error;
180        }
181
182        $error = &PEAR::raiseError(null, $code, $mode, $options, $userinfo,
183                                   'Net_UserAgent_Mobile_Error', true
184                                   );
185        return $error;
186    }
187
188    // }}}
189    // {{{ getUserAgent()
190
191    /**
192     * returns User-Agent string
193     *
194     * @return string
195     */
196    function getUserAgent()
197    {
198        return $this->_userAgent;
199    }
200
201    // }}}
202    // {{{ getHeader()
203
204    /**
205     * returns a specified HTTP header
206     *
207     * @param string $header
208     * @return string
209     */
210    function getHeader($header)
211    {
212        return @$_SERVER[ 'HTTP_' . str_replace('-', '_', $header) ];
213    }
214
215    // }}}
216    // {{{ getName()
217
218    /**
219     * returns User-Agent name like 'DoCoMo'
220     *
221     * @return string
222     */
223    function getName()
224    {
225        return $this->name;
226    }
227
228    // }}}
229    // {{{ getDisplay()
230
231    /**
232     * returns {@link Net_UserAgent_Mobile_Disply} object
233     *
234     * @return object a {@link Net_UserAgent_Mobile_Display} object, or a
235     *     PEAR error object on error
236     * @see Net_UserAgent_Mobile_Display
237     */
238    function getDisplay()
239    {
240        if (!is_object($this->_display)) {
241            $this->_display = $this->makeDisplay();
242        }
243        return $this->_display;
244    }
245
246    // }}}
247    // {{{ getVersion()
248
249    /**
250     * returns User-Agent version number like '1.0'
251     *
252     * @return string
253     */
254    function getVersion()
255    {
256        return $this->version;
257    }
258
259    // }}}
260    // {{{ noMatch()
261
262    /**
263     * generates a warning message for new variants
264     *
265     * @return object a PEAR error object
266     */
267    function noMatch()
268    {
269        return $this->raiseError(NET_USERAGENT_MOBILE_ERROR_NOMATCH, null,
270                                 null, $this->getUserAgent() .
271                                 ': might be new variants. Please contact the author of Net_UserAgent_Mobile!'
272                                 );
273    }
274
275    // }}}
276    // {{{ parse()
277
278    /**
279     * Parses HTTP_USER_AGENT string.
280     *
281     * @param string $userAgent User-Agent string
282     * @abstract
283     */
284    function parse($userAgent) {}
285
286    // }}}
287    // {{{ makeDisplay()
288
289    /**
290     * create a new Net_UserAgent_Mobile_Display class instance (should be
291     * implemented in subclasses)
292     *
293     * @abstract
294     */
295    function makeDisplay()
296    {
297        die();
298    }
299
300    // }}}
301    // {{{ isDoCoMo()
302
303    /**
304     * returns true if the agent is DoCoMo
305     *
306     * @return boolean
307     */
308    function isDoCoMo()
309    {
310        return false;
311    }
312
313    // }}}
314    // {{{ isJPhone()
315
316    /**
317     * returns true if the agent is J-PHONE
318     *
319     * @return boolean
320     */
321    function isJPhone()
322    {
323        return false;
324    }
325
326    // }}}
327    // {{{ isVodafone()
328
329    /**
330     * returns true if the agent is Vodafone
331     *
332     * @return boolean
333     */
334    function isVodafone()
335    {
336        return false;
337    }
338
339    // }}}
340    // {{{ isEZweb()
341
342    /**
343     * returns true if the agent is EZweb
344     *
345     * @return boolean
346     */
347    function isEZweb()
348    {
349        return false;
350    }
351
352    // }}}
353    // {{{ isAirHPhone()
354
355    /**
356     * returns true if the agent is AirH"PHONE
357     *
358     * @return boolean
359     */
360    function isAirHPhone()
361    {
362        return false;
363    }
364
365    // }}}
366    // {{{ isNonMobile()
367
368    /**
369     * returns true if the agent is NonMobile
370     *
371     * @return boolean
372     */
373    function isNonMobile()
374    {
375        return false;
376    }
377
378    // }}}
379    // {{{ isTUKa()
380
381    /**
382     * returns true if the agent is TU-Ka
383     *
384     * @return boolean
385     */
386    function isTUKa()
387    {
388        return false;
389    }
390
391    // }}}
392    // {{{ isWAP1()
393
394    /**
395     * returns true if the agent can speak WAP1 protocol
396     *
397     * @return boolean
398     */
399    function isWAP1()
400    {
401        return $this->isEZweb() && !$this->isWAP2();
402    }
403
404    // }}}
405    // {{{ isWAP2()
406
407    /**
408     * returns true if the agent can speak WAP2 protocol
409     *
410     * @return boolean
411     */
412    function isWAP2()
413    {
414        return $this->isEZweb() && $this->isXHTMLCompliant();
415    }
416
417    // }}}
418    // {{{ getCarrierShortName()
419
420    /**
421     * returns the short name of the carrier
422     *
423     * @abstract
424     */
425    function getCarrierShortName()
426    {
427        die();
428    }
429
430    // }}}
431    // {{{ getCarrierLongName()
432
433    /**
434     * returns the long name of the carrier
435     *
436     * @abstract
437     */
438    function getCarrierLongName()
439    {
440        die();
441    }
442
443    // }}}
444    // {{{ isSoftBank()
445
446    /**
447     * Returns whether the agent is SoftBank or not.
448     *
449     * @return boolean
450     * @since Method available since Release 0.31.0
451     */
452    function isSoftBank()
453    {
454        return false;
455    }
456
457    // }}}
458    // {{{ isWillcom()
459
460    /**
461     * Returns whether the agent is Willcom or not.
462     *
463     * @return boolean
464     * @since Method available since Release 0.31.0
465     */
466    function isWillcom()
467    {
468        return false;
469    }
470
471    // }}}
472    // {{{ getModel()
473
474    /**
475     * Returns the model name of the user agent.
476     *
477     * @return string
478     * @since Method available since Release 0.31.0
479     */
480    function getModel()
481    {
482        if (is_null($this->_model)) {
483            return $this->_rawModel;
484        } else {
485            return $this->_model;
486        }
487    }
488
489    // }}}
490    // {{{ getRawModel()
491
492    /**
493     * Returns the raw model name of the user agent.
494     *
495     * @return string
496     * @since Method available since Release 0.31.0
497     */
498    function getRawModel()
499    {
500        return $this->_rawModel;
501    }
502
503    /**#@-*/
504
505    /**#@+
506     * @access private
507     */
508
509    /**#@-*/
510
511    // }}}
512}
513
514// }}}
515
516/*
517 * Local Variables:
518 * mode: php
519 * coding: iso-8859-1
520 * tab-width: 4
521 * c-basic-offset: 4
522 * c-hanging-comment-ender-p: nil
523 * indent-tabs-mode: nil
524 * End:
525 */
Note: See TracBrowser for help on using the repository browser.