栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

FileViewFinder-2.php

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

FileViewFinder-2.php

    protected function findNamedPathView($name)

    {

        list($namespace, $view) = $this->getNamespaceSegments($name);// get this namespace and view

 

        return $this->findInPaths($view, $this->hints[$namespace]);// findInPaths

    }// Get the path to a template with a named path

 

   

    protected function getNamespaceSegments($name)

    {// Get the segments of a template with a named path.

        $segments = explode(static::HINT_PATH_DELIMITER, $name);// get a segments

       // in this segments

 

        if (count($segments) != 2) {

            throw new InvalidArgumentException("View [$name] has an invalid name.");

        }// if the result not like as we think, so threw exception

 

        if (! isset($this->hints[$segments[0]])) {

            throw new InvalidArgumentException("No hint path defined for [{$segments[0]}].");

        }// if no hints , we will throw Exception

 

        return $segments;// return segments

    }

 

   

    protected function findInPaths($name, $paths)

    {//Find the given view in the list of paths.

        foreach ((array) $paths as $path) {

            foreach ($this->getPossibleViewFiles($name) as $file) {

                if ($this->files->exists($viewPath = $path.'/'.$file)) {

                    return $viewPath;// if find it just return

                }

            }// get Possible View Files

        }// loop path

 

        throw new InvalidArgumentException("View [$name] not found.");// default throw Exception

    }

 

   

    protected function getPossibleViewFiles($name)

    {//get Possible View Files

        return array_map(function ($extension) use ($name) {

            return str_replace('.', '/', $name).'.'.$extension;

 

        }, $this->extensions);// two powerfull

    }//Get an array of possible view files.

 

   

    public function addLocation($location)

    {

        $this->paths[] = $location;// add location to path

    }//Add a location to the finder

 

   

    public function addNamespace($namespace, $hints)

    {//add a namespace hint to the finder

        $hints = (array) $hints;// get the array hints

 

        if (isset($this->hints[$namespace])) {

            $hints = array_merge($this->hints[$namespace], $hints);

        }// if it is isset, combine it with new hints

 

        $this->hints[$namespace] = $hints;// then reset it

    }

 

   

    public function prependNamespace($namespace, $hints)

    {//Prepend a namespace hint to the finder.

        $hints = (array) $hints;// get a right hints

 

        if (isset($this->hints[$namespace])) {

            $hints = array_merge($hints, $this->hints[$namespace]);

        }// this is a good way to hints

 

        $this->hints[$namespace] = $hints;// rewrite it

    }

 

   

    public function addExtension($extension)

    {//register an extension with the view finder.

        if (($index = array_search($extension, $this->extensions)) !== false) {

            unset($this->extensions[$index]);

        }// index

 

        array_unshift($this->extensions, $extension);

    }// add function use this system function to add it

 

   

    public function hasHintInformation($name)

    {

        return strpos($name, static::HINT_PATH_DELIMITER) > 0;

    }// Returns whether or not the view specify a hint information.

 

   

    public function getFilesystem()

    {

        return $this->files;// return files

    }// get the filesystem instance.

 

   

    public function getPaths()

    {

        return $this->paths;

    }//get paths

 

   

    public function getHints()

    {

        return $this->hints;

    }//get hints

 

   

    public function getExtensions()

    {

        return $this->extensions;

    }// get extensions

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/229216.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号