thonyx/phppods

PHP 辅助工具

1.0.1 2018-04-04 20:44 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:46:48 UTC


README

一系列用于构建快速 PHP 应用的辅助组件。

有什么可用?

  • 点表示法数组
  • 使用模板或占位文件按需创建 PHP 文件

如何安装?

composer require thonyx/phppods 

想看看它的实际应用吗?

运行测试!安装包后,进入您的 PHP 项目中的 --from /vendor/thonyx/phppods 并运行

例如:将点表示法数组转换回数组

composer install && php UndotterTest.php

如何使用它?

所有可用函数都可以通过以下方式访问

\Axonbits\ComponentName::functionName();

点表示法数组

将点表示法转换回多维数组,其中包含来自“点”表示法的扁平化键值对。

在调用函数之前

\Axonbits\Arrays::undot[
	'name'=>'Yale', 
	'timeseries.2014.enrollment'=>'1',
	'timeseries.2014.cost'=>'100',
	'timeseries.2015.enrollment'=>'200',
	'timeseries.2015.cost'=>'200',
	'groups.colors.default'=>'#white',
	'groups.colors.blue'=>'#lalala'
]);

调用函数之后

[
  'name' => 'Yale',
  'timeseries' =>
  [
    2014 =>
    [
      'enrollment' => '1',
      'cost' => '100',
    ],
    2015 =>
    [
      'enrollment' => '200',
      'cost' => '200',
    ],
  ],
  'groups' =>
  [
    'colors' =>
    [
      'default' => '#white',
      'blue' => '#lalala',
    ],
  ],
]

在转换数组时,您可以指定函数调用应返回的响应格式

--可用:JSON 或 ARRAY--

例如:将结果作为 JSON 返回

\Axonbits\Arrays::toJson()->undot[
	'name'=>'Yale', 
	'timeseries.2014.enrollment'=>'1',
	'timeseries.2014.cost'=>'100',
	'timeseries.2015.enrollment'=>'200',
	'timeseries.2015.cost'=>'200',
	'groups.colors.default'=>'#white',
	'groups.colors.blue'=>'#lalala'
]);

文件系统:从模板或占位文件创建文件

示例

\Axonbits\Filesystem::
    newFile(__DIR__ . '/tmp/SessionClass.php')
    ->withStub($stubPath = __DIR__ . '/tmp/DummyClass.php', [
        'DummyClass'     => 'SessionClass',
        'DummyTimestamp' => '"2018-01-01"',
        'DummyNamespace' => 'App\\Sessions',
    ])
    ->write();