ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Index.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\Export\ImportHandler\I\Path\Node\IndexInterface as IndexFilePathNodeInterface;
25 
26 class Index implements IndexFilePathNodeInterface
27 {
29  protected int $index;
31 
32  public function __construct()
33  {
34  $this->index = 0;
35  $this->indexing_from_end_enabled = false;
36  }
37 
38  public function withIndex(int $index): IndexFilePathNodeInterface
39  {
40  $clone = clone $this;
41  $clone->index = $index;
42  return $clone;
43  }
44 
45  public function withComparison(HandlerInterface $comparison): IndexFilePathNodeInterface
46  {
47  $clone = clone $this;
48  $clone->comparison = $comparison;
49  return $clone;
50  }
51 
52  public function withIndexingFromEndEnabled(bool $enabled): IndexFilePathNodeInterface
53  {
54  $clone = clone $this;
55  $clone->indexing_from_end_enabled = $enabled;
56  return $clone;
57  }
58 
59  public function toString(): string
60  {
61  $indexing = '';
62  if (!isset($this->comparison)) {
63  $indexing = $this->indexing_from_end_enabled
64  ? '(last)-' . $this->index
65  : $this->index;
66  } else {
67  $indexing = 'position()' . $this->comparison->toString();
68  }
69  return '[' . $indexing . ']';
70  }
71 
72  public function requiresPathSeparator(): bool
73  {
74  return false;
75  }
76 }
withComparison(HandlerInterface $comparison)
Definition: Index.php:45