Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
adds CDN handler to handle videos using a cdn from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
cdowdy committed Jun 28, 2017
1 parent e476316 commit 7230a1d
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/Handler/CDNHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php


namespace Bolt\Extension\cdowdy\html5video\Handler;

use Silex\Application;


class CDNHandler {
/**
* @var
*/
protected $app;

/**
* @var array
*/
protected $_extensionConfig;
protected $_configname;


/**
* CDNHandler constructor.
*
* @param array $_extensionConfig
* @param $configname
* @param Application $app
*/
public function __construct( array $_extensionConfig, $configname, Application $app )
{
$this->_extensionConfig = $_extensionConfig;
$this->_configname = $configname;
$this->app = $app;
}


/**
* @param $filename
*
* @return array
*/
public function cdnFile( $filename )
{

$cdnURL = $this->_extensionConfig['cdn_url'];
$video = [];

if ( $cdnURL ) {

if ( is_array( $filename ) ) {
foreach ( $filename as $key => $value ) {
$pathInfo = pathinfo( $value );
$video += [ $cdnURL . $value => $pathInfo['extension'] ];
}
} else {
$pathInfo = pathinfo( $filename );

$video += [ $cdnURL . $filename => $pathInfo['extension'] ];
}

} else {


if ( is_array( $filename ) ) {
foreach ( $filename as $key => $value ) {
$pathInfo = pathinfo( $value );
$video += [ $value => $pathInfo['extension'] ];
}
} else {
$pathInfo = pathinfo( $filename );

$video += [ $filename => $pathInfo['extension'] ];
}

}


return $video;
}

/**
* @param $url
*
* @return bool
*/
public function checkForActualURL( $url )
{
$configCDNURL = $this->_extensionConfig['cdn_url'];
// no cdn url found in the config so check if the string submitted in the template is an actual URL
$templateURL = parse_url( $url, PHP_URL_HOST );
$errorMessage = "A CDN Url could not be found in the config and a proper url wasn't supplied in the template. The File used in the template is: {$url}";

if ( ! $configCDNURL && ! $templateURL ) {
$this->app['logger.flash']->error( 'HTML5Video:: ' . $errorMessage );

$this->app['logger.system']->error( 'HTML5Video:: ' . $errorMessage, [ 'event' => 'extension' ] );

return false;
}

return true;
}
}

0 comments on commit 7230a1d

Please sign in to comment.