virusecks/objectron

从模板创建对象

0.0.4-alpha 2018-04-30 21:20 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:31:46 UTC


README

Objectron 使用字符串模板来返回一个设计好的类。

而不是使用 30 个不同的模型在项目中使用前修改数据,使用 1 个基础模型和不同的字符串(模板)来修改输出

安装

Composer

VirusEcks/Objectron

使用示例

$arr[] = ['id'=> 1, 'name'=>'john', 'class'=>10];
$arr[] = ['id'=> 5, 'name'=>'clam', 'class'=>4];
$arr[] = ['id'=> 8, 'name'=>'robot', 'class'=>1];


$result1 = Objectron::toObject($arr, 'id', '%id%, Student Class=%class%, Student Name => %name% ,Student group=>%id%');
$result2 = Objectron::toObject($arr, 'name', '%id%, %class%, %name%');
$result3 = Objectron::toObject($arr, 'id', '%name%');
$result4 = Objectron::toObject($arr, 'id');
$result5 = Objectron::toObject($arr);


print_r($result1);
print_r($result2);
print_r($result3);
print_r($result4);
print_r($result5);


$result1 =
            stdClass Object
            (
                [1] => stdClass Object
                    (
                        [0] => 1
                        [Student Class] => 10
                        [Student Name] => john
                        [Student group] => 1
                    )
            
                [5] => stdClass Object
                    (
                        [0] => 5
                        [Student Class] => 4
                        [Student Name] => clam
                        [Student group] => 5
                    )
            
                [8] => stdClass Object
                    (
                        [0] => 8
                        [Student Class] => 1
                        [Student Name] => robot
                        [Student group] => 8
                    )
            
            )
            
$result2 =
            stdClass Object
            (
                [john] => stdClass Object
                    (
                        [0] => 1
                        [1] => 10
                        [2] => john
                    )
            
                [clam] => stdClass Object
                    (
                        [0] => 5
                        [1] => 4
                        [2] => clam
                    )
            
                [robot] => stdClass Object
                    (
                        [0] => 8
                        [1] => 1
                        [2] => robot
                    )
            
            )
            
$result3 =
            stdClass Object
            (
                [1] => john
                [5] => clam
                [8] => robot
            )
            
$result4 =
            stdClass Object
            (
                [1] => Array
                    (
                        [id] => 1
                        [name] => john
                        [class] => 10
                    )
            
                [5] => Array
                    (
                        [id] => 5
                        [name] => clam
                        [class] => 4
                    )
            
                [8] => Array
                    (
                        [id] => 8
                        [name] => robot
                        [class] => 1
                    )
            
            )
            
$result5 =
            stdClass Object
            (
                [0] => Array
                    (
                        [id] => 1
                        [name] => john
                        [class] => 10
                    )
            
                [1] => Array
                    (
                        [id] => 5
                        [name] => clam
                        [class] => 4
                    )
            
                [2] => Array
                    (
                        [id] => 8
                        [name] => robot
                        [class] => 1
                    )
            
            )

有关更多示例和用法,请参阅 Wiki

开发

这个项目是为了证明某些人认为它毫无用处且无法实现,如果实现了,将会非常缓慢的工作。

这是在空闲时间用一天完成的,可能需要大量的修改和测试,我会在一个项目中使用它,这将是一个很好的测试场。

发布历史

  • 0.0.4-alpha
    • 增加了使用标记化器的选项
    • 将调用方式改为静态函数
    • 性能提升 -> 相比上一版本,相同数据格式下性能提升了 260%
    • 增加了一些通用测试(尚无单元测试)
    • 增加了更好的属性值查找器(可用于项目外)
    • 移除了一些不必要的代码
    • 将正则表达式改为更好地处理非统一格式
  • 0.0.3-alpha
    • 更改了布局和命名空间
  • 0.0.2-alpha
    • 添加了一些调整和修复
  • 0.0.1-alpha
    • 初始发布和正在进行中

元数据

Ahmed Salah – @virusecksvirus.ecks@gmail.com

在 MIT 许可证下分发。有关更多信息,请参阅 LICENSE

https://github.com/virusecks/objectron

贡献

  1. 将其分支(https://github.com/virusecks/objectron/fork
  2. 创建您的功能分支(git checkout -b feature/fooBar
  3. 提交您的更改(git commit -am 'Add some fooBar'
  4. 推送到分支(git push origin feature/fooBar
  5. 创建新的拉取请求