【发布时间】:2016-09-15 13:33:39
【问题描述】:
我正在寻找一种方法来用 appserver.io SessionBeans 替换现有应用程序中的选择功能,但我找不到有关如何在普通 php 类中访问 SessionBean 的示例。
我有一个来自示例的超级简单的 Singleton SessionBean:
<?php
namespace MyVendor\MyApp;
/**
* @Singleton(name="MySingletonBean")
*/
class MySingletonBean extends \Stackable
{
protected $counter = 0;
public function raiseMe()
{
return $this->counter++;
}
}
在 Servlet 内的实现非常简单,而且工作起来很吸引人,但我找不到任何关于在 Servlet 外的普通 php 文件中访问它的文档。
我希望它非常简单,例如:
<?php
use MyVendor\MyApp\MySingletonBean;
class IndexController extends App
{
/**
* maybe some funky annotations...
*
* @var \MyVendor\MyApp\MySingletonBean
* @EnterpriseBean(name="MySingletonBean")
*/
protected $mySingletonBean;
public function index() {
// and then servlet style...
echo $this->mySingletonBean->raiseMe();
// ... or like this?
echo MySingletonBean::getInstance()->raiseMe();
}
}
有人可以指点我正确的方向吗?
谢谢,
彼得
【问题讨论】: