예제 #1
0
 /**
  * Set available languages. This method accepts one parameter,
  * array contaning language codes prefably in short ISO form.
  * Example valid array and method calls:
  * ```php
  * $languages = ['en', 'pl', 'ru'];
  * $model->setLanguages($languages);
  * $model2->setLanguages(['en']);
  * ```
  * @param string[] $languages
  * @Ignored
  */
 public function setLanguages($languages)
 {
     $event = new ModelEvent($this);
     $event->data = $languages;
     if (!Event::valid($this, InternationalInterface::EventBeforeLanguagesSet, $event)) {
         return;
     }
     $this->_languages = $languages;
     Event::trigger($this, InternationalInterface::EventAfterLanguagesSet, $event);
 }
예제 #2
0
 /**
  * This method is invoked after deleting a record.
  * The default implementation raises the {@link onAfterDelete} event.
  * You may override this method to do postprocessing after the record is deleted.
  * Make sure you call the parent implementation so that the event is raised properly.
  * @since v1.0
  */
 private function _afterDelete()
 {
     $event = new ModelEvent($this->model);
     Event::trigger($this->model, EntityManagerInterface::EventAfterDelete, $event);
     (new Signal())->emit(new AfterDelete($this->model));
 }
예제 #3
0
파일: Event.php 프로젝트: maslosoft/mangan
 /**
  * Triggers a class-level event and checks if it's handled.
  * If don't have event handler returns true. If event handler is set, return true if `Event::handled`.
  * This method will cause invocation of event handlers that are attached to the named event
  * for the specified class and all its parent classes.
  * @param AnnotatedInterface $model the object specifying the class-level event.
  * @param string $name the event name.
  * @param ModelEvent $event the event parameter. If not set, a default [[Event]] object will be created.
  * @return bool|null True if handled, false otherway, null if not triggered
  */
 public static function handled(AnnotatedInterface $model, $name, $event = null)
 {
     if (Event::trigger($model, $name, $event)) {
         return $event->handled;
     }
     return true;
 }
예제 #4
0
파일: Finder.php 프로젝트: maslosoft/mangan
 /**
  * Creates an model with the given attributes.
  * This method is internally used by the find methods.
  * @param mixed[] $data attribute values (column name=>column value)
  * @return AnnotatedInterface|null the newly created document. The class of the object is the same as the model class.
  * Null is returned if the input data is false.
  * @since v1.0
  */
 protected function populateRecord($data)
 {
     if ($data !== null) {
         if (!empty($data['$err'])) {
             throw new ManganException(sprintf("There is an error in query: %s", $data['$err']));
         }
         $model = RawArray::toModel($data, $this->model);
         ScenarioManager::setScenario($model, ScenariosInterface::Update);
         Event::trigger($model, FinderInterface::EventAfterFind);
         return $model;
     } else {
         return null;
     }
 }