github.com/LanceLRQ/deer-common@v0.0.9-0.20210319081233-e8222ac018a8/provider/php.go (about)

     1  /* PHP Compiler Provider
     2   * (C) 2019 LanceLRQ
     3   *
     4   * This code is licenced under the GPLv3.
     5   */
     6  package provider
     7  
     8  import (
     9  	"fmt"
    10  )
    11  
    12  type PHPCompileProvider struct {
    13  	CodeCompileProvider
    14  }
    15  
    16  func NewPHPCompileProvider() *PHPCompileProvider {
    17  	return &PHPCompileProvider{
    18  		CodeCompileProvider{
    19  			isReady:  false,
    20  			realTime: true,
    21  			Name:     "php",
    22  		},
    23  	}
    24  }
    25  
    26  func (prov *PHPCompileProvider) Init(code string, workDir string) error {
    27  	prov.codeContent = code
    28  	prov.workDir = workDir
    29  
    30  	err := prov.checkWorkDir()
    31  	if err != nil {
    32  		return err
    33  	}
    34  
    35  	err = prov.initFiles(".php", "")
    36  	return err
    37  }
    38  
    39  func (prov *PHPCompileProvider) Compile() (result bool, errmsg string) {
    40  	result, errmsg = prov.shell(fmt.Sprintf(CompileCommands.PHP, prov.codeFilePath))
    41  	if result {
    42  		prov.isReady = true
    43  	}
    44  	return
    45  }
    46  
    47  func (prov *PHPCompileProvider) GetRunArgs() (args []string) {
    48  	args = []string{"/usr/bin/php", "-f", prov.codeFilePath}
    49  	return
    50  }
    51  
    52  func (prov *PHPCompileProvider) IsCompileError(remsg string) bool {
    53  	return false
    54  }