pharext\Task\StreamFetch::run PHP Method

run() public method

public run ( boolean $verbose = false ) : pharext\Task\Tempfile
$verbose boolean
return pharext\Task\Tempfile
    public function run($verbose = false)
    {
        if ($verbose !== false) {
            printf("Fetching %s ...\n", $this->source);
        }
        $context = $this->createStreamContext();
        if (!($remote = fopen($this->source, "r", false, $context))) {
            throw new Exception();
        }
        $local = new Tempfile("remote");
        if (!stream_copy_to_stream($remote, $local->getStream())) {
            throw new Exception();
        }
        $local->closeStream();
        /* STREAM_NOTIFY_COMPLETED is not generated, see above */
        call_user_func($this->progress, 1);
        return $local;
    }

Usage Example

Example #1
0
 function testPecl()
 {
     $cmd = new Task\StreamFetch("http://pecl.php.net/get/pecl_http", function ($pct) use(&$log) {
         $log[] = $pct;
     });
     $tmp = $cmd->run();
     $this->assertTrue(is_file($tmp), "is_file({$tmp})");
     $this->assertGreaterThan(1, count($log), "1 < count(\$log)");
     $this->assertContains(0, $log, "in_array(0, \$log)");
     $this->assertContains(1, $log, "in_array(1, \$log)");
     $cmd = new Task\Extract($tmp);
     $dir = $cmd->run();
     $this->assertTrue(is_dir($dir), "is_dir({$dir})");
     $this->assertTrue(is_file("{$dir}/package.xml"), "is_file({$dir}/package.xml");
     $cmd = new Task\PeclFixup($dir);
     $new = $cmd->run();
     $this->assertTrue(is_dir($new), "is_dir({$new})");
     $this->assertFalse(is_file("{$dir}/package.xml"), "is_file({$dir}/package.xml");
     $this->assertTrue(is_file("{$new}/package.xml"), "is_file({$new}/package.xml");
     (new Task\Cleanup($dir))->run();
     $this->assertFalse(is_dir($dir), "is_dir({$dir})");
     $this->assertFalse(is_dir($new), "is_dir({$new})");
 }
All Usage Examples Of pharext\Task\StreamFetch::run