定制 devly/repository 二次开发

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

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

devly/repository

最新稳定版本:1.1.0

Composer 安装命令:

composer require devly/repository

包简介

PHP data repository object with array access using dot notation

README 文档

README

Provides an object to store and access data arrays with dot notation support.

Usage

A new data container instance can be created empty or from data provided as array, object or another Devly\Repository instance.

$repository = new \Devly\Repository();

// Or create with initial data
$repository = new \Devly\Repository(['user' => [...]]);

Can also be created using the static method Devly\Repository::new()

set()

$repository->set('user.name', 'johndoe');

// Or as array
$repository['user.name'] = 'johndoe';

// Equivalent vanilla PHP
$array['user']['name'] = 'johndoe';

get()

Retrieves data by key name

$username = $repository->get('user.name');

// Or as array
$username = $repository['user.name'];

// Equivalent vanilla PHP
$username = $array['user']['name'];

has()

Check whether a key name exists

$repository->has('user.name');

// Or as array
isset($repository['user.name']);

// Equivalent vanilla PHP
isset($array['user']['name']);

all()

Returns all the data as array

$array = $repository->all();

remove()

Removes given key

$repository->remove('user.name');

// Or as array
unset($repository['user.name']);

clear()

Removes all the data

$repository->clear();

count()

Counts the number of items in the data container

$repository->count();

// Or using the count function
count($repository);

isEmpty()

Checks whether the container contains data

$repository->isEmpty();

toJson()

Returns a JSON representation of the data

Returns the value of a given key as JSON:

$repository->toJson('user');

Returns all the stored items as JSON:

$repository->toJson();

// Same as:
json_encode($repository);

createFrom()

Create a new Repository instance from an existing item

$repository  = new Repository(['name' => ['first' => 'John', 'last' => 'Doe']]);
$repository2 = $repository->createFrom('name');

$repository2->all(); // ['first' => 'John', 'last' => 'Doe']

merge()

Merge array, object or an instance of IRepository into the current Repository

$repository = new Repository(['first' => 'John', 'last' => 'Doe']);

$repository->merge(new Repository(['first' => 'Johnny']));

// Can also be merged with an object
$repository->merge((object) ['first' => 'Johnny']);

// Can also be merged with an object
$repository->merge(['first' => 'Johnny']);

$repository->all(); // ['first' => 'Johnny', 'last' => 'Doe']

mergeRecursive()

Merge array, object or an instance of IRepository into the current Repository recursively

$repository = new Repository(['name' => ['first' => 'John', 'last' => 'Doe']]);

$repository->mergeRecursive(['name' => ['first' => 'Johnny']]);

$repository->all(); // ['name' => ['first' => 'Johnny', 'last' => 'Doe'] 

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-10-25