Skip to content

Commit ca89dac

Browse files
committed
first commit
0 parents  commit ca89dac

File tree

7 files changed

+219
-0
lines changed

7 files changed

+219
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
phpunit.phar
3+
/vendor
4+
composer.phar
5+
composer.lock
6+
*.project
7+
.idea/

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jens Segers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
PHP editor extension for laravel-admin based on code-mirror
2+
======
3+
4+
## Installation
5+
6+
```bash
7+
composer require laravel-admin-ext/php-editor
8+
9+
php artisan vendor:publish --tag=laravel-admin-code-mirror
10+
```
11+
12+
## 配置
13+
14+
`config/admin.php`文件的`extensions`,加上属于这个扩展的一些配置
15+
```php
16+
17+
'extensions' => [
18+
19+
'php-editor' => [
20+
21+
// 如果要关掉这个扩展,设置为false
22+
'enable' => true,
23+
24+
// 编辑器的配置
25+
'config' => [
26+
27+
]
28+
]
29+
]
30+
31+
```
32+
33+
更多配置可以到[CodeMirror文档](https://codemirror.net/)找到
34+
35+
## 使用
36+
37+
在form表单中使用它:
38+
```php
39+
$form->php('code');
40+
```
41+
42+
设置高度
43+
```php
44+
$form->php('code')->height(500);
45+
```
46+
47+
## 支持
48+
49+
如果觉得这个项目帮你节约了时间,不妨支持一下;)
50+
51+
![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg)
52+
53+
License
54+
------------
55+
Licensed under [The MIT License (MIT)](LICENSE).

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "laravel-admin-ext/php-editor",
3+
"description": "PHP editor extension for laravel-admin based on code-mirror",
4+
"type": "library",
5+
"keywords": ["laravel-admin", "extension", "code mirror", "php", "editor"],
6+
"homepage": "https://github.com/laravel-admin-ext/php-editor",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "song",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=7.0.0",
16+
"jxlwqq/code-mirror": "*"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "~6.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Encore\\PHPEditor\\": "src/"
24+
}
25+
},
26+
"extra": {
27+
"laravel": {
28+
"providers": [
29+
"Encore\\PHPEditor\\PHPEditorServiceProvider"
30+
]
31+
}
32+
}
33+
}

src/Editor.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Encore\PHPEditor;
4+
5+
use Encore\Admin\Form\Field;
6+
7+
class Editor extends Field
8+
{
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
protected $view = 'laravel-admin-code-mirror::editor';
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected static $css = [
18+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.css',
19+
];
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected static $js = [
25+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.js',
26+
// x-httpd-php mode
27+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/htmlmixed/htmlmixed.js',
28+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/xml/xml.js',
29+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/javascript/javascript.js',
30+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/css/css.js',
31+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/clike/clike.js',
32+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/php/php.js',
33+
];
34+
35+
/**
36+
* Set editor height.
37+
*
38+
* @param int $height
39+
* @return $this
40+
*/
41+
public function height($height = 10)
42+
{
43+
return $this->addVariables(compact('height'));
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function render()
50+
{
51+
$options = array_merge(
52+
[
53+
'mode' => 'application/x-httpd-php',
54+
'lineNumbers' => true,
55+
'matchBrackets' => true,
56+
'indentUnit' => 4,
57+
'indentWithTabs' => true,
58+
],
59+
PHPEditor::config('config', [])
60+
);
61+
62+
$options = json_encode($options);
63+
64+
$this->script = <<<EOT
65+
CodeMirror.fromTextArea(document.getElementById("{$this->id}"), $options);
66+
EOT;
67+
68+
return parent::render();
69+
}
70+
}

src/PHPEditor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Encore\PHPEditor;
4+
5+
use Encore\Admin\Extension;
6+
7+
class PHPEditor extends Extension
8+
{
9+
public $name = 'php-editor';
10+
}

src/PHPEditorServiceProvider.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Encore\PHPEditor;
4+
5+
use Encore\Admin\Admin;
6+
use Encore\Admin\Form;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class PHPEditorServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function boot(PHPEditor $extension)
15+
{
16+
if (! PHPEditor::boot()) {
17+
return ;
18+
}
19+
20+
Admin::booting(function () {
21+
Form::extend('php', Editor::class);
22+
});
23+
}
24+
}

0 commit comments

Comments
 (0)