0

I tried overriding the core classes but this one doesnt seem to work. I know I will need to update the application/config/app.php file to point to the new class. But when I do this the HTML redender stops at head tag.

I extended the Request Class from core to application/src, updated the app.php file, but it doest work and gives me a blank page. I will need this to use redirect url.

pritywiz
  • 109
  • 3

2 Answers2

0

if your goal is to do something to the request before sending it back you might want to use a middleware instead of overriding the class.

A good example is the Centry portal package which you can find here: https://github.com/a3020/centry

Have a look at centry\Provider\CentryServiceProvider.php function registerMiddleware() to see how to register a middleware. And then look at the 2 files in centry\Http\Middleware to see how it's used.

Nour Akalay
  • 429
  • 3
  • 4
0

If you are using version 8 you will need to autoload your classes in the src folder.

In application/bootstrap/autoload.php

$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
$classLoader->addPrefix('Application\\Example', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Example');

From here you will need to override the associated service provider. It's not entirely clear which class you are trying to override and which service provider this would require. Below is an example for overriding the \Concrete\Core\Http\HttpServiceProvider with class placed in application/Src/Example/HttpServiceProvider

return [
   'providers' => [
    'core_http' => 'Application\Example\HttpServiceProvider'
   ]
]

From the service provider you can extend classes and override the returned classes in a way the suits your use case scenario (It can be tedious if multiple classes have references but it's the only way I'm aware of to properly override core classes). Typically you can just extend existing classes overriding a single method or two and come up with an elegant solution.

John Everden
  • 176
  • 8