示例#1
0
 function __construct($callback = null, $ttl = -1)
 {
     //Maximum entropy, minimum data
     $this->id = \Radical\Basic\String\Random::GenerateBase64(6) . dechex(crc32(session_id() . time()));
     $len = strlen($this->id) - rand(0, 4);
     $this->id = substr($this->id, 0, $len);
     $this->key = \Radical\Basic\String\Random::GenerateBytes(32);
     $this->callback = $callback;
     if ($ttl > 0) {
         $this->expires = $ttl + time();
     }
     KeyStorage::AddKey($this);
 }
 protected function _processEvent($post = true)
 {
     $id = Key::fromRequest($post);
     if (!empty($id)) {
         $key = KeyStorage::GetKey($id);
         if ($key) {
             $this->eventKey = $key;
             $result = $key->Callback();
             if ($result) {
                 return $result;
             }
         } else {
             throw new \Exception('Event invalid (session timeout?)');
         }
     }
 }
 function __construct($handler, $method = 'execute')
 {
     parent::__construct();
     //store even description
     $this->eventHandler = $handler;
     $this->eventMethod = $method;
     //Build security field
     $securityField = KeyStorage::newKey(array($this, 'Execute'));
     //Event details
     $this->hidden(self::EVENT_HANDLER, $securityField->Store(@serialize($handler)));
     $this->hidden(self::EVENT_METHOD, base64_encode($securityField->Encrypt($this->eventMethod)));
     //Security event
     $this->Add($this->getSecurityFieldElement($securityField));
     //Ensure its post, security fields only work on post requests currently.
     $this->method('post');
     if (isset($_SERVER['QUERY_STRING'])) {
         $this->action('?' . $_SERVER['QUERY_STRING']);
     }
 }
 private function data($query_params = array())
 {
     //Build security field
     if ($this->securityField === null) {
         $this->securityField = KeyStorage::newKey(array($this, 'Execute'));
         $this->eHandler = $this->securityField->Store(serialize($this->object));
         $this->eMethod = base64_encode($this->securityField->Encrypt($this->method));
     }
     $g = $_GET;
     if (isset($g['error'])) {
         unset($g['error']);
     }
     if (isset($g['eid'])) {
         unset($g['eid']);
     }
     //Event details
     $qs = array_merge($g, $query_params);
     $qs[self::EVENT_HANDLER] = $this->eHandler;
     $qs[self::EVENT_METHOD] = $this->eMethod;
     $qs[Key::FIELD_NAME] = $this->securityField->getId();
     $str_qs = '?' . http_build_query($qs);
     return $str_qs;
 }