1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169:
<?php
namespace MvcCore\Ext\Routers\Localizations\Route;
trait InternalInits {
public function InitAll () {
$router = $this->router;
$allowedLocalizations = $router->GetAllowedLocalizations();
$routeRecordsByLanguageAndLocale = $router->getRouteRecordsByLanguageAndLocale();
foreach ($allowedLocalizations as $allowedLocalization) {
if ($routeRecordsByLanguageAndLocale) {
$routeLocalization = $allowedLocalization;
} else {
$allowedLocalizationExpl = explode($router::LANG_AND_LOCALE_SEPARATOR, $allowedLocalization);
$routeLocalization = strtolower($allowedLocalizationExpl[0]);
}
$noMatch = $this->match === NULL && !array_key_exists($routeLocalization, $this->matchLocalized);
$noReverse = $this->reverse === NULL && !array_key_exists($routeLocalization, $this->reverseLocalized);
if ($noMatch && $noReverse) {
$this->initMatchAndReverse($routeLocalization);
} else if ($noReverse) {
$this->initReverse($routeLocalization);
}
}
return $this;
}
protected function initMatchAndReverse ($localization = NULL) {
if (array_key_exists($localization, $this->reverseSectionsLocalized)) return;
$pattern = NULL;
$reverse = NULL;
if ($this->pattern !== NULL) {
$pattern = $this->pattern;
} else if (isset($this->patternLocalized[$localization])) {
$pattern = $this->patternLocalized[$localization];
} else {
$this->throwExceptionIfKeyPropertyIsMissing(
'pattern', 'patternLocalized'
);
}
if ($this->reverse !== NULL) {
$reverse = $this->reverse;
} else if (isset($this->reverseLocalized[$localization])) {
$reverse = $this->reverseLocalized[$localization];
}
$this->lastPatternParam = NULL;
$match = addcslashes($pattern, "#(){}-?!=^$.+|:*\\");
$reverse = $reverse !== NULL
? $reverse
: $pattern;
list($reverseSections, $matchSections) = $this->initSectionsInfoForMatchAndReverse(
$reverse, $match
);
$this->reverseSectionsLocalized[$localization] = $reverseSections;
$this->reverseLocalized[$localization] = $reverse;
$constraintsLocalized = $this->GetConstraints($localization);
$reverseParams = $this->initReverseParams(
$reverse, $reverseSections, $constraintsLocalized, $match
);
$this->reverseParamsLocalized[$localization] = $reverseParams;
$this->reverseParams = array_keys($reverseParams);
$this->initFlagsByPatternOrReverse($reverse);
$this->matchLocalized[$localization] = $this->initMatchComposeRegex(
$match, $matchSections, $reverseParams, $constraintsLocalized
);
}
protected function initReverse ($localization = NULL) {
if (array_key_exists($localization, $this->reverseSectionsLocalized)) return;
$reverse = NULL;
if ($this->reverse !== NULL) {
$reverse = $this->reverse;
} else if (isset($this->reverseLocalized[$localization])) {
$reverse = $this->reverseLocalized[$localization];
} else if ($this->pattern !== NULL) {
$reverse = $this->pattern;
} else if (isset($this->patternLocalized[$localization])) {
$reverse = $this->patternLocalized[$localization];
} else {
if ($this->redirect !== NULL) {
$pattern = NULL;
$match = NULL;
if ($this->pattern !== NULL) {
$pattern = $this->pattern;
} else if (isset($this->patternLocalized[$localization])) {
$pattern = $this->patternLocalized[$localization];
}
if ($this->match !== NULL) {
$match = $this->match;
} else if (isset($this->matchLocalized[$localization])) {
$match = $this->matchLocalized[$localization];
}
return $this->initFlagsByPatternOrReverse(
$pattern !== NULL ? $pattern : str_replace(['\\', '(?', ')?', '/?'], '', $match)
);
}
$this->throwExceptionIfKeyPropertyIsMissing(
'reverse', 'reverseLocalized', 'pattern', 'patternLocalized'
);
}
$this->lastPatternParam = NULL;
$reverseSections = $this->initSectionsInfo($reverse);
$this->reverseSectionsLocalized[$localization] = $reverseSections;
$this->reverseLocalized[$localization] = $reverse;
$match = NULL;
$reverseParams = $this->initReverseParams(
$reverse, $reverseSections, $this->GetConstraints($localization), $match
);
$this->reverseParamsLocalized[$localization] = $reverseParams;
$this->reverseParams = array_keys($reverseParams);
$this->initFlagsByPatternOrReverse($reverse);
}
}