/** * Return a serialized closure. * * @param closure $closure * @return string */ protected static function hash($closure) { // serializer $serializer = new Serializer(); // serialize $string = $serializer->serialize($closure); // return return md5($string); }
/** * @param callable $job * @return string */ public static function serialize($job) { $serializedJob = $job; if (self::isClosure($serializedJob)) { $serializer = new Serializer(); $serializedJob = $serializer->serialize($job); $serializedJob .= self::$serializedTag; } return openssl_encrypt($serializedJob, self::$encryptMethod, self::$encryptMethod, false, self::$encryptIV); }
/** * Create payload from for storing somewhere * @param \Closure|Huuuk\Queues\Job $job * @return string */ protected function createPayload($job) { if ($job instanceof Job) { return serialize($job); } elseif ($job instanceof Closure) { $serializer = new Serializer(); return $serializer->serialize($job); } return null; }
static function add_callable($function, $note = '') { $serializer = new Serializer(); $s_closure = $serializer->serialize($function); $callable = R::dispense('queueitem'); $callable->callser = $s_closure; $callable->added_at = time(); $callable->note = $note; $callable->status = 'open'; R::store($callable); }
/** * Add answer to node * * @param Mixed $answers Message * @param String $node_type Node Type * @param null $asks Question * * @return Node */ public function addNode(array $answers, $node_type, $asks = null) { foreach ($answers as $index => $answer) { if (isset($answer['type']) && isset($answer['content']) && is_callable($answer['content'])) { $answer['content'] = $this->serializer->serialize($answer['content']); } $answers[$index] = $answer; } $this->current_node = Storage::addNode($answers, $node_type, $asks); return $this->current_node; }
/** * Prepares the controller closures to be serialized * * @return array The list of properties to store */ public function __sleep() { $serializer = new Serializer(new AstAnalyzer()); foreach ($this->routes as $method => $routesByMethod) { /** @var ParsedRoute $route */ foreach ($routesByMethod as $route) { if ($route->usesClosure()) { $route->setControllerClosure($serializer->serialize($route->getController())); } } } return array_keys(get_object_vars($this)); }
/** * Run the passed closure via command line. * * @param function $closure * @return void */ public static function run($closure) { // serializer $serializer = new Serializer(); // serialize $serialized = $serializer->serialize($closure); // pack $packed = base64_encode(serialize($serialized)); // environment $environment = \App::environment(); // command $command = 'php ' . base_path() . '/artisan fork ' . $packed . ' --env=' . $environment . ' > /dev/null 2>&1 &'; // execute exec($command); }
/** * Initialize the queue. * @return void */ public function init() { parent::init(); $this->queue = \yii\di\Instance::ensure($this->queue, Queue::className()); $this->_hasEventHandlers = !\yii\helpers\ArrayHelper::isIndexed($this->events, true); if ($this->_hasEventHandlers) { foreach ($this->events as $attr => $handler) { if (is_callable($handler)) { if (!isset($this->_serializer)) { $this->_serializer = new \SuperClosure\Serializer(); } $this->events[$attr] = $this->_serializer->serialize($handler); } } } }
function create_route($slug, $callable, $allow_params = false) { // Create the route in the database //Serialize the callable object $serializer = new Serializer(); $s_closure = $serializer->serialize($callable); $hash = md5($s_closure); if (R::findOne('route', 'hash = :hash', ['hash' => $hash])) { return; } $route = current(R::findOrDispense('route', 'slug = :slug', ['slug' => $slug])); $route->hash = $hash; $route->slug = $slug; $route->closure = $s_closure; $route->allow_params = $allow_params; R::store($route); // Store }
/** * Initialize the queue. * @throws \Exception */ public function init() { parent::init(); $queueName = $this->queue; $this->queue = Yii::$app->get($queueName); if (!$this->queue instanceof \UrbanIndo\Yii2\Queue\Queue) { throw new \Exception("Can not found queue component named '{$queueName}'"); } $this->_hasEventHandlers = !\yii\helpers\ArrayHelper::isIndexed($this->events, true); if ($this->_hasEventHandlers) { foreach ($this->events as $attr => $handler) { if (is_callable($handler)) { if (!isset($this->_serializer)) { $this->_serializer = new \SuperClosure\Serializer(); } $this->events[$attr] = $this->_serializer->serialize($handler); } } } }
/** * @param \OCP\Command\ICommand | callable $command * @return string */ private function serializeCommand($command) { if ($command instanceof \Closure) { $serializer = new Serializer(); return $serializer->serialize($command); } else { if (is_callable($command) or $command instanceof ICommand) { return serialize($command); } else { throw new \InvalidArgumentException('Invalid command'); } } }
/** * @inheritdoc */ public function push($taskId, callable $task) { $this->illuminateQueue->push(IlluminateQueueHandler::class, [$taskId, $this->serializer->serialize($task)]); }
/** * @param \Closure $closure * * @return string */ private function createDefaultTemplateEngine(\Closure $closure) { return $this->createDefaultFromSerializedClosure($this->fnSerializer->serialize($closure)); }