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.10 2004/09/25 07:41:09 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.10 $
  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.      * {@link Net_UserAgent_Mobile_Error} object for error handling in the
  76.      *     constructor
  77.      * @var object 
  78.      ***/
  79.     var $_error = null;
  80.  
  81.     /**#@-*/
  82.  
  83.     // }}}
  84.     // {{{ constructor
  85.  
  86.     /**
  87.      * constructor
  88.      *
  89.      * @param object $request {@link Net_UserAgent_Mobile_Request_Env}
  90.      *      object
  91.      */
  92.     function Net_UserAgent_Mobile_Common($request)
  93.     {
  94.         parent::PEAR('Net_UserAgent_Mobile_Error');
  95.         $this->_request $request;
  96.         if (Net_UserAgent_Mobile::isError($result $this->parse())) {
  97.             $this->isError($result);
  98.         }
  99.     }
  100.  
  101.     /**#@+
  102.      * @access public
  103.      */
  104.  
  105.     // }}}
  106.     // {{{ isError
  107.  
  108.     /**
  109.      * Returns/set an error when the instance couldn't initialize properly
  110.      *
  111.      * @param object {@link Net_UserAgent_Mobile_Error} object when setting
  112.      *      an error
  113.      * @return object {@link Net_UserAgent_Mobile_Error} object
  114.      */
  115.     function &isError($error = null)
  116.     {
  117.         if ($error !== null{
  118.             $this->_error &$error;
  119.         }
  120.  
  121.         return $this->_error;
  122.     }
  123.  
  124.     // }}}
  125.     // {{{ raiseError()
  126.  
  127.     /**
  128.      * This method is used to communicate an error and invoke error
  129.      * callbacks etc. Basically a wrapper for PEAR::raiseError without
  130.      * the message string.
  131.      *
  132.      * @param mixed $code integer error code, or a PEAR error object (all
  133.      *      other parameters are ignored if this parameter is an object
  134.      * @param int $mode error mode, see PEAR_Error docs
  135.      * @param mixed $options If error mode is PEAR_ERROR_TRIGGER, this is the
  136.      *      error level (E_USER_NOTICE etc). If error mode is
  137.      *      PEAR_ERROR_CALLBACK, this is the callback function, either as a
  138.      *      function name, or as an array of an object and method name. For
  139.      *      other error modes this parameter is ignored.
  140.      * @param string $userinfo Extra debug information. Defaults to the last
  141.      *      query and native error code.
  142.      * @return object PEAR error object
  143.      * @see PEAR_Error
  144.      */
  145.     function &raiseError($code = NET_USERAGENT_MOBILE_ERROR$mode = null,
  146.                          $options = null$userinfo = null
  147.                          )
  148.     {
  149.  
  150.         // The error is yet a Net_UserAgent_Mobile error object
  151.         if (is_object($code)) {
  152.             return PEAR::raiseError($codenullnullnullnullnull,
  153.                                     true
  154.                                     );
  155.         }
  156.  
  157.         return PEAR::raiseError(null$code$mode$options$userinfo,
  158.                                 'Net_UserAgent_Mobile_Error'true
  159.                                 );
  160.     }
  161.  
  162.     // }}}
  163.     // {{{ getUserAgent()
  164.  
  165.     /**
  166.      * returns User-Agent string
  167.      *
  168.      * @return string 
  169.      */
  170.     function getUserAgent()
  171.     {
  172.         return $this->getHeader('User-Agent');
  173.     }
  174.  
  175.     // }}}
  176.     // {{{ getHeader()
  177.  
  178.     /**
  179.      * returns a specified HTTP header
  180.      *
  181.      * @param string $header 
  182.      * @return string 
  183.      */
  184.     function getHeader($header)
  185.     {
  186.         return $this->_request->get($header);
  187.     }
  188.  
  189.     // }}}
  190.     // {{{ getName()
  191.  
  192.     /**
  193.      * returns User-Agent name like 'DoCoMo'
  194.      *
  195.      * @return string 
  196.      */
  197.     function getName()
  198.     {
  199.         return $this->name;
  200.     }
  201.  
  202.     // }}}
  203.     // {{{ getDisplay()
  204.  
  205.     /**
  206.      * returns {@link Net_UserAgent_Mobile_Disply} object
  207.      *
  208.      * @return object {@link Net_UserAgent_Mobile_Display} object, or a
  209.      *      PEAR error object on error
  210.      * @see Net_UserAgent_Mobile_Display
  211.      */
  212.     function getDisplay()
  213.     {
  214.         if (!is_object($this->_display)) {
  215.             $this->_display $this->makeDisplay();
  216.         }
  217.         return $this->_display;
  218.     }
  219.  
  220.     // }}}
  221.     // {{{ getVersion()
  222.  
  223.     /**
  224.      * returns User-Agent version number like '1.0'
  225.      *
  226.      * @return string 
  227.      */
  228.     function getVersion()
  229.     {
  230.         return $this->version;
  231.     }
  232.  
  233.     // }}}
  234.     // {{{ noMatch()
  235.  
  236.     /**
  237.      * generates a warning message for new variants
  238.      *
  239.      * @return object PEAR error object
  240.      */
  241.     function noMatch()
  242.     {
  243.         return $this->raiseError(NET_USERAGENT_MOBILE_ERROR_NOMATCHnull,
  244.                                  null$this->getUserAgent(.
  245.                                  ': might be new variants. Please contact the author of Net_UserAgent_Mobile!'
  246.                                  );
  247.     }
  248.  
  249.     // }}}
  250.     // {{{ parse()
  251.  
  252.     /**
  253.      * parse HTTP_USER_AGENT string (should be implemented in subclasses)
  254.      *
  255.      * @abstract
  256.      */
  257.     function parse()
  258.     {
  259.         die();
  260.     }
  261.  
  262.     // }}}
  263.     // {{{ makeDisplay()
  264.  
  265.     /**
  266.      * create a new Net_UserAgent_Mobile_Display class instance (should be
  267.      * implemented in subclasses)
  268.      *
  269.      * @abstract
  270.      */
  271.     function makeDisplay()
  272.     {
  273.         die();
  274.     }
  275.  
  276.     // }}}
  277.     // {{{ isDoCoMo()
  278.  
  279.     /**
  280.      * returns true if the agent is DoCoMo
  281.      *
  282.      * @return boolean 
  283.      */
  284.     function isDoCoMo()
  285.     {
  286.         return false;
  287.     }
  288.  
  289.     // }}}
  290.     // {{{ isJPhone()
  291.  
  292.     /**
  293.      * returns true if the agent is J-PHONE
  294.      *
  295.      * @return boolean 
  296.      */
  297.     function isJPhone()
  298.     {
  299.         return false;
  300.     }
  301.  
  302.     // }}}
  303.     // {{{ isVodafone()
  304.  
  305.     /**
  306.      * returns true if the agent is Vodafone
  307.      *
  308.      * @return boolean 
  309.      */
  310.     function isVodafone()
  311.     {
  312.         return false;
  313.     }
  314.  
  315.     // }}}
  316.     // {{{ isEZweb()
  317.  
  318.     /**
  319.      * returns true if the agent is EZweb
  320.      *
  321.      * @return boolean 
  322.      */
  323.     function isEZweb()
  324.     {
  325.         return false;
  326.     }
  327.  
  328.     // }}}
  329.     // {{{ isAirHPhone()
  330.  
  331.     /**
  332.      * returns true if the agent is AirH"PHONE
  333.      *
  334.      * @return boolean 
  335.      */
  336.     function isAirHPhone()
  337.     {
  338.         return false;
  339.     }
  340.  
  341.     // }}}
  342.     // {{{ isNonMobile()
  343.  
  344.     /**
  345.      * returns true if the agent is NonMobile
  346.      *
  347.      * @return boolean 
  348.      */
  349.     function isNonMobile()
  350.     {
  351.         return false;
  352.     }
  353.  
  354.     // }}}
  355.     // {{{ isTUKa()
  356.  
  357.     /**
  358.      * returns true if the agent is TU-Ka
  359.      *
  360.      * @return boolean 
  361.      */
  362.     function isTUKa()
  363.     {
  364.         return false;
  365.     }
  366.  
  367.     // }}}
  368.     // {{{ isWAP1()
  369.  
  370.     /**
  371.      * returns true if the agent can speak WAP1 protocol
  372.      *
  373.      * @return boolean 
  374.      */
  375.     function isWAP1()
  376.     {
  377.         return $this->isEZweb(&& !$this->isWAP2();
  378.     }
  379.  
  380.     // }}}
  381.     // {{{ isWAP2()
  382.  
  383.     /**
  384.      * returns true if the agent can speak WAP2 protocol
  385.      *
  386.      * @return boolean 
  387.      */
  388.     function isWAP2()
  389.     {
  390.         return $this->isEZweb(&& $this->isXHTMLCompliant();
  391.     }
  392.  
  393.     // }}}
  394.     // {{{ getCarrierShortName()
  395.  
  396.     /**
  397.      * returns the short name of the carrier
  398.      *
  399.      * @abstract
  400.      */
  401.     function getCarrierShortName()
  402.     {
  403.         die();
  404.     }
  405.  
  406.     // }}}
  407.     // {{{ getCarrierLongName()
  408.  
  409.     /**
  410.      * returns the long name of the carrier
  411.      *
  412.      * @abstract
  413.      */
  414.     function getCarrierLongName()
  415.     {
  416.         die();
  417.     }
  418.  
  419.     /**#@-*/
  420. }
  421.  
  422. /*
  423.  * Local Variables:
  424.  * mode: php
  425.  * coding: iso-8859-1
  426.  * tab-width: 4
  427.  * c-basic-offset: 4
  428.  * c-hanging-comment-ender-p: nil
  429.  * indent-tabs-mode: nil
  430.  * End:
  431.  */
  432. ?>

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