Row edit and delete card working

This commit is contained in:
2018-08-05 17:07:34 +02:00
parent bb8bc459dc
commit a4103e7084
15 changed files with 393 additions and 209 deletions
+72 -50
View File
@@ -65,29 +65,45 @@ function unless($cond, $then, $else = '')
* - Undefined keys are returned as null.
* - array and object values are wrapped in objBag when returned.
*/
class objBag implements JsonSerializable, ArrayAccess {
class objBag implements JsonSerializable, ArrayAccess, \Illuminate\Contracts\Support\Arrayable
{
/** @var object */
private $wrapped;
private $wrapped;
private $recursive;
public function __construct($wrapped)
{
$this->wrapped = (object)$wrapped;
}
/**
* objBag constructor.
* @param mixed $wrapped - wrapped object/array/class
* @param bool $recursive - return array/object values as objBags too
*/
public function __construct($wrapped, $recursive = true)
{
$this->wrapped = (object)$wrapped;
$this->recursive = $recursive;
}
public function __get($name)
{
if ($this->wrapped) {
if (isset($this->wrapped->$name)) {
$x = $this->wrapped->$name;
if (is_array($x) || is_object($x)) return objBag($x);
return $x;
}
}
/**
* @param $name
* @return null|objBag|mixed
*/
public function __get($name)
{
if ($this->wrapped) {
if (isset($this->wrapped->$name)) {
$x = $this->wrapped->$name;
return null;
}
if ($this->recursive && (is_array($x) || is_object($x))) {
return objBag($x);
}
public function __set($name, $value)
return $x;
}
}
return null;
}
public function __set($name, $value)
{
if ($this->wrapped) {
$this->wrapped->$name = $value;
@@ -102,48 +118,53 @@ class objBag implements JsonSerializable, ArrayAccess {
}
public function __isset($name)
{
return isset($this->wrapped->$name);
}
{
return isset($this->wrapped->$name);
}
public function get($name, $def = null)
{
if (!isset($this->$name)) return $def;
return $this->$name;
}
/**
* @param $name
* @param null $def
* @return null|array|mixed
*/
public function get($name, $def = null)
{
if (!isset($this->$name)) return $def;
return $this->$name;
}
public function has($name)
{
return isset($this->$name) && $this->$name !== null;
}
public function has($name)
{
return isset($this->$name) && $this->$name !== null;
}
public function unpack()
{
return $this->wrapped;
}
public function unpack()
{
return $this->wrapped;
}
public function toArray()
{
return(array)$this->wrapped;
}
return (array)$this->wrapped;
}
public function all()
{
return $this->toArray();
}
/**
* Specify data which should be serialized to JSON
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->wrapped;
}
/**
* Specify data which should be serialized to JSON
*
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return $this->wrapped;
}
public function offsetExists($offset)
{
@@ -168,10 +189,11 @@ class objBag implements JsonSerializable, ArrayAccess {
/**
* @param $obj
* @param bool $recursive - whether the bag should be recursive
* @return objBag
*/
function objBag($obj) {
return new \objBag($obj);
function objBag($obj, $recursive=true) {
return new \objBag($obj, $recursive);
}
/**