如何在php

时间:2017-06-28 08:32:41

标签: php design-patterns

在我的情况下,我的查询结果来自数据库:

结果是一个数组,

我想在多个对象中传递结果并获得结果。

我尝试使用中介模式,但它在我的情况下不起作用,因为我需要从第一个对象获得结果并将主题传递给第二个,依此类推。

代码:

$mediator->add('test',[$obj1,'methodobj1']);
$mediator->add('test',[$obj2,'methodobj2']);
$mediator->run('test','resultCameFromDataBase(array)');

我想要这样的事情:

$data = $obj1($result);
$data1 = $obj2($data);
$data2 = $obj3($data1);
...
return $Result; 

有什么建议吗?我应该使用调解员吗?

我需要在这种情况下使用模式吗?

我知道有很多像doctrine2这样的工具,但在我的情况下我不能使用主题。

1 个答案:

答案 0 :(得分:1)

Pipes and Filters设计模式就是你要找的。

查看准备使用库作为用例的https://github.com/thephpleague/pipeline

如果你需要知道它是如何工作的,这个维基可以帮助你https://en.wikipedia.org/wiki/Pipeline_(software)

我希望这会有所帮助。