diff --git a/actions/ConnectivityAction.php b/actions/ConnectivityAction.php index 9a78d167..ac86fa1b 100644 --- a/actions/ConnectivityAction.php +++ b/actions/ConnectivityAction.php @@ -24,8 +24,6 @@ */ class ConnectivityAction implements ActionInterface { - public $userData = []; - private BridgeFactory $bridgeFactory; public function __construct() @@ -33,18 +31,18 @@ class ConnectivityAction implements ActionInterface $this->bridgeFactory = new \BridgeFactory(); } - public function execute() + public function execute(array $request) { if (!Debug::isEnabled()) { returnError('This action is only available in debug mode!', 400); } - if (!isset($this->userData['bridge'])) { + if (!isset($request['bridge'])) { $this->returnEntryPage(); return; } - $bridgeName = $this->userData['bridge']; + $bridgeName = $request['bridge']; $bridgeClassName = $this->bridgeFactory->sanitizeBridgeName($bridgeName); diff --git a/actions/DetectAction.php b/actions/DetectAction.php index dc6cdc61..1ed002af 100644 --- a/actions/DetectAction.php +++ b/actions/DetectAction.php @@ -14,14 +14,12 @@ class DetectAction implements ActionInterface { - public $userData = []; - - public function execute() + public function execute(array $request) { - $targetURL = $this->userData['url'] + $targetURL = $request['url'] or returnClientError('You must specify a url!'); - $format = $this->userData['format'] + $format = $request['format'] or returnClientError('You must specify a format!'); $bridgeFactory = new \BridgeFactory(); diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index b345bddc..d8baf016 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -14,19 +14,20 @@ class DisplayAction implements ActionInterface { - public $userData = []; - - public function execute() + public function execute(array $request) { $bridgeFactory = new \BridgeFactory(); - $bridgeClassName = isset($this->userData['bridge']) ? $bridgeFactory->sanitizeBridgeName($this->userData['bridge']) : null; + $bridgeClassName = null; + if (isset($request['bridge'])) { + $bridgeClassName = $bridgeFactory->sanitizeBridgeName($request['bridge']); + } if ($bridgeClassName === null) { throw new \InvalidArgumentException('Bridge name invalid!'); } - $format = $this->userData['format'] + $format = $request['format'] or returnClientError('You must specify a format!'); // whitelist control @@ -39,8 +40,8 @@ class DisplayAction implements ActionInterface $bridge = $bridgeFactory->create($bridgeClassName); $bridge->loadConfiguration(); - $noproxy = array_key_exists('_noproxy', $this->userData) - && filter_var($this->userData['_noproxy'], FILTER_VALIDATE_BOOLEAN); + $noproxy = array_key_exists('_noproxy', $request) + && filter_var($request['_noproxy'], FILTER_VALIDATE_BOOLEAN); if (defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy) { define('NOPROXY', true); @@ -48,22 +49,22 @@ class DisplayAction implements ActionInterface // Cache timeout $cache_timeout = -1; - if (array_key_exists('_cache_timeout', $this->userData)) { + if (array_key_exists('_cache_timeout', $request)) { if (!CUSTOM_CACHE_TIMEOUT) { - unset($this->userData['_cache_timeout']); - $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($this->userData); + unset($request['_cache_timeout']); + $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) . '?' . http_build_query($request); header('Location: ' . $uri, true, 301); exit; } - $cache_timeout = filter_var($this->userData['_cache_timeout'], FILTER_VALIDATE_INT); + $cache_timeout = filter_var($request['_cache_timeout'], FILTER_VALIDATE_INT); } else { $cache_timeout = $bridge->getCacheTimeout(); } // Remove parameters that don't concern bridges $bridge_params = array_diff_key( - $this->userData, + $request, array_fill_keys( [ 'action', @@ -79,7 +80,7 @@ class DisplayAction implements ActionInterface // Remove parameters that don't concern caches $cache_params = array_diff_key( - $this->userData, + $request, array_fill_keys( [ 'action', @@ -162,19 +163,19 @@ class DisplayAction implements ActionInterface $item = new \FeedItem(); // Create "new" error message every 24 hours - $this->userData['_error_time'] = urlencode((int)(time() / 86400)); + $request['_error_time'] = urlencode((int)(time() / 86400)); $message = sprintf( 'Bridge returned error %s! (%s)', $e->getCode(), - $this->userData['_error_time'] + $request['_error_time'] ); $item->setTitle($message); $item->setURI( (isset($_SERVER['REQUEST_URI']) ? parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) : '') . '?' - . http_build_query($this->userData) + . http_build_query($request) ); $item->setTimestamp(time()); diff --git a/actions/ListAction.php b/actions/ListAction.php index 58a79ce5..5076b6dc 100644 --- a/actions/ListAction.php +++ b/actions/ListAction.php @@ -14,7 +14,7 @@ class ListAction implements ActionInterface { - public function execute() + public function execute(array $request) { $list = new StdClass(); $list->bridges = []; diff --git a/index.php b/index.php index 39e970c5..9eddc71b 100644 --- a/index.php +++ b/index.php @@ -8,18 +8,18 @@ rss-bridge from the command line */ if (isset($argv)) { parse_str(implode('&', array_slice($argv, 1)), $cliArgs); - $params = array_merge($_GET, $cliArgs); + $request = array_merge($_GET, $cliArgs); } else { - $params = $_GET; + $request = $_GET; } try { $actionFactory = new ActionFactory(); - if (array_key_exists('action', $params)) { - $action = $actionFactory->create($params['action']); - $action->userData = $params; - $action->execute(); + if (array_key_exists('action', $request)) { + $action = $actionFactory->create($request['action']); + + $action->execute($request); } else { $showInactive = filter_input(INPUT_GET, 'show_inactive', FILTER_VALIDATE_BOOLEAN); echo BridgeList::create($showInactive); diff --git a/lib/ActionInterface.php b/lib/ActionInterface.php index 78284ab4..ea5020a3 100644 --- a/lib/ActionInterface.php +++ b/lib/ActionInterface.php @@ -24,5 +24,5 @@ interface ActionInterface * * @return void */ - public function execute(); + public function execute(array $request); } diff --git a/tests/Actions/ListActionTest.php b/tests/Actions/ListActionTest.php index 5056050e..f3d06db6 100644 --- a/tests/Actions/ListActionTest.php +++ b/tests/Actions/ListActionTest.php @@ -85,7 +85,7 @@ class ListActionTest extends TestCase $action = $actionFactory->create('list'); ob_start(); - $action->execute(); + $action->execute([]); $this->data = ob_get_contents(); ob_clean(); ob_end_flush();