Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
UrlRewrite Class Reference
Inheritance diagram for UrlRewrite:
AbstractHelper

Public Member Functions

 validateRequestPath ($requestPath)
 
 validateSuffix ($suffix)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const VERR_MANYSLASHES = 1
 
const VERR_ANCHOR = 2
 

Protected Member Functions

 _validateRequestPath ($requestPath)
 
- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Additional Inherited Members

- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Definition at line 8 of file UrlRewrite.php.

Member Function Documentation

◆ _validateRequestPath()

_validateRequestPath (   $requestPath)
protected

Core func to validate request path If something is wrong with a path it throws localized error message and error code, that can be checked to by wrapper func to alternate error message

Parameters
string$requestPath
Returns
bool
Exceptions

Definition at line 29 of file UrlRewrite.php.

30  {
31  if (strpos($requestPath, '//') !== false) {
32  throw new \Exception(
33  __('Do not use two or more consecutive slashes in the request path.'),
34  self::VERR_MANYSLASHES
35  );
36  }
37  if (strpos($requestPath, '#') !== false) {
38  throw new \Exception(__('Anchor symbol (#) is not supported in request path.'), self::VERR_ANCHOR);
39  }
40  return true;
41  }
__()
Definition: __.php:13

◆ validateRequestPath()

validateRequestPath (   $requestPath)

Validates request path Either returns TRUE (success) or throws error (validation failed)

Parameters
string$requestPath
Exceptions

Definition at line 51 of file UrlRewrite.php.

52  {
53  try {
54  $this->_validateRequestPath($requestPath);
55  } catch (\Exception $e) {
56  throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
57  }
58  return true;
59  }
__()
Definition: __.php:13

◆ validateSuffix()

validateSuffix (   $suffix)

Validates suffix for url rewrites to inform user about errors in it Either returns TRUE (success) or throws error (validation failed)

Parameters
string$suffix
Exceptions

Definition at line 69 of file UrlRewrite.php.

70  {
71  try {
72  // Suffix itself must be a valid request path
74  } catch (\Exception $e) {
75  // Make message saying about suffix, not request path
76  switch ($e->getCode()) {
78  throw new \Magento\Framework\Exception\LocalizedException(
79  __('Do not use two or more consecutive slashes in the url rewrite suffix.')
80  );
81  case self::VERR_ANCHOR:
82  throw new \Magento\Framework\Exception\LocalizedException(
83  __('Anchor symbol (#) is not supported in url rewrite suffix.')
84  );
85  }
86  }
87  return true;
88  }
$suffix
Definition: name.phtml:27
__()
Definition: __.php:13

Field Documentation

◆ VERR_ANCHOR

const VERR_ANCHOR = 2

Definition at line 16 of file UrlRewrite.php.

◆ VERR_MANYSLASHES

const VERR_MANYSLASHES = 1

Validation error constants

Definition at line 13 of file UrlRewrite.php.


The documentation for this class was generated from the following file: