Skip to content

Commit

Permalink
Bug #3/#5, PSR-2 fix - split Oembed_Provider.php up [iet:3633574]
Browse files Browse the repository at this point in the history
* Plus, edits to `SubClasses` class
  • Loading branch information
nfreear committed Jun 26, 2015
1 parent a3fcf72 commit 233cd14
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 68 deletions.
62 changes: 10 additions & 52 deletions src/Oembed_Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
39 changes: 23 additions & 16 deletions src/SubClasses/SubClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/providers/External_Oembed_Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php namespace IET_OU\Open_Media_Player;

/**
*
*/
use \IET_OU\Open_Media_Player\Oembed_Provider;

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);
}
}
34 changes: 34 additions & 0 deletions src/providers/Generic_Iframe_Oembed_Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php namespace IET_OU\Open_Media_Player;

/**
* Extend the base class for a generic IFRAME oEmbed provider.
*/
use \IET_OU\Open_Media_Player\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,
);
}
}

0 comments on commit 233cd14

Please sign in to comment.