from() public static method

Wraps a closure and sets the serialization context (if any)
public static from ( Closure $closure, boolean $serializeThis = false ) : self
$closure Closure Closure to be wrapped
$serializeThis boolean - Obsolete
return self The wrapped closure
Esempio n. 1
0
 /**
  * String representation of object
  * @link http://php.net/manual/en/serializable.serialize.php
  * @return string the string representation of the object or null
  * @since 5.1.0
  */
 public function serialize()
 {
     SerializableClosure::enterContext();
     $object = serialize(array_map(function ($value) {
         return $value instanceof Closure ? SerializableClosure::from($value) : $value;
     }, $this->factories));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 2
0
 /**
  * @return string
  */
 public function serialize()
 {
     $map = function ($value) {
         return $value instanceof Closure ? SerializableClosure::from($value) : $value;
     };
     SerializableClosure::enterContext();
     $object = serialize(array('callback' => $map($this->callback), 'setters' => array_map($map, $this->setters)));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 3
0
 /**
  * @return string
  */
 public function serialize()
 {
     SerializableClosure::enterContext();
     $callable = $this->callback;
     if ($callable instanceof Closure) {
         $callable = SerializableClosure::from($callable);
     }
     $object = serialize($callable);
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 4
0
 /**
  * Wrap all closures
  *
  * @param   mixed   $value
  *
  * @return  mixed
  */
 protected static function wrapClosures($value)
 {
     if ($value instanceof Closure) {
         return SerializableClosure::from($value);
     } elseif (is_array($value)) {
         return array_map(static::class . '::' . __FUNCTION__, $value);
     } elseif ($value instanceof \stdClass) {
         return (object) array_map(static::class . '::' . __FUNCTION__, (array) $value);
     }
     return $value;
 }
Esempio n. 5
0
 public function serialize()
 {
     SerializableClosure::enterContext();
     $object = serialize(array_map(function ($value) {
         if ($value instanceof Closure) {
             return SerializableClosure::from($value);
         }
         return $value;
     }, $this->callbacks));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 6
0
 /**
  * @return string
  */
 public function serialize()
 {
     SerializableClosure::enterContext();
     $map = function ($value) {
         if ($value instanceof \Closure) {
             return SerializableClosure::from($value);
         }
         return $value;
     };
     $object = serialize(['builder' => $map($this->builder), 'storage' => array_map($map, $this->storage)]);
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 7
0
 protected function mapFunction1($value)
 {
     if (is_array($value)) {
         return array_map(array($this, __FUNCTION__), $value);
     } elseif ($value instanceof \stdClass) {
         $ret = (array) $value;
         $ret = array_map(array($this, __FUNCTION__), $ret);
         $ret = (object) $ret;
         return $ret;
     } elseif ($value instanceof Closure) {
         return SerializableClosure::from($value);
     }
     return $value;
 }
Esempio n. 8
0
 public function serialize()
 {
     SerializableClosure::enterContext();
     $object = serialize(array('builder' => SerializableClosure::from($this->builder), 'defaultStorage' => $this->defaultStorage, 'storages' => array_map(function ($value) {
         return SerializableClosure::from($value);
     }, $this->storages)));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 9
0
 public function serialize()
 {
     SerializableClosure::enterContext();
     $object = serialize(array('subtest' => $this->subtest, 'func' => SerializableClosure::from($this->func)));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 10
0
 /**
  * Serialize
  *
  * @return  string
  */
 public function serialize()
 {
     SerializableClosure::enterContext();
     $object = serialize(array('handler' => $this->handler instanceof \Closure ? SerializableClosure::from($this->handler) : $this->handler, 'factory' => $this->factory instanceof \Closure ? SerializableClosure::from($this->factory) : $this->factory));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 11
0
 /**
  * Serialize the route
  * 
  * @return  string
  */
 public function serialize()
 {
     SerializableClosure::enterContext();
     $routeAction = $this->routeAction;
     if ($routeAction instanceof Closure) {
         $routeAction = SerializableClosure::from($routeAction);
     }
     $map = array(static::class, 'wrapClosures');
     $object = serialize(array('routePattern' => $this->routePattern, 'routeAction' => $routeAction, 'routeName' => $this->routeName, 'routeID' => $this->routeID, 'wildcards' => $this->wildcards, 'bindings' => array_map($map, $this->bindings), 'defaults' => array_map($map, $this->defaults), 'properties' => array_map($map, $this->properties), 'collection' => $this->collection));
     SerializableClosure::exitContext();
     return $object;
 }
Esempio n. 12
0
 /**
  * @return string
  */
 public function serialize()
 {
     SerializableClosure::enterContext();
     $callback = function ($value) {
         return $value instanceof Closure ? SerializableClosure::from($value) : $value;
     };
     $object = serialize(array('concrete' => $callback($this->concrete), 'shared' => $this->shared, 'setters' => array_map($callback, $this->setters), 'extenders' => $this->extenders));
     SerializableClosure::exitContext();
     return $object;
 }