-
Notifications
You must be signed in to change notification settings - Fork 223
Allow using project composer Classloader and some more optimizations #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Contributing | ||
============ | ||
|
||
Running tests | ||
-------------- | ||
|
||
Install [phpunit](https://phpunit.de/manual/current/en/installation.html). | ||
|
||
In the bundle directory: | ||
|
||
```bash | ||
bin/phpunit | ||
``` | ||
|
||
Giving some love to PHP CS | ||
--------------------------- | ||
|
||
```bash | ||
bin/php-cs-fixer fix ./ | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,22 @@ class ConfigTypesPass implements CompilerPassInterface | |
public function process(ContainerBuilder $container) | ||
{ | ||
$config = $container->getParameter('overblog_graphql_types.config'); | ||
$generatedClasses = $container->get('overblog_graphql.cache_compiler')->compile($this->processConfig($config)); | ||
$generatedClasses = $container->get('overblog_graphql.cache_compiler')->compile( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea to extract |
||
$this->processConfig($config), | ||
$container->getParameter('overblog_graphql.use_classloader_listener') | ||
); | ||
|
||
foreach ($generatedClasses as $class => $file) { | ||
if (!class_exists($class)) { | ||
throw new \RuntimeException(sprintf( | ||
'Type class %s not found. If you are using your own classLoader verify the path and the namespace please.', | ||
json_encode($class)) | ||
); | ||
} | ||
$aliases = call_user_func($class.'::getAliases'); | ||
$this->setTypeServiceDefinition($container, $class, $aliases); | ||
} | ||
$container->getParameterBag()->remove('overblog_graphql_types.config'); | ||
} | ||
|
||
private function setTypeServiceDefinition(ContainerBuilder $container, $class, array $aliases) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,13 +199,13 @@ public function compile(array $configs, $loadClasses = true) | |
|
||
$classes = $this->generateClasses($configs, $cacheDir, true); | ||
|
||
$content = "<?php\nreturn ".var_export($classes, true).';'; | ||
// replaced hard-coding absolute path by __DIR__ (see https://github.com/overblog/GraphQLBundle/issues/167) | ||
$content = str_replace(' => \''.$cacheDir, ' => __DIR__ . \'', $content); | ||
if ($loadClasses) { | ||
$content = "<?php\nreturn ".var_export($classes, true).';'; | ||
// replaced hard-coding absolute path by __DIR__ (see https://github.com/overblog/GraphQLBundle/issues/167) | ||
$content = str_replace(' => \''.$cacheDir, ' => __DIR__ . \'', $content); | ||
|
||
file_put_contents($this->getClassesMap(), $content); | ||
file_put_contents($this->getClassesMap(), $content); | ||
|
||
if ($loadClasses) { | ||
$this->loadClasses(true); | ||
} | ||
|
||
|
@@ -216,8 +216,14 @@ public function loadClasses($forceReload = false) | |
{ | ||
if (!self::$classMapLoaded || $forceReload) { | ||
$classes = require $this->getClassesMap(); | ||
|
||
$mapClassLoader = new ClassLoader(); | ||
/** @var ClassLoader $mapClassLoader */ | ||
static $mapClassLoader = null; | ||
if (null === $mapClassLoader) { | ||
$mapClassLoader = new ClassLoader(); | ||
$mapClassLoader->setClassMapAuthoritative(true); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to enter this else statement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it is null on init because $mapClassLoader is declare as static so after it init it always has the same instance of ClassLoader. |
||
$mapClassLoader->unregister(); | ||
} | ||
$mapClassLoader->addClassMap($classes); | ||
$mapClassLoader->register(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool 👍