Beispiel #1
0
 /**
  * Computes a signature for the specified secret and payload
  *
  * @param string $secret the secret token to secure messages
  * @param string $payload the payload
  * @param string $algo the hash algorithm [facultative]
  *
  * @return string the payload signature
  */
 public static function hashPayload($secret, $payload, $algo = self::DEFAULT_HASH_ALGO)
 {
     $instance = new static($secret, $algo);
     $instance->payload = $payload;
     return $instance->compute();
 }
Beispiel #2
0
 /**
  * Calculate the difference between two snapshots for a given key
  *
  * @param mixed $key Key to compare
  *
  * @return AbstractChange|null a change if a change was detected, null otherwise
  * @internal
  */
 private function computeEntry(AbstractSnapshot $old, AbstractSnapshot $new, $key)
 {
     if (!isset($old[$key])) {
         return new Addition($this->getRawData($new[$key]));
     }
     if (!isset($new[$key])) {
         return new Removal($this->getRawData($old[$key]));
     }
     $values = ['old' => $this->getRawData($old[$key]), 'new' => $this->getRawData($new[$key])];
     switch (true) {
         // type verification
         case gettype($old[$key]) !== gettype($new[$key]):
             return new Modification($values['old'], $values['new']);
             // could we compare two snapshots ?
         // could we compare two snapshots ?
         case $old[$key] instanceof AbstractSnapshot:
             if (!$new[$key] instanceof AbstractSnapshot) {
                 return new Modification($values['old'], $values['new']);
             }
             if (!$old[$key]->isComparable($new[$key])) {
                 return new Modification($values['old'], $values['new']);
             }
             $set = new static();
             $set->compute($old[$key], $new[$key]);
             if (0 < count($set)) {
                 return $set;
             }
             return null;
             // unknown type : compare raw data
         // unknown type : compare raw data
         case $values['old'] !== $values['new']:
             return new Modification($values['old'], $values['new']);
             // PHPUnit coverage wtf start
             // @codeCoverageIgnoreStart
     }
     // @codeCoverageIgnoreEnd
     // PHPUnit coverage wtf end
 }
Beispiel #3
0
 /**
  * Calculate the difference between two snapshots for a given key
  *
  * @param mixed $key Key to compare
  *
  * @return AbstractChange|null a change if a change was detected, null otherwise
  * @internal
  */
 private function computeEntry(AbstractSnapshot $old, AbstractSnapshot $new, $key)
 {
     if (!isset($old[$key])) {
         return new Addition($this->getRawData($new[$key]));
     }
     if (!isset($new[$key])) {
         return new Removal($this->getRawData($old[$key]));
     }
     $raw = ['old' => $this->getRawData($old[$key]), 'new' => $this->getRawData($new[$key])];
     if ($old[$key] instanceof AbstractSnapshot && $new[$key] instanceof AbstractSnapshot && $new[$key]->isComparable($old[$key])) {
         $set = new static();
         $set->compute($old[$key], $new[$key]);
         if (0 < count($set)) {
             return $set;
         }
     }
     if ($raw['old'] !== $raw['new']) {
         return new Modification($raw['old'], $raw['new']);
     }
     return null;
 }