Example #1
0
File: php.php Project: xpd1437/swap
 public static function forward_to($target, $deny_self = true)
 {
     if (!$target instanceof target) {
         $target = new target($target);
     }
     if ($deny_self && $target->get_target_name() === parent::$target->get_target_name()) {
         throw new developer_error('cannot forward to self');
     }
     $forward = new action_forward();
     $forward->set_target($target);
     throw $forward;
 }
Example #2
0
File: pps.php Project: xpd1437/swap
 protected static function do_render_in($_view_dir, $_pps_type, target $_target)
 {
     foreach ($_target->get_param('link', []) as $_linked_name) {
         $_file = $_pps_type . '/' . $_linked_name . '.' . $_pps_type;
         $_pps_file = $_view_dir . '/' . $_file;
         if (is_readable($_pps_file)) {
             if (kernel::is_debug()) {
                 echo "\n/******** {$_file} ********/\n\n";
             }
             require $_pps_file;
         }
     }
     $_layout_name = $_target->get_param('layout', '');
     if ($_layout_name !== '') {
         $_file = 'layout/' . $_layout_name . '.' . $_pps_type;
         $_pps_file = $_view_dir . '/' . $_file;
         if (is_readable($_pps_file)) {
             if (kernel::is_debug()) {
                 echo "\n/******** {$_file} ********/\n\n";
             }
             require $_pps_file;
         }
     }
     foreach ($_target->get_param('block', []) as $_block_name) {
         $_file = 'block/' . $_block_name . '.' . $_pps_type;
         $_pps_file = $_view_dir . '/' . $_file;
         if (is_readable($_pps_file)) {
             if (kernel::is_debug()) {
                 echo "\n/******** {$_file} ********/\n\n";
             }
             require $_pps_file;
         }
     }
     if ($_target->get_target_name() !== '') {
         $_file = 'page/' . $_target->get_target_file('.' . $_pps_type);
         $_pps_file = $_view_dir . '/' . $_file;
         if (is_readable($_pps_file)) {
             if (kernel::is_debug()) {
                 echo "\n/******** {$_file} ********/\n\n";
             }
             require $_pps_file;
         }
     }
 }
Example #3
0
 protected static function build_routed_left_url(target $target)
 {
     $target_params = $target->get_params();
     $target_name = $target->get_target_name();
     if ($target->has_module()) {
         $target_module = $target->get_module_name();
         $flipped_routes = self::$module_flipped_routes[$target_module];
     } else {
         $target_module = '';
         $flipped_routes = self::$base_flipped_routes;
     }
     if ($target_params === []) {
         if (isset($flipped_routes[$target_name])) {
             $result_pattern = $flipped_routes[$target_name];
             return $target_module === '' ? ltrim($result_pattern, '/') : substr($result_pattern, strpos($result_pattern, '-') + 1);
         }
     } else {
         $target_param_keys = $target->get_param_keys();
         foreach ($flipped_routes as $match_token => $result_pattern) {
             $match_target = new target($match_token);
             if ($match_target->get_target_name() === $target_name && $match_target->get_param_keys() === $target_param_keys) {
                 $args = [];
                 $match = true;
                 foreach ($match_target->get_params() as $key => $value) {
                     if ($value[0] === '$') {
                         $number = substr($value, 1);
                         $args[$number] = $target_params[$key];
                     } else {
                         if ($value !== $target_params[$key]) {
                             $match = false;
                             break;
                         }
                     }
                 }
                 if ($match) {
                     ksort($args);
                     if ($target->has_module()) {
                         $result_pattern = substr($result_pattern, strpos($result_pattern, '-') + 1);
                     }
                     $request_parts = explode('*', $result_pattern);
                     $result_uri = '';
                     for ($i = 0, $n = count($args); $i < $n; $i++) {
                         $result_uri .= $request_parts[$i] . urlencode($args[$i + 1]);
                     }
                     $result_uri .= $request_parts[$i];
                     return ltrim($result_uri, '/');
                 }
             }
         }
     }
     return null;
 }