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/Teamleader/Base/ApiResource.php
<?php

namespace App\Komma\Teamleader\Base;

abstract class ApiResource
{
    /**
     * The original api response
     *
     * @var object
     */
    protected object $_apiResponse;

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected array $_dates = [];

    /**
     * The attributes that should be mapped into other classes or types
     *
     * @var array
     */
    protected array $_typeAttributes = [];

    /**
     * The attributes can be skipped during the factory building
     *
     * @var array
     */
    protected array $_skippableAttributes = [];

    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'date_created';

    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'date_modified';

    /**
     * Get the attributes that should be converted to dates.
     *
     * @return array
     */
    public function getDatesAttributes()
    {
        $defaults = [
            self::CREATED_AT,
            self::UPDATED_AT,
        ];

        return array_unique(array_merge($this->_dates, $defaults));
    }

    /**
     * Set the original api response
     *
     * @param object $apiResponse
     * @return $this
     */
    public function setApiResponse(object $apiResponse): self
    {
        $this->_apiResponse = $apiResponse;
        if (method_exists($this, 'customFactory')) {
            $this->customFactory();
        }

        return $this;
    }

    /**
     * Determine if the given attribute is a date or date castable.
     *
     * @param string $key
     * @return bool
     */
    public function isDateAttribute(string $key)
    {
        return in_array($key, $this->getDatesAttributes(), true);
    }

    /**
     * Is the given attribute an Typed attribute
     *
     * @param string $key
     * @return bool
     */
    public function isTypeAttribute(string $key): bool
    {
        return in_array($key, array_keys($this->_typeAttributes));
    }

    /**
     * Get the Type of the given attribute
     *
     * @param string $key
     * @return string
     */
    public function getTypeOfAttribute(string $key): string
    {
        return $this->_typeAttributes[$key];
    }

    /**
     * Is the given attribute an Skippable attribute
     *
     * @param string $key
     * @return bool
     */
    public function isSkippableAttribute(string $key): bool
    {
        return in_array($key, $this->_skippableAttributes);
    }
}