From 9cacd34e325416f62705267cf8217594854492ad Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 7 Sep 2016 21:07:54 +0200 Subject: s/multipaste_queue: Refactor constructor to support dependency injection Signed-off-by: Florian Pritz --- application/service/multipaste_queue.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'application') diff --git a/application/service/multipaste_queue.php b/application/service/multipaste_queue.php index 28ff683b7..453ea3429 100644 --- a/application/service/multipaste_queue.php +++ b/application/service/multipaste_queue.php @@ -11,13 +11,26 @@ namespace service; class multipaste_queue { - public function __construct() { + public function __construct($session = null, $mfile = null, $mmultipaste = null) { $CI =& get_instance(); - $CI->load->model("mfile"); - $CI->load->model("mmultipaste"); - $this->session = $CI->session; - $this->mfile = $CI->mfile; - $this->mmultipaste = $CI->mmultipaste; + + $this->session = $session; + $this->mfile = $mfile; + $this->mmultipaste = $mmultipaste; + + if ($this->session === null) { + $this->session = $CI->session; + } + + if ($this->mfile === null) { + $CI->load->model("mfile"); + $this->mfile = $CI->mfile; + } + + if ($this->mmultipaste === null) { + $CI->load->model("mmultipaste"); + $this->mmultipaste = $CI->mmultipaste; + } } /** -- cgit v1.2.3-24-g4f1b