<?php
if (! function_exists('root')) {
    /**
     * $fileまでのパスをトップからの相対パスで返します。
     *
     * @param string $file
     * @return string
     */
    function root($file)
    {
        $file = str_replace(["'", '"'], "", $file);
        $url =  Request::path();
        if ($url=="/") {
            $pathToRoot = "";
            $url = "";
        }else {
            $pathToRoot = '../';
        }
        $countToRoot = mb_substr_count($url, '/');
        for ($i=0; $i < $countToRoot; $i++) {
            $pathToRoot .= '../';
        }
        $pathToFile = $pathToRoot.$file;
        return "$pathToFile";
    }
}
