ITPub博客

首页 > IT职业 > IT生活 > FileLoader.php

FileLoader.php

IT生活 作者:huntwu 时间:2021-09-09 09:16:11 0 删除 编辑

 

namespace IlluminateTranslation;

 

use IlluminateFilesystemFilesystem;

 

class FileLoader implements LoaderInterface

{// FileLoader implements Loader Interface

   

    protected $files;//The filesystem instance.

 

   

    protected $path;//The default path for the loader.

 

   

    protected $hints = [];// All of the namespace hints.

 

   

    public function __construct(Filesystem $files, $path)

    {

        $this->path = $path;// path

        $this->files = $files;// files

    }//Create a new file loader instance.

 

   

    public function load($locale, $group, $namespace = null)

    {

        if (is_null($namespace) || $namespace == '*') {

            return $this->loadPath($this->path, $locale, $group);// two type,one is loadPath

        }//locale group and namespace

 

        return $this->loadNamespaced($locale, $group, $namespace);// Load Namespace

    }//Load the messages for the given locale.

 

   

    protected function loadNamespaced($locale, $group, $namespace)

    {//Load a namespaced translation group

        if (isset($this->hints[$namespace])) {// if it is set

            $lines = $this->loadPath($this->hints[$namespace], $locale, $group);//get this line

 

            return $this->loadNamespaceOverrides($lines, $locale, $group, $namespace);// return a wrap function

        }

 

        return [];//default null

    }

 

   

    protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace)

    {//another load space

        $file = "{$this->path}/vendor/{$namespace}/{$locale}/{$group}.php";//get this file

 

        if ($this->files->exists($file)) {// if it is exists

            return array_replace_recursive($lines, $this->files->getRequire($file));

        }// return this thing

 

        return $lines;// return line

    }

 

   

    protected function loadPath($path, $locale, $group)

    {

        if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) {

            return $this->files->getRequire($full);

        }// like include file by path ,the full is the full path

 

        return [];// null

    }//load a locale from a given path

 

   

    public function addNamespace($namespace, $hint)

    {

        $this->hints[$namespace] = $hint;

    }// addNamespace

   //Add a new namespace to the loader

}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2387/viewspace-2801579/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-15

  • 博文量
    94
  • 访问量
    737