-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
Replaced hard coded "new" object creation with Magento friendly way #993
Replaced hard coded "new" object creation with Magento friendly way #993
Conversation
Please use @deprecated only for classes, which are intended to get removed completely, not as a workaround to mark direct instanciation. Also for reviewers: check usage is only changed, where magento is already loaded, there are probably uses where this will fail now, because magento is not loaded yet. |
So I remove the @deprecated word? |
yes, please :) |
…allowing other modules to rewrite these objects.
I removed the 3 |
I dont sse problems with changes inside |
Thanks for the PR! Can you explain the use case for this in more detail? Also, did you consider that you can override any class file by dropping classes with the same name into My thinking is that the |
We have created a module that uses Amazon S3 as primary media storage without using the media dir on the disk. Other modules have S3 or other storage options too, but in our case the media dir is completely empty. To build this, we had to dig deep in Maganto and found these models to be not easily rewriteable. You’re right about the include path etc, but I would prefer Magento to load models in the same way, as Magento tells us to do. Why the ‘new’ keyword is used at all seams to break Magento’s own rules without valid reason. So I can understand your workaround, but my thinking was to have an easy and clean solution that does not need any workarounds. I’d even endeavor to remove all uses of ‘new’ as much as possible. Let devs rewrite any and all I understand Varien is a lib, but Magento always extends lib files and then uses these, while also loading them the Magento way. Some examples here are the Zend_Db classes. These (and others) are all wrapped in ‘Mage_’ classes. So hope you like this PR. There is always an alternative, but my goal is following best practises even when Magento forgot their own rules. |
Thanks for the additional detail. You make a good case and I think I am more convinced than before so no objections. As an aside, any chance your S3 module will be open-source? :) |
The S3 module actually needs more core edits, but it's very hard for me to post them here and get everyone to agree on them. So, let's first try to get this one in... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the changes to lib/Varien required if you use your added wrapper classes?
This kind of change has a significant risk of introducing some side effects. Can you describe implementation details of your change? |
app/code/core/Mage/Catalog/Model/Api2/Product/Image/Rest/Admin/V1.php
Outdated
Show resolved
Hide resolved
app/code/core/Mage/Adminhtml/Model/System/Config/Backend/File.php
Outdated
Show resolved
Hide resolved
app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php
Outdated
Show resolved
Hide resolved
app/code/core/Mage/Catalog/Model/Category/Attribute/Backend/Image.php
Outdated
Show resolved
Hide resolved
3b893da
@luigifab I fixed these few nit-picks |
I love how @luigifab is our syntax police (I really do, that's not sarcastic) :-) |
We should use PHP CS Fixer for these nit-picks. Devs really have better things to do imo. |
From what I understand this PR comes as a proposal to solve a particular situation encountered in Magento. At first glance, the changes are made correctly, but what are the implications in the wrong sense? If this PR will be merged I would change the phrase bellow is by removing the comma:
|
I agree with @sreichel that it's very weird to see Mage:: in "lib/", is it absolutely necessary for some reason? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this:
echo get_class(new Varien_Io_File()),"\n";
echo get_class(Mage::getModel('Varien_Io_File')),"\n";
echo get_class(Mage::getModel('varien/io_file')),"\n";
Results are:
Varien_Io_File
Varien_Io_File
Varien_Io_File
So, Mage_Core_Model_Varien_File_Uploader
+ Mage_Core_Model_Varien_Image
+ Mage_Core_Model_Varien_Io_File
are not necessary?
I wouldn't have this in v20 only, it will create too many merging problems. Also, there are conflicts to be fixed, I'm setting it to draft. |
@@ -30,6 +30,8 @@ | |||
* ATTENTION! This class must be used like abstract class and must added | |||
* validation by protected file extension list to extended class | |||
* | |||
* Instead of creating instances using "new", use Mage::getModel('core/varien_file_uploader') | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Mage::getModel('core/varien_file_uploader') instead of creating instances with "new"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway files in "lib/" should never have references to "Mage::" as Sven pointed out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only wanted to correct a few sentences, This PR has some important issues that need to be discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep for sure, if we merge luigifab PR (which is similar) I'll take this one further but I without the "lib/" part ;-)
@@ -26,6 +26,7 @@ | |||
|
|||
/** | |||
* Image handler library | |||
* Instead of creating instances using "new", use Mage::getModel('core/varien_image') | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Mage::getModel('core/varien_image') instead of creating instances with "new"
@@ -27,6 +27,7 @@ | |||
|
|||
/** | |||
* Filesystem client | |||
* Instead of creating instances using "new", use Mage::getModel('core/varien_io_file') | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Mage::getModel('core/varien_io_file') instead of creating instances with "new"
Replaced hard coded "new" object creation with Magento friendly way, allowing other modules to rewrite these objects.