<?php

namespace app\models\mikrotik\ip\webproxy;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use yii\base\Model;
use Yii;
use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Contents extends Model {

    public $file_size;
    public $uri;
    public $last_modified;

    public function rules() {
        return [
            ['file_size', 'string'],
            ['uri', 'string'],
            ['last_modified', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/ip/proxy/cache-contents/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Contents();
                $c->file_size = $response->getProperty('file-size');
                $c->uri = $response->getProperty('uri');
                $c->last_modified = $response->getProperty('last-modified');
                $return[] = $c;
            }
        }
        return $return;
    }

}
