예제 #1
0
 /**
  * Set the memory layout to store something into a shared memory
  * segment. The layout should always follow the regular expression
  * '[variable][serialize($sth)]'. If the layout differs, e.g. if 
  * one wants to implement anything more complex like a group chat
  * this layout needs to be adjusted to an regular expression like
  * '[from_uid][to_uid][msg_type][serialize(message)]'.
  * Some examples on how to use this function
  * <pre>
  *   set_shm_seg_layout(array("[a-z]+", "[^\\[\\]]"));
  *   set_shm_seg_layout(array("[a-z]+", "[1-9]+[0-9]*", "[^\[\]]+"));
  * </pre>
  * The last should always be something like '[^\[\]]+' as the last
  * element stored in a shared memory segment belonging to this layout 
  * should be a serialized object/variable which MUST NOT contain the
  * encapsulators defined above.
  */
 public function set_shm_seg_layout($lparams = array())
 {
     // set the layout parameters if
     if (strncmp(gettype($lparams), "array", 5) == 0 && count($lparams) > 2) {
         foreach ($lparams as $lp) {
             $this->shm_seg_layout = $this->shm_seg_layout . StringUtil::escape($this->shm_seg_var_eleft) . $lp . StringUtil::escape($this->shm_seg_var_eright);
         }
         $this->shm_seg_layout = $this->shm_seg_layout . $this->shm_seg_var_delimiter;
         // otherwise set the default layout to simply store variables
     } else {
         // default layout looks like '[varname][varvalue]'
         $this->shm_seg_layout = $this->shm_seg_layout . StringUtil::escape($this->shm_seg_var_eleft) . "[a-z]+" . StringUtil::escape($this->shm_seg_var_eright) . StringUtil::escape($this->shm_seg_var_eleft) . "[^" . StringUtil::escape($this->shm_seg_var_eleft) . StringUtil::escape($this->shm_seg_var_eright) . "]*" . StringUtil::escape($this->shm_seg_var_eright) . $this->shm_seg_var_delimiter;
     }
 }