[P2-php-svn] [793] expack:

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 1月 18日 (月) 18:46:51 JST


Revision: 793
          http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=793
Author:   rsk
Date:     2010-01-18 18:46:50 +0900 (Mon, 18 Jan 2010)

Log Message:
-----------
expack:
- 新着まとめ読みキャッシュの作業データをメモリでなく、
  一時ファイルに保存するようにした。
- P2KeyValueStoreにJSON Codecを追加。
-- $kvs->getRawKVS()->get($key) として値をデコードせずに
   取り出し、Ajaxで利用することを想定している。
-- この操作はP2DataStoreファミリーのクラスでラップする。

Modified Paths:
--------------
    p2ex/trunk/lib/MatomeCache.php
    p2ex/trunk/lib/MatomeCacheList.php
    p2ex/trunk/lib/P2Client.php
    p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php
    p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php
    p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php
    p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php
    p2ex/trunk/lib/P2KeyValueStore.php

Added Paths:
-----------
    p2ex/trunk/lib/P2KeyValueStore/Codec/JSON.php
    p2ex/trunk/lib/P2KeyValueStore/Codec/JSONShiftJIS.php


-------------- next part --------------
Modified: p2ex/trunk/lib/MatomeCache.php
===================================================================
--- p2ex/trunk/lib/MatomeCache.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/MatomeCache.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -24,6 +24,20 @@
     private $_metaData;
 
     /**
+     * ‚Ü‚Æ‚ß“Ç‚Ý‚ðˆ³k•Û‘¶‚·‚éƒtƒ@ƒCƒ‹–¼
+     *
+     * @var string
+     */
+    private $_tempFile;
+
+    /**
+     * ‚Ü‚Æ‚ß“Ç‚Ý‚ðˆ³k•Û‘¶‚·‚éƒXƒgƒŠ[ƒ€
+     *
+     * @var stream
+     */
+    private $_stream;
+
+    /**
      * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚ðŽc‚·”
      *
      * @var int
@@ -43,25 +57,57 @@
     /**
      * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
      *
-     * “à—e‚ð‰Šú‰»‚µAƒL[‚ðŽæ“¾‚·‚éB
+     * ƒvƒƒpƒeƒB‚ð‰Šú‰»‚µAˆêŽžƒtƒ@ƒCƒ‹‚ðì¬‚·‚éB
      *
      * @param string $title
      * @param int $maxNumEntries
      */
     public function __construct($title, $maxNumEntries = -1)
     {
+        global $_conf;
+
+        if ($maxNumEntries == 0) {
+            $this->_enabled = false;
+            return;
+        }
+
+        // ƒvƒƒpƒeƒB‚̏‰Šú‰»
         $this->_content = '';
         $this->_metaData = array(
             'time' => time(),
             'title' => $title,
             'threads' => array(),
-            'size' => null,
+            'size' => 0,
         );
+        $this->_tempFile = null;
+        $this->_stream = null;
         $this->_maxNumEntries = $maxNumEntries;
-        if ($maxNumEntries == 0) {
-            $this->_enabled = false;
+        $this->_enabled = true;
+
+        // ˆêŽžƒtƒ@ƒCƒ‹‚ðì¬‚·‚é
+        /*
+         * PHP‚Å tmpnam() ŠÖ”‚ªŒÄ‚΂ê‚é‚ƁACŒ¾ŒêƒŒƒxƒ‹‚Å‚Í
+         *  PHP_FUNCTION(tempnam) -> php_open_temporary_fd() ->
+         *  php_do_open_temporary_file() -> virtual_file_ex()
+         * ‚Æ‚¢‚¤—¬‚ê‚ňꎞƒtƒ@ƒCƒ‹—pƒfƒBƒŒƒNƒgƒŠ‚Ì‰ðŒˆ‚ªs‚í‚ê‚éB
+         * ‚±‚̍ہAvirtual_file_ex() ‚Ì use_realpath ˆø”‚É
+         * CWD_REALPATH ‚ªŽw’肳‚ê‚Ä‚¢‚é‚Ì‚Å tempnam() ‚ÌŒ‹‰Ê‚Í
+         * realpath() ‚É‚©‚¯‚é•K—v‚ª‚È‚¢B
+        */
+        $tempFile = tempnam($_conf['tmp_dir'], 'matome_');
+        if (!$tempFile) {
+            return;
+        }
+
+        // ˆêŽžƒtƒ@ƒCƒ‹‚ðŠJ‚«AƒXƒgƒŠ[ƒ€ƒtƒBƒ‹ƒ^‚ð•t‰Á‚·‚é
+        $fp = fopen($tempFile, 'wb');
+        if ($fp) {
+            stream_filter_append($fp, 'zlib.deflate');
+            stream_filter_append($fp, 'convert.base64-encode');
+            $this->_tempFile = $tempFile;
+            $this->_stream = $fp;
         } else {
-            $this->_enabled = true;
+            unlink($tempfile);
         }
     }
 
@@ -72,19 +118,39 @@
      * ƒfƒXƒgƒ‰ƒNƒ^
      *
      * “à—e‚ð•Û‘¶‚µAŒÃ‚¢ƒLƒƒƒbƒVƒ…‚ðíœ‚·‚éB
-     * ƒXƒŒƒbƒhî•ñ‚ª‹ó‚̏ꍇ‚͐V’…ƒŒƒX‚È‚µ‚Æ‚Ý‚È‚µA•Û‘¶‚µ‚È‚¢B
+     * ƒXƒŒƒbƒhî•ñ‚ª‹ó‚̏ꍇ‚Í•Û‘¶‚µ‚È‚¢B
      *
      * @param void
      */
     public function __destruct()
     {
-        if ($this->_enabled && count($this->_metaData['threads'])) {
-            $this->_metaData['size'] = strlen($this->_content);
-            MatomeCacheList::add($this->_content, $this->_metaData);
+        if (!$this->_enabled) {
+            return;
+        }
+
+        // ƒXƒgƒŠ[ƒ€‚ð•Â‚¶‚é
+        if ($this->_stream) {
+            fclose($this->_stream);
+        }
+
+        // ƒŒƒX‚ª‚ ‚é‚È‚ç
+        if (count($this->_metaData['threads'])) {
+            // “à—e‚ð•Û‘¶‚·‚é
+            if ($this->_tempFile) {
+                MatomeCacheList::add($this->_tempFile, $this->_metaData, true);
+            } else {
+                MatomeCacheList::add($this->_content, $this->_metaData, false);
+            }
+            // ŒÃ‚¢ƒLƒƒƒbƒVƒ…‚ðíœ‚·‚éB
             if ($this->_maxNumEntries > 0) {
                 MatomeCacheList::trim($this->_maxNumEntries);
             }
         }
+
+        // ˆêŽžƒtƒ@ƒCƒ‹‚ðíœ‚·‚é
+        if ($this->_tempFile) {
+            unlink($this->_tempFile);
+        }
     }
 
     // }}}
@@ -99,7 +165,12 @@
     public function concat($content)
     {
         if ($this->_enabled) {
-            $this->_content .= $content;
+            if ($this->_stream) {
+                fwrite($this->_stream, $content);
+            } else {
+                $this->_content .= $content;
+            }
+            $this->_metaData['size'] += strlen($content);
         }
     }
 

Modified: p2ex/trunk/lib/MatomeCacheList.php
===================================================================
--- p2ex/trunk/lib/MatomeCacheList.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/MatomeCacheList.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -14,13 +14,22 @@
      *
      * @param string $content
      * @param array $metaData
-     * @return $key
+     * @param bool $isRawFile   true‚È‚ç$content‚̓tƒ@ƒCƒ‹–¼‚ŁA‚»‚Ì“à—e‚Í
+     *                          deflateˆ³k+Base64ƒGƒ“ƒR[ƒh‚³‚ꂽƒf[ƒ^
+     * @return string
      */
-    static public function add($content, array $metaData)
+    static public function add($content, array $metaData, $isRawFile = false)
     {
         $key = sprintf('%s%0.6f', self::getKeyPrefix(), microtime(true));
-        MatomeCacheDataStore::set($key, $content);
+
+        if ($isRawFile) {
+            MatomeCacheDataStore::setRaw($key, file_get_contents($content));
+        } else {
+            MatomeCacheDataStore::set($key, $content);
+        }
+
         MatomeCacheMetaDataStore::set($key, $metaData);
+
         return $key;
     }
 
@@ -107,9 +116,12 @@
 
         // $length‚ªƒ[ƒ‚̏ꍇ‚Í‘SŒíœ
         if ($length == 0) {
-            MatomeCacheDataStore::clear($prefix);
+            $numRemoved = MatomeCacheDataStore::clear($prefix);
+            if ($numRemoved === false) {
+                return false;
+            }
             MatomeCacheMetaDataStore::clear($prefix);
-            return true;
+            return $numRemoved;
         }
 
         // XVŽž‡‚Ƀ\[ƒg‚µ‚Ä$length+1”Ԗڂ̃ŒƒR[ƒh‚ðŽæ“¾
@@ -159,7 +171,7 @@
 
     // }}}
     // {{{ optimize()
-    
+
     /**
      * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚ðÅ“K‰»‚·‚é
      *

Modified: p2ex/trunk/lib/P2Client.php
===================================================================
--- p2ex/trunk/lib/P2Client.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/P2Client.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -16,7 +16,7 @@
     const COOKIE_STORE_NAME = 'p2_2ch_net_cookies.sqlite3';
 
     /**
-     * ŒöŽ®P2‚ÌURI‚ÆŠeƒGƒ“ƒgƒŠƒ|ƒCƒ“ƒg
+     * ŒöŽ®p2‚ÌURI‚ÆŠeƒGƒ“ƒgƒŠƒ|ƒCƒ“ƒg
      */
     const P2_ROOT_URI = 'http://p2.2ch.net/p2/';
     const SCRIPT_NAME_READ = 'read.php';
@@ -133,7 +133,7 @@
         }
 
         if ($cookieManager = $cookieStore->get($loginId)) {
-            if (!$cookieManager instanceof HTTP_Client_CookieManager) {
+            if (!($cookieManager instanceof HTTP_Client_CookieManager)) {
                 $cookieStore->delete($loginId);
                 throw new Exception('Cannot restore the cookie manager.');
             }
@@ -289,7 +289,7 @@
         $expression = './/a[contains(@href, "' . self::SCRIPT_NAME_READ . '?")'
                     . ' and contains(@href, "&moritapodat=")]';
         $result = $dom->query($expression);
-        if ($result instanceof DOMNodeList && $result->length > 0) {
+        if (($result instanceof DOMNodeList) && $result->length > 0) {
             $anchor = $result->item(0);
             $uri = self::P2_ROOT_URI
                  . strstr($anchor->getAttribute('href'), self::SCRIPT_NAME_READ);
@@ -365,7 +365,7 @@
             $dom = new P2DOM($html);
             $expression = './/form[contains(@action, "' . self::SCRIPT_NAME_POST . '")]';
             $result = $dom->query($expression);
-            if ($result instanceof DOMNodeList && $result->length > 0) {
+            if (($result instanceof DOMNodeList) && $result->length > 0) {
                 $postData = $this->setupPostData($dom, $result->item(0), $name, $mail, $message);
                 $response = $this->httpPost($uri, $postData, true);
             } else {
@@ -437,7 +437,7 @@
     protected function getLoginForm(P2DOM $dom)
     {
         $result = $dom->query('.//form[@action and @id="login"]');
-        if ($result instanceof DOMNodeList && $result->length > 0) {
+        if (($result instanceof DOMNodeList) && $result->length > 0) {
             return $result->item(0);
         }
         return null;
@@ -455,7 +455,7 @@
     protected function getPostForm(P2DOM $dom)
     {
         $result = $dom->query('.//form[@action and @id="resform"]');
-        if ($result instanceof DOMNodeList && $result->length > 0) {
+        if (($result instanceof DOMNodeList) && $result->length > 0) {
             return $result->item(0);
         }
         return null;

Modified: p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -10,7 +10,7 @@
     // {{{ getKVS()
 
     /**
-     * ‘‚«ž‚݃f[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
+     * ‚܂Ƃߓǂ݃f[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
      *
      * @param void
      * @return P2KeyValueStore
@@ -96,6 +96,26 @@
 
     // }}}
     // }}} ƒRƒsƒy‚±‚±‚Ü‚Å
+    // {{{ setRaw()
+
+    /**
+     * Codec‚É‚æ‚é•ÏŠ·‚È‚µ‚Ńf[ƒ^‚ð•Û‘¶‚·‚é
+     *
+     * @param string $key
+     * @param string $value
+     * @return bool
+     */
+    static public function setRaw($key, $value)
+    {
+        $kvs = self::getKVS()->getRawKVS();
+        if ($kvs->exists($key)) {
+            return $kvs->update($key, $value);
+        } else {
+            return $kvs->set($key, $value);
+        }
+    }
+
+    // }}}
 }
 
 // }}}

Modified: p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -10,7 +10,7 @@
     // {{{ getKVS()
 
     /**
-     * ‘‚«ž‚݃f[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
+     * ‚܂Ƃߓǂ݃ƒ^ƒf[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
      *
      * @param void
      * @return P2KeyValueStore

Modified: p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -5,6 +5,8 @@
 /**
  * ”z—ñ‚ðƒVƒŠƒAƒ‰ƒCƒYEƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚éCodec
  *
+ * ŽÀÛ‚Í”ñˆ³kƒVƒŠƒAƒ‰ƒCƒYCodec‚È‚Ì‚Å”z—ñˆÈŠO‚É‚à‘Ήž‚µ‚Ä‚¢‚éB
+ *
  * ƒVƒŠƒAƒ‰ƒCƒYŒã‚̃TƒCƒY‚ªˆ³k‚ð•K—v‚Æ‚·‚é‚Ù‚Ç‘å‚«‚­‚È‚¢ê‡‚ÉŽg‚¤B
  * ”z—ñ‚Ì—v‘f‚É•¶Žš—ñ‚ðŠÜ‚ޏꍇA‘Ó–‚ÈUTF-8ƒV[ƒPƒ“ƒX‚Å‚È‚¯‚ê‚΂Ȃç‚È‚¢B
  */

Modified: p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -5,6 +5,8 @@
 /**
  * ”z—ñ‚ðƒVƒŠƒAƒ‰ƒCƒYEƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚éCodec
  *
+ * ŽÀÛ‚Í”ñˆ³kƒVƒŠƒAƒ‰ƒCƒYCodec‚È‚Ì‚Å”z—ñˆÈŠO‚É‚à‘Ήž‚µ‚Ä‚¢‚éB
+ *
  * ƒVƒŠƒAƒ‰ƒCƒYŒã‚̃TƒCƒY‚ªˆ³k‚ð•K—v‚Æ‚·‚é‚Ù‚Ç‘å‚«‚­‚È‚¢ê‡‚ÉŽg‚¤B
  * ”z—ñ‚Ì—v‘f‚ÉŠÜ‚Ü‚ê‚镶Žš—ñ‚͑Ó–‚ÈShift_JISƒV[ƒPƒ“ƒX‚Å‚È‚¯‚ê‚΂Ȃ炸A
  * ƒL[‚͐”’l‚©US-ASCII•¶Žš—ñ‚Å‚ ‚邱‚Æ‚ðŠú‘Ò‚·‚éB
@@ -14,7 +16,7 @@
     // {{{ encodeValue()
 
     /**
-     * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     * ’l‚ðUTF-8‚É•ÏŠ·‚µ‚½ŒãAƒVƒŠƒAƒ‰ƒCƒY‚·‚é
      *
      * @param array $array
      * @return string
@@ -29,7 +31,7 @@
     // {{{ decodeValue()
 
     /**
-     * ’l‚ðƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     * ’l‚ðƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚µ‚½ŒãAShift_JIS‚É•ÏŠ·‚·‚é
      *
      * @param string $value
      * @return array

Added: p2ex/trunk/lib/P2KeyValueStore/Codec/JSON.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Codec/JSON.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Codec/JSON.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -0,0 +1,84 @@
+<?php
+
+// {{{ P2KeyValueStore_Codec_JSON
+
+/**
+ * ’l‚ðJSONƒGƒ“ƒR[ƒhEƒfƒR[ƒh‚·‚éCodec
+ *
+ * •¶Žš—ñ‚͑Ó–‚ÈUTF-8ƒV[ƒPƒ“ƒX‚Å‚È‚¯‚ê‚΂Ȃç‚È‚¢B
+ */
+class P2KeyValueStore_Codec_JSON implements P2KeyValueStore_Codec_Interface
+{
+    // {{{ encodeKey()
+
+    /**
+     * ƒL[‚Í‚»‚Ì‚Ü‚Ü
+     *
+     * @param string $key
+     * @return string
+     */
+    public function encodeKey($key)
+    {
+        return $key;
+    }
+
+    // }}}
+    // {{{ decodeKey()
+
+    /**
+     * ƒL[‚Í‚»‚Ì‚Ü‚Ü
+     *
+     * @param string $key
+     * @return string
+     */
+    public function decodeKey($key)
+    {
+        return $key;
+    }
+
+    // }}}
+    // {{{ encodeValue()
+
+    /**
+     * ’l‚ðJSONƒGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param mixed $value
+     * @return string
+     */
+    public function encodeValue($value)
+    {
+        return json_encode($value);
+    }
+
+    // }}}
+    // {{{ decodeValue()
+
+    /**
+     * ’l‚ðJSONƒfƒR[ƒh‚·‚é
+     *
+     * JSON‚̃IƒuƒWƒFƒNƒg‚ÍstdClassƒIƒuƒWƒFƒNƒg‚Å‚Í‚È‚­
+     * ˜A‘z”z—ñ‚É•ÏŠ·‚·‚é
+     *
+     * @param string $json
+     * @return mixed
+     */
+    public function decodeValue($json)
+    {
+        return json_decode($json, true);
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Added: p2ex/trunk/lib/P2KeyValueStore/Codec/JSONShiftJIS.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Codec/JSONShiftJIS.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Codec/JSONShiftJIS.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -0,0 +1,57 @@
+<?php
+
+// {{{ P2KeyValueStore_Codec_JSONShiftJIS
+
+/**
+ * ’l‚ðJSONƒGƒ“ƒR[ƒhEƒfƒR[ƒh‚·‚éCodec
+ *
+ * •¶Žš—ñ‚͑Ó–‚ÈShift_JISƒV[ƒPƒ“ƒX‚Å‚È‚¯‚ê‚΂Ȃ炸A
+ * ”z—ñ‚̃L[‚͐”’l‚©US-ASCII•¶Žš—ñ‚Å‚ ‚邱‚Æ‚ðŠú‘Ò‚·‚éB
+ */
+class P2KeyValueStore_Codec_JSONShiftJIS extends P2KeyValueStore_Codec_JSON
+{
+    // {{{ encodeValue()
+
+    /**
+     * ’l‚ðUTF-8‚É•ÏŠ·‚µ‚½ŒãAJSONƒGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param mixed $value
+     * @return string
+     */
+    public function encodeValue($value)
+    {
+        mb_convert_variables('UTF-8', 'Shift_JIS', $value);
+        return parent::encodeValue($value);
+    }
+
+    // }}}
+    // {{{ decodeValue()
+
+    /**
+     * ’l‚ðJSONƒfƒR[ƒh‚µ‚½ŒãAShift_JIS‚É•ÏŠ·‚·‚é
+     *
+     * @param string $value
+     * @return mixed
+     */
+    public function decodeValue($json)
+    {
+        $value = parent::decodeValue($json);
+        mb_convert_variables('SJIS-win', 'UTF-8', $value);
+        return $value;
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/lib/P2KeyValueStore.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore.php	2010-01-17 10:34:34 UTC (rev 792)
+++ p2ex/trunk/lib/P2KeyValueStore.php	2010-01-18 09:46:50 UTC (rev 793)
@@ -36,13 +36,15 @@
 
     const C_KEY_BEGINS = 'arkey LIKE :pattern ESCAPE :escape';
 
-    const CODEC_DEFAULT     = 'P2KeyValueStore_Codec_Default';
-    const CODEC_BINARY      = 'P2KeyValueStore_Codec_Binary';
-    const CODEC_COMPRESSING = 'P2KeyValueStore_Codec_Compressing';
-    const CODEC_SHIFTJIS    = 'P2KeyValueStore_Codec_ShiftJIS';
-    const CODEC_SERIALIZING = 'P2KeyValueStore_Codec_Serializing';
-    const CODEC_ARRAY       = 'P2KeyValueStore_Codec_Array';
-    const CODEC_ARRAYSHIFTJIS = 'P2KeyValueStore_Codec_ArrayShiftJIS';
+    const CODEC_DEFAULT         = 'P2KeyValueStore_Codec_Default';
+    const CODEC_BINARY          = 'P2KeyValueStore_Codec_Binary';
+    const CODEC_COMPRESSING     = 'P2KeyValueStore_Codec_Compressing';
+    const CODEC_SHIFTJIS        = 'P2KeyValueStore_Codec_ShiftJIS';
+    const CODEC_SERIALIZING     = 'P2KeyValueStore_Codec_Serializing';
+    const CODEC_ARRAY           = 'P2KeyValueStore_Codec_Array';
+    const CODEC_ARRAYSHIFTJIS   = 'P2KeyValueStore_Codec_ArrayShiftJIS';
+    const CODEC_JSON            = 'P2KeyValueStore_Codec_JSON';
+    const CODEC_JSONSHIFTJIS    = 'P2KeyValueStore_Codec_JSONShiftJIS';
 
     const MEMORY_DATABASE   = ':memory:';
 
@@ -84,6 +86,13 @@
     private $_codec;
 
     /**
+     * ƒe[ƒuƒ‹–¼
+     *
+     * @var string
+     */
+    private $_tableName;
+
+    /**
      * Ž¯•ÊŽq‚Æ‚µ‚ăNƒH[ƒgÏ‚݂̃e[ƒuƒ‹–¼
      *
      * @var string
@@ -184,6 +193,7 @@
         $this->_pdo = $pdo;
         $this->_pdoId = spl_object_hash($pdo);
         $this->_codec = $codec;
+        $this->_tableName = $tableName;
         $this->_quotedTableName = '"' . str_replace('"', '""', $tableName) . '"';
         $this->_sharedResult = new P2KeyValueStore_Result;
 
@@ -921,17 +931,43 @@
     // {{{ getTableName()
 
     /**
-     * ƒNƒH[ƒgÏ‚݂̃e[ƒuƒ‹–¼‚ð•Ô‚·
+     * ƒe[ƒuƒ‹–¼‚ð•Ô‚·
      *
-     * @param void
+     * @param bool $quoted
      * @return string
      */
-    public function getTableName()
+    public function getTableName($quoted = false)
     {
-        return $this->_quotedTableName;
+        if ($quoted) {
+            return $this->_quotedTableName;
+        } else {
+            return $this->_tableName;
+        }
     }
 
     // }}}
+    // {{{ getRawKVS()
+
+    /**
+     * “¯‚¶ƒe[ƒuƒ‹‚ðˆµ‚¢AƒL[E’l‚Ì•ÏŠ·‚ð‚µ‚È‚¢Key-Value Store‚ð•Ô‚·
+     *
+     * @param void
+     * @return new P2KeyValueStore
+     */
+    public function getRawKVS()
+    {
+        if (array_key_exists('__raw__', self::$_codecCache)) {
+            $codec = self::$_codecCache['__raw__'];
+        } else {
+            $className = self::CODEC_DEFAULT;
+            $codec = new $className;
+            self::$_codecCache['__raw__'] = $codec;
+        }
+
+        return new P2KeyValueStore($this->_pdo, $codec, $this->_tableName);
+    }
+
+    // }}}
     // {{{ loadClass()
 
     /**



P2-php-svn メーリングリストの案内
Back to archive index