Created
October 4, 2016 17:24
-
-
Save Adamwaheed/0395a20815835ad49d0b08e2650f6ebe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface CalculateInterface{ | |
public function canculate(); | |
} | |
class PilotageCharges implements CalculateInterface{ | |
public $model; | |
public $profile_id; | |
public function __construct($model,$profile_id){ | |
$this->model = $model; | |
$this->profile_id = $profile_id; | |
} | |
public function canculate(){ | |
$invoice['customer_id'] = $this->profile_id; | |
$invoice['total'] = $this->model->rate * $this->model->duration; | |
$invoice['details'] = "PilotageCharges Calculations"; | |
return $invoice; | |
} | |
} | |
class TugCharges implements CalculateInterface{ | |
public $model; | |
public $profile_id; | |
public function __construct($model,$profile_id){ | |
$this->model = $model; | |
$this->profile_id = $profile_id; | |
} | |
public function canculate(){ | |
$invoice['customer_id'] = $this->profile_id; | |
$invoice['total'] = $this->model->rate + $this->model->duration; | |
$invoice['details'] = "TugCharges Calculations"; | |
return $invoice; | |
} | |
} | |
class Tarrif{ | |
public function canculate(CalculateInterface $loger){ | |
return $loger->canculate(); | |
} | |
} | |
Route::get('/', function(){ | |
$tarrif= new Tarrif(); | |
$model = new StdClass(); | |
$model->rate = 52; | |
$model->duration = 2; | |
$result1 = $tarrif->canculate(new PilotageCharges($model,25)); | |
$result2 = $tarrif->canculate(new TugCharges($model,30));; | |
dd($result1,$result2); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment