Skip to content

Instantly share code, notes, and snippets.

@schmittjoh
Created October 27, 2011 20:46
Show Gist options
  • Save schmittjoh/b493493ecdb22c21590e to your computer and use it in GitHub Desktop.
Save schmittjoh/b493493ecdb22c21590e to your computer and use it in GitHub Desktop.
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);
}
}
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
@beberlei
Copy link

beberlei commented Dec 1, 2011

@beberlei
Copy link

beberlei commented Dec 3, 2011

@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