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
-~----------~----~----~----~------~----~------~--~---