【发布时间】:2015-12-12 01:50:15
【问题描述】:
当我打电话时,下面的独立命令应用程序可以正常工作:php console.php say:hello MyName
问题在底部。
/var/www/html/local/test-app/composer.json
{
"name": "my/test-package",
"description": "......",
"type": "library",
"version": "1.0.0",
"autoload": {
"psr-0": {"": ""}
},
"require": {
"symfony/console": "2.*"
},
"minimum-stability": "stable"
}
/var/www/html/local/test-app/Command/HelloCommand.php
<?php
namespace Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class HelloCommand extends Command
{
protected function configure()
{
$this
->setName('say:hello')
->setDescription('Say hello to someone')
->addArgument(
'name',
InputArgument::OPTIONAL,
'Who do you want to say hello?'
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
$hello = $name ? 'Hello '.$name : 'Hello';
$output->writeln($hello);
}
}
/var/www/html/local/test-app/console.php
#!/usr/bin/env php
<?php
require __DIR__.'/vendor/autoload.php';
use Command\HelloCommand;
use Symfony\Component\Console\Application;
$application = new Application();
$application->add(new HelloCommand());
$application->run();
问题
当我在主项目的 composer.json 中包含独立包时,composer 会安装所有内容,但当我调用 php console.php say:hello MyName 时,我收到 Could not open input file: console.php 错误。显然,我必须在 bin 目录中创建一个符号链接,例如 behat、phing、phpspec、doct 等,但是如何?
我主要项目的composer json
"require": {
"my/test-package": "dev-master"
},
我已经检查过:
- The Console Component
- step-by-step how to use a single component in your project
- Symfony2 Components as standalone Packages
- https://github.com/exu/symfony2-console-standalone
- Command line PHP using Symfony Console
等等……
【问题讨论】:
-
我认为这里没有魔法,你不在正确的目录中,或者
console.php的权限不正确。 -
这与 Symfony 相关的任何东西都无关——每当您使用不存在的文件调用 php 时都会出现该错误:
$ php DoesNotExist.php输出Could not open input file: DoesNotExist.php。否则,请检查以确保console.php具有 读取 权限。
标签: php symfony composer-php