Changeset 2416

Show
Ignore:
Timestamp:
03/30/08 14:10:18 (10 months ago)
Author:
david
Message:

change if to remove indent/braces, refs #742

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/src/filter/AgaviExecutionFilter.class.php

    r2414 r2416  
    320320    $container->clearNext(); 
    321321 
    322     if($actionCache['view_name'] !== AgaviView::NONE) { 
    323  
    324       $container->setViewModuleName($actionCache['view_module']); 
    325       $container->setViewName($actionCache['view_name']); 
    326  
     322    if($actionCache['view_name'] === AgaviView::NONE) { 
     323      return; 
     324    } 
     325 
     326    $container->setViewModuleName($actionCache['view_module']); 
     327    $container->setViewName($actionCache['view_name']); 
     328 
     329    $key = $request->toggleLock(); 
     330    // get the view instance 
     331    $viewInstance = $controller->createViewInstance($actionCache['view_module'], $actionCache['view_name']); 
     332    // initialize the view 
     333    $viewInstance->initialize($container); 
     334    $request->toggleLock($key); 
     335 
     336    // Set the View Instance in the container 
     337    $container->setViewInstance($viewInstance); 
     338     
     339    $outputType = $container->getOutputType()->getName(); 
     340 
     341    $isViewCached = false; 
     342 
     343    if($isCacheable) { 
     344      if(isset($config['output_types'][$otConfig = $outputType]) || isset($config['output_types'][$otConfig = '*'])) { 
     345        $otConfig = $config['output_types'][$otConfig]; 
     346 
     347        if($isActionCached) { 
     348          $isViewCached = $this->checkCache(array_merge($groups, array($outputType)), $config['lifetime']); 
     349        } 
     350      } else { 
     351        $isCacheable = false; 
     352      } 
     353    } 
     354 
     355    if($isViewCached) { 
     356      // $lm->log('View is cached, loading...'); 
     357      try { 
     358        $viewCache = $this->readCache(array_merge($groups, array($outputType))); 
     359      } catch(AgaviException $e) { 
     360        $isViewCached = false; 
     361      } 
     362    } 
     363    if(!$isViewCached) { 
     364      $viewCache = array(); 
     365 
     366      // $lm->log('View is not cached, executing...'); 
     367      // view initialization completed successfully 
     368      $executeMethod = 'execute' . $outputType; 
     369      if(!method_exists($viewInstance, $executeMethod)) { 
     370        $executeMethod = 'execute'; 
     371      } 
    327372      $key = $request->toggleLock(); 
    328       // get the view instance 
    329       $viewInstance = $controller->createViewInstance($actionCache['view_module'], $actionCache['view_name']); 
    330       // initialize the view 
    331       $viewInstance->initialize($container); 
     373      $viewCache['next'] = $viewInstance->$executeMethod($container->getRequestData()); 
    332374      $request->toggleLock($key); 
    333  
    334       // Set the View Instance in the container 
    335       $container->setViewInstance($viewInstance); 
    336        
    337       $outputType = $container->getOutputType()->getName(); 
    338  
    339       $isViewCached = false; 
    340  
    341       if($isCacheable) { 
    342         if(isset($config['output_types'][$otConfig = $outputType]) || isset($config['output_types'][$otConfig = '*'])) { 
    343           $otConfig = $config['output_types'][$otConfig]; 
    344  
    345           if($isActionCached) { 
    346             $isViewCached = $this->checkCache(array_merge($groups, array($outputType)), $config['lifetime']); 
     375    } 
     376 
     377    if($viewCache['next'] instanceof AgaviExecutionContainer) { 
     378      // $lm->log('Forwarding request, skipping rendering...'); 
     379      $container->setNext($viewCache['next']); 
     380    } else { 
     381      if($isViewCached) { 
     382        $layers = $viewCache['layers']; 
     383        $response = $viewCache['response']; 
     384        $container->setResponse($response); 
     385 
     386        foreach($viewCache['template_variables'] as $name => $value) { 
     387          $viewInstance->setAttribute($name, $value); 
     388        } 
     389 
     390        foreach($viewCache['request_attributes'] as $requestAttribute) { 
     391          $request->setAttribute($requestAttribute['name'], $requestAttribute['value'], $requestAttribute['namespace']); 
     392        } 
     393         
     394        foreach($viewCache['request_attribute_namespaces'] as $ranName => $ranValues) { 
     395          $request->setAttributes($ranValues, $ranName); 
     396        } 
     397 
     398        $output = array(); 
     399        $nextOutput = $response->getContent(); 
     400      } else { 
     401        if($viewCache['next'] !== null) { 
     402          // response content was returned from view execute() 
     403          $response->setContent($viewCache['next']); 
     404          $viewCache['next'] = null; 
     405        } 
     406 
     407        $layers = $viewInstance->getLayers(); 
     408 
     409        if($isCacheable) { 
     410          $viewCache['template_variables'] = array(); 
     411          foreach($otConfig['template_variables'] as $varName) { 
     412            $viewCache['template_variables'][$varName] = $viewInstance->getAttribute($varName); 
    347413          } 
    348         } else { 
    349           $isCacheable = false; 
    350         } 
    351       } 
    352  
    353       if($isViewCached) { 
    354         // $lm->log('View is cached, loading...'); 
    355         try { 
    356           $viewCache = $this->readCache(array_merge($groups, array($outputType))); 
    357         } catch(AgaviException $e) { 
    358           $isViewCached = false; 
    359         } 
    360       } 
    361       if(!$isViewCached) { 
    362         $viewCache = array(); 
    363  
    364         // $lm->log('View is not cached, executing...'); 
    365         // view initialization completed successfully 
    366         $executeMethod = 'execute' . $outputType; 
    367         if(!method_exists($viewInstance, $executeMethod)) { 
    368           $executeMethod = 'execute'; 
    369         } 
    370         $key = $request->toggleLock(); 
    371         $viewCache['next'] = $viewInstance->$executeMethod($container->getRequestData()); 
    372         $request->toggleLock($key); 
    373       } 
    374  
    375       if($viewCache['next'] instanceof AgaviExecutionContainer) { 
    376         // $lm->log('Forwarding request, skipping rendering...'); 
    377         $container->setNext($viewCache['next']); 
    378       } else { 
    379         if($isViewCached) { 
    380           $layers = $viewCache['layers']; 
    381           $response = $viewCache['response']; 
    382           $container->setResponse($response); 
    383  
    384           foreach($viewCache['template_variables'] as $name => $value) { 
    385             $viewInstance->setAttribute($name, $value); 
    386           } 
    387  
    388           foreach($viewCache['request_attributes'] as $requestAttribute) { 
    389             $request->setAttribute($requestAttribute['name'], $requestAttribute['value'], $requestAttribute['namespace']); 
    390           } 
    391            
    392           foreach($viewCache['request_attribute_namespaces'] as $ranName => $ranValues) { 
    393             $request->setAttributes($ranValues, $ranName); 
    394           } 
    395  
    396           $output = array(); 
    397           $nextOutput = $response->getContent(); 
    398         } else { 
    399           if($viewCache['next'] !== null) { 
    400             // response content was returned from view execute() 
    401             $response->setContent($viewCache['next']); 
    402             $viewCache['next'] = null; 
    403           } 
    404  
    405           $layers = $viewInstance->getLayers(); 
    406  
    407           if($isCacheable) { 
    408             $viewCache['template_variables'] = array(); 
    409             foreach($otConfig['template_variables'] as $varName) { 
    410               $viewCache['template_variables'][$varName] = $viewInstance->getAttribute($varName); 
    411             } 
    412  
    413             $viewCache['response'] = clone $response; 
    414  
    415             $viewCache['layers'] = array(); 
    416  
    417             $viewCache['slots'] = array(); 
    418  
    419             $lastCacheableLayer = -1; 
    420             if(is_array($otConfig['layers'])) { 
    421               if(count($otConfig['layers'])) { 
    422                 for($i = count($layers)-1; $i >= 0; $i--) { 
    423                   $layer = $layers[$i]; 
    424                   $layerName = $layer->getName(); 
    425                   if(isset($otConfig['layers'][$layerName])) { 
    426                     if(is_array($otConfig['layers'][$layerName])) { 
    427                       $lastCacheableLayer = $i - 1; 
    428                     } else { 
    429                       $lastCacheableLayer = $i; 
    430                     } 
     414 
     415          $viewCache['response'] = clone $response; 
     416 
     417          $viewCache['layers'] = array(); 
     418 
     419          $viewCache['slots'] = array(); 
     420 
     421          $lastCacheableLayer = -1; 
     422          if(is_array($otConfig['layers'])) { 
     423            if(count($otConfig['layers'])) { 
     424              for($i = count($layers)-1; $i >= 0; $i--) { 
     425                $layer = $layers[$i]; 
     426                $layerName = $layer->getName(); 
     427                if(isset($otConfig['layers'][$layerName])) { 
     428                  if(is_array($otConfig['layers'][$layerName])) { 
     429                    $lastCacheableLayer = $i - 1; 
     430                  } else { 
     431                    $lastCacheableLayer = $i; 
    431432                  } 
    432433                } 
    433434              } 
    434             } else { 
    435               $lastCacheableLayer = count($layers) - 1; 
    436435            } 
    437  
    438             for($i = $lastCacheableLayer + 1; $i < count($layers); $i++) { 
    439               // $lm->log('Adding non-cacheable layer "' . $layers[$i]->getName() . '" to list'); 
    440               $viewCache['layers'][] = clone $layers[$i]; 
     436          } else { 
     437            $lastCacheableLayer = count($layers) - 1; 
     438          } 
     439 
     440          for($i = $lastCacheableLayer + 1; $i < count($layers); $i++) { 
     441            // $lm->log('Adding non-cacheable layer "' . $layers[$i]->getName() . '" to list'); 
     442            $viewCache['layers'][] = clone $layers[$i]; 
     443          } 
     444        } 
     445 
     446        $output = array(); 
     447        $nextOutput = null; 
     448      } 
     449 
     450      $attributes =& $viewInstance->getAttributes(); 
     451 
     452      // $lm->log('Starting rendering...'); 
     453      for($i = 0; $i < count($layers); $i++) { 
     454        $layer = $layers[$i]; 
     455        $layerName = $layer->getName(); 
     456        // $lm->log('Running layer "' . $layerName . '"...'); 
     457        foreach($layer->getSlots() as $slotName => $slotContainer) { 
     458          if($isViewCached && isset($viewCache['slots'][$layerName][$slotName])) { 
     459            // $lm->log('Loading cached slot "' . $slotName . '"...'); 
     460            $slotResponse = $viewCache['slots'][$layerName][$slotName]; 
     461          } else { 
     462            // $lm->log('Running slot "' . $slotName . '"...'); 
     463            $slotResponse = $slotContainer->execute(); 
     464            if($isCacheable && !$isViewCached && isset($otConfig['layers'][$layerName]) && is_array($otConfig['layers'][$layerName]) && in_array($slotName, $otConfig['layers'][$layerName])) { 
     465              // $lm->log('Adding response of slot "' . $slotName . '" to cache...'); 
     466              $viewCache['slots'][$layerName][$slotName] = $slotResponse; 
    441467            } 
    442468          } 
    443  
    444           $output = array(); 
    445           $nextOutput = null; 
    446         } 
    447  
    448         $attributes =& $viewInstance->getAttributes(); 
    449  
    450         // $lm->log('Starting rendering...'); 
    451         for($i = 0; $i < count($layers); $i++) { 
    452           $layer = $layers[$i]; 
    453           $layerName = $layer->getName(); 
    454           // $lm->log('Running layer "' . $layerName . '"...'); 
    455           foreach($layer->getSlots() as $slotName => $slotContainer) { 
    456             if($isViewCached && isset($viewCache['slots'][$layerName][$slotName])) { 
    457               // $lm->log('Loading cached slot "' . $slotName . '"...'); 
    458               $slotResponse = $viewCache['slots'][$layerName][$slotName]; 
    459             } else { 
    460               // $lm->log('Running slot "' . $slotName . '"...'); 
    461               $slotResponse = $slotContainer->execute(); 
    462               if($isCacheable && !$isViewCached && isset($otConfig['layers'][$layerName]) && is_array($otConfig['layers'][$layerName]) && in_array($slotName, $otConfig['layers'][$layerName])) { 
    463                 // $lm->log('Adding response of slot "' . $slotName . '" to cache...'); 
    464                 $viewCache['slots'][$layerName][$slotName] = $slotResponse; 
    465               } 
    466             } 
    467             // set the presentation data as a template attribute 
    468             if(($output[$slotName] = $slotResponse->getContent()) !== null) { 
    469               // $lm->log('Merging in response from slot "' . $slotName . '"...'); 
    470               // the slot really output something 
    471               // let our response grab the stuff it needs from the slot's response 
    472               $response->merge($slotResponse); 
    473             } 
     469          // set the presentation data as a template attribute 
     470          if(($output[$slotName] = $slotResponse->getContent()) !== null) { 
     471            // $lm->log('Merging in response from slot "' . $slotName . '"...'); 
     472            // the slot really output something 
     473            // let our response grab the stuff it needs from the slot's response 
     474            $response->merge($slotResponse); 
    474475          } 
    475           $moreAssigns = array( 
    476             'container' => $container, 
    477             'inner' => $nextOutput, 
    478             'request_data' => $container->getRequestData(), 
    479             'validation_manager' => $container->getValidationManager(), 
    480             'view' => $viewInstance, 
    481           ); 
    482           // lock the request. can't be done outside the loop for the whole run, see #628 
    483           $key = $request->toggleLock(); 
    484           $nextOutput = $layer->getRenderer()->render($layer, $attributes, $output, $moreAssigns); 
    485           // and unlock the request again 
    486           $request->toggleLock($key); 
    487  
    488           $response->setContent($nextOutput); 
    489  
    490           if($isCacheable && !$isViewCached && $i === $lastCacheableLayer) { 
    491             $viewCache['response'] = clone $response; 
    492           } 
    493  
    494           $output = array(); 
    495           $output[$layer->getName()] = $nextOutput; 
    496         } 
    497       } 
    498  
    499       if($isCacheable) { 
    500         // we're writing the view cache first. this is just in case we get into a situation with really bad timing on the leap of a second 
    501         if(!$isViewCached) { 
    502           $viewCache['request_attributes'] = array(); 
    503           foreach($otConfig['request_attributes'] as $requestAttribute) { 
    504             $viewCache['request_attributes'][] = $requestAttribute + array('value' => $request->getAttribute($requestAttribute['name'], $requestAttribute['namespace'])); 
    505           } 
    506           $viewCache['request_attribute_namespaces'] = array(); 
    507           foreach($otConfig['request_attribute_namespaces'] as $requestAttributeNamespace) { 
    508             $viewCache['request_attribute_namespaces'][$requestAttributeNamespace] = $request->getAttributes($requestAttributeNamespace); 
    509           } 
    510  
    511           $this->writeCache(array_merge($groups, array($outputType)), $viewCache, $config['lifetime']); 
    512  
    513           // $lm->log('Writing View cache...'); 
    514         } 
    515         if(!$isActionCached) { 
    516           $actionCache['action_attributes'] = array(); 
    517           foreach($config['action_attributes'] as $attributeName) { 
    518             $actionCache['action_attributes'][$attributeName] = $actionAttributes[$attributeName]; 
    519           } 
    520  
    521           // $lm->log('Writing Action cache...'); 
    522  
    523           $this->writeCache(array_merge($groups, array(self::ACTION_CACHE_ID)), $actionCache, $config['lifetime']); 
    524         } 
     476        } 
     477        $moreAssigns = array( 
     478          'container' => $container, 
     479          'inner' => $nextOutput, 
     480          'request_data' => $container->getRequestData(), 
     481          'validation_manager' => $container->getValidationManager(), 
     482          'view' => $viewInstance, 
     483        ); 
     484        // lock the request. can't be done outside the loop for the whole run, see #628 
     485        $key = $request->toggleLock(); 
     486        $nextOutput = $layer->getRenderer()->render($layer, $attributes, $output, $moreAssigns); 
     487        // and unlock the request again 
     488        $request->toggleLock($key); 
     489 
     490        $response->setContent($nextOutput); 
     491 
     492        if($isCacheable && !$isViewCached && $i === $lastCacheableLayer) { 
     493          $viewCache['response'] = clone $response; 
     494        } 
     495 
     496        $output = array(); 
     497        $output[$layer->getName()] = $nextOutput; 
     498      } 
     499    } 
     500 
     501    if($isCacheable) { 
     502      // we're writing the view cache first. this is just in case we get into a situation with really bad timing on the leap of a second 
     503      if(!$isViewCached) { 
     504        $viewCache['request_attributes'] = array(); 
     505        foreach($otConfig['request_attributes'] as $requestAttribute) { 
     506          $viewCache['request_attributes'][] = $requestAttribute + array('value' => $request->getAttribute($requestAttribute['name'], $requestAttribute['namespace'])); 
     507        } 
     508        $viewCache['request_attribute_namespaces'] = array(); 
     509        foreach($otConfig['request_attribute_namespaces'] as $requestAttributeNamespace) { 
     510          $viewCache['request_attribute_namespaces'][$requestAttributeNamespace] = $request->getAttributes($requestAttributeNamespace); 
     511        } 
     512 
     513        $this->writeCache(array_merge($groups, array($outputType)), $viewCache, $config['lifetime']); 
     514 
     515        // $lm->log('Writing View cache...'); 
     516      } 
     517      if(!$isActionCached) { 
     518        $actionCache['action_attributes'] = array(); 
     519        foreach($config['action_attributes'] as $attributeName) { 
     520          $actionCache['action_attributes'][$attributeName] = $actionAttributes[$attributeName]; 
     521        } 
     522 
     523        // $lm->log('Writing Action cache...'); 
     524 
     525        $this->writeCache(array_merge($groups, array(self::ACTION_CACHE_ID)), $actionCache, $config['lifetime']); 
    525526      } 
    526527    }