suzunone / code-runner
来自 piza.io 的 code-runner。(piza.io API 非官方包装器。)
v1.0.1
2022-02-03 00:28 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.4
Requires (Dev)
- fakerphp/faker: ^1.9.1
- mockery/mockery: ^1.4.4
- phpunit/phpunit: ^9.5.10
This package is not auto-updated.
Last update: 2024-09-26 12:56:12 UTC
README
简介
paiza.io API 非官方包装器。使用 Paiza API,在多种编程语言中编译和执行任意代码。
使用说明
此包使用 paiza.io API。因此,请阅读 使用条款(仅限日语)。
安装说明
Composer
composer require suzunone/code-runner
示例
示例1
源代码
<?php use Suzunone\CodeRunner\CodeRunner; $source_code = 'console.log("Hello, world...");'; $CodeRunner = new CodeRunner; $entity = $CodeRunner->create($source_code, CodeRunner::LANG_JAVASCRIPT); while ($entity->is_running) { $entity = $entity->status(); sleep(1); } var_dump($entity->details()->toArray());
结果
array(17) {
["id"]=>
string(22) ""
["language"]=>
string(10) "javascript"
["note"]=>
NULL
["status"]=>
string(9) "completed"
["build_stdout"]=>
NULL
["build_stderr"]=>
NULL
["build_exit_code"]=>
int(0)
["build_time"]=>
NULL
["build_memory"]=>
NULL
["build_result"]=>
NULL
["stdout"]=>
string(16) "Hello, world...
"
["stderr"]=>
string(0) ""
["exit_code"]=>
int(0)
["time"]=>
string(4) "0.07"
["memory"]=>
int(32408000)
["connections"]=>
int(0)
["result"]=>
string(7) "success"
API 参考
Suzunone\CodeRunner\CodeRunner
常量。
CodeRunner::LANG_C (字符串)
C 语言常量
CodeRunner::LANG_CPP (字符串)
C++ 语言常量
CodeRunner::LANG_OBJECTIVE_C (字符串)
Objective-C 语言常量
CodeRunner::LANG_JAVA (字符串)
Java 语言常量
CodeRunner::LANG_KOTLIN (字符串)
Kotlin 语言常量
CodeRunner::LANG_SCALA (字符串)
Scala 语言常量
CodeRunner::LANG_SWIFT (字符串)
Swift 语言常量
CodeRunner::LANG_CSHARP (字符串)
C# 语言常量
CodeRunner::LANG_GO (字符串)
GO 语言常量
CodeRunner::LANG_HASKELL (字符串)
Haskell 语言常量
CodeRunner::LANG_ERLANG (字符串)
Erlang 语言常量
CodeRunner::LANG_PERL (字符串)
Perl 语言常量
CodeRunner::LANG_PYTHON (字符串)
Python2 语言常量 (字符串)
CodeRunner::LANG_PYTHON3 (字符串)
Python3 语言常量
CodeRunner::LANG_RUBY (字符串)
Ruby 语言常量
CodeRunner::LANG_PHP (字符串)
PHP 语言常量
CodeRunner::LANG_BASH (字符串)
Bash 语言常量
CodeRunner::LANG_R (字符串)
R 语言常量
CodeRunner::LANG_JAVASCRIPT (字符串)
JavaScript 语言常量
CodeRunner::LANG_COFFEESCRIPT (字符串)
CoffeeScript 语言常量
CodeRunner::LANG_VB (字符串)
VB 语言常量
CodeRunner::LANG_COBOL (字符串)
Cobol 语言常量
CodeRunner::LANG_FSHARP (字符串)
F# 语言常量
CodeRunner::LANG_D (字符串)
D 语言常量
CodeRunner::LANG_CLOJURE (字符串)
Clojure 语言常量
CodeRunner::LANG_ELIXIR (字符串)
Elixir 语言常量
CodeRunner::LANG_MYSQL (字符串)
MySQL 语言常量
CodeRunner::LANG_RUST (字符串)
Rust 语言常量
CodeRunner::LANG_SCHEME (字符串)
Scheme 语言常量
CodeRunner::LANG_COMMON_LISP (字符串)
Common Lisp 语言常量
CodeRunner::LANG_NADESIKO (字符串)
なでしこ 语言常量
CodeRunner::LANG_TYPESCRIPT (字符串)
TypeScript 语言常量
CodeRunner::LANG_PLAIN (字符串)
PlainText 语言常量
CodeRunner::LANGS (数组)
CodeRunner::EXTENSIONS (数组)
CodeRunner::STATUS_RUNNING (字符串)
表示状态已正在运行。
CodeRunner::STATUS_COMPLETED (字符串)
表示状态已完成。
CodeRunner::create()
开始编译和执行程序代码。
CodeRunner::create(string $source_code, string $language, string $input = '', bool $longpoll = false, int $longpoll_timeout = 10): Suzunone\CodeRunner\Entities\OutputEntityInterface
参数
返回
\Suzunone\CodeRunner\Entities\OutputEntityInterface
CodeRunner::getTemplate()
根据语言常量返回程序代码的模板。
CodeRunner::getTemplate(string $language): string
参数
返回
string
CodeRunner::getLanguageName()
根据语言常量获取程序名称。
CodeRunner::getLanguageName(string $language): string
参数
返回
string
CodeRunner::getLangExtension()
根据语言常量获取程序文件扩展名。
CodeRunner::getLangExtension(string $language): string
参数
返回
string
CodeRunner::getApiKey()
获取API密钥。
CodeRunner::getApiKey(): string
参数
返回
string
CodeRunner::setApiKey()
设置API密钥。
CodeRunner::setApiKey(string $api_key): void
参数
返回
string
\Suzunone\CodeRunner\Entities\OutputEntityInterface
获取程序的编译和执行状态。
OutputEntityInterface::status()
OutputEntityInterface::status(): StatusEntity;
参数
返回
Suzunone\CodeRunner\Entities\Input|StatusEntity
OutputEntityInterface::details()
获取编译和执行程序的结果。
OutputEntityInterface::details(): StatusEntity;
参数
返回
Suzunone\CodeRunner\Entities\Input|StatusEntity
OutputEntityInterface::getResponse()
获取响应数据。
getResponse() : ResponseElementInterface
参数
返回
Suzunone\CodeRunner\Entities\Elements\Input|ResponseElementInterface