Example #1
1
 /**
  *
  * @param PWECore $PWE
  * @param bool $forceNewConnection
  * @param string $alias
  * @return Connection
  * @throws DBALException
  */
 public static function getConnection(PWECore $PWE, $forceNewConnection = false, $alias = null)
 {
     if (!$forceNewConnection && self::$connection[$alias]) {
         PWELogger::debug('Used cached connection');
         return self::$connection[$alias];
     }
     $settings = $PWE->getModulesManager()->getModuleSettings(self::getClass());
     $connections = $settings['!c']['connection'];
     $ix = PWEXMLFunctions::findNodeWithAttributeValue($connections, 'alias', $alias);
     if ($ix < 0) {
         throw new \InvalidArgumentException("Alias {$alias} not found in database configs");
     }
     $params = $connections[$ix]['!a'];
     $config = new Configuration();
     $config->setSQLLogger(new PWEDoctrineLogger($alias ? $alias : ''));
     PWELogger::debug("Getting connection: %s", $params);
     self::$connection[$alias] = DriverManager::getConnection($params, $config);
     return self::$connection[$alias];
 }
Example #2
0
 private function recursiveNodeSearch(array $search_uri)
 {
     $link = reset($search_uri);
     $ix = PWEXMLFunctions::findNodeWithAttributeValue($this->node['!c']['url'], 'link', $link);
     if ($ix >= 0) {
         $this->URLArrayMatched[] = array_shift($search_uri);
         $inherited_attrs = $this->node['!i'];
         $this->node =& $this->node['!c']['url'][$ix];
         $this->node['!i'] = (isset($this->node['!a']) ? $this->node['!a'] : array()) + $inherited_attrs;
         if ($search_uri && isset($this->node['!c']['url'])) {
             $this->recursiveNodeSearch($search_uri);
             return;
         }
     }
     PWELogger::debug("Search: %s", $search_uri);
     if ($search_uri && isset($this->node['!c']['params'])) {
         $paramsNode =& $this->node['!c']['params'][0];
         PWELogger::debug("Params branch");
         $count = $paramsNode['!a']['count'];
         if (!$count) {
             $count = 1;
         }
         for ($n = 0; $search_uri && $n < $count; $n++) {
             $this->URLArrayParams[] = array_shift($search_uri);
         }
         $inherited_attrs = $this->node['!i'];
         $paramsNode['!i'] = (isset($paramsNode['!a']) ? $paramsNode['!a'] : array()) + $inherited_attrs;
         if ($search_uri && isset($paramsNode['!c']['url'])) {
             $this->node =& $paramsNode;
             $this->recursiveNodeSearch($search_uri);
             return;
         } else {
             $this->node['!i'] = $paramsNode['!i'];
         }
     }
     if (end($this->URLArray) && !$this->hadTrailingSlash) {
         if ($this->node['!i']['force_trailing_slash'] || !isset($this->node['!i']['force_trailing_slash'])) {
             if (!strstr(end($this->URLArray), '.')) {
                 $url = $this->URL . '/';
                 if ($_GET) {
                     $url .= '?' . http_build_query($_GET);
                 }
                 PWELogger::debug("Node attributes: %s", $this->node['!i']);
                 throw new HTTP3xxException($url, HTTP3xxException::PERMANENT);
             }
         }
     }
     // check params count
     if ($search_uri && isset($this->node['!i']['accept'])) {
         for ($n = 0; $search_uri && $n < $this->node['!i']['accept']; $n++) {
             $this->URLArrayParams[] = array_shift($search_uri);
         }
     }
     if (sizeof($search_uri)) {
         if (strlen(end($search_uri)) || sizeof($search_uri) > 1) {
             $this->failure = new HTTP4xxException("Requested page not found", HTTP4xxException::NOT_FOUND);
         }
     }
 }
Example #3
0
 /**
  * Returns array of hierarchical arrays for site structure level $level.
  * Array chosen by current page path in site structure and current pages
  * have key 'selected' set to true
  * @param int $level level to return
  * @return array
  */
 public function getStructLevel($level)
 {
     PWELogger::debug("Building struct level %s", $level);
     $matched = $this->getURL()->getMatchedAsArray();
     if ($level > sizeof($matched)) {
         if (sizeof($this->getURL()->getParamsAsArray())) {
             $module = $this->getCurrentModuleInstance();
             if ($module instanceof MenuGenerator) {
                 PWELogger::debug('Building menu via current module');
                 return $module->getMenuLevel($level);
             }
         }
         return array();
     } else {
         $levelCount = 0;
         $current =& $this->siteStructure['url'];
         while ($levelCount <= $level) {
             $pos = PWEXMLFunctions::findNodeWithAttributeValue($current, 'link', $matched[$levelCount]);
             if ($pos < 0) {
                 //throw new HTTP5xxException("Something gone completely wrong with the structure");
                 break;
             }
             $current[$pos]['selected'] = true;
             //PWELogger::debug("I", $current[$pos]);
             if ($levelCount == $level) {
                 break;
             }
             $current =& $current[$pos]['!c']['url'];
             $levelCount++;
         }
         //PWELogger::debug("Final array: ", $current);
         return $current;
     }
 }