Hey there. I am writing a program that converts some data to our database and then calls Doctrine to create YAML files from the specified Mysql database structure. I have a Doctrine working with PHP. However, I cannot figure out how to call CLI commands from PHP. The following is a Doctrine 2 CLI command that does what I need.
php./doctrine orm: convert-mapping --filter = "users" --from-database yml./test
This command works from the Linux command line, but how do I do the same through Doctrine objects? I do not want to just use the PHP exec statement to send the command to the shell. I want to use the Doctrine object model.
:
-, . , Doctrine PHP, PHP EXEC. , , . . .
$cmd_string = "php ./doctrine orm:generate-entities --generate-annotations=1 --regenerate-entities=1 $this->entity_file_dir"; $result = array(); exec($cmd_string, &$result);
, , -Don!
PHP script CLI.
, orm: --. Doctrine : http://www.doctrine-project.org/api/orm/2.4/namespace-Doctrine.ORM.Tools.Console.Command.html
$entityManager = ...; // Get the entity manager somehow in your application // Creates the helper set $helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager); // Initializes the desired command and sets the helper set // In your case it should be ConvertMappingCommand instead $command = new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(); $command->setHelperSet($helperSet); // Initializes the input // Alternatives: http://api.symfony.com/2.0/Symfony/Component/Console/Input.html $input = new \Symfony\Component\Console\Input\ArgvInput(); // Input coming from the CLI arguments // Initializes the output // Alternatives: http://api.symfony.com/2.0/Symfony/Component/Console/Output.html $output = new \Symfony\Component\Console\Output\ConsoleOutput(); // Prints the output in the console // Runs the command $command->run($input, $output);
Doctrine, , , . .