Custom Class / Extending Object?
Permalink
What's the proper 5.7 way to go about defining a custom class?
The examples in app.php show only how to override a built-in core class. For instance, if I want a Car class, where would the class file go so that it auto loads? Do I need to register it somehow in app.php?
Thanks for any pointers,
-Steve
The examples in app.php show only how to override a built-in core class. For instance, if I want a Car class, where would the class file go so that it auto loads? Do I need to register it somehow in app.php?
Thanks for any pointers,
-Steve
It almost seems that something like...
...should be added to...
concrete/core/Foundation/ClassLoader.php
...at around line 83, no? Or am I missing something?
-Steve
$symfonyLoader->addPrefix(NAMESPACE_SEGMENT_APPLICATION . '\\Core', DIR_APPLICATION . '/' . DIRNAME_CLASSES);
...should be added to...
concrete/core/Foundation/ClassLoader.php
...at around line 83, no? Or am I missing something?
-Steve
Unless I'm misunderstanding something (which could well be the case), it seems to me that the class loader should be modified as per this pull request...
https://github.com/concrete5/concrete5-5.7.0/pull/166...
If I'm off base here, please ignore the PR and point me in the right direction.
Thanks,
-Steve
https://github.com/concrete5/concrete5-5.7.0/pull/166...
If I'm off base here, please ignore the PR and point me in the right direction.
Thanks,
-Steve
I have no clue what the answer is, but I sure do hope there is a way to override specific methods of core classes in 5.7 (like we have in 5.6). One of the videos Andrew posted for 5.7 said that he's doing away with the "core" directory... but I hope we're not throwing away the baby with the bathwater here, because being able to override specific methods of core classes is a very useful feature.
> I have no clue what the answer is, but I sure do hope there is a
> way to override specific methods of core classes in 5.7...
Jordan,
It turns out the pull request I referenced was accepted, and it fixed the override issue. Overriding in 5.7 is actually easier than in 5.6. See app.php in the config directory for examples in the comments.
-Steve
> way to override specific methods of core classes in 5.7...
Jordan,
It turns out the pull request I referenced was accepted, and it fixed the override issue. Overriding in 5.7 is actually easier than in 5.6. See app.php in the config directory for examples in the comments.
-Steve
Actually, I think I spoke too soon! I see what you're saying, Jordan. It's unclear to me, for instance, how one would simply override a method of the Page class (which is what I'm trying to do right now).
Creating a custom class based on a core class and using it in your own code is straightforward, but simply overriding/extending a core class (so that the rest of the core uses your implementation) is not. It seems the best (and proper) solution would be to fully exploit IoC and dependency injection throughout the core code -- i.e. using Core::bind() and Core::make() -- but that would entail some major refactoring.
Or am I missing something? Can anyone provide any insights or assistance?
Thanks,
-Steve
Creating a custom class based on a core class and using it in your own code is straightforward, but simply overriding/extending a core class (so that the rest of the core uses your implementation) is not. It seems the best (and proper) solution would be to fully exploit IoC and dependency injection throughout the core code -- i.e. using Core::bind() and Core::make() -- but that would entail some major refactoring.
Or am I missing something? Can anyone provide any insights or assistance?
Thanks,
-Steve
Anyone got any insights?
-Steve