-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackup_Ler.php
108 lines (91 loc) · 3.32 KB
/
Backup_Ler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
Classe Backup_Ler. Classe que salva os dados no arquivo em formato serializado e comprimido letras, retornando um float de 0 a 100
Copyright (C) 2010 Silas Ribas Martins and Hugo Henrique
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Classe que salva os dados no arquivo em formato serializado e comprimido
*
* @package Backup
* @name Backup_Ler
* @version 0.1
* @author Silas Ribas Martins < [email protected] >
* @example $x = new Backup_Ler( 'pasta/onde/esta/salvo/o/arquivo_bkp' ); $x->getDados();
*/
class Backup_Ler
{
/**
* Onde será atribuido os dados recuperados do arquivo
* @var array
*/
protected $dados = array();
/**
* Caminho do arquivo onde está os dados a ser recuperado
* @var string
*/
protected $arquivo = null;
/**
* Construtor podendo passar o nome do arquivo a ser recuperado os dados
* @param string|null $arquivo
* @return Backup_Ler
*/
public function __construct( $arquivo = null )
{
if( !empty( $arquivo ) )
$this->setArquivo( $arquivo );
return $this;
}
/**
* Seta array vazio para $dados e null para arquivo, para corrigir problema de cache de informações carregadas
*/
public function destroi()
{
$this->dados = array();
$this->arquivo = null;
}
/**
* Caminho do arquvios onde está os dados a serem recuperados
* @param string $arquivo
* @return Backup_Ler
*/
public function setArquivo( $arquivo )
{
if( !file_exists( $arquivo ) )
throw new InvalidArgumentException ( 'Arquivo não existe.' );
$this->arquivo = $arquivo;
return $this;
}
/**
* Retorna o caminho do arquivo
* @return string
*/
public function getArquivo()
{
return $this->arquivo;
}
/**
* Retorna os dados descomprimidos e deserealizados
* @return array
*/
public function getDados()
{
if( strlen( $this->getArquivo() ) == 0 )
throw new Exception( 'Arquivo não informado.' );
if( !file_exists( $this->getArquivo() ) )
throw new Exception( 'Arquivo não existe.' );
if( empty( $this->dados ) )
$this->dados = unserialize( gzuncompress( file_get_contents( $this->getArquivo() ) ) );
return $this->dados;
}
}
?>