File "InitializeTrait-20250815123703.php"

Full Path: /home/humancap/cl.humancap.com.my/vendor/desarrolla2/cache/src/Option/InitializeTrait-20250815123703.php
File size: 1.24 KB
MIME-type: text/x-php
Charset: utf-8

<?php
/**
 * This file is part of the Cache package.
 *
 * Copyright (c) Daniel González
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Daniel González <daniel@desarrolla2.com>
 * @author Arnold Daniels <arnold@jasny.net>
 */

declare(strict_types=1);

namespace Desarrolla2\Cache\Option;

/**
 * Auto initialize the cache
 */
trait InitializeTrait
{
    /**
     * Is cache initialized
     * @var bool|null
     */
    protected $initialized = false;


    /**
     * Enable/disable initialization
     *
     * @param bool $enabled
     */
    public function setInitializeOption(bool $enabled)
    {
        $this->initialized = $enabled ? (bool)$this->initialized : null;
    }

    /**
     * Should initialize
     *
     * @return bool
     */
    protected function getInitializeOption(): bool
    {
        return $this->initialized !== null;
    }

    /**
     * Mark as initialization required (if enabled)
     */
    protected function requireInitialization()
    {
        $this->initialized = isset($this->initialized) ? false : null;
    }


    /**
     * Initialize
     *
     * @return void
     */
    abstract protected function initialize(): void;
}