當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Event::trigger方法代碼示例

本文整理匯總了PHP中yii\base\Event::trigger方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::trigger方法的具體用法?PHP Event::trigger怎麽用?PHP Event::trigger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\Event的用法示例。


在下文中一共展示了Event::trigger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parse

 /**
  * Parse a Less file to CSS
  */
 public function parse($src, $dst, $options)
 {
     $this->auto = isset($options['auto']) ? $options['auto'] : $this->auto;
     $variables = $this->variables;
     $assetManager = Yii::$app->assetManager;
     // Final url of the file being compiled
     $assetUrl = substr($dst, strpos($assetManager->basePath, $assetManager->baseUrl));
     $variables['published-url'] = '"' . $assetUrl . '"';
     // Root for the published folder
     $variables['published-base-url'] = '"/' . implode('/', array_slice(explode('/', ltrim($assetUrl, '/')), 0, 2)) . '"';
     $less = new \lessc();
     $less->setVariables($variables);
     // Compressed setting
     if ($this->compressed) {
         $less->setFormatter('compressed');
     }
     \Less_Parser::$default_options['compress'] = $this->compressed;
     \Less_Parser::$default_options['relativeUrls'] = $this->relativeUrls;
     // Send out pre-compile event
     $event = new \yii\base\Event();
     $this->runtime = ['sourceFile' => $src, 'destinationFile' => $dst, 'compiler' => $less];
     $event->sender = $this;
     Event::trigger($this, self::EVENT_BEFORE_COMPILE, $event);
     try {
         if ($this->auto) {
             /* @var FileCache $cacheMgr */
             $cacheMgr = Yii::createObject('yii\\caching\\FileCache');
             $cacheMgr->init();
             $cacheId = 'less#' . $dst;
             $cache = $cacheMgr->get($cacheId);
             if ($cache === false || @filemtime($dst) < @filemtime($src)) {
                 $cache = $src;
             }
             $newCache = $less->cachedCompile($cache);
             if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
                 $cacheMgr->set($cacheId, $newCache);
                 file_put_contents($dst, $newCache['compiled']);
             }
         } else {
             $less->compileFile($src, $dst);
         }
         // If needed, respect the users configuration
         if ($assetManager->fileMode !== null) {
             @chmod($dst, $assetManager->fileMode);
         }
         unset($this->less);
     } catch (\Exception $e) {
         throw new \Exception(__CLASS__ . ': Failed to compile less file : ' . $e->getMessage() . '.');
     }
 }
開發者ID:dfatt,項目名稱:yii2-asset-converter,代碼行數:53,代碼來源:Less.php

示例2: actionAccount

 /**
  * Displays page where user can update account settings (username, email or password).
  * @return string|\yii\web\Response
  */
 public function actionAccount()
 {
     $profileModel = $this->finder->findProfileById(\Yii::$app->user->identity->getId());
     $accountModel = \Yii::createObject(SettingsForm::className());
     $this->performAjaxValidation($profileModel);
     $this->performAjaxValidation($accountModel);
     if ($profileModel->load(\Yii::$app->request->post()) && $accountModel->load(\Yii::$app->request->post())) {
         if ($profileModel->validate() && $accountModel->validate() && $profileModel->save() && $accountModel->save()) {
             Event::trigger(BaseController::class, BaseController::EVENT_MODEL_UPDATED, new MessageEvent($profileModel));
             \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'Your account has been updated'));
             return $this->refresh();
         }
     }
     return $this->render('account', ['profileModel' => $profileModel, 'accountModel' => $accountModel]);
 }
開發者ID:qi-interactive,項目名稱:matacms-user,代碼行數:19,代碼來源:SettingsController.php

示例3: fetchItems

 private function fetchItems()
 {
     $items = is_array($this->items) ? $this->items : $this->invoke($this->items);
     if (isset($this->empty)) {
         $items = ArrayHelper::merge(['' => empty($this->empty) ? Yii::t('gromver.models', 'Select...') : $this->empty], $items);
     }
     if (isset($this->editable) && !isset($this->multiple) && ($value = $this->getValue()) && !array_key_exists($value, $items)) {
         $items[$value] = $value;
     }
     if ($this->getModel() instanceof ObjectModelInterface) {
         preg_match_all('/\\[([a-zA-Z]\\w*)\\]/', Html::getInputName($this->getModel(), $this->getAttribute()), $matches);
         $event = new ListItemsEvent(['items' => $items, 'model' => $this->getModel()->getObjectModel(), 'attribute' => end($matches[1])]);
         Event::trigger(static::className(), self::EVENT_FETCH_ITEMS, $event);
         return $event->items;
     }
     return $items;
 }
開發者ID:gromver,項目名稱:yii2-models,代碼行數:17,代碼來源:ListField.php

示例4: widget

 /**
  * Creates a widget instance and runs it.
  * 
  * The widget rendering result is returned by this method.
  * @param array $config name-value pairs that will be used to initialize the object properties
  * @return string the rendering result of the widget.
  * @throws \Exception
  */
 public static function widget($config = [])
 {
     if (!isset($config['class'])) {
         $config['class'] = get_called_class();
     }
     Event::trigger(self::className(), self::EVENT_CREATE, new WidgetCreateEvent($config));
     ob_start();
     ob_implicit_flush(false);
     try {
         /* @var $widget Widget */
         $widget = Yii::createObject($config);
         $out = $widget->run();
     } catch (\Exception $e) {
         // close the output buffer opened above if it has not been closed already
         if (ob_get_level() > 0) {
             ob_end_clean();
         }
         throw $e;
     }
     $widget->trigger(self::EVENT_AFTER_RUN);
     return ob_get_clean() . $out;
 }
開發者ID:SimonBaeumer,項目名稱:humhub,代碼行數:30,代碼來源:Widget.php

示例5: _createRatingAddEvent

 /**
  * @param $id
  * @param $rating
  */
 private function _createRatingAddEvent($id, $rating)
 {
     $event = new RatingAddEvent();
     $event->recordId = $id;
     $event->rating = $rating;
     $event->userId = \Yii::$app->user->id;
     Event::trigger(RatingModule::className(), RatingModule::EVENT_RATING_ADD, $event);
 }
開發者ID:MaizerGomes,項目名稱:openbay,代碼行數:12,代碼來源:DefaultController.php

示例6: trigger

 /**
  * 觸發事件(對象的觸發)
  * @param $name
  */
 public function trigger($name, Event $event = null)
 {
     $this->ensureBehaviors();
     if (!empty($this->_events[$name])) {
         //存在該事件名稱
         if ($event === null) {
             $event = new Event();
         }
         if ($event->sender === null) {
             $event->sender = $this;
         }
         $event->handled = false;
         $event->name = $name;
         foreach ($this->_events[$name] as $handler) {
             $event->data = $handler[1];
             call_user_func($handler[0], $event);
             if ($event->handled) {
                 return;
             }
         }
     }
     /**
      * 觸發該對象的類的事件,如果該類的每個對象都需要綁定該事件,則把該事件綁定到該類上麵,當觸發該對象的事件時,則會自動觸發該對象的類事件,避免每個類都需要進行綁定
      */
     Event::trigger($this, $name, $event);
 }
開發者ID:xinyifuyun,項目名稱:code-yii,代碼行數:30,代碼來源:Component.php

示例7: beforeSave

 /**
  * changed beforeSave as I want to trigger an individual event for this
  * @param  [type] $insert [description]
  * @return boolean         [description]
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         Event::trigger(self::className(), self::EVENT_ACTIVITY_UPDATE, new Event(['sender' => $this]));
         \Yii::trace('The Event ' . self::EVENT_ACTIVITY_UPDATE . ' should be fired, pls. check!');
         $nextDate = new DateTime($this->next_at);
         $this->next_at = $nextDate->format('U');
         if (is_null($this->next_by)) {
             $this->next_by = $this->created_by;
         }
         return true;
     }
     return false;
 }
開發者ID:frenzelgmbh,項目名稱:cm-activity,代碼行數:19,代碼來源:Activity.php

示例8: actionClear

 /**
  * @return array
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function actionClear()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $result = [];
     $order = $this->loadOrder();
     if (null === $order->stage || true === $order->getImmutability(Order::IMMUTABLE_USER)) {
         throw new BadRequestHttpException();
     }
     $products = array_reduce($order->items, function ($res, $item) {
         $res[] = ['model' => $item->product, 'quantity' => $item->quantity, 'orderItem' => $item];
         return $res;
     }, []);
     /** @var OrderItem $item */
     foreach ($order->items as $item) {
         $item->delete();
     }
     Order::clearStaticOrder();
     $order = $this->loadOrder();
     $result['success'] = $order->calculate(true);
     $event = new CartActionEvent($order, $products);
     Event::trigger($this, self::EVENT_ACTION_CLEAR, $event);
     $result['additional'] = $event->getEventData();
     $result['products'] = $this->productsModelsToArray($products);
     return $result;
 }
開發者ID:lzpfmh,項目名稱:dotplant2,代碼行數:30,代碼來源:CartController.php

示例9: test

 public function test()
 {
     Event::trigger(TestEvent::className(), self::TEST);
 }
開發者ID:VampireMe,項目名稱:yii2test_advanced,代碼行數:4,代碼來源:TestEvent.php

示例10: trigger

 /**
  * Triggers an event.
  * This method represents the happening of an event. It invokes
  * all attached handlers for the event including class-level handlers.
  * @param string $name the event name
  * @param Event $event the event parameter. If not set, a default [[Event]] object will be created.
  */
 public function trigger($name, Event $event = null)
 {
     // 保證 behaviors 都加載進來了
     $this->ensureBehaviors();
     if (!empty($this->_events[$name])) {
         // 構建Event對象,為傳入到handler函數中做準備
         if ($event === null) {
             $event = new Event();
         }
         if ($event->sender === null) {
             $event->sender = $this;
         }
         $event->handled = false;
         $event->name = $name;
         foreach ($this->_events[$name] as $handler) {
             // 給event的data屬性賦值
             $event->data = $handler[1];
             // handler的函數中傳入了一個Event對象
             call_user_func($handler[0], $event);
             // stop further handling if the event is handled
             // 事件是否被handle,當handled被設置為true時,執行到這個event的時候,會停止,並忽略剩下的event
             if ($event->handled) {
                 return;
             }
         }
     }
     // invoke class-level attached handlers
     // 觸發class級別的handler
     Event::trigger($this, $name, $event);
 }
開發者ID:heartshare,項目名稱:yii2-2.0.3-annotated,代碼行數:37,代碼來源:Component.php

示例11: _createComplaintAddEvent

 /**
  * @param $recordId
  * @param $type
  */
 private function _createComplaintAddEvent($recordId, $type)
 {
     $event = new ComplaintAddEvent();
     $event->recordId = $recordId;
     $event->type = $type;
     $event->userId = \Yii::$app->user->id;
     $event->total = Complaint::find()->where(['record_id' => $recordId, 'type' => $type])->count();
     Event::trigger(ComplainModule::className(), ComplainModule::EVENT_COMPLAINT_ADD, $event);
 }
開發者ID:testbots,項目名稱:openbay,代碼行數:13,代碼來源:DefaultController.php

示例12: _createCommentAddEvent

 /**
  *
  */
 private function _createCommentAddEvent()
 {
     $event = new CommentAddEvent();
     $event->recordId = $this->_model->record_id;
     $event->userId = $this->_model->user_id;
     Event::trigger(CommentModule::className(), CommentModule::EVENT_COMMENT_ADD, $event);
 }
開發者ID:MaizerGomes,項目名稱:openbay,代碼行數:10,代碼來源:CommentWidget.php

示例13: actionProcessConfigControl

 public function actionProcessConfigControl()
 {
     $request = \Yii::$app->request;
     $actionType = $request->post('actionType');
     $response = ['isSuccessful' => true];
     try {
         $group = new ProcessConfig($request->post('groupName'));
         if ($group->hasMethod($actionType)) {
             $group->{$actionType}();
         }
         Event::trigger(Supervisor::className(), Supervisor::EVENT_CONFIG_CHANGED);
     } catch (SupervisorException $error) {
         $response = ['isSuccessful' => false, 'error' => $error->getMessage()];
     }
     return $response;
 }
開發者ID:HEXA-UA,項目名稱:supervisor-manager,代碼行數:16,代碼來源:DefaultController.php

示例14: trigger

 /**
  * Triggers an event.
  * This method represents the happening of an event. It invokes
  * all attached handlers for the event including class-level handlers.
  * @param string $name the event name
  * @param Event $event the event parameter. If not set, a default [[Event]] object will be created.
  * @return array|mixed
  */
 public function trigger($name, Event $event = null)
 {
     $return_data = [];
     if (!empty($this->_events[$name])) {
         if ($event === null) {
             $event = new Event();
         }
         if ($event->sender === null) {
             $event->sender = $this;
         }
         $event->handled = false;
         $event->name = $name;
         foreach ($this->_events[$name] as $handler) {
             $event->data = $handler[1];
             $return_data[] = call_user_func($handler[0], $event);
             // stop further handling if the event is handled
             if ($event->handled) {
                 break;
             }
         }
     }
     // invoke class-level attached handlers
     // but won't return anything in this case...
     Event::trigger($this, $name, $event);
     return $return_data;
 }
開發者ID:AtuinCMS,項目名稱:engine,代碼行數:34,代碼來源:Hooks.php

示例15: actionUpdate

 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'index' page.
  * @param  integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $user = $this->findModel($id);
     $user->scenario = 'update';
     $profile = $this->finder->findProfileById($id);
     $r = \Yii::$app->request;
     $this->performAjaxValidation([$user, $profile]);
     if ($user->load($r->post()) && $profile->load($r->post()) && $user->save() && $profile->save()) {
         Event::trigger(BaseController::class, BaseController::EVENT_MODEL_UPDATED, new MessageEvent($profile));
         $this->trigger(BaseController::EVENT_MODEL_UPDATED, new MessageEvent($user));
         \Yii::$app->getSession()->setFlash('success', \Yii::t('user', 'User has been updated'));
         return $this->redirect(['index']);
     }
     return $this->render('update', ['user' => $user, 'profile' => $profile, 'module' => $this->module]);
 }
開發者ID:qi-interactive,項目名稱:matacms-user,代碼行數:21,代碼來源:AdminController.php


注:本文中的yii\base\Event::trigger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。