Getting Symfony Doctrine Entity Manager within PHP Docker container / phpbrew for PHP 5.3.10

639 Views Asked by At

I'm trying to run a Symfony command under Docker with PHP 5.3.10. When I get to a line like

class Data{

    public function prepareData(){
        echo 'before getContainer';
        $em = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection();
        echo 'after getContainer';

    }
}

It fails silently.

The docker command to set up the container is

docker run --network="host" -t -i -p 80:80 -v /srv/www/live/:/srv/www/live/ -v /var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock bylexus/apache-php53 /bin/bash

When in the Docker container I install mysql and then can log in and see the databases that exist on my local system.

The Symfony command I run inside the Docker container is like

php app/console mytask:preparedata

from

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

class PrepareDataCommand extends Command
{

    protected function configure()
    {
        parent::configure();

        $this->setName('mytask:preparedata');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

          $this->getHelper('Data')->prepareData();

    }

}

which executes the prepareData function. The 'after getContainer' never echoes, just the 'before getContainer'. There is nothing in the logs, Apache, MySQL or Symfony.

Do you have an idea how to debug this or how to get the container like it occurs outside Docker?

Update

I have now tested this using phpbrew. It works on PHP version 5.6.30 but not on the desired PHP version 5.3.10 (stopping at the same $em = $this->getContainer line as above). Curiously it also doesn't work on PHP 7.0.3 in phpbrew. Could it be a Symfony or Doctrine-related problem with respect to PHP version now?

1

There are 1 best solutions below

0
On BEST ANSWER

I tried some other Symfony CLI commands and noticed that sometimes there would be fatal errors within Doctrine's vendor repository, installed via composer. Upon inspection, it was where an array was initialised using PHP 5.4 syntax (square brackets). So of course this would not work in a 5.3 container. So I downgraded doctrine/cache, doctrine/common and doctrine/orm and the commands now run.