class \mpf\web\request\HTML

class \mpf\web\request\HTML

-no description found-

Attributes
protected mixed $_deleteParams

-no description found-

protected mixed $_putParams

-no description found-

protected string $_preferredLanguage

Records browser preferred language

protected string $currentURL

Records current URL used later to extract all info.

protected string $currentDomain

Records current domain, port and protocol.

protected string $baseURL

Base URL from where link root and web root is determined.

public bool $debug = false

Set this to true to generate debug messages from when it parses current URL. So that you can see what URI was used, what route was selected and what params were found

public string[] $modules = []

List of available modules. Config options for each module can be set here but be careful because they won't apply for already initialized classes except \mpf\WebApp and \mpf\web\request\HTML classes. Example : [ 'admin', 'mobile' => [ 'mpf\WebApp' => [ 'title' => 'Some new Title' ], 'path' => '/full/path/to/model' ] ] Optionally a "path" can be set for each module. In case that the path is set then a new namespace called: \app\modules\moduleName will be added to autoloader with basePath specified here.

public string $defaultModule

Useful when setting a different index file for a different module and don't want the linkroot to have module name in it. To use this update that second index file with this lines just before App run: Config::get()->set('\mpf\web\request\HTML', array( 'defaultModule' => 'moduleName' )); It can also be used to have different modules for access from different browsers( like a mobile module from phones and tables ) so it will have the same url but it will access the mobile module.

public string $defaultController = "home"

Name of the controller to be used when none it's specified;

public bool $SEO = false

If it's set to be SEO then it will generate the url using the templates. If not, it will use basig GET;

public bool $secure = true

If is secured then CSRF token will be generated and checked

protected string $csrfKey = "MPF_CSRF_TOKEN"

Name of the CSRF token key.

public string $csrfSalt = "D$F#$dx32x43"

Used to generate hash for CSRF value

private string $controller

Active controller

public array $urlRoutes = {"0":"(?[a-zA-Z0-9]+)\\\/(?[a-zA-Z0-9_\\-]+)\\\/(?[0-9]+)","(?[a-zA-Z0-9]+)\\\/(?[0-9]+)":{"action":"view"},"1":"(?[a-zA-Z0-9]+)\\\/(?[a-zA-Z0-9_\\-]+)","2":"(?[a-zA-Z0-9]+)"}

List of URL route templates. From here is specified how controller and action can be extracted but also a different parameter if needed. Structure: array( regexp => list of obtained params) Example array('([a-z]{2})/([a-zA-Z0-9]+)' => 'language,controller') Priority will be determined by the order they are entered here.

public string $paramsPairStructure = "{name},{value}"

Must include keywords {name} and {value} in for that it will be used later by the app.

public string $paramsSeparator = "/"

Separator used between pairs of name&value for parameters.

public string $defaultLanguage

Default Site Language;

public array $availableLanguages = ["ro","en","en_us"]

List of available languages;

private string $module

Active module

private string $modulePath

Full path to current module

private string $action

Active action

private string $params

Request parameters

private string $language

User selected language

private string $host

Current host

private static \mpf\web\request\HTML[] $_instances = []

List of instantiated classes

Methods

protected string calculateCurrentURL ()

Calculates current URL and returns it.

protected \mpf\web\request\HTML applyModuleConfig (string $config)

  • $config

    -no description found-

Updates Config class with values from Module config.

protected mixed calculateModulePath ()

Calculates module path to be later used for viewers.

protected mixed updateURLData ()

Calculates controller, action, model and all extra info.

protected mixed _updateURLDataUsingMatches (mixed $matches, mixed $defined)

  • $matches

    -no description found-

  • $defined

    -no description found-

-no description found-

protected mixed _addToParamsFromString (mixed $paramString)

  • $paramString

    -no description found-

-no description found-

protected mixed addValue (mixed $original, mixed $name, mixed $value)

  • $original

    -no description found-

  • $name

    -no description found-

  • $value

    -no description found-

-no description found-

protected mixed init (mixed $options)

  • $options

    -no description found-

-no description found-

public string getHost ()

Get current host

public bool getLanguage ()

Get current language

public void setModulePath (string $path)

  • $path

    -no description found-

Changes path for current module. Is called by WebApp but in some exceptions it can be called by any other class.

public static \mpf\web\request\HTML get (string[] $options = [])

  • $options

    -no description found-

Return an instantiated class of HTML

public string createURL (string $controller, string $action = null, array $params = [], string $module = null, string $language = null)

  • $controller

    Name of the controller where the URL must link

  • $action

    Name of the action where the URL must link

  • $params

    List of associative parameters

  • $module

    Name of the module where the URL must link. If you want to removed current module and go to default use false. If none it's set it will use current module;

  • $language

    Language to use. Must exists in the list of available languages;

Get url to the selected page;

protected mixed _prepareParams (mixed $params)

  • $params

    -no description found-

-no description found-

protected string _createURL (string $base, string $controller, string $action, string $params, bool $searchDefined = true)

  • $base

    -no description found-

  • $controller

    -no description found-

  • $action

    -no description found-

  • $params

    -no description found-

  • $searchDefined

    -no description found-

Create url by checking all routes.

protected string _params2string (mixed $params)

  • $params

    -no description found-

Get query params from array.

public string getAction ()

Get current action name

public mixed setAction (string $name)

  • $name

    -no description found-

Change current action

public string getController ()

Get current controller name

public mixed setController (string $name)

  • $name

    -no description found-

Change current controller

public string getCurrentURL ()

Get full current URL;

public string getModule ()

Get active module name;

public string getModuleNamespace ()

Get current module namespace.

public array getParams ()

Get an associative list of parameters and values;

public null goBack ()

Go back to the last page

public void goToPage (string $controller, string $action = null, string[] $params = [], string $module = null)

  • $controller

    -no description found-

  • $action

    -no description found-

  • $params

    -no description found-

  • $module

    -no description found-

-no description found-

public null goToURL (mixed $url)

  • $url

    -no description found-

Redirect to selected string URL;

public null reloadPage ()

Reload current page

public null simulateURI (mixed $uri)

  • $uri

    -no description found-

Will replace current HTML request with selected URI. This is used by HtmlRequest unit test.

public string[] stripSlashes (string[] $data)

  • $data

    input data to be processed

Strips slashes from input data. This method is applied when magic quotes is enabled.

protected mixed normalizeRequest ()

Normalizes the request data. This method strips off slashes in request data if getmagicquotes_gpc() returns true.

public mixed getLinkRoot ()

-no description found-

public mixed getWebRoot ()

-no description found-

public string getLanguageChangeURL (mixed $lang)

  • $lang

    -no description found-

-no description found-

public mixed getPreferredLanguage ()

-no description found-

public mixed sendFile (mixed $fileName, mixed $content, mixed $mimeType = null, mixed $terminate = true)

  • $fileName

    -no description found-

  • $content

    -no description found-

  • $mimeType

    -no description found-

  • $terminate

    -no description found-

-no description found-

public null xSendFile (string $filePath, array $options = [])

  • $filePath

    file name with full path

  • $options

    additional options:

    • saveName: file name shown to the user, if not set real file name will be used
    • mimeType: mime type of the file, if not set it will be guessed automatically based on the file name, if set to null no content-type header will be sent.
    • xHeader: appropriate x-sendfile header, defaults to "X-Sendfile"
    • terminate: whether to terminate the current application after calling this method, defaults to true
    • forceDownload: specifies whether the file will be downloaded or shown inline, defaults to true. (Since version 1.1.9.)
    • addHeaders: an array of additional http headers in header-value pairs (available since version 1.1.10)

Sends existing file to a browser as a download using x-sendfile.

X-Sendfile is a feature allowing a web application to redirect the request for a file to the webserver that in turn processes the request, this way eliminating the need to perform tasks like reading the file and sending it to the user. When dealing with a lot of files (or very big files) this can lead to a great increase in performance as the web application is allowed to terminate earlier while the webserver is handling the request.

The request is sent to the server through a special non-standard HTTP-header. When the web server encounters the presence of such header it will discard all output and send the file specified by that header using web server internals including all optimizations like caching-headers.

As this header directive is non-standard different directives exists for different web servers applications:

  • Apache: {@link http://tn123.org/mod_xsendfile X-Sendfile}
  • Lighttpd v1.4: {@link http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file X-LIGHTTPD-send-file}
  • Lighttpd v1.5: {@link http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file X-Sendfile}
  • Nginx: {@link http://wiki.nginx.org/XSendfile X-Accel-Redirect}
  • Cherokee: {@link http://www.cherokee-project.com/doc/other_goodies.html#x-sendfile X-Sendfile and X-Accel-Redirect}

So for this method to work the X-SENDFILE option/module should be enabled by the web server and a proper xHeader should be sent.

Note: This option allows to download files that are not under web folders, and even files that are otherwise protected (deny from all) like .htaccess

Side effects: If this option is disabled by the web server, when this method is called a download configuration dialog will open but the downloaded file will have 0 bytes.

Example:

request->xSendFile('/home/user/Pictures/picture1.jpg',array(
       'saveName'=>'image1.jpg',
       'mimeType'=>'image/jpeg',
       'terminate'=>false,
   ));
?>

public bool isAjaxRequest ()

-no description found-

public bool isDeleteRequest ()

-no description found-

public bool isPutRequest ()

-no description found-

public bool isPostRequest ()

-no description found-

public bool isSecureConnection ()

-no description found-

public string getReferrer ()

Get URL referrer. Similar to goBack(), but instead of redirect will return the address;

public mixed getUserAgent ()

-no description found-

protected mixed getRestParams ()

-no description found-

public mixed getDelete (mixed $name, mixed $defaultValue = null)

  • $name

    -no description found-

  • $defaultValue

    -no description found-

-no description found-

public mixed getPut (mixed $name, mixed $defaultValue = null)

  • $name

    -no description found-

  • $defaultValue

    -no description found-

-no description found-

public string getCsrfKey ()

Get csrf token key

public string getCsrfValue ()

Get csrf token value

public string getModulePath ()

Get full path for current module