-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use class_alias
instead of DynamicParent
class and autoload with psr-0
#15
Comments
Now I wonder how I did not stumble upon class_alias before, it is amazing :D I will implement your changes :) |
I reacted the same way. When I followed an outdated example on StackOverflow for working with SMTP in WordPress, I found this simple function, that changes everything. WordPress uses this technique to throw a deprection notice for a renamed vendor namespace. It feels like a hack - and it probably is one. So don't over-use it, when there are better alternatives. But extending Parsedown 1.x, feels like the perfect match. |
You missed one point:
|
And you can replace lines like $Block = ParsedownTocParentAlias::blockHeader($Line); with $Block = parent::blockHeader($Line); |
wait why did I not thing about that... that make so much sense |
I found a cleaner solution to dynamically load Parsedown or ParsedownExtra as parent:
class_alias
.Here is my implementation in action:
https://codeberg.org/raffaelj/parsedown-tasks/src/branch/main/ParsedownTasks.php#L6-L14
This removes one problem of multiple classes named
DynamicParent
in the global scope, when trying to mix multiple Parsedown addons, that use that same technique.If you want to implement it, make sure to check for
is_callable('parent::__construct')
in your constructor to fix the missing constructor inParsedown
.And while I'm here - instead of opening another issue - it's better to autoload with
psr-0
instead of withfiles
. The difference is, that autoloading withfiles
always includes the file, whenrequire(__DIR__.'/vendor/autoload.php');
is called. Autoloading withpsr-0
only includes the file when the class is in use, e. g.$test = new Test();
. This is a huge performance improvement when dealing with many classes.Thanks again for your work and have a nice day,
Raffael
The text was updated successfully, but these errors were encountered: