Пример #1
0
 /**
  * Returns the global Event Dispatcher object, only creating it
  * if it doesn't already exist.
  *
  * @return  FOFUtilsObservableDispatcher  The EventDispatcher object.
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new static();
     }
     return self::$instance;
 }
 /**
  * Execute plugins (system-level triggers) and fetch back an array with
  * their return values.
  *
  * @param   string  $event  The event (trigger) name, e.g. onBeforeScratchMyEar
  * @param   array   $data   A hash array of data sent to the plugins as part of the trigger
  *
  * @see FOFPlatformInterface::runPlugins()
  *
  * @return  array  A simple array containing the resutls of the plugins triggered
  */
 public function runPlugins($event, $data)
 {
     if (!$this->isCli()) {
         $dispatcher = FOFUtilsObservableDispatcher::getInstance();
         return $dispatcher->trigger($event, $data);
     } else {
         return array();
     }
 }
Пример #3
0
 /**
  * Method to allow derived classes to preprocess the form.
  *
  * @param   FOFForm  $form   A FOFForm object.
  * @param   mixed    &$data  The data expected for the form.
  * @param   string   $group  The name of the plugin group to import (defaults to "content").
  *
  * @return  void
  *
  * @see     FOFFormField
  * @since   2.0
  * @throws  Exception if there is an error in the form event.
  */
 protected function preprocessForm(FOFForm &$form, &$data, $group = 'content')
 {
     // Import the appropriate plugin group.
     FOFPlatform::getInstance()->importPlugin($group);
     // Trigger the form preparation event.
     $results = FOFPlatform::getInstance()->runPlugins('onContentPrepareForm', array($form, $data));
     // Check for errors encountered while preparing the form.
     if (count($results) && in_array(false, $results, true)) {
         // Get the last error.
         $dispatcher = FOFUtilsObservableDispatcher::getInstance();
         $error = $dispatcher->getError();
         if (!$error instanceof Exception) {
             throw new Exception($error);
         }
     }
 }