knot-lib/cache

View on GitHub
src/util/CacheDataTrait.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
declare(strict_types=1);

namespace knotlib\cache\util;

trait CacheDataTrait
{
    /**
     * encode cache data
     *
     * @param $data
     *
     * @return string
     */
    public function encodeData($data) : string
    {
        return base64_encode(serialize($data));
    }

    /**
     * decode cache data
     *
     * @param $data
     *
     * @return mixed
     */
    public function decodeData($data)
    {
        return unserialize(base64_decode($data));
    }
}