Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d41c29

Browse filesBrowse files
committed
fix
1 parent f92348e commit 6d41c29
Copy full SHA for 6d41c29

File tree

Expand file treeCollapse file tree

3 files changed

+141
-291
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+141
-291
lines changed

‎src/Symfony/Component/Finder/FtpSplFileInfo.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/FtpSplFileInfo.php
+39-172Lines changed: 39 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -17,145 +17,50 @@
1717
*
1818
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
1919
*/
20-
class FtpSplFileInfo extends \SplFileInfo
20+
class FtpSplFileInfo extends SplFileInfo
2121
{
2222

23-
const TYPE_UNKNOWN = 1;
23+
const TYPE_UNKNOWN = 1;
2424
const TYPE_DIRECTORY = 2;
25-
const TYPE_FILE = 3;
26-
const TYPE_LINK = 4;
25+
const TYPE_FILE = 3;
26+
const TYPE_LINK = 4;
2727

28-
private $type = self::TYPE_DIRECTORY;
28+
private $type = self::TYPE_FILE;
29+
private $basePath = '';
2930

30-
/**
31-
* The name of a directory is always .:
32-
*
33-
* Directory: /lorem/ipsum/dolor
34-
* Path: /lorem/ipsum/dolor
35-
* Filename: .
36-
*
37-
*
38-
* File: /lorem/ipsum/dolor/sit.txt
39-
* Path: /lorem/ipsum/dolor
40-
* Filename: sit.txt
41-
*
42-
*/
43-
private $path = '/';
44-
private $filename = '.';
45-
46-
/**
47-
* Constructor.
48-
*
49-
* Examples:
50-
*
51-
* $e = new FtpSplFileInfo('/this/is/a/dir');
52-
* $e = new FtpSplFileInfo('/and/this/is/a/file.txt', self::TYPE_FILE);
53-
*
54-
* @param type $item The name of the file or directory
55-
* @param type $type The type of the first parameter: directory or file
56-
*/
57-
public function __construct($item = '/', $type = self::TYPE_DIRECTORY)
31+
public function __construct($file, $relativePath, $relativePathname, $basePath)
5832
{
59-
$this->setType($type);
60-
61-
if ($type === self::TYPE_DIRECTORY) {
62-
$this->filename = '.';
63-
$this->path = $item;
64-
} else if ($type === self::TYPE_FILE) {
65-
$tmp = self::parseFile($item);
66-
$this->filename = $tmp['filename'];
67-
$this->path = $tmp['path'];
68-
}
69-
parent::__construct($this->getFullFilename());
33+
parent::__construct($file, $relativePath, $relativePathname);
34+
$this->setBasePath($basePath);
7035
}
7136

72-
/**
73-
* Checks if the current object is a directory.
74-
*
75-
* @return Boolean true if the current object represents a directory
76-
*
77-
*/
78-
public function isDir()
37+
public function setBasePath($basePath)
7938
{
80-
return self::TYPE_DIRECTORY === $this->type;
39+
$this->basePath = $basePath;
8140
}
8241

83-
/**
84-
* Checks if the current object is a file.
85-
*
86-
* @return Boolean true if the current object represents a file
87-
*
88-
*/
89-
public function isFile()
42+
public function getBasePath()
9043
{
91-
return self::TYPE_FILE === $this->type;
44+
return $this->basePath;
9245
}
9346

94-
/**
95-
* Returns the full name of the current object.
96-
*
97-
* Example outputs:
98-
* /
99-
* /pub
100-
* /pub/some/dir
101-
* /some/file.txt
102-
* /other.yml
103-
*
104-
* @return string full absolute name of a current object
105-
*
106-
*/
107-
public function getFullFilename()
47+
public function getRealpath()
10848
{
109-
if ($this->isDir()) {
110-
return $this->getPath();
111-
}
112-
if ($this->path === '/' && $this->filename === '.') {
113-
return '/';
114-
}
115-
if ($this->path === '/') {
116-
return '/' . $this->filename;
117-
}
118-
119-
return $this->path . '/' . $this->filename;
49+
return $this->getPathname();
12050
}
12151

122-
/**
123-
* Current object represents a directory.
124-
* Returns the absolute path of the $item from the current dir.
125-
*
126-
* Example:
127-
*
128-
* Current dir:
129-
* path: /some/dir
130-
* name: .
131-
*
132-
* Item:
133-
* info.xml
134-
*
135-
* Result:
136-
* /some/dir/info.xml
137-
*
138-
* @return string
139-
*
140-
*/
14152
public function getItemname($item)
14253
{
143-
if ($this->path === '/') {
144-
return '/' . $item;
54+
if (0 === strpos($item, '/')) {
55+
throw new \InvalidArgumentException(sprintf('Item can not be absolute path: "%s".', $item));
56+
}
57+
$result = $this->getRealpath();
58+
$len = strlen($result);
59+
if ($result[$len - 1] != '/') {
60+
$result .= '/';
14561
}
14662

147-
return $this->path . '/' . $item;
148-
}
149-
150-
/**
151-
* Returns filename.
152-
*
153-
* @return string
154-
*
155-
*/
156-
public function getFilename()
157-
{
158-
return $this->filename;
63+
return $result . $item;
15964
}
16065

16166
/**
@@ -179,13 +84,25 @@ public function getType()
17984
}
18085

18186
/**
182-
* Returns path.
87+
* Checks if the current object is a directory.
88+
*
89+
* @return Boolean true if the current object represents a directory
18390
*
184-
* @return string the path of the current object
18591
*/
186-
public function getPath()
92+
public function isDir()
93+
{
94+
return self::TYPE_DIRECTORY === $this->type;
95+
}
96+
97+
/**
98+
* Checks if the current object is a file.
99+
*
100+
* @return Boolean true if the current object represents a file
101+
*
102+
*/
103+
public function isFile()
187104
{
188-
return $this->path;
105+
return self::TYPE_FILE === $this->type;
189106
}
190107

191108
/**
@@ -200,7 +117,6 @@ public static function parseRawListItem($item)
200117
{
201118
if ($item === '') {
202119
return self::TYPE_UNKNOWN;
203-
//throw new \InvalidArgumentException('$item is null!');
204120
}
205121
switch ($item[0]) {
206122

@@ -218,53 +134,4 @@ public static function parseRawListItem($item)
218134
}
219135
}
220136

221-
/**
222-
* Parse the name of the file into pair: path/name.
223-
* The name must be absolute (i.e. it must start with /).
224-
*
225-
* Example:
226-
*
227-
* /abc/defgh/ij.txt
228-
*
229-
* path: /abc/defgh
230-
* filename: ij.txt
231-
*
232-
* @param type $file the name to parse
233-
*
234-
* @return array
235-
*
236-
* @throws \InvalidArgumentException
237-
*/
238-
public static function parseFile($file = '/')
239-
{
240-
if (0 !== strpos($file, '/')) {
241-
throw new \InvalidArgumentException(sprintf('File must start with /. It doesnt: "%s"', $file));
242-
}
243-
244-
if (strlen($file) < 2) {
245-
throw new \InvalidArgumentException(sprintf('The name must contain at least two characters. It doesnt: "%s"', $file));
246-
}
247-
248-
$found = strrpos($file, '/');
249-
$tmpPath = substr($file, 0, $found);
250-
$tmpName = substr($file, $found + 1);
251-
if ($tmpPath === '') {
252-
$tmpPath = '/';
253-
}
254-
return array(
255-
'filename' => $tmpName,
256-
'path' => $tmpPath
257-
);
258-
}
259-
260-
/**
261-
* Returns full filename
262-
*
263-
* @return string full filename of the current object
264-
*/
265-
public function __toString()
266-
{
267-
return $this->getFullFilename();
268-
}
269-
270137
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.