Skip to content

Commit

Permalink
Use full namespaces in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Sep 30, 2021
1 parent eb89af1 commit e6228f1
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 57 deletions.
13 changes: 4 additions & 9 deletions examples/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,22 @@
// how it can be passed to a TAR decoder and how we can then pipe each
// individual file to the console output.

use Clue\CaretNotation\Encoder;
use Clue\React\Docker\Client;
use Clue\React\Tar\Decoder;
use React\Stream\ReadableStreamInterface;

require __DIR__ . '/../vendor/autoload.php';

$container = isset($argv[1]) ? $argv[1] : 'asd';
$path = isset($argv[2]) ? $argv[2] : '/etc/passwd';
echo 'Container "' . $container . '" dumping "' . $path . '" (pass as arguments to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

$stream = $client->containerArchiveStream($container, $path);

$tar = new Decoder();
$tar = new Clue\React\Tar\Decoder();

// use caret notation for any control characters except \t, \r and \n
$caret = new Encoder("\t\r\n");
$caret = new Clue\CaretNotation\Encoder("\t\r\n");

$tar->on('entry', function ($header, ReadableStreamInterface $file) use ($caret) {
$tar->on('entry', function ($header, React\Stream\ReadableStreamInterface $file) use ($caret) {
// write each entry to the console output
echo '########## ' . $caret->encode($header['filename']) . ' ##########' . PHP_EOL;
$file->on('data', function ($chunk) use ($caret) {
Expand Down
7 changes: 2 additions & 5 deletions examples/attach-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
// $ docker run -it --rm --name=foo busybox sh
// $ php examples/attach-stream.php foo

use Clue\CaretNotation\Encoder;
use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$container = isset($argv[1]) ? $argv[1] : 'foo';
echo 'Dumping output of container "' . $container . '" (pass as argument to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

// use caret notation for any control characters except \t, \r and \n
$caret = new Encoder("\t\r\n");
$caret = new Clue\CaretNotation\Encoder("\t\r\n");

$stream = $client->containerAttachStream($container, true, true);
$stream->on('data', function ($data) use ($caret) {
Expand Down
3 changes: 1 addition & 2 deletions examples/benchmark-attach.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
// $ docker run -i --rm --log-driver=none busybox dd if=/dev/zero bs=1M count=1000 status=none | dd of=/dev/null

use Clue\React\Docker\Client;
use React\EventLoop\Loop;

require __DIR__ . '/../vendor/autoload.php';
Expand All @@ -27,7 +26,7 @@
$cmd = array_slice($argv, 2);
}

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->containerCreate(array(
'Image' => $image,
Expand Down
3 changes: 1 addition & 2 deletions examples/benchmark-exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//
// $ docker exec foo dd if=/dev/zero bs=1M count=1000 | dd of=/dev/null

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -29,7 +28,7 @@
$cmd = array_slice($argv, 2);
}

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->execCreate($container, $cmd)->then(function ($info) use ($client) {
$stream = $client->execStartStream($info['Id'], true);
Expand Down
3 changes: 1 addition & 2 deletions examples/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
// this simple example displays all docker events that happen in the next 10s.
// try starting / removing a container in the meantime to see some output.

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client();
$client = new Clue\React\Docker\Client();

// get a list of all events that happened up until this point
// expect this list to be limited to the last 64 (or so) events
Expand Down
7 changes: 2 additions & 5 deletions examples/exec-inspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

// this simple example executes a "sleep 2" within the given running container

use Clue\React\Buzz\Message\ResponseException;
use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$container = 'asd';
Expand All @@ -18,7 +15,7 @@
$cmd = array_slice($argv, 2);
}

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->execCreate($container, $cmd)->then(function ($info) use ($client) {
echo 'Created with info: ' . json_encode($info) . PHP_EOL;
Expand All @@ -38,7 +35,7 @@
}, function (Exception $e) {
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;

if ($e instanceof ResponseException) {
if ($e instanceof React\Http\Message\ResponseException) {
echo 'Response: ' . $e->getResponse()->getBody() . PHP_EOL;
}
});
8 changes: 3 additions & 5 deletions examples/exec-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
// this example executes some commands within the given running container and
// displays the streaming output as it happens.

use Clue\React\Docker\Client;
use React\EventLoop\Loop;
use React\Stream\WritableResourceStream;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -24,10 +22,10 @@
$cmd = array_slice($argv, 2);
}

$client = new Client();
$client = new Clue\React\Docker\Client();

$out = new WritableResourceStream(STDOUT);
$stderr = new WritableResourceStream(STDERR);
$out = new React\Stream\WritableResourceStream(STDOUT);
$stderr = new React\Stream\WritableResourceStream(STDERR);

// unkown exit code by default
$exit = 1;
Expand Down
7 changes: 2 additions & 5 deletions examples/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// this example shows how the containerExport() call returns a TAR stream
// and how we it can be piped into a output tar file.

use Clue\React\Docker\Client;
use React\Stream\WritableResourceStream;

require __DIR__ . '/../vendor/autoload.php';

if (DIRECTORY_SEPARATOR === '\\') {
Expand All @@ -16,7 +13,7 @@
$target = isset($argv[2]) ? $argv[2] : ($container . '.tar');
echo 'Exporting whole container "' . $container . '" to "' . $target .'" (pass as arguments to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

$stream = $client->containerExportStream($container);

Expand All @@ -25,5 +22,5 @@
echo 'ERROR requesting stream' . PHP_EOL . $e;
});

$out = new WritableResourceStream(fopen($target, 'w'));
$out = new React\Stream\WritableResourceStream(fopen($target, 'w'));
$stream->pipe($out);
4 changes: 1 addition & 3 deletions examples/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

// this simple example displays system wide information from Docker as a simple JSON

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->info()->then(function ($info) {
echo json_encode($info, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
Expand Down
7 changes: 2 additions & 5 deletions examples/logs-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
// this example shows how the containerLogsStream() call can be used to get the logs of the given container.
// demonstrates the streaming logs API, which can be used to dump the logs as they arrive

use Clue\CaretNotation\Encoder;
use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$container = isset($argv[1]) ? $argv[1] : 'asd';
echo 'Dumping logs (last 100 lines) of container "' . $container . '" (pass as argument to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

// use caret notation for any control characters except \t, \r and \n
$caret = new Encoder("\t\r\n");
$caret = new Clue\CaretNotation\Encoder("\t\r\n");

$stream = $client->containerLogsStream($container, true, true, true, 0, false, 100);
$stream->on('data', function ($data) use ($caret) {
Expand Down
4 changes: 2 additions & 2 deletions examples/logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
$container = isset($argv[1]) ? $argv[1] : 'foo';
echo 'Dumping logs (last 100 lines) of container "' . $container . '" (pass as argument to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->containerLogs($container, false, true, true, 0, false, 100)->then(
function ($logs) {
echo 'Received the following logs:' . PHP_EOL;

// escape control characters (dumping logs of vi/nano etc.)
$caret = new Encoder("\t\r\n");
$caret = new Clue\CaretNotation\Encoder("\t\r\n");
echo $caret->encode($logs);
},
function ($error) use ($container) {
Expand Down
4 changes: 1 addition & 3 deletions examples/pull.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
// this example shows how the imageCreateStream() call can be used to pull a given image.
// demonstrates the JSON streaming API, individual progress events will be printed as they happen.

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$image = isset($argv[1]) ? $argv[1] : 'clue/redis-benchmark';
echo 'Pulling image "' . $image . '" (pass as argument to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

$stream = $client->imageCreateStream($image);

Expand Down
4 changes: 1 addition & 3 deletions examples/push.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
// this example shows how the imagePush() call can be used to publish a given image.
// this requires authorization and this example includes some invalid defaults.

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$image = isset($argv[1]) ? $argv[1] : 'asd';
$auth = json_decode('{"username": "string", "password": "string", "email": "string", "serveraddress" : "string", "auth": ""}');
echo 'Pushing image "' . $image . '" (pass as argument to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->imagePush($image, null, null, $auth)->then(function ($result) {
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
Expand Down
4 changes: 1 addition & 3 deletions examples/resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
// this example tries to adjust the TTY size of the given container to 10x10.
// you can check this via "docker logs".

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$container = isset($argv[1]) ? $argv[1] : 'asd';

$client = new Client();
$client = new Clue\React\Docker\Client();

$client->containerInspect($container)->then(function ($info) use ($client, $container) {
$size = $info['HostConfig']['ConsoleSize'];
Expand Down
4 changes: 1 addition & 3 deletions examples/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
// this example shows how the `containerStatsStream()` method can be used show live container stats.
// demonstrates the JSON streaming API, individual stats events will be printed as they happen.

use Clue\React\Docker\Client;

require __DIR__ . '/../vendor/autoload.php';

$container = isset($argv[1]) ? $argv[1] : 'asd';
echo 'Monitoring "' . $container . '" (pass as argument to this example)' . PHP_EOL;

$client = new Client();
$client = new Clue\React\Docker\Client();

$stream = $client->containerStatsStream($container);

Expand Down

0 comments on commit e6228f1

Please sign in to comment.