magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.52k stars 9.31k forks source link

Implementation of Composition Instead of Inhertance in Controllers Magento 2 #34748

Open TheRealHunzik opened 2 years ago

TheRealHunzik commented 2 years ago

Summary (*)

I am trying to implement Magneto 2 Coding Standard so I found an Article Here -> https://community.magento.com/t5/Magento-DevBlog/Decomposition-of-Magento-Controllers/ba-p/430883

I have changed my frontend And backend Controllers in the same way

Examples (*)

Frontend Controller:


use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\RedirectFactory;

class HomeRedirect implements HttpGetActionInterface
{
    private RedirectFactory $redirectFactory;

    /**
     * @param RedirectFactory $redirectFactory
     */
    public function __construct(
        RedirectFactory $redirectFactory
    ) {
        $this->redirectFactory = $redirectFactory;
    }

    /**
     * Check is Allowed
     * @return bool
     */
    protected function _isAllowed()
    {
        return true;
    }

    public function execute()
    {
        $this->redirectFactory->create()->setPath('dashboard');
    }
}

, in the same way, I am have implemented an admin controller


use Magento\Backend\Model\View\Result\Forward;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Backend\Model\View\Result\ForwardFactory;

class NewAction implements HttpGetActionInterface
{
    private ForwardFactory $forwardFactory;

    /**
     * @param ForwardFactory $forwardFactory
     */
    public function __construct(
        ForwardFactory $forwardFactory
    ) {
        $this->forwardFactory = $forwardFactory;
    }

    /**
     * @return Forward
     */
    public function execute()
    {
        return $this->forwardFactory->create()->forward('edit');
    }
}

is this the right way to do so

Proposed solution

anyone, please suggest to me any Module in which the composition is implemented on controllers properly, My concern is that, is there any security issue if I implement this of Backend Controllers


Please provide Severity assessment for the Issue as a Reporter. This information will help during the Confirmation and Issue triage processes.

m2-assistant[bot] commented 2 years ago

Hi @TheRealHunzik. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

ihor-sviziev commented 2 years ago

@lbajsarowicz, maybe you can explain? :)

TheRealHunzik commented 2 years ago

@lbajsarowicz can you please help us to understand?

lbajsarowicz commented 2 years ago

We never had enough time and resources to finish decomposition for Admin Panel. That is why it does not work for Admin

m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 2 years ago

Hi @TheRealHunzik,

Thank you for reporting the issue.

Hope you got the answer to your question. I think you can wait until it is implemented or Documented in Magento.

As of now since there is no action required from our side, we are closing this issue. You can re-open this issue or raise a new one if you still need assistance on this. Similar questions can be raised on various Magento Forums like Magento Community(https://community.magento.com/) or Magento Stack Exchange(https://magento.stackexchange.com/) also.

Thanks

markshust commented 2 years ago

@lbajsarowicz I think the "deprecated" flags should be removed from the admin controller parent classes, since they aren't really deprecated (there is no alternative, and I don't think there are plans for any moving forward at this time).

ihor-sviziev commented 2 years ago

I think it's better to mark this issue as a feature request rather than just close it. What do you think?

markshust commented 2 years ago

@ihor-sviziev if you'd like to build in the ability for backend controllers to be created using composition, yes 👍

markshust commented 2 years ago

@ihor-sviziev I just noticed this issue is still closed, it should have been re-opened as a feature request?