继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

FileViewFinder-2.php

慕莱坞森
关注TA
已关注
手记 304
粉丝 36
获赞 146

/**

     * Get the path to a template with a named path.

     *

     * @param  string  $name

     * @return string

     */

    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

 

    /**

     * Get the segments of a template with a named path.

     *

     * @param  string  $name

     * @return array

     *

     * @throws \InvalidArgumentException

     */

    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

    }

 

    /**

     * Find the given view in the list of paths.

     *

     * @param  string  $name

     * @param  array   $paths

     * @return string

     *

     * @throws \InvalidArgumentException

     */

    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

    }

 

    /**

     * Get an array of possible view files.

     *

     * @param  string  $name

     * @return array

     */

    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.

 

    /**

     * Add a location to the finder.

     *

     * @param  string  $location

     * @return void

     */

    public function addLocation($location)

    {

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

    }//Add a location to the finder

 

    /**

     * Add a namespace hint to the finder.

     *

     * @param  string  $namespace

     * @param  string|array  $hints

     * @return void

     */

    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

    }

 

    /**

     * Prepend a namespace hint to the finder.

     *

     * @param  string  $namespace

     * @param  string|array  $hints

     * @return void

     */

    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

    }

 

    /**

     * Register an extension with the view finder.

     *

     * @param  string  $extension

     * @return void

     */

    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

 

    /**

     * Returns whether or not the view specify a hint information.

     *

     * @param  string  $name

     * @return bool

     */

    public function hasHintInformation($name)

    {

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

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

 

    /**

     * Get the filesystem instance.

     *

     * @return \Illuminate\Filesystem\Filesystem

     */

    public function getFilesystem()

    {

        return $this->files;// return files

    }// get the filesystem instance.

 

    /**

     * Get the active view paths.

     *

     * @return array

     */

    public function getPaths()

    {

        return $this->paths;

    }//get paths

 

    /**

     * Get the namespace to file path hints.

     *

     * @return array

     */

    public function getHints()

    {

        return $this->hints;

    }//get hints

 

    /**

     * Get registered extensions.

     *

     * @return array

     */

    public function getExtensions()

    {

        return $this->extensions;

    }// get extensions

}

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP