June 2017
Intermediate to advanced
536 pages
9h 49m
English
The registry pattern is an interesting one. It allows us to store and retrieve objects for later use. The process of storing and retrieving is based on the keys we define. Depending on the data scope, the association of keys and objects is made global across a process, thread, or a session, allowing us to retrieve the objects from anywhere within the data scope.
The following example demonstrates a possible registry pattern implementation:
<?phpclass Registry{ private $registry = []; public function get($key) { if (isset($this->registry[$key])) { return $this->registry[$key]; } return null; } public function set($key, $value, $graceful = false) { if (isset($this->registry[$key])) { if ($graceful) { return; } throw new ...
Read now
Unlock full access