Kdyby / Events

Events for Nette Framework
https://packagist.org/packages/kdyby/events
Other
57 stars 60 forks source link

Cannot instantiate abstract class Doctrine\Common\EventManager #105

Closed Wirone closed 7 years ago

Wirone commented 7 years ago

I've installed apigen/apigen globally and configured PHP to include global autoload.php using auto_prepend_file. It worked, until now. I've updated ApiGen (dev-master ddf5b27 => v4.1.2) and now I get in my Silex application:

FatalThrowableError in DoctrineServiceProvider.php line 104:

Cannot instantiate abstract class Doctrine\Common\EventManager
in DoctrineServiceProvider.php line 104
at DoctrineServiceProvider->Silex\Provider\{closure}(object(Application)) in Container.php line 113
at Container->offsetGet('dbs.event_manager') in DoctrineServiceProvider.php line 124
at DoctrineServiceProvider->Silex\Provider\{closure}(object(Application)) in Container.php line 113
at Container->offsetGet('db.event_manager') in DoctrineServiceProvider.php line 70
at DoctrineServiceProvider->Silex\Provider\{closure}(object(Application)) in Container.php line 113
at Container->offsetGet('dbs') in RepositoryServiceProvider.php line 43
at RepositoryServiceProvider->{closure}('default') in RepositoryServiceProvider.php line 52
at RepositoryServiceProvider->boot(object(Application)) in Application.php line 115
at Application->boot() in Application.php line 491
at Application->handle(object(Request)) in Application.php line 477
at Application->run() in index.php line 15

I open DoctrineServiceProvider, go to Doctrine\Common\EventManager and WTF? It's not abstract. Then I edit service provider and just before EventManager initialization I use:

$ref = new \ReflectionClass('Doctrine\Common\EventManager');
print $ref->getFileName() . ':' . $ref->getStartLine();

Effect?

<path>\Composer\vendor\kdyby\events\src\Doctrine\aliases.php:15

Why do you declare something which is incompatible with commonly used Doctrine class?

enumag commented 7 years ago

It's autoloaded only if the doctrine/common package is not installed. See https://github.com/Kdyby/Events/blob/master/src/Doctrine/compatibility.php.

Wirone commented 7 years ago

When Composer's global autoloading is added to auto_prepend_file in php.ini it is always loaded before actual application's autoload, so these aliases are defined and used within application.

For now I moved it to auto_append_file, but it's not good since I have symfony/var-dumper installed globally and I wanted to load it at the beginning and use it.

Wirone commented 7 years ago

In order to use auto_prepend_file (I miss dump for quick developing) I've tried to bypass it by removing apigen/apigen from Composer's global config and installing as standalone vendor in my docs root directory and configuring NetBeans to use it. But I got another error:

$ apigen.bat --debug

Fatal error: Class Kdyby\Events\SymfonyDispatcher contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symfony\Component\EventDispatcher\EventDispatcherInterface::getListenerPriority) in vendor\kdyby\events\src\Kdyby\Events\SymfonyDispatcher.php on line 30
ErrorException: Class Kdyby\Events\SymfonyDispatcher contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symfony\Component\EventDispatcher\EventDispatcherInterface::getListenerPriority) in vendor\kdyby\events\src\Kdyby\Events\SymfonyDispatcher.php:30
Stack trace:
#0 [internal function]: Tracy\Debugger::shutdownHandler()
#1 {main}

composer.json

{
    "prefer-stable": true,
    "require": {
        "apigen/apigen": "~4.1"
    }
}

composer info

$ composer info
andrewsville/php-token-reflection 1.4.0   Library emulating the PHP internal reflection using just the tokenized source code.
apigen/apigen                     v4.1.2  PHP source code API generator
apigen/theme-bootstrap            v1.1.3  Twitter Bootstrap theme for ApiGen
apigen/theme-default              v1.0.2  Default theme for ApiGen
herrera-io/json                   1.0.3   A library for simplifying JSON linting and validation.
herrera-io/phar-update            2.0.0   A library for self-updating Phars.
herrera-io/version                1.1.1   A library for creating, editing, and comparing semantic versioning numbers.
justinrainbow/json-schema         1.6.1   A library to validate a json schema.
kdyby/events                      v2.4.1  Events for Nette Framework
kukulich/fshl                     2.1.0   FSHL is a free, open source, universal, fast syntax highlighter written in PHP.
latte/latte                       v2.3.4  Latte: the amazing template engine for PHP
michelf/php-markdown              1.7.0   PHP Markdown
nette/application                 v2.4.2  Nette Application MVC Component
nette/bootstrap                   v2.4.1  Nette Bootstrap
nette/caching                     v2.5.2  Nette Caching Component
nette/component-model             v2.3.0  Nette Component Model
nette/di                          v2.4.4  Nette Dependency Injection Component
nette/finder                      v2.4.0  Nette Finder: Files Searching
nette/http                        v2.4.2  Nette HTTP Component
nette/mail                        v2.4.1  Nette Mail: Sending E-mails
nette/neon                        v2.4.0  Nette NEON: parser & generator for Nette Object Notation
nette/php-generator               v2.4.1  Nette PHP Generator
nette/reflection                  v2.4.0  Nette PHP Reflection Component
nette/robot-loader                v2.4.1  Nette RobotLoader: comfortable autoloading
nette/safe-stream                 v2.3.2  Nette SafeStream: Atomic Operations
nette/utils                       v2.4.1  Nette Utility Classes
psr/log                           1.0.2   Common interface for logging libraries
seld/jsonlint                     1.5.0   JSON Linter
symfony/console                   v2.8.15 Symfony Console Component
symfony/debug                     v3.0.9  Symfony Debug Component
symfony/options-resolver          v2.6.13 Symfony OptionsResolver Component
symfony/polyfill-mbstring         v1.3.0  Symfony polyfill for the Mbstring extension
symfony/yaml                      v2.8.15 Symfony Yaml Component
tracy/tracy                       v2.4.4  Tracy: useful PHP debugger

Sigh...

fprochazka commented 7 years ago

Sorry, but I have no idea what is this good for, but this doesn't sound right to me

I've installed apigen/apigen globally and configured PHP to include global autoload.php using auto_prepend_file.

Possible solution might be for you the #97.

Wirone commented 7 years ago

Ahahahaha. "doesn't sound right to me", ok, this is the final argument.

I'm going to tell Composer's developers that whole "global" thing is "not right". Let's download every vendor everytime instead of using e.g. symfony/var-dumper globally for all projects.

You made my day :joy:

fprochazka commented 7 years ago

Yeah, global dependencies are wrong :) I'm happy you agree!

Majkl578 commented 7 years ago

I'm going to tell Composer's developers that whole "global" thing is "not right".

You can of couse. Global installation is meant solely for projects that are used directly from CLI, not for libraries with dependants etc.

since I have symfony/var-dumper installed globally and I wanted to load it at the beginning and use it

This is definitely totally wrong.

Let's download every vendor everytime instead of using e.g. symfony/var-dumper globally for all projects.

Correct, that's intended way of how dependencies are supposed to work. Don't forget there are multiple versions etc.

Wirone commented 7 years ago

I will not go further with this discussion because it does not make sense. I think global LIBRARIES (not dependencies! I'm using dump for debugging because I know it's installed and loaded, project does not depend on it in any way) are still better than "mocking" interfaces (not compatible...) from other libraries to fix own library. Cheers!