This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow usage of Reader without GooglePlayPodcast extension
Custom implementations of `ExtensionManagerInterface` may not have _new core_ extensions present. As a result, when upgrading, an exception is thrown due to inability to load the new extension. This was discovered with the 2.10 release, when we added a new core extension, GooglePlayPodcast; see #80 and https://www.drupal.org/project/drupal/issues/2976335 for more details. As such, we now check for _new_ core extensions before registering them. When we discover they are not in the extension manager, we emit an `E_USER_NOTICE` indicating the user should update their `ExtensionManagerInterface` implementation to add entries for the new extension, but then continue on without registering the extension. This ensures no exception is thrown.
- Loading branch information
1 parent
875414e
commit 2c09572
Showing
3 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-feed for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Feed\Reader\TestAsset; | ||
|
||
use Zend\Feed\Reader\Exception\InvalidArgumentException; | ||
use Zend\Feed\Reader\Extension; | ||
use Zend\Feed\Reader\ExtensionManagerInterface; | ||
|
||
/** | ||
* Standalone extension manager that omits any extensions added after the 2.9 series. | ||
*/ | ||
class CustomExtensionManager implements ExtensionManagerInterface | ||
{ | ||
private $extensions = [ | ||
'Atom\Entry' => Extension\Atom\Entry::class, | ||
'Atom\Feed' => Extension\Atom\Feed::class, | ||
'Content\Entry' => Extension\Content\Entry::class, | ||
'CreativeCommons\Entry' => Extension\CreativeCommons\Entry::class, | ||
'CreativeCommons\Feed' => Extension\CreativeCommons\Feed::class, | ||
'DublinCore\Entry' => Extension\DublinCore\Entry::class, | ||
'DublinCore\Feed' => Extension\DublinCore\Feed::class, | ||
'Podcast\Entry' => Extension\Podcast\Entry::class, | ||
'Podcast\Feed' => Extension\Podcast\Feed::class, | ||
'Slash\Entry' => Extension\Slash\Entry::class, | ||
'Syndication\Feed' => Extension\Syndication\Feed::class, | ||
'Thread\Entry' => Extension\Thread\Entry::class, | ||
'WellFormedWeb\Entry' => Extension\WellFormedWeb\Entry::class, | ||
]; | ||
|
||
/** | ||
* Do we have the extension? | ||
* | ||
* @param string $extension | ||
* @return bool | ||
*/ | ||
public function has($extension) | ||
{ | ||
return array_key_exists($extension, $this->extensions); | ||
} | ||
|
||
/** | ||
* Retrieve the extension | ||
* | ||
* @param string $extension | ||
* @return Extension\AbstractEntry|Extension\AbstractFeed | ||
*/ | ||
public function get($extension) | ||
{ | ||
$class = $this->extensions[$extension]; | ||
return new $class(); | ||
} | ||
|
||
/** | ||
* Add an extension. | ||
* | ||
* @param string $name | ||
* @param string $class | ||
*/ | ||
public function add($name, $class) | ||
{ | ||
if (is_string($class) | ||
&& ( | ||
is_a($class, Extension\AbstractEntry::class, true) | ||
|| is_a($class, Extension\AbstractFeed::class, true) | ||
) | ||
) { | ||
$this->extensions[$name] = $class; | ||
return; | ||
} | ||
|
||
throw new InvalidArgumentException(sprintf( | ||
'Plugin of type %s is invalid; must implement %2$s\Extension\AbstractFeed ' | ||
. 'or %2$s\Extension\AbstractEntry', | ||
$class, | ||
'Zend\Feed\Reader' | ||
)); | ||
} | ||
|
||
/** | ||
* Remove an extension. | ||
* | ||
* @param string $name | ||
*/ | ||
public function remove($name) | ||
{ | ||
unset($this->extensions[$name]); | ||
} | ||
} |