Symfony\Component\Process\Process::setInput PHP Method

setInput() public method

This content will be passed to the underlying process standard input.
public setInput ( resource | scalar | Traversable | null $input ) : self
$input resource | scalar | Traversable | null The content
return self The current Process instance
    public function setInput($input)
    {
        if ($this->isRunning()) {
            throw new LogicException('Input can not be set while the process is running.');
        }
        $this->input = ProcessUtils::validateInput(__METHOD__, $input);
        return $this;
    }

Usage Example

Example #1
0
 public static function kanjiToRomaji($input, &$returnCode = '')
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         return $input;
     }
     $japanese = "/([\\x{3000}-\\x{303f}\\x{3040}-\\x{309f}\\x{30a0}-\\x{30ff}\\x{ff00}-\\x{ff9f}\\x{4e00}-\\x{9faf}\\x{3400}-\\x{4dbf}])+/iu";
     preg_match_all($japanese, $input, $matches);
     if (empty($matches[0]) || !is_array($matches[0])) {
         return $input;
     }
     $placeholders = ['in' => $matches[0], 'out' => []];
     $uniq = uniqid();
     $kakasi = 'kakasi -i euc -w | kakasi -i euc -Ha -Ka -Ja -Ea -ka';
     $process = new Process($kakasi);
     $words = implode($uniq, $placeholders['in']);
     $convertedWords = mb_convert_encoding($words, 'eucjp', 'utf-8');
     $process->setInput($convertedWords);
     $process->run();
     if (!$process->isSuccessful()) {
         return IRCHelper::colorText('ERROR', IRCHelper::COLOR_RED) . ': can\'t run kakasi';
     }
     $romaji = $process->getOutput();
     $placeholders['out'] = explode($uniq, $romaji);
     $input = str_replace($placeholders['in'], $placeholders['out'], $input);
     return $input;
 }
All Usage Examples Of Symfony\Component\Process\Process::setInput