PackedDownloadController
extends AdminHttpViewController
in package
Class PackedDownloadController
This class implements a mass downloader. It can be used to have the shop retrieve a list of resources (denoted by their URLs) and pack them in a ZIP file. The ZIP file is stored in the cache folder and can then be downloaded.
Tags
Table of Contents
- $assets : AssetCollectionInterface
- $contentView : ContentViewInterface
- $httpContextReader : HttpContextReaderInterface
- $httpResponseProcessor : HttpResponseProcessorInterface
- $postDataArray : array<string|int, mixed>
- $queryParametersArray : array<string|int, mixed>
- $serverDataArray : array<string|int, mixed>
- __construct() : mixed
- initializes the controller
- actionDefault() : HttpControllerResponseInterface
- Default action method.
- actionDownloadByJson() : JsonHttpControllerResponse
- Retrieves a number of resources and puts them in a ZIP for later retrieval by the user.
- actionDownloadPackage() : HttpControllerResponse
- Download a pack of resources retrieved with actionDownloadByJson() identified by a downloadKey
- defaultAction() : JsonHttpControllerResponse
- Returns an error (JSON-encoded) as this controller does not have a default action
- proceed() : mixed
- Processes a http response object which is get by invoking an action method.
- validateCurrentAdminStatus() : mixed
- Makes sure that the admin status is currently given in session
- _callActionMethod() : HttpControllerResponseInterface
- Invokes an action method by the given action name.
- _getPostData() : string|null
- Returns the expected $_POST value by the given key name.
- _getPostDataCollection() : KeyValueCollection
- Creates and returns a key value collection which represent the global $_POST array.
- _getQueryParameter() : mixed|null
- Returns the expected $_GET value by the given key name.
- _getQueryParametersCollection() : KeyValueCollection
- Creates and returns a key value collection which represent the global $_GET array.
- _getServerData() : string|null
- Returns the expected $_SERVER value by the given key name.
- _render() : string
- Renders and returns a template file.
- _validatePageToken() : mixed
- Check if the $_POST['pageToken'] or $_GET['pageToken'] variable is provided and if it's valid.
- cleanUp() : bool
- Clean up $tmpDir
- downloadFile() : string
- Retrieve a file/resource and store in $tmpDir File name is determined from URL.
- getTemplateFile() : ExistingFile
- Searches the GXModules directory and admin/html directory for a template file, wich can be useed inside the AdminLayoutHttpControllerResponse object for the template parameter.
- isValidJson() : bool
- isValidRequestMethod() : bool
- makeTmpDir() : string
- Makes a new tmpDir location
- packForDownload() : downloadKey
- Packs up files in $tmpDir into a ZIP file
- prepareJsonInput() : array<string|int, mixed>
Properties
$assets
protected
AssetCollectionInterface
$assets
$contentView
protected
ContentViewInterface
$contentView
$httpContextReader
protected
HttpContextReaderInterface
$httpContextReader
$httpResponseProcessor
protected
HttpResponseProcessorInterface
$httpResponseProcessor
$postDataArray
protected
array<string|int, mixed>
$postDataArray
$queryParametersArray
protected
array<string|int, mixed>
$queryParametersArray
$serverDataArray
protected
array<string|int, mixed>
$serverDataArray
Methods
__construct()
initializes the controller
public
__construct(HttpContextReaderInterface $httpContextReader, HttpResponseProcessorInterface $httpResponseProcessor, ContentViewInterface $contentView) : mixed
Parameters
- $httpContextReader : HttpContextReaderInterface
- $httpResponseProcessor : HttpResponseProcessorInterface
- $contentView : ContentViewInterface
Return values
mixed —actionDefault()
Default action method.
public
actionDefault() : HttpControllerResponseInterface
Every controller child class requires at least the default action method, which is invoked when the ::_getQueryParameterData('do') value is not separated by a trailing slash.
Every action method have to return an instance which implements the http controller response interface.
Return values
HttpControllerResponseInterface —actionDownloadByJson()
Retrieves a number of resources and puts them in a ZIP for later retrieval by the user.
public
actionDownloadByJson() : JsonHttpControllerResponse
Input is a JSON-encoded list (array) of URLs. Response is a JSON object with a downloadKey property (cf. actionDownloadPackage()) or an error message.
Return values
JsonHttpControllerResponse —actionDownloadPackage()
Download a pack of resources retrieved with actionDownloadByJson() identified by a downloadKey
public
actionDownloadPackage() : HttpControllerResponse
Return values
HttpControllerResponse —(empty; download is initiated prior to standard response handling)
defaultAction()
Returns an error (JSON-encoded) as this controller does not have a default action
public
defaultAction() : JsonHttpControllerResponse
Return values
JsonHttpControllerResponse —proceed()
Processes a http response object which is get by invoking an action method.
public
proceed(HttpContextInterface $httpContext) : mixed
The action method is determined by the http context reader instance and the current request context. Re-implement this method in child classes to enable XSS and CSRF protection on demand.
Parameters
- $httpContext : HttpContextInterface
-
Http context object which hold the request variables.
Tags
Return values
mixed —validateCurrentAdminStatus()
Makes sure that the admin status is currently given in session
public
validateCurrentAdminStatus() : mixed
Tags
Return values
mixed —_callActionMethod()
Invokes an action method by the given action name.
protected
_callActionMethod(string $actionName) : HttpControllerResponseInterface
Parameters
- $actionName : string
-
Name of action method to call, without 'action'-Suffix.
Tags
Return values
HttpControllerResponseInterface —Response message.
_getPostData()
Returns the expected $_POST value by the given key name.
protected
_getPostData(string $keyName) : string|null
This method is the object oriented layer for $_POST[$keyName].
Parameters
- $keyName : string
-
Expected key of post parameter.
Return values
string|null —Either the expected value or null, of not found.
_getPostDataCollection()
Creates and returns a key value collection which represent the global $_POST array.
protected
_getPostDataCollection() : KeyValueCollection
Return values
KeyValueCollection —_getQueryParameter()
Returns the expected $_GET value by the given key name.
protected
_getQueryParameter(string $keyName) : mixed|null
This method is the object oriented layer for $_GET[$keyName].
Parameters
- $keyName : string
-
Expected key of query parameter.
Return values
mixed|null —Either the expected value or null, of not found.
_getQueryParametersCollection()
Creates and returns a key value collection which represent the global $_GET array.
protected
_getQueryParametersCollection() : KeyValueCollection
Return values
KeyValueCollection —_getServerData()
Returns the expected $_SERVER value by the given key name.
protected
_getServerData(string $keyName) : string|null
This method is the object oriented layer for $_SERVER[$keyName].
Parameters
- $keyName : string
-
Expected key of server parameter.
Return values
string|null —Either the expected value or null, of not found.
_render()
Renders and returns a template file.
protected
_render(string $templateFile, array<string|int, mixed> $contentArray) : string
Parameters
- $templateFile : string
-
Template file to render.
- $contentArray : array<string|int, mixed>
-
Content array which represent the variables of the template.
Return values
string —Rendered template.
_validatePageToken()
Check if the $_POST['pageToken'] or $_GET['pageToken'] variable is provided and if it's valid.
protected
_validatePageToken([string $customExceptionMessage = null ]) : mixed
Example: public function proceed(HttpContextInterface $httpContext) { parent::proceed($httpContext); // proceed http context from parent class if($_SERVER['REQUEST_METHOD'] === 'POST') { $this->_validatePageToken(); // CSRF Protection } }
Parameters
- $customExceptionMessage : string = null
-
(optional) You can specify a custom exception message.
Tags
Return values
mixed —cleanUp()
Clean up $tmpDir
protected
cleanUp( $tmpDir) : bool
Parameters
Return values
bool —downloadFile()
Retrieve a file/resource and store in $tmpDir File name is determined from URL.
protected
downloadFile(string $url, string $tmpDir) : string
Parameters
- $url : string
- $tmpDir : string
Return values
string —name of retrieved file
getTemplateFile()
Searches the GXModules directory and admin/html directory for a template file, wich can be useed inside the AdminLayoutHttpControllerResponse object for the template parameter.
protected
getTemplateFile(string $templateFile) : ExistingFile
Parameters
- $templateFile : string
-
The relative path and filename to search for
Tags
Return values
ExistingFile —containing absolute file path to the given template file
isValidJson()
protected
isValidJson(string $string) : bool
Parameters
- $string : string
Return values
bool —isValidRequestMethod()
protected
isValidRequestMethod(string $method) : bool
Parameters
- $method : string
Return values
bool —makeTmpDir()
Makes a new tmpDir location
protected
makeTmpDir() : string
Return values
string —full path of tmpDir
packForDownload()
Packs up files in $tmpDir into a ZIP file
protected
packForDownload(mixed $tmpDir, mixed $files) : downloadKey
Parameters
- $tmpDir : mixed
- $files : mixed
Return values
downloadKey —prepareJsonInput()
protected
prepareJsonInput(string $json) : array<string|int, mixed>
Parameters
- $json : string