Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Oct 27, 2022
1 parent 934e549 commit f05deb3
Show file tree
Hide file tree
Showing 41 changed files with 1,015 additions and 226 deletions.
6 changes: 5 additions & 1 deletion .lintmdrc
@@ -1,5 +1,9 @@
{
"excludeFiles": [
"art/",
"config/",
"resources/",
"routes/",
"src/",
"tests/",
"vendor/"
Expand All @@ -9,7 +13,7 @@
"no-long-code": [
2,
{
"length": 100,
"length": 150,
"exclude": [
"dot"
]
Expand Down
12 changes: 8 additions & 4 deletions .php-cs-fixer.php
Expand Up @@ -3,22 +3,26 @@
declare(strict_types=1);

/**
* This file is part of the guanguans/laravel-web-tinker.
* This file is part of the guanguans/laravel-code-runner.
*
* (c) guanguans <ityaozm@gmail.com>
*
* This source file is subject to the MIT license that is bundled.
*/

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$header = <<<EOF
This file is part of the guanguans/laravel-web-tinker.
This file is part of the guanguans/laravel-code-runner.
(c) guanguans <ityaozm@gmail.com>
This source file is subject to the MIT license that is bundled.
EOF;

$finder = PhpCsFixer\Finder::create()
/** @noinspection PhpParamsInspection */
$finder = Finder::create()
->in([
__DIR__.'/config',
__DIR__.'/routes',
Expand Down Expand Up @@ -46,7 +50,7 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
return (new Config())
->setRules([
'@DoctrineAnnotation' => true,
'@PHP80Migration:risky' => true,
Expand Down
5 changes: 1 addition & 4 deletions CHANGELOG.md
@@ -1,7 +1,4 @@
# Changelog

All notable changes to `guanguans/laravel-web-tinker` will be documented in this file.
All notable changes to `guanguans/laravel-code-runner` will be documented in this file.

## 1.0.0 - 202X-XX-XX

- Initial release.
73 changes: 57 additions & 16 deletions README-zh_CN.md
@@ -1,34 +1,75 @@
# package-skeleton
# laravel-code-runner

[简体中文](README-zh_CN.md) | [ENGLISH](README.md)
[ENGLISH](README.md) | [简体中文](README-zh_CN.md)

> 一个 PHP 软件包模板存储库。- A PHP package template repository.
> Run the code in the browser. - 在浏览器中运行代码。
[![tests](https://github.com/guanguans/laravel-web-tinker/workflows/tests/badge.svg)](https://github.com/guanguans/laravel-web-tinker/actions)
[![check & fix styling](https://github.com/guanguans/laravel-web-tinker/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/laravel-web-tinker/actions)
[![codecov](https://codecov.io/gh/guanguans/laravel-web-tinker/branch/main/graph/badge.svg?token=URGFAWS6S4)](https://codecov.io/gh/guanguans/laravel-web-tinker)
[![Latest Stable Version](https://poser.pugx.org/guanguans/laravel-web-tinker/v)](//packagist.org/packages/guanguans/laravel-web-tinker)
[![Total Downloads](https://poser.pugx.org/guanguans/laravel-web-tinker/downloads)](//packagist.org/packages/guanguans/laravel-web-tinker)
[![License](https://poser.pugx.org/guanguans/laravel-web-tinker/license)](//packagist.org/packages/guanguans/laravel-web-tinker)
![GitHub repo size](https://img.shields.io/github/repo-size/guanguans/laravel-web-tinker)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/guanguans/laravel-web-tinker)

## 功能

* 功能
[![tests](https://github.com/guanguans/laravel-code-runner/workflows/tests/badge.svg)](https://github.com/guanguans/laravel-code-runner/actions)
[![check & fix styling](https://github.com/guanguans/laravel-code-runner/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/laravel-code-runner/actions)
[![codecov](https://codecov.io/gh/guanguans/laravel-code-runner/branch/main/graph/badge.svg?token=URGFAWS6S4)](https://codecov.io/gh/guanguans/laravel-code-runner)
[![Latest Stable Version](https://poser.pugx.org/guanguans/laravel-code-runner/v)](//packagist.org/packages/guanguans/laravel-code-runner)
[![Total Downloads](https://poser.pugx.org/guanguans/laravel-code-runner/downloads)](//packagist.org/packages/guanguans/laravel-code-runner)
[![License](https://poser.pugx.org/guanguans/laravel-code-runner/license)](//packagist.org/packages/guanguans/laravel-code-runner)
![GitHub repo size](https://img.shields.io/github/repo-size/guanguans/laravel-code-runner)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/guanguans/laravel-code-runner)

## 环境要求

* PHP >= 7.4
* Laravel >= 7.0

## 安装

通过 Composer 安装该软件包。

```bash
$ composer require guanguans/laravel-code-runner --prefer-dist -vvv
```

运行此命令来发布资源文件。

```bash
$ php artisan code-runner:install
```

发布配置文件(可选的)。

```bash
$ composer require guanguans/laravel-web-tinker --prefer-dist -vvv
$ php artisan vendor:publish --provider="Guanguans\LaravelCodeRunner\WebTinkerServiceProvider" --tag="code-runner-config"
```

## 使用

默认情况下,此包仅在本地环境中运行。

访问 `/code-runner` 查看页面。

![](docs/usage.png)

### Authorization

如果您想在另一个环境中运行它(我们不建议这样做),您必须执行两个步骤。

1. 您必须将 `code-runner` 配置文件中的 `enabled` 值设置为 `true`

2. 您必须注册一个 `view-code-runner``ability`。最好在 Laravel 附带的 `AuthServiceProvider` 中。

```php
use Illuminate\Contracts\Auth\Authenticatable;

public function boot()
{
$this->registerPolicies();

Gate::define('view-code-runner', function (?Authenticatable $user = null) {
// 如果允许访问 web tinker,则返回 true。这是一个例子:
return $user && in_array($user->email, [
'admin@example.com',
]);
});
}
```

## 测试

```bash
Expand Down
73 changes: 57 additions & 16 deletions README.md
@@ -1,34 +1,75 @@
# laravel-web-tinker
# laravel-code-runner

[简体中文](README-zh_CN.md) | [ENGLISH](README.md)
[ENGLISH](README.md) | [简体中文](README-zh_CN.md)

> A PHP package template repository. - 一个 PHP 软件包模板存储库
> Run the code in the browser. - 在浏览器中运行代码
[![tests](https://github.com/guanguans/laravel-web-tinker/workflows/tests/badge.svg)](https://github.com/guanguans/laravel-web-tinker/actions)
[![check & fix styling](https://github.com/guanguans/laravel-web-tinker/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/laravel-web-tinker/actions)
[![codecov](https://codecov.io/gh/guanguans/laravel-web-tinker/branch/main/graph/badge.svg?token=URGFAWS6S4)](https://codecov.io/gh/guanguans/laravel-web-tinker)
[![Latest Stable Version](https://poser.pugx.org/guanguans/laravel-web-tinker/v)](//packagist.org/packages/guanguans/laravel-web-tinker)
[![Total Downloads](https://poser.pugx.org/guanguans/laravel-web-tinker/downloads)](//packagist.org/packages/guanguans/laravel-web-tinker)
[![License](https://poser.pugx.org/guanguans/laravel-web-tinker/license)](//packagist.org/packages/guanguans/laravel-web-tinker)
![GitHub repo size](https://img.shields.io/github/repo-size/guanguans/laravel-web-tinker)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/guanguans/laravel-web-tinker)

## Features

* Feature
[![tests](https://github.com/guanguans/laravel-code-runner/workflows/tests/badge.svg)](https://github.com/guanguans/laravel-code-runner/actions)
[![check & fix styling](https://github.com/guanguans/laravel-code-runner/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/laravel-code-runner/actions)
[![codecov](https://codecov.io/gh/guanguans/laravel-code-runner/branch/main/graph/badge.svg?token=URGFAWS6S4)](https://codecov.io/gh/guanguans/laravel-code-runner)
[![Latest Stable Version](https://poser.pugx.org/guanguans/laravel-code-runner/v)](//packagist.org/packages/guanguans/laravel-code-runner)
[![Total Downloads](https://poser.pugx.org/guanguans/laravel-code-runner/downloads)](//packagist.org/packages/guanguans/laravel-code-runner)
[![License](https://poser.pugx.org/guanguans/laravel-code-runner/license)](//packagist.org/packages/guanguans/laravel-code-runner)
![GitHub repo size](https://img.shields.io/github/repo-size/guanguans/laravel-code-runner)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/guanguans/laravel-code-runner)

## Requirement

* PHP >= 7.4
* Laravel >= 7.0

## Installation

You can install the package via composer.

```bash
$ composer require guanguans/laravel-code-runner --prefer-dist -vvv
```

Next, you must publish the assets from this package by running this command.

```bash
$ php artisan code-runner:install
```

Optionally, you can publish the config file of the package.

```bash
$ composer require guanguans/laravel-web-tinker --prefer-dist -vvv
$ php artisan vendor:publish --provider="Guanguans\LaravelCodeRunner\WebTinkerServiceProvider" --tag="code-runner-config"
```

## Usage

![](docs/usage.png)

By default this package will only run in a local environment.

Visit `/code-runner` in your app to view page.

### Authorization

Should you want to run this in another environment (we do not recommend this), there are two steps you must perform.

1. You must set the `enabled` variable in the `code-runner` config file to `true`.

2. You must register a `view-code-runner` ability. A good place to do this is in the `AuthServiceProvider` that ships with Laravel.

```php
use Illuminate\Contracts\Auth\Authenticatable;

public function boot()
{
$this->registerPolicies();

Gate::define('view-code-runner', function (?Authenticatable $user = null) {
// Return true if access to web tinker is allowed. Here's an example:
return $user && in_array($user->email, [
'admin@example.com',
]);
});
}
```

## Testing

```bash
Expand Down
5 changes: 4 additions & 1 deletion _ide_helper.php
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the guanguans/laravel-web-tinker.
* This file is part of the guanguans/laravel-code-runner.
*
* (c) guanguans <ityaozm@gmail.com>
*
Expand All @@ -10,4 +10,7 @@

namespace {

class CodeRunner extends \Guanguans\LaravelCodeRunner\Facades\CodeRunner
{
}
}
42 changes: 26 additions & 16 deletions composer.json
@@ -1,14 +1,19 @@
{
"name": "guanguans/laravel-web-tinker",
"description": "Artisan Tinker in your browser",
"name": "guanguans/laravel-code-runner",
"description": "Run the code in the browser. - 在浏览器中运行代码。",
"license": "MIT",
"type": "library",
"abandoned": false,
"non-feature-branches": [],
"keywords": [
"web-tinker",
"laravel",
"code-runner",
"code",
"runner",
"web",
"tinker",
"artisan",
"browser",
"debug",
"development"
],
Expand All @@ -21,10 +26,10 @@
"role": "developer"
}
],
"homepage": "https://github.com/guanguans/laravel-web-tinker",
"homepage": "https://github.com/guanguans/laravel-code-runner",
"support": {
"issues": "https://github.com/guanguans/laravel-web-tinker/issues",
"source": "https://github.com/guanguans/laravel-web-tinker"
"issues": "https://github.com/guanguans/laravel-code-runner/issues",
"source": "https://github.com/guanguans/laravel-code-runner"
},
"funding": [
{
Expand Down Expand Up @@ -75,7 +80,7 @@
"autoload": {
"psr-0": {},
"psr-4": {
"Guanguans\\LaravelWebTinker\\": "src"
"Guanguans\\LaravelCodeRunner\\": "src"
},
"classmap": [],
"files": [],
Expand All @@ -85,14 +90,15 @@
},
"autoload-dev": {
"psr-4": {
"Guanguans\\LaravelWebTinkerTests\\": "tests"
"Guanguans\\LaravelCodeRunnerTests\\": "tests"
}
},
"bin": [],
"archive": {},
"config": {
"allow-plugins": {
"infection/extension-installer": true,
"kylekatarnls/update-helper": false,
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
},
Expand All @@ -114,15 +120,18 @@
"composer checks"
]
},
"laravel": {
"aliases": {
"CodeRunner": "Guanguans\\LaravelCodeRunner\\Facades\\CodeRunner"
},
"providers": [
"Guanguans\\LaravelCodeRunner\\CodeRunnerServiceProvider"
]
},
"phpstan": {
"includes": [
"extension.neon"
]
},
"laravel": {
"providers": [
"Guanguans\\LaravelWebTinker\\WebTinkerServiceProvider"
]
}
},
"scripts": {
Expand All @@ -133,14 +142,15 @@
"post-update-cmd": [
"@cghooks update"
],
"post-autoload-dump": [
],
"post-autoload-dump": [],
"cghooks": "./vendor/bin/cghooks",
"checks": [
"@mark-start",
"@style-lint",
"@mark-separate",
"@test",
"@mark-separate",
"@psalm",
"@mark-finish"
],
"infection": "./vendor/bin/infection --test-framework=pest --show-mutations --threads=4 --ansi",
Expand All @@ -161,7 +171,7 @@
"rector": "./vendor/bin/rector --clear-cache --ansi -v",
"rector-dry-run": "@rector --dry-run",
"style-fix": "./vendor/bin/php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.php --ansi",
"style-lint": "@style-fix --diff --dry-run",
"style-lint": "@style-fix --dry-run --diff",
"test": "@pest",
"test-coverage": "@pest-coverage"
},
Expand Down

0 comments on commit f05deb3

Please sign in to comment.