<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 概述 數據映射器是一種數據訪問層,它執行持久性數據存儲(通常是關系數據庫)和內存數據表示(域層)之間的數據雙向傳輸。 該模式的目標是保持內存表示和持久數據存儲相互獨立,并 保持數據映射器本身。 該層由一個或多個映射器(或數據訪問對象)組成,執行數據傳輸。 映射器實現的范圍有所不同。 通用映射器將處理許多不同的域實體類型,專用映射器將處理一 個或幾個。 ### 實例 ~~~ class User{ private $username; private $email; public function __construct($username, $email) { $this->username = $username; $this->email = $email; } public static function fromState(array $state): User { return new self( $state['username'], $state['email'] ); } public function getUsername() { return $this->username; } public function getEmail() { return $this->email; } } class StorageAdapter{ private $data = []; public function __construct(array $data) { $this->data = $data; } public function find(int $id) { if(isset($this->data[$id])){ return $this->data[$id]; } return null; } } class UserMapper{ private $adapter; public function __construct(StorageAdapter $storage) { $this->adapter = $storage; } /** * 根據ID從儲存器中找到用戶,并返回一個用戶對象 * 在內存中,通常這種邏輯使用Repository模式來實現 * 然后,中的部分是在下面的mapRowToUser()中,它將從中創建一個業務對象 * 從儲存中獲取的數據 */ public function findById(int $id): User { $res = $this->adapter->find($id); if($res === null){ throw new Exception("not found"); } return $this->mapRowToUser($res); } private function mapRowToUser(array $row): User { return User::fromState($row); } } $storage = new StorageAdapter([1=>['username'=>'jack','email'=>'7740280@qq.com']]); $mapper = new UserMapper($storage); $user = $mapper->findById(1); var_dump($user instanceof User); ~~~ ~~~ true ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看