简体   繁体   English

在Laravel中加载phpBB代码冲突

[英]Loading phpBB in Laravel code conflicts

I am trying to access some of the functions within phpBB from my Laravel application, this is for actions such as adding a user when a registration happens on my main site and autologins. 我试图从我的Laravel应用程序访问phpBB中的一些函数,这是为了在我的主站点和自动登录发生注册时添加用户等操作。

PhpBB is installed under /public/forums and I have updated .htaccess to allow it. PhpBB安装在/public/forums ,我更新了.htaccess以允许它。 I am able to access and use it just fine. 我能够访问并使用它就好了。

I have a helper that was originally constructed for codeigniter but should translate in to the laravel world. 我有一个最初为codeigniter构建的帮助器,但应该转换到laravel世界。 I am loading it as a helper by putting it under app, loading it using 我将它作为助手加载,将其置于应用程序下,使用它加载它

use App\Helpers\phpBBHelper;

and I access the functions as such 我这样访问这些功能

   $ph = new phpBBHelper();
   $ph->addPhpbb3User('dave','password','dave@dave.com');

At the top of my helper I have this constructor 在我的助手的顶部,我有这个构造函数

public function __construct() {

    // Set the variables scope
    global $phpbb_root_path, $phpEx, $cache, $user, $db, $config, $template, $table_prefix;

    define('IN_PHPBB', TRUE);
    define('FORUM_ROOT_PATH', 'forum/');

    $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : FORUM_ROOT_PATH;
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    // Include needed files
    include($phpbb_root_path . 'common.' . $phpEx);

    // Initialize phpBB user session
    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    // Save user data into $_user variable
    $this->_user = $user;   
}

When i execute the code I get a server 500 error 当我执行代码时,我得到服务器500错误

PHP Fatal error:  Call to a member function getScriptName() on null in
/home/ubuntu/workspace/public/forum/phpbb/session.php on line 50

which is this line 这是这条线

$script_name = $request->escape($symfony_request->getScriptName(), true);

I have found a post on stack overflow that exactly refers to my issue but the resolution of that issue was never posted 我发现了一个关于堆栈溢出的帖子,它正好引用了我的问题,但该问题的解决方案从未发布过

Laravel conflicting Laravel相互矛盾

In that thread it was suggested that because both phpBB and Laravel both use composer it was causing a conflict when loading the classes. 在该线程中,有人建议因为phpBB和Laravel都使用composer,所以在加载类时会引起冲突。 I am not sure if that is true. 我不确定这是否属实。

But Laravel is certainly affecting phpBB when I call the $user->session_begin(); 但是当我调用$user->session_begin();时,Laravel肯定会影响phpBB $user->session_begin(); .

I would suggest to not reinvent the wheel and use already coded extension like lara-auth-bridge . 我建议不要重新发明轮子并使用已编码的扩展,如lara-auth-bridge The registration is simply inserting the right rows in the right tables, not familiar with phpBB3 in particular, but you could see the changes in the database after a new account is created. 注册只是在右表中插入右行,特别是不熟悉phpBB3,但是在创建新帐户后,您可以看到数据库中的更改。

Edit: You can surround the problematic code in try {} catch {} block in case that the error is not fatal for the registration itself so the server will not end up with 500. 编辑:您可以在try {} catch {}块中包围有问题的代码,以防错误对于注册本身而言是致命的,因此服务器不会以500结尾。

When two applications had to communicates, I updated the twice. 当两个应用程序必须通信时,我更新了两次。 PhpBB is written to be upgradable with extension. PhpBB编写为可扩展的可升级版本。 You can develop a phpBB extension which is an API to create a new user. 您可以开发一个phpBB扩展,它是一个用于创建新用户的API。

Your new extension uses XML-RPC over HTTP for all communications between your laravel app and the forum system. 您的新扩展程序使用基于HTTP的XML-RPC进行laravel应用程序和论坛系统之间的所有通信。 You define a route which receives informations about the new users and then you analyse the creation process in phpbb. 您定义一个接收有关新用户的信息的路由,然后分析phpbb中的创建过程。 This way is easier because you're inside the phpBB/symfony Framework. 这种方式更容易,因为你在phpBB / symfony框架内。

In your laravel application, you have to call the API to start communications. 在laravel应用程序中,您必须调用API以启动通信。

The error clearly indicates that the symfony_request object is null. 该错误清楚地表明symfony_request对象为null。 By browsing the source code a bit, I found that that variable (and many others) are expected to exist globally. 通过稍微浏览源代码,我发现该变量(以及许多其他变量)预计将全局存在。

It seems like you have to include the phpBB/app.php file. 好像你必须include phpBB/app.php文件。 It creates most of the objects needed. 它创建了大部分所需的对象。

update : 更新

Actually, you are including the common file which does most of the initial setup. 实际上,您正在包含执行大多数初始设置的common文件。 Maybe just making a global 也许只是做一个全球性的

$symfony_request = $phpbb_container->get('symfony_request');

will work. 将工作。 (I can't test it myself now, just throwing ideas) (我现在不能自己测试,只是投掷想法)


(If possible, though, I'd try another library. I don't like those globals. Nobody does. It makes tracing stuff and debugging harder, as this question shows) (如果可能的话,我会尝试另一个库。我不喜欢那些全局变量。没有人这样做。它使得跟踪和调试更加困难,正如这个问题所示)

To be able to get the session request, you have to be sure both the PhpBB forum and your Laravel application use the same kind of cookie : 为了能够获得会话请求,您必须确保PhpBB论坛和Laravel应用程序都使用相同类型的cookie:

  • Same domain 相同的域名
  • Same path 同样的道路
  • Same secure flag 相同的安全标志

Are these settings ok? 这些设置好吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM