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/farmfun.komma.pro/app/Komma/Kms/Core/AbstractModelHandler.php
<?php

declare(strict_types=1);

namespace App\Komma\Kms\Core;

use App\Komma\Kms\Core\Attributes\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;

abstract class AbstractModelHandler implements AbstractModelHandlerInterface
{
    /**
     * @param Collection $attributes
     * @param bool $mayTrowException
     * @return bool
     */
    protected function checkContainsAttributes(Collection $attributes, bool $mayTrowException = true)
    {
        $containsAttributes = true;
        $attributes->each(function ($attribute) use (&$containsAttributes, $mayTrowException) {
            if (! is_a($attribute, Attribute::class)) {
                if ($mayTrowException) {
                    throw new \InvalidArgumentException('The collection did not exclusively contain attributes.');
                }
                $containsAttributes = false;

                return false;
            }
        });

        return $containsAttributes;
    }

    /**
     * Puts the values of attributes in an Eloquent model. And then saves that model.
     *
     * @param Model $model
     * @param Collection $attributes
     * @return Model
     */
    abstract public function save(Model $model, Collection $attributes = null): Model;

    /**
     * Gets the values of an Eloquent model and passes them to a collection of attributes
     *
     * @param Model $model
     * @param Collection $attributes
     * @return Collection
     */
    abstract public function load(Model $model, Collection $attributes = null): Collection;

    /**
     * Destroys the appropriate related models for a given model.
     * Those related models must be the responsibility of this service
     *
     * @param Model $model
     */
    abstract public function destroyForModel(Model $model);
}