mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Optimized.
This commit is contained in:
parent
0104246011
commit
fe265aa632
@ -15,7 +15,6 @@ namespace Hyperf\Di\Annotation;
|
|||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||||
use Hyperf\Di\Aop\Ast;
|
use Hyperf\Di\Aop\Ast;
|
||||||
use Hyperf\Di\Aop\AstCollector;
|
|
||||||
use Hyperf\Di\ReflectionManager;
|
use Hyperf\Di\ReflectionManager;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ use Hyperf\Di\Annotation\AspectCollector;
|
|||||||
use Hyperf\Di\Annotation\Inject;
|
use Hyperf\Di\Annotation\Inject;
|
||||||
use Hyperf\Di\Annotation\Scanner;
|
use Hyperf\Di\Annotation\Scanner;
|
||||||
use Hyperf\Di\Aop\AstCollector;
|
use Hyperf\Di\Aop\AstCollector;
|
||||||
use Hyperf\Di\MetadataCacheCollector;
|
|
||||||
use Hyperf\Di\ReflectionManager;
|
use Hyperf\Di\ReflectionManager;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionFunctionAbstract;
|
use ReflectionFunctionAbstract;
|
||||||
@ -25,7 +24,6 @@ use Symfony\Component\Finder\Finder;
|
|||||||
use function class_exists;
|
use function class_exists;
|
||||||
use function count;
|
use function count;
|
||||||
use function explode;
|
use function explode;
|
||||||
use function fclose;
|
|
||||||
use function feof;
|
use function feof;
|
||||||
use function fgets;
|
use function fgets;
|
||||||
use function file_exists;
|
use function file_exists;
|
||||||
@ -57,7 +55,7 @@ class DefinitionSource implements DefinitionSourceInterface
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $cachePath = BASE_PATH . '/runtime/container/annotations.cache';
|
private $cachePath = BASE_PATH . '/runtime/container/annotations';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -222,7 +220,7 @@ class DefinitionSource implements DefinitionSourceInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* if you are a hyperf developer
|
* if you are a hyperf developer
|
||||||
* this var value will be your local path, like hyperf/src
|
* this var value will be your local path, like hyperf/src.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
$ident = 'vendor';
|
$ident = 'vendor';
|
||||||
@ -235,13 +233,9 @@ class DefinitionSource implements DefinitionSourceInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$collectors = [
|
$this->loadMetadata($appPaths, $collectors, 'app');
|
||||||
AnnotationCollector::class,
|
$this->loadMetadata($vendorPaths, $collectors, 'vendor');
|
||||||
AspectCollector::class,
|
|
||||||
];
|
|
||||||
|
|
||||||
$appMetadata = $this->loadMetadata($appPaths, $collectors, 'app');
|
|
||||||
$vendorMetadata = $this->loadMetadata($vendorPaths, $collectors, 'vendor');
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,15 +244,12 @@ class DefinitionSource implements DefinitionSourceInterface
|
|||||||
if (empty($paths)) {
|
if (empty($paths)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$cachePath = $this->cachePath . '.' . $type;
|
$cachePath = $this->cachePath . '.' . $type . '.cache';
|
||||||
$pathsHash = md5(implode(',', $paths));
|
$pathsHash = md5(implode(',', $paths));
|
||||||
$cacher = new MetadataCacheCollector($collectors);
|
|
||||||
if ($this->hasAvailableCache($paths, $pathsHash, $cachePath)) {
|
if ($this->hasAvailableCache($paths, $pathsHash, $cachePath)) {
|
||||||
$this->printLn('Detected an available cache, skip the ' . $type . ' scan process.');
|
$this->printLn('Detected an available cache, skip the ' . $type . ' scan process.');
|
||||||
[, $serialized] = explode(PHP_EOL, file_get_contents($cachePath));
|
[, $serialized] = explode(PHP_EOL, file_get_contents($cachePath));
|
||||||
$serialized = base64_decode($serialized);
|
$this->scanner->collect(unserialize($serialized));
|
||||||
$cacher->unserialize($serialized);
|
|
||||||
$this->scanner->collect(array_keys(unserialize($serialized)));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->printLn('Scanning ' . $type . ' ...');
|
$this->printLn('Scanning ' . $type . ' ...');
|
||||||
@ -282,7 +273,7 @@ class DefinitionSource implements DefinitionSourceInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = implode(PHP_EOL, [$pathsHash, base64_encode(serialize($meta))]);
|
$data = implode(PHP_EOL, [$pathsHash, serialize(array_keys($meta))]);
|
||||||
file_put_contents($cachePath, $data);
|
file_put_contents($cachePath, $data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user