#1267: Add support for Doctrine query/result caching
-------------------------------+--------------------------------------------
 Reporter:  MugeSo@…           |       Owner:  david   
     Type:  enhancement        |      Status:  assigned
 Priority:  normal             |   Milestone:  1.0.6   
Component:  database           |     Version:  1.0.3   
 Severity:  normal             |    Keywords:          
Has_patch:  1                  |  
-------------------------------+--------------------------------------------
Changes (by david):

  * status:  new => assigned


Comment:

 I propose this patch:
 {{{
 #!diff
 Index: src/database/doctrine/AgaviDoctrineDatabaseEventListener.class.php
 ===================================================================
 --- src/database/doctrine/AgaviDoctrineDatabaseEventListener.class.php
 (revision 4743)
 +++ src/database/doctrine/AgaviDoctrineDatabaseEventListener.class.php
 (working copy)
 @@ -48,6 +48,19 @@
         }

         /**
 +        * Return the AgaviDoctrineDatabase instance associated with this
 listener.
 +        *
 +        * @return     AgaviDoctrineDatabase
 +        *
 +        * @author     David Zülke <[email protected]>
 +        * @since      1.0.6
 +        */
 +       public function getDatabase()
 +       {
 +               return $this->database;
 +       }
 +
 +       /**
          * Post-connect listener. Will set charset and run init queries if
 configured.
          *
          * @param      Doctrine_Event The Doctrine event object.
 @@ -57,11 +70,13 @@
          */
         public function postConnect(Doctrine_Event $event)
         {
 +               $database = $this->getDatabase();
 +
 -               if($this->database->hasParameter('charset')) {
 +               if($database->hasParameter('charset')) {
 -
 $event->getInvoker()->setCharset($this->database->getParameter('charset'));
 +
 $event->getInvoker()->setCharset($database->getParameter('charset'));
                 }

 -
 foreach((array)$this->database->getParameter('init_queries') as $query) {
 +               foreach((array)$database->getParameter('init_queries') as
 $query) {
                         $event->getInvoker()->exec($query);
                 }
         }
 Index: src/database/AgaviDoctrineDatabase.class.php
 ===================================================================
 --- src/database/AgaviDoctrineDatabase.class.php        (revision 4743)
 +++ src/database/AgaviDoctrineDatabase.class.php        (working copy)
 @@ -118,7 +118,8 @@
                         // $this->resource = $this->connection->getDbh();

                         // set our event listener that, on connect, sets
 the configured charset and runs init queries
 -                       $this->connection->setListener(new
 AgaviDoctrineDatabaseEventListener($this));
 +                       $connectionListener =
 $this->getParameter('connection_listener',
 'AgaviDoctrineDatabaseEventListener');
 +                       $this->connection->setListener(new
 $connectionListener($this));

                         // set the context instance as a connection
 parameter
                         $this->connection->setParam('context',
 $databaseManager->getContext(), 'org.agavi');
 }}}

 This way, people can set their own event listener and implement
 {{{preConnect()}}} where they can set all sorts of things (the
 {{{AgaviDoctrineDatabase}}} and thus any configuration parameters to
 control stuff can be accessed from the listener, just like the Doctrine
 connection and the manager).

 Does that work for this case?

-- 
Ticket URL: <http://trac.agavi.org/ticket/1267#comment:7>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5



_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets

Reply via email to