Skip to content

Commit e21e514

Browse files
authored
Merge pull request #137 from iMattPro/phpbb4
Forcing backwards compatibility using Legacy and PHP8 classes
2 parents dc0e9ef + 9e72253 commit e21e514

6 files changed

Lines changed: 561 additions & 458 deletions

File tree

src/Output/HtmlOutput.php

Lines changed: 14 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -9,200 +9,18 @@
99
*/
1010
namespace Phpbb\Epv\Output;
1111

12-
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
13-
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
14-
use Symfony\Component\Console\Output\OutputInterface;
15-
16-
class HtmlOutput implements OutputInterface
17-
{
18-
const TYPE_HTML = 1;
19-
const TYPE_BBCODE = 2;
20-
21-
private $buffer = "";
22-
private $type;
23-
24-
/**
25-
* @param int $type Output type (HTML or BBCode)
26-
*/
27-
public function __construct($type = self::TYPE_HTML)
28-
{
29-
$this->type = $type;
30-
}
31-
32-
/**
33-
* Writes a message to the output.
34-
*
35-
* @param string|array $messages The message as an array of lines or a single string
36-
* @param bool $newline Whether to add a newline
37-
* @param int $type The type of output (one of the OUTPUT constants)
38-
*
39-
* @throws \InvalidArgumentException When unknown output type is given
40-
*
41-
* @api
42-
*/
43-
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
44-
{
45-
if (!is_array($messages))
46-
{
47-
$messages = array($messages);
48-
}
49-
50-
foreach ($messages as $message)
51-
{
52-
$this->buffer .= $this->parse($message);
53-
if ($newline)
54-
{
55-
$this->buffer .= "\n";
56-
}
57-
}
58-
}
59-
60-
/**
61-
* Writes a message to the output and adds a newline at the end.
62-
*
63-
* @param string|array $messages The message as an array of lines of a single string
64-
* @param int $type The type of output (one of the OUTPUT constants)
65-
*
66-
* @throws \InvalidArgumentException When unknown output type is given
67-
*
68-
* @api
69-
*/
70-
public function writeln($messages, $type = self::OUTPUT_NORMAL)
71-
{
72-
$this->write($messages, true, $type);
73-
}
74-
75-
/**
76-
* Sets the verbosity of the output.
77-
*
78-
* @param int $level The level of verbosity (one of the VERBOSITY constants)
79-
*
80-
* @api
81-
*/
82-
public function setVerbosity($level)
83-
{
84-
85-
}
86-
87-
/**
88-
* Gets the current verbosity of the output.
89-
*
90-
* @return int The current level of verbosity (one of the VERBOSITY constants)
91-
*
92-
* @api
93-
*/
94-
public function getVerbosity(): int
95-
{
96-
97-
}
98-
99-
/**
100-
* Sets the decorated flag.
101-
*
102-
* @param bool $decorated Whether to decorate the messages
103-
*
104-
* @api
105-
*/
106-
public function setDecorated($decorated)
107-
{
108-
109-
}
110-
111-
/**
112-
* Gets the decorated flag.
113-
*
114-
* @return bool true if the output will decorate messages, false otherwise
115-
*
116-
* @api
117-
*/
118-
public function isDecorated(): bool
119-
{
120-
121-
}
122-
123-
/**
124-
* Sets output formatter.
125-
*
126-
* @param OutputFormatterInterface $formatter
127-
*
128-
* @api
129-
*/
130-
public function setFormatter(OutputFormatterInterface $formatter)
131-
{
132-
133-
}
134-
135-
/**
136-
* Returns current output formatter instance.
137-
*
138-
* @return OutputFormatterInterface
139-
*
140-
* @api
141-
*/
142-
public function getFormatter(): OutputFormatterInterface
143-
{
144-
145-
}
146-
147-
public function getBuffer()
148-
{
149-
if ($this->type == self::TYPE_HTML)
150-
{
151-
$formatter = new OutputFormatter(true);
152-
153-
$convertor = new AnsiToHtmlConverter();
154-
155-
return nl2br($convertor->convert($formatter->format($this->buffer)));
156-
}
157-
158-
return $this->buffer;
159-
}
160-
161-
/**
162-
* Parse the code from the CLI to html.
163-
*
164-
* @param $message
165-
*
166-
* @return mixed Parsed message
167-
*/
168-
private function parse($message)
169-
{
170-
return $message;
171-
}
172-
173-
/**
174-
* Returns whether verbosity is quiet (-q).
175-
*
176-
* @return bool true if verbosity is set to VERBOSITY_QUIET, false otherwise
177-
*/
178-
public function isQuiet(): bool
179-
{
180-
}
181-
182-
/**
183-
* Returns whether verbosity is verbose (-v).
184-
*
185-
* @return bool true if verbosity is set to VERBOSITY_VERBOSE, false otherwise
186-
*/
187-
public function isVerbose(): bool
188-
{
189-
}
190-
191-
/**
192-
* Returns whether verbosity is very verbose (-vv).
193-
*
194-
* @return bool true if verbosity is set to VERBOSITY_VERY_VERBOSE, false otherwise
195-
*/
196-
public function isVeryVerbose(): bool
197-
{
198-
}
199-
200-
/**
201-
* Returns whether verbosity is debug (-vvv).
202-
*
203-
* @return bool true if verbosity is set to VERBOSITY_DEBUG, false otherwise
204-
*/
205-
public function isDebug(): bool
206-
{
207-
}
12+
// Runtime selection of HtmlOutput implementation based on PHP version and Symfony interface
13+
if (PHP_VERSION_ID >= 80000) {
14+
// Check if Symfony interface has union types (Symfony 7+)
15+
$reflection = new \ReflectionMethod('\Symfony\Component\Console\Output\OutputInterface', 'write');
16+
$parameters = $reflection->getParameters();
17+
$hasUnionTypes = $parameters[0]->getType() && $parameters[0]->getType()->__toString() === 'string|iterable';
18+
19+
if ($hasUnionTypes) {
20+
class_alias('\Phpbb\Epv\Output\HtmlOutputPhp8', '\Phpbb\Epv\Output\HtmlOutput');
21+
} else {
22+
class_alias('\Phpbb\Epv\Output\HtmlOutputLegacy', '\Phpbb\Epv\Output\HtmlOutput');
23+
}
24+
} else {
25+
class_alias('\Phpbb\Epv\Output\HtmlOutputLegacy', '\Phpbb\Epv\Output\HtmlOutput');
20826
}

src/Output/HtmlOutputLegacy.php

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
*
4+
* EPV :: The phpBB Forum Extension Pre Validator.
5+
*
6+
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
namespace Phpbb\Epv\Output;
11+
12+
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
13+
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
class HtmlOutputLegacy implements OutputInterface
17+
{
18+
const TYPE_HTML = 1;
19+
const TYPE_BBCODE = 2;
20+
21+
private $buffer = "";
22+
private $type;
23+
24+
public function __construct($type = self::TYPE_HTML)
25+
{
26+
$this->type = $type;
27+
}
28+
29+
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
30+
{
31+
if (!is_array($messages))
32+
{
33+
$messages = array($messages);
34+
}
35+
36+
foreach ($messages as $message)
37+
{
38+
$this->buffer .= $this->parse($message);
39+
if ($newline)
40+
{
41+
$this->buffer .= "\n";
42+
}
43+
}
44+
}
45+
46+
public function writeln($messages, $type = self::OUTPUT_NORMAL)
47+
{
48+
$this->write($messages, true, $type);
49+
}
50+
51+
public function setVerbosity($level)
52+
{
53+
}
54+
55+
public function getVerbosity()
56+
{
57+
}
58+
59+
public function setDecorated($decorated)
60+
{
61+
}
62+
63+
public function isDecorated()
64+
{
65+
}
66+
67+
public function setFormatter(OutputFormatterInterface $formatter)
68+
{
69+
}
70+
71+
public function getFormatter()
72+
{
73+
}
74+
75+
public function getBuffer()
76+
{
77+
if ($this->type == self::TYPE_HTML)
78+
{
79+
$formatter = new OutputFormatter(true);
80+
$convertor = new AnsiToHtmlConverter();
81+
return nl2br($convertor->convert($formatter->format($this->buffer)));
82+
}
83+
return $this->buffer;
84+
}
85+
86+
private function parse($message)
87+
{
88+
return $message;
89+
}
90+
91+
public function isQuiet()
92+
{
93+
}
94+
95+
public function isVerbose()
96+
{
97+
}
98+
99+
public function isVeryVerbose()
100+
{
101+
}
102+
103+
public function isDebug()
104+
{
105+
}
106+
}

0 commit comments

Comments
 (0)