zuffik/structures

此包已被废弃且不再维护。作者建议使用 srvant 包代替。

原始数据类型的数据结构和对象包装器

安装: 145

依赖: 0

建议者: 0

安全性: 0

星级: 0

关注者: 1

分支: 1

开放问题: 0

类型:composer

0.2.3 2017-12-15 18:16 UTC

README

此包包含一些基本数据结构(ArrayList、LinkedList...)、数据类型(例如 Integer、String...)和格式(URL、Random、JSON、...)。

安装

使用 composer

composer require zuffik/structures

使用

ArrayList 和 LinkedList

这两个结构接口相同。区别仅在于存储数据。ArrayList 使用连续的 PHP 数组结构来存储数据,而 LinkedList 使用对象的链(一个链接到另一个)。

示例

$list = new \Zuffik\Structures\Data\ArrayList();
$list->add(2, 3);           // Contains 2,3
$list->add(4, 5);           // Contains 2,3,4,5
$list->addFirst(1);         // Contains 1,2,3,4,5
$list->delete(1);           // Contains 1,3,4,5
$list->deleteByValue(1);    // Contains 3,4,5
$list->map(function($item) {
  return $item + 1;
});                         // Contains 4,5,6
$list->filter(function() {
  return $item % 2 == 1;
});                         // Contains 5
$list->size();              // Returns 1
$list->add('a');            // Contains 5, 'a'
$list->join(';');           // Returns '5;a'
// All these methods can be chained (except of size, join, etc.)
// Full docs will be available in next release

String

Str 类(因为字符串是保留关键字)提供了最常用的字符串函数。这个类可以通过 __toString 方法转换为字符串,也可以链接,因为类中的每个方法都返回 对象 而不是 字符串。如果安装了 mbstring 扩展,则此类会使用它而不是本地的 PHP 函数。

示例

$string = new \Zuffik\Structures\Types\Str('Hello world');
$string->toUppercase();     // HELLO WORLD
$string->camelCase();       // helloWorld
$string->slug();            // hello-world
// Full docs will be available in next release

贡献

您可以通过创建 pull request 来贡献。

捐赠

如果您对这个包感到满意,请随意捐赠给我

paypal