예제 #1
0
 /**
  * {@inheritdoc}
  */
 public final function getTypeValue()
 {
     return $this->typeName->getValue();
 }
예제 #2
0
파일: Field.php 프로젝트: gdbots/pbj-php
 /**
  * @param mixed $default
  * @throws AssertionFailed
  * @throws \Exception
  */
 private function applyDefault($default = null)
 {
     $this->default = $default;
     if ($this->type->isScalar()) {
         if ($this->type->getTypeName() !== TypeName::TIMESTAMP()) {
             $this->useTypeDefault = true;
         }
     } else {
         $decodeDefault = null !== $this->default && !$this->default instanceof \Closure;
         switch ($this->type->getTypeValue()) {
             case TypeName::IDENTIFIER:
                 Assertion::notNull($this->className, sprintf('Field [%s] requires a className.', $this->name));
                 if ($decodeDefault && !$this->default instanceof Identifier) {
                     $this->default = $this->type->decode($this->default, $this);
                 }
                 break;
             case TypeName::INT_ENUM:
             case TypeName::STRING_ENUM:
                 Assertion::notNull($this->className, sprintf('Field [%s] requires a className.', $this->name));
                 if ($decodeDefault && !$this->default instanceof Enum) {
                     $this->default = $this->type->decode($this->default, $this);
                 }
                 break;
             default:
                 break;
         }
     }
     if (null !== $this->default && !$this->default instanceof \Closure) {
         $this->guardDefault($this->default);
     }
 }
예제 #3
0
 /**
  * @param array $value
  * @param Field $field
  * @return mixed
  *
  * @throws EncodeValueFailed
  */
 private function encodeASetValue(array $value, Field $field)
 {
     $type = $field->getType();
     /*
      * A MessageRefType is the only object/map value that can be
      * used in a set.  In this case of DynamoDb, we can store it as
      * a list of maps.
      */
     if ($type->getTypeName() === TypeName::MESSAGE_REF()) {
         $list = [];
         foreach ($value as $v) {
             $list[] = $type->encode($v, $field, $this);
         }
         return ['L' => $list];
     }
     if ($type->isString()) {
         $dynamoType = self::TYPE_STRING_SET;
     } elseif ($type->isNumeric()) {
         $dynamoType = self::TYPE_NUMBER_SET;
     } elseif ($type->isBinary()) {
         $dynamoType = self::TYPE_BINARY_SET;
     } else {
         throw new EncodeValueFailed($value, $field, sprintf('%s::%s has no handling for this value.', get_called_class(), __FUNCTION__));
     }
     $result = [];
     foreach ($value as $v) {
         if ($type->encodesToScalar()) {
             $result[] = (string) $type->encode($v, $field, $this);
         } else {
             $result[] = (string) $v;
         }
     }
     return [$dynamoType => $result];
 }