定制 nocs/laravel-retriever 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nocs/laravel-retriever

最新稳定版本:v1.1.9

Composer 安装命令:

composer require nocs/laravel-retriever

包简介

Retrieve cached data made simple.

README 文档

README

Latest Version on Packagist Total Downloads

Retrieve cached data made simple

Installation

Install with composer

composer require nocs/laravel-retriever

Usage

Place your cache files under app/Retrievers (primary) or app/Cache (secondary).

Use the App\Retrievers or App\Cache namespace for your classes.

Use, as usual, studlied strings for your classnames. When retrieving use a snaked version in your key.

Define public non-static methods which return the cached values.

Basic usage

Example: app/Cache/Colors.php

<?php

namespace Nocs\Retriever\Tests\Cache;

class Colors {

    public function red()
    {
        return 'red';
    }

}

Retrieve the value with:

<?php

$value = retriever()->get('colors.red');

Using one method

When using only one method, you can use the get method. app/Cache/Colors.php

<?php

namespace Nocs\Retriever\Tests\Cache;

class Colors {

    public function get()
    {
        return 'red';
    }

}

And retrieve the value with:

<?php

$value = retriever()->get('colors');

Using namespaces

When creating vendors you can use namespaces.

Give your cache files the correct namespace, for example MyVendor\Cache.

Place your cache class files in location src/Retrievers or src/Cache.

Add the location in your ServiceProvider class in the boot section.

<?php

namespace Vendor\Package\Providers;

use Illuminate\Support\ServiceProvider;
use Nocs\Retriever\Support\Facades\Retriever;

class PackageServiceProvider extends ServiceProvider
{

    public function boot(Router $router)
    {

        Retriever::loadRetrieversFrom(__dir__.'/../Cache', 'package');

    }
}

Retrieve the value with the namespace prefixed (snaked) to the key:

<?php

$value = retriever()->get('my_vendor::colors');

Arguments

A second argument to the get call can be provided as an array of arguments that will be passed to the cache closure.

Short

Instead of using

<?php

$value = retriever()->get('key');
$value = retriever()->get('key', 'default');

you can use

<?php

$value = retriever('key', 'default');

Testing

To test, run

composer test

Security

If you discover any security related issues, please email the author instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

统计信息

  • 总下载量: 1.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-16