Created
January 11, 2018 10:27
-
-
Save kobus1998/fee08b267568eb306a8e55a86b6295c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// map class, map method, data | |
$postMapper = new Mapper('post', 'y', ['x' => 'y']); | |
$mappedData = $m->map(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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