Skip to content

Commit be1f9c9

Browse files
committed
php8 compatibility + stuff
1 parent 7df651b commit be1f9c9

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/php/MsgMeTools.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2-
declare(strict_types = 1);
2+
3+
declare(strict_types=1);
4+
35
namespace MsgMe\tools;
46

57
function isItSafeToOnlyUseFirstFormInputMatch(\DOMDocument $domd, \DOMNode $form = NULL): bool
@@ -18,7 +20,8 @@ function isItSafeToOnlyUseFirstFormInputMatch(\DOMDocument $domd, \DOMNode $form
1820
return true;
1921
}
2022

21-
function return_var_dump(/*...*/){
23+
function return_var_dump(/*...*/)
24+
{
2225
$args = func_get_args();
2326
ob_start();
2427
call_user_func_array('var_dump', $args);
@@ -28,7 +31,7 @@ function return_var_dump(/*...*/){
2831
function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches = false, bool $getElements = true): array
2932
{
3033
// :DOMNodeList?
31-
if (! $getOnlyFirstMatches && ! $getElements) {
34+
if (!$getOnlyFirstMatches && !$getElements) {
3235
throw new \InvalidArgumentException('!$getElements is currently only implemented for $getOnlyFirstMatches (cus im lazy and nobody has written the code yet)');
3336
}
3437
$forms = $domd->getElementsByTagName('form');
@@ -71,11 +74,11 @@ function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches
7174
// echo "inputs with no name are ignored when submitted by mainstream browsers (presumably because of specs)... follow suite?", PHP_EOL;
7275
continue;
7376
}
74-
if (! $isDescendantOf($input, $form) && $form->getAttribute("id") !== '' && $input->getAttribute("form") !== $form->getAttribute("id")) {
77+
if (!$isDescendantOf($input, $form) && $form->getAttribute("id") !== '' && $input->getAttribute("form") !== $form->getAttribute("id")) {
7578
// echo "this input does not belong to this form.", PHP_EOL;
7679
continue;
7780
}
78-
if (! array_key_exists($name, $ret)) {
81+
if (!array_key_exists($name, $ret)) {
7982
$ret[$name] = array(
8083
$input
8184
);
@@ -94,12 +97,12 @@ function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches
9497
$hasName = false;
9598
}
9699
}
97-
if (! $hasName) {
100+
if (!$hasName) {
98101
$parsedForms[] = array(
99102
$inputs
100103
);
101104
} else {
102-
if (! array_key_exists($name, $parsedForms)) {
105+
if (!array_key_exists($name, $parsedForms)) {
103106
$parsedForms[$name] = array(
104107
$inputs
105108
);
@@ -136,7 +139,7 @@ function getDOMDocumentFormInputs(\DOMDocument $domd, bool $getOnlyFirstMatches
136139
function loadHTML_noemptywhitespace(string $html, int $extra_flags = 0, int $exclude_flags = 0): \DOMDocument
137140
{
138141
$flags = LIBXML_HTML_NODEFDTD | LIBXML_NOBLANKS | LIBXML_NONET;
139-
$flags = ($flags | $extra_flags) & ~ $exclude_flags;
142+
$flags = ($flags | $extra_flags) & ~$exclude_flags;
140143

141144
$domd = new \DOMDocument();
142145
$domd->preserveWhiteSpace = false;
@@ -145,11 +148,11 @@ function loadHTML_noemptywhitespace(string $html, int $extra_flags = 0, int $exc
145148
if ($node->hasChildNodes()) {
146149
// Warning: it's important to do it backwards; if you do it forwards, the index for DOMNodeList might become invalidated;
147150
// that's why i don't use foreach() - don't change it (unless you know what you're doing, ofc)
148-
for ($i = $node->childNodes->length - 1; $i >= 0; -- $i) {
151+
for ($i = $node->childNodes->length - 1; $i >= 0; --$i) {
149152
$removeAnnoyingWhitespaceTextNodes($node->childNodes->item($i));
150153
}
151154
}
152-
if ($node->nodeType === XML_TEXT_NODE && ! $node->hasChildNodes() && ! $node->hasAttributes() && ! strlen(trim($node->textContent))) {
155+
if ($node->nodeType === XML_TEXT_NODE && !$node->hasChildNodes() && !$node->hasAttributes() && !strlen(trim($node->textContent))) {
153156
// echo "Removing annoying POS";
154157
// var_dump($node);
155158
$node->parentNode->removeChild($node);
@@ -161,7 +164,7 @@ function loadHTML_noemptywhitespace(string $html, int $extra_flags = 0, int $exc
161164
function loadHTML(string $html, int $extra_flags = 0, int $exclude_flags = 0): \DOMDocument
162165
{
163166
$flags = LIBXML_HTML_NODEFDTD | LIBXML_NONET;
164-
$flags = ($flags | $extra_flags) & ~ $exclude_flags;
167+
$flags = ($flags | $extra_flags) & ~$exclude_flags;
165168

166169
$domd = new \DOMDocument();
167170
//$domd->preserveWhiteSpace = false;
@@ -176,4 +179,13 @@ function prettify_html(string $html): string
176179
$domd->preserveWhiteSpace = false;
177180
$domd->formatOutput = true;
178181
return $domd->saveHTML();
179-
}
182+
}
183+
184+
function dd(...$args): void /*: never */
185+
{
186+
$trace = debug_backtrace(0, 2)[1];
187+
echo "<pre>\ndd() called from ", $trace['file'], ":", $trace['line'], "\n";
188+
var_dump(...$args);
189+
echo "</pre>\n";
190+
die(1);
191+
}

src/php/hhb_.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ function hhb_init()
374374
// ini_set("error_log",__DIR__.DIRECTORY_SEPARATOR.'error_log.php.txt');
375375
assert_options(ASSERT_ACTIVE, 1);
376376
assert_options(ASSERT_WARNING, 0);
377-
assert_options(ASSERT_QUIET_EVAL, 1);
377+
if(PHP_MAJOR_VERSION < 8){
378+
assert_options(ASSERT_QUIET_EVAL, 1);
379+
}
378380
assert_options(ASSERT_CALLBACK, 'hhb_assert_handler');
379381
}
380382

src/php/relays/facebook.relay.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use MsgMe\tools as tools;
88
use function var_dump as d;
9+
use function MsgMe\tools\dd as dd;
910

1011
require_once(__DIR__ . '/../hhb_.inc.php');
1112

@@ -219,6 +220,11 @@ function __destruct()
219220
unset($this->hc); // im trying to force it to hhb_curl::__destruct, this would be the appropriate time.
220221
}
221222

223+
public function _getHc(): \hhb_curl
224+
{
225+
return $this->hc;
226+
}
227+
222228
private function fixRelativeUrl(string $url, string $effective_url): string
223229
{
224230
if (0 === stripos($url, "https:") || 0 === stripos($url, "http:")) {

0 commit comments

Comments
 (0)