Exemple #1
0
 /**
  * Initializes router and prepares routing table.
  * @return void
  */
 protected static function init()
 {
     if (static::$initialized) {
         return;
     }
     static::$managedCache = Application::getInstance()->getManagedCache();
     if (static::$managedCache->read(static::CACHE_TTL, static::CACHE_ID)) {
         static::$routeTable = (array) static::$managedCache->get(static::CACHE_ID);
     } else {
         $queryResult = RouteTable::getList(array('select' => array('*')));
         while ($routeRecord = $queryResult->fetch()) {
             $routeRecord['REGEXP'] = static::convertRouteToRegexp($routeRecord['ROUTE']);
             static::$routeTable[$routeRecord['ROUTE']] = $routeRecord;
         }
         uksort(static::$routeTable, function ($a, $b) {
             $lengthOfA = strlen($a);
             $lengthOfB = strlen($b);
             if ($lengthOfA > $lengthOfB) {
                 return -1;
             } else {
                 if ($lengthOfA == $lengthOfB) {
                     return 0;
                 } else {
                     return 1;
                 }
             }
         });
         static::$managedCache->set(static::CACHE_ID, static::$routeTable);
     }
     static::$initialized = true;
 }
Exemple #2
0
 public function _Finalize()
 {
     \Bitrix\Main\Data\ManagedCache::finalize();
 }