Source for file Token.php

Documentation is available at Token.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 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.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. /**
  19.  * Token管理を行う
  20.  *
  21.  * @package     teeple
  22.  */
  23. {
  24.     /**
  25.      * @var Tokenの名前を保持する 
  26.      *
  27.      * @access  private
  28.      * @since   3.0.0
  29.      */
  30.     var $_name;
  31.  
  32.     /**
  33.      * @var Teeple_Session 
  34.      */
  35.     var $_session;
  36.     public function setComponent_Teeple_Session($c{
  37.         $this->_session = $c;
  38.     }
  39.  
  40.     /**
  41.      * コンストラクター
  42.      *
  43.      * @access  public
  44.      * @since   3.0.0
  45.      */
  46.     function __construct()
  47.     {
  48.         $this->_name "";
  49.         $this->_session = NULL;
  50.     }
  51.  
  52.     /**
  53.      * Sessionのインスタンスをセット
  54.      *
  55.      * @param   Object  $session    Sessionのインスタンス
  56.      * @access  public
  57.      * @since   3.0.0
  58.      */
  59.     function setSession($session)
  60.     {
  61.         $this->_session = $session;
  62.     }
  63.  
  64.     /**
  65.      * Tokenの名前を返却
  66.      *
  67.      * @return  string  Tokenの名前
  68.      * @access  public
  69.      * @since   3.0.0
  70.      */
  71.     function getName()
  72.     {
  73.         if ($this->_name == ""{
  74.             $this->_name "mapleToken";
  75.         }
  76.  
  77.         return $this->_name;
  78.     }
  79.  
  80.     /**
  81.      * Tokenの名前を設定
  82.      *
  83.      * @param   string  $name   Tokenの名前
  84.      * @access  public
  85.      * @since   3.0.0
  86.      */
  87.     function setName($name)
  88.     {
  89.         $this->_name $name;
  90.     }
  91.  
  92.     /**
  93.      * Tokenの値を返却
  94.      *
  95.      * @return  string  Tokenの値を返却
  96.      * @access  public
  97.      * @since   3.0.0
  98.      */
  99.     function getValue()
  100.     {
  101.         return $this->_session->getParameter($this->getName());
  102.     }
  103.  
  104.     /**
  105.      * Tokenの値を生成
  106.      *
  107.      * @access  public
  108.      * @since   3.0.0
  109.      */
  110.     function build()
  111.     {
  112.         $this->_session->setParameter($this->getName()md5(uniqid(rand(),1)));
  113.     }
  114.  
  115.     /**
  116.      * Tokenの値を比較
  117.      *
  118.      * @param   Object  $value  Requestクラスのインスタンス
  119.      * @return  boolean Tokenの値が一致するか?
  120.      * @access  public
  121.      * @since   3.0.0
  122.      */
  123.     function check(&$request)
  124.     {
  125.         return (($this->getValue(!= ''&&
  126.                 $this->getValue(== $request->getParameter($this->getName()));
  127.     }
  128.  
  129.     /**
  130.      * Tokenの値を削除
  131.      *
  132.      * @access  public
  133.      * @since   3.0.0
  134.      */
  135.     function remove()
  136.     {
  137.         $this->_session->removeParameter($this->getName());
  138.     }
  139. }
  140. ?>

Documentation generated on Mon, 26 Apr 2010 09:00:00 +0900 by phpDocumentor 1.4.3