From 07c258ab9275f0bd3a738dd08c4f1f6b9834720c Mon Sep 17 00:00:00 2001 From: Kevin van Hoorn Date: Tue, 18 Jul 2017 20:17:27 +0200 Subject: [PATCH 1/3] replaced PropertyAccessor with dumb property altering --- src/SM/StateMachine/StateMachine.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/SM/StateMachine/StateMachine.php b/src/SM/StateMachine/StateMachine.php index 6b785c2..4925b54 100644 --- a/src/SM/StateMachine/StateMachine.php +++ b/src/SM/StateMachine/StateMachine.php @@ -156,8 +156,9 @@ public function apply($transition, $soft = false) */ public function getState() { - $accessor = new PropertyAccessor(); - return $accessor->getValue($this->object, $this->config['property_path']); + return $this->object->{$this->config['property_path']}; + // $accessor = new PropertyAccessor(); + // return $accessor->getValue($this->object, $this->config['property_path']); } /** @@ -205,8 +206,9 @@ protected function setState($state) )); } - $accessor = new PropertyAccessor(); - $accessor->setValue($this->object, $this->config['property_path'], $state); + $this->object->{$this->config['property_path']} = $state; + // $accessor = new PropertyAccessor(); + // $accessor->setValue($this->object, $this->config['property_path'], $state); } /** From a76b9d4814172db46966c8fde9829038f3db252e Mon Sep 17 00:00:00 2001 From: Kevin van Hoorn Date: Tue, 18 Jul 2017 23:08:44 +0200 Subject: [PATCH 2/3] other approach dumb property setting --- src/SM/StateMachine/StateMachine.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SM/StateMachine/StateMachine.php b/src/SM/StateMachine/StateMachine.php index 4925b54..d0d68c3 100644 --- a/src/SM/StateMachine/StateMachine.php +++ b/src/SM/StateMachine/StateMachine.php @@ -156,7 +156,9 @@ public function apply($transition, $soft = false) */ public function getState() { - return $this->object->{$this->config['property_path']}; + $property = $this->config['property_path']; + return $this->object->$property; + // $accessor = new PropertyAccessor(); // return $accessor->getValue($this->object, $this->config['property_path']); } @@ -206,7 +208,9 @@ protected function setState($state) )); } - $this->object->{$this->config['property_path']} = $state; + $property = $this->config['property_path']; + $this->object->$property = $state; + // $accessor = new PropertyAccessor(); // $accessor->setValue($this->object, $this->config['property_path'], $state); } From da5c9d62248afe8c8a6a6019ed0aeaa630337a99 Mon Sep 17 00:00:00 2001 From: Kevin van Hoorn Date: Wed, 19 Jul 2017 07:57:15 +0200 Subject: [PATCH 3/3] added getConfig to get raw config - needed to retrieve other values from object config --- spec/SM/StateMachine/StateMachineSpec.php | 10 ++++++++ src/SM/StateMachine/StateMachine.php | 25 +++++++++++-------- src/SM/StateMachine/StateMachineInterface.php | 7 ++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/spec/SM/StateMachine/StateMachineSpec.php b/spec/SM/StateMachine/StateMachineSpec.php index 5324cd0..1b34d61 100644 --- a/spec/SM/StateMachine/StateMachineSpec.php +++ b/spec/SM/StateMachine/StateMachineSpec.php @@ -194,6 +194,16 @@ function it_returns_current_object($object) $this->getObject()->shouldReturn($object); } + function it_returns_current_config() + { + $this->getConfig()->shouldReturn($this->config); + } + + function it_returns_current_config_item() + { + $this->getConfig('graph')->shouldReturn($this->config['graph']); + } + function it_returns_possible_transitions($object, $callbackFactory, CallbackInterface $guard) { $object->getState()->shouldBeCalled()->willReturn('checkout'); diff --git a/src/SM/StateMachine/StateMachine.php b/src/SM/StateMachine/StateMachine.php index d0d68c3..4c6c83e 100644 --- a/src/SM/StateMachine/StateMachine.php +++ b/src/SM/StateMachine/StateMachine.php @@ -156,11 +156,8 @@ public function apply($transition, $soft = false) */ public function getState() { - $property = $this->config['property_path']; - return $this->object->$property; - - // $accessor = new PropertyAccessor(); - // return $accessor->getValue($this->object, $this->config['property_path']); + $accessor = new PropertyAccessor(); + return $accessor->getValue($this->object, $this->config['property_path']); } /** @@ -171,6 +168,17 @@ public function getObject() return $this->object; } + /** + * {@inheritDoc} + */ + public function getConfig($key = null) + { + if ($key == null) { + return $this->config; + } + return $this->config[$key]; + } + /** * {@inheritDoc} */ @@ -208,11 +216,8 @@ protected function setState($state) )); } - $property = $this->config['property_path']; - $this->object->$property = $state; - - // $accessor = new PropertyAccessor(); - // $accessor->setValue($this->object, $this->config['property_path'], $state); + $accessor = new PropertyAccessor(); + $accessor->setValue($this->object, $this->config['property_path'], $state); } /** diff --git a/src/SM/StateMachine/StateMachineInterface.php b/src/SM/StateMachine/StateMachineInterface.php index b09da5f..1c08a1f 100644 --- a/src/SM/StateMachine/StateMachineInterface.php +++ b/src/SM/StateMachine/StateMachineInterface.php @@ -52,6 +52,13 @@ public function getState(); */ public function getObject(); + /** + * Returns the whole config + * + * @return object + */ + public function getConfig($key = null); + /** * Returns the current graph *