Upgrading to v8

Permalink
I'm currently attempting to upgrade to v8 from 5.7.5.13
I have a custom helper that extends the date helper, but currently receiving the following error message

Class 'Application\Src\Localization\Service\ContextualDate' not found


This is the line from the app.php

Core::bind('helper/date', function() {
    return new \Application\Src\Localization\Service\ContextualDate();
});


Path and namespace details from the ContextualDate file
//Path /application/src/Localization/Service/ContextualDate.php
namespace Application\Src\Localization\Service;
class ContextualDate extends Date {...}


Can anyone see the issue?

TheRealSean
 
Gondwana replied on at Permalink Best Answer Reply
Gondwana
It could be the changed default autoloading behaviour in 8. Consider
https://documentation.concrete5.org/developers/extending-concrete5-w...
TheRealSean replied on at Permalink Reply
TheRealSean
Interesting, thanks for the link. I'll investigate
TheRealSean replied on at Permalink Reply
TheRealSean
So there are two options for resolving this the first is the quickest.

add the following line to the array in application/config/app.php
'enable_legacy_src_namespace' => true


The other is to refactor the extension to suit the new autoload version
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
$classLoader->addPrefix('Application\\Localization\\Service', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Localization/Service');
$classLoader->register();


The class would also need its namespace amended (but not the path)
namespace Application\Localization\Service;
TheRealSean replied on at Permalink Reply
TheRealSean
'enable_legacy_src_namespace' => true

update this now appears to break newer functionality in the latest 8.4 version.

I've managed to run into the same issue again this time trying to autoload a file from a package, whilst attempting to add a new framework.

It suggests something is up with the autoloader of the site but I'm stumped :shrug:
kenchi09 replied on at Permalink Reply
kenchi09
Did your "refactoring" solution work for you in 8.4?