Closed tbcorr closed 9 years ago
I've given this a lot of thought and I don't think the benefits are enough to warrant the additional complexity. I'd like to keep this theme as light (in terms of technical complexity) as possible.
I can see a lot of use for leveraging name spacing and auto-loading in plugins and I'll probably come back and review your notes above when next doing this for a plugin but I don't want to add them to this theme.
This is what we were talking about earlier.
So our composer file looks like the following.
So what is cool about this is that as long as we conform to the PSR-4 standard for class / namespace naming we get autoloading for free without having to setup class maps or anything. However our class names are camel case ie: "TextWidget" not the preferred WordPress standard of "Text_Widget". We ran into problems with the underscores. There may be a way to fix this though and still conform to PSR-4. Probably should make this work with WP standards.
Why not PSR-0? PSR-0 has been deprecated. http://www.php-fig.org/psr/psr-0/
Another potential issue is that namespaces are not supported below PHP 5.3.0 and WP requirements only state PHP 5.2.4.
Currently the all classes in the theme fall under the LDM namespace. From there we break it down into sub namespaces like "LDM\Widget" or "LDM\Utils" which matches the folder structure of lib/Widget/TextWidget.php.
This may be overkill unless the theme utilizes a lot of classes in which case it could pay off. You could probably have all classes under one namespace...