Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kraity committed Dec 27, 2021
1 parent 29cc15d commit cb95d8d
Show file tree
Hide file tree
Showing 9 changed files with 2,952 additions and 0 deletions.
438 changes: 438 additions & 0 deletions Format.php

Large diffs are not rendered by default.

638 changes: 638 additions & 0 deletions Kat/Kat.php

Large diffs are not rendered by default.

223 changes: 223 additions & 0 deletions Kat/Plus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?php
/**
* @Package Kat
* @Author 陆之岇(kraity)
* @Studio 南博网络科技工作室
* @GitHub https://github.com/krait-team/kat-php
* @Version 1.0.0
* @Description Data exchange format
*/

/**
* @param $data
* @param null $name
*/
function kat_response($data, $name = NULL)
{
$kat = kat_encode($data, $name);
header('Content-Length: ' . strlen($kat));
header('Content-Type: text/kat');
exit($kat);
}

/**
* Class Crash
*/
class Crash extends Exception
{
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct($message = '', $code = 500, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}

/**
* Class KatAry
*/
class KatAry
{
protected $alias;
protected $value;

/**
* @param array|$value
* @param null $alias
*/
public function __construct($value = [], $alias = null)
{
$this->alias = $alias;
$this->value = $value;
}

/**
* @param $alias
*/
public function alias($alias): void
{
$this->alias = $alias;
}

/**
* @param $val
*/
public function add($val)
{
$this->value[] = $val;
}

/**
* @param $key
* @param $val
*/
public function set($key, $val)
{
$this->value[$key] = $val;
}

/**
* @param $key
* @param null $def
* @return mixed|null
*/
public function get($key, $def = null)
{
return isset($this->value[$key]) ?
$this->value[$key] : $def;
}

/**
* @param $key
*/
public function del($key)
{
unset($this->value[$key]);
}

/**
* @target clear
*/
public function clear()
{
$this->alias = null;
$this->value = [];
}

/**
* @target clean
*/
public function clean()
{
$this->alias = null;
$this->value = null;
}

/**
* @return null|string
*/
public function class()
{
return $this->alias;
}

/**
* @return array
*/
public function entry()
{
return $this->value;
}
}

/**
* Class KatAny
*/
class KatAny
{
protected $alias;
protected $value;

/**
* @param array|$value
* @param null $alias
*/
public function __construct($value = [], $alias = null)
{
$this->alias = $alias;
$this->value = $value;
}

/**
* @param $alias
*/
public function alias($alias): void
{
$this->alias = $alias;
}

/**
* @param $key
* @param $val
*/
public function set($key, $val)
{
$this->value[$key] = $val;
}

/**
* @param $key
* @param null $def
* @return mixed|null
*/
public function get($key, $def = null)
{
return isset($this->value[$key]) ?
$this->value[$key] : $def;
}

/**
* @param $key
*/
public function del($key)
{
unset($this->value[$key]);
}

/**
* @target clear
*/
public function clear()
{
$this->alias = null;
$this->value = [];
}

/**
* @target clean
*/
public function clean()
{
$this->alias = null;
$this->value = null;
}

/**
* @return null|string
*/
public function class()
{
return $this->alias;
}

/**
* @return array
*/
public function entry()
{
return $this->value;
}
}
Loading

0 comments on commit cb95d8d

Please sign in to comment.