Question

I'm trying to use Doctrine's MongoDB ODM with FlightPHP in what I thought would be a pretty quick little project.

I've registered the DocumentManager class with Flight like so:

$dm = DocumentManager::create( $connection, $config );

Flight::register('dm', 'Doctrine\ODM\MongoDB\DocumentManager', array($connection,     $config));

// Endpoints
Flight::route( '/api/create', function ( )
{
    $thing = new Thing();

    $dm = Flight::dm();
    $dm->persist( $thing );
    $dm->flush();
} );

And it appears that flight tries to call Doctrine's constructor which is protected? What are my options to get around this?

Fatal error: Call to protected Doctrine\ODM\MongoDB\DocumentManager::__construct() from context 'flight\core\Loader' in /../vendor/mikecao/flight/flight/core/Loader.php on line 116
Was it helpful?

Solution 2

The DocumentManager class is intended to be constructed through its create() static factory method, as is shown in the Getting Started and Introduction documentation entries.

Taking a look at Flight's Registering Classes, it only appears to support constructing classes by invoking their constructor. This is in contrast to frameworks such as Silex, which allow you full control over constructing your shared services (see here). As-is, I don't see a work-around within Flight's current code, so I would suggest opening an issue or submitting a pull request to the project to request/add more flexible service construction.

OTHER TIPS

This is resolved in the latest version of Flight

It should now be possible in the latest commit b9b2d0f. You can register a callable instead of just a classname:

Flight::register('db', array('Doctrine\ORM\EntityManager','create'), array($connection, $config));

Added ability to register callbacks for class instantiation. https://github.com/mikecao/flight/commit/b9b2d0fa2d75e6b2f606fbd0d9a8059a0f741578 https://github.com/mikecao/flight/issues/105

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top