Cakephp 3:React/zmq库名称空间 [英] Cakephp 3: React/zmq library namespace

查看:140
本文介绍了Cakephp 3:React/zmq库名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究此处提到的使用棘轮的基本教程 http://socketo.me/docs/推.

I am working on on the basic tutorial on using ratchet mentioned here http://socketo.me/docs/push.

我已经为该教程创建了可以完美运行的测试设置.但是,当我尝试将安装程序与CakePHP 3集成时,我遇到了问题.棘轮服务器和ZMQ服务器是独立的,就像本教程中提到的那样.只需将以下代码移入CakePHP 3控制器即可:

I have created a test setup for the tutorial that works flawlessly. However, when I am trying to integrate the setup with CakePHP 3 I am running into problems. The ratchet and ZMQ servers are independent just the way mentioned in the tutorial. Only the following piece of code needs to move into CakePHP 3 controllers:

$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH, 'my pusher');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($entryData));

此代码基本上将新数据提交到ZMQ队列以转发到棘轮.如果我将相同的4行放在CakePHP 3代码库之外的纯PHP文件中,那么它将起作用.当我在APP \ Controller \ SamplesController中放置相同的四行时,它说未找到类APP \ Controller \ ZMQContext.

This code basically submits new data to ZMQ queue for forwarding to ratchet. If I place the same 4 lines in a plain PHP file outside CakePHP 3 codebase it works. When I place the same four lines inside APP\Controller\SamplesController it says the class APP\Controller\ZMQContext not found.

CakePHP 3文档提到通过composer安装的供应商库将通过自动加载器自动提供.我已经通过以下命令安装了React \ ZMQ库:

CakePHP 3 docs mention that vendor libraries installed via composer will be automatically available through autoloader. I have installed React\ZMQ library via following command:

php composer require react/zmq

我尝试通过以下命名空间访问该类,但是它们都没有起作用:

I have tried accessing the class via following namespaces but none of them have worked:

ZMQContext ( Class 'App\Controller\ZMQContext' not found )
\ZMQContext ( Class 'App\Controller\ZMQ' not found )
React\ZMQ\ZMQContext ( Class 'App\Controller\React\ZMQ\ZMQContext' not found )
\React\ZMQ\ZMQContext ( Class 'React\ZMQ\ZMQContext' not found )

在PHP中可能缺少某些命名空间概念,但是我的理解是,如果通过全局命名空间在常规PHP文件中可以使用ZMQContext,那么在CakePHP 3中通过\ ZMQContext也可以使用ZMQContext.

Probably missing out on some namespace concept in PHP but my understanding is that if ZMQContext is available in a normal PHP file through global namespace, then it should also be available within CakePHP 3 via \ZMQContext.

我有以下问题:

  1. 如何在CakePHP 3 APP中将数据推送到ZMQ队列?
  2. APP :: path()& APP :: classname()似乎仅适用于CakePHP 3应用程序中的类.如何检查特定供应商库类的路径?
  3. 如何正确自动加载供应商库类? (我不希望要求/要求它们,因为需要对每个要通过棘轮发布数据的控制器执行此操作)
  4. 关于通过\ CLASSNAME访问全局名称空间的假设是否错误?
  5. 我第二次尝试访问\ ZMQContext上的供应商库类的问题解析为App \ Controller \ ZMQ.应该在根名称空间中尝试该怎么办?
  6. ZMQContext不是react/zmq库的一部分,这是否意味着它是libzmq的默认php绑定的一部分?
  1. How can I push data to ZMQ Queue within my CakePHP 3 APP ?
  2. APP::path() & APP::classname() seems to work only for classes within the CakePHP 3 application. How to check path for a particular vendor library class ?
  3. How to autoload vendor library classes correctly ? (I do not wish to require/require_once them as it will needed to be done for each controller that wants to publish data via ratchet)
  4. Is the assumption about accessing global namespace via \CLASSNAME wrong ?
  5. My second attempt at accessing vendor library class at \ZMQContext resolved to App\Controller\ZMQ. How is that possible when it should have attempted within root namespace ?
  6. ZMQContext is not part of react/zmq library so does it mean it part of default php bindings for libzmq ?

推荐答案

这是一个简单的错字问题:

This was a simple typo problem:

$context = new \ZMQContext();
$socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
$socket->connect("tcp://localhost:5555");
$socket->send(json_encode($entryData));

第二行中的第二个名称空间规范丢失.

The second namespace specification in second line was missing.

这篇关于Cakephp 3:React/zmq库名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆