TestClientUser.php #2

  • //
  • guest/
  • jon_parise/
  • api/
  • php/
  • tests/
  • TestClientUser.php
  • View
  • Commits
  • Open Download .zip Download (3 KB)
<?php
class TestClientUser implements PerforceClientUser
{
    private $output = array();
    private $tags = array();

    function ClearOutput()
    {
        $this->output = array();
    }

    function GetOutput()
    {
        return $this->output;
    }

    function AppendOutput($text)
    {
        $this->output = array_merge($this->output, split("\n", $text));
    }

    function GetTags()
    {
        return $this->tags;
    }

    function OutputError($error)
    {
        $this->AppendOutput("$error\n");
    }

    function HandleError($msg, $severity)
    {
        $this->OutputError($msg);
    }

    function Message($msg, $severity)
    {
        $this->OutputInfo(0, $msg);
    }

    function InputData()
    {
        return fgets(STDIN);
    }

    function OutputInfo($level, $data)
    {
        $this->AppendOutput($data);
    }

    function OutputBinary($data)
    {
        $this->AppendOutput($data);
    }

    function OutputText($data)
    {
        $this->AppendOutput($data);
    }

    function OutputStat($tags)
    {
        $this->tags = array_merge($this->tags, $tags);
    }

    function Prompt($msg)
    {
        echo $msg;

        return fgets(STDIN);
    }

    function ErrorPause($buf)
    {
        $this->OutputError($buf);
        fgetc(STDIN);
    }

    function Edit($file)
    {
        if (!empty($_ENV['P4EDITOR'])) {
            $editor = $_ENV['P4EDITOR'];
        } else if (!empty($_ENV['EDITOR'])) {
            $editor = $_ENV['EDITOR'];
        } else {
            $editor = 'vi';
        }

        system("$editor $file");
    }

    function Diff($file1, $file2, $doPage, $flags)
    {
        if (!empty($_ENV['P4DIFF'])) {
            $diff = $_ENV['P4DIFF'];
        } else if (!empty($_ENV['DIFF'])) {
            $diff = $_ENV['DIFF'];
        } else {
            $this->OutputError(
                'No diff program specified with $P4DIFF or $DIFF.');
        }

        $pager = false;
        if ($doPage) {
            if (!empty($_ENV['P4PAGER'])) {
                $pager = $_ENV['P4PAGER'];
            } else if (!empty($_ENV['PAGER'])) {
                $pager = $_ENV['PAGER'];
            } else {
                $pager = false;
            }
        }

        if ($pager) {
            system("$diff $flags $file1 $file2 | $pager");
        } else {
            system("$diff $flags $file1 $file2");
        }
    }

    function Merge($base, $leg1, $leg2, $result)
    {
        if (!empty($_ENV['P4MERGE'])) {
            $merge = $_ENV['P4MERGE'];
        } else if (!empty($_ENV['MERGE'])) {
            $merge = $_ENV['MERGE'];
        } else {
            $this->OutputError(
                'No merge program specified with $P4MERGE or $MERGE.');
        }

        system("$merge $base $leg1 $leg2 $result");
    }

    function Help($help)
    {
        $this->Message(implode("\n", $help));
    }
}
# Change User Description Committed
#2 6092 Jon_Parise Fixing support for tagged output.
 We also now return all of the tags
   (unfiltered) to the user's OutputStat() implementation.
#1 6084 Jon_Parise Adding some initial unit tests.