Ejemplo n.º 1
0
 /**
  * mappableFilter
  * @param LexiconMethod[] $subParsed
  * @return array
  */
 public function mappableFilter(array $subParsed)
 {
     $outputValue = [];
     foreach ($this->getModel()->getValue() as $key => $value) {
         $output = Parameter::parseLexiconParameter($subParsed, false, Root::createObject($value));
         if ($output instanceof BooleanInterface) {
             /** @var BooleanInterface $output */
             $output = $output->getValue();
         }
         if ($output) {
             $outputValue[] = $value;
         }
     }
     return $outputValue;
 }
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));
     }
 }