0
votes

I don't find any solution through Symfony's docs and google. I find only stuff about starting an application from scratch.

I have a big own-framework application and i want slowly migrate to Symfony2. I have not the convenience to build a new application from scratch. Until now i cloned the entire symfony folder into my own-framework application's root folder. I was using Doctrine by directly implementing it, whitout touching Symfony, like following.

<?php
namespace QueryBuild\Helpers;

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

class Listing
{
protected $appConfig;
protected $doctrineEntityManager;

public function __construct(\cConfig $app_config)
{
    $this->setAppConfig($app_config);
    $this->setDoctrineEntityManager();
}

public function setAppConfig($app_config)
{
    $this->appConfig = $app_config;
}

public function setDoctrineEntityManager()
{
    $paths = array(
        $this->getAppConfig()->BasePath() . "/symfony/src/El/Entity/"
    );
    $isDevMode = true;

    // the connection configuration
    $dbParams = array(
        'driver' => 'sqlsrv', // pdo_sqlsrv for mssql
        'host' => $this->getAppConfig()->db->Host,
        'user' => $this->getAppConfig()->db->User,
        'password' => $this->getAppConfig()->db->Password,
        'dbname' => $this->getAppConfig()->db->Database
    );

    // 5th param on false, to NOT use the simple annotation reader. Otherwise annotations are going to be readed wrong. Can be due to server configurations.
    $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
    $doctrineEntityManager = EntityManager::create($dbParams, $config);

    $this->doctrineEntityManager = $doctrineEntityManager;
}

public function getAppConfig()
{
    return $this->appConfig;
}

public function getDoctrineEntityManager()
{
    return $this->doctrineEntityManager;
}


}

Dont be confused on my namespace, my actual task is to create a query building feature.

Now i don't want anymore to connect to the db by passing the login datas into setDoctrineEntityManager(). I already wrote those informations in /symfony/app/config/parameters.yml . Now my idea was to instanciate symfony to be able to read the configuration, and howewer from symfony to instanciate doctrine.

How can i accomplish this? Many thanks in advice.

1
How are you using symfony together with your application? i.e: How are you bootstrapping symfony? Nothing happens by only 'copying' the files.user2268997
Hi, that's the question, Symfony is not yet used/implemented/instanciated/bootstrapped in my Application. How i can accomplish this, and then how can i get the logged-in doctrine instance?Fabian Picone
There are many different ways for that, you'll have to ask another question. for a start see slideshare.net/fabrice.bernhard/… after slide 19.user2268997
All right, i will check the link, thanks.Fabian Picone

1 Answers

0
votes

Finally my solution was the contrary as i thinked before. Symfony2 is now the wrapping base application, and the legacy application is (at the moment) encapsulated as a LegacyBundle. Now i can pass e.g. the Entity-Manager or even the Controller-Container to the legacy application.