public function buildRelativePath($path)
    {
        if (is_null($path)) return $path;

        $relativePath = str_replace(array(realpath($this->publicPath), '\\'), array('', '/'), $path);

        // If the asset is not a remote asset then we'll trim the relative path even further to remove
        // any unnecessary leading or trailing slashes. This will leave us with a nice relative path.
        if ( ! starts_with($path, '//') and ! (bool) filter_var($path, FILTER_VALIDATE_URL))
        {
            $relativePath = trim($relativePath, '/');

            // If the given path is the same as the built relative path then the asset appears to be
            // outside of the public directory. If this is the case then we'll use an MD5 hash of
            // the assets path as the relative path to the asset.
            if (trim(str_replace('\\', '/', $path), '/') == trim($relativePath, '/'))
            {
                $path = pathinfo($path);

                $relativePath = md5($path['dirname']).'/'.$path['basename'];
            }
        }

        return $relativePath;
    }