/** * Uses the closure parser to fetch the closure's code. The code and the closure's context are serialized * * @return string */ public function serialize() { // Prepare the state to serialize using a ClosureParser if (!$this->state) { $parser = new ClosureParser($this->getReflection()); $this->state = array($parser->getCode()); // Add the used variables (context) to the state, but wrap all closures with SerializableClosure $this->state[] = array_map(function ($var) { return $var instanceof \Closure ? new self($var) : $var; }, $parser->getUsedVariables()); } return serialize($this->state); }
/** * Uses the closure parser to fetch the closure's code and context */ protected function createState() { $parser = new ClosureParser($this->getReflection()); $this->state = array($parser->getCode()); // Add the used variables (context) to the state, but wrap all closures with SerializableClosure $this->state[] = array_map(function ($var) { return $var instanceof \Closure ? new self($var) : $var; }, $parser->getUsedVariables()); }