-
-
Save schmittjoh/b493493ecdb22c21590e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassUtils | |
{ | |
const MARKER = '__CG__'; | |
public static function getUserClassAlternative1($class) | |
{ | |
if (false === $pos = strrpos($class, self::MARKER)) { | |
return $class; | |
} | |
return substr($class, 0, $pos); | |
} | |
public static function getUserClassAlternative2($class) | |
{ | |
if (false === strpos($class, self::MARKER)) { | |
return $class; | |
} | |
return get_parent_class($class); | |
} | |
public static function getUserClassAlternative3($class) | |
{ | |
if (false === $pos = strrpos($class, '\\'.self::MARKER.'\\')) { | |
return $class; | |
} | |
return substr($class, $pos + strlen(self::MARKER) + 2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Alternative 1: | |
- works over several levels, e.g. a proxy of a proxy, A (proxy) inherits from B (proxy) inherits from C (user class) | |
- requires the proxy to use a suffix | |
- autoloaders must be silent, or the proxy autoloader must be registered first | |
- user may not configure proxy namespace | |
Alternative 2: | |
- does only work for one level | |
- does not require to use a suffix, but would also allow a different namespace DoctrineProxy/FooName | |
- allows autoloader to be non-silent assuming that you use a unique namespace for the proxy | |
- user may still configure proxy namespace | |
Alternative 3: | |
- works over several levels | |
- requires \__CG__\ directly after the namespace prefix | |
- allows autoloader to be non-silent | |
- user may still configure proxy namespace |
Using strrpos, we would take everything after the last occurrence of \__CG__\
as the user's class name. So you could have any number of proxies for a given class, we wouldn't impose anything on the naming of these proxies except that \__CG__\
must be directly before the user class part starts.
ping @beberlei, does (3) look like an actionable plan?
@schmittjoh yes
@schmittjoh appending CG doesn't help if people define proxy namespaces to be equal to existing namespaces. Should we ignore this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would proxies of proxies work with this approach?