我正在为我的 Web 项目使用 Symfony2,并且我有几个控制器具有完全相同的 try catch 块
<?php
class MyBaseController extends Controller {
private $manager = new MyManager();
// Some generic stuff
}
class MyController1 extends MyBaseController {
try {
$manager->one();
}
catch (Exception $e) {
return $this->someOtherMessage();
}
}
class MyController2 extends MyBaseController {
try {
$manager->two();
}
catch (Exception $e) {
return $this->someOtherMessage();
}
}
class MyController3 extends MyBaseController {
try {
$manager->three();
}
catch (Exception $e) {
return $this->someOtherMessage();
}
}
我怎么能写这个来避免这么多重复?