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/vanderkampen.komma.pro/app/KommaApp/Kms/Core/Attributes/View.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\KommaApp\Kms\Core\Attributes;

use App\KommaApp\Kms\Core\Attributes\Traits\LabelTrait;

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 $viewName)
    {
        $this->viewName = $viewName;
        parent::__construct();
    }

    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): 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($viewData): View
    {
        $this->viewData = $viewData;
        return $this;
    }

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