matt_falcon Posted August 7, 2008 Share Posted August 7, 2008 In need to produce a component where by a data set supercedes another, and that the user always sees the superceded value. For example: X --> Y --> Z As X is superceded by Y and then Z supercedes Y then the need to just view the latest value is onle needed, example: X --> Z Please can anyone help? Link to comment https://forums.phpfreaks.com/topic/118627-supersession/ Share on other sites More sharing options...
genericnumber1 Posted August 7, 2008 Share Posted August 7, 2008 I don't really understand. When it comes to data stored in variables, the newly added data has always superseded the old data... can you explain more thoroughly? Link to comment https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611197 Share on other sites More sharing options...
matt_falcon Posted August 8, 2008 Author Share Posted August 8, 2008 Basically we have a number of different models which usually over time get replaced byanother model, meaninf it can be super ceded several times! So the result should be that the latest model should be shown, not the first model in the supersession series, e.g. model A gets super ceded by B, then by C. Therefore model A should show model C as the supersession model, not B. Please can you can Link to comment https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611403 Share on other sites More sharing options...
448191 Posted August 8, 2008 Share Posted August 8, 2008 Your question is a bit vague, but maybe this is what you are looking for? <?php /** * Chain of Responsibilty * */ class DataChain { /** * Internal data * * @var array */ private $_data = array(); /** * Successor DataChain * * @var DataChain */ private $_successor; /** * Set the successor * * @param DataChain $successor */ public function setSuccessor(DataChain $successor) { $this->_successor = $successor; } /** * Get data by key * * @param string|int $key */ public function get($key) { if(isset($this->_data[$key])) { return $this->_data[$key]; } if($this->_successor !== null) { return $this->_successor->get($key); } return null; } /** * Set data by key * * @param string|int $key * @param mixed $value */ public function set($key, $value) { return $this->_data[$key] = $value; } } ?> Edit: Probably you want this: /** * Get data by key * * @param string|int $key */ public function get($key) { if($this->_successor !== null) { return $this->_successor->get($key); } if(isset($this->_data[$key])) { return $this->_data[$key]; } return null; } It's no longer a Chain of Responsibility (rather the reverse), but if I understand correctly, this is what you are after. Link to comment https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611505 Share on other sites More sharing options...
matt_falcon Posted August 8, 2008 Author Share Posted August 8, 2008 Thanks for the code! This is exactly what I was looking for . Your help has been greatly appreciated Kind Regards Link to comment https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611583 Share on other sites More sharing options...
448191 Posted August 8, 2008 Share Posted August 8, 2008 You're welcome, though I don't really see in what situation you would want this. I'm pretty sure there is a better solution to the underlying problem... Link to comment https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611692 Share on other sites More sharing options...
matt_falcon Posted August 8, 2008 Author Share Posted August 8, 2008 Well the situation is that we want our users to have access to the latest model of our product, not only do we want users to be able to view old models but a link to the latest model that super cedes that old model. Hopefully that gives you a better reason to why! Again thanks for you time. Link to comment https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.