Skip to content
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

Add getParams and setParams to Magento\Framework\App\RequestInterface #865

Closed
ashsmith opened this issue Dec 23, 2014 · 8 comments
Closed

Comments

@ashsmith
Copy link

I have noticed in multiple places that getParams() is expected to be set on the request object, despite the interface not requiring the getParams() method. My understanding is that we're using DI and specifying the Interface, it means we shouldn't rely on methods not in the implementation interface.

Adding getParams() to Magento\Framework\App\RequestInterface seems like the right thing to do, and is a common method used by not only the core of Magento, but by extension developers too. I wouldn't feel comfortable using this method knowing that I can't rely on it existence.

More than happy to fork, and submit a pull request but it requires a fair bit of work - so before I commit to that I'd want approval :)

By searching for $this->getRequest()->getParams() I was able to find 20 occurrences, 18 of which happen with app/code/Magento/*. This is just for controllers, I'm sure there are instances in helpers and models where getParams from the request interface is used.

Thanks,
Ash Smith

@antonmakarenko
Copy link

Makes sense.

I believe this interface is meant to be an abstraction layer to Zend_Controller_Request_Abstract (which doesn't happen to have an interface). It has the getParams() and a setParam() methods -- I'd recommend to add both, because they are used in the client code and because there are similar counterparts in this interface (getModuleName()/setModuleName(), getActionName()/setActionName())

@benmarks
Copy link
Contributor

👍

@kandy
Copy link
Contributor

kandy commented Dec 24, 2014

I believe that is no reason to add a method to interface when it used in some places, because it contradicts the Interface segregation principle.

Better to define dependencies on real interfaces and never use method not from interface. So better to define new interface Magento\Framework\Request with getParameter and extend Magento\Framework\App\RequestInterface from this.

Also I propose to split interfaces on mutable and readonly part. For example PSR proposal for http message do not have setters for parameters.

@punkstar
Copy link
Contributor

@ashsmith 👍

@kandy 👍 for specialised interfaces. IMO the getParams() method would be a sensible addition to base request interface as it would be useful for absolutely every implementation of a request. Any interface that has a getParam($name) should have a getParams(), so that I may discover available parameters if I don't know a $name.

@vpelipenko
Copy link
Contributor

Internal ticket: MAGETWO-32340

@TexanHogman
Copy link

@ashsmith After a review of your proposal a pull request would be accepted. Having getParams() missing is a mistake causing us to go around the defined interface. Thanks for the suggestion and your help is appreciated.
Let's limit scope to adding these two methods to the interface and address implementation classes. While I agree with @kandy on splitting interface across get and sets I am concerned to the amount of change this will create with a PR so let's hold off on that change.

@ashsmith
Copy link
Author

ashsmith commented Feb 7, 2015

@TexanHogman good stuff, I'll submit the PR tomorrow then! :)

vpelipenko pushed a commit to vpelipenko/magento2 that referenced this issue Mar 5, 2015
…erface magento#865 magento#1053

Merge branch '865-add-getParams-setParams-to-request-interface' of git://github.com/ashsmith/magento2 into ashsmith-865-add-getParams-setParams-to-request-interface

Conflicts:
	dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/SaveTest.php
	dev/tests/unit/testsuite/Magento/Checkout/Helper/CartTest.php
	dev/tests/unit/testsuite/Magento/Checkout/Model/Type/OnepageTest.php
	dev/tests/unit/testsuite/Magento/Customer/Controller/Account/CreateTest.php
	dev/tests/unit/testsuite/Magento/Customer/Controller/Account/LoginPostTest.php
	dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/IndexTest.php
	dev/tests/unit/testsuite/Magento/Customer/Controller/Ajax/LoginTest.php
	dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/FileTest.php
	dev/tests/unit/testsuite/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/LinkTest.php
	dev/tests/unit/testsuite/Magento/Downloadable/Controller/Adminhtml/Downloadable/Product/Edit/SampleTest.php
	dev/tests/unit/testsuite/Magento/Downloadable/Controller/Download/LinkTest.php
	dev/tests/unit/testsuite/Magento/Framework/App/Action/ActionTest.php
	dev/tests/unit/testsuite/Magento/Framework/App/Router/NoRouteHandlerTest.php
	dev/tests/unit/testsuite/Magento/Framework/Controller/Result/ForwardTest.php
	dev/tests/unit/testsuite/Magento/Framework/UrlTest.php
vpelipenko pushed a commit to vpelipenko/magento2 that referenced this issue Mar 5, 2015
…erface magento#865 magento#1053

- Remove RequestInterface::getParam from obsolete_methods since it still exists
- Move getCookie to PhpEnvironment\Request
@vpelipenko
Copy link
Contributor

Closed. PR is merged.

mmansoor-magento pushed a commit that referenced this issue Feb 24, 2017
fe-lix- pushed a commit to fe-lix-/magento2 that referenced this issue Apr 29, 2018
MSI-836: Merchant should see the salable qty for product in single source mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants