2017 © Pedro Peláez
 

library customer

Customer component for Reservat

image

reservat/customer

Customer component for Reservat

  • Tuesday, April 21, 2015
  • by steadweb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Reservat\Customer

Customer component service for Reservat application., (*1)

Build Status, (*2)

Basic Usage

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);

Mapper

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);

Repository

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)

@todo

  • Implement CustomerRepository
  • Add tests
  • Include RESTful API endpoints

The Versions

21/04 2015

dev-feature/manager

dev-feature/manager

Customer component for Reservat

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Steadman

06/04 2015

dev-master

9999999-dev

Customer component for Reservat

  Sources   Download

MIT

The Requires

 

The Development Requires

by Luke Steadman