2017 © Pedro Peláez
 

library ap-xml-strategy

XmlStrategy for Zend Framework 2. AP_XmlStrategy select the Xml Render if the ViewModel is an XmlModel or if the Accept header contains 'application/xml' media type.

image

ap/ap-xml-strategy

XmlStrategy for Zend Framework 2. AP_XmlStrategy select the Xml Render if the ViewModel is an XmlModel or if the Accept header contains 'application/xml' media type.

  • Thursday, November 14, 2013
  • by alessandropietrobelli
  • Repository
  • 0 Watchers
  • 3 Stars
  • 11,440 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

AP_XmlStrategy

Version 1.0.0 created by Alessandro Pietrobelli, (*1)

Description

Like the latest changes on Zend Framework 2.0.4 version, AP_XmlStrategy select the Xml Render if the ViewModel is an XmlModel or if the Accept header contains "application/xml" media type. Using the new controller plugin acceptableViewModelSelector() you can select and set the appropriate ViewModel if Accept header meets criteria you specify, (*2)

Require

PHP >= 5.3.3, (*3)

Zend Framework >= 2.0.4, (*4)

Installation

with Composer

Add "ap/ap-xml-strategy": "dev-master" to your composer.json file and run php composer.phar update., (*5)

with Git submodule

Clone this project to your ```./vendor/`` directory:, (*6)

git submodule add git://github.com/alessandropietrobelli/AP_XmlStrategy.git vendor/AP_XmlStrategy

enable it on your application.config.php file

<?php
return array(
    'modules' => array(
        // ...
        'AP_XmlStrategy',
    ),
    // ...
);

Post Installation

Like on Zend Framework 2.0.4 change log example, (*7)

<?php
namespace SomeNamespace\Controller;

use Zend\View\Model\JsonModel;
use Zend\View\Model\FeedModel;
use AP_XmlStrategy\View\Model\XmlModel;

class SomeController extends AbstractActionController
{
    protected $acceptCriteria = array(
        'Zend\View\Model\JsonModel' => array(
            'application/json',
        ),
        'Zend\View\Model\FeedModel' => array(
            'application/rss+xml',
        ),
        'AP_XmlStrategy\View\Model\XmlModel' => array(
            'application/xml',
        ),
    );

    public function apiAction()
    {
        $viewModel = $this->acceptableViewModelSelector($this->acceptCriteria);

        if ($viewModel instanceof JsonModel) {
            return new JsonModel(array(
                'response' => 'foo',
                )
            );
        }

        if ($viewModel instanceof FeedModel) {
            return new FeedModel(array( 
                'response' => 'foo',
                )
            );
        }

        if ($viewModel instanceof XmlModel){
            return new XmlModel(array( 
                'response' => 'foo',
                )
            );
        }
    }
}

The Versions

14/11 2013

dev-master

9999999-dev http://github.com/alessandropietrobelli/AP_XmlStrategy

XmlStrategy for Zend Framework 2. AP_XmlStrategy select the Xml Render if the ViewModel is an XmlModel or if the Accept header contains 'application/xml' media type.

  Sources   Download

MIT

The Requires

 

xml zf2 zendframework strategy xmlstrategy