Don't use global variables
This commit is contained in:
parent
cf805740fe
commit
3074595b51
2 changed files with 19 additions and 24 deletions
|
@ -33,10 +33,11 @@ use Slim\Http\Response;
|
||||||
* */
|
* */
|
||||||
class FrontController
|
class FrontController
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct($container)
|
||||||
{
|
{
|
||||||
$this->config = Config::getInstance();
|
$this->config = Config::getInstance();
|
||||||
$this->download = new VideoDownload();
|
$this->download = new VideoDownload();
|
||||||
|
$this->container = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,8 +50,7 @@ class FrontController
|
||||||
*/
|
*/
|
||||||
public function index(Request $request, Response $response)
|
public function index(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
global $container;
|
$this->container->view->render(
|
||||||
$container->view->render(
|
|
||||||
$response,
|
$response,
|
||||||
'head.tpl',
|
'head.tpl',
|
||||||
array(
|
array(
|
||||||
|
@ -58,18 +58,18 @@ class FrontController
|
||||||
'description'=>'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.'
|
'description'=>'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'header.tpl'
|
'header.tpl'
|
||||||
);
|
);
|
||||||
$container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'index.tpl',
|
'index.tpl',
|
||||||
array(
|
array(
|
||||||
'convert'=>$this->config->convert
|
'convert'=>$this->config->convert
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render($response, 'footer.tpl');
|
$this->container->view->render($response, 'footer.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,8 +82,7 @@ class FrontController
|
||||||
*/
|
*/
|
||||||
public function extractors(Request $request, Response $response)
|
public function extractors(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
global $container;
|
$this->container->view->render(
|
||||||
$container->view->render(
|
|
||||||
$response,
|
$response,
|
||||||
'head.tpl',
|
'head.tpl',
|
||||||
array(
|
array(
|
||||||
|
@ -93,16 +92,16 @@ class FrontController
|
||||||
=>'List of all supported websites from which Alltube Download can extract video or audio files'
|
=>'List of all supported websites from which Alltube Download can extract video or audio files'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render($response, 'header.tpl');
|
$this->container->view->render($response, 'header.tpl');
|
||||||
$container->view->render($response, 'logo.tpl');
|
$this->container->view->render($response, 'logo.tpl');
|
||||||
$container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'extractors.tpl',
|
'extractors.tpl',
|
||||||
array(
|
array(
|
||||||
'extractors'=>$this->download->listExtractors()
|
'extractors'=>$this->download->listExtractors()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render($response, 'footer.tpl');
|
$this->container->view->render($response, 'footer.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +114,6 @@ class FrontController
|
||||||
*/
|
*/
|
||||||
public function video(Request $request, Response $response)
|
public function video(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
global $container;
|
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
$this->config = Config::getInstance();
|
$this->config = Config::getInstance();
|
||||||
if (isset($params["url"])) {
|
if (isset($params["url"])) {
|
||||||
|
@ -218,7 +216,7 @@ class FrontController
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$video = $this->download->getJSON($params["url"]);
|
$video = $this->download->getJSON($params["url"]);
|
||||||
$container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'head.tpl',
|
'head.tpl',
|
||||||
array(
|
array(
|
||||||
|
@ -227,24 +225,23 @@ class FrontController
|
||||||
'description'=>'Download "'.$video->title.'" from '.$video->extractor_key
|
'description'=>'Download "'.$video->title.'" from '.$video->extractor_key
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'video.tpl',
|
'video.tpl',
|
||||||
array(
|
array(
|
||||||
'video'=>$video
|
'video'=>$video
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render($response, 'footer.tpl');
|
$this->container->view->render($response, 'footer.tpl');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return $response->withRedirect($container->get('router')->pathFor('index'));
|
return $response->withRedirect($this->container->get('router')->pathFor('index'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function error(Request $request, Response $response, \Exception $exception)
|
public function error(Request $request, Response $response, \Exception $exception)
|
||||||
{
|
{
|
||||||
global $container;
|
$this->container->view->render(
|
||||||
$container->view->render(
|
|
||||||
$response,
|
$response,
|
||||||
'head.tpl',
|
'head.tpl',
|
||||||
array(
|
array(
|
||||||
|
@ -252,14 +249,14 @@ class FrontController
|
||||||
'title'=>'Error'
|
'title'=>'Error'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render(
|
$this->container->view->render(
|
||||||
$response,
|
$response,
|
||||||
'error.tpl',
|
'error.tpl',
|
||||||
array(
|
array(
|
||||||
'errors'=>$exception->getMessage()
|
'errors'=>$exception->getMessage()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$container->view->render($response, 'footer.tpl');
|
$this->container->view->render($response, 'footer.tpl');
|
||||||
return $response->withStatus(500);
|
return $response->withStatus(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +270,6 @@ class FrontController
|
||||||
*/
|
*/
|
||||||
public function redirect(Request $request, Response $response)
|
public function redirect(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
global $app;
|
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
if (isset($params["url"])) {
|
if (isset($params["url"])) {
|
||||||
try {
|
try {
|
||||||
|
@ -296,7 +292,6 @@ class FrontController
|
||||||
*/
|
*/
|
||||||
public function json(Request $request, Response $response)
|
public function json(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
global $app;
|
|
||||||
$params = $request->getQueryParams();
|
$params = $request->getQueryParams();
|
||||||
if (isset($params["url"])) {
|
if (isset($params["url"])) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -28,7 +28,7 @@ $container['view'] = function ($c) {
|
||||||
return $view;
|
return $view;
|
||||||
};
|
};
|
||||||
|
|
||||||
$controller = new FrontController();
|
$controller = new FrontController($container);
|
||||||
|
|
||||||
$container['errorHandler'] = array($controller, 'error');
|
$container['errorHandler'] = array($controller, 'error');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue