コード例 #1
0
 /**
  * Encode method calls.
  *
  * @param MethodCall[] $methodCalls Method calls.
  * @param Encoder      $encoder     Javascript encoder.
  * @param null         $flags       Encoder flags.
  *
  * @return string
  */
 protected function encodeMethodCalls($methodCalls, Encoder $encoder, $flags = null)
 {
     $buffer = '';
     $flags = Flags::add(Flags::CLOSE_STATEMENT, $flags);
     foreach ($methodCalls as $call) {
         $buffer .= "\n" . $call->encode($encoder, $flags);
     }
     return $buffer;
 }
コード例 #2
0
 /**
  * Encode an value and return it.
  *
  * @param mixed    $value  The value being encoded.
  * @param int|null $flags  Optional encoder flags.
  * @param Output   $output The output being generated.
  *
  * @return string
  */
 public function encode($value, $flags = Flags::CLOSE_STATEMENT, Output $output = null)
 {
     $factory = $this->encoderFactory;
     $output = $output ?: new Output();
     /** @var Encoder $encoder */
     $encoder = $factory($output);
     $flags = Flags::add($flags, $encoder->getFlags());
     $output->append($encoder->encodeValue($value, $flags));
     return $output->getBuffer();
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function encodeReference($value)
 {
     if (!is_object($value)) {
         return null;
     }
     $hash = $this->hash($value);
     $encoder = $this->chain->getEncoder();
     if (!array_key_exists($hash, $this->references)) {
         $this->references[$hash] = $this->chain->next($this, __FUNCTION__, [$value]);
         if ($this->references[$hash] && !array_key_exists($hash, $this->values)) {
             $encoder->getOutput()->append($encoder->encodeObject($value, Flags::add(Flags::CLOSE_STATEMENT, $encoder->getFlags())));
         }
     }
     return $this->references[$hash];
 }
コード例 #4
0
 /**
  * Check if given array is an numeric one.
  *
  * @param array    $data  The array being encoded.
  * @param int|null $flags Optional json encode flags.
  *
  * @return bool
  */
 private function isNumericArray(array $data, $flags)
 {
     if (Flags::contains(JSON_FORCE_OBJECT, $flags)) {
         return false;
     }
     foreach (array_keys($data) as $key) {
         if (!is_numeric($key)) {
             return false;
         }
     }
     return true;
 }
コード例 #5
0
 /**
  * Encode the javascript representation of the object.
  *
  * @param Encoder  $encoder The javascript encoder.
  * @param int|null $flags   The encoding flags.
  *
  * @return string
  */
 public function encode(Encoder $encoder, $flags = null)
 {
     $options = get_object_vars($this);
     unset($options['formId']);
     $options = $this->removeEmptyOptions($options);
     if (!empty($options['fields'])) {
         foreach ($options['fields'] as $name => $value) {
             /** @var Field $value */
             $options['fields'][$name] = $value->getOptions();
         }
     }
     return sprintf('$(\'#%s\').formValidation(%s);', $this->getFormId(), $encoder->encodeArray($options, Flags::add(JSON_FORCE_OBJECT, $flags)));
 }