Skip to content

Commit

Permalink
Merge d221cb1 into 0a6fa6a
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Jan 13, 2020
2 parents 0a6fa6a + d221cb1 commit a12fe7c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
23 changes: 18 additions & 5 deletions DependencyInjection/GraphqliteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
use ReflectionParameter;
use Symfony\Component\Cache\Simple\ApcuCache as SymfonyApcuCache;
use Symfony\Component\Cache\Simple\PhpFilesCache as SymfonyPhpFilesCache;
use function filter_var;
use function function_exists;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ObjectType;
use Psr\Container\ContainerInterface;
use ReflectionClass;
use ReflectionMethod;
use function ini_get;
use function interface_exists;
use function php_sapi_name;
use function str_replace;
use function strpos;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down Expand Up @@ -252,7 +256,7 @@ public function process(ContainerBuilder $container)
$this->mapAdderToTag('graphql.type_mapper_factory', 'addTypeMapperFactory', $container, $schemaFactory);

// Configure cache
if (ApcuAdapter::isSupported()) {
if (ApcuAdapter::isSupported() && (PHP_SAPI !== 'cli' || filter_var(ini_get('apc.enabled_cli')))) {
$container->setAlias('graphqlite.cache', 'graphqlite.apcucache');
} else {
$container->setAlias('graphqlite.cache', 'graphqlite.phpfilescache');
Expand Down Expand Up @@ -421,12 +425,21 @@ private function getCodeCache(): ClassBoundCacheContractInterface
private function getClassList(string $namespace, int $globTtl = 2, bool $recursive = true): array
{
$explorer = new GlobClassExplorer($namespace, $this->getPsr16Cache(), $globTtl, ClassNameMapper::createFromComposerFile(null, null, true), $recursive);
$allClasses = $explorer->getClasses();
$allClasses = $explorer->getClassMap();
$classes = [];
foreach ($allClasses as $className) {
if (! class_exists($className)) {
continue;
foreach ($allClasses as $className => $phpFile) {
if (! class_exists($className, false)) {
// Let's try to load the file if it was not imported yet.
// We are importing the file manually to avoid triggering the autoloader.
// The autoloader might trigger errors if the file does not respect PSR-4 or if the
// Symfony DebugAutoLoader is installed. (see https://github.com/thecodingmachine/graphqlite/issues/216)
require_once $phpFile;
// Does it exists now?
if (! class_exists($className, false)) {
continue;
}
}

$refClass = new ReflectionClass($className);
if (! $refClass->isInstantiable()) {
continue;
Expand Down
8 changes: 8 additions & 0 deletions Tests/Fixtures/Entities/BadClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php


// The namespace for this class is broken. It must not impact Symfony.
class BadClass
{

}
6 changes: 5 additions & 1 deletion Tests/GraphqliteTestingKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
'secret' => 'S0ME_SECRET'
);

$frameworkConf['cache'] =[
'app' => 'cache.adapter.array',
];

if ($this->enableSession) {
$frameworkConf['session'] =[
'enabled' => true,
Expand Down Expand Up @@ -139,6 +143,6 @@ protected function configureRoutes(RouteCollectionBuilder $routes)

public function getCacheDir()
{
return __DIR__.'/../cache/'.spl_object_hash($this);
return __DIR__.'/../cache/'.($this->enableSession?'withSession':'withoutSession').$this->enableLogin.($this->enableSecurity?'withSecurity':'withoutSecurity').$this->enableMe;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require" : {
"php" : ">=7.2",
"thecodingmachine/graphqlite" : "~4.0.0",
"thecodingmachine/graphqlite" : "~4.0.1",
"thecodingmachine/graphqlite-symfony-validator-bridge" : "~4.0.0",
"symfony/framework-bundle": "^4.1.9 | ^5",
"symfony/validator": "^4.1.9 | ^5",
Expand Down

0 comments on commit a12fe7c

Please sign in to comment.