示例#1
0
 /**
  * @return string|null
  */
 public function hash()
 {
     if ($this->hash) {
         return $this->hash;
     }
     if (is_null($this->first) && is_null($this->second)) {
         return null;
     }
     $first = $this->first;
     $second = $this->second;
     if ($this->first instanceof ITreeNode) {
         $first = $this->first->hash();
         $second = $this->second->hash();
         if ($first === null || $second === null) {
             return null;
         }
     }
     $hash = call_user_func($this->hasher, $first . $second);
     if (!is_string($hash)) {
         throw new UnexpectedValueException('Hash callback must return a string.');
     }
     $this->hash = $hash;
     $this->first = false;
     $this->second = false;
     return $this->hash;
 }
示例#2
0
 /**
  * @return null
  */
 private function resolveHashes()
 {
     $res = $this->treeRoot->hash();
     if (is_null($res)) {
         return;
     }
     if ($this->finished) {
         call_user_func($this->finished, $res);
     }
 }