updated-packages
This commit is contained in:
24
vendor/php-parallel-lint/php-console-highlighter/CHANGELOG.md
vendored
Normal file
24
vendor/php-parallel-lint/php-console-highlighter/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.5] - 2020-05-13
|
||||
|
||||
### Added
|
||||
|
||||
- Added changelog from [@reedy](https://github.com/reedy).
|
||||
|
||||
### Internal
|
||||
|
||||
- Cleaned readme - new organization from previous package from [@grogy](https://github.com/grogy).
|
||||
- Composer: marked package as replacing jakub-onderka/php-console-highlighter from [@grogy](https://github.com/grogy).
|
||||
- Composer: updated dependancies to use new php-parallel-lint organisation from [@grogy](https://github.com/grogy).
|
||||
- Travis: test against PHP 7.4 and nightly from [@jrfnl](https://github.com/jrfnl).
|
||||
- Fixed build script from [@jrfnl](https://github.com/jrfnl).
|
||||
- Added a .gitattributes file from [@reedy](https://github.com/reedy).
|
||||
- Updated installation command from [@cafferata](https://github.com/cafferata).
|
||||
|
21
vendor/php-parallel-lint/php-console-highlighter/LICENSE
vendored
Normal file
21
vendor/php-parallel-lint/php-console-highlighter/LICENSE
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Jakub Onderka
|
||||
|
||||
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.
|
36
vendor/php-parallel-lint/php-console-highlighter/README.md
vendored
Normal file
36
vendor/php-parallel-lint/php-console-highlighter/README.md
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
PHP Console Highlighter
|
||||
=======================
|
||||
|
||||
Highlight PHP code in console (terminal).
|
||||
|
||||
Example
|
||||
-------
|
||||

|
||||
|
||||
Install
|
||||
-------
|
||||
|
||||
Just run the following command to install it:
|
||||
|
||||
composer require --dev php-parallel-lint/php-console-highlighter:"0.*"
|
||||
|
||||
Usage
|
||||
-------
|
||||
```php
|
||||
<?php
|
||||
use JakubOnderka\PhpConsoleColor\ConsoleColor;
|
||||
use JakubOnderka\PhpConsoleHighlighter\Highlighter;
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$highlighter = new Highlighter(new ConsoleColor());
|
||||
|
||||
$fileContent = file_get_contents(__FILE__);
|
||||
echo $highlighter->getWholeFile($fileContent);
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
[](https://packagist.org/packages/php-parallel-lint/php-console-highlighter)
|
||||
[](https://travis-ci.org/php-parallel-lint/PHP-Console-Highlighter)
|
||||
[](https://packagist.org/packages/php-parallel-lint/php-console-highlighter)
|
31
vendor/php-parallel-lint/php-console-highlighter/composer.json
vendored
Normal file
31
vendor/php-parallel-lint/php-console-highlighter/composer.json
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "php-parallel-lint/php-console-highlighter",
|
||||
"description": "Highlight PHP code in terminal",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jakub Onderka",
|
||||
"email": "acci@acci.cz",
|
||||
"homepage": "http://www.acci.cz/"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {"JakubOnderka\\PhpConsoleHighlighter\\": "src/"}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.4.0",
|
||||
"ext-tokenizer": "*",
|
||||
"php-parallel-lint/php-console-color": "~0.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"php-parallel-lint/php-parallel-lint": "~1.0",
|
||||
"php-parallel-lint/php-var-dump-check": "~0.1",
|
||||
"squizlabs/php_codesniffer": "~1.5",
|
||||
"php-parallel-lint/php-code-style": "~1.0"
|
||||
},
|
||||
"replace": {
|
||||
"jakub-onderka/php-console-highlighter": "*"
|
||||
}
|
||||
}
|
263
vendor/php-parallel-lint/php-console-highlighter/src/Highlighter.php
vendored
Normal file
263
vendor/php-parallel-lint/php-console-highlighter/src/Highlighter.php
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
namespace JakubOnderka\PhpConsoleHighlighter;
|
||||
|
||||
use JakubOnderka\PhpConsoleColor\ConsoleColor;
|
||||
|
||||
class Highlighter
|
||||
{
|
||||
const TOKEN_DEFAULT = 'token_default',
|
||||
TOKEN_COMMENT = 'token_comment',
|
||||
TOKEN_STRING = 'token_string',
|
||||
TOKEN_HTML = 'token_html',
|
||||
TOKEN_KEYWORD = 'token_keyword';
|
||||
|
||||
const ACTUAL_LINE_MARK = 'actual_line_mark',
|
||||
LINE_NUMBER = 'line_number';
|
||||
|
||||
/** @var ConsoleColor */
|
||||
private $color;
|
||||
|
||||
/** @var array */
|
||||
private $defaultTheme = array(
|
||||
self::TOKEN_STRING => 'red',
|
||||
self::TOKEN_COMMENT => 'yellow',
|
||||
self::TOKEN_KEYWORD => 'green',
|
||||
self::TOKEN_DEFAULT => 'default',
|
||||
self::TOKEN_HTML => 'cyan',
|
||||
|
||||
self::ACTUAL_LINE_MARK => 'red',
|
||||
self::LINE_NUMBER => 'dark_gray',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param ConsoleColor $color
|
||||
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
|
||||
*/
|
||||
public function __construct(ConsoleColor $color)
|
||||
{
|
||||
$this->color = $color;
|
||||
|
||||
foreach ($this->defaultTheme as $name => $styles) {
|
||||
if (!$this->color->hasTheme($name)) {
|
||||
$this->color->addTheme($name, $styles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @param int $lineNumber
|
||||
* @param int $linesBefore
|
||||
* @param int $linesAfter
|
||||
* @return string
|
||||
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getCodeSnippet($source, $lineNumber, $linesBefore = 2, $linesAfter = 2)
|
||||
{
|
||||
$tokenLines = $this->getHighlightedLines($source);
|
||||
|
||||
$offset = $lineNumber - $linesBefore - 1;
|
||||
$offset = max($offset, 0);
|
||||
$length = $linesAfter + $linesBefore + 1;
|
||||
$tokenLines = array_slice($tokenLines, $offset, $length, $preserveKeys = true);
|
||||
|
||||
$lines = $this->colorLines($tokenLines);
|
||||
|
||||
return $this->lineNumbers($lines, $lineNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return string
|
||||
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getWholeFile($source)
|
||||
{
|
||||
$tokenLines = $this->getHighlightedLines($source);
|
||||
$lines = $this->colorLines($tokenLines);
|
||||
return implode(PHP_EOL, $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return string
|
||||
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getWholeFileWithLineNumbers($source)
|
||||
{
|
||||
$tokenLines = $this->getHighlightedLines($source);
|
||||
$lines = $this->colorLines($tokenLines);
|
||||
return $this->lineNumbers($lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return array
|
||||
*/
|
||||
private function getHighlightedLines($source)
|
||||
{
|
||||
$source = str_replace(array("\r\n", "\r"), "\n", $source);
|
||||
$tokens = $this->tokenize($source);
|
||||
return $this->splitToLines($tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source
|
||||
* @return array
|
||||
*/
|
||||
private function tokenize($source)
|
||||
{
|
||||
$tokens = token_get_all($source);
|
||||
|
||||
$output = array();
|
||||
$currentType = null;
|
||||
$buffer = '';
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (is_array($token)) {
|
||||
switch ($token[0]) {
|
||||
case T_WHITESPACE:
|
||||
break;
|
||||
|
||||
case T_OPEN_TAG:
|
||||
case T_OPEN_TAG_WITH_ECHO:
|
||||
case T_CLOSE_TAG:
|
||||
case T_STRING:
|
||||
case T_VARIABLE:
|
||||
|
||||
// Constants
|
||||
case T_DIR:
|
||||
case T_FILE:
|
||||
case T_METHOD_C:
|
||||
case T_DNUMBER:
|
||||
case T_LNUMBER:
|
||||
case T_NS_C:
|
||||
case T_LINE:
|
||||
case T_CLASS_C:
|
||||
case T_FUNC_C:
|
||||
case T_TRAIT_C:
|
||||
$newType = self::TOKEN_DEFAULT;
|
||||
break;
|
||||
|
||||
case T_COMMENT:
|
||||
case T_DOC_COMMENT:
|
||||
$newType = self::TOKEN_COMMENT;
|
||||
break;
|
||||
|
||||
case T_ENCAPSED_AND_WHITESPACE:
|
||||
case T_CONSTANT_ENCAPSED_STRING:
|
||||
$newType = self::TOKEN_STRING;
|
||||
break;
|
||||
|
||||
case T_INLINE_HTML:
|
||||
$newType = self::TOKEN_HTML;
|
||||
break;
|
||||
|
||||
default:
|
||||
$newType = self::TOKEN_KEYWORD;
|
||||
}
|
||||
} else {
|
||||
$newType = $token === '"' ? self::TOKEN_STRING : self::TOKEN_KEYWORD;
|
||||
}
|
||||
|
||||
if ($currentType === null) {
|
||||
$currentType = $newType;
|
||||
}
|
||||
|
||||
if ($currentType !== $newType) {
|
||||
$output[] = array($currentType, $buffer);
|
||||
$buffer = '';
|
||||
$currentType = $newType;
|
||||
}
|
||||
|
||||
$buffer .= is_array($token) ? $token[1] : $token;
|
||||
}
|
||||
|
||||
if (isset($newType)) {
|
||||
$output[] = array($newType, $buffer);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tokens
|
||||
* @return array
|
||||
*/
|
||||
private function splitToLines(array $tokens)
|
||||
{
|
||||
$lines = array();
|
||||
|
||||
$line = array();
|
||||
foreach ($tokens as $token) {
|
||||
foreach (explode("\n", $token[1]) as $count => $tokenLine) {
|
||||
if ($count > 0) {
|
||||
$lines[] = $line;
|
||||
$line = array();
|
||||
}
|
||||
|
||||
if ($tokenLine === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$line[] = array($token[0], $tokenLine);
|
||||
}
|
||||
}
|
||||
|
||||
$lines[] = $line;
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tokenLines
|
||||
* @return array
|
||||
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
private function colorLines(array $tokenLines)
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($tokenLines as $lineCount => $tokenLine) {
|
||||
$line = '';
|
||||
foreach ($tokenLine as $token) {
|
||||
list($tokenType, $tokenValue) = $token;
|
||||
if ($this->color->hasTheme($tokenType)) {
|
||||
$line .= $this->color->apply($tokenType, $tokenValue);
|
||||
} else {
|
||||
$line .= $tokenValue;
|
||||
}
|
||||
}
|
||||
$lines[$lineCount] = $line;
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $lines
|
||||
* @param null|int $markLine
|
||||
* @return string
|
||||
* @throws \JakubOnderka\PhpConsoleColor\InvalidStyleException
|
||||
*/
|
||||
private function lineNumbers(array $lines, $markLine = null)
|
||||
{
|
||||
end($lines);
|
||||
$lineStrlen = strlen(key($lines) + 1);
|
||||
|
||||
$snippet = '';
|
||||
foreach ($lines as $i => $line) {
|
||||
if ($markLine !== null) {
|
||||
$snippet .= ($markLine === $i + 1 ? $this->color->apply(self::ACTUAL_LINE_MARK, ' > ') : ' ');
|
||||
}
|
||||
|
||||
$snippet .= $this->color->apply(self::LINE_NUMBER, str_pad($i + 1, $lineStrlen, ' ', STR_PAD_LEFT) . '| ');
|
||||
$snippet .= $line . PHP_EOL;
|
||||
}
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user