假设一个Human
可以Item
在他的口袋里有(s)。每种Item
对Human
.
当他使用一个项目时,它会转到ItemController
:
class ItemController extends Controller
{
public function useAction() {
// Human
$human = new Human();
// Item
$request = Request::createFromGlobals();
$item_id = $request->request->get('item_id', 0);
$item = new Item($item_id);
// Different effects depending on the Item used
switch($item->getArticleId()) {
case 1: $this->heal($human, $item, 5); break; // small potion
case 2: $this->heal($human, $item, 10); break; // medium potion
case 3: $this->heal($human, $item, 15); break; // big potion
}
}
// The following Heal Function can be placed here ?
private function heal($human, $item, $life_points) {
$human->addLife($life_points);
$item->remove();
return new Response("You have been healed of $life_points");
}
}
heal function
可以放在这里吗?我相信它不应该在控制器中。但我也认为它不应该放在里面Item Entity
(因为 Response,而且因为它使用 $Human)