php - Doctrine Common trying to create an annotation -
i trying use doctrine common create own annotation. http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/annotations.html not match https://github.com/doctrine/common because call undefined method doctrine\\common\\annotations\\annotationreader::setdefaultannotationnamespace
, php fatal error: call undefined method doctrine\\common\\annotations\\annotationregistry::registerannotationnamespace
. checked source, not there. according git log removed year ago.
i have psr-0 autoloader going (from symfony). have file psr-0 loader expects:
namespace my\test; /** * @annotation */ class foo { }
another class
namespace my\annotated /** * @my\test\foo */ class test { }
reader:
namespace my\reader use reflectionclass; use doctrine\common\annotations\annotationreader; use doctrine\common\annotations\annotationregistry; use my\test\foo; $reader = new annotationreader(); $reflectionclass = new reflectionclass('my\\annotated\\test'); $classannotations = $reader->getclassannotations($reflectionclass); var_dump($classannotations);
gets: "[semantical error] annotation "@my\\test\\foo" in class my\\annotated\\test never imported. did maybe forget add "use" statement annotation?"
ilikely did life can't figure out add it. , use @foo if possible.
i stumbled accross issue error messages like:
fatal error: uncaught exception doctrine\common\annotations\annotationexception' message '[semantical error] annotation "@symfony\component\validator\constraints\notnull" in property my\namespace\model\foo\bar::$name not exist, or not auto-loaded.' in var/www/virtual/hive/current/vendor/doctrine/annotations/lib/doctrine/common/annotations/annotationexception.php on line 54
while trying symfony2 validator component work standalone in legacy non-symfony2 project.
i under impression annotations should autoloaded, whereas 1 indeed has realize 1 has use doctrine's autoloader in order annotations working.
i have looked @ how symfony2 loads registry, , in app/autoload.php
<?php use doctrine\common\annotations\annotationregistry; use composer\autoload\classloader; /** * @var classloader $loader */ $loader = require __dir__.'/../vendor/autoload.php'; annotationregistry::registerloader(array($loader, 'loadclass'));
return $loader;
my project uses bootstrap.inc.php
file loaded , had:
require_once project_path . '/vendor/autoload.php';
i refactored similar:
use doctrine\common\annotations\annotationregistry; ... $loader = require_once project_path . '/vendor/autoload.php'; annotationregistry::registerloader([$loader, 'loadclass']);
and annotation found.
Comments
Post a Comment