Profiling with DOCTRINE

Home Forums Learn ZF2 Profiling with DOCTRINE

This topic contains 8 replies, has 2 voices, and was last updated by  philippe 3 years, 1 month ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #285

    philippe
    Participant

    Hi,
    I’ve been trying for weeks, but I don’t know what to do to make the DoctrineProfiler work in my test application.

    I read page 123 of the book :
    “The implementation of ProfilerAwareInterface and the Database Profiler initializer will guarantee that we will have access to the ZF2 profiler.”

    I see that DoctrineProfiler implements ProfilerAwareInterface, but I don’t understand what is Database Profiler initializer : is it MyModule/Service/Initializer/DbProfiler ?

    If yes, even if I replace “database-profiler” with “doctrine-profiler” in DbProfiler, it doesn’t work.

    What can I do ?

    Thanks

    #288

    Slavey Karadzhov
    Participant

    Hi Philippe,
    First you have to make sure that you have in module/User/src/User/Service/Invokable/DoctrineProfiler.php the content from here: https://github.com/slaff/learnzf2/blob/master/module/User/src/User/Service/Invokable/DoctrineProfiler.php

    Then in your module.config.php for the User module you should add the following line under the service_manager key

    — module/User/config/module.config.php

    <?php
    return array(
    //....
    
    'service_manager' => array(
      // ...
      'invokables' => array (
           'doctrine-profiler' => 'User\Service\Invokable\DoctrineProfiler',
       )
      
    );

    You will find the code above in line 67 in that file: https://github.com/slaff/learnzf2/blob/master/module/User/config/module.config.php#67

    > I see that DoctrineProfiler implements ProfilerAwareInterface, but I don’t understand what is Database Profiler initializer

    When you decide to get an instance of the doctrine profiler using the service manager what will happen is that based on the definition

    'invokables' => array (
           'doctrine-profiler' => 'User\Service\Invokable\DoctrineProfiler',
    )

    It will create an instance of the User\Service\Invokable\DoctrineProfiler class. After this instance is created there is an initializer called Database Profiler initializer, defined in the Debug module configuration ( Line 12 in this file: https://github.com/slaff/learnzf2/blob/ch-doctrine/module/Debug/config/module.config.php#12 ) :

    'service_manager' => array(
    //..
            'initializers' => array(
                'Debug\Service\Initializer\DbProfiler',
            ),
    //..

    With code from here: https://github.com/slaff/learnzf2/blob/ch-doctrine/module/Debug/src/Debug/Service/Initializer/DbProfiler.php

    That will check if the newly created object is instance of ProfilerAwareInterface and if yes it injects the database profiler.

    If you skipped reading some chapters and jumped directly the Doctrine Profiler section I recommend you to go back and read carefully “Database Profiling” to see from where comes the database profiler initializer.

    #289

    philippe
    Participant

    Hi Slavey,

    Thank you for this answer; it helps me, but what is the correspondence for “database-profiler” in DbProfiler.php ?

    You wrote : “When you decide to get an instance of the doctrine profiler using the service manager …” : I realize that I don’t understand where to place this code to get this instance …

    I know you’re very busy, but I’ve read several times your book (I’ve even bought the paper and the PDF versions because I thought something was lacking somewhere…).

    Thank you

    #290

    philippe
    Participant

    Here is the message I get in the “Bottom Line” area :

    Bottom Line
    Db Profiler:

    Fatal error: Call to undefined method Cine\Service\Invokable\DoctrineProfiler::getProfiles() in D:\Zend\Apache2\htdocs\cinesiope\module\Cine\view\cine\layout\sidebar.phtml on line 12

    #291

    Slavey Karadzhov
    Participant

    Hi Philippe, I am getting the feeling that something is wrong with your service manager configuration. Let’s do the following: put the source code of your application in a guthub repository and share it with me. I can take a look over it and make changes related to the database profiling and doctrine profiling. This way you can easily observe the changes that I will make.
    Does it sound like a plan to you?

    #292

    philippe
    Participant

    Hi Slavey,

    I feel honored. Thank you very much.
    I’m going to do according your proposal. I just need a few days to make it as clean as possible!

    Regards

    #295

    philippe
    Participant

    Hi Slavey,
    Here is my repo (it’s the first time for me!)
    testforSK

    It’s a test project. Do you need a sample of my database ?
    I started from the ZendframeworkSkeleton and I add codes from here and there (it was before I read your book)…It’s the reason why it’s dirty !
    This project includes DoctrineModule and DoctrineORMModule.
    I’d like to have the doctrine profiler work with Cine\Controller (list action) and see the result with sidebar.phtml as you did.

    Thank you very much to take time for that.

    #296

    Slavey Karadzhov
    Participant

    Take a look at the commits from today. If this does not help you to figure out how to use the doctrine profiler then read agian the chapter in the book related to Doctrine 2 and discuss it with fellow programmers 🙂

    https://github.com/slaff/testforSK/commits/master

    #297

    philippe
    Participant

    Ok,
    Now I understand what was wrong and why it didn’t work.

    Thank you very much

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.