Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created January 11, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobus1998/fee08b267568eb306a8e55a86b6295c3 to your computer and use it in GitHub Desktop.
Save kobus1998/fee08b267568eb306a8e55a86b6295c3 to your computer and use it in GitHub Desktop.
<?php
// map class, map method, data
$postMapper = new Mapper('post', 'y', ['x' => 'y']);
$mappedData = $m->map();
<?php
class Mapper
{
private $instance;
function __construct (string $type, string $method, array $data)
{
if ($type == 'post')
{
$this->instance = $this->postMapper($method, $data);
}
}
private function postMapper (string $method, array $data)
{
return new PostMapper($method, $data);
}
public function map ()
{
return $instance;
}
}
<?php
class PostMapper
{
private $method;
private $data;
function __construct ($method, $data)
{
$this->method = $method;
$this->data = $data;
}
private function decide()
{
if ($this->method == 'x')
{
$this->mapX();
}
else if ($this->method == 'y')
{
$this->mapY();
}
}
private function mapX ()
{
// map some data on one way
}
private function mapY ()
{
// map some data on another way
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment