|
I ran into a problem while writing a custom feed writer extension (a subclass of \Zend\Feed\Writer\Extension\ITunes\Entry). It contains these methods: public function addDCFormat($format) { $this->dcFormats[] = $format; } public function getDCFormats() { return $this->dcFormats; } I noticed that each entry in my feed contained all of the formats from all of the previous feeds. Apparently the data is persisting in the plug-in even though I would expect it to be reset every time you create a new entry. One solution is to change Zend\Feed\Writer\Entry so that it clones extensions in the _loadExtensions() method rather than using references to the same instances: protected function _loadExtensions() { $all = Writer::getExtensions(); $manager = Writer::getExtensionManager(); $exts = $all['entry']; foreach ($exts as $ext) { $this->_extensions[$ext] = clone($manager->get($ext)); $this->_extensions[$ext]->setEncoding($this->getEncoding()); } } However, without being more familiar with the code, I’m not sure if this will cause other problems. Is this a bug? If so, I’ll send a PR. Is this not a bug? If so, is there a simple workaround for the problem of data persisting in the plug-in between entries? I could add an explicit reset method and call it between creating entries, but this seems like it should be handled
automatically somehow. thanks, |
|
Administrator
|
Just a followup -- we resolved this in IRC.
The ExtensionManager has the shareByDefault flag disabled. Demian was trying to add an extension _instance_ using setService() -- which basically is a NO-OP, due to no shared services. Changing his usage to call setInvokableClass() instead solved the problem. -- Demian Katz <[hidden email]> wrote (on Tuesday, 31 July 2012, 03:32 PM +0000): > I ran into a problem while writing a custom feed writer extension (a subclass > of \Zend\Feed\Writer\Extension\ITunes\Entry). It contains these methods: > > > > public function addDCFormat($format) > > { > > $this->dcFormats[] = $format; > > } > > > > public function getDCFormats() > > { > > return $this->dcFormats; > > } > > > > I noticed that each entry in my feed contained all of the formats from all of > the previous feeds. Apparently the data is persisting in the plug-in even > though I would expect it to be reset every time you create a new entry. > > > > One solution is to change Zend\Feed\Writer\Entry so that it clones extensions > in the _loadExtensions() method rather than using references to the same > instances: > > > > protected function _loadExtensions() > > { > > $all = Writer::getExtensions(); > > $manager = Writer::getExtensionManager(); > > $exts = $all['entry']; > > foreach ($exts as $ext) { > > $this->_extensions[$ext] = clone($manager->get($ext)); > > $this->_extensions[$ext]->setEncoding($this->getEncoding()); > > } > > } > > > > However, without being more familiar with the code, I’m not sure if this will > cause other problems. > > > > Is this a bug? If so, I’ll send a PR. > > > > Is this not a bug? If so, is there a simple workaround for the problem of data > persisting in the plug-in between entries? I could add an explicit reset > method and call it between creating entries, but this seems like it should be > handled automatically somehow. > > > > thanks, > Demian > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
| Powered by Nabble | Edit this page |
