PHP code example of damiantw / fake-customer-gateway
1. Go to this page and download the library: Download damiantw/fake-customer-gateway library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
damiantw / fake-customer-gateway example snippets
DamianTW\FakeCustomerGateway\CustomerGateway;
DamianTW\FakeCustomerGateway\CustomerGateway;
$customerGateway = new CustomerGateway();
amianTW\FakeCustomerGateway\CustomerGateway;
$customerGateway = new CustomerGateway();
/*
* Data Retrieval
*/
//Returns an array of all of the customers.
$customerGateway->all();
//Returns a paginated array of customers.
$customerGateway->paginate($pageNumber, $perPage);
//Returns an array of all customer sorted on the selected field in ascending order.
//$field can be any of the following strings: 'id', 'name', 'company', 'email', 'phone_number'
$customerGateway->sortByAsc($field);
//Returns an array of all customer sorted on the selected field in descending order.
//$field can be any of the following strings: 'id', 'name', 'company', 'email', 'phone_number'
$customerGateway->sortByDesc($field);
//Returns a paginated array of all customer sorted on the selected field in ascending order.
//$field can be any of the following strings: 'id', 'name', 'company', 'email', 'phone_number'
$customerGateway->sortByPaginatedAsc($field, $pageNumber, $perPage);
//Returns a paginated array of all customer sorted on the selected field in descending order.
//$field can be any of the following strings: 'id', 'name', 'company', 'email', 'phone_number'
$customerGateway->sortByPaginatedDesc($field, $pageNumber, $perPage);
//Returns the number of customer records
$customerGateway->count();
//Returns the customer with the given id. Throws an exception if no user with that id is found.
$customerGateway->get($id);
/*
* Data Manipulation
*/
//Add a customer record.
//Requires a value for at least the $name field or an exception will be thrown.
//Returns the automatically generated id of the new customer.
$customerGateway->add($name, $company, $email, $phone_number);
//Update a customer record.
//Throws an exception if there is no user with the given id.
$customerGateway->update($id, $name, $company, $email, $phone_number);
//Delete a customer record.
//Throws an exception if there is no user with the given id.
$customerGateway->delete($id);
amianTW\FakeCustomerGateway\CustomerGateway;
$customerGateway = new CustomerGateway();
echo '<ul>';
foreach ($customerGateway->all() as $customer) {
echo "<li>$customer->id - $customer->name</li>";
}
echo '</ul>';
amianTW\FakeCustomerGateway\CustomerGateway;
$customerGateway = new CustomerGateway();
/*
* Saves the current state of customer data to disk.
* Returns false if the file write was not successful.
* Make sure PHP has permission to write to the directory you choose!
* Include this at the bottom of any PHP script that changes data.
* $pathToFile example: './customers.db'.
*/
$customerGateway->saveDataFile($pathToFile);
/*
* Overwrites the default customer data given a file generated using the saveDataFile function.
* No changes will be made to the CustomerGateways data if the file does not exist.
* Returns false if the given file does not exist.
* Loading the data file should be one of the first tasks of your PHP script if persisting data.
* $pathToFile example: './customers.db'.
*/
$customerGateway->loadDataFileIfExists($pathToFile);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.