original_string: public static function getPagePathFromToken($path, PageInterface $page = null)
      {
          $path_parts = pathinfo($path);
          $grav       = Grav::instance();
  
          $basename = '';
          if (isset($path_parts['extension'])) {
              $basename = '/' . $path_parts['basename'];
              $path     = rtrim($path_parts['dirname'], ':');
          }
  
          $regex = '/(@self|self@)|((?:@page|page@):(?:.*))|((?:@theme|theme@):(?:.*))/';
          preg_match($regex, $path, $matches);
  
          if ($matches) {
              if ($matches[1]) {
                  if (null === $page) {
                      throw new \RuntimeException('Page not available for this self@ reference');
                  }
              } elseif ($matches[2]) {
                  // page@
                  $parts = explode(':', $path);
                  $route = $parts[1];
                  $page  = $grav['page']->find($route);
              } elseif ($matches[3]) {
                  // theme@
                  $parts = explode(':', $path);
                  $route = $parts[1];
                  $theme = str_replace(ROOT_DIR, '', $grav['locator']->findResource("theme://"));
  
                  return $theme . $route . $basename;
              }
          } else {
              return $path . $basename;
          }
  
          if (!$page) {
              throw new \RuntimeException('Page route not found: ' . $path);
          }
  
          $path = str_replace($matches[0], rtrim($page->relativePagePath(), '/'), $path);
  
          return $path . $basename;
      }
code: public static function getPagePathFromToken($path, PageInterface $page = null)
      {
          $path_parts = pathinfo($path);
          $grav       = Grav::instance();
  
          $basename = '';
          if (isset($path_parts['extension'])) {
              $basename = '/' . $path_parts['basename'];
              $path     = rtrim($path_parts['dirname'], ':');
          }
  
          $regex = '/(@self|self@)|((?:@page|page@):(?:.*))|((?:@theme|theme@):(?:.*))/';
          preg_match($regex, $path, $matches);
  
          if ($matches) {
              if ($matches[1]) {
                  if (null === $page) {
                      throw new \RuntimeException('Page not available for this self@ reference');
                  }
              } elseif ($matches[2]) {
                  // page@
                  $parts = explode(':', $path);
                  $route = $parts[1];
                  $page  = $grav['page']->find($route);
              } elseif ($matches[3]) {
                  // theme@
                  $parts = explode(':', $path);
                  $route = $parts[1];
                  $theme = str_replace(ROOT_DIR, '', $grav['locator']->findResource("theme://"));
  
                  return $theme . $route . $basename;
              }
          } else {
              return $path . $basename;
          }
  
          if (!$page) {
              throw new \RuntimeException('Page route not found: ' . $path);
          }
  
          $path = str_replace($matches[0], rtrim($page->relativePagePath(), '/'), $path);
  
          return $path . $basename;
      }
code_tokens: public static function getPagePathFromToken ( $ path , PageInterface $ page = null ) { $ path_parts = pathinfo ( $ path ) ; $ grav = Grav :: instance ( ) ; $ basename = '' ; if ( isset ( $ path_parts [ 'extension' ] ) ) { $ basename = '/' . $ path_parts [ 'basename' ] ; $ path = rtrim ( $ path_parts [ 'dirname' ] , ':' ) ; } $ regex = '/(@self|self@)|((?:@page|page@):(?:.*))|((?:@theme|theme@):(?:.*))/' ; preg_match ( $ regex , $ path , $ matches ) ; if ( $ matches ) { if ( $ matches [ 1 ] ) { if ( null === $ page ) { throw new \ RuntimeException ( 'Page not available for this self@ reference' ) ; } } elseif ( $ matches [ 2 ] ) { // page@ $ parts = explode ( ':' , $ path ) ; $ route = $ parts [ 1 ] ; $ page = $ grav [ 'page' ] -> find ( $ route ) ; } elseif ( $ matches [ 3 ] ) { // theme@ $ parts = explode ( ':' , $ path ) ; $ route = $ parts [ 1 ] ; $ theme = str_replace ( ROOT_DIR , '' , $ grav [ 'locator' ] -> findResource ( "theme://" ) ) ; return $ theme . $ route . $ basename ; } } else { return $ path . $ basename ; } if ( ! $ page ) { throw new \ RuntimeException ( 'Page route not found: ' . $ path ) ; } $ path = str_replace ( $ matches [ 0 ] , rtrim ( $ page -> relativePagePath ( ) , '/' ) , $ path ) ; return $ path . $ basename ; }
docstring: Get's path based on a token
  
  @param string $path
  @param PageInterface|null $page
  @return string
  @throws \RuntimeException
docstring_tokens: Get s path based on a token