[DCOM-164] @type phpdoc annotations are not ignored (@type == @var) Created: 22/Jan/13 Updated: 22/Jan/13 |
|
| Status: | Open |
| Project: | Doctrine Common |
| Component/s: | Annotations |
| Affects Version/s: | 2.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Matthieu Napoli | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
phpDocumentor guys wrote their own PSR to define how to use phpdoc properly (https://github.com/phpDocumentor/phpDocumentor2/blob/develop/docs/PSR.md). They deprecate the @var annotation and recommend using @type instead. The @type (phpdoc) annotation is not blacklisted/ignored by the AnnotationReader. Code that uses this annotation raises errors with Doctrine/Annotations. @type should be blacklisted/ignored, but may that create BC breaks for users? |
| Comments |
| Comment by Matthieu Napoli [ 22/Jan/13 ] |
[DCOM-75] remove leading backslash from class name before comparing to namespace in annotation autoloading Created: 03/Nov/11 Updated: 03/Nov/11 |
|
| Status: | Open |
| Project: | Doctrine Common |
| Component/s: | Annotations |
| Affects Version/s: | 2.1.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor |
| Reporter: | Guillaume ORIOL | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
not relevant |
||
| Description |
|
I am figuring a problem with Symfony Validator constraints (I use annotations to define the constraint rules). As I don't use Symfony's framework, I create the validator service by myself.
AnnotationRegistry::registerAutoloadNamespaces(array(
'\Symfony\Component\Validator\Constraints' => APPLICATION_ROOT . '/library'
));
Then, in my entities, I have annotations such as: use Symfony\Component\Validator\Constraints as Assert;
class Author {
/**
* @Assert\NotBlank()
*/
protected $name;
}
In this configuration, I get the following error:
I was able to trace it down to the Doctrine\Common\Annotations\AnnotationRegistry#loadAnnotationClass($class) where we can find the following test: if (strpos($class, $namespace) === 0) {
require ...;
}
which means "if the namespace can be found at the beginning of the FQCN, require it". Christophe Coevoet answered:
Benjamin Eberlei suggested to remove the leading backslash before comparing the class to the namespace. When I add a use statement to my code for a class, I can then use its alias to get an instance of that class. use Doctrine\ORM\Mapping\ClassMetadata;
...
$metadata = new ClassMetadata();
The same is true with: use Doctrine\ORM\Mapping as Foo;
...
$metadata = new Foo\ClassMetadata();
This is not a fully qualified class name. But I find the syntax of a fully-qualified annotation (@My\Annotation\Whatever) erroneous (or at least counter-intuitive) as it doesn't start with a backslash. |
[DCOM-168] ignoredAnnotationNames doesn't work in Annotation loop Created: 27/Jan/13 Updated: 27/Jan/13 |
|
| Status: | Open |
| Project: | Doctrine Common |
| Component/s: | Annotations |
| Affects Version/s: | 2.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | James S | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Mac OSX 10.6.8 |
||
| Description |
|
I'm just starting out with Doctrine, so my setup is a bit messy, but hopefully someone can figure out what is relevant from all my code. Basically, I'm using Annotations on Doctrine ORM, and am integrating with Gedmo for several of their extensions. I can run the CLI tool and update the schema, but when running via my web server, I'm getting the following error: object(Doctrine\Common\Annotations\AnnotationException)[150] protected 'message' => string '[Semantical Error] The annotation "@Entity" in class Innertube\Models\Device was never imported. Did you maybe forget to add a "use" statement for this annotation?' (length=163) private 'string' (Exception) => string '' (length=0) protected 'code' => int 0 protected 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationException.php' (length=211) protected 'line' => int 52 private 'trace' (Exception) => array 0 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php' (length=201) 'line' => int 592 'function' => string 'semanticalError' (length=15) 'class' => string 'Doctrine\Common\Annotations\AnnotationException' (length=47) 'type' => string '::' (length=2) 'args' => array ... 1 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php' (length=201) 'line' => int 533 'function' => string 'Annotation' (length=10) 'class' => string 'Doctrine\Common\Annotations\DocParser' (length=37) 'type' => string '->' (length=2) 'args' => array ... 2 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php' (length=201) 'line' => int 297 'function' => string 'Annotations' (length=11) 'class' => string 'Doctrine\Common\Annotations\DocParser' (length=37) 'type' => string '->' (length=2) 'args' => array ... 3 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationReader.php' (length=208) 'line' => int 151 'function' => string 'parse' (length=5) 'class' => string 'Doctrine\Common\Annotations\DocParser' (length=37) 'type' => string '->' (length=2) 'args' => array ... 4 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Annotations/CachedReader.php' (length=204) 'line' => int 86 'function' => string 'getClassAnnotations' (length=19) 'class' => string 'Doctrine\Common\Annotations\AnnotationReader' (length=44) 'type' => string '->' (length=2) 'args' => array ... 5 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php' (length=205) 'line' => int 61 'function' => string 'getClassAnnotations' (length=19) 'class' => string 'Doctrine\Common\Annotations\CachedReader' (length=40) 'type' => string '->' (length=2) 'args' => array ... 6 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php' (length=202) 'line' => int 112 'function' => string 'loadMetadataForClass' (length=20) 'class' => string 'Doctrine\ORM\Mapping\Driver\AnnotationDriver' (length=44) 'type' => string '->' (length=2) 'args' => array ... 7 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php' (length=228) 'line' => int 302 'function' => string 'doLoadMetadata' (length=14) 'class' => string 'Doctrine\ORM\Mapping\ClassMetadataFactory' (length=41) 'type' => string '->' (length=2) 'args' => array ... 8 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php' (length=228) 'line' => int 205 'function' => string 'loadMetadata' (length=12) 'class' => string 'Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory' (length=64) 'type' => string '->' (length=2) 'args' => array ... 9 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/orm/lib/Doctrine/ORM/EntityManager.php' (length=187) 'line' => int 268 'function' => string 'getMetadataFor' (length=14) 'class' => string 'Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory' (length=64) 'type' => string '->' (length=2) 'args' => array ... 10 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/libraries/lerteco_framework/libraries/vendor-composer/doctrine/orm/lib/Doctrine/ORM/EntityManager.php' (length=187) 'line' => int 682 'function' => string 'getClassMetadata' (length=16) 'class' => string 'Doctrine\ORM\EntityManager' (length=26) 'type' => string '->' (length=2) 'args' => array ... 11 => array 'file' => string '/Users/jshannon/Documents/Work/Projects/InnerTube/Repo/web/packages/lerteco_innertube/api/routes/devices.php' (length=108) 'line' => int 16 'function' => string 'getRepository' (length=13) 'class' => string 'Doctrine\ORM\EntityManager' (length=26) The call that initiates this is getRepository(), which IS NOT in the CLI. I've tracked it down to the fact that DocParser is not getting the list of names to ignore. Oddly, it gets it the first time that it's called by AnnotationReader. However, DocParser->parse() calls $this->Annotations(), which calls $this->Annotation(), calls $this->collectAnnotationMetadata(), which then creates a new parser self::$metadataParser = new self();
and eventually parses it self::$metadataParser->parse() , but DOES NOT pass its ignorednames. This seems like an oversight, but it clearly works for a lot of people. My configuration code is:
if (self::$isDevMode) {
$cache = new \Doctrine\Common\Cache\ArrayCache;
} else {
$cache = new \Doctrine\Common\Cache\ApcCache;
}
\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('package');
AnnotationRegistry::registerFile(__DIR__ . "/vendor-composer/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
\Gedmo\DoctrineExtensions::registerAnnotations();
$annotationReader = new \Doctrine\Common\Annotations\AnnotationReader();
$cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
$annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, self::$namespaceArray);
$config = new \Doctrine\ORM\Configuration;
$config->setProxyNamespace('Proxy');
$config->setAutoGenerateProxyClasses(self::$isDevMode); // this can be based on production config.
// register metadata driver
$config->setMetadataDriverImpl($annotationDriver);
// use our allready initialized cache driver
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
if (defined('DIR_FILES_CACHE')) {
$config->setProxyDir(DIR_FILES_CACHE);
} else {
$config->setProxyDir(sys_get_temp_dir());
}
// create event manager and hook prefered extension listeners
$evm = new \Doctrine\Common\EventManager();
$prefix = new TablePrefix(null);
$prefix->useNamespace(true);
$evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $prefix);
$blameableListener = new \Gedmo\Blameable\BlameableListener();
$blameableListener->setAnnotationReader($config->getMetadataDriverImpl()->getReader());
//class_exists makes this usable with the command-line
if (class_exists('\User') && ($u = new \User()) != false) {
$blameableListener->setUserValue($u->getUserID());
}
$evm->addEventSubscriber($blameableListener);
$timestampableListener = new \Gedmo\Timestampable\TimestampableListener();
$timestampableListener->setAnnotationReader($config->getMetadataDriverImpl()->getReader());
$evm->addEventSubscriber($timestampableListener);
$config->addFilter('soft-deleteable', '\Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
return EntityManager::create($connectionOptions, $config, $evm);
and the entity is (which sets up the repository) is:
namespace Innertube\Models;
defined('C5_EXECUTE') or die('Access Denied.');
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass="DeviceRepository") @ORM\Table(name="Devices")
* @Gedmo\SoftDeleteable(fieldName="deletedOn")
**/
class Device {
and the repository is:
namespace Innertube\Models;
defined('C5_EXECUTE') or die('Access Denied.');
use Doctrine\ORM\EntityRepository;
class DeviceRepository extends EntityRepository {
|
[DCOM-179] Underscore at the end of a label is not working with annotations Created: 03/Mar/13 Updated: 03/Mar/13 |
|
| Status: | Open |
| Project: | Doctrine Common |
| Component/s: | Annotations |
| Affects Version/s: | 2.3 |
| Fix Version/s: | 2.3 |
| Type: | Bug | Priority: | Minor |
| Reporter: | exoon | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
apache2, php 5.4, mysql |
||
| Description |
|
use Zend\Form\Annotation; [...] works:
works not:
Error message: /vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationException.php:52 [Semantical Error] Couldn't find constant Namespace\Entity\::LABEL, property ... The _ at the end is missing. |
[DCOM-165] Entities seems not be recognized by AnnotationDriver Created: 02/Sep/12 Updated: 23/Jan/13 |
|
| Status: | Open |
| Project: | Doctrine Common |
| Component/s: | Annotations |
| Affects Version/s: | 2.2, 2.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Trivial |
| Reporter: | Maarten de Keizer | Assignee: | Marco Pivetta |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | annotationdriver, realpath, symlink, windows | ||
| Environment: |
Windows 7 Profesional, Enterprise and Windows Server 2003 and 2008; Common: 2.2.3 DBAL: 2.2.2 ORM: 2.2.3; PHP 5.4.5 and 5.3.5 |
||
| Description |
|
Problem: Debug steps: file AnnotationDriver.php method getAllClassNames() file AnnotationDriver.php method getAllClassNames() the following output will be displayed: It seems that Doctrine includes the file from f: but ReflectionClass say it is loaded from F:. The in_array() will fail and Doctrine will not recognized the entity. But this is not the full problem. I created a new debug point: file AnnotationDriver.php method getAllClassNames() This will result in the following output: So the conversion of the F: to f: is done by realpath; its look like A simple fix should be in AnnotationDriver.php / getAllClassNames() After I did that, the problem still exists. So I add to echo's (one with realpath and one without at the part of the code). And both echo's result in a path starting with "F:". So my first reaction was freaky! After some frustrating hours I found the problem in the symlink I used. Summary: Possible solutions: |
| Comments |
| Comment by Marco Pivetta [ 23/Jan/13 ] |
|
Maarten de Keizer looks like the issue is still there in doctrine/annotations. Are you able to come up with a failing test case? |