PHP Class Nexcessnet_Turpentine_Model_Observer_Esi

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Inheritance: extends Varien_Event_Observer
Exibir arquivo Open project: nexcess/magento-turpentine

Public Methods

Method Description
addMessagesBlockRewrite ( Varien_Object $eventObject ) : null Add the core/messages block rewrite if the flash message fix is enabled
checkCacheFlag ( Varien_Object $eventObject ) : null Allows disabling page-caching by setting the cache flag on a controller
checkRedirectUrl ( Varien_Object $eventObject ) : null On controller redirects, check the target URL and set to home page if it would otherwise go to a getBlock URL
hookToAddToCartAfter ( $observer )
hookToAddToCartBefore ( $observer )
hookToAddToWishlistBefore ( $observer ) : Nexcessnet_Turpentine_Model_Observer_Esi Set the form key on the add to wishlist request
hookToControllerActionPostDispatch ( $observer )
hookToControllerActionPreDispatch ( $observer )
injectEsi ( Varien_Object $eventObject ) : null Encode block data in URL then replace with ESI template
loadCacheClearEvents ( Varien_Object $eventObject ) : null Load the cache clear events from stored config
removeCustomerGroupCookie ( Varien_Object $eventObject ) : null Destroy the cookie with the customer group when customer logs out
replaceFormKeyPlaceholder ( Varien_Object $eventObject ) : null Replace the form key placeholder with the ESI include fragment
setCustomerGroupCookie ( Varien_Object $eventObject ) : null Set a cookie with the customer group id when customer logs in
setFlagHeaders ( Varien_Object $eventObject ) : null Check the ESI flag and set the ESI header if needed
setReplaceFormKeyFlag ( Varien_Object $eventObject ) : null Check the magento version and runtime env and set the replace_form_key flag if needed

Protected Methods

Method Description
_checkIsEsiUrl ( string $url ) : boolean Check if a URL *is* for the /turpentine/esi/getBlock/ action
_checkIsNotEsiUrl ( string $url ) : boolean Check if a URL *is not* for the /turpentine/esi/getBlock/ action
_fixupUencUrl ( string $uencUrl ) : string Fix a URL to ensure it uses Magento's base URL instead of the backend URL
_getBlockLayoutHandles ( Mage_Core_Block_Template $block ) : array Get the active layout handles for this block and any child blocks
_getComplexRegistryData ( array $valueOptions, mixed $value ) : array Get the complex registry entry data
_getDefaultEsiOptions ( $options ) : array Get the default ESI options
_getEsiData ( Mage_Core_Block_Template $blockObject, array $esiOptions ) : Varien_Object Generate ESI data to be encoded in URL

Method Details

_checkIsEsiUrl() protected method

Check if a URL *is* for the /turpentine/esi/getBlock/ action
protected _checkIsEsiUrl ( string $url ) : boolean
$url string
return boolean

_checkIsNotEsiUrl() protected method

Check if a URL *is not* for the /turpentine/esi/getBlock/ action
protected _checkIsNotEsiUrl ( string $url ) : boolean
$url string
return boolean

_fixupUencUrl() protected method

Fix a URL to ensure it uses Magento's base URL instead of the backend URL
protected _fixupUencUrl ( string $uencUrl ) : string
$uencUrl string
return string

_getBlockLayoutHandles() protected method

This is probably kind of slow since it uses a bunch of xpath searches but this was the easiest way to get the info needed. Should be a target for future optimization There is an issue with encoding the used handles in the URL, if the used handles change (ex customer logs in), the cached version of the page will still have the old handles encoded in it's ESI url. This can lead to weirdness like the "Log in" link displaying for already logged in visitors on pages that were initially visited by not-logged-in visitors. Not sure of a solution for this yet. Above problem is currently solved by EsiController::_swapCustomerHandles() but it would be best to find a more general solution to this.
protected _getBlockLayoutHandles ( Mage_Core_Block_Template $block ) : array
$block Mage_Core_Block_Template
return array

_getComplexRegistryData() protected method

Get the complex registry entry data
protected _getComplexRegistryData ( array $valueOptions, mixed $value ) : array
$valueOptions array
$value mixed
return array

_getDefaultEsiOptions() protected method

Get the default ESI options
protected _getDefaultEsiOptions ( $options ) : array
return array

_getEsiData() protected method

Generate ESI data to be encoded in URL
protected _getEsiData ( Mage_Core_Block_Template $blockObject, array $esiOptions ) : Varien_Object
$blockObject Mage_Core_Block_Template
$esiOptions array
return Varien_Object

addMessagesBlockRewrite() public method

The core/messages block is rewritten because it doesn't use a template we can replace with an ESI include tag, just dumps out a block of hard-coded HTML and also frequently skips the toHtml method
public addMessagesBlockRewrite ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

checkCacheFlag() public method

Events: controller_action_layout_generate_blocks_after
public checkCacheFlag ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

checkRedirectUrl() public method

On controller redirects, check the target URL and set to home page if it would otherwise go to a getBlock URL
public checkRedirectUrl ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

hookToAddToCartAfter() public method

public hookToAddToCartAfter ( $observer )

hookToAddToCartBefore() public method

public hookToAddToCartBefore ( $observer )

hookToAddToWishlistBefore() public method

Set the form key on the add to wishlist request
public hookToAddToWishlistBefore ( $observer ) : Nexcessnet_Turpentine_Model_Observer_Esi
$observer
return Nexcessnet_Turpentine_Model_Observer_Esi

hookToControllerActionPostDispatch() public method

public hookToControllerActionPostDispatch ( $observer )

hookToControllerActionPreDispatch() public method

public hookToControllerActionPreDispatch ( $observer )

injectEsi() public method

Encode block data in URL then replace with ESI template
public injectEsi ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

loadCacheClearEvents() public method

Load the cache clear events from stored config
public loadCacheClearEvents ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

removeCustomerGroupCookie() public method

Events: customer_logout
public removeCustomerGroupCookie ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

replaceFormKeyPlaceholder() public method

Replace the form key placeholder with the ESI include fragment
public replaceFormKeyPlaceholder ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

setCustomerGroupCookie() public method

Events: customer_login
public setCustomerGroupCookie ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

setFlagHeaders() public method

Events: http_response_send_before
public setFlagHeaders ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null

setReplaceFormKeyFlag() public method

Check the magento version and runtime env and set the replace_form_key flag if needed
public setReplaceFormKeyFlag ( Varien_Object $eventObject ) : null
$eventObject Varien_Object
return null