Your IP : 216.73.216.79


Current Path : /var/www/html/dynaweb-starter/plugin/dynaweb-site/src/Classes/
Upload File :
Current File : /var/www/html/dynaweb-starter/plugin/dynaweb-site/src/Classes/GenerateLayoutFile.php

<?php

namespace Dynaweb\DynawebSite\Classes;

use Illuminate\Support\Facades\Storage;
use Dynaweb\DynawebSite\Enums\FrontendComponentType;
use Dynaweb\DynawebSite\Models\FrontendComponent;

class GenerateLayoutFile
{
    private $extension;

    private $content;

    private $name;

    public function __construct(
        public $provider
    ) {
    }

    /**
     * storage directory
     */
    public function setDir($dir=null)
    {
        $this->dir = !empty($dir) ? $dir : '/LAYOUTS/';
        return $this;
    }

    /**
     *
     * Handle the generation of component
     */
    public function handle()
    {
        $this
            ->setFileName()
            ->setFileType()
            ->setFileContent()
            ->createFile();
    }

    /***
    * Handle file name
    */
    public function setFileName()
    {
        $this->name = $this->provider['slug'];
        return $this;
    }

    /***
     * Handle file type
     */
    public function setFileType()
    {
        $this->extension = FrontendComponentType::PHP->extension(); //enums

        return $this;
    }

    /***
     * Handle file content
     */
    public function setFileContent()
    {
        $this->content = $this->provider['layout'];
        return $this;
    }

    /**
     * Create file
     */
    public function createFile()
    {

        $site_meta = Storage::disk('local')->put($this->dir . $this->name . $this->extension, $this->content);
    }
}