Doctrine命令行忽略输入

时间:2016-08-26 09:31:29

标签: php doctrine-orm doctrine

我在wordpress-plugin中使用了doctrine。但是,命令行工具无法正常工作。 它似乎忽略了所有输入或参数,只是一直显示默认的帮助文本,无论我输入什么。

PHP版本是7.0.7。

我的cli-config(位于vendor / orm / bin / config中)的内容如下所示:

<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;

require_once __DIR__ . '/../../../../../doctrine-bootstrap.php';

$spmm = new doctrineBootstrap();

$entityManager = $spmm->getEntityManager();

return ConsoleRunner::createHelperSet($entityManager);

?>

引导程序本身的内容:

<?php

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

class doctrineBootstrap {

    private $entityManager;

    public function __construct() {
        $this->initDoctrine();
    }

    private function initDoctrine() {
        $paths = array("/model");
        $isDevMode = false;

        // the connection configuration
        $dbParams = array(
            'host' => 'XXXX',
            'driver'   => 'pdo_mysql',
            'user'     => 'XXXX',
            'password' => 'XXXX',
            'dbname'   => 'XXXX',
        );

        $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
        $this->entityManager = EntityManager::create($dbParams, $config);
    }

    public function getEntityManager() {
        return $this->entityManager;
    }
}

命令本身不会向控制台输出任何错误,但在php errorlog中会出现此错误:

[26-Aug-2016 11:17:26 Europe/Berlin] PHP Notice:  Undefined index: argv in /html/wordpress/wp-content/plugins/wp-openimmo/vendor/symfony/console/Input/ArgvInput.php on line 55
[26-Aug-2016 11:17:26 Europe/Berlin] PHP Warning:  array_shift() expects parameter 1 to be array, null given in /html/wordpress/wp-content/plugins/wp-openimmo/vendor/symfony/console/Input/ArgvInput.php on line 59
[26-Aug-2016 11:17:26 Europe/Berlin] PHP Warning:  Invalid argument supplied for foreach() in /html/wordpress/wp-content/plugins/wp-openimmo/vendor/symfony/console/Input/ArgvInput.php on line 276
[26-Aug-2016 11:17:26 Europe/Berlin] PHP Warning:  Invalid argument supplied for foreach() in /html/wordpress/wp-content/plugins/wp-openimmo/vendor/symfony/console/Input/ArgvInput.php on line 276
[26-Aug-2016 11:17:26 Europe/Berlin] PHP Warning:  Invalid argument supplied for foreach() in /html/wordpress/wp-content/plugins/wp-openimmo/vendor/symfony/console/Input/ArgvInput.php on line 276

我有点困惑,因为关于此的文档并不是很清楚。我如何让它运作?

1 个答案:

答案 0 :(得分:0)

好的,我发现了导致我问题的原因:

最后,它是getcwd()php_cli vs php的路径问题,并通过php.ini禁用错误输出。

正如我在我的问题中提到的,我的cli-config位于vendor/orm/bin/config,如果您想使用php运行命令,这是正确的。

如果你使用php_cli运行命令,它需要在当前目录中执行命令的配置文件。当我第一次尝试使用php_cli时,我根本没有得到任何响应。所以我用命令尝试了php_cli -n并得到了关于丢失cli-config.php的错误。所以我复制了文件,瞧,它的工作原理。我只是没有看到错误消息,因为默认情况下禁用了错误输出。

但是,如果要使用php运行它,请确保在php.ini中将register_argc_argv指令设置为ON。