My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
<?php

require_once 'Ftp/Adapter/Interface.php';

require_once 'Ftp/Adapter/Ftp.php';

require_once 'Ftp/Directory.php';

class Skjb_Ftp
{
protected $config = array(
'adapter' => 'Skjb_Ftp_Adapter_Ftp',
);

protected $adapter = null;

private $_currentPath = null;

private $_currentDirectory = null;

public function __construct($config = null)
{
if ($config !== null) {
$this->setConfig($config);
}
}

public function setConfig($config = array())
{
if ($config instanceof Zend_Config) {
$config = $config->toArray();

} elseif (! is_array($config)) {
throw new Exception('Array or Zend_Config object expected, got ' . gettype($config));
}

foreach ($config as $k => $v) {
$this->config[strtolower($k)] = $v;
}

// Pass configuration options to the adapter if it exists
if ($this->adapter instanceof Skjb_Ftp_Adapter_Interface) {
$this->adapter->setConfig($config);
}

return $this;
}

public function getCurrentDirectory()
{
if ($this->_currentDirectory == null) {
if ($this->_currentPath == null) {
$this->_currentPath = $this->getAdapter()->getCurrentPath();
}
$this->_currentDirectory = new Skjb_Ftp_Directory($this->_currentPath, $this);
}

return $this->_currentDirectory;
}

public function setAdapter($adapter)
{
if (is_string($adapter)) {
$adapter = new $adapter;
}

if (! $adapter instanceof Skjb_Ftp_Adapter_Interface) {
throw new Exception('Passed adapter is not a valid FTP connection adapter');
}

$this->adapter = $adapter;
$config = $this->config;
unset($config['adapter']);
$this->adapter->setConfig($config);
}

public function getAdapter()
{
if ($this->adapter == null) {
$this->setAdapter($this->config['adapter']);
}

return $this->adapter;
}

public function changeDir($path)
{
$this->getAdapter()->changeDir($path);

$this->_currentPath = $path;
}
}

Change log

r59 by superhappycamperboy on May 26, 2010   Diff
Moving everything to the library subfolder
Go to: 
Project members, sign in to write a code review

Older revisions

r34 by superhappycamperboy on May 21, 2010   Diff
Moving everything into the Skjb folder
r31 by superhappycamperboy on Mar 23, 2010   Diff
Changing FTP to use adapters
r22 by superhappycamperboy on Mar 17, 2010   Diff
Adding some of my ZF proposal code and
other utilities
All revisions of this file

File info

Size: 2368 bytes, 92 lines
Powered by Google Project Hosting