Example #1
0
 /**
  * @param string $key
  * @param $value
  * @throws KnitException
  */
 public function set(string $key, $value)
 {
     // Lowercase key
     $key = strtolower($key);
     // Check if key is reserved
     if (in_array($key, $this->reservedKeys)) {
         throw KnitException::reservedDataKey($key);
     }
     // Check value type
     if (is_object($value)) {
         // Convert Object to Array
         $value = json_decode(json_encode($value), true);
     }
     if (!is_scalar($value) && !is_null($value) && !is_array($value)) {
         // Unsupported value type
         throw KnitException::badAssignedValue($key, gettype($value));
     }
     // Assign
     $this->data[$key] = $value;
 }