-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpArrayVsObjectBenchmark\Classes; | ||
|
||
use function spl_object_id; | ||
|
||
class ChainPlainClass802 extends PrinstChain802 { | ||
public function __construct( | ||
public ?string $info = null, | ||
public ?string $first = null, | ||
public ?int $second = null, | ||
?self $previous = null | ||
) { | ||
parent::__construct($previous); | ||
} | ||
|
||
public function __debugInfo(): array | ||
{ | ||
return [ | ||
'info' => $this->info, | ||
'first' => $this->first, | ||
'second' => $this->second, | ||
'object id' => spl_object_id($this), | ||
'previous object id' => $this->previous ? spl_object_id($this->previous) : null, | ||
'next object id' => $this->next ? spl_object_id($this->next) : null, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php /** @noinspection PhpUnusedPrivateFieldInspection */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpArrayVsObjectBenchmark\Classes; | ||
|
||
use IteratorAggregate; | ||
|
||
abstract class PrinstChain802 implements IteratorAggregate | ||
{ | ||
private ?PrinstChain802Iterator $iterator = null; | ||
protected ?self $next = null; | ||
|
||
|
||
/** | ||
* @param static|null $previous | ||
*/ | ||
public function __construct(protected ?self $previous = null) | ||
{ | ||
$this->previous?->setNext($this); | ||
$this->iterator?->append($this); | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
$this->previous?->setNext($this->next); | ||
$this->next?->setPrevious($this->previous); | ||
|
||
if ($current = ($this->previous ?? $this->next)) { | ||
$this->iterator?->recreate($current); | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getIterator(): PrinstChain802Iterator | ||
{ | ||
if (!$this->iterator) { | ||
while ($element = ($element ?? $this)->getPrevious()) { | ||
$this->iterator = $element->iterator; | ||
|
||
if ($this->iterator) { | ||
return $this->iterator; | ||
} | ||
} | ||
|
||
while ($element = ($element ?? $this)->getNext()) { | ||
$this->iterator = $element->iterator; | ||
|
||
if ($this->iterator) { | ||
return $this->iterator; | ||
} | ||
} | ||
|
||
$this->iterator = new PrinstChain802Iterator($this); | ||
} | ||
|
||
return $this->iterator; | ||
} | ||
|
||
public function getNext(): ?static | ||
{ | ||
return $this->next; | ||
} | ||
|
||
public function setNext(?self $next, bool $chainThisToNextPrevious = true): ?static | ||
{ | ||
$this->next = $next; | ||
|
||
if ($chainThisToNextPrevious && $this !== $next?->getPrevious()) { | ||
$this->next?->setPrevious($this); | ||
} | ||
|
||
// ToDo: chain old next to him second previous if exists | ||
|
||
return $this; | ||
} | ||
|
||
public function getPrevious(): ?static | ||
{ | ||
return $this->previous; | ||
} | ||
|
||
public function setPrevious(?self $previous, bool $chainThisToPreviousNext = true): ?static | ||
{ | ||
$this->previous = $previous; | ||
|
||
if ($chainThisToPreviousNext && $this !== $previous?->getNext()) { | ||
$this->previous?->setNext($this); | ||
} | ||
|
||
// ToDo: chain old previous to him second next if exists | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.