[李景山php]每天laravel-20161027|FileLoader.php

<?php

namespace Illuminate\Translation;

use Illuminate\Filesystem\Filesystem;

class FileLoader implements LoaderInterface
{// FileLoader implements Loader Interface
    /**
     * The filesystem instance.
     *
     * @var \Illuminate\Filesystem\Filesystem
     */
    protected $files;//The filesystem instance.

    /**
     * The default path for the loader.
     *
     * @var string
     */
    protected $path;//The default path for the loader.

    /**
     * All of the namespace hints.
     *
     * @var array
     */
    protected $hints = [];// All of the namespace hints.

    /**
     * Create a new file loader instance.
     *
     * @param  \Illuminate\Filesystem\Filesystem  $files
     * @param  string  $path
     * @return void
     */
    public function __construct(Filesystem $files, $path)
    {
        $this->path = $path;// path
        $this->files = $files;// files
    }//Create a new file loader instance.

    /**
     * Load the messages for the given locale.
     *
     * @param  string  $locale
     * @param  string  $group
     * @param  string  $namespace
     * @return array
     */
    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.

    /**
     * Load a namespaced translation group.
     *
     * @param  string  $locale
     * @param  string  $group
     * @param  string  $namespace
     * @return array
     */
    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
    }

    /**
     * Load a local namespaced translation group for overrides.
     *
     * @param  array  $lines
     * @param  string  $locale
     * @param  string  $group
     * @param  string  $namespace
     * @return array
     */
    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
    }

    /**
     * Load a locale from a given path.
     *
     * @param  string  $path
     * @param  string  $locale
     * @param  string  $group
     * @return array
     */
    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

    /**
     * Add a new namespace to the loader.
     *
     * @param  string  $namespace
     * @param  string  $hint
     * @return void
     */
    public function addNamespace($namespace, $hint)
    {
        $this->hints[$namespace] = $hint;
    }// addNamespace
    //Add a new namespace to the loader
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值