mirror of
https://gh.wpcy.net/https://github.com/aspirepress/AspireCloud.git
synced 2026-06-01 00:19:09 +08:00
27 lines
519 B
PHP
27 lines
519 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Utils;
|
|
|
|
use Generator;
|
|
use SplFileObject;
|
|
|
|
final class File
|
|
{
|
|
public static function lazyLines(string $filename): Generator
|
|
{
|
|
$file = new SplFileObject($filename);
|
|
while (!$file->eof()) {
|
|
$line = $file->fgets();
|
|
if (str_ends_with($line, "\n")) {
|
|
$line = substr($line, 0, -1);
|
|
}
|
|
yield $line;
|
|
}
|
|
}
|
|
|
|
private function __construct()
|
|
{
|
|
// not instantiable
|
|
}
|
|
}
|