ken\trade
来源:互联网 发布:怎样开通淘宝客 编辑:程序博客网 时间:2024/05/16 15:39
<?phpnamespace ken\trade;use Yii;use yii\base\BootstrapInterface;use yii\web\ForbiddenHttpException;/** * 交易模块 - Ken Trade * * 使用配置 * * ~~~ * return [ * 'bootstrap' => ['ktrade'], * 'modules' => [ * 'ktrade' => [ * 'class' => 'ken\trade\Module', * 'allowedIPs' => ['127.0.0.1', '192.168.*.*'], * ], * ], * ] * ~~~ * * 默认时此模块仅允许在 localhost 上进行访问,也可以通过配置 * [[allowedIPs]] 属性来让其它机器访问. * * 访问地址: `http://localhost/path/to/index.php?r=gii` * * 如果启用url 美化功能 [[\yii\web\UrlManager::enablePrettyUrl|pretty URLs]], * 则访问地址为: `http://localhost/path/to/index.php/gii` * * @author Xiaohan Xu <vb2005xu@qq.com> * @since 2.0 */class Module extends \yii\base\Module implements BootstrapInterface{ /** * @inheritdoc */ public $controllerNamespace = 'ken\trade\controllers'; /** * @var array * * 默认只允许 localhost 访问. * 也可以设置 外网机器访问,例如 ['127.0.0.1', '192.168.*.*'] */ public $allowedIPs = ['127.0.0.1', '::1']; public $allowedHosts = []; /** * @var string 交易日志的目录 */ public $logPath = '@runtime/ktrade'; /** * @var array 对外访问的api列表 */ public $apis = []; /** * @inheritdoc */ public function init() { parent::init(); $this->logPath = Yii::getAlias($this->logPath); } /** * @inheritdoc */ public function bootstrap($app) { $app->getUrlManager()->addRules([ $this->id => $this->id, $this->id . '/<controller:[\w\-]+>/<action:[\w\-]+>' => $this->id . '/<controller>/<action>', ], false); } /** * @inheritdoc */ public function beforeAction($action) { if (!parent::beforeAction($action)) { return false; } if (Yii::$app instanceof \yii\web\Application && !$this->checkAccess()) { throw new ForbiddenHttpException('You are not allowed to access this page.'); } foreach (array_merge($this->coreApis(), $this->apis) as $id => $config) { $this->apis[$id] = Yii::createObject($config); } $this->resetGlobalSettings(); return true; } /** * Resets potentially incompatible global settings done in app config. */ protected function resetGlobalSettings() { if (Yii::$app instanceof \yii\web\Application) { Yii::$app->assetManager->bundles = []; } } /** * @return boolean whether the module can be accessed by the current user */ protected function checkAccess() { $ip = Yii::$app->getRequest()->getUserIP(); foreach ($this->allowedIPs as $filter) { if ($filter === '*' || $filter === $ip || (($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos))) { return true; } } foreach ($this->allowedHosts as $hostname) { $filter = gethostbyname($hostname); if ($filter === $ip) { return true; } } Yii::warning('拒绝访问 kentrade. 请求的 IP 是 ' . $ip, __METHOD__); return false; } /** * 返回 交易模块提供的对外api接口 * @return array * * * */ protected function coreApis() { return [ 'pay' => ['class' => 'ken\trade\apis'], 'pay' => ['class' => 'ken\trade\apis'], ]; }}
0 0
- ken\trade
- trade
- Trade
- Ken Thompson
- Ken Perlin
- Ken Perlin
- Ken Thompson(肯汤普森)
- Ken Thompson的故事
- Ken按照特性设计方法论
- Ken Burns特效的幻灯片
- Ken Burns特效的幻灯片
- Ken Burns特效的幻灯片
- Trade Mark
- HDOJ_1009_FatMouse' Trade
- RQNOJ520 trade
- FatMouse' Trade
- Cross Trade
- FatMouse' Trade
- CSS3制作圆角图片和椭圆形图片
- 皆大欢喜的加薪
- Realm数据库学习之快速入门
- 我承认我手贱: 升级 xcode
- Accp 7.0 第14章 示例5 仅供参考
- ken\trade
- 常用的 js 代码梳理
- [置顶] Windows下DLL编程技术及应用
- Synthesis of Gold Nanorods
- 浅析 Linux 初始化 init 系统,Systemd
- [置顶] EXT/FCKEditor 集成 -- AJAX UI -- 一种web开发的新的思维
- [置顶] ajax实时任务提示功能的实现 -- vb2005xu自己动手系列(1)
- T4模版引擎之基础入门
- [置顶] 网站浏览统计功能的简单实现-- vb2005xu自己动手系列(2)