承接 werx/collections 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

werx/collections

Composer 安装命令:

composer require werx/collections

包简介

Base class for working with collections of things

README 文档

README

Base class for working with collections of things.

Build Status Total Downloads Latest Stable Version

Usage

You can either create instances of the Collection object...

$foo = new \werx\Collections\Collection;

Or create a class that extends it.

class Foo extends \werx\Collections\Collection
{

}

$foo = new Foo();

Fill the collection in the constructor.

$foo = new new \werx\Collections\Collection(['foo' => 'Foo', 'bar' => 'bar']);

Add multiple items to collection by passing an array to the set() method.

$foo = new Foo();
$foo->set(['foo' => 'Foo', 'bar' => 'bar']);

How many items in the collection?

var_dump($foo->count());
# OR
var_dump(count($foo)); // The Collection class implements the Countable() interface.
// 2

Does the collection have a key named 'foo'? (yes)

var_dump($foo->has('foo'));
// true

Does the collection have a key named 'x'? (no)

var_dump($foo->has('x'));
// false

Get the value of the key named 'foo' from the collection.

var_dump($foo->get('foo'));
// Foo

Return default null if key doesn't exist.

var_dump($foo->get('x'));
// null

Set a different default value if key doesn't exist.

var_dump($foo->get('x', 'no'));
// no

Set a key/value.

$foo->set('name', 'Josh');

Add an item to the collection without a specific key.

$foo->add('Josh');

Add an array to the collection without a specific key.

$foo->add(['name' => 'Josh', 'location' => 'Arkansas']);

Remove a key from the collection.

$foo->remove('name');

Get all keys in the collection.

$foo->all();

OR

$foo->toArray();

Convert the collection to json.

var_dump($foo->toJson());
// {"foo":"Foo","bar":"Bar"}

Casting the collection to a string will also return json.

var_dump((string) $foo);
// {"foo":"Foo","bar":"Bar"}

Empty the collection.

$foo->clear();

Installation

Installation of this package is easy with Composer. If you aren't familiar with the Composer Dependency Manager for PHP, you should read this first.

composer.json

"require": {
	"werx/collections": "dev-master"
}

Contributing

Unit Testing

$ vendor/bin/phpunit

Coding Standards

This library uses PHP_CodeSniffer to ensure coding standards are followed.

I have adopted the PHP FIG PSR-2 Coding Standard EXCEPT for the tabs vs spaces for indentation rule. PSR-2 says 4 spaces. I use tabs. No discussion.

To support indenting with tabs, I've defined a custom PSR-2 ruleset that extends the standard PSR-2 ruleset used by PHP_CodeSniffer. You can find this ruleset in the root of this project at PSR2Tabs.xml

Executing the codesniffer command from the root of this project to run the sniffer using these custom rules.

$ ./codesniffer

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固