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/stafa/stafa.nl/app/Komma/Kms/Core/Attributes/SendSetPasswordMailButton.php
<?php
namespace App\Komma\Kms\Core\Attributes;

use App\Komma\Users\Models\KmsUser;
use App\Komma\Users\Models\SiteUser;
use InvalidArgumentException;
use Illuminate\Foundation\Auth\User as Authenticatable;

class SendSetPasswordMailButton extends Attribute
{
    /** @var string */
    private $buttonText = '';

    /** @var string */
    private $setPasswordUrl = '';

    /** @var Authenticatable */
    private $authenticatable;

    /**
     * Password constructor.
     * @param Authenticatable $authenticatable
     */
    public function __construct(Authenticatable $authenticatable)
    {
        $this->authenticatable = $authenticatable;
        $this->setPasswordSetUrl($authenticatable);
        parent::__construct();
        $uuid = uniqid('', true);
        $this->mapValueFrom(Attribute::ValueFromItself, $uuid);
    }

    /**
     * @param Authenticatable $authenticatable
     */
    private function setPasswordSetUrl(Authenticatable $authenticatable) {
        if(is_a($authenticatable, KmsUser::class)) {
            $this->setPasswordUrl = route('kms_users.send_set_password_email');
        } else if(is_a($authenticatable, SiteUser::class)) {
            $this->setPasswordUrl = route('site_users.send_set_password_email');
        } else {
            throw new InvalidArgumentException('The authenticatable is not supported.');
        }
    }

    /**
     * Returns a view that visually represents this attribute
     *
     * @return \Illuminate\View\View
     */
    public function render()
    {
        return view('kms/attributes.sendSetPasswordMailButton', [
            'setPasswordUrl' => $this->setPasswordUrl,
            'buttonText' => $this->buttonText,
            'dataAttributes' => $this->getDataAttributes(),
            'styleClass' => $this->getStyleClass(),
            'authenticatableId' => $this->authenticatable->id,
            'key' => $this->getKey()
        ]);
    }

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

    /**
     * @param string $buttonText
     * @return $this
     */
    public function setButtonText(string $buttonText): SendSetPasswordMailButton
    {
        $this->buttonText = $buttonText;
        return $this;
    }
}