Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -1,3 +1,7 @@
---
title: Null Object Proxy
---
# Null Object Proxy
A Null Object proxy is a [null object pattern](http://en.wikipedia.org/wiki/Null_Object_pattern) implementation.
@@ -9,7 +13,7 @@ In your application, when you can't return the object related to the request, th
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
wouldnt do anything, therefore offloading client code from doing repetitive checks for ugly null values when the operation
wouldn't do anything, therefore offloading client code from doing repetitive checks for ugly null values when the operation
is executed.
## Usage examples
@@ -24,16 +28,20 @@ class UserMapper
}
public function fetchById($id) {
$this->adapter->select("users", array("id" => $id));
$this->adapter->select('users', ['id' => $id]);
if (!$row = $this->adapter->fetch()) {
return null;
}
return $this->createUser($row);
}
private function createUser(array $row) {
$user = new Entity\User($row["name"], $row["email"]);
$user->setId($row["id"]);
$user = new Entity\User($row['name'], $row['email']);
$user->setId($row['id']);
return $user;
}
}
@@ -62,7 +70,8 @@ class UserMapper
}
public function fetchById($id) {
$this->adapter->select("users", array("id" => $id));
$this->adapter->select('users', ['id' => $id]);
return $this->createUser($this->adapter->fetch());
}
@@ -72,8 +81,11 @@ class UserMapper
return $factory->createProxy('Entity\User');
}
$user = new Entity\User($row["name"], $row["email"]);
$user->setId($row["id"]);
$user = new Entity\User($row['name'], $row['email']);
$user->setId($row['id']);
return $user;
}
}
@@ -86,4 +98,4 @@ methods defined by the interface itself, and like with the object, the methods a
## Tuning performance for production
See [Tuning ProxyManager for Production](https://github.com/Ocramius/ProxyManager/blob/master/docs/tuning-for-production.md).
See [Tuning ProxyManager for Production](tuning-for-production.md).