Beispiel #1
0
 /**
  * Get the URI for the current request.
  *
  * @return string
  */
 public static function uri()
 {
     // check cache
     if (static::$uri !== false) {
         return static::$uri;
     }
     // determine URI from Request
     $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : (isset($_SERVER['REDIRECT_URL']) ? $_SERVER['REDIRECT_URL'] : '')));
     // remove unnecessarily slashes, like doubles and leading
     $uri = preg_replace('|//+|', '/', $uri);
     $uri = ltrim($uri, '/');
     // remove get params
     if (strpos($uri, '?') !== false) {
         $e = explode('?', $uri, 2);
         $uri = $e[0];
         if (isset($e[1])) {
             static::$queue = $e[1];
         }
     }
     // $uri = trim($uri, '/');
     // add / only on empty URI - not good, because this will not work:
     // 		Route::uri('(<controller>(/<action>(/<param>*)))', function ($params) {
     // since we have no "/", this is OK, but it's more complicated:
     //		Route::uri('(/)(<controller>(/<action>(/<param>*)))', function ($params) {
     //
     // if (!$uri) $uri = '/';
     // cache and return
     return static::$uri = $uri;
 }
Beispiel #2
0
 /**
  * Create a queue instance.
  *
  * @return \Resque\Queue
  */
 public static function queue()
 {
     if (!static::$queue) {
         static::$queue = new Resque\Queue();
     }
     return static::$queue;
 }
Beispiel #3
0
 /**
  * Save Queue
  *
  * Persist all queued Events into Event Store.
  * @return void
  */
 public function publishQueue()
 {
     foreach (static::$queue as $record) {
         EventBus::fire('publish:' . $record['event'], $record['payload']);
     }
     static::$queue = [];
 }
Beispiel #4
0
 /**
  * Initialise the facade. Must be called first.
  *
  * @param string                                     $token API token.
  * @param string|int                                 $room  Room to send message to.
  * @param string                                     $from  Who the message is from.
  * @param \rcrowe\Hippy\Transport\TransportInterface $transport
  */
 public static function init($token, $room, $from, $transport = null)
 {
     if ($transport === null) {
         $transport = new Guzzle($token, $room, $from);
     }
     static::$client = new Client($transport);
     static::$queue = new Queue();
 }
Beispiel #5
0
 /**
  * Create a new job and save it to the specified queue.
  *
  * @param string  $queue  The name of the queue to place the job in
  * @param string  $class  The name of the class that contains the code to execute the job
  * @param array   $data   Any optional arguments that should be passed when the job is executed
  * @param int     $run_at Unix timestamp of when to run the job to delay execution
  * @return string
  */
 public static function create($queue, $class, array $data = null, $run_at = 0)
 {
     $id = static::createId($queue, $class, $data, $run_at);
     $job = new static($queue, $id, $class, $data);
     if ($run_at > 0) {
         if (!$job->delay($run_at)) {
             return false;
         }
     } elseif (!$job->queue()) {
         return false;
     }
     Stats::incr('total', 1);
     Stats::incr('total', 1, Queue::redisKey($queue, 'stats'));
     return $job;
 }
Beispiel #6
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     static::$queue = static::createQueueClass();
     static::clearAllTubes();
 }
Beispiel #7
0
 public function defer()
 {
     if (!isset(static::$queue)) {
         static::$queue = new Queue();
     }
     static::$queue->schedule(func_get_args());
 }
Beispiel #8
0
 /**
  * @return Queue
  */
 protected function getQueue()
 {
     if (null === static::$queue) {
         static::$queue = static::getProducer()->getQueue();
     }
     return static::$queue;
 }