src/CarteBlanche/App/Locator.php
public static function locateView($view = null, $remap = true)
    {
        if (empty($view)) return;

        // from views mapping
        if (true===$remap) {
            $views_mapping = CarteBlanche::getContainer()->get('config')->get('views');
            if (!empty($views_mapping) && array_key_exists($view, $views_mapping)) {
                $view = $views_mapping[$view];
                if (false!==($remaped = self::locateView($view, false))) {
                    return self::fallback($view, $remaped);
                }
            }
        }

        $views_dir = DirectoryHelper::slashDirname(CarteBlanche::getPath('views_dir'));

        // from the application
        if ($_f = self::locate($views_dir.$view)) {
            return self::fallback($view, $_f);
        }

        // from a bundle
        if ($_f = self::locate(
            DirectoryHelper::slashDirname(CarteBlanche::getPath('bundles_dir')).$view
        )) {
            return self::fallback($view, $_f);
        }

        // from a tool
        if ($_f = self::locate(
            DirectoryHelper::slashDirname(CarteBlanche::getPath('tools_dir')).$view
        )) {
            return self::fallback($view, $_f);
        }

        // globally
        if ($_f = self::locate($view)) {
            return self::fallback($view, $_f);
        }

        if (!self::locate($view)) {
            $view_file = $views_dir.$view;
        } else {
            $view_file = $view;
        }

        if (!self::locate($view_file)) {
            $_ctrl = CarteBlanche::getContainer()
                ->get('front_controller')->getController();
            if (!empty($_ctrl) && property_exists($_ctrl, 'views_dir')) {
                $subdir     = $_ctrl::$views_dir;
                $view_file  = $views_dir.$subdir.$view;
            }
        }

        if (!self::locate($view_file)) {
            $view_file = $view;
        }

        if (!self::locate($view_file)) {
            $view_file = $view;
        }

        if (self::locate($view_file)) {
            return self::fallback($view_file);
        }

        // not found: try with one of configured extensions
        if (true===$remap) {
            $views_extensions = CarteBlanche::getContainer()->get('config')->get('views.extensions');
            if (!empty($views_extensions)) {
                foreach ($views_extensions as $_ext) {
                    $_extended_view = $view.'.'.$_ext;
                    if ($found = self::locateView($_extended_view, false)) {
                        return self::fallback($_extended_view, $found);
                    }
                }
            }
        }

        return false;
    }
public static function locateView($view = null, $remap = true)
    {
        if (empty($view)) return;

        // from views mapping
        if (true===$remap) {
            $views_mapping = CarteBlanche::getContainer()->get('config')->get('views');
            if (!empty($views_mapping) && array_key_exists($view, $views_mapping)) {
                $view = $views_mapping[$view];
                if (false!==($remaped = self::locateView($view, false))) {
                    return self::fallback($view, $remaped);
                }
            }
        }

        $views_dir = DirectoryHelper::slashDirname(CarteBlanche::getPath('views_dir'));

        // from the application
        if ($_f = self::locate($views_dir.$view)) {
            return self::fallback($view, $_f);
        }

        // from a bundle
        if ($_f = self::locate(
            DirectoryHelper::slashDirname(CarteBlanche::getPath('bundles_dir')).$view
        )) {
            return self::fallback($view, $_f);
        }

        // from a tool
        if ($_f = self::locate(
            DirectoryHelper::slashDirname(CarteBlanche::getPath('tools_dir')).$view
        )) {
            return self::fallback($view, $_f);
        }

        // globally
        if ($_f = self::locate($view)) {
            return self::fallback($view, $_f);
        }

        if (!self::locate($view)) {
            $view_file = $views_dir.$view;
        } else {
            $view_file = $view;
        }

        if (!self::locate($view_file)) {
            $_ctrl = CarteBlanche::getContainer()
                ->get('front_controller')->getController();
            if (!empty($_ctrl) && property_exists($_ctrl, 'views_dir')) {
                $subdir     = $_ctrl::$views_dir;
                $view_file  = $views_dir.$subdir.$view;
            }
        }

        if (!self::locate($view_file)) {
            $view_file = $view;
        }

        if (!self::locate($view_file)) {
            $view_file = $view;
        }

        if (self::locate($view_file)) {
            return self::fallback($view_file);
        }

        // not found: try with one of configured extensions
        if (true===$remap) {
            $views_extensions = CarteBlanche::getContainer()->get('config')->get('views.extensions');
            if (!empty($views_extensions)) {
                foreach ($views_extensions as $_ext) {
                    $_extended_view = $view.'.'.$_ext;
                    if ($found = self::locateView($_extended_view, false)) {
                        return self::fallback($_extended_view, $found);
                    }
                }
            }
        }

        return false;
    }
Search a view file in the views directory and sub-directories

@param string $view The view filename
@param bool $remap
@return mixed FALSE if nothing had been find, the filename otherwise