Example #1
0
 /**
  * コントローラをプラグする
  */
 function plug_controller($file, $segments = NULL)
 {
     $instance =& get_instance();
     if ($segments === NULL) {
         $segments = isset($instance->segments) ? $instance->segments : NULL;
     }
     if ($file !== 'controller') {
         plug_controller('controller', $segments);
     }
     $class = ucfirst($file);
     $sockets = [$GLOBALS['packages'], ['controllers']];
     foreach (array_keys($instance->config['segments']) as $key) {
         if ($key == 'target') {
             break;
         }
         $sockets[] = isset($segments[$key]) ? [$segments[$key], ''] : [''];
     }
     $socket = [$class . '.php'];
     if (isset($instance->config['wild_targets'])) {
         foreach ($instance->config['wild_targets'] as $key => $value) {
             if (in_array($file, $value)) {
                 $socket[] = ucfirst($key) . '.php';
             }
         }
     }
     $sockets[] = $socket;
     $plugged = plug($sockets);
     if (is_null($plugged)) {
         echo "Controller '{$file}' not found.";
         exit(1);
     }
     require_once BASEPATH . $plugged;
     return $plugged;
 }
Example #2
0
<?php

if (preg_match('#^' . dirname($_SERVER['SCRIPT_NAME']) . '/index#', $_SERVER['REQUEST_URI']) !== 0) {
    echo 'URI must not begin with index.';
    exit(1);
}
require_once BASEPATH . plug([$packages, ['common.php']]);
require_once BASEPATH . plug([$packages, ['plug.php']]);
plug_config('wild_targets');
plug_config('segments');
$instance =& get_instance();
foreach ($instance->config['wild_targets'] as $array) {
    foreach ($array as $value) {
        $instance->config['segments']['target'][] = $value;
    }
}
$instance->segments = path_to_segments($_SERVER['PATH_INFO']);
$plugged = plug_controller($instance->segments['target']);
$class = preg_replace('/.php$/', '', basename($plugged));
$instance = new $class();
call_user_func_array([$instance, $instance->segments['action']], $instance->segments['args']);