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. /**
  5.  * PHP versions 4 and 5
  6.  *
  7.  * Copyright (c) 2003-2009 KUBO Atsuhiro <kubo@iteman.jp>,
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions are met:
  12.  *
  13.  *     * Redistributions of source code must retain the above copyright
  14.  *       notice, this list of conditions and the following disclaimer.
  15.  *     * Redistributions in binary form must reproduce the above copyright
  16.  *       notice, this list of conditions and the following disclaimer in the
  17.  *       documentation and/or other materials provided with the distribution.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29.  * POSSIBILITY OF SUCH DAMAGE.
  30.  *
  31.  * @category   Networking
  32.  * @package    Net_UserAgent_Mobile
  33.  * @author     KUBO Atsuhiro <kubo@iteman.jp>
  34.  * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
  35.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  36.  * @version    CVS: $Id: Common.php,v 1.1 2009/05/26 08:48:16 kuboa Exp $
  37.  * @since      File available since Release 0.1
  38.  */
  39.  
  40. require_once 'Net/UserAgent/Mobile/Error.php';
  41. require_once 'PEAR.php';
  42.  
  43. // {{{ Net_UserAgent_Mobile_Common
  44.  
  45. /**
  46.  * Base class that is extended by each user agents implementor
  47.  *
  48.  * Net_UserAgent_Mobile_Common is a class for mobile user agent
  49.  * abstraction layer on Net_UserAgent_Mobile.
  50.  *
  51.  * @category   Networking
  52.  * @package    Net_UserAgent_Mobile
  53.  * @author     KUBO Atsuhiro <kubo@iteman.jp>
  54.  * @copyright  2003-2009 KUBO Atsuhiro <kubo@iteman.jp>
  55.  * @license    http://www.opensource.org/licenses/bsd-license.php  New BSD License
  56.  * @version    Release: 1.0.0
  57.  * @since      Class available since Release 0.1
  58.  */
  59. {
  60.  
  61.     // {{{ properties
  62.  
  63.     /**#@+
  64.      * @access public
  65.      */
  66.  
  67.     /**
  68.      * User-Agent name like 'DoCoMo'
  69.      * @var string 
  70.      */
  71.     var $name;
  72.  
  73.     /**
  74.      * User-Agent version number like '1.0'
  75.      * @var string 
  76.      */
  77.     var $version;
  78.  
  79.     /**#@-*/
  80.  
  81.     /**#@+
  82.      * @access private
  83.      */
  84.  
  85.     /**
  86.      * {@link Net_UserAgent_Mobile_Display} object
  87.      * @var object {@link Net_UserAgent_Mobile_Display}
  88.      */
  89.     var $_display;
  90.  
  91.     /**
  92.      * {@link Net_UserAgent_Mobile_Error} object for error handling in the constructor
  93.      * @var object 
  94.      ***/
  95.     var $_error;
  96.  
  97.     /**
  98.      * The User-Agent string.
  99.      * @var string 
  100.      * @since Property available since Release 0.31.0
  101.      ***/
  102.     var $_userAgent;
  103.  
  104.     /**
  105.      * The model name of the user agent.
  106.      *
  107.      * @var string 
  108.      * @since Property available since Release 0.31.0
  109.      */
  110.     var $_model;
  111.  
  112.     /**
  113.      * The raw model name of the user agent.
  114.      *
  115.      * @var string 
  116.      * @since Property available since Release 0.31.0
  117.      */
  118.     var $_rawModel;
  119.  
  120.     /**#@-*/
  121.  
  122.     /**#@+
  123.      * @access public
  124.      */
  125.  
  126.     // }}}
  127.     // {{{ constructor
  128.  
  129.     /**
  130.      * constructor
  131.      *
  132.      * @param string $userAgent User-Agent string
  133.      */
  134.     function Net_UserAgent_Mobile_Common($userAgent)
  135.     {
  136.         $this->_userAgent $userAgent;
  137.  
  138.         $result $this->parse($userAgent);
  139.         if (PEAR::isError($result)) {
  140.             $this->_error &$result;
  141.         }
  142.     }
  143.  
  144.     // }}}
  145.     // {{{ getError
  146.  
  147.     /**
  148.      * Gets a Net_UserAgent_Mobile_Error object.
  149.      *
  150.      * @param object {@link Net_UserAgent_Mobile_Error} object when setting an error
  151.      * @return Net_UserAgent_Mobile_Error 
  152.      * @since Method available since Release 1.0.0RC2
  153.      */
  154.     function &getError()
  155.     {
  156.         if (is_null($this->_error)) {
  157.             $return = null;
  158.             return $return;
  159.         }
  160.  
  161.         return $this->_error;
  162.     }
  163.  
  164.     // }}}
  165.     // {{{ getUserAgent()
  166.  
  167.     /**
  168.      * returns User-Agent string
  169.      *
  170.      * @return string 
  171.      */
  172.     function getUserAgent()
  173.     {
  174.         return $this->_userAgent;
  175.     }
  176.  
  177.     // }}}
  178.     // {{{ getHeader()
  179.  
  180.     /**
  181.      * returns a specified HTTP header
  182.      *
  183.      * @param string $header 
  184.      * @return string 
  185.      */
  186.     function getHeader($header)
  187.     {
  188.         return @$_SERVER'HTTP_' str_replace('-''_'$header];
  189.     }
  190.  
  191.     // }}}
  192.     // {{{ getName()
  193.  
  194.     /**
  195.      * returns User-Agent name like 'DoCoMo'
  196.      *
  197.      * @return string 
  198.      */
  199.     function getName()
  200.     {
  201.         return $this->name;
  202.     }
  203.  
  204.     // }}}
  205.     // {{{ getDisplay()
  206.  
  207.     /**
  208.      * returns {@link Net_UserAgent_Mobile_Disply} object
  209.      *
  210.      * @return Net_UserAgent_Mobile_Display 
  211.      */
  212.     function getDisplay()
  213.     {
  214.         if (is_null($this->_display)) {
  215.             $this->_display $this->makeDisplay();
  216.         }
  217.  
  218.         return $this->_display;
  219.     }
  220.  
  221.     // }}}
  222.     // {{{ getVersion()
  223.  
  224.     /**
  225.      * returns User-Agent version number like '1.0'
  226.      *
  227.      * @return string 
  228.      */
  229.     function getVersion()
  230.     {
  231.         return $this->version;
  232.     }
  233.  
  234.     // }}}
  235.     // {{{ noMatch()
  236.  
  237.     /**
  238.      * generates a warning message for new variants
  239.      *
  240.      * @throws Net_UserAgent_Mobile_Error
  241.      */
  242.     function noMatch()
  243.     {
  244.         return PEAR::raiseError($this->getUserAgent(': might be new variants. Please contact the author of Net_UserAgent_Mobile!',
  245.                                 NET_USERAGENT_MOBILE_ERROR_NOMATCH,
  246.                                 null,
  247.                                 null,
  248.                                 null,
  249.                                 'Net_UserAgent_Mobile_Error'
  250.                                 );
  251.     }
  252.  
  253.     // }}}
  254.     // {{{ parse()
  255.  
  256.     /**
  257.      * Parses HTTP_USER_AGENT string.
  258.      *
  259.      * @param string $userAgent User-Agent string
  260.      * @abstract
  261.      */
  262.     function parse($userAgent{}
  263.  
  264.     // }}}
  265.     // {{{ makeDisplay()
  266.  
  267.     /**
  268.      * create a new Net_UserAgent_Mobile_Display class instance (should be
  269.      * implemented in subclasses)
  270.      *
  271.      * @return Net_UserAgent_Mobile_Display 
  272.      * @abstract
  273.      */
  274.     function makeDisplay({}
  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.     // {{{ isSoftBank()
  421.  
  422.     /**
  423.      * Returns whether the agent is SoftBank or not.
  424.      *
  425.      * @return boolean 
  426.      * @since Method available since Release 0.31.0
  427.      */
  428.     function isSoftBank()
  429.     {
  430.         return false;
  431.     }
  432.  
  433.     // }}}
  434.     // {{{ isWillcom()
  435.  
  436.     /**
  437.      * Returns whether the agent is Willcom or not.
  438.      *
  439.      * @return boolean 
  440.      * @since Method available since Release 0.31.0
  441.      */
  442.     function isWillcom()
  443.     {
  444.         return false;
  445.     }
  446.  
  447.     // }}}
  448.     // {{{ getModel()
  449.  
  450.     /**
  451.      * Returns the model name of the user agent.
  452.      *
  453.      * @return string 
  454.      * @since Method available since Release 0.31.0
  455.      */
  456.     function getModel()
  457.     {
  458.         if (is_null($this->_model)) {
  459.             return $this->_rawModel;
  460.         else {
  461.             return $this->_model;
  462.         }
  463.     }
  464.  
  465.     // }}}
  466.     // {{{ getRawModel()
  467.  
  468.     /**
  469.      * Returns the raw model name of the user agent.
  470.      *
  471.      * @return string 
  472.      * @since Method available since Release 0.31.0
  473.      */
  474.     function getRawModel()
  475.     {
  476.         return $this->_rawModel;
  477.     }
  478.  
  479.     // }}}
  480.     // {{{ getUID()
  481.  
  482.     /**
  483.      * Gets the UID of a subscriber.
  484.      *
  485.      * @return string 
  486.      * @since Method available since Release 1.0.0RC1
  487.      */
  488.     function getUID({}
  489.  
  490.     /**#@-*/
  491.  
  492.     /**#@+
  493.      * @access private
  494.      */
  495.  
  496.     /**#@-*/
  497.  
  498.     // }}}
  499. }
  500.  
  501. // }}}
  502.  
  503. /*
  504.  * Local Variables:
  505.  * mode: php
  506.  * coding: iso-8859-1
  507.  * tab-width: 4
  508.  * c-basic-offset: 4
  509.  * c-hanging-comment-ender-p: nil
  510.  * indent-tabs-mode: nil
  511.  * End:
  512.  */

Documentation generated on Tue, 23 Jun 2009 10:00:03 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.