From 65358ecdb30e8f2442857c4661692de82512bc81 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 28 Jan 2016 17:29:39 +0100 Subject: [PATCH] #272 - Example of ghost object skipped properties --- examples/ghost-object-skipped-properties.php | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/ghost-object-skipped-properties.php diff --git a/examples/ghost-object-skipped-properties.php b/examples/ghost-object-skipped-properties.php new file mode 100644 index 000000000..f1eb9f952 --- /dev/null +++ b/examples/ghost-object-skipped-properties.php @@ -0,0 +1,51 @@ +id; + } + + public function getUsername() : string + { + return $this->username; + } +} + +/* @var $proxy User */ +$proxy = (new LazyLoadingGhostFactory())->createProxy( + User::class, + function (GhostObjectInterface $proxy, string $method, array $parameters, & $initializer, array $properties) { + $initializer = null; + + var_dump('Triggered lazy-loading!'); + + $properties["\0User\0username"] = 'Ocramius'; + + return true; + }, + [ + 'skippedProperties' => [ + "\0User\0id", + ], + ] +); + +$idReflection = new \ReflectionProperty(User::class, 'id'); + +$idReflection->setAccessible(true); +$idReflection->setValue($proxy, 123); + +var_dump($proxy->getId()); +var_dump($proxy->getUsername());