[Solar-talk] Making a Solar::callback() method

Pierre Oztel pierre.oztel at gmail.com
Fri Aug 3 08:33:13 CDT 2007


Ah, I forgot to mention that I did some speed tests with the Solar_View
Object with and without the __call hook.

In those tests, i removed View helpers completely. I had average times of
100ms (without any opcode cache) with the hook, it falled down to a mean of
20ms for this script on the bookmark application.

Solar::start();

$controller->fetch();

Solar::stop();

I need advices before refactoring all callbacks :)



2007/8/3, Pierre Oztel <pierre.oztel at gmail.com>:
>
> Yes, that is why i thought about pushing Solar_Valid, Solar_Filter in the
> registry.
>
> At least it can be passed as a property for client objects, I mean isn't
> it a waste of instanciating object like Valid or Filter ?
>
> 2007/8/2, Rodrigo Moraes <rodrigo.moraes at gmail.com>:
> >
> > On 8/2/07, Pierre Oztel wrote:
> > >
> > > It is too bad i cannot post my suggestion to the TRAC, Akismet just
> > > don't let me in ...
> > >
> > > Since call_user_func functions are so slow, and since we have many
> > > callback in Solar, maybe it is a good idea to function refactor what you did
> > > in the Controller of 0.28 version.
> >
> >
> > Hi, Pierre.
> > I commented about this some time ago on IRC: that specific piece of code
> > on the Page_Controller is not used many times per request, so it's probably
> > an optimization with little gain. I think that it *could* make a difference
> > applied to validation callbacks, Solar_Form and View (to call helpers),
> > where call_user_func*() is used in a much bigger number.
> >
> > Anyway, I personally dislike the workaround a bit because it is not
> > elegant imo, but extracting it from the Page_Controller to a place where it
> > could be used more times makes sense. :)
> >
> > -- rodrigo
> > PS: I'm dropping below a refactored version (geez, I love callbacks)
> >
> > public static function callback($exec) {
> >     if (! is_callable($exec)) {
> >         throw Solar::exception(
> >             'Solar',
> >             'ERR_INVALID_CALLBACK',
> >             'Invalid callback',
> >             array('callback' => $exec)
> >         );
> >     }
> >
> >     // Get the additional arguments.
> >     $args = func_get_args();
> >     // Drop $exec.
> >     array_shift($args);
> >
> >     if (is_array($exec)) {
> >         if (! is_object($exec[0])) {
> >             // Static method call.
> >             return call_user_func_array($exec, $args);
> >         } else {
> >             // Instance method call.
> >             $obj = $exec[0];
> >             $method = $exec[1];
> >
> >             switch(count($args)) {
> >                 case 0:
> >                     return $obj->$method();
> >                     break;
> >
> >                 case 1:
> >                     return $obj->$method($args[0]);
> >                     break;
> >
> >                 case 2:
> >                     return $obj->$method($args[0], $args[1]);
> >                     break;
> >
> >                 case 3:
> >                     return $obj->$method($args[0], $args[1], $args[2]);
> >                     break;
> >
> >                 default:
> >                     return call_user_func_array(array($obj, $method),
> > $args);
> >                     break;
> >             }
> >         }
> >     } else {
> >          // Simple function call.
> >         switch(count($args)) {
> >             case 0:
> >                 return $exec();
> >                 break;
> >
> >             case 1:
> >                 return $exec($args[0]);
> >                 break;
> >
> >             case 2:
> >                 return $exec($args[0], $args[1]);
> >                 break;
> >
> >             case 3:
> >                 return $exec($args[0], $args[1], $args[2]);
> >                 break;
> >
> >             default:
> >                 return call_user_func_array($exec, $args);
> >                 break;
> >         }
> >     }
> > }
> >
> > _______________________________________________
> > Solar-talk mailing list
> > Solar-talk at lists.solarphp.com
> > http://mailman-mail3.webfaction.com/listinfo/solar-talk
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman-mail3.webfaction.com/pipermail/solar-talk/attachments/20070803/38b6f299/attachment.html


More information about the Solar-talk mailing list