| @@ 10-31 (lines=22) @@ | ||
| 7 | use Cake\Utility\Inflector; |
|
| 8 | use Polidog\Chatwork\Entity\File; |
|
| 9 | ||
| 10 | class FileFactory extends AbstractFactory |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @param array $data |
|
| 14 | * |
|
| 15 | * @return File |
|
| 16 | */ |
|
| 17 | public function entity(array $data = []) |
|
| 18 | { |
|
| 19 | $userFactory = new UserFactory(); |
|
| 20 | $file = new File(); |
|
| 21 | $file->account = $userFactory->entity($data['account']); |
|
| 22 | unset($data['account']); |
|
| 23 | ||
| 24 | foreach ($data as $key => $value) { |
|
| 25 | $property = Inflector::variable($key); |
|
| 26 | $file->$property = $value; |
|
| 27 | } |
|
| 28 | ||
| 29 | return $file; |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 10-33 (lines=24) @@ | ||
| 7 | use Cake\Utility\Inflector; |
|
| 8 | use Polidog\Chatwork\Entity\Message; |
|
| 9 | ||
| 10 | class MessageFactory extends AbstractFactory |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @param array $data |
|
| 14 | * |
|
| 15 | * @return Message |
|
| 16 | */ |
|
| 17 | public function entity(array $data = []) |
|
| 18 | { |
|
| 19 | // @todo ここでnewするのなんとかしたい・・・ |
|
| 20 | $userFactory = new UserFactory(); |
|
| 21 | $message = new Message(); |
|
| 22 | ||
| 23 | $message->account = $userFactory->entity($data['account']); |
|
| 24 | unset($data['account']); |
|
| 25 | ||
| 26 | foreach ($data as $key => $value) { |
|
| 27 | $property = Inflector::variable($key); |
|
| 28 | $message->$property = $value; |
|
| 29 | } |
|
| 30 | ||
| 31 | return $message; |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||