X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Fclasses%2Fmain%2Fhelper%2Fweb%2Flinks%2Fclass_WebLinkHelper.php;h=8ff8e54c9ad586ef446403d736c036587ab8aab3;hb=3e1fbf30a631cf1cd64562b69228452c49e0033f;hp=83b806d89ac8685a9cee7379f90b577eaad95609;hpb=3107989f93cfb5808ce9d75f1c7d2b7ee3d83d18;p=core.git diff --git a/inc/classes/main/helper/web/links/class_WebLinkHelper.php b/inc/classes/main/helper/web/links/class_WebLinkHelper.php index 83b806d8..8ff8e54c 100644 --- a/inc/classes/main/helper/web/links/class_WebLinkHelper.php +++ b/inc/classes/main/helper/web/links/class_WebLinkHelper.php @@ -4,7 +4,7 @@ * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007 - 2009 Roland Haeder, this is free software + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @@ -32,6 +32,16 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate { */ private $linkBase = ''; + /** + * First parameter seperator + */ + const FIRST_PARAMETER_SEPERATOR = '?'; + + /** + * Seperator for more paraemters + */ + const EXTRA_PARAMETER_SEPERATOR = '&'; + /** * Protected constructor * @@ -47,10 +57,11 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate { * * @param $templateInstance An instance of a template engine * @param $linkName Name of the link we shall generate - * @param $linkBase Link base for all generated links + * @param $linkBase Link base for the link. This parameter is deprecated. * @return $helperInstance A prepared instance of this helper + * @throws NoConfigEntryException A deprecated exception at this point */ - public final static function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase) { + public static final function createWebLinkHelper (CompileableTemplate $templateInstance, $linkName, $linkBase = NULL) { // Get new instance $helperInstance = new WebLinkHelper(); @@ -60,6 +71,42 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate { // Set link name $helperInstance->setLinkName($linkName); + // Get the application instance + $applicationInstance = Registry::getRegistry()->getInstance('application'); + + // Get the request instance + $requestInstance = $applicationInstance->getRequestInstance(); + + // Sanity-check on it + if (is_null($requestInstance)) { + // Throw an exception here + throw new NullPointerException($helperInstance, self::EXCEPTION_IS_NULL_POINTER); + } // END - if + + // Get page (this will throw an exception if not set) + $page = $helperInstance->convertDashesToUnderscores($requestInstance->getRequestElement('page')); + + // Construct config entry + $configEntry = $page . '_' . $linkName . '_action_url'; + + // Is the deprecated parameter set? + if (!is_null($linkBase)) { + // Then output a deprecation message + $helperInstance->deprecationWarning(__METHOD__ . ': linkBase is deprecated. Please remove it from your templates and add a config entry ' . $configEntry . ' in your config.php file.'); + } // END - if + + // Determine link base from config now and 'page' request + try { + $newLinkBase = $helperInstance->getConfigInstance()->getConfigEntry($configEntry); + $linkBase = $newLinkBase; + } catch (NoConfigEntryException $e) { + // Is the deprecated linkBase not set? + if (is_null($linkBase)) { + // Then throw again the exception + throw new NoConfigEntryException(array(__CLASS__, ($configEntry)), FrameworkConfiguration::EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND); + } // END - if + } + // Set link base $helperInstance->setLinkBase($linkBase); @@ -226,17 +273,17 @@ class WebLinkHelper extends BaseWebHelper implements HelpableTemplate { // Check if a previous group was opened if ($this->ifGroupOpenedPreviously() === false) { // No group was opened before! - throw new NoGroupOpenedException(array($this, $linkAction."(".$linkText.")"), self::EXCEPTION_GROUP_NOT_OPENED); + throw new NoGroupOpenedException(array($this, $linkAction . '(' . $linkText . ')'), self::EXCEPTION_GROUP_NOT_OPENED); } // END - if // Default parameter seperator is & - $seperator = "&"; + $seperator = self::EXTRA_PARAMETER_SEPERATOR; // Is there a question mark in? - $linkArray = explode("?", $this->getLinkBase()); + $linkArray = explode(self::FIRST_PARAMETER_SEPERATOR, $this->getLinkBase()); if (count($linkArray) == 0) { // No question mark - $seperator = "?"; + $seperator = self::FIRST_PARAMETER_SEPERATOR; } // END - if // Prepare action