suzunone/code-runner

code-runner from piza.io.(piza.io API unofficial wrapper.)

v1.0.1 2022-02-03 00:28 UTC

This package is not auto-updated.

Last update: 2024-11-21 13:36:30 UTC


README

example workflow

Introduction

paiza.io API unofficial wrapper. Using the Paiza API, compile and execute arbitrary code in a variety of programming languages.

Notice for using

This package use paiza.io API. So please read term of use (Japanese only).

Installation Instructions

Composer

composer require suzunone/code-runner

Example

Example1

Source code

<?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());

Results

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 Reference

Suzunone\CodeRunner\CodeRunner

constants.

CodeRunner::LANG_C (string)

C Language constant

CodeRunner::LANG_CPP (string)

C++ Language constant

CodeRunner::LANG_OBJECTIVE_C (string)

Objective-C Language constant

CodeRunner::LANG_JAVA (string)

Java Language constant

CodeRunner::LANG_KOTLIN (string)

Kotlin Language constant

CodeRunner::LANG_SCALA (string)

Scala Language constant

CodeRunner::LANG_SWIFT (string)

Swift Language constant

CodeRunner::LANG_CSHARP (string)

C# Language constant

CodeRunner::LANG_GO (string)

GO Language constant

CodeRunner::LANG_HASKELL (string)

Haskell Language constant

CodeRunner::LANG_ERLANG (string)

Erlang Language constant

CodeRunner::LANG_PERL (string)

Perl Language constant

CodeRunner::LANG_PYTHON (string)

Python2 Language constant (string)

CodeRunner::LANG_PYTHON3 (string)

Python3 Language constant

CodeRunner::LANG_RUBY (string)

Ruby Language constant

CodeRunner::LANG_PHP (string)

PHP Language constant

CodeRunner::LANG_BASH (string)

Bash Language constant

CodeRunner::LANG_R (string)

R Language constant

CodeRunner::LANG_JAVASCRIPT (string)

JavaScript Language constant

CodeRunner::LANG_COFFEESCRIPT (string)

CoffeeScript Language constant

CodeRunner::LANG_VB (string)

VB Language constant

CodeRunner::LANG_COBOL (string)

Cobol Language constant

CodeRunner::LANG_FSHARP (string)

F# Language constant

CodeRunner::LANG_D (string)

D Language constant

CodeRunner::LANG_CLOJURE (string)

Clojure Language constant

CodeRunner::LANG_ELIXIR (string)

Elixir Language constant

CodeRunner::LANG_MYSQL (string)

MySQL Language constant

CodeRunner::LANG_RUST (string)

Rust Language constant

CodeRunner::LANG_SCHEME (string)

Scheme Language constant

CodeRunner::LANG_COMMON_LISP (string)

Common Lisp Language constant

CodeRunner::LANG_NADESIKO (string)

ăȘでしこ Language constant

CodeRunner::LANG_TYPESCRIPT (string)

TypeScript Language constant

CodeRunner::LANG_PLAIN (string)

PlainText Language constant

CodeRunner::LANGS (array)

CodeRunner::EXTENSIONS (array)

CodeRunner::STATUS_RUNNING (string)

is status already running.

CodeRunner::STATUS_COMPLETED (string)

is status already completed.

CodeRunner::create()

Start compiling and executing the program code.

CodeRunner::create(string $source_code, string $language, string $input = '', bool $longpoll = false, int $longpoll_timeout = 10): Suzunone\CodeRunner\Entities\OutputEntityInterface

Parameters:

Return:

\Suzunone\CodeRunner\Entities\OutputEntityInterface

CodeRunner::getTemplate()

Returns a template of the program code according to the language constants.

CodeRunner::getTemplate(string $language): string

Parameters:

Return:

string

CodeRunner::getLanguageName()

Get the program name according to the language constant.

CodeRunner::getLanguageName(string $language): string

Parameters:

Return:

string

CodeRunner::getLangExtension()

Get the program file extension according to the language constant.

CodeRunner::getLangExtension(string $language): string

Parameters:

Return:

string

CodeRunner::getApiKey()

Get the API Key.

CodeRunner::getApiKey(): string

Parameters:

Return:

string

CodeRunner::setApiKey()

Set the API Key.

CodeRunner::setApiKey(string $api_key): void

Parameters:

Return:

string

\Suzunone\CodeRunner\Entities\OutputEntityInterface

Get the compilation and execution status of a program

OutputEntityInterface::status()

OutputEntityInterface::status(): StatusEntity;

Parameters:

Return:

Suzunone\CodeRunner\Entities\Input|StatusEntity

OutputEntityInterface::details()

Get the results of compiling and executing a program.

OutputEntityInterface::details(): StatusEntity;

Parameters:

Return:

Suzunone\CodeRunner\Entities\Input|StatusEntity

OutputEntityInterface::getResponse()

Get Response data.

getResponse() : ResponseElementInterface

Parameters:

Return:

Suzunone\CodeRunner\Entities\Elements\Input|ResponseElementInterface

\Suzunone\CodeRunner\Entities\Output\CreateEntity

properties

\Suzunone\CodeRunner\Entities\Output\StatusEntity

properties

\Suzunone\CodeRunner\Entities\Output\DetailsEntity

properties