| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Giancarlo
- * Date: 09/08/2018
- * Time: 11:27
- */
- namespace OpenMind\System;
- use DB\SQL\Mapper;
- class QueueSystem extends Mapper
- {
- private $f3;
- private $serviceName;
- // Used internally
- private $initLoad;
- public function __construct(string $serviceName)
- {
- global $f3;
- $this->f3 = $f3;
- parent::__construct($f3->get('DB'), 'queuesystem');
- $this->serviceName = $serviceName;
- }
- /**
- * Send object to <$serviceName>.
- * send() serialize $obj before send to queue
- *
- * @param $obj
- */
- public function send($obj)
- {
- $serializedObject = serialize($obj);
- $this->reset();
- $this->servicename = $this->serviceName;
- $this->command = base64_encode($serializedObject);
- $this->save();
- }
- /**
- * Retrieve and unserialize current object
- *
- * @return mixed
- */
- public function getCommandObject() {
- $decodedObj = base64_decode($this->command);
- $obj = unserialize($decodedObj);
- return $obj;
- }
- /**
- * Retrieve messages
- *
- * @return array|FALSE
- */
- public function check()
- {
- if (!$this->initLoad) {
- $this->initLoad = true;
- $this->load(['servicename=?', $this->serviceName]);
- }
- return $this->dry();
- }
- /**
- * Delete all messages of <$serviceName>
- */
- public function deleteAll()
- {
- $this->reset();
- $this->erase(['servicename=?', $this->serviceName]);
- }
- }
|