Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

null-object.html

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 7.10 KiB


 001  <!DOCTYPE html>
 002  <html class="no-js" id="top">
 003  <head>
 004      <title>ProxyManager - Null object</title>
 005   
 006      <meta name="description" content="A proxyManager write in php" />
 007      <meta name="keywords" content="ProxyManager, proxy, manager, ocramius, Marco Pivetta, php, null object" />
 008      <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
 009      <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600' rel='stylesheet' type='text/css'>
 010      <link href="css/styles.css" rel="stylesheet" />
 011      <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/default.min.css">
 012      <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
 013      <script>hljs.initHighlightingOnLoad();</script>
 014      <link rel="shortcut icon" href="favicon.ico">
 015  </head>
 016  <body>
 017   
 018  <header class="site-header">
 019  <div class="container">
 020  <h1><a href="index.html"><img alt="ProxyManager" src="img/block.png" /></a></h1>
 021   
 022  <nav class="main-nav" role="navigation">
 023  <ul>
 024      <li><a href="https://github.com/Ocramius/ProxyManager" target="_blank">Github</a>
 025      <div class="bcms-clearfix"></div>
 026  </li>
 027  </ul>
 028  </nav>
 029  </div>
 030  </header>
 031  <main role="main">
 032  <section class="component-content">
 033   
 034  <div class="component-demo" id="live-demo">
 035      <div class="container">
 036              <div class="main-wrapper" style="text-align: right">
 037                  <iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=fork&amp;count=true&amp;size=large"
 038    allowtransparency="true" frameborder="0" scrolling="0" width="310" height="40"></iframe>
 039   
 040                  <iframe src="http://ghbtns.com/github-btn.html?user=ocramius&amp;repo=ProxyManager&amp;type=watch&amp;count=true&amp;size=large"
 041    allowtransparency="true" frameborder="0" scrolling="0" width="200" height="40"></iframe>
 042   
 043              </div>
 044          <div class="bcms-clearfix bcms-clearfix"></div>
 045      </div>
 046  </div>
 047  <div class="component-info">
 048  <div class="container">
 049  <aside class="sidebar">
 050      <nav class="spy-nav">
 051          <ul>
 052              <li><a href="index.html">Intro</a></li>
 053              <li><a href="virtual-proxy.html">Virtual Proxy</a></li>
 054              <li><a href="null-object.html">Null Objects</a></li>
 055              <li><a href="ghost-object.html">Ghost Objects</a></li>
 056              <li><a href="remote-object.html">Remote Object</a></li>
 057              <li><a href="contributing.html">Contributing</a></li>
 058              <li><a href="credits.html">Credits</a></li>
 059              <li><a href="copyright.html">Copyright</a></li>
 060          </ul>
 061      </nav>
 062  <div class="bcms-clearfix bcms-clearfix"></div>
 063  <a class="btn btn-action btn-full download-component"
 064      href="download.html">Download</a>
 065      <div class="bcms-clearfix"></div>
 066  </aside>
 067   
 068  <div class="content">
 069      <div class="bcms-clearfix"></div>
 070      <h3 class="section-title">Null Object Proxy</h3>
 071      <p>A Null Object proxy is a <a href="http://en.wikipedia.org/wiki/Null_Object_pattern" target="_blank">null object pattern</a> implementation. The proxy factory creates a new object with defined neutral behavior based on an other object, class name or interface.</p>
 072  <hr />
 073   
 074      <h3 class="section-title">What is null object proxy ?</h3>
 075   
 076      <p>In your application, when you can't return the object related to the request, the consumer of the model must check for the return value and handle the failing condition gracefully, thus generating an explosion of conditionals throughout your code. Fortunately, this seemingly-tangled situation can be sorted out simply by creating a polymorphic implementation of the domain object, which would implement the same interface as the one of the object in question, only that its methods wouldn’t do anything, therefore offloading client code from doing repetitive checks for ugly null values when the operation is executed.</p>
 077   
 078  <hr />
 079   
 080      <h3 class="section-title">Usage examples</h3>
 081   
 082      <pre>
 083          <code class="php">
 084  class UserMapper
 085  {   
 086      private $adapter;
 087   
 088      public function __construct(DatabaseAdapterInterface $adapter) {
 089          $this->adapter = $adapter;
 090      }
 091   
 092      public function fetchById($id) {
 093          $this->adapter->select("users", array("id" => $id));
 094          if (!$row = $this->adapter->fetch()) {
 095              return null;
 096          }
 097          return $this->createUser($row);
 098      }
 099   
 100      private function createUser(array $row) {
 101          $user = new Entity\User($row["name"], $row["email"]);
 102          $user->setId($row["id"]);
 103          return $user;
 104      }
 105  }
 106          </code>
 107      </pre>
 108   
 109      <p>If you want to remove conditionals from client code, you need to have a version of the entity conforming to the corresponding interface. With the Null Object Proxy, you can build this object :</p>
 110   
 111      <pre>
 112          <code class="php">
 113  $factory = new \ProxyManager\Factory\NullObjectFactory();
 114   
 115  $nullUser = $factory->createProxy('Entity\User');
 116   
 117  var_dump($nullUser->getName()); // empty return
 118          </code>
 119      </pre>
 120   
 121      <p>You can now return a valid entity :</p>
 122   
 123      <pre>
 124          <code class="php">
 125  class UserMapper
 126  {   
 127      private $adapter;
 128   
 129      public function __construct(DatabaseAdapterInterface $adapter) {
 130          $this->adapter = $adapter;
 131      }
 132   
 133      public function fetchById($id) {
 134          $this->adapter->select("users", array("id" => $id));
 135          return $this->createUser($this->adapter->fetch());
 136      }
 137   
 138      private function createUser($row) {
 139          if (!$row) {
 140              $factory = new \ProxyManager\Factory\NullObjectFactory();
 141   
 142              return $factory->createProxy('Entity\User');
 143          }
 144          $user = new Entity\User($row["name"], $row["email"]);
 145          $user->setId($row["id"]);
 146          return $user; 
 147      }
 148  }
 149          </code>
 150      </pre>
 151      
 152      
 153  <hr />
 154   
 155      <h3 class="section-title">Proxying interfaces</h3>
 156   
 157      <p>You can also generate proxies from an interface FQCN. By proxying an interface, you will only be able to access the methods defined by the interface itself, and like with the object, the methods are empty.</p>
 158   
 159      <p>Tuning performance for production</p>
 160   
 161      <p>See <a href="production.html">Tuning ProxyManager for Production.</a></p>
 162   
 163  </main>
 164   
 165      <footer class="site-footer" role="contentinfo">
 166          <div class="container">
 167              <div class="footer-logos">
 168                  <ul>
 169                      <li><a href="index.html">Intro</a> | </li>
 170                      <li><a href="virtual-proxy.html">Virtual Proxy</a> | </li>
 171                      <li><a href="null-object.html">Null Objects</a> | </li>
 172                      <li><a href="ghost-object.html">Ghost Objects</a> | </li>
 173                      <li><a href="remote-object.html">Remote Object</a> | </li>
 174                      <li><a href="contributing.html">Contributing</a> | </li>
 175                      <li><a href="credits.html">Credits</a> | </li>
 176                      <li><a href="copyright.html">Copyright</a></li>
 177                  </ul>
 178              </div>
 179          </div>
 180   
 181          <div class="bcms-clearfix"></div>
 182      </footer>
 183      <div class="bcms-clearfix"></div>
 184      </body>
 185  </html>
 186