来自PHP的dump-autoload命令 [英] dump-autoload command from php

查看:62
本文介绍了来自PHP的dump-autoload命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Web应用程序,用户可以动态地从Web浏览器上载Controllers php文件.所有这一切都有问题.

I am building a web application where the user dynamically can upload Controllers php files from the web browser. There is a problem in all of this.

由于应该编译每个类以便在laravel内部使用,因此必须执行命令composer dump-autoload.但是我不想从终端手动执行此操作.在注册类"内部,我明确地调用了一些对我不起作用的命令,例如:

Since every class should be compiled in order be used inside of laravel, the commmand composer dump-autoload must be executed. But I do not want to do this manually from the terminal. Inside of a "register class" I have called explicitly some commands that have not worked for me, for example:

  • Artisan::call('dump-autoload');
  • exec("/path/to/app/composer dump-autoload");
  • shell_exec('php artisan dump-autoload');
  • shell_exec('composer dump-autoload');
  • Artisan::call('dump-autoload');
  • exec("/path/to/app/composer dump-autoload");
  • shell_exec('php artisan dump-autoload');
  • shell_exec('composer dump-autoload');

仍然找不到新的控制器.所以,我不知道我在想什么.或者,如果还有另一种动态加载"我的类的方法.

The new controllers are still not being found. So, I do not know what I am missing. Or if there is another way to "load" my classes dynamically.

  1. 安全隐患:当然,但是我的问题是广泛开放的,可以在执行时动态识别新类
  2. 我完全确定路径,我已经从linux终端测试了每个问题,并且一切正常(使用绝对路径和相对路径).由于这些原因,我寻找另一个原因而不是路径.
  3. Don't forget to actually 'require' or 'include' the class after you compile it当然,该文件已包含并由第2点确认.
  4. 这看起来很可疑:

  1. Security implications: of course, but my question is widely open to dynamically recognize new classes in execution time
  2. I am completely sure about paths, I have tested every issue from a linux terminal and all worked fine (with absolute and relative path). For these reasons, I look for another reason instead of paths.
  3. Don't forget to actually 'require' or 'include' the class after you compile it Sure, the file is included and confirmed by the point 2.
  4. This looks suspicious:

我的猜测是运行php的用户没有足够的特权来执行操作或写入所需的目录

my off-the-cuff guess would be that the user running php doesn't have sufficient privileges to perform the operation or write to the required directories

但是,怎么可能php没有足够的特权,可能会影响composer dump-autoclass命令?

However, how could it be possible that php doesn't have enough privileges, could be it affects the composer dump-autoclass command?

Apache/2.4.9(Fedora)PHP/5.5.12

Apache/2.4.9 (Fedora) PHP/5.5.12

推荐答案

要解决这个问题,您可以执行以下操作:

Well to work this out you can do this:

exec("composer dump-autoload -d /path/to/laravel-project/");

您必须明确告诉作曲家在哪里寻找composer.json.

You have to explicitly tell composer where to look for composer.json.

-d如果指定,则使用给定目录作为工作目录

-d If specified use the given directory as working directory

如果没有-d选项,作曲家将假定您的composer.json生活在path/to/laravel-project/public/中.因为所有请求都路由到前端控制器index.php,因此当前工作目录为public/

Without -d option, composer assumes your composer.json lives in path/to/laravel-project/public/. Because all requests are routed to front controller index.php and by that mean the current working directory is public/

这篇关于来自PHP的dump-autoload命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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