<?php

namespace inc;


class fileStorage
{
    public static $path = __DIR__ . '/../Log/';

    public static function checkexistAndMkrPath()
    {
        $a = realpath(self::$path);
        if (!file_exists($a)) {
            mkdir($a, 0777);
        }
    }

    public static function checkStore($name)
    {
        self::checkexistAndMkrPath();
        return file_exists(self::$path . $name . '.json');
    }

    public static function saveTofile($name, $data)
    {
            file_put_contents(self::$path . $name . '.json', json_encode($data));

        return true;
    }

    public static function readFile($name)
    {
        if (self::checkStore($name)) {
            return (array) json_decode(file_get_contents(self::$path . $name . '.json'),true);
        }
        return false;

    }

    public static function removeFile($name)
    {
        if (self::checkStore($name)) {
            return unlink(self::$path . $name . '.json');
        }
    }
}