ngomafortuna/list-formatter
Composer 安装命令:
composer require ngomafortuna/list-formatter
包简介
Formatter from composite datas to string list. This library accepts lists in array or database format and converts them into strings where each item is separated by commas. This library also sorts a composite list (array/object) in ascending and descending order. (Formatador de dados compostos para
README 文档
README
List formatter is a component with three main functions: (1) convert data in list format (array/object) to text, separating them by commas; (2) sort in ascending or descending order; and (3) convert lists from array format to object and vice-versa.
(Formatador de listas é um componente, com três funções principais (1) converter dados em formato de lista (array/objecto) para texto separando-os por vírgulas, (2) Ordenar de forma crescente ou decrescente e (3) converter listas do formato de array para objecto e vice-versa)
This component have 3 features:
-
ListToString: To convert a list in array or object format into a string with each item separated by a comma, or also to add a hyperlink to each item. (para converter lista em formato de array ou objecto em string com cada item separado por vírgula ou ainda colocar um hiperlink para cada item).
- get: Returns a string, with each item separated by a comma. (retorna um string, com cada item separado por vígula)
- getWithLink: Returns a string, with each item as a hyperlink separated by a comma. (retorna um string, com cada item com hiperlink separado por vírgula)
-
Order: to order array or object list, for two options ascending end descending. (Para ordenar elementos de uma lista, de forma crescente ou decrecente).
- get: return list in asc order (retorna uma lista em ordem crescente)
- getReverse: return list in desc order (retorna uma lista em ordem decrescente)
-
ToListType: Converts object to array and vice-versa. (Converte objecto em array e vice-versa)
- toObject
- toArray
Require
Necessary PHP 8.0 or more (Necessário PHP 8.0 ou superior)
Install
composer require ngomafortuna/list-formatter
Syntax and mode of use
ListToString::get($array, 'array_key'); ListToString::getWithLink($array, ['array_key', 'array_key'], 'url');
Order::get($array, 'array_key'); Order::getReverse($array, 'array_key');
ToListType::toObject($array); ToListType::toArray($object);
Example
use Ngomafortuna\ListFormatter\ListToString; use Ngomafortuna\ListFormatter\Order; use Ngomafortuna\ListFormatter\ToListType; $arrayLIst = [ ['title' => 'Socieda', 'slug'=> 'sociedade','date' => '2024-76-06'], ['title' => 'Vestimentas', 'slug'=> 'vestimentas', 'date' => '2024-06-06'], ['title' => 'Cultura', 'slug'=> 'cultura','date' => '2025-06-06'], ];
Transforme array or object list to string
$list = ListToString::get($arrayLIst, 'title'); $list_with_link = ListToString::getWithLink($arrayLIst, ['title', 'slug'], 'https://www.minharosa.ao'); var_dump($list, $list_with_link);
Result
string(29) "Socieda, Vestimentas e Cultura" string(176) "<a href='https://www.minharosa.ao/sociedade'>Socieda</a>, <a href='https://www.minharosa.ao/vestimentas'>Vestimentas</a> e <a href='https://www.minharosa.ao/cultura'>Cultura</a>"
Order array or object list
$order = Order::get($arrayLIst, 'title'); $order_reverse = Order::getReverse($arrayLIst, 'title'); var_dump($order, $order_reverse);
Result
array(3) {
[0]=>
array(3) {
["title"]=>
string(7) "Cultura"
["slug"]=>
string(7) "cultura"
["date"]=>
string(10) "2025-06-06"
}
[1]=>
array(3) {
["title"]=>
string(7) "Socieda"
["slug"]=>
string(9) "sociedade"
["date"]=>
string(10) "2024-76-06"
}
[2]=>
array(3) {
["title"]=>
string(11) "Vestimentas"
["slug"]=>
string(11) "vestimentas"
["date"]=>
string(10) "2024-06-06"
}
}
array(3) {
[0]=>
array(3) {
["title"]=>
string(11) "Vestimentas"
["slug"]=>
string(11) "vestimentas"
["date"]=>
string(10) "2024-06-06"
}
[1]=>
array(3) {
["title"]=>
string(7) "Socieda"
["slug"]=>
string(9) "sociedade"
["date"]=>
string(10) "2024-76-06"
}
[2]=>
array(3) {
["title"]=>
string(7) "Cultura"
["slug"]=>
string(7) "cultura"
["date"]=>
string(10) "2025-06-06"
}
}
Convert array list to object end object list to array
$conv_to_object = ToListType::toObject($arrayLIst); // create object to convert $listObj = []; foreach($arrayLIst as $item) { $objModel = new \stdClass(); $objModel->title = $item['title']; $objModel->slug = $item['slug']; $objModel->date = $item['date']; $listObj[] = $objModel; } $listObj = (object) $listObj; $conv_to_array = ToListType::toArray($listObj); var_dump($conv_to_object, $conv_to_array);
Result
object(stdClass)#6 (3) { ["0"]=> object(stdClass)#2 (3) { ["title"]=> string(7) "Socieda" ["slug"]=> string(9) "sociedade" ["date"]=> string(10) "2024-76-06" } ["1"]=> object(stdClass)#4 (3) { ["title"]=> string(11) "Vestimentas" ["slug"]=> string(11) "vestimentas" ["date"]=> string(10) "2024-06-06" } ["2"]=> object(stdClass)#5 (3) { ["title"]=> string(7) "Cultura" ["slug"]=> string(7) "cultura" ["date"]=> string(10) "2025-06-06" } } array(3) { [0]=> array(3) { ["title"]=> string(7) "Socieda" ["slug"]=> string(9) "sociedade" ["date"]=> string(10) "2024-76-06" } [1]=> array(3) { ["title"]=> string(11) "Vestimentas" ["slug"]=> string(11) "vestimentas" ["date"]=> string(10) "2024-06-06" } [2]=> array(3) { ["title"]=> string(7) "Cultura" ["slug"]=> string(7) "cultura" ["date"]=> string(10) "2025-06-06" } }
ngomafortuna/list-formatter 适用场景与选型建议
ngomafortuna/list-formatter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ngomafortuna/list-formatter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ngomafortuna/list-formatter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-06-08