Example #1
0
 public function __toString()
 {
     if ($this->numCode > 0) {
         switch ($this->numCode) {
             case 404:
                 $objRequest = Request::getInstance();
                 header(sprintf("%s 404 Not Found", $objRequest->protocol()));
                 break;
             default:
                 exit('unexcepted response header code');
                 break;
         }
     }
     return $this->strContent;
 }
Example #2
0
 private function currentAppUrl()
 {
     $strResult = '';
     $strConfigName = '_appUrlsByEnvironment';
     $objRequest = Request::getInstance();
     $strRequestDomain = $objRequest->domain();
     //        echo $strRequestDomain;
     //        exit();
     foreach ($this->arrWorkingEnvironments as $numEnvironment) {
         $strConfigKeyName = sprintf('environment::%d', $numEnvironment);
         $arrEnvironmentUrls = Config::get($strConfigKeyName, $strConfigName);
         if (empty($arrEnvironmentUrls)) {
             continue;
         }
         foreach ($arrEnvironmentUrls as $strEnvironmentUrl) {
             if ($strEnvironmentUrl === $strRequestDomain) {
                 $strResult = $strRequestDomain;
                 self::$numCurrentEnvironment = $numEnvironment;
                 break;
             }
         }
     }
     return $strResult;
 }
Example #3
0
 public function launch()
 {
     $strController = sprintf('controller\\%s', $this->strControllerName);
     $objController = new $strController();
     $objController->strControllerName = $this->strControllerName;
     //        $objController->strView = strtolower($this->strControllerName).'/'.$this->strActionName;
     //        $objController->strLayout = 'default';
     $objActionMethod = new \ReflectionMethod($strController, $this->strActionName);
     $arrRequestParams = Request::getParams();
     $objResponse = $objActionMethod->invokeArgs($objController, $arrRequestParams);
     //        echo '<pre>';
     //        print_r($objController);
     //        print_r($objActionMethod);
     //        print_r($objResponse);
     //        exit();
     return $objResponse;
 }
Example #4
0
 public function findRoute($strUri, $strCurrentLanguage, $boolDebug = false)
 {
     $objRoute = null;
     $arrHits = array();
     $objRecognizedRoute = null;
     if (!empty($this->arrRoutes[$strCurrentLanguage])) {
         $arrRoutesToCheck = $this->arrRoutes[$strCurrentLanguage];
     } else {
         $arrRoutesToCheck = $this->arrRoutes;
     }
     foreach ($arrRoutesToCheck as $objRoute) {
         //            $strPattern = $objRoute->strUri;
         foreach ($objRoute->arrUris as $strPattern) {
             $strPattern = str_replace('/', '\\/', $strPattern);
             $strPattern = str_replace('.', '\\.', $strPattern);
             $strPattern = str_replace('-', '\\-', $strPattern);
             //            echo str_replace(array('\/', '\-', '\.'), array('/', '-', '.'), $strPattern) .' -> ';
             $strPattern = sprintf('^%s$', preg_replace('/\\{[^}]+\\}/', '([^\\/]+)', $strPattern));
             //            echo str_replace(array('\/', '\-', '/.'), array('/', '-', '.'), $strPattern).'<br />';
             $strPattern = '/' . $strPattern . '/';
             //            echo $strUri .' -> '.$strPattern.'<br />';
             $numPregMatchResult = @preg_match($strPattern, $strUri, $arrHits);
             //                if ($boolDebug === true) {
             //                    echo '<pre>'.$numPregMatchResult;
             //                    print_r($arrHits);
             //                    echo '</pre> ('.$numPregMatchResult.')';
             //                }
             if ($numPregMatchResult === 1) {
                 //                exit();
                 if (!empty($arrHits)) {
                     $arrFilteredHits = array();
                     if ($boolDebug === true) {
                         echo '1) "' . $numPregMatchResult . '"<pre>';
                         print_r($arrHits);
                         echo '</pre>';
                     }
                     //                    for ($numHit = 1; $numHit<count($arrHits); $numHit+=2) {
                     //                        $arrFilteredHits[] = $arrHits[$numHit];
                     //                    }
                     //                    array_shift($arrHits);
                     ////                    Request::setParams($arrFilteredHits);
                     //
                     //                    Request::setParams($arrHits);
                     for ($numHit = 1; $numHit < count($arrHits); $numHit++) {
                         if (substr($arrHits[$numHit], -1) !== '/') {
                             $arrFilteredHits[] = $arrHits[$numHit];
                         }
                     }
                     Request::setParams($arrFilteredHits);
                     //                    echo '<pre>';
                     //                    print_r($arrFilteredHits);
                     //
                     //                    print_r($arrHits);
                     //                    exit();
                 }
                 $objRecognizedRoute = $objRoute;
                 Debug::log('On route ' . $objRecognizedRoute->strRouteFullName, 'core-router');
                 break;
             }
         }
         if (!empty($objRecognizedRoute)) {
             break;
         }
     }
     //        if (empty($objRecognizedRoute)) {
     //            echo "ERROR! ".__FILE__.'::'.__FUNCTION__.'#'.__LINE__;
     //            exit();
     //        }
     //        echo 's';
     //        echo '<pre>';
     //        print_r($objRecognizedRoute);
     //        exit();
     return $objRecognizedRoute;
 }
Example #5
0
 public static function currentUrl()
 {
     $objCurrentRoute = \webcitron\Subframe\Router::getCurrentRoute();
     $arrRequestParams = \webcitron\Subframe\Request::getParams();
     $strUrl = \webcitron\Subframe\Url::route($objCurrentRoute->strRouteFullName, $arrRequestParams);
     return $strUrl;
 }
Example #6
0
 public function withArgs()
 {
     $arrArgs = Request::args();
     return !empty($arrArgs);
 }