/**
  * {@inheritdoc}
  */
 public function encodeObject($value, $flags = null)
 {
     $hash = $this->hash($value);
     if (!array_key_exists($hash, $this->values)) {
         if (Flags::contains(Flags::BUILD_STACK, $flags)) {
             $flags = Flags::remove(Flags::BUILD_STACK, $flags);
             $flags = Flags::add(Flags::CLOSE_STATEMENT, $flags);
             $this->buildStack($value, $flags);
         }
         $this->values[$hash] = null;
         $this->values[$hash] = $this->chain->next($this, __FUNCTION__, [$value, $flags]);
     }
     return $this->values[$hash];
 }
 /**
  * {@inheritdoc}
  */
 public function encodeArguments(array $arguments, $flags = null)
 {
     $values = array();
     $flags = Flags::remove(Flags::CLOSE_STATEMENT, $flags);
     foreach ($arguments as $value) {
         if (ValueHelper::isScalar($value) || $value instanceof \JsonSerializable) {
             $values[] = $this->chain->first('encodeScalar', [$value, $flags]);
             continue;
         }
         $ref = $this->chain->first('encodeReference', [$value]);
         if ($ref) {
             $values[] = $ref;
         } else {
             $values[] = $this->chain->first('encodeValue', [$value, $flags]);
         }
     }
     return implode(', ', $values);
 }