codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
43 stars 24 forks source link

Contao 4 error #98

Closed garyee closed 7 years ago

garyee commented 7 years ago

Hi,

so I'm on my first Contao 4 Project now. With Contao 4.3.5 managed Edition. Haste is a dependency of a conato extension I need. At first I tried just putting the extension in the /system/modules/ folder . That did not work. Than I installed it with the composer, but since there is no Pluign oder Bundle Class, this way did not work either. So I retried the "old way" (/system/modules/) and found the following fault in the error-log:

[2017-02-27 15:36:12] request.INFO: Matched route "contao_install". {"route":"contao_install","route_parameters":{"_scope":"backend","_token_check":true,"_controller":"Contao\InstallationBundle\Controller\InstallationController::installAction","_route":"contao_install"},"request_uri":"localhost/contao/install","method":"GET"} [] [2017-02-27 15:36:14] app.CRITICAL: An exception occurred. {"exception":"[object] (Symfony\Component\Debug\Exception\ClassNotFoundException(code: 0): Attempted to load class \"DateRangeFilter\" from namespace \"Haste\Dca\".\nDid you forget a \"use\" statement for another namespace? at C:\xampp\htdocs_contao_4\vendor\contao\core-bundle\src\Resources\contao\library\Contao\System.php:166)"} []

In the Frontend there was this Stacktrace:

unbenannt

aschempp commented 7 years ago

I'm pretty sure this is a dependency issue. Did you install the _autoload extension that is required for Haste if you don't use Composer?

garyee commented 7 years ago

I did not, but when do it says:

Fatal error: Uncaught LogicException: The module folder "system/modules/NamespaceClassLoader" does not exist. in C:\xampp\htdocs_contao_4\vendor\contao\core-bundle\src\HttpKernel\Bundle\ContaoModuleBundle.php on line 36

And

LogicException: The module folder "system/modules/NamespaceClassLoader" does not exist. in C:\xampp\htdocs_contao_4\vendor\contao\core-bundle\src\HttpKernel\Bundle\ContaoModuleBundle.php on line 36

aschempp commented 7 years ago

I cannot tell you what's wrong, but it sure is a setup of your installation. If you install extensions manually, you have to follow the definition by the extension repository. There is no NamespaceClassLoader extension, it must be named _autoload. Also make sure to delete any folders in var/cache.

PS: it should work fine with Composer as well… did you get a specific error message?

garyee commented 7 years ago

Hi,

I deleted the cache and the error went back to the error message I wrote at first.

...Attempted to load class \"DateRangeFilter\" from namespace \"Haste\\Dca\".\nDid you forget a \"use\" statement for another namespace? at C:\\xampp\\htdocs_contao_4\\vendor\\contao\\core-bundle\\src\\Resources\\contao\\library\\Contao\\System.php:166)"} []

I debuged a little and if I am right, the _autoload is not loaded or at least the NamespaceClassLoader is not used. I do not know if it is loaded thouh.

aschempp commented 7 years ago

You should be able to see the loaded bundes in var/cache/prod/bundles.map. It's a serialized array of the configuration, but there should be a ModuleBundle instance for _autoload if it worked correctly.

garyee commented 7 years ago

Part of the unserialized var_dump of the bundels.map

  ["haste"]=>
  object(Contao\ManagerPlugin\Bundle\Config\BundleConfig)#20 (6) {
    ["Contao\ManagerPlugin\Bundle\Config\BundleConfig"]=>
    string(47) "Contao\ManagerPlugin\Bundle\Config\ModuleConfig"
    [" * name"]=>
    string(5) "haste"
    [" * replace"]=>
    array(0) {
    }
    [" * loadAfter"]=>
    array(1) {
      [0]=>
      string(4) "core"
    }
    [" * loadInProduction"]=>
    bool(true)
    [" * loadInDevelopment"]=>
    bool(true)
  }
  ["_autoload"]=>
  object(Contao\ManagerPlugin\Bundle\Config\BundleConfig)#21 (6) {
    ["Contao\ManagerPlugin\Bundle\Config\BundleConfig"]=>
    string(47) "Contao\ManagerPlugin\Bundle\Config\ModuleConfig"
    [" * name"]=>
    string(9) "_autoload"
    [" * replace"]=>
    array(0) {
    }
    [" * loadAfter"]=>
    array(1) {
      [0]=>
      string(4) "core"
    }
    [" * loadInProduction"]=>
    bool(true)
    [" * loadInDevelopment"]=>
    bool(true)
  }

so it seems that _autoload is loaded. The problem is that the Haste\Dca\DateRangeFilter Class does not get loaded... So I debuged a little, and I found out that the autoload.php of haste ist executed before the autoload of _autoload. So the NamespaceClassLoader Class does not exist when it should... So maybe the problem is in the order in which the bundles are loaded?

garyee commented 7 years ago

So I tried something... I added sort(files) in line 243 in \vendor\contao\core-bundle\src\Resources\contao\library\Contao\ClassLoader.php Because I do not know how to modifiy the loding order of the bundels. And it worked!

So either it change how contao loads the legacy exentsions, to recreate <4 behavoir, or "tell" symfony to load _autoload before haste... Please do not get me wrong... it would good if you could fix it. :)

aschempp commented 7 years ago

So apparently Haste never correctly defined it's autoload dependencies. Should be fixed in 3a710f566d4a521f9a82c4e0eb22a4f34fa85ba6, please try to patch that file and see if it works then.