Sindbad~EG File Manager

Current Path : /opt/nginxhttpd_/src/Repository/Redis/
Upload File :
Current File : //opt/nginxhttpd_/src/Repository/Redis/VhostRepository.php

<?php

namespace App\Repository\Redis;

use App\Entity\Redis\VhostEntity;
use Predis\ClientInterface;

class VhostRepository
{
    public function __construct(ClientInterface $redis)
    {
        $this->redis = $redis;
    }

    public function getAllKeys(string $pattern = '*.*') : array {
        return $this->redis->keys($pattern);
    }

    public function get(string $key) : ?VhostEntity {
        if(!$this->exists($key)){
            return null;
        }

        $vhost = new VhostEntity();
        $vhost->setKey($key);

        // Keep the setters
        foreach(get_class_methods(VhostEntity::class) as $k => $method) {
            if (strpos($method, 'set') === 0) {
                $redisFieldKey = lcfirst(str_replace('set', '', $method));
                $value = $this->redis->hget($key, $redisFieldKey);
                if($redisFieldKey === 'key' && is_null($value)){
                    continue;
                }
                $vhost->$method($value);
            }
        }

        return $vhost;
    }

    public function exists(string $key) : bool {
        return $this->redis->exists($key);
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists