From 233cd14ee9f1e42c3bbcef3bd1ec4e7c7ae3f7d2 Mon Sep 17 00:00:00 2001 From: Nick Freear Date: Fri, 26 Jun 2015 16:57:31 +0100 Subject: [PATCH] Bug #3/#5, PSR-2 fix - split `Oembed_Provider.php` up [iet:3633574] * Plus, edits to `SubClasses` class --- src/Oembed_Provider.php | 62 +++---------------- src/SubClasses/SubClasses.php | 39 +++++++----- src/providers/External_Oembed_Provider.php | 17 +++++ .../Generic_Iframe_Oembed_Provider.php | 34 ++++++++++ 4 files changed, 84 insertions(+), 68 deletions(-) create mode 100644 src/providers/External_Oembed_Provider.php create mode 100644 src/providers/Generic_Iframe_Oembed_Provider.php diff --git a/src/Oembed_Provider.php b/src/Oembed_Provider.php index d98673d..b17ae9e 100644 --- a/src/Oembed_Provider.php +++ b/src/Oembed_Provider.php @@ -10,18 +10,14 @@ use \IET_OU\Open_Media_Player\Base; use \IET_OU\SubClasses\PluginInterface; -interface iService +/*interface iService { - - /** call. - * @return object Return a $meta meta-data object, as inserted in DB. - */ public function call($url, $regex_matches); -} +}*/ /** Was: Base_service */ -abstract class Oembed_Provider extends Base implements iService, PluginInterface +abstract class Oembed_Provider extends Base implements PluginInterface { public $regex = ''; # array(); public $about = ''; # Human @@ -75,6 +71,13 @@ public function __construct() } } + + /** call. + * @return object Return a $meta meta-data object, as inserted in DB. + */ + abstract public function call($url, $regex_matches); + + /** Called by SubClasses. */ public function registerPlugin(array & $class_array) @@ -234,48 +237,3 @@ protected function _embedly_oembed_url($url) return "http://api.embed.ly/1/oembed?format=json&url=$url&key=".$this->_embedly_api_key(); } } - -/** - * Extend the base class for a generic IFRAME oEmbed provider. - */ -abstract class Generic_Iframe_Oembed_Provider extends Oembed_Provider -{ - - public function getView() - { - return 'oembed/_generic_iframe'; - } - - protected function getIframeResponse($url) - { - return (object) array( - '_comment' => '/*TODO: work-in-progress! */', - 'original_url' => $url, - #'is_iframe' => TRUE, - #'view_name' => $this->getView(), - 'class_name' => $this->name, - 'provider_name' => $this->displayname, - 'provider_url' => $this->_about_url, - 'provider_icon' => $this->favicon, - 'type' => $this->type, #rich - 'title'=> null, - 'width' => '100%', #640, #720, - 'height'=> 400, #$height, - 'embed_url'=> null, - ); - } -} - -/** - * - */ -abstract class External_Oembed_Provider extends Oembed_Provider -{ - - #protected $_endpoint_url; # oEmbed endpoint for 'external' providers, eg. iSpot. - - public function call($url, $matches) - { - $this->_error('sorry the endpoint is: '. $this->_endpoint_url, 400.9); - } -} diff --git a/src/SubClasses/SubClasses.php b/src/SubClasses/SubClasses.php index 05aa6a7..68942c5 100644 --- a/src/SubClasses/SubClasses.php +++ b/src/SubClasses/SubClasses.php @@ -23,7 +23,7 @@ class SubClasses extends OffsetIterator const PLUGIN_INTERFACE = '\\IET_OU\\SubClasses\\PluginInterface'; const REGISTER_FN = 'registerPlugin'; - public static $verbose = true; //false; + public static $verbose = false; protected $classes = array(); protected static $skip_me = array('\\Wikimedia\\Composer\\MergePlugin', '\\Nfreear\\Composer\\Suggest'); @@ -48,13 +48,23 @@ public function match($base_class, $callback = true, $use_constructor = false) foreach ($this->classes as $class) { if (is_subclass_of($class, $base_class)) { if ($callback) { - if ($use_constructor) { - $obj = new $class (); - } else { - $reflect = new \ReflectionClass($class); - $obj = $reflect->newInstanceWithoutConstructor(); + try { + if ($use_constructor) { + $obj = new $class (); + } else { + $reflect = new \ReflectionClass($class); + if ($reflect->isInstantiable()) { + $obj = $reflect->newInstanceWithoutConstructor(); + } + } + if ($obj) { + $obj->{ self::REGISTER_FN }($results); + } + } catch (\ReflectionException $e) { + $this->debug('Warning! (RF) '. $e->getMessage()); + } catch (\Exception $e) { + $this->debug('Warning! '. $e->getMessage()); } - $obj->{ self::REGISTER_FN }($results); //Was: $results[ $class::{ $callback }() ] = $class; } else { $results[] = $class; @@ -86,7 +96,6 @@ protected function getPsr4Paths() $path = __DIR__ .'/../../vendor/composer/autoload_psr4.php'; $psr4 = require $path; } - //$flat_paths = call_user_func_array('array_merge', $psr4); return $psr4; } @@ -97,7 +106,6 @@ protected function discoverClasses() foreach ($psr4_paths as $namespace => $paths) { //$glob = sprintf('{%s/*.php}', implode('/*.php,', $paths)); // Not on Windows! - //$glob = $paths[ 0 ] .'/*.php'; foreach ($paths as $file_path) { $glob = $file_path .'/*.php'; $this->debug('Glob: '. $glob); @@ -113,23 +121,22 @@ protected function discoverClasses() } $this->debug($class, $path); - try { - if (class_exists($class) && is_subclass_of($class, self::PLUGIN_INTERFACE)) + if (class_exists($class) + && is_subclass_of($class, self::PLUGIN_INTERFACE)) { /*$reflect = new \ReflectionClass($class); if ($reflect->implementsInterface(self::PLUGIN_INTERFACE) - && $reflect->isInstantiable())*/ { - $this->classes[] = $class; //ltrim($class, '\\'); + && $reflect->isInstantiable()) {*/ + $this->classes[] = $class; } - } catch(ErrorException $e) { - $this->debug('XX Warning! '. $e->getMessage()); } catch (\Exception $e) { $this->debug('Warning! '. $e->getMessage()); } } } } - $this->debug('OK, discovered classes: '. count($this->classes)); + $count = count($this->classes); + $this->debug('OK, discovered classes: '. $count, $this->classes); } protected function debug($message) diff --git a/src/providers/External_Oembed_Provider.php b/src/providers/External_Oembed_Provider.php new file mode 100644 index 0000000..29ee7b8 --- /dev/null +++ b/src/providers/External_Oembed_Provider.php @@ -0,0 +1,17 @@ +_error('sorry the endpoint is: '. $this->_endpoint_url, 400.9); + } +} diff --git a/src/providers/Generic_Iframe_Oembed_Provider.php b/src/providers/Generic_Iframe_Oembed_Provider.php new file mode 100644 index 0000000..6e3846d --- /dev/null +++ b/src/providers/Generic_Iframe_Oembed_Provider.php @@ -0,0 +1,34 @@ + '/*TODO: work-in-progress! */', + 'original_url' => $url, + #'is_iframe' => TRUE, + #'view_name' => $this->getView(), + 'class_name' => $this->name, + 'provider_name' => $this->displayname, + 'provider_url' => $this->_about_url, + 'provider_icon' => $this->favicon, + 'type' => $this->type, #rich + 'title'=> null, + 'width' => '100%', #640, #720, + 'height'=> 400, #$height, + 'embed_url'=> null, + ); + } +}