diff --git a/composer.json b/composer.json index ee258aea..7a0f7799 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "leafo/scssphp": "^0.7.5", "monolog/monolog": "^1.23", "firephp/firephp-core": "^0.4.0", - "vlucas/valitron": "^1.4" + "vlucas/valitron": "^1.4", + "php-extended/php-tail": "^2.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 25ee5fcb..498256b0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4659ec09c50a2ccd1b53194b3f53890a", + "content-hash": "4b18f5660106f71d2aba7f1dcee07033", "packages": [ { "name": "brandonwamboldt/utilphp", @@ -454,6 +454,90 @@ ], "time": "2017-06-19T01:22:40+00:00" }, + { + "name": "php-extended/php-system", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-extended/php-system.git", + "reference": "66727d5dc0a665916bd7e08bcfb9820e7be1d20c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-extended/php-system/zipball/66727d5dc0a665916bd7e08bcfb9820e7be1d20c", + "reference": "66727d5dc0a665916bd7e08bcfb9820e7be1d20c", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpExtended\\System\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anastaszor", + "role": "developer" + } + ], + "description": "A generic way to find informations about the running system", + "homepage": "https://github.com/php-extended/php-system", + "keywords": [ + "operating system", + "os", + "php", + "system" + ], + "time": "2017-01-14T11:56:24+00:00" + }, + { + "name": "php-extended/php-tail", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/php-extended/php-tail.git", + "reference": "eabf7bee64f8c30fe9b9e1176562fdb903c54ae7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-extended/php-tail/zipball/eabf7bee64f8c30fe9b9e1176562fdb903c54ae7", + "reference": "eabf7bee64f8c30fe9b9e1176562fdb903c54ae7", + "shasum": "" + }, + "require": { + "php-extended/php-system": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpExtended\\Tail\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anastaszor", + "role": "developer" + } + ], + "description": "A smart way to tail files depending of the environment", + "homepage": "https://github.com/php-extended/php-tail", + "keywords": [ + "cheat", + "mighty", + "naive", + "php", + "tail" + ], + "time": "2017-07-25T13:52:42+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 66b2fef0..b625f69c 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -10,6 +10,8 @@ return array( 'kakao\\' => array($baseDir . '/d_setting', $baseDir . '/src/kakao'), 'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'), 'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'), + 'PhpExtended\\Tail\\' => array($vendorDir . '/php-extended/php-tail/src'), + 'PhpExtended\\System\\' => array($vendorDir . '/php-extended/php-system/src'), 'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'), 'League\\Plates\\' => array($vendorDir . '/league/plates/src'), 'Leafo\\ScssPhp\\' => array($vendorDir . '/leafo/scssphp/src'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index c57e0ac1..0be97ecf 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -25,6 +25,8 @@ class ComposerStaticInit67b09c83b85c3bc0027caefe5bba171a array ( 'Psr\\Log\\' => 8, 'Psr\\Http\\Message\\' => 17, + 'PhpExtended\\Tail\\' => 17, + 'PhpExtended\\System\\' => 19, ), 'M' => array ( @@ -62,6 +64,14 @@ class ComposerStaticInit67b09c83b85c3bc0027caefe5bba171a array ( 0 => __DIR__ . '/..' . '/psr/http-message/src', ), + 'PhpExtended\\Tail\\' => + array ( + 0 => __DIR__ . '/..' . '/php-extended/php-tail/src', + ), + 'PhpExtended\\System\\' => + array ( + 0 => __DIR__ . '/..' . '/php-extended/php-system/src', + ), 'Monolog\\' => array ( 0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index b8365b68..425ca3e6 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -463,6 +463,94 @@ "psr-3" ] }, + { + "name": "php-extended/php-system", + "version": "1.3.0", + "version_normalized": "1.3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-extended/php-system.git", + "reference": "66727d5dc0a665916bd7e08bcfb9820e7be1d20c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-extended/php-system/zipball/66727d5dc0a665916bd7e08bcfb9820e7be1d20c", + "reference": "66727d5dc0a665916bd7e08bcfb9820e7be1d20c", + "shasum": "" + }, + "time": "2017-01-14T11:56:24+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "PhpExtended\\System\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anastaszor", + "role": "developer" + } + ], + "description": "A generic way to find informations about the running system", + "homepage": "https://github.com/php-extended/php-system", + "keywords": [ + "operating system", + "os", + "php", + "system" + ] + }, + { + "name": "php-extended/php-tail", + "version": "2.1.1", + "version_normalized": "2.1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-extended/php-tail.git", + "reference": "eabf7bee64f8c30fe9b9e1176562fdb903c54ae7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-extended/php-tail/zipball/eabf7bee64f8c30fe9b9e1176562fdb903c54ae7", + "reference": "eabf7bee64f8c30fe9b9e1176562fdb903c54ae7", + "shasum": "" + }, + "require": { + "php-extended/php-system": "^1.2" + }, + "time": "2017-07-25T13:52:42+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "PhpExtended\\Tail\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anastaszor", + "role": "developer" + } + ], + "description": "A smart way to tail files depending of the environment", + "homepage": "https://github.com/php-extended/php-tail", + "keywords": [ + "cheat", + "mighty", + "naive", + "php", + "tail" + ] + }, { "name": "psr/http-message", "version": "1.0.1", diff --git a/vendor/php-extended/php-system/.gitignore b/vendor/php-extended/php-system/.gitignore new file mode 100644 index 00000000..70f6fbb3 --- /dev/null +++ b/vendor/php-extended/php-system/.gitignore @@ -0,0 +1,10 @@ +composer.phar +/vendor/ + +# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file +# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file +# composer.lock + +.settings/ +.buildpath +.project diff --git a/vendor/php-extended/php-system/LICENSE b/vendor/php-extended/php-system/LICENSE new file mode 100644 index 00000000..853b46db --- /dev/null +++ b/vendor/php-extended/php-system/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/php-extended/php-system/README.md b/vendor/php-extended/php-system/README.md new file mode 100644 index 00000000..308879aa --- /dev/null +++ b/vendor/php-extended/php-system/README.md @@ -0,0 +1,38 @@ +# php-system +A generic way to find informations about your system + +## Installation + +The installation of this library is made via composer. +Download `composer.phar` from [their website](https://getcomposer.org/download/). +Then add to your composer.json : + +```json + "require": { + ... + "php-extended/php-system": "^1.0", + ... + } +``` + +Then run `php composer.phar update` to install this library. +The autoloading of all classes of this library is made through composer's autoloader. + +## Basic Usage + +You can get the singleton php-system object by doing the following: + +```php + +use PhpExtended\System\OperatingSystem; + +$system = OperatingSystem::get(); + +``` + +This system object have lots of useful properties. An instance of `UnknownOs` is returned in case this is not implemented. +The `get` method never throws any exception. + +## License + +MIT (See [license file](LICENSE)). diff --git a/vendor/php-extended/php-system/composer.json b/vendor/php-extended/php-system/composer.json new file mode 100644 index 00000000..3b068bb4 --- /dev/null +++ b/vendor/php-extended/php-system/composer.json @@ -0,0 +1,27 @@ +{ + "name" : "php-extended/php-system", + "description" : "A generic way to find informations about the running system", + "type" : "library", + "homepage" : "https://github.com/php-extended/php-system", + "license" : "MIT", + "authors" : [{ + "name" : "Anastaszor", + "role" : "Developer" + } + ], + "support" : { + "issues" : "https://github.com/php-extended/php-system/issues", + "source" : "https://github.com/php-extended/php-system" + }, + "autoload" : { + "psr-4" : { + "PhpExtended\\System\\" : "src/" + } + }, + "keywords" : [ + "php", + "system", + "os", + "operating system" + ] +} \ No newline at end of file diff --git a/vendor/php-extended/php-system/src/Cygwin.php b/vendor/php-extended/php-system/src/Cygwin.php new file mode 100644 index 00000000..044ff3b4 --- /dev/null +++ b/vendor/php-extended/php-system/src/Cygwin.php @@ -0,0 +1,36 @@ +smart(10, 200, false); +} +catch(TailException $e) +{ + // do something is case it fails +} + +``` + +This library proposes 6 methods to tail a file, which can be more or less +performant depending on the context. They each follow the same signature +(see sample code above). + +Those methods are : +- `naive` : Loads the whole file into php, then retains only the last lines +- `cheat` : Uses underlying unix `tail -n` function +- `single` : Uses a signle byte buffer to read backwards the file +- `simple` : Uses a fixed size buffer to read backwards the file +- `dynamic` : Uses a dynamically sized buffer to read backwards the file +- `smart` : Tries to choose the best among those five to be the fastest (recommanded) + +This library is inspired from this [specific stackoverflow topic](http://stackoverflow.com/questions/15025875/what-is-the-best-way-in-php-to-read-last-lines-from-a-file/15025877). + + +## License +MIT (See [license file](LICENSE)). diff --git a/vendor/php-extended/php-tail/composer.json b/vendor/php-extended/php-tail/composer.json new file mode 100644 index 00000000..4f8568c5 --- /dev/null +++ b/vendor/php-extended/php-tail/composer.json @@ -0,0 +1,31 @@ +{ + "name" : "php-extended/php-tail", + "description" : "A smart way to tail files depending of the environment", + "type" : "library", + "license" : "MIT", + "authors" : [{ + "name" : "Anastaszor", + "role" : "Developer" + } + ], + "support" : { + "issues" : "https://github.com/php-extended/php-tail/issues", + "source" : "https://github.com/php-extended/php-tail" + }, + "keywords" : [ + "php", + "tail", + "naive", + "cheat", + "mighty" + ], + "autoload" : { + "psr-4" : { + "PhpExtended\\Tail\\" : "src/" + } + }, + "homepage" : "https://github.com/php-extended/php-tail", + "require" : { + "php-extended/php-system" : "^1.2" + } +} \ No newline at end of file diff --git a/vendor/php-extended/php-tail/src/FileNotFoundException.php b/vendor/php-extended/php-tail/src/FileNotFoundException.php new file mode 100644 index 00000000..95163256 --- /dev/null +++ b/vendor/php-extended/php-tail/src/FileNotFoundException.php @@ -0,0 +1,32 @@ + $filename)), + 404 + ); + } + +} diff --git a/vendor/php-extended/php-tail/src/FileTooBigException.php b/vendor/php-extended/php-tail/src/FileTooBigException.php new file mode 100644 index 00000000..f0b2e43f --- /dev/null +++ b/vendor/php-extended/php-tail/src/FileTooBigException.php @@ -0,0 +1,32 @@ + $filename)), + 500 + ); + } + +} diff --git a/vendor/php-extended/php-tail/src/IOException.php b/vendor/php-extended/php-tail/src/IOException.php new file mode 100644 index 00000000..54398cf4 --- /dev/null +++ b/vendor/php-extended/php-tail/src/IOException.php @@ -0,0 +1,30 @@ + $filename)), + 500 + ); + } + +} diff --git a/vendor/php-extended/php-tail/src/IllegalArgumentException.php b/vendor/php-extended/php-tail/src/IllegalArgumentException.php new file mode 100644 index 00000000..8d7a6c68 --- /dev/null +++ b/vendor/php-extended/php-tail/src/IllegalArgumentException.php @@ -0,0 +1,30 @@ + $filename)), + 500 + ); + } + +} diff --git a/vendor/php-extended/php-tail/src/IllegalOsException.php b/vendor/php-extended/php-tail/src/IllegalOsException.php new file mode 100644 index 00000000..f4e0734b --- /dev/null +++ b/vendor/php-extended/php-tail/src/IllegalOsException.php @@ -0,0 +1,31 @@ +getFileExists() method to be safe as tailing targeted + * file. + * + * @param string $filepath the targeted file path, may be absolute or + * relative, all rules for finding it with fopen will be unchanged. + */ + public function __construct($filepath) + { + $this->_file_path = $filepath; + $this->_file_exists = is_file($this->_file_path); + } + + /** + * Gets the file path that was given to this object. + * + * @return string the file path of the target. + */ + public function getFilePath() + { + return $this->_file_path; + } + + /** + * Gets whether target file exists or not. + * + * @return boolean + */ + public function getFileExists() + { + return $this->_file_exists; + } + + /** + * Gets whether this running system is from an unix family. This is called + * only assuming that ALL linux based operating system have the tail -n + * command available and in their $PATH, so it can direcly be called by + * php's passthru() function. + * + * @return boolean true if `tail -n` is supported. + */ + protected function isUnixSystem() + { + return OperatingSystem::get()->isUnix(); + } + + /** + * Decides the best way to tail the given file given the environment. + * + * @param int $nblines the number of lines wanted + * @param int $hint a median number of bytes for each line in target file + * @param boolean $silent if false, any error will throw an exception. If + * true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + */ + public function smart($nblines, $hint = null, $silent = false) + { + if(!$this->_file_exists) + { + if($silent) return array(); + throw new FileNotFoundException($this->_file_path, $nblines, $hint); + } + + $nblines = (int) $nblines; + if($nblines <= 0) + { + if($silent) return array(); + throw new IllegalArgumentException($this->_file_path, $nblines, $hint); + } + + $filelength = @filesize($this->_file_path); + if($filelength === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + if($filelength == 0) + return array(); + if($filelength < 0) + { + if($this->isUnixSystem()) + return $this->cheat($nblines, $hint, $silent); + + if($silent) return array(); + throw new FileTooBigException($this->_file_path, $nblines, $hint); + } + + if($nblines <= 2) + return $this->single($nblines, $hint, $silent); + + if($filelength <= 10240) // 10kB + return $this->naive($nblines, $hint, $silent); + + return $this->dynamic($nblines, $hint, $silent); + } + + /** + * The naive approach. This will load the whole file into php's buffer + * and extract only the last wanted lines. + * + * @param int $nblines the number of lines wanted + * @param int $hint a median number of bytes for each line in target file + * @param boolean $silent if false, any error will throw an exception. If + * true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + */ + public function naive($nblines, $hint = null, $silent = false) + { + if(!$this->_file_exists) + { + if($silent) return array(); + throw new FileNotFoundException($this->_file_path, $nblines, $hint); + } + + $nblines = (int) $nblines; + if($nblines <= 0) + { + if($silent) return array(); + throw new IllegalArgumentException($this->_file_path, $nblines, $hint); + } + + $filedata = file($this->_file_path); + if($filedata === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + return array_slice($filedata, -$nblines); + } + + /** + * The cheating approach. This will call the tail unix function and get + * the return from it. + * + * @param int $nblines the number of lines wanted + * @param int $hint a median number of bytes for each line in target file + * @param boolean $silent if false, any error will throw an exception. If + * true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + */ + public function cheat($nblines, $hint = null, $silent = false) + { + if(!$this->_file_exists) + { + if($silent) return array(); + throw new FileNotFoundException($this->_file_path, $nblines, $hint); + } + + $nblines = (int) $nblines; + if($nblines <= 0) + { + if($silent) return array(); + throw new IllegalArgumentException($this->_file_path, $nblines, $hint); + } + + if(!$this->isUnixSystem()) + { + if($silent) return array(); + throw new IllegalOsException($this->_file_path, $nblines, $hint); + } + + if(!function_exists('ob_start')) + { + if($silent) return array(); + throw new OutputBufferException($this->_file_path, $nblines, $hint); + } + + if(!ob_start()) + { + if($silent) return array(); + throw new OutputBufferException($this->_file_path, $nblines, $hint); + } + + $returnvar = 0; + passthru('tail -n '.$nblines.' '.escapeshellarg($this->_file_path), $returnvar); + if($returnvar !== 0) + { + ob_end_clean(); + if($silent) return array(); + throw new TailShellException($this->_file_path, $nblines, $hint, $returnvar); + } + + $results = ob_get_clean(); + if($results === false) + { + if($silent) return array(); + throw new OutputBufferException($this->_file_path, $nblines, $hint); + } + + return array_map('trim', explode("\n", $results)); + } + + /** + * The single byte buffer approach. This will read backward from the end + * of the file each char until wanted lines are read. + * + * @param int $nblines the number of lines wanted + * @param int $hint a median number of bytes for each line in target file + * @param boolean $silent if false, any error will throw an exception. If + * true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + */ + public function single($nblines, $hint = null, $silent = false) + { + if(!$this->_file_exists) + { + if($silent) return array(); + throw new FileNotFoundException($nblines, $hint); + } + + $nblines = (int) $nblines; + if($nblines <= 0) + { + if($silent) return array(); + throw new IllegalArgumentException($this->_file_path, $nblines, $hint); + } + + $handle = fopen($this->_file_path, 'r'); + if($handle === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + $linecounter = $nblines; + $pos = -2; + $beginning = false; + $text = array(); + while($linecounter > 0) + { + $t = " "; + while($t != "\n") + { + $seek = fseek($handle, $pos, SEEK_END); + if($seek === -1) + { + $beginning = true; + break; + } + $t = fgetc($handle); + if($t === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + $pos--; + } + $linecounter--; + if($beginning) + { + $rewind = rewind($handle); + if($rewind === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + } + $data = fgetc($handle); + if($data === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + $text[$nblines - $linecounter - 1] = $data; + if($beginning) break; + } + + fclose($handle); + + return array_reverse($text); + } + + /** + * The simple buffer approach. This will read backward from the end of the + * file with a fixed size buffer until wanted lines are read. + * + * @param int $nblines the number of lines wanted + * @param int $hint a median number of bytes for each line in target file + * @param boolean $silent if false, any error will throw an exception. If + * true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + */ + public function simple($nblines, $hint = null, $silent = false) + { + if(!$this->_file_exists) + { + if($silent) return array(); + throw new FileNotFoundException($nblines, $hint); + } + + $nblines = (int) $nblines; + if($nblines <= 0) + { + if($silent) return array(); + throw new IllegalArgumentException($this->_file_path, $nblines, $hint); + } + + if($hint === null) + { + // just assuming that this is text file with 40 char per line as a + // median basis. May be larger if it is a log file + $hint = 40; + if(strrpos($this->_file_path, '.log') === strlen($this->_file_path) - 4) + { + $hint = 240; + } + } + + $buffer = 4096; + + return $this->find($nblines, $buffer, $hint, $silent); + } + + /** + * The dynamic buffer approach. This will read backward from the end of the + * file with a fixed size buffer which is proportional to the size of the + * wanted chunk of that file. + * + * @param int $nblines the number of lines wanted + * @param int $hint a median number of bytes for each line in target file + * @param boolean $silent if false, any error will throw an exception. If + * true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + */ + public function dynamic($nblines, $hint = null, $silent = false) + { + if(!$this->_file_exists) + { + if($silent) return array(); + throw new FileNotFoundException($nblines, $hint); + } + + $nblines = (int) $nblines; + if($nblines <= 0) + { + if($silent) return array(); + throw new IllegalArgumentException($this->_file_path, $nblines, $hint); + } + + if($hint === null) + { + // just assuming that this is text file with 40 char per line as a + // median basis. May be larger if it is a log file + $hint = 40; + if(strrpos($this->_file_path, '.log') === strlen($this->_file_path) - 4) + { + $hint = 240; + } + } + + $buffer = $hint * $nblines / 10; + + return $this->find($nblines, $buffer, $hint, $silent); + } + + /** + * Extracts the wanted number of lines according to the given buffer + * length. + * + * @param int $nblines the number of lines wanted + * @param int $buffer the size of the buffer that will be used to seek + * @param int $hint an estimation of the median line length on this file + * @param boolean $silent if false, any error will throw an exception. + * If true, any error will silently return an empty array. + * @return string[] the wanted tailed lines + * @throws IOException if any error occur + */ + protected function find($nblines, $buffer, $hint, $silent) + { + $lines = $nblines; + $f = fopen($this->_file_path, 'r'); + if($f === false) + { + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + $seek = fseek($f, -1, SEEK_END); + if($seek === -1) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + $read = fread($f, 1); + if($read === false) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + if($read === "\n") $lines -= 1; + + // faster initialisation + $seek = min(ftell($f), $hint * $nblines); + $seeked = fseek($f, -$seek, SEEK_CUR); + if($seeked === -1) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + $chunk = fread($f, $seek); + if($chunk === false) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + $output = $chunk; + $seeked = fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR); + if($seeked === -1) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + $lines -= substr_count($chunk, "\n"); + + // while we want more + while(ftell($f) > 0 && $lines >= 0) + { + // figure out how far back we should jump + $seek = min(ftell($f), $buffer); + + // do the jump backwards relative to where we are + $seeked = fseek($f, -$seek, SEEK_CUR); + if($seeked === -1) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + // read a chunk and prepend it to out output + $chunk = fread($f, $seek); + if($chunk === false) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + $output = $chunk . $output; + + // jump back to where we started reading + $seeked = fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR); + if($seeked === -1) + { + fclose($f); + if($silent) return array(); + throw new IOException($this->_file_path, $nblines, $hint); + } + + // decrease out line counter + $lines -= substr_count($chunk, "\n"); + } + + fclose($f); + + // while we have too many lines + // because the buffer size we might have read too many + while($lines++ < 0) + { + $output = substr($output, strpos($output, "\n") + 1); + } + + return explode("\n", str_replace(array("\r\n", "\r"), array("\n", ''), trim($output))); + } + +} diff --git a/vendor/php-extended/php-tail/src/TailException.php b/vendor/php-extended/php-tail/src/TailException.php new file mode 100644 index 00000000..592f5076 --- /dev/null +++ b/vendor/php-extended/php-tail/src/TailException.php @@ -0,0 +1,84 @@ +_filename = $filename; + $this->_nblines = $nblines; + $this->_hint = $hint; + } + + /** + * Gets the file path that was asked. + * + * @return string + */ + public function getFilename() + { + return $this->_filename; + } + + /** + * Gets the number of lines that was asked. + * + * @return int + */ + public function getNblines() + { + return $this->_nblines; + } + + /** + * Gets the median number of characters per line that was given, or + * calculated, if applicable. + * + * @return int + */ + public function getHint() + { + return $this->_hint; + } + +} diff --git a/vendor/php-extended/php-tail/src/TailShellException.php b/vendor/php-extended/php-tail/src/TailShellException.php new file mode 100644 index 00000000..9a7f6d13 --- /dev/null +++ b/vendor/php-extended/php-tail/src/TailShellException.php @@ -0,0 +1,30 @@ + $filename)), + 500 + ); + } + +}