phpDocumentor phpIcqBot
[ class tree: phpIcqBot ] [ index: phpIcqBot ] [ all elements ]

Source for file store.flatfile.class.php

Documentation is available at store.flatfile.class.php

  1. <?php
  2. define("ICQBOT_DEFAULTSTOREDIR",'./store/modules/');
  3.  
  4. {
  5.  
  6.     private $storedir;
  7.     private $writable;
  8.     
  9.     public function __construct(IcqBot_Logs &$logs)
  10.     {
  11.         parent::__construct($logs);
  12.         
  13.         $this->storedir ICQBOT_DEFAULTSTOREDIR;
  14.         
  15.         if (!file_exists($this->storedir))
  16.         {
  17.             $old_umask umask(0);
  18.             $res mkdir($this->storedir,0777true);
  19.             umask($old_umask);
  20.             
  21.             if ($res == false)
  22.             {
  23.                 $this->logs->write('Cannot create STORE dir "'.$this->storedir.'".');
  24.             }
  25.         }
  26.         
  27.         if (false == ($this->writable is_writeable($this->storedir)))
  28.         {
  29.             $this->logs->write('STORE dir "'.$this->storedir.'" is not writable!');
  30.         }
  31.     }
  32.     
  33.     public function setData(IcqBot_Module $module$key$value false)
  34.     {
  35.         if (!$this->writable)
  36.         {
  37.             return false;
  38.         }
  39.         $mod_name get_class($module);
  40.         $keys $this->createOrGet($this->storedir.$mod_name);
  41.         $keys[$key$value;
  42.         file_put_contents($this->storedir.$mod_name,serialize($keys));
  43.         return true;
  44.     }
  45.     
  46.     public function getData(IcqBot_Module $module$key)
  47.     {
  48.         if (!$this->writable)
  49.         {
  50.             return null;
  51.         }
  52.         $keys $this->createOrGet($this->storedir.get_class($module));
  53.         if (isset($keys[$key]))
  54.         {
  55.             return $keys[$key];
  56.         }
  57.         return null;        
  58.     }
  59.     
  60.     public function clearData(IcqBot_Module $module)
  61.     {
  62.         if ($this->writable)
  63.         {
  64.             return false;
  65.         }
  66.         file_put_contents($this->storedir.get_class($module),serialize(array()));
  67.         return true;
  68.     }
  69.     
  70.     public function getAllData(IcqBot_Module $module)
  71.     {
  72.         if ($this->writable)
  73.         {
  74.             return null;
  75.         }
  76.         return $this->createOrGet($this->storedir.get_class($module));
  77.     }
  78.     
  79.     private function createOrGet($fname)
  80.     {
  81.         if (!file_exists($fname))
  82.         {
  83.             file_put_contents($fname,serialize(array()));
  84.             clearstatcache();
  85.         }
  86.         return unserialize(file_get_contents($fname));
  87.     }
  88.  
  89. }

Documentation generated on Mon, 24 Dec 2007 09:34:35 +0500 by phpDocumentor 1.4.0