Last active
August 29, 2015 14:02
-
-
Save sasezaki/b429bfb87d831a3474c2 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 | |
// I'm not fun to see your handling data masturbation. | |
// (I'm not intend DDD, too) | |
// Don't annoy me with such article. http://www.1x1.jp/blog/2014/06/how-to-scan-array-in-php.html | |
use Zend\Stdlib\Hydrator; | |
require_once 'vendor/autoload.php'; | |
$usersData = [ | |
[ | |
'id' => 1, | |
'year' => 1993, | |
'name' => 'Harada', | |
], | |
[ | |
'id' => 2, | |
'year' => 2001, | |
'name' => 'Kato', | |
], | |
[ | |
'id' => 3, | |
'year' => 2009, | |
'name' => 'Aoyama', | |
] | |
]; | |
class User | |
{ | |
private $id, $year, $name; | |
public function getYear() | |
{ | |
return $this->year; | |
} | |
public function getEmployeeNumber() | |
{ | |
return $this->year.$this->name; | |
} | |
} | |
class UserSet extends ArrayIterator | |
{ | |
public function current() | |
{ | |
$user = new User; | |
$hydrator = new Hydrator\Reflection(); | |
$hydrator->hydrate(parent::current(), $user); | |
return $user; | |
} | |
} | |
class UserRepository | |
{ | |
public function findByOverYear($year) | |
{ | |
global $usersData; | |
return new CallbackFilterIterator(new UserSet($usersData), function($user) use($year) { return $user->getYear() >= $year;}); | |
} | |
} | |
$users = (new UserRepository())->findByOverYear(2000); | |
?> | |
view | |
<?php foreach ($users as $user) :?> | |
社員番号 | |
<?= htmlspecialchars($user->getEmployeeNumber()); ?> | |
<br /> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment