当前位置: 首页>>代码示例>>PHP>>正文


PHP Hook::exec方法代码示例

本文整理汇总了PHP中think\Hook::exec方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::exec方法的具体用法?PHP Hook::exec怎么用?PHP Hook::exec使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在think\Hook的用法示例。


在下文中一共展示了Hook::exec方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testExec

 public function testExec()
 {
     $data['id'] = 0;
     $data['name'] = 'thinkphp';
     $this->assertEquals(true, Hook::exec('\\tests\\thinkphp\\library\\think\\behavior\\One'));
     $this->assertEquals(false, Hook::exec('\\tests\\thinkphp\\library\\think\\behavior\\One', 'test', $data));
     $this->assertEquals('test', $data['name']);
     $this->assertEquals('Closure', Hook::exec(function (&$data) {
         $data['name'] = 'Closure';
         return 'Closure';
     }));
 }
开发者ID:Lofanmi,项目名称:think,代码行数:12,代码来源:hookTest.php

示例2: getWeiboDetail

 public function getWeiboDetail($id)
 {
     $weibo = S('weibo_' . $id);
     $check_empty = empty($weibo);
     if ($check_empty) {
         $weibo = $this->where(array('status' => 1, 'id' => $id))->find();
         if (!$weibo) {
             return null;
         }
         $weibo_data = unserialize($weibo['data']);
         $class_exists = true;
         $type = array('repost', 'feed', 'image', 'share');
         if (!in_array($weibo['type'], $type)) {
             $class_exists = class_exists('Addons\\Insert' . ucfirst($weibo['type']) . '\\Insert' . ucfirst($weibo['type']) . 'Addon');
         }
         $weibo['content'] = parse_topic(parse_weibo_content($weibo['content']));
         if ($weibo['type'] === 'feed' || $weibo['type'] == '' || !$class_exists) {
             $fetchContent = "<p class='word-wrap'>" . $weibo['content'] . "</p>";
         } elseif ($weibo['type'] === 'repost') {
             $fetchContent = A('Weibo/Type')->fetchRepost($weibo);
         } elseif ($weibo['type'] === 'image') {
             $fetchContent = A('Weibo/Type')->fetchImage($weibo);
         } elseif ($weibo['type'] === 'share') {
             $fetchContent = R('Weibo/Share/getFetchHtml', array('param' => unserialize($weibo['data']), 'weibo' => $weibo), 'Widget');
         } else {
             $fetchContent = Hook::exec('Addons\\Insert' . ucfirst($weibo['type']) . '\\Insert' . ucfirst($weibo['type']) . 'Addon', 'fetch' . ucfirst($weibo['type']), $weibo);
         }
         $weibo = array('id' => intval($weibo['id']), 'content' => strval($weibo['content']), 'create_time' => intval($weibo['create_time']), 'type' => $weibo['type'], 'data' => unserialize($weibo['data']), 'weibo_data' => $weibo_data, 'comment_count' => intval($weibo['comment_count']), 'repost_count' => intval($weibo['repost_count']), 'can_delete' => 0, 'is_top' => $weibo['is_top'], 'uid' => $weibo['uid'], 'fetchContent' => $fetchContent, 'from' => $weibo['from']);
         S('weibo_' . $id, $weibo, 60 * 60);
     }
     $weibo['fetchContent'] = parse_at_users($weibo['fetchContent']);
     $weibo['user'] = query_user(array('uid', 'nickname', 'avatar64', 'space_url', 'rank_link', 'title'), $weibo['uid']);
     $weibo['can_delete'] = $this->canDeleteWeibo($weibo);
     // 判断转发的原微博是否已经删除
     if ($weibo['type'] == 'repost') {
         $source_weibo = $this->getWeiboDetail($weibo['weibo_data']['sourceId']);
         if (!$source_weibo['uid']) {
             if (!$check_empty) {
                 S('weibo_' . $id, null);
                 $weibo = $this->getWeiboDetail($id);
             }
         }
     }
     return $weibo;
 }
开发者ID:naliduo,项目名称:Lightweight-social-platform,代码行数:45,代码来源:WeiboModel.class.php

示例3: B

/**
 * 执行某个行为
 * @param string $name 行为名称
 * @param string $tag 标签名称(行为类无需传入) 
 * @param Mixed $params 传入的参数
 * @return void
 */
function B($name, $tag = '', &$params = NULL)
{
    if ('' == $tag) {
        $name .= 'Behavior';
    }
    \Think\Hook::exec($name, $tag, $params);
}
开发者ID:shaoxianhui,项目名称:guodaxia,代码行数:14,代码来源:functions.php

示例4: B

/**
 * 执行某个行为
 * @param string $name 行为名称
 * @param string $tag 标签名称(行为类无需传入)
 * @param Mixed $params 传入的参数
 * @return void
 */
function B($name, $tag = '', &$params = null)
{
    if ('' == $tag) {
        $name .= 'Behavior';
    }
    return \Think\Hook::exec($name, $tag, $params);
}
开发者ID:a3147972,项目名称:micro_business,代码行数:14,代码来源:functions.php

示例5: behavior

 /**
  * 使用行为类验证
  * @access protected
  * @param mixed     $value  字段值
  * @param mixed     $rule  验证规则
  * @param array     $data  数据
  * @return mixed
  */
 protected function behavior($value, $rule, $data)
 {
     return Hook::exec($rule, '', $data);
 }
开发者ID:HXFY,项目名称:think,代码行数:12,代码来源:Validate.php

示例6: B

/**
 * 执行某个行为
 * @param string $name 行为名称
 * @param Mixed $params 传入的参数
 * @return void
 */
function B($name, &$params = NULL)
{
    if (strpos($name, '/')) {
        list($name, $tag) = explode('/', $name);
    } else {
        $tag = 'run';
    }
    return \Think\Hook::exec($name, $tag, $params);
}
开发者ID:chenpusn,项目名称:guoxian,代码行数:15,代码来源:functions.php

示例7: getWeiboStructure

 private function getWeiboStructure($id)
 {
     $weibo = $this->weiboModel->find($id);
     $canDelete = $this->canDeleteWeibo($id);
     $weibo_data = unserialize($weibo['data']);
     if ($weibo['type'] === 'feed' || $weibo['type'] == '') {
         $fetchContent = "<p class='word-wrap'>" . parse_weibo_content($weibo['content']) . "</p>";
     } elseif ($weibo['type'] === 'repost') {
         $result = Hook::exec('Repost', 'fetchRepost', $weibo);
         $fetchContent = $result;
     } else {
         $result = Hook::exec('Insert' . ucfirst($weibo['type']), 'fetch' . ucfirst($weibo['type']), $weibo);
         $fetchContent = $result;
     }
     return array('id' => intval($weibo['id']), 'content' => strval($weibo['content']), 'create_time' => intval($weibo['create_time']), 'type' => $weibo['type'], 'data' => unserialize($weibo['data']), 'weibo_data' => $weibo_data, 'comment_count' => intval($weibo['comment_count']), 'repost_count' => intval($weibo['repost_count']), 'can_delete' => boolval($canDelete), 'user' => $this->getUserStructure($weibo['uid']), 'is_top' => $weibo['is_top'], 'uid' => $weibo['uid'], 'fetchContent' => $fetchContent);
 }
开发者ID:nullog,项目名称:zhanglubao,代码行数:16,代码来源:WeiboApi.class.php

示例8: parseRule

 /**
  * 解析规则路由
  * @access private
  * @param string    $rule 路由规则
  * @param string    $route 路由地址
  * @param string    $pathinfo URL地址
  * @param array     $option 路由参数
  * @param array     $matches 匹配的变量
  * @return array
  */
 private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = [])
 {
     $request = Request::instance();
     // 解析路由规则
     if ($rule) {
         $rule = explode('/', $rule);
         // 获取URL地址中的参数
         $paths = explode('|', $pathinfo);
         foreach ($rule as $item) {
             $fun = '';
             if (0 === strpos($item, '[:')) {
                 $item = substr($item, 1, -1);
             }
             if (0 === strpos($item, ':')) {
                 $var = substr($item, 1);
                 $matches[$var] = array_shift($paths);
             } else {
                 // 过滤URL中的静态变量
                 array_shift($paths);
             }
         }
     } else {
         $paths = explode('|', $pathinfo);
     }
     // 获取路由地址规则
     if (is_string($route) && isset($option['prefix'])) {
         // 路由地址前缀
         $route = $option['prefix'] . $route;
     }
     // 替换路由地址中的变量
     if (is_string($route) && !empty($matches)) {
         foreach ($matches as $key => $val) {
             if (false !== strpos($route, ':' . $key)) {
                 $route = str_replace(':' . $key, $val, $route);
                 unset($matches[$key]);
             }
         }
     }
     // 绑定模型数据
     if (isset($option['bind_model'])) {
         $bind = [];
         foreach ($option['bind_model'] as $key => $val) {
             if ($val instanceof \Closure) {
                 $result = call_user_func_array($val, [$matches]);
             } else {
                 if (is_array($val)) {
                     $fields = explode('&', $val[1]);
                     $model = $val[0];
                     $exception = isset($val[2]) ? $val[2] : true;
                 } else {
                     $fields = ['id'];
                     $model = $val;
                     $exception = true;
                 }
                 $where = [];
                 $match = true;
                 foreach ($fields as $field) {
                     if (!isset($matches[$field])) {
                         $match = false;
                         break;
                     } else {
                         $where[$field] = $matches[$field];
                     }
                 }
                 if ($match) {
                     $query = strpos($model, '\\') ? $model::where($where) : Loader::model($model)->where($where);
                     $result = $query->failException($exception)->find();
                 }
             }
             if (!empty($result)) {
                 $bind[$key] = $result;
             }
         }
         $request->bind($bind);
     }
     // 解析额外参数
     self::parseUrlParams(empty($paths) ? '' : implode('|', $paths), $matches);
     // 记录匹配的路由信息
     $request->routeInfo(['rule' => $rule, 'route' => $route, 'option' => $option, 'var' => $matches]);
     // 检测路由after行为
     if (!empty($option['after_behavior'])) {
         if ($option['after_behavior'] instanceof \Closure) {
             $result = call_user_func_array($option['after_behavior'], []);
         } else {
             foreach ((array) $option['after_behavior'] as $behavior) {
                 $result = Hook::exec($behavior, '');
                 if (!is_null($result)) {
                     break;
                 }
             }
//.........这里部分代码省略.........
开发者ID:pangPython,项目名称:iNewsCMS,代码行数:101,代码来源:Route.php

示例9: getWeiboStructure

 private function getWeiboStructure($id)
 {
     $weibo = S('weibo_' . $id);
     if (empty($weibo)) {
         $weibo = $this->weiboModel->find($id);
         $canDelete = $this->canDeleteWeibo($id);
         $weibo_data = unserialize($weibo['data']);
         $class_exists = true;
         $type = array('repost', 'feed');
         if (!in_array($weibo['type'], $type)) {
             $class_exists = class_exists('Addons\\Insert' . ucfirst($weibo['type']) . '\\Insert' . ucfirst($weibo['type']) . 'Addon');
         }
         if ($weibo['type'] === 'feed' || $weibo['type'] == '' || !$class_exists) {
             $fetchContent = "<p class='word-wrap'>" . parse_weibo_content($weibo['content']) . "</p>";
         } elseif ($weibo['type'] === 'repost') {
             $result = Hook::exec('Repost', 'fetchRepost', $weibo);
             $fetchContent = $result;
         } else {
             $result = Hook::exec('Insert' . ucfirst($weibo['type']), 'fetch' . ucfirst($weibo['type']), $weibo);
             $fetchContent = $result;
         }
         $weibo = array('id' => intval($weibo['id']), 'content' => strval($weibo['content']), 'create_time' => intval($weibo['create_time']), 'type' => $weibo['type'], 'data' => unserialize($weibo['data']), 'weibo_data' => $weibo_data, 'comment_count' => intval($weibo['comment_count']), 'repost_count' => intval($weibo['repost_count']), 'can_delete' => boolval($canDelete), 'user' => $this->getUserStructure($weibo['uid']), 'is_top' => $weibo['is_top'], 'uid' => $weibo['uid'], 'fetchContent' => $fetchContent, 'from' => $weibo['from']);
         S('weibo_' . $id, $weibo);
     }
     return $weibo;
 }
开发者ID:yaomoo,项目名称:bbs,代码行数:26,代码来源:WeiboApi.class.php

示例10: parseRule

 /**
  * 解析规则路由
  * @access private
  * @param string    $rule 路由规则
  * @param string    $route 路由地址
  * @param string    $pathinfo URL地址
  * @param array     $option 路由参数
  * @param array     $matches 匹配的变量
  * @param bool      $merge 合并额外变量
  * @return array
  */
 private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = [], $merge = false)
 {
     // 检测是否定义路由
     if (!empty($option['after_behavior'])) {
         if ($option['after_behavior'] instanceof \Closure) {
             $result = call_user_func_array($option['after_behavior'], [$route]);
         } else {
             foreach ((array) $option['after_behavior'] as $behavior) {
                 $result = Hook::exec($behavior, '', $route);
                 if (!is_null($result)) {
                     break;
                 }
             }
         }
         // 路由规则重定向
         if ($result instanceof Response) {
             return ['type' => 'response', 'response' => $result, 'params' => $matches];
         } elseif (is_array($result)) {
             return $result;
         }
     }
     // 解析路由规则
     if ($rule) {
         $rule = explode('/', $rule);
         // 获取URL地址中的参数
         $paths = $merge ? explode('/', $pathinfo, count($rule)) : explode('/', $pathinfo);
         foreach ($rule as $item) {
             $fun = '';
             if (0 === strpos($item, '[:')) {
                 $item = substr($item, 1, -1);
             }
             if (0 === strpos($item, ':')) {
                 $var = substr($item, 1);
                 $matches[$var] = array_shift($paths);
             } else {
                 // 过滤URL中的静态变量
                 array_shift($paths);
             }
         }
     } else {
         $paths = explode('/', $pathinfo);
     }
     // 获取路由地址规则
     $url = $route;
     // 替换路由地址中的变量
     if (is_string($url) && !empty($matches)) {
         foreach ($matches as $key => $val) {
             if (false !== strpos($url, ':' . $key)) {
                 $url = str_replace(':' . $key, $val, $url);
                 unset($matches[$key]);
             }
         }
     }
     if ($url instanceof \Closure) {
         // 执行闭包
         $result = ['type' => 'function', 'function' => $url, 'params' => $matches];
     } elseif (0 === strpos($url, '/') || 0 === strpos($url, 'http')) {
         // 路由到重定向地址
         $result = ['type' => 'redirect', 'url' => $url, 'status' => isset($option['status']) ? $option['status'] : 301];
     } elseif (0 === strpos($url, '\\')) {
         // 路由到方法
         $method = strpos($url, '@') ? explode('@', $url) : $url;
         $result = ['type' => 'method', 'method' => $method, 'params' => $matches];
     } elseif (0 === strpos($url, '@')) {
         // 路由到控制器
         $result = ['type' => 'controller', 'controller' => substr($url, 1), 'params' => $matches];
     } else {
         // 路由到模块/控制器/操作
         $result = self::parseModule($url);
     }
     // 解析额外参数
     self::parseUrlParams(empty($paths) ? '' : implode('/', $paths), $matches);
     // 记录匹配的路由信息
     Request::instance()->routeInfo(['rule' => $rule, 'route' => $route, 'option' => $option]);
     return $result;
 }
开发者ID:GDdark,项目名称:cici,代码行数:87,代码来源:Route.php

示例11: addMoreHotWeibo

 /**
  * 加载更多热门微博
  */
 public function addMoreHotWeibo()
 {
     $aPage = I('post.page', 1, 'op_t');
     $aCount = I('post.count', 10, 'op_t');
     $hot_left = modC('HOT_LEFT', 3);
     $time_left = get_some_day($hot_left);
     $time_left = get_some_day($hot_left);
     $param['create_time'] = array('gt', $time_left);
     $param['status'] = 1;
     $param['is_top'] = 0;
     $weibo = D('Weibo')->where(array('status' => 1, $param))->page($aPage, $aCount)->order('comment_count desc')->select();
     $support['appname'] = 'Weibo';
     //查找是否点赞
     $support['table'] = 'weibo';
     $support['uid'] = is_login();
     $is_zan = D('Support')->where($support)->select();
     $is_zan = array_column($is_zan, 'row');
     foreach ($weibo as &$v) {
         $v['user'] = query_user(array('nickname', 'avatar64', 'uid'), $v['uid']);
         $v['rand_title'] = mob_get_head_title($v['uid']);
         $v['support'] = D('Support')->where(array('appname' => 'Weibo', 'table' => 'weibo', 'row' => $v['id']))->count();
         if ($v['type'] === "repost") {
             $v['content'] = A('Mob/WeiboType')->fetchRepost($v);
         } else {
             if ($v['type'] === "xiami" || $v['type'] == "video") {
                 $v['content'] = Hook::exec('Addons\\Insert' . ucfirst($v['type']) . '\\Insert' . ucfirst($v['type']) . 'Addon', 'fetch' . ucfirst($v['type']), $v);
             } else {
                 $v['content'] = parse_weibo_mobile_content($v['content']);
             }
         }
         if (empty($v['from'])) {
             $v['from'] = "网站端";
         }
         $v['data'] = unserialize($v['data']);
         //字符串转换成数组,获取微博源ID
         if ($v['data']['sourceId']) {
             //判断是否是源微博
             $v['sourceId'] = $v['data']['sourceId'];
             $v['is_sourceId'] = '1';
         } else {
             $v['sourceId'] = $v['id'];
             $v['is_sourceId'] = '0';
         }
         $v['sourceId_user'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->find();
         //源微博用户名
         $v['sourceId_user'] = $v['sourceId_user']['uid'];
         $v['sourceId_user'] = query_user(array('nickname', 'uid'), $v['sourceId_user']);
         $v['sourceId_content'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('content')->find();
         //源微博内容
         if (!is_null($v['sourceId_content'])) {
             $v['sourceId_content'] = parse_weibo_mobile_content($v['sourceId_content']['content']);
             //把表情显示出来。
         }
         $v['sourceId_repost_count'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('repost_count')->find();
         //源微博转发数
         $v['sourceId_from'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('from')->find();
         //源微博来源
         if (empty($v['sourceId_from']['from'])) {
             $v['sourceId_from'] = "网站端";
         } else {
             $v['sourceId_from'] = "手机网页版";
         }
         $v['sourceId_img'] = D('Weibo')->where(array('status' => 1, 'id' => $v['sourceId']))->field('data')->find();
         //为了获取源微图片
         $v['sourceId_img'] = unserialize($v['sourceId_img']['data']);
         $v['sourceId_img'] = explode(',', $v['sourceId_img']['attach_ids']);
         //把attach_ids里的图片ID转出来
         foreach ($v['sourceId_img'] as &$b) {
             $v['sourceId_img_path'][] = getThumbImageById($b, 100, 100);
             //获得缩略图
             //获得原图
             $bi = M('Picture')->where(array('status' => 1))->getById($b);
             if (!is_bool(strpos($bi['path'], 'http://'))) {
                 $v['sourceId_img_big'][] = $bi['path'];
             } else {
                 $v['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
             }
         }
         $v['cover_url'] = explode(',', $v['data']['attach_ids']);
         //把attach_ids里的图片ID转出来
         foreach ($v['cover_url'] as &$a) {
             $v['img_path'][] = getThumbImageById($a, 100, 100);
             //获得原图
             $bi = M('Picture')->where(array('status' => 1))->getById($b);
             if (!is_bool(strpos($bi['path'], 'http://'))) {
                 $v['sourceId_img_big'][] = $bi['path'];
             } else {
                 $v['sourceId_img_big'][] = getRootUrl() . substr($bi['path'], 1);
             }
         }
         if (in_array($v['id'], $is_zan)) {
             //判断是否已经点赞
             $v['is_support'] = '1';
         } else {
             $v['is_support'] = '0';
         }
         if (empty($v['data']['attach_ids'])) {
//.........这里部分代码省略.........
开发者ID:ccccy,项目名称:wuanlife,代码行数:101,代码来源:WeiboController.class.php


注:本文中的think\Hook::exec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。