PHPDaemon\Core\Daemon::lintFile PHP Method

lintFile() public static method

Check file syntax via runkit_lint_file if supported or via php -l
public static lintFile ( $filename ) : boolean
return boolean
    public static function lintFile($filename)
    {
        if (!file_exists($filename)) {
            return false;
        }
        if (self::supported(self::SUPPORT_RUNKIT_SANDBOX)) {
            /** @noinspection PhpUndefinedFunctionInspection */
            return runkit_lint_file($filename);
        }
        $cmd = 'php -l ' . escapeshellcmd($filename) . ' 2>&1';
        exec($cmd, $output, $retcode);
        return 0 === $retcode;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Called when file $path is changed
  * @param  string $path Path
  * @return void
  */
 public function onFileChanged($path)
 {
     if (!Daemon::lintFile($path)) {
         Daemon::log(__METHOD__ . ': Detected parse error in ' . $path);
         return;
     }
     foreach ($this->files[$path] as $cb) {
         if (is_callable($cb) || is_array($cb)) {
             $cb($path);
         } elseif (!Daemon::$process->IPCManager->importFile($cb, $path)) {
             $this->rmWatch($path, $cb);
         }
     }
 }