10000 fix integration on Windows · trdynet/laravel-filemanager@687a02d · GitHub
[go: up one dir, main page]

Skip to content

Commit 687a02d

Browse files
committed
fix integration on Windows
1 parent ed59a91 commit 687a02d

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

src/Lfm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function __construct(Config $config = null, Request $request = null)
2222
public function getStorage($storage_path)
2323
{
2424
if ($this->config->get('lfm.driver') === 'storage') {
25-
return new LfmStorageRepository($storage_path, $this->config->get('lfm.disk'));
25+
return new LfmStorageRepository($storage_path, $this);
2626
} else {
27-
return new LfmFileRepository($storage_path);
27+
return new LfmFileRepository($storage_path, $this);
2828
}
2929
}
3030

src/LfmFileRepository.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
class LfmFileRepository implements RepositoryContract
88
{
99
private $path;
10+
private $helper;
1011

11-
public function __construct($storage_path)
12+
public function __construct($storage_path, $helper)
1213
{
1314
$this->path = $storage_path;
15+
$this->helper = $helper;
1416
}
1517

1618
public function __call($function_name, $arguments)
@@ -22,23 +24,14 @@ public function __call($function_name, $arguments)
2224
// TODO: check ending with slash in tests
2325
public function rootPath()
2426
{
25-
return public_path() . '/';
27+
return public_path() . $this->helper->ds();
2628
}
2729

2830
public function url($path)
2931
{
3032
return '/' . $path;
3133
}
32-
33-
public function isDirectory()
34-
{
35-
$parent_path = substr($this->path, 0, strrpos($this->path, '/'));
36-
$current_path = $this->path;
37-
$this->path = $parent_path;
38-
39-
return in_array($current_path, $this->directories());
40-
}
41-
34+
4235
public function move($new_lfm_path)
4336
{
4437
return File::move($this->path, $new_lfm_path->path('storage'));

src/LfmPath.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(Lfm $lfm = null)
2424
public function __get($var_name)
2525
{
2626
if ($var_name == 'storage') {
27-
return $this->helper->getStorage($this->path('storage'));
27+
return $this->helper->getStorage($this->path('url'));
2828
}
2929
}
3030

@@ -63,7 +63,7 @@ public function path($type = 'storage')
6363
{
6464
if ($type == 'working_dir') {
6565
// working directory: /{user_slug}
66-
return $this->normalizeWorkingDir();
66+
return $this->translateToLfmPath($this->normalizeWorkingDir());
6767
} elseif ($type == 'url') {
6868
// storage: files/{user_slug}
6969
return $this->helper->getCategoryName() . $this->path('working_dir');
@@ -78,6 +78,11 @@ public function path($type = 'storage')
7878
}
7979
}
8080

81+
public function translateToLfmPath($path)
82+
{
83+
return str_replace($this->helper->ds(), Lfm::DS, $path);
84+
}
85+
8186
public function translateToOsPath($path)
8287
{
8388
return str_replace(Lfm::DS, $this->helper->ds(), $path);
@@ -142,6 +147,25 @@ public function createFolder()
142147
$this->storage->makeDirectory(0777, true, true);
143148
}
144149

150+
public function isDirectory()
151+
{
152+
$working_dir = $this->path('working_dir');
153+
$parent_dir = substr($working_dir, 0, strrpos($working_dir, '/'));
154+
155+
$parent_path = clone $this;
156+
$parent_path->dir($parent_dir)->setName(null);
157+
158+
$directories = $parent_path->directories();
159+
160+
$that = $this;
161+
162+
$directories = array_map(function ($directory_path) use ($that) {
163+
return $this->translateToLfmPath($directory_path);
164+
}, $directories);
165+
166+
return in_array($this->path('url'), $directories);
167+
}
168+
145169
/**
146170
* Check a folder and its subfolders is empty or not.
147171
*

src/LfmStorageRepository.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
class LfmStorageRepository implements RepositoryContract
88
{
99
private $disk;
10-
1110
private $path;
11+
private $helper;
1212

13-
public function __construct($storage_path, $disk_name)
13+
public function __construct($storage_path, $helper)
1414
{
15-
$this->disk = Storage::disk($disk_name);
15+
$this->helper = $helper;
16+
$this->disk = Storage::disk($this->helper->config('disk'));
1617
$this->path = $storage_path;
1718
}
1819

@@ -28,15 +29,6 @@ public function rootPath()
2829
return $this->disk->getDriver()->getAdapter()->getPathPrefix();
2930
}
3031

31-
public function isDirectory()
32-
{
33-
$parent_path = substr($this->path, 0, strrpos($this->path, '/'));
34-
$current_path = $this->path;
35-
$this->path = $parent_path;
36-
37-
return in_array($current_path, $this->directories());
38-
}
39-
4032
public function move($new_lfm_path)
4133
{
4234
return $this->disk->move($this->path, $new_lfm_path->path('storage'));

src/controllers/FolderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getFolders()
2323
return (object) [
2424
'name' => trans('laravel-filemanager::lfm.title-' . $type),
2525
'url' => $path->path('working_dir'),
26-
'children' => $path->folders('name'),
26+
'children' => $path->folders(),
2727
'has_next' => ! ($type == end($folder_types)),
2828
];
2929
}, $folder_types),

0 commit comments

Comments
 (0)
0