Exemple #1
0
 public function testShouldReturnTrueForStringIndicatingScalarValue()
 {
     $this->assertTrue(Scalar::isScalar('int'));
     $this->assertTrue(Scalar::isScalar('boolean'));
     $this->assertTrue(Scalar::isScalar('float'));
     $this->assertTrue(Scalar::isScalar('array'));
 }
Exemple #2
0
 /**
  * @param $type
  * @param $value
  * @return mixed
  */
 private function mapField($type, $value)
 {
     $cacheKey = $this->getCacheKey($type, $value);
     if (!isset($this->mappingFieldsCache[$cacheKey])) {
         if (Scalar::isScalar($type)) {
             $this->mappingFieldsCache[$cacheKey] = Scalar::map($value, $type);
         } else {
             $class = new \ReflectionClass($type);
             $result = $class->getMethod('getMapped')->invoke(null, $value);
             if (is_object($result)) {
                 $object = new \ReflectionObject($result);
                 if ($object->isCloneable()) {
                     $result = clone $result;
                 }
             }
             $this->mappingFieldsCache[$cacheKey] = $result;
         }
     }
     return $this->mappingFieldsCache[$cacheKey];
 }