File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Dynamic/Component/ViewComponent.php
<?php
/**
* Created by PhpStorm.
* User: mikevandersanden
* Date: 2019-02-10
* Time: 12:27
*/
namespace App\Komma\Dynamic\Component;
class ViewComponent
{
private $attributes = [];
private $guarded = ['id', 'type', 'view'];
public $id;
public $type_id;
public $type;
public $view;
/**
* @param $name
* @param $value
*/
public function __set($name, $value)
{
if (! in_array($name, $this->guarded)) {
$this->attributes[$name] = $value;
}
}
/**
* @param $name
* @return mixed
*/
public function __get($name)
{
return $this->getAttribute($name);
}
/**
* Determine if an attribute or relation exists on the model.
*
* @param string $key
* @return bool
*/
public function __isset($key)
{
return $this->offsetExists($key);
}
/**
* @param $name
*/
public function __unset($name)
{
if (array_key_exists($name, $this->attributes)) unset($this->attributes[$name]);
}
/**
* @param string $view
*/
public function setView(string $view)
{
$this->view = $view;
}
/**
* @param $id
*/
public function setId($id)
{
$this->id = $id;
}
public function setType($type)
{
$this->type = $type;
}
public function setTypeId($typeId)
{
$this->type_id = $typeId;
}
/**
* Determine if the given attribute exists.
*
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
{
return ! is_null($this->getAttribute($offset));
}
/**
* Get an attribute from the model.
*
* @param string $key
* @return mixed
*/
public function getAttribute($key)
{
if (! $key) {
return;
}
// If the attribute exists in the attribute array or has a "get" mutator we will
// get the attribute's value. Otherwise, we will proceed as if the developers
// are asking for a relationship's value. This covers both types of values.
if (array_key_exists($key, $this->attributes)) {
return $this->attributes[$key];
}
// return $this->getRelationValue($key);
}
}