snapshotpl / ZfSnapPhpDebugBar

PHP Debug Bar module for Zend Framework 2 & 3
29 stars 11 forks source link

createService seems to fail on parameters #5

Closed gplv2 closed 9 years ago

gplv2 commented 9 years ago

Hi,

I'm receiving this one:

( ! ) Fatal error: Uncaught exception 'Zend\Db\Adapter\Exception\InvalidArgumentException' with message 'createDriver expects a "driver" key to be present inside the parameters' in /usr/share/bareos-webui_bck/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 930

after debugging the 'parameters' I managed to actually bypass this error and see the debugbar working well. But somehow the format of the parameters is not what zend is expecting:

in vendor/zendframework/zendframework/library/Zend/Db/Adapter/Adapter.php

   protected function createDriver($parameters)
    {
        /* why is $parameter not as expected when enabling the debug bar ?
        // Array ( [adapters] => Array ( 
                        [localhost-dir] => Array ( 
                                [driver] => Pdo_Mysql [dbname] => bacula [host] => localhost [port] => 3306 [username] => bareos_gui [password] => bareos_secret ) 
                        ) 
                ) 
        // This is zen package fix , driver is from a deeper nested area, why is this and why does it work after doing this ?
        */
        if (is_array($parameters) and isset($parameters['adapters'])) {
                $parameters = array_pop($parameters['adapters']);
        }
        if (!isset($parameters['driver'])) {
            throw new Exception\InvalidArgumentException(__FUNCTION__ . ' expects a "driver" key to be present inside the parameters');
        }
....

It only happens when I include ZfSnapPhpDebugBar in the modules. I managed to fix this by modding the parameters in the wrong place ( Zend ) but it seems that is all what is needed to get the debug bar to work in https://github.com/gplv2/bareos-webui for now.

any idea why the '$parameters' are in the wrong format while setting up the service ?

Tx for making this for SF2

gplv2 commented 9 years ago

stack trace

#   Time    Memory  Function    Location
1   0.0001  286680  {main}( )   ../index.php:0
2   0.0016  347336  Zend\Mvc\Application::init( )   ../index.php:24
3   0.0606  2022200 Zend\Mvc\Application->bootstrap( )  ../Application.php:260
4   0.0733  2380392 Zend\EventManager\EventManager->trigger( )  ../Application.php:156
5   0.0733  2380688 Zend\EventManager\EventManager->triggerListeners( ) ../EventManager.php:207
6   0.0857  2846568 call_user_func:{/usr/share/bareos-webui_bck/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:468} ( )  ../EventManager.php:468
7   0.0857  2846904 ZfSnapPhpDebugBar\Module->onBootstrap( )    ../EventManager.php:468
8   0.0858  2846952 Zend\ServiceManager\ServiceManager->get( )  ../Module.php:95
9   0.0860  2847888 Zend\ServiceManager\ServiceManager->create( )   ../ServiceManager.php:525
10  0.0860  2847888 Zend\ServiceManager\ServiceManager->doCreate( ) ../ServiceManager.php:593
11  0.0860  2847936 Zend\ServiceManager\ServiceManager->createFromFactory( )    ../ServiceManager.php:633
12  0.0862  2850192 Zend\ServiceManager\ServiceManager->createServiceViaCallback( ) ../ServiceManager.php:1055
13  0.0862  2850536 call_user_func:{/usr/share/bareos-webui_bck/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:923} ( )  ../ServiceManager.php:923
14  0.0862  2850808 ZfSnapPhpDebugBar\Service\PhpDebugBarFactory->createService( )  ../ServiceManager.php:923
15  0.0881  2948208 Zend\ServiceManager\ServiceManager->get( )  ../PhpDebugBarFactory.php:41
16  0.0883  2949104 Zend\ServiceManager\ServiceManager->create( )   ../ServiceManager.php:525
17  0.0883  2949104 Zend\ServiceManager\ServiceManager->doCreate( ) ../ServiceManager.php:593
18  0.0883  2949152 Zend\ServiceManager\ServiceManager->createFromFactory( )    ../ServiceManager.php:633
19  0.0884  2950944 Zend\ServiceManager\ServiceManager->createServiceViaCallback( ) ../ServiceManager.php:1055
20  0.0884  2951304 call_user_func:{/usr/share/bareos-webui_bck/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:923} ( )  ../ServiceManager.php:923
21  0.0884  2951384 Zend\Db\Adapter\AdapterServiceFactory->createService( ) ../ServiceManager.php:923
22  0.0909  2968328 Zend\Db\Adapter\Adapter->__construct( ) ../AdapterServiceFactory.php:26
23  0.0909  2968632 Zend\Db\Adapter\Adapter->createDriver( )    ../Adapter.php:80
snapshotpl commented 9 years ago

Thanks for the report. I'm working on it.

gplv2 commented 9 years ago

Great, appreciate it ! Let me know if you need more information, would love to get this to work.

snapshotpl commented 9 years ago

@gplv2 I pushed fix to master. Please download and test it! :) Details here https://github.com/snapshotpl/ZfSnapPhpDebugBar/commit/38804033e2e3f96e9657f151a277573c6b29e967

gplv2 commented 9 years ago

Awesome stuff. I upgraded, removed the ZF2 code workaround , enabled the module and the debug bar is working fine. Really appreciate your time and effort!! Thanks a lot.

edit: I'm not seeing the database tab anymore though, but It was empty before this problem too. I'm not interested in the queries so not really a focus here.

gplv2 commented 9 years ago

Fixed!

snapshotpl commented 9 years ago

@gplv2 But did you run any queries?

gplv2 commented 9 years ago

You might have a point there, most stuff is interacting with a console daemon in the application. I've forked the open source version , it might be just that no queries are being run although the console daemon requires a DB, the interaction is probably not directly. Before the upgrade the 'database' tab in the debug window was always empty,now it is gone. Which is better imho when no queries are actually performed. The great news is that thanks to your fixes I can now dig in deeper using the debug tool. It's the first time I worked with ZF2 application, I still need to learn a lot about it.

snapshotpl commented 9 years ago

@gplv2 cool. Have fun with zf2! :smile: