meebio/php-eval-console 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

meebio/php-eval-console

Composer 安装命令:

composer require meebio/php-eval-console

包简介

Standalone php eval console. In-browser, standalone console that executes your PHP code and returns the produced output.

README 文档

README

In-browser, standalone console that executes your PHP code and returns the produced output. This package is based on package darsain/laravel-console.

Screenshot

Table of contents

Installation

Get package through composer:

composer require meebio/php-eval-console

Copy vendor/meebio/php-eval-console/assets to assets in project root directory.

Create index.php in project root directory with following content:

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Meebio\PhpEvalConsole\Console;

$console = new Console();
$console->boot();

Open index.php page in browser.

Configuration

Key Type Description Default
assets_dir string Relative path to assets directory. 'assets'
views_path string Absolute path to views directory. Modify only if you want to use custom views. '<...>/Views'
console_view_path string Absolute path to main view. Modify only if you want to use custom views. '<...>/Views/console.php'
execute_url string|null URL to application execute route. If null set it is guessed. null
evaluator EvaluatorInterface Instance of EvaluatorInterface implementation that will be used for running code. EvalEvaluator
authorizer null|AuthorizerInterface Instance of AuthorizerInterface implementation that will be used for running code. This option also accepts null or array of authorizers. IpAuthorizer
queries_callback null|closure Callback that will return database queries to display after running code. null
post_execute_callback null|closure Post execute callback. Can be used to perform some actions after code evaluation, but before returning result. null

Evaluators

EvalEvaluator

Basic evaluator that uses eval command. This is entirely not secure.

PhpSandboxEvaluator

More advanced php evaluator that make use of fieryprophet/php-sandbox package. This sandbox class utilizes PHP-Parser to prevent sandboxed code from running unsafe code. If configured properly this evaluator could probably allow application to be exposed to public users. To use this evaluator require fieryprophet/php-sandbox package in composer.

Authorizers

IpAuthorizer

This authorizer ensures that only access from provided ips is possible. Authorizer constructor takes to arguments first is array of allowed ips (null if this check should be disabled) and second is array of disallowed ips (null if this check should be disabled).

Queries callback

Closure that will provide array of queries after code evaluation. Returned data should be in following format:

array(
    array(
        'query' => 'SELECT * FROM `users`;',
        'time'  => 0.113,
    ),
    array(
        'query' => 'SELECT * FROM `posts` JOIN `category` ON `post`.`category_id` = `category`.`id`;',
        'time'  => 0.231,
    ),
);

Laravel support

You should install the package through Composer:

composer require meebio/php-eval-console

You must add service provider to app config:

'providers' => [
    ...
    Meebio\PhpEvalConsole\Providers\PhpEvalConsoleLaravelServiceProvider::class,
    ...
];

You can publish package assets through artisan command:

php artisan vendor:publish --provider="Meebio\PhpEvalConsole\Providers\PhpEvalConsoleLaravelServiceProvider"

or just copy directory vendor/meebio/php-eval-console/assets to public/vendor/php-eval-console.

Last thing that should be done is to make sure CSRF Protection is not blocking console post requests. To do that in Laravel 5.1 you should add console URI to be excluded in VerifyCsrfToken class. So it looks something like this:

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'console',
    ];
}

For lower versions of Laravel, that can be done as well, but some manual method overriding is needed.

When everything is done you should see Console at /console uri.

TODO

  • Improve errors handling.

meebio/php-eval-console 适用场景与选型建议

meebio/php-eval-console 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 15.99k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「debug」 「debugging」 「console」 「sandbox」 「eval」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 meebio/php-eval-console 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 meebio/php-eval-console 我们能提供哪些服务?
定制开发 / 二次开发

基于 meebio/php-eval-console 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 15.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 30
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-05