Skip to content

Commit

Permalink
ENH PHP 8.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 14, 2022
1 parent bf440e4 commit e644ef7
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"composer/installers": "^2.2",
"guzzlehttp/guzzle": "^7.5.0",
"guzzlehttp/psr7": "^2.4.0",
"embed/embed": "^4.4.4",
"embed/embed": "^4.4.7",
"league/csv": "^9.8.0",
"m1/env": "^2.2.0",
"monolog/monolog": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Control/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public function match($pattern, $shiftOnSuccess = false)
$shiftCount = sizeof($patternParts ?? []);
$remaining = count($this->dirParts ?? []) - $i;
for ($j = 1; $j <= $remaining; $j++) {
$arguments["$${j}"] = $this->dirParts[$j + $i - 1];
$arguments['$' . $j] = $this->dirParts[$j + $i - 1];
}
$patternParts = array_merge($patternParts, array_keys($arguments ?? []));
break;
Expand Down
2 changes: 0 additions & 2 deletions src/Dev/Constraint/SSListContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class SSListContains extends Constraint implements TestOnly

public function __construct(array $matches)
{
$this->exporter = new SSListExporter();

$this->matches = $matches;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Dev/Constraint/SSListContainsOnlyMatchingItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class SSListContainsOnlyMatchingItems extends Constraint implements TestOnly

public function __construct($match)
{
$this->exporter = new SSListExporter();

$this->constraint = new ViewableDataContains($match);
$this->match = $match;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Dev/SapphireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ abstract class SapphireTest extends TestCase implements TestOnly
*/
protected static $tempDB = null;

protected FixtureFactory|bool $fixtureFactory;

/**
* @return TempDatabase
*/
Expand Down
2 changes: 2 additions & 0 deletions src/ORM/Connect/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MySQLDatabase extends Database implements TransactionManager
*/
private $transactionManager = null;

private int $transactionNesting = 0;

/**
* Default collation
*
Expand Down
1 change: 0 additions & 1 deletion src/ORM/Connect/MySQLStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function __construct($statement, $metadata)
public function __destruct()
{
$this->statement->close();
$this->currentRecord = false;
}

/**
Expand Down
23 changes: 17 additions & 6 deletions src/View/ViewableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class ViewableData implements IteratorAggregate
*/
private static $casting_cache = [];

/**
* Acts as a PHP 8.2+ compliant replacement for dynamic properties
*/
private array $data = [];

// -----------------------------------------------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -191,7 +196,7 @@ public function getFailover()
*/
public function hasField($field)
{
return property_exists($this, $field ?? '');
return property_exists($this, $field) || isset($this->data[$field]);
}

/**
Expand All @@ -202,7 +207,10 @@ public function hasField($field)
*/
public function getField($field)
{
return $this->$field;
if (property_exists($this, $field)) {
return $this->$field;
}
return $this->data[$field];
}

/**
Expand All @@ -215,7 +223,10 @@ public function getField($field)
public function setField($field, $value)
{
$this->objCacheClear();
$this->$field = $value;
if (property_exists($this, $field)) {
$this->$field = $value;
}
$this->data[$field] = $value;
return $this;
}

Expand Down Expand Up @@ -509,14 +520,14 @@ public function obj($fieldName, $arguments = [], $cache = false, $cacheName = nu
* A simple wrapper around {@link ViewableData::obj()} that automatically caches the result so it can be used again
* without re-running the method.
*
* @param string $field
* @param string $fieldName
* @param array $arguments
* @param string $identifier an optional custom cache identifier
* @return Object|DBField
*/
public function cachedCall($field, $arguments = [], $identifier = null)
public function cachedCall($fieldName, $arguments = [], $identifier = null)
{
return $this->obj($field, $arguments, true, $identifier);
return $this->obj($fieldName, $arguments, true, $identifier);
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/View/ViewableData_Customised.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,26 @@ public function hasMethod($method)
return $this->customised->hasMethod($method) || $this->original->hasMethod($method);
}

public function cachedCall($field, $arguments = null, $identifier = null)
public function cachedCall($fieldName, $arguments = null, $identifier = null)
{
if ($this->customised->hasMethod($field) || $this->customised->hasField($field)) {
return $this->customised->cachedCall($field, $arguments, $identifier);
if ($this->customisedHas($fieldName)) {
return $this->customised->cachedCall($fieldName, $arguments, $identifier);
}
return $this->original->cachedCall($field, $arguments, $identifier);
return $this->original->cachedCall($fieldName, $arguments, $identifier);
}

public function obj($fieldName, $arguments = null, $cache = false, $cacheName = null)
{
if ($this->customised->hasField($fieldName) || $this->customised->hasMethod($fieldName)) {
if ($this->customisedHas($fieldName)) {
return $this->customised->obj($fieldName, $arguments, $cache, $cacheName);
}
return $this->original->obj($fieldName, $arguments, $cache, $cacheName);
}

private function customisedHas(string $fieldName): bool
{
return property_exists($this->customised, $fieldName) ||
$this->customised->hasField($fieldName) ||
$this->customised->hasMethod($fieldName);
}
}
19 changes: 9 additions & 10 deletions tests/php/Forms/GridField/GridFieldFilterHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,17 @@ public function testHandleActionReset()
public function testGetSearchForm()
{
$searchForm = $this->component->getSearchForm($this->gridField);

$this->assertTrue($searchForm instanceof Form);
$this->assertEquals('Search__q', $searchForm->fields[0]->Name);
$this->assertEquals('Search__Name', $searchForm->fields[1]->Name);
$this->assertEquals('Search__City', $searchForm->fields[2]->Name);
$this->assertEquals('Search__Cheerleader__Hat__Colour', $searchForm->fields[3]->Name);
$fields = $searchForm->Fields()->toArray();
$this->assertEquals('Search__q', $fields[0]->Name);
$this->assertEquals('Search__Name', $fields[1]->Name);
$this->assertEquals('Search__City', $fields[2]->Name);
$this->assertEquals('Search__Cheerleader__Hat__Colour', $fields[3]->Name);
$this->assertEquals('TeamsSearchForm', $searchForm->Name);
$this->assertEquals('cms-search-form', $searchForm->extraClasses['cms-search-form']);

foreach ($searchForm->fields as $field) {
$this->assertEquals('stacked', $field->extraClasses['stacked']);
$this->assertEquals('no-change-track', $field->extraClasses['no-change-track']);
$this->assertTrue($searchForm->hasExtraClass('cms-search-form'));
foreach ($fields as $field) {
$this->assertTrue($field->hasExtraClass('stacked'));
$this->assertTrue($field->hasExtraClass('no-change-track'));
}
}

Expand Down
7 changes: 7 additions & 0 deletions thirdparty/php-peg/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
* the bracket if a failed match + restore has moved the current position backwards - so we have to check that too.
*/
class ParserRegexp {

public $parser;
public $rx;
public $matches;
public $match_pos;
public $check_pos;

function __construct( $parser, $rx ) {
$this->parser = $parser ;
$this->rx = $rx . 'Sx' ;
Expand Down

0 comments on commit e644ef7

Please sign in to comment.