Created
February 9, 2015 14:02
-
-
Save chukShirley/0194bc9f56097486e057 to your computer and use it in GitHub Desktop.
Domain Design for Apigility on IBM i
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 | |
// module/Acme/src/Acme/V1/Rest/Customer/CustomerCollection.php | |
namespace Acme\V1\Rest\PeddlerPricingFormula; | |
use Zend\Paginator\Paginator; | |
class CustomerCollection extends Paginator | |
{ | |
} |
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 | |
// module/Acme/src/Acme/V1/Rest/Customer/CustomerEntity.php | |
namespace Acme\V1\Rest\Customer; | |
class CustomerEntity | |
{ | |
public $id; | |
public $name; | |
public $address; | |
} |
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 | |
// module/Acme/src/Acme/V1/Rest/Customer/CustomerResource.php | |
namespace Acme\V1\Rest\Customer; | |
class CustomerResource extends AbstractResourceListener | |
{ | |
protected $toolkitService; | |
public function __construct($toolkitService) | |
{ | |
$this->toolkitService = $toolkitService; | |
} | |
/** | |
* Create a customer | |
* | |
* @param mixed $data | |
* return ApiProblem|mixed | |
*/ | |
public function create($data) | |
{ | |
// Construct parameters for toolkit call | |
$params = [ | |
$this->toolkitService->AddParameterChar('both', 25, 'name', 'customer name', $data->name), | |
$this->toolkitService->AddparameterChar('both', 50, 'address', 'customer address', $data->address), | |
]; | |
// Call program | |
$result = $this->toolkitService->PgmCall('PGMNAME', 'LIBNAME', $params, null, null); | |
// Error handling for toolkit | |
if (!$result) | |
{ | |
return new ApiProblem(500, 'Problem calling program. Code:'.$this->toolkitService->getErrorCode().'. Text: '.$this->toolkitService->getErrorMsg()); | |
} | |
// Error handling for everything else | |
if ($result['io_param']['errorCode'] > 0) | |
{ | |
// TODO: Delegate error handling to another class | |
return new ApiProblem( | |
$result['io_param']['errorCode'], | |
$result['io_param']['errorMessage'] | |
); | |
} | |
$customer = $result['io_param']; | |
return $customer; | |
} | |
} |
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 | |
// /module/Acme/src/Acme/V1/Rest/Customer/CustomerResourceFactory.php | |
namespace Acme\V1\Rest\Customer; | |
class CustomerResourceFactory | |
{ | |
public function __invoke($services) | |
{ | |
$toolkitService = $services->get('tkconn'); | |
return new CustomerResource($toolkitService); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment