-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Zend feed refactoring #9347
Zend feed refactoring #9347
Conversation
@ldusan84 I think this is a great start! I would love to see it migrated over to https://github.com/zendframework/zend-feed but I understand with going with the bare minimum to start with. |
@dmanners thanks, yes, that would be the next step and I would like to do that after this one. |
return $this->feedFactory->create(['feed' => $feed]); | ||
} catch (\Zend_Feed_Exception $e) { | ||
throw new \Magento\Framework\Exception\FeedImporterException( | ||
new \Magento\Framework\Phrase($e->getMessage()), |
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.
Should just use __($e->getMessage)
. It's the same thing, but shorter.
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.
Nice one, makes sense, thanks 👍
There is an error on Travis CI - "The command "phpenv global 7.1" failed and exited with 1 during .", anything I can do about it? |
@ldusan84 Looks like it was some temporary error with the Travis CI. I've restarted the job in question and its green now. |
app/code/Magento/Rss/Model/Rss.php
Outdated
* @param SerializerInterface|null $serializer | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\CacheInterface $cache, | ||
\Magento\Framework\App\FeedImporterInterface $feedImporter, |
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.
That's backward incompatible, new parameter should be added last into the list, and that parameter should be optional. You can read more about it here - http://devdocs.magento.com/guides/v2.1/ext-best-practices/extension-coding/backwards-compatible-development/index.html "Adding a constructor parameter" section
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.
Makes sense, it's fixed now.
@@ -34,6 +34,27 @@ class RssTest extends \PHPUnit_Framework_TestCase | |||
]; | |||
|
|||
/** | |||
* @var string | |||
*/ | |||
protected $feedXml = '<?xml version="1.0" encoding="UTF-8"?> |
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.
better to make variable as private
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.
Agreed, fixed.
return $this->feedFactory->create(['feed' => $feed]); | ||
} catch (\Zend_Feed_Exception $e) { | ||
throw new \Magento\Framework\Exception\FeedImporterException( | ||
__($e->getMessage()), |
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.
it's not correct to translate low level exception providing its output to translation function.
Because there is no guarantee that the phrase would be translated .
All you need to do - is to log initial exception.
And provide new description which says about the problem in general words
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.
This is done, can you please check?
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\Exception; |
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.
don't think that we need to introduce new exception type. It's better to re-use some of the existing ones.
Or at least to introduce new exception for ImportException
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.
If you look at the Zend_Feed module Zend_Feed_Exception can be thrown for a lot of things. The only common exception for all those cases would be RuntimeException, so I picked that one. Let me know what you think.
* @param string $format | ||
* @return FeedInterface | ||
*/ | ||
public function importArray(array $data, $format = 'atom'); |
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.
it's not good from interface point of view, that 'atom' passed as a default parameter.
What other formats does this Importer support?
It's not clear from the interface.
And not clear how to check this out.
Interface should be clear enough to get this knowledge
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 see your point but I did it because I wanted to replicate the original importArray method from Zend_Feed which has those arguments. What would be the best thing to do in this case?
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.
It's not always a good Idea to replicate contracts from Zend. Because sometimes we would provide a wider contract than Zend does, and sometimes their contracts are not so ideal.
Above I described my idea what we can do with this
interface FeedImporterInterface | ||
{ | ||
|
||
/** |
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.
please provide a precise description what this method is actually do
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.
Done.
*/ | ||
namespace Magento\Framework\App; | ||
|
||
interface FeedImporterInterface |
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.
maybe make sense to rename this interface to
FeedFactoryInterface ?
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 am not sure about this, why do you think that it should be renamed to factory, it doesn't create new objects?
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.
Looks like it creates. Description from the importArray method says:
Get a new \Magento\Framework\App\Feed object from a custom array
and implementation looks like:
$feed = $this->feedProcessor->importArray($data, $format);
return $this->feedFactory->create(['feed' => $feed]);
for now it's not clear why it's called importer? From where it imports data?
Looking at the interface and implementation I see FeedFactory which accepts array of data and format
For me it's not clear why we need to keep both objects
\Magento\Framework\App\Feed\Importer
and
FeedFactory
Because both of them responsible for \Magento\Framework\App\FeedInterface creation.
I propose to get rid of \Magento\Framework\App\Feed\Importer and move it's logic to FeedFactory.
Thus, FeedFactoryInterface would look like:
class FeedFactoryInterface
{
public function importArray(array $data, $format = SupportedFeedFormatsInterface::DEFAULT_FORMAT)
}
hey @ldusan84 , sorry for late response. |
Hi @maghamed no problem, thanks for the feedback. I'll look into the stuff you mentioned. |
Hi @maghamed I made some changes and posted comments to your feedback. Let me know what you think please. |
@ishakhsuvarov @maghamed @dmanners any news on this one guys? |
@maksek can your team check? |
@ldusan84 @benmarks We are looking into this PR. Review takes somewhat more time then usual, since it introduces updates to the API, which must be in ideal desired-state if updated. We attempt to design APIs which would not require and additional changes in foreseeable future. Thank you for your patience. |
*/ | ||
namespace Magento\Framework\App; | ||
|
||
interface FeedImporterInterface |
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.
Looks like it creates. Description from the importArray method says:
Get a new \Magento\Framework\App\Feed object from a custom array
and implementation looks like:
$feed = $this->feedProcessor->importArray($data, $format);
return $this->feedFactory->create(['feed' => $feed]);
for now it's not clear why it's called importer? From where it imports data?
Looking at the interface and implementation I see FeedFactory which accepts array of data and format
For me it's not clear why we need to keep both objects
\Magento\Framework\App\Feed\Importer
and
FeedFactory
Because both of them responsible for \Magento\Framework\App\FeedInterface creation.
I propose to get rid of \Magento\Framework\App\Feed\Importer and move it's logic to FeedFactory.
Thus, FeedFactoryInterface would look like:
class FeedFactoryInterface
{
public function importArray(array $data, $format = SupportedFeedFormatsInterface::DEFAULT_FORMAT)
}
/** | ||
* @return string | ||
*/ | ||
public function asXml(); |
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 prefer to see this method as
public function getFormatedContentAs($format = SupportedFeedFormatsInterface::DEFAULT_FORMAT);
Naming could be changed, but main idea is to make FeedInteface agnostic to the possible representation formats.
Because we no need to have coupling between Data and different ways how these data could be presented.
Thus, all that we need to have is kind of "output" method which accepts a format in which data should be presented. And we need to have a dedicated interface/entity responsible for format registration.
I mentioned SupportedFeedFormatsInterface
here
* @param string $format | ||
* @return FeedInterface | ||
*/ | ||
public function importArray(array $data, $format = 'atom'); |
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.
It's not always a good Idea to replicate contracts from Zend. Because sometimes we would provide a wider contract than Zend does, and sometimes their contracts are not so ideal.
Above I described my idea what we can do with this
hey @ldusan84 do you have some time to make requested changes for current PR? |
Hi @maghamed yes sure, I would like to, sorry I read your comments but didn't have time to respond these days. |
Cool, thanks! Take your time |
Hi, Currently ZF1 zend feed usage was replaced with ZF 2 Zend\Feed in magento-engcom/php-7.2-support#89 and we have conflicts in this PR. |
Hi @ldusan84 Please do not change or modify the code in your branch till merge. |
Hi @ldusan84. Thank you for your contribution. |
Refactoring in order to move hardcoded Zend_Feed dependency into interface for further refactoring. Ticket #9240
Description
I have created an interface that replaces Zend_Feed::importArray static call. The concrete class takes Zend_Feed object and returns it's own result that's a wrapper around Zend_Feed_Abstract.
I am not sure what the policies are on this type of things so I just went with the bare minimum of what is required.
Would appreciate hearing your thoughts on this one.