depage-fs
Loading...
Searching...
No Matches
PublicSshKey.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Depage\Fs;
4
5
class
PublicSshKey
6
{
7
protected
$key
=
null
;
8
protected
$path
=
null
;
9
protected
$temporary
=
false
;
10
public
function
__construct
($data, $tmpDir =
false
)
11
{
12
if
($tmpDir) {
13
$this->key = $this->
parse
($data);
14
$this->path = $this->
createTmpFile
($tmpDir, $data);
15
}
else
{
16
$this->path = $data;
17
if
(is_file($data) && is_readable($data)) {
18
$this->key = $this->
parse
(file_get_contents($data));
19
}
else
{
20
throw
new
Exceptions\FsException
(
'SSH key file not accessible: "'
. $data .
'".'
);
21
}
22
}
23
}
24
public
function
__destruct
()
25
{
26
$this->
clean
();
27
}
28
29
protected
function
createTmpFile
($tmpDir, $data)
30
{
31
$this->temporary =
true
;
32
33
if
(is_dir($tmpDir) && is_writable($tmpDir)) {
34
$path
= tempnam($tmpDir,
'depage-fs'
);
35
$bytesWritten = $this->
file_put_contents
(
$path
, $data);
36
37
if
($bytesWritten ===
false
) {
38
throw
new
Exceptions\FsException
(
'Cannot create temporary key file "'
.
$path
.
'".'
);
39
}
40
}
else
{
41
throw
new
Exceptions\FsException
(
'Cannot write to temporary key file directory "'
. $tmpDir .
'".'
);
42
}
43
44
return
$path
;
45
}
46
47
protected
function
parse
($keyString)
48
{
49
// @todo do proper check
50
return
$keyString;
51
}
52
public
function
__toString
()
53
{
54
return
$this->path
;
55
}
56
public
function
clean
()
57
{
58
unset($this->key);
59
if
($this->temporary) {
60
if
(is_file($this->path) && is_writable($this->path)) {
61
unlink($this->path);
62
$this->temporary =
false
;
63
}
else
{
64
throw
new
Exceptions\FsException
(
'Cannot delete temporary key file "'
. $this->path .
'".'
);
65
}
66
}
67
}
68
72
public
function
file_put_contents
($filename, $data, $flags = 0, $context =
null
)
73
{
74
\file_put_contents
($filename, $data, $flags, $context);
75
}
76
}
77
78
/* vim:set ft=php sw=4 sts=4 fdm=marker : */
Depage\Fs\Exceptions\FsException
Definition
FsException.php:5
Depage\Fs\PublicSshKey
Definition
PublicSshKey.php:6
Depage\Fs\PublicSshKey\$path
$path
Definition
PublicSshKey.php:8
Depage\Fs\PublicSshKey\$temporary
$temporary
Definition
PublicSshKey.php:9
Depage\Fs\PublicSshKey\__destruct
__destruct()
Definition
PublicSshKey.php:24
Depage\Fs\PublicSshKey\parse
parse($keyString)
Definition
PublicSshKey.php:47
Depage\Fs\PublicSshKey\__construct
__construct($data, $tmpDir=false)
Definition
PublicSshKey.php:10
Depage\Fs\PublicSshKey\__toString
__toString()
Definition
PublicSshKey.php:52
Depage\Fs\PublicSshKey\file_put_contents
file_put_contents($filename, $data, $flags=0, $context=null)
Hook, allows overriding of file_put_contents function.
Definition
PublicSshKey.php:72
Depage\Fs\PublicSshKey\$key
$key
Definition
PublicSshKey.php:7
Depage\Fs\PublicSshKey\createTmpFile
createTmpFile($tmpDir, $data)
Definition
PublicSshKey.php:29
Depage\Fs\PublicSshKey\clean
clean()
Definition
PublicSshKey.php:56
PublicSshKey.php
Generated on
for depage-fs by
doxygen
1.14.0
For an overview of all docs, go to
docs.depage.net