Skip to content

DCOM-84 - Improve proxy names #83

Merged
merged 3 commits into from Dec 12, 2011

4 participants

@beberlei
Doctrine member

No description provided.

@stof stof commented on an outdated diff Dec 12, 2011
lib/Doctrine/Common/Persistence/Proxy.php
* @author Roman Borschel <roman@code-factory.org>
* @since 2.2
*/
interface Proxy
{
/**
+ * Marker for Proxy class names.
+ *
+ * @var string
+ */
+ const MARKER = '__CG__';
+ /**
@stof
Doctrine member
stof added a note Dec 12, 2011

missing empty line here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Dec 12, 2011
lib/Doctrine/Common/Util/ClassUtils.php
+ */
+ public static function newReflectionObject($object)
+ {
+ return self::newReflectionClass( self::getClass( $object ) );
+ }
+
+ /**
+ * Given a class name and a proxy namespace return the proxy name.
+ *
+ * @param string $className
+ * @param string $proxyNamespace
+ * @return string
+ */
+ public static function generateProxyClassName($className, $proxyNamespace)
+ {
+ return rtrim($proxyNamespace, '\\') . '\\__CG__\\' . ltrim($className, '\\');
@stof
Doctrine member
stof added a note Dec 12, 2011

shouldn't it use Proxy::MARKER here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@schmittjoh schmittjoh commented on an outdated diff Dec 12, 2011
lib/Doctrine/Common/Util/ClassUtils.php
+ */
+class ClassUtils
+{
+ /**
+ * Get the real class name of a class name that could be a proxy.
+ *
+ * @param string
+ * @return string
+ */
+ public static function getRealClass($class)
+ {
+ if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
+ return $class;
+ }
+
+ return substr($class, $pos + strlen(Proxy::MARKER) + 2);
@schmittjoh
Doctrine member
schmittjoh added a note Dec 12, 2011

Maybe add a constant for the length? PHP doesn't optimize this AFAIK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77 lsmith77 commented on the diff Dec 12, 2011
lib/Doctrine/Common/Persistence/Proxy.php
* @return void
*/
public function __load();
+
+ /**
+ * Is this proxy initialized or not.
+ *
+ * @return bool
+ */
+ public function __isInitialized();
@lsmith77
Doctrine member
lsmith77 added a note Dec 12, 2011

do you guys include public in interfaces?

@beberlei
Doctrine member
beberlei added a note Dec 12, 2011

i don't think about that stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77
Doctrine member

i wonder if an isProxy method like i added in https://github.com/doctrine/common/pull/82/files#L1R56 would be useful to have in ClassUtils?

@stof
Doctrine member
stof commented Dec 12, 2011

@lsmith77 instanceof Proxy ?

@beberlei beberlei merged commit 97d9ef4 into master Dec 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.