зеркало из https://github.com/nextcloud/cookbook.git
Use dependency injection to get rid of the RecipeService Constructor
That makes it easier to test.
This commit is contained in:
Родитель
5658e3b1c8
Коммит
f044df745e
|
@ -13,16 +13,14 @@ use OCA\Cookbook\Service\RecipeService;
|
|||
|
||||
class PageController extends Controller
|
||||
{
|
||||
private $userId;
|
||||
private $service;
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, $UserId, IConfig $config, IURLGenerator $urlGenerator)
|
||||
public function __construct($AppName, IRequest $request, RecipeService $recipeService, IURLGenerator $urlGenerator)
|
||||
{
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
|
||||
$this->service = new RecipeService($root, $UserId, $db, $config);
|
||||
$this->service = $recipeService;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,11 @@ class RecipeController extends Controller
|
|||
*/
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, IConfig $config, $UserId, IURLGenerator $urlGenerator)
|
||||
public function __construct($AppName, IRequest $request, IURLGenerator $urlGenerator, RecipeService $recipeService)
|
||||
{
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
|
||||
$this->service = new RecipeService($root, $UserId, $db, $config);
|
||||
$this->service = $recipeService;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class RecipeService {
|
|||
private $db;
|
||||
private $config;
|
||||
|
||||
public function __construct($root, $userId, IDBConnection $db, IConfig $config) {
|
||||
$this->userId = $userId;
|
||||
public function __construct($UserId, IRootFolder $root, IDBConnection $db, IConfig $config) {
|
||||
$this->userId = $UserId;
|
||||
$this->root = $root;
|
||||
$this->db = new RecipeDb($db);
|
||||
$this->config = $config;
|
||||
|
|
Загрузка…
Ссылка в новой задаче