repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
callmez/yii2-wechat
models/Module.php
Module.updateCache
public static function updateCache($cacheKey = self::CACHE_MODULES_DATA_DEPENDENCY_TAG) { $cache = Yii::$app->get(static::getDb()->queryCache, false); if ($cache instanceof Cache) { TagDependency::invalidate($cache, $cacheKey); } }
php
public static function updateCache($cacheKey = self::CACHE_MODULES_DATA_DEPENDENCY_TAG) { $cache = Yii::$app->get(static::getDb()->queryCache, false); if ($cache instanceof Cache) { TagDependency::invalidate($cache, $cacheKey); } }
[ "public", "static", "function", "updateCache", "(", "$", "cacheKey", "=", "self", "::", "CACHE_MODULES_DATA_DEPENDENCY_TAG", ")", "{", "$", "cache", "=", "Yii", "::", "$", "app", "->", "get", "(", "static", "::", "getDb", "(", ")", "->", "queryCache", ",",...
更新列表数据缓存 @see callmez\wechat\Module::addonModules() @param $cacheKey
[ "更新列表数据缓存" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Module.php#L201-L207
callmez/yii2-wechat
models/Module.php
Module.migration
protected function migration($type) { $class = ModuleHelper::getBaseNamespace($this) . '\migrations\WechatMigration'; if (!class_exists($class)) { // 卸载如果迁移文件不存在也直接返回迁移成功(防止卸载失败) if ($type == self::MIGRATION_UNINSTALL) { return true; } $this->addError('migration', '模块迁移文件不存在'); return false; } $migration = Yii::createObject([ 'class' => $class, 'module' => $this ]); switch ($type) { case self::MIGRATION_INSTALL: $result = $migration->up(); break; case self::MIGRATION_UNINSTALL: $result = $migration->down(); break; case self::MIGRATION_UPGRADE: $result = $migration->to($this->getOldAttribute('version'), $this->getAttribute('version')); break; default: throw new InvalidParamException("Migration type does not support '{$type}'."); } if ($result === false) { $this->addError('migration', '模块迁移脚本执行失败'); return false; } return true; }
php
protected function migration($type) { $class = ModuleHelper::getBaseNamespace($this) . '\migrations\WechatMigration'; if (!class_exists($class)) { // 卸载如果迁移文件不存在也直接返回迁移成功(防止卸载失败) if ($type == self::MIGRATION_UNINSTALL) { return true; } $this->addError('migration', '模块迁移文件不存在'); return false; } $migration = Yii::createObject([ 'class' => $class, 'module' => $this ]); switch ($type) { case self::MIGRATION_INSTALL: $result = $migration->up(); break; case self::MIGRATION_UNINSTALL: $result = $migration->down(); break; case self::MIGRATION_UPGRADE: $result = $migration->to($this->getOldAttribute('version'), $this->getAttribute('version')); break; default: throw new InvalidParamException("Migration type does not support '{$type}'."); } if ($result === false) { $this->addError('migration', '模块迁移脚本执行失败'); return false; } return true; }
[ "protected", "function", "migration", "(", "$", "type", ")", "{", "$", "class", "=", "ModuleHelper", "::", "getBaseNamespace", "(", "$", "this", ")", ".", "'\\migrations\\WechatMigration'", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", ...
执行模块迁移(安装,升级,卸载)脚本 @param $type @return bool
[ "执行模块迁移", "(", "安装", "升级", "卸载", ")", "脚本" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Module.php#L214-L247
callmez/yii2-wechat
models/Module.php
Module.checkType
public function checkType($attribute, $params) { // 核心模块的优先级最高 if (file_exists(Yii::getAlias(WechatModule::CORE_MODULE_PATH . '/' . $this->id . '/wechat.yml'))) { $type = self::TYPE_CORE; } else { $type = self::TYPE_ADDON; } if ($this->$attribute != $type) { return $this->addError($attribute, '模块类型匹配错误'); } }
php
public function checkType($attribute, $params) { // 核心模块的优先级最高 if (file_exists(Yii::getAlias(WechatModule::CORE_MODULE_PATH . '/' . $this->id . '/wechat.yml'))) { $type = self::TYPE_CORE; } else { $type = self::TYPE_ADDON; } if ($this->$attribute != $type) { return $this->addError($attribute, '模块类型匹配错误'); } }
[ "public", "function", "checkType", "(", "$", "attribute", ",", "$", "params", ")", "{", "// 核心模块的优先级最高", "if", "(", "file_exists", "(", "Yii", "::", "getAlias", "(", "WechatModule", "::", "CORE_MODULE_PATH", ".", "'/'", ".", "$", "this", "->", "id", ".", ...
根据模块的存放路径判断模块的类型
[ "根据模块的存放路径判断模块的类型" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Module.php#L280-L291
callmez/yii2-wechat
models/Module.php
Module.models
public static function models() { $cache = Yii::$app->cache; if (($modules = $cache->get(self::CACHE_MODULES_DATA)) === false) { $modules = static::find()->indexBy('id')->asArray()->all(); $cache->set(self::CACHE_MODULES_DATA, $modules, null, new TagDependency([ 'tags' => [self::CACHE_MODULES_DATA_DEPENDENCY_TAG] ])); } return $modules; }
php
public static function models() { $cache = Yii::$app->cache; if (($modules = $cache->get(self::CACHE_MODULES_DATA)) === false) { $modules = static::find()->indexBy('id')->asArray()->all(); $cache->set(self::CACHE_MODULES_DATA, $modules, null, new TagDependency([ 'tags' => [self::CACHE_MODULES_DATA_DEPENDENCY_TAG] ])); } return $modules; }
[ "public", "static", "function", "models", "(", ")", "{", "$", "cache", "=", "Yii", "::", "$", "app", "->", "cache", ";", "if", "(", "(", "$", "modules", "=", "$", "cache", "->", "get", "(", "self", "::", "CACHE_MODULES_DATA", ")", ")", "===", "fals...
模块数据列表缓存 该数据只会返回数组形态模块数据,用于频繁操作(提高效率)的逻辑处理部分 @return array|mixed|\yii\db\ActiveRecord[]
[ "模块数据列表缓存", "该数据只会返回数组形态模块数据", "用于频繁操作", "(", "提高效率", ")", "的逻辑处理部分" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Module.php#L298-L308
callmez/yii2-wechat
models/Wechat.php
Wechat.getApiUrl
public function getApiUrl($scheme = true) { return Url::toRoute([ '/wechat/' . Yii::$app->getModule('wechat')->apiRoute, 'id' => $this->id ], $scheme); }
php
public function getApiUrl($scheme = true) { return Url::toRoute([ '/wechat/' . Yii::$app->getModule('wechat')->apiRoute, 'id' => $this->id ], $scheme); }
[ "public", "function", "getApiUrl", "(", "$", "scheme", "=", "true", ")", "{", "return", "Url", "::", "toRoute", "(", "[", "'/wechat/'", ".", "Yii", "::", "$", "app", "->", "getModule", "(", "'wechat'", ")", "->", "apiRoute", ",", "'id'", "=>", "$", "...
返回公众号微信接口链接 @param boolean|string $scheme the URI scheme to use in the generated URL: @return string
[ "返回公众号微信接口链接" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Wechat.php#L153-L159
callmez/yii2-wechat
models/Wechat.php
Wechat.getSdk
public function getSdk() { if ($this->_sdk === null) { $this->_sdk = Yii::createObject(MpWechat::className(), [$this]); } return $this->_sdk; }
php
public function getSdk() { if ($this->_sdk === null) { $this->_sdk = Yii::createObject(MpWechat::className(), [$this]); } return $this->_sdk; }
[ "public", "function", "getSdk", "(", ")", "{", "if", "(", "$", "this", "->", "_sdk", "===", "null", ")", "{", "$", "this", "->", "_sdk", "=", "Yii", "::", "createObject", "(", "MpWechat", "::", "className", "(", ")", ",", "[", "$", "this", "]", "...
获取实例化后的公众号SDK类 @return mixed|object
[ "获取实例化后的公众号SDK类" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Wechat.php#L170-L176
callmez/yii2-wechat
models/Message.php
Message.send
public function send($runValidation = true) { if ($runValidation && !$this->validate()) { return false; } $method = 'send' . $this->msgType; if (!method_exists($this, $method)) { $this->addError('msgType', '未找到指定发送方法'); return false; } $result = call_user_func([$this, $method]); if (!$result) { $this->addError('msgType', json_encode($this->wechat->getSdk()->lastError)); } return $result; }
php
public function send($runValidation = true) { if ($runValidation && !$this->validate()) { return false; } $method = 'send' . $this->msgType; if (!method_exists($this, $method)) { $this->addError('msgType', '未找到指定发送方法'); return false; } $result = call_user_func([$this, $method]); if (!$result) { $this->addError('msgType', json_encode($this->wechat->getSdk()->lastError)); } return $result; }
[ "public", "function", "send", "(", "$", "runValidation", "=", "true", ")", "{", "if", "(", "$", "runValidation", "&&", "!", "$", "this", "->", "validate", "(", ")", ")", "{", "return", "false", ";", "}", "$", "method", "=", "'send'", ".", "$", "thi...
发送消息 @param bool $runValidation @return bool
[ "发送消息" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Message.php#L144-L159
callmez/yii2-wechat
models/WechatSearch.php
WechatSearch.search
public function search($params) { $query = Wechat::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'type' => $this->type, 'status' => $this->status, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'token', $this->token]) ->andFilterWhere(['like', 'access_token', $this->access_token]) ->andFilterWhere(['like', 'account', $this->account]) ->andFilterWhere(['like', 'original', $this->original]) ->andFilterWhere(['like', 'key', $this->key]) ->andFilterWhere(['like', 'secret', $this->secret]) ->andFilterWhere(['like', 'encoding_aes_key', $this->encoding_aes_key]) ->andFilterWhere(['like', 'avatar', $this->avatar]) ->andFilterWhere(['like', 'qrcode', $this->qrcode]) ->andFilterWhere(['like', 'address', $this->address]) ->andFilterWhere(['like', 'description', $this->description]) ->andFilterWhere(['like', 'username', $this->username]) ->andFilterWhere(['like', 'password', $this->password]); return $dataProvider; }
php
public function search($params) { $query = Wechat::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'type' => $this->type, 'status' => $this->status, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'token', $this->token]) ->andFilterWhere(['like', 'access_token', $this->access_token]) ->andFilterWhere(['like', 'account', $this->account]) ->andFilterWhere(['like', 'original', $this->original]) ->andFilterWhere(['like', 'key', $this->key]) ->andFilterWhere(['like', 'secret', $this->secret]) ->andFilterWhere(['like', 'encoding_aes_key', $this->encoding_aes_key]) ->andFilterWhere(['like', 'avatar', $this->avatar]) ->andFilterWhere(['like', 'qrcode', $this->qrcode]) ->andFilterWhere(['like', 'address', $this->address]) ->andFilterWhere(['like', 'description', $this->description]) ->andFilterWhere(['like', 'username', $this->username]) ->andFilterWhere(['like', 'password', $this->password]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "Wechat", "::", "find", "(", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "this", ...
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/WechatSearch.php#L38-L76
callmez/yii2-wechat
widgets/CategoryMenu.php
CategoryMenu.registerPlugin
protected function registerPlugin($name) { $view = $this->getView(); BootstrapPluginAsset::register($view); $id = $this->options['id']; $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); $js = "jQuery('#$id').$name($options);"; $view->registerJs($js); }
php
protected function registerPlugin($name) { $view = $this->getView(); BootstrapPluginAsset::register($view); $id = $this->options['id']; $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions); $js = "jQuery('#$id').$name($options);"; $view->registerJs($js); }
[ "protected", "function", "registerPlugin", "(", "$", "name", ")", "{", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "BootstrapPluginAsset", "::", "register", "(", "$", "view", ")", ";", "$", "id", "=", "$", "this", "->", "options", ...
Registers a specific Bootstrap plugin and the related events @param string $name the name of the Bootstrap plugin
[ "Registers", "a", "specific", "Bootstrap", "plugin", "and", "the", "related", "events" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/widgets/CategoryMenu.php#L147-L158
callmez/yii2-wechat
models/MediaForm.php
MediaForm.checkFile
public function checkFile($attribute, $params) { // 按照类型 验证上传 switch ($this->type) { case Media::TYPE_IMAGE: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 1048576]; // 1MB break; case Media::TYPE_THUMB: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 524288]; // 64KB break; case Media::TYPE_VOICE: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'amr, mp3', 'maxSize' => 2097152]; // 2MB break; case Media::TYPE_VIDEO: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'mp4', 'maxSize' => 10485760]; // 10MB break; default: return ; } $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2)); $validator->validateAttributes($this); }
php
public function checkFile($attribute, $params) { // 按照类型 验证上传 switch ($this->type) { case Media::TYPE_IMAGE: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 1048576]; // 1MB break; case Media::TYPE_THUMB: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg', 'maxSize' => 524288]; // 64KB break; case Media::TYPE_VOICE: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'amr, mp3', 'maxSize' => 2097152]; // 2MB break; case Media::TYPE_VIDEO: $rule = [[$attribute], 'file', 'skipOnEmpty' => false, 'extensions' => 'mp4', 'maxSize' => 10485760]; // 10MB break; default: return ; } $validator = Validator::createValidator($rule[1], $this, (array) $rule[0], array_slice($rule, 2)); $validator->validateAttributes($this); }
[ "public", "function", "checkFile", "(", "$", "attribute", ",", "$", "params", ")", "{", "// 按照类型 验证上传", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "Media", "::", "TYPE_IMAGE", ":", "$", "rule", "=", "[", "[", "$", "attribute", "]", "...
各类型上传文件验证 @param $attribute @param $params
[ "各类型上传文件验证" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/MediaForm.php#L65-L86
callmez/yii2-wechat
controllers/FansController.php
FansController.actionIndex
public function actionIndex() { $searchModel = new FansSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, true); $dataProvider->query->andWhere(['wid' => $this->getWechat()->id]); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
php
public function actionIndex() { $searchModel = new FansSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, true); $dataProvider->query->andWhere(['wid' => $this->getWechat()->id]); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionIndex", "(", ")", "{", "$", "searchModel", "=", "new", "FansSearch", "(", ")", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "Yii", "::", "$", "app", "->", "request", "->", "queryParams", ",", "true"...
Lists all Fans models. @return mixed
[ "Lists", "all", "Fans", "models", "." ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/FansController.php#L23-L33
callmez/yii2-wechat
controllers/FansController.php
FansController.actionMessage
public function actionMessage($id) { $model = $this->findModel($id); $message = new Message($this->getWechat()); if ($message->load(Yii::$app->request->post())) { $message->toUser = $model->open_id; if ($message->send()) { $this->flash('消息发送成功!', 'success'); $message = new Message($this->getWechat()); } } $message->toUser = $model->open_id; $searchModel = new MessageHistorySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); // $dataProvider->sort = [ // 'defaultOrder' => ['created_at' => SORT_DESC] // ]; $dataProvider->query ->wechat($this->getWechat()->id) ->wechatFans($model->open_id, $this->getWechat()->original); return $this->render('message', [ 'model' => $model, 'message' => $message, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
php
public function actionMessage($id) { $model = $this->findModel($id); $message = new Message($this->getWechat()); if ($message->load(Yii::$app->request->post())) { $message->toUser = $model->open_id; if ($message->send()) { $this->flash('消息发送成功!', 'success'); $message = new Message($this->getWechat()); } } $message->toUser = $model->open_id; $searchModel = new MessageHistorySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); // $dataProvider->sort = [ // 'defaultOrder' => ['created_at' => SORT_DESC] // ]; $dataProvider->query ->wechat($this->getWechat()->id) ->wechatFans($model->open_id, $this->getWechat()->original); return $this->render('message', [ 'model' => $model, 'message' => $message, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionMessage", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "message", "=", "new", "Message", "(", "$", "this", "->", "getWechat", "(", ")", ")", ";", "if", "(...
用户查看 @param $id @return string @throws NotFoundHttpException
[ "用户查看" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/FansController.php#L41-L70
callmez/yii2-wechat
controllers/FansController.php
FansController.actionUpload
public function actionUpload($id) { $model = $this->findModel($id); if (isset($_FILES[$model->formName()]['name'])) { foreach ($_POST[$model->formName()] as $attribute => $value) { $uploadedFile = UploadedFile::getInstance($model, $attribute); if ($uploadedFile === null) { continue; } elseif ($uploadedFile->error == UPLOAD_ERR_OK) { // $this->getWechat()->getSdk()->uploadMedia($this->tempName, ); } } } return $this->message('上传失败', 'error'); }
php
public function actionUpload($id) { $model = $this->findModel($id); if (isset($_FILES[$model->formName()]['name'])) { foreach ($_POST[$model->formName()] as $attribute => $value) { $uploadedFile = UploadedFile::getInstance($model, $attribute); if ($uploadedFile === null) { continue; } elseif ($uploadedFile->error == UPLOAD_ERR_OK) { // $this->getWechat()->getSdk()->uploadMedia($this->tempName, ); } } } return $this->message('上传失败', 'error'); }
[ "public", "function", "actionUpload", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "if", "(", "isset", "(", "$", "_FILES", "[", "$", "model", "->", "formName", "(", ")", "]", "[", "'name'"...
上传素材 @param $id @throws NotFoundHttpException
[ "上传素材" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/FansController.php#L77-L91
callmez/yii2-wechat
controllers/FansController.php
FansController.findModel
protected function findModel($id) { $query = Fans::find() ->andWhere([ 'id' => $id, 'wid' => $this->getWechat()->id ]); if (($model = $query->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
php
protected function findModel($id) { $query = Fans::find() ->andWhere([ 'id' => $id, 'wid' => $this->getWechat()->id ]); if (($model = $query->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
[ "protected", "function", "findModel", "(", "$", "id", ")", "{", "$", "query", "=", "Fans", "::", "find", "(", ")", "->", "andWhere", "(", "[", "'id'", "=>", "$", "id", ",", "'wid'", "=>", "$", "this", "->", "getWechat", "(", ")", "->", "id", "]",...
Finds the Fans model based on its primary key value. If the model is not found, a 404 HTTP exception will be thrown. @param integer $id @return Fans the loaded model @throws NotFoundHttpException if the model cannot be found
[ "Finds", "the", "Fans", "model", "based", "on", "its", "primary", "key", "value", ".", "If", "the", "model", "is", "not", "found", "a", "404", "HTTP", "exception", "will", "be", "thrown", "." ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/FansController.php#L119-L131
callmez/yii2-wechat
helpers/ModuleHelper.php
ModuleHelper.getApiUrl
public static function getApiUrl(Wechat $wechat, array $params = [], $scheme = false) { $token = $wechat->token; $nonce = Yii::$app->security->generateRandomString(5); $signArray = [$token, TIMESTAMP, $nonce]; sort($signArray, SORT_STRING); $signature = sha1(implode($signArray)); return Url::to(array_merge([ '/wechat/' . Yii::$app->getModule('wechat')->apiRoute, 'timestamp' => TIMESTAMP, 'nonce' => $nonce, 'signature' => $signature ], $params), $scheme); }
php
public static function getApiUrl(Wechat $wechat, array $params = [], $scheme = false) { $token = $wechat->token; $nonce = Yii::$app->security->generateRandomString(5); $signArray = [$token, TIMESTAMP, $nonce]; sort($signArray, SORT_STRING); $signature = sha1(implode($signArray)); return Url::to(array_merge([ '/wechat/' . Yii::$app->getModule('wechat')->apiRoute, 'timestamp' => TIMESTAMP, 'nonce' => $nonce, 'signature' => $signature ], $params), $scheme); }
[ "public", "static", "function", "getApiUrl", "(", "Wechat", "$", "wechat", ",", "array", "$", "params", "=", "[", "]", ",", "$", "scheme", "=", "false", ")", "{", "$", "token", "=", "$", "wechat", "->", "token", ";", "$", "nonce", "=", "Yii", "::",...
获取API接口地址 @param Wechat $wechat 公众号 @param array $params 补充的参数 @param bool $scheme 完整地址,或者其他协议完整地址 @return string
[ "获取API接口地址" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/helpers/ModuleHelper.php#L23-L36
callmez/yii2-wechat
helpers/ModuleHelper.php
ModuleHelper.getBaseNamespace
public static function getBaseNamespace($module) { $type = ArrayHelper::getValue($module, 'type'); $id = ArrayHelper::getValue($module, 'id'); if ($type && $id) { $path = $type == ModuleModel::TYPE_ADDON ? Module::ADDON_MODULE_PATH : Module::CORE_MODULE_PATH; return str_replace('/', '\\', ltrim($path, '@')) . '\\' . $id; } return false; }
php
public static function getBaseNamespace($module) { $type = ArrayHelper::getValue($module, 'type'); $id = ArrayHelper::getValue($module, 'id'); if ($type && $id) { $path = $type == ModuleModel::TYPE_ADDON ? Module::ADDON_MODULE_PATH : Module::CORE_MODULE_PATH; return str_replace('/', '\\', ltrim($path, '@')) . '\\' . $id; } return false; }
[ "public", "static", "function", "getBaseNamespace", "(", "$", "module", ")", "{", "$", "type", "=", "ArrayHelper", "::", "getValue", "(", "$", "module", ",", "'type'", ")", ";", "$", "id", "=", "ArrayHelper", "::", "getValue", "(", "$", "module", ",", ...
获取扩展模块基本命名空间 @param Module|array $module @return bool|string
[ "获取扩展模块基本命名空间" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/helpers/ModuleHelper.php#L63-L72
callmez/yii2-wechat
helpers/ModuleHelper.php
ModuleHelper.findAvailableModuleById
public static function findAvailableModuleById($id) { $availableModels = static::findAvailableModules(); return array_key_exists($id, $availableModels) ? $availableModels[$id] : null; }
php
public static function findAvailableModuleById($id) { $availableModels = static::findAvailableModules(); return array_key_exists($id, $availableModels) ? $availableModels[$id] : null; }
[ "public", "static", "function", "findAvailableModuleById", "(", "$", "id", ")", "{", "$", "availableModels", "=", "static", "::", "findAvailableModules", "(", ")", ";", "return", "array_key_exists", "(", "$", "id", ",", "$", "availableModels", ")", "?", "$", ...
根据ID查找可用的模块 @param $id @return null
[ "根据ID查找可用的模块" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/helpers/ModuleHelper.php#L79-L83
callmez/yii2-wechat
helpers/ModuleHelper.php
ModuleHelper.scanAvailableModules
protected static function scanAvailableModules($paths) { if (!is_array($paths)) { $paths = [$paths]; } $modules = []; foreach ($paths as $path) { $path = Yii::getAlias($path); if (is_dir($path) && (($handle = opendir($path)) !== false)) { while (($file = readdir($handle)) !== false) { if (in_array($file, ['.', '..']) || !is_dir($currentPath = $path . DIRECTORY_SEPARATOR . $file)) { continue; } // 是否有wechat.yml安装配置文件 $settingFile = $currentPath . DIRECTORY_SEPARATOR . 'wechat.yml'; if (file_exists($settingFile)) { $class = Yii::$app->getModule('wechat')->moduleModelClass; $model = new $class; $model->setAttributes(Yaml::parse(file_get_contents($settingFile))); if ($model->id == $file && $model->validate()) { // 模块名必须等于目录名并且验证模块正确性 $modules[$model->id] = $model; } } } } } return $modules; }
php
protected static function scanAvailableModules($paths) { if (!is_array($paths)) { $paths = [$paths]; } $modules = []; foreach ($paths as $path) { $path = Yii::getAlias($path); if (is_dir($path) && (($handle = opendir($path)) !== false)) { while (($file = readdir($handle)) !== false) { if (in_array($file, ['.', '..']) || !is_dir($currentPath = $path . DIRECTORY_SEPARATOR . $file)) { continue; } // 是否有wechat.yml安装配置文件 $settingFile = $currentPath . DIRECTORY_SEPARATOR . 'wechat.yml'; if (file_exists($settingFile)) { $class = Yii::$app->getModule('wechat')->moduleModelClass; $model = new $class; $model->setAttributes(Yaml::parse(file_get_contents($settingFile))); if ($model->id == $file && $model->validate()) { // 模块名必须等于目录名并且验证模块正确性 $modules[$model->id] = $model; } } } } } return $modules; }
[ "protected", "static", "function", "scanAvailableModules", "(", "$", "paths", ")", "{", "if", "(", "!", "is_array", "(", "$", "paths", ")", ")", "{", "$", "paths", "=", "[", "$", "paths", "]", ";", "}", "$", "modules", "=", "[", "]", ";", "foreach"...
扫描可用的插件模块 该方法是严格按照Yii的模块路径规则(比如@app/modules, @app/mdoules/example/modules)来查找模块 如果您的模块有特殊路径需求. 可能正确安装不了, 建议按照规则设计扩展模块 @param array|string $paths @return array
[ "扫描可用的插件模块" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/helpers/ModuleHelper.php#L103-L130
callmez/yii2-wechat
models/MessageHistory.php
MessageHistory.add
public static function add(array $data) { $model = Yii::createObject(static::className()); $model->setAttributes($data); return $model->save() ?: $model; }
php
public static function add(array $data) { $model = Yii::createObject(static::className()); $model->setAttributes($data); return $model->save() ?: $model; }
[ "public", "static", "function", "add", "(", "array", "$", "data", ")", "{", "$", "model", "=", "Yii", "::", "createObject", "(", "static", "::", "className", "(", ")", ")", ";", "$", "model", "->", "setAttributes", "(", "$", "data", ")", ";", "return...
快速添加记录 @param array $data @return bool|object 错误将返回model类
[ "快速添加记录" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/MessageHistory.php#L106-L111
callmez/yii2-wechat
helpers/User.php
User.can
public static function can($permissionName, $params = [], $allowCaching = true) { $user = Yii::$app->user; $adminId = (array) Yii::$app->getModule('wechat')->adminId; return in_array($user->getId(), $adminId) || $user->can($permissionName, $params, $allowCaching); }
php
public static function can($permissionName, $params = [], $allowCaching = true) { $user = Yii::$app->user; $adminId = (array) Yii::$app->getModule('wechat')->adminId; return in_array($user->getId(), $adminId) || $user->can($permissionName, $params, $allowCaching); }
[ "public", "static", "function", "can", "(", "$", "permissionName", ",", "$", "params", "=", "[", "]", ",", "$", "allowCaching", "=", "true", ")", "{", "$", "user", "=", "Yii", "::", "$", "app", "->", "user", ";", "$", "adminId", "=", "(", "array", ...
微信操作权限判断 增加微信管理员ID判断 @see yii\wechat\User::can() @return bool
[ "微信操作权限判断", "增加微信管理员ID判断" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/helpers/User.php#L19-L24
callmez/yii2-wechat
helpers/Request.php
Request.isAjax
public static function isAjax() { $request = Yii::$app->request; return (bool) $request->get(self::QUEYR_PARAM_AJAX, $request->getIsAjax()); }
php
public static function isAjax() { $request = Yii::$app->request; return (bool) $request->get(self::QUEYR_PARAM_AJAX, $request->getIsAjax()); }
[ "public", "static", "function", "isAjax", "(", ")", "{", "$", "request", "=", "Yii", "::", "$", "app", "->", "request", ";", "return", "(", "bool", ")", "$", "request", "->", "get", "(", "self", "::", "QUEYR_PARAM_AJAX", ",", "$", "request", "->", "g...
是否ajax请求 @return bool
[ "是否ajax请求" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/helpers/Request.php#L18-L22
callmez/yii2-wechat
models/Fans.php
Fans.updateUser
public function updateUser($force = false) { $user = $this->user; if (!$user || $force) { $wechat = $this->wechat; $user = new MpUser(); $this->populateRelation('user',$user); $data = $wechat->getSdk()->getUserInfo($this->open_id); if ($data) { $user->setAttributes([ 'id' => $this->id, 'nickname' => $data['nickname'], 'sex' => $data['sex'], 'city' => $data['city'], 'country' => $data['country'], 'province' => $data['province'], 'language' => $data['language'], 'avatar' => $data['headimgurl'], 'subscribe_time' => $data['subscribe_time'], 'remark' => $data['remark'], 'union_id' => isset($data['unionid']) ? $data['unionid'] : '', // 测试号无此项 'group_id' => $data['groupid'], ]); return $user->save(); } $user->addError('id', '用户资料更新失败!'); return false; } return true; }
php
public function updateUser($force = false) { $user = $this->user; if (!$user || $force) { $wechat = $this->wechat; $user = new MpUser(); $this->populateRelation('user',$user); $data = $wechat->getSdk()->getUserInfo($this->open_id); if ($data) { $user->setAttributes([ 'id' => $this->id, 'nickname' => $data['nickname'], 'sex' => $data['sex'], 'city' => $data['city'], 'country' => $data['country'], 'province' => $data['province'], 'language' => $data['language'], 'avatar' => $data['headimgurl'], 'subscribe_time' => $data['subscribe_time'], 'remark' => $data['remark'], 'union_id' => isset($data['unionid']) ? $data['unionid'] : '', // 测试号无此项 'group_id' => $data['groupid'], ]); return $user->save(); } $user->addError('id', '用户资料更新失败!'); return false; } return true; }
[ "public", "function", "updateUser", "(", "$", "force", "=", "false", ")", "{", "$", "user", "=", "$", "this", "->", "user", ";", "if", "(", "!", "$", "user", "||", "$", "force", ")", "{", "$", "wechat", "=", "$", "this", "->", "wechat", ";", "$...
更新用户微信数据 更新失败将会在$this->user->getErrors()中记录错误 @param bool $force @return bool
[ "更新用户微信数据", "更新失败将会在$this", "-", ">", "user", "-", ">", "getErrors", "()", "中记录错误" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/Fans.php#L136-L165
callmez/yii2-wechat
models/MessageHistorySearch.php
MessageHistorySearch.search
public function search($params) { $query = MessageHistory::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'wid' => $this->wid, 'rid' => $this->rid, 'kid' => $this->kid, 'created_at' => $this->created_at, ]); $query->andFilterWhere(['like', 'from', $this->from]) ->andFilterWhere(['like', 'to', $this->to]) ->andFilterWhere(['like', 'module', $this->module]) ->andFilterWhere(['like', 'message', $this->message]) ->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
php
public function search($params) { $query = MessageHistory::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'wid' => $this->wid, 'rid' => $this->rid, 'kid' => $this->kid, 'created_at' => $this->created_at, ]); $query->andFilterWhere(['like', 'from', $this->from]) ->andFilterWhere(['like', 'to', $this->to]) ->andFilterWhere(['like', 'module', $this->module]) ->andFilterWhere(['like', 'message', $this->message]) ->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "MessageHistory", "::", "find", "(", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "...
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/MessageHistorySearch.php#L42-L73
callmez/yii2-wechat
components/BaseModule.php
BaseModule.getAdminMenus
public function getAdminMenus() { if ($this->_adminMenus === null) { $this->setAdminMenus(array_merge($this->defaultAdminMenus(), $this->adminMenus())); } return $this->_adminMenus; }
php
public function getAdminMenus() { if ($this->_adminMenus === null) { $this->setAdminMenus(array_merge($this->defaultAdminMenus(), $this->adminMenus())); } return $this->_adminMenus; }
[ "public", "function", "getAdminMenus", "(", ")", "{", "if", "(", "$", "this", "->", "_adminMenus", "===", "null", ")", "{", "$", "this", "->", "setAdminMenus", "(", "array_merge", "(", "$", "this", "->", "defaultAdminMenus", "(", ")", ",", "$", "this", ...
获取后台菜单 @return mixed|null
[ "获取后台菜单" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/BaseModule.php#L25-L31
callmez/yii2-wechat
components/BaseModule.php
BaseModule.getModuleModel
public function getModuleModel() { if ($this->_moduleModel === null) { // 默认根据缓存的模块数据生成模块model $class = $this->module->moduleModelClass; $model = new $class; $class::populateRecord($model, ModuleModel::models()[$this->id]); $this->setModuleModel($model); } return $this->_moduleModel; }
php
public function getModuleModel() { if ($this->_moduleModel === null) { // 默认根据缓存的模块数据生成模块model $class = $this->module->moduleModelClass; $model = new $class; $class::populateRecord($model, ModuleModel::models()[$this->id]); $this->setModuleModel($model); } return $this->_moduleModel; }
[ "public", "function", "getModuleModel", "(", ")", "{", "if", "(", "$", "this", "->", "_moduleModel", "===", "null", ")", "{", "// 默认根据缓存的模块数据生成模块model", "$", "class", "=", "$", "this", "->", "module", "->", "moduleModelClass", ";", "$", "model", "=", "new"...
获取模块Model @return mixed|null
[ "获取模块Model" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/BaseModule.php#L51-L61
callmez/yii2-wechat
components/AdminController.php
AdminController.setWechat
public function setWechat(Wechat $wechat) { Yii::$app->session->set(self::SESSION_MANAGE_WECHAT_KEY, $wechat->id); $this->_wechat = $wechat; }
php
public function setWechat(Wechat $wechat) { Yii::$app->session->set(self::SESSION_MANAGE_WECHAT_KEY, $wechat->id); $this->_wechat = $wechat; }
[ "public", "function", "setWechat", "(", "Wechat", "$", "wechat", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "set", "(", "self", "::", "SESSION_MANAGE_WECHAT_KEY", ",", "$", "wechat", "->", "id", ")", ";", "$", "this", "->", "_wechat", "=...
设置当前需要管理的公众号 @param Wechat $wechat
[ "设置当前需要管理的公众号" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/AdminController.php#L66-L70
callmez/yii2-wechat
components/AdminController.php
AdminController.getWechat
public function getWechat() { if ($this->_wechat === null) { $wid = Yii::$app->session->get(self::SESSION_MANAGE_WECHAT_KEY); if (!$wid || ($wechat = Wechat::findOne($wid)) === null) { return false; } $this->setWechat($wechat); } return $this->_wechat; }
php
public function getWechat() { if ($this->_wechat === null) { $wid = Yii::$app->session->get(self::SESSION_MANAGE_WECHAT_KEY); if (!$wid || ($wechat = Wechat::findOne($wid)) === null) { return false; } $this->setWechat($wechat); } return $this->_wechat; }
[ "public", "function", "getWechat", "(", ")", "{", "if", "(", "$", "this", "->", "_wechat", "===", "null", ")", "{", "$", "wid", "=", "Yii", "::", "$", "app", "->", "session", "->", "get", "(", "self", "::", "SESSION_MANAGE_WECHAT_KEY", ")", ";", "if"...
获取当前管理的公众号 @return Wechat|null @throws InvalidConfigException
[ "获取当前管理的公众号" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/AdminController.php#L77-L87
callmez/yii2-wechat
components/ProcessController.php
ProcessController.getFans
public function getFans() { if ($this->_fans === false) { $this->_fans = Fans::findByOpenId($this->message['FromUserName']); } return $this->_fans; }
php
public function getFans() { if ($this->_fans === false) { $this->_fans = Fans::findByOpenId($this->message['FromUserName']); } return $this->_fans; }
[ "public", "function", "getFans", "(", ")", "{", "if", "(", "$", "this", "->", "_fans", "===", "false", ")", "{", "$", "this", "->", "_fans", "=", "Fans", "::", "findByOpenId", "(", "$", "this", "->", "message", "[", "'FromUserName'", "]", ")", ";", ...
获取触发微信请求的微信用户信息 @return Fans
[ "获取触发微信请求的微信用户信息" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/ProcessController.php#L61-L67
callmez/yii2-wechat
components/ProcessController.php
ProcessController.responseNews
public function responseNews(array $articles) { if (isset($articles['title'])) { $articles = [$articles]; } $response = [ 'MsgType' => 'news', 'ArticleCount' => count($articles), ]; foreach ($articles as $article) { $response['Articles'][] = [ 'Title' => $article['title'], 'Description' => $article['description'], 'PicUrl' => $article['picUrl'], 'Url' => $article['url'] ]; } return $response; }
php
public function responseNews(array $articles) { if (isset($articles['title'])) { $articles = [$articles]; } $response = [ 'MsgType' => 'news', 'ArticleCount' => count($articles), ]; foreach ($articles as $article) { $response['Articles'][] = [ 'Title' => $article['title'], 'Description' => $article['description'], 'PicUrl' => $article['picUrl'], 'Url' => $article['url'] ]; } return $response; }
[ "public", "function", "responseNews", "(", "array", "$", "articles", ")", "{", "if", "(", "isset", "(", "$", "articles", "[", "'title'", "]", ")", ")", "{", "$", "articles", "=", "[", "$", "articles", "]", ";", "}", "$", "response", "=", "[", "'Msg...
响应图文消息 例: $this->responseNews([ [ 'title' => 'test title', 'description' => 'test description', 'picUrl' => 'pic url', 'url' => 'link' ], ... ]); @param array $articles @return array
[ "响应图文消息", "例", ":", "$this", "-", ">", "responseNews", "(", "[", "[", "title", "=", ">", "test", "title", "description", "=", ">", "test", "description", "picUrl", "=", ">", "pic", "url", "url", "=", ">", "link", "]", "...", "]", ")", ";" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/ProcessController.php#L97-L115
callmez/yii2-wechat
components/ProcessController.php
ProcessController.responseMusic
public function responseMusic(array $music) { return [ 'MsgType' => 'music', 'Image' => [ 'Title' => $music['title'], 'Description' => $music['description'], 'MusicUrl' => $music['musicUrl'], 'HQMusicUrl' => isset($music['hqMusicUrl']) ? $music['hqMusicUrl'] : $music['musicUrl'], 'ThumbMediaId' => $music['thumbMid'] ] ]; }
php
public function responseMusic(array $music) { return [ 'MsgType' => 'music', 'Image' => [ 'Title' => $music['title'], 'Description' => $music['description'], 'MusicUrl' => $music['musicUrl'], 'HQMusicUrl' => isset($music['hqMusicUrl']) ? $music['hqMusicUrl'] : $music['musicUrl'], 'ThumbMediaId' => $music['thumbMid'] ] ]; }
[ "public", "function", "responseMusic", "(", "array", "$", "music", ")", "{", "return", "[", "'MsgType'", "=>", "'music'", ",", "'Image'", "=>", "[", "'Title'", "=>", "$", "music", "[", "'title'", "]", ",", "'Description'", "=>", "$", "music", "[", "'desc...
响应音乐消息 例: $this->responseMusic([ 'title' => 'music title', 'description' => 'music description', 'musicUrl' => 'music link', 'hgMusicUrl' => 'HQ music link', // 选填, 'thumbMid' = '123456' ]) @param array $music @return array
[ "响应音乐消息", "例", ":", "$this", "-", ">", "responseMusic", "(", "[", "title", "=", ">", "music", "title", "description", "=", ">", "music", "description", "musicUrl", "=", ">", "music", "link", "hgMusicUrl", "=", ">", "HQ", "music", "link", "//", "选填", "t...
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/ProcessController.php#L185-L197
callmez/yii2-wechat
Module.php
Module.modules
public function modules() { $cache = Yii::$app->cache; if (($modules = $cache->get(self::CACHE_MODULES_DATA)) === false) { $modules = []; $model = $this->moduleModelClass; foreach ($model::models() as $id => $model) { $class = ModuleHelper::getBaseNamespace($model) . '\Module'; if (!ModuleHelper::isAddonModule($class)) { // 扩展模块必须继承BaseModule continue; } $modules[$id] = [ 'class' => $class, 'name' => $model['name'], ]; } $cache->set(self::CACHE_MODULES_DATA, $modules, null, new TagDependency([ 'tags' => [ModuleModel::CACHE_MODULES_DATA_DEPENDENCY_TAG] ])); } return $modules; }
php
public function modules() { $cache = Yii::$app->cache; if (($modules = $cache->get(self::CACHE_MODULES_DATA)) === false) { $modules = []; $model = $this->moduleModelClass; foreach ($model::models() as $id => $model) { $class = ModuleHelper::getBaseNamespace($model) . '\Module'; if (!ModuleHelper::isAddonModule($class)) { // 扩展模块必须继承BaseModule continue; } $modules[$id] = [ 'class' => $class, 'name' => $model['name'], ]; } $cache->set(self::CACHE_MODULES_DATA, $modules, null, new TagDependency([ 'tags' => [ModuleModel::CACHE_MODULES_DATA_DEPENDENCY_TAG] ])); } return $modules; }
[ "public", "function", "modules", "(", ")", "{", "$", "cache", "=", "Yii", "::", "$", "app", "->", "cache", ";", "if", "(", "(", "$", "modules", "=", "$", "cache", "->", "get", "(", "self", "::", "CACHE_MODULES_DATA", ")", ")", "===", "false", ")", ...
获取扩展模块列表 @return array|mixed
[ "获取扩展模块列表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/Module.php#L97-L120
callmez/yii2-wechat
Module.php
Module.setCategories
public function setCategories($categories) { foreach ($categories as $key => $name) { $this->_categories[$key] = $name; } }
php
public function setCategories($categories) { foreach ($categories as $key => $name) { $this->_categories[$key] = $name; } }
[ "public", "function", "setCategories", "(", "$", "categories", ")", "{", "foreach", "(", "$", "categories", "as", "$", "key", "=>", "$", "name", ")", "{", "$", "this", "->", "_categories", "[", "$", "key", "]", "=", "$", "name", ";", "}", "}" ]
设置所有的模块分类 @param array $categories
[ "设置所有的模块分类" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/Module.php#L163-L168
callmez/yii2-wechat
Module.php
Module.getCategory
public function getCategory($key) { return array_key_exists($key, $this->_categories) ? $this->_categories[$key] : null; }
php
public function getCategory($key) { return array_key_exists($key, $this->_categories) ? $this->_categories[$key] : null; }
[ "public", "function", "getCategory", "(", "$", "key", ")", "{", "return", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "_categories", ")", "?", "$", "this", "->", "_categories", "[", "$", "key", "]", ":", "null", ";", "}" ]
获取模块分类 @param $key @return null
[ "获取模块分类" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/Module.php#L185-L188
callmez/yii2-wechat
Module.php
Module.getCategoryMenus
public function getCategoryMenus() { if ($this->_categoryMenus === null) { $this->setCategoryMenus($this->categoryMenus()); } return $this->_categoryMenus; }
php
public function getCategoryMenus() { if ($this->_categoryMenus === null) { $this->setCategoryMenus($this->categoryMenus()); } return $this->_categoryMenus; }
[ "public", "function", "getCategoryMenus", "(", ")", "{", "if", "(", "$", "this", "->", "_categoryMenus", "===", "null", ")", "{", "$", "this", "->", "setCategoryMenus", "(", "$", "this", "->", "categoryMenus", "(", ")", ")", ";", "}", "return", "$", "t...
获取分类菜单 @return array|null
[ "获取分类菜单" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/Module.php#L199-L205
callmez/yii2-wechat
Module.php
Module.categoryMenus
protected function categoryMenus() { $menus = []; $categories = $this->getCategories(); foreach ($categories as $key => $label) { $menus[$key] = [ 'label' => $label, 'items' => array_key_exists($key, $this->defaultCateMenus) ? $this->defaultCateMenus[$key] : [] ]; } $class = $this->moduleModelClass; foreach ($class::models() as $model) { // 安装的扩展模块(开启后台功能) if (!$model['admin'] || !array_key_exists($model['category'], $categories)) { continue; } $menus[$model['category']]['items'][] = [ 'label' => $model['name'], 'url' => ModuleHelper::getAdminHomeUrl($model['id']) ]; } return $menus; }
php
protected function categoryMenus() { $menus = []; $categories = $this->getCategories(); foreach ($categories as $key => $label) { $menus[$key] = [ 'label' => $label, 'items' => array_key_exists($key, $this->defaultCateMenus) ? $this->defaultCateMenus[$key] : [] ]; } $class = $this->moduleModelClass; foreach ($class::models() as $model) { // 安装的扩展模块(开启后台功能) if (!$model['admin'] || !array_key_exists($model['category'], $categories)) { continue; } $menus[$model['category']]['items'][] = [ 'label' => $model['name'], 'url' => ModuleHelper::getAdminHomeUrl($model['id']) ]; } return $menus; }
[ "protected", "function", "categoryMenus", "(", ")", "{", "$", "menus", "=", "[", "]", ";", "$", "categories", "=", "$", "this", "->", "getCategories", "(", ")", ";", "foreach", "(", "$", "categories", "as", "$", "key", "=>", "$", "label", ")", "{", ...
生成分类菜单 @return array
[ "生成分类菜单" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/Module.php#L244-L267
callmez/yii2-wechat
Module.php
Module.canCreateModule
public function canCreateModule() { $gii = Yii::$app->getModule($this->giiModuleName); return $gii !== null && isset($gii->generators[$this->giiGeneratorName]); }
php
public function canCreateModule() { $gii = Yii::$app->getModule($this->giiModuleName); return $gii !== null && isset($gii->generators[$this->giiGeneratorName]); }
[ "public", "function", "canCreateModule", "(", ")", "{", "$", "gii", "=", "Yii", "::", "$", "app", "->", "getModule", "(", "$", "this", "->", "giiModuleName", ")", ";", "return", "$", "gii", "!==", "null", "&&", "isset", "(", "$", "gii", "->", "genera...
模块设计器是否可用 @return bool
[ "模块设计器是否可用" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/Module.php#L296-L300
callmez/yii2-wechat
models/MediaSearch.php
MediaSearch.search
public function search($params) { $query = Media::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'material' => $this->material, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'mediaId', $this->mediaId]) ->andFilterWhere(['like', 'post', $this->post]) ->andFilterWhere(['like', 'result', $this->result]) ->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
php
public function search($params) { $query = Media::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'material' => $this->material, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'mediaId', $this->mediaId]) ->andFilterWhere(['like', 'post', $this->post]) ->andFilterWhere(['like', 'result', $this->result]) ->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "Media", "::", "find", "(", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "this", ...
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/MediaSearch.php#L42-L71
callmez/yii2-wechat
generators/module/Generator.php
Generator.getBaseNamespace
public function getBaseNamespace($type = null) { if ($type === null) { $type = $this->type; } switch ($type) { case Module::TYPE_ADDON: return str_replace('/', '\\', ltrim(WechatModule::ADDON_MODULE_PATH, '@')); case Module::TYPE_CORE: return str_replace('/', '\\', ltrim(WechatModule::CORE_MODULE_PATH, '@')); default: return false; } }
php
public function getBaseNamespace($type = null) { if ($type === null) { $type = $this->type; } switch ($type) { case Module::TYPE_ADDON: return str_replace('/', '\\', ltrim(WechatModule::ADDON_MODULE_PATH, '@')); case Module::TYPE_CORE: return str_replace('/', '\\', ltrim(WechatModule::CORE_MODULE_PATH, '@')); default: return false; } }
[ "public", "function", "getBaseNamespace", "(", "$", "type", "=", "null", ")", "{", "if", "(", "$", "type", "===", "null", ")", "{", "$", "type", "=", "$", "this", "->", "type", ";", "}", "switch", "(", "$", "type", ")", "{", "case", "Module", "::...
获取基本命名空间 @param string $type @return bool|mixed
[ "获取基本命名空间" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/generators/module/Generator.php#L207-L220
callmez/yii2-wechat
models/ReplyRuleSearch.php
ReplyRuleSearch.search
public function search($params) { $query = ReplyRule::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'wid' => $this->wid, 'status' => $this->status, 'priority' => $this->priority, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'mid', $this->mid]); return $dataProvider; }
php
public function search($params) { $query = ReplyRule::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'wid' => $this->wid, 'status' => $this->status, 'priority' => $this->priority, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'mid', $this->mid]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "ReplyRule", "::", "find", "(", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "$", "this"...
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/ReplyRuleSearch.php#L42-L71
callmez/yii2-wechat
controllers/ApiController.php
ApiController.beforeProcess
public function beforeProcess() { $event = new ProcessEvent($this->message, $this->getWechat()); $this->trigger(self::EVENT_BEFORE_PROCESS, $event); return $event->isValid; }
php
public function beforeProcess() { $event = new ProcessEvent($this->message, $this->getWechat()); $this->trigger(self::EVENT_BEFORE_PROCESS, $event); return $event->isValid; }
[ "public", "function", "beforeProcess", "(", ")", "{", "$", "event", "=", "new", "ProcessEvent", "(", "$", "this", "->", "message", ",", "$", "this", "->", "getWechat", "(", ")", ")", ";", "$", "this", "->", "trigger", "(", "self", "::", "EVENT_BEFORE_P...
消息处理前事件 @return mixed
[ "消息处理前事件" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L84-L89
callmez/yii2-wechat
controllers/ApiController.php
ApiController.afterProcess
public function afterProcess(&$result) { if ($this->hasEventHandlers(self::EVENT_AFTER_PROCESS)) { $event = new ProcessEvent($this->message, $this->getWechat()); $event->result = $result; $this->trigger(self::EVENT_AFTER_PROCESS, $event); $result = $event->result; } }
php
public function afterProcess(&$result) { if ($this->hasEventHandlers(self::EVENT_AFTER_PROCESS)) { $event = new ProcessEvent($this->message, $this->getWechat()); $event->result = $result; $this->trigger(self::EVENT_AFTER_PROCESS, $event); $result = $event->result; } }
[ "public", "function", "afterProcess", "(", "&", "$", "result", ")", "{", "if", "(", "$", "this", "->", "hasEventHandlers", "(", "self", "::", "EVENT_AFTER_PROCESS", ")", ")", "{", "$", "event", "=", "new", "ProcessEvent", "(", "$", "this", "->", "message...
消息处理后事件 @param $result @throws NotFoundHttpException
[ "消息处理后事件" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L100-L108
callmez/yii2-wechat
controllers/ApiController.php
ApiController.actionIndex
public function actionIndex($id) { // TODO 群发事件推送群发处理 // TODO 模板消息事件推送处理 // TODO 用户上报地理位置事件推送处理 // TODO 自定义菜单事件推送处理 // TODO 微信小店订单付款通知处理 // TODO 微信卡卷(卡券通过审核、卡券被用户领取、卡券被用户删除)通知处理 // TODO 智能设备接口 // TODO 多客服转发处理 $request = Yii::$app->request; $wechat = $this->findWechat($id); if (!$wechat->getSdk()->checkSignature()) { return 'Sign check fail!'; } switch ($request->getMethod()) { case 'GET': if ($wechat->status == Wechat::STATUS_INACTIVE) { // 激活公众号 $wechat->updateAttributes(['status' => Wechat::STATUS_ACTIVE]); } return $request->get('echostr'); case 'POST': $this->setWechat($wechat); $this->message = $this->parseRequest(); $result = null; if($this->beforeProcess()) { $result = $this->resolveProcess(); // 处理请求 $this->afterProcess($result); } return is_array($result) ? $this->createResponse($result) : $result; default: throw new NotFoundHttpException('The requested page does not exist.'); } }
php
public function actionIndex($id) { // TODO 群发事件推送群发处理 // TODO 模板消息事件推送处理 // TODO 用户上报地理位置事件推送处理 // TODO 自定义菜单事件推送处理 // TODO 微信小店订单付款通知处理 // TODO 微信卡卷(卡券通过审核、卡券被用户领取、卡券被用户删除)通知处理 // TODO 智能设备接口 // TODO 多客服转发处理 $request = Yii::$app->request; $wechat = $this->findWechat($id); if (!$wechat->getSdk()->checkSignature()) { return 'Sign check fail!'; } switch ($request->getMethod()) { case 'GET': if ($wechat->status == Wechat::STATUS_INACTIVE) { // 激活公众号 $wechat->updateAttributes(['status' => Wechat::STATUS_ACTIVE]); } return $request->get('echostr'); case 'POST': $this->setWechat($wechat); $this->message = $this->parseRequest(); $result = null; if($this->beforeProcess()) { $result = $this->resolveProcess(); // 处理请求 $this->afterProcess($result); } return is_array($result) ? $this->createResponse($result) : $result; default: throw new NotFoundHttpException('The requested page does not exist.'); } }
[ "public", "function", "actionIndex", "(", "$", "id", ")", "{", "// TODO 群发事件推送群发处理", "// TODO 模板消息事件推送处理", "// TODO 用户上报地理位置事件推送处理", "// TODO 自定义菜单事件推送处理", "// TODO 微信小店订单付款通知处理", "// TODO 微信卡卷(卡券通过审核、卡券被用户领取、卡券被用户删除)通知处理", "// TODO 智能设备接口", "// TODO 多客服转发处理", "$", "request", "="...
微信请求响应Action 分析请求后分发给指定的处理流程 @param $id @return mixed|null @throws NotFoundHttpException
[ "微信请求响应Action", "分析请求后分发给指定的处理流程" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L117-L150
callmez/yii2-wechat
controllers/ApiController.php
ApiController.parseRequest
public function parseRequest() { $xml = $this->getWechat()->getSdk()->parseRequestXml(); if (empty($xml)) { Yii::$app->response->content = 'Request data parse failed!'; Yii::$app->end(); } $message = []; foreach ($xml as $attribute => $value) { $message[$attribute] = is_array($value) ? $value : (string) $value; } Yii::info($message, __METHOD__); return $message; }
php
public function parseRequest() { $xml = $this->getWechat()->getSdk()->parseRequestXml(); if (empty($xml)) { Yii::$app->response->content = 'Request data parse failed!'; Yii::$app->end(); } $message = []; foreach ($xml as $attribute => $value) { $message[$attribute] = is_array($value) ? $value : (string) $value; } Yii::info($message, __METHOD__); return $message; }
[ "public", "function", "parseRequest", "(", ")", "{", "$", "xml", "=", "$", "this", "->", "getWechat", "(", ")", "->", "getSdk", "(", ")", "->", "parseRequestXml", "(", ")", ";", "if", "(", "empty", "(", "$", "xml", ")", ")", "{", "Yii", "::", "$"...
解析微信请求内容 @return array @throws NotFoundHttpException
[ "解析微信请求内容" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L157-L171
callmez/yii2-wechat
controllers/ApiController.php
ApiController.createResponse
public function createResponse(array $data) { $timestamp = time(); $data = array_merge([ 'FromUserName' => $this->message['ToUserName'], 'ToUserName' => $this->message['FromUserName'], 'CreateTime' => $timestamp ], $data); Yii::info($data, __METHOD__); $sdk = $this->getWechat()->getSdk(); $xml = $sdk->xml($data); if ($xml && Yii::$app->request->get('encrypt_type') == 'aes') { // aes加密 $xml = $sdk->encryptXml($xml, $timestamp, Yii::$app->security->generateRandomString(6)); } return $xml; }
php
public function createResponse(array $data) { $timestamp = time(); $data = array_merge([ 'FromUserName' => $this->message['ToUserName'], 'ToUserName' => $this->message['FromUserName'], 'CreateTime' => $timestamp ], $data); Yii::info($data, __METHOD__); $sdk = $this->getWechat()->getSdk(); $xml = $sdk->xml($data); if ($xml && Yii::$app->request->get('encrypt_type') == 'aes') { // aes加密 $xml = $sdk->encryptXml($xml, $timestamp, Yii::$app->security->generateRandomString(6)); } return $xml; }
[ "public", "function", "createResponse", "(", "array", "$", "data", ")", "{", "$", "timestamp", "=", "time", "(", ")", ";", "$", "data", "=", "array_merge", "(", "[", "'FromUserName'", "=>", "$", "this", "->", "message", "[", "'ToUserName'", "]", ",", "...
生成响应内容Response @param array $data @return object
[ "生成响应内容Response" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L178-L195
callmez/yii2-wechat
controllers/ApiController.php
ApiController.resolveProcess
public function resolveProcess() { $result = null; foreach ($this->match() as $model) { if ($model instanceof ReplyRuleKeyword) { $processor = $model->rule->processor; $route = $processor[0] == '/' ? $processor : '/wechat/' . $model->rule->mid . '/' . $model->rule->processor; } elseif (isset($model['route'])) { // 直接返回处理route $route = $model['route']; } else { continue; } // 转发路由请求 参考: Yii::$app->runAction() $parts = Yii::$app->createController($route); if (is_array($parts)) { list($controller, $actionID) = $parts; // 微信请求的处理器必须继承callmez\wechat\components\ProcessController if (!($controller instanceof ProcessController)) { throw new InvalidCallException("Wechat process controller must instance of '" . ProcessController::className() . "'"); } // 传入当前公众号和微信请求内容 $controller->message = $this->message; $controller->setWechat($this->getWechat()); $oldController = Yii::$app->controller; $result = $controller->runAction($actionID); Yii::$app->controller = $oldController; } // 如果有数据则跳出循环直接输出. 否则只作为订阅类型继续循环处理 if ($result !== null) { break; } } $module = isset($controller) ? $controller->module->id : 'wechat'; // 处理的模块 if ($model instanceof ReplyRuleKeyword) { $kid = $model->id; $rid = $model->rid; } else { $kid = $rid = 0; } // 记录请求内容 MessageHistory::add([ 'wid' => $this->getWechat()->id, 'rid' => $rid, 'kid' => $kid, 'from' => $this->message['FromUserName'], 'to' => $this->message['ToUserName'], 'module' => $module, 'message' => $this->message, 'type' => MessageHistory::TYPE_REQUEST ]); // 记录响应内容 if ($result !== null) { // 记录响应内容 MessageHistory::add([ 'wid' => $this->getWechat()->id, 'rid' => $rid, 'kid' => $kid, 'from' => $this->message['ToUserName'], 'to' => $this->message['FromUserName'], 'module' => $module, 'message' => $result, 'type' => MessageHistory::TYPE_RESPONSE ]); } return $result; }
php
public function resolveProcess() { $result = null; foreach ($this->match() as $model) { if ($model instanceof ReplyRuleKeyword) { $processor = $model->rule->processor; $route = $processor[0] == '/' ? $processor : '/wechat/' . $model->rule->mid . '/' . $model->rule->processor; } elseif (isset($model['route'])) { // 直接返回处理route $route = $model['route']; } else { continue; } // 转发路由请求 参考: Yii::$app->runAction() $parts = Yii::$app->createController($route); if (is_array($parts)) { list($controller, $actionID) = $parts; // 微信请求的处理器必须继承callmez\wechat\components\ProcessController if (!($controller instanceof ProcessController)) { throw new InvalidCallException("Wechat process controller must instance of '" . ProcessController::className() . "'"); } // 传入当前公众号和微信请求内容 $controller->message = $this->message; $controller->setWechat($this->getWechat()); $oldController = Yii::$app->controller; $result = $controller->runAction($actionID); Yii::$app->controller = $oldController; } // 如果有数据则跳出循环直接输出. 否则只作为订阅类型继续循环处理 if ($result !== null) { break; } } $module = isset($controller) ? $controller->module->id : 'wechat'; // 处理的模块 if ($model instanceof ReplyRuleKeyword) { $kid = $model->id; $rid = $model->rid; } else { $kid = $rid = 0; } // 记录请求内容 MessageHistory::add([ 'wid' => $this->getWechat()->id, 'rid' => $rid, 'kid' => $kid, 'from' => $this->message['FromUserName'], 'to' => $this->message['ToUserName'], 'module' => $module, 'message' => $this->message, 'type' => MessageHistory::TYPE_REQUEST ]); // 记录响应内容 if ($result !== null) { // 记录响应内容 MessageHistory::add([ 'wid' => $this->getWechat()->id, 'rid' => $rid, 'kid' => $kid, 'from' => $this->message['ToUserName'], 'to' => $this->message['FromUserName'], 'module' => $module, 'message' => $result, 'type' => MessageHistory::TYPE_RESPONSE ]); } return $result; }
[ "public", "function", "resolveProcess", "(", ")", "{", "$", "result", "=", "null", ";", "foreach", "(", "$", "this", "->", "match", "(", ")", "as", "$", "model", ")", "{", "if", "(", "$", "model", "instanceof", "ReplyRuleKeyword", ")", "{", "$", "pro...
解析到控制器 @return null
[ "解析到控制器" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L201-L273
callmez/yii2-wechat
controllers/ApiController.php
ApiController.match
public function match() { if ($this->message['MsgType'] == 'event') { // 事件 $method = 'matchEvent' . $this->message['Event']; } else { $method = 'match' . $this->message['MsgType']; } $matches = []; if (method_exists($this, $method)) { $matches = call_user_func([$this, $method]); } $matches = array_merge([ ['route' => '/wechat/process/fans/record'] // 记录常用数据 ], $matches); Yii::info($matches, __METHOD__); return $matches; }
php
public function match() { if ($this->message['MsgType'] == 'event') { // 事件 $method = 'matchEvent' . $this->message['Event']; } else { $method = 'match' . $this->message['MsgType']; } $matches = []; if (method_exists($this, $method)) { $matches = call_user_func([$this, $method]); } $matches = array_merge([ ['route' => '/wechat/process/fans/record'] // 记录常用数据 ], $matches); Yii::info($matches, __METHOD__); return $matches; }
[ "public", "function", "match", "(", ")", "{", "if", "(", "$", "this", "->", "message", "[", "'MsgType'", "]", "==", "'event'", ")", "{", "// 事件", "$", "method", "=", "'matchEvent'", ".", "$", "this", "->", "message", "[", "'Event'", "]", ";", "}", ...
回复规则匹配 @return array|mixed
[ "回复规则匹配" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L279-L296
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchText
protected function matchText() { return ReplyRuleKeyword::find() ->keyword($this->message['Content']) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchText() { return ReplyRuleKeyword::find() ->keyword($this->message['Content']) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchText", "(", ")", "{", "return", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "keyword", "(", "$", "this", "->", "message", "[", "'Content'", "]", ")", "->", "wechatRule", "(", "$", "this", "->", "getWechat", "(", ")", ...
文本消息关键字触发 @return array
[ "文本消息关键字触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L302-L309
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchImage
protected function matchImage() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => ReplyRuleKeyword::TYPE_IMAGE]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchImage() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => ReplyRuleKeyword::TYPE_IMAGE]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchImage", "(", ")", "{", "return", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "ReplyRuleKeyword", "::", "TYPE_IMAGE", "]", ")", "->", "wechatRule", "(", "$", "this", "->", "getWe...
图片消息触发 @return mixed
[ "图片消息触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L315-L322
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchVoice
protected function matchVoice() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => ReplyRuleKeyword::TYPE_VOICE]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchVoice() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => ReplyRuleKeyword::TYPE_VOICE]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchVoice", "(", ")", "{", "return", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "ReplyRuleKeyword", "::", "TYPE_VOICE", "]", ")", "->", "wechatRule", "(", "$", "this", "->", "getWe...
音频消息触发 @return mixed
[ "音频消息触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L328-L335
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchVideo
protected function matchVideo() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_VIDEO, ReplyRuleKeyword::TYPE_SHORT_VIDEO]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchVideo() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_VIDEO, ReplyRuleKeyword::TYPE_SHORT_VIDEO]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchVideo", "(", ")", "{", "return", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "[", "ReplyRuleKeyword", "::", "TYPE_VIDEO", ",", "ReplyRuleKeyword", "::", "TYPE_SHORT_VIDEO", "]", "]"...
视频, 短视频消息触发 @return mixed
[ "视频", "短视频消息触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L341-L348
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchLocation
protected function matchLocation() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_LOCATION]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchLocation() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_LOCATION]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchLocation", "(", ")", "{", "return", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "[", "ReplyRuleKeyword", "::", "TYPE_LOCATION", "]", "]", ")", "->", "wechatRule", "(", "$", "thi...
位置消息触发 @return mixed
[ "位置消息触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L354-L361
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchLink
protected function matchLink() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_LINK]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchLink() { return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_LINK]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchLink", "(", ")", "{", "return", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "[", "ReplyRuleKeyword", "::", "TYPE_LINK", "]", "]", ")", "->", "wechatRule", "(", "$", "this", "-...
链接消息触发 @return mixed
[ "链接消息触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L367-L374
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchEventSubscribe
protected function matchEventSubscribe() { // 扫码关注 if (array_key_exists('Eventkey', $this->message) && strexists($this->message['Eventkey'], 'qrscene')) { $this->message['Eventkey'] = explode('_', $this->message['Eventkey'])[1]; // 取二维码的参数值 return $this->matchEventScan(); } // 订阅请求回复规则触发 return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_SUBSCRIBE]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
php
protected function matchEventSubscribe() { // 扫码关注 if (array_key_exists('Eventkey', $this->message) && strexists($this->message['Eventkey'], 'qrscene')) { $this->message['Eventkey'] = explode('_', $this->message['Eventkey'])[1]; // 取二维码的参数值 return $this->matchEventScan(); } // 订阅请求回复规则触发 return ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_SUBSCRIBE]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); }
[ "protected", "function", "matchEventSubscribe", "(", ")", "{", "// 扫码关注", "if", "(", "array_key_exists", "(", "'Eventkey'", ",", "$", "this", "->", "message", ")", "&&", "strexists", "(", "$", "this", "->", "message", "[", "'Eventkey'", "]", ",", "'qrscene'"...
关注事件 @return array|void
[ "关注事件" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L380-L393
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchEventUnsubscribe
protected function matchEventUnsubscribe() { $match = ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_UNSUBSCRIBE]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); return array_merge([ // 取消关注默认处理 ['route' => '/wechat/process/fans/unsubscribe'] ], $match); }
php
protected function matchEventUnsubscribe() { $match = ReplyRuleKeyword::find() ->andFilterWhere(['type' => [ReplyRuleKeyword::TYPE_UNSUBSCRIBE]]) ->wechatRule($this->getWechat()->id) ->limitTime(TIMESTAMP) ->all(); return array_merge([ // 取消关注默认处理 ['route' => '/wechat/process/fans/unsubscribe'] ], $match); }
[ "protected", "function", "matchEventUnsubscribe", "(", ")", "{", "$", "match", "=", "ReplyRuleKeyword", "::", "find", "(", ")", "->", "andFilterWhere", "(", "[", "'type'", "=>", "[", "ReplyRuleKeyword", "::", "TYPE_UNSUBSCRIBE", "]", "]", ")", "->", "wechatRul...
取消关注事件 @return array
[ "取消关注事件" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L399-L409
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchEventScan
protected function matchEventScan() { if (array_key_exists('Eventkey', $this->message)) { $this->message['Content'] = $this->message['EventKey']; return $this->matchText(); } return []; }
php
protected function matchEventScan() { if (array_key_exists('Eventkey', $this->message)) { $this->message['Content'] = $this->message['EventKey']; return $this->matchText(); } return []; }
[ "protected", "function", "matchEventScan", "(", ")", "{", "if", "(", "array_key_exists", "(", "'Eventkey'", ",", "$", "this", "->", "message", ")", ")", "{", "$", "this", "->", "message", "[", "'Content'", "]", "=", "$", "this", "->", "message", "[", "...
用户已关注时的扫码事件触发 @return array
[ "用户已关注时的扫码事件触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L415-L422
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchEventClick
protected function matchEventClick() { // 触发作为关键字处理 if (array_key_exists('EventKey', $this->message)) { $this->message['Content'] = $this->message['EventKey']; // EventKey作为关键字Content return $this->matchText(); } return []; }
php
protected function matchEventClick() { // 触发作为关键字处理 if (array_key_exists('EventKey', $this->message)) { $this->message['Content'] = $this->message['EventKey']; // EventKey作为关键字Content return $this->matchText(); } return []; }
[ "protected", "function", "matchEventClick", "(", ")", "{", "// 触发作为关键字处理", "if", "(", "array_key_exists", "(", "'EventKey'", ",", "$", "this", "->", "message", ")", ")", "{", "$", "this", "->", "message", "[", "'Content'", "]", "=", "$", "this", "->", "m...
点击菜单拉取消息时的事件触发 @return array
[ "点击菜单拉取消息时的事件触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L437-L445
callmez/yii2-wechat
controllers/ApiController.php
ApiController.matchEventView
protected function matchEventView() { // 链接内容作为关键字 if (array_key_exists('EventKey', $this->message)) { $this->message['Content'] = $this->message['EventKey']; // EventKey作为关键字Content return $this->matchText(); } return []; }
php
protected function matchEventView() { // 链接内容作为关键字 if (array_key_exists('EventKey', $this->message)) { $this->message['Content'] = $this->message['EventKey']; // EventKey作为关键字Content return $this->matchText(); } return []; }
[ "protected", "function", "matchEventView", "(", ")", "{", "// 链接内容作为关键字", "if", "(", "array_key_exists", "(", "'EventKey'", ",", "$", "this", "->", "message", ")", ")", "{", "$", "this", "->", "message", "[", "'Content'", "]", "=", "$", "this", "->", "me...
点击菜单跳转链接时的事件触发 @return array
[ "点击菜单跳转链接时的事件触发" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ApiController.php#L451-L459
callmez/yii2-wechat
widgets/FileApiInputWidget.php
FileApiInputWidget.run
public function run() { $this->registerClientScript(); if ($this->hasModel()) { $input = Html::activeTextInput($this->model, $this->attribute, $this->options); $fileInput = Html::fileInput(Html::getInputName($this->model, $this->attribute), null, $this->fileInputOptions); } else { $input = Html::textInput($this->name, $this->value, $this->options); $fileInput = Html::fileInput($this->name, $this->value, $this->fileInputOptions); } $button = Html::tag('div', $fileInput . '<span>' . $this->buttonText . '</span>', $this->buttonOptions); return strtr($this->template, [ '{id}' => $this->getId(), '{input}' => $input, '{button}' => $button, '{fields}' => $this->fields ]); }
php
public function run() { $this->registerClientScript(); if ($this->hasModel()) { $input = Html::activeTextInput($this->model, $this->attribute, $this->options); $fileInput = Html::fileInput(Html::getInputName($this->model, $this->attribute), null, $this->fileInputOptions); } else { $input = Html::textInput($this->name, $this->value, $this->options); $fileInput = Html::fileInput($this->name, $this->value, $this->fileInputOptions); } $button = Html::tag('div', $fileInput . '<span>' . $this->buttonText . '</span>', $this->buttonOptions); return strtr($this->template, [ '{id}' => $this->getId(), '{input}' => $input, '{button}' => $button, '{fields}' => $this->fields ]); }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "registerClientScript", "(", ")", ";", "if", "(", "$", "this", "->", "hasModel", "(", ")", ")", "{", "$", "input", "=", "Html", "::", "activeTextInput", "(", "$", "this", "->", "model", ...
输出模板内容 @return string
[ "输出模板内容" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/widgets/FileApiInputWidget.php#L74-L92
callmez/yii2-wechat
widgets/FileApiInputWidget.php
FileApiInputWidget.registerClientScript
public function registerClientScript() { $options = Json::htmlEncode($this->getClientOptions()); $view = $this->getView(); FileApiAsset::register($view); $view->registerJs("$('{$this->target}').fileapi({$options});"); }
php
public function registerClientScript() { $options = Json::htmlEncode($this->getClientOptions()); $view = $this->getView(); FileApiAsset::register($view); $view->registerJs("$('{$this->target}').fileapi({$options});"); }
[ "public", "function", "registerClientScript", "(", ")", "{", "$", "options", "=", "Json", "::", "htmlEncode", "(", "$", "this", "->", "getClientOptions", "(", ")", ")", ";", "$", "view", "=", "$", "this", "->", "getView", "(", ")", ";", "FileApiAsset", ...
注册FileAPI上传控制JS
[ "注册FileAPI上传控制JS" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/widgets/FileApiInputWidget.php#L97-L103
callmez/yii2-wechat
widgets/FileApiInputWidget.php
FileApiInputWidget.getClientOptions
protected function getClientOptions() { $request = Yii::$app->getRequest(); $options = array_merge([ 'autoUpload' => true, 'data' => [ $request->csrfParam => $request->getCsrfToken() // 带上csr参数 ] ], $this->jsOptions); $options['url'] = isset($options['url']) ? Url::to($options['url'], true) : $request->getAbsoluteUrl(); if (!isset($options['onUpload'])) { $options['onUpload'] = new JsExpression (<<<EOF function(evt, uiEvt) { var fileInput = $(this).find('[type=file]'); var text = fileInput.siblings('span').text(); fileInput.data('text', text).siblings('span').text('上传中...'); } EOF ); } if (!isset($options['onProgress'])) { $options['onProgress'] = new JsExpression (<<<EOF function(evt, uiEvt) { $(this).find('[type=file]').siblings('span').text('上传中(' + parseInt(uiEvt.loaded / uiEvt.total * 100) + '%)...'); } EOF ); } if (!isset($options['onComplete'])) { $options['onComplete'] = new JsExpression (<<<EOF function(evt, uiEvt) { var _this = $(this); var fileInput = _this.find('[type=file]'); var text = fileInput.data('text'); if (text) { _this.find('[type=file]').siblings('span').text(text) } if (uiEvt.error) { return alert('上传错误:' + uiEvt.error); } else if (uiEvt.result.type != 'success') { return alert(uiEvt.result.message); } evt.widget.\$el.find('[type=text]').val(uiEvt.result.message.path); } EOF ); } return $options; }
php
protected function getClientOptions() { $request = Yii::$app->getRequest(); $options = array_merge([ 'autoUpload' => true, 'data' => [ $request->csrfParam => $request->getCsrfToken() // 带上csr参数 ] ], $this->jsOptions); $options['url'] = isset($options['url']) ? Url::to($options['url'], true) : $request->getAbsoluteUrl(); if (!isset($options['onUpload'])) { $options['onUpload'] = new JsExpression (<<<EOF function(evt, uiEvt) { var fileInput = $(this).find('[type=file]'); var text = fileInput.siblings('span').text(); fileInput.data('text', text).siblings('span').text('上传中...'); } EOF ); } if (!isset($options['onProgress'])) { $options['onProgress'] = new JsExpression (<<<EOF function(evt, uiEvt) { $(this).find('[type=file]').siblings('span').text('上传中(' + parseInt(uiEvt.loaded / uiEvt.total * 100) + '%)...'); } EOF ); } if (!isset($options['onComplete'])) { $options['onComplete'] = new JsExpression (<<<EOF function(evt, uiEvt) { var _this = $(this); var fileInput = _this.find('[type=file]'); var text = fileInput.data('text'); if (text) { _this.find('[type=file]').siblings('span').text(text) } if (uiEvt.error) { return alert('上传错误:' + uiEvt.error); } else if (uiEvt.result.type != 'success') { return alert(uiEvt.result.message); } evt.widget.\$el.find('[type=text]').val(uiEvt.result.message.path); } EOF ); } return $options; }
[ "protected", "function", "getClientOptions", "(", ")", "{", "$", "request", "=", "Yii", "::", "$", "app", "->", "getRequest", "(", ")", ";", "$", "options", "=", "array_merge", "(", "[", "'autoUpload'", "=>", "true", ",", "'data'", "=>", "[", "$", "req...
返回FileApi所需要的JS设置 该设置默认会自动上传图片, 并会根据服务器端返回的JSON内容判断成功失败 成功则会写入返回的数据到input中 成功返回: ``` { 'type': 'success', 'message' => { 'path' => 'path' } } ``` 失败或其他返回: ``` { 'type': 'error|info|warning', 'message' => 'message' } ``` @return array
[ "返回FileApi所需要的JS设置", "该设置默认会自动上传图片", "并会根据服务器端返回的JSON内容判断成功失败", "成功则会写入返回的数据到input中", "成功返回", ":", "{", "type", ":", "success", "message", "=", ">", "{", "path", "=", ">", "path", "}", "}", "失败或其他返回", ":", "{", "type", ":", "error|info|warning", "message", "=", ...
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/widgets/FileApiInputWidget.php#L128-L176
callmez/yii2-wechat
models/ReplyRuleKeywordQuery.php
ReplyRuleKeywordQuery.keyword
public function keyword($keyword) { $this->andWhere([ 'or', ['and', '{{type}}=:typeMatch', '{{keyword}}=:keyword'], // 直接匹配关键字 ['and', '{{type}}=:typeInclude', 'INSTR(:keyword, {{keyword}})>0'], // 包含关键字 ['and', '{{type}}=:typeRegular', ':keyword REGEXP {{keyword}}'], // 正则匹配关键字 ]) ->addParams([ ':keyword' => $keyword, ':typeMatch' => ReplyRuleKeyword::TYPE_MATCH, ':typeInclude' => ReplyRuleKeyword::TYPE_INCLUDE, ':typeRegular' => ReplyRuleKeyword::TYPE_REGULAR ]); return $this; }
php
public function keyword($keyword) { $this->andWhere([ 'or', ['and', '{{type}}=:typeMatch', '{{keyword}}=:keyword'], // 直接匹配关键字 ['and', '{{type}}=:typeInclude', 'INSTR(:keyword, {{keyword}})>0'], // 包含关键字 ['and', '{{type}}=:typeRegular', ':keyword REGEXP {{keyword}}'], // 正则匹配关键字 ]) ->addParams([ ':keyword' => $keyword, ':typeMatch' => ReplyRuleKeyword::TYPE_MATCH, ':typeInclude' => ReplyRuleKeyword::TYPE_INCLUDE, ':typeRegular' => ReplyRuleKeyword::TYPE_REGULAR ]); return $this; }
[ "public", "function", "keyword", "(", "$", "keyword", ")", "{", "$", "this", "->", "andWhere", "(", "[", "'or'", ",", "[", "'and'", ",", "'{{type}}=:typeMatch'", ",", "'{{keyword}}=:keyword'", "]", ",", "// 直接匹配关键字", "[", "'and'", ",", "'{{type}}=:typeInclude'...
文本类型关键字过滤 @param $keyword @return $this
[ "文本类型关键字过滤" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/ReplyRuleKeywordQuery.php#L13-L28
callmez/yii2-wechat
models/ReplyRuleKeywordQuery.php
ReplyRuleKeywordQuery.wechatRule
public function wechatRule($wid, $status = ReplyRule::STATUS_ACTIVE) { $this->joinWith([ 'rule' => function($query) use ($wid, $status) { if ($status !== null) { $query->active($status); } $query->andWhere(['wid' => $wid]); } ]); return $this; }
php
public function wechatRule($wid, $status = ReplyRule::STATUS_ACTIVE) { $this->joinWith([ 'rule' => function($query) use ($wid, $status) { if ($status !== null) { $query->active($status); } $query->andWhere(['wid' => $wid]); } ]); return $this; }
[ "public", "function", "wechatRule", "(", "$", "wid", ",", "$", "status", "=", "ReplyRule", "::", "STATUS_ACTIVE", ")", "{", "$", "this", "->", "joinWith", "(", "[", "'rule'", "=>", "function", "(", "$", "query", ")", "use", "(", "$", "wid", ",", "$",...
查询公众号规则 @return $this
[ "查询公众号规则" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/ReplyRuleKeywordQuery.php#L34-L45
callmez/yii2-wechat
controllers/ModuleController.php
ModuleController.actionIndex
public function actionIndex() { $models = $this->findInstalledModules(); $dataProvider = new ArrayDataProvider([ 'allModels' => array_merge(ModuleHelper::findAvailableModules(), $models), // TODO 多model排序字段相同的话,会报错 @see https://github.com/yiisoft/yii2/issues/8348 // 'sort' => [ // 'attributes' => ['type'], // 'defaultOrder' => [ // 'type' => SORT_DESC // ] // ] ]); return $this->render('index', [ 'models' => $models, 'dataProvider' => $dataProvider, ]); }
php
public function actionIndex() { $models = $this->findInstalledModules(); $dataProvider = new ArrayDataProvider([ 'allModels' => array_merge(ModuleHelper::findAvailableModules(), $models), // TODO 多model排序字段相同的话,会报错 @see https://github.com/yiisoft/yii2/issues/8348 // 'sort' => [ // 'attributes' => ['type'], // 'defaultOrder' => [ // 'type' => SORT_DESC // ] // ] ]); return $this->render('index', [ 'models' => $models, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionIndex", "(", ")", "{", "$", "models", "=", "$", "this", "->", "findInstalledModules", "(", ")", ";", "$", "dataProvider", "=", "new", "ArrayDataProvider", "(", "[", "'allModels'", "=>", "array_merge", "(", "ModuleHelper", "::", "...
显示所有可用的扩展模块 @return mixed
[ "显示所有可用的扩展模块" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ModuleController.php#L21-L39
callmez/yii2-wechat
controllers/ModuleController.php
ModuleController.actionInstall
public function actionInstall($id) { $model = $this->findAvailableModule($id); if (!$model->validate()) { return $this->message('模块的设置错误: ' . array_values($model->firstErrors)[0]); } if (!empty($_POST)) { if ($model->install(false)) { return $this->flash('模块安装成功!', 'success', ['index']); } elseif (!$model->hasErrors()) { return $this->flash('模块安装失败!', 'error'); } } return $this->render('install', [ 'model' => $model ]); }
php
public function actionInstall($id) { $model = $this->findAvailableModule($id); if (!$model->validate()) { return $this->message('模块的设置错误: ' . array_values($model->firstErrors)[0]); } if (!empty($_POST)) { if ($model->install(false)) { return $this->flash('模块安装成功!', 'success', ['index']); } elseif (!$model->hasErrors()) { return $this->flash('模块安装失败!', 'error'); } } return $this->render('install', [ 'model' => $model ]); }
[ "public", "function", "actionInstall", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findAvailableModule", "(", "$", "id", ")", ";", "if", "(", "!", "$", "model", "->", "validate", "(", ")", ")", "{", "return", "$", "this", "->",...
安装模块 @param $id @return array|bool|string @throws NotFoundHttpException
[ "安装模块" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ModuleController.php#L47-L63
callmez/yii2-wechat
controllers/ModuleController.php
ModuleController.actionUninstall
public function actionUninstall($id) { $model = $this->findInstalledModule($id); if (!empty($_POST)) { if ($model->uninstall()) { return $this->flash('模块卸载成功!', 'success', ['index']); } else { return $this->flash('模块卸载失败!', 'error'); } } return $this->render('uninstall', [ 'model' => $model ]); }
php
public function actionUninstall($id) { $model = $this->findInstalledModule($id); if (!empty($_POST)) { if ($model->uninstall()) { return $this->flash('模块卸载成功!', 'success', ['index']); } else { return $this->flash('模块卸载失败!', 'error'); } } return $this->render('uninstall', [ 'model' => $model ]); }
[ "public", "function", "actionUninstall", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findInstalledModule", "(", "$", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "_POST", ")", ")", "{", "if", "(", "$", "model", "->", "u...
卸载模块 @param $id @return array|bool|string @throws NotFoundHttpException
[ "卸载模块" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ModuleController.php#L71-L84
callmez/yii2-wechat
components/MobileController.php
MobileController.getWechat
public function getWechat() { if ($this->_wechat === null) { $wid = Yii::$app->request->get(Yii::$app->getModule('wechat')->wechatUrlParam); if (!$wid || ($wechat = Wechat::find()->active()->one()) === null) { throw new NotFoundHttpException('The requested page does not exist.'); } $this->setWechat($wechat); } return $this->_wechat; }
php
public function getWechat() { if ($this->_wechat === null) { $wid = Yii::$app->request->get(Yii::$app->getModule('wechat')->wechatUrlParam); if (!$wid || ($wechat = Wechat::find()->active()->one()) === null) { throw new NotFoundHttpException('The requested page does not exist.'); } $this->setWechat($wechat); } return $this->_wechat; }
[ "public", "function", "getWechat", "(", ")", "{", "if", "(", "$", "this", "->", "_wechat", "===", "null", ")", "{", "$", "wid", "=", "Yii", "::", "$", "app", "->", "request", "->", "get", "(", "Yii", "::", "$", "app", "->", "getModule", "(", "'we...
获取公众号 该方法会通过设定的公众wid函数来获取公众号数据 @return null @throws NotFoundHttpException
[ "获取公众号", "该方法会通过设定的公众wid函数来获取公众号数据" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/MobileController.php#L37-L47
callmez/yii2-wechat
components/MobileController.php
MobileController.getFans
public function getFans($oauth = true) { if ($this->_fans === null) { $wechat = $this->getWechat(); $sessionKey = self::SESSION_MOBILE_FANS_PREFIX . '_' . $wechat->id; $openId = Yii::$app->session->get($sessionKey); if (!$openId && $oauth) { // API获取用户 $data = $wechat->getSdk()->getAuthorizeUserInfo('fansInfo'); if (isset($data['openid'])) { $openId = $data['openid']; } } if (!$openId || ($fans = Fans::findByOpenId($openId)) === null) { return false; } $this->setFans($fans); } return $this->_fans; }
php
public function getFans($oauth = true) { if ($this->_fans === null) { $wechat = $this->getWechat(); $sessionKey = self::SESSION_MOBILE_FANS_PREFIX . '_' . $wechat->id; $openId = Yii::$app->session->get($sessionKey); if (!$openId && $oauth) { // API获取用户 $data = $wechat->getSdk()->getAuthorizeUserInfo('fansInfo'); if (isset($data['openid'])) { $openId = $data['openid']; } } if (!$openId || ($fans = Fans::findByOpenId($openId)) === null) { return false; } $this->setFans($fans); } return $this->_fans; }
[ "public", "function", "getFans", "(", "$", "oauth", "=", "true", ")", "{", "if", "(", "$", "this", "->", "_fans", "===", "null", ")", "{", "$", "wechat", "=", "$", "this", "->", "getWechat", "(", ")", ";", "$", "sessionKey", "=", "self", "::", "S...
获取粉丝数据(当前公众号唯一) @param bool $oauth 是否通过微信服务器Oauth API跳转获取 通过API获取的用户信息会存入session中 @return mixed
[ "获取粉丝数据", "(", "当前公众号唯一", ")" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/MobileController.php#L68-L86
callmez/yii2-wechat
components/MobileController.php
MobileController.setFans
public function setFans(Fans $fans) { Yii::$app->session->set(self::SESSION_MOBILE_FANS_PREFIX . '_' . $fans->wid, $fans->open_id); return $this->_fans = $fans; }
php
public function setFans(Fans $fans) { Yii::$app->session->set(self::SESSION_MOBILE_FANS_PREFIX . '_' . $fans->wid, $fans->open_id); return $this->_fans = $fans; }
[ "public", "function", "setFans", "(", "Fans", "$", "fans", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "set", "(", "self", "::", "SESSION_MOBILE_FANS_PREFIX", ".", "'_'", ".", "$", "fans", "->", "wid", ",", "$", "fans", "->", "open_id", ...
设置粉丝数据 @return mixed
[ "设置粉丝数据" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/MobileController.php#L92-L96
callmez/yii2-wechat
controllers/ReplyController.php
ReplyController.actionIndex
public function actionIndex($mid) { $searchModel = new ReplyRuleSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->query->andWhere([ 'wid' => $this->getWechat()->id, // 公众号过滤 'mid' => $mid ]); return $this->render('index', [ 'mid' => $mid, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
php
public function actionIndex($mid) { $searchModel = new ReplyRuleSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->query->andWhere([ 'wid' => $this->getWechat()->id, // 公众号过滤 'mid' => $mid ]); return $this->render('index', [ 'mid' => $mid, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); }
[ "public", "function", "actionIndex", "(", "$", "mid", ")", "{", "$", "searchModel", "=", "new", "ReplyRuleSearch", "(", ")", ";", "$", "dataProvider", "=", "$", "searchModel", "->", "search", "(", "Yii", "::", "$", "app", "->", "request", "->", "queryPar...
扩展模块回复列表 @return mixed
[ "扩展模块回复列表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ReplyController.php#L24-L38
callmez/yii2-wechat
controllers/ReplyController.php
ReplyController.actionCreate
public function actionCreate($mid) { $model = new ReplyRule(); $ruleKeyword = new ReplyRuleKeyword(); $ruleKeywords = []; if ($model->load(Yii::$app->request->post())) { $model->wid = $this->getWechat()->id; $model->mid = $mid; if ($this->save($model, $ruleKeyword, $ruleKeywords)) { return $this->flash('添加成功!', 'success', ['update', 'id' => $model->id]); } } return $this->render('create', [ 'mid' => $mid, 'model' => $model, 'ruleKeyword' => $ruleKeyword, 'ruleKeywords' => $ruleKeywords ]); }
php
public function actionCreate($mid) { $model = new ReplyRule(); $ruleKeyword = new ReplyRuleKeyword(); $ruleKeywords = []; if ($model->load(Yii::$app->request->post())) { $model->wid = $this->getWechat()->id; $model->mid = $mid; if ($this->save($model, $ruleKeyword, $ruleKeywords)) { return $this->flash('添加成功!', 'success', ['update', 'id' => $model->id]); } } return $this->render('create', [ 'mid' => $mid, 'model' => $model, 'ruleKeyword' => $ruleKeyword, 'ruleKeywords' => $ruleKeywords ]); }
[ "public", "function", "actionCreate", "(", "$", "mid", ")", "{", "$", "model", "=", "new", "ReplyRule", "(", ")", ";", "$", "ruleKeyword", "=", "new", "ReplyRuleKeyword", "(", ")", ";", "$", "ruleKeywords", "=", "[", "]", ";", "if", "(", "$", "model"...
Creates a new ReplyRule model. If creation is successful, the browser will be redirected to the 'view' page. @return mixed
[ "Creates", "a", "new", "ReplyRule", "model", ".", "If", "creation", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ReplyController.php#L45-L63
callmez/yii2-wechat
controllers/ReplyController.php
ReplyController.actionUpdate
public function actionUpdate($id) { $model = $this->findModel($id); $ruleKeyword = new ReplyRuleKeyword(); $ruleKeywords = $model->keywords; if ($model->load(Yii::$app->request->post())) { $model->wid = $this->getWechat()->id; if ($this->save($model, $ruleKeyword, $ruleKeywords)) { return $this->flash('修改成功!', 'success', ['update', 'id' => $model->id]); } } return $this->render('update', [ 'model' => $model, 'ruleKeyword' => $ruleKeyword, 'ruleKeywords' => $ruleKeywords ]); }
php
public function actionUpdate($id) { $model = $this->findModel($id); $ruleKeyword = new ReplyRuleKeyword(); $ruleKeywords = $model->keywords; if ($model->load(Yii::$app->request->post())) { $model->wid = $this->getWechat()->id; if ($this->save($model, $ruleKeyword, $ruleKeywords)) { return $this->flash('修改成功!', 'success', ['update', 'id' => $model->id]); } } return $this->render('update', [ 'model' => $model, 'ruleKeyword' => $ruleKeyword, 'ruleKeywords' => $ruleKeywords ]); }
[ "public", "function", "actionUpdate", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "ruleKeyword", "=", "new", "ReplyRuleKeyword", "(", ")", ";", "$", "ruleKeywords", "=", "$", "model", "-...
Updates an existing ReplyRule model. If update is successful, the browser will be redirected to the 'view' page. @param integer $id @return mixed
[ "Updates", "an", "existing", "ReplyRule", "model", ".", "If", "update", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ReplyController.php#L71-L87
callmez/yii2-wechat
controllers/ReplyController.php
ReplyController.save
protected function save($rule, $keyword, $keywords = []) { if (!$rule->save()) { return false; } $_keywords = ArrayHelper::index($keywords, 'id'); $keywords = []; $valid = true; foreach (Yii::$app->request->post($keyword->formName(), []) as $k => $data) { if (!empty($data['id']) && $_keywords[$data['id']]) { $_keyword = $_keywords[$data['id']]; unset($_keywords[$data['id']]); } else { $_keyword = clone $keyword; } unset($data['id']); $keywords[] = $_keyword; $_keyword->setAttributes(array_merge($data, [ 'rid' => $rule->id ])); $valid = $valid && $_keyword->save(); } !empty($_keywords) && ReplyRuleKeyword::deleteAll(['id' => array_keys($_keywords)]); // 无更新的则删除 return $valid; }
php
protected function save($rule, $keyword, $keywords = []) { if (!$rule->save()) { return false; } $_keywords = ArrayHelper::index($keywords, 'id'); $keywords = []; $valid = true; foreach (Yii::$app->request->post($keyword->formName(), []) as $k => $data) { if (!empty($data['id']) && $_keywords[$data['id']]) { $_keyword = $_keywords[$data['id']]; unset($_keywords[$data['id']]); } else { $_keyword = clone $keyword; } unset($data['id']); $keywords[] = $_keyword; $_keyword->setAttributes(array_merge($data, [ 'rid' => $rule->id ])); $valid = $valid && $_keyword->save(); } !empty($_keywords) && ReplyRuleKeyword::deleteAll(['id' => array_keys($_keywords)]); // 无更新的则删除 return $valid; }
[ "protected", "function", "save", "(", "$", "rule", ",", "$", "keyword", ",", "$", "keywords", "=", "[", "]", ")", "{", "if", "(", "!", "$", "rule", "->", "save", "(", ")", ")", "{", "return", "false", ";", "}", "$", "_keywords", "=", "ArrayHelper...
保存内容 @param $rule @param $keyword @param array $keywords @return bool
[ "保存内容" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/ReplyController.php#L111-L135
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initWechatTable
public function initWechatTable() { $tableName = Wechat::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'name' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '公众号名称'", 'token' => Schema::TYPE_STRING . "(32) NOT NULL DEFAULT '' COMMENT '微信服务访问验证token'", 'access_token' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '访问微信服务验证token'", 'account' => Schema::TYPE_STRING . "(30) NOT NULL DEFAULT '' COMMENT '微信号'", 'original' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '原始ID'", 'type' => Schema::TYPE_BOOLEAN . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号类型'", 'key' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '公众号的AppID'", 'secret' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '公众号的AppSecret'", 'encoding_aes_key' => Schema::TYPE_STRING . "(43) NOT NULL DEFAULT '' COMMENT '消息加密秘钥EncodingAesKey'", 'avatar' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '头像地址'", 'qrcode' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '二维码地址'", 'address' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '所在地址'", 'description' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '公众号简介'", 'username' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '微信官网登录名'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '状态'", 'password' => Schema::TYPE_STRING . "(32) NOT NULL DEFAULT '' COMMENT '微信官网登录密码'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('key', $tableName, 'key'); }
php
public function initWechatTable() { $tableName = Wechat::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'name' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '公众号名称'", 'token' => Schema::TYPE_STRING . "(32) NOT NULL DEFAULT '' COMMENT '微信服务访问验证token'", 'access_token' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '访问微信服务验证token'", 'account' => Schema::TYPE_STRING . "(30) NOT NULL DEFAULT '' COMMENT '微信号'", 'original' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '原始ID'", 'type' => Schema::TYPE_BOOLEAN . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号类型'", 'key' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '公众号的AppID'", 'secret' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '公众号的AppSecret'", 'encoding_aes_key' => Schema::TYPE_STRING . "(43) NOT NULL DEFAULT '' COMMENT '消息加密秘钥EncodingAesKey'", 'avatar' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '头像地址'", 'qrcode' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '二维码地址'", 'address' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '所在地址'", 'description' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '公众号简介'", 'username' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '微信官网登录名'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '状态'", 'password' => Schema::TYPE_STRING . "(32) NOT NULL DEFAULT '' COMMENT '微信官网登录密码'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('key', $tableName, 'key'); }
[ "public", "function", "initWechatTable", "(", ")", "{", "$", "tableName", "=", "Wechat", "::", "tableName", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_PK", ",", "'name'", "=>", ...
公众号表
[ "公众号表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L41-L66
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initModuleTable
public function initModuleTable() { $tableName = Module::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '模块ID'", 'name' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '模块名称'", 'type' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '模块类型'", 'category' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '模块类型'", 'version' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '模块版本'", 'ability' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT '' COMMENT '模块功能简述'", 'description' => Schema::TYPE_TEXT . " NOT NULL COMMENT '模块详细描述'", 'author' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '模块作者'", 'site' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '模块详情地址'", 'admin' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '是否有后台界面'", 'migration' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '是否有迁移数据'", 'reply_rule' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '是否启用回复规则'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->addPrimaryKey('id', $tableName, 'id'); }
php
public function initModuleTable() { $tableName = Module::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '模块ID'", 'name' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '模块名称'", 'type' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '模块类型'", 'category' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '模块类型'", 'version' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '模块版本'", 'ability' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT '' COMMENT '模块功能简述'", 'description' => Schema::TYPE_TEXT . " NOT NULL COMMENT '模块详细描述'", 'author' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '模块作者'", 'site' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '模块详情地址'", 'admin' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '是否有后台界面'", 'migration' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '是否有迁移数据'", 'reply_rule' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '是否启用回复规则'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->addPrimaryKey('id', $tableName, 'id'); }
[ "public", "function", "initModuleTable", "(", ")", "{", "$", "tableName", "=", "Module", "::", "tableName", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_STRING", ".", "\"(20) NOT NULL...
扩展模块表
[ "扩展模块表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L71-L91
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initReplyRuleTable
public function initReplyRuleTable() { $tableName = ReplyRule::tablename(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'name' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '规则名称'", 'mid' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '处理的插件模块'", 'processor' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '处理类'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '状态'", 'priority' => Schema::TYPE_BOOLEAN . "(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优先级'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('wid', $tableName, 'wid'); $this->createIndex('mid', $tableName, 'mid'); // 回复规则关键字表 $tableName = ReplyRuleKeyword::tablename(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'rid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属规则ID'", 'keyword' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '规则关键字'", 'type' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '关键字类型'", 'priority' => Schema::TYPE_BOOLEAN . "(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优先级'", 'start_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '开始时间'", 'end_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '结束时间'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('rid', $tableName, 'rid'); $this->createIndex('keyword', $tableName, 'keyword'); $this->createIndex('type', $tableName, 'type'); $this->createIndex('start_at', $tableName, 'start_at'); $this->createIndex('end_at', $tableName, 'end_at'); }
php
public function initReplyRuleTable() { $tableName = ReplyRule::tablename(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'name' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '规则名称'", 'mid' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '处理的插件模块'", 'processor' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '处理类'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '状态'", 'priority' => Schema::TYPE_BOOLEAN . "(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优先级'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('wid', $tableName, 'wid'); $this->createIndex('mid', $tableName, 'mid'); // 回复规则关键字表 $tableName = ReplyRuleKeyword::tablename(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'rid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属规则ID'", 'keyword' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '规则关键字'", 'type' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '关键字类型'", 'priority' => Schema::TYPE_BOOLEAN . "(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优先级'", 'start_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '开始时间'", 'end_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '结束时间'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('rid', $tableName, 'rid'); $this->createIndex('keyword', $tableName, 'keyword'); $this->createIndex('type', $tableName, 'type'); $this->createIndex('start_at', $tableName, 'start_at'); $this->createIndex('end_at', $tableName, 'end_at'); }
[ "public", "function", "initReplyRuleTable", "(", ")", "{", "$", "tableName", "=", "ReplyRule", "::", "tablename", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_PK", ",", "'wid'", "=>...
回复规则表
[ "回复规则表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L96-L131
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initFansTable
public function initFansTable() { $tableName = Fans::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'open_id' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '微信ID'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '关注状态'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '关注时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('wid', $tableName, 'wid'); $this->createIndex('open_id', $tableName, 'open_id'); }
php
public function initFansTable() { $tableName = Fans::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'open_id' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '微信ID'", 'status' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0' COMMENT '关注状态'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '关注时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('wid', $tableName, 'wid'); $this->createIndex('open_id', $tableName, 'open_id'); }
[ "public", "function", "initFansTable", "(", ")", "{", "$", "tableName", "=", "Fans", "::", "tableName", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_PK", ",", "'wid'", "=>", "Sche...
粉丝表
[ "粉丝表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L136-L149
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initUserTable
public function initUserTable() { // 公众号粉丝详情表 $tableName = MpUser::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '粉丝ID'", 'nickname' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '昵称'", 'sex' => Schema::TYPE_BOOLEAN . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '性别'", 'city' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '所在城市'", 'country' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '所在省'", 'province' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '微信ID'", 'language' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '用户语言'", 'avatar' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '用户头像'", 'subscribe_time' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '关注时间'", 'union_id' => Schema::TYPE_STRING . "(30) NOT NULL DEFAULT '' COMMENT '用户头像'", 'remark' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '备注'", 'group_id' => Schema::TYPE_SMALLINT . " NOT NULL DEFAULT '0' COMMENT '分组ID'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('id', $tableName, 'id', true); }
php
public function initUserTable() { // 公众号粉丝详情表 $tableName = MpUser::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '粉丝ID'", 'nickname' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '昵称'", 'sex' => Schema::TYPE_BOOLEAN . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '性别'", 'city' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '所在城市'", 'country' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '所在省'", 'province' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '微信ID'", 'language' => Schema::TYPE_STRING . "(40) NOT NULL DEFAULT '' COMMENT '用户语言'", 'avatar' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '用户头像'", 'subscribe_time' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '关注时间'", 'union_id' => Schema::TYPE_STRING . "(30) NOT NULL DEFAULT '' COMMENT '用户头像'", 'remark' => Schema::TYPE_STRING . " NOT NULL DEFAULT '' COMMENT '备注'", 'group_id' => Schema::TYPE_SMALLINT . " NOT NULL DEFAULT '0' COMMENT '分组ID'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); $this->createIndex('id', $tableName, 'id', true); }
[ "public", "function", "initUserTable", "(", ")", "{", "// 公众号粉丝详情表", "$", "tableName", "=", "MpUser", "::", "tableName", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_INTEGER", ".", ...
粉丝用户表
[ "粉丝用户表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L154-L174
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initMessageHistoryTable
public function initMessageHistoryTable() { $tableName = MessageHistory::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'rid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '相应规则ID'", 'kid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属关键字ID'", 'from' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '请求用户ID'", 'to' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '相应用户ID'", 'module' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '处理模块'", 'message' => Schema::TYPE_TEXT . " NOT NULL COMMENT '消息体内容'", 'type' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '发送类型'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'" ]); $this->createIndex('wid', $tableName, 'wid'); $this->createIndex('module', $tableName, 'module'); }
php
public function initMessageHistoryTable() { $tableName = MessageHistory::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'wid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属微信公众号ID'", 'rid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '相应规则ID'", 'kid' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属关键字ID'", 'from' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '请求用户ID'", 'to' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT '' COMMENT '相应用户ID'", 'module' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '处理模块'", 'message' => Schema::TYPE_TEXT . " NOT NULL COMMENT '消息体内容'", 'type' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '发送类型'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'" ]); $this->createIndex('wid', $tableName, 'wid'); $this->createIndex('module', $tableName, 'module'); }
[ "public", "function", "initMessageHistoryTable", "(", ")", "{", "$", "tableName", "=", "MessageHistory", "::", "tableName", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_PK", ",", "'wi...
消息记录表
[ "消息记录表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L179-L196
callmez/yii2-wechat
migrations/m150217_131752_initWechat.php
m150217_131752_initWechat.initMediaTable
public function initMediaTable() { $tableName = Media::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'mediaId' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT '' COMMENT '素材ID'", 'filename' => Schema::TYPE_STRING . "(100) NOT NULL COMMENT '文件名'", 'result' => Schema::TYPE_TEXT . " NOT NULL COMMENT '微信返回数据'", 'type' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '素材类型'", 'material' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '素材类别'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); }
php
public function initMediaTable() { $tableName = Media::tableName(); $this->createTable($tableName, [ 'id' => Schema::TYPE_PK, 'mediaId' => Schema::TYPE_STRING . "(100) NOT NULL DEFAULT '' COMMENT '素材ID'", 'filename' => Schema::TYPE_STRING . "(100) NOT NULL COMMENT '文件名'", 'result' => Schema::TYPE_TEXT . " NOT NULL COMMENT '微信返回数据'", 'type' => Schema::TYPE_STRING . "(10) NOT NULL DEFAULT '' COMMENT '素材类型'", 'material' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT '' COMMENT '素材类别'", 'created_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间'", 'updated_at' => Schema::TYPE_INTEGER . " UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间'" ]); }
[ "public", "function", "initMediaTable", "(", ")", "{", "$", "tableName", "=", "Media", "::", "tableName", "(", ")", ";", "$", "this", "->", "createTable", "(", "$", "tableName", ",", "[", "'id'", "=>", "Schema", "::", "TYPE_PK", ",", "'mediaId'", "=>", ...
素材表
[ "素材表" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/migrations/m150217_131752_initWechat.php#L201-L214
callmez/yii2-wechat
models/FansSearch.php
FansSearch.search
public function search($params, $user = false) { $query = Fans::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if ($user) { $query->with('user'); } $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'wid' => $this->wid, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'open_id', $this->open_id]); return $dataProvider; }
php
public function search($params, $user = false) { $query = Fans::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if ($user) { $query->with('user'); } $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'wid' => $this->wid, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'open_id', $this->open_id]); return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ",", "$", "user", "=", "false", ")", "{", "$", "query", "=", "Fans", "::", "find", "(", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",",...
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/FansSearch.php#L42-L72
callmez/yii2-wechat
behaviors/ArrayBehavior.php
ArrayBehavior.evaluateAttributes
public function evaluateAttributes($event) { if (in_array($event->name, $this->events)) { foreach ($this->attributes as $type => $attributes) { $method = 'get' . $type . 'value'; if (method_exists($this, $method)) { foreach ( (array) $attributes as $attribute) { $this->owner->$attribute = $this->$method($this->owner->$attribute, $event->name); } } } } }
php
public function evaluateAttributes($event) { if (in_array($event->name, $this->events)) { foreach ($this->attributes as $type => $attributes) { $method = 'get' . $type . 'value'; if (method_exists($this, $method)) { foreach ( (array) $attributes as $attribute) { $this->owner->$attribute = $this->$method($this->owner->$attribute, $event->name); } } } } }
[ "public", "function", "evaluateAttributes", "(", "$", "event", ")", "{", "if", "(", "in_array", "(", "$", "event", "->", "name", ",", "$", "this", "->", "events", ")", ")", "{", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "type", "=>"...
Evaluates the attribute value and assigns it to the current attributes. @param Event $event
[ "Evaluates", "the", "attribute", "value", "and", "assigns", "it", "to", "the", "current", "attributes", "." ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/behaviors/ArrayBehavior.php#L75-L87
callmez/yii2-wechat
behaviors/ArrayBehavior.php
ArrayBehavior.getSerializeValue
protected function getSerializeValue($value, $event) { switch ($event) { case ActiveRecord::EVENT_BEFORE_INSERT: case ActiveRecord::EVENT_BEFORE_UPDATE: if (is_array($value)) { $value = serialize($value); } break; case ActiveRecord::EVENT_AFTER_FIND: $value = @unserialize($value) ?: $value; break; } return $value; }
php
protected function getSerializeValue($value, $event) { switch ($event) { case ActiveRecord::EVENT_BEFORE_INSERT: case ActiveRecord::EVENT_BEFORE_UPDATE: if (is_array($value)) { $value = serialize($value); } break; case ActiveRecord::EVENT_AFTER_FIND: $value = @unserialize($value) ?: $value; break; } return $value; }
[ "protected", "function", "getSerializeValue", "(", "$", "value", ",", "$", "event", ")", "{", "switch", "(", "$", "event", ")", "{", "case", "ActiveRecord", "::", "EVENT_BEFORE_INSERT", ":", "case", "ActiveRecord", "::", "EVENT_BEFORE_UPDATE", ":", "if", "(", ...
获取序列化后的值 @param $value @param $event @return string
[ "获取序列化后的值" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/behaviors/ArrayBehavior.php#L95-L109
callmez/yii2-wechat
behaviors/ArrayBehavior.php
ArrayBehavior.getJsonValue
protected function getJsonValue($value, $event) { switch ($event) { case ActiveRecord::EVENT_BEFORE_INSERT: case ActiveRecord::EVENT_BEFORE_UPDATE: if (is_array($value)) { $value = json_encode($value); } break; case ActiveRecord::EVENT_AFTER_FIND: $value = @json_encode($value, true) ?: $value; break; } return $value; }
php
protected function getJsonValue($value, $event) { switch ($event) { case ActiveRecord::EVENT_BEFORE_INSERT: case ActiveRecord::EVENT_BEFORE_UPDATE: if (is_array($value)) { $value = json_encode($value); } break; case ActiveRecord::EVENT_AFTER_FIND: $value = @json_encode($value, true) ?: $value; break; } return $value; }
[ "protected", "function", "getJsonValue", "(", "$", "value", ",", "$", "event", ")", "{", "switch", "(", "$", "event", ")", "{", "case", "ActiveRecord", "::", "EVENT_BEFORE_INSERT", ":", "case", "ActiveRecord", "::", "EVENT_BEFORE_UPDATE", ":", "if", "(", "is...
获取json转换后的值 @param $value @param $event @return mixed|\Services_JSON_Error|string
[ "获取json转换后的值" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/behaviors/ArrayBehavior.php#L117-L131
callmez/yii2-wechat
controllers/WechatController.php
WechatController.actionManage
public function actionManage($id) { $model = $this->findModel($id); $this->setWechat($model); $this->flash('当前管理公众号设置为"' . $model->name . '", 您现在可以管理该公众号了', 'success'); return $this->redirect(['/wechat']); }
php
public function actionManage($id) { $model = $this->findModel($id); $this->setWechat($model); $this->flash('当前管理公众号设置为"' . $model->name . '", 您现在可以管理该公众号了', 'success'); return $this->redirect(['/wechat']); }
[ "public", "function", "actionManage", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "this", "->", "setWechat", "(", "$", "model", ")", ";", "$", "this", "->", "flash", "(", "'当前管理公众号设置为\...
设置当前管理的公众号 @param $id @return Response @throws \yii\web\NotFoundHttpException
[ "设置当前管理的公众号" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/WechatController.php#L49-L55
callmez/yii2-wechat
controllers/WechatController.php
WechatController.actionCreate
public function actionCreate() { $model = new WechatForm(); if ($model->load(Yii::$app->request->post())) { if (Request::isAjax()) { Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } elseif ($model->save()) { return $this->flash('公众号创建成功! 请补充余下公众号设置以激活公众号', 'info', ['update', 'id' => $model->id]); } } return $this->render('create', [ 'model' => $model ]); }
php
public function actionCreate() { $model = new WechatForm(); if ($model->load(Yii::$app->request->post())) { if (Request::isAjax()) { Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } elseif ($model->save()) { return $this->flash('公众号创建成功! 请补充余下公众号设置以激活公众号', 'info', ['update', 'id' => $model->id]); } } return $this->render('create', [ 'model' => $model ]); }
[ "public", "function", "actionCreate", "(", ")", "{", "$", "model", "=", "new", "WechatForm", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", ")", "{", "if", "(", ...
创建公众号 @return string
[ "创建公众号" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/WechatController.php#L61-L75
callmez/yii2-wechat
controllers/WechatController.php
WechatController.actionUpload
public function actionUpload($id) { $model = $this->findModel($id); $formName = $model->formName(); $attribute = isset($_POST[$formName]['avatar']) ? 'avatar' : 'qrcode'; $model->$attribute = UploadedFile::getInstance($model, $attribute); $model->setScenario($attribute . 'Upload'); if ($model->$attribute && $model->validate()) { $path = '/wechat/' . $attribute . '_' . $model->id . '.' . $model->$attribute->getExtension(); $realPath = Yii::getAlias('@storageRoot' . $path); FileHelper::createDirectory(dirname($realPath)); if ($model->$attribute->saveAs($realPath)) { return $this->message(['path' => $path], 'success'); } else { return $this->message('上传失败, 无法保存上传文件!'); } } return $this->message('图片上传失败' . ($model->hasErrors() ? ':' . array_values($model->getFirstErrors())[0] : '')); }
php
public function actionUpload($id) { $model = $this->findModel($id); $formName = $model->formName(); $attribute = isset($_POST[$formName]['avatar']) ? 'avatar' : 'qrcode'; $model->$attribute = UploadedFile::getInstance($model, $attribute); $model->setScenario($attribute . 'Upload'); if ($model->$attribute && $model->validate()) { $path = '/wechat/' . $attribute . '_' . $model->id . '.' . $model->$attribute->getExtension(); $realPath = Yii::getAlias('@storageRoot' . $path); FileHelper::createDirectory(dirname($realPath)); if ($model->$attribute->saveAs($realPath)) { return $this->message(['path' => $path], 'success'); } else { return $this->message('上传失败, 无法保存上传文件!'); } } return $this->message('图片上传失败' . ($model->hasErrors() ? ':' . array_values($model->getFirstErrors())[0] : '')); }
[ "public", "function", "actionUpload", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "$", "formName", "=", "$", "model", "->", "formName", "(", ")", ";", "$", "attribute", "=", "isset", "(", ...
头像,二维码上传 @param $id @return array|bool|string @throws NotFoundHttpException
[ "头像", "二维码上传" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/WechatController.php#L83-L101
callmez/yii2-wechat
controllers/WechatController.php
WechatController.actionUpdate
public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { if (Request::isAjax()) { Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } elseif ($model->save()) { return $this->flash('更新成功', 'success'); } } return $this->render('update', [ 'model' => $model, ]); }
php
public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { if (Request::isAjax()) { Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } elseif ($model->save()) { return $this->flash('更新成功', 'success'); } } return $this->render('update', [ 'model' => $model, ]); }
[ "public", "function", "actionUpdate", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "$", "id", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ...
修改公众号信息 @param integer $id @return mixed
[ "修改公众号信息" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/WechatController.php#L108-L122
callmez/yii2-wechat
controllers/MediaController.php
MediaController.actionUpload
public function actionUpload() { $model = new MediaForm(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->upload()) { return $this->message('上传成功', 'success'); } } // $files = static::getFiles(); // if (!empty($files)) { // if (($mediaType = Yii::$app->request->post('mediaType')) === null) { // return $this->message('错误的媒体素材类型!', 'error'); // } // foreach ($files as $name) { // $_model = clone $model; // $_model->setAttributes([ // 'type' => $mediaType, // 'material' => '' // ]); // $uploadedFile = UploadedFile::getInstanceByName($name); // $result = $this->getWechat()->getSdk()->uploadMedia($uploadedFile->tempName, $mediaType); // } // } return $this->render('upload', [ 'model' => $model ]); }
php
public function actionUpload() { $model = new MediaForm(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->upload()) { return $this->message('上传成功', 'success'); } } // $files = static::getFiles(); // if (!empty($files)) { // if (($mediaType = Yii::$app->request->post('mediaType')) === null) { // return $this->message('错误的媒体素材类型!', 'error'); // } // foreach ($files as $name) { // $_model = clone $model; // $_model->setAttributes([ // 'type' => $mediaType, // 'material' => '' // ]); // $uploadedFile = UploadedFile::getInstanceByName($name); // $result = $this->getWechat()->getSdk()->uploadMedia($uploadedFile->tempName, $mediaType); // } // } return $this->render('upload', [ 'model' => $model ]); }
[ "public", "function", "actionUpload", "(", ")", "{", "$", "model", "=", "new", "MediaForm", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", ")", "{", "$", "model", ...
上传图片接口 @throws NotFoundHttpException
[ "上传图片接口" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/MediaController.php#L35-L62
callmez/yii2-wechat
controllers/MediaController.php
MediaController.actionCreate
public function actionCreate() { $media = new MediaForm($this->getWechat()); $news = new MediaNewsForm(); $request = Yii::$app->request; if ($request->getIsPost()) { $post = $request->post(); switch ($request->post('mediaType')) { case Media::TYPE_MEDIA: $media->load($post); $media->file = UploadedFile::getInstance($media, 'file'); if ($media->save()) { return $this->message('操作成功!', 'success'); } break; case Media::TYPE_NEWS: $news->load($post); if ($news->save()) { } break; default: throw new NotFoundHttpException('The requested page does not exist.'); } } return $this->render('create', [ 'media' => $media, 'news' => $news ]); }
php
public function actionCreate() { $media = new MediaForm($this->getWechat()); $news = new MediaNewsForm(); $request = Yii::$app->request; if ($request->getIsPost()) { $post = $request->post(); switch ($request->post('mediaType')) { case Media::TYPE_MEDIA: $media->load($post); $media->file = UploadedFile::getInstance($media, 'file'); if ($media->save()) { return $this->message('操作成功!', 'success'); } break; case Media::TYPE_NEWS: $news->load($post); if ($news->save()) { } break; default: throw new NotFoundHttpException('The requested page does not exist.'); } } return $this->render('create', [ 'media' => $media, 'news' => $news ]); }
[ "public", "function", "actionCreate", "(", ")", "{", "$", "media", "=", "new", "MediaForm", "(", "$", "this", "->", "getWechat", "(", ")", ")", ";", "$", "news", "=", "new", "MediaNewsForm", "(", ")", ";", "$", "request", "=", "Yii", "::", "$", "ap...
Creates a new Media model. If creation is successful, the browser will be redirected to the 'view' page. @return mixed
[ "Creates", "a", "new", "Media", "model", ".", "If", "creation", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/MediaController.php#L96-L126
callmez/yii2-wechat
controllers/MediaController.php
MediaController.getFiles
public static function getFiles() { if (self::$_files === null) { self::$_files = []; if (isset($_FILES) && is_array($_FILES)) { foreach ($_FILES as $class => $info) { self::getUploadFilesRecursive($class, $info['name'], $info['error']); } } } return self::$_files; }
php
public static function getFiles() { if (self::$_files === null) { self::$_files = []; if (isset($_FILES) && is_array($_FILES)) { foreach ($_FILES as $class => $info) { self::getUploadFilesRecursive($class, $info['name'], $info['error']); } } } return self::$_files; }
[ "public", "static", "function", "getFiles", "(", ")", "{", "if", "(", "self", "::", "$", "_files", "===", "null", ")", "{", "self", "::", "$", "_files", "=", "[", "]", ";", "if", "(", "isset", "(", "$", "_FILES", ")", "&&", "is_array", "(", "$", ...
获取上传文件 @return array
[ "获取上传文件" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/MediaController.php#L185-L196
callmez/yii2-wechat
controllers/MediaController.php
MediaController.getUploadFilesRecursive
protected static function getUploadFilesRecursive($key, $names, $errors) { if (is_array($names)) { foreach ($names as $i => $name) { static::getUploadFilesRecursive($key . '[' . $i . ']', $name, $errors); } } elseif ($errors !== UPLOAD_ERR_NO_FILE) { self::$_files[] = $key; } }
php
protected static function getUploadFilesRecursive($key, $names, $errors) { if (is_array($names)) { foreach ($names as $i => $name) { static::getUploadFilesRecursive($key . '[' . $i . ']', $name, $errors); } } elseif ($errors !== UPLOAD_ERR_NO_FILE) { self::$_files[] = $key; } }
[ "protected", "static", "function", "getUploadFilesRecursive", "(", "$", "key", ",", "$", "names", ",", "$", "errors", ")", "{", "if", "(", "is_array", "(", "$", "names", ")", ")", "{", "foreach", "(", "$", "names", "as", "$", "i", "=>", "$", "name", ...
递归查询上传文件 @param $key @param $names @param $errors
[ "递归查询上传文件" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/controllers/MediaController.php#L204-L213
callmez/yii2-wechat
models/MessageHistoryQuery.php
MessageHistoryQuery.wechatFans
public function wechatFans($original, $openId) { return $this->orWhere([ 'from' => $openId, 'to' => $original ])->orWhere([ 'to' => $openId, 'from' => $original ]); }
php
public function wechatFans($original, $openId) { return $this->orWhere([ 'from' => $openId, 'to' => $original ])->orWhere([ 'to' => $openId, 'from' => $original ]); }
[ "public", "function", "wechatFans", "(", "$", "original", ",", "$", "openId", ")", "{", "return", "$", "this", "->", "orWhere", "(", "[", "'from'", "=>", "$", "openId", ",", "'to'", "=>", "$", "original", "]", ")", "->", "orWhere", "(", "[", "'to'", ...
查找指定公众号 @param $openId @param $original @return $this
[ "查找指定公众号" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/models/MessageHistoryQuery.php#L25-L34
callmez/yii2-wechat
components/ModuleMigration.php
ModuleMigration.to
final public function to($fromVersion, $toVersion) { $transaction = $this->db->beginTransaction(); try { if ($this->upgrade($fromVersion, $toVersion) === false) { $transaction->rollBack(); return false; } $transaction->commit(); } catch (\Exception $e) { Yii::warning("Exception: " . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")", __METHOD__); $transaction->rollBack(); return false; } return null; }
php
final public function to($fromVersion, $toVersion) { $transaction = $this->db->beginTransaction(); try { if ($this->upgrade($fromVersion, $toVersion) === false) { $transaction->rollBack(); return false; } $transaction->commit(); } catch (\Exception $e) { Yii::warning("Exception: " . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")", __METHOD__); $transaction->rollBack(); return false; } return null; }
[ "final", "public", "function", "to", "(", "$", "fromVersion", ",", "$", "toVersion", ")", "{", "$", "transaction", "=", "$", "this", "->", "db", "->", "beginTransaction", "(", ")", ";", "try", "{", "if", "(", "$", "this", "->", "upgrade", "(", "$", ...
升级到指定版本
[ "升级到指定版本" ]
train
https://github.com/callmez/yii2-wechat/blob/1f6f8894fcb9d71223c1714de15fa635f438bce9/components/ModuleMigration.php#L64-L82
snowair/phalcon-debugbar
src/DataCollector/SessionCollector.php
SessionCollector.collect
function collect() { $data = array(); if ( !empty($_SESSION) ) { $opt = $this->session->getOptions(); $prefix = 0; if (isset($opt['uniqueId'])) { $prefix = strlen($opt['uniqueId']); } foreach ($_SESSION as $key => $value) { if (strpos( $key, 'PHPDEBUGBAR_STACK_DATA' )===false) { @$data[ substr_replace($key,'',0,$prefix)] = is_string($value) ? $value : $this->formatVar($value); } } } return $data; }
php
function collect() { $data = array(); if ( !empty($_SESSION) ) { $opt = $this->session->getOptions(); $prefix = 0; if (isset($opt['uniqueId'])) { $prefix = strlen($opt['uniqueId']); } foreach ($_SESSION as $key => $value) { if (strpos( $key, 'PHPDEBUGBAR_STACK_DATA' )===false) { @$data[ substr_replace($key,'',0,$prefix)] = is_string($value) ? $value : $this->formatVar($value); } } } return $data; }
[ "function", "collect", "(", ")", "{", "$", "data", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "_SESSION", ")", ")", "{", "$", "opt", "=", "$", "this", "->", "session", "->", "getOptions", "(", ")", ";", "$", "prefix", "=", ...
Called by the DebugBar when data needs to be collected @return array Collected data
[ "Called", "by", "the", "DebugBar", "when", "data", "needs", "to", "be", "collected" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/DataCollector/SessionCollector.php#L28-L43
snowair/phalcon-debugbar
src/DataCollector/PhalconRequestCollector.php
PhalconRequestCollector.collect
function collect() { $request = $this->request; $response = $this->response; $status = $response->getHeaders()->get('Status')?:'200 ok'; $responseHeaders = $response->getHeaders()->toArray()?:headers_list(); $cookies = $_COOKIE; unset($cookies[session_name()]); $cookies_service = $response->getCookies(); if ( $cookies_service ) { $useEncrypt = true; if ( $cookies_service->isUsingEncryption() && $this->di->has('crypt') && !$this->di['crypt']->getKey()) { $useEncrypt = false; } if ( !$cookies_service->isUsingEncryption() ) { $useEncrypt = false; } foreach ( $cookies as $key=>$vlaue ) { $cookies[$key] = $cookies_service->get($key)->useEncryption($useEncrypt)->getValue(); } } $data = array( 'status' => $status, 'request_query' => $request->getQuery(), 'request_post' => $request->getPost(), 'request_body' => $request->getRawBody(), 'request_cookies' => $cookies, 'request_server' => $_SERVER, 'response_headers' => $responseHeaders, 'response_body' => $request->isAjax()?$response->getContent():'', ); if ( Version::getId()<2000000 && $request->isAjax()) { $data['request_headers']=''; // 1.3.x has a ajax bug , so we use empty string insdead. }else{ $data['request_headers']=$request->getHeaders(); } $data = array_filter($data); if ( isset($data['request_query']['_url']) ) { unset($data['request_query']['_url']); } if ( empty($data['request_query']) ) { unset($data['request_query']); } if (isset($data['request_headers']['php-auth-pw'])) { $data['request_headers']['php-auth-pw'] = '******'; } if (isset($data['request_server']['PHP_AUTH_PW'])) { $data['request_server']['PHP_AUTH_PW'] = '******'; } foreach ($data as $key => $var) { if (!is_string($data[$key])) { $data[$key] = $this->formatVar($var); } } return $data; }
php
function collect() { $request = $this->request; $response = $this->response; $status = $response->getHeaders()->get('Status')?:'200 ok'; $responseHeaders = $response->getHeaders()->toArray()?:headers_list(); $cookies = $_COOKIE; unset($cookies[session_name()]); $cookies_service = $response->getCookies(); if ( $cookies_service ) { $useEncrypt = true; if ( $cookies_service->isUsingEncryption() && $this->di->has('crypt') && !$this->di['crypt']->getKey()) { $useEncrypt = false; } if ( !$cookies_service->isUsingEncryption() ) { $useEncrypt = false; } foreach ( $cookies as $key=>$vlaue ) { $cookies[$key] = $cookies_service->get($key)->useEncryption($useEncrypt)->getValue(); } } $data = array( 'status' => $status, 'request_query' => $request->getQuery(), 'request_post' => $request->getPost(), 'request_body' => $request->getRawBody(), 'request_cookies' => $cookies, 'request_server' => $_SERVER, 'response_headers' => $responseHeaders, 'response_body' => $request->isAjax()?$response->getContent():'', ); if ( Version::getId()<2000000 && $request->isAjax()) { $data['request_headers']=''; // 1.3.x has a ajax bug , so we use empty string insdead. }else{ $data['request_headers']=$request->getHeaders(); } $data = array_filter($data); if ( isset($data['request_query']['_url']) ) { unset($data['request_query']['_url']); } if ( empty($data['request_query']) ) { unset($data['request_query']); } if (isset($data['request_headers']['php-auth-pw'])) { $data['request_headers']['php-auth-pw'] = '******'; } if (isset($data['request_server']['PHP_AUTH_PW'])) { $data['request_server']['PHP_AUTH_PW'] = '******'; } foreach ($data as $key => $var) { if (!is_string($data[$key])) { $data[$key] = $this->formatVar($var); } } return $data; }
[ "function", "collect", "(", ")", "{", "$", "request", "=", "$", "this", "->", "request", ";", "$", "response", "=", "$", "this", "->", "response", ";", "$", "status", "=", "$", "response", "->", "getHeaders", "(", ")", "->", "get", "(", "'Status'", ...
Called by the DebugBar when data needs to be collected @return array Collected data
[ "Called", "by", "the", "DebugBar", "when", "data", "needs", "to", "be", "collected" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/DataCollector/PhalconRequestCollector.php#L45-L107
snowair/phalcon-debugbar
src/PhalconDebugbar.php
PhalconDebugbar.boot
public function boot() { if (!$this->isEnabled() ) { return; } $debugbar = $this; if ( !$this->isDataPersisted() ) { $this->selectStorage($debugbar); // for normal request and debugbar request both } if ($this->booted) { return; } $this->booted = true; if ( isset($_REQUEST['_url']) and $_REQUEST['_url']=='/favicon.ico' || isset($_SERVER['REQUEST_URI']) and $_SERVER['REQUEST_URI']=='/favicon.ico'|| !$this->isEnabled()) { return; } $this->initCollectors(); $renderer = $this->getJavascriptRenderer(); $renderer->setIncludeVendors($this->config->get('include_vendors', true)); $renderer->setBindAjaxHandlerToXHR($this->config->get('capture_ajax', true)); $renderer->setAjaxHandlerAutoShow($this->config->get('ajax_handler_auto_show', true)); }
php
public function boot() { if (!$this->isEnabled() ) { return; } $debugbar = $this; if ( !$this->isDataPersisted() ) { $this->selectStorage($debugbar); // for normal request and debugbar request both } if ($this->booted) { return; } $this->booted = true; if ( isset($_REQUEST['_url']) and $_REQUEST['_url']=='/favicon.ico' || isset($_SERVER['REQUEST_URI']) and $_SERVER['REQUEST_URI']=='/favicon.ico'|| !$this->isEnabled()) { return; } $this->initCollectors(); $renderer = $this->getJavascriptRenderer(); $renderer->setIncludeVendors($this->config->get('include_vendors', true)); $renderer->setBindAjaxHandlerToXHR($this->config->get('capture_ajax', true)); $renderer->setAjaxHandlerAutoShow($this->config->get('ajax_handler_auto_show', true)); }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "return", ";", "}", "$", "debugbar", "=", "$", "this", ";", "if", "(", "!", "$", "this", "->", "isDataPersisted", "(", ")", ")", "{...
启动debugbar: 设置collector
[ "启动debugbar", ":", "设置collector" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/PhalconDebugbar.php#L193-L218
snowair/phalcon-debugbar
src/PhalconDebugbar.php
PhalconDebugbar.attachView
public function attachView( $view ) { // You can add only One View instance if ( isset($this->collectors['views']) ) { return; } if ( is_string( $view ) ) { $view = $this->di[$view]; } // try to add PhalconDebugbar VoltFunctions $engins =$view->getRegisteredEngines(); if ( isset($engins['.volt']) ) { $volt = $engins['.volt']; if ( is_object( $volt ) ) { if ( $volt instanceof \Closure ) { $volt = $volt($view,$this->di); } }elseif(is_string($volt)){ if ( class_exists( $volt ) ) { $volt = new Volt( $view, $this->di ); }elseif( $this->di->has($volt)){ $volt = $this->di->getShared($volt,array($view,$this->di)); } } $engins['.volt'] = $volt; $view->registerEngines($engins); $volt->getCompiler()->addExtension(new VoltFunctions($this->di)); } // attach the ViewCollector if ( !$this->shouldCollect('view', true) ) { return; } $viewProfiler = new Registry(); $viewProfiler->templates=array(); $viewProfiler->engines = $view->getRegisteredEngines(); $config = $this->config; $eventsManager = $view->getEventsManager(); if ( !is_object( $eventsManager ) ) { $eventsManager = new Manager(); } $eventsManager->attach('view:beforeRender',function($event,$view) use($viewProfiler) { $viewProfiler->startRender= microtime(true); }); $eventsManager->attach('view:afterRender',function($event,$view) use($viewProfiler,$config) { $viewProfiler->stopRender= microtime(true); if ( $config->options->views->get( 'data', false ) ) { $viewProfiler->params = $view->getParamsToView(); }else{ $viewProfiler->params = null; } }); $eventsManager->attach('view:beforeRenderView',function($event,$view) use($viewProfiler) { $viewFilePath = $view->getActiveRenderPath(); if (Version::getId()>=2000140) { if ( !$view instanceof \Phalcon\Mvc\ViewInterface && $view instanceof \Phalcon\Mvc\ViewBaseInterface) { $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } }elseif( $view instanceof Simple){ $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } $templates = $viewProfiler->templates; $templates[$viewFilePath]['startTime'] = microtime(true); $viewProfiler->templates = $templates; }); $eventsManager->attach('view:afterRenderView',function($event,$view) use($viewProfiler) { $viewFilePath = $view->getActiveRenderPath(); if (Version::getId()>=2000140) { if ( !$view instanceof \Phalcon\Mvc\ViewInterface && $view instanceof \Phalcon\Mvc\ViewBaseInterface) { $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } }elseif( $view instanceof Simple){ $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } $templates = $viewProfiler->templates; $templates[$viewFilePath]['stopTime'] = microtime(true); $viewProfiler->templates = $templates; }); $view->setEventsManager($eventsManager); $collector = new ViewCollector($viewProfiler,$view); $this->addCollector($collector); }
php
public function attachView( $view ) { // You can add only One View instance if ( isset($this->collectors['views']) ) { return; } if ( is_string( $view ) ) { $view = $this->di[$view]; } // try to add PhalconDebugbar VoltFunctions $engins =$view->getRegisteredEngines(); if ( isset($engins['.volt']) ) { $volt = $engins['.volt']; if ( is_object( $volt ) ) { if ( $volt instanceof \Closure ) { $volt = $volt($view,$this->di); } }elseif(is_string($volt)){ if ( class_exists( $volt ) ) { $volt = new Volt( $view, $this->di ); }elseif( $this->di->has($volt)){ $volt = $this->di->getShared($volt,array($view,$this->di)); } } $engins['.volt'] = $volt; $view->registerEngines($engins); $volt->getCompiler()->addExtension(new VoltFunctions($this->di)); } // attach the ViewCollector if ( !$this->shouldCollect('view', true) ) { return; } $viewProfiler = new Registry(); $viewProfiler->templates=array(); $viewProfiler->engines = $view->getRegisteredEngines(); $config = $this->config; $eventsManager = $view->getEventsManager(); if ( !is_object( $eventsManager ) ) { $eventsManager = new Manager(); } $eventsManager->attach('view:beforeRender',function($event,$view) use($viewProfiler) { $viewProfiler->startRender= microtime(true); }); $eventsManager->attach('view:afterRender',function($event,$view) use($viewProfiler,$config) { $viewProfiler->stopRender= microtime(true); if ( $config->options->views->get( 'data', false ) ) { $viewProfiler->params = $view->getParamsToView(); }else{ $viewProfiler->params = null; } }); $eventsManager->attach('view:beforeRenderView',function($event,$view) use($viewProfiler) { $viewFilePath = $view->getActiveRenderPath(); if (Version::getId()>=2000140) { if ( !$view instanceof \Phalcon\Mvc\ViewInterface && $view instanceof \Phalcon\Mvc\ViewBaseInterface) { $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } }elseif( $view instanceof Simple){ $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } $templates = $viewProfiler->templates; $templates[$viewFilePath]['startTime'] = microtime(true); $viewProfiler->templates = $templates; }); $eventsManager->attach('view:afterRenderView',function($event,$view) use($viewProfiler) { $viewFilePath = $view->getActiveRenderPath(); if (Version::getId()>=2000140) { if ( !$view instanceof \Phalcon\Mvc\ViewInterface && $view instanceof \Phalcon\Mvc\ViewBaseInterface) { $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } }elseif( $view instanceof Simple){ $viewFilePath = realpath($view->getViewsDir()).DIRECTORY_SEPARATOR.$viewFilePath; } $templates = $viewProfiler->templates; $templates[$viewFilePath]['stopTime'] = microtime(true); $viewProfiler->templates = $templates; }); $view->setEventsManager($eventsManager); $collector = new ViewCollector($viewProfiler,$view); $this->addCollector($collector); }
[ "public", "function", "attachView", "(", "$", "view", ")", "{", "// You can add only One View instance\r", "if", "(", "isset", "(", "$", "this", "->", "collectors", "[", "'views'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "is_string", "(", "$", ...
@param $view @throws \DebugBar\DebugBarException
[ "@param", "$view" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/PhalconDebugbar.php#L347-L441
snowair/phalcon-debugbar
src/PhalconDebugbar.php
PhalconDebugbar.getJavascriptRenderer
public function getJavascriptRenderer($baseUrl = null, $basePath = null) { if ($this->jsRenderer === null) { $this->jsRenderer = new JsRender($this, $baseUrl, $basePath); $this->jsRenderer->setUrlGenerator($this->di['url']); } return $this->jsRenderer; }
php
public function getJavascriptRenderer($baseUrl = null, $basePath = null) { if ($this->jsRenderer === null) { $this->jsRenderer = new JsRender($this, $baseUrl, $basePath); $this->jsRenderer->setUrlGenerator($this->di['url']); } return $this->jsRenderer; }
[ "public", "function", "getJavascriptRenderer", "(", "$", "baseUrl", "=", "null", ",", "$", "basePath", "=", "null", ")", "{", "if", "(", "$", "this", "->", "jsRenderer", "===", "null", ")", "{", "$", "this", "->", "jsRenderer", "=", "new", "JsRender", ...
Returns a JavascriptRenderer for this instance @param string $baseUrl @param null $basePath @return JsRender
[ "Returns", "a", "JavascriptRenderer", "for", "this", "instance" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/PhalconDebugbar.php#L534-L541
snowair/phalcon-debugbar
src/PhalconDebugbar.php
PhalconDebugbar.modifyResponse
public function modifyResponse($response){ $config = $this->config; if (!$this->isEnabled() ) { return $response; } if ($this->shouldCollect('config', false) && $this->di->has('config')) { try { $config_data = $this->di['config']->toArray(); $protect = $config->options->config->get('protect'); $configCollector = new ConfigCollector($config_data); $configCollector->setProtect($protect); $this->addCollector($configCollector); } catch (\Exception $e) { $this->addException( new Exception( 'Cannot add ConfigCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e ) ); } } if ($this->shouldCollect('session') && $this->di->has('session') ) { try { $this->addCollector(new SessionCollector($this->di['session'])); } catch (\Exception $e) { $this->addException( new Exception( 'Cannot add SessionCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e ) ); } } if ($this->shouldCollect('phalcon_request', true) and !$this->hasCollector('request')) { try { $this->addCollector(new PhalconRequestCollector($this->di['request'],$response,$this->di)); } catch (\Exception $e) { $this->addException( new Exception( 'Cannot add PhalconRequestCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e ) ); } } if( $this->hasCollector('pdo') ){ /** @var Profiler $profiler */ $profiler = $this->getCollector('pdo')->getProfiler(); $profiler->handleFailed(); } if ( $this->isDebugbarRequest ) { // Notice: All Collectors must be added before check if is debugbar request. return $response; } try { if ($this->isRedirection($response)) { $this->stackData(); } elseif ( $this->isJsonRequest() && $config->get('capture_ajax', true) ) { $this->sendDataInHeaders(true); } elseif ( ($content_type = $response->getHeaders()->get('Content-Type')) && strpos($response->getHeaders()->get('Content-Type'), 'html') !== false && $config->get('inject', true) ) { $response->setHeader('Phalcon-Debugbar','on'); $this->injectDebugbar($response); } elseif ( ($content_type = $response->getHeaders()->get('Content-Type')) && strpos($response->getHeaders()->get('Content-Type'), 'html') === false ) { $this->collect(); } elseif($config->get('inject', true)) { $response->setHeader('Phalcon-Debugbar','on'); $this->injectDebugbar($response); }else{ $this->collect(); } } catch (\Exception $e) { $this->addException($e); } // Stop further rendering (on subrequests etc) $this->disable(); return $response; }
php
public function modifyResponse($response){ $config = $this->config; if (!$this->isEnabled() ) { return $response; } if ($this->shouldCollect('config', false) && $this->di->has('config')) { try { $config_data = $this->di['config']->toArray(); $protect = $config->options->config->get('protect'); $configCollector = new ConfigCollector($config_data); $configCollector->setProtect($protect); $this->addCollector($configCollector); } catch (\Exception $e) { $this->addException( new Exception( 'Cannot add ConfigCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e ) ); } } if ($this->shouldCollect('session') && $this->di->has('session') ) { try { $this->addCollector(new SessionCollector($this->di['session'])); } catch (\Exception $e) { $this->addException( new Exception( 'Cannot add SessionCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e ) ); } } if ($this->shouldCollect('phalcon_request', true) and !$this->hasCollector('request')) { try { $this->addCollector(new PhalconRequestCollector($this->di['request'],$response,$this->di)); } catch (\Exception $e) { $this->addException( new Exception( 'Cannot add PhalconRequestCollector to Phalcon Debugbar: ' . $e->getMessage(), $e->getCode(), $e ) ); } } if( $this->hasCollector('pdo') ){ /** @var Profiler $profiler */ $profiler = $this->getCollector('pdo')->getProfiler(); $profiler->handleFailed(); } if ( $this->isDebugbarRequest ) { // Notice: All Collectors must be added before check if is debugbar request. return $response; } try { if ($this->isRedirection($response)) { $this->stackData(); } elseif ( $this->isJsonRequest() && $config->get('capture_ajax', true) ) { $this->sendDataInHeaders(true); } elseif ( ($content_type = $response->getHeaders()->get('Content-Type')) && strpos($response->getHeaders()->get('Content-Type'), 'html') !== false && $config->get('inject', true) ) { $response->setHeader('Phalcon-Debugbar','on'); $this->injectDebugbar($response); } elseif ( ($content_type = $response->getHeaders()->get('Content-Type')) && strpos($response->getHeaders()->get('Content-Type'), 'html') === false ) { $this->collect(); } elseif($config->get('inject', true)) { $response->setHeader('Phalcon-Debugbar','on'); $this->injectDebugbar($response); }else{ $this->collect(); } } catch (\Exception $e) { $this->addException($e); } // Stop further rendering (on subrequests etc) $this->disable(); return $response; }
[ "public", "function", "modifyResponse", "(", "$", "response", ")", "{", "$", "config", "=", "$", "this", "->", "config", ";", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "return", "$", "response", ";", "}", "if", "(", "$", ...
@param Response $response @return mixed @throws Exception
[ "@param", "Response", "$response" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/PhalconDebugbar.php#L549-L648
snowair/phalcon-debugbar
src/PhalconDebugbar.php
PhalconDebugbar.isRedirection
public function isRedirection($response) { $status = $response->getHeaders()->get('Status'); $code = (int)strstr($status,' ',true); return $code >= 300 && $code < 400; }
php
public function isRedirection($response) { $status = $response->getHeaders()->get('Status'); $code = (int)strstr($status,' ',true); return $code >= 300 && $code < 400; }
[ "public", "function", "isRedirection", "(", "$", "response", ")", "{", "$", "status", "=", "$", "response", "->", "getHeaders", "(", ")", "->", "get", "(", "'Status'", ")", ";", "$", "code", "=", "(", "int", ")", "strstr", "(", "$", "status", ",", ...
@param Response $response @return bool
[ "@param", "Response", "$response" ]
train
https://github.com/snowair/phalcon-debugbar/blob/80ccce21b206ab90d40bd5c33f3173831ab9ed9c/src/PhalconDebugbar.php#L734-L738