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/wingssprayer.komma.pro/app/Components/ComponentService.php
<?php
/**
 * Created by PhpStorm.
 * User: mike
 * Date: 27/07/2018
 * Time: 15:22
 */

namespace App\Components;


use App\Components\Component\Component;
use App\Components\Component\ViewComponent;
use App\Components\ComponentArea\ComponentAreaServiceInterface;
use Komma\KMS\Core\AbstractTranslationModel;
use Illuminate\Support\Collection;

class ComponentService
{
    /**
     * @var ComponentAreaServiceInterface
     */
    private $componentAreaService;

    /**
     * ComponentService constructor.
     * @param ComponentAreaServiceInterface $componentAreaService
     */
    public function __construct(ComponentAreaServiceInterface $componentAreaService)
    {
        $this->componentAreaService = $componentAreaService;
    }

    /**
     * For a View we want a simplified class which includes flat values instead of models
     *
     * @param AbstractTranslationModel $modelTranslation
     * @return Collection
     * @throws \ReflectionException
     */
    public function getViewComponents(AbstractTranslationModel $modelTranslation)
    {
        $viewComponents = collect();

        // Fetch components
        $components = $modelTranslation->components();

        /** @var Component $component */
        foreach($components as $component)
        {
            // Create our ViewComponent
            /** @var ViewComponent $viewComponent */
            $viewComponent = new ViewComponent($component);

            // Push prepared ViewComponent in collection
            $viewComponents->push($viewComponent);
        }

        return $viewComponents;
    }

}