<?php
/**
 * Author: Rymera Web Co
 *
 * @package SAAI\Traits
 */

namespace SAAI\Traits;

/**
 * Trait Trait_Instance
 *
 * @since 1.0.0
 */
trait Singleton_Trait {

    /**
     * Holds the class instance object
     *
     * @var static $instance object
     * @since 1.0.0
     */
    protected static $instance;

    /**
     * Return an instance of this class
     *
     * @param array ...$args The arguments to pass to the constructor.
     *
     * @codeCoverageIgnore
     *
     * @since 1.0.0
     * @return static The class instance object
     */
    public static function instance( ...$args ) {

        if ( null === static::$instance ) {
            static::$instance = new static( ...$args );
        }

        return static::$instance;
    }

    /**
     * Magic get method
     *
     * @param string $key Class property to get.
     *
     * @since 1.0.0
     * @return null|mixed
     */
    public function __get( $key ) {

        return $this->$key ?? null;
    }
}
