-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add prioritisation of main entities
Resolves: #77
- Loading branch information
1 parent
559446e
commit a37297c
Showing
11 changed files
with
458 additions
and
48 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
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
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the "schema" extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brotkrueml\Schema\Manager; | ||
|
||
use Brotkrueml\Schema\Core\Model\TypeInterface; | ||
|
||
/** | ||
* This bag holds the assigned main entity types. Additional types can be added | ||
* via the add() method. The add method returns an array of not prioritised types | ||
* when a type with priority is added. | ||
* | ||
* @internal | ||
*/ | ||
final class MainEntityOfWebPageBag implements \Countable | ||
{ | ||
/** | ||
* @var TypeInterface[] | ||
*/ | ||
private array $types = []; | ||
private bool $isPrioritised = false; | ||
|
||
/** | ||
* @return TypeInterface[] | ||
*/ | ||
public function add(TypeInterface $type, bool $typeIsPrioritised): array | ||
{ | ||
if (! $typeIsPrioritised && $this->isPrioritised) { | ||
return [$type]; | ||
} | ||
|
||
$notPrioritisedTypes = []; | ||
if ($typeIsPrioritised && ! $this->isPrioritised) { | ||
$notPrioritisedTypes = $this->types; | ||
$this->types = []; | ||
$this->isPrioritised = true; | ||
} | ||
|
||
$this->types[] = $type; | ||
|
||
return $notPrioritisedTypes; | ||
} | ||
|
||
/** | ||
* @return TypeInterface[] | ||
*/ | ||
public function getTypes(): array | ||
{ | ||
return $this->types; | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return \count($this->types); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.