Net_UserAgent_Mobile
[ class tree: Net_UserAgent_Mobile ] [ index: Net_UserAgent_Mobile ] [ all elements ]

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: KUBO Atsuhiro <kubo@isite.co.jp>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Common.php,v 1.8 2004/02/08 11:58:38 kuboa Exp $
  20. //
  21.  
  22. /**
  23.  * Base class that is extended by each user agents implementor
  24.  *
  25.  * Net_UserAgent_Mobile_Common is a class for mobile user agent
  26.  * abstraction layer on Net_UserAgent_Mobile.
  27.  *
  28.  * @package  Net_UserAgent_Mobile
  29.  * @category Networking
  30.  * @abstract
  31.  * @author   KUBO Atsuhiro <kubo@isite.co.jp>
  32.  * @access   public
  33.  * @version  $Revision: 1.8 $
  34.  */
  35. class Net_UserAgent_Mobile_Common extends PEAR
  36. {
  37.  
  38.     // {{{ properties
  39.  
  40.     /**#@+
  41.      * @access public
  42.      */
  43.  
  44.     /**
  45.      * User-Agent name like 'DoCoMo'
  46.      * @var string 
  47.      */
  48.     var $name = '';
  49.  
  50.     /**
  51.      * User-Agent version number like '1.0'
  52.      * @var string 
  53.      */
  54.     var $version = '';
  55.  
  56.     /**#@-*/
  57.  
  58.     /**#@+
  59.      * @access private
  60.      */
  61.  
  62.     /**
  63.      * {@link Net_UserAgent_Mobile_Display} object
  64.      * @var object {@link Net_UserAgent_Mobile_Display}
  65.      */
  66.     var $_display;
  67.  
  68.     /**
  69.      * Net_UserAgent_Mobile_Request_XXX object
  70.      * @var object {@link Net_UserAgent_Mobile_Request_Env}
  71.      */
  72.     var $_request;
  73.  
  74.     /**#@-*/
  75.  
  76.     // }}}
  77.     // {{{ constructor
  78.  
  79.     /**
  80.      * constructor
  81.      *
  82.      * @param object $request {@link Net_UserAgent_Mobile_Request_Env}
  83.      *      object
  84.      */
  85.     function Net_UserAgent_Mobile_Common($request)
  86.     {
  87.         parent::PEAR('Net_UserAgent_Mobile_Error');
  88.         $this->_request $request;
  89.         if (Net_UserAgent_Mobile::isError($result $this->parse())) {
  90.             $this $result;
  91.         }
  92.     }
  93.  
  94.     /**#@+
  95.      * @access public
  96.      */
  97.  
  98.     // }}}
  99.     // {{{ raiseError()
  100.  
  101.     /**
  102.      * This method is used to communicate an error and invoke error
  103.      * callbacks etc. Basically a wrapper for PEAR::raiseError without
  104.      * the message string.
  105.      *
  106.      * @param mixed $code integer error code, or a PEAR error object (all
  107.      *      other parameters are ignored if this parameter is an object
  108.      * @param int $mode error mode, see PEAR_Error docs
  109.      * @param mixed $options If error mode is PEAR_ERROR_TRIGGER, this is the
  110.      *      error level (E_USER_NOTICE etc). If error mode is
  111.      *      PEAR_ERROR_CALLBACK, this is the callback function, either as a
  112.      *      function name, or as an array of an object and method name. For
  113.      *      other error modes this parameter is ignored.
  114.      * @param string $userinfo Extra debug information. Defaults to the last
  115.      *      query and native error code.
  116.      * @return object PEAR error object
  117.      * @see PEAR_Error
  118.      */
  119.     function &raiseError($code = NET_USERAGENT_MOBILE_ERROR$mode = null,
  120.                          $options = null$userinfo = null
  121.                          )
  122.     {
  123.  
  124.         // The error is yet a Net_UserAgent_Mobile error object
  125.         if (is_object($code)) {
  126.             return PEAR::raiseError($codenullnullnullnullnull,
  127.                                     true
  128.                                     );
  129.         }
  130.  
  131.         return PEAR::raiseError(null$code$mode$options$userinfo,
  132.                                 'Net_UserAgent_Mobile_Error'true
  133.                                 );
  134.     }
  135.  
  136.     // }}}
  137.     // {{{ getUserAgent()
  138.  
  139.     /**
  140.      * returns User-Agent string
  141.      *
  142.      * @return string 
  143.      */
  144.     function getUserAgent()
  145.     {
  146.         return $this->getHeader('User-Agent');
  147.     }
  148.  
  149.     // }}}
  150.     // {{{ getHeader()
  151.  
  152.     /**
  153.      * returns a specified HTTP header
  154.      *
  155.      * @param string $header 
  156.      * @return string 
  157.      */
  158.     function getHeader($header)
  159.     {
  160.         return $this->_request->get($header);
  161.     }
  162.  
  163.     // }}}
  164.     // {{{ getName()
  165.  
  166.     /**
  167.      * returns User-Agent name like 'DoCoMo'
  168.      *
  169.      * @return string 
  170.      */
  171.     function getName()
  172.     {
  173.         return $this->name;
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ getDisplay()
  178.  
  179.     /**
  180.      * returns {@link Net_UserAgent_Mobile_Disply} object
  181.      *
  182.      * @return object {@link Net_UserAgent_Mobile_Display} object, or a
  183.      *      PEAR error object on error
  184.      * @see Net_UserAgent_Mobile_Display
  185.      */
  186.     function getDisplay()
  187.     {
  188.         if (!is_object($this->_display)) {
  189.             $this->_display $this->makeDisplay();
  190.         }
  191.         return $this->_display;
  192.     }
  193.  
  194.     // }}}
  195.     // {{{ getVersion()
  196.  
  197.     /**
  198.      * returns User-Agent version number like '1.0'
  199.      *
  200.      * @return string 
  201.      */
  202.     function getVersion()
  203.     {
  204.         return $this->version;
  205.     }
  206.  
  207.     // }}}
  208.     // {{{ noMatch()
  209.  
  210.     /**
  211.      * generates a warning message for new variants
  212.      *
  213.      * @return object PEAR error object
  214.      */
  215.     function noMatch()
  216.     {
  217.         return $this->raiseError(NET_USERAGENT_MOBILE_ERROR_NOMATCHnull,
  218.                                  null$this->getUserAgent(.
  219.                                  ': might be new variants. Please contact the author of Net_UserAgent_Mobile!'
  220.                                  );
  221.     }
  222.  
  223.     // }}}
  224.     // {{{ parse()
  225.  
  226.     /**
  227.      * parse HTTP_USER_AGENT string (should be implemented in subclasses)
  228.      *
  229.      * @abstract
  230.      */
  231.     function parse()
  232.     {
  233.         die();
  234.     }
  235.  
  236.     // }}}
  237.     // {{{ makeDisplay()
  238.  
  239.     /**
  240.      * create a new Net_UserAgent_Mobile_Display class instance (should be
  241.      * implemented in subclasses)
  242.      *
  243.      * @abstract
  244.      */
  245.     function makeDisplay()
  246.     {
  247.         die();
  248.     }
  249.  
  250.     // }}}
  251.     // {{{ isDoCoMo()
  252.  
  253.     /**
  254.      * returns true if the agent is DoCoMo
  255.      *
  256.      * @return boolean 
  257.      */
  258.     function isDoCoMo()
  259.     {
  260.         return false;
  261.     }
  262.  
  263.     // }}}
  264.     // {{{ isJPhone()
  265.  
  266.     /**
  267.      * returns true if the agent is J-PHONE
  268.      *
  269.      * @return boolean 
  270.      */
  271.     function isJPhone()
  272.     {
  273.         return false;
  274.     }
  275.  
  276.     // }}}
  277.     // {{{ isEZweb()
  278.  
  279.     /**
  280.      * returns true if the agent is EZweb
  281.      *
  282.      * @return boolean 
  283.      */
  284.     function isEZweb()
  285.     {
  286.         return false;
  287.     }
  288.  
  289.     // }}}
  290.     // {{{ isAirHPhone()
  291.  
  292.     /**
  293.      * returns true if the agent is AirH"PHONE
  294.      *
  295.      * @return boolean 
  296.      */
  297.     function isAirHPhone()
  298.     {
  299.         return false;
  300.     }
  301.  
  302.     // }}}
  303.     // {{{ isWAP1()
  304.  
  305.     /**
  306.      * returns true if the agent can speak WAP1 protocol
  307.      *
  308.      * @return boolean 
  309.      */
  310.     function isWAP1()
  311.     {
  312.         return $this->isEZweb(&& !$this->isWAP2();
  313.     }
  314.  
  315.     // }}}
  316.     // {{{ isWAP2()
  317.  
  318.     /**
  319.      * returns true if the agent can speak WAP2 protocol
  320.      *
  321.      * @return boolean 
  322.      */
  323.     function isWAP2()
  324.     {
  325.         return $this->isEZweb(&& $this->isXHTMLCompliant();
  326.     }
  327.  
  328.     // }}}
  329.     // {{{ isNonMobile()
  330.  
  331.     /**
  332.      * returns true if the agent is NonMobile
  333.      *
  334.      * @return boolean 
  335.      */
  336.     function isNonMobile()
  337.     {
  338.         return false;
  339.     }
  340.  
  341.     /**#@-*/
  342. }
  343.  
  344. /*
  345.  * Local Variables:
  346.  * mode: php
  347.  * coding: iso-8859-1
  348.  * tab-width: 4
  349.  * c-basic-offset: 4
  350.  * c-hanging-comment-ender-p: nil
  351.  * indent-tabs-mode: nil
  352.  * End:
  353.  */
  354. ?>

Documentation generated on Mon, 11 Mar 2019 10:16:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.