Example #1
0
    /**
     * Helper method to access some private/protected methods
     * @see lib/ezc/MvcTools/src/interfaces/ezcMvcController::__get()
     */
    public function __get( $name )
    {
        $ret = null;
        switch( $name )
        {
            case 'cacheLocation':
                $ret = $this->getCacheLocation();
            break;

            case 'cacheId':
                $refObj = new ReflectionObject( $this );
                $refMethod = $refObj->getMethod( 'generateCacheId' );
                $refMethod->setAccessible( true );
                $ret = $refMethod->invoke( $this );
            break;

            case 'cacheTTL':
                $ret = $this->getActionTTL();
            break;

            default:
                $ret = parent::__get( $name );
        }

        return $ret;
    }
 public function __construct($action, $request)
 {
     $moduleRepositories = eZModule::activeModuleRepositories();
     eZModule::setGlobalPathList($moduleRepositories);
     parent::__construct($action, $request);
 }
 /**
  * Override to add the "requestedResponseGroups" variable for every REST requests
  *
  * @see lib/ezc/MvcTools/src/interfaces/ezcMvcController::createResult()
  */
 public function createResult()
 {
     $debug = ezpRestDebug::getInstance();
     $debug->startTimer('GeneratingRestResult', 'RestController');
     if (!self::$isCacheCreated) {
         ezcCacheManager::createCache(self::CACHE_ID, $this->getCacheLocation(), 'ezpRestCacheStorageClusterObject', array('ttl' => $this->getActionTTL()));
         self::$isCacheCreated = true;
     }
     $cache = ezcCacheManager::getCache(self::CACHE_ID);
     $controllerCacheId = $this->generateCacheId();
     $isCacheEnabled = $this->isCacheEnabled();
     // Try to restore application cache.
     // If expired or not yet available, generate it and store it
     $cache->isCacheEnabled = $isCacheEnabled;
     if (($res = $cache->restore($controllerCacheId)) === false) {
         try {
             $debug->log('Generating cache', ezcLog::DEBUG);
             $debug->switchTimer('GeneratingCache', 'GeneratingRestResult');
             $res = parent::createResult();
             $resGroups = $this->getResponseGroups();
             if (!empty($resGroups)) {
                 $res->variables['requestedResponseGroups'] = $resGroups;
             }
             if ($res instanceof ezpRestMvcResult) {
                 $res->responseGroups = $resGroups;
             }
             if ($isCacheEnabled) {
                 $cache->store($controllerCacheId, $res);
             }
             $debug->stopTimer('GeneratingCache');
         } catch (Exception $e) {
             $debug->log('Exception caught, aborting cache generation', ezcLog::DEBUG);
             if ($isCacheEnabled) {
                 $cache->abortCacheGeneration();
             }
             throw $e;
         }
     }
     // Add debug infos to output if debug is enabled
     $debug->stopTimer('GeneratingRestResult');
     if (ezpRestDebug::isDebugEnabled()) {
         $res->variables['debug'] = $debug->getReport();
     }
     return $res;
 }