Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RelativePathConverter.php
Go to the documentation of this file.
1 <?php
11 
17 {
26  public function convert($nodePath, $relativePath)
27  {
28  $nodePath = trim($nodePath);
30 
31  if (empty($nodePath) || empty($relativePath)) {
32  throw new \InvalidArgumentException('Invalid arguments');
33  }
34 
35  $relativePathParts = explode('/', $relativePath);
36  $pathParts = explode('/', $nodePath);
37 
38  $relativePartsCount = count($relativePathParts);
39  $pathPartsCount = count($pathParts);
40 
41  if ($relativePartsCount === 1 && $pathPartsCount > 1) {
42  $relativePathParts = array_pad($relativePathParts, -$pathPartsCount, '*');
43  }
44 
45  $realPath = [];
46  foreach ($relativePathParts as $index => $path) {
47  if ($path === '*') {
48  if (false == array_key_exists($index, $pathParts)) {
49  throw new \InvalidArgumentException(
50  sprintf('Invalid relative path %s in %s node', $relativePath, $nodePath)
51  );
52  }
53  $path = $pathParts[$index];
54  }
55  $realPath[$index] = $path;
56  }
57 
58  return implode('/', $realPath);
59  }
60 }
$relativePath
Definition: get.php:35
$index
Definition: list.phtml:44