Author: Johannes M. Schmitt (schmittjoh@gmail.com)
Author: Benjamin Eberlei (kontakt@beberlei.de)
Inheritance: implements Doctrine\Common\Annotations\Reader
コード例 #1
0
ファイル: AnnotationReader.php プロジェクト: swimson/poncho
 /**
  * Annotations specifically related to Entity Transformation as defined in the TransformMapping class
  *
  * @param $class
  * @return null | TransformMapping
  */
 public function getTransformAnnotations($class)
 {
     $annotations = $this->reader->getClassAnnotations(new \ReflectionClass($class));
     foreach ($annotations as $annotation) {
         if ($annotation instanceof TransformMapping) {
             return $annotation;
         }
     }
     return null;
 }
コード例 #2
0
ファイル: PerformanceTest.php プロジェクト: eltondias/Relogio
 /**
  * @group performance
  */
 public function testCachedReadPerformanceWithInMemory()
 {
     $reader = new CachedReader(new AnnotationReader(), new ArrayCache());
     $method = $this->getMethod();
     $time = microtime(true);
     for ($i = 0, $c = 500; $i < $c; $i++) {
         $reader->getMethodAnnotations($method);
     }
     $time = microtime(true) - $time;
     $this->printResults('cached reader (in-memory)', $time, $c);
 }
コード例 #3
0
ファイル: AnnHelper.php プロジェクト: nxnx/donatservice
 /**
  * Получает список параметров для которых определена аннотация $ann_name
  * @param mixed $object
  * @param callable $cb function($annotation_class,$propery_name){}
  */
 public function getFields($object, $annotation_class, callable $cb)
 {
     $reflClass = new \ReflectionClass($object);
     $props = $reflClass->getProperties();
     foreach ($props as $prop) {
         $annotation = $this->annotation_reader->getPropertyAnnotation($prop, $annotation_class);
         if (is_null($annotation)) {
             continue;
         }
         $cb($annotation, $prop->name);
     }
 }
コード例 #4
0
 /**
  * Annotations specifically related to Entity Transformation as defined in the Proxy class
  *
  * @param $class
  * @return null | Proxy
  */
 public function getProxyAnnotations($class)
 {
     if ($this->doctrineProxyResolver->isDoctrineProxy($class)) {
         $class = $this->doctrineProxyResolver->unwrapDoctrineProxyClass($class);
     }
     $annotations = $this->reader->getClassAnnotations(new \ReflectionClass($class));
     foreach ($annotations as $annotation) {
         if ($annotation instanceof Proxy) {
             return $annotation;
         }
     }
     return null;
 }
コード例 #5
0
 public function testIgnoresStaleCache()
 {
     $file = __DIR__ . '/Fixtures/Controller.php';
     touch($file);
     $name = 'Doctrine\\Tests\\Common\\Annotations\\Fixtures\\Controller';
     $cacheKey = $name . '@[Annot]';
     $cache = $this->getMock('Doctrine\\Common\\Cache\\Cache');
     $cache->expects($this->at(0))->method('fetch')->with($this->equalTo($cacheKey))->will($this->returnValue(array()));
     $cache->expects($this->at(1))->method('fetch')->with($this->equalTo('[C]' . $cacheKey))->will($this->returnValue(time() - 10));
     $cache->expects($this->at(2))->method('save')->with($this->equalTo($cacheKey));
     $cache->expects($this->at(3))->method('save')->with($this->equalTo('[C]' . $cacheKey));
     $reader = new CachedReader(new AnnotationReader(), $cache, true);
     $this->assertEquals(array(new Route(array('value' => '/someprefix'))), $reader->getClassAnnotations(new \ReflectionClass($name)));
 }
コード例 #6
0
 public static function getMappings(LifecycleEventArgs $eventArguments)
 {
     $meta = $eventArguments->getEntityManager()->getClassMetadata(get_class($eventArguments->getEntity()));
     $class = $meta->getReflectionClass();
     if (isset(self::$mappings[$class->getName()])) {
         return self::$mappings[$class->getName()];
     }
     self::$mappings[$class->getName()] = [];
     $reader = new CachedReader(new AnnotationReader(), $eventArguments->getEntityManager()->getConfiguration()->getMetadataCacheImpl());
     foreach ($class->getProperties() as $property) {
         $annotations = $reader->getPropertyAnnotations($property);
         foreach ($annotations as $annotation) {
             if (isset(self::$mappingNames[get_class($annotation)])) {
                 self::$mappings[$class->getName()][get_class($annotation)][$property->getName()] = $annotation;
             }
         }
     }
     return self::$mappings[$class->getName()];
 }
コード例 #7
0
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $metadata = $eventArgs->getClassMetadata();
     $cacheKey = $this->getCacheKey($metadata->getName());
     $cache = $this->getCache($eventArgs->getEntityManager());
     $enums = [];
     foreach ($metadata->getFieldNames() as $field) {
         if (isset(self::$enumTypeMap[$metadata->getTypeOfField($field)])) {
             $reflProp = $metadata->getReflectionClass()->getProperty($field);
             foreach ($this->annotationReader->getPropertyAnnotations($reflProp) as $annotation) {
                 if ($annotation instanceof Enum) {
                     $enums[$field] = $annotation;
                 }
             }
         }
     }
     if (count($enums)) {
         $cache->save($cacheKey, $enums);
     }
 }
 /**
  * On pre serialize
  *
  * @param ObjectEvent $event Event
  */
 public function onPreSerialize(ObjectEvent $event)
 {
     $object = $event->getObject();
     if ($object instanceof Proxy && !$object->__isInitialized()) {
         $object->__load();
     }
     $objectUid = spl_object_hash($object);
     if (in_array($objectUid, $this->serializedObjects)) {
         return;
     }
     $classAnnotation = $this->annotationReader->getClassAnnotation(new \ReflectionClass(ClassUtils::getClass($object)), VichSerializableClass::class);
     if ($classAnnotation instanceof VichSerializableClass) {
         $reflectionClass = ClassUtils::newReflectionClass(get_class($object));
         $this->logger->debug(sprintf('Found @VichSerializableClass annotation for the class "%s"', $reflectionClass->getName()));
         foreach ($reflectionClass->getProperties() as $property) {
             $vichSerializableAnnotation = $this->annotationReader->getPropertyAnnotation($property, VichSerializableField::class);
             if ($vichSerializableAnnotation instanceof VichSerializableField) {
                 $vichUploadableFileAnnotation = $this->annotationReader->getPropertyAnnotation($property, UploadableField::class);
                 if ($vichUploadableFileAnnotation instanceof UploadableField) {
                     throw new IncompatibleUploadableAndSerializableFieldAnnotationException(sprintf('The field "%s" in the class "%s" cannot have @UploadableField and @VichSerializableField annotations at the same moment.', $property->getName(), $reflectionClass->getName()));
                 }
                 $this->logger->debug(sprintf('Found @VichSerializableField annotation for the field "%s" in the class "%s"', $property->getName(), $reflectionClass->getName()));
                 $uri = null;
                 $property->setAccessible(true);
                 if ($property->getValue($event->getObject())) {
                     $uri = $this->storage->resolveUri($object, $vichSerializableAnnotation->getField());
                     if ($vichSerializableAnnotation->isIncludeHost()) {
                         $uri = $this->getHostUrl() . $uri;
                     }
                 }
                 $property->setValue($object, $uri);
             }
         }
         $this->serializedObjects[$objectUid] = $objectUid;
     }
 }
コード例 #9
0
 public function getMethodNameByClass($methodClass)
 {
     $refMethod = new \ReflectionClass($methodClass);
     $annotationMethod = $this->annotationReader->getClassAnnotation($refMethod, '\\TSCore\\JsonRpcServerBundle\\Method\\Annotation\\Method');
     return $annotationMethod->getName();
 }