每天laravel-20160708|Repository

<?php

namespace Illuminate\Config;

use ArrayAccess;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Config\Repository as ConfigContract;
// a knowledge library ,that is a namespace
class Repository implements ArrayAccess, ConfigContract
{
    /**
     * All of the configuration items.
     *
     * @var array
     */
    protected $items = [];// all of the configuration items.

    /**
     * Create a new configuration repository.
     *
     * @param  array  $items
     * @return void
     */
    public function __construct(array $items = [])
    {
        $this->items = $items;
    }// a construct function about the repository.
   // create a new configuration repository

    /**
     * Determine if the given configuration value exists.
     *
     * @param  string  $key
     * @return bool
     */
    public function has($key)
    {
        return Arr::has($this->items, $key);
    }// use a static method

    /**
     * Get the specified configuration value.
     *
     * @param  string  $key
     * @param  mixed   $default
     * @return mixed
     */
    public function get($key, $default = null)
    {
        return Arr::get($this->items, $key, $default);
    }// Get the specified configuration value.

    /**
     * Set a given configuration value.
     *
     * @param  array|string  $key
     * @param  mixed   $value
     * @return void
     */
    public function set($key, $value = null)
    {
        if (is_array($key)) {// more get many get
            foreach ($key as $innerKey => $innerValue) {// set the keys
                Arr::set($this->items, $innerKey, $innerValue);
            }
        } else {// single  set
            Arr::set($this->items, $key, $value);
        }
    }// Set a given configuration value

    /**
     * Prepend a value onto an array configuration value.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return void
     */
    public function prepend($key, $value)// Prepend a value onto an array configuration value.
    {
        $array = $this->get($key);// get way to get value by key

        array_unshift($array, $value);// insert a value to the array by key in th first place

        $this->set($key, $array);// set key
    }

    /**
     * Push a value onto an array configuration value.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return void
     */
    public function push($key, $value)
    {
        $array = $this->get($key);

        $array[] = $value;

        $this->set($key, $array);
    }// push a value onto an array configuration value.
   // insert into the last key

    /**
     * Get all of the configuration items for the application.
     *
     * @return array
     */
    public function all()
    {
        return $this->items;
    }// get all the items[] array

    /**
     * Determine if the given configuration option exists.
     *
     * @param  string  $key
     * @return bool
     */
    public function offsetExists($key)
    {
        return $this->has($key);
    }// check has the key

    /**
     * Get a configuration option.
     *
     * @param  string  $key
     * @return mixed
     */
    public function offsetGet($key)
    {
        return $this->get($key);
    }// get a value by key

    /**
     * Set a configuration option.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return void
     */
    public function offsetSet($key, $value)
    {
        $this->set($key, $value);
    }// set/ add/ a option

    /**
     * Unset a configuration option.
     *
     * @param  string  $key
     * @return void
     */
    public function offsetUnset($key)
    {
        $this->set($key, null);
    }// delete a item[option]
}
时间: 2024-08-03 00:21:11

每天laravel-20160708|Repository的相关文章

laravel Repository 模式 优化代码

laravel(商)城代码优化   Repository 模式 优点:使Controller层更加解耦和易读 第1步 配置composer.json  "infyomlabs/laravel-generator": "dev-master",        "laravelcollective/html": "5.4.*",        "infyomlabs/core-templates": "

Laravel之控制器

一.简介 将所有的请求处理逻辑都放在单个routes.php 中肯定是不合理的,你也许还希望使用控制器类组织管理这些行为.控制器可以将相关的 HTTP 请求封装到一个类中进行处理.通常控制器存放在app/Http/Controllers 目录中. 二.基本控制器 1.简单示例下面是一个基本控制器类的例子.所有的 Laravel 控制器应该继承自 Laravel 自带的控制器基类Controller <?php namespace App\Http\Controllers; use App\Use

Laravel 5.2 INSTALL- node&#39;s npm and ruby&#39;s bundler.

https://getcomposer.org/doc/00-intro.md Introduction# Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Dependency management# Compose

为什么Laravel是最成功的PHP框架?

Laravel 是一个有着美好前景的年轻框架,它的社区充满着活力,相关的文档和教程完整而清晰,并为快速.安全地开发现代应用程序提供了必要的功能.在近几年对PHP 框架流行度的统计中,Laravel始终遥遥领先.那么是什么让Laravel成为最成功的PHP框架? 2011 年,Taylor Otwell将Laravel作为一种包含全新现代方法的框架介绍给大家.Laravel最初的设计是为了面向MVC架构的,它可以满足如事件处理.用户 身份验证等各种需求.另外它还有一个由管理数据库强力支持,用于管理

laravel小抄

原文地址:http://cheats.jesse-obrien.ca/ Artisan // Displays help for a given command php artisan --help OR -h // Do not output any message php artisan --quiet OR -q // Display this application version php artisan --version OR -V // Do not ask any interac

Laravel框架怎样使用阿里云ACE缓存服务

Laravel框架怎样使用阿里云ACE缓存服务 之前我写了一篇在 Laravel 4 框架中使用阿里云 OCS 缓存的文章.介绍了怎样通过扩展 Laravel 4 来支持须要 SASL 认证的阿里云 OCS 缓存服务.有网友问我.ACE 的缓存怎么在 Laravel 4 中使用.我本来认为应该能够全然用同样的办法,后来自己尝试的时候才发现,ACE 的缓存区别很大.所以再写一篇,介绍一下怎样在 Laravel 框架中使用阿里云 ACE 的缓存服务. 怎样扩展 Laravel 的缓存驱动 在 Lar

[php]laravel框架容器管理的一些要点

本文面向php语言的laravel框架的用户,介绍一些laravel框架里面容器管理方面的使用要点.文章很长,但是内容应该很有用,希望有需要的朋友能看到.php经验有限,不到位的地方,欢迎帮忙指正. 1. laravel容器基本认识 laravel框架是有一个容器框架,框架应用程序的实例就是一个超大的容器,这个实例在bootstrap/app.php内进行初始化: 这个文件在每一次请求到达laravel框架都会执行,所创建的$app即是laravel框架的应用程序实例,它在整个请求生命周期都是唯

Laravel 进阶任务笔记

在任务开始,我们会扩展一下新建的数据库表移植文件.刚建立的移植文件只有两列,手动添加如下: public function up() { Schema::create('tasks', function (Blueprint $table) { $table->increments('id'); $table->integer('user_id')->index(); $table->string('name'); $table->timestamps(); }); } 再次

Laravel框架如何使用阿里云ACE缓存服务

Laravel框架如何使用阿里云ACE缓存服务 之前我写了一篇在 Laravel 4 框架中使用阿里云 OCS 缓存的文章,介绍了如何通过扩展 Laravel 4 来支持需要 SASL 认证的阿里云 OCS 缓存服务.有网友问我,ACE 的缓存怎么在 Laravel 4 中使用.我本来觉得应该可以完全用相同的办法,后来自己尝试的时候才发现,ACE 的缓存差别非常大.所以再写一篇,介绍一下如何在 Laravel 框架中使用阿里云 ACE 的缓存服务. 如何扩展 Laravel 的缓存驱动 在 La

laravel框架容器管理的一些要点(转)

本文面向php语言的laravel框架的用户,介绍一些laravel框架里面容器管理方面的使用要点.文章很长,但是内容应该很有用,希望有需要的朋友能看到.php经验有限,不到位的地方,欢迎帮忙指正. 1. laravel容器基本认识 laravel框架是有一个容器框架,框架应用程序的实例就是一个超大的容器,这个实例在bootstrap/app.php内进行初始化: 这个文件在每一次请求到达laravel框架都会执行,所创建的$app即是laravel框架的应用程序实例,它在整个请求生命周期都是唯