ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
MaxNestingPathGenerator.php
Go to the documentation of this file.
1 <?php declare(strict_types=1);
2 
4 
6 
13 {
14  private const MAX_NESTING_256 = 256;
15  private const MAX_NESTING_4096 = 4096;
16  private const MAX_NESTING_65536 = 65536;
17 
18  protected $max_nesting = self::MAX_NESTING_4096;
22  protected $splitter = 3;
26  protected $limited_layers = 3;
27 
31  public function __construct()
32  {
33  switch ($this->max_nesting) {
34  case self::MAX_NESTING_4096:
35  $this->splitter = 3;
36  break;
37  case self::MAX_NESTING_65536:
38  $this->splitter = 4;
39  break;
40  case self::MAX_NESTING_256:
41  default:
42  $this->splitter = 2;
43  break;
44  }
45  }
46 
47  public function getPathFor(ResourceIdentification $i) : string
48  {
49  $splitted = str_split(str_replace("-", "", $i->serialize()), $this->splitter);
50 
51  $first_part = array_slice($splitted, 0, $this->limited_layers + 1);
52  $second_part = array_slice($splitted, $this->limited_layers + 1);
53 
54  return implode("/", $first_part) . implode("", $second_part);
55  }
56 
57  public function getIdentificationFor(string $path) : ResourceIdentification
58  {
59  $str = str_replace("/", "", $path);
60 
61  $p1 = substr($str, 0, 8);
62  $p2 = substr($str, 8, 4);
63  $p3 = substr($str, 12, 4);
64  $p4 = substr($str, 16, 4);
65  $p5 = substr($str, 20, 12);
66 
67  return new ResourceIdentification("$p1-$p2-$p3-$p4-$p5");
68  }
69 
70 }
$i
Definition: metadata.php:24