I run some tests on part of my current project (450 PHP class files).
regexp version : 0.2 second
token version 3.5 seconds

The token version is indeed much slower but more reliable.


On 10/15/07, Ratibus <[EMAIL PROTECTED]> wrote:
> It is possible (I will benchmark it on my own project) but the result
> of the detection is directly cached in the following file :
> ROOT_DIR/cache/APP/ENV/config/config_autoload.yml.php file.
> So there is no problem for production performance.
> In this case, I think that the reliability of the detection system in
> more important than performance (as long as it does not take hours to
> perform ;)).
>
> Eric
>
> On 10/15/07, Olivier Mansour <[EMAIL PROTECTED]> wrote:
> >
> >
> > Le 15 oct. 07 à 14:51, Eric Lemoine a écrit :
> >
> > >
> > > Hello
> > >
> > > The current autoloading feature in symfony is based on class and
> > > interface detection within project and symfony source files.
> > > The detection is made with a regexp on the source code of these files
> > > (in the file lib/config/sfAutoloadConfigHandler.class.php).
> > >
> > > Current code :
> > >
> > > $regex = '~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w
> > > +)~mi';
> > > foreach ($files as $file)
> > > {
> > >       preg_match_all($regex, file_get_contents($file), $classes);
> > >       foreach ($classes[1] as $class)
> > >       {
> > >               ...
> > >       }
> > > }
> > >
> > > This code can lead to some problems. Indeed if we consider the
> > > following source code, the results will be wrong :
> > > <?php
> > >
> > > class myClass {
> > > }
> > > /*
> > > class myOldClass {
> > > }
> > > */
> > >
> > > ?>
> > >
> > > myOldClass is going to be detected, though it should not be, because
> > > inside a comment block. I think we can easily find other examples.
> > >
> > >
> > > I think we could improve the detection using PHP token system.
> > > Here is a function I made to detect correctly (I presume) classes and
> > > interfaces within a source code :
> > >
> > > /**
> > >  * Get names of classes and interfaces defined within PHP code.
> > >  *
> > >  * @param string Source code to analyze
> > >  *
> > >  * @return array Names of the classes and interfaces defined in the
> > > source code
> > >  */
> > > function getClasses($code) {
> > >       $classIn = false;
> > >       $classes = array();
> > >       foreach(token_get_all($code) as $c) {
> > >               if(is_array($c)) {
> > >                       switch($c[0]) {
> > >                               case T_CLASS:
> > >                               case T_INTERFACE:
> > >                                       $classIn = true;
> > >                                       break;
> > >
> > >                               case T_STRING:
> > >                                       if($classIn) {
> > >                                               $classes[] = $c[1];
> > >                                               $classIn = false;
> > >                                       }
> > >                                       break;
> > >                       }
> > >               }
> > >       }
> > >       return $classes;
> > > }
> > >
> > > Defining this function as a method of the sfAutoloadConfigHandler
> > > class (not sure whether it is the right place to define it), the
> > > current code could be replace with the following one :
> > >
> > > foreach ($files as $file)
> > > {
> > >       foreach (self::getClasses(file_get_contents($file)) as $class)
> > >       {
> > >               ...
> > >       }
> > > }
> > >
> > > Tell me what you think about it ;)
> >
> > My intuition is telling me that this way is much slower than the
> > regexp based code :-(
> >
> > Olivier
> >
> > >
> > > Eric
> > >
> > >
> > > >
> >
> >
> >
> > --
> > Olivier Mansour
> > [EMAIL PROTECTED]
> > http://www.glagla.org
> >
> >
> >
> > > >
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to