diff --git a/src/Kdyby/Events/DI/EventsExtension.php b/src/Kdyby/Events/DI/EventsExtension.php index 67ff804..3d45f39 100644 --- a/src/Kdyby/Events/DI/EventsExtension.php +++ b/src/Kdyby/Events/DI/EventsExtension.php @@ -89,13 +89,13 @@ public function loadConfiguration() Nette\Utils\Validators::assertField($config, 'subscribers', 'array'); foreach ($config['subscribers'] as $subscriber) { $def = $builder->addDefinition($this->prefix('subscriber.' . md5(Nette\Utils\Json::encode($subscriber)))); - list($def->factory) = Nette\DI\Compiler::filterArguments(array( + $def->setFactory(Nette\DI\Compiler::filterArguments(array( is_string($subscriber) ? new Nette\DI\Statement($subscriber) : $subscriber - )); + ))[0]); - list($subscriberClass) = (array) $builder->normalizeEntity($def->factory->entity); + list($subscriberClass) = (array) $builder->normalizeEntity($def->getEntity()); if (class_exists($subscriberClass)) { - $def->class = $subscriberClass; + $def->setClass($subscriberClass); } $def->setAutowired(FALSE); @@ -145,12 +145,12 @@ public function beforeCompile() public function afterCompile(Code\ClassType $class) { - $init = $class->methods['initialize']; + $init = $class->getMethod('initialize'); /** @hack This tries to add the event invokation right after the code, generated by NetteExtension. */ $foundNetteInitStart = $foundNetteInitEnd = FALSE; - $lines = explode(";\n", trim($init->body)); - $init->body = NULL; + $lines = explode(";\n", trim($init->getBody())); + $init->setBody(NULL); while (($line = array_shift($lines)) || $lines) { if ($foundNetteInitStart && !$foundNetteInitEnd && stripos($line, 'Nette\\') === FALSE && stripos($line, 'set_include_path') === FALSE && stripos($line, 'date_default_timezone_set') === FALSE @@ -191,8 +191,8 @@ public function afterCompile(Code\ClassType $class) */ private function validateSubscribers(Nette\DI\ContainerBuilder $builder, Nette\DI\ServiceDefinition $manager) { - foreach ($manager->setup as $stt) { - if ($stt->entity !== 'addEventSubscriber') { + foreach ($manager->getSetup() as $stt) { + if ($stt->getEntity() !== 'addEventSubscriber') { $this->allowedManagerSetup[] = $stt; continue; } @@ -209,32 +209,32 @@ private function validateSubscribers(Nette\DI\ContainerBuilder $builder, Nette\D ); } - if (!$def->class) { + if (!$def->getClass()) { throw new AssertionException( "Please, specify existing class for " . (is_numeric($serviceName) ? 'anonymous ' : '') . "service '$serviceName' explicitly, " . "and make sure, that the class exists and can be autoloaded." ); - } elseif (!class_exists($def->class)) { + } elseif (!class_exists($def->getClass())) { throw new AssertionException( - "Class '{$def->class}' of " . (is_numeric($serviceName) ? 'anonymous ' : '') . "service '$serviceName' cannot be found. " . + "Class '" . $def->getClass() . "' of " . (is_numeric($serviceName) ? 'anonymous ' : '') . "service '$serviceName' cannot be found. " . "Please make sure, that the class exists and can be autoloaded." ); } - if (!in_array('Doctrine\Common\EventSubscriber' , class_implements($def->class))) { + if (!in_array('Doctrine\Common\EventSubscriber' , class_implements($def->getClass()))) { // the minimum is Doctrine EventSubscriber, but recommend is Kdyby Subscriber throw new AssertionException("Subscriber '$serviceName' doesn't implement Kdyby\\Events\\Subscriber."); } $eventNames = array(); - $listenerInst = self::createInstanceWithoutConstructor($def->class); + $listenerInst = self::createInstanceWithoutConstructor($def->getClass()); foreach ($listenerInst->getSubscribedEvents() as $eventName => $params) { if (is_numeric($eventName) && is_string($params)) { // [EventName, ...] list(, $method) = Kdyby\Events\Event::parseName($params); $eventNames[] = ltrim($params, '\\'); if (!method_exists($listenerInst, $method)) { - throw new AssertionException("Event listener " . $def->class . "::{$method}() is not implemented."); + throw new AssertionException("Event listener " . $def->getClass() . "::{$method}() is not implemented."); } } elseif (is_string($eventName)) { // [EventName => ???, ...] @@ -242,18 +242,18 @@ private function validateSubscribers(Nette\DI\ContainerBuilder $builder, Nette\D if (is_string($params)) { // [EventName => method, ...] if (!method_exists($listenerInst, $params)) { - throw new AssertionException("Event listener " . $def->class . "::{$params}() is not implemented."); + throw new AssertionException("Event listener " . $def->getClass() . "::{$params}() is not implemented."); } } elseif (is_string($params[0])) { // [EventName => [method, priority], ...] if (!method_exists($listenerInst, $params[0])) { - throw new AssertionException("Event listener " . $def->class . "::{$params[0]}() is not implemented."); + throw new AssertionException("Event listener " . $def->getClass() . "::{$params[0]}() is not implemented."); } } else { foreach ($params as $listener) { // [EventName => [[method, priority], ...], ...] if (!method_exists($listenerInst, $listener[0])) { - throw new AssertionException("Event listener " . $def->class . "::{$listener[0]}() is not implemented."); + throw new AssertionException("Event listener " . $def->getClass() . "::{$listener[0]}() is not implemented."); } } } @@ -268,9 +268,9 @@ private function validateSubscribers(Nette\DI\ContainerBuilder $builder, Nette\D private function isAlias(Nette\DI\ServiceDefinition $definition) { - return $definition->factory instanceof Nette\DI\Statement && ( - $definition->factory->entity instanceof Nette\DI\ServiceDefinition - || (is_string($definition->factory->entity) && substr($definition->factory->entity, 0, 1) === '@') + return $definition->getFactory() && ( + $definition->getEntity() instanceof Nette\DI\ServiceDefinition + || (is_string($definition->getEntity()) && substr($definition->getEntity(), 0, 1) === '@') ); } @@ -287,11 +287,11 @@ private function autowireEvents(Nette\DI\ContainerBuilder $builder) continue; // alias } - if (!class_exists($class = $builder->expand($def->class))) { - if (!$def->factory) { + if (!class_exists($class = $builder->expand($def->getClass()))) { + if (!$def->getFactory()) { continue; - } elseif (is_array($class = $builder->expand($def->factory->entity))) { + } elseif (is_array($class = $builder->expand($def->getEntity()))) { continue; } elseif (!class_exists($class)) { @@ -364,7 +364,7 @@ private function optimizeListeners(Nette\DI\ContainerBuilder $builder) $builder->getDefinition($this->prefix('manager')) ->setClass('Kdyby\Events\LazyEventManager', array($listeners)) - ->setup = $this->allowedManagerSetup; + ->setSetup($this->allowedManagerSetup); } diff --git a/tests/KdybyTests/Events/Extension.phpt b/tests/KdybyTests/Events/Extension.phpt index f0067d6..7249af9 100644 --- a/tests/KdybyTests/Events/Extension.phpt +++ b/tests/KdybyTests/Events/Extension.phpt @@ -76,7 +76,7 @@ class ExtensionTest extends Tester\TestCase Assert::match('Please, specify existing class for service \'events.subscriber.%a%\' explicitly, and make sure, that the class exists and can be autoloaded.', $e->getMessage()); } catch (Nette\DI\ServiceCreationException $e) { - Assert::match("Class NonExistingClass_%a% used in service 'events.subscriber.%a%' not found or is not instantiable.", $e->getMessage()); + Assert::match("Class NonExistingClass_%a% used in service 'events.subscriber.%a%' not found%a?%.", $e->getMessage()); } catch (\Exception $e) { Assert::fail($e->getMessage());