コード例 #1
0
ファイル: Flow.php プロジェクト: satully/dev_socialapp
 /**
  * URLパターンからハンドリング
  * @param mixed{} $urls
  * @param int $index
  * @return $this
  */
 private function handler(array $urls = array(), $index = 0)
 {
     if (preg_match("/^\\/" . str_replace("/", "\\/", self::$package_media_url) . "\\/(\\d+)\\/(\\d+)\\/(.+)\$/", $this->args(), $match)) {
         if ($match[1] == $index) {
             foreach ($urls as $args) {
                 if ($match[2] == $args['map_index'] && isset($args['class'])) {
                     $this->attach_file(File::absolute(Lib::module_root_path(Lib::imported_path(Lib::import($args['class']))) . '/resources/media', $match[3]));
                 }
             }
             Http::status_header(404);
             exit;
         }
         return $this;
     }
     foreach (array_keys($urls) as $pattern) {
         if (preg_match("/^" . (empty($pattern) ? "" : "\\/") . str_replace(array("\\/", "/", "__SLASH__"), array("__SLASH__", "\\/", "\\/"), $pattern) . '[\\/]{0,1}$/', $this->args(), $params)) {
             Log::debug("match pattern `" . $pattern . "` " . (empty($urls[$pattern]['name']) ? '' : '[' . $urls[$pattern]['name'] . ']'));
             array_shift($params);
             $this->pattern = $pattern;
             $map = $urls[$pattern];
             $action = null;
             if (!empty($map['redirect']) && empty($map['class'])) {
                 $this->redirect($map['redirect'][0] == '/' ? substr($map['redirect'], 1) : $map['redirect']);
             }
             if (!empty($map['template']) && empty($map['method'])) {
                 $action = new self('_scope_=' . $map['scope']);
                 $action->set($this, $map, $pattern, $params, $urls);
             } else {
                 if (empty($map['class'])) {
                     throw new RuntimeException('Invalid map');
                 }
                 $class = class_exists($map['class']) ? $map['class'] : Lib::import($map['class']);
                 if (!method_exists($class, $map['method'])) {
                     throw new RuntimeException($map['class'] . '::' . $map['method'] . ' not found');
                 }
                 if (!is_subclass_of($class, __CLASS__)) {
                     throw new RuntimeException("class is not " . __CLASS__);
                 }
                 $action = new $class('_scope_=' . $map['scope'] . ',_init_=false');
                 foreach (array('redirect', 'name') as $k) {
                     $action->{$k} = $map[$k];
                 }
                 $action->set($this, $map, $pattern, $params, $urls);
                 call_user_func_array(array($action, $map['method']), $params);
                 if (!$action->is_filename()) {
                     $ref = new ReflectionObject($action);
                     $file = dirname($ref->getFileName()) . '/resources/templates/' . $map['method'] . '.html';
                     if (is_file($file)) {
                         $action->template($file);
                         $action->media_url(App::url('/' . self::$package_media_url . '/' . $index . '/' . $urls[$pattern]['map_index']));
                     } else {
                         if ($action->is_filename($map['method'] . '.html')) {
                             $action->template($map['method'] . '.html');
                         }
                     }
                 }
             }
             $action->call_module('after_flow', $action);
             $this->add_object($action->o('Template'));
             $this->cp(self::execute_var($map['vars']));
             $this->vars('t', new Templf($action));
             break;
         }
     }
     return $this;
 }
コード例 #2
0
ファイル: __funcs__.php プロジェクト: satully/dev_socialapp
/**
 * パッケージのmediaのパスを返す
 * @param strng $path ベースパスに続くメディアのパス
 * @return string
 */
function module_media($path = null)
{
    list($file) = debug_backtrace(false);
    $root = Lib::module_root_path($file["file"]) . "/resources/media";
    return empty($path) ? $root : File::absolute($root, $path);
}