Serialize the instance.

@param  mixed  $instance
@param  string  $name

@return array
4473
protected function serializeWith($instance, string $name)
    {
        $serializer = $this->getVersionedResourceClassName('Serializers', $name);

        if (\class_exists($serializer)) {
            return \call_user_func(app($serializer), $instance);
        }

        if ($instance instanceof Fluent) {
            return $instance->getAttributes();
        } elseif ($instance instanceof Collection) {
            return $instance->all();
        } elseif ($instance instanceof Arrayable) {
            return $instance->toArray();
        }

        return $instance;
    }
395430
public function parseTable($name): array
    {
        if ($name instanceof Model) {
            return [$name->alias(), $name->name()];
        }

        if (is_array($name)) {
            return [key($name), current($name)];
        }

        if (is_scalar($name)) {
            return static::parseName($name);
        }

        return [null, $name];
    }
185188
public function serialize()
	{
		// Load all of the inputs.
		$this->loadAllInputs();

		// Remove $_ENV and $_SERVER from the inputs.
		$inputs = $this->inputs;
		unset($inputs['env'], $inputs['server']);

		// Serialize the executable, args, options, data, and inputs.
		return serialize(array($this->executable, $this->args, $this->options, $this->data, $inputs));
	}
132071
public function serialize($object)
    {
        if (!(is_array($object) || is_object($object))) {
            throw new \InvalidArgumentException();
        }

        return $this->innerSerialize($object);
    }
530125
private function build(string $name)
    {
        $instance = null;
        $map = $this->map[$name];

        if (is_array($map)) {
            $params = $this->getParamsFromMap($map);
            $instance = new $name(...$params);
        } elseif ($map instanceof \Closure) {
            $instance = $map($this);
        } elseif (is_object($map)) {
            $instance = $map;
        } elseif (is_string($map)) {
            $instance = $this->get($map);
        } else {
            throw new \Exception('Invalid map');
        }

        return $instance;
    }
797588
public function set($name, $instance)
    {
        $key = $this->makeKey($name);

        $this->alias($name, $this->describe(get_class($instance)));

        $this->instances[$key] = $instance;

        return $this;
    }
914699
private function innerSerialize($object)
    {
        if (is_array($object)) {
            $serializedArray = [];
            foreach ($object as $key => $value) {
                $serializedArray[$key] = $this->innerSerialize($value);
            }

            return $serializedArray;
        } elseif (is_object($object)) {
            return $this->serializeObject($object);
        } else {
            return $object;
        }
    }
965895
public function serialize($entity)
    {
        return array($this->getName().'.'.$this->_target_parent_key => $entity->get($this->_target_parent_key));
    }
399419
public static function serialize($filename, $instance, $force = false)
    {
        if ($filename == '') {
            throw new \danog\MadelineProto\Exception('Empty filename');
        }
        if ($instance->API->asyncInitPromise) {
            return $instance->call(static function () use ($filename, $instance, $force) {
                yield $instance->API->asyncInitPromise;
                $instance->API->asyncInitPromise = null;
                return self::serialize($filename, $instance, $force);
            });
        }
        if (isset($instance->API->setdem) && $instance->API->setdem) {
            $instance->API->setdem = false;
            $instance->API->__construct($instance->API->settings);
        }
        if ($instance->API === null && !$instance->getting_api_id) {
            return false;
        }
        $instance->serialized = time();
        $realpaths = self::realpaths($filename);
        if (!file_exists($realpaths['lockfile'])) {
            touch($realpaths['lockfile']);
            clearstatcache();
        }
        $realpaths['lockfile'] = fopen($realpaths['lockfile'], 'w');
        \danog\MadelineProto\Logger::log('Waiting for exclusive lock of serialization lockfile...');
        flock($realpaths['lockfile'], LOCK_EX);
        \danog\MadelineProto\Logger::log('Lock acquired, serializing');

        try {
            if (!$instance->getting_api_id) {
                $update_closure = $instance->API->settings['updates']['callback'];
                if ($instance->API->settings['updates']['callback'] instanceof \Closure) {
                    $instance->API->settings['updates']['callback'] = [$instance->API, 'noop'];
                }
                $logger_closure = $instance->API->settings['logger']['logger_param'];
                if ($instance->API->settings['logger']['logger_param'] instanceof \Closure) {
                    $instance->API->settings['logger']['logger_param'] = [$instance->API, 'noop'];
                }
            }
            $wrote = file_put_contents($realpaths['tempfile'], serialize($instance));
            rename($realpaths['tempfile'], $realpaths['file']);
        } finally {
            if (!$instance->getting_api_id) {
                $instance->API->settings['updates']['callback'] = $update_closure;
                $instance->API->settings['logger']['logger_param'] = $logger_closure;
            }
            flock($realpaths['lockfile'], LOCK_UN);
            fclose($realpaths['lockfile']);
        }

        return $wrote;
    }
701276
public static function &getAuth($instance)
	{
		static $instances;
		if (!isset($instances)) {
			$instances = array();
		}
		//only create a new authentication instance if it has not been created before
		if (!isset($instances[$instance])) {
			$name = static::getNameFromInstance($instance);

			static::pluginAutoLoad($name);

			$class = '\JFusion\Plugins\\' . $name . '\Auth';
			if (!class_exists($class)) {
				$class = '\JFusion\Plugin\Auth';
			}
			$instances[$instance] = new $class($instance);
		}
		return $instances[$instance];
	}
1138473
public static function getInstance($name)
  {
    $key = self::_instanceKey($name);
    if (!isset(self::$_instances[$key])) {

      $dataSource = self::getDataAdapter();
      if (is_null($dataSource)) {
        $data = array();
      } else {
        $data = $dataSource->load($key);
      }
      
      $config = new self($data);
      /* @var $config Config */
      $config->_root = $config;
      $config->_key = $key;

      self::$_instances[$key] = $config;
    }
    return self::$_instances[$key];
  }
962561
@Override
   protected Object convert(Object instance) {
      try {
         return ProtobufUtil.toWrappedByteArray(serializationContext, instance);
      } catch (IOException e) {
         throw new CacheException(e);
      }
   }
1052442
public function serialize()
    {
        SerializableClosure::enterContext();

        $engines = $this->engines;

        foreach ($engines as &$engine) {
            if ($engine[0] instanceof \Closure) {
                $engine[0] = SerializableClosure::from($engine[0]);
            }
        }

        $object = serialize([
            'engines' => $engines,
            'renderer' => $this->renderer
        ]);

        SerializableClosure::exitContext();

        return $object;
    }
548173
public function serialize($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('Argument must be an object');
        }

        $reflectedObject = new \ReflectionObject($object);
        $reflectedProperties = $reflectedObject->getProperties();

        $array = array();

        foreach ($reflectedProperties as $property) {
            $value = $this->getValue($object, $property);

            if (null !== $value) {
                if (!is_scalar($value)) {
                    $value = $this->normalize($value);
                }

                $array[$this->formatter->toMongoKey($property->getName())] = $value;
            }
        }

        return $array;
    }
422927
public static function instance($instance = null)
	{
		if ($instance !== null)
		{
			if ( ! array_key_exists($instance, static::$_instances))
			{
				return false;
			}

			return static::$_instances[$instance];
		}

		if (static::$_instance === null)
		{
			static::$_instance = static::forge();
		}

		return static::$_instance;
	}
1166282
public static function deleteInstance($name)
  {
    $adapter = self::getDataAdapter();
    if (!is_null($adapter)) {
      $key = self::_instanceKey($name);
      
      $result = $adapter->delete($key);
    } else {
      $result = false;
    }
    self::clearInstance($name);
    
    return $result;
  }
942013
protected function _buildInstance($instance, array $parameters = [])
  {
    if(is_scalar($instance) && class_exists($instance))
    {
      return Objects::create($instance, $parameters);
    }
    return $instance;
  }