Elgg\ViewsService::canonicalizeViewName PHP Метод

canonicalizeViewName() публичный Метод

Takes a view name and returns the canonical name for that view.
public canonicalizeViewName ( string $alias ) : string
$alias string The possibly non-canonical view name.
Результат string The canonical view name.
    public function canonicalizeViewName($alias)
    {
        if (!is_string($alias)) {
            return false;
        }
        $canonical = $alias;
        $extension = pathinfo($canonical, PATHINFO_EXTENSION);
        $hasValidFileExtension = isset(CacheHandler::$extensions[$extension]);
        if (strpos($canonical, "js/") === 0) {
            $canonical = substr($canonical, 3);
            if (!$hasValidFileExtension) {
                $canonical .= ".js";
            }
        } else {
            if (strpos($canonical, "css/") === 0) {
                $canonical = substr($canonical, 4);
                if (!$hasValidFileExtension) {
                    $canonical .= ".css";
                }
            }
        }
        return $canonical;
    }

Usage Example

Пример #1
0
 /**
  * Get the URL for the cached view.
  *
  * Recommended usage is to just pass the entire view name as the first and only arg:
  *
  * ```
  * $blog_js = $simpleCache->getUrl('blog/save_draft.js');
  * $favicon = $simpleCache->getUrl('graphics/favicon.ico');
  * ```
  *
  * For backwards compatibility with older versions of Elgg, you can also pass
  * "js" or "css" as the first arg, with the rest of the view name as the second arg:
  *
  * ```
  * $blog_js = $simpleCache->getUrl('js', 'blog/save_draft.js');
  * ```
  *
  * This automatically registers the view with Elgg's simplecache.
  *
  * @param string $view    The full view name
  * @param string $subview If the first arg is "css" or "js", the rest of the view name
  *
  * @return string
  */
 function getUrl($view, $subview = '')
 {
     // handle `getUrl('js', 'js/blog/save_draft')`
     if (($view === 'js' || $view === 'css') && 0 === strpos($subview, $view . '/')) {
         $view = $subview;
         $subview = '';
     }
     // handle `getUrl('js', 'blog/save_draft')`
     if (!empty($subview)) {
         $view = "{$view}/{$subview}";
     }
     $view = $this->views->canonicalizeViewName($view);
     // should be normalized to canonical form by now: `getUrl('blog/save_draft.js')`
     $this->registerView($view);
     return $this->getRoot() . $view;
 }
All Usage Examples Of Elgg\ViewsService::canonicalizeViewName