Exemplo n.º 1
0
 /**
  * Returns class name for provided file name and package pointer.
  *
  * @param string $fileName
  * @param string $packagePointer
  * @return string
  */
 public function filenameToClass($fileName, $packagePointer = null)
 {
     $packagePointer = $packagePointer === null ? '' : strtoupper($packagePointer) . '_';
     return $packagePointer . UTIL_String::delimiterToCaps('_' . substr($fileName, 0, -4));
 }
Exemplo n.º 2
0
 /**
  * Returns dispatch params (controller, action, vars) for provided URI.
  * 
  * @throws Redirect404Exception
  * @param string $uri
  * @return array
  */
 public function getDispatchAttrs($uri)
 {
     //TODO check if method is in try/catch
     $uriString = UTIL_String::removeFirstAndLastSlashes($uri);
     $uriArray = explode('/', $uriString);
     if (sizeof($uriArray) < 2) {
         throw new Redirect404Exception('Invalid uri was provided for routing!');
     }
     $controllerNamePrefixAdd = '';
     if (strstr($uriArray[0], '-')) {
         $uriPartArray = explode('-', $uriArray[0]);
         $uriArray[0] = $uriPartArray[1];
         $controllerNamePrefixAdd = strtoupper($uriPartArray[0]);
     }
     $dispatchAttrs = array();
     $classPrefix = null;
     $arraySize = sizeof($uriArray);
     for ($i = 0; $i < $arraySize; $i++) {
         if ($i === 0) {
             try {
                 $classPrefix = strtoupper(OW::getPluginManager()->getPluginKey($uriArray[$i])) . '_' . $controllerNamePrefixAdd . $this->controllerNamePrefix;
             } catch (InvalidArgumentException $e) {
                 throw new Redirect404Exception('Invalid uri was provided for routing!');
             }
             continue;
         }
         if ($i === 1) {
             if ($classPrefix === null) {
                 throw new Redirect404Exception('Invalid uri was provided for routing!');
             }
             $ctrClass = $classPrefix . '_' . UTIL_String::delimiterToCaps('-' . $uriArray[$i], '-');
             if (!file_exists(OW::getAutoloader()->getClassPath($ctrClass))) {
                 throw new Redirect404Exception('Invalid uri was provided for routing!');
             }
             $dispatchAttrs['controller'] = $ctrClass;
             continue;
         }
         if ($i === 2) {
             $dispatchAttrs['action'] = UTIL_String::delimiterToCaps($uriArray[$i], '-');
             continue;
         }
         if ($i % 2 !== 0) {
             $dispatchAttrs['vars'][$uriArray[$i]] = null;
         } else {
             $dispatchAttrs['vars'][$uriArray[$i - 1]] = $uriArray[$i];
         }
     }
     return $dispatchAttrs;
 }