Skip to content

Commit

Permalink
fix: metadata cache loading
Browse files Browse the repository at this point in the history
  • Loading branch information
bednic committed Aug 31, 2020
1 parent 800dcc0 commit 7fb43eb
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 31 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -39,7 +39,8 @@
"psr/http-server-middleware": "^1.0",
"psr/log": "^1.1",
"psr/simple-cache": "^1.0",
"swaggest/json-schema": "^0.12.29"
"swaggest/json-schema": "^0.12.29",
"symfony/class-loader": "^3.4"
},
"require-dev": {
"doctrine/cache": "^1.8",
Expand Down
1 change: 1 addition & 0 deletions json-api.iml
Expand Up @@ -62,6 +62,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/squizlabs/php_codesniffer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/swaggest/json-diff" />
<excludeFolder url="file://$MODULE_DIR$/vendor/swaggest/json-schema" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/class-loader" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-grapheme" />
Expand Down
27 changes: 3 additions & 24 deletions src/Metadata/MetadataFactory.php
Expand Up @@ -15,8 +15,7 @@
use Psr\Log\NullLogger;
use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\InvalidArgumentException as CacheException;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Symfony\Component\ClassLoader\ClassMapGenerator;

/**
* Class MetadataFactory
Expand Down Expand Up @@ -153,28 +152,8 @@ private function createMetadataCache(): void
if (!is_dir($path)) {
throw new InvalidArgumentException("Path '$path' is not directory.");
}
$predeclaredClasses = get_declared_classes();
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$it->rewind();
while ($it->valid()) {
/** @var $it RecursiveDirectoryIterator */
if (!$it->isDot()) {
$file = $it->key();
if (
is_file($file)
&& (
isset(pathinfo($file)["extension"])
&& pathinfo($file)["extension"] === "php"
)
) {
require_once $file;
}
}
$it->next();
}
$newLoadedClasses = array_diff(get_declared_classes(), $predeclaredClasses);

foreach ($newLoadedClasses as $className) {
$map = ClassMapGenerator::createMap($path);
foreach ($map as $className => $file) {
try {
$this->loadMetadata($className);
} catch (ClassNotResource $ignored) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Driver/AnnotationMisplaceTest.php
Expand Up @@ -12,7 +12,7 @@
class AnnotationMisplaceTest extends TestCase
{

protected $runTestInSeparateProcess = true;


public function testConstruct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Driver/BadMethodSignatureTest.php
Expand Up @@ -18,7 +18,7 @@
class BadMethodSignatureTest extends TestCase
{

protected $runTestInSeparateProcess = true;


public function testConstruct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Driver/ClassNotExistTest.php
Expand Up @@ -10,7 +10,7 @@

class ClassNotExistTest extends TestCase
{
protected $runTestInSeparateProcess = true;


public function testConstruct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Driver/ClassNotResourceTest.php
Expand Up @@ -11,7 +11,7 @@

class ClassNotResourceTest extends TestCase
{
protected $runTestInSeparateProcess = true;


public function testConstruct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Driver/MethodNotExistTest.php
Expand Up @@ -11,7 +11,7 @@

class MethodNotExistTest extends TestCase
{
protected $runTestInSeparateProcess = true;


public function testConstruct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Metadata/NameUsedAlreadyTest.php
Expand Up @@ -11,7 +11,7 @@

class NameUsedAlreadyTest extends TestCase
{
protected $runTestInSeparateProcess = true;


public function testConstruct()
{
Expand Down

0 comments on commit 7fb43eb

Please sign in to comment.