-
Notifications
You must be signed in to change notification settings - Fork 101
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
Make Kdyby/Events optional #266
Conversation
Travis is failing because of some incompatibility in dev Nette. |
Failing because of Kdyby/Console#54. |
|
||
|
||
|
||
protected function processRepositories() |
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.
I would like to keep this as a separate method
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.
No problem. It's just that beforeCompile will only call this method and nothing else which seems a bit odd. But sure. :-)
I've cherrypicked and fixed few missing occurences of |
18701c1
to
eff881f
Compare
Travis finally passed after rebase. Which means I at least didn't break any tests. I'm still unable to run the tests on localhost though so writing a new test is not easy. |
Finally managed to run the tests on localhost by using In the end I didn't write any new tests, just changed the old ones little bit:
|
@fprochazka With the tests updated I'm satisfied with this PR as it is. Can you review the changes please? :-) |
Refactored Kdyby/Events detection since you recently wanted a method instead of a property in similar case in Kdyby/Console. |
@@ -64,6 +69,12 @@ protected function createMemoryManager() | |||
|
|||
|
|||
|
|||
protected function configure(Configurator $config) |
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.
this is not used anywhere
@enumag Thank you, merged! I've made some minor changes diff --git a/src/Kdyby/Doctrine/DI/OrmExtension.php b/src/Kdyby/Doctrine/DI/OrmExtension.php
index 7155fd4..0da259f 100644
--- a/src/Kdyby/Doctrine/DI/OrmExtension.php
+++ b/src/Kdyby/Doctrine/DI/OrmExtension.php
@@ -351,24 +351,26 @@ class OrmExtension extends Nette\DI\CompilerExtension
$this->targetEntityMappings = Nette\Utils\Arrays::mergeTree($this->targetEntityMappings, $config['targetEntityMappings']);
}
- $entityManagerArguments = [
- $connectionService = $this->processConnection($name, $defaults, $isDefault),
- $this->prefix('@' . $name . '.ormConfiguration'),
- ];
-
if ($this->isKdybyEventsPresent()) {
$builder->addDefinition($this->prefix($name . '.evm'))
->setClass('Kdyby\Events\NamespacedEventManager', [Kdyby\Doctrine\Events::NS . '::'])
->addSetup('$dispatchGlobalEvents', [TRUE]) // for BC
->setAutowired(FALSE);
- $entityManagerArguments[] = $this->prefix('@' . $name . '.evm');
+ } else {
+ $builder->addDefinition($this->prefix($name . '.evm'))
+ ->setClass('Doctrine\Common\EventManager')
+ ->setAutowired(FALSE);
}
// entity manager
$entityManager = $builder->addDefinition($managerServiceId = $this->prefix($name . '.entityManager'))
->setClass('Kdyby\Doctrine\EntityManager')
- ->setFactory('Kdyby\Doctrine\EntityManager::create', $entityManagerArguments)
+ ->setFactory('Kdyby\Doctrine\EntityManager::create', [
+ $connectionService = $this->processConnection($name, $defaults, $isDefault),
+ $this->prefix('@' . $name . '.ormConfiguration'),
+ $this->prefix('@' . $name . '.evm'),
+ ])
->addTag(self::TAG_ENTITY_MANAGER)
->addTag('kdyby.doctrine.entityManager')
->setAutowired($isDefault)
@@ -523,19 +525,13 @@ class OrmExtension extends Nette\DI\CompilerExtension
// connection
$options = array_diff_key($config, array_flip(['types', 'resultCache', 'connection', 'logging']));
-
- $connectionArguments = [
- $options,
- $this->prefix('@' . $name . '.dbalConfiguration'),
- ];
-
- if ($this->isKdybyEventsPresent()) {
- $connectionArguments[] = $this->prefix('@' . $name . '.evm');
- }
-
$connection = $builder->addDefinition($connectionServiceId = $this->prefix($name . '.connection'))
->setClass('Kdyby\Doctrine\Connection')
- ->setFactory('Kdyby\Doctrine\Connection::create', $connectionArguments)
+ ->setFactory('Kdyby\Doctrine\Connection::create', [
+ $options,
+ $this->prefix('@' . $name . '.dbalConfiguration'),
+ $this->prefix('@' . $name . '.evm'),
+ ])
->addSetup('setSchemaTypes', [$schemaTypes])
->addSetup('setDbalTypes', [$dbalTypes])
->addTag(self::TAG_CONNECTION)
diff --git a/tests/KdybyTests/Doctrine/ORMTestCase.php b/tests/KdybyTests/Doctrine/ORMTestCase.php
index 0d6a521..b6d0f4f 100644
--- a/tests/KdybyTests/Doctrine/ORMTestCase.php
+++ b/tests/KdybyTests/Doctrine/ORMTestCase.php
@@ -69,12 +69,6 @@ abstract class ORMTestCase extends Tester\TestCase
- protected function configure(Configurator $config)
- {
- }
-
-
-
/**
* @param string $className
* @param array $props
diff --git a/tests/KdybyTests/nette-reset.neon b/tests/KdybyTests/nette-reset.neon
index 0e29325..cc18417 100644
--- a/tests/KdybyTests/nette-reset.neon
+++ b/tests/KdybyTests/nette-reset.neon
@@ -31,5 +31,3 @@ session:
services:
cacheStorage:
class: Nette\Caching\Storages\MemoryStorage
- evm:
- class: Doctrine\Common\EventManager |
If I'm not mistaken those minor changes break what I intended - I need the evm to be autowired, not use some dummy replacement |
I know, but I don't want the users to have to configure some magic service, that should be configured by Kdyby. Now you can
IMHO it's cleaner that way and it makes sense that the third requires you to touch the |
I can't agree. I have an extension providing a simple ContainerAwareEventManager and wanted to use it in Kdyby Doctrine. However my extension should not be aware of Kdyby/Doctrine at all (it's independent) - you're forcing me to specifically look for OrmExtension and hack it. That's not clean at all. |
First of all
I hope you understand that. I wanna avoid this at all costs. By just simply accepting what you've proposed, It would be simple for you, but I'd cripple the UX of the lib for everyone else. About your argument - I don't consider it hacking. But I understand why you don't like it. What about adding another case - if Kdyby/Events is not registered and a service of type |
How about adding the evm service only if there is no autowired EventManager? EDIT: Well that alias means pretty much the same thing so I don't care which one of these two solutions we use. |
Imho it would be better to do something like $evm = $builder->addDefinition($this->prefix($name . '.evm'))
->setClass('Doctrine\Common\EventManager')
->setAutowired(FALSE);
if ($customEvmService = $builder->getByType('Doctrine\Common\EventManager')) {
$evm->setFactory('@' . $customEvmService);
} but that's a detail :) |
@fprochazka Yeah. This is fine by me. :-) |
My point is that you don't have to introduce more if's in the rest of the code :) |
I'm aware... I didn't like the ifs in my PR either. :-) |
I'm lazy to write a test for it right now. You mind doing it and sending a PR? |
Well... You're well aware that I won't refuse. :-D |
#239
I wanted to add some tests but unfortunately I was not even able to run the current tests - PHP just crashed. :-( Which means this is highly experimental.