original_string: public static function url($input, $domain = false)
      {
          if (!trim((string)$input)) {
              $input = '/';
          }
  
          if (Grav::instance()['config']->get('system.absolute_urls', false)) {
              $domain = true;
          }
  
          if (Grav::instance()['uri']->isExternal($input)) {
              return $input;
          }
  
          /** @var Uri $uri */
          $uri = Grav::instance()['uri'];
  
          $root = $uri->rootUrl();
          $input = Utils::replaceFirstOccurrence($root, '', $input);
  
          $input = ltrim((string)$input, '/');
  
          if (Utils::contains((string)$input, '://')) {
              /** @var UniformResourceLocator $locator */
              $locator = Grav::instance()['locator'];
  
              $parts = Uri::parseUrl($input);
  
              if ($parts) {
                  $resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false);
  
                  if (isset($parts['query'])) {
                      $resource = $resource . '?' . $parts['query'];
                  }
              } else {
                  // Not a valid URL (can still be a stream).
                  $resource = $locator->findResource($input, false);
              }
  
  
          } else {
              $resource = $input;
          }
  
  
  
          return rtrim($uri->rootUrl($domain), '/') . '/' . ($resource ?? '');
      }
code: public static function url($input, $domain = false)
      {
          if (!trim((string)$input)) {
              $input = '/';
          }
  
          if (Grav::instance()['config']->get('system.absolute_urls', false)) {
              $domain = true;
          }
  
          if (Grav::instance()['uri']->isExternal($input)) {
              return $input;
          }
  
          /** @var Uri $uri */
          $uri = Grav::instance()['uri'];
  
          $root = $uri->rootUrl();
          $input = Utils::replaceFirstOccurrence($root, '', $input);
  
          $input = ltrim((string)$input, '/');
  
          if (Utils::contains((string)$input, '://')) {
              /** @var UniformResourceLocator $locator */
              $locator = Grav::instance()['locator'];
  
              $parts = Uri::parseUrl($input);
  
              if ($parts) {
                  $resource = $locator->findResource("{$parts['scheme']}://{$parts['host']}{$parts['path']}", false);
  
                  if (isset($parts['query'])) {
                      $resource = $resource . '?' . $parts['query'];
                  }
              } else {
                  // Not a valid URL (can still be a stream).
                  $resource = $locator->findResource($input, false);
              }
  
  
          } else {
              $resource = $input;
          }
  
  
  
          return rtrim($uri->rootUrl($domain), '/') . '/' . ($resource ?? '');
      }
code_tokens: public static function url ( $ input , $ domain = false ) { if ( ! trim ( ( string ) $ input ) ) { $ input = '/' ; } if ( Grav :: instance ( ) [ 'config' ] -> get ( 'system.absolute_urls' , false ) ) { $ domain = true ; } if ( Grav :: instance ( ) [ 'uri' ] -> isExternal ( $ input ) ) { return $ input ; } /** @var Uri $uri */ $ uri = Grav :: instance ( ) [ 'uri' ] ; $ root = $ uri -> rootUrl ( ) ; $ input = Utils :: replaceFirstOccurrence ( $ root , '' , $ input ) ; $ input = ltrim ( ( string ) $ input , '/' ) ; if ( Utils :: contains ( ( string ) $ input , '://' ) ) { /** @var UniformResourceLocator $locator */ $ locator = Grav :: instance ( ) [ 'locator' ] ; $ parts = Uri :: parseUrl ( $ input ) ; if ( $ parts ) { $ resource = $ locator -> findResource ( "{$parts['scheme']}://{$parts['host']}{$parts['path']}" , false ) ; if ( isset ( $ parts [ 'query' ] ) ) { $ resource = $ resource . '?' . $ parts [ 'query' ] ; } } else { // Not a valid URL (can still be a stream). $ resource = $ locator -> findResource ( $ input , false ) ; } } else { $ resource = $ input ; } return rtrim ( $ uri -> rootUrl ( $ domain ) , '/' ) . '/' . ( $ resource ?? '' ) ; }
docstring: Simple helper method to make getting a Grav URL easier
  
  @param string $input
  @param bool $domain
  @return bool|null|string
docstring_tokens: Simple helper method to make getting a Grav URL easier