Ejemplo n.º 1
0
 /**
  * testIsArray_valid
  * @return void
  */
 public function testIsArray_valid()
 {
     $expected = ['a'];
     $actual = Assert::isArray($expected);
     $this->assertSame($expected, $actual);
 }
Ejemplo n.º 2
0
 /**
  * call
  * @param bool|false $useOriginalObject
  * @return Boolean|Map|Number|ObjectInterface|String
  * @throws CatchableException
  * @throws \Exception
  */
 public function call($useOriginalObject = false)
 {
     if ($this->getName() instanceof RawValue) {
         return $this->getName()->getValue();
     } else {
         $currentObject = $useOriginalObject ? $this->getOriginalObject() : $this->getCurrentObject();
         if ($this->getName() == '') {
             return $currentObject;
         }
         $mappableFields = $currentObject->getMappableFields();
         Assert::isArray($mappableFields);
         $validMappings = [];
         foreach ($mappableFields as $mappableField) {
             $validMappings[] = $mappableField->getName();
             if ($mappableField->getName() == $this->getName()) {
                 try {
                     $returnVar = $mappableField->handle($this->getParameters());
                 } catch (CatchableException $e) {
                     $this->throwMappingException($e->getMessage());
                 }
                 if (is_object($returnVar) && $returnVar instanceof ObjectInterface) {
                     return $returnVar;
                 } elseif ($mappableField->getReturnType() == ParseMethod::RETURN_STRING || is_null($returnVar)) {
                     return new String($returnVar);
                 } elseif (in_array($mappableField->getReturnType(), [ParseMethod::RETURN_DOUBLE, ParseMethod::RETURN_INT])) {
                     return new Number($returnVar);
                 } elseif (in_array($mappableField->getReturnType(), [ParseMethod::RETURN_DATE, ParseMethod::RETURN_DATETIME])) {
                     return new Date($returnVar);
                 } elseif ($mappableField->getReturnType() == ParseMethod::RETURN_BOOLEAN) {
                     return new Boolean($returnVar);
                 } elseif ($mappableField->getReturnType() == ParseMethod::RETURN_MAP) {
                     return new Map($returnVar);
                 } elseif ($mappableField->getReturnType() == ParseMethod::RETURN_MIXED) {
                     return Root::createObject($returnVar);
                 } else {
                     throw new \Exception('To Implement: ' . $mappableField->getReturnType());
                 }
             }
         }
         $this->throwMappingException('Could not find a method with the name of: ' . $this->getName() . ' valid options are: ' . implode("\n", $validMappings));
     }
 }
Ejemplo n.º 3
0
 /**
  * arrayFirst
  * @param array $value
  * @return mixed
  */
 private function arrayFirst($value)
 {
     $value = Assert::isArray($value);
     foreach ($value as $part) {
         return $part;
     }
     return null;
 }
Ejemplo n.º 4
0
 /**
  * call
  * @param string          $rawMapping
  * @param int             $index
  * @param ObjectInterface $currentObject
  * @param string          $currentMapping
  * @param array           $parameters
  * @return ObjectInterface
  * @throws \Exception
  */
 private function call($rawMapping, $index, ObjectInterface $currentObject, $currentMapping, array $parameters = [])
 {
     if ($currentMapping == '') {
         return $currentObject;
     }
     $mappableFields = $currentObject->getMappableFields();
     Assert::isArray($mappableFields);
     $validMappings = [];
     foreach ($mappableFields as $mappableField) {
         $validMappings[] = $mappableField->getName();
         if ($mappableField->getName() == $currentMapping) {
             try {
                 $returnVar = $mappableField->handle($parameters);
             } catch (CatchableException $e) {
                 $this->throwMappingException($e->getMessage(), $currentMapping, $index);
             }
             if (is_object($returnVar) && $returnVar instanceof ObjectInterface) {
                 return $returnVar;
             } elseif ($mappableField->getReturnType() == Method::RETURN_STRING || is_null($returnVar)) {
                 return new String($returnVar);
             } elseif (in_array($mappableField->getReturnType(), [Method::RETURN_DOUBLE, Method::RETURN_INT])) {
                 return new Number($returnVar);
             } elseif (in_array($mappableField->getReturnType(), [Method::RETURN_DATE, Method::RETURN_DATETIME])) {
                 return new Date($returnVar);
             } elseif ($mappableField->getReturnType() == Method::RETURN_BOOLEAN) {
                 return new Boolean($returnVar);
             } elseif ($mappableField->getReturnType() == Method::RETURN_MAP) {
                 return new Map($returnVar);
             } else {
                 throw new \Exception('To Implement: ' . $mappableField->getReturnType());
             }
         }
     }
     $this->throwMappingException('Could not find a method with the name of: ' . $currentMapping . ' valid options are: ' . implode("\n", $validMappings), $rawMapping, $index);
 }