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/SBogers95/rentman.io/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;

class View extends Attribute
{
    use LabelTrait;

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

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

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

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

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

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

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

    /**
     * @param string $viewName
     * @return View
     */
    public function setViewName(string $viewName): self
    {
        $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): self
    {
        $this->viewComposerClass = $viewComposerClass;
        $this->updateViewComposer();

        return $this;
    }

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

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

        return $this;
    }

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