Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

router.php
Go to the documentation of this file.
1 <?php
11 class ezpRestRouter extends ezcMvcRouter
12 {
13 const ROUTE_CACHE_ID = 'ezpRestRouteApcCache',
14 ROUTE_CACHE_KEY = 'ezpRestRouteApcCacheKey',
15 ROUTE_CACHE_PATH = 'restRouteAPC';
16
21 public static $isRouteCacheCreated = false;
22
27 public function createRoutes()
28 {
29 if( empty( $this->routes ) )
30 {
31 // Check if route caching is enabled and if APC is available
32 $isRouteCacheEnabled = eZINI::instance( 'rest.ini' )->variable( 'CacheSettings', 'RouteApcCache' ) === 'enabled';
33 if( $isRouteCacheEnabled && ezcBaseFeatures::hasExtensionSupport( 'apc' ) )
34 {
35 $this->routes = $this->getCachedRoutes();
36 }
37 else
38 {
39 $this->routes = $this->doCreateRoutes();
40 }
41 }
42
43 return $this->routes;
44 }
45
50 protected function doCreateRoutes()
51 {
52 $providerRoutes = ezpRestProvider::getProvider( ezpRestPrefixFilterInterface::getApiProviderName() )->getRoutes();
53 $providerRoutes['fatal'] = new ezpMvcRailsRoute( '/fatal', 'ezpRestErrorController', 'show' );
54
55 return ezcMvcRouter::prefix(
56 eZINI::instance( 'rest.ini' )->variable( 'System', 'ApiPrefix' ),
57 $providerRoutes
58 );
59 }
60
66 protected function getCachedRoutes()
67 {
68 $ttl = (int)eZINI::instance( 'rest.ini' )->variable( 'CacheSettings', 'RouteApcCacheTTL' );
69
70 if( self::$isRouteCacheCreated === false )
71 {
72 $options = array( 'ttl' => $ttl );
73 ezcCacheManager::createCache( self::ROUTE_CACHE_ID, self::ROUTE_CACHE_PATH, 'ezpRestCacheStorageApcCluster', $options );
74 self::$isRouteCacheCreated = true;
75 }
76
77 $cache = ezcCacheManager::getCache( self::ROUTE_CACHE_ID );
78 $cacheKey = self::ROUTE_CACHE_KEY . '_' . ezpRestPrefixFilterInterface::getApiProviderName();
79 if( ( $prefixedRoutes = $cache->restore( $cacheKey ) ) === false )
80 {
81 try
82 {
83 $prefixedRoutes = $this->doCreateRoutes();
84 $cache->store( $cacheKey, $prefixedRoutes );
85 }
86 catch( Exception $e )
87 {
88 // Sometimes APC can miss a write. No big deal, just log it.
89 // Cache will be regenerated next time
90 ezpRestDebug::getInstance()->log( $e->getMessage(), ezcLog::ERROR );
91 }
92 }
93
94 return $prefixedRoutes;
95 }
96 }
97 ?>
ezpMvcRailsRoute
Definition: rails.php:12
ezpRestDebug\getInstance
static getInstance()
Definition: debug.php:50
ezpRestPrefixFilterInterface\getApiProviderName
static getApiProviderName()
Definition: prefix_filter.php:98
ezpRestProvider\getProvider
static getProvider( $provider)
Definition: rest_provider.php:47
ezpRestRouter
Definition: router.php:12
ezpRestRouter\$isRouteCacheCreated
static $isRouteCacheCreated
Definition: router.php:21
ezpRestRouter\createRoutes
createRoutes()
Definition: router.php:27
ezpRestRouter\ROUTE_CACHE_ID
const ROUTE_CACHE_ID
Definition: router.php:13
ezpRestRouter\ROUTE_CACHE_PATH
const ROUTE_CACHE_PATH
Definition: router.php:15
ezpRestRouter\doCreateRoutes
doCreateRoutes()
Definition: router.php:50
ezpRestRouter\ROUTE_CACHE_KEY
const ROUTE_CACHE_KEY
Definition: router.php:14
ezpRestRouter\getCachedRoutes
getCachedRoutes()
Definition: router.php:66
$options
$options
Definition: optionlist.php:56
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.