On controller redirects, check the target URL and set to home page
if it would otherwise go to a getBlock URL

@param  Varien_Object $eventObject
@return null
18832
public function checkRedirectUrl($eventObject) {
        $esiHelper = Mage::helper('turpentine/esi');
        $url = $eventObject->getTransport()->getUrl();
        $referer = Mage::helper('core/http')->getHttpReferer();
        $dummyUrl = $esiHelper->getDummyUrl();
        $reqUenc = Mage::helper('core')->urlDecode(
            Mage::app()->getRequest()->getParam('uenc') );

        if ($this->_checkIsEsiUrl($url)) {
            if ($this->_checkIsNotEsiUrl($reqUenc) &&
                    Mage::getBaseUrl() == $url) {
                $newUrl = $this->_fixupUencUrl($reqUenc);
            } elseif ($this->_checkIsNotEsiUrl($referer)) {
                $newUrl = $referer;
            } else {
                $newUrl = $dummyUrl;
            }
            // TODO: make sure this actually looks like a URL
            $eventObject->getTransport()->setUrl($newUrl);
        }

        if ($eventObject->getTransport()->getUrl() != $url) {
            Mage::helper('turpentine/debug')->logDebug(
                'Detected redirect to ESI URL, changing: %s => %s',
                $url, $eventObject->getTransport()->getUrl() );
        }
    }
1195296
public Object getBlockEventResult() {
		Object result = eventResultCache.get();
		if (result != null) {
			return result;
		}

		if (eventResultHandler != null) {
			result = eventResultHandler.getBlockedValue();
			if (result != null){
				if (!eventResultCache.compareAndSet(null, result)){
					result = eventResultCache.get();	
				}
			}
		}
		return result;
	}
821037
public function writeUrlElement(QueryResult $entryObject)
    {
        $url = new ODataURL();
        if (null !== $entryObject->results) {
            $currentResourceType = $this->getCurrentResourceSetWrapper()->getResourceType();
            $relativeUri = $this->getEntryInstanceKey(
                $entryObject->results,
                $currentResourceType,
                $this->getCurrentResourceSetWrapper()->getName()
            );

            $url->url = rtrim($this->absoluteServiceUri, '/') . '/' . $relativeUri;
        }

        return $url;
    }
960031
public function redirectTo($object)
    {
        $url = false;

        if ($this->getRequest()->get('btn_update_and_list')) {
            $url = $this->admin->generateUrl('list', ['active_tab' => $this->getRequest()->get('context')]);
        }
        if ($this->getRequest()->get('btn_create_and_list')) {
            $url = $this->admin->generateUrl('list', ['active_tab' => $this->getRequest()->get('context')]);
        }

        if ($this->getRequest()->get('btn_create_and_create')) {
            $params = [];
            if ($this->admin->hasActiveSubClass()) {
                $params['subclass'] = $this->getRequest()->get('subclass');
            }
            $url = $this->admin->generateUrl('create', $params);
        }

        if (!$url) {
            $url = $this->admin->generateObjectUrl('edit', $object);
        }

        return new RedirectResponse($url);
    }
465504
public function onPostSerialize(ObjectEvent $event)
    {
        /** @var Content $content */
        $content = $event->getObject();
        /** @var JsonSerializationVisitor $visitor */
        $visitor = $event->getVisitor();

        if (!($content instanceof Content)) {
            return;
        }

        foreach ($content->getData() as $key => $value) {
            $visitor->setData($key, $value);
        }

        $visitor->setData('publishedState', (WorkflowStage::PUBLISHED === $content->getWorkflowStage()));

        if (RedirectType::EXTERNAL === $content->getNodeType()) {
            $visitor->setData('linked', 'external');
        } elseif (RedirectType::INTERNAL === $content->getNodeType()) {
            $visitor->setData('linked', 'internal');
        }

        if (null !== $content->getLocalizationType()) {
            $visitor->setData('type', $content->getLocalizationType()->toArray());
        }

        $visitor->setData(
            '_permissions',
            $this->accessControlManager->getUserPermissionByArray(
                $content->getLocale(),
                PageAdmin::SECURITY_CONTEXT_PREFIX . $content->getWebspaceKey(),
                $content->getPermissions(),
                $this->tokenStorage->getToken()->getUser()
            )
        );
    }
1344975
public static function getWebhookPayload($returnObject = false) {
        $data = file_get_contents("php://input");
        if ($data) {
            return self::jsonDecode($data, !$returnObject);
        } else {
            return null;
        }
    }
281421
public function onKernelView(GetResponseForControllerResultEvent $event)
    {
        /* @var Template $template */
        $request = $event->getRequest();
        $template = $request->attributes->get('_template');

        if (!$template instanceof Template) {
            return;
        }

        if (null === $this->twig) {
            throw new \LogicException('You can not use the "@Template" annotation if the Twig Bundle is not available.');
        }

        $parameters = $event->getControllerResult();
        $owner = $template->getOwner();
        list($controller, $action) = $owner;

        // when the annotation declares no default vars and the action returns
        // null, all action method arguments are used as default vars
        if (null === $parameters) {
            $parameters = $this->resolveDefaultParameters($request, $template, $controller, $action);
        }

        // attempt to render the actual response
        if ($template->isStreamable()) {
            $callback = function () use ($template, $parameters) {
                $this->twig->display($template->getTemplate(), $parameters);
            };

            $event->setResponse(new StreamedResponse($callback));
        } else {
            $event->setResponse(new Response($this->twig->render($template->getTemplate(), $parameters)));
        }

        // make sure the owner (controller+dependencies) is not cached or stored elsewhere
        $template->setOwner([]);
    }
165863
public function execute($eventName, $object)
    {
        if (isset($this->events[$eventName]) && is_array(($this->events[$eventName]))) {
            foreach ($this->events[$eventName] as $method) {
                call_user_func([$object, $method]);
            }
        }
    }
797902
public static function fetchBySourceURL( $url, $asObject = true )
    {
        return eZPersistentObject::fetchObject( self::definition(),
                                                null,
                                                array( "source_url" => $url ),
                                                $asObject );
    }
234539
public function setBlockAreaObject(&$a)
    {
        $this->a = $a;
        $this->arHandle = $a ? $a->getAreaHandle() : null;
    }
582070
public function banProductPageCacheCheckStock($eventObject) {
        if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) {
            $item = $eventObject->getItem();
            if ($item->getStockStatusChangedAutomatically() ||
                    ($item->getOriginalInventoryQty() <= 0 &&
                        $item->getQty() > 0 &&
                        $item->getQtyCorrection() > 0)) {
                $banHelper = Mage::helper('turpentine/ban');
                $cronHelper = Mage::helper('turpentine/cron');
                $product = Mage::getModel('catalog/product')
                    ->load($item->getProductId());
                $urlPattern = $banHelper->getProductBanRegex($product);
                $result = $this->_getVarnishAdmin()->flushUrl($urlPattern);
                Mage::dispatchEvent('turpentine_ban_product_cache_check_stock',
                    $result);
                if ($this->_checkResult($result) &&
                        $cronHelper->getCrawlerEnabled()) {
                    $cronHelper->addProductToCrawlerQueue($product);
                    foreach ($banHelper->getParentProducts($product)
                            as $parentProduct) {
                        $cronHelper->addProductToCrawlerQueue($parentProduct);
                    }
                }
            }
        }
    }
48749
public function onBeforeRedirect(Event $event)
    {
        /**
         * @var Container $container
         * @var Collector $collector
         * @var Profiler  $profiler
         */
        $container = $event['app']->getContainer();
        $collector = $container->get('debugger.collector');
        $profiler  = $container->get('profiler');

        $collector['redirect'] = [
            'url' => $event['url'],
            'moved' => $event['moved'],
        ];
    }
731077
public function crawlUrls($eventObject) {
        $helper = Mage::helper('turpentine/cron');
        if ($helper->getCrawlerEnabled()) {
            $maxRunTime = $helper->getAllowedRunTime();
            if ($maxRunTime === 0) {
                $maxRunTime = self::MAX_CRAWL_TIME;
            }

            $batchSize = $helper->getCrawlerBatchSize();
            $timeout = $helper->getCrawlerWaitPeriod();
            $crawlCount = 0;

            // just in case we have a silly short max_execution_time
            $maxRunTime = abs($maxRunTime - self::EXEC_TIME_BUFFER);
            while (($helper->getRunTime() < $maxRunTime) &&
                    $url = $helper->getNextUrl()) {
                if ( ! $this->_crawlUrl($url)) {
                    Mage::helper('turpentine/debug')->logWarn(
                        'Failed to crawl URL: %s', $url );
                }

                if ($crawlCount > 0
                    && $timeout > 0
                    && $batchSize > 0
                    && $crawlCount % $batchSize == 0
                ) {
                    Mage::helper('turpentine/debug')->logDebug('Crawled '.$crawlCount.' urls, sleeping for '.$timeout.' seconds');
                    sleep($timeout);
                }
                $crawlCount++;
            }
        }
    }
820205
public function canEditTarget(DataObject $target)
    {
        $absolute = $this->BaseAction()->canEditTarget($target);
        if (!is_null($absolute)) {
            return $absolute;
        }
        switch ($this->BaseAction()->AllowEditing) {
            case 'By Assignees':
                return $this->Workflow()->canEdit();
            case 'No':
                return false;
            case 'Content Settings':
            default:
                return null;
        }
    }
358510
public function ajaxUrl(PageBlockInterface $block, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
    {
        $parameters['blockId'] = $block->getId();

        if ($block->getPage() instanceof PageInterface) {
            $parameters['pageId'] = $block->getPage()->getId();
        }

        return $this->router->generate('sonata_page_ajax_block', $parameters, $absolute);
    }
356507
protected function locateObject()
	{
		if ( $this->locatorUsed ) {
			return;
		}

		// NodeElement + TargetElement = Proxy.
		$this->locatorUsed = true;

		$object = call_user_func(
			array($this->className, 'fromNodeElements'),
			$this->locateElements(),
			null,
			$this->pageFactory
		);

		\ArrayObject::offsetSet(null, $object);
	}
417849
public function getRouteMatch()
    {
        if ($this->routeMatch instanceof RouteMatch) {
            return $this->routeMatch;
        }

        $controller = $this->getController();

        if (!$controller instanceof InjectApplicationEventInterface) {
            throw new Exception\DomainException(
                'Url plugin requires a controller that implements InjectApplicationEventInterface'
            );
        }

        $event      = $controller->getEvent();
        $routeMatch = null;

        if ($event instanceof MvcEvent) {
            $routeMatch = $event->getRouteMatch();
        } elseif ($event instanceof EventInterface) {
            $routeMatch = $event->getParam('route-match', false);
        }

        if (!($routeMatch instanceof RouteMatch)) {
            throw new Exception\RuntimeException('Url plugin requires event compose a route match');
        }

        return $this->routeMatch;
    }