定制 emc/xmlhttprequest-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

emc/xmlhttprequest-bundle

Composer 安装命令:

composer require emc/xmlhttprequest-bundle

包简介

This bundle gives a unified way to handle and control AJAX requests. For more informations https://github.com/chafiq/EMCXmlHttpRequest/blob/master/README.md

README 文档

README

This bundle gives a unified way to handle and control AJAX requests.

Installation

  1. Download EMCXmlHttpRequest
  2. Configure the Autoloader
  3. Enable the Bundle

Step 1: Download EMCXmlHttpRequest

Ultimately, the EMCXmlHttpRequest files should be downloaded to the vendor/bundles/EMC/Bundle/XmlHttpRequest directory.

This can be done in several ways, depending on your preference. The first method is the standard Symfony2 method.

Using Composer

Add EMCXmlHttpRequest in your composer.json:

{
    "require": {
        "emc/xmlhttprequest-bundle": "*"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update emc/xmlhttprequest-bundle

Using submodules

If you prefer instead to use git submodules, then run the following:

$ git submodule add git://github.com/chafiq/EMCXmlHttpRequest.git vendor/emc/xmlhttprequest-bundle/EMC/XmlHttpRequestBundle/
$ git submodule update --init

Note that using submodules requires manually registering the EMC namespace to your autoloader:

<?php
// app/autoload.php

$loader->registerNamespaces(array(
    // ...
    'EMC' => __DIR__.'/../vendor/bundles',
));

Step 2: Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new EMC\Bundle\XmlHttpRequestBundle\EMCXmlHttpRequestBundle(),
    );
}

Dependances

Exemples

Simple Post

Controller Code

    use EMC\XmlHttpRequestBundle\Annotation\XmlHttpRequest;

    /**
     * @Route("/ajax/", name="_ajax_call")
     * @XmlHttpRequest(type="json") // You can add streaming=true to get the streaming mode
     */
    public function ajaxAction()
    {
    	/**
    	 * Data result
    	 * mixed
    	 * The response will be "{code:0,data:{1:'My result',2:'My fancy bundle',5:'My reponse'}}"
    	 */
        return array(
        	1 => 'My result',
        	2 => 'My fancy bundle',
        	5 => 'My reponse'
        );
    }

Template Code

...
	<script type="text/javascript">
		$(document).ready(function(){
		
			var params = {test : 123};
			
			/* "xml_http_request" is a twig extension.
			   It creates the JavaScript call using the route annotation "XmlHttpRequest".
			   The first and second parameters are used for creating the route path.
			   The third parameter is the name of data source parameters for the ajax call.
			   You can add a fourth parameter which is the name of the JS callback.
			   
			   @see @EMCXmlHttpRequestBundle\Twig\XmlHttpRequestExtension for more information
			   
			   The generated code of "{% xml_http_request('_ajax_call', {}, 'params') %}" is :
			   
			   EMCXmlHttpRequest.getInstance().stream("http://www.dev.local/app_dev.php/demo/ajax/", params, "json", null);
			*/
			var result = {% xml_http_request('_ajax_call', {}, 'params') %}
			
			console.log( result );
		});
	</script>
...

Streaming Informations

Controller Code

    use EMC\XmlHttpRequestBundle\Annotation\XmlHttpRequest;
    use EMC\XmlHttpRequestBundle\Event\StreamingProgress;

    /**
     * @Route("/ajax/", name="_ajax_call")
     * @XmlHttpRequest(type="json", streaming=true)
     */
    public function ajaxAction()
    {
    
    	for($i=0; $i<5; $i++) {
    		
    		$event = new StreamingProgress($i*20, 'Execution message info ' . ($i*20) . '% ...');
    		
    		$this->get('event_dispatcher')->dispatch( 'emc.streaming.progress', $event);
    		
    		sleep(1);
    	}
    	
        return array(
        	1 => 'My result',
        	2 => 'My fancy bundle',
        	5 => 'My reponse'
        );
    }

Template Code

Same then the first exemple.

emc/xmlhttprequest-bundle 适用场景与选型建议

emc/xmlhttprequest-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 206 次下载、GitHub Stars 达 2, 最近一次更新时间为 2012 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ajax」 「xmlhttprequest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 emc/xmlhttprequest-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 emc/xmlhttprequest-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 emc/xmlhttprequest-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 206
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 37
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-12-06