我从Symfony 2.8中看到了一些非常奇怪的行为。我已经在一些标准的Symfony类中添加了一些echo
和var_dump
来尝试找出正在进行的操作。
这个Application
类扩展了下一个类。我添加了四个echo
和一个var_dump
,它们是半缩进的:
vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php
<?php
namespace Symfony\Bundle\FrameworkBundle\Console;
use Symfony\Component\Console\Application as BaseApplication;
class Application extends BaseApplication
{
private $kernel;
public function __construct(KernelInterface $kernel)
{
echo "Construct Symfony\Bundle\FrameworkBundle\Console\Application\n";
echo get_class($this) . PHP_EOL;
echo get_parent_class($this) . PHP_EOL;
$this->kernel = $kernel;
var_dump('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
$this->getDefinition()->addOption(new InputOption('--shell', '-s', InputOption::VALUE_NONE, 'Launch the shell.'));
$this->getDefinition()->addOption(new InputOption('--process-isolation', null, InputOption::VALUE_NONE, 'Launch commands from shell as a separate process.'));
$this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $kernel->getEnvironment()));
$this->getDefinition()->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
echo "Finished constructing Symfony\Bundle\FrameworkBundle\Console\Application\n";
}
这是基础Application
类。我只在这个类中添加了echo
,这也是半缩进的:
vendor/symfony/symfony/src/Symfony/Component/Console/Application.php
<?php
namespace Symfony\Component\Console;
class Application
{
private $name;
private $version;
private $definition;
private $helperSet;
private $defaultCommand;
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
{
echo "--> Construct Symfony\Component\Console\Application\n";
$this->name = $name;
$this->version = $version;
$this->defaultCommand = 'list';
$this->helperSet = $this->getDefaultHelperSet();
$this->definition = $this->getDefaultInputDefinition();
foreach ($this->getDefaultCommands() as $command) {
$this->add($command);
}
}
当我运行php app/console hmrx:app:filecheck
时,我明白了:
Construct Symfony\Bundle\FrameworkBundle\Console\Application
Symfony\Bundle\FrameworkBundle\Console\Application
Symfony\Component\Console\Application
C:\server\Apache24\htdocs\dev.hmr-app\hmrex\HMRX_App\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:44:
string(7) "Symfony"
C:\server\Apache24\htdocs\dev.hmr-app\hmrex\HMRX_App\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:44:
string(21) "2.8.2 - app/dev/debug"
--> Construct Symfony\Component\Console\Application
Finished constructing Symfony\Bundle\FrameworkBundle\Console\Application
当我通过测试运行相同的代码时,我得到了这个:
Construct Symfony\Bundle\FrameworkBundle\Console\Application
Symfony\Bundle\FrameworkBundle\Console\Application
Symfony\Component\Console\Application
C:\server\Apache24\htdocs\dev.hmr-app\hmrex\HMRX_App\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:44:
string(7) "Symfony"
C:\server\Apache24\htdocs\dev.hmr-app\hmrex\HMRX_App\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:44:
string(21) "2.8.2 - app/dev/debug"
Finished constructing Symfony\Bundle\FrameworkBundle\Console\Application
请注意除了第二行--> Construct Symfony\Component\Console\Application
之外的输出是相同的,当作为测试的一部分运行时,它会丢失。似乎parent::__construct('Symfony', Kernel::VERSION.' - '.$kernel->getName().'/'.$kernel->getEnvironment().($kernel->isDebug() ? '/debug' : ''));
没有运行。 PHP / Symfony如何可能跳过运行没有条件的行?