-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from thewulf7/feature/entities
Feature/entities
- Loading branch information
Showing
27 changed files
with
1,472 additions
and
308 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace travelPayouts\components; | ||
|
||
|
||
abstract class AbstractService | ||
{ | ||
use ServiceInjector; | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
namespace travelPayouts\components; | ||
|
||
use travelPayouts\services\TicketsService; | ||
use travelPayouts\services\DataService; | ||
use travelPayouts\services\FlightService; | ||
use travelPayouts\services\PartnerService; | ||
|
||
/** | ||
* Class ServiceInjector | ||
* | ||
* @method DataService getDataService() | ||
* @method FlightService getFlightService() | ||
* @method PartnerService getPartnerService() | ||
* @method TicketsService getTicketsService() | ||
* | ||
* @package travelPayouts\components | ||
*/ | ||
trait ServiceInjector | ||
{ | ||
|
||
private $_serviceMap = []; | ||
|
||
/** | ||
* Get service | ||
* | ||
* @param $name | ||
* @param $args | ||
* | ||
* @return mixed | ||
* @throws \BadMethodCallException | ||
*/ | ||
public function __call($name, $args) | ||
{ | ||
if (array_key_exists($name, $this->getServiceMap())) | ||
{ | ||
return $this->getService($this->_serviceMap[$name]); | ||
} | ||
|
||
throw new \BadMethodCallException('Calling unknown method: ' . get_class($this) . "::$name()"); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getServiceMap() | ||
{ | ||
if (count($this->_serviceMap) === 0) | ||
{ | ||
$services = require(__DIR__ . '/../config/services.php'); | ||
|
||
foreach ($services as $serviceName => $serviceClass) { | ||
$methodName = 'get' . ucfirst($serviceName); | ||
$this->_serviceMap[$methodName] = $serviceClass; | ||
} | ||
} | ||
|
||
return $this->_serviceMap; | ||
} | ||
|
||
/** | ||
* @param $serviceName | ||
* | ||
* @return mixed | ||
*/ | ||
private function getService($serviceName) | ||
{ | ||
|
||
if (!($this->getClient() instanceof Client)) | ||
{ | ||
throw new \RuntimeException('No token specified'); | ||
} | ||
$service = new $serviceName(); | ||
$service->setClient($this->getClient()); | ||
|
||
return $service; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace travelPayouts\config; | ||
|
||
|
||
use travelPayouts\components\iService; | ||
use travelPayouts\services\TicketsService; | ||
use travelPayouts\services\DataService; | ||
use travelPayouts\services\FlightService; | ||
use travelPayouts\services\PartnerService; | ||
|
||
return [ | ||
iService::DATA_SERVICE => DataService::class, | ||
iService::FLIGHT_SERVICE => FlightService::class, | ||
iService::PARTNER_SERVICE => PartnerService::class, | ||
iService::TICKETS_SERVICE => TicketsService::class, | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace travelPayouts\config; | ||
|
||
return [ | ||
'token' => '321d6a221f8926b5ec41ae89a3b2ae7b' //test token from api.travelpayouts.com | ||
]; |
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"name":"Star Alliance","airlines":["A3","AC","AV","CA","CM","ET","JJ","JP","KF","LH","LO","LX","MS","NH","NZ","OS","OU","OZ","PZ","SA","SK","SN","SQ","TA","TG","TK","TP","UA","US"]},{"name":"oneworld","airlines":["4M","AA","AB","BA","CX","AY","HG","IB","JC","JL","JO","KA","LA","LP","MA","MN","MX","NU","QF","RJ","S7","XL"]},{"name":"SkyTeam","airlines":["AF","AE","AM","AR","AZ","CI","CZ","DL","FM","KE","KL","KQ","ME","MU","OK","RO","SU","SV","UX","VN"]}] |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.