Skip to content
This repository was archived by the owner on Aug 22, 2021. It is now read-only.

Commit 4297ed4

Browse files
committed
Compatible with Laravel 5.8 +
1 parent 728fad8 commit 4297ed4

File tree

9 files changed

+67
-72
lines changed

9 files changed

+67
-72
lines changed

README.md

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,29 @@
22

33
UEditor integration for Laravel 5.
44

5-
# 使用
6-
7-
> 视频教程:https://www.laravist.com/series/awesome-laravel-packages/episodes/7
8-
95
## 安装
106

117
```shell
12-
$ composer require "overtrue/laravel-ueditor:~1.0"
8+
$ composer require "codingyu/laravel-ueditor:~2.0"
139
```
1410

1511
## 配置
1612

17-
1. 添加下面一行到 `config/app.php``providers` 部分:
13+
1. 发布配置文件与资源
1814

1915
```php
20-
Overtrue\LaravelUEditor\UEditorServiceProvider::class,
16+
$ php artisan vendor:publish --provider='Codingyu\LaravelUEditor\UEditorServiceProvider'
2117
```
2218

23-
2. 发布配置文件与资源
24-
25-
```php
26-
$ php artisan vendor:publish --provider='Overtrue\LaravelUEditor\UEditorServiceProvider'
27-
```
28-
29-
3. 模板引入编辑器
19+
2. 模板引入编辑器
3020

3121
这行的作用是引入编辑器需要的 css,js 等文件,所以你不需要再手动去引入它们。
3222

3323
```php
3424
@include('vendor.ueditor.assets')
3525
```
3626

37-
4. 编辑器的初始化
27+
3. 编辑器的初始化
3828

3929
```html
4030
<!-- 实例化编辑器 -->
@@ -51,15 +41,10 @@ $ composer require "overtrue/laravel-ueditor:~1.0"
5141

5242
# 说明
5343

54-
1. 5.4+ 请不要忘记 `php artisan storage:link`
55-
1. 如果你使用的是 laravel 5.3 以下版本,请先创建软链接:
56-
```shell
57-
# 请在项目根目录执行以下命令
58-
$ ln -s `pwd`/storage/app/public `pwd`/public/storage
59-
```
60-
1. 在 `config/ueditor.php` 配置 `disk` 为 `'public'` 情况下,上传路径在:`public/uploads/` 下,确认该目录存在并可写。
61-
1. 如果要修改上传路径,请在 `config/ueditor.php` 里各种类型的上传路径,但是都在 public 下。
62-
1. 请在 `.env` 中正确配置 `APP_URL` 为你的当前域名,否则可能上传成功了,但是无法正确显示。
44+
- 5.4+ 请不要忘记 `php artisan storage:link`
45+
- 在 `config/ueditor.php` 配置 `disk` 为 `'public'` 情况下,上传路径在:`public/uploads/` 下,确认该目录存在并可写。
46+
- 如果要修改上传路径,请在 `config/ueditor.php` 里各种类型的上传路径,但是都在 public 下。
47+
- 请在 `.env` 中正确配置 `APP_URL` 为你的当前域名,否则可能上传成功了,但是无法正确显示。
6348

6449
## 七牛支持
6550

@@ -86,7 +71,7 @@ $ composer require "overtrue/laravel-ueditor:~1.0"
8671
8772
### 上传中事件
8873

89-
> Overtrue\LaravelUEditor\Events\Uploading
74+
> Codingyu\LaravelUEditor\Events\Uploading
9075
9176
在保存文件之前,你可以拿到一些信息:
9277

@@ -98,7 +83,7 @@ $ composer require "overtrue/laravel-ueditor:~1.0"
9883

9984
### 上传完成事件
10085

101-
> Overtrue\LaravelUEditor\Events\Uploaded
86+
> Codingyu\LaravelUEditor\Events\Uploaded
10287
10388
它有两个属性:
10489

composer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
2-
"name": "overtrue/laravel-ueditor",
2+
"name": "codingyu/laravel-ueditor",
33
"description": "UEditor integration for Laravel.",
44
"license": "MIT",
55
"authors": [
66
{
7-
"name": "overtrue",
8-
"email": "anzhengchao@gmail.com"
7+
"name": "codingyu",
8+
"email": "everceyu@gmail.com"
99
}
1010
],
11+
"require": {
12+
"laravel/framework": "~5.5|~6.0"
13+
},
1114
"autoload": {
12-
"psr-4":{
13-
"Overtrue\\LaravelUEditor\\":"src/"
15+
"psr-4": {
16+
"Codingyu\\LaravelUEditor\\": "src/"
1417
}
1518
},
1619
"suggest": {
@@ -22,8 +25,8 @@
2225
"extra": {
2326
"laravel": {
2427
"providers": [
25-
"Overtrue\\LaravelUEditor\\UEditorServiceProvider"
28+
"Codingyu\\LaravelUEditor\\UEditorServiceProvider"
2629
]
2730
}
2831
}
29-
}
32+
}

src/Events/Catched.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor\Events;
12+
namespace Codingyu\LaravelUEditor\Events;
1313

1414
use Illuminate\Broadcasting\InteractsWithSockets;
1515
use Illuminate\Foundation\Events\Dispatchable;
@@ -21,7 +21,7 @@
2121
*
2222
* @author yueziii <[email protected]>
2323
*/
24-
class Catched
24+
class Catched
2525
{
2626
use Dispatchable, InteractsWithSockets, SerializesModels;
2727

src/Events/Uploaded.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor\Events;
12+
namespace Codingyu\LaravelUEditor\Events;
1313

1414
use Illuminate\Broadcasting\InteractsWithSockets;
1515
use Illuminate\Foundation\Events\Dispatchable;

src/Events/Uploading.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor\Events;
12+
namespace Codingyu\LaravelUEditor\Events;
1313

14-
use Illuminate\Broadcasting\InteractsWithSockets;
15-
use Illuminate\Foundation\Events\Dispatchable;
1614
use Illuminate\Queue\SerializesModels;
15+
use Illuminate\Foundation\Events\Dispatchable;
16+
use Illuminate\Broadcasting\InteractsWithSockets;
1717
use Symfony\Component\HttpFoundation\File\UploadedFile;
1818

1919
/**

src/StorageManager.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor;
12+
namespace Codingyu\LaravelUEditor;
1313

14-
use Illuminate\Contracts\Filesystem\Filesystem;
14+
use Illuminate\Support\Arr;
15+
use Illuminate\Support\Str;
1516
use Illuminate\Http\Request;
1617
use Illuminate\Support\Facades\Storage;
18+
use Overtrue\LaravelUEditor\Events\Catched;
1719
use Overtrue\LaravelUEditor\Events\Uploaded;
1820
use Overtrue\LaravelUEditor\Events\Uploading;
19-
use Overtrue\LaravelUEditor\Events\Catched;
21+
use Illuminate\Contracts\Filesystem\Filesystem;
2022
use Symfony\Component\HttpFoundation\File\UploadedFile;
2123

2224
/**
@@ -121,8 +123,8 @@ public function fetch(Request $request)
121123
}
122124

123125
$response = [
124-
'state'=> count($list) ? 'SUCCESS':'ERROR',
125-
'list'=> $list
126+
'state' => count($list) ? 'SUCCESS' : 'ERROR',
127+
'list' => $list
126128
];
127129

128130
return response()->json($response);
@@ -267,8 +269,10 @@ protected function fileHasError(UploadedFile $file, array $config)
267269
$error = $file->getError();
268270
} elseif ($file->getSize() > $config['max_size']) {
269271
$error = 'upload.ERROR_SIZE_EXCEED';
270-
} elseif (!empty($config['allow_files']) &&
271-
!in_array('.'.$file->getClientOriginalExtension(), $config['allow_files'])) {
272+
} elseif (
273+
!empty($config['allow_files']) &&
274+
!in_array('.' . $file->getClientOriginalExtension(), $config['allow_files'])
275+
) {
272276
$error = 'upload.ERROR_TYPE_NOT_ALLOWED';
273277
}
274278

@@ -285,9 +289,9 @@ protected function fileHasError(UploadedFile $file, array $config)
285289
*/
286290
protected function getFilename(UploadedFile $file, array $config)
287291
{
288-
$ext = '.'.$file->getClientOriginalExtension();
292+
$ext = '.' . $file->getClientOriginalExtension();
289293

290-
$filename = config('ueditor.hash_filename') ? md5($file->getFilename()).$ext : $file->getClientOriginalName();
294+
$filename = config('ueditor.hash_filename') ? md5($file->getFilename()) . $ext : $file->getClientOriginalName();
291295

292296
return $this->formatPath($config['path_format'], $filename);
293297
}
@@ -311,13 +315,13 @@ protected function getUploadConfig($action)
311315
$config = [];
312316

313317
foreach ($prefixes as $prefix) {
314-
if ($action == $upload[$prefix.'ActionName']) {
318+
if ($action == $upload[$prefix . 'ActionName']) {
315319
$config = [
316-
'action' => array_get($upload, $prefix.'ActionName'),
317-
'field_name' => array_get($upload, $prefix.'FieldName'),
318-
'max_size' => array_get($upload, $prefix.'MaxSize'),
319-
'allow_files' => array_get($upload, $prefix.'AllowFiles', []),
320-
'path_format' => array_get($upload, $prefix.'PathFormat'),
320+
'action' => Arr::get($upload, $prefix . 'ActionName'),
321+
'field_name' => Arr::get($upload, $prefix . 'FieldName'),
322+
'max_size' => Arr::get($upload, $prefix . 'MaxSize'),
323+
'allow_files' => Arr::get($upload, $prefix . 'AllowFiles', []),
324+
'path_format' => Arr::get($upload, $prefix . 'PathFormat'),
321325
];
322326

323327
break;
@@ -359,8 +363,8 @@ protected function formatPath($path, $filename)
359363
$path = preg_replace('/\{rand\:[\d]*\}/i', str_pad(mt_rand(0, pow(10, $length) - 1), $length, '0', STR_PAD_LEFT), $path);
360364
}
361365

362-
if (!str_contains($path, $filename)) {
363-
$path = str_finish($path, '/').$filename;
366+
if (!Str::contains($path, $filename)) {
367+
$path = Str::finish($path, '/') . $filename;
364368
}
365369

366370
return $path;

src/UEditorController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor;
12+
namespace Codingyu\LaravelUEditor;
1313

1414
use Illuminate\Http\Request;
1515
use Illuminate\Routing\Controller;
@@ -28,19 +28,21 @@ public function serve(Request $request)
2828
case 'config':
2929
return config('ueditor.upload');
3030

31-
// lists
31+
// lists
3232
case $upload['imageManagerActionName']:
3333
return $storage->listFiles(
3434
$upload['imageManagerListPath'],
3535
$request->get('start'),
3636
$request->get('size'),
37-
$upload['imageManagerAllowFiles']);
37+
$upload['imageManagerAllowFiles']
38+
);
3839
case $upload['fileManagerActionName']:
3940
return $storage->listFiles(
4041
$upload['fileManagerListPath'],
4142
$request->get('start'),
4243
$request->get('size'),
43-
$upload['fileManagerAllowFiles']);
44+
$upload['fileManagerAllowFiles']
45+
);
4446
case $upload['catcherActionName']:
4547
return $storage->fetch($request);
4648
default:

src/UEditorServiceProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor;
12+
namespace Codingyu\LaravelUEditor;
1313

1414
use Illuminate\Routing\Router;
1515
use Illuminate\Support\Facades\Storage;
@@ -27,20 +27,20 @@ class UEditorServiceProvider extends ServiceProvider
2727
*/
2828
public function boot(Router $router)
2929
{
30-
$this->loadViewsFrom(__DIR__.'/views', 'ueditor');
31-
$this->loadTranslationsFrom(__DIR__.'/translations', 'ueditor');
30+
$this->loadViewsFrom(__DIR__ . '/views', 'ueditor');
31+
$this->loadTranslationsFrom(__DIR__ . '/translations', 'ueditor');
3232

3333
$this->publishes([
34-
__DIR__.'/config/ueditor.php' => config_path('ueditor.php'),
34+
__DIR__ . '/config/ueditor.php' => config_path('ueditor.php'),
3535
], 'config');
3636

3737
$this->publishes([
38-
__DIR__.'/assets/ueditor' => public_path('vendor/ueditor'),
38+
__DIR__ . '/assets/ueditor' => public_path('vendor/ueditor'),
3939
], 'assets');
4040

4141
$this->publishes([
42-
__DIR__.'/views' => base_path('resources/views/vendor/ueditor'),
43-
__DIR__.'/translations' => base_path('resources/lang/vendor/ueditor'),
42+
__DIR__ . '/views' => base_path('resources/views/vendor/ueditor'),
43+
__DIR__ . '/translations' => base_path('resources/lang/vendor/ueditor'),
4444
], 'resources');
4545

4646
$this->registerRoute($router);
@@ -51,7 +51,7 @@ public function boot(Router $router)
5151
*/
5252
public function register()
5353
{
54-
$this->mergeConfigFrom(__DIR__.'/config/ueditor.php', 'ueditor');
54+
$this->mergeConfigFrom(__DIR__ . '/config/ueditor.php', 'ueditor');
5555
$this->app->singleton('ueditor.storage', function ($app) {
5656
return new StorageManager(Storage::disk($app['config']->get('ueditor.disk', 'public')));
5757
});

src/UrlResolverTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Overtrue\LaravelUEditor;
12+
namespace Codingyu\LaravelUEditor;
1313

1414
use Illuminate\Support\Str;
1515
use League\Flysystem\Adapter\Local as LocalAdapter;
@@ -68,7 +68,8 @@ public function url($path)
6868
protected function getAwsUrl($adapter, $path)
6969
{
7070
return $adapter->getClient()->getObjectUrl(
71-
$adapter->getBucket(), $adapter->getPathPrefix().$path
71+
$adapter->getBucket(),
72+
$adapter->getPathPrefix() . $path
7273
);
7374
}
7475

@@ -87,10 +88,10 @@ protected function getLocalUrl($path)
8788
// it as the base URL instead of the default path. This allows the developer to
8889
// have full control over the base path for this filesystem's generated URLs.
8990
if ($config->has('url')) {
90-
return rtrim($config->get('url'), '/').'/'.ltrim($path, '/');
91+
return rtrim($config->get('url'), '/') . '/' . ltrim($path, '/');
9192
}
9293

93-
$path = '/storage/'.ltrim($path, '/');
94+
$path = '/storage/' . ltrim($path, '/');
9495

9596
// If the path contains "storage/public", it probably means the developer is using
9697
// the default disk to generate the path instead of the "public" disk like they

0 commit comments

Comments
 (0)