Skip to content

Commit a89c099

Browse files
committed
MFH
2 parents 71f7af1 + 91e5345 commit a89c099

File tree

5 files changed

+84
-45
lines changed

5 files changed

+84
-45
lines changed

ChangeLog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ FTP protocol support for the XP Framework ChangeLog
33

44
## ?.?.? / ????-??-??
55

6-
## 9.0.2 / 2020-04-04
6+
## 9.1.1 / 2020-04-04
77

88
* Made compatible with XP 10 - @thekid
99

10+
## 9.1.0 / 2019-01-15
11+
12+
* Made `FtpEntry`, `FtpEntryList`, `FtpTransfer` and `FtpTransferStream`
13+
implement `lang.Value`, restoring their custom string representations.
14+
(@thekid)
15+
* Added compatibility with PHP 7.3 - @thekid
16+
1017
## 9.0.1 / 2018-08-24
1118

1219
* Made compatible with `xp-framework/logging` version 9.0.0 - @thekid

src/main/php/peer/ftp/FtpEntry.class.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace peer\ftp;
22

3+
use lang\Value;
34
use util\Date;
45

56
/**
@@ -9,7 +10,7 @@
910
* @see xp://peer.ftp.FtpFile
1011
* @test xp://peer.ftp.unittest.FtpEntryListTest
1112
*/
12-
abstract class FtpEntry {
13+
abstract class FtpEntry implements Value {
1314
protected
1415
$connection = null,
1516
$name = '',
@@ -268,29 +269,16 @@ public function lastModified() {
268269
}
269270
}
270271

271-
/**
272-
* Set Name
273-
*
274-
* @param var name
275-
*/
276-
public function setName($name) {
277-
$this->name= $name;
278-
}
272+
/** @param string $name */
273+
public function setName($name) { $this->name= $name; }
279274

280-
/**
281-
* Get Name
282-
*
283-
* @return string
284-
*/
285-
public function getName() {
286-
return $this->name;
287-
}
275+
/** @return string */
276+
public function getName() { return $this->name; }
277+
278+
/** @return string */
279+
public function hashCode() { return md5($this->name); }
288280

289-
/**
290-
* Creates a string representation of this object
291-
*
292-
* @return string
293-
*/
281+
/** @return string */
294282
public function toString() {
295283
return sprintf(
296284
"%s(name= %s) {\n".
@@ -311,4 +299,14 @@ public function toString() {
311299
\xp::stringOf($this->date)
312300
);
313301
}
302+
303+
/**
304+
* Comparison implementation
305+
*
306+
* @param var $value
307+
* @return int
308+
*/
309+
public function compareTo($value) {
310+
return $value instanceof self ? strcmp($this->name, $value->name) : 1;
311+
}
314312
}

src/main/php/peer/ftp/FtpEntryList.class.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php namespace peer\ftp;
22

3+
use lang\Value;
4+
35
/**
46
* List of entries on an FTP server
57
*
68
* @see xp://peer.ftp.FtpDir#entries
79
*/
8-
class FtpEntryList implements \IteratorAggregate {
10+
class FtpEntryList implements Value, \IteratorAggregate {
911
protected
1012
$connection = null,
1113
$list = [],
@@ -68,12 +70,21 @@ public function asArray() {
6870
return $r;
6971
}
7072

73+
/** @return string */
74+
public function hashCode() { return spl_object_hash($this); }
75+
76+
/** @return string */
77+
public function toString() {
78+
return nameof($this).'('.$this->size().' entries)@'.\xp::stringOf($this->list);
79+
}
80+
7181
/**
72-
* Creates a string representation of this list
82+
* Comparison implementation
7383
*
74-
* @return string
84+
* @param var $value
85+
* @return int
7586
*/
76-
public function toString() {
77-
return nameof($this).'('.$this->size().' entries)@'.\xp::stringOf($this->list);
87+
public function compareTo($value) {
88+
return $value === $this ? 0 : 1;
7889
}
7990
}

src/main/php/peer/ftp/FtpTransfer.class.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php namespace peer\ftp;
22

3+
use lang\Value;
4+
35
/**
46
* Base class for up- and downloads
57
*
6-
* @see xp://peer.ftp.FtpUpload
7-
* @see xp://peer.ftp.FtpDownload
8-
* @purpose Abstract base class
8+
* @see xp://peer.ftp.FtpUpload
9+
* @see xp://peer.ftp.FtpDownload
910
*/
10-
abstract class FtpTransfer {
11+
abstract class FtpTransfer implements Value {
1112
const ASCII = 1;
1213
const BINARY = 2;
1314

@@ -175,4 +176,20 @@ protected abstract function doTransfer();
175176
* @param int size
176177
*/
177178
public abstract function size();
179+
180+
/** @return string */
181+
public function hashCode() { return spl_object_hash($this); }
182+
183+
/** @return string */
184+
public function toString() { return nameof($this); }
185+
186+
/**
187+
* Comparison implementation
188+
*
189+
* @param var $value
190+
* @return int
191+
*/
192+
public function compareTo($value) {
193+
return $value === $this ? 0 : 1;
194+
}
178195
}

src/main/php/peer/ftp/FtpTransferStream.class.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php namespace peer\ftp;
22

3+
use lang\Value;
34
use peer\Socket;
45

5-
66
/**
77
* Base class for in- and output streams
88
*
9-
* @see xp://peer.ftp.FtpOutputStream
10-
* @see xp://peer.ftp.FtpIntputStream
11-
* @purpose Abstract base class
9+
* @see xp://peer.ftp.FtpOutputStream
10+
* @see xp://peer.ftp.FtpIntputStream
1211
*/
1312
abstract class FtpTransferStream {
1413
protected
@@ -46,15 +45,6 @@ public function __construct(FtpFile $file) {
4645
*/
4746
protected abstract function getCommand();
4847

49-
/**
50-
* Creates a string representation of this file
51-
*
52-
* @return string
53-
*/
54-
public function toString() {
55-
return nameof($this).'<'.$this->file->toString().'>';
56-
}
57-
5848
/**
5949
* Close this buffer.
6050
*
@@ -76,6 +66,22 @@ public function close() {
7666
}
7767
}
7868

69+
/** @return string */
70+
public function hashCode() { return '>'.$this->file->hashCode(); }
71+
72+
/** @return string */
73+
public function toString() { return nameof($this).'<'.$this->file->toString().'>'; }
74+
75+
/**
76+
* Comparison implementation
77+
*
78+
* @param var $value
79+
* @return int
80+
*/
81+
public function compareTo($value) {
82+
return $value instanceof self ? $this->file->compareTo($value->file) : 1;
83+
}
84+
7985
/**
8086
* Destructor. Ensures transfer socket is closed
8187
*

0 commit comments

Comments
 (0)