Beispiel #1
0
 /**
  * Get an array of plugins
  *
  * If $instanciate is true then the returned array will have instanciated
  * plugin objects that are ready for use.
  *
  * @param string $event       What event you want the plugin to be enabled for
  * @param bool   $instanciate Whether or not to instanciate the plugins
  *
  * @return array
  */
 public static function getPlugins($event, $instanciate = true)
 {
     $config = Resqee_Config::getInstance()->getConfigSection(self::KEY_PLUGINS);
     if (empty($config)) {
         return array();
     }
     $rtn = array();
     foreach ($config as $pluginClass => $eventName) {
         if ($event == $eventName) {
             if ($instanciate) {
                 Resqee::loadClass($pluginClass);
                 $rtn[$pluginClass] = new $pluginClass();
             } else {
                 $rtn[] = $pluginClass;
             }
         }
     }
     return $rtn;
 }
Beispiel #2
0
 /**
  * Handle requests for POST /job
  *
  * This is where we're handed a job and need to start running it
  *
  */
 public function post()
 {
     try {
         Resqee::loadClass($_POST[Resqee::KEY_POST_JOB_CLASS_PARAM]);
     } catch (Exception $e) {
         throw new Resqee_Exception("Could not load job class");
     }
     $plugins = Resqee_Plugins::getPlugins(Resqee_Plugin_Events::SERVER_JOB_POST);
     $responses = array();
     $serialized = stripslashes(urldecode($_POST[Resqee::KEY_POST_JOB_PARAM]));
     $jobs = unserialize($serialized);
     foreach ($jobs as $jobId => $jobData) {
         $job = unserialize($jobData[Resqee::KEY_POST_JOB_PARAM]);
         if (!is_object($job) || !$job instanceof Resqee_Job) {
             throw new Resqee_Exception("Invalid job. Job must be an instance of Resqee_Job");
         }
         // don't bother unserializing nulls
         $args = 'N;' != $jobData[Resqee::KEY_POST_JOB_ARGS_PARAM] ? unserialize($jobData[Resqee::KEY_POST_JOB_ARGS_PARAM]) : null;
         $item = new Resqee_Persistence_Item();
         $item->jobId = $jobId;
         $item->job = $jobData[Resqee::KEY_POST_JOB_PARAM];
         $item->args = $jobData[Resqee::KEY_POST_JOB_ARGS_PARAM];
         $item->class = get_class($job);
         $item->parentClass = get_parent_class($job);
         $item->requestTime = $this->serverGlobal['REQUEST_TIME'];
         // run before() on each regsitered plugin
         foreach ($plugins as $plugin) {
             $plugin->before($item);
         }
         $runner = new Resqee_JobRunner($job, $args, $this->serverGlobal);
         $responses[$jobData[Resqee::KEY_POST_JOB_ID_PARAM]] = $runner->getResponse();
     }
     // run after() for each registered plugin
     foreach ($responses as $jobId => $response) {
         foreach ($plugins as $plugin) {
             $plugin->after($jobId, $response);
         }
     }
     echo serialize($responses);
 }
Beispiel #3
0
 /**
  * Factory method to get an instance of a controller
  *
  * @param string $uri The URI we want a controller for
  *
  * @return Resqee_Controller
  */
 public static function factory($serverGlobal)
 {
     $uri = $serverGlobal['REDIRECT_URL'];
     $controller = null;
     $trimmed = trim($uri, '/');
     if ($trimmed == '') {
         $controller = 'Index';
     } else {
         $pathParts = explode('/', $trimmed);
         $controller = ucfirst($pathParts[0]);
     }
     $className = "Resqee_Controller_{$controller}";
     try {
         Resqee::loadClass($className);
         return new $className($serverGlobal);
     } catch (Resqee_Exception $e) {
         throw new Resqee_Exception("404");
     }
 }
Beispiel #4
0
 /**
  * Get the result
  *
  * This method will unserialize the response from the server
  *
  * @return mixed
  */
 public function getResult()
 {
     if ($this->resultDataType !== null) {
         Resqee::loadClass($this->resultDataType);
     }
     return unserialize($this->serializedResult);
 }