/** * Register the service provider. * * @return void */ public function register() { $this->app['parameters'] = $this->app->share(function ($app) { return new Parameters(); }); // Find the default Controller class of the current Laravel application $controllerClass = $this->app['config']->get('authority-controller.controllerClass', 'Illuminate\\Routing\\Controller'); $this->app->resolving(function ($object) use($controllerClass) { // Check if the current $object class is a Controller class and if it responds to paramsBeforeFilter method if (is_a($object, $controllerClass) && respond_to($object, 'paramsBeforeFilter')) { // Fill $params properties of the current controller $this->app['parameters']->fillController($object); } }); $this->app['authority'] = $this->app->share(function ($app) { $user = $app['auth']->user(); $authority = new Authority($user); $fn = $app['config']->get('authority-controller.initialize'); $serializer = new Serializer(); if (is_string($fn)) { $fn = $serializer->unserialize($fn); } if ($fn) { $fn($authority); } return $authority; }); $this->app->bind('Efficiently\\AuthorityController\\ControllerResource', function ($app, $parameters) { list($controller, $resourceName, $resourceOptions) = $parameters; return new ControllerResource($controller, $resourceName, $resourceOptions); }); }
/** * Executes the current command * * @param use Symfony\Component\Console\Input\InputInterface $input * @param use Symfony\Component\Console\Input\OutputIterface $output * * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $args = []; $this->arguments = $input->getArguments(); parse_str($this->arguments['closure'], $args); $serializer = new Serializer(); call_user_func_array($serializer->unserialize($args[0]), []); }
/** * 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); }
/** * 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; }
/** * @param string $serializedJob * @return callable */ public static function deserialize($serializedJob) { $serializedJob = openssl_decrypt($serializedJob, self::$encryptMethod, self::$encryptMethod, false, self::$encryptIV); if (self::endswith($serializedJob, self::$serializedTag)) { $serializedJob = rtrim($serializedJob, self::$serializedTag); $serializer = new Serializer(); $serializedJob = $serializer->unserialize($serializedJob); } return $serializedJob; }
protected function run($serializedCallable) { $serializer = new Serializer(); $callable = $serializer->unserialize($serializedCallable); if (is_callable($callable)) { $callable(); } else { throw new \InvalidArgumentException('Invalid serialized callable'); } }
/** * Run the passed closure as received via command line. * * @param function $closure * @return void */ public static function pickup($closure) { // serializer $serializer = new Serializer(); // unpack $unpacked = unserialize(base64_decode($closure)); // unserialize $unserialized = $serializer->unserialize($unpacked); // process $unserialized(); }
/** * Prepares the controller closures to be unserialized */ public function __wakeup() { $serializer = new Serializer(new AstAnalyzer()); foreach ($this->routes as $method => $routesByMethod) { /** @var ParsedRoute $route */ foreach ($routesByMethod as $route) { if ($route->usesClosure()) { $route->setControllerClosure($serializer->unserialize($route->getController())); } } } }
function route($slug) { //Load calleble object via slug $route = $this->load_route($slug); if ($route) { $serializer = new Serializer(); $closure = $serializer->unserialize($route->closure); $params = explode('/', $slug); array_shift($params); $closure($slug, $params); } //Run calleble object render function }
/** * Set the currently logged in user for the application and load his authorization rules * * @param Illuminate\Contracts\Auth\Authenticatable $user * @param Closure $fn Function callback who contains Authority rules. * By default it loads the default config file: 'config/authority-controller.php'. * @return Authority */ protected function loginAs(Illuminate\Contracts\Auth\Authenticatable $user, $fn = null) { $this->app['auth']->login($user); $this->app['authority'] = new Authority($user); $authority = $this->app->make('authority'); $fn = $fn ?: $this->app['config']->get('authority-controller.initialize'); $serializer = new Serializer(); if (is_string($fn)) { $fn = $serializer->unserialize($fn); } if ($fn) { $fn($authority); } return $authority; }
/** * 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; }
/** * 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); } } } }
/** * 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); } } } }
/** * Response sender message * * @param $nodes * @param null $lead_id */ public function response($nodes, $lead_id = null) { if (is_null($lead_id)) { $lead_id = $this->conversation->get('lead_id'); } foreach ($nodes as $node) { /** New wait */ if (!empty($node->wait)) { $this->storage->set($lead_id, '_wait', $node->wait); } // Backward compatibility if (array_key_exists('type', $node->answers)) { $node->answers = [$node->answers]; } foreach ($node->answers as $answer) { /** Process dynamic content */ if (isset($answer['type'])) { // Backward compatibility if (isset($answer['callback'])) { $answer['content'] = $answer['callback']; } if (giga_match('%SerializableClosure%', $answer['content'])) { $answer['content'] = $this->serializer->unserialize($answer['content']); } $return = DynamicParser::parse($answer); // If the callback return, we'll send that message to user. if ($return != null || !empty($return)) { $answer = $this->model->parseWithoutSave($return); // Answer == 0 means that answers is already parsed and it's a single message. if ($answer != false) { $this->request->sendMessages($answer); } else { $this->request->sendMessage($return); } continue; } } $this->request->sendMessage($answer); } } }
/** * @param \Closure $closure * * @return string */ private function createDefaultTemplateEngine(\Closure $closure) { return $this->createDefaultFromSerializedClosure($this->fnSerializer->serialize($closure)); }
/** * @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)]); }
static function execute($number = 5) { if (!is_numeric($number)) { throw new Exception('Number must be numeric'); } $callables = R::findAll('queueitem', 'status = "open" ORDER BY id DESC LIMIT ' . $number); $c = 0; foreach (array_values($callables) as $index => $calleble) { $c++; if ($calleble->done) { $c--; continue; } if ($c >= $number) { break; } $serializer = new Serializer(); $closure = $serializer->unserialize($calleble->callser); //// $calleble->status = 'busy'; // R::store($calleble); $closure(); $calleble->status = 'done'; $calleble->done = true; $calleble->doneat = time(); R::store($calleble); } return; }