mouadbnl / laravel-judge0
支持Judge0 API以在不同语言中运行/判断代码
0.4.2
2021-09-17 13:19 UTC
Requires
- php: ^8.0|^7.4
- guzzlehttp/guzzle: ^7
- illuminate/auth: ^6.0|^7.0|^8.0
- illuminate/contracts: ^6.0|^7.0|^8.0
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.15
- phpunit/phpunit: ^9.3
README
为不同语言的 运行/判断
代码提供Judge0 API集成
use Mouadbnl\Judge0\Models\Submission; $submission = Submission::create([ 'language_id' => 54, // C++ (GCC 9.2.0) 'source_code' =>' #include<iostream> #include<string> using namespace std; int main(){ string s; cin >> s; cout << "the value you entered is : " << s; return 0; } ' ]) ->setInput('judge0') ->setExpectedOutput('the value you entered is : judge0') ->setTimeLimit(1) // seconds ->setMemoryLimitInMegabytes(256) ->submit();
安装
您可以通过composer安装此包
composer require mouadbnl/laravel-judge0
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --provider="Mouadbnl\Judge0\Judge0ServiceProvider" --tag="judge0-migrations" php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Mouadbnl\Judge0\Judge0ServiceProvider" --tag="judge0-config"
用法
首先将 Submitter
特性添加到用户模型中。
use Mouadbnl\Judge0\Traits\Submitter; class User extends Authenticatable { use Submitter; /** **/ }
这将在用户模型和由该包提供的提交模型之间创建一个多态关系。您可以使用以下代码让用户提交
$user = User::firstOrFail(); $user->submissions()->create([ 'language_id' => 54, // C++ (GCC 9.2.0) 'source_code' =>' #include<iostream> #include<string> using namespace std; int main(){ string s; cin >> s; cout << "the value you entered is : " << s; return 0; } ' ]) ->setInput('judge0') ->setExpectedOutput('the value you entered is : judge0') ->setTimeLimit(1) // seconds ->setMemoryLimitInMegabytes(256) ->submit();
定义要使用的API
此包提供两个驱动程序来连接到judge0 API
实例驱动程序
这允许您连接到judge0 Docker实例。为此,请定义 JUDGE0_BASE_URI
,这是您实例的URL,以及 JUDGE0_KEY
,这是用于在 环境变量
或 .env
文件中认证的API密钥。
JUDGE0_BASE_URI=localhost:2358 JUDGE0_KEY=yout_key
Rapidapi驱动程序
这允许您连接到RapidAPI上的Judge0应用程序。为此,您需要在 环境变量
或 .env
文件中定义以下内容。
JUDGE0_RAPIDAPI_BASE_URI
,这是请求的RapidAPI URL,默认为https://judge0-ce.p.rapidapi.com
。JUDGE0_RAPIDAPI_HOST
,默认为judge0-ce.p.rapidapi.com
。JUDGE0_RAPIDAPI_KEY
,您的RapidAPI密钥。
JUDGE0_RAPIDAPI_BASE_URI=https://judge0-ce.p.rapidapi.com JUDGE0_RAPIDAPI_HOST=judge0-ce.p.rapidapi.com JUDGE0_RAPIDAPI_KEY=yout_key
测试
composer test
致谢
- Mouad Benali
- Spatie 提供骨架和 包培训
- 所有贡献者
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。