Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getNamespacedId protected instead of private #196

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Doctrine/Common/Annotations/AnnotationReader.php
Expand Up @@ -68,6 +68,8 @@ final class AnnotationReader implements Reader
'codeCoverageIgnore' => true, 'codeCoverageIgnoreStart' => true, 'codeCoverageIgnoreEnd' => true, 'codeCoverageIgnore' => true, 'codeCoverageIgnoreStart' => true, 'codeCoverageIgnoreEnd' => true,
'Required' => true, 'Attribute' => true, 'Attributes' => true, 'Required' => true, 'Attribute' => true, 'Attributes' => true,
'Target' => true, 'SuppressWarnings' => true, 'Target' => true, 'SuppressWarnings' => true,
'ingroup' => true, 'code' => true, 'endcode' => true,
'package_version' => true,
); );


/** /**
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php
Expand Up @@ -68,7 +68,6 @@ public function addNamespace($namespace)
*/ */
public function getClassAnnotations(\ReflectionClass $class) public function getClassAnnotations(\ReflectionClass $class)
{ {
$this->parser->setTarget(Target::TARGET_CLASS);
return $this->parser->parse($class->getDocComment(), 'class '.$class->getName()); return $this->parser->parse($class->getDocComment(), 'class '.$class->getName());
} }


Expand All @@ -81,7 +80,6 @@ public function getClassAnnotations(\ReflectionClass $class)
*/ */
public function getMethodAnnotations(\ReflectionMethod $method) public function getMethodAnnotations(\ReflectionMethod $method)
{ {
$this->parser->setTarget(Target::TARGET_METHOD);
return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()'); return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()');
} }


Expand All @@ -94,7 +92,6 @@ public function getMethodAnnotations(\ReflectionMethod $method)
*/ */
public function getPropertyAnnotations(\ReflectionProperty $property) public function getPropertyAnnotations(\ReflectionProperty $property)
{ {
$this->parser->setTarget(Target::TARGET_PROPERTY);
return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName()); return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName());
} }


Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Cache/CacheProvider.php
Expand Up @@ -129,7 +129,7 @@ public function deleteAll()
* @param string $id The id to namespace * @param string $id The id to namespace
* @return string $id The namespaced id * @return string $id The namespaced id
*/ */
private function getNamespacedId($id) protected function getNamespacedId($id)
{ {
$namespaceCacheKey = sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace); $namespaceCacheKey = sprintf(self::DOCTRINE_NAMESPACE_CACHEKEY, $this->namespace);
$namespaceVersion = ($this->doContains($namespaceCacheKey)) ? $this->doFetch($namespaceCacheKey) : 1; $namespaceVersion = ($this->doContains($namespaceCacheKey)) ? $this->doFetch($namespaceCacheKey) : 1;
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/Common/Cache/MemcacheCache.php
Expand Up @@ -82,6 +82,9 @@ protected function doContains($id)
*/ */
protected function doSave($id, $data, $lifeTime = 0) protected function doSave($id, $data, $lifeTime = 0)
{ {
if ($lifeTime > 30 * 24 * 3600) {
$lifeTime = time() + $lifeTime;
}
return $this->memcache->set($id, $data, 0, (int) $lifeTime); return $this->memcache->set($id, $data, 0, (int) $lifeTime);
} }


Expand Down Expand Up @@ -115,4 +118,4 @@ protected function doGetStats()
Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'], Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'],
); );
} }
} }
5 changes: 4 additions & 1 deletion lib/Doctrine/Common/Cache/MemcachedCache.php
Expand Up @@ -82,6 +82,9 @@ protected function doContains($id)
*/ */
protected function doSave($id, $data, $lifeTime = 0) protected function doSave($id, $data, $lifeTime = 0)
{ {
if ($lifeTime > 30 * 24 * 3600) {
$lifeTime = time() + $lifeTime;
}
return $this->memcached->set($id, $data, (int) $lifeTime); return $this->memcached->set($id, $data, (int) $lifeTime);
} }


Expand Down Expand Up @@ -118,4 +121,4 @@ protected function doGetStats()
Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'], Cache::STATS_MEMORY_AVAILIABLE => $stats['limit_maxbytes'],
); );
} }
} }
6 changes: 6 additions & 0 deletions lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php
Expand Up @@ -155,6 +155,12 @@ public function getManager($name = null)
*/ */
public function getManagerForClass($class) public function getManagerForClass($class)
{ {
// Check for namespace alias
if (strpos($class, ':') !== false) {
list($namespaceAlias, $simpleClassName) = explode(':', $class);
$class = $this->getAliasNamespace($namespaceAlias) . '\\' . $simpleClassName;
}

$proxyClass = new \ReflectionClass($class); $proxyClass = new \ReflectionClass($class);
if ($proxyClass->implementsInterface($this->proxyInterfaceName)) { if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
$class = $proxyClass->getParentClass()->getName(); $class = $proxyClass->getParentClass()->getName();
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Version.php
Expand Up @@ -36,7 +36,7 @@ class Version
/** /**
* Current Doctrine Version * Current Doctrine Version
*/ */
const VERSION = '2.2.0-DEV'; const VERSION = '2.2.4';


/** /**
* Compares a Doctrine version with the current one. * Compares a Doctrine version with the current one.
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/AbstractReaderTest.php
Expand Up @@ -311,6 +311,21 @@ public function testInvalidAnnotationUsageButIgnoredClass()
$this->assertEquals(2, count($annots)); $this->assertEquals(2, count($annots));
} }


/**
* @group DDC-1660
* @group regression
*/
public function testInvalidAnnotationButIgnored()
{
$reader = $this->getReader();
$class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassDDC1660');

$this->assertTrue(class_exists('Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Version'));
$this->assertCount(0, $reader->getClassAnnotations($class));
$this->assertCount(0, $reader->getMethodAnnotations($class->getMethod('bar')));
$this->assertCount(0, $reader->getPropertyAnnotations($class->getProperty('foo')));
}

abstract protected function getReader(); abstract protected function getReader();
} }


Expand Down
@@ -0,0 +1,11 @@
<?php

namespace Doctrine\Tests\Common\Annotations\Fixtures\Annotation;

/**
* @Annotation
* @Target("PROPERTY")
*/
final class Version
{
}
30 changes: 30 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassDDC1660.php
@@ -0,0 +1,30 @@
<?php

namespace Doctrine\Tests\Common\Annotations\Fixtures;

/**
* @since 2.0
* @version $Id: SomeEntityClass.php 509 2012-02-03 09:38:48Z mf $
*/
class ClassDDC1660
{

/**
* @var string
* @since 2.0
* @version 1
*/
public $foo;

/**
* @param string
* @return string
* @since 2.0
* @version 1
*/
public function bar($param)
{
return null;
}

}
Expand Up @@ -24,6 +24,42 @@ public function testImportDetectsNonExistentAnnotation()
parent::testImportDetectsNonExistentAnnotation(); parent::testImportDetectsNonExistentAnnotation();
} }


/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidAnnotationTargetAtClassDocBlock()
{
parent::testClassWithInvalidAnnotationTargetAtClassDocBlock();
}

/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidAnnotationTargetAtPropertyDocBlock()
{
parent::testClassWithInvalidAnnotationTargetAtPropertyDocBlock();
}

/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock()
{
parent::testClassWithInvalidNestedAnnotationTargetAtPropertyDocBlock();
}

/**
* Contrary to the behavior of the default annotation reader, we do just ignore
* these in the simple annotation reader (so, no expected exception here).
*/
public function testClassWithInvalidAnnotationTargetAtMethodDocBlock()
{
parent::testClassWithInvalidAnnotationTargetAtMethodDocBlock();
}

/** /**
* @expectedException Doctrine\Common\Annotations\AnnotationException * @expectedException Doctrine\Common\Annotations\AnnotationException
*/ */
Expand All @@ -32,11 +68,29 @@ public function testInvalidAnnotationUsageButIgnoredClass()
parent::testInvalidAnnotationUsageButIgnoredClass(); parent::testInvalidAnnotationUsageButIgnoredClass();
} }


/**
* @group DDC-1660
* @group regression
*
* Contrary to the behavior of the default annotation reader, @version is not ignored
*/
public function testInvalidAnnotationButIgnored()
{
$reader = $this->getReader();
$class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\ClassDDC1660');

$this->assertTrue(class_exists('Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Version'));
$this->assertCount(1, $reader->getClassAnnotations($class));
$this->assertCount(1, $reader->getMethodAnnotations($class->getMethod('bar')));
$this->assertCount(1, $reader->getPropertyAnnotations($class->getProperty('foo')));
}

protected function getReader() protected function getReader()
{ {
$reader = new SimpleAnnotationReader(); $reader = new SimpleAnnotationReader();
$reader->addNamespace(__NAMESPACE__); $reader->addNamespace(__NAMESPACE__);
$reader->addNamespace(__NAMESPACE__ . '\Fixtures'); $reader->addNamespace(__NAMESPACE__ . '\Fixtures');
$reader->addNamespace(__NAMESPACE__ . '\Fixtures\Annotation');


return $reader; return $reader;
} }
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/Common/Cache/MemcacheCacheTest.php
Expand Up @@ -21,10 +21,18 @@ public function setUp()
} }
} }


public function testNoExpire() {
$cache = $this->_getCacheDriver();
$cache->save('noexpire', 'value', 0);
sleep(1);
$this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
}

protected function _getCacheDriver() protected function _getCacheDriver()
{ {
$driver = new MemcacheCache(); $driver = new MemcacheCache();
$driver->setMemcache($this->_memcache); $driver->setMemcache($this->_memcache);
return $driver; return $driver;
} }

} }
7 changes: 7 additions & 0 deletions tests/Doctrine/Tests/Common/Cache/MemcachedCacheTest.php
Expand Up @@ -24,6 +24,13 @@ public function setUp()
} }
} }


public function testNoExpire() {
$cache = $this->_getCacheDriver();
$cache->save('noexpire', 'value', 0);
sleep(1);
$this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
}

protected function _getCacheDriver() protected function _getCacheDriver()
{ {
$driver = new MemcachedCache(); $driver = new MemcachedCache();
Expand Down