ZF2 - ServiceManager injecting into 84 tables... tedious

Posted by Dominic Watson on Stack Overflow See other posts from Stack Overflow or by Dominic Watson
Published on 2012-09-19T23:33:08Z Indexed on 2012/09/20 3:37 UTC
Read the original article Hit count: 131

I originally made another thread about this a couple of months ago in regards to ZF2 injecting into tables with DI during Beta 1 and figured back then that it wasn't really possible. Now ZF2 has been released as version 2.0.0 and ServiceManager is defaulted to instead of DI I guess I have the same question now I'm refactoring.

I've got 84 tables that need the DbAdapter injecting into them and I'm sure there has to be a better way as I'm replicating myself SO much.

public function getServiceConfig()
{
    return array(
        'factories' => array(
            'accountTable' => function ($sm) {
                $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                $table     = new Model\DbTable\AccountTable($dbAdapter);
                return $table;
            },
            'userTable' => function ($sm) {
                $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                $table     = new Model\DbTable\UserTable($dbAdapter);
                return $table;
            },
            // another 82 tables of the above
        )
    )
}

With the EventsManager and ServiceManager I have no idea where I stand in getting my application's instances/resources.

Thanks, Dom

© Stack Overflow or respective owner

Related posts about php

Related posts about zend-framework