- WIP on File lib and CLI's definition
This commit is contained in:
1 parent
777f4af1aa
commit
2e51ff9f4a
3 files changed
+44
-19
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Lean;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function tail(string $path, int $lines = 10) : false|array
|
||||
{
|
||||
$handle = fopen($path, "r");
|
||||
|
||||
$counter = $lines;
|
||||
|
||||
$pos = -2;
|
||||
$beginning = false;
|
||||
$text = array();
|
||||
|
||||
while ($counter && ! $beginning) {
|
||||
$t = "";
|
||||
|
||||
while ($t !== PHP_EOL) {
|
||||
if(fseek($handle, $pos, SEEK_END) == -1) {
|
||||
$beginning = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$t = fgetc($handle);
|
||||
$pos --;
|
||||
}
|
||||
|
||||
$counter --;
|
||||
|
||||
if ($beginning) {
|
||||
rewind($handle);
|
||||
}
|
||||
|
||||
$text[$lines - $counter - 1] = fgets($handle);
|
||||
}
|
||||
|
||||
fclose ($handle);
|
||||
|
||||
return array_reverse($text);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -133,7 +133,7 @@ class Lean
|
||||
$path = dirname(__DIR__) . "/meta/definitions/";
|
||||
|
||||
return array_merge(
|
||||
class_exists(\Mcnd\CLI\Middleware::class) ? require($path . "cli.php") : [],
|
||||
class_exists(\Mcnd\CLI\CliMiddleware::class) ? require($path . "cli.php") : [],
|
||||
class_exists(\Cronard\CronardMiddleware::class) ? require($path . "cronard.php") : [],
|
||||
require($path . "email.php"),
|
||||
require($path . "event.php"),
|
||||
|
||||
Reference in new issue
Block a user