dev-feature/manager
dev-feature/managerCustomer component for Reservat
MIT
The Requires
The Development Requires
by Luke Steadman
dev-master
9999999-devCustomer component for Reservat
MIT
The Requires
The Development Requires
by Luke Steadman
Wallogit.com
2017 © Pedro Peláez
Customer component for Reservat
Customer component service for Reservat application., (*1)
Create a new customer object, (*3)
$customer = new \Reservat\Customer('Luke', 'Steadman', '01234567890', 'luke@steadman.com');
Create an instance of \Reservat\Datamapper\CustomerDatamapper, (*4)
// We assume $pdo is stored elsewhere and shared $mapper = new \Reservat\Datamapper\CustomerDatamapper($pdo);
Now save your customer, (*5)
$mapper->save($customer);
DataMapper functionality allows you to save (insert / update) and delete customer records. First off, create a mapper instance., (*6)
$mapper = new \Reservat\Datamapper\CustomerDatamapper($pdo);
Let's create a new customer object and insert this with the mapper, (*7)
$customer = new \Reservat\Customer('Paul', 'Westerdale', '01234567890', 'paul@westerdale.com');
$mapper->insert($customer); // same as $mapper->save($customer);
Let's update the customer object. We need to know the ID of the customer which might not be passed back to the customer entity object, you will have to handle this., (*8)
$customer->setEmail('paulo@westerdale.com');
$mapper->update($customer, 2);
Or use the save function to update the customer, (*9)
$mapper->save($customer, 2);
Finally, remove the customer with the mapper, (*10)
$mapper->delete($customer, 2);
The repository allows us to retrieve data stored in our persistent storage. We abide to two methods, getById and getAll., (*11)
First off, create an instance of repo., (*12)
$repo = \Reservat\Repository\CustomerRepository($pdo);
Grab all the records (default limit: 20), (*13)
$customers = $repo->getAll();
This will return an instance of \Reservat\Repository\CustomerRepository, but implements the Iterator interface, so you can foreach over this object., (*14)
foreach($customers as $customer) {
$forename = $customer['forename'];
...
}
To get a single object, simply call the getById method, passing the ID of the record., (*15)
$customer = $repo->getById(1)->current();
getById also returns an instance of \Reservat\Repository\CustomerRepository., (*16)
Using current will either return NULL (if the record is not found) or an array of the customer data., (*17)
Customer component for Reservat
MIT
Customer component for Reservat
MIT