<?

namespace Shop\Concrete;

/**
 * Description of ModuleUserCacheTrait
 *
 * @author Admin
 */
trait ModuleUserCacheTrait
{
    
    use \Shop\Concrete\ShopAuthUserTrait;

    public function getCacheKey(): string
    {
        if(! is_a($this->customerService, \Shop\Services\Customer::class)){
            throw new \Exception("shop sevice not set");
        }
        $customer = serialize($this->customerService->buildCurrentCustomer());
        
        $o = new \ReflectionObject($this);
        $hash = "";
        
        foreach(get_object_vars($this) as $props){
            if(!is_object($props)){
                $hash .= json_encode($props);
            }
        }
        //dump($this, $hash);
        $hashM = md5($hash);
        
        return md5($customer . $o->getName() . $hashM);
    }

    public function getCacheLifeTime(): int
    {
        return 3600;
    }

}