Skip to content

Instantly share code, notes, and snippets.

@giovanisilveira
Created August 1, 2014 00:41
Show Gist options
  • Save giovanisilveira/3261d577f4de90300743 to your computer and use it in GitHub Desktop.
Save giovanisilveira/3261d577f4de90300743 to your computer and use it in GitHub Desktop.
<?php
interface DAOFactory
{
public function createAccessDAO();
public function createClientDAO();
public function createAddressDAO();
}
/**
* Concrete AccessDAO
*/
class AccessDAO
{
/**
* Retrieve instance of Access
* @param String $login
* @return Access
*/
public function getAccessByLogin($login)
{
}
}
/**
* Concrete ClientDAO
*/
class ClientDAO
{
/**
* Retrieve instance of Client
* @param int $id
* @return Client
*/
public function getById($id)
{
}
}
/**
* Concrete AddressDAO
*/
class AddressDAO
{
/**
* Retrieve instance of Address
* @param Access $access
* @return Address
*/
public function getByAccess(Access $access)
{
}
}
/**
* Entity Access
*/
class Access {
private $id;
private $login;
private $client;
private $address;
/**
* DAO Objects
*/
private $DAOFactory;
private $clientDAO;
private $addressDAO;
public function getters() {
}
public function setters() {
}
public function setDAOFactory(DAOFactory $DAOFactory)
{
$this->DAOFactory = $DAOFactory;
}
private function checkDAOFactory()
{
if (!$this->DAOFactory instanceof DAOFactory) {
throw RuntimeException("Set a DAOFactory.");
}
return $this->DAOFactory;
}
public function getClient()
{
if (!$this->clientDAO instanceof ClientDAO) {
$this->clientDAO = $this->checkDAOFactory()->createClientDAO();
}
return $this->clientDAO->getById($this->client);;
}
public function getAddress()
{
if (!$this->addressDAO instanceof AddressDAO) {
$this->addressDAO = $this->checkDAOFactory()->createAddressDAO();
}
return $this->addressDAO->getByAccess($this);
}
}
/**
* Entity Client
*/
class Client {
}
/**
* Entity Address
*/
class Address {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment