Skip to content

Commit

Permalink
Remove usages of PHP_EOL
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jan 8, 2024
1 parent 6e73380 commit 4a95db4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
8 changes: 3 additions & 5 deletions examples/gridfs_stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use function getenv;
use function strlen;

use const PHP_EOL;

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

$client = new Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/');
Expand All @@ -31,7 +29,7 @@
$stream = $bucket->openUploadStream('hello.txt');

for ($i = 0; $i < 1_000_000; $i++) {
fwrite($stream, 'Hello line ' . $i . PHP_EOL);
fwrite($stream, 'Hello line ' . $i . "\n");
}

// Last data are flushed to the server when the stream is closed
Expand All @@ -46,11 +44,11 @@
$size += strlen($data);
}

echo 'Read a total of ' . $size . ' bytes' . PHP_EOL;
echo 'Read a total of ' . $size . ' bytes' . "\n";

// Retrieve the file ID to delete it
$id = $bucket->getFileIdForStream($stream);
assert($id instanceof ObjectId);
$bucket->delete($id);

echo 'Deleted file with ID: ' . $id . PHP_EOL;
echo 'Deleted file with ID: ' . $id . "\n";
16 changes: 7 additions & 9 deletions examples/gridfs_stream_wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use function getenv;
use function stream_context_create;

use const PHP_EOL;

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

$client = new Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/');
Expand All @@ -31,29 +29,29 @@

echo 'File exists: ';
echo file_exists('gridfs://mybucket/hello.txt') ? 'yes' : 'no';
echo PHP_EOL;
echo "\n";

echo 'Writing file';
file_put_contents('gridfs://mybucket/hello.txt', 'Hello, GridFS!');
echo PHP_EOL;
echo "\n";

echo 'File exists: ';
echo file_exists('gridfs://mybucket/hello.txt') ? 'yes' : 'no';
echo PHP_EOL;
echo "\n";

echo 'Reading file: ';
echo file_get_contents('gridfs://mybucket/hello.txt');
echo PHP_EOL;
echo "\n";

echo 'Writing new version of the file';
file_put_contents('gridfs://mybucket/hello.txt', 'Hello, GridFS! (v2)');
echo PHP_EOL;
echo "\n";

echo 'Reading new version of the file: ';
echo file_get_contents('gridfs://mybucket/hello.txt');
echo PHP_EOL;
echo "\n";

echo 'Reading previous version of the file: ';
$context = stream_context_create(['gridfs' => ['revision' => -2]]);
echo file_get_contents('gridfs://mybucket/hello.txt', false, $context);
echo PHP_EOL;
echo "\n";
8 changes: 3 additions & 5 deletions examples/gridfs_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use function rewind;
use function stream_get_contents;

use const PHP_EOL;

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

$client = new Client(getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/');
Expand All @@ -35,16 +33,16 @@
// Upload to GridFS from the stream
$id = $gridfs->uploadFromStream('hello.txt', $stream);
assert($id instanceof ObjectId);
echo 'Inserted file with ID: ' . $id . PHP_EOL;
echo 'Inserted file with ID: ', $id, "\n";
fclose($stream);

// Download the file and print the contents directly to an in-memory stream, chunk by chunk
$stream = fopen('php://temp', 'w+');
$gridfs->downloadToStreamByName('hello.txt', $stream);
rewind($stream);
echo 'File contents: ' . stream_get_contents($stream) . PHP_EOL;
echo 'File contents: ', stream_get_contents($stream), "\n";

// Delete the file
$gridfs->delete($id);

echo 'Deleted file with ID: ' . $id . PHP_EOL;
echo 'Deleted file with ID: ', $id, "\n";

0 comments on commit 4a95db4

Please sign in to comment.