Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote you a prototype for an extended class from this base class. Not sure what <code>$PatternFlip</code> is for, its not accessible in this class so you'll have to change it as you see necessary. If you want the result in a different format you can add functions to the class.</p> <pre><code>class MyProtector extends Protector { var $Object; var $encode;//1 means encode, not 1 means decode var $result; function __MyProtector($obj="",$encode=0,$pattern="") { $this-&gt;$Object=$obj; if($encode){//encode object $this-&gt;$EncodePattern=$pattern; $this-&gt;$result=smartEncode($obj); }else{//decode object $this-&gt;$DecodePattern=$pattern; $this-&gt;result=smartDecode($obj); } } private function smartEncode($object){ //encodes string or array if(is_array($object){ return encodeArray($object); }else if(is_string($object)){ return encodeString($object); } return 0; } private function smartDecode($object){ //encodes string or array if(is_string($object)&amp;&amp;strpos("&amp;",$object)===1){ return encodeDelimiter($object); }else if(is_string($object)){ return encodeString($object); } return 0; } private function decodeDelimiter($object){ $a=explode("&amp;",$string);//will only work if your encoding does not include "&amp;"! $aDecoded=array(); $k=0; foreach($a as $i){ $this-&gt;toDecode=$i; $aDecoded[$k]=$this-&gt;Decode(); $k++; } return $aDecoded; } private function decodeString($s){ $this-&gt;toDecode=$s; return $this-&gt;Decode(); } private function encodeString($s){ $this-&gt;toEncode=$s; return $this-&gt;Encode(); } private function encodeArray($s){ foreach($s as $i){ $this-&gt;toEncode=$i; $s=$s.$this-&gt;Encode()."&amp;"; } return $s; } //setters and getters function getPattern(){ return $this-&gt;Pattern; } function getPatternFlip(){ return $this-&gt;Pattern; } function getPattern(){ return $this-&gt;Pattern; } //..etc </code></pre> <p>Example usage:</p> <pre><code>$o=new MyProtector($string,0,$pattern); echo $o-&gt;$result; //returns encoded string $o=new MyProtector($string,1,$pattern); echo $o-&gt;$result; //returns decoded string $o=new MyProtector($array,0,$pattern); echo $o-&gt;$result; //returns decoded string with '&amp;' inbetween encoded array entries $o=new MyProtector($stringWithDelimiter,1,$pattern); echo $o-&gt;$result;//returns decoded array </code></pre> <p>I'm sure there will be a few syntax errors, typos in there as I haven't compiled/tried the thing. Hope that helped.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload