/**
  * @since  3.1.0
  * @group  issue_58
  * @test
  */
 public function canEnableOtherAnnotationCache()
 {
     $annotationData = $this->createdCachedAnnotation();
     persistAnnotations(function () use($annotationData) {
         return $annotationData;
     }, function ($data) {
     });
     assertTrue(AnnotationCache::has('foo', 'bar'));
 }
Esempio n. 2
0
/**
 * returns annotations for given reflected
 *
 * @param   \Reflector|string|object  $reflected   class name, function name of or object instance to reflect
 * @param   string                    $methodName  optional  specific method to reflect
 * @return  \stubbles\reflect\annotation\Annotations
 * @since   5.3.0
 */
function annotationsOf($reflected, string $methodName = null) : Annotations
{
    $reflector = $reflected instanceof \Reflector ? $reflected : reflect($reflected, $methodName);
    $target = _annotationTarget($reflector);
    if (AnnotationCache::has($target)) {
        return AnnotationCache::get($target);
    }
    list($sourceTarget) = explode('#', $target);
    $return = null;
    foreach (Annotations::parse(docComment($reflector), $sourceTarget) as $annotations) {
        AnnotationCache::put($annotations);
        if ($annotations->target() === $target) {
            $return = $annotations;
        }
    }
    if (null === $return) {
        $return = new Annotations($target);
        AnnotationCache::put($return);
    }
    return $return;
}
 /**
  * @since  3.0.0
  * @group  issue_58
  * @test
  */
 public function startAnnotationCacheWithNonSerializedCacheDataThrowsRuntimeException()
 {
     expect(function () {
         AnnotationCache::start(function () {
             return 'foo';
         }, function () {
         });
     })->throws(\RuntimeException::class);
 }