Skip to content

Instantly share code, notes, and snippets.

@cxj
Created July 2, 2015 19:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cxj/a2bf5a77c44f2b002b15 to your computer and use it in GitHub Desktop.
Class to generate concrete instances of Aura\SqlMapper_Bundle mapper and gateway classes
<?php
/**
* @file PayerSource.php
*
* Returns the concrete instances of AbstractGateway and AbstractMapper
* specific to the particular database table.
*/
namespace Clx\DataSources;
use Aura\SqlMapper_Bundle\ObjectFactory;
use Aura\SqlMapper_Bundle\Query\ConnectedQueryFactory;
use Aura\SqlMapper_Bundle\Filter;
class PayerSource extends AbstractPdoSource
{
public function myGateway(ConnectedQueryFactory $q)
{
$filter = new Filter();
return new PayerGateway($this->connectionLocator, $q, $filter);
}
public function myMapper()
{
$objectFactory = new ObjectFactory();
$filter = new Filter();
return new PayerMapper($this->gateway, $objectFactory, $filter);
}
}
@cxj
Copy link
Author

cxj commented Jul 2, 2015

The idea is to not have to write all the set-up code over and over for each table. Instead, just this small class, and the typically small mapper, gateway and object (entity) classes need to be written. Error and connection handling all come along in the abstract super class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment