ZF2 how to disable Zend\Feed\Writer\Feed extensions

Trying to create a simple rss feed in zend framework2 by using Zend\Feed\Writer\Feed:

$feed = new \Zend\Feed\Writer\Feed();


$out = $feed->export('rss');
echo $out;

And this will output:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <generator>Zend_Feed_Writer 2 (http://framework.zend.com)</generator>
      <pubDate>Fri, 11 Apr 2014 06:32:53 +0000</pubDate>
      <pubDate>Fri, 11 Apr 2014 06:32:53 +0000</pubDate>

My question is:

how to disable xmlns:slash extension <slash:comments>0</slash:comments>?


It's quite a mess in the Zend\Feed component with extensions. I have been messing around with it for a while.

What happens?

You construct a Zend\Feed\Writer\Feed. The Feed extends the Zend\Feed\Writer\AbstractFeed. In the __construct() of AbstractFeed happens this:

public function __construct()

Writer is here the Zend\Feed\Writer\Writer. The registerCoreExtensions looks as follows:

public static function registerCoreExtensions()

Here, you see the different extens are added to the static Writer instance. From there on, the _loadExtensions() call fetches all extensions registered from the Writer and imports them into the Feed. The same happens by the way in the AbstractRenderer.

How to fix?

Because internally inside the Feed and Renderer the registerCoreExtensions() is called, you cannot overwrite the default list of extensions. Also, the Feed and the Renderer do not have getters/setters for the extension. The only way I came up with is to write your own Feed object and Renderer object.

For the Feed object you create a getter/setter to remove the extensions you want. You also override export where you copy the contents of the method, but overwrite the $renderClass variable name to the render class of your own.

For the Renderer class you create a getter/setter to remove the extensions you want as well. This way, you can tune the extensions you need. It's not that pretty, but hopefully it's something improved upon in ZF3 :)

Need Your Help

C# groupbox visibility in windows form

c# winforms groupbox

I Googled around but seems my problem happens when two gropboxes are overlapping, in my case they are not overlapping!