HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/werken-bij-stafa.komma.pro/app/Komma/Kms/Core/Attributes/View.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Komma\Kms\Core\Attributes;

use App\Komma\Kms\Core\Attributes\Traits\LabelTrait;
use Illuminate\Support\Arr;

class View extends Attribute {
    use LabelTrait;

    /** @var string $viewName */
    protected $viewName;

    /** @var string $viewComposerClass */
    protected $viewComposerClass;

    /** @var mixed $viewData */
    protected $viewData;

    public function __construct(string $viewLabelText)
    {
        parent::__construct();

        $this->viewName = $viewLabelText;
        $uuid = uniqid('seperator', true);
        $this->mapValueFrom(Attribute::ValueFromItself, $uuid);
        parent::setValue($uuid);
    }

    public function render()
    {
        $data = array_merge($this->viewData, [
            'viewName' => $this->viewName,
            'attribute' => $this,
        ]);
        return view('kms/attributes.view', $data)->render();
    }

    /**
     * @return string
     */
    public function getViewName(): string
    {
        return $this->viewName;
    }

    /**
     * @param string $viewName
     * @return View
     */
    public function setViewName(string $viewName): View
    {
        $this->viewName = $viewName;
        $this->updateViewComposer();
        return $this;
    }

    /**
     * @return string
     */
    public function getViewComposerClass(): string
    {
        return $this->viewComposerClass;
    }

    /**
     * @param string $viewComposerClass
     * @return View
     */
    public function setViewComposerClass(string $viewComposerClass): View
    {
        $this->viewComposerClass = $viewComposerClass;
        $this->updateViewComposer();
        return $this;
    }

    /**
     * @return mixed
     */
    public function getViewData()
    {
        return $this->viewData;
    }

    /**
     * @param mixed $viewData
     * @return View
     */
    public function setViewData(array $viewData): View
    {
        $this->viewData = $viewData;
        return $this;
    }

    private function updateViewComposer()
    {
        if(!$this->viewName || !$this->viewComposerClass) return;
        \View::composer($this->viewName, $this->viewComposerClass);
    }
}