satooshi/symfony2contrib-http-foundation-extra-bundle

Symfony2 contrib http foundation extra bundle

Maintainers

👁 satooshi

Package info

github.com/satooshi/ContribHttpFoundationExtraBundle

Type:symfony-bundle

pkg:composer/satooshi/symfony2contrib-http-foundation-extra-bundle

Statistics

Installs: 32

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

0.1.1 2013-01-21 11:21 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 44b49a270d04f54a0e6a2f4d06eeac3061dd254f

contrib

This package is not auto-updated.

Last update: 2026-06-20 20:14:51 UTC


README

Install

See Packagist.

Annotation Usage

This bundle contains the following annotations.

  • @File: force to download a file.
  • @Json: create JsonResponse from controller result.
    • Content-Type is
      • application/json for json response
      • text/javascript for jsonp response
# Acme/Bundle/Controller/SiteController.php

use Contrib\Bundle\HttpFoundationExtraBundle\Configuration\File;
use Contrib\Bundle\HttpFoundationExtraBundle\Configuration\Json;

/**
 * @Route("/site")
 */
class SiteController
{
 /**
 * @Route("/csv", name="site_csv")
 * @Method("GET")
 * @File(filename = "test.csv", charset = "Shift_JIS")
 */
 public function csvAction()
 {
 $content = 'item1,item2';

 return array(
 'content' => $content,

 // read file in FileResponse and ignore content if this was set to controller result
 //'path' => './test.csv', 
 );
 }

 /**
 * @Route("/json", name="site_json")
 * @Method("GET")
 * @Json
 */
 public function jsonAction()
 {
 	// result response
 	// {"prop1":"value1","prop2":"value2"}
 return array(
 	'prop1' => 'value1',
 	'prop2' => 'value2'
 );
 }

 /**
 * @Route("/jsonp", name="site_jsonp")
 * @Method("GET")
 * @Json(callbackName = "jsoncallback")
 */
 public function jsonpAction()
 {
 	// request
 	// /site/jsonp?jsoncallback=mycallback
 	// response
 	// mycallback({"prop1":"value1","prop2":"value2"});
 return array(
 	'prop1' => 'value1',
 	'prop2' => 'value2'
 );
 }
}

@File parameters

  • filename: required if "content" was set to controller result. optional if "path" was set. used for "Content-Disposition" HTTP header
  • charset: optional charactor encoding. used for "Content-Type" HTTP header
  • mimeType: optional mime type. default value is "application/octet-stream". used for "Content-Type" HTTP header

@Json parameters

  • callbackName: optional callback request parameter name (default value: callback).
  • serialize: optional boolean whether to use serializer (jms/serializer).
  • serializeGroups: optional array to use serialize group.

todo

  • avoid HTTP header conflict if it has already been set
  • add supecific file type annotation support (@Plain, @Csv, @Pdf, @Zip, and so on)
  • add rendering template functionality as the same as @Template
  • add DependencyInjection/Cofiguration to support default parameter configuration
  • add unit test