PHP Classes

File: src/Storage/LocalFilesStorage.php

Recommend this page to a friend!
  Classes of Joseluis Laso   PHP Telegram CLI Wrapper   src/Storage/LocalFilesStorage.php   Download  
File: src/Storage/LocalFilesStorage.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Telegram CLI Wrapper
Send messages and other commands to Telegram users
Author: By
Last change:
Date: 8 years ago
Size: 1,338 bytes
 

Contents

Class file image Download
<?php

namespace TelegramCliWrapper\Storage;

use
TelegramCliWrapper\Models\BasicObject;
use
TelegramCliWrapper\Models\User;

class
LocalFilesStorage implements StorageInterface
{
    protected
$path;
    protected
$table;

   
/**
     * LocalFilesStorage constructor.
     * @param string $table
     */
   
public function __construct($table)
    {
       
$this->table = $table;
       
$this->path = __DIR__ . '/../../data/' . $table . '/';
        @
mkdir($this->path, 0777, true);
    }

   
/**
     * @param BasicObject $obj
     * @return bool
     */
   
public function save(BasicObject $obj)
    {
       
file_put_contents(
           
$this->path . $obj->getId() . '.db',
           
serialize($obj)
        );
    }

   
/**
     * @param string $id
     * @return BasicObject
     */
   
public function getById($id)
    {
       
$fileName = $this->path . $id . '.db';
        if (
file_exists($fileName)) {
           
$data = file_get_contents($fileName);

            return
unserialize($data);
        }

        return
null;
    }

   
/**
     * @param string $id
     * @return bool
     */
   
public function remove($id)
    {
       
$fileName = $this->path . $id . '.db';
        if (
file_exists($fileName)) {
           
unlink($fileName);

            return
true;
        }

        return
false;
    }


}