コード例 #1
0
ファイル: Response.php プロジェクト: lrezek/Cbor4Laravel
 /**
  * Morph the given content into CBOR.
  *
  * @param  mixed   $content
  * @return string
  */
 protected function morphToCbor($content)
 {
     if ($content instanceof CborableInterface) {
         return $content->toCbor();
     }
     return Cbor::encode($content);
 }
コード例 #2
0
ファイル: Request.php プロジェクト: lrezek/Cbor4Laravel
 /**
  * Get the CBOR payload for the request.
  *
  * @param  string  $key The key to get the value for, in "dot notation" (ex: user.username = cbor["user"]["username"]).
  * @param  mixed   $default Default value if the key isn't found.
  * @return mixed
  */
 public function cbor($key = null, $default = null)
 {
     //Grab the content
     $content = $this->getContent();
     //Deal with empty input.
     if (empty($content)) {
         return null;
     }
     //Don't decode twice!
     if (!isset($this->cbor)) {
         $this->cbor = new ParameterBag((array) Cbor::decode($content, true));
     }
     //Return the whole array if no key was specified
     if (is_null($key)) {
         return $this->cbor;
     }
     //Get key value in dot notation
     return array_get($this->cbor->all(), $key, $default);
 }
コード例 #3
0
ファイル: CborResponse.php プロジェクト: lrezek/Cbor4Laravel
 /**
  * Get the cbor decoded data from the response
  *
  * @return mixed
  */
 public function getData()
 {
     return Cbor::decode($this->data);
 }
コード例 #4
0
ファイル: CborTest.php プロジェクト: lemonblast/cbor4php
 function testAbruptStringEnd()
 {
     $this->setExpectedException(CBOR_EXCEPTION);
     Cbor::decode(pack('C*', 0b1111011, 97, 98));
 }
コード例 #5
0
ファイル: AbstractFloat.php プロジェクト: lemonblast/cbor4php
 /**
  * Encodes the first byte, with an additional type that is dependent on the float type.
  *
  * @return string The encoded byte.
  */
 protected static function encodeFirstByte()
 {
     return Cbor::encodeFirstByte(MajorType::SIMPLE_AND_FLOAT, static::getAdditionalType());
 }